spoint 0.1.0 → 0.1.10

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