esperanto-source 0.7.0 → 0.7.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a98d5b601e29366275a76d72e9234655c36d0648
4
- data.tar.gz: 316a57604f6c072b894b40515d491a0fc744029d
3
+ metadata.gz: 74793fe87882c4316ec0e42c0303dbfd38b0547c
4
+ data.tar.gz: ec991184cfdc52b1c697c330d7fe7c94431384da
5
5
  SHA512:
6
- metadata.gz: 0e53f43007bf4a985cdca9e133012ef276e0e5a90f09e25c77ef7d60289e246b9c1f51b9187c5a24e7ec1d3b635489493d720a74c5bfa10bd41c968fcab58101
7
- data.tar.gz: 381b8dccc8c4e3f8a112124726711253c3031a7031a6cc366370b8489c5cad297a8dda07a4f1af4d9f843eb971370d90609798eed6522cda1c73dad3faea8b76
6
+ metadata.gz: 4997f99064e6c91a0f3798c6309c5f38028a92c8fc08114970e0ee99c3b86c0ddf74b87a854f0ac738fdabfaecf312acd52b54c1d552e49c5fa6209e9d13f338
7
+ data.tar.gz: 3c63d37f7b49fbe1d058a3a65828203799800b3999ec1f43972fe162b3939d5d3b9420f2cfe7a6bb141c662818e958b543681162fd2c77aedb54e095a59a34fb
@@ -9,7 +9,6 @@ module Esperanto
9
9
 
10
10
  def bundled_paths
11
11
  %w(
12
- acorn.js
13
12
  base64.js
14
13
  esperanto.browser.js
15
14
  ).map {|js| bundled_path_for(js) }
@@ -1,5 +1,5 @@
1
1
  module Esperanto
2
2
  module Source
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.0.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esperanto-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryunosuke SATO
@@ -97,7 +97,6 @@ files:
97
97
  - lib/esperanto/source.rb
98
98
  - lib/esperanto/source/version.rb
99
99
  - test/test_esperanto_source.rb
100
- - vendor/acorn.js
101
100
  - vendor/base64.js
102
101
  - vendor/esperanto.browser.js
103
102
  - vendor/esperanto.browser.js.map
