acorn.js 130 KB

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