acorn_loose.js 44 KB

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