@thanhthbm/scene-editor 0.1.0

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 (136) hide show
  1. package/README.md +169 -0
  2. package/dist/index.css +921 -0
  3. package/dist/index.js +14076 -0
  4. package/package.json +49 -0
  5. package/src/editor/css/main.css +1030 -0
  6. package/src/editor/js/Animation.js +618 -0
  7. package/src/editor/js/AnimationResizer.js +73 -0
  8. package/src/editor/js/Command.js +40 -0
  9. package/src/editor/js/Config.js +86 -0
  10. package/src/editor/js/Editor.js +1006 -0
  11. package/src/editor/js/EditorControls.js +489 -0
  12. package/src/editor/js/GLTFImportDialog.js +112 -0
  13. package/src/editor/js/History.js +321 -0
  14. package/src/editor/js/Loader.js +1162 -0
  15. package/src/editor/js/LoaderUtils.js +90 -0
  16. package/src/editor/js/Menubar.Add.js +559 -0
  17. package/src/editor/js/Menubar.Edit.js +155 -0
  18. package/src/editor/js/Menubar.File.js +585 -0
  19. package/src/editor/js/Menubar.Help.js +73 -0
  20. package/src/editor/js/Menubar.Render.js +858 -0
  21. package/src/editor/js/Menubar.Status.js +51 -0
  22. package/src/editor/js/Menubar.View.js +193 -0
  23. package/src/editor/js/Menubar.js +29 -0
  24. package/src/editor/js/Player.js +53 -0
  25. package/src/editor/js/Resizer.js +65 -0
  26. package/src/editor/js/Script.js +532 -0
  27. package/src/editor/js/Selector.js +129 -0
  28. package/src/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
  29. package/src/editor/js/Sidebar.Geometry.BufferGeometry.js +124 -0
  30. package/src/editor/js/Sidebar.Geometry.CapsuleGeometry.js +109 -0
  31. package/src/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
  32. package/src/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
  33. package/src/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
  34. package/src/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
  35. package/src/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
  36. package/src/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
  37. package/src/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
  38. package/src/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
  39. package/src/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
  40. package/src/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
  41. package/src/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
  42. package/src/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
  43. package/src/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
  44. package/src/editor/js/Sidebar.Geometry.TextGeometry.js +136 -0
  45. package/src/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
  46. package/src/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
  47. package/src/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
  48. package/src/editor/js/Sidebar.Geometry.js +471 -0
  49. package/src/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
  50. package/src/editor/js/Sidebar.Material.ColorProperty.js +87 -0
  51. package/src/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
  52. package/src/editor/js/Sidebar.Material.MapProperty.js +277 -0
  53. package/src/editor/js/Sidebar.Material.NumberProperty.js +60 -0
  54. package/src/editor/js/Sidebar.Material.Program.js +73 -0
  55. package/src/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
  56. package/src/editor/js/Sidebar.Material.js +751 -0
  57. package/src/editor/js/Sidebar.Object.js +892 -0
  58. package/src/editor/js/Sidebar.Project.App.js +218 -0
  59. package/src/editor/js/Sidebar.Project.Materials.js +82 -0
  60. package/src/editor/js/Sidebar.Project.Renderer.js +193 -0
  61. package/src/editor/js/Sidebar.Project.Resources.js +242 -0
  62. package/src/editor/js/Sidebar.Project.js +21 -0
  63. package/src/editor/js/Sidebar.Properties.js +73 -0
  64. package/src/editor/js/Sidebar.Scene.js +643 -0
  65. package/src/editor/js/Sidebar.Script.js +129 -0
  66. package/src/editor/js/Sidebar.Settings.History.js +146 -0
  67. package/src/editor/js/Sidebar.Settings.Shortcuts.js +198 -0
  68. package/src/editor/js/Sidebar.Settings.js +58 -0
  69. package/src/editor/js/Sidebar.js +41 -0
  70. package/src/editor/js/Storage.js +98 -0
  71. package/src/editor/js/Strings.js +2718 -0
  72. package/src/editor/js/TextureParametersDialog.js +293 -0
  73. package/src/editor/js/Toolbar.js +75 -0
  74. package/src/editor/js/Viewport.Controls.js +98 -0
  75. package/src/editor/js/Viewport.Info.js +144 -0
  76. package/src/editor/js/Viewport.Pathtracer.js +27 -0
  77. package/src/editor/js/Viewport.ViewHelper.js +41 -0
  78. package/src/editor/js/Viewport.XR.js +7 -0
  79. package/src/editor/js/Viewport.js +982 -0
  80. package/src/editor/js/commands/AddObjectCommand.js +68 -0
  81. package/src/editor/js/commands/AddScriptCommand.js +75 -0
  82. package/src/editor/js/commands/Commands.js +24 -0
  83. package/src/editor/js/commands/MoveObjectCommand.js +117 -0
  84. package/src/editor/js/commands/MultiCmdsCommand.js +85 -0
  85. package/src/editor/js/commands/RemoveObjectCommand.js +88 -0
  86. package/src/editor/js/commands/RemoveScriptCommand.js +81 -0
  87. package/src/editor/js/commands/SetColorCommand.js +73 -0
  88. package/src/editor/js/commands/SetGeometryCommand.js +86 -0
  89. package/src/editor/js/commands/SetGeometryValueCommand.js +70 -0
  90. package/src/editor/js/commands/SetMaterialColorCommand.js +87 -0
  91. package/src/editor/js/commands/SetMaterialCommand.js +80 -0
  92. package/src/editor/js/commands/SetMaterialMapCommand.js +144 -0
  93. package/src/editor/js/commands/SetMaterialRangeCommand.js +92 -0
  94. package/src/editor/js/commands/SetMaterialValueCommand.js +91 -0
  95. package/src/editor/js/commands/SetMaterialVectorCommand.js +88 -0
  96. package/src/editor/js/commands/SetPositionCommand.js +84 -0
  97. package/src/editor/js/commands/SetRotationCommand.js +84 -0
  98. package/src/editor/js/commands/SetScaleCommand.js +84 -0
  99. package/src/editor/js/commands/SetSceneCommand.js +104 -0
  100. package/src/editor/js/commands/SetScriptValueCommand.js +80 -0
  101. package/src/editor/js/commands/SetShadowValueCommand.js +73 -0
  102. package/src/editor/js/commands/SetTextureParametersCommand.js +143 -0
  103. package/src/editor/js/commands/SetUuidCommand.js +70 -0
  104. package/src/editor/js/commands/SetValueCommand.js +75 -0
  105. package/src/editor/js/libs/acorn/acorn.js +3236 -0
  106. package/src/editor/js/libs/acorn/acorn_loose.js +1299 -0
  107. package/src/editor/js/libs/acorn/walk.js +344 -0
  108. package/src/editor/js/libs/app/index.html +51 -0
  109. package/src/editor/js/libs/app.js +14 -0
  110. package/src/editor/js/libs/codemirror/addon/dialog.css +32 -0
  111. package/src/editor/js/libs/codemirror/addon/dialog.js +163 -0
  112. package/src/editor/js/libs/codemirror/addon/show-hint.css +36 -0
  113. package/src/editor/js/libs/codemirror/addon/show-hint.js +529 -0
  114. package/src/editor/js/libs/codemirror/addon/tern.css +87 -0
  115. package/src/editor/js/libs/codemirror/addon/tern.js +750 -0
  116. package/src/editor/js/libs/codemirror/codemirror.css +344 -0
  117. package/src/editor/js/libs/codemirror/codemirror.js +9849 -0
  118. package/src/editor/js/libs/codemirror/mode/glsl.js +233 -0
  119. package/src/editor/js/libs/codemirror/mode/javascript.js +959 -0
  120. package/src/editor/js/libs/codemirror/theme/monokai.css +41 -0
  121. package/src/editor/js/libs/esprima.js +6401 -0
  122. package/src/editor/js/libs/jsonlint.js +453 -0
  123. package/src/editor/js/libs/signals.min.js +14 -0
  124. package/src/editor/js/libs/tern-threejs/build-defs.js +233 -0
  125. package/src/editor/js/libs/ternjs/comment.js +87 -0
  126. package/src/editor/js/libs/ternjs/def.js +588 -0
  127. package/src/editor/js/libs/ternjs/doc_comment.js +401 -0
  128. package/src/editor/js/libs/ternjs/infer.js +1635 -0
  129. package/src/editor/js/libs/ternjs/polyfill.js +80 -0
  130. package/src/editor/js/libs/ternjs/signal.js +26 -0
  131. package/src/editor/js/libs/ternjs/tern.js +993 -0
  132. package/src/editor/js/libs/ui.js +1305 -0
  133. package/src/editor/js/libs/ui.three.js +946 -0
  134. package/src/events.js +273 -0
  135. package/src/index.js +284 -0
  136. package/src/presets/machines.js +239 -0
