index.js 476 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381
  1. 'use strict';
  2. function _objectWithoutPropertiesLoose(source, excluded) {
  3. if (source == null) return {};
  4. var target = {};
  5. var sourceKeys = Object.keys(source);
  6. var key, i;
  7. for (i = 0; i < sourceKeys.length; i++) {
  8. key = sourceKeys[i];
  9. if (excluded.indexOf(key) >= 0) continue;
  10. target[key] = source[key];
  11. }
  12. return target;
  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. var ParseErrorCode = {
  43. SyntaxError: "BABEL_PARSER_SYNTAX_ERROR",
  44. SourceTypeModuleError: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED"
  45. };
  46. const reflect = (keys, last = keys.length - 1) => ({
  47. get() {
  48. return keys.reduce((object, key) => object[key], this);
  49. },
  50. set(value) {
  51. keys.reduce((item, key, i) => i === last ? item[key] = value : item[key], this);
  52. }
  53. });
  54. const instantiate = (constructor, properties, descriptors) => Object.keys(descriptors).map(key => [key, descriptors[key]]).filter(([, descriptor]) => !!descriptor).map(([key, descriptor]) => [key, typeof descriptor === "function" ? {
  55. value: descriptor,
  56. enumerable: false
  57. } : typeof descriptor.reflect === "string" ? Object.assign({}, descriptor, reflect(descriptor.reflect.split("."))) : descriptor]).reduce((instance, [key, descriptor]) => Object.defineProperty(instance, key, Object.assign({
  58. configurable: true
  59. }, descriptor)), Object.assign(new constructor(), properties));
  60. var ModuleErrors = {
  61. ImportMetaOutsideModule: {
  62. message: `import.meta may appear only with 'sourceType: "module"'`,
  63. code: ParseErrorCode.SourceTypeModuleError
  64. },
  65. ImportOutsideModule: {
  66. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  67. code: ParseErrorCode.SourceTypeModuleError
  68. }
  69. };
  70. const NodeDescriptions = {
  71. ArrayPattern: "array destructuring pattern",
  72. AssignmentExpression: "assignment expression",
  73. AssignmentPattern: "assignment expression",
  74. ArrowFunctionExpression: "arrow function expression",
  75. ConditionalExpression: "conditional expression",
  76. CatchClause: "catch clause",
  77. ForOfStatement: "for-of statement",
  78. ForInStatement: "for-in statement",
  79. ForStatement: "for-loop",
  80. FormalParameters: "function parameter list",
  81. Identifier: "identifier",
  82. ImportSpecifier: "import specifier",
  83. ImportDefaultSpecifier: "import default specifier",
  84. ImportNamespaceSpecifier: "import namespace specifier",
  85. ObjectPattern: "object destructuring pattern",
  86. ParenthesizedExpression: "parenthesized expression",
  87. RestElement: "rest element",
  88. UpdateExpression: {
  89. true: "prefix operation",
  90. false: "postfix operation"
  91. },
  92. VariableDeclarator: "variable declaration",
  93. YieldExpression: "yield expression"
  94. };
  95. const toNodeDescription = ({
  96. type,
  97. prefix
  98. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  99. var StandardErrors = {
  100. AccessorIsGenerator: ({
  101. kind
  102. }) => `A ${kind}ter cannot be a generator.`,
  103. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  104. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  105. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  106. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  107. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  108. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  109. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  110. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  111. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  112. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  113. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  114. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  115. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  116. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  117. ConstructorIsAsync: "Constructor can't be an async function.",
  118. ConstructorIsGenerator: "Constructor can't be a generator.",
  119. DeclarationMissingInitializer: ({
  120. kind
  121. }) => `Missing initializer in ${kind} declaration.`,
  122. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  123. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  124. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  125. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  126. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  127. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  128. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  129. DeletePrivateField: "Deleting a private field is not allowed.",
  130. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  131. DuplicateConstructor: "Duplicate constructor in the same class.",
  132. DuplicateDefaultExport: "Only one default export allowed per module.",
  133. DuplicateExport: ({
  134. exportName
  135. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  136. DuplicateProto: "Redefinition of __proto__ property.",
  137. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  138. ElementAfterRest: "Rest element must be last element.",
  139. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  140. ExportBindingIsString: ({
  141. localName,
  142. exportName
  143. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  144. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  145. ForInOfLoopInitializer: ({
  146. type
  147. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  148. ForInUsing: "For-in loop may not start with 'using' declaration.",
  149. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  150. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  151. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  152. IllegalBreakContinue: ({
  153. type
  154. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  155. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  156. IllegalReturn: "'return' outside of function.",
  157. ImportAttributesUseAssert: "The `assert` keyword in import attributes is deprecated and it has been replaced by the `with` keyword. You can enable the `deprecatedAssertSyntax: true` option in the import attributes plugin to suppress this error.",
  158. ImportBindingIsString: ({
  159. importName
  160. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  161. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  162. ImportCallArity: ({
  163. maxArgumentCount
  164. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  165. ImportCallNotNewExpression: "Cannot use new with import(...).",
  166. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  167. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  168. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  169. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  170. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  171. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  172. InvalidCodePoint: "Code point out of bounds.",
  173. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  174. InvalidDecimal: "Invalid decimal.",
  175. InvalidDigit: ({
  176. radix
  177. }) => `Expected number in radix ${radix}.`,
  178. InvalidEscapeSequence: "Bad character escape sequence.",
  179. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  180. InvalidEscapedReservedWord: ({
  181. reservedWord
  182. }) => `Escape sequence in keyword ${reservedWord}.`,
  183. InvalidIdentifier: ({
  184. identifierName
  185. }) => `Invalid identifier ${identifierName}.`,
  186. InvalidLhs: ({
  187. ancestor
  188. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  189. InvalidLhsBinding: ({
  190. ancestor
  191. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  192. InvalidNumber: "Invalid number.",
  193. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  194. InvalidOrUnexpectedToken: ({
  195. unexpected
  196. }) => `Unexpected character '${unexpected}'.`,
  197. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  198. InvalidPrivateFieldResolution: ({
  199. identifierName
  200. }) => `Private name #${identifierName} is not defined.`,
  201. InvalidPropertyBindingPattern: "Binding member expression.",
  202. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  203. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  204. LabelRedeclaration: ({
  205. labelName
  206. }) => `Label '${labelName}' is already declared.`,
  207. LetInLexicalBinding: "'let' is not allowed to be used as a name in 'let' or 'const' declarations.",
  208. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  209. MalformedRegExpFlags: "Invalid regular expression flag.",
  210. MissingClassName: "A class name is required.",
  211. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  212. MissingSemicolon: "Missing semicolon.",
  213. MissingPlugin: ({
  214. missingPlugin
  215. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  216. MissingOneOfPlugins: ({
  217. missingPlugin
  218. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  219. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  220. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  221. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  222. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  223. ModuleAttributesWithDuplicateKeys: ({
  224. key
  225. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  226. ModuleExportNameHasLoneSurrogate: ({
  227. surrogateCharCode
  228. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  229. ModuleExportUndefined: ({
  230. localName
  231. }) => `Export '${localName}' is not defined.`,
  232. MultipleDefaultsInSwitch: "Multiple default clauses.",
  233. NewlineAfterThrow: "Illegal newline after throw.",
  234. NoCatchOrFinally: "Missing catch or finally clause.",
  235. NumberIdentifier: "Identifier directly after number.",
  236. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  237. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  238. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  239. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  240. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  241. ParamDupe: "Argument name clash.",
  242. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  243. PatternHasMethod: "Object pattern can't contain methods.",
  244. PrivateInExpectedIn: ({
  245. identifierName
  246. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  247. PrivateNameRedeclaration: ({
  248. identifierName
  249. }) => `Duplicate private name #${identifierName}.`,
  250. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  251. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  252. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  253. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  254. RestTrailingComma: "Unexpected trailing comma after rest element.",
  255. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  256. 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.",
  257. StaticPrototype: "Classes may not have static property named prototype.",
  258. 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?",
  259. SuperPrivateField: "Private fields can't be accessed on super.",
  260. TrailingDecorator: "Decorators must be attached to a class element.",
  261. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  262. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  263. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  264. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  265. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  266. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  267. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  268. UnexpectedKeyword: ({
  269. keyword
  270. }) => `Unexpected keyword '${keyword}'.`,
  271. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  272. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  273. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  274. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  275. UnexpectedPrivateField: "Unexpected private name.",
  276. UnexpectedReservedWord: ({
  277. reservedWord
  278. }) => `Unexpected reserved word '${reservedWord}'.`,
  279. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  280. UnexpectedToken: ({
  281. expected,
  282. unexpected
  283. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  284. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  285. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  286. UnsupportedBind: "Binding should be performed on object property.",
  287. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  288. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  289. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  290. UnsupportedMetaProperty: ({
  291. target,
  292. onlyValidPropertyName
  293. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  294. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  295. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  296. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  297. UnterminatedComment: "Unterminated comment.",
  298. UnterminatedRegExp: "Unterminated regular expression.",
  299. UnterminatedString: "Unterminated string constant.",
  300. UnterminatedTemplate: "Unterminated template.",
  301. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  302. VarRedeclaration: ({
  303. identifierName
  304. }) => `Identifier '${identifierName}' has already been declared.`,
  305. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  306. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  307. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  308. };
  309. var StrictModeErrors = {
  310. StrictDelete: "Deleting local variable in strict mode.",
  311. StrictEvalArguments: ({
  312. referenceName
  313. }) => `Assigning to '${referenceName}' in strict mode.`,
  314. StrictEvalArgumentsBinding: ({
  315. bindingName
  316. }) => `Binding '${bindingName}' in strict mode.`,
  317. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  318. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  319. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  320. StrictWith: "'with' in strict mode."
  321. };
  322. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  323. var PipelineOperatorErrors = {
  324. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  325. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  326. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  327. PipeTopicUnconfiguredToken: ({
  328. token
  329. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  330. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  331. PipeUnparenthesizedBody: ({
  332. type
  333. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  334. type
  335. })}; please wrap it in parentheses.`,
  336. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  337. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  338. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  339. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  340. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  341. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  342. };
  343. const _excluded$1 = ["toMessage"],
  344. _excluded2$1 = ["message"];
  345. function toParseErrorConstructor(_ref) {
  346. let {
  347. toMessage
  348. } = _ref,
  349. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  350. return function constructor({
  351. loc,
  352. details
  353. }) {
  354. return instantiate(SyntaxError, Object.assign({}, properties, {
  355. loc
  356. }), {
  357. clone(overrides = {}) {
  358. const loc = overrides.loc || {};
  359. return constructor({
  360. loc: new Position("line" in loc ? loc.line : this.loc.line, "column" in loc ? loc.column : this.loc.column, "index" in loc ? loc.index : this.loc.index),
  361. details: Object.assign({}, this.details, overrides.details)
  362. });
  363. },
  364. details: {
  365. value: details,
  366. enumerable: false
  367. },
  368. message: {
  369. get() {
  370. return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`;
  371. },
  372. set(value) {
  373. Object.defineProperty(this, "message", {
  374. value
  375. });
  376. }
  377. },
  378. pos: {
  379. reflect: "loc.index",
  380. enumerable: true
  381. },
  382. missingPlugin: "missingPlugin" in details && {
  383. reflect: "details.missingPlugin",
  384. enumerable: true
  385. }
  386. });
  387. };
  388. }
  389. function ParseErrorEnum(argument, syntaxPlugin) {
  390. if (Array.isArray(argument)) {
  391. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  392. }
  393. const ParseErrorConstructors = {};
  394. for (const reasonCode of Object.keys(argument)) {
  395. const template = argument[reasonCode];
  396. const _ref2 = typeof template === "string" ? {
  397. message: () => template
  398. } : typeof template === "function" ? {
  399. message: template
  400. } : template,
  401. {
  402. message
  403. } = _ref2,
  404. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  405. const toMessage = typeof message === "string" ? () => message : message;
  406. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  407. code: ParseErrorCode.SyntaxError,
  408. reasonCode,
  409. toMessage
  410. }, syntaxPlugin ? {
  411. syntaxPlugin
  412. } : {}, rest));
  413. }
  414. return ParseErrorConstructors;
  415. }
  416. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  417. const {
  418. defineProperty
  419. } = Object;
  420. const toUnenumerable = (object, key) => defineProperty(object, key, {
  421. enumerable: false,
  422. value: object[key]
  423. });
  424. function toESTreeLocation(node) {
  425. node.loc.start && toUnenumerable(node.loc.start, "index");
  426. node.loc.end && toUnenumerable(node.loc.end, "index");
  427. return node;
  428. }
  429. var estree = superClass => class ESTreeParserMixin extends superClass {
  430. parse() {
  431. const file = toESTreeLocation(super.parse());
  432. if (this.options.tokens) {
  433. file.tokens = file.tokens.map(toESTreeLocation);
  434. }
  435. return file;
  436. }
  437. parseRegExpLiteral({
  438. pattern,
  439. flags
  440. }) {
  441. let regex = null;
  442. try {
  443. regex = new RegExp(pattern, flags);
  444. } catch (e) {}
  445. const node = this.estreeParseLiteral(regex);
  446. node.regex = {
  447. pattern,
  448. flags
  449. };
  450. return node;
  451. }
  452. parseBigIntLiteral(value) {
  453. let bigInt;
  454. try {
  455. bigInt = BigInt(value);
  456. } catch (_unused) {
  457. bigInt = null;
  458. }
  459. const node = this.estreeParseLiteral(bigInt);
  460. node.bigint = String(node.value || value);
  461. return node;
  462. }
  463. parseDecimalLiteral(value) {
  464. const decimal = null;
  465. const node = this.estreeParseLiteral(decimal);
  466. node.decimal = String(node.value || value);
  467. return node;
  468. }
  469. estreeParseLiteral(value) {
  470. return this.parseLiteral(value, "Literal");
  471. }
  472. parseStringLiteral(value) {
  473. return this.estreeParseLiteral(value);
  474. }
  475. parseNumericLiteral(value) {
  476. return this.estreeParseLiteral(value);
  477. }
  478. parseNullLiteral() {
  479. return this.estreeParseLiteral(null);
  480. }
  481. parseBooleanLiteral(value) {
  482. return this.estreeParseLiteral(value);
  483. }
  484. directiveToStmt(directive) {
  485. const expression = directive.value;
  486. delete directive.value;
  487. expression.type = "Literal";
  488. expression.raw = expression.extra.raw;
  489. expression.value = expression.extra.expressionValue;
  490. const stmt = directive;
  491. stmt.type = "ExpressionStatement";
  492. stmt.expression = expression;
  493. stmt.directive = expression.extra.rawValue;
  494. delete expression.extra;
  495. return stmt;
  496. }
  497. initFunction(node, isAsync) {
  498. super.initFunction(node, isAsync);
  499. node.expression = false;
  500. }
  501. checkDeclaration(node) {
  502. if (node != null && this.isObjectProperty(node)) {
  503. this.checkDeclaration(node.value);
  504. } else {
  505. super.checkDeclaration(node);
  506. }
  507. }
  508. getObjectOrClassMethodParams(method) {
  509. return method.value.params;
  510. }
  511. isValidDirective(stmt) {
  512. var _stmt$expression$extr;
  513. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  514. }
  515. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  516. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  517. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  518. node.body = directiveStatements.concat(node.body);
  519. delete node.directives;
  520. }
  521. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  522. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  523. if (method.typeParameters) {
  524. method.value.typeParameters = method.typeParameters;
  525. delete method.typeParameters;
  526. }
  527. classBody.body.push(method);
  528. }
  529. parsePrivateName() {
  530. const node = super.parsePrivateName();
  531. {
  532. if (!this.getPluginOption("estree", "classFeatures")) {
  533. return node;
  534. }
  535. }
  536. return this.convertPrivateNameToPrivateIdentifier(node);
  537. }
  538. convertPrivateNameToPrivateIdentifier(node) {
  539. const name = super.getPrivateNameSV(node);
  540. node = node;
  541. delete node.id;
  542. node.name = name;
  543. node.type = "PrivateIdentifier";
  544. return node;
  545. }
  546. isPrivateName(node) {
  547. {
  548. if (!this.getPluginOption("estree", "classFeatures")) {
  549. return super.isPrivateName(node);
  550. }
  551. }
  552. return node.type === "PrivateIdentifier";
  553. }
  554. getPrivateNameSV(node) {
  555. {
  556. if (!this.getPluginOption("estree", "classFeatures")) {
  557. return super.getPrivateNameSV(node);
  558. }
  559. }
  560. return node.name;
  561. }
  562. parseLiteral(value, type) {
  563. const node = super.parseLiteral(value, type);
  564. node.raw = node.extra.raw;
  565. delete node.extra;
  566. return node;
  567. }
  568. parseFunctionBody(node, allowExpression, isMethod = false) {
  569. super.parseFunctionBody(node, allowExpression, isMethod);
  570. node.expression = node.body.type !== "BlockStatement";
  571. }
  572. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  573. let funcNode = this.startNode();
  574. funcNode.kind = node.kind;
  575. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  576. funcNode.type = "FunctionExpression";
  577. delete funcNode.kind;
  578. node.value = funcNode;
  579. if (type === "ClassPrivateMethod") {
  580. node.computed = false;
  581. }
  582. return this.finishNode(node, "MethodDefinition");
  583. }
  584. parseClassProperty(...args) {
  585. const propertyNode = super.parseClassProperty(...args);
  586. {
  587. if (!this.getPluginOption("estree", "classFeatures")) {
  588. return propertyNode;
  589. }
  590. }
  591. propertyNode.type = "PropertyDefinition";
  592. return propertyNode;
  593. }
  594. parseClassPrivateProperty(...args) {
  595. const propertyNode = super.parseClassPrivateProperty(...args);
  596. {
  597. if (!this.getPluginOption("estree", "classFeatures")) {
  598. return propertyNode;
  599. }
  600. }
  601. propertyNode.type = "PropertyDefinition";
  602. propertyNode.computed = false;
  603. return propertyNode;
  604. }
  605. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  606. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  607. if (node) {
  608. node.type = "Property";
  609. if (node.kind === "method") {
  610. node.kind = "init";
  611. }
  612. node.shorthand = false;
  613. }
  614. return node;
  615. }
  616. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  617. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  618. if (node) {
  619. node.kind = "init";
  620. node.type = "Property";
  621. }
  622. return node;
  623. }
  624. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  625. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  626. }
  627. isAssignable(node, isBinding) {
  628. if (node != null && this.isObjectProperty(node)) {
  629. return this.isAssignable(node.value, isBinding);
  630. }
  631. return super.isAssignable(node, isBinding);
  632. }
  633. toAssignable(node, isLHS = false) {
  634. if (node != null && this.isObjectProperty(node)) {
  635. const {
  636. key,
  637. value
  638. } = node;
  639. if (this.isPrivateName(key)) {
  640. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  641. }
  642. this.toAssignable(value, isLHS);
  643. } else {
  644. super.toAssignable(node, isLHS);
  645. }
  646. }
  647. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  648. if (prop.kind === "get" || prop.kind === "set") {
  649. this.raise(Errors.PatternHasAccessor, {
  650. at: prop.key
  651. });
  652. } else if (prop.method) {
  653. this.raise(Errors.PatternHasMethod, {
  654. at: prop.key
  655. });
  656. } else {
  657. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  658. }
  659. }
  660. finishCallExpression(unfinished, optional) {
  661. const node = super.finishCallExpression(unfinished, optional);
  662. if (node.callee.type === "Import") {
  663. node.type = "ImportExpression";
  664. node.source = node.arguments[0];
  665. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  666. var _node$arguments$;
  667. node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  668. }
  669. delete node.arguments;
  670. delete node.callee;
  671. }
  672. return node;
  673. }
  674. toReferencedArguments(node) {
  675. if (node.type === "ImportExpression") {
  676. return;
  677. }
  678. super.toReferencedArguments(node);
  679. }
  680. parseExport(unfinished, decorators) {
  681. const exportStartLoc = this.state.lastTokStartLoc;
  682. const node = super.parseExport(unfinished, decorators);
  683. switch (node.type) {
  684. case "ExportAllDeclaration":
  685. node.exported = null;
  686. break;
  687. case "ExportNamedDeclaration":
  688. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  689. node.type = "ExportAllDeclaration";
  690. node.exported = node.specifiers[0].exported;
  691. delete node.specifiers;
  692. }
  693. case "ExportDefaultDeclaration":
  694. {
  695. var _declaration$decorato;
  696. const {
  697. declaration
  698. } = node;
  699. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  700. this.resetStartLocation(node, exportStartLoc);
  701. }
  702. }
  703. break;
  704. }
  705. return node;
  706. }
  707. parseSubscript(base, startLoc, noCalls, state) {
  708. const node = super.parseSubscript(base, startLoc, noCalls, state);
  709. if (state.optionalChainMember) {
  710. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  711. node.type = node.type.substring(8);
  712. }
  713. if (state.stop) {
  714. const chain = this.startNodeAtNode(node);
  715. chain.expression = node;
  716. return this.finishNode(chain, "ChainExpression");
  717. }
  718. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  719. node.optional = false;
  720. }
  721. return node;
  722. }
  723. hasPropertyAsPrivateName(node) {
  724. if (node.type === "ChainExpression") {
  725. node = node.expression;
  726. }
  727. return super.hasPropertyAsPrivateName(node);
  728. }
  729. isObjectProperty(node) {
  730. return node.type === "Property" && node.kind === "init" && !node.method;
  731. }
  732. isObjectMethod(node) {
  733. return node.method || node.kind === "get" || node.kind === "set";
  734. }
  735. finishNodeAt(node, type, endLoc) {
  736. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  737. }
  738. resetStartLocation(node, startLoc) {
  739. super.resetStartLocation(node, startLoc);
  740. toESTreeLocation(node);
  741. }
  742. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  743. super.resetEndLocation(node, endLoc);
  744. toESTreeLocation(node);
  745. }
  746. };
  747. class TokContext {
  748. constructor(token, preserveSpace) {
  749. this.token = void 0;
  750. this.preserveSpace = void 0;
  751. this.token = token;
  752. this.preserveSpace = !!preserveSpace;
  753. }
  754. }
  755. const types = {
  756. brace: new TokContext("{"),
  757. j_oTag: new TokContext("<tag"),
  758. j_cTag: new TokContext("</tag"),
  759. j_expr: new TokContext("<tag>...</tag>", true)
  760. };
  761. {
  762. types.template = new TokContext("`", true);
  763. }
  764. const beforeExpr = true;
  765. const startsExpr = true;
  766. const isLoop = true;
  767. const isAssign = true;
  768. const prefix = true;
  769. const postfix = true;
  770. class ExportedTokenType {
  771. constructor(label, conf = {}) {
  772. this.label = void 0;
  773. this.keyword = void 0;
  774. this.beforeExpr = void 0;
  775. this.startsExpr = void 0;
  776. this.rightAssociative = void 0;
  777. this.isLoop = void 0;
  778. this.isAssign = void 0;
  779. this.prefix = void 0;
  780. this.postfix = void 0;
  781. this.binop = void 0;
  782. this.label = label;
  783. this.keyword = conf.keyword;
  784. this.beforeExpr = !!conf.beforeExpr;
  785. this.startsExpr = !!conf.startsExpr;
  786. this.rightAssociative = !!conf.rightAssociative;
  787. this.isLoop = !!conf.isLoop;
  788. this.isAssign = !!conf.isAssign;
  789. this.prefix = !!conf.prefix;
  790. this.postfix = !!conf.postfix;
  791. this.binop = conf.binop != null ? conf.binop : null;
  792. {
  793. this.updateContext = null;
  794. }
  795. }
  796. }
  797. const keywords$1 = new Map();
  798. function createKeyword(name, options = {}) {
  799. options.keyword = name;
  800. const token = createToken(name, options);
  801. keywords$1.set(name, token);
  802. return token;
  803. }
  804. function createBinop(name, binop) {
  805. return createToken(name, {
  806. beforeExpr,
  807. binop
  808. });
  809. }
  810. let tokenTypeCounter = -1;
  811. const tokenTypes = [];
  812. const tokenLabels = [];
  813. const tokenBinops = [];
  814. const tokenBeforeExprs = [];
  815. const tokenStartsExprs = [];
  816. const tokenPrefixes = [];
  817. function createToken(name, options = {}) {
  818. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  819. ++tokenTypeCounter;
  820. tokenLabels.push(name);
  821. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  822. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  823. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  824. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  825. tokenTypes.push(new ExportedTokenType(name, options));
  826. return tokenTypeCounter;
  827. }
  828. function createKeywordLike(name, options = {}) {
  829. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  830. ++tokenTypeCounter;
  831. keywords$1.set(name, tokenTypeCounter);
  832. tokenLabels.push(name);
  833. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  834. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  835. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  836. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  837. tokenTypes.push(new ExportedTokenType("name", options));
  838. return tokenTypeCounter;
  839. }
  840. const tt = {
  841. bracketL: createToken("[", {
  842. beforeExpr,
  843. startsExpr
  844. }),
  845. bracketHashL: createToken("#[", {
  846. beforeExpr,
  847. startsExpr
  848. }),
  849. bracketBarL: createToken("[|", {
  850. beforeExpr,
  851. startsExpr
  852. }),
  853. bracketR: createToken("]"),
  854. bracketBarR: createToken("|]"),
  855. braceL: createToken("{", {
  856. beforeExpr,
  857. startsExpr
  858. }),
  859. braceBarL: createToken("{|", {
  860. beforeExpr,
  861. startsExpr
  862. }),
  863. braceHashL: createToken("#{", {
  864. beforeExpr,
  865. startsExpr
  866. }),
  867. braceR: createToken("}"),
  868. braceBarR: createToken("|}"),
  869. parenL: createToken("(", {
  870. beforeExpr,
  871. startsExpr
  872. }),
  873. parenR: createToken(")"),
  874. comma: createToken(",", {
  875. beforeExpr
  876. }),
  877. semi: createToken(";", {
  878. beforeExpr
  879. }),
  880. colon: createToken(":", {
  881. beforeExpr
  882. }),
  883. doubleColon: createToken("::", {
  884. beforeExpr
  885. }),
  886. dot: createToken("."),
  887. question: createToken("?", {
  888. beforeExpr
  889. }),
  890. questionDot: createToken("?."),
  891. arrow: createToken("=>", {
  892. beforeExpr
  893. }),
  894. template: createToken("template"),
  895. ellipsis: createToken("...", {
  896. beforeExpr
  897. }),
  898. backQuote: createToken("`", {
  899. startsExpr
  900. }),
  901. dollarBraceL: createToken("${", {
  902. beforeExpr,
  903. startsExpr
  904. }),
  905. templateTail: createToken("...`", {
  906. startsExpr
  907. }),
  908. templateNonTail: createToken("...${", {
  909. beforeExpr,
  910. startsExpr
  911. }),
  912. at: createToken("@"),
  913. hash: createToken("#", {
  914. startsExpr
  915. }),
  916. interpreterDirective: createToken("#!..."),
  917. eq: createToken("=", {
  918. beforeExpr,
  919. isAssign
  920. }),
  921. assign: createToken("_=", {
  922. beforeExpr,
  923. isAssign
  924. }),
  925. slashAssign: createToken("_=", {
  926. beforeExpr,
  927. isAssign
  928. }),
  929. xorAssign: createToken("_=", {
  930. beforeExpr,
  931. isAssign
  932. }),
  933. moduloAssign: createToken("_=", {
  934. beforeExpr,
  935. isAssign
  936. }),
  937. incDec: createToken("++/--", {
  938. prefix,
  939. postfix,
  940. startsExpr
  941. }),
  942. bang: createToken("!", {
  943. beforeExpr,
  944. prefix,
  945. startsExpr
  946. }),
  947. tilde: createToken("~", {
  948. beforeExpr,
  949. prefix,
  950. startsExpr
  951. }),
  952. doubleCaret: createToken("^^", {
  953. startsExpr
  954. }),
  955. doubleAt: createToken("@@", {
  956. startsExpr
  957. }),
  958. pipeline: createBinop("|>", 0),
  959. nullishCoalescing: createBinop("??", 1),
  960. logicalOR: createBinop("||", 1),
  961. logicalAND: createBinop("&&", 2),
  962. bitwiseOR: createBinop("|", 3),
  963. bitwiseXOR: createBinop("^", 4),
  964. bitwiseAND: createBinop("&", 5),
  965. equality: createBinop("==/!=/===/!==", 6),
  966. lt: createBinop("</>/<=/>=", 7),
  967. gt: createBinop("</>/<=/>=", 7),
  968. relational: createBinop("</>/<=/>=", 7),
  969. bitShift: createBinop("<</>>/>>>", 8),
  970. bitShiftL: createBinop("<</>>/>>>", 8),
  971. bitShiftR: createBinop("<</>>/>>>", 8),
  972. plusMin: createToken("+/-", {
  973. beforeExpr,
  974. binop: 9,
  975. prefix,
  976. startsExpr
  977. }),
  978. modulo: createToken("%", {
  979. binop: 10,
  980. startsExpr
  981. }),
  982. star: createToken("*", {
  983. binop: 10
  984. }),
  985. slash: createBinop("/", 10),
  986. exponent: createToken("**", {
  987. beforeExpr,
  988. binop: 11,
  989. rightAssociative: true
  990. }),
  991. _in: createKeyword("in", {
  992. beforeExpr,
  993. binop: 7
  994. }),
  995. _instanceof: createKeyword("instanceof", {
  996. beforeExpr,
  997. binop: 7
  998. }),
  999. _break: createKeyword("break"),
  1000. _case: createKeyword("case", {
  1001. beforeExpr
  1002. }),
  1003. _catch: createKeyword("catch"),
  1004. _continue: createKeyword("continue"),
  1005. _debugger: createKeyword("debugger"),
  1006. _default: createKeyword("default", {
  1007. beforeExpr
  1008. }),
  1009. _else: createKeyword("else", {
  1010. beforeExpr
  1011. }),
  1012. _finally: createKeyword("finally"),
  1013. _function: createKeyword("function", {
  1014. startsExpr
  1015. }),
  1016. _if: createKeyword("if"),
  1017. _return: createKeyword("return", {
  1018. beforeExpr
  1019. }),
  1020. _switch: createKeyword("switch"),
  1021. _throw: createKeyword("throw", {
  1022. beforeExpr,
  1023. prefix,
  1024. startsExpr
  1025. }),
  1026. _try: createKeyword("try"),
  1027. _var: createKeyword("var"),
  1028. _const: createKeyword("const"),
  1029. _with: createKeyword("with"),
  1030. _new: createKeyword("new", {
  1031. beforeExpr,
  1032. startsExpr
  1033. }),
  1034. _this: createKeyword("this", {
  1035. startsExpr
  1036. }),
  1037. _super: createKeyword("super", {
  1038. startsExpr
  1039. }),
  1040. _class: createKeyword("class", {
  1041. startsExpr
  1042. }),
  1043. _extends: createKeyword("extends", {
  1044. beforeExpr
  1045. }),
  1046. _export: createKeyword("export"),
  1047. _import: createKeyword("import", {
  1048. startsExpr
  1049. }),
  1050. _null: createKeyword("null", {
  1051. startsExpr
  1052. }),
  1053. _true: createKeyword("true", {
  1054. startsExpr
  1055. }),
  1056. _false: createKeyword("false", {
  1057. startsExpr
  1058. }),
  1059. _typeof: createKeyword("typeof", {
  1060. beforeExpr,
  1061. prefix,
  1062. startsExpr
  1063. }),
  1064. _void: createKeyword("void", {
  1065. beforeExpr,
  1066. prefix,
  1067. startsExpr
  1068. }),
  1069. _delete: createKeyword("delete", {
  1070. beforeExpr,
  1071. prefix,
  1072. startsExpr
  1073. }),
  1074. _do: createKeyword("do", {
  1075. isLoop,
  1076. beforeExpr
  1077. }),
  1078. _for: createKeyword("for", {
  1079. isLoop
  1080. }),
  1081. _while: createKeyword("while", {
  1082. isLoop
  1083. }),
  1084. _as: createKeywordLike("as", {
  1085. startsExpr
  1086. }),
  1087. _assert: createKeywordLike("assert", {
  1088. startsExpr
  1089. }),
  1090. _async: createKeywordLike("async", {
  1091. startsExpr
  1092. }),
  1093. _await: createKeywordLike("await", {
  1094. startsExpr
  1095. }),
  1096. _from: createKeywordLike("from", {
  1097. startsExpr
  1098. }),
  1099. _get: createKeywordLike("get", {
  1100. startsExpr
  1101. }),
  1102. _let: createKeywordLike("let", {
  1103. startsExpr
  1104. }),
  1105. _meta: createKeywordLike("meta", {
  1106. startsExpr
  1107. }),
  1108. _of: createKeywordLike("of", {
  1109. startsExpr
  1110. }),
  1111. _sent: createKeywordLike("sent", {
  1112. startsExpr
  1113. }),
  1114. _set: createKeywordLike("set", {
  1115. startsExpr
  1116. }),
  1117. _static: createKeywordLike("static", {
  1118. startsExpr
  1119. }),
  1120. _using: createKeywordLike("using", {
  1121. startsExpr
  1122. }),
  1123. _yield: createKeywordLike("yield", {
  1124. startsExpr
  1125. }),
  1126. _asserts: createKeywordLike("asserts", {
  1127. startsExpr
  1128. }),
  1129. _checks: createKeywordLike("checks", {
  1130. startsExpr
  1131. }),
  1132. _exports: createKeywordLike("exports", {
  1133. startsExpr
  1134. }),
  1135. _global: createKeywordLike("global", {
  1136. startsExpr
  1137. }),
  1138. _implements: createKeywordLike("implements", {
  1139. startsExpr
  1140. }),
  1141. _intrinsic: createKeywordLike("intrinsic", {
  1142. startsExpr
  1143. }),
  1144. _infer: createKeywordLike("infer", {
  1145. startsExpr
  1146. }),
  1147. _is: createKeywordLike("is", {
  1148. startsExpr
  1149. }),
  1150. _mixins: createKeywordLike("mixins", {
  1151. startsExpr
  1152. }),
  1153. _proto: createKeywordLike("proto", {
  1154. startsExpr
  1155. }),
  1156. _require: createKeywordLike("require", {
  1157. startsExpr
  1158. }),
  1159. _satisfies: createKeywordLike("satisfies", {
  1160. startsExpr
  1161. }),
  1162. _keyof: createKeywordLike("keyof", {
  1163. startsExpr
  1164. }),
  1165. _readonly: createKeywordLike("readonly", {
  1166. startsExpr
  1167. }),
  1168. _unique: createKeywordLike("unique", {
  1169. startsExpr
  1170. }),
  1171. _abstract: createKeywordLike("abstract", {
  1172. startsExpr
  1173. }),
  1174. _declare: createKeywordLike("declare", {
  1175. startsExpr
  1176. }),
  1177. _enum: createKeywordLike("enum", {
  1178. startsExpr
  1179. }),
  1180. _module: createKeywordLike("module", {
  1181. startsExpr
  1182. }),
  1183. _namespace: createKeywordLike("namespace", {
  1184. startsExpr
  1185. }),
  1186. _interface: createKeywordLike("interface", {
  1187. startsExpr
  1188. }),
  1189. _type: createKeywordLike("type", {
  1190. startsExpr
  1191. }),
  1192. _opaque: createKeywordLike("opaque", {
  1193. startsExpr
  1194. }),
  1195. name: createToken("name", {
  1196. startsExpr
  1197. }),
  1198. string: createToken("string", {
  1199. startsExpr
  1200. }),
  1201. num: createToken("num", {
  1202. startsExpr
  1203. }),
  1204. bigint: createToken("bigint", {
  1205. startsExpr
  1206. }),
  1207. decimal: createToken("decimal", {
  1208. startsExpr
  1209. }),
  1210. regexp: createToken("regexp", {
  1211. startsExpr
  1212. }),
  1213. privateName: createToken("#name", {
  1214. startsExpr
  1215. }),
  1216. eof: createToken("eof"),
  1217. jsxName: createToken("jsxName"),
  1218. jsxText: createToken("jsxText", {
  1219. beforeExpr: true
  1220. }),
  1221. jsxTagStart: createToken("jsxTagStart", {
  1222. startsExpr: true
  1223. }),
  1224. jsxTagEnd: createToken("jsxTagEnd"),
  1225. placeholder: createToken("%%", {
  1226. startsExpr: true
  1227. })
  1228. };
  1229. function tokenIsIdentifier(token) {
  1230. return token >= 93 && token <= 130;
  1231. }
  1232. function tokenKeywordOrIdentifierIsKeyword(token) {
  1233. return token <= 92;
  1234. }
  1235. function tokenIsKeywordOrIdentifier(token) {
  1236. return token >= 58 && token <= 130;
  1237. }
  1238. function tokenIsLiteralPropertyName(token) {
  1239. return token >= 58 && token <= 134;
  1240. }
  1241. function tokenComesBeforeExpression(token) {
  1242. return tokenBeforeExprs[token];
  1243. }
  1244. function tokenCanStartExpression(token) {
  1245. return tokenStartsExprs[token];
  1246. }
  1247. function tokenIsAssignment(token) {
  1248. return token >= 29 && token <= 33;
  1249. }
  1250. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1251. return token >= 127 && token <= 129;
  1252. }
  1253. function tokenIsLoop(token) {
  1254. return token >= 90 && token <= 92;
  1255. }
  1256. function tokenIsKeyword(token) {
  1257. return token >= 58 && token <= 92;
  1258. }
  1259. function tokenIsOperator(token) {
  1260. return token >= 39 && token <= 59;
  1261. }
  1262. function tokenIsPostfix(token) {
  1263. return token === 34;
  1264. }
  1265. function tokenIsPrefix(token) {
  1266. return tokenPrefixes[token];
  1267. }
  1268. function tokenIsTSTypeOperator(token) {
  1269. return token >= 119 && token <= 121;
  1270. }
  1271. function tokenIsTSDeclarationStart(token) {
  1272. return token >= 122 && token <= 128;
  1273. }
  1274. function tokenLabelName(token) {
  1275. return tokenLabels[token];
  1276. }
  1277. function tokenOperatorPrecedence(token) {
  1278. return tokenBinops[token];
  1279. }
  1280. function tokenIsRightAssociative(token) {
  1281. return token === 57;
  1282. }
  1283. function tokenIsTemplate(token) {
  1284. return token >= 24 && token <= 25;
  1285. }
  1286. function getExportedToken(token) {
  1287. return tokenTypes[token];
  1288. }
  1289. {
  1290. tokenTypes[8].updateContext = context => {
  1291. context.pop();
  1292. };
  1293. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1294. context.push(types.brace);
  1295. };
  1296. tokenTypes[22].updateContext = context => {
  1297. if (context[context.length - 1] === types.template) {
  1298. context.pop();
  1299. } else {
  1300. context.push(types.template);
  1301. }
  1302. };
  1303. tokenTypes[140].updateContext = context => {
  1304. context.push(types.j_expr, types.j_oTag);
  1305. };
  1306. }
  1307. 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-\u1c88\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-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\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";
  1308. let nonASCIIidentifierChars = "\u200c\u200d\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\u0898-\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\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\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";
  1309. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1310. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1311. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1312. 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, 68, 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, 349, 41, 7, 1, 79, 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, 159, 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, 264, 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, 4026, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 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, 757, 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, 3104, 541, 1507, 4938, 6, 4191];
  1313. 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, 370, 1, 81, 2, 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, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 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, 406, 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, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 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, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  1314. function isInAstralSet(code, set) {
  1315. let pos = 0x10000;
  1316. for (let i = 0, length = set.length; i < length; i += 2) {
  1317. pos += set[i];
  1318. if (pos > code) return false;
  1319. pos += set[i + 1];
  1320. if (pos >= code) return true;
  1321. }
  1322. return false;
  1323. }
  1324. function isIdentifierStart(code) {
  1325. if (code < 65) return code === 36;
  1326. if (code <= 90) return true;
  1327. if (code < 97) return code === 95;
  1328. if (code <= 122) return true;
  1329. if (code <= 0xffff) {
  1330. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1331. }
  1332. return isInAstralSet(code, astralIdentifierStartCodes);
  1333. }
  1334. function isIdentifierChar(code) {
  1335. if (code < 48) return code === 36;
  1336. if (code < 58) return true;
  1337. if (code < 65) return false;
  1338. if (code <= 90) return true;
  1339. if (code < 97) return code === 95;
  1340. if (code <= 122) return true;
  1341. if (code <= 0xffff) {
  1342. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1343. }
  1344. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1345. }
  1346. const reservedWords = {
  1347. 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"],
  1348. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1349. strictBind: ["eval", "arguments"]
  1350. };
  1351. const keywords = new Set(reservedWords.keyword);
  1352. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1353. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1354. function isReservedWord(word, inModule) {
  1355. return inModule && word === "await" || word === "enum";
  1356. }
  1357. function isStrictReservedWord(word, inModule) {
  1358. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1359. }
  1360. function isStrictBindOnlyReservedWord(word) {
  1361. return reservedWordsStrictBindSet.has(word);
  1362. }
  1363. function isStrictBindReservedWord(word, inModule) {
  1364. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1365. }
  1366. function isKeyword(word) {
  1367. return keywords.has(word);
  1368. }
  1369. function isIteratorStart(current, next, next2) {
  1370. return current === 64 && next === 64 && isIdentifierStart(next2);
  1371. }
  1372. 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"]);
  1373. function canBeReservedWord(word) {
  1374. return reservedWordLikeSet.has(word);
  1375. }
  1376. class Scope {
  1377. constructor(flags) {
  1378. this.var = new Set();
  1379. this.lexical = new Set();
  1380. this.functions = new Set();
  1381. this.flags = flags;
  1382. }
  1383. }
  1384. class ScopeHandler {
  1385. constructor(parser, inModule) {
  1386. this.parser = void 0;
  1387. this.scopeStack = [];
  1388. this.inModule = void 0;
  1389. this.undefinedExports = new Map();
  1390. this.parser = parser;
  1391. this.inModule = inModule;
  1392. }
  1393. get inTopLevel() {
  1394. return (this.currentScope().flags & 1) > 0;
  1395. }
  1396. get inFunction() {
  1397. return (this.currentVarScopeFlags() & 2) > 0;
  1398. }
  1399. get allowSuper() {
  1400. return (this.currentThisScopeFlags() & 16) > 0;
  1401. }
  1402. get allowDirectSuper() {
  1403. return (this.currentThisScopeFlags() & 32) > 0;
  1404. }
  1405. get inClass() {
  1406. return (this.currentThisScopeFlags() & 64) > 0;
  1407. }
  1408. get inClassAndNotInNonArrowFunction() {
  1409. const flags = this.currentThisScopeFlags();
  1410. return (flags & 64) > 0 && (flags & 2) === 0;
  1411. }
  1412. get inStaticBlock() {
  1413. for (let i = this.scopeStack.length - 1;; i--) {
  1414. const {
  1415. flags
  1416. } = this.scopeStack[i];
  1417. if (flags & 128) {
  1418. return true;
  1419. }
  1420. if (flags & (387 | 64)) {
  1421. return false;
  1422. }
  1423. }
  1424. }
  1425. get inNonArrowFunction() {
  1426. return (this.currentThisScopeFlags() & 2) > 0;
  1427. }
  1428. get treatFunctionsAsVar() {
  1429. return this.treatFunctionsAsVarInScope(this.currentScope());
  1430. }
  1431. createScope(flags) {
  1432. return new Scope(flags);
  1433. }
  1434. enter(flags) {
  1435. this.scopeStack.push(this.createScope(flags));
  1436. }
  1437. exit() {
  1438. const scope = this.scopeStack.pop();
  1439. return scope.flags;
  1440. }
  1441. treatFunctionsAsVarInScope(scope) {
  1442. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1443. }
  1444. declareName(name, bindingType, loc) {
  1445. let scope = this.currentScope();
  1446. if (bindingType & 8 || bindingType & 16) {
  1447. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1448. if (bindingType & 16) {
  1449. scope.functions.add(name);
  1450. } else {
  1451. scope.lexical.add(name);
  1452. }
  1453. if (bindingType & 8) {
  1454. this.maybeExportDefined(scope, name);
  1455. }
  1456. } else if (bindingType & 4) {
  1457. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1458. scope = this.scopeStack[i];
  1459. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1460. scope.var.add(name);
  1461. this.maybeExportDefined(scope, name);
  1462. if (scope.flags & 387) break;
  1463. }
  1464. }
  1465. if (this.parser.inModule && scope.flags & 1) {
  1466. this.undefinedExports.delete(name);
  1467. }
  1468. }
  1469. maybeExportDefined(scope, name) {
  1470. if (this.parser.inModule && scope.flags & 1) {
  1471. this.undefinedExports.delete(name);
  1472. }
  1473. }
  1474. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1475. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1476. this.parser.raise(Errors.VarRedeclaration, {
  1477. at: loc,
  1478. identifierName: name
  1479. });
  1480. }
  1481. }
  1482. isRedeclaredInScope(scope, name, bindingType) {
  1483. if (!(bindingType & 1)) return false;
  1484. if (bindingType & 8) {
  1485. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  1486. }
  1487. if (bindingType & 16) {
  1488. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  1489. }
  1490. return scope.lexical.has(name) && !(scope.flags & 8 && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  1491. }
  1492. checkLocalExport(id) {
  1493. const {
  1494. name
  1495. } = id;
  1496. const topLevelScope = this.scopeStack[0];
  1497. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  1498. this.undefinedExports.set(name, id.loc.start);
  1499. }
  1500. }
  1501. currentScope() {
  1502. return this.scopeStack[this.scopeStack.length - 1];
  1503. }
  1504. currentVarScopeFlags() {
  1505. for (let i = this.scopeStack.length - 1;; i--) {
  1506. const {
  1507. flags
  1508. } = this.scopeStack[i];
  1509. if (flags & 387) {
  1510. return flags;
  1511. }
  1512. }
  1513. }
  1514. currentThisScopeFlags() {
  1515. for (let i = this.scopeStack.length - 1;; i--) {
  1516. const {
  1517. flags
  1518. } = this.scopeStack[i];
  1519. if (flags & (387 | 64) && !(flags & 4)) {
  1520. return flags;
  1521. }
  1522. }
  1523. }
  1524. }
  1525. class FlowScope extends Scope {
  1526. constructor(...args) {
  1527. super(...args);
  1528. this.declareFunctions = new Set();
  1529. }
  1530. }
  1531. class FlowScopeHandler extends ScopeHandler {
  1532. createScope(flags) {
  1533. return new FlowScope(flags);
  1534. }
  1535. declareName(name, bindingType, loc) {
  1536. const scope = this.currentScope();
  1537. if (bindingType & 2048) {
  1538. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1539. this.maybeExportDefined(scope, name);
  1540. scope.declareFunctions.add(name);
  1541. return;
  1542. }
  1543. super.declareName(name, bindingType, loc);
  1544. }
  1545. isRedeclaredInScope(scope, name, bindingType) {
  1546. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1547. if (bindingType & 2048) {
  1548. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  1549. }
  1550. return false;
  1551. }
  1552. checkLocalExport(id) {
  1553. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1554. super.checkLocalExport(id);
  1555. }
  1556. }
  1557. }
  1558. class BaseParser {
  1559. constructor() {
  1560. this.sawUnambiguousESM = false;
  1561. this.ambiguousScriptDifferentAst = false;
  1562. }
  1563. hasPlugin(pluginConfig) {
  1564. if (typeof pluginConfig === "string") {
  1565. return this.plugins.has(pluginConfig);
  1566. } else {
  1567. const [pluginName, pluginOptions] = pluginConfig;
  1568. if (!this.hasPlugin(pluginName)) {
  1569. return false;
  1570. }
  1571. const actualOptions = this.plugins.get(pluginName);
  1572. for (const key of Object.keys(pluginOptions)) {
  1573. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1574. return false;
  1575. }
  1576. }
  1577. return true;
  1578. }
  1579. }
  1580. getPluginOption(plugin, name) {
  1581. var _this$plugins$get;
  1582. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1583. }
  1584. }
  1585. function setTrailingComments(node, comments) {
  1586. if (node.trailingComments === undefined) {
  1587. node.trailingComments = comments;
  1588. } else {
  1589. node.trailingComments.unshift(...comments);
  1590. }
  1591. }
  1592. function setLeadingComments(node, comments) {
  1593. if (node.leadingComments === undefined) {
  1594. node.leadingComments = comments;
  1595. } else {
  1596. node.leadingComments.unshift(...comments);
  1597. }
  1598. }
  1599. function setInnerComments(node, comments) {
  1600. if (node.innerComments === undefined) {
  1601. node.innerComments = comments;
  1602. } else {
  1603. node.innerComments.unshift(...comments);
  1604. }
  1605. }
  1606. function adjustInnerComments(node, elements, commentWS) {
  1607. let lastElement = null;
  1608. let i = elements.length;
  1609. while (lastElement === null && i > 0) {
  1610. lastElement = elements[--i];
  1611. }
  1612. if (lastElement === null || lastElement.start > commentWS.start) {
  1613. setInnerComments(node, commentWS.comments);
  1614. } else {
  1615. setTrailingComments(lastElement, commentWS.comments);
  1616. }
  1617. }
  1618. class CommentsParser extends BaseParser {
  1619. addComment(comment) {
  1620. if (this.filename) comment.loc.filename = this.filename;
  1621. this.state.comments.push(comment);
  1622. }
  1623. processComment(node) {
  1624. const {
  1625. commentStack
  1626. } = this.state;
  1627. const commentStackLength = commentStack.length;
  1628. if (commentStackLength === 0) return;
  1629. let i = commentStackLength - 1;
  1630. const lastCommentWS = commentStack[i];
  1631. if (lastCommentWS.start === node.end) {
  1632. lastCommentWS.leadingNode = node;
  1633. i--;
  1634. }
  1635. const {
  1636. start: nodeStart
  1637. } = node;
  1638. for (; i >= 0; i--) {
  1639. const commentWS = commentStack[i];
  1640. const commentEnd = commentWS.end;
  1641. if (commentEnd > nodeStart) {
  1642. commentWS.containingNode = node;
  1643. this.finalizeComment(commentWS);
  1644. commentStack.splice(i, 1);
  1645. } else {
  1646. if (commentEnd === nodeStart) {
  1647. commentWS.trailingNode = node;
  1648. }
  1649. break;
  1650. }
  1651. }
  1652. }
  1653. finalizeComment(commentWS) {
  1654. const {
  1655. comments
  1656. } = commentWS;
  1657. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1658. if (commentWS.leadingNode !== null) {
  1659. setTrailingComments(commentWS.leadingNode, comments);
  1660. }
  1661. if (commentWS.trailingNode !== null) {
  1662. setLeadingComments(commentWS.trailingNode, comments);
  1663. }
  1664. } else {
  1665. const {
  1666. containingNode: node,
  1667. start: commentStart
  1668. } = commentWS;
  1669. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1670. switch (node.type) {
  1671. case "ObjectExpression":
  1672. case "ObjectPattern":
  1673. case "RecordExpression":
  1674. adjustInnerComments(node, node.properties, commentWS);
  1675. break;
  1676. case "CallExpression":
  1677. case "OptionalCallExpression":
  1678. adjustInnerComments(node, node.arguments, commentWS);
  1679. break;
  1680. case "FunctionDeclaration":
  1681. case "FunctionExpression":
  1682. case "ArrowFunctionExpression":
  1683. case "ObjectMethod":
  1684. case "ClassMethod":
  1685. case "ClassPrivateMethod":
  1686. adjustInnerComments(node, node.params, commentWS);
  1687. break;
  1688. case "ArrayExpression":
  1689. case "ArrayPattern":
  1690. case "TupleExpression":
  1691. adjustInnerComments(node, node.elements, commentWS);
  1692. break;
  1693. case "ExportNamedDeclaration":
  1694. case "ImportDeclaration":
  1695. adjustInnerComments(node, node.specifiers, commentWS);
  1696. break;
  1697. default:
  1698. {
  1699. setInnerComments(node, comments);
  1700. }
  1701. }
  1702. } else {
  1703. setInnerComments(node, comments);
  1704. }
  1705. }
  1706. }
  1707. finalizeRemainingComments() {
  1708. const {
  1709. commentStack
  1710. } = this.state;
  1711. for (let i = commentStack.length - 1; i >= 0; i--) {
  1712. this.finalizeComment(commentStack[i]);
  1713. }
  1714. this.state.commentStack = [];
  1715. }
  1716. resetPreviousNodeTrailingComments(node) {
  1717. const {
  1718. commentStack
  1719. } = this.state;
  1720. const {
  1721. length
  1722. } = commentStack;
  1723. if (length === 0) return;
  1724. const commentWS = commentStack[length - 1];
  1725. if (commentWS.leadingNode === node) {
  1726. commentWS.leadingNode = null;
  1727. }
  1728. }
  1729. resetPreviousIdentifierLeadingComments(node) {
  1730. const {
  1731. commentStack
  1732. } = this.state;
  1733. const {
  1734. length
  1735. } = commentStack;
  1736. if (length === 0) return;
  1737. if (commentStack[length - 1].trailingNode === node) {
  1738. commentStack[length - 1].trailingNode = null;
  1739. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1740. commentStack[length - 2].trailingNode = null;
  1741. }
  1742. }
  1743. takeSurroundingComments(node, start, end) {
  1744. const {
  1745. commentStack
  1746. } = this.state;
  1747. const commentStackLength = commentStack.length;
  1748. if (commentStackLength === 0) return;
  1749. let i = commentStackLength - 1;
  1750. for (; i >= 0; i--) {
  1751. const commentWS = commentStack[i];
  1752. const commentEnd = commentWS.end;
  1753. const commentStart = commentWS.start;
  1754. if (commentStart === end) {
  1755. commentWS.leadingNode = node;
  1756. } else if (commentEnd === start) {
  1757. commentWS.trailingNode = node;
  1758. } else if (commentEnd < start) {
  1759. break;
  1760. }
  1761. }
  1762. }
  1763. }
  1764. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1765. const lineBreakG = new RegExp(lineBreak.source, "g");
  1766. function isNewLine(code) {
  1767. switch (code) {
  1768. case 10:
  1769. case 13:
  1770. case 8232:
  1771. case 8233:
  1772. return true;
  1773. default:
  1774. return false;
  1775. }
  1776. }
  1777. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1778. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1779. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1780. function isWhitespace(code) {
  1781. switch (code) {
  1782. case 0x0009:
  1783. case 0x000b:
  1784. case 0x000c:
  1785. case 32:
  1786. case 160:
  1787. case 5760:
  1788. case 0x2000:
  1789. case 0x2001:
  1790. case 0x2002:
  1791. case 0x2003:
  1792. case 0x2004:
  1793. case 0x2005:
  1794. case 0x2006:
  1795. case 0x2007:
  1796. case 0x2008:
  1797. case 0x2009:
  1798. case 0x200a:
  1799. case 0x202f:
  1800. case 0x205f:
  1801. case 0x3000:
  1802. case 0xfeff:
  1803. return true;
  1804. default:
  1805. return false;
  1806. }
  1807. }
  1808. class State {
  1809. constructor() {
  1810. this.strict = void 0;
  1811. this.curLine = void 0;
  1812. this.lineStart = void 0;
  1813. this.startLoc = void 0;
  1814. this.endLoc = void 0;
  1815. this.errors = [];
  1816. this.potentialArrowAt = -1;
  1817. this.noArrowAt = [];
  1818. this.noArrowParamsConversionAt = [];
  1819. this.maybeInArrowParameters = false;
  1820. this.inType = false;
  1821. this.noAnonFunctionType = false;
  1822. this.hasFlowComment = false;
  1823. this.isAmbientContext = false;
  1824. this.inAbstractClass = false;
  1825. this.inDisallowConditionalTypesContext = false;
  1826. this.topicContext = {
  1827. maxNumOfResolvableTopics: 0,
  1828. maxTopicIndex: null
  1829. };
  1830. this.soloAwait = false;
  1831. this.inFSharpPipelineDirectBody = false;
  1832. this.labels = [];
  1833. this.comments = [];
  1834. this.commentStack = [];
  1835. this.pos = 0;
  1836. this.type = 137;
  1837. this.value = null;
  1838. this.start = 0;
  1839. this.end = 0;
  1840. this.lastTokEndLoc = null;
  1841. this.lastTokStartLoc = null;
  1842. this.lastTokStart = 0;
  1843. this.context = [types.brace];
  1844. this.canStartJSXElement = true;
  1845. this.containsEsc = false;
  1846. this.firstInvalidTemplateEscapePos = null;
  1847. this.strictErrors = new Map();
  1848. this.tokensLength = 0;
  1849. }
  1850. init({
  1851. strictMode,
  1852. sourceType,
  1853. startLine,
  1854. startColumn
  1855. }) {
  1856. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1857. this.curLine = startLine;
  1858. this.lineStart = -startColumn;
  1859. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1860. }
  1861. curPosition() {
  1862. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1863. }
  1864. clone(skipArrays) {
  1865. const state = new State();
  1866. const keys = Object.keys(this);
  1867. for (let i = 0, length = keys.length; i < length; i++) {
  1868. const key = keys[i];
  1869. let val = this[key];
  1870. if (!skipArrays && Array.isArray(val)) {
  1871. val = val.slice();
  1872. }
  1873. state[key] = val;
  1874. }
  1875. return state;
  1876. }
  1877. }
  1878. var _isDigit = function isDigit(code) {
  1879. return code >= 48 && code <= 57;
  1880. };
  1881. const forbiddenNumericSeparatorSiblings = {
  1882. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  1883. hex: new Set([46, 88, 95, 120])
  1884. };
  1885. const isAllowedNumericSeparatorSibling = {
  1886. bin: ch => ch === 48 || ch === 49,
  1887. oct: ch => ch >= 48 && ch <= 55,
  1888. dec: ch => ch >= 48 && ch <= 57,
  1889. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  1890. };
  1891. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  1892. const initialPos = pos;
  1893. const initialLineStart = lineStart;
  1894. const initialCurLine = curLine;
  1895. let out = "";
  1896. let firstInvalidLoc = null;
  1897. let chunkStart = pos;
  1898. const {
  1899. length
  1900. } = input;
  1901. for (;;) {
  1902. if (pos >= length) {
  1903. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1904. out += input.slice(chunkStart, pos);
  1905. break;
  1906. }
  1907. const ch = input.charCodeAt(pos);
  1908. if (isStringEnd(type, ch, input, pos)) {
  1909. out += input.slice(chunkStart, pos);
  1910. break;
  1911. }
  1912. if (ch === 92) {
  1913. out += input.slice(chunkStart, pos);
  1914. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  1915. if (res.ch === null && !firstInvalidLoc) {
  1916. firstInvalidLoc = {
  1917. pos,
  1918. lineStart,
  1919. curLine
  1920. };
  1921. } else {
  1922. out += res.ch;
  1923. }
  1924. ({
  1925. pos,
  1926. lineStart,
  1927. curLine
  1928. } = res);
  1929. chunkStart = pos;
  1930. } else if (ch === 8232 || ch === 8233) {
  1931. ++pos;
  1932. ++curLine;
  1933. lineStart = pos;
  1934. } else if (ch === 10 || ch === 13) {
  1935. if (type === "template") {
  1936. out += input.slice(chunkStart, pos) + "\n";
  1937. ++pos;
  1938. if (ch === 13 && input.charCodeAt(pos) === 10) {
  1939. ++pos;
  1940. }
  1941. ++curLine;
  1942. chunkStart = lineStart = pos;
  1943. } else {
  1944. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1945. }
  1946. } else {
  1947. ++pos;
  1948. }
  1949. }
  1950. return {
  1951. pos,
  1952. str: out,
  1953. firstInvalidLoc,
  1954. lineStart,
  1955. curLine,
  1956. containsInvalid: !!firstInvalidLoc
  1957. };
  1958. }
  1959. function isStringEnd(type, ch, input, pos) {
  1960. if (type === "template") {
  1961. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  1962. }
  1963. return ch === (type === "double" ? 34 : 39);
  1964. }
  1965. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  1966. const throwOnInvalid = !inTemplate;
  1967. pos++;
  1968. const res = ch => ({
  1969. pos,
  1970. ch,
  1971. lineStart,
  1972. curLine
  1973. });
  1974. const ch = input.charCodeAt(pos++);
  1975. switch (ch) {
  1976. case 110:
  1977. return res("\n");
  1978. case 114:
  1979. return res("\r");
  1980. case 120:
  1981. {
  1982. let code;
  1983. ({
  1984. code,
  1985. pos
  1986. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  1987. return res(code === null ? null : String.fromCharCode(code));
  1988. }
  1989. case 117:
  1990. {
  1991. let code;
  1992. ({
  1993. code,
  1994. pos
  1995. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  1996. return res(code === null ? null : String.fromCodePoint(code));
  1997. }
  1998. case 116:
  1999. return res("\t");
  2000. case 98:
  2001. return res("\b");
  2002. case 118:
  2003. return res("\u000b");
  2004. case 102:
  2005. return res("\f");
  2006. case 13:
  2007. if (input.charCodeAt(pos) === 10) {
  2008. ++pos;
  2009. }
  2010. case 10:
  2011. lineStart = pos;
  2012. ++curLine;
  2013. case 8232:
  2014. case 8233:
  2015. return res("");
  2016. case 56:
  2017. case 57:
  2018. if (inTemplate) {
  2019. return res(null);
  2020. } else {
  2021. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2022. }
  2023. default:
  2024. if (ch >= 48 && ch <= 55) {
  2025. const startPos = pos - 1;
  2026. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2027. let octalStr = match[0];
  2028. let octal = parseInt(octalStr, 8);
  2029. if (octal > 255) {
  2030. octalStr = octalStr.slice(0, -1);
  2031. octal = parseInt(octalStr, 8);
  2032. }
  2033. pos += octalStr.length - 1;
  2034. const next = input.charCodeAt(pos);
  2035. if (octalStr !== "0" || next === 56 || next === 57) {
  2036. if (inTemplate) {
  2037. return res(null);
  2038. } else {
  2039. errors.strictNumericEscape(startPos, lineStart, curLine);
  2040. }
  2041. }
  2042. return res(String.fromCharCode(octal));
  2043. }
  2044. return res(String.fromCharCode(ch));
  2045. }
  2046. }
  2047. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2048. const initialPos = pos;
  2049. let n;
  2050. ({
  2051. n,
  2052. pos
  2053. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2054. if (n === null) {
  2055. if (throwOnInvalid) {
  2056. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2057. } else {
  2058. pos = initialPos - 1;
  2059. }
  2060. }
  2061. return {
  2062. code: n,
  2063. pos
  2064. };
  2065. }
  2066. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2067. const start = pos;
  2068. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2069. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2070. let invalid = false;
  2071. let total = 0;
  2072. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2073. const code = input.charCodeAt(pos);
  2074. let val;
  2075. if (code === 95 && allowNumSeparator !== "bail") {
  2076. const prev = input.charCodeAt(pos - 1);
  2077. const next = input.charCodeAt(pos + 1);
  2078. if (!allowNumSeparator) {
  2079. if (bailOnError) return {
  2080. n: null,
  2081. pos
  2082. };
  2083. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2084. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2085. if (bailOnError) return {
  2086. n: null,
  2087. pos
  2088. };
  2089. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2090. }
  2091. ++pos;
  2092. continue;
  2093. }
  2094. if (code >= 97) {
  2095. val = code - 97 + 10;
  2096. } else if (code >= 65) {
  2097. val = code - 65 + 10;
  2098. } else if (_isDigit(code)) {
  2099. val = code - 48;
  2100. } else {
  2101. val = Infinity;
  2102. }
  2103. if (val >= radix) {
  2104. if (val <= 9 && bailOnError) {
  2105. return {
  2106. n: null,
  2107. pos
  2108. };
  2109. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2110. val = 0;
  2111. } else if (forceLen) {
  2112. val = 0;
  2113. invalid = true;
  2114. } else {
  2115. break;
  2116. }
  2117. }
  2118. ++pos;
  2119. total = total * radix + val;
  2120. }
  2121. if (pos === start || len != null && pos - start !== len || invalid) {
  2122. return {
  2123. n: null,
  2124. pos
  2125. };
  2126. }
  2127. return {
  2128. n: total,
  2129. pos
  2130. };
  2131. }
  2132. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2133. const ch = input.charCodeAt(pos);
  2134. let code;
  2135. if (ch === 123) {
  2136. ++pos;
  2137. ({
  2138. code,
  2139. pos
  2140. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2141. ++pos;
  2142. if (code !== null && code > 0x10ffff) {
  2143. if (throwOnInvalid) {
  2144. errors.invalidCodePoint(pos, lineStart, curLine);
  2145. } else {
  2146. return {
  2147. code: null,
  2148. pos
  2149. };
  2150. }
  2151. }
  2152. } else {
  2153. ({
  2154. code,
  2155. pos
  2156. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2157. }
  2158. return {
  2159. code,
  2160. pos
  2161. };
  2162. }
  2163. const _excluded = ["at"],
  2164. _excluded2 = ["at"];
  2165. function buildPosition(pos, lineStart, curLine) {
  2166. return new Position(curLine, pos - lineStart, pos);
  2167. }
  2168. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2169. class Token {
  2170. constructor(state) {
  2171. this.type = state.type;
  2172. this.value = state.value;
  2173. this.start = state.start;
  2174. this.end = state.end;
  2175. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2176. }
  2177. }
  2178. class Tokenizer extends CommentsParser {
  2179. constructor(options, input) {
  2180. super();
  2181. this.isLookahead = void 0;
  2182. this.tokens = [];
  2183. this.errorHandlers_readInt = {
  2184. invalidDigit: (pos, lineStart, curLine, radix) => {
  2185. if (!this.options.errorRecovery) return false;
  2186. this.raise(Errors.InvalidDigit, {
  2187. at: buildPosition(pos, lineStart, curLine),
  2188. radix
  2189. });
  2190. return true;
  2191. },
  2192. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2193. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2194. };
  2195. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2196. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2197. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2198. });
  2199. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2200. strictNumericEscape: (pos, lineStart, curLine) => {
  2201. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2202. at: buildPosition(pos, lineStart, curLine)
  2203. });
  2204. },
  2205. unterminated: (pos, lineStart, curLine) => {
  2206. throw this.raise(Errors.UnterminatedString, {
  2207. at: buildPosition(pos - 1, lineStart, curLine)
  2208. });
  2209. }
  2210. });
  2211. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2212. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2213. unterminated: (pos, lineStart, curLine) => {
  2214. throw this.raise(Errors.UnterminatedTemplate, {
  2215. at: buildPosition(pos, lineStart, curLine)
  2216. });
  2217. }
  2218. });
  2219. this.state = new State();
  2220. this.state.init(options);
  2221. this.input = input;
  2222. this.length = input.length;
  2223. this.isLookahead = false;
  2224. }
  2225. pushToken(token) {
  2226. this.tokens.length = this.state.tokensLength;
  2227. this.tokens.push(token);
  2228. ++this.state.tokensLength;
  2229. }
  2230. next() {
  2231. this.checkKeywordEscapes();
  2232. if (this.options.tokens) {
  2233. this.pushToken(new Token(this.state));
  2234. }
  2235. this.state.lastTokStart = this.state.start;
  2236. this.state.lastTokEndLoc = this.state.endLoc;
  2237. this.state.lastTokStartLoc = this.state.startLoc;
  2238. this.nextToken();
  2239. }
  2240. eat(type) {
  2241. if (this.match(type)) {
  2242. this.next();
  2243. return true;
  2244. } else {
  2245. return false;
  2246. }
  2247. }
  2248. match(type) {
  2249. return this.state.type === type;
  2250. }
  2251. createLookaheadState(state) {
  2252. return {
  2253. pos: state.pos,
  2254. value: null,
  2255. type: state.type,
  2256. start: state.start,
  2257. end: state.end,
  2258. context: [this.curContext()],
  2259. inType: state.inType,
  2260. startLoc: state.startLoc,
  2261. lastTokEndLoc: state.lastTokEndLoc,
  2262. curLine: state.curLine,
  2263. lineStart: state.lineStart,
  2264. curPosition: state.curPosition
  2265. };
  2266. }
  2267. lookahead() {
  2268. const old = this.state;
  2269. this.state = this.createLookaheadState(old);
  2270. this.isLookahead = true;
  2271. this.nextToken();
  2272. this.isLookahead = false;
  2273. const curr = this.state;
  2274. this.state = old;
  2275. return curr;
  2276. }
  2277. nextTokenStart() {
  2278. return this.nextTokenStartSince(this.state.pos);
  2279. }
  2280. nextTokenStartSince(pos) {
  2281. skipWhiteSpace.lastIndex = pos;
  2282. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2283. }
  2284. lookaheadCharCode() {
  2285. return this.input.charCodeAt(this.nextTokenStart());
  2286. }
  2287. nextTokenInLineStart() {
  2288. return this.nextTokenInLineStartSince(this.state.pos);
  2289. }
  2290. nextTokenInLineStartSince(pos) {
  2291. skipWhiteSpaceInLine.lastIndex = pos;
  2292. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2293. }
  2294. lookaheadInLineCharCode() {
  2295. return this.input.charCodeAt(this.nextTokenInLineStart());
  2296. }
  2297. codePointAtPos(pos) {
  2298. let cp = this.input.charCodeAt(pos);
  2299. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2300. const trail = this.input.charCodeAt(pos);
  2301. if ((trail & 0xfc00) === 0xdc00) {
  2302. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2303. }
  2304. }
  2305. return cp;
  2306. }
  2307. setStrict(strict) {
  2308. this.state.strict = strict;
  2309. if (strict) {
  2310. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  2311. at
  2312. }));
  2313. this.state.strictErrors.clear();
  2314. }
  2315. }
  2316. curContext() {
  2317. return this.state.context[this.state.context.length - 1];
  2318. }
  2319. nextToken() {
  2320. this.skipSpace();
  2321. this.state.start = this.state.pos;
  2322. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2323. if (this.state.pos >= this.length) {
  2324. this.finishToken(137);
  2325. return;
  2326. }
  2327. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2328. }
  2329. skipBlockComment(commentEnd) {
  2330. let startLoc;
  2331. if (!this.isLookahead) startLoc = this.state.curPosition();
  2332. const start = this.state.pos;
  2333. const end = this.input.indexOf(commentEnd, start + 2);
  2334. if (end === -1) {
  2335. throw this.raise(Errors.UnterminatedComment, {
  2336. at: this.state.curPosition()
  2337. });
  2338. }
  2339. this.state.pos = end + commentEnd.length;
  2340. lineBreakG.lastIndex = start + 2;
  2341. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2342. ++this.state.curLine;
  2343. this.state.lineStart = lineBreakG.lastIndex;
  2344. }
  2345. if (this.isLookahead) return;
  2346. const comment = {
  2347. type: "CommentBlock",
  2348. value: this.input.slice(start + 2, end),
  2349. start,
  2350. end: end + commentEnd.length,
  2351. loc: new SourceLocation(startLoc, this.state.curPosition())
  2352. };
  2353. if (this.options.tokens) this.pushToken(comment);
  2354. return comment;
  2355. }
  2356. skipLineComment(startSkip) {
  2357. const start = this.state.pos;
  2358. let startLoc;
  2359. if (!this.isLookahead) startLoc = this.state.curPosition();
  2360. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2361. if (this.state.pos < this.length) {
  2362. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2363. ch = this.input.charCodeAt(this.state.pos);
  2364. }
  2365. }
  2366. if (this.isLookahead) return;
  2367. const end = this.state.pos;
  2368. const value = this.input.slice(start + startSkip, end);
  2369. const comment = {
  2370. type: "CommentLine",
  2371. value,
  2372. start,
  2373. end,
  2374. loc: new SourceLocation(startLoc, this.state.curPosition())
  2375. };
  2376. if (this.options.tokens) this.pushToken(comment);
  2377. return comment;
  2378. }
  2379. skipSpace() {
  2380. const spaceStart = this.state.pos;
  2381. const comments = [];
  2382. loop: while (this.state.pos < this.length) {
  2383. const ch = this.input.charCodeAt(this.state.pos);
  2384. switch (ch) {
  2385. case 32:
  2386. case 160:
  2387. case 9:
  2388. ++this.state.pos;
  2389. break;
  2390. case 13:
  2391. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2392. ++this.state.pos;
  2393. }
  2394. case 10:
  2395. case 8232:
  2396. case 8233:
  2397. ++this.state.pos;
  2398. ++this.state.curLine;
  2399. this.state.lineStart = this.state.pos;
  2400. break;
  2401. case 47:
  2402. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2403. case 42:
  2404. {
  2405. const comment = this.skipBlockComment("*/");
  2406. if (comment !== undefined) {
  2407. this.addComment(comment);
  2408. if (this.options.attachComment) comments.push(comment);
  2409. }
  2410. break;
  2411. }
  2412. case 47:
  2413. {
  2414. const comment = this.skipLineComment(2);
  2415. if (comment !== undefined) {
  2416. this.addComment(comment);
  2417. if (this.options.attachComment) comments.push(comment);
  2418. }
  2419. break;
  2420. }
  2421. default:
  2422. break loop;
  2423. }
  2424. break;
  2425. default:
  2426. if (isWhitespace(ch)) {
  2427. ++this.state.pos;
  2428. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2429. const pos = this.state.pos;
  2430. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2431. const comment = this.skipLineComment(3);
  2432. if (comment !== undefined) {
  2433. this.addComment(comment);
  2434. if (this.options.attachComment) comments.push(comment);
  2435. }
  2436. } else {
  2437. break loop;
  2438. }
  2439. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2440. const pos = this.state.pos;
  2441. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2442. const comment = this.skipLineComment(4);
  2443. if (comment !== undefined) {
  2444. this.addComment(comment);
  2445. if (this.options.attachComment) comments.push(comment);
  2446. }
  2447. } else {
  2448. break loop;
  2449. }
  2450. } else {
  2451. break loop;
  2452. }
  2453. }
  2454. }
  2455. if (comments.length > 0) {
  2456. const end = this.state.pos;
  2457. const commentWhitespace = {
  2458. start: spaceStart,
  2459. end,
  2460. comments,
  2461. leadingNode: null,
  2462. trailingNode: null,
  2463. containingNode: null
  2464. };
  2465. this.state.commentStack.push(commentWhitespace);
  2466. }
  2467. }
  2468. finishToken(type, val) {
  2469. this.state.end = this.state.pos;
  2470. this.state.endLoc = this.state.curPosition();
  2471. const prevType = this.state.type;
  2472. this.state.type = type;
  2473. this.state.value = val;
  2474. if (!this.isLookahead) {
  2475. this.updateContext(prevType);
  2476. }
  2477. }
  2478. replaceToken(type) {
  2479. this.state.type = type;
  2480. this.updateContext();
  2481. }
  2482. readToken_numberSign() {
  2483. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2484. return;
  2485. }
  2486. const nextPos = this.state.pos + 1;
  2487. const next = this.codePointAtPos(nextPos);
  2488. if (next >= 48 && next <= 57) {
  2489. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  2490. at: this.state.curPosition()
  2491. });
  2492. }
  2493. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2494. this.expectPlugin("recordAndTuple");
  2495. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2496. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  2497. at: this.state.curPosition()
  2498. });
  2499. }
  2500. this.state.pos += 2;
  2501. if (next === 123) {
  2502. this.finishToken(7);
  2503. } else {
  2504. this.finishToken(1);
  2505. }
  2506. } else if (isIdentifierStart(next)) {
  2507. ++this.state.pos;
  2508. this.finishToken(136, this.readWord1(next));
  2509. } else if (next === 92) {
  2510. ++this.state.pos;
  2511. this.finishToken(136, this.readWord1());
  2512. } else {
  2513. this.finishOp(27, 1);
  2514. }
  2515. }
  2516. readToken_dot() {
  2517. const next = this.input.charCodeAt(this.state.pos + 1);
  2518. if (next >= 48 && next <= 57) {
  2519. this.readNumber(true);
  2520. return;
  2521. }
  2522. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2523. this.state.pos += 3;
  2524. this.finishToken(21);
  2525. } else {
  2526. ++this.state.pos;
  2527. this.finishToken(16);
  2528. }
  2529. }
  2530. readToken_slash() {
  2531. const next = this.input.charCodeAt(this.state.pos + 1);
  2532. if (next === 61) {
  2533. this.finishOp(31, 2);
  2534. } else {
  2535. this.finishOp(56, 1);
  2536. }
  2537. }
  2538. readToken_interpreter() {
  2539. if (this.state.pos !== 0 || this.length < 2) return false;
  2540. let ch = this.input.charCodeAt(this.state.pos + 1);
  2541. if (ch !== 33) return false;
  2542. const start = this.state.pos;
  2543. this.state.pos += 1;
  2544. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2545. ch = this.input.charCodeAt(this.state.pos);
  2546. }
  2547. const value = this.input.slice(start + 2, this.state.pos);
  2548. this.finishToken(28, value);
  2549. return true;
  2550. }
  2551. readToken_mult_modulo(code) {
  2552. let type = code === 42 ? 55 : 54;
  2553. let width = 1;
  2554. let next = this.input.charCodeAt(this.state.pos + 1);
  2555. if (code === 42 && next === 42) {
  2556. width++;
  2557. next = this.input.charCodeAt(this.state.pos + 2);
  2558. type = 57;
  2559. }
  2560. if (next === 61 && !this.state.inType) {
  2561. width++;
  2562. type = code === 37 ? 33 : 30;
  2563. }
  2564. this.finishOp(type, width);
  2565. }
  2566. readToken_pipe_amp(code) {
  2567. const next = this.input.charCodeAt(this.state.pos + 1);
  2568. if (next === code) {
  2569. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2570. this.finishOp(30, 3);
  2571. } else {
  2572. this.finishOp(code === 124 ? 41 : 42, 2);
  2573. }
  2574. return;
  2575. }
  2576. if (code === 124) {
  2577. if (next === 62) {
  2578. this.finishOp(39, 2);
  2579. return;
  2580. }
  2581. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2582. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2583. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  2584. at: this.state.curPosition()
  2585. });
  2586. }
  2587. this.state.pos += 2;
  2588. this.finishToken(9);
  2589. return;
  2590. }
  2591. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2592. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2593. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  2594. at: this.state.curPosition()
  2595. });
  2596. }
  2597. this.state.pos += 2;
  2598. this.finishToken(4);
  2599. return;
  2600. }
  2601. }
  2602. if (next === 61) {
  2603. this.finishOp(30, 2);
  2604. return;
  2605. }
  2606. this.finishOp(code === 124 ? 43 : 45, 1);
  2607. }
  2608. readToken_caret() {
  2609. const next = this.input.charCodeAt(this.state.pos + 1);
  2610. if (next === 61 && !this.state.inType) {
  2611. this.finishOp(32, 2);
  2612. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2613. proposal: "hack",
  2614. topicToken: "^^"
  2615. }])) {
  2616. this.finishOp(37, 2);
  2617. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2618. if (lookaheadCh === 94) {
  2619. this.unexpected();
  2620. }
  2621. } else {
  2622. this.finishOp(44, 1);
  2623. }
  2624. }
  2625. readToken_atSign() {
  2626. const next = this.input.charCodeAt(this.state.pos + 1);
  2627. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2628. proposal: "hack",
  2629. topicToken: "@@"
  2630. }])) {
  2631. this.finishOp(38, 2);
  2632. } else {
  2633. this.finishOp(26, 1);
  2634. }
  2635. }
  2636. readToken_plus_min(code) {
  2637. const next = this.input.charCodeAt(this.state.pos + 1);
  2638. if (next === code) {
  2639. this.finishOp(34, 2);
  2640. return;
  2641. }
  2642. if (next === 61) {
  2643. this.finishOp(30, 2);
  2644. } else {
  2645. this.finishOp(53, 1);
  2646. }
  2647. }
  2648. readToken_lt() {
  2649. const {
  2650. pos
  2651. } = this.state;
  2652. const next = this.input.charCodeAt(pos + 1);
  2653. if (next === 60) {
  2654. if (this.input.charCodeAt(pos + 2) === 61) {
  2655. this.finishOp(30, 3);
  2656. return;
  2657. }
  2658. this.finishOp(51, 2);
  2659. return;
  2660. }
  2661. if (next === 61) {
  2662. this.finishOp(49, 2);
  2663. return;
  2664. }
  2665. this.finishOp(47, 1);
  2666. }
  2667. readToken_gt() {
  2668. const {
  2669. pos
  2670. } = this.state;
  2671. const next = this.input.charCodeAt(pos + 1);
  2672. if (next === 62) {
  2673. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2674. if (this.input.charCodeAt(pos + size) === 61) {
  2675. this.finishOp(30, size + 1);
  2676. return;
  2677. }
  2678. this.finishOp(52, size);
  2679. return;
  2680. }
  2681. if (next === 61) {
  2682. this.finishOp(49, 2);
  2683. return;
  2684. }
  2685. this.finishOp(48, 1);
  2686. }
  2687. readToken_eq_excl(code) {
  2688. const next = this.input.charCodeAt(this.state.pos + 1);
  2689. if (next === 61) {
  2690. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2691. return;
  2692. }
  2693. if (code === 61 && next === 62) {
  2694. this.state.pos += 2;
  2695. this.finishToken(19);
  2696. return;
  2697. }
  2698. this.finishOp(code === 61 ? 29 : 35, 1);
  2699. }
  2700. readToken_question() {
  2701. const next = this.input.charCodeAt(this.state.pos + 1);
  2702. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2703. if (next === 63) {
  2704. if (next2 === 61) {
  2705. this.finishOp(30, 3);
  2706. } else {
  2707. this.finishOp(40, 2);
  2708. }
  2709. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2710. this.state.pos += 2;
  2711. this.finishToken(18);
  2712. } else {
  2713. ++this.state.pos;
  2714. this.finishToken(17);
  2715. }
  2716. }
  2717. getTokenFromCode(code) {
  2718. switch (code) {
  2719. case 46:
  2720. this.readToken_dot();
  2721. return;
  2722. case 40:
  2723. ++this.state.pos;
  2724. this.finishToken(10);
  2725. return;
  2726. case 41:
  2727. ++this.state.pos;
  2728. this.finishToken(11);
  2729. return;
  2730. case 59:
  2731. ++this.state.pos;
  2732. this.finishToken(13);
  2733. return;
  2734. case 44:
  2735. ++this.state.pos;
  2736. this.finishToken(12);
  2737. return;
  2738. case 91:
  2739. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2740. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2741. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  2742. at: this.state.curPosition()
  2743. });
  2744. }
  2745. this.state.pos += 2;
  2746. this.finishToken(2);
  2747. } else {
  2748. ++this.state.pos;
  2749. this.finishToken(0);
  2750. }
  2751. return;
  2752. case 93:
  2753. ++this.state.pos;
  2754. this.finishToken(3);
  2755. return;
  2756. case 123:
  2757. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2758. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2759. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  2760. at: this.state.curPosition()
  2761. });
  2762. }
  2763. this.state.pos += 2;
  2764. this.finishToken(6);
  2765. } else {
  2766. ++this.state.pos;
  2767. this.finishToken(5);
  2768. }
  2769. return;
  2770. case 125:
  2771. ++this.state.pos;
  2772. this.finishToken(8);
  2773. return;
  2774. case 58:
  2775. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2776. this.finishOp(15, 2);
  2777. } else {
  2778. ++this.state.pos;
  2779. this.finishToken(14);
  2780. }
  2781. return;
  2782. case 63:
  2783. this.readToken_question();
  2784. return;
  2785. case 96:
  2786. this.readTemplateToken();
  2787. return;
  2788. case 48:
  2789. {
  2790. const next = this.input.charCodeAt(this.state.pos + 1);
  2791. if (next === 120 || next === 88) {
  2792. this.readRadixNumber(16);
  2793. return;
  2794. }
  2795. if (next === 111 || next === 79) {
  2796. this.readRadixNumber(8);
  2797. return;
  2798. }
  2799. if (next === 98 || next === 66) {
  2800. this.readRadixNumber(2);
  2801. return;
  2802. }
  2803. }
  2804. case 49:
  2805. case 50:
  2806. case 51:
  2807. case 52:
  2808. case 53:
  2809. case 54:
  2810. case 55:
  2811. case 56:
  2812. case 57:
  2813. this.readNumber(false);
  2814. return;
  2815. case 34:
  2816. case 39:
  2817. this.readString(code);
  2818. return;
  2819. case 47:
  2820. this.readToken_slash();
  2821. return;
  2822. case 37:
  2823. case 42:
  2824. this.readToken_mult_modulo(code);
  2825. return;
  2826. case 124:
  2827. case 38:
  2828. this.readToken_pipe_amp(code);
  2829. return;
  2830. case 94:
  2831. this.readToken_caret();
  2832. return;
  2833. case 43:
  2834. case 45:
  2835. this.readToken_plus_min(code);
  2836. return;
  2837. case 60:
  2838. this.readToken_lt();
  2839. return;
  2840. case 62:
  2841. this.readToken_gt();
  2842. return;
  2843. case 61:
  2844. case 33:
  2845. this.readToken_eq_excl(code);
  2846. return;
  2847. case 126:
  2848. this.finishOp(36, 1);
  2849. return;
  2850. case 64:
  2851. this.readToken_atSign();
  2852. return;
  2853. case 35:
  2854. this.readToken_numberSign();
  2855. return;
  2856. case 92:
  2857. this.readWord();
  2858. return;
  2859. default:
  2860. if (isIdentifierStart(code)) {
  2861. this.readWord(code);
  2862. return;
  2863. }
  2864. }
  2865. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  2866. at: this.state.curPosition(),
  2867. unexpected: String.fromCodePoint(code)
  2868. });
  2869. }
  2870. finishOp(type, size) {
  2871. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2872. this.state.pos += size;
  2873. this.finishToken(type, str);
  2874. }
  2875. readRegexp() {
  2876. const startLoc = this.state.startLoc;
  2877. const start = this.state.start + 1;
  2878. let escaped, inClass;
  2879. let {
  2880. pos
  2881. } = this.state;
  2882. for (;; ++pos) {
  2883. if (pos >= this.length) {
  2884. throw this.raise(Errors.UnterminatedRegExp, {
  2885. at: createPositionWithColumnOffset(startLoc, 1)
  2886. });
  2887. }
  2888. const ch = this.input.charCodeAt(pos);
  2889. if (isNewLine(ch)) {
  2890. throw this.raise(Errors.UnterminatedRegExp, {
  2891. at: createPositionWithColumnOffset(startLoc, 1)
  2892. });
  2893. }
  2894. if (escaped) {
  2895. escaped = false;
  2896. } else {
  2897. if (ch === 91) {
  2898. inClass = true;
  2899. } else if (ch === 93 && inClass) {
  2900. inClass = false;
  2901. } else if (ch === 47 && !inClass) {
  2902. break;
  2903. }
  2904. escaped = ch === 92;
  2905. }
  2906. }
  2907. const content = this.input.slice(start, pos);
  2908. ++pos;
  2909. let mods = "";
  2910. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  2911. while (pos < this.length) {
  2912. const cp = this.codePointAtPos(pos);
  2913. const char = String.fromCharCode(cp);
  2914. if (VALID_REGEX_FLAGS.has(cp)) {
  2915. if (cp === 118) {
  2916. if (mods.includes("u")) {
  2917. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2918. at: nextPos()
  2919. });
  2920. }
  2921. } else if (cp === 117) {
  2922. if (mods.includes("v")) {
  2923. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2924. at: nextPos()
  2925. });
  2926. }
  2927. }
  2928. if (mods.includes(char)) {
  2929. this.raise(Errors.DuplicateRegExpFlags, {
  2930. at: nextPos()
  2931. });
  2932. }
  2933. } else if (isIdentifierChar(cp) || cp === 92) {
  2934. this.raise(Errors.MalformedRegExpFlags, {
  2935. at: nextPos()
  2936. });
  2937. } else {
  2938. break;
  2939. }
  2940. ++pos;
  2941. mods += char;
  2942. }
  2943. this.state.pos = pos;
  2944. this.finishToken(135, {
  2945. pattern: content,
  2946. flags: mods
  2947. });
  2948. }
  2949. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  2950. const {
  2951. n,
  2952. pos
  2953. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  2954. this.state.pos = pos;
  2955. return n;
  2956. }
  2957. readRadixNumber(radix) {
  2958. const startLoc = this.state.curPosition();
  2959. let isBigInt = false;
  2960. this.state.pos += 2;
  2961. const val = this.readInt(radix);
  2962. if (val == null) {
  2963. this.raise(Errors.InvalidDigit, {
  2964. at: createPositionWithColumnOffset(startLoc, 2),
  2965. radix
  2966. });
  2967. }
  2968. const next = this.input.charCodeAt(this.state.pos);
  2969. if (next === 110) {
  2970. ++this.state.pos;
  2971. isBigInt = true;
  2972. } else if (next === 109) {
  2973. throw this.raise(Errors.InvalidDecimal, {
  2974. at: startLoc
  2975. });
  2976. }
  2977. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  2978. throw this.raise(Errors.NumberIdentifier, {
  2979. at: this.state.curPosition()
  2980. });
  2981. }
  2982. if (isBigInt) {
  2983. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  2984. this.finishToken(133, str);
  2985. return;
  2986. }
  2987. this.finishToken(132, val);
  2988. }
  2989. readNumber(startsWithDot) {
  2990. const start = this.state.pos;
  2991. const startLoc = this.state.curPosition();
  2992. let isFloat = false;
  2993. let isBigInt = false;
  2994. let isDecimal = false;
  2995. let hasExponent = false;
  2996. let isOctal = false;
  2997. if (!startsWithDot && this.readInt(10) === null) {
  2998. this.raise(Errors.InvalidNumber, {
  2999. at: this.state.curPosition()
  3000. });
  3001. }
  3002. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3003. if (hasLeadingZero) {
  3004. const integer = this.input.slice(start, this.state.pos);
  3005. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3006. at: startLoc
  3007. });
  3008. if (!this.state.strict) {
  3009. const underscorePos = integer.indexOf("_");
  3010. if (underscorePos > 0) {
  3011. this.raise(Errors.ZeroDigitNumericSeparator, {
  3012. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3013. });
  3014. }
  3015. }
  3016. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3017. }
  3018. let next = this.input.charCodeAt(this.state.pos);
  3019. if (next === 46 && !isOctal) {
  3020. ++this.state.pos;
  3021. this.readInt(10);
  3022. isFloat = true;
  3023. next = this.input.charCodeAt(this.state.pos);
  3024. }
  3025. if ((next === 69 || next === 101) && !isOctal) {
  3026. next = this.input.charCodeAt(++this.state.pos);
  3027. if (next === 43 || next === 45) {
  3028. ++this.state.pos;
  3029. }
  3030. if (this.readInt(10) === null) {
  3031. this.raise(Errors.InvalidOrMissingExponent, {
  3032. at: startLoc
  3033. });
  3034. }
  3035. isFloat = true;
  3036. hasExponent = true;
  3037. next = this.input.charCodeAt(this.state.pos);
  3038. }
  3039. if (next === 110) {
  3040. if (isFloat || hasLeadingZero) {
  3041. this.raise(Errors.InvalidBigIntLiteral, {
  3042. at: startLoc
  3043. });
  3044. }
  3045. ++this.state.pos;
  3046. isBigInt = true;
  3047. }
  3048. if (next === 109) {
  3049. this.expectPlugin("decimal", this.state.curPosition());
  3050. if (hasExponent || hasLeadingZero) {
  3051. this.raise(Errors.InvalidDecimal, {
  3052. at: startLoc
  3053. });
  3054. }
  3055. ++this.state.pos;
  3056. isDecimal = true;
  3057. }
  3058. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3059. throw this.raise(Errors.NumberIdentifier, {
  3060. at: this.state.curPosition()
  3061. });
  3062. }
  3063. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3064. if (isBigInt) {
  3065. this.finishToken(133, str);
  3066. return;
  3067. }
  3068. if (isDecimal) {
  3069. this.finishToken(134, str);
  3070. return;
  3071. }
  3072. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3073. this.finishToken(132, val);
  3074. }
  3075. readCodePoint(throwOnInvalid) {
  3076. const {
  3077. code,
  3078. pos
  3079. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3080. this.state.pos = pos;
  3081. return code;
  3082. }
  3083. readString(quote) {
  3084. const {
  3085. str,
  3086. pos,
  3087. curLine,
  3088. lineStart
  3089. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3090. this.state.pos = pos + 1;
  3091. this.state.lineStart = lineStart;
  3092. this.state.curLine = curLine;
  3093. this.finishToken(131, str);
  3094. }
  3095. readTemplateContinuation() {
  3096. if (!this.match(8)) {
  3097. this.unexpected(null, 8);
  3098. }
  3099. this.state.pos--;
  3100. this.readTemplateToken();
  3101. }
  3102. readTemplateToken() {
  3103. const opening = this.input[this.state.pos];
  3104. const {
  3105. str,
  3106. firstInvalidLoc,
  3107. pos,
  3108. curLine,
  3109. lineStart
  3110. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3111. this.state.pos = pos + 1;
  3112. this.state.lineStart = lineStart;
  3113. this.state.curLine = curLine;
  3114. if (firstInvalidLoc) {
  3115. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3116. }
  3117. if (this.input.codePointAt(pos) === 96) {
  3118. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3119. } else {
  3120. this.state.pos++;
  3121. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3122. }
  3123. }
  3124. recordStrictModeErrors(toParseError, {
  3125. at
  3126. }) {
  3127. const index = at.index;
  3128. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3129. this.raise(toParseError, {
  3130. at
  3131. });
  3132. } else {
  3133. this.state.strictErrors.set(index, [toParseError, at]);
  3134. }
  3135. }
  3136. readWord1(firstCode) {
  3137. this.state.containsEsc = false;
  3138. let word = "";
  3139. const start = this.state.pos;
  3140. let chunkStart = this.state.pos;
  3141. if (firstCode !== undefined) {
  3142. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3143. }
  3144. while (this.state.pos < this.length) {
  3145. const ch = this.codePointAtPos(this.state.pos);
  3146. if (isIdentifierChar(ch)) {
  3147. this.state.pos += ch <= 0xffff ? 1 : 2;
  3148. } else if (ch === 92) {
  3149. this.state.containsEsc = true;
  3150. word += this.input.slice(chunkStart, this.state.pos);
  3151. const escStart = this.state.curPosition();
  3152. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3153. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3154. this.raise(Errors.MissingUnicodeEscape, {
  3155. at: this.state.curPosition()
  3156. });
  3157. chunkStart = this.state.pos - 1;
  3158. continue;
  3159. }
  3160. ++this.state.pos;
  3161. const esc = this.readCodePoint(true);
  3162. if (esc !== null) {
  3163. if (!identifierCheck(esc)) {
  3164. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3165. at: escStart
  3166. });
  3167. }
  3168. word += String.fromCodePoint(esc);
  3169. }
  3170. chunkStart = this.state.pos;
  3171. } else {
  3172. break;
  3173. }
  3174. }
  3175. return word + this.input.slice(chunkStart, this.state.pos);
  3176. }
  3177. readWord(firstCode) {
  3178. const word = this.readWord1(firstCode);
  3179. const type = keywords$1.get(word);
  3180. if (type !== undefined) {
  3181. this.finishToken(type, tokenLabelName(type));
  3182. } else {
  3183. this.finishToken(130, word);
  3184. }
  3185. }
  3186. checkKeywordEscapes() {
  3187. const {
  3188. type
  3189. } = this.state;
  3190. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3191. this.raise(Errors.InvalidEscapedReservedWord, {
  3192. at: this.state.startLoc,
  3193. reservedWord: tokenLabelName(type)
  3194. });
  3195. }
  3196. }
  3197. raise(toParseError, raiseProperties) {
  3198. const {
  3199. at
  3200. } = raiseProperties,
  3201. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3202. const loc = at instanceof Position ? at : at.loc.start;
  3203. const error = toParseError({
  3204. loc,
  3205. details
  3206. });
  3207. if (!this.options.errorRecovery) throw error;
  3208. if (!this.isLookahead) this.state.errors.push(error);
  3209. return error;
  3210. }
  3211. raiseOverwrite(toParseError, raiseProperties) {
  3212. const {
  3213. at
  3214. } = raiseProperties,
  3215. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3216. const loc = at instanceof Position ? at : at.loc.start;
  3217. const pos = loc.index;
  3218. const errors = this.state.errors;
  3219. for (let i = errors.length - 1; i >= 0; i--) {
  3220. const error = errors[i];
  3221. if (error.loc.index === pos) {
  3222. return errors[i] = toParseError({
  3223. loc,
  3224. details
  3225. });
  3226. }
  3227. if (error.loc.index < pos) break;
  3228. }
  3229. return this.raise(toParseError, raiseProperties);
  3230. }
  3231. updateContext(prevType) {}
  3232. unexpected(loc, type) {
  3233. throw this.raise(Errors.UnexpectedToken, {
  3234. expected: type ? tokenLabelName(type) : null,
  3235. at: loc != null ? loc : this.state.startLoc
  3236. });
  3237. }
  3238. expectPlugin(pluginName, loc) {
  3239. if (this.hasPlugin(pluginName)) {
  3240. return true;
  3241. }
  3242. throw this.raise(Errors.MissingPlugin, {
  3243. at: loc != null ? loc : this.state.startLoc,
  3244. missingPlugin: [pluginName]
  3245. });
  3246. }
  3247. expectOnePlugin(pluginNames) {
  3248. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3249. throw this.raise(Errors.MissingOneOfPlugins, {
  3250. at: this.state.startLoc,
  3251. missingPlugin: pluginNames
  3252. });
  3253. }
  3254. }
  3255. errorBuilder(error) {
  3256. return (pos, lineStart, curLine) => {
  3257. this.raise(error, {
  3258. at: buildPosition(pos, lineStart, curLine)
  3259. });
  3260. };
  3261. }
  3262. }
  3263. class ClassScope {
  3264. constructor() {
  3265. this.privateNames = new Set();
  3266. this.loneAccessors = new Map();
  3267. this.undefinedPrivateNames = new Map();
  3268. }
  3269. }
  3270. class ClassScopeHandler {
  3271. constructor(parser) {
  3272. this.parser = void 0;
  3273. this.stack = [];
  3274. this.undefinedPrivateNames = new Map();
  3275. this.parser = parser;
  3276. }
  3277. current() {
  3278. return this.stack[this.stack.length - 1];
  3279. }
  3280. enter() {
  3281. this.stack.push(new ClassScope());
  3282. }
  3283. exit() {
  3284. const oldClassScope = this.stack.pop();
  3285. const current = this.current();
  3286. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3287. if (current) {
  3288. if (!current.undefinedPrivateNames.has(name)) {
  3289. current.undefinedPrivateNames.set(name, loc);
  3290. }
  3291. } else {
  3292. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3293. at: loc,
  3294. identifierName: name
  3295. });
  3296. }
  3297. }
  3298. }
  3299. declarePrivateName(name, elementType, loc) {
  3300. const {
  3301. privateNames,
  3302. loneAccessors,
  3303. undefinedPrivateNames
  3304. } = this.current();
  3305. let redefined = privateNames.has(name);
  3306. if (elementType & 3) {
  3307. const accessor = redefined && loneAccessors.get(name);
  3308. if (accessor) {
  3309. const oldStatic = accessor & 4;
  3310. const newStatic = elementType & 4;
  3311. const oldKind = accessor & 3;
  3312. const newKind = elementType & 3;
  3313. redefined = oldKind === newKind || oldStatic !== newStatic;
  3314. if (!redefined) loneAccessors.delete(name);
  3315. } else if (!redefined) {
  3316. loneAccessors.set(name, elementType);
  3317. }
  3318. }
  3319. if (redefined) {
  3320. this.parser.raise(Errors.PrivateNameRedeclaration, {
  3321. at: loc,
  3322. identifierName: name
  3323. });
  3324. }
  3325. privateNames.add(name);
  3326. undefinedPrivateNames.delete(name);
  3327. }
  3328. usePrivateName(name, loc) {
  3329. let classScope;
  3330. for (classScope of this.stack) {
  3331. if (classScope.privateNames.has(name)) return;
  3332. }
  3333. if (classScope) {
  3334. classScope.undefinedPrivateNames.set(name, loc);
  3335. } else {
  3336. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3337. at: loc,
  3338. identifierName: name
  3339. });
  3340. }
  3341. }
  3342. }
  3343. class ExpressionScope {
  3344. constructor(type = 0) {
  3345. this.type = type;
  3346. }
  3347. canBeArrowParameterDeclaration() {
  3348. return this.type === 2 || this.type === 1;
  3349. }
  3350. isCertainlyParameterDeclaration() {
  3351. return this.type === 3;
  3352. }
  3353. }
  3354. class ArrowHeadParsingScope extends ExpressionScope {
  3355. constructor(type) {
  3356. super(type);
  3357. this.declarationErrors = new Map();
  3358. }
  3359. recordDeclarationError(ParsingErrorClass, {
  3360. at
  3361. }) {
  3362. const index = at.index;
  3363. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3364. }
  3365. clearDeclarationError(index) {
  3366. this.declarationErrors.delete(index);
  3367. }
  3368. iterateErrors(iterator) {
  3369. this.declarationErrors.forEach(iterator);
  3370. }
  3371. }
  3372. class ExpressionScopeHandler {
  3373. constructor(parser) {
  3374. this.parser = void 0;
  3375. this.stack = [new ExpressionScope()];
  3376. this.parser = parser;
  3377. }
  3378. enter(scope) {
  3379. this.stack.push(scope);
  3380. }
  3381. exit() {
  3382. this.stack.pop();
  3383. }
  3384. recordParameterInitializerError(toParseError, {
  3385. at: node
  3386. }) {
  3387. const origin = {
  3388. at: node.loc.start
  3389. };
  3390. const {
  3391. stack
  3392. } = this;
  3393. let i = stack.length - 1;
  3394. let scope = stack[i];
  3395. while (!scope.isCertainlyParameterDeclaration()) {
  3396. if (scope.canBeArrowParameterDeclaration()) {
  3397. scope.recordDeclarationError(toParseError, origin);
  3398. } else {
  3399. return;
  3400. }
  3401. scope = stack[--i];
  3402. }
  3403. this.parser.raise(toParseError, origin);
  3404. }
  3405. recordArrowParameterBindingError(error, {
  3406. at: node
  3407. }) {
  3408. const {
  3409. stack
  3410. } = this;
  3411. const scope = stack[stack.length - 1];
  3412. const origin = {
  3413. at: node.loc.start
  3414. };
  3415. if (scope.isCertainlyParameterDeclaration()) {
  3416. this.parser.raise(error, origin);
  3417. } else if (scope.canBeArrowParameterDeclaration()) {
  3418. scope.recordDeclarationError(error, origin);
  3419. } else {
  3420. return;
  3421. }
  3422. }
  3423. recordAsyncArrowParametersError({
  3424. at
  3425. }) {
  3426. const {
  3427. stack
  3428. } = this;
  3429. let i = stack.length - 1;
  3430. let scope = stack[i];
  3431. while (scope.canBeArrowParameterDeclaration()) {
  3432. if (scope.type === 2) {
  3433. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  3434. at
  3435. });
  3436. }
  3437. scope = stack[--i];
  3438. }
  3439. }
  3440. validateAsPattern() {
  3441. const {
  3442. stack
  3443. } = this;
  3444. const currentScope = stack[stack.length - 1];
  3445. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3446. currentScope.iterateErrors(([toParseError, loc]) => {
  3447. this.parser.raise(toParseError, {
  3448. at: loc
  3449. });
  3450. let i = stack.length - 2;
  3451. let scope = stack[i];
  3452. while (scope.canBeArrowParameterDeclaration()) {
  3453. scope.clearDeclarationError(loc.index);
  3454. scope = stack[--i];
  3455. }
  3456. });
  3457. }
  3458. }
  3459. function newParameterDeclarationScope() {
  3460. return new ExpressionScope(3);
  3461. }
  3462. function newArrowHeadScope() {
  3463. return new ArrowHeadParsingScope(1);
  3464. }
  3465. function newAsyncArrowScope() {
  3466. return new ArrowHeadParsingScope(2);
  3467. }
  3468. function newExpressionScope() {
  3469. return new ExpressionScope();
  3470. }
  3471. const PARAM = 0b0000,
  3472. PARAM_YIELD = 0b0001,
  3473. PARAM_AWAIT = 0b0010,
  3474. PARAM_RETURN = 0b0100,
  3475. PARAM_IN = 0b1000;
  3476. class ProductionParameterHandler {
  3477. constructor() {
  3478. this.stacks = [];
  3479. }
  3480. enter(flags) {
  3481. this.stacks.push(flags);
  3482. }
  3483. exit() {
  3484. this.stacks.pop();
  3485. }
  3486. currentFlags() {
  3487. return this.stacks[this.stacks.length - 1];
  3488. }
  3489. get hasAwait() {
  3490. return (this.currentFlags() & PARAM_AWAIT) > 0;
  3491. }
  3492. get hasYield() {
  3493. return (this.currentFlags() & PARAM_YIELD) > 0;
  3494. }
  3495. get hasReturn() {
  3496. return (this.currentFlags() & PARAM_RETURN) > 0;
  3497. }
  3498. get hasIn() {
  3499. return (this.currentFlags() & PARAM_IN) > 0;
  3500. }
  3501. }
  3502. function functionFlags(isAsync, isGenerator) {
  3503. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  3504. }
  3505. class UtilParser extends Tokenizer {
  3506. addExtra(node, key, value, enumerable = true) {
  3507. if (!node) return;
  3508. const extra = node.extra = node.extra || {};
  3509. if (enumerable) {
  3510. extra[key] = value;
  3511. } else {
  3512. Object.defineProperty(extra, key, {
  3513. enumerable,
  3514. value
  3515. });
  3516. }
  3517. }
  3518. isContextual(token) {
  3519. return this.state.type === token && !this.state.containsEsc;
  3520. }
  3521. isUnparsedContextual(nameStart, name) {
  3522. const nameEnd = nameStart + name.length;
  3523. if (this.input.slice(nameStart, nameEnd) === name) {
  3524. const nextCh = this.input.charCodeAt(nameEnd);
  3525. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3526. }
  3527. return false;
  3528. }
  3529. isLookaheadContextual(name) {
  3530. const next = this.nextTokenStart();
  3531. return this.isUnparsedContextual(next, name);
  3532. }
  3533. eatContextual(token) {
  3534. if (this.isContextual(token)) {
  3535. this.next();
  3536. return true;
  3537. }
  3538. return false;
  3539. }
  3540. expectContextual(token, toParseError) {
  3541. if (!this.eatContextual(token)) {
  3542. if (toParseError != null) {
  3543. throw this.raise(toParseError, {
  3544. at: this.state.startLoc
  3545. });
  3546. }
  3547. this.unexpected(null, token);
  3548. }
  3549. }
  3550. canInsertSemicolon() {
  3551. return this.match(137) || this.match(8) || this.hasPrecedingLineBreak();
  3552. }
  3553. hasPrecedingLineBreak() {
  3554. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3555. }
  3556. hasFollowingLineBreak() {
  3557. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3558. return skipWhiteSpaceToLineBreak.test(this.input);
  3559. }
  3560. isLineTerminator() {
  3561. return this.eat(13) || this.canInsertSemicolon();
  3562. }
  3563. semicolon(allowAsi = true) {
  3564. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3565. this.raise(Errors.MissingSemicolon, {
  3566. at: this.state.lastTokEndLoc
  3567. });
  3568. }
  3569. expect(type, loc) {
  3570. this.eat(type) || this.unexpected(loc, type);
  3571. }
  3572. tryParse(fn, oldState = this.state.clone()) {
  3573. const abortSignal = {
  3574. node: null
  3575. };
  3576. try {
  3577. const node = fn((node = null) => {
  3578. abortSignal.node = node;
  3579. throw abortSignal;
  3580. });
  3581. if (this.state.errors.length > oldState.errors.length) {
  3582. const failState = this.state;
  3583. this.state = oldState;
  3584. this.state.tokensLength = failState.tokensLength;
  3585. return {
  3586. node,
  3587. error: failState.errors[oldState.errors.length],
  3588. thrown: false,
  3589. aborted: false,
  3590. failState
  3591. };
  3592. }
  3593. return {
  3594. node,
  3595. error: null,
  3596. thrown: false,
  3597. aborted: false,
  3598. failState: null
  3599. };
  3600. } catch (error) {
  3601. const failState = this.state;
  3602. this.state = oldState;
  3603. if (error instanceof SyntaxError) {
  3604. return {
  3605. node: null,
  3606. error,
  3607. thrown: true,
  3608. aborted: false,
  3609. failState
  3610. };
  3611. }
  3612. if (error === abortSignal) {
  3613. return {
  3614. node: abortSignal.node,
  3615. error: null,
  3616. thrown: false,
  3617. aborted: true,
  3618. failState
  3619. };
  3620. }
  3621. throw error;
  3622. }
  3623. }
  3624. checkExpressionErrors(refExpressionErrors, andThrow) {
  3625. if (!refExpressionErrors) return false;
  3626. const {
  3627. shorthandAssignLoc,
  3628. doubleProtoLoc,
  3629. privateKeyLoc,
  3630. optionalParametersLoc
  3631. } = refExpressionErrors;
  3632. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3633. if (!andThrow) {
  3634. return hasErrors;
  3635. }
  3636. if (shorthandAssignLoc != null) {
  3637. this.raise(Errors.InvalidCoverInitializedName, {
  3638. at: shorthandAssignLoc
  3639. });
  3640. }
  3641. if (doubleProtoLoc != null) {
  3642. this.raise(Errors.DuplicateProto, {
  3643. at: doubleProtoLoc
  3644. });
  3645. }
  3646. if (privateKeyLoc != null) {
  3647. this.raise(Errors.UnexpectedPrivateField, {
  3648. at: privateKeyLoc
  3649. });
  3650. }
  3651. if (optionalParametersLoc != null) {
  3652. this.unexpected(optionalParametersLoc);
  3653. }
  3654. }
  3655. isLiteralPropertyName() {
  3656. return tokenIsLiteralPropertyName(this.state.type);
  3657. }
  3658. isPrivateName(node) {
  3659. return node.type === "PrivateName";
  3660. }
  3661. getPrivateNameSV(node) {
  3662. return node.id.name;
  3663. }
  3664. hasPropertyAsPrivateName(node) {
  3665. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3666. }
  3667. isObjectProperty(node) {
  3668. return node.type === "ObjectProperty";
  3669. }
  3670. isObjectMethod(node) {
  3671. return node.type === "ObjectMethod";
  3672. }
  3673. initializeScopes(inModule = this.options.sourceType === "module") {
  3674. const oldLabels = this.state.labels;
  3675. this.state.labels = [];
  3676. const oldExportedIdentifiers = this.exportedIdentifiers;
  3677. this.exportedIdentifiers = new Set();
  3678. const oldInModule = this.inModule;
  3679. this.inModule = inModule;
  3680. const oldScope = this.scope;
  3681. const ScopeHandler = this.getScopeHandler();
  3682. this.scope = new ScopeHandler(this, inModule);
  3683. const oldProdParam = this.prodParam;
  3684. this.prodParam = new ProductionParameterHandler();
  3685. const oldClassScope = this.classScope;
  3686. this.classScope = new ClassScopeHandler(this);
  3687. const oldExpressionScope = this.expressionScope;
  3688. this.expressionScope = new ExpressionScopeHandler(this);
  3689. return () => {
  3690. this.state.labels = oldLabels;
  3691. this.exportedIdentifiers = oldExportedIdentifiers;
  3692. this.inModule = oldInModule;
  3693. this.scope = oldScope;
  3694. this.prodParam = oldProdParam;
  3695. this.classScope = oldClassScope;
  3696. this.expressionScope = oldExpressionScope;
  3697. };
  3698. }
  3699. enterInitialScopes() {
  3700. let paramFlags = PARAM;
  3701. if (this.inModule) {
  3702. paramFlags |= PARAM_AWAIT;
  3703. }
  3704. this.scope.enter(1);
  3705. this.prodParam.enter(paramFlags);
  3706. }
  3707. checkDestructuringPrivate(refExpressionErrors) {
  3708. const {
  3709. privateKeyLoc
  3710. } = refExpressionErrors;
  3711. if (privateKeyLoc !== null) {
  3712. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3713. }
  3714. }
  3715. }
  3716. class ExpressionErrors {
  3717. constructor() {
  3718. this.shorthandAssignLoc = null;
  3719. this.doubleProtoLoc = null;
  3720. this.privateKeyLoc = null;
  3721. this.optionalParametersLoc = null;
  3722. }
  3723. }
  3724. class Node {
  3725. constructor(parser, pos, loc) {
  3726. this.type = "";
  3727. this.start = pos;
  3728. this.end = 0;
  3729. this.loc = new SourceLocation(loc);
  3730. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3731. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3732. }
  3733. }
  3734. const NodePrototype = Node.prototype;
  3735. {
  3736. NodePrototype.__clone = function () {
  3737. const newNode = new Node(undefined, this.start, this.loc.start);
  3738. const keys = Object.keys(this);
  3739. for (let i = 0, length = keys.length; i < length; i++) {
  3740. const key = keys[i];
  3741. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3742. newNode[key] = this[key];
  3743. }
  3744. }
  3745. return newNode;
  3746. };
  3747. }
  3748. function clonePlaceholder(node) {
  3749. return cloneIdentifier(node);
  3750. }
  3751. function cloneIdentifier(node) {
  3752. const {
  3753. type,
  3754. start,
  3755. end,
  3756. loc,
  3757. range,
  3758. extra,
  3759. name
  3760. } = node;
  3761. const cloned = Object.create(NodePrototype);
  3762. cloned.type = type;
  3763. cloned.start = start;
  3764. cloned.end = end;
  3765. cloned.loc = loc;
  3766. cloned.range = range;
  3767. cloned.extra = extra;
  3768. cloned.name = name;
  3769. if (type === "Placeholder") {
  3770. cloned.expectedNode = node.expectedNode;
  3771. }
  3772. return cloned;
  3773. }
  3774. function cloneStringLiteral(node) {
  3775. const {
  3776. type,
  3777. start,
  3778. end,
  3779. loc,
  3780. range,
  3781. extra
  3782. } = node;
  3783. if (type === "Placeholder") {
  3784. return clonePlaceholder(node);
  3785. }
  3786. const cloned = Object.create(NodePrototype);
  3787. cloned.type = type;
  3788. cloned.start = start;
  3789. cloned.end = end;
  3790. cloned.loc = loc;
  3791. cloned.range = range;
  3792. if (node.raw !== undefined) {
  3793. cloned.raw = node.raw;
  3794. } else {
  3795. cloned.extra = extra;
  3796. }
  3797. cloned.value = node.value;
  3798. return cloned;
  3799. }
  3800. class NodeUtils extends UtilParser {
  3801. startNode() {
  3802. return new Node(this, this.state.start, this.state.startLoc);
  3803. }
  3804. startNodeAt(loc) {
  3805. return new Node(this, loc.index, loc);
  3806. }
  3807. startNodeAtNode(type) {
  3808. return this.startNodeAt(type.loc.start);
  3809. }
  3810. finishNode(node, type) {
  3811. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3812. }
  3813. finishNodeAt(node, type, endLoc) {
  3814. node.type = type;
  3815. node.end = endLoc.index;
  3816. node.loc.end = endLoc;
  3817. if (this.options.ranges) node.range[1] = endLoc.index;
  3818. if (this.options.attachComment) this.processComment(node);
  3819. return node;
  3820. }
  3821. resetStartLocation(node, startLoc) {
  3822. node.start = startLoc.index;
  3823. node.loc.start = startLoc;
  3824. if (this.options.ranges) node.range[0] = startLoc.index;
  3825. }
  3826. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3827. node.end = endLoc.index;
  3828. node.loc.end = endLoc;
  3829. if (this.options.ranges) node.range[1] = endLoc.index;
  3830. }
  3831. resetStartLocationFromNode(node, locationNode) {
  3832. this.resetStartLocation(node, locationNode.loc.start);
  3833. }
  3834. }
  3835. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3836. const FlowErrors = ParseErrorEnum`flow`({
  3837. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3838. 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.",
  3839. AssignReservedType: ({
  3840. reservedType
  3841. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3842. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3843. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3844. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3845. EnumBooleanMemberNotInitialized: ({
  3846. memberName,
  3847. enumName
  3848. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3849. EnumDuplicateMemberName: ({
  3850. memberName,
  3851. enumName
  3852. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3853. EnumInconsistentMemberValues: ({
  3854. enumName
  3855. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3856. EnumInvalidExplicitType: ({
  3857. invalidEnumType,
  3858. enumName
  3859. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3860. EnumInvalidExplicitTypeUnknownSupplied: ({
  3861. enumName
  3862. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3863. EnumInvalidMemberInitializerPrimaryType: ({
  3864. enumName,
  3865. memberName,
  3866. explicitType
  3867. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3868. EnumInvalidMemberInitializerSymbolType: ({
  3869. enumName,
  3870. memberName
  3871. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3872. EnumInvalidMemberInitializerUnknownType: ({
  3873. enumName,
  3874. memberName
  3875. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3876. EnumInvalidMemberName: ({
  3877. enumName,
  3878. memberName,
  3879. suggestion
  3880. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3881. EnumNumberMemberNotInitialized: ({
  3882. enumName,
  3883. memberName
  3884. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3885. EnumStringMemberInconsistentlyInitialized: ({
  3886. enumName
  3887. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3888. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3889. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3890. 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.",
  3891. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3892. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3893. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3894. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3895. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3896. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3897. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3898. PatternIsOptional: Object.assign({
  3899. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3900. }, {
  3901. reasonCode: "OptionalBindingPattern"
  3902. }),
  3903. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3904. SpreadVariance: "Spread properties cannot have variance.",
  3905. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3906. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3907. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3908. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3909. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3910. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3911. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3912. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3913. UnexpectedReservedType: ({
  3914. reservedType
  3915. }) => `Unexpected reserved type ${reservedType}.`,
  3916. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3917. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3918. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3919. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3920. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3921. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3922. UnsupportedDeclareExportKind: ({
  3923. unsupportedExportKind,
  3924. suggestion
  3925. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3926. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3927. UnterminatedFlowComment: "Unterminated flow-comment."
  3928. });
  3929. function isEsModuleType(bodyElement) {
  3930. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3931. }
  3932. function hasTypeImportKind(node) {
  3933. return node.importKind === "type" || node.importKind === "typeof";
  3934. }
  3935. const exportSuggestions = {
  3936. const: "declare export var",
  3937. let: "declare export var",
  3938. type: "export type",
  3939. interface: "export interface"
  3940. };
  3941. function partition(list, test) {
  3942. const list1 = [];
  3943. const list2 = [];
  3944. for (let i = 0; i < list.length; i++) {
  3945. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3946. }
  3947. return [list1, list2];
  3948. }
  3949. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3950. var flow = superClass => class FlowParserMixin extends superClass {
  3951. constructor(...args) {
  3952. super(...args);
  3953. this.flowPragma = undefined;
  3954. }
  3955. getScopeHandler() {
  3956. return FlowScopeHandler;
  3957. }
  3958. shouldParseTypes() {
  3959. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3960. }
  3961. shouldParseEnums() {
  3962. return !!this.getPluginOption("flow", "enums");
  3963. }
  3964. finishToken(type, val) {
  3965. if (type !== 131 && type !== 13 && type !== 28) {
  3966. if (this.flowPragma === undefined) {
  3967. this.flowPragma = null;
  3968. }
  3969. }
  3970. super.finishToken(type, val);
  3971. }
  3972. addComment(comment) {
  3973. if (this.flowPragma === undefined) {
  3974. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  3975. if (!matches) ;else if (matches[1] === "flow") {
  3976. this.flowPragma = "flow";
  3977. } else if (matches[1] === "noflow") {
  3978. this.flowPragma = "noflow";
  3979. } else {
  3980. throw new Error("Unexpected flow pragma");
  3981. }
  3982. }
  3983. super.addComment(comment);
  3984. }
  3985. flowParseTypeInitialiser(tok) {
  3986. const oldInType = this.state.inType;
  3987. this.state.inType = true;
  3988. this.expect(tok || 14);
  3989. const type = this.flowParseType();
  3990. this.state.inType = oldInType;
  3991. return type;
  3992. }
  3993. flowParsePredicate() {
  3994. const node = this.startNode();
  3995. const moduloLoc = this.state.startLoc;
  3996. this.next();
  3997. this.expectContextual(108);
  3998. if (this.state.lastTokStart > moduloLoc.index + 1) {
  3999. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4000. at: moduloLoc
  4001. });
  4002. }
  4003. if (this.eat(10)) {
  4004. node.value = super.parseExpression();
  4005. this.expect(11);
  4006. return this.finishNode(node, "DeclaredPredicate");
  4007. } else {
  4008. return this.finishNode(node, "InferredPredicate");
  4009. }
  4010. }
  4011. flowParseTypeAndPredicateInitialiser() {
  4012. const oldInType = this.state.inType;
  4013. this.state.inType = true;
  4014. this.expect(14);
  4015. let type = null;
  4016. let predicate = null;
  4017. if (this.match(54)) {
  4018. this.state.inType = oldInType;
  4019. predicate = this.flowParsePredicate();
  4020. } else {
  4021. type = this.flowParseType();
  4022. this.state.inType = oldInType;
  4023. if (this.match(54)) {
  4024. predicate = this.flowParsePredicate();
  4025. }
  4026. }
  4027. return [type, predicate];
  4028. }
  4029. flowParseDeclareClass(node) {
  4030. this.next();
  4031. this.flowParseInterfaceish(node, true);
  4032. return this.finishNode(node, "DeclareClass");
  4033. }
  4034. flowParseDeclareFunction(node) {
  4035. this.next();
  4036. const id = node.id = this.parseIdentifier();
  4037. const typeNode = this.startNode();
  4038. const typeContainer = this.startNode();
  4039. if (this.match(47)) {
  4040. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4041. } else {
  4042. typeNode.typeParameters = null;
  4043. }
  4044. this.expect(10);
  4045. const tmp = this.flowParseFunctionTypeParams();
  4046. typeNode.params = tmp.params;
  4047. typeNode.rest = tmp.rest;
  4048. typeNode.this = tmp._this;
  4049. this.expect(11);
  4050. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4051. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4052. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4053. this.resetEndLocation(id);
  4054. this.semicolon();
  4055. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4056. return this.finishNode(node, "DeclareFunction");
  4057. }
  4058. flowParseDeclare(node, insideModule) {
  4059. if (this.match(80)) {
  4060. return this.flowParseDeclareClass(node);
  4061. } else if (this.match(68)) {
  4062. return this.flowParseDeclareFunction(node);
  4063. } else if (this.match(74)) {
  4064. return this.flowParseDeclareVariable(node);
  4065. } else if (this.eatContextual(125)) {
  4066. if (this.match(16)) {
  4067. return this.flowParseDeclareModuleExports(node);
  4068. } else {
  4069. if (insideModule) {
  4070. this.raise(FlowErrors.NestedDeclareModule, {
  4071. at: this.state.lastTokStartLoc
  4072. });
  4073. }
  4074. return this.flowParseDeclareModule(node);
  4075. }
  4076. } else if (this.isContextual(128)) {
  4077. return this.flowParseDeclareTypeAlias(node);
  4078. } else if (this.isContextual(129)) {
  4079. return this.flowParseDeclareOpaqueType(node);
  4080. } else if (this.isContextual(127)) {
  4081. return this.flowParseDeclareInterface(node);
  4082. } else if (this.match(82)) {
  4083. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4084. } else {
  4085. this.unexpected();
  4086. }
  4087. }
  4088. flowParseDeclareVariable(node) {
  4089. this.next();
  4090. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4091. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4092. this.semicolon();
  4093. return this.finishNode(node, "DeclareVariable");
  4094. }
  4095. flowParseDeclareModule(node) {
  4096. this.scope.enter(0);
  4097. if (this.match(131)) {
  4098. node.id = super.parseExprAtom();
  4099. } else {
  4100. node.id = this.parseIdentifier();
  4101. }
  4102. const bodyNode = node.body = this.startNode();
  4103. const body = bodyNode.body = [];
  4104. this.expect(5);
  4105. while (!this.match(8)) {
  4106. let bodyNode = this.startNode();
  4107. if (this.match(83)) {
  4108. this.next();
  4109. if (!this.isContextual(128) && !this.match(87)) {
  4110. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4111. at: this.state.lastTokStartLoc
  4112. });
  4113. }
  4114. super.parseImport(bodyNode);
  4115. } else {
  4116. this.expectContextual(123, FlowErrors.UnsupportedStatementInDeclareModule);
  4117. bodyNode = this.flowParseDeclare(bodyNode, true);
  4118. }
  4119. body.push(bodyNode);
  4120. }
  4121. this.scope.exit();
  4122. this.expect(8);
  4123. this.finishNode(bodyNode, "BlockStatement");
  4124. let kind = null;
  4125. let hasModuleExport = false;
  4126. body.forEach(bodyElement => {
  4127. if (isEsModuleType(bodyElement)) {
  4128. if (kind === "CommonJS") {
  4129. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4130. at: bodyElement
  4131. });
  4132. }
  4133. kind = "ES";
  4134. } else if (bodyElement.type === "DeclareModuleExports") {
  4135. if (hasModuleExport) {
  4136. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4137. at: bodyElement
  4138. });
  4139. }
  4140. if (kind === "ES") {
  4141. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4142. at: bodyElement
  4143. });
  4144. }
  4145. kind = "CommonJS";
  4146. hasModuleExport = true;
  4147. }
  4148. });
  4149. node.kind = kind || "CommonJS";
  4150. return this.finishNode(node, "DeclareModule");
  4151. }
  4152. flowParseDeclareExportDeclaration(node, insideModule) {
  4153. this.expect(82);
  4154. if (this.eat(65)) {
  4155. if (this.match(68) || this.match(80)) {
  4156. node.declaration = this.flowParseDeclare(this.startNode());
  4157. } else {
  4158. node.declaration = this.flowParseType();
  4159. this.semicolon();
  4160. }
  4161. node.default = true;
  4162. return this.finishNode(node, "DeclareExportDeclaration");
  4163. } else {
  4164. if (this.match(75) || this.isLet() || (this.isContextual(128) || this.isContextual(127)) && !insideModule) {
  4165. const label = this.state.value;
  4166. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4167. at: this.state.startLoc,
  4168. unsupportedExportKind: label,
  4169. suggestion: exportSuggestions[label]
  4170. });
  4171. }
  4172. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(129)) {
  4173. node.declaration = this.flowParseDeclare(this.startNode());
  4174. node.default = false;
  4175. return this.finishNode(node, "DeclareExportDeclaration");
  4176. } else if (this.match(55) || this.match(5) || this.isContextual(127) || this.isContextual(128) || this.isContextual(129)) {
  4177. node = this.parseExport(node, null);
  4178. if (node.type === "ExportNamedDeclaration") {
  4179. node.type = "ExportDeclaration";
  4180. node.default = false;
  4181. delete node.exportKind;
  4182. }
  4183. node.type = "Declare" + node.type;
  4184. return node;
  4185. }
  4186. }
  4187. this.unexpected();
  4188. }
  4189. flowParseDeclareModuleExports(node) {
  4190. this.next();
  4191. this.expectContextual(109);
  4192. node.typeAnnotation = this.flowParseTypeAnnotation();
  4193. this.semicolon();
  4194. return this.finishNode(node, "DeclareModuleExports");
  4195. }
  4196. flowParseDeclareTypeAlias(node) {
  4197. this.next();
  4198. const finished = this.flowParseTypeAlias(node);
  4199. finished.type = "DeclareTypeAlias";
  4200. return finished;
  4201. }
  4202. flowParseDeclareOpaqueType(node) {
  4203. this.next();
  4204. const finished = this.flowParseOpaqueType(node, true);
  4205. finished.type = "DeclareOpaqueType";
  4206. return finished;
  4207. }
  4208. flowParseDeclareInterface(node) {
  4209. this.next();
  4210. this.flowParseInterfaceish(node, false);
  4211. return this.finishNode(node, "DeclareInterface");
  4212. }
  4213. flowParseInterfaceish(node, isClass) {
  4214. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4215. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4216. if (this.match(47)) {
  4217. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4218. } else {
  4219. node.typeParameters = null;
  4220. }
  4221. node.extends = [];
  4222. if (this.eat(81)) {
  4223. do {
  4224. node.extends.push(this.flowParseInterfaceExtends());
  4225. } while (!isClass && this.eat(12));
  4226. }
  4227. if (isClass) {
  4228. node.implements = [];
  4229. node.mixins = [];
  4230. if (this.eatContextual(115)) {
  4231. do {
  4232. node.mixins.push(this.flowParseInterfaceExtends());
  4233. } while (this.eat(12));
  4234. }
  4235. if (this.eatContextual(111)) {
  4236. do {
  4237. node.implements.push(this.flowParseInterfaceExtends());
  4238. } while (this.eat(12));
  4239. }
  4240. }
  4241. node.body = this.flowParseObjectType({
  4242. allowStatic: isClass,
  4243. allowExact: false,
  4244. allowSpread: false,
  4245. allowProto: isClass,
  4246. allowInexact: false
  4247. });
  4248. }
  4249. flowParseInterfaceExtends() {
  4250. const node = this.startNode();
  4251. node.id = this.flowParseQualifiedTypeIdentifier();
  4252. if (this.match(47)) {
  4253. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4254. } else {
  4255. node.typeParameters = null;
  4256. }
  4257. return this.finishNode(node, "InterfaceExtends");
  4258. }
  4259. flowParseInterface(node) {
  4260. this.flowParseInterfaceish(node, false);
  4261. return this.finishNode(node, "InterfaceDeclaration");
  4262. }
  4263. checkNotUnderscore(word) {
  4264. if (word === "_") {
  4265. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4266. at: this.state.startLoc
  4267. });
  4268. }
  4269. }
  4270. checkReservedType(word, startLoc, declaration) {
  4271. if (!reservedTypes.has(word)) return;
  4272. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4273. at: startLoc,
  4274. reservedType: word
  4275. });
  4276. }
  4277. flowParseRestrictedIdentifier(liberal, declaration) {
  4278. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4279. return this.parseIdentifier(liberal);
  4280. }
  4281. flowParseTypeAlias(node) {
  4282. node.id = this.flowParseRestrictedIdentifier(false, true);
  4283. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4284. if (this.match(47)) {
  4285. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4286. } else {
  4287. node.typeParameters = null;
  4288. }
  4289. node.right = this.flowParseTypeInitialiser(29);
  4290. this.semicolon();
  4291. return this.finishNode(node, "TypeAlias");
  4292. }
  4293. flowParseOpaqueType(node, declare) {
  4294. this.expectContextual(128);
  4295. node.id = this.flowParseRestrictedIdentifier(true, true);
  4296. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4297. if (this.match(47)) {
  4298. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4299. } else {
  4300. node.typeParameters = null;
  4301. }
  4302. node.supertype = null;
  4303. if (this.match(14)) {
  4304. node.supertype = this.flowParseTypeInitialiser(14);
  4305. }
  4306. node.impltype = null;
  4307. if (!declare) {
  4308. node.impltype = this.flowParseTypeInitialiser(29);
  4309. }
  4310. this.semicolon();
  4311. return this.finishNode(node, "OpaqueType");
  4312. }
  4313. flowParseTypeParameter(requireDefault = false) {
  4314. const nodeStartLoc = this.state.startLoc;
  4315. const node = this.startNode();
  4316. const variance = this.flowParseVariance();
  4317. const ident = this.flowParseTypeAnnotatableIdentifier();
  4318. node.name = ident.name;
  4319. node.variance = variance;
  4320. node.bound = ident.typeAnnotation;
  4321. if (this.match(29)) {
  4322. this.eat(29);
  4323. node.default = this.flowParseType();
  4324. } else {
  4325. if (requireDefault) {
  4326. this.raise(FlowErrors.MissingTypeParamDefault, {
  4327. at: nodeStartLoc
  4328. });
  4329. }
  4330. }
  4331. return this.finishNode(node, "TypeParameter");
  4332. }
  4333. flowParseTypeParameterDeclaration() {
  4334. const oldInType = this.state.inType;
  4335. const node = this.startNode();
  4336. node.params = [];
  4337. this.state.inType = true;
  4338. if (this.match(47) || this.match(140)) {
  4339. this.next();
  4340. } else {
  4341. this.unexpected();
  4342. }
  4343. let defaultRequired = false;
  4344. do {
  4345. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4346. node.params.push(typeParameter);
  4347. if (typeParameter.default) {
  4348. defaultRequired = true;
  4349. }
  4350. if (!this.match(48)) {
  4351. this.expect(12);
  4352. }
  4353. } while (!this.match(48));
  4354. this.expect(48);
  4355. this.state.inType = oldInType;
  4356. return this.finishNode(node, "TypeParameterDeclaration");
  4357. }
  4358. flowParseTypeParameterInstantiation() {
  4359. const node = this.startNode();
  4360. const oldInType = this.state.inType;
  4361. node.params = [];
  4362. this.state.inType = true;
  4363. this.expect(47);
  4364. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4365. this.state.noAnonFunctionType = false;
  4366. while (!this.match(48)) {
  4367. node.params.push(this.flowParseType());
  4368. if (!this.match(48)) {
  4369. this.expect(12);
  4370. }
  4371. }
  4372. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4373. this.expect(48);
  4374. this.state.inType = oldInType;
  4375. return this.finishNode(node, "TypeParameterInstantiation");
  4376. }
  4377. flowParseTypeParameterInstantiationCallOrNew() {
  4378. const node = this.startNode();
  4379. const oldInType = this.state.inType;
  4380. node.params = [];
  4381. this.state.inType = true;
  4382. this.expect(47);
  4383. while (!this.match(48)) {
  4384. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4385. if (!this.match(48)) {
  4386. this.expect(12);
  4387. }
  4388. }
  4389. this.expect(48);
  4390. this.state.inType = oldInType;
  4391. return this.finishNode(node, "TypeParameterInstantiation");
  4392. }
  4393. flowParseInterfaceType() {
  4394. const node = this.startNode();
  4395. this.expectContextual(127);
  4396. node.extends = [];
  4397. if (this.eat(81)) {
  4398. do {
  4399. node.extends.push(this.flowParseInterfaceExtends());
  4400. } while (this.eat(12));
  4401. }
  4402. node.body = this.flowParseObjectType({
  4403. allowStatic: false,
  4404. allowExact: false,
  4405. allowSpread: false,
  4406. allowProto: false,
  4407. allowInexact: false
  4408. });
  4409. return this.finishNode(node, "InterfaceTypeAnnotation");
  4410. }
  4411. flowParseObjectPropertyKey() {
  4412. return this.match(132) || this.match(131) ? super.parseExprAtom() : this.parseIdentifier(true);
  4413. }
  4414. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4415. node.static = isStatic;
  4416. if (this.lookahead().type === 14) {
  4417. node.id = this.flowParseObjectPropertyKey();
  4418. node.key = this.flowParseTypeInitialiser();
  4419. } else {
  4420. node.id = null;
  4421. node.key = this.flowParseType();
  4422. }
  4423. this.expect(3);
  4424. node.value = this.flowParseTypeInitialiser();
  4425. node.variance = variance;
  4426. return this.finishNode(node, "ObjectTypeIndexer");
  4427. }
  4428. flowParseObjectTypeInternalSlot(node, isStatic) {
  4429. node.static = isStatic;
  4430. node.id = this.flowParseObjectPropertyKey();
  4431. this.expect(3);
  4432. this.expect(3);
  4433. if (this.match(47) || this.match(10)) {
  4434. node.method = true;
  4435. node.optional = false;
  4436. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4437. } else {
  4438. node.method = false;
  4439. if (this.eat(17)) {
  4440. node.optional = true;
  4441. }
  4442. node.value = this.flowParseTypeInitialiser();
  4443. }
  4444. return this.finishNode(node, "ObjectTypeInternalSlot");
  4445. }
  4446. flowParseObjectTypeMethodish(node) {
  4447. node.params = [];
  4448. node.rest = null;
  4449. node.typeParameters = null;
  4450. node.this = null;
  4451. if (this.match(47)) {
  4452. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4453. }
  4454. this.expect(10);
  4455. if (this.match(78)) {
  4456. node.this = this.flowParseFunctionTypeParam(true);
  4457. node.this.name = null;
  4458. if (!this.match(11)) {
  4459. this.expect(12);
  4460. }
  4461. }
  4462. while (!this.match(11) && !this.match(21)) {
  4463. node.params.push(this.flowParseFunctionTypeParam(false));
  4464. if (!this.match(11)) {
  4465. this.expect(12);
  4466. }
  4467. }
  4468. if (this.eat(21)) {
  4469. node.rest = this.flowParseFunctionTypeParam(false);
  4470. }
  4471. this.expect(11);
  4472. node.returnType = this.flowParseTypeInitialiser();
  4473. return this.finishNode(node, "FunctionTypeAnnotation");
  4474. }
  4475. flowParseObjectTypeCallProperty(node, isStatic) {
  4476. const valueNode = this.startNode();
  4477. node.static = isStatic;
  4478. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4479. return this.finishNode(node, "ObjectTypeCallProperty");
  4480. }
  4481. flowParseObjectType({
  4482. allowStatic,
  4483. allowExact,
  4484. allowSpread,
  4485. allowProto,
  4486. allowInexact
  4487. }) {
  4488. const oldInType = this.state.inType;
  4489. this.state.inType = true;
  4490. const nodeStart = this.startNode();
  4491. nodeStart.callProperties = [];
  4492. nodeStart.properties = [];
  4493. nodeStart.indexers = [];
  4494. nodeStart.internalSlots = [];
  4495. let endDelim;
  4496. let exact;
  4497. let inexact = false;
  4498. if (allowExact && this.match(6)) {
  4499. this.expect(6);
  4500. endDelim = 9;
  4501. exact = true;
  4502. } else {
  4503. this.expect(5);
  4504. endDelim = 8;
  4505. exact = false;
  4506. }
  4507. nodeStart.exact = exact;
  4508. while (!this.match(endDelim)) {
  4509. let isStatic = false;
  4510. let protoStartLoc = null;
  4511. let inexactStartLoc = null;
  4512. const node = this.startNode();
  4513. if (allowProto && this.isContextual(116)) {
  4514. const lookahead = this.lookahead();
  4515. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4516. this.next();
  4517. protoStartLoc = this.state.startLoc;
  4518. allowStatic = false;
  4519. }
  4520. }
  4521. if (allowStatic && this.isContextual(104)) {
  4522. const lookahead = this.lookahead();
  4523. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4524. this.next();
  4525. isStatic = true;
  4526. }
  4527. }
  4528. const variance = this.flowParseVariance();
  4529. if (this.eat(0)) {
  4530. if (protoStartLoc != null) {
  4531. this.unexpected(protoStartLoc);
  4532. }
  4533. if (this.eat(0)) {
  4534. if (variance) {
  4535. this.unexpected(variance.loc.start);
  4536. }
  4537. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4538. } else {
  4539. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4540. }
  4541. } else if (this.match(10) || this.match(47)) {
  4542. if (protoStartLoc != null) {
  4543. this.unexpected(protoStartLoc);
  4544. }
  4545. if (variance) {
  4546. this.unexpected(variance.loc.start);
  4547. }
  4548. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4549. } else {
  4550. let kind = "init";
  4551. if (this.isContextual(98) || this.isContextual(103)) {
  4552. const lookahead = this.lookahead();
  4553. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4554. kind = this.state.value;
  4555. this.next();
  4556. }
  4557. }
  4558. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4559. if (propOrInexact === null) {
  4560. inexact = true;
  4561. inexactStartLoc = this.state.lastTokStartLoc;
  4562. } else {
  4563. nodeStart.properties.push(propOrInexact);
  4564. }
  4565. }
  4566. this.flowObjectTypeSemicolon();
  4567. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4568. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  4569. at: inexactStartLoc
  4570. });
  4571. }
  4572. }
  4573. this.expect(endDelim);
  4574. if (allowSpread) {
  4575. nodeStart.inexact = inexact;
  4576. }
  4577. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4578. this.state.inType = oldInType;
  4579. return out;
  4580. }
  4581. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4582. if (this.eat(21)) {
  4583. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4584. if (isInexactToken) {
  4585. if (!allowSpread) {
  4586. this.raise(FlowErrors.InexactInsideNonObject, {
  4587. at: this.state.lastTokStartLoc
  4588. });
  4589. } else if (!allowInexact) {
  4590. this.raise(FlowErrors.InexactInsideExact, {
  4591. at: this.state.lastTokStartLoc
  4592. });
  4593. }
  4594. if (variance) {
  4595. this.raise(FlowErrors.InexactVariance, {
  4596. at: variance
  4597. });
  4598. }
  4599. return null;
  4600. }
  4601. if (!allowSpread) {
  4602. this.raise(FlowErrors.UnexpectedSpreadType, {
  4603. at: this.state.lastTokStartLoc
  4604. });
  4605. }
  4606. if (protoStartLoc != null) {
  4607. this.unexpected(protoStartLoc);
  4608. }
  4609. if (variance) {
  4610. this.raise(FlowErrors.SpreadVariance, {
  4611. at: variance
  4612. });
  4613. }
  4614. node.argument = this.flowParseType();
  4615. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4616. } else {
  4617. node.key = this.flowParseObjectPropertyKey();
  4618. node.static = isStatic;
  4619. node.proto = protoStartLoc != null;
  4620. node.kind = kind;
  4621. let optional = false;
  4622. if (this.match(47) || this.match(10)) {
  4623. node.method = true;
  4624. if (protoStartLoc != null) {
  4625. this.unexpected(protoStartLoc);
  4626. }
  4627. if (variance) {
  4628. this.unexpected(variance.loc.start);
  4629. }
  4630. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4631. if (kind === "get" || kind === "set") {
  4632. this.flowCheckGetterSetterParams(node);
  4633. }
  4634. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4635. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  4636. at: node.value.this
  4637. });
  4638. }
  4639. } else {
  4640. if (kind !== "init") this.unexpected();
  4641. node.method = false;
  4642. if (this.eat(17)) {
  4643. optional = true;
  4644. }
  4645. node.value = this.flowParseTypeInitialiser();
  4646. node.variance = variance;
  4647. }
  4648. node.optional = optional;
  4649. return this.finishNode(node, "ObjectTypeProperty");
  4650. }
  4651. }
  4652. flowCheckGetterSetterParams(property) {
  4653. const paramCount = property.kind === "get" ? 0 : 1;
  4654. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4655. if (property.value.this) {
  4656. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  4657. at: property.value.this
  4658. });
  4659. }
  4660. if (length !== paramCount) {
  4661. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  4662. at: property
  4663. });
  4664. }
  4665. if (property.kind === "set" && property.value.rest) {
  4666. this.raise(Errors.BadSetterRestParameter, {
  4667. at: property
  4668. });
  4669. }
  4670. }
  4671. flowObjectTypeSemicolon() {
  4672. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4673. this.unexpected();
  4674. }
  4675. }
  4676. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4677. var _startLoc;
  4678. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4679. let node = id || this.flowParseRestrictedIdentifier(true);
  4680. while (this.eat(16)) {
  4681. const node2 = this.startNodeAt(startLoc);
  4682. node2.qualification = node;
  4683. node2.id = this.flowParseRestrictedIdentifier(true);
  4684. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4685. }
  4686. return node;
  4687. }
  4688. flowParseGenericType(startLoc, id) {
  4689. const node = this.startNodeAt(startLoc);
  4690. node.typeParameters = null;
  4691. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4692. if (this.match(47)) {
  4693. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4694. }
  4695. return this.finishNode(node, "GenericTypeAnnotation");
  4696. }
  4697. flowParseTypeofType() {
  4698. const node = this.startNode();
  4699. this.expect(87);
  4700. node.argument = this.flowParsePrimaryType();
  4701. return this.finishNode(node, "TypeofTypeAnnotation");
  4702. }
  4703. flowParseTupleType() {
  4704. const node = this.startNode();
  4705. node.types = [];
  4706. this.expect(0);
  4707. while (this.state.pos < this.length && !this.match(3)) {
  4708. node.types.push(this.flowParseType());
  4709. if (this.match(3)) break;
  4710. this.expect(12);
  4711. }
  4712. this.expect(3);
  4713. return this.finishNode(node, "TupleTypeAnnotation");
  4714. }
  4715. flowParseFunctionTypeParam(first) {
  4716. let name = null;
  4717. let optional = false;
  4718. let typeAnnotation = null;
  4719. const node = this.startNode();
  4720. const lh = this.lookahead();
  4721. const isThis = this.state.type === 78;
  4722. if (lh.type === 14 || lh.type === 17) {
  4723. if (isThis && !first) {
  4724. this.raise(FlowErrors.ThisParamMustBeFirst, {
  4725. at: node
  4726. });
  4727. }
  4728. name = this.parseIdentifier(isThis);
  4729. if (this.eat(17)) {
  4730. optional = true;
  4731. if (isThis) {
  4732. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  4733. at: node
  4734. });
  4735. }
  4736. }
  4737. typeAnnotation = this.flowParseTypeInitialiser();
  4738. } else {
  4739. typeAnnotation = this.flowParseType();
  4740. }
  4741. node.name = name;
  4742. node.optional = optional;
  4743. node.typeAnnotation = typeAnnotation;
  4744. return this.finishNode(node, "FunctionTypeParam");
  4745. }
  4746. reinterpretTypeAsFunctionTypeParam(type) {
  4747. const node = this.startNodeAt(type.loc.start);
  4748. node.name = null;
  4749. node.optional = false;
  4750. node.typeAnnotation = type;
  4751. return this.finishNode(node, "FunctionTypeParam");
  4752. }
  4753. flowParseFunctionTypeParams(params = []) {
  4754. let rest = null;
  4755. let _this = null;
  4756. if (this.match(78)) {
  4757. _this = this.flowParseFunctionTypeParam(true);
  4758. _this.name = null;
  4759. if (!this.match(11)) {
  4760. this.expect(12);
  4761. }
  4762. }
  4763. while (!this.match(11) && !this.match(21)) {
  4764. params.push(this.flowParseFunctionTypeParam(false));
  4765. if (!this.match(11)) {
  4766. this.expect(12);
  4767. }
  4768. }
  4769. if (this.eat(21)) {
  4770. rest = this.flowParseFunctionTypeParam(false);
  4771. }
  4772. return {
  4773. params,
  4774. rest,
  4775. _this
  4776. };
  4777. }
  4778. flowIdentToTypeAnnotation(startLoc, node, id) {
  4779. switch (id.name) {
  4780. case "any":
  4781. return this.finishNode(node, "AnyTypeAnnotation");
  4782. case "bool":
  4783. case "boolean":
  4784. return this.finishNode(node, "BooleanTypeAnnotation");
  4785. case "mixed":
  4786. return this.finishNode(node, "MixedTypeAnnotation");
  4787. case "empty":
  4788. return this.finishNode(node, "EmptyTypeAnnotation");
  4789. case "number":
  4790. return this.finishNode(node, "NumberTypeAnnotation");
  4791. case "string":
  4792. return this.finishNode(node, "StringTypeAnnotation");
  4793. case "symbol":
  4794. return this.finishNode(node, "SymbolTypeAnnotation");
  4795. default:
  4796. this.checkNotUnderscore(id.name);
  4797. return this.flowParseGenericType(startLoc, id);
  4798. }
  4799. }
  4800. flowParsePrimaryType() {
  4801. const startLoc = this.state.startLoc;
  4802. const node = this.startNode();
  4803. let tmp;
  4804. let type;
  4805. let isGroupedType = false;
  4806. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4807. switch (this.state.type) {
  4808. case 5:
  4809. return this.flowParseObjectType({
  4810. allowStatic: false,
  4811. allowExact: false,
  4812. allowSpread: true,
  4813. allowProto: false,
  4814. allowInexact: true
  4815. });
  4816. case 6:
  4817. return this.flowParseObjectType({
  4818. allowStatic: false,
  4819. allowExact: true,
  4820. allowSpread: true,
  4821. allowProto: false,
  4822. allowInexact: false
  4823. });
  4824. case 0:
  4825. this.state.noAnonFunctionType = false;
  4826. type = this.flowParseTupleType();
  4827. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4828. return type;
  4829. case 47:
  4830. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4831. this.expect(10);
  4832. tmp = this.flowParseFunctionTypeParams();
  4833. node.params = tmp.params;
  4834. node.rest = tmp.rest;
  4835. node.this = tmp._this;
  4836. this.expect(11);
  4837. this.expect(19);
  4838. node.returnType = this.flowParseType();
  4839. return this.finishNode(node, "FunctionTypeAnnotation");
  4840. case 10:
  4841. this.next();
  4842. if (!this.match(11) && !this.match(21)) {
  4843. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4844. const token = this.lookahead().type;
  4845. isGroupedType = token !== 17 && token !== 14;
  4846. } else {
  4847. isGroupedType = true;
  4848. }
  4849. }
  4850. if (isGroupedType) {
  4851. this.state.noAnonFunctionType = false;
  4852. type = this.flowParseType();
  4853. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4854. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4855. this.expect(11);
  4856. return type;
  4857. } else {
  4858. this.eat(12);
  4859. }
  4860. }
  4861. if (type) {
  4862. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4863. } else {
  4864. tmp = this.flowParseFunctionTypeParams();
  4865. }
  4866. node.params = tmp.params;
  4867. node.rest = tmp.rest;
  4868. node.this = tmp._this;
  4869. this.expect(11);
  4870. this.expect(19);
  4871. node.returnType = this.flowParseType();
  4872. node.typeParameters = null;
  4873. return this.finishNode(node, "FunctionTypeAnnotation");
  4874. case 131:
  4875. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4876. case 85:
  4877. case 86:
  4878. node.value = this.match(85);
  4879. this.next();
  4880. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4881. case 53:
  4882. if (this.state.value === "-") {
  4883. this.next();
  4884. if (this.match(132)) {
  4885. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4886. }
  4887. if (this.match(133)) {
  4888. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4889. }
  4890. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  4891. at: this.state.startLoc
  4892. });
  4893. }
  4894. this.unexpected();
  4895. return;
  4896. case 132:
  4897. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4898. case 133:
  4899. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4900. case 88:
  4901. this.next();
  4902. return this.finishNode(node, "VoidTypeAnnotation");
  4903. case 84:
  4904. this.next();
  4905. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4906. case 78:
  4907. this.next();
  4908. return this.finishNode(node, "ThisTypeAnnotation");
  4909. case 55:
  4910. this.next();
  4911. return this.finishNode(node, "ExistsTypeAnnotation");
  4912. case 87:
  4913. return this.flowParseTypeofType();
  4914. default:
  4915. if (tokenIsKeyword(this.state.type)) {
  4916. const label = tokenLabelName(this.state.type);
  4917. this.next();
  4918. return super.createIdentifier(node, label);
  4919. } else if (tokenIsIdentifier(this.state.type)) {
  4920. if (this.isContextual(127)) {
  4921. return this.flowParseInterfaceType();
  4922. }
  4923. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4924. }
  4925. }
  4926. this.unexpected();
  4927. }
  4928. flowParsePostfixType() {
  4929. const startLoc = this.state.startLoc;
  4930. let type = this.flowParsePrimaryType();
  4931. let seenOptionalIndexedAccess = false;
  4932. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4933. const node = this.startNodeAt(startLoc);
  4934. const optional = this.eat(18);
  4935. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4936. this.expect(0);
  4937. if (!optional && this.match(3)) {
  4938. node.elementType = type;
  4939. this.next();
  4940. type = this.finishNode(node, "ArrayTypeAnnotation");
  4941. } else {
  4942. node.objectType = type;
  4943. node.indexType = this.flowParseType();
  4944. this.expect(3);
  4945. if (seenOptionalIndexedAccess) {
  4946. node.optional = optional;
  4947. type = this.finishNode(node, "OptionalIndexedAccessType");
  4948. } else {
  4949. type = this.finishNode(node, "IndexedAccessType");
  4950. }
  4951. }
  4952. }
  4953. return type;
  4954. }
  4955. flowParsePrefixType() {
  4956. const node = this.startNode();
  4957. if (this.eat(17)) {
  4958. node.typeAnnotation = this.flowParsePrefixType();
  4959. return this.finishNode(node, "NullableTypeAnnotation");
  4960. } else {
  4961. return this.flowParsePostfixType();
  4962. }
  4963. }
  4964. flowParseAnonFunctionWithoutParens() {
  4965. const param = this.flowParsePrefixType();
  4966. if (!this.state.noAnonFunctionType && this.eat(19)) {
  4967. const node = this.startNodeAt(param.loc.start);
  4968. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  4969. node.rest = null;
  4970. node.this = null;
  4971. node.returnType = this.flowParseType();
  4972. node.typeParameters = null;
  4973. return this.finishNode(node, "FunctionTypeAnnotation");
  4974. }
  4975. return param;
  4976. }
  4977. flowParseIntersectionType() {
  4978. const node = this.startNode();
  4979. this.eat(45);
  4980. const type = this.flowParseAnonFunctionWithoutParens();
  4981. node.types = [type];
  4982. while (this.eat(45)) {
  4983. node.types.push(this.flowParseAnonFunctionWithoutParens());
  4984. }
  4985. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  4986. }
  4987. flowParseUnionType() {
  4988. const node = this.startNode();
  4989. this.eat(43);
  4990. const type = this.flowParseIntersectionType();
  4991. node.types = [type];
  4992. while (this.eat(43)) {
  4993. node.types.push(this.flowParseIntersectionType());
  4994. }
  4995. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  4996. }
  4997. flowParseType() {
  4998. const oldInType = this.state.inType;
  4999. this.state.inType = true;
  5000. const type = this.flowParseUnionType();
  5001. this.state.inType = oldInType;
  5002. return type;
  5003. }
  5004. flowParseTypeOrImplicitInstantiation() {
  5005. if (this.state.type === 130 && this.state.value === "_") {
  5006. const startLoc = this.state.startLoc;
  5007. const node = this.parseIdentifier();
  5008. return this.flowParseGenericType(startLoc, node);
  5009. } else {
  5010. return this.flowParseType();
  5011. }
  5012. }
  5013. flowParseTypeAnnotation() {
  5014. const node = this.startNode();
  5015. node.typeAnnotation = this.flowParseTypeInitialiser();
  5016. return this.finishNode(node, "TypeAnnotation");
  5017. }
  5018. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5019. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5020. if (this.match(14)) {
  5021. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5022. this.resetEndLocation(ident);
  5023. }
  5024. return ident;
  5025. }
  5026. typeCastToParameter(node) {
  5027. node.expression.typeAnnotation = node.typeAnnotation;
  5028. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5029. return node.expression;
  5030. }
  5031. flowParseVariance() {
  5032. let variance = null;
  5033. if (this.match(53)) {
  5034. variance = this.startNode();
  5035. if (this.state.value === "+") {
  5036. variance.kind = "plus";
  5037. } else {
  5038. variance.kind = "minus";
  5039. }
  5040. this.next();
  5041. return this.finishNode(variance, "Variance");
  5042. }
  5043. return variance;
  5044. }
  5045. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5046. if (allowExpressionBody) {
  5047. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5048. return;
  5049. }
  5050. super.parseFunctionBody(node, false, isMethod);
  5051. }
  5052. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5053. if (this.match(14)) {
  5054. const typeNode = this.startNode();
  5055. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5056. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5057. }
  5058. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5059. }
  5060. parseStatementLike(flags) {
  5061. if (this.state.strict && this.isContextual(127)) {
  5062. const lookahead = this.lookahead();
  5063. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5064. const node = this.startNode();
  5065. this.next();
  5066. return this.flowParseInterface(node);
  5067. }
  5068. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5069. const node = this.startNode();
  5070. this.next();
  5071. return this.flowParseEnumDeclaration(node);
  5072. }
  5073. const stmt = super.parseStatementLike(flags);
  5074. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5075. this.flowPragma = null;
  5076. }
  5077. return stmt;
  5078. }
  5079. parseExpressionStatement(node, expr, decorators) {
  5080. if (expr.type === "Identifier") {
  5081. if (expr.name === "declare") {
  5082. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5083. return this.flowParseDeclare(node);
  5084. }
  5085. } else if (tokenIsIdentifier(this.state.type)) {
  5086. if (expr.name === "interface") {
  5087. return this.flowParseInterface(node);
  5088. } else if (expr.name === "type") {
  5089. return this.flowParseTypeAlias(node);
  5090. } else if (expr.name === "opaque") {
  5091. return this.flowParseOpaqueType(node, false);
  5092. }
  5093. }
  5094. }
  5095. return super.parseExpressionStatement(node, expr, decorators);
  5096. }
  5097. shouldParseExportDeclaration() {
  5098. const {
  5099. type
  5100. } = this.state;
  5101. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5102. return !this.state.containsEsc;
  5103. }
  5104. return super.shouldParseExportDeclaration();
  5105. }
  5106. isExportDefaultSpecifier() {
  5107. const {
  5108. type
  5109. } = this.state;
  5110. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 124) {
  5111. return this.state.containsEsc;
  5112. }
  5113. return super.isExportDefaultSpecifier();
  5114. }
  5115. parseExportDefaultExpression() {
  5116. if (this.shouldParseEnums() && this.isContextual(124)) {
  5117. const node = this.startNode();
  5118. this.next();
  5119. return this.flowParseEnumDeclaration(node);
  5120. }
  5121. return super.parseExportDefaultExpression();
  5122. }
  5123. parseConditional(expr, startLoc, refExpressionErrors) {
  5124. if (!this.match(17)) return expr;
  5125. if (this.state.maybeInArrowParameters) {
  5126. const nextCh = this.lookaheadCharCode();
  5127. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5128. this.setOptionalParametersError(refExpressionErrors);
  5129. return expr;
  5130. }
  5131. }
  5132. this.expect(17);
  5133. const state = this.state.clone();
  5134. const originalNoArrowAt = this.state.noArrowAt;
  5135. const node = this.startNodeAt(startLoc);
  5136. let {
  5137. consequent,
  5138. failed
  5139. } = this.tryParseConditionalConsequent();
  5140. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5141. if (failed || invalid.length > 0) {
  5142. const noArrowAt = [...originalNoArrowAt];
  5143. if (invalid.length > 0) {
  5144. this.state = state;
  5145. this.state.noArrowAt = noArrowAt;
  5146. for (let i = 0; i < invalid.length; i++) {
  5147. noArrowAt.push(invalid[i].start);
  5148. }
  5149. ({
  5150. consequent,
  5151. failed
  5152. } = this.tryParseConditionalConsequent());
  5153. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5154. }
  5155. if (failed && valid.length > 1) {
  5156. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5157. at: state.startLoc
  5158. });
  5159. }
  5160. if (failed && valid.length === 1) {
  5161. this.state = state;
  5162. noArrowAt.push(valid[0].start);
  5163. this.state.noArrowAt = noArrowAt;
  5164. ({
  5165. consequent,
  5166. failed
  5167. } = this.tryParseConditionalConsequent());
  5168. }
  5169. }
  5170. this.getArrowLikeExpressions(consequent, true);
  5171. this.state.noArrowAt = originalNoArrowAt;
  5172. this.expect(14);
  5173. node.test = expr;
  5174. node.consequent = consequent;
  5175. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5176. return this.finishNode(node, "ConditionalExpression");
  5177. }
  5178. tryParseConditionalConsequent() {
  5179. this.state.noArrowParamsConversionAt.push(this.state.start);
  5180. const consequent = this.parseMaybeAssignAllowIn();
  5181. const failed = !this.match(14);
  5182. this.state.noArrowParamsConversionAt.pop();
  5183. return {
  5184. consequent,
  5185. failed
  5186. };
  5187. }
  5188. getArrowLikeExpressions(node, disallowInvalid) {
  5189. const stack = [node];
  5190. const arrows = [];
  5191. while (stack.length !== 0) {
  5192. const node = stack.pop();
  5193. if (node.type === "ArrowFunctionExpression") {
  5194. if (node.typeParameters || !node.returnType) {
  5195. this.finishArrowValidation(node);
  5196. } else {
  5197. arrows.push(node);
  5198. }
  5199. stack.push(node.body);
  5200. } else if (node.type === "ConditionalExpression") {
  5201. stack.push(node.consequent);
  5202. stack.push(node.alternate);
  5203. }
  5204. }
  5205. if (disallowInvalid) {
  5206. arrows.forEach(node => this.finishArrowValidation(node));
  5207. return [arrows, []];
  5208. }
  5209. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5210. }
  5211. finishArrowValidation(node) {
  5212. var _node$extra;
  5213. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5214. this.scope.enter(2 | 4);
  5215. super.checkParams(node, false, true);
  5216. this.scope.exit();
  5217. }
  5218. forwardNoArrowParamsConversionAt(node, parse) {
  5219. let result;
  5220. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5221. this.state.noArrowParamsConversionAt.push(this.state.start);
  5222. result = parse();
  5223. this.state.noArrowParamsConversionAt.pop();
  5224. } else {
  5225. result = parse();
  5226. }
  5227. return result;
  5228. }
  5229. parseParenItem(node, startLoc) {
  5230. node = super.parseParenItem(node, startLoc);
  5231. if (this.eat(17)) {
  5232. node.optional = true;
  5233. this.resetEndLocation(node);
  5234. }
  5235. if (this.match(14)) {
  5236. const typeCastNode = this.startNodeAt(startLoc);
  5237. typeCastNode.expression = node;
  5238. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5239. return this.finishNode(typeCastNode, "TypeCastExpression");
  5240. }
  5241. return node;
  5242. }
  5243. assertModuleNodeAllowed(node) {
  5244. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5245. return;
  5246. }
  5247. super.assertModuleNodeAllowed(node);
  5248. }
  5249. parseExportDeclaration(node) {
  5250. if (this.isContextual(128)) {
  5251. node.exportKind = "type";
  5252. const declarationNode = this.startNode();
  5253. this.next();
  5254. if (this.match(5)) {
  5255. node.specifiers = this.parseExportSpecifiers(true);
  5256. super.parseExportFrom(node);
  5257. return null;
  5258. } else {
  5259. return this.flowParseTypeAlias(declarationNode);
  5260. }
  5261. } else if (this.isContextual(129)) {
  5262. node.exportKind = "type";
  5263. const declarationNode = this.startNode();
  5264. this.next();
  5265. return this.flowParseOpaqueType(declarationNode, false);
  5266. } else if (this.isContextual(127)) {
  5267. node.exportKind = "type";
  5268. const declarationNode = this.startNode();
  5269. this.next();
  5270. return this.flowParseInterface(declarationNode);
  5271. } else if (this.shouldParseEnums() && this.isContextual(124)) {
  5272. node.exportKind = "value";
  5273. const declarationNode = this.startNode();
  5274. this.next();
  5275. return this.flowParseEnumDeclaration(declarationNode);
  5276. } else {
  5277. return super.parseExportDeclaration(node);
  5278. }
  5279. }
  5280. eatExportStar(node) {
  5281. if (super.eatExportStar(node)) return true;
  5282. if (this.isContextual(128) && this.lookahead().type === 55) {
  5283. node.exportKind = "type";
  5284. this.next();
  5285. this.next();
  5286. return true;
  5287. }
  5288. return false;
  5289. }
  5290. maybeParseExportNamespaceSpecifier(node) {
  5291. const {
  5292. startLoc
  5293. } = this.state;
  5294. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5295. if (hasNamespace && node.exportKind === "type") {
  5296. this.unexpected(startLoc);
  5297. }
  5298. return hasNamespace;
  5299. }
  5300. parseClassId(node, isStatement, optionalId) {
  5301. super.parseClassId(node, isStatement, optionalId);
  5302. if (this.match(47)) {
  5303. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5304. }
  5305. }
  5306. parseClassMember(classBody, member, state) {
  5307. const {
  5308. startLoc
  5309. } = this.state;
  5310. if (this.isContextual(123)) {
  5311. if (super.parseClassMemberFromModifier(classBody, member)) {
  5312. return;
  5313. }
  5314. member.declare = true;
  5315. }
  5316. super.parseClassMember(classBody, member, state);
  5317. if (member.declare) {
  5318. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5319. this.raise(FlowErrors.DeclareClassElement, {
  5320. at: startLoc
  5321. });
  5322. } else if (member.value) {
  5323. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  5324. at: member.value
  5325. });
  5326. }
  5327. }
  5328. }
  5329. isIterator(word) {
  5330. return word === "iterator" || word === "asyncIterator";
  5331. }
  5332. readIterator() {
  5333. const word = super.readWord1();
  5334. const fullWord = "@@" + word;
  5335. if (!this.isIterator(word) || !this.state.inType) {
  5336. this.raise(Errors.InvalidIdentifier, {
  5337. at: this.state.curPosition(),
  5338. identifierName: fullWord
  5339. });
  5340. }
  5341. this.finishToken(130, fullWord);
  5342. }
  5343. getTokenFromCode(code) {
  5344. const next = this.input.charCodeAt(this.state.pos + 1);
  5345. if (code === 123 && next === 124) {
  5346. this.finishOp(6, 2);
  5347. } else if (this.state.inType && (code === 62 || code === 60)) {
  5348. this.finishOp(code === 62 ? 48 : 47, 1);
  5349. } else if (this.state.inType && code === 63) {
  5350. if (next === 46) {
  5351. this.finishOp(18, 2);
  5352. } else {
  5353. this.finishOp(17, 1);
  5354. }
  5355. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5356. this.state.pos += 2;
  5357. this.readIterator();
  5358. } else {
  5359. super.getTokenFromCode(code);
  5360. }
  5361. }
  5362. isAssignable(node, isBinding) {
  5363. if (node.type === "TypeCastExpression") {
  5364. return this.isAssignable(node.expression, isBinding);
  5365. } else {
  5366. return super.isAssignable(node, isBinding);
  5367. }
  5368. }
  5369. toAssignable(node, isLHS = false) {
  5370. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5371. node.left = this.typeCastToParameter(node.left);
  5372. }
  5373. super.toAssignable(node, isLHS);
  5374. }
  5375. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5376. for (let i = 0; i < exprList.length; i++) {
  5377. const expr = exprList[i];
  5378. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5379. exprList[i] = this.typeCastToParameter(expr);
  5380. }
  5381. }
  5382. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5383. }
  5384. toReferencedList(exprList, isParenthesizedExpr) {
  5385. for (let i = 0; i < exprList.length; i++) {
  5386. var _expr$extra;
  5387. const expr = exprList[i];
  5388. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5389. this.raise(FlowErrors.TypeCastInPattern, {
  5390. at: expr.typeAnnotation
  5391. });
  5392. }
  5393. }
  5394. return exprList;
  5395. }
  5396. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5397. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5398. if (canBePattern && !this.state.maybeInArrowParameters) {
  5399. this.toReferencedList(node.elements);
  5400. }
  5401. return node;
  5402. }
  5403. isValidLVal(type, isParenthesized, binding) {
  5404. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5405. }
  5406. parseClassProperty(node) {
  5407. if (this.match(14)) {
  5408. node.typeAnnotation = this.flowParseTypeAnnotation();
  5409. }
  5410. return super.parseClassProperty(node);
  5411. }
  5412. parseClassPrivateProperty(node) {
  5413. if (this.match(14)) {
  5414. node.typeAnnotation = this.flowParseTypeAnnotation();
  5415. }
  5416. return super.parseClassPrivateProperty(node);
  5417. }
  5418. isClassMethod() {
  5419. return this.match(47) || super.isClassMethod();
  5420. }
  5421. isClassProperty() {
  5422. return this.match(14) || super.isClassProperty();
  5423. }
  5424. isNonstaticConstructor(method) {
  5425. return !this.match(14) && super.isNonstaticConstructor(method);
  5426. }
  5427. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5428. if (method.variance) {
  5429. this.unexpected(method.variance.loc.start);
  5430. }
  5431. delete method.variance;
  5432. if (this.match(47)) {
  5433. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5434. }
  5435. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5436. if (method.params && isConstructor) {
  5437. const params = method.params;
  5438. if (params.length > 0 && this.isThisParam(params[0])) {
  5439. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5440. at: method
  5441. });
  5442. }
  5443. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5444. const params = method.value.params;
  5445. if (params.length > 0 && this.isThisParam(params[0])) {
  5446. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5447. at: method
  5448. });
  5449. }
  5450. }
  5451. }
  5452. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5453. if (method.variance) {
  5454. this.unexpected(method.variance.loc.start);
  5455. }
  5456. delete method.variance;
  5457. if (this.match(47)) {
  5458. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5459. }
  5460. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5461. }
  5462. parseClassSuper(node) {
  5463. super.parseClassSuper(node);
  5464. if (node.superClass && this.match(47)) {
  5465. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5466. }
  5467. if (this.isContextual(111)) {
  5468. this.next();
  5469. const implemented = node.implements = [];
  5470. do {
  5471. const node = this.startNode();
  5472. node.id = this.flowParseRestrictedIdentifier(true);
  5473. if (this.match(47)) {
  5474. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5475. } else {
  5476. node.typeParameters = null;
  5477. }
  5478. implemented.push(this.finishNode(node, "ClassImplements"));
  5479. } while (this.eat(12));
  5480. }
  5481. }
  5482. checkGetterSetterParams(method) {
  5483. super.checkGetterSetterParams(method);
  5484. const params = this.getObjectOrClassMethodParams(method);
  5485. if (params.length > 0) {
  5486. const param = params[0];
  5487. if (this.isThisParam(param) && method.kind === "get") {
  5488. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  5489. at: param
  5490. });
  5491. } else if (this.isThisParam(param)) {
  5492. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  5493. at: param
  5494. });
  5495. }
  5496. }
  5497. }
  5498. parsePropertyNamePrefixOperator(node) {
  5499. node.variance = this.flowParseVariance();
  5500. }
  5501. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5502. if (prop.variance) {
  5503. this.unexpected(prop.variance.loc.start);
  5504. }
  5505. delete prop.variance;
  5506. let typeParameters;
  5507. if (this.match(47) && !isAccessor) {
  5508. typeParameters = this.flowParseTypeParameterDeclaration();
  5509. if (!this.match(10)) this.unexpected();
  5510. }
  5511. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5512. if (typeParameters) {
  5513. (result.value || result).typeParameters = typeParameters;
  5514. }
  5515. return result;
  5516. }
  5517. parseAssignableListItemTypes(param) {
  5518. if (this.eat(17)) {
  5519. if (param.type !== "Identifier") {
  5520. this.raise(FlowErrors.PatternIsOptional, {
  5521. at: param
  5522. });
  5523. }
  5524. if (this.isThisParam(param)) {
  5525. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5526. at: param
  5527. });
  5528. }
  5529. param.optional = true;
  5530. }
  5531. if (this.match(14)) {
  5532. param.typeAnnotation = this.flowParseTypeAnnotation();
  5533. } else if (this.isThisParam(param)) {
  5534. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  5535. at: param
  5536. });
  5537. }
  5538. if (this.match(29) && this.isThisParam(param)) {
  5539. this.raise(FlowErrors.ThisParamNoDefault, {
  5540. at: param
  5541. });
  5542. }
  5543. this.resetEndLocation(param);
  5544. return param;
  5545. }
  5546. parseMaybeDefault(startLoc, left) {
  5547. const node = super.parseMaybeDefault(startLoc, left);
  5548. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5549. this.raise(FlowErrors.TypeBeforeInitializer, {
  5550. at: node.typeAnnotation
  5551. });
  5552. }
  5553. return node;
  5554. }
  5555. checkImportReflection(node) {
  5556. super.checkImportReflection(node);
  5557. if (node.module && node.importKind !== "value") {
  5558. this.raise(FlowErrors.ImportReflectionHasImportType, {
  5559. at: node.specifiers[0].loc.start
  5560. });
  5561. }
  5562. }
  5563. parseImportSpecifierLocal(node, specifier, type) {
  5564. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5565. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5566. }
  5567. isPotentialImportPhase(isExport) {
  5568. if (super.isPotentialImportPhase(isExport)) return true;
  5569. if (this.isContextual(128)) {
  5570. if (!isExport) return true;
  5571. const ch = this.lookaheadCharCode();
  5572. return ch === 123 || ch === 42;
  5573. }
  5574. return !isExport && this.isContextual(87);
  5575. }
  5576. applyImportPhase(node, isExport, phase, loc) {
  5577. super.applyImportPhase(node, isExport, phase, loc);
  5578. if (isExport) {
  5579. if (!phase && this.match(65)) {
  5580. return;
  5581. }
  5582. node.exportKind = phase === "type" ? phase : "value";
  5583. } else {
  5584. if (phase === "type" && this.match(55)) this.unexpected();
  5585. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5586. }
  5587. }
  5588. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5589. const firstIdent = specifier.imported;
  5590. let specifierTypeKind = null;
  5591. if (firstIdent.type === "Identifier") {
  5592. if (firstIdent.name === "type") {
  5593. specifierTypeKind = "type";
  5594. } else if (firstIdent.name === "typeof") {
  5595. specifierTypeKind = "typeof";
  5596. }
  5597. }
  5598. let isBinding = false;
  5599. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5600. const as_ident = this.parseIdentifier(true);
  5601. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5602. specifier.imported = as_ident;
  5603. specifier.importKind = specifierTypeKind;
  5604. specifier.local = cloneIdentifier(as_ident);
  5605. } else {
  5606. specifier.imported = firstIdent;
  5607. specifier.importKind = null;
  5608. specifier.local = this.parseIdentifier();
  5609. }
  5610. } else {
  5611. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5612. specifier.imported = this.parseIdentifier(true);
  5613. specifier.importKind = specifierTypeKind;
  5614. } else {
  5615. if (importedIsString) {
  5616. throw this.raise(Errors.ImportBindingIsString, {
  5617. at: specifier,
  5618. importName: firstIdent.value
  5619. });
  5620. }
  5621. specifier.imported = firstIdent;
  5622. specifier.importKind = null;
  5623. }
  5624. if (this.eatContextual(93)) {
  5625. specifier.local = this.parseIdentifier();
  5626. } else {
  5627. isBinding = true;
  5628. specifier.local = cloneIdentifier(specifier.imported);
  5629. }
  5630. }
  5631. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5632. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5633. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  5634. at: specifier
  5635. });
  5636. }
  5637. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5638. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5639. }
  5640. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5641. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5642. }
  5643. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5644. }
  5645. parseBindingAtom() {
  5646. switch (this.state.type) {
  5647. case 78:
  5648. return this.parseIdentifier(true);
  5649. default:
  5650. return super.parseBindingAtom();
  5651. }
  5652. }
  5653. parseFunctionParams(node, isConstructor) {
  5654. const kind = node.kind;
  5655. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5656. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5657. }
  5658. super.parseFunctionParams(node, isConstructor);
  5659. }
  5660. parseVarId(decl, kind) {
  5661. super.parseVarId(decl, kind);
  5662. if (this.match(14)) {
  5663. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5664. this.resetEndLocation(decl.id);
  5665. }
  5666. }
  5667. parseAsyncArrowFromCallExpression(node, call) {
  5668. if (this.match(14)) {
  5669. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5670. this.state.noAnonFunctionType = true;
  5671. node.returnType = this.flowParseTypeAnnotation();
  5672. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5673. }
  5674. return super.parseAsyncArrowFromCallExpression(node, call);
  5675. }
  5676. shouldParseAsyncArrow() {
  5677. return this.match(14) || super.shouldParseAsyncArrow();
  5678. }
  5679. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5680. var _jsx;
  5681. let state = null;
  5682. let jsx;
  5683. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  5684. state = this.state.clone();
  5685. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5686. if (!jsx.error) return jsx.node;
  5687. const {
  5688. context
  5689. } = this.state;
  5690. const currentContext = context[context.length - 1];
  5691. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5692. context.pop();
  5693. }
  5694. }
  5695. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5696. var _jsx2, _jsx3;
  5697. state = state || this.state.clone();
  5698. let typeParameters;
  5699. const arrow = this.tryParse(abort => {
  5700. var _arrowExpression$extr;
  5701. typeParameters = this.flowParseTypeParameterDeclaration();
  5702. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5703. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5704. this.resetStartLocationFromNode(result, typeParameters);
  5705. return result;
  5706. });
  5707. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5708. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5709. if (expr.type !== "ArrowFunctionExpression") abort();
  5710. expr.typeParameters = typeParameters;
  5711. this.resetStartLocationFromNode(expr, typeParameters);
  5712. return arrowExpression;
  5713. }, state);
  5714. let arrowExpression = null;
  5715. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5716. if (!arrow.error && !arrow.aborted) {
  5717. if (arrow.node.async) {
  5718. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  5719. at: typeParameters
  5720. });
  5721. }
  5722. return arrow.node;
  5723. }
  5724. arrowExpression = arrow.node;
  5725. }
  5726. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5727. this.state = jsx.failState;
  5728. return jsx.node;
  5729. }
  5730. if (arrowExpression) {
  5731. this.state = arrow.failState;
  5732. return arrowExpression;
  5733. }
  5734. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5735. if (arrow.thrown) throw arrow.error;
  5736. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  5737. at: typeParameters
  5738. });
  5739. }
  5740. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5741. }
  5742. parseArrow(node) {
  5743. if (this.match(14)) {
  5744. const result = this.tryParse(() => {
  5745. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5746. this.state.noAnonFunctionType = true;
  5747. const typeNode = this.startNode();
  5748. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5749. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5750. if (this.canInsertSemicolon()) this.unexpected();
  5751. if (!this.match(19)) this.unexpected();
  5752. return typeNode;
  5753. });
  5754. if (result.thrown) return null;
  5755. if (result.error) this.state = result.failState;
  5756. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5757. }
  5758. return super.parseArrow(node);
  5759. }
  5760. shouldParseArrow(params) {
  5761. return this.match(14) || super.shouldParseArrow(params);
  5762. }
  5763. setArrowFunctionParameters(node, params) {
  5764. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5765. node.params = params;
  5766. } else {
  5767. super.setArrowFunctionParameters(node, params);
  5768. }
  5769. }
  5770. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5771. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5772. return;
  5773. }
  5774. for (let i = 0; i < node.params.length; i++) {
  5775. if (this.isThisParam(node.params[i]) && i > 0) {
  5776. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5777. at: node.params[i]
  5778. });
  5779. }
  5780. }
  5781. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5782. }
  5783. parseParenAndDistinguishExpression(canBeArrow) {
  5784. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5785. }
  5786. parseSubscripts(base, startLoc, noCalls) {
  5787. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  5788. this.next();
  5789. const node = this.startNodeAt(startLoc);
  5790. node.callee = base;
  5791. node.arguments = super.parseCallExpressionArguments(11, false);
  5792. base = this.finishNode(node, "CallExpression");
  5793. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5794. const state = this.state.clone();
  5795. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5796. if (!arrow.error && !arrow.aborted) return arrow.node;
  5797. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5798. if (result.node && !result.error) return result.node;
  5799. if (arrow.node) {
  5800. this.state = arrow.failState;
  5801. return arrow.node;
  5802. }
  5803. if (result.node) {
  5804. this.state = result.failState;
  5805. return result.node;
  5806. }
  5807. throw arrow.error || result.error;
  5808. }
  5809. return super.parseSubscripts(base, startLoc, noCalls);
  5810. }
  5811. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5812. if (this.match(18) && this.isLookaheadToken_lt()) {
  5813. subscriptState.optionalChainMember = true;
  5814. if (noCalls) {
  5815. subscriptState.stop = true;
  5816. return base;
  5817. }
  5818. this.next();
  5819. const node = this.startNodeAt(startLoc);
  5820. node.callee = base;
  5821. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5822. this.expect(10);
  5823. node.arguments = this.parseCallExpressionArguments(11, false);
  5824. node.optional = true;
  5825. return this.finishCallExpression(node, true);
  5826. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5827. const node = this.startNodeAt(startLoc);
  5828. node.callee = base;
  5829. const result = this.tryParse(() => {
  5830. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5831. this.expect(10);
  5832. node.arguments = super.parseCallExpressionArguments(11, false);
  5833. if (subscriptState.optionalChainMember) {
  5834. node.optional = false;
  5835. }
  5836. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5837. });
  5838. if (result.node) {
  5839. if (result.error) this.state = result.failState;
  5840. return result.node;
  5841. }
  5842. }
  5843. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5844. }
  5845. parseNewCallee(node) {
  5846. super.parseNewCallee(node);
  5847. let targs = null;
  5848. if (this.shouldParseTypes() && this.match(47)) {
  5849. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5850. }
  5851. node.typeArguments = targs;
  5852. }
  5853. parseAsyncArrowWithTypeParameters(startLoc) {
  5854. const node = this.startNodeAt(startLoc);
  5855. this.parseFunctionParams(node, false);
  5856. if (!this.parseArrow(node)) return;
  5857. return super.parseArrowExpression(node, undefined, true);
  5858. }
  5859. readToken_mult_modulo(code) {
  5860. const next = this.input.charCodeAt(this.state.pos + 1);
  5861. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5862. this.state.hasFlowComment = false;
  5863. this.state.pos += 2;
  5864. this.nextToken();
  5865. return;
  5866. }
  5867. super.readToken_mult_modulo(code);
  5868. }
  5869. readToken_pipe_amp(code) {
  5870. const next = this.input.charCodeAt(this.state.pos + 1);
  5871. if (code === 124 && next === 125) {
  5872. this.finishOp(9, 2);
  5873. return;
  5874. }
  5875. super.readToken_pipe_amp(code);
  5876. }
  5877. parseTopLevel(file, program) {
  5878. const fileNode = super.parseTopLevel(file, program);
  5879. if (this.state.hasFlowComment) {
  5880. this.raise(FlowErrors.UnterminatedFlowComment, {
  5881. at: this.state.curPosition()
  5882. });
  5883. }
  5884. return fileNode;
  5885. }
  5886. skipBlockComment() {
  5887. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5888. if (this.state.hasFlowComment) {
  5889. throw this.raise(FlowErrors.NestedFlowComment, {
  5890. at: this.state.startLoc
  5891. });
  5892. }
  5893. this.hasFlowCommentCompletion();
  5894. const commentSkip = this.skipFlowComment();
  5895. if (commentSkip) {
  5896. this.state.pos += commentSkip;
  5897. this.state.hasFlowComment = true;
  5898. }
  5899. return;
  5900. }
  5901. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5902. }
  5903. skipFlowComment() {
  5904. const {
  5905. pos
  5906. } = this.state;
  5907. let shiftToFirstNonWhiteSpace = 2;
  5908. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5909. shiftToFirstNonWhiteSpace++;
  5910. }
  5911. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5912. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5913. if (ch2 === 58 && ch3 === 58) {
  5914. return shiftToFirstNonWhiteSpace + 2;
  5915. }
  5916. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5917. return shiftToFirstNonWhiteSpace + 12;
  5918. }
  5919. if (ch2 === 58 && ch3 !== 58) {
  5920. return shiftToFirstNonWhiteSpace;
  5921. }
  5922. return false;
  5923. }
  5924. hasFlowCommentCompletion() {
  5925. const end = this.input.indexOf("*/", this.state.pos);
  5926. if (end === -1) {
  5927. throw this.raise(Errors.UnterminatedComment, {
  5928. at: this.state.curPosition()
  5929. });
  5930. }
  5931. }
  5932. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5933. enumName,
  5934. memberName
  5935. }) {
  5936. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  5937. at: loc,
  5938. memberName,
  5939. enumName
  5940. });
  5941. }
  5942. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5943. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  5944. at: loc
  5945. }, enumContext));
  5946. }
  5947. flowEnumErrorNumberMemberNotInitialized(loc, {
  5948. enumName,
  5949. memberName
  5950. }) {
  5951. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  5952. at: loc,
  5953. enumName,
  5954. memberName
  5955. });
  5956. }
  5957. flowEnumErrorStringMemberInconsistentlyInitialized(node, {
  5958. enumName
  5959. }) {
  5960. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, {
  5961. at: node,
  5962. enumName
  5963. });
  5964. }
  5965. flowEnumMemberInit() {
  5966. const startLoc = this.state.startLoc;
  5967. const endOfInit = () => this.match(12) || this.match(8);
  5968. switch (this.state.type) {
  5969. case 132:
  5970. {
  5971. const literal = this.parseNumericLiteral(this.state.value);
  5972. if (endOfInit()) {
  5973. return {
  5974. type: "number",
  5975. loc: literal.loc.start,
  5976. value: literal
  5977. };
  5978. }
  5979. return {
  5980. type: "invalid",
  5981. loc: startLoc
  5982. };
  5983. }
  5984. case 131:
  5985. {
  5986. const literal = this.parseStringLiteral(this.state.value);
  5987. if (endOfInit()) {
  5988. return {
  5989. type: "string",
  5990. loc: literal.loc.start,
  5991. value: literal
  5992. };
  5993. }
  5994. return {
  5995. type: "invalid",
  5996. loc: startLoc
  5997. };
  5998. }
  5999. case 85:
  6000. case 86:
  6001. {
  6002. const literal = this.parseBooleanLiteral(this.match(85));
  6003. if (endOfInit()) {
  6004. return {
  6005. type: "boolean",
  6006. loc: literal.loc.start,
  6007. value: literal
  6008. };
  6009. }
  6010. return {
  6011. type: "invalid",
  6012. loc: startLoc
  6013. };
  6014. }
  6015. default:
  6016. return {
  6017. type: "invalid",
  6018. loc: startLoc
  6019. };
  6020. }
  6021. }
  6022. flowEnumMemberRaw() {
  6023. const loc = this.state.startLoc;
  6024. const id = this.parseIdentifier(true);
  6025. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6026. type: "none",
  6027. loc
  6028. };
  6029. return {
  6030. id,
  6031. init
  6032. };
  6033. }
  6034. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6035. const {
  6036. explicitType
  6037. } = context;
  6038. if (explicitType === null) {
  6039. return;
  6040. }
  6041. if (explicitType !== expectedType) {
  6042. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6043. }
  6044. }
  6045. flowEnumMembers({
  6046. enumName,
  6047. explicitType
  6048. }) {
  6049. const seenNames = new Set();
  6050. const members = {
  6051. booleanMembers: [],
  6052. numberMembers: [],
  6053. stringMembers: [],
  6054. defaultedMembers: []
  6055. };
  6056. let hasUnknownMembers = false;
  6057. while (!this.match(8)) {
  6058. if (this.eat(21)) {
  6059. hasUnknownMembers = true;
  6060. break;
  6061. }
  6062. const memberNode = this.startNode();
  6063. const {
  6064. id,
  6065. init
  6066. } = this.flowEnumMemberRaw();
  6067. const memberName = id.name;
  6068. if (memberName === "") {
  6069. continue;
  6070. }
  6071. if (/^[a-z]/.test(memberName)) {
  6072. this.raise(FlowErrors.EnumInvalidMemberName, {
  6073. at: id,
  6074. memberName,
  6075. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6076. enumName
  6077. });
  6078. }
  6079. if (seenNames.has(memberName)) {
  6080. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6081. at: id,
  6082. memberName,
  6083. enumName
  6084. });
  6085. }
  6086. seenNames.add(memberName);
  6087. const context = {
  6088. enumName,
  6089. explicitType,
  6090. memberName
  6091. };
  6092. memberNode.id = id;
  6093. switch (init.type) {
  6094. case "boolean":
  6095. {
  6096. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6097. memberNode.init = init.value;
  6098. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6099. break;
  6100. }
  6101. case "number":
  6102. {
  6103. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6104. memberNode.init = init.value;
  6105. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6106. break;
  6107. }
  6108. case "string":
  6109. {
  6110. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6111. memberNode.init = init.value;
  6112. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6113. break;
  6114. }
  6115. case "invalid":
  6116. {
  6117. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6118. }
  6119. case "none":
  6120. {
  6121. switch (explicitType) {
  6122. case "boolean":
  6123. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6124. break;
  6125. case "number":
  6126. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6127. break;
  6128. default:
  6129. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6130. }
  6131. }
  6132. }
  6133. if (!this.match(8)) {
  6134. this.expect(12);
  6135. }
  6136. }
  6137. return {
  6138. members,
  6139. hasUnknownMembers
  6140. };
  6141. }
  6142. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6143. enumName
  6144. }) {
  6145. if (initializedMembers.length === 0) {
  6146. return defaultedMembers;
  6147. } else if (defaultedMembers.length === 0) {
  6148. return initializedMembers;
  6149. } else if (defaultedMembers.length > initializedMembers.length) {
  6150. for (const member of initializedMembers) {
  6151. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6152. enumName
  6153. });
  6154. }
  6155. return defaultedMembers;
  6156. } else {
  6157. for (const member of defaultedMembers) {
  6158. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6159. enumName
  6160. });
  6161. }
  6162. return initializedMembers;
  6163. }
  6164. }
  6165. flowEnumParseExplicitType({
  6166. enumName
  6167. }) {
  6168. if (!this.eatContextual(101)) return null;
  6169. if (!tokenIsIdentifier(this.state.type)) {
  6170. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6171. at: this.state.startLoc,
  6172. enumName
  6173. });
  6174. }
  6175. const {
  6176. value
  6177. } = this.state;
  6178. this.next();
  6179. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6180. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6181. at: this.state.startLoc,
  6182. enumName,
  6183. invalidEnumType: value
  6184. });
  6185. }
  6186. return value;
  6187. }
  6188. flowEnumBody(node, id) {
  6189. const enumName = id.name;
  6190. const nameLoc = id.loc.start;
  6191. const explicitType = this.flowEnumParseExplicitType({
  6192. enumName
  6193. });
  6194. this.expect(5);
  6195. const {
  6196. members,
  6197. hasUnknownMembers
  6198. } = this.flowEnumMembers({
  6199. enumName,
  6200. explicitType
  6201. });
  6202. node.hasUnknownMembers = hasUnknownMembers;
  6203. switch (explicitType) {
  6204. case "boolean":
  6205. node.explicitType = true;
  6206. node.members = members.booleanMembers;
  6207. this.expect(8);
  6208. return this.finishNode(node, "EnumBooleanBody");
  6209. case "number":
  6210. node.explicitType = true;
  6211. node.members = members.numberMembers;
  6212. this.expect(8);
  6213. return this.finishNode(node, "EnumNumberBody");
  6214. case "string":
  6215. node.explicitType = true;
  6216. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6217. enumName
  6218. });
  6219. this.expect(8);
  6220. return this.finishNode(node, "EnumStringBody");
  6221. case "symbol":
  6222. node.members = members.defaultedMembers;
  6223. this.expect(8);
  6224. return this.finishNode(node, "EnumSymbolBody");
  6225. default:
  6226. {
  6227. const empty = () => {
  6228. node.members = [];
  6229. this.expect(8);
  6230. return this.finishNode(node, "EnumStringBody");
  6231. };
  6232. node.explicitType = false;
  6233. const boolsLen = members.booleanMembers.length;
  6234. const numsLen = members.numberMembers.length;
  6235. const strsLen = members.stringMembers.length;
  6236. const defaultedLen = members.defaultedMembers.length;
  6237. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6238. return empty();
  6239. } else if (!boolsLen && !numsLen) {
  6240. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6241. enumName
  6242. });
  6243. this.expect(8);
  6244. return this.finishNode(node, "EnumStringBody");
  6245. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6246. for (const member of members.defaultedMembers) {
  6247. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6248. enumName,
  6249. memberName: member.id.name
  6250. });
  6251. }
  6252. node.members = members.booleanMembers;
  6253. this.expect(8);
  6254. return this.finishNode(node, "EnumBooleanBody");
  6255. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6256. for (const member of members.defaultedMembers) {
  6257. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6258. enumName,
  6259. memberName: member.id.name
  6260. });
  6261. }
  6262. node.members = members.numberMembers;
  6263. this.expect(8);
  6264. return this.finishNode(node, "EnumNumberBody");
  6265. } else {
  6266. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6267. at: nameLoc,
  6268. enumName
  6269. });
  6270. return empty();
  6271. }
  6272. }
  6273. }
  6274. }
  6275. flowParseEnumDeclaration(node) {
  6276. const id = this.parseIdentifier();
  6277. node.id = id;
  6278. node.body = this.flowEnumBody(this.startNode(), id);
  6279. return this.finishNode(node, "EnumDeclaration");
  6280. }
  6281. isLookaheadToken_lt() {
  6282. const next = this.nextTokenStart();
  6283. if (this.input.charCodeAt(next) === 60) {
  6284. const afterNext = this.input.charCodeAt(next + 1);
  6285. return afterNext !== 60 && afterNext !== 61;
  6286. }
  6287. return false;
  6288. }
  6289. maybeUnwrapTypeCastExpression(node) {
  6290. return node.type === "TypeCastExpression" ? node.expression : node;
  6291. }
  6292. };
  6293. const entities = {
  6294. __proto__: null,
  6295. quot: "\u0022",
  6296. amp: "&",
  6297. apos: "\u0027",
  6298. lt: "<",
  6299. gt: ">",
  6300. nbsp: "\u00A0",
  6301. iexcl: "\u00A1",
  6302. cent: "\u00A2",
  6303. pound: "\u00A3",
  6304. curren: "\u00A4",
  6305. yen: "\u00A5",
  6306. brvbar: "\u00A6",
  6307. sect: "\u00A7",
  6308. uml: "\u00A8",
  6309. copy: "\u00A9",
  6310. ordf: "\u00AA",
  6311. laquo: "\u00AB",
  6312. not: "\u00AC",
  6313. shy: "\u00AD",
  6314. reg: "\u00AE",
  6315. macr: "\u00AF",
  6316. deg: "\u00B0",
  6317. plusmn: "\u00B1",
  6318. sup2: "\u00B2",
  6319. sup3: "\u00B3",
  6320. acute: "\u00B4",
  6321. micro: "\u00B5",
  6322. para: "\u00B6",
  6323. middot: "\u00B7",
  6324. cedil: "\u00B8",
  6325. sup1: "\u00B9",
  6326. ordm: "\u00BA",
  6327. raquo: "\u00BB",
  6328. frac14: "\u00BC",
  6329. frac12: "\u00BD",
  6330. frac34: "\u00BE",
  6331. iquest: "\u00BF",
  6332. Agrave: "\u00C0",
  6333. Aacute: "\u00C1",
  6334. Acirc: "\u00C2",
  6335. Atilde: "\u00C3",
  6336. Auml: "\u00C4",
  6337. Aring: "\u00C5",
  6338. AElig: "\u00C6",
  6339. Ccedil: "\u00C7",
  6340. Egrave: "\u00C8",
  6341. Eacute: "\u00C9",
  6342. Ecirc: "\u00CA",
  6343. Euml: "\u00CB",
  6344. Igrave: "\u00CC",
  6345. Iacute: "\u00CD",
  6346. Icirc: "\u00CE",
  6347. Iuml: "\u00CF",
  6348. ETH: "\u00D0",
  6349. Ntilde: "\u00D1",
  6350. Ograve: "\u00D2",
  6351. Oacute: "\u00D3",
  6352. Ocirc: "\u00D4",
  6353. Otilde: "\u00D5",
  6354. Ouml: "\u00D6",
  6355. times: "\u00D7",
  6356. Oslash: "\u00D8",
  6357. Ugrave: "\u00D9",
  6358. Uacute: "\u00DA",
  6359. Ucirc: "\u00DB",
  6360. Uuml: "\u00DC",
  6361. Yacute: "\u00DD",
  6362. THORN: "\u00DE",
  6363. szlig: "\u00DF",
  6364. agrave: "\u00E0",
  6365. aacute: "\u00E1",
  6366. acirc: "\u00E2",
  6367. atilde: "\u00E3",
  6368. auml: "\u00E4",
  6369. aring: "\u00E5",
  6370. aelig: "\u00E6",
  6371. ccedil: "\u00E7",
  6372. egrave: "\u00E8",
  6373. eacute: "\u00E9",
  6374. ecirc: "\u00EA",
  6375. euml: "\u00EB",
  6376. igrave: "\u00EC",
  6377. iacute: "\u00ED",
  6378. icirc: "\u00EE",
  6379. iuml: "\u00EF",
  6380. eth: "\u00F0",
  6381. ntilde: "\u00F1",
  6382. ograve: "\u00F2",
  6383. oacute: "\u00F3",
  6384. ocirc: "\u00F4",
  6385. otilde: "\u00F5",
  6386. ouml: "\u00F6",
  6387. divide: "\u00F7",
  6388. oslash: "\u00F8",
  6389. ugrave: "\u00F9",
  6390. uacute: "\u00FA",
  6391. ucirc: "\u00FB",
  6392. uuml: "\u00FC",
  6393. yacute: "\u00FD",
  6394. thorn: "\u00FE",
  6395. yuml: "\u00FF",
  6396. OElig: "\u0152",
  6397. oelig: "\u0153",
  6398. Scaron: "\u0160",
  6399. scaron: "\u0161",
  6400. Yuml: "\u0178",
  6401. fnof: "\u0192",
  6402. circ: "\u02C6",
  6403. tilde: "\u02DC",
  6404. Alpha: "\u0391",
  6405. Beta: "\u0392",
  6406. Gamma: "\u0393",
  6407. Delta: "\u0394",
  6408. Epsilon: "\u0395",
  6409. Zeta: "\u0396",
  6410. Eta: "\u0397",
  6411. Theta: "\u0398",
  6412. Iota: "\u0399",
  6413. Kappa: "\u039A",
  6414. Lambda: "\u039B",
  6415. Mu: "\u039C",
  6416. Nu: "\u039D",
  6417. Xi: "\u039E",
  6418. Omicron: "\u039F",
  6419. Pi: "\u03A0",
  6420. Rho: "\u03A1",
  6421. Sigma: "\u03A3",
  6422. Tau: "\u03A4",
  6423. Upsilon: "\u03A5",
  6424. Phi: "\u03A6",
  6425. Chi: "\u03A7",
  6426. Psi: "\u03A8",
  6427. Omega: "\u03A9",
  6428. alpha: "\u03B1",
  6429. beta: "\u03B2",
  6430. gamma: "\u03B3",
  6431. delta: "\u03B4",
  6432. epsilon: "\u03B5",
  6433. zeta: "\u03B6",
  6434. eta: "\u03B7",
  6435. theta: "\u03B8",
  6436. iota: "\u03B9",
  6437. kappa: "\u03BA",
  6438. lambda: "\u03BB",
  6439. mu: "\u03BC",
  6440. nu: "\u03BD",
  6441. xi: "\u03BE",
  6442. omicron: "\u03BF",
  6443. pi: "\u03C0",
  6444. rho: "\u03C1",
  6445. sigmaf: "\u03C2",
  6446. sigma: "\u03C3",
  6447. tau: "\u03C4",
  6448. upsilon: "\u03C5",
  6449. phi: "\u03C6",
  6450. chi: "\u03C7",
  6451. psi: "\u03C8",
  6452. omega: "\u03C9",
  6453. thetasym: "\u03D1",
  6454. upsih: "\u03D2",
  6455. piv: "\u03D6",
  6456. ensp: "\u2002",
  6457. emsp: "\u2003",
  6458. thinsp: "\u2009",
  6459. zwnj: "\u200C",
  6460. zwj: "\u200D",
  6461. lrm: "\u200E",
  6462. rlm: "\u200F",
  6463. ndash: "\u2013",
  6464. mdash: "\u2014",
  6465. lsquo: "\u2018",
  6466. rsquo: "\u2019",
  6467. sbquo: "\u201A",
  6468. ldquo: "\u201C",
  6469. rdquo: "\u201D",
  6470. bdquo: "\u201E",
  6471. dagger: "\u2020",
  6472. Dagger: "\u2021",
  6473. bull: "\u2022",
  6474. hellip: "\u2026",
  6475. permil: "\u2030",
  6476. prime: "\u2032",
  6477. Prime: "\u2033",
  6478. lsaquo: "\u2039",
  6479. rsaquo: "\u203A",
  6480. oline: "\u203E",
  6481. frasl: "\u2044",
  6482. euro: "\u20AC",
  6483. image: "\u2111",
  6484. weierp: "\u2118",
  6485. real: "\u211C",
  6486. trade: "\u2122",
  6487. alefsym: "\u2135",
  6488. larr: "\u2190",
  6489. uarr: "\u2191",
  6490. rarr: "\u2192",
  6491. darr: "\u2193",
  6492. harr: "\u2194",
  6493. crarr: "\u21B5",
  6494. lArr: "\u21D0",
  6495. uArr: "\u21D1",
  6496. rArr: "\u21D2",
  6497. dArr: "\u21D3",
  6498. hArr: "\u21D4",
  6499. forall: "\u2200",
  6500. part: "\u2202",
  6501. exist: "\u2203",
  6502. empty: "\u2205",
  6503. nabla: "\u2207",
  6504. isin: "\u2208",
  6505. notin: "\u2209",
  6506. ni: "\u220B",
  6507. prod: "\u220F",
  6508. sum: "\u2211",
  6509. minus: "\u2212",
  6510. lowast: "\u2217",
  6511. radic: "\u221A",
  6512. prop: "\u221D",
  6513. infin: "\u221E",
  6514. ang: "\u2220",
  6515. and: "\u2227",
  6516. or: "\u2228",
  6517. cap: "\u2229",
  6518. cup: "\u222A",
  6519. int: "\u222B",
  6520. there4: "\u2234",
  6521. sim: "\u223C",
  6522. cong: "\u2245",
  6523. asymp: "\u2248",
  6524. ne: "\u2260",
  6525. equiv: "\u2261",
  6526. le: "\u2264",
  6527. ge: "\u2265",
  6528. sub: "\u2282",
  6529. sup: "\u2283",
  6530. nsub: "\u2284",
  6531. sube: "\u2286",
  6532. supe: "\u2287",
  6533. oplus: "\u2295",
  6534. otimes: "\u2297",
  6535. perp: "\u22A5",
  6536. sdot: "\u22C5",
  6537. lceil: "\u2308",
  6538. rceil: "\u2309",
  6539. lfloor: "\u230A",
  6540. rfloor: "\u230B",
  6541. lang: "\u2329",
  6542. rang: "\u232A",
  6543. loz: "\u25CA",
  6544. spades: "\u2660",
  6545. clubs: "\u2663",
  6546. hearts: "\u2665",
  6547. diams: "\u2666"
  6548. };
  6549. const JsxErrors = ParseErrorEnum`jsx`({
  6550. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6551. MissingClosingTagElement: ({
  6552. openingTagName
  6553. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6554. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6555. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6556. UnexpectedToken: ({
  6557. unexpected,
  6558. HTMLEntity
  6559. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6560. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6561. UnterminatedJsxContent: "Unterminated JSX contents.",
  6562. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6563. });
  6564. function isFragment(object) {
  6565. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6566. }
  6567. function getQualifiedJSXName(object) {
  6568. if (object.type === "JSXIdentifier") {
  6569. return object.name;
  6570. }
  6571. if (object.type === "JSXNamespacedName") {
  6572. return object.namespace.name + ":" + object.name.name;
  6573. }
  6574. if (object.type === "JSXMemberExpression") {
  6575. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6576. }
  6577. throw new Error("Node had unexpected type: " + object.type);
  6578. }
  6579. var jsx = superClass => class JSXParserMixin extends superClass {
  6580. jsxReadToken() {
  6581. let out = "";
  6582. let chunkStart = this.state.pos;
  6583. for (;;) {
  6584. if (this.state.pos >= this.length) {
  6585. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  6586. at: this.state.startLoc
  6587. });
  6588. }
  6589. const ch = this.input.charCodeAt(this.state.pos);
  6590. switch (ch) {
  6591. case 60:
  6592. case 123:
  6593. if (this.state.pos === this.state.start) {
  6594. if (ch === 60 && this.state.canStartJSXElement) {
  6595. ++this.state.pos;
  6596. this.finishToken(140);
  6597. } else {
  6598. super.getTokenFromCode(ch);
  6599. }
  6600. return;
  6601. }
  6602. out += this.input.slice(chunkStart, this.state.pos);
  6603. this.finishToken(139, out);
  6604. return;
  6605. case 38:
  6606. out += this.input.slice(chunkStart, this.state.pos);
  6607. out += this.jsxReadEntity();
  6608. chunkStart = this.state.pos;
  6609. break;
  6610. case 62:
  6611. case 125:
  6612. default:
  6613. if (isNewLine(ch)) {
  6614. out += this.input.slice(chunkStart, this.state.pos);
  6615. out += this.jsxReadNewLine(true);
  6616. chunkStart = this.state.pos;
  6617. } else {
  6618. ++this.state.pos;
  6619. }
  6620. }
  6621. }
  6622. }
  6623. jsxReadNewLine(normalizeCRLF) {
  6624. const ch = this.input.charCodeAt(this.state.pos);
  6625. let out;
  6626. ++this.state.pos;
  6627. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6628. ++this.state.pos;
  6629. out = normalizeCRLF ? "\n" : "\r\n";
  6630. } else {
  6631. out = String.fromCharCode(ch);
  6632. }
  6633. ++this.state.curLine;
  6634. this.state.lineStart = this.state.pos;
  6635. return out;
  6636. }
  6637. jsxReadString(quote) {
  6638. let out = "";
  6639. let chunkStart = ++this.state.pos;
  6640. for (;;) {
  6641. if (this.state.pos >= this.length) {
  6642. throw this.raise(Errors.UnterminatedString, {
  6643. at: this.state.startLoc
  6644. });
  6645. }
  6646. const ch = this.input.charCodeAt(this.state.pos);
  6647. if (ch === quote) break;
  6648. if (ch === 38) {
  6649. out += this.input.slice(chunkStart, this.state.pos);
  6650. out += this.jsxReadEntity();
  6651. chunkStart = this.state.pos;
  6652. } else if (isNewLine(ch)) {
  6653. out += this.input.slice(chunkStart, this.state.pos);
  6654. out += this.jsxReadNewLine(false);
  6655. chunkStart = this.state.pos;
  6656. } else {
  6657. ++this.state.pos;
  6658. }
  6659. }
  6660. out += this.input.slice(chunkStart, this.state.pos++);
  6661. this.finishToken(131, out);
  6662. }
  6663. jsxReadEntity() {
  6664. const startPos = ++this.state.pos;
  6665. if (this.codePointAtPos(this.state.pos) === 35) {
  6666. ++this.state.pos;
  6667. let radix = 10;
  6668. if (this.codePointAtPos(this.state.pos) === 120) {
  6669. radix = 16;
  6670. ++this.state.pos;
  6671. }
  6672. const codePoint = this.readInt(radix, undefined, false, "bail");
  6673. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6674. ++this.state.pos;
  6675. return String.fromCodePoint(codePoint);
  6676. }
  6677. } else {
  6678. let count = 0;
  6679. let semi = false;
  6680. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  6681. ++this.state.pos;
  6682. }
  6683. if (semi) {
  6684. const desc = this.input.slice(startPos, this.state.pos);
  6685. const entity = entities[desc];
  6686. ++this.state.pos;
  6687. if (entity) {
  6688. return entity;
  6689. }
  6690. }
  6691. }
  6692. this.state.pos = startPos;
  6693. return "&";
  6694. }
  6695. jsxReadWord() {
  6696. let ch;
  6697. const start = this.state.pos;
  6698. do {
  6699. ch = this.input.charCodeAt(++this.state.pos);
  6700. } while (isIdentifierChar(ch) || ch === 45);
  6701. this.finishToken(138, this.input.slice(start, this.state.pos));
  6702. }
  6703. jsxParseIdentifier() {
  6704. const node = this.startNode();
  6705. if (this.match(138)) {
  6706. node.name = this.state.value;
  6707. } else if (tokenIsKeyword(this.state.type)) {
  6708. node.name = tokenLabelName(this.state.type);
  6709. } else {
  6710. this.unexpected();
  6711. }
  6712. this.next();
  6713. return this.finishNode(node, "JSXIdentifier");
  6714. }
  6715. jsxParseNamespacedName() {
  6716. const startLoc = this.state.startLoc;
  6717. const name = this.jsxParseIdentifier();
  6718. if (!this.eat(14)) return name;
  6719. const node = this.startNodeAt(startLoc);
  6720. node.namespace = name;
  6721. node.name = this.jsxParseIdentifier();
  6722. return this.finishNode(node, "JSXNamespacedName");
  6723. }
  6724. jsxParseElementName() {
  6725. const startLoc = this.state.startLoc;
  6726. let node = this.jsxParseNamespacedName();
  6727. if (node.type === "JSXNamespacedName") {
  6728. return node;
  6729. }
  6730. while (this.eat(16)) {
  6731. const newNode = this.startNodeAt(startLoc);
  6732. newNode.object = node;
  6733. newNode.property = this.jsxParseIdentifier();
  6734. node = this.finishNode(newNode, "JSXMemberExpression");
  6735. }
  6736. return node;
  6737. }
  6738. jsxParseAttributeValue() {
  6739. let node;
  6740. switch (this.state.type) {
  6741. case 5:
  6742. node = this.startNode();
  6743. this.setContext(types.brace);
  6744. this.next();
  6745. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6746. if (node.expression.type === "JSXEmptyExpression") {
  6747. this.raise(JsxErrors.AttributeIsEmpty, {
  6748. at: node
  6749. });
  6750. }
  6751. return node;
  6752. case 140:
  6753. case 131:
  6754. return this.parseExprAtom();
  6755. default:
  6756. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  6757. at: this.state.startLoc
  6758. });
  6759. }
  6760. }
  6761. jsxParseEmptyExpression() {
  6762. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6763. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6764. }
  6765. jsxParseSpreadChild(node) {
  6766. this.next();
  6767. node.expression = this.parseExpression();
  6768. this.setContext(types.j_expr);
  6769. this.state.canStartJSXElement = true;
  6770. this.expect(8);
  6771. return this.finishNode(node, "JSXSpreadChild");
  6772. }
  6773. jsxParseExpressionContainer(node, previousContext) {
  6774. if (this.match(8)) {
  6775. node.expression = this.jsxParseEmptyExpression();
  6776. } else {
  6777. const expression = this.parseExpression();
  6778. node.expression = expression;
  6779. }
  6780. this.setContext(previousContext);
  6781. this.state.canStartJSXElement = true;
  6782. this.expect(8);
  6783. return this.finishNode(node, "JSXExpressionContainer");
  6784. }
  6785. jsxParseAttribute() {
  6786. const node = this.startNode();
  6787. if (this.match(5)) {
  6788. this.setContext(types.brace);
  6789. this.next();
  6790. this.expect(21);
  6791. node.argument = this.parseMaybeAssignAllowIn();
  6792. this.setContext(types.j_oTag);
  6793. this.state.canStartJSXElement = true;
  6794. this.expect(8);
  6795. return this.finishNode(node, "JSXSpreadAttribute");
  6796. }
  6797. node.name = this.jsxParseNamespacedName();
  6798. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6799. return this.finishNode(node, "JSXAttribute");
  6800. }
  6801. jsxParseOpeningElementAt(startLoc) {
  6802. const node = this.startNodeAt(startLoc);
  6803. if (this.eat(141)) {
  6804. return this.finishNode(node, "JSXOpeningFragment");
  6805. }
  6806. node.name = this.jsxParseElementName();
  6807. return this.jsxParseOpeningElementAfterName(node);
  6808. }
  6809. jsxParseOpeningElementAfterName(node) {
  6810. const attributes = [];
  6811. while (!this.match(56) && !this.match(141)) {
  6812. attributes.push(this.jsxParseAttribute());
  6813. }
  6814. node.attributes = attributes;
  6815. node.selfClosing = this.eat(56);
  6816. this.expect(141);
  6817. return this.finishNode(node, "JSXOpeningElement");
  6818. }
  6819. jsxParseClosingElementAt(startLoc) {
  6820. const node = this.startNodeAt(startLoc);
  6821. if (this.eat(141)) {
  6822. return this.finishNode(node, "JSXClosingFragment");
  6823. }
  6824. node.name = this.jsxParseElementName();
  6825. this.expect(141);
  6826. return this.finishNode(node, "JSXClosingElement");
  6827. }
  6828. jsxParseElementAt(startLoc) {
  6829. const node = this.startNodeAt(startLoc);
  6830. const children = [];
  6831. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6832. let closingElement = null;
  6833. if (!openingElement.selfClosing) {
  6834. contents: for (;;) {
  6835. switch (this.state.type) {
  6836. case 140:
  6837. startLoc = this.state.startLoc;
  6838. this.next();
  6839. if (this.eat(56)) {
  6840. closingElement = this.jsxParseClosingElementAt(startLoc);
  6841. break contents;
  6842. }
  6843. children.push(this.jsxParseElementAt(startLoc));
  6844. break;
  6845. case 139:
  6846. children.push(this.parseExprAtom());
  6847. break;
  6848. case 5:
  6849. {
  6850. const node = this.startNode();
  6851. this.setContext(types.brace);
  6852. this.next();
  6853. if (this.match(21)) {
  6854. children.push(this.jsxParseSpreadChild(node));
  6855. } else {
  6856. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6857. }
  6858. break;
  6859. }
  6860. default:
  6861. this.unexpected();
  6862. }
  6863. }
  6864. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6865. this.raise(JsxErrors.MissingClosingTagFragment, {
  6866. at: closingElement
  6867. });
  6868. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6869. this.raise(JsxErrors.MissingClosingTagElement, {
  6870. at: closingElement,
  6871. openingTagName: getQualifiedJSXName(openingElement.name)
  6872. });
  6873. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6874. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6875. this.raise(JsxErrors.MissingClosingTagElement, {
  6876. at: closingElement,
  6877. openingTagName: getQualifiedJSXName(openingElement.name)
  6878. });
  6879. }
  6880. }
  6881. }
  6882. if (isFragment(openingElement)) {
  6883. node.openingFragment = openingElement;
  6884. node.closingFragment = closingElement;
  6885. } else {
  6886. node.openingElement = openingElement;
  6887. node.closingElement = closingElement;
  6888. }
  6889. node.children = children;
  6890. if (this.match(47)) {
  6891. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  6892. at: this.state.startLoc
  6893. });
  6894. }
  6895. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6896. }
  6897. jsxParseElement() {
  6898. const startLoc = this.state.startLoc;
  6899. this.next();
  6900. return this.jsxParseElementAt(startLoc);
  6901. }
  6902. setContext(newContext) {
  6903. const {
  6904. context
  6905. } = this.state;
  6906. context[context.length - 1] = newContext;
  6907. }
  6908. parseExprAtom(refExpressionErrors) {
  6909. if (this.match(139)) {
  6910. return this.parseLiteral(this.state.value, "JSXText");
  6911. } else if (this.match(140)) {
  6912. return this.jsxParseElement();
  6913. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6914. this.replaceToken(140);
  6915. return this.jsxParseElement();
  6916. } else {
  6917. return super.parseExprAtom(refExpressionErrors);
  6918. }
  6919. }
  6920. skipSpace() {
  6921. const curContext = this.curContext();
  6922. if (!curContext.preserveSpace) super.skipSpace();
  6923. }
  6924. getTokenFromCode(code) {
  6925. const context = this.curContext();
  6926. if (context === types.j_expr) {
  6927. this.jsxReadToken();
  6928. return;
  6929. }
  6930. if (context === types.j_oTag || context === types.j_cTag) {
  6931. if (isIdentifierStart(code)) {
  6932. this.jsxReadWord();
  6933. return;
  6934. }
  6935. if (code === 62) {
  6936. ++this.state.pos;
  6937. this.finishToken(141);
  6938. return;
  6939. }
  6940. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6941. this.jsxReadString(code);
  6942. return;
  6943. }
  6944. }
  6945. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6946. ++this.state.pos;
  6947. this.finishToken(140);
  6948. return;
  6949. }
  6950. super.getTokenFromCode(code);
  6951. }
  6952. updateContext(prevType) {
  6953. const {
  6954. context,
  6955. type
  6956. } = this.state;
  6957. if (type === 56 && prevType === 140) {
  6958. context.splice(-2, 2, types.j_cTag);
  6959. this.state.canStartJSXElement = false;
  6960. } else if (type === 140) {
  6961. context.push(types.j_oTag);
  6962. } else if (type === 141) {
  6963. const out = context[context.length - 1];
  6964. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6965. context.pop();
  6966. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6967. } else {
  6968. this.setContext(types.j_expr);
  6969. this.state.canStartJSXElement = true;
  6970. }
  6971. } else {
  6972. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6973. }
  6974. }
  6975. };
  6976. class TypeScriptScope extends Scope {
  6977. constructor(...args) {
  6978. super(...args);
  6979. this.types = new Set();
  6980. this.enums = new Set();
  6981. this.constEnums = new Set();
  6982. this.classes = new Set();
  6983. this.exportOnlyBindings = new Set();
  6984. }
  6985. }
  6986. class TypeScriptScopeHandler extends ScopeHandler {
  6987. constructor(...args) {
  6988. super(...args);
  6989. this.importsStack = [];
  6990. }
  6991. createScope(flags) {
  6992. this.importsStack.push(new Set());
  6993. return new TypeScriptScope(flags);
  6994. }
  6995. enter(flags) {
  6996. if (flags == 256) {
  6997. this.importsStack.push(new Set());
  6998. }
  6999. super.enter(flags);
  7000. }
  7001. exit() {
  7002. const flags = super.exit();
  7003. if (flags == 256) {
  7004. this.importsStack.pop();
  7005. }
  7006. return flags;
  7007. }
  7008. hasImport(name, allowShadow) {
  7009. const len = this.importsStack.length;
  7010. if (this.importsStack[len - 1].has(name)) {
  7011. return true;
  7012. }
  7013. if (!allowShadow && len > 1) {
  7014. for (let i = 0; i < len - 1; i++) {
  7015. if (this.importsStack[i].has(name)) return true;
  7016. }
  7017. }
  7018. return false;
  7019. }
  7020. declareName(name, bindingType, loc) {
  7021. if (bindingType & 4096) {
  7022. if (this.hasImport(name, true)) {
  7023. this.parser.raise(Errors.VarRedeclaration, {
  7024. at: loc,
  7025. identifierName: name
  7026. });
  7027. }
  7028. this.importsStack[this.importsStack.length - 1].add(name);
  7029. return;
  7030. }
  7031. const scope = this.currentScope();
  7032. if (bindingType & 1024) {
  7033. this.maybeExportDefined(scope, name);
  7034. scope.exportOnlyBindings.add(name);
  7035. return;
  7036. }
  7037. super.declareName(name, bindingType, loc);
  7038. if (bindingType & 2) {
  7039. if (!(bindingType & 1)) {
  7040. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7041. this.maybeExportDefined(scope, name);
  7042. }
  7043. scope.types.add(name);
  7044. }
  7045. if (bindingType & 256) scope.enums.add(name);
  7046. if (bindingType & 512) {
  7047. scope.constEnums.add(name);
  7048. }
  7049. if (bindingType & 128) scope.classes.add(name);
  7050. }
  7051. isRedeclaredInScope(scope, name, bindingType) {
  7052. if (scope.enums.has(name)) {
  7053. if (bindingType & 256) {
  7054. const isConst = !!(bindingType & 512);
  7055. const wasConst = scope.constEnums.has(name);
  7056. return isConst !== wasConst;
  7057. }
  7058. return true;
  7059. }
  7060. if (bindingType & 128 && scope.classes.has(name)) {
  7061. if (scope.lexical.has(name)) {
  7062. return !!(bindingType & 1);
  7063. } else {
  7064. return false;
  7065. }
  7066. }
  7067. if (bindingType & 2 && scope.types.has(name)) {
  7068. return true;
  7069. }
  7070. return super.isRedeclaredInScope(scope, name, bindingType);
  7071. }
  7072. checkLocalExport(id) {
  7073. const {
  7074. name
  7075. } = id;
  7076. if (this.hasImport(name)) return;
  7077. const len = this.scopeStack.length;
  7078. for (let i = len - 1; i >= 0; i--) {
  7079. const scope = this.scopeStack[i];
  7080. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7081. }
  7082. super.checkLocalExport(id);
  7083. }
  7084. }
  7085. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7086. const unwrapParenthesizedExpression = node => {
  7087. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7088. };
  7089. class LValParser extends NodeUtils {
  7090. toAssignable(node, isLHS = false) {
  7091. var _node$extra, _node$extra3;
  7092. let parenthesized = undefined;
  7093. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7094. parenthesized = unwrapParenthesizedExpression(node);
  7095. if (isLHS) {
  7096. if (parenthesized.type === "Identifier") {
  7097. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
  7098. at: node
  7099. });
  7100. } else if (parenthesized.type !== "MemberExpression") {
  7101. this.raise(Errors.InvalidParenthesizedAssignment, {
  7102. at: node
  7103. });
  7104. }
  7105. } else {
  7106. this.raise(Errors.InvalidParenthesizedAssignment, {
  7107. at: node
  7108. });
  7109. }
  7110. }
  7111. switch (node.type) {
  7112. case "Identifier":
  7113. case "ObjectPattern":
  7114. case "ArrayPattern":
  7115. case "AssignmentPattern":
  7116. case "RestElement":
  7117. break;
  7118. case "ObjectExpression":
  7119. node.type = "ObjectPattern";
  7120. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7121. var _node$extra2;
  7122. const prop = node.properties[i];
  7123. const isLast = i === last;
  7124. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7125. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7126. this.raise(Errors.RestTrailingComma, {
  7127. at: node.extra.trailingCommaLoc
  7128. });
  7129. }
  7130. }
  7131. break;
  7132. case "ObjectProperty":
  7133. {
  7134. const {
  7135. key,
  7136. value
  7137. } = node;
  7138. if (this.isPrivateName(key)) {
  7139. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7140. }
  7141. this.toAssignable(value, isLHS);
  7142. break;
  7143. }
  7144. case "SpreadElement":
  7145. {
  7146. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7147. }
  7148. case "ArrayExpression":
  7149. node.type = "ArrayPattern";
  7150. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7151. break;
  7152. case "AssignmentExpression":
  7153. if (node.operator !== "=") {
  7154. this.raise(Errors.MissingEqInAssignment, {
  7155. at: node.left.loc.end
  7156. });
  7157. }
  7158. node.type = "AssignmentPattern";
  7159. delete node.operator;
  7160. this.toAssignable(node.left, isLHS);
  7161. break;
  7162. case "ParenthesizedExpression":
  7163. this.toAssignable(parenthesized, isLHS);
  7164. break;
  7165. }
  7166. }
  7167. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7168. if (prop.type === "ObjectMethod") {
  7169. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  7170. at: prop.key
  7171. });
  7172. } else if (prop.type === "SpreadElement") {
  7173. prop.type = "RestElement";
  7174. const arg = prop.argument;
  7175. this.checkToRestConversion(arg, false);
  7176. this.toAssignable(arg, isLHS);
  7177. if (!isLast) {
  7178. this.raise(Errors.RestTrailingComma, {
  7179. at: prop
  7180. });
  7181. }
  7182. } else {
  7183. this.toAssignable(prop, isLHS);
  7184. }
  7185. }
  7186. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7187. const end = exprList.length - 1;
  7188. for (let i = 0; i <= end; i++) {
  7189. const elt = exprList[i];
  7190. if (!elt) continue;
  7191. if (elt.type === "SpreadElement") {
  7192. elt.type = "RestElement";
  7193. const arg = elt.argument;
  7194. this.checkToRestConversion(arg, true);
  7195. this.toAssignable(arg, isLHS);
  7196. } else {
  7197. this.toAssignable(elt, isLHS);
  7198. }
  7199. if (elt.type === "RestElement") {
  7200. if (i < end) {
  7201. this.raise(Errors.RestTrailingComma, {
  7202. at: elt
  7203. });
  7204. } else if (trailingCommaLoc) {
  7205. this.raise(Errors.RestTrailingComma, {
  7206. at: trailingCommaLoc
  7207. });
  7208. }
  7209. }
  7210. }
  7211. }
  7212. isAssignable(node, isBinding) {
  7213. switch (node.type) {
  7214. case "Identifier":
  7215. case "ObjectPattern":
  7216. case "ArrayPattern":
  7217. case "AssignmentPattern":
  7218. case "RestElement":
  7219. return true;
  7220. case "ObjectExpression":
  7221. {
  7222. const last = node.properties.length - 1;
  7223. return node.properties.every((prop, i) => {
  7224. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7225. });
  7226. }
  7227. case "ObjectProperty":
  7228. return this.isAssignable(node.value);
  7229. case "SpreadElement":
  7230. return this.isAssignable(node.argument);
  7231. case "ArrayExpression":
  7232. return node.elements.every(element => element === null || this.isAssignable(element));
  7233. case "AssignmentExpression":
  7234. return node.operator === "=";
  7235. case "ParenthesizedExpression":
  7236. return this.isAssignable(node.expression);
  7237. case "MemberExpression":
  7238. case "OptionalMemberExpression":
  7239. return !isBinding;
  7240. default:
  7241. return false;
  7242. }
  7243. }
  7244. toReferencedList(exprList, isParenthesizedExpr) {
  7245. return exprList;
  7246. }
  7247. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7248. this.toReferencedList(exprList, isParenthesizedExpr);
  7249. for (const expr of exprList) {
  7250. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7251. this.toReferencedListDeep(expr.elements);
  7252. }
  7253. }
  7254. }
  7255. parseSpread(refExpressionErrors) {
  7256. const node = this.startNode();
  7257. this.next();
  7258. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7259. return this.finishNode(node, "SpreadElement");
  7260. }
  7261. parseRestBinding() {
  7262. const node = this.startNode();
  7263. this.next();
  7264. node.argument = this.parseBindingAtom();
  7265. return this.finishNode(node, "RestElement");
  7266. }
  7267. parseBindingAtom() {
  7268. switch (this.state.type) {
  7269. case 0:
  7270. {
  7271. const node = this.startNode();
  7272. this.next();
  7273. node.elements = this.parseBindingList(3, 93, 1);
  7274. return this.finishNode(node, "ArrayPattern");
  7275. }
  7276. case 5:
  7277. return this.parseObjectLike(8, true);
  7278. }
  7279. return this.parseIdentifier();
  7280. }
  7281. parseBindingList(close, closeCharCode, flags) {
  7282. const allowEmpty = flags & 1;
  7283. const elts = [];
  7284. let first = true;
  7285. while (!this.eat(close)) {
  7286. if (first) {
  7287. first = false;
  7288. } else {
  7289. this.expect(12);
  7290. }
  7291. if (allowEmpty && this.match(12)) {
  7292. elts.push(null);
  7293. } else if (this.eat(close)) {
  7294. break;
  7295. } else if (this.match(21)) {
  7296. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  7297. if (!this.checkCommaAfterRest(closeCharCode)) {
  7298. this.expect(close);
  7299. break;
  7300. }
  7301. } else {
  7302. const decorators = [];
  7303. if (this.match(26) && this.hasPlugin("decorators")) {
  7304. this.raise(Errors.UnsupportedParameterDecorator, {
  7305. at: this.state.startLoc
  7306. });
  7307. }
  7308. while (this.match(26)) {
  7309. decorators.push(this.parseDecorator());
  7310. }
  7311. elts.push(this.parseAssignableListItem(flags, decorators));
  7312. }
  7313. }
  7314. return elts;
  7315. }
  7316. parseBindingRestProperty(prop) {
  7317. this.next();
  7318. prop.argument = this.parseIdentifier();
  7319. this.checkCommaAfterRest(125);
  7320. return this.finishNode(prop, "RestElement");
  7321. }
  7322. parseBindingProperty() {
  7323. const prop = this.startNode();
  7324. const {
  7325. type,
  7326. startLoc
  7327. } = this.state;
  7328. if (type === 21) {
  7329. return this.parseBindingRestProperty(prop);
  7330. } else if (type === 136) {
  7331. this.expectPlugin("destructuringPrivate", startLoc);
  7332. this.classScope.usePrivateName(this.state.value, startLoc);
  7333. prop.key = this.parsePrivateName();
  7334. } else {
  7335. this.parsePropertyName(prop);
  7336. }
  7337. prop.method = false;
  7338. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7339. }
  7340. parseAssignableListItem(flags, decorators) {
  7341. const left = this.parseMaybeDefault();
  7342. this.parseAssignableListItemTypes(left, flags);
  7343. const elt = this.parseMaybeDefault(left.loc.start, left);
  7344. if (decorators.length) {
  7345. left.decorators = decorators;
  7346. }
  7347. return elt;
  7348. }
  7349. parseAssignableListItemTypes(param, flags) {
  7350. return param;
  7351. }
  7352. parseMaybeDefault(startLoc, left) {
  7353. var _startLoc, _left;
  7354. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7355. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7356. if (!this.eat(29)) return left;
  7357. const node = this.startNodeAt(startLoc);
  7358. node.left = left;
  7359. node.right = this.parseMaybeAssignAllowIn();
  7360. return this.finishNode(node, "AssignmentPattern");
  7361. }
  7362. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7363. return getOwn$1({
  7364. AssignmentPattern: "left",
  7365. RestElement: "argument",
  7366. ObjectProperty: "value",
  7367. ParenthesizedExpression: "expression",
  7368. ArrayPattern: "elements",
  7369. ObjectPattern: "properties"
  7370. }, type);
  7371. }
  7372. checkLVal(expression, {
  7373. in: ancestor,
  7374. binding = 64,
  7375. checkClashes = false,
  7376. strictModeChanged = false,
  7377. hasParenthesizedAncestor = false
  7378. }) {
  7379. var _expression$extra;
  7380. const type = expression.type;
  7381. if (this.isObjectMethod(expression)) return;
  7382. if (type === "MemberExpression") {
  7383. if (binding !== 64) {
  7384. this.raise(Errors.InvalidPropertyBindingPattern, {
  7385. at: expression
  7386. });
  7387. }
  7388. return;
  7389. }
  7390. if (type === "Identifier") {
  7391. this.checkIdentifier(expression, binding, strictModeChanged);
  7392. const {
  7393. name
  7394. } = expression;
  7395. if (checkClashes) {
  7396. if (checkClashes.has(name)) {
  7397. this.raise(Errors.ParamDupe, {
  7398. at: expression
  7399. });
  7400. } else {
  7401. checkClashes.add(name);
  7402. }
  7403. }
  7404. return;
  7405. }
  7406. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7407. if (validity === true) return;
  7408. if (validity === false) {
  7409. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7410. this.raise(ParseErrorClass, {
  7411. at: expression,
  7412. ancestor
  7413. });
  7414. return;
  7415. }
  7416. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  7417. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? {
  7418. type
  7419. } : ancestor;
  7420. for (const child of [].concat(expression[key])) {
  7421. if (child) {
  7422. this.checkLVal(child, {
  7423. in: nextAncestor,
  7424. binding,
  7425. checkClashes,
  7426. strictModeChanged,
  7427. hasParenthesizedAncestor: isParenthesizedExpression
  7428. });
  7429. }
  7430. }
  7431. }
  7432. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7433. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7434. if (bindingType === 64) {
  7435. this.raise(Errors.StrictEvalArguments, {
  7436. at,
  7437. referenceName: at.name
  7438. });
  7439. } else {
  7440. this.raise(Errors.StrictEvalArgumentsBinding, {
  7441. at,
  7442. bindingName: at.name
  7443. });
  7444. }
  7445. }
  7446. if (bindingType & 8192 && at.name === "let") {
  7447. this.raise(Errors.LetInLexicalBinding, {
  7448. at
  7449. });
  7450. }
  7451. if (!(bindingType & 64)) {
  7452. this.declareNameFromIdentifier(at, bindingType);
  7453. }
  7454. }
  7455. declareNameFromIdentifier(identifier, binding) {
  7456. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7457. }
  7458. checkToRestConversion(node, allowPattern) {
  7459. switch (node.type) {
  7460. case "ParenthesizedExpression":
  7461. this.checkToRestConversion(node.expression, allowPattern);
  7462. break;
  7463. case "Identifier":
  7464. case "MemberExpression":
  7465. break;
  7466. case "ArrayExpression":
  7467. case "ObjectExpression":
  7468. if (allowPattern) break;
  7469. default:
  7470. this.raise(Errors.InvalidRestAssignmentPattern, {
  7471. at: node
  7472. });
  7473. }
  7474. }
  7475. checkCommaAfterRest(close) {
  7476. if (!this.match(12)) {
  7477. return false;
  7478. }
  7479. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  7480. at: this.state.startLoc
  7481. });
  7482. return true;
  7483. }
  7484. }
  7485. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7486. function nonNull(x) {
  7487. if (x == null) {
  7488. throw new Error(`Unexpected ${x} value.`);
  7489. }
  7490. return x;
  7491. }
  7492. function assert(x) {
  7493. if (!x) {
  7494. throw new Error("Assert fail");
  7495. }
  7496. }
  7497. const TSErrors = ParseErrorEnum`typescript`({
  7498. AbstractMethodHasImplementation: ({
  7499. methodName
  7500. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7501. AbstractPropertyHasInitializer: ({
  7502. propertyName
  7503. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7504. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7505. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7506. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7507. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7508. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7509. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7510. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7511. DeclareAccessor: ({
  7512. kind
  7513. }) => `'declare' is not allowed in ${kind}ters.`,
  7514. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7515. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7516. DuplicateAccessibilityModifier: ({
  7517. modifier
  7518. }) => `Accessibility modifier already seen.`,
  7519. DuplicateModifier: ({
  7520. modifier
  7521. }) => `Duplicate modifier: '${modifier}'.`,
  7522. EmptyHeritageClauseType: ({
  7523. token
  7524. }) => `'${token}' list cannot be empty.`,
  7525. EmptyTypeArguments: "Type argument list cannot be empty.",
  7526. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7527. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7528. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7529. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7530. IncompatibleModifiers: ({
  7531. modifiers
  7532. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7533. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7534. IndexSignatureHasAccessibility: ({
  7535. modifier
  7536. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7537. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7538. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7539. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7540. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7541. InvalidModifierOnTypeMember: ({
  7542. modifier
  7543. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7544. InvalidModifierOnTypeParameter: ({
  7545. modifier
  7546. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7547. InvalidModifierOnTypeParameterPositions: ({
  7548. modifier
  7549. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7550. InvalidModifiersOrder: ({
  7551. orderedModifiers
  7552. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7553. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7554. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7555. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7556. MixedLabeledAndUnlabeledElements: "Tuple members must all have names or all not have names.",
  7557. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7558. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7559. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7560. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7561. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7562. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7563. PrivateElementHasAccessibility: ({
  7564. modifier
  7565. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7566. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7567. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7568. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7569. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7570. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7571. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7572. SingleTypeParameterWithoutTrailingComma: ({
  7573. typeParameterName
  7574. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7575. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7576. 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?`).",
  7577. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7578. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7579. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7580. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7581. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7582. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7583. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7584. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7585. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7586. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7587. UnsupportedSignatureParameterKind: ({
  7588. type
  7589. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7590. });
  7591. function keywordTypeFromName(value) {
  7592. switch (value) {
  7593. case "any":
  7594. return "TSAnyKeyword";
  7595. case "boolean":
  7596. return "TSBooleanKeyword";
  7597. case "bigint":
  7598. return "TSBigIntKeyword";
  7599. case "never":
  7600. return "TSNeverKeyword";
  7601. case "number":
  7602. return "TSNumberKeyword";
  7603. case "object":
  7604. return "TSObjectKeyword";
  7605. case "string":
  7606. return "TSStringKeyword";
  7607. case "symbol":
  7608. return "TSSymbolKeyword";
  7609. case "undefined":
  7610. return "TSUndefinedKeyword";
  7611. case "unknown":
  7612. return "TSUnknownKeyword";
  7613. default:
  7614. return undefined;
  7615. }
  7616. }
  7617. function tsIsAccessModifier(modifier) {
  7618. return modifier === "private" || modifier === "public" || modifier === "protected";
  7619. }
  7620. function tsIsVarianceAnnotations(modifier) {
  7621. return modifier === "in" || modifier === "out";
  7622. }
  7623. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7624. constructor(...args) {
  7625. super(...args);
  7626. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7627. allowedModifiers: ["in", "out"],
  7628. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7629. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7630. });
  7631. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7632. allowedModifiers: ["const"],
  7633. disallowedModifiers: ["in", "out"],
  7634. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7635. });
  7636. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7637. allowedModifiers: ["in", "out", "const"],
  7638. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7639. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7640. });
  7641. }
  7642. getScopeHandler() {
  7643. return TypeScriptScopeHandler;
  7644. }
  7645. tsIsIdentifier() {
  7646. return tokenIsIdentifier(this.state.type);
  7647. }
  7648. tsTokenCanFollowModifier() {
  7649. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(136) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7650. }
  7651. tsNextTokenCanFollowModifier() {
  7652. this.next();
  7653. return this.tsTokenCanFollowModifier();
  7654. }
  7655. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7656. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7657. return undefined;
  7658. }
  7659. const modifier = this.state.value;
  7660. if (allowedModifiers.indexOf(modifier) !== -1) {
  7661. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7662. return undefined;
  7663. }
  7664. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7665. return modifier;
  7666. }
  7667. }
  7668. return undefined;
  7669. }
  7670. tsParseModifiers({
  7671. allowedModifiers,
  7672. disallowedModifiers,
  7673. stopOnStartOfClassStaticBlock,
  7674. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7675. }, modified) {
  7676. const enforceOrder = (loc, modifier, before, after) => {
  7677. if (modifier === before && modified[after]) {
  7678. this.raise(TSErrors.InvalidModifiersOrder, {
  7679. at: loc,
  7680. orderedModifiers: [before, after]
  7681. });
  7682. }
  7683. };
  7684. const incompatible = (loc, modifier, mod1, mod2) => {
  7685. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7686. this.raise(TSErrors.IncompatibleModifiers, {
  7687. at: loc,
  7688. modifiers: [mod1, mod2]
  7689. });
  7690. }
  7691. };
  7692. for (;;) {
  7693. const {
  7694. startLoc
  7695. } = this.state;
  7696. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7697. if (!modifier) break;
  7698. if (tsIsAccessModifier(modifier)) {
  7699. if (modified.accessibility) {
  7700. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  7701. at: startLoc,
  7702. modifier
  7703. });
  7704. } else {
  7705. enforceOrder(startLoc, modifier, modifier, "override");
  7706. enforceOrder(startLoc, modifier, modifier, "static");
  7707. enforceOrder(startLoc, modifier, modifier, "readonly");
  7708. modified.accessibility = modifier;
  7709. }
  7710. } else if (tsIsVarianceAnnotations(modifier)) {
  7711. if (modified[modifier]) {
  7712. this.raise(TSErrors.DuplicateModifier, {
  7713. at: startLoc,
  7714. modifier
  7715. });
  7716. }
  7717. modified[modifier] = true;
  7718. enforceOrder(startLoc, modifier, "in", "out");
  7719. } else {
  7720. if (Object.hasOwnProperty.call(modified, modifier)) {
  7721. this.raise(TSErrors.DuplicateModifier, {
  7722. at: startLoc,
  7723. modifier
  7724. });
  7725. } else {
  7726. enforceOrder(startLoc, modifier, "static", "readonly");
  7727. enforceOrder(startLoc, modifier, "static", "override");
  7728. enforceOrder(startLoc, modifier, "override", "readonly");
  7729. enforceOrder(startLoc, modifier, "abstract", "override");
  7730. incompatible(startLoc, modifier, "declare", "override");
  7731. incompatible(startLoc, modifier, "static", "abstract");
  7732. }
  7733. modified[modifier] = true;
  7734. }
  7735. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7736. this.raise(errorTemplate, {
  7737. at: startLoc,
  7738. modifier
  7739. });
  7740. }
  7741. }
  7742. }
  7743. tsIsListTerminator(kind) {
  7744. switch (kind) {
  7745. case "EnumMembers":
  7746. case "TypeMembers":
  7747. return this.match(8);
  7748. case "HeritageClauseElement":
  7749. return this.match(5);
  7750. case "TupleElementTypes":
  7751. return this.match(3);
  7752. case "TypeParametersOrArguments":
  7753. return this.match(48);
  7754. }
  7755. }
  7756. tsParseList(kind, parseElement) {
  7757. const result = [];
  7758. while (!this.tsIsListTerminator(kind)) {
  7759. result.push(parseElement());
  7760. }
  7761. return result;
  7762. }
  7763. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7764. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7765. }
  7766. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7767. const result = [];
  7768. let trailingCommaPos = -1;
  7769. for (;;) {
  7770. if (this.tsIsListTerminator(kind)) {
  7771. break;
  7772. }
  7773. trailingCommaPos = -1;
  7774. const element = parseElement();
  7775. if (element == null) {
  7776. return undefined;
  7777. }
  7778. result.push(element);
  7779. if (this.eat(12)) {
  7780. trailingCommaPos = this.state.lastTokStart;
  7781. continue;
  7782. }
  7783. if (this.tsIsListTerminator(kind)) {
  7784. break;
  7785. }
  7786. if (expectSuccess) {
  7787. this.expect(12);
  7788. }
  7789. return undefined;
  7790. }
  7791. if (refTrailingCommaPos) {
  7792. refTrailingCommaPos.value = trailingCommaPos;
  7793. }
  7794. return result;
  7795. }
  7796. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7797. if (!skipFirstToken) {
  7798. if (bracket) {
  7799. this.expect(0);
  7800. } else {
  7801. this.expect(47);
  7802. }
  7803. }
  7804. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7805. if (bracket) {
  7806. this.expect(3);
  7807. } else {
  7808. this.expect(48);
  7809. }
  7810. return result;
  7811. }
  7812. tsParseImportType() {
  7813. const node = this.startNode();
  7814. this.expect(83);
  7815. this.expect(10);
  7816. if (!this.match(131)) {
  7817. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  7818. at: this.state.startLoc
  7819. });
  7820. }
  7821. node.argument = super.parseExprAtom();
  7822. this.expect(11);
  7823. if (this.eat(16)) {
  7824. node.qualifier = this.tsParseEntityName();
  7825. }
  7826. if (this.match(47)) {
  7827. node.typeParameters = this.tsParseTypeArguments();
  7828. }
  7829. return this.finishNode(node, "TSImportType");
  7830. }
  7831. tsParseEntityName(allowReservedWords = true) {
  7832. let entity = this.parseIdentifier(allowReservedWords);
  7833. while (this.eat(16)) {
  7834. const node = this.startNodeAtNode(entity);
  7835. node.left = entity;
  7836. node.right = this.parseIdentifier(allowReservedWords);
  7837. entity = this.finishNode(node, "TSQualifiedName");
  7838. }
  7839. return entity;
  7840. }
  7841. tsParseTypeReference() {
  7842. const node = this.startNode();
  7843. node.typeName = this.tsParseEntityName();
  7844. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7845. node.typeParameters = this.tsParseTypeArguments();
  7846. }
  7847. return this.finishNode(node, "TSTypeReference");
  7848. }
  7849. tsParseThisTypePredicate(lhs) {
  7850. this.next();
  7851. const node = this.startNodeAtNode(lhs);
  7852. node.parameterName = lhs;
  7853. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7854. node.asserts = false;
  7855. return this.finishNode(node, "TSTypePredicate");
  7856. }
  7857. tsParseThisTypeNode() {
  7858. const node = this.startNode();
  7859. this.next();
  7860. return this.finishNode(node, "TSThisType");
  7861. }
  7862. tsParseTypeQuery() {
  7863. const node = this.startNode();
  7864. this.expect(87);
  7865. if (this.match(83)) {
  7866. node.exprName = this.tsParseImportType();
  7867. } else {
  7868. node.exprName = this.tsParseEntityName();
  7869. }
  7870. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7871. node.typeParameters = this.tsParseTypeArguments();
  7872. }
  7873. return this.finishNode(node, "TSTypeQuery");
  7874. }
  7875. tsParseTypeParameter(parseModifiers) {
  7876. const node = this.startNode();
  7877. parseModifiers(node);
  7878. node.name = this.tsParseTypeParameterName();
  7879. node.constraint = this.tsEatThenParseType(81);
  7880. node.default = this.tsEatThenParseType(29);
  7881. return this.finishNode(node, "TSTypeParameter");
  7882. }
  7883. tsTryParseTypeParameters(parseModifiers) {
  7884. if (this.match(47)) {
  7885. return this.tsParseTypeParameters(parseModifiers);
  7886. }
  7887. }
  7888. tsParseTypeParameters(parseModifiers) {
  7889. const node = this.startNode();
  7890. if (this.match(47) || this.match(140)) {
  7891. this.next();
  7892. } else {
  7893. this.unexpected();
  7894. }
  7895. const refTrailingCommaPos = {
  7896. value: -1
  7897. };
  7898. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7899. if (node.params.length === 0) {
  7900. this.raise(TSErrors.EmptyTypeParameters, {
  7901. at: node
  7902. });
  7903. }
  7904. if (refTrailingCommaPos.value !== -1) {
  7905. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7906. }
  7907. return this.finishNode(node, "TSTypeParameterDeclaration");
  7908. }
  7909. tsFillSignature(returnToken, signature) {
  7910. const returnTokenRequired = returnToken === 19;
  7911. const paramsKey = "parameters";
  7912. const returnTypeKey = "typeAnnotation";
  7913. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7914. this.expect(10);
  7915. signature[paramsKey] = this.tsParseBindingListForSignature();
  7916. if (returnTokenRequired) {
  7917. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7918. } else if (this.match(returnToken)) {
  7919. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7920. }
  7921. }
  7922. tsParseBindingListForSignature() {
  7923. const list = super.parseBindingList(11, 41, 2);
  7924. for (const pattern of list) {
  7925. const {
  7926. type
  7927. } = pattern;
  7928. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7929. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  7930. at: pattern,
  7931. type
  7932. });
  7933. }
  7934. }
  7935. return list;
  7936. }
  7937. tsParseTypeMemberSemicolon() {
  7938. if (!this.eat(12) && !this.isLineTerminator()) {
  7939. this.expect(13);
  7940. }
  7941. }
  7942. tsParseSignatureMember(kind, node) {
  7943. this.tsFillSignature(14, node);
  7944. this.tsParseTypeMemberSemicolon();
  7945. return this.finishNode(node, kind);
  7946. }
  7947. tsIsUnambiguouslyIndexSignature() {
  7948. this.next();
  7949. if (tokenIsIdentifier(this.state.type)) {
  7950. this.next();
  7951. return this.match(14);
  7952. }
  7953. return false;
  7954. }
  7955. tsTryParseIndexSignature(node) {
  7956. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7957. return;
  7958. }
  7959. this.expect(0);
  7960. const id = this.parseIdentifier();
  7961. id.typeAnnotation = this.tsParseTypeAnnotation();
  7962. this.resetEndLocation(id);
  7963. this.expect(3);
  7964. node.parameters = [id];
  7965. const type = this.tsTryParseTypeAnnotation();
  7966. if (type) node.typeAnnotation = type;
  7967. this.tsParseTypeMemberSemicolon();
  7968. return this.finishNode(node, "TSIndexSignature");
  7969. }
  7970. tsParsePropertyOrMethodSignature(node, readonly) {
  7971. if (this.eat(17)) node.optional = true;
  7972. const nodeAny = node;
  7973. if (this.match(10) || this.match(47)) {
  7974. if (readonly) {
  7975. this.raise(TSErrors.ReadonlyForMethodSignature, {
  7976. at: node
  7977. });
  7978. }
  7979. const method = nodeAny;
  7980. if (method.kind && this.match(47)) {
  7981. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  7982. at: this.state.curPosition()
  7983. });
  7984. }
  7985. this.tsFillSignature(14, method);
  7986. this.tsParseTypeMemberSemicolon();
  7987. const paramsKey = "parameters";
  7988. const returnTypeKey = "typeAnnotation";
  7989. if (method.kind === "get") {
  7990. if (method[paramsKey].length > 0) {
  7991. this.raise(Errors.BadGetterArity, {
  7992. at: this.state.curPosition()
  7993. });
  7994. if (this.isThisParam(method[paramsKey][0])) {
  7995. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  7996. at: this.state.curPosition()
  7997. });
  7998. }
  7999. }
  8000. } else if (method.kind === "set") {
  8001. if (method[paramsKey].length !== 1) {
  8002. this.raise(Errors.BadSetterArity, {
  8003. at: this.state.curPosition()
  8004. });
  8005. } else {
  8006. const firstParameter = method[paramsKey][0];
  8007. if (this.isThisParam(firstParameter)) {
  8008. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8009. at: this.state.curPosition()
  8010. });
  8011. }
  8012. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8013. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  8014. at: this.state.curPosition()
  8015. });
  8016. }
  8017. if (firstParameter.type === "RestElement") {
  8018. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  8019. at: this.state.curPosition()
  8020. });
  8021. }
  8022. }
  8023. if (method[returnTypeKey]) {
  8024. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  8025. at: method[returnTypeKey]
  8026. });
  8027. }
  8028. } else {
  8029. method.kind = "method";
  8030. }
  8031. return this.finishNode(method, "TSMethodSignature");
  8032. } else {
  8033. const property = nodeAny;
  8034. if (readonly) property.readonly = true;
  8035. const type = this.tsTryParseTypeAnnotation();
  8036. if (type) property.typeAnnotation = type;
  8037. this.tsParseTypeMemberSemicolon();
  8038. return this.finishNode(property, "TSPropertySignature");
  8039. }
  8040. }
  8041. tsParseTypeMember() {
  8042. const node = this.startNode();
  8043. if (this.match(10) || this.match(47)) {
  8044. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8045. }
  8046. if (this.match(77)) {
  8047. const id = this.startNode();
  8048. this.next();
  8049. if (this.match(10) || this.match(47)) {
  8050. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8051. } else {
  8052. node.key = this.createIdentifier(id, "new");
  8053. return this.tsParsePropertyOrMethodSignature(node, false);
  8054. }
  8055. }
  8056. this.tsParseModifiers({
  8057. allowedModifiers: ["readonly"],
  8058. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8059. }, node);
  8060. const idx = this.tsTryParseIndexSignature(node);
  8061. if (idx) {
  8062. return idx;
  8063. }
  8064. super.parsePropertyName(node);
  8065. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8066. node.kind = node.key.name;
  8067. super.parsePropertyName(node);
  8068. }
  8069. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8070. }
  8071. tsParseTypeLiteral() {
  8072. const node = this.startNode();
  8073. node.members = this.tsParseObjectTypeMembers();
  8074. return this.finishNode(node, "TSTypeLiteral");
  8075. }
  8076. tsParseObjectTypeMembers() {
  8077. this.expect(5);
  8078. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8079. this.expect(8);
  8080. return members;
  8081. }
  8082. tsIsStartOfMappedType() {
  8083. this.next();
  8084. if (this.eat(53)) {
  8085. return this.isContextual(120);
  8086. }
  8087. if (this.isContextual(120)) {
  8088. this.next();
  8089. }
  8090. if (!this.match(0)) {
  8091. return false;
  8092. }
  8093. this.next();
  8094. if (!this.tsIsIdentifier()) {
  8095. return false;
  8096. }
  8097. this.next();
  8098. return this.match(58);
  8099. }
  8100. tsParseMappedTypeParameter() {
  8101. const node = this.startNode();
  8102. node.name = this.tsParseTypeParameterName();
  8103. node.constraint = this.tsExpectThenParseType(58);
  8104. return this.finishNode(node, "TSTypeParameter");
  8105. }
  8106. tsParseMappedType() {
  8107. const node = this.startNode();
  8108. this.expect(5);
  8109. if (this.match(53)) {
  8110. node.readonly = this.state.value;
  8111. this.next();
  8112. this.expectContextual(120);
  8113. } else if (this.eatContextual(120)) {
  8114. node.readonly = true;
  8115. }
  8116. this.expect(0);
  8117. node.typeParameter = this.tsParseMappedTypeParameter();
  8118. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8119. this.expect(3);
  8120. if (this.match(53)) {
  8121. node.optional = this.state.value;
  8122. this.next();
  8123. this.expect(17);
  8124. } else if (this.eat(17)) {
  8125. node.optional = true;
  8126. }
  8127. node.typeAnnotation = this.tsTryParseType();
  8128. this.semicolon();
  8129. this.expect(8);
  8130. return this.finishNode(node, "TSMappedType");
  8131. }
  8132. tsParseTupleType() {
  8133. const node = this.startNode();
  8134. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8135. let seenOptionalElement = false;
  8136. let labeledElements = null;
  8137. node.elementTypes.forEach(elementNode => {
  8138. var _labeledElements;
  8139. const {
  8140. type
  8141. } = elementNode;
  8142. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8143. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  8144. at: elementNode
  8145. });
  8146. }
  8147. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8148. let checkType = type;
  8149. if (type === "TSRestType") {
  8150. elementNode = elementNode.typeAnnotation;
  8151. checkType = elementNode.type;
  8152. }
  8153. const isLabeled = checkType === "TSNamedTupleMember";
  8154. (_labeledElements = labeledElements) != null ? _labeledElements : labeledElements = isLabeled;
  8155. if (labeledElements !== isLabeled) {
  8156. this.raise(TSErrors.MixedLabeledAndUnlabeledElements, {
  8157. at: elementNode
  8158. });
  8159. }
  8160. });
  8161. return this.finishNode(node, "TSTupleType");
  8162. }
  8163. tsParseTupleElementType() {
  8164. const {
  8165. startLoc
  8166. } = this.state;
  8167. const rest = this.eat(21);
  8168. let labeled;
  8169. let label;
  8170. let optional;
  8171. let type;
  8172. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8173. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8174. if (chAfterWord === 58) {
  8175. labeled = true;
  8176. optional = false;
  8177. label = this.parseIdentifier(true);
  8178. this.expect(14);
  8179. type = this.tsParseType();
  8180. } else if (chAfterWord === 63) {
  8181. optional = true;
  8182. const startLoc = this.state.startLoc;
  8183. const wordName = this.state.value;
  8184. const typeOrLabel = this.tsParseNonArrayType();
  8185. if (this.lookaheadCharCode() === 58) {
  8186. labeled = true;
  8187. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8188. this.expect(17);
  8189. this.expect(14);
  8190. type = this.tsParseType();
  8191. } else {
  8192. labeled = false;
  8193. type = typeOrLabel;
  8194. this.expect(17);
  8195. }
  8196. } else {
  8197. type = this.tsParseType();
  8198. optional = this.eat(17);
  8199. labeled = this.eat(14);
  8200. }
  8201. if (labeled) {
  8202. let labeledNode;
  8203. if (label) {
  8204. labeledNode = this.startNodeAtNode(label);
  8205. labeledNode.optional = optional;
  8206. labeledNode.label = label;
  8207. labeledNode.elementType = type;
  8208. if (this.eat(17)) {
  8209. labeledNode.optional = true;
  8210. this.raise(TSErrors.TupleOptionalAfterType, {
  8211. at: this.state.lastTokStartLoc
  8212. });
  8213. }
  8214. } else {
  8215. labeledNode = this.startNodeAtNode(type);
  8216. labeledNode.optional = optional;
  8217. this.raise(TSErrors.InvalidTupleMemberLabel, {
  8218. at: type
  8219. });
  8220. labeledNode.label = type;
  8221. labeledNode.elementType = this.tsParseType();
  8222. }
  8223. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8224. } else if (optional) {
  8225. const optionalTypeNode = this.startNodeAtNode(type);
  8226. optionalTypeNode.typeAnnotation = type;
  8227. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8228. }
  8229. if (rest) {
  8230. const restNode = this.startNodeAt(startLoc);
  8231. restNode.typeAnnotation = type;
  8232. type = this.finishNode(restNode, "TSRestType");
  8233. }
  8234. return type;
  8235. }
  8236. tsParseParenthesizedType() {
  8237. const node = this.startNode();
  8238. this.expect(10);
  8239. node.typeAnnotation = this.tsParseType();
  8240. this.expect(11);
  8241. return this.finishNode(node, "TSParenthesizedType");
  8242. }
  8243. tsParseFunctionOrConstructorType(type, abstract) {
  8244. const node = this.startNode();
  8245. if (type === "TSConstructorType") {
  8246. node.abstract = !!abstract;
  8247. if (abstract) this.next();
  8248. this.next();
  8249. }
  8250. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8251. return this.finishNode(node, type);
  8252. }
  8253. tsParseLiteralTypeNode() {
  8254. const node = this.startNode();
  8255. switch (this.state.type) {
  8256. case 132:
  8257. case 133:
  8258. case 131:
  8259. case 85:
  8260. case 86:
  8261. node.literal = super.parseExprAtom();
  8262. break;
  8263. default:
  8264. this.unexpected();
  8265. }
  8266. return this.finishNode(node, "TSLiteralType");
  8267. }
  8268. tsParseTemplateLiteralType() {
  8269. const node = this.startNode();
  8270. node.literal = super.parseTemplate(false);
  8271. return this.finishNode(node, "TSLiteralType");
  8272. }
  8273. parseTemplateSubstitution() {
  8274. if (this.state.inType) return this.tsParseType();
  8275. return super.parseTemplateSubstitution();
  8276. }
  8277. tsParseThisTypeOrThisTypePredicate() {
  8278. const thisKeyword = this.tsParseThisTypeNode();
  8279. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  8280. return this.tsParseThisTypePredicate(thisKeyword);
  8281. } else {
  8282. return thisKeyword;
  8283. }
  8284. }
  8285. tsParseNonArrayType() {
  8286. switch (this.state.type) {
  8287. case 131:
  8288. case 132:
  8289. case 133:
  8290. case 85:
  8291. case 86:
  8292. return this.tsParseLiteralTypeNode();
  8293. case 53:
  8294. if (this.state.value === "-") {
  8295. const node = this.startNode();
  8296. const nextToken = this.lookahead();
  8297. if (nextToken.type !== 132 && nextToken.type !== 133) {
  8298. this.unexpected();
  8299. }
  8300. node.literal = this.parseMaybeUnary();
  8301. return this.finishNode(node, "TSLiteralType");
  8302. }
  8303. break;
  8304. case 78:
  8305. return this.tsParseThisTypeOrThisTypePredicate();
  8306. case 87:
  8307. return this.tsParseTypeQuery();
  8308. case 83:
  8309. return this.tsParseImportType();
  8310. case 5:
  8311. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8312. case 0:
  8313. return this.tsParseTupleType();
  8314. case 10:
  8315. return this.tsParseParenthesizedType();
  8316. case 25:
  8317. case 24:
  8318. return this.tsParseTemplateLiteralType();
  8319. default:
  8320. {
  8321. const {
  8322. type
  8323. } = this.state;
  8324. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8325. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8326. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8327. const node = this.startNode();
  8328. this.next();
  8329. return this.finishNode(node, nodeType);
  8330. }
  8331. return this.tsParseTypeReference();
  8332. }
  8333. }
  8334. }
  8335. this.unexpected();
  8336. }
  8337. tsParseArrayTypeOrHigher() {
  8338. let type = this.tsParseNonArrayType();
  8339. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8340. if (this.match(3)) {
  8341. const node = this.startNodeAtNode(type);
  8342. node.elementType = type;
  8343. this.expect(3);
  8344. type = this.finishNode(node, "TSArrayType");
  8345. } else {
  8346. const node = this.startNodeAtNode(type);
  8347. node.objectType = type;
  8348. node.indexType = this.tsParseType();
  8349. this.expect(3);
  8350. type = this.finishNode(node, "TSIndexedAccessType");
  8351. }
  8352. }
  8353. return type;
  8354. }
  8355. tsParseTypeOperator() {
  8356. const node = this.startNode();
  8357. const operator = this.state.value;
  8358. this.next();
  8359. node.operator = operator;
  8360. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8361. if (operator === "readonly") {
  8362. this.tsCheckTypeAnnotationForReadOnly(node);
  8363. }
  8364. return this.finishNode(node, "TSTypeOperator");
  8365. }
  8366. tsCheckTypeAnnotationForReadOnly(node) {
  8367. switch (node.typeAnnotation.type) {
  8368. case "TSTupleType":
  8369. case "TSArrayType":
  8370. return;
  8371. default:
  8372. this.raise(TSErrors.UnexpectedReadonly, {
  8373. at: node
  8374. });
  8375. }
  8376. }
  8377. tsParseInferType() {
  8378. const node = this.startNode();
  8379. this.expectContextual(113);
  8380. const typeParameter = this.startNode();
  8381. typeParameter.name = this.tsParseTypeParameterName();
  8382. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8383. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8384. return this.finishNode(node, "TSInferType");
  8385. }
  8386. tsParseConstraintForInferType() {
  8387. if (this.eat(81)) {
  8388. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8389. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8390. return constraint;
  8391. }
  8392. }
  8393. }
  8394. tsParseTypeOperatorOrHigher() {
  8395. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8396. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(113) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8397. }
  8398. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8399. const node = this.startNode();
  8400. const hasLeadingOperator = this.eat(operator);
  8401. const types = [];
  8402. do {
  8403. types.push(parseConstituentType());
  8404. } while (this.eat(operator));
  8405. if (types.length === 1 && !hasLeadingOperator) {
  8406. return types[0];
  8407. }
  8408. node.types = types;
  8409. return this.finishNode(node, kind);
  8410. }
  8411. tsParseIntersectionTypeOrHigher() {
  8412. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8413. }
  8414. tsParseUnionTypeOrHigher() {
  8415. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8416. }
  8417. tsIsStartOfFunctionType() {
  8418. if (this.match(47)) {
  8419. return true;
  8420. }
  8421. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8422. }
  8423. tsSkipParameterStart() {
  8424. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8425. this.next();
  8426. return true;
  8427. }
  8428. if (this.match(5)) {
  8429. const {
  8430. errors
  8431. } = this.state;
  8432. const previousErrorCount = errors.length;
  8433. try {
  8434. this.parseObjectLike(8, true);
  8435. return errors.length === previousErrorCount;
  8436. } catch (_unused) {
  8437. return false;
  8438. }
  8439. }
  8440. if (this.match(0)) {
  8441. this.next();
  8442. const {
  8443. errors
  8444. } = this.state;
  8445. const previousErrorCount = errors.length;
  8446. try {
  8447. super.parseBindingList(3, 93, 1);
  8448. return errors.length === previousErrorCount;
  8449. } catch (_unused2) {
  8450. return false;
  8451. }
  8452. }
  8453. return false;
  8454. }
  8455. tsIsUnambiguouslyStartOfFunctionType() {
  8456. this.next();
  8457. if (this.match(11) || this.match(21)) {
  8458. return true;
  8459. }
  8460. if (this.tsSkipParameterStart()) {
  8461. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8462. return true;
  8463. }
  8464. if (this.match(11)) {
  8465. this.next();
  8466. if (this.match(19)) {
  8467. return true;
  8468. }
  8469. }
  8470. }
  8471. return false;
  8472. }
  8473. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8474. return this.tsInType(() => {
  8475. const t = this.startNode();
  8476. this.expect(returnToken);
  8477. const node = this.startNode();
  8478. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8479. if (asserts && this.match(78)) {
  8480. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8481. if (thisTypePredicate.type === "TSThisType") {
  8482. node.parameterName = thisTypePredicate;
  8483. node.asserts = true;
  8484. node.typeAnnotation = null;
  8485. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8486. } else {
  8487. this.resetStartLocationFromNode(thisTypePredicate, node);
  8488. thisTypePredicate.asserts = true;
  8489. }
  8490. t.typeAnnotation = thisTypePredicate;
  8491. return this.finishNode(t, "TSTypeAnnotation");
  8492. }
  8493. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8494. if (!typePredicateVariable) {
  8495. if (!asserts) {
  8496. return this.tsParseTypeAnnotation(false, t);
  8497. }
  8498. node.parameterName = this.parseIdentifier();
  8499. node.asserts = asserts;
  8500. node.typeAnnotation = null;
  8501. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8502. return this.finishNode(t, "TSTypeAnnotation");
  8503. }
  8504. const type = this.tsParseTypeAnnotation(false);
  8505. node.parameterName = typePredicateVariable;
  8506. node.typeAnnotation = type;
  8507. node.asserts = asserts;
  8508. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8509. return this.finishNode(t, "TSTypeAnnotation");
  8510. });
  8511. }
  8512. tsTryParseTypeOrTypePredicateAnnotation() {
  8513. if (this.match(14)) {
  8514. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8515. }
  8516. }
  8517. tsTryParseTypeAnnotation() {
  8518. if (this.match(14)) {
  8519. return this.tsParseTypeAnnotation();
  8520. }
  8521. }
  8522. tsTryParseType() {
  8523. return this.tsEatThenParseType(14);
  8524. }
  8525. tsParseTypePredicatePrefix() {
  8526. const id = this.parseIdentifier();
  8527. if (this.isContextual(114) && !this.hasPrecedingLineBreak()) {
  8528. this.next();
  8529. return id;
  8530. }
  8531. }
  8532. tsParseTypePredicateAsserts() {
  8533. if (this.state.type !== 107) {
  8534. return false;
  8535. }
  8536. const containsEsc = this.state.containsEsc;
  8537. this.next();
  8538. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8539. return false;
  8540. }
  8541. if (containsEsc) {
  8542. this.raise(Errors.InvalidEscapedReservedWord, {
  8543. at: this.state.lastTokStartLoc,
  8544. reservedWord: "asserts"
  8545. });
  8546. }
  8547. return true;
  8548. }
  8549. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8550. this.tsInType(() => {
  8551. if (eatColon) this.expect(14);
  8552. t.typeAnnotation = this.tsParseType();
  8553. });
  8554. return this.finishNode(t, "TSTypeAnnotation");
  8555. }
  8556. tsParseType() {
  8557. assert(this.state.inType);
  8558. const type = this.tsParseNonConditionalType();
  8559. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8560. return type;
  8561. }
  8562. const node = this.startNodeAtNode(type);
  8563. node.checkType = type;
  8564. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8565. this.expect(17);
  8566. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8567. this.expect(14);
  8568. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8569. return this.finishNode(node, "TSConditionalType");
  8570. }
  8571. isAbstractConstructorSignature() {
  8572. return this.isContextual(122) && this.lookahead().type === 77;
  8573. }
  8574. tsParseNonConditionalType() {
  8575. if (this.tsIsStartOfFunctionType()) {
  8576. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8577. }
  8578. if (this.match(77)) {
  8579. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8580. } else if (this.isAbstractConstructorSignature()) {
  8581. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8582. }
  8583. return this.tsParseUnionTypeOrHigher();
  8584. }
  8585. tsParseTypeAssertion() {
  8586. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8587. this.raise(TSErrors.ReservedTypeAssertion, {
  8588. at: this.state.startLoc
  8589. });
  8590. }
  8591. const node = this.startNode();
  8592. node.typeAnnotation = this.tsInType(() => {
  8593. this.next();
  8594. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8595. });
  8596. this.expect(48);
  8597. node.expression = this.parseMaybeUnary();
  8598. return this.finishNode(node, "TSTypeAssertion");
  8599. }
  8600. tsParseHeritageClause(token) {
  8601. const originalStartLoc = this.state.startLoc;
  8602. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8603. const node = this.startNode();
  8604. node.expression = this.tsParseEntityName();
  8605. if (this.match(47)) {
  8606. node.typeParameters = this.tsParseTypeArguments();
  8607. }
  8608. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8609. });
  8610. if (!delimitedList.length) {
  8611. this.raise(TSErrors.EmptyHeritageClauseType, {
  8612. at: originalStartLoc,
  8613. token
  8614. });
  8615. }
  8616. return delimitedList;
  8617. }
  8618. tsParseInterfaceDeclaration(node, properties = {}) {
  8619. if (this.hasFollowingLineBreak()) return null;
  8620. this.expectContextual(127);
  8621. if (properties.declare) node.declare = true;
  8622. if (tokenIsIdentifier(this.state.type)) {
  8623. node.id = this.parseIdentifier();
  8624. this.checkIdentifier(node.id, 130);
  8625. } else {
  8626. node.id = null;
  8627. this.raise(TSErrors.MissingInterfaceName, {
  8628. at: this.state.startLoc
  8629. });
  8630. }
  8631. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8632. if (this.eat(81)) {
  8633. node.extends = this.tsParseHeritageClause("extends");
  8634. }
  8635. const body = this.startNode();
  8636. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8637. node.body = this.finishNode(body, "TSInterfaceBody");
  8638. return this.finishNode(node, "TSInterfaceDeclaration");
  8639. }
  8640. tsParseTypeAliasDeclaration(node) {
  8641. node.id = this.parseIdentifier();
  8642. this.checkIdentifier(node.id, 2);
  8643. node.typeAnnotation = this.tsInType(() => {
  8644. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8645. this.expect(29);
  8646. if (this.isContextual(112) && this.lookahead().type !== 16) {
  8647. const node = this.startNode();
  8648. this.next();
  8649. return this.finishNode(node, "TSIntrinsicKeyword");
  8650. }
  8651. return this.tsParseType();
  8652. });
  8653. this.semicolon();
  8654. return this.finishNode(node, "TSTypeAliasDeclaration");
  8655. }
  8656. tsInNoContext(cb) {
  8657. const oldContext = this.state.context;
  8658. this.state.context = [oldContext[0]];
  8659. try {
  8660. return cb();
  8661. } finally {
  8662. this.state.context = oldContext;
  8663. }
  8664. }
  8665. tsInType(cb) {
  8666. const oldInType = this.state.inType;
  8667. this.state.inType = true;
  8668. try {
  8669. return cb();
  8670. } finally {
  8671. this.state.inType = oldInType;
  8672. }
  8673. }
  8674. tsInDisallowConditionalTypesContext(cb) {
  8675. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8676. this.state.inDisallowConditionalTypesContext = true;
  8677. try {
  8678. return cb();
  8679. } finally {
  8680. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8681. }
  8682. }
  8683. tsInAllowConditionalTypesContext(cb) {
  8684. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8685. this.state.inDisallowConditionalTypesContext = false;
  8686. try {
  8687. return cb();
  8688. } finally {
  8689. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8690. }
  8691. }
  8692. tsEatThenParseType(token) {
  8693. if (this.match(token)) {
  8694. return this.tsNextThenParseType();
  8695. }
  8696. }
  8697. tsExpectThenParseType(token) {
  8698. return this.tsInType(() => {
  8699. this.expect(token);
  8700. return this.tsParseType();
  8701. });
  8702. }
  8703. tsNextThenParseType() {
  8704. return this.tsInType(() => {
  8705. this.next();
  8706. return this.tsParseType();
  8707. });
  8708. }
  8709. tsParseEnumMember() {
  8710. const node = this.startNode();
  8711. node.id = this.match(131) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8712. if (this.eat(29)) {
  8713. node.initializer = super.parseMaybeAssignAllowIn();
  8714. }
  8715. return this.finishNode(node, "TSEnumMember");
  8716. }
  8717. tsParseEnumDeclaration(node, properties = {}) {
  8718. if (properties.const) node.const = true;
  8719. if (properties.declare) node.declare = true;
  8720. this.expectContextual(124);
  8721. node.id = this.parseIdentifier();
  8722. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8723. this.expect(5);
  8724. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8725. this.expect(8);
  8726. return this.finishNode(node, "TSEnumDeclaration");
  8727. }
  8728. tsParseModuleBlock() {
  8729. const node = this.startNode();
  8730. this.scope.enter(0);
  8731. this.expect(5);
  8732. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8733. this.scope.exit();
  8734. return this.finishNode(node, "TSModuleBlock");
  8735. }
  8736. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8737. node.id = this.parseIdentifier();
  8738. if (!nested) {
  8739. this.checkIdentifier(node.id, 1024);
  8740. }
  8741. if (this.eat(16)) {
  8742. const inner = this.startNode();
  8743. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8744. node.body = inner;
  8745. } else {
  8746. this.scope.enter(256);
  8747. this.prodParam.enter(PARAM);
  8748. node.body = this.tsParseModuleBlock();
  8749. this.prodParam.exit();
  8750. this.scope.exit();
  8751. }
  8752. return this.finishNode(node, "TSModuleDeclaration");
  8753. }
  8754. tsParseAmbientExternalModuleDeclaration(node) {
  8755. if (this.isContextual(110)) {
  8756. node.global = true;
  8757. node.id = this.parseIdentifier();
  8758. } else if (this.match(131)) {
  8759. node.id = super.parseStringLiteral(this.state.value);
  8760. } else {
  8761. this.unexpected();
  8762. }
  8763. if (this.match(5)) {
  8764. this.scope.enter(256);
  8765. this.prodParam.enter(PARAM);
  8766. node.body = this.tsParseModuleBlock();
  8767. this.prodParam.exit();
  8768. this.scope.exit();
  8769. } else {
  8770. this.semicolon();
  8771. }
  8772. return this.finishNode(node, "TSModuleDeclaration");
  8773. }
  8774. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8775. node.isExport = isExport || false;
  8776. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8777. this.checkIdentifier(node.id, 4096);
  8778. this.expect(29);
  8779. const moduleReference = this.tsParseModuleReference();
  8780. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8781. this.raise(TSErrors.ImportAliasHasImportType, {
  8782. at: moduleReference
  8783. });
  8784. }
  8785. node.moduleReference = moduleReference;
  8786. this.semicolon();
  8787. return this.finishNode(node, "TSImportEqualsDeclaration");
  8788. }
  8789. tsIsExternalModuleReference() {
  8790. return this.isContextual(117) && 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(117);
  8798. this.expect(10);
  8799. if (!this.match(131)) {
  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(99)) {
  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 124:
  8846. return this.tsParseEnumDeclaration(nany, {
  8847. declare: true
  8848. });
  8849. case 110:
  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 127:
  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(PARAM);
  8893. const mod = node;
  8894. mod.global = true;
  8895. mod.id = expr;
  8896. mod.body = this.tsParseModuleBlock();
  8897. this.scope.exit();
  8898. this.prodParam.exit();
  8899. return this.finishNode(mod, "TSModuleDeclaration");
  8900. }
  8901. break;
  8902. default:
  8903. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8904. }
  8905. }
  8906. tsParseDeclaration(node, value, next, decorators) {
  8907. switch (value) {
  8908. case "abstract":
  8909. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8910. return this.tsParseAbstractDeclaration(node, decorators);
  8911. }
  8912. break;
  8913. case "module":
  8914. if (this.tsCheckLineTerminator(next)) {
  8915. if (this.match(131)) {
  8916. return this.tsParseAmbientExternalModuleDeclaration(node);
  8917. } else if (tokenIsIdentifier(this.state.type)) {
  8918. return this.tsParseModuleOrNamespaceDeclaration(node);
  8919. }
  8920. }
  8921. break;
  8922. case "namespace":
  8923. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8924. return this.tsParseModuleOrNamespaceDeclaration(node);
  8925. }
  8926. break;
  8927. case "type":
  8928. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8929. return this.tsParseTypeAliasDeclaration(node);
  8930. }
  8931. break;
  8932. }
  8933. }
  8934. tsCheckLineTerminator(next) {
  8935. if (next) {
  8936. if (this.hasFollowingLineBreak()) return false;
  8937. this.next();
  8938. return true;
  8939. }
  8940. return !this.isLineTerminator();
  8941. }
  8942. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8943. if (!this.match(47)) return;
  8944. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8945. this.state.maybeInArrowParameters = true;
  8946. const res = this.tsTryParseAndCatch(() => {
  8947. const node = this.startNodeAt(startLoc);
  8948. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  8949. super.parseFunctionParams(node);
  8950. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8951. this.expect(19);
  8952. return node;
  8953. });
  8954. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8955. if (!res) return;
  8956. return super.parseArrowExpression(res, null, true);
  8957. }
  8958. tsParseTypeArgumentsInExpression() {
  8959. if (this.reScan_lt() !== 47) return;
  8960. return this.tsParseTypeArguments();
  8961. }
  8962. tsParseTypeArguments() {
  8963. const node = this.startNode();
  8964. node.params = this.tsInType(() => this.tsInNoContext(() => {
  8965. this.expect(47);
  8966. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8967. }));
  8968. if (node.params.length === 0) {
  8969. this.raise(TSErrors.EmptyTypeArguments, {
  8970. at: node
  8971. });
  8972. } else if (!this.state.inType && this.curContext() === types.brace) {
  8973. this.reScan_lt_gt();
  8974. }
  8975. this.expect(48);
  8976. return this.finishNode(node, "TSTypeParameterInstantiation");
  8977. }
  8978. tsIsDeclarationStart() {
  8979. return tokenIsTSDeclarationStart(this.state.type);
  8980. }
  8981. isExportDefaultSpecifier() {
  8982. if (this.tsIsDeclarationStart()) return false;
  8983. return super.isExportDefaultSpecifier();
  8984. }
  8985. parseAssignableListItem(flags, decorators) {
  8986. const startLoc = this.state.startLoc;
  8987. const modified = {};
  8988. this.tsParseModifiers({
  8989. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  8990. }, modified);
  8991. const accessibility = modified.accessibility;
  8992. const override = modified.override;
  8993. const readonly = modified.readonly;
  8994. if (!(flags & 4) && (accessibility || readonly || override)) {
  8995. this.raise(TSErrors.UnexpectedParameterModifier, {
  8996. at: startLoc
  8997. });
  8998. }
  8999. const left = this.parseMaybeDefault();
  9000. this.parseAssignableListItemTypes(left, flags);
  9001. const elt = this.parseMaybeDefault(left.loc.start, left);
  9002. if (accessibility || readonly || override) {
  9003. const pp = this.startNodeAt(startLoc);
  9004. if (decorators.length) {
  9005. pp.decorators = decorators;
  9006. }
  9007. if (accessibility) pp.accessibility = accessibility;
  9008. if (readonly) pp.readonly = readonly;
  9009. if (override) pp.override = override;
  9010. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9011. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  9012. at: pp
  9013. });
  9014. }
  9015. pp.parameter = elt;
  9016. return this.finishNode(pp, "TSParameterProperty");
  9017. }
  9018. if (decorators.length) {
  9019. left.decorators = decorators;
  9020. }
  9021. return elt;
  9022. }
  9023. isSimpleParameter(node) {
  9024. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9025. }
  9026. tsDisallowOptionalPattern(node) {
  9027. for (const param of node.params) {
  9028. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9029. this.raise(TSErrors.PatternIsOptional, {
  9030. at: param
  9031. });
  9032. }
  9033. }
  9034. }
  9035. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9036. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9037. this.tsDisallowOptionalPattern(node);
  9038. }
  9039. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9040. if (this.match(14)) {
  9041. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9042. }
  9043. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9044. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9045. return this.finishNode(node, bodilessType);
  9046. }
  9047. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9048. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  9049. at: node
  9050. });
  9051. if (node.declare) {
  9052. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9053. }
  9054. }
  9055. this.tsDisallowOptionalPattern(node);
  9056. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9057. }
  9058. registerFunctionStatementId(node) {
  9059. if (!node.body && node.id) {
  9060. this.checkIdentifier(node.id, 1024);
  9061. } else {
  9062. super.registerFunctionStatementId(node);
  9063. }
  9064. }
  9065. tsCheckForInvalidTypeCasts(items) {
  9066. items.forEach(node => {
  9067. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9068. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  9069. at: node.typeAnnotation
  9070. });
  9071. }
  9072. });
  9073. }
  9074. toReferencedList(exprList, isInParens) {
  9075. this.tsCheckForInvalidTypeCasts(exprList);
  9076. return exprList;
  9077. }
  9078. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9079. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9080. if (node.type === "ArrayExpression") {
  9081. this.tsCheckForInvalidTypeCasts(node.elements);
  9082. }
  9083. return node;
  9084. }
  9085. parseSubscript(base, startLoc, noCalls, state) {
  9086. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9087. this.state.canStartJSXElement = false;
  9088. this.next();
  9089. const nonNullExpression = this.startNodeAt(startLoc);
  9090. nonNullExpression.expression = base;
  9091. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9092. }
  9093. let isOptionalCall = false;
  9094. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9095. if (noCalls) {
  9096. state.stop = true;
  9097. return base;
  9098. }
  9099. state.optionalChainMember = isOptionalCall = true;
  9100. this.next();
  9101. }
  9102. if (this.match(47) || this.match(51)) {
  9103. let missingParenErrorLoc;
  9104. const result = this.tsTryParseAndCatch(() => {
  9105. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9106. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9107. if (asyncArrowFn) {
  9108. return asyncArrowFn;
  9109. }
  9110. }
  9111. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9112. if (!typeArguments) return;
  9113. if (isOptionalCall && !this.match(10)) {
  9114. missingParenErrorLoc = this.state.curPosition();
  9115. return;
  9116. }
  9117. if (tokenIsTemplate(this.state.type)) {
  9118. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9119. result.typeParameters = typeArguments;
  9120. return result;
  9121. }
  9122. if (!noCalls && this.eat(10)) {
  9123. const node = this.startNodeAt(startLoc);
  9124. node.callee = base;
  9125. node.arguments = this.parseCallExpressionArguments(11, false);
  9126. this.tsCheckForInvalidTypeCasts(node.arguments);
  9127. node.typeParameters = typeArguments;
  9128. if (state.optionalChainMember) {
  9129. node.optional = isOptionalCall;
  9130. }
  9131. return this.finishCallExpression(node, state.optionalChainMember);
  9132. }
  9133. const tokenType = this.state.type;
  9134. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9135. return;
  9136. }
  9137. const node = this.startNodeAt(startLoc);
  9138. node.expression = base;
  9139. node.typeParameters = typeArguments;
  9140. return this.finishNode(node, "TSInstantiationExpression");
  9141. });
  9142. if (missingParenErrorLoc) {
  9143. this.unexpected(missingParenErrorLoc, 10);
  9144. }
  9145. if (result) {
  9146. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9147. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  9148. at: this.state.startLoc
  9149. });
  9150. }
  9151. return result;
  9152. }
  9153. }
  9154. return super.parseSubscript(base, startLoc, noCalls, state);
  9155. }
  9156. parseNewCallee(node) {
  9157. var _callee$extra;
  9158. super.parseNewCallee(node);
  9159. const {
  9160. callee
  9161. } = node;
  9162. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9163. node.typeParameters = callee.typeParameters;
  9164. node.callee = callee.expression;
  9165. }
  9166. }
  9167. parseExprOp(left, leftStartLoc, minPrec) {
  9168. let isSatisfies;
  9169. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(118)))) {
  9170. const node = this.startNodeAt(leftStartLoc);
  9171. node.expression = left;
  9172. node.typeAnnotation = this.tsInType(() => {
  9173. this.next();
  9174. if (this.match(75)) {
  9175. if (isSatisfies) {
  9176. this.raise(Errors.UnexpectedKeyword, {
  9177. at: 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, {
  9200. at: node.specifiers[0].loc.start
  9201. });
  9202. }
  9203. }
  9204. checkDuplicateExports() {}
  9205. isPotentialImportPhase(isExport) {
  9206. if (super.isPotentialImportPhase(isExport)) return true;
  9207. if (this.isContextual(128)) {
  9208. const ch = this.lookaheadCharCode();
  9209. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9210. }
  9211. return !isExport && this.isContextual(87);
  9212. }
  9213. applyImportPhase(node, isExport, phase, loc) {
  9214. super.applyImportPhase(node, isExport, phase, loc);
  9215. if (isExport) {
  9216. node.exportKind = phase === "type" ? "type" : "value";
  9217. } else {
  9218. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9219. }
  9220. }
  9221. parseImport(node) {
  9222. if (this.match(131)) {
  9223. node.importKind = "value";
  9224. return super.parseImport(node);
  9225. }
  9226. let importNode;
  9227. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9228. node.importKind = "value";
  9229. return this.tsParseImportEqualsDeclaration(node);
  9230. } else if (this.isContextual(128)) {
  9231. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9232. if (this.lookaheadCharCode() === 61) {
  9233. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9234. } else {
  9235. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9236. }
  9237. } else {
  9238. importNode = super.parseImport(node);
  9239. }
  9240. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9241. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  9242. at: importNode
  9243. });
  9244. }
  9245. return importNode;
  9246. }
  9247. parseExport(node, decorators) {
  9248. if (this.match(83)) {
  9249. this.next();
  9250. let maybeDefaultIdentifier = null;
  9251. if (this.isContextual(128) && this.isPotentialImportPhase(false)) {
  9252. maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9253. } else {
  9254. node.importKind = "value";
  9255. }
  9256. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true);
  9257. } else if (this.eat(29)) {
  9258. const assign = node;
  9259. assign.expression = super.parseExpression();
  9260. this.semicolon();
  9261. this.sawUnambiguousESM = true;
  9262. return this.finishNode(assign, "TSExportAssignment");
  9263. } else if (this.eatContextual(93)) {
  9264. const decl = node;
  9265. this.expectContextual(126);
  9266. decl.id = this.parseIdentifier();
  9267. this.semicolon();
  9268. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9269. } else {
  9270. return super.parseExport(node, decorators);
  9271. }
  9272. }
  9273. isAbstractClass() {
  9274. return this.isContextual(122) && this.lookahead().type === 80;
  9275. }
  9276. parseExportDefaultExpression() {
  9277. if (this.isAbstractClass()) {
  9278. const cls = this.startNode();
  9279. this.next();
  9280. cls.abstract = true;
  9281. return this.parseClass(cls, true, true);
  9282. }
  9283. if (this.match(127)) {
  9284. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9285. if (result) return result;
  9286. }
  9287. return super.parseExportDefaultExpression();
  9288. }
  9289. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9290. const {
  9291. isAmbientContext
  9292. } = this.state;
  9293. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9294. if (!isAmbientContext) return declaration;
  9295. for (const {
  9296. id,
  9297. init
  9298. } of declaration.declarations) {
  9299. if (!init) continue;
  9300. if (kind !== "const" || !!id.typeAnnotation) {
  9301. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  9302. at: init
  9303. });
  9304. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9305. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  9306. at: init
  9307. });
  9308. }
  9309. }
  9310. return declaration;
  9311. }
  9312. parseStatementContent(flags, decorators) {
  9313. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9314. const node = this.startNode();
  9315. this.expect(75);
  9316. return this.tsParseEnumDeclaration(node, {
  9317. const: true
  9318. });
  9319. }
  9320. if (this.isContextual(124)) {
  9321. return this.tsParseEnumDeclaration(this.startNode());
  9322. }
  9323. if (this.isContextual(127)) {
  9324. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9325. if (result) return result;
  9326. }
  9327. return super.parseStatementContent(flags, decorators);
  9328. }
  9329. parseAccessModifier() {
  9330. return this.tsParseModifier(["public", "protected", "private"]);
  9331. }
  9332. tsHasSomeModifiers(member, modifiers) {
  9333. return modifiers.some(modifier => {
  9334. if (tsIsAccessModifier(modifier)) {
  9335. return member.accessibility === modifier;
  9336. }
  9337. return !!member[modifier];
  9338. });
  9339. }
  9340. tsIsStartOfStaticBlocks() {
  9341. return this.isContextual(104) && this.lookaheadCharCode() === 123;
  9342. }
  9343. parseClassMember(classBody, member, state) {
  9344. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9345. this.tsParseModifiers({
  9346. allowedModifiers: modifiers,
  9347. disallowedModifiers: ["in", "out"],
  9348. stopOnStartOfClassStaticBlock: true,
  9349. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9350. }, member);
  9351. const callParseClassMemberWithIsStatic = () => {
  9352. if (this.tsIsStartOfStaticBlocks()) {
  9353. this.next();
  9354. this.next();
  9355. if (this.tsHasSomeModifiers(member, modifiers)) {
  9356. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  9357. at: this.state.curPosition()
  9358. });
  9359. }
  9360. super.parseClassStaticBlock(classBody, member);
  9361. } else {
  9362. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9363. }
  9364. };
  9365. if (member.declare) {
  9366. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9367. } else {
  9368. callParseClassMemberWithIsStatic();
  9369. }
  9370. }
  9371. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9372. const idx = this.tsTryParseIndexSignature(member);
  9373. if (idx) {
  9374. classBody.body.push(idx);
  9375. if (member.abstract) {
  9376. this.raise(TSErrors.IndexSignatureHasAbstract, {
  9377. at: member
  9378. });
  9379. }
  9380. if (member.accessibility) {
  9381. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  9382. at: member,
  9383. modifier: member.accessibility
  9384. });
  9385. }
  9386. if (member.declare) {
  9387. this.raise(TSErrors.IndexSignatureHasDeclare, {
  9388. at: member
  9389. });
  9390. }
  9391. if (member.override) {
  9392. this.raise(TSErrors.IndexSignatureHasOverride, {
  9393. at: member
  9394. });
  9395. }
  9396. return;
  9397. }
  9398. if (!this.state.inAbstractClass && member.abstract) {
  9399. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  9400. at: member
  9401. });
  9402. }
  9403. if (member.override) {
  9404. if (!state.hadSuperClass) {
  9405. this.raise(TSErrors.OverrideNotInSubClass, {
  9406. at: member
  9407. });
  9408. }
  9409. }
  9410. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9411. }
  9412. parsePostMemberNameModifiers(methodOrProp) {
  9413. const optional = this.eat(17);
  9414. if (optional) methodOrProp.optional = true;
  9415. if (methodOrProp.readonly && this.match(10)) {
  9416. this.raise(TSErrors.ClassMethodHasReadonly, {
  9417. at: methodOrProp
  9418. });
  9419. }
  9420. if (methodOrProp.declare && this.match(10)) {
  9421. this.raise(TSErrors.ClassMethodHasDeclare, {
  9422. at: methodOrProp
  9423. });
  9424. }
  9425. }
  9426. parseExpressionStatement(node, expr, decorators) {
  9427. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9428. return decl || super.parseExpressionStatement(node, expr, decorators);
  9429. }
  9430. shouldParseExportDeclaration() {
  9431. if (this.tsIsDeclarationStart()) return true;
  9432. return super.shouldParseExportDeclaration();
  9433. }
  9434. parseConditional(expr, startLoc, refExpressionErrors) {
  9435. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9436. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9437. }
  9438. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9439. if (!result.node) {
  9440. if (result.error) {
  9441. super.setOptionalParametersError(refExpressionErrors, result.error);
  9442. }
  9443. return expr;
  9444. }
  9445. if (result.error) this.state = result.failState;
  9446. return result.node;
  9447. }
  9448. parseParenItem(node, startLoc) {
  9449. node = super.parseParenItem(node, startLoc);
  9450. if (this.eat(17)) {
  9451. node.optional = true;
  9452. this.resetEndLocation(node);
  9453. }
  9454. if (this.match(14)) {
  9455. const typeCastNode = this.startNodeAt(startLoc);
  9456. typeCastNode.expression = node;
  9457. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9458. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9459. }
  9460. return node;
  9461. }
  9462. parseExportDeclaration(node) {
  9463. if (!this.state.isAmbientContext && this.isContextual(123)) {
  9464. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9465. }
  9466. const startLoc = this.state.startLoc;
  9467. const isDeclare = this.eatContextual(123);
  9468. if (isDeclare && (this.isContextual(123) || !this.shouldParseExportDeclaration())) {
  9469. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  9470. at: this.state.startLoc
  9471. });
  9472. }
  9473. const isIdentifier = tokenIsIdentifier(this.state.type);
  9474. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9475. if (!declaration) return null;
  9476. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9477. node.exportKind = "type";
  9478. }
  9479. if (isDeclare) {
  9480. this.resetStartLocation(declaration, startLoc);
  9481. declaration.declare = true;
  9482. }
  9483. return declaration;
  9484. }
  9485. parseClassId(node, isStatement, optionalId, bindingType) {
  9486. if ((!isStatement || optionalId) && this.isContextual(111)) {
  9487. return;
  9488. }
  9489. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9490. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9491. if (typeParameters) node.typeParameters = typeParameters;
  9492. }
  9493. parseClassPropertyAnnotation(node) {
  9494. if (!node.optional) {
  9495. if (this.eat(35)) {
  9496. node.definite = true;
  9497. } else if (this.eat(17)) {
  9498. node.optional = true;
  9499. }
  9500. }
  9501. const type = this.tsTryParseTypeAnnotation();
  9502. if (type) node.typeAnnotation = type;
  9503. }
  9504. parseClassProperty(node) {
  9505. this.parseClassPropertyAnnotation(node);
  9506. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9507. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  9508. at: this.state.startLoc
  9509. });
  9510. }
  9511. if (node.abstract && this.match(29)) {
  9512. const {
  9513. key
  9514. } = node;
  9515. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  9516. at: this.state.startLoc,
  9517. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9518. });
  9519. }
  9520. return super.parseClassProperty(node);
  9521. }
  9522. parseClassPrivateProperty(node) {
  9523. if (node.abstract) {
  9524. this.raise(TSErrors.PrivateElementHasAbstract, {
  9525. at: node
  9526. });
  9527. }
  9528. if (node.accessibility) {
  9529. this.raise(TSErrors.PrivateElementHasAccessibility, {
  9530. at: node,
  9531. modifier: node.accessibility
  9532. });
  9533. }
  9534. this.parseClassPropertyAnnotation(node);
  9535. return super.parseClassPrivateProperty(node);
  9536. }
  9537. parseClassAccessorProperty(node) {
  9538. this.parseClassPropertyAnnotation(node);
  9539. if (node.optional) {
  9540. this.raise(TSErrors.AccessorCannotBeOptional, {
  9541. at: node
  9542. });
  9543. }
  9544. return super.parseClassAccessorProperty(node);
  9545. }
  9546. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9547. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9548. if (typeParameters && isConstructor) {
  9549. this.raise(TSErrors.ConstructorHasTypeParameters, {
  9550. at: typeParameters
  9551. });
  9552. }
  9553. const {
  9554. declare = false,
  9555. kind
  9556. } = method;
  9557. if (declare && (kind === "get" || kind === "set")) {
  9558. this.raise(TSErrors.DeclareAccessor, {
  9559. at: method,
  9560. kind
  9561. });
  9562. }
  9563. if (typeParameters) method.typeParameters = typeParameters;
  9564. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9565. }
  9566. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9567. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9568. if (typeParameters) method.typeParameters = typeParameters;
  9569. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9570. }
  9571. declareClassPrivateMethodInScope(node, kind) {
  9572. if (node.type === "TSDeclareMethod") return;
  9573. if (node.type === "MethodDefinition" && !node.value.body) return;
  9574. super.declareClassPrivateMethodInScope(node, kind);
  9575. }
  9576. parseClassSuper(node) {
  9577. super.parseClassSuper(node);
  9578. if (node.superClass && (this.match(47) || this.match(51))) {
  9579. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9580. }
  9581. if (this.eatContextual(111)) {
  9582. node.implements = this.tsParseHeritageClause("implements");
  9583. }
  9584. }
  9585. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9586. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9587. if (typeParameters) prop.typeParameters = typeParameters;
  9588. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9589. }
  9590. parseFunctionParams(node, isConstructor) {
  9591. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9592. if (typeParameters) node.typeParameters = typeParameters;
  9593. super.parseFunctionParams(node, isConstructor);
  9594. }
  9595. parseVarId(decl, kind) {
  9596. super.parseVarId(decl, kind);
  9597. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9598. decl.definite = true;
  9599. }
  9600. const type = this.tsTryParseTypeAnnotation();
  9601. if (type) {
  9602. decl.id.typeAnnotation = type;
  9603. this.resetEndLocation(decl.id);
  9604. }
  9605. }
  9606. parseAsyncArrowFromCallExpression(node, call) {
  9607. if (this.match(14)) {
  9608. node.returnType = this.tsParseTypeAnnotation();
  9609. }
  9610. return super.parseAsyncArrowFromCallExpression(node, call);
  9611. }
  9612. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9613. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9614. let state;
  9615. let jsx;
  9616. let typeCast;
  9617. if (this.hasPlugin("jsx") && (this.match(140) || this.match(47))) {
  9618. state = this.state.clone();
  9619. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9620. if (!jsx.error) return jsx.node;
  9621. const {
  9622. context
  9623. } = this.state;
  9624. const currentContext = context[context.length - 1];
  9625. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9626. context.pop();
  9627. }
  9628. }
  9629. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9630. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9631. }
  9632. if (!state || state === this.state) state = this.state.clone();
  9633. let typeParameters;
  9634. const arrow = this.tryParse(abort => {
  9635. var _expr$extra, _typeParameters;
  9636. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9637. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9638. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9639. abort();
  9640. }
  9641. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9642. this.resetStartLocationFromNode(expr, typeParameters);
  9643. }
  9644. expr.typeParameters = typeParameters;
  9645. return expr;
  9646. }, state);
  9647. if (!arrow.error && !arrow.aborted) {
  9648. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9649. return arrow.node;
  9650. }
  9651. if (!jsx) {
  9652. assert(!this.hasPlugin("jsx"));
  9653. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9654. if (!typeCast.error) return typeCast.node;
  9655. }
  9656. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9657. this.state = jsx.failState;
  9658. return jsx.node;
  9659. }
  9660. if (arrow.node) {
  9661. this.state = arrow.failState;
  9662. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9663. return arrow.node;
  9664. }
  9665. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9666. this.state = typeCast.failState;
  9667. return typeCast.node;
  9668. }
  9669. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9670. }
  9671. reportReservedArrowTypeParam(node) {
  9672. var _node$extra;
  9673. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9674. this.raise(TSErrors.ReservedArrowTypeParam, {
  9675. at: node
  9676. });
  9677. }
  9678. }
  9679. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9680. if (!this.hasPlugin("jsx") && this.match(47)) {
  9681. return this.tsParseTypeAssertion();
  9682. }
  9683. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9684. }
  9685. parseArrow(node) {
  9686. if (this.match(14)) {
  9687. const result = this.tryParse(abort => {
  9688. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9689. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9690. return returnType;
  9691. });
  9692. if (result.aborted) return;
  9693. if (!result.thrown) {
  9694. if (result.error) this.state = result.failState;
  9695. node.returnType = result.node;
  9696. }
  9697. }
  9698. return super.parseArrow(node);
  9699. }
  9700. parseAssignableListItemTypes(param, flags) {
  9701. if (!(flags & 2)) return param;
  9702. if (this.eat(17)) {
  9703. param.optional = true;
  9704. }
  9705. const type = this.tsTryParseTypeAnnotation();
  9706. if (type) param.typeAnnotation = type;
  9707. this.resetEndLocation(param);
  9708. return param;
  9709. }
  9710. isAssignable(node, isBinding) {
  9711. switch (node.type) {
  9712. case "TSTypeCastExpression":
  9713. return this.isAssignable(node.expression, isBinding);
  9714. case "TSParameterProperty":
  9715. return true;
  9716. default:
  9717. return super.isAssignable(node, isBinding);
  9718. }
  9719. }
  9720. toAssignable(node, isLHS = false) {
  9721. switch (node.type) {
  9722. case "ParenthesizedExpression":
  9723. this.toAssignableParenthesizedExpression(node, isLHS);
  9724. break;
  9725. case "TSAsExpression":
  9726. case "TSSatisfiesExpression":
  9727. case "TSNonNullExpression":
  9728. case "TSTypeAssertion":
  9729. if (isLHS) {
  9730. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  9731. at: node
  9732. });
  9733. } else {
  9734. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  9735. at: node
  9736. });
  9737. }
  9738. this.toAssignable(node.expression, isLHS);
  9739. break;
  9740. case "AssignmentExpression":
  9741. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9742. node.left = this.typeCastToParameter(node.left);
  9743. }
  9744. default:
  9745. super.toAssignable(node, isLHS);
  9746. }
  9747. }
  9748. toAssignableParenthesizedExpression(node, isLHS) {
  9749. switch (node.expression.type) {
  9750. case "TSAsExpression":
  9751. case "TSSatisfiesExpression":
  9752. case "TSNonNullExpression":
  9753. case "TSTypeAssertion":
  9754. case "ParenthesizedExpression":
  9755. this.toAssignable(node.expression, isLHS);
  9756. break;
  9757. default:
  9758. super.toAssignable(node, isLHS);
  9759. }
  9760. }
  9761. checkToRestConversion(node, allowPattern) {
  9762. switch (node.type) {
  9763. case "TSAsExpression":
  9764. case "TSSatisfiesExpression":
  9765. case "TSTypeAssertion":
  9766. case "TSNonNullExpression":
  9767. this.checkToRestConversion(node.expression, false);
  9768. break;
  9769. default:
  9770. super.checkToRestConversion(node, allowPattern);
  9771. }
  9772. }
  9773. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9774. return getOwn({
  9775. TSTypeCastExpression: true,
  9776. TSParameterProperty: "parameter",
  9777. TSNonNullExpression: "expression",
  9778. TSAsExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9779. TSSatisfiesExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9780. TSTypeAssertion: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true]
  9781. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9782. }
  9783. parseBindingAtom() {
  9784. if (this.state.type === 78) {
  9785. return this.parseIdentifier(true);
  9786. }
  9787. return super.parseBindingAtom();
  9788. }
  9789. parseMaybeDecoratorArguments(expr) {
  9790. if (this.match(47) || this.match(51)) {
  9791. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9792. if (this.match(10)) {
  9793. const call = super.parseMaybeDecoratorArguments(expr);
  9794. call.typeParameters = typeArguments;
  9795. return call;
  9796. }
  9797. this.unexpected(null, 10);
  9798. }
  9799. return super.parseMaybeDecoratorArguments(expr);
  9800. }
  9801. checkCommaAfterRest(close) {
  9802. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9803. this.next();
  9804. return false;
  9805. }
  9806. return super.checkCommaAfterRest(close);
  9807. }
  9808. isClassMethod() {
  9809. return this.match(47) || super.isClassMethod();
  9810. }
  9811. isClassProperty() {
  9812. return this.match(35) || this.match(14) || super.isClassProperty();
  9813. }
  9814. parseMaybeDefault(startLoc, left) {
  9815. const node = super.parseMaybeDefault(startLoc, left);
  9816. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9817. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  9818. at: node.typeAnnotation
  9819. });
  9820. }
  9821. return node;
  9822. }
  9823. getTokenFromCode(code) {
  9824. if (this.state.inType) {
  9825. if (code === 62) {
  9826. this.finishOp(48, 1);
  9827. return;
  9828. }
  9829. if (code === 60) {
  9830. this.finishOp(47, 1);
  9831. return;
  9832. }
  9833. }
  9834. super.getTokenFromCode(code);
  9835. }
  9836. reScan_lt_gt() {
  9837. const {
  9838. type
  9839. } = this.state;
  9840. if (type === 47) {
  9841. this.state.pos -= 1;
  9842. this.readToken_lt();
  9843. } else if (type === 48) {
  9844. this.state.pos -= 1;
  9845. this.readToken_gt();
  9846. }
  9847. }
  9848. reScan_lt() {
  9849. const {
  9850. type
  9851. } = this.state;
  9852. if (type === 51) {
  9853. this.state.pos -= 2;
  9854. this.finishOp(47, 1);
  9855. return 47;
  9856. }
  9857. return type;
  9858. }
  9859. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9860. for (let i = 0; i < exprList.length; i++) {
  9861. const expr = exprList[i];
  9862. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9863. exprList[i] = this.typeCastToParameter(expr);
  9864. }
  9865. }
  9866. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9867. }
  9868. typeCastToParameter(node) {
  9869. node.expression.typeAnnotation = node.typeAnnotation;
  9870. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9871. return node.expression;
  9872. }
  9873. shouldParseArrow(params) {
  9874. if (this.match(14)) {
  9875. return params.every(expr => this.isAssignable(expr, true));
  9876. }
  9877. return super.shouldParseArrow(params);
  9878. }
  9879. shouldParseAsyncArrow() {
  9880. return this.match(14) || super.shouldParseAsyncArrow();
  9881. }
  9882. canHaveLeadingDecorator() {
  9883. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9884. }
  9885. jsxParseOpeningElementAfterName(node) {
  9886. if (this.match(47) || this.match(51)) {
  9887. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9888. if (typeArguments) node.typeParameters = typeArguments;
  9889. }
  9890. return super.jsxParseOpeningElementAfterName(node);
  9891. }
  9892. getGetterSetterExpectedParamCount(method) {
  9893. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9894. const params = this.getObjectOrClassMethodParams(method);
  9895. const firstParam = params[0];
  9896. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9897. return hasContextParam ? baseCount + 1 : baseCount;
  9898. }
  9899. parseCatchClauseParam() {
  9900. const param = super.parseCatchClauseParam();
  9901. const type = this.tsTryParseTypeAnnotation();
  9902. if (type) {
  9903. param.typeAnnotation = type;
  9904. this.resetEndLocation(param);
  9905. }
  9906. return param;
  9907. }
  9908. tsInAmbientContext(cb) {
  9909. const oldIsAmbientContext = this.state.isAmbientContext;
  9910. this.state.isAmbientContext = true;
  9911. try {
  9912. return cb();
  9913. } finally {
  9914. this.state.isAmbientContext = oldIsAmbientContext;
  9915. }
  9916. }
  9917. parseClass(node, isStatement, optionalId) {
  9918. const oldInAbstractClass = this.state.inAbstractClass;
  9919. this.state.inAbstractClass = !!node.abstract;
  9920. try {
  9921. return super.parseClass(node, isStatement, optionalId);
  9922. } finally {
  9923. this.state.inAbstractClass = oldInAbstractClass;
  9924. }
  9925. }
  9926. tsParseAbstractDeclaration(node, decorators) {
  9927. if (this.match(80)) {
  9928. node.abstract = true;
  9929. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9930. } else if (this.isContextual(127)) {
  9931. if (!this.hasFollowingLineBreak()) {
  9932. node.abstract = true;
  9933. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  9934. at: node
  9935. });
  9936. return this.tsParseInterfaceDeclaration(node);
  9937. }
  9938. } else {
  9939. this.unexpected(null, 80);
  9940. }
  9941. }
  9942. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9943. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9944. if (method.abstract) {
  9945. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  9946. if (hasBody) {
  9947. const {
  9948. key
  9949. } = method;
  9950. this.raise(TSErrors.AbstractMethodHasImplementation, {
  9951. at: method,
  9952. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9953. });
  9954. }
  9955. }
  9956. return method;
  9957. }
  9958. tsParseTypeParameterName() {
  9959. const typeName = this.parseIdentifier();
  9960. return typeName.name;
  9961. }
  9962. shouldParseAsAmbientContext() {
  9963. return !!this.getPluginOption("typescript", "dts");
  9964. }
  9965. parse() {
  9966. if (this.shouldParseAsAmbientContext()) {
  9967. this.state.isAmbientContext = true;
  9968. }
  9969. return super.parse();
  9970. }
  9971. getExpression() {
  9972. if (this.shouldParseAsAmbientContext()) {
  9973. this.state.isAmbientContext = true;
  9974. }
  9975. return super.getExpression();
  9976. }
  9977. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9978. if (!isString && isMaybeTypeOnly) {
  9979. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9980. return this.finishNode(node, "ExportSpecifier");
  9981. }
  9982. node.exportKind = "value";
  9983. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  9984. }
  9985. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  9986. if (!importedIsString && isMaybeTypeOnly) {
  9987. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  9988. return this.finishNode(specifier, "ImportSpecifier");
  9989. }
  9990. specifier.importKind = "value";
  9991. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  9992. }
  9993. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  9994. const leftOfAsKey = isImport ? "imported" : "local";
  9995. const rightOfAsKey = isImport ? "local" : "exported";
  9996. let leftOfAs = node[leftOfAsKey];
  9997. let rightOfAs;
  9998. let hasTypeSpecifier = false;
  9999. let canParseAsKeyword = true;
  10000. const loc = leftOfAs.loc.start;
  10001. if (this.isContextual(93)) {
  10002. const firstAs = this.parseIdentifier();
  10003. if (this.isContextual(93)) {
  10004. const secondAs = this.parseIdentifier();
  10005. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10006. hasTypeSpecifier = true;
  10007. leftOfAs = firstAs;
  10008. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10009. canParseAsKeyword = false;
  10010. } else {
  10011. rightOfAs = secondAs;
  10012. canParseAsKeyword = false;
  10013. }
  10014. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10015. canParseAsKeyword = false;
  10016. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10017. } else {
  10018. hasTypeSpecifier = true;
  10019. leftOfAs = firstAs;
  10020. }
  10021. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10022. hasTypeSpecifier = true;
  10023. if (isImport) {
  10024. leftOfAs = this.parseIdentifier(true);
  10025. if (!this.isContextual(93)) {
  10026. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10027. }
  10028. } else {
  10029. leftOfAs = this.parseModuleExportName();
  10030. }
  10031. }
  10032. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10033. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  10034. at: loc
  10035. });
  10036. }
  10037. node[leftOfAsKey] = leftOfAs;
  10038. node[rightOfAsKey] = rightOfAs;
  10039. const kindKey = isImport ? "importKind" : "exportKind";
  10040. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10041. if (canParseAsKeyword && this.eatContextual(93)) {
  10042. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10043. }
  10044. if (!node[rightOfAsKey]) {
  10045. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10046. }
  10047. if (isImport) {
  10048. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10049. }
  10050. }
  10051. };
  10052. function isPossiblyLiteralEnum(expression) {
  10053. if (expression.type !== "MemberExpression") return false;
  10054. const {
  10055. computed,
  10056. property
  10057. } = expression;
  10058. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10059. return false;
  10060. }
  10061. return isUncomputedMemberExpressionChain(expression.object);
  10062. }
  10063. function isValidAmbientConstInitializer(expression, estree) {
  10064. var _expression$extra;
  10065. const {
  10066. type
  10067. } = expression;
  10068. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10069. return false;
  10070. }
  10071. if (estree) {
  10072. if (type === "Literal") {
  10073. const {
  10074. value
  10075. } = expression;
  10076. if (typeof value === "string" || typeof value === "boolean") {
  10077. return true;
  10078. }
  10079. }
  10080. } else {
  10081. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10082. return true;
  10083. }
  10084. }
  10085. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10086. return true;
  10087. }
  10088. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10089. return true;
  10090. }
  10091. if (isPossiblyLiteralEnum(expression)) {
  10092. return true;
  10093. }
  10094. return false;
  10095. }
  10096. function isNumber(expression, estree) {
  10097. if (estree) {
  10098. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10099. }
  10100. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10101. }
  10102. function isNegativeNumber(expression, estree) {
  10103. if (expression.type === "UnaryExpression") {
  10104. const {
  10105. operator,
  10106. argument
  10107. } = expression;
  10108. if (operator === "-" && isNumber(argument, estree)) {
  10109. return true;
  10110. }
  10111. }
  10112. return false;
  10113. }
  10114. function isUncomputedMemberExpressionChain(expression) {
  10115. if (expression.type === "Identifier") return true;
  10116. if (expression.type !== "MemberExpression" || expression.computed) {
  10117. return false;
  10118. }
  10119. return isUncomputedMemberExpressionChain(expression.object);
  10120. }
  10121. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10122. ClassNameIsRequired: "A class name is required.",
  10123. UnexpectedSpace: "Unexpected space in placeholder."
  10124. });
  10125. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10126. parsePlaceholder(expectedNode) {
  10127. if (this.match(142)) {
  10128. const node = this.startNode();
  10129. this.next();
  10130. this.assertNoSpace();
  10131. node.name = super.parseIdentifier(true);
  10132. this.assertNoSpace();
  10133. this.expect(142);
  10134. return this.finishPlaceholder(node, expectedNode);
  10135. }
  10136. }
  10137. finishPlaceholder(node, expectedNode) {
  10138. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  10139. node.expectedNode = expectedNode;
  10140. return isFinished ? node : this.finishNode(node, "Placeholder");
  10141. }
  10142. getTokenFromCode(code) {
  10143. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10144. this.finishOp(142, 2);
  10145. } else {
  10146. super.getTokenFromCode(code);
  10147. }
  10148. }
  10149. parseExprAtom(refExpressionErrors) {
  10150. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10151. }
  10152. parseIdentifier(liberal) {
  10153. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10154. }
  10155. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10156. if (word !== undefined) {
  10157. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10158. }
  10159. }
  10160. parseBindingAtom() {
  10161. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10162. }
  10163. isValidLVal(type, isParenthesized, binding) {
  10164. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10165. }
  10166. toAssignable(node, isLHS) {
  10167. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10168. node.expectedNode = "Pattern";
  10169. } else {
  10170. super.toAssignable(node, isLHS);
  10171. }
  10172. }
  10173. chStartsBindingIdentifier(ch, pos) {
  10174. if (super.chStartsBindingIdentifier(ch, pos)) {
  10175. return true;
  10176. }
  10177. const nextToken = this.lookahead();
  10178. if (nextToken.type === 142) {
  10179. return true;
  10180. }
  10181. return false;
  10182. }
  10183. verifyBreakContinue(node, isBreak) {
  10184. if (node.label && node.label.type === "Placeholder") return;
  10185. super.verifyBreakContinue(node, isBreak);
  10186. }
  10187. parseExpressionStatement(node, expr) {
  10188. var _expr$extra;
  10189. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10190. return super.parseExpressionStatement(node, expr);
  10191. }
  10192. if (this.match(14)) {
  10193. const stmt = node;
  10194. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10195. this.next();
  10196. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10197. return this.finishNode(stmt, "LabeledStatement");
  10198. }
  10199. this.semicolon();
  10200. node.name = expr.name;
  10201. return this.finishPlaceholder(node, "Statement");
  10202. }
  10203. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10204. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10205. }
  10206. parseFunctionId(requireId) {
  10207. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10208. }
  10209. parseClass(node, isStatement, optionalId) {
  10210. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10211. this.next();
  10212. const oldStrict = this.state.strict;
  10213. const placeholder = this.parsePlaceholder("Identifier");
  10214. if (placeholder) {
  10215. if (this.match(81) || this.match(142) || this.match(5)) {
  10216. node.id = placeholder;
  10217. } else if (optionalId || !isStatement) {
  10218. node.id = null;
  10219. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10220. return this.finishNode(node, type);
  10221. } else {
  10222. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  10223. at: this.state.startLoc
  10224. });
  10225. }
  10226. } else {
  10227. this.parseClassId(node, isStatement, optionalId);
  10228. }
  10229. super.parseClassSuper(node);
  10230. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10231. return this.finishNode(node, type);
  10232. }
  10233. parseExport(node, decorators) {
  10234. const placeholder = this.parsePlaceholder("Identifier");
  10235. if (!placeholder) return super.parseExport(node, decorators);
  10236. if (!this.isContextual(97) && !this.match(12)) {
  10237. node.specifiers = [];
  10238. node.source = null;
  10239. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10240. return this.finishNode(node, "ExportNamedDeclaration");
  10241. }
  10242. this.expectPlugin("exportDefaultFrom");
  10243. const specifier = this.startNode();
  10244. specifier.exported = placeholder;
  10245. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10246. return super.parseExport(node, decorators);
  10247. }
  10248. isExportDefaultSpecifier() {
  10249. if (this.match(65)) {
  10250. const next = this.nextTokenStart();
  10251. if (this.isUnparsedContextual(next, "from")) {
  10252. if (this.input.startsWith(tokenLabelName(142), this.nextTokenStartSince(next + 4))) {
  10253. return true;
  10254. }
  10255. }
  10256. }
  10257. return super.isExportDefaultSpecifier();
  10258. }
  10259. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10260. var _specifiers;
  10261. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10262. return true;
  10263. }
  10264. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10265. }
  10266. checkExport(node) {
  10267. const {
  10268. specifiers
  10269. } = node;
  10270. if (specifiers != null && specifiers.length) {
  10271. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10272. }
  10273. super.checkExport(node);
  10274. node.specifiers = specifiers;
  10275. }
  10276. parseImport(node) {
  10277. const placeholder = this.parsePlaceholder("Identifier");
  10278. if (!placeholder) return super.parseImport(node);
  10279. node.specifiers = [];
  10280. if (!this.isContextual(97) && !this.match(12)) {
  10281. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10282. this.semicolon();
  10283. return this.finishNode(node, "ImportDeclaration");
  10284. }
  10285. const specifier = this.startNodeAtNode(placeholder);
  10286. specifier.local = placeholder;
  10287. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10288. if (this.eat(12)) {
  10289. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10290. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10291. }
  10292. this.expectContextual(97);
  10293. node.source = this.parseImportSource();
  10294. this.semicolon();
  10295. return this.finishNode(node, "ImportDeclaration");
  10296. }
  10297. parseImportSource() {
  10298. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10299. }
  10300. assertNoSpace() {
  10301. if (this.state.start > this.state.lastTokEndLoc.index) {
  10302. this.raise(PlaceholderErrors.UnexpectedSpace, {
  10303. at: this.state.lastTokEndLoc
  10304. });
  10305. }
  10306. }
  10307. };
  10308. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10309. parseV8Intrinsic() {
  10310. if (this.match(54)) {
  10311. const v8IntrinsicStartLoc = this.state.startLoc;
  10312. const node = this.startNode();
  10313. this.next();
  10314. if (tokenIsIdentifier(this.state.type)) {
  10315. const name = this.parseIdentifierName();
  10316. const identifier = this.createIdentifier(node, name);
  10317. identifier.type = "V8IntrinsicIdentifier";
  10318. if (this.match(10)) {
  10319. return identifier;
  10320. }
  10321. }
  10322. this.unexpected(v8IntrinsicStartLoc);
  10323. }
  10324. }
  10325. parseExprAtom(refExpressionErrors) {
  10326. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10327. }
  10328. };
  10329. function hasPlugin(plugins, expectedConfig) {
  10330. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  10331. const expectedKeys = Object.keys(expectedOptions);
  10332. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  10333. return plugins.some(p => {
  10334. if (typeof p === "string") {
  10335. return expectedOptionsIsEmpty && p === expectedName;
  10336. } else {
  10337. const [pluginName, pluginOptions] = p;
  10338. if (pluginName !== expectedName) {
  10339. return false;
  10340. }
  10341. for (const key of expectedKeys) {
  10342. if (pluginOptions[key] !== expectedOptions[key]) {
  10343. return false;
  10344. }
  10345. }
  10346. return true;
  10347. }
  10348. });
  10349. }
  10350. function getPluginOption(plugins, name, option) {
  10351. const plugin = plugins.find(plugin => {
  10352. if (Array.isArray(plugin)) {
  10353. return plugin[0] === name;
  10354. } else {
  10355. return plugin === name;
  10356. }
  10357. });
  10358. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  10359. return plugin[1][option];
  10360. }
  10361. return null;
  10362. }
  10363. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10364. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10365. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10366. function validatePlugins(plugins) {
  10367. if (hasPlugin(plugins, "decorators")) {
  10368. if (hasPlugin(plugins, "decorators-legacy")) {
  10369. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10370. }
  10371. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  10372. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10373. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10374. }
  10375. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  10376. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10377. throw new Error("'allowCallParenthesized' must be a boolean.");
  10378. }
  10379. }
  10380. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  10381. throw new Error("Cannot combine flow and typescript plugins.");
  10382. }
  10383. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  10384. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10385. }
  10386. if (hasPlugin(plugins, "pipelineOperator")) {
  10387. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  10388. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10389. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10390. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10391. }
  10392. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  10393. syntaxType: "hash"
  10394. }]);
  10395. if (proposal === "hack") {
  10396. if (hasPlugin(plugins, "placeholders")) {
  10397. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10398. }
  10399. if (hasPlugin(plugins, "v8intrinsic")) {
  10400. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10401. }
  10402. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  10403. if (!TOPIC_TOKENS.includes(topicToken)) {
  10404. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10405. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10406. }
  10407. if (topicToken === "#" && tupleSyntaxIsHash) {
  10408. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10409. }
  10410. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10411. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10412. }
  10413. }
  10414. if (hasPlugin(plugins, "moduleAttributes")) {
  10415. {
  10416. if (hasPlugin(plugins, "importAssertions") || hasPlugin(plugins, "importAttributes")) {
  10417. throw new Error("Cannot combine importAssertions, importAttributes and moduleAttributes plugins.");
  10418. }
  10419. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  10420. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10421. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10422. }
  10423. }
  10424. }
  10425. if (hasPlugin(plugins, "importAssertions") && hasPlugin(plugins, "importAttributes")) {
  10426. throw new Error("Cannot combine importAssertions and importAttributes plugins.");
  10427. }
  10428. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  10429. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10430. }
  10431. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  10432. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10433. error.missingPlugins = "doExpressions";
  10434. throw error;
  10435. }
  10436. }
  10437. const mixinPlugins = {
  10438. estree,
  10439. jsx,
  10440. flow,
  10441. typescript,
  10442. v8intrinsic,
  10443. placeholders
  10444. };
  10445. const mixinPluginNames = Object.keys(mixinPlugins);
  10446. const defaultOptions = {
  10447. sourceType: "script",
  10448. sourceFilename: undefined,
  10449. startColumn: 0,
  10450. startLine: 1,
  10451. allowAwaitOutsideFunction: false,
  10452. allowReturnOutsideFunction: false,
  10453. allowNewTargetOutsideFunction: false,
  10454. allowImportExportEverywhere: false,
  10455. allowSuperOutsideMethod: false,
  10456. allowUndeclaredExports: false,
  10457. plugins: [],
  10458. strictMode: null,
  10459. ranges: false,
  10460. tokens: false,
  10461. createParenthesizedExpressions: false,
  10462. errorRecovery: false,
  10463. attachComment: true,
  10464. annexB: true
  10465. };
  10466. function getOptions(opts) {
  10467. if (opts == null) {
  10468. return Object.assign({}, defaultOptions);
  10469. }
  10470. if (opts.annexB != null && opts.annexB !== false) {
  10471. throw new Error("The `annexB` option can only be set to `false`.");
  10472. }
  10473. const options = {};
  10474. for (const key of Object.keys(defaultOptions)) {
  10475. var _opts$key;
  10476. options[key] = (_opts$key = opts[key]) != null ? _opts$key : defaultOptions[key];
  10477. }
  10478. return options;
  10479. }
  10480. class ExpressionParser extends LValParser {
  10481. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10482. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10483. return;
  10484. }
  10485. const key = prop.key;
  10486. const name = key.type === "Identifier" ? key.name : key.value;
  10487. if (name === "__proto__") {
  10488. if (isRecord) {
  10489. this.raise(Errors.RecordNoProto, {
  10490. at: key
  10491. });
  10492. return;
  10493. }
  10494. if (protoRef.used) {
  10495. if (refExpressionErrors) {
  10496. if (refExpressionErrors.doubleProtoLoc === null) {
  10497. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10498. }
  10499. } else {
  10500. this.raise(Errors.DuplicateProto, {
  10501. at: key
  10502. });
  10503. }
  10504. }
  10505. protoRef.used = true;
  10506. }
  10507. }
  10508. shouldExitDescending(expr, potentialArrowAt) {
  10509. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10510. }
  10511. getExpression() {
  10512. this.enterInitialScopes();
  10513. this.nextToken();
  10514. const expr = this.parseExpression();
  10515. if (!this.match(137)) {
  10516. this.unexpected();
  10517. }
  10518. this.finalizeRemainingComments();
  10519. expr.comments = this.state.comments;
  10520. expr.errors = this.state.errors;
  10521. if (this.options.tokens) {
  10522. expr.tokens = this.tokens;
  10523. }
  10524. return expr;
  10525. }
  10526. parseExpression(disallowIn, refExpressionErrors) {
  10527. if (disallowIn) {
  10528. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10529. }
  10530. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10531. }
  10532. parseExpressionBase(refExpressionErrors) {
  10533. const startLoc = this.state.startLoc;
  10534. const expr = this.parseMaybeAssign(refExpressionErrors);
  10535. if (this.match(12)) {
  10536. const node = this.startNodeAt(startLoc);
  10537. node.expressions = [expr];
  10538. while (this.eat(12)) {
  10539. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10540. }
  10541. this.toReferencedList(node.expressions);
  10542. return this.finishNode(node, "SequenceExpression");
  10543. }
  10544. return expr;
  10545. }
  10546. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10547. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10548. }
  10549. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10550. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10551. }
  10552. setOptionalParametersError(refExpressionErrors, resultError) {
  10553. var _resultError$loc;
  10554. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10555. }
  10556. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10557. const startLoc = this.state.startLoc;
  10558. if (this.isContextual(106)) {
  10559. if (this.prodParam.hasYield) {
  10560. let left = this.parseYield();
  10561. if (afterLeftParse) {
  10562. left = afterLeftParse.call(this, left, startLoc);
  10563. }
  10564. return left;
  10565. }
  10566. }
  10567. let ownExpressionErrors;
  10568. if (refExpressionErrors) {
  10569. ownExpressionErrors = false;
  10570. } else {
  10571. refExpressionErrors = new ExpressionErrors();
  10572. ownExpressionErrors = true;
  10573. }
  10574. const {
  10575. type
  10576. } = this.state;
  10577. if (type === 10 || tokenIsIdentifier(type)) {
  10578. this.state.potentialArrowAt = this.state.start;
  10579. }
  10580. let left = this.parseMaybeConditional(refExpressionErrors);
  10581. if (afterLeftParse) {
  10582. left = afterLeftParse.call(this, left, startLoc);
  10583. }
  10584. if (tokenIsAssignment(this.state.type)) {
  10585. const node = this.startNodeAt(startLoc);
  10586. const operator = this.state.value;
  10587. node.operator = operator;
  10588. if (this.match(29)) {
  10589. this.toAssignable(left, true);
  10590. node.left = left;
  10591. const startIndex = startLoc.index;
  10592. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10593. refExpressionErrors.doubleProtoLoc = null;
  10594. }
  10595. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10596. refExpressionErrors.shorthandAssignLoc = null;
  10597. }
  10598. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10599. this.checkDestructuringPrivate(refExpressionErrors);
  10600. refExpressionErrors.privateKeyLoc = null;
  10601. }
  10602. } else {
  10603. node.left = left;
  10604. }
  10605. this.next();
  10606. node.right = this.parseMaybeAssign();
  10607. this.checkLVal(left, {
  10608. in: this.finishNode(node, "AssignmentExpression")
  10609. });
  10610. return node;
  10611. } else if (ownExpressionErrors) {
  10612. this.checkExpressionErrors(refExpressionErrors, true);
  10613. }
  10614. return left;
  10615. }
  10616. parseMaybeConditional(refExpressionErrors) {
  10617. const startLoc = this.state.startLoc;
  10618. const potentialArrowAt = this.state.potentialArrowAt;
  10619. const expr = this.parseExprOps(refExpressionErrors);
  10620. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10621. return expr;
  10622. }
  10623. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10624. }
  10625. parseConditional(expr, startLoc, refExpressionErrors) {
  10626. if (this.eat(17)) {
  10627. const node = this.startNodeAt(startLoc);
  10628. node.test = expr;
  10629. node.consequent = this.parseMaybeAssignAllowIn();
  10630. this.expect(14);
  10631. node.alternate = this.parseMaybeAssign();
  10632. return this.finishNode(node, "ConditionalExpression");
  10633. }
  10634. return expr;
  10635. }
  10636. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10637. return this.match(136) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10638. }
  10639. parseExprOps(refExpressionErrors) {
  10640. const startLoc = this.state.startLoc;
  10641. const potentialArrowAt = this.state.potentialArrowAt;
  10642. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10643. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10644. return expr;
  10645. }
  10646. return this.parseExprOp(expr, startLoc, -1);
  10647. }
  10648. parseExprOp(left, leftStartLoc, minPrec) {
  10649. if (this.isPrivateName(left)) {
  10650. const value = this.getPrivateNameSV(left);
  10651. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10652. this.raise(Errors.PrivateInExpectedIn, {
  10653. at: left,
  10654. identifierName: value
  10655. });
  10656. }
  10657. this.classScope.usePrivateName(value, left.loc.start);
  10658. }
  10659. const op = this.state.type;
  10660. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10661. let prec = tokenOperatorPrecedence(op);
  10662. if (prec > minPrec) {
  10663. if (op === 39) {
  10664. this.expectPlugin("pipelineOperator");
  10665. if (this.state.inFSharpPipelineDirectBody) {
  10666. return left;
  10667. }
  10668. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10669. }
  10670. const node = this.startNodeAt(leftStartLoc);
  10671. node.left = left;
  10672. node.operator = this.state.value;
  10673. const logical = op === 41 || op === 42;
  10674. const coalesce = op === 40;
  10675. if (coalesce) {
  10676. prec = tokenOperatorPrecedence(42);
  10677. }
  10678. this.next();
  10679. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10680. proposal: "minimal"
  10681. }])) {
  10682. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10683. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  10684. at: this.state.startLoc
  10685. });
  10686. }
  10687. }
  10688. node.right = this.parseExprOpRightExpr(op, prec);
  10689. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10690. const nextOp = this.state.type;
  10691. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10692. throw this.raise(Errors.MixingCoalesceWithLogical, {
  10693. at: this.state.startLoc
  10694. });
  10695. }
  10696. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10697. }
  10698. }
  10699. return left;
  10700. }
  10701. parseExprOpRightExpr(op, prec) {
  10702. const startLoc = this.state.startLoc;
  10703. switch (op) {
  10704. case 39:
  10705. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10706. case "hack":
  10707. return this.withTopicBindingContext(() => {
  10708. return this.parseHackPipeBody();
  10709. });
  10710. case "smart":
  10711. return this.withTopicBindingContext(() => {
  10712. if (this.prodParam.hasYield && this.isContextual(106)) {
  10713. throw this.raise(Errors.PipeBodyIsTighter, {
  10714. at: this.state.startLoc
  10715. });
  10716. }
  10717. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10718. });
  10719. case "fsharp":
  10720. return this.withSoloAwaitPermittingContext(() => {
  10721. return this.parseFSharpPipelineBody(prec);
  10722. });
  10723. }
  10724. default:
  10725. return this.parseExprOpBaseRightExpr(op, prec);
  10726. }
  10727. }
  10728. parseExprOpBaseRightExpr(op, prec) {
  10729. const startLoc = this.state.startLoc;
  10730. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10731. }
  10732. parseHackPipeBody() {
  10733. var _body$extra;
  10734. const {
  10735. startLoc
  10736. } = this.state;
  10737. const body = this.parseMaybeAssign();
  10738. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10739. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10740. this.raise(Errors.PipeUnparenthesizedBody, {
  10741. at: startLoc,
  10742. type: body.type
  10743. });
  10744. }
  10745. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10746. this.raise(Errors.PipeTopicUnused, {
  10747. at: startLoc
  10748. });
  10749. }
  10750. return body;
  10751. }
  10752. checkExponentialAfterUnary(node) {
  10753. if (this.match(57)) {
  10754. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  10755. at: node.argument
  10756. });
  10757. }
  10758. }
  10759. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10760. const startLoc = this.state.startLoc;
  10761. const isAwait = this.isContextual(96);
  10762. if (isAwait && this.isAwaitAllowed()) {
  10763. this.next();
  10764. const expr = this.parseAwait(startLoc);
  10765. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10766. return expr;
  10767. }
  10768. const update = this.match(34);
  10769. const node = this.startNode();
  10770. if (tokenIsPrefix(this.state.type)) {
  10771. node.operator = this.state.value;
  10772. node.prefix = true;
  10773. if (this.match(72)) {
  10774. this.expectPlugin("throwExpressions");
  10775. }
  10776. const isDelete = this.match(89);
  10777. this.next();
  10778. node.argument = this.parseMaybeUnary(null, true);
  10779. this.checkExpressionErrors(refExpressionErrors, true);
  10780. if (this.state.strict && isDelete) {
  10781. const arg = node.argument;
  10782. if (arg.type === "Identifier") {
  10783. this.raise(Errors.StrictDelete, {
  10784. at: node
  10785. });
  10786. } else if (this.hasPropertyAsPrivateName(arg)) {
  10787. this.raise(Errors.DeletePrivateField, {
  10788. at: node
  10789. });
  10790. }
  10791. }
  10792. if (!update) {
  10793. if (!sawUnary) {
  10794. this.checkExponentialAfterUnary(node);
  10795. }
  10796. return this.finishNode(node, "UnaryExpression");
  10797. }
  10798. }
  10799. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10800. if (isAwait) {
  10801. const {
  10802. type
  10803. } = this.state;
  10804. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10805. if (startsExpr && !this.isAmbiguousAwait()) {
  10806. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  10807. at: startLoc
  10808. });
  10809. return this.parseAwait(startLoc);
  10810. }
  10811. }
  10812. return expr;
  10813. }
  10814. parseUpdate(node, update, refExpressionErrors) {
  10815. if (update) {
  10816. const updateExpressionNode = node;
  10817. this.checkLVal(updateExpressionNode.argument, {
  10818. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  10819. });
  10820. return node;
  10821. }
  10822. const startLoc = this.state.startLoc;
  10823. let expr = this.parseExprSubscripts(refExpressionErrors);
  10824. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10825. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10826. const node = this.startNodeAt(startLoc);
  10827. node.operator = this.state.value;
  10828. node.prefix = false;
  10829. node.argument = expr;
  10830. this.next();
  10831. this.checkLVal(expr, {
  10832. in: expr = this.finishNode(node, "UpdateExpression")
  10833. });
  10834. }
  10835. return expr;
  10836. }
  10837. parseExprSubscripts(refExpressionErrors) {
  10838. const startLoc = this.state.startLoc;
  10839. const potentialArrowAt = this.state.potentialArrowAt;
  10840. const expr = this.parseExprAtom(refExpressionErrors);
  10841. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10842. return expr;
  10843. }
  10844. return this.parseSubscripts(expr, startLoc);
  10845. }
  10846. parseSubscripts(base, startLoc, noCalls) {
  10847. const state = {
  10848. optionalChainMember: false,
  10849. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10850. stop: false
  10851. };
  10852. do {
  10853. base = this.parseSubscript(base, startLoc, noCalls, state);
  10854. state.maybeAsyncArrow = false;
  10855. } while (!state.stop);
  10856. return base;
  10857. }
  10858. parseSubscript(base, startLoc, noCalls, state) {
  10859. const {
  10860. type
  10861. } = this.state;
  10862. if (!noCalls && type === 15) {
  10863. return this.parseBind(base, startLoc, noCalls, state);
  10864. } else if (tokenIsTemplate(type)) {
  10865. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10866. }
  10867. let optional = false;
  10868. if (type === 18) {
  10869. if (noCalls) {
  10870. this.raise(Errors.OptionalChainingNoNew, {
  10871. at: this.state.startLoc
  10872. });
  10873. if (this.lookaheadCharCode() === 40) {
  10874. state.stop = true;
  10875. return base;
  10876. }
  10877. }
  10878. state.optionalChainMember = optional = true;
  10879. this.next();
  10880. }
  10881. if (!noCalls && this.match(10)) {
  10882. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10883. } else {
  10884. const computed = this.eat(0);
  10885. if (computed || optional || this.eat(16)) {
  10886. return this.parseMember(base, startLoc, state, computed, optional);
  10887. } else {
  10888. state.stop = true;
  10889. return base;
  10890. }
  10891. }
  10892. }
  10893. parseMember(base, startLoc, state, computed, optional) {
  10894. const node = this.startNodeAt(startLoc);
  10895. node.object = base;
  10896. node.computed = computed;
  10897. if (computed) {
  10898. node.property = this.parseExpression();
  10899. this.expect(3);
  10900. } else if (this.match(136)) {
  10901. if (base.type === "Super") {
  10902. this.raise(Errors.SuperPrivateField, {
  10903. at: startLoc
  10904. });
  10905. }
  10906. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10907. node.property = this.parsePrivateName();
  10908. } else {
  10909. node.property = this.parseIdentifier(true);
  10910. }
  10911. if (state.optionalChainMember) {
  10912. node.optional = optional;
  10913. return this.finishNode(node, "OptionalMemberExpression");
  10914. } else {
  10915. return this.finishNode(node, "MemberExpression");
  10916. }
  10917. }
  10918. parseBind(base, startLoc, noCalls, state) {
  10919. const node = this.startNodeAt(startLoc);
  10920. node.object = base;
  10921. this.next();
  10922. node.callee = this.parseNoCallExpr();
  10923. state.stop = true;
  10924. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10925. }
  10926. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10927. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10928. let refExpressionErrors = null;
  10929. this.state.maybeInArrowParameters = true;
  10930. this.next();
  10931. const node = this.startNodeAt(startLoc);
  10932. node.callee = base;
  10933. const {
  10934. maybeAsyncArrow,
  10935. optionalChainMember
  10936. } = state;
  10937. if (maybeAsyncArrow) {
  10938. this.expressionScope.enter(newAsyncArrowScope());
  10939. refExpressionErrors = new ExpressionErrors();
  10940. }
  10941. if (optionalChainMember) {
  10942. node.optional = optional;
  10943. }
  10944. if (optional) {
  10945. node.arguments = this.parseCallExpressionArguments(11);
  10946. } else {
  10947. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  10948. }
  10949. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10950. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10951. state.stop = true;
  10952. this.checkDestructuringPrivate(refExpressionErrors);
  10953. this.expressionScope.validateAsPattern();
  10954. this.expressionScope.exit();
  10955. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10956. } else {
  10957. if (maybeAsyncArrow) {
  10958. this.checkExpressionErrors(refExpressionErrors, true);
  10959. this.expressionScope.exit();
  10960. }
  10961. this.toReferencedArguments(finishedNode);
  10962. }
  10963. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10964. return finishedNode;
  10965. }
  10966. toReferencedArguments(node, isParenthesizedExpr) {
  10967. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10968. }
  10969. parseTaggedTemplateExpression(base, startLoc, state) {
  10970. const node = this.startNodeAt(startLoc);
  10971. node.tag = base;
  10972. node.quasi = this.parseTemplate(true);
  10973. if (state.optionalChainMember) {
  10974. this.raise(Errors.OptionalChainingNoTemplate, {
  10975. at: startLoc
  10976. });
  10977. }
  10978. return this.finishNode(node, "TaggedTemplateExpression");
  10979. }
  10980. atPossibleAsyncArrow(base) {
  10981. return base.type === "Identifier" && base.name === "async" && this.state.lastTokEndLoc.index === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.state.potentialArrowAt;
  10982. }
  10983. expectImportAttributesPlugin() {
  10984. if (!this.hasPlugin("importAssertions")) {
  10985. this.expectPlugin("importAttributes");
  10986. }
  10987. }
  10988. finishCallExpression(node, optional) {
  10989. if (node.callee.type === "Import") {
  10990. if (node.arguments.length === 2) {
  10991. {
  10992. if (!this.hasPlugin("moduleAttributes")) {
  10993. this.expectImportAttributesPlugin();
  10994. }
  10995. }
  10996. }
  10997. if (node.arguments.length === 0 || node.arguments.length > 2) {
  10998. this.raise(Errors.ImportCallArity, {
  10999. at: node,
  11000. maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  11001. });
  11002. } else {
  11003. for (const arg of node.arguments) {
  11004. if (arg.type === "SpreadElement") {
  11005. this.raise(Errors.ImportCallSpreadArgument, {
  11006. at: arg
  11007. });
  11008. }
  11009. }
  11010. }
  11011. }
  11012. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11013. }
  11014. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11015. const elts = [];
  11016. let first = true;
  11017. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11018. this.state.inFSharpPipelineDirectBody = false;
  11019. while (!this.eat(close)) {
  11020. if (first) {
  11021. first = false;
  11022. } else {
  11023. this.expect(12);
  11024. if (this.match(close)) {
  11025. if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  11026. this.raise(Errors.ImportCallArgumentTrailingComma, {
  11027. at: this.state.lastTokStartLoc
  11028. });
  11029. }
  11030. if (nodeForExtra) {
  11031. this.addTrailingCommaExtraToNode(nodeForExtra);
  11032. }
  11033. this.next();
  11034. break;
  11035. }
  11036. }
  11037. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11038. }
  11039. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11040. return elts;
  11041. }
  11042. shouldParseAsyncArrow() {
  11043. return this.match(19) && !this.canInsertSemicolon();
  11044. }
  11045. parseAsyncArrowFromCallExpression(node, call) {
  11046. var _call$extra;
  11047. this.resetPreviousNodeTrailingComments(call);
  11048. this.expect(19);
  11049. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11050. if (call.innerComments) {
  11051. setInnerComments(node, call.innerComments);
  11052. }
  11053. if (call.callee.trailingComments) {
  11054. setInnerComments(node, call.callee.trailingComments);
  11055. }
  11056. return node;
  11057. }
  11058. parseNoCallExpr() {
  11059. const startLoc = this.state.startLoc;
  11060. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11061. }
  11062. parseExprAtom(refExpressionErrors) {
  11063. let node;
  11064. let decorators = null;
  11065. const {
  11066. type
  11067. } = this.state;
  11068. switch (type) {
  11069. case 79:
  11070. return this.parseSuper();
  11071. case 83:
  11072. node = this.startNode();
  11073. this.next();
  11074. if (this.match(16)) {
  11075. return this.parseImportMetaProperty(node);
  11076. }
  11077. if (!this.match(10)) {
  11078. this.raise(Errors.UnsupportedImport, {
  11079. at: this.state.lastTokStartLoc
  11080. });
  11081. }
  11082. return this.finishNode(node, "Import");
  11083. case 78:
  11084. node = this.startNode();
  11085. this.next();
  11086. return this.finishNode(node, "ThisExpression");
  11087. case 90:
  11088. {
  11089. return this.parseDo(this.startNode(), false);
  11090. }
  11091. case 56:
  11092. case 31:
  11093. {
  11094. this.readRegexp();
  11095. return this.parseRegExpLiteral(this.state.value);
  11096. }
  11097. case 132:
  11098. return this.parseNumericLiteral(this.state.value);
  11099. case 133:
  11100. return this.parseBigIntLiteral(this.state.value);
  11101. case 134:
  11102. return this.parseDecimalLiteral(this.state.value);
  11103. case 131:
  11104. return this.parseStringLiteral(this.state.value);
  11105. case 84:
  11106. return this.parseNullLiteral();
  11107. case 85:
  11108. return this.parseBooleanLiteral(true);
  11109. case 86:
  11110. return this.parseBooleanLiteral(false);
  11111. case 10:
  11112. {
  11113. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11114. return this.parseParenAndDistinguishExpression(canBeArrow);
  11115. }
  11116. case 2:
  11117. case 1:
  11118. {
  11119. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11120. }
  11121. case 0:
  11122. {
  11123. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11124. }
  11125. case 6:
  11126. case 7:
  11127. {
  11128. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11129. }
  11130. case 5:
  11131. {
  11132. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11133. }
  11134. case 68:
  11135. return this.parseFunctionOrFunctionSent();
  11136. case 26:
  11137. decorators = this.parseDecorators();
  11138. case 80:
  11139. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11140. case 77:
  11141. return this.parseNewOrNewTarget();
  11142. case 25:
  11143. case 24:
  11144. return this.parseTemplate(false);
  11145. case 15:
  11146. {
  11147. node = this.startNode();
  11148. this.next();
  11149. node.object = null;
  11150. const callee = node.callee = this.parseNoCallExpr();
  11151. if (callee.type === "MemberExpression") {
  11152. return this.finishNode(node, "BindExpression");
  11153. } else {
  11154. throw this.raise(Errors.UnsupportedBind, {
  11155. at: callee
  11156. });
  11157. }
  11158. }
  11159. case 136:
  11160. {
  11161. this.raise(Errors.PrivateInExpectedIn, {
  11162. at: this.state.startLoc,
  11163. identifierName: this.state.value
  11164. });
  11165. return this.parsePrivateName();
  11166. }
  11167. case 33:
  11168. {
  11169. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11170. }
  11171. case 32:
  11172. {
  11173. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11174. }
  11175. case 37:
  11176. case 38:
  11177. {
  11178. return this.parseTopicReference("hack");
  11179. }
  11180. case 44:
  11181. case 54:
  11182. case 27:
  11183. {
  11184. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11185. if (pipeProposal) {
  11186. return this.parseTopicReference(pipeProposal);
  11187. }
  11188. this.unexpected();
  11189. break;
  11190. }
  11191. case 47:
  11192. {
  11193. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11194. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11195. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11196. } else {
  11197. this.unexpected();
  11198. }
  11199. break;
  11200. }
  11201. default:
  11202. if (tokenIsIdentifier(type)) {
  11203. if (this.isContextual(125) && this.lookaheadInLineCharCode() === 123) {
  11204. return this.parseModuleExpression();
  11205. }
  11206. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11207. const containsEsc = this.state.containsEsc;
  11208. const id = this.parseIdentifier();
  11209. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11210. const {
  11211. type
  11212. } = this.state;
  11213. if (type === 68) {
  11214. this.resetPreviousNodeTrailingComments(id);
  11215. this.next();
  11216. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11217. } else if (tokenIsIdentifier(type)) {
  11218. if (this.lookaheadCharCode() === 61) {
  11219. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11220. } else {
  11221. return id;
  11222. }
  11223. } else if (type === 90) {
  11224. this.resetPreviousNodeTrailingComments(id);
  11225. return this.parseDo(this.startNodeAtNode(id), true);
  11226. }
  11227. }
  11228. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11229. this.next();
  11230. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11231. }
  11232. return id;
  11233. } else {
  11234. this.unexpected();
  11235. }
  11236. }
  11237. }
  11238. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11239. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11240. if (pipeProposal) {
  11241. this.state.type = topicTokenType;
  11242. this.state.value = topicTokenValue;
  11243. this.state.pos--;
  11244. this.state.end--;
  11245. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11246. return this.parseTopicReference(pipeProposal);
  11247. } else {
  11248. this.unexpected();
  11249. }
  11250. }
  11251. parseTopicReference(pipeProposal) {
  11252. const node = this.startNode();
  11253. const startLoc = this.state.startLoc;
  11254. const tokenType = this.state.type;
  11255. this.next();
  11256. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11257. }
  11258. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11259. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11260. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11261. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11262. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  11263. at: startLoc
  11264. });
  11265. }
  11266. this.registerTopicReference();
  11267. return this.finishNode(node, nodeType);
  11268. } else {
  11269. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11270. at: startLoc,
  11271. token: tokenLabelName(tokenType)
  11272. });
  11273. }
  11274. }
  11275. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11276. switch (pipeProposal) {
  11277. case "hack":
  11278. {
  11279. return this.hasPlugin(["pipelineOperator", {
  11280. topicToken: tokenLabelName(tokenType)
  11281. }]);
  11282. }
  11283. case "smart":
  11284. return tokenType === 27;
  11285. default:
  11286. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11287. at: startLoc
  11288. });
  11289. }
  11290. }
  11291. parseAsyncArrowUnaryFunction(node) {
  11292. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11293. const params = [this.parseIdentifier()];
  11294. this.prodParam.exit();
  11295. if (this.hasPrecedingLineBreak()) {
  11296. this.raise(Errors.LineTerminatorBeforeArrow, {
  11297. at: this.state.curPosition()
  11298. });
  11299. }
  11300. this.expect(19);
  11301. return this.parseArrowExpression(node, params, true);
  11302. }
  11303. parseDo(node, isAsync) {
  11304. this.expectPlugin("doExpressions");
  11305. if (isAsync) {
  11306. this.expectPlugin("asyncDoExpressions");
  11307. }
  11308. node.async = isAsync;
  11309. this.next();
  11310. const oldLabels = this.state.labels;
  11311. this.state.labels = [];
  11312. if (isAsync) {
  11313. this.prodParam.enter(PARAM_AWAIT);
  11314. node.body = this.parseBlock();
  11315. this.prodParam.exit();
  11316. } else {
  11317. node.body = this.parseBlock();
  11318. }
  11319. this.state.labels = oldLabels;
  11320. return this.finishNode(node, "DoExpression");
  11321. }
  11322. parseSuper() {
  11323. const node = this.startNode();
  11324. this.next();
  11325. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11326. this.raise(Errors.SuperNotAllowed, {
  11327. at: node
  11328. });
  11329. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11330. this.raise(Errors.UnexpectedSuper, {
  11331. at: node
  11332. });
  11333. }
  11334. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11335. this.raise(Errors.UnsupportedSuper, {
  11336. at: node
  11337. });
  11338. }
  11339. return this.finishNode(node, "Super");
  11340. }
  11341. parsePrivateName() {
  11342. const node = this.startNode();
  11343. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11344. const name = this.state.value;
  11345. this.next();
  11346. node.id = this.createIdentifier(id, name);
  11347. return this.finishNode(node, "PrivateName");
  11348. }
  11349. parseFunctionOrFunctionSent() {
  11350. const node = this.startNode();
  11351. this.next();
  11352. if (this.prodParam.hasYield && this.match(16)) {
  11353. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11354. this.next();
  11355. if (this.match(102)) {
  11356. this.expectPlugin("functionSent");
  11357. } else if (!this.hasPlugin("functionSent")) {
  11358. this.unexpected();
  11359. }
  11360. return this.parseMetaProperty(node, meta, "sent");
  11361. }
  11362. return this.parseFunction(node);
  11363. }
  11364. parseMetaProperty(node, meta, propertyName) {
  11365. node.meta = meta;
  11366. const containsEsc = this.state.containsEsc;
  11367. node.property = this.parseIdentifier(true);
  11368. if (node.property.name !== propertyName || containsEsc) {
  11369. this.raise(Errors.UnsupportedMetaProperty, {
  11370. at: node.property,
  11371. target: meta.name,
  11372. onlyValidPropertyName: propertyName
  11373. });
  11374. }
  11375. return this.finishNode(node, "MetaProperty");
  11376. }
  11377. parseImportMetaProperty(node) {
  11378. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11379. this.next();
  11380. if (this.isContextual(100)) {
  11381. if (!this.inModule) {
  11382. this.raise(Errors.ImportMetaOutsideModule, {
  11383. at: id
  11384. });
  11385. }
  11386. this.sawUnambiguousESM = true;
  11387. }
  11388. return this.parseMetaProperty(node, id, "meta");
  11389. }
  11390. parseLiteralAtNode(value, type, node) {
  11391. this.addExtra(node, "rawValue", value);
  11392. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11393. node.value = value;
  11394. this.next();
  11395. return this.finishNode(node, type);
  11396. }
  11397. parseLiteral(value, type) {
  11398. const node = this.startNode();
  11399. return this.parseLiteralAtNode(value, type, node);
  11400. }
  11401. parseStringLiteral(value) {
  11402. return this.parseLiteral(value, "StringLiteral");
  11403. }
  11404. parseNumericLiteral(value) {
  11405. return this.parseLiteral(value, "NumericLiteral");
  11406. }
  11407. parseBigIntLiteral(value) {
  11408. return this.parseLiteral(value, "BigIntLiteral");
  11409. }
  11410. parseDecimalLiteral(value) {
  11411. return this.parseLiteral(value, "DecimalLiteral");
  11412. }
  11413. parseRegExpLiteral(value) {
  11414. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11415. node.pattern = value.pattern;
  11416. node.flags = value.flags;
  11417. return node;
  11418. }
  11419. parseBooleanLiteral(value) {
  11420. const node = this.startNode();
  11421. node.value = value;
  11422. this.next();
  11423. return this.finishNode(node, "BooleanLiteral");
  11424. }
  11425. parseNullLiteral() {
  11426. const node = this.startNode();
  11427. this.next();
  11428. return this.finishNode(node, "NullLiteral");
  11429. }
  11430. parseParenAndDistinguishExpression(canBeArrow) {
  11431. const startLoc = this.state.startLoc;
  11432. let val;
  11433. this.next();
  11434. this.expressionScope.enter(newArrowHeadScope());
  11435. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11436. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11437. this.state.maybeInArrowParameters = true;
  11438. this.state.inFSharpPipelineDirectBody = false;
  11439. const innerStartLoc = this.state.startLoc;
  11440. const exprList = [];
  11441. const refExpressionErrors = new ExpressionErrors();
  11442. let first = true;
  11443. let spreadStartLoc;
  11444. let optionalCommaStartLoc;
  11445. while (!this.match(11)) {
  11446. if (first) {
  11447. first = false;
  11448. } else {
  11449. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11450. if (this.match(11)) {
  11451. optionalCommaStartLoc = this.state.startLoc;
  11452. break;
  11453. }
  11454. }
  11455. if (this.match(21)) {
  11456. const spreadNodeStartLoc = this.state.startLoc;
  11457. spreadStartLoc = this.state.startLoc;
  11458. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11459. if (!this.checkCommaAfterRest(41)) {
  11460. break;
  11461. }
  11462. } else {
  11463. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11464. }
  11465. }
  11466. const innerEndLoc = this.state.lastTokEndLoc;
  11467. this.expect(11);
  11468. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11469. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11470. let arrowNode = this.startNodeAt(startLoc);
  11471. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11472. this.checkDestructuringPrivate(refExpressionErrors);
  11473. this.expressionScope.validateAsPattern();
  11474. this.expressionScope.exit();
  11475. this.parseArrowExpression(arrowNode, exprList, false);
  11476. return arrowNode;
  11477. }
  11478. this.expressionScope.exit();
  11479. if (!exprList.length) {
  11480. this.unexpected(this.state.lastTokStartLoc);
  11481. }
  11482. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11483. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11484. this.checkExpressionErrors(refExpressionErrors, true);
  11485. this.toReferencedListDeep(exprList, true);
  11486. if (exprList.length > 1) {
  11487. val = this.startNodeAt(innerStartLoc);
  11488. val.expressions = exprList;
  11489. this.finishNode(val, "SequenceExpression");
  11490. this.resetEndLocation(val, innerEndLoc);
  11491. } else {
  11492. val = exprList[0];
  11493. }
  11494. return this.wrapParenthesis(startLoc, val);
  11495. }
  11496. wrapParenthesis(startLoc, expression) {
  11497. if (!this.options.createParenthesizedExpressions) {
  11498. this.addExtra(expression, "parenthesized", true);
  11499. this.addExtra(expression, "parenStart", startLoc.index);
  11500. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11501. return expression;
  11502. }
  11503. const parenExpression = this.startNodeAt(startLoc);
  11504. parenExpression.expression = expression;
  11505. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11506. }
  11507. shouldParseArrow(params) {
  11508. return !this.canInsertSemicolon();
  11509. }
  11510. parseArrow(node) {
  11511. if (this.eat(19)) {
  11512. return node;
  11513. }
  11514. }
  11515. parseParenItem(node, startLoc) {
  11516. return node;
  11517. }
  11518. parseNewOrNewTarget() {
  11519. const node = this.startNode();
  11520. this.next();
  11521. if (this.match(16)) {
  11522. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11523. this.next();
  11524. const metaProp = this.parseMetaProperty(node, meta, "target");
  11525. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  11526. this.raise(Errors.UnexpectedNewTarget, {
  11527. at: metaProp
  11528. });
  11529. }
  11530. return metaProp;
  11531. }
  11532. return this.parseNew(node);
  11533. }
  11534. parseNew(node) {
  11535. this.parseNewCallee(node);
  11536. if (this.eat(10)) {
  11537. const args = this.parseExprList(11);
  11538. this.toReferencedList(args);
  11539. node.arguments = args;
  11540. } else {
  11541. node.arguments = [];
  11542. }
  11543. return this.finishNode(node, "NewExpression");
  11544. }
  11545. parseNewCallee(node) {
  11546. node.callee = this.parseNoCallExpr();
  11547. if (node.callee.type === "Import") {
  11548. this.raise(Errors.ImportCallNotNewExpression, {
  11549. at: node.callee
  11550. });
  11551. }
  11552. }
  11553. parseTemplateElement(isTagged) {
  11554. const {
  11555. start,
  11556. startLoc,
  11557. end,
  11558. value
  11559. } = this.state;
  11560. const elemStart = start + 1;
  11561. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11562. if (value === null) {
  11563. if (!isTagged) {
  11564. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  11565. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  11566. });
  11567. }
  11568. }
  11569. const isTail = this.match(24);
  11570. const endOffset = isTail ? -1 : -2;
  11571. const elemEnd = end + endOffset;
  11572. elem.value = {
  11573. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11574. cooked: value === null ? null : value.slice(1, endOffset)
  11575. };
  11576. elem.tail = isTail;
  11577. this.next();
  11578. const finishedNode = this.finishNode(elem, "TemplateElement");
  11579. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11580. return finishedNode;
  11581. }
  11582. parseTemplate(isTagged) {
  11583. const node = this.startNode();
  11584. node.expressions = [];
  11585. let curElt = this.parseTemplateElement(isTagged);
  11586. node.quasis = [curElt];
  11587. while (!curElt.tail) {
  11588. node.expressions.push(this.parseTemplateSubstitution());
  11589. this.readTemplateContinuation();
  11590. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  11591. }
  11592. return this.finishNode(node, "TemplateLiteral");
  11593. }
  11594. parseTemplateSubstitution() {
  11595. return this.parseExpression();
  11596. }
  11597. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11598. if (isRecord) {
  11599. this.expectPlugin("recordAndTuple");
  11600. }
  11601. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11602. this.state.inFSharpPipelineDirectBody = false;
  11603. const propHash = Object.create(null);
  11604. let first = true;
  11605. const node = this.startNode();
  11606. node.properties = [];
  11607. this.next();
  11608. while (!this.match(close)) {
  11609. if (first) {
  11610. first = false;
  11611. } else {
  11612. this.expect(12);
  11613. if (this.match(close)) {
  11614. this.addTrailingCommaExtraToNode(node);
  11615. break;
  11616. }
  11617. }
  11618. let prop;
  11619. if (isPattern) {
  11620. prop = this.parseBindingProperty();
  11621. } else {
  11622. prop = this.parsePropertyDefinition(refExpressionErrors);
  11623. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11624. }
  11625. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11626. this.raise(Errors.InvalidRecordProperty, {
  11627. at: prop
  11628. });
  11629. }
  11630. if (prop.shorthand) {
  11631. this.addExtra(prop, "shorthand", true);
  11632. }
  11633. node.properties.push(prop);
  11634. }
  11635. this.next();
  11636. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11637. let type = "ObjectExpression";
  11638. if (isPattern) {
  11639. type = "ObjectPattern";
  11640. } else if (isRecord) {
  11641. type = "RecordExpression";
  11642. }
  11643. return this.finishNode(node, type);
  11644. }
  11645. addTrailingCommaExtraToNode(node) {
  11646. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  11647. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11648. }
  11649. maybeAsyncOrAccessorProp(prop) {
  11650. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11651. }
  11652. parsePropertyDefinition(refExpressionErrors) {
  11653. let decorators = [];
  11654. if (this.match(26)) {
  11655. if (this.hasPlugin("decorators")) {
  11656. this.raise(Errors.UnsupportedPropertyDecorator, {
  11657. at: this.state.startLoc
  11658. });
  11659. }
  11660. while (this.match(26)) {
  11661. decorators.push(this.parseDecorator());
  11662. }
  11663. }
  11664. const prop = this.startNode();
  11665. let isAsync = false;
  11666. let isAccessor = false;
  11667. let startLoc;
  11668. if (this.match(21)) {
  11669. if (decorators.length) this.unexpected();
  11670. return this.parseSpread();
  11671. }
  11672. if (decorators.length) {
  11673. prop.decorators = decorators;
  11674. decorators = [];
  11675. }
  11676. prop.method = false;
  11677. if (refExpressionErrors) {
  11678. startLoc = this.state.startLoc;
  11679. }
  11680. let isGenerator = this.eat(55);
  11681. this.parsePropertyNamePrefixOperator(prop);
  11682. const containsEsc = this.state.containsEsc;
  11683. const key = this.parsePropertyName(prop, refExpressionErrors);
  11684. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11685. const keyName = key.name;
  11686. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11687. isAsync = true;
  11688. this.resetPreviousNodeTrailingComments(key);
  11689. isGenerator = this.eat(55);
  11690. this.parsePropertyName(prop);
  11691. }
  11692. if (keyName === "get" || keyName === "set") {
  11693. isAccessor = true;
  11694. this.resetPreviousNodeTrailingComments(key);
  11695. prop.kind = keyName;
  11696. if (this.match(55)) {
  11697. isGenerator = true;
  11698. this.raise(Errors.AccessorIsGenerator, {
  11699. at: this.state.curPosition(),
  11700. kind: keyName
  11701. });
  11702. this.next();
  11703. }
  11704. this.parsePropertyName(prop);
  11705. }
  11706. }
  11707. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11708. }
  11709. getGetterSetterExpectedParamCount(method) {
  11710. return method.kind === "get" ? 0 : 1;
  11711. }
  11712. getObjectOrClassMethodParams(method) {
  11713. return method.params;
  11714. }
  11715. checkGetterSetterParams(method) {
  11716. var _params;
  11717. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11718. const params = this.getObjectOrClassMethodParams(method);
  11719. if (params.length !== paramCount) {
  11720. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  11721. at: method
  11722. });
  11723. }
  11724. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11725. this.raise(Errors.BadSetterRestParameter, {
  11726. at: method
  11727. });
  11728. }
  11729. }
  11730. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11731. if (isAccessor) {
  11732. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11733. this.checkGetterSetterParams(finishedProp);
  11734. return finishedProp;
  11735. }
  11736. if (isAsync || isGenerator || this.match(10)) {
  11737. if (isPattern) this.unexpected();
  11738. prop.kind = "method";
  11739. prop.method = true;
  11740. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11741. }
  11742. }
  11743. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11744. prop.shorthand = false;
  11745. if (this.eat(14)) {
  11746. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11747. return this.finishNode(prop, "ObjectProperty");
  11748. }
  11749. if (!prop.computed && prop.key.type === "Identifier") {
  11750. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11751. if (isPattern) {
  11752. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11753. } else if (this.match(29)) {
  11754. const shorthandAssignLoc = this.state.startLoc;
  11755. if (refExpressionErrors != null) {
  11756. if (refExpressionErrors.shorthandAssignLoc === null) {
  11757. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11758. }
  11759. } else {
  11760. this.raise(Errors.InvalidCoverInitializedName, {
  11761. at: shorthandAssignLoc
  11762. });
  11763. }
  11764. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11765. } else {
  11766. prop.value = cloneIdentifier(prop.key);
  11767. }
  11768. prop.shorthand = true;
  11769. return this.finishNode(prop, "ObjectProperty");
  11770. }
  11771. }
  11772. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11773. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11774. if (!node) this.unexpected();
  11775. return node;
  11776. }
  11777. parsePropertyName(prop, refExpressionErrors) {
  11778. if (this.eat(0)) {
  11779. prop.computed = true;
  11780. prop.key = this.parseMaybeAssignAllowIn();
  11781. this.expect(3);
  11782. } else {
  11783. const {
  11784. type,
  11785. value
  11786. } = this.state;
  11787. let key;
  11788. if (tokenIsKeywordOrIdentifier(type)) {
  11789. key = this.parseIdentifier(true);
  11790. } else {
  11791. switch (type) {
  11792. case 132:
  11793. key = this.parseNumericLiteral(value);
  11794. break;
  11795. case 131:
  11796. key = this.parseStringLiteral(value);
  11797. break;
  11798. case 133:
  11799. key = this.parseBigIntLiteral(value);
  11800. break;
  11801. case 134:
  11802. key = this.parseDecimalLiteral(value);
  11803. break;
  11804. case 136:
  11805. {
  11806. const privateKeyLoc = this.state.startLoc;
  11807. if (refExpressionErrors != null) {
  11808. if (refExpressionErrors.privateKeyLoc === null) {
  11809. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11810. }
  11811. } else {
  11812. this.raise(Errors.UnexpectedPrivateField, {
  11813. at: privateKeyLoc
  11814. });
  11815. }
  11816. key = this.parsePrivateName();
  11817. break;
  11818. }
  11819. default:
  11820. this.unexpected();
  11821. }
  11822. }
  11823. prop.key = key;
  11824. if (type !== 136) {
  11825. prop.computed = false;
  11826. }
  11827. }
  11828. return prop.key;
  11829. }
  11830. initFunction(node, isAsync) {
  11831. node.id = null;
  11832. node.generator = false;
  11833. node.async = isAsync;
  11834. }
  11835. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11836. this.initFunction(node, isAsync);
  11837. node.generator = isGenerator;
  11838. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11839. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11840. this.parseFunctionParams(node, isConstructor);
  11841. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11842. this.prodParam.exit();
  11843. this.scope.exit();
  11844. return finishedNode;
  11845. }
  11846. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11847. if (isTuple) {
  11848. this.expectPlugin("recordAndTuple");
  11849. }
  11850. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11851. this.state.inFSharpPipelineDirectBody = false;
  11852. const node = this.startNode();
  11853. this.next();
  11854. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11855. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11856. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11857. }
  11858. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11859. this.scope.enter(2 | 4);
  11860. let flags = functionFlags(isAsync, false);
  11861. if (!this.match(5) && this.prodParam.hasIn) {
  11862. flags |= PARAM_IN;
  11863. }
  11864. this.prodParam.enter(flags);
  11865. this.initFunction(node, isAsync);
  11866. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11867. if (params) {
  11868. this.state.maybeInArrowParameters = true;
  11869. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11870. }
  11871. this.state.maybeInArrowParameters = false;
  11872. this.parseFunctionBody(node, true);
  11873. this.prodParam.exit();
  11874. this.scope.exit();
  11875. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11876. return this.finishNode(node, "ArrowFunctionExpression");
  11877. }
  11878. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11879. this.toAssignableList(params, trailingCommaLoc, false);
  11880. node.params = params;
  11881. }
  11882. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11883. this.parseFunctionBody(node, false, isMethod);
  11884. return this.finishNode(node, type);
  11885. }
  11886. parseFunctionBody(node, allowExpression, isMethod = false) {
  11887. const isExpression = allowExpression && !this.match(5);
  11888. this.expressionScope.enter(newExpressionScope());
  11889. if (isExpression) {
  11890. node.body = this.parseMaybeAssign();
  11891. this.checkParams(node, false, allowExpression, false);
  11892. } else {
  11893. const oldStrict = this.state.strict;
  11894. const oldLabels = this.state.labels;
  11895. this.state.labels = [];
  11896. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  11897. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11898. const nonSimple = !this.isSimpleParamList(node.params);
  11899. if (hasStrictModeDirective && nonSimple) {
  11900. this.raise(Errors.IllegalLanguageModeDirective, {
  11901. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  11902. });
  11903. }
  11904. const strictModeChanged = !oldStrict && this.state.strict;
  11905. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11906. if (this.state.strict && node.id) {
  11907. this.checkIdentifier(node.id, 65, strictModeChanged);
  11908. }
  11909. });
  11910. this.prodParam.exit();
  11911. this.state.labels = oldLabels;
  11912. }
  11913. this.expressionScope.exit();
  11914. }
  11915. isSimpleParameter(node) {
  11916. return node.type === "Identifier";
  11917. }
  11918. isSimpleParamList(params) {
  11919. for (let i = 0, len = params.length; i < len; i++) {
  11920. if (!this.isSimpleParameter(params[i])) return false;
  11921. }
  11922. return true;
  11923. }
  11924. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11925. const checkClashes = !allowDuplicates && new Set();
  11926. const formalParameters = {
  11927. type: "FormalParameters"
  11928. };
  11929. for (const param of node.params) {
  11930. this.checkLVal(param, {
  11931. in: formalParameters,
  11932. binding: 5,
  11933. checkClashes,
  11934. strictModeChanged
  11935. });
  11936. }
  11937. }
  11938. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11939. const elts = [];
  11940. let first = true;
  11941. while (!this.eat(close)) {
  11942. if (first) {
  11943. first = false;
  11944. } else {
  11945. this.expect(12);
  11946. if (this.match(close)) {
  11947. if (nodeForExtra) {
  11948. this.addTrailingCommaExtraToNode(nodeForExtra);
  11949. }
  11950. this.next();
  11951. break;
  11952. }
  11953. }
  11954. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11955. }
  11956. return elts;
  11957. }
  11958. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  11959. let elt;
  11960. if (this.match(12)) {
  11961. if (!allowEmpty) {
  11962. this.raise(Errors.UnexpectedToken, {
  11963. at: this.state.curPosition(),
  11964. unexpected: ","
  11965. });
  11966. }
  11967. elt = null;
  11968. } else if (this.match(21)) {
  11969. const spreadNodeStartLoc = this.state.startLoc;
  11970. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  11971. } else if (this.match(17)) {
  11972. this.expectPlugin("partialApplication");
  11973. if (!allowPlaceholder) {
  11974. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  11975. at: this.state.startLoc
  11976. });
  11977. }
  11978. const node = this.startNode();
  11979. this.next();
  11980. elt = this.finishNode(node, "ArgumentPlaceholder");
  11981. } else {
  11982. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  11983. }
  11984. return elt;
  11985. }
  11986. parseIdentifier(liberal) {
  11987. const node = this.startNode();
  11988. const name = this.parseIdentifierName(liberal);
  11989. return this.createIdentifier(node, name);
  11990. }
  11991. createIdentifier(node, name) {
  11992. node.name = name;
  11993. node.loc.identifierName = name;
  11994. return this.finishNode(node, "Identifier");
  11995. }
  11996. parseIdentifierName(liberal) {
  11997. let name;
  11998. const {
  11999. startLoc,
  12000. type
  12001. } = this.state;
  12002. if (tokenIsKeywordOrIdentifier(type)) {
  12003. name = this.state.value;
  12004. } else {
  12005. this.unexpected();
  12006. }
  12007. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12008. if (liberal) {
  12009. if (tokenIsKeyword) {
  12010. this.replaceToken(130);
  12011. }
  12012. } else {
  12013. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12014. }
  12015. this.next();
  12016. return name;
  12017. }
  12018. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12019. if (word.length > 10) {
  12020. return;
  12021. }
  12022. if (!canBeReservedWord(word)) {
  12023. return;
  12024. }
  12025. if (checkKeywords && isKeyword(word)) {
  12026. this.raise(Errors.UnexpectedKeyword, {
  12027. at: startLoc,
  12028. keyword: word
  12029. });
  12030. return;
  12031. }
  12032. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12033. if (reservedTest(word, this.inModule)) {
  12034. this.raise(Errors.UnexpectedReservedWord, {
  12035. at: startLoc,
  12036. reservedWord: word
  12037. });
  12038. return;
  12039. } else if (word === "yield") {
  12040. if (this.prodParam.hasYield) {
  12041. this.raise(Errors.YieldBindingIdentifier, {
  12042. at: startLoc
  12043. });
  12044. return;
  12045. }
  12046. } else if (word === "await") {
  12047. if (this.prodParam.hasAwait) {
  12048. this.raise(Errors.AwaitBindingIdentifier, {
  12049. at: startLoc
  12050. });
  12051. return;
  12052. }
  12053. if (this.scope.inStaticBlock) {
  12054. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12055. at: startLoc
  12056. });
  12057. return;
  12058. }
  12059. this.expressionScope.recordAsyncArrowParametersError({
  12060. at: startLoc
  12061. });
  12062. } else if (word === "arguments") {
  12063. if (this.scope.inClassAndNotInNonArrowFunction) {
  12064. this.raise(Errors.ArgumentsInClass, {
  12065. at: startLoc
  12066. });
  12067. return;
  12068. }
  12069. }
  12070. }
  12071. isAwaitAllowed() {
  12072. if (this.prodParam.hasAwait) return true;
  12073. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12074. return true;
  12075. }
  12076. return false;
  12077. }
  12078. parseAwait(startLoc) {
  12079. const node = this.startNodeAt(startLoc);
  12080. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12081. at: node
  12082. });
  12083. if (this.eat(55)) {
  12084. this.raise(Errors.ObsoleteAwaitStar, {
  12085. at: node
  12086. });
  12087. }
  12088. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12089. if (this.isAmbiguousAwait()) {
  12090. this.ambiguousScriptDifferentAst = true;
  12091. } else {
  12092. this.sawUnambiguousESM = true;
  12093. }
  12094. }
  12095. if (!this.state.soloAwait) {
  12096. node.argument = this.parseMaybeUnary(null, true);
  12097. }
  12098. return this.finishNode(node, "AwaitExpression");
  12099. }
  12100. isAmbiguousAwait() {
  12101. if (this.hasPrecedingLineBreak()) return true;
  12102. const {
  12103. type
  12104. } = this.state;
  12105. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 101 && !this.state.containsEsc || type === 135 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12106. }
  12107. parseYield() {
  12108. const node = this.startNode();
  12109. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12110. at: node
  12111. });
  12112. this.next();
  12113. let delegating = false;
  12114. let argument = null;
  12115. if (!this.hasPrecedingLineBreak()) {
  12116. delegating = this.eat(55);
  12117. switch (this.state.type) {
  12118. case 13:
  12119. case 137:
  12120. case 8:
  12121. case 11:
  12122. case 3:
  12123. case 9:
  12124. case 14:
  12125. case 12:
  12126. if (!delegating) break;
  12127. default:
  12128. argument = this.parseMaybeAssign();
  12129. }
  12130. }
  12131. node.delegate = delegating;
  12132. node.argument = argument;
  12133. return this.finishNode(node, "YieldExpression");
  12134. }
  12135. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12136. if (this.hasPlugin(["pipelineOperator", {
  12137. proposal: "smart"
  12138. }])) {
  12139. if (left.type === "SequenceExpression") {
  12140. this.raise(Errors.PipelineHeadSequenceExpression, {
  12141. at: leftStartLoc
  12142. });
  12143. }
  12144. }
  12145. }
  12146. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12147. if (this.isSimpleReference(childExpr)) {
  12148. const bodyNode = this.startNodeAt(startLoc);
  12149. bodyNode.callee = childExpr;
  12150. return this.finishNode(bodyNode, "PipelineBareFunction");
  12151. } else {
  12152. const bodyNode = this.startNodeAt(startLoc);
  12153. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12154. bodyNode.expression = childExpr;
  12155. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12156. }
  12157. }
  12158. isSimpleReference(expression) {
  12159. switch (expression.type) {
  12160. case "MemberExpression":
  12161. return !expression.computed && this.isSimpleReference(expression.object);
  12162. case "Identifier":
  12163. return true;
  12164. default:
  12165. return false;
  12166. }
  12167. }
  12168. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12169. if (this.match(19)) {
  12170. throw this.raise(Errors.PipelineBodyNoArrow, {
  12171. at: this.state.startLoc
  12172. });
  12173. }
  12174. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12175. this.raise(Errors.PipelineTopicUnused, {
  12176. at: startLoc
  12177. });
  12178. }
  12179. }
  12180. withTopicBindingContext(callback) {
  12181. const outerContextTopicState = this.state.topicContext;
  12182. this.state.topicContext = {
  12183. maxNumOfResolvableTopics: 1,
  12184. maxTopicIndex: null
  12185. };
  12186. try {
  12187. return callback();
  12188. } finally {
  12189. this.state.topicContext = outerContextTopicState;
  12190. }
  12191. }
  12192. withSmartMixTopicForbiddingContext(callback) {
  12193. if (this.hasPlugin(["pipelineOperator", {
  12194. proposal: "smart"
  12195. }])) {
  12196. const outerContextTopicState = this.state.topicContext;
  12197. this.state.topicContext = {
  12198. maxNumOfResolvableTopics: 0,
  12199. maxTopicIndex: null
  12200. };
  12201. try {
  12202. return callback();
  12203. } finally {
  12204. this.state.topicContext = outerContextTopicState;
  12205. }
  12206. } else {
  12207. return callback();
  12208. }
  12209. }
  12210. withSoloAwaitPermittingContext(callback) {
  12211. const outerContextSoloAwaitState = this.state.soloAwait;
  12212. this.state.soloAwait = true;
  12213. try {
  12214. return callback();
  12215. } finally {
  12216. this.state.soloAwait = outerContextSoloAwaitState;
  12217. }
  12218. }
  12219. allowInAnd(callback) {
  12220. const flags = this.prodParam.currentFlags();
  12221. const prodParamToSet = PARAM_IN & ~flags;
  12222. if (prodParamToSet) {
  12223. this.prodParam.enter(flags | PARAM_IN);
  12224. try {
  12225. return callback();
  12226. } finally {
  12227. this.prodParam.exit();
  12228. }
  12229. }
  12230. return callback();
  12231. }
  12232. disallowInAnd(callback) {
  12233. const flags = this.prodParam.currentFlags();
  12234. const prodParamToClear = PARAM_IN & flags;
  12235. if (prodParamToClear) {
  12236. this.prodParam.enter(flags & ~PARAM_IN);
  12237. try {
  12238. return callback();
  12239. } finally {
  12240. this.prodParam.exit();
  12241. }
  12242. }
  12243. return callback();
  12244. }
  12245. registerTopicReference() {
  12246. this.state.topicContext.maxTopicIndex = 0;
  12247. }
  12248. topicReferenceIsAllowedInCurrentContext() {
  12249. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12250. }
  12251. topicReferenceWasUsedInCurrentContext() {
  12252. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12253. }
  12254. parseFSharpPipelineBody(prec) {
  12255. const startLoc = this.state.startLoc;
  12256. this.state.potentialArrowAt = this.state.start;
  12257. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12258. this.state.inFSharpPipelineDirectBody = true;
  12259. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12260. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12261. return ret;
  12262. }
  12263. parseModuleExpression() {
  12264. this.expectPlugin("moduleBlocks");
  12265. const node = this.startNode();
  12266. this.next();
  12267. if (!this.match(5)) {
  12268. this.unexpected(null, 5);
  12269. }
  12270. const program = this.startNodeAt(this.state.endLoc);
  12271. this.next();
  12272. const revertScopes = this.initializeScopes(true);
  12273. this.enterInitialScopes();
  12274. try {
  12275. node.body = this.parseProgram(program, 8, "module");
  12276. } finally {
  12277. revertScopes();
  12278. }
  12279. return this.finishNode(node, "ModuleExpression");
  12280. }
  12281. parsePropertyNamePrefixOperator(prop) {}
  12282. }
  12283. const loopLabel = {
  12284. kind: "loop"
  12285. },
  12286. switchLabel = {
  12287. kind: "switch"
  12288. };
  12289. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12290. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12291. function babel7CompatTokens(tokens, input) {
  12292. for (let i = 0; i < tokens.length; i++) {
  12293. const token = tokens[i];
  12294. const {
  12295. type
  12296. } = token;
  12297. if (typeof type === "number") {
  12298. {
  12299. if (type === 136) {
  12300. const {
  12301. loc,
  12302. start,
  12303. value,
  12304. end
  12305. } = token;
  12306. const hashEndPos = start + 1;
  12307. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12308. tokens.splice(i, 1, new Token({
  12309. type: getExportedToken(27),
  12310. value: "#",
  12311. start: start,
  12312. end: hashEndPos,
  12313. startLoc: loc.start,
  12314. endLoc: hashEndLoc
  12315. }), new Token({
  12316. type: getExportedToken(130),
  12317. value: value,
  12318. start: hashEndPos,
  12319. end: end,
  12320. startLoc: hashEndLoc,
  12321. endLoc: loc.end
  12322. }));
  12323. i++;
  12324. continue;
  12325. }
  12326. if (tokenIsTemplate(type)) {
  12327. const {
  12328. loc,
  12329. start,
  12330. value,
  12331. end
  12332. } = token;
  12333. const backquoteEnd = start + 1;
  12334. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12335. let startToken;
  12336. if (input.charCodeAt(start) === 96) {
  12337. startToken = new Token({
  12338. type: getExportedToken(22),
  12339. value: "`",
  12340. start: start,
  12341. end: backquoteEnd,
  12342. startLoc: loc.start,
  12343. endLoc: backquoteEndLoc
  12344. });
  12345. } else {
  12346. startToken = new Token({
  12347. type: getExportedToken(8),
  12348. value: "}",
  12349. start: start,
  12350. end: backquoteEnd,
  12351. startLoc: loc.start,
  12352. endLoc: backquoteEndLoc
  12353. });
  12354. }
  12355. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12356. if (type === 24) {
  12357. templateElementEnd = end - 1;
  12358. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12359. templateValue = value === null ? null : value.slice(1, -1);
  12360. endToken = new Token({
  12361. type: getExportedToken(22),
  12362. value: "`",
  12363. start: templateElementEnd,
  12364. end: end,
  12365. startLoc: templateElementEndLoc,
  12366. endLoc: loc.end
  12367. });
  12368. } else {
  12369. templateElementEnd = end - 2;
  12370. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12371. templateValue = value === null ? null : value.slice(1, -2);
  12372. endToken = new Token({
  12373. type: getExportedToken(23),
  12374. value: "${",
  12375. start: templateElementEnd,
  12376. end: end,
  12377. startLoc: templateElementEndLoc,
  12378. endLoc: loc.end
  12379. });
  12380. }
  12381. tokens.splice(i, 1, startToken, new Token({
  12382. type: getExportedToken(20),
  12383. value: templateValue,
  12384. start: backquoteEnd,
  12385. end: templateElementEnd,
  12386. startLoc: backquoteEndLoc,
  12387. endLoc: templateElementEndLoc
  12388. }), endToken);
  12389. i += 2;
  12390. continue;
  12391. }
  12392. }
  12393. token.type = getExportedToken(type);
  12394. }
  12395. }
  12396. return tokens;
  12397. }
  12398. class StatementParser extends ExpressionParser {
  12399. parseTopLevel(file, program) {
  12400. file.program = this.parseProgram(program);
  12401. file.comments = this.state.comments;
  12402. if (this.options.tokens) {
  12403. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12404. }
  12405. return this.finishNode(file, "File");
  12406. }
  12407. parseProgram(program, end = 137, sourceType = this.options.sourceType) {
  12408. program.sourceType = sourceType;
  12409. program.interpreter = this.parseInterpreterDirective();
  12410. this.parseBlockBody(program, true, true, end);
  12411. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12412. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12413. this.raise(Errors.ModuleExportUndefined, {
  12414. at,
  12415. localName
  12416. });
  12417. }
  12418. }
  12419. let finishedProgram;
  12420. if (end === 137) {
  12421. finishedProgram = this.finishNode(program, "Program");
  12422. } else {
  12423. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12424. }
  12425. return finishedProgram;
  12426. }
  12427. stmtToDirective(stmt) {
  12428. const directive = stmt;
  12429. directive.type = "Directive";
  12430. directive.value = directive.expression;
  12431. delete directive.expression;
  12432. const directiveLiteral = directive.value;
  12433. const expressionValue = directiveLiteral.value;
  12434. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12435. const val = directiveLiteral.value = raw.slice(1, -1);
  12436. this.addExtra(directiveLiteral, "raw", raw);
  12437. this.addExtra(directiveLiteral, "rawValue", val);
  12438. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12439. directiveLiteral.type = "DirectiveLiteral";
  12440. return directive;
  12441. }
  12442. parseInterpreterDirective() {
  12443. if (!this.match(28)) {
  12444. return null;
  12445. }
  12446. const node = this.startNode();
  12447. node.value = this.state.value;
  12448. this.next();
  12449. return this.finishNode(node, "InterpreterDirective");
  12450. }
  12451. isLet() {
  12452. if (!this.isContextual(99)) {
  12453. return false;
  12454. }
  12455. return this.hasFollowingBindingAtom();
  12456. }
  12457. chStartsBindingIdentifier(ch, pos) {
  12458. if (isIdentifierStart(ch)) {
  12459. keywordRelationalOperator.lastIndex = pos;
  12460. if (keywordRelationalOperator.test(this.input)) {
  12461. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12462. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12463. return false;
  12464. }
  12465. }
  12466. return true;
  12467. } else if (ch === 92) {
  12468. return true;
  12469. } else {
  12470. return false;
  12471. }
  12472. }
  12473. chStartsBindingPattern(ch) {
  12474. return ch === 91 || ch === 123;
  12475. }
  12476. hasFollowingBindingAtom() {
  12477. const next = this.nextTokenStart();
  12478. const nextCh = this.codePointAtPos(next);
  12479. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12480. }
  12481. hasInLineFollowingBindingIdentifier() {
  12482. const next = this.nextTokenInLineStart();
  12483. const nextCh = this.codePointAtPos(next);
  12484. return this.chStartsBindingIdentifier(nextCh, next);
  12485. }
  12486. startsUsingForOf() {
  12487. const {
  12488. type,
  12489. containsEsc
  12490. } = this.lookahead();
  12491. if (type === 101 && !containsEsc) {
  12492. return false;
  12493. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12494. this.expectPlugin("explicitResourceManagement");
  12495. return true;
  12496. }
  12497. }
  12498. startsAwaitUsing() {
  12499. let next = this.nextTokenInLineStart();
  12500. if (this.isUnparsedContextual(next, "using")) {
  12501. next = this.nextTokenInLineStartSince(next + 5);
  12502. const nextCh = this.codePointAtPos(next);
  12503. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12504. this.expectPlugin("explicitResourceManagement");
  12505. return true;
  12506. }
  12507. }
  12508. return false;
  12509. }
  12510. parseModuleItem() {
  12511. return this.parseStatementLike(1 | 2 | 4 | 8);
  12512. }
  12513. parseStatementListItem() {
  12514. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12515. }
  12516. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12517. let flags = 0;
  12518. if (this.options.annexB && !this.state.strict) {
  12519. flags |= 4;
  12520. if (allowLabeledFunction) {
  12521. flags |= 8;
  12522. }
  12523. }
  12524. return this.parseStatementLike(flags);
  12525. }
  12526. parseStatement() {
  12527. return this.parseStatementLike(0);
  12528. }
  12529. parseStatementLike(flags) {
  12530. let decorators = null;
  12531. if (this.match(26)) {
  12532. decorators = this.parseDecorators(true);
  12533. }
  12534. return this.parseStatementContent(flags, decorators);
  12535. }
  12536. parseStatementContent(flags, decorators) {
  12537. const starttype = this.state.type;
  12538. const node = this.startNode();
  12539. const allowDeclaration = !!(flags & 2);
  12540. const allowFunctionDeclaration = !!(flags & 4);
  12541. const topLevel = flags & 1;
  12542. switch (starttype) {
  12543. case 60:
  12544. return this.parseBreakContinueStatement(node, true);
  12545. case 63:
  12546. return this.parseBreakContinueStatement(node, false);
  12547. case 64:
  12548. return this.parseDebuggerStatement(node);
  12549. case 90:
  12550. return this.parseDoWhileStatement(node);
  12551. case 91:
  12552. return this.parseForStatement(node);
  12553. case 68:
  12554. if (this.lookaheadCharCode() === 46) break;
  12555. if (!allowFunctionDeclaration) {
  12556. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
  12557. at: this.state.startLoc
  12558. });
  12559. }
  12560. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12561. case 80:
  12562. if (!allowDeclaration) this.unexpected();
  12563. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12564. case 69:
  12565. return this.parseIfStatement(node);
  12566. case 70:
  12567. return this.parseReturnStatement(node);
  12568. case 71:
  12569. return this.parseSwitchStatement(node);
  12570. case 72:
  12571. return this.parseThrowStatement(node);
  12572. case 73:
  12573. return this.parseTryStatement(node);
  12574. case 96:
  12575. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12576. if (!this.isAwaitAllowed()) {
  12577. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12578. at: node
  12579. });
  12580. } else if (!allowDeclaration) {
  12581. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12582. at: node
  12583. });
  12584. }
  12585. this.next();
  12586. return this.parseVarStatement(node, "await using");
  12587. }
  12588. break;
  12589. case 105:
  12590. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
  12591. break;
  12592. }
  12593. this.expectPlugin("explicitResourceManagement");
  12594. if (!this.scope.inModule && this.scope.inTopLevel) {
  12595. this.raise(Errors.UnexpectedUsingDeclaration, {
  12596. at: this.state.startLoc
  12597. });
  12598. } else if (!allowDeclaration) {
  12599. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12600. at: this.state.startLoc
  12601. });
  12602. }
  12603. return this.parseVarStatement(node, "using");
  12604. case 99:
  12605. {
  12606. if (this.state.containsEsc) {
  12607. break;
  12608. }
  12609. const next = this.nextTokenStart();
  12610. const nextCh = this.codePointAtPos(next);
  12611. if (nextCh !== 91) {
  12612. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12613. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12614. break;
  12615. }
  12616. }
  12617. }
  12618. case 75:
  12619. {
  12620. if (!allowDeclaration) {
  12621. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12622. at: this.state.startLoc
  12623. });
  12624. }
  12625. }
  12626. case 74:
  12627. {
  12628. const kind = this.state.value;
  12629. return this.parseVarStatement(node, kind);
  12630. }
  12631. case 92:
  12632. return this.parseWhileStatement(node);
  12633. case 76:
  12634. return this.parseWithStatement(node);
  12635. case 5:
  12636. return this.parseBlock();
  12637. case 13:
  12638. return this.parseEmptyStatement(node);
  12639. case 83:
  12640. {
  12641. const nextTokenCharCode = this.lookaheadCharCode();
  12642. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12643. break;
  12644. }
  12645. }
  12646. case 82:
  12647. {
  12648. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12649. this.raise(Errors.UnexpectedImportExport, {
  12650. at: this.state.startLoc
  12651. });
  12652. }
  12653. this.next();
  12654. let result;
  12655. if (starttype === 83) {
  12656. result = this.parseImport(node);
  12657. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12658. this.sawUnambiguousESM = true;
  12659. }
  12660. } else {
  12661. result = this.parseExport(node, decorators);
  12662. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12663. this.sawUnambiguousESM = true;
  12664. }
  12665. }
  12666. this.assertModuleNodeAllowed(result);
  12667. return result;
  12668. }
  12669. default:
  12670. {
  12671. if (this.isAsyncFunction()) {
  12672. if (!allowDeclaration) {
  12673. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  12674. at: this.state.startLoc
  12675. });
  12676. }
  12677. this.next();
  12678. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12679. }
  12680. }
  12681. }
  12682. const maybeName = this.state.value;
  12683. const expr = this.parseExpression();
  12684. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12685. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12686. } else {
  12687. return this.parseExpressionStatement(node, expr, decorators);
  12688. }
  12689. }
  12690. assertModuleNodeAllowed(node) {
  12691. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12692. this.raise(Errors.ImportOutsideModule, {
  12693. at: node
  12694. });
  12695. }
  12696. }
  12697. decoratorsEnabledBeforeExport() {
  12698. if (this.hasPlugin("decorators-legacy")) return true;
  12699. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12700. }
  12701. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12702. if (maybeDecorators) {
  12703. if (classNode.decorators && classNode.decorators.length > 0) {
  12704. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12705. this.raise(Errors.DecoratorsBeforeAfterExport, {
  12706. at: classNode.decorators[0]
  12707. });
  12708. }
  12709. classNode.decorators.unshift(...maybeDecorators);
  12710. } else {
  12711. classNode.decorators = maybeDecorators;
  12712. }
  12713. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12714. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12715. }
  12716. return classNode;
  12717. }
  12718. canHaveLeadingDecorator() {
  12719. return this.match(80);
  12720. }
  12721. parseDecorators(allowExport) {
  12722. const decorators = [];
  12723. do {
  12724. decorators.push(this.parseDecorator());
  12725. } while (this.match(26));
  12726. if (this.match(82)) {
  12727. if (!allowExport) {
  12728. this.unexpected();
  12729. }
  12730. if (!this.decoratorsEnabledBeforeExport()) {
  12731. this.raise(Errors.DecoratorExportClass, {
  12732. at: this.state.startLoc
  12733. });
  12734. }
  12735. } else if (!this.canHaveLeadingDecorator()) {
  12736. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  12737. at: this.state.startLoc
  12738. });
  12739. }
  12740. return decorators;
  12741. }
  12742. parseDecorator() {
  12743. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12744. const node = this.startNode();
  12745. this.next();
  12746. if (this.hasPlugin("decorators")) {
  12747. const startLoc = this.state.startLoc;
  12748. let expr;
  12749. if (this.match(10)) {
  12750. const startLoc = this.state.startLoc;
  12751. this.next();
  12752. expr = this.parseExpression();
  12753. this.expect(11);
  12754. expr = this.wrapParenthesis(startLoc, expr);
  12755. const paramsStartLoc = this.state.startLoc;
  12756. node.expression = this.parseMaybeDecoratorArguments(expr);
  12757. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12758. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  12759. at: paramsStartLoc
  12760. });
  12761. }
  12762. } else {
  12763. expr = this.parseIdentifier(false);
  12764. while (this.eat(16)) {
  12765. const node = this.startNodeAt(startLoc);
  12766. node.object = expr;
  12767. if (this.match(136)) {
  12768. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12769. node.property = this.parsePrivateName();
  12770. } else {
  12771. node.property = this.parseIdentifier(true);
  12772. }
  12773. node.computed = false;
  12774. expr = this.finishNode(node, "MemberExpression");
  12775. }
  12776. node.expression = this.parseMaybeDecoratorArguments(expr);
  12777. }
  12778. } else {
  12779. node.expression = this.parseExprSubscripts();
  12780. }
  12781. return this.finishNode(node, "Decorator");
  12782. }
  12783. parseMaybeDecoratorArguments(expr) {
  12784. if (this.eat(10)) {
  12785. const node = this.startNodeAtNode(expr);
  12786. node.callee = expr;
  12787. node.arguments = this.parseCallExpressionArguments(11, false);
  12788. this.toReferencedList(node.arguments);
  12789. return this.finishNode(node, "CallExpression");
  12790. }
  12791. return expr;
  12792. }
  12793. parseBreakContinueStatement(node, isBreak) {
  12794. this.next();
  12795. if (this.isLineTerminator()) {
  12796. node.label = null;
  12797. } else {
  12798. node.label = this.parseIdentifier();
  12799. this.semicolon();
  12800. }
  12801. this.verifyBreakContinue(node, isBreak);
  12802. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12803. }
  12804. verifyBreakContinue(node, isBreak) {
  12805. let i;
  12806. for (i = 0; i < this.state.labels.length; ++i) {
  12807. const lab = this.state.labels[i];
  12808. if (node.label == null || lab.name === node.label.name) {
  12809. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  12810. if (node.label && isBreak) break;
  12811. }
  12812. }
  12813. if (i === this.state.labels.length) {
  12814. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12815. this.raise(Errors.IllegalBreakContinue, {
  12816. at: node,
  12817. type
  12818. });
  12819. }
  12820. }
  12821. parseDebuggerStatement(node) {
  12822. this.next();
  12823. this.semicolon();
  12824. return this.finishNode(node, "DebuggerStatement");
  12825. }
  12826. parseHeaderExpression() {
  12827. this.expect(10);
  12828. const val = this.parseExpression();
  12829. this.expect(11);
  12830. return val;
  12831. }
  12832. parseDoWhileStatement(node) {
  12833. this.next();
  12834. this.state.labels.push(loopLabel);
  12835. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12836. this.state.labels.pop();
  12837. this.expect(92);
  12838. node.test = this.parseHeaderExpression();
  12839. this.eat(13);
  12840. return this.finishNode(node, "DoWhileStatement");
  12841. }
  12842. parseForStatement(node) {
  12843. this.next();
  12844. this.state.labels.push(loopLabel);
  12845. let awaitAt = null;
  12846. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12847. awaitAt = this.state.lastTokStartLoc;
  12848. }
  12849. this.scope.enter(0);
  12850. this.expect(10);
  12851. if (this.match(13)) {
  12852. if (awaitAt !== null) {
  12853. this.unexpected(awaitAt);
  12854. }
  12855. return this.parseFor(node, null);
  12856. }
  12857. const startsWithLet = this.isContextual(99);
  12858. {
  12859. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12860. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(105) && this.startsUsingForOf();
  12861. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12862. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12863. const initNode = this.startNode();
  12864. let kind;
  12865. if (startsWithAwaitUsing) {
  12866. kind = "await using";
  12867. if (!this.isAwaitAllowed()) {
  12868. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12869. at: this.state.startLoc
  12870. });
  12871. }
  12872. this.next();
  12873. } else {
  12874. kind = this.state.value;
  12875. }
  12876. this.next();
  12877. this.parseVar(initNode, true, kind);
  12878. const init = this.finishNode(initNode, "VariableDeclaration");
  12879. const isForIn = this.match(58);
  12880. if (isForIn && starsWithUsingDeclaration) {
  12881. this.raise(Errors.ForInUsing, {
  12882. at: init
  12883. });
  12884. }
  12885. if ((isForIn || this.isContextual(101)) && init.declarations.length === 1) {
  12886. return this.parseForIn(node, init, awaitAt);
  12887. }
  12888. if (awaitAt !== null) {
  12889. this.unexpected(awaitAt);
  12890. }
  12891. return this.parseFor(node, init);
  12892. }
  12893. }
  12894. const startsWithAsync = this.isContextual(95);
  12895. const refExpressionErrors = new ExpressionErrors();
  12896. const init = this.parseExpression(true, refExpressionErrors);
  12897. const isForOf = this.isContextual(101);
  12898. if (isForOf) {
  12899. if (startsWithLet) {
  12900. this.raise(Errors.ForOfLet, {
  12901. at: init
  12902. });
  12903. }
  12904. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12905. this.raise(Errors.ForOfAsync, {
  12906. at: init
  12907. });
  12908. }
  12909. }
  12910. if (isForOf || this.match(58)) {
  12911. this.checkDestructuringPrivate(refExpressionErrors);
  12912. this.toAssignable(init, true);
  12913. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12914. this.checkLVal(init, {
  12915. in: {
  12916. type
  12917. }
  12918. });
  12919. return this.parseForIn(node, init, awaitAt);
  12920. } else {
  12921. this.checkExpressionErrors(refExpressionErrors, true);
  12922. }
  12923. if (awaitAt !== null) {
  12924. this.unexpected(awaitAt);
  12925. }
  12926. return this.parseFor(node, init);
  12927. }
  12928. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12929. this.next();
  12930. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12931. }
  12932. parseIfStatement(node) {
  12933. this.next();
  12934. node.test = this.parseHeaderExpression();
  12935. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12936. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12937. return this.finishNode(node, "IfStatement");
  12938. }
  12939. parseReturnStatement(node) {
  12940. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12941. this.raise(Errors.IllegalReturn, {
  12942. at: this.state.startLoc
  12943. });
  12944. }
  12945. this.next();
  12946. if (this.isLineTerminator()) {
  12947. node.argument = null;
  12948. } else {
  12949. node.argument = this.parseExpression();
  12950. this.semicolon();
  12951. }
  12952. return this.finishNode(node, "ReturnStatement");
  12953. }
  12954. parseSwitchStatement(node) {
  12955. this.next();
  12956. node.discriminant = this.parseHeaderExpression();
  12957. const cases = node.cases = [];
  12958. this.expect(5);
  12959. this.state.labels.push(switchLabel);
  12960. this.scope.enter(0);
  12961. let cur;
  12962. for (let sawDefault; !this.match(8);) {
  12963. if (this.match(61) || this.match(65)) {
  12964. const isCase = this.match(61);
  12965. if (cur) this.finishNode(cur, "SwitchCase");
  12966. cases.push(cur = this.startNode());
  12967. cur.consequent = [];
  12968. this.next();
  12969. if (isCase) {
  12970. cur.test = this.parseExpression();
  12971. } else {
  12972. if (sawDefault) {
  12973. this.raise(Errors.MultipleDefaultsInSwitch, {
  12974. at: this.state.lastTokStartLoc
  12975. });
  12976. }
  12977. sawDefault = true;
  12978. cur.test = null;
  12979. }
  12980. this.expect(14);
  12981. } else {
  12982. if (cur) {
  12983. cur.consequent.push(this.parseStatementListItem());
  12984. } else {
  12985. this.unexpected();
  12986. }
  12987. }
  12988. }
  12989. this.scope.exit();
  12990. if (cur) this.finishNode(cur, "SwitchCase");
  12991. this.next();
  12992. this.state.labels.pop();
  12993. return this.finishNode(node, "SwitchStatement");
  12994. }
  12995. parseThrowStatement(node) {
  12996. this.next();
  12997. if (this.hasPrecedingLineBreak()) {
  12998. this.raise(Errors.NewlineAfterThrow, {
  12999. at: this.state.lastTokEndLoc
  13000. });
  13001. }
  13002. node.argument = this.parseExpression();
  13003. this.semicolon();
  13004. return this.finishNode(node, "ThrowStatement");
  13005. }
  13006. parseCatchClauseParam() {
  13007. const param = this.parseBindingAtom();
  13008. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13009. this.checkLVal(param, {
  13010. in: {
  13011. type: "CatchClause"
  13012. },
  13013. binding: 9
  13014. });
  13015. return param;
  13016. }
  13017. parseTryStatement(node) {
  13018. this.next();
  13019. node.block = this.parseBlock();
  13020. node.handler = null;
  13021. if (this.match(62)) {
  13022. const clause = this.startNode();
  13023. this.next();
  13024. if (this.match(10)) {
  13025. this.expect(10);
  13026. clause.param = this.parseCatchClauseParam();
  13027. this.expect(11);
  13028. } else {
  13029. clause.param = null;
  13030. this.scope.enter(0);
  13031. }
  13032. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13033. this.scope.exit();
  13034. node.handler = this.finishNode(clause, "CatchClause");
  13035. }
  13036. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13037. if (!node.handler && !node.finalizer) {
  13038. this.raise(Errors.NoCatchOrFinally, {
  13039. at: node
  13040. });
  13041. }
  13042. return this.finishNode(node, "TryStatement");
  13043. }
  13044. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13045. this.next();
  13046. this.parseVar(node, false, kind, allowMissingInitializer);
  13047. this.semicolon();
  13048. return this.finishNode(node, "VariableDeclaration");
  13049. }
  13050. parseWhileStatement(node) {
  13051. this.next();
  13052. node.test = this.parseHeaderExpression();
  13053. this.state.labels.push(loopLabel);
  13054. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13055. this.state.labels.pop();
  13056. return this.finishNode(node, "WhileStatement");
  13057. }
  13058. parseWithStatement(node) {
  13059. if (this.state.strict) {
  13060. this.raise(Errors.StrictWith, {
  13061. at: this.state.startLoc
  13062. });
  13063. }
  13064. this.next();
  13065. node.object = this.parseHeaderExpression();
  13066. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13067. return this.finishNode(node, "WithStatement");
  13068. }
  13069. parseEmptyStatement(node) {
  13070. this.next();
  13071. return this.finishNode(node, "EmptyStatement");
  13072. }
  13073. parseLabeledStatement(node, maybeName, expr, flags) {
  13074. for (const label of this.state.labels) {
  13075. if (label.name === maybeName) {
  13076. this.raise(Errors.LabelRedeclaration, {
  13077. at: expr,
  13078. labelName: maybeName
  13079. });
  13080. }
  13081. }
  13082. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13083. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13084. const label = this.state.labels[i];
  13085. if (label.statementStart === node.start) {
  13086. label.statementStart = this.state.start;
  13087. label.kind = kind;
  13088. } else {
  13089. break;
  13090. }
  13091. }
  13092. this.state.labels.push({
  13093. name: maybeName,
  13094. kind: kind,
  13095. statementStart: this.state.start
  13096. });
  13097. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13098. this.state.labels.pop();
  13099. node.label = expr;
  13100. return this.finishNode(node, "LabeledStatement");
  13101. }
  13102. parseExpressionStatement(node, expr, decorators) {
  13103. node.expression = expr;
  13104. this.semicolon();
  13105. return this.finishNode(node, "ExpressionStatement");
  13106. }
  13107. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13108. const node = this.startNode();
  13109. if (allowDirectives) {
  13110. this.state.strictErrors.clear();
  13111. }
  13112. this.expect(5);
  13113. if (createNewLexicalScope) {
  13114. this.scope.enter(0);
  13115. }
  13116. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13117. if (createNewLexicalScope) {
  13118. this.scope.exit();
  13119. }
  13120. return this.finishNode(node, "BlockStatement");
  13121. }
  13122. isValidDirective(stmt) {
  13123. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13124. }
  13125. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13126. const body = node.body = [];
  13127. const directives = node.directives = [];
  13128. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13129. }
  13130. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13131. const oldStrict = this.state.strict;
  13132. let hasStrictModeDirective = false;
  13133. let parsedNonDirective = false;
  13134. while (!this.match(end)) {
  13135. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13136. if (directives && !parsedNonDirective) {
  13137. if (this.isValidDirective(stmt)) {
  13138. const directive = this.stmtToDirective(stmt);
  13139. directives.push(directive);
  13140. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13141. hasStrictModeDirective = true;
  13142. this.setStrict(true);
  13143. }
  13144. continue;
  13145. }
  13146. parsedNonDirective = true;
  13147. this.state.strictErrors.clear();
  13148. }
  13149. body.push(stmt);
  13150. }
  13151. afterBlockParse == null ? void 0 : afterBlockParse.call(this, hasStrictModeDirective);
  13152. if (!oldStrict) {
  13153. this.setStrict(false);
  13154. }
  13155. this.next();
  13156. }
  13157. parseFor(node, init) {
  13158. node.init = init;
  13159. this.semicolon(false);
  13160. node.test = this.match(13) ? null : this.parseExpression();
  13161. this.semicolon(false);
  13162. node.update = this.match(11) ? null : this.parseExpression();
  13163. this.expect(11);
  13164. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13165. this.scope.exit();
  13166. this.state.labels.pop();
  13167. return this.finishNode(node, "ForStatement");
  13168. }
  13169. parseForIn(node, init, awaitAt) {
  13170. const isForIn = this.match(58);
  13171. this.next();
  13172. if (isForIn) {
  13173. if (awaitAt !== null) this.unexpected(awaitAt);
  13174. } else {
  13175. node.await = awaitAt !== null;
  13176. }
  13177. 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")) {
  13178. this.raise(Errors.ForInOfLoopInitializer, {
  13179. at: init,
  13180. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13181. });
  13182. }
  13183. if (init.type === "AssignmentPattern") {
  13184. this.raise(Errors.InvalidLhs, {
  13185. at: init,
  13186. ancestor: {
  13187. type: "ForStatement"
  13188. }
  13189. });
  13190. }
  13191. node.left = init;
  13192. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13193. this.expect(11);
  13194. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13195. this.scope.exit();
  13196. this.state.labels.pop();
  13197. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13198. }
  13199. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13200. const declarations = node.declarations = [];
  13201. node.kind = kind;
  13202. for (;;) {
  13203. const decl = this.startNode();
  13204. this.parseVarId(decl, kind);
  13205. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13206. if (decl.init === null && !allowMissingInitializer) {
  13207. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(101)))) {
  13208. this.raise(Errors.DeclarationMissingInitializer, {
  13209. at: this.state.lastTokEndLoc,
  13210. kind: "destructuring"
  13211. });
  13212. } else if (kind === "const" && !(this.match(58) || this.isContextual(101))) {
  13213. this.raise(Errors.DeclarationMissingInitializer, {
  13214. at: this.state.lastTokEndLoc,
  13215. kind: "const"
  13216. });
  13217. }
  13218. }
  13219. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13220. if (!this.eat(12)) break;
  13221. }
  13222. return node;
  13223. }
  13224. parseVarId(decl, kind) {
  13225. const id = this.parseBindingAtom();
  13226. this.checkLVal(id, {
  13227. in: {
  13228. type: "VariableDeclarator"
  13229. },
  13230. binding: kind === "var" ? 5 : 8201
  13231. });
  13232. decl.id = id;
  13233. }
  13234. parseAsyncFunctionExpression(node) {
  13235. return this.parseFunction(node, 8);
  13236. }
  13237. parseFunction(node, flags = 0) {
  13238. const hangingDeclaration = flags & 2;
  13239. const isDeclaration = !!(flags & 1);
  13240. const requireId = isDeclaration && !(flags & 4);
  13241. const isAsync = !!(flags & 8);
  13242. this.initFunction(node, isAsync);
  13243. if (this.match(55)) {
  13244. if (hangingDeclaration) {
  13245. this.raise(Errors.GeneratorInSingleStatementContext, {
  13246. at: this.state.startLoc
  13247. });
  13248. }
  13249. this.next();
  13250. node.generator = true;
  13251. }
  13252. if (isDeclaration) {
  13253. node.id = this.parseFunctionId(requireId);
  13254. }
  13255. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13256. this.state.maybeInArrowParameters = false;
  13257. this.scope.enter(2);
  13258. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13259. if (!isDeclaration) {
  13260. node.id = this.parseFunctionId();
  13261. }
  13262. this.parseFunctionParams(node, false);
  13263. this.withSmartMixTopicForbiddingContext(() => {
  13264. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13265. });
  13266. this.prodParam.exit();
  13267. this.scope.exit();
  13268. if (isDeclaration && !hangingDeclaration) {
  13269. this.registerFunctionStatementId(node);
  13270. }
  13271. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13272. return node;
  13273. }
  13274. parseFunctionId(requireId) {
  13275. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13276. }
  13277. parseFunctionParams(node, isConstructor) {
  13278. this.expect(10);
  13279. this.expressionScope.enter(newParameterDeclarationScope());
  13280. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13281. this.expressionScope.exit();
  13282. }
  13283. registerFunctionStatementId(node) {
  13284. if (!node.id) return;
  13285. 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);
  13286. }
  13287. parseClass(node, isStatement, optionalId) {
  13288. this.next();
  13289. const oldStrict = this.state.strict;
  13290. this.state.strict = true;
  13291. this.parseClassId(node, isStatement, optionalId);
  13292. this.parseClassSuper(node);
  13293. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13294. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13295. }
  13296. isClassProperty() {
  13297. return this.match(29) || this.match(13) || this.match(8);
  13298. }
  13299. isClassMethod() {
  13300. return this.match(10);
  13301. }
  13302. isNonstaticConstructor(method) {
  13303. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  13304. }
  13305. parseClassBody(hadSuperClass, oldStrict) {
  13306. this.classScope.enter();
  13307. const state = {
  13308. hadConstructor: false,
  13309. hadSuperClass
  13310. };
  13311. let decorators = [];
  13312. const classBody = this.startNode();
  13313. classBody.body = [];
  13314. this.expect(5);
  13315. this.withSmartMixTopicForbiddingContext(() => {
  13316. while (!this.match(8)) {
  13317. if (this.eat(13)) {
  13318. if (decorators.length > 0) {
  13319. throw this.raise(Errors.DecoratorSemicolon, {
  13320. at: this.state.lastTokEndLoc
  13321. });
  13322. }
  13323. continue;
  13324. }
  13325. if (this.match(26)) {
  13326. decorators.push(this.parseDecorator());
  13327. continue;
  13328. }
  13329. const member = this.startNode();
  13330. if (decorators.length) {
  13331. member.decorators = decorators;
  13332. this.resetStartLocationFromNode(member, decorators[0]);
  13333. decorators = [];
  13334. }
  13335. this.parseClassMember(classBody, member, state);
  13336. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13337. this.raise(Errors.DecoratorConstructor, {
  13338. at: member
  13339. });
  13340. }
  13341. }
  13342. });
  13343. this.state.strict = oldStrict;
  13344. this.next();
  13345. if (decorators.length) {
  13346. throw this.raise(Errors.TrailingDecorator, {
  13347. at: this.state.startLoc
  13348. });
  13349. }
  13350. this.classScope.exit();
  13351. return this.finishNode(classBody, "ClassBody");
  13352. }
  13353. parseClassMemberFromModifier(classBody, member) {
  13354. const key = this.parseIdentifier(true);
  13355. if (this.isClassMethod()) {
  13356. const method = member;
  13357. method.kind = "method";
  13358. method.computed = false;
  13359. method.key = key;
  13360. method.static = false;
  13361. this.pushClassMethod(classBody, method, false, false, false, false);
  13362. return true;
  13363. } else if (this.isClassProperty()) {
  13364. const prop = member;
  13365. prop.computed = false;
  13366. prop.key = key;
  13367. prop.static = false;
  13368. classBody.body.push(this.parseClassProperty(prop));
  13369. return true;
  13370. }
  13371. this.resetPreviousNodeTrailingComments(key);
  13372. return false;
  13373. }
  13374. parseClassMember(classBody, member, state) {
  13375. const isStatic = this.isContextual(104);
  13376. if (isStatic) {
  13377. if (this.parseClassMemberFromModifier(classBody, member)) {
  13378. return;
  13379. }
  13380. if (this.eat(5)) {
  13381. this.parseClassStaticBlock(classBody, member);
  13382. return;
  13383. }
  13384. }
  13385. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13386. }
  13387. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13388. const publicMethod = member;
  13389. const privateMethod = member;
  13390. const publicProp = member;
  13391. const privateProp = member;
  13392. const accessorProp = member;
  13393. const method = publicMethod;
  13394. const publicMember = publicMethod;
  13395. member.static = isStatic;
  13396. this.parsePropertyNamePrefixOperator(member);
  13397. if (this.eat(55)) {
  13398. method.kind = "method";
  13399. const isPrivateName = this.match(136);
  13400. this.parseClassElementName(method);
  13401. if (isPrivateName) {
  13402. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13403. return;
  13404. }
  13405. if (this.isNonstaticConstructor(publicMethod)) {
  13406. this.raise(Errors.ConstructorIsGenerator, {
  13407. at: publicMethod.key
  13408. });
  13409. }
  13410. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13411. return;
  13412. }
  13413. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  13414. const isPrivate = this.match(136);
  13415. const key = this.parseClassElementName(member);
  13416. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13417. this.parsePostMemberNameModifiers(publicMember);
  13418. if (this.isClassMethod()) {
  13419. method.kind = "method";
  13420. if (isPrivate) {
  13421. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13422. return;
  13423. }
  13424. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13425. let allowsDirectSuper = false;
  13426. if (isConstructor) {
  13427. publicMethod.kind = "constructor";
  13428. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13429. this.raise(Errors.DuplicateConstructor, {
  13430. at: key
  13431. });
  13432. }
  13433. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13434. this.raise(Errors.OverrideOnConstructor, {
  13435. at: key
  13436. });
  13437. }
  13438. state.hadConstructor = true;
  13439. allowsDirectSuper = state.hadSuperClass;
  13440. }
  13441. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13442. } else if (this.isClassProperty()) {
  13443. if (isPrivate) {
  13444. this.pushClassPrivateProperty(classBody, privateProp);
  13445. } else {
  13446. this.pushClassProperty(classBody, publicProp);
  13447. }
  13448. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  13449. this.resetPreviousNodeTrailingComments(key);
  13450. const isGenerator = this.eat(55);
  13451. if (publicMember.optional) {
  13452. this.unexpected(maybeQuestionTokenStartLoc);
  13453. }
  13454. method.kind = "method";
  13455. const isPrivate = this.match(136);
  13456. this.parseClassElementName(method);
  13457. this.parsePostMemberNameModifiers(publicMember);
  13458. if (isPrivate) {
  13459. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13460. } else {
  13461. if (this.isNonstaticConstructor(publicMethod)) {
  13462. this.raise(Errors.ConstructorIsAsync, {
  13463. at: publicMethod.key
  13464. });
  13465. }
  13466. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13467. }
  13468. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  13469. this.resetPreviousNodeTrailingComments(key);
  13470. method.kind = key.name;
  13471. const isPrivate = this.match(136);
  13472. this.parseClassElementName(publicMethod);
  13473. if (isPrivate) {
  13474. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13475. } else {
  13476. if (this.isNonstaticConstructor(publicMethod)) {
  13477. this.raise(Errors.ConstructorIsAccessor, {
  13478. at: publicMethod.key
  13479. });
  13480. }
  13481. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13482. }
  13483. this.checkGetterSetterParams(publicMethod);
  13484. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  13485. this.expectPlugin("decoratorAutoAccessors");
  13486. this.resetPreviousNodeTrailingComments(key);
  13487. const isPrivate = this.match(136);
  13488. this.parseClassElementName(publicProp);
  13489. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13490. } else if (this.isLineTerminator()) {
  13491. if (isPrivate) {
  13492. this.pushClassPrivateProperty(classBody, privateProp);
  13493. } else {
  13494. this.pushClassProperty(classBody, publicProp);
  13495. }
  13496. } else {
  13497. this.unexpected();
  13498. }
  13499. }
  13500. parseClassElementName(member) {
  13501. const {
  13502. type,
  13503. value
  13504. } = this.state;
  13505. if ((type === 130 || type === 131) && member.static && value === "prototype") {
  13506. this.raise(Errors.StaticPrototype, {
  13507. at: this.state.startLoc
  13508. });
  13509. }
  13510. if (type === 136) {
  13511. if (value === "constructor") {
  13512. this.raise(Errors.ConstructorClassPrivateField, {
  13513. at: this.state.startLoc
  13514. });
  13515. }
  13516. const key = this.parsePrivateName();
  13517. member.key = key;
  13518. return key;
  13519. }
  13520. return this.parsePropertyName(member);
  13521. }
  13522. parseClassStaticBlock(classBody, member) {
  13523. var _member$decorators;
  13524. this.scope.enter(64 | 128 | 16);
  13525. const oldLabels = this.state.labels;
  13526. this.state.labels = [];
  13527. this.prodParam.enter(PARAM);
  13528. const body = member.body = [];
  13529. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13530. this.prodParam.exit();
  13531. this.scope.exit();
  13532. this.state.labels = oldLabels;
  13533. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13534. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13535. this.raise(Errors.DecoratorStaticBlock, {
  13536. at: member
  13537. });
  13538. }
  13539. }
  13540. pushClassProperty(classBody, prop) {
  13541. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  13542. this.raise(Errors.ConstructorClassField, {
  13543. at: prop.key
  13544. });
  13545. }
  13546. classBody.body.push(this.parseClassProperty(prop));
  13547. }
  13548. pushClassPrivateProperty(classBody, prop) {
  13549. const node = this.parseClassPrivateProperty(prop);
  13550. classBody.body.push(node);
  13551. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13552. }
  13553. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13554. if (!isPrivate && !prop.computed) {
  13555. const key = prop.key;
  13556. if (key.name === "constructor" || key.value === "constructor") {
  13557. this.raise(Errors.ConstructorClassField, {
  13558. at: key
  13559. });
  13560. }
  13561. }
  13562. const node = this.parseClassAccessorProperty(prop);
  13563. classBody.body.push(node);
  13564. if (isPrivate) {
  13565. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13566. }
  13567. }
  13568. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13569. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13570. }
  13571. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13572. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13573. classBody.body.push(node);
  13574. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13575. this.declareClassPrivateMethodInScope(node, kind);
  13576. }
  13577. declareClassPrivateMethodInScope(node, kind) {
  13578. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13579. }
  13580. parsePostMemberNameModifiers(methodOrProp) {}
  13581. parseClassPrivateProperty(node) {
  13582. this.parseInitializer(node);
  13583. this.semicolon();
  13584. return this.finishNode(node, "ClassPrivateProperty");
  13585. }
  13586. parseClassProperty(node) {
  13587. this.parseInitializer(node);
  13588. this.semicolon();
  13589. return this.finishNode(node, "ClassProperty");
  13590. }
  13591. parseClassAccessorProperty(node) {
  13592. this.parseInitializer(node);
  13593. this.semicolon();
  13594. return this.finishNode(node, "ClassAccessorProperty");
  13595. }
  13596. parseInitializer(node) {
  13597. this.scope.enter(64 | 16);
  13598. this.expressionScope.enter(newExpressionScope());
  13599. this.prodParam.enter(PARAM);
  13600. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13601. this.expressionScope.exit();
  13602. this.prodParam.exit();
  13603. this.scope.exit();
  13604. }
  13605. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13606. if (tokenIsIdentifier(this.state.type)) {
  13607. node.id = this.parseIdentifier();
  13608. if (isStatement) {
  13609. this.declareNameFromIdentifier(node.id, bindingType);
  13610. }
  13611. } else {
  13612. if (optionalId || !isStatement) {
  13613. node.id = null;
  13614. } else {
  13615. throw this.raise(Errors.MissingClassName, {
  13616. at: this.state.startLoc
  13617. });
  13618. }
  13619. }
  13620. }
  13621. parseClassSuper(node) {
  13622. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13623. }
  13624. parseExport(node, decorators) {
  13625. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13626. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13627. const parseAfterDefault = !hasDefault || this.eat(12);
  13628. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13629. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13630. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13631. const isFromRequired = hasDefault || hasStar;
  13632. if (hasStar && !hasNamespace) {
  13633. if (hasDefault) this.unexpected();
  13634. if (decorators) {
  13635. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13636. at: node
  13637. });
  13638. }
  13639. this.parseExportFrom(node, true);
  13640. return this.finishNode(node, "ExportAllDeclaration");
  13641. }
  13642. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13643. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13644. this.unexpected(null, 5);
  13645. }
  13646. if (hasNamespace && parseAfterNamespace) {
  13647. this.unexpected(null, 97);
  13648. }
  13649. let hasDeclaration;
  13650. if (isFromRequired || hasSpecifiers) {
  13651. hasDeclaration = false;
  13652. if (decorators) {
  13653. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13654. at: node
  13655. });
  13656. }
  13657. this.parseExportFrom(node, isFromRequired);
  13658. } else {
  13659. hasDeclaration = this.maybeParseExportDeclaration(node);
  13660. }
  13661. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13662. var _node2$declaration;
  13663. const node2 = node;
  13664. this.checkExport(node2, true, false, !!node2.source);
  13665. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13666. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13667. } else if (decorators) {
  13668. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13669. at: node
  13670. });
  13671. }
  13672. return this.finishNode(node2, "ExportNamedDeclaration");
  13673. }
  13674. if (this.eat(65)) {
  13675. const node2 = node;
  13676. const decl = this.parseExportDefaultExpression();
  13677. node2.declaration = decl;
  13678. if (decl.type === "ClassDeclaration") {
  13679. this.maybeTakeDecorators(decorators, decl, node2);
  13680. } else if (decorators) {
  13681. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13682. at: node
  13683. });
  13684. }
  13685. this.checkExport(node2, true, true);
  13686. return this.finishNode(node2, "ExportDefaultDeclaration");
  13687. }
  13688. this.unexpected(null, 5);
  13689. }
  13690. eatExportStar(node) {
  13691. return this.eat(55);
  13692. }
  13693. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13694. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13695. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13696. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13697. const specifier = this.startNodeAtNode(id);
  13698. specifier.exported = id;
  13699. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13700. return true;
  13701. }
  13702. return false;
  13703. }
  13704. maybeParseExportNamespaceSpecifier(node) {
  13705. if (this.isContextual(93)) {
  13706. if (!node.specifiers) node.specifiers = [];
  13707. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13708. this.next();
  13709. specifier.exported = this.parseModuleExportName();
  13710. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13711. return true;
  13712. }
  13713. return false;
  13714. }
  13715. maybeParseExportNamedSpecifiers(node) {
  13716. if (this.match(5)) {
  13717. if (!node.specifiers) node.specifiers = [];
  13718. const isTypeExport = node.exportKind === "type";
  13719. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13720. node.source = null;
  13721. node.declaration = null;
  13722. if (this.hasPlugin("importAssertions")) {
  13723. node.assertions = [];
  13724. }
  13725. return true;
  13726. }
  13727. return false;
  13728. }
  13729. maybeParseExportDeclaration(node) {
  13730. if (this.shouldParseExportDeclaration()) {
  13731. node.specifiers = [];
  13732. node.source = null;
  13733. if (this.hasPlugin("importAssertions")) {
  13734. node.assertions = [];
  13735. }
  13736. node.declaration = this.parseExportDeclaration(node);
  13737. return true;
  13738. }
  13739. return false;
  13740. }
  13741. isAsyncFunction() {
  13742. if (!this.isContextual(95)) return false;
  13743. const next = this.nextTokenInLineStart();
  13744. return this.isUnparsedContextual(next, "function");
  13745. }
  13746. parseExportDefaultExpression() {
  13747. const expr = this.startNode();
  13748. if (this.match(68)) {
  13749. this.next();
  13750. return this.parseFunction(expr, 1 | 4);
  13751. } else if (this.isAsyncFunction()) {
  13752. this.next();
  13753. this.next();
  13754. return this.parseFunction(expr, 1 | 4 | 8);
  13755. }
  13756. if (this.match(80)) {
  13757. return this.parseClass(expr, true, true);
  13758. }
  13759. if (this.match(26)) {
  13760. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13761. this.raise(Errors.DecoratorBeforeExport, {
  13762. at: this.state.startLoc
  13763. });
  13764. }
  13765. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13766. }
  13767. if (this.match(75) || this.match(74) || this.isLet()) {
  13768. throw this.raise(Errors.UnsupportedDefaultExport, {
  13769. at: this.state.startLoc
  13770. });
  13771. }
  13772. const res = this.parseMaybeAssignAllowIn();
  13773. this.semicolon();
  13774. return res;
  13775. }
  13776. parseExportDeclaration(node) {
  13777. if (this.match(80)) {
  13778. const node = this.parseClass(this.startNode(), true, false);
  13779. return node;
  13780. }
  13781. return this.parseStatementListItem();
  13782. }
  13783. isExportDefaultSpecifier() {
  13784. const {
  13785. type
  13786. } = this.state;
  13787. if (tokenIsIdentifier(type)) {
  13788. if (type === 95 && !this.state.containsEsc || type === 99) {
  13789. return false;
  13790. }
  13791. if ((type === 128 || type === 127) && !this.state.containsEsc) {
  13792. const {
  13793. type: nextType
  13794. } = this.lookahead();
  13795. if (tokenIsIdentifier(nextType) && nextType !== 97 || nextType === 5) {
  13796. this.expectOnePlugin(["flow", "typescript"]);
  13797. return false;
  13798. }
  13799. }
  13800. } else if (!this.match(65)) {
  13801. return false;
  13802. }
  13803. const next = this.nextTokenStart();
  13804. const hasFrom = this.isUnparsedContextual(next, "from");
  13805. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13806. return true;
  13807. }
  13808. if (this.match(65) && hasFrom) {
  13809. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13810. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13811. }
  13812. return false;
  13813. }
  13814. parseExportFrom(node, expect) {
  13815. if (this.eatContextual(97)) {
  13816. node.source = this.parseImportSource();
  13817. this.checkExport(node);
  13818. this.maybeParseImportAttributes(node);
  13819. this.checkJSONModuleImport(node);
  13820. } else if (expect) {
  13821. this.unexpected();
  13822. }
  13823. this.semicolon();
  13824. }
  13825. shouldParseExportDeclaration() {
  13826. const {
  13827. type
  13828. } = this.state;
  13829. if (type === 26) {
  13830. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13831. if (this.hasPlugin("decorators")) {
  13832. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13833. this.raise(Errors.DecoratorBeforeExport, {
  13834. at: this.state.startLoc
  13835. });
  13836. }
  13837. return true;
  13838. }
  13839. }
  13840. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13841. }
  13842. checkExport(node, checkNames, isDefault, isFrom) {
  13843. if (checkNames) {
  13844. var _node$specifiers;
  13845. if (isDefault) {
  13846. this.checkDuplicateExports(node, "default");
  13847. if (this.hasPlugin("exportDefaultFrom")) {
  13848. var _declaration$extra;
  13849. const declaration = node.declaration;
  13850. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13851. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  13852. at: declaration
  13853. });
  13854. }
  13855. }
  13856. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13857. for (const specifier of node.specifiers) {
  13858. const {
  13859. exported
  13860. } = specifier;
  13861. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13862. this.checkDuplicateExports(specifier, exportName);
  13863. if (!isFrom && specifier.local) {
  13864. const {
  13865. local
  13866. } = specifier;
  13867. if (local.type !== "Identifier") {
  13868. this.raise(Errors.ExportBindingIsString, {
  13869. at: specifier,
  13870. localName: local.value,
  13871. exportName
  13872. });
  13873. } else {
  13874. this.checkReservedWord(local.name, local.loc.start, true, false);
  13875. this.scope.checkLocalExport(local);
  13876. }
  13877. }
  13878. }
  13879. } else if (node.declaration) {
  13880. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  13881. const id = node.declaration.id;
  13882. if (!id) throw new Error("Assertion failure");
  13883. this.checkDuplicateExports(node, id.name);
  13884. } else if (node.declaration.type === "VariableDeclaration") {
  13885. for (const declaration of node.declaration.declarations) {
  13886. this.checkDeclaration(declaration.id);
  13887. }
  13888. }
  13889. }
  13890. }
  13891. }
  13892. checkDeclaration(node) {
  13893. if (node.type === "Identifier") {
  13894. this.checkDuplicateExports(node, node.name);
  13895. } else if (node.type === "ObjectPattern") {
  13896. for (const prop of node.properties) {
  13897. this.checkDeclaration(prop);
  13898. }
  13899. } else if (node.type === "ArrayPattern") {
  13900. for (const elem of node.elements) {
  13901. if (elem) {
  13902. this.checkDeclaration(elem);
  13903. }
  13904. }
  13905. } else if (node.type === "ObjectProperty") {
  13906. this.checkDeclaration(node.value);
  13907. } else if (node.type === "RestElement") {
  13908. this.checkDeclaration(node.argument);
  13909. } else if (node.type === "AssignmentPattern") {
  13910. this.checkDeclaration(node.left);
  13911. }
  13912. }
  13913. checkDuplicateExports(node, exportName) {
  13914. if (this.exportedIdentifiers.has(exportName)) {
  13915. if (exportName === "default") {
  13916. this.raise(Errors.DuplicateDefaultExport, {
  13917. at: node
  13918. });
  13919. } else {
  13920. this.raise(Errors.DuplicateExport, {
  13921. at: node,
  13922. exportName
  13923. });
  13924. }
  13925. }
  13926. this.exportedIdentifiers.add(exportName);
  13927. }
  13928. parseExportSpecifiers(isInTypeExport) {
  13929. const nodes = [];
  13930. let first = true;
  13931. this.expect(5);
  13932. while (!this.eat(8)) {
  13933. if (first) {
  13934. first = false;
  13935. } else {
  13936. this.expect(12);
  13937. if (this.eat(8)) break;
  13938. }
  13939. const isMaybeTypeOnly = this.isContextual(128);
  13940. const isString = this.match(131);
  13941. const node = this.startNode();
  13942. node.local = this.parseModuleExportName();
  13943. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  13944. }
  13945. return nodes;
  13946. }
  13947. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  13948. if (this.eatContextual(93)) {
  13949. node.exported = this.parseModuleExportName();
  13950. } else if (isString) {
  13951. node.exported = cloneStringLiteral(node.local);
  13952. } else if (!node.exported) {
  13953. node.exported = cloneIdentifier(node.local);
  13954. }
  13955. return this.finishNode(node, "ExportSpecifier");
  13956. }
  13957. parseModuleExportName() {
  13958. if (this.match(131)) {
  13959. const result = this.parseStringLiteral(this.state.value);
  13960. const surrogate = result.value.match(loneSurrogate);
  13961. if (surrogate) {
  13962. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  13963. at: result,
  13964. surrogateCharCode: surrogate[0].charCodeAt(0)
  13965. });
  13966. }
  13967. return result;
  13968. }
  13969. return this.parseIdentifier(true);
  13970. }
  13971. isJSONModuleImport(node) {
  13972. if (node.assertions != null) {
  13973. return node.assertions.some(({
  13974. key,
  13975. value
  13976. }) => {
  13977. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  13978. });
  13979. }
  13980. return false;
  13981. }
  13982. checkImportReflection(node) {
  13983. if (node.module) {
  13984. var _node$assertions;
  13985. if (node.specifiers.length !== 1 || node.specifiers[0].type !== "ImportDefaultSpecifier") {
  13986. this.raise(Errors.ImportReflectionNotBinding, {
  13987. at: node.specifiers[0].loc.start
  13988. });
  13989. }
  13990. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  13991. this.raise(Errors.ImportReflectionHasAssertion, {
  13992. at: node.specifiers[0].loc.start
  13993. });
  13994. }
  13995. }
  13996. }
  13997. checkJSONModuleImport(node) {
  13998. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  13999. const {
  14000. specifiers
  14001. } = node;
  14002. if (specifiers != null) {
  14003. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14004. let imported;
  14005. if (specifier.type === "ExportSpecifier") {
  14006. imported = specifier.local;
  14007. } else if (specifier.type === "ImportSpecifier") {
  14008. imported = specifier.imported;
  14009. }
  14010. if (imported !== undefined) {
  14011. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14012. }
  14013. });
  14014. if (nonDefaultNamedSpecifier !== undefined) {
  14015. this.raise(Errors.ImportJSONBindingNotDefault, {
  14016. at: nonDefaultNamedSpecifier.loc.start
  14017. });
  14018. }
  14019. }
  14020. }
  14021. }
  14022. isPotentialImportPhase(isExport) {
  14023. return !isExport && this.isContextual(125);
  14024. }
  14025. applyImportPhase(node, isExport, phase, loc) {
  14026. if (isExport) {
  14027. return;
  14028. }
  14029. if (phase === "module") {
  14030. this.expectPlugin("importReflection", loc);
  14031. node.module = true;
  14032. } else if (this.hasPlugin("importReflection")) {
  14033. node.module = false;
  14034. }
  14035. }
  14036. parseMaybeImportPhase(node, isExport) {
  14037. if (!this.isPotentialImportPhase(isExport)) {
  14038. this.applyImportPhase(node, isExport, null);
  14039. return null;
  14040. }
  14041. const phaseIdentifier = this.parseIdentifier(true);
  14042. const {
  14043. type
  14044. } = this.state;
  14045. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 97 || this.lookaheadCharCode() === 102 : type !== 12;
  14046. if (isImportPhase) {
  14047. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  14048. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  14049. return null;
  14050. } else {
  14051. this.applyImportPhase(node, isExport, null);
  14052. return phaseIdentifier;
  14053. }
  14054. }
  14055. isPrecedingIdImportPhase(phase) {
  14056. const {
  14057. type
  14058. } = this.state;
  14059. return tokenIsIdentifier(type) ? type !== 97 || this.lookaheadCharCode() === 102 : type !== 12;
  14060. }
  14061. parseImport(node) {
  14062. if (this.match(131)) {
  14063. return this.parseImportSourceAndAttributes(node);
  14064. }
  14065. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14066. }
  14067. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14068. node.specifiers = [];
  14069. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14070. const parseNext = !hasDefault || this.eat(12);
  14071. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14072. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14073. this.expectContextual(97);
  14074. return this.parseImportSourceAndAttributes(node);
  14075. }
  14076. parseImportSourceAndAttributes(node) {
  14077. var _node$specifiers2;
  14078. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14079. node.source = this.parseImportSource();
  14080. this.maybeParseImportAttributes(node);
  14081. this.checkImportReflection(node);
  14082. this.checkJSONModuleImport(node);
  14083. this.semicolon();
  14084. return this.finishNode(node, "ImportDeclaration");
  14085. }
  14086. parseImportSource() {
  14087. if (!this.match(131)) this.unexpected();
  14088. return this.parseExprAtom();
  14089. }
  14090. parseImportSpecifierLocal(node, specifier, type) {
  14091. specifier.local = this.parseIdentifier();
  14092. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14093. }
  14094. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14095. this.checkLVal(specifier.local, {
  14096. in: {
  14097. type
  14098. },
  14099. binding: bindingType
  14100. });
  14101. return this.finishNode(specifier, type);
  14102. }
  14103. parseImportAttributes() {
  14104. this.expect(5);
  14105. const attrs = [];
  14106. const attrNames = new Set();
  14107. do {
  14108. if (this.match(8)) {
  14109. break;
  14110. }
  14111. const node = this.startNode();
  14112. const keyName = this.state.value;
  14113. if (attrNames.has(keyName)) {
  14114. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14115. at: this.state.startLoc,
  14116. key: keyName
  14117. });
  14118. }
  14119. attrNames.add(keyName);
  14120. if (this.match(131)) {
  14121. node.key = this.parseStringLiteral(keyName);
  14122. } else {
  14123. node.key = this.parseIdentifier(true);
  14124. }
  14125. this.expect(14);
  14126. if (!this.match(131)) {
  14127. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14128. at: this.state.startLoc
  14129. });
  14130. }
  14131. node.value = this.parseStringLiteral(this.state.value);
  14132. attrs.push(this.finishNode(node, "ImportAttribute"));
  14133. } while (this.eat(12));
  14134. this.expect(8);
  14135. return attrs;
  14136. }
  14137. parseModuleAttributes() {
  14138. const attrs = [];
  14139. const attributes = new Set();
  14140. do {
  14141. const node = this.startNode();
  14142. node.key = this.parseIdentifier(true);
  14143. if (node.key.name !== "type") {
  14144. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14145. at: node.key
  14146. });
  14147. }
  14148. if (attributes.has(node.key.name)) {
  14149. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14150. at: node.key,
  14151. key: node.key.name
  14152. });
  14153. }
  14154. attributes.add(node.key.name);
  14155. this.expect(14);
  14156. if (!this.match(131)) {
  14157. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14158. at: this.state.startLoc
  14159. });
  14160. }
  14161. node.value = this.parseStringLiteral(this.state.value);
  14162. attrs.push(this.finishNode(node, "ImportAttribute"));
  14163. } while (this.eat(12));
  14164. return attrs;
  14165. }
  14166. maybeParseImportAttributes(node) {
  14167. let attributes;
  14168. let useWith = false;
  14169. if (this.match(76)) {
  14170. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14171. return;
  14172. }
  14173. this.next();
  14174. {
  14175. if (this.hasPlugin("moduleAttributes")) {
  14176. attributes = this.parseModuleAttributes();
  14177. } else {
  14178. this.expectImportAttributesPlugin();
  14179. attributes = this.parseImportAttributes();
  14180. }
  14181. }
  14182. useWith = true;
  14183. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14184. if (this.hasPlugin("importAttributes")) {
  14185. if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) {
  14186. this.raise(Errors.ImportAttributesUseAssert, {
  14187. at: this.state.startLoc
  14188. });
  14189. }
  14190. this.addExtra(node, "deprecatedAssertSyntax", true);
  14191. } else {
  14192. this.expectOnePlugin(["importAttributes", "importAssertions"]);
  14193. }
  14194. this.next();
  14195. attributes = this.parseImportAttributes();
  14196. } else if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  14197. attributes = [];
  14198. } else {
  14199. if (this.hasPlugin("moduleAttributes")) {
  14200. attributes = [];
  14201. } else return;
  14202. }
  14203. if (!useWith && this.hasPlugin("importAssertions")) {
  14204. node.assertions = attributes;
  14205. } else {
  14206. node.attributes = attributes;
  14207. }
  14208. }
  14209. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14210. if (maybeDefaultIdentifier) {
  14211. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14212. specifier.local = maybeDefaultIdentifier;
  14213. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14214. return true;
  14215. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14216. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14217. return true;
  14218. }
  14219. return false;
  14220. }
  14221. maybeParseStarImportSpecifier(node) {
  14222. if (this.match(55)) {
  14223. const specifier = this.startNode();
  14224. this.next();
  14225. this.expectContextual(93);
  14226. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14227. return true;
  14228. }
  14229. return false;
  14230. }
  14231. parseNamedImportSpecifiers(node) {
  14232. let first = true;
  14233. this.expect(5);
  14234. while (!this.eat(8)) {
  14235. if (first) {
  14236. first = false;
  14237. } else {
  14238. if (this.eat(14)) {
  14239. throw this.raise(Errors.DestructureNamedImport, {
  14240. at: this.state.startLoc
  14241. });
  14242. }
  14243. this.expect(12);
  14244. if (this.eat(8)) break;
  14245. }
  14246. const specifier = this.startNode();
  14247. const importedIsString = this.match(131);
  14248. const isMaybeTypeOnly = this.isContextual(128);
  14249. specifier.imported = this.parseModuleExportName();
  14250. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14251. node.specifiers.push(importSpecifier);
  14252. }
  14253. }
  14254. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14255. if (this.eatContextual(93)) {
  14256. specifier.local = this.parseIdentifier();
  14257. } else {
  14258. const {
  14259. imported
  14260. } = specifier;
  14261. if (importedIsString) {
  14262. throw this.raise(Errors.ImportBindingIsString, {
  14263. at: specifier,
  14264. importName: imported.value
  14265. });
  14266. }
  14267. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14268. if (!specifier.local) {
  14269. specifier.local = cloneIdentifier(imported);
  14270. }
  14271. }
  14272. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14273. }
  14274. isThisParam(param) {
  14275. return param.type === "Identifier" && param.name === "this";
  14276. }
  14277. }
  14278. class Parser extends StatementParser {
  14279. constructor(options, input) {
  14280. options = getOptions(options);
  14281. super(options, input);
  14282. this.options = options;
  14283. this.initializeScopes();
  14284. this.plugins = pluginsMap(this.options.plugins);
  14285. this.filename = options.sourceFilename;
  14286. }
  14287. getScopeHandler() {
  14288. return ScopeHandler;
  14289. }
  14290. parse() {
  14291. this.enterInitialScopes();
  14292. const file = this.startNode();
  14293. const program = this.startNode();
  14294. this.nextToken();
  14295. file.errors = null;
  14296. this.parseTopLevel(file, program);
  14297. file.errors = this.state.errors;
  14298. return file;
  14299. }
  14300. }
  14301. function pluginsMap(plugins) {
  14302. const pluginMap = new Map();
  14303. for (const plugin of plugins) {
  14304. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  14305. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  14306. }
  14307. return pluginMap;
  14308. }
  14309. function parse(input, options) {
  14310. var _options;
  14311. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14312. options = Object.assign({}, options);
  14313. try {
  14314. options.sourceType = "module";
  14315. const parser = getParser(options, input);
  14316. const ast = parser.parse();
  14317. if (parser.sawUnambiguousESM) {
  14318. return ast;
  14319. }
  14320. if (parser.ambiguousScriptDifferentAst) {
  14321. try {
  14322. options.sourceType = "script";
  14323. return getParser(options, input).parse();
  14324. } catch (_unused) {}
  14325. } else {
  14326. ast.program.sourceType = "script";
  14327. }
  14328. return ast;
  14329. } catch (moduleError) {
  14330. try {
  14331. options.sourceType = "script";
  14332. return getParser(options, input).parse();
  14333. } catch (_unused2) {}
  14334. throw moduleError;
  14335. }
  14336. } else {
  14337. return getParser(options, input).parse();
  14338. }
  14339. }
  14340. function parseExpression(input, options) {
  14341. const parser = getParser(options, input);
  14342. if (parser.options.strictMode) {
  14343. parser.state.strict = true;
  14344. }
  14345. return parser.getExpression();
  14346. }
  14347. function generateExportedTokenTypes(internalTokenTypes) {
  14348. const tokenTypes = {};
  14349. for (const typeName of Object.keys(internalTokenTypes)) {
  14350. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14351. }
  14352. return tokenTypes;
  14353. }
  14354. const tokTypes = generateExportedTokenTypes(tt);
  14355. function getParser(options, input) {
  14356. let cls = Parser;
  14357. if (options != null && options.plugins) {
  14358. validatePlugins(options.plugins);
  14359. cls = getParserClass(options.plugins);
  14360. }
  14361. return new cls(options, input);
  14362. }
  14363. const parserClassCache = {};
  14364. function getParserClass(pluginsFromOptions) {
  14365. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14366. const key = pluginList.join("/");
  14367. let cls = parserClassCache[key];
  14368. if (!cls) {
  14369. cls = Parser;
  14370. for (const plugin of pluginList) {
  14371. cls = mixinPlugins[plugin](cls);
  14372. }
  14373. parserClassCache[key] = cls;
  14374. }
  14375. return cls;
  14376. }
  14377. exports.parse = parse;
  14378. exports.parseExpression = parseExpression;
  14379. exports.tokTypes = tokTypes;
  14380. //# sourceMappingURL=index.js.map