acorn.js 119 KB

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