acorn_loose.js 46 KB

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