acorn.js 110 KB

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