@@ -1,3208 +0,0 @@
1
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.acorn = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
2
-
3
-
4
- // The main exported interface (under `self.acorn` when in the
5
- // browser) is a `parse` function that takes a code string and
6
- // returns an abstract syntax tree as specified by [Mozilla parser
7
- // API][api].
8
- //
9
- // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
10
-
11
- "use strict";
12
-
13
- exports.parse = parse;
14
-
15
- // This function tries to parse a single expression at a given
16
- // offset in a string. Useful for parsing mixed-language formats
17
- // that embed JavaScript expressions.
18
-
19
- exports.parseExpressionAt = parseExpressionAt;
20
-
21
- // Acorn is organized as a tokenizer and a recursive-descent parser.
22
- // The `tokenize` export provides an interface to the tokenizer.
23
-
24
- exports.tokenizer = tokenizer;
25
- exports.__esModule = true;
26
- // Acorn is a tiny, fast JavaScript parser written in JavaScript.
27
- //
28
- // Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
29
- // various contributors and released under an MIT license.
30
- //
31
- // Git repositories for Acorn are available at
32
- //
33
- // http://marijnhaverbeke.nl/git/acorn
34
- // https://github.com/marijnh/acorn.git
35
- //
36
- // Please use the [github bug tracker][ghbt] to report issues.
37
- //
38
- // [ghbt]: https://github.com/marijnh/acorn/issues
39
- //
40
- // This file defines the main parser interface. The library also comes
41
- // with a [error-tolerant parser][dammit] and an
42
- // [abstract syntax tree walker][walk], defined in other files.
43
- //
44
- // [dammit]: acorn_loose.js
45
- // [walk]: util/walk.js
46
-
47
- var _state = _dereq_("./state");
48
-
49
- var Parser = _state.Parser;
50
-
51
- var _options = _dereq_("./options");
52
-
53
- var getOptions = _options.getOptions;
54
-
55
- _dereq_("./parseutil");
56
-
57
- _dereq_("./statement");
58
-
59
- _dereq_("./lval");
60
-
61
- _dereq_("./expression");
62
-
63
- exports.Parser = _state.Parser;
64
- exports.plugins = _state.plugins;
65
- exports.defaultOptions = _options.defaultOptions;
66
-
67
- var _location = _dereq_("./location");
68
-
69
- exports.SourceLocation = _location.SourceLocation;
70
- exports.getLineInfo = _location.getLineInfo;
71
- exports.Node = _dereq_("./node").Node;
72
-
73
- var _tokentype = _dereq_("./tokentype");
74
-
75
- exports.TokenType = _tokentype.TokenType;
76
- exports.tokTypes = _tokentype.types;
77
-
78
- var _tokencontext = _dereq_("./tokencontext");
79
-
80
- exports.TokContext = _tokencontext.TokContext;
81
- exports.tokContexts = _tokencontext.types;
82
-
83
- var _identifier = _dereq_("./identifier");
84
-
85
- exports.isIdentifierChar = _identifier.isIdentifierChar;
86
- exports.isIdentifierStart = _identifier.isIdentifierStart;
87
- exports.Token = _dereq_("./tokenize").Token;
88
-
89
- var _whitespace = _dereq_("./whitespace");
90
-
91
- exports.isNewLine = _whitespace.isNewLine;
92
- exports.lineBreak = _whitespace.lineBreak;
93
- exports.lineBreakG = _whitespace.lineBreakG;
94
- var version = "1.0.3";exports.version = version;
95
-
96
- function parse(input, options) {
97
- var p = parser(options, input);
98
- var startPos = p.options.locations ? [p.pos, p.curPosition()] : p.pos;
99
- p.nextToken();
100
- return p.parseTopLevel(p.options.program || p.startNodeAt(startPos));
101
- }
102
-
103
- function parseExpressionAt(input, pos, options) {
104
- var p = parser(options, input, pos);
105
- p.nextToken();
106
- return p.parseExpression();
107
- }
108
-
109
- function tokenizer(input, options) {
110
- return parser(options, input);
111
- }
112
-
113
- function parser(options, input) {
114
- return new Parser(getOptions(options), String(input));
115
- }
116
-
117
- },{"./expression":2,"./identifier":3,"./location":4,"./lval":5,"./node":6,"./options":7,"./parseutil":8,"./state":9,"./statement":10,"./tokencontext":11,"./tokenize":12,"./tokentype":13,"./whitespace":15}],2:[function(_dereq_,module,exports){
118
- // A recursive descent parser operates by defining functions for all
119
- // syntactic elements, and recursively calling those, each function
120
- // advancing the input stream and returning an AST node. Precedence
121
- // of constructs (for example, the fact that `!x[1]` means `!(x[1])`
122
- // instead of `(!x)[1]` is handled by the fact that the parser
123
- // function that parses unary prefix operators is called first, and
124
- // in turn calls the function that parses `[]` subscripts — that
125
- // way, it'll receive the node for `x[1]` already parsed, and wraps
126
- // *that* in the unary operator node.
127
- //
128
- // Acorn uses an [operator precedence parser][opp] to handle binary
129
- // operator precedence, because it is much more compact than using
130
- // the technique outlined above, which uses different, nesting
131
- // functions to specify precedence, for all of the ten binary
132
- // precedence levels that JavaScript defines.
133
- //
134
- // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
135
-
136
- "use strict";
137
-
138
- var tt = _dereq_("./tokentype").types;
139
-
140
- var Parser = _dereq_("./state").Parser;
141
-
142
- var reservedWords = _dereq_("./identifier").reservedWords;
143
-
144
- var has = _dereq_("./util").has;
145
-
146
- var pp = Parser.prototype;
147
-
148
- // Check if property name clashes with already added.
149
- // Object/class getters and setters are not allowed to clash —
150
- // either with each other or with an init property — and in
151
- // strict mode, init properties are also not allowed to be repeated.
152
-
153
- pp.checkPropClash = function (prop, propHash) {
154
- if (this.options.ecmaVersion >= 6) return;
155
- var key = prop.key,
156
- name = undefined;
157
- switch (key.type) {
158
- case "Identifier":
159
- name = key.name;break;
160
- case "Literal":
161
- name = String(key.value);break;
162
- default:
163
- return;
164
- }
165
- var kind = prop.kind || "init",
166
- other = undefined;
167
- if (has(propHash, name)) {
168
- other = propHash[name];
169
- var isGetSet = kind !== "init";
170
- if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init)) this.raise(key.start, "Redefinition of property");
171
- } else {
172
- other = propHash[name] = {
173
- init: false,
174
- get: false,
175
- set: false
176
- };
177
- }
178
- other[kind] = true;
179
- };
180
-
181
- // ### Expression parsing
182
-
183
- // These nest, from the most general expression type at the top to
184
- // 'atomic', nondivisible expression types at the bottom. Most of
185
- // the functions will simply let the function(s) below them parse,
186
- // and, *if* the syntactic construct they handle is present, wrap
187
- // the AST node that the inner parser gave them in another node.
188
-
189
- // Parse a full expression. The optional arguments are used to
190
- // forbid the `in` operator (in for loops initalization expressions)
191
- // and provide reference for storing '=' operator inside shorthand
192
- // property assignment in contexts where both object expression
193
- // and object pattern might appear (so it's possible to raise
194
- // delayed syntax error at correct position).
195
-
196
- pp.parseExpression = function (noIn, refShorthandDefaultPos) {
197
- var start = this.markPosition();
198
- var expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos);
199
- if (this.type === tt.comma) {
200
- var node = this.startNodeAt(start);
201
- node.expressions = [expr];
202
- while (this.eat(tt.comma)) node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
203
- return this.finishNode(node, "SequenceExpression");
204
- }
205
- return expr;
206
- };
207
-
208
- // Parse an assignment expression. This includes applications of
209
- // operators like `+=`.
210
-
211
- pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos) {
212
- if (this.type == tt._yield && this.inGenerator) return this.parseYield();
213
-
214
- var failOnShorthandAssign = undefined;
215
- if (!refShorthandDefaultPos) {
216
- refShorthandDefaultPos = { start: 0 };
217
- failOnShorthandAssign = true;
218
- } else {
219
- failOnShorthandAssign = false;
220
- }
221
- var start = this.markPosition();
222
- var left = this.parseMaybeConditional(noIn, refShorthandDefaultPos);
223
- if (this.type.isAssign) {
224
- var node = this.startNodeAt(start);
225
- node.operator = this.value;
226
- node.left = this.type === tt.eq ? this.toAssignable(left) : left;
227
- refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly
228
- this.checkLVal(left);
229
- this.next();
230
- node.right = this.parseMaybeAssign(noIn);
231
- return this.finishNode(node, "AssignmentExpression");
232
- } else if (failOnShorthandAssign && refShorthandDefaultPos.start) {
233
- this.unexpected(refShorthandDefaultPos.start);
234
- }
235
- return left;
236
- };
237
-
238
- // Parse a ternary conditional (`?:`) operator.
239
-
240
- pp.parseMaybeConditional = function (noIn, refShorthandDefaultPos) {
241
- var start = this.markPosition();
242
- var expr = this.parseExprOps(noIn, refShorthandDefaultPos);
243
- if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
244
- if (this.eat(tt.question)) {
245
- var node = this.startNodeAt(start);
246
- node.test = expr;
247
- node.consequent = this.parseMaybeAssign();
248
- this.expect(tt.colon);
249
- node.alternate = this.parseMaybeAssign(noIn);
250
- return this.finishNode(node, "ConditionalExpression");
251
- }
252
- return expr;
253
- };
254
-
255
- // Start the precedence parser.
256
-
257
- pp.parseExprOps = function (noIn, refShorthandDefaultPos) {
258
- var start = this.markPosition();
259
- var expr = this.parseMaybeUnary(refShorthandDefaultPos);
260
- if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
261
- return this.parseExprOp(expr, start, -1, noIn);
262
- };
263
-
264
- // Parse binary operators with the operator precedence parsing
265
- // algorithm. `left` is the left-hand side of the operator.
266
- // `minPrec` provides context that allows the function to stop and
267
- // defer further parser to one of its callers when it encounters an
268
- // operator that has a lower precedence than the set it is parsing.
269
-
270
- pp.parseExprOp = function (left, leftStart, minPrec, noIn) {
271
- var prec = this.type.binop;
272
- if (prec != null && (!noIn || this.type !== tt._in)) {
273
- if (prec > minPrec) {
274
- var node = this.startNodeAt(leftStart);
275
- node.left = left;
276
- node.operator = this.value;
277
- var op = this.type;
278
- this.next();
279
- var start = this.markPosition();
280
- node.right = this.parseExprOp(this.parseMaybeUnary(), start, prec, noIn);
281
- this.finishNode(node, op === tt.logicalOR || op === tt.logicalAND ? "LogicalExpression" : "BinaryExpression");
282
- return this.parseExprOp(node, leftStart, minPrec, noIn);
283
- }
284
- }
285
- return left;
286
- };
287
-
288
- // Parse unary operators, both prefix and postfix.
289
-
290
- pp.parseMaybeUnary = function (refShorthandDefaultPos) {
291
- if (this.type.prefix) {
292
- var node = this.startNode(),
293
- update = this.type === tt.incDec;
294
- node.operator = this.value;
295
- node.prefix = true;
296
- this.next();
297
- node.argument = this.parseMaybeUnary();
298
- if (refShorthandDefaultPos && refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start);
299
- if (update) this.checkLVal(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raise(node.start, "Deleting local variable in strict mode");
300
- return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
301
- }
302
- var start = this.markPosition();
303
- var expr = this.parseExprSubscripts(refShorthandDefaultPos);
304
- if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
305
- while (this.type.postfix && !this.canInsertSemicolon()) {
306
- var node = this.startNodeAt(start);
307
- node.operator = this.value;
308
- node.prefix = false;
309
- node.argument = expr;
310
- this.checkLVal(expr);
311
- this.next();
312
- expr = this.finishNode(node, "UpdateExpression");
313
- }
314
- return expr;
315
- };
316
-
317
- // Parse call, dot, and `[]`-subscript expressions.
318
-
319
- pp.parseExprSubscripts = function (refShorthandDefaultPos) {
320
- var start = this.markPosition();
321
- var expr = this.parseExprAtom(refShorthandDefaultPos);
322
- if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr;
323
- return this.parseSubscripts(expr, start);
324
- };
325
-
326
- pp.parseSubscripts = function (base, start, noCalls) {
327
- if (this.eat(tt.dot)) {
328
- var node = this.startNodeAt(start);
329
- node.object = base;
330
- node.property = this.parseIdent(true);
331
- node.computed = false;
332
- return this.parseSubscripts(this.finishNode(node, "MemberExpression"), start, noCalls);
333
- } else if (this.eat(tt.bracketL)) {
334
- var node = this.startNodeAt(start);
335
- node.object = base;
336
- node.property = this.parseExpression();
337
- node.computed = true;
338
- this.expect(tt.bracketR);
339
- return this.parseSubscripts(this.finishNode(node, "MemberExpression"), start, noCalls);
340
- } else if (!noCalls && this.eat(tt.parenL)) {
341
- var node = this.startNodeAt(start);
342
- node.callee = base;
343
- node.arguments = this.parseExprList(tt.parenR, false);
344
- return this.parseSubscripts(this.finishNode(node, "CallExpression"), start, noCalls);
345
- } else if (this.type === tt.backQuote) {
346
- var node = this.startNodeAt(start);
347
- node.tag = base;
348
- node.quasi = this.parseTemplate();
349
- return this.parseSubscripts(this.finishNode(node, "TaggedTemplateExpression"), start, noCalls);
350
- }return base;
351
- };
352
-
353
- // Parse an atomic expression — either a single token that is an
354
- // expression, an expression started by a keyword like `function` or
355
- // `new`, or an expression wrapped in punctuation like `()`, `[]`,
356
- // or `{}`.
357
-
358
- pp.parseExprAtom = function (refShorthandDefaultPos) {
359
- var node = undefined;
360
- switch (this.type) {
361
- case tt._this:
362
- case tt._super:
363
- var type = this.type === tt._this ? "ThisExpression" : "Super";
364
- node = this.startNode();
365
- this.next();
366
- return this.finishNode(node, type);
367
-
368
- case tt._yield:
369
- if (this.inGenerator) this.unexpected();
370
-
371
- case tt.name:
372
- var start = this.markPosition();
373
- var id = this.parseIdent(this.type !== tt.name);
374
- if (!this.canInsertSemicolon() && this.eat(tt.arrow)) {
375
- return this.parseArrowExpression(this.startNodeAt(start), [id]);
376
- }
377
- return id;
378
-
379
- case tt.regexp:
380
- var value = this.value;
381
- node = this.parseLiteral(value.value);
382
- node.regex = { pattern: value.pattern, flags: value.flags };
383
- return node;
384
-
385
- case tt.num:case tt.string:
386
- return this.parseLiteral(this.value);
387
-
388
- case tt._null:case tt._true:case tt._false:
389
- node = this.startNode();
390
- node.value = this.type === tt._null ? null : this.type === tt._true;
391
- node.raw = this.type.keyword;
392
- this.next();
393
- return this.finishNode(node, "Literal");
394
-
395
- case tt.parenL:
396
- return this.parseParenAndDistinguishExpression();
397
-
398
- case tt.bracketL:
399
- node = this.startNode();
400
- this.next();
401
- // check whether this is array comprehension or regular array
402
- if (this.options.ecmaVersion >= 7 && this.type === tt._for) {
403
- return this.parseComprehension(node, false);
404
- }
405
- node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
406
- return this.finishNode(node, "ArrayExpression");
407
-
408
- case tt.braceL:
409
- return this.parseObj(false, refShorthandDefaultPos);
410
-
411
- case tt._function:
412
- node = this.startNode();
413
- this.next();
414
- return this.parseFunction(node, false);
415
-
416
- case tt._class:
417
- return this.parseClass(this.startNode(), false);
418
-
419
- case tt._new:
420
- return this.parseNew();
421
-
422
- case tt.backQuote:
423
- return this.parseTemplate();
424
-
425
- default:
426
- this.unexpected();
427
- }
428
- };
429
-
430
- pp.parseLiteral = function (value) {
431
- var node = this.startNode();
432
- node.value = value;
433
- node.raw = this.input.slice(this.start, this.end);
434
- this.next();
435
- return this.finishNode(node, "Literal");
436
- };
437
-
438
- pp.parseParenExpression = function () {
439
- this.expect(tt.parenL);
440
- var val = this.parseExpression();
441
- this.expect(tt.parenR);
442
- return val;
443
- };
444
-
445
- pp.parseParenAndDistinguishExpression = function () {
446
- var start = this.markPosition(),
447
- val = undefined;
448
- if (this.options.ecmaVersion >= 6) {
449
- this.next();
450
-
451
- if (this.options.ecmaVersion >= 7 && this.type === tt._for) {
452
- return this.parseComprehension(this.startNodeAt(start), true);
453
- }
454
-
455
- var innerStart = this.markPosition(),
456
- exprList = [],
457
- first = true;
458
- var refShorthandDefaultPos = { start: 0 },
459
- spreadStart = undefined,
460
- innerParenStart = undefined;
461
- while (this.type !== tt.parenR) {
462
- first ? first = false : this.expect(tt.comma);
463
- if (this.type === tt.ellipsis) {
464
- spreadStart = this.start;
465
- exprList.push(this.parseRest());
466
- break;
467
- } else {
468
- if (this.type === tt.parenL && !innerParenStart) {
469
- innerParenStart = this.start;
470
- }
471
- exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos));
472
- }
473
- }
474
- var innerEnd = this.markPosition();
475
- this.expect(tt.parenR);
476
-
477
- if (!this.canInsertSemicolon() && this.eat(tt.arrow)) {
478
- if (innerParenStart) this.unexpected(innerParenStart);
479
- return this.parseArrowExpression(this.startNodeAt(start), exprList);
480
- }
481
-
482
- if (!exprList.length) this.unexpected(this.lastTokStart);
483
- if (spreadStart) this.unexpected(spreadStart);
484
- if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start);
485
-
486
- if (exprList.length > 1) {
487
- val = this.startNodeAt(innerStart);
488
- val.expressions = exprList;
489
- this.finishNodeAt(val, "SequenceExpression", innerEnd);
490
- } else {
491
- val = exprList[0];
492
- }
493
- } else {
494
- val = this.parseParenExpression();
495
- }
496
-
497
- if (this.options.preserveParens) {
498
- var par = this.startNodeAt(start);
499
- par.expression = val;
500
- return this.finishNode(par, "ParenthesizedExpression");
501
- } else {
502
- return val;
503
- }
504
- };
505
-
506
- // New's precedence is slightly tricky. It must allow its argument
507
- // to be a `[]` or dot subscript expression, but not a call — at
508
- // least, not without wrapping it in parentheses. Thus, it uses the
509
-
510
- var empty = [];
511
-
512
- pp.parseNew = function () {
513
- var node = this.startNode();
514
- var meta = this.parseIdent(true);
515
- if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
516
- node.meta = meta;
517
- node.property = this.parseIdent(true);
518
- if (node.property.name !== "target") this.raise(node.property.start, "The only valid meta property for new is new.target");
519
- return this.finishNode(node, "MetaProperty");
520
- }
521
- var start = this.markPosition();
522
- node.callee = this.parseSubscripts(this.parseExprAtom(), start, true);
523
- if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false);else node.arguments = empty;
524
- return this.finishNode(node, "NewExpression");
525
- };
526
-
527
- // Parse template expression.
528
-
529
- pp.parseTemplateElement = function () {
530
- var elem = this.startNode();
531
- elem.value = {
532
- raw: this.input.slice(this.start, this.end),
533
- cooked: this.value
534
- };
535
- this.next();
536
- elem.tail = this.type === tt.backQuote;
537
- return this.finishNode(elem, "TemplateElement");
538
- };
539
-
540
- pp.parseTemplate = function () {
541
- var node = this.startNode();
542
- this.next();
543
- node.expressions = [];
544
- var curElt = this.parseTemplateElement();
545
- node.quasis = [curElt];
546
- while (!curElt.tail) {
547
- this.expect(tt.dollarBraceL);
548
- node.expressions.push(this.parseExpression());
549
- this.expect(tt.braceR);
550
- node.quasis.push(curElt = this.parseTemplateElement());
551
- }
552
- this.next();
553
- return this.finishNode(node, "TemplateLiteral");
554
- };
555
-
556
- // Parse an object literal or binding pattern.
557
-
558
- pp.parseObj = function (isPattern, refShorthandDefaultPos) {
559
- var node = this.startNode(),
560
- first = true,
561
- propHash = {};
562
- node.properties = [];
563
- this.next();
564
- while (!this.eat(tt.braceR)) {
565
- if (!first) {
566
- this.expect(tt.comma);
567
- if (this.afterTrailingComma(tt.braceR)) break;
568
- } else first = false;
569
-
570
- var prop = this.startNode(),
571
- isGenerator = undefined,
572
- start = undefined;
573
- if (this.options.ecmaVersion >= 6) {
574
- prop.method = false;
575
- prop.shorthand = false;
576
- if (isPattern || refShorthandDefaultPos) start = this.markPosition();
577
- if (!isPattern) isGenerator = this.eat(tt.star);
578
- }
579
- this.parsePropertyName(prop);
580
- if (this.eat(tt.colon)) {
581
- prop.value = isPattern ? this.parseMaybeDefault() : this.parseMaybeAssign(false, refShorthandDefaultPos);
582
- prop.kind = "init";
583
- } else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
584
- if (isPattern) this.unexpected();
585
- prop.kind = "init";
586
- prop.method = true;
587
- prop.value = this.parseMethod(isGenerator);
588
- } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.type != tt.comma && this.type != tt.braceR)) {
589
- if (isGenerator || isPattern) this.unexpected();
590
- prop.kind = prop.key.name;
591
- this.parsePropertyName(prop);
592
- prop.value = this.parseMethod(false);
593
- } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
594
- prop.kind = "init";
595
- if (isPattern) {
596
- if (this.isKeyword(prop.key.name) || this.strict && (reservedWords.strictBind(prop.key.name) || reservedWords.strict(prop.key.name)) || !this.options.allowReserved && this.isReservedWord(prop.key.name)) this.raise(prop.key.start, "Binding " + prop.key.name);
597
- prop.value = this.parseMaybeDefault(start, prop.key);
598
- } else if (this.type === tt.eq && refShorthandDefaultPos) {
599
- if (!refShorthandDefaultPos.start) refShorthandDefaultPos.start = this.start;
600
- prop.value = this.parseMaybeDefault(start, prop.key);
601
- } else {
602
- prop.value = prop.key;
603
- }
604
- prop.shorthand = true;
605
- } else this.unexpected();
606
-
607
- this.checkPropClash(prop, propHash);
608
- node.properties.push(this.finishNode(prop, "Property"));
609
- }
610
- return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression");
611
- };
612
-
613
- pp.parsePropertyName = function (prop) {
614
- if (this.options.ecmaVersion >= 6) {
615
- if (this.eat(tt.bracketL)) {
616
- prop.computed = true;
617
- prop.key = this.parseMaybeAssign();
618
- this.expect(tt.bracketR);
619
- return;
620
- } else {
621
- prop.computed = false;
622
- }
623
- }
624
- prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true);
625
- };
626
-
627
- // Initialize empty function node.
628
-
629
- pp.initFunction = function (node) {
630
- node.id = null;
631
- if (this.options.ecmaVersion >= 6) {
632
- node.generator = false;
633
- node.expression = false;
634
- }
635
- };
636
-
637
- // Parse object or class method.
638
-
639
- pp.parseMethod = function (isGenerator) {
640
- var node = this.startNode();
641
- this.initFunction(node);
642
- this.expect(tt.parenL);
643
- node.params = this.parseBindingList(tt.parenR, false, false);
644
- var allowExpressionBody = undefined;
645
- if (this.options.ecmaVersion >= 6) {
646
- node.generator = isGenerator;
647
- allowExpressionBody = true;
648
- } else {
649
- allowExpressionBody = false;
650
- }
651
- this.parseFunctionBody(node, allowExpressionBody);
652
- return this.finishNode(node, "FunctionExpression");
653
- };
654
-
655
- // Parse arrow function expression with given parameters.
656
-
657
- pp.parseArrowExpression = function (node, params) {
658
- this.initFunction(node);
659
- node.params = this.toAssignableList(params, true);
660
- this.parseFunctionBody(node, true);
661
- return this.finishNode(node, "ArrowFunctionExpression");
662
- };
663
-
664
- // Parse function body and check parameters.
665
-
666
- pp.parseFunctionBody = function (node, allowExpression) {
667
- var isExpression = allowExpression && this.type !== tt.braceL;
668
-
669
- if (isExpression) {
670
- node.body = this.parseMaybeAssign();
671
- node.expression = true;
672
- } else {
673
- // Start a new scope with regard to labels and the `inFunction`
674
- // flag (restore them to their old value afterwards).
675
- var oldInFunc = this.inFunction,
676
- oldInGen = this.inGenerator,
677
- oldLabels = this.labels;
678
- this.inFunction = true;this.inGenerator = node.generator;this.labels = [];
679
- node.body = this.parseBlock(true);
680
- node.expression = false;
681
- this.inFunction = oldInFunc;this.inGenerator = oldInGen;this.labels = oldLabels;
682
- }
683
-
684
- // If this is a strict mode function, verify that argument names
685
- // are not repeated, and it does not try to bind the words `eval`
686
- // or `arguments`.
687
- if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) {
688
- var nameHash = {},
689
- oldStrict = this.strict;
690
- this.strict = true;
691
- if (node.id) this.checkLVal(node.id, true);
692
- for (var i = 0; i < node.params.length; i++) {
693
- this.checkLVal(node.params[i], true, nameHash);
694
- }this.strict = oldStrict;
695
- }
696
- };
697
-
698
- // Parses a comma-separated list of expressions, and returns them as
699
- // an array. `close` is the token type that ends the list, and
700
- // `allowEmpty` can be turned on to allow subsequent commas with
701
- // nothing in between them to be parsed as `null` (which is needed
702
- // for array literals).
703
-
704
- pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthandDefaultPos) {
705
- var elts = [],
706
- first = true;
707
- while (!this.eat(close)) {
708
- if (!first) {
709
- this.expect(tt.comma);
710
- if (allowTrailingComma && this.afterTrailingComma(close)) break;
711
- } else first = false;
712
-
713
- if (allowEmpty && this.type === tt.comma) {
714
- elts.push(null);
715
- } else {
716
- if (this.type === tt.ellipsis) elts.push(this.parseSpread(refShorthandDefaultPos));else elts.push(this.parseMaybeAssign(false, refShorthandDefaultPos));
717
- }
718
- }
719
- return elts;
720
- };
721
-
722
- // Parse the next token as an identifier. If `liberal` is true (used
723
- // when parsing properties), it will also convert keywords into
724
- // identifiers.
725
-
726
- pp.parseIdent = function (liberal) {
727
- var node = this.startNode();
728
- if (liberal && this.options.allowReserved == "never") liberal = false;
729
- if (this.type === tt.name) {
730
- if (!liberal && (!this.options.allowReserved && this.isReservedWord(this.value) || this.strict && reservedWords.strict(this.value) && (this.options.ecmaVersion >= 6 || this.input.slice(this.start, this.end).indexOf("\\") == -1))) this.raise(this.start, "The keyword '" + this.value + "' is reserved");
731
- node.name = this.value;
732
- } else if (liberal && this.type.keyword) {
733
- node.name = this.type.keyword;
734
- } else {
735
- this.unexpected();
736
- }
737
- this.next();
738
- return this.finishNode(node, "Identifier");
739
- };
740
-
741
- // Parses yield expression inside generator.
742
-
743
- pp.parseYield = function () {
744
- var node = this.startNode();
745
- this.next();
746
- if (this.type == tt.semi || this.canInsertSemicolon() || this.type != tt.star && !this.type.startsExpr) {
747
- node.delegate = false;
748
- node.argument = null;
749
- } else {
750
- node.delegate = this.eat(tt.star);
751
- node.argument = this.parseMaybeAssign();
752
- }
753
- return this.finishNode(node, "YieldExpression");
754
- };
755
-
756
- // Parses array and generator comprehensions.
757
-
758
- pp.parseComprehension = function (node, isGenerator) {
759
- node.blocks = [];
760
- while (this.type === tt._for) {
761
- var block = this.startNode();
762
- this.next();
763
- this.expect(tt.parenL);
764
- block.left = this.parseBindingAtom();
765
- this.checkLVal(block.left, true);
766
- this.expectContextual("of");
767
- block.right = this.parseExpression();
768
- this.expect(tt.parenR);
769
- node.blocks.push(this.finishNode(block, "ComprehensionBlock"));
770
- }
771
- node.filter = this.eat(tt._if) ? this.parseParenExpression() : null;
772
- node.body = this.parseExpression();
773
- this.expect(isGenerator ? tt.parenR : tt.bracketR);
774
- node.generator = isGenerator;
775
- return this.finishNode(node, "ComprehensionExpression");
776
- };
777
-
778
- },{"./identifier":3,"./state":9,"./tokentype":13,"./util":14}],3:[function(_dereq_,module,exports){
779
-
780
-
781
- // Test whether a given character code starts an identifier.
782
-
783
- "use strict";
784
-
785
- exports.isIdentifierStart = isIdentifierStart;
786
-
787
- // Test whether a given character is part of an identifier.
788
-
789
- exports.isIdentifierChar = isIdentifierChar;
790
- exports.__esModule = true;
791
- // This is a trick taken from Esprima. It turns out that, on
792
- // non-Chrome browsers, to check whether a string is in a set, a
793
- // predicate containing a big ugly `switch` statement is faster than
794
- // a regular expression, and on Chrome the two are about on par.
795
- // This function uses `eval` (non-lexical) to produce such a
796
- // predicate from a space-separated string of words.
797
- //
798
- // It starts by sorting the words by length.
799
-
800
- function makePredicate(words) {
801
- words = words.split(" ");
802
- var f = "",
803
- cats = [];
804
- out: for (var i = 0; i < words.length; ++i) {
805
- for (var j = 0; j < cats.length; ++j) {
806
- if (cats[j][0].length == words[i].length) {
807
- cats[j].push(words[i]);
808
- continue out;
809
- }
810
- }cats.push([words[i]]);
811
- }
812
- function compareTo(arr) {
813
- if (arr.length == 1) {
814
- return f += "return str === " + JSON.stringify(arr[0]) + ";";
815
- }f += "switch(str){";
816
- for (var i = 0; i < arr.length; ++i) {
817
- f += "case " + JSON.stringify(arr[i]) + ":";
818
- }f += "return true}return false;";
819
- }
820
-
821
- // When there are more than three length categories, an outer
822
- // switch first dispatches on the lengths, to save on comparisons.
823
-
824
- if (cats.length > 3) {
825
- cats.sort(function (a, b) {
826
- return b.length - a.length;
827
- });
828
- f += "switch(str.length){";
829
- for (var i = 0; i < cats.length; ++i) {
830
- var cat = cats[i];
831
- f += "case " + cat[0].length + ":";
832
- compareTo(cat);
833
- }
834
- f += "}"
835
-
836
- // Otherwise, simply generate a flat `switch` statement.
837
-
838
- ;
839
- } else {
840
- compareTo(words);
841
- }
842
- return new Function("str", f);
843
- }
844
-
845
- // Reserved word lists for various dialects of the language
846
-
847
- var reservedWords = {
848
- 3: makePredicate("abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile"),
849
- 5: makePredicate("class enum extends super const export import"),
850
- 6: makePredicate("enum await"),
851
- strict: makePredicate("implements interface let package private protected public static yield"),
852
- strictBind: makePredicate("eval arguments")
853
- };
854
-
855
- exports.reservedWords = reservedWords;
856
- // And the keywords
857
-
858
- var ecma5AndLessKeywords = "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";
859
-
860
- var keywords = {
861
- 5: makePredicate(ecma5AndLessKeywords),
862
- 6: makePredicate(ecma5AndLessKeywords + " let const class extends export import yield super")
863
- };
864
-
865
- exports.keywords = keywords;
866
- // ## Character categories
867
-
868
- // Big ugly regular expressions that match characters in the
869
- // whitespace, identifier, and identifier-start categories. These
870
- // are only applied when a character is found to actually have a
871
- // code point above 128.
872
- // Generated by `tools/generate-identifier-regex.js`.
873
-
874
- var nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠ-ࢲऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞭꞰꞱꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭟꭤꭥꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ";
875
- var nonASCIIidentifierChars = "‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣤ-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఃా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏ᦰ-ᧀᧈᧉ᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷼-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-꣄꣐-꣙꣠-꣱꤀-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︭︳︴﹍-﹏0-9_";
876
-
877
- var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
878
- var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
879
-
880
- nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
881
-
882
- // These are a run-length and offset encoded representation of the
883
- // >0xffff code points that are a valid part of identifiers. The
884
- // offset starts at 0x10000, and each pair of numbers represents an
885
- // offset to the next range, and then a size of the range. They were
886
- // generated by tools/generate-identifier-regex.js
887
- var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 17, 26, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 99, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 98, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 26, 45, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 955, 52, 76, 44, 33, 24, 27, 35, 42, 34, 4, 0, 13, 47, 15, 3, 22, 0, 38, 17, 2, 24, 133, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 32, 4, 287, 47, 21, 1, 2, 0, 185, 46, 82, 47, 21, 0, 60, 42, 502, 63, 32, 0, 449, 56, 1288, 920, 104, 110, 2962, 1070, 13266, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 881, 68, 12, 0, 67, 12, 16481, 1, 3071, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 4149, 196, 1340, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 16355, 541];
888
- var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 1306, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 52, 0, 13, 2, 49, 13, 16, 9, 83, 11, 168, 11, 6, 9, 8, 2, 57, 0, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 316, 19, 13, 9, 214, 6, 3, 8, 112, 16, 16, 9, 82, 12, 9, 9, 535, 9, 20855, 9, 135, 4, 60, 6, 26, 9, 1016, 45, 17, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 4305, 6, 792618, 239];
889
-
890
- // This has a complexity linear to the value of the code. The
891
- // assumption is that looking up astral identifier characters is
892
- // rare.
893
- function isInAstralSet(code, set) {
894
- var pos = 65536;
895
- for (var i = 0; i < set.length; i += 2) {
896
- pos += set[i];
897
- if (pos > code) {
898
- return false;
899
- }pos += set[i + 1];
900
- if (pos >= code) {
901
- return true;
902
- }
903
- }
904
- }
905
- function isIdentifierStart(code, astral) {
906
- if (code < 65) {
907
- return code === 36;
908
- }if (code < 91) {
909
- return true;
910
- }if (code < 97) {
911
- return code === 95;
912
- }if (code < 123) {
913
- return true;
914
- }if (code <= 65535) {
915
- return code >= 170 && nonASCIIidentifierStart.test(String.fromCharCode(code));
916
- }if (astral === false) {
917
- return false;
918
- }return isInAstralSet(code, astralIdentifierStartCodes);
919
- }
920
-
921
- function isIdentifierChar(code, astral) {
922
- if (code < 48) {
923
- return code === 36;
924
- }if (code < 58) {
925
- return true;
926
- }if (code < 65) {
927
- return false;
928
- }if (code < 91) {
929
- return true;
930
- }if (code < 97) {
931
- return code === 95;
932
- }if (code < 123) {
933
- return true;
934
- }if (code <= 65535) {
935
- return code >= 170 && nonASCIIidentifier.test(String.fromCharCode(code));
936
- }if (astral === false) {
937
- return false;
938
- }return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
939
- }
940
-
941
- },{}],4:[function(_dereq_,module,exports){
942
- "use strict";
943
-
944
- var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
945
-
946
- // The `getLineInfo` function is mostly useful when the
947
- // `locations` option is off (for performance reasons) and you
948
- // want to find the line/column position for a given character
949
- // offset. `input` should be the code string that the offset refers
950
- // into.
951
-
952
- exports.getLineInfo = getLineInfo;
953
- exports.__esModule = true;
954
-
955
- var Parser = _dereq_("./state").Parser;
956
-
957
- var lineBreakG = _dereq_("./whitespace").lineBreakG;
958
-
959
- // These are used when `options.locations` is on, for the
960
- // `startLoc` and `endLoc` properties.
961
-
962
- var Position = exports.Position = (function () {
963
- function Position(line, col) {
964
- _classCallCheck(this, Position);
965
-
966
- this.line = line;
967
- this.column = col;
968
- }
969
-
970
- Position.prototype.offset = function offset(n) {
971
- return new Position(this.line, this.column + n);
972
- };
973
-
974
- return Position;
975
- })();
976
-
977
- var SourceLocation = exports.SourceLocation = function SourceLocation(p, start, end) {
978
- _classCallCheck(this, SourceLocation);
979
-
980
- this.start = start;
981
- this.end = end;
982
- if (p.sourceFile !== null) this.source = p.sourceFile;
983
- };
984
-
985
- function getLineInfo(input, offset) {
986
- for (var line = 1, cur = 0;;) {
987
- lineBreakG.lastIndex = cur;
988
- var match = lineBreakG.exec(input);
989
- if (match && match.index < offset) {
990
- ++line;
991
- cur = match.index + match[0].length;
992
- } else {
993
- return new Position(line, offset - cur);
994
- }
995
- }
996
- }
997
-
998
- var pp = Parser.prototype;
999
-
1000
- // This function is used to raise exceptions on parse errors. It
1001
- // takes an offset integer (into the current `input`) to indicate
1002
- // the location of the error, attaches the position to the end
1003
- // of the error message, and then raises a `SyntaxError` with that
1004
- // message.
1005
-
1006
- pp.raise = function (pos, message) {
1007
- var loc = getLineInfo(this.input, pos);
1008
- message += " (" + loc.line + ":" + loc.column + ")";
1009
- var err = new SyntaxError(message);
1010
- err.pos = pos;err.loc = loc;err.raisedAt = this.pos;
1011
- throw err;
1012
- };
1013
-
1014
- pp.curPosition = function () {
1015
- return new Position(this.curLine, this.pos - this.lineStart);
1016
- };
1017
-
1018
- pp.markPosition = function () {
1019
- return this.options.locations ? [this.start, this.startLoc] : this.start;
1020
- };
1021
-
1022
- },{"./state":9,"./whitespace":15}],5:[function(_dereq_,module,exports){
1023
- "use strict";
1024
-
1025
- var tt = _dereq_("./tokentype").types;
1026
-
1027
- var Parser = _dereq_("./state").Parser;
1028
-
1029
- var reservedWords = _dereq_("./identifier").reservedWords;
1030
-
1031
- var has = _dereq_("./util").has;
1032
-
1033
- var pp = Parser.prototype;
1034
-
1035
- // Convert existing expression atom to assignable pattern
1036
- // if possible.
1037
-
1038
- pp.toAssignable = function (node, isBinding) {
1039
- if (this.options.ecmaVersion >= 6 && node) {
1040
- switch (node.type) {
1041
- case "Identifier":
1042
- case "ObjectPattern":
1043
- case "ArrayPattern":
1044
- case "AssignmentPattern":
1045
- break;
1046
-
1047
- case "ObjectExpression":
1048
- node.type = "ObjectPattern";
1049
- for (var i = 0; i < node.properties.length; i++) {
1050
- var prop = node.properties[i];
1051
- if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter");
1052
- this.toAssignable(prop.value, isBinding);
1053
- }
1054
- break;
1055
-
1056
- case "ArrayExpression":
1057
- node.type = "ArrayPattern";
1058
- this.toAssignableList(node.elements, isBinding);
1059
- break;
1060
-
1061
- case "AssignmentExpression":
1062
- if (node.operator === "=") {
1063
- node.type = "AssignmentPattern";
1064
- } else {
1065
- this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
1066
- }
1067
- break;
1068
-
1069
- case "MemberExpression":
1070
- if (!isBinding) break;
1071
-
1072
- default:
1073
- this.raise(node.start, "Assigning to rvalue");
1074
- }
1075
- }
1076
- return node;
1077
- };
1078
-
1079
- // Convert list of expression atoms to binding list.
1080
-
1081
- pp.toAssignableList = function (exprList, isBinding) {
1082
- var end = exprList.length;
1083
- if (end) {
1084
- var last = exprList[end - 1];
1085
- if (last && last.type == "RestElement") {
1086
- --end;
1087
- } else if (last && last.type == "SpreadElement") {
1088
- last.type = "RestElement";
1089
- var arg = last.argument;
1090
- this.toAssignable(arg, isBinding);
1091
- if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") this.unexpected(arg.start);
1092
- --end;
1093
- }
1094
- }
1095
- for (var i = 0; i < end; i++) {
1096
- var elt = exprList[i];
1097
- if (elt) this.toAssignable(elt, isBinding);
1098
- }
1099
- return exprList;
1100
- };
1101
-
1102
- // Parses spread element.
1103
-
1104
- pp.parseSpread = function (refShorthandDefaultPos) {
1105
- var node = this.startNode();
1106
- this.next();
1107
- node.argument = this.parseMaybeAssign(refShorthandDefaultPos);
1108
- return this.finishNode(node, "SpreadElement");
1109
- };
1110
-
1111
- pp.parseRest = function () {
1112
- var node = this.startNode();
1113
- this.next();
1114
- node.argument = this.type === tt.name || this.type === tt.bracketL ? this.parseBindingAtom() : this.unexpected();
1115
- return this.finishNode(node, "RestElement");
1116
- };
1117
-
1118
- // Parses lvalue (assignable) atom.
1119
-
1120
- pp.parseBindingAtom = function () {
1121
- if (this.options.ecmaVersion < 6) return this.parseIdent();
1122
- switch (this.type) {
1123
- case tt.name:
1124
- return this.parseIdent();
1125
-
1126
- case tt.bracketL:
1127
- var node = this.startNode();
1128
- this.next();
1129
- node.elements = this.parseBindingList(tt.bracketR, true, true);
1130
- return this.finishNode(node, "ArrayPattern");
1131
-
1132
- case tt.braceL:
1133
- return this.parseObj(true);
1134
-
1135
- default:
1136
- this.unexpected();
1137
- }
1138
- };
1139
-
1140
- pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
1141
- var elts = [],
1142
- first = true;
1143
- while (!this.eat(close)) {
1144
- if (first) first = false;else this.expect(tt.comma);
1145
- if (allowEmpty && this.type === tt.comma) {
1146
- elts.push(null);
1147
- } else if (allowTrailingComma && this.afterTrailingComma(close)) {
1148
- break;
1149
- } else if (this.type === tt.ellipsis) {
1150
- elts.push(this.parseRest());
1151
- this.expect(close);
1152
- break;
1153
- } else {
1154
- elts.push(this.parseMaybeDefault());
1155
- }
1156
- }
1157
- return elts;
1158
- };
1159
-
1160
- // Parses assignment pattern around given atom if possible.
1161
-
1162
- pp.parseMaybeDefault = function (startPos, left) {
1163
- startPos = startPos || this.markPosition();
1164
- left = left || this.parseBindingAtom();
1165
- if (!this.eat(tt.eq)) return left;
1166
- var node = this.startNodeAt(startPos);
1167
- node.operator = "=";
1168
- node.left = left;
1169
- node.right = this.parseMaybeAssign();
1170
- return this.finishNode(node, "AssignmentPattern");
1171
- };
1172
-
1173
- // Verify that a node is an lval — something that can be assigned
1174
- // to.
1175
-
1176
- pp.checkLVal = function (expr, isBinding, checkClashes) {
1177
- switch (expr.type) {
1178
- case "Identifier":
1179
- if (this.strict && (reservedWords.strictBind(expr.name) || reservedWords.strict(expr.name))) this.raise(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode");
1180
- if (checkClashes) {
1181
- if (has(checkClashes, expr.name)) this.raise(expr.start, "Argument name clash in strict mode");
1182
- checkClashes[expr.name] = true;
1183
- }
1184
- break;
1185
-
1186
- case "MemberExpression":
1187
- if (isBinding) this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression");
1188
- break;
1189
-
1190
- case "ObjectPattern":
1191
- for (var i = 0; i < expr.properties.length; i++) {
1192
- this.checkLVal(expr.properties[i].value, isBinding, checkClashes);
1193
- }break;
1194
-
1195
- case "ArrayPattern":
1196
- for (var i = 0; i < expr.elements.length; i++) {
1197
- var elem = expr.elements[i];
1198
- if (elem) this.checkLVal(elem, isBinding, checkClashes);
1199
- }
1200
- break;
1201
-
1202
- case "AssignmentPattern":
1203
- this.checkLVal(expr.left, isBinding, checkClashes);
1204
- break;
1205
-
1206
- case "RestElement":
1207
- this.checkLVal(expr.argument, isBinding, checkClashes);
1208
- break;
1209
-
1210
- default:
1211
- this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue");
1212
- }
1213
- };
1214
-
1215
- },{"./identifier":3,"./state":9,"./tokentype":13,"./util":14}],6:[function(_dereq_,module,exports){
1216
- "use strict";
1217
-
1218
- var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
1219
-
1220
- exports.__esModule = true;
1221
-
1222
- var Parser = _dereq_("./state").Parser;
1223
-
1224
- var SourceLocation = _dereq_("./location").SourceLocation;
1225
-
1226
- // Start an AST node, attaching a start offset.
1227
-
1228
- var pp = Parser.prototype;
1229
-
1230
- var Node = exports.Node = function Node() {
1231
- _classCallCheck(this, Node);
1232
- };
1233
-
1234
- pp.startNode = function () {
1235
- var node = new Node();
1236
- node.start = this.start;
1237
- if (this.options.locations) node.loc = new SourceLocation(this, this.startLoc);
1238
- if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
1239
- if (this.options.ranges) node.range = [this.start, 0];
1240
- return node;
1241
- };
1242
-
1243
- pp.startNodeAt = function (pos) {
1244
- var node = new Node(),
1245
- start = pos;
1246
- if (this.options.locations) {
1247
- node.loc = new SourceLocation(this, start[1]);
1248
- start = pos[0];
1249
- }
1250
- node.start = start;
1251
- if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
1252
- if (this.options.ranges) node.range = [start, 0];
1253
- return node;
1254
- };
1255
-
1256
- // Finish an AST node, adding `type` and `end` properties.
1257
-
1258
- pp.finishNode = function (node, type) {
1259
- node.type = type;
1260
- node.end = this.lastTokEnd;
1261
- if (this.options.locations) node.loc.end = this.lastTokEndLoc;
1262
- if (this.options.ranges) node.range[1] = this.lastTokEnd;
1263
- return node;
1264
- };
1265
-
1266
- // Finish node at given position
1267
-
1268
- pp.finishNodeAt = function (node, type, pos) {
1269
- if (this.options.locations) {
1270
- node.loc.end = pos[1];pos = pos[0];
1271
- }
1272
- node.type = type;
1273
- node.end = pos;
1274
- if (this.options.ranges) node.range[1] = pos;
1275
- return node;
1276
- };
1277
-
1278
- },{"./location":4,"./state":9}],7:[function(_dereq_,module,exports){
1279
-
1280
-
1281
- // Interpret and default an options object
1282
-
1283
- "use strict";
1284
-
1285
- exports.getOptions = getOptions;
1286
- exports.__esModule = true;
1287
-
1288
- var _util = _dereq_("./util");
1289
-
1290
- var has = _util.has;
1291
- var isArray = _util.isArray;
1292
-
1293
- var SourceLocation = _dereq_("./location").SourceLocation;
1294
-
1295
- // A second optional argument can be given to further configure
1296
- // the parser process. These options are recognized:
1297
-
1298
- var defaultOptions = {
1299
- // `ecmaVersion` indicates the ECMAScript version to parse. Must
1300
- // be either 3, or 5, or 6. This influences support for strict
1301
- // mode, the set of reserved words, support for getters and
1302
- // setters and other features.
1303
- ecmaVersion: 5,
1304
- // Source type ("script" or "module") for different semantics
1305
- sourceType: "script",
1306
- // `onInsertedSemicolon` can be a callback that will be called
1307
- // when a semicolon is automatically inserted. It will be passed
1308
- // th position of the comma as an offset, and if `locations` is
1309
- // enabled, it is given the location as a `{line, column}` object
1310
- // as second argument.
1311
- onInsertedSemicolon: null,
1312
- // `onTrailingComma` is similar to `onInsertedSemicolon`, but for
1313
- // trailing commas.
1314
- onTrailingComma: null,
1315
- // By default, reserved words are not enforced. Disable
1316
- // `allowReserved` to enforce them. When this option has the
1317
- // value "never", reserved words and keywords can also not be
1318
- // used as property names.
1319
- allowReserved: true,
1320
- // When enabled, a return at the top level is not considered an
1321
- // error.
1322
- allowReturnOutsideFunction: false,
1323
- // When enabled, import/export statements are not constrained to
1324
- // appearing at the top of the program.
1325
- allowImportExportEverywhere: false,
1326
- // When enabled, hashbang directive in the beginning of file
1327
- // is allowed and treated as a line comment.
1328
- allowHashBang: false,
1329
- // When `locations` is on, `loc` properties holding objects with
1330
- // `start` and `end` properties in `{line, column}` form (with
1331
- // line being 1-based and column 0-based) will be attached to the
1332
- // nodes.
1333
- locations: false,
1334
- // A function can be passed as `onToken` option, which will
1335
- // cause Acorn to call that function with object in the same
1336
- // format as tokenize() returns. Note that you are not
1337
- // allowed to call the parser from the callback—that will
1338
- // corrupt its internal state.
1339
- onToken: null,
1340
- // A function can be passed as `onComment` option, which will
1341
- // cause Acorn to call that function with `(block, text, start,
1342
- // end)` parameters whenever a comment is skipped. `block` is a
1343
- // boolean indicating whether this is a block (`/* */`) comment,
1344
- // `text` is the content of the comment, and `start` and `end` are
1345
- // character offsets that denote the start and end of the comment.
1346
- // When the `locations` option is on, two more parameters are
1347
- // passed, the full `{line, column}` locations of the start and
1348
- // end of the comments. Note that you are not allowed to call the
1349
- // parser from the callback—that will corrupt its internal state.
1350
- onComment: null,
1351
- // Nodes have their start and end characters offsets recorded in
1352
- // `start` and `end` properties (directly on the node, rather than
1353
- // the `loc` object, which holds line/column data. To also add a
1354
- // [semi-standardized][range] `range` property holding a `[start,
1355
- // end]` array with the same numbers, set the `ranges` option to
1356
- // `true`.
1357
- //
1358
- // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
1359
- ranges: false,
1360
- // It is possible to parse multiple files into a single AST by
1361
- // passing the tree produced by parsing the first file as
1362
- // `program` option in subsequent parses. This will add the
1363
- // toplevel forms of the parsed file to the `Program` (top) node
1364
- // of an existing parse tree.
1365
- program: null,
1366
- // When `locations` is on, you can pass this to record the source
1367
- // file in every node's `loc` object.
1368
- sourceFile: null,
1369
- // This value, if given, is stored in every node, whether
1370
- // `locations` is on or off.
1371
- directSourceFile: null,
1372
- // When enabled, parenthesized expressions are represented by
1373
- // (non-standard) ParenthesizedExpression nodes
1374
- preserveParens: false,
1375
- plugins: {}
1376
- };exports.defaultOptions = defaultOptions;
1377
-
1378
- function getOptions(opts) {
1379
- var options = {};
1380
- for (var opt in defaultOptions) {
1381
- options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt];
1382
- }if (isArray(options.onToken)) {
1383
- (function () {
1384
- var tokens = options.onToken;
1385
- options.onToken = function (token) {
1386
- return tokens.push(token);
1387
- };
1388
- })();
1389
- }
1390
- if (isArray(options.onComment)) options.onComment = pushComment(options, options.onComment);
1391
-
1392
- return options;
1393
- }
1394
-
1395
- function pushComment(options, array) {
1396
- return function (block, text, start, end, startLoc, endLoc) {
1397
- var comment = {
1398
- type: block ? "Block" : "Line",
1399
- value: text,
1400
- start: start,
1401
- end: end
1402
- };
1403
- if (options.locations) comment.loc = new SourceLocation(this, startLoc, endLoc);
1404
- if (options.ranges) comment.range = [start, end];
1405
- array.push(comment);
1406
- };
1407
- }
1408
-
1409
- },{"./location":4,"./util":14}],8:[function(_dereq_,module,exports){
1410
- "use strict";
1411
-
1412
- var tt = _dereq_("./tokentype").types;
1413
-
1414
- var Parser = _dereq_("./state").Parser;
1415
-
1416
- var lineBreak = _dereq_("./whitespace").lineBreak;
1417
-
1418
- var pp = Parser.prototype;
1419
-
1420
- // ## Parser utilities
1421
-
1422
- // Test whether a statement node is the string literal `"use strict"`.
1423
-
1424
- pp.isUseStrict = function (stmt) {
1425
- return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.value === "use strict";
1426
- };
1427
-
1428
- // Predicate that tests whether the next token is of the given
1429
- // type, and if yes, consumes it as a side effect.
1430
-
1431
- pp.eat = function (type) {
1432
- if (this.type === type) {
1433
- this.next();
1434
- return true;
1435
- } else {
1436
- return false;
1437
- }
1438
- };
1439
-
1440
- // Tests whether parsed token is a contextual keyword.
1441
-
1442
- pp.isContextual = function (name) {
1443
- return this.type === tt.name && this.value === name;
1444
- };
1445
-
1446
- // Consumes contextual keyword if possible.
1447
-
1448
- pp.eatContextual = function (name) {
1449
- return this.value === name && this.eat(tt.name);
1450
- };
1451
-
1452
- // Asserts that following token is given contextual keyword.
1453
-
1454
- pp.expectContextual = function (name) {
1455
- if (!this.eatContextual(name)) this.unexpected();
1456
- };
1457
-
1458
- // Test whether a semicolon can be inserted at the current position.
1459
-
1460
- pp.canInsertSemicolon = function () {
1461
- return this.type === tt.eof || this.type === tt.braceR || lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
1462
- };
1463
-
1464
- pp.insertSemicolon = function () {
1465
- if (this.canInsertSemicolon()) {
1466
- if (this.options.onInsertedSemicolon) this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc);
1467
- return true;
1468
- }
1469
- };
1470
-
1471
- // Consume a semicolon, or, failing that, see if we are allowed to
1472
- // pretend that there is a semicolon at this position.
1473
-
1474
- pp.semicolon = function () {
1475
- if (!this.eat(tt.semi) && !this.insertSemicolon()) this.unexpected();
1476
- };
1477
-
1478
- pp.afterTrailingComma = function (tokType) {
1479
- if (this.type == tokType) {
1480
- if (this.options.onTrailingComma) this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc);
1481
- this.next();
1482
- return true;
1483
- }
1484
- };
1485
-
1486
- // Expect a token of a given type. If found, consume it, otherwise,
1487
- // raise an unexpected token error.
1488
-
1489
- pp.expect = function (type) {
1490
- this.eat(type) || this.unexpected();
1491
- };
1492
-
1493
- // Raise an unexpected token error.
1494
-
1495
- pp.unexpected = function (pos) {
1496
- this.raise(pos != null ? pos : this.start, "Unexpected token");
1497
- };
1498
-
1499
- },{"./state":9,"./tokentype":13,"./whitespace":15}],9:[function(_dereq_,module,exports){
1500
- "use strict";
1501
-
1502
- exports.Parser = Parser;
1503
- exports.__esModule = true;
1504
-
1505
- var _identifier = _dereq_("./identifier");
1506
-
1507
- var reservedWords = _identifier.reservedWords;
1508
- var keywords = _identifier.keywords;
1509
-
1510
- var _tokentype = _dereq_("./tokentype");
1511
-
1512
- var tt = _tokentype.types;
1513
- var lineBreak = _tokentype.lineBreak;
1514
-
1515
- function Parser(options, input, startPos) {
1516
- this.options = options;
1517
- this.loadPlugins(this.options.plugins);
1518
- this.sourceFile = this.options.sourceFile || null;
1519
- this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5];
1520
- this.isReservedWord = reservedWords[this.options.ecmaVersion];
1521
- this.input = input;
1522
-
1523
- // Set up token state
1524
-
1525
- // The current position of the tokenizer in the input.
1526
- if (startPos) {
1527
- this.pos = startPos;
1528
- this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos));
1529
- this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
1530
- } else {
1531
- this.pos = this.lineStart = 0;
1532
- this.curLine = 1;
1533
- }
1534
-
1535
- // Properties of the current token:
1536
- // Its type
1537
- this.type = tt.eof;
1538
- // For tokens that include more information than their type, the value
1539
- this.value = null;
1540
- // Its start and end offset
1541
- this.start = this.end = this.pos;
1542
- // And, if locations are used, the {line, column} object
1543
- // corresponding to those offsets
1544
- this.startLoc = this.endLoc = null;
1545
-
1546
- // Position information for the previous token
1547
- this.lastTokEndLoc = this.lastTokStartLoc = null;
1548
- this.lastTokStart = this.lastTokEnd = this.pos;
1549
-
1550
- // The context stack is used to superficially track syntactic
1551
- // context to predict whether a regular expression is allowed in a
1552
- // given position.
1553
- this.context = this.initialContext();
1554
- this.exprAllowed = true;
1555
-
1556
- // Figure out if it's a module code.
1557
- this.strict = this.inModule = this.options.sourceType === "module";
1558
-
1559
- // Flags to track whether we are in a function, a generator.
1560
- this.inFunction = this.inGenerator = false;
1561
- // Labels in scope.
1562
- this.labels = [];
1563
-
1564
- // If enabled, skip leading hashbang line.
1565
- if (this.pos === 0 && this.options.allowHashBang && this.input.slice(0, 2) === "#!") this.skipLineComment(2);
1566
- }
1567
-
1568
- Parser.prototype.extend = function (name, f) {
1569
- this[name] = f(this[name]);
1570
- };
1571
-
1572
- // Registered plugins
1573
-
1574
- var plugins = {};
1575
-
1576
- exports.plugins = plugins;
1577
- Parser.prototype.loadPlugins = function (plugins) {
1578
- for (var _name in plugins) {
1579
- var plugin = exports.plugins[_name];
1580
- if (!plugin) throw new Error("Plugin '" + _name + "' not found");
1581
- plugin(this, plugins[_name]);
1582
- }
1583
- };
1584
-
1585
- },{"./identifier":3,"./tokentype":13}],10:[function(_dereq_,module,exports){
1586
- "use strict";
1587
-
1588
- var tt = _dereq_("./tokentype").types;
1589
-
1590
- var Parser = _dereq_("./state").Parser;
1591
-
1592
- var lineBreak = _dereq_("./whitespace").lineBreak;
1593
-
1594
- var pp = Parser.prototype;
1595
-
1596
- // ### Statement parsing
1597
-
1598
- // Parse a program. Initializes the parser, reads any number of
1599
- // statements, and wraps them in a Program node. Optionally takes a
1600
- // `program` argument. If present, the statements will be appended
1601
- // to its body instead of creating a new node.
1602
-
1603
- pp.parseTopLevel = function (node) {
1604
- var first = true;
1605
- if (!node.body) node.body = [];
1606
- while (this.type !== tt.eof) {
1607
- var stmt = this.parseStatement(true, true);
1608
- node.body.push(stmt);
1609
- if (first && this.isUseStrict(stmt)) this.setStrict(true);
1610
- first = false;
1611
- }
1612
- this.next();
1613
- if (this.options.ecmaVersion >= 6) {
1614
- node.sourceType = this.options.sourceType;
1615
- }
1616
- return this.finishNode(node, "Program");
1617
- };
1618
-
1619
- var loopLabel = { kind: "loop" },
1620
- switchLabel = { kind: "switch" };
1621
-
1622
- // Parse a single statement.
1623
- //
1624
- // If expecting a statement and finding a slash operator, parse a
1625
- // regular expression literal. This is to handle cases like
1626
- // `if (foo) /blah/.exec(foo)`, where looking at the previous token
1627
- // does not help.
1628
-
1629
- pp.parseStatement = function (declaration, topLevel) {
1630
- var starttype = this.type,
1631
- node = this.startNode();
1632
-
1633
- // Most types of statements are recognized by the keyword they
1634
- // start with. Many are trivial to parse, some require a bit of
1635
- // complexity.
1636
-
1637
- switch (starttype) {
1638
- case tt._break:case tt._continue:
1639
- return this.parseBreakContinueStatement(node, starttype.keyword);
1640
- case tt._debugger:
1641
- return this.parseDebuggerStatement(node);
1642
- case tt._do:
1643
- return this.parseDoStatement(node);
1644
- case tt._for:
1645
- return this.parseForStatement(node);
1646
- case tt._function:
1647
- if (!declaration && this.options.ecmaVersion >= 6) this.unexpected();
1648
- return this.parseFunctionStatement(node);
1649
- case tt._class:
1650
- if (!declaration) this.unexpected();
1651
- return this.parseClass(node, true);
1652
- case tt._if:
1653
- return this.parseIfStatement(node);
1654
- case tt._return:
1655
- return this.parseReturnStatement(node);
1656
- case tt._switch:
1657
- return this.parseSwitchStatement(node);
1658
- case tt._throw:
1659
- return this.parseThrowStatement(node);
1660
- case tt._try:
1661
- return this.parseTryStatement(node);
1662
- case tt._let:case tt._const:
1663
- if (!declaration) this.unexpected(); // NOTE: falls through to _var
1664
- case tt._var:
1665
- return this.parseVarStatement(node, starttype);
1666
- case tt._while:
1667
- return this.parseWhileStatement(node);
1668
- case tt._with:
1669
- return this.parseWithStatement(node);
1670
- case tt.braceL:
1671
- return this.parseBlock();
1672
- case tt.semi:
1673
- return this.parseEmptyStatement(node);
1674
- case tt._export:
1675
- case tt._import:
1676
- if (!this.options.allowImportExportEverywhere) {
1677
- if (!topLevel) this.raise(this.start, "'import' and 'export' may only appear at the top level");
1678
- if (!this.inModule) this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'");
1679
- }
1680
- return starttype === tt._import ? this.parseImport(node) : this.parseExport(node);
1681
-
1682
- // If the statement does not start with a statement keyword or a
1683
- // brace, it's an ExpressionStatement or LabeledStatement. We
1684
- // simply start parsing an expression, and afterwards, if the
1685
- // next token is a colon and the expression was a simple
1686
- // Identifier node, we switch to interpreting it as a label.
1687
- default:
1688
- var maybeName = this.value,
1689
- expr = this.parseExpression();
1690
- if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) return this.parseLabeledStatement(node, maybeName, expr);else return this.parseExpressionStatement(node, expr);
1691
- }
1692
- };
1693
-
1694
- pp.parseBreakContinueStatement = function (node, keyword) {
1695
- var isBreak = keyword == "break";
1696
- this.next();
1697
- if (this.eat(tt.semi) || this.insertSemicolon()) node.label = null;else if (this.type !== tt.name) this.unexpected();else {
1698
- node.label = this.parseIdent();
1699
- this.semicolon();
1700
- }
1701
-
1702
- // Verify that there is an actual destination to break or
1703
- // continue to.
1704
- for (var i = 0; i < this.labels.length; ++i) {
1705
- var lab = this.labels[i];
1706
- if (node.label == null || lab.name === node.label.name) {
1707
- if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
1708
- if (node.label && isBreak) break;
1709
- }
1710
- }
1711
- if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword);
1712
- return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
1713
- };
1714
-
1715
- pp.parseDebuggerStatement = function (node) {
1716
- this.next();
1717
- this.semicolon();
1718
- return this.finishNode(node, "DebuggerStatement");
1719
- };
1720
-
1721
- pp.parseDoStatement = function (node) {
1722
- this.next();
1723
- this.labels.push(loopLabel);
1724
- node.body = this.parseStatement(false);
1725
- this.labels.pop();
1726
- this.expect(tt._while);
1727
- node.test = this.parseParenExpression();
1728
- if (this.options.ecmaVersion >= 6) this.eat(tt.semi);else this.semicolon();
1729
- return this.finishNode(node, "DoWhileStatement");
1730
- };
1731
-
1732
- // Disambiguating between a `for` and a `for`/`in` or `for`/`of`
1733
- // loop is non-trivial. Basically, we have to parse the init `var`
1734
- // statement or expression, disallowing the `in` operator (see
1735
- // the second parameter to `parseExpression`), and then check
1736
- // whether the next token is `in` or `of`. When there is no init
1737
- // part (semicolon immediately after the opening parenthesis), it
1738
- // is a regular `for` loop.
1739
-
1740
- pp.parseForStatement = function (node) {
1741
- this.next();
1742
- this.labels.push(loopLabel);
1743
- this.expect(tt.parenL);
1744
- if (this.type === tt.semi) return this.parseFor(node, null);
1745
- if (this.type === tt._var || this.type === tt._let || this.type === tt._const) {
1746
- var _init = this.startNode(),
1747
- varKind = this.type;
1748
- this.next();
1749
- this.parseVar(_init, true, varKind);
1750
- this.finishNode(_init, "VariableDeclaration");
1751
- if ((this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && _init.declarations.length === 1 && !(varKind !== tt._var && _init.declarations[0].init)) return this.parseForIn(node, _init);
1752
- return this.parseFor(node, _init);
1753
- }
1754
- var refShorthandDefaultPos = { start: 0 };
1755
- var init = this.parseExpression(true, refShorthandDefaultPos);
1756
- if (this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) {
1757
- this.toAssignable(init);
1758
- this.checkLVal(init);
1759
- return this.parseForIn(node, init);
1760
- } else if (refShorthandDefaultPos.start) {
1761
- this.unexpected(refShorthandDefaultPos.start);
1762
- }
1763
- return this.parseFor(node, init);
1764
- };
1765
-
1766
- pp.parseFunctionStatement = function (node) {
1767
- this.next();
1768
- return this.parseFunction(node, true);
1769
- };
1770
-
1771
- pp.parseIfStatement = function (node) {
1772
- this.next();
1773
- node.test = this.parseParenExpression();
1774
- node.consequent = this.parseStatement(false);
1775
- node.alternate = this.eat(tt._else) ? this.parseStatement(false) : null;
1776
- return this.finishNode(node, "IfStatement");
1777
- };
1778
-
1779
- pp.parseReturnStatement = function (node) {
1780
- if (!this.inFunction && !this.options.allowReturnOutsideFunction) this.raise(this.start, "'return' outside of function");
1781
- this.next();
1782
-
1783
- // In `return` (and `break`/`continue`), the keywords with
1784
- // optional arguments, we eagerly look for a semicolon or the
1785
- // possibility to insert one.
1786
-
1787
- if (this.eat(tt.semi) || this.insertSemicolon()) node.argument = null;else {
1788
- node.argument = this.parseExpression();this.semicolon();
1789
- }
1790
- return this.finishNode(node, "ReturnStatement");
1791
- };
1792
-
1793
- pp.parseSwitchStatement = function (node) {
1794
- this.next();
1795
- node.discriminant = this.parseParenExpression();
1796
- node.cases = [];
1797
- this.expect(tt.braceL);
1798
- this.labels.push(switchLabel);
1799
-
1800
- // Statements under must be grouped (by label) in SwitchCase
1801
- // nodes. `cur` is used to keep the node that we are currently
1802
- // adding statements to.
1803
-
1804
- for (var cur, sawDefault; this.type != tt.braceR;) {
1805
- if (this.type === tt._case || this.type === tt._default) {
1806
- var isCase = this.type === tt._case;
1807
- if (cur) this.finishNode(cur, "SwitchCase");
1808
- node.cases.push(cur = this.startNode());
1809
- cur.consequent = [];
1810
- this.next();
1811
- if (isCase) {
1812
- cur.test = this.parseExpression();
1813
- } else {
1814
- if (sawDefault) this.raise(this.lastTokStart, "Multiple default clauses");
1815
- sawDefault = true;
1816
- cur.test = null;
1817
- }
1818
- this.expect(tt.colon);
1819
- } else {
1820
- if (!cur) this.unexpected();
1821
- cur.consequent.push(this.parseStatement(true));
1822
- }
1823
- }
1824
- if (cur) this.finishNode(cur, "SwitchCase");
1825
- this.next(); // Closing brace
1826
- this.labels.pop();
1827
- return this.finishNode(node, "SwitchStatement");
1828
- };
1829
-
1830
- pp.parseThrowStatement = function (node) {
1831
- this.next();
1832
- if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) this.raise(this.lastTokEnd, "Illegal newline after throw");
1833
- node.argument = this.parseExpression();
1834
- this.semicolon();
1835
- return this.finishNode(node, "ThrowStatement");
1836
- };
1837
-
1838
- // Reused empty array added for node fields that are always empty.
1839
-
1840
- var empty = [];
1841
-
1842
- pp.parseTryStatement = function (node) {
1843
- this.next();
1844
- node.block = this.parseBlock();
1845
- node.handler = null;
1846
- if (this.type === tt._catch) {
1847
- var clause = this.startNode();
1848
- this.next();
1849
- this.expect(tt.parenL);
1850
- clause.param = this.parseBindingAtom();
1851
- this.checkLVal(clause.param, true);
1852
- this.expect(tt.parenR);
1853
- clause.guard = null;
1854
- clause.body = this.parseBlock();
1855
- node.handler = this.finishNode(clause, "CatchClause");
1856
- }
1857
- node.guardedHandlers = empty;
1858
- node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
1859
- if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause");
1860
- return this.finishNode(node, "TryStatement");
1861
- };
1862
-
1863
- pp.parseVarStatement = function (node, kind) {
1864
- this.next();
1865
- this.parseVar(node, false, kind);
1866
- this.semicolon();
1867
- return this.finishNode(node, "VariableDeclaration");
1868
- };
1869
-
1870
- pp.parseWhileStatement = function (node) {
1871
- this.next();
1872
- node.test = this.parseParenExpression();
1873
- this.labels.push(loopLabel);
1874
- node.body = this.parseStatement(false);
1875
- this.labels.pop();
1876
- return this.finishNode(node, "WhileStatement");
1877
- };
1878
-
1879
- pp.parseWithStatement = function (node) {
1880
- if (this.strict) this.raise(this.start, "'with' in strict mode");
1881
- this.next();
1882
- node.object = this.parseParenExpression();
1883
- node.body = this.parseStatement(false);
1884
- return this.finishNode(node, "WithStatement");
1885
- };
1886
-
1887
- pp.parseEmptyStatement = function (node) {
1888
- this.next();
1889
- return this.finishNode(node, "EmptyStatement");
1890
- };
1891
-
1892
- pp.parseLabeledStatement = function (node, maybeName, expr) {
1893
- for (var i = 0; i < this.labels.length; ++i) {
1894
- if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared");
1895
- }var kind = this.type.isLoop ? "loop" : this.type === tt._switch ? "switch" : null;
1896
- this.labels.push({ name: maybeName, kind: kind });
1897
- node.body = this.parseStatement(true);
1898
- this.labels.pop();
1899
- node.label = expr;
1900
- return this.finishNode(node, "LabeledStatement");
1901
- };
1902
-
1903
- pp.parseExpressionStatement = function (node, expr) {
1904
- node.expression = expr;
1905
- this.semicolon();
1906
- return this.finishNode(node, "ExpressionStatement");
1907
- };
1908
-
1909
- // Parse a semicolon-enclosed block of statements, handling `"use
1910
- // strict"` declarations when `allowStrict` is true (used for
1911
- // function bodies).
1912
-
1913
- pp.parseBlock = function (allowStrict) {
1914
- var node = this.startNode(),
1915
- first = true,
1916
- oldStrict = undefined;
1917
- node.body = [];
1918
- this.expect(tt.braceL);
1919
- while (!this.eat(tt.braceR)) {
1920
- var stmt = this.parseStatement(true);
1921
- node.body.push(stmt);
1922
- if (first && allowStrict && this.isUseStrict(stmt)) {
1923
- oldStrict = this.strict;
1924
- this.setStrict(this.strict = true);
1925
- }
1926
- first = false;
1927
- }
1928
- if (oldStrict === false) this.setStrict(false);
1929
- return this.finishNode(node, "BlockStatement");
1930
- };
1931
-
1932
- // Parse a regular `for` loop. The disambiguation code in
1933
- // `parseStatement` will already have parsed the init statement or
1934
- // expression.
1935
-
1936
- pp.parseFor = function (node, init) {
1937
- node.init = init;
1938
- this.expect(tt.semi);
1939
- node.test = this.type === tt.semi ? null : this.parseExpression();
1940
- this.expect(tt.semi);
1941
- node.update = this.type === tt.parenR ? null : this.parseExpression();
1942
- this.expect(tt.parenR);
1943
- node.body = this.parseStatement(false);
1944
- this.labels.pop();
1945
- return this.finishNode(node, "ForStatement");
1946
- };
1947
-
1948
- // Parse a `for`/`in` and `for`/`of` loop, which are almost
1949
- // same from parser's perspective.
1950
-
1951
- pp.parseForIn = function (node, init) {
1952
- var type = this.type === tt._in ? "ForInStatement" : "ForOfStatement";
1953
- this.next();
1954
- node.left = init;
1955
- node.right = this.parseExpression();
1956
- this.expect(tt.parenR);
1957
- node.body = this.parseStatement(false);
1958
- this.labels.pop();
1959
- return this.finishNode(node, type);
1960
- };
1961
-
1962
- // Parse a list of variable declarations.
1963
-
1964
- pp.parseVar = function (node, isFor, kind) {
1965
- node.declarations = [];
1966
- node.kind = kind.keyword;
1967
- for (;;) {
1968
- var decl = this.startNode();
1969
- decl.id = this.parseBindingAtom();
1970
- this.checkLVal(decl.id, true);
1971
- if (this.eat(tt.eq)) {
1972
- decl.init = this.parseMaybeAssign(isFor);
1973
- } else if (kind === tt._const && !(this.type === tt._in || this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
1974
- this.unexpected();
1975
- } else if (decl.id.type != "Identifier" && !(isFor && (this.type === tt._in || this.isContextual("of")))) {
1976
- this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
1977
- } else {
1978
- decl.init = null;
1979
- }
1980
- node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
1981
- if (!this.eat(tt.comma)) break;
1982
- }
1983
- return node;
1984
- };
1985
-
1986
- // Parse a function declaration or literal (depending on the
1987
- // `isStatement` parameter).
1988
-
1989
- pp.parseFunction = function (node, isStatement, allowExpressionBody) {
1990
- this.initFunction(node);
1991
- if (this.options.ecmaVersion >= 6) node.generator = this.eat(tt.star);
1992
- if (isStatement || this.type === tt.name) node.id = this.parseIdent();
1993
- this.expect(tt.parenL);
1994
- node.params = this.parseBindingList(tt.parenR, false, false);
1995
- this.parseFunctionBody(node, allowExpressionBody);
1996
- return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
1997
- };
1998
-
1999
- // Parse a class declaration or literal (depending on the
2000
- // `isStatement` parameter).
2001
-
2002
- pp.parseClass = function (node, isStatement) {
2003
- this.next();
2004
- node.id = this.type === tt.name ? this.parseIdent() : isStatement ? this.unexpected() : null;
2005
- node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null;
2006
- var classBody = this.startNode();
2007
- classBody.body = [];
2008
- this.expect(tt.braceL);
2009
- while (!this.eat(tt.braceR)) {
2010
- if (this.eat(tt.semi)) continue;
2011
- var method = this.startNode();
2012
- var isGenerator = this.eat(tt.star);
2013
- this.parsePropertyName(method);
2014
- if (this.type !== tt.parenL && !method.computed && method.key.type === "Identifier" && method.key.name === "static") {
2015
- if (isGenerator) this.unexpected();
2016
- method["static"] = true;
2017
- isGenerator = this.eat(tt.star);
2018
- this.parsePropertyName(method);
2019
- } else {
2020
- method["static"] = false;
2021
- }
2022
- method.kind = "method";
2023
- if (!method.computed && !isGenerator) {
2024
- if (method.key.type === "Identifier") {
2025
- if (this.type !== tt.parenL && (method.key.name === "get" || method.key.name === "set")) {
2026
- method.kind = method.key.name;
2027
- this.parsePropertyName(method);
2028
- } else if (!method["static"] && method.key.name === "constructor") {
2029
- method.kind = "constructor";
2030
- }
2031
- } else if (!method["static"] && method.key.type === "Literal" && method.key.value === "constructor") {
2032
- method.kind = "constructor";
2033
- }
2034
- }
2035
- method.value = this.parseMethod(isGenerator);
2036
- classBody.body.push(this.finishNode(method, "MethodDefinition"));
2037
- }
2038
- node.body = this.finishNode(classBody, "ClassBody");
2039
- return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
2040
- };
2041
-
2042
- // Parses module export declaration.
2043
-
2044
- pp.parseExport = function (node) {
2045
- this.next();
2046
- // export * from '...'
2047
- if (this.eat(tt.star)) {
2048
- this.expectContextual("from");
2049
- node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
2050
- this.semicolon();
2051
- return this.finishNode(node, "ExportAllDeclaration");
2052
- }
2053
- if (this.eat(tt._default)) {
2054
- // export default ...
2055
- var expr = this.parseMaybeAssign();
2056
- var needsSemi = true;
2057
- if (expr.type == "FunctionExpression" || expr.type == "ClassExpression") {
2058
- needsSemi = false;
2059
- if (expr.id) {
2060
- expr.type = expr.type == "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration";
2061
- }
2062
- }
2063
- node.declaration = expr;
2064
- if (needsSemi) this.semicolon();
2065
- return this.finishNode(node, "ExportDefaultDeclaration");
2066
- }
2067
- // export var|const|let|function|class ...
2068
- if (this.type.keyword) {
2069
- node.declaration = this.parseStatement(true);
2070
- node.specifiers = [];
2071
- node.source = null;
2072
- } else {
2073
- // export { x, y as z } [from '...']
2074
- node.declaration = null;
2075
- node.specifiers = this.parseExportSpecifiers();
2076
- if (this.eatContextual("from")) {
2077
- node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
2078
- } else {
2079
- node.source = null;
2080
- }
2081
- this.semicolon();
2082
- }
2083
- return this.finishNode(node, "ExportNamedDeclaration");
2084
- };
2085
-
2086
- // Parses a comma-separated list of module exports.
2087
-
2088
- pp.parseExportSpecifiers = function () {
2089
- var nodes = [],
2090
- first = true;
2091
- // export { x, y as z } [from '...']
2092
- this.expect(tt.braceL);
2093
- while (!this.eat(tt.braceR)) {
2094
- if (!first) {
2095
- this.expect(tt.comma);
2096
- if (this.afterTrailingComma(tt.braceR)) break;
2097
- } else first = false;
2098
-
2099
- var node = this.startNode();
2100
- node.local = this.parseIdent(this.type === tt._default);
2101
- node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
2102
- nodes.push(this.finishNode(node, "ExportSpecifier"));
2103
- }
2104
- return nodes;
2105
- };
2106
-
2107
- // Parses import declaration.
2108
-
2109
- pp.parseImport = function (node) {
2110
- this.next();
2111
- // import '...'
2112
- if (this.type === tt.string) {
2113
- node.specifiers = empty;
2114
- node.source = this.parseExprAtom();
2115
- node.kind = "";
2116
- } else {
2117
- node.specifiers = this.parseImportSpecifiers();
2118
- this.expectContextual("from");
2119
- node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
2120
- }
2121
- this.semicolon();
2122
- return this.finishNode(node, "ImportDeclaration");
2123
- };
2124
-
2125
- // Parses a comma-separated list of module imports.
2126
-
2127
- pp.parseImportSpecifiers = function () {
2128
- var nodes = [],
2129
- first = true;
2130
- if (this.type === tt.name) {
2131
- // import defaultObj, { x, y as z } from '...'
2132
- var node = this.startNode();
2133
- node.local = this.parseIdent();
2134
- this.checkLVal(node.local, true);
2135
- nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
2136
- if (!this.eat(tt.comma)) return nodes;
2137
- }
2138
- if (this.type === tt.star) {
2139
- var node = this.startNode();
2140
- this.next();
2141
- this.expectContextual("as");
2142
- node.local = this.parseIdent();
2143
- this.checkLVal(node.local, true);
2144
- nodes.push(this.finishNode(node, "ImportNamespaceSpecifier"));
2145
- return nodes;
2146
- }
2147
- this.expect(tt.braceL);
2148
- while (!this.eat(tt.braceR)) {
2149
- if (!first) {
2150
- this.expect(tt.comma);
2151
- if (this.afterTrailingComma(tt.braceR)) break;
2152
- } else first = false;
2153
-
2154
- var node = this.startNode();
2155
- node.imported = this.parseIdent(true);
2156
- node.local = this.eatContextual("as") ? this.parseIdent() : node.imported;
2157
- this.checkLVal(node.local, true);
2158
- nodes.push(this.finishNode(node, "ImportSpecifier"));
2159
- }
2160
- return nodes;
2161
- };
2162
-
2163
- },{"./state":9,"./tokentype":13,"./whitespace":15}],11:[function(_dereq_,module,exports){
2164
- "use strict";
2165
-
2166
- var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
2167
-
2168
- exports.__esModule = true;
2169
- // The algorithm used to determine whether a regexp can appear at a
2170
- // given point in the program is loosely based on sweet.js' approach.
2171
- // See https://github.com/mozilla/sweet.js/wiki/design
2172
-
2173
- var Parser = _dereq_("./state").Parser;
2174
-
2175
- var tt = _dereq_("./tokentype").types;
2176
-
2177
- var lineBreak = _dereq_("./whitespace").lineBreak;
2178
-
2179
- var TokContext = exports.TokContext = function TokContext(token, isExpr, preserveSpace, override) {
2180
- _classCallCheck(this, TokContext);
2181
-
2182
- this.token = token;
2183
- this.isExpr = isExpr;
2184
- this.preserveSpace = preserveSpace;
2185
- this.override = override;
2186
- };
2187
-
2188
- var types = {
2189
- b_stat: new TokContext("{", false),
2190
- b_expr: new TokContext("{", true),
2191
- b_tmpl: new TokContext("${", true),
2192
- p_stat: new TokContext("(", false),
2193
- p_expr: new TokContext("(", true),
2194
- q_tmpl: new TokContext("`", true, true, function (p) {
2195
- return p.readTmplToken();
2196
- }),
2197
- f_expr: new TokContext("function", true)
2198
- };
2199
-
2200
- exports.types = types;
2201
- var pp = Parser.prototype;
2202
-
2203
- pp.initialContext = function () {
2204
- return [types.b_stat];
2205
- };
2206
-
2207
- pp.braceIsBlock = function (prevType) {
2208
- var parent = undefined;
2209
- if (prevType === tt.colon && (parent = this.curContext()).token == "{") return !parent.isExpr;
2210
- if (prevType === tt._return) return lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
2211
- if (prevType === tt._else || prevType === tt.semi || prevType === tt.eof) return true;
2212
- if (prevType == tt.braceL) return this.curContext() === types.b_stat;
2213
- return !this.exprAllowed;
2214
- };
2215
-
2216
- pp.updateContext = function (prevType) {
2217
- var update = undefined,
2218
- type = this.type;
2219
- if (type.keyword && prevType == tt.dot) this.exprAllowed = false;else if (update = type.updateContext) update.call(this, prevType);else this.exprAllowed = type.beforeExpr;
2220
- };
2221
-
2222
- // Token-specific context update code
2223
-
2224
- tt.parenR.updateContext = tt.braceR.updateContext = function () {
2225
- if (this.context.length == 1) {
2226
- this.exprAllowed = true;
2227
- return;
2228
- }
2229
- var out = this.context.pop();
2230
- if (out === types.b_stat && this.curContext() === types.f_expr) {
2231
- this.context.pop();
2232
- this.exprAllowed = false;
2233
- } else if (out === types.b_tmpl) {
2234
- this.exprAllowed = true;
2235
- } else {
2236
- this.exprAllowed = !out.isExpr;
2237
- }
2238
- };
2239
-
2240
- tt.braceL.updateContext = function (prevType) {
2241
- this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
2242
- this.exprAllowed = true;
2243
- };
2244
-
2245
- tt.dollarBraceL.updateContext = function () {
2246
- this.context.push(types.b_tmpl);
2247
- this.exprAllowed = true;
2248
- };
2249
-
2250
- tt.parenL.updateContext = function (prevType) {
2251
- var statementParens = prevType === tt._if || prevType === tt._for || prevType === tt._with || prevType === tt._while;
2252
- this.context.push(statementParens ? types.p_stat : types.p_expr);
2253
- this.exprAllowed = true;
2254
- };
2255
-
2256
- tt.incDec.updateContext = function () {};
2257
-
2258
- tt._function.updateContext = function () {
2259
- if (this.curContext() !== types.b_stat) this.context.push(types.f_expr);
2260
- this.exprAllowed = false;
2261
- };
2262
-
2263
- tt.backQuote.updateContext = function () {
2264
- if (this.curContext() === types.q_tmpl) this.context.pop();else this.context.push(types.q_tmpl);
2265
- this.exprAllowed = false;
2266
- };
2267
-
2268
- // tokExprAllowed stays unchanged
2269
-
2270
- },{"./state":9,"./tokentype":13,"./whitespace":15}],12:[function(_dereq_,module,exports){
2271
- "use strict";
2272
-
2273
- var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
2274
-
2275
- exports.__esModule = true;
2276
-
2277
- var _identifier = _dereq_("./identifier");
2278
-
2279
- var isIdentifierStart = _identifier.isIdentifierStart;
2280
- var isIdentifierChar = _identifier.isIdentifierChar;
2281
-
2282
- var _tokentype = _dereq_("./tokentype");
2283
-
2284
- var tt = _tokentype.types;
2285
- var keywordTypes = _tokentype.keywords;
2286
-
2287
- var Parser = _dereq_("./state").Parser;
2288
-
2289
- var SourceLocation = _dereq_("./location").SourceLocation;
2290
-
2291
- var _whitespace = _dereq_("./whitespace");
2292
-
2293
- var lineBreak = _whitespace.lineBreak;
2294
- var lineBreakG = _whitespace.lineBreakG;
2295
- var isNewLine = _whitespace.isNewLine;
2296
- var nonASCIIwhitespace = _whitespace.nonASCIIwhitespace;
2297
-
2298
- // Object type used to represent tokens. Note that normally, tokens
2299
- // simply exist as properties on the parser object. This is only
2300
- // used for the onToken callback and the external tokenizer.
2301
-
2302
- var Token = exports.Token = function Token(p) {
2303
- _classCallCheck(this, Token);
2304
-
2305
- this.type = p.type;
2306
- this.value = p.value;
2307
- this.start = p.start;
2308
- this.end = p.end;
2309
- if (p.options.locations) this.loc = new SourceLocation(p, p.startLoc, p.endLoc);
2310
- if (p.options.ranges) this.range = [p.start, p.end];
2311
- };
2312
-
2313
- // ## Tokenizer
2314
-
2315
- var pp = Parser.prototype;
2316
-
2317
- // Move to the next token
2318
-
2319
- pp.next = function () {
2320
- if (this.options.onToken) this.options.onToken(new Token(this));
2321
-
2322
- this.lastTokEnd = this.end;
2323
- this.lastTokStart = this.start;
2324
- this.lastTokEndLoc = this.endLoc;
2325
- this.lastTokStartLoc = this.startLoc;
2326
- this.nextToken();
2327
- };
2328
-
2329
- pp.getToken = function () {
2330
- this.next();
2331
- return new Token(this);
2332
- };
2333
-
2334
- // If we're in an ES6 environment, make parsers iterable
2335
- if (typeof Symbol !== "undefined") pp[Symbol.iterator] = function () {
2336
- var self = this;
2337
- return { next: function next() {
2338
- var token = self.getToken();
2339
- return {
2340
- done: token.type === tt.eof,
2341
- value: token
2342
- };
2343
- } };
2344
- };
2345
-
2346
- // Toggle strict mode. Re-reads the next number or string to please
2347
- // pedantic tests (`"use strict"; 010;` should fail).
2348
-
2349
- pp.setStrict = function (strict) {
2350
- this.strict = strict;
2351
- if (this.type !== tt.num && this.type !== tt.string) return;
2352
- this.pos = this.start;
2353
- if (this.options.locations) {
2354
- while (this.pos < this.lineStart) {
2355
- this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
2356
- --this.curLine;
2357
- }
2358
- }
2359
- this.nextToken();
2360
- };
2361
-
2362
- pp.curContext = function () {
2363
- return this.context[this.context.length - 1];
2364
- };
2365
-
2366
- // Read a single token, updating the parser object's token-related
2367
- // properties.
2368
-
2369
- pp.nextToken = function () {
2370
- var curContext = this.curContext();
2371
- if (!curContext || !curContext.preserveSpace) this.skipSpace();
2372
-
2373
- this.start = this.pos;
2374
- if (this.options.locations) this.startLoc = this.curPosition();
2375
- if (this.pos >= this.input.length) return this.finishToken(tt.eof);
2376
-
2377
- if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos());
2378
- };
2379
-
2380
- pp.readToken = function (code) {
2381
- // Identifier or keyword. '\uXXXX' sequences are allowed in
2382
- // identifiers, so '\' also dispatches to that.
2383
- if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) return this.readWord();
2384
-
2385
- return this.getTokenFromCode(code);
2386
- };
2387
-
2388
- pp.fullCharCodeAtPos = function () {
2389
- var code = this.input.charCodeAt(this.pos);
2390
- if (code <= 55295 || code >= 57344) return code;
2391
- var next = this.input.charCodeAt(this.pos + 1);
2392
- return (code << 10) + next - 56613888;
2393
- };
2394
-
2395
- pp.skipBlockComment = function () {
2396
- var startLoc = this.options.onComment && this.options.locations && this.curPosition();
2397
- var start = this.pos,
2398
- end = this.input.indexOf("*/", this.pos += 2);
2399
- if (end === -1) this.raise(this.pos - 2, "Unterminated comment");
2400
- this.pos = end + 2;
2401
- if (this.options.locations) {
2402
- lineBreakG.lastIndex = start;
2403
- var match = undefined;
2404
- while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
2405
- ++this.curLine;
2406
- this.lineStart = match.index + match[0].length;
2407
- }
2408
- }
2409
- if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.options.locations && this.curPosition());
2410
- };
2411
-
2412
- pp.skipLineComment = function (startSkip) {
2413
- var start = this.pos;
2414
- var startLoc = this.options.onComment && this.options.locations && this.curPosition();
2415
- var ch = this.input.charCodeAt(this.pos += startSkip);
2416
- while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
2417
- ++this.pos;
2418
- ch = this.input.charCodeAt(this.pos);
2419
- }
2420
- if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.options.locations && this.curPosition());
2421
- };
2422
-
2423
- // Called at the start of the parse and after every token. Skips
2424
- // whitespace and comments, and.
2425
-
2426
- pp.skipSpace = function () {
2427
- while (this.pos < this.input.length) {
2428
- var ch = this.input.charCodeAt(this.pos);
2429
- if (ch === 32) {
2430
- // ' '
2431
- ++this.pos;
2432
- } else if (ch === 13) {
2433
- ++this.pos;
2434
- var next = this.input.charCodeAt(this.pos);
2435
- if (next === 10) {
2436
- ++this.pos;
2437
- }
2438
- if (this.options.locations) {
2439
- ++this.curLine;
2440
- this.lineStart = this.pos;
2441
- }
2442
- } else if (ch === 10 || ch === 8232 || ch === 8233) {
2443
- ++this.pos;
2444
- if (this.options.locations) {
2445
- ++this.curLine;
2446
- this.lineStart = this.pos;
2447
- }
2448
- } else if (ch > 8 && ch < 14) {
2449
- ++this.pos;
2450
- } else if (ch === 47) {
2451
- // '/'
2452
- var next = this.input.charCodeAt(this.pos + 1);
2453
- if (next === 42) {
2454
- // '*'
2455
- this.skipBlockComment();
2456
- } else if (next === 47) {
2457
- // '/'
2458
- this.skipLineComment(2);
2459
- } else break;
2460
- } else if (ch === 160) {
2461
- // '\xa0'
2462
- ++this.pos;
2463
- } else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
2464
- ++this.pos;
2465
- } else {
2466
- break;
2467
- }
2468
- }
2469
- };
2470
-
2471
- // Called at the end of every token. Sets `end`, `val`, and
2472
- // maintains `context` and `exprAllowed`, and skips the space after
2473
- // the token, so that the next one's `start` will point at the
2474
- // right position.
2475
-
2476
- pp.finishToken = function (type, val) {
2477
- this.end = this.pos;
2478
- if (this.options.locations) this.endLoc = this.curPosition();
2479
- var prevType = this.type;
2480
- this.type = type;
2481
- this.value = val;
2482
-
2483
- this.updateContext(prevType);
2484
- };
2485
-
2486
- // ### Token reading
2487
-
2488
- // This is the function that is called to fetch the next token. It
2489
- // is somewhat obscure, because it works in character codes rather
2490
- // than characters, and because operator parsing has been inlined
2491
- // into it.
2492
- //
2493
- // All in the name of speed.
2494
- //
2495
- pp.readToken_dot = function () {
2496
- var next = this.input.charCodeAt(this.pos + 1);
2497
- if (next >= 48 && next <= 57) return this.readNumber(true);
2498
- var next2 = this.input.charCodeAt(this.pos + 2);
2499
- if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
2500
- // 46 = dot '.'
2501
- this.pos += 3;
2502
- return this.finishToken(tt.ellipsis);
2503
- } else {
2504
- ++this.pos;
2505
- return this.finishToken(tt.dot);
2506
- }
2507
- };
2508
-
2509
- pp.readToken_slash = function () {
2510
- // '/'
2511
- var next = this.input.charCodeAt(this.pos + 1);
2512
- if (this.exprAllowed) {
2513
- ++this.pos;return this.readRegexp();
2514
- }
2515
- if (next === 61) return this.finishOp(tt.assign, 2);
2516
- return this.finishOp(tt.slash, 1);
2517
- };
2518
-
2519
- pp.readToken_mult_modulo = function (code) {
2520
- // '%*'
2521
- var next = this.input.charCodeAt(this.pos + 1);
2522
- if (next === 61) return this.finishOp(tt.assign, 2);
2523
- return this.finishOp(code === 42 ? tt.star : tt.modulo, 1);
2524
- };
2525
-
2526
- pp.readToken_pipe_amp = function (code) {
2527
- // '|&'
2528
- var next = this.input.charCodeAt(this.pos + 1);
2529
- if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2);
2530
- if (next === 61) return this.finishOp(tt.assign, 2);
2531
- return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1);
2532
- };
2533
-
2534
- pp.readToken_caret = function () {
2535
- // '^'
2536
- var next = this.input.charCodeAt(this.pos + 1);
2537
- if (next === 61) return this.finishOp(tt.assign, 2);
2538
- return this.finishOp(tt.bitwiseXOR, 1);
2539
- };
2540
-
2541
- pp.readToken_plus_min = function (code) {
2542
- // '+-'
2543
- var next = this.input.charCodeAt(this.pos + 1);
2544
- if (next === code) {
2545
- if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 && lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) {
2546
- // A `-->` line comment
2547
- this.skipLineComment(3);
2548
- this.skipSpace();
2549
- return this.nextToken();
2550
- }
2551
- return this.finishOp(tt.incDec, 2);
2552
- }
2553
- if (next === 61) return this.finishOp(tt.assign, 2);
2554
- return this.finishOp(tt.plusMin, 1);
2555
- };
2556
-
2557
- pp.readToken_lt_gt = function (code) {
2558
- // '<>'
2559
- var next = this.input.charCodeAt(this.pos + 1);
2560
- var size = 1;
2561
- if (next === code) {
2562
- size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
2563
- if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(tt.assign, size + 1);
2564
- return this.finishOp(tt.bitShift, size);
2565
- }
2566
- if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 && this.input.charCodeAt(this.pos + 3) == 45) {
2567
- if (this.inModule) unexpected();
2568
- // `<!--`, an XML-style comment that should be interpreted as a line comment
2569
- this.skipLineComment(4);
2570
- this.skipSpace();
2571
- return this.nextToken();
2572
- }
2573
- if (next === 61) size = this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2;
2574
- return this.finishOp(tt.relational, size);
2575
- };
2576
-
2577
- pp.readToken_eq_excl = function (code) {
2578
- // '=!'
2579
- var next = this.input.charCodeAt(this.pos + 1);
2580
- if (next === 61) return this.finishOp(tt.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2);
2581
- if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
2582
- // '=>'
2583
- this.pos += 2;
2584
- return this.finishToken(tt.arrow);
2585
- }
2586
- return this.finishOp(code === 61 ? tt.eq : tt.prefix, 1);
2587
- };
2588
-
2589
- pp.getTokenFromCode = function (code) {
2590
- switch (code) {
2591
- // The interpretation of a dot depends on whether it is followed
2592
- // by a digit or another two dots.
2593
- case 46:
2594
- // '.'
2595
- return this.readToken_dot();
2596
-
2597
- // Punctuation tokens.
2598
- case 40:
2599
- ++this.pos;return this.finishToken(tt.parenL);
2600
- case 41:
2601
- ++this.pos;return this.finishToken(tt.parenR);
2602
- case 59:
2603
- ++this.pos;return this.finishToken(tt.semi);
2604
- case 44:
2605
- ++this.pos;return this.finishToken(tt.comma);
2606
- case 91:
2607
- ++this.pos;return this.finishToken(tt.bracketL);
2608
- case 93:
2609
- ++this.pos;return this.finishToken(tt.bracketR);
2610
- case 123:
2611
- ++this.pos;return this.finishToken(tt.braceL);
2612
- case 125:
2613
- ++this.pos;return this.finishToken(tt.braceR);
2614
- case 58:
2615
- ++this.pos;return this.finishToken(tt.colon);
2616
- case 63:
2617
- ++this.pos;return this.finishToken(tt.question);
2618
-
2619
- case 96:
2620
- // '`'
2621
- if (this.options.ecmaVersion < 6) break;
2622
- ++this.pos;
2623
- return this.finishToken(tt.backQuote);
2624
-
2625
- case 48:
2626
- // '0'
2627
- var next = this.input.charCodeAt(this.pos + 1);
2628
- if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
2629
- if (this.options.ecmaVersion >= 6) {
2630
- if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
2631
- if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
2632
- }
2633
- // Anything else beginning with a digit is an integer, octal
2634
- // number, or float.
2635
- case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:
2636
- // 1-9
2637
- return this.readNumber(false);
2638
-
2639
- // Quotes produce strings.
2640
- case 34:case 39:
2641
- // '"', "'"
2642
- return this.readString(code);
2643
-
2644
- // Operators are parsed inline in tiny state machines. '=' (61) is
2645
- // often referred to. `finishOp` simply skips the amount of
2646
- // characters it is given as second argument, and returns a token
2647
- // of the type given by its first argument.
2648
-
2649
- case 47:
2650
- // '/'
2651
- return this.readToken_slash();
2652
-
2653
- case 37:case 42:
2654
- // '%*'
2655
- return this.readToken_mult_modulo(code);
2656
-
2657
- case 124:case 38:
2658
- // '|&'
2659
- return this.readToken_pipe_amp(code);
2660
-
2661
- case 94:
2662
- // '^'
2663
- return this.readToken_caret();
2664
-
2665
- case 43:case 45:
2666
- // '+-'
2667
- return this.readToken_plus_min(code);
2668
-
2669
- case 60:case 62:
2670
- // '<>'
2671
- return this.readToken_lt_gt(code);
2672
-
2673
- case 61:case 33:
2674
- // '=!'
2675
- return this.readToken_eq_excl(code);
2676
-
2677
- case 126:
2678
- // '~'
2679
- return this.finishOp(tt.prefix, 1);
2680
- }
2681
-
2682
- this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
2683
- };
2684
-
2685
- pp.finishOp = function (type, size) {
2686
- var str = this.input.slice(this.pos, this.pos + size);
2687
- this.pos += size;
2688
- return this.finishToken(type, str);
2689
- };
2690
-
2691
- var regexpUnicodeSupport = false;
2692
- try {
2693
- new RegExp("￿", "u");regexpUnicodeSupport = true;
2694
- } catch (e) {}
2695
-
2696
- // Parse a regular expression. Some context-awareness is necessary,
2697
- // since a '/' inside a '[]' set does not end the expression.
2698
-
2699
- pp.readRegexp = function () {
2700
- var escaped = undefined,
2701
- inClass = undefined,
2702
- start = this.pos;
2703
- for (;;) {
2704
- if (this.pos >= this.input.length) this.raise(start, "Unterminated regular expression");
2705
- var ch = this.input.charAt(this.pos);
2706
- if (lineBreak.test(ch)) this.raise(start, "Unterminated regular expression");
2707
- if (!escaped) {
2708
- if (ch === "[") inClass = true;else if (ch === "]" && inClass) inClass = false;else if (ch === "/" && !inClass) break;
2709
- escaped = ch === "\\";
2710
- } else escaped = false;
2711
- ++this.pos;
2712
- }
2713
- var content = this.input.slice(start, this.pos);
2714
- ++this.pos;
2715
- // Need to use `readWord1` because '\uXXXX' sequences are allowed
2716
- // here (don't ask).
2717
- var mods = this.readWord1();
2718
- var tmp = content;
2719
- if (mods) {
2720
- var validFlags = /^[gmsiy]*$/;
2721
- if (this.options.ecmaVersion >= 6) validFlags = /^[gmsiyu]*$/;
2722
- if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag");
2723
- if (mods.indexOf("u") >= 0 && !regexpUnicodeSupport) {
2724
- // Replace each astral symbol and every Unicode escape sequence that
2725
- // possibly represents an astral symbol or a paired surrogate with a
2726
- // single ASCII symbol to avoid throwing on regular expressions that
2727
- // are only valid in combination with the `/u` flag.
2728
- // Note: replacing with the ASCII symbol `x` might cause false
2729
- // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
2730
- // perfectly valid pattern that is equivalent to `[a-b]`, but it would
2731
- // be replaced by `[x-b]` which throws an error.
2732
- tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|\\u\{([0-9a-fA-F]+)\}|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
2733
- }
2734
- }
2735
- // Detect invalid regular expressions.
2736
- try {
2737
- new RegExp(tmp);
2738
- } catch (e) {
2739
- if (e instanceof SyntaxError) this.raise(start, "Error parsing regular expression: " + e.message);
2740
- this.raise(e);
2741
- }
2742
- // Get a regular expression object for this pattern-flag pair, or `null` in
2743
- // case the current environment doesn't support the flags it uses.
2744
- var value = undefined;
2745
- try {
2746
- value = new RegExp(content, mods);
2747
- } catch (err) {
2748
- value = null;
2749
- }
2750
- return this.finishToken(tt.regexp, { pattern: content, flags: mods, value: value });
2751
- };
2752
-
2753
- // Read an integer in the given radix. Return null if zero digits
2754
- // were read, the integer value otherwise. When `len` is given, this
2755
- // will return `null` unless the integer has exactly `len` digits.
2756
-
2757
- pp.readInt = function (radix, len) {
2758
- var start = this.pos,
2759
- total = 0;
2760
- for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
2761
- var code = this.input.charCodeAt(this.pos),
2762
- val = undefined;
2763
- if (code >= 97) val = code - 97 + 10; // a
2764
- else if (code >= 65) val = code - 65 + 10; // A
2765
- else if (code >= 48 && code <= 57) val = code - 48; // 0-9
2766
- else val = Infinity;
2767
- if (val >= radix) break;
2768
- ++this.pos;
2769
- total = total * radix + val;
2770
- }
2771
- if (this.pos === start || len != null && this.pos - start !== len) return null;
2772
-
2773
- return total;
2774
- };
2775
-
2776
- pp.readRadixNumber = function (radix) {
2777
- this.pos += 2; // 0x
2778
- var val = this.readInt(radix);
2779
- if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix);
2780
- if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
2781
- return this.finishToken(tt.num, val);
2782
- };
2783
-
2784
- // Read an integer, octal integer, or floating-point number.
2785
-
2786
- pp.readNumber = function (startsWithDot) {
2787
- var start = this.pos,
2788
- isFloat = false,
2789
- octal = this.input.charCodeAt(this.pos) === 48;
2790
- if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
2791
- if (this.input.charCodeAt(this.pos) === 46) {
2792
- ++this.pos;
2793
- this.readInt(10);
2794
- isFloat = true;
2795
- }
2796
- var next = this.input.charCodeAt(this.pos);
2797
- if (next === 69 || next === 101) {
2798
- // 'eE'
2799
- next = this.input.charCodeAt(++this.pos);
2800
- if (next === 43 || next === 45) ++this.pos; // '+-'
2801
- if (this.readInt(10) === null) this.raise(start, "Invalid number");
2802
- isFloat = true;
2803
- }
2804
- if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number");
2805
-
2806
- var str = this.input.slice(start, this.pos),
2807
- val = undefined;
2808
- if (isFloat) val = parseFloat(str);else if (!octal || str.length === 1) val = parseInt(str, 10);else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number");else val = parseInt(str, 8);
2809
- return this.finishToken(tt.num, val);
2810
- };
2811
-
2812
- // Read a string value, interpreting backslash-escapes.
2813
-
2814
- pp.readCodePoint = function () {
2815
- var ch = this.input.charCodeAt(this.pos),
2816
- code = undefined;
2817
-
2818
- if (ch === 123) {
2819
- if (this.options.ecmaVersion < 6) this.unexpected();
2820
- ++this.pos;
2821
- code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
2822
- ++this.pos;
2823
- if (code > 1114111) this.unexpected();
2824
- } else {
2825
- code = this.readHexChar(4);
2826
- }
2827
- return code;
2828
- };
2829
-
2830
- function codePointToString(code) {
2831
- // UTF-16 Decoding
2832
- if (code <= 65535) {
2833
- return String.fromCharCode(code);
2834
- }return String.fromCharCode((code - 65536 >> 10) + 55296, (code - 65536 & 1023) + 56320);
2835
- }
2836
-
2837
- pp.readString = function (quote) {
2838
- var out = "",
2839
- chunkStart = ++this.pos;
2840
- for (;;) {
2841
- if (this.pos >= this.input.length) this.raise(this.start, "Unterminated string constant");
2842
- var ch = this.input.charCodeAt(this.pos);
2843
- if (ch === quote) break;
2844
- if (ch === 92) {
2845
- // '\'
2846
- out += this.input.slice(chunkStart, this.pos);
2847
- out += this.readEscapedChar();
2848
- chunkStart = this.pos;
2849
- } else {
2850
- if (isNewLine(ch)) this.raise(this.start, "Unterminated string constant");
2851
- ++this.pos;
2852
- }
2853
- }
2854
- out += this.input.slice(chunkStart, this.pos++);
2855
- return this.finishToken(tt.string, out);
2856
- };
2857
-
2858
- // Reads template string tokens.
2859
-
2860
- pp.readTmplToken = function () {
2861
- var out = "",
2862
- chunkStart = this.pos;
2863
- for (;;) {
2864
- if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template");
2865
- var ch = this.input.charCodeAt(this.pos);
2866
- if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
2867
- // '`', '${'
2868
- if (this.pos === this.start && this.type === tt.template) {
2869
- if (ch === 36) {
2870
- this.pos += 2;
2871
- return this.finishToken(tt.dollarBraceL);
2872
- } else {
2873
- ++this.pos;
2874
- return this.finishToken(tt.backQuote);
2875
- }
2876
- }
2877
- out += this.input.slice(chunkStart, this.pos);
2878
- return this.finishToken(tt.template, out);
2879
- }
2880
- if (ch === 92) {
2881
- // '\'
2882
- out += this.input.slice(chunkStart, this.pos);
2883
- out += this.readEscapedChar();
2884
- chunkStart = this.pos;
2885
- } else if (isNewLine(ch)) {
2886
- out += this.input.slice(chunkStart, this.pos);
2887
- ++this.pos;
2888
- if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
2889
- ++this.pos;
2890
- out += "\n";
2891
- } else {
2892
- out += String.fromCharCode(ch);
2893
- }
2894
- if (this.options.locations) {
2895
- ++this.curLine;
2896
- this.lineStart = this.pos;
2897
- }
2898
- chunkStart = this.pos;
2899
- } else {
2900
- ++this.pos;
2901
- }
2902
- }
2903
- };
2904
-
2905
- // Used to read escaped characters
2906
-
2907
- pp.readEscapedChar = function () {
2908
- var ch = this.input.charCodeAt(++this.pos);
2909
- var octal = /^[0-7]+/.exec(this.input.slice(this.pos, this.pos + 3));
2910
- if (octal) octal = octal[0];
2911
- while (octal && parseInt(octal, 8) > 255) octal = octal.slice(0, -1);
2912
- if (octal === "0") octal = null;
2913
- ++this.pos;
2914
- if (octal) {
2915
- if (this.strict) this.raise(this.pos - 2, "Octal literal in strict mode");
2916
- this.pos += octal.length - 1;
2917
- return String.fromCharCode(parseInt(octal, 8));
2918
- } else {
2919
- switch (ch) {
2920
- case 110:
2921
- return "\n"; // 'n' -> '\n'
2922
- case 114:
2923
- return "\r"; // 'r' -> '\r'
2924
- case 120:
2925
- return String.fromCharCode(this.readHexChar(2)); // 'x'
2926
- case 117:
2927
- return codePointToString(this.readCodePoint()); // 'u'
2928
- case 116:
2929
- return "\t"; // 't' -> '\t'
2930
- case 98:
2931
- return "\b"; // 'b' -> '\b'
2932
- case 118:
2933
- return "\u000b"; // 'v' -> '\u000b'
2934
- case 102:
2935
- return "\f"; // 'f' -> '\f'
2936
- case 48:
2937
- return "\u0000"; // 0 -> '\0'
2938
- case 13:
2939
- if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
2940
- case 10:
2941
- // ' \n'
2942
- if (this.options.locations) {
2943
- this.lineStart = this.pos;++this.curLine;
2944
- }
2945
- return "";
2946
- default:
2947
- return String.fromCharCode(ch);
2948
- }
2949
- }
2950
- };
2951
-
2952
- // Used to read character escape sequences ('\x', '\u', '\U').
2953
-
2954
- pp.readHexChar = function (len) {
2955
- var n = this.readInt(16, len);
2956
- if (n === null) this.raise(this.start, "Bad character escape sequence");
2957
- return n;
2958
- };
2959
-
2960
- // Used to signal to callers of `readWord1` whether the word
2961
- // contained any escape sequences. This is needed because words with
2962
- // escape sequences must not be interpreted as keywords.
2963
-
2964
- var containsEsc;
2965
-
2966
- // Read an identifier, and return it as a string. Sets `containsEsc`
2967
- // to whether the word contained a '\u' escape.
2968
- //
2969
- // Incrementally adds only escaped chars, adding other chunks as-is
2970
- // as a micro-optimization.
2971
-
2972
- pp.readWord1 = function () {
2973
- containsEsc = false;
2974
- var word = "",
2975
- first = true,
2976
- chunkStart = this.pos;
2977
- var astral = this.options.ecmaVersion >= 6;
2978
- while (this.pos < this.input.length) {
2979
- var ch = this.fullCharCodeAtPos();
2980
- if (isIdentifierChar(ch, astral)) {
2981
- this.pos += ch <= 65535 ? 1 : 2;
2982
- } else if (ch === 92) {
2983
- // "\"
2984
- containsEsc = true;
2985
- word += this.input.slice(chunkStart, this.pos);
2986
- var escStart = this.pos;
2987
- if (this.input.charCodeAt(++this.pos) != 117) // "u"
2988
- this.raise(this.pos, "Expecting Unicode escape sequence \\uXXXX");
2989
- ++this.pos;
2990
- var esc = this.readCodePoint();
2991
- if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral)) this.raise(escStart, "Invalid Unicode escape");
2992
- word += codePointToString(esc);
2993
- chunkStart = this.pos;
2994
- } else {
2995
- break;
2996
- }
2997
- first = false;
2998
- }
2999
- return word + this.input.slice(chunkStart, this.pos);
3000
- };
3001
-
3002
- // Read an identifier or keyword token. Will check for reserved
3003
- // words when necessary.
3004
-
3005
- pp.readWord = function () {
3006
- var word = this.readWord1();
3007
- var type = tt.name;
3008
- if ((this.options.ecmaVersion >= 6 || !containsEsc) && this.isKeyword(word)) type = keywordTypes[word];
3009
- return this.finishToken(type, word);
3010
- };
3011
-
3012
- },{"./identifier":3,"./location":4,"./state":9,"./tokentype":13,"./whitespace":15}],13:[function(_dereq_,module,exports){
3013
- "use strict";
3014
-
3015
- var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
3016
-
3017
- exports.__esModule = true;
3018
- // ## Token types
3019
-
3020
- // The assignment of fine-grained, information-carrying type objects
3021
- // allows the tokenizer to store the information it has about a
3022
- // token in a way that is very cheap for the parser to look up.
3023
-
3024
- // All token type variables start with an underscore, to make them
3025
- // easy to recognize.
3026
-
3027
- // The `beforeExpr` property is used to disambiguate between regular
3028
- // expressions and divisions. It is set on all token types that can
3029
- // be followed by an expression (thus, a slash after them would be a
3030
- // regular expression).
3031
- //
3032
- // `isLoop` marks a keyword as starting a loop, which is important
3033
- // to know when parsing a label, in order to allow or disallow
3034
- // continue jumps to that label.
3035
-
3036
- var TokenType = exports.TokenType = function TokenType(label) {
3037
- var conf = arguments[1] === undefined ? {} : arguments[1];
3038
-
3039
- _classCallCheck(this, TokenType);
3040
-
3041
- this.label = label;
3042
- this.keyword = conf.keyword;
3043
- this.beforeExpr = !!conf.beforeExpr;
3044
- this.startsExpr = !!conf.startsExpr;
3045
- this.isLoop = !!conf.isLoop;
3046
- this.isAssign = !!conf.isAssign;
3047
- this.prefix = !!conf.prefix;
3048
- this.postfix = !!conf.postfix;
3049
- this.binop = conf.binop || null;
3050
- this.updateContext = null;
3051
- };
3052
-
3053
- function binop(name, prec) {
3054
- return new TokenType(name, { beforeExpr: true, binop: prec });
3055
- }
3056
- var beforeExpr = { beforeExpr: true },
3057
- startsExpr = { startsExpr: true };
3058
-
3059
- var types = {
3060
- num: new TokenType("num", startsExpr),
3061
- regexp: new TokenType("regexp", startsExpr),
3062
- string: new TokenType("string", startsExpr),
3063
- name: new TokenType("name", startsExpr),
3064
- eof: new TokenType("eof"),
3065
-
3066
- // Punctuation token types.
3067
- bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }),
3068
- bracketR: new TokenType("]"),
3069
- braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }),
3070
- braceR: new TokenType("}"),
3071
- parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }),
3072
- parenR: new TokenType(")"),
3073
- comma: new TokenType(",", beforeExpr),
3074
- semi: new TokenType(";", beforeExpr),
3075
- colon: new TokenType(":", beforeExpr),
3076
- dot: new TokenType("."),
3077
- question: new TokenType("?", beforeExpr),
3078
- arrow: new TokenType("=>", beforeExpr),
3079
- template: new TokenType("template"),
3080
- ellipsis: new TokenType("...", beforeExpr),
3081
- backQuote: new TokenType("`", startsExpr),
3082
- dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }),
3083
-
3084
- // Operators. These carry several kinds of properties to help the
3085
- // parser use them properly (the presence of these properties is
3086
- // what categorizes them as operators).
3087
- //
3088
- // `binop`, when present, specifies that this operator is a binary
3089
- // operator, and will refer to its precedence.
3090
- //
3091
- // `prefix` and `postfix` mark the operator as a prefix or postfix
3092
- // unary operator.
3093
- //
3094
- // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
3095
- // binary operators with a very low precedence, that should result
3096
- // in AssignmentExpression nodes.
3097
-
3098
- eq: new TokenType("=", { beforeExpr: true, isAssign: true }),
3099
- assign: new TokenType("_=", { beforeExpr: true, isAssign: true }),
3100
- incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }),
3101
- prefix: new TokenType("prefix", { beforeExpr: true, prefix: true, startsExpr: true }),
3102
- logicalOR: binop("||", 1),
3103
- logicalAND: binop("&&", 2),
3104
- bitwiseOR: binop("|", 3),
3105
- bitwiseXOR: binop("^", 4),
3106
- bitwiseAND: binop("&", 5),
3107
- equality: binop("==/!=", 6),
3108
- relational: binop("</>", 7),
3109
- bitShift: binop("<</>>", 8),
3110
- plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }),
3111
- modulo: binop("%", 10),
3112
- star: binop("*", 10),
3113
- slash: binop("/", 10)
3114
- };
3115
-
3116
- exports.types = types;
3117
- // Map keyword names to token types.
3118
-
3119
- var keywords = {};
3120
-
3121
- exports.keywords = keywords;
3122
- // Succinct definitions of keyword token types
3123
- function kw(name) {
3124
- var options = arguments[1] === undefined ? {} : arguments[1];
3125
-
3126
- options.keyword = name;
3127
- keywords[name] = types["_" + name] = new TokenType(name, options);
3128
- }
3129
-
3130
- kw("break");
3131
- kw("case", beforeExpr);
3132
- kw("catch");
3133
- kw("continue");
3134
- kw("debugger");
3135
- kw("default");
3136
- kw("do", { isLoop: true });
3137
- kw("else", beforeExpr);
3138
- kw("finally");
3139
- kw("for", { isLoop: true });
3140
- kw("function");
3141
- kw("if");
3142
- kw("return", beforeExpr);
3143
- kw("switch");
3144
- kw("throw", beforeExpr);
3145
- kw("try");
3146
- kw("var");
3147
- kw("let");
3148
- kw("const");
3149
- kw("while", { isLoop: true });
3150
- kw("with");
3151
- kw("new", { beforeExpr: true, startsExpr: true });
3152
- kw("this", startsExpr);
3153
- kw("super", startsExpr);
3154
- kw("class");
3155
- kw("extends", beforeExpr);
3156
- kw("export");
3157
- kw("import");
3158
- kw("yield", { beforeExpr: true, startsExpr: true });
3159
- kw("null", startsExpr);
3160
- kw("true", startsExpr);
3161
- kw("false", startsExpr);
3162
- kw("in", { beforeExpr: true, binop: 7 });
3163
- kw("instanceof", { beforeExpr: true, binop: 7 });
3164
- kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true });
3165
- kw("void", { beforeExpr: true, prefix: true, startsExpr: true });
3166
- kw("delete", { beforeExpr: true, prefix: true, startsExpr: true });
3167
-
3168
- },{}],14:[function(_dereq_,module,exports){
3169
- "use strict";
3170
-
3171
- exports.isArray = isArray;
3172
-
3173
- // Checks if an object has a property.
3174
-
3175
- exports.has = has;
3176
- exports.__esModule = true;
3177
-
3178
- function isArray(obj) {
3179
- return Object.prototype.toString.call(obj) === "[object Array]";
3180
- }
3181
-
3182
- function has(obj, propName) {
3183
- return Object.prototype.hasOwnProperty.call(obj, propName);
3184
- }
3185
-
3186
- },{}],15:[function(_dereq_,module,exports){
3187
- "use strict";
3188
-
3189
- exports.isNewLine = isNewLine;
3190
- exports.__esModule = true;
3191
- // Matches a whole line break (where CRLF is considered a single
3192
- // line break). Used to count lines.
3193
-
3194
- var lineBreak = /\r\n?|\n|\u2028|\u2029/;
3195
- exports.lineBreak = lineBreak;
3196
- var lineBreakG = new RegExp(lineBreak.source, "g");
3197
-
3198
- exports.lineBreakG = lineBreakG;
3199
-
3200
- function isNewLine(code) {
3201
- return code === 10 || code === 13 || code === 8232 || code == 8233;
3202
- }
3203
-
3204
- var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
3205
- exports.nonASCIIwhitespace = nonASCIIwhitespace;
3206
-
3207
- },{}]},{},[1])(1)
3208
- });