acorn_loose.js 41 KB

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