index.js 148 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(r, e) {
  6. if (null == r) return {};
  7. var t = {};
  8. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  9. if (e.includes(n)) continue;
  10. t[n] = r[n];
  11. }
  12. return t;
  13. }
  14. class Position {
  15. constructor(line, col, index) {
  16. this.line = void 0;
  17. this.column = void 0;
  18. this.index = void 0;
  19. this.line = line;
  20. this.column = col;
  21. this.index = index;
  22. }
  23. }
  24. class SourceLocation {
  25. constructor(start, end) {
  26. this.start = void 0;
  27. this.end = void 0;
  28. this.filename = void 0;
  29. this.identifierName = void 0;
  30. this.start = start;
  31. this.end = end;
  32. }
  33. }
  34. function createPositionWithColumnOffset(position, columnOffset) {
  35. const {
  36. line,
  37. column,
  38. index
  39. } = position;
  40. return new Position(line, column + columnOffset, index + columnOffset);
  41. }
  42. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  43. var ModuleErrors = {
  44. ImportMetaOutsideModule: {
  45. message: `import.meta may appear only with 'sourceType: "module"'`,
  46. code
  47. },
  48. ImportOutsideModule: {
  49. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  50. code
  51. }
  52. };
  53. const NodeDescriptions = {
  54. ArrayPattern: "array destructuring pattern",
  55. AssignmentExpression: "assignment expression",
  56. AssignmentPattern: "assignment expression",
  57. ArrowFunctionExpression: "arrow function expression",
  58. ConditionalExpression: "conditional expression",
  59. CatchClause: "catch clause",
  60. ForOfStatement: "for-of statement",
  61. ForInStatement: "for-in statement",
  62. ForStatement: "for-loop",
  63. FormalParameters: "function parameter list",
  64. Identifier: "identifier",
  65. ImportSpecifier: "import specifier",
  66. ImportDefaultSpecifier: "import default specifier",
  67. ImportNamespaceSpecifier: "import namespace specifier",
  68. ObjectPattern: "object destructuring pattern",
  69. ParenthesizedExpression: "parenthesized expression",
  70. RestElement: "rest element",
  71. UpdateExpression: {
  72. true: "prefix operation",
  73. false: "postfix operation"
  74. },
  75. VariableDeclarator: "variable declaration",
  76. YieldExpression: "yield expression"
  77. };
  78. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  79. var StandardErrors = {
  80. AccessorIsGenerator: ({
  81. kind
  82. }) => `A ${kind}ter cannot be a generator.`,
  83. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  84. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  85. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  86. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  87. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  88. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  89. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  90. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  91. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  92. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  93. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  94. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  95. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  96. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  97. ConstructorIsAsync: "Constructor can't be an async function.",
  98. ConstructorIsGenerator: "Constructor can't be a generator.",
  99. DeclarationMissingInitializer: ({
  100. kind
  101. }) => `Missing initializer in ${kind} declaration.`,
  102. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  103. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  104. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  105. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  106. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  107. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  108. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  109. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  110. DeletePrivateField: "Deleting a private field is not allowed.",
  111. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  112. DuplicateConstructor: "Duplicate constructor in the same class.",
  113. DuplicateDefaultExport: "Only one default export allowed per module.",
  114. DuplicateExport: ({
  115. exportName
  116. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  117. DuplicateProto: "Redefinition of __proto__ property.",
  118. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  119. DynamicImportPhaseRequiresImportExpressions: ({
  120. phase
  121. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  122. ElementAfterRest: "Rest element must be last element.",
  123. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  124. ExportBindingIsString: ({
  125. localName,
  126. exportName
  127. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  128. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  129. ForInOfLoopInitializer: ({
  130. type
  131. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  132. ForInUsing: "For-in loop may not start with 'using' declaration.",
  133. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  134. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  135. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  136. IllegalBreakContinue: ({
  137. type
  138. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  139. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  140. IllegalReturn: "'return' outside of function.",
  141. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedImportAssert` parser plugin to suppress this error.",
  142. ImportBindingIsString: ({
  143. importName
  144. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  145. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  146. ImportCallNotNewExpression: "Cannot use new with import(...).",
  147. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  148. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  149. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  150. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  151. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  152. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  153. InvalidCodePoint: "Code point out of bounds.",
  154. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  155. InvalidDecimal: "Invalid decimal.",
  156. InvalidDigit: ({
  157. radix
  158. }) => `Expected number in radix ${radix}.`,
  159. InvalidEscapeSequence: "Bad character escape sequence.",
  160. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  161. InvalidEscapedReservedWord: ({
  162. reservedWord
  163. }) => `Escape sequence in keyword ${reservedWord}.`,
  164. InvalidIdentifier: ({
  165. identifierName
  166. }) => `Invalid identifier ${identifierName}.`,
  167. InvalidLhs: ({
  168. ancestor
  169. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  170. InvalidLhsBinding: ({
  171. ancestor
  172. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  173. InvalidLhsOptionalChaining: ({
  174. ancestor
  175. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  176. InvalidNumber: "Invalid number.",
  177. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  178. InvalidOrUnexpectedToken: ({
  179. unexpected
  180. }) => `Unexpected character '${unexpected}'.`,
  181. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  182. InvalidPrivateFieldResolution: ({
  183. identifierName
  184. }) => `Private name #${identifierName} is not defined.`,
  185. InvalidPropertyBindingPattern: "Binding member expression.",
  186. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  187. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  188. LabelRedeclaration: ({
  189. labelName
  190. }) => `Label '${labelName}' is already declared.`,
  191. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  192. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  193. MalformedRegExpFlags: "Invalid regular expression flag.",
  194. MissingClassName: "A class name is required.",
  195. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  196. MissingSemicolon: "Missing semicolon.",
  197. MissingPlugin: ({
  198. missingPlugin
  199. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  200. MissingOneOfPlugins: ({
  201. missingPlugin
  202. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  203. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  204. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  205. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  206. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  207. ModuleAttributesWithDuplicateKeys: ({
  208. key
  209. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  210. ModuleExportNameHasLoneSurrogate: ({
  211. surrogateCharCode
  212. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  213. ModuleExportUndefined: ({
  214. localName
  215. }) => `Export '${localName}' is not defined.`,
  216. MultipleDefaultsInSwitch: "Multiple default clauses.",
  217. NewlineAfterThrow: "Illegal newline after throw.",
  218. NoCatchOrFinally: "Missing catch or finally clause.",
  219. NumberIdentifier: "Identifier directly after number.",
  220. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  221. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  222. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  223. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  224. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  225. ParamDupe: "Argument name clash.",
  226. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  227. PatternHasMethod: "Object pattern can't contain methods.",
  228. PrivateInExpectedIn: ({
  229. identifierName
  230. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  231. PrivateNameRedeclaration: ({
  232. identifierName
  233. }) => `Duplicate private name #${identifierName}.`,
  234. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  235. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  236. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  237. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  238. RestTrailingComma: "Unexpected trailing comma after rest element.",
  239. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  240. SloppyFunctionAnnexB: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.",
  241. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  242. StaticPrototype: "Classes may not have static property named prototype.",
  243. SuperNotAllowed: "`super()` is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?",
  244. SuperPrivateField: "Private fields can't be accessed on super.",
  245. TrailingDecorator: "Decorators must be attached to a class element.",
  246. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  247. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  248. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  249. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  250. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  251. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  252. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  253. UnexpectedKeyword: ({
  254. keyword
  255. }) => `Unexpected keyword '${keyword}'.`,
  256. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  257. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  258. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  259. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  260. UnexpectedPrivateField: "Unexpected private name.",
  261. UnexpectedReservedWord: ({
  262. reservedWord
  263. }) => `Unexpected reserved word '${reservedWord}'.`,
  264. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  265. UnexpectedToken: ({
  266. expected,
  267. unexpected
  268. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  269. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  270. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  271. UnsupportedBind: "Binding should be performed on object property.",
  272. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  273. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  274. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  275. UnsupportedMetaProperty: ({
  276. target,
  277. onlyValidPropertyName
  278. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  279. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  280. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  281. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  282. UnterminatedComment: "Unterminated comment.",
  283. UnterminatedRegExp: "Unterminated regular expression.",
  284. UnterminatedString: "Unterminated string constant.",
  285. UnterminatedTemplate: "Unterminated template.",
  286. UsingDeclarationExport: "Using declaration cannot be exported.",
  287. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  288. VarRedeclaration: ({
  289. identifierName
  290. }) => `Identifier '${identifierName}' has already been declared.`,
  291. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  292. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  293. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  294. };
  295. var StrictModeErrors = {
  296. StrictDelete: "Deleting local variable in strict mode.",
  297. StrictEvalArguments: ({
  298. referenceName
  299. }) => `Assigning to '${referenceName}' in strict mode.`,
  300. StrictEvalArgumentsBinding: ({
  301. bindingName
  302. }) => `Binding '${bindingName}' in strict mode.`,
  303. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  304. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  305. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  306. StrictWith: "'with' in strict mode."
  307. };
  308. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  309. var PipelineOperatorErrors = {
  310. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  311. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  312. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  313. PipeTopicUnconfiguredToken: ({
  314. token
  315. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  316. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  317. PipeUnparenthesizedBody: ({
  318. type
  319. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  320. type
  321. })}; please wrap it in parentheses.`,
  322. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  323. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  324. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  325. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  326. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  327. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  328. };
  329. const _excluded = ["message"];
  330. function defineHidden(obj, key, value) {
  331. Object.defineProperty(obj, key, {
  332. enumerable: false,
  333. configurable: true,
  334. value
  335. });
  336. }
  337. function toParseErrorConstructor({
  338. toMessage,
  339. code,
  340. reasonCode,
  341. syntaxPlugin
  342. }) {
  343. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  344. {
  345. const oldReasonCodes = {
  346. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  347. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  348. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  349. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  350. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  351. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  352. };
  353. if (oldReasonCodes[reasonCode]) {
  354. reasonCode = oldReasonCodes[reasonCode];
  355. }
  356. }
  357. return function constructor(loc, details) {
  358. const error = new SyntaxError();
  359. error.code = code;
  360. error.reasonCode = reasonCode;
  361. error.loc = loc;
  362. error.pos = loc.index;
  363. error.syntaxPlugin = syntaxPlugin;
  364. if (hasMissingPlugin) {
  365. error.missingPlugin = details.missingPlugin;
  366. }
  367. defineHidden(error, "clone", function clone(overrides = {}) {
  368. var _overrides$loc;
  369. const {
  370. line,
  371. column,
  372. index
  373. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  374. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  375. });
  376. defineHidden(error, "details", details);
  377. Object.defineProperty(error, "message", {
  378. configurable: true,
  379. get() {
  380. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  381. this.message = message;
  382. return message;
  383. },
  384. set(value) {
  385. Object.defineProperty(this, "message", {
  386. value,
  387. writable: true
  388. });
  389. }
  390. });
  391. return error;
  392. };
  393. }
  394. function ParseErrorEnum(argument, syntaxPlugin) {
  395. if (Array.isArray(argument)) {
  396. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  397. }
  398. const ParseErrorConstructors = {};
  399. for (const reasonCode of Object.keys(argument)) {
  400. const template = argument[reasonCode];
  401. const _ref = typeof template === "string" ? {
  402. message: () => template
  403. } : typeof template === "function" ? {
  404. message: template
  405. } : template,
  406. {
  407. message
  408. } = _ref,
  409. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  410. const toMessage = typeof message === "string" ? () => message : message;
  411. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  412. code: "BABEL_PARSER_SYNTAX_ERROR",
  413. reasonCode,
  414. toMessage
  415. }, syntaxPlugin ? {
  416. syntaxPlugin
  417. } : {}, rest));
  418. }
  419. return ParseErrorConstructors;
  420. }
  421. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  422. const {
  423. defineProperty
  424. } = Object;
  425. const toUnenumerable = (object, key) => {
  426. if (object) {
  427. defineProperty(object, key, {
  428. enumerable: false,
  429. value: object[key]
  430. });
  431. }
  432. };
  433. function toESTreeLocation(node) {
  434. toUnenumerable(node.loc.start, "index");
  435. toUnenumerable(node.loc.end, "index");
  436. return node;
  437. }
  438. var estree = superClass => class ESTreeParserMixin extends superClass {
  439. parse() {
  440. const file = toESTreeLocation(super.parse());
  441. if (this.options.tokens) {
  442. file.tokens = file.tokens.map(toESTreeLocation);
  443. }
  444. return file;
  445. }
  446. parseRegExpLiteral({
  447. pattern,
  448. flags
  449. }) {
  450. let regex = null;
  451. try {
  452. regex = new RegExp(pattern, flags);
  453. } catch (_) {}
  454. const node = this.estreeParseLiteral(regex);
  455. node.regex = {
  456. pattern,
  457. flags
  458. };
  459. return node;
  460. }
  461. parseBigIntLiteral(value) {
  462. let bigInt;
  463. try {
  464. bigInt = BigInt(value);
  465. } catch (_unused) {
  466. bigInt = null;
  467. }
  468. const node = this.estreeParseLiteral(bigInt);
  469. node.bigint = String(node.value || value);
  470. return node;
  471. }
  472. parseDecimalLiteral(value) {
  473. const decimal = null;
  474. const node = this.estreeParseLiteral(decimal);
  475. node.decimal = String(node.value || value);
  476. return node;
  477. }
  478. estreeParseLiteral(value) {
  479. return this.parseLiteral(value, "Literal");
  480. }
  481. parseStringLiteral(value) {
  482. return this.estreeParseLiteral(value);
  483. }
  484. parseNumericLiteral(value) {
  485. return this.estreeParseLiteral(value);
  486. }
  487. parseNullLiteral() {
  488. return this.estreeParseLiteral(null);
  489. }
  490. parseBooleanLiteral(value) {
  491. return this.estreeParseLiteral(value);
  492. }
  493. directiveToStmt(directive) {
  494. const expression = directive.value;
  495. delete directive.value;
  496. expression.type = "Literal";
  497. expression.raw = expression.extra.raw;
  498. expression.value = expression.extra.expressionValue;
  499. const stmt = directive;
  500. stmt.type = "ExpressionStatement";
  501. stmt.expression = expression;
  502. stmt.directive = expression.extra.rawValue;
  503. delete expression.extra;
  504. return stmt;
  505. }
  506. initFunction(node, isAsync) {
  507. super.initFunction(node, isAsync);
  508. node.expression = false;
  509. }
  510. checkDeclaration(node) {
  511. if (node != null && this.isObjectProperty(node)) {
  512. this.checkDeclaration(node.value);
  513. } else {
  514. super.checkDeclaration(node);
  515. }
  516. }
  517. getObjectOrClassMethodParams(method) {
  518. return method.value.params;
  519. }
  520. isValidDirective(stmt) {
  521. var _stmt$expression$extr;
  522. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  523. }
  524. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  525. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  526. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  527. node.body = directiveStatements.concat(node.body);
  528. delete node.directives;
  529. }
  530. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  531. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  532. if (method.typeParameters) {
  533. method.value.typeParameters = method.typeParameters;
  534. delete method.typeParameters;
  535. }
  536. classBody.body.push(method);
  537. }
  538. parsePrivateName() {
  539. const node = super.parsePrivateName();
  540. {
  541. if (!this.getPluginOption("estree", "classFeatures")) {
  542. return node;
  543. }
  544. }
  545. return this.convertPrivateNameToPrivateIdentifier(node);
  546. }
  547. convertPrivateNameToPrivateIdentifier(node) {
  548. const name = super.getPrivateNameSV(node);
  549. node = node;
  550. delete node.id;
  551. node.name = name;
  552. node.type = "PrivateIdentifier";
  553. return node;
  554. }
  555. isPrivateName(node) {
  556. {
  557. if (!this.getPluginOption("estree", "classFeatures")) {
  558. return super.isPrivateName(node);
  559. }
  560. }
  561. return node.type === "PrivateIdentifier";
  562. }
  563. getPrivateNameSV(node) {
  564. {
  565. if (!this.getPluginOption("estree", "classFeatures")) {
  566. return super.getPrivateNameSV(node);
  567. }
  568. }
  569. return node.name;
  570. }
  571. parseLiteral(value, type) {
  572. const node = super.parseLiteral(value, type);
  573. node.raw = node.extra.raw;
  574. delete node.extra;
  575. return node;
  576. }
  577. parseFunctionBody(node, allowExpression, isMethod = false) {
  578. super.parseFunctionBody(node, allowExpression, isMethod);
  579. node.expression = node.body.type !== "BlockStatement";
  580. }
  581. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  582. let funcNode = this.startNode();
  583. funcNode.kind = node.kind;
  584. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  585. funcNode.type = "FunctionExpression";
  586. delete funcNode.kind;
  587. node.value = funcNode;
  588. if (type === "ClassPrivateMethod") {
  589. node.computed = false;
  590. }
  591. return this.finishNode(node, "MethodDefinition");
  592. }
  593. nameIsConstructor(key) {
  594. if (key.type === "Literal") return key.value === "constructor";
  595. return super.nameIsConstructor(key);
  596. }
  597. parseClassProperty(...args) {
  598. const propertyNode = super.parseClassProperty(...args);
  599. {
  600. if (!this.getPluginOption("estree", "classFeatures")) {
  601. return propertyNode;
  602. }
  603. }
  604. propertyNode.type = "PropertyDefinition";
  605. return propertyNode;
  606. }
  607. parseClassPrivateProperty(...args) {
  608. const propertyNode = super.parseClassPrivateProperty(...args);
  609. {
  610. if (!this.getPluginOption("estree", "classFeatures")) {
  611. return propertyNode;
  612. }
  613. }
  614. propertyNode.type = "PropertyDefinition";
  615. propertyNode.computed = false;
  616. return propertyNode;
  617. }
  618. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  619. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  620. if (node) {
  621. node.type = "Property";
  622. if (node.kind === "method") {
  623. node.kind = "init";
  624. }
  625. node.shorthand = false;
  626. }
  627. return node;
  628. }
  629. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  630. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  631. if (node) {
  632. node.kind = "init";
  633. node.type = "Property";
  634. }
  635. return node;
  636. }
  637. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  638. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  639. }
  640. isAssignable(node, isBinding) {
  641. if (node != null && this.isObjectProperty(node)) {
  642. return this.isAssignable(node.value, isBinding);
  643. }
  644. return super.isAssignable(node, isBinding);
  645. }
  646. toAssignable(node, isLHS = false) {
  647. if (node != null && this.isObjectProperty(node)) {
  648. const {
  649. key,
  650. value
  651. } = node;
  652. if (this.isPrivateName(key)) {
  653. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  654. }
  655. this.toAssignable(value, isLHS);
  656. } else {
  657. super.toAssignable(node, isLHS);
  658. }
  659. }
  660. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  661. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  662. this.raise(Errors.PatternHasAccessor, prop.key);
  663. } else if (prop.type === "Property" && prop.method) {
  664. this.raise(Errors.PatternHasMethod, prop.key);
  665. } else {
  666. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  667. }
  668. }
  669. finishCallExpression(unfinished, optional) {
  670. const node = super.finishCallExpression(unfinished, optional);
  671. if (node.callee.type === "Import") {
  672. var _ref, _ref2;
  673. node.type = "ImportExpression";
  674. node.source = node.arguments[0];
  675. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  676. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  677. delete node.arguments;
  678. delete node.callee;
  679. }
  680. return node;
  681. }
  682. toReferencedArguments(node) {
  683. if (node.type === "ImportExpression") {
  684. return;
  685. }
  686. super.toReferencedArguments(node);
  687. }
  688. parseExport(unfinished, decorators) {
  689. const exportStartLoc = this.state.lastTokStartLoc;
  690. const node = super.parseExport(unfinished, decorators);
  691. switch (node.type) {
  692. case "ExportAllDeclaration":
  693. node.exported = null;
  694. break;
  695. case "ExportNamedDeclaration":
  696. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  697. node.type = "ExportAllDeclaration";
  698. node.exported = node.specifiers[0].exported;
  699. delete node.specifiers;
  700. }
  701. case "ExportDefaultDeclaration":
  702. {
  703. var _declaration$decorato;
  704. const {
  705. declaration
  706. } = node;
  707. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  708. this.resetStartLocation(node, exportStartLoc);
  709. }
  710. }
  711. break;
  712. }
  713. return node;
  714. }
  715. parseSubscript(base, startLoc, noCalls, state) {
  716. const node = super.parseSubscript(base, startLoc, noCalls, state);
  717. if (state.optionalChainMember) {
  718. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  719. node.type = node.type.substring(8);
  720. }
  721. if (state.stop) {
  722. const chain = this.startNodeAtNode(node);
  723. chain.expression = node;
  724. return this.finishNode(chain, "ChainExpression");
  725. }
  726. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  727. node.optional = false;
  728. }
  729. return node;
  730. }
  731. isOptionalMemberExpression(node) {
  732. if (node.type === "ChainExpression") {
  733. return node.expression.type === "MemberExpression";
  734. }
  735. return super.isOptionalMemberExpression(node);
  736. }
  737. hasPropertyAsPrivateName(node) {
  738. if (node.type === "ChainExpression") {
  739. node = node.expression;
  740. }
  741. return super.hasPropertyAsPrivateName(node);
  742. }
  743. isObjectProperty(node) {
  744. return node.type === "Property" && node.kind === "init" && !node.method;
  745. }
  746. isObjectMethod(node) {
  747. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  748. }
  749. finishNodeAt(node, type, endLoc) {
  750. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  751. }
  752. resetStartLocation(node, startLoc) {
  753. super.resetStartLocation(node, startLoc);
  754. toESTreeLocation(node);
  755. }
  756. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  757. super.resetEndLocation(node, endLoc);
  758. toESTreeLocation(node);
  759. }
  760. };
  761. class TokContext {
  762. constructor(token, preserveSpace) {
  763. this.token = void 0;
  764. this.preserveSpace = void 0;
  765. this.token = token;
  766. this.preserveSpace = !!preserveSpace;
  767. }
  768. }
  769. const types = {
  770. brace: new TokContext("{"),
  771. j_oTag: new TokContext("<tag"),
  772. j_cTag: new TokContext("</tag"),
  773. j_expr: new TokContext("<tag>...</tag>", true)
  774. };
  775. {
  776. types.template = new TokContext("`", true);
  777. }
  778. const beforeExpr = true;
  779. const startsExpr = true;
  780. const isLoop = true;
  781. const isAssign = true;
  782. const prefix = true;
  783. const postfix = true;
  784. class ExportedTokenType {
  785. constructor(label, conf = {}) {
  786. this.label = void 0;
  787. this.keyword = void 0;
  788. this.beforeExpr = void 0;
  789. this.startsExpr = void 0;
  790. this.rightAssociative = void 0;
  791. this.isLoop = void 0;
  792. this.isAssign = void 0;
  793. this.prefix = void 0;
  794. this.postfix = void 0;
  795. this.binop = void 0;
  796. this.label = label;
  797. this.keyword = conf.keyword;
  798. this.beforeExpr = !!conf.beforeExpr;
  799. this.startsExpr = !!conf.startsExpr;
  800. this.rightAssociative = !!conf.rightAssociative;
  801. this.isLoop = !!conf.isLoop;
  802. this.isAssign = !!conf.isAssign;
  803. this.prefix = !!conf.prefix;
  804. this.postfix = !!conf.postfix;
  805. this.binop = conf.binop != null ? conf.binop : null;
  806. {
  807. this.updateContext = null;
  808. }
  809. }
  810. }
  811. const keywords$1 = new Map();
  812. function createKeyword(name, options = {}) {
  813. options.keyword = name;
  814. const token = createToken(name, options);
  815. keywords$1.set(name, token);
  816. return token;
  817. }
  818. function createBinop(name, binop) {
  819. return createToken(name, {
  820. beforeExpr,
  821. binop
  822. });
  823. }
  824. let tokenTypeCounter = -1;
  825. const tokenTypes = [];
  826. const tokenLabels = [];
  827. const tokenBinops = [];
  828. const tokenBeforeExprs = [];
  829. const tokenStartsExprs = [];
  830. const tokenPrefixes = [];
  831. function createToken(name, options = {}) {
  832. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  833. ++tokenTypeCounter;
  834. tokenLabels.push(name);
  835. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  836. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  837. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  838. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  839. tokenTypes.push(new ExportedTokenType(name, options));
  840. return tokenTypeCounter;
  841. }
  842. function createKeywordLike(name, options = {}) {
  843. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  844. ++tokenTypeCounter;
  845. keywords$1.set(name, tokenTypeCounter);
  846. tokenLabels.push(name);
  847. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  848. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  849. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  850. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  851. tokenTypes.push(new ExportedTokenType("name", options));
  852. return tokenTypeCounter;
  853. }
  854. const tt = {
  855. bracketL: createToken("[", {
  856. beforeExpr,
  857. startsExpr
  858. }),
  859. bracketHashL: createToken("#[", {
  860. beforeExpr,
  861. startsExpr
  862. }),
  863. bracketBarL: createToken("[|", {
  864. beforeExpr,
  865. startsExpr
  866. }),
  867. bracketR: createToken("]"),
  868. bracketBarR: createToken("|]"),
  869. braceL: createToken("{", {
  870. beforeExpr,
  871. startsExpr
  872. }),
  873. braceBarL: createToken("{|", {
  874. beforeExpr,
  875. startsExpr
  876. }),
  877. braceHashL: createToken("#{", {
  878. beforeExpr,
  879. startsExpr
  880. }),
  881. braceR: createToken("}"),
  882. braceBarR: createToken("|}"),
  883. parenL: createToken("(", {
  884. beforeExpr,
  885. startsExpr
  886. }),
  887. parenR: createToken(")"),
  888. comma: createToken(",", {
  889. beforeExpr
  890. }),
  891. semi: createToken(";", {
  892. beforeExpr
  893. }),
  894. colon: createToken(":", {
  895. beforeExpr
  896. }),
  897. doubleColon: createToken("::", {
  898. beforeExpr
  899. }),
  900. dot: createToken("."),
  901. question: createToken("?", {
  902. beforeExpr
  903. }),
  904. questionDot: createToken("?."),
  905. arrow: createToken("=>", {
  906. beforeExpr
  907. }),
  908. template: createToken("template"),
  909. ellipsis: createToken("...", {
  910. beforeExpr
  911. }),
  912. backQuote: createToken("`", {
  913. startsExpr
  914. }),
  915. dollarBraceL: createToken("${", {
  916. beforeExpr,
  917. startsExpr
  918. }),
  919. templateTail: createToken("...`", {
  920. startsExpr
  921. }),
  922. templateNonTail: createToken("...${", {
  923. beforeExpr,
  924. startsExpr
  925. }),
  926. at: createToken("@"),
  927. hash: createToken("#", {
  928. startsExpr
  929. }),
  930. interpreterDirective: createToken("#!..."),
  931. eq: createToken("=", {
  932. beforeExpr,
  933. isAssign
  934. }),
  935. assign: createToken("_=", {
  936. beforeExpr,
  937. isAssign
  938. }),
  939. slashAssign: createToken("_=", {
  940. beforeExpr,
  941. isAssign
  942. }),
  943. xorAssign: createToken("_=", {
  944. beforeExpr,
  945. isAssign
  946. }),
  947. moduloAssign: createToken("_=", {
  948. beforeExpr,
  949. isAssign
  950. }),
  951. incDec: createToken("++/--", {
  952. prefix,
  953. postfix,
  954. startsExpr
  955. }),
  956. bang: createToken("!", {
  957. beforeExpr,
  958. prefix,
  959. startsExpr
  960. }),
  961. tilde: createToken("~", {
  962. beforeExpr,
  963. prefix,
  964. startsExpr
  965. }),
  966. doubleCaret: createToken("^^", {
  967. startsExpr
  968. }),
  969. doubleAt: createToken("@@", {
  970. startsExpr
  971. }),
  972. pipeline: createBinop("|>", 0),
  973. nullishCoalescing: createBinop("??", 1),
  974. logicalOR: createBinop("||", 1),
  975. logicalAND: createBinop("&&", 2),
  976. bitwiseOR: createBinop("|", 3),
  977. bitwiseXOR: createBinop("^", 4),
  978. bitwiseAND: createBinop("&", 5),
  979. equality: createBinop("==/!=/===/!==", 6),
  980. lt: createBinop("</>/<=/>=", 7),
  981. gt: createBinop("</>/<=/>=", 7),
  982. relational: createBinop("</>/<=/>=", 7),
  983. bitShift: createBinop("<</>>/>>>", 8),
  984. bitShiftL: createBinop("<</>>/>>>", 8),
  985. bitShiftR: createBinop("<</>>/>>>", 8),
  986. plusMin: createToken("+/-", {
  987. beforeExpr,
  988. binop: 9,
  989. prefix,
  990. startsExpr
  991. }),
  992. modulo: createToken("%", {
  993. binop: 10,
  994. startsExpr
  995. }),
  996. star: createToken("*", {
  997. binop: 10
  998. }),
  999. slash: createBinop("/", 10),
  1000. exponent: createToken("**", {
  1001. beforeExpr,
  1002. binop: 11,
  1003. rightAssociative: true
  1004. }),
  1005. _in: createKeyword("in", {
  1006. beforeExpr,
  1007. binop: 7
  1008. }),
  1009. _instanceof: createKeyword("instanceof", {
  1010. beforeExpr,
  1011. binop: 7
  1012. }),
  1013. _break: createKeyword("break"),
  1014. _case: createKeyword("case", {
  1015. beforeExpr
  1016. }),
  1017. _catch: createKeyword("catch"),
  1018. _continue: createKeyword("continue"),
  1019. _debugger: createKeyword("debugger"),
  1020. _default: createKeyword("default", {
  1021. beforeExpr
  1022. }),
  1023. _else: createKeyword("else", {
  1024. beforeExpr
  1025. }),
  1026. _finally: createKeyword("finally"),
  1027. _function: createKeyword("function", {
  1028. startsExpr
  1029. }),
  1030. _if: createKeyword("if"),
  1031. _return: createKeyword("return", {
  1032. beforeExpr
  1033. }),
  1034. _switch: createKeyword("switch"),
  1035. _throw: createKeyword("throw", {
  1036. beforeExpr,
  1037. prefix,
  1038. startsExpr
  1039. }),
  1040. _try: createKeyword("try"),
  1041. _var: createKeyword("var"),
  1042. _const: createKeyword("const"),
  1043. _with: createKeyword("with"),
  1044. _new: createKeyword("new", {
  1045. beforeExpr,
  1046. startsExpr
  1047. }),
  1048. _this: createKeyword("this", {
  1049. startsExpr
  1050. }),
  1051. _super: createKeyword("super", {
  1052. startsExpr
  1053. }),
  1054. _class: createKeyword("class", {
  1055. startsExpr
  1056. }),
  1057. _extends: createKeyword("extends", {
  1058. beforeExpr
  1059. }),
  1060. _export: createKeyword("export"),
  1061. _import: createKeyword("import", {
  1062. startsExpr
  1063. }),
  1064. _null: createKeyword("null", {
  1065. startsExpr
  1066. }),
  1067. _true: createKeyword("true", {
  1068. startsExpr
  1069. }),
  1070. _false: createKeyword("false", {
  1071. startsExpr
  1072. }),
  1073. _typeof: createKeyword("typeof", {
  1074. beforeExpr,
  1075. prefix,
  1076. startsExpr
  1077. }),
  1078. _void: createKeyword("void", {
  1079. beforeExpr,
  1080. prefix,
  1081. startsExpr
  1082. }),
  1083. _delete: createKeyword("delete", {
  1084. beforeExpr,
  1085. prefix,
  1086. startsExpr
  1087. }),
  1088. _do: createKeyword("do", {
  1089. isLoop,
  1090. beforeExpr
  1091. }),
  1092. _for: createKeyword("for", {
  1093. isLoop
  1094. }),
  1095. _while: createKeyword("while", {
  1096. isLoop
  1097. }),
  1098. _as: createKeywordLike("as", {
  1099. startsExpr
  1100. }),
  1101. _assert: createKeywordLike("assert", {
  1102. startsExpr
  1103. }),
  1104. _async: createKeywordLike("async", {
  1105. startsExpr
  1106. }),
  1107. _await: createKeywordLike("await", {
  1108. startsExpr
  1109. }),
  1110. _defer: createKeywordLike("defer", {
  1111. startsExpr
  1112. }),
  1113. _from: createKeywordLike("from", {
  1114. startsExpr
  1115. }),
  1116. _get: createKeywordLike("get", {
  1117. startsExpr
  1118. }),
  1119. _let: createKeywordLike("let", {
  1120. startsExpr
  1121. }),
  1122. _meta: createKeywordLike("meta", {
  1123. startsExpr
  1124. }),
  1125. _of: createKeywordLike("of", {
  1126. startsExpr
  1127. }),
  1128. _sent: createKeywordLike("sent", {
  1129. startsExpr
  1130. }),
  1131. _set: createKeywordLike("set", {
  1132. startsExpr
  1133. }),
  1134. _source: createKeywordLike("source", {
  1135. startsExpr
  1136. }),
  1137. _static: createKeywordLike("static", {
  1138. startsExpr
  1139. }),
  1140. _using: createKeywordLike("using", {
  1141. startsExpr
  1142. }),
  1143. _yield: createKeywordLike("yield", {
  1144. startsExpr
  1145. }),
  1146. _asserts: createKeywordLike("asserts", {
  1147. startsExpr
  1148. }),
  1149. _checks: createKeywordLike("checks", {
  1150. startsExpr
  1151. }),
  1152. _exports: createKeywordLike("exports", {
  1153. startsExpr
  1154. }),
  1155. _global: createKeywordLike("global", {
  1156. startsExpr
  1157. }),
  1158. _implements: createKeywordLike("implements", {
  1159. startsExpr
  1160. }),
  1161. _intrinsic: createKeywordLike("intrinsic", {
  1162. startsExpr
  1163. }),
  1164. _infer: createKeywordLike("infer", {
  1165. startsExpr
  1166. }),
  1167. _is: createKeywordLike("is", {
  1168. startsExpr
  1169. }),
  1170. _mixins: createKeywordLike("mixins", {
  1171. startsExpr
  1172. }),
  1173. _proto: createKeywordLike("proto", {
  1174. startsExpr
  1175. }),
  1176. _require: createKeywordLike("require", {
  1177. startsExpr
  1178. }),
  1179. _satisfies: createKeywordLike("satisfies", {
  1180. startsExpr
  1181. }),
  1182. _keyof: createKeywordLike("keyof", {
  1183. startsExpr
  1184. }),
  1185. _readonly: createKeywordLike("readonly", {
  1186. startsExpr
  1187. }),
  1188. _unique: createKeywordLike("unique", {
  1189. startsExpr
  1190. }),
  1191. _abstract: createKeywordLike("abstract", {
  1192. startsExpr
  1193. }),
  1194. _declare: createKeywordLike("declare", {
  1195. startsExpr
  1196. }),
  1197. _enum: createKeywordLike("enum", {
  1198. startsExpr
  1199. }),
  1200. _module: createKeywordLike("module", {
  1201. startsExpr
  1202. }),
  1203. _namespace: createKeywordLike("namespace", {
  1204. startsExpr
  1205. }),
  1206. _interface: createKeywordLike("interface", {
  1207. startsExpr
  1208. }),
  1209. _type: createKeywordLike("type", {
  1210. startsExpr
  1211. }),
  1212. _opaque: createKeywordLike("opaque", {
  1213. startsExpr
  1214. }),
  1215. name: createToken("name", {
  1216. startsExpr
  1217. }),
  1218. placeholder: createToken("%%", {
  1219. startsExpr: true
  1220. }),
  1221. string: createToken("string", {
  1222. startsExpr
  1223. }),
  1224. num: createToken("num", {
  1225. startsExpr
  1226. }),
  1227. bigint: createToken("bigint", {
  1228. startsExpr
  1229. }),
  1230. decimal: createToken("decimal", {
  1231. startsExpr
  1232. }),
  1233. regexp: createToken("regexp", {
  1234. startsExpr
  1235. }),
  1236. privateName: createToken("#name", {
  1237. startsExpr
  1238. }),
  1239. eof: createToken("eof"),
  1240. jsxName: createToken("jsxName"),
  1241. jsxText: createToken("jsxText", {
  1242. beforeExpr: true
  1243. }),
  1244. jsxTagStart: createToken("jsxTagStart", {
  1245. startsExpr: true
  1246. }),
  1247. jsxTagEnd: createToken("jsxTagEnd")
  1248. };
  1249. function tokenIsIdentifier(token) {
  1250. return token >= 93 && token <= 133;
  1251. }
  1252. function tokenKeywordOrIdentifierIsKeyword(token) {
  1253. return token <= 92;
  1254. }
  1255. function tokenIsKeywordOrIdentifier(token) {
  1256. return token >= 58 && token <= 133;
  1257. }
  1258. function tokenIsLiteralPropertyName(token) {
  1259. return token >= 58 && token <= 137;
  1260. }
  1261. function tokenComesBeforeExpression(token) {
  1262. return tokenBeforeExprs[token];
  1263. }
  1264. function tokenCanStartExpression(token) {
  1265. return tokenStartsExprs[token];
  1266. }
  1267. function tokenIsAssignment(token) {
  1268. return token >= 29 && token <= 33;
  1269. }
  1270. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1271. return token >= 129 && token <= 131;
  1272. }
  1273. function tokenIsLoop(token) {
  1274. return token >= 90 && token <= 92;
  1275. }
  1276. function tokenIsKeyword(token) {
  1277. return token >= 58 && token <= 92;
  1278. }
  1279. function tokenIsOperator(token) {
  1280. return token >= 39 && token <= 59;
  1281. }
  1282. function tokenIsPostfix(token) {
  1283. return token === 34;
  1284. }
  1285. function tokenIsPrefix(token) {
  1286. return tokenPrefixes[token];
  1287. }
  1288. function tokenIsTSTypeOperator(token) {
  1289. return token >= 121 && token <= 123;
  1290. }
  1291. function tokenIsTSDeclarationStart(token) {
  1292. return token >= 124 && token <= 130;
  1293. }
  1294. function tokenLabelName(token) {
  1295. return tokenLabels[token];
  1296. }
  1297. function tokenOperatorPrecedence(token) {
  1298. return tokenBinops[token];
  1299. }
  1300. function tokenIsRightAssociative(token) {
  1301. return token === 57;
  1302. }
  1303. function tokenIsTemplate(token) {
  1304. return token >= 24 && token <= 25;
  1305. }
  1306. function getExportedToken(token) {
  1307. return tokenTypes[token];
  1308. }
  1309. {
  1310. tokenTypes[8].updateContext = context => {
  1311. context.pop();
  1312. };
  1313. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1314. context.push(types.brace);
  1315. };
  1316. tokenTypes[22].updateContext = context => {
  1317. if (context[context.length - 1] === types.template) {
  1318. context.pop();
  1319. } else {
  1320. context.push(types.template);
  1321. }
  1322. };
  1323. tokenTypes[143].updateContext = context => {
  1324. context.push(types.j_expr, types.j_oTag);
  1325. };
  1326. }
  1327. let nonASCIIidentifierStartChars = "\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\u0560-\u0588\u05d0-\u05ea\u05ef-\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\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\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\u09fc\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\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\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-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\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-\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-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7cd\ua7d0\ua7d1\ua7d3\ua7d5-\ua7dc\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\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-\uab69\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";
  1328. let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  1329. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1330. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1331. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1332. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
  1333. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1334. function isInAstralSet(code, set) {
  1335. let pos = 0x10000;
  1336. for (let i = 0, length = set.length; i < length; i += 2) {
  1337. pos += set[i];
  1338. if (pos > code) return false;
  1339. pos += set[i + 1];
  1340. if (pos >= code) return true;
  1341. }
  1342. return false;
  1343. }
  1344. function isIdentifierStart(code) {
  1345. if (code < 65) return code === 36;
  1346. if (code <= 90) return true;
  1347. if (code < 97) return code === 95;
  1348. if (code <= 122) return true;
  1349. if (code <= 0xffff) {
  1350. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1351. }
  1352. return isInAstralSet(code, astralIdentifierStartCodes);
  1353. }
  1354. function isIdentifierChar(code) {
  1355. if (code < 48) return code === 36;
  1356. if (code < 58) return true;
  1357. if (code < 65) return false;
  1358. if (code <= 90) return true;
  1359. if (code < 97) return code === 95;
  1360. if (code <= 122) return true;
  1361. if (code <= 0xffff) {
  1362. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1363. }
  1364. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1365. }
  1366. const reservedWords = {
  1367. keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
  1368. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1369. strictBind: ["eval", "arguments"]
  1370. };
  1371. const keywords = new Set(reservedWords.keyword);
  1372. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1373. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1374. function isReservedWord(word, inModule) {
  1375. return inModule && word === "await" || word === "enum";
  1376. }
  1377. function isStrictReservedWord(word, inModule) {
  1378. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1379. }
  1380. function isStrictBindOnlyReservedWord(word) {
  1381. return reservedWordsStrictBindSet.has(word);
  1382. }
  1383. function isStrictBindReservedWord(word, inModule) {
  1384. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1385. }
  1386. function isKeyword(word) {
  1387. return keywords.has(word);
  1388. }
  1389. function isIteratorStart(current, next, next2) {
  1390. return current === 64 && next === 64 && isIdentifierStart(next2);
  1391. }
  1392. const reservedWordLikeSet = new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "eval", "arguments", "enum", "await"]);
  1393. function canBeReservedWord(word) {
  1394. return reservedWordLikeSet.has(word);
  1395. }
  1396. class Scope {
  1397. constructor(flags) {
  1398. this.flags = 0;
  1399. this.names = new Map();
  1400. this.firstLexicalName = "";
  1401. this.flags = flags;
  1402. }
  1403. }
  1404. class ScopeHandler {
  1405. constructor(parser, inModule) {
  1406. this.parser = void 0;
  1407. this.scopeStack = [];
  1408. this.inModule = void 0;
  1409. this.undefinedExports = new Map();
  1410. this.parser = parser;
  1411. this.inModule = inModule;
  1412. }
  1413. get inTopLevel() {
  1414. return (this.currentScope().flags & 1) > 0;
  1415. }
  1416. get inFunction() {
  1417. return (this.currentVarScopeFlags() & 2) > 0;
  1418. }
  1419. get allowSuper() {
  1420. return (this.currentThisScopeFlags() & 16) > 0;
  1421. }
  1422. get allowDirectSuper() {
  1423. return (this.currentThisScopeFlags() & 32) > 0;
  1424. }
  1425. get inClass() {
  1426. return (this.currentThisScopeFlags() & 64) > 0;
  1427. }
  1428. get inClassAndNotInNonArrowFunction() {
  1429. const flags = this.currentThisScopeFlags();
  1430. return (flags & 64) > 0 && (flags & 2) === 0;
  1431. }
  1432. get inStaticBlock() {
  1433. for (let i = this.scopeStack.length - 1;; i--) {
  1434. const {
  1435. flags
  1436. } = this.scopeStack[i];
  1437. if (flags & 128) {
  1438. return true;
  1439. }
  1440. if (flags & (387 | 64)) {
  1441. return false;
  1442. }
  1443. }
  1444. }
  1445. get inNonArrowFunction() {
  1446. return (this.currentThisScopeFlags() & 2) > 0;
  1447. }
  1448. get treatFunctionsAsVar() {
  1449. return this.treatFunctionsAsVarInScope(this.currentScope());
  1450. }
  1451. createScope(flags) {
  1452. return new Scope(flags);
  1453. }
  1454. enter(flags) {
  1455. this.scopeStack.push(this.createScope(flags));
  1456. }
  1457. exit() {
  1458. const scope = this.scopeStack.pop();
  1459. return scope.flags;
  1460. }
  1461. treatFunctionsAsVarInScope(scope) {
  1462. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1463. }
  1464. declareName(name, bindingType, loc) {
  1465. let scope = this.currentScope();
  1466. if (bindingType & 8 || bindingType & 16) {
  1467. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1468. let type = scope.names.get(name) || 0;
  1469. if (bindingType & 16) {
  1470. type = type | 4;
  1471. } else {
  1472. if (!scope.firstLexicalName) {
  1473. scope.firstLexicalName = name;
  1474. }
  1475. type = type | 2;
  1476. }
  1477. scope.names.set(name, type);
  1478. if (bindingType & 8) {
  1479. this.maybeExportDefined(scope, name);
  1480. }
  1481. } else if (bindingType & 4) {
  1482. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1483. scope = this.scopeStack[i];
  1484. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1485. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1486. this.maybeExportDefined(scope, name);
  1487. if (scope.flags & 387) break;
  1488. }
  1489. }
  1490. if (this.parser.inModule && scope.flags & 1) {
  1491. this.undefinedExports.delete(name);
  1492. }
  1493. }
  1494. maybeExportDefined(scope, name) {
  1495. if (this.parser.inModule && scope.flags & 1) {
  1496. this.undefinedExports.delete(name);
  1497. }
  1498. }
  1499. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1500. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1501. this.parser.raise(Errors.VarRedeclaration, loc, {
  1502. identifierName: name
  1503. });
  1504. }
  1505. }
  1506. isRedeclaredInScope(scope, name, bindingType) {
  1507. if (!(bindingType & 1)) return false;
  1508. if (bindingType & 8) {
  1509. return scope.names.has(name);
  1510. }
  1511. const type = scope.names.get(name);
  1512. if (bindingType & 16) {
  1513. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1514. }
  1515. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1516. }
  1517. checkLocalExport(id) {
  1518. const {
  1519. name
  1520. } = id;
  1521. const topLevelScope = this.scopeStack[0];
  1522. if (!topLevelScope.names.has(name)) {
  1523. this.undefinedExports.set(name, id.loc.start);
  1524. }
  1525. }
  1526. currentScope() {
  1527. return this.scopeStack[this.scopeStack.length - 1];
  1528. }
  1529. currentVarScopeFlags() {
  1530. for (let i = this.scopeStack.length - 1;; i--) {
  1531. const {
  1532. flags
  1533. } = this.scopeStack[i];
  1534. if (flags & 387) {
  1535. return flags;
  1536. }
  1537. }
  1538. }
  1539. currentThisScopeFlags() {
  1540. for (let i = this.scopeStack.length - 1;; i--) {
  1541. const {
  1542. flags
  1543. } = this.scopeStack[i];
  1544. if (flags & (387 | 64) && !(flags & 4)) {
  1545. return flags;
  1546. }
  1547. }
  1548. }
  1549. }
  1550. class FlowScope extends Scope {
  1551. constructor(...args) {
  1552. super(...args);
  1553. this.declareFunctions = new Set();
  1554. }
  1555. }
  1556. class FlowScopeHandler extends ScopeHandler {
  1557. createScope(flags) {
  1558. return new FlowScope(flags);
  1559. }
  1560. declareName(name, bindingType, loc) {
  1561. const scope = this.currentScope();
  1562. if (bindingType & 2048) {
  1563. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1564. this.maybeExportDefined(scope, name);
  1565. scope.declareFunctions.add(name);
  1566. return;
  1567. }
  1568. super.declareName(name, bindingType, loc);
  1569. }
  1570. isRedeclaredInScope(scope, name, bindingType) {
  1571. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1572. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1573. const type = scope.names.get(name);
  1574. return (type & 4) > 0 || (type & 2) > 0;
  1575. }
  1576. return false;
  1577. }
  1578. checkLocalExport(id) {
  1579. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1580. super.checkLocalExport(id);
  1581. }
  1582. }
  1583. }
  1584. class BaseParser {
  1585. constructor() {
  1586. this.sawUnambiguousESM = false;
  1587. this.ambiguousScriptDifferentAst = false;
  1588. }
  1589. sourceToOffsetPos(sourcePos) {
  1590. return sourcePos + this.startIndex;
  1591. }
  1592. offsetToSourcePos(offsetPos) {
  1593. return offsetPos - this.startIndex;
  1594. }
  1595. hasPlugin(pluginConfig) {
  1596. if (typeof pluginConfig === "string") {
  1597. return this.plugins.has(pluginConfig);
  1598. } else {
  1599. const [pluginName, pluginOptions] = pluginConfig;
  1600. if (!this.hasPlugin(pluginName)) {
  1601. return false;
  1602. }
  1603. const actualOptions = this.plugins.get(pluginName);
  1604. for (const key of Object.keys(pluginOptions)) {
  1605. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1606. return false;
  1607. }
  1608. }
  1609. return true;
  1610. }
  1611. }
  1612. getPluginOption(plugin, name) {
  1613. var _this$plugins$get;
  1614. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1615. }
  1616. }
  1617. function setTrailingComments(node, comments) {
  1618. if (node.trailingComments === undefined) {
  1619. node.trailingComments = comments;
  1620. } else {
  1621. node.trailingComments.unshift(...comments);
  1622. }
  1623. }
  1624. function setLeadingComments(node, comments) {
  1625. if (node.leadingComments === undefined) {
  1626. node.leadingComments = comments;
  1627. } else {
  1628. node.leadingComments.unshift(...comments);
  1629. }
  1630. }
  1631. function setInnerComments(node, comments) {
  1632. if (node.innerComments === undefined) {
  1633. node.innerComments = comments;
  1634. } else {
  1635. node.innerComments.unshift(...comments);
  1636. }
  1637. }
  1638. function adjustInnerComments(node, elements, commentWS) {
  1639. let lastElement = null;
  1640. let i = elements.length;
  1641. while (lastElement === null && i > 0) {
  1642. lastElement = elements[--i];
  1643. }
  1644. if (lastElement === null || lastElement.start > commentWS.start) {
  1645. setInnerComments(node, commentWS.comments);
  1646. } else {
  1647. setTrailingComments(lastElement, commentWS.comments);
  1648. }
  1649. }
  1650. class CommentsParser extends BaseParser {
  1651. addComment(comment) {
  1652. if (this.filename) comment.loc.filename = this.filename;
  1653. const {
  1654. commentsLen
  1655. } = this.state;
  1656. if (this.comments.length !== commentsLen) {
  1657. this.comments.length = commentsLen;
  1658. }
  1659. this.comments.push(comment);
  1660. this.state.commentsLen++;
  1661. }
  1662. processComment(node) {
  1663. const {
  1664. commentStack
  1665. } = this.state;
  1666. const commentStackLength = commentStack.length;
  1667. if (commentStackLength === 0) return;
  1668. let i = commentStackLength - 1;
  1669. const lastCommentWS = commentStack[i];
  1670. if (lastCommentWS.start === node.end) {
  1671. lastCommentWS.leadingNode = node;
  1672. i--;
  1673. }
  1674. const {
  1675. start: nodeStart
  1676. } = node;
  1677. for (; i >= 0; i--) {
  1678. const commentWS = commentStack[i];
  1679. const commentEnd = commentWS.end;
  1680. if (commentEnd > nodeStart) {
  1681. commentWS.containingNode = node;
  1682. this.finalizeComment(commentWS);
  1683. commentStack.splice(i, 1);
  1684. } else {
  1685. if (commentEnd === nodeStart) {
  1686. commentWS.trailingNode = node;
  1687. }
  1688. break;
  1689. }
  1690. }
  1691. }
  1692. finalizeComment(commentWS) {
  1693. const {
  1694. comments
  1695. } = commentWS;
  1696. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1697. if (commentWS.leadingNode !== null) {
  1698. setTrailingComments(commentWS.leadingNode, comments);
  1699. }
  1700. if (commentWS.trailingNode !== null) {
  1701. setLeadingComments(commentWS.trailingNode, comments);
  1702. }
  1703. } else {
  1704. const {
  1705. containingNode: node,
  1706. start: commentStart
  1707. } = commentWS;
  1708. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  1709. switch (node.type) {
  1710. case "ObjectExpression":
  1711. case "ObjectPattern":
  1712. case "RecordExpression":
  1713. adjustInnerComments(node, node.properties, commentWS);
  1714. break;
  1715. case "CallExpression":
  1716. case "OptionalCallExpression":
  1717. adjustInnerComments(node, node.arguments, commentWS);
  1718. break;
  1719. case "FunctionDeclaration":
  1720. case "FunctionExpression":
  1721. case "ArrowFunctionExpression":
  1722. case "ObjectMethod":
  1723. case "ClassMethod":
  1724. case "ClassPrivateMethod":
  1725. adjustInnerComments(node, node.params, commentWS);
  1726. break;
  1727. case "ArrayExpression":
  1728. case "ArrayPattern":
  1729. case "TupleExpression":
  1730. adjustInnerComments(node, node.elements, commentWS);
  1731. break;
  1732. case "ExportNamedDeclaration":
  1733. case "ImportDeclaration":
  1734. adjustInnerComments(node, node.specifiers, commentWS);
  1735. break;
  1736. default:
  1737. {
  1738. setInnerComments(node, comments);
  1739. }
  1740. }
  1741. } else {
  1742. setInnerComments(node, comments);
  1743. }
  1744. }
  1745. }
  1746. finalizeRemainingComments() {
  1747. const {
  1748. commentStack
  1749. } = this.state;
  1750. for (let i = commentStack.length - 1; i >= 0; i--) {
  1751. this.finalizeComment(commentStack[i]);
  1752. }
  1753. this.state.commentStack = [];
  1754. }
  1755. resetPreviousNodeTrailingComments(node) {
  1756. const {
  1757. commentStack
  1758. } = this.state;
  1759. const {
  1760. length
  1761. } = commentStack;
  1762. if (length === 0) return;
  1763. const commentWS = commentStack[length - 1];
  1764. if (commentWS.leadingNode === node) {
  1765. commentWS.leadingNode = null;
  1766. }
  1767. }
  1768. resetPreviousIdentifierLeadingComments(node) {
  1769. const {
  1770. commentStack
  1771. } = this.state;
  1772. const {
  1773. length
  1774. } = commentStack;
  1775. if (length === 0) return;
  1776. if (commentStack[length - 1].trailingNode === node) {
  1777. commentStack[length - 1].trailingNode = null;
  1778. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1779. commentStack[length - 2].trailingNode = null;
  1780. }
  1781. }
  1782. takeSurroundingComments(node, start, end) {
  1783. const {
  1784. commentStack
  1785. } = this.state;
  1786. const commentStackLength = commentStack.length;
  1787. if (commentStackLength === 0) return;
  1788. let i = commentStackLength - 1;
  1789. for (; i >= 0; i--) {
  1790. const commentWS = commentStack[i];
  1791. const commentEnd = commentWS.end;
  1792. const commentStart = commentWS.start;
  1793. if (commentStart === end) {
  1794. commentWS.leadingNode = node;
  1795. } else if (commentEnd === start) {
  1796. commentWS.trailingNode = node;
  1797. } else if (commentEnd < start) {
  1798. break;
  1799. }
  1800. }
  1801. }
  1802. }
  1803. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  1804. const lineBreakG = new RegExp(lineBreak.source, "g");
  1805. function isNewLine(code) {
  1806. switch (code) {
  1807. case 10:
  1808. case 13:
  1809. case 8232:
  1810. case 8233:
  1811. return true;
  1812. default:
  1813. return false;
  1814. }
  1815. }
  1816. function hasNewLine(input, start, end) {
  1817. for (let i = start; i < end; i++) {
  1818. if (isNewLine(input.charCodeAt(i))) {
  1819. return true;
  1820. }
  1821. }
  1822. return false;
  1823. }
  1824. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1825. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1826. function isWhitespace(code) {
  1827. switch (code) {
  1828. case 0x0009:
  1829. case 0x000b:
  1830. case 0x000c:
  1831. case 32:
  1832. case 160:
  1833. case 5760:
  1834. case 0x2000:
  1835. case 0x2001:
  1836. case 0x2002:
  1837. case 0x2003:
  1838. case 0x2004:
  1839. case 0x2005:
  1840. case 0x2006:
  1841. case 0x2007:
  1842. case 0x2008:
  1843. case 0x2009:
  1844. case 0x200a:
  1845. case 0x202f:
  1846. case 0x205f:
  1847. case 0x3000:
  1848. case 0xfeff:
  1849. return true;
  1850. default:
  1851. return false;
  1852. }
  1853. }
  1854. class State {
  1855. constructor() {
  1856. this.flags = 1024;
  1857. this.startIndex = void 0;
  1858. this.curLine = void 0;
  1859. this.lineStart = void 0;
  1860. this.startLoc = void 0;
  1861. this.endLoc = void 0;
  1862. this.errors = [];
  1863. this.potentialArrowAt = -1;
  1864. this.noArrowAt = [];
  1865. this.noArrowParamsConversionAt = [];
  1866. this.topicContext = {
  1867. maxNumOfResolvableTopics: 0,
  1868. maxTopicIndex: null
  1869. };
  1870. this.labels = [];
  1871. this.commentsLen = 0;
  1872. this.commentStack = [];
  1873. this.pos = 0;
  1874. this.type = 140;
  1875. this.value = null;
  1876. this.start = 0;
  1877. this.end = 0;
  1878. this.lastTokEndLoc = null;
  1879. this.lastTokStartLoc = null;
  1880. this.context = [types.brace];
  1881. this.firstInvalidTemplateEscapePos = null;
  1882. this.strictErrors = new Map();
  1883. this.tokensLength = 0;
  1884. }
  1885. get strict() {
  1886. return (this.flags & 1) > 0;
  1887. }
  1888. set strict(v) {
  1889. if (v) this.flags |= 1;else this.flags &= -2;
  1890. }
  1891. init({
  1892. strictMode,
  1893. sourceType,
  1894. startIndex,
  1895. startLine,
  1896. startColumn
  1897. }) {
  1898. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1899. this.startIndex = startIndex;
  1900. this.curLine = startLine;
  1901. this.lineStart = -startColumn;
  1902. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  1903. }
  1904. get maybeInArrowParameters() {
  1905. return (this.flags & 2) > 0;
  1906. }
  1907. set maybeInArrowParameters(v) {
  1908. if (v) this.flags |= 2;else this.flags &= -3;
  1909. }
  1910. get inType() {
  1911. return (this.flags & 4) > 0;
  1912. }
  1913. set inType(v) {
  1914. if (v) this.flags |= 4;else this.flags &= -5;
  1915. }
  1916. get noAnonFunctionType() {
  1917. return (this.flags & 8) > 0;
  1918. }
  1919. set noAnonFunctionType(v) {
  1920. if (v) this.flags |= 8;else this.flags &= -9;
  1921. }
  1922. get hasFlowComment() {
  1923. return (this.flags & 16) > 0;
  1924. }
  1925. set hasFlowComment(v) {
  1926. if (v) this.flags |= 16;else this.flags &= -17;
  1927. }
  1928. get isAmbientContext() {
  1929. return (this.flags & 32) > 0;
  1930. }
  1931. set isAmbientContext(v) {
  1932. if (v) this.flags |= 32;else this.flags &= -33;
  1933. }
  1934. get inAbstractClass() {
  1935. return (this.flags & 64) > 0;
  1936. }
  1937. set inAbstractClass(v) {
  1938. if (v) this.flags |= 64;else this.flags &= -65;
  1939. }
  1940. get inDisallowConditionalTypesContext() {
  1941. return (this.flags & 128) > 0;
  1942. }
  1943. set inDisallowConditionalTypesContext(v) {
  1944. if (v) this.flags |= 128;else this.flags &= -129;
  1945. }
  1946. get soloAwait() {
  1947. return (this.flags & 256) > 0;
  1948. }
  1949. set soloAwait(v) {
  1950. if (v) this.flags |= 256;else this.flags &= -257;
  1951. }
  1952. get inFSharpPipelineDirectBody() {
  1953. return (this.flags & 512) > 0;
  1954. }
  1955. set inFSharpPipelineDirectBody(v) {
  1956. if (v) this.flags |= 512;else this.flags &= -513;
  1957. }
  1958. get canStartJSXElement() {
  1959. return (this.flags & 1024) > 0;
  1960. }
  1961. set canStartJSXElement(v) {
  1962. if (v) this.flags |= 1024;else this.flags &= -1025;
  1963. }
  1964. get containsEsc() {
  1965. return (this.flags & 2048) > 0;
  1966. }
  1967. set containsEsc(v) {
  1968. if (v) this.flags |= 2048;else this.flags &= -2049;
  1969. }
  1970. get hasTopLevelAwait() {
  1971. return (this.flags & 4096) > 0;
  1972. }
  1973. set hasTopLevelAwait(v) {
  1974. if (v) this.flags |= 4096;else this.flags &= -4097;
  1975. }
  1976. curPosition() {
  1977. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  1978. }
  1979. clone() {
  1980. const state = new State();
  1981. state.flags = this.flags;
  1982. state.startIndex = this.startIndex;
  1983. state.curLine = this.curLine;
  1984. state.lineStart = this.lineStart;
  1985. state.startLoc = this.startLoc;
  1986. state.endLoc = this.endLoc;
  1987. state.errors = this.errors.slice();
  1988. state.potentialArrowAt = this.potentialArrowAt;
  1989. state.noArrowAt = this.noArrowAt.slice();
  1990. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  1991. state.topicContext = this.topicContext;
  1992. state.labels = this.labels.slice();
  1993. state.commentsLen = this.commentsLen;
  1994. state.commentStack = this.commentStack.slice();
  1995. state.pos = this.pos;
  1996. state.type = this.type;
  1997. state.value = this.value;
  1998. state.start = this.start;
  1999. state.end = this.end;
  2000. state.lastTokEndLoc = this.lastTokEndLoc;
  2001. state.lastTokStartLoc = this.lastTokStartLoc;
  2002. state.context = this.context.slice();
  2003. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  2004. state.strictErrors = this.strictErrors;
  2005. state.tokensLength = this.tokensLength;
  2006. return state;
  2007. }
  2008. }
  2009. var _isDigit = function isDigit(code) {
  2010. return code >= 48 && code <= 57;
  2011. };
  2012. const forbiddenNumericSeparatorSiblings = {
  2013. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  2014. hex: new Set([46, 88, 95, 120])
  2015. };
  2016. const isAllowedNumericSeparatorSibling = {
  2017. bin: ch => ch === 48 || ch === 49,
  2018. oct: ch => ch >= 48 && ch <= 55,
  2019. dec: ch => ch >= 48 && ch <= 57,
  2020. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  2021. };
  2022. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  2023. const initialPos = pos;
  2024. const initialLineStart = lineStart;
  2025. const initialCurLine = curLine;
  2026. let out = "";
  2027. let firstInvalidLoc = null;
  2028. let chunkStart = pos;
  2029. const {
  2030. length
  2031. } = input;
  2032. for (;;) {
  2033. if (pos >= length) {
  2034. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2035. out += input.slice(chunkStart, pos);
  2036. break;
  2037. }
  2038. const ch = input.charCodeAt(pos);
  2039. if (isStringEnd(type, ch, input, pos)) {
  2040. out += input.slice(chunkStart, pos);
  2041. break;
  2042. }
  2043. if (ch === 92) {
  2044. out += input.slice(chunkStart, pos);
  2045. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  2046. if (res.ch === null && !firstInvalidLoc) {
  2047. firstInvalidLoc = {
  2048. pos,
  2049. lineStart,
  2050. curLine
  2051. };
  2052. } else {
  2053. out += res.ch;
  2054. }
  2055. ({
  2056. pos,
  2057. lineStart,
  2058. curLine
  2059. } = res);
  2060. chunkStart = pos;
  2061. } else if (ch === 8232 || ch === 8233) {
  2062. ++pos;
  2063. ++curLine;
  2064. lineStart = pos;
  2065. } else if (ch === 10 || ch === 13) {
  2066. if (type === "template") {
  2067. out += input.slice(chunkStart, pos) + "\n";
  2068. ++pos;
  2069. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2070. ++pos;
  2071. }
  2072. ++curLine;
  2073. chunkStart = lineStart = pos;
  2074. } else {
  2075. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2076. }
  2077. } else {
  2078. ++pos;
  2079. }
  2080. }
  2081. return {
  2082. pos,
  2083. str: out,
  2084. firstInvalidLoc,
  2085. lineStart,
  2086. curLine,
  2087. containsInvalid: !!firstInvalidLoc
  2088. };
  2089. }
  2090. function isStringEnd(type, ch, input, pos) {
  2091. if (type === "template") {
  2092. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2093. }
  2094. return ch === (type === "double" ? 34 : 39);
  2095. }
  2096. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2097. const throwOnInvalid = !inTemplate;
  2098. pos++;
  2099. const res = ch => ({
  2100. pos,
  2101. ch,
  2102. lineStart,
  2103. curLine
  2104. });
  2105. const ch = input.charCodeAt(pos++);
  2106. switch (ch) {
  2107. case 110:
  2108. return res("\n");
  2109. case 114:
  2110. return res("\r");
  2111. case 120:
  2112. {
  2113. let code;
  2114. ({
  2115. code,
  2116. pos
  2117. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2118. return res(code === null ? null : String.fromCharCode(code));
  2119. }
  2120. case 117:
  2121. {
  2122. let code;
  2123. ({
  2124. code,
  2125. pos
  2126. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2127. return res(code === null ? null : String.fromCodePoint(code));
  2128. }
  2129. case 116:
  2130. return res("\t");
  2131. case 98:
  2132. return res("\b");
  2133. case 118:
  2134. return res("\u000b");
  2135. case 102:
  2136. return res("\f");
  2137. case 13:
  2138. if (input.charCodeAt(pos) === 10) {
  2139. ++pos;
  2140. }
  2141. case 10:
  2142. lineStart = pos;
  2143. ++curLine;
  2144. case 8232:
  2145. case 8233:
  2146. return res("");
  2147. case 56:
  2148. case 57:
  2149. if (inTemplate) {
  2150. return res(null);
  2151. } else {
  2152. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2153. }
  2154. default:
  2155. if (ch >= 48 && ch <= 55) {
  2156. const startPos = pos - 1;
  2157. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  2158. let octalStr = match[0];
  2159. let octal = parseInt(octalStr, 8);
  2160. if (octal > 255) {
  2161. octalStr = octalStr.slice(0, -1);
  2162. octal = parseInt(octalStr, 8);
  2163. }
  2164. pos += octalStr.length - 1;
  2165. const next = input.charCodeAt(pos);
  2166. if (octalStr !== "0" || next === 56 || next === 57) {
  2167. if (inTemplate) {
  2168. return res(null);
  2169. } else {
  2170. errors.strictNumericEscape(startPos, lineStart, curLine);
  2171. }
  2172. }
  2173. return res(String.fromCharCode(octal));
  2174. }
  2175. return res(String.fromCharCode(ch));
  2176. }
  2177. }
  2178. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2179. const initialPos = pos;
  2180. let n;
  2181. ({
  2182. n,
  2183. pos
  2184. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2185. if (n === null) {
  2186. if (throwOnInvalid) {
  2187. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2188. } else {
  2189. pos = initialPos - 1;
  2190. }
  2191. }
  2192. return {
  2193. code: n,
  2194. pos
  2195. };
  2196. }
  2197. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2198. const start = pos;
  2199. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2200. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2201. let invalid = false;
  2202. let total = 0;
  2203. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2204. const code = input.charCodeAt(pos);
  2205. let val;
  2206. if (code === 95 && allowNumSeparator !== "bail") {
  2207. const prev = input.charCodeAt(pos - 1);
  2208. const next = input.charCodeAt(pos + 1);
  2209. if (!allowNumSeparator) {
  2210. if (bailOnError) return {
  2211. n: null,
  2212. pos
  2213. };
  2214. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2215. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2216. if (bailOnError) return {
  2217. n: null,
  2218. pos
  2219. };
  2220. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2221. }
  2222. ++pos;
  2223. continue;
  2224. }
  2225. if (code >= 97) {
  2226. val = code - 97 + 10;
  2227. } else if (code >= 65) {
  2228. val = code - 65 + 10;
  2229. } else if (_isDigit(code)) {
  2230. val = code - 48;
  2231. } else {
  2232. val = Infinity;
  2233. }
  2234. if (val >= radix) {
  2235. if (val <= 9 && bailOnError) {
  2236. return {
  2237. n: null,
  2238. pos
  2239. };
  2240. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2241. val = 0;
  2242. } else if (forceLen) {
  2243. val = 0;
  2244. invalid = true;
  2245. } else {
  2246. break;
  2247. }
  2248. }
  2249. ++pos;
  2250. total = total * radix + val;
  2251. }
  2252. if (pos === start || len != null && pos - start !== len || invalid) {
  2253. return {
  2254. n: null,
  2255. pos
  2256. };
  2257. }
  2258. return {
  2259. n: total,
  2260. pos
  2261. };
  2262. }
  2263. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2264. const ch = input.charCodeAt(pos);
  2265. let code;
  2266. if (ch === 123) {
  2267. ++pos;
  2268. ({
  2269. code,
  2270. pos
  2271. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2272. ++pos;
  2273. if (code !== null && code > 0x10ffff) {
  2274. if (throwOnInvalid) {
  2275. errors.invalidCodePoint(pos, lineStart, curLine);
  2276. } else {
  2277. return {
  2278. code: null,
  2279. pos
  2280. };
  2281. }
  2282. }
  2283. } else {
  2284. ({
  2285. code,
  2286. pos
  2287. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2288. }
  2289. return {
  2290. code,
  2291. pos
  2292. };
  2293. }
  2294. function buildPosition(pos, lineStart, curLine) {
  2295. return new Position(curLine, pos - lineStart, pos);
  2296. }
  2297. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2298. class Token {
  2299. constructor(state) {
  2300. const startIndex = state.startIndex || 0;
  2301. this.type = state.type;
  2302. this.value = state.value;
  2303. this.start = startIndex + state.start;
  2304. this.end = startIndex + state.end;
  2305. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2306. }
  2307. }
  2308. class Tokenizer extends CommentsParser {
  2309. constructor(options, input) {
  2310. super();
  2311. this.isLookahead = void 0;
  2312. this.tokens = [];
  2313. this.errorHandlers_readInt = {
  2314. invalidDigit: (pos, lineStart, curLine, radix) => {
  2315. if (!this.options.errorRecovery) return false;
  2316. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  2317. radix
  2318. });
  2319. return true;
  2320. },
  2321. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2322. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2323. };
  2324. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2325. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2326. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2327. });
  2328. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2329. strictNumericEscape: (pos, lineStart, curLine) => {
  2330. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  2331. },
  2332. unterminated: (pos, lineStart, curLine) => {
  2333. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  2334. }
  2335. });
  2336. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2337. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2338. unterminated: (pos, lineStart, curLine) => {
  2339. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  2340. }
  2341. });
  2342. this.state = new State();
  2343. this.state.init(options);
  2344. this.input = input;
  2345. this.length = input.length;
  2346. this.comments = [];
  2347. this.isLookahead = false;
  2348. }
  2349. pushToken(token) {
  2350. this.tokens.length = this.state.tokensLength;
  2351. this.tokens.push(token);
  2352. ++this.state.tokensLength;
  2353. }
  2354. next() {
  2355. this.checkKeywordEscapes();
  2356. if (this.options.tokens) {
  2357. this.pushToken(new Token(this.state));
  2358. }
  2359. this.state.lastTokEndLoc = this.state.endLoc;
  2360. this.state.lastTokStartLoc = this.state.startLoc;
  2361. this.nextToken();
  2362. }
  2363. eat(type) {
  2364. if (this.match(type)) {
  2365. this.next();
  2366. return true;
  2367. } else {
  2368. return false;
  2369. }
  2370. }
  2371. match(type) {
  2372. return this.state.type === type;
  2373. }
  2374. createLookaheadState(state) {
  2375. return {
  2376. pos: state.pos,
  2377. value: null,
  2378. type: state.type,
  2379. start: state.start,
  2380. end: state.end,
  2381. context: [this.curContext()],
  2382. inType: state.inType,
  2383. startLoc: state.startLoc,
  2384. lastTokEndLoc: state.lastTokEndLoc,
  2385. curLine: state.curLine,
  2386. lineStart: state.lineStart,
  2387. curPosition: state.curPosition
  2388. };
  2389. }
  2390. lookahead() {
  2391. const old = this.state;
  2392. this.state = this.createLookaheadState(old);
  2393. this.isLookahead = true;
  2394. this.nextToken();
  2395. this.isLookahead = false;
  2396. const curr = this.state;
  2397. this.state = old;
  2398. return curr;
  2399. }
  2400. nextTokenStart() {
  2401. return this.nextTokenStartSince(this.state.pos);
  2402. }
  2403. nextTokenStartSince(pos) {
  2404. skipWhiteSpace.lastIndex = pos;
  2405. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2406. }
  2407. lookaheadCharCode() {
  2408. return this.input.charCodeAt(this.nextTokenStart());
  2409. }
  2410. nextTokenInLineStart() {
  2411. return this.nextTokenInLineStartSince(this.state.pos);
  2412. }
  2413. nextTokenInLineStartSince(pos) {
  2414. skipWhiteSpaceInLine.lastIndex = pos;
  2415. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2416. }
  2417. lookaheadInLineCharCode() {
  2418. return this.input.charCodeAt(this.nextTokenInLineStart());
  2419. }
  2420. codePointAtPos(pos) {
  2421. let cp = this.input.charCodeAt(pos);
  2422. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2423. const trail = this.input.charCodeAt(pos);
  2424. if ((trail & 0xfc00) === 0xdc00) {
  2425. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2426. }
  2427. }
  2428. return cp;
  2429. }
  2430. setStrict(strict) {
  2431. this.state.strict = strict;
  2432. if (strict) {
  2433. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  2434. this.state.strictErrors.clear();
  2435. }
  2436. }
  2437. curContext() {
  2438. return this.state.context[this.state.context.length - 1];
  2439. }
  2440. nextToken() {
  2441. this.skipSpace();
  2442. this.state.start = this.state.pos;
  2443. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2444. if (this.state.pos >= this.length) {
  2445. this.finishToken(140);
  2446. return;
  2447. }
  2448. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2449. }
  2450. skipBlockComment(commentEnd) {
  2451. let startLoc;
  2452. if (!this.isLookahead) startLoc = this.state.curPosition();
  2453. const start = this.state.pos;
  2454. const end = this.input.indexOf(commentEnd, start + 2);
  2455. if (end === -1) {
  2456. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  2457. }
  2458. this.state.pos = end + commentEnd.length;
  2459. lineBreakG.lastIndex = start + 2;
  2460. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2461. ++this.state.curLine;
  2462. this.state.lineStart = lineBreakG.lastIndex;
  2463. }
  2464. if (this.isLookahead) return;
  2465. const comment = {
  2466. type: "CommentBlock",
  2467. value: this.input.slice(start + 2, end),
  2468. start: this.sourceToOffsetPos(start),
  2469. end: this.sourceToOffsetPos(end + commentEnd.length),
  2470. loc: new SourceLocation(startLoc, this.state.curPosition())
  2471. };
  2472. if (this.options.tokens) this.pushToken(comment);
  2473. return comment;
  2474. }
  2475. skipLineComment(startSkip) {
  2476. const start = this.state.pos;
  2477. let startLoc;
  2478. if (!this.isLookahead) startLoc = this.state.curPosition();
  2479. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2480. if (this.state.pos < this.length) {
  2481. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2482. ch = this.input.charCodeAt(this.state.pos);
  2483. }
  2484. }
  2485. if (this.isLookahead) return;
  2486. const end = this.state.pos;
  2487. const value = this.input.slice(start + startSkip, end);
  2488. const comment = {
  2489. type: "CommentLine",
  2490. value,
  2491. start: this.sourceToOffsetPos(start),
  2492. end: this.sourceToOffsetPos(end),
  2493. loc: new SourceLocation(startLoc, this.state.curPosition())
  2494. };
  2495. if (this.options.tokens) this.pushToken(comment);
  2496. return comment;
  2497. }
  2498. skipSpace() {
  2499. const spaceStart = this.state.pos;
  2500. const comments = [];
  2501. loop: while (this.state.pos < this.length) {
  2502. const ch = this.input.charCodeAt(this.state.pos);
  2503. switch (ch) {
  2504. case 32:
  2505. case 160:
  2506. case 9:
  2507. ++this.state.pos;
  2508. break;
  2509. case 13:
  2510. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2511. ++this.state.pos;
  2512. }
  2513. case 10:
  2514. case 8232:
  2515. case 8233:
  2516. ++this.state.pos;
  2517. ++this.state.curLine;
  2518. this.state.lineStart = this.state.pos;
  2519. break;
  2520. case 47:
  2521. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2522. case 42:
  2523. {
  2524. const comment = this.skipBlockComment("*/");
  2525. if (comment !== undefined) {
  2526. this.addComment(comment);
  2527. if (this.options.attachComment) comments.push(comment);
  2528. }
  2529. break;
  2530. }
  2531. case 47:
  2532. {
  2533. const comment = this.skipLineComment(2);
  2534. if (comment !== undefined) {
  2535. this.addComment(comment);
  2536. if (this.options.attachComment) comments.push(comment);
  2537. }
  2538. break;
  2539. }
  2540. default:
  2541. break loop;
  2542. }
  2543. break;
  2544. default:
  2545. if (isWhitespace(ch)) {
  2546. ++this.state.pos;
  2547. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2548. const pos = this.state.pos;
  2549. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2550. const comment = this.skipLineComment(3);
  2551. if (comment !== undefined) {
  2552. this.addComment(comment);
  2553. if (this.options.attachComment) comments.push(comment);
  2554. }
  2555. } else {
  2556. break loop;
  2557. }
  2558. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2559. const pos = this.state.pos;
  2560. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2561. const comment = this.skipLineComment(4);
  2562. if (comment !== undefined) {
  2563. this.addComment(comment);
  2564. if (this.options.attachComment) comments.push(comment);
  2565. }
  2566. } else {
  2567. break loop;
  2568. }
  2569. } else {
  2570. break loop;
  2571. }
  2572. }
  2573. }
  2574. if (comments.length > 0) {
  2575. const end = this.state.pos;
  2576. const commentWhitespace = {
  2577. start: this.sourceToOffsetPos(spaceStart),
  2578. end: this.sourceToOffsetPos(end),
  2579. comments,
  2580. leadingNode: null,
  2581. trailingNode: null,
  2582. containingNode: null
  2583. };
  2584. this.state.commentStack.push(commentWhitespace);
  2585. }
  2586. }
  2587. finishToken(type, val) {
  2588. this.state.end = this.state.pos;
  2589. this.state.endLoc = this.state.curPosition();
  2590. const prevType = this.state.type;
  2591. this.state.type = type;
  2592. this.state.value = val;
  2593. if (!this.isLookahead) {
  2594. this.updateContext(prevType);
  2595. }
  2596. }
  2597. replaceToken(type) {
  2598. this.state.type = type;
  2599. this.updateContext();
  2600. }
  2601. readToken_numberSign() {
  2602. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2603. return;
  2604. }
  2605. const nextPos = this.state.pos + 1;
  2606. const next = this.codePointAtPos(nextPos);
  2607. if (next >= 48 && next <= 57) {
  2608. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  2609. }
  2610. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2611. this.expectPlugin("recordAndTuple");
  2612. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2613. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  2614. }
  2615. this.state.pos += 2;
  2616. if (next === 123) {
  2617. this.finishToken(7);
  2618. } else {
  2619. this.finishToken(1);
  2620. }
  2621. } else if (isIdentifierStart(next)) {
  2622. ++this.state.pos;
  2623. this.finishToken(139, this.readWord1(next));
  2624. } else if (next === 92) {
  2625. ++this.state.pos;
  2626. this.finishToken(139, this.readWord1());
  2627. } else {
  2628. this.finishOp(27, 1);
  2629. }
  2630. }
  2631. readToken_dot() {
  2632. const next = this.input.charCodeAt(this.state.pos + 1);
  2633. if (next >= 48 && next <= 57) {
  2634. this.readNumber(true);
  2635. return;
  2636. }
  2637. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2638. this.state.pos += 3;
  2639. this.finishToken(21);
  2640. } else {
  2641. ++this.state.pos;
  2642. this.finishToken(16);
  2643. }
  2644. }
  2645. readToken_slash() {
  2646. const next = this.input.charCodeAt(this.state.pos + 1);
  2647. if (next === 61) {
  2648. this.finishOp(31, 2);
  2649. } else {
  2650. this.finishOp(56, 1);
  2651. }
  2652. }
  2653. readToken_interpreter() {
  2654. if (this.state.pos !== 0 || this.length < 2) return false;
  2655. let ch = this.input.charCodeAt(this.state.pos + 1);
  2656. if (ch !== 33) return false;
  2657. const start = this.state.pos;
  2658. this.state.pos += 1;
  2659. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2660. ch = this.input.charCodeAt(this.state.pos);
  2661. }
  2662. const value = this.input.slice(start + 2, this.state.pos);
  2663. this.finishToken(28, value);
  2664. return true;
  2665. }
  2666. readToken_mult_modulo(code) {
  2667. let type = code === 42 ? 55 : 54;
  2668. let width = 1;
  2669. let next = this.input.charCodeAt(this.state.pos + 1);
  2670. if (code === 42 && next === 42) {
  2671. width++;
  2672. next = this.input.charCodeAt(this.state.pos + 2);
  2673. type = 57;
  2674. }
  2675. if (next === 61 && !this.state.inType) {
  2676. width++;
  2677. type = code === 37 ? 33 : 30;
  2678. }
  2679. this.finishOp(type, width);
  2680. }
  2681. readToken_pipe_amp(code) {
  2682. const next = this.input.charCodeAt(this.state.pos + 1);
  2683. if (next === code) {
  2684. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2685. this.finishOp(30, 3);
  2686. } else {
  2687. this.finishOp(code === 124 ? 41 : 42, 2);
  2688. }
  2689. return;
  2690. }
  2691. if (code === 124) {
  2692. if (next === 62) {
  2693. this.finishOp(39, 2);
  2694. return;
  2695. }
  2696. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2697. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2698. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2699. }
  2700. this.state.pos += 2;
  2701. this.finishToken(9);
  2702. return;
  2703. }
  2704. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2705. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2706. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2707. }
  2708. this.state.pos += 2;
  2709. this.finishToken(4);
  2710. return;
  2711. }
  2712. }
  2713. if (next === 61) {
  2714. this.finishOp(30, 2);
  2715. return;
  2716. }
  2717. this.finishOp(code === 124 ? 43 : 45, 1);
  2718. }
  2719. readToken_caret() {
  2720. const next = this.input.charCodeAt(this.state.pos + 1);
  2721. if (next === 61 && !this.state.inType) {
  2722. this.finishOp(32, 2);
  2723. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2724. proposal: "hack",
  2725. topicToken: "^^"
  2726. }])) {
  2727. this.finishOp(37, 2);
  2728. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2729. if (lookaheadCh === 94) {
  2730. this.unexpected();
  2731. }
  2732. } else {
  2733. this.finishOp(44, 1);
  2734. }
  2735. }
  2736. readToken_atSign() {
  2737. const next = this.input.charCodeAt(this.state.pos + 1);
  2738. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2739. proposal: "hack",
  2740. topicToken: "@@"
  2741. }])) {
  2742. this.finishOp(38, 2);
  2743. } else {
  2744. this.finishOp(26, 1);
  2745. }
  2746. }
  2747. readToken_plus_min(code) {
  2748. const next = this.input.charCodeAt(this.state.pos + 1);
  2749. if (next === code) {
  2750. this.finishOp(34, 2);
  2751. return;
  2752. }
  2753. if (next === 61) {
  2754. this.finishOp(30, 2);
  2755. } else {
  2756. this.finishOp(53, 1);
  2757. }
  2758. }
  2759. readToken_lt() {
  2760. const {
  2761. pos
  2762. } = this.state;
  2763. const next = this.input.charCodeAt(pos + 1);
  2764. if (next === 60) {
  2765. if (this.input.charCodeAt(pos + 2) === 61) {
  2766. this.finishOp(30, 3);
  2767. return;
  2768. }
  2769. this.finishOp(51, 2);
  2770. return;
  2771. }
  2772. if (next === 61) {
  2773. this.finishOp(49, 2);
  2774. return;
  2775. }
  2776. this.finishOp(47, 1);
  2777. }
  2778. readToken_gt() {
  2779. const {
  2780. pos
  2781. } = this.state;
  2782. const next = this.input.charCodeAt(pos + 1);
  2783. if (next === 62) {
  2784. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2785. if (this.input.charCodeAt(pos + size) === 61) {
  2786. this.finishOp(30, size + 1);
  2787. return;
  2788. }
  2789. this.finishOp(52, size);
  2790. return;
  2791. }
  2792. if (next === 61) {
  2793. this.finishOp(49, 2);
  2794. return;
  2795. }
  2796. this.finishOp(48, 1);
  2797. }
  2798. readToken_eq_excl(code) {
  2799. const next = this.input.charCodeAt(this.state.pos + 1);
  2800. if (next === 61) {
  2801. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2802. return;
  2803. }
  2804. if (code === 61 && next === 62) {
  2805. this.state.pos += 2;
  2806. this.finishToken(19);
  2807. return;
  2808. }
  2809. this.finishOp(code === 61 ? 29 : 35, 1);
  2810. }
  2811. readToken_question() {
  2812. const next = this.input.charCodeAt(this.state.pos + 1);
  2813. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2814. if (next === 63) {
  2815. if (next2 === 61) {
  2816. this.finishOp(30, 3);
  2817. } else {
  2818. this.finishOp(40, 2);
  2819. }
  2820. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2821. this.state.pos += 2;
  2822. this.finishToken(18);
  2823. } else {
  2824. ++this.state.pos;
  2825. this.finishToken(17);
  2826. }
  2827. }
  2828. getTokenFromCode(code) {
  2829. switch (code) {
  2830. case 46:
  2831. this.readToken_dot();
  2832. return;
  2833. case 40:
  2834. ++this.state.pos;
  2835. this.finishToken(10);
  2836. return;
  2837. case 41:
  2838. ++this.state.pos;
  2839. this.finishToken(11);
  2840. return;
  2841. case 59:
  2842. ++this.state.pos;
  2843. this.finishToken(13);
  2844. return;
  2845. case 44:
  2846. ++this.state.pos;
  2847. this.finishToken(12);
  2848. return;
  2849. case 91:
  2850. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2851. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2852. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2853. }
  2854. this.state.pos += 2;
  2855. this.finishToken(2);
  2856. } else {
  2857. ++this.state.pos;
  2858. this.finishToken(0);
  2859. }
  2860. return;
  2861. case 93:
  2862. ++this.state.pos;
  2863. this.finishToken(3);
  2864. return;
  2865. case 123:
  2866. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2867. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2868. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2869. }
  2870. this.state.pos += 2;
  2871. this.finishToken(6);
  2872. } else {
  2873. ++this.state.pos;
  2874. this.finishToken(5);
  2875. }
  2876. return;
  2877. case 125:
  2878. ++this.state.pos;
  2879. this.finishToken(8);
  2880. return;
  2881. case 58:
  2882. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2883. this.finishOp(15, 2);
  2884. } else {
  2885. ++this.state.pos;
  2886. this.finishToken(14);
  2887. }
  2888. return;
  2889. case 63:
  2890. this.readToken_question();
  2891. return;
  2892. case 96:
  2893. this.readTemplateToken();
  2894. return;
  2895. case 48:
  2896. {
  2897. const next = this.input.charCodeAt(this.state.pos + 1);
  2898. if (next === 120 || next === 88) {
  2899. this.readRadixNumber(16);
  2900. return;
  2901. }
  2902. if (next === 111 || next === 79) {
  2903. this.readRadixNumber(8);
  2904. return;
  2905. }
  2906. if (next === 98 || next === 66) {
  2907. this.readRadixNumber(2);
  2908. return;
  2909. }
  2910. }
  2911. case 49:
  2912. case 50:
  2913. case 51:
  2914. case 52:
  2915. case 53:
  2916. case 54:
  2917. case 55:
  2918. case 56:
  2919. case 57:
  2920. this.readNumber(false);
  2921. return;
  2922. case 34:
  2923. case 39:
  2924. this.readString(code);
  2925. return;
  2926. case 47:
  2927. this.readToken_slash();
  2928. return;
  2929. case 37:
  2930. case 42:
  2931. this.readToken_mult_modulo(code);
  2932. return;
  2933. case 124:
  2934. case 38:
  2935. this.readToken_pipe_amp(code);
  2936. return;
  2937. case 94:
  2938. this.readToken_caret();
  2939. return;
  2940. case 43:
  2941. case 45:
  2942. this.readToken_plus_min(code);
  2943. return;
  2944. case 60:
  2945. this.readToken_lt();
  2946. return;
  2947. case 62:
  2948. this.readToken_gt();
  2949. return;
  2950. case 61:
  2951. case 33:
  2952. this.readToken_eq_excl(code);
  2953. return;
  2954. case 126:
  2955. this.finishOp(36, 1);
  2956. return;
  2957. case 64:
  2958. this.readToken_atSign();
  2959. return;
  2960. case 35:
  2961. this.readToken_numberSign();
  2962. return;
  2963. case 92:
  2964. this.readWord();
  2965. return;
  2966. default:
  2967. if (isIdentifierStart(code)) {
  2968. this.readWord(code);
  2969. return;
  2970. }
  2971. }
  2972. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  2973. unexpected: String.fromCodePoint(code)
  2974. });
  2975. }
  2976. finishOp(type, size) {
  2977. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2978. this.state.pos += size;
  2979. this.finishToken(type, str);
  2980. }
  2981. readRegexp() {
  2982. const startLoc = this.state.startLoc;
  2983. const start = this.state.start + 1;
  2984. let escaped, inClass;
  2985. let {
  2986. pos
  2987. } = this.state;
  2988. for (;; ++pos) {
  2989. if (pos >= this.length) {
  2990. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  2991. }
  2992. const ch = this.input.charCodeAt(pos);
  2993. if (isNewLine(ch)) {
  2994. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  2995. }
  2996. if (escaped) {
  2997. escaped = false;
  2998. } else {
  2999. if (ch === 91) {
  3000. inClass = true;
  3001. } else if (ch === 93 && inClass) {
  3002. inClass = false;
  3003. } else if (ch === 47 && !inClass) {
  3004. break;
  3005. }
  3006. escaped = ch === 92;
  3007. }
  3008. }
  3009. const content = this.input.slice(start, pos);
  3010. ++pos;
  3011. let mods = "";
  3012. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  3013. while (pos < this.length) {
  3014. const cp = this.codePointAtPos(pos);
  3015. const char = String.fromCharCode(cp);
  3016. if (VALID_REGEX_FLAGS.has(cp)) {
  3017. if (cp === 118) {
  3018. if (mods.includes("u")) {
  3019. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3020. }
  3021. } else if (cp === 117) {
  3022. if (mods.includes("v")) {
  3023. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3024. }
  3025. }
  3026. if (mods.includes(char)) {
  3027. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  3028. }
  3029. } else if (isIdentifierChar(cp) || cp === 92) {
  3030. this.raise(Errors.MalformedRegExpFlags, nextPos());
  3031. } else {
  3032. break;
  3033. }
  3034. ++pos;
  3035. mods += char;
  3036. }
  3037. this.state.pos = pos;
  3038. this.finishToken(138, {
  3039. pattern: content,
  3040. flags: mods
  3041. });
  3042. }
  3043. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3044. const {
  3045. n,
  3046. pos
  3047. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3048. this.state.pos = pos;
  3049. return n;
  3050. }
  3051. readRadixNumber(radix) {
  3052. const start = this.state.pos;
  3053. const startLoc = this.state.curPosition();
  3054. let isBigInt = false;
  3055. this.state.pos += 2;
  3056. const val = this.readInt(radix);
  3057. if (val == null) {
  3058. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  3059. radix
  3060. });
  3061. }
  3062. const next = this.input.charCodeAt(this.state.pos);
  3063. if (next === 110) {
  3064. ++this.state.pos;
  3065. isBigInt = true;
  3066. } else if (next === 109) {
  3067. throw this.raise(Errors.InvalidDecimal, startLoc);
  3068. }
  3069. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3070. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3071. }
  3072. if (isBigInt) {
  3073. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  3074. this.finishToken(136, str);
  3075. return;
  3076. }
  3077. this.finishToken(135, val);
  3078. }
  3079. readNumber(startsWithDot) {
  3080. const start = this.state.pos;
  3081. const startLoc = this.state.curPosition();
  3082. let isFloat = false;
  3083. let isBigInt = false;
  3084. let hasExponent = false;
  3085. let isOctal = false;
  3086. if (!startsWithDot && this.readInt(10) === null) {
  3087. this.raise(Errors.InvalidNumber, this.state.curPosition());
  3088. }
  3089. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3090. if (hasLeadingZero) {
  3091. const integer = this.input.slice(start, this.state.pos);
  3092. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  3093. if (!this.state.strict) {
  3094. const underscorePos = integer.indexOf("_");
  3095. if (underscorePos > 0) {
  3096. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  3097. }
  3098. }
  3099. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3100. }
  3101. let next = this.input.charCodeAt(this.state.pos);
  3102. if (next === 46 && !isOctal) {
  3103. ++this.state.pos;
  3104. this.readInt(10);
  3105. isFloat = true;
  3106. next = this.input.charCodeAt(this.state.pos);
  3107. }
  3108. if ((next === 69 || next === 101) && !isOctal) {
  3109. next = this.input.charCodeAt(++this.state.pos);
  3110. if (next === 43 || next === 45) {
  3111. ++this.state.pos;
  3112. }
  3113. if (this.readInt(10) === null) {
  3114. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  3115. }
  3116. isFloat = true;
  3117. hasExponent = true;
  3118. next = this.input.charCodeAt(this.state.pos);
  3119. }
  3120. if (next === 110) {
  3121. if (isFloat || hasLeadingZero) {
  3122. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  3123. }
  3124. ++this.state.pos;
  3125. isBigInt = true;
  3126. }
  3127. if (next === 109) {
  3128. this.expectPlugin("decimal", this.state.curPosition());
  3129. if (hasExponent || hasLeadingZero) {
  3130. this.raise(Errors.InvalidDecimal, startLoc);
  3131. }
  3132. ++this.state.pos;
  3133. var isDecimal = true;
  3134. }
  3135. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3136. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3137. }
  3138. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3139. if (isBigInt) {
  3140. this.finishToken(136, str);
  3141. return;
  3142. }
  3143. if (isDecimal) {
  3144. this.finishToken(137, str);
  3145. return;
  3146. }
  3147. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3148. this.finishToken(135, val);
  3149. }
  3150. readCodePoint(throwOnInvalid) {
  3151. const {
  3152. code,
  3153. pos
  3154. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3155. this.state.pos = pos;
  3156. return code;
  3157. }
  3158. readString(quote) {
  3159. const {
  3160. str,
  3161. pos,
  3162. curLine,
  3163. lineStart
  3164. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3165. this.state.pos = pos + 1;
  3166. this.state.lineStart = lineStart;
  3167. this.state.curLine = curLine;
  3168. this.finishToken(134, str);
  3169. }
  3170. readTemplateContinuation() {
  3171. if (!this.match(8)) {
  3172. this.unexpected(null, 8);
  3173. }
  3174. this.state.pos--;
  3175. this.readTemplateToken();
  3176. }
  3177. readTemplateToken() {
  3178. const opening = this.input[this.state.pos];
  3179. const {
  3180. str,
  3181. firstInvalidLoc,
  3182. pos,
  3183. curLine,
  3184. lineStart
  3185. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3186. this.state.pos = pos + 1;
  3187. this.state.lineStart = lineStart;
  3188. this.state.curLine = curLine;
  3189. if (firstInvalidLoc) {
  3190. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  3191. }
  3192. if (this.input.codePointAt(pos) === 96) {
  3193. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3194. } else {
  3195. this.state.pos++;
  3196. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3197. }
  3198. }
  3199. recordStrictModeErrors(toParseError, at) {
  3200. const index = at.index;
  3201. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3202. this.raise(toParseError, at);
  3203. } else {
  3204. this.state.strictErrors.set(index, [toParseError, at]);
  3205. }
  3206. }
  3207. readWord1(firstCode) {
  3208. this.state.containsEsc = false;
  3209. let word = "";
  3210. const start = this.state.pos;
  3211. let chunkStart = this.state.pos;
  3212. if (firstCode !== undefined) {
  3213. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3214. }
  3215. while (this.state.pos < this.length) {
  3216. const ch = this.codePointAtPos(this.state.pos);
  3217. if (isIdentifierChar(ch)) {
  3218. this.state.pos += ch <= 0xffff ? 1 : 2;
  3219. } else if (ch === 92) {
  3220. this.state.containsEsc = true;
  3221. word += this.input.slice(chunkStart, this.state.pos);
  3222. const escStart = this.state.curPosition();
  3223. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3224. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3225. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  3226. chunkStart = this.state.pos - 1;
  3227. continue;
  3228. }
  3229. ++this.state.pos;
  3230. const esc = this.readCodePoint(true);
  3231. if (esc !== null) {
  3232. if (!identifierCheck(esc)) {
  3233. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  3234. }
  3235. word += String.fromCodePoint(esc);
  3236. }
  3237. chunkStart = this.state.pos;
  3238. } else {
  3239. break;
  3240. }
  3241. }
  3242. return word + this.input.slice(chunkStart, this.state.pos);
  3243. }
  3244. readWord(firstCode) {
  3245. const word = this.readWord1(firstCode);
  3246. const type = keywords$1.get(word);
  3247. if (type !== undefined) {
  3248. this.finishToken(type, tokenLabelName(type));
  3249. } else {
  3250. this.finishToken(132, word);
  3251. }
  3252. }
  3253. checkKeywordEscapes() {
  3254. const {
  3255. type
  3256. } = this.state;
  3257. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3258. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  3259. reservedWord: tokenLabelName(type)
  3260. });
  3261. }
  3262. }
  3263. raise(toParseError, at, details = {}) {
  3264. const loc = at instanceof Position ? at : at.loc.start;
  3265. const error = toParseError(loc, details);
  3266. if (!this.options.errorRecovery) throw error;
  3267. if (!this.isLookahead) this.state.errors.push(error);
  3268. return error;
  3269. }
  3270. raiseOverwrite(toParseError, at, details = {}) {
  3271. const loc = at instanceof Position ? at : at.loc.start;
  3272. const pos = loc.index;
  3273. const errors = this.state.errors;
  3274. for (let i = errors.length - 1; i >= 0; i--) {
  3275. const error = errors[i];
  3276. if (error.loc.index === pos) {
  3277. return errors[i] = toParseError(loc, details);
  3278. }
  3279. if (error.loc.index < pos) break;
  3280. }
  3281. return this.raise(toParseError, at, details);
  3282. }
  3283. updateContext(prevType) {}
  3284. unexpected(loc, type) {
  3285. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  3286. expected: type ? tokenLabelName(type) : null
  3287. });
  3288. }
  3289. expectPlugin(pluginName, loc) {
  3290. if (this.hasPlugin(pluginName)) {
  3291. return true;
  3292. }
  3293. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  3294. missingPlugin: [pluginName]
  3295. });
  3296. }
  3297. expectOnePlugin(pluginNames) {
  3298. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3299. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  3300. missingPlugin: pluginNames
  3301. });
  3302. }
  3303. }
  3304. errorBuilder(error) {
  3305. return (pos, lineStart, curLine) => {
  3306. this.raise(error, buildPosition(pos, lineStart, curLine));
  3307. };
  3308. }
  3309. }
  3310. class ClassScope {
  3311. constructor() {
  3312. this.privateNames = new Set();
  3313. this.loneAccessors = new Map();
  3314. this.undefinedPrivateNames = new Map();
  3315. }
  3316. }
  3317. class ClassScopeHandler {
  3318. constructor(parser) {
  3319. this.parser = void 0;
  3320. this.stack = [];
  3321. this.undefinedPrivateNames = new Map();
  3322. this.parser = parser;
  3323. }
  3324. current() {
  3325. return this.stack[this.stack.length - 1];
  3326. }
  3327. enter() {
  3328. this.stack.push(new ClassScope());
  3329. }
  3330. exit() {
  3331. const oldClassScope = this.stack.pop();
  3332. const current = this.current();
  3333. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3334. if (current) {
  3335. if (!current.undefinedPrivateNames.has(name)) {
  3336. current.undefinedPrivateNames.set(name, loc);
  3337. }
  3338. } else {
  3339. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3340. identifierName: name
  3341. });
  3342. }
  3343. }
  3344. }
  3345. declarePrivateName(name, elementType, loc) {
  3346. const {
  3347. privateNames,
  3348. loneAccessors,
  3349. undefinedPrivateNames
  3350. } = this.current();
  3351. let redefined = privateNames.has(name);
  3352. if (elementType & 3) {
  3353. const accessor = redefined && loneAccessors.get(name);
  3354. if (accessor) {
  3355. const oldStatic = accessor & 4;
  3356. const newStatic = elementType & 4;
  3357. const oldKind = accessor & 3;
  3358. const newKind = elementType & 3;
  3359. redefined = oldKind === newKind || oldStatic !== newStatic;
  3360. if (!redefined) loneAccessors.delete(name);
  3361. } else if (!redefined) {
  3362. loneAccessors.set(name, elementType);
  3363. }
  3364. }
  3365. if (redefined) {
  3366. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  3367. identifierName: name
  3368. });
  3369. }
  3370. privateNames.add(name);
  3371. undefinedPrivateNames.delete(name);
  3372. }
  3373. usePrivateName(name, loc) {
  3374. let classScope;
  3375. for (classScope of this.stack) {
  3376. if (classScope.privateNames.has(name)) return;
  3377. }
  3378. if (classScope) {
  3379. classScope.undefinedPrivateNames.set(name, loc);
  3380. } else {
  3381. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3382. identifierName: name
  3383. });
  3384. }
  3385. }
  3386. }
  3387. class ExpressionScope {
  3388. constructor(type = 0) {
  3389. this.type = type;
  3390. }
  3391. canBeArrowParameterDeclaration() {
  3392. return this.type === 2 || this.type === 1;
  3393. }
  3394. isCertainlyParameterDeclaration() {
  3395. return this.type === 3;
  3396. }
  3397. }
  3398. class ArrowHeadParsingScope extends ExpressionScope {
  3399. constructor(type) {
  3400. super(type);
  3401. this.declarationErrors = new Map();
  3402. }
  3403. recordDeclarationError(ParsingErrorClass, at) {
  3404. const index = at.index;
  3405. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3406. }
  3407. clearDeclarationError(index) {
  3408. this.declarationErrors.delete(index);
  3409. }
  3410. iterateErrors(iterator) {
  3411. this.declarationErrors.forEach(iterator);
  3412. }
  3413. }
  3414. class ExpressionScopeHandler {
  3415. constructor(parser) {
  3416. this.parser = void 0;
  3417. this.stack = [new ExpressionScope()];
  3418. this.parser = parser;
  3419. }
  3420. enter(scope) {
  3421. this.stack.push(scope);
  3422. }
  3423. exit() {
  3424. this.stack.pop();
  3425. }
  3426. recordParameterInitializerError(toParseError, node) {
  3427. const origin = node.loc.start;
  3428. const {
  3429. stack
  3430. } = this;
  3431. let i = stack.length - 1;
  3432. let scope = stack[i];
  3433. while (!scope.isCertainlyParameterDeclaration()) {
  3434. if (scope.canBeArrowParameterDeclaration()) {
  3435. scope.recordDeclarationError(toParseError, origin);
  3436. } else {
  3437. return;
  3438. }
  3439. scope = stack[--i];
  3440. }
  3441. this.parser.raise(toParseError, origin);
  3442. }
  3443. recordArrowParameterBindingError(error, node) {
  3444. const {
  3445. stack
  3446. } = this;
  3447. const scope = stack[stack.length - 1];
  3448. const origin = node.loc.start;
  3449. if (scope.isCertainlyParameterDeclaration()) {
  3450. this.parser.raise(error, origin);
  3451. } else if (scope.canBeArrowParameterDeclaration()) {
  3452. scope.recordDeclarationError(error, origin);
  3453. } else {
  3454. return;
  3455. }
  3456. }
  3457. recordAsyncArrowParametersError(at) {
  3458. const {
  3459. stack
  3460. } = this;
  3461. let i = stack.length - 1;
  3462. let scope = stack[i];
  3463. while (scope.canBeArrowParameterDeclaration()) {
  3464. if (scope.type === 2) {
  3465. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  3466. }
  3467. scope = stack[--i];
  3468. }
  3469. }
  3470. validateAsPattern() {
  3471. const {
  3472. stack
  3473. } = this;
  3474. const currentScope = stack[stack.length - 1];
  3475. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3476. currentScope.iterateErrors(([toParseError, loc]) => {
  3477. this.parser.raise(toParseError, loc);
  3478. let i = stack.length - 2;
  3479. let scope = stack[i];
  3480. while (scope.canBeArrowParameterDeclaration()) {
  3481. scope.clearDeclarationError(loc.index);
  3482. scope = stack[--i];
  3483. }
  3484. });
  3485. }
  3486. }
  3487. function newParameterDeclarationScope() {
  3488. return new ExpressionScope(3);
  3489. }
  3490. function newArrowHeadScope() {
  3491. return new ArrowHeadParsingScope(1);
  3492. }
  3493. function newAsyncArrowScope() {
  3494. return new ArrowHeadParsingScope(2);
  3495. }
  3496. function newExpressionScope() {
  3497. return new ExpressionScope();
  3498. }
  3499. class ProductionParameterHandler {
  3500. constructor() {
  3501. this.stacks = [];
  3502. }
  3503. enter(flags) {
  3504. this.stacks.push(flags);
  3505. }
  3506. exit() {
  3507. this.stacks.pop();
  3508. }
  3509. currentFlags() {
  3510. return this.stacks[this.stacks.length - 1];
  3511. }
  3512. get hasAwait() {
  3513. return (this.currentFlags() & 2) > 0;
  3514. }
  3515. get hasYield() {
  3516. return (this.currentFlags() & 1) > 0;
  3517. }
  3518. get hasReturn() {
  3519. return (this.currentFlags() & 4) > 0;
  3520. }
  3521. get hasIn() {
  3522. return (this.currentFlags() & 8) > 0;
  3523. }
  3524. }
  3525. function functionFlags(isAsync, isGenerator) {
  3526. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  3527. }
  3528. class UtilParser extends Tokenizer {
  3529. addExtra(node, key, value, enumerable = true) {
  3530. if (!node) return;
  3531. let {
  3532. extra
  3533. } = node;
  3534. if (extra == null) {
  3535. extra = {};
  3536. node.extra = extra;
  3537. }
  3538. if (enumerable) {
  3539. extra[key] = value;
  3540. } else {
  3541. Object.defineProperty(extra, key, {
  3542. enumerable,
  3543. value
  3544. });
  3545. }
  3546. }
  3547. isContextual(token) {
  3548. return this.state.type === token && !this.state.containsEsc;
  3549. }
  3550. isUnparsedContextual(nameStart, name) {
  3551. const nameEnd = nameStart + name.length;
  3552. if (this.input.slice(nameStart, nameEnd) === name) {
  3553. const nextCh = this.input.charCodeAt(nameEnd);
  3554. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3555. }
  3556. return false;
  3557. }
  3558. isLookaheadContextual(name) {
  3559. const next = this.nextTokenStart();
  3560. return this.isUnparsedContextual(next, name);
  3561. }
  3562. eatContextual(token) {
  3563. if (this.isContextual(token)) {
  3564. this.next();
  3565. return true;
  3566. }
  3567. return false;
  3568. }
  3569. expectContextual(token, toParseError) {
  3570. if (!this.eatContextual(token)) {
  3571. if (toParseError != null) {
  3572. throw this.raise(toParseError, this.state.startLoc);
  3573. }
  3574. this.unexpected(null, token);
  3575. }
  3576. }
  3577. canInsertSemicolon() {
  3578. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  3579. }
  3580. hasPrecedingLineBreak() {
  3581. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  3582. }
  3583. hasFollowingLineBreak() {
  3584. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  3585. }
  3586. isLineTerminator() {
  3587. return this.eat(13) || this.canInsertSemicolon();
  3588. }
  3589. semicolon(allowAsi = true) {
  3590. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3591. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  3592. }
  3593. expect(type, loc) {
  3594. if (!this.eat(type)) {
  3595. this.unexpected(loc, type);
  3596. }
  3597. }
  3598. tryParse(fn, oldState = this.state.clone()) {
  3599. const abortSignal = {
  3600. node: null
  3601. };
  3602. try {
  3603. const node = fn((node = null) => {
  3604. abortSignal.node = node;
  3605. throw abortSignal;
  3606. });
  3607. if (this.state.errors.length > oldState.errors.length) {
  3608. const failState = this.state;
  3609. this.state = oldState;
  3610. this.state.tokensLength = failState.tokensLength;
  3611. return {
  3612. node,
  3613. error: failState.errors[oldState.errors.length],
  3614. thrown: false,
  3615. aborted: false,
  3616. failState
  3617. };
  3618. }
  3619. return {
  3620. node,
  3621. error: null,
  3622. thrown: false,
  3623. aborted: false,
  3624. failState: null
  3625. };
  3626. } catch (error) {
  3627. const failState = this.state;
  3628. this.state = oldState;
  3629. if (error instanceof SyntaxError) {
  3630. return {
  3631. node: null,
  3632. error,
  3633. thrown: true,
  3634. aborted: false,
  3635. failState
  3636. };
  3637. }
  3638. if (error === abortSignal) {
  3639. return {
  3640. node: abortSignal.node,
  3641. error: null,
  3642. thrown: false,
  3643. aborted: true,
  3644. failState
  3645. };
  3646. }
  3647. throw error;
  3648. }
  3649. }
  3650. checkExpressionErrors(refExpressionErrors, andThrow) {
  3651. if (!refExpressionErrors) return false;
  3652. const {
  3653. shorthandAssignLoc,
  3654. doubleProtoLoc,
  3655. privateKeyLoc,
  3656. optionalParametersLoc
  3657. } = refExpressionErrors;
  3658. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3659. if (!andThrow) {
  3660. return hasErrors;
  3661. }
  3662. if (shorthandAssignLoc != null) {
  3663. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  3664. }
  3665. if (doubleProtoLoc != null) {
  3666. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  3667. }
  3668. if (privateKeyLoc != null) {
  3669. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  3670. }
  3671. if (optionalParametersLoc != null) {
  3672. this.unexpected(optionalParametersLoc);
  3673. }
  3674. }
  3675. isLiteralPropertyName() {
  3676. return tokenIsLiteralPropertyName(this.state.type);
  3677. }
  3678. isPrivateName(node) {
  3679. return node.type === "PrivateName";
  3680. }
  3681. getPrivateNameSV(node) {
  3682. return node.id.name;
  3683. }
  3684. hasPropertyAsPrivateName(node) {
  3685. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3686. }
  3687. isObjectProperty(node) {
  3688. return node.type === "ObjectProperty";
  3689. }
  3690. isObjectMethod(node) {
  3691. return node.type === "ObjectMethod";
  3692. }
  3693. initializeScopes(inModule = this.options.sourceType === "module") {
  3694. const oldLabels = this.state.labels;
  3695. this.state.labels = [];
  3696. const oldExportedIdentifiers = this.exportedIdentifiers;
  3697. this.exportedIdentifiers = new Set();
  3698. const oldInModule = this.inModule;
  3699. this.inModule = inModule;
  3700. const oldScope = this.scope;
  3701. const ScopeHandler = this.getScopeHandler();
  3702. this.scope = new ScopeHandler(this, inModule);
  3703. const oldProdParam = this.prodParam;
  3704. this.prodParam = new ProductionParameterHandler();
  3705. const oldClassScope = this.classScope;
  3706. this.classScope = new ClassScopeHandler(this);
  3707. const oldExpressionScope = this.expressionScope;
  3708. this.expressionScope = new ExpressionScopeHandler(this);
  3709. return () => {
  3710. this.state.labels = oldLabels;
  3711. this.exportedIdentifiers = oldExportedIdentifiers;
  3712. this.inModule = oldInModule;
  3713. this.scope = oldScope;
  3714. this.prodParam = oldProdParam;
  3715. this.classScope = oldClassScope;
  3716. this.expressionScope = oldExpressionScope;
  3717. };
  3718. }
  3719. enterInitialScopes() {
  3720. let paramFlags = 0;
  3721. if (this.inModule) {
  3722. paramFlags |= 2;
  3723. }
  3724. this.scope.enter(1);
  3725. this.prodParam.enter(paramFlags);
  3726. }
  3727. checkDestructuringPrivate(refExpressionErrors) {
  3728. const {
  3729. privateKeyLoc
  3730. } = refExpressionErrors;
  3731. if (privateKeyLoc !== null) {
  3732. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3733. }
  3734. }
  3735. }
  3736. class ExpressionErrors {
  3737. constructor() {
  3738. this.shorthandAssignLoc = null;
  3739. this.doubleProtoLoc = null;
  3740. this.privateKeyLoc = null;
  3741. this.optionalParametersLoc = null;
  3742. }
  3743. }
  3744. class Node {
  3745. constructor(parser, pos, loc) {
  3746. this.type = "";
  3747. this.start = pos;
  3748. this.end = 0;
  3749. this.loc = new SourceLocation(loc);
  3750. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3751. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3752. }
  3753. }
  3754. const NodePrototype = Node.prototype;
  3755. {
  3756. NodePrototype.__clone = function () {
  3757. const newNode = new Node(undefined, this.start, this.loc.start);
  3758. const keys = Object.keys(this);
  3759. for (let i = 0, length = keys.length; i < length; i++) {
  3760. const key = keys[i];
  3761. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3762. newNode[key] = this[key];
  3763. }
  3764. }
  3765. return newNode;
  3766. };
  3767. }
  3768. function clonePlaceholder(node) {
  3769. return cloneIdentifier(node);
  3770. }
  3771. function cloneIdentifier(node) {
  3772. const {
  3773. type,
  3774. start,
  3775. end,
  3776. loc,
  3777. range,
  3778. extra,
  3779. name
  3780. } = node;
  3781. const cloned = Object.create(NodePrototype);
  3782. cloned.type = type;
  3783. cloned.start = start;
  3784. cloned.end = end;
  3785. cloned.loc = loc;
  3786. cloned.range = range;
  3787. cloned.extra = extra;
  3788. cloned.name = name;
  3789. if (type === "Placeholder") {
  3790. cloned.expectedNode = node.expectedNode;
  3791. }
  3792. return cloned;
  3793. }
  3794. function cloneStringLiteral(node) {
  3795. const {
  3796. type,
  3797. start,
  3798. end,
  3799. loc,
  3800. range,
  3801. extra
  3802. } = node;
  3803. if (type === "Placeholder") {
  3804. return clonePlaceholder(node);
  3805. }
  3806. const cloned = Object.create(NodePrototype);
  3807. cloned.type = type;
  3808. cloned.start = start;
  3809. cloned.end = end;
  3810. cloned.loc = loc;
  3811. cloned.range = range;
  3812. if (node.raw !== undefined) {
  3813. cloned.raw = node.raw;
  3814. } else {
  3815. cloned.extra = extra;
  3816. }
  3817. cloned.value = node.value;
  3818. return cloned;
  3819. }
  3820. class NodeUtils extends UtilParser {
  3821. startNode() {
  3822. const loc = this.state.startLoc;
  3823. return new Node(this, loc.index, loc);
  3824. }
  3825. startNodeAt(loc) {
  3826. return new Node(this, loc.index, loc);
  3827. }
  3828. startNodeAtNode(type) {
  3829. return this.startNodeAt(type.loc.start);
  3830. }
  3831. finishNode(node, type) {
  3832. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3833. }
  3834. finishNodeAt(node, type, endLoc) {
  3835. node.type = type;
  3836. node.end = endLoc.index;
  3837. node.loc.end = endLoc;
  3838. if (this.options.ranges) node.range[1] = endLoc.index;
  3839. if (this.options.attachComment) this.processComment(node);
  3840. return node;
  3841. }
  3842. resetStartLocation(node, startLoc) {
  3843. node.start = startLoc.index;
  3844. node.loc.start = startLoc;
  3845. if (this.options.ranges) node.range[0] = startLoc.index;
  3846. }
  3847. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3848. node.end = endLoc.index;
  3849. node.loc.end = endLoc;
  3850. if (this.options.ranges) node.range[1] = endLoc.index;
  3851. }
  3852. resetStartLocationFromNode(node, locationNode) {
  3853. this.resetStartLocation(node, locationNode.loc.start);
  3854. }
  3855. }
  3856. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3857. const FlowErrors = ParseErrorEnum`flow`({
  3858. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3859. AmbiguousDeclareModuleKind: "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module.",
  3860. AssignReservedType: ({
  3861. reservedType
  3862. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3863. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3864. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3865. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3866. EnumBooleanMemberNotInitialized: ({
  3867. memberName,
  3868. enumName
  3869. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3870. EnumDuplicateMemberName: ({
  3871. memberName,
  3872. enumName
  3873. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3874. EnumInconsistentMemberValues: ({
  3875. enumName
  3876. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3877. EnumInvalidExplicitType: ({
  3878. invalidEnumType,
  3879. enumName
  3880. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3881. EnumInvalidExplicitTypeUnknownSupplied: ({
  3882. enumName
  3883. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3884. EnumInvalidMemberInitializerPrimaryType: ({
  3885. enumName,
  3886. memberName,
  3887. explicitType
  3888. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3889. EnumInvalidMemberInitializerSymbolType: ({
  3890. enumName,
  3891. memberName
  3892. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3893. EnumInvalidMemberInitializerUnknownType: ({
  3894. enumName,
  3895. memberName
  3896. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3897. EnumInvalidMemberName: ({
  3898. enumName,
  3899. memberName,
  3900. suggestion
  3901. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3902. EnumNumberMemberNotInitialized: ({
  3903. enumName,
  3904. memberName
  3905. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3906. EnumStringMemberInconsistentlyInitialized: ({
  3907. enumName
  3908. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3909. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3910. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3911. ImportTypeShorthandOnlyInPureImport: "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.",
  3912. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3913. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3914. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3915. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3916. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3917. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3918. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3919. PatternIsOptional: Object.assign({
  3920. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3921. }, {
  3922. reasonCode: "OptionalBindingPattern"
  3923. }),
  3924. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3925. SpreadVariance: "Spread properties cannot have variance.",
  3926. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3927. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3928. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3929. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3930. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3931. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3932. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3933. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3934. UnexpectedReservedType: ({
  3935. reservedType
  3936. }) => `Unexpected reserved type ${reservedType}.`,
  3937. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3938. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3939. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3940. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3941. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3942. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3943. UnsupportedDeclareExportKind: ({
  3944. unsupportedExportKind,
  3945. suggestion
  3946. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3947. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3948. UnterminatedFlowComment: "Unterminated flow-comment."
  3949. });
  3950. function isEsModuleType(bodyElement) {
  3951. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3952. }
  3953. function hasTypeImportKind(node) {
  3954. return node.importKind === "type" || node.importKind === "typeof";
  3955. }
  3956. const exportSuggestions = {
  3957. const: "declare export var",
  3958. let: "declare export var",
  3959. type: "export type",
  3960. interface: "export interface"
  3961. };
  3962. function partition(list, test) {
  3963. const list1 = [];
  3964. const list2 = [];
  3965. for (let i = 0; i < list.length; i++) {
  3966. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3967. }
  3968. return [list1, list2];
  3969. }
  3970. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3971. var flow = superClass => class FlowParserMixin extends superClass {
  3972. constructor(...args) {
  3973. super(...args);
  3974. this.flowPragma = undefined;
  3975. }
  3976. getScopeHandler() {
  3977. return FlowScopeHandler;
  3978. }
  3979. shouldParseTypes() {
  3980. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3981. }
  3982. finishToken(type, val) {
  3983. if (type !== 134 && type !== 13 && type !== 28) {
  3984. if (this.flowPragma === undefined) {
  3985. this.flowPragma = null;
  3986. }
  3987. }
  3988. super.finishToken(type, val);
  3989. }
  3990. addComment(comment) {
  3991. if (this.flowPragma === undefined) {
  3992. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  3993. if (!matches) ;else if (matches[1] === "flow") {
  3994. this.flowPragma = "flow";
  3995. } else if (matches[1] === "noflow") {
  3996. this.flowPragma = "noflow";
  3997. } else {
  3998. throw new Error("Unexpected flow pragma");
  3999. }
  4000. }
  4001. super.addComment(comment);
  4002. }
  4003. flowParseTypeInitialiser(tok) {
  4004. const oldInType = this.state.inType;
  4005. this.state.inType = true;
  4006. this.expect(tok || 14);
  4007. const type = this.flowParseType();
  4008. this.state.inType = oldInType;
  4009. return type;
  4010. }
  4011. flowParsePredicate() {
  4012. const node = this.startNode();
  4013. const moduloLoc = this.state.startLoc;
  4014. this.next();
  4015. this.expectContextual(110);
  4016. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  4017. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  4018. }
  4019. if (this.eat(10)) {
  4020. node.value = super.parseExpression();
  4021. this.expect(11);
  4022. return this.finishNode(node, "DeclaredPredicate");
  4023. } else {
  4024. return this.finishNode(node, "InferredPredicate");
  4025. }
  4026. }
  4027. flowParseTypeAndPredicateInitialiser() {
  4028. const oldInType = this.state.inType;
  4029. this.state.inType = true;
  4030. this.expect(14);
  4031. let type = null;
  4032. let predicate = null;
  4033. if (this.match(54)) {
  4034. this.state.inType = oldInType;
  4035. predicate = this.flowParsePredicate();
  4036. } else {
  4037. type = this.flowParseType();
  4038. this.state.inType = oldInType;
  4039. if (this.match(54)) {
  4040. predicate = this.flowParsePredicate();
  4041. }
  4042. }
  4043. return [type, predicate];
  4044. }
  4045. flowParseDeclareClass(node) {
  4046. this.next();
  4047. this.flowParseInterfaceish(node, true);
  4048. return this.finishNode(node, "DeclareClass");
  4049. }
  4050. flowParseDeclareFunction(node) {
  4051. this.next();
  4052. const id = node.id = this.parseIdentifier();
  4053. const typeNode = this.startNode();
  4054. const typeContainer = this.startNode();
  4055. if (this.match(47)) {
  4056. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4057. } else {
  4058. typeNode.typeParameters = null;
  4059. }
  4060. this.expect(10);
  4061. const tmp = this.flowParseFunctionTypeParams();
  4062. typeNode.params = tmp.params;
  4063. typeNode.rest = tmp.rest;
  4064. typeNode.this = tmp._this;
  4065. this.expect(11);
  4066. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4067. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4068. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4069. this.resetEndLocation(id);
  4070. this.semicolon();
  4071. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4072. return this.finishNode(node, "DeclareFunction");
  4073. }
  4074. flowParseDeclare(node, insideModule) {
  4075. if (this.match(80)) {
  4076. return this.flowParseDeclareClass(node);
  4077. } else if (this.match(68)) {
  4078. return this.flowParseDeclareFunction(node);
  4079. } else if (this.match(74)) {
  4080. return this.flowParseDeclareVariable(node);
  4081. } else if (this.eatContextual(127)) {
  4082. if (this.match(16)) {
  4083. return this.flowParseDeclareModuleExports(node);
  4084. } else {
  4085. if (insideModule) {
  4086. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  4087. }
  4088. return this.flowParseDeclareModule(node);
  4089. }
  4090. } else if (this.isContextual(130)) {
  4091. return this.flowParseDeclareTypeAlias(node);
  4092. } else if (this.isContextual(131)) {
  4093. return this.flowParseDeclareOpaqueType(node);
  4094. } else if (this.isContextual(129)) {
  4095. return this.flowParseDeclareInterface(node);
  4096. } else if (this.match(82)) {
  4097. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4098. } else {
  4099. this.unexpected();
  4100. }
  4101. }
  4102. flowParseDeclareVariable(node) {
  4103. this.next();
  4104. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4105. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4106. this.semicolon();
  4107. return this.finishNode(node, "DeclareVariable");
  4108. }
  4109. flowParseDeclareModule(node) {
  4110. this.scope.enter(0);
  4111. if (this.match(134)) {
  4112. node.id = super.parseExprAtom();
  4113. } else {
  4114. node.id = this.parseIdentifier();
  4115. }
  4116. const bodyNode = node.body = this.startNode();
  4117. const body = bodyNode.body = [];
  4118. this.expect(5);
  4119. while (!this.match(8)) {
  4120. let bodyNode = this.startNode();
  4121. if (this.match(83)) {
  4122. this.next();
  4123. if (!this.isContextual(130) && !this.match(87)) {
  4124. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  4125. }
  4126. super.parseImport(bodyNode);
  4127. } else {
  4128. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4129. bodyNode = this.flowParseDeclare(bodyNode, true);
  4130. }
  4131. body.push(bodyNode);
  4132. }
  4133. this.scope.exit();
  4134. this.expect(8);
  4135. this.finishNode(bodyNode, "BlockStatement");
  4136. let kind = null;
  4137. let hasModuleExport = false;
  4138. body.forEach(bodyElement => {
  4139. if (isEsModuleType(bodyElement)) {
  4140. if (kind === "CommonJS") {
  4141. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4142. }
  4143. kind = "ES";
  4144. } else if (bodyElement.type === "DeclareModuleExports") {
  4145. if (hasModuleExport) {
  4146. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  4147. }
  4148. if (kind === "ES") {
  4149. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4150. }
  4151. kind = "CommonJS";
  4152. hasModuleExport = true;
  4153. }
  4154. });
  4155. node.kind = kind || "CommonJS";
  4156. return this.finishNode(node, "DeclareModule");
  4157. }
  4158. flowParseDeclareExportDeclaration(node, insideModule) {
  4159. this.expect(82);
  4160. if (this.eat(65)) {
  4161. if (this.match(68) || this.match(80)) {
  4162. node.declaration = this.flowParseDeclare(this.startNode());
  4163. } else {
  4164. node.declaration = this.flowParseType();
  4165. this.semicolon();
  4166. }
  4167. node.default = true;
  4168. return this.finishNode(node, "DeclareExportDeclaration");
  4169. } else {
  4170. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4171. const label = this.state.value;
  4172. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  4173. unsupportedExportKind: label,
  4174. suggestion: exportSuggestions[label]
  4175. });
  4176. }
  4177. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4178. node.declaration = this.flowParseDeclare(this.startNode());
  4179. node.default = false;
  4180. return this.finishNode(node, "DeclareExportDeclaration");
  4181. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4182. node = this.parseExport(node, null);
  4183. if (node.type === "ExportNamedDeclaration") {
  4184. node.type = "ExportDeclaration";
  4185. node.default = false;
  4186. delete node.exportKind;
  4187. }
  4188. node.type = "Declare" + node.type;
  4189. return node;
  4190. }
  4191. }
  4192. this.unexpected();
  4193. }
  4194. flowParseDeclareModuleExports(node) {
  4195. this.next();
  4196. this.expectContextual(111);
  4197. node.typeAnnotation = this.flowParseTypeAnnotation();
  4198. this.semicolon();
  4199. return this.finishNode(node, "DeclareModuleExports");
  4200. }
  4201. flowParseDeclareTypeAlias(node) {
  4202. this.next();
  4203. const finished = this.flowParseTypeAlias(node);
  4204. finished.type = "DeclareTypeAlias";
  4205. return finished;
  4206. }
  4207. flowParseDeclareOpaqueType(node) {
  4208. this.next();
  4209. const finished = this.flowParseOpaqueType(node, true);
  4210. finished.type = "DeclareOpaqueType";
  4211. return finished;
  4212. }
  4213. flowParseDeclareInterface(node) {
  4214. this.next();
  4215. this.flowParseInterfaceish(node, false);
  4216. return this.finishNode(node, "DeclareInterface");
  4217. }
  4218. flowParseInterfaceish(node, isClass) {
  4219. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4220. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4221. if (this.match(47)) {
  4222. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4223. } else {
  4224. node.typeParameters = null;
  4225. }
  4226. node.extends = [];
  4227. if (this.eat(81)) {
  4228. do {
  4229. node.extends.push(this.flowParseInterfaceExtends());
  4230. } while (!isClass && this.eat(12));
  4231. }
  4232. if (isClass) {
  4233. node.implements = [];
  4234. node.mixins = [];
  4235. if (this.eatContextual(117)) {
  4236. do {
  4237. node.mixins.push(this.flowParseInterfaceExtends());
  4238. } while (this.eat(12));
  4239. }
  4240. if (this.eatContextual(113)) {
  4241. do {
  4242. node.implements.push(this.flowParseInterfaceExtends());
  4243. } while (this.eat(12));
  4244. }
  4245. }
  4246. node.body = this.flowParseObjectType({
  4247. allowStatic: isClass,
  4248. allowExact: false,
  4249. allowSpread: false,
  4250. allowProto: isClass,
  4251. allowInexact: false
  4252. });
  4253. }
  4254. flowParseInterfaceExtends() {
  4255. const node = this.startNode();
  4256. node.id = this.flowParseQualifiedTypeIdentifier();
  4257. if (this.match(47)) {
  4258. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4259. } else {
  4260. node.typeParameters = null;
  4261. }
  4262. return this.finishNode(node, "InterfaceExtends");
  4263. }
  4264. flowParseInterface(node) {
  4265. this.flowParseInterfaceish(node, false);
  4266. return this.finishNode(node, "InterfaceDeclaration");
  4267. }
  4268. checkNotUnderscore(word) {
  4269. if (word === "_") {
  4270. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  4271. }
  4272. }
  4273. checkReservedType(word, startLoc, declaration) {
  4274. if (!reservedTypes.has(word)) return;
  4275. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  4276. reservedType: word
  4277. });
  4278. }
  4279. flowParseRestrictedIdentifier(liberal, declaration) {
  4280. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4281. return this.parseIdentifier(liberal);
  4282. }
  4283. flowParseTypeAlias(node) {
  4284. node.id = this.flowParseRestrictedIdentifier(false, true);
  4285. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4286. if (this.match(47)) {
  4287. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4288. } else {
  4289. node.typeParameters = null;
  4290. }
  4291. node.right = this.flowParseTypeInitialiser(29);
  4292. this.semicolon();
  4293. return this.finishNode(node, "TypeAlias");
  4294. }
  4295. flowParseOpaqueType(node, declare) {
  4296. this.expectContextual(130);
  4297. node.id = this.flowParseRestrictedIdentifier(true, true);
  4298. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4299. if (this.match(47)) {
  4300. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4301. } else {
  4302. node.typeParameters = null;
  4303. }
  4304. node.supertype = null;
  4305. if (this.match(14)) {
  4306. node.supertype = this.flowParseTypeInitialiser(14);
  4307. }
  4308. node.impltype = null;
  4309. if (!declare) {
  4310. node.impltype = this.flowParseTypeInitialiser(29);
  4311. }
  4312. this.semicolon();
  4313. return this.finishNode(node, "OpaqueType");
  4314. }
  4315. flowParseTypeParameter(requireDefault = false) {
  4316. const nodeStartLoc = this.state.startLoc;
  4317. const node = this.startNode();
  4318. const variance = this.flowParseVariance();
  4319. const ident = this.flowParseTypeAnnotatableIdentifier();
  4320. node.name = ident.name;
  4321. node.variance = variance;
  4322. node.bound = ident.typeAnnotation;
  4323. if (this.match(29)) {
  4324. this.eat(29);
  4325. node.default = this.flowParseType();
  4326. } else {
  4327. if (requireDefault) {
  4328. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  4329. }
  4330. }
  4331. return this.finishNode(node, "TypeParameter");
  4332. }
  4333. flowParseTypeParameterDeclaration() {
  4334. const oldInType = this.state.inType;
  4335. const node = this.startNode();
  4336. node.params = [];
  4337. this.state.inType = true;
  4338. if (this.match(47) || this.match(143)) {
  4339. this.next();
  4340. } else {
  4341. this.unexpected();
  4342. }
  4343. let defaultRequired = false;
  4344. do {
  4345. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4346. node.params.push(typeParameter);
  4347. if (typeParameter.default) {
  4348. defaultRequired = true;
  4349. }
  4350. if (!this.match(48)) {
  4351. this.expect(12);
  4352. }
  4353. } while (!this.match(48));
  4354. this.expect(48);
  4355. this.state.inType = oldInType;
  4356. return this.finishNode(node, "TypeParameterDeclaration");
  4357. }
  4358. flowParseTypeParameterInstantiation() {
  4359. const node = this.startNode();
  4360. const oldInType = this.state.inType;
  4361. node.params = [];
  4362. this.state.inType = true;
  4363. this.expect(47);
  4364. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4365. this.state.noAnonFunctionType = false;
  4366. while (!this.match(48)) {
  4367. node.params.push(this.flowParseType());
  4368. if (!this.match(48)) {
  4369. this.expect(12);
  4370. }
  4371. }
  4372. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4373. this.expect(48);
  4374. this.state.inType = oldInType;
  4375. return this.finishNode(node, "TypeParameterInstantiation");
  4376. }
  4377. flowParseTypeParameterInstantiationCallOrNew() {
  4378. const node = this.startNode();
  4379. const oldInType = this.state.inType;
  4380. node.para