parse.js 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493
  1. /***********************************************************************
  2. A JavaScript tokenizer / parser / beautifier / compressor.
  3. https://github.com/mishoo/UglifyJS2
  4. -------------------------------- (C) ---------------------------------
  5. Author: Mihai Bazon
  6. <mihai.bazon@gmail.com>
  7. http://mihai.bazon.net/blog
  8. Distributed under the BSD license:
  9. Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
  10. Parser based on parse-js (http://marijn.haverbeke.nl/parse-js/).
  11. Redistribution and use in source and binary forms, with or without
  12. modification, are permitted provided that the following conditions
  13. are met:
  14. * Redistributions of source code must retain the above
  15. copyright notice, this list of conditions and the following
  16. disclaimer.
  17. * Redistributions in binary form must reproduce the above
  18. copyright notice, this list of conditions and the following
  19. disclaimer in the documentation and/or other materials
  20. provided with the distribution.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
  22. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
  25. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  26. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  30. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. SUCH DAMAGE.
  33. ***********************************************************************/
  34. "use strict";
  35. import {
  36. characters,
  37. defaults,
  38. makePredicate,
  39. set_annotation,
  40. } from "./utils/index.js";
  41. import {
  42. AST_Accessor,
  43. AST_Array,
  44. AST_Arrow,
  45. AST_Assign,
  46. AST_Await,
  47. AST_BigInt,
  48. AST_Binary,
  49. AST_BlockStatement,
  50. AST_Break,
  51. AST_Call,
  52. AST_Case,
  53. AST_Catch,
  54. AST_Chain,
  55. AST_ClassExpression,
  56. AST_ClassPrivateProperty,
  57. AST_ClassProperty,
  58. AST_ClassStaticBlock,
  59. AST_ConciseMethod,
  60. AST_PrivateIn,
  61. AST_PrivateGetter,
  62. AST_PrivateMethod,
  63. AST_PrivateSetter,
  64. AST_Conditional,
  65. AST_Const,
  66. AST_Continue,
  67. AST_Debugger,
  68. AST_Default,
  69. AST_DefaultAssign,
  70. AST_DefClass,
  71. AST_Definitions,
  72. AST_Defun,
  73. AST_Destructuring,
  74. AST_Directive,
  75. AST_Do,
  76. AST_Dot,
  77. AST_DotHash,
  78. AST_EmptyStatement,
  79. AST_Expansion,
  80. AST_Export,
  81. AST_False,
  82. AST_Finally,
  83. AST_For,
  84. AST_ForIn,
  85. AST_ForOf,
  86. AST_Function,
  87. AST_Hole,
  88. AST_If,
  89. AST_Import,
  90. AST_ImportMeta,
  91. AST_IterationStatement,
  92. AST_Label,
  93. AST_LabeledStatement,
  94. AST_LabelRef,
  95. AST_Let,
  96. AST_NameMapping,
  97. AST_New,
  98. AST_NewTarget,
  99. AST_Node,
  100. AST_Null,
  101. AST_Number,
  102. AST_Object,
  103. AST_ObjectGetter,
  104. AST_ObjectKeyVal,
  105. AST_ObjectProperty,
  106. AST_ObjectSetter,
  107. AST_PrefixedTemplateString,
  108. AST_PropAccess,
  109. AST_RegExp,
  110. AST_Return,
  111. AST_Sequence,
  112. AST_SimpleStatement,
  113. AST_String,
  114. AST_Sub,
  115. AST_Super,
  116. AST_Switch,
  117. AST_SymbolCatch,
  118. AST_SymbolClass,
  119. AST_SymbolClassProperty,
  120. AST_SymbolConst,
  121. AST_SymbolDeclaration,
  122. AST_SymbolDefClass,
  123. AST_SymbolDefun,
  124. AST_SymbolExport,
  125. AST_SymbolExportForeign,
  126. AST_SymbolFunarg,
  127. AST_SymbolImport,
  128. AST_SymbolImportForeign,
  129. AST_SymbolLambda,
  130. AST_SymbolLet,
  131. AST_SymbolMethod,
  132. AST_SymbolRef,
  133. AST_SymbolVar,
  134. AST_TemplateSegment,
  135. AST_TemplateString,
  136. AST_This,
  137. AST_SymbolPrivateProperty,
  138. AST_Throw,
  139. AST_Token,
  140. AST_Toplevel,
  141. AST_True,
  142. AST_Try,
  143. AST_TryBlock,
  144. AST_UnaryPostfix,
  145. AST_UnaryPrefix,
  146. AST_Var,
  147. AST_VarDef,
  148. AST_While,
  149. AST_With,
  150. AST_Yield,
  151. _INLINE,
  152. _NOINLINE,
  153. _PURE,
  154. _KEY,
  155. _MANGLEPROP,
  156. } from "./ast.js";
  157. var LATEST_RAW = ""; // Only used for numbers and template strings
  158. var TEMPLATE_RAWS = new Map(); // Raw template strings
  159. var KEYWORDS = "break case catch class const continue debugger default delete do else export extends finally for function if in instanceof let new return switch throw try typeof var void while with";
  160. var KEYWORDS_ATOM = "false null true";
  161. var RESERVED_WORDS = "enum import super this " + KEYWORDS_ATOM + " " + KEYWORDS;
  162. var ALL_RESERVED_WORDS = "implements interface package private protected public static " + RESERVED_WORDS;
  163. var KEYWORDS_BEFORE_EXPRESSION = "return new delete throw else case yield await";
  164. KEYWORDS = makePredicate(KEYWORDS);
  165. RESERVED_WORDS = makePredicate(RESERVED_WORDS);
  166. KEYWORDS_BEFORE_EXPRESSION = makePredicate(KEYWORDS_BEFORE_EXPRESSION);
  167. KEYWORDS_ATOM = makePredicate(KEYWORDS_ATOM);
  168. ALL_RESERVED_WORDS = makePredicate(ALL_RESERVED_WORDS);
  169. var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));
  170. var RE_NUM_LITERAL = /[0-9a-f]/i;
  171. var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
  172. var RE_OCT_NUMBER = /^0[0-7]+$/;
  173. var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i;
  174. var RE_BIN_NUMBER = /^0b[01]+$/i;
  175. var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;
  176. var RE_BIG_INT = /^(0[xob])?[0-9a-f]+n$/i;
  177. var OPERATORS = makePredicate([
  178. "in",
  179. "instanceof",
  180. "typeof",
  181. "new",
  182. "void",
  183. "delete",
  184. "++",
  185. "--",
  186. "+",
  187. "-",
  188. "!",
  189. "~",
  190. "&",
  191. "|",
  192. "^",
  193. "*",
  194. "**",
  195. "/",
  196. "%",
  197. ">>",
  198. "<<",
  199. ">>>",
  200. "<",
  201. ">",
  202. "<=",
  203. ">=",
  204. "==",
  205. "===",
  206. "!=",
  207. "!==",
  208. "?",
  209. "=",
  210. "+=",
  211. "-=",
  212. "||=",
  213. "&&=",
  214. "??=",
  215. "/=",
  216. "*=",
  217. "**=",
  218. "%=",
  219. ">>=",
  220. "<<=",
  221. ">>>=",
  222. "|=",
  223. "^=",
  224. "&=",
  225. "&&",
  226. "??",
  227. "||",
  228. ]);
  229. var WHITESPACE_CHARS = makePredicate(characters(" \u00a0\n\r\t\f\u000b\u200b\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\uFEFF"));
  230. var NEWLINE_CHARS = makePredicate(characters("\n\r\u2028\u2029"));
  231. var PUNC_AFTER_EXPRESSION = makePredicate(characters(";]),:"));
  232. var PUNC_BEFORE_EXPRESSION = makePredicate(characters("[{(,;:"));
  233. var PUNC_CHARS = makePredicate(characters("[]{}(),;:"));
  234. /* -----[ Tokenizer ]----- */
  235. // surrogate safe regexps adapted from https://github.com/mathiasbynens/unicode-8.0.0/tree/89b412d8a71ecca9ed593d9e9fa073ab64acfebe/Binary_Property
  236. var UNICODE = {
  237. ID_Start: /[$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,
  238. ID_Continue: /(?:[$0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF])+/,
  239. };
  240. function get_full_char(str, pos) {
  241. if (is_surrogate_pair_head(str.charCodeAt(pos))) {
  242. if (is_surrogate_pair_tail(str.charCodeAt(pos + 1))) {
  243. return str.charAt(pos) + str.charAt(pos + 1);
  244. }
  245. } else if (is_surrogate_pair_tail(str.charCodeAt(pos))) {
  246. if (is_surrogate_pair_head(str.charCodeAt(pos - 1))) {
  247. return str.charAt(pos - 1) + str.charAt(pos);
  248. }
  249. }
  250. return str.charAt(pos);
  251. }
  252. function get_full_char_code(str, pos) {
  253. // https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates
  254. if (is_surrogate_pair_head(str.charCodeAt(pos))) {
  255. return 0x10000 + (str.charCodeAt(pos) - 0xd800 << 10) + str.charCodeAt(pos + 1) - 0xdc00;
  256. }
  257. return str.charCodeAt(pos);
  258. }
  259. function get_full_char_length(str) {
  260. var surrogates = 0;
  261. for (var i = 0; i < str.length; i++) {
  262. if (is_surrogate_pair_head(str.charCodeAt(i)) && is_surrogate_pair_tail(str.charCodeAt(i + 1))) {
  263. surrogates++;
  264. i++;
  265. }
  266. }
  267. return str.length - surrogates;
  268. }
  269. function from_char_code(code) {
  270. // Based on https://github.com/mathiasbynens/String.fromCodePoint/blob/master/fromcodepoint.js
  271. if (code > 0xFFFF) {
  272. code -= 0x10000;
  273. return (String.fromCharCode((code >> 10) + 0xD800) +
  274. String.fromCharCode((code % 0x400) + 0xDC00));
  275. }
  276. return String.fromCharCode(code);
  277. }
  278. function is_surrogate_pair_head(code) {
  279. return code >= 0xd800 && code <= 0xdbff;
  280. }
  281. function is_surrogate_pair_tail(code) {
  282. return code >= 0xdc00 && code <= 0xdfff;
  283. }
  284. function is_digit(code) {
  285. return code >= 48 && code <= 57;
  286. }
  287. function is_identifier_start(ch) {
  288. return UNICODE.ID_Start.test(ch);
  289. }
  290. function is_identifier_char(ch) {
  291. return UNICODE.ID_Continue.test(ch);
  292. }
  293. const BASIC_IDENT = /^[a-z_$][a-z0-9_$]*$/i;
  294. function is_basic_identifier_string(str) {
  295. return BASIC_IDENT.test(str);
  296. }
  297. function is_identifier_string(str, allow_surrogates) {
  298. if (BASIC_IDENT.test(str)) {
  299. return true;
  300. }
  301. if (!allow_surrogates && /[\ud800-\udfff]/.test(str)) {
  302. return false;
  303. }
  304. var match = UNICODE.ID_Start.exec(str);
  305. if (!match || match.index !== 0) {
  306. return false;
  307. }
  308. str = str.slice(match[0].length);
  309. if (!str) {
  310. return true;
  311. }
  312. match = UNICODE.ID_Continue.exec(str);
  313. return !!match && match[0].length === str.length;
  314. }
  315. function parse_js_number(num, allow_e = true) {
  316. if (!allow_e && num.includes("e")) {
  317. return NaN;
  318. }
  319. if (RE_HEX_NUMBER.test(num)) {
  320. return parseInt(num.substr(2), 16);
  321. } else if (RE_OCT_NUMBER.test(num)) {
  322. return parseInt(num.substr(1), 8);
  323. } else if (RE_ES6_OCT_NUMBER.test(num)) {
  324. return parseInt(num.substr(2), 8);
  325. } else if (RE_BIN_NUMBER.test(num)) {
  326. return parseInt(num.substr(2), 2);
  327. } else if (RE_DEC_NUMBER.test(num)) {
  328. return parseFloat(num);
  329. } else {
  330. var val = parseFloat(num);
  331. if (val == num) return val;
  332. }
  333. }
  334. class JS_Parse_Error extends Error {
  335. constructor(message, filename, line, col, pos) {
  336. super();
  337. this.name = "SyntaxError";
  338. this.message = message;
  339. this.filename = filename;
  340. this.line = line;
  341. this.col = col;
  342. this.pos = pos;
  343. }
  344. }
  345. function js_error(message, filename, line, col, pos) {
  346. throw new JS_Parse_Error(message, filename, line, col, pos);
  347. }
  348. function is_token(token, type, val) {
  349. return token.type == type && (val == null || token.value == val);
  350. }
  351. var EX_EOF = {};
  352. function tokenizer($TEXT, filename, html5_comments, shebang) {
  353. var S = {
  354. text : $TEXT,
  355. filename : filename,
  356. pos : 0,
  357. tokpos : 0,
  358. line : 1,
  359. tokline : 0,
  360. col : 0,
  361. tokcol : 0,
  362. newline_before : false,
  363. regex_allowed : false,
  364. brace_counter : 0,
  365. template_braces : [],
  366. comments_before : [],
  367. directives : {},
  368. directive_stack : []
  369. };
  370. function peek() { return get_full_char(S.text, S.pos); }
  371. // Used because parsing ?. involves a lookahead for a digit
  372. function is_option_chain_op() {
  373. const must_be_dot = S.text.charCodeAt(S.pos + 1) === 46;
  374. if (!must_be_dot) return false;
  375. const cannot_be_digit = S.text.charCodeAt(S.pos + 2);
  376. return cannot_be_digit < 48 || cannot_be_digit > 57;
  377. }
  378. function next(signal_eof, in_string) {
  379. var ch = get_full_char(S.text, S.pos++);
  380. if (signal_eof && !ch)
  381. throw EX_EOF;
  382. if (NEWLINE_CHARS.has(ch)) {
  383. S.newline_before = S.newline_before || !in_string;
  384. ++S.line;
  385. S.col = 0;
  386. if (ch == "\r" && peek() == "\n") {
  387. // treat a \r\n sequence as a single \n
  388. ++S.pos;
  389. ch = "\n";
  390. }
  391. } else {
  392. if (ch.length > 1) {
  393. ++S.pos;
  394. ++S.col;
  395. }
  396. ++S.col;
  397. }
  398. return ch;
  399. }
  400. function forward(i) {
  401. while (i--) next();
  402. }
  403. function looking_at(str) {
  404. return S.text.substr(S.pos, str.length) == str;
  405. }
  406. function find_eol() {
  407. var text = S.text;
  408. for (var i = S.pos, n = S.text.length; i < n; ++i) {
  409. var ch = text[i];
  410. if (NEWLINE_CHARS.has(ch))
  411. return i;
  412. }
  413. return -1;
  414. }
  415. function find(what, signal_eof) {
  416. var pos = S.text.indexOf(what, S.pos);
  417. if (signal_eof && pos == -1) throw EX_EOF;
  418. return pos;
  419. }
  420. function start_token() {
  421. S.tokline = S.line;
  422. S.tokcol = S.col;
  423. S.tokpos = S.pos;
  424. }
  425. var prev_was_dot = false;
  426. var previous_token = null;
  427. function token(type, value, is_comment) {
  428. S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX.has(value)) ||
  429. (type == "keyword" && KEYWORDS_BEFORE_EXPRESSION.has(value)) ||
  430. (type == "punc" && PUNC_BEFORE_EXPRESSION.has(value))) ||
  431. (type == "arrow");
  432. if (type == "punc" && (value == "." || value == "?.")) {
  433. prev_was_dot = true;
  434. } else if (!is_comment) {
  435. prev_was_dot = false;
  436. }
  437. const line = S.tokline;
  438. const col = S.tokcol;
  439. const pos = S.tokpos;
  440. const nlb = S.newline_before;
  441. const file = filename;
  442. let comments_before = [];
  443. let comments_after = [];
  444. if (!is_comment) {
  445. comments_before = S.comments_before;
  446. comments_after = S.comments_before = [];
  447. }
  448. S.newline_before = false;
  449. const tok = new AST_Token(type, value, line, col, pos, nlb, comments_before, comments_after, file);
  450. if (!is_comment) previous_token = tok;
  451. return tok;
  452. }
  453. function skip_whitespace() {
  454. while (WHITESPACE_CHARS.has(peek()))
  455. next();
  456. }
  457. function read_while(pred) {
  458. var ret = "", ch, i = 0;
  459. while ((ch = peek()) && pred(ch, i++))
  460. ret += next();
  461. return ret;
  462. }
  463. function parse_error(err) {
  464. js_error(err, filename, S.tokline, S.tokcol, S.tokpos);
  465. }
  466. function read_num(prefix) {
  467. var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".", is_big_int = false, numeric_separator = false;
  468. var num = read_while(function(ch, i) {
  469. if (is_big_int) return false;
  470. var code = ch.charCodeAt(0);
  471. switch (code) {
  472. case 95: // _
  473. return (numeric_separator = true);
  474. case 98: case 66: // bB
  475. return (has_x = true); // Can occur in hex sequence, don't return false yet
  476. case 111: case 79: // oO
  477. case 120: case 88: // xX
  478. return has_x ? false : (has_x = true);
  479. case 101: case 69: // eE
  480. return has_x ? true : has_e ? false : (has_e = after_e = true);
  481. case 45: // -
  482. return after_e || (i == 0 && !prefix);
  483. case 43: // +
  484. return after_e;
  485. case (after_e = false, 46): // .
  486. return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;
  487. }
  488. if (ch === "n") {
  489. is_big_int = true;
  490. return true;
  491. }
  492. return RE_NUM_LITERAL.test(ch);
  493. });
  494. if (prefix) num = prefix + num;
  495. LATEST_RAW = num;
  496. if (RE_OCT_NUMBER.test(num) && next_token.has_directive("use strict")) {
  497. parse_error("Legacy octal literals are not allowed in strict mode");
  498. }
  499. if (numeric_separator) {
  500. if (num.endsWith("_")) {
  501. parse_error("Numeric separators are not allowed at the end of numeric literals");
  502. } else if (num.includes("__")) {
  503. parse_error("Only one underscore is allowed as numeric separator");
  504. }
  505. num = num.replace(/_/g, "");
  506. }
  507. if (num.endsWith("n")) {
  508. const without_n = num.slice(0, -1);
  509. const allow_e = RE_HEX_NUMBER.test(without_n);
  510. const valid = parse_js_number(without_n, allow_e);
  511. if (!has_dot && RE_BIG_INT.test(num) && !isNaN(valid))
  512. return token("big_int", without_n);
  513. parse_error("Invalid or unexpected token");
  514. }
  515. var valid = parse_js_number(num);
  516. if (!isNaN(valid)) {
  517. return token("num", valid);
  518. } else {
  519. parse_error("Invalid syntax: " + num);
  520. }
  521. }
  522. function is_octal(ch) {
  523. return ch >= "0" && ch <= "7";
  524. }
  525. function read_escaped_char(in_string, strict_hex, template_string) {
  526. var ch = next(true, in_string);
  527. switch (ch.charCodeAt(0)) {
  528. case 110 : return "\n";
  529. case 114 : return "\r";
  530. case 116 : return "\t";
  531. case 98 : return "\b";
  532. case 118 : return "\u000b"; // \v
  533. case 102 : return "\f";
  534. case 120 : return String.fromCharCode(hex_bytes(2, strict_hex)); // \x
  535. case 117 : // \u
  536. if (peek() == "{") {
  537. next(true);
  538. if (peek() === "}")
  539. parse_error("Expecting hex-character between {}");
  540. while (peek() == "0") next(true); // No significance
  541. var result, length = find("}", true) - S.pos;
  542. // Avoid 32 bit integer overflow (1 << 32 === 1)
  543. // We know first character isn't 0 and thus out of range anyway
  544. if (length > 6 || (result = hex_bytes(length, strict_hex)) > 0x10FFFF) {
  545. parse_error("Unicode reference out of bounds");
  546. }
  547. next(true);
  548. return from_char_code(result);
  549. }
  550. return String.fromCharCode(hex_bytes(4, strict_hex));
  551. case 10 : return ""; // newline
  552. case 13 : // \r
  553. if (peek() == "\n") { // DOS newline
  554. next(true, in_string);
  555. return "";
  556. }
  557. }
  558. if (is_octal(ch)) {
  559. if (template_string && strict_hex) {
  560. const represents_null_character = ch === "0" && !is_octal(peek());
  561. if (!represents_null_character) {
  562. parse_error("Octal escape sequences are not allowed in template strings");
  563. }
  564. }
  565. return read_octal_escape_sequence(ch, strict_hex);
  566. }
  567. return ch;
  568. }
  569. function read_octal_escape_sequence(ch, strict_octal) {
  570. // Read
  571. var p = peek();
  572. if (p >= "0" && p <= "7") {
  573. ch += next(true);
  574. if (ch[0] <= "3" && (p = peek()) >= "0" && p <= "7")
  575. ch += next(true);
  576. }
  577. // Parse
  578. if (ch === "0") return "\0";
  579. if (ch.length > 0 && next_token.has_directive("use strict") && strict_octal)
  580. parse_error("Legacy octal escape sequences are not allowed in strict mode");
  581. return String.fromCharCode(parseInt(ch, 8));
  582. }
  583. function hex_bytes(n, strict_hex) {
  584. var num = 0;
  585. for (; n > 0; --n) {
  586. if (!strict_hex && isNaN(parseInt(peek(), 16))) {
  587. return parseInt(num, 16) || "";
  588. }
  589. var digit = next(true);
  590. if (isNaN(parseInt(digit, 16)))
  591. parse_error("Invalid hex-character pattern in string");
  592. num += digit;
  593. }
  594. return parseInt(num, 16);
  595. }
  596. var read_string = with_eof_error("Unterminated string constant", function() {
  597. const start_pos = S.pos;
  598. var quote = next(), ret = [];
  599. for (;;) {
  600. var ch = next(true, true);
  601. if (ch == "\\") ch = read_escaped_char(true, true);
  602. else if (ch == "\r" || ch == "\n") parse_error("Unterminated string constant");
  603. else if (ch == quote) break;
  604. ret.push(ch);
  605. }
  606. var tok = token("string", ret.join(""));
  607. LATEST_RAW = S.text.slice(start_pos, S.pos);
  608. tok.quote = quote;
  609. return tok;
  610. });
  611. var read_template_characters = with_eof_error("Unterminated template", function(begin) {
  612. if (begin) {
  613. S.template_braces.push(S.brace_counter);
  614. }
  615. var content = "", raw = "", ch, tok;
  616. next(true, true);
  617. while ((ch = next(true, true)) != "`") {
  618. if (ch == "\r") {
  619. if (peek() == "\n") ++S.pos;
  620. ch = "\n";
  621. } else if (ch == "$" && peek() == "{") {
  622. next(true, true);
  623. S.brace_counter++;
  624. tok = token(begin ? "template_head" : "template_substitution", content);
  625. TEMPLATE_RAWS.set(tok, raw);
  626. tok.template_end = false;
  627. return tok;
  628. }
  629. raw += ch;
  630. if (ch == "\\") {
  631. var tmp = S.pos;
  632. var prev_is_tag = previous_token && (previous_token.type === "name" || previous_token.type === "punc" && (previous_token.value === ")" || previous_token.value === "]"));
  633. ch = read_escaped_char(true, !prev_is_tag, true);
  634. raw += S.text.substr(tmp, S.pos - tmp);
  635. }
  636. content += ch;
  637. }
  638. S.template_braces.pop();
  639. tok = token(begin ? "template_head" : "template_substitution", content);
  640. TEMPLATE_RAWS.set(tok, raw);
  641. tok.template_end = true;
  642. return tok;
  643. });
  644. function skip_line_comment(type) {
  645. var regex_allowed = S.regex_allowed;
  646. var i = find_eol(), ret;
  647. if (i == -1) {
  648. ret = S.text.substr(S.pos);
  649. S.pos = S.text.length;
  650. } else {
  651. ret = S.text.substring(S.pos, i);
  652. S.pos = i;
  653. }
  654. S.col = S.tokcol + (S.pos - S.tokpos);
  655. S.comments_before.push(token(type, ret, true));
  656. S.regex_allowed = regex_allowed;
  657. return next_token;
  658. }
  659. var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function() {
  660. var regex_allowed = S.regex_allowed;
  661. var i = find("*/", true);
  662. var text = S.text.substring(S.pos, i).replace(/\r\n|\r|\u2028|\u2029/g, "\n");
  663. // update stream position
  664. forward(get_full_char_length(text) /* text length doesn't count \r\n as 2 char while S.pos - i does */ + 2);
  665. S.comments_before.push(token("comment2", text, true));
  666. S.newline_before = S.newline_before || text.includes("\n");
  667. S.regex_allowed = regex_allowed;
  668. return next_token;
  669. });
  670. var read_name = with_eof_error("Unterminated identifier name", function() {
  671. var name = [], ch, escaped = false;
  672. var read_escaped_identifier_char = function() {
  673. escaped = true;
  674. next();
  675. if (peek() !== "u") {
  676. parse_error("Expecting UnicodeEscapeSequence -- uXXXX or u{XXXX}");
  677. }
  678. return read_escaped_char(false, true);
  679. };
  680. // Read first character (ID_Start)
  681. if ((ch = peek()) === "\\") {
  682. ch = read_escaped_identifier_char();
  683. if (!is_identifier_start(ch)) {
  684. parse_error("First identifier char is an invalid identifier char");
  685. }
  686. } else if (is_identifier_start(ch)) {
  687. next();
  688. } else {
  689. return "";
  690. }
  691. name.push(ch);
  692. // Read ID_Continue
  693. while ((ch = peek()) != null) {
  694. if ((ch = peek()) === "\\") {
  695. ch = read_escaped_identifier_char();
  696. if (!is_identifier_char(ch)) {
  697. parse_error("Invalid escaped identifier char");
  698. }
  699. } else {
  700. if (!is_identifier_char(ch)) {
  701. break;
  702. }
  703. next();
  704. }
  705. name.push(ch);
  706. }
  707. const name_str = name.join("");
  708. if (RESERVED_WORDS.has(name_str) && escaped) {
  709. parse_error("Escaped characters are not allowed in keywords");
  710. }
  711. return name_str;
  712. });
  713. var read_regexp = with_eof_error("Unterminated regular expression", function(source) {
  714. var prev_backslash = false, ch, in_class = false;
  715. while ((ch = next(true))) if (NEWLINE_CHARS.has(ch)) {
  716. parse_error("Unexpected line terminator");
  717. } else if (prev_backslash) {
  718. if (/^[\u0000-\u007F]$/.test(ch)) {
  719. source += "\\" + ch;
  720. } else {
  721. // Remove the useless slash before the escape, but only for characters that won't be added to regexp syntax
  722. source += ch;
  723. }
  724. prev_backslash = false;
  725. } else if (ch == "[") {
  726. in_class = true;
  727. source += ch;
  728. } else if (ch == "]" && in_class) {
  729. in_class = false;
  730. source += ch;
  731. } else if (ch == "/" && !in_class) {
  732. break;
  733. } else if (ch == "\\") {
  734. prev_backslash = true;
  735. } else {
  736. source += ch;
  737. }
  738. const flags = read_name();
  739. return token("regexp", "/" + source + "/" + flags);
  740. });
  741. function read_operator(prefix) {
  742. function grow(op) {
  743. if (!peek()) return op;
  744. var bigger = op + peek();
  745. if (OPERATORS.has(bigger)) {
  746. next();
  747. return grow(bigger);
  748. } else {
  749. return op;
  750. }
  751. }
  752. return token("operator", grow(prefix || next()));
  753. }
  754. function handle_slash() {
  755. next();
  756. switch (peek()) {
  757. case "/":
  758. next();
  759. return skip_line_comment("comment1");
  760. case "*":
  761. next();
  762. return skip_multiline_comment();
  763. }
  764. return S.regex_allowed ? read_regexp("") : read_operator("/");
  765. }
  766. function handle_eq_sign() {
  767. next();
  768. if (peek() === ">") {
  769. next();
  770. return token("arrow", "=>");
  771. } else {
  772. return read_operator("=");
  773. }
  774. }
  775. function handle_dot() {
  776. next();
  777. if (is_digit(peek().charCodeAt(0))) {
  778. return read_num(".");
  779. }
  780. if (peek() === ".") {
  781. next(); // Consume second dot
  782. next(); // Consume third dot
  783. return token("expand", "...");
  784. }
  785. return token("punc", ".");
  786. }
  787. function read_word() {
  788. var word = read_name();
  789. if (prev_was_dot) return token("name", word);
  790. return KEYWORDS_ATOM.has(word) ? token("atom", word)
  791. : !KEYWORDS.has(word) ? token("name", word)
  792. : OPERATORS.has(word) ? token("operator", word)
  793. : token("keyword", word);
  794. }
  795. function read_private_word() {
  796. next();
  797. return token("privatename", read_name());
  798. }
  799. function with_eof_error(eof_error, cont) {
  800. return function(x) {
  801. try {
  802. return cont(x);
  803. } catch(ex) {
  804. if (ex === EX_EOF) parse_error(eof_error);
  805. else throw ex;
  806. }
  807. };
  808. }
  809. function next_token(force_regexp) {
  810. if (force_regexp != null)
  811. return read_regexp(force_regexp);
  812. if (shebang && S.pos == 0 && looking_at("#!")) {
  813. start_token();
  814. forward(2);
  815. skip_line_comment("comment5");
  816. }
  817. for (;;) {
  818. skip_whitespace();
  819. start_token();
  820. if (html5_comments) {
  821. if (looking_at("<!--")) {
  822. forward(4);
  823. skip_line_comment("comment3");
  824. continue;
  825. }
  826. if (looking_at("-->") && S.newline_before) {
  827. forward(3);
  828. skip_line_comment("comment4");
  829. continue;
  830. }
  831. }
  832. var ch = peek();
  833. if (!ch) return token("eof");
  834. var code = ch.charCodeAt(0);
  835. switch (code) {
  836. case 34: case 39: return read_string();
  837. case 46: return handle_dot();
  838. case 47: {
  839. var tok = handle_slash();
  840. if (tok === next_token) continue;
  841. return tok;
  842. }
  843. case 61: return handle_eq_sign();
  844. case 63: {
  845. if (!is_option_chain_op()) break; // Handled below
  846. next(); // ?
  847. next(); // .
  848. return token("punc", "?.");
  849. }
  850. case 96: return read_template_characters(true);
  851. case 123:
  852. S.brace_counter++;
  853. break;
  854. case 125:
  855. S.brace_counter--;
  856. if (S.template_braces.length > 0
  857. && S.template_braces[S.template_braces.length - 1] === S.brace_counter)
  858. return read_template_characters(false);
  859. break;
  860. }
  861. if (is_digit(code)) return read_num();
  862. if (PUNC_CHARS.has(ch)) return token("punc", next());
  863. if (OPERATOR_CHARS.has(ch)) return read_operator();
  864. if (code == 92 || is_identifier_start(ch)) return read_word();
  865. if (code == 35) return read_private_word();
  866. break;
  867. }
  868. parse_error("Unexpected character '" + ch + "'");
  869. }
  870. next_token.next = next;
  871. next_token.peek = peek;
  872. next_token.context = function(nc) {
  873. if (nc) S = nc;
  874. return S;
  875. };
  876. next_token.add_directive = function(directive) {
  877. S.directive_stack[S.directive_stack.length - 1].push(directive);
  878. if (S.directives[directive] === undefined) {
  879. S.directives[directive] = 1;
  880. } else {
  881. S.directives[directive]++;
  882. }
  883. };
  884. next_token.push_directives_stack = function() {
  885. S.directive_stack.push([]);
  886. };
  887. next_token.pop_directives_stack = function() {
  888. var directives = S.directive_stack[S.directive_stack.length - 1];
  889. for (var i = 0; i < directives.length; i++) {
  890. S.directives[directives[i]]--;
  891. }
  892. S.directive_stack.pop();
  893. };
  894. next_token.has_directive = function(directive) {
  895. return S.directives[directive] > 0;
  896. };
  897. return next_token;
  898. }
  899. /* -----[ Parser (constants) ]----- */
  900. var UNARY_PREFIX = makePredicate([
  901. "typeof",
  902. "void",
  903. "delete",
  904. "--",
  905. "++",
  906. "!",
  907. "~",
  908. "-",
  909. "+"
  910. ]);
  911. var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
  912. var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "??=", "&&=", "||=", "/=", "*=", "**=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
  913. var LOGICAL_ASSIGNMENT = makePredicate([ "??=", "&&=", "||=" ]);
  914. var PRECEDENCE = (function(a, ret) {
  915. for (var i = 0; i < a.length; ++i) {
  916. for (const op of a[i]) {
  917. ret[op] = i + 1;
  918. }
  919. }
  920. return ret;
  921. })(
  922. [
  923. ["||"],
  924. ["??"],
  925. ["&&"],
  926. ["|"],
  927. ["^"],
  928. ["&"],
  929. ["==", "===", "!=", "!=="],
  930. ["<", ">", "<=", ">=", "in", "instanceof"],
  931. [">>", "<<", ">>>"],
  932. ["+", "-"],
  933. ["*", "/", "%"],
  934. ["**"]
  935. ],
  936. {}
  937. );
  938. var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "big_int", "string", "regexp", "name"]);
  939. /* -----[ Parser ]----- */
  940. function parse($TEXT, options) {
  941. // maps start tokens to count of comments found outside of their parens
  942. // Example: /* I count */ ( /* I don't */ foo() )
  943. // Useful because comments_before property of call with parens outside
  944. // contains both comments inside and outside these parens. Used to find the
  945. // right #__PURE__ comments for an expression
  946. const outer_comments_before_counts = new WeakMap();
  947. options = defaults(options, {
  948. bare_returns : false,
  949. ecma : null, // Legacy
  950. expression : false,
  951. filename : null,
  952. html5_comments : true,
  953. module : false,
  954. shebang : true,
  955. strict : false,
  956. toplevel : null,
  957. }, true);
  958. var S = {
  959. input : (typeof $TEXT == "string"
  960. ? tokenizer($TEXT, options.filename,
  961. options.html5_comments, options.shebang)
  962. : $TEXT),
  963. token : null,
  964. prev : null,
  965. peeked : null,
  966. in_function : 0,
  967. in_async : -1,
  968. in_generator : -1,
  969. in_directives : true,
  970. in_loop : 0,
  971. labels : []
  972. };
  973. S.token = next();
  974. function is(type, value) {
  975. return is_token(S.token, type, value);
  976. }
  977. function peek() { return S.peeked || (S.peeked = S.input()); }
  978. function next() {
  979. S.prev = S.token;
  980. if (!S.peeked) peek();
  981. S.token = S.peeked;
  982. S.peeked = null;
  983. S.in_directives = S.in_directives && (
  984. S.token.type == "string" || is("punc", ";")
  985. );
  986. return S.token;
  987. }
  988. function prev() {
  989. return S.prev;
  990. }
  991. function croak(msg, line, col, pos) {
  992. var ctx = S.input.context();
  993. js_error(msg,
  994. ctx.filename,
  995. line != null ? line : ctx.tokline,
  996. col != null ? col : ctx.tokcol,
  997. pos != null ? pos : ctx.tokpos);
  998. }
  999. function token_error(token, msg) {
  1000. croak(msg, token.line, token.col);
  1001. }
  1002. function unexpected(token) {
  1003. if (token == null)
  1004. token = S.token;
  1005. token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
  1006. }
  1007. function expect_token(type, val) {
  1008. if (is(type, val)) {
  1009. return next();
  1010. }
  1011. token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
  1012. }
  1013. function expect(punc) { return expect_token("punc", punc); }
  1014. function has_newline_before(token) {
  1015. return token.nlb || !token.comments_before.every((comment) => !comment.nlb);
  1016. }
  1017. function can_insert_semicolon() {
  1018. return !options.strict
  1019. && (is("eof") || is("punc", "}") || has_newline_before(S.token));
  1020. }
  1021. function is_in_generator() {
  1022. return S.in_generator === S.in_function;
  1023. }
  1024. function is_in_async() {
  1025. return S.in_async === S.in_function;
  1026. }
  1027. function can_await() {
  1028. return (
  1029. S.in_async === S.in_function
  1030. || S.in_function === 0 && S.input.has_directive("use strict")
  1031. );
  1032. }
  1033. function semicolon(optional) {
  1034. if (is("punc", ";")) next();
  1035. else if (!optional && !can_insert_semicolon()) unexpected();
  1036. }
  1037. function parenthesised() {
  1038. expect("(");
  1039. var exp = expression(true);
  1040. expect(")");
  1041. return exp;
  1042. }
  1043. function embed_tokens(parser) {
  1044. return function _embed_tokens_wrapper(...args) {
  1045. const start = S.token;
  1046. const expr = parser(...args);
  1047. expr.start = start;
  1048. expr.end = prev();
  1049. return expr;
  1050. };
  1051. }
  1052. function handle_regexp() {
  1053. if (is("operator", "/") || is("operator", "/=")) {
  1054. S.peeked = null;
  1055. S.token = S.input(S.token.value.substr(1)); // force regexp
  1056. }
  1057. }
  1058. var statement = embed_tokens(function statement(is_export_default, is_for_body, is_if_body) {
  1059. handle_regexp();
  1060. switch (S.token.type) {
  1061. case "string":
  1062. if (S.in_directives) {
  1063. var token = peek();
  1064. if (!LATEST_RAW.includes("\\")
  1065. && (is_token(token, "punc", ";")
  1066. || is_token(token, "punc", "}")
  1067. || has_newline_before(token)
  1068. || is_token(token, "eof"))) {
  1069. S.input.add_directive(S.token.value);
  1070. } else {
  1071. S.in_directives = false;
  1072. }
  1073. }
  1074. var dir = S.in_directives, stat = simple_statement();
  1075. return dir && stat.body instanceof AST_String ? new AST_Directive(stat.body) : stat;
  1076. case "template_head":
  1077. case "num":
  1078. case "big_int":
  1079. case "regexp":
  1080. case "operator":
  1081. case "atom":
  1082. return simple_statement();
  1083. case "name":
  1084. case "privatename":
  1085. if(is("privatename") && !S.in_class)
  1086. croak("Private field must be used in an enclosing class");
  1087. if (S.token.value == "async" && is_token(peek(), "keyword", "function")) {
  1088. next();
  1089. next();
  1090. if (is_for_body) {
  1091. croak("functions are not allowed as the body of a loop");
  1092. }
  1093. return function_(AST_Defun, false, true, is_export_default);
  1094. }
  1095. if (S.token.value == "import" && !is_token(peek(), "punc", "(") && !is_token(peek(), "punc", ".")) {
  1096. next();
  1097. var node = import_statement();
  1098. semicolon();
  1099. return node;
  1100. }
  1101. return is_token(peek(), "punc", ":")
  1102. ? labeled_statement()
  1103. : simple_statement();
  1104. case "punc":
  1105. switch (S.token.value) {
  1106. case "{":
  1107. return new AST_BlockStatement({
  1108. start : S.token,
  1109. body : block_(),
  1110. end : prev()
  1111. });
  1112. case "[":
  1113. case "(":
  1114. return simple_statement();
  1115. case ";":
  1116. S.in_directives = false;
  1117. next();
  1118. return new AST_EmptyStatement();
  1119. default:
  1120. unexpected();
  1121. }
  1122. case "keyword":
  1123. switch (S.token.value) {
  1124. case "break":
  1125. next();
  1126. return break_cont(AST_Break);
  1127. case "continue":
  1128. next();
  1129. return break_cont(AST_Continue);
  1130. case "debugger":
  1131. next();
  1132. semicolon();
  1133. return new AST_Debugger();
  1134. case "do":
  1135. next();
  1136. var body = in_loop(statement);
  1137. expect_token("keyword", "while");
  1138. var condition = parenthesised();
  1139. semicolon(true);
  1140. return new AST_Do({
  1141. body : body,
  1142. condition : condition
  1143. });
  1144. case "while":
  1145. next();
  1146. return new AST_While({
  1147. condition : parenthesised(),
  1148. body : in_loop(function() { return statement(false, true); })
  1149. });
  1150. case "for":
  1151. next();
  1152. return for_();
  1153. case "class":
  1154. next();
  1155. if (is_for_body) {
  1156. croak("classes are not allowed as the body of a loop");
  1157. }
  1158. if (is_if_body) {
  1159. croak("classes are not allowed as the body of an if");
  1160. }
  1161. return class_(AST_DefClass, is_export_default);
  1162. case "function":
  1163. next();
  1164. if (is_for_body) {
  1165. croak("functions are not allowed as the body of a loop");
  1166. }
  1167. return function_(AST_Defun, false, false, is_export_default);
  1168. case "if":
  1169. next();
  1170. return if_();
  1171. case "return":
  1172. if (S.in_function == 0 && !options.bare_returns)
  1173. croak("'return' outside of function");
  1174. next();
  1175. var value = null;
  1176. if (is("punc", ";")) {
  1177. next();
  1178. } else if (!can_insert_semicolon()) {
  1179. value = expression(true);
  1180. semicolon();
  1181. }
  1182. return new AST_Return({
  1183. value: value
  1184. });
  1185. case "switch":
  1186. next();
  1187. return new AST_Switch({
  1188. expression : parenthesised(),
  1189. body : in_loop(switch_body_)
  1190. });
  1191. case "throw":
  1192. next();
  1193. if (has_newline_before(S.token))
  1194. croak("Illegal newline after 'throw'");
  1195. var value = expression(true);
  1196. semicolon();
  1197. return new AST_Throw({
  1198. value: value
  1199. });
  1200. case "try":
  1201. next();
  1202. return try_();
  1203. case "var":
  1204. next();
  1205. var node = var_();
  1206. semicolon();
  1207. return node;
  1208. case "let":
  1209. next();
  1210. var node = let_();
  1211. semicolon();
  1212. return node;
  1213. case "const":
  1214. next();
  1215. var node = const_();
  1216. semicolon();
  1217. return node;
  1218. case "with":
  1219. if (S.input.has_directive("use strict")) {
  1220. croak("Strict mode may not include a with statement");
  1221. }
  1222. next();
  1223. return new AST_With({
  1224. expression : parenthesised(),
  1225. body : statement()
  1226. });
  1227. case "export":
  1228. if (!is_token(peek(), "punc", "(")) {
  1229. next();
  1230. var node = export_statement();
  1231. if (is("punc", ";")) semicolon();
  1232. return node;
  1233. }
  1234. }
  1235. }
  1236. unexpected();
  1237. });
  1238. function labeled_statement() {
  1239. var label = as_symbol(AST_Label);
  1240. if (label.name === "await" && is_in_async()) {
  1241. token_error(S.prev, "await cannot be used as label inside async function");
  1242. }
  1243. if (S.labels.some((l) => l.name === label.name)) {
  1244. // ECMA-262, 12.12: An ECMAScript program is considered
  1245. // syntactically incorrect if it contains a
  1246. // LabelledStatement that is enclosed by a
  1247. // LabelledStatement with the same Identifier as label.
  1248. croak("Label " + label.name + " defined twice");
  1249. }
  1250. expect(":");
  1251. S.labels.push(label);
  1252. var stat = statement();
  1253. S.labels.pop();
  1254. if (!(stat instanceof AST_IterationStatement)) {
  1255. // check for `continue` that refers to this label.
  1256. // those should be reported as syntax errors.
  1257. // https://github.com/mishoo/UglifyJS2/issues/287
  1258. label.references.forEach(function(ref) {
  1259. if (ref instanceof AST_Continue) {
  1260. ref = ref.label.start;
  1261. croak("Continue label `" + label.name + "` refers to non-IterationStatement.",
  1262. ref.line, ref.col, ref.pos);
  1263. }
  1264. });
  1265. }
  1266. return new AST_LabeledStatement({ body: stat, label: label });
  1267. }
  1268. function simple_statement(tmp) {
  1269. return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) });
  1270. }
  1271. function break_cont(type) {
  1272. var label = null, ldef;
  1273. if (!can_insert_semicolon()) {
  1274. label = as_symbol(AST_LabelRef, true);
  1275. }
  1276. if (label != null) {
  1277. ldef = S.labels.find((l) => l.name === label.name);
  1278. if (!ldef)
  1279. croak("Undefined label " + label.name);
  1280. label.thedef = ldef;
  1281. } else if (S.in_loop == 0)
  1282. croak(type.TYPE + " not inside a loop or switch");
  1283. semicolon();
  1284. var stat = new type({ label: label });
  1285. if (ldef) ldef.references.push(stat);
  1286. return stat;
  1287. }
  1288. function for_() {
  1289. var for_await_error = "`for await` invalid in this context";
  1290. var await_tok = S.token;
  1291. if (await_tok.type == "name" && await_tok.value == "await") {
  1292. if (!can_await()) {
  1293. token_error(await_tok, for_await_error);
  1294. }
  1295. next();
  1296. } else {
  1297. await_tok = false;
  1298. }
  1299. expect("(");
  1300. var init = null;
  1301. if (!is("punc", ";")) {
  1302. init =
  1303. is("keyword", "var") ? (next(), var_(true)) :
  1304. is("keyword", "let") ? (next(), let_(true)) :
  1305. is("keyword", "const") ? (next(), const_(true)) :
  1306. expression(true, true);
  1307. var is_in = is("operator", "in");
  1308. var is_of = is("name", "of");
  1309. if (await_tok && !is_of) {
  1310. token_error(await_tok, for_await_error);
  1311. }
  1312. if (is_in || is_of) {
  1313. if (init instanceof AST_Definitions) {
  1314. if (init.definitions.length > 1)
  1315. token_error(init.start, "Only one variable declaration allowed in for..in loop");
  1316. } else if (!(is_assignable(init) || (init = to_destructuring(init)) instanceof AST_Destructuring)) {
  1317. token_error(init.start, "Invalid left-hand side in for..in loop");
  1318. }
  1319. next();
  1320. if (is_in) {
  1321. return for_in(init);
  1322. } else {
  1323. return for_of(init, !!await_tok);
  1324. }
  1325. }
  1326. } else if (await_tok) {
  1327. token_error(await_tok, for_await_error);
  1328. }
  1329. return regular_for(init);
  1330. }
  1331. function regular_for(init) {
  1332. expect(";");
  1333. var test = is("punc", ";") ? null : expression(true);
  1334. expect(";");
  1335. var step = is("punc", ")") ? null : expression(true);
  1336. expect(")");
  1337. return new AST_For({
  1338. init : init,
  1339. condition : test,
  1340. step : step,
  1341. body : in_loop(function() { return statement(false, true); })
  1342. });
  1343. }
  1344. function for_of(init, is_await) {
  1345. var lhs = init instanceof AST_Definitions ? init.definitions[0].name : null;
  1346. var obj = expression(true);
  1347. expect(")");
  1348. return new AST_ForOf({
  1349. await : is_await,
  1350. init : init,
  1351. name : lhs,
  1352. object : obj,
  1353. body : in_loop(function() { return statement(false, true); })
  1354. });
  1355. }
  1356. function for_in(init) {
  1357. var obj = expression(true);
  1358. expect(")");
  1359. return new AST_ForIn({
  1360. init : init,
  1361. object : obj,
  1362. body : in_loop(function() { return statement(false, true); })
  1363. });
  1364. }
  1365. var arrow_function = function(start, argnames, is_async) {
  1366. if (has_newline_before(S.token)) {
  1367. croak("Unexpected newline before arrow (=>)");
  1368. }
  1369. expect_token("arrow", "=>");
  1370. var body = _function_body(is("punc", "{"), false, is_async);
  1371. var end =
  1372. body instanceof Array && body.length ? body[body.length - 1].end :
  1373. body instanceof Array ? start :
  1374. body.end;
  1375. return new AST_Arrow({
  1376. start : start,
  1377. end : end,
  1378. async : is_async,
  1379. argnames : argnames,
  1380. body : body
  1381. });
  1382. };
  1383. var function_ = function(ctor, is_generator_property, is_async, is_export_default) {
  1384. var in_statement = ctor === AST_Defun;
  1385. var is_generator = is("operator", "*");
  1386. if (is_generator) {
  1387. next();
  1388. }
  1389. var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
  1390. if (in_statement && !name) {
  1391. if (is_export_default) {
  1392. ctor = AST_Function;
  1393. } else {
  1394. unexpected();
  1395. }
  1396. }
  1397. if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
  1398. unexpected(prev());
  1399. var args = [];
  1400. var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);
  1401. return new ctor({
  1402. start : args.start,
  1403. end : body.end,
  1404. is_generator: is_generator,
  1405. async : is_async,
  1406. name : name,
  1407. argnames: args,
  1408. body : body
  1409. });
  1410. };
  1411. class UsedParametersTracker {
  1412. constructor(is_parameter, strict, duplicates_ok = false) {
  1413. this.is_parameter = is_parameter;
  1414. this.duplicates_ok = duplicates_ok;
  1415. this.parameters = new Set();
  1416. this.duplicate = null;
  1417. this.default_assignment = false;
  1418. this.spread = false;
  1419. this.strict_mode = !!strict;
  1420. }
  1421. add_parameter(token) {
  1422. if (this.parameters.has(token.value)) {
  1423. if (this.duplicate === null) {
  1424. this.duplicate = token;
  1425. }
  1426. this.check_strict();
  1427. } else {
  1428. this.parameters.add(token.value);
  1429. if (this.is_parameter) {
  1430. switch (token.value) {
  1431. case "arguments":
  1432. case "eval":
  1433. case "yield":
  1434. if (this.strict_mode) {
  1435. token_error(token, "Unexpected " + token.value + " identifier as parameter inside strict mode");
  1436. }
  1437. break;
  1438. default:
  1439. if (RESERVED_WORDS.has(token.value)) {
  1440. unexpected();
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. mark_default_assignment(token) {
  1447. if (this.default_assignment === false) {
  1448. this.default_assignment = token;
  1449. }
  1450. }
  1451. mark_spread(token) {
  1452. if (this.spread === false) {
  1453. this.spread = token;
  1454. }
  1455. }
  1456. mark_strict_mode() {
  1457. this.strict_mode = true;
  1458. }
  1459. is_strict() {
  1460. return this.default_assignment !== false || this.spread !== false || this.strict_mode;
  1461. }
  1462. check_strict() {
  1463. if (this.is_strict() && this.duplicate !== null && !this.duplicates_ok) {
  1464. token_error(this.duplicate, "Parameter " + this.duplicate.value + " was used already");
  1465. }
  1466. }
  1467. }
  1468. function parameters(params) {
  1469. var used_parameters = new UsedParametersTracker(true, S.input.has_directive("use strict"));
  1470. expect("(");
  1471. while (!is("punc", ")")) {
  1472. var param = parameter(used_parameters);
  1473. params.push(param);
  1474. if (!is("punc", ")")) {
  1475. expect(",");
  1476. }
  1477. if (param instanceof AST_Expansion) {
  1478. break;
  1479. }
  1480. }
  1481. next();
  1482. }
  1483. function parameter(used_parameters, symbol_type) {
  1484. var param;
  1485. var expand = false;
  1486. if (used_parameters === undefined) {
  1487. used_parameters = new UsedParametersTracker(true, S.input.has_directive("use strict"));
  1488. }
  1489. if (is("expand", "...")) {
  1490. expand = S.token;
  1491. used_parameters.mark_spread(S.token);
  1492. next();
  1493. }
  1494. param = binding_element(used_parameters, symbol_type);
  1495. if (is("operator", "=") && expand === false) {
  1496. used_parameters.mark_default_assignment(S.token);
  1497. next();
  1498. param = new AST_DefaultAssign({
  1499. start: param.start,
  1500. left: param,
  1501. operator: "=",
  1502. right: expression(false),
  1503. end: S.token
  1504. });
  1505. }
  1506. if (expand !== false) {
  1507. if (!is("punc", ")")) {
  1508. unexpected();
  1509. }
  1510. param = new AST_Expansion({
  1511. start: expand,
  1512. expression: param,
  1513. end: expand
  1514. });
  1515. }
  1516. used_parameters.check_strict();
  1517. return param;
  1518. }
  1519. function binding_element(used_parameters, symbol_type) {
  1520. var elements = [];
  1521. var first = true;
  1522. var is_expand = false;
  1523. var expand_token;
  1524. var first_token = S.token;
  1525. if (used_parameters === undefined) {
  1526. const strict = S.input.has_directive("use strict");
  1527. const duplicates_ok = symbol_type === AST_SymbolVar;
  1528. used_parameters = new UsedParametersTracker(false, strict, duplicates_ok);
  1529. }
  1530. symbol_type = symbol_type === undefined ? AST_SymbolFunarg : symbol_type;
  1531. if (is("punc", "[")) {
  1532. next();
  1533. while (!is("punc", "]")) {
  1534. if (first) {
  1535. first = false;
  1536. } else {
  1537. expect(",");
  1538. }
  1539. if (is("expand", "...")) {
  1540. is_expand = true;
  1541. expand_token = S.token;
  1542. used_parameters.mark_spread(S.token);
  1543. next();
  1544. }
  1545. if (is("punc")) {
  1546. switch (S.token.value) {
  1547. case ",":
  1548. elements.push(new AST_Hole({
  1549. start: S.token,
  1550. end: S.token
  1551. }));
  1552. continue;
  1553. case "]": // Trailing comma after last element
  1554. break;
  1555. case "[":
  1556. case "{":
  1557. elements.push(binding_element(used_parameters, symbol_type));
  1558. break;
  1559. default:
  1560. unexpected();
  1561. }
  1562. } else if (is("name")) {
  1563. used_parameters.add_parameter(S.token);
  1564. elements.push(as_symbol(symbol_type));
  1565. } else {
  1566. croak("Invalid function parameter");
  1567. }
  1568. if (is("operator", "=") && is_expand === false) {
  1569. used_parameters.mark_default_assignment(S.token);
  1570. next();
  1571. elements[elements.length - 1] = new AST_DefaultAssign({
  1572. start: elements[elements.length - 1].start,
  1573. left: elements[elements.length - 1],
  1574. operator: "=",
  1575. right: expression(false),
  1576. end: S.token
  1577. });
  1578. }
  1579. if (is_expand) {
  1580. if (!is("punc", "]")) {
  1581. croak("Rest element must be last element");
  1582. }
  1583. elements[elements.length - 1] = new AST_Expansion({
  1584. start: expand_token,
  1585. expression: elements[elements.length - 1],
  1586. end: expand_token
  1587. });
  1588. }
  1589. }
  1590. expect("]");
  1591. used_parameters.check_strict();
  1592. return new AST_Destructuring({
  1593. start: first_token,
  1594. names: elements,
  1595. is_array: true,
  1596. end: prev()
  1597. });
  1598. } else if (is("punc", "{")) {
  1599. next();
  1600. while (!is("punc", "}")) {
  1601. if (first) {
  1602. first = false;
  1603. } else {
  1604. expect(",");
  1605. }
  1606. if (is("expand", "...")) {
  1607. is_expand = true;
  1608. expand_token = S.token;
  1609. used_parameters.mark_spread(S.token);
  1610. next();
  1611. }
  1612. if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].includes(peek().value)) {
  1613. used_parameters.add_parameter(S.token);
  1614. var start = prev();
  1615. var value = as_symbol(symbol_type);
  1616. if (is_expand) {
  1617. elements.push(new AST_Expansion({
  1618. start: expand_token,
  1619. expression: value,
  1620. end: value.end,
  1621. }));
  1622. } else {
  1623. elements.push(new AST_ObjectKeyVal({
  1624. start: start,
  1625. key: value.name,
  1626. value: value,
  1627. end: value.end,
  1628. }));
  1629. }
  1630. } else if (is("punc", "}")) {
  1631. continue; // Allow trailing hole
  1632. } else {
  1633. var property_token = S.token;
  1634. var property = as_property_name();
  1635. if (property === null) {
  1636. unexpected(prev());
  1637. } else if (prev().type === "name" && !is("punc", ":")) {
  1638. elements.push(new AST_ObjectKeyVal({
  1639. start: prev(),
  1640. key: property,
  1641. value: new symbol_type({
  1642. start: prev(),
  1643. name: property,
  1644. end: prev()
  1645. }),
  1646. end: prev()
  1647. }));
  1648. } else {
  1649. expect(":");
  1650. elements.push(new AST_ObjectKeyVal({
  1651. start: property_token,
  1652. quote: property_token.quote,
  1653. key: property,
  1654. value: binding_element(used_parameters, symbol_type),
  1655. end: prev()
  1656. }));
  1657. }
  1658. }
  1659. if (is_expand) {
  1660. if (!is("punc", "}")) {
  1661. croak("Rest element must be last element");
  1662. }
  1663. } else if (is("operator", "=")) {
  1664. used_parameters.mark_default_assignment(S.token);
  1665. next();
  1666. elements[elements.length - 1].value = new AST_DefaultAssign({
  1667. start: elements[elements.length - 1].value.start,
  1668. left: elements[elements.length - 1].value,
  1669. operator: "=",
  1670. right: expression(false),
  1671. end: S.token
  1672. });
  1673. }
  1674. }
  1675. expect("}");
  1676. used_parameters.check_strict();
  1677. return new AST_Destructuring({
  1678. start: first_token,
  1679. names: elements,
  1680. is_array: false,
  1681. end: prev()
  1682. });
  1683. } else if (is("name")) {
  1684. used_parameters.add_parameter(S.token);
  1685. return as_symbol(symbol_type);
  1686. } else {
  1687. croak("Invalid function parameter");
  1688. }
  1689. }
  1690. function params_or_seq_(allow_arrows, maybe_sequence) {
  1691. var spread_token;
  1692. var invalid_sequence;
  1693. var trailing_comma;
  1694. var a = [];
  1695. expect("(");
  1696. while (!is("punc", ")")) {
  1697. if (spread_token) unexpected(spread_token);
  1698. if (is("expand", "...")) {
  1699. spread_token = S.token;
  1700. if (maybe_sequence) invalid_sequence = S.token;
  1701. next();
  1702. a.push(new AST_Expansion({
  1703. start: prev(),
  1704. expression: expression(),
  1705. end: S.token,
  1706. }));
  1707. } else {
  1708. a.push(expression());
  1709. }
  1710. if (!is("punc", ")")) {
  1711. expect(",");
  1712. if (is("punc", ")")) {
  1713. trailing_comma = prev();
  1714. if (maybe_sequence) invalid_sequence = trailing_comma;
  1715. }
  1716. }
  1717. }
  1718. expect(")");
  1719. if (allow_arrows && is("arrow", "=>")) {
  1720. if (spread_token && trailing_comma) unexpected(trailing_comma);
  1721. } else if (invalid_sequence) {
  1722. unexpected(invalid_sequence);
  1723. }
  1724. return a;
  1725. }
  1726. function _function_body(block, generator, is_async, name, args) {
  1727. var loop = S.in_loop;
  1728. var labels = S.labels;
  1729. var current_generator = S.in_generator;
  1730. var current_async = S.in_async;
  1731. ++S.in_function;
  1732. if (generator)
  1733. S.in_generator = S.in_function;
  1734. if (is_async)
  1735. S.in_async = S.in_function;
  1736. if (args) parameters(args);
  1737. if (block)
  1738. S.in_directives = true;
  1739. S.in_loop = 0;
  1740. S.labels = [];
  1741. if (block) {
  1742. S.input.push_directives_stack();
  1743. var a = block_();
  1744. if (name) _verify_symbol(name);
  1745. if (args) args.forEach(_verify_symbol);
  1746. S.input.pop_directives_stack();
  1747. } else {
  1748. var a = [new AST_Return({
  1749. start: S.token,
  1750. value: expression(false),
  1751. end: S.token
  1752. })];
  1753. }
  1754. --S.in_function;
  1755. S.in_loop = loop;
  1756. S.labels = labels;
  1757. S.in_generator = current_generator;
  1758. S.in_async = current_async;
  1759. return a;
  1760. }
  1761. function _await_expression() {
  1762. // Previous token must be "await" and not be interpreted as an identifier
  1763. if (!can_await()) {
  1764. croak("Unexpected await expression outside async function",
  1765. S.prev.line, S.prev.col, S.prev.pos);
  1766. }
  1767. // the await expression is parsed as a unary expression in Babel
  1768. return new AST_Await({
  1769. start: prev(),
  1770. end: S.token,
  1771. expression : maybe_unary(true),
  1772. });
  1773. }
  1774. function _yield_expression() {
  1775. // Previous token must be keyword yield and not be interpret as an identifier
  1776. if (!is_in_generator()) {
  1777. croak("Unexpected yield expression outside generator function",
  1778. S.prev.line, S.prev.col, S.prev.pos);
  1779. }
  1780. var start = S.token;
  1781. var star = false;
  1782. var has_expression = true;
  1783. // Attempt to get expression or star (and then the mandatory expression)
  1784. // behind yield on the same line.
  1785. //
  1786. // If nothing follows on the same line of the yieldExpression,
  1787. // it should default to the value `undefined` for yield to return.
  1788. // In that case, the `undefined` stored as `null` in ast.
  1789. //
  1790. // Note 1: It isn't allowed for yield* to close without an expression
  1791. // Note 2: If there is a nlb between yield and star, it is interpret as
  1792. // yield <explicit undefined> <inserted automatic semicolon> *
  1793. if (can_insert_semicolon() ||
  1794. (is("punc") && PUNC_AFTER_EXPRESSION.has(S.token.value))) {
  1795. has_expression = false;
  1796. } else if (is("operator", "*")) {
  1797. star = true;
  1798. next();
  1799. }
  1800. return new AST_Yield({
  1801. start : start,
  1802. is_star : star,
  1803. expression : has_expression ? expression() : null,
  1804. end : prev()
  1805. });
  1806. }
  1807. function if_() {
  1808. var cond = parenthesised(), body = statement(false, false, true), belse = null;
  1809. if (is("keyword", "else")) {
  1810. next();
  1811. belse = statement(false, false, true);
  1812. }
  1813. return new AST_If({
  1814. condition : cond,
  1815. body : body,
  1816. alternative : belse
  1817. });
  1818. }
  1819. function block_() {
  1820. expect("{");
  1821. var a = [];
  1822. while (!is("punc", "}")) {
  1823. if (is("eof")) unexpected();
  1824. a.push(statement());
  1825. }
  1826. next();
  1827. return a;
  1828. }
  1829. function switch_body_() {
  1830. expect("{");
  1831. var a = [], cur = null, branch = null, tmp;
  1832. while (!is("punc", "}")) {
  1833. if (is("eof")) unexpected();
  1834. if (is("keyword", "case")) {
  1835. if (branch) branch.end = prev();
  1836. cur = [];
  1837. branch = new AST_Case({
  1838. start : (tmp = S.token, next(), tmp),
  1839. expression : expression(true),
  1840. body : cur
  1841. });
  1842. a.push(branch);
  1843. expect(":");
  1844. } else if (is("keyword", "default")) {
  1845. if (branch) branch.end = prev();
  1846. cur = [];
  1847. branch = new AST_Default({
  1848. start : (tmp = S.token, next(), expect(":"), tmp),
  1849. body : cur
  1850. });
  1851. a.push(branch);
  1852. } else {
  1853. if (!cur) unexpected();
  1854. cur.push(statement());
  1855. }
  1856. }
  1857. if (branch) branch.end = prev();
  1858. next();
  1859. return a;
  1860. }
  1861. function try_() {
  1862. var body, bcatch = null, bfinally = null;
  1863. body = new AST_TryBlock({
  1864. start : S.token,
  1865. body : block_(),
  1866. end : prev(),
  1867. });
  1868. if (is("keyword", "catch")) {
  1869. var start = S.token;
  1870. next();
  1871. if (is("punc", "{")) {
  1872. var name = null;
  1873. } else {
  1874. expect("(");
  1875. var name = parameter(undefined, AST_SymbolCatch);
  1876. expect(")");
  1877. }
  1878. bcatch = new AST_Catch({
  1879. start : start,
  1880. argname : name,
  1881. body : block_(),
  1882. end : prev()
  1883. });
  1884. }
  1885. if (is("keyword", "finally")) {
  1886. var start = S.token;
  1887. next();
  1888. bfinally = new AST_Finally({
  1889. start : start,
  1890. body : block_(),
  1891. end : prev()
  1892. });
  1893. }
  1894. if (!bcatch && !bfinally)
  1895. croak("Missing catch/finally blocks");
  1896. return new AST_Try({
  1897. body : body,
  1898. bcatch : bcatch,
  1899. bfinally : bfinally
  1900. });
  1901. }
  1902. /**
  1903. * var
  1904. * vardef1 = 2,
  1905. * vardef2 = 3;
  1906. */
  1907. function vardefs(no_in, kind) {
  1908. var var_defs = [];
  1909. var def;
  1910. for (;;) {
  1911. var sym_type =
  1912. kind === "var" ? AST_SymbolVar :
  1913. kind === "const" ? AST_SymbolConst :
  1914. kind === "let" ? AST_SymbolLet : null;
  1915. // var { a } = b
  1916. if (is("punc", "{") || is("punc", "[")) {
  1917. def = new AST_VarDef({
  1918. start: S.token,
  1919. name: binding_element(undefined, sym_type),
  1920. value: is("operator", "=") ? (expect_token("operator", "="), expression(false, no_in)) : null,
  1921. end: prev()
  1922. });
  1923. } else {
  1924. def = new AST_VarDef({
  1925. start : S.token,
  1926. name : as_symbol(sym_type),
  1927. value : is("operator", "=")
  1928. ? (next(), expression(false, no_in))
  1929. : !no_in && kind === "const"
  1930. ? croak("Missing initializer in const declaration") : null,
  1931. end : prev()
  1932. });
  1933. if (def.name.name == "import") croak("Unexpected token: import");
  1934. }
  1935. var_defs.push(def);
  1936. if (!is("punc", ","))
  1937. break;
  1938. next();
  1939. }
  1940. return var_defs;
  1941. }
  1942. var var_ = function(no_in) {
  1943. return new AST_Var({
  1944. start : prev(),
  1945. definitions : vardefs(no_in, "var"),
  1946. end : prev()
  1947. });
  1948. };
  1949. var let_ = function(no_in) {
  1950. return new AST_Let({
  1951. start : prev(),
  1952. definitions : vardefs(no_in, "let"),
  1953. end : prev()
  1954. });
  1955. };
  1956. var const_ = function(no_in) {
  1957. return new AST_Const({
  1958. start : prev(),
  1959. definitions : vardefs(no_in, "const"),
  1960. end : prev()
  1961. });
  1962. };
  1963. var new_ = function(allow_calls) {
  1964. var start = S.token;
  1965. expect_token("operator", "new");
  1966. if (is("punc", ".")) {
  1967. next();
  1968. expect_token("name", "target");
  1969. return subscripts(new AST_NewTarget({
  1970. start : start,
  1971. end : prev()
  1972. }), allow_calls);
  1973. }
  1974. var newexp = expr_atom(false), args;
  1975. if (is("punc", "(")) {
  1976. next();
  1977. args = expr_list(")", true);
  1978. } else {
  1979. args = [];
  1980. }
  1981. var call = new AST_New({
  1982. start : start,
  1983. expression : newexp,
  1984. args : args,
  1985. end : prev()
  1986. });
  1987. annotate(call);
  1988. return subscripts(call, allow_calls);
  1989. };
  1990. function as_atom_node() {
  1991. var tok = S.token, ret;
  1992. switch (tok.type) {
  1993. case "name":
  1994. ret = _make_symbol(AST_SymbolRef);
  1995. break;
  1996. case "num":
  1997. ret = new AST_Number({
  1998. start: tok,
  1999. end: tok,
  2000. value: tok.value,
  2001. raw: LATEST_RAW
  2002. });
  2003. break;
  2004. case "big_int":
  2005. ret = new AST_BigInt({ start: tok, end: tok, value: tok.value });
  2006. break;
  2007. case "string":
  2008. ret = new AST_String({
  2009. start : tok,
  2010. end : tok,
  2011. value : tok.value,
  2012. quote : tok.quote
  2013. });
  2014. annotate(ret);
  2015. break;
  2016. case "regexp":
  2017. const [_, source, flags] = tok.value.match(/^\/(.*)\/(\w*)$/);
  2018. ret = new AST_RegExp({ start: tok, end: tok, value: { source, flags } });
  2019. break;
  2020. case "atom":
  2021. switch (tok.value) {
  2022. case "false":
  2023. ret = new AST_False({ start: tok, end: tok });
  2024. break;
  2025. case "true":
  2026. ret = new AST_True({ start: tok, end: tok });
  2027. break;
  2028. case "null":
  2029. ret = new AST_Null({ start: tok, end: tok });
  2030. break;
  2031. }
  2032. break;
  2033. }
  2034. next();
  2035. return ret;
  2036. }
  2037. function to_fun_args(ex, default_seen_above) {
  2038. var insert_default = function(ex, default_value) {
  2039. if (default_value) {
  2040. return new AST_DefaultAssign({
  2041. start: ex.start,
  2042. left: ex,
  2043. operator: "=",
  2044. right: default_value,
  2045. end: default_value.end
  2046. });
  2047. }
  2048. return ex;
  2049. };
  2050. if (ex instanceof AST_Object) {
  2051. return insert_default(new AST_Destructuring({
  2052. start: ex.start,
  2053. end: ex.end,
  2054. is_array: false,
  2055. names: ex.properties.map(prop => to_fun_args(prop))
  2056. }), default_seen_above);
  2057. } else if (ex instanceof AST_ObjectKeyVal) {
  2058. ex.value = to_fun_args(ex.value);
  2059. return insert_default(ex, default_seen_above);
  2060. } else if (ex instanceof AST_Hole) {
  2061. return ex;
  2062. } else if (ex instanceof AST_Destructuring) {
  2063. ex.names = ex.names.map(name => to_fun_args(name));
  2064. return insert_default(ex, default_seen_above);
  2065. } else if (ex instanceof AST_SymbolRef) {
  2066. return insert_default(new AST_SymbolFunarg({
  2067. name: ex.name,
  2068. start: ex.start,
  2069. end: ex.end
  2070. }), default_seen_above);
  2071. } else if (ex instanceof AST_Expansion) {
  2072. ex.expression = to_fun_args(ex.expression);
  2073. return insert_default(ex, default_seen_above);
  2074. } else if (ex instanceof AST_Array) {
  2075. return insert_default(new AST_Destructuring({
  2076. start: ex.start,
  2077. end: ex.end,
  2078. is_array: true,
  2079. names: ex.elements.map(elm => to_fun_args(elm))
  2080. }), default_seen_above);
  2081. } else if (ex instanceof AST_Assign) {
  2082. return insert_default(to_fun_args(ex.left, ex.right), default_seen_above);
  2083. } else if (ex instanceof AST_DefaultAssign) {
  2084. ex.left = to_fun_args(ex.left);
  2085. return ex;
  2086. } else {
  2087. croak("Invalid function parameter", ex.start.line, ex.start.col);
  2088. }
  2089. }
  2090. var expr_atom = function(allow_calls, allow_arrows) {
  2091. if (is("operator", "new")) {
  2092. return new_(allow_calls);
  2093. }
  2094. if (is("name", "import") && is_token(peek(), "punc", ".")) {
  2095. return import_meta(allow_calls);
  2096. }
  2097. var start = S.token;
  2098. var peeked;
  2099. var async = is("name", "async")
  2100. && (peeked = peek()).value != "["
  2101. && peeked.type != "arrow"
  2102. && as_atom_node();
  2103. if (is("punc")) {
  2104. switch (S.token.value) {
  2105. case "(":
  2106. if (async && !allow_calls) break;
  2107. var exprs = params_or_seq_(allow_arrows, !async);
  2108. if (allow_arrows && is("arrow", "=>")) {
  2109. return arrow_function(start, exprs.map(e => to_fun_args(e)), !!async);
  2110. }
  2111. var ex = async ? new AST_Call({
  2112. expression: async,
  2113. args: exprs
  2114. }) : to_expr_or_sequence(start, exprs);
  2115. if (ex.start) {
  2116. const outer_comments_before = start.comments_before.length;
  2117. outer_comments_before_counts.set(start, outer_comments_before);
  2118. ex.start.comments_before.unshift(...start.comments_before);
  2119. start.comments_before = ex.start.comments_before;
  2120. if (outer_comments_before == 0 && start.comments_before.length > 0) {
  2121. var comment = start.comments_before[0];
  2122. if (!comment.nlb) {
  2123. comment.nlb = start.nlb;
  2124. start.nlb = false;
  2125. }
  2126. }
  2127. start.comments_after = ex.start.comments_after;
  2128. }
  2129. ex.start = start;
  2130. var end = prev();
  2131. if (ex.end) {
  2132. end.comments_before = ex.end.comments_before;
  2133. ex.end.comments_after.push(...end.comments_after);
  2134. end.comments_after = ex.end.comments_after;
  2135. }
  2136. ex.end = end;
  2137. if (ex instanceof AST_Call) annotate(ex);
  2138. return subscripts(ex, allow_calls);
  2139. case "[":
  2140. return subscripts(array_(), allow_calls);
  2141. case "{":
  2142. return subscripts(object_or_destructuring_(), allow_calls);
  2143. }
  2144. if (!async) unexpected();
  2145. }
  2146. if (allow_arrows && is("name") && is_token(peek(), "arrow")) {
  2147. var param = new AST_SymbolFunarg({
  2148. name: S.token.value,
  2149. start: start,
  2150. end: start,
  2151. });
  2152. next();
  2153. return arrow_function(start, [param], !!async);
  2154. }
  2155. if (is("keyword", "function")) {
  2156. next();
  2157. var func = function_(AST_Function, false, !!async);
  2158. func.start = start;
  2159. func.end = prev();
  2160. return subscripts(func, allow_calls);
  2161. }
  2162. if (async) return subscripts(async, allow_calls);
  2163. if (is("keyword", "class")) {
  2164. next();
  2165. var cls = class_(AST_ClassExpression);
  2166. cls.start = start;
  2167. cls.end = prev();
  2168. return subscripts(cls, allow_calls);
  2169. }
  2170. if (is("template_head")) {
  2171. return subscripts(template_string(), allow_calls);
  2172. }
  2173. if (ATOMIC_START_TOKEN.has(S.token.type)) {
  2174. return subscripts(as_atom_node(), allow_calls);
  2175. }
  2176. unexpected();
  2177. };
  2178. function template_string() {
  2179. var segments = [], start = S.token;
  2180. segments.push(new AST_TemplateSegment({
  2181. start: S.token,
  2182. raw: TEMPLATE_RAWS.get(S.token),
  2183. value: S.token.value,
  2184. end: S.token
  2185. }));
  2186. while (!S.token.template_end) {
  2187. next();
  2188. handle_regexp();
  2189. segments.push(expression(true));
  2190. segments.push(new AST_TemplateSegment({
  2191. start: S.token,
  2192. raw: TEMPLATE_RAWS.get(S.token),
  2193. value: S.token.value,
  2194. end: S.token
  2195. }));
  2196. }
  2197. next();
  2198. return new AST_TemplateString({
  2199. start: start,
  2200. segments: segments,
  2201. end: S.token
  2202. });
  2203. }
  2204. function expr_list(closing, allow_trailing_comma, allow_empty) {
  2205. var first = true, a = [];
  2206. while (!is("punc", closing)) {
  2207. if (first) first = false; else expect(",");
  2208. if (allow_trailing_comma && is("punc", closing)) break;
  2209. if (is("punc", ",") && allow_empty) {
  2210. a.push(new AST_Hole({ start: S.token, end: S.token }));
  2211. } else if (is("expand", "...")) {
  2212. next();
  2213. a.push(new AST_Expansion({start: prev(), expression: expression(),end: S.token}));
  2214. } else {
  2215. a.push(expression(false));
  2216. }
  2217. }
  2218. next();
  2219. return a;
  2220. }
  2221. var array_ = embed_tokens(function() {
  2222. expect("[");
  2223. return new AST_Array({
  2224. elements: expr_list("]", !options.strict, true)
  2225. });
  2226. });
  2227. var create_accessor = embed_tokens((is_generator, is_async) => {
  2228. return function_(AST_Accessor, is_generator, is_async);
  2229. });
  2230. var object_or_destructuring_ = embed_tokens(function object_or_destructuring_() {
  2231. var start = S.token, first = true, a = [];
  2232. expect("{");
  2233. while (!is("punc", "}")) {
  2234. if (first) first = false; else expect(",");
  2235. if (!options.strict && is("punc", "}"))
  2236. // allow trailing comma
  2237. break;
  2238. start = S.token;
  2239. if (start.type == "expand") {
  2240. next();
  2241. a.push(new AST_Expansion({
  2242. start: start,
  2243. expression: expression(false),
  2244. end: prev(),
  2245. }));
  2246. continue;
  2247. }
  2248. if(is("privatename")) {
  2249. croak("private fields are not allowed in an object");
  2250. }
  2251. var name = as_property_name();
  2252. var value;
  2253. // Check property and fetch value
  2254. if (!is("punc", ":")) {
  2255. var concise = concise_method_or_getset(name, start);
  2256. if (concise) {
  2257. a.push(concise);
  2258. continue;
  2259. }
  2260. value = new AST_SymbolRef({
  2261. start: prev(),
  2262. name: name,
  2263. end: prev()
  2264. });
  2265. } else if (name === null) {
  2266. unexpected(prev());
  2267. } else {
  2268. next(); // `:` - see first condition
  2269. value = expression(false);
  2270. }
  2271. // Check for default value and alter value accordingly if necessary
  2272. if (is("operator", "=")) {
  2273. next();
  2274. value = new AST_Assign({
  2275. start: start,
  2276. left: value,
  2277. operator: "=",
  2278. right: expression(false),
  2279. logical: false,
  2280. end: prev()
  2281. });
  2282. }
  2283. // Create property
  2284. const kv = new AST_ObjectKeyVal({
  2285. start: start,
  2286. quote: start.quote,
  2287. key: name instanceof AST_Node ? name : "" + name,
  2288. value: value,
  2289. end: prev()
  2290. });
  2291. a.push(annotate(kv));
  2292. }
  2293. next();
  2294. return new AST_Object({ properties: a });
  2295. });
  2296. function class_(KindOfClass, is_export_default) {
  2297. var start, method, class_name, extends_, a = [];
  2298. S.input.push_directives_stack(); // Push directive stack, but not scope stack
  2299. S.input.add_directive("use strict");
  2300. if (S.token.type == "name" && S.token.value != "extends") {
  2301. class_name = as_symbol(KindOfClass === AST_DefClass ? AST_SymbolDefClass : AST_SymbolClass);
  2302. }
  2303. if (KindOfClass === AST_DefClass && !class_name) {
  2304. if (is_export_default) {
  2305. KindOfClass = AST_ClassExpression;
  2306. } else {
  2307. unexpected();
  2308. }
  2309. }
  2310. if (S.token.value == "extends") {
  2311. next();
  2312. extends_ = expression(true);
  2313. }
  2314. expect("{");
  2315. // mark in class feild,
  2316. const save_in_class = S.in_class;
  2317. S.in_class = true;
  2318. while (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies.
  2319. while (!is("punc", "}")) {
  2320. start = S.token;
  2321. method = concise_method_or_getset(as_property_name(), start, true);
  2322. if (!method) { unexpected(); }
  2323. a.push(method);
  2324. while (is("punc", ";")) { next(); }
  2325. }
  2326. // mark in class feild,
  2327. S.in_class = save_in_class;
  2328. S.input.pop_directives_stack();
  2329. next();
  2330. return new KindOfClass({
  2331. start: start,
  2332. name: class_name,
  2333. extends: extends_,
  2334. properties: a,
  2335. end: prev(),
  2336. });
  2337. }
  2338. function concise_method_or_getset(name, start, is_class) {
  2339. const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => {
  2340. if (typeof name === "string" || typeof name === "number") {
  2341. return new SymbolClass({
  2342. start,
  2343. name: "" + name,
  2344. end: prev()
  2345. });
  2346. } else if (name === null) {
  2347. unexpected();
  2348. }
  2349. return name;
  2350. };
  2351. const is_not_method_start = () =>
  2352. !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("punc", ";") && !is("operator", "=");
  2353. var is_async = false;
  2354. var is_static = false;
  2355. var is_generator = false;
  2356. var is_private = false;
  2357. var accessor_type = null;
  2358. if (is_class && name === "static" && is_not_method_start()) {
  2359. const static_block = class_static_block();
  2360. if (static_block != null) {
  2361. return static_block;
  2362. }
  2363. is_static = true;
  2364. name = as_property_name();
  2365. }
  2366. if (name === "async" && is_not_method_start()) {
  2367. is_async = true;
  2368. name = as_property_name();
  2369. }
  2370. if (prev().type === "operator" && prev().value === "*") {
  2371. is_generator = true;
  2372. name = as_property_name();
  2373. }
  2374. if ((name === "get" || name === "set") && is_not_method_start()) {
  2375. accessor_type = name;
  2376. name = as_property_name();
  2377. }
  2378. if (prev().type === "privatename") {
  2379. is_private = true;
  2380. }
  2381. const property_token = prev();
  2382. if (accessor_type != null) {
  2383. if (!is_private) {
  2384. const AccessorClass = accessor_type === "get"
  2385. ? AST_ObjectGetter
  2386. : AST_ObjectSetter;
  2387. name = get_symbol_ast(name);
  2388. return annotate(new AccessorClass({
  2389. start,
  2390. static: is_static,
  2391. key: name,
  2392. quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined,
  2393. value: create_accessor(),
  2394. end: prev()
  2395. }));
  2396. } else {
  2397. const AccessorClass = accessor_type === "get"
  2398. ? AST_PrivateGetter
  2399. : AST_PrivateSetter;
  2400. return annotate(new AccessorClass({
  2401. start,
  2402. static: is_static,
  2403. key: get_symbol_ast(name),
  2404. value: create_accessor(),
  2405. end: prev(),
  2406. }));
  2407. }
  2408. }
  2409. if (is("punc", "(")) {
  2410. name = get_symbol_ast(name);
  2411. const AST_MethodVariant = is_private
  2412. ? AST_PrivateMethod
  2413. : AST_ConciseMethod;
  2414. var node = new AST_MethodVariant({
  2415. start : start,
  2416. static : is_static,
  2417. is_generator: is_generator,
  2418. async : is_async,
  2419. key : name,
  2420. quote : name instanceof AST_SymbolMethod ?
  2421. property_token.quote : undefined,
  2422. value : create_accessor(is_generator, is_async),
  2423. end : prev()
  2424. });
  2425. return annotate(node);
  2426. }
  2427. if (is_class) {
  2428. const key = get_symbol_ast(name, AST_SymbolClassProperty);
  2429. const quote = key instanceof AST_SymbolClassProperty
  2430. ? property_token.quote
  2431. : undefined;
  2432. const AST_ClassPropertyVariant = is_private
  2433. ? AST_ClassPrivateProperty
  2434. : AST_ClassProperty;
  2435. if (is("operator", "=")) {
  2436. next();
  2437. return annotate(
  2438. new AST_ClassPropertyVariant({
  2439. start,
  2440. static: is_static,
  2441. quote,
  2442. key,
  2443. value: expression(false),
  2444. end: prev()
  2445. })
  2446. );
  2447. } else if (
  2448. is("name")
  2449. || is("privatename")
  2450. || is("operator", "*")
  2451. || is("punc", ";")
  2452. || is("punc", "}")
  2453. ) {
  2454. return annotate(
  2455. new AST_ClassPropertyVariant({
  2456. start,
  2457. static: is_static,
  2458. quote,
  2459. key,
  2460. end: prev()
  2461. })
  2462. );
  2463. }
  2464. }
  2465. }
  2466. function class_static_block() {
  2467. if (!is("punc", "{")) {
  2468. return null;
  2469. }
  2470. const start = S.token;
  2471. const body = [];
  2472. next();
  2473. while (!is("punc", "}")) {
  2474. body.push(statement());
  2475. }
  2476. next();
  2477. return new AST_ClassStaticBlock({ start, body, end: prev() });
  2478. }
  2479. function maybe_import_assertion() {
  2480. if (is("name", "assert") && !has_newline_before(S.token)) {
  2481. next();
  2482. return object_or_destructuring_();
  2483. }
  2484. return null;
  2485. }
  2486. function import_statement() {
  2487. var start = prev();
  2488. var imported_name;
  2489. var imported_names;
  2490. if (is("name")) {
  2491. imported_name = as_symbol(AST_SymbolImport);
  2492. }
  2493. if (is("punc", ",")) {
  2494. next();
  2495. }
  2496. imported_names = map_names(true);
  2497. if (imported_names || imported_name) {
  2498. expect_token("name", "from");
  2499. }
  2500. var mod_str = S.token;
  2501. if (mod_str.type !== "string") {
  2502. unexpected();
  2503. }
  2504. next();
  2505. const assert_clause = maybe_import_assertion();
  2506. return new AST_Import({
  2507. start,
  2508. imported_name,
  2509. imported_names,
  2510. module_name: new AST_String({
  2511. start: mod_str,
  2512. value: mod_str.value,
  2513. quote: mod_str.quote,
  2514. end: mod_str,
  2515. }),
  2516. assert_clause,
  2517. end: S.token,
  2518. });
  2519. }
  2520. function import_meta(allow_calls) {
  2521. var start = S.token;
  2522. expect_token("name", "import");
  2523. expect_token("punc", ".");
  2524. expect_token("name", "meta");
  2525. return subscripts(new AST_ImportMeta({
  2526. start: start,
  2527. end: prev()
  2528. }), allow_calls);
  2529. }
  2530. function map_name(is_import) {
  2531. function make_symbol(type, quote) {
  2532. return new type({
  2533. name: as_property_name(),
  2534. quote: quote || undefined,
  2535. start: prev(),
  2536. end: prev()
  2537. });
  2538. }
  2539. var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;
  2540. var type = is_import ? AST_SymbolImport : AST_SymbolExport;
  2541. var start = S.token;
  2542. var foreign_name;
  2543. var name;
  2544. if (is_import) {
  2545. foreign_name = make_symbol(foreign_type, start.quote);
  2546. } else {
  2547. name = make_symbol(type, start.quote);
  2548. }
  2549. if (is("name", "as")) {
  2550. next(); // The "as" word
  2551. if (is_import) {
  2552. name = make_symbol(type);
  2553. } else {
  2554. foreign_name = make_symbol(foreign_type, S.token.quote);
  2555. }
  2556. } else if (is_import) {
  2557. name = new type(foreign_name);
  2558. } else {
  2559. foreign_name = new foreign_type(name);
  2560. }
  2561. return new AST_NameMapping({
  2562. start: start,
  2563. foreign_name: foreign_name,
  2564. name: name,
  2565. end: prev(),
  2566. });
  2567. }
  2568. function map_nameAsterisk(is_import, import_or_export_foreign_name) {
  2569. var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign;
  2570. var type = is_import ? AST_SymbolImport : AST_SymbolExport;
  2571. var start = S.token;
  2572. var name, foreign_name;
  2573. var end = prev();
  2574. if (is_import) {
  2575. name = import_or_export_foreign_name;
  2576. } else {
  2577. foreign_name = import_or_export_foreign_name;
  2578. }
  2579. name = name || new type({
  2580. start: start,
  2581. name: "*",
  2582. end: end,
  2583. });
  2584. foreign_name = foreign_name || new foreign_type({
  2585. start: start,
  2586. name: "*",
  2587. end: end,
  2588. });
  2589. return new AST_NameMapping({
  2590. start: start,
  2591. foreign_name: foreign_name,
  2592. name: name,
  2593. end: end,
  2594. });
  2595. }
  2596. function map_names(is_import) {
  2597. var names;
  2598. if (is("punc", "{")) {
  2599. next();
  2600. names = [];
  2601. while (!is("punc", "}")) {
  2602. names.push(map_name(is_import));
  2603. if (is("punc", ",")) {
  2604. next();
  2605. }
  2606. }
  2607. next();
  2608. } else if (is("operator", "*")) {
  2609. var name;
  2610. next();
  2611. if (is("name", "as")) {
  2612. next(); // The "as" word
  2613. name = is_import ? as_symbol(AST_SymbolImport) : as_symbol_or_string(AST_SymbolExportForeign);
  2614. }
  2615. names = [map_nameAsterisk(is_import, name)];
  2616. }
  2617. return names;
  2618. }
  2619. function export_statement() {
  2620. var start = S.token;
  2621. var is_default;
  2622. var exported_names;
  2623. if (is("keyword", "default")) {
  2624. is_default = true;
  2625. next();
  2626. } else if (exported_names = map_names(false)) {
  2627. if (is("name", "from")) {
  2628. next();
  2629. var mod_str = S.token;
  2630. if (mod_str.type !== "string") {
  2631. unexpected();
  2632. }
  2633. next();
  2634. const assert_clause = maybe_import_assertion();
  2635. return new AST_Export({
  2636. start: start,
  2637. is_default: is_default,
  2638. exported_names: exported_names,
  2639. module_name: new AST_String({
  2640. start: mod_str,
  2641. value: mod_str.value,
  2642. quote: mod_str.quote,
  2643. end: mod_str,
  2644. }),
  2645. end: prev(),
  2646. assert_clause
  2647. });
  2648. } else {
  2649. return new AST_Export({
  2650. start: start,
  2651. is_default: is_default,
  2652. exported_names: exported_names,
  2653. end: prev(),
  2654. });
  2655. }
  2656. }
  2657. var node;
  2658. var exported_value;
  2659. var exported_definition;
  2660. if (is("punc", "{")
  2661. || is_default
  2662. && (is("keyword", "class") || is("keyword", "function"))
  2663. && is_token(peek(), "punc")) {
  2664. exported_value = expression(false);
  2665. semicolon();
  2666. } else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
  2667. unexpected(node.start);
  2668. } else if (
  2669. node instanceof AST_Definitions
  2670. || node instanceof AST_Defun
  2671. || node instanceof AST_DefClass
  2672. ) {
  2673. exported_definition = node;
  2674. } else if (
  2675. node instanceof AST_ClassExpression
  2676. || node instanceof AST_Function
  2677. ) {
  2678. exported_value = node;
  2679. } else if (node instanceof AST_SimpleStatement) {
  2680. exported_value = node.body;
  2681. } else {
  2682. unexpected(node.start);
  2683. }
  2684. return new AST_Export({
  2685. start: start,
  2686. is_default: is_default,
  2687. exported_value: exported_value,
  2688. exported_definition: exported_definition,
  2689. end: prev(),
  2690. assert_clause: null
  2691. });
  2692. }
  2693. function as_property_name() {
  2694. var tmp = S.token;
  2695. switch (tmp.type) {
  2696. case "punc":
  2697. if (tmp.value === "[") {
  2698. next();
  2699. var ex = expression(false);
  2700. expect("]");
  2701. return ex;
  2702. } else unexpected(tmp);
  2703. case "operator":
  2704. if (tmp.value === "*") {
  2705. next();
  2706. return null;
  2707. }
  2708. if (!["delete", "in", "instanceof", "new", "typeof", "void"].includes(tmp.value)) {
  2709. unexpected(tmp);
  2710. }
  2711. /* falls through */
  2712. case "name":
  2713. case "privatename":
  2714. case "string":
  2715. case "num":
  2716. case "big_int":
  2717. case "keyword":
  2718. case "atom":
  2719. next();
  2720. return tmp.value;
  2721. default:
  2722. unexpected(tmp);
  2723. }
  2724. }
  2725. function as_name() {
  2726. var tmp = S.token;
  2727. if (tmp.type != "name" && tmp.type != "privatename") unexpected();
  2728. next();
  2729. return tmp.value;
  2730. }
  2731. function _make_symbol(type) {
  2732. var name = S.token.value;
  2733. return new (name == "this" ? AST_This :
  2734. name == "super" ? AST_Super :
  2735. type)({
  2736. name : String(name),
  2737. start : S.token,
  2738. end : S.token
  2739. });
  2740. }
  2741. function _verify_symbol(sym) {
  2742. var name = sym.name;
  2743. if (is_in_generator() && name == "yield") {
  2744. token_error(sym.start, "Yield cannot be used as identifier inside generators");
  2745. }
  2746. if (S.input.has_directive("use strict")) {
  2747. if (name == "yield") {
  2748. token_error(sym.start, "Unexpected yield identifier inside strict mode");
  2749. }
  2750. if (sym instanceof AST_SymbolDeclaration && (name == "arguments" || name == "eval")) {
  2751. token_error(sym.start, "Unexpected " + name + " in strict mode");
  2752. }
  2753. }
  2754. }
  2755. function as_symbol(type, noerror) {
  2756. if (!is("name")) {
  2757. if (!noerror) croak("Name expected");
  2758. return null;
  2759. }
  2760. var sym = _make_symbol(type);
  2761. _verify_symbol(sym);
  2762. next();
  2763. return sym;
  2764. }
  2765. function as_symbol_or_string(type) {
  2766. if (!is("name")) {
  2767. if (!is("string")) {
  2768. croak("Name or string expected");
  2769. }
  2770. var tok = S.token;
  2771. var ret = new type({
  2772. start : tok,
  2773. end : tok,
  2774. name : tok.value,
  2775. quote : tok.quote
  2776. });
  2777. next();
  2778. return ret;
  2779. }
  2780. var sym = _make_symbol(type);
  2781. _verify_symbol(sym);
  2782. next();
  2783. return sym;
  2784. }
  2785. // Annotate AST_Call, AST_Lambda or AST_New with the special comments
  2786. function annotate(node, before_token = node.start) {
  2787. var comments = before_token.comments_before;
  2788. const comments_outside_parens = outer_comments_before_counts.get(before_token);
  2789. var i = comments_outside_parens != null ? comments_outside_parens : comments.length;
  2790. while (--i >= 0) {
  2791. var comment = comments[i];
  2792. if (/[@#]__/.test(comment.value)) {
  2793. if (/[@#]__PURE__/.test(comment.value)) {
  2794. set_annotation(node, _PURE);
  2795. break;
  2796. }
  2797. if (/[@#]__INLINE__/.test(comment.value)) {
  2798. set_annotation(node, _INLINE);
  2799. break;
  2800. }
  2801. if (/[@#]__NOINLINE__/.test(comment.value)) {
  2802. set_annotation(node, _NOINLINE);
  2803. break;
  2804. }
  2805. if (/[@#]__KEY__/.test(comment.value)) {
  2806. set_annotation(node, _KEY);
  2807. break;
  2808. }
  2809. if (/[@#]__MANGLE_PROP__/.test(comment.value)) {
  2810. set_annotation(node, _MANGLEPROP);
  2811. break;
  2812. }
  2813. }
  2814. }
  2815. return node;
  2816. }
  2817. var subscripts = function(expr, allow_calls, is_chain) {
  2818. var start = expr.start;
  2819. if (is("punc", ".")) {
  2820. next();
  2821. if(is("privatename") && !S.in_class)
  2822. croak("Private field must be used in an enclosing class");
  2823. const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
  2824. return annotate(subscripts(new AST_DotVariant({
  2825. start : start,
  2826. expression : expr,
  2827. optional : false,
  2828. property : as_name(),
  2829. end : prev()
  2830. }), allow_calls, is_chain));
  2831. }
  2832. if (is("punc", "[")) {
  2833. next();
  2834. var prop = expression(true);
  2835. expect("]");
  2836. return annotate(subscripts(new AST_Sub({
  2837. start : start,
  2838. expression : expr,
  2839. optional : false,
  2840. property : prop,
  2841. end : prev()
  2842. }), allow_calls, is_chain));
  2843. }
  2844. if (allow_calls && is("punc", "(")) {
  2845. next();
  2846. var call = new AST_Call({
  2847. start : start,
  2848. expression : expr,
  2849. optional : false,
  2850. args : call_args(),
  2851. end : prev()
  2852. });
  2853. annotate(call);
  2854. return subscripts(call, true, is_chain);
  2855. }
  2856. if (is("punc", "?.")) {
  2857. next();
  2858. let chain_contents;
  2859. if (allow_calls && is("punc", "(")) {
  2860. next();
  2861. const call = new AST_Call({
  2862. start,
  2863. optional: true,
  2864. expression: expr,
  2865. args: call_args(),
  2866. end: prev()
  2867. });
  2868. annotate(call);
  2869. chain_contents = subscripts(call, true, true);
  2870. } else if (is("name") || is("privatename")) {
  2871. if(is("privatename") && !S.in_class)
  2872. croak("Private field must be used in an enclosing class");
  2873. const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
  2874. chain_contents = annotate(subscripts(new AST_DotVariant({
  2875. start,
  2876. expression: expr,
  2877. optional: true,
  2878. property: as_name(),
  2879. end: prev()
  2880. }), allow_calls, true));
  2881. } else if (is("punc", "[")) {
  2882. next();
  2883. const property = expression(true);
  2884. expect("]");
  2885. chain_contents = annotate(subscripts(new AST_Sub({
  2886. start,
  2887. expression: expr,
  2888. optional: true,
  2889. property,
  2890. end: prev()
  2891. }), allow_calls, true));
  2892. }
  2893. if (!chain_contents) unexpected();
  2894. if (chain_contents instanceof AST_Chain) return chain_contents;
  2895. return new AST_Chain({
  2896. start,
  2897. expression: chain_contents,
  2898. end: prev()
  2899. });
  2900. }
  2901. if (is("template_head")) {
  2902. if (is_chain) {
  2903. // a?.b`c` is a syntax error
  2904. unexpected();
  2905. }
  2906. return subscripts(new AST_PrefixedTemplateString({
  2907. start: start,
  2908. prefix: expr,
  2909. template_string: template_string(),
  2910. end: prev()
  2911. }), allow_calls);
  2912. }
  2913. return expr;
  2914. };
  2915. function call_args() {
  2916. var args = [];
  2917. while (!is("punc", ")")) {
  2918. if (is("expand", "...")) {
  2919. next();
  2920. args.push(new AST_Expansion({
  2921. start: prev(),
  2922. expression: expression(false),
  2923. end: prev()
  2924. }));
  2925. } else {
  2926. args.push(expression(false));
  2927. }
  2928. if (!is("punc", ")")) {
  2929. expect(",");
  2930. }
  2931. }
  2932. next();
  2933. return args;
  2934. }
  2935. var maybe_unary = function(allow_calls, allow_arrows) {
  2936. var start = S.token;
  2937. if (start.type == "name" && start.value == "await" && can_await()) {
  2938. next();
  2939. return _await_expression();
  2940. }
  2941. if (is("operator") && UNARY_PREFIX.has(start.value)) {
  2942. next();
  2943. handle_regexp();
  2944. var ex = make_unary(AST_UnaryPrefix, start, maybe_unary(allow_calls));
  2945. ex.start = start;
  2946. ex.end = prev();
  2947. return ex;
  2948. }
  2949. var val = expr_atom(allow_calls, allow_arrows);
  2950. while (is("operator") && UNARY_POSTFIX.has(S.token.value) && !has_newline_before(S.token)) {
  2951. if (val instanceof AST_Arrow) unexpected();
  2952. val = make_unary(AST_UnaryPostfix, S.token, val);
  2953. val.start = start;
  2954. val.end = S.token;
  2955. next();
  2956. }
  2957. return val;
  2958. };
  2959. function make_unary(ctor, token, expr) {
  2960. var op = token.value;
  2961. switch (op) {
  2962. case "++":
  2963. case "--":
  2964. if (!is_assignable(expr))
  2965. croak("Invalid use of " + op + " operator", token.line, token.col, token.pos);
  2966. break;
  2967. case "delete":
  2968. if (expr instanceof AST_SymbolRef && S.input.has_directive("use strict"))
  2969. croak("Calling delete on expression not allowed in strict mode", expr.start.line, expr.start.col, expr.start.pos);
  2970. break;
  2971. }
  2972. return new ctor({ operator: op, expression: expr });
  2973. }
  2974. var expr_op = function(left, min_prec, no_in) {
  2975. var op = is("operator") ? S.token.value : null;
  2976. if (op == "in" && no_in) op = null;
  2977. if (op == "**" && left instanceof AST_UnaryPrefix
  2978. /* unary token in front not allowed - parenthesis required */
  2979. && !is_token(left.start, "punc", "(")
  2980. && left.operator !== "--" && left.operator !== "++")
  2981. unexpected(left.start);
  2982. var prec = op != null ? PRECEDENCE[op] : null;
  2983. if (prec != null && (prec > min_prec || (op === "**" && min_prec === prec))) {
  2984. next();
  2985. var right = expr_ops(no_in, prec, true);
  2986. return expr_op(new AST_Binary({
  2987. start : left.start,
  2988. left : left,
  2989. operator : op,
  2990. right : right,
  2991. end : right.end
  2992. }), min_prec, no_in);
  2993. }
  2994. return left;
  2995. };
  2996. function expr_ops(no_in, min_prec, allow_calls, allow_arrows) {
  2997. // maybe_unary won't return us a AST_SymbolPrivateProperty
  2998. if (!no_in && min_prec < PRECEDENCE["in"] && is("privatename")) {
  2999. if(!S.in_class) {
  3000. croak("Private field must be used in an enclosing class");
  3001. }
  3002. const start = S.token;
  3003. const key = new AST_SymbolPrivateProperty({
  3004. start,
  3005. name: start.value,
  3006. end: start
  3007. });
  3008. next();
  3009. expect_token("operator", "in");
  3010. const private_in = new AST_PrivateIn({
  3011. start,
  3012. key,
  3013. value: expr_ops(no_in, PRECEDENCE["in"], true),
  3014. end: prev()
  3015. });
  3016. return expr_op(private_in, 0, no_in);
  3017. } else {
  3018. return expr_op(maybe_unary(allow_calls, allow_arrows), min_prec, no_in);
  3019. }
  3020. }
  3021. var maybe_conditional = function(no_in) {
  3022. var start = S.token;
  3023. var expr = expr_ops(no_in, 0, true, true);
  3024. if (is("operator", "?")) {
  3025. next();
  3026. var yes = expression(false);
  3027. expect(":");
  3028. return new AST_Conditional({
  3029. start : start,
  3030. condition : expr,
  3031. consequent : yes,
  3032. alternative : expression(false, no_in),
  3033. end : prev()
  3034. });
  3035. }
  3036. return expr;
  3037. };
  3038. function is_assignable(expr) {
  3039. return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef;
  3040. }
  3041. function to_destructuring(node) {
  3042. if (node instanceof AST_Object) {
  3043. node = new AST_Destructuring({
  3044. start: node.start,
  3045. names: node.properties.map(to_destructuring),
  3046. is_array: false,
  3047. end: node.end
  3048. });
  3049. } else if (node instanceof AST_Array) {
  3050. var names = [];
  3051. for (var i = 0; i < node.elements.length; i++) {
  3052. // Only allow expansion as last element
  3053. if (node.elements[i] instanceof AST_Expansion) {
  3054. if (i + 1 !== node.elements.length) {
  3055. token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
  3056. }
  3057. node.elements[i].expression = to_destructuring(node.elements[i].expression);
  3058. }
  3059. names.push(to_destructuring(node.elements[i]));
  3060. }
  3061. node = new AST_Destructuring({
  3062. start: node.start,
  3063. names: names,
  3064. is_array: true,
  3065. end: node.end
  3066. });
  3067. } else if (node instanceof AST_ObjectProperty) {
  3068. node.value = to_destructuring(node.value);
  3069. } else if (node instanceof AST_Assign) {
  3070. node = new AST_DefaultAssign({
  3071. start: node.start,
  3072. left: node.left,
  3073. operator: "=",
  3074. right: node.right,
  3075. end: node.end
  3076. });
  3077. }
  3078. return node;
  3079. }
  3080. // In ES6, AssignmentExpression can also be an ArrowFunction
  3081. var maybe_assign = function(no_in) {
  3082. handle_regexp();
  3083. var start = S.token;
  3084. if (start.type == "name" && start.value == "yield") {
  3085. if (is_in_generator()) {
  3086. next();
  3087. return _yield_expression();
  3088. } else if (S.input.has_directive("use strict")) {
  3089. token_error(S.token, "Unexpected yield identifier inside strict mode");
  3090. }
  3091. }
  3092. var left = maybe_conditional(no_in);
  3093. var val = S.token.value;
  3094. if (is("operator") && ASSIGNMENT.has(val)) {
  3095. if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {
  3096. next();
  3097. return new AST_Assign({
  3098. start : start,
  3099. left : left,
  3100. operator : val,
  3101. right : maybe_assign(no_in),
  3102. logical : LOGICAL_ASSIGNMENT.has(val),
  3103. end : prev()
  3104. });
  3105. }
  3106. croak("Invalid assignment");
  3107. }
  3108. return left;
  3109. };
  3110. var to_expr_or_sequence = function(start, exprs) {
  3111. if (exprs.length === 1) {
  3112. return exprs[0];
  3113. } else if (exprs.length > 1) {
  3114. return new AST_Sequence({ start, expressions: exprs, end: peek() });
  3115. } else {
  3116. croak("Invalid parenthesized expression");
  3117. }
  3118. };
  3119. var expression = function(commas, no_in) {
  3120. var start = S.token;
  3121. var exprs = [];
  3122. while (true) {
  3123. exprs.push(maybe_assign(no_in));
  3124. if (!commas || !is("punc", ",")) break;
  3125. next();
  3126. commas = true;
  3127. }
  3128. return to_expr_or_sequence(start, exprs);
  3129. };
  3130. function in_loop(cont) {
  3131. ++S.in_loop;
  3132. var ret = cont();
  3133. --S.in_loop;
  3134. return ret;
  3135. }
  3136. if (options.expression) {
  3137. return expression(true);
  3138. }
  3139. return (function parse_toplevel() {
  3140. var start = S.token;
  3141. var body = [];
  3142. S.input.push_directives_stack();
  3143. if (options.module) S.input.add_directive("use strict");
  3144. while (!is("eof")) {
  3145. body.push(statement());
  3146. }
  3147. S.input.pop_directives_stack();
  3148. var end = prev();
  3149. var toplevel = options.toplevel;
  3150. if (toplevel) {
  3151. toplevel.body = toplevel.body.concat(body);
  3152. toplevel.end = end;
  3153. } else {
  3154. toplevel = new AST_Toplevel({ start: start, body: body, end: end });
  3155. }
  3156. TEMPLATE_RAWS = new Map();
  3157. return toplevel;
  3158. })();
  3159. }
  3160. export {
  3161. get_full_char_code,
  3162. get_full_char,
  3163. is_identifier_char,
  3164. is_basic_identifier_string,
  3165. is_identifier_string,
  3166. is_surrogate_pair_head,
  3167. is_surrogate_pair_tail,
  3168. js_error,
  3169. JS_Parse_Error,
  3170. parse,
  3171. PRECEDENCE,
  3172. ALL_RESERVED_WORDS,
  3173. tokenizer,
  3174. };