@builder.io/sdk-react-nextjs 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.
@@ -1,2432 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- /* eslint-disable */
4
- /**
5
- * Copied from source: https://github.com/NeilFraser/JS-Interpreter/blob/master/acorn.js
6
- * Any changes made here have a comment above them starting with: "// BUILDER.IO"
7
- */
8
- /**
9
- * @license
10
- * Copyright 2012 Marijn Haverbeke
11
- * SPDX-License-Identifier: MIT
12
- */
13
- // Acorn is a tiny, fast JavaScript parser written in JavaScript.
14
- //
15
- // Acorn was written by Marijn Haverbeke and released under an MIT
16
- // license. The Unicode regexps (for identifiers and whitespace) were
17
- // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
18
- //
19
- // Git repositories for Acorn are available at
20
- //
21
- // http://marijnhaverbeke.nl/git/acorn
22
- // https://github.com/marijnh/acorn.git
23
- //
24
- // Please use the [github bug tracker][ghbt] to report issues.
25
- //
26
- // [ghbt]: https://github.com/marijnh/acorn/issues
27
- //
28
- // This file defines the main parser interface. The library also comes
29
- // with a [error-tolerant parser][dammit] and an
30
- // [abstract syntax tree walker][walk], defined in other files.
31
- //
32
- // [dammit]: acorn_loose.js
33
- // [walk]: util/walk.js
34
- (function (root, mod) {
35
- if (typeof exports === 'object' && typeof module === 'object')
36
- return mod(exports); // CommonJS
37
- if (typeof define === 'function' && define.amd)
38
- return define(['exports'], mod); // AMD
39
- mod(root.acorn || (root.acorn = {})); // Plain browser env
40
- })(this, function (exports) {
41
- exports.version = '0.5.0';
42
- // Plus additional edits marked with 'JS-Interpreter change' comments.
43
- // JS-Interpreter change:
44
- // Added JSDoc type definitions.
45
- // -- Neil Fraser, July 2023.
46
- // JS-Interpreter change:
47
- // No longer exporting defaultOptions, getLineInfo, tokenize, tokTypes,
48
- // isIdentifierStart, and isIdentifierChar. Not used by JS-Interpreter.
49
- // -- Neil Fraser, February 2023.
50
- // The main exported interface (under `self.acorn` when in the
51
- // browser) is a `parse` function that takes a code string and
52
- // returns an abstract syntax tree as specified by [Mozilla parser
53
- // API][api], with the caveat that the SpiderMonkey-specific syntax
54
- // (`let`, `yield`, inline XML, etc) is not recognized.
55
- //
56
- // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
57
- /** @type {!Object|undefined} */
58
- var options;
59
- /** @type {string} */
60
- var input = '';
61
- /** @type {number|undefined} */
62
- var inputLen;
63
- /** @type {*} */
64
- var sourceFile;
65
- /**
66
- * @param {string} inpt
67
- * @param {Object=} opts
68
- * @returns
69
- */
70
- exports.parse = function (inpt, opts) {
71
- input = String(inpt);
72
- inputLen = input.length;
73
- setOptions(opts);
74
- initTokenState();
75
- return parseTopLevel(options.program);
76
- };
77
- // A second optional argument can be given to further configure
78
- // the parser process. These options are recognized:
79
- var defaultOptions = {
80
- // JS-Interpreter change:
81
- // `ecmaVersion` option has been removed along with all cases where
82
- // it is checked. In this version of Acorn it was limited to 3 or 5,
83
- // and there's no use case for 3 with JS-Interpreter.
84
- // -- Neil Fraser, December 2022.
85
- // Turn on `strictSemicolons` to prevent the parser from doing
86
- // automatic semicolon insertion.
87
- strictSemicolons: false,
88
- // When `allowTrailingCommas` is false, the parser will not allow
89
- // trailing commas in array and object literals.
90
- allowTrailingCommas: true,
91
- // By default, reserved words are not enforced. Enable
92
- // `forbidReserved` to enforce them. When this option has the
93
- // value "everywhere", reserved words and keywords can also not be
94
- // used as property names.
95
- forbidReserved: false,
96
- // When enabled, a return at the top level is not considered an
97
- // error.
98
- allowReturnOutsideFunction: false,
99
- // When `locations` is on, `loc` properties holding objects with
100
- // `start` and `end` properties in `{line, column}` form (with
101
- // line being 1-based and column 0-based) will be attached to the
102
- // nodes.
103
- locations: false,
104
- // A function can be passed as `onComment` option, which will
105
- // cause Acorn to call that function with `(block, text, start,
106
- // end)` parameters whenever a comment is skipped. `block` is a
107
- // boolean indicating whether this is a block (`/* */`) comment,
108
- // `text` is the content of the comment, and `start` and `end` are
109
- // character offsets that denote the start and end of the comment.
110
- // When the `locations` option is on, two more parameters are
111
- // passed, the full `{line, column}` locations of the start and
112
- // end of the comments. Note that you are not allowed to call the
113
- // parser from the callback—that will corrupt its internal state.
114
- onComment: null,
115
- // Nodes have their start and end characters offsets recorded in
116
- // `start` and `end` properties (directly on the node, rather than
117
- // the `loc` object, which holds line/column data. To also add a
118
- // [semi-standardized][range] `range` property holding a `[start,
119
- // end]` array with the same numbers, set the `ranges` option to
120
- // `true`.
121
- //
122
- // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
123
- ranges: false,
124
- // It is possible to parse multiple files into a single AST by
125
- // passing the tree produced by parsing the first file as
126
- // `program` option in subsequent parses. This will add the
127
- // toplevel forms of the parsed file to the `Program` (top) node
128
- // of an existing parse tree.
129
- program: null,
130
- // When `locations` is on, you can pass this to record the source
131
- // file in every node's `loc` object.
132
- sourceFile: null,
133
- // This value, if given, is stored in every node, whether
134
- // `locations` is on or off.
135
- directSourceFile: null
136
- };
137
- /**
138
- * @param {Object|undefined} opts
139
- */
140
- function setOptions(opts) {
141
- options = opts || {};
142
- for (var opt in defaultOptions) {
143
- if (!Object.prototype.hasOwnProperty.call(options, opt)) {
144
- options[opt] = defaultOptions[opt];
145
- }
146
- }
147
- sourceFile = options.sourceFile;
148
- }
149
- /**
150
- * The `getLineInfo` function is mostly useful when the
151
- * `locations` option is off (for performance reasons) and you
152
- * want to find the line/column position for a given character
153
- * offset. `input` should be the code string that the offset refers
154
- * into.
155
- *
156
- * @param {string} input
157
- * @param {number} offset
158
- * @returns {!Object}
159
- */
160
- var getLineInfo = function (input, offset) {
161
- for (var line = 1, cur = 0;;) {
162
- lineBreak.lastIndex = cur;
163
- var match = lineBreak.exec(input);
164
- if (match && match.index < offset) {
165
- ++line;
166
- cur = match.index + match[0].length;
167
- }
168
- else {
169
- break;
170
- }
171
- }
172
- return {
173
- line,
174
- column: offset - cur
175
- };
176
- };
177
- // JS-Interpreter change:
178
- // tokenize function never used. Removed.
179
- // -- Neil Fraser, February 2023.
180
- // State is kept in (closure-)global variables. We already saw the
181
- // `options`, `input`, and `inputLen` variables above.
182
- /**
183
- * The current position of the tokenizer in the input.
184
- * @type {number}
185
- */
186
- var tokPos = 0;
187
- /**
188
- * The start offset of the current token.
189
- * @type {number}
190
- */
191
- var tokStart = 0;
192
- /**
193
- * The end offset of the current token.
194
- * @type {number}
195
- */
196
- var tokEnd = 0;
197
- /**
198
- * When `options.locations` is true, holds object
199
- * containing the token's start line/column pairs.
200
- * @type {!line_loc_t|undefined}
201
- */
202
- var tokStartLoc;
203
- /**
204
- * When `options.locations` is true, holds object
205
- * containing the token's end line/column pairs.
206
- * @type {!line_loc_t|undefined}
207
- */
208
- var tokEndLoc;
209
- /**
210
- * The type of the current token. Token types are objects,
211
- * named by variables against which they can be compared, and
212
- * holding properties that describe them (indicating, for example,
213
- * the precedence of an infix operator, and the original name of a
214
- * keyword token).
215
- * @type {!Object|undefined}
216
- */
217
- var tokType;
218
- /**
219
- * The value of the current token. The kind of value that's held in
220
- * `tokVal` depends on the type of the token. For literals, it is the
221
- * literal value, for operators, the operator name, and so on.
222
- * @type {*}
223
- */
224
- var tokVal;
225
- /**
226
- * Interal state for the tokenizer. To distinguish between division
227
- * operators and regular expressions, it remembers whether the last
228
- * token was one that is allowed to be followed by an expression.
229
- * (If it is, a slash is probably a regexp, if it isn't it's a
230
- * division operator. See the `parseStatement` function for a caveat.)
231
- * @type {boolean|undefined}
232
- */
233
- var tokRegexpAllowed;
234
- /**
235
- * When `options.locations` is true, `tokCurLine` is used to keep
236
- * track of the current line.
237
- * @type {number|undefined}
238
- */
239
- var tokCurLine;
240
- /**
241
- * When `options.locations` is true, `tokLineStart` is used to know
242
- * when a new line has been entered.
243
- * @type {number|undefined}
244
- */
245
- var tokLineStart;
246
- /**
247
- * The start of the position of the previous token, which is useful
248
- * when finishing a node and assigning its `end` position.
249
- * @type {number}
250
- */
251
- var lastStart = 0;
252
- /**
253
- * The end oy the position of the previous token, which is useful
254
- * when finishing a node and assigning its `end` position.
255
- * @type {number}
256
- */
257
- var lastEnd = 0;
258
- /**
259
- * Stores the position of the previous token, which is useful
260
- * when finishing a node and assigning its `end` position.
261
- * @type {!line_loc_t|undefined}
262
- */
263
- var lastEndLoc;
264
- /**
265
- * `inFunction` is used to reject `return` statements outside of functions.
266
- * @type {boolean|undefined}
267
- */
268
- var inFunction;
269
- /**
270
- * `labels` is used to verify that `break` and `continue` have somewhere
271
- * to jump to.
272
- * @type {!Array<!Object>|undefined}
273
- */
274
- var labels;
275
- /**
276
- * `strict` indicates whether strict mode is on.
277
- * @type {boolean|undefined}
278
- */
279
- var strict;
280
- /**
281
- * This function is used to raise exceptions on parse errors. It
282
- * takes an offset integer (into the current `input`) to indicate
283
- * the location of the error, attaches the position to the end
284
- * of the error message, and then raises a `SyntaxError` with that
285
- * message.
286
- *
287
- * @param {number} pos
288
- * @param {string} message
289
- * @throws {SyntaxError}
290
- */
291
- function raise(pos, message) {
292
- var loc = getLineInfo(input, pos);
293
- message += ' (' + loc.line + ':' + loc.column + ')';
294
- var err = new SyntaxError(message);
295
- err.pos = pos;
296
- err.loc = loc;
297
- err.raisedAt = tokPos;
298
- throw err;
299
- }
300
- // Reused empty array added for node fields that are always empty.
301
- var empty = [];
302
- // ## Token types
303
- // The assignment of fine-grained, information-carrying type objects
304
- // allows the tokenizer to store the information it has about a
305
- // token in a way that is very cheap for the parser to look up.
306
- // All token type variables start with an underscore, to make them
307
- // easy to recognize.
308
- // These are the general types. The `type` property is only used to
309
- // make them recognizeable when debugging.
310
- var _num = {
311
- type: 'num'
312
- };
313
- var _regexp = {
314
- type: 'regexp'
315
- };
316
- var _string = {
317
- type: 'string'
318
- };
319
- var _name = {
320
- type: 'name'
321
- };
322
- var _eof = {
323
- type: 'eof'
324
- };
325
- // Keyword tokens. The `keyword` property (also used in keyword-like
326
- // operators) indicates that the token originated from an
327
- // identifier-like word, which is used when parsing property names.
328
- //
329
- // The `beforeExpr` property is used to disambiguate between regular
330
- // expressions and divisions. It is set on all token types that can
331
- // be followed by an expression (thus, a slash after them would be a
332
- // regular expression).
333
- //
334
- // `isLoop` marks a keyword as starting a loop, which is important
335
- // to know when parsing a label, in order to allow or disallow
336
- // continue jumps to that label.
337
- var _break = {
338
- keyword: 'break'
339
- };
340
- var _case = {
341
- keyword: 'case',
342
- beforeExpr: true
343
- };
344
- var _catch = {
345
- keyword: 'catch'
346
- };
347
- var _continue = {
348
- keyword: 'continue'
349
- };
350
- var _debugger = {
351
- keyword: 'debugger'
352
- };
353
- var _default = {
354
- keyword: 'default'
355
- };
356
- var _do = {
357
- keyword: 'do',
358
- isLoop: true
359
- };
360
- var _else = {
361
- keyword: 'else',
362
- beforeExpr: true
363
- };
364
- var _finally = {
365
- keyword: 'finally'
366
- };
367
- var _for = {
368
- keyword: 'for',
369
- isLoop: true
370
- };
371
- var _function = {
372
- keyword: 'function'
373
- };
374
- var _if = {
375
- keyword: 'if'
376
- };
377
- var _return = {
378
- keyword: 'return',
379
- beforeExpr: true
380
- };
381
- var _switch = {
382
- keyword: 'switch'
383
- };
384
- var _throw = {
385
- keyword: 'throw',
386
- beforeExpr: true
387
- };
388
- var _try = {
389
- keyword: 'try'
390
- };
391
- var _var = {
392
- keyword: 'var'
393
- };
394
- var _while = {
395
- keyword: 'while',
396
- isLoop: true
397
- };
398
- var _with = {
399
- keyword: 'with'
400
- };
401
- var _new = {
402
- keyword: 'new',
403
- beforeExpr: true
404
- };
405
- var _this = {
406
- keyword: 'this'
407
- };
408
- // The keywords that denote values.
409
- var _null = {
410
- keyword: 'null',
411
- atomValue: null
412
- };
413
- var _true = {
414
- keyword: 'true',
415
- atomValue: true
416
- };
417
- var _false = {
418
- keyword: 'false',
419
- atomValue: false
420
- };
421
- // Some keywords are treated as regular operators. `in` sometimes
422
- // (when parsing `for`) needs to be tested against specifically, so
423
- // we assign a variable name to it for quick comparing.
424
- var _in = {
425
- keyword: 'in',
426
- binop: 7,
427
- beforeExpr: true
428
- };
429
- // Map keyword names to token types.
430
- var keywordTypes = {
431
- break: _break,
432
- case: _case,
433
- catch: _catch,
434
- continue: _continue,
435
- debugger: _debugger,
436
- default: _default,
437
- do: _do,
438
- else: _else,
439
- finally: _finally,
440
- for: _for,
441
- function: _function,
442
- if: _if,
443
- return: _return,
444
- switch: _switch,
445
- throw: _throw,
446
- try: _try,
447
- var: _var,
448
- while: _while,
449
- with: _with,
450
- null: _null,
451
- true: _true,
452
- false: _false,
453
- new: _new,
454
- in: _in,
455
- instanceof: {
456
- keyword: 'instanceof',
457
- binop: 7,
458
- beforeExpr: true
459
- },
460
- this: _this,
461
- typeof: {
462
- keyword: 'typeof',
463
- prefix: true,
464
- beforeExpr: true
465
- },
466
- void: {
467
- keyword: 'void',
468
- prefix: true,
469
- beforeExpr: true
470
- },
471
- delete: {
472
- keyword: 'delete',
473
- prefix: true,
474
- beforeExpr: true
475
- }
476
- };
477
- // Punctuation token types. Again, the `type` property is purely for debugging.
478
- var _bracketL = {
479
- type: '[',
480
- beforeExpr: true
481
- };
482
- var _bracketR = {
483
- type: ']'
484
- };
485
- var _braceL = {
486
- type: '{',
487
- beforeExpr: true
488
- };
489
- var _braceR = {
490
- type: '}'
491
- };
492
- var _parenL = {
493
- type: '(',
494
- beforeExpr: true
495
- };
496
- var _parenR = {
497
- type: ')'
498
- };
499
- var _comma = {
500
- type: ',',
501
- beforeExpr: true
502
- };
503
- var _semi = {
504
- type: ';',
505
- beforeExpr: true
506
- };
507
- var _colon = {
508
- type: ':',
509
- beforeExpr: true
510
- };
511
- var _dot = {
512
- type: '.'
513
- };
514
- var _question = {
515
- type: '?',
516
- beforeExpr: true
517
- };
518
- // Operators. These carry several kinds of properties to help the
519
- // parser use them properly (the presence of these properties is
520
- // what categorizes them as operators).
521
- //
522
- // `binop`, when present, specifies that this operator is a binary
523
- // operator, and will refer to its precedence.
524
- //
525
- // `prefix` and `postfix` mark the operator as a prefix or postfix
526
- // unary operator. `isUpdate` specifies that the node produced by
527
- // the operator should be of type UpdateExpression rather than
528
- // simply UnaryExpression (`++` and `--`).
529
- //
530
- // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
531
- // binary operators with a very low precedence, that should result
532
- // in AssignmentExpression nodes.
533
- var _slash = {
534
- binop: 10,
535
- beforeExpr: true
536
- };
537
- var _eq = {
538
- isAssign: true,
539
- beforeExpr: true
540
- };
541
- var _assign = {
542
- isAssign: true,
543
- beforeExpr: true
544
- };
545
- var _incDec = {
546
- postfix: true,
547
- prefix: true,
548
- isUpdate: true
549
- };
550
- var _prefix = {
551
- prefix: true,
552
- beforeExpr: true
553
- };
554
- var _logicalOR = {
555
- binop: 1,
556
- beforeExpr: true
557
- };
558
- var _logicalAND = {
559
- binop: 2,
560
- beforeExpr: true
561
- };
562
- var _bitwiseOR = {
563
- binop: 3,
564
- beforeExpr: true
565
- };
566
- var _bitwiseXOR = {
567
- binop: 4,
568
- beforeExpr: true
569
- };
570
- var _bitwiseAND = {
571
- binop: 5,
572
- beforeExpr: true
573
- };
574
- var _equality = {
575
- binop: 6,
576
- beforeExpr: true
577
- };
578
- var _relational = {
579
- binop: 7,
580
- beforeExpr: true
581
- };
582
- var _bitShift = {
583
- binop: 8,
584
- beforeExpr: true
585
- };
586
- var _plusMin = {
587
- binop: 9,
588
- prefix: true,
589
- beforeExpr: true
590
- };
591
- var _multiplyModulo = {
592
- binop: 10,
593
- beforeExpr: true
594
- };
595
- // JS-Interpreter change:
596
- // tokTypes map never used. Removed.
597
- // -- Neil Fraser, February 2023.
598
- // JS-Interpreter change:
599
- // Acorn's original code built up functions using strings for maximum efficiency.
600
- // However, this triggered a CSP unsafe-eval requirement. Here's a slower, but
601
- // simpler approach. -- Neil Fraser, January 2022.
602
- // https://github.com/NeilFraser/JS-Interpreter/issues/228
603
- /**
604
- * @param {string} words
605
- * @returns {function(*): boolean}
606
- */
607
- function makePredicate(words) {
608
- var wordList = words.split(' ');
609
- var set = Object.create(null);
610
- for (var i = 0; i < wordList.length; i++) {
611
- set[wordList[i]] = true;
612
- }
613
- return function (str) {
614
- return set[str] || false;
615
- };
616
- }
617
- // ECMAScript 5 reserved words.
618
- var isReservedWord5 = makePredicate('class enum extends super const export import');
619
- // The additional reserved words in strict mode.
620
- var isStrictReservedWord = makePredicate('implements interface let package private protected public static yield');
621
- // The forbidden variable names in strict mode.
622
- var isStrictBadIdWord = makePredicate('eval arguments');
623
- // And the keywords.
624
- 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');
625
- // ## Character categories
626
- // Big ugly regular expressions that match characters in the
627
- // whitespace, identifier, and identifier-start categories. These
628
- // are only applied when a character is found to actually have a
629
- // code point above 128.
630
- var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
631
- 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';
632
- 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';
633
- var nonASCIIidentifierStart = new RegExp('[' + nonASCIIidentifierStartChars + ']');
634
- var nonASCIIidentifier = new RegExp('[' + nonASCIIidentifierStartChars + nonASCIIidentifierChars + ']');
635
- // Whether a single character denotes a newline.
636
- var newline = /[\n\r\u2028\u2029]/;
637
- // Matches a whole line break (where CRLF is considered a single
638
- // line break). Used to count lines.
639
- var lineBreak = /\r\n|[\n\r\u2028\u2029]/g;
640
- /**
641
- * Test whether a given character code starts an identifier.
642
- *
643
- * @param {number} code
644
- * @returns {boolean}
645
- */
646
- var isIdentifierStart = function (code) {
647
- if (code < 65)
648
- return code === 36;
649
- if (code < 91)
650
- return true;
651
- if (code < 97)
652
- return code === 95;
653
- if (code < 123)
654
- return true;
655
- return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
656
- };
657
- /**
658
- * Test whether a given character is part of an identifier.
659
- *
660
- * @param {number} code
661
- * @returns {boolean}
662
- */
663
- var isIdentifierChar = function (code) {
664
- if (code < 48)
665
- return code === 36;
666
- if (code < 58)
667
- return true;
668
- if (code < 65)
669
- return false;
670
- if (code < 91)
671
- return true;
672
- if (code < 97)
673
- return code === 95;
674
- if (code < 123)
675
- return true;
676
- return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
677
- };
678
- // ## Tokenizer
679
- /**
680
- * These are used when `options.locations` is on, for the
681
- * `tokStartLoc` and `tokEndLoc` properties.
682
- * @constructor
683
- */
684
- function line_loc_t() {
685
- this.line = tokCurLine;
686
- this.column = tokPos - tokLineStart;
687
- }
688
- /**
689
- * Reset the token state. Used at the start of a parse.
690
- */
691
- function initTokenState() {
692
- tokCurLine = 1;
693
- tokPos = tokLineStart = 0;
694
- tokRegexpAllowed = true;
695
- skipSpace();
696
- }
697
- /**
698
- * Called at the end of every token. Sets `tokEnd`, `tokVal`, and
699
- * `tokRegexpAllowed`, and skips the space after the token, so that
700
- * the next one's `tokStart` will point at the right position.
701
- *
702
- * @param {!Object} type
703
- * @param {*=} val
704
- */
705
- function finishToken(type, val) {
706
- tokEnd = tokPos;
707
- if (options.locations) {
708
- tokEndLoc = new line_loc_t();
709
- }
710
- tokType = type;
711
- skipSpace();
712
- tokVal = val;
713
- tokRegexpAllowed = type.beforeExpr;
714
- }
715
- function skipBlockComment() {
716
- var startLoc = options.onComment && options.locations && new line_loc_t();
717
- var start = tokPos;
718
- var end = input.indexOf('*/', tokPos += 2);
719
- if (end === -1) {
720
- raise(tokPos - 2, 'Unterminated comment');
721
- }
722
- tokPos = end + 2;
723
- if (options.locations) {
724
- lineBreak.lastIndex = start;
725
- var match;
726
- while ((match = lineBreak.exec(input)) && match.index < tokPos) {
727
- ++tokCurLine;
728
- tokLineStart = match.index + match[0].length;
729
- }
730
- }
731
- if (options.onComment) {
732
- options.onComment(true, input.slice(start + 2, end), start, tokPos, startLoc, options.locations && new line_loc_t());
733
- }
734
- }
735
- function skipLineComment() {
736
- var start = tokPos;
737
- var startLoc = options.onComment && options.locations && new line_loc_t();
738
- var ch = input.charCodeAt(tokPos += 2);
739
- while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
740
- ++tokPos;
741
- ch = input.charCodeAt(tokPos);
742
- }
743
- if (options.onComment) {
744
- options.onComment(false, input.slice(start + 2, tokPos), start, tokPos, startLoc, options.locations && new line_loc_t());
745
- }
746
- }
747
- // Called at the start of the parse and after every token. Skips
748
- // whitespace and comments, and.
749
- function skipSpace() {
750
- while (tokPos < inputLen) {
751
- var ch = input.charCodeAt(tokPos);
752
- if (ch === 32) {
753
- // ' '
754
- ++tokPos;
755
- }
756
- else if (ch === 13) {
757
- ++tokPos;
758
- var next = input.charCodeAt(tokPos);
759
- if (next === 10) {
760
- ++tokPos;
761
- }
762
- if (options.locations) {
763
- ++tokCurLine;
764
- tokLineStart = tokPos;
765
- }
766
- }
767
- else if (ch === 10 || ch === 8232 || ch === 8233) {
768
- ++tokPos;
769
- if (options.locations) {
770
- ++tokCurLine;
771
- tokLineStart = tokPos;
772
- }
773
- }
774
- else if (ch > 8 && ch < 14) {
775
- ++tokPos;
776
- }
777
- else if (ch === 47) {
778
- // '/'
779
- var next = input.charCodeAt(tokPos + 1);
780
- if (next === 42) {
781
- // '*'
782
- skipBlockComment();
783
- }
784
- else if (next === 47) {
785
- // '/'
786
- skipLineComment();
787
- }
788
- else
789
- break;
790
- }
791
- else if (ch === 160) {
792
- // '\xa0'
793
- ++tokPos;
794
- }
795
- else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
796
- ++tokPos;
797
- }
798
- else {
799
- break;
800
- }
801
- }
802
- }
803
- // ### Token reading
804
- // This is the function that is called to fetch the next token. It
805
- // is somewhat obscure, because it works in character codes rather
806
- // than characters, and because operator parsing has been inlined
807
- // into it.
808
- //
809
- // All in the name of speed.
810
- //
811
- // The `forceRegexp` parameter is used in the one case where the
812
- // `tokRegexpAllowed` trick does not work. See `parseStatement`.
813
- function readToken_dot() {
814
- var next = input.charCodeAt(tokPos + 1);
815
- if (next >= 48 && next <= 57) {
816
- readNumber(true);
817
- }
818
- else {
819
- ++tokPos;
820
- finishToken(_dot);
821
- }
822
- }
823
- function readToken_slash() {
824
- // '/'
825
- var next = input.charCodeAt(tokPos + 1);
826
- if (tokRegexpAllowed) {
827
- ++tokPos;
828
- readRegexp();
829
- }
830
- else if (next === 61) {
831
- finishOp(_assign, 2);
832
- }
833
- else {
834
- finishOp(_slash, 1);
835
- }
836
- }
837
- function readToken_mult_modulo() {
838
- // '%*'
839
- var next = input.charCodeAt(tokPos + 1);
840
- if (next === 61) {
841
- finishOp(_assign, 2);
842
- }
843
- else {
844
- finishOp(_multiplyModulo, 1);
845
- }
846
- }
847
- /**
848
- * @param {number} code
849
- */
850
- function readToken_pipe_amp(code) {
851
- // '|&'
852
- var next = input.charCodeAt(tokPos + 1);
853
- if (next === code) {
854
- finishOp(code === 124 ? _logicalOR : _logicalAND, 2);
855
- }
856
- else if (next === 61) {
857
- finishOp(_assign, 2);
858
- }
859
- else {
860
- finishOp(code === 124 ? _bitwiseOR : _bitwiseAND, 1);
861
- }
862
- }
863
- function readToken_caret() {
864
- // '^'
865
- var next = input.charCodeAt(tokPos + 1);
866
- if (next === 61) {
867
- finishOp(_assign, 2);
868
- }
869
- else {
870
- finishOp(_bitwiseXOR, 1);
871
- }
872
- }
873
- /**
874
- * @param {number} code
875
- */
876
- function readToken_plus_min(code) {
877
- // '+-'
878
- var next = input.charCodeAt(tokPos + 1);
879
- if (next === code) {
880
- if (next === 45 && input.charCodeAt(tokPos + 2) === 62 && newline.test(input.slice(lastEnd, tokPos))) {
881
- // A `-->` line comment
882
- tokPos += 3;
883
- skipLineComment();
884
- skipSpace();
885
- readToken();
886
- return;
887
- }
888
- finishOp(_incDec, 2);
889
- }
890
- else if (next === 61) {
891
- finishOp(_assign, 2);
892
- }
893
- else {
894
- finishOp(_plusMin, 1);
895
- }
896
- }
897
- /**
898
- * @param {number} code
899
- */
900
- function readToken_lt_gt(code) {
901
- // '<>'
902
- var next = input.charCodeAt(tokPos + 1);
903
- var size = 1;
904
- if (next === code) {
905
- size = code === 62 && input.charCodeAt(tokPos + 2) === 62 ? 3 : 2;
906
- if (input.charCodeAt(tokPos + size) === 61) {
907
- finishOp(_assign, size + 1);
908
- }
909
- else {
910
- finishOp(_bitShift, size);
911
- }
912
- return;
913
- }
914
- if (next === 33 && code === 60 && input.charCodeAt(tokPos + 2) === 45 && input.charCodeAt(tokPos + 3) === 45) {
915
- // `<!--`, an XML-style comment that should be interpreted as a line comment
916
- tokPos += 4;
917
- skipLineComment();
918
- skipSpace();
919
- readToken();
920
- return;
921
- }
922
- if (next === 61) {
923
- size = input.charCodeAt(tokPos + 2) === 61 ? 3 : 2;
924
- }
925
- finishOp(_relational, size);
926
- }
927
- /**
928
- * @param {number} code
929
- */
930
- function readToken_eq_excl(code) {
931
- // '=!'
932
- var next = input.charCodeAt(tokPos + 1);
933
- if (next === 61) {
934
- finishOp(_equality, input.charCodeAt(tokPos + 2) === 61 ? 3 : 2);
935
- }
936
- else {
937
- finishOp(code === 61 ? _eq : _prefix, 1);
938
- }
939
- }
940
- /**
941
- * @param {number} code
942
- * @returns {boolean|undefined}
943
- */
944
- function getTokenFromCode(code) {
945
- switch (code) {
946
- // The interpretation of a dot depends on whether it is followed
947
- // by a digit.
948
- case 46:
949
- // '.'
950
- return readToken_dot();
951
- // Punctuation tokens.
952
- case 40:
953
- ++tokPos;
954
- return finishToken(_parenL);
955
- case 41:
956
- ++tokPos;
957
- return finishToken(_parenR);
958
- case 59:
959
- ++tokPos;
960
- return finishToken(_semi);
961
- case 44:
962
- ++tokPos;
963
- return finishToken(_comma);
964
- case 91:
965
- ++tokPos;
966
- return finishToken(_bracketL);
967
- case 93:
968
- ++tokPos;
969
- return finishToken(_bracketR);
970
- case 123:
971
- ++tokPos;
972
- return finishToken(_braceL);
973
- case 125:
974
- ++tokPos;
975
- return finishToken(_braceR);
976
- case 58:
977
- ++tokPos;
978
- return finishToken(_colon);
979
- case 63:
980
- ++tokPos;
981
- return finishToken(_question);
982
- // '0x' is a hexadecimal number.
983
- case 48:
984
- // '0'
985
- var next = input.charCodeAt(tokPos + 1);
986
- if (next === 120 || next === 88)
987
- return readHexNumber();
988
- // Anything else beginning with a digit is an integer, octal
989
- // number, or float.
990
- case 49:
991
- case 50:
992
- case 51:
993
- case 52:
994
- case 53:
995
- case 54:
996
- case 55:
997
- case 56:
998
- case 57:
999
- // 1-9
1000
- return readNumber(false);
1001
- // Quotes produce strings.
1002
- case 34:
1003
- case 39:
1004
- // '"', "'"
1005
- return readString(code);
1006
- // Operators are parsed inline in tiny state machines. '=' (61) is
1007
- // often referred to. `finishOp` simply skips the amount of
1008
- // characters it is given as second argument, and returns a token
1009
- // of the type given by its first argument.
1010
- case 47:
1011
- // '/'
1012
- return readToken_slash();
1013
- case 37:
1014
- case 42:
1015
- // '%*'
1016
- return readToken_mult_modulo();
1017
- case 124:
1018
- case 38:
1019
- // '|&'
1020
- return readToken_pipe_amp(code);
1021
- case 94:
1022
- // '^'
1023
- return readToken_caret();
1024
- case 43:
1025
- case 45:
1026
- // '+-'
1027
- return readToken_plus_min(code);
1028
- case 60:
1029
- case 62:
1030
- // '<>'
1031
- return readToken_lt_gt(code);
1032
- case 61:
1033
- case 33:
1034
- // '=!'
1035
- return readToken_eq_excl(code);
1036
- case 126:
1037
- // '~'
1038
- return finishOp(_prefix, 1);
1039
- }
1040
- return false;
1041
- }
1042
- /**
1043
- * @param {boolean=} forceRegexp
1044
- */
1045
- function readToken(forceRegexp) {
1046
- if (!forceRegexp) {
1047
- tokStart = tokPos;
1048
- }
1049
- else {
1050
- tokPos = tokStart + 1;
1051
- }
1052
- if (options.locations) {
1053
- tokStartLoc = new line_loc_t();
1054
- }
1055
- if (forceRegexp)
1056
- return readRegexp();
1057
- if (tokPos >= inputLen)
1058
- return finishToken(_eof);
1059
- var code = input.charCodeAt(tokPos);
1060
- // Identifier or keyword. '\uXXXX' sequences are allowed in
1061
- // identifiers, so '\' also dispatches to that.
1062
- if (isIdentifierStart(code) || code === 92) {
1063
- // '\'
1064
- return readWord();
1065
- }
1066
- var tok = getTokenFromCode(code);
1067
- if (tok === false) {
1068
- // If we are here, we either found a non-ASCII identifier
1069
- // character, or something that's entirely disallowed.
1070
- var ch = String.fromCharCode(code);
1071
- if (ch === '\\' || nonASCIIidentifierStart.test(ch)) {
1072
- return readWord();
1073
- }
1074
- raise(tokPos, "Unexpected character '" + ch + "'");
1075
- }
1076
- }
1077
- /**
1078
- * @param {!Object} type
1079
- * @param {number} size
1080
- */
1081
- function finishOp(type, size) {
1082
- var str = input.slice(tokPos, tokPos + size);
1083
- tokPos += size;
1084
- finishToken(type, str);
1085
- }
1086
- /**
1087
- * Parse a regular expression. Some context-awareness is necessary,
1088
- * since a '/' inside a '[]' set does not end the expression.
1089
- */
1090
- function readRegexp() {
1091
- // JS-Interpreter change:
1092
- // Removed redundant declaration of 'content' here. Caused lint errors.
1093
- // -- Neil Fraser, June 2022.
1094
- var escaped;
1095
- var inClass;
1096
- var start = tokPos;
1097
- for (;;) {
1098
- if (tokPos >= inputLen)
1099
- raise(start, 'Unterminated regexp');
1100
- var ch = input.charAt(tokPos);
1101
- if (newline.test(ch))
1102
- raise(start, 'Unterminated regexp');
1103
- if (!escaped) {
1104
- if (ch === '[') {
1105
- inClass = true;
1106
- }
1107
- else if (ch === ']' && inClass) {
1108
- inClass = false;
1109
- }
1110
- else if (ch === '/' && !inClass) {
1111
- break;
1112
- }
1113
- escaped = ch === '\\';
1114
- }
1115
- else
1116
- escaped = false;
1117
- ++tokPos;
1118
- }
1119
- var content = input.slice(start, tokPos);
1120
- ++tokPos;
1121
- // Need to use `readWord1` because '\uXXXX' sequences are allowed
1122
- // here (don't ask).
1123
- var mods = readWord1();
1124
- // JS-Interpreter change:
1125
- // Acorn used to use 'gmsiy' to check for flags. But 's' and 'y' are ES6.
1126
- // -- Neil Fraser, December 2022.
1127
- // https://github.com/acornjs/acorn/issues/1163
1128
- if (mods && !/^[gmi]*$/.test(mods)) {
1129
- raise(start, 'Invalid regexp flag');
1130
- }
1131
- try {
1132
- var value = new RegExp(content, mods);
1133
- }
1134
- catch (e) {
1135
- if (e instanceof SyntaxError)
1136
- raise(start, e.message);
1137
- // JS-Interpreter change:
1138
- // Acorn used to use raise(e) here which is incorrect.
1139
- // -- Neil Fraser, July 2023.
1140
- throw e;
1141
- }
1142
- finishToken(_regexp, value);
1143
- }
1144
- /**
1145
- * Read an integer in the given radix. Return null if zero digits
1146
- * were read, the integer value otherwise. When `len` is given, this
1147
- * will return `null` unless the integer has exactly `len` digits.
1148
- * @param {number} radix
1149
- * @param {number=} len
1150
- * @returns {?number}
1151
- */
1152
- function readInt(radix, len) {
1153
- var start = tokPos;
1154
- var total = 0;
1155
- var e = len === undefined ? Infinity : len;
1156
- for (var i = 0; i < e; ++i) {
1157
- var code = input.charCodeAt(tokPos), val;
1158
- if (code >= 97) {
1159
- val = code - 97 + 10; // a
1160
- }
1161
- else if (code >= 65) {
1162
- val = code - 65 + 10; // A
1163
- }
1164
- else if (code >= 48 && code <= 57) {
1165
- val = code - 48; // 0-9
1166
- }
1167
- else {
1168
- val = Infinity;
1169
- }
1170
- if (val >= radix)
1171
- break;
1172
- ++tokPos;
1173
- total = total * radix + val;
1174
- }
1175
- if (tokPos === start || len !== undefined && tokPos - start !== len) {
1176
- return null;
1177
- }
1178
- return total;
1179
- }
1180
- function readHexNumber() {
1181
- tokPos += 2; // 0x
1182
- var val = readInt(16);
1183
- if (val === null) {
1184
- raise(tokStart + 2, 'Expected hexadecimal number');
1185
- }
1186
- if (isIdentifierStart(input.charCodeAt(tokPos))) {
1187
- raise(tokPos, 'Identifier directly after number');
1188
- }
1189
- finishToken(_num, val);
1190
- }
1191
- /**
1192
- * Read an integer, octal integer, or floating-point number.
1193
- *
1194
- * @param {boolean} startsWithDot
1195
- */
1196
- function readNumber(startsWithDot) {
1197
- var start = tokPos;
1198
- var isFloat = false;
1199
- var octal = input.charCodeAt(tokPos) === 48;
1200
- if (!startsWithDot && readInt(10) === null) {
1201
- raise(start, 'Invalid number');
1202
- }
1203
- if (input.charCodeAt(tokPos) === 46) {
1204
- ++tokPos;
1205
- readInt(10);
1206
- isFloat = true;
1207
- }
1208
- var next = input.charCodeAt(tokPos);
1209
- if (next === 69 || next === 101) {
1210
- // 'eE'
1211
- next = input.charCodeAt(++tokPos);
1212
- if (next === 43 || next === 45) {
1213
- ++tokPos; // '+-'
1214
- }
1215
- if (readInt(10) === null) {
1216
- raise(start, 'Invalid number');
1217
- }
1218
- isFloat = true;
1219
- }
1220
- if (isIdentifierStart(input.charCodeAt(tokPos))) {
1221
- raise(tokPos, 'Identifier directly after number');
1222
- }
1223
- var str = input.slice(start, tokPos);
1224
- var val;
1225
- if (isFloat) {
1226
- val = parseFloat(str);
1227
- }
1228
- else if (!octal || str.length === 1) {
1229
- val = parseInt(str, 10);
1230
- }
1231
- else if (/[89]/.test(str) || strict) {
1232
- raise(start, 'Invalid number');
1233
- }
1234
- else {
1235
- val = parseInt(str, 8);
1236
- }
1237
- finishToken(_num, val);
1238
- }
1239
- /**
1240
- * Read a string value, interpreting backslash-escapes.
1241
- *
1242
- * @param {number} quote
1243
- */
1244
- function readString(quote) {
1245
- tokPos++;
1246
- var out = '';
1247
- for (;;) {
1248
- if (tokPos >= inputLen)
1249
- raise(tokStart, 'Unterminated string constant');
1250
- var ch = input.charCodeAt(tokPos);
1251
- if (ch === quote) {
1252
- ++tokPos;
1253
- finishToken(_string, out);
1254
- return;
1255
- }
1256
- if (ch === 92) {
1257
- // '\'
1258
- ch = input.charCodeAt(++tokPos);
1259
- var octal = /^[0-7]+/.exec(input.slice(tokPos, tokPos + 3));
1260
- if (octal) {
1261
- octal = octal[0];
1262
- }
1263
- while (octal && parseInt(octal, 8) > 255) {
1264
- octal = octal.slice(0, -1);
1265
- }
1266
- if (octal === '0') {
1267
- octal = null;
1268
- }
1269
- ++tokPos;
1270
- if (octal) {
1271
- if (strict)
1272
- raise(tokPos - 2, 'Octal literal in strict mode');
1273
- out += String.fromCharCode(parseInt(octal, 8));
1274
- tokPos += octal.length - 1;
1275
- }
1276
- else {
1277
- switch (ch) {
1278
- case 110:
1279
- out += '\n';
1280
- break;
1281
- // 'n' -> '\n'
1282
- case 114:
1283
- out += '\r';
1284
- break;
1285
- // 'r' -> '\r'
1286
- case 120:
1287
- out += String.fromCharCode(readHexChar(2));
1288
- break;
1289
- // 'x'
1290
- case 117:
1291
- out += String.fromCharCode(readHexChar(4));
1292
- break;
1293
- // 'u'
1294
- case 85:
1295
- out += String.fromCharCode(readHexChar(8));
1296
- break;
1297
- // 'U'
1298
- case 116:
1299
- out += '\t';
1300
- break;
1301
- // 't' -> '\t'
1302
- case 98:
1303
- out += '\b';
1304
- break;
1305
- // 'b' -> '\b'
1306
- case 118:
1307
- out += '\u000b';
1308
- break;
1309
- // 'v' -> '\u000b'
1310
- case 102:
1311
- out += '\f';
1312
- break;
1313
- // 'f' -> '\f'
1314
- case 48:
1315
- out += '\0';
1316
- break;
1317
- // 0 -> '\0'
1318
- case 13:
1319
- // '\r'
1320
- if (input.charCodeAt(tokPos) === 10) {
1321
- ++tokPos; // '\r\n'
1322
- }
1323
- case 10:
1324
- // ' \n'
1325
- if (options.locations) {
1326
- tokLineStart = tokPos;
1327
- ++tokCurLine;
1328
- }
1329
- break;
1330
- default:
1331
- out += String.fromCharCode(ch);
1332
- break;
1333
- }
1334
- }
1335
- }
1336
- else {
1337
- if (ch === 13 || ch === 10 || ch === 8232 || ch === 8233) {
1338
- raise(tokStart, 'Unterminated string constant');
1339
- }
1340
- out += String.fromCharCode(ch); // '\'
1341
- ++tokPos;
1342
- }
1343
- }
1344
- }
1345
- /**
1346
- * Used to read character escape sequences ('\x', '\u', '\U').
1347
- *
1348
- * @param {number} len
1349
- * @returns {number}
1350
- */
1351
- function readHexChar(len) {
1352
- var n = readInt(16, len);
1353
- if (n === null)
1354
- raise(tokStart, 'Bad character escape sequence');
1355
- return ( /** @type {number} */n);
1356
- }
1357
- // Used to signal to callers of `readWord1` whether the word
1358
- // contained any escape sequences. This is needed because words with
1359
- // escape sequences must not be interpreted as keywords.
1360
- /** @type {boolean|undefined} */
1361
- var containsEsc;
1362
- /**
1363
- * Read an identifier, and return it as a string. Sets `containsEsc`
1364
- * to whether the word contained a '\u' escape.
1365
- *
1366
- * Only builds up the word character-by-character when it actually
1367
- * containeds an escape, as a micro-optimization.
1368
- *
1369
- * @returns {string|undefined}
1370
- */
1371
- function readWord1() {
1372
- containsEsc = false;
1373
- var word;
1374
- var first = true;
1375
- var start = tokPos;
1376
- for (;;) {
1377
- var ch = input.charCodeAt(tokPos);
1378
- if (isIdentifierChar(ch)) {
1379
- if (containsEsc) {
1380
- word += input.charAt(tokPos);
1381
- }
1382
- ++tokPos;
1383
- }
1384
- else if (ch === 92) {
1385
- // "\"
1386
- if (!containsEsc) {
1387
- word = input.slice(start, tokPos);
1388
- }
1389
- containsEsc = true;
1390
- if (input.charCodeAt(++tokPos) !== 117) {
1391
- // "u"
1392
- raise(tokPos, 'Expecting Unicode escape sequence \\uXXXX');
1393
- }
1394
- ++tokPos;
1395
- var esc = readHexChar(4);
1396
- var escStr = String.fromCharCode(esc);
1397
- if (!escStr)
1398
- raise(tokPos - 1, 'Invalid Unicode escape');
1399
- if (!(first ? isIdentifierStart(esc) : isIdentifierChar(esc))) {
1400
- raise(tokPos - 4, 'Invalid Unicode escape');
1401
- }
1402
- word += escStr;
1403
- }
1404
- else {
1405
- break;
1406
- }
1407
- first = false;
1408
- }
1409
- return containsEsc ? word : input.slice(start, tokPos);
1410
- }
1411
- /**
1412
- * Read an identifier or keyword token. Will check for reserved
1413
- * words when necessary.
1414
- */
1415
- function readWord() {
1416
- var word = readWord1();
1417
- var type = _name;
1418
- if (!containsEsc && isKeyword(word)) {
1419
- type = keywordTypes[word];
1420
- }
1421
- finishToken(type, word);
1422
- }
1423
- // ## Parser
1424
- // A recursive descent parser operates by defining functions for all
1425
- // syntactic elements, and recursively calling those, each function
1426
- // advancing the input stream and returning an AST node. Precedence
1427
- // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
1428
- // instead of `(!x)[1]` is handled by the fact that the parser
1429
- // function that parses unary prefix operators is called first, and
1430
- // in turn calls the function that parses `[]` subscripts — that
1431
- // way, it'll receive the node for `x[1]` already parsed, and wraps
1432
- // *that* in the unary operator node.
1433
- //
1434
- // Acorn uses an [operator precedence parser][opp] to handle binary
1435
- // operator precedence, because it is much more compact than using
1436
- // the technique outlined above, which uses different, nesting
1437
- // functions to specify precedence, for all of the ten binary
1438
- // precedence levels that JavaScript defines.
1439
- //
1440
- // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
1441
- // ### Parser utilities
1442
- /**
1443
- * Continue to the next token.
1444
- */
1445
- function next() {
1446
- lastStart = tokStart;
1447
- lastEnd = tokEnd;
1448
- lastEndLoc = tokEndLoc;
1449
- readToken();
1450
- }
1451
- /**
1452
- * Enter strict mode. Re-reads the next token to please pedantic
1453
- * tests ("use strict"; 010; -- should fail).
1454
- *
1455
- * @param {boolean} strct
1456
- */
1457
- function setStrict(strct) {
1458
- strict = strct;
1459
- tokPos = tokStart;
1460
- if (options.locations) {
1461
- while (tokPos < tokLineStart) {
1462
- tokLineStart = input.lastIndexOf('\n', tokLineStart - 2) + 1;
1463
- --tokCurLine;
1464
- }
1465
- }
1466
- skipSpace();
1467
- readToken();
1468
- }
1469
- // Start an AST node, attaching a start offset.
1470
- /**
1471
- * @constructor
1472
- */
1473
- function node_t() {
1474
- this.type = null;
1475
- this.start = tokStart;
1476
- this.end = null;
1477
- }
1478
- /**
1479
- * @constructor
1480
- */
1481
- function node_loc_t() {
1482
- this.start = tokStartLoc;
1483
- this.end = null;
1484
- if (sourceFile) {
1485
- this.source = sourceFile;
1486
- }
1487
- }
1488
- /**
1489
- * @returns {!node_t}
1490
- */
1491
- function startNode() {
1492
- var node = new node_t();
1493
- if (options.locations) {
1494
- node.loc = new node_loc_t();
1495
- }
1496
- if (options.directSourceFile) {
1497
- node.sourceFile = options.directSourceFile;
1498
- }
1499
- if (options.ranges) {
1500
- node.range = [tokStart, 0];
1501
- }
1502
- return node;
1503
- }
1504
- /**
1505
- * Start a node whose start offset information should be based on
1506
- * the start of another node. For example, a binary operator node is
1507
- * only started after its left-hand side has already been parsed.
1508
- *
1509
- * @param {!node_t} other
1510
- * @returns {!node_t}
1511
- */
1512
- function startNodeFrom(other) {
1513
- var node = new node_t();
1514
- node.start = other.start;
1515
- if (options.locations) {
1516
- node.loc = new node_loc_t();
1517
- node.loc.start = other.loc.start;
1518
- }
1519
- if (options.ranges) {
1520
- node.range = [other.range[0], 0];
1521
- }
1522
- return node;
1523
- }
1524
- /**
1525
- * Finish an AST node, adding `type` and `end` properties.
1526
- *
1527
- * @param {!node_t} node
1528
- * @param {string} type
1529
- * @returns {!node_t}
1530
- */
1531
- function finishNode(node, type) {
1532
- node.type = type;
1533
- node.end = lastEnd;
1534
- if (options.locations) {
1535
- node.loc.end = lastEndLoc;
1536
- }
1537
- if (options.ranges) {
1538
- node.range[1] = lastEnd;
1539
- }
1540
- return node;
1541
- }
1542
- /**
1543
- * Test whether a statement node is the string literal `"use strict"`.
1544
- *
1545
- * @param {!node_t} stmt
1546
- * @returns {boolean}
1547
- */
1548
- function isUseStrict(stmt) {
1549
- return stmt.type === 'ExpressionStatement' && stmt.expression.type === 'Literal' && stmt.expression.value === 'use strict';
1550
- }
1551
- /**
1552
- * Predicate that tests whether the next token is of the given
1553
- * type, and if yes, consumes it as a side effect.
1554
- * @param {!Object} type
1555
- * @returns {boolean}
1556
- */
1557
- function eat(type) {
1558
- if (tokType === type) {
1559
- next();
1560
- return true;
1561
- }
1562
- return false;
1563
- }
1564
- /**
1565
- * Test whether a semicolon can be inserted at the current position.
1566
- *
1567
- * @returns {boolean}
1568
- */
1569
- function canInsertSemicolon() {
1570
- return !options.strictSemicolons && (tokType === _eof || tokType === _braceR || newline.test(input.slice(lastEnd, tokStart)));
1571
- }
1572
- /**
1573
- * Consume a semicolon, or, failing that, see if we are allowed to
1574
- * pretend that there is a semicolon at this position.
1575
- */
1576
- function semicolon() {
1577
- if (!eat(_semi) && !canInsertSemicolon()) {
1578
- unexpected();
1579
- }
1580
- }
1581
- /**
1582
- * Expect a token of a given type. If found, consume it, otherwise,
1583
- * raise an unexpected token error.
1584
- *
1585
- * @param {!Object} type
1586
- */
1587
- function expect(type) {
1588
- if (tokType === type) {
1589
- next();
1590
- }
1591
- else {
1592
- unexpected();
1593
- }
1594
- }
1595
- /**
1596
- * Raise an unexpected token error.
1597
- * @throws {SyntaxError}
1598
- */
1599
- function unexpected() {
1600
- raise(tokStart, 'Unexpected token');
1601
- }
1602
- /**
1603
- * Verify that a node is an lval — something that can be assigned to.
1604
- *
1605
- * @param {!node_t} expr
1606
- */
1607
- function checkLVal(expr) {
1608
- if (expr.type !== 'Identifier' && expr.type !== 'MemberExpression') {
1609
- raise(expr.start, 'Assigning to rvalue');
1610
- }
1611
- if (strict && expr.type === 'Identifier' && isStrictBadIdWord(expr.name)) {
1612
- raise(expr.start, 'Assigning to ' + expr.name + ' in strict mode');
1613
- }
1614
- }
1615
- // ### Statement parsing
1616
- /**
1617
- * Parse a program. Initializes the parser, reads any number of
1618
- * statements, and wraps them in a Program node. Optionally takes a
1619
- * `program` argument. If present, the statements will be appended
1620
- * to its body instead of creating a new node.
1621
- *
1622
- * @param {node_t} program
1623
- * @returns {!node_t}
1624
- */
1625
- function parseTopLevel(program) {
1626
- lastStart = lastEnd = tokPos;
1627
- if (options.locations) {
1628
- lastEndLoc = new line_loc_t();
1629
- }
1630
- inFunction = strict = false;
1631
- labels = [];
1632
- readToken();
1633
- var node = program || startNode();
1634
- var first = true;
1635
- if (!program) {
1636
- node.body = [];
1637
- }
1638
- while (tokType !== _eof) {
1639
- var stmt = parseStatement();
1640
- node.body.push(stmt);
1641
- if (first && isUseStrict(stmt)) {
1642
- setStrict(true);
1643
- }
1644
- first = false;
1645
- }
1646
- return finishNode(node, 'Program');
1647
- }
1648
- var loopLabel = {
1649
- kind: 'loop'
1650
- };
1651
- var switchLabel = {
1652
- kind: 'switch'
1653
- };
1654
- /**
1655
- * Parse a single statement.
1656
- *
1657
- * If expecting a statement and finding a slash operator, parse a
1658
- * regular expression literal. This is to handle cases like
1659
- * `if (foo) /blah/.exec(foo);`, where looking at the previous token
1660
- * does not help.
1661
- *
1662
- * @returns {!node_t}
1663
- */
1664
- function parseStatement() {
1665
- if (tokType === _slash || tokType === _assign && tokVal === '/=') {
1666
- readToken(true);
1667
- }
1668
- var starttype = tokType;
1669
- var node = startNode();
1670
- // Most types of statements are recognized by the keyword they
1671
- // start with. Many are trivial to parse, some require a bit of
1672
- // complexity.
1673
- switch (starttype) {
1674
- case _break:
1675
- case _continue:
1676
- next();
1677
- var isBreak = starttype === _break;
1678
- if (eat(_semi) || canInsertSemicolon()) {
1679
- node.label = null;
1680
- }
1681
- else if (tokType !== _name) {
1682
- unexpected();
1683
- }
1684
- else {
1685
- node.label = parseIdent();
1686
- semicolon();
1687
- }
1688
- // Verify that there is an actual destination to break or
1689
- // continue to.
1690
- for (var i = 0; i < labels.length; ++i) {
1691
- var lab = labels[i];
1692
- if (node.label === null || lab.name === node.label.name) {
1693
- if (lab.kind !== null && (isBreak || lab.kind === 'loop'))
1694
- break;
1695
- if (node.label && isBreak)
1696
- break;
1697
- }
1698
- }
1699
- if (i === labels.length) {
1700
- raise(node.start, 'Unsyntactic ' + starttype.keyword);
1701
- }
1702
- return finishNode(node, isBreak ? 'BreakStatement' : 'ContinueStatement');
1703
- case _debugger:
1704
- next();
1705
- semicolon();
1706
- return finishNode(node, 'DebuggerStatement');
1707
- case _do:
1708
- next();
1709
- labels.push(loopLabel);
1710
- node.body = parseStatement();
1711
- labels.pop();
1712
- expect(_while);
1713
- node.test = parseParenExpression();
1714
- semicolon();
1715
- return finishNode(node, 'DoWhileStatement');
1716
- // Disambiguating between a `for` and a `for`/`in` loop is
1717
- // non-trivial. Basically, we have to parse the init `var`
1718
- // statement or expression, disallowing the `in` operator (see
1719
- // the second parameter to `parseExpression`), and then check
1720
- // whether the next token is `in`. When there is no init part
1721
- // (semicolon immediately after the opening parenthesis), it is
1722
- // a regular `for` loop.
1723
- case _for:
1724
- next();
1725
- labels.push(loopLabel);
1726
- expect(_parenL);
1727
- if (tokType === _semi)
1728
- return parseFor(node, null);
1729
- if (tokType === _var) {
1730
- var init = startNode();
1731
- next();
1732
- parseVar(init, true);
1733
- finishNode(init, 'VariableDeclaration');
1734
- if (init.declarations.length === 1 && eat(_in))
1735
- return parseForIn(node, init);
1736
- return parseFor(node, init);
1737
- }
1738
- var init = parseExpression(false, true);
1739
- if (eat(_in)) {
1740
- checkLVal(init);
1741
- return parseForIn(node, init);
1742
- }
1743
- return parseFor(node, init);
1744
- case _function:
1745
- next();
1746
- return parseFunction(node, true);
1747
- case _if:
1748
- next();
1749
- node.test = parseParenExpression();
1750
- node.consequent = parseStatement();
1751
- node.alternate = eat(_else) ? parseStatement() : null;
1752
- return finishNode(node, 'IfStatement');
1753
- case _return:
1754
- if (!inFunction && !options.allowReturnOutsideFunction) {
1755
- raise(tokStart, "'return' outside of function");
1756
- }
1757
- next();
1758
- // In `return` (and `break`/`continue`), the keywords with
1759
- // optional arguments, we eagerly look for a semicolon or the
1760
- // possibility to insert one.
1761
- if (eat(_semi) || canInsertSemicolon()) {
1762
- node.argument = null;
1763
- }
1764
- else {
1765
- node.argument = parseExpression();
1766
- semicolon();
1767
- }
1768
- return finishNode(node, 'ReturnStatement');
1769
- case _switch:
1770
- next();
1771
- node.discriminant = parseParenExpression();
1772
- node.cases = [];
1773
- expect(_braceL);
1774
- labels.push(switchLabel);
1775
- // Statements under must be grouped (by label) in SwitchCase
1776
- // nodes. `cur` is used to keep the node that we are currently
1777
- // adding statements to.
1778
- for (var cur, sawDefault; tokType !== _braceR;) {
1779
- if (tokType === _case || tokType === _default) {
1780
- var isCase = tokType === _case;
1781
- if (cur) {
1782
- finishNode(cur, 'SwitchCase');
1783
- }
1784
- node.cases.push(cur = startNode());
1785
- cur.consequent = [];
1786
- next();
1787
- if (isCase) {
1788
- cur.test = parseExpression();
1789
- }
1790
- else {
1791
- if (sawDefault) {
1792
- raise(lastStart, 'Multiple default clauses');
1793
- }
1794
- sawDefault = true;
1795
- cur.test = null;
1796
- }
1797
- expect(_colon);
1798
- }
1799
- else {
1800
- if (!cur)
1801
- unexpected();
1802
- cur.consequent.push(parseStatement());
1803
- }
1804
- }
1805
- if (cur)
1806
- finishNode(cur, 'SwitchCase');
1807
- next(); // Closing brace
1808
- labels.pop();
1809
- return finishNode(node, 'SwitchStatement');
1810
- case _throw:
1811
- next();
1812
- if (newline.test(input.slice(lastEnd, tokStart)))
1813
- raise(lastEnd, 'Illegal newline after throw');
1814
- node.argument = parseExpression();
1815
- semicolon();
1816
- return finishNode(node, 'ThrowStatement');
1817
- case _try:
1818
- next();
1819
- node.block = parseBlock();
1820
- node.handler = null;
1821
- if (tokType === _catch) {
1822
- var clause = startNode();
1823
- next();
1824
- expect(_parenL);
1825
- clause.param = parseIdent();
1826
- if (strict && isStrictBadIdWord(clause.param.name))
1827
- raise(clause.param.start, 'Binding ' + clause.param.name + ' in strict mode');
1828
- expect(_parenR);
1829
- // JS-Interpreter change:
1830
- // Obsolete unused property; commenting out.
1831
- // -- Neil Fraser, January 2023.
1832
- // clause.guard = null;
1833
- clause.body = parseBlock();
1834
- node.handler = finishNode(clause, 'CatchClause');
1835
- }
1836
- // JS-Interpreter change:
1837
- // Obsolete unused property; commenting out.
1838
- // -- Neil Fraser, January 2023.
1839
- // node.guardedHandlers = empty;
1840
- node.finalizer = eat(_finally) ? parseBlock() : null;
1841
- if (!node.handler && !node.finalizer)
1842
- raise(node.start, 'Missing catch or finally clause');
1843
- return finishNode(node, 'TryStatement');
1844
- case _var:
1845
- next();
1846
- parseVar(node);
1847
- semicolon();
1848
- return finishNode(node, 'VariableDeclaration');
1849
- case _while:
1850
- next();
1851
- node.test = parseParenExpression();
1852
- labels.push(loopLabel);
1853
- node.body = parseStatement();
1854
- labels.pop();
1855
- return finishNode(node, 'WhileStatement');
1856
- case _with:
1857
- if (strict)
1858
- raise(tokStart, "'with' in strict mode");
1859
- next();
1860
- node.object = parseParenExpression();
1861
- node.body = parseStatement();
1862
- return finishNode(node, 'WithStatement');
1863
- case _braceL:
1864
- return parseBlock();
1865
- case _semi:
1866
- next();
1867
- return finishNode(node, 'EmptyStatement');
1868
- // If the statement does not start with a statement keyword or a
1869
- // brace, it's an ExpressionStatement or LabeledStatement. We
1870
- // simply start parsing an expression, and afterwards, if the
1871
- // next token is a colon and the expression was a simple
1872
- // Identifier node, we switch to interpreting it as a label.
1873
- default:
1874
- var maybeName = tokVal;
1875
- var expr = parseExpression();
1876
- if (starttype === _name && expr.type === 'Identifier' && eat(_colon)) {
1877
- for (var i = 0; i < labels.length; ++i) {
1878
- if (labels[i].name === maybeName) {
1879
- raise(expr.start, "Label '" + maybeName + "' is already declared");
1880
- }
1881
- }
1882
- var kind = tokType.isLoop ? 'loop' : tokType === _switch ? 'switch' : null;
1883
- labels.push({
1884
- name: maybeName,
1885
- kind
1886
- });
1887
- node.body = parseStatement();
1888
- labels.pop();
1889
- node.label = expr;
1890
- return finishNode(node, 'LabeledStatement');
1891
- }
1892
- else {
1893
- node.expression = expr;
1894
- semicolon();
1895
- return finishNode(node, 'ExpressionStatement');
1896
- }
1897
- }
1898
- }
1899
- /**
1900
- * Used for constructs like `switch` and `if` that insist on
1901
- * parentheses around their expression.
1902
- *
1903
- * @returns {!node_t}
1904
- */
1905
- function parseParenExpression() {
1906
- expect(_parenL);
1907
- var val = parseExpression();
1908
- expect(_parenR);
1909
- return val;
1910
- }
1911
- /**
1912
- * Parse a semicolon-enclosed block of statements, handling `"use
1913
- * strict"` declarations when `allowStrict` is true (used for
1914
- * function bodies).
1915
- *
1916
- * @param {boolean=} allowStrict
1917
- * @returns {!node_t}
1918
- */
1919
- function parseBlock(allowStrict) {
1920
- var node = startNode();
1921
- var first = true;
1922
- var strict = false;
1923
- var oldStrict;
1924
- node.body = [];
1925
- expect(_braceL);
1926
- while (!eat(_braceR)) {
1927
- var stmt = parseStatement();
1928
- node.body.push(stmt);
1929
- if (first && allowStrict && isUseStrict(stmt)) {
1930
- oldStrict = strict;
1931
- setStrict(strict = true);
1932
- }
1933
- first = false;
1934
- }
1935
- if (strict && !oldStrict)
1936
- setStrict(false);
1937
- return finishNode(node, 'BlockStatement');
1938
- }
1939
- /**
1940
- * Parse a regular `for` loop. The disambiguation code in `parseStatement`
1941
- * will already have parsed the init statement or expression.
1942
- *
1943
- * @param {!node_t} node
1944
- * @param {node_t} init
1945
- * @returns {!node_t}
1946
- */
1947
- function parseFor(node, init) {
1948
- node.init = init;
1949
- expect(_semi);
1950
- node.test = tokType === _semi ? null : parseExpression();
1951
- expect(_semi);
1952
- node.update = tokType === _parenR ? null : parseExpression();
1953
- expect(_parenR);
1954
- node.body = parseStatement();
1955
- labels.pop();
1956
- return finishNode(node, 'ForStatement');
1957
- }
1958
- /**
1959
- * Parse a `for`/`in` loop.
1960
- *
1961
- * @param {!node_t} node
1962
- * @param {!node_t} init
1963
- * @returns {!node_t}
1964
- */
1965
- function parseForIn(node, init) {
1966
- node.left = init;
1967
- node.right = parseExpression();
1968
- expect(_parenR);
1969
- node.body = parseStatement();
1970
- labels.pop();
1971
- return finishNode(node, 'ForInStatement');
1972
- }
1973
- /**
1974
- * Parse a list of variable declarations.
1975
- *
1976
- * @param {!node_t} node
1977
- * @param {boolean=} noIn
1978
- */
1979
- function parseVar(node, noIn) {
1980
- node.declarations = [];
1981
- node.kind = 'var';
1982
- for (;;) {
1983
- var decl = startNode();
1984
- decl.id = parseIdent();
1985
- if (strict && isStrictBadIdWord(decl.id.name))
1986
- raise(decl.id.start, 'Binding ' + decl.id.name + ' in strict mode');
1987
- decl.init = eat(_eq) ? parseExpression(true, noIn) : null;
1988
- node.declarations.push(finishNode(decl, 'VariableDeclarator'));
1989
- if (!eat(_comma))
1990
- break;
1991
- }
1992
- }
1993
- // ### Expression parsing
1994
- // These nest, from the most general expression type at the top to
1995
- // 'atomic', nondivisible expression types at the bottom. Most of
1996
- // the functions will simply let the function(s) below them parse,
1997
- // and, *if* the syntactic construct they handle is present, wrap
1998
- // the AST node that the inner parser gave them in another node.
1999
- /**
2000
- * Parse a full expression. The arguments are used to forbid comma
2001
- * sequences (in argument lists, array literals, or object literals)
2002
- * or the `in` operator (in for loops initalization expressions).
2003
- *
2004
- * @param {boolean=} noComma
2005
- * @param {boolean=} noIn
2006
- * @returns {!node_t}
2007
- */
2008
- function parseExpression(noComma, noIn) {
2009
- var expr = parseMaybeAssign(noIn);
2010
- if (!noComma && tokType === _comma) {
2011
- var node = startNodeFrom(expr);
2012
- node.expressions = [expr];
2013
- while (eat(_comma))
2014
- node.expressions.push(parseMaybeAssign(noIn));
2015
- return finishNode(node, 'SequenceExpression');
2016
- }
2017
- return expr;
2018
- }
2019
- /**
2020
- * Parse an assignment expression. This includes applications of
2021
- * operators like `+=`.
2022
- *
2023
- * @param {boolean|undefined} noIn
2024
- * @returns {!node_t}
2025
- */
2026
- function parseMaybeAssign(noIn) {
2027
- var left = parseMaybeConditional(noIn);
2028
- if (tokType.isAssign) {
2029
- var node = startNodeFrom(left);
2030
- node.operator = tokVal;
2031
- node.left = left;
2032
- next();
2033
- node.right = parseMaybeAssign(noIn);
2034
- checkLVal(left);
2035
- return finishNode(node, 'AssignmentExpression');
2036
- }
2037
- return left;
2038
- }
2039
- /**
2040
- * Parse a ternary conditional (`?:`) operator.
2041
- *
2042
- * @param {boolean|undefined} noIn
2043
- * @returns {!node_t}
2044
- */
2045
- function parseMaybeConditional(noIn) {
2046
- var expr = parseExprOps(noIn);
2047
- if (eat(_question)) {
2048
- var node = startNodeFrom(expr);
2049
- node.test = expr;
2050
- node.consequent = parseExpression(true);
2051
- expect(_colon);
2052
- node.alternate = parseExpression(true, noIn);
2053
- return finishNode(node, 'ConditionalExpression');
2054
- }
2055
- return expr;
2056
- }
2057
- /**
2058
- * Start the precedence parser.
2059
- *
2060
- * @param {boolean|undefined} noIn
2061
- * @returns {!node_t}
2062
- */
2063
- function parseExprOps(noIn) {
2064
- return parseExprOp(parseMaybeUnary(), -1, noIn);
2065
- }
2066
- /**
2067
- * Parse binary operators with the operator precedence parsing
2068
- * algorithm. `left` is the left-hand side of the operator.
2069
- * `minPrec` provides context that allows the function to stop and
2070
- * defer further parser to one of its callers when it encounters an
2071
- * operator that has a lower precedence than the set it is parsing.
2072
- *
2073
- * @param {!node_t} left
2074
- * @param {number} minPrec
2075
- * @param {boolean|undefined} noIn
2076
- * @returns {!node_t}
2077
- */
2078
- function parseExprOp(left, minPrec, noIn) {
2079
- var prec = tokType.binop;
2080
- if (prec !== null && (!noIn || tokType !== _in)) {
2081
- if (prec > minPrec) {
2082
- var node = startNodeFrom(left);
2083
- node.left = left;
2084
- node.operator = tokVal;
2085
- var op = tokType;
2086
- next();
2087
- node.right = parseExprOp(parseMaybeUnary(), prec, noIn);
2088
- var exprNode = finishNode(node, op === _logicalOR || op === _logicalAND ? 'LogicalExpression' : 'BinaryExpression');
2089
- return parseExprOp(exprNode, minPrec, noIn);
2090
- }
2091
- }
2092
- return left;
2093
- }
2094
- /**
2095
- * Parse unary operators, both prefix and postfix.
2096
- *
2097
- * @returns {!node_t}
2098
- */
2099
- function parseMaybeUnary() {
2100
- if (tokType.prefix) {
2101
- var node = startNode();
2102
- var update = tokType.isUpdate;
2103
- node.operator = tokVal;
2104
- node.prefix = true;
2105
- tokRegexpAllowed = true;
2106
- next();
2107
- node.argument = parseMaybeUnary();
2108
- if (update)
2109
- checkLVal(node.argument);
2110
- else if (strict && node.operator === 'delete' && node.argument.type === 'Identifier')
2111
- raise(node.start, 'Deleting local variable in strict mode');
2112
- return finishNode(node, update ? 'UpdateExpression' : 'UnaryExpression');
2113
- }
2114
- var expr = parseExprSubscripts();
2115
- while (tokType.postfix && !canInsertSemicolon()) {
2116
- var node = startNodeFrom(expr);
2117
- node.operator = tokVal;
2118
- node.prefix = false;
2119
- node.argument = expr;
2120
- checkLVal(expr);
2121
- next();
2122
- expr = finishNode(node, 'UpdateExpression');
2123
- }
2124
- return expr;
2125
- }
2126
- /**
2127
- * Parse call, dot, and `[]`-subscript expressions.
2128
- *
2129
- * @returns {!node_t}
2130
- */
2131
- function parseExprSubscripts() {
2132
- return parseSubscripts(parseExprAtom());
2133
- }
2134
- /**
2135
- * @param {!node_t} base
2136
- * @param {boolean=} noCalls
2137
- * @returns {!node_t}
2138
- */
2139
- function parseSubscripts(base, noCalls) {
2140
- var node;
2141
- if (eat(_dot)) {
2142
- node = startNodeFrom(base);
2143
- node.object = base;
2144
- node.property = parseIdent(true);
2145
- node.computed = false;
2146
- return parseSubscripts(finishNode(node, 'MemberExpression'), noCalls);
2147
- }
2148
- if (eat(_bracketL)) {
2149
- node = startNodeFrom(base);
2150
- node.object = base;
2151
- node.property = parseExpression();
2152
- node.computed = true;
2153
- expect(_bracketR);
2154
- return parseSubscripts(finishNode(node, 'MemberExpression'), noCalls);
2155
- }
2156
- if (!noCalls && eat(_parenL)) {
2157
- node = startNodeFrom(base);
2158
- node.callee = base;
2159
- node.arguments = parseExprList(_parenR, false);
2160
- return parseSubscripts(finishNode(node, 'CallExpression'), noCalls);
2161
- }
2162
- return base;
2163
- }
2164
- /**
2165
- * Parse an atomic expression — either a single token that is an expression,
2166
- * an expression started by a keyword like `function` or `new`,
2167
- * or an expression wrapped in punctuation like `()`, `[]`, or `{}`.
2168
- *
2169
- * @returns {!node_t}
2170
- * @suppress {missingReturn}
2171
- */
2172
- function parseExprAtom() {
2173
- var node;
2174
- switch (tokType) {
2175
- case _this:
2176
- node = startNode();
2177
- next();
2178
- return finishNode(node, 'ThisExpression');
2179
- case _name:
2180
- return parseIdent();
2181
- case _num:
2182
- case _string:
2183
- case _regexp:
2184
- node = startNode();
2185
- node.value = tokVal;
2186
- node.raw = input.slice(tokStart, tokEnd);
2187
- next();
2188
- return finishNode(node, 'Literal');
2189
- case _null:
2190
- case _true:
2191
- case _false:
2192
- node = startNode();
2193
- node.value = tokType.atomValue;
2194
- node.raw = tokType.keyword;
2195
- next();
2196
- return finishNode(node, 'Literal');
2197
- case _parenL:
2198
- var tokStartLoc1 = tokStartLoc;
2199
- var tokStart1 = tokStart;
2200
- next();
2201
- var val = parseExpression();
2202
- val.start = tokStart1;
2203
- val.end = tokEnd;
2204
- if (options.locations) {
2205
- val.loc.start = tokStartLoc1;
2206
- val.loc.end = tokEndLoc;
2207
- }
2208
- if (options.ranges) {
2209
- val.range = [tokStart1, tokEnd];
2210
- }
2211
- expect(_parenR);
2212
- return val;
2213
- case _bracketL:
2214
- node = startNode();
2215
- next();
2216
- node.elements = parseExprList(_bracketR, true, true);
2217
- return finishNode(node, 'ArrayExpression');
2218
- case _braceL:
2219
- return parseObj();
2220
- case _function:
2221
- node = startNode();
2222
- next();
2223
- return parseFunction(node, false);
2224
- case _new:
2225
- return parseNew();
2226
- }
2227
- unexpected();
2228
- }
2229
- /**
2230
- * New's precedence is slightly tricky. It must allow its argument to be
2231
- * a `[]` or dot subscript expression, but not a call — at least, not
2232
- * without wrapping it in parentheses. Thus, it uses the noCalls argument
2233
- * to parseSubscripts to prevent it from consuming the argument list.
2234
- *
2235
- * @returns {!node_t}
2236
- */
2237
- function parseNew() {
2238
- var node = startNode();
2239
- next();
2240
- node.callee = parseSubscripts(parseExprAtom(), true);
2241
- node.arguments = eat(_parenL) ? parseExprList(_parenR, false) : empty;
2242
- return finishNode(node, 'NewExpression');
2243
- }
2244
- /**
2245
- * Parse an object literal.
2246
- *
2247
- * @returns {!node_t}
2248
- */
2249
- function parseObj() {
2250
- var node = startNode();
2251
- var first = true;
2252
- var sawGetSet = false;
2253
- node.properties = [];
2254
- next();
2255
- while (!eat(_braceR)) {
2256
- if (!first) {
2257
- expect(_comma);
2258
- if (options.allowTrailingCommas && eat(_braceR)) {
2259
- break;
2260
- }
2261
- }
2262
- else {
2263
- first = false;
2264
- }
2265
- var prop = {
2266
- key: parsePropertyName()
2267
- };
2268
- var isGetSet = false;
2269
- var kind;
2270
- if (eat(_colon)) {
2271
- prop.value = parseExpression(true);
2272
- kind = prop.kind = 'init';
2273
- }
2274
- else if (prop.key.type === 'Identifier' && (prop.key.name === 'get' || prop.key.name === 'set')) {
2275
- isGetSet = sawGetSet = true;
2276
- kind = prop.kind = prop.key.name;
2277
- prop.key = parsePropertyName();
2278
- if (tokType !== _parenL)
2279
- unexpected();
2280
- prop.value = parseFunction(startNode(), false);
2281
- }
2282
- else {
2283
- unexpected();
2284
- }
2285
- // getters and setters are not allowed to clash — either with
2286
- // each other or with an init property — and in strict mode,
2287
- // init properties are also not allowed to be repeated.
2288
- if (prop.key.type === 'Identifier' && (strict || sawGetSet)) {
2289
- for (var i = 0; i < node.properties.length; ++i) {
2290
- var other = node.properties[i];
2291
- if (other.key.name === prop.key.name) {
2292
- var conflict = kind === other.kind || isGetSet && other.kind === 'init' || kind === 'init' && (other.kind === 'get' || other.kind === 'set');
2293
- if (conflict && !strict && kind === 'init' && other.kind === 'init') {
2294
- conflict = false;
2295
- }
2296
- if (conflict) {
2297
- raise(prop.key.start, 'Redefinition of property');
2298
- }
2299
- }
2300
- }
2301
- }
2302
- node.properties.push(prop);
2303
- }
2304
- return finishNode(node, 'ObjectExpression');
2305
- }
2306
- /**
2307
- * @returns {!node_t}
2308
- */
2309
- function parsePropertyName() {
2310
- if (tokType === _num || tokType === _string) {
2311
- return parseExprAtom();
2312
- }
2313
- return parseIdent(true);
2314
- }
2315
- /**
2316
- * Parse a function declaration or literal (depending on the
2317
- * `isStatement` parameter).
2318
- *
2319
- * @param {!node_t} node
2320
- * @param {boolean} isStatement
2321
- * @returns {!node_t}
2322
- */
2323
- function parseFunction(node, isStatement) {
2324
- if (tokType === _name) {
2325
- node.id = parseIdent();
2326
- }
2327
- else if (isStatement) {
2328
- unexpected();
2329
- }
2330
- else {
2331
- node.id = null;
2332
- }
2333
- node.params = [];
2334
- var first = true;
2335
- expect(_parenL);
2336
- while (!eat(_parenR)) {
2337
- if (!first) {
2338
- expect(_comma);
2339
- }
2340
- else {
2341
- first = false;
2342
- }
2343
- node.params.push(parseIdent());
2344
- }
2345
- // Start a new scope with regard to labels and the `inFunction`
2346
- // flag (restore them to their old value afterwards).
2347
- var oldInFunc = inFunction;
2348
- var oldLabels = labels;
2349
- inFunction = true;
2350
- labels = [];
2351
- node.body = parseBlock(true);
2352
- inFunction = oldInFunc;
2353
- labels = oldLabels;
2354
- // If this is a strict mode function, verify that argument names
2355
- // are not repeated, and it does not try to bind the words `eval`
2356
- // or `arguments`.
2357
- if (strict || node.body.body.length && isUseStrict(node.body.body[0])) {
2358
- for (var i = node.id ? -1 : 0; i < node.params.length; ++i) {
2359
- var id = i < 0 ? node.id : node.params[i];
2360
- if (isStrictReservedWord(id.name) || isStrictBadIdWord(id.name)) {
2361
- raise(id.start, "Defining '" + id.name + "' in strict mode");
2362
- }
2363
- if (i >= 0) {
2364
- for (var j = 0; j < i; ++j) {
2365
- if (id.name === node.params[j].name) {
2366
- raise(id.start, 'Argument name clash in strict mode');
2367
- }
2368
- }
2369
- }
2370
- }
2371
- }
2372
- return finishNode(node, isStatement ? 'FunctionDeclaration' : 'FunctionExpression');
2373
- }
2374
- /**
2375
- * Parses a comma-separated list of expressions, and returns them as
2376
- * an array. `close` is the token type that ends the list, and
2377
- * `allowEmpty` can be turned on to allow subsequent commas with
2378
- * nothing in between them to be parsed as `null` (which is needed
2379
- * for array literals).
2380
- *
2381
- * @param {!Object} close
2382
- * @param {boolean} allowTrailingComma
2383
- * @param {boolean=} allowEmpty
2384
- * @returns {!Array<!node_t>}
2385
- */
2386
- function parseExprList(close, allowTrailingComma, allowEmpty) {
2387
- var elts = [];
2388
- var first = true;
2389
- while (!eat(close)) {
2390
- if (!first) {
2391
- expect(_comma);
2392
- if (allowTrailingComma && options.allowTrailingCommas && eat(close)) {
2393
- break;
2394
- }
2395
- }
2396
- else {
2397
- first = false;
2398
- }
2399
- elts.push(allowEmpty && tokType === _comma ? null : parseExpression(true));
2400
- }
2401
- return elts;
2402
- }
2403
- /**
2404
- * Parse the next token as an identifier. If `liberal` is true (used
2405
- * when parsing properties), it will also convert keywords into
2406
- * identifiers.
2407
- *
2408
- * @param {boolean=} liberal
2409
- * @returns {!node_t}
2410
- */
2411
- function parseIdent(liberal) {
2412
- var node = startNode();
2413
- if (liberal && options.forbidReserved === 'everywhere') {
2414
- liberal = false;
2415
- }
2416
- if (tokType === _name) {
2417
- if (!liberal && (options.forbidReserved && isReservedWord5(tokVal) || strict && isStrictReservedWord(tokVal)) && input.slice(tokStart, tokEnd).indexOf('\\') === -1) {
2418
- raise(tokStart, "The keyword '" + tokVal + "' is reserved");
2419
- }
2420
- node.name = tokVal;
2421
- }
2422
- else if (liberal && tokType.keyword) {
2423
- node.name = tokType.keyword;
2424
- }
2425
- else {
2426
- unexpected();
2427
- }
2428
- tokRegexpAllowed = false;
2429
- next();
2430
- return finishNode(node, 'Identifier');
2431
- }
2432
- });