index.js 479 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183
  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. function createDefaultOptions() {
  423. return {
  424. sourceType: "script",
  425. sourceFilename: undefined,
  426. startIndex: 0,
  427. startColumn: 0,
  428. startLine: 1,
  429. allowAwaitOutsideFunction: false,
  430. allowReturnOutsideFunction: false,
  431. allowNewTargetOutsideFunction: false,
  432. allowImportExportEverywhere: false,
  433. allowSuperOutsideMethod: false,
  434. allowUndeclaredExports: false,
  435. plugins: [],
  436. strictMode: null,
  437. ranges: false,
  438. tokens: false,
  439. createImportExpressions: false,
  440. createParenthesizedExpressions: false,
  441. errorRecovery: false,
  442. attachComment: true,
  443. annexB: true
  444. };
  445. }
  446. function getOptions(opts) {
  447. const options = createDefaultOptions();
  448. if (opts == null) {
  449. return options;
  450. }
  451. if (opts.annexB != null && opts.annexB !== false) {
  452. throw new Error("The `annexB` option can only be set to `false`.");
  453. }
  454. for (const key of Object.keys(options)) {
  455. if (opts[key] != null) options[key] = opts[key];
  456. }
  457. if (options.startLine === 1) {
  458. if (opts.startIndex == null && options.startColumn > 0) {
  459. options.startIndex = options.startColumn;
  460. } else if (opts.startColumn == null && options.startIndex > 0) {
  461. options.startColumn = options.startIndex;
  462. }
  463. } else if (opts.startColumn == null || opts.startIndex == null) {
  464. if (opts.startIndex != null) {
  465. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  466. }
  467. }
  468. return options;
  469. }
  470. const {
  471. defineProperty
  472. } = Object;
  473. const toUnenumerable = (object, key) => {
  474. if (object) {
  475. defineProperty(object, key, {
  476. enumerable: false,
  477. value: object[key]
  478. });
  479. }
  480. };
  481. function toESTreeLocation(node) {
  482. toUnenumerable(node.loc.start, "index");
  483. toUnenumerable(node.loc.end, "index");
  484. return node;
  485. }
  486. var estree = superClass => class ESTreeParserMixin extends superClass {
  487. parse() {
  488. const file = toESTreeLocation(super.parse());
  489. if (this.optionFlags & 128) {
  490. file.tokens = file.tokens.map(toESTreeLocation);
  491. }
  492. return file;
  493. }
  494. parseRegExpLiteral({
  495. pattern,
  496. flags
  497. }) {
  498. let regex = null;
  499. try {
  500. regex = new RegExp(pattern, flags);
  501. } catch (_) {}
  502. const node = this.estreeParseLiteral(regex);
  503. node.regex = {
  504. pattern,
  505. flags
  506. };
  507. return node;
  508. }
  509. parseBigIntLiteral(value) {
  510. let bigInt;
  511. try {
  512. bigInt = BigInt(value);
  513. } catch (_unused) {
  514. bigInt = null;
  515. }
  516. const node = this.estreeParseLiteral(bigInt);
  517. node.bigint = String(node.value || value);
  518. return node;
  519. }
  520. parseDecimalLiteral(value) {
  521. const decimal = null;
  522. const node = this.estreeParseLiteral(decimal);
  523. node.decimal = String(node.value || value);
  524. return node;
  525. }
  526. estreeParseLiteral(value) {
  527. return this.parseLiteral(value, "Literal");
  528. }
  529. parseStringLiteral(value) {
  530. return this.estreeParseLiteral(value);
  531. }
  532. parseNumericLiteral(value) {
  533. return this.estreeParseLiteral(value);
  534. }
  535. parseNullLiteral() {
  536. return this.estreeParseLiteral(null);
  537. }
  538. parseBooleanLiteral(value) {
  539. return this.estreeParseLiteral(value);
  540. }
  541. directiveToStmt(directive) {
  542. const expression = directive.value;
  543. delete directive.value;
  544. expression.type = "Literal";
  545. expression.raw = expression.extra.raw;
  546. expression.value = expression.extra.expressionValue;
  547. const stmt = directive;
  548. stmt.type = "ExpressionStatement";
  549. stmt.expression = expression;
  550. stmt.directive = expression.extra.rawValue;
  551. delete expression.extra;
  552. return stmt;
  553. }
  554. initFunction(node, isAsync) {
  555. super.initFunction(node, isAsync);
  556. node.expression = false;
  557. }
  558. checkDeclaration(node) {
  559. if (node != null && this.isObjectProperty(node)) {
  560. this.checkDeclaration(node.value);
  561. } else {
  562. super.checkDeclaration(node);
  563. }
  564. }
  565. getObjectOrClassMethodParams(method) {
  566. return method.value.params;
  567. }
  568. isValidDirective(stmt) {
  569. var _stmt$expression$extr;
  570. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  571. }
  572. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  573. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  574. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  575. node.body = directiveStatements.concat(node.body);
  576. delete node.directives;
  577. }
  578. parsePrivateName() {
  579. const node = super.parsePrivateName();
  580. {
  581. if (!this.getPluginOption("estree", "classFeatures")) {
  582. return node;
  583. }
  584. }
  585. return this.convertPrivateNameToPrivateIdentifier(node);
  586. }
  587. convertPrivateNameToPrivateIdentifier(node) {
  588. const name = super.getPrivateNameSV(node);
  589. node = node;
  590. delete node.id;
  591. node.name = name;
  592. node.type = "PrivateIdentifier";
  593. return node;
  594. }
  595. isPrivateName(node) {
  596. {
  597. if (!this.getPluginOption("estree", "classFeatures")) {
  598. return super.isPrivateName(node);
  599. }
  600. }
  601. return node.type === "PrivateIdentifier";
  602. }
  603. getPrivateNameSV(node) {
  604. {
  605. if (!this.getPluginOption("estree", "classFeatures")) {
  606. return super.getPrivateNameSV(node);
  607. }
  608. }
  609. return node.name;
  610. }
  611. parseLiteral(value, type) {
  612. const node = super.parseLiteral(value, type);
  613. node.raw = node.extra.raw;
  614. delete node.extra;
  615. return node;
  616. }
  617. parseFunctionBody(node, allowExpression, isMethod = false) {
  618. super.parseFunctionBody(node, allowExpression, isMethod);
  619. node.expression = node.body.type !== "BlockStatement";
  620. }
  621. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  622. let funcNode = this.startNode();
  623. funcNode.kind = node.kind;
  624. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  625. funcNode.type = "FunctionExpression";
  626. delete funcNode.kind;
  627. node.value = funcNode;
  628. const {
  629. typeParameters
  630. } = node;
  631. if (typeParameters) {
  632. delete node.typeParameters;
  633. funcNode.typeParameters = typeParameters;
  634. funcNode.start = typeParameters.start;
  635. funcNode.loc.start = typeParameters.loc.start;
  636. }
  637. if (type === "ClassPrivateMethod") {
  638. node.computed = false;
  639. }
  640. return this.finishNode(node, "MethodDefinition");
  641. }
  642. nameIsConstructor(key) {
  643. if (key.type === "Literal") return key.value === "constructor";
  644. return super.nameIsConstructor(key);
  645. }
  646. parseClassProperty(...args) {
  647. const propertyNode = super.parseClassProperty(...args);
  648. {
  649. if (!this.getPluginOption("estree", "classFeatures")) {
  650. return propertyNode;
  651. }
  652. }
  653. {
  654. propertyNode.type = "PropertyDefinition";
  655. }
  656. return propertyNode;
  657. }
  658. parseClassPrivateProperty(...args) {
  659. const propertyNode = super.parseClassPrivateProperty(...args);
  660. {
  661. if (!this.getPluginOption("estree", "classFeatures")) {
  662. return propertyNode;
  663. }
  664. }
  665. {
  666. propertyNode.type = "PropertyDefinition";
  667. }
  668. propertyNode.computed = false;
  669. return propertyNode;
  670. }
  671. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  672. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  673. if (node) {
  674. node.type = "Property";
  675. if (node.kind === "method") {
  676. node.kind = "init";
  677. }
  678. node.shorthand = false;
  679. }
  680. return node;
  681. }
  682. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  683. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  684. if (node) {
  685. node.kind = "init";
  686. node.type = "Property";
  687. }
  688. return node;
  689. }
  690. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  691. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  692. }
  693. isAssignable(node, isBinding) {
  694. if (node != null && this.isObjectProperty(node)) {
  695. return this.isAssignable(node.value, isBinding);
  696. }
  697. return super.isAssignable(node, isBinding);
  698. }
  699. toAssignable(node, isLHS = false) {
  700. if (node != null && this.isObjectProperty(node)) {
  701. const {
  702. key,
  703. value
  704. } = node;
  705. if (this.isPrivateName(key)) {
  706. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  707. }
  708. this.toAssignable(value, isLHS);
  709. } else {
  710. super.toAssignable(node, isLHS);
  711. }
  712. }
  713. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  714. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  715. this.raise(Errors.PatternHasAccessor, prop.key);
  716. } else if (prop.type === "Property" && prop.method) {
  717. this.raise(Errors.PatternHasMethod, prop.key);
  718. } else {
  719. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  720. }
  721. }
  722. finishCallExpression(unfinished, optional) {
  723. const node = super.finishCallExpression(unfinished, optional);
  724. if (node.callee.type === "Import") {
  725. var _ref, _ref2;
  726. node.type = "ImportExpression";
  727. node.source = node.arguments[0];
  728. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  729. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  730. delete node.arguments;
  731. delete node.callee;
  732. }
  733. return node;
  734. }
  735. toReferencedArguments(node) {
  736. if (node.type === "ImportExpression") {
  737. return;
  738. }
  739. super.toReferencedArguments(node);
  740. }
  741. parseExport(unfinished, decorators) {
  742. const exportStartLoc = this.state.lastTokStartLoc;
  743. const node = super.parseExport(unfinished, decorators);
  744. switch (node.type) {
  745. case "ExportAllDeclaration":
  746. node.exported = null;
  747. break;
  748. case "ExportNamedDeclaration":
  749. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  750. node.type = "ExportAllDeclaration";
  751. node.exported = node.specifiers[0].exported;
  752. delete node.specifiers;
  753. }
  754. case "ExportDefaultDeclaration":
  755. {
  756. var _declaration$decorato;
  757. const {
  758. declaration
  759. } = node;
  760. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  761. this.resetStartLocation(node, exportStartLoc);
  762. }
  763. }
  764. break;
  765. }
  766. return node;
  767. }
  768. parseSubscript(base, startLoc, noCalls, state) {
  769. const node = super.parseSubscript(base, startLoc, noCalls, state);
  770. if (state.optionalChainMember) {
  771. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  772. node.type = node.type.substring(8);
  773. }
  774. if (state.stop) {
  775. const chain = this.startNodeAtNode(node);
  776. chain.expression = node;
  777. return this.finishNode(chain, "ChainExpression");
  778. }
  779. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  780. node.optional = false;
  781. }
  782. return node;
  783. }
  784. isOptionalMemberExpression(node) {
  785. if (node.type === "ChainExpression") {
  786. return node.expression.type === "MemberExpression";
  787. }
  788. return super.isOptionalMemberExpression(node);
  789. }
  790. hasPropertyAsPrivateName(node) {
  791. if (node.type === "ChainExpression") {
  792. node = node.expression;
  793. }
  794. return super.hasPropertyAsPrivateName(node);
  795. }
  796. isObjectProperty(node) {
  797. return node.type === "Property" && node.kind === "init" && !node.method;
  798. }
  799. isObjectMethod(node) {
  800. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  801. }
  802. finishNodeAt(node, type, endLoc) {
  803. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  804. }
  805. resetStartLocation(node, startLoc) {
  806. super.resetStartLocation(node, startLoc);
  807. toESTreeLocation(node);
  808. }
  809. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  810. super.resetEndLocation(node, endLoc);
  811. toESTreeLocation(node);
  812. }
  813. };
  814. class TokContext {
  815. constructor(token, preserveSpace) {
  816. this.token = void 0;
  817. this.preserveSpace = void 0;
  818. this.token = token;
  819. this.preserveSpace = !!preserveSpace;
  820. }
  821. }
  822. const types = {
  823. brace: new TokContext("{"),
  824. j_oTag: new TokContext("<tag"),
  825. j_cTag: new TokContext("</tag"),
  826. j_expr: new TokContext("<tag>...</tag>", true)
  827. };
  828. {
  829. types.template = new TokContext("`", true);
  830. }
  831. const beforeExpr = true;
  832. const startsExpr = true;
  833. const isLoop = true;
  834. const isAssign = true;
  835. const prefix = true;
  836. const postfix = true;
  837. class ExportedTokenType {
  838. constructor(label, conf = {}) {
  839. this.label = void 0;
  840. this.keyword = void 0;
  841. this.beforeExpr = void 0;
  842. this.startsExpr = void 0;
  843. this.rightAssociative = void 0;
  844. this.isLoop = void 0;
  845. this.isAssign = void 0;
  846. this.prefix = void 0;
  847. this.postfix = void 0;
  848. this.binop = void 0;
  849. this.label = label;
  850. this.keyword = conf.keyword;
  851. this.beforeExpr = !!conf.beforeExpr;
  852. this.startsExpr = !!conf.startsExpr;
  853. this.rightAssociative = !!conf.rightAssociative;
  854. this.isLoop = !!conf.isLoop;
  855. this.isAssign = !!conf.isAssign;
  856. this.prefix = !!conf.prefix;
  857. this.postfix = !!conf.postfix;
  858. this.binop = conf.binop != null ? conf.binop : null;
  859. {
  860. this.updateContext = null;
  861. }
  862. }
  863. }
  864. const keywords$1 = new Map();
  865. function createKeyword(name, options = {}) {
  866. options.keyword = name;
  867. const token = createToken(name, options);
  868. keywords$1.set(name, token);
  869. return token;
  870. }
  871. function createBinop(name, binop) {
  872. return createToken(name, {
  873. beforeExpr,
  874. binop
  875. });
  876. }
  877. let tokenTypeCounter = -1;
  878. const tokenTypes = [];
  879. const tokenLabels = [];
  880. const tokenBinops = [];
  881. const tokenBeforeExprs = [];
  882. const tokenStartsExprs = [];
  883. const tokenPrefixes = [];
  884. function createToken(name, options = {}) {
  885. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  886. ++tokenTypeCounter;
  887. tokenLabels.push(name);
  888. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  889. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  890. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  891. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  892. tokenTypes.push(new ExportedTokenType(name, options));
  893. return tokenTypeCounter;
  894. }
  895. function createKeywordLike(name, options = {}) {
  896. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  897. ++tokenTypeCounter;
  898. keywords$1.set(name, tokenTypeCounter);
  899. tokenLabels.push(name);
  900. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  901. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  902. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  903. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  904. tokenTypes.push(new ExportedTokenType("name", options));
  905. return tokenTypeCounter;
  906. }
  907. const tt = {
  908. bracketL: createToken("[", {
  909. beforeExpr,
  910. startsExpr
  911. }),
  912. bracketHashL: createToken("#[", {
  913. beforeExpr,
  914. startsExpr
  915. }),
  916. bracketBarL: createToken("[|", {
  917. beforeExpr,
  918. startsExpr
  919. }),
  920. bracketR: createToken("]"),
  921. bracketBarR: createToken("|]"),
  922. braceL: createToken("{", {
  923. beforeExpr,
  924. startsExpr
  925. }),
  926. braceBarL: createToken("{|", {
  927. beforeExpr,
  928. startsExpr
  929. }),
  930. braceHashL: createToken("#{", {
  931. beforeExpr,
  932. startsExpr
  933. }),
  934. braceR: createToken("}"),
  935. braceBarR: createToken("|}"),
  936. parenL: createToken("(", {
  937. beforeExpr,
  938. startsExpr
  939. }),
  940. parenR: createToken(")"),
  941. comma: createToken(",", {
  942. beforeExpr
  943. }),
  944. semi: createToken(";", {
  945. beforeExpr
  946. }),
  947. colon: createToken(":", {
  948. beforeExpr
  949. }),
  950. doubleColon: createToken("::", {
  951. beforeExpr
  952. }),
  953. dot: createToken("."),
  954. question: createToken("?", {
  955. beforeExpr
  956. }),
  957. questionDot: createToken("?."),
  958. arrow: createToken("=>", {
  959. beforeExpr
  960. }),
  961. template: createToken("template"),
  962. ellipsis: createToken("...", {
  963. beforeExpr
  964. }),
  965. backQuote: createToken("`", {
  966. startsExpr
  967. }),
  968. dollarBraceL: createToken("${", {
  969. beforeExpr,
  970. startsExpr
  971. }),
  972. templateTail: createToken("...`", {
  973. startsExpr
  974. }),
  975. templateNonTail: createToken("...${", {
  976. beforeExpr,
  977. startsExpr
  978. }),
  979. at: createToken("@"),
  980. hash: createToken("#", {
  981. startsExpr
  982. }),
  983. interpreterDirective: createToken("#!..."),
  984. eq: createToken("=", {
  985. beforeExpr,
  986. isAssign
  987. }),
  988. assign: createToken("_=", {
  989. beforeExpr,
  990. isAssign
  991. }),
  992. slashAssign: createToken("_=", {
  993. beforeExpr,
  994. isAssign
  995. }),
  996. xorAssign: createToken("_=", {
  997. beforeExpr,
  998. isAssign
  999. }),
  1000. moduloAssign: createToken("_=", {
  1001. beforeExpr,
  1002. isAssign
  1003. }),
  1004. incDec: createToken("++/--", {
  1005. prefix,
  1006. postfix,
  1007. startsExpr
  1008. }),
  1009. bang: createToken("!", {
  1010. beforeExpr,
  1011. prefix,
  1012. startsExpr
  1013. }),
  1014. tilde: createToken("~", {
  1015. beforeExpr,
  1016. prefix,
  1017. startsExpr
  1018. }),
  1019. doubleCaret: createToken("^^", {
  1020. startsExpr
  1021. }),
  1022. doubleAt: createToken("@@", {
  1023. startsExpr
  1024. }),
  1025. pipeline: createBinop("|>", 0),
  1026. nullishCoalescing: createBinop("??", 1),
  1027. logicalOR: createBinop("||", 1),
  1028. logicalAND: createBinop("&&", 2),
  1029. bitwiseOR: createBinop("|", 3),
  1030. bitwiseXOR: createBinop("^", 4),
  1031. bitwiseAND: createBinop("&", 5),
  1032. equality: createBinop("==/!=/===/!==", 6),
  1033. lt: createBinop("</>/<=/>=", 7),
  1034. gt: createBinop("</>/<=/>=", 7),
  1035. relational: createBinop("</>/<=/>=", 7),
  1036. bitShift: createBinop("<</>>/>>>", 8),
  1037. bitShiftL: createBinop("<</>>/>>>", 8),
  1038. bitShiftR: createBinop("<</>>/>>>", 8),
  1039. plusMin: createToken("+/-", {
  1040. beforeExpr,
  1041. binop: 9,
  1042. prefix,
  1043. startsExpr
  1044. }),
  1045. modulo: createToken("%", {
  1046. binop: 10,
  1047. startsExpr
  1048. }),
  1049. star: createToken("*", {
  1050. binop: 10
  1051. }),
  1052. slash: createBinop("/", 10),
  1053. exponent: createToken("**", {
  1054. beforeExpr,
  1055. binop: 11,
  1056. rightAssociative: true
  1057. }),
  1058. _in: createKeyword("in", {
  1059. beforeExpr,
  1060. binop: 7
  1061. }),
  1062. _instanceof: createKeyword("instanceof", {
  1063. beforeExpr,
  1064. binop: 7
  1065. }),
  1066. _break: createKeyword("break"),
  1067. _case: createKeyword("case", {
  1068. beforeExpr
  1069. }),
  1070. _catch: createKeyword("catch"),
  1071. _continue: createKeyword("continue"),
  1072. _debugger: createKeyword("debugger"),
  1073. _default: createKeyword("default", {
  1074. beforeExpr
  1075. }),
  1076. _else: createKeyword("else", {
  1077. beforeExpr
  1078. }),
  1079. _finally: createKeyword("finally"),
  1080. _function: createKeyword("function", {
  1081. startsExpr
  1082. }),
  1083. _if: createKeyword("if"),
  1084. _return: createKeyword("return", {
  1085. beforeExpr
  1086. }),
  1087. _switch: createKeyword("switch"),
  1088. _throw: createKeyword("throw", {
  1089. beforeExpr,
  1090. prefix,
  1091. startsExpr
  1092. }),
  1093. _try: createKeyword("try"),
  1094. _var: createKeyword("var"),
  1095. _const: createKeyword("const"),
  1096. _with: createKeyword("with"),
  1097. _new: createKeyword("new", {
  1098. beforeExpr,
  1099. startsExpr
  1100. }),
  1101. _this: createKeyword("this", {
  1102. startsExpr
  1103. }),
  1104. _super: createKeyword("super", {
  1105. startsExpr
  1106. }),
  1107. _class: createKeyword("class", {
  1108. startsExpr
  1109. }),
  1110. _extends: createKeyword("extends", {
  1111. beforeExpr
  1112. }),
  1113. _export: createKeyword("export"),
  1114. _import: createKeyword("import", {
  1115. startsExpr
  1116. }),
  1117. _null: createKeyword("null", {
  1118. startsExpr
  1119. }),
  1120. _true: createKeyword("true", {
  1121. startsExpr
  1122. }),
  1123. _false: createKeyword("false", {
  1124. startsExpr
  1125. }),
  1126. _typeof: createKeyword("typeof", {
  1127. beforeExpr,
  1128. prefix,
  1129. startsExpr
  1130. }),
  1131. _void: createKeyword("void", {
  1132. beforeExpr,
  1133. prefix,
  1134. startsExpr
  1135. }),
  1136. _delete: createKeyword("delete", {
  1137. beforeExpr,
  1138. prefix,
  1139. startsExpr
  1140. }),
  1141. _do: createKeyword("do", {
  1142. isLoop,
  1143. beforeExpr
  1144. }),
  1145. _for: createKeyword("for", {
  1146. isLoop
  1147. }),
  1148. _while: createKeyword("while", {
  1149. isLoop
  1150. }),
  1151. _as: createKeywordLike("as", {
  1152. startsExpr
  1153. }),
  1154. _assert: createKeywordLike("assert", {
  1155. startsExpr
  1156. }),
  1157. _async: createKeywordLike("async", {
  1158. startsExpr
  1159. }),
  1160. _await: createKeywordLike("await", {
  1161. startsExpr
  1162. }),
  1163. _defer: createKeywordLike("defer", {
  1164. startsExpr
  1165. }),
  1166. _from: createKeywordLike("from", {
  1167. startsExpr
  1168. }),
  1169. _get: createKeywordLike("get", {
  1170. startsExpr
  1171. }),
  1172. _let: createKeywordLike("let", {
  1173. startsExpr
  1174. }),
  1175. _meta: createKeywordLike("meta", {
  1176. startsExpr
  1177. }),
  1178. _of: createKeywordLike("of", {
  1179. startsExpr
  1180. }),
  1181. _sent: createKeywordLike("sent", {
  1182. startsExpr
  1183. }),
  1184. _set: createKeywordLike("set", {
  1185. startsExpr
  1186. }),
  1187. _source: createKeywordLike("source", {
  1188. startsExpr
  1189. }),
  1190. _static: createKeywordLike("static", {
  1191. startsExpr
  1192. }),
  1193. _using: createKeywordLike("using", {
  1194. startsExpr
  1195. }),
  1196. _yield: createKeywordLike("yield", {
  1197. startsExpr
  1198. }),
  1199. _asserts: createKeywordLike("asserts", {
  1200. startsExpr
  1201. }),
  1202. _checks: createKeywordLike("checks", {
  1203. startsExpr
  1204. }),
  1205. _exports: createKeywordLike("exports", {
  1206. startsExpr
  1207. }),
  1208. _global: createKeywordLike("global", {
  1209. startsExpr
  1210. }),
  1211. _implements: createKeywordLike("implements", {
  1212. startsExpr
  1213. }),
  1214. _intrinsic: createKeywordLike("intrinsic", {
  1215. startsExpr
  1216. }),
  1217. _infer: createKeywordLike("infer", {
  1218. startsExpr
  1219. }),
  1220. _is: createKeywordLike("is", {
  1221. startsExpr
  1222. }),
  1223. _mixins: createKeywordLike("mixins", {
  1224. startsExpr
  1225. }),
  1226. _proto: createKeywordLike("proto", {
  1227. startsExpr
  1228. }),
  1229. _require: createKeywordLike("require", {
  1230. startsExpr
  1231. }),
  1232. _satisfies: createKeywordLike("satisfies", {
  1233. startsExpr
  1234. }),
  1235. _keyof: createKeywordLike("keyof", {
  1236. startsExpr
  1237. }),
  1238. _readonly: createKeywordLike("readonly", {
  1239. startsExpr
  1240. }),
  1241. _unique: createKeywordLike("unique", {
  1242. startsExpr
  1243. }),
  1244. _abstract: createKeywordLike("abstract", {
  1245. startsExpr
  1246. }),
  1247. _declare: createKeywordLike("declare", {
  1248. startsExpr
  1249. }),
  1250. _enum: createKeywordLike("enum", {
  1251. startsExpr
  1252. }),
  1253. _module: createKeywordLike("module", {
  1254. startsExpr
  1255. }),
  1256. _namespace: createKeywordLike("namespace", {
  1257. startsExpr
  1258. }),
  1259. _interface: createKeywordLike("interface", {
  1260. startsExpr
  1261. }),
  1262. _type: createKeywordLike("type", {
  1263. startsExpr
  1264. }),
  1265. _opaque: createKeywordLike("opaque", {
  1266. startsExpr
  1267. }),
  1268. name: createToken("name", {
  1269. startsExpr
  1270. }),
  1271. placeholder: createToken("%%", {
  1272. startsExpr: true
  1273. }),
  1274. string: createToken("string", {
  1275. startsExpr
  1276. }),
  1277. num: createToken("num", {
  1278. startsExpr
  1279. }),
  1280. bigint: createToken("bigint", {
  1281. startsExpr
  1282. }),
  1283. decimal: createToken("decimal", {
  1284. startsExpr
  1285. }),
  1286. regexp: createToken("regexp", {
  1287. startsExpr
  1288. }),
  1289. privateName: createToken("#name", {
  1290. startsExpr
  1291. }),
  1292. eof: createToken("eof"),
  1293. jsxName: createToken("jsxName"),
  1294. jsxText: createToken("jsxText", {
  1295. beforeExpr: true
  1296. }),
  1297. jsxTagStart: createToken("jsxTagStart", {
  1298. startsExpr: true
  1299. }),
  1300. jsxTagEnd: createToken("jsxTagEnd")
  1301. };
  1302. function tokenIsIdentifier(token) {
  1303. return token >= 93 && token <= 133;
  1304. }
  1305. function tokenKeywordOrIdentifierIsKeyword(token) {
  1306. return token <= 92;
  1307. }
  1308. function tokenIsKeywordOrIdentifier(token) {
  1309. return token >= 58 && token <= 133;
  1310. }
  1311. function tokenIsLiteralPropertyName(token) {
  1312. return token >= 58 && token <= 137;
  1313. }
  1314. function tokenComesBeforeExpression(token) {
  1315. return tokenBeforeExprs[token];
  1316. }
  1317. function tokenCanStartExpression(token) {
  1318. return tokenStartsExprs[token];
  1319. }
  1320. function tokenIsAssignment(token) {
  1321. return token >= 29 && token <= 33;
  1322. }
  1323. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1324. return token >= 129 && token <= 131;
  1325. }
  1326. function tokenIsLoop(token) {
  1327. return token >= 90 && token <= 92;
  1328. }
  1329. function tokenIsKeyword(token) {
  1330. return token >= 58 && token <= 92;
  1331. }
  1332. function tokenIsOperator(token) {
  1333. return token >= 39 && token <= 59;
  1334. }
  1335. function tokenIsPostfix(token) {
  1336. return token === 34;
  1337. }
  1338. function tokenIsPrefix(token) {
  1339. return tokenPrefixes[token];
  1340. }
  1341. function tokenIsTSTypeOperator(token) {
  1342. return token >= 121 && token <= 123;
  1343. }
  1344. function tokenIsTSDeclarationStart(token) {
  1345. return token >= 124 && token <= 130;
  1346. }
  1347. function tokenLabelName(token) {
  1348. return tokenLabels[token];
  1349. }
  1350. function tokenOperatorPrecedence(token) {
  1351. return tokenBinops[token];
  1352. }
  1353. function tokenIsRightAssociative(token) {
  1354. return token === 57;
  1355. }
  1356. function tokenIsTemplate(token) {
  1357. return token >= 24 && token <= 25;
  1358. }
  1359. function getExportedToken(token) {
  1360. return tokenTypes[token];
  1361. }
  1362. {
  1363. tokenTypes[8].updateContext = context => {
  1364. context.pop();
  1365. };
  1366. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1367. context.push(types.brace);
  1368. };
  1369. tokenTypes[22].updateContext = context => {
  1370. if (context[context.length - 1] === types.template) {
  1371. context.pop();
  1372. } else {
  1373. context.push(types.template);
  1374. }
  1375. };
  1376. tokenTypes[143].updateContext = context => {
  1377. context.push(types.j_expr, types.j_oTag);
  1378. };
  1379. }
  1380. 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";
  1381. 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";
  1382. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1383. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1384. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1385. 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];
  1386. 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];
  1387. function isInAstralSet(code, set) {
  1388. let pos = 0x10000;
  1389. for (let i = 0, length = set.length; i < length; i += 2) {
  1390. pos += set[i];
  1391. if (pos > code) return false;
  1392. pos += set[i + 1];
  1393. if (pos >= code) return true;
  1394. }
  1395. return false;
  1396. }
  1397. function isIdentifierStart(code) {
  1398. if (code < 65) return code === 36;
  1399. if (code <= 90) return true;
  1400. if (code < 97) return code === 95;
  1401. if (code <= 122) return true;
  1402. if (code <= 0xffff) {
  1403. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1404. }
  1405. return isInAstralSet(code, astralIdentifierStartCodes);
  1406. }
  1407. function isIdentifierChar(code) {
  1408. if (code < 48) return code === 36;
  1409. if (code < 58) return true;
  1410. if (code < 65) return false;
  1411. if (code <= 90) return true;
  1412. if (code < 97) return code === 95;
  1413. if (code <= 122) return true;
  1414. if (code <= 0xffff) {
  1415. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1416. }
  1417. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1418. }
  1419. const reservedWords = {
  1420. 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"],
  1421. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1422. strictBind: ["eval", "arguments"]
  1423. };
  1424. const keywords = new Set(reservedWords.keyword);
  1425. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1426. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1427. function isReservedWord(word, inModule) {
  1428. return inModule && word === "await" || word === "enum";
  1429. }
  1430. function isStrictReservedWord(word, inModule) {
  1431. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1432. }
  1433. function isStrictBindOnlyReservedWord(word) {
  1434. return reservedWordsStrictBindSet.has(word);
  1435. }
  1436. function isStrictBindReservedWord(word, inModule) {
  1437. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1438. }
  1439. function isKeyword(word) {
  1440. return keywords.has(word);
  1441. }
  1442. function isIteratorStart(current, next, next2) {
  1443. return current === 64 && next === 64 && isIdentifierStart(next2);
  1444. }
  1445. 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"]);
  1446. function canBeReservedWord(word) {
  1447. return reservedWordLikeSet.has(word);
  1448. }
  1449. class Scope {
  1450. constructor(flags) {
  1451. this.flags = 0;
  1452. this.names = new Map();
  1453. this.firstLexicalName = "";
  1454. this.flags = flags;
  1455. }
  1456. }
  1457. class ScopeHandler {
  1458. constructor(parser, inModule) {
  1459. this.parser = void 0;
  1460. this.scopeStack = [];
  1461. this.inModule = void 0;
  1462. this.undefinedExports = new Map();
  1463. this.parser = parser;
  1464. this.inModule = inModule;
  1465. }
  1466. get inTopLevel() {
  1467. return (this.currentScope().flags & 1) > 0;
  1468. }
  1469. get inFunction() {
  1470. return (this.currentVarScopeFlags() & 2) > 0;
  1471. }
  1472. get allowSuper() {
  1473. return (this.currentThisScopeFlags() & 16) > 0;
  1474. }
  1475. get allowDirectSuper() {
  1476. return (this.currentThisScopeFlags() & 32) > 0;
  1477. }
  1478. get inClass() {
  1479. return (this.currentThisScopeFlags() & 64) > 0;
  1480. }
  1481. get inClassAndNotInNonArrowFunction() {
  1482. const flags = this.currentThisScopeFlags();
  1483. return (flags & 64) > 0 && (flags & 2) === 0;
  1484. }
  1485. get inStaticBlock() {
  1486. for (let i = this.scopeStack.length - 1;; i--) {
  1487. const {
  1488. flags
  1489. } = this.scopeStack[i];
  1490. if (flags & 128) {
  1491. return true;
  1492. }
  1493. if (flags & (387 | 64)) {
  1494. return false;
  1495. }
  1496. }
  1497. }
  1498. get inNonArrowFunction() {
  1499. return (this.currentThisScopeFlags() & 2) > 0;
  1500. }
  1501. get treatFunctionsAsVar() {
  1502. return this.treatFunctionsAsVarInScope(this.currentScope());
  1503. }
  1504. createScope(flags) {
  1505. return new Scope(flags);
  1506. }
  1507. enter(flags) {
  1508. this.scopeStack.push(this.createScope(flags));
  1509. }
  1510. exit() {
  1511. const scope = this.scopeStack.pop();
  1512. return scope.flags;
  1513. }
  1514. treatFunctionsAsVarInScope(scope) {
  1515. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1516. }
  1517. declareName(name, bindingType, loc) {
  1518. let scope = this.currentScope();
  1519. if (bindingType & 8 || bindingType & 16) {
  1520. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1521. let type = scope.names.get(name) || 0;
  1522. if (bindingType & 16) {
  1523. type = type | 4;
  1524. } else {
  1525. if (!scope.firstLexicalName) {
  1526. scope.firstLexicalName = name;
  1527. }
  1528. type = type | 2;
  1529. }
  1530. scope.names.set(name, type);
  1531. if (bindingType & 8) {
  1532. this.maybeExportDefined(scope, name);
  1533. }
  1534. } else if (bindingType & 4) {
  1535. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1536. scope = this.scopeStack[i];
  1537. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1538. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  1539. this.maybeExportDefined(scope, name);
  1540. if (scope.flags & 387) break;
  1541. }
  1542. }
  1543. if (this.parser.inModule && scope.flags & 1) {
  1544. this.undefinedExports.delete(name);
  1545. }
  1546. }
  1547. maybeExportDefined(scope, name) {
  1548. if (this.parser.inModule && scope.flags & 1) {
  1549. this.undefinedExports.delete(name);
  1550. }
  1551. }
  1552. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1553. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1554. this.parser.raise(Errors.VarRedeclaration, loc, {
  1555. identifierName: name
  1556. });
  1557. }
  1558. }
  1559. isRedeclaredInScope(scope, name, bindingType) {
  1560. if (!(bindingType & 1)) return false;
  1561. if (bindingType & 8) {
  1562. return scope.names.has(name);
  1563. }
  1564. const type = scope.names.get(name);
  1565. if (bindingType & 16) {
  1566. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  1567. }
  1568. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  1569. }
  1570. checkLocalExport(id) {
  1571. const {
  1572. name
  1573. } = id;
  1574. const topLevelScope = this.scopeStack[0];
  1575. if (!topLevelScope.names.has(name)) {
  1576. this.undefinedExports.set(name, id.loc.start);
  1577. }
  1578. }
  1579. currentScope() {
  1580. return this.scopeStack[this.scopeStack.length - 1];
  1581. }
  1582. currentVarScopeFlags() {
  1583. for (let i = this.scopeStack.length - 1;; i--) {
  1584. const {
  1585. flags
  1586. } = this.scopeStack[i];
  1587. if (flags & 387) {
  1588. return flags;
  1589. }
  1590. }
  1591. }
  1592. currentThisScopeFlags() {
  1593. for (let i = this.scopeStack.length - 1;; i--) {
  1594. const {
  1595. flags
  1596. } = this.scopeStack[i];
  1597. if (flags & (387 | 64) && !(flags & 4)) {
  1598. return flags;
  1599. }
  1600. }
  1601. }
  1602. }
  1603. class FlowScope extends Scope {
  1604. constructor(...args) {
  1605. super(...args);
  1606. this.declareFunctions = new Set();
  1607. }
  1608. }
  1609. class FlowScopeHandler extends ScopeHandler {
  1610. createScope(flags) {
  1611. return new FlowScope(flags);
  1612. }
  1613. declareName(name, bindingType, loc) {
  1614. const scope = this.currentScope();
  1615. if (bindingType & 2048) {
  1616. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1617. this.maybeExportDefined(scope, name);
  1618. scope.declareFunctions.add(name);
  1619. return;
  1620. }
  1621. super.declareName(name, bindingType, loc);
  1622. }
  1623. isRedeclaredInScope(scope, name, bindingType) {
  1624. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1625. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  1626. const type = scope.names.get(name);
  1627. return (type & 4) > 0 || (type & 2) > 0;
  1628. }
  1629. return false;
  1630. }
  1631. checkLocalExport(id) {
  1632. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1633. super.checkLocalExport(id);
  1634. }
  1635. }
  1636. }
  1637. class BaseParser {
  1638. constructor() {
  1639. this.sawUnambiguousESM = false;
  1640. this.ambiguousScriptDifferentAst = false;
  1641. }
  1642. sourceToOffsetPos(sourcePos) {
  1643. return sourcePos + this.startIndex;
  1644. }
  1645. offsetToSourcePos(offsetPos) {
  1646. return offsetPos - this.startIndex;
  1647. }
  1648. hasPlugin(pluginConfig) {
  1649. if (typeof pluginConfig === "string") {
  1650. return this.plugins.has(pluginConfig);
  1651. } else {
  1652. const [pluginName, pluginOptions] = pluginConfig;
  1653. if (!this.hasPlugin(pluginName)) {
  1654. return false;
  1655. }
  1656. const actualOptions = this.plugins.get(pluginName);
  1657. for (const key of Object.keys(pluginOptions)) {
  1658. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1659. return false;
  1660. }
  1661. }
  1662. return true;
  1663. }
  1664. }
  1665. getPluginOption(plugin, name) {
  1666. var _this$plugins$get;
  1667. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1668. }
  1669. }
  1670. function setTrailingComments(node, comments) {
  1671. if (node.trailingComments === undefined) {
  1672. node.trailingComments = comments;
  1673. } else {
  1674. node.trailingComments.unshift(...comments);
  1675. }
  1676. }
  1677. function setLeadingComments(node, comments) {
  1678. if (node.leadingComments === undefined) {
  1679. node.leadingComments = comments;
  1680. } else {
  1681. node.leadingComments.unshift(...comments);
  1682. }
  1683. }
  1684. function setInnerComments(node, comments) {
  1685. if (node.innerComments === undefined) {
  1686. node.innerComments = comments;
  1687. } else {
  1688. node.innerComments.unshift(...comments);
  1689. }
  1690. }
  1691. function adjustInnerComments(node, elements, commentWS) {
  1692. let lastElement = null;
  1693. let i = elements.length;
  1694. while (lastElement === null && i > 0) {
  1695. lastElement = elements[--i];
  1696. }
  1697. if (lastElement === null || lastElement.start > commentWS.start) {
  1698. setInnerComments(node, commentWS.comments);
  1699. } else {
  1700. setTrailingComments(lastElement, commentWS.comments);
  1701. }
  1702. }
  1703. class CommentsParser extends BaseParser {
  1704. addComment(comment) {
  1705. if (this.filename) comment.loc.filename = this.filename;
  1706. const {
  1707. commentsLen
  1708. } = this.state;
  1709. if (this.comments.length !== commentsLen) {
  1710. this.comments.length = commentsLen;
  1711. }
  1712. this.comments.push(comment);
  1713. this.state.commentsLen++;
  1714. }
  1715. processComment(node) {
  1716. const {
  1717. commentStack
  1718. } = this.state;
  1719. const commentStackLength = commentStack.length;
  1720. if (commentStackLength === 0) return;
  1721. let i = commentStackLength - 1;
  1722. const lastCommentWS = commentStack[i];
  1723. if (lastCommentWS.start === node.end) {
  1724. lastCommentWS.leadingNode = node;
  1725. i--;
  1726. }
  1727. const {
  1728. start: nodeStart
  1729. } = node;
  1730. for (; i >= 0; i--) {
  1731. const commentWS = commentStack[i];
  1732. const commentEnd = commentWS.end;
  1733. if (commentEnd > nodeStart) {
  1734. commentWS.containingNode = node;
  1735. this.finalizeComment(commentWS);
  1736. commentStack.splice(i, 1);
  1737. } else {
  1738. if (commentEnd === nodeStart) {
  1739. commentWS.trailingNode = node;
  1740. }
  1741. break;
  1742. }
  1743. }
  1744. }
  1745. finalizeComment(commentWS) {
  1746. const {
  1747. comments
  1748. } = commentWS;
  1749. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1750. if (commentWS.leadingNode !== null) {
  1751. setTrailingComments(commentWS.leadingNode, comments);
  1752. }
  1753. if (commentWS.trailingNode !== null) {
  1754. setLeadingComments(commentWS.trailingNode, comments);
  1755. }
  1756. } else {
  1757. const {
  1758. containingNode: node,
  1759. start: commentStart
  1760. } = commentWS;
  1761. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  1762. switch (node.type) {
  1763. case "ObjectExpression":
  1764. case "ObjectPattern":
  1765. case "RecordExpression":
  1766. adjustInnerComments(node, node.properties, commentWS);
  1767. break;
  1768. case "CallExpression":
  1769. case "OptionalCallExpression":
  1770. adjustInnerComments(node, node.arguments, commentWS);
  1771. break;
  1772. case "FunctionDeclaration":
  1773. case "FunctionExpression":
  1774. case "ArrowFunctionExpression":
  1775. case "ObjectMethod":
  1776. case "ClassMethod":
  1777. case "ClassPrivateMethod":
  1778. adjustInnerComments(node, node.params, commentWS);
  1779. break;
  1780. case "ArrayExpression":
  1781. case "ArrayPattern":
  1782. case "TupleExpression":
  1783. adjustInnerComments(node, node.elements, commentWS);
  1784. break;
  1785. case "ExportNamedDeclaration":
  1786. case "ImportDeclaration":
  1787. adjustInnerComments(node, node.specifiers, commentWS);
  1788. break;
  1789. case "TSEnumDeclaration":
  1790. {
  1791. adjustInnerComments(node, node.members, commentWS);
  1792. }
  1793. break;
  1794. case "TSEnumBody":
  1795. adjustInnerComments(node, node.members, commentWS);
  1796. break;
  1797. default:
  1798. {
  1799. setInnerComments(node, comments);
  1800. }
  1801. }
  1802. } else {
  1803. setInnerComments(node, comments);
  1804. }
  1805. }
  1806. }
  1807. finalizeRemainingComments() {
  1808. const {
  1809. commentStack
  1810. } = this.state;
  1811. for (let i = commentStack.length - 1; i >= 0; i--) {
  1812. this.finalizeComment(commentStack[i]);
  1813. }
  1814. this.state.commentStack = [];
  1815. }
  1816. resetPreviousNodeTrailingComments(node) {
  1817. const {
  1818. commentStack
  1819. } = this.state;
  1820. const {
  1821. length
  1822. } = commentStack;
  1823. if (length === 0) return;
  1824. const commentWS = commentStack[length - 1];
  1825. if (commentWS.leadingNode === node) {
  1826. commentWS.leadingNode = null;
  1827. }
  1828. }
  1829. resetPreviousIdentifierLeadingComments(node) {
  1830. const {
  1831. commentStack
  1832. } = this.state;
  1833. const {
  1834. length
  1835. } = commentStack;
  1836. if (length === 0) return;
  1837. if (commentStack[length - 1].trailingNode === node) {
  1838. commentStack[length - 1].trailingNode = null;
  1839. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1840. commentStack[length - 2].trailingNode = null;
  1841. }
  1842. }
  1843. takeSurroundingComments(node, start, end) {
  1844. const {
  1845. commentStack
  1846. } = this.state;
  1847. const commentStackLength = commentStack.length;
  1848. if (commentStackLength === 0) return;
  1849. let i = commentStackLength - 1;
  1850. for (; i >= 0; i--) {
  1851. const commentWS = commentStack[i];
  1852. const commentEnd = commentWS.end;
  1853. const commentStart = commentWS.start;
  1854. if (commentStart === end) {
  1855. commentWS.leadingNode = node;
  1856. } else if (commentEnd === start) {
  1857. commentWS.trailingNode = node;
  1858. } else if (commentEnd < start) {
  1859. break;
  1860. }
  1861. }
  1862. }
  1863. }
  1864. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  1865. const lineBreakG = new RegExp(lineBreak.source, "g");
  1866. function isNewLine(code) {
  1867. switch (code) {
  1868. case 10:
  1869. case 13:
  1870. case 8232:
  1871. case 8233:
  1872. return true;
  1873. default:
  1874. return false;
  1875. }
  1876. }
  1877. function hasNewLine(input, start, end) {
  1878. for (let i = start; i < end; i++) {
  1879. if (isNewLine(input.charCodeAt(i))) {
  1880. return true;
  1881. }
  1882. }
  1883. return false;
  1884. }
  1885. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1886. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1887. function isWhitespace(code) {
  1888. switch (code) {
  1889. case 0x0009:
  1890. case 0x000b:
  1891. case 0x000c:
  1892. case 32:
  1893. case 160:
  1894. case 5760:
  1895. case 0x2000:
  1896. case 0x2001:
  1897. case 0x2002:
  1898. case 0x2003:
  1899. case 0x2004:
  1900. case 0x2005:
  1901. case 0x2006:
  1902. case 0x2007:
  1903. case 0x2008:
  1904. case 0x2009:
  1905. case 0x200a:
  1906. case 0x202f:
  1907. case 0x205f:
  1908. case 0x3000:
  1909. case 0xfeff:
  1910. return true;
  1911. default:
  1912. return false;
  1913. }
  1914. }
  1915. class State {
  1916. constructor() {
  1917. this.flags = 1024;
  1918. this.startIndex = void 0;
  1919. this.curLine = void 0;
  1920. this.lineStart = void 0;
  1921. this.startLoc = void 0;
  1922. this.endLoc = void 0;
  1923. this.errors = [];
  1924. this.potentialArrowAt = -1;
  1925. this.noArrowAt = [];
  1926. this.noArrowParamsConversionAt = [];
  1927. this.topicContext = {
  1928. maxNumOfResolvableTopics: 0,
  1929. maxTopicIndex: null
  1930. };
  1931. this.labels = [];
  1932. this.commentsLen = 0;
  1933. this.commentStack = [];
  1934. this.pos = 0;
  1935. this.type = 140;
  1936. this.value = null;
  1937. this.start = 0;
  1938. this.end = 0;
  1939. this.lastTokEndLoc = null;
  1940. this.lastTokStartLoc = null;
  1941. this.context = [types.brace];
  1942. this.firstInvalidTemplateEscapePos = null;
  1943. this.strictErrors = new Map();
  1944. this.tokensLength = 0;
  1945. }
  1946. get strict() {
  1947. return (this.flags & 1) > 0;
  1948. }
  1949. set strict(v) {
  1950. if (v) this.flags |= 1;else this.flags &= -2;
  1951. }
  1952. init({
  1953. strictMode,
  1954. sourceType,
  1955. startIndex,
  1956. startLine,
  1957. startColumn
  1958. }) {
  1959. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1960. this.startIndex = startIndex;
  1961. this.curLine = startLine;
  1962. this.lineStart = -startColumn;
  1963. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  1964. }
  1965. get maybeInArrowParameters() {
  1966. return (this.flags & 2) > 0;
  1967. }
  1968. set maybeInArrowParameters(v) {
  1969. if (v) this.flags |= 2;else this.flags &= -3;
  1970. }
  1971. get inType() {
  1972. return (this.flags & 4) > 0;
  1973. }
  1974. set inType(v) {
  1975. if (v) this.flags |= 4;else this.flags &= -5;
  1976. }
  1977. get noAnonFunctionType() {
  1978. return (this.flags & 8) > 0;
  1979. }
  1980. set noAnonFunctionType(v) {
  1981. if (v) this.flags |= 8;else this.flags &= -9;
  1982. }
  1983. get hasFlowComment() {
  1984. return (this.flags & 16) > 0;
  1985. }
  1986. set hasFlowComment(v) {
  1987. if (v) this.flags |= 16;else this.flags &= -17;
  1988. }
  1989. get isAmbientContext() {
  1990. return (this.flags & 32) > 0;
  1991. }
  1992. set isAmbientContext(v) {
  1993. if (v) this.flags |= 32;else this.flags &= -33;
  1994. }
  1995. get inAbstractClass() {
  1996. return (this.flags & 64) > 0;
  1997. }
  1998. set inAbstractClass(v) {
  1999. if (v) this.flags |= 64;else this.flags &= -65;
  2000. }
  2001. get inDisallowConditionalTypesContext() {
  2002. return (this.flags & 128) > 0;
  2003. }
  2004. set inDisallowConditionalTypesContext(v) {
  2005. if (v) this.flags |= 128;else this.flags &= -129;
  2006. }
  2007. get soloAwait() {
  2008. return (this.flags & 256) > 0;
  2009. }
  2010. set soloAwait(v) {
  2011. if (v) this.flags |= 256;else this.flags &= -257;
  2012. }
  2013. get inFSharpPipelineDirectBody() {
  2014. return (this.flags & 512) > 0;
  2015. }
  2016. set inFSharpPipelineDirectBody(v) {
  2017. if (v) this.flags |= 512;else this.flags &= -513;
  2018. }
  2019. get canStartJSXElement() {
  2020. return (this.flags & 1024) > 0;
  2021. }
  2022. set canStartJSXElement(v) {
  2023. if (v) this.flags |= 1024;else this.flags &= -1025;
  2024. }
  2025. get containsEsc() {
  2026. return (this.flags & 2048) > 0;
  2027. }
  2028. set containsEsc(v) {
  2029. if (v) this.flags |= 2048;else this.flags &= -2049;
  2030. }
  2031. get hasTopLevelAwait() {
  2032. return (this.flags & 4096) > 0;
  2033. }
  2034. set hasTopLevelAwait(v) {
  2035. if (v) this.flags |= 4096;else this.flags &= -4097;
  2036. }
  2037. curPosition() {
  2038. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  2039. }
  2040. clone() {
  2041. const state = new State();
  2042. state.flags = this.flags;
  2043. state.startIndex = this.startIndex;
  2044. state.curLine = this.curLine;
  2045. state.lineStart = this.lineStart;
  2046. state.startLoc = this.startLoc;
  2047. state.endLoc = this.endLoc;
  2048. state.errors = this.errors.slice();
  2049. state.potentialArrowAt = this.potentialArrowAt;
  2050. state.noArrowAt = this.noArrowAt.slice();
  2051. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  2052. state.topicContext = this.topicContext;
  2053. state.labels = this.labels.slice();
  2054. state.commentsLen = this.commentsLen;
  2055. state.commentStack = this.commentStack.slice();
  2056. state.pos = this.pos;
  2057. state.type = this.type;
  2058. state.value = this.value;
  2059. state.start = this.start;
  2060. state.end = this.end;
  2061. state.lastTokEndLoc = this.lastTokEndLoc;
  2062. state.lastTokStartLoc = this.lastTokStartLoc;
  2063. state.context = this.context.slice();
  2064. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  2065. state.strictErrors = this.strictErrors;
  2066. state.tokensLength = this.tokensLength;
  2067. return state;
  2068. }
  2069. }
  2070. var _isDigit = function isDigit(code) {
  2071. return code >= 48 && code <= 57;
  2072. };
  2073. const forbiddenNumericSeparatorSiblings = {
  2074. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  2075. hex: new Set([46, 88, 95, 120])
  2076. };
  2077. const isAllowedNumericSeparatorSibling = {
  2078. bin: ch => ch === 48 || ch === 49,
  2079. oct: ch => ch >= 48 && ch <= 55,
  2080. dec: ch => ch >= 48 && ch <= 57,
  2081. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  2082. };
  2083. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  2084. const initialPos = pos;
  2085. const initialLineStart = lineStart;
  2086. const initialCurLine = curLine;
  2087. let out = "";
  2088. let firstInvalidLoc = null;
  2089. let chunkStart = pos;
  2090. const {
  2091. length
  2092. } = input;
  2093. for (;;) {
  2094. if (pos >= length) {
  2095. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2096. out += input.slice(chunkStart, pos);
  2097. break;
  2098. }
  2099. const ch = input.charCodeAt(pos);
  2100. if (isStringEnd(type, ch, input, pos)) {
  2101. out += input.slice(chunkStart, pos);
  2102. break;
  2103. }
  2104. if (ch === 92) {
  2105. out += input.slice(chunkStart, pos);
  2106. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  2107. if (res.ch === null && !firstInvalidLoc) {
  2108. firstInvalidLoc = {
  2109. pos,
  2110. lineStart,
  2111. curLine
  2112. };
  2113. } else {
  2114. out += res.ch;
  2115. }
  2116. ({
  2117. pos,
  2118. lineStart,
  2119. curLine
  2120. } = res);
  2121. chunkStart = pos;
  2122. } else if (ch === 8232 || ch === 8233) {
  2123. ++pos;
  2124. ++curLine;
  2125. lineStart = pos;
  2126. } else if (ch === 10 || ch === 13) {
  2127. if (type === "template") {
  2128. out += input.slice(chunkStart, pos) + "\n";
  2129. ++pos;
  2130. if (ch === 13 && input.charCodeAt(pos) === 10) {
  2131. ++pos;
  2132. }
  2133. ++curLine;
  2134. chunkStart = lineStart = pos;
  2135. } else {
  2136. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  2137. }
  2138. } else {
  2139. ++pos;
  2140. }
  2141. }
  2142. return {
  2143. pos,
  2144. str: out,
  2145. firstInvalidLoc,
  2146. lineStart,
  2147. curLine,
  2148. containsInvalid: !!firstInvalidLoc
  2149. };
  2150. }
  2151. function isStringEnd(type, ch, input, pos) {
  2152. if (type === "template") {
  2153. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  2154. }
  2155. return ch === (type === "double" ? 34 : 39);
  2156. }
  2157. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  2158. const throwOnInvalid = !inTemplate;
  2159. pos++;
  2160. const res = ch => ({
  2161. pos,
  2162. ch,
  2163. lineStart,
  2164. curLine
  2165. });
  2166. const ch = input.charCodeAt(pos++);
  2167. switch (ch) {
  2168. case 110:
  2169. return res("\n");
  2170. case 114:
  2171. return res("\r");
  2172. case 120:
  2173. {
  2174. let code;
  2175. ({
  2176. code,
  2177. pos
  2178. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2179. return res(code === null ? null : String.fromCharCode(code));
  2180. }
  2181. case 117:
  2182. {
  2183. let code;
  2184. ({
  2185. code,
  2186. pos
  2187. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2188. return res(code === null ? null : String.fromCodePoint(code));
  2189. }
  2190. case 116:
  2191. return res("\t");
  2192. case 98:
  2193. return res("\b");
  2194. case 118:
  2195. return res("\u000b");
  2196. case 102:
  2197. return res("\f");
  2198. case 13:
  2199. if (input.charCodeAt(pos) === 10) {
  2200. ++pos;
  2201. }
  2202. case 10:
  2203. lineStart = pos;
  2204. ++curLine;
  2205. case 8232:
  2206. case 8233:
  2207. return res("");
  2208. case 56:
  2209. case 57:
  2210. if (inTemplate) {
  2211. return res(null);
  2212. } else {
  2213. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2214. }
  2215. default:
  2216. if (ch >= 48 && ch <= 55) {
  2217. const startPos = pos - 1;
  2218. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  2219. let octalStr = match[0];
  2220. let octal = parseInt(octalStr, 8);
  2221. if (octal > 255) {
  2222. octalStr = octalStr.slice(0, -1);
  2223. octal = parseInt(octalStr, 8);
  2224. }
  2225. pos += octalStr.length - 1;
  2226. const next = input.charCodeAt(pos);
  2227. if (octalStr !== "0" || next === 56 || next === 57) {
  2228. if (inTemplate) {
  2229. return res(null);
  2230. } else {
  2231. errors.strictNumericEscape(startPos, lineStart, curLine);
  2232. }
  2233. }
  2234. return res(String.fromCharCode(octal));
  2235. }
  2236. return res(String.fromCharCode(ch));
  2237. }
  2238. }
  2239. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2240. const initialPos = pos;
  2241. let n;
  2242. ({
  2243. n,
  2244. pos
  2245. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2246. if (n === null) {
  2247. if (throwOnInvalid) {
  2248. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2249. } else {
  2250. pos = initialPos - 1;
  2251. }
  2252. }
  2253. return {
  2254. code: n,
  2255. pos
  2256. };
  2257. }
  2258. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2259. const start = pos;
  2260. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2261. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2262. let invalid = false;
  2263. let total = 0;
  2264. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2265. const code = input.charCodeAt(pos);
  2266. let val;
  2267. if (code === 95 && allowNumSeparator !== "bail") {
  2268. const prev = input.charCodeAt(pos - 1);
  2269. const next = input.charCodeAt(pos + 1);
  2270. if (!allowNumSeparator) {
  2271. if (bailOnError) return {
  2272. n: null,
  2273. pos
  2274. };
  2275. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2276. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2277. if (bailOnError) return {
  2278. n: null,
  2279. pos
  2280. };
  2281. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2282. }
  2283. ++pos;
  2284. continue;
  2285. }
  2286. if (code >= 97) {
  2287. val = code - 97 + 10;
  2288. } else if (code >= 65) {
  2289. val = code - 65 + 10;
  2290. } else if (_isDigit(code)) {
  2291. val = code - 48;
  2292. } else {
  2293. val = Infinity;
  2294. }
  2295. if (val >= radix) {
  2296. if (val <= 9 && bailOnError) {
  2297. return {
  2298. n: null,
  2299. pos
  2300. };
  2301. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2302. val = 0;
  2303. } else if (forceLen) {
  2304. val = 0;
  2305. invalid = true;
  2306. } else {
  2307. break;
  2308. }
  2309. }
  2310. ++pos;
  2311. total = total * radix + val;
  2312. }
  2313. if (pos === start || len != null && pos - start !== len || invalid) {
  2314. return {
  2315. n: null,
  2316. pos
  2317. };
  2318. }
  2319. return {
  2320. n: total,
  2321. pos
  2322. };
  2323. }
  2324. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2325. const ch = input.charCodeAt(pos);
  2326. let code;
  2327. if (ch === 123) {
  2328. ++pos;
  2329. ({
  2330. code,
  2331. pos
  2332. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2333. ++pos;
  2334. if (code !== null && code > 0x10ffff) {
  2335. if (throwOnInvalid) {
  2336. errors.invalidCodePoint(pos, lineStart, curLine);
  2337. } else {
  2338. return {
  2339. code: null,
  2340. pos
  2341. };
  2342. }
  2343. }
  2344. } else {
  2345. ({
  2346. code,
  2347. pos
  2348. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2349. }
  2350. return {
  2351. code,
  2352. pos
  2353. };
  2354. }
  2355. function buildPosition(pos, lineStart, curLine) {
  2356. return new Position(curLine, pos - lineStart, pos);
  2357. }
  2358. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2359. class Token {
  2360. constructor(state) {
  2361. const startIndex = state.startIndex || 0;
  2362. this.type = state.type;
  2363. this.value = state.value;
  2364. this.start = startIndex + state.start;
  2365. this.end = startIndex + state.end;
  2366. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2367. }
  2368. }
  2369. class Tokenizer extends CommentsParser {
  2370. constructor(options, input) {
  2371. super();
  2372. this.isLookahead = void 0;
  2373. this.tokens = [];
  2374. this.errorHandlers_readInt = {
  2375. invalidDigit: (pos, lineStart, curLine, radix) => {
  2376. if (!(this.optionFlags & 1024)) return false;
  2377. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  2378. radix
  2379. });
  2380. return true;
  2381. },
  2382. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2383. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2384. };
  2385. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2386. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2387. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2388. });
  2389. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2390. strictNumericEscape: (pos, lineStart, curLine) => {
  2391. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  2392. },
  2393. unterminated: (pos, lineStart, curLine) => {
  2394. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  2395. }
  2396. });
  2397. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2398. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2399. unterminated: (pos, lineStart, curLine) => {
  2400. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  2401. }
  2402. });
  2403. this.state = new State();
  2404. this.state.init(options);
  2405. this.input = input;
  2406. this.length = input.length;
  2407. this.comments = [];
  2408. this.isLookahead = false;
  2409. }
  2410. pushToken(token) {
  2411. this.tokens.length = this.state.tokensLength;
  2412. this.tokens.push(token);
  2413. ++this.state.tokensLength;
  2414. }
  2415. next() {
  2416. this.checkKeywordEscapes();
  2417. if (this.optionFlags & 128) {
  2418. this.pushToken(new Token(this.state));
  2419. }
  2420. this.state.lastTokEndLoc = this.state.endLoc;
  2421. this.state.lastTokStartLoc = this.state.startLoc;
  2422. this.nextToken();
  2423. }
  2424. eat(type) {
  2425. if (this.match(type)) {
  2426. this.next();
  2427. return true;
  2428. } else {
  2429. return false;
  2430. }
  2431. }
  2432. match(type) {
  2433. return this.state.type === type;
  2434. }
  2435. createLookaheadState(state) {
  2436. return {
  2437. pos: state.pos,
  2438. value: null,
  2439. type: state.type,
  2440. start: state.start,
  2441. end: state.end,
  2442. context: [this.curContext()],
  2443. inType: state.inType,
  2444. startLoc: state.startLoc,
  2445. lastTokEndLoc: state.lastTokEndLoc,
  2446. curLine: state.curLine,
  2447. lineStart: state.lineStart,
  2448. curPosition: state.curPosition
  2449. };
  2450. }
  2451. lookahead() {
  2452. const old = this.state;
  2453. this.state = this.createLookaheadState(old);
  2454. this.isLookahead = true;
  2455. this.nextToken();
  2456. this.isLookahead = false;
  2457. const curr = this.state;
  2458. this.state = old;
  2459. return curr;
  2460. }
  2461. nextTokenStart() {
  2462. return this.nextTokenStartSince(this.state.pos);
  2463. }
  2464. nextTokenStartSince(pos) {
  2465. skipWhiteSpace.lastIndex = pos;
  2466. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2467. }
  2468. lookaheadCharCode() {
  2469. return this.input.charCodeAt(this.nextTokenStart());
  2470. }
  2471. nextTokenInLineStart() {
  2472. return this.nextTokenInLineStartSince(this.state.pos);
  2473. }
  2474. nextTokenInLineStartSince(pos) {
  2475. skipWhiteSpaceInLine.lastIndex = pos;
  2476. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2477. }
  2478. lookaheadInLineCharCode() {
  2479. return this.input.charCodeAt(this.nextTokenInLineStart());
  2480. }
  2481. codePointAtPos(pos) {
  2482. let cp = this.input.charCodeAt(pos);
  2483. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2484. const trail = this.input.charCodeAt(pos);
  2485. if ((trail & 0xfc00) === 0xdc00) {
  2486. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2487. }
  2488. }
  2489. return cp;
  2490. }
  2491. setStrict(strict) {
  2492. this.state.strict = strict;
  2493. if (strict) {
  2494. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  2495. this.state.strictErrors.clear();
  2496. }
  2497. }
  2498. curContext() {
  2499. return this.state.context[this.state.context.length - 1];
  2500. }
  2501. nextToken() {
  2502. this.skipSpace();
  2503. this.state.start = this.state.pos;
  2504. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2505. if (this.state.pos >= this.length) {
  2506. this.finishToken(140);
  2507. return;
  2508. }
  2509. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2510. }
  2511. skipBlockComment(commentEnd) {
  2512. let startLoc;
  2513. if (!this.isLookahead) startLoc = this.state.curPosition();
  2514. const start = this.state.pos;
  2515. const end = this.input.indexOf(commentEnd, start + 2);
  2516. if (end === -1) {
  2517. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  2518. }
  2519. this.state.pos = end + commentEnd.length;
  2520. lineBreakG.lastIndex = start + 2;
  2521. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2522. ++this.state.curLine;
  2523. this.state.lineStart = lineBreakG.lastIndex;
  2524. }
  2525. if (this.isLookahead) return;
  2526. const comment = {
  2527. type: "CommentBlock",
  2528. value: this.input.slice(start + 2, end),
  2529. start: this.sourceToOffsetPos(start),
  2530. end: this.sourceToOffsetPos(end + commentEnd.length),
  2531. loc: new SourceLocation(startLoc, this.state.curPosition())
  2532. };
  2533. if (this.optionFlags & 128) this.pushToken(comment);
  2534. return comment;
  2535. }
  2536. skipLineComment(startSkip) {
  2537. const start = this.state.pos;
  2538. let startLoc;
  2539. if (!this.isLookahead) startLoc = this.state.curPosition();
  2540. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2541. if (this.state.pos < this.length) {
  2542. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2543. ch = this.input.charCodeAt(this.state.pos);
  2544. }
  2545. }
  2546. if (this.isLookahead) return;
  2547. const end = this.state.pos;
  2548. const value = this.input.slice(start + startSkip, end);
  2549. const comment = {
  2550. type: "CommentLine",
  2551. value,
  2552. start: this.sourceToOffsetPos(start),
  2553. end: this.sourceToOffsetPos(end),
  2554. loc: new SourceLocation(startLoc, this.state.curPosition())
  2555. };
  2556. if (this.optionFlags & 128) this.pushToken(comment);
  2557. return comment;
  2558. }
  2559. skipSpace() {
  2560. const spaceStart = this.state.pos;
  2561. const comments = this.optionFlags & 2048 ? [] : null;
  2562. loop: while (this.state.pos < this.length) {
  2563. const ch = this.input.charCodeAt(this.state.pos);
  2564. switch (ch) {
  2565. case 32:
  2566. case 160:
  2567. case 9:
  2568. ++this.state.pos;
  2569. break;
  2570. case 13:
  2571. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2572. ++this.state.pos;
  2573. }
  2574. case 10:
  2575. case 8232:
  2576. case 8233:
  2577. ++this.state.pos;
  2578. ++this.state.curLine;
  2579. this.state.lineStart = this.state.pos;
  2580. break;
  2581. case 47:
  2582. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2583. case 42:
  2584. {
  2585. const comment = this.skipBlockComment("*/");
  2586. if (comment !== undefined) {
  2587. this.addComment(comment);
  2588. comments == null || comments.push(comment);
  2589. }
  2590. break;
  2591. }
  2592. case 47:
  2593. {
  2594. const comment = this.skipLineComment(2);
  2595. if (comment !== undefined) {
  2596. this.addComment(comment);
  2597. comments == null || comments.push(comment);
  2598. }
  2599. break;
  2600. }
  2601. default:
  2602. break loop;
  2603. }
  2604. break;
  2605. default:
  2606. if (isWhitespace(ch)) {
  2607. ++this.state.pos;
  2608. } else if (ch === 45 && !this.inModule && this.optionFlags & 4096) {
  2609. const pos = this.state.pos;
  2610. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2611. const comment = this.skipLineComment(3);
  2612. if (comment !== undefined) {
  2613. this.addComment(comment);
  2614. comments == null || comments.push(comment);
  2615. }
  2616. } else {
  2617. break loop;
  2618. }
  2619. } else if (ch === 60 && !this.inModule && this.optionFlags & 4096) {
  2620. const pos = this.state.pos;
  2621. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2622. const comment = this.skipLineComment(4);
  2623. if (comment !== undefined) {
  2624. this.addComment(comment);
  2625. comments == null || comments.push(comment);
  2626. }
  2627. } else {
  2628. break loop;
  2629. }
  2630. } else {
  2631. break loop;
  2632. }
  2633. }
  2634. }
  2635. if ((comments == null ? void 0 : comments.length) > 0) {
  2636. const end = this.state.pos;
  2637. const commentWhitespace = {
  2638. start: this.sourceToOffsetPos(spaceStart),
  2639. end: this.sourceToOffsetPos(end),
  2640. comments,
  2641. leadingNode: null,
  2642. trailingNode: null,
  2643. containingNode: null
  2644. };
  2645. this.state.commentStack.push(commentWhitespace);
  2646. }
  2647. }
  2648. finishToken(type, val) {
  2649. this.state.end = this.state.pos;
  2650. this.state.endLoc = this.state.curPosition();
  2651. const prevType = this.state.type;
  2652. this.state.type = type;
  2653. this.state.value = val;
  2654. if (!this.isLookahead) {
  2655. this.updateContext(prevType);
  2656. }
  2657. }
  2658. replaceToken(type) {
  2659. this.state.type = type;
  2660. this.updateContext();
  2661. }
  2662. readToken_numberSign() {
  2663. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2664. return;
  2665. }
  2666. const nextPos = this.state.pos + 1;
  2667. const next = this.codePointAtPos(nextPos);
  2668. if (next >= 48 && next <= 57) {
  2669. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  2670. }
  2671. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2672. this.expectPlugin("recordAndTuple");
  2673. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2674. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  2675. }
  2676. this.state.pos += 2;
  2677. if (next === 123) {
  2678. this.finishToken(7);
  2679. } else {
  2680. this.finishToken(1);
  2681. }
  2682. } else if (isIdentifierStart(next)) {
  2683. ++this.state.pos;
  2684. this.finishToken(139, this.readWord1(next));
  2685. } else if (next === 92) {
  2686. ++this.state.pos;
  2687. this.finishToken(139, this.readWord1());
  2688. } else {
  2689. this.finishOp(27, 1);
  2690. }
  2691. }
  2692. readToken_dot() {
  2693. const next = this.input.charCodeAt(this.state.pos + 1);
  2694. if (next >= 48 && next <= 57) {
  2695. this.readNumber(true);
  2696. return;
  2697. }
  2698. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2699. this.state.pos += 3;
  2700. this.finishToken(21);
  2701. } else {
  2702. ++this.state.pos;
  2703. this.finishToken(16);
  2704. }
  2705. }
  2706. readToken_slash() {
  2707. const next = this.input.charCodeAt(this.state.pos + 1);
  2708. if (next === 61) {
  2709. this.finishOp(31, 2);
  2710. } else {
  2711. this.finishOp(56, 1);
  2712. }
  2713. }
  2714. readToken_interpreter() {
  2715. if (this.state.pos !== 0 || this.length < 2) return false;
  2716. let ch = this.input.charCodeAt(this.state.pos + 1);
  2717. if (ch !== 33) return false;
  2718. const start = this.state.pos;
  2719. this.state.pos += 1;
  2720. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2721. ch = this.input.charCodeAt(this.state.pos);
  2722. }
  2723. const value = this.input.slice(start + 2, this.state.pos);
  2724. this.finishToken(28, value);
  2725. return true;
  2726. }
  2727. readToken_mult_modulo(code) {
  2728. let type = code === 42 ? 55 : 54;
  2729. let width = 1;
  2730. let next = this.input.charCodeAt(this.state.pos + 1);
  2731. if (code === 42 && next === 42) {
  2732. width++;
  2733. next = this.input.charCodeAt(this.state.pos + 2);
  2734. type = 57;
  2735. }
  2736. if (next === 61 && !this.state.inType) {
  2737. width++;
  2738. type = code === 37 ? 33 : 30;
  2739. }
  2740. this.finishOp(type, width);
  2741. }
  2742. readToken_pipe_amp(code) {
  2743. const next = this.input.charCodeAt(this.state.pos + 1);
  2744. if (next === code) {
  2745. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2746. this.finishOp(30, 3);
  2747. } else {
  2748. this.finishOp(code === 124 ? 41 : 42, 2);
  2749. }
  2750. return;
  2751. }
  2752. if (code === 124) {
  2753. if (next === 62) {
  2754. this.finishOp(39, 2);
  2755. return;
  2756. }
  2757. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2758. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2759. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2760. }
  2761. this.state.pos += 2;
  2762. this.finishToken(9);
  2763. return;
  2764. }
  2765. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2766. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2767. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  2768. }
  2769. this.state.pos += 2;
  2770. this.finishToken(4);
  2771. return;
  2772. }
  2773. }
  2774. if (next === 61) {
  2775. this.finishOp(30, 2);
  2776. return;
  2777. }
  2778. this.finishOp(code === 124 ? 43 : 45, 1);
  2779. }
  2780. readToken_caret() {
  2781. const next = this.input.charCodeAt(this.state.pos + 1);
  2782. if (next === 61 && !this.state.inType) {
  2783. this.finishOp(32, 2);
  2784. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2785. proposal: "hack",
  2786. topicToken: "^^"
  2787. }])) {
  2788. this.finishOp(37, 2);
  2789. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2790. if (lookaheadCh === 94) {
  2791. this.unexpected();
  2792. }
  2793. } else {
  2794. this.finishOp(44, 1);
  2795. }
  2796. }
  2797. readToken_atSign() {
  2798. const next = this.input.charCodeAt(this.state.pos + 1);
  2799. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2800. proposal: "hack",
  2801. topicToken: "@@"
  2802. }])) {
  2803. this.finishOp(38, 2);
  2804. } else {
  2805. this.finishOp(26, 1);
  2806. }
  2807. }
  2808. readToken_plus_min(code) {
  2809. const next = this.input.charCodeAt(this.state.pos + 1);
  2810. if (next === code) {
  2811. this.finishOp(34, 2);
  2812. return;
  2813. }
  2814. if (next === 61) {
  2815. this.finishOp(30, 2);
  2816. } else {
  2817. this.finishOp(53, 1);
  2818. }
  2819. }
  2820. readToken_lt() {
  2821. const {
  2822. pos
  2823. } = this.state;
  2824. const next = this.input.charCodeAt(pos + 1);
  2825. if (next === 60) {
  2826. if (this.input.charCodeAt(pos + 2) === 61) {
  2827. this.finishOp(30, 3);
  2828. return;
  2829. }
  2830. this.finishOp(51, 2);
  2831. return;
  2832. }
  2833. if (next === 61) {
  2834. this.finishOp(49, 2);
  2835. return;
  2836. }
  2837. this.finishOp(47, 1);
  2838. }
  2839. readToken_gt() {
  2840. const {
  2841. pos
  2842. } = this.state;
  2843. const next = this.input.charCodeAt(pos + 1);
  2844. if (next === 62) {
  2845. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2846. if (this.input.charCodeAt(pos + size) === 61) {
  2847. this.finishOp(30, size + 1);
  2848. return;
  2849. }
  2850. this.finishOp(52, size);
  2851. return;
  2852. }
  2853. if (next === 61) {
  2854. this.finishOp(49, 2);
  2855. return;
  2856. }
  2857. this.finishOp(48, 1);
  2858. }
  2859. readToken_eq_excl(code) {
  2860. const next = this.input.charCodeAt(this.state.pos + 1);
  2861. if (next === 61) {
  2862. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2863. return;
  2864. }
  2865. if (code === 61 && next === 62) {
  2866. this.state.pos += 2;
  2867. this.finishToken(19);
  2868. return;
  2869. }
  2870. this.finishOp(code === 61 ? 29 : 35, 1);
  2871. }
  2872. readToken_question() {
  2873. const next = this.input.charCodeAt(this.state.pos + 1);
  2874. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2875. if (next === 63) {
  2876. if (next2 === 61) {
  2877. this.finishOp(30, 3);
  2878. } else {
  2879. this.finishOp(40, 2);
  2880. }
  2881. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2882. this.state.pos += 2;
  2883. this.finishToken(18);
  2884. } else {
  2885. ++this.state.pos;
  2886. this.finishToken(17);
  2887. }
  2888. }
  2889. getTokenFromCode(code) {
  2890. switch (code) {
  2891. case 46:
  2892. this.readToken_dot();
  2893. return;
  2894. case 40:
  2895. ++this.state.pos;
  2896. this.finishToken(10);
  2897. return;
  2898. case 41:
  2899. ++this.state.pos;
  2900. this.finishToken(11);
  2901. return;
  2902. case 59:
  2903. ++this.state.pos;
  2904. this.finishToken(13);
  2905. return;
  2906. case 44:
  2907. ++this.state.pos;
  2908. this.finishToken(12);
  2909. return;
  2910. case 91:
  2911. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2912. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2913. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2914. }
  2915. this.state.pos += 2;
  2916. this.finishToken(2);
  2917. } else {
  2918. ++this.state.pos;
  2919. this.finishToken(0);
  2920. }
  2921. return;
  2922. case 93:
  2923. ++this.state.pos;
  2924. this.finishToken(3);
  2925. return;
  2926. case 123:
  2927. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2928. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2929. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  2930. }
  2931. this.state.pos += 2;
  2932. this.finishToken(6);
  2933. } else {
  2934. ++this.state.pos;
  2935. this.finishToken(5);
  2936. }
  2937. return;
  2938. case 125:
  2939. ++this.state.pos;
  2940. this.finishToken(8);
  2941. return;
  2942. case 58:
  2943. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2944. this.finishOp(15, 2);
  2945. } else {
  2946. ++this.state.pos;
  2947. this.finishToken(14);
  2948. }
  2949. return;
  2950. case 63:
  2951. this.readToken_question();
  2952. return;
  2953. case 96:
  2954. this.readTemplateToken();
  2955. return;
  2956. case 48:
  2957. {
  2958. const next = this.input.charCodeAt(this.state.pos + 1);
  2959. if (next === 120 || next === 88) {
  2960. this.readRadixNumber(16);
  2961. return;
  2962. }
  2963. if (next === 111 || next === 79) {
  2964. this.readRadixNumber(8);
  2965. return;
  2966. }
  2967. if (next === 98 || next === 66) {
  2968. this.readRadixNumber(2);
  2969. return;
  2970. }
  2971. }
  2972. case 49:
  2973. case 50:
  2974. case 51:
  2975. case 52:
  2976. case 53:
  2977. case 54:
  2978. case 55:
  2979. case 56:
  2980. case 57:
  2981. this.readNumber(false);
  2982. return;
  2983. case 34:
  2984. case 39:
  2985. this.readString(code);
  2986. return;
  2987. case 47:
  2988. this.readToken_slash();
  2989. return;
  2990. case 37:
  2991. case 42:
  2992. this.readToken_mult_modulo(code);
  2993. return;
  2994. case 124:
  2995. case 38:
  2996. this.readToken_pipe_amp(code);
  2997. return;
  2998. case 94:
  2999. this.readToken_caret();
  3000. return;
  3001. case 43:
  3002. case 45:
  3003. this.readToken_plus_min(code);
  3004. return;
  3005. case 60:
  3006. this.readToken_lt();
  3007. return;
  3008. case 62:
  3009. this.readToken_gt();
  3010. return;
  3011. case 61:
  3012. case 33:
  3013. this.readToken_eq_excl(code);
  3014. return;
  3015. case 126:
  3016. this.finishOp(36, 1);
  3017. return;
  3018. case 64:
  3019. this.readToken_atSign();
  3020. return;
  3021. case 35:
  3022. this.readToken_numberSign();
  3023. return;
  3024. case 92:
  3025. this.readWord();
  3026. return;
  3027. default:
  3028. if (isIdentifierStart(code)) {
  3029. this.readWord(code);
  3030. return;
  3031. }
  3032. }
  3033. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  3034. unexpected: String.fromCodePoint(code)
  3035. });
  3036. }
  3037. finishOp(type, size) {
  3038. const str = this.input.slice(this.state.pos, this.state.pos + size);
  3039. this.state.pos += size;
  3040. this.finishToken(type, str);
  3041. }
  3042. readRegexp() {
  3043. const startLoc = this.state.startLoc;
  3044. const start = this.state.start + 1;
  3045. let escaped, inClass;
  3046. let {
  3047. pos
  3048. } = this.state;
  3049. for (;; ++pos) {
  3050. if (pos >= this.length) {
  3051. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  3052. }
  3053. const ch = this.input.charCodeAt(pos);
  3054. if (isNewLine(ch)) {
  3055. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  3056. }
  3057. if (escaped) {
  3058. escaped = false;
  3059. } else {
  3060. if (ch === 91) {
  3061. inClass = true;
  3062. } else if (ch === 93 && inClass) {
  3063. inClass = false;
  3064. } else if (ch === 47 && !inClass) {
  3065. break;
  3066. }
  3067. escaped = ch === 92;
  3068. }
  3069. }
  3070. const content = this.input.slice(start, pos);
  3071. ++pos;
  3072. let mods = "";
  3073. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  3074. while (pos < this.length) {
  3075. const cp = this.codePointAtPos(pos);
  3076. const char = String.fromCharCode(cp);
  3077. if (VALID_REGEX_FLAGS.has(cp)) {
  3078. if (cp === 118) {
  3079. if (mods.includes("u")) {
  3080. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3081. }
  3082. } else if (cp === 117) {
  3083. if (mods.includes("v")) {
  3084. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  3085. }
  3086. }
  3087. if (mods.includes(char)) {
  3088. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  3089. }
  3090. } else if (isIdentifierChar(cp) || cp === 92) {
  3091. this.raise(Errors.MalformedRegExpFlags, nextPos());
  3092. } else {
  3093. break;
  3094. }
  3095. ++pos;
  3096. mods += char;
  3097. }
  3098. this.state.pos = pos;
  3099. this.finishToken(138, {
  3100. pattern: content,
  3101. flags: mods
  3102. });
  3103. }
  3104. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  3105. const {
  3106. n,
  3107. pos
  3108. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  3109. this.state.pos = pos;
  3110. return n;
  3111. }
  3112. readRadixNumber(radix) {
  3113. const start = this.state.pos;
  3114. const startLoc = this.state.curPosition();
  3115. let isBigInt = false;
  3116. this.state.pos += 2;
  3117. const val = this.readInt(radix);
  3118. if (val == null) {
  3119. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  3120. radix
  3121. });
  3122. }
  3123. const next = this.input.charCodeAt(this.state.pos);
  3124. if (next === 110) {
  3125. ++this.state.pos;
  3126. isBigInt = true;
  3127. } else if (next === 109) {
  3128. throw this.raise(Errors.InvalidDecimal, startLoc);
  3129. }
  3130. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3131. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3132. }
  3133. if (isBigInt) {
  3134. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  3135. this.finishToken(136, str);
  3136. return;
  3137. }
  3138. this.finishToken(135, val);
  3139. }
  3140. readNumber(startsWithDot) {
  3141. const start = this.state.pos;
  3142. const startLoc = this.state.curPosition();
  3143. let isFloat = false;
  3144. let isBigInt = false;
  3145. let hasExponent = false;
  3146. let isOctal = false;
  3147. if (!startsWithDot && this.readInt(10) === null) {
  3148. this.raise(Errors.InvalidNumber, this.state.curPosition());
  3149. }
  3150. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3151. if (hasLeadingZero) {
  3152. const integer = this.input.slice(start, this.state.pos);
  3153. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  3154. if (!this.state.strict) {
  3155. const underscorePos = integer.indexOf("_");
  3156. if (underscorePos > 0) {
  3157. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  3158. }
  3159. }
  3160. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3161. }
  3162. let next = this.input.charCodeAt(this.state.pos);
  3163. if (next === 46 && !isOctal) {
  3164. ++this.state.pos;
  3165. this.readInt(10);
  3166. isFloat = true;
  3167. next = this.input.charCodeAt(this.state.pos);
  3168. }
  3169. if ((next === 69 || next === 101) && !isOctal) {
  3170. next = this.input.charCodeAt(++this.state.pos);
  3171. if (next === 43 || next === 45) {
  3172. ++this.state.pos;
  3173. }
  3174. if (this.readInt(10) === null) {
  3175. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  3176. }
  3177. isFloat = true;
  3178. hasExponent = true;
  3179. next = this.input.charCodeAt(this.state.pos);
  3180. }
  3181. if (next === 110) {
  3182. if (isFloat || hasLeadingZero) {
  3183. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  3184. }
  3185. ++this.state.pos;
  3186. isBigInt = true;
  3187. }
  3188. if (next === 109) {
  3189. this.expectPlugin("decimal", this.state.curPosition());
  3190. if (hasExponent || hasLeadingZero) {
  3191. this.raise(Errors.InvalidDecimal, startLoc);
  3192. }
  3193. ++this.state.pos;
  3194. var isDecimal = true;
  3195. }
  3196. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3197. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  3198. }
  3199. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3200. if (isBigInt) {
  3201. this.finishToken(136, str);
  3202. return;
  3203. }
  3204. if (isDecimal) {
  3205. this.finishToken(137, str);
  3206. return;
  3207. }
  3208. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3209. this.finishToken(135, val);
  3210. }
  3211. readCodePoint(throwOnInvalid) {
  3212. const {
  3213. code,
  3214. pos
  3215. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3216. this.state.pos = pos;
  3217. return code;
  3218. }
  3219. readString(quote) {
  3220. const {
  3221. str,
  3222. pos,
  3223. curLine,
  3224. lineStart
  3225. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3226. this.state.pos = pos + 1;
  3227. this.state.lineStart = lineStart;
  3228. this.state.curLine = curLine;
  3229. this.finishToken(134, str);
  3230. }
  3231. readTemplateContinuation() {
  3232. if (!this.match(8)) {
  3233. this.unexpected(null, 8);
  3234. }
  3235. this.state.pos--;
  3236. this.readTemplateToken();
  3237. }
  3238. readTemplateToken() {
  3239. const opening = this.input[this.state.pos];
  3240. const {
  3241. str,
  3242. firstInvalidLoc,
  3243. pos,
  3244. curLine,
  3245. lineStart
  3246. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3247. this.state.pos = pos + 1;
  3248. this.state.lineStart = lineStart;
  3249. this.state.curLine = curLine;
  3250. if (firstInvalidLoc) {
  3251. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  3252. }
  3253. if (this.input.codePointAt(pos) === 96) {
  3254. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3255. } else {
  3256. this.state.pos++;
  3257. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3258. }
  3259. }
  3260. recordStrictModeErrors(toParseError, at) {
  3261. const index = at.index;
  3262. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3263. this.raise(toParseError, at);
  3264. } else {
  3265. this.state.strictErrors.set(index, [toParseError, at]);
  3266. }
  3267. }
  3268. readWord1(firstCode) {
  3269. this.state.containsEsc = false;
  3270. let word = "";
  3271. const start = this.state.pos;
  3272. let chunkStart = this.state.pos;
  3273. if (firstCode !== undefined) {
  3274. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3275. }
  3276. while (this.state.pos < this.length) {
  3277. const ch = this.codePointAtPos(this.state.pos);
  3278. if (isIdentifierChar(ch)) {
  3279. this.state.pos += ch <= 0xffff ? 1 : 2;
  3280. } else if (ch === 92) {
  3281. this.state.containsEsc = true;
  3282. word += this.input.slice(chunkStart, this.state.pos);
  3283. const escStart = this.state.curPosition();
  3284. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3285. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3286. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  3287. chunkStart = this.state.pos - 1;
  3288. continue;
  3289. }
  3290. ++this.state.pos;
  3291. const esc = this.readCodePoint(true);
  3292. if (esc !== null) {
  3293. if (!identifierCheck(esc)) {
  3294. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  3295. }
  3296. word += String.fromCodePoint(esc);
  3297. }
  3298. chunkStart = this.state.pos;
  3299. } else {
  3300. break;
  3301. }
  3302. }
  3303. return word + this.input.slice(chunkStart, this.state.pos);
  3304. }
  3305. readWord(firstCode) {
  3306. const word = this.readWord1(firstCode);
  3307. const type = keywords$1.get(word);
  3308. if (type !== undefined) {
  3309. this.finishToken(type, tokenLabelName(type));
  3310. } else {
  3311. this.finishToken(132, word);
  3312. }
  3313. }
  3314. checkKeywordEscapes() {
  3315. const {
  3316. type
  3317. } = this.state;
  3318. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3319. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  3320. reservedWord: tokenLabelName(type)
  3321. });
  3322. }
  3323. }
  3324. raise(toParseError, at, details = {}) {
  3325. const loc = at instanceof Position ? at : at.loc.start;
  3326. const error = toParseError(loc, details);
  3327. if (!(this.optionFlags & 1024)) throw error;
  3328. if (!this.isLookahead) this.state.errors.push(error);
  3329. return error;
  3330. }
  3331. raiseOverwrite(toParseError, at, details = {}) {
  3332. const loc = at instanceof Position ? at : at.loc.start;
  3333. const pos = loc.index;
  3334. const errors = this.state.errors;
  3335. for (let i = errors.length - 1; i >= 0; i--) {
  3336. const error = errors[i];
  3337. if (error.loc.index === pos) {
  3338. return errors[i] = toParseError(loc, details);
  3339. }
  3340. if (error.loc.index < pos) break;
  3341. }
  3342. return this.raise(toParseError, at, details);
  3343. }
  3344. updateContext(prevType) {}
  3345. unexpected(loc, type) {
  3346. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  3347. expected: type ? tokenLabelName(type) : null
  3348. });
  3349. }
  3350. expectPlugin(pluginName, loc) {
  3351. if (this.hasPlugin(pluginName)) {
  3352. return true;
  3353. }
  3354. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  3355. missingPlugin: [pluginName]
  3356. });
  3357. }
  3358. expectOnePlugin(pluginNames) {
  3359. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3360. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  3361. missingPlugin: pluginNames
  3362. });
  3363. }
  3364. }
  3365. errorBuilder(error) {
  3366. return (pos, lineStart, curLine) => {
  3367. this.raise(error, buildPosition(pos, lineStart, curLine));
  3368. };
  3369. }
  3370. }
  3371. class ClassScope {
  3372. constructor() {
  3373. this.privateNames = new Set();
  3374. this.loneAccessors = new Map();
  3375. this.undefinedPrivateNames = new Map();
  3376. }
  3377. }
  3378. class ClassScopeHandler {
  3379. constructor(parser) {
  3380. this.parser = void 0;
  3381. this.stack = [];
  3382. this.undefinedPrivateNames = new Map();
  3383. this.parser = parser;
  3384. }
  3385. current() {
  3386. return this.stack[this.stack.length - 1];
  3387. }
  3388. enter() {
  3389. this.stack.push(new ClassScope());
  3390. }
  3391. exit() {
  3392. const oldClassScope = this.stack.pop();
  3393. const current = this.current();
  3394. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3395. if (current) {
  3396. if (!current.undefinedPrivateNames.has(name)) {
  3397. current.undefinedPrivateNames.set(name, loc);
  3398. }
  3399. } else {
  3400. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3401. identifierName: name
  3402. });
  3403. }
  3404. }
  3405. }
  3406. declarePrivateName(name, elementType, loc) {
  3407. const {
  3408. privateNames,
  3409. loneAccessors,
  3410. undefinedPrivateNames
  3411. } = this.current();
  3412. let redefined = privateNames.has(name);
  3413. if (elementType & 3) {
  3414. const accessor = redefined && loneAccessors.get(name);
  3415. if (accessor) {
  3416. const oldStatic = accessor & 4;
  3417. const newStatic = elementType & 4;
  3418. const oldKind = accessor & 3;
  3419. const newKind = elementType & 3;
  3420. redefined = oldKind === newKind || oldStatic !== newStatic;
  3421. if (!redefined) loneAccessors.delete(name);
  3422. } else if (!redefined) {
  3423. loneAccessors.set(name, elementType);
  3424. }
  3425. }
  3426. if (redefined) {
  3427. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  3428. identifierName: name
  3429. });
  3430. }
  3431. privateNames.add(name);
  3432. undefinedPrivateNames.delete(name);
  3433. }
  3434. usePrivateName(name, loc) {
  3435. let classScope;
  3436. for (classScope of this.stack) {
  3437. if (classScope.privateNames.has(name)) return;
  3438. }
  3439. if (classScope) {
  3440. classScope.undefinedPrivateNames.set(name, loc);
  3441. } else {
  3442. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  3443. identifierName: name
  3444. });
  3445. }
  3446. }
  3447. }
  3448. class ExpressionScope {
  3449. constructor(type = 0) {
  3450. this.type = type;
  3451. }
  3452. canBeArrowParameterDeclaration() {
  3453. return this.type === 2 || this.type === 1;
  3454. }
  3455. isCertainlyParameterDeclaration() {
  3456. return this.type === 3;
  3457. }
  3458. }
  3459. class ArrowHeadParsingScope extends ExpressionScope {
  3460. constructor(type) {
  3461. super(type);
  3462. this.declarationErrors = new Map();
  3463. }
  3464. recordDeclarationError(ParsingErrorClass, at) {
  3465. const index = at.index;
  3466. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3467. }
  3468. clearDeclarationError(index) {
  3469. this.declarationErrors.delete(index);
  3470. }
  3471. iterateErrors(iterator) {
  3472. this.declarationErrors.forEach(iterator);
  3473. }
  3474. }
  3475. class ExpressionScopeHandler {
  3476. constructor(parser) {
  3477. this.parser = void 0;
  3478. this.stack = [new ExpressionScope()];
  3479. this.parser = parser;
  3480. }
  3481. enter(scope) {
  3482. this.stack.push(scope);
  3483. }
  3484. exit() {
  3485. this.stack.pop();
  3486. }
  3487. recordParameterInitializerError(toParseError, node) {
  3488. const origin = node.loc.start;
  3489. const {
  3490. stack
  3491. } = this;
  3492. let i = stack.length - 1;
  3493. let scope = stack[i];
  3494. while (!scope.isCertainlyParameterDeclaration()) {
  3495. if (scope.canBeArrowParameterDeclaration()) {
  3496. scope.recordDeclarationError(toParseError, origin);
  3497. } else {
  3498. return;
  3499. }
  3500. scope = stack[--i];
  3501. }
  3502. this.parser.raise(toParseError, origin);
  3503. }
  3504. recordArrowParameterBindingError(error, node) {
  3505. const {
  3506. stack
  3507. } = this;
  3508. const scope = stack[stack.length - 1];
  3509. const origin = node.loc.start;
  3510. if (scope.isCertainlyParameterDeclaration()) {
  3511. this.parser.raise(error, origin);
  3512. } else if (scope.canBeArrowParameterDeclaration()) {
  3513. scope.recordDeclarationError(error, origin);
  3514. } else {
  3515. return;
  3516. }
  3517. }
  3518. recordAsyncArrowParametersError(at) {
  3519. const {
  3520. stack
  3521. } = this;
  3522. let i = stack.length - 1;
  3523. let scope = stack[i];
  3524. while (scope.canBeArrowParameterDeclaration()) {
  3525. if (scope.type === 2) {
  3526. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  3527. }
  3528. scope = stack[--i];
  3529. }
  3530. }
  3531. validateAsPattern() {
  3532. const {
  3533. stack
  3534. } = this;
  3535. const currentScope = stack[stack.length - 1];
  3536. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3537. currentScope.iterateErrors(([toParseError, loc]) => {
  3538. this.parser.raise(toParseError, loc);
  3539. let i = stack.length - 2;
  3540. let scope = stack[i];
  3541. while (scope.canBeArrowParameterDeclaration()) {
  3542. scope.clearDeclarationError(loc.index);
  3543. scope = stack[--i];
  3544. }
  3545. });
  3546. }
  3547. }
  3548. function newParameterDeclarationScope() {
  3549. return new ExpressionScope(3);
  3550. }
  3551. function newArrowHeadScope() {
  3552. return new ArrowHeadParsingScope(1);
  3553. }
  3554. function newAsyncArrowScope() {
  3555. return new ArrowHeadParsingScope(2);
  3556. }
  3557. function newExpressionScope() {
  3558. return new ExpressionScope();
  3559. }
  3560. class ProductionParameterHandler {
  3561. constructor() {
  3562. this.stacks = [];
  3563. }
  3564. enter(flags) {
  3565. this.stacks.push(flags);
  3566. }
  3567. exit() {
  3568. this.stacks.pop();
  3569. }
  3570. currentFlags() {
  3571. return this.stacks[this.stacks.length - 1];
  3572. }
  3573. get hasAwait() {
  3574. return (this.currentFlags() & 2) > 0;
  3575. }
  3576. get hasYield() {
  3577. return (this.currentFlags() & 1) > 0;
  3578. }
  3579. get hasReturn() {
  3580. return (this.currentFlags() & 4) > 0;
  3581. }
  3582. get hasIn() {
  3583. return (this.currentFlags() & 8) > 0;
  3584. }
  3585. }
  3586. function functionFlags(isAsync, isGenerator) {
  3587. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  3588. }
  3589. class UtilParser extends Tokenizer {
  3590. addExtra(node, key, value, enumerable = true) {
  3591. if (!node) return;
  3592. let {
  3593. extra
  3594. } = node;
  3595. if (extra == null) {
  3596. extra = {};
  3597. node.extra = extra;
  3598. }
  3599. if (enumerable) {
  3600. extra[key] = value;
  3601. } else {
  3602. Object.defineProperty(extra, key, {
  3603. enumerable,
  3604. value
  3605. });
  3606. }
  3607. }
  3608. isContextual(token) {
  3609. return this.state.type === token && !this.state.containsEsc;
  3610. }
  3611. isUnparsedContextual(nameStart, name) {
  3612. const nameEnd = nameStart + name.length;
  3613. if (this.input.slice(nameStart, nameEnd) === name) {
  3614. const nextCh = this.input.charCodeAt(nameEnd);
  3615. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3616. }
  3617. return false;
  3618. }
  3619. isLookaheadContextual(name) {
  3620. const next = this.nextTokenStart();
  3621. return this.isUnparsedContextual(next, name);
  3622. }
  3623. eatContextual(token) {
  3624. if (this.isContextual(token)) {
  3625. this.next();
  3626. return true;
  3627. }
  3628. return false;
  3629. }
  3630. expectContextual(token, toParseError) {
  3631. if (!this.eatContextual(token)) {
  3632. if (toParseError != null) {
  3633. throw this.raise(toParseError, this.state.startLoc);
  3634. }
  3635. this.unexpected(null, token);
  3636. }
  3637. }
  3638. canInsertSemicolon() {
  3639. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  3640. }
  3641. hasPrecedingLineBreak() {
  3642. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  3643. }
  3644. hasFollowingLineBreak() {
  3645. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  3646. }
  3647. isLineTerminator() {
  3648. return this.eat(13) || this.canInsertSemicolon();
  3649. }
  3650. semicolon(allowAsi = true) {
  3651. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3652. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  3653. }
  3654. expect(type, loc) {
  3655. if (!this.eat(type)) {
  3656. this.unexpected(loc, type);
  3657. }
  3658. }
  3659. tryParse(fn, oldState = this.state.clone()) {
  3660. const abortSignal = {
  3661. node: null
  3662. };
  3663. try {
  3664. const node = fn((node = null) => {
  3665. abortSignal.node = node;
  3666. throw abortSignal;
  3667. });
  3668. if (this.state.errors.length > oldState.errors.length) {
  3669. const failState = this.state;
  3670. this.state = oldState;
  3671. this.state.tokensLength = failState.tokensLength;
  3672. return {
  3673. node,
  3674. error: failState.errors[oldState.errors.length],
  3675. thrown: false,
  3676. aborted: false,
  3677. failState
  3678. };
  3679. }
  3680. return {
  3681. node,
  3682. error: null,
  3683. thrown: false,
  3684. aborted: false,
  3685. failState: null
  3686. };
  3687. } catch (error) {
  3688. const failState = this.state;
  3689. this.state = oldState;
  3690. if (error instanceof SyntaxError) {
  3691. return {
  3692. node: null,
  3693. error,
  3694. thrown: true,
  3695. aborted: false,
  3696. failState
  3697. };
  3698. }
  3699. if (error === abortSignal) {
  3700. return {
  3701. node: abortSignal.node,
  3702. error: null,
  3703. thrown: false,
  3704. aborted: true,
  3705. failState
  3706. };
  3707. }
  3708. throw error;
  3709. }
  3710. }
  3711. checkExpressionErrors(refExpressionErrors, andThrow) {
  3712. if (!refExpressionErrors) return false;
  3713. const {
  3714. shorthandAssignLoc,
  3715. doubleProtoLoc,
  3716. privateKeyLoc,
  3717. optionalParametersLoc
  3718. } = refExpressionErrors;
  3719. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3720. if (!andThrow) {
  3721. return hasErrors;
  3722. }
  3723. if (shorthandAssignLoc != null) {
  3724. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  3725. }
  3726. if (doubleProtoLoc != null) {
  3727. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  3728. }
  3729. if (privateKeyLoc != null) {
  3730. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  3731. }
  3732. if (optionalParametersLoc != null) {
  3733. this.unexpected(optionalParametersLoc);
  3734. }
  3735. }
  3736. isLiteralPropertyName() {
  3737. return tokenIsLiteralPropertyName(this.state.type);
  3738. }
  3739. isPrivateName(node) {
  3740. return node.type === "PrivateName";
  3741. }
  3742. getPrivateNameSV(node) {
  3743. return node.id.name;
  3744. }
  3745. hasPropertyAsPrivateName(node) {
  3746. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3747. }
  3748. isObjectProperty(node) {
  3749. return node.type === "ObjectProperty";
  3750. }
  3751. isObjectMethod(node) {
  3752. return node.type === "ObjectMethod";
  3753. }
  3754. initializeScopes(inModule = this.options.sourceType === "module") {
  3755. const oldLabels = this.state.labels;
  3756. this.state.labels = [];
  3757. const oldExportedIdentifiers = this.exportedIdentifiers;
  3758. this.exportedIdentifiers = new Set();
  3759. const oldInModule = this.inModule;
  3760. this.inModule = inModule;
  3761. const oldScope = this.scope;
  3762. const ScopeHandler = this.getScopeHandler();
  3763. this.scope = new ScopeHandler(this, inModule);
  3764. const oldProdParam = this.prodParam;
  3765. this.prodParam = new ProductionParameterHandler();
  3766. const oldClassScope = this.classScope;
  3767. this.classScope = new ClassScopeHandler(this);
  3768. const oldExpressionScope = this.expressionScope;
  3769. this.expressionScope = new ExpressionScopeHandler(this);
  3770. return () => {
  3771. this.state.labels = oldLabels;
  3772. this.exportedIdentifiers = oldExportedIdentifiers;
  3773. this.inModule = oldInModule;
  3774. this.scope = oldScope;
  3775. this.prodParam = oldProdParam;
  3776. this.classScope = oldClassScope;
  3777. this.expressionScope = oldExpressionScope;
  3778. };
  3779. }
  3780. enterInitialScopes() {
  3781. let paramFlags = 0;
  3782. if (this.inModule) {
  3783. paramFlags |= 2;
  3784. }
  3785. this.scope.enter(1);
  3786. this.prodParam.enter(paramFlags);
  3787. }
  3788. checkDestructuringPrivate(refExpressionErrors) {
  3789. const {
  3790. privateKeyLoc
  3791. } = refExpressionErrors;
  3792. if (privateKeyLoc !== null) {
  3793. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3794. }
  3795. }
  3796. }
  3797. class ExpressionErrors {
  3798. constructor() {
  3799. this.shorthandAssignLoc = null;
  3800. this.doubleProtoLoc = null;
  3801. this.privateKeyLoc = null;
  3802. this.optionalParametersLoc = null;
  3803. }
  3804. }
  3805. class Node {
  3806. constructor(parser, pos, loc) {
  3807. this.type = "";
  3808. this.start = pos;
  3809. this.end = 0;
  3810. this.loc = new SourceLocation(loc);
  3811. if ((parser == null ? void 0 : parser.optionFlags) & 64) this.range = [pos, 0];
  3812. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3813. }
  3814. }
  3815. const NodePrototype = Node.prototype;
  3816. {
  3817. NodePrototype.__clone = function () {
  3818. const newNode = new Node(undefined, this.start, this.loc.start);
  3819. const keys = Object.keys(this);
  3820. for (let i = 0, length = keys.length; i < length; i++) {
  3821. const key = keys[i];
  3822. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3823. newNode[key] = this[key];
  3824. }
  3825. }
  3826. return newNode;
  3827. };
  3828. }
  3829. function clonePlaceholder(node) {
  3830. return cloneIdentifier(node);
  3831. }
  3832. function cloneIdentifier(node) {
  3833. const {
  3834. type,
  3835. start,
  3836. end,
  3837. loc,
  3838. range,
  3839. extra,
  3840. name
  3841. } = node;
  3842. const cloned = Object.create(NodePrototype);
  3843. cloned.type = type;
  3844. cloned.start = start;
  3845. cloned.end = end;
  3846. cloned.loc = loc;
  3847. cloned.range = range;
  3848. cloned.extra = extra;
  3849. cloned.name = name;
  3850. if (type === "Placeholder") {
  3851. cloned.expectedNode = node.expectedNode;
  3852. }
  3853. return cloned;
  3854. }
  3855. function cloneStringLiteral(node) {
  3856. const {
  3857. type,
  3858. start,
  3859. end,
  3860. loc,
  3861. range,
  3862. extra
  3863. } = node;
  3864. if (type === "Placeholder") {
  3865. return clonePlaceholder(node);
  3866. }
  3867. const cloned = Object.create(NodePrototype);
  3868. cloned.type = type;
  3869. cloned.start = start;
  3870. cloned.end = end;
  3871. cloned.loc = loc;
  3872. cloned.range = range;
  3873. if (node.raw !== undefined) {
  3874. cloned.raw = node.raw;
  3875. } else {
  3876. cloned.extra = extra;
  3877. }
  3878. cloned.value = node.value;
  3879. return cloned;
  3880. }
  3881. class NodeUtils extends UtilParser {
  3882. startNode() {
  3883. const loc = this.state.startLoc;
  3884. return new Node(this, loc.index, loc);
  3885. }
  3886. startNodeAt(loc) {
  3887. return new Node(this, loc.index, loc);
  3888. }
  3889. startNodeAtNode(type) {
  3890. return this.startNodeAt(type.loc.start);
  3891. }
  3892. finishNode(node, type) {
  3893. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3894. }
  3895. finishNodeAt(node, type, endLoc) {
  3896. node.type = type;
  3897. node.end = endLoc.index;
  3898. node.loc.end = endLoc;
  3899. if (this.optionFlags & 64) node.range[1] = endLoc.index;
  3900. if (this.optionFlags & 2048) {
  3901. this.processComment(node);
  3902. }
  3903. return node;
  3904. }
  3905. resetStartLocation(node, startLoc) {
  3906. node.start = startLoc.index;
  3907. node.loc.start = startLoc;
  3908. if (this.optionFlags & 64) node.range[0] = startLoc.index;
  3909. }
  3910. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3911. node.end = endLoc.index;
  3912. node.loc.end = endLoc;
  3913. if (this.optionFlags & 64) node.range[1] = endLoc.index;
  3914. }
  3915. resetStartLocationFromNode(node, locationNode) {
  3916. this.resetStartLocation(node, locationNode.loc.start);
  3917. }
  3918. }
  3919. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3920. const FlowErrors = ParseErrorEnum`flow`({
  3921. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3922. 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.",
  3923. AssignReservedType: ({
  3924. reservedType
  3925. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3926. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3927. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3928. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3929. EnumBooleanMemberNotInitialized: ({
  3930. memberName,
  3931. enumName
  3932. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3933. EnumDuplicateMemberName: ({
  3934. memberName,
  3935. enumName
  3936. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3937. EnumInconsistentMemberValues: ({
  3938. enumName
  3939. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3940. EnumInvalidExplicitType: ({
  3941. invalidEnumType,
  3942. enumName
  3943. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3944. EnumInvalidExplicitTypeUnknownSupplied: ({
  3945. enumName
  3946. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3947. EnumInvalidMemberInitializerPrimaryType: ({
  3948. enumName,
  3949. memberName,
  3950. explicitType
  3951. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3952. EnumInvalidMemberInitializerSymbolType: ({
  3953. enumName,
  3954. memberName
  3955. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3956. EnumInvalidMemberInitializerUnknownType: ({
  3957. enumName,
  3958. memberName
  3959. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3960. EnumInvalidMemberName: ({
  3961. enumName,
  3962. memberName,
  3963. suggestion
  3964. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3965. EnumNumberMemberNotInitialized: ({
  3966. enumName,
  3967. memberName
  3968. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3969. EnumStringMemberInconsistentlyInitialized: ({
  3970. enumName
  3971. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3972. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3973. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3974. 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.",
  3975. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3976. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3977. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3978. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3979. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3980. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3981. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3982. PatternIsOptional: Object.assign({
  3983. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3984. }, {
  3985. reasonCode: "OptionalBindingPattern"
  3986. }),
  3987. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3988. SpreadVariance: "Spread properties cannot have variance.",
  3989. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3990. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3991. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3992. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3993. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3994. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3995. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3996. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3997. UnexpectedReservedType: ({
  3998. reservedType
  3999. }) => `Unexpected reserved type ${reservedType}.`,
  4000. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  4001. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  4002. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  4003. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  4004. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  4005. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  4006. UnsupportedDeclareExportKind: ({
  4007. unsupportedExportKind,
  4008. suggestion
  4009. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  4010. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  4011. UnterminatedFlowComment: "Unterminated flow-comment."
  4012. });
  4013. function isEsModuleType(bodyElement) {
  4014. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  4015. }
  4016. function hasTypeImportKind(node) {
  4017. return node.importKind === "type" || node.importKind === "typeof";
  4018. }
  4019. const exportSuggestions = {
  4020. const: "declare export var",
  4021. let: "declare export var",
  4022. type: "export type",
  4023. interface: "export interface"
  4024. };
  4025. function partition(list, test) {
  4026. const list1 = [];
  4027. const list2 = [];
  4028. for (let i = 0; i < list.length; i++) {
  4029. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4030. }
  4031. return [list1, list2];
  4032. }
  4033. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4034. var flow = superClass => class FlowParserMixin extends superClass {
  4035. constructor(...args) {
  4036. super(...args);
  4037. this.flowPragma = undefined;
  4038. }
  4039. getScopeHandler() {
  4040. return FlowScopeHandler;
  4041. }
  4042. shouldParseTypes() {
  4043. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4044. }
  4045. finishToken(type, val) {
  4046. if (type !== 134 && type !== 13 && type !== 28) {
  4047. if (this.flowPragma === undefined) {
  4048. this.flowPragma = null;
  4049. }
  4050. }
  4051. super.finishToken(type, val);
  4052. }
  4053. addComment(comment) {
  4054. if (this.flowPragma === undefined) {
  4055. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4056. if (!matches) ;else if (matches[1] === "flow") {
  4057. this.flowPragma = "flow";
  4058. } else if (matches[1] === "noflow") {
  4059. this.flowPragma = "noflow";
  4060. } else {
  4061. throw new Error("Unexpected flow pragma");
  4062. }
  4063. }
  4064. super.addComment(comment);
  4065. }
  4066. flowParseTypeInitialiser(tok) {
  4067. const oldInType = this.state.inType;
  4068. this.state.inType = true;
  4069. this.expect(tok || 14);
  4070. const type = this.flowParseType();
  4071. this.state.inType = oldInType;
  4072. return type;
  4073. }
  4074. flowParsePredicate() {
  4075. const node = this.startNode();
  4076. const moduloLoc = this.state.startLoc;
  4077. this.next();
  4078. this.expectContextual(110);
  4079. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  4080. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  4081. }
  4082. if (this.eat(10)) {
  4083. node.value = super.parseExpression();
  4084. this.expect(11);
  4085. return this.finishNode(node, "DeclaredPredicate");
  4086. } else {
  4087. return this.finishNode(node, "InferredPredicate");
  4088. }
  4089. }
  4090. flowParseTypeAndPredicateInitialiser() {
  4091. const oldInType = this.state.inType;
  4092. this.state.inType = true;
  4093. this.expect(14);
  4094. let type = null;
  4095. let predicate = null;
  4096. if (this.match(54)) {
  4097. this.state.inType = oldInType;
  4098. predicate = this.flowParsePredicate();
  4099. } else {
  4100. type = this.flowParseType();
  4101. this.state.inType = oldInType;
  4102. if (this.match(54)) {
  4103. predicate = this.flowParsePredicate();
  4104. }
  4105. }
  4106. return [type, predicate];
  4107. }
  4108. flowParseDeclareClass(node) {
  4109. this.next();
  4110. this.flowParseInterfaceish(node, true);
  4111. return this.finishNode(node, "DeclareClass");
  4112. }
  4113. flowParseDeclareFunction(node) {
  4114. this.next();
  4115. const id = node.id = this.parseIdentifier();
  4116. const typeNode = this.startNode();
  4117. const typeContainer = this.startNode();
  4118. if (this.match(47)) {
  4119. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4120. } else {
  4121. typeNode.typeParameters = null;
  4122. }
  4123. this.expect(10);
  4124. const tmp = this.flowParseFunctionTypeParams();
  4125. typeNode.params = tmp.params;
  4126. typeNode.rest = tmp.rest;
  4127. typeNode.this = tmp._this;
  4128. this.expect(11);
  4129. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4130. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4131. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4132. this.resetEndLocation(id);
  4133. this.semicolon();
  4134. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4135. return this.finishNode(node, "DeclareFunction");
  4136. }
  4137. flowParseDeclare(node, insideModule) {
  4138. if (this.match(80)) {
  4139. return this.flowParseDeclareClass(node);
  4140. } else if (this.match(68)) {
  4141. return this.flowParseDeclareFunction(node);
  4142. } else if (this.match(74)) {
  4143. return this.flowParseDeclareVariable(node);
  4144. } else if (this.eatContextual(127)) {
  4145. if (this.match(16)) {
  4146. return this.flowParseDeclareModuleExports(node);
  4147. } else {
  4148. if (insideModule) {
  4149. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  4150. }
  4151. return this.flowParseDeclareModule(node);
  4152. }
  4153. } else if (this.isContextual(130)) {
  4154. return this.flowParseDeclareTypeAlias(node);
  4155. } else if (this.isContextual(131)) {
  4156. return this.flowParseDeclareOpaqueType(node);
  4157. } else if (this.isContextual(129)) {
  4158. return this.flowParseDeclareInterface(node);
  4159. } else if (this.match(82)) {
  4160. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4161. } else {
  4162. this.unexpected();
  4163. }
  4164. }
  4165. flowParseDeclareVariable(node) {
  4166. this.next();
  4167. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4168. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4169. this.semicolon();
  4170. return this.finishNode(node, "DeclareVariable");
  4171. }
  4172. flowParseDeclareModule(node) {
  4173. this.scope.enter(0);
  4174. if (this.match(134)) {
  4175. node.id = super.parseExprAtom();
  4176. } else {
  4177. node.id = this.parseIdentifier();
  4178. }
  4179. const bodyNode = node.body = this.startNode();
  4180. const body = bodyNode.body = [];
  4181. this.expect(5);
  4182. while (!this.match(8)) {
  4183. let bodyNode = this.startNode();
  4184. if (this.match(83)) {
  4185. this.next();
  4186. if (!this.isContextual(130) && !this.match(87)) {
  4187. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  4188. }
  4189. super.parseImport(bodyNode);
  4190. } else {
  4191. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4192. bodyNode = this.flowParseDeclare(bodyNode, true);
  4193. }
  4194. body.push(bodyNode);
  4195. }
  4196. this.scope.exit();
  4197. this.expect(8);
  4198. this.finishNode(bodyNode, "BlockStatement");
  4199. let kind = null;
  4200. let hasModuleExport = false;
  4201. body.forEach(bodyElement => {
  4202. if (isEsModuleType(bodyElement)) {
  4203. if (kind === "CommonJS") {
  4204. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4205. }
  4206. kind = "ES";
  4207. } else if (bodyElement.type === "DeclareModuleExports") {
  4208. if (hasModuleExport) {
  4209. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  4210. }
  4211. if (kind === "ES") {
  4212. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4213. }
  4214. kind = "CommonJS";
  4215. hasModuleExport = true;
  4216. }
  4217. });
  4218. node.kind = kind || "CommonJS";
  4219. return this.finishNode(node, "DeclareModule");
  4220. }
  4221. flowParseDeclareExportDeclaration(node, insideModule) {
  4222. this.expect(82);
  4223. if (this.eat(65)) {
  4224. if (this.match(68) || this.match(80)) {
  4225. node.declaration = this.flowParseDeclare(this.startNode());
  4226. } else {
  4227. node.declaration = this.flowParseType();
  4228. this.semicolon();
  4229. }
  4230. node.default = true;
  4231. return this.finishNode(node, "DeclareExportDeclaration");
  4232. } else {
  4233. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4234. const label = this.state.value;
  4235. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  4236. unsupportedExportKind: label,
  4237. suggestion: exportSuggestions[label]
  4238. });
  4239. }
  4240. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4241. node.declaration = this.flowParseDeclare(this.startNode());
  4242. node.default = false;
  4243. return this.finishNode(node, "DeclareExportDeclaration");
  4244. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4245. node = this.parseExport(node, null);
  4246. if (node.type === "ExportNamedDeclaration") {
  4247. node.type = "ExportDeclaration";
  4248. node.default = false;
  4249. delete node.exportKind;
  4250. }
  4251. node.type = "Declare" + node.type;
  4252. return node;
  4253. }
  4254. }
  4255. this.unexpected();
  4256. }
  4257. flowParseDeclareModuleExports(node) {
  4258. this.next();
  4259. this.expectContextual(111);
  4260. node.typeAnnotation = this.flowParseTypeAnnotation();
  4261. this.semicolon();
  4262. return this.finishNode(node, "DeclareModuleExports");
  4263. }
  4264. flowParseDeclareTypeAlias(node) {
  4265. this.next();
  4266. const finished = this.flowParseTypeAlias(node);
  4267. finished.type = "DeclareTypeAlias";
  4268. return finished;
  4269. }
  4270. flowParseDeclareOpaqueType(node) {
  4271. this.next();
  4272. const finished = this.flowParseOpaqueType(node, true);
  4273. finished.type = "DeclareOpaqueType";
  4274. return finished;
  4275. }
  4276. flowParseDeclareInterface(node) {
  4277. this.next();
  4278. this.flowParseInterfaceish(node, false);
  4279. return this.finishNode(node, "DeclareInterface");
  4280. }
  4281. flowParseInterfaceish(node, isClass) {
  4282. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4283. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4284. if (this.match(47)) {
  4285. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4286. } else {
  4287. node.typeParameters = null;
  4288. }
  4289. node.extends = [];
  4290. if (this.eat(81)) {
  4291. do {
  4292. node.extends.push(this.flowParseInterfaceExtends());
  4293. } while (!isClass && this.eat(12));
  4294. }
  4295. if (isClass) {
  4296. node.implements = [];
  4297. node.mixins = [];
  4298. if (this.eatContextual(117)) {
  4299. do {
  4300. node.mixins.push(this.flowParseInterfaceExtends());
  4301. } while (this.eat(12));
  4302. }
  4303. if (this.eatContextual(113)) {
  4304. do {
  4305. node.implements.push(this.flowParseInterfaceExtends());
  4306. } while (this.eat(12));
  4307. }
  4308. }
  4309. node.body = this.flowParseObjectType({
  4310. allowStatic: isClass,
  4311. allowExact: false,
  4312. allowSpread: false,
  4313. allowProto: isClass,
  4314. allowInexact: false
  4315. });
  4316. }
  4317. flowParseInterfaceExtends() {
  4318. const node = this.startNode();
  4319. node.id = this.flowParseQualifiedTypeIdentifier();
  4320. if (this.match(47)) {
  4321. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4322. } else {
  4323. node.typeParameters = null;
  4324. }
  4325. return this.finishNode(node, "InterfaceExtends");
  4326. }
  4327. flowParseInterface(node) {
  4328. this.flowParseInterfaceish(node, false);
  4329. return this.finishNode(node, "InterfaceDeclaration");
  4330. }
  4331. checkNotUnderscore(word) {
  4332. if (word === "_") {
  4333. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  4334. }
  4335. }
  4336. checkReservedType(word, startLoc, declaration) {
  4337. if (!reservedTypes.has(word)) return;
  4338. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  4339. reservedType: word
  4340. });
  4341. }
  4342. flowParseRestrictedIdentifier(liberal, declaration) {
  4343. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4344. return this.parseIdentifier(liberal);
  4345. }
  4346. flowParseTypeAlias(node) {
  4347. node.id = this.flowParseRestrictedIdentifier(false, true);
  4348. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4349. if (this.match(47)) {
  4350. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4351. } else {
  4352. node.typeParameters = null;
  4353. }
  4354. node.right = this.flowParseTypeInitialiser(29);
  4355. this.semicolon();
  4356. return this.finishNode(node, "TypeAlias");
  4357. }
  4358. flowParseOpaqueType(node, declare) {
  4359. this.expectContextual(130);
  4360. node.id = this.flowParseRestrictedIdentifier(true, true);
  4361. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4362. if (this.match(47)) {
  4363. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4364. } else {
  4365. node.typeParameters = null;
  4366. }
  4367. node.supertype = null;
  4368. if (this.match(14)) {
  4369. node.supertype = this.flowParseTypeInitialiser(14);
  4370. }
  4371. node.impltype = null;
  4372. if (!declare) {
  4373. node.impltype = this.flowParseTypeInitialiser(29);
  4374. }
  4375. this.semicolon();
  4376. return this.finishNode(node, "OpaqueType");
  4377. }
  4378. flowParseTypeParameter(requireDefault = false) {
  4379. const nodeStartLoc = this.state.startLoc;
  4380. const node = this.startNode();
  4381. const variance = this.flowParseVariance();
  4382. const ident = this.flowParseTypeAnnotatableIdentifier();
  4383. node.name = ident.name;
  4384. node.variance = variance;
  4385. node.bound = ident.typeAnnotation;
  4386. if (this.match(29)) {
  4387. this.eat(29);
  4388. node.default = this.flowParseType();
  4389. } else {
  4390. if (requireDefault) {
  4391. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  4392. }
  4393. }
  4394. return this.finishNode(node, "TypeParameter");
  4395. }
  4396. flowParseTypeParameterDeclaration() {
  4397. const oldInType = this.state.inType;
  4398. const node = this.startNode();
  4399. node.params = [];
  4400. this.state.inType = true;
  4401. if (this.match(47) || this.match(143)) {
  4402. this.next();
  4403. } else {
  4404. this.unexpected();
  4405. }
  4406. let defaultRequired = false;
  4407. do {
  4408. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4409. node.params.push(typeParameter);
  4410. if (typeParameter.default) {
  4411. defaultRequired = true;
  4412. }
  4413. if (!this.match(48)) {
  4414. this.expect(12);
  4415. }
  4416. } while (!this.match(48));
  4417. this.expect(48);
  4418. this.state.inType = oldInType;
  4419. return this.finishNode(node, "TypeParameterDeclaration");
  4420. }
  4421. flowInTopLevelContext(cb) {
  4422. if (this.curContext() !== types.brace) {
  4423. const oldContext = this.state.context;
  4424. this.state.context = [oldContext[0]];
  4425. try {
  4426. return cb();
  4427. } finally {
  4428. this.state.context = oldContext;
  4429. }
  4430. } else {
  4431. return cb();
  4432. }
  4433. }
  4434. flowParseTypeParameterInstantiationInExpression() {
  4435. if (this.reScan_lt() !== 47) return;
  4436. return this.flowParseTypeParameterInstantiation();
  4437. }
  4438. flowParseTypeParameterInstantiation() {
  4439. const node = this.startNode();
  4440. const oldInType = this.state.inType;
  4441. this.state.inType = true;
  4442. node.params = [];
  4443. this.flowInTopLevelContext(() => {
  4444. this.expect(47);
  4445. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4446. this.state.noAnonFunctionType = false;
  4447. while (!this.match(48)) {
  4448. node.params.push(this.flowParseType());
  4449. if (!this.match(48)) {
  4450. this.expect(12);
  4451. }
  4452. }
  4453. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4454. });
  4455. this.state.inType = oldInType;
  4456. if (!this.state.inType && this.curContext() === types.brace) {
  4457. this.reScan_lt_gt();
  4458. }
  4459. this.expect(48);
  4460. return this.finishNode(node, "TypeParameterInstantiation");
  4461. }
  4462. flowParseTypeParameterInstantiationCallOrNew() {
  4463. if (this.reScan_lt() !== 47) return;
  4464. const node = this.startNode();
  4465. const oldInType = this.state.inType;
  4466. node.params = [];
  4467. this.state.inType = true;
  4468. this.expect(47);
  4469. while (!this.match(48)) {
  4470. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4471. if (!this.match(48)) {
  4472. this.expect(12);
  4473. }
  4474. }
  4475. this.expect(48);
  4476. this.state.inType = oldInType;
  4477. return this.finishNode(node, "TypeParameterInstantiation");
  4478. }
  4479. flowParseInterfaceType() {
  4480. const node = this.startNode();
  4481. this.expectContextual(129);
  4482. node.extends = [];
  4483. if (this.eat(81)) {
  4484. do {
  4485. node.extends.push(this.flowParseInterfaceExtends());
  4486. } while (this.eat(12));
  4487. }
  4488. node.body = this.flowParseObjectType({
  4489. allowStatic: false,
  4490. allowExact: false,
  4491. allowSpread: false,
  4492. allowProto: false,
  4493. allowInexact: false
  4494. });
  4495. return this.finishNode(node, "InterfaceTypeAnnotation");
  4496. }
  4497. flowParseObjectPropertyKey() {
  4498. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  4499. }
  4500. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4501. node.static = isStatic;
  4502. if (this.lookahead().type === 14) {
  4503. node.id = this.flowParseObjectPropertyKey();
  4504. node.key = this.flowParseTypeInitialiser();
  4505. } else {
  4506. node.id = null;
  4507. node.key = this.flowParseType();
  4508. }
  4509. this.expect(3);
  4510. node.value = this.flowParseTypeInitialiser();
  4511. node.variance = variance;
  4512. return this.finishNode(node, "ObjectTypeIndexer");
  4513. }
  4514. flowParseObjectTypeInternalSlot(node, isStatic) {
  4515. node.static = isStatic;
  4516. node.id = this.flowParseObjectPropertyKey();
  4517. this.expect(3);
  4518. this.expect(3);
  4519. if (this.match(47) || this.match(10)) {
  4520. node.method = true;
  4521. node.optional = false;
  4522. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4523. } else {
  4524. node.method = false;
  4525. if (this.eat(17)) {
  4526. node.optional = true;
  4527. }
  4528. node.value = this.flowParseTypeInitialiser();
  4529. }
  4530. return this.finishNode(node, "ObjectTypeInternalSlot");
  4531. }
  4532. flowParseObjectTypeMethodish(node) {
  4533. node.params = [];
  4534. node.rest = null;
  4535. node.typeParameters = null;
  4536. node.this = null;
  4537. if (this.match(47)) {
  4538. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4539. }
  4540. this.expect(10);
  4541. if (this.match(78)) {
  4542. node.this = this.flowParseFunctionTypeParam(true);
  4543. node.this.name = null;
  4544. if (!this.match(11)) {
  4545. this.expect(12);
  4546. }
  4547. }
  4548. while (!this.match(11) && !this.match(21)) {
  4549. node.params.push(this.flowParseFunctionTypeParam(false));
  4550. if (!this.match(11)) {
  4551. this.expect(12);
  4552. }
  4553. }
  4554. if (this.eat(21)) {
  4555. node.rest = this.flowParseFunctionTypeParam(false);
  4556. }
  4557. this.expect(11);
  4558. node.returnType = this.flowParseTypeInitialiser();
  4559. return this.finishNode(node, "FunctionTypeAnnotation");
  4560. }
  4561. flowParseObjectTypeCallProperty(node, isStatic) {
  4562. const valueNode = this.startNode();
  4563. node.static = isStatic;
  4564. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4565. return this.finishNode(node, "ObjectTypeCallProperty");
  4566. }
  4567. flowParseObjectType({
  4568. allowStatic,
  4569. allowExact,
  4570. allowSpread,
  4571. allowProto,
  4572. allowInexact
  4573. }) {
  4574. const oldInType = this.state.inType;
  4575. this.state.inType = true;
  4576. const nodeStart = this.startNode();
  4577. nodeStart.callProperties = [];
  4578. nodeStart.properties = [];
  4579. nodeStart.indexers = [];
  4580. nodeStart.internalSlots = [];
  4581. let endDelim;
  4582. let exact;
  4583. let inexact = false;
  4584. if (allowExact && this.match(6)) {
  4585. this.expect(6);
  4586. endDelim = 9;
  4587. exact = true;
  4588. } else {
  4589. this.expect(5);
  4590. endDelim = 8;
  4591. exact = false;
  4592. }
  4593. nodeStart.exact = exact;
  4594. while (!this.match(endDelim)) {
  4595. let isStatic = false;
  4596. let protoStartLoc = null;
  4597. let inexactStartLoc = null;
  4598. const node = this.startNode();
  4599. if (allowProto && this.isContextual(118)) {
  4600. const lookahead = this.lookahead();
  4601. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4602. this.next();
  4603. protoStartLoc = this.state.startLoc;
  4604. allowStatic = false;
  4605. }
  4606. }
  4607. if (allowStatic && this.isContextual(106)) {
  4608. const lookahead = this.lookahead();
  4609. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4610. this.next();
  4611. isStatic = true;
  4612. }
  4613. }
  4614. const variance = this.flowParseVariance();
  4615. if (this.eat(0)) {
  4616. if (protoStartLoc != null) {
  4617. this.unexpected(protoStartLoc);
  4618. }
  4619. if (this.eat(0)) {
  4620. if (variance) {
  4621. this.unexpected(variance.loc.start);
  4622. }
  4623. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4624. } else {
  4625. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4626. }
  4627. } else if (this.match(10) || this.match(47)) {
  4628. if (protoStartLoc != null) {
  4629. this.unexpected(protoStartLoc);
  4630. }
  4631. if (variance) {
  4632. this.unexpected(variance.loc.start);
  4633. }
  4634. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4635. } else {
  4636. let kind = "init";
  4637. if (this.isContextual(99) || this.isContextual(104)) {
  4638. const lookahead = this.lookahead();
  4639. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4640. kind = this.state.value;
  4641. this.next();
  4642. }
  4643. }
  4644. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4645. if (propOrInexact === null) {
  4646. inexact = true;
  4647. inexactStartLoc = this.state.lastTokStartLoc;
  4648. } else {
  4649. nodeStart.properties.push(propOrInexact);
  4650. }
  4651. }
  4652. this.flowObjectTypeSemicolon();
  4653. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4654. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  4655. }
  4656. }
  4657. this.expect(endDelim);
  4658. if (allowSpread) {
  4659. nodeStart.inexact = inexact;
  4660. }
  4661. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4662. this.state.inType = oldInType;
  4663. return out;
  4664. }
  4665. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4666. if (this.eat(21)) {
  4667. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4668. if (isInexactToken) {
  4669. if (!allowSpread) {
  4670. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  4671. } else if (!allowInexact) {
  4672. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  4673. }
  4674. if (variance) {
  4675. this.raise(FlowErrors.InexactVariance, variance);
  4676. }
  4677. return null;
  4678. }
  4679. if (!allowSpread) {
  4680. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  4681. }
  4682. if (protoStartLoc != null) {
  4683. this.unexpected(protoStartLoc);
  4684. }
  4685. if (variance) {
  4686. this.raise(FlowErrors.SpreadVariance, variance);
  4687. }
  4688. node.argument = this.flowParseType();
  4689. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4690. } else {
  4691. node.key = this.flowParseObjectPropertyKey();
  4692. node.static = isStatic;
  4693. node.proto = protoStartLoc != null;
  4694. node.kind = kind;
  4695. let optional = false;
  4696. if (this.match(47) || this.match(10)) {
  4697. node.method = true;
  4698. if (protoStartLoc != null) {
  4699. this.unexpected(protoStartLoc);
  4700. }
  4701. if (variance) {
  4702. this.unexpected(variance.loc.start);
  4703. }
  4704. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4705. if (kind === "get" || kind === "set") {
  4706. this.flowCheckGetterSetterParams(node);
  4707. }
  4708. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4709. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  4710. }
  4711. } else {
  4712. if (kind !== "init") this.unexpected();
  4713. node.method = false;
  4714. if (this.eat(17)) {
  4715. optional = true;
  4716. }
  4717. node.value = this.flowParseTypeInitialiser();
  4718. node.variance = variance;
  4719. }
  4720. node.optional = optional;
  4721. return this.finishNode(node, "ObjectTypeProperty");
  4722. }
  4723. }
  4724. flowCheckGetterSetterParams(property) {
  4725. const paramCount = property.kind === "get" ? 0 : 1;
  4726. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4727. if (property.value.this) {
  4728. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  4729. }
  4730. if (length !== paramCount) {
  4731. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  4732. }
  4733. if (property.kind === "set" && property.value.rest) {
  4734. this.raise(Errors.BadSetterRestParameter, property);
  4735. }
  4736. }
  4737. flowObjectTypeSemicolon() {
  4738. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4739. this.unexpected();
  4740. }
  4741. }
  4742. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4743. var _startLoc;
  4744. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4745. let node = id || this.flowParseRestrictedIdentifier(true);
  4746. while (this.eat(16)) {
  4747. const node2 = this.startNodeAt(startLoc);
  4748. node2.qualification = node;
  4749. node2.id = this.flowParseRestrictedIdentifier(true);
  4750. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4751. }
  4752. return node;
  4753. }
  4754. flowParseGenericType(startLoc, id) {
  4755. const node = this.startNodeAt(startLoc);
  4756. node.typeParameters = null;
  4757. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4758. if (this.match(47)) {
  4759. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4760. }
  4761. return this.finishNode(node, "GenericTypeAnnotation");
  4762. }
  4763. flowParseTypeofType() {
  4764. const node = this.startNode();
  4765. this.expect(87);
  4766. node.argument = this.flowParsePrimaryType();
  4767. return this.finishNode(node, "TypeofTypeAnnotation");
  4768. }
  4769. flowParseTupleType() {
  4770. const node = this.startNode();
  4771. node.types = [];
  4772. this.expect(0);
  4773. while (this.state.pos < this.length && !this.match(3)) {
  4774. node.types.push(this.flowParseType());
  4775. if (this.match(3)) break;
  4776. this.expect(12);
  4777. }
  4778. this.expect(3);
  4779. return this.finishNode(node, "TupleTypeAnnotation");
  4780. }
  4781. flowParseFunctionTypeParam(first) {
  4782. let name = null;
  4783. let optional = false;
  4784. let typeAnnotation = null;
  4785. const node = this.startNode();
  4786. const lh = this.lookahead();
  4787. const isThis = this.state.type === 78;
  4788. if (lh.type === 14 || lh.type === 17) {
  4789. if (isThis && !first) {
  4790. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  4791. }
  4792. name = this.parseIdentifier(isThis);
  4793. if (this.eat(17)) {
  4794. optional = true;
  4795. if (isThis) {
  4796. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  4797. }
  4798. }
  4799. typeAnnotation = this.flowParseTypeInitialiser();
  4800. } else {
  4801. typeAnnotation = this.flowParseType();
  4802. }
  4803. node.name = name;
  4804. node.optional = optional;
  4805. node.typeAnnotation = typeAnnotation;
  4806. return this.finishNode(node, "FunctionTypeParam");
  4807. }
  4808. reinterpretTypeAsFunctionTypeParam(type) {
  4809. const node = this.startNodeAt(type.loc.start);
  4810. node.name = null;
  4811. node.optional = false;
  4812. node.typeAnnotation = type;
  4813. return this.finishNode(node, "FunctionTypeParam");
  4814. }
  4815. flowParseFunctionTypeParams(params = []) {
  4816. let rest = null;
  4817. let _this = null;
  4818. if (this.match(78)) {
  4819. _this = this.flowParseFunctionTypeParam(true);
  4820. _this.name = null;
  4821. if (!this.match(11)) {
  4822. this.expect(12);
  4823. }
  4824. }
  4825. while (!this.match(11) && !this.match(21)) {
  4826. params.push(this.flowParseFunctionTypeParam(false));
  4827. if (!this.match(11)) {
  4828. this.expect(12);
  4829. }
  4830. }
  4831. if (this.eat(21)) {
  4832. rest = this.flowParseFunctionTypeParam(false);
  4833. }
  4834. return {
  4835. params,
  4836. rest,
  4837. _this
  4838. };
  4839. }
  4840. flowIdentToTypeAnnotation(startLoc, node, id) {
  4841. switch (id.name) {
  4842. case "any":
  4843. return this.finishNode(node, "AnyTypeAnnotation");
  4844. case "bool":
  4845. case "boolean":
  4846. return this.finishNode(node, "BooleanTypeAnnotation");
  4847. case "mixed":
  4848. return this.finishNode(node, "MixedTypeAnnotation");
  4849. case "empty":
  4850. return this.finishNode(node, "EmptyTypeAnnotation");
  4851. case "number":
  4852. return this.finishNode(node, "NumberTypeAnnotation");
  4853. case "string":
  4854. return this.finishNode(node, "StringTypeAnnotation");
  4855. case "symbol":
  4856. return this.finishNode(node, "SymbolTypeAnnotation");
  4857. default:
  4858. this.checkNotUnderscore(id.name);
  4859. return this.flowParseGenericType(startLoc, id);
  4860. }
  4861. }
  4862. flowParsePrimaryType() {
  4863. const startLoc = this.state.startLoc;
  4864. const node = this.startNode();
  4865. let tmp;
  4866. let type;
  4867. let isGroupedType = false;
  4868. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4869. switch (this.state.type) {
  4870. case 5:
  4871. return this.flowParseObjectType({
  4872. allowStatic: false,
  4873. allowExact: false,
  4874. allowSpread: true,
  4875. allowProto: false,
  4876. allowInexact: true
  4877. });
  4878. case 6:
  4879. return this.flowParseObjectType({
  4880. allowStatic: false,
  4881. allowExact: true,
  4882. allowSpread: true,
  4883. allowProto: false,
  4884. allowInexact: false
  4885. });
  4886. case 0:
  4887. this.state.noAnonFunctionType = false;
  4888. type = this.flowParseTupleType();
  4889. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4890. return type;
  4891. case 47:
  4892. {
  4893. const node = this.startNode();
  4894. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4895. this.expect(10);
  4896. tmp = this.flowParseFunctionTypeParams();
  4897. node.params = tmp.params;
  4898. node.rest = tmp.rest;
  4899. node.this = tmp._this;
  4900. this.expect(11);
  4901. this.expect(19);
  4902. node.returnType = this.flowParseType();
  4903. return this.finishNode(node, "FunctionTypeAnnotation");
  4904. }
  4905. case 10:
  4906. {
  4907. const node = this.startNode();
  4908. this.next();
  4909. if (!this.match(11) && !this.match(21)) {
  4910. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4911. const token = this.lookahead().type;
  4912. isGroupedType = token !== 17 && token !== 14;
  4913. } else {
  4914. isGroupedType = true;
  4915. }
  4916. }
  4917. if (isGroupedType) {
  4918. this.state.noAnonFunctionType = false;
  4919. type = this.flowParseType();
  4920. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4921. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4922. this.expect(11);
  4923. return type;
  4924. } else {
  4925. this.eat(12);
  4926. }
  4927. }
  4928. if (type) {
  4929. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4930. } else {
  4931. tmp = this.flowParseFunctionTypeParams();
  4932. }
  4933. node.params = tmp.params;
  4934. node.rest = tmp.rest;
  4935. node.this = tmp._this;
  4936. this.expect(11);
  4937. this.expect(19);
  4938. node.returnType = this.flowParseType();
  4939. node.typeParameters = null;
  4940. return this.finishNode(node, "FunctionTypeAnnotation");
  4941. }
  4942. case 134:
  4943. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4944. case 85:
  4945. case 86:
  4946. node.value = this.match(85);
  4947. this.next();
  4948. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4949. case 53:
  4950. if (this.state.value === "-") {
  4951. this.next();
  4952. if (this.match(135)) {
  4953. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4954. }
  4955. if (this.match(136)) {
  4956. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4957. }
  4958. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  4959. }
  4960. this.unexpected();
  4961. return;
  4962. case 135:
  4963. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4964. case 136:
  4965. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4966. case 88:
  4967. this.next();
  4968. return this.finishNode(node, "VoidTypeAnnotation");
  4969. case 84:
  4970. this.next();
  4971. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4972. case 78:
  4973. this.next();
  4974. return this.finishNode(node, "ThisTypeAnnotation");
  4975. case 55:
  4976. this.next();
  4977. return this.finishNode(node, "ExistsTypeAnnotation");
  4978. case 87:
  4979. return this.flowParseTypeofType();
  4980. default:
  4981. if (tokenIsKeyword(this.state.type)) {
  4982. const label = tokenLabelName(this.state.type);
  4983. this.next();
  4984. return super.createIdentifier(node, label);
  4985. } else if (tokenIsIdentifier(this.state.type)) {
  4986. if (this.isContextual(129)) {
  4987. return this.flowParseInterfaceType();
  4988. }
  4989. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4990. }
  4991. }
  4992. this.unexpected();
  4993. }
  4994. flowParsePostfixType() {
  4995. const startLoc = this.state.startLoc;
  4996. let type = this.flowParsePrimaryType();
  4997. let seenOptionalIndexedAccess = false;
  4998. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4999. const node = this.startNodeAt(startLoc);
  5000. const optional = this.eat(18);
  5001. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5002. this.expect(0);
  5003. if (!optional && this.match(3)) {
  5004. node.elementType = type;
  5005. this.next();
  5006. type = this.finishNode(node, "ArrayTypeAnnotation");
  5007. } else {
  5008. node.objectType = type;
  5009. node.indexType = this.flowParseType();
  5010. this.expect(3);
  5011. if (seenOptionalIndexedAccess) {
  5012. node.optional = optional;
  5013. type = this.finishNode(node, "OptionalIndexedAccessType");
  5014. } else {
  5015. type = this.finishNode(node, "IndexedAccessType");
  5016. }
  5017. }
  5018. }
  5019. return type;
  5020. }
  5021. flowParsePrefixType() {
  5022. const node = this.startNode();
  5023. if (this.eat(17)) {
  5024. node.typeAnnotation = this.flowParsePrefixType();
  5025. return this.finishNode(node, "NullableTypeAnnotation");
  5026. } else {
  5027. return this.flowParsePostfixType();
  5028. }
  5029. }
  5030. flowParseAnonFunctionWithoutParens() {
  5031. const param = this.flowParsePrefixType();
  5032. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5033. const node = this.startNodeAt(param.loc.start);
  5034. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5035. node.rest = null;
  5036. node.this = null;
  5037. node.returnType = this.flowParseType();
  5038. node.typeParameters = null;
  5039. return this.finishNode(node, "FunctionTypeAnnotation");
  5040. }
  5041. return param;
  5042. }
  5043. flowParseIntersectionType() {
  5044. const node = this.startNode();
  5045. this.eat(45);
  5046. const type = this.flowParseAnonFunctionWithoutParens();
  5047. node.types = [type];
  5048. while (this.eat(45)) {
  5049. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5050. }
  5051. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5052. }
  5053. flowParseUnionType() {
  5054. const node = this.startNode();
  5055. this.eat(43);
  5056. const type = this.flowParseIntersectionType();
  5057. node.types = [type];
  5058. while (this.eat(43)) {
  5059. node.types.push(this.flowParseIntersectionType());
  5060. }
  5061. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5062. }
  5063. flowParseType() {
  5064. const oldInType = this.state.inType;
  5065. this.state.inType = true;
  5066. const type = this.flowParseUnionType();
  5067. this.state.inType = oldInType;
  5068. return type;
  5069. }
  5070. flowParseTypeOrImplicitInstantiation() {
  5071. if (this.state.type === 132 && this.state.value === "_") {
  5072. const startLoc = this.state.startLoc;
  5073. const node = this.parseIdentifier();
  5074. return this.flowParseGenericType(startLoc, node);
  5075. } else {
  5076. return this.flowParseType();
  5077. }
  5078. }
  5079. flowParseTypeAnnotation() {
  5080. const node = this.startNode();
  5081. node.typeAnnotation = this.flowParseTypeInitialiser();
  5082. return this.finishNode(node, "TypeAnnotation");
  5083. }
  5084. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5085. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5086. if (this.match(14)) {
  5087. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5088. this.resetEndLocation(ident);
  5089. }
  5090. return ident;
  5091. }
  5092. typeCastToParameter(node) {
  5093. node.expression.typeAnnotation = node.typeAnnotation;
  5094. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5095. return node.expression;
  5096. }
  5097. flowParseVariance() {
  5098. let variance = null;
  5099. if (this.match(53)) {
  5100. variance = this.startNode();
  5101. if (this.state.value === "+") {
  5102. variance.kind = "plus";
  5103. } else {
  5104. variance.kind = "minus";
  5105. }
  5106. this.next();
  5107. return this.finishNode(variance, "Variance");
  5108. }
  5109. return variance;
  5110. }
  5111. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5112. if (allowExpressionBody) {
  5113. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5114. return;
  5115. }
  5116. super.parseFunctionBody(node, false, isMethod);
  5117. }
  5118. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5119. if (this.match(14)) {
  5120. const typeNode = this.startNode();
  5121. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5122. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5123. }
  5124. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5125. }
  5126. parseStatementLike(flags) {
  5127. if (this.state.strict && this.isContextual(129)) {
  5128. const lookahead = this.lookahead();
  5129. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5130. const node = this.startNode();
  5131. this.next();
  5132. return this.flowParseInterface(node);
  5133. }
  5134. } else if (this.isContextual(126)) {
  5135. const node = this.startNode();
  5136. this.next();
  5137. return this.flowParseEnumDeclaration(node);
  5138. }
  5139. const stmt = super.parseStatementLike(flags);
  5140. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5141. this.flowPragma = null;
  5142. }
  5143. return stmt;
  5144. }
  5145. parseExpressionStatement(node, expr, decorators) {
  5146. if (expr.type === "Identifier") {
  5147. if (expr.name === "declare") {
  5148. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5149. return this.flowParseDeclare(node);
  5150. }
  5151. } else if (tokenIsIdentifier(this.state.type)) {
  5152. if (expr.name === "interface") {
  5153. return this.flowParseInterface(node);
  5154. } else if (expr.name === "type") {
  5155. return this.flowParseTypeAlias(node);
  5156. } else if (expr.name === "opaque") {
  5157. return this.flowParseOpaqueType(node, false);
  5158. }
  5159. }
  5160. }
  5161. return super.parseExpressionStatement(node, expr, decorators);
  5162. }
  5163. shouldParseExportDeclaration() {
  5164. const {
  5165. type
  5166. } = this.state;
  5167. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5168. return !this.state.containsEsc;
  5169. }
  5170. return super.shouldParseExportDeclaration();
  5171. }
  5172. isExportDefaultSpecifier() {
  5173. const {
  5174. type
  5175. } = this.state;
  5176. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5177. return this.state.containsEsc;
  5178. }
  5179. return super.isExportDefaultSpecifier();
  5180. }
  5181. parseExportDefaultExpression() {
  5182. if (this.isContextual(126)) {
  5183. const node = this.startNode();
  5184. this.next();
  5185. return this.flowParseEnumDeclaration(node);
  5186. }
  5187. return super.parseExportDefaultExpression();
  5188. }
  5189. parseConditional(expr, startLoc, refExpressionErrors) {
  5190. if (!this.match(17)) return expr;
  5191. if (this.state.maybeInArrowParameters) {
  5192. const nextCh = this.lookaheadCharCode();
  5193. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5194. this.setOptionalParametersError(refExpressionErrors);
  5195. return expr;
  5196. }
  5197. }
  5198. this.expect(17);
  5199. const state = this.state.clone();
  5200. const originalNoArrowAt = this.state.noArrowAt;
  5201. const node = this.startNodeAt(startLoc);
  5202. let {
  5203. consequent,
  5204. failed
  5205. } = this.tryParseConditionalConsequent();
  5206. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5207. if (failed || invalid.length > 0) {
  5208. const noArrowAt = [...originalNoArrowAt];
  5209. if (invalid.length > 0) {
  5210. this.state = state;
  5211. this.state.noArrowAt = noArrowAt;
  5212. for (let i = 0; i < invalid.length; i++) {
  5213. noArrowAt.push(invalid[i].start);
  5214. }
  5215. ({
  5216. consequent,
  5217. failed
  5218. } = this.tryParseConditionalConsequent());
  5219. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5220. }
  5221. if (failed && valid.length > 1) {
  5222. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  5223. }
  5224. if (failed && valid.length === 1) {
  5225. this.state = state;
  5226. noArrowAt.push(valid[0].start);
  5227. this.state.noArrowAt = noArrowAt;
  5228. ({
  5229. consequent,
  5230. failed
  5231. } = this.tryParseConditionalConsequent());
  5232. }
  5233. }
  5234. this.getArrowLikeExpressions(consequent, true);
  5235. this.state.noArrowAt = originalNoArrowAt;
  5236. this.expect(14);
  5237. node.test = expr;
  5238. node.consequent = consequent;
  5239. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5240. return this.finishNode(node, "ConditionalExpression");
  5241. }
  5242. tryParseConditionalConsequent() {
  5243. this.state.noArrowParamsConversionAt.push(this.state.start);
  5244. const consequent = this.parseMaybeAssignAllowIn();
  5245. const failed = !this.match(14);
  5246. this.state.noArrowParamsConversionAt.pop();
  5247. return {
  5248. consequent,
  5249. failed
  5250. };
  5251. }
  5252. getArrowLikeExpressions(node, disallowInvalid) {
  5253. const stack = [node];
  5254. const arrows = [];
  5255. while (stack.length !== 0) {
  5256. const node = stack.pop();
  5257. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  5258. if (node.typeParameters || !node.returnType) {
  5259. this.finishArrowValidation(node);
  5260. } else {
  5261. arrows.push(node);
  5262. }
  5263. stack.push(node.body);
  5264. } else if (node.type === "ConditionalExpression") {
  5265. stack.push(node.consequent);
  5266. stack.push(node.alternate);
  5267. }
  5268. }
  5269. if (disallowInvalid) {
  5270. arrows.forEach(node => this.finishArrowValidation(node));
  5271. return [arrows, []];
  5272. }
  5273. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5274. }
  5275. finishArrowValidation(node) {
  5276. var _node$extra;
  5277. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5278. this.scope.enter(2 | 4);
  5279. super.checkParams(node, false, true);
  5280. this.scope.exit();
  5281. }
  5282. forwardNoArrowParamsConversionAt(node, parse) {
  5283. let result;
  5284. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5285. this.state.noArrowParamsConversionAt.push(this.state.start);
  5286. result = parse();
  5287. this.state.noArrowParamsConversionAt.pop();
  5288. } else {
  5289. result = parse();
  5290. }
  5291. return result;
  5292. }
  5293. parseParenItem(node, startLoc) {
  5294. const newNode = super.parseParenItem(node, startLoc);
  5295. if (this.eat(17)) {
  5296. newNode.optional = true;
  5297. this.resetEndLocation(node);
  5298. }
  5299. if (this.match(14)) {
  5300. const typeCastNode = this.startNodeAt(startLoc);
  5301. typeCastNode.expression = newNode;
  5302. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5303. return this.finishNode(typeCastNode, "TypeCastExpression");
  5304. }
  5305. return newNode;
  5306. }
  5307. assertModuleNodeAllowed(node) {
  5308. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5309. return;
  5310. }
  5311. super.assertModuleNodeAllowed(node);
  5312. }
  5313. parseExportDeclaration(node) {
  5314. if (this.isContextual(130)) {
  5315. node.exportKind = "type";
  5316. const declarationNode = this.startNode();
  5317. this.next();
  5318. if (this.match(5)) {
  5319. node.specifiers = this.parseExportSpecifiers(true);
  5320. super.parseExportFrom(node);
  5321. return null;
  5322. } else {
  5323. return this.flowParseTypeAlias(declarationNode);
  5324. }
  5325. } else if (this.isContextual(131)) {
  5326. node.exportKind = "type";
  5327. const declarationNode = this.startNode();
  5328. this.next();
  5329. return this.flowParseOpaqueType(declarationNode, false);
  5330. } else if (this.isContextual(129)) {
  5331. node.exportKind = "type";
  5332. const declarationNode = this.startNode();
  5333. this.next();
  5334. return this.flowParseInterface(declarationNode);
  5335. } else if (this.isContextual(126)) {
  5336. node.exportKind = "value";
  5337. const declarationNode = this.startNode();
  5338. this.next();
  5339. return this.flowParseEnumDeclaration(declarationNode);
  5340. } else {
  5341. return super.parseExportDeclaration(node);
  5342. }
  5343. }
  5344. eatExportStar(node) {
  5345. if (super.eatExportStar(node)) return true;
  5346. if (this.isContextual(130) && this.lookahead().type === 55) {
  5347. node.exportKind = "type";
  5348. this.next();
  5349. this.next();
  5350. return true;
  5351. }
  5352. return false;
  5353. }
  5354. maybeParseExportNamespaceSpecifier(node) {
  5355. const {
  5356. startLoc
  5357. } = this.state;
  5358. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5359. if (hasNamespace && node.exportKind === "type") {
  5360. this.unexpected(startLoc);
  5361. }
  5362. return hasNamespace;
  5363. }
  5364. parseClassId(node, isStatement, optionalId) {
  5365. super.parseClassId(node, isStatement, optionalId);
  5366. if (this.match(47)) {
  5367. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5368. }
  5369. }
  5370. parseClassMember(classBody, member, state) {
  5371. const {
  5372. startLoc
  5373. } = this.state;
  5374. if (this.isContextual(125)) {
  5375. if (super.parseClassMemberFromModifier(classBody, member)) {
  5376. return;
  5377. }
  5378. member.declare = true;
  5379. }
  5380. super.parseClassMember(classBody, member, state);
  5381. if (member.declare) {
  5382. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5383. this.raise(FlowErrors.DeclareClassElement, startLoc);
  5384. } else if (member.value) {
  5385. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  5386. }
  5387. }
  5388. }
  5389. isIterator(word) {
  5390. return word === "iterator" || word === "asyncIterator";
  5391. }
  5392. readIterator() {
  5393. const word = super.readWord1();
  5394. const fullWord = "@@" + word;
  5395. if (!this.isIterator(word) || !this.state.inType) {
  5396. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  5397. identifierName: fullWord
  5398. });
  5399. }
  5400. this.finishToken(132, fullWord);
  5401. }
  5402. getTokenFromCode(code) {
  5403. const next = this.input.charCodeAt(this.state.pos + 1);
  5404. if (code === 123 && next === 124) {
  5405. this.finishOp(6, 2);
  5406. } else if (this.state.inType && (code === 62 || code === 60)) {
  5407. this.finishOp(code === 62 ? 48 : 47, 1);
  5408. } else if (this.state.inType && code === 63) {
  5409. if (next === 46) {
  5410. this.finishOp(18, 2);
  5411. } else {
  5412. this.finishOp(17, 1);
  5413. }
  5414. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5415. this.state.pos += 2;
  5416. this.readIterator();
  5417. } else {
  5418. super.getTokenFromCode(code);
  5419. }
  5420. }
  5421. isAssignable(node, isBinding) {
  5422. if (node.type === "TypeCastExpression") {
  5423. return this.isAssignable(node.expression, isBinding);
  5424. } else {
  5425. return super.isAssignable(node, isBinding);
  5426. }
  5427. }
  5428. toAssignable(node, isLHS = false) {
  5429. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5430. node.left = this.typeCastToParameter(node.left);
  5431. }
  5432. super.toAssignable(node, isLHS);
  5433. }
  5434. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5435. for (let i = 0; i < exprList.length; i++) {
  5436. const expr = exprList[i];
  5437. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5438. exprList[i] = this.typeCastToParameter(expr);
  5439. }
  5440. }
  5441. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5442. }
  5443. toReferencedList(exprList, isParenthesizedExpr) {
  5444. for (let i = 0; i < exprList.length; i++) {
  5445. var _expr$extra;
  5446. const expr = exprList[i];
  5447. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5448. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  5449. }
  5450. }
  5451. return exprList;
  5452. }
  5453. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5454. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5455. if (canBePattern && !this.state.maybeInArrowParameters) {
  5456. this.toReferencedList(node.elements);
  5457. }
  5458. return node;
  5459. }
  5460. isValidLVal(type, isParenthesized, binding) {
  5461. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5462. }
  5463. parseClassProperty(node) {
  5464. if (this.match(14)) {
  5465. node.typeAnnotation = this.flowParseTypeAnnotation();
  5466. }
  5467. return super.parseClassProperty(node);
  5468. }
  5469. parseClassPrivateProperty(node) {
  5470. if (this.match(14)) {
  5471. node.typeAnnotation = this.flowParseTypeAnnotation();
  5472. }
  5473. return super.parseClassPrivateProperty(node);
  5474. }
  5475. isClassMethod() {
  5476. return this.match(47) || super.isClassMethod();
  5477. }
  5478. isClassProperty() {
  5479. return this.match(14) || super.isClassProperty();
  5480. }
  5481. isNonstaticConstructor(method) {
  5482. return !this.match(14) && super.isNonstaticConstructor(method);
  5483. }
  5484. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5485. if (method.variance) {
  5486. this.unexpected(method.variance.loc.start);
  5487. }
  5488. delete method.variance;
  5489. if (this.match(47)) {
  5490. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5491. }
  5492. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5493. if (method.params && isConstructor) {
  5494. const params = method.params;
  5495. if (params.length > 0 && this.isThisParam(params[0])) {
  5496. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5497. }
  5498. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5499. const params = method.value.params;
  5500. if (params.length > 0 && this.isThisParam(params[0])) {
  5501. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5502. }
  5503. }
  5504. }
  5505. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5506. if (method.variance) {
  5507. this.unexpected(method.variance.loc.start);
  5508. }
  5509. delete method.variance;
  5510. if (this.match(47)) {
  5511. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5512. }
  5513. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5514. }
  5515. parseClassSuper(node) {
  5516. super.parseClassSuper(node);
  5517. if (node.superClass && (this.match(47) || this.match(51))) {
  5518. {
  5519. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  5520. }
  5521. }
  5522. if (this.isContextual(113)) {
  5523. this.next();
  5524. const implemented = node.implements = [];
  5525. do {
  5526. const node = this.startNode();
  5527. node.id = this.flowParseRestrictedIdentifier(true);
  5528. if (this.match(47)) {
  5529. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5530. } else {
  5531. node.typeParameters = null;
  5532. }
  5533. implemented.push(this.finishNode(node, "ClassImplements"));
  5534. } while (this.eat(12));
  5535. }
  5536. }
  5537. checkGetterSetterParams(method) {
  5538. super.checkGetterSetterParams(method);
  5539. const params = this.getObjectOrClassMethodParams(method);
  5540. if (params.length > 0) {
  5541. const param = params[0];
  5542. if (this.isThisParam(param) && method.kind === "get") {
  5543. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  5544. } else if (this.isThisParam(param)) {
  5545. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  5546. }
  5547. }
  5548. }
  5549. parsePropertyNamePrefixOperator(node) {
  5550. node.variance = this.flowParseVariance();
  5551. }
  5552. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5553. if (prop.variance) {
  5554. this.unexpected(prop.variance.loc.start);
  5555. }
  5556. delete prop.variance;
  5557. let typeParameters;
  5558. if (this.match(47) && !isAccessor) {
  5559. typeParameters = this.flowParseTypeParameterDeclaration();
  5560. if (!this.match(10)) this.unexpected();
  5561. }
  5562. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5563. if (typeParameters) {
  5564. (result.value || result).typeParameters = typeParameters;
  5565. }
  5566. return result;
  5567. }
  5568. parseFunctionParamType(param) {
  5569. if (this.eat(17)) {
  5570. if (param.type !== "Identifier") {
  5571. this.raise(FlowErrors.PatternIsOptional, param);
  5572. }
  5573. if (this.isThisParam(param)) {
  5574. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  5575. }
  5576. param.optional = true;
  5577. }
  5578. if (this.match(14)) {
  5579. param.typeAnnotation = this.flowParseTypeAnnotation();
  5580. } else if (this.isThisParam(param)) {
  5581. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  5582. }
  5583. if (this.match(29) && this.isThisParam(param)) {
  5584. this.raise(FlowErrors.ThisParamNoDefault, param);
  5585. }
  5586. this.resetEndLocation(param);
  5587. return param;
  5588. }
  5589. parseMaybeDefault(startLoc, left) {
  5590. const node = super.parseMaybeDefault(startLoc, left);
  5591. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5592. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  5593. }
  5594. return node;
  5595. }
  5596. checkImportReflection(node) {
  5597. super.checkImportReflection(node);
  5598. if (node.module && node.importKind !== "value") {
  5599. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  5600. }
  5601. }
  5602. parseImportSpecifierLocal(node, specifier, type) {
  5603. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5604. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5605. }
  5606. isPotentialImportPhase(isExport) {
  5607. if (super.isPotentialImportPhase(isExport)) return true;
  5608. if (this.isContextual(130)) {
  5609. if (!isExport) return true;
  5610. const ch = this.lookaheadCharCode();
  5611. return ch === 123 || ch === 42;
  5612. }
  5613. return !isExport && this.isContextual(87);
  5614. }
  5615. applyImportPhase(node, isExport, phase, loc) {
  5616. super.applyImportPhase(node, isExport, phase, loc);
  5617. if (isExport) {
  5618. if (!phase && this.match(65)) {
  5619. return;
  5620. }
  5621. node.exportKind = phase === "type" ? phase : "value";
  5622. } else {
  5623. if (phase === "type" && this.match(55)) this.unexpected();
  5624. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5625. }
  5626. }
  5627. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5628. const firstIdent = specifier.imported;
  5629. let specifierTypeKind = null;
  5630. if (firstIdent.type === "Identifier") {
  5631. if (firstIdent.name === "type") {
  5632. specifierTypeKind = "type";
  5633. } else if (firstIdent.name === "typeof") {
  5634. specifierTypeKind = "typeof";
  5635. }
  5636. }
  5637. let isBinding = false;
  5638. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5639. const as_ident = this.parseIdentifier(true);
  5640. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5641. specifier.imported = as_ident;
  5642. specifier.importKind = specifierTypeKind;
  5643. specifier.local = cloneIdentifier(as_ident);
  5644. } else {
  5645. specifier.imported = firstIdent;
  5646. specifier.importKind = null;
  5647. specifier.local = this.parseIdentifier();
  5648. }
  5649. } else {
  5650. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5651. specifier.imported = this.parseIdentifier(true);
  5652. specifier.importKind = specifierTypeKind;
  5653. } else {
  5654. if (importedIsString) {
  5655. throw this.raise(Errors.ImportBindingIsString, specifier, {
  5656. importName: firstIdent.value
  5657. });
  5658. }
  5659. specifier.imported = firstIdent;
  5660. specifier.importKind = null;
  5661. }
  5662. if (this.eatContextual(93)) {
  5663. specifier.local = this.parseIdentifier();
  5664. } else {
  5665. isBinding = true;
  5666. specifier.local = cloneIdentifier(specifier.imported);
  5667. }
  5668. }
  5669. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5670. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5671. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  5672. }
  5673. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5674. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5675. }
  5676. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5677. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5678. }
  5679. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5680. }
  5681. parseBindingAtom() {
  5682. switch (this.state.type) {
  5683. case 78:
  5684. return this.parseIdentifier(true);
  5685. default:
  5686. return super.parseBindingAtom();
  5687. }
  5688. }
  5689. parseFunctionParams(node, isConstructor) {
  5690. const kind = node.kind;
  5691. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5692. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5693. }
  5694. super.parseFunctionParams(node, isConstructor);
  5695. }
  5696. parseVarId(decl, kind) {
  5697. super.parseVarId(decl, kind);
  5698. if (this.match(14)) {
  5699. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5700. this.resetEndLocation(decl.id);
  5701. }
  5702. }
  5703. parseAsyncArrowFromCallExpression(node, call) {
  5704. if (this.match(14)) {
  5705. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5706. this.state.noAnonFunctionType = true;
  5707. node.returnType = this.flowParseTypeAnnotation();
  5708. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5709. }
  5710. return super.parseAsyncArrowFromCallExpression(node, call);
  5711. }
  5712. shouldParseAsyncArrow() {
  5713. return this.match(14) || super.shouldParseAsyncArrow();
  5714. }
  5715. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5716. var _jsx;
  5717. let state = null;
  5718. let jsx;
  5719. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  5720. state = this.state.clone();
  5721. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5722. if (!jsx.error) return jsx.node;
  5723. const {
  5724. context
  5725. } = this.state;
  5726. const currentContext = context[context.length - 1];
  5727. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5728. context.pop();
  5729. }
  5730. }
  5731. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5732. var _jsx2, _jsx3;
  5733. state = state || this.state.clone();
  5734. let typeParameters;
  5735. const arrow = this.tryParse(abort => {
  5736. var _arrowExpression$extr;
  5737. typeParameters = this.flowParseTypeParameterDeclaration();
  5738. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5739. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5740. this.resetStartLocationFromNode(result, typeParameters);
  5741. return result;
  5742. });
  5743. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5744. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5745. if (expr.type !== "ArrowFunctionExpression") abort();
  5746. expr.typeParameters = typeParameters;
  5747. this.resetStartLocationFromNode(expr, typeParameters);
  5748. return arrowExpression;
  5749. }, state);
  5750. let arrowExpression = null;
  5751. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5752. if (!arrow.error && !arrow.aborted) {
  5753. if (arrow.node.async) {
  5754. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  5755. }
  5756. return arrow.node;
  5757. }
  5758. arrowExpression = arrow.node;
  5759. }
  5760. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5761. this.state = jsx.failState;
  5762. return jsx.node;
  5763. }
  5764. if (arrowExpression) {
  5765. this.state = arrow.failState;
  5766. return arrowExpression;
  5767. }
  5768. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5769. if (arrow.thrown) throw arrow.error;
  5770. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  5771. }
  5772. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5773. }
  5774. parseArrow(node) {
  5775. if (this.match(14)) {
  5776. const result = this.tryParse(() => {
  5777. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5778. this.state.noAnonFunctionType = true;
  5779. const typeNode = this.startNode();
  5780. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5781. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5782. if (this.canInsertSemicolon()) this.unexpected();
  5783. if (!this.match(19)) this.unexpected();
  5784. return typeNode;
  5785. });
  5786. if (result.thrown) return null;
  5787. if (result.error) this.state = result.failState;
  5788. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5789. }
  5790. return super.parseArrow(node);
  5791. }
  5792. shouldParseArrow(params) {
  5793. return this.match(14) || super.shouldParseArrow(params);
  5794. }
  5795. setArrowFunctionParameters(node, params) {
  5796. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5797. node.params = params;
  5798. } else {
  5799. super.setArrowFunctionParameters(node, params);
  5800. }
  5801. }
  5802. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5803. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5804. return;
  5805. }
  5806. for (let i = 0; i < node.params.length; i++) {
  5807. if (this.isThisParam(node.params[i]) && i > 0) {
  5808. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  5809. }
  5810. }
  5811. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5812. }
  5813. parseParenAndDistinguishExpression(canBeArrow) {
  5814. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  5815. }
  5816. parseSubscripts(base, startLoc, noCalls) {
  5817. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  5818. this.next();
  5819. const node = this.startNodeAt(startLoc);
  5820. node.callee = base;
  5821. node.arguments = super.parseCallExpressionArguments(11);
  5822. base = this.finishNode(node, "CallExpression");
  5823. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5824. const state = this.state.clone();
  5825. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5826. if (!arrow.error && !arrow.aborted) return arrow.node;
  5827. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5828. if (result.node && !result.error) return result.node;
  5829. if (arrow.node) {
  5830. this.state = arrow.failState;
  5831. return arrow.node;
  5832. }
  5833. if (result.node) {
  5834. this.state = result.failState;
  5835. return result.node;
  5836. }
  5837. throw arrow.error || result.error;
  5838. }
  5839. return super.parseSubscripts(base, startLoc, noCalls);
  5840. }
  5841. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5842. if (this.match(18) && this.isLookaheadToken_lt()) {
  5843. subscriptState.optionalChainMember = true;
  5844. if (noCalls) {
  5845. subscriptState.stop = true;
  5846. return base;
  5847. }
  5848. this.next();
  5849. const node = this.startNodeAt(startLoc);
  5850. node.callee = base;
  5851. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  5852. this.expect(10);
  5853. node.arguments = this.parseCallExpressionArguments(11);
  5854. node.optional = true;
  5855. return this.finishCallExpression(node, true);
  5856. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  5857. const node = this.startNodeAt(startLoc);
  5858. node.callee = base;
  5859. const result = this.tryParse(() => {
  5860. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5861. this.expect(10);
  5862. node.arguments = super.parseCallExpressionArguments(11);
  5863. if (subscriptState.optionalChainMember) {
  5864. node.optional = false;
  5865. }
  5866. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5867. });
  5868. if (result.node) {
  5869. if (result.error) this.state = result.failState;
  5870. return result.node;
  5871. }
  5872. }
  5873. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5874. }
  5875. parseNewCallee(node) {
  5876. super.parseNewCallee(node);
  5877. let targs = null;
  5878. if (this.shouldParseTypes() && this.match(47)) {
  5879. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5880. }
  5881. node.typeArguments = targs;
  5882. }
  5883. parseAsyncArrowWithTypeParameters(startLoc) {
  5884. const node = this.startNodeAt(startLoc);
  5885. this.parseFunctionParams(node, false);
  5886. if (!this.parseArrow(node)) return;
  5887. return super.parseArrowExpression(node, undefined, true);
  5888. }
  5889. readToken_mult_modulo(code) {
  5890. const next = this.input.charCodeAt(this.state.pos + 1);
  5891. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5892. this.state.hasFlowComment = false;
  5893. this.state.pos += 2;
  5894. this.nextToken();
  5895. return;
  5896. }
  5897. super.readToken_mult_modulo(code);
  5898. }
  5899. readToken_pipe_amp(code) {
  5900. const next = this.input.charCodeAt(this.state.pos + 1);
  5901. if (code === 124 && next === 125) {
  5902. this.finishOp(9, 2);
  5903. return;
  5904. }
  5905. super.readToken_pipe_amp(code);
  5906. }
  5907. parseTopLevel(file, program) {
  5908. const fileNode = super.parseTopLevel(file, program);
  5909. if (this.state.hasFlowComment) {
  5910. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  5911. }
  5912. return fileNode;
  5913. }
  5914. skipBlockComment() {
  5915. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5916. if (this.state.hasFlowComment) {
  5917. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  5918. }
  5919. this.hasFlowCommentCompletion();
  5920. const commentSkip = this.skipFlowComment();
  5921. if (commentSkip) {
  5922. this.state.pos += commentSkip;
  5923. this.state.hasFlowComment = true;
  5924. }
  5925. return;
  5926. }
  5927. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5928. }
  5929. skipFlowComment() {
  5930. const {
  5931. pos
  5932. } = this.state;
  5933. let shiftToFirstNonWhiteSpace = 2;
  5934. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5935. shiftToFirstNonWhiteSpace++;
  5936. }
  5937. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5938. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5939. if (ch2 === 58 && ch3 === 58) {
  5940. return shiftToFirstNonWhiteSpace + 2;
  5941. }
  5942. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5943. return shiftToFirstNonWhiteSpace + 12;
  5944. }
  5945. if (ch2 === 58 && ch3 !== 58) {
  5946. return shiftToFirstNonWhiteSpace;
  5947. }
  5948. return false;
  5949. }
  5950. hasFlowCommentCompletion() {
  5951. const end = this.input.indexOf("*/", this.state.pos);
  5952. if (end === -1) {
  5953. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  5954. }
  5955. }
  5956. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5957. enumName,
  5958. memberName
  5959. }) {
  5960. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  5961. memberName,
  5962. enumName
  5963. });
  5964. }
  5965. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5966. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  5967. }
  5968. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  5969. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  5970. }
  5971. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  5972. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  5973. }
  5974. flowEnumMemberInit() {
  5975. const startLoc = this.state.startLoc;
  5976. const endOfInit = () => this.match(12) || this.match(8);
  5977. switch (this.state.type) {
  5978. case 135:
  5979. {
  5980. const literal = this.parseNumericLiteral(this.state.value);
  5981. if (endOfInit()) {
  5982. return {
  5983. type: "number",
  5984. loc: literal.loc.start,
  5985. value: literal
  5986. };
  5987. }
  5988. return {
  5989. type: "invalid",
  5990. loc: startLoc
  5991. };
  5992. }
  5993. case 134:
  5994. {
  5995. const literal = this.parseStringLiteral(this.state.value);
  5996. if (endOfInit()) {
  5997. return {
  5998. type: "string",
  5999. loc: literal.loc.start,
  6000. value: literal
  6001. };
  6002. }
  6003. return {
  6004. type: "invalid",
  6005. loc: startLoc
  6006. };
  6007. }
  6008. case 85:
  6009. case 86:
  6010. {
  6011. const literal = this.parseBooleanLiteral(this.match(85));
  6012. if (endOfInit()) {
  6013. return {
  6014. type: "boolean",
  6015. loc: literal.loc.start,
  6016. value: literal
  6017. };
  6018. }
  6019. return {
  6020. type: "invalid",
  6021. loc: startLoc
  6022. };
  6023. }
  6024. default:
  6025. return {
  6026. type: "invalid",
  6027. loc: startLoc
  6028. };
  6029. }
  6030. }
  6031. flowEnumMemberRaw() {
  6032. const loc = this.state.startLoc;
  6033. const id = this.parseIdentifier(true);
  6034. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6035. type: "none",
  6036. loc
  6037. };
  6038. return {
  6039. id,
  6040. init
  6041. };
  6042. }
  6043. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6044. const {
  6045. explicitType
  6046. } = context;
  6047. if (explicitType === null) {
  6048. return;
  6049. }
  6050. if (explicitType !== expectedType) {
  6051. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6052. }
  6053. }
  6054. flowEnumMembers({
  6055. enumName,
  6056. explicitType
  6057. }) {
  6058. const seenNames = new Set();
  6059. const members = {
  6060. booleanMembers: [],
  6061. numberMembers: [],
  6062. stringMembers: [],
  6063. defaultedMembers: []
  6064. };
  6065. let hasUnknownMembers = false;
  6066. while (!this.match(8)) {
  6067. if (this.eat(21)) {
  6068. hasUnknownMembers = true;
  6069. break;
  6070. }
  6071. const memberNode = this.startNode();
  6072. const {
  6073. id,
  6074. init
  6075. } = this.flowEnumMemberRaw();
  6076. const memberName = id.name;
  6077. if (memberName === "") {
  6078. continue;
  6079. }
  6080. if (/^[a-z]/.test(memberName)) {
  6081. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  6082. memberName,
  6083. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6084. enumName
  6085. });
  6086. }
  6087. if (seenNames.has(memberName)) {
  6088. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  6089. memberName,
  6090. enumName
  6091. });
  6092. }
  6093. seenNames.add(memberName);
  6094. const context = {
  6095. enumName,
  6096. explicitType,
  6097. memberName
  6098. };
  6099. memberNode.id = id;
  6100. switch (init.type) {
  6101. case "boolean":
  6102. {
  6103. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6104. memberNode.init = init.value;
  6105. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6106. break;
  6107. }
  6108. case "number":
  6109. {
  6110. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6111. memberNode.init = init.value;
  6112. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6113. break;
  6114. }
  6115. case "string":
  6116. {
  6117. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6118. memberNode.init = init.value;
  6119. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6120. break;
  6121. }
  6122. case "invalid":
  6123. {
  6124. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6125. }
  6126. case "none":
  6127. {
  6128. switch (explicitType) {
  6129. case "boolean":
  6130. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6131. break;
  6132. case "number":
  6133. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6134. break;
  6135. default:
  6136. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6137. }
  6138. }
  6139. }
  6140. if (!this.match(8)) {
  6141. this.expect(12);
  6142. }
  6143. }
  6144. return {
  6145. members,
  6146. hasUnknownMembers
  6147. };
  6148. }
  6149. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6150. enumName
  6151. }) {
  6152. if (initializedMembers.length === 0) {
  6153. return defaultedMembers;
  6154. } else if (defaultedMembers.length === 0) {
  6155. return initializedMembers;
  6156. } else if (defaultedMembers.length > initializedMembers.length) {
  6157. for (const member of initializedMembers) {
  6158. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6159. enumName
  6160. });
  6161. }
  6162. return defaultedMembers;
  6163. } else {
  6164. for (const member of defaultedMembers) {
  6165. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6166. enumName
  6167. });
  6168. }
  6169. return initializedMembers;
  6170. }
  6171. }
  6172. flowEnumParseExplicitType({
  6173. enumName
  6174. }) {
  6175. if (!this.eatContextual(102)) return null;
  6176. if (!tokenIsIdentifier(this.state.type)) {
  6177. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  6178. enumName
  6179. });
  6180. }
  6181. const {
  6182. value
  6183. } = this.state;
  6184. this.next();
  6185. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6186. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  6187. enumName,
  6188. invalidEnumType: value
  6189. });
  6190. }
  6191. return value;
  6192. }
  6193. flowEnumBody(node, id) {
  6194. const enumName = id.name;
  6195. const nameLoc = id.loc.start;
  6196. const explicitType = this.flowEnumParseExplicitType({
  6197. enumName
  6198. });
  6199. this.expect(5);
  6200. const {
  6201. members,
  6202. hasUnknownMembers
  6203. } = this.flowEnumMembers({
  6204. enumName,
  6205. explicitType
  6206. });
  6207. node.hasUnknownMembers = hasUnknownMembers;
  6208. switch (explicitType) {
  6209. case "boolean":
  6210. node.explicitType = true;
  6211. node.members = members.booleanMembers;
  6212. this.expect(8);
  6213. return this.finishNode(node, "EnumBooleanBody");
  6214. case "number":
  6215. node.explicitType = true;
  6216. node.members = members.numberMembers;
  6217. this.expect(8);
  6218. return this.finishNode(node, "EnumNumberBody");
  6219. case "string":
  6220. node.explicitType = true;
  6221. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6222. enumName
  6223. });
  6224. this.expect(8);
  6225. return this.finishNode(node, "EnumStringBody");
  6226. case "symbol":
  6227. node.members = members.defaultedMembers;
  6228. this.expect(8);
  6229. return this.finishNode(node, "EnumSymbolBody");
  6230. default:
  6231. {
  6232. const empty = () => {
  6233. node.members = [];
  6234. this.expect(8);
  6235. return this.finishNode(node, "EnumStringBody");
  6236. };
  6237. node.explicitType = false;
  6238. const boolsLen = members.booleanMembers.length;
  6239. const numsLen = members.numberMembers.length;
  6240. const strsLen = members.stringMembers.length;
  6241. const defaultedLen = members.defaultedMembers.length;
  6242. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6243. return empty();
  6244. } else if (!boolsLen && !numsLen) {
  6245. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6246. enumName
  6247. });
  6248. this.expect(8);
  6249. return this.finishNode(node, "EnumStringBody");
  6250. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6251. for (const member of members.defaultedMembers) {
  6252. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6253. enumName,
  6254. memberName: member.id.name
  6255. });
  6256. }
  6257. node.members = members.booleanMembers;
  6258. this.expect(8);
  6259. return this.finishNode(node, "EnumBooleanBody");
  6260. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6261. for (const member of members.defaultedMembers) {
  6262. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6263. enumName,
  6264. memberName: member.id.name
  6265. });
  6266. }
  6267. node.members = members.numberMembers;
  6268. this.expect(8);
  6269. return this.finishNode(node, "EnumNumberBody");
  6270. } else {
  6271. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  6272. enumName
  6273. });
  6274. return empty();
  6275. }
  6276. }
  6277. }
  6278. }
  6279. flowParseEnumDeclaration(node) {
  6280. const id = this.parseIdentifier();
  6281. node.id = id;
  6282. node.body = this.flowEnumBody(this.startNode(), id);
  6283. return this.finishNode(node, "EnumDeclaration");
  6284. }
  6285. jsxParseOpeningElementAfterName(node) {
  6286. if (this.shouldParseTypes()) {
  6287. if (this.match(47) || this.match(51)) {
  6288. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  6289. }
  6290. }
  6291. return super.jsxParseOpeningElementAfterName(node);
  6292. }
  6293. isLookaheadToken_lt() {
  6294. const next = this.nextTokenStart();
  6295. if (this.input.charCodeAt(next) === 60) {
  6296. const afterNext = this.input.charCodeAt(next + 1);
  6297. return afterNext !== 60 && afterNext !== 61;
  6298. }
  6299. return false;
  6300. }
  6301. reScan_lt_gt() {
  6302. const {
  6303. type
  6304. } = this.state;
  6305. if (type === 47) {
  6306. this.state.pos -= 1;
  6307. this.readToken_lt();
  6308. } else if (type === 48) {
  6309. this.state.pos -= 1;
  6310. this.readToken_gt();
  6311. }
  6312. }
  6313. reScan_lt() {
  6314. const {
  6315. type
  6316. } = this.state;
  6317. if (type === 51) {
  6318. this.state.pos -= 2;
  6319. this.finishOp(47, 1);
  6320. return 47;
  6321. }
  6322. return type;
  6323. }
  6324. maybeUnwrapTypeCastExpression(node) {
  6325. return node.type === "TypeCastExpression" ? node.expression : node;
  6326. }
  6327. };
  6328. const entities = {
  6329. __proto__: null,
  6330. quot: "\u0022",
  6331. amp: "&",
  6332. apos: "\u0027",
  6333. lt: "<",
  6334. gt: ">",
  6335. nbsp: "\u00A0",
  6336. iexcl: "\u00A1",
  6337. cent: "\u00A2",
  6338. pound: "\u00A3",
  6339. curren: "\u00A4",
  6340. yen: "\u00A5",
  6341. brvbar: "\u00A6",
  6342. sect: "\u00A7",
  6343. uml: "\u00A8",
  6344. copy: "\u00A9",
  6345. ordf: "\u00AA",
  6346. laquo: "\u00AB",
  6347. not: "\u00AC",
  6348. shy: "\u00AD",
  6349. reg: "\u00AE",
  6350. macr: "\u00AF",
  6351. deg: "\u00B0",
  6352. plusmn: "\u00B1",
  6353. sup2: "\u00B2",
  6354. sup3: "\u00B3",
  6355. acute: "\u00B4",
  6356. micro: "\u00B5",
  6357. para: "\u00B6",
  6358. middot: "\u00B7",
  6359. cedil: "\u00B8",
  6360. sup1: "\u00B9",
  6361. ordm: "\u00BA",
  6362. raquo: "\u00BB",
  6363. frac14: "\u00BC",
  6364. frac12: "\u00BD",
  6365. frac34: "\u00BE",
  6366. iquest: "\u00BF",
  6367. Agrave: "\u00C0",
  6368. Aacute: "\u00C1",
  6369. Acirc: "\u00C2",
  6370. Atilde: "\u00C3",
  6371. Auml: "\u00C4",
  6372. Aring: "\u00C5",
  6373. AElig: "\u00C6",
  6374. Ccedil: "\u00C7",
  6375. Egrave: "\u00C8",
  6376. Eacute: "\u00C9",
  6377. Ecirc: "\u00CA",
  6378. Euml: "\u00CB",
  6379. Igrave: "\u00CC",
  6380. Iacute: "\u00CD",
  6381. Icirc: "\u00CE",
  6382. Iuml: "\u00CF",
  6383. ETH: "\u00D0",
  6384. Ntilde: "\u00D1",
  6385. Ograve: "\u00D2",
  6386. Oacute: "\u00D3",
  6387. Ocirc: "\u00D4",
  6388. Otilde: "\u00D5",
  6389. Ouml: "\u00D6",
  6390. times: "\u00D7",
  6391. Oslash: "\u00D8",
  6392. Ugrave: "\u00D9",
  6393. Uacute: "\u00DA",
  6394. Ucirc: "\u00DB",
  6395. Uuml: "\u00DC",
  6396. Yacute: "\u00DD",
  6397. THORN: "\u00DE",
  6398. szlig: "\u00DF",
  6399. agrave: "\u00E0",
  6400. aacute: "\u00E1",
  6401. acirc: "\u00E2",
  6402. atilde: "\u00E3",
  6403. auml: "\u00E4",
  6404. aring: "\u00E5",
  6405. aelig: "\u00E6",
  6406. ccedil: "\u00E7",
  6407. egrave: "\u00E8",
  6408. eacute: "\u00E9",
  6409. ecirc: "\u00EA",
  6410. euml: "\u00EB",
  6411. igrave: "\u00EC",
  6412. iacute: "\u00ED",
  6413. icirc: "\u00EE",
  6414. iuml: "\u00EF",
  6415. eth: "\u00F0",
  6416. ntilde: "\u00F1",
  6417. ograve: "\u00F2",
  6418. oacute: "\u00F3",
  6419. ocirc: "\u00F4",
  6420. otilde: "\u00F5",
  6421. ouml: "\u00F6",
  6422. divide: "\u00F7",
  6423. oslash: "\u00F8",
  6424. ugrave: "\u00F9",
  6425. uacute: "\u00FA",
  6426. ucirc: "\u00FB",
  6427. uuml: "\u00FC",
  6428. yacute: "\u00FD",
  6429. thorn: "\u00FE",
  6430. yuml: "\u00FF",
  6431. OElig: "\u0152",
  6432. oelig: "\u0153",
  6433. Scaron: "\u0160",
  6434. scaron: "\u0161",
  6435. Yuml: "\u0178",
  6436. fnof: "\u0192",
  6437. circ: "\u02C6",
  6438. tilde: "\u02DC",
  6439. Alpha: "\u0391",
  6440. Beta: "\u0392",
  6441. Gamma: "\u0393",
  6442. Delta: "\u0394",
  6443. Epsilon: "\u0395",
  6444. Zeta: "\u0396",
  6445. Eta: "\u0397",
  6446. Theta: "\u0398",
  6447. Iota: "\u0399",
  6448. Kappa: "\u039A",
  6449. Lambda: "\u039B",
  6450. Mu: "\u039C",
  6451. Nu: "\u039D",
  6452. Xi: "\u039E",
  6453. Omicron: "\u039F",
  6454. Pi: "\u03A0",
  6455. Rho: "\u03A1",
  6456. Sigma: "\u03A3",
  6457. Tau: "\u03A4",
  6458. Upsilon: "\u03A5",
  6459. Phi: "\u03A6",
  6460. Chi: "\u03A7",
  6461. Psi: "\u03A8",
  6462. Omega: "\u03A9",
  6463. alpha: "\u03B1",
  6464. beta: "\u03B2",
  6465. gamma: "\u03B3",
  6466. delta: "\u03B4",
  6467. epsilon: "\u03B5",
  6468. zeta: "\u03B6",
  6469. eta: "\u03B7",
  6470. theta: "\u03B8",
  6471. iota: "\u03B9",
  6472. kappa: "\u03BA",
  6473. lambda: "\u03BB",
  6474. mu: "\u03BC",
  6475. nu: "\u03BD",
  6476. xi: "\u03BE",
  6477. omicron: "\u03BF",
  6478. pi: "\u03C0",
  6479. rho: "\u03C1",
  6480. sigmaf: "\u03C2",
  6481. sigma: "\u03C3",
  6482. tau: "\u03C4",
  6483. upsilon: "\u03C5",
  6484. phi: "\u03C6",
  6485. chi: "\u03C7",
  6486. psi: "\u03C8",
  6487. omega: "\u03C9",
  6488. thetasym: "\u03D1",
  6489. upsih: "\u03D2",
  6490. piv: "\u03D6",
  6491. ensp: "\u2002",
  6492. emsp: "\u2003",
  6493. thinsp: "\u2009",
  6494. zwnj: "\u200C",
  6495. zwj: "\u200D",
  6496. lrm: "\u200E",
  6497. rlm: "\u200F",
  6498. ndash: "\u2013",
  6499. mdash: "\u2014",
  6500. lsquo: "\u2018",
  6501. rsquo: "\u2019",
  6502. sbquo: "\u201A",
  6503. ldquo: "\u201C",
  6504. rdquo: "\u201D",
  6505. bdquo: "\u201E",
  6506. dagger: "\u2020",
  6507. Dagger: "\u2021",
  6508. bull: "\u2022",
  6509. hellip: "\u2026",
  6510. permil: "\u2030",
  6511. prime: "\u2032",
  6512. Prime: "\u2033",
  6513. lsaquo: "\u2039",
  6514. rsaquo: "\u203A",
  6515. oline: "\u203E",
  6516. frasl: "\u2044",
  6517. euro: "\u20AC",
  6518. image: "\u2111",
  6519. weierp: "\u2118",
  6520. real: "\u211C",
  6521. trade: "\u2122",
  6522. alefsym: "\u2135",
  6523. larr: "\u2190",
  6524. uarr: "\u2191",
  6525. rarr: "\u2192",
  6526. darr: "\u2193",
  6527. harr: "\u2194",
  6528. crarr: "\u21B5",
  6529. lArr: "\u21D0",
  6530. uArr: "\u21D1",
  6531. rArr: "\u21D2",
  6532. dArr: "\u21D3",
  6533. hArr: "\u21D4",
  6534. forall: "\u2200",
  6535. part: "\u2202",
  6536. exist: "\u2203",
  6537. empty: "\u2205",
  6538. nabla: "\u2207",
  6539. isin: "\u2208",
  6540. notin: "\u2209",
  6541. ni: "\u220B",
  6542. prod: "\u220F",
  6543. sum: "\u2211",
  6544. minus: "\u2212",
  6545. lowast: "\u2217",
  6546. radic: "\u221A",
  6547. prop: "\u221D",
  6548. infin: "\u221E",
  6549. ang: "\u2220",
  6550. and: "\u2227",
  6551. or: "\u2228",
  6552. cap: "\u2229",
  6553. cup: "\u222A",
  6554. int: "\u222B",
  6555. there4: "\u2234",
  6556. sim: "\u223C",
  6557. cong: "\u2245",
  6558. asymp: "\u2248",
  6559. ne: "\u2260",
  6560. equiv: "\u2261",
  6561. le: "\u2264",
  6562. ge: "\u2265",
  6563. sub: "\u2282",
  6564. sup: "\u2283",
  6565. nsub: "\u2284",
  6566. sube: "\u2286",
  6567. supe: "\u2287",
  6568. oplus: "\u2295",
  6569. otimes: "\u2297",
  6570. perp: "\u22A5",
  6571. sdot: "\u22C5",
  6572. lceil: "\u2308",
  6573. rceil: "\u2309",
  6574. lfloor: "\u230A",
  6575. rfloor: "\u230B",
  6576. lang: "\u2329",
  6577. rang: "\u232A",
  6578. loz: "\u25CA",
  6579. spades: "\u2660",
  6580. clubs: "\u2663",
  6581. hearts: "\u2665",
  6582. diams: "\u2666"
  6583. };
  6584. const JsxErrors = ParseErrorEnum`jsx`({
  6585. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6586. MissingClosingTagElement: ({
  6587. openingTagName
  6588. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6589. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6590. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6591. UnexpectedToken: ({
  6592. unexpected,
  6593. HTMLEntity
  6594. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6595. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6596. UnterminatedJsxContent: "Unterminated JSX contents.",
  6597. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6598. });
  6599. function isFragment(object) {
  6600. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6601. }
  6602. function getQualifiedJSXName(object) {
  6603. if (object.type === "JSXIdentifier") {
  6604. return object.name;
  6605. }
  6606. if (object.type === "JSXNamespacedName") {
  6607. return object.namespace.name + ":" + object.name.name;
  6608. }
  6609. if (object.type === "JSXMemberExpression") {
  6610. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6611. }
  6612. throw new Error("Node had unexpected type: " + object.type);
  6613. }
  6614. var jsx = superClass => class JSXParserMixin extends superClass {
  6615. jsxReadToken() {
  6616. let out = "";
  6617. let chunkStart = this.state.pos;
  6618. for (;;) {
  6619. if (this.state.pos >= this.length) {
  6620. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  6621. }
  6622. const ch = this.input.charCodeAt(this.state.pos);
  6623. switch (ch) {
  6624. case 60:
  6625. case 123:
  6626. if (this.state.pos === this.state.start) {
  6627. if (ch === 60 && this.state.canStartJSXElement) {
  6628. ++this.state.pos;
  6629. this.finishToken(143);
  6630. } else {
  6631. super.getTokenFromCode(ch);
  6632. }
  6633. return;
  6634. }
  6635. out += this.input.slice(chunkStart, this.state.pos);
  6636. this.finishToken(142, out);
  6637. return;
  6638. case 38:
  6639. out += this.input.slice(chunkStart, this.state.pos);
  6640. out += this.jsxReadEntity();
  6641. chunkStart = this.state.pos;
  6642. break;
  6643. case 62:
  6644. case 125:
  6645. default:
  6646. if (isNewLine(ch)) {
  6647. out += this.input.slice(chunkStart, this.state.pos);
  6648. out += this.jsxReadNewLine(true);
  6649. chunkStart = this.state.pos;
  6650. } else {
  6651. ++this.state.pos;
  6652. }
  6653. }
  6654. }
  6655. }
  6656. jsxReadNewLine(normalizeCRLF) {
  6657. const ch = this.input.charCodeAt(this.state.pos);
  6658. let out;
  6659. ++this.state.pos;
  6660. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6661. ++this.state.pos;
  6662. out = normalizeCRLF ? "\n" : "\r\n";
  6663. } else {
  6664. out = String.fromCharCode(ch);
  6665. }
  6666. ++this.state.curLine;
  6667. this.state.lineStart = this.state.pos;
  6668. return out;
  6669. }
  6670. jsxReadString(quote) {
  6671. let out = "";
  6672. let chunkStart = ++this.state.pos;
  6673. for (;;) {
  6674. if (this.state.pos >= this.length) {
  6675. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  6676. }
  6677. const ch = this.input.charCodeAt(this.state.pos);
  6678. if (ch === quote) break;
  6679. if (ch === 38) {
  6680. out += this.input.slice(chunkStart, this.state.pos);
  6681. out += this.jsxReadEntity();
  6682. chunkStart = this.state.pos;
  6683. } else if (isNewLine(ch)) {
  6684. out += this.input.slice(chunkStart, this.state.pos);
  6685. out += this.jsxReadNewLine(false);
  6686. chunkStart = this.state.pos;
  6687. } else {
  6688. ++this.state.pos;
  6689. }
  6690. }
  6691. out += this.input.slice(chunkStart, this.state.pos++);
  6692. this.finishToken(134, out);
  6693. }
  6694. jsxReadEntity() {
  6695. const startPos = ++this.state.pos;
  6696. if (this.codePointAtPos(this.state.pos) === 35) {
  6697. ++this.state.pos;
  6698. let radix = 10;
  6699. if (this.codePointAtPos(this.state.pos) === 120) {
  6700. radix = 16;
  6701. ++this.state.pos;
  6702. }
  6703. const codePoint = this.readInt(radix, undefined, false, "bail");
  6704. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6705. ++this.state.pos;
  6706. return String.fromCodePoint(codePoint);
  6707. }
  6708. } else {
  6709. let count = 0;
  6710. let semi = false;
  6711. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  6712. ++this.state.pos;
  6713. }
  6714. if (semi) {
  6715. const desc = this.input.slice(startPos, this.state.pos);
  6716. const entity = entities[desc];
  6717. ++this.state.pos;
  6718. if (entity) {
  6719. return entity;
  6720. }
  6721. }
  6722. }
  6723. this.state.pos = startPos;
  6724. return "&";
  6725. }
  6726. jsxReadWord() {
  6727. let ch;
  6728. const start = this.state.pos;
  6729. do {
  6730. ch = this.input.charCodeAt(++this.state.pos);
  6731. } while (isIdentifierChar(ch) || ch === 45);
  6732. this.finishToken(141, this.input.slice(start, this.state.pos));
  6733. }
  6734. jsxParseIdentifier() {
  6735. const node = this.startNode();
  6736. if (this.match(141)) {
  6737. node.name = this.state.value;
  6738. } else if (tokenIsKeyword(this.state.type)) {
  6739. node.name = tokenLabelName(this.state.type);
  6740. } else {
  6741. this.unexpected();
  6742. }
  6743. this.next();
  6744. return this.finishNode(node, "JSXIdentifier");
  6745. }
  6746. jsxParseNamespacedName() {
  6747. const startLoc = this.state.startLoc;
  6748. const name = this.jsxParseIdentifier();
  6749. if (!this.eat(14)) return name;
  6750. const node = this.startNodeAt(startLoc);
  6751. node.namespace = name;
  6752. node.name = this.jsxParseIdentifier();
  6753. return this.finishNode(node, "JSXNamespacedName");
  6754. }
  6755. jsxParseElementName() {
  6756. const startLoc = this.state.startLoc;
  6757. let node = this.jsxParseNamespacedName();
  6758. if (node.type === "JSXNamespacedName") {
  6759. return node;
  6760. }
  6761. while (this.eat(16)) {
  6762. const newNode = this.startNodeAt(startLoc);
  6763. newNode.object = node;
  6764. newNode.property = this.jsxParseIdentifier();
  6765. node = this.finishNode(newNode, "JSXMemberExpression");
  6766. }
  6767. return node;
  6768. }
  6769. jsxParseAttributeValue() {
  6770. let node;
  6771. switch (this.state.type) {
  6772. case 5:
  6773. node = this.startNode();
  6774. this.setContext(types.brace);
  6775. this.next();
  6776. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6777. if (node.expression.type === "JSXEmptyExpression") {
  6778. this.raise(JsxErrors.AttributeIsEmpty, node);
  6779. }
  6780. return node;
  6781. case 143:
  6782. case 134:
  6783. return this.parseExprAtom();
  6784. default:
  6785. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  6786. }
  6787. }
  6788. jsxParseEmptyExpression() {
  6789. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6790. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6791. }
  6792. jsxParseSpreadChild(node) {
  6793. this.next();
  6794. node.expression = this.parseExpression();
  6795. this.setContext(types.j_expr);
  6796. this.state.canStartJSXElement = true;
  6797. this.expect(8);
  6798. return this.finishNode(node, "JSXSpreadChild");
  6799. }
  6800. jsxParseExpressionContainer(node, previousContext) {
  6801. if (this.match(8)) {
  6802. node.expression = this.jsxParseEmptyExpression();
  6803. } else {
  6804. const expression = this.parseExpression();
  6805. node.expression = expression;
  6806. }
  6807. this.setContext(previousContext);
  6808. this.state.canStartJSXElement = true;
  6809. this.expect(8);
  6810. return this.finishNode(node, "JSXExpressionContainer");
  6811. }
  6812. jsxParseAttribute() {
  6813. const node = this.startNode();
  6814. if (this.match(5)) {
  6815. this.setContext(types.brace);
  6816. this.next();
  6817. this.expect(21);
  6818. node.argument = this.parseMaybeAssignAllowIn();
  6819. this.setContext(types.j_oTag);
  6820. this.state.canStartJSXElement = true;
  6821. this.expect(8);
  6822. return this.finishNode(node, "JSXSpreadAttribute");
  6823. }
  6824. node.name = this.jsxParseNamespacedName();
  6825. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6826. return this.finishNode(node, "JSXAttribute");
  6827. }
  6828. jsxParseOpeningElementAt(startLoc) {
  6829. const node = this.startNodeAt(startLoc);
  6830. if (this.eat(144)) {
  6831. return this.finishNode(node, "JSXOpeningFragment");
  6832. }
  6833. node.name = this.jsxParseElementName();
  6834. return this.jsxParseOpeningElementAfterName(node);
  6835. }
  6836. jsxParseOpeningElementAfterName(node) {
  6837. const attributes = [];
  6838. while (!this.match(56) && !this.match(144)) {
  6839. attributes.push(this.jsxParseAttribute());
  6840. }
  6841. node.attributes = attributes;
  6842. node.selfClosing = this.eat(56);
  6843. this.expect(144);
  6844. return this.finishNode(node, "JSXOpeningElement");
  6845. }
  6846. jsxParseClosingElementAt(startLoc) {
  6847. const node = this.startNodeAt(startLoc);
  6848. if (this.eat(144)) {
  6849. return this.finishNode(node, "JSXClosingFragment");
  6850. }
  6851. node.name = this.jsxParseElementName();
  6852. this.expect(144);
  6853. return this.finishNode(node, "JSXClosingElement");
  6854. }
  6855. jsxParseElementAt(startLoc) {
  6856. const node = this.startNodeAt(startLoc);
  6857. const children = [];
  6858. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6859. let closingElement = null;
  6860. if (!openingElement.selfClosing) {
  6861. contents: for (;;) {
  6862. switch (this.state.type) {
  6863. case 143:
  6864. startLoc = this.state.startLoc;
  6865. this.next();
  6866. if (this.eat(56)) {
  6867. closingElement = this.jsxParseClosingElementAt(startLoc);
  6868. break contents;
  6869. }
  6870. children.push(this.jsxParseElementAt(startLoc));
  6871. break;
  6872. case 142:
  6873. children.push(this.parseLiteral(this.state.value, "JSXText"));
  6874. break;
  6875. case 5:
  6876. {
  6877. const node = this.startNode();
  6878. this.setContext(types.brace);
  6879. this.next();
  6880. if (this.match(21)) {
  6881. children.push(this.jsxParseSpreadChild(node));
  6882. } else {
  6883. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6884. }
  6885. break;
  6886. }
  6887. default:
  6888. this.unexpected();
  6889. }
  6890. }
  6891. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6892. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  6893. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6894. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6895. openingTagName: getQualifiedJSXName(openingElement.name)
  6896. });
  6897. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6898. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6899. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  6900. openingTagName: getQualifiedJSXName(openingElement.name)
  6901. });
  6902. }
  6903. }
  6904. }
  6905. if (isFragment(openingElement)) {
  6906. node.openingFragment = openingElement;
  6907. node.closingFragment = closingElement;
  6908. } else {
  6909. node.openingElement = openingElement;
  6910. node.closingElement = closingElement;
  6911. }
  6912. node.children = children;
  6913. if (this.match(47)) {
  6914. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  6915. }
  6916. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6917. }
  6918. jsxParseElement() {
  6919. const startLoc = this.state.startLoc;
  6920. this.next();
  6921. return this.jsxParseElementAt(startLoc);
  6922. }
  6923. setContext(newContext) {
  6924. const {
  6925. context
  6926. } = this.state;
  6927. context[context.length - 1] = newContext;
  6928. }
  6929. parseExprAtom(refExpressionErrors) {
  6930. if (this.match(143)) {
  6931. return this.jsxParseElement();
  6932. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6933. this.replaceToken(143);
  6934. return this.jsxParseElement();
  6935. } else {
  6936. return super.parseExprAtom(refExpressionErrors);
  6937. }
  6938. }
  6939. skipSpace() {
  6940. const curContext = this.curContext();
  6941. if (!curContext.preserveSpace) super.skipSpace();
  6942. }
  6943. getTokenFromCode(code) {
  6944. const context = this.curContext();
  6945. if (context === types.j_expr) {
  6946. this.jsxReadToken();
  6947. return;
  6948. }
  6949. if (context === types.j_oTag || context === types.j_cTag) {
  6950. if (isIdentifierStart(code)) {
  6951. this.jsxReadWord();
  6952. return;
  6953. }
  6954. if (code === 62) {
  6955. ++this.state.pos;
  6956. this.finishToken(144);
  6957. return;
  6958. }
  6959. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6960. this.jsxReadString(code);
  6961. return;
  6962. }
  6963. }
  6964. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6965. ++this.state.pos;
  6966. this.finishToken(143);
  6967. return;
  6968. }
  6969. super.getTokenFromCode(code);
  6970. }
  6971. updateContext(prevType) {
  6972. const {
  6973. context,
  6974. type
  6975. } = this.state;
  6976. if (type === 56 && prevType === 143) {
  6977. context.splice(-2, 2, types.j_cTag);
  6978. this.state.canStartJSXElement = false;
  6979. } else if (type === 143) {
  6980. context.push(types.j_oTag);
  6981. } else if (type === 144) {
  6982. const out = context[context.length - 1];
  6983. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6984. context.pop();
  6985. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6986. } else {
  6987. this.setContext(types.j_expr);
  6988. this.state.canStartJSXElement = true;
  6989. }
  6990. } else {
  6991. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6992. }
  6993. }
  6994. };
  6995. class TypeScriptScope extends Scope {
  6996. constructor(...args) {
  6997. super(...args);
  6998. this.tsNames = new Map();
  6999. }
  7000. }
  7001. class TypeScriptScopeHandler extends ScopeHandler {
  7002. constructor(...args) {
  7003. super(...args);
  7004. this.importsStack = [];
  7005. }
  7006. createScope(flags) {
  7007. this.importsStack.push(new Set());
  7008. return new TypeScriptScope(flags);
  7009. }
  7010. enter(flags) {
  7011. if (flags === 256) {
  7012. this.importsStack.push(new Set());
  7013. }
  7014. super.enter(flags);
  7015. }
  7016. exit() {
  7017. const flags = super.exit();
  7018. if (flags === 256) {
  7019. this.importsStack.pop();
  7020. }
  7021. return flags;
  7022. }
  7023. hasImport(name, allowShadow) {
  7024. const len = this.importsStack.length;
  7025. if (this.importsStack[len - 1].has(name)) {
  7026. return true;
  7027. }
  7028. if (!allowShadow && len > 1) {
  7029. for (let i = 0; i < len - 1; i++) {
  7030. if (this.importsStack[i].has(name)) return true;
  7031. }
  7032. }
  7033. return false;
  7034. }
  7035. declareName(name, bindingType, loc) {
  7036. if (bindingType & 4096) {
  7037. if (this.hasImport(name, true)) {
  7038. this.parser.raise(Errors.VarRedeclaration, loc, {
  7039. identifierName: name
  7040. });
  7041. }
  7042. this.importsStack[this.importsStack.length - 1].add(name);
  7043. return;
  7044. }
  7045. const scope = this.currentScope();
  7046. let type = scope.tsNames.get(name) || 0;
  7047. if (bindingType & 1024) {
  7048. this.maybeExportDefined(scope, name);
  7049. scope.tsNames.set(name, type | 16);
  7050. return;
  7051. }
  7052. super.declareName(name, bindingType, loc);
  7053. if (bindingType & 2) {
  7054. if (!(bindingType & 1)) {
  7055. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7056. this.maybeExportDefined(scope, name);
  7057. }
  7058. type = type | 1;
  7059. }
  7060. if (bindingType & 256) {
  7061. type = type | 2;
  7062. }
  7063. if (bindingType & 512) {
  7064. type = type | 4;
  7065. }
  7066. if (bindingType & 128) {
  7067. type = type | 8;
  7068. }
  7069. if (type) scope.tsNames.set(name, type);
  7070. }
  7071. isRedeclaredInScope(scope, name, bindingType) {
  7072. const type = scope.tsNames.get(name);
  7073. if ((type & 2) > 0) {
  7074. if (bindingType & 256) {
  7075. const isConst = !!(bindingType & 512);
  7076. const wasConst = (type & 4) > 0;
  7077. return isConst !== wasConst;
  7078. }
  7079. return true;
  7080. }
  7081. if (bindingType & 128 && (type & 8) > 0) {
  7082. if (scope.names.get(name) & 2) {
  7083. return !!(bindingType & 1);
  7084. } else {
  7085. return false;
  7086. }
  7087. }
  7088. if (bindingType & 2 && (type & 1) > 0) {
  7089. return true;
  7090. }
  7091. return super.isRedeclaredInScope(scope, name, bindingType);
  7092. }
  7093. checkLocalExport(id) {
  7094. const {
  7095. name
  7096. } = id;
  7097. if (this.hasImport(name)) return;
  7098. const len = this.scopeStack.length;
  7099. for (let i = len - 1; i >= 0; i--) {
  7100. const scope = this.scopeStack[i];
  7101. const type = scope.tsNames.get(name);
  7102. if ((type & 1) > 0 || (type & 16) > 0) {
  7103. return;
  7104. }
  7105. }
  7106. super.checkLocalExport(id);
  7107. }
  7108. }
  7109. const unwrapParenthesizedExpression = node => {
  7110. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7111. };
  7112. class LValParser extends NodeUtils {
  7113. toAssignable(node, isLHS = false) {
  7114. var _node$extra, _node$extra3;
  7115. let parenthesized = undefined;
  7116. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7117. parenthesized = unwrapParenthesizedExpression(node);
  7118. if (isLHS) {
  7119. if (parenthesized.type === "Identifier") {
  7120. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  7121. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7122. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7123. }
  7124. } else {
  7125. this.raise(Errors.InvalidParenthesizedAssignment, node);
  7126. }
  7127. }
  7128. switch (node.type) {
  7129. case "Identifier":
  7130. case "ObjectPattern":
  7131. case "ArrayPattern":
  7132. case "AssignmentPattern":
  7133. case "RestElement":
  7134. break;
  7135. case "ObjectExpression":
  7136. node.type = "ObjectPattern";
  7137. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7138. var _node$extra2;
  7139. const prop = node.properties[i];
  7140. const isLast = i === last;
  7141. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7142. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7143. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  7144. }
  7145. }
  7146. break;
  7147. case "ObjectProperty":
  7148. {
  7149. const {
  7150. key,
  7151. value
  7152. } = node;
  7153. if (this.isPrivateName(key)) {
  7154. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7155. }
  7156. this.toAssignable(value, isLHS);
  7157. break;
  7158. }
  7159. case "SpreadElement":
  7160. {
  7161. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7162. }
  7163. case "ArrayExpression":
  7164. node.type = "ArrayPattern";
  7165. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7166. break;
  7167. case "AssignmentExpression":
  7168. if (node.operator !== "=") {
  7169. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  7170. }
  7171. node.type = "AssignmentPattern";
  7172. delete node.operator;
  7173. this.toAssignable(node.left, isLHS);
  7174. break;
  7175. case "ParenthesizedExpression":
  7176. this.toAssignable(parenthesized, isLHS);
  7177. break;
  7178. }
  7179. }
  7180. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7181. if (prop.type === "ObjectMethod") {
  7182. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  7183. } else if (prop.type === "SpreadElement") {
  7184. prop.type = "RestElement";
  7185. const arg = prop.argument;
  7186. this.checkToRestConversion(arg, false);
  7187. this.toAssignable(arg, isLHS);
  7188. if (!isLast) {
  7189. this.raise(Errors.RestTrailingComma, prop);
  7190. }
  7191. } else {
  7192. this.toAssignable(prop, isLHS);
  7193. }
  7194. }
  7195. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7196. const end = exprList.length - 1;
  7197. for (let i = 0; i <= end; i++) {
  7198. const elt = exprList[i];
  7199. if (!elt) continue;
  7200. if (elt.type === "SpreadElement") {
  7201. elt.type = "RestElement";
  7202. const arg = elt.argument;
  7203. this.checkToRestConversion(arg, true);
  7204. this.toAssignable(arg, isLHS);
  7205. } else {
  7206. this.toAssignable(elt, isLHS);
  7207. }
  7208. if (elt.type === "RestElement") {
  7209. if (i < end) {
  7210. this.raise(Errors.RestTrailingComma, elt);
  7211. } else if (trailingCommaLoc) {
  7212. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  7213. }
  7214. }
  7215. }
  7216. }
  7217. isAssignable(node, isBinding) {
  7218. switch (node.type) {
  7219. case "Identifier":
  7220. case "ObjectPattern":
  7221. case "ArrayPattern":
  7222. case "AssignmentPattern":
  7223. case "RestElement":
  7224. return true;
  7225. case "ObjectExpression":
  7226. {
  7227. const last = node.properties.length - 1;
  7228. return node.properties.every((prop, i) => {
  7229. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7230. });
  7231. }
  7232. case "ObjectProperty":
  7233. return this.isAssignable(node.value);
  7234. case "SpreadElement":
  7235. return this.isAssignable(node.argument);
  7236. case "ArrayExpression":
  7237. return node.elements.every(element => element === null || this.isAssignable(element));
  7238. case "AssignmentExpression":
  7239. return node.operator === "=";
  7240. case "ParenthesizedExpression":
  7241. return this.isAssignable(node.expression);
  7242. case "MemberExpression":
  7243. case "OptionalMemberExpression":
  7244. return !isBinding;
  7245. default:
  7246. return false;
  7247. }
  7248. }
  7249. toReferencedList(exprList, isParenthesizedExpr) {
  7250. return exprList;
  7251. }
  7252. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7253. this.toReferencedList(exprList, isParenthesizedExpr);
  7254. for (const expr of exprList) {
  7255. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7256. this.toReferencedListDeep(expr.elements);
  7257. }
  7258. }
  7259. }
  7260. parseSpread(refExpressionErrors) {
  7261. const node = this.startNode();
  7262. this.next();
  7263. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7264. return this.finishNode(node, "SpreadElement");
  7265. }
  7266. parseRestBinding() {
  7267. const node = this.startNode();
  7268. this.next();
  7269. node.argument = this.parseBindingAtom();
  7270. return this.finishNode(node, "RestElement");
  7271. }
  7272. parseBindingAtom() {
  7273. switch (this.state.type) {
  7274. case 0:
  7275. {
  7276. const node = this.startNode();
  7277. this.next();
  7278. node.elements = this.parseBindingList(3, 93, 1);
  7279. return this.finishNode(node, "ArrayPattern");
  7280. }
  7281. case 5:
  7282. return this.parseObjectLike(8, true);
  7283. }
  7284. return this.parseIdentifier();
  7285. }
  7286. parseBindingList(close, closeCharCode, flags) {
  7287. const allowEmpty = flags & 1;
  7288. const elts = [];
  7289. let first = true;
  7290. while (!this.eat(close)) {
  7291. if (first) {
  7292. first = false;
  7293. } else {
  7294. this.expect(12);
  7295. }
  7296. if (allowEmpty && this.match(12)) {
  7297. elts.push(null);
  7298. } else if (this.eat(close)) {
  7299. break;
  7300. } else if (this.match(21)) {
  7301. let rest = this.parseRestBinding();
  7302. if (this.hasPlugin("flow") || flags & 2) {
  7303. rest = this.parseFunctionParamType(rest);
  7304. }
  7305. elts.push(rest);
  7306. if (!this.checkCommaAfterRest(closeCharCode)) {
  7307. this.expect(close);
  7308. break;
  7309. }
  7310. } else {
  7311. const decorators = [];
  7312. if (this.match(26) && this.hasPlugin("decorators")) {
  7313. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  7314. }
  7315. while (this.match(26)) {
  7316. decorators.push(this.parseDecorator());
  7317. }
  7318. elts.push(this.parseAssignableListItem(flags, decorators));
  7319. }
  7320. }
  7321. return elts;
  7322. }
  7323. parseBindingRestProperty(prop) {
  7324. this.next();
  7325. prop.argument = this.parseIdentifier();
  7326. this.checkCommaAfterRest(125);
  7327. return this.finishNode(prop, "RestElement");
  7328. }
  7329. parseBindingProperty() {
  7330. const {
  7331. type,
  7332. startLoc
  7333. } = this.state;
  7334. if (type === 21) {
  7335. return this.parseBindingRestProperty(this.startNode());
  7336. }
  7337. const prop = this.startNode();
  7338. if (type === 139) {
  7339. this.expectPlugin("destructuringPrivate", startLoc);
  7340. this.classScope.usePrivateName(this.state.value, startLoc);
  7341. prop.key = this.parsePrivateName();
  7342. } else {
  7343. this.parsePropertyName(prop);
  7344. }
  7345. prop.method = false;
  7346. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7347. }
  7348. parseAssignableListItem(flags, decorators) {
  7349. const left = this.parseMaybeDefault();
  7350. if (this.hasPlugin("flow") || flags & 2) {
  7351. this.parseFunctionParamType(left);
  7352. }
  7353. const elt = this.parseMaybeDefault(left.loc.start, left);
  7354. if (decorators.length) {
  7355. left.decorators = decorators;
  7356. }
  7357. return elt;
  7358. }
  7359. parseFunctionParamType(param) {
  7360. return param;
  7361. }
  7362. parseMaybeDefault(startLoc, left) {
  7363. var _startLoc, _left;
  7364. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7365. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7366. if (!this.eat(29)) return left;
  7367. const node = this.startNodeAt(startLoc);
  7368. node.left = left;
  7369. node.right = this.parseMaybeAssignAllowIn();
  7370. return this.finishNode(node, "AssignmentPattern");
  7371. }
  7372. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7373. switch (type) {
  7374. case "AssignmentPattern":
  7375. return "left";
  7376. case "RestElement":
  7377. return "argument";
  7378. case "ObjectProperty":
  7379. return "value";
  7380. case "ParenthesizedExpression":
  7381. return "expression";
  7382. case "ArrayPattern":
  7383. return "elements";
  7384. case "ObjectPattern":
  7385. return "properties";
  7386. }
  7387. return false;
  7388. }
  7389. isOptionalMemberExpression(expression) {
  7390. return expression.type === "OptionalMemberExpression";
  7391. }
  7392. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false) {
  7393. var _expression$extra;
  7394. const type = expression.type;
  7395. if (this.isObjectMethod(expression)) return;
  7396. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7397. if (isOptionalMemberExpression || type === "MemberExpression") {
  7398. if (isOptionalMemberExpression) {
  7399. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7400. if (ancestor.type !== "AssignmentExpression") {
  7401. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  7402. ancestor
  7403. });
  7404. }
  7405. }
  7406. if (binding !== 64) {
  7407. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  7408. }
  7409. return;
  7410. }
  7411. if (type === "Identifier") {
  7412. this.checkIdentifier(expression, binding, strictModeChanged);
  7413. const {
  7414. name
  7415. } = expression;
  7416. if (checkClashes) {
  7417. if (checkClashes.has(name)) {
  7418. this.raise(Errors.ParamDupe, expression);
  7419. } else {
  7420. checkClashes.add(name);
  7421. }
  7422. }
  7423. return;
  7424. }
  7425. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7426. if (validity === true) return;
  7427. if (validity === false) {
  7428. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7429. this.raise(ParseErrorClass, expression, {
  7430. ancestor
  7431. });
  7432. return;
  7433. }
  7434. let key, isParenthesizedExpression;
  7435. if (typeof validity === "string") {
  7436. key = validity;
  7437. isParenthesizedExpression = type === "ParenthesizedExpression";
  7438. } else {
  7439. [key, isParenthesizedExpression] = validity;
  7440. }
  7441. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7442. type
  7443. } : ancestor;
  7444. const val = expression[key];
  7445. if (Array.isArray(val)) {
  7446. for (const child of val) {
  7447. if (child) {
  7448. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7449. }
  7450. }
  7451. } else if (val) {
  7452. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  7453. }
  7454. }
  7455. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7456. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7457. if (bindingType === 64) {
  7458. this.raise(Errors.StrictEvalArguments, at, {
  7459. referenceName: at.name
  7460. });
  7461. } else {
  7462. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  7463. bindingName: at.name
  7464. });
  7465. }
  7466. }
  7467. if (bindingType & 8192 && at.name === "let") {
  7468. this.raise(Errors.LetInLexicalBinding, at);
  7469. }
  7470. if (!(bindingType & 64)) {
  7471. this.declareNameFromIdentifier(at, bindingType);
  7472. }
  7473. }
  7474. declareNameFromIdentifier(identifier, binding) {
  7475. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7476. }
  7477. checkToRestConversion(node, allowPattern) {
  7478. switch (node.type) {
  7479. case "ParenthesizedExpression":
  7480. this.checkToRestConversion(node.expression, allowPattern);
  7481. break;
  7482. case "Identifier":
  7483. case "MemberExpression":
  7484. break;
  7485. case "ArrayExpression":
  7486. case "ObjectExpression":
  7487. if (allowPattern) break;
  7488. default:
  7489. this.raise(Errors.InvalidRestAssignmentPattern, node);
  7490. }
  7491. }
  7492. checkCommaAfterRest(close) {
  7493. if (!this.match(12)) {
  7494. return false;
  7495. }
  7496. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  7497. return true;
  7498. }
  7499. }
  7500. function nonNull(x) {
  7501. if (x == null) {
  7502. throw new Error(`Unexpected ${x} value.`);
  7503. }
  7504. return x;
  7505. }
  7506. function assert(x) {
  7507. if (!x) {
  7508. throw new Error("Assert fail");
  7509. }
  7510. }
  7511. const TSErrors = ParseErrorEnum`typescript`({
  7512. AbstractMethodHasImplementation: ({
  7513. methodName
  7514. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7515. AbstractPropertyHasInitializer: ({
  7516. propertyName
  7517. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7518. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7519. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7520. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7521. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7522. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7523. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7524. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7525. DeclareAccessor: ({
  7526. kind
  7527. }) => `'declare' is not allowed in ${kind}ters.`,
  7528. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7529. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7530. DuplicateAccessibilityModifier: ({
  7531. modifier
  7532. }) => `Accessibility modifier already seen.`,
  7533. DuplicateModifier: ({
  7534. modifier
  7535. }) => `Duplicate modifier: '${modifier}'.`,
  7536. EmptyHeritageClauseType: ({
  7537. token
  7538. }) => `'${token}' list cannot be empty.`,
  7539. EmptyTypeArguments: "Type argument list cannot be empty.",
  7540. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7541. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7542. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7543. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7544. IncompatibleModifiers: ({
  7545. modifiers
  7546. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7547. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7548. IndexSignatureHasAccessibility: ({
  7549. modifier
  7550. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7551. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7552. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7553. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7554. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7555. InvalidModifierOnTypeMember: ({
  7556. modifier
  7557. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7558. InvalidModifierOnTypeParameter: ({
  7559. modifier
  7560. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7561. InvalidModifierOnTypeParameterPositions: ({
  7562. modifier
  7563. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7564. InvalidModifiersOrder: ({
  7565. orderedModifiers
  7566. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7567. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7568. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7569. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7570. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7571. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7572. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7573. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7574. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7575. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7576. PrivateElementHasAccessibility: ({
  7577. modifier
  7578. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7579. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7580. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7581. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7582. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7583. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7584. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7585. SingleTypeParameterWithoutTrailingComma: ({
  7586. typeParameterName
  7587. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7588. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7589. TupleOptionalAfterType: "A labeled tuple optional element must be declared using a question mark after the name and before the colon (`name?: type`), rather than after the type (`name: type?`).",
  7590. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7591. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7592. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7593. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7594. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7595. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7596. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7597. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7598. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7599. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7600. UnsupportedSignatureParameterKind: ({
  7601. type
  7602. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7603. });
  7604. function keywordTypeFromName(value) {
  7605. switch (value) {
  7606. case "any":
  7607. return "TSAnyKeyword";
  7608. case "boolean":
  7609. return "TSBooleanKeyword";
  7610. case "bigint":
  7611. return "TSBigIntKeyword";
  7612. case "never":
  7613. return "TSNeverKeyword";
  7614. case "number":
  7615. return "TSNumberKeyword";
  7616. case "object":
  7617. return "TSObjectKeyword";
  7618. case "string":
  7619. return "TSStringKeyword";
  7620. case "symbol":
  7621. return "TSSymbolKeyword";
  7622. case "undefined":
  7623. return "TSUndefinedKeyword";
  7624. case "unknown":
  7625. return "TSUnknownKeyword";
  7626. default:
  7627. return undefined;
  7628. }
  7629. }
  7630. function tsIsAccessModifier(modifier) {
  7631. return modifier === "private" || modifier === "public" || modifier === "protected";
  7632. }
  7633. function tsIsVarianceAnnotations(modifier) {
  7634. return modifier === "in" || modifier === "out";
  7635. }
  7636. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7637. constructor(...args) {
  7638. super(...args);
  7639. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7640. allowedModifiers: ["in", "out"],
  7641. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7642. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7643. });
  7644. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7645. allowedModifiers: ["const"],
  7646. disallowedModifiers: ["in", "out"],
  7647. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7648. });
  7649. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7650. allowedModifiers: ["in", "out", "const"],
  7651. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7652. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7653. });
  7654. }
  7655. getScopeHandler() {
  7656. return TypeScriptScopeHandler;
  7657. }
  7658. tsIsIdentifier() {
  7659. return tokenIsIdentifier(this.state.type);
  7660. }
  7661. tsTokenCanFollowModifier() {
  7662. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  7663. }
  7664. tsNextTokenOnSameLineAndCanFollowModifier() {
  7665. this.next();
  7666. if (this.hasPrecedingLineBreak()) {
  7667. return false;
  7668. }
  7669. return this.tsTokenCanFollowModifier();
  7670. }
  7671. tsNextTokenCanFollowModifier() {
  7672. if (this.match(106)) {
  7673. this.next();
  7674. return this.tsTokenCanFollowModifier();
  7675. }
  7676. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  7677. }
  7678. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7679. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7680. return undefined;
  7681. }
  7682. const modifier = this.state.value;
  7683. if (allowedModifiers.includes(modifier)) {
  7684. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7685. return undefined;
  7686. }
  7687. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7688. return modifier;
  7689. }
  7690. }
  7691. return undefined;
  7692. }
  7693. tsParseModifiers({
  7694. allowedModifiers,
  7695. disallowedModifiers,
  7696. stopOnStartOfClassStaticBlock,
  7697. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7698. }, modified) {
  7699. const enforceOrder = (loc, modifier, before, after) => {
  7700. if (modifier === before && modified[after]) {
  7701. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  7702. orderedModifiers: [before, after]
  7703. });
  7704. }
  7705. };
  7706. const incompatible = (loc, modifier, mod1, mod2) => {
  7707. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7708. this.raise(TSErrors.IncompatibleModifiers, loc, {
  7709. modifiers: [mod1, mod2]
  7710. });
  7711. }
  7712. };
  7713. for (;;) {
  7714. const {
  7715. startLoc
  7716. } = this.state;
  7717. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7718. if (!modifier) break;
  7719. if (tsIsAccessModifier(modifier)) {
  7720. if (modified.accessibility) {
  7721. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  7722. modifier
  7723. });
  7724. } else {
  7725. enforceOrder(startLoc, modifier, modifier, "override");
  7726. enforceOrder(startLoc, modifier, modifier, "static");
  7727. enforceOrder(startLoc, modifier, modifier, "readonly");
  7728. modified.accessibility = modifier;
  7729. }
  7730. } else if (tsIsVarianceAnnotations(modifier)) {
  7731. if (modified[modifier]) {
  7732. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7733. modifier
  7734. });
  7735. }
  7736. modified[modifier] = true;
  7737. enforceOrder(startLoc, modifier, "in", "out");
  7738. } else {
  7739. if (hasOwnProperty.call(modified, modifier)) {
  7740. this.raise(TSErrors.DuplicateModifier, startLoc, {
  7741. modifier
  7742. });
  7743. } else {
  7744. enforceOrder(startLoc, modifier, "static", "readonly");
  7745. enforceOrder(startLoc, modifier, "static", "override");
  7746. enforceOrder(startLoc, modifier, "override", "readonly");
  7747. enforceOrder(startLoc, modifier, "abstract", "override");
  7748. incompatible(startLoc, modifier, "declare", "override");
  7749. incompatible(startLoc, modifier, "static", "abstract");
  7750. }
  7751. modified[modifier] = true;
  7752. }
  7753. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7754. this.raise(errorTemplate, startLoc, {
  7755. modifier
  7756. });
  7757. }
  7758. }
  7759. }
  7760. tsIsListTerminator(kind) {
  7761. switch (kind) {
  7762. case "EnumMembers":
  7763. case "TypeMembers":
  7764. return this.match(8);
  7765. case "HeritageClauseElement":
  7766. return this.match(5);
  7767. case "TupleElementTypes":
  7768. return this.match(3);
  7769. case "TypeParametersOrArguments":
  7770. return this.match(48);
  7771. }
  7772. }
  7773. tsParseList(kind, parseElement) {
  7774. const result = [];
  7775. while (!this.tsIsListTerminator(kind)) {
  7776. result.push(parseElement());
  7777. }
  7778. return result;
  7779. }
  7780. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7781. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7782. }
  7783. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7784. const result = [];
  7785. let trailingCommaPos = -1;
  7786. for (;;) {
  7787. if (this.tsIsListTerminator(kind)) {
  7788. break;
  7789. }
  7790. trailingCommaPos = -1;
  7791. const element = parseElement();
  7792. if (element == null) {
  7793. return undefined;
  7794. }
  7795. result.push(element);
  7796. if (this.eat(12)) {
  7797. trailingCommaPos = this.state.lastTokStartLoc.index;
  7798. continue;
  7799. }
  7800. if (this.tsIsListTerminator(kind)) {
  7801. break;
  7802. }
  7803. if (expectSuccess) {
  7804. this.expect(12);
  7805. }
  7806. return undefined;
  7807. }
  7808. if (refTrailingCommaPos) {
  7809. refTrailingCommaPos.value = trailingCommaPos;
  7810. }
  7811. return result;
  7812. }
  7813. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7814. if (!skipFirstToken) {
  7815. if (bracket) {
  7816. this.expect(0);
  7817. } else {
  7818. this.expect(47);
  7819. }
  7820. }
  7821. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7822. if (bracket) {
  7823. this.expect(3);
  7824. } else {
  7825. this.expect(48);
  7826. }
  7827. return result;
  7828. }
  7829. tsParseImportType() {
  7830. const node = this.startNode();
  7831. this.expect(83);
  7832. this.expect(10);
  7833. if (!this.match(134)) {
  7834. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  7835. {
  7836. node.argument = super.parseExprAtom();
  7837. }
  7838. } else {
  7839. {
  7840. node.argument = this.parseStringLiteral(this.state.value);
  7841. }
  7842. }
  7843. if (this.eat(12) && !this.match(11)) {
  7844. node.options = super.parseMaybeAssignAllowIn();
  7845. this.eat(12);
  7846. } else {
  7847. node.options = null;
  7848. }
  7849. this.expect(11);
  7850. if (this.eat(16)) {
  7851. node.qualifier = this.tsParseEntityName();
  7852. }
  7853. if (this.match(47)) {
  7854. {
  7855. node.typeParameters = this.tsParseTypeArguments();
  7856. }
  7857. }
  7858. return this.finishNode(node, "TSImportType");
  7859. }
  7860. tsParseEntityName(allowReservedWords = true) {
  7861. let entity = this.parseIdentifier(allowReservedWords);
  7862. while (this.eat(16)) {
  7863. const node = this.startNodeAtNode(entity);
  7864. node.left = entity;
  7865. node.right = this.parseIdentifier(allowReservedWords);
  7866. entity = this.finishNode(node, "TSQualifiedName");
  7867. }
  7868. return entity;
  7869. }
  7870. tsParseTypeReference() {
  7871. const node = this.startNode();
  7872. node.typeName = this.tsParseEntityName();
  7873. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7874. {
  7875. node.typeParameters = this.tsParseTypeArguments();
  7876. }
  7877. }
  7878. return this.finishNode(node, "TSTypeReference");
  7879. }
  7880. tsParseThisTypePredicate(lhs) {
  7881. this.next();
  7882. const node = this.startNodeAtNode(lhs);
  7883. node.parameterName = lhs;
  7884. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7885. node.asserts = false;
  7886. return this.finishNode(node, "TSTypePredicate");
  7887. }
  7888. tsParseThisTypeNode() {
  7889. const node = this.startNode();
  7890. this.next();
  7891. return this.finishNode(node, "TSThisType");
  7892. }
  7893. tsParseTypeQuery() {
  7894. const node = this.startNode();
  7895. this.expect(87);
  7896. if (this.match(83)) {
  7897. node.exprName = this.tsParseImportType();
  7898. } else {
  7899. node.exprName = this.tsParseEntityName();
  7900. }
  7901. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7902. {
  7903. node.typeParameters = this.tsParseTypeArguments();
  7904. }
  7905. }
  7906. return this.finishNode(node, "TSTypeQuery");
  7907. }
  7908. tsParseTypeParameter(parseModifiers) {
  7909. const node = this.startNode();
  7910. parseModifiers(node);
  7911. node.name = this.tsParseTypeParameterName();
  7912. node.constraint = this.tsEatThenParseType(81);
  7913. node.default = this.tsEatThenParseType(29);
  7914. return this.finishNode(node, "TSTypeParameter");
  7915. }
  7916. tsTryParseTypeParameters(parseModifiers) {
  7917. if (this.match(47)) {
  7918. return this.tsParseTypeParameters(parseModifiers);
  7919. }
  7920. }
  7921. tsParseTypeParameters(parseModifiers) {
  7922. const node = this.startNode();
  7923. if (this.match(47) || this.match(143)) {
  7924. this.next();
  7925. } else {
  7926. this.unexpected();
  7927. }
  7928. const refTrailingCommaPos = {
  7929. value: -1
  7930. };
  7931. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7932. if (node.params.length === 0) {
  7933. this.raise(TSErrors.EmptyTypeParameters, node);
  7934. }
  7935. if (refTrailingCommaPos.value !== -1) {
  7936. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7937. }
  7938. return this.finishNode(node, "TSTypeParameterDeclaration");
  7939. }
  7940. tsFillSignature(returnToken, signature) {
  7941. const returnTokenRequired = returnToken === 19;
  7942. const paramsKey = "parameters";
  7943. const returnTypeKey = "typeAnnotation";
  7944. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7945. this.expect(10);
  7946. signature[paramsKey] = this.tsParseBindingListForSignature();
  7947. if (returnTokenRequired) {
  7948. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7949. } else if (this.match(returnToken)) {
  7950. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7951. }
  7952. }
  7953. tsParseBindingListForSignature() {
  7954. const list = super.parseBindingList(11, 41, 2);
  7955. for (const pattern of list) {
  7956. const {
  7957. type
  7958. } = pattern;
  7959. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7960. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  7961. type
  7962. });
  7963. }
  7964. }
  7965. return list;
  7966. }
  7967. tsParseTypeMemberSemicolon() {
  7968. if (!this.eat(12) && !this.isLineTerminator()) {
  7969. this.expect(13);
  7970. }
  7971. }
  7972. tsParseSignatureMember(kind, node) {
  7973. this.tsFillSignature(14, node);
  7974. this.tsParseTypeMemberSemicolon();
  7975. return this.finishNode(node, kind);
  7976. }
  7977. tsIsUnambiguouslyIndexSignature() {
  7978. this.next();
  7979. if (tokenIsIdentifier(this.state.type)) {
  7980. this.next();
  7981. return this.match(14);
  7982. }
  7983. return false;
  7984. }
  7985. tsTryParseIndexSignature(node) {
  7986. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7987. return;
  7988. }
  7989. this.expect(0);
  7990. const id = this.parseIdentifier();
  7991. id.typeAnnotation = this.tsParseTypeAnnotation();
  7992. this.resetEndLocation(id);
  7993. this.expect(3);
  7994. node.parameters = [id];
  7995. const type = this.tsTryParseTypeAnnotation();
  7996. if (type) node.typeAnnotation = type;
  7997. this.tsParseTypeMemberSemicolon();
  7998. return this.finishNode(node, "TSIndexSignature");
  7999. }
  8000. tsParsePropertyOrMethodSignature(node, readonly) {
  8001. if (this.eat(17)) node.optional = true;
  8002. const nodeAny = node;
  8003. if (this.match(10) || this.match(47)) {
  8004. if (readonly) {
  8005. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  8006. }
  8007. const method = nodeAny;
  8008. if (method.kind && this.match(47)) {
  8009. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  8010. }
  8011. this.tsFillSignature(14, method);
  8012. this.tsParseTypeMemberSemicolon();
  8013. const paramsKey = "parameters";
  8014. const returnTypeKey = "typeAnnotation";
  8015. if (method.kind === "get") {
  8016. if (method[paramsKey].length > 0) {
  8017. this.raise(Errors.BadGetterArity, this.state.curPosition());
  8018. if (this.isThisParam(method[paramsKey][0])) {
  8019. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8020. }
  8021. }
  8022. } else if (method.kind === "set") {
  8023. if (method[paramsKey].length !== 1) {
  8024. this.raise(Errors.BadSetterArity, this.state.curPosition());
  8025. } else {
  8026. const firstParameter = method[paramsKey][0];
  8027. if (this.isThisParam(firstParameter)) {
  8028. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  8029. }
  8030. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8031. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  8032. }
  8033. if (firstParameter.type === "RestElement") {
  8034. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  8035. }
  8036. }
  8037. if (method[returnTypeKey]) {
  8038. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  8039. }
  8040. } else {
  8041. method.kind = "method";
  8042. }
  8043. return this.finishNode(method, "TSMethodSignature");
  8044. } else {
  8045. const property = nodeAny;
  8046. if (readonly) property.readonly = true;
  8047. const type = this.tsTryParseTypeAnnotation();
  8048. if (type) property.typeAnnotation = type;
  8049. this.tsParseTypeMemberSemicolon();
  8050. return this.finishNode(property, "TSPropertySignature");
  8051. }
  8052. }
  8053. tsParseTypeMember() {
  8054. const node = this.startNode();
  8055. if (this.match(10) || this.match(47)) {
  8056. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8057. }
  8058. if (this.match(77)) {
  8059. const id = this.startNode();
  8060. this.next();
  8061. if (this.match(10) || this.match(47)) {
  8062. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8063. } else {
  8064. node.key = this.createIdentifier(id, "new");
  8065. return this.tsParsePropertyOrMethodSignature(node, false);
  8066. }
  8067. }
  8068. this.tsParseModifiers({
  8069. allowedModifiers: ["readonly"],
  8070. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8071. }, node);
  8072. const idx = this.tsTryParseIndexSignature(node);
  8073. if (idx) {
  8074. return idx;
  8075. }
  8076. super.parsePropertyName(node);
  8077. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8078. node.kind = node.key.name;
  8079. super.parsePropertyName(node);
  8080. }
  8081. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8082. }
  8083. tsParseTypeLiteral() {
  8084. const node = this.startNode();
  8085. node.members = this.tsParseObjectTypeMembers();
  8086. return this.finishNode(node, "TSTypeLiteral");
  8087. }
  8088. tsParseObjectTypeMembers() {
  8089. this.expect(5);
  8090. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8091. this.expect(8);
  8092. return members;
  8093. }
  8094. tsIsStartOfMappedType() {
  8095. this.next();
  8096. if (this.eat(53)) {
  8097. return this.isContextual(122);
  8098. }
  8099. if (this.isContextual(122)) {
  8100. this.next();
  8101. }
  8102. if (!this.match(0)) {
  8103. return false;
  8104. }
  8105. this.next();
  8106. if (!this.tsIsIdentifier()) {
  8107. return false;
  8108. }
  8109. this.next();
  8110. return this.match(58);
  8111. }
  8112. tsParseMappedType() {
  8113. const node = this.startNode();
  8114. this.expect(5);
  8115. if (this.match(53)) {
  8116. node.readonly = this.state.value;
  8117. this.next();
  8118. this.expectContextual(122);
  8119. } else if (this.eatContextual(122)) {
  8120. node.readonly = true;
  8121. }
  8122. this.expect(0);
  8123. {
  8124. const typeParameter = this.startNode();
  8125. typeParameter.name = this.tsParseTypeParameterName();
  8126. typeParameter.constraint = this.tsExpectThenParseType(58);
  8127. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8128. }
  8129. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8130. this.expect(3);
  8131. if (this.match(53)) {
  8132. node.optional = this.state.value;
  8133. this.next();
  8134. this.expect(17);
  8135. } else if (this.eat(17)) {
  8136. node.optional = true;
  8137. }
  8138. node.typeAnnotation = this.tsTryParseType();
  8139. this.semicolon();
  8140. this.expect(8);
  8141. return this.finishNode(node, "TSMappedType");
  8142. }
  8143. tsParseTupleType() {
  8144. const node = this.startNode();
  8145. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8146. let seenOptionalElement = false;
  8147. node.elementTypes.forEach(elementNode => {
  8148. const {
  8149. type
  8150. } = elementNode;
  8151. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8152. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  8153. }
  8154. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8155. });
  8156. return this.finishNode(node, "TSTupleType");
  8157. }
  8158. tsParseTupleElementType() {
  8159. const {
  8160. startLoc
  8161. } = this.state;
  8162. const rest = this.eat(21);
  8163. let labeled;
  8164. let label;
  8165. let optional;
  8166. let type;
  8167. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8168. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8169. if (chAfterWord === 58) {
  8170. labeled = true;
  8171. optional = false;
  8172. label = this.parseIdentifier(true);
  8173. this.expect(14);
  8174. type = this.tsParseType();
  8175. } else if (chAfterWord === 63) {
  8176. optional = true;
  8177. const startLoc = this.state.startLoc;
  8178. const wordName = this.state.value;
  8179. const typeOrLabel = this.tsParseNonArrayType();
  8180. if (this.lookaheadCharCode() === 58) {
  8181. labeled = true;
  8182. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8183. this.expect(17);
  8184. this.expect(14);
  8185. type = this.tsParseType();
  8186. } else {
  8187. labeled = false;
  8188. type = typeOrLabel;
  8189. this.expect(17);
  8190. }
  8191. } else {
  8192. type = this.tsParseType();
  8193. optional = this.eat(17);
  8194. labeled = this.eat(14);
  8195. }
  8196. if (labeled) {
  8197. let labeledNode;
  8198. if (label) {
  8199. labeledNode = this.startNodeAtNode(label);
  8200. labeledNode.optional = optional;
  8201. labeledNode.label = label;
  8202. labeledNode.elementType = type;
  8203. if (this.eat(17)) {
  8204. labeledNode.optional = true;
  8205. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  8206. }
  8207. } else {
  8208. labeledNode = this.startNodeAtNode(type);
  8209. labeledNode.optional = optional;
  8210. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  8211. labeledNode.label = type;
  8212. labeledNode.elementType = this.tsParseType();
  8213. }
  8214. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8215. } else if (optional) {
  8216. const optionalTypeNode = this.startNodeAtNode(type);
  8217. optionalTypeNode.typeAnnotation = type;
  8218. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8219. }
  8220. if (rest) {
  8221. const restNode = this.startNodeAt(startLoc);
  8222. restNode.typeAnnotation = type;
  8223. type = this.finishNode(restNode, "TSRestType");
  8224. }
  8225. return type;
  8226. }
  8227. tsParseParenthesizedType() {
  8228. const node = this.startNode();
  8229. this.expect(10);
  8230. node.typeAnnotation = this.tsParseType();
  8231. this.expect(11);
  8232. return this.finishNode(node, "TSParenthesizedType");
  8233. }
  8234. tsParseFunctionOrConstructorType(type, abstract) {
  8235. const node = this.startNode();
  8236. if (type === "TSConstructorType") {
  8237. node.abstract = !!abstract;
  8238. if (abstract) this.next();
  8239. this.next();
  8240. }
  8241. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8242. return this.finishNode(node, type);
  8243. }
  8244. tsParseLiteralTypeNode() {
  8245. const node = this.startNode();
  8246. switch (this.state.type) {
  8247. case 135:
  8248. case 136:
  8249. case 134:
  8250. case 85:
  8251. case 86:
  8252. node.literal = super.parseExprAtom();
  8253. break;
  8254. default:
  8255. this.unexpected();
  8256. }
  8257. return this.finishNode(node, "TSLiteralType");
  8258. }
  8259. tsParseTemplateLiteralType() {
  8260. const node = this.startNode();
  8261. node.literal = super.parseTemplate(false);
  8262. return this.finishNode(node, "TSLiteralType");
  8263. }
  8264. parseTemplateSubstitution() {
  8265. if (this.state.inType) return this.tsParseType();
  8266. return super.parseTemplateSubstitution();
  8267. }
  8268. tsParseThisTypeOrThisTypePredicate() {
  8269. const thisKeyword = this.tsParseThisTypeNode();
  8270. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8271. return this.tsParseThisTypePredicate(thisKeyword);
  8272. } else {
  8273. return thisKeyword;
  8274. }
  8275. }
  8276. tsParseNonArrayType() {
  8277. switch (this.state.type) {
  8278. case 134:
  8279. case 135:
  8280. case 136:
  8281. case 85:
  8282. case 86:
  8283. return this.tsParseLiteralTypeNode();
  8284. case 53:
  8285. if (this.state.value === "-") {
  8286. const node = this.startNode();
  8287. const nextToken = this.lookahead();
  8288. if (nextToken.type !== 135 && nextToken.type !== 136) {
  8289. this.unexpected();
  8290. }
  8291. node.literal = this.parseMaybeUnary();
  8292. return this.finishNode(node, "TSLiteralType");
  8293. }
  8294. break;
  8295. case 78:
  8296. return this.tsParseThisTypeOrThisTypePredicate();
  8297. case 87:
  8298. return this.tsParseTypeQuery();
  8299. case 83:
  8300. return this.tsParseImportType();
  8301. case 5:
  8302. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8303. case 0:
  8304. return this.tsParseTupleType();
  8305. case 10:
  8306. return this.tsParseParenthesizedType();
  8307. case 25:
  8308. case 24:
  8309. return this.tsParseTemplateLiteralType();
  8310. default:
  8311. {
  8312. const {
  8313. type
  8314. } = this.state;
  8315. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8316. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8317. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8318. const node = this.startNode();
  8319. this.next();
  8320. return this.finishNode(node, nodeType);
  8321. }
  8322. return this.tsParseTypeReference();
  8323. }
  8324. }
  8325. }
  8326. this.unexpected();
  8327. }
  8328. tsParseArrayTypeOrHigher() {
  8329. let type = this.tsParseNonArrayType();
  8330. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8331. if (this.match(3)) {
  8332. const node = this.startNodeAtNode(type);
  8333. node.elementType = type;
  8334. this.expect(3);
  8335. type = this.finishNode(node, "TSArrayType");
  8336. } else {
  8337. const node = this.startNodeAtNode(type);
  8338. node.objectType = type;
  8339. node.indexType = this.tsParseType();
  8340. this.expect(3);
  8341. type = this.finishNode(node, "TSIndexedAccessType");
  8342. }
  8343. }
  8344. return type;
  8345. }
  8346. tsParseTypeOperator() {
  8347. const node = this.startNode();
  8348. const operator = this.state.value;
  8349. this.next();
  8350. node.operator = operator;
  8351. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8352. if (operator === "readonly") {
  8353. this.tsCheckTypeAnnotationForReadOnly(node);
  8354. }
  8355. return this.finishNode(node, "TSTypeOperator");
  8356. }
  8357. tsCheckTypeAnnotationForReadOnly(node) {
  8358. switch (node.typeAnnotation.type) {
  8359. case "TSTupleType":
  8360. case "TSArrayType":
  8361. return;
  8362. default:
  8363. this.raise(TSErrors.UnexpectedReadonly, node);
  8364. }
  8365. }
  8366. tsParseInferType() {
  8367. const node = this.startNode();
  8368. this.expectContextual(115);
  8369. const typeParameter = this.startNode();
  8370. typeParameter.name = this.tsParseTypeParameterName();
  8371. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8372. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8373. return this.finishNode(node, "TSInferType");
  8374. }
  8375. tsParseConstraintForInferType() {
  8376. if (this.eat(81)) {
  8377. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8378. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8379. return constraint;
  8380. }
  8381. }
  8382. }
  8383. tsParseTypeOperatorOrHigher() {
  8384. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8385. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8386. }
  8387. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8388. const node = this.startNode();
  8389. const hasLeadingOperator = this.eat(operator);
  8390. const types = [];
  8391. do {
  8392. types.push(parseConstituentType());
  8393. } while (this.eat(operator));
  8394. if (types.length === 1 && !hasLeadingOperator) {
  8395. return types[0];
  8396. }
  8397. node.types = types;
  8398. return this.finishNode(node, kind);
  8399. }
  8400. tsParseIntersectionTypeOrHigher() {
  8401. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8402. }
  8403. tsParseUnionTypeOrHigher() {
  8404. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8405. }
  8406. tsIsStartOfFunctionType() {
  8407. if (this.match(47)) {
  8408. return true;
  8409. }
  8410. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8411. }
  8412. tsSkipParameterStart() {
  8413. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8414. this.next();
  8415. return true;
  8416. }
  8417. if (this.match(5)) {
  8418. const {
  8419. errors
  8420. } = this.state;
  8421. const previousErrorCount = errors.length;
  8422. try {
  8423. this.parseObjectLike(8, true);
  8424. return errors.length === previousErrorCount;
  8425. } catch (_unused) {
  8426. return false;
  8427. }
  8428. }
  8429. if (this.match(0)) {
  8430. this.next();
  8431. const {
  8432. errors
  8433. } = this.state;
  8434. const previousErrorCount = errors.length;
  8435. try {
  8436. super.parseBindingList(3, 93, 1);
  8437. return errors.length === previousErrorCount;
  8438. } catch (_unused2) {
  8439. return false;
  8440. }
  8441. }
  8442. return false;
  8443. }
  8444. tsIsUnambiguouslyStartOfFunctionType() {
  8445. this.next();
  8446. if (this.match(11) || this.match(21)) {
  8447. return true;
  8448. }
  8449. if (this.tsSkipParameterStart()) {
  8450. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8451. return true;
  8452. }
  8453. if (this.match(11)) {
  8454. this.next();
  8455. if (this.match(19)) {
  8456. return true;
  8457. }
  8458. }
  8459. }
  8460. return false;
  8461. }
  8462. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8463. return this.tsInType(() => {
  8464. const t = this.startNode();
  8465. this.expect(returnToken);
  8466. const node = this.startNode();
  8467. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8468. if (asserts && this.match(78)) {
  8469. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8470. if (thisTypePredicate.type === "TSThisType") {
  8471. node.parameterName = thisTypePredicate;
  8472. node.asserts = true;
  8473. node.typeAnnotation = null;
  8474. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8475. } else {
  8476. this.resetStartLocationFromNode(thisTypePredicate, node);
  8477. thisTypePredicate.asserts = true;
  8478. }
  8479. t.typeAnnotation = thisTypePredicate;
  8480. return this.finishNode(t, "TSTypeAnnotation");
  8481. }
  8482. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8483. if (!typePredicateVariable) {
  8484. if (!asserts) {
  8485. return this.tsParseTypeAnnotation(false, t);
  8486. }
  8487. node.parameterName = this.parseIdentifier();
  8488. node.asserts = asserts;
  8489. node.typeAnnotation = null;
  8490. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8491. return this.finishNode(t, "TSTypeAnnotation");
  8492. }
  8493. const type = this.tsParseTypeAnnotation(false);
  8494. node.parameterName = typePredicateVariable;
  8495. node.typeAnnotation = type;
  8496. node.asserts = asserts;
  8497. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8498. return this.finishNode(t, "TSTypeAnnotation");
  8499. });
  8500. }
  8501. tsTryParseTypeOrTypePredicateAnnotation() {
  8502. if (this.match(14)) {
  8503. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8504. }
  8505. }
  8506. tsTryParseTypeAnnotation() {
  8507. if (this.match(14)) {
  8508. return this.tsParseTypeAnnotation();
  8509. }
  8510. }
  8511. tsTryParseType() {
  8512. return this.tsEatThenParseType(14);
  8513. }
  8514. tsParseTypePredicatePrefix() {
  8515. const id = this.parseIdentifier();
  8516. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8517. this.next();
  8518. return id;
  8519. }
  8520. }
  8521. tsParseTypePredicateAsserts() {
  8522. if (this.state.type !== 109) {
  8523. return false;
  8524. }
  8525. const containsEsc = this.state.containsEsc;
  8526. this.next();
  8527. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8528. return false;
  8529. }
  8530. if (containsEsc) {
  8531. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  8532. reservedWord: "asserts"
  8533. });
  8534. }
  8535. return true;
  8536. }
  8537. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8538. this.tsInType(() => {
  8539. if (eatColon) this.expect(14);
  8540. t.typeAnnotation = this.tsParseType();
  8541. });
  8542. return this.finishNode(t, "TSTypeAnnotation");
  8543. }
  8544. tsParseType() {
  8545. assert(this.state.inType);
  8546. const type = this.tsParseNonConditionalType();
  8547. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8548. return type;
  8549. }
  8550. const node = this.startNodeAtNode(type);
  8551. node.checkType = type;
  8552. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8553. this.expect(17);
  8554. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8555. this.expect(14);
  8556. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8557. return this.finishNode(node, "TSConditionalType");
  8558. }
  8559. isAbstractConstructorSignature() {
  8560. return this.isContextual(124) && this.lookahead().type === 77;
  8561. }
  8562. tsParseNonConditionalType() {
  8563. if (this.tsIsStartOfFunctionType()) {
  8564. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8565. }
  8566. if (this.match(77)) {
  8567. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8568. } else if (this.isAbstractConstructorSignature()) {
  8569. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8570. }
  8571. return this.tsParseUnionTypeOrHigher();
  8572. }
  8573. tsParseTypeAssertion() {
  8574. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8575. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  8576. }
  8577. const node = this.startNode();
  8578. node.typeAnnotation = this.tsInType(() => {
  8579. this.next();
  8580. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8581. });
  8582. this.expect(48);
  8583. node.expression = this.parseMaybeUnary();
  8584. return this.finishNode(node, "TSTypeAssertion");
  8585. }
  8586. tsParseHeritageClause(token) {
  8587. const originalStartLoc = this.state.startLoc;
  8588. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8589. const node = this.startNode();
  8590. node.expression = this.tsParseEntityName();
  8591. {
  8592. if (this.match(47)) {
  8593. node.typeParameters = this.tsParseTypeArguments();
  8594. }
  8595. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8596. }
  8597. });
  8598. if (!delimitedList.length) {
  8599. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  8600. token
  8601. });
  8602. }
  8603. return delimitedList;
  8604. }
  8605. tsParseInterfaceDeclaration(node, properties = {}) {
  8606. if (this.hasFollowingLineBreak()) return null;
  8607. this.expectContextual(129);
  8608. if (properties.declare) node.declare = true;
  8609. if (tokenIsIdentifier(this.state.type)) {
  8610. node.id = this.parseIdentifier();
  8611. this.checkIdentifier(node.id, 130);
  8612. } else {
  8613. node.id = null;
  8614. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  8615. }
  8616. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8617. if (this.eat(81)) {
  8618. node.extends = this.tsParseHeritageClause("extends");
  8619. }
  8620. const body = this.startNode();
  8621. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8622. node.body = this.finishNode(body, "TSInterfaceBody");
  8623. return this.finishNode(node, "TSInterfaceDeclaration");
  8624. }
  8625. tsParseTypeAliasDeclaration(node) {
  8626. node.id = this.parseIdentifier();
  8627. this.checkIdentifier(node.id, 2);
  8628. node.typeAnnotation = this.tsInType(() => {
  8629. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8630. this.expect(29);
  8631. if (this.isContextual(114) && this.lookahead().type !== 16) {
  8632. const node = this.startNode();
  8633. this.next();
  8634. return this.finishNode(node, "TSIntrinsicKeyword");
  8635. }
  8636. return this.tsParseType();
  8637. });
  8638. this.semicolon();
  8639. return this.finishNode(node, "TSTypeAliasDeclaration");
  8640. }
  8641. tsInTopLevelContext(cb) {
  8642. if (this.curContext() !== types.brace) {
  8643. const oldContext = this.state.context;
  8644. this.state.context = [oldContext[0]];
  8645. try {
  8646. return cb();
  8647. } finally {
  8648. this.state.context = oldContext;
  8649. }
  8650. } else {
  8651. return cb();
  8652. }
  8653. }
  8654. tsInType(cb) {
  8655. const oldInType = this.state.inType;
  8656. this.state.inType = true;
  8657. try {
  8658. return cb();
  8659. } finally {
  8660. this.state.inType = oldInType;
  8661. }
  8662. }
  8663. tsInDisallowConditionalTypesContext(cb) {
  8664. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8665. this.state.inDisallowConditionalTypesContext = true;
  8666. try {
  8667. return cb();
  8668. } finally {
  8669. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8670. }
  8671. }
  8672. tsInAllowConditionalTypesContext(cb) {
  8673. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8674. this.state.inDisallowConditionalTypesContext = false;
  8675. try {
  8676. return cb();
  8677. } finally {
  8678. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8679. }
  8680. }
  8681. tsEatThenParseType(token) {
  8682. if (this.match(token)) {
  8683. return this.tsNextThenParseType();
  8684. }
  8685. }
  8686. tsExpectThenParseType(token) {
  8687. return this.tsInType(() => {
  8688. this.expect(token);
  8689. return this.tsParseType();
  8690. });
  8691. }
  8692. tsNextThenParseType() {
  8693. return this.tsInType(() => {
  8694. this.next();
  8695. return this.tsParseType();
  8696. });
  8697. }
  8698. tsParseEnumMember() {
  8699. const node = this.startNode();
  8700. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8701. if (this.eat(29)) {
  8702. node.initializer = super.parseMaybeAssignAllowIn();
  8703. }
  8704. return this.finishNode(node, "TSEnumMember");
  8705. }
  8706. tsParseEnumDeclaration(node, properties = {}) {
  8707. if (properties.const) node.const = true;
  8708. if (properties.declare) node.declare = true;
  8709. this.expectContextual(126);
  8710. node.id = this.parseIdentifier();
  8711. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8712. {
  8713. this.expect(5);
  8714. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8715. this.expect(8);
  8716. }
  8717. return this.finishNode(node, "TSEnumDeclaration");
  8718. }
  8719. tsParseEnumBody() {
  8720. const node = this.startNode();
  8721. this.expect(5);
  8722. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8723. this.expect(8);
  8724. return this.finishNode(node, "TSEnumBody");
  8725. }
  8726. tsParseModuleBlock() {
  8727. const node = this.startNode();
  8728. this.scope.enter(0);
  8729. this.expect(5);
  8730. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8731. this.scope.exit();
  8732. return this.finishNode(node, "TSModuleBlock");
  8733. }
  8734. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8735. node.id = this.parseIdentifier();
  8736. if (!nested) {
  8737. this.checkIdentifier(node.id, 1024);
  8738. }
  8739. if (this.eat(16)) {
  8740. const inner = this.startNode();
  8741. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8742. node.body = inner;
  8743. } else {
  8744. this.scope.enter(256);
  8745. this.prodParam.enter(0);
  8746. node.body = this.tsParseModuleBlock();
  8747. this.prodParam.exit();
  8748. this.scope.exit();
  8749. }
  8750. return this.finishNode(node, "TSModuleDeclaration");
  8751. }
  8752. tsParseAmbientExternalModuleDeclaration(node) {
  8753. if (this.isContextual(112)) {
  8754. node.kind = "global";
  8755. {
  8756. node.global = true;
  8757. }
  8758. node.id = this.parseIdentifier();
  8759. } else if (this.match(134)) {
  8760. node.kind = "module";
  8761. node.id = super.parseStringLiteral(this.state.value);
  8762. } else {
  8763. this.unexpected();
  8764. }
  8765. if (this.match(5)) {
  8766. this.scope.enter(256);
  8767. this.prodParam.enter(0);
  8768. node.body = this.tsParseModuleBlock();
  8769. this.prodParam.exit();
  8770. this.scope.exit();
  8771. } else {
  8772. this.semicolon();
  8773. }
  8774. return this.finishNode(node, "TSModuleDeclaration");
  8775. }
  8776. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8777. node.isExport = isExport || false;
  8778. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8779. this.checkIdentifier(node.id, 4096);
  8780. this.expect(29);
  8781. const moduleReference = this.tsParseModuleReference();
  8782. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8783. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  8784. }
  8785. node.moduleReference = moduleReference;
  8786. this.semicolon();
  8787. return this.finishNode(node, "TSImportEqualsDeclaration");
  8788. }
  8789. tsIsExternalModuleReference() {
  8790. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8791. }
  8792. tsParseModuleReference() {
  8793. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8794. }
  8795. tsParseExternalModuleReference() {
  8796. const node = this.startNode();
  8797. this.expectContextual(119);
  8798. this.expect(10);
  8799. if (!this.match(134)) {
  8800. this.unexpected();
  8801. }
  8802. node.expression = super.parseExprAtom();
  8803. this.expect(11);
  8804. this.sawUnambiguousESM = true;
  8805. return this.finishNode(node, "TSExternalModuleReference");
  8806. }
  8807. tsLookAhead(f) {
  8808. const state = this.state.clone();
  8809. const res = f();
  8810. this.state = state;
  8811. return res;
  8812. }
  8813. tsTryParseAndCatch(f) {
  8814. const result = this.tryParse(abort => f() || abort());
  8815. if (result.aborted || !result.node) return;
  8816. if (result.error) this.state = result.failState;
  8817. return result.node;
  8818. }
  8819. tsTryParse(f) {
  8820. const state = this.state.clone();
  8821. const result = f();
  8822. if (result !== undefined && result !== false) {
  8823. return result;
  8824. }
  8825. this.state = state;
  8826. }
  8827. tsTryParseDeclare(nany) {
  8828. if (this.isLineTerminator()) {
  8829. return;
  8830. }
  8831. let startType = this.state.type;
  8832. let kind;
  8833. if (this.isContextual(100)) {
  8834. startType = 74;
  8835. kind = "let";
  8836. }
  8837. return this.tsInAmbientContext(() => {
  8838. switch (startType) {
  8839. case 68:
  8840. nany.declare = true;
  8841. return super.parseFunctionStatement(nany, false, false);
  8842. case 80:
  8843. nany.declare = true;
  8844. return this.parseClass(nany, true, false);
  8845. case 126:
  8846. return this.tsParseEnumDeclaration(nany, {
  8847. declare: true
  8848. });
  8849. case 112:
  8850. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8851. case 75:
  8852. case 74:
  8853. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8854. nany.declare = true;
  8855. return this.parseVarStatement(nany, kind || this.state.value, true);
  8856. }
  8857. this.expect(75);
  8858. return this.tsParseEnumDeclaration(nany, {
  8859. const: true,
  8860. declare: true
  8861. });
  8862. case 129:
  8863. {
  8864. const result = this.tsParseInterfaceDeclaration(nany, {
  8865. declare: true
  8866. });
  8867. if (result) return result;
  8868. }
  8869. default:
  8870. if (tokenIsIdentifier(startType)) {
  8871. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8872. }
  8873. }
  8874. });
  8875. }
  8876. tsTryParseExportDeclaration() {
  8877. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8878. }
  8879. tsParseExpressionStatement(node, expr, decorators) {
  8880. switch (expr.name) {
  8881. case "declare":
  8882. {
  8883. const declaration = this.tsTryParseDeclare(node);
  8884. if (declaration) {
  8885. declaration.declare = true;
  8886. }
  8887. return declaration;
  8888. }
  8889. case "global":
  8890. if (this.match(5)) {
  8891. this.scope.enter(256);
  8892. this.prodParam.enter(0);
  8893. const mod = node;
  8894. mod.kind = "global";
  8895. {
  8896. node.global = true;
  8897. }
  8898. mod.id = expr;
  8899. mod.body = this.tsParseModuleBlock();
  8900. this.scope.exit();
  8901. this.prodParam.exit();
  8902. return this.finishNode(mod, "TSModuleDeclaration");
  8903. }
  8904. break;
  8905. default:
  8906. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8907. }
  8908. }
  8909. tsParseDeclaration(node, value, next, decorators) {
  8910. switch (value) {
  8911. case "abstract":
  8912. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8913. return this.tsParseAbstractDeclaration(node, decorators);
  8914. }
  8915. break;
  8916. case "module":
  8917. if (this.tsCheckLineTerminator(next)) {
  8918. if (this.match(134)) {
  8919. return this.tsParseAmbientExternalModuleDeclaration(node);
  8920. } else if (tokenIsIdentifier(this.state.type)) {
  8921. node.kind = "module";
  8922. return this.tsParseModuleOrNamespaceDeclaration(node);
  8923. }
  8924. }
  8925. break;
  8926. case "namespace":
  8927. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8928. node.kind = "namespace";
  8929. return this.tsParseModuleOrNamespaceDeclaration(node);
  8930. }
  8931. break;
  8932. case "type":
  8933. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8934. return this.tsParseTypeAliasDeclaration(node);
  8935. }
  8936. break;
  8937. }
  8938. }
  8939. tsCheckLineTerminator(next) {
  8940. if (next) {
  8941. if (this.hasFollowingLineBreak()) return false;
  8942. this.next();
  8943. return true;
  8944. }
  8945. return !this.isLineTerminator();
  8946. }
  8947. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8948. if (!this.match(47)) return;
  8949. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8950. this.state.maybeInArrowParameters = true;
  8951. const res = this.tsTryParseAndCatch(() => {
  8952. const node = this.startNodeAt(startLoc);
  8953. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  8954. super.parseFunctionParams(node);
  8955. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8956. this.expect(19);
  8957. return node;
  8958. });
  8959. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8960. if (!res) return;
  8961. return super.parseArrowExpression(res, null, true);
  8962. }
  8963. tsParseTypeArgumentsInExpression() {
  8964. if (this.reScan_lt() !== 47) return;
  8965. return this.tsParseTypeArguments();
  8966. }
  8967. tsParseTypeArguments() {
  8968. const node = this.startNode();
  8969. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  8970. this.expect(47);
  8971. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8972. }));
  8973. if (node.params.length === 0) {
  8974. this.raise(TSErrors.EmptyTypeArguments, node);
  8975. } else if (!this.state.inType && this.curContext() === types.brace) {
  8976. this.reScan_lt_gt();
  8977. }
  8978. this.expect(48);
  8979. return this.finishNode(node, "TSTypeParameterInstantiation");
  8980. }
  8981. tsIsDeclarationStart() {
  8982. return tokenIsTSDeclarationStart(this.state.type);
  8983. }
  8984. isExportDefaultSpecifier() {
  8985. if (this.tsIsDeclarationStart()) return false;
  8986. return super.isExportDefaultSpecifier();
  8987. }
  8988. parseAssignableListItem(flags, decorators) {
  8989. const startLoc = this.state.startLoc;
  8990. const modified = {};
  8991. this.tsParseModifiers({
  8992. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  8993. }, modified);
  8994. const accessibility = modified.accessibility;
  8995. const override = modified.override;
  8996. const readonly = modified.readonly;
  8997. if (!(flags & 4) && (accessibility || readonly || override)) {
  8998. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  8999. }
  9000. const left = this.parseMaybeDefault();
  9001. if (flags & 2) {
  9002. this.parseFunctionParamType(left);
  9003. }
  9004. const elt = this.parseMaybeDefault(left.loc.start, left);
  9005. if (accessibility || readonly || override) {
  9006. const pp = this.startNodeAt(startLoc);
  9007. if (decorators.length) {
  9008. pp.decorators = decorators;
  9009. }
  9010. if (accessibility) pp.accessibility = accessibility;
  9011. if (readonly) pp.readonly = readonly;
  9012. if (override) pp.override = override;
  9013. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9014. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  9015. }
  9016. pp.parameter = elt;
  9017. return this.finishNode(pp, "TSParameterProperty");
  9018. }
  9019. if (decorators.length) {
  9020. left.decorators = decorators;
  9021. }
  9022. return elt;
  9023. }
  9024. isSimpleParameter(node) {
  9025. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9026. }
  9027. tsDisallowOptionalPattern(node) {
  9028. for (const param of node.params) {
  9029. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9030. this.raise(TSErrors.PatternIsOptional, param);
  9031. }
  9032. }
  9033. }
  9034. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9035. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9036. this.tsDisallowOptionalPattern(node);
  9037. }
  9038. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9039. if (this.match(14)) {
  9040. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9041. }
  9042. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9043. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9044. return this.finishNode(node, bodilessType);
  9045. }
  9046. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9047. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  9048. if (node.declare) {
  9049. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9050. }
  9051. }
  9052. this.tsDisallowOptionalPattern(node);
  9053. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9054. }
  9055. registerFunctionStatementId(node) {
  9056. if (!node.body && node.id) {
  9057. this.checkIdentifier(node.id, 1024);
  9058. } else {
  9059. super.registerFunctionStatementId(node);
  9060. }
  9061. }
  9062. tsCheckForInvalidTypeCasts(items) {
  9063. items.forEach(node => {
  9064. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9065. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  9066. }
  9067. });
  9068. }
  9069. toReferencedList(exprList, isInParens) {
  9070. this.tsCheckForInvalidTypeCasts(exprList);
  9071. return exprList;
  9072. }
  9073. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9074. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9075. if (node.type === "ArrayExpression") {
  9076. this.tsCheckForInvalidTypeCasts(node.elements);
  9077. }
  9078. return node;
  9079. }
  9080. parseSubscript(base, startLoc, noCalls, state) {
  9081. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9082. this.state.canStartJSXElement = false;
  9083. this.next();
  9084. const nonNullExpression = this.startNodeAt(startLoc);
  9085. nonNullExpression.expression = base;
  9086. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9087. }
  9088. let isOptionalCall = false;
  9089. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9090. if (noCalls) {
  9091. state.stop = true;
  9092. return base;
  9093. }
  9094. state.optionalChainMember = isOptionalCall = true;
  9095. this.next();
  9096. }
  9097. if (this.match(47) || this.match(51)) {
  9098. let missingParenErrorLoc;
  9099. const result = this.tsTryParseAndCatch(() => {
  9100. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9101. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9102. if (asyncArrowFn) {
  9103. return asyncArrowFn;
  9104. }
  9105. }
  9106. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9107. if (!typeArguments) return;
  9108. if (isOptionalCall && !this.match(10)) {
  9109. missingParenErrorLoc = this.state.curPosition();
  9110. return;
  9111. }
  9112. if (tokenIsTemplate(this.state.type)) {
  9113. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9114. {
  9115. result.typeParameters = typeArguments;
  9116. }
  9117. return result;
  9118. }
  9119. if (!noCalls && this.eat(10)) {
  9120. const node = this.startNodeAt(startLoc);
  9121. node.callee = base;
  9122. node.arguments = this.parseCallExpressionArguments(11);
  9123. this.tsCheckForInvalidTypeCasts(node.arguments);
  9124. {
  9125. node.typeParameters = typeArguments;
  9126. }
  9127. if (state.optionalChainMember) {
  9128. node.optional = isOptionalCall;
  9129. }
  9130. return this.finishCallExpression(node, state.optionalChainMember);
  9131. }
  9132. const tokenType = this.state.type;
  9133. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9134. return;
  9135. }
  9136. const node = this.startNodeAt(startLoc);
  9137. node.expression = base;
  9138. {
  9139. node.typeParameters = typeArguments;
  9140. }
  9141. return this.finishNode(node, "TSInstantiationExpression");
  9142. });
  9143. if (missingParenErrorLoc) {
  9144. this.unexpected(missingParenErrorLoc, 10);
  9145. }
  9146. if (result) {
  9147. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9148. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  9149. }
  9150. return result;
  9151. }
  9152. }
  9153. return super.parseSubscript(base, startLoc, noCalls, state);
  9154. }
  9155. parseNewCallee(node) {
  9156. var _callee$extra;
  9157. super.parseNewCallee(node);
  9158. const {
  9159. callee
  9160. } = node;
  9161. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9162. {
  9163. node.typeParameters = callee.typeParameters;
  9164. }
  9165. node.callee = callee.expression;
  9166. }
  9167. }
  9168. parseExprOp(left, leftStartLoc, minPrec) {
  9169. let isSatisfies;
  9170. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9171. const node = this.startNodeAt(leftStartLoc);
  9172. node.expression = left;
  9173. node.typeAnnotation = this.tsInType(() => {
  9174. this.next();
  9175. if (this.match(75)) {
  9176. if (isSatisfies) {
  9177. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  9178. keyword: "const"
  9179. });
  9180. }
  9181. return this.tsParseTypeReference();
  9182. }
  9183. return this.tsParseType();
  9184. });
  9185. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9186. this.reScan_lt_gt();
  9187. return this.parseExprOp(node, leftStartLoc, minPrec);
  9188. }
  9189. return super.parseExprOp(left, leftStartLoc, minPrec);
  9190. }
  9191. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9192. if (!this.state.isAmbientContext) {
  9193. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9194. }
  9195. }
  9196. checkImportReflection(node) {
  9197. super.checkImportReflection(node);
  9198. if (node.module && node.importKind !== "value") {
  9199. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  9200. }
  9201. }
  9202. checkDuplicateExports() {}
  9203. isPotentialImportPhase(isExport) {
  9204. if (super.isPotentialImportPhase(isExport)) return true;
  9205. if (this.isContextual(130)) {
  9206. const ch = this.lookaheadCharCode();
  9207. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9208. }
  9209. return !isExport && this.isContextual(87);
  9210. }
  9211. applyImportPhase(node, isExport, phase, loc) {
  9212. super.applyImportPhase(node, isExport, phase, loc);
  9213. if (isExport) {
  9214. node.exportKind = phase === "type" ? "type" : "value";
  9215. } else {
  9216. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9217. }
  9218. }
  9219. parseImport(node) {
  9220. if (this.match(134)) {
  9221. node.importKind = "value";
  9222. return super.parseImport(node);
  9223. }
  9224. let importNode;
  9225. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9226. node.importKind = "value";
  9227. return this.tsParseImportEqualsDeclaration(node);
  9228. } else if (this.isContextual(130)) {
  9229. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9230. if (this.lookaheadCharCode() === 61) {
  9231. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9232. } else {
  9233. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9234. }
  9235. } else {
  9236. importNode = super.parseImport(node);
  9237. }
  9238. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9239. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  9240. }
  9241. return importNode;
  9242. }
  9243. parseExport(node, decorators) {
  9244. if (this.match(83)) {
  9245. this.next();
  9246. const nodeImportEquals = node;
  9247. let maybeDefaultIdentifier = null;
  9248. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9249. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  9250. } else {
  9251. nodeImportEquals.importKind = "value";
  9252. }
  9253. return this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  9254. } else if (this.eat(29)) {
  9255. const assign = node;
  9256. assign.expression = super.parseExpression();
  9257. this.semicolon();
  9258. this.sawUnambiguousESM = true;
  9259. return this.finishNode(assign, "TSExportAssignment");
  9260. } else if (this.eatContextual(93)) {
  9261. const decl = node;
  9262. this.expectContextual(128);
  9263. decl.id = this.parseIdentifier();
  9264. this.semicolon();
  9265. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9266. } else {
  9267. return super.parseExport(node, decorators);
  9268. }
  9269. }
  9270. isAbstractClass() {
  9271. return this.isContextual(124) && this.lookahead().type === 80;
  9272. }
  9273. parseExportDefaultExpression() {
  9274. if (this.isAbstractClass()) {
  9275. const cls = this.startNode();
  9276. this.next();
  9277. cls.abstract = true;
  9278. return this.parseClass(cls, true, true);
  9279. }
  9280. if (this.match(129)) {
  9281. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9282. if (result) return result;
  9283. }
  9284. return super.parseExportDefaultExpression();
  9285. }
  9286. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9287. const {
  9288. isAmbientContext
  9289. } = this.state;
  9290. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9291. if (!isAmbientContext) return declaration;
  9292. for (const {
  9293. id,
  9294. init
  9295. } of declaration.declarations) {
  9296. if (!init) continue;
  9297. if (kind !== "const" || !!id.typeAnnotation) {
  9298. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  9299. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9300. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  9301. }
  9302. }
  9303. return declaration;
  9304. }
  9305. parseStatementContent(flags, decorators) {
  9306. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9307. const node = this.startNode();
  9308. this.expect(75);
  9309. return this.tsParseEnumDeclaration(node, {
  9310. const: true
  9311. });
  9312. }
  9313. if (this.isContextual(126)) {
  9314. return this.tsParseEnumDeclaration(this.startNode());
  9315. }
  9316. if (this.isContextual(129)) {
  9317. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9318. if (result) return result;
  9319. }
  9320. return super.parseStatementContent(flags, decorators);
  9321. }
  9322. parseAccessModifier() {
  9323. return this.tsParseModifier(["public", "protected", "private"]);
  9324. }
  9325. tsHasSomeModifiers(member, modifiers) {
  9326. return modifiers.some(modifier => {
  9327. if (tsIsAccessModifier(modifier)) {
  9328. return member.accessibility === modifier;
  9329. }
  9330. return !!member[modifier];
  9331. });
  9332. }
  9333. tsIsStartOfStaticBlocks() {
  9334. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9335. }
  9336. parseClassMember(classBody, member, state) {
  9337. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9338. this.tsParseModifiers({
  9339. allowedModifiers: modifiers,
  9340. disallowedModifiers: ["in", "out"],
  9341. stopOnStartOfClassStaticBlock: true,
  9342. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9343. }, member);
  9344. const callParseClassMemberWithIsStatic = () => {
  9345. if (this.tsIsStartOfStaticBlocks()) {
  9346. this.next();
  9347. this.next();
  9348. if (this.tsHasSomeModifiers(member, modifiers)) {
  9349. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  9350. }
  9351. super.parseClassStaticBlock(classBody, member);
  9352. } else {
  9353. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9354. }
  9355. };
  9356. if (member.declare) {
  9357. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9358. } else {
  9359. callParseClassMemberWithIsStatic();
  9360. }
  9361. }
  9362. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9363. const idx = this.tsTryParseIndexSignature(member);
  9364. if (idx) {
  9365. classBody.body.push(idx);
  9366. if (member.abstract) {
  9367. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  9368. }
  9369. if (member.accessibility) {
  9370. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  9371. modifier: member.accessibility
  9372. });
  9373. }
  9374. if (member.declare) {
  9375. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  9376. }
  9377. if (member.override) {
  9378. this.raise(TSErrors.IndexSignatureHasOverride, member);
  9379. }
  9380. return;
  9381. }
  9382. if (!this.state.inAbstractClass && member.abstract) {
  9383. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  9384. }
  9385. if (member.override) {
  9386. if (!state.hadSuperClass) {
  9387. this.raise(TSErrors.OverrideNotInSubClass, member);
  9388. }
  9389. }
  9390. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9391. }
  9392. parsePostMemberNameModifiers(methodOrProp) {
  9393. const optional = this.eat(17);
  9394. if (optional) methodOrProp.optional = true;
  9395. if (methodOrProp.readonly && this.match(10)) {
  9396. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  9397. }
  9398. if (methodOrProp.declare && this.match(10)) {
  9399. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  9400. }
  9401. }
  9402. parseExpressionStatement(node, expr, decorators) {
  9403. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9404. return decl || super.parseExpressionStatement(node, expr, decorators);
  9405. }
  9406. shouldParseExportDeclaration() {
  9407. if (this.tsIsDeclarationStart()) return true;
  9408. return super.shouldParseExportDeclaration();
  9409. }
  9410. parseConditional(expr, startLoc, refExpressionErrors) {
  9411. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9412. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9413. }
  9414. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9415. if (!result.node) {
  9416. if (result.error) {
  9417. super.setOptionalParametersError(refExpressionErrors, result.error);
  9418. }
  9419. return expr;
  9420. }
  9421. if (result.error) this.state = result.failState;
  9422. return result.node;
  9423. }
  9424. parseParenItem(node, startLoc) {
  9425. const newNode = super.parseParenItem(node, startLoc);
  9426. if (this.eat(17)) {
  9427. newNode.optional = true;
  9428. this.resetEndLocation(node);
  9429. }
  9430. if (this.match(14)) {
  9431. const typeCastNode = this.startNodeAt(startLoc);
  9432. typeCastNode.expression = node;
  9433. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9434. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9435. }
  9436. return node;
  9437. }
  9438. parseExportDeclaration(node) {
  9439. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9440. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9441. }
  9442. const startLoc = this.state.startLoc;
  9443. const isDeclare = this.eatContextual(125);
  9444. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9445. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  9446. }
  9447. const isIdentifier = tokenIsIdentifier(this.state.type);
  9448. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9449. if (!declaration) return null;
  9450. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9451. node.exportKind = "type";
  9452. }
  9453. if (isDeclare) {
  9454. this.resetStartLocation(declaration, startLoc);
  9455. declaration.declare = true;
  9456. }
  9457. return declaration;
  9458. }
  9459. parseClassId(node, isStatement, optionalId, bindingType) {
  9460. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9461. return;
  9462. }
  9463. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9464. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9465. if (typeParameters) node.typeParameters = typeParameters;
  9466. }
  9467. parseClassPropertyAnnotation(node) {
  9468. if (!node.optional) {
  9469. if (this.eat(35)) {
  9470. node.definite = true;
  9471. } else if (this.eat(17)) {
  9472. node.optional = true;
  9473. }
  9474. }
  9475. const type = this.tsTryParseTypeAnnotation();
  9476. if (type) node.typeAnnotation = type;
  9477. }
  9478. parseClassProperty(node) {
  9479. this.parseClassPropertyAnnotation(node);
  9480. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9481. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  9482. }
  9483. if (node.abstract && this.match(29)) {
  9484. const {
  9485. key
  9486. } = node;
  9487. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  9488. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9489. });
  9490. }
  9491. return super.parseClassProperty(node);
  9492. }
  9493. parseClassPrivateProperty(node) {
  9494. if (node.abstract) {
  9495. this.raise(TSErrors.PrivateElementHasAbstract, node);
  9496. }
  9497. if (node.accessibility) {
  9498. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  9499. modifier: node.accessibility
  9500. });
  9501. }
  9502. this.parseClassPropertyAnnotation(node);
  9503. return super.parseClassPrivateProperty(node);
  9504. }
  9505. parseClassAccessorProperty(node) {
  9506. this.parseClassPropertyAnnotation(node);
  9507. if (node.optional) {
  9508. this.raise(TSErrors.AccessorCannotBeOptional, node);
  9509. }
  9510. return super.parseClassAccessorProperty(node);
  9511. }
  9512. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9513. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9514. if (typeParameters && isConstructor) {
  9515. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  9516. }
  9517. const {
  9518. declare = false,
  9519. kind
  9520. } = method;
  9521. if (declare && (kind === "get" || kind === "set")) {
  9522. this.raise(TSErrors.DeclareAccessor, method, {
  9523. kind
  9524. });
  9525. }
  9526. if (typeParameters) method.typeParameters = typeParameters;
  9527. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9528. }
  9529. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9530. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9531. if (typeParameters) method.typeParameters = typeParameters;
  9532. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9533. }
  9534. declareClassPrivateMethodInScope(node, kind) {
  9535. if (node.type === "TSDeclareMethod") return;
  9536. if (node.type === "MethodDefinition" && !hasOwnProperty.call(node.value, "body")) {
  9537. return;
  9538. }
  9539. super.declareClassPrivateMethodInScope(node, kind);
  9540. }
  9541. parseClassSuper(node) {
  9542. super.parseClassSuper(node);
  9543. if (node.superClass && (this.match(47) || this.match(51))) {
  9544. {
  9545. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9546. }
  9547. }
  9548. if (this.eatContextual(113)) {
  9549. node.implements = this.tsParseHeritageClause("implements");
  9550. }
  9551. }
  9552. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9553. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9554. if (typeParameters) prop.typeParameters = typeParameters;
  9555. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9556. }
  9557. parseFunctionParams(node, isConstructor) {
  9558. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9559. if (typeParameters) node.typeParameters = typeParameters;
  9560. super.parseFunctionParams(node, isConstructor);
  9561. }
  9562. parseVarId(decl, kind) {
  9563. super.parseVarId(decl, kind);
  9564. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9565. decl.definite = true;
  9566. }
  9567. const type = this.tsTryParseTypeAnnotation();
  9568. if (type) {
  9569. decl.id.typeAnnotation = type;
  9570. this.resetEndLocation(decl.id);
  9571. }
  9572. }
  9573. parseAsyncArrowFromCallExpression(node, call) {
  9574. if (this.match(14)) {
  9575. node.returnType = this.tsParseTypeAnnotation();
  9576. }
  9577. return super.parseAsyncArrowFromCallExpression(node, call);
  9578. }
  9579. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9580. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9581. let state;
  9582. let jsx;
  9583. let typeCast;
  9584. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  9585. state = this.state.clone();
  9586. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9587. if (!jsx.error) return jsx.node;
  9588. const {
  9589. context
  9590. } = this.state;
  9591. const currentContext = context[context.length - 1];
  9592. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9593. context.pop();
  9594. }
  9595. }
  9596. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9597. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9598. }
  9599. if (!state || state === this.state) state = this.state.clone();
  9600. let typeParameters;
  9601. const arrow = this.tryParse(abort => {
  9602. var _expr$extra, _typeParameters;
  9603. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9604. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9605. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9606. abort();
  9607. }
  9608. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9609. this.resetStartLocationFromNode(expr, typeParameters);
  9610. }
  9611. expr.typeParameters = typeParameters;
  9612. return expr;
  9613. }, state);
  9614. if (!arrow.error && !arrow.aborted) {
  9615. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9616. return arrow.node;
  9617. }
  9618. if (!jsx) {
  9619. assert(!this.hasPlugin("jsx"));
  9620. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9621. if (!typeCast.error) return typeCast.node;
  9622. }
  9623. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9624. this.state = jsx.failState;
  9625. return jsx.node;
  9626. }
  9627. if (arrow.node) {
  9628. this.state = arrow.failState;
  9629. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9630. return arrow.node;
  9631. }
  9632. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9633. this.state = typeCast.failState;
  9634. return typeCast.node;
  9635. }
  9636. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9637. }
  9638. reportReservedArrowTypeParam(node) {
  9639. var _node$extra;
  9640. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9641. this.raise(TSErrors.ReservedArrowTypeParam, node);
  9642. }
  9643. }
  9644. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9645. if (!this.hasPlugin("jsx") && this.match(47)) {
  9646. return this.tsParseTypeAssertion();
  9647. }
  9648. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9649. }
  9650. parseArrow(node) {
  9651. if (this.match(14)) {
  9652. const result = this.tryParse(abort => {
  9653. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9654. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9655. return returnType;
  9656. });
  9657. if (result.aborted) return;
  9658. if (!result.thrown) {
  9659. if (result.error) this.state = result.failState;
  9660. node.returnType = result.node;
  9661. }
  9662. }
  9663. return super.parseArrow(node);
  9664. }
  9665. parseFunctionParamType(param) {
  9666. if (this.eat(17)) {
  9667. param.optional = true;
  9668. }
  9669. const type = this.tsTryParseTypeAnnotation();
  9670. if (type) param.typeAnnotation = type;
  9671. this.resetEndLocation(param);
  9672. return param;
  9673. }
  9674. isAssignable(node, isBinding) {
  9675. switch (node.type) {
  9676. case "TSTypeCastExpression":
  9677. return this.isAssignable(node.expression, isBinding);
  9678. case "TSParameterProperty":
  9679. return true;
  9680. default:
  9681. return super.isAssignable(node, isBinding);
  9682. }
  9683. }
  9684. toAssignable(node, isLHS = false) {
  9685. switch (node.type) {
  9686. case "ParenthesizedExpression":
  9687. this.toAssignableParenthesizedExpression(node, isLHS);
  9688. break;
  9689. case "TSAsExpression":
  9690. case "TSSatisfiesExpression":
  9691. case "TSNonNullExpression":
  9692. case "TSTypeAssertion":
  9693. if (isLHS) {
  9694. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  9695. } else {
  9696. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  9697. }
  9698. this.toAssignable(node.expression, isLHS);
  9699. break;
  9700. case "AssignmentExpression":
  9701. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9702. node.left = this.typeCastToParameter(node.left);
  9703. }
  9704. default:
  9705. super.toAssignable(node, isLHS);
  9706. }
  9707. }
  9708. toAssignableParenthesizedExpression(node, isLHS) {
  9709. switch (node.expression.type) {
  9710. case "TSAsExpression":
  9711. case "TSSatisfiesExpression":
  9712. case "TSNonNullExpression":
  9713. case "TSTypeAssertion":
  9714. case "ParenthesizedExpression":
  9715. this.toAssignable(node.expression, isLHS);
  9716. break;
  9717. default:
  9718. super.toAssignable(node, isLHS);
  9719. }
  9720. }
  9721. checkToRestConversion(node, allowPattern) {
  9722. switch (node.type) {
  9723. case "TSAsExpression":
  9724. case "TSSatisfiesExpression":
  9725. case "TSTypeAssertion":
  9726. case "TSNonNullExpression":
  9727. this.checkToRestConversion(node.expression, false);
  9728. break;
  9729. default:
  9730. super.checkToRestConversion(node, allowPattern);
  9731. }
  9732. }
  9733. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9734. switch (type) {
  9735. case "TSTypeCastExpression":
  9736. return true;
  9737. case "TSParameterProperty":
  9738. return "parameter";
  9739. case "TSNonNullExpression":
  9740. case "TSInstantiationExpression":
  9741. return "expression";
  9742. case "TSAsExpression":
  9743. case "TSSatisfiesExpression":
  9744. case "TSTypeAssertion":
  9745. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  9746. default:
  9747. return super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9748. }
  9749. }
  9750. parseBindingAtom() {
  9751. if (this.state.type === 78) {
  9752. return this.parseIdentifier(true);
  9753. }
  9754. return super.parseBindingAtom();
  9755. }
  9756. parseMaybeDecoratorArguments(expr, startLoc) {
  9757. if (this.match(47) || this.match(51)) {
  9758. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9759. if (this.match(10)) {
  9760. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  9761. {
  9762. call.typeParameters = typeArguments;
  9763. }
  9764. return call;
  9765. }
  9766. this.unexpected(null, 10);
  9767. }
  9768. return super.parseMaybeDecoratorArguments(expr, startLoc);
  9769. }
  9770. checkCommaAfterRest(close) {
  9771. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9772. this.next();
  9773. return false;
  9774. }
  9775. return super.checkCommaAfterRest(close);
  9776. }
  9777. isClassMethod() {
  9778. return this.match(47) || super.isClassMethod();
  9779. }
  9780. isClassProperty() {
  9781. return this.match(35) || this.match(14) || super.isClassProperty();
  9782. }
  9783. parseMaybeDefault(startLoc, left) {
  9784. const node = super.parseMaybeDefault(startLoc, left);
  9785. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9786. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  9787. }
  9788. return node;
  9789. }
  9790. getTokenFromCode(code) {
  9791. if (this.state.inType) {
  9792. if (code === 62) {
  9793. this.finishOp(48, 1);
  9794. return;
  9795. }
  9796. if (code === 60) {
  9797. this.finishOp(47, 1);
  9798. return;
  9799. }
  9800. }
  9801. super.getTokenFromCode(code);
  9802. }
  9803. reScan_lt_gt() {
  9804. const {
  9805. type
  9806. } = this.state;
  9807. if (type === 47) {
  9808. this.state.pos -= 1;
  9809. this.readToken_lt();
  9810. } else if (type === 48) {
  9811. this.state.pos -= 1;
  9812. this.readToken_gt();
  9813. }
  9814. }
  9815. reScan_lt() {
  9816. const {
  9817. type
  9818. } = this.state;
  9819. if (type === 51) {
  9820. this.state.pos -= 2;
  9821. this.finishOp(47, 1);
  9822. return 47;
  9823. }
  9824. return type;
  9825. }
  9826. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9827. for (let i = 0; i < exprList.length; i++) {
  9828. const expr = exprList[i];
  9829. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9830. exprList[i] = this.typeCastToParameter(expr);
  9831. }
  9832. }
  9833. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9834. }
  9835. typeCastToParameter(node) {
  9836. node.expression.typeAnnotation = node.typeAnnotation;
  9837. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9838. return node.expression;
  9839. }
  9840. shouldParseArrow(params) {
  9841. if (this.match(14)) {
  9842. return params.every(expr => this.isAssignable(expr, true));
  9843. }
  9844. return super.shouldParseArrow(params);
  9845. }
  9846. shouldParseAsyncArrow() {
  9847. return this.match(14) || super.shouldParseAsyncArrow();
  9848. }
  9849. canHaveLeadingDecorator() {
  9850. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9851. }
  9852. jsxParseOpeningElementAfterName(node) {
  9853. if (this.match(47) || this.match(51)) {
  9854. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9855. if (typeArguments) {
  9856. {
  9857. node.typeParameters = typeArguments;
  9858. }
  9859. }
  9860. }
  9861. return super.jsxParseOpeningElementAfterName(node);
  9862. }
  9863. getGetterSetterExpectedParamCount(method) {
  9864. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9865. const params = this.getObjectOrClassMethodParams(method);
  9866. const firstParam = params[0];
  9867. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9868. return hasContextParam ? baseCount + 1 : baseCount;
  9869. }
  9870. parseCatchClauseParam() {
  9871. const param = super.parseCatchClauseParam();
  9872. const type = this.tsTryParseTypeAnnotation();
  9873. if (type) {
  9874. param.typeAnnotation = type;
  9875. this.resetEndLocation(param);
  9876. }
  9877. return param;
  9878. }
  9879. tsInAmbientContext(cb) {
  9880. const {
  9881. isAmbientContext: oldIsAmbientContext,
  9882. strict: oldStrict
  9883. } = this.state;
  9884. this.state.isAmbientContext = true;
  9885. this.state.strict = false;
  9886. try {
  9887. return cb();
  9888. } finally {
  9889. this.state.isAmbientContext = oldIsAmbientContext;
  9890. this.state.strict = oldStrict;
  9891. }
  9892. }
  9893. parseClass(node, isStatement, optionalId) {
  9894. const oldInAbstractClass = this.state.inAbstractClass;
  9895. this.state.inAbstractClass = !!node.abstract;
  9896. try {
  9897. return super.parseClass(node, isStatement, optionalId);
  9898. } finally {
  9899. this.state.inAbstractClass = oldInAbstractClass;
  9900. }
  9901. }
  9902. tsParseAbstractDeclaration(node, decorators) {
  9903. if (this.match(80)) {
  9904. node.abstract = true;
  9905. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9906. } else if (this.isContextual(129)) {
  9907. if (!this.hasFollowingLineBreak()) {
  9908. node.abstract = true;
  9909. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, node);
  9910. return this.tsParseInterfaceDeclaration(node);
  9911. }
  9912. } else {
  9913. this.unexpected(null, 80);
  9914. }
  9915. }
  9916. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9917. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9918. if (method.abstract) {
  9919. const hasEstreePlugin = this.hasPlugin("estree");
  9920. const methodFn = hasEstreePlugin ? method.value : method;
  9921. if (methodFn.body) {
  9922. const {
  9923. key
  9924. } = method;
  9925. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  9926. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  9927. });
  9928. }
  9929. }
  9930. return method;
  9931. }
  9932. tsParseTypeParameterName() {
  9933. const typeName = this.parseIdentifier();
  9934. return typeName.name;
  9935. }
  9936. shouldParseAsAmbientContext() {
  9937. return !!this.getPluginOption("typescript", "dts");
  9938. }
  9939. parse() {
  9940. if (this.shouldParseAsAmbientContext()) {
  9941. this.state.isAmbientContext = true;
  9942. }
  9943. return super.parse();
  9944. }
  9945. getExpression() {
  9946. if (this.shouldParseAsAmbientContext()) {
  9947. this.state.isAmbientContext = true;
  9948. }
  9949. return super.getExpression();
  9950. }
  9951. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9952. if (!isString && isMaybeTypeOnly) {
  9953. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9954. return this.finishNode(node, "ExportSpecifier");
  9955. }
  9956. node.exportKind = "value";
  9957. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9958. }
  9959. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  9960. if (!importedIsString && isMaybeTypeOnly) {
  9961. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  9962. return this.finishNode(specifier, "ImportSpecifier");
  9963. }
  9964. specifier.importKind = "value";
  9965. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  9966. }
  9967. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  9968. const leftOfAsKey = isImport ? "imported" : "local";
  9969. const rightOfAsKey = isImport ? "local" : "exported";
  9970. let leftOfAs = node[leftOfAsKey];
  9971. let rightOfAs;
  9972. let hasTypeSpecifier = false;
  9973. let canParseAsKeyword = true;
  9974. const loc = leftOfAs.loc.start;
  9975. if (this.isContextual(93)) {
  9976. const firstAs = this.parseIdentifier();
  9977. if (this.isContextual(93)) {
  9978. const secondAs = this.parseIdentifier();
  9979. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9980. hasTypeSpecifier = true;
  9981. leftOfAs = firstAs;
  9982. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9983. canParseAsKeyword = false;
  9984. } else {
  9985. rightOfAs = secondAs;
  9986. canParseAsKeyword = false;
  9987. }
  9988. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9989. canParseAsKeyword = false;
  9990. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  9991. } else {
  9992. hasTypeSpecifier = true;
  9993. leftOfAs = firstAs;
  9994. }
  9995. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  9996. hasTypeSpecifier = true;
  9997. if (isImport) {
  9998. leftOfAs = this.parseIdentifier(true);
  9999. if (!this.isContextual(93)) {
  10000. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10001. }
  10002. } else {
  10003. leftOfAs = this.parseModuleExportName();
  10004. }
  10005. }
  10006. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10007. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  10008. }
  10009. node[leftOfAsKey] = leftOfAs;
  10010. node[rightOfAsKey] = rightOfAs;
  10011. const kindKey = isImport ? "importKind" : "exportKind";
  10012. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10013. if (canParseAsKeyword && this.eatContextual(93)) {
  10014. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10015. }
  10016. if (!node[rightOfAsKey]) {
  10017. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10018. }
  10019. if (isImport) {
  10020. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10021. }
  10022. }
  10023. };
  10024. function isPossiblyLiteralEnum(expression) {
  10025. if (expression.type !== "MemberExpression") return false;
  10026. const {
  10027. computed,
  10028. property
  10029. } = expression;
  10030. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10031. return false;
  10032. }
  10033. return isUncomputedMemberExpressionChain(expression.object);
  10034. }
  10035. function isValidAmbientConstInitializer(expression, estree) {
  10036. var _expression$extra;
  10037. const {
  10038. type
  10039. } = expression;
  10040. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10041. return false;
  10042. }
  10043. if (estree) {
  10044. if (type === "Literal") {
  10045. const {
  10046. value
  10047. } = expression;
  10048. if (typeof value === "string" || typeof value === "boolean") {
  10049. return true;
  10050. }
  10051. }
  10052. } else {
  10053. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10054. return true;
  10055. }
  10056. }
  10057. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10058. return true;
  10059. }
  10060. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10061. return true;
  10062. }
  10063. if (isPossiblyLiteralEnum(expression)) {
  10064. return true;
  10065. }
  10066. return false;
  10067. }
  10068. function isNumber(expression, estree) {
  10069. if (estree) {
  10070. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10071. }
  10072. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10073. }
  10074. function isNegativeNumber(expression, estree) {
  10075. if (expression.type === "UnaryExpression") {
  10076. const {
  10077. operator,
  10078. argument
  10079. } = expression;
  10080. if (operator === "-" && isNumber(argument, estree)) {
  10081. return true;
  10082. }
  10083. }
  10084. return false;
  10085. }
  10086. function isUncomputedMemberExpressionChain(expression) {
  10087. if (expression.type === "Identifier") return true;
  10088. if (expression.type !== "MemberExpression" || expression.computed) {
  10089. return false;
  10090. }
  10091. return isUncomputedMemberExpressionChain(expression.object);
  10092. }
  10093. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10094. ClassNameIsRequired: "A class name is required.",
  10095. UnexpectedSpace: "Unexpected space in placeholder."
  10096. });
  10097. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10098. parsePlaceholder(expectedNode) {
  10099. if (this.match(133)) {
  10100. const node = this.startNode();
  10101. this.next();
  10102. this.assertNoSpace();
  10103. node.name = super.parseIdentifier(true);
  10104. this.assertNoSpace();
  10105. this.expect(133);
  10106. return this.finishPlaceholder(node, expectedNode);
  10107. }
  10108. }
  10109. finishPlaceholder(node, expectedNode) {
  10110. let placeholder = node;
  10111. if (!placeholder.expectedNode || !placeholder.type) {
  10112. placeholder = this.finishNode(placeholder, "Placeholder");
  10113. }
  10114. placeholder.expectedNode = expectedNode;
  10115. return placeholder;
  10116. }
  10117. getTokenFromCode(code) {
  10118. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10119. this.finishOp(133, 2);
  10120. } else {
  10121. super.getTokenFromCode(code);
  10122. }
  10123. }
  10124. parseExprAtom(refExpressionErrors) {
  10125. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10126. }
  10127. parseIdentifier(liberal) {
  10128. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10129. }
  10130. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10131. if (word !== undefined) {
  10132. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10133. }
  10134. }
  10135. parseBindingAtom() {
  10136. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10137. }
  10138. isValidLVal(type, isParenthesized, binding) {
  10139. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10140. }
  10141. toAssignable(node, isLHS) {
  10142. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10143. node.expectedNode = "Pattern";
  10144. } else {
  10145. super.toAssignable(node, isLHS);
  10146. }
  10147. }
  10148. chStartsBindingIdentifier(ch, pos) {
  10149. if (super.chStartsBindingIdentifier(ch, pos)) {
  10150. return true;
  10151. }
  10152. const nextToken = this.lookahead();
  10153. if (nextToken.type === 133) {
  10154. return true;
  10155. }
  10156. return false;
  10157. }
  10158. verifyBreakContinue(node, isBreak) {
  10159. if (node.label && node.label.type === "Placeholder") return;
  10160. super.verifyBreakContinue(node, isBreak);
  10161. }
  10162. parseExpressionStatement(node, expr) {
  10163. var _expr$extra;
  10164. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10165. return super.parseExpressionStatement(node, expr);
  10166. }
  10167. if (this.match(14)) {
  10168. const stmt = node;
  10169. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10170. this.next();
  10171. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10172. return this.finishNode(stmt, "LabeledStatement");
  10173. }
  10174. this.semicolon();
  10175. const stmtPlaceholder = node;
  10176. stmtPlaceholder.name = expr.name;
  10177. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  10178. }
  10179. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10180. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10181. }
  10182. parseFunctionId(requireId) {
  10183. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10184. }
  10185. parseClass(node, isStatement, optionalId) {
  10186. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10187. this.next();
  10188. const oldStrict = this.state.strict;
  10189. const placeholder = this.parsePlaceholder("Identifier");
  10190. if (placeholder) {
  10191. if (this.match(81) || this.match(133) || this.match(5)) {
  10192. node.id = placeholder;
  10193. } else if (optionalId || !isStatement) {
  10194. node.id = null;
  10195. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10196. return this.finishNode(node, type);
  10197. } else {
  10198. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  10199. }
  10200. } else {
  10201. this.parseClassId(node, isStatement, optionalId);
  10202. }
  10203. super.parseClassSuper(node);
  10204. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10205. return this.finishNode(node, type);
  10206. }
  10207. parseExport(node, decorators) {
  10208. const placeholder = this.parsePlaceholder("Identifier");
  10209. if (!placeholder) return super.parseExport(node, decorators);
  10210. const node2 = node;
  10211. if (!this.isContextual(98) && !this.match(12)) {
  10212. node2.specifiers = [];
  10213. node2.source = null;
  10214. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10215. return this.finishNode(node2, "ExportNamedDeclaration");
  10216. }
  10217. this.expectPlugin("exportDefaultFrom");
  10218. const specifier = this.startNode();
  10219. specifier.exported = placeholder;
  10220. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10221. return super.parseExport(node2, decorators);
  10222. }
  10223. isExportDefaultSpecifier() {
  10224. if (this.match(65)) {
  10225. const next = this.nextTokenStart();
  10226. if (this.isUnparsedContextual(next, "from")) {
  10227. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  10228. return true;
  10229. }
  10230. }
  10231. }
  10232. return super.isExportDefaultSpecifier();
  10233. }
  10234. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10235. var _specifiers;
  10236. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10237. return true;
  10238. }
  10239. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10240. }
  10241. checkExport(node) {
  10242. const {
  10243. specifiers
  10244. } = node;
  10245. if (specifiers != null && specifiers.length) {
  10246. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10247. }
  10248. super.checkExport(node);
  10249. node.specifiers = specifiers;
  10250. }
  10251. parseImport(node) {
  10252. const placeholder = this.parsePlaceholder("Identifier");
  10253. if (!placeholder) return super.parseImport(node);
  10254. node.specifiers = [];
  10255. if (!this.isContextual(98) && !this.match(12)) {
  10256. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10257. this.semicolon();
  10258. return this.finishNode(node, "ImportDeclaration");
  10259. }
  10260. const specifier = this.startNodeAtNode(placeholder);
  10261. specifier.local = placeholder;
  10262. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10263. if (this.eat(12)) {
  10264. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10265. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10266. }
  10267. this.expectContextual(98);
  10268. node.source = this.parseImportSource();
  10269. this.semicolon();
  10270. return this.finishNode(node, "ImportDeclaration");
  10271. }
  10272. parseImportSource() {
  10273. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10274. }
  10275. assertNoSpace() {
  10276. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  10277. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  10278. }
  10279. }
  10280. };
  10281. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10282. parseV8Intrinsic() {
  10283. if (this.match(54)) {
  10284. const v8IntrinsicStartLoc = this.state.startLoc;
  10285. const node = this.startNode();
  10286. this.next();
  10287. if (tokenIsIdentifier(this.state.type)) {
  10288. const name = this.parseIdentifierName();
  10289. const identifier = this.createIdentifier(node, name);
  10290. identifier.type = "V8IntrinsicIdentifier";
  10291. if (this.match(10)) {
  10292. return identifier;
  10293. }
  10294. }
  10295. this.unexpected(v8IntrinsicStartLoc);
  10296. }
  10297. }
  10298. parseExprAtom(refExpressionErrors) {
  10299. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10300. }
  10301. };
  10302. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10303. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10304. function validatePlugins(pluginsMap) {
  10305. if (pluginsMap.has("decorators")) {
  10306. if (pluginsMap.has("decorators-legacy")) {
  10307. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10308. }
  10309. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  10310. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10311. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10312. }
  10313. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  10314. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10315. throw new Error("'allowCallParenthesized' must be a boolean.");
  10316. }
  10317. }
  10318. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  10319. throw new Error("Cannot combine flow and typescript plugins.");
  10320. }
  10321. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  10322. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10323. }
  10324. if (pluginsMap.has("pipelineOperator")) {
  10325. var _pluginsMap$get;
  10326. const proposal = pluginsMap.get("pipelineOperator").proposal;
  10327. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10328. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10329. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10330. }
  10331. const tupleSyntaxIsHash = ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash";
  10332. if (proposal === "hack") {
  10333. if (pluginsMap.has("placeholders")) {
  10334. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10335. }
  10336. if (pluginsMap.has("v8intrinsic")) {
  10337. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10338. }
  10339. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  10340. if (!TOPIC_TOKENS.includes(topicToken)) {
  10341. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10342. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10343. }
  10344. if (topicToken === "#" && tupleSyntaxIsHash) {
  10345. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10346. }
  10347. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10348. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  10349. }
  10350. }
  10351. if (pluginsMap.has("moduleAttributes")) {
  10352. {
  10353. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  10354. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  10355. }
  10356. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  10357. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10358. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10359. }
  10360. }
  10361. }
  10362. if (pluginsMap.has("importAssertions")) {
  10363. if (pluginsMap.has("deprecatedImportAssert")) {
  10364. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  10365. }
  10366. }
  10367. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  10368. {
  10369. pluginsMap.set("deprecatedImportAssert", {});
  10370. }
  10371. }
  10372. if (pluginsMap.has("recordAndTuple")) {
  10373. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  10374. if (syntaxType != null) {
  10375. {
  10376. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10377. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  10378. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10379. }
  10380. }
  10381. }
  10382. }
  10383. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  10384. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10385. error.missingPlugins = "doExpressions";
  10386. throw error;
  10387. }
  10388. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  10389. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10390. }
  10391. }
  10392. const mixinPlugins = {
  10393. estree,
  10394. jsx,
  10395. flow,
  10396. typescript,
  10397. v8intrinsic,
  10398. placeholders
  10399. };
  10400. const mixinPluginNames = Object.keys(mixinPlugins);
  10401. class ExpressionParser extends LValParser {
  10402. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10403. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10404. return;
  10405. }
  10406. const key = prop.key;
  10407. const name = key.type === "Identifier" ? key.name : key.value;
  10408. if (name === "__proto__") {
  10409. if (isRecord) {
  10410. this.raise(Errors.RecordNoProto, key);
  10411. return;
  10412. }
  10413. if (protoRef.used) {
  10414. if (refExpressionErrors) {
  10415. if (refExpressionErrors.doubleProtoLoc === null) {
  10416. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10417. }
  10418. } else {
  10419. this.raise(Errors.DuplicateProto, key);
  10420. }
  10421. }
  10422. protoRef.used = true;
  10423. }
  10424. }
  10425. shouldExitDescending(expr, potentialArrowAt) {
  10426. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  10427. }
  10428. getExpression() {
  10429. this.enterInitialScopes();
  10430. this.nextToken();
  10431. const expr = this.parseExpression();
  10432. if (!this.match(140)) {
  10433. this.unexpected();
  10434. }
  10435. this.finalizeRemainingComments();
  10436. expr.comments = this.comments;
  10437. expr.errors = this.state.errors;
  10438. if (this.optionFlags & 128) {
  10439. expr.tokens = this.tokens;
  10440. }
  10441. return expr;
  10442. }
  10443. parseExpression(disallowIn, refExpressionErrors) {
  10444. if (disallowIn) {
  10445. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10446. }
  10447. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10448. }
  10449. parseExpressionBase(refExpressionErrors) {
  10450. const startLoc = this.state.startLoc;
  10451. const expr = this.parseMaybeAssign(refExpressionErrors);
  10452. if (this.match(12)) {
  10453. const node = this.startNodeAt(startLoc);
  10454. node.expressions = [expr];
  10455. while (this.eat(12)) {
  10456. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10457. }
  10458. this.toReferencedList(node.expressions);
  10459. return this.finishNode(node, "SequenceExpression");
  10460. }
  10461. return expr;
  10462. }
  10463. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10464. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10465. }
  10466. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10467. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10468. }
  10469. setOptionalParametersError(refExpressionErrors, resultError) {
  10470. var _resultError$loc;
  10471. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10472. }
  10473. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10474. const startLoc = this.state.startLoc;
  10475. if (this.isContextual(108)) {
  10476. if (this.prodParam.hasYield) {
  10477. let left = this.parseYield();
  10478. if (afterLeftParse) {
  10479. left = afterLeftParse.call(this, left, startLoc);
  10480. }
  10481. return left;
  10482. }
  10483. }
  10484. let ownExpressionErrors;
  10485. if (refExpressionErrors) {
  10486. ownExpressionErrors = false;
  10487. } else {
  10488. refExpressionErrors = new ExpressionErrors();
  10489. ownExpressionErrors = true;
  10490. }
  10491. const {
  10492. type
  10493. } = this.state;
  10494. if (type === 10 || tokenIsIdentifier(type)) {
  10495. this.state.potentialArrowAt = this.state.start;
  10496. }
  10497. let left = this.parseMaybeConditional(refExpressionErrors);
  10498. if (afterLeftParse) {
  10499. left = afterLeftParse.call(this, left, startLoc);
  10500. }
  10501. if (tokenIsAssignment(this.state.type)) {
  10502. const node = this.startNodeAt(startLoc);
  10503. const operator = this.state.value;
  10504. node.operator = operator;
  10505. if (this.match(29)) {
  10506. this.toAssignable(left, true);
  10507. node.left = left;
  10508. const startIndex = startLoc.index;
  10509. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10510. refExpressionErrors.doubleProtoLoc = null;
  10511. }
  10512. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10513. refExpressionErrors.shorthandAssignLoc = null;
  10514. }
  10515. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10516. this.checkDestructuringPrivate(refExpressionErrors);
  10517. refExpressionErrors.privateKeyLoc = null;
  10518. }
  10519. } else {
  10520. node.left = left;
  10521. }
  10522. this.next();
  10523. node.right = this.parseMaybeAssign();
  10524. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"));
  10525. return node;
  10526. } else if (ownExpressionErrors) {
  10527. this.checkExpressionErrors(refExpressionErrors, true);
  10528. }
  10529. return left;
  10530. }
  10531. parseMaybeConditional(refExpressionErrors) {
  10532. const startLoc = this.state.startLoc;
  10533. const potentialArrowAt = this.state.potentialArrowAt;
  10534. const expr = this.parseExprOps(refExpressionErrors);
  10535. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10536. return expr;
  10537. }
  10538. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10539. }
  10540. parseConditional(expr, startLoc, refExpressionErrors) {
  10541. if (this.eat(17)) {
  10542. const node = this.startNodeAt(startLoc);
  10543. node.test = expr;
  10544. node.consequent = this.parseMaybeAssignAllowIn();
  10545. this.expect(14);
  10546. node.alternate = this.parseMaybeAssign();
  10547. return this.finishNode(node, "ConditionalExpression");
  10548. }
  10549. return expr;
  10550. }
  10551. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10552. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10553. }
  10554. parseExprOps(refExpressionErrors) {
  10555. const startLoc = this.state.startLoc;
  10556. const potentialArrowAt = this.state.potentialArrowAt;
  10557. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10558. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10559. return expr;
  10560. }
  10561. return this.parseExprOp(expr, startLoc, -1);
  10562. }
  10563. parseExprOp(left, leftStartLoc, minPrec) {
  10564. if (this.isPrivateName(left)) {
  10565. const value = this.getPrivateNameSV(left);
  10566. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10567. this.raise(Errors.PrivateInExpectedIn, left, {
  10568. identifierName: value
  10569. });
  10570. }
  10571. this.classScope.usePrivateName(value, left.loc.start);
  10572. }
  10573. const op = this.state.type;
  10574. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10575. let prec = tokenOperatorPrecedence(op);
  10576. if (prec > minPrec) {
  10577. if (op === 39) {
  10578. this.expectPlugin("pipelineOperator");
  10579. if (this.state.inFSharpPipelineDirectBody) {
  10580. return left;
  10581. }
  10582. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10583. }
  10584. const node = this.startNodeAt(leftStartLoc);
  10585. node.left = left;
  10586. node.operator = this.state.value;
  10587. const logical = op === 41 || op === 42;
  10588. const coalesce = op === 40;
  10589. if (coalesce) {
  10590. prec = tokenOperatorPrecedence(42);
  10591. }
  10592. this.next();
  10593. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10594. proposal: "minimal"
  10595. }])) {
  10596. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10597. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  10598. }
  10599. }
  10600. node.right = this.parseExprOpRightExpr(op, prec);
  10601. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10602. const nextOp = this.state.type;
  10603. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10604. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  10605. }
  10606. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10607. }
  10608. }
  10609. return left;
  10610. }
  10611. parseExprOpRightExpr(op, prec) {
  10612. const startLoc = this.state.startLoc;
  10613. switch (op) {
  10614. case 39:
  10615. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10616. case "hack":
  10617. return this.withTopicBindingContext(() => {
  10618. return this.parseHackPipeBody();
  10619. });
  10620. case "smart":
  10621. return this.withTopicBindingContext(() => {
  10622. if (this.prodParam.hasYield && this.isContextual(108)) {
  10623. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  10624. }
  10625. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10626. });
  10627. case "fsharp":
  10628. return this.withSoloAwaitPermittingContext(() => {
  10629. return this.parseFSharpPipelineBody(prec);
  10630. });
  10631. }
  10632. default:
  10633. return this.parseExprOpBaseRightExpr(op, prec);
  10634. }
  10635. }
  10636. parseExprOpBaseRightExpr(op, prec) {
  10637. const startLoc = this.state.startLoc;
  10638. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10639. }
  10640. parseHackPipeBody() {
  10641. var _body$extra;
  10642. const {
  10643. startLoc
  10644. } = this.state;
  10645. const body = this.parseMaybeAssign();
  10646. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10647. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10648. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  10649. type: body.type
  10650. });
  10651. }
  10652. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10653. this.raise(Errors.PipeTopicUnused, startLoc);
  10654. }
  10655. return body;
  10656. }
  10657. checkExponentialAfterUnary(node) {
  10658. if (this.match(57)) {
  10659. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  10660. }
  10661. }
  10662. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10663. const startLoc = this.state.startLoc;
  10664. const isAwait = this.isContextual(96);
  10665. if (isAwait && this.recordAwaitIfAllowed()) {
  10666. this.next();
  10667. const expr = this.parseAwait(startLoc);
  10668. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10669. return expr;
  10670. }
  10671. const update = this.match(34);
  10672. const node = this.startNode();
  10673. if (tokenIsPrefix(this.state.type)) {
  10674. node.operator = this.state.value;
  10675. node.prefix = true;
  10676. if (this.match(72)) {
  10677. this.expectPlugin("throwExpressions");
  10678. }
  10679. const isDelete = this.match(89);
  10680. this.next();
  10681. node.argument = this.parseMaybeUnary(null, true);
  10682. this.checkExpressionErrors(refExpressionErrors, true);
  10683. if (this.state.strict && isDelete) {
  10684. const arg = node.argument;
  10685. if (arg.type === "Identifier") {
  10686. this.raise(Errors.StrictDelete, node);
  10687. } else if (this.hasPropertyAsPrivateName(arg)) {
  10688. this.raise(Errors.DeletePrivateField, node);
  10689. }
  10690. }
  10691. if (!update) {
  10692. if (!sawUnary) {
  10693. this.checkExponentialAfterUnary(node);
  10694. }
  10695. return this.finishNode(node, "UnaryExpression");
  10696. }
  10697. }
  10698. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10699. if (isAwait) {
  10700. const {
  10701. type
  10702. } = this.state;
  10703. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10704. if (startsExpr && !this.isAmbiguousAwait()) {
  10705. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  10706. return this.parseAwait(startLoc);
  10707. }
  10708. }
  10709. return expr;
  10710. }
  10711. parseUpdate(node, update, refExpressionErrors) {
  10712. if (update) {
  10713. const updateExpressionNode = node;
  10714. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  10715. return node;
  10716. }
  10717. const startLoc = this.state.startLoc;
  10718. let expr = this.parseExprSubscripts(refExpressionErrors);
  10719. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10720. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10721. const node = this.startNodeAt(startLoc);
  10722. node.operator = this.state.value;
  10723. node.prefix = false;
  10724. node.argument = expr;
  10725. this.next();
  10726. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  10727. }
  10728. return expr;
  10729. }
  10730. parseExprSubscripts(refExpressionErrors) {
  10731. const startLoc = this.state.startLoc;
  10732. const potentialArrowAt = this.state.potentialArrowAt;
  10733. const expr = this.parseExprAtom(refExpressionErrors);
  10734. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10735. return expr;
  10736. }
  10737. return this.parseSubscripts(expr, startLoc);
  10738. }
  10739. parseSubscripts(base, startLoc, noCalls) {
  10740. const state = {
  10741. optionalChainMember: false,
  10742. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10743. stop: false
  10744. };
  10745. do {
  10746. base = this.parseSubscript(base, startLoc, noCalls, state);
  10747. state.maybeAsyncArrow = false;
  10748. } while (!state.stop);
  10749. return base;
  10750. }
  10751. parseSubscript(base, startLoc, noCalls, state) {
  10752. const {
  10753. type
  10754. } = this.state;
  10755. if (!noCalls && type === 15) {
  10756. return this.parseBind(base, startLoc, noCalls, state);
  10757. } else if (tokenIsTemplate(type)) {
  10758. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10759. }
  10760. let optional = false;
  10761. if (type === 18) {
  10762. if (noCalls) {
  10763. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  10764. if (this.lookaheadCharCode() === 40) {
  10765. state.stop = true;
  10766. return base;
  10767. }
  10768. }
  10769. state.optionalChainMember = optional = true;
  10770. this.next();
  10771. }
  10772. if (!noCalls && this.match(10)) {
  10773. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10774. } else {
  10775. const computed = this.eat(0);
  10776. if (computed || optional || this.eat(16)) {
  10777. return this.parseMember(base, startLoc, state, computed, optional);
  10778. } else {
  10779. state.stop = true;
  10780. return base;
  10781. }
  10782. }
  10783. }
  10784. parseMember(base, startLoc, state, computed, optional) {
  10785. const node = this.startNodeAt(startLoc);
  10786. node.object = base;
  10787. node.computed = computed;
  10788. if (computed) {
  10789. node.property = this.parseExpression();
  10790. this.expect(3);
  10791. } else if (this.match(139)) {
  10792. if (base.type === "Super") {
  10793. this.raise(Errors.SuperPrivateField, startLoc);
  10794. }
  10795. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10796. node.property = this.parsePrivateName();
  10797. } else {
  10798. node.property = this.parseIdentifier(true);
  10799. }
  10800. if (state.optionalChainMember) {
  10801. node.optional = optional;
  10802. return this.finishNode(node, "OptionalMemberExpression");
  10803. } else {
  10804. return this.finishNode(node, "MemberExpression");
  10805. }
  10806. }
  10807. parseBind(base, startLoc, noCalls, state) {
  10808. const node = this.startNodeAt(startLoc);
  10809. node.object = base;
  10810. this.next();
  10811. node.callee = this.parseNoCallExpr();
  10812. state.stop = true;
  10813. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10814. }
  10815. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10816. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10817. let refExpressionErrors = null;
  10818. this.state.maybeInArrowParameters = true;
  10819. this.next();
  10820. const node = this.startNodeAt(startLoc);
  10821. node.callee = base;
  10822. const {
  10823. maybeAsyncArrow,
  10824. optionalChainMember
  10825. } = state;
  10826. if (maybeAsyncArrow) {
  10827. this.expressionScope.enter(newAsyncArrowScope());
  10828. refExpressionErrors = new ExpressionErrors();
  10829. }
  10830. if (optionalChainMember) {
  10831. node.optional = optional;
  10832. }
  10833. if (optional) {
  10834. node.arguments = this.parseCallExpressionArguments(11);
  10835. } else {
  10836. node.arguments = this.parseCallExpressionArguments(11, base.type !== "Super", node, refExpressionErrors);
  10837. }
  10838. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10839. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10840. state.stop = true;
  10841. this.checkDestructuringPrivate(refExpressionErrors);
  10842. this.expressionScope.validateAsPattern();
  10843. this.expressionScope.exit();
  10844. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10845. } else {
  10846. if (maybeAsyncArrow) {
  10847. this.checkExpressionErrors(refExpressionErrors, true);
  10848. this.expressionScope.exit();
  10849. }
  10850. this.toReferencedArguments(finishedNode);
  10851. }
  10852. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10853. return finishedNode;
  10854. }
  10855. toReferencedArguments(node, isParenthesizedExpr) {
  10856. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10857. }
  10858. parseTaggedTemplateExpression(base, startLoc, state) {
  10859. const node = this.startNodeAt(startLoc);
  10860. node.tag = base;
  10861. node.quasi = this.parseTemplate(true);
  10862. if (state.optionalChainMember) {
  10863. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  10864. }
  10865. return this.finishNode(node, "TaggedTemplateExpression");
  10866. }
  10867. atPossibleAsyncArrow(base) {
  10868. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.offsetToSourcePos(base.start) === this.state.potentialArrowAt;
  10869. }
  10870. finishCallExpression(node, optional) {
  10871. if (node.callee.type === "Import") {
  10872. if (node.arguments.length === 0 || node.arguments.length > 2) {
  10873. this.raise(Errors.ImportCallArity, node);
  10874. } else {
  10875. for (const arg of node.arguments) {
  10876. if (arg.type === "SpreadElement") {
  10877. this.raise(Errors.ImportCallSpreadArgument, arg);
  10878. }
  10879. }
  10880. }
  10881. }
  10882. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  10883. }
  10884. parseCallExpressionArguments(close, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  10885. const elts = [];
  10886. let first = true;
  10887. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  10888. this.state.inFSharpPipelineDirectBody = false;
  10889. while (!this.eat(close)) {
  10890. if (first) {
  10891. first = false;
  10892. } else {
  10893. this.expect(12);
  10894. if (this.match(close)) {
  10895. if (nodeForExtra) {
  10896. this.addTrailingCommaExtraToNode(nodeForExtra);
  10897. }
  10898. this.next();
  10899. break;
  10900. }
  10901. }
  10902. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  10903. }
  10904. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  10905. return elts;
  10906. }
  10907. shouldParseAsyncArrow() {
  10908. return this.match(19) && !this.canInsertSemicolon();
  10909. }
  10910. parseAsyncArrowFromCallExpression(node, call) {
  10911. var _call$extra;
  10912. this.resetPreviousNodeTrailingComments(call);
  10913. this.expect(19);
  10914. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  10915. if (call.innerComments) {
  10916. setInnerComments(node, call.innerComments);
  10917. }
  10918. if (call.callee.trailingComments) {
  10919. setInnerComments(node, call.callee.trailingComments);
  10920. }
  10921. return node;
  10922. }
  10923. parseNoCallExpr() {
  10924. const startLoc = this.state.startLoc;
  10925. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  10926. }
  10927. parseExprAtom(refExpressionErrors) {
  10928. let node;
  10929. let decorators = null;
  10930. const {
  10931. type
  10932. } = this.state;
  10933. switch (type) {
  10934. case 79:
  10935. return this.parseSuper();
  10936. case 83:
  10937. node = this.startNode();
  10938. this.next();
  10939. if (this.match(16)) {
  10940. return this.parseImportMetaProperty(node);
  10941. }
  10942. if (this.match(10)) {
  10943. if (this.optionFlags & 256) {
  10944. return this.parseImportCall(node);
  10945. } else {
  10946. return this.finishNode(node, "Import");
  10947. }
  10948. } else {
  10949. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  10950. return this.finishNode(node, "Import");
  10951. }
  10952. case 78:
  10953. node = this.startNode();
  10954. this.next();
  10955. return this.finishNode(node, "ThisExpression");
  10956. case 90:
  10957. {
  10958. return this.parseDo(this.startNode(), false);
  10959. }
  10960. case 56:
  10961. case 31:
  10962. {
  10963. this.readRegexp();
  10964. return this.parseRegExpLiteral(this.state.value);
  10965. }
  10966. case 135:
  10967. return this.parseNumericLiteral(this.state.value);
  10968. case 136:
  10969. return this.parseBigIntLiteral(this.state.value);
  10970. case 134:
  10971. return this.parseStringLiteral(this.state.value);
  10972. case 84:
  10973. return this.parseNullLiteral();
  10974. case 85:
  10975. return this.parseBooleanLiteral(true);
  10976. case 86:
  10977. return this.parseBooleanLiteral(false);
  10978. case 10:
  10979. {
  10980. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  10981. return this.parseParenAndDistinguishExpression(canBeArrow);
  10982. }
  10983. case 2:
  10984. case 1:
  10985. {
  10986. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  10987. }
  10988. case 0:
  10989. {
  10990. return this.parseArrayLike(3, true, false, refExpressionErrors);
  10991. }
  10992. case 6:
  10993. case 7:
  10994. {
  10995. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  10996. }
  10997. case 5:
  10998. {
  10999. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11000. }
  11001. case 68:
  11002. return this.parseFunctionOrFunctionSent();
  11003. case 26:
  11004. decorators = this.parseDecorators();
  11005. case 80:
  11006. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11007. case 77:
  11008. return this.parseNewOrNewTarget();
  11009. case 25:
  11010. case 24:
  11011. return this.parseTemplate(false);
  11012. case 15:
  11013. {
  11014. node = this.startNode();
  11015. this.next();
  11016. node.object = null;
  11017. const callee = node.callee = this.parseNoCallExpr();
  11018. if (callee.type === "MemberExpression") {
  11019. return this.finishNode(node, "BindExpression");
  11020. } else {
  11021. throw this.raise(Errors.UnsupportedBind, callee);
  11022. }
  11023. }
  11024. case 139:
  11025. {
  11026. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  11027. identifierName: this.state.value
  11028. });
  11029. return this.parsePrivateName();
  11030. }
  11031. case 33:
  11032. {
  11033. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11034. }
  11035. case 32:
  11036. {
  11037. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11038. }
  11039. case 37:
  11040. case 38:
  11041. {
  11042. return this.parseTopicReference("hack");
  11043. }
  11044. case 44:
  11045. case 54:
  11046. case 27:
  11047. {
  11048. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11049. if (pipeProposal) {
  11050. return this.parseTopicReference(pipeProposal);
  11051. }
  11052. this.unexpected();
  11053. break;
  11054. }
  11055. case 47:
  11056. {
  11057. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11058. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11059. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11060. } else {
  11061. this.unexpected();
  11062. }
  11063. break;
  11064. }
  11065. default:
  11066. if (type === 137) {
  11067. return this.parseDecimalLiteral(this.state.value);
  11068. }
  11069. if (tokenIsIdentifier(type)) {
  11070. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11071. return this.parseModuleExpression();
  11072. }
  11073. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11074. const containsEsc = this.state.containsEsc;
  11075. const id = this.parseIdentifier();
  11076. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11077. const {
  11078. type
  11079. } = this.state;
  11080. if (type === 68) {
  11081. this.resetPreviousNodeTrailingComments(id);
  11082. this.next();
  11083. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11084. } else if (tokenIsIdentifier(type)) {
  11085. if (this.lookaheadCharCode() === 61) {
  11086. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11087. } else {
  11088. return id;
  11089. }
  11090. } else if (type === 90) {
  11091. this.resetPreviousNodeTrailingComments(id);
  11092. return this.parseDo(this.startNodeAtNode(id), true);
  11093. }
  11094. }
  11095. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11096. this.next();
  11097. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11098. }
  11099. return id;
  11100. } else {
  11101. this.unexpected();
  11102. }
  11103. }
  11104. }
  11105. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11106. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11107. if (pipeProposal) {
  11108. this.state.type = topicTokenType;
  11109. this.state.value = topicTokenValue;
  11110. this.state.pos--;
  11111. this.state.end--;
  11112. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11113. return this.parseTopicReference(pipeProposal);
  11114. } else {
  11115. this.unexpected();
  11116. }
  11117. }
  11118. parseTopicReference(pipeProposal) {
  11119. const node = this.startNode();
  11120. const startLoc = this.state.startLoc;
  11121. const tokenType = this.state.type;
  11122. this.next();
  11123. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11124. }
  11125. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11126. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11127. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11128. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11129. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, startLoc);
  11130. }
  11131. this.registerTopicReference();
  11132. return this.finishNode(node, nodeType);
  11133. } else {
  11134. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  11135. token: tokenLabelName(tokenType)
  11136. });
  11137. }
  11138. }
  11139. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11140. switch (pipeProposal) {
  11141. case "hack":
  11142. {
  11143. return this.hasPlugin(["pipelineOperator", {
  11144. topicToken: tokenLabelName(tokenType)
  11145. }]);
  11146. }
  11147. case "smart":
  11148. return tokenType === 27;
  11149. default:
  11150. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  11151. }
  11152. }
  11153. parseAsyncArrowUnaryFunction(node) {
  11154. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11155. const params = [this.parseIdentifier()];
  11156. this.prodParam.exit();
  11157. if (this.hasPrecedingLineBreak()) {
  11158. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  11159. }
  11160. this.expect(19);
  11161. return this.parseArrowExpression(node, params, true);
  11162. }
  11163. parseDo(node, isAsync) {
  11164. this.expectPlugin("doExpressions");
  11165. if (isAsync) {
  11166. this.expectPlugin("asyncDoExpressions");
  11167. }
  11168. node.async = isAsync;
  11169. this.next();
  11170. const oldLabels = this.state.labels;
  11171. this.state.labels = [];
  11172. if (isAsync) {
  11173. this.prodParam.enter(2);
  11174. node.body = this.parseBlock();
  11175. this.prodParam.exit();
  11176. } else {
  11177. node.body = this.parseBlock();
  11178. }
  11179. this.state.labels = oldLabels;
  11180. return this.finishNode(node, "DoExpression");
  11181. }
  11182. parseSuper() {
  11183. const node = this.startNode();
  11184. this.next();
  11185. if (this.match(10) && !this.scope.allowDirectSuper && !(this.optionFlags & 16)) {
  11186. this.raise(Errors.SuperNotAllowed, node);
  11187. } else if (!this.scope.allowSuper && !(this.optionFlags & 16)) {
  11188. this.raise(Errors.UnexpectedSuper, node);
  11189. }
  11190. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11191. this.raise(Errors.UnsupportedSuper, node);
  11192. }
  11193. return this.finishNode(node, "Super");
  11194. }
  11195. parsePrivateName() {
  11196. const node = this.startNode();
  11197. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11198. const name = this.state.value;
  11199. this.next();
  11200. node.id = this.createIdentifier(id, name);
  11201. return this.finishNode(node, "PrivateName");
  11202. }
  11203. parseFunctionOrFunctionSent() {
  11204. const node = this.startNode();
  11205. this.next();
  11206. if (this.prodParam.hasYield && this.match(16)) {
  11207. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11208. this.next();
  11209. if (this.match(103)) {
  11210. this.expectPlugin("functionSent");
  11211. } else if (!this.hasPlugin("functionSent")) {
  11212. this.unexpected();
  11213. }
  11214. return this.parseMetaProperty(node, meta, "sent");
  11215. }
  11216. return this.parseFunction(node);
  11217. }
  11218. parseMetaProperty(node, meta, propertyName) {
  11219. node.meta = meta;
  11220. const containsEsc = this.state.containsEsc;
  11221. node.property = this.parseIdentifier(true);
  11222. if (node.property.name !== propertyName || containsEsc) {
  11223. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  11224. target: meta.name,
  11225. onlyValidPropertyName: propertyName
  11226. });
  11227. }
  11228. return this.finishNode(node, "MetaProperty");
  11229. }
  11230. parseImportMetaProperty(node) {
  11231. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11232. this.next();
  11233. if (this.isContextual(101)) {
  11234. if (!this.inModule) {
  11235. this.raise(Errors.ImportMetaOutsideModule, id);
  11236. }
  11237. this.sawUnambiguousESM = true;
  11238. } else if (this.isContextual(105) || this.isContextual(97)) {
  11239. const isSource = this.isContextual(105);
  11240. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11241. if (!(this.optionFlags & 256)) {
  11242. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, this.state.startLoc, {
  11243. phase: this.state.value
  11244. });
  11245. }
  11246. this.next();
  11247. node.phase = isSource ? "source" : "defer";
  11248. return this.parseImportCall(node);
  11249. }
  11250. return this.parseMetaProperty(node, id, "meta");
  11251. }
  11252. parseLiteralAtNode(value, type, node) {
  11253. this.addExtra(node, "rawValue", value);
  11254. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11255. node.value = value;
  11256. this.next();
  11257. return this.finishNode(node, type);
  11258. }
  11259. parseLiteral(value, type) {
  11260. const node = this.startNode();
  11261. return this.parseLiteralAtNode(value, type, node);
  11262. }
  11263. parseStringLiteral(value) {
  11264. return this.parseLiteral(value, "StringLiteral");
  11265. }
  11266. parseNumericLiteral(value) {
  11267. return this.parseLiteral(value, "NumericLiteral");
  11268. }
  11269. parseBigIntLiteral(value) {
  11270. return this.parseLiteral(value, "BigIntLiteral");
  11271. }
  11272. parseDecimalLiteral(value) {
  11273. return this.parseLiteral(value, "DecimalLiteral");
  11274. }
  11275. parseRegExpLiteral(value) {
  11276. const node = this.startNode();
  11277. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  11278. node.pattern = value.pattern;
  11279. node.flags = value.flags;
  11280. this.next();
  11281. return this.finishNode(node, "RegExpLiteral");
  11282. }
  11283. parseBooleanLiteral(value) {
  11284. const node = this.startNode();
  11285. node.value = value;
  11286. this.next();
  11287. return this.finishNode(node, "BooleanLiteral");
  11288. }
  11289. parseNullLiteral() {
  11290. const node = this.startNode();
  11291. this.next();
  11292. return this.finishNode(node, "NullLiteral");
  11293. }
  11294. parseParenAndDistinguishExpression(canBeArrow) {
  11295. const startLoc = this.state.startLoc;
  11296. let val;
  11297. this.next();
  11298. this.expressionScope.enter(newArrowHeadScope());
  11299. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11300. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11301. this.state.maybeInArrowParameters = true;
  11302. this.state.inFSharpPipelineDirectBody = false;
  11303. const innerStartLoc = this.state.startLoc;
  11304. const exprList = [];
  11305. const refExpressionErrors = new ExpressionErrors();
  11306. let first = true;
  11307. let spreadStartLoc;
  11308. let optionalCommaStartLoc;
  11309. while (!this.match(11)) {
  11310. if (first) {
  11311. first = false;
  11312. } else {
  11313. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11314. if (this.match(11)) {
  11315. optionalCommaStartLoc = this.state.startLoc;
  11316. break;
  11317. }
  11318. }
  11319. if (this.match(21)) {
  11320. const spreadNodeStartLoc = this.state.startLoc;
  11321. spreadStartLoc = this.state.startLoc;
  11322. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11323. if (!this.checkCommaAfterRest(41)) {
  11324. break;
  11325. }
  11326. } else {
  11327. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11328. }
  11329. }
  11330. const innerEndLoc = this.state.lastTokEndLoc;
  11331. this.expect(11);
  11332. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11333. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11334. let arrowNode = this.startNodeAt(startLoc);
  11335. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11336. this.checkDestructuringPrivate(refExpressionErrors);
  11337. this.expressionScope.validateAsPattern();
  11338. this.expressionScope.exit();
  11339. this.parseArrowExpression(arrowNode, exprList, false);
  11340. return arrowNode;
  11341. }
  11342. this.expressionScope.exit();
  11343. if (!exprList.length) {
  11344. this.unexpected(this.state.lastTokStartLoc);
  11345. }
  11346. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11347. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11348. this.checkExpressionErrors(refExpressionErrors, true);
  11349. this.toReferencedListDeep(exprList, true);
  11350. if (exprList.length > 1) {
  11351. val = this.startNodeAt(innerStartLoc);
  11352. val.expressions = exprList;
  11353. this.finishNode(val, "SequenceExpression");
  11354. this.resetEndLocation(val, innerEndLoc);
  11355. } else {
  11356. val = exprList[0];
  11357. }
  11358. return this.wrapParenthesis(startLoc, val);
  11359. }
  11360. wrapParenthesis(startLoc, expression) {
  11361. if (!(this.optionFlags & 512)) {
  11362. this.addExtra(expression, "parenthesized", true);
  11363. this.addExtra(expression, "parenStart", startLoc.index);
  11364. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11365. return expression;
  11366. }
  11367. const parenExpression = this.startNodeAt(startLoc);
  11368. parenExpression.expression = expression;
  11369. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11370. }
  11371. shouldParseArrow(params) {
  11372. return !this.canInsertSemicolon();
  11373. }
  11374. parseArrow(node) {
  11375. if (this.eat(19)) {
  11376. return node;
  11377. }
  11378. }
  11379. parseParenItem(node, startLoc) {
  11380. return node;
  11381. }
  11382. parseNewOrNewTarget() {
  11383. const node = this.startNode();
  11384. this.next();
  11385. if (this.match(16)) {
  11386. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11387. this.next();
  11388. const metaProp = this.parseMetaProperty(node, meta, "target");
  11389. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !(this.optionFlags & 4)) {
  11390. this.raise(Errors.UnexpectedNewTarget, metaProp);
  11391. }
  11392. return metaProp;
  11393. }
  11394. return this.parseNew(node);
  11395. }
  11396. parseNew(node) {
  11397. this.parseNewCallee(node);
  11398. if (this.eat(10)) {
  11399. const args = this.parseExprList(11);
  11400. this.toReferencedList(args);
  11401. node.arguments = args;
  11402. } else {
  11403. node.arguments = [];
  11404. }
  11405. return this.finishNode(node, "NewExpression");
  11406. }
  11407. parseNewCallee(node) {
  11408. const isImport = this.match(83);
  11409. const callee = this.parseNoCallExpr();
  11410. node.callee = callee;
  11411. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11412. this.raise(Errors.ImportCallNotNewExpression, callee);
  11413. }
  11414. }
  11415. parseTemplateElement(isTagged) {
  11416. const {
  11417. start,
  11418. startLoc,
  11419. end,
  11420. value
  11421. } = this.state;
  11422. const elemStart = start + 1;
  11423. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11424. if (value === null) {
  11425. if (!isTagged) {
  11426. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  11427. }
  11428. }
  11429. const isTail = this.match(24);
  11430. const endOffset = isTail ? -1 : -2;
  11431. const elemEnd = end + endOffset;
  11432. elem.value = {
  11433. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11434. cooked: value === null ? null : value.slice(1, endOffset)
  11435. };
  11436. elem.tail = isTail;
  11437. this.next();
  11438. const finishedNode = this.finishNode(elem, "TemplateElement");
  11439. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11440. return finishedNode;
  11441. }
  11442. parseTemplate(isTagged) {
  11443. const node = this.startNode();
  11444. let curElt = this.parseTemplateElement(isTagged);
  11445. const quasis = [curElt];
  11446. const substitutions = [];
  11447. while (!curElt.tail) {
  11448. substitutions.push(this.parseTemplateSubstitution());
  11449. this.readTemplateContinuation();
  11450. quasis.push(curElt = this.parseTemplateElement(isTagged));
  11451. }
  11452. node.expressions = substitutions;
  11453. node.quasis = quasis;
  11454. return this.finishNode(node, "TemplateLiteral");
  11455. }
  11456. parseTemplateSubstitution() {
  11457. return this.parseExpression();
  11458. }
  11459. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11460. if (isRecord) {
  11461. this.expectPlugin("recordAndTuple");
  11462. }
  11463. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11464. this.state.inFSharpPipelineDirectBody = false;
  11465. const propHash = Object.create(null);
  11466. let first = true;
  11467. const node = this.startNode();
  11468. node.properties = [];
  11469. this.next();
  11470. while (!this.match(close)) {
  11471. if (first) {
  11472. first = false;
  11473. } else {
  11474. this.expect(12);
  11475. if (this.match(close)) {
  11476. this.addTrailingCommaExtraToNode(node);
  11477. break;
  11478. }
  11479. }
  11480. let prop;
  11481. if (isPattern) {
  11482. prop = this.parseBindingProperty();
  11483. } else {
  11484. prop = this.parsePropertyDefinition(refExpressionErrors);
  11485. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11486. }
  11487. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11488. this.raise(Errors.InvalidRecordProperty, prop);
  11489. }
  11490. {
  11491. if (prop.shorthand) {
  11492. this.addExtra(prop, "shorthand", true);
  11493. }
  11494. }
  11495. node.properties.push(prop);
  11496. }
  11497. this.next();
  11498. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11499. let type = "ObjectExpression";
  11500. if (isPattern) {
  11501. type = "ObjectPattern";
  11502. } else if (isRecord) {
  11503. type = "RecordExpression";
  11504. }
  11505. return this.finishNode(node, type);
  11506. }
  11507. addTrailingCommaExtraToNode(node) {
  11508. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  11509. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11510. }
  11511. maybeAsyncOrAccessorProp(prop) {
  11512. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11513. }
  11514. parsePropertyDefinition(refExpressionErrors) {
  11515. let decorators = [];
  11516. if (this.match(26)) {
  11517. if (this.hasPlugin("decorators")) {
  11518. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  11519. }
  11520. while (this.match(26)) {
  11521. decorators.push(this.parseDecorator());
  11522. }
  11523. }
  11524. const prop = this.startNode();
  11525. let isAsync = false;
  11526. let isAccessor = false;
  11527. let startLoc;
  11528. if (this.match(21)) {
  11529. if (decorators.length) this.unexpected();
  11530. return this.parseSpread();
  11531. }
  11532. if (decorators.length) {
  11533. prop.decorators = decorators;
  11534. decorators = [];
  11535. }
  11536. prop.method = false;
  11537. if (refExpressionErrors) {
  11538. startLoc = this.state.startLoc;
  11539. }
  11540. let isGenerator = this.eat(55);
  11541. this.parsePropertyNamePrefixOperator(prop);
  11542. const containsEsc = this.state.containsEsc;
  11543. this.parsePropertyName(prop, refExpressionErrors);
  11544. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11545. const {
  11546. key
  11547. } = prop;
  11548. const keyName = key.name;
  11549. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11550. isAsync = true;
  11551. this.resetPreviousNodeTrailingComments(key);
  11552. isGenerator = this.eat(55);
  11553. this.parsePropertyName(prop);
  11554. }
  11555. if (keyName === "get" || keyName === "set") {
  11556. isAccessor = true;
  11557. this.resetPreviousNodeTrailingComments(key);
  11558. prop.kind = keyName;
  11559. if (this.match(55)) {
  11560. isGenerator = true;
  11561. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  11562. kind: keyName
  11563. });
  11564. this.next();
  11565. }
  11566. this.parsePropertyName(prop);
  11567. }
  11568. }
  11569. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11570. }
  11571. getGetterSetterExpectedParamCount(method) {
  11572. return method.kind === "get" ? 0 : 1;
  11573. }
  11574. getObjectOrClassMethodParams(method) {
  11575. return method.params;
  11576. }
  11577. checkGetterSetterParams(method) {
  11578. var _params;
  11579. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11580. const params = this.getObjectOrClassMethodParams(method);
  11581. if (params.length !== paramCount) {
  11582. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  11583. }
  11584. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11585. this.raise(Errors.BadSetterRestParameter, method);
  11586. }
  11587. }
  11588. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11589. if (isAccessor) {
  11590. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11591. this.checkGetterSetterParams(finishedProp);
  11592. return finishedProp;
  11593. }
  11594. if (isAsync || isGenerator || this.match(10)) {
  11595. if (isPattern) this.unexpected();
  11596. prop.kind = "method";
  11597. prop.method = true;
  11598. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11599. }
  11600. }
  11601. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11602. prop.shorthand = false;
  11603. if (this.eat(14)) {
  11604. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11605. return this.finishNode(prop, "ObjectProperty");
  11606. }
  11607. if (!prop.computed && prop.key.type === "Identifier") {
  11608. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11609. if (isPattern) {
  11610. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11611. } else if (this.match(29)) {
  11612. const shorthandAssignLoc = this.state.startLoc;
  11613. if (refExpressionErrors != null) {
  11614. if (refExpressionErrors.shorthandAssignLoc === null) {
  11615. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11616. }
  11617. } else {
  11618. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11619. }
  11620. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11621. } else {
  11622. prop.value = cloneIdentifier(prop.key);
  11623. }
  11624. prop.shorthand = true;
  11625. return this.finishNode(prop, "ObjectProperty");
  11626. }
  11627. }
  11628. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11629. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11630. if (!node) this.unexpected();
  11631. return node;
  11632. }
  11633. parsePropertyName(prop, refExpressionErrors) {
  11634. if (this.eat(0)) {
  11635. prop.computed = true;
  11636. prop.key = this.parseMaybeAssignAllowIn();
  11637. this.expect(3);
  11638. } else {
  11639. const {
  11640. type,
  11641. value
  11642. } = this.state;
  11643. let key;
  11644. if (tokenIsKeywordOrIdentifier(type)) {
  11645. key = this.parseIdentifier(true);
  11646. } else {
  11647. switch (type) {
  11648. case 135:
  11649. key = this.parseNumericLiteral(value);
  11650. break;
  11651. case 134:
  11652. key = this.parseStringLiteral(value);
  11653. break;
  11654. case 136:
  11655. key = this.parseBigIntLiteral(value);
  11656. break;
  11657. case 139:
  11658. {
  11659. const privateKeyLoc = this.state.startLoc;
  11660. if (refExpressionErrors != null) {
  11661. if (refExpressionErrors.privateKeyLoc === null) {
  11662. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11663. }
  11664. } else {
  11665. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  11666. }
  11667. key = this.parsePrivateName();
  11668. break;
  11669. }
  11670. default:
  11671. if (type === 137) {
  11672. key = this.parseDecimalLiteral(value);
  11673. break;
  11674. }
  11675. this.unexpected();
  11676. }
  11677. }
  11678. prop.key = key;
  11679. if (type !== 139) {
  11680. prop.computed = false;
  11681. }
  11682. }
  11683. }
  11684. initFunction(node, isAsync) {
  11685. node.id = null;
  11686. node.generator = false;
  11687. node.async = isAsync;
  11688. }
  11689. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11690. this.initFunction(node, isAsync);
  11691. node.generator = isGenerator;
  11692. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11693. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11694. this.parseFunctionParams(node, isConstructor);
  11695. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11696. this.prodParam.exit();
  11697. this.scope.exit();
  11698. return finishedNode;
  11699. }
  11700. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11701. if (isTuple) {
  11702. this.expectPlugin("recordAndTuple");
  11703. }
  11704. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11705. this.state.inFSharpPipelineDirectBody = false;
  11706. const node = this.startNode();
  11707. this.next();
  11708. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11709. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11710. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11711. }
  11712. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11713. this.scope.enter(2 | 4);
  11714. let flags = functionFlags(isAsync, false);
  11715. if (!this.match(5) && this.prodParam.hasIn) {
  11716. flags |= 8;
  11717. }
  11718. this.prodParam.enter(flags);
  11719. this.initFunction(node, isAsync);
  11720. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11721. if (params) {
  11722. this.state.maybeInArrowParameters = true;
  11723. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11724. }
  11725. this.state.maybeInArrowParameters = false;
  11726. this.parseFunctionBody(node, true);
  11727. this.prodParam.exit();
  11728. this.scope.exit();
  11729. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11730. return this.finishNode(node, "ArrowFunctionExpression");
  11731. }
  11732. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11733. this.toAssignableList(params, trailingCommaLoc, false);
  11734. node.params = params;
  11735. }
  11736. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11737. this.parseFunctionBody(node, false, isMethod);
  11738. return this.finishNode(node, type);
  11739. }
  11740. parseFunctionBody(node, allowExpression, isMethod = false) {
  11741. const isExpression = allowExpression && !this.match(5);
  11742. this.expressionScope.enter(newExpressionScope());
  11743. if (isExpression) {
  11744. node.body = this.parseMaybeAssign();
  11745. this.checkParams(node, false, allowExpression, false);
  11746. } else {
  11747. const oldStrict = this.state.strict;
  11748. const oldLabels = this.state.labels;
  11749. this.state.labels = [];
  11750. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  11751. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11752. const nonSimple = !this.isSimpleParamList(node.params);
  11753. if (hasStrictModeDirective && nonSimple) {
  11754. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  11755. }
  11756. const strictModeChanged = !oldStrict && this.state.strict;
  11757. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11758. if (this.state.strict && node.id) {
  11759. this.checkIdentifier(node.id, 65, strictModeChanged);
  11760. }
  11761. });
  11762. this.prodParam.exit();
  11763. this.state.labels = oldLabels;
  11764. }
  11765. this.expressionScope.exit();
  11766. }
  11767. isSimpleParameter(node) {
  11768. return node.type === "Identifier";
  11769. }
  11770. isSimpleParamList(params) {
  11771. for (let i = 0, len = params.length; i < len; i++) {
  11772. if (!this.isSimpleParameter(params[i])) return false;
  11773. }
  11774. return true;
  11775. }
  11776. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11777. const checkClashes = !allowDuplicates && new Set();
  11778. const formalParameters = {
  11779. type: "FormalParameters"
  11780. };
  11781. for (const param of node.params) {
  11782. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  11783. }
  11784. }
  11785. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11786. const elts = [];
  11787. let first = true;
  11788. while (!this.eat(close)) {
  11789. if (first) {
  11790. first = false;
  11791. } else {
  11792. this.expect(12);
  11793. if (this.match(close)) {
  11794. if (nodeForExtra) {
  11795. this.addTrailingCommaExtraToNode(nodeForExtra);
  11796. }
  11797. this.next();
  11798. break;
  11799. }
  11800. }
  11801. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11802. }
  11803. return elts;
  11804. }
  11805. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11806. let elt;
  11807. if (this.match(12)) {
  11808. if (!allowEmpty) {
  11809. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  11810. unexpected: ","
  11811. });
  11812. }
  11813. elt = null;
  11814. } else if (this.match(21)) {
  11815. const spreadNodeStartLoc = this.state.startLoc;
  11816. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  11817. } else if (this.match(17)) {
  11818. this.expectPlugin("partialApplication");
  11819. if (!allowPlaceholder) {
  11820. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  11821. }
  11822. const node = this.startNode();
  11823. this.next();
  11824. elt = this.finishNode(node, "ArgumentPlaceholder");
  11825. } else {
  11826. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  11827. }
  11828. return elt;
  11829. }
  11830. parseIdentifier(liberal) {
  11831. const node = this.startNode();
  11832. const name = this.parseIdentifierName(liberal);
  11833. return this.createIdentifier(node, name);
  11834. }
  11835. createIdentifier(node, name) {
  11836. node.name = name;
  11837. node.loc.identifierName = name;
  11838. return this.finishNode(node, "Identifier");
  11839. }
  11840. parseIdentifierName(liberal) {
  11841. let name;
  11842. const {
  11843. startLoc,
  11844. type
  11845. } = this.state;
  11846. if (tokenIsKeywordOrIdentifier(type)) {
  11847. name = this.state.value;
  11848. } else {
  11849. this.unexpected();
  11850. }
  11851. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  11852. if (liberal) {
  11853. if (tokenIsKeyword) {
  11854. this.replaceToken(132);
  11855. }
  11856. } else {
  11857. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  11858. }
  11859. this.next();
  11860. return name;
  11861. }
  11862. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  11863. if (word.length > 10) {
  11864. return;
  11865. }
  11866. if (!canBeReservedWord(word)) {
  11867. return;
  11868. }
  11869. if (checkKeywords && isKeyword(word)) {
  11870. this.raise(Errors.UnexpectedKeyword, startLoc, {
  11871. keyword: word
  11872. });
  11873. return;
  11874. }
  11875. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  11876. if (reservedTest(word, this.inModule)) {
  11877. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  11878. reservedWord: word
  11879. });
  11880. return;
  11881. } else if (word === "yield") {
  11882. if (this.prodParam.hasYield) {
  11883. this.raise(Errors.YieldBindingIdentifier, startLoc);
  11884. return;
  11885. }
  11886. } else if (word === "await") {
  11887. if (this.prodParam.hasAwait) {
  11888. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  11889. return;
  11890. }
  11891. if (this.scope.inStaticBlock) {
  11892. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  11893. return;
  11894. }
  11895. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  11896. } else if (word === "arguments") {
  11897. if (this.scope.inClassAndNotInNonArrowFunction) {
  11898. this.raise(Errors.ArgumentsInClass, startLoc);
  11899. return;
  11900. }
  11901. }
  11902. }
  11903. recordAwaitIfAllowed() {
  11904. const isAwaitAllowed = this.prodParam.hasAwait || this.optionFlags & 1 && !this.scope.inFunction;
  11905. if (isAwaitAllowed && !this.scope.inFunction) {
  11906. this.state.hasTopLevelAwait = true;
  11907. }
  11908. return isAwaitAllowed;
  11909. }
  11910. parseAwait(startLoc) {
  11911. const node = this.startNodeAt(startLoc);
  11912. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  11913. if (this.eat(55)) {
  11914. this.raise(Errors.ObsoleteAwaitStar, node);
  11915. }
  11916. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  11917. if (this.isAmbiguousAwait()) {
  11918. this.ambiguousScriptDifferentAst = true;
  11919. } else {
  11920. this.sawUnambiguousESM = true;
  11921. }
  11922. }
  11923. if (!this.state.soloAwait) {
  11924. node.argument = this.parseMaybeUnary(null, true);
  11925. }
  11926. return this.finishNode(node, "AwaitExpression");
  11927. }
  11928. isAmbiguousAwait() {
  11929. if (this.hasPrecedingLineBreak()) return true;
  11930. const {
  11931. type
  11932. } = this.state;
  11933. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  11934. }
  11935. parseYield() {
  11936. const node = this.startNode();
  11937. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  11938. this.next();
  11939. let delegating = false;
  11940. let argument = null;
  11941. if (!this.hasPrecedingLineBreak()) {
  11942. delegating = this.eat(55);
  11943. switch (this.state.type) {
  11944. case 13:
  11945. case 140:
  11946. case 8:
  11947. case 11:
  11948. case 3:
  11949. case 9:
  11950. case 14:
  11951. case 12:
  11952. if (!delegating) break;
  11953. default:
  11954. argument = this.parseMaybeAssign();
  11955. }
  11956. }
  11957. node.delegate = delegating;
  11958. node.argument = argument;
  11959. return this.finishNode(node, "YieldExpression");
  11960. }
  11961. parseImportCall(node) {
  11962. this.next();
  11963. node.source = this.parseMaybeAssignAllowIn();
  11964. node.options = null;
  11965. if (this.eat(12)) {
  11966. if (!this.match(11)) {
  11967. node.options = this.parseMaybeAssignAllowIn();
  11968. if (this.eat(12) && !this.match(11)) {
  11969. do {
  11970. this.parseMaybeAssignAllowIn();
  11971. } while (this.eat(12) && !this.match(11));
  11972. this.raise(Errors.ImportCallArity, node);
  11973. }
  11974. }
  11975. }
  11976. this.expect(11);
  11977. return this.finishNode(node, "ImportExpression");
  11978. }
  11979. checkPipelineAtInfixOperator(left, leftStartLoc) {
  11980. if (this.hasPlugin(["pipelineOperator", {
  11981. proposal: "smart"
  11982. }])) {
  11983. if (left.type === "SequenceExpression") {
  11984. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  11985. }
  11986. }
  11987. }
  11988. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  11989. if (this.isSimpleReference(childExpr)) {
  11990. const bodyNode = this.startNodeAt(startLoc);
  11991. bodyNode.callee = childExpr;
  11992. return this.finishNode(bodyNode, "PipelineBareFunction");
  11993. } else {
  11994. const bodyNode = this.startNodeAt(startLoc);
  11995. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  11996. bodyNode.expression = childExpr;
  11997. return this.finishNode(bodyNode, "PipelineTopicExpression");
  11998. }
  11999. }
  12000. isSimpleReference(expression) {
  12001. switch (expression.type) {
  12002. case "MemberExpression":
  12003. return !expression.computed && this.isSimpleReference(expression.object);
  12004. case "Identifier":
  12005. return true;
  12006. default:
  12007. return false;
  12008. }
  12009. }
  12010. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12011. if (this.match(19)) {
  12012. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  12013. }
  12014. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12015. this.raise(Errors.PipelineTopicUnused, startLoc);
  12016. }
  12017. }
  12018. withTopicBindingContext(callback) {
  12019. const outerContextTopicState = this.state.topicContext;
  12020. this.state.topicContext = {
  12021. maxNumOfResolvableTopics: 1,
  12022. maxTopicIndex: null
  12023. };
  12024. try {
  12025. return callback();
  12026. } finally {
  12027. this.state.topicContext = outerContextTopicState;
  12028. }
  12029. }
  12030. withSmartMixTopicForbiddingContext(callback) {
  12031. if (this.hasPlugin(["pipelineOperator", {
  12032. proposal: "smart"
  12033. }])) {
  12034. const outerContextTopicState = this.state.topicContext;
  12035. this.state.topicContext = {
  12036. maxNumOfResolvableTopics: 0,
  12037. maxTopicIndex: null
  12038. };
  12039. try {
  12040. return callback();
  12041. } finally {
  12042. this.state.topicContext = outerContextTopicState;
  12043. }
  12044. } else {
  12045. return callback();
  12046. }
  12047. }
  12048. withSoloAwaitPermittingContext(callback) {
  12049. const outerContextSoloAwaitState = this.state.soloAwait;
  12050. this.state.soloAwait = true;
  12051. try {
  12052. return callback();
  12053. } finally {
  12054. this.state.soloAwait = outerContextSoloAwaitState;
  12055. }
  12056. }
  12057. allowInAnd(callback) {
  12058. const flags = this.prodParam.currentFlags();
  12059. const prodParamToSet = 8 & ~flags;
  12060. if (prodParamToSet) {
  12061. this.prodParam.enter(flags | 8);
  12062. try {
  12063. return callback();
  12064. } finally {
  12065. this.prodParam.exit();
  12066. }
  12067. }
  12068. return callback();
  12069. }
  12070. disallowInAnd(callback) {
  12071. const flags = this.prodParam.currentFlags();
  12072. const prodParamToClear = 8 & flags;
  12073. if (prodParamToClear) {
  12074. this.prodParam.enter(flags & ~8);
  12075. try {
  12076. return callback();
  12077. } finally {
  12078. this.prodParam.exit();
  12079. }
  12080. }
  12081. return callback();
  12082. }
  12083. registerTopicReference() {
  12084. this.state.topicContext.maxTopicIndex = 0;
  12085. }
  12086. topicReferenceIsAllowedInCurrentContext() {
  12087. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12088. }
  12089. topicReferenceWasUsedInCurrentContext() {
  12090. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12091. }
  12092. parseFSharpPipelineBody(prec) {
  12093. const startLoc = this.state.startLoc;
  12094. this.state.potentialArrowAt = this.state.start;
  12095. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12096. this.state.inFSharpPipelineDirectBody = true;
  12097. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12098. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12099. return ret;
  12100. }
  12101. parseModuleExpression() {
  12102. this.expectPlugin("moduleBlocks");
  12103. const node = this.startNode();
  12104. this.next();
  12105. if (!this.match(5)) {
  12106. this.unexpected(null, 5);
  12107. }
  12108. const program = this.startNodeAt(this.state.endLoc);
  12109. this.next();
  12110. const revertScopes = this.initializeScopes(true);
  12111. this.enterInitialScopes();
  12112. try {
  12113. node.body = this.parseProgram(program, 8, "module");
  12114. } finally {
  12115. revertScopes();
  12116. }
  12117. return this.finishNode(node, "ModuleExpression");
  12118. }
  12119. parsePropertyNamePrefixOperator(prop) {}
  12120. }
  12121. const loopLabel = {
  12122. kind: 1
  12123. },
  12124. switchLabel = {
  12125. kind: 2
  12126. };
  12127. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12128. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12129. function babel7CompatTokens(tokens, input, startIndex) {
  12130. for (let i = 0; i < tokens.length; i++) {
  12131. const token = tokens[i];
  12132. const {
  12133. type
  12134. } = token;
  12135. if (typeof type === "number") {
  12136. {
  12137. if (type === 139) {
  12138. const {
  12139. loc,
  12140. start,
  12141. value,
  12142. end
  12143. } = token;
  12144. const hashEndPos = start + 1;
  12145. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12146. tokens.splice(i, 1, new Token({
  12147. type: getExportedToken(27),
  12148. value: "#",
  12149. start: start,
  12150. end: hashEndPos,
  12151. startLoc: loc.start,
  12152. endLoc: hashEndLoc
  12153. }), new Token({
  12154. type: getExportedToken(132),
  12155. value: value,
  12156. start: hashEndPos,
  12157. end: end,
  12158. startLoc: hashEndLoc,
  12159. endLoc: loc.end
  12160. }));
  12161. i++;
  12162. continue;
  12163. }
  12164. if (tokenIsTemplate(type)) {
  12165. const {
  12166. loc,
  12167. start,
  12168. value,
  12169. end
  12170. } = token;
  12171. const backquoteEnd = start + 1;
  12172. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12173. let startToken;
  12174. if (input.charCodeAt(start - startIndex) === 96) {
  12175. startToken = new Token({
  12176. type: getExportedToken(22),
  12177. value: "`",
  12178. start: start,
  12179. end: backquoteEnd,
  12180. startLoc: loc.start,
  12181. endLoc: backquoteEndLoc
  12182. });
  12183. } else {
  12184. startToken = new Token({
  12185. type: getExportedToken(8),
  12186. value: "}",
  12187. start: start,
  12188. end: backquoteEnd,
  12189. startLoc: loc.start,
  12190. endLoc: backquoteEndLoc
  12191. });
  12192. }
  12193. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12194. if (type === 24) {
  12195. templateElementEnd = end - 1;
  12196. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12197. templateValue = value === null ? null : value.slice(1, -1);
  12198. endToken = new Token({
  12199. type: getExportedToken(22),
  12200. value: "`",
  12201. start: templateElementEnd,
  12202. end: end,
  12203. startLoc: templateElementEndLoc,
  12204. endLoc: loc.end
  12205. });
  12206. } else {
  12207. templateElementEnd = end - 2;
  12208. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12209. templateValue = value === null ? null : value.slice(1, -2);
  12210. endToken = new Token({
  12211. type: getExportedToken(23),
  12212. value: "${",
  12213. start: templateElementEnd,
  12214. end: end,
  12215. startLoc: templateElementEndLoc,
  12216. endLoc: loc.end
  12217. });
  12218. }
  12219. tokens.splice(i, 1, startToken, new Token({
  12220. type: getExportedToken(20),
  12221. value: templateValue,
  12222. start: backquoteEnd,
  12223. end: templateElementEnd,
  12224. startLoc: backquoteEndLoc,
  12225. endLoc: templateElementEndLoc
  12226. }), endToken);
  12227. i += 2;
  12228. continue;
  12229. }
  12230. }
  12231. token.type = getExportedToken(type);
  12232. }
  12233. }
  12234. return tokens;
  12235. }
  12236. class StatementParser extends ExpressionParser {
  12237. parseTopLevel(file, program) {
  12238. file.program = this.parseProgram(program);
  12239. file.comments = this.comments;
  12240. if (this.optionFlags & 128) {
  12241. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  12242. }
  12243. return this.finishNode(file, "File");
  12244. }
  12245. parseProgram(program, end = 140, sourceType = this.options.sourceType) {
  12246. program.sourceType = sourceType;
  12247. program.interpreter = this.parseInterpreterDirective();
  12248. this.parseBlockBody(program, true, true, end);
  12249. if (this.inModule) {
  12250. if (!(this.optionFlags & 32) && this.scope.undefinedExports.size > 0) {
  12251. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12252. this.raise(Errors.ModuleExportUndefined, at, {
  12253. localName
  12254. });
  12255. }
  12256. }
  12257. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  12258. }
  12259. let finishedProgram;
  12260. if (end === 140) {
  12261. finishedProgram = this.finishNode(program, "Program");
  12262. } else {
  12263. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12264. }
  12265. return finishedProgram;
  12266. }
  12267. stmtToDirective(stmt) {
  12268. const directive = stmt;
  12269. directive.type = "Directive";
  12270. directive.value = directive.expression;
  12271. delete directive.expression;
  12272. const directiveLiteral = directive.value;
  12273. const expressionValue = directiveLiteral.value;
  12274. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  12275. const val = directiveLiteral.value = raw.slice(1, -1);
  12276. this.addExtra(directiveLiteral, "raw", raw);
  12277. this.addExtra(directiveLiteral, "rawValue", val);
  12278. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12279. directiveLiteral.type = "DirectiveLiteral";
  12280. return directive;
  12281. }
  12282. parseInterpreterDirective() {
  12283. if (!this.match(28)) {
  12284. return null;
  12285. }
  12286. const node = this.startNode();
  12287. node.value = this.state.value;
  12288. this.next();
  12289. return this.finishNode(node, "InterpreterDirective");
  12290. }
  12291. isLet() {
  12292. if (!this.isContextual(100)) {
  12293. return false;
  12294. }
  12295. return this.hasFollowingBindingAtom();
  12296. }
  12297. chStartsBindingIdentifier(ch, pos) {
  12298. if (isIdentifierStart(ch)) {
  12299. keywordRelationalOperator.lastIndex = pos;
  12300. if (keywordRelationalOperator.test(this.input)) {
  12301. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12302. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12303. return false;
  12304. }
  12305. }
  12306. return true;
  12307. } else if (ch === 92) {
  12308. return true;
  12309. } else {
  12310. return false;
  12311. }
  12312. }
  12313. chStartsBindingPattern(ch) {
  12314. return ch === 91 || ch === 123;
  12315. }
  12316. hasFollowingBindingAtom() {
  12317. const next = this.nextTokenStart();
  12318. const nextCh = this.codePointAtPos(next);
  12319. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12320. }
  12321. hasInLineFollowingBindingIdentifierOrBrace() {
  12322. const next = this.nextTokenInLineStart();
  12323. const nextCh = this.codePointAtPos(next);
  12324. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  12325. }
  12326. startsUsingForOf() {
  12327. const {
  12328. type,
  12329. containsEsc
  12330. } = this.lookahead();
  12331. if (type === 102 && !containsEsc) {
  12332. return false;
  12333. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12334. this.expectPlugin("explicitResourceManagement");
  12335. return true;
  12336. }
  12337. }
  12338. startsAwaitUsing() {
  12339. let next = this.nextTokenInLineStart();
  12340. if (this.isUnparsedContextual(next, "using")) {
  12341. next = this.nextTokenInLineStartSince(next + 5);
  12342. const nextCh = this.codePointAtPos(next);
  12343. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12344. this.expectPlugin("explicitResourceManagement");
  12345. return true;
  12346. }
  12347. }
  12348. return false;
  12349. }
  12350. parseModuleItem() {
  12351. return this.parseStatementLike(1 | 2 | 4 | 8);
  12352. }
  12353. parseStatementListItem() {
  12354. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12355. }
  12356. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12357. let flags = 0;
  12358. if (this.options.annexB && !this.state.strict) {
  12359. flags |= 4;
  12360. if (allowLabeledFunction) {
  12361. flags |= 8;
  12362. }
  12363. }
  12364. return this.parseStatementLike(flags);
  12365. }
  12366. parseStatement() {
  12367. return this.parseStatementLike(0);
  12368. }
  12369. parseStatementLike(flags) {
  12370. let decorators = null;
  12371. if (this.match(26)) {
  12372. decorators = this.parseDecorators(true);
  12373. }
  12374. return this.parseStatementContent(flags, decorators);
  12375. }
  12376. parseStatementContent(flags, decorators) {
  12377. const startType = this.state.type;
  12378. const node = this.startNode();
  12379. const allowDeclaration = !!(flags & 2);
  12380. const allowFunctionDeclaration = !!(flags & 4);
  12381. const topLevel = flags & 1;
  12382. switch (startType) {
  12383. case 60:
  12384. return this.parseBreakContinueStatement(node, true);
  12385. case 63:
  12386. return this.parseBreakContinueStatement(node, false);
  12387. case 64:
  12388. return this.parseDebuggerStatement(node);
  12389. case 90:
  12390. return this.parseDoWhileStatement(node);
  12391. case 91:
  12392. return this.parseForStatement(node);
  12393. case 68:
  12394. if (this.lookaheadCharCode() === 46) break;
  12395. if (!allowFunctionDeclaration) {
  12396. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  12397. }
  12398. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12399. case 80:
  12400. if (!allowDeclaration) this.unexpected();
  12401. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12402. case 69:
  12403. return this.parseIfStatement(node);
  12404. case 70:
  12405. return this.parseReturnStatement(node);
  12406. case 71:
  12407. return this.parseSwitchStatement(node);
  12408. case 72:
  12409. return this.parseThrowStatement(node);
  12410. case 73:
  12411. return this.parseTryStatement(node);
  12412. case 96:
  12413. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12414. if (!this.recordAwaitIfAllowed()) {
  12415. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  12416. } else if (!allowDeclaration) {
  12417. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  12418. }
  12419. this.next();
  12420. return this.parseVarStatement(node, "await using");
  12421. }
  12422. break;
  12423. case 107:
  12424. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  12425. break;
  12426. }
  12427. this.expectPlugin("explicitResourceManagement");
  12428. if (!this.scope.inModule && this.scope.inTopLevel) {
  12429. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  12430. } else if (!allowDeclaration) {
  12431. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12432. }
  12433. return this.parseVarStatement(node, "using");
  12434. case 100:
  12435. {
  12436. if (this.state.containsEsc) {
  12437. break;
  12438. }
  12439. const next = this.nextTokenStart();
  12440. const nextCh = this.codePointAtPos(next);
  12441. if (nextCh !== 91) {
  12442. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12443. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12444. break;
  12445. }
  12446. }
  12447. }
  12448. case 75:
  12449. {
  12450. if (!allowDeclaration) {
  12451. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  12452. }
  12453. }
  12454. case 74:
  12455. {
  12456. const kind = this.state.value;
  12457. return this.parseVarStatement(node, kind);
  12458. }
  12459. case 92:
  12460. return this.parseWhileStatement(node);
  12461. case 76:
  12462. return this.parseWithStatement(node);
  12463. case 5:
  12464. return this.parseBlock();
  12465. case 13:
  12466. return this.parseEmptyStatement(node);
  12467. case 83:
  12468. {
  12469. const nextTokenCharCode = this.lookaheadCharCode();
  12470. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12471. break;
  12472. }
  12473. }
  12474. case 82:
  12475. {
  12476. if (!(this.optionFlags & 8) && !topLevel) {
  12477. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  12478. }
  12479. this.next();
  12480. let result;
  12481. if (startType === 83) {
  12482. result = this.parseImport(node);
  12483. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12484. this.sawUnambiguousESM = true;
  12485. }
  12486. } else {
  12487. result = this.parseExport(node, decorators);
  12488. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12489. this.sawUnambiguousESM = true;
  12490. }
  12491. }
  12492. this.assertModuleNodeAllowed(result);
  12493. return result;
  12494. }
  12495. default:
  12496. {
  12497. if (this.isAsyncFunction()) {
  12498. if (!allowDeclaration) {
  12499. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  12500. }
  12501. this.next();
  12502. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12503. }
  12504. }
  12505. }
  12506. const maybeName = this.state.value;
  12507. const expr = this.parseExpression();
  12508. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  12509. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12510. } else {
  12511. return this.parseExpressionStatement(node, expr, decorators);
  12512. }
  12513. }
  12514. assertModuleNodeAllowed(node) {
  12515. if (!(this.optionFlags & 8) && !this.inModule) {
  12516. this.raise(Errors.ImportOutsideModule, node);
  12517. }
  12518. }
  12519. decoratorsEnabledBeforeExport() {
  12520. if (this.hasPlugin("decorators-legacy")) return true;
  12521. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12522. }
  12523. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12524. if (maybeDecorators) {
  12525. var _classNode$decorators;
  12526. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  12527. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12528. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  12529. }
  12530. classNode.decorators.unshift(...maybeDecorators);
  12531. } else {
  12532. classNode.decorators = maybeDecorators;
  12533. }
  12534. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12535. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12536. }
  12537. return classNode;
  12538. }
  12539. canHaveLeadingDecorator() {
  12540. return this.match(80);
  12541. }
  12542. parseDecorators(allowExport) {
  12543. const decorators = [];
  12544. do {
  12545. decorators.push(this.parseDecorator());
  12546. } while (this.match(26));
  12547. if (this.match(82)) {
  12548. if (!allowExport) {
  12549. this.unexpected();
  12550. }
  12551. if (!this.decoratorsEnabledBeforeExport()) {
  12552. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  12553. }
  12554. } else if (!this.canHaveLeadingDecorator()) {
  12555. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  12556. }
  12557. return decorators;
  12558. }
  12559. parseDecorator() {
  12560. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12561. const node = this.startNode();
  12562. this.next();
  12563. if (this.hasPlugin("decorators")) {
  12564. const startLoc = this.state.startLoc;
  12565. let expr;
  12566. if (this.match(10)) {
  12567. const startLoc = this.state.startLoc;
  12568. this.next();
  12569. expr = this.parseExpression();
  12570. this.expect(11);
  12571. expr = this.wrapParenthesis(startLoc, expr);
  12572. const paramsStartLoc = this.state.startLoc;
  12573. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12574. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12575. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  12576. }
  12577. } else {
  12578. expr = this.parseIdentifier(false);
  12579. while (this.eat(16)) {
  12580. const node = this.startNodeAt(startLoc);
  12581. node.object = expr;
  12582. if (this.match(139)) {
  12583. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12584. node.property = this.parsePrivateName();
  12585. } else {
  12586. node.property = this.parseIdentifier(true);
  12587. }
  12588. node.computed = false;
  12589. expr = this.finishNode(node, "MemberExpression");
  12590. }
  12591. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  12592. }
  12593. } else {
  12594. node.expression = this.parseExprSubscripts();
  12595. }
  12596. return this.finishNode(node, "Decorator");
  12597. }
  12598. parseMaybeDecoratorArguments(expr, startLoc) {
  12599. if (this.eat(10)) {
  12600. const node = this.startNodeAt(startLoc);
  12601. node.callee = expr;
  12602. node.arguments = this.parseCallExpressionArguments(11);
  12603. this.toReferencedList(node.arguments);
  12604. return this.finishNode(node, "CallExpression");
  12605. }
  12606. return expr;
  12607. }
  12608. parseBreakContinueStatement(node, isBreak) {
  12609. this.next();
  12610. if (this.isLineTerminator()) {
  12611. node.label = null;
  12612. } else {
  12613. node.label = this.parseIdentifier();
  12614. this.semicolon();
  12615. }
  12616. this.verifyBreakContinue(node, isBreak);
  12617. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12618. }
  12619. verifyBreakContinue(node, isBreak) {
  12620. let i;
  12621. for (i = 0; i < this.state.labels.length; ++i) {
  12622. const lab = this.state.labels[i];
  12623. if (node.label == null || lab.name === node.label.name) {
  12624. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  12625. break;
  12626. }
  12627. if (node.label && isBreak) break;
  12628. }
  12629. }
  12630. if (i === this.state.labels.length) {
  12631. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12632. this.raise(Errors.IllegalBreakContinue, node, {
  12633. type
  12634. });
  12635. }
  12636. }
  12637. parseDebuggerStatement(node) {
  12638. this.next();
  12639. this.semicolon();
  12640. return this.finishNode(node, "DebuggerStatement");
  12641. }
  12642. parseHeaderExpression() {
  12643. this.expect(10);
  12644. const val = this.parseExpression();
  12645. this.expect(11);
  12646. return val;
  12647. }
  12648. parseDoWhileStatement(node) {
  12649. this.next();
  12650. this.state.labels.push(loopLabel);
  12651. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12652. this.state.labels.pop();
  12653. this.expect(92);
  12654. node.test = this.parseHeaderExpression();
  12655. this.eat(13);
  12656. return this.finishNode(node, "DoWhileStatement");
  12657. }
  12658. parseForStatement(node) {
  12659. this.next();
  12660. this.state.labels.push(loopLabel);
  12661. let awaitAt = null;
  12662. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  12663. awaitAt = this.state.startLoc;
  12664. this.next();
  12665. }
  12666. this.scope.enter(0);
  12667. this.expect(10);
  12668. if (this.match(13)) {
  12669. if (awaitAt !== null) {
  12670. this.unexpected(awaitAt);
  12671. }
  12672. return this.parseFor(node, null);
  12673. }
  12674. const startsWithLet = this.isContextual(100);
  12675. {
  12676. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12677. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.startsUsingForOf();
  12678. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12679. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12680. const initNode = this.startNode();
  12681. let kind;
  12682. if (startsWithAwaitUsing) {
  12683. kind = "await using";
  12684. if (!this.recordAwaitIfAllowed()) {
  12685. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  12686. }
  12687. this.next();
  12688. } else {
  12689. kind = this.state.value;
  12690. }
  12691. this.next();
  12692. this.parseVar(initNode, true, kind);
  12693. const init = this.finishNode(initNode, "VariableDeclaration");
  12694. const isForIn = this.match(58);
  12695. if (isForIn && starsWithUsingDeclaration) {
  12696. this.raise(Errors.ForInUsing, init);
  12697. }
  12698. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  12699. return this.parseForIn(node, init, awaitAt);
  12700. }
  12701. if (awaitAt !== null) {
  12702. this.unexpected(awaitAt);
  12703. }
  12704. return this.parseFor(node, init);
  12705. }
  12706. }
  12707. const startsWithAsync = this.isContextual(95);
  12708. const refExpressionErrors = new ExpressionErrors();
  12709. const init = this.parseExpression(true, refExpressionErrors);
  12710. const isForOf = this.isContextual(102);
  12711. if (isForOf) {
  12712. if (startsWithLet) {
  12713. this.raise(Errors.ForOfLet, init);
  12714. }
  12715. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12716. this.raise(Errors.ForOfAsync, init);
  12717. }
  12718. }
  12719. if (isForOf || this.match(58)) {
  12720. this.checkDestructuringPrivate(refExpressionErrors);
  12721. this.toAssignable(init, true);
  12722. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12723. this.checkLVal(init, {
  12724. type
  12725. });
  12726. return this.parseForIn(node, init, awaitAt);
  12727. } else {
  12728. this.checkExpressionErrors(refExpressionErrors, true);
  12729. }
  12730. if (awaitAt !== null) {
  12731. this.unexpected(awaitAt);
  12732. }
  12733. return this.parseFor(node, init);
  12734. }
  12735. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12736. this.next();
  12737. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12738. }
  12739. parseIfStatement(node) {
  12740. this.next();
  12741. node.test = this.parseHeaderExpression();
  12742. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12743. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12744. return this.finishNode(node, "IfStatement");
  12745. }
  12746. parseReturnStatement(node) {
  12747. if (!this.prodParam.hasReturn && !(this.optionFlags & 2)) {
  12748. this.raise(Errors.IllegalReturn, this.state.startLoc);
  12749. }
  12750. this.next();
  12751. if (this.isLineTerminator()) {
  12752. node.argument = null;
  12753. } else {
  12754. node.argument = this.parseExpression();
  12755. this.semicolon();
  12756. }
  12757. return this.finishNode(node, "ReturnStatement");
  12758. }
  12759. parseSwitchStatement(node) {
  12760. this.next();
  12761. node.discriminant = this.parseHeaderExpression();
  12762. const cases = node.cases = [];
  12763. this.expect(5);
  12764. this.state.labels.push(switchLabel);
  12765. this.scope.enter(0);
  12766. let cur;
  12767. for (let sawDefault; !this.match(8);) {
  12768. if (this.match(61) || this.match(65)) {
  12769. const isCase = this.match(61);
  12770. if (cur) this.finishNode(cur, "SwitchCase");
  12771. cases.push(cur = this.startNode());
  12772. cur.consequent = [];
  12773. this.next();
  12774. if (isCase) {
  12775. cur.test = this.parseExpression();
  12776. } else {
  12777. if (sawDefault) {
  12778. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  12779. }
  12780. sawDefault = true;
  12781. cur.test = null;
  12782. }
  12783. this.expect(14);
  12784. } else {
  12785. if (cur) {
  12786. cur.consequent.push(this.parseStatementListItem());
  12787. } else {
  12788. this.unexpected();
  12789. }
  12790. }
  12791. }
  12792. this.scope.exit();
  12793. if (cur) this.finishNode(cur, "SwitchCase");
  12794. this.next();
  12795. this.state.labels.pop();
  12796. return this.finishNode(node, "SwitchStatement");
  12797. }
  12798. parseThrowStatement(node) {
  12799. this.next();
  12800. if (this.hasPrecedingLineBreak()) {
  12801. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  12802. }
  12803. node.argument = this.parseExpression();
  12804. this.semicolon();
  12805. return this.finishNode(node, "ThrowStatement");
  12806. }
  12807. parseCatchClauseParam() {
  12808. const param = this.parseBindingAtom();
  12809. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  12810. this.checkLVal(param, {
  12811. type: "CatchClause"
  12812. }, 9);
  12813. return param;
  12814. }
  12815. parseTryStatement(node) {
  12816. this.next();
  12817. node.block = this.parseBlock();
  12818. node.handler = null;
  12819. if (this.match(62)) {
  12820. const clause = this.startNode();
  12821. this.next();
  12822. if (this.match(10)) {
  12823. this.expect(10);
  12824. clause.param = this.parseCatchClauseParam();
  12825. this.expect(11);
  12826. } else {
  12827. clause.param = null;
  12828. this.scope.enter(0);
  12829. }
  12830. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  12831. this.scope.exit();
  12832. node.handler = this.finishNode(clause, "CatchClause");
  12833. }
  12834. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  12835. if (!node.handler && !node.finalizer) {
  12836. this.raise(Errors.NoCatchOrFinally, node);
  12837. }
  12838. return this.finishNode(node, "TryStatement");
  12839. }
  12840. parseVarStatement(node, kind, allowMissingInitializer = false) {
  12841. this.next();
  12842. this.parseVar(node, false, kind, allowMissingInitializer);
  12843. this.semicolon();
  12844. return this.finishNode(node, "VariableDeclaration");
  12845. }
  12846. parseWhileStatement(node) {
  12847. this.next();
  12848. node.test = this.parseHeaderExpression();
  12849. this.state.labels.push(loopLabel);
  12850. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12851. this.state.labels.pop();
  12852. return this.finishNode(node, "WhileStatement");
  12853. }
  12854. parseWithStatement(node) {
  12855. if (this.state.strict) {
  12856. this.raise(Errors.StrictWith, this.state.startLoc);
  12857. }
  12858. this.next();
  12859. node.object = this.parseHeaderExpression();
  12860. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12861. return this.finishNode(node, "WithStatement");
  12862. }
  12863. parseEmptyStatement(node) {
  12864. this.next();
  12865. return this.finishNode(node, "EmptyStatement");
  12866. }
  12867. parseLabeledStatement(node, maybeName, expr, flags) {
  12868. for (const label of this.state.labels) {
  12869. if (label.name === maybeName) {
  12870. this.raise(Errors.LabelRedeclaration, expr, {
  12871. labelName: maybeName
  12872. });
  12873. }
  12874. }
  12875. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  12876. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  12877. const label = this.state.labels[i];
  12878. if (label.statementStart === node.start) {
  12879. label.statementStart = this.sourceToOffsetPos(this.state.start);
  12880. label.kind = kind;
  12881. } else {
  12882. break;
  12883. }
  12884. }
  12885. this.state.labels.push({
  12886. name: maybeName,
  12887. kind: kind,
  12888. statementStart: this.sourceToOffsetPos(this.state.start)
  12889. });
  12890. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  12891. this.state.labels.pop();
  12892. node.label = expr;
  12893. return this.finishNode(node, "LabeledStatement");
  12894. }
  12895. parseExpressionStatement(node, expr, decorators) {
  12896. node.expression = expr;
  12897. this.semicolon();
  12898. return this.finishNode(node, "ExpressionStatement");
  12899. }
  12900. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  12901. const node = this.startNode();
  12902. if (allowDirectives) {
  12903. this.state.strictErrors.clear();
  12904. }
  12905. this.expect(5);
  12906. if (createNewLexicalScope) {
  12907. this.scope.enter(0);
  12908. }
  12909. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  12910. if (createNewLexicalScope) {
  12911. this.scope.exit();
  12912. }
  12913. return this.finishNode(node, "BlockStatement");
  12914. }
  12915. isValidDirective(stmt) {
  12916. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  12917. }
  12918. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  12919. const body = node.body = [];
  12920. const directives = node.directives = [];
  12921. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  12922. }
  12923. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  12924. const oldStrict = this.state.strict;
  12925. let hasStrictModeDirective = false;
  12926. let parsedNonDirective = false;
  12927. while (!this.match(end)) {
  12928. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  12929. if (directives && !parsedNonDirective) {
  12930. if (this.isValidDirective(stmt)) {
  12931. const directive = this.stmtToDirective(stmt);
  12932. directives.push(directive);
  12933. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  12934. hasStrictModeDirective = true;
  12935. this.setStrict(true);
  12936. }
  12937. continue;
  12938. }
  12939. parsedNonDirective = true;
  12940. this.state.strictErrors.clear();
  12941. }
  12942. body.push(stmt);
  12943. }
  12944. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  12945. if (!oldStrict) {
  12946. this.setStrict(false);
  12947. }
  12948. this.next();
  12949. }
  12950. parseFor(node, init) {
  12951. node.init = init;
  12952. this.semicolon(false);
  12953. node.test = this.match(13) ? null : this.parseExpression();
  12954. this.semicolon(false);
  12955. node.update = this.match(11) ? null : this.parseExpression();
  12956. this.expect(11);
  12957. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12958. this.scope.exit();
  12959. this.state.labels.pop();
  12960. return this.finishNode(node, "ForStatement");
  12961. }
  12962. parseForIn(node, init, awaitAt) {
  12963. const isForIn = this.match(58);
  12964. this.next();
  12965. if (isForIn) {
  12966. if (awaitAt !== null) this.unexpected(awaitAt);
  12967. } else {
  12968. node.await = awaitAt !== null;
  12969. }
  12970. if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || !this.options.annexB || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
  12971. this.raise(Errors.ForInOfLoopInitializer, init, {
  12972. type: isForIn ? "ForInStatement" : "ForOfStatement"
  12973. });
  12974. }
  12975. if (init.type === "AssignmentPattern") {
  12976. this.raise(Errors.InvalidLhs, init, {
  12977. ancestor: {
  12978. type: "ForStatement"
  12979. }
  12980. });
  12981. }
  12982. node.left = init;
  12983. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  12984. this.expect(11);
  12985. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12986. this.scope.exit();
  12987. this.state.labels.pop();
  12988. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  12989. }
  12990. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  12991. const declarations = node.declarations = [];
  12992. node.kind = kind;
  12993. for (;;) {
  12994. const decl = this.startNode();
  12995. this.parseVarId(decl, kind);
  12996. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  12997. if (decl.init === null && !allowMissingInitializer) {
  12998. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  12999. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13000. kind: "destructuring"
  13001. });
  13002. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  13003. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  13004. kind
  13005. });
  13006. }
  13007. }
  13008. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13009. if (!this.eat(12)) break;
  13010. }
  13011. return node;
  13012. }
  13013. parseVarId(decl, kind) {
  13014. const id = this.parseBindingAtom();
  13015. if (kind === "using" || kind === "await using") {
  13016. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  13017. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  13018. }
  13019. }
  13020. this.checkLVal(id, {
  13021. type: "VariableDeclarator"
  13022. }, kind === "var" ? 5 : 8201);
  13023. decl.id = id;
  13024. }
  13025. parseAsyncFunctionExpression(node) {
  13026. return this.parseFunction(node, 8);
  13027. }
  13028. parseFunction(node, flags = 0) {
  13029. const hangingDeclaration = flags & 2;
  13030. const isDeclaration = !!(flags & 1);
  13031. const requireId = isDeclaration && !(flags & 4);
  13032. const isAsync = !!(flags & 8);
  13033. this.initFunction(node, isAsync);
  13034. if (this.match(55)) {
  13035. if (hangingDeclaration) {
  13036. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  13037. }
  13038. this.next();
  13039. node.generator = true;
  13040. }
  13041. if (isDeclaration) {
  13042. node.id = this.parseFunctionId(requireId);
  13043. }
  13044. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13045. this.state.maybeInArrowParameters = false;
  13046. this.scope.enter(2);
  13047. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13048. if (!isDeclaration) {
  13049. node.id = this.parseFunctionId();
  13050. }
  13051. this.parseFunctionParams(node, false);
  13052. this.withSmartMixTopicForbiddingContext(() => {
  13053. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13054. });
  13055. this.prodParam.exit();
  13056. this.scope.exit();
  13057. if (isDeclaration && !hangingDeclaration) {
  13058. this.registerFunctionStatementId(node);
  13059. }
  13060. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13061. return node;
  13062. }
  13063. parseFunctionId(requireId) {
  13064. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13065. }
  13066. parseFunctionParams(node, isConstructor) {
  13067. this.expect(10);
  13068. this.expressionScope.enter(newParameterDeclarationScope());
  13069. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13070. this.expressionScope.exit();
  13071. }
  13072. registerFunctionStatementId(node) {
  13073. if (!node.id) return;
  13074. this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? 5 : 8201 : 17, node.id.loc.start);
  13075. }
  13076. parseClass(node, isStatement, optionalId) {
  13077. this.next();
  13078. const oldStrict = this.state.strict;
  13079. this.state.strict = true;
  13080. this.parseClassId(node, isStatement, optionalId);
  13081. this.parseClassSuper(node);
  13082. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13083. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13084. }
  13085. isClassProperty() {
  13086. return this.match(29) || this.match(13) || this.match(8);
  13087. }
  13088. isClassMethod() {
  13089. return this.match(10);
  13090. }
  13091. nameIsConstructor(key) {
  13092. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  13093. }
  13094. isNonstaticConstructor(method) {
  13095. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  13096. }
  13097. parseClassBody(hadSuperClass, oldStrict) {
  13098. this.classScope.enter();
  13099. const state = {
  13100. hadConstructor: false,
  13101. hadSuperClass
  13102. };
  13103. let decorators = [];
  13104. const classBody = this.startNode();
  13105. classBody.body = [];
  13106. this.expect(5);
  13107. this.withSmartMixTopicForbiddingContext(() => {
  13108. while (!this.match(8)) {
  13109. if (this.eat(13)) {
  13110. if (decorators.length > 0) {
  13111. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  13112. }
  13113. continue;
  13114. }
  13115. if (this.match(26)) {
  13116. decorators.push(this.parseDecorator());
  13117. continue;
  13118. }
  13119. const member = this.startNode();
  13120. if (decorators.length) {
  13121. member.decorators = decorators;
  13122. this.resetStartLocationFromNode(member, decorators[0]);
  13123. decorators = [];
  13124. }
  13125. this.parseClassMember(classBody, member, state);
  13126. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13127. this.raise(Errors.DecoratorConstructor, member);
  13128. }
  13129. }
  13130. });
  13131. this.state.strict = oldStrict;
  13132. this.next();
  13133. if (decorators.length) {
  13134. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  13135. }
  13136. this.classScope.exit();
  13137. return this.finishNode(classBody, "ClassBody");
  13138. }
  13139. parseClassMemberFromModifier(classBody, member) {
  13140. const key = this.parseIdentifier(true);
  13141. if (this.isClassMethod()) {
  13142. const method = member;
  13143. method.kind = "method";
  13144. method.computed = false;
  13145. method.key = key;
  13146. method.static = false;
  13147. this.pushClassMethod(classBody, method, false, false, false, false);
  13148. return true;
  13149. } else if (this.isClassProperty()) {
  13150. const prop = member;
  13151. prop.computed = false;
  13152. prop.key = key;
  13153. prop.static = false;
  13154. classBody.body.push(this.parseClassProperty(prop));
  13155. return true;
  13156. }
  13157. this.resetPreviousNodeTrailingComments(key);
  13158. return false;
  13159. }
  13160. parseClassMember(classBody, member, state) {
  13161. const isStatic = this.isContextual(106);
  13162. if (isStatic) {
  13163. if (this.parseClassMemberFromModifier(classBody, member)) {
  13164. return;
  13165. }
  13166. if (this.eat(5)) {
  13167. this.parseClassStaticBlock(classBody, member);
  13168. return;
  13169. }
  13170. }
  13171. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13172. }
  13173. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13174. const publicMethod = member;
  13175. const privateMethod = member;
  13176. const publicProp = member;
  13177. const privateProp = member;
  13178. const accessorProp = member;
  13179. const method = publicMethod;
  13180. const publicMember = publicMethod;
  13181. member.static = isStatic;
  13182. this.parsePropertyNamePrefixOperator(member);
  13183. if (this.eat(55)) {
  13184. method.kind = "method";
  13185. const isPrivateName = this.match(139);
  13186. this.parseClassElementName(method);
  13187. if (isPrivateName) {
  13188. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13189. return;
  13190. }
  13191. if (this.isNonstaticConstructor(publicMethod)) {
  13192. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  13193. }
  13194. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13195. return;
  13196. }
  13197. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  13198. const key = this.parseClassElementName(member);
  13199. const maybeContextualKw = isContextual ? key.name : null;
  13200. const isPrivate = this.isPrivateName(key);
  13201. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13202. this.parsePostMemberNameModifiers(publicMember);
  13203. if (this.isClassMethod()) {
  13204. method.kind = "method";
  13205. if (isPrivate) {
  13206. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13207. return;
  13208. }
  13209. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13210. let allowsDirectSuper = false;
  13211. if (isConstructor) {
  13212. publicMethod.kind = "constructor";
  13213. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13214. this.raise(Errors.DuplicateConstructor, key);
  13215. }
  13216. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13217. this.raise(Errors.OverrideOnConstructor, key);
  13218. }
  13219. state.hadConstructor = true;
  13220. allowsDirectSuper = state.hadSuperClass;
  13221. }
  13222. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13223. } else if (this.isClassProperty()) {
  13224. if (isPrivate) {
  13225. this.pushClassPrivateProperty(classBody, privateProp);
  13226. } else {
  13227. this.pushClassProperty(classBody, publicProp);
  13228. }
  13229. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  13230. this.resetPreviousNodeTrailingComments(key);
  13231. const isGenerator = this.eat(55);
  13232. if (publicMember.optional) {
  13233. this.unexpected(maybeQuestionTokenStartLoc);
  13234. }
  13235. method.kind = "method";
  13236. const isPrivate = this.match(139);
  13237. this.parseClassElementName(method);
  13238. this.parsePostMemberNameModifiers(publicMember);
  13239. if (isPrivate) {
  13240. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13241. } else {
  13242. if (this.isNonstaticConstructor(publicMethod)) {
  13243. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  13244. }
  13245. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13246. }
  13247. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  13248. this.resetPreviousNodeTrailingComments(key);
  13249. method.kind = maybeContextualKw;
  13250. const isPrivate = this.match(139);
  13251. this.parseClassElementName(publicMethod);
  13252. if (isPrivate) {
  13253. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13254. } else {
  13255. if (this.isNonstaticConstructor(publicMethod)) {
  13256. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  13257. }
  13258. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13259. }
  13260. this.checkGetterSetterParams(publicMethod);
  13261. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  13262. this.expectPlugin("decoratorAutoAccessors");
  13263. this.resetPreviousNodeTrailingComments(key);
  13264. const isPrivate = this.match(139);
  13265. this.parseClassElementName(publicProp);
  13266. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13267. } else if (this.isLineTerminator()) {
  13268. if (isPrivate) {
  13269. this.pushClassPrivateProperty(classBody, privateProp);
  13270. } else {
  13271. this.pushClassProperty(classBody, publicProp);
  13272. }
  13273. } else {
  13274. this.unexpected();
  13275. }
  13276. }
  13277. parseClassElementName(member) {
  13278. const {
  13279. type,
  13280. value
  13281. } = this.state;
  13282. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  13283. this.raise(Errors.StaticPrototype, this.state.startLoc);
  13284. }
  13285. if (type === 139) {
  13286. if (value === "constructor") {
  13287. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  13288. }
  13289. const key = this.parsePrivateName();
  13290. member.key = key;
  13291. return key;
  13292. }
  13293. this.parsePropertyName(member);
  13294. return member.key;
  13295. }
  13296. parseClassStaticBlock(classBody, member) {
  13297. var _member$decorators;
  13298. this.scope.enter(64 | 128 | 16);
  13299. const oldLabels = this.state.labels;
  13300. this.state.labels = [];
  13301. this.prodParam.enter(0);
  13302. const body = member.body = [];
  13303. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13304. this.prodParam.exit();
  13305. this.scope.exit();
  13306. this.state.labels = oldLabels;
  13307. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13308. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13309. this.raise(Errors.DecoratorStaticBlock, member);
  13310. }
  13311. }
  13312. pushClassProperty(classBody, prop) {
  13313. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  13314. this.raise(Errors.ConstructorClassField, prop.key);
  13315. }
  13316. classBody.body.push(this.parseClassProperty(prop));
  13317. }
  13318. pushClassPrivateProperty(classBody, prop) {
  13319. const node = this.parseClassPrivateProperty(prop);
  13320. classBody.body.push(node);
  13321. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13322. }
  13323. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13324. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  13325. this.raise(Errors.ConstructorClassField, prop.key);
  13326. }
  13327. const node = this.parseClassAccessorProperty(prop);
  13328. classBody.body.push(node);
  13329. if (isPrivate) {
  13330. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13331. }
  13332. }
  13333. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13334. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13335. }
  13336. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13337. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13338. classBody.body.push(node);
  13339. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13340. this.declareClassPrivateMethodInScope(node, kind);
  13341. }
  13342. declareClassPrivateMethodInScope(node, kind) {
  13343. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13344. }
  13345. parsePostMemberNameModifiers(methodOrProp) {}
  13346. parseClassPrivateProperty(node) {
  13347. this.parseInitializer(node);
  13348. this.semicolon();
  13349. return this.finishNode(node, "ClassPrivateProperty");
  13350. }
  13351. parseClassProperty(node) {
  13352. this.parseInitializer(node);
  13353. this.semicolon();
  13354. return this.finishNode(node, "ClassProperty");
  13355. }
  13356. parseClassAccessorProperty(node) {
  13357. this.parseInitializer(node);
  13358. this.semicolon();
  13359. return this.finishNode(node, "ClassAccessorProperty");
  13360. }
  13361. parseInitializer(node) {
  13362. this.scope.enter(64 | 16);
  13363. this.expressionScope.enter(newExpressionScope());
  13364. this.prodParam.enter(0);
  13365. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13366. this.expressionScope.exit();
  13367. this.prodParam.exit();
  13368. this.scope.exit();
  13369. }
  13370. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13371. if (tokenIsIdentifier(this.state.type)) {
  13372. node.id = this.parseIdentifier();
  13373. if (isStatement) {
  13374. this.declareNameFromIdentifier(node.id, bindingType);
  13375. }
  13376. } else {
  13377. if (optionalId || !isStatement) {
  13378. node.id = null;
  13379. } else {
  13380. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  13381. }
  13382. }
  13383. }
  13384. parseClassSuper(node) {
  13385. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13386. }
  13387. parseExport(node, decorators) {
  13388. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13389. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13390. const parseAfterDefault = !hasDefault || this.eat(12);
  13391. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13392. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13393. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13394. const isFromRequired = hasDefault || hasStar;
  13395. if (hasStar && !hasNamespace) {
  13396. if (hasDefault) this.unexpected();
  13397. if (decorators) {
  13398. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13399. }
  13400. this.parseExportFrom(node, true);
  13401. return this.finishNode(node, "ExportAllDeclaration");
  13402. }
  13403. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13404. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13405. this.unexpected(null, 5);
  13406. }
  13407. if (hasNamespace && parseAfterNamespace) {
  13408. this.unexpected(null, 98);
  13409. }
  13410. let hasDeclaration;
  13411. if (isFromRequired || hasSpecifiers) {
  13412. hasDeclaration = false;
  13413. if (decorators) {
  13414. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13415. }
  13416. this.parseExportFrom(node, isFromRequired);
  13417. } else {
  13418. hasDeclaration = this.maybeParseExportDeclaration(node);
  13419. }
  13420. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13421. var _node2$declaration;
  13422. const node2 = node;
  13423. this.checkExport(node2, true, false, !!node2.source);
  13424. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13425. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13426. } else if (decorators) {
  13427. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13428. }
  13429. return this.finishNode(node2, "ExportNamedDeclaration");
  13430. }
  13431. if (this.eat(65)) {
  13432. const node2 = node;
  13433. const decl = this.parseExportDefaultExpression();
  13434. node2.declaration = decl;
  13435. if (decl.type === "ClassDeclaration") {
  13436. this.maybeTakeDecorators(decorators, decl, node2);
  13437. } else if (decorators) {
  13438. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  13439. }
  13440. this.checkExport(node2, true, true);
  13441. return this.finishNode(node2, "ExportDefaultDeclaration");
  13442. }
  13443. this.unexpected(null, 5);
  13444. }
  13445. eatExportStar(node) {
  13446. return this.eat(55);
  13447. }
  13448. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13449. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13450. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13451. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13452. const specifier = this.startNodeAtNode(id);
  13453. specifier.exported = id;
  13454. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13455. return true;
  13456. }
  13457. return false;
  13458. }
  13459. maybeParseExportNamespaceSpecifier(node) {
  13460. if (this.isContextual(93)) {
  13461. var _ref, _ref$specifiers;
  13462. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  13463. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13464. this.next();
  13465. specifier.exported = this.parseModuleExportName();
  13466. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13467. return true;
  13468. }
  13469. return false;
  13470. }
  13471. maybeParseExportNamedSpecifiers(node) {
  13472. if (this.match(5)) {
  13473. const node2 = node;
  13474. if (!node2.specifiers) node2.specifiers = [];
  13475. const isTypeExport = node2.exportKind === "type";
  13476. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13477. node2.source = null;
  13478. node2.declaration = null;
  13479. if (this.hasPlugin("importAssertions")) {
  13480. node2.assertions = [];
  13481. }
  13482. return true;
  13483. }
  13484. return false;
  13485. }
  13486. maybeParseExportDeclaration(node) {
  13487. if (this.shouldParseExportDeclaration()) {
  13488. node.specifiers = [];
  13489. node.source = null;
  13490. if (this.hasPlugin("importAssertions")) {
  13491. node.assertions = [];
  13492. }
  13493. node.declaration = this.parseExportDeclaration(node);
  13494. return true;
  13495. }
  13496. return false;
  13497. }
  13498. isAsyncFunction() {
  13499. if (!this.isContextual(95)) return false;
  13500. const next = this.nextTokenInLineStart();
  13501. return this.isUnparsedContextual(next, "function");
  13502. }
  13503. parseExportDefaultExpression() {
  13504. const expr = this.startNode();
  13505. if (this.match(68)) {
  13506. this.next();
  13507. return this.parseFunction(expr, 1 | 4);
  13508. } else if (this.isAsyncFunction()) {
  13509. this.next();
  13510. this.next();
  13511. return this.parseFunction(expr, 1 | 4 | 8);
  13512. }
  13513. if (this.match(80)) {
  13514. return this.parseClass(expr, true, true);
  13515. }
  13516. if (this.match(26)) {
  13517. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13518. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13519. }
  13520. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13521. }
  13522. if (this.match(75) || this.match(74) || this.isLet()) {
  13523. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  13524. }
  13525. const res = this.parseMaybeAssignAllowIn();
  13526. this.semicolon();
  13527. return res;
  13528. }
  13529. parseExportDeclaration(node) {
  13530. if (this.match(80)) {
  13531. const node = this.parseClass(this.startNode(), true, false);
  13532. return node;
  13533. }
  13534. return this.parseStatementListItem();
  13535. }
  13536. isExportDefaultSpecifier() {
  13537. const {
  13538. type
  13539. } = this.state;
  13540. if (tokenIsIdentifier(type)) {
  13541. if (type === 95 && !this.state.containsEsc || type === 100) {
  13542. return false;
  13543. }
  13544. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13545. const {
  13546. type: nextType
  13547. } = this.lookahead();
  13548. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  13549. this.expectOnePlugin(["flow", "typescript"]);
  13550. return false;
  13551. }
  13552. }
  13553. } else if (!this.match(65)) {
  13554. return false;
  13555. }
  13556. const next = this.nextTokenStart();
  13557. const hasFrom = this.isUnparsedContextual(next, "from");
  13558. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13559. return true;
  13560. }
  13561. if (this.match(65) && hasFrom) {
  13562. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13563. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13564. }
  13565. return false;
  13566. }
  13567. parseExportFrom(node, expect) {
  13568. if (this.eatContextual(98)) {
  13569. node.source = this.parseImportSource();
  13570. this.checkExport(node);
  13571. this.maybeParseImportAttributes(node);
  13572. this.checkJSONModuleImport(node);
  13573. } else if (expect) {
  13574. this.unexpected();
  13575. }
  13576. this.semicolon();
  13577. }
  13578. shouldParseExportDeclaration() {
  13579. const {
  13580. type
  13581. } = this.state;
  13582. if (type === 26) {
  13583. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13584. if (this.hasPlugin("decorators")) {
  13585. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13586. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  13587. }
  13588. return true;
  13589. }
  13590. }
  13591. if (this.isContextual(107)) {
  13592. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13593. return true;
  13594. }
  13595. if (this.isContextual(96) && this.startsAwaitUsing()) {
  13596. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  13597. return true;
  13598. }
  13599. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13600. }
  13601. checkExport(node, checkNames, isDefault, isFrom) {
  13602. if (checkNames) {
  13603. var _node$specifiers;
  13604. if (isDefault) {
  13605. this.checkDuplicateExports(node, "default");
  13606. if (this.hasPlugin("exportDefaultFrom")) {
  13607. var _declaration$extra;
  13608. const declaration = node.declaration;
  13609. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13610. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  13611. }
  13612. }
  13613. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13614. for (const specifier of node.specifiers) {
  13615. const {
  13616. exported
  13617. } = specifier;
  13618. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13619. this.checkDuplicateExports(specifier, exportName);
  13620. if (!isFrom && specifier.local) {
  13621. const {
  13622. local
  13623. } = specifier;
  13624. if (local.type !== "Identifier") {
  13625. this.raise(Errors.ExportBindingIsString, specifier, {
  13626. localName: local.value,
  13627. exportName
  13628. });
  13629. } else {
  13630. this.checkReservedWord(local.name, local.loc.start, true, false);
  13631. this.scope.checkLocalExport(local);
  13632. }
  13633. }
  13634. }
  13635. } else if (node.declaration) {
  13636. const decl = node.declaration;
  13637. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  13638. const {
  13639. id
  13640. } = decl;
  13641. if (!id) throw new Error("Assertion failure");
  13642. this.checkDuplicateExports(node, id.name);
  13643. } else if (decl.type === "VariableDeclaration") {
  13644. for (const declaration of decl.declarations) {
  13645. this.checkDeclaration(declaration.id);
  13646. }
  13647. }
  13648. }
  13649. }
  13650. }
  13651. checkDeclaration(node) {
  13652. if (node.type === "Identifier") {
  13653. this.checkDuplicateExports(node, node.name);
  13654. } else if (node.type === "ObjectPattern") {
  13655. for (const prop of node.properties) {
  13656. this.checkDeclaration(prop);
  13657. }
  13658. } else if (node.type === "ArrayPattern") {
  13659. for (const elem of node.elements) {
  13660. if (elem) {
  13661. this.checkDeclaration(elem);
  13662. }
  13663. }
  13664. } else if (node.type === "ObjectProperty") {
  13665. this.checkDeclaration(node.value);
  13666. } else if (node.type === "RestElement") {
  13667. this.checkDeclaration(node.argument);
  13668. } else if (node.type === "AssignmentPattern") {
  13669. this.checkDeclaration(node.left);
  13670. }
  13671. }
  13672. checkDuplicateExports(node, exportName) {
  13673. if (this.exportedIdentifiers.has(exportName)) {
  13674. if (exportName === "default") {
  13675. this.raise(Errors.DuplicateDefaultExport, node);
  13676. } else {
  13677. this.raise(Errors.DuplicateExport, node, {
  13678. exportName
  13679. });
  13680. }
  13681. }
  13682. this.exportedIdentifiers.add(exportName);
  13683. }
  13684. parseExportSpecifiers(isInTypeExport) {
  13685. const nodes = [];
  13686. let first = true;
  13687. this.expect(5);
  13688. while (!this.eat(8)) {
  13689. if (first) {
  13690. first = false;
  13691. } else {
  13692. this.expect(12);
  13693. if (this.eat(8)) break;
  13694. }
  13695. const isMaybeTypeOnly = this.isContextual(130);
  13696. const isString = this.match(134);
  13697. const node = this.startNode();
  13698. node.local = this.parseModuleExportName();
  13699. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13700. }
  13701. return nodes;
  13702. }
  13703. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13704. if (this.eatContextual(93)) {
  13705. node.exported = this.parseModuleExportName();
  13706. } else if (isString) {
  13707. node.exported = cloneStringLiteral(node.local);
  13708. } else if (!node.exported) {
  13709. node.exported = cloneIdentifier(node.local);
  13710. }
  13711. return this.finishNode(node, "ExportSpecifier");
  13712. }
  13713. parseModuleExportName() {
  13714. if (this.match(134)) {
  13715. const result = this.parseStringLiteral(this.state.value);
  13716. const surrogate = loneSurrogate.exec(result.value);
  13717. if (surrogate) {
  13718. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  13719. surrogateCharCode: surrogate[0].charCodeAt(0)
  13720. });
  13721. }
  13722. return result;
  13723. }
  13724. return this.parseIdentifier(true);
  13725. }
  13726. isJSONModuleImport(node) {
  13727. if (node.assertions != null) {
  13728. return node.assertions.some(({
  13729. key,
  13730. value
  13731. }) => {
  13732. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13733. });
  13734. }
  13735. return false;
  13736. }
  13737. checkImportReflection(node) {
  13738. const {
  13739. specifiers
  13740. } = node;
  13741. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  13742. if (node.phase === "source") {
  13743. if (singleBindingType !== "ImportDefaultSpecifier") {
  13744. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  13745. }
  13746. } else if (node.phase === "defer") {
  13747. if (singleBindingType !== "ImportNamespaceSpecifier") {
  13748. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  13749. }
  13750. } else if (node.module) {
  13751. var _node$assertions;
  13752. if (singleBindingType !== "ImportDefaultSpecifier") {
  13753. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  13754. }
  13755. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  13756. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  13757. }
  13758. }
  13759. }
  13760. checkJSONModuleImport(node) {
  13761. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13762. const {
  13763. specifiers
  13764. } = node;
  13765. if (specifiers != null) {
  13766. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  13767. let imported;
  13768. if (specifier.type === "ExportSpecifier") {
  13769. imported = specifier.local;
  13770. } else if (specifier.type === "ImportSpecifier") {
  13771. imported = specifier.imported;
  13772. }
  13773. if (imported !== undefined) {
  13774. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  13775. }
  13776. });
  13777. if (nonDefaultNamedSpecifier !== undefined) {
  13778. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  13779. }
  13780. }
  13781. }
  13782. }
  13783. isPotentialImportPhase(isExport) {
  13784. if (isExport) return false;
  13785. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  13786. }
  13787. applyImportPhase(node, isExport, phase, loc) {
  13788. if (isExport) {
  13789. return;
  13790. }
  13791. if (phase === "module") {
  13792. this.expectPlugin("importReflection", loc);
  13793. node.module = true;
  13794. } else if (this.hasPlugin("importReflection")) {
  13795. node.module = false;
  13796. }
  13797. if (phase === "source") {
  13798. this.expectPlugin("sourcePhaseImports", loc);
  13799. node.phase = "source";
  13800. } else if (phase === "defer") {
  13801. this.expectPlugin("deferredImportEvaluation", loc);
  13802. node.phase = "defer";
  13803. } else if (this.hasPlugin("sourcePhaseImports")) {
  13804. node.phase = null;
  13805. }
  13806. }
  13807. parseMaybeImportPhase(node, isExport) {
  13808. if (!this.isPotentialImportPhase(isExport)) {
  13809. this.applyImportPhase(node, isExport, null);
  13810. return null;
  13811. }
  13812. const phaseIdentifier = this.parseIdentifier(true);
  13813. const {
  13814. type
  13815. } = this.state;
  13816. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13817. if (isImportPhase) {
  13818. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  13819. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  13820. return null;
  13821. } else {
  13822. this.applyImportPhase(node, isExport, null);
  13823. return phaseIdentifier;
  13824. }
  13825. }
  13826. isPrecedingIdImportPhase(phase) {
  13827. const {
  13828. type
  13829. } = this.state;
  13830. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  13831. }
  13832. parseImport(node) {
  13833. if (this.match(134)) {
  13834. return this.parseImportSourceAndAttributes(node);
  13835. }
  13836. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  13837. }
  13838. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  13839. node.specifiers = [];
  13840. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  13841. const parseNext = !hasDefault || this.eat(12);
  13842. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  13843. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  13844. this.expectContextual(98);
  13845. return this.parseImportSourceAndAttributes(node);
  13846. }
  13847. parseImportSourceAndAttributes(node) {
  13848. var _node$specifiers2;
  13849. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  13850. node.source = this.parseImportSource();
  13851. this.maybeParseImportAttributes(node);
  13852. this.checkImportReflection(node);
  13853. this.checkJSONModuleImport(node);
  13854. this.semicolon();
  13855. return this.finishNode(node, "ImportDeclaration");
  13856. }
  13857. parseImportSource() {
  13858. if (!this.match(134)) this.unexpected();
  13859. return this.parseExprAtom();
  13860. }
  13861. parseImportSpecifierLocal(node, specifier, type) {
  13862. specifier.local = this.parseIdentifier();
  13863. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  13864. }
  13865. finishImportSpecifier(specifier, type, bindingType = 8201) {
  13866. this.checkLVal(specifier.local, {
  13867. type
  13868. }, bindingType);
  13869. return this.finishNode(specifier, type);
  13870. }
  13871. parseImportAttributes() {
  13872. this.expect(5);
  13873. const attrs = [];
  13874. const attrNames = new Set();
  13875. do {
  13876. if (this.match(8)) {
  13877. break;
  13878. }
  13879. const node = this.startNode();
  13880. const keyName = this.state.value;
  13881. if (attrNames.has(keyName)) {
  13882. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  13883. key: keyName
  13884. });
  13885. }
  13886. attrNames.add(keyName);
  13887. if (this.match(134)) {
  13888. node.key = this.parseStringLiteral(keyName);
  13889. } else {
  13890. node.key = this.parseIdentifier(true);
  13891. }
  13892. this.expect(14);
  13893. if (!this.match(134)) {
  13894. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13895. }
  13896. node.value = this.parseStringLiteral(this.state.value);
  13897. attrs.push(this.finishNode(node, "ImportAttribute"));
  13898. } while (this.eat(12));
  13899. this.expect(8);
  13900. return attrs;
  13901. }
  13902. parseModuleAttributes() {
  13903. const attrs = [];
  13904. const attributes = new Set();
  13905. do {
  13906. const node = this.startNode();
  13907. node.key = this.parseIdentifier(true);
  13908. if (node.key.name !== "type") {
  13909. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  13910. }
  13911. if (attributes.has(node.key.name)) {
  13912. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  13913. key: node.key.name
  13914. });
  13915. }
  13916. attributes.add(node.key.name);
  13917. this.expect(14);
  13918. if (!this.match(134)) {
  13919. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  13920. }
  13921. node.value = this.parseStringLiteral(this.state.value);
  13922. attrs.push(this.finishNode(node, "ImportAttribute"));
  13923. } while (this.eat(12));
  13924. return attrs;
  13925. }
  13926. maybeParseImportAttributes(node) {
  13927. let attributes;
  13928. {
  13929. var useWith = false;
  13930. }
  13931. if (this.match(76)) {
  13932. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  13933. return;
  13934. }
  13935. this.next();
  13936. if (this.hasPlugin("moduleAttributes")) {
  13937. attributes = this.parseModuleAttributes();
  13938. } else {
  13939. attributes = this.parseImportAttributes();
  13940. }
  13941. {
  13942. useWith = true;
  13943. }
  13944. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  13945. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  13946. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  13947. }
  13948. if (!this.hasPlugin("importAssertions")) {
  13949. this.addExtra(node, "deprecatedAssertSyntax", true);
  13950. }
  13951. this.next();
  13952. attributes = this.parseImportAttributes();
  13953. } else {
  13954. attributes = [];
  13955. }
  13956. if (!useWith && this.hasPlugin("importAssertions")) {
  13957. node.assertions = attributes;
  13958. } else {
  13959. node.attributes = attributes;
  13960. }
  13961. }
  13962. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  13963. if (maybeDefaultIdentifier) {
  13964. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  13965. specifier.local = maybeDefaultIdentifier;
  13966. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  13967. return true;
  13968. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  13969. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  13970. return true;
  13971. }
  13972. return false;
  13973. }
  13974. maybeParseStarImportSpecifier(node) {
  13975. if (this.match(55)) {
  13976. const specifier = this.startNode();
  13977. this.next();
  13978. this.expectContextual(93);
  13979. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  13980. return true;
  13981. }
  13982. return false;
  13983. }
  13984. parseNamedImportSpecifiers(node) {
  13985. let first = true;
  13986. this.expect(5);
  13987. while (!this.eat(8)) {
  13988. if (first) {
  13989. first = false;
  13990. } else {
  13991. if (this.eat(14)) {
  13992. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  13993. }
  13994. this.expect(12);
  13995. if (this.eat(8)) break;
  13996. }
  13997. const specifier = this.startNode();
  13998. const importedIsString = this.match(134);
  13999. const isMaybeTypeOnly = this.isContextual(130);
  14000. specifier.imported = this.parseModuleExportName();
  14001. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14002. node.specifiers.push(importSpecifier);
  14003. }
  14004. }
  14005. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14006. if (this.eatContextual(93)) {
  14007. specifier.local = this.parseIdentifier();
  14008. } else {
  14009. const {
  14010. imported
  14011. } = specifier;
  14012. if (importedIsString) {
  14013. throw this.raise(Errors.ImportBindingIsString, specifier, {
  14014. importName: imported.value
  14015. });
  14016. }
  14017. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14018. if (!specifier.local) {
  14019. specifier.local = cloneIdentifier(imported);
  14020. }
  14021. }
  14022. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14023. }
  14024. isThisParam(param) {
  14025. return param.type === "Identifier" && param.name === "this";
  14026. }
  14027. }
  14028. class Parser extends StatementParser {
  14029. constructor(options, input, pluginsMap) {
  14030. options = getOptions(options);
  14031. super(options, input);
  14032. this.options = options;
  14033. this.initializeScopes();
  14034. this.plugins = pluginsMap;
  14035. this.filename = options.sourceFilename;
  14036. this.startIndex = options.startIndex;
  14037. let optionFlags = 0;
  14038. if (options.allowAwaitOutsideFunction) {
  14039. optionFlags |= 1;
  14040. }
  14041. if (options.allowReturnOutsideFunction) {
  14042. optionFlags |= 2;
  14043. }
  14044. if (options.allowImportExportEverywhere) {
  14045. optionFlags |= 8;
  14046. }
  14047. if (options.allowSuperOutsideMethod) {
  14048. optionFlags |= 16;
  14049. }
  14050. if (options.allowUndeclaredExports) {
  14051. optionFlags |= 32;
  14052. }
  14053. if (options.allowNewTargetOutsideFunction) {
  14054. optionFlags |= 4;
  14055. }
  14056. if (options.ranges) {
  14057. optionFlags |= 64;
  14058. }
  14059. if (options.tokens) {
  14060. optionFlags |= 128;
  14061. }
  14062. if (options.createImportExpressions) {
  14063. optionFlags |= 256;
  14064. }
  14065. if (options.createParenthesizedExpressions) {
  14066. optionFlags |= 512;
  14067. }
  14068. if (options.errorRecovery) {
  14069. optionFlags |= 1024;
  14070. }
  14071. if (options.attachComment) {
  14072. optionFlags |= 2048;
  14073. }
  14074. if (options.annexB) {
  14075. optionFlags |= 4096;
  14076. }
  14077. this.optionFlags = optionFlags;
  14078. }
  14079. getScopeHandler() {
  14080. return ScopeHandler;
  14081. }
  14082. parse() {
  14083. this.enterInitialScopes();
  14084. const file = this.startNode();
  14085. const program = this.startNode();
  14086. this.nextToken();
  14087. file.errors = null;
  14088. this.parseTopLevel(file, program);
  14089. file.errors = this.state.errors;
  14090. file.comments.length = this.state.commentsLen;
  14091. return file;
  14092. }
  14093. }
  14094. function parse(input, options) {
  14095. var _options;
  14096. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14097. options = Object.assign({}, options);
  14098. try {
  14099. options.sourceType = "module";
  14100. const parser = getParser(options, input);
  14101. const ast = parser.parse();
  14102. if (parser.sawUnambiguousESM) {
  14103. return ast;
  14104. }
  14105. if (parser.ambiguousScriptDifferentAst) {
  14106. try {
  14107. options.sourceType = "script";
  14108. return getParser(options, input).parse();
  14109. } catch (_unused) {}
  14110. } else {
  14111. ast.program.sourceType = "script";
  14112. }
  14113. return ast;
  14114. } catch (moduleError) {
  14115. try {
  14116. options.sourceType = "script";
  14117. return getParser(options, input).parse();
  14118. } catch (_unused2) {}
  14119. throw moduleError;
  14120. }
  14121. } else {
  14122. return getParser(options, input).parse();
  14123. }
  14124. }
  14125. function parseExpression(input, options) {
  14126. const parser = getParser(options, input);
  14127. if (parser.options.strictMode) {
  14128. parser.state.strict = true;
  14129. }
  14130. return parser.getExpression();
  14131. }
  14132. function generateExportedTokenTypes(internalTokenTypes) {
  14133. const tokenTypes = {};
  14134. for (const typeName of Object.keys(internalTokenTypes)) {
  14135. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14136. }
  14137. return tokenTypes;
  14138. }
  14139. const tokTypes = generateExportedTokenTypes(tt);
  14140. function getParser(options, input) {
  14141. let cls = Parser;
  14142. const pluginsMap = new Map();
  14143. if (options != null && options.plugins) {
  14144. for (const plugin of options.plugins) {
  14145. let name, opts;
  14146. if (typeof plugin === "string") {
  14147. name = plugin;
  14148. } else {
  14149. [name, opts] = plugin;
  14150. }
  14151. if (!pluginsMap.has(name)) {
  14152. pluginsMap.set(name, opts || {});
  14153. }
  14154. }
  14155. validatePlugins(pluginsMap);
  14156. cls = getParserClass(pluginsMap);
  14157. }
  14158. return new cls(options, input, pluginsMap);
  14159. }
  14160. const parserClassCache = new Map();
  14161. function getParserClass(pluginsMap) {
  14162. const pluginList = [];
  14163. for (const name of mixinPluginNames) {
  14164. if (pluginsMap.has(name)) {
  14165. pluginList.push(name);
  14166. }
  14167. }
  14168. const key = pluginList.join("|");
  14169. let cls = parserClassCache.get(key);
  14170. if (!cls) {
  14171. cls = Parser;
  14172. for (const plugin of pluginList) {
  14173. cls = mixinPlugins[plugin](cls);
  14174. }
  14175. parserClassCache.set(key, cls);
  14176. }
  14177. return cls;
  14178. }
  14179. exports.parse = parse;
  14180. exports.parseExpression = parseExpression;
  14181. exports.tokTypes = tokTypes;
  14182. //# sourceMappingURL=index.js.map