@builder.io/sdk-svelte 0.5.3 → 0.5.5

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.
Files changed (32) hide show
  1. package/package/--package.json +4 -4
  2. package/package/CHANGELOG.md +9 -0
  3. package/package/functions/evaluate/acorn-interpreter.js +3111 -0
  4. package/package/functions/evaluate/evaluate.js +1 -19
  5. package/package/functions/evaluate/non-node-runtime/index.d.ts +6 -0
  6. package/package/functions/evaluate/non-node-runtime/index.js +22 -0
  7. package/package/functions/evaluate/{non-node-runtime.d.ts → non-node-runtime/non-node-runtime.d.ts} +1 -1
  8. package/package/functions/evaluate/{non-node-runtime.js → non-node-runtime/non-node-runtime.js} +3 -3
  9. package/package/helpers/preview-lru-cache/get.d.ts +2 -1
  10. package/package/helpers/preview-lru-cache/get.js +2 -6
  11. package/package/helpers/preview-lru-cache/helpers.d.ts +0 -1
  12. package/package/helpers/preview-lru-cache/helpers.js +1 -9
  13. package/package/helpers/preview-lru-cache/init.js +1 -10
  14. package/package/helpers/preview-lru-cache/set.js +0 -4
  15. package/package/helpers/preview-lru-cache/types.d.ts +0 -12
  16. package/package/helpers/preview-lru-cache/types.js +1 -6
  17. package/package.json +1 -1
  18. package/src/functions/evaluate/acorn-interpreter.ts +2891 -0
  19. package/src/functions/evaluate/evaluate.ts +1 -20
  20. package/src/functions/evaluate/non-node-runtime/index.ts +23 -0
  21. package/src/functions/evaluate/{non-node-runtime.ts → non-node-runtime/non-node-runtime.ts} +4 -4
  22. package/src/helpers/preview-lru-cache/get.ts +3 -7
  23. package/src/helpers/preview-lru-cache/helpers.ts +0 -9
  24. package/src/helpers/preview-lru-cache/init.ts +1 -11
  25. package/src/helpers/preview-lru-cache/set.ts +0 -6
  26. package/src/helpers/preview-lru-cache/types.ts +0 -12
  27. package/package/functions/evaluate/acorn.d.ts +0 -0
  28. package/package/functions/evaluate/acorn.js +0 -2433
  29. package/package/functions/evaluate/interpreter.js +0 -3853
  30. package/src/functions/evaluate/acorn.ts +0 -2501
  31. package/src/functions/evaluate/interpreter.ts +0 -3887
  32. /package/package/functions/evaluate/{interpreter.d.ts → acorn-interpreter.d.ts} +0 -0
