@supernova-studio/pulsar-core 1.5.0 → 1.5.1
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/build/main/pulsar-core.js +11 -1101
- package/build/main/pulsar-core.js.map +1 -1
- package/package.json +2 -1
|
@@ -21827,7 +21827,7 @@ exports.SyntaxNodeSubstitution = void 0;
|
|
|
21827
21827
|
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
21828
21828
|
// MARK: - Imports
|
|
21829
21829
|
const SyntaxNode_1 = __webpack_require__(/*! ../SyntaxNode */ "../language/src/parser/syntax/nodes/SyntaxNode.ts");
|
|
21830
|
-
const jsep_1 = __importDefault(__webpack_require__(/*! jsep */ "
|
|
21830
|
+
const jsep_1 = __importDefault(__webpack_require__(/*! jsep */ "jsep"));
|
|
21831
21831
|
const ExpressionObject_1 = __webpack_require__(/*! ../jsep/ExpressionObject */ "../language/src/parser/syntax/nodes/jsep/ExpressionObject.ts");
|
|
21832
21832
|
const SyntaxNodeSubstitutionAnalyzer_1 = __webpack_require__(/*! ./SyntaxNodeSubstitutionAnalyzer */ "../language/src/parser/syntax/nodes/substitution/SyntaxNodeSubstitutionAnalyzer.ts");
|
|
21833
21833
|
const SyntaxNodeSubstitutionSyncInterpreter_1 = __webpack_require__(/*! ./interpreters/SyntaxNodeSubstitutionSyncInterpreter */ "../language/src/parser/syntax/nodes/substitution/interpreters/SyntaxNodeSubstitutionSyncInterpreter.ts");
|
|
@@ -26271,1106 +26271,6 @@ function withTimeout(sync, timeout, timeoutError) {
|
|
|
26271
26271
|
exports.withTimeout = withTimeout;
|
|
26272
26272
|
|
|
26273
26273
|
|
|
26274
|
-
/***/ }),
|
|
26275
|
-
|
|
26276
|
-
/***/ "../language/node_modules/jsep/dist/cjs/jsep.cjs.js":
|
|
26277
|
-
/*!**********************************************************!*\
|
|
26278
|
-
!*** ../language/node_modules/jsep/dist/cjs/jsep.cjs.js ***!
|
|
26279
|
-
\**********************************************************/
|
|
26280
|
-
/***/ ((module) => {
|
|
26281
|
-
|
|
26282
|
-
|
|
26283
|
-
|
|
26284
|
-
/**
|
|
26285
|
-
* @implements {IHooks}
|
|
26286
|
-
*/
|
|
26287
|
-
class Hooks {
|
|
26288
|
-
/**
|
|
26289
|
-
* @callback HookCallback
|
|
26290
|
-
* @this {*|Jsep} this
|
|
26291
|
-
* @param {Jsep} env
|
|
26292
|
-
* @returns: void
|
|
26293
|
-
*/
|
|
26294
|
-
/**
|
|
26295
|
-
* Adds the given callback to the list of callbacks for the given hook.
|
|
26296
|
-
*
|
|
26297
|
-
* The callback will be invoked when the hook it is registered for is run.
|
|
26298
|
-
*
|
|
26299
|
-
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
26300
|
-
*
|
|
26301
|
-
* @param {string|object} name The name of the hook, or an object of callbacks keyed by name
|
|
26302
|
-
* @param {HookCallback|boolean} callback The callback function which is given environment variables.
|
|
26303
|
-
* @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)
|
|
26304
|
-
* @public
|
|
26305
|
-
*/
|
|
26306
|
-
add(name, callback, first) {
|
|
26307
|
-
if (typeof arguments[0] != 'string') {
|
|
26308
|
-
// Multiple hook callbacks, keyed by name
|
|
26309
|
-
for (let name in arguments[0]) {
|
|
26310
|
-
this.add(name, arguments[0][name], arguments[1]);
|
|
26311
|
-
}
|
|
26312
|
-
}
|
|
26313
|
-
else {
|
|
26314
|
-
(Array.isArray(name) ? name : [name]).forEach(function (name) {
|
|
26315
|
-
this[name] = this[name] || [];
|
|
26316
|
-
|
|
26317
|
-
if (callback) {
|
|
26318
|
-
this[name][first ? 'unshift' : 'push'](callback);
|
|
26319
|
-
}
|
|
26320
|
-
}, this);
|
|
26321
|
-
}
|
|
26322
|
-
}
|
|
26323
|
-
|
|
26324
|
-
/**
|
|
26325
|
-
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
26326
|
-
*
|
|
26327
|
-
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
26328
|
-
*
|
|
26329
|
-
* @param {string} name The name of the hook.
|
|
26330
|
-
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
26331
|
-
* @public
|
|
26332
|
-
*/
|
|
26333
|
-
run(name, env) {
|
|
26334
|
-
this[name] = this[name] || [];
|
|
26335
|
-
this[name].forEach(function (callback) {
|
|
26336
|
-
callback.call(env && env.context ? env.context : env, env);
|
|
26337
|
-
});
|
|
26338
|
-
}
|
|
26339
|
-
}
|
|
26340
|
-
|
|
26341
|
-
/**
|
|
26342
|
-
* @implements {IPlugins}
|
|
26343
|
-
*/
|
|
26344
|
-
class Plugins {
|
|
26345
|
-
constructor(jsep) {
|
|
26346
|
-
this.jsep = jsep;
|
|
26347
|
-
this.registered = {};
|
|
26348
|
-
}
|
|
26349
|
-
|
|
26350
|
-
/**
|
|
26351
|
-
* @callback PluginSetup
|
|
26352
|
-
* @this {Jsep} jsep
|
|
26353
|
-
* @returns: void
|
|
26354
|
-
*/
|
|
26355
|
-
/**
|
|
26356
|
-
* Adds the given plugin(s) to the registry
|
|
26357
|
-
*
|
|
26358
|
-
* @param {object} plugins
|
|
26359
|
-
* @param {string} plugins.name The name of the plugin
|
|
26360
|
-
* @param {PluginSetup} plugins.init The init function
|
|
26361
|
-
* @public
|
|
26362
|
-
*/
|
|
26363
|
-
register(...plugins) {
|
|
26364
|
-
plugins.forEach((plugin) => {
|
|
26365
|
-
if (typeof plugin !== 'object' || !plugin.name || !plugin.init) {
|
|
26366
|
-
throw new Error('Invalid JSEP plugin format');
|
|
26367
|
-
}
|
|
26368
|
-
if (this.registered[plugin.name]) {
|
|
26369
|
-
// already registered. Ignore.
|
|
26370
|
-
return;
|
|
26371
|
-
}
|
|
26372
|
-
plugin.init(this.jsep);
|
|
26373
|
-
this.registered[plugin.name] = plugin;
|
|
26374
|
-
});
|
|
26375
|
-
}
|
|
26376
|
-
}
|
|
26377
|
-
|
|
26378
|
-
// JavaScript Expression Parser (JSEP) 1.0.2
|
|
26379
|
-
|
|
26380
|
-
class Jsep {
|
|
26381
|
-
/**
|
|
26382
|
-
* @returns {string}
|
|
26383
|
-
*/
|
|
26384
|
-
static get version() {
|
|
26385
|
-
// To be filled in by the template
|
|
26386
|
-
return '1.0.2';
|
|
26387
|
-
}
|
|
26388
|
-
|
|
26389
|
-
/**
|
|
26390
|
-
* @returns {string}
|
|
26391
|
-
*/
|
|
26392
|
-
static toString() {
|
|
26393
|
-
return 'JavaScript Expression Parser (JSEP) v' + Jsep.version;
|
|
26394
|
-
};
|
|
26395
|
-
|
|
26396
|
-
// ==================== CONFIG ================================
|
|
26397
|
-
/**
|
|
26398
|
-
* @method addUnaryOp
|
|
26399
|
-
* @param {string} op_name The name of the unary op to add
|
|
26400
|
-
* @returns {Jsep}
|
|
26401
|
-
*/
|
|
26402
|
-
static addUnaryOp(op_name) {
|
|
26403
|
-
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
26404
|
-
Jsep.unary_ops[op_name] = 1;
|
|
26405
|
-
return Jsep;
|
|
26406
|
-
}
|
|
26407
|
-
|
|
26408
|
-
/**
|
|
26409
|
-
* @method jsep.addBinaryOp
|
|
26410
|
-
* @param {string} op_name The name of the binary op to add
|
|
26411
|
-
* @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence
|
|
26412
|
-
* @returns {Jsep}
|
|
26413
|
-
*/
|
|
26414
|
-
static addBinaryOp(op_name, precedence) {
|
|
26415
|
-
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
26416
|
-
Jsep.binary_ops[op_name] = precedence;
|
|
26417
|
-
return Jsep;
|
|
26418
|
-
}
|
|
26419
|
-
|
|
26420
|
-
/**
|
|
26421
|
-
* @method addIdentifierChar
|
|
26422
|
-
* @param {string} char The additional character to treat as a valid part of an identifier
|
|
26423
|
-
* @returns {Jsep}
|
|
26424
|
-
*/
|
|
26425
|
-
static addIdentifierChar(char) {
|
|
26426
|
-
Jsep.additional_identifier_chars.add(char);
|
|
26427
|
-
return Jsep;
|
|
26428
|
-
}
|
|
26429
|
-
|
|
26430
|
-
/**
|
|
26431
|
-
* @method addLiteral
|
|
26432
|
-
* @param {string} literal_name The name of the literal to add
|
|
26433
|
-
* @param {*} literal_value The value of the literal
|
|
26434
|
-
* @returns {Jsep}
|
|
26435
|
-
*/
|
|
26436
|
-
static addLiteral(literal_name, literal_value) {
|
|
26437
|
-
Jsep.literals[literal_name] = literal_value;
|
|
26438
|
-
return Jsep;
|
|
26439
|
-
}
|
|
26440
|
-
|
|
26441
|
-
/**
|
|
26442
|
-
* @method removeUnaryOp
|
|
26443
|
-
* @param {string} op_name The name of the unary op to remove
|
|
26444
|
-
* @returns {Jsep}
|
|
26445
|
-
*/
|
|
26446
|
-
static removeUnaryOp(op_name) {
|
|
26447
|
-
delete Jsep.unary_ops[op_name];
|
|
26448
|
-
if (op_name.length === Jsep.max_unop_len) {
|
|
26449
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
26450
|
-
}
|
|
26451
|
-
return Jsep;
|
|
26452
|
-
}
|
|
26453
|
-
|
|
26454
|
-
/**
|
|
26455
|
-
* @method removeAllUnaryOps
|
|
26456
|
-
* @returns {Jsep}
|
|
26457
|
-
*/
|
|
26458
|
-
static removeAllUnaryOps() {
|
|
26459
|
-
Jsep.unary_ops = {};
|
|
26460
|
-
Jsep.max_unop_len = 0;
|
|
26461
|
-
|
|
26462
|
-
return Jsep;
|
|
26463
|
-
}
|
|
26464
|
-
|
|
26465
|
-
/**
|
|
26466
|
-
* @method removeIdentifierChar
|
|
26467
|
-
* @param {string} char The additional character to stop treating as a valid part of an identifier
|
|
26468
|
-
* @returns {Jsep}
|
|
26469
|
-
*/
|
|
26470
|
-
static removeIdentifierChar(char) {
|
|
26471
|
-
Jsep.additional_identifier_chars.delete(char);
|
|
26472
|
-
return Jsep;
|
|
26473
|
-
}
|
|
26474
|
-
|
|
26475
|
-
/**
|
|
26476
|
-
* @method removeBinaryOp
|
|
26477
|
-
* @param {string} op_name The name of the binary op to remove
|
|
26478
|
-
* @returns {Jsep}
|
|
26479
|
-
*/
|
|
26480
|
-
static removeBinaryOp(op_name) {
|
|
26481
|
-
delete Jsep.binary_ops[op_name];
|
|
26482
|
-
|
|
26483
|
-
if (op_name.length === Jsep.max_binop_len) {
|
|
26484
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
26485
|
-
}
|
|
26486
|
-
|
|
26487
|
-
return Jsep;
|
|
26488
|
-
}
|
|
26489
|
-
|
|
26490
|
-
/**
|
|
26491
|
-
* @method removeAllBinaryOps
|
|
26492
|
-
* @returns {Jsep}
|
|
26493
|
-
*/
|
|
26494
|
-
static removeAllBinaryOps() {
|
|
26495
|
-
Jsep.binary_ops = {};
|
|
26496
|
-
Jsep.max_binop_len = 0;
|
|
26497
|
-
|
|
26498
|
-
return Jsep;
|
|
26499
|
-
}
|
|
26500
|
-
|
|
26501
|
-
/**
|
|
26502
|
-
* @method removeLiteral
|
|
26503
|
-
* @param {string} literal_name The name of the literal to remove
|
|
26504
|
-
* @returns {Jsep}
|
|
26505
|
-
*/
|
|
26506
|
-
static removeLiteral(literal_name) {
|
|
26507
|
-
delete Jsep.literals[literal_name];
|
|
26508
|
-
return Jsep;
|
|
26509
|
-
}
|
|
26510
|
-
|
|
26511
|
-
/**
|
|
26512
|
-
* @method removeAllLiterals
|
|
26513
|
-
* @returns {Jsep}
|
|
26514
|
-
*/
|
|
26515
|
-
static removeAllLiterals() {
|
|
26516
|
-
Jsep.literals = {};
|
|
26517
|
-
|
|
26518
|
-
return Jsep;
|
|
26519
|
-
}
|
|
26520
|
-
// ==================== END CONFIG ============================
|
|
26521
|
-
|
|
26522
|
-
|
|
26523
|
-
/**
|
|
26524
|
-
* @returns {string}
|
|
26525
|
-
*/
|
|
26526
|
-
get char() {
|
|
26527
|
-
return this.expr.charAt(this.index);
|
|
26528
|
-
}
|
|
26529
|
-
|
|
26530
|
-
/**
|
|
26531
|
-
* @returns {number}
|
|
26532
|
-
*/
|
|
26533
|
-
get code() {
|
|
26534
|
-
return this.expr.charCodeAt(this.index);
|
|
26535
|
-
};
|
|
26536
|
-
|
|
26537
|
-
|
|
26538
|
-
/**
|
|
26539
|
-
* @param {string} expr a string with the passed in express
|
|
26540
|
-
* @returns Jsep
|
|
26541
|
-
*/
|
|
26542
|
-
constructor(expr) {
|
|
26543
|
-
// `index` stores the character number we are currently at
|
|
26544
|
-
// All of the gobbles below will modify `index` as we move along
|
|
26545
|
-
this.expr = expr;
|
|
26546
|
-
this.index = 0;
|
|
26547
|
-
}
|
|
26548
|
-
|
|
26549
|
-
/**
|
|
26550
|
-
* static top-level parser
|
|
26551
|
-
* @returns {jsep.Expression}
|
|
26552
|
-
*/
|
|
26553
|
-
static parse(expr) {
|
|
26554
|
-
return (new Jsep(expr)).parse();
|
|
26555
|
-
}
|
|
26556
|
-
|
|
26557
|
-
/**
|
|
26558
|
-
* Get the longest key length of any object
|
|
26559
|
-
* @param {object} obj
|
|
26560
|
-
* @returns {number}
|
|
26561
|
-
*/
|
|
26562
|
-
static getMaxKeyLen(obj) {
|
|
26563
|
-
return Math.max(0, ...Object.keys(obj).map(k => k.length));
|
|
26564
|
-
}
|
|
26565
|
-
|
|
26566
|
-
/**
|
|
26567
|
-
* `ch` is a character code in the next three functions
|
|
26568
|
-
* @param {number} ch
|
|
26569
|
-
* @returns {boolean}
|
|
26570
|
-
*/
|
|
26571
|
-
static isDecimalDigit(ch) {
|
|
26572
|
-
return (ch >= 48 && ch <= 57); // 0...9
|
|
26573
|
-
}
|
|
26574
|
-
|
|
26575
|
-
/**
|
|
26576
|
-
* Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.
|
|
26577
|
-
* @param {string} op_val
|
|
26578
|
-
* @returns {number}
|
|
26579
|
-
*/
|
|
26580
|
-
static binaryPrecedence(op_val) {
|
|
26581
|
-
return Jsep.binary_ops[op_val] || 0;
|
|
26582
|
-
}
|
|
26583
|
-
|
|
26584
|
-
/**
|
|
26585
|
-
* Looks for start of identifier
|
|
26586
|
-
* @param {number} ch
|
|
26587
|
-
* @returns {boolean}
|
|
26588
|
-
*/
|
|
26589
|
-
static isIdentifierStart(ch) {
|
|
26590
|
-
return (ch >= 65 && ch <= 90) || // A...Z
|
|
26591
|
-
(ch >= 97 && ch <= 122) || // a...z
|
|
26592
|
-
(ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)]) || // any non-ASCII that is not an operator
|
|
26593
|
-
(Jsep.additional_identifier_chars.has(String.fromCharCode(ch))); // additional characters
|
|
26594
|
-
}
|
|
26595
|
-
|
|
26596
|
-
/**
|
|
26597
|
-
* @param {number} ch
|
|
26598
|
-
* @returns {boolean}
|
|
26599
|
-
*/
|
|
26600
|
-
static isIdentifierPart(ch) {
|
|
26601
|
-
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
26602
|
-
}
|
|
26603
|
-
|
|
26604
|
-
/**
|
|
26605
|
-
* throw error at index of the expression
|
|
26606
|
-
* @param {string} message
|
|
26607
|
-
* @throws
|
|
26608
|
-
*/
|
|
26609
|
-
throwError(message) {
|
|
26610
|
-
const error = new Error(message + ' at character ' + this.index);
|
|
26611
|
-
error.index = this.index;
|
|
26612
|
-
error.description = message;
|
|
26613
|
-
throw error;
|
|
26614
|
-
}
|
|
26615
|
-
|
|
26616
|
-
/**
|
|
26617
|
-
* Run a given hook
|
|
26618
|
-
* @param {string} name
|
|
26619
|
-
* @param {jsep.Expression|false} [node]
|
|
26620
|
-
* @returns {?jsep.Expression}
|
|
26621
|
-
*/
|
|
26622
|
-
runHook(name, node) {
|
|
26623
|
-
if (Jsep.hooks[name]) {
|
|
26624
|
-
const env = { context: this, node };
|
|
26625
|
-
Jsep.hooks.run(name, env);
|
|
26626
|
-
return env.node;
|
|
26627
|
-
}
|
|
26628
|
-
return node;
|
|
26629
|
-
}
|
|
26630
|
-
|
|
26631
|
-
/**
|
|
26632
|
-
* Runs a given hook until one returns a node
|
|
26633
|
-
* @param {string} name
|
|
26634
|
-
* @returns {?jsep.Expression}
|
|
26635
|
-
*/
|
|
26636
|
-
searchHook(name) {
|
|
26637
|
-
if (Jsep.hooks[name]) {
|
|
26638
|
-
const env = { context: this };
|
|
26639
|
-
Jsep.hooks[name].find(function (callback) {
|
|
26640
|
-
callback.call(env.context, env);
|
|
26641
|
-
return env.node;
|
|
26642
|
-
});
|
|
26643
|
-
return env.node;
|
|
26644
|
-
}
|
|
26645
|
-
}
|
|
26646
|
-
|
|
26647
|
-
/**
|
|
26648
|
-
* Push `index` up to the next non-space character
|
|
26649
|
-
*/
|
|
26650
|
-
gobbleSpaces() {
|
|
26651
|
-
let ch = this.code;
|
|
26652
|
-
// Whitespace
|
|
26653
|
-
while (ch === Jsep.SPACE_CODE
|
|
26654
|
-
|| ch === Jsep.TAB_CODE
|
|
26655
|
-
|| ch === Jsep.LF_CODE
|
|
26656
|
-
|| ch === Jsep.CR_CODE) {
|
|
26657
|
-
ch = this.expr.charCodeAt(++this.index);
|
|
26658
|
-
}
|
|
26659
|
-
this.runHook('gobble-spaces');
|
|
26660
|
-
}
|
|
26661
|
-
|
|
26662
|
-
/**
|
|
26663
|
-
* Top-level method to parse all expressions and returns compound or single node
|
|
26664
|
-
* @returns {jsep.Expression}
|
|
26665
|
-
*/
|
|
26666
|
-
parse() {
|
|
26667
|
-
this.runHook('before-all');
|
|
26668
|
-
const nodes = this.gobbleExpressions();
|
|
26669
|
-
|
|
26670
|
-
// If there's only one expression just try returning the expression
|
|
26671
|
-
const node = nodes.length === 1
|
|
26672
|
-
? nodes[0]
|
|
26673
|
-
: {
|
|
26674
|
-
type: Jsep.COMPOUND,
|
|
26675
|
-
body: nodes
|
|
26676
|
-
};
|
|
26677
|
-
return this.runHook('after-all', node);
|
|
26678
|
-
}
|
|
26679
|
-
|
|
26680
|
-
/**
|
|
26681
|
-
* top-level parser (but can be reused within as well)
|
|
26682
|
-
* @param {number} [untilICode]
|
|
26683
|
-
* @returns {jsep.Expression[]}
|
|
26684
|
-
*/
|
|
26685
|
-
gobbleExpressions(untilICode) {
|
|
26686
|
-
let nodes = [], ch_i, node;
|
|
26687
|
-
|
|
26688
|
-
while (this.index < this.expr.length) {
|
|
26689
|
-
ch_i = this.code;
|
|
26690
|
-
|
|
26691
|
-
// Expressions can be separated by semicolons, commas, or just inferred without any
|
|
26692
|
-
// separators
|
|
26693
|
-
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
26694
|
-
this.index++; // ignore separators
|
|
26695
|
-
}
|
|
26696
|
-
else {
|
|
26697
|
-
// Try to gobble each expression individually
|
|
26698
|
-
if (node = this.gobbleExpression()) {
|
|
26699
|
-
nodes.push(node);
|
|
26700
|
-
// If we weren't able to find a binary expression and are out of room, then
|
|
26701
|
-
// the expression passed in probably has too much
|
|
26702
|
-
}
|
|
26703
|
-
else if (this.index < this.expr.length) {
|
|
26704
|
-
if (ch_i === untilICode) {
|
|
26705
|
-
break;
|
|
26706
|
-
}
|
|
26707
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
26708
|
-
}
|
|
26709
|
-
}
|
|
26710
|
-
}
|
|
26711
|
-
|
|
26712
|
-
return nodes;
|
|
26713
|
-
}
|
|
26714
|
-
|
|
26715
|
-
/**
|
|
26716
|
-
* The main parsing function.
|
|
26717
|
-
* @returns {?jsep.Expression}
|
|
26718
|
-
*/
|
|
26719
|
-
gobbleExpression() {
|
|
26720
|
-
const node = this.searchHook('gobble-expression') || this.gobbleBinaryExpression();
|
|
26721
|
-
this.gobbleSpaces();
|
|
26722
|
-
|
|
26723
|
-
return this.runHook('after-expression', node);
|
|
26724
|
-
}
|
|
26725
|
-
|
|
26726
|
-
/**
|
|
26727
|
-
* Search for the operation portion of the string (e.g. `+`, `===`)
|
|
26728
|
-
* Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)
|
|
26729
|
-
* and move down from 3 to 2 to 1 character until a matching binary operation is found
|
|
26730
|
-
* then, return that binary operation
|
|
26731
|
-
* @returns {string|boolean}
|
|
26732
|
-
*/
|
|
26733
|
-
gobbleBinaryOp() {
|
|
26734
|
-
this.gobbleSpaces();
|
|
26735
|
-
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
26736
|
-
let tc_len = to_check.length;
|
|
26737
|
-
|
|
26738
|
-
while (tc_len > 0) {
|
|
26739
|
-
// Don't accept a binary op when it is an identifier.
|
|
26740
|
-
// Binary ops that start with a identifier-valid character must be followed
|
|
26741
|
-
// by a non identifier-part valid character
|
|
26742
|
-
if (Jsep.binary_ops.hasOwnProperty(to_check) && (
|
|
26743
|
-
!Jsep.isIdentifierStart(this.code) ||
|
|
26744
|
-
(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))
|
|
26745
|
-
)) {
|
|
26746
|
-
this.index += tc_len;
|
|
26747
|
-
return to_check;
|
|
26748
|
-
}
|
|
26749
|
-
to_check = to_check.substr(0, --tc_len);
|
|
26750
|
-
}
|
|
26751
|
-
return false;
|
|
26752
|
-
}
|
|
26753
|
-
|
|
26754
|
-
/**
|
|
26755
|
-
* This function is responsible for gobbling an individual expression,
|
|
26756
|
-
* e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`
|
|
26757
|
-
* @returns {?jsep.BinaryExpression}
|
|
26758
|
-
*/
|
|
26759
|
-
gobbleBinaryExpression() {
|
|
26760
|
-
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
26761
|
-
|
|
26762
|
-
// First, try to get the leftmost thing
|
|
26763
|
-
// Then, check to see if there's a binary operator operating on that leftmost thing
|
|
26764
|
-
// Don't gobbleBinaryOp without a left-hand-side
|
|
26765
|
-
left = this.gobbleToken();
|
|
26766
|
-
if (!left) {
|
|
26767
|
-
return left;
|
|
26768
|
-
}
|
|
26769
|
-
biop = this.gobbleBinaryOp();
|
|
26770
|
-
|
|
26771
|
-
// If there wasn't a binary operator, just return the leftmost node
|
|
26772
|
-
if (!biop) {
|
|
26773
|
-
return left;
|
|
26774
|
-
}
|
|
26775
|
-
|
|
26776
|
-
// Otherwise, we need to start a stack to properly place the binary operations in their
|
|
26777
|
-
// precedence structure
|
|
26778
|
-
biop_info = { value: biop, prec: Jsep.binaryPrecedence(biop)};
|
|
26779
|
-
|
|
26780
|
-
right = this.gobbleToken();
|
|
26781
|
-
|
|
26782
|
-
if (!right) {
|
|
26783
|
-
this.throwError("Expected expression after " + biop);
|
|
26784
|
-
}
|
|
26785
|
-
|
|
26786
|
-
stack = [left, biop_info, right];
|
|
26787
|
-
|
|
26788
|
-
// Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm)
|
|
26789
|
-
while ((biop = this.gobbleBinaryOp())) {
|
|
26790
|
-
prec = Jsep.binaryPrecedence(biop);
|
|
26791
|
-
|
|
26792
|
-
if (prec === 0) {
|
|
26793
|
-
this.index -= biop.length;
|
|
26794
|
-
break;
|
|
26795
|
-
}
|
|
26796
|
-
|
|
26797
|
-
biop_info = { value: biop, prec };
|
|
26798
|
-
|
|
26799
|
-
cur_biop = biop;
|
|
26800
|
-
|
|
26801
|
-
// Reduce: make a binary expression from the three topmost entries.
|
|
26802
|
-
while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
|
|
26803
|
-
right = stack.pop();
|
|
26804
|
-
biop = stack.pop().value;
|
|
26805
|
-
left = stack.pop();
|
|
26806
|
-
node = {
|
|
26807
|
-
type: Jsep.BINARY_EXP,
|
|
26808
|
-
operator: biop,
|
|
26809
|
-
left,
|
|
26810
|
-
right
|
|
26811
|
-
};
|
|
26812
|
-
stack.push(node);
|
|
26813
|
-
}
|
|
26814
|
-
|
|
26815
|
-
node = this.gobbleToken();
|
|
26816
|
-
|
|
26817
|
-
if (!node) {
|
|
26818
|
-
this.throwError("Expected expression after " + cur_biop);
|
|
26819
|
-
}
|
|
26820
|
-
|
|
26821
|
-
stack.push(biop_info, node);
|
|
26822
|
-
}
|
|
26823
|
-
|
|
26824
|
-
i = stack.length - 1;
|
|
26825
|
-
node = stack[i];
|
|
26826
|
-
|
|
26827
|
-
while (i > 1) {
|
|
26828
|
-
node = {
|
|
26829
|
-
type: Jsep.BINARY_EXP,
|
|
26830
|
-
operator: stack[i - 1].value,
|
|
26831
|
-
left: stack[i - 2],
|
|
26832
|
-
right: node
|
|
26833
|
-
};
|
|
26834
|
-
i -= 2;
|
|
26835
|
-
}
|
|
26836
|
-
|
|
26837
|
-
return node;
|
|
26838
|
-
}
|
|
26839
|
-
|
|
26840
|
-
/**
|
|
26841
|
-
* An individual part of a binary expression:
|
|
26842
|
-
* e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis)
|
|
26843
|
-
* @returns {boolean|jsep.Expression}
|
|
26844
|
-
*/
|
|
26845
|
-
gobbleToken() {
|
|
26846
|
-
let ch, to_check, tc_len, node;
|
|
26847
|
-
|
|
26848
|
-
this.gobbleSpaces();
|
|
26849
|
-
node = this.searchHook('gobble-token');
|
|
26850
|
-
if (node) {
|
|
26851
|
-
return this.runHook('after-token', node);
|
|
26852
|
-
}
|
|
26853
|
-
|
|
26854
|
-
ch = this.code;
|
|
26855
|
-
|
|
26856
|
-
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
26857
|
-
// Char code 46 is a dot `.` which can start off a numeric literal
|
|
26858
|
-
return this.gobbleNumericLiteral();
|
|
26859
|
-
}
|
|
26860
|
-
|
|
26861
|
-
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
26862
|
-
// Single or double quotes
|
|
26863
|
-
node = this.gobbleStringLiteral();
|
|
26864
|
-
}
|
|
26865
|
-
else if (ch === Jsep.OBRACK_CODE) {
|
|
26866
|
-
node = this.gobbleArray();
|
|
26867
|
-
}
|
|
26868
|
-
else {
|
|
26869
|
-
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
26870
|
-
tc_len = to_check.length;
|
|
26871
|
-
|
|
26872
|
-
while (tc_len > 0) {
|
|
26873
|
-
// Don't accept an unary op when it is an identifier.
|
|
26874
|
-
// Unary ops that start with a identifier-valid character must be followed
|
|
26875
|
-
// by a non identifier-part valid character
|
|
26876
|
-
if (Jsep.unary_ops.hasOwnProperty(to_check) && (
|
|
26877
|
-
!Jsep.isIdentifierStart(this.code) ||
|
|
26878
|
-
(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))
|
|
26879
|
-
)) {
|
|
26880
|
-
this.index += tc_len;
|
|
26881
|
-
const argument = this.gobbleToken();
|
|
26882
|
-
if (!argument) {
|
|
26883
|
-
this.throwError('missing unaryOp argument');
|
|
26884
|
-
}
|
|
26885
|
-
return this.runHook('after-token', {
|
|
26886
|
-
type: Jsep.UNARY_EXP,
|
|
26887
|
-
operator: to_check,
|
|
26888
|
-
argument,
|
|
26889
|
-
prefix: true
|
|
26890
|
-
});
|
|
26891
|
-
}
|
|
26892
|
-
|
|
26893
|
-
to_check = to_check.substr(0, --tc_len);
|
|
26894
|
-
}
|
|
26895
|
-
|
|
26896
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
26897
|
-
node = this.gobbleIdentifier();
|
|
26898
|
-
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
26899
|
-
node = {
|
|
26900
|
-
type: Jsep.LITERAL,
|
|
26901
|
-
value: Jsep.literals[node.name],
|
|
26902
|
-
raw: node.name,
|
|
26903
|
-
};
|
|
26904
|
-
}
|
|
26905
|
-
else if (node.name === Jsep.this_str) {
|
|
26906
|
-
node = { type: Jsep.THIS_EXP };
|
|
26907
|
-
}
|
|
26908
|
-
}
|
|
26909
|
-
else if (ch === Jsep.OPAREN_CODE) { // open parenthesis
|
|
26910
|
-
node = this.gobbleGroup();
|
|
26911
|
-
}
|
|
26912
|
-
}
|
|
26913
|
-
|
|
26914
|
-
if (!node) {
|
|
26915
|
-
return this.runHook('after-token', false);
|
|
26916
|
-
}
|
|
26917
|
-
|
|
26918
|
-
node = this.gobbleTokenProperty(node);
|
|
26919
|
-
return this.runHook('after-token', node);
|
|
26920
|
-
}
|
|
26921
|
-
|
|
26922
|
-
/**
|
|
26923
|
-
* Gobble properties of of identifiers/strings/arrays/groups.
|
|
26924
|
-
* e.g. `foo`, `bar.baz`, `foo['bar'].baz`
|
|
26925
|
-
* It also gobbles function calls:
|
|
26926
|
-
* e.g. `Math.acos(obj.angle)`
|
|
26927
|
-
* @param {jsep.Expression} node
|
|
26928
|
-
* @returns {jsep.Expression}
|
|
26929
|
-
*/
|
|
26930
|
-
gobbleTokenProperty(node) {
|
|
26931
|
-
this.gobbleSpaces();
|
|
26932
|
-
|
|
26933
|
-
let ch = this.code;
|
|
26934
|
-
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE) {
|
|
26935
|
-
this.index++;
|
|
26936
|
-
|
|
26937
|
-
if (ch === Jsep.PERIOD_CODE) {
|
|
26938
|
-
this.gobbleSpaces();
|
|
26939
|
-
node = {
|
|
26940
|
-
type: Jsep.MEMBER_EXP,
|
|
26941
|
-
computed: false,
|
|
26942
|
-
object: node,
|
|
26943
|
-
property: this.gobbleIdentifier(),
|
|
26944
|
-
};
|
|
26945
|
-
}
|
|
26946
|
-
else if (ch === Jsep.OBRACK_CODE) {
|
|
26947
|
-
node = {
|
|
26948
|
-
type: Jsep.MEMBER_EXP,
|
|
26949
|
-
computed: true,
|
|
26950
|
-
object: node,
|
|
26951
|
-
property: this.gobbleExpression()
|
|
26952
|
-
};
|
|
26953
|
-
this.gobbleSpaces();
|
|
26954
|
-
ch = this.code;
|
|
26955
|
-
if (ch !== Jsep.CBRACK_CODE) {
|
|
26956
|
-
this.throwError('Unclosed [');
|
|
26957
|
-
}
|
|
26958
|
-
this.index++;
|
|
26959
|
-
}
|
|
26960
|
-
else if (ch === Jsep.OPAREN_CODE) {
|
|
26961
|
-
// A function call is being made; gobble all the arguments
|
|
26962
|
-
node = {
|
|
26963
|
-
type: Jsep.CALL_EXP,
|
|
26964
|
-
'arguments': this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
26965
|
-
callee: node
|
|
26966
|
-
};
|
|
26967
|
-
}
|
|
26968
|
-
this.gobbleSpaces();
|
|
26969
|
-
ch = this.code;
|
|
26970
|
-
}
|
|
26971
|
-
|
|
26972
|
-
return node;
|
|
26973
|
-
}
|
|
26974
|
-
|
|
26975
|
-
/**
|
|
26976
|
-
* Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to
|
|
26977
|
-
* keep track of everything in the numeric literal and then calling `parseFloat` on that string
|
|
26978
|
-
* @returns {jsep.Literal}
|
|
26979
|
-
*/
|
|
26980
|
-
gobbleNumericLiteral() {
|
|
26981
|
-
let number = '', ch, chCode;
|
|
26982
|
-
|
|
26983
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
26984
|
-
number += this.expr.charAt(this.index++);
|
|
26985
|
-
}
|
|
26986
|
-
|
|
26987
|
-
if (this.code === Jsep.PERIOD_CODE) { // can start with a decimal marker
|
|
26988
|
-
number += this.expr.charAt(this.index++);
|
|
26989
|
-
|
|
26990
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
26991
|
-
number += this.expr.charAt(this.index++);
|
|
26992
|
-
}
|
|
26993
|
-
}
|
|
26994
|
-
|
|
26995
|
-
ch = this.char;
|
|
26996
|
-
|
|
26997
|
-
if (ch === 'e' || ch === 'E') { // exponent marker
|
|
26998
|
-
number += this.expr.charAt(this.index++);
|
|
26999
|
-
ch = this.char;
|
|
27000
|
-
|
|
27001
|
-
if (ch === '+' || ch === '-') { // exponent sign
|
|
27002
|
-
number += this.expr.charAt(this.index++);
|
|
27003
|
-
}
|
|
27004
|
-
|
|
27005
|
-
while (Jsep.isDecimalDigit(this.code)) { // exponent itself
|
|
27006
|
-
number += this.expr.charAt(this.index++);
|
|
27007
|
-
}
|
|
27008
|
-
|
|
27009
|
-
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1)) ) {
|
|
27010
|
-
this.throwError('Expected exponent (' + number + this.char + ')');
|
|
27011
|
-
}
|
|
27012
|
-
}
|
|
27013
|
-
|
|
27014
|
-
chCode = this.code;
|
|
27015
|
-
|
|
27016
|
-
// Check to make sure this isn't a variable name that start with a number (123abc)
|
|
27017
|
-
if (Jsep.isIdentifierStart(chCode)) {
|
|
27018
|
-
this.throwError('Variable names cannot start with a number (' +
|
|
27019
|
-
number + this.char + ')');
|
|
27020
|
-
}
|
|
27021
|
-
else if (chCode === Jsep.PERIOD_CODE || (number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE)) {
|
|
27022
|
-
this.throwError('Unexpected period');
|
|
27023
|
-
}
|
|
27024
|
-
|
|
27025
|
-
return {
|
|
27026
|
-
type: Jsep.LITERAL,
|
|
27027
|
-
value: parseFloat(number),
|
|
27028
|
-
raw: number
|
|
27029
|
-
};
|
|
27030
|
-
}
|
|
27031
|
-
|
|
27032
|
-
/**
|
|
27033
|
-
* Parses a string literal, staring with single or double quotes with basic support for escape codes
|
|
27034
|
-
* e.g. `"hello world"`, `'this is\nJSEP'`
|
|
27035
|
-
* @returns {jsep.Literal}
|
|
27036
|
-
*/
|
|
27037
|
-
gobbleStringLiteral() {
|
|
27038
|
-
let str = '';
|
|
27039
|
-
let quote = this.expr.charAt(this.index++);
|
|
27040
|
-
let closed = false;
|
|
27041
|
-
|
|
27042
|
-
while (this.index < this.expr.length) {
|
|
27043
|
-
let ch = this.expr.charAt(this.index++);
|
|
27044
|
-
|
|
27045
|
-
if (ch === quote) {
|
|
27046
|
-
closed = true;
|
|
27047
|
-
break;
|
|
27048
|
-
}
|
|
27049
|
-
else if (ch === '\\') {
|
|
27050
|
-
// Check for all of the common escape codes
|
|
27051
|
-
ch = this.expr.charAt(this.index++);
|
|
27052
|
-
|
|
27053
|
-
switch (ch) {
|
|
27054
|
-
case 'n': str += '\n'; break;
|
|
27055
|
-
case 'r': str += '\r'; break;
|
|
27056
|
-
case 't': str += '\t'; break;
|
|
27057
|
-
case 'b': str += '\b'; break;
|
|
27058
|
-
case 'f': str += '\f'; break;
|
|
27059
|
-
case 'v': str += '\x0B'; break;
|
|
27060
|
-
default : str += ch;
|
|
27061
|
-
}
|
|
27062
|
-
}
|
|
27063
|
-
else {
|
|
27064
|
-
str += ch;
|
|
27065
|
-
}
|
|
27066
|
-
}
|
|
27067
|
-
|
|
27068
|
-
if (!closed) {
|
|
27069
|
-
this.throwError('Unclosed quote after "' + str + '"');
|
|
27070
|
-
}
|
|
27071
|
-
|
|
27072
|
-
return {
|
|
27073
|
-
type: Jsep.LITERAL,
|
|
27074
|
-
value: str,
|
|
27075
|
-
raw: quote + str + quote
|
|
27076
|
-
};
|
|
27077
|
-
}
|
|
27078
|
-
|
|
27079
|
-
/**
|
|
27080
|
-
* Gobbles only identifiers
|
|
27081
|
-
* e.g.: `foo`, `_value`, `$x1`
|
|
27082
|
-
* Also, this function checks if that identifier is a literal:
|
|
27083
|
-
* (e.g. `true`, `false`, `null`) or `this`
|
|
27084
|
-
* @returns {jsep.Identifier}
|
|
27085
|
-
*/
|
|
27086
|
-
gobbleIdentifier() {
|
|
27087
|
-
let ch = this.code, start = this.index;
|
|
27088
|
-
|
|
27089
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
27090
|
-
this.index++;
|
|
27091
|
-
}
|
|
27092
|
-
else {
|
|
27093
|
-
this.throwError('Unexpected ' + this.char);
|
|
27094
|
-
}
|
|
27095
|
-
|
|
27096
|
-
while (this.index < this.expr.length) {
|
|
27097
|
-
ch = this.code;
|
|
27098
|
-
|
|
27099
|
-
if (Jsep.isIdentifierPart(ch)) {
|
|
27100
|
-
this.index++;
|
|
27101
|
-
}
|
|
27102
|
-
else {
|
|
27103
|
-
break;
|
|
27104
|
-
}
|
|
27105
|
-
}
|
|
27106
|
-
return {
|
|
27107
|
-
type: Jsep.IDENTIFIER,
|
|
27108
|
-
name: this.expr.slice(start, this.index),
|
|
27109
|
-
};
|
|
27110
|
-
}
|
|
27111
|
-
|
|
27112
|
-
/**
|
|
27113
|
-
* Gobbles a list of arguments within the context of a function call
|
|
27114
|
-
* or array literal. This function also assumes that the opening character
|
|
27115
|
-
* `(` or `[` has already been gobbled, and gobbles expressions and commas
|
|
27116
|
-
* until the terminator character `)` or `]` is encountered.
|
|
27117
|
-
* e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`
|
|
27118
|
-
* @param {number} termination
|
|
27119
|
-
* @returns {jsep.Expression[]}
|
|
27120
|
-
*/
|
|
27121
|
-
gobbleArguments(termination) {
|
|
27122
|
-
const args = [];
|
|
27123
|
-
let closed = false;
|
|
27124
|
-
let separator_count = 0;
|
|
27125
|
-
|
|
27126
|
-
while (this.index < this.expr.length) {
|
|
27127
|
-
this.gobbleSpaces();
|
|
27128
|
-
let ch_i = this.code;
|
|
27129
|
-
|
|
27130
|
-
if (ch_i === termination) { // done parsing
|
|
27131
|
-
closed = true;
|
|
27132
|
-
this.index++;
|
|
27133
|
-
|
|
27134
|
-
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length){
|
|
27135
|
-
this.throwError('Unexpected token ' + String.fromCharCode(termination));
|
|
27136
|
-
}
|
|
27137
|
-
|
|
27138
|
-
break;
|
|
27139
|
-
}
|
|
27140
|
-
else if (ch_i === Jsep.COMMA_CODE) { // between expressions
|
|
27141
|
-
this.index++;
|
|
27142
|
-
separator_count++;
|
|
27143
|
-
|
|
27144
|
-
if (separator_count !== args.length) { // missing argument
|
|
27145
|
-
if (termination === Jsep.CPAREN_CODE) {
|
|
27146
|
-
this.throwError('Unexpected token ,');
|
|
27147
|
-
}
|
|
27148
|
-
else if (termination === Jsep.CBRACK_CODE) {
|
|
27149
|
-
for (let arg = args.length; arg < separator_count; arg++) {
|
|
27150
|
-
args.push(null);
|
|
27151
|
-
}
|
|
27152
|
-
}
|
|
27153
|
-
}
|
|
27154
|
-
}
|
|
27155
|
-
else if (args.length !== separator_count && separator_count !== 0) {
|
|
27156
|
-
// NOTE: `&& separator_count !== 0` allows for either all commas, or all spaces as arguments
|
|
27157
|
-
this.throwError('Expected comma');
|
|
27158
|
-
}
|
|
27159
|
-
else {
|
|
27160
|
-
const node = this.gobbleExpression();
|
|
27161
|
-
|
|
27162
|
-
if (!node || node.type === Jsep.COMPOUND) {
|
|
27163
|
-
this.throwError('Expected comma');
|
|
27164
|
-
}
|
|
27165
|
-
|
|
27166
|
-
args.push(node);
|
|
27167
|
-
}
|
|
27168
|
-
}
|
|
27169
|
-
|
|
27170
|
-
if (!closed) {
|
|
27171
|
-
this.throwError('Expected ' + String.fromCharCode(termination));
|
|
27172
|
-
}
|
|
27173
|
-
|
|
27174
|
-
return args;
|
|
27175
|
-
}
|
|
27176
|
-
|
|
27177
|
-
/**
|
|
27178
|
-
* Responsible for parsing a group of things within parentheses `()`
|
|
27179
|
-
* that have no identifier in front (so not a function call)
|
|
27180
|
-
* This function assumes that it needs to gobble the opening parenthesis
|
|
27181
|
-
* and then tries to gobble everything within that parenthesis, assuming
|
|
27182
|
-
* that the next thing it should see is the close parenthesis. If not,
|
|
27183
|
-
* then the expression probably doesn't have a `)`
|
|
27184
|
-
* @returns {boolean|jsep.Expression}
|
|
27185
|
-
*/
|
|
27186
|
-
gobbleGroup() {
|
|
27187
|
-
this.index++;
|
|
27188
|
-
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
27189
|
-
if (this.code === Jsep.CPAREN_CODE) {
|
|
27190
|
-
this.index++;
|
|
27191
|
-
if (nodes.length === 1) {
|
|
27192
|
-
return nodes[0];
|
|
27193
|
-
}
|
|
27194
|
-
else if (!nodes.length) {
|
|
27195
|
-
return false;
|
|
27196
|
-
}
|
|
27197
|
-
else {
|
|
27198
|
-
return {
|
|
27199
|
-
type: Jsep.SEQUENCE_EXP,
|
|
27200
|
-
expressions: nodes,
|
|
27201
|
-
};
|
|
27202
|
-
}
|
|
27203
|
-
}
|
|
27204
|
-
else {
|
|
27205
|
-
this.throwError('Unclosed (');
|
|
27206
|
-
}
|
|
27207
|
-
}
|
|
27208
|
-
|
|
27209
|
-
/**
|
|
27210
|
-
* Responsible for parsing Array literals `[1, 2, 3]`
|
|
27211
|
-
* This function assumes that it needs to gobble the opening bracket
|
|
27212
|
-
* and then tries to gobble the expressions as arguments.
|
|
27213
|
-
* @returns {jsep.ArrayExpression}
|
|
27214
|
-
*/
|
|
27215
|
-
gobbleArray() {
|
|
27216
|
-
this.index++;
|
|
27217
|
-
|
|
27218
|
-
return {
|
|
27219
|
-
type: Jsep.ARRAY_EXP,
|
|
27220
|
-
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
27221
|
-
};
|
|
27222
|
-
}
|
|
27223
|
-
}
|
|
27224
|
-
|
|
27225
|
-
// Static fields:
|
|
27226
|
-
const hooks = new Hooks();
|
|
27227
|
-
Object.assign(Jsep, {
|
|
27228
|
-
hooks,
|
|
27229
|
-
plugins: new Plugins(Jsep),
|
|
27230
|
-
|
|
27231
|
-
// Node Types
|
|
27232
|
-
// ----------
|
|
27233
|
-
// This is the full set of types that any JSEP node can be.
|
|
27234
|
-
// Store them here to save space when minified
|
|
27235
|
-
COMPOUND: 'Compound',
|
|
27236
|
-
SEQUENCE_EXP: 'SequenceExpression',
|
|
27237
|
-
IDENTIFIER: 'Identifier',
|
|
27238
|
-
MEMBER_EXP: 'MemberExpression',
|
|
27239
|
-
LITERAL: 'Literal',
|
|
27240
|
-
THIS_EXP: 'ThisExpression',
|
|
27241
|
-
CALL_EXP: 'CallExpression',
|
|
27242
|
-
UNARY_EXP: 'UnaryExpression',
|
|
27243
|
-
BINARY_EXP: 'BinaryExpression',
|
|
27244
|
-
ARRAY_EXP: 'ArrayExpression',
|
|
27245
|
-
|
|
27246
|
-
TAB_CODE: 9,
|
|
27247
|
-
LF_CODE: 10,
|
|
27248
|
-
CR_CODE: 13,
|
|
27249
|
-
SPACE_CODE: 32,
|
|
27250
|
-
PERIOD_CODE: 46, // '.'
|
|
27251
|
-
COMMA_CODE: 44, // ','
|
|
27252
|
-
SQUOTE_CODE: 39, // single quote
|
|
27253
|
-
DQUOTE_CODE: 34, // double quotes
|
|
27254
|
-
OPAREN_CODE: 40, // (
|
|
27255
|
-
CPAREN_CODE: 41, // )
|
|
27256
|
-
OBRACK_CODE: 91, // [
|
|
27257
|
-
CBRACK_CODE: 93, // ]
|
|
27258
|
-
QUMARK_CODE: 63, // ?
|
|
27259
|
-
SEMCOL_CODE: 59, // ;
|
|
27260
|
-
COLON_CODE: 58, // :
|
|
27261
|
-
|
|
27262
|
-
|
|
27263
|
-
// Operations
|
|
27264
|
-
// ----------
|
|
27265
|
-
// Use a quickly-accessible map to store all of the unary operators
|
|
27266
|
-
// Values are set to `1` (it really doesn't matter)
|
|
27267
|
-
unary_ops: {
|
|
27268
|
-
'-': 1,
|
|
27269
|
-
'!': 1,
|
|
27270
|
-
'~': 1,
|
|
27271
|
-
'+': 1
|
|
27272
|
-
},
|
|
27273
|
-
|
|
27274
|
-
// Also use a map for the binary operations but set their values to their
|
|
27275
|
-
// binary precedence for quick reference (higher number = higher precedence)
|
|
27276
|
-
// see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
|
|
27277
|
-
binary_ops: {
|
|
27278
|
-
'||': 1, '&&': 2, '|': 3, '^': 4, '&': 5,
|
|
27279
|
-
'==': 6, '!=': 6, '===': 6, '!==': 6,
|
|
27280
|
-
'<': 7, '>': 7, '<=': 7, '>=': 7,
|
|
27281
|
-
'<<': 8, '>>': 8, '>>>': 8,
|
|
27282
|
-
'+': 9, '-': 9,
|
|
27283
|
-
'*': 10, '/': 10, '%': 10
|
|
27284
|
-
},
|
|
27285
|
-
|
|
27286
|
-
// Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)
|
|
27287
|
-
additional_identifier_chars: new Set(['$', '_']),
|
|
27288
|
-
|
|
27289
|
-
// Literals
|
|
27290
|
-
// ----------
|
|
27291
|
-
// Store the values to return for the various literals we may encounter
|
|
27292
|
-
literals: {
|
|
27293
|
-
'true': true,
|
|
27294
|
-
'false': false,
|
|
27295
|
-
'null': null
|
|
27296
|
-
},
|
|
27297
|
-
|
|
27298
|
-
// Except for `this`, which is special. This could be changed to something like `'self'` as well
|
|
27299
|
-
this_str: 'this',
|
|
27300
|
-
});
|
|
27301
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
27302
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
27303
|
-
|
|
27304
|
-
// Backward Compatibility:
|
|
27305
|
-
const jsep = expr => (new Jsep(expr)).parse();
|
|
27306
|
-
const staticMethods = Object.getOwnPropertyNames(Jsep);
|
|
27307
|
-
staticMethods
|
|
27308
|
-
.slice(staticMethods.indexOf('version'))
|
|
27309
|
-
.forEach((m) => {
|
|
27310
|
-
if (m !== 'name') {
|
|
27311
|
-
jsep[m] = Jsep[m];
|
|
27312
|
-
}
|
|
27313
|
-
});
|
|
27314
|
-
jsep.Jsep = Jsep; // allows for const { Jsep } = require('jsep');
|
|
27315
|
-
|
|
27316
|
-
const CONDITIONAL_EXP = 'ConditionalExpression';
|
|
27317
|
-
|
|
27318
|
-
var ternary = {
|
|
27319
|
-
name: 'ternary',
|
|
27320
|
-
|
|
27321
|
-
init(jsep) {
|
|
27322
|
-
// Ternary expression: test ? consequent : alternate
|
|
27323
|
-
jsep.hooks.add('after-expression', function gobbleTernary(env) {
|
|
27324
|
-
if (env.node && this.code === jsep.QUMARK_CODE) {
|
|
27325
|
-
this.index++;
|
|
27326
|
-
const test = env.node;
|
|
27327
|
-
const consequent = this.gobbleExpression();
|
|
27328
|
-
|
|
27329
|
-
if (!consequent) {
|
|
27330
|
-
this.throwError('Expected expression');
|
|
27331
|
-
}
|
|
27332
|
-
|
|
27333
|
-
this.gobbleSpaces();
|
|
27334
|
-
|
|
27335
|
-
if (this.code === jsep.COLON_CODE) {
|
|
27336
|
-
this.index++;
|
|
27337
|
-
const alternate = this.gobbleExpression();
|
|
27338
|
-
|
|
27339
|
-
if (!alternate) {
|
|
27340
|
-
this.throwError('Expected expression');
|
|
27341
|
-
}
|
|
27342
|
-
env.node = {
|
|
27343
|
-
type: CONDITIONAL_EXP,
|
|
27344
|
-
test,
|
|
27345
|
-
consequent,
|
|
27346
|
-
alternate,
|
|
27347
|
-
};
|
|
27348
|
-
}
|
|
27349
|
-
// if binary operator is custom-added (i.e. object plugin), then correct it to a ternary node:
|
|
27350
|
-
else if (consequent.operator === ':') {
|
|
27351
|
-
env.node = {
|
|
27352
|
-
type: CONDITIONAL_EXP,
|
|
27353
|
-
test,
|
|
27354
|
-
consequent: consequent.left,
|
|
27355
|
-
alternate: consequent.right,
|
|
27356
|
-
};
|
|
27357
|
-
}
|
|
27358
|
-
else {
|
|
27359
|
-
this.throwError('Expected :');
|
|
27360
|
-
}
|
|
27361
|
-
}
|
|
27362
|
-
});
|
|
27363
|
-
},
|
|
27364
|
-
};
|
|
27365
|
-
|
|
27366
|
-
// Add default plugins:
|
|
27367
|
-
|
|
27368
|
-
jsep.plugins.register(ternary);
|
|
27369
|
-
|
|
27370
|
-
module.exports = jsep;
|
|
27371
|
-
//# sourceMappingURL=jsep.cjs.js.map
|
|
27372
|
-
|
|
27373
|
-
|
|
27374
26274
|
/***/ }),
|
|
27375
26275
|
|
|
27376
26276
|
/***/ "../language/node_modules/ses/dist/ses.cjs":
|
|
@@ -135314,6 +134214,16 @@ module.exports = require("fs");;
|
|
|
135314
134214
|
|
|
135315
134215
|
/***/ }),
|
|
135316
134216
|
|
|
134217
|
+
/***/ "jsep":
|
|
134218
|
+
/*!***********************!*\
|
|
134219
|
+
!*** external "jsep" ***!
|
|
134220
|
+
\***********************/
|
|
134221
|
+
/***/ ((module) => {
|
|
134222
|
+
|
|
134223
|
+
module.exports = require("jsep");;
|
|
134224
|
+
|
|
134225
|
+
/***/ }),
|
|
134226
|
+
|
|
135317
134227
|
/***/ "jszip":
|
|
135318
134228
|
/*!************************!*\
|
|
135319
134229
|
!*** external "jszip" ***!
|