bare-script 2.2.7 → 2.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/parser.js +2 -16
- package/lib/runtime.js +5 -1
- package/lib/runtimeAsync.js +10 -2
- package/package.json +1 -1
package/lib/parser.js
CHANGED
|
@@ -346,7 +346,7 @@ export function parseScript(scriptText, startLineNumber = 1) {
|
|
|
346
346
|
const matchBreak = line.match(rScriptBreak);
|
|
347
347
|
if (matchBreak !== null) {
|
|
348
348
|
// Get the loop definition
|
|
349
|
-
const labelDef = (labelDefs.length > 0 ?
|
|
349
|
+
const labelDef = (labelDefs.length > 0 ? (labelDefs.findLast((def) => !('if' in def)) ?? null) : null);
|
|
350
350
|
if (labelDef === null) {
|
|
351
351
|
throw new BareScriptParserError('Break statement outside of loop', line, 1, startLineNumber + ixLine);
|
|
352
352
|
}
|
|
@@ -362,7 +362,7 @@ export function parseScript(scriptText, startLineNumber = 1) {
|
|
|
362
362
|
const matchContinue = line.match(rScriptContinue);
|
|
363
363
|
if (matchContinue !== null) {
|
|
364
364
|
// Get the loop definition
|
|
365
|
-
const labelDef = (labelDefs.length > 0 ?
|
|
365
|
+
const labelDef = (labelDefs.length > 0 ? (labelDefs.findLast((def) => !('if' in def)) ?? null) : null);
|
|
366
366
|
if (labelDef === null) {
|
|
367
367
|
throw new BareScriptParserError('Continue statement outside of loop', line, 1, startLineNumber + ixLine);
|
|
368
368
|
}
|
|
@@ -449,20 +449,6 @@ export function parseScript(scriptText, startLineNumber = 1) {
|
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
|
|
452
|
-
// Firefox versions prior to 103 are missing Array.findLast - Debian Bookworm has Firefox 102
|
|
453
|
-
function arrayFindLast(array, findFn) {
|
|
454
|
-
let ixValue = array.length - 1;
|
|
455
|
-
while (ixValue >= 0) {
|
|
456
|
-
const value = array[ixValue];
|
|
457
|
-
if (findFn(value)) {
|
|
458
|
-
return value;
|
|
459
|
-
}
|
|
460
|
-
ixValue -= 1;
|
|
461
|
-
}
|
|
462
|
-
return null;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
452
|
// BareScript expression regex
|
|
467
453
|
const rExprBinaryOp = /^\s*(\*\*|\*|\/|%|\+|-|<=|<|>=|>|==|!=|&&|\|\|)/;
|
|
468
454
|
const rExprUnaryOp = /^\s*(!|-)/;
|
package/lib/runtime.js
CHANGED
|
@@ -138,7 +138,11 @@ export function executeScriptHelper(statements, options, locals) {
|
|
|
138
138
|
const ixArgLast = (statement.function.lastArgArray ?? null) && (funcArgsLength - 1);
|
|
139
139
|
for (let ixArg = 0; ixArg < funcArgsLength; ixArg++) {
|
|
140
140
|
const argName = statement.function.args[ixArg];
|
|
141
|
-
|
|
141
|
+
if (ixArg < argsLength) {
|
|
142
|
+
funcLocals[argName] = (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]);
|
|
143
|
+
} else {
|
|
144
|
+
funcLocals[argName] = (ixArg === ixArgLast ? [] : null);
|
|
145
|
+
}
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
148
|
return executeScriptHelper(statement.function.statements, fnOptions, funcLocals);
|
package/lib/runtimeAsync.js
CHANGED
|
@@ -108,7 +108,11 @@ async function executeScriptHelperAsync(statements, options, locals) {
|
|
|
108
108
|
const ixArgLast = (statement.function.lastArgArray ?? null) && (funcArgsLength - 1);
|
|
109
109
|
for (let ixArg = 0; ixArg < funcArgsLength; ixArg++) {
|
|
110
110
|
const argName = statement.function.args[ixArg];
|
|
111
|
-
|
|
111
|
+
if (ixArg < argsLength) {
|
|
112
|
+
funcLocals[argName] = (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]);
|
|
113
|
+
} else {
|
|
114
|
+
funcLocals[argName] = (ixArg === ixArgLast ? [] : null);
|
|
115
|
+
}
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
return executeScriptHelperAsync(statement.function.statements, fnOptions, funcLocals);
|
|
@@ -122,7 +126,11 @@ async function executeScriptHelperAsync(statements, options, locals) {
|
|
|
122
126
|
const ixArgLast = (statement.function.lastArgArray ?? null) && (funcArgsLength - 1);
|
|
123
127
|
for (let ixArg = 0; ixArg < funcArgsLength; ixArg++) {
|
|
124
128
|
const argName = statement.function.args[ixArg];
|
|
125
|
-
|
|
129
|
+
if (ixArg < argsLength) {
|
|
130
|
+
funcLocals[argName] = (ixArg === ixArgLast ? args.slice(ixArg) : args[ixArg]);
|
|
131
|
+
} else {
|
|
132
|
+
funcLocals[argName] = (ixArg === ixArgLast ? [] : null);
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
return executeScriptHelper(statement.function.statements, fnOptions, funcLocals);
|