@@ -0,0 +1,1299 @@
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 || (g.acorn = {})).loose = 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
+ "use strict";
3
+
4
+ var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };
5
+
6
+ exports.parse_dammit = parse_dammit;
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ // Acorn: Loose parser
11
+ //
12
+ // This module provides an alternative parser (`parse_dammit`) that
13
+ // exposes that same interface as `parse`, but will try to parse
14
+ // anything as JavaScript, repairing syntax error the best it can.
15
+ // There are circumstances in which it will raise an error and give
16
+ // up, but they are very rare. The resulting AST will be a mostly
17
+ // valid JavaScript AST (as per the [Mozilla parser API][api], except
18
+ // that:
19
+ //
20
+ // - Return outside functions is allowed
21
+ //
22
+ // - Label consistency (no conflicts, break only to existing labels)
23
+ // is not enforced.
24
+ //
25
+ // - Bogus Identifier nodes with a name of `"✖"` are inserted whenever
26
+ // the parser got too confused to return anything meaningful.
27
+ //
28
+ // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
29
+ //
30
+ // The expected use for this is to *first* try `acorn.parse`, and only
31
+ // if that fails switch to `parse_dammit`. The loose parser might
32
+ // parse badly indented code incorrectly, so **don't** use it as
33
+ // your default parser.
34
+ //
35
+ // Quite a lot of acorn.js is duplicated here. The alternative was to
36
+ // add a *lot* of extra cruft to that file, making it less readable
37
+ // and slower. Copying and editing the code allowed me to make
38
+ // invasive changes and simplifications without creating a complicated
39
+ // tangle.
40
+
41
+ var acorn = _interopRequireWildcard(require(".."));
42
+
43
+ var _state = require("./state");
44
+
45
+ var LooseParser = _state.LooseParser;
46
+
47
+ require("./tokenize");
48
+
49
+ require("./parseutil");
50
+
51
+ require("./statement");
52
+
53
+ require("./expression");
54
+
55
+ exports.LooseParser = _state.LooseParser;
56
+
57
+ acorn.defaultOptions.tabSize = 4;
58
+
59
+ function parse_dammit(input, options) {
60
+ var p = new LooseParser(input, options);
61
+ p.next();
62
+ return p.parseTopLevel();
63
+ }
64
+
65
+ acorn.parse_dammit = parse_dammit;
66
+ acorn.LooseParser = LooseParser;
67
+
68
+ },{"..":2,"./expression":3,"./parseutil":4,"./state":5,"./statement":6,"./tokenize":7}],2:[function(require,module,exports){
69
+ "use strict";
70
+
71
+ module.exports = typeof window != "undefined" ? window.acorn : require(("suppress", "./acorn"));
72
+
73
+ },{}],3:[function(require,module,exports){
74
+ "use strict";
75
+
76
+ var LooseParser = require("./state").LooseParser;
77
+
78
+ var isDummy = require("./parseutil").isDummy;
79
+
80
+ var tt = require("..").tokTypes;
81
+
82
+ var lp = LooseParser.prototype;
83
+
84
+ lp.checkLVal = function (expr) {
85
+ if (!expr) return expr;
86
+ switch (expr.type) {
87
+ case "Identifier":
88
+ case "MemberExpression":
89
+ case "ObjectPattern":
90
+ case "ArrayPattern":
91
+ case "RestElement":
92
+ case "AssignmentPattern":
93
+ return expr;
94
+
95
+ default:
96
+ return this.dummyIdent();
97
+ }
98
+ };
99
+
100
+ lp.parseExpression = function (noIn) {
101
+ var start = this.storeCurrentPos();
102
+ var expr = this.parseMaybeAssign(noIn);
103
+ if (this.tok.type === tt.comma) {
104
+ var node = this.startNodeAt(start);
105
+ node.expressions = [expr];
106
+ while (this.eat(tt.comma)) node.expressions.push(this.parseMaybeAssign(noIn));
107
+ return this.finishNode(node, "SequenceExpression");
108
+ }
109
+ return expr;
110
+ };
111
+
112
+ lp.parseParenExpression = function () {
113
+ this.pushCx();
114
+ this.expect(tt.parenL);
115
+ var val = this.parseExpression();
116
+ this.popCx();
117
+ this.expect(tt.parenR);
118
+ return val;
119
+ };
120
+
121
+ lp.parseMaybeAssign = function (noIn) {
122
+ var start = this.storeCurrentPos();
123
+ var left = this.parseMaybeConditional(noIn);
124
+ if (this.tok.type.isAssign) {
125
+ var node = this.startNodeAt(start);
126
+ node.operator = this.tok.value;
127
+ node.left = this.tok.type === tt.eq ? this.toAssignable(left) : this.checkLVal(left);
128
+ this.next();
129
+ node.right = this.parseMaybeAssign(noIn);
130
+ return this.finishNode(node, "AssignmentExpression");
131
+ }
132
+ return left;
133
+ };
134
+
135
+ lp.parseMaybeConditional = function (noIn) {
136
+ var start = this.storeCurrentPos();
137
+ var expr = this.parseExprOps(noIn);
138
+ if (this.eat(tt.question)) {
139
+ var node = this.startNodeAt(start);
140
+ node.test = expr;
141
+ node.consequent = this.parseMaybeAssign();
142
+ node.alternate = this.expect(tt.colon) ? this.parseMaybeAssign(noIn) : this.dummyIdent();
143
+ return this.finishNode(node, "ConditionalExpression");
144
+ }
145
+ return expr;
146
+ };
147
+
148
+ lp.parseExprOps = function (noIn) {
149
+ var start = this.storeCurrentPos();
150
+ var indent = this.curIndent,
151
+ line = this.curLineStart;
152
+ return this.parseExprOp(this.parseMaybeUnary(noIn), start, -1, noIn, indent, line);
153
+ };
154
+
155
+ lp.parseExprOp = function (left, start, minPrec, noIn, indent, line) {
156
+ if (this.curLineStart != line && this.curIndent < indent && this.tokenStartsLine()) return left;
157
+ var prec = this.tok.type.binop;
158
+ if (prec != null && (!noIn || this.tok.type !== tt._in)) {
159
+ if (prec > minPrec) {
160
+ var node = this.startNodeAt(start);
161
+ node.left = left;
162
+ node.operator = this.tok.value;
163
+ this.next();
164
+ if (this.curLineStart != line && this.curIndent < indent && this.tokenStartsLine()) {
165
+ node.right = this.dummyIdent();
166
+ } else {
167
+ var rightStart = this.storeCurrentPos();
168
+ node.right = this.parseExprOp(this.parseMaybeUnary(noIn), rightStart, prec, noIn, indent, line);
169
+ }
170
+ this.finishNode(node, /&&|\|\|/.test(node.operator) ? "LogicalExpression" : "BinaryExpression");
171
+ return this.parseExprOp(node, start, minPrec, noIn, indent, line);
172
+ }
173
+ }
174
+ return left;
175
+ };
176
+
177
+ lp.parseMaybeUnary = function (noIn) {
178
+ if (this.tok.type.prefix) {
179
+ var node = this.startNode(),
180
+ update = this.tok.type === tt.incDec;
181
+ node.operator = this.tok.value;
182
+ node.prefix = true;
183
+ this.next();
184
+ node.argument = this.parseMaybeUnary(noIn);
185
+ if (update) node.argument = this.checkLVal(node.argument);
186
+ return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
187
+ } else if (this.tok.type === tt.ellipsis) {
188
+ var node = this.startNode();
189
+ this.next();
190
+ node.argument = this.parseMaybeUnary(noIn);
191
+ return this.finishNode(node, "SpreadElement");
192
+ }
193
+ var start = this.storeCurrentPos();
194
+ var expr = this.parseExprSubscripts();
195
+ while (this.tok.type.postfix && !this.canInsertSemicolon()) {
196
+ var node = this.startNodeAt(start);
197
+ node.operator = this.tok.value;
198
+ node.prefix = false;
199
+ node.argument = this.checkLVal(expr);
200
+ this.next();
201
+ expr = this.finishNode(node, "UpdateExpression");
202
+ }
203
+ return expr;
204
+ };
205
+
206
+ lp.parseExprSubscripts = function () {
207
+ var start = this.storeCurrentPos();
208
+ return this.parseSubscripts(this.parseExprAtom(), start, false, this.curIndent, this.curLineStart);
209
+ };
210
+
211
+ lp.parseSubscripts = function (base, start, noCalls, startIndent, line) {
212
+ for (;;) {
213
+ if (this.curLineStart != line && this.curIndent <= startIndent && this.tokenStartsLine()) {
214
+ if (this.tok.type == tt.dot && this.curIndent == startIndent) --startIndent;else return base;
215
+ }
216
+
217
+ if (this.eat(tt.dot)) {
218
+ var node = this.startNodeAt(start);
219
+ node.object = base;
220
+ if (this.curLineStart != line && this.curIndent <= startIndent && this.tokenStartsLine()) node.property = this.dummyIdent();else node.property = this.parsePropertyAccessor() || this.dummyIdent();
221
+ node.computed = false;
222
+ base = this.finishNode(node, "MemberExpression");
223
+ } else if (this.tok.type == tt.bracketL) {
224
+ this.pushCx();
225
+ this.next();
226
+ var node = this.startNodeAt(start);
227
+ node.object = base;
228
+ node.property = this.parseExpression();
229
+ node.computed = true;
230
+ this.popCx();
231
+ this.expect(tt.bracketR);
232
+ base = this.finishNode(node, "MemberExpression");
233
+ } else if (!noCalls && this.tok.type == tt.parenL) {
234
+ this.pushCx();
235
+ var node = this.startNodeAt(start);
236
+ node.callee = base;
237
+ node.arguments = this.parseExprList(tt.parenR);
238
+ base = this.finishNode(node, "CallExpression");
239
+ } else if (this.tok.type == tt.backQuote) {
240
+ var node = this.startNodeAt(start);
241
+ node.tag = base;
242
+ node.quasi = this.parseTemplate();
243
+ base = this.finishNode(node, "TaggedTemplateExpression");
244
+ } else {
245
+ return base;
246
+ }
247
+ }
248
+ };
249
+
250
+ lp.parseExprAtom = function () {
251
+ var node = undefined;
252
+ switch (this.tok.type) {
253
+ case tt._this:
254
+ case tt._super:
255
+ var type = this.tok.type === tt._this ? "ThisExpression" : "Super";
256
+ node = this.startNode();
257
+ this.next();
258
+ return this.finishNode(node, type);
259
+
260
+ case tt.name:
261
+ var start = this.storeCurrentPos();
262
+ var id = this.parseIdent();
263
+ return this.eat(tt.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id]) : id;
264
+
265
+ case tt.regexp:
266
+ node = this.startNode();
267
+ var val = this.tok.value;
268
+ node.regex = { pattern: val.pattern, flags: val.flags };
269
+ node.value = val.value;
270
+ node.raw = this.input.slice(this.tok.start, this.tok.end);
271
+ this.next();
272
+ return this.finishNode(node, "Literal");
273
+
274
+ case tt.num:case tt.string:
275
+ node = this.startNode();
276
+ node.value = this.tok.value;
277
+ node.raw = this.input.slice(this.tok.start, this.tok.end);
278
+ this.next();
279
+ return this.finishNode(node, "Literal");
280
+
281
+ case tt._null:case tt._true:case tt._false:
282
+ node = this.startNode();
283
+ node.value = this.tok.type === tt._null ? null : this.tok.type === tt._true;
284
+ node.raw = this.tok.type.keyword;
285
+ this.next();
286
+ return this.finishNode(node, "Literal");
287
+
288
+ case tt.parenL:
289
+ var parenStart = this.storeCurrentPos();
290
+ this.next();
291
+ var inner = this.parseExpression();
292
+ this.expect(tt.parenR);
293
+ if (this.eat(tt.arrow)) {
294
+ return this.parseArrowExpression(this.startNodeAt(parenStart), inner.expressions || (isDummy(inner) ? [] : [inner]));
295
+ }
296
+ if (this.options.preserveParens) {
297
+ var par = this.startNodeAt(parenStart);
298
+ par.expression = inner;
299
+ inner = this.finishNode(par, "ParenthesizedExpression");
300
+ }
301
+ return inner;
302
+
303
+ case tt.bracketL:
304
+ node = this.startNode();
305
+ this.pushCx();
306
+ node.elements = this.parseExprList(tt.bracketR, true);
307
+ return this.finishNode(node, "ArrayExpression");
308
+
309
+ case tt.braceL:
310
+ return this.parseObj();
311
+
312
+ case tt._class:
313
+ return this.parseClass();
314
+
315
+ case tt._function:
316
+ node = this.startNode();
317
+ this.next();
318
+ return this.parseFunction(node, false);
319
+
320
+ case tt._new:
321
+ return this.parseNew();
322
+
323
+ case tt._yield:
324
+ node = this.startNode();
325
+ this.next();
326
+ if (this.semicolon() || this.canInsertSemicolon() || this.tok.type != tt.star && !this.tok.type.startsExpr) {
327
+ node.delegate = false;
328
+ node.argument = null;
329
+ } else {
330
+ node.delegate = this.eat(tt.star);
331
+ node.argument = this.parseMaybeAssign();
332
+ }
333
+ return this.finishNode(node, "YieldExpression");
334
+
335
+ case tt.backQuote:
336
+ return this.parseTemplate();
337
+
338
+ default:
339
+ return this.dummyIdent();
340
+ }
341
+ };
342
+
343
+ lp.parseNew = function () {
344
+ var node = this.startNode(),
345
+ startIndent = this.curIndent,
346
+ line = this.curLineStart;
347
+ var meta = this.parseIdent(true);
348
+ if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
349
+ node.meta = meta;
350
+ node.property = this.parseIdent(true);
351
+ return this.finishNode(node, "MetaProperty");
352
+ }
353
+ var start = this.storeCurrentPos();
354
+ node.callee = this.parseSubscripts(this.parseExprAtom(), start, true, startIndent, line);
355
+ if (this.tok.type == tt.parenL) {
356
+ this.pushCx();
357
+ node.arguments = this.parseExprList(tt.parenR);
358
+ } else {
359
+ node.arguments = [];
360
+ }
361
+ return this.finishNode(node, "NewExpression");
362
+ };
363
+
364
+ lp.parseTemplateElement = function () {
365
+ var elem = this.startNode();
366
+ elem.value = {
367
+ raw: this.input.slice(this.tok.start, this.tok.end),
368
+ cooked: this.tok.value
369
+ };
370
+ this.next();
371
+ elem.tail = this.tok.type === tt.backQuote;
372
+ return this.finishNode(elem, "TemplateElement");
373
+ };
374
+
375
+ lp.parseTemplate = function () {
376
+ var node = this.startNode();
377
+ this.next();
378
+ node.expressions = [];
379
+ var curElt = this.parseTemplateElement();
380
+ node.quasis = [curElt];
381
+ while (!curElt.tail) {
382
+ this.next();
383
+ node.expressions.push(this.parseExpression());
384
+ if (this.expect(tt.braceR)) {
385
+ curElt = this.parseTemplateElement();
386
+ } else {
387
+ curElt = this.startNode();
388
+ curElt.value = { cooked: "", raw: "" };
389
+ curElt.tail = true;
390
+ }
391
+ node.quasis.push(curElt);
392
+ }
393
+ this.expect(tt.backQuote);
394
+ return this.finishNode(node, "TemplateLiteral");
395
+ };
396
+
397
+ lp.parseObj = function () {
398
+ var node = this.startNode();
399
+ node.properties = [];
400
+ this.pushCx();
401
+ var indent = this.curIndent + 1,
402
+ line = this.curLineStart;
403
+ this.eat(tt.braceL);
404
+ if (this.curIndent + 1 < indent) {
405
+ indent = this.curIndent;line = this.curLineStart;
406
+ }
407
+ while (!this.closes(tt.braceR, indent, line)) {
408
+ var prop = this.startNode(),
409
+ isGenerator = undefined,
410
+ start = undefined;
411
+ if (this.options.ecmaVersion >= 6) {
412
+ start = this.storeCurrentPos();
413
+ prop.method = false;
414
+ prop.shorthand = false;
415
+ isGenerator = this.eat(tt.star);
416
+ }
417
+ this.parsePropertyName(prop);
418
+ if (isDummy(prop.key)) {
419
+ if (isDummy(this.parseMaybeAssign())) this.next();this.eat(tt.comma);continue;
420
+ }
421
+ if (this.eat(tt.colon)) {
422
+ prop.kind = "init";
423
+ prop.value = this.parseMaybeAssign();
424
+ } else if (this.options.ecmaVersion >= 6 && (this.tok.type === tt.parenL || this.tok.type === tt.braceL)) {
425
+ prop.kind = "init";
426
+ prop.method = true;
427
+ prop.value = this.parseMethod(isGenerator);
428
+ } else if (this.options.ecmaVersion >= 5 && prop.key.type === "Identifier" && !prop.computed && (prop.key.name === "get" || prop.key.name === "set") && (this.tok.type != tt.comma && this.tok.type != tt.braceR)) {
429
+ prop.kind = prop.key.name;
430
+ this.parsePropertyName(prop);
431
+ prop.value = this.parseMethod(false);
432
+ } else {
433
+ prop.kind = "init";
434
+ if (this.options.ecmaVersion >= 6) {
435
+ if (this.eat(tt.eq)) {
436
+ var assign = this.startNodeAt(start);
437
+ assign.operator = "=";
438
+ assign.left = prop.key;
439
+ assign.right = this.parseMaybeAssign();
440
+ prop.value = this.finishNode(assign, "AssignmentExpression");
441
+ } else {
442
+ prop.value = prop.key;
443
+ }
444
+ } else {
445
+ prop.value = this.dummyIdent();
446
+ }
447
+ prop.shorthand = true;
448
+ }
449
+ node.properties.push(this.finishNode(prop, "Property"));
450
+ this.eat(tt.comma);
451
+ }
452
+ this.popCx();
453
+ if (!this.eat(tt.braceR)) {
454
+ // If there is no closing brace, make the node span to the start
455
+ // of the next token (this is useful for Tern)
456
+ this.last.end = this.tok.start;
457
+ if (this.options.locations) this.last.loc.end = this.tok.loc.start;
458
+ }
459
+ return this.finishNode(node, "ObjectExpression");
460
+ };
461
+
462
+ lp.parsePropertyName = function (prop) {
463
+ if (this.options.ecmaVersion >= 6) {
464
+ if (this.eat(tt.bracketL)) {
465
+ prop.computed = true;
466
+ prop.key = this.parseExpression();
467
+ this.expect(tt.bracketR);
468
+ return;
469
+ } else {
470
+ prop.computed = false;
471
+ }
472
+ }
473
+ var key = this.tok.type === tt.num || this.tok.type === tt.string ? this.parseExprAtom() : this.parseIdent();
474
+ prop.key = key || this.dummyIdent();
475
+ };
476
+
477
+ lp.parsePropertyAccessor = function () {
478
+ if (this.tok.type === tt.name || this.tok.type.keyword) return this.parseIdent();
479
+ };
480
+
481
+ lp.parseIdent = function () {
482
+ var name = this.tok.type === tt.name ? this.tok.value : this.tok.type.keyword;
483
+ if (!name) return this.dummyIdent();
484
+ var node = this.startNode();
485
+ this.next();
486
+ node.name = name;
487
+ return this.finishNode(node, "Identifier");
488
+ };
489
+
490
+ lp.initFunction = function (node) {
491
+ node.id = null;
492
+ node.params = [];
493
+ if (this.options.ecmaVersion >= 6) {
494
+ node.generator = false;
495
+ node.expression = false;
496
+ }
497
+ };
498
+
499
+ // Convert existing expression atom to assignable pattern
500
+ // if possible.
501
+
502
+ lp.toAssignable = function (node) {
503
+ if (this.options.ecmaVersion >= 6 && node) {
504
+ switch (node.type) {
505
+ case "ObjectExpression":
506
+ node.type = "ObjectPattern";
507
+ var props = node.properties;
508
+ for (var i = 0; i < props.length; i++) {
509
+ this.toAssignable(props[i].value);
510
+ }break;
511
+
512
+ case "ArrayExpression":
513
+ node.type = "ArrayPattern";
514
+ this.toAssignableList(node.elements);
515
+ break;
516
+
517
+ case "SpreadElement":
518
+ node.type = "RestElement";
519
+ node.argument = this.toAssignable(node.argument);
520
+ break;
521
+
522
+ case "AssignmentExpression":
523
+ node.type = "AssignmentPattern";
524
+ break;
525
+ }
526
+ }
527
+ return this.checkLVal(node);
528
+ };
529
+
530
+ lp.toAssignableList = function (exprList) {
531
+ for (var i = 0; i < exprList.length; i++) {
532
+ this.toAssignable(exprList[i]);
533
+ }return exprList;
534
+ };
535
+
536
+ lp.parseFunctionParams = function (params) {
537
+ this.pushCx();
538
+ params = this.parseExprList(tt.parenR);
539
+ return this.toAssignableList(params);
540
+ };
541
+
542
+ lp.parseMethod = function (isGenerator) {
543
+ var node = this.startNode();
544
+ this.initFunction(node);
545
+ node.params = this.parseFunctionParams();
546
+ node.generator = isGenerator || false;
547
+ node.expression = this.options.ecmaVersion >= 6 && this.tok.type !== tt.braceL;
548
+ node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock();
549
+ return this.finishNode(node, "FunctionExpression");
550
+ };
551
+
552
+ lp.parseArrowExpression = function (node, params) {
553
+ this.initFunction(node);
554
+ node.params = this.toAssignableList(params);
555
+ node.expression = this.tok.type !== tt.braceL;
556
+ node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock();
557
+ return this.finishNode(node, "ArrowFunctionExpression");
558
+ };
559
+
560
+ lp.parseExprList = function (close, allowEmpty) {
561
+ var indent = this.curIndent,
562
+ line = this.curLineStart,
563
+ elts = [];
564
+ this.next(); // Opening bracket
565
+ while (!this.closes(close, indent + 1, line)) {
566
+ if (this.eat(tt.comma)) {
567
+ elts.push(allowEmpty ? null : this.dummyIdent());
568
+ continue;
569
+ }
570
+ var elt = this.parseMaybeAssign();
571
+ if (isDummy(elt)) {
572
+ if (this.closes(close, indent, line)) break;
573
+ this.next();
574
+ } else {
575
+ elts.push(elt);
576
+ }
577
+ this.eat(tt.comma);
578
+ }
579
+ this.popCx();
580
+ if (!this.eat(close)) {
581
+ // If there is no closing brace, make the node span to the start
582
+ // of the next token (this is useful for Tern)
583
+ this.last.end = this.tok.start;
584
+ if (this.options.locations) this.last.loc.end = this.tok.loc.start;
585
+ }
586
+ return elts;
587
+ };
588
+
589
+ },{"..":2,"./parseutil":4,"./state":5}],4:[function(require,module,exports){
590
+ "use strict";
591
+
592
+ exports.isDummy = isDummy;
593
+ Object.defineProperty(exports, "__esModule", {
594
+ value: true
595
+ });
596
+
597
+ var LooseParser = require("./state").LooseParser;
598
+
599
+ var _ = require("..");
600
+
601
+ var Node = _.Node;
602
+ var SourceLocation = _.SourceLocation;
603
+ var lineBreak = _.lineBreak;
604
+ var isNewLine = _.isNewLine;
605
+ var tt = _.tokTypes;
606
+
607
+ var lp = LooseParser.prototype;
608
+
609
+ lp.startNode = function () {
610
+ var node = new Node();
611
+ node.start = this.tok.start;
612
+ if (this.options.locations) node.loc = new SourceLocation(this.toks, this.tok.loc.start);
613
+ if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
614
+ if (this.options.ranges) node.range = [this.tok.start, 0];
615
+ return node;
616
+ };
617
+
618
+ lp.storeCurrentPos = function () {
619
+ return this.options.locations ? [this.tok.start, this.tok.loc.start] : this.tok.start;
620
+ };
621
+
622
+ lp.startNodeAt = function (pos) {
623
+ var node = new Node();
624
+ if (this.options.locations) {
625
+ node.start = pos[0];
626
+ node.loc = new SourceLocation(this.toks, pos[1]);
627
+ pos = pos[0];
628
+ } else {
629
+ node.start = pos;
630
+ }
631
+ if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;
632
+ if (this.options.ranges) node.range = [pos, 0];
633
+ return node;
634
+ };
635
+
636
+ lp.finishNode = function (node, type) {
637
+ node.type = type;
638
+ node.end = this.last.end;
639
+ if (this.options.locations) node.loc.end = this.last.loc.end;
640
+ if (this.options.ranges) node.range[1] = this.last.end;
641
+ return node;
642
+ };
643
+
644
+ lp.dummyIdent = function () {
645
+ var dummy = this.startNode();
646
+ dummy.name = "✖";
647
+ return this.finishNode(dummy, "Identifier");
648
+ };
649
+
650
+ function isDummy(node) {
651
+ return node.name == "✖";
652
+ }
653
+
654
+ lp.eat = function (type) {
655
+ if (this.tok.type === type) {
656
+ this.next();
657
+ return true;
658
+ } else {
659
+ return false;
660
+ }
661
+ };
662
+
663
+ lp.isContextual = function (name) {
664
+ return this.tok.type === tt.name && this.tok.value === name;
665
+ };
666
+
667
+ lp.eatContextual = function (name) {
668
+ return this.tok.value === name && this.eat(tt.name);
669
+ };
670
+
671
+ lp.canInsertSemicolon = function () {
672
+ return this.tok.type === tt.eof || this.tok.type === tt.braceR || lineBreak.test(this.input.slice(this.last.end, this.tok.start));
673
+ };
674
+
675
+ lp.semicolon = function () {
676
+ return this.eat(tt.semi);
677
+ };
678
+
679
+ lp.expect = function (type) {
680
+ if (this.eat(type)) return true;
681
+ for (var i = 1; i <= 2; i++) {
682
+ if (this.lookAhead(i).type == type) {
683
+ for (var j = 0; j < i; j++) {
684
+ this.next();
685
+ }return true;
686
+ }
687
+ }
688
+ };
689
+
690
+ lp.pushCx = function () {
691
+ this.context.push(this.curIndent);
692
+ };
693
+ lp.popCx = function () {
694
+ this.curIndent = this.context.pop();
695
+ };
696
+
697
+ lp.lineEnd = function (pos) {
698
+ while (pos < this.input.length && !isNewLine(this.input.charCodeAt(pos))) ++pos;
699
+ return pos;
700
+ };
701
+
702
+ lp.indentationAfter = function (pos) {
703
+ for (var count = 0;; ++pos) {
704
+ var ch = this.input.charCodeAt(pos);
705
+ if (ch === 32) ++count;else if (ch === 9) count += this.options.tabSize;else return count;
706
+ }
707
+ };
708
+
709
+ lp.closes = function (closeTok, indent, line, blockHeuristic) {
710
+ if (this.tok.type === closeTok || this.tok.type === tt.eof) return true;
711
+ return line != this.curLineStart && this.curIndent < indent && this.tokenStartsLine() && (!blockHeuristic || this.nextLineStart >= this.input.length || this.indentationAfter(this.nextLineStart) < indent);
712
+ };
713
+
714
+ lp.tokenStartsLine = function () {
715
+ for (var p = this.tok.start - 1; p >= this.curLineStart; --p) {
716
+ var ch = this.input.charCodeAt(p);
717
+ if (ch !== 9 && ch !== 32) return false;
718
+ }
719
+ return true;
720
+ };
721
+
722
+ },{"..":2,"./state":5}],5:[function(require,module,exports){
723
+ "use strict";
724
+
725
+ exports.LooseParser = LooseParser;
726
+ Object.defineProperty(exports, "__esModule", {
727
+ value: true
728
+ });
729
+
730
+ var _ = require("..");
731
+
732
+ var tokenizer = _.tokenizer;
733
+ var SourceLocation = _.SourceLocation;
734
+ var tt = _.tokTypes;
735
+
736
+ function LooseParser(input, options) {
737
+ this.toks = tokenizer(input, options);
738
+ this.options = this.toks.options;
739
+ this.input = this.toks.input;
740
+ this.tok = this.last = { type: tt.eof, start: 0, end: 0 };
741
+ if (this.options.locations) {
742
+ var here = this.toks.curPosition();
743
+ this.tok.loc = new SourceLocation(this.toks, here, here);
744
+ }
745
+ this.ahead = []; // Tokens ahead
746
+ this.context = []; // Indentation contexted
747
+ this.curIndent = 0;
748
+ this.curLineStart = 0;
749
+ this.nextLineStart = this.lineEnd(this.curLineStart) + 1;
750
+ }
751
+
752
+ },{"..":2}],6:[function(require,module,exports){
753
+ "use strict";
754
+
755
+ var LooseParser = require("./state").LooseParser;
756
+
757
+ var isDummy = require("./parseutil").isDummy;
758
+
759
+ var _ = require("..");
760
+
761
+ var getLineInfo = _.getLineInfo;
762
+ var tt = _.tokTypes;
763
+
764
+ var lp = LooseParser.prototype;
765
+
766
+ lp.parseTopLevel = function () {
767
+ var node = this.startNodeAt(this.options.locations ? [0, getLineInfo(this.input, 0)] : 0);
768
+ node.body = [];
769
+ while (this.tok.type !== tt.eof) node.body.push(this.parseStatement());
770
+ this.last = this.tok;
771
+ if (this.options.ecmaVersion >= 6) {
772
+ node.sourceType = this.options.sourceType;
773
+ }
774
+ return this.finishNode(node, "Program");
775
+ };
776
+
777
+ lp.parseStatement = function () {
778
+ var starttype = this.tok.type,
779
+ node = this.startNode();
780
+
781
+ switch (starttype) {
782
+ case tt._break:case tt._continue:
783
+ this.next();
784
+ var isBreak = starttype === tt._break;
785
+ if (this.semicolon() || this.canInsertSemicolon()) {
786
+ node.label = null;
787
+ } else {
788
+ node.label = this.tok.type === tt.name ? this.parseIdent() : null;
789
+ this.semicolon();
790
+ }
791
+ return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
792
+
793
+ case tt._debugger:
794
+ this.next();
795
+ this.semicolon();
796
+ return this.finishNode(node, "DebuggerStatement");
797
+
798
+ case tt._do:
799
+ this.next();
800
+ node.body = this.parseStatement();
801
+ node.test = this.eat(tt._while) ? this.parseParenExpression() : this.dummyIdent();
802
+ this.semicolon();
803
+ return this.finishNode(node, "DoWhileStatement");
804
+
805
+ case tt._for:
806
+ this.next();
807
+ this.pushCx();
808
+ this.expect(tt.parenL);
809
+ if (this.tok.type === tt.semi) return this.parseFor(node, null);
810
+ if (this.tok.type === tt._var || this.tok.type === tt._let || this.tok.type === tt._const) {
811
+ var _init = this.parseVar(true);
812
+ if (_init.declarations.length === 1 && (this.tok.type === tt._in || this.isContextual("of"))) {
813
+ return this.parseForIn(node, _init);
814
+ }
815
+ return this.parseFor(node, _init);
816
+ }
817
+ var init = this.parseExpression(true);
818
+ if (this.tok.type === tt._in || this.isContextual("of")) return this.parseForIn(node, this.toAssignable(init));
819
+ return this.parseFor(node, init);
820
+
821
+ case tt._function:
822
+ this.next();
823
+ return this.parseFunction(node, true);
824
+
825
+ case tt._if:
826
+ this.next();
827
+ node.test = this.parseParenExpression();
828
+ node.consequent = this.parseStatement();
829
+ node.alternate = this.eat(tt._else) ? this.parseStatement() : null;
830
+ return this.finishNode(node, "IfStatement");
831
+
832
+ case tt._return:
833
+ this.next();
834
+ if (this.eat(tt.semi) || this.canInsertSemicolon()) node.argument = null;else {
835
+ node.argument = this.parseExpression();this.semicolon();
836
+ }
837
+ return this.finishNode(node, "ReturnStatement");
838
+
839
+ case tt._switch:
840
+ var blockIndent = this.curIndent,
841
+ line = this.curLineStart;
842
+ this.next();
843
+ node.discriminant = this.parseParenExpression();
844
+ node.cases = [];
845
+ this.pushCx();
846
+ this.expect(tt.braceL);
847
+
848
+ var cur = undefined;
849
+ while (!this.closes(tt.braceR, blockIndent, line, true)) {
850
+ if (this.tok.type === tt._case || this.tok.type === tt._default) {
851
+ var isCase = this.tok.type === tt._case;
852
+ if (cur) this.finishNode(cur, "SwitchCase");
853
+ node.cases.push(cur = this.startNode());
854
+ cur.consequent = [];
855
+ this.next();
856
+ if (isCase) cur.test = this.parseExpression();else cur.test = null;
857
+ this.expect(tt.colon);
858
+ } else {
859
+ if (!cur) {
860
+ node.cases.push(cur = this.startNode());
861
+ cur.consequent = [];
862
+ cur.test = null;
863
+ }
864
+ cur.consequent.push(this.parseStatement());
865
+ }
866
+ }
867
+ if (cur) this.finishNode(cur, "SwitchCase");
868
+ this.popCx();
869
+ this.eat(tt.braceR);
870
+ return this.finishNode(node, "SwitchStatement");
871
+
872
+ case tt._throw:
873
+ this.next();
874
+ node.argument = this.parseExpression();
875
+ this.semicolon();
876
+ return this.finishNode(node, "ThrowStatement");
877
+
878
+ case tt._try:
879
+ this.next();
880
+ node.block = this.parseBlock();
881
+ node.handler = null;
882
+ if (this.tok.type === tt._catch) {
883
+ var clause = this.startNode();
884
+ this.next();
885
+ this.expect(tt.parenL);
886
+ clause.param = this.toAssignable(this.parseExprAtom());
887
+ this.expect(tt.parenR);
888
+ clause.guard = null;
889
+ clause.body = this.parseBlock();
890
+ node.handler = this.finishNode(clause, "CatchClause");
891
+ }
892
+ node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
893
+ if (!node.handler && !node.finalizer) return node.block;
894
+ return this.finishNode(node, "TryStatement");
895
+
896
+ case tt._var:
897
+ case tt._let:
898
+ case tt._const:
899
+ return this.parseVar();
900
+
901
+ case tt._while:
902
+ this.next();
903
+ node.test = this.parseParenExpression();
904
+ node.body = this.parseStatement();
905
+ return this.finishNode(node, "WhileStatement");
906
+
907
+ case tt._with:
908
+ this.next();
909
+ node.object = this.parseParenExpression();
910
+ node.body = this.parseStatement();
911
+ return this.finishNode(node, "WithStatement");
912
+
913
+ case tt.braceL:
914
+ return this.parseBlock();
915
+
916
+ case tt.semi:
917
+ this.next();
918
+ return this.finishNode(node, "EmptyStatement");
919
+
920
+ case tt._class:
921
+ return this.parseClass(true);
922
+
923
+ case tt._import:
924
+ return this.parseImport();
925
+
926
+ case tt._export:
927
+ return this.parseExport();
928
+
929
+ default:
930
+ var expr = this.parseExpression();
931
+ if (isDummy(expr)) {
932
+ this.next();
933
+ if (this.tok.type === tt.eof) return this.finishNode(node, "EmptyStatement");
934
+ return this.parseStatement();
935
+ } else if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) {
936
+ node.body = this.parseStatement();
937
+ node.label = expr;
938
+ return this.finishNode(node, "LabeledStatement");
939
+ } else {
940
+ node.expression = expr;
941
+ this.semicolon();
942
+ return this.finishNode(node, "ExpressionStatement");
943
+ }
944
+ }
945
+ };
946
+
947
+ lp.parseBlock = function () {
948
+ var node = this.startNode();
949
+ this.pushCx();
950
+ this.expect(tt.braceL);
951
+ var blockIndent = this.curIndent,
952
+ line = this.curLineStart;
953
+ node.body = [];
954
+ while (!this.closes(tt.braceR, blockIndent, line, true)) node.body.push(this.parseStatement());
955
+ this.popCx();
956
+ this.eat(tt.braceR);
957
+ return this.finishNode(node, "BlockStatement");
958
+ };
959
+
960
+ lp.parseFor = function (node, init) {
961
+ node.init = init;
962
+ node.test = node.update = null;
963
+ if (this.eat(tt.semi) && this.tok.type !== tt.semi) node.test = this.parseExpression();
964
+ if (this.eat(tt.semi) && this.tok.type !== tt.parenR) node.update = this.parseExpression();
965
+ this.popCx();
966
+ this.expect(tt.parenR);
967
+ node.body = this.parseStatement();
968
+ return this.finishNode(node, "ForStatement");
969
+ };
970
+
971
+ lp.parseForIn = function (node, init) {
972
+ var type = this.tok.type === tt._in ? "ForInStatement" : "ForOfStatement";
973
+ this.next();
974
+ node.left = init;
975
+ node.right = this.parseExpression();
976
+ this.popCx();
977
+ this.expect(tt.parenR);
978
+ node.body = this.parseStatement();
979
+ return this.finishNode(node, type);
980
+ };
981
+
982
+ lp.parseVar = function (noIn) {
983
+ var node = this.startNode();
984
+ node.kind = this.tok.type.keyword;
985
+ this.next();
986
+ node.declarations = [];
987
+ do {
988
+ var decl = this.startNode();
989
+ decl.id = this.options.ecmaVersion >= 6 ? this.toAssignable(this.parseExprAtom()) : this.parseIdent();
990
+ decl.init = this.eat(tt.eq) ? this.parseMaybeAssign(noIn) : null;
991
+ node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
992
+ } while (this.eat(tt.comma));
993
+ if (!node.declarations.length) {
994
+ var decl = this.startNode();
995
+ decl.id = this.dummyIdent();
996
+ node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
997
+ }
998
+ if (!noIn) this.semicolon();
999
+ return this.finishNode(node, "VariableDeclaration");
1000
+ };
1001
+
1002
+ lp.parseClass = function (isStatement) {
1003
+ var node = this.startNode();
1004
+ this.next();
1005
+ if (this.tok.type === tt.name) node.id = this.parseIdent();else if (isStatement) node.id = this.dummyIdent();else node.id = null;
1006
+ node.superClass = this.eat(tt._extends) ? this.parseExpression() : null;
1007
+ node.body = this.startNode();
1008
+ node.body.body = [];
1009
+ this.pushCx();
1010
+ var indent = this.curIndent + 1,
1011
+ line = this.curLineStart;
1012
+ this.eat(tt.braceL);
1013
+ if (this.curIndent + 1 < indent) {
1014
+ indent = this.curIndent;line = this.curLineStart;
1015
+ }
1016
+ while (!this.closes(tt.braceR, indent, line)) {
1017
+ if (this.semicolon()) continue;
1018
+ var method = this.startNode(),
1019
+ isGenerator = undefined,
1020
+ start = undefined;
1021
+ if (this.options.ecmaVersion >= 6) {
1022
+ method["static"] = false;
1023
+ isGenerator = this.eat(tt.star);
1024
+ }
1025
+ this.parsePropertyName(method);
1026
+ if (isDummy(method.key)) {
1027
+ if (isDummy(this.parseMaybeAssign())) this.next();this.eat(tt.comma);continue;
1028
+ }
1029
+ if (method.key.type === "Identifier" && !method.computed && method.key.name === "static" && (this.tok.type != tt.parenL && this.tok.type != tt.braceL)) {
1030
+ method["static"] = true;
1031
+ isGenerator = this.eat(tt.star);
1032
+ this.parsePropertyName(method);
1033
+ } else {
1034
+ method["static"] = false;
1035
+ }
1036
+ if (this.options.ecmaVersion >= 5 && method.key.type === "Identifier" && !method.computed && (method.key.name === "get" || method.key.name === "set") && this.tok.type !== tt.parenL && this.tok.type !== tt.braceL) {
1037
+ method.kind = method.key.name;
1038
+ this.parsePropertyName(method);
1039
+ method.value = this.parseMethod(false);
1040
+ } else {
1041
+ if (!method.computed && !method["static"] && !isGenerator && (method.key.type === "Identifier" && method.key.name === "constructor" || method.key.type === "Literal" && method.key.value === "constructor")) {
1042
+ method.kind = "constructor";
1043
+ } else {
1044
+ method.kind = "method";
1045
+ }
1046
+ method.value = this.parseMethod(isGenerator);
1047
+ }
1048
+ node.body.body.push(this.finishNode(method, "MethodDefinition"));
1049
+ }
1050
+ this.popCx();
1051
+ if (!this.eat(tt.braceR)) {
1052
+ // If there is no closing brace, make the node span to the start
1053
+ // of the next token (this is useful for Tern)
1054
+ this.last.end = this.tok.start;
1055
+ if (this.options.locations) this.last.loc.end = this.tok.loc.start;
1056
+ }
1057
+ this.semicolon();
1058
+ this.finishNode(node.body, "ClassBody");
1059
+ return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
1060
+ };
1061
+
1062
+ lp.parseFunction = function (node, isStatement) {
1063
+ this.initFunction(node);
1064
+ if (this.options.ecmaVersion >= 6) {
1065
+ node.generator = this.eat(tt.star);
1066
+ }
1067
+ if (this.tok.type === tt.name) node.id = this.parseIdent();else if (isStatement) node.id = this.dummyIdent();
1068
+ node.params = this.parseFunctionParams();
1069
+ node.body = this.parseBlock();
1070
+ return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
1071
+ };
1072
+
1073
+ lp.parseExport = function () {
1074
+ var node = this.startNode();
1075
+ this.next();
1076
+ if (this.eat(tt.star)) {
1077
+ node.source = this.eatContextual("from") ? this.parseExprAtom() : null;
1078
+ return this.finishNode(node, "ExportAllDeclaration");
1079
+ }
1080
+ if (this.eat(tt._default)) {
1081
+ var expr = this.parseMaybeAssign();
1082
+ if (expr.id) {
1083
+ switch (expr.type) {
1084
+ case "FunctionExpression":
1085
+ expr.type = "FunctionDeclaration";break;
1086
+ case "ClassExpression":
1087
+ expr.type = "ClassDeclaration";break;
1088
+ }
1089
+ }
1090
+ node.declaration = expr;
1091
+ this.semicolon();
1092
+ return this.finishNode(node, "ExportDefaultDeclaration");
1093
+ }
1094
+ if (this.tok.type.keyword) {
1095
+ node.declaration = this.parseStatement();
1096
+ node.specifiers = [];
1097
+ node.source = null;
1098
+ } else {
1099
+ node.declaration = null;
1100
+ node.specifiers = this.parseExportSpecifierList();
1101
+ node.source = this.eatContextual("from") ? this.parseExprAtom() : null;
1102
+ this.semicolon();
1103
+ }
1104
+ return this.finishNode(node, "ExportNamedDeclaration");
1105
+ };
1106
+
1107
+ lp.parseImport = function () {
1108
+ var node = this.startNode();
1109
+ this.next();
1110
+ if (this.tok.type === tt.string) {
1111
+ node.specifiers = [];
1112
+ node.source = this.parseExprAtom();
1113
+ node.kind = "";
1114
+ } else {
1115
+ var elt = undefined;
1116
+ if (this.tok.type === tt.name && this.tok.value !== "from") {
1117
+ elt = this.startNode();
1118
+ elt.local = this.parseIdent();
1119
+ this.finishNode(elt, "ImportDefaultSpecifier");
1120
+ this.eat(tt.comma);
1121
+ }
1122
+ node.specifiers = this.parseImportSpecifierList();
1123
+ node.source = this.eatContextual("from") ? this.parseExprAtom() : null;
1124
+ if (elt) node.specifiers.unshift(elt);
1125
+ }
1126
+ this.semicolon();
1127
+ return this.finishNode(node, "ImportDeclaration");
1128
+ };
1129
+
1130
+ lp.parseImportSpecifierList = function () {
1131
+ var elts = [];
1132
+ if (this.tok.type === tt.star) {
1133
+ var elt = this.startNode();
1134
+ this.next();
1135
+ if (this.eatContextual("as")) elt.local = this.parseIdent();
1136
+ elts.push(this.finishNode(elt, "ImportNamespaceSpecifier"));
1137
+ } else {
1138
+ var indent = this.curIndent,
1139
+ line = this.curLineStart,
1140
+ continuedLine = this.nextLineStart;
1141
+ this.pushCx();
1142
+ this.eat(tt.braceL);
1143
+ if (this.curLineStart > continuedLine) continuedLine = this.curLineStart;
1144
+ while (!this.closes(tt.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) {
1145
+ var elt = this.startNode();
1146
+ if (this.eat(tt.star)) {
1147
+ if (this.eatContextual("as")) elt.local = this.parseIdent();
1148
+ this.finishNode(elt, "ImportNamespaceSpecifier");
1149
+ } else {
1150
+ if (this.isContextual("from")) break;
1151
+ elt.imported = this.parseIdent();
1152
+ elt.local = this.eatContextual("as") ? this.parseIdent() : elt.imported;
1153
+ this.finishNode(elt, "ImportSpecifier");
1154
+ }
1155
+ elts.push(elt);
1156
+ this.eat(tt.comma);
1157
+ }
1158
+ this.eat(tt.braceR);
1159
+ this.popCx();
1160
+ }
1161
+ return elts;
1162
+ };
1163
+
1164
+ lp.parseExportSpecifierList = function () {
1165
+ var elts = [];
1166
+ var indent = this.curIndent,
1167
+ line = this.curLineStart,
1168
+ continuedLine = this.nextLineStart;
1169
+ this.pushCx();
1170
+ this.eat(tt.braceL);
1171
+ if (this.curLineStart > continuedLine) continuedLine = this.curLineStart;
1172
+ while (!this.closes(tt.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) {
1173
+ if (this.isContextual("from")) break;
1174
+ var elt = this.startNode();
1175
+ elt.local = this.parseIdent();
1176
+ elt.exported = this.eatContextual("as") ? this.parseIdent() : elt.local;
1177
+ this.finishNode(elt, "ExportSpecifier");
1178
+ elts.push(elt);
1179
+ this.eat(tt.comma);
1180
+ }
1181
+ this.eat(tt.braceR);
1182
+ this.popCx();
1183
+ return elts;
1184
+ };
1185
+
1186
+ },{"..":2,"./parseutil":4,"./state":5}],7:[function(require,module,exports){
1187
+ "use strict";
1188
+
1189
+ var _ = require("..");
1190
+
1191
+ var tt = _.tokTypes;
1192
+ var Token = _.Token;
1193
+ var isNewLine = _.isNewLine;
1194
+ var SourceLocation = _.SourceLocation;
1195
+ var getLineInfo = _.getLineInfo;
1196
+ var lineBreakG = _.lineBreakG;
1197
+
1198
+ var LooseParser = require("./state").LooseParser;
1199
+
1200
+ var lp = LooseParser.prototype;
1201
+
1202
+ function isSpace(ch) {
1203
+ return ch < 14 && ch > 8 || ch === 32 || ch === 160 || isNewLine(ch);
1204
+ }
1205
+
1206
+ lp.next = function () {
1207
+ this.last = this.tok;
1208
+ if (this.ahead.length) this.tok = this.ahead.shift();else this.tok = this.readToken();
1209
+
1210
+ if (this.tok.start >= this.nextLineStart) {
1211
+ while (this.tok.start >= this.nextLineStart) {
1212
+ this.curLineStart = this.nextLineStart;
1213
+ this.nextLineStart = this.lineEnd(this.curLineStart) + 1;
1214
+ }
1215
+ this.curIndent = this.indentationAfter(this.curLineStart);
1216
+ }
1217
+ };
1218
+
1219
+ lp.readToken = function () {
1220
+ for (;;) {
1221
+ try {
1222
+ this.toks.next();
1223
+ if (this.toks.type === tt.dot && this.input.substr(this.toks.end, 1) === "." && this.options.ecmaVersion >= 6) {
1224
+ this.toks.end++;
1225
+ this.toks.type = tt.ellipsis;
1226
+ }
1227
+ return new Token(this.toks);
1228
+ } catch (e) {
1229
+ if (!(e instanceof SyntaxError)) throw e;
1230
+
1231
+ // Try to skip some text, based on the error message, and then continue
1232
+ var msg = e.message,
1233
+ pos = e.raisedAt,
1234
+ replace = true;
1235
+ if (/unterminated/i.test(msg)) {
1236
+ pos = this.lineEnd(e.pos + 1);
1237
+ if (/string/.test(msg)) {
1238
+ replace = { start: e.pos, end: pos, type: tt.string, value: this.input.slice(e.pos + 1, pos) };
1239
+ } else if (/regular expr/i.test(msg)) {
1240
+ var re = this.input.slice(e.pos, pos);
1241
+ try {
1242
+ re = new RegExp(re);
1243
+ } catch (e) {}
1244
+ replace = { start: e.pos, end: pos, type: tt.regexp, value: re };
1245
+ } else if (/template/.test(msg)) {
1246
+ replace = { start: e.pos, end: pos,
1247
+ type: tt.template,
1248
+ value: this.input.slice(e.pos, pos) };
1249
+ } else {
1250
+ replace = false;
1251
+ }
1252
+ } else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number/i.test(msg)) {
1253
+ while (pos < this.input.length && !isSpace(this.input.charCodeAt(pos))) ++pos;
1254
+ } else if (/character escape|expected hexadecimal/i.test(msg)) {
1255
+ while (pos < this.input.length) {
1256
+ var ch = this.input.charCodeAt(pos++);
1257
+ if (ch === 34 || ch === 39 || isNewLine(ch)) break;
1258
+ }
1259
+ } else if (/unexpected character/i.test(msg)) {
1260
+ pos++;
1261
+ replace = false;
1262
+ } else if (/regular expression/i.test(msg)) {
1263
+ replace = true;
1264
+ } else {
1265
+ throw e;
1266
+ }
1267
+ this.resetTo(pos);
1268
+ if (replace === true) replace = { start: pos, end: pos, type: tt.name, value: "✖" };
1269
+ if (replace) {
1270
+ if (this.options.locations) replace.loc = new SourceLocation(this.toks, getLineInfo(this.input, replace.start), getLineInfo(this.input, replace.end));
1271
+ return replace;
1272
+ }
1273
+ }
1274
+ }
1275
+ };
1276
+
1277
+ lp.resetTo = function (pos) {
1278
+ this.toks.pos = pos;
1279
+ var ch = this.input.charAt(pos - 1);
1280
+ this.toks.exprAllowed = !ch || /[\[\{\(,;:?\/*=+\-~!|&%^<>]/.test(ch) || /[enwfd]/.test(ch) && /\b(keywords|case|else|return|throw|new|in|(instance|type)of|delete|void)$/.test(this.input.slice(pos - 10, pos));
1281
+
1282
+ if (this.options.locations) {
1283
+ this.toks.curLine = 1;
1284
+ this.toks.lineStart = lineBreakG.lastIndex = 0;
1285
+ var match = undefined;
1286
+ while ((match = lineBreakG.exec(this.input)) && match.index < pos) {
1287
+ ++this.toks.curLine;
1288
+ this.toks.lineStart = match.index + match[0].length;
1289
+ }
1290
+ }
1291
+ };
1292
+
1293
+ lp.lookAhead = function (n) {
1294
+ while (n > this.ahead.length) this.ahead.push(this.readToken());
1295
+ return this.ahead[n - 1];
1296
+ };
1297
+
1298
+ },{"..":2,"./state":5}]},{},[1])(1)
1299
+ });