Skip to content

Commit

Permalink
Pass with --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Schamp committed Apr 17, 2017
1 parent f646a61 commit e01c4ae
Show file tree
Hide file tree
Showing 41 changed files with 803 additions and 824 deletions.
24 changes: 12 additions & 12 deletions src/blocks/scratch3_control.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Cast = require('../util/cast');
var Timer = require('../util/timer');
const Cast = require('../util/cast');
const Timer = require('../util/timer');

var Scratch3ControlBlocks = function (runtime) {
const Scratch3ControlBlocks = function (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
Expand Down Expand Up @@ -37,7 +37,7 @@ Scratch3ControlBlocks.prototype.getHats = function () {
};

Scratch3ControlBlocks.prototype.repeat = function (args, util) {
var times = Math.floor(Cast.toNumber(args.TIMES));
const times = Math.floor(Cast.toNumber(args.TIMES));
// Initialize loop
if (typeof util.stackFrame.loopCounter === 'undefined') {
util.stackFrame.loopCounter = times;
Expand All @@ -54,15 +54,15 @@ Scratch3ControlBlocks.prototype.repeat = function (args, util) {
};

Scratch3ControlBlocks.prototype.repeatUntil = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
const condition = Cast.toBoolean(args.CONDITION);
// If the condition is true, start the branch.
if (!condition) {
util.startBranch(1, true);
}
};

Scratch3ControlBlocks.prototype.waitUntil = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
const condition = Cast.toBoolean(args.CONDITION);
if (!condition) {
util.yield();
}
Expand All @@ -79,22 +79,22 @@ Scratch3ControlBlocks.prototype.wait = function (args, util) {
util.yield();
this.runtime.requestRedraw();
} else {
var duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION));
const duration = Math.max(0, 1000 * Cast.toNumber(args.DURATION));
if (util.stackFrame.timer.timeElapsed() < duration) {
util.yield();
}
}
};

Scratch3ControlBlocks.prototype.if = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
const condition = Cast.toBoolean(args.CONDITION);
if (condition) {
util.startBranch(1, false);
}
};