@@ -1,2433 +0,0 @@
1
- "use strict";
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
4
- /* eslint-disable */
5
- /**
6
- * Copied from source: https://github.com/NeilFraser/JS-Interpreter/blob/master/acorn.js
7
- * Any changes made here have a comment above them starting with: "// BUILDER.IO"
8
- */
9
- /**
10
- * @license
11
- * Copyright 2012 Marijn Haverbeke
12
- * SPDX-License-Identifier: MIT
13
- */
14
- // Acorn is a tiny, fast JavaScript parser written in JavaScript.
15
- //
16
- // Acorn was written by Marijn Haverbeke and released under an MIT
17
- // license. The Unicode regexps (for identifiers and whitespace) were
18
- // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
19
- //
20
- // Git repositories for Acorn are available at
21
- //
22
- // http://marijnhaverbeke.nl/git/acorn
23
- // https://github.com/marijnh/acorn.git
24
- //
25
- // Please use the [github bug tracker][ghbt] to report issues.
26
- //
27
- // [ghbt]: https://github.com/marijnh/acorn/issues
28
- //
29
- // This file defines the main parser interface. The library also comes
30
- // with a [error-tolerant parser][dammit] and an
31
- // [abstract syntax tree walker][walk], defined in other files.
32
- //
33
- // [dammit]: acorn_loose.js
34
- // [walk]: util/walk.js
35
- (function (root, mod) {
36
- if (typeof exports === 'object' && typeof module === 'object')
37
- return mod(exports); // CommonJS
38
- if (typeof define === 'function' && define.amd)
39
- return define(['exports'], mod); // AMD
40
- mod(root.acorn || (root.acorn = {})); // Plain browser env
41
- })(this, function (exports) {
42
- exports.version = '0.5.0';
43
- // Plus additional edits marked with 'JS-Interpreter change' comments.
44
- // JS-Interpreter change:
45
- // Added JSDoc type definitions.
46
- // -- Neil Fraser, July 2023.
47
- // JS-Interpreter change:
48
- // No longer exporting defaultOptions, getLineInfo, tokenize, tokTypes,
49
- // isIdentifierStart, and isIdentifierChar. Not used by JS-Interpreter.
50
- // -- Neil Fraser, February 2023.
51
- // The main exported interface (under `self.acorn` when in the
52
- // browser) is a `parse` function that takes a code string and
53
- // returns an abstract syntax tree as specified by [Mozilla parser
54
- // API][api], with the caveat that the SpiderMonkey-specific syntax
55
- // (`let`, `yield`, inline XML, etc) is not recognized.
56
- //
57
- // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
58
- /** @type {!Object|undefined} */
59
- var options;
60
- /** @type {string} */
61
- var input = '';
62
- /** @type {number|undefined} */
63
- var inputLen;
64
- /** @type {*} */
65
- var sourceFile;
66
- /**
67
- * @param {string} inpt
68
- * @param {Object=} opts
69
- * @returns
70
- */
71
- exports.parse = function (inpt, opts) {
72
- input = String(inpt);
73
- inputLen = input.length;
74
- setOptions(opts);
75
- initTokenState();
76
- return parseTopLevel(options.program);
77
- };
78
- // A second optional argument can be given to further configure
79
- // the parser process. These options are recognized:
80
- var defaultOptions = {
81
- // JS-Interpreter change:
82
- // `ecmaVersion` option has been removed along with all cases where
83
- // it is checked. In this version of Acorn it was limited to 3 or 5,
84
- // and there's no use case for 3 with JS-Interpreter.
85
- // -- Neil Fraser, December 2022.
86
- // Turn on `strictSemicolons` to prevent the parser from doing
87
- // automatic semicolon insertion.
88
- strictSemicolons: false,
89
- // When `allowTrailingCommas` is false, the parser will not allow
90
- // trailing commas in array and object literals.
91
- allowTrailingCommas: true,
92
- // By default, reserved words are not enforced. Enable
93
- // `forbidReserved` to enforce them. When this option has the
94
- // value "everywhere", reserved words and keywords can also not be
95
- // used as property names.
96
- forbidReserved: false,
97
- // When enabled, a return at the top level is not considered an
98
- // error.
99
- allowReturnOutsideFunction: false,
100
- // When `locations` is on, `loc` properties holding objects with
101
- // `start` and `end` properties in `{line, column}` form (with
102
- // line being 1-based and column 0-based) will be attached to the
103
- // nodes.
104
- locations: false,
105
- // A function can be passed as `onComment` option, which will
106
- // cause Acorn to call that function with `(block, text, start,
107
- // end)` parameters whenever a comment is skipped. `block` is a
108
- // boolean indicating whether this is a block (`/* */`) comment,
109
- // `text` is the content of the comment, and `start` and `end` are
110
- // character offsets that denote the start and end of the comment.
111
- // When the `locations` option is on, two more parameters are
112
- // passed, the full `{line, column}` locations of the start and
113
- // end of the comments. Note that you are not allowed to call the
114
- // parser from the callback—that will corrupt its internal state.
115
- onComment: null,
116
- // Nodes have their start and end characters offsets recorded in
117
- // `start` and `end` properties (directly on the node, rather than
118
- // the `loc` object, which holds line/column data. To also add a
119
- // [semi-standardized][range] `range` property holding a `[start,
120
- // end]` array with the same numbers, set the `ranges` option to
121
- // `true`.
122
- //
123
- // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
124
- ranges: false,
125
- // It is possible to parse multiple files into a single AST by
126
- // passing the tree produced by parsing the first file as
127
- // `program` option in subsequent parses. This will add the
128
- // toplevel forms of the parsed file to the `Program` (top) node
129
- // of an existing parse tree.
130
- program: null,
131
- // When `locations` is on, you can pass this to record the source
132
- // file in every node's `loc` object.
133
- sourceFile: null,
134
- // This value, if given, is stored in every node, whether
135
- // `locations` is on or off.
136
- directSourceFile: null
137
- };
138
- /**
139
- * @param {Object|undefined} opts
140
- */
141
- function setOptions(opts) {
142
- options = opts || {};
143
- for (var opt in defaultOptions) {
144
- if (!Object.prototype.hasOwnProperty.call(options, opt)) {
145
- options[opt] = defaultOptions[opt];
146
- }
147
- }
148
- sourceFile = options.sourceFile;
149
- }
150
- /**
151
- * The `getLineInfo` function is mostly useful when the
152
- * `locations` option is off (for performance reasons) and you
153
- * want to find the line/column position for a given character
154
- * offset. `input` should be the code string that the offset refers
155
- * into.
156
- *
157
- * @param {string} input
158
- * @param {number} offset
159
- * @returns {!Object}
160
- */
161
- var getLineInfo = function (input, offset) {
162
- for (var line = 1, cur = 0;;) {
163
- lineBreak.lastIndex = cur;
164
- var match = lineBreak.exec(input);
165
- if (match && match.index < offset) {
166
- ++line;
167
- cur = match.index + match[0].length;
168
- }
169
- else {
170
- break;
171
- }
172
- }
173
- return {
174
- line,
175
- column: offset - cur
176
- };
177
- };
178
- // JS-Interpreter change:
179
- // tokenize function never used. Removed.
180
- // -- Neil Fraser, February 2023.
181
- // State is kept in (closure-)global variables. We already saw the
182
- // `options`, `input`, and `inputLen` variables above.
183
- /**
184
- * The current position of the tokenizer in the input.
185
- * @type {number}
186
- */
187
- var tokPos = 0;
188
- /**
189
- * The start offset of the current token.
190
- * @type {number}
191
- */
192
- var tokStart = 0;
193
- /**
194
- * The end offset of the current token.
195
- * @type {number}
196
- */
197
- var tokEnd = 0;
198
- /**
199
- * When `options.locations` is true, holds object
200
- * containing the token's start line/column pairs.
201
- * @type {!line_loc_t|undefined}
202
- */
203
- var tokStartLoc;
204
- /**
205
- * When `options.locations` is true, holds object
206
- * containing the token's end line/column pairs.
207
- * @type {!line_loc_t|undefined}
208
- */
209
- var tokEndLoc;
210
- /**
211
- * The type of the current token. Token types are objects,
212
- * named by variables against which they can be compared, and
213
- * holding properties that describe them (indicating, for example,
214
- * the precedence of an infix operator, and the original name of a
215
- * keyword token).
216
- * @type {!Object|undefined}
217
- */
218
- var tokType;
219
- /**
220
- * The value of the current token. The kind of value that's held in
221
- * `tokVal` depends on the type of the token. For literals, it is the
222
- * literal value, for operators, the operator name, and so on.
223
- * @type {*}
224
- */
225
- var tokVal;
226
- /**
227
- * Interal state for the tokenizer. To distinguish between division
228
- * operators and regular expressions, it remembers whether the last
229
- * token was one that is allowed to be followed by an expression.
230
- * (If it is, a slash is probably a regexp, if it isn't it's a
231
- * division operator. See the `parseStatement` function for a caveat.)
232
- * @type {boolean|undefined}
233
- */
234
- var tokRegexpAllowed;
235
- /**
236
- * When `options.locations` is true, `tokCurLine` is used to keep
237
- * track of the current line.
238
- * @type {number|undefined}
239
- */
240
- var tokCurLine;
241
- /**
242
- * When `options.locations` is true, `tokLineStart` is used to know
243
- * when a new line has been entered.
244
- * @type {number|undefined}
245
- */
246
- var tokLineStart;
247
- /**
248
- * The start of the position of the previous token, which is useful
249
- * when finishing a node and assigning its `end` position.
250
- * @type {number}
251
- */
252
- var lastStart = 0;
253
- /**
254
- * The end oy the position of the previous token, which is useful
255
- * when finishing a node and assigning its `end` position.
256
- * @type {number}
257
- */
258
- var lastEnd = 0;
259
- /**
260
- * Stores the position of the previous token, which is useful
261
- * when finishing a node and assigning its `end` position.
262
- * @type {!line_loc_t|undefined}
263
- */
264
- var lastEndLoc;
265
- /**
266
- * `inFunction` is used to reject `return` statements outside of functions.
267
- * @type {boolean|undefined}
268
- */
269
- var inFunction;
270
- /**
271
- * `labels` is used to verify that `break` and `continue` have somewhere
272
- * to jump to.
273
- * @type {!Array<!Object>|undefined}
274
- */
275
- var labels;
276
- /**
277
- * `strict` indicates whether strict mode is on.
278
- * @type {boolean|undefined}
279
- */
280
- var strict;
281
- /**
282
- * This function is used to raise exceptions on parse errors. It
283
- * takes an offset integer (into the current `input`) to indicate
284
- * the location of the error, attaches the position to the end
285
- * of the error message, and then raises a `SyntaxError` with that
286
- * message.
287
- *
288
- * @param {number} pos
289
- * @param {string} message
290
- * @throws {SyntaxError}
291
- */
292
- function raise(pos, message) {
293
- var loc = getLineInfo(input, pos);
294
- message += ' (' + loc.line + ':' + loc.column + ')';
295
- var err = new SyntaxError(message);
296
- err.pos = pos;
297
- err.loc = loc;
298
- err.raisedAt = tokPos;
299
- throw err;
300
- }
301
- // Reused empty array added for node fields that are always empty.
302
- var empty = [];
303
- // ## Token types
304
- // The assignment of fine-grained, information-carrying type objects
305
- // allows the tokenizer to store the information it has about a
306
- // token in a way that is very cheap for the parser to look up.
307
- // All token type variables start with an underscore, to make them
308
- // easy to recognize.
309
- // These are the general types. The `type` property is only used to
310
- // make them recognizeable when debugging.
311
- var _num = {
312
- type: 'num'
313
- };
314
- var _regexp = {
315
- type: 'regexp'
316
- };
317
- var _string = {
318
- type: 'string'
319
- };
320
- var _name = {
321
- type: 'name'
322
- };
323
- var _eof = {
324
- type: 'eof'
325
- };
326
- // Keyword tokens. The `keyword` property (also used in keyword-like
327
- // operators) indicates that the token originated from an
328
- // identifier-like word, which is used when parsing property names.
329
- //
330
- // The `beforeExpr` property is used to disambiguate between regular
331
- // expressions and divisions. It is set on all token types that can
332
- // be followed by an expression (thus, a slash after them would be a
333
- // regular expression).
334
- //
335
- // `isLoop` marks a keyword as starting a loop, which is important
336
- // to know when parsing a label, in order to allow or disallow
337
- // continue jumps to that label.
338
- var _break = {
339
- keyword: 'break'
340
- };
341
- var _case = {
342
- keyword: 'case',
343
- beforeExpr: true
344
- };
345
- var _catch = {
346
- keyword: 'catch'
347
- };
348
- var _continue = {
349
- keyword: 'continue'
350
- };
351
- var _debugger = {
352
- keyword: 'debugger'
353
- };
354
- var _default = {
355
- keyword: 'default'
356
- };
357
- var _do = {
358
- keyword: 'do',
359
- isLoop: true
360
- };
361
- var _else = {
362
- keyword: 'else',
363
- beforeExpr: true
364
- };
365
- var _finally = {
366
- keyword: 'finally'
367
- };
368
- var _for = {
369
- keyword: 'for',
370
- isLoop: true
371
- };
372
- var _function = {
373
- keyword: 'function'
374
- };
375
- var _if = {
376
- keyword: 'if'
377
- };
378
- var _return = {
379
- keyword: 'return',
380
- beforeExpr: true
381
- };
382
- var _switch = {
383
- keyword: 'switch'
384
- };
385
- var _throw = {
386
- keyword: 'throw',
387
- beforeExpr: true
388
- };
389
- var _try = {
390
- keyword: 'try'
391
- };
392
- var _var = {
393
- keyword: 'var'
394
- };
395
- var _while = {
396
- keyword: 'while',
397
- isLoop: true
398
- };
399
- var _with = {
400
- keyword: 'with'
401
- };
402
- var _new = {
403
- keyword: 'new',
404
- beforeExpr: true
405
- };
406
- var _this = {
407
- keyword: 'this'
408
- };
409
- // The keywords that denote values.
410
- var _null = {
411
- keyword: 'null',
412
- atomValue: null
413
- };
414
- var _true = {
415
- keyword: 'true',
416
- atomValue: true
417
- };
418
- var _false = {
419
- keyword: 'false',
420
- atomValue: false
421
- };
422
- // Some keywords are treated as regular operators. `in` sometimes
423
- // (when parsing `for`) needs to be tested against specifically, so
424
- // we assign a variable name to it for quick comparing.
425
- var _in = {
426
- keyword: 'in',
427
- binop: 7,
428
- beforeExpr: true
429
- };
430
- // Map keyword names to token types.
431
- var keywordTypes = {
432
- break: _break,
433
- case: _case,
434
- catch: _catch,
435
- continue: _continue,
436
- debugger: _debugger,
437
- default: _default,
438
- do: _do,
439
- else: _else,
440
- finally: _finally,
441
- for: _for,
442
- function: _function,
443
- if: _if,
444
- return: _return,
445
- switch: _switch,
446
- throw: _throw,
447
- try: _try,
448
- var: _var,
449
- while: _while,
450
- with: _with,
451
- null: _null,
452
- true: _true,
453
- false: _false,
454
- new: _new,
455
- in: _in,
456
- instanceof: {
457
- keyword: 'instanceof',
458
- binop: 7,
459
- beforeExpr: true
460
- },
461
- this: _this,
462
- typeof: {
463
- keyword: 'typeof',
464
- prefix: true,
465
- beforeExpr: true
466
- },
467
- void: {
468
- keyword: 'void',
469
- prefix: true,
470
- beforeExpr: true
471
- },
472
- delete: {
473
- keyword: 'delete',
474
- prefix: true,
475
- beforeExpr: true
476
- }
477
- };
478
- // Punctuation token types. Again, the `type` property is purely for debugging.
479
- var _bracketL = {
480
- type: '[',
481
- beforeExpr: true
482
- };
483
- var _bracketR = {
484
- type: ']'
485
- };
486
- var _braceL = {
487
- type: '{',
488
- beforeExpr: true
489
- };
490
- var _braceR = {
491
- type: '}'
492
- };
493
- var _parenL = {
494
- type: '(',
495
- beforeExpr: true
496
- };
497
- var _parenR = {
498
- type: ')'
499
- };
500
- var _comma = {
501
- type: ',',
502
- beforeExpr: true
503
- };
504
- var _semi = {
505
- type: ';',
506
- beforeExpr: true
507
- };
508
- var _colon = {
509
- type: ':',
510
- beforeExpr: true
511
- };
512
- var _dot = {
513
- type: '.'
514
- };
515
- var _question = {
516
- type: '?',
517
- beforeExpr: true
518
- };
519
- // Operators. These carry several kinds of properties to help the
520
- // parser use them properly (the presence of these properties is
521
- // what categorizes them as operators).
522
- //
523
- // `binop`, when present, specifies that this operator is a binary
524
- // operator, and will refer to its precedence.
525
- //
526
- // `prefix` and `postfix` mark the operator as a prefix or postfix
527
- // unary operator. `isUpdate` specifies that the node produced by
528
- // the operator should be of type UpdateExpression rather than
529
- // simply UnaryExpression (`++` and `--`).
530
- //
531
- // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
532
- // binary operators with a very low precedence, that should result
533
- // in AssignmentExpression nodes.
534
- var _slash = {
535
- binop: 10,
536
- beforeExpr: true
537
- };
538
- var _eq = {
539
- isAssign: true,
540
- beforeExpr: true
541
- };
542
- var _assign = {
543
- isAssign: true,
544
- beforeExpr: true
545
- };
546
- var _incDec = {
547
- postfix: true,
548
- prefix: true,
549
- isUpdate: true
550
- };
551
- var _prefix = {
552
- prefix: true,
553
- beforeExpr: true
554
- };
555
- var _logicalOR = {
556
- binop: 1,
557
- beforeExpr: true
558
- };
559
- var _logicalAND = {
560
- binop: 2,
561
- beforeExpr: true
562
- };
563
- var _bitwiseOR = {
564
- binop: 3,
565
- beforeExpr: true
566
- };
567
- var _bitwiseXOR = {
568
- binop: 4,
569
- beforeExpr: true
570
- };
571
- var _bitwiseAND = {
572
- binop: 5,
573
- beforeExpr: true
574
- };
575
- var _equality = {
576
- binop: 6,
577
- beforeExpr: true
578
- };
579
- var _relational = {
580
- binop: 7,
581
- beforeExpr: true
582
- };
583
- var _bitShift = {
584
- binop: 8,
585
- beforeExpr: true
586
- };
587
- var _plusMin = {
588
- binop: 9,
589
- prefix: true,
590
- beforeExpr: true
591
- };
592
- var _multiplyModulo = {
593
- binop: 10,
594
- beforeExpr: true
595
- };
596
- // JS-Interpreter change:
597
- // tokTypes map never used. Removed.
598
- // -- Neil Fraser, February 2023.
599
- // JS-Interpreter change:
600
- // Acorn's original code built up functions using strings for maximum efficiency.
601
- // However, this triggered a CSP unsafe-eval requirement. Here's a slower, but
602
- // simpler approach. -- Neil Fraser, January 2022.
603
- // https://github.com/NeilFraser/JS-Interpreter/issues/228
604
- /**
605
- * @param {string} words
606
- * @returns {function(*): boolean}
607
- */
608
- function makePredicate(words) {
609
- var wordList = words.split(' ');
610
- var set = Object.create(null);
611
- for (var i = 0; i < wordList.length; i++) {
612
- set[wordList[i]] = true;
613
- }
614
- return function (str) {
615
- return set[str] || false;
616
- };
617
- }
618
- // ECMAScript 5 reserved words.
619
- var isReservedWord5 = makePredicate('class enum extends super const export import');
620
- // The additional reserved words in strict mode.
621
- var isStrictReservedWord = makePredicate('implements interface let package private protected public static yield');
622
- // The forbidden variable names in strict mode.
623
- var isStrictBadIdWord = makePredicate('eval arguments');
624
- // And the keywords.
625
- var isKeyword = makePredicate('break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this');
626
- // ## Character categories
627
- // Big ugly regular expressions that match characters in the
628
- // whitespace, identifier, and identifier-start categories. These
629
- // are only applied when a character is found to actually have a
630
- // code point above 128.
631
- var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
632
- var nonASCIIidentifierStartChars = '\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc';
633
- var nonASCIIidentifierChars = '\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\ua980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f';
634
- var nonASCIIidentifierStart = new RegExp('[' + nonASCIIidentifierStartChars + ']');
635
- var nonASCIIidentifier = new RegExp('[' + nonASCIIidentifierStartChars + nonASCIIidentifierChars + ']');
636
- // Whether a single character denotes a newline.
637
- var newline = /[\n\r\u2028\u2029]/;
638
- // Matches a whole line break (where CRLF is considered a single
639
- // line break). Used to count lines.
640
- var lineBreak = /\r\n|[\n\r\u2028\u2029]/g;
641
- /**
642
- * Test whether a given character code starts an identifier.
643
- *
644
- * @param {number} code
645
- * @returns {boolean}
646
- */
647
- var isIdentifierStart = function (code) {
648
- if (code < 65)
649
- return code === 36;
650
- if (code < 91)
651
- return true;
652
- if (code < 97)
653
- return code === 95;
654
- if (code < 123)
655
- return true;
656
- return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
657
- };
658
- /**
659
- * Test whether a given character is part of an identifier.
660
- *
661
- * @param {number} code
662
- * @returns {boolean}
663
- */
664
- var isIdentifierChar = function (code) {
665
- if (code < 48)
666
- return code === 36;
667
- if (code < 58)
668
- return true;
669
- if (code < 65)
670
- return false;
671
- if (code < 91)
672
- return true;
673
- if (code < 97)
674
- return code === 95;
675
- if (code < 123)
676
- return true;
677
- return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
678
- };
679
- // ## Tokenizer
680
- /**
681
- * These are used when `options.locations` is on, for the
682
- * `tokStartLoc` and `tokEndLoc` properties.
683
- * @constructor
684
- */
685
- function line_loc_t() {
686
- this.line = tokCurLine;
687
- this.column = tokPos - tokLineStart;
688
- }
689
- /**
690
- * Reset the token state. Used at the start of a parse.
691
- */
692
- function initTokenState() {
693
- tokCurLine = 1;
694
- tokPos = tokLineStart = 0;
695
- tokRegexpAllowed = true;
696
- skipSpace();
697
- }
698
- /**
699
- * Called at the end of every token. Sets `tokEnd`, `tokVal`, and
700
- * `tokRegexpAllowed`, and skips the space after the token, so that
701
- * the next one's `tokStart` will point at the right position.
702
- *
703
- * @param {!Object} type
704
- * @param {*=} val
705
- */
706
- function finishToken(type, val) {
707
- tokEnd = tokPos;
708
- if (options.locations) {
709
- tokEndLoc = new line_loc_t();
710
- }
711
- tokType = type;
712
- skipSpace();
713
- tokVal = val;
714
- tokRegexpAllowed = type.beforeExpr;
715
- }
716
- function skipBlockComment() {
717
- var startLoc = options.onComment && options.locations && new line_loc_t();
718
- var start = tokPos;
719
- var end = input.indexOf('*/', tokPos += 2);
720
- if (end === -1) {
721
- raise(tokPos - 2, 'Unterminated comment');
722
- }
723
- tokPos = end + 2;
724
- if (options.locations) {
725
- lineBreak.lastIndex = start;
726
- var match;
727
- while ((match = lineBreak.exec(input)) && match.index < tokPos) {
728
- ++tokCurLine;
729
- tokLineStart = match.index + match[0].length;
730
- }
731
- }
732
- if (options.onComment) {
733
- options.onComment(true, input.slice(start + 2, end), start, tokPos, startLoc, options.locations && new line_loc_t());
734
- }
735
- }
736
- function skipLineComment() {
737
- var start = tokPos;
738
- var startLoc = options.onComment && options.locations && new line_loc_t();
739
- var ch = input.charCodeAt(tokPos += 2);
740
- while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
741
- ++tokPos;
742
- ch = input.charCodeAt(tokPos);
743
- }
744
- if (options.onComment) {
745
- options.onComment(false, input.slice(start + 2, tokPos), start, tokPos, startLoc, options.locations && new line_loc_t());
746
- }
747
- }
748
- // Called at the start of the parse and after every token. Skips
749
- // whitespace and comments, and.
750
- function skipSpace() {
751
- while (tokPos < inputLen) {
752
- var ch = input.charCodeAt(tokPos);
753
- if (ch === 32) {
754
- // ' '
755
- ++tokPos;
756
- }
757
- else if (ch === 13) {
758
- ++tokPos;
759
- var next = input.charCodeAt(tokPos);
760
- if (next === 10) {
761
- ++tokPos;
762
- }
763
- if (options.locations) {
764
- ++tokCurLine;
765
- tokLineStart = tokPos;
766
- }
767
- }
768
- else if (ch === 10 || ch === 8232 || ch === 8233) {
769
- ++tokPos;
770
- if (options.locations) {
771
- ++tokCurLine;
772
- tokLineStart = tokPos;
773
- }
774
- }
775
- else if (ch > 8 && ch < 14) {
776
- ++tokPos;
777
- }
778
- else if (ch === 47) {
779
- // '/'
780
- var next = input.charCodeAt(tokPos + 1);
781
- if (next === 42) {
782
- // '*'
783
- skipBlockComment();
784
- }
785
- else if (next === 47) {
786
- // '/'
787
- skipLineComment();
788
- }
789
- else
790
- break;
791
- }
792
- else if (ch === 160) {
793
- // '\xa0'
794
- ++tokPos;
795
- }
796
- else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
797
- ++tokPos;
798
- }
799
- else {
800
- break;
801
- }
802
- }
803
- }
804
- // ### Token reading
805
- // This is the function that is called to fetch the next token. It
806
- // is somewhat obscure, because it works in character codes rather
807
- // than characters, and because operator parsing has been inlined
808
- // into it.
809
- //
810
- // All in the name of speed.
811
- //
812
- // The `forceRegexp` parameter is used in the one case where the
813
- // `tokRegexpAllowed` trick does not work. See `parseStatement`.
814
- function readToken_dot() {
815
- var next = input.charCodeAt(tokPos + 1);
816
- if (next >= 48 && next <= 57) {
817
- readNumber(true);
818
- }
819
- else {
820
- ++tokPos;
821
- finishToken(_dot);
822
- }
823
- }
824
- function readToken_slash() {
825
- // '/'
826
- var next = input.charCodeAt(tokPos + 1);
827
- if (tokRegexpAllowed) {
828
- ++tokPos;
829
- readRegexp();
830
- }
831
- else if (next === 61) {
832
- finishOp(_assign, 2);
833
- }
834
- else {
835
- finishOp(_slash, 1);
836
- }
837
- }
838
- function readToken_mult_modulo() {
839
- // '%*'
840
- var next = input.charCodeAt(tokPos + 1);
841
- if (next === 61) {
842
- finishOp(_assign, 2);
843
- }
844
- else {
845
- finishOp(_multiplyModulo, 1);
846
- }
847
- }
848
- /**
849
- * @param {number} code
850
- */
851
- function readToken_pipe_amp(code) {
852
- // '|&'
853
- var next = input.charCodeAt(tokPos + 1);
854
- if (next === code) {
855
- finishOp(code === 124 ? _logicalOR : _logicalAND, 2);
856
- }
857
- else if (next === 61) {
858
- finishOp(_assign, 2);
859
- }
860
- else {
861
- finishOp(code === 124 ? _bitwiseOR : _bitwiseAND, 1);
862
- }
863
- }
864
- function readToken_caret() {
865
- // '^'
866
- var next = input.charCodeAt(tokPos + 1);
867
- if (next === 61) {
868
- finishOp(_assign, 2);
869
- }
870
- else {
871
- finishOp(_bitwiseXOR, 1);
872
- }
873
- }
874
- /**
875
- * @param {number} code
876
- */
877
- function readToken_plus_min(code) {
878
- // '+-'
879
- var next = input.charCodeAt(tokPos + 1);
880
- if (next === code) {
881
- if (next === 45 && input.charCodeAt(tokPos + 2) === 62 && newline.test(input.slice(lastEnd, tokPos))) {
882
- // A `-->` line comment
883
- tokPos += 3;
884
- skipLineComment();
885
- skipSpace();
886
- readToken();
887
- return;
888
- }
889
- finishOp(_incDec, 2);
890
- }
891
- else if (next === 61) {
892
- finishOp(_assign, 2);
893
- }
894
- else {
895
- finishOp(_plusMin, 1);
896
- }
897
- }
898
- /**
899
- * @param {number} code
900
- */
901
- function readToken_lt_gt(code) {
902
- // '<>'
903
- var next = input.charCodeAt(tokPos + 1);
904
- var size = 1;
905
- if (next === code) {
906
- size = code === 62 && input.charCodeAt(tokPos + 2) === 62 ? 3 : 2;
907
- if (input.charCodeAt(tokPos + size) === 61) {
908
- finishOp(_assign, size + 1);
909
- }
910
- else {
911
- finishOp(_bitShift, size);
912
- }
913
- return;
914
- }
915
- if (next === 33 && code === 60 && input.charCodeAt(tokPos + 2) === 45 && input.charCodeAt(tokPos + 3) === 45) {
916
- // `<!--`, an XML-style comment that should be interpreted as a line comment
917
- tokPos += 4;
918
- skipLineComment();
919
- skipSpace();
920
- readToken();
921
- return;
922
- }
923
- if (next === 61) {
924
- size = input.charCodeAt(tokPos + 2) === 61 ? 3 : 2;
925
- }
926
- finishOp(_relational, size);
927
- }
928
- /**
929
- * @param {number} code
930
- */
931
- function readToken_eq_excl(code) {
932
- // '=!'
933
- var next = input.charCodeAt(tokPos + 1);
934
- if (next === 61) {
935
- finishOp(_equality, input.charCodeAt(tokPos + 2) === 61 ? 3 : 2);
936
- }
937
- else {
938
- finishOp(code === 61 ? _eq : _prefix, 1);
939
- }
940
- }
941
- /**
942
- * @param {number} code
943
- * @returns {boolean|undefined}
944
- */
945
- function getTokenFromCode(code) {
946
- switch (code) {
947
- // The interpretation of a dot depends on whether it is followed
948
- // by a digit.
949
- case 46:
950
- // '.'
951
- return readToken_dot();
952
- // Punctuation tokens.
953
- case 40:
954
- ++tokPos;
955
- return finishToken(_parenL);
956
- case 41:
957
- ++tokPos;
958
- return finishToken(_parenR);
959
- case 59:
960
- ++tokPos;
961
- return finishToken(_semi);
962
- case 44:
963
- ++tokPos;
964
- return finishToken(_comma);
965
- case 91:
966
- ++tokPos;
967
- return finishToken(_bracketL);
968
- case 93:
969
- ++tokPos;
970
- return finishToken(_bracketR);
971
- case 123:
972
- ++tokPos;
973
- return finishToken(_braceL);
974
- case 125:
975
- ++tokPos;
976
- return finishToken(_braceR);
977
- case 58:
978
- ++tokPos;
979
- return finishToken(_colon);
980
- case 63:
981
- ++tokPos;
982
- return finishToken(_question);
983
- // '0x' is a hexadecimal number.
984
- case 48:
985
- // '0'
986
- var next = input.charCodeAt(tokPos + 1);
987
- if (next === 120 || next === 88)
988
- return readHexNumber();
989
- // Anything else beginning with a digit is an integer, octal
990
- // number, or float.
991
- case 49:
992
- case 50:
993
- case 51:
994
- case 52:
995
- case 53:
996
- case 54:
997
- case 55:
998
- case 56:
999
- case 57:
1000
- // 1-9
1001
- return readNumber(false);
1002
- // Quotes produce strings.
1003
- case 34:
1004
- case 39:
1005
- // '"', "'"
1006
- return readString(code);
1007
- // Operators are parsed inline in tiny state machines. '=' (61) is
1008
- // often referred to. `finishOp` simply skips the amount of
1009
- // characters it is given as second argument, and returns a token
1010
- // of the type given by its first argument.
1011
- case 47:
1012
- // '/'
1013
- return readToken_slash();
1014
- case 37:
1015
- case 42:
1016
- // '%*'
1017
- return readToken_mult_modulo();
1018
- case 124:
1019
- case 38:
1020
- // '|&'
1021
- return readToken_pipe_amp(code);
1022
- case 94:
1023
- // '^'
1024
- return readToken_caret();
1025
- case 43:
1026
- case 45:
1027
- // '+-'
1028
- return readToken_plus_min(code);
1029
- case 60:
1030
- case 62:
1031
- // '<>'
1032
- return readToken_lt_gt(code);
1033
- case 61:
1034
- case 33:
1035
- // '=!'
1036
- return readToken_eq_excl(code);
1037
- case 126:
1038
- // '~'
1039
- return finishOp(_prefix, 1);
1040
- }
1041
- return false;
1042
- }
1043
- /**
1044
- * @param {boolean=} forceRegexp
1045
- */
1046
- function readToken(forceRegexp) {
1047
- if (!forceRegexp) {
1048
- tokStart = tokPos;
1049
- }
1050
- else {
1051
- tokPos = tokStart + 1;
1052
- }
1053
- if (options.locations) {
1054
- tokStartLoc = new line_loc_t();
1055
- }
1056
- if (forceRegexp)
1057
- return readRegexp();
1058
- if (tokPos >= inputLen)
1059
- return finishToken(_eof);
1060
- var code = input.charCodeAt(tokPos);
1061
- // Identifier or keyword. '\uXXXX' sequences are allowed in
1062
- // identifiers, so '\' also dispatches to that.
1063
- if (isIdentifierStart(code) || code === 92) {
1064
- // '\'
1065
- return readWord();
1066
- }
1067
- var tok = getTokenFromCode(code);
1068
- if (tok === false) {
1069
- // If we are here, we either found a non-ASCII identifier
1070
- // character, or something that's entirely disallowed.
1071
- var ch = String.fromCharCode(code);
1072
- if (ch === '\\' || nonASCIIidentifierStart.test(ch)) {
1073
- return readWord();
1074
- }
1075
- raise(tokPos, "Unexpected character '" + ch + "'");
1076
- }
1077
- }
1078
- /**
1079
- * @param {!Object} type
1080
- * @param {number} size
1081
- */
1082
- function finishOp(type, size) {
1083
- var str = input.slice(tokPos, tokPos + size);
1084
- tokPos += size;
1085
- finishToken(type, str);
1086
- }
1087
- /**
1088
- * Parse a regular expression. Some context-awareness is necessary,
1089
- * since a '/' inside a '[]' set does not end the expression.
1090
- */
1091
- function readRegexp() {
1092
- // JS-Interpreter change:
1093
- // Removed redundant declaration of 'content' here. Caused lint errors.
1094
- // -- Neil Fraser, June 2022.
1095
- var escaped;
1096
- var inClass;
1097
- var start = tokPos;
1098
- for (;;) {
1099
- if (tokPos >= inputLen)
1100
- raise(start, 'Unterminated regexp');
1101
- var ch = input.charAt(tokPos);
1102
- if (newline.test(ch))
1103
- raise(start, 'Unterminated regexp');
1104
- if (!escaped) {
1105
- if (ch === '[') {
1106
- inClass = true;
1107
- }
1108
- else if (ch === ']' && inClass) {
1109
- inClass = false;
1110
- }
1111
- else if (ch === '/' && !inClass) {
1112
- break;
1113
- }
1114
- escaped = ch === '\\';
1115
- }
1116
- else
1117
- escaped = false;
1118
- ++tokPos;
1119
- }
1120
- var content = input.slice(start, tokPos);
1121
- ++tokPos;
1122
- // Need to use `readWord1` because '\uXXXX' sequences are allowed
1123
- // here (don't ask).
1124
- var mods = readWord1();
1125
- // JS-Interpreter change:
1126
- // Acorn used to use 'gmsiy' to check for flags. But 's' and 'y' are ES6.
1127
- // -- Neil Fraser, December 2022.
1128
- // https://github.com/acornjs/acorn/issues/1163
1129
- if (mods && !/^[gmi]*$/.test(mods)) {
1130
- raise(start, 'Invalid regexp flag');
1131
- }
1132
- try {
1133
- var value = new RegExp(content, mods);
1134
- }
1135
- catch (e) {
1136
- if (e instanceof SyntaxError)
1137
- raise(start, e.message);
1138
- // JS-Interpreter change:
1139
- // Acorn used to use raise(e) here which is incorrect.
1140
- // -- Neil Fraser, July 2023.
1141
- throw e;
1142
- }
1143
- finishToken(_regexp, value);
1144
- }
1145
- /**
1146
- * Read an integer in the given radix. Return null if zero digits
1147
- * were read, the integer value otherwise. When `len` is given, this
1148
- * will return `null` unless the integer has exactly `len` digits.
1149
- * @param {number} radix
1150
- * @param {number=} len
1151
- * @returns {?number}
1152
- */
1153
- function readInt(radix, len) {
1154
- var start = tokPos;
1155
- var total = 0;
1156
- var e = len === undefined ? Infinity : len;
1157
- for (var i = 0; i < e; ++i) {
1158
- var code = input.charCodeAt(tokPos), val;
1159
- if (code >= 97) {
1160
- val = code - 97 + 10; // a
1161
- }
1162
- else if (code >= 65) {
1163
- val = code - 65 + 10; // A
1164
- }
1165
- else if (code >= 48 && code <= 57) {
1166
- val = code - 48; // 0-9
1167
- }
1168
- else {
1169
- val = Infinity;
1170
- }
1171
- if (val >= radix)
1172
- break;
1173
- ++tokPos;
1174
- total = total * radix + val;
1175
- }
1176
- if (tokPos === start || len !== undefined && tokPos - start !== len) {
1177
- return null;
1178
- }
1179
- return total;
1180
- }
1181
- function readHexNumber() {
1182
- tokPos += 2; // 0x
1183
- var val = readInt(16);
1184
- if (val === null) {
1185
- raise(tokStart + 2, 'Expected hexadecimal number');
1186
- }
1187
- if (isIdentifierStart(input.charCodeAt(tokPos))) {
1188
- raise(tokPos, 'Identifier directly after number');
1189
- }
1190
- finishToken(_num, val);
1191
- }
1192
- /**
1193
- * Read an integer, octal integer, or floating-point number.
1194
- *
1195
- * @param {boolean} startsWithDot
1196
- */
1197
- function readNumber(startsWithDot) {
1198
- var start = tokPos;
1199
- var isFloat = false;
1200
- var octal = input.charCodeAt(tokPos) === 48;
1201
- if (!startsWithDot && readInt(10) === null) {
1202
- raise(start, 'Invalid number');
1203
- }
1204
- if (input.charCodeAt(tokPos) === 46) {
1205
- ++tokPos;
1206
- readInt(10);
1207
- isFloat = true;
1208
- }
1209
- var next = input.charCodeAt(tokPos);
1210
- if (next === 69 || next === 101) {
1211
- // 'eE'
1212
- next = input.charCodeAt(++tokPos);
1213
- if (next === 43 || next === 45) {
1214
- ++tokPos; // '+-'
1215
- }
1216
- if (readInt(10) === null) {
1217
- raise(start, 'Invalid number');
1218
- }
1219
- isFloat = true;
1220
- }
1221
- if (isIdentifierStart(input.charCodeAt(tokPos))) {
1222
- raise(tokPos, 'Identifier directly after number');
1223
- }
1224
- var str = input.slice(start, tokPos);
1225
- var val;
1226
- if (isFloat) {
1227
- val = parseFloat(str);
1228
- }
1229
- else if (!octal || str.length === 1) {
1230
- val = parseInt(str, 10);
1231
- }
1232
- else if (/[89]/.test(str) || strict) {
1233
- raise(start, 'Invalid number');
1234
- }
1235
- else {
1236
- val = parseInt(str, 8);
1237
- }
1238
- finishToken(_num, val);
1239
- }
1240
- /**
1241
- * Read a string value, interpreting backslash-escapes.
1242
- *
1243
- * @param {number} quote
1244
- */
1245
- function readString(quote) {
1246
- tokPos++;
1247
- var out = '';
1248
- for (;;) {
1249
- if (tokPos >= inputLen)
1250
- raise(tokStart, 'Unterminated string constant');
1251
- var ch = input.charCodeAt(tokPos);
1252
- if (ch === quote) {
1253
- ++tokPos;
1254
- finishToken(_string, out);
1255
- return;
1256
- }
1257
- if (ch === 92) {
1258
- // '\'
1259
- ch = input.charCodeAt(++tokPos);
1260
- var octal = /^[0-7]+/.exec(input.slice(tokPos, tokPos + 3));
1261
- if (octal) {
1262
- octal = octal[0];
1263
- }
1264
- while (octal && parseInt(octal, 8) > 255) {
1265
- octal = octal.slice(0, -1);
1266
- }
1267
- if (octal === '0') {
1268
- octal = null;
1269
- }
1270
- ++tokPos;
1271
- if (octal) {
1272
- if (strict)
1273
- raise(tokPos - 2, 'Octal literal in strict mode');
1274
- out += String.fromCharCode(parseInt(octal, 8));
1275
- tokPos += octal.length - 1;
1276
- }
1277
- else {
1278
- switch (ch) {
1279
- case 110:
1280
- out += '\n';
1281
- break;
1282
- // 'n' -> '\n'
1283
- case 114:
1284
- out += '\r';
1285
- break;
1286
- // 'r' -> '\r'
1287
- case 120:
1288
- out += String.fromCharCode(readHexChar(2));
1289
- break;
1290
- // 'x'
1291
- case 117:
1292
- out += String.fromCharCode(readHexChar(4));
1293
- break;
1294
- // 'u'
1295
- case 85:
1296
- out += String.fromCharCode(readHexChar(8));
1297
- break;
1298
- // 'U'
1299
- case 116:
1300
- out += '\t';
1301
- break;
1302
- // 't' -> '\t'
1303
- case 98:
1304
- out += '\b';
1305
- break;
1306
- // 'b' -> '\b'
1307
- case 118:
1308
- out += '\u000b';
1309
- break;
1310
- // 'v' -> '\u000b'
1311
- case 102:
1312
- out += '\f';
1313
- break;
1314
- // 'f' -> '\f'
1315
- case 48:
1316
- out += '\0';
1317
- break;
1318
- // 0 -> '\0'
1319
- case 13:
1320
- // '\r'
1321
- if (input.charCodeAt(tokPos) === 10) {
1322
- ++tokPos; // '\r\n'
1323
- }
1324
- case 10:
1325
- // ' \n'
1326
- if (options.locations) {
1327
- tokLineStart = tokPos;
1328
- ++tokCurLine;
1329
- }
1330
- break;
1331
- default:
1332
- out += String.fromCharCode(ch);
1333
- break;
1334
- }
1335
- }
1336
- }
1337
- else {
1338
- if (ch === 13 || ch === 10 || ch === 8232 || ch === 8233) {
1339
- raise(tokStart, 'Unterminated string constant');
1340
- }
1341
- out += String.fromCharCode(ch); // '\'
1342
- ++tokPos;
1343
- }
1344
- }
1345
- }
1346
- /**
1347
- * Used to read character escape sequences ('\x', '\u', '\U').
1348
- *
1349
- * @param {number} len
1350
- * @returns {number}
1351
- */
1352
- function readHexChar(len) {
1353
- var n = readInt(16, len);
1354
- if (n === null)
1355
- raise(tokStart, 'Bad character escape sequence');
1356
- return ( /** @type {number} */n);
1357
- }
1358
- // Used to signal to callers of `readWord1` whether the word
1359
- // contained any escape sequences. This is needed because words with
1360
- // escape sequences must not be interpreted as keywords.
1361
- /** @type {boolean|undefined} */
1362
- var containsEsc;
1363
- /**
1364
- * Read an identifier, and return it as a string. Sets `containsEsc`
1365
- * to whether the word contained a '\u' escape.
1366
- *
1367
- * Only builds up the word character-by-character when it actually
1368
- * containeds an escape, as a micro-optimization.
1369
- *
1370
- * @returns {string|undefined}
1371
- */
1372
- function readWord1() {
1373
- containsEsc = false;
1374
- var word;
1375
- var first = true;
1376
- var start = tokPos;
1377
- for (;;) {
1378
- var ch = input.charCodeAt(tokPos);
1379
- if (isIdentifierChar(ch)) {
1380
- if (containsEsc) {
1381
- word += input.charAt(tokPos);
1382
- }
1383
- ++tokPos;
1384
- }
1385
- else if (ch === 92) {
1386
- // "\"
1387
- if (!containsEsc) {
1388
- word = input.slice(start, tokPos);
1389
- }
1390
- containsEsc = true;
1391
- if (input.charCodeAt(++tokPos) !== 117) {
1392
- // "u"
1393
- raise(tokPos, 'Expecting Unicode escape sequence \\uXXXX');
1394
- }
1395
- ++tokPos;
1396
- var esc = readHexChar(4);
1397
- var escStr = String.fromCharCode(esc);
1398
- if (!escStr)
1399
- raise(tokPos - 1, 'Invalid Unicode escape');
1400
- if (!(first ? isIdentifierStart(esc) : isIdentifierChar(esc))) {
1401
- raise(tokPos - 4, 'Invalid Unicode escape');
1402
- }
1403
- word += escStr;
1404
- }
1405
- else {
1406
- break;
1407
- }
1408
- first = false;
1409
- }
1410
- return containsEsc ? word : input.slice(start, tokPos);
1411
- }
1412
- /**
1413
- * Read an identifier or keyword token. Will check for reserved
1414
- * words when necessary.
1415
- */
1416
- function readWord() {
1417
- var word = readWord1();
1418
- var type = _name;
1419
- if (!containsEsc && isKeyword(word)) {
1420
- type = keywordTypes[word];
1421
- }
1422
- finishToken(type, word);
1423
- }
1424
- // ## Parser
1425
- // A recursive descent parser operates by defining functions for all
1426
- // syntactic elements, and recursively calling those, each function
1427
- // advancing the input stream and returning an AST node. Precedence
1428
- // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
1429
- // instead of `(!x)[1]` is handled by the fact that the parser
1430
- // function that parses unary prefix operators is called first, and
1431
- // in turn calls the function that parses `[]` subscripts — that
1432
- // way, it'll receive the node for `x[1]` already parsed, and wraps
1433
- // *that* in the unary operator node.
1434
- //
1435
- // Acorn uses an [operator precedence parser][opp] to handle binary
1436
- // operator precedence, because it is much more compact than using
1437
- // the technique outlined above, which uses different, nesting
1438
- // functions to specify precedence, for all of the ten binary
1439
- // precedence levels that JavaScript defines.
1440
- //
1441
- // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
1442
- // ### Parser utilities
1443
- /**
1444
- * Continue to the next token.
1445
- */
1446
- function next() {
1447
- lastStart = tokStart;
1448
- lastEnd = tokEnd;
1449
- lastEndLoc = tokEndLoc;
1450
- readToken();
1451
- }
1452
- /**
1453
- * Enter strict mode. Re-reads the next token to please pedantic
1454
- * tests ("use strict"; 010; -- should fail).
1455
- *
1456
- * @param {boolean} strct
1457
- */
1458
- function setStrict(strct) {
1459
- strict = strct;
1460
- tokPos = tokStart;
1461
- if (options.locations) {
1462
- while (tokPos < tokLineStart) {
1463
- tokLineStart = input.lastIndexOf('\n', tokLineStart - 2) + 1;
1464
- --tokCurLine;
1465
- }
1466
- }
1467
- skipSpace();
1468
- readToken();
1469
- }
1470
- // Start an AST node, attaching a start offset.
1471
- /**
1472
- * @constructor
1473
- */
1474
- function node_t() {
1475
- this.type = null;
1476
- this.start = tokStart;
1477
- this.end = null;
1478
- }
1479
- /**
1480
- * @constructor
1481
- */
1482
- function node_loc_t() {
1483
- this.start = tokStartLoc;
1484
- this.end = null;
1485
- if (sourceFile) {
1486
- this.source = sourceFile;
1487
- }
1488
- }
1489
- /**
1490
- * @returns {!node_t}
1491
- */
1492
- function startNode() {
1493
- var node = new node_t();
1494
- if (options.locations) {
1495
- node.loc = new node_loc_t();
1496
- }
1497
- if (options.directSourceFile) {
1498
- node.sourceFile = options.directSourceFile;
1499
- }
1500
- if (options.ranges) {
1501
- node.range = [tokStart, 0];
1502
- }
1503
- return node;
1504
- }
1505
- /**
1506
- * Start a node whose start offset information should be based on
1507
- * the start of another node. For example, a binary operator node is
1508
- * only started after its left-hand side has already been parsed.
1509
- *
1510
- * @param {!node_t} other
1511
- * @returns {!node_t}
1512
- */
1513
- function startNodeFrom(other) {
1514
- var node = new node_t();
1515
- node.start = other.start;
1516
- if (options.locations) {
1517
- node.loc = new node_loc_t();
1518
- node.loc.start = other.loc.start;
1519
- }
1520
- if (options.ranges) {
1521
- node.range = [other.range[0], 0];
1522
- }
1523
- return node;
1524
- }
1525
- /**
1526
- * Finish an AST node, adding `type` and `end` properties.
1527
- *
1528
- * @param {!node_t} node
1529
- * @param {string} type
1530
- * @returns {!node_t}
1531
- */
1532
- function finishNode(node, type) {
1533
- node.type = type;
1534
- node.end = lastEnd;
1535
- if (options.locations) {
1536
- node.loc.end = lastEndLoc;
1537
- }
1538
- if (options.ranges) {
1539
- node.range[1] = lastEnd;
1540
- }
1541
- return node;
1542
- }
1543
- /**
1544
- * Test whether a statement node is the string literal `"use strict"`.
1545
- *
1546
- * @param {!node_t} stmt
1547
- * @returns {boolean}
1548
- */
1549
- function isUseStrict(stmt) {
1550
- return stmt.type === 'ExpressionStatement' && stmt.expression.type === 'Literal' && stmt.expression.value === 'use strict';
1551
- }
1552
- /**
1553
- * Predicate that tests whether the next token is of the given
1554
- * type, and if yes, consumes it as a side effect.
1555
- * @param {!Object} type
1556
- * @returns {boolean}
1557
- */
1558
- function eat(type) {
1559
- if (tokType === type) {
1560
- next();
1561
- return true;
1562
- }
1563
- return false;
1564
- }
1565
- /**
1566
- * Test whether a semicolon can be inserted at the current position.
1567
- *
1568
- * @returns {boolean}
1569
- */
1570
- function canInsertSemicolon() {
1571
- return !options.strictSemicolons && (tokType === _eof || tokType === _braceR || newline.test(input.slice(lastEnd, tokStart)));
1572
- }
1573
- /**
1574
- * Consume a semicolon, or, failing that, see if we are allowed to
1575
- * pretend that there is a semicolon at this position.
1576
- */
1577
- function semicolon() {
1578
- if (!eat(_semi) && !canInsertSemicolon()) {
1579
- unexpected();
1580
- }
1581
- }
1582
- /**
1583
- * Expect a token of a given type. If found, consume it, otherwise,
1584
- * raise an unexpected token error.
1585
- *
1586
- * @param {!Object} type
1587
- */
1588
- function expect(type) {
1589
- if (tokType === type) {
1590
- next();
1591
- }
1592
- else {
1593
- unexpected();
1594
- }
1595
- }
1596
- /**
1597
- * Raise an unexpected token error.
1598
- * @throws {SyntaxError}
1599
- */
1600
- function unexpected() {
1601
- raise(tokStart, 'Unexpected token');
1602
- }
1603
- /**
1604
- * Verify that a node is an lval — something that can be assigned to.
1605
- *
1606
- * @param {!node_t} expr
1607
- */
1608
- function checkLVal(expr) {
1609
- if (expr.type !== 'Identifier' && expr.type !== 'MemberExpression') {
1610
- raise(expr.start, 'Assigning to rvalue');
1611
- }
1612
- if (strict && expr.type === 'Identifier' && isStrictBadIdWord(expr.name)) {
1613
- raise(expr.start, 'Assigning to ' + expr.name + ' in strict mode');
1614
- }
1615
- }
1616
- // ### Statement parsing
1617
- /**
1618
- * Parse a program. Initializes the parser, reads any number of
1619
- * statements, and wraps them in a Program node. Optionally takes a
1620
- * `program` argument. If present, the statements will be appended
1621
- * to its body instead of creating a new node.
1622
- *
1623
- * @param {node_t} program
1624
- * @returns {!node_t}
1625
- */
1626
- function parseTopLevel(program) {
1627
- lastStart = lastEnd = tokPos;
1628
- if (options.locations) {
1629
- lastEndLoc = new line_loc_t();
1630
- }
1631
- inFunction = strict = false;
1632
- labels = [];
1633
- readToken();
1634
- var node = program || startNode();
1635
- var first = true;
1636
- if (!program) {
1637
- node.body = [];
1638
- }
1639
- while (tokType !== _eof) {
1640
- var stmt = parseStatement();
1641
- node.body.push(stmt);
1642
- if (first && isUseStrict(stmt)) {
1643
- setStrict(true);
1644
- }
1645
- first = false;
1646
- }
1647
- return finishNode(node, 'Program');
1648
- }
1649
- var loopLabel = {
1650
- kind: 'loop'
1651
- };
1652
- var switchLabel = {
1653
- kind: 'switch'
1654
- };
1655
- /**
1656
- * Parse a single statement.
1657
- *
1658
- * If expecting a statement and finding a slash operator, parse a
1659
- * regular expression literal. This is to handle cases like
1660
- * `if (foo) /blah/.exec(foo);`, where looking at the previous token
1661
- * does not help.
1662
- *
1663
- * @returns {!node_t}
1664
- */
1665
- function parseStatement() {
1666
- if (tokType === _slash || tokType === _assign && tokVal === '/=') {
1667
- readToken(true);
1668
- }
1669
- var starttype = tokType;
1670
- var node = startNode();
1671
- // Most types of statements are recognized by the keyword they
1672
- // start with. Many are trivial to parse, some require a bit of
1673
- // complexity.
1674
- switch (starttype) {
1675
- case _break:
1676
- case _continue:
1677
- next();
1678
- var isBreak = starttype === _break;
1679
- if (eat(_semi) || canInsertSemicolon()) {
1680
- node.label = null;
1681
- }
1682
- else if (tokType !== _name) {
1683
- unexpected();
1684
- }
1685
- else {
1686
- node.label = parseIdent();
1687
- semicolon();
1688
- }
1689
- // Verify that there is an actual destination to break or
1690
- // continue to.
1691
- for (var i = 0; i < labels.length; ++i) {
1692
- var lab = labels[i];
1693
- if (node.label === null || lab.name === node.label.name) {
1694
- if (lab.kind !== null && (isBreak || lab.kind === 'loop'))
1695
- break;
1696
- if (node.label && isBreak)
1697
- break;
1698
- }
1699
- }
1700
- if (i === labels.length) {
1701
- raise(node.start, 'Unsyntactic ' + starttype.keyword);
1702
- }
1703
- return finishNode(node, isBreak ? 'BreakStatement' : 'ContinueStatement');
1704
- case _debugger:
1705
- next();
1706
- semicolon();
1707
- return finishNode(node, 'DebuggerStatement');
1708
- case _do:
1709
- next();
1710
- labels.push(loopLabel);
1711
- node.body = parseStatement();
1712
- labels.pop();
1713
- expect(_while);
1714
- node.test = parseParenExpression();
1715
- semicolon();
1716
- return finishNode(node, 'DoWhileStatement');
1717
- // Disambiguating between a `for` and a `for`/`in` loop is
1718
- // non-trivial. Basically, we have to parse the init `var`
1719
- // statement or expression, disallowing the `in` operator (see
1720
- // the second parameter to `parseExpression`), and then check
1721
- // whether the next token is `in`. When there is no init part
1722
- // (semicolon immediately after the opening parenthesis), it is
1723
- // a regular `for` loop.
1724
- case _for:
1725
- next();
1726
- labels.push(loopLabel);
1727
- expect(_parenL);
1728
- if (tokType === _semi)
1729
- return parseFor(node, null);
1730
- if (tokType === _var) {
1731
- var init = startNode();
1732
- next();
1733
- parseVar(init, true);
1734
- finishNode(init, 'VariableDeclaration');
1735
- if (init.declarations.length === 1 && eat(_in))
1736
- return parseForIn(node, init);
1737
- return parseFor(node, init);
1738
- }
1739
- var init = parseExpression(false, true);
1740
- if (eat(_in)) {
1741
- checkLVal(init);
1742
- return parseForIn(node, init);
1743
- }
1744
- return parseFor(node, init);
1745
- case _function:
1746
- next();
1747
- return parseFunction(node, true);
1748
- case _if:
1749
- next();
1750
- node.test = parseParenExpression();
1751
- node.consequent = parseStatement();
1752
- node.alternate = eat(_else) ? parseStatement() : null;
1753
- return finishNode(node, 'IfStatement');
1754
- case _return:
1755
- if (!inFunction && !options.allowReturnOutsideFunction) {
1756
- raise(tokStart, "'return' outside of function");
1757
- }
1758
- next();
1759
- // In `return` (and `break`/`continue`), the keywords with
1760
- // optional arguments, we eagerly look for a semicolon or the
1761
- // possibility to insert one.
1762
- if (eat(_semi) || canInsertSemicolon()) {
1763
- node.argument = null;
1764
- }
1765
- else {
1766
- node.argument = parseExpression();
1767
- semicolon();
1768
- }
1769
- return finishNode(node, 'ReturnStatement');
1770
- case _switch:
1771
- next();
1772
- node.discriminant = parseParenExpression();
1773
- node.cases = [];
1774
- expect(_braceL);
1775
- labels.push(switchLabel);
1776
- // Statements under must be grouped (by label) in SwitchCase
1777
- // nodes. `cur` is used to keep the node that we are currently
1778
- // adding statements to.
1779
- for (var cur, sawDefault; tokType !== _braceR;) {
1780
- if (tokType === _case || tokType === _default) {
1781
- var isCase = tokType === _case;
1782
- if (cur) {
1783
- finishNode(cur, 'SwitchCase');
1784
- }
1785
- node.cases.push(cur = startNode());
1786
- cur.consequent = [];
1787
- next();
1788
- if (isCase) {
1789
- cur.test = parseExpression();
1790
- }
1791
- else {
1792
- if (sawDefault) {
1793
- raise(lastStart, 'Multiple default clauses');
1794
- }
1795
- sawDefault = true;
1796
- cur.test = null;
1797
- }
1798
- expect(_colon);
1799
- }
1800
- else {
1801
- if (!cur)
1802
- unexpected();
1803
- cur.consequent.push(parseStatement());
1804
- }
1805
- }
1806
- if (cur)
1807
- finishNode(cur, 'SwitchCase');
1808
- next(); // Closing brace
1809
- labels.pop();
1810
- return finishNode(node, 'SwitchStatement');
1811
- case _throw:
1812
- next();
1813
- if (newline.test(input.slice(lastEnd, tokStart)))
1814
- raise(lastEnd, 'Illegal newline after throw');
1815
- node.argument = parseExpression();
1816
- semicolon();
1817
- return finishNode(node, 'ThrowStatement');
1818
- case _try:
1819
- next();
1820
- node.block = parseBlock();
1821
- node.handler = null;
1822
- if (tokType === _catch) {
1823
- var clause = startNode();
1824
- next();
1825
- expect(_parenL);
1826
- clause.param = parseIdent();
1827
- if (strict && isStrictBadIdWord(clause.param.name))
1828
- raise(clause.param.start, 'Binding ' + clause.param.name + ' in strict mode');
1829
- expect(_parenR);
1830
- // JS-Interpreter change:
1831
- // Obsolete unused property; commenting out.
1832
- // -- Neil Fraser, January 2023.
1833
- // clause.guard = null;
1834
- clause.body = parseBlock();
1835
- node.handler = finishNode(clause, 'CatchClause');
1836
- }
1837
- // JS-Interpreter change:
1838
- // Obsolete unused property; commenting out.
1839
- // -- Neil Fraser, January 2023.
1840
- // node.guardedHandlers = empty;
1841
- node.finalizer = eat(_finally) ? parseBlock() : null;
1842
- if (!node.handler && !node.finalizer)
1843
- raise(node.start, 'Missing catch or finally clause');
1844
- return finishNode(node, 'TryStatement');
1845
- case _var:
1846
- next();
1847
- parseVar(node);
1848
- semicolon();
1849
- return finishNode(node, 'VariableDeclaration');
1850
- case _while:
1851
- next();
1852
- node.test = parseParenExpression();
1853
- labels.push(loopLabel);
1854
- node.body = parseStatement();
1855
- labels.pop();
1856
- return finishNode(node, 'WhileStatement');
1857
- case _with:
1858
- if (strict)
1859
- raise(tokStart, "'with' in strict mode");
1860
- next();
1861
- node.object = parseParenExpression();
1862
- node.body = parseStatement();
1863
- return finishNode(node, 'WithStatement');
1864
- case _braceL:
1865
- return parseBlock();
1866
- case _semi:
1867
- next();
1868
- return finishNode(node, 'EmptyStatement');
1869
- // If the statement does not start with a statement keyword or a
1870
- // brace, it's an ExpressionStatement or LabeledStatement. We
1871
- // simply start parsing an expression, and afterwards, if the
1872
- // next token is a colon and the expression was a simple
1873
- // Identifier node, we switch to interpreting it as a label.
1874
- default:
1875
- var maybeName = tokVal;
1876
- var expr = parseExpression();
1877
- if (starttype === _name && expr.type === 'Identifier' && eat(_colon)) {
1878
- for (var i = 0; i < labels.length; ++i) {
1879
- if (labels[i].name === maybeName) {
1880
- raise(expr.start, "Label '" + maybeName + "' is already declared");
1881
- }
1882
- }
1883
- var kind = tokType.isLoop ? 'loop' : tokType === _switch ? 'switch' : null;
1884
- labels.push({
1885
- name: maybeName,
1886
- kind
1887
- });
1888
- node.body = parseStatement();
1889
- labels.pop();
1890
- node.label = expr;
1891
- return finishNode(node, 'LabeledStatement');
1892
- }
1893
- else {
1894
- node.expression = expr;
1895
- semicolon();
1896
- return finishNode(node, 'ExpressionStatement');
1897
- }
1898
- }
1899
- }
1900
- /**
1901
- * Used for constructs like `switch` and `if` that insist on
1902
- * parentheses around their expression.
1903
- *
1904
- * @returns {!node_t}
1905
- */
1906
- function parseParenExpression() {
1907
- expect(_parenL);
1908
- var val = parseExpression();
1909
- expect(_parenR);
1910
- return val;
1911
- }
1912
- /**
1913
- * Parse a semicolon-enclosed block of statements, handling `"use
1914
- * strict"` declarations when `allowStrict` is true (used for
1915
- * function bodies).
1916
- *
1917
- * @param {boolean=} allowStrict
1918
- * @returns {!node_t}
1919
- */
1920
- function parseBlock(allowStrict) {
1921
- var node = startNode();
1922
- var first = true;
1923
- var strict = false;
1924
- var oldStrict;
1925
- node.body = [];
1926
- expect(_braceL);
1927
- while (!eat(_braceR)) {
1928
- var stmt = parseStatement();
1929
- node.body.push(stmt);
1930
- if (first && allowStrict && isUseStrict(stmt)) {
1931
- oldStrict = strict;
1932
- setStrict(strict = true);
1933
- }
1934
- first = false;
1935
- }
1936
- if (strict && !oldStrict)
1937
- setStrict(false);
1938
- return finishNode(node, 'BlockStatement');
1939
- }
1940
- /**
1941
- * Parse a regular `for` loop. The disambiguation code in `parseStatement`
1942
- * will already have parsed the init statement or expression.
1943
- *
1944
- * @param {!node_t} node
1945
- * @param {node_t} init
1946
- * @returns {!node_t}
1947
- */
1948
- function parseFor(node, init) {
1949
- node.init = init;
1950
- expect(_semi);
1951
- node.test = tokType === _semi ? null : parseExpression();
1952
- expect(_semi);
1953
- node.update = tokType === _parenR ? null : parseExpression();
1954
- expect(_parenR);
1955
- node.body = parseStatement();
1956
- labels.pop();
1957
- return finishNode(node, 'ForStatement');
1958
- }
1959
- /**
1960
- * Parse a `for`/`in` loop.
1961
- *
1962
- * @param {!node_t} node
1963
- * @param {!node_t} init
1964
- * @returns {!node_t}
1965
- */
1966
- function parseForIn(node, init) {
1967
- node.left = init;
1968
- node.right = parseExpression();
1969
- expect(_parenR);
1970
- node.body = parseStatement();
1971
- labels.pop();
1972
- return finishNode(node, 'ForInStatement');
1973
- }
1974
- /**
1975
- * Parse a list of variable declarations.
1976
- *
1977
- * @param {!node_t} node
1978
- * @param {boolean=} noIn
1979
- */
1980
- function parseVar(node, noIn) {
1981
- node.declarations = [];
1982
- node.kind = 'var';
1983
- for (;;) {
1984
- var decl = startNode();
1985
- decl.id = parseIdent();
1986
- if (strict && isStrictBadIdWord(decl.id.name))
1987
- raise(decl.id.start, 'Binding ' + decl.id.name + ' in strict mode');
1988
- decl.init = eat(_eq) ? parseExpression(true, noIn) : null;
1989
- node.declarations.push(finishNode(decl, 'VariableDeclarator'));
1990
- if (!eat(_comma))
1991
- break;
1992
- }
1993
- }
1994
- // ### Expression parsing
1995
- // These nest, from the most general expression type at the top to
1996
- // 'atomic', nondivisible expression types at the bottom. Most of
1997
- // the functions will simply let the function(s) below them parse,
1998
- // and, *if* the syntactic construct they handle is present, wrap
1999
- // the AST node that the inner parser gave them in another node.
2000
- /**
2001
- * Parse a full expression. The arguments are used to forbid comma
2002
- * sequences (in argument lists, array literals, or object literals)
2003
- * or the `in` operator (in for loops initalization expressions).
2004
- *
2005
- * @param {boolean=} noComma
2006
- * @param {boolean=} noIn
2007
- * @returns {!node_t}
2008
- */
2009
- function parseExpression(noComma, noIn) {
2010
- var expr = parseMaybeAssign(noIn);
2011
- if (!noComma && tokType === _comma) {
2012
- var node = startNodeFrom(expr);
2013
- node.expressions = [expr];
2014
- while (eat(_comma))
2015
- node.expressions.push(parseMaybeAssign(noIn));
2016
- return finishNode(node, 'SequenceExpression');
2017
- }
2018
- return expr;
2019
- }
2020
- /**
2021
- * Parse an assignment expression. This includes applications of
2022
- * operators like `+=`.
2023
- *
2024
- * @param {boolean|undefined} noIn
2025
- * @returns {!node_t}
2026
- */
2027
- function parseMaybeAssign(noIn) {
2028
- var left = parseMaybeConditional(noIn);
2029
- if (tokType.isAssign) {
2030
- var node = startNodeFrom(left);
2031
- node.operator = tokVal;
2032
- node.left = left;
2033
- next();
2034
- node.right = parseMaybeAssign(noIn);
2035
- checkLVal(left);
2036
- return finishNode(node, 'AssignmentExpression');
2037
- }
2038
- return left;
2039
- }
2040
- /**
2041
- * Parse a ternary conditional (`?:`) operator.
2042
- *
2043
- * @param {boolean|undefined} noIn
2044
- * @returns {!node_t}
2045
- */
2046
- function parseMaybeConditional(noIn) {
2047
- var expr = parseExprOps(noIn);
2048
- if (eat(_question)) {
2049
- var node = startNodeFrom(expr);
2050
- node.test = expr;
2051
- node.consequent = parseExpression(true);
2052
- expect(_colon);
2053
- node.alternate = parseExpression(true, noIn);
2054
- return finishNode(node, 'ConditionalExpression');
2055
- }
2056
- return expr;
2057
- }
2058
- /**
2059
- * Start the precedence parser.
2060
- *
2061
- * @param {boolean|undefined} noIn
2062
- * @returns {!node_t}
2063
- */
2064
- function parseExprOps(noIn) {
2065
- return parseExprOp(parseMaybeUnary(), -1, noIn);
2066
- }
2067
- /**
2068
- * Parse binary operators with the operator precedence parsing
2069
- * algorithm. `left` is the left-hand side of the operator.
2070
- * `minPrec` provides context that allows the function to stop and
2071
- * defer further parser to one of its callers when it encounters an
2072
- * operator that has a lower precedence than the set it is parsing.
2073
- *
2074
- * @param {!node_t} left
2075
- * @param {number} minPrec
2076
- * @param {boolean|undefined} noIn
2077
- * @returns {!node_t}
2078
- */
2079
- function parseExprOp(left, minPrec, noIn) {
2080
- var prec = tokType.binop;
2081
- if (prec !== null && (!noIn || tokType !== _in)) {
2082
- if (prec > minPrec) {
2083
- var node = startNodeFrom(left);
2084
- node.left = left;
2085
- node.operator = tokVal;
2086
- var op = tokType;
2087
- next();
2088
- node.right = parseExprOp(parseMaybeUnary(), prec, noIn);
2089
- var exprNode = finishNode(node, op === _logicalOR || op === _logicalAND ? 'LogicalExpression' : 'BinaryExpression');
2090
- return parseExprOp(exprNode, minPrec, noIn);
2091
- }
2092
- }
2093
- return left;
2094
- }
2095
- /**
2096
- * Parse unary operators, both prefix and postfix.
2097
- *
2098
- * @returns {!node_t}
2099
- */
2100
- function parseMaybeUnary() {
2101
- if (tokType.prefix) {
2102
- var node = startNode();
2103
- var update = tokType.isUpdate;
2104
- node.operator = tokVal;
2105
- node.prefix = true;
2106
- tokRegexpAllowed = true;
2107
- next();
2108
- node.argument = parseMaybeUnary();
2109
- if (update)
2110
- checkLVal(node.argument);
2111
- else if (strict && node.operator === 'delete' && node.argument.type === 'Identifier')
2112
- raise(node.start, 'Deleting local variable in strict mode');
2113
- return finishNode(node, update ? 'UpdateExpression' : 'UnaryExpression');
2114
- }
2115
- var expr = parseExprSubscripts();
2116
- while (tokType.postfix && !canInsertSemicolon()) {
2117
- var node = startNodeFrom(expr);
2118
- node.operator = tokVal;
2119
- node.prefix = false;
2120
- node.argument = expr;
2121
- checkLVal(expr);
2122
- next();
2123
- expr = finishNode(node, 'UpdateExpression');
2124
- }
2125
- return expr;
2126
- }
2127
- /**
2128
- * Parse call, dot, and `[]`-subscript expressions.
2129
- *
2130
- * @returns {!node_t}
2131
- */
2132
- function parseExprSubscripts() {
2133
- return parseSubscripts(parseExprAtom());
2134
- }
2135
- /**
2136
- * @param {!node_t} base
2137
- * @param {boolean=} noCalls
2138
- * @returns {!node_t}
2139
- */
2140
- function parseSubscripts(base, noCalls) {
2141
- var node;
2142
- if (eat(_dot)) {
2143
- node = startNodeFrom(base);
2144
- node.object = base;
2145
- node.property = parseIdent(true);
2146
- node.computed = false;
2147
- return parseSubscripts(finishNode(node, 'MemberExpression'), noCalls);
2148
- }
2149
- if (eat(_bracketL)) {
2150
- node = startNodeFrom(base);
2151
- node.object = base;
2152
- node.property = parseExpression();
2153
- node.computed = true;
2154
- expect(_bracketR);
2155
- return parseSubscripts(finishNode(node, 'MemberExpression'), noCalls);
2156
- }
2157
- if (!noCalls && eat(_parenL)) {
2158
- node = startNodeFrom(base);
2159
- node.callee = base;
2160
- node.arguments = parseExprList(_parenR, false);
2161
- return parseSubscripts(finishNode(node, 'CallExpression'), noCalls);
2162
- }
2163
- return base;
2164
- }
2165
- /**
2166
- * Parse an atomic expression — either a single token that is an expression,
2167
- * an expression started by a keyword like `function` or `new`,
2168
- * or an expression wrapped in punctuation like `()`, `[]`, or `{}`.
2169
- *
2170
- * @returns {!node_t}
2171
- * @suppress {missingReturn}
2172
- */
2173
- function parseExprAtom() {
2174
- var node;
2175
- switch (tokType) {
2176
- case _this:
2177
- node = startNode();
2178
- next();
2179
- return finishNode(node, 'ThisExpression');
2180
- case _name:
2181
- return parseIdent();
2182
- case _num:
2183
- case _string:
2184
- case _regexp:
2185
- node = startNode();
2186
- node.value = tokVal;
2187
- node.raw = input.slice(tokStart, tokEnd);
2188
- next();
2189
- return finishNode(node, 'Literal');
2190
- case _null:
2191
- case _true:
2192
- case _false:
2193
- node = startNode();
2194
- node.value = tokType.atomValue;
2195
- node.raw = tokType.keyword;
2196
- next();
2197
- return finishNode(node, 'Literal');
2198
- case _parenL:
2199
- var tokStartLoc1 = tokStartLoc;
2200
- var tokStart1 = tokStart;
2201
- next();
2202
- var val = parseExpression();
2203
- val.start = tokStart1;
2204
- val.end = tokEnd;
2205
- if (options.locations) {
2206
- val.loc.start = tokStartLoc1;
2207
- val.loc.end = tokEndLoc;
2208
- }
2209
- if (options.ranges) {
2210
- val.range = [tokStart1, tokEnd];
2211
- }
2212
- expect(_parenR);
2213
- return val;
2214
- case _bracketL:
2215
- node = startNode();
2216
- next();
2217
- node.elements = parseExprList(_bracketR, true, true);
2218
- return finishNode(node, 'ArrayExpression');
2219
- case _braceL:
2220
- return parseObj();
2221
- case _function:
2222
- node = startNode();
2223
- next();
2224
- return parseFunction(node, false);
2225
- case _new:
2226
- return parseNew();
2227
- }
2228
- unexpected();
2229
- }
2230
- /**
2231
- * New's precedence is slightly tricky. It must allow its argument to be
2232
- * a `[]` or dot subscript expression, but not a call — at least, not
2233
- * without wrapping it in parentheses. Thus, it uses the noCalls argument
2234
- * to parseSubscripts to prevent it from consuming the argument list.
2235
- *
2236
- * @returns {!node_t}
2237
- */
2238
- function parseNew() {
2239
- var node = startNode();
2240
- next();
2241
- node.callee = parseSubscripts(parseExprAtom(), true);
2242
- node.arguments = eat(_parenL) ? parseExprList(_parenR, false) : empty;
2243
- return finishNode(node, 'NewExpression');
2244
- }
2245
- /**
2246
- * Parse an object literal.
2247
- *
2248
- * @returns {!node_t}
2249
- */
2250
- function parseObj() {
2251
- var node = startNode();
2252
- var first = true;
2253
- var sawGetSet = false;
2254
- node.properties = [];
2255
- next();
2256
- while (!eat(_braceR)) {
2257
- if (!first) {
2258
- expect(_comma);
2259
- if (options.allowTrailingCommas && eat(_braceR)) {
2260
- break;
2261
- }
2262
- }
2263
- else {
2264
- first = false;
2265
- }
2266
- var prop = {
2267
- key: parsePropertyName()
2268
- };
2269
- var isGetSet = false;
2270
- var kind;
2271
- if (eat(_colon)) {
2272
- prop.value = parseExpression(true);
2273
- kind = prop.kind = 'init';
2274
- }
2275
- else if (prop.key.type === 'Identifier' && (prop.key.name === 'get' || prop.key.name === 'set')) {
2276
- isGetSet = sawGetSet = true;
2277
- kind = prop.kind = prop.key.name;
2278
- prop.key = parsePropertyName();
2279
- if (tokType !== _parenL)
2280
- unexpected();
2281
- prop.value = parseFunction(startNode(), false);
2282
- }
2283
- else {
2284
- unexpected();
2285
- }
2286
- // getters and setters are not allowed to clash — either with
2287
- // each other or with an init property — and in strict mode,
2288
- // init properties are also not allowed to be repeated.
2289
- if (prop.key.type === 'Identifier' && (strict || sawGetSet)) {
2290
- for (var i = 0; i < node.properties.length; ++i) {
2291
- var other = node.properties[i];
2292
- if (other.key.name === prop.key.name) {
2293
- var conflict = kind === other.kind || isGetSet && other.kind === 'init' || kind === 'init' && (other.kind === 'get' || other.kind === 'set');
2294
- if (conflict && !strict && kind === 'init' && other.kind === 'init') {
2295
- conflict = false;
2296
- }
2297
- if (conflict) {
2298
- raise(prop.key.start, 'Redefinition of property');
2299
- }
2300
- }
2301
- }
2302
- }
2303
- node.properties.push(prop);
2304
- }
2305
- return finishNode(node, 'ObjectExpression');
2306
- }
2307
- /**
2308
- * @returns {!node_t}
2309
- */
2310
- function parsePropertyName() {
2311
- if (tokType === _num || tokType === _string) {
2312
- return parseExprAtom();
2313
- }
2314
- return parseIdent(true);
2315
- }
2316
- /**
2317
- * Parse a function declaration or literal (depending on the
2318
- * `isStatement` parameter).
2319
- *
2320
- * @param {!node_t} node
2321
- * @param {boolean} isStatement
2322
- * @returns {!node_t}
2323
- */
2324
- function parseFunction(node, isStatement) {
2325
- if (tokType === _name) {
2326
- node.id = parseIdent();
2327
- }
2328
- else if (isStatement) {
2329
- unexpected();
2330
- }
2331
- else {
2332
- node.id = null;
2333
- }
2334
- node.params = [];
2335
- var first = true;
2336
- expect(_parenL);
2337
- while (!eat(_parenR)) {
2338
- if (!first) {
2339
- expect(_comma);
2340
- }
2341
- else {
2342
- first = false;
2343
- }
2344
- node.params.push(parseIdent());
2345
- }
2346
- // Start a new scope with regard to labels and the `inFunction`
2347
- // flag (restore them to their old value afterwards).
2348
- var oldInFunc = inFunction;
2349
- var oldLabels = labels;
2350
- inFunction = true;
2351
- labels = [];
2352
- node.body = parseBlock(true);
2353
- inFunction = oldInFunc;
2354
- labels = oldLabels;
2355
- // If this is a strict mode function, verify that argument names
2356
- // are not repeated, and it does not try to bind the words `eval`
2357
- // or `arguments`.
2358
- if (strict || node.body.body.length && isUseStrict(node.body.body[0])) {
2359
- for (var i = node.id ? -1 : 0; i < node.params.length; ++i) {
2360
- var id = i < 0 ? node.id : node.params[i];
2361
- if (isStrictReservedWord(id.name) || isStrictBadIdWord(id.name)) {
2362
- raise(id.start, "Defining '" + id.name + "' in strict mode");
2363
- }
2364
- if (i >= 0) {
2365
- for (var j = 0; j < i; ++j) {
2366
- if (id.name === node.params[j].name) {
2367
- raise(id.start, 'Argument name clash in strict mode');
2368
- }
2369
- }
2370
- }
2371
- }
2372
- }
2373
- return finishNode(node, isStatement ? 'FunctionDeclaration' : 'FunctionExpression');
2374
- }
2375
- /**
2376
- * Parses a comma-separated list of expressions, and returns them as
2377
- * an array. `close` is the token type that ends the list, and
2378
- * `allowEmpty` can be turned on to allow subsequent commas with
2379
- * nothing in between them to be parsed as `null` (which is needed
2380
- * for array literals).
2381
- *
2382
- * @param {!Object} close
2383
- * @param {boolean} allowTrailingComma
2384
- * @param {boolean=} allowEmpty
2385
- * @returns {!Array<!node_t>}
2386
- */
2387
- function parseExprList(close, allowTrailingComma, allowEmpty) {
2388
- var elts = [];
2389
- var first = true;
2390
- while (!eat(close)) {
2391
- if (!first) {
2392
- expect(_comma);
2393
- if (allowTrailingComma && options.allowTrailingCommas && eat(close)) {
2394
- break;
2395
- }
2396
- }
2397
- else {
2398
- first = false;
2399
- }
2400
- elts.push(allowEmpty && tokType === _comma ? null : parseExpression(true));
2401
- }
2402
- return elts;
2403
- }
2404
- /**
2405
- * Parse the next token as an identifier. If `liberal` is true (used
2406
- * when parsing properties), it will also convert keywords into
2407
- * identifiers.
2408
- *
2409
- * @param {boolean=} liberal
2410
- * @returns {!node_t}
2411
- */
2412
- function parseIdent(liberal) {
2413
- var node = startNode();
2414
- if (liberal && options.forbidReserved === 'everywhere') {
2415
- liberal = false;
2416
- }
2417
- if (tokType === _name) {
2418
- if (!liberal && (options.forbidReserved && isReservedWord5(tokVal) || strict && isStrictReservedWord(tokVal)) && input.slice(tokStart, tokEnd).indexOf('\\') === -1) {
2419
- raise(tokStart, "The keyword '" + tokVal + "' is reserved");
2420
- }
2421
- node.name = tokVal;
2422
- }
2423
- else if (liberal && tokType.keyword) {
2424
- node.name = tokType.keyword;
2425
- }
2426
- else {
2427
- unexpected();
2428
- }
2429
- tokRegexpAllowed = false;
2430
- next();
2431
- return finishNode(node, 'Identifier');
2432
- }
2433
- });