bare-script 2.2.17 → 2.3.0

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 CHANGED
@@ -510,7 +510,7 @@ const binaryReorder = {
510
510
  /**
511
511
  * Parse a BareScript expression
512
512
  *
513
- * @param {string} exprText - The [expression text]{@link https://craigahobbs.github.io/bare-script/language/#Expressions}
513
+ * @param {string} exprText - The [expression text]{@link https://craigahobbs.github.io/bare-script/language/#expressions}
514
514
  * @returns {Object} The [expression model]{@link https://craigahobbs.github.io/bare-script/model/#var.vName='Expression'}
515
515
  * @throws [BareScriptParserError]{@link module:lib/parser.BareScriptParserError}
516
516
  */
package/lib/runtime.js CHANGED
@@ -176,13 +176,15 @@ export function evaluateExpression(expr, options = null, locals = null, builtins
176
176
  // Number
177
177
  if (exprKey === 'number') {
178
178
  return expr.number;
179
+ }
179
180
 
180
181
  // String
181
- } else if (exprKey === 'string') {
182
+ if (exprKey === 'string') {
182
183
  return expr.string;
184
+ }
183
185
 
184
186
  // Variable
185
- } else if (exprKey === 'variable') {
187
+ if (exprKey === 'variable') {
186
188
  // Keywords
187
189
  if (expr.variable === 'null') {
188
190
  return null;
@@ -193,16 +195,15 @@ export function evaluateExpression(expr, options = null, locals = null, builtins
193
195
  }
194
196
 
195
197
  // Get the local or global variable value or null if undefined
196
- let varValue;
197
- if (locals !== null && expr.variable in locals) {
198
- varValue = locals[expr.variable];
199
- } else {
198
+ let varValue = (locals !== null ? locals[expr.variable] : undefined);
199
+ if (typeof varValue === 'undefined') {
200
200
  varValue = (globals !== null ? (globals[expr.variable] ?? null) : null);
201
201
  }
202
202
  return varValue;
203
+ }
203
204
 
204
205
  // Function
205
- } else if (exprKey === 'function') {
206
+ if (exprKey === 'function') {
206
207
  // "if" built-in function?
207
208
  const funcName = expr.function.name;
208
209
  if (funcName === 'if') {
@@ -222,7 +223,7 @@ export function evaluateExpression(expr, options = null, locals = null, builtins
222
223
  if (typeof funcValue === 'undefined') {
223
224
  funcValue = (globals !== null ? globals[funcName] : undefined);
224
225
  if (typeof funcValue === 'undefined') {
225
- funcValue = (builtins ? expressionFunctions[funcName] : null) ?? null;
226
+ funcValue = (builtins ? (expressionFunctions[funcName] ?? null) : null);
226
227
  }
227
228
  }
228
229
  if (funcValue !== null) {
@@ -249,9 +250,10 @@ export function evaluateExpression(expr, options = null, locals = null, builtins
249
250
  }
250
251
 
251
252
  throw new BareScriptRuntimeError(`Undefined function "${funcName}"`);
253
+ }
252
254
 
253
255
  // Binary expression
254
- } else if (exprKey === 'binary') {
256
+ if (exprKey === 'binary') {
255
257
  const binOp = expr.binary.op;
256
258
  const leftValue = evaluateExpression(expr.binary.left, options, locals, builtins);
257
259
 
@@ -289,9 +291,10 @@ export function evaluateExpression(expr, options = null, locals = null, builtins
289
291
  }
290
292
  // else if (binOp === '!=')
291
293
  return leftValue !== rightValue;
294
+ }
292
295
 
293
296
  // Unary expression
294
- } else if (exprKey === 'unary') {
297
+ if (exprKey === 'unary') {
295
298
  const unaryOp = expr.unary.op;
296
299
  const value = evaluateExpression(expr.unary.expr, options, locals, builtins);
297
300
  if (unaryOp === '!') {
@@ -244,13 +244,15 @@ export async function evaluateExpressionAsync(expr, options = null, locals = nul
244
244
  // Number
245
245
  if (exprKey === 'number') {
246
246
  return expr.number;
247
+ }
247
248
 
248
249
  // String
249
- } else if (exprKey === 'string') {
250
+ if (exprKey === 'string') {
250
251
  return expr.string;
252
+ }
251
253
 
252
254
  // Variable
253
- } else if (exprKey === 'variable') {
255
+ if (exprKey === 'variable') {
254
256
  // Keywords
255
257
  if (expr.variable === 'null') {
256
258
  return null;
@@ -266,9 +268,10 @@ export async function evaluateExpressionAsync(expr, options = null, locals = nul
266
268
  varValue = (globals !== null ? (globals[expr.variable] ?? null) : null);
267
269
  }
268
270
  return varValue;
271
+ }
269
272
 
270
273
  // Function
271
- } else if (exprKey === 'function') {
274
+ if (exprKey === 'function') {
272
275
  // "if" built-in function?
273
276
  const funcName = expr.function.name;
274
277
  if (funcName === 'if') {
@@ -311,9 +314,10 @@ export async function evaluateExpressionAsync(expr, options = null, locals = nul
311
314
  }
312
315
 
313
316
  throw new BareScriptRuntimeError(`Undefined function "${funcName}"`);
317
+ }
314
318
 
315
319
  // Binary expression
316
- } else if (exprKey === 'binary') {
320
+ if (exprKey === 'binary') {
317
321
  const binOp = expr.binary.op;
318
322
  const leftValue = await evaluateExpressionAsync(expr.binary.left, options, locals, builtins);
319
323
 
@@ -351,9 +355,10 @@ export async function evaluateExpressionAsync(expr, options = null, locals = nul
351
355
  }
352
356
  // else if (binOp === '!=')
353
357
  return leftValue !== rightValue;
358
+ }
354
359
 
355
360
  // Unary expression
356
- } else if (exprKey === 'unary') {
361
+ if (exprKey === 'unary') {
357
362
  const unaryOp = expr.unary.op;
358
363
  const value = await evaluateExpressionAsync(expr.unary.expr, options, locals, builtins);
359
364
  if (unaryOp === '!') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "2.2.17",
4
+ "version": "2.3.0",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",
@@ -30,8 +30,8 @@
30
30
  "schema-markdown": "~1.2"
31
31
  },
32
32
  "devDependencies": {
33
- "c8": "~8.0",
34
- "eslint": "~8.52",
33
+ "c8": "~9.1",
34
+ "eslint": "~8.56",
35
35
  "jsdoc": "~4.0"
36
36
  }
37
37
  }