Scratch3ControlBlocks.prototype.ifElse = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
const condition = Cast.toBoolean(args.CONDITION);
if (condition) {
util.startBranch(1, false);
} else {
Expand All @@ -103,7 +103,7 @@ Scratch3ControlBlocks.prototype.ifElse = function (args, util) {
};

Scratch3ControlBlocks.prototype.stop = function (args, util) {
var option = args.STOP_OPTION;
const option = args.STOP_OPTION;
if (option === 'all') {
util.stopAll();
} else if (option === 'other scripts in sprite' ||
Expand All @@ -115,7 +115,7 @@ Scratch3ControlBlocks.prototype.stop = function (args, util) {
};

Scratch3ControlBlocks.prototype.createClone = function (args, util) {
var cloneTarget;
let cloneTarget;
if (args.CLONE_OPTION === '_myself_') {
cloneTarget = util.target;
} else {
Expand All @@ -124,7 +124,7 @@ Scratch3ControlBlocks.prototype.createClone = function (args, util) {
if (!cloneTarget) {
return;
}
var newClone = cloneTarget.makeClone();
const newClone = cloneTarget.makeClone();
if (newClone) {
this.runtime.targets.push(newClone);
}
Expand Down
56 changes: 28 additions & 28 deletions src/blocks/scratch3_data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Cast = require('../util/cast');
const Cast = require('../util/cast');

var Scratch3DataBlocks = function (runtime) {
const Scratch3DataBlocks = function (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
Expand Down Expand Up @@ -29,30 +29,30 @@ Scratch3DataBlocks.prototype.getPrimitives = function () {
};

Scratch3DataBlocks.prototype.getVariable = function (args, util) {
var variable = util.target.lookupOrCreateVariable(args.VARIABLE);
const variable = util.target.lookupOrCreateVariable(args.VARIABLE);
return variable.value;
};

Scratch3DataBlocks.prototype.setVariableTo = function (args, util) {
var variable = util.target.lookupOrCreateVariable(args.VARIABLE);
const variable = util.target.lookupOrCreateVariable(args.VARIABLE);
variable.value = args.VALUE;
};

Scratch3DataBlocks.prototype.changeVariableBy = function (args, util) {
var variable = util.target.lookupOrCreateVariable(args.VARIABLE);
var castedValue = Cast.toNumber(variable.value);
var dValue = Cast.toNumber(args.VALUE);
const variable = util.target.lookupOrCreateVariable(args.VARIABLE);
const castedValue = Cast.toNumber(variable.value);
const dValue = Cast.toNumber(args.VALUE);
variable.value = castedValue + dValue;
};

Scratch3DataBlocks.prototype.getListContents = function (args, util) {
var list = util.target.lookupOrCreateList(args.LIST);
const list = util.target.lookupOrCreateList(args.LIST);
// Determine if the list is all single letters.
// If it is, report contents joined together with no separator.
// If it's not, report contents joined together with a space.
var allSingleLetters = true;
for (var i = 0; i < list.contents.length; i++) {
var listItem = list.contents[i];
let allSingleLetters = true;
for (let i = 0; i < list.contents.length; i++) {
const listItem = list.contents[i];
if (!((typeof listItem === 'string') &&
(listItem.length === 1))) {
allSingleLetters = false;
Expand All @@ -61,19 +61,19 @@ Scratch3DataBlocks.prototype.getListContents = function (args, util) {
}
if (allSingleLetters) {
return list.contents.join('');
} else {
return list.contents.join(' ');
}
return list.contents.join(' ');

};

Scratch3DataBlocks.prototype.addToList = function (args, util) {
var list = util.target.lookupOrCreateList(args.LIST);
const list = util.target.lookupOrCreateList(args.LIST);
list.contents.push(args.ITEM);
};

Scratch3DataBlocks.prototype.deleteOfList = function (args, util) {
var list = util.target.lookupOrCreateList(args.LIST);
var index = Cast.toListIndex(args.INDEX, list.contents.length);
const list = util.target.lookupOrCreateList(args.LIST);
const index = Cast.toListIndex(args.INDEX, list.contents.length);
if (index === Cast.LIST_INVALID) {
return;
} else if (index === Cast.LIST_ALL) {
Expand All @@ -84,48 +84,48 @@ Scratch3DataBlocks.prototype.deleteOfList = function (args, util) {
};

Scratch3DataBlocks.prototype.insertAtList = function (args, util) {
var item = args.ITEM;
var list = util.target.lookupOrCreateList(args.LIST);
var index = Cast.toListIndex(args.INDEX, list.contents.length + 1);
const item = args.ITEM;
const list = util.target.lookupOrCreateList(args.LIST);
const index = Cast.toListIndex(args.INDEX, list.contents.length + 1);
if (index === Cast.LIST_INVALID) {
return;
}
list.contents.splice(index - 1, 0, item);
};

Scratch3DataBlocks.prototype.replaceItemOfList = function (args, util) {
var item = args.ITEM;
var list = util.target.lookupOrCreateList(args.LIST);
var index = Cast.toListIndex(args.INDEX, list.contents.length);
const item = args.ITEM;
const list = util.target.lookupOrCreateList(args.LIST);
const index = Cast.toListIndex(args.INDEX, list.contents.length);
if (index === Cast.LIST_INVALID) {
return;
}
list.contents.splice(index - 1, 1, item);
};

Scratch3DataBlocks.prototype.getItemOfList = function (args, util) {
var list = util.target.lookupOrCreateList(args.LIST);
var index = Cast.toListIndex(args.INDEX, list.contents.length);
const list = util.target.lookupOrCreateList(args.LIST);
const index = Cast.toListIndex(args.INDEX, list.contents.length);
if (index === Cast.LIST_INVALID) {
return '';
}
return list.contents[index - 1];
};

Scratch3DataBlocks.prototype.lengthOfList = function (args, util) {
var list = util.target.lookupOrCreateList(args.LIST);
const list = util.target.lookupOrCreateList(args.LIST);
return list.contents.length;
};

Scratch3DataBlocks.prototype.listContainsItem = function (args, util) {
var item = args.ITEM;
var list = util.target.lookupOrCreateList(args.LIST);
const item = args.ITEM;
const list = util.target.lookupOrCreateList(args.LIST);
if (list.contents.indexOf(item) >= 0) {
return true;
}
// Try using Scratch comparison operator on each item.
// (Scratch considers the string '123' equal to the number 123).
for (var i = 0; i < list.contents.length; i++) {
for (let i = 0; i < list.contents.length; i++) {
if (Cast.compare(list.contents[i], item) === 0) {
return true;
}
Expand Down
18 changes: 8 additions & 10 deletions src/blocks/scratch3_event.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Cast = require('../util/cast');
const Cast = require('../util/cast');

var Scratch3EventBlocks = function (runtime) {
const Scratch3EventBlocks = function (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
Expand Down Expand Up @@ -45,8 +45,8 @@ Scratch3EventBlocks.prototype.getHats = function () {
};

Scratch3EventBlocks.prototype.hatGreaterThanPredicate = function (args, util) {
var option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
var value = Cast.toNumber(args.VALUE);
const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
const value = Cast.toNumber(args.VALUE);
// @todo: Other cases :)
if (option === 'timer') {
return util.ioQuery('clock', 'projectTimer') > value;
Expand All @@ -55,14 +55,14 @@ Scratch3EventBlocks.prototype.hatGreaterThanPredicate = function (args, util) {
};

Scratch3EventBlocks.prototype.broadcast = function (args, util) {
var broadcastOption = Cast.toString(args.BROADCAST_OPTION);
const broadcastOption = Cast.toString(args.BROADCAST_OPTION);
util.startHats('event_whenbroadcastreceived', {
BROADCAST_OPTION: broadcastOption
});
};

Scratch3EventBlocks.prototype.broadcastAndWait = function (args, util) {
var broadcastOption = Cast.toString(args.BROADCAST_OPTION);
const broadcastOption = Cast.toString(args.BROADCAST_OPTION);
// Have we run before, starting threads?
if (!util.stackFrame.startedThreads) {
// No - start hats for this broadcast.
Expand All @@ -77,10 +77,8 @@ Scratch3EventBlocks.prototype.broadcastAndWait = function (args, util) {
}
}
// We've run before; check if the wait is still going on.
var instance = this;
var waiting = util.stackFrame.startedThreads.some(function (thread) {
return instance.runtime.isActiveThread(thread);
});
const instance = this;
const waiting = util.stackFrame.startedThreads.some(thread => instance.runtime.isActiveThread(thread));
if (waiting) {
util.yield();
}
Expand Down
Loading

0 comments on commit e01c4ae

Please sign in to comment.