ESM: Tidied up FlowControl ops

This commit is contained in:
n1474335 committed 2018-05-21 11:39:10 +00:00
1 parent 1472f82205
commit 28b24b725f
9 files changed
+6 -34

No files matched your search

-2
View File
@@ -4,13 +4,11 @@
* @author d98762625 [d98762625@gmail.com] * @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2018 * @copyright Crown Copyright 2018
* @license Apache-2.0 * @license Apache-2.0
*
*/ */
/** /**
* Returns the index of a label. * Returns the index of a label.
* *
* @private
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {string} name - The label name to look for. * @param {string} name - The label name to look for.
* @returns {number} * @returns {number}
-3
View File
@@ -33,8 +33,6 @@ class Comment extends Operation {
} }
/** /**
* Comment operation.
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.
@@ -43,7 +41,6 @@ class Comment extends Operation {
*/ */
run(state) { run(state) {
return state; return state;
} }
} }
+1 -6
View File
@@ -50,8 +50,6 @@ class ConditionalJump extends Operation {
} }
/** /**
* Conditional Jump operation.
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.
@@ -62,10 +60,7 @@ class ConditionalJump extends Operation {
async run(state) { async run(state) {
const ings = state.opList[state.progress].ingValues, const ings = state.opList[state.progress].ingValues,
dish = state.dish, dish = state.dish,
regexStr = ings[0], [regexStr, invert, label, maxJumps] = ings,
invert = ings[1],
label = ings[2],
maxJumps = ings[3],
jmpIndex = getLabelIndex(label, state); jmpIndex = getLabelIndex(label, state);
if (state.numJumps >= maxJumps || jmpIndex === -1) { if (state.numJumps >= maxJumps || jmpIndex === -1) {
+1 -5
View File
@@ -45,8 +45,6 @@ class Fork extends Operation {
} }
/** /**
* Fork operation.
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.
@@ -59,9 +57,7 @@ class Fork extends Operation {
outputType = opList[state.progress].outputType, outputType = opList[state.progress].outputType,
input = await state.dish.get(inputType), input = await state.dish.get(inputType),
ings = opList[state.progress].ingValues, ings = opList[state.progress].ingValues,
splitDelim = ings[0], [splitDelim, mergeDelim, ignoreErrors] = ings,
mergeDelim = ings[1],
ignoreErrors = ings[2],
subOpList = []; subOpList = [];
let inputs = [], let inputs = [],
i; i;
+2 -6
View File
@@ -39,8 +39,6 @@ class Jump extends Operation {
} }
/** /**
* Jump operation.
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.
@@ -49,9 +47,8 @@ class Jump extends Operation {
* @returns {Object} The updated state of the recipe. * @returns {Object} The updated state of the recipe.
*/ */
run(state) { run(state) {
const ings = state.opList[state.progress].ingValues; const ings = state.opList[state.progress].ingValues;
const label = ings[0]; const [label, maxJumps] = ings;
const maxJumps = ings[1];
const jmpIndex = getLabelIndex(label, state); const jmpIndex = getLabelIndex(label, state);
if (state.numJumps >= maxJumps || jmpIndex === -1) { if (state.numJumps >= maxJumps || jmpIndex === -1) {
@@ -61,7 +58,6 @@ class Jump extends Operation {
state.progress = jmpIndex; state.progress = jmpIndex;
state.numJumps++; state.numJumps++;
return state; return state;
} }
} }
+1 -3
View File
@@ -7,7 +7,7 @@
import Operation from "../Operation"; import Operation from "../Operation";
/** /**
* Label operation * Label operation. For use with Jump and Conditional Jump.
*/ */
class Label extends Operation { class Label extends Operation {
@@ -33,8 +33,6 @@ class Label extends Operation {
} }
/** /**
* Label operation. For use with Jump and Conditional Jump
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.
-2
View File
@@ -27,8 +27,6 @@ class Merge extends Operation {
} }
/** /**
* Merge operation.
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.
+1 -5
View File
@@ -44,8 +44,6 @@ class Register extends Operation {
} }
/** /**
* Register operation.
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.
@@ -54,9 +52,7 @@ class Register extends Operation {
*/ */
async run(state) { async run(state) {
const ings = state.opList[state.progress].ingValues; const ings = state.opList[state.progress].ingValues;
const extractorStr = ings[0]; const [extractorStr, i, m] = ings;
const i = ings[1];
const m = ings[2];
let modifiers = ""; let modifiers = "";
if (i) modifiers += "i"; if (i) modifiers += "i";
-2
View File
@@ -27,8 +27,6 @@ class Return extends Operation {
} }
/** /**
* Return operation.
*
* @param {Object} state - The current state of the recipe. * @param {Object} state - The current state of the recipe.
* @param {number} state.progress - The current position in the recipe. * @param {number} state.progress - The current position in the recipe.
* @param {Dish} state.dish - The Dish being operated on. * @param {Dish} state.dish - The Dish being operated on.