index.js 479 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. function _objectWithoutPropertiesLoose(source, excluded) {
  6. if (source == null) return {};
  7. var target = {};
  8. var sourceKeys = Object.keys(source);
  9. var key, i;
  10. for (i = 0; i < sourceKeys.length; i++) {
  11. key = sourceKeys[i];
  12. if (excluded.indexOf(key) >= 0) continue;
  13. target[key] = source[key];
  14. }
  15. return target;
  16. }
  17. class Position {
  18. constructor(line, col, index) {
  19. this.line = void 0;
  20. this.column = void 0;
  21. this.index = void 0;
  22. this.line = line;
  23. this.column = col;
  24. this.index = index;
  25. }
  26. }
  27. class SourceLocation {
  28. constructor(start, end) {
  29. this.start = void 0;
  30. this.end = void 0;
  31. this.filename = void 0;
  32. this.identifierName = void 0;
  33. this.start = start;
  34. this.end = end;
  35. }
  36. }
  37. function createPositionWithColumnOffset(position, columnOffset) {
  38. const {
  39. line,
  40. column,
  41. index
  42. } = position;
  43. return new Position(line, column + columnOffset, index + columnOffset);
  44. }
  45. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  46. var ModuleErrors = {
  47. ImportMetaOutsideModule: {
  48. message: `import.meta may appear only with 'sourceType: "module"'`,
  49. code
  50. },
  51. ImportOutsideModule: {
  52. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  53. code
  54. }
  55. };
  56. const NodeDescriptions = {
  57. ArrayPattern: "array destructuring pattern",
  58. AssignmentExpression: "assignment expression",
  59. AssignmentPattern: "assignment expression",
  60. ArrowFunctionExpression: "arrow function expression",
  61. ConditionalExpression: "conditional expression",
  62. CatchClause: "catch clause",
  63. ForOfStatement: "for-of statement",
  64. ForInStatement: "for-in statement",
  65. ForStatement: "for-loop",
  66. FormalParameters: "function parameter list",
  67. Identifier: "identifier",
  68. ImportSpecifier: "import specifier",
  69. ImportDefaultSpecifier: "import default specifier",
  70. ImportNamespaceSpecifier: "import namespace specifier",
  71. ObjectPattern: "object destructuring pattern",
  72. ParenthesizedExpression: "parenthesized expression",
  73. RestElement: "rest element",
  74. UpdateExpression: {
  75. true: "prefix operation",
  76. false: "postfix operation"
  77. },
  78. VariableDeclarator: "variable declaration",
  79. YieldExpression: "yield expression"
  80. };
  81. const toNodeDescription = ({
  82. type,
  83. prefix
  84. }) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type];
  85. var StandardErrors = {
  86. AccessorIsGenerator: ({
  87. kind
  88. }) => `A ${kind}ter cannot be a generator.`,
  89. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  90. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  91. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  92. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  93. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  94. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  95. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  96. AwaitNotInAsyncFunction: "'await' is only allowed within async functions.",
  97. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  98. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  99. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  100. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  101. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  102. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  103. ConstructorIsAsync: "Constructor can't be an async function.",
  104. ConstructorIsGenerator: "Constructor can't be a generator.",
  105. DeclarationMissingInitializer: ({
  106. kind
  107. }) => `Missing initializer in ${kind} declaration.`,
  108. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  109. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  110. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  111. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  112. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  113. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  114. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  115. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  116. DeletePrivateField: "Deleting a private field is not allowed.",
  117. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  118. DuplicateConstructor: "Duplicate constructor in the same class.",
  119. DuplicateDefaultExport: "Only one default export allowed per module.",
  120. DuplicateExport: ({
  121. exportName
  122. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  123. DuplicateProto: "Redefinition of __proto__ property.",
  124. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  125. DynamicImportPhaseRequiresImportExpressions: ({
  126. phase
  127. }) => `'import.${phase}(...)' can only be parsed when using the 'createImportExpressions' option.`,
  128. ElementAfterRest: "Rest element must be last element.",
  129. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  130. ExportBindingIsString: ({
  131. localName,
  132. exportName
  133. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  134. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  135. ForInOfLoopInitializer: ({
  136. type
  137. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  138. ForInUsing: "For-in loop may not start with 'using' declaration.",
  139. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  140. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  141. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  142. IllegalBreakContinue: ({
  143. type
  144. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  145. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  146. IllegalReturn: "'return' outside of function.",
  147. 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.",
  148. ImportBindingIsString: ({
  149. importName
  150. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  151. ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.",
  152. ImportCallArity: ({
  153. maxArgumentCount
  154. }) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`,
  155. ImportCallNotNewExpression: "Cannot use new with import(...).",
  156. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  157. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  158. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  159. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  160. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  161. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  162. InvalidCodePoint: "Code point out of bounds.",
  163. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  164. InvalidDecimal: "Invalid decimal.",
  165. InvalidDigit: ({
  166. radix
  167. }) => `Expected number in radix ${radix}.`,
  168. InvalidEscapeSequence: "Bad character escape sequence.",
  169. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  170. InvalidEscapedReservedWord: ({
  171. reservedWord
  172. }) => `Escape sequence in keyword ${reservedWord}.`,
  173. InvalidIdentifier: ({
  174. identifierName
  175. }) => `Invalid identifier ${identifierName}.`,
  176. InvalidLhs: ({
  177. ancestor
  178. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  179. InvalidLhsBinding: ({
  180. ancestor
  181. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  182. InvalidLhsOptionalChaining: ({
  183. ancestor
  184. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  185. InvalidNumber: "Invalid number.",
  186. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  187. InvalidOrUnexpectedToken: ({
  188. unexpected
  189. }) => `Unexpected character '${unexpected}'.`,
  190. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  191. InvalidPrivateFieldResolution: ({
  192. identifierName
  193. }) => `Private name #${identifierName} is not defined.`,
  194. InvalidPropertyBindingPattern: "Binding member expression.",
  195. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  196. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  197. LabelRedeclaration: ({
  198. labelName
  199. }) => `Label '${labelName}' is already declared.`,
  200. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  201. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  202. MalformedRegExpFlags: "Invalid regular expression flag.",
  203. MissingClassName: "A class name is required.",
  204. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  205. MissingSemicolon: "Missing semicolon.",
  206. MissingPlugin: ({
  207. missingPlugin
  208. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  209. MissingOneOfPlugins: ({
  210. missingPlugin
  211. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  212. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  213. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  214. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  215. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  216. ModuleAttributesWithDuplicateKeys: ({
  217. key
  218. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  219. ModuleExportNameHasLoneSurrogate: ({
  220. surrogateCharCode
  221. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  222. ModuleExportUndefined: ({
  223. localName
  224. }) => `Export '${localName}' is not defined.`,
  225. MultipleDefaultsInSwitch: "Multiple default clauses.",
  226. NewlineAfterThrow: "Illegal newline after throw.",
  227. NoCatchOrFinally: "Missing catch or finally clause.",
  228. NumberIdentifier: "Identifier directly after number.",
  229. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  230. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  231. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  232. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  233. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  234. ParamDupe: "Argument name clash.",
  235. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  236. PatternHasMethod: "Object pattern can't contain methods.",
  237. PrivateInExpectedIn: ({
  238. identifierName
  239. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  240. PrivateNameRedeclaration: ({
  241. identifierName
  242. }) => `Duplicate private name #${identifierName}.`,
  243. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  244. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  245. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  246. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  247. RestTrailingComma: "Unexpected trailing comma after rest element.",
  248. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  249. 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.",
  250. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  251. StaticPrototype: "Classes may not have static property named prototype.",
  252. 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?",
  253. SuperPrivateField: "Private fields can't be accessed on super.",
  254. TrailingDecorator: "Decorators must be attached to a class element.",
  255. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  256. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  257. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  258. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  259. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  260. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  261. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  262. UnexpectedKeyword: ({
  263. keyword
  264. }) => `Unexpected keyword '${keyword}'.`,
  265. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  266. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  267. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  268. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  269. UnexpectedPrivateField: "Unexpected private name.",
  270. UnexpectedReservedWord: ({
  271. reservedWord
  272. }) => `Unexpected reserved word '${reservedWord}'.`,
  273. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  274. UnexpectedToken: ({
  275. expected,
  276. unexpected
  277. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  278. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  279. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.",
  280. UnsupportedBind: "Binding should be performed on object property.",
  281. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  282. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  283. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  284. UnsupportedMetaProperty: ({
  285. target,
  286. onlyValidPropertyName
  287. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  288. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  289. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  290. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  291. UnterminatedComment: "Unterminated comment.",
  292. UnterminatedRegExp: "Unterminated regular expression.",
  293. UnterminatedString: "Unterminated string constant.",
  294. UnterminatedTemplate: "Unterminated template.",
  295. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  296. VarRedeclaration: ({
  297. identifierName
  298. }) => `Identifier '${identifierName}' has already been declared.`,
  299. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  300. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  301. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  302. };
  303. var StrictModeErrors = {
  304. StrictDelete: "Deleting local variable in strict mode.",
  305. StrictEvalArguments: ({
  306. referenceName
  307. }) => `Assigning to '${referenceName}' in strict mode.`,
  308. StrictEvalArgumentsBinding: ({
  309. bindingName
  310. }) => `Binding '${bindingName}' in strict mode.`,
  311. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  312. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  313. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  314. StrictWith: "'with' in strict mode."
  315. };
  316. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  317. var PipelineOperatorErrors = {
  318. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  319. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  320. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  321. PipeTopicUnconfiguredToken: ({
  322. token
  323. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  324. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  325. PipeUnparenthesizedBody: ({
  326. type
  327. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  328. type
  329. })}; please wrap it in parentheses.`,
  330. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  331. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  332. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  333. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  334. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  335. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  336. };
  337. const _excluded$1 = ["toMessage"],
  338. _excluded2$1 = ["message"];
  339. function defineHidden(obj, key, value) {
  340. Object.defineProperty(obj, key, {
  341. enumerable: false,
  342. configurable: true,
  343. value
  344. });
  345. }
  346. function toParseErrorConstructor(_ref) {
  347. let {
  348. toMessage
  349. } = _ref,
  350. properties = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  351. return function constructor({
  352. loc,
  353. details
  354. }) {
  355. const error = new SyntaxError();
  356. Object.assign(error, properties, {
  357. loc,
  358. pos: loc.index
  359. });
  360. if ("missingPlugin" in details) {
  361. Object.assign(error, {
  362. missingPlugin: details.missingPlugin
  363. });
  364. }
  365. defineHidden(error, "clone", function clone(overrides = {}) {
  366. var _overrides$loc;
  367. const {
  368. line,
  369. column,
  370. index
  371. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  372. return constructor({
  373. loc: new Position(line, column, index),
  374. details: Object.assign({}, details, overrides.details)
  375. });
  376. });
  377. defineHidden(error, "details", details);
  378. Object.defineProperty(error, "message", {
  379. configurable: true,
  380. get() {
  381. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  382. this.message = message;
  383. return message;
  384. },
  385. set(value) {
  386. Object.defineProperty(this, "message", {
  387. value,
  388. writable: true
  389. });
  390. }
  391. });
  392. return error;
  393. };
  394. }
  395. function ParseErrorEnum(argument, syntaxPlugin) {
  396. if (Array.isArray(argument)) {
  397. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  398. }
  399. const ParseErrorConstructors = {};
  400. for (const reasonCode of Object.keys(argument)) {
  401. const template = argument[reasonCode];
  402. const _ref2 = typeof template === "string" ? {
  403. message: () => template
  404. } : typeof template === "function" ? {
  405. message: template
  406. } : template,
  407. {
  408. message
  409. } = _ref2,
  410. rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
  411. const toMessage = typeof message === "string" ? () => message : message;
  412. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  413. code: "BABEL_PARSER_SYNTAX_ERROR",
  414. reasonCode,
  415. toMessage
  416. }, syntaxPlugin ? {
  417. syntaxPlugin
  418. } : {}, rest));
  419. }
  420. return ParseErrorConstructors;
  421. }
  422. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  423. const {
  424. defineProperty
  425. } = Object;
  426. const toUnenumerable = (object, key) => defineProperty(object, key, {
  427. enumerable: false,
  428. value: object[key]
  429. });
  430. function toESTreeLocation(node) {
  431. node.loc.start && toUnenumerable(node.loc.start, "index");
  432. node.loc.end && toUnenumerable(node.loc.end, "index");
  433. return node;
  434. }
  435. var estree = superClass => class ESTreeParserMixin extends superClass {
  436. parse() {
  437. const file = toESTreeLocation(super.parse());
  438. if (this.options.tokens) {
  439. file.tokens = file.tokens.map(toESTreeLocation);
  440. }
  441. return file;
  442. }
  443. parseRegExpLiteral({
  444. pattern,
  445. flags
  446. }) {
  447. let regex = null;
  448. try {
  449. regex = new RegExp(pattern, flags);
  450. } catch (e) {}
  451. const node = this.estreeParseLiteral(regex);
  452. node.regex = {
  453. pattern,
  454. flags
  455. };
  456. return node;
  457. }
  458. parseBigIntLiteral(value) {
  459. let bigInt;
  460. try {
  461. bigInt = BigInt(value);
  462. } catch (_unused) {
  463. bigInt = null;
  464. }
  465. const node = this.estreeParseLiteral(bigInt);
  466. node.bigint = String(node.value || value);
  467. return node;
  468. }
  469. parseDecimalLiteral(value) {
  470. const decimal = null;
  471. const node = this.estreeParseLiteral(decimal);
  472. node.decimal = String(node.value || value);
  473. return node;
  474. }
  475. estreeParseLiteral(value) {
  476. return this.parseLiteral(value, "Literal");
  477. }
  478. parseStringLiteral(value) {
  479. return this.estreeParseLiteral(value);
  480. }
  481. parseNumericLiteral(value) {
  482. return this.estreeParseLiteral(value);
  483. }
  484. parseNullLiteral() {
  485. return this.estreeParseLiteral(null);
  486. }
  487. parseBooleanLiteral(value) {
  488. return this.estreeParseLiteral(value);
  489. }
  490. directiveToStmt(directive) {
  491. const expression = directive.value;
  492. delete directive.value;
  493. expression.type = "Literal";
  494. expression.raw = expression.extra.raw;
  495. expression.value = expression.extra.expressionValue;
  496. const stmt = directive;
  497. stmt.type = "ExpressionStatement";
  498. stmt.expression = expression;
  499. stmt.directive = expression.extra.rawValue;
  500. delete expression.extra;
  501. return stmt;
  502. }
  503. initFunction(node, isAsync) {
  504. super.initFunction(node, isAsync);
  505. node.expression = false;
  506. }
  507. checkDeclaration(node) {
  508. if (node != null && this.isObjectProperty(node)) {
  509. this.checkDeclaration(node.value);
  510. } else {
  511. super.checkDeclaration(node);
  512. }
  513. }
  514. getObjectOrClassMethodParams(method) {
  515. return method.value.params;
  516. }
  517. isValidDirective(stmt) {
  518. var _stmt$expression$extr;
  519. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  520. }
  521. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  522. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  523. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  524. node.body = directiveStatements.concat(node.body);
  525. delete node.directives;
  526. }
  527. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  528. this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true);
  529. if (method.typeParameters) {
  530. method.value.typeParameters = method.typeParameters;
  531. delete method.typeParameters;
  532. }
  533. classBody.body.push(method);
  534. }
  535. parsePrivateName() {
  536. const node = super.parsePrivateName();
  537. {
  538. if (!this.getPluginOption("estree", "classFeatures")) {
  539. return node;
  540. }
  541. }
  542. return this.convertPrivateNameToPrivateIdentifier(node);
  543. }
  544. convertPrivateNameToPrivateIdentifier(node) {
  545. const name = super.getPrivateNameSV(node);
  546. node = node;
  547. delete node.id;
  548. node.name = name;
  549. node.type = "PrivateIdentifier";
  550. return node;
  551. }
  552. isPrivateName(node) {
  553. {
  554. if (!this.getPluginOption("estree", "classFeatures")) {
  555. return super.isPrivateName(node);
  556. }
  557. }
  558. return node.type === "PrivateIdentifier";
  559. }
  560. getPrivateNameSV(node) {
  561. {
  562. if (!this.getPluginOption("estree", "classFeatures")) {
  563. return super.getPrivateNameSV(node);
  564. }
  565. }
  566. return node.name;
  567. }
  568. parseLiteral(value, type) {
  569. const node = super.parseLiteral(value, type);
  570. node.raw = node.extra.raw;
  571. delete node.extra;
  572. return node;
  573. }
  574. parseFunctionBody(node, allowExpression, isMethod = false) {
  575. super.parseFunctionBody(node, allowExpression, isMethod);
  576. node.expression = node.body.type !== "BlockStatement";
  577. }
  578. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  579. let funcNode = this.startNode();
  580. funcNode.kind = node.kind;
  581. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  582. funcNode.type = "FunctionExpression";
  583. delete funcNode.kind;
  584. node.value = funcNode;
  585. if (type === "ClassPrivateMethod") {
  586. node.computed = false;
  587. }
  588. return this.finishNode(node, "MethodDefinition");
  589. }
  590. parseClassProperty(...args) {
  591. const propertyNode = super.parseClassProperty(...args);
  592. {
  593. if (!this.getPluginOption("estree", "classFeatures")) {
  594. return propertyNode;
  595. }
  596. }
  597. propertyNode.type = "PropertyDefinition";
  598. return propertyNode;
  599. }
  600. parseClassPrivateProperty(...args) {
  601. const propertyNode = super.parseClassPrivateProperty(...args);
  602. {
  603. if (!this.getPluginOption("estree", "classFeatures")) {
  604. return propertyNode;
  605. }
  606. }
  607. propertyNode.type = "PropertyDefinition";
  608. propertyNode.computed = false;
  609. return propertyNode;
  610. }
  611. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  612. const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor);
  613. if (node) {
  614. node.type = "Property";
  615. if (node.kind === "method") {
  616. node.kind = "init";
  617. }
  618. node.shorthand = false;
  619. }
  620. return node;
  621. }
  622. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  623. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  624. if (node) {
  625. node.kind = "init";
  626. node.type = "Property";
  627. }
  628. return node;
  629. }
  630. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  631. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  632. }
  633. isAssignable(node, isBinding) {
  634. if (node != null && this.isObjectProperty(node)) {
  635. return this.isAssignable(node.value, isBinding);
  636. }
  637. return super.isAssignable(node, isBinding);
  638. }
  639. toAssignable(node, isLHS = false) {
  640. if (node != null && this.isObjectProperty(node)) {
  641. const {
  642. key,
  643. value
  644. } = node;
  645. if (this.isPrivateName(key)) {
  646. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  647. }
  648. this.toAssignable(value, isLHS);
  649. } else {
  650. super.toAssignable(node, isLHS);
  651. }
  652. }
  653. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  654. if (prop.kind === "get" || prop.kind === "set") {
  655. this.raise(Errors.PatternHasAccessor, {
  656. at: prop.key
  657. });
  658. } else if (prop.method) {
  659. this.raise(Errors.PatternHasMethod, {
  660. at: prop.key
  661. });
  662. } else {
  663. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  664. }
  665. }
  666. finishCallExpression(unfinished, optional) {
  667. const node = super.finishCallExpression(unfinished, optional);
  668. if (node.callee.type === "Import") {
  669. node.type = "ImportExpression";
  670. node.source = node.arguments[0];
  671. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  672. var _node$arguments$, _node$arguments$2;
  673. node.options = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null;
  674. node.attributes = (_node$arguments$2 = node.arguments[1]) != null ? _node$arguments$2 : null;
  675. }
  676. delete node.arguments;
  677. delete node.callee;
  678. }
  679. return node;
  680. }
  681. toReferencedArguments(node) {
  682. if (node.type === "ImportExpression") {
  683. return;
  684. }
  685. super.toReferencedArguments(node);
  686. }
  687. parseExport(unfinished, decorators) {
  688. const exportStartLoc = this.state.lastTokStartLoc;
  689. const node = super.parseExport(unfinished, decorators);
  690. switch (node.type) {
  691. case "ExportAllDeclaration":
  692. node.exported = null;
  693. break;
  694. case "ExportNamedDeclaration":
  695. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  696. node.type = "ExportAllDeclaration";
  697. node.exported = node.specifiers[0].exported;
  698. delete node.specifiers;
  699. }
  700. case "ExportDefaultDeclaration":
  701. {
  702. var _declaration$decorato;
  703. const {
  704. declaration
  705. } = node;
  706. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  707. this.resetStartLocation(node, exportStartLoc);
  708. }
  709. }
  710. break;
  711. }
  712. return node;
  713. }
  714. parseSubscript(base, startLoc, noCalls, state) {
  715. const node = super.parseSubscript(base, startLoc, noCalls, state);
  716. if (state.optionalChainMember) {
  717. if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") {
  718. node.type = node.type.substring(8);
  719. }
  720. if (state.stop) {
  721. const chain = this.startNodeAtNode(node);
  722. chain.expression = node;
  723. return this.finishNode(chain, "ChainExpression");
  724. }
  725. } else if (node.type === "MemberExpression" || node.type === "CallExpression") {
  726. node.optional = false;
  727. }
  728. return node;
  729. }
  730. isOptionalMemberExpression(node) {
  731. if (node.type === "ChainExpression") {
  732. return node.expression.type === "MemberExpression";
  733. }
  734. return super.isOptionalMemberExpression(node);
  735. }
  736. hasPropertyAsPrivateName(node) {
  737. if (node.type === "ChainExpression") {
  738. node = node.expression;
  739. }
  740. return super.hasPropertyAsPrivateName(node);
  741. }
  742. isObjectProperty(node) {
  743. return node.type === "Property" && node.kind === "init" && !node.method;
  744. }
  745. isObjectMethod(node) {
  746. return node.method || node.kind === "get" || node.kind === "set";
  747. }
  748. finishNodeAt(node, type, endLoc) {
  749. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  750. }
  751. resetStartLocation(node, startLoc) {
  752. super.resetStartLocation(node, startLoc);
  753. toESTreeLocation(node);
  754. }
  755. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  756. super.resetEndLocation(node, endLoc);
  757. toESTreeLocation(node);
  758. }
  759. };
  760. class TokContext {
  761. constructor(token, preserveSpace) {
  762. this.token = void 0;
  763. this.preserveSpace = void 0;
  764. this.token = token;
  765. this.preserveSpace = !!preserveSpace;
  766. }
  767. }
  768. const types = {
  769. brace: new TokContext("{"),
  770. j_oTag: new TokContext("<tag"),
  771. j_cTag: new TokContext("</tag"),
  772. j_expr: new TokContext("<tag>...</tag>", true)
  773. };
  774. {
  775. types.template = new TokContext("`", true);
  776. }
  777. const beforeExpr = true;
  778. const startsExpr = true;
  779. const isLoop = true;
  780. const isAssign = true;
  781. const prefix = true;
  782. const postfix = true;
  783. class ExportedTokenType {
  784. constructor(label, conf = {}) {
  785. this.label = void 0;
  786. this.keyword = void 0;
  787. this.beforeExpr = void 0;
  788. this.startsExpr = void 0;
  789. this.rightAssociative = void 0;
  790. this.isLoop = void 0;
  791. this.isAssign = void 0;
  792. this.prefix = void 0;
  793. this.postfix = void 0;
  794. this.binop = void 0;
  795. this.label = label;
  796. this.keyword = conf.keyword;
  797. this.beforeExpr = !!conf.beforeExpr;
  798. this.startsExpr = !!conf.startsExpr;
  799. this.rightAssociative = !!conf.rightAssociative;
  800. this.isLoop = !!conf.isLoop;
  801. this.isAssign = !!conf.isAssign;
  802. this.prefix = !!conf.prefix;
  803. this.postfix = !!conf.postfix;
  804. this.binop = conf.binop != null ? conf.binop : null;
  805. {
  806. this.updateContext = null;
  807. }
  808. }
  809. }
  810. const keywords$1 = new Map();
  811. function createKeyword(name, options = {}) {
  812. options.keyword = name;
  813. const token = createToken(name, options);
  814. keywords$1.set(name, token);
  815. return token;
  816. }
  817. function createBinop(name, binop) {
  818. return createToken(name, {
  819. beforeExpr,
  820. binop
  821. });
  822. }
  823. let tokenTypeCounter = -1;
  824. const tokenTypes = [];
  825. const tokenLabels = [];
  826. const tokenBinops = [];
  827. const tokenBeforeExprs = [];
  828. const tokenStartsExprs = [];
  829. const tokenPrefixes = [];
  830. function createToken(name, options = {}) {
  831. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  832. ++tokenTypeCounter;
  833. tokenLabels.push(name);
  834. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  835. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  836. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  837. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  838. tokenTypes.push(new ExportedTokenType(name, options));
  839. return tokenTypeCounter;
  840. }
  841. function createKeywordLike(name, options = {}) {
  842. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  843. ++tokenTypeCounter;
  844. keywords$1.set(name, tokenTypeCounter);
  845. tokenLabels.push(name);
  846. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  847. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  848. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  849. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  850. tokenTypes.push(new ExportedTokenType("name", options));
  851. return tokenTypeCounter;
  852. }
  853. const tt = {
  854. bracketL: createToken("[", {
  855. beforeExpr,
  856. startsExpr
  857. }),
  858. bracketHashL: createToken("#[", {
  859. beforeExpr,
  860. startsExpr
  861. }),
  862. bracketBarL: createToken("[|", {
  863. beforeExpr,
  864. startsExpr
  865. }),
  866. bracketR: createToken("]"),
  867. bracketBarR: createToken("|]"),
  868. braceL: createToken("{", {
  869. beforeExpr,
  870. startsExpr
  871. }),
  872. braceBarL: createToken("{|", {
  873. beforeExpr,
  874. startsExpr
  875. }),
  876. braceHashL: createToken("#{", {
  877. beforeExpr,
  878. startsExpr
  879. }),
  880. braceR: createToken("}"),
  881. braceBarR: createToken("|}"),
  882. parenL: createToken("(", {
  883. beforeExpr,
  884. startsExpr
  885. }),
  886. parenR: createToken(")"),
  887. comma: createToken(",", {
  888. beforeExpr
  889. }),
  890. semi: createToken(";", {
  891. beforeExpr
  892. }),
  893. colon: createToken(":", {
  894. beforeExpr
  895. }),
  896. doubleColon: createToken("::", {
  897. beforeExpr
  898. }),
  899. dot: createToken("."),
  900. question: createToken("?", {
  901. beforeExpr
  902. }),
  903. questionDot: createToken("?."),
  904. arrow: createToken("=>", {
  905. beforeExpr
  906. }),
  907. template: createToken("template"),
  908. ellipsis: createToken("...", {
  909. beforeExpr
  910. }),
  911. backQuote: createToken("`", {
  912. startsExpr
  913. }),
  914. dollarBraceL: createToken("${", {
  915. beforeExpr,
  916. startsExpr
  917. }),
  918. templateTail: createToken("...`", {
  919. startsExpr
  920. }),
  921. templateNonTail: createToken("...${", {
  922. beforeExpr,
  923. startsExpr
  924. }),
  925. at: createToken("@"),
  926. hash: createToken("#", {
  927. startsExpr
  928. }),
  929. interpreterDirective: createToken("#!..."),
  930. eq: createToken("=", {
  931. beforeExpr,
  932. isAssign
  933. }),
  934. assign: createToken("_=", {
  935. beforeExpr,
  936. isAssign
  937. }),
  938. slashAssign: createToken("_=", {
  939. beforeExpr,
  940. isAssign
  941. }),
  942. xorAssign: createToken("_=", {
  943. beforeExpr,
  944. isAssign
  945. }),
  946. moduloAssign: createToken("_=", {
  947. beforeExpr,
  948. isAssign
  949. }),
  950. incDec: createToken("++/--", {
  951. prefix,
  952. postfix,
  953. startsExpr
  954. }),
  955. bang: createToken("!", {
  956. beforeExpr,
  957. prefix,
  958. startsExpr
  959. }),
  960. tilde: createToken("~", {
  961. beforeExpr,
  962. prefix,
  963. startsExpr
  964. }),
  965. doubleCaret: createToken("^^", {
  966. startsExpr
  967. }),
  968. doubleAt: createToken("@@", {
  969. startsExpr
  970. }),
  971. pipeline: createBinop("|>", 0),
  972. nullishCoalescing: createBinop("??", 1),
  973. logicalOR: createBinop("||", 1),
  974. logicalAND: createBinop("&&", 2),
  975. bitwiseOR: createBinop("|", 3),
  976. bitwiseXOR: createBinop("^", 4),
  977. bitwiseAND: createBinop("&", 5),
  978. equality: createBinop("==/!=/===/!==", 6),
  979. lt: createBinop("</>/<=/>=", 7),
  980. gt: createBinop("</>/<=/>=", 7),
  981. relational: createBinop("</>/<=/>=", 7),
  982. bitShift: createBinop("<</>>/>>>", 8),
  983. bitShiftL: createBinop("<</>>/>>>", 8),
  984. bitShiftR: createBinop("<</>>/>>>", 8),
  985. plusMin: createToken("+/-", {
  986. beforeExpr,
  987. binop: 9,
  988. prefix,
  989. startsExpr
  990. }),
  991. modulo: createToken("%", {
  992. binop: 10,
  993. startsExpr
  994. }),
  995. star: createToken("*", {
  996. binop: 10
  997. }),
  998. slash: createBinop("/", 10),
  999. exponent: createToken("**", {
  1000. beforeExpr,
  1001. binop: 11,
  1002. rightAssociative: true
  1003. }),
  1004. _in: createKeyword("in", {
  1005. beforeExpr,
  1006. binop: 7
  1007. }),
  1008. _instanceof: createKeyword("instanceof", {
  1009. beforeExpr,
  1010. binop: 7
  1011. }),
  1012. _break: createKeyword("break"),
  1013. _case: createKeyword("case", {
  1014. beforeExpr
  1015. }),
  1016. _catch: createKeyword("catch"),
  1017. _continue: createKeyword("continue"),
  1018. _debugger: createKeyword("debugger"),
  1019. _default: createKeyword("default", {
  1020. beforeExpr
  1021. }),
  1022. _else: createKeyword("else", {
  1023. beforeExpr
  1024. }),
  1025. _finally: createKeyword("finally"),
  1026. _function: createKeyword("function", {
  1027. startsExpr
  1028. }),
  1029. _if: createKeyword("if"),
  1030. _return: createKeyword("return", {
  1031. beforeExpr
  1032. }),
  1033. _switch: createKeyword("switch"),
  1034. _throw: createKeyword("throw", {
  1035. beforeExpr,
  1036. prefix,
  1037. startsExpr
  1038. }),
  1039. _try: createKeyword("try"),
  1040. _var: createKeyword("var"),
  1041. _const: createKeyword("const"),
  1042. _with: createKeyword("with"),
  1043. _new: createKeyword("new", {
  1044. beforeExpr,
  1045. startsExpr
  1046. }),
  1047. _this: createKeyword("this", {
  1048. startsExpr
  1049. }),
  1050. _super: createKeyword("super", {
  1051. startsExpr
  1052. }),
  1053. _class: createKeyword("class", {
  1054. startsExpr
  1055. }),
  1056. _extends: createKeyword("extends", {
  1057. beforeExpr
  1058. }),
  1059. _export: createKeyword("export"),
  1060. _import: createKeyword("import", {
  1061. startsExpr
  1062. }),
  1063. _null: createKeyword("null", {
  1064. startsExpr
  1065. }),
  1066. _true: createKeyword("true", {
  1067. startsExpr
  1068. }),
  1069. _false: createKeyword("false", {
  1070. startsExpr
  1071. }),
  1072. _typeof: createKeyword("typeof", {
  1073. beforeExpr,
  1074. prefix,
  1075. startsExpr
  1076. }),
  1077. _void: createKeyword("void", {
  1078. beforeExpr,
  1079. prefix,
  1080. startsExpr
  1081. }),
  1082. _delete: createKeyword("delete", {
  1083. beforeExpr,
  1084. prefix,
  1085. startsExpr
  1086. }),
  1087. _do: createKeyword("do", {
  1088. isLoop,
  1089. beforeExpr
  1090. }),
  1091. _for: createKeyword("for", {
  1092. isLoop
  1093. }),
  1094. _while: createKeyword("while", {
  1095. isLoop
  1096. }),
  1097. _as: createKeywordLike("as", {
  1098. startsExpr
  1099. }),
  1100. _assert: createKeywordLike("assert", {
  1101. startsExpr
  1102. }),
  1103. _async: createKeywordLike("async", {
  1104. startsExpr
  1105. }),
  1106. _await: createKeywordLike("await", {
  1107. startsExpr
  1108. }),
  1109. _defer: createKeywordLike("defer", {
  1110. startsExpr
  1111. }),
  1112. _from: createKeywordLike("from", {
  1113. startsExpr
  1114. }),
  1115. _get: createKeywordLike("get", {
  1116. startsExpr
  1117. }),
  1118. _let: createKeywordLike("let", {
  1119. startsExpr
  1120. }),
  1121. _meta: createKeywordLike("meta", {
  1122. startsExpr
  1123. }),
  1124. _of: createKeywordLike("of", {
  1125. startsExpr
  1126. }),
  1127. _sent: createKeywordLike("sent", {
  1128. startsExpr
  1129. }),
  1130. _set: createKeywordLike("set", {
  1131. startsExpr
  1132. }),
  1133. _source: createKeywordLike("source", {
  1134. startsExpr
  1135. }),
  1136. _static: createKeywordLike("static", {
  1137. startsExpr
  1138. }),
  1139. _using: createKeywordLike("using", {
  1140. startsExpr
  1141. }),
  1142. _yield: createKeywordLike("yield", {
  1143. startsExpr
  1144. }),
  1145. _asserts: createKeywordLike("asserts", {
  1146. startsExpr
  1147. }),
  1148. _checks: createKeywordLike("checks", {
  1149. startsExpr
  1150. }),
  1151. _exports: createKeywordLike("exports", {
  1152. startsExpr
  1153. }),
  1154. _global: createKeywordLike("global", {
  1155. startsExpr
  1156. }),
  1157. _implements: createKeywordLike("implements", {
  1158. startsExpr
  1159. }),
  1160. _intrinsic: createKeywordLike("intrinsic", {
  1161. startsExpr
  1162. }),
  1163. _infer: createKeywordLike("infer", {
  1164. startsExpr
  1165. }),
  1166. _is: createKeywordLike("is", {
  1167. startsExpr
  1168. }),
  1169. _mixins: createKeywordLike("mixins", {
  1170. startsExpr
  1171. }),
  1172. _proto: createKeywordLike("proto", {
  1173. startsExpr
  1174. }),
  1175. _require: createKeywordLike("require", {
  1176. startsExpr
  1177. }),
  1178. _satisfies: createKeywordLike("satisfies", {
  1179. startsExpr
  1180. }),
  1181. _keyof: createKeywordLike("keyof", {
  1182. startsExpr
  1183. }),
  1184. _readonly: createKeywordLike("readonly", {
  1185. startsExpr
  1186. }),
  1187. _unique: createKeywordLike("unique", {
  1188. startsExpr
  1189. }),
  1190. _abstract: createKeywordLike("abstract", {
  1191. startsExpr
  1192. }),
  1193. _declare: createKeywordLike("declare", {
  1194. startsExpr
  1195. }),
  1196. _enum: createKeywordLike("enum", {
  1197. startsExpr
  1198. }),
  1199. _module: createKeywordLike("module", {
  1200. startsExpr
  1201. }),
  1202. _namespace: createKeywordLike("namespace", {
  1203. startsExpr
  1204. }),
  1205. _interface: createKeywordLike("interface", {
  1206. startsExpr
  1207. }),
  1208. _type: createKeywordLike("type", {
  1209. startsExpr
  1210. }),
  1211. _opaque: createKeywordLike("opaque", {
  1212. startsExpr
  1213. }),
  1214. name: createToken("name", {
  1215. startsExpr
  1216. }),
  1217. string: createToken("string", {
  1218. startsExpr
  1219. }),
  1220. num: createToken("num", {
  1221. startsExpr
  1222. }),
  1223. bigint: createToken("bigint", {
  1224. startsExpr
  1225. }),
  1226. decimal: createToken("decimal", {
  1227. startsExpr
  1228. }),
  1229. regexp: createToken("regexp", {
  1230. startsExpr
  1231. }),
  1232. privateName: createToken("#name", {
  1233. startsExpr
  1234. }),
  1235. eof: createToken("eof"),
  1236. jsxName: createToken("jsxName"),
  1237. jsxText: createToken("jsxText", {
  1238. beforeExpr: true
  1239. }),
  1240. jsxTagStart: createToken("jsxTagStart", {
  1241. startsExpr: true
  1242. }),
  1243. jsxTagEnd: createToken("jsxTagEnd"),
  1244. placeholder: createToken("%%", {
  1245. startsExpr: true
  1246. })
  1247. };
  1248. function tokenIsIdentifier(token) {
  1249. return token >= 93 && token <= 132;
  1250. }
  1251. function tokenKeywordOrIdentifierIsKeyword(token) {
  1252. return token <= 92;
  1253. }
  1254. function tokenIsKeywordOrIdentifier(token) {
  1255. return token >= 58 && token <= 132;
  1256. }
  1257. function tokenIsLiteralPropertyName(token) {
  1258. return token >= 58 && token <= 136;
  1259. }
  1260. function tokenComesBeforeExpression(token) {
  1261. return tokenBeforeExprs[token];
  1262. }
  1263. function tokenCanStartExpression(token) {
  1264. return tokenStartsExprs[token];
  1265. }
  1266. function tokenIsAssignment(token) {
  1267. return token >= 29 && token <= 33;
  1268. }
  1269. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  1270. return token >= 129 && token <= 131;
  1271. }
  1272. function tokenIsLoop(token) {
  1273. return token >= 90 && token <= 92;
  1274. }
  1275. function tokenIsKeyword(token) {
  1276. return token >= 58 && token <= 92;
  1277. }
  1278. function tokenIsOperator(token) {
  1279. return token >= 39 && token <= 59;
  1280. }
  1281. function tokenIsPostfix(token) {
  1282. return token === 34;
  1283. }
  1284. function tokenIsPrefix(token) {
  1285. return tokenPrefixes[token];
  1286. }
  1287. function tokenIsTSTypeOperator(token) {
  1288. return token >= 121 && token <= 123;
  1289. }
  1290. function tokenIsTSDeclarationStart(token) {
  1291. return token >= 124 && token <= 130;
  1292. }
  1293. function tokenLabelName(token) {
  1294. return tokenLabels[token];
  1295. }
  1296. function tokenOperatorPrecedence(token) {
  1297. return tokenBinops[token];
  1298. }
  1299. function tokenIsRightAssociative(token) {
  1300. return token === 57;
  1301. }
  1302. function tokenIsTemplate(token) {
  1303. return token >= 24 && token <= 25;
  1304. }
  1305. function getExportedToken(token) {
  1306. return tokenTypes[token];
  1307. }
  1308. {
  1309. tokenTypes[8].updateContext = context => {
  1310. context.pop();
  1311. };
  1312. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  1313. context.push(types.brace);
  1314. };
  1315. tokenTypes[22].updateContext = context => {
  1316. if (context[context.length - 1] === types.template) {
  1317. context.pop();
  1318. } else {
  1319. context.push(types.template);
  1320. }
  1321. };
  1322. tokenTypes[142].updateContext = context => {
  1323. context.push(types.j_expr, types.j_oTag);
  1324. };
  1325. }
  1326. 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";
  1327. 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\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
  1328. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1329. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1330. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  1331. 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, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
  1332. 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];
  1333. function isInAstralSet(code, set) {
  1334. let pos = 0x10000;
  1335. for (let i = 0, length = set.length; i < length; i += 2) {
  1336. pos += set[i];
  1337. if (pos > code) return false;
  1338. pos += set[i + 1];
  1339. if (pos >= code) return true;
  1340. }
  1341. return false;
  1342. }
  1343. function isIdentifierStart(code) {
  1344. if (code < 65) return code === 36;
  1345. if (code <= 90) return true;
  1346. if (code < 97) return code === 95;
  1347. if (code <= 122) return true;
  1348. if (code <= 0xffff) {
  1349. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  1350. }
  1351. return isInAstralSet(code, astralIdentifierStartCodes);
  1352. }
  1353. function isIdentifierChar(code) {
  1354. if (code < 48) return code === 36;
  1355. if (code < 58) return true;
  1356. if (code < 65) return false;
  1357. if (code <= 90) return true;
  1358. if (code < 97) return code === 95;
  1359. if (code <= 122) return true;
  1360. if (code <= 0xffff) {
  1361. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  1362. }
  1363. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  1364. }
  1365. const reservedWords = {
  1366. 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"],
  1367. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  1368. strictBind: ["eval", "arguments"]
  1369. };
  1370. const keywords = new Set(reservedWords.keyword);
  1371. const reservedWordsStrictSet = new Set(reservedWords.strict);
  1372. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  1373. function isReservedWord(word, inModule) {
  1374. return inModule && word === "await" || word === "enum";
  1375. }
  1376. function isStrictReservedWord(word, inModule) {
  1377. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  1378. }
  1379. function isStrictBindOnlyReservedWord(word) {
  1380. return reservedWordsStrictBindSet.has(word);
  1381. }
  1382. function isStrictBindReservedWord(word, inModule) {
  1383. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  1384. }
  1385. function isKeyword(word) {
  1386. return keywords.has(word);
  1387. }
  1388. function isIteratorStart(current, next, next2) {
  1389. return current === 64 && next === 64 && isIdentifierStart(next2);
  1390. }
  1391. 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"]);
  1392. function canBeReservedWord(word) {
  1393. return reservedWordLikeSet.has(word);
  1394. }
  1395. class Scope {
  1396. constructor(flags) {
  1397. this.var = new Set();
  1398. this.lexical = new Set();
  1399. this.functions = new Set();
  1400. this.flags = flags;
  1401. }
  1402. }
  1403. class ScopeHandler {
  1404. constructor(parser, inModule) {
  1405. this.parser = void 0;
  1406. this.scopeStack = [];
  1407. this.inModule = void 0;
  1408. this.undefinedExports = new Map();
  1409. this.parser = parser;
  1410. this.inModule = inModule;
  1411. }
  1412. get inTopLevel() {
  1413. return (this.currentScope().flags & 1) > 0;
  1414. }
  1415. get inFunction() {
  1416. return (this.currentVarScopeFlags() & 2) > 0;
  1417. }
  1418. get allowSuper() {
  1419. return (this.currentThisScopeFlags() & 16) > 0;
  1420. }
  1421. get allowDirectSuper() {
  1422. return (this.currentThisScopeFlags() & 32) > 0;
  1423. }
  1424. get inClass() {
  1425. return (this.currentThisScopeFlags() & 64) > 0;
  1426. }
  1427. get inClassAndNotInNonArrowFunction() {
  1428. const flags = this.currentThisScopeFlags();
  1429. return (flags & 64) > 0 && (flags & 2) === 0;
  1430. }
  1431. get inStaticBlock() {
  1432. for (let i = this.scopeStack.length - 1;; i--) {
  1433. const {
  1434. flags
  1435. } = this.scopeStack[i];
  1436. if (flags & 128) {
  1437. return true;
  1438. }
  1439. if (flags & (387 | 64)) {
  1440. return false;
  1441. }
  1442. }
  1443. }
  1444. get inNonArrowFunction() {
  1445. return (this.currentThisScopeFlags() & 2) > 0;
  1446. }
  1447. get treatFunctionsAsVar() {
  1448. return this.treatFunctionsAsVarInScope(this.currentScope());
  1449. }
  1450. createScope(flags) {
  1451. return new Scope(flags);
  1452. }
  1453. enter(flags) {
  1454. this.scopeStack.push(this.createScope(flags));
  1455. }
  1456. exit() {
  1457. const scope = this.scopeStack.pop();
  1458. return scope.flags;
  1459. }
  1460. treatFunctionsAsVarInScope(scope) {
  1461. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  1462. }
  1463. declareName(name, bindingType, loc) {
  1464. let scope = this.currentScope();
  1465. if (bindingType & 8 || bindingType & 16) {
  1466. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1467. if (bindingType & 16) {
  1468. scope.functions.add(name);
  1469. } else {
  1470. scope.lexical.add(name);
  1471. }
  1472. if (bindingType & 8) {
  1473. this.maybeExportDefined(scope, name);
  1474. }
  1475. } else if (bindingType & 4) {
  1476. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  1477. scope = this.scopeStack[i];
  1478. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1479. scope.var.add(name);
  1480. this.maybeExportDefined(scope, name);
  1481. if (scope.flags & 387) break;
  1482. }
  1483. }
  1484. if (this.parser.inModule && scope.flags & 1) {
  1485. this.undefinedExports.delete(name);
  1486. }
  1487. }
  1488. maybeExportDefined(scope, name) {
  1489. if (this.parser.inModule && scope.flags & 1) {
  1490. this.undefinedExports.delete(name);
  1491. }
  1492. }
  1493. checkRedeclarationInScope(scope, name, bindingType, loc) {
  1494. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  1495. this.parser.raise(Errors.VarRedeclaration, {
  1496. at: loc,
  1497. identifierName: name
  1498. });
  1499. }
  1500. }
  1501. isRedeclaredInScope(scope, name, bindingType) {
  1502. if (!(bindingType & 1)) return false;
  1503. if (bindingType & 8) {
  1504. return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name);
  1505. }
  1506. if (bindingType & 16) {
  1507. return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name);
  1508. }
  1509. return scope.lexical.has(name) && !(scope.flags & 8 && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name);
  1510. }
  1511. checkLocalExport(id) {
  1512. const {
  1513. name
  1514. } = id;
  1515. const topLevelScope = this.scopeStack[0];
  1516. if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) {
  1517. this.undefinedExports.set(name, id.loc.start);
  1518. }
  1519. }
  1520. currentScope() {
  1521. return this.scopeStack[this.scopeStack.length - 1];
  1522. }
  1523. currentVarScopeFlags() {
  1524. for (let i = this.scopeStack.length - 1;; i--) {
  1525. const {
  1526. flags
  1527. } = this.scopeStack[i];
  1528. if (flags & 387) {
  1529. return flags;
  1530. }
  1531. }
  1532. }
  1533. currentThisScopeFlags() {
  1534. for (let i = this.scopeStack.length - 1;; i--) {
  1535. const {
  1536. flags
  1537. } = this.scopeStack[i];
  1538. if (flags & (387 | 64) && !(flags & 4)) {
  1539. return flags;
  1540. }
  1541. }
  1542. }
  1543. }
  1544. class FlowScope extends Scope {
  1545. constructor(...args) {
  1546. super(...args);
  1547. this.declareFunctions = new Set();
  1548. }
  1549. }
  1550. class FlowScopeHandler extends ScopeHandler {
  1551. createScope(flags) {
  1552. return new FlowScope(flags);
  1553. }
  1554. declareName(name, bindingType, loc) {
  1555. const scope = this.currentScope();
  1556. if (bindingType & 2048) {
  1557. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  1558. this.maybeExportDefined(scope, name);
  1559. scope.declareFunctions.add(name);
  1560. return;
  1561. }
  1562. super.declareName(name, bindingType, loc);
  1563. }
  1564. isRedeclaredInScope(scope, name, bindingType) {
  1565. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  1566. if (bindingType & 2048) {
  1567. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  1568. }
  1569. return false;
  1570. }
  1571. checkLocalExport(id) {
  1572. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  1573. super.checkLocalExport(id);
  1574. }
  1575. }
  1576. }
  1577. class BaseParser {
  1578. constructor() {
  1579. this.sawUnambiguousESM = false;
  1580. this.ambiguousScriptDifferentAst = false;
  1581. }
  1582. hasPlugin(pluginConfig) {
  1583. if (typeof pluginConfig === "string") {
  1584. return this.plugins.has(pluginConfig);
  1585. } else {
  1586. const [pluginName, pluginOptions] = pluginConfig;
  1587. if (!this.hasPlugin(pluginName)) {
  1588. return false;
  1589. }
  1590. const actualOptions = this.plugins.get(pluginName);
  1591. for (const key of Object.keys(pluginOptions)) {
  1592. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  1593. return false;
  1594. }
  1595. }
  1596. return true;
  1597. }
  1598. }
  1599. getPluginOption(plugin, name) {
  1600. var _this$plugins$get;
  1601. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  1602. }
  1603. }
  1604. function setTrailingComments(node, comments) {
  1605. if (node.trailingComments === undefined) {
  1606. node.trailingComments = comments;
  1607. } else {
  1608. node.trailingComments.unshift(...comments);
  1609. }
  1610. }
  1611. function setLeadingComments(node, comments) {
  1612. if (node.leadingComments === undefined) {
  1613. node.leadingComments = comments;
  1614. } else {
  1615. node.leadingComments.unshift(...comments);
  1616. }
  1617. }
  1618. function setInnerComments(node, comments) {
  1619. if (node.innerComments === undefined) {
  1620. node.innerComments = comments;
  1621. } else {
  1622. node.innerComments.unshift(...comments);
  1623. }
  1624. }
  1625. function adjustInnerComments(node, elements, commentWS) {
  1626. let lastElement = null;
  1627. let i = elements.length;
  1628. while (lastElement === null && i > 0) {
  1629. lastElement = elements[--i];
  1630. }
  1631. if (lastElement === null || lastElement.start > commentWS.start) {
  1632. setInnerComments(node, commentWS.comments);
  1633. } else {
  1634. setTrailingComments(lastElement, commentWS.comments);
  1635. }
  1636. }
  1637. class CommentsParser extends BaseParser {
  1638. addComment(comment) {
  1639. if (this.filename) comment.loc.filename = this.filename;
  1640. this.state.comments.push(comment);
  1641. }
  1642. processComment(node) {
  1643. const {
  1644. commentStack
  1645. } = this.state;
  1646. const commentStackLength = commentStack.length;
  1647. if (commentStackLength === 0) return;
  1648. let i = commentStackLength - 1;
  1649. const lastCommentWS = commentStack[i];
  1650. if (lastCommentWS.start === node.end) {
  1651. lastCommentWS.leadingNode = node;
  1652. i--;
  1653. }
  1654. const {
  1655. start: nodeStart
  1656. } = node;
  1657. for (; i >= 0; i--) {
  1658. const commentWS = commentStack[i];
  1659. const commentEnd = commentWS.end;
  1660. if (commentEnd > nodeStart) {
  1661. commentWS.containingNode = node;
  1662. this.finalizeComment(commentWS);
  1663. commentStack.splice(i, 1);
  1664. } else {
  1665. if (commentEnd === nodeStart) {
  1666. commentWS.trailingNode = node;
  1667. }
  1668. break;
  1669. }
  1670. }
  1671. }
  1672. finalizeComment(commentWS) {
  1673. const {
  1674. comments
  1675. } = commentWS;
  1676. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  1677. if (commentWS.leadingNode !== null) {
  1678. setTrailingComments(commentWS.leadingNode, comments);
  1679. }
  1680. if (commentWS.trailingNode !== null) {
  1681. setLeadingComments(commentWS.trailingNode, comments);
  1682. }
  1683. } else {
  1684. const {
  1685. containingNode: node,
  1686. start: commentStart
  1687. } = commentWS;
  1688. if (this.input.charCodeAt(commentStart - 1) === 44) {
  1689. switch (node.type) {
  1690. case "ObjectExpression":
  1691. case "ObjectPattern":
  1692. case "RecordExpression":
  1693. adjustInnerComments(node, node.properties, commentWS);
  1694. break;
  1695. case "CallExpression":
  1696. case "OptionalCallExpression":
  1697. adjustInnerComments(node, node.arguments, commentWS);
  1698. break;
  1699. case "FunctionDeclaration":
  1700. case "FunctionExpression":
  1701. case "ArrowFunctionExpression":
  1702. case "ObjectMethod":
  1703. case "ClassMethod":
  1704. case "ClassPrivateMethod":
  1705. adjustInnerComments(node, node.params, commentWS);
  1706. break;
  1707. case "ArrayExpression":
  1708. case "ArrayPattern":
  1709. case "TupleExpression":
  1710. adjustInnerComments(node, node.elements, commentWS);
  1711. break;
  1712. case "ExportNamedDeclaration":
  1713. case "ImportDeclaration":
  1714. adjustInnerComments(node, node.specifiers, commentWS);
  1715. break;
  1716. default:
  1717. {
  1718. setInnerComments(node, comments);
  1719. }
  1720. }
  1721. } else {
  1722. setInnerComments(node, comments);
  1723. }
  1724. }
  1725. }
  1726. finalizeRemainingComments() {
  1727. const {
  1728. commentStack
  1729. } = this.state;
  1730. for (let i = commentStack.length - 1; i >= 0; i--) {
  1731. this.finalizeComment(commentStack[i]);
  1732. }
  1733. this.state.commentStack = [];
  1734. }
  1735. resetPreviousNodeTrailingComments(node) {
  1736. const {
  1737. commentStack
  1738. } = this.state;
  1739. const {
  1740. length
  1741. } = commentStack;
  1742. if (length === 0) return;
  1743. const commentWS = commentStack[length - 1];
  1744. if (commentWS.leadingNode === node) {
  1745. commentWS.leadingNode = null;
  1746. }
  1747. }
  1748. resetPreviousIdentifierLeadingComments(node) {
  1749. const {
  1750. commentStack
  1751. } = this.state;
  1752. const {
  1753. length
  1754. } = commentStack;
  1755. if (length === 0) return;
  1756. if (commentStack[length - 1].trailingNode === node) {
  1757. commentStack[length - 1].trailingNode = null;
  1758. } else if (length >= 2 && commentStack[length - 2].trailingNode === node) {
  1759. commentStack[length - 2].trailingNode = null;
  1760. }
  1761. }
  1762. takeSurroundingComments(node, start, end) {
  1763. const {
  1764. commentStack
  1765. } = this.state;
  1766. const commentStackLength = commentStack.length;
  1767. if (commentStackLength === 0) return;
  1768. let i = commentStackLength - 1;
  1769. for (; i >= 0; i--) {
  1770. const commentWS = commentStack[i];
  1771. const commentEnd = commentWS.end;
  1772. const commentStart = commentWS.start;
  1773. if (commentStart === end) {
  1774. commentWS.leadingNode = node;
  1775. } else if (commentEnd === start) {
  1776. commentWS.trailingNode = node;
  1777. } else if (commentEnd < start) {
  1778. break;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. const lineBreak = /\r\n?|[\n\u2028\u2029]/;
  1784. const lineBreakG = new RegExp(lineBreak.source, "g");
  1785. function isNewLine(code) {
  1786. switch (code) {
  1787. case 10:
  1788. case 13:
  1789. case 8232:
  1790. case 8233:
  1791. return true;
  1792. default:
  1793. return false;
  1794. }
  1795. }
  1796. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  1797. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  1798. const skipWhiteSpaceToLineBreak = new RegExp("(?=(" + skipWhiteSpaceInLine.source + "))\\1" + /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, "y");
  1799. function isWhitespace(code) {
  1800. switch (code) {
  1801. case 0x0009:
  1802. case 0x000b:
  1803. case 0x000c:
  1804. case 32:
  1805. case 160:
  1806. case 5760:
  1807. case 0x2000:
  1808. case 0x2001:
  1809. case 0x2002:
  1810. case 0x2003:
  1811. case 0x2004:
  1812. case 0x2005:
  1813. case 0x2006:
  1814. case 0x2007:
  1815. case 0x2008:
  1816. case 0x2009:
  1817. case 0x200a:
  1818. case 0x202f:
  1819. case 0x205f:
  1820. case 0x3000:
  1821. case 0xfeff:
  1822. return true;
  1823. default:
  1824. return false;
  1825. }
  1826. }
  1827. class State {
  1828. constructor() {
  1829. this.strict = void 0;
  1830. this.curLine = void 0;
  1831. this.lineStart = void 0;
  1832. this.startLoc = void 0;
  1833. this.endLoc = void 0;
  1834. this.errors = [];
  1835. this.potentialArrowAt = -1;
  1836. this.noArrowAt = [];
  1837. this.noArrowParamsConversionAt = [];
  1838. this.maybeInArrowParameters = false;
  1839. this.inType = false;
  1840. this.noAnonFunctionType = false;
  1841. this.hasFlowComment = false;
  1842. this.isAmbientContext = false;
  1843. this.inAbstractClass = false;
  1844. this.inDisallowConditionalTypesContext = false;
  1845. this.topicContext = {
  1846. maxNumOfResolvableTopics: 0,
  1847. maxTopicIndex: null
  1848. };
  1849. this.soloAwait = false;
  1850. this.inFSharpPipelineDirectBody = false;
  1851. this.labels = [];
  1852. this.comments = [];
  1853. this.commentStack = [];
  1854. this.pos = 0;
  1855. this.type = 139;
  1856. this.value = null;
  1857. this.start = 0;
  1858. this.end = 0;
  1859. this.lastTokEndLoc = null;
  1860. this.lastTokStartLoc = null;
  1861. this.lastTokStart = 0;
  1862. this.context = [types.brace];
  1863. this.canStartJSXElement = true;
  1864. this.containsEsc = false;
  1865. this.firstInvalidTemplateEscapePos = null;
  1866. this.strictErrors = new Map();
  1867. this.tokensLength = 0;
  1868. }
  1869. init({
  1870. strictMode,
  1871. sourceType,
  1872. startLine,
  1873. startColumn
  1874. }) {
  1875. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  1876. this.curLine = startLine;
  1877. this.lineStart = -startColumn;
  1878. this.startLoc = this.endLoc = new Position(startLine, startColumn, 0);
  1879. }
  1880. curPosition() {
  1881. return new Position(this.curLine, this.pos - this.lineStart, this.pos);
  1882. }
  1883. clone(skipArrays) {
  1884. const state = new State();
  1885. const keys = Object.keys(this);
  1886. for (let i = 0, length = keys.length; i < length; i++) {
  1887. const key = keys[i];
  1888. let val = this[key];
  1889. if (!skipArrays && Array.isArray(val)) {
  1890. val = val.slice();
  1891. }
  1892. state[key] = val;
  1893. }
  1894. return state;
  1895. }
  1896. }
  1897. var _isDigit = function isDigit(code) {
  1898. return code >= 48 && code <= 57;
  1899. };
  1900. const forbiddenNumericSeparatorSiblings = {
  1901. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  1902. hex: new Set([46, 88, 95, 120])
  1903. };
  1904. const isAllowedNumericSeparatorSibling = {
  1905. bin: ch => ch === 48 || ch === 49,
  1906. oct: ch => ch >= 48 && ch <= 55,
  1907. dec: ch => ch >= 48 && ch <= 57,
  1908. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  1909. };
  1910. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  1911. const initialPos = pos;
  1912. const initialLineStart = lineStart;
  1913. const initialCurLine = curLine;
  1914. let out = "";
  1915. let firstInvalidLoc = null;
  1916. let chunkStart = pos;
  1917. const {
  1918. length
  1919. } = input;
  1920. for (;;) {
  1921. if (pos >= length) {
  1922. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1923. out += input.slice(chunkStart, pos);
  1924. break;
  1925. }
  1926. const ch = input.charCodeAt(pos);
  1927. if (isStringEnd(type, ch, input, pos)) {
  1928. out += input.slice(chunkStart, pos);
  1929. break;
  1930. }
  1931. if (ch === 92) {
  1932. out += input.slice(chunkStart, pos);
  1933. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  1934. if (res.ch === null && !firstInvalidLoc) {
  1935. firstInvalidLoc = {
  1936. pos,
  1937. lineStart,
  1938. curLine
  1939. };
  1940. } else {
  1941. out += res.ch;
  1942. }
  1943. ({
  1944. pos,
  1945. lineStart,
  1946. curLine
  1947. } = res);
  1948. chunkStart = pos;
  1949. } else if (ch === 8232 || ch === 8233) {
  1950. ++pos;
  1951. ++curLine;
  1952. lineStart = pos;
  1953. } else if (ch === 10 || ch === 13) {
  1954. if (type === "template") {
  1955. out += input.slice(chunkStart, pos) + "\n";
  1956. ++pos;
  1957. if (ch === 13 && input.charCodeAt(pos) === 10) {
  1958. ++pos;
  1959. }
  1960. ++curLine;
  1961. chunkStart = lineStart = pos;
  1962. } else {
  1963. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  1964. }
  1965. } else {
  1966. ++pos;
  1967. }
  1968. }
  1969. return {
  1970. pos,
  1971. str: out,
  1972. firstInvalidLoc,
  1973. lineStart,
  1974. curLine,
  1975. containsInvalid: !!firstInvalidLoc
  1976. };
  1977. }
  1978. function isStringEnd(type, ch, input, pos) {
  1979. if (type === "template") {
  1980. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  1981. }
  1982. return ch === (type === "double" ? 34 : 39);
  1983. }
  1984. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  1985. const throwOnInvalid = !inTemplate;
  1986. pos++;
  1987. const res = ch => ({
  1988. pos,
  1989. ch,
  1990. lineStart,
  1991. curLine
  1992. });
  1993. const ch = input.charCodeAt(pos++);
  1994. switch (ch) {
  1995. case 110:
  1996. return res("\n");
  1997. case 114:
  1998. return res("\r");
  1999. case 120:
  2000. {
  2001. let code;
  2002. ({
  2003. code,
  2004. pos
  2005. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  2006. return res(code === null ? null : String.fromCharCode(code));
  2007. }
  2008. case 117:
  2009. {
  2010. let code;
  2011. ({
  2012. code,
  2013. pos
  2014. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  2015. return res(code === null ? null : String.fromCodePoint(code));
  2016. }
  2017. case 116:
  2018. return res("\t");
  2019. case 98:
  2020. return res("\b");
  2021. case 118:
  2022. return res("\u000b");
  2023. case 102:
  2024. return res("\f");
  2025. case 13:
  2026. if (input.charCodeAt(pos) === 10) {
  2027. ++pos;
  2028. }
  2029. case 10:
  2030. lineStart = pos;
  2031. ++curLine;
  2032. case 8232:
  2033. case 8233:
  2034. return res("");
  2035. case 56:
  2036. case 57:
  2037. if (inTemplate) {
  2038. return res(null);
  2039. } else {
  2040. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  2041. }
  2042. default:
  2043. if (ch >= 48 && ch <= 55) {
  2044. const startPos = pos - 1;
  2045. const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
  2046. let octalStr = match[0];
  2047. let octal = parseInt(octalStr, 8);
  2048. if (octal > 255) {
  2049. octalStr = octalStr.slice(0, -1);
  2050. octal = parseInt(octalStr, 8);
  2051. }
  2052. pos += octalStr.length - 1;
  2053. const next = input.charCodeAt(pos);
  2054. if (octalStr !== "0" || next === 56 || next === 57) {
  2055. if (inTemplate) {
  2056. return res(null);
  2057. } else {
  2058. errors.strictNumericEscape(startPos, lineStart, curLine);
  2059. }
  2060. }
  2061. return res(String.fromCharCode(octal));
  2062. }
  2063. return res(String.fromCharCode(ch));
  2064. }
  2065. }
  2066. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  2067. const initialPos = pos;
  2068. let n;
  2069. ({
  2070. n,
  2071. pos
  2072. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  2073. if (n === null) {
  2074. if (throwOnInvalid) {
  2075. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  2076. } else {
  2077. pos = initialPos - 1;
  2078. }
  2079. }
  2080. return {
  2081. code: n,
  2082. pos
  2083. };
  2084. }
  2085. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  2086. const start = pos;
  2087. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  2088. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  2089. let invalid = false;
  2090. let total = 0;
  2091. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  2092. const code = input.charCodeAt(pos);
  2093. let val;
  2094. if (code === 95 && allowNumSeparator !== "bail") {
  2095. const prev = input.charCodeAt(pos - 1);
  2096. const next = input.charCodeAt(pos + 1);
  2097. if (!allowNumSeparator) {
  2098. if (bailOnError) return {
  2099. n: null,
  2100. pos
  2101. };
  2102. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  2103. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  2104. if (bailOnError) return {
  2105. n: null,
  2106. pos
  2107. };
  2108. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  2109. }
  2110. ++pos;
  2111. continue;
  2112. }
  2113. if (code >= 97) {
  2114. val = code - 97 + 10;
  2115. } else if (code >= 65) {
  2116. val = code - 65 + 10;
  2117. } else if (_isDigit(code)) {
  2118. val = code - 48;
  2119. } else {
  2120. val = Infinity;
  2121. }
  2122. if (val >= radix) {
  2123. if (val <= 9 && bailOnError) {
  2124. return {
  2125. n: null,
  2126. pos
  2127. };
  2128. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  2129. val = 0;
  2130. } else if (forceLen) {
  2131. val = 0;
  2132. invalid = true;
  2133. } else {
  2134. break;
  2135. }
  2136. }
  2137. ++pos;
  2138. total = total * radix + val;
  2139. }
  2140. if (pos === start || len != null && pos - start !== len || invalid) {
  2141. return {
  2142. n: null,
  2143. pos
  2144. };
  2145. }
  2146. return {
  2147. n: total,
  2148. pos
  2149. };
  2150. }
  2151. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  2152. const ch = input.charCodeAt(pos);
  2153. let code;
  2154. if (ch === 123) {
  2155. ++pos;
  2156. ({
  2157. code,
  2158. pos
  2159. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  2160. ++pos;
  2161. if (code !== null && code > 0x10ffff) {
  2162. if (throwOnInvalid) {
  2163. errors.invalidCodePoint(pos, lineStart, curLine);
  2164. } else {
  2165. return {
  2166. code: null,
  2167. pos
  2168. };
  2169. }
  2170. }
  2171. } else {
  2172. ({
  2173. code,
  2174. pos
  2175. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  2176. }
  2177. return {
  2178. code,
  2179. pos
  2180. };
  2181. }
  2182. const _excluded = ["at"],
  2183. _excluded2 = ["at"];
  2184. function buildPosition(pos, lineStart, curLine) {
  2185. return new Position(curLine, pos - lineStart, pos);
  2186. }
  2187. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  2188. class Token {
  2189. constructor(state) {
  2190. this.type = state.type;
  2191. this.value = state.value;
  2192. this.start = state.start;
  2193. this.end = state.end;
  2194. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  2195. }
  2196. }
  2197. class Tokenizer extends CommentsParser {
  2198. constructor(options, input) {
  2199. super();
  2200. this.isLookahead = void 0;
  2201. this.tokens = [];
  2202. this.errorHandlers_readInt = {
  2203. invalidDigit: (pos, lineStart, curLine, radix) => {
  2204. if (!this.options.errorRecovery) return false;
  2205. this.raise(Errors.InvalidDigit, {
  2206. at: buildPosition(pos, lineStart, curLine),
  2207. radix
  2208. });
  2209. return true;
  2210. },
  2211. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  2212. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  2213. };
  2214. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  2215. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  2216. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  2217. });
  2218. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  2219. strictNumericEscape: (pos, lineStart, curLine) => {
  2220. this.recordStrictModeErrors(Errors.StrictNumericEscape, {
  2221. at: buildPosition(pos, lineStart, curLine)
  2222. });
  2223. },
  2224. unterminated: (pos, lineStart, curLine) => {
  2225. throw this.raise(Errors.UnterminatedString, {
  2226. at: buildPosition(pos - 1, lineStart, curLine)
  2227. });
  2228. }
  2229. });
  2230. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  2231. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  2232. unterminated: (pos, lineStart, curLine) => {
  2233. throw this.raise(Errors.UnterminatedTemplate, {
  2234. at: buildPosition(pos, lineStart, curLine)
  2235. });
  2236. }
  2237. });
  2238. this.state = new State();
  2239. this.state.init(options);
  2240. this.input = input;
  2241. this.length = input.length;
  2242. this.isLookahead = false;
  2243. }
  2244. pushToken(token) {
  2245. this.tokens.length = this.state.tokensLength;
  2246. this.tokens.push(token);
  2247. ++this.state.tokensLength;
  2248. }
  2249. next() {
  2250. this.checkKeywordEscapes();
  2251. if (this.options.tokens) {
  2252. this.pushToken(new Token(this.state));
  2253. }
  2254. this.state.lastTokStart = this.state.start;
  2255. this.state.lastTokEndLoc = this.state.endLoc;
  2256. this.state.lastTokStartLoc = this.state.startLoc;
  2257. this.nextToken();
  2258. }
  2259. eat(type) {
  2260. if (this.match(type)) {
  2261. this.next();
  2262. return true;
  2263. } else {
  2264. return false;
  2265. }
  2266. }
  2267. match(type) {
  2268. return this.state.type === type;
  2269. }
  2270. createLookaheadState(state) {
  2271. return {
  2272. pos: state.pos,
  2273. value: null,
  2274. type: state.type,
  2275. start: state.start,
  2276. end: state.end,
  2277. context: [this.curContext()],
  2278. inType: state.inType,
  2279. startLoc: state.startLoc,
  2280. lastTokEndLoc: state.lastTokEndLoc,
  2281. curLine: state.curLine,
  2282. lineStart: state.lineStart,
  2283. curPosition: state.curPosition
  2284. };
  2285. }
  2286. lookahead() {
  2287. const old = this.state;
  2288. this.state = this.createLookaheadState(old);
  2289. this.isLookahead = true;
  2290. this.nextToken();
  2291. this.isLookahead = false;
  2292. const curr = this.state;
  2293. this.state = old;
  2294. return curr;
  2295. }
  2296. nextTokenStart() {
  2297. return this.nextTokenStartSince(this.state.pos);
  2298. }
  2299. nextTokenStartSince(pos) {
  2300. skipWhiteSpace.lastIndex = pos;
  2301. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  2302. }
  2303. lookaheadCharCode() {
  2304. return this.input.charCodeAt(this.nextTokenStart());
  2305. }
  2306. nextTokenInLineStart() {
  2307. return this.nextTokenInLineStartSince(this.state.pos);
  2308. }
  2309. nextTokenInLineStartSince(pos) {
  2310. skipWhiteSpaceInLine.lastIndex = pos;
  2311. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  2312. }
  2313. lookaheadInLineCharCode() {
  2314. return this.input.charCodeAt(this.nextTokenInLineStart());
  2315. }
  2316. codePointAtPos(pos) {
  2317. let cp = this.input.charCodeAt(pos);
  2318. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  2319. const trail = this.input.charCodeAt(pos);
  2320. if ((trail & 0xfc00) === 0xdc00) {
  2321. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  2322. }
  2323. }
  2324. return cp;
  2325. }
  2326. setStrict(strict) {
  2327. this.state.strict = strict;
  2328. if (strict) {
  2329. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, {
  2330. at
  2331. }));
  2332. this.state.strictErrors.clear();
  2333. }
  2334. }
  2335. curContext() {
  2336. return this.state.context[this.state.context.length - 1];
  2337. }
  2338. nextToken() {
  2339. this.skipSpace();
  2340. this.state.start = this.state.pos;
  2341. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  2342. if (this.state.pos >= this.length) {
  2343. this.finishToken(139);
  2344. return;
  2345. }
  2346. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  2347. }
  2348. skipBlockComment(commentEnd) {
  2349. let startLoc;
  2350. if (!this.isLookahead) startLoc = this.state.curPosition();
  2351. const start = this.state.pos;
  2352. const end = this.input.indexOf(commentEnd, start + 2);
  2353. if (end === -1) {
  2354. throw this.raise(Errors.UnterminatedComment, {
  2355. at: this.state.curPosition()
  2356. });
  2357. }
  2358. this.state.pos = end + commentEnd.length;
  2359. lineBreakG.lastIndex = start + 2;
  2360. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  2361. ++this.state.curLine;
  2362. this.state.lineStart = lineBreakG.lastIndex;
  2363. }
  2364. if (this.isLookahead) return;
  2365. const comment = {
  2366. type: "CommentBlock",
  2367. value: this.input.slice(start + 2, end),
  2368. start,
  2369. end: end + commentEnd.length,
  2370. loc: new SourceLocation(startLoc, this.state.curPosition())
  2371. };
  2372. if (this.options.tokens) this.pushToken(comment);
  2373. return comment;
  2374. }
  2375. skipLineComment(startSkip) {
  2376. const start = this.state.pos;
  2377. let startLoc;
  2378. if (!this.isLookahead) startLoc = this.state.curPosition();
  2379. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  2380. if (this.state.pos < this.length) {
  2381. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2382. ch = this.input.charCodeAt(this.state.pos);
  2383. }
  2384. }
  2385. if (this.isLookahead) return;
  2386. const end = this.state.pos;
  2387. const value = this.input.slice(start + startSkip, end);
  2388. const comment = {
  2389. type: "CommentLine",
  2390. value,
  2391. start,
  2392. end,
  2393. loc: new SourceLocation(startLoc, this.state.curPosition())
  2394. };
  2395. if (this.options.tokens) this.pushToken(comment);
  2396. return comment;
  2397. }
  2398. skipSpace() {
  2399. const spaceStart = this.state.pos;
  2400. const comments = [];
  2401. loop: while (this.state.pos < this.length) {
  2402. const ch = this.input.charCodeAt(this.state.pos);
  2403. switch (ch) {
  2404. case 32:
  2405. case 160:
  2406. case 9:
  2407. ++this.state.pos;
  2408. break;
  2409. case 13:
  2410. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  2411. ++this.state.pos;
  2412. }
  2413. case 10:
  2414. case 8232:
  2415. case 8233:
  2416. ++this.state.pos;
  2417. ++this.state.curLine;
  2418. this.state.lineStart = this.state.pos;
  2419. break;
  2420. case 47:
  2421. switch (this.input.charCodeAt(this.state.pos + 1)) {
  2422. case 42:
  2423. {
  2424. const comment = this.skipBlockComment("*/");
  2425. if (comment !== undefined) {
  2426. this.addComment(comment);
  2427. if (this.options.attachComment) comments.push(comment);
  2428. }
  2429. break;
  2430. }
  2431. case 47:
  2432. {
  2433. const comment = this.skipLineComment(2);
  2434. if (comment !== undefined) {
  2435. this.addComment(comment);
  2436. if (this.options.attachComment) comments.push(comment);
  2437. }
  2438. break;
  2439. }
  2440. default:
  2441. break loop;
  2442. }
  2443. break;
  2444. default:
  2445. if (isWhitespace(ch)) {
  2446. ++this.state.pos;
  2447. } else if (ch === 45 && !this.inModule && this.options.annexB) {
  2448. const pos = this.state.pos;
  2449. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  2450. const comment = this.skipLineComment(3);
  2451. if (comment !== undefined) {
  2452. this.addComment(comment);
  2453. if (this.options.attachComment) comments.push(comment);
  2454. }
  2455. } else {
  2456. break loop;
  2457. }
  2458. } else if (ch === 60 && !this.inModule && this.options.annexB) {
  2459. const pos = this.state.pos;
  2460. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  2461. const comment = this.skipLineComment(4);
  2462. if (comment !== undefined) {
  2463. this.addComment(comment);
  2464. if (this.options.attachComment) comments.push(comment);
  2465. }
  2466. } else {
  2467. break loop;
  2468. }
  2469. } else {
  2470. break loop;
  2471. }
  2472. }
  2473. }
  2474. if (comments.length > 0) {
  2475. const end = this.state.pos;
  2476. const commentWhitespace = {
  2477. start: spaceStart,
  2478. end,
  2479. comments,
  2480. leadingNode: null,
  2481. trailingNode: null,
  2482. containingNode: null
  2483. };
  2484. this.state.commentStack.push(commentWhitespace);
  2485. }
  2486. }
  2487. finishToken(type, val) {
  2488. this.state.end = this.state.pos;
  2489. this.state.endLoc = this.state.curPosition();
  2490. const prevType = this.state.type;
  2491. this.state.type = type;
  2492. this.state.value = val;
  2493. if (!this.isLookahead) {
  2494. this.updateContext(prevType);
  2495. }
  2496. }
  2497. replaceToken(type) {
  2498. this.state.type = type;
  2499. this.updateContext();
  2500. }
  2501. readToken_numberSign() {
  2502. if (this.state.pos === 0 && this.readToken_interpreter()) {
  2503. return;
  2504. }
  2505. const nextPos = this.state.pos + 1;
  2506. const next = this.codePointAtPos(nextPos);
  2507. if (next >= 48 && next <= 57) {
  2508. throw this.raise(Errors.UnexpectedDigitAfterHash, {
  2509. at: this.state.curPosition()
  2510. });
  2511. }
  2512. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  2513. this.expectPlugin("recordAndTuple");
  2514. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  2515. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, {
  2516. at: this.state.curPosition()
  2517. });
  2518. }
  2519. this.state.pos += 2;
  2520. if (next === 123) {
  2521. this.finishToken(7);
  2522. } else {
  2523. this.finishToken(1);
  2524. }
  2525. } else if (isIdentifierStart(next)) {
  2526. ++this.state.pos;
  2527. this.finishToken(138, this.readWord1(next));
  2528. } else if (next === 92) {
  2529. ++this.state.pos;
  2530. this.finishToken(138, this.readWord1());
  2531. } else {
  2532. this.finishOp(27, 1);
  2533. }
  2534. }
  2535. readToken_dot() {
  2536. const next = this.input.charCodeAt(this.state.pos + 1);
  2537. if (next >= 48 && next <= 57) {
  2538. this.readNumber(true);
  2539. return;
  2540. }
  2541. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  2542. this.state.pos += 3;
  2543. this.finishToken(21);
  2544. } else {
  2545. ++this.state.pos;
  2546. this.finishToken(16);
  2547. }
  2548. }
  2549. readToken_slash() {
  2550. const next = this.input.charCodeAt(this.state.pos + 1);
  2551. if (next === 61) {
  2552. this.finishOp(31, 2);
  2553. } else {
  2554. this.finishOp(56, 1);
  2555. }
  2556. }
  2557. readToken_interpreter() {
  2558. if (this.state.pos !== 0 || this.length < 2) return false;
  2559. let ch = this.input.charCodeAt(this.state.pos + 1);
  2560. if (ch !== 33) return false;
  2561. const start = this.state.pos;
  2562. this.state.pos += 1;
  2563. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  2564. ch = this.input.charCodeAt(this.state.pos);
  2565. }
  2566. const value = this.input.slice(start + 2, this.state.pos);
  2567. this.finishToken(28, value);
  2568. return true;
  2569. }
  2570. readToken_mult_modulo(code) {
  2571. let type = code === 42 ? 55 : 54;
  2572. let width = 1;
  2573. let next = this.input.charCodeAt(this.state.pos + 1);
  2574. if (code === 42 && next === 42) {
  2575. width++;
  2576. next = this.input.charCodeAt(this.state.pos + 2);
  2577. type = 57;
  2578. }
  2579. if (next === 61 && !this.state.inType) {
  2580. width++;
  2581. type = code === 37 ? 33 : 30;
  2582. }
  2583. this.finishOp(type, width);
  2584. }
  2585. readToken_pipe_amp(code) {
  2586. const next = this.input.charCodeAt(this.state.pos + 1);
  2587. if (next === code) {
  2588. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  2589. this.finishOp(30, 3);
  2590. } else {
  2591. this.finishOp(code === 124 ? 41 : 42, 2);
  2592. }
  2593. return;
  2594. }
  2595. if (code === 124) {
  2596. if (next === 62) {
  2597. this.finishOp(39, 2);
  2598. return;
  2599. }
  2600. if (this.hasPlugin("recordAndTuple") && next === 125) {
  2601. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2602. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, {
  2603. at: this.state.curPosition()
  2604. });
  2605. }
  2606. this.state.pos += 2;
  2607. this.finishToken(9);
  2608. return;
  2609. }
  2610. if (this.hasPlugin("recordAndTuple") && next === 93) {
  2611. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2612. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, {
  2613. at: this.state.curPosition()
  2614. });
  2615. }
  2616. this.state.pos += 2;
  2617. this.finishToken(4);
  2618. return;
  2619. }
  2620. }
  2621. if (next === 61) {
  2622. this.finishOp(30, 2);
  2623. return;
  2624. }
  2625. this.finishOp(code === 124 ? 43 : 45, 1);
  2626. }
  2627. readToken_caret() {
  2628. const next = this.input.charCodeAt(this.state.pos + 1);
  2629. if (next === 61 && !this.state.inType) {
  2630. this.finishOp(32, 2);
  2631. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  2632. proposal: "hack",
  2633. topicToken: "^^"
  2634. }])) {
  2635. this.finishOp(37, 2);
  2636. const lookaheadCh = this.input.codePointAt(this.state.pos);
  2637. if (lookaheadCh === 94) {
  2638. this.unexpected();
  2639. }
  2640. } else {
  2641. this.finishOp(44, 1);
  2642. }
  2643. }
  2644. readToken_atSign() {
  2645. const next = this.input.charCodeAt(this.state.pos + 1);
  2646. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  2647. proposal: "hack",
  2648. topicToken: "@@"
  2649. }])) {
  2650. this.finishOp(38, 2);
  2651. } else {
  2652. this.finishOp(26, 1);
  2653. }
  2654. }
  2655. readToken_plus_min(code) {
  2656. const next = this.input.charCodeAt(this.state.pos + 1);
  2657. if (next === code) {
  2658. this.finishOp(34, 2);
  2659. return;
  2660. }
  2661. if (next === 61) {
  2662. this.finishOp(30, 2);
  2663. } else {
  2664. this.finishOp(53, 1);
  2665. }
  2666. }
  2667. readToken_lt() {
  2668. const {
  2669. pos
  2670. } = this.state;
  2671. const next = this.input.charCodeAt(pos + 1);
  2672. if (next === 60) {
  2673. if (this.input.charCodeAt(pos + 2) === 61) {
  2674. this.finishOp(30, 3);
  2675. return;
  2676. }
  2677. this.finishOp(51, 2);
  2678. return;
  2679. }
  2680. if (next === 61) {
  2681. this.finishOp(49, 2);
  2682. return;
  2683. }
  2684. this.finishOp(47, 1);
  2685. }
  2686. readToken_gt() {
  2687. const {
  2688. pos
  2689. } = this.state;
  2690. const next = this.input.charCodeAt(pos + 1);
  2691. if (next === 62) {
  2692. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  2693. if (this.input.charCodeAt(pos + size) === 61) {
  2694. this.finishOp(30, size + 1);
  2695. return;
  2696. }
  2697. this.finishOp(52, size);
  2698. return;
  2699. }
  2700. if (next === 61) {
  2701. this.finishOp(49, 2);
  2702. return;
  2703. }
  2704. this.finishOp(48, 1);
  2705. }
  2706. readToken_eq_excl(code) {
  2707. const next = this.input.charCodeAt(this.state.pos + 1);
  2708. if (next === 61) {
  2709. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  2710. return;
  2711. }
  2712. if (code === 61 && next === 62) {
  2713. this.state.pos += 2;
  2714. this.finishToken(19);
  2715. return;
  2716. }
  2717. this.finishOp(code === 61 ? 29 : 35, 1);
  2718. }
  2719. readToken_question() {
  2720. const next = this.input.charCodeAt(this.state.pos + 1);
  2721. const next2 = this.input.charCodeAt(this.state.pos + 2);
  2722. if (next === 63) {
  2723. if (next2 === 61) {
  2724. this.finishOp(30, 3);
  2725. } else {
  2726. this.finishOp(40, 2);
  2727. }
  2728. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  2729. this.state.pos += 2;
  2730. this.finishToken(18);
  2731. } else {
  2732. ++this.state.pos;
  2733. this.finishToken(17);
  2734. }
  2735. }
  2736. getTokenFromCode(code) {
  2737. switch (code) {
  2738. case 46:
  2739. this.readToken_dot();
  2740. return;
  2741. case 40:
  2742. ++this.state.pos;
  2743. this.finishToken(10);
  2744. return;
  2745. case 41:
  2746. ++this.state.pos;
  2747. this.finishToken(11);
  2748. return;
  2749. case 59:
  2750. ++this.state.pos;
  2751. this.finishToken(13);
  2752. return;
  2753. case 44:
  2754. ++this.state.pos;
  2755. this.finishToken(12);
  2756. return;
  2757. case 91:
  2758. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2759. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2760. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, {
  2761. at: this.state.curPosition()
  2762. });
  2763. }
  2764. this.state.pos += 2;
  2765. this.finishToken(2);
  2766. } else {
  2767. ++this.state.pos;
  2768. this.finishToken(0);
  2769. }
  2770. return;
  2771. case 93:
  2772. ++this.state.pos;
  2773. this.finishToken(3);
  2774. return;
  2775. case 123:
  2776. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  2777. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  2778. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, {
  2779. at: this.state.curPosition()
  2780. });
  2781. }
  2782. this.state.pos += 2;
  2783. this.finishToken(6);
  2784. } else {
  2785. ++this.state.pos;
  2786. this.finishToken(5);
  2787. }
  2788. return;
  2789. case 125:
  2790. ++this.state.pos;
  2791. this.finishToken(8);
  2792. return;
  2793. case 58:
  2794. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  2795. this.finishOp(15, 2);
  2796. } else {
  2797. ++this.state.pos;
  2798. this.finishToken(14);
  2799. }
  2800. return;
  2801. case 63:
  2802. this.readToken_question();
  2803. return;
  2804. case 96:
  2805. this.readTemplateToken();
  2806. return;
  2807. case 48:
  2808. {
  2809. const next = this.input.charCodeAt(this.state.pos + 1);
  2810. if (next === 120 || next === 88) {
  2811. this.readRadixNumber(16);
  2812. return;
  2813. }
  2814. if (next === 111 || next === 79) {
  2815. this.readRadixNumber(8);
  2816. return;
  2817. }
  2818. if (next === 98 || next === 66) {
  2819. this.readRadixNumber(2);
  2820. return;
  2821. }
  2822. }
  2823. case 49:
  2824. case 50:
  2825. case 51:
  2826. case 52:
  2827. case 53:
  2828. case 54:
  2829. case 55:
  2830. case 56:
  2831. case 57:
  2832. this.readNumber(false);
  2833. return;
  2834. case 34:
  2835. case 39:
  2836. this.readString(code);
  2837. return;
  2838. case 47:
  2839. this.readToken_slash();
  2840. return;
  2841. case 37:
  2842. case 42:
  2843. this.readToken_mult_modulo(code);
  2844. return;
  2845. case 124:
  2846. case 38:
  2847. this.readToken_pipe_amp(code);
  2848. return;
  2849. case 94:
  2850. this.readToken_caret();
  2851. return;
  2852. case 43:
  2853. case 45:
  2854. this.readToken_plus_min(code);
  2855. return;
  2856. case 60:
  2857. this.readToken_lt();
  2858. return;
  2859. case 62:
  2860. this.readToken_gt();
  2861. return;
  2862. case 61:
  2863. case 33:
  2864. this.readToken_eq_excl(code);
  2865. return;
  2866. case 126:
  2867. this.finishOp(36, 1);
  2868. return;
  2869. case 64:
  2870. this.readToken_atSign();
  2871. return;
  2872. case 35:
  2873. this.readToken_numberSign();
  2874. return;
  2875. case 92:
  2876. this.readWord();
  2877. return;
  2878. default:
  2879. if (isIdentifierStart(code)) {
  2880. this.readWord(code);
  2881. return;
  2882. }
  2883. }
  2884. throw this.raise(Errors.InvalidOrUnexpectedToken, {
  2885. at: this.state.curPosition(),
  2886. unexpected: String.fromCodePoint(code)
  2887. });
  2888. }
  2889. finishOp(type, size) {
  2890. const str = this.input.slice(this.state.pos, this.state.pos + size);
  2891. this.state.pos += size;
  2892. this.finishToken(type, str);
  2893. }
  2894. readRegexp() {
  2895. const startLoc = this.state.startLoc;
  2896. const start = this.state.start + 1;
  2897. let escaped, inClass;
  2898. let {
  2899. pos
  2900. } = this.state;
  2901. for (;; ++pos) {
  2902. if (pos >= this.length) {
  2903. throw this.raise(Errors.UnterminatedRegExp, {
  2904. at: createPositionWithColumnOffset(startLoc, 1)
  2905. });
  2906. }
  2907. const ch = this.input.charCodeAt(pos);
  2908. if (isNewLine(ch)) {
  2909. throw this.raise(Errors.UnterminatedRegExp, {
  2910. at: createPositionWithColumnOffset(startLoc, 1)
  2911. });
  2912. }
  2913. if (escaped) {
  2914. escaped = false;
  2915. } else {
  2916. if (ch === 91) {
  2917. inClass = true;
  2918. } else if (ch === 93 && inClass) {
  2919. inClass = false;
  2920. } else if (ch === 47 && !inClass) {
  2921. break;
  2922. }
  2923. escaped = ch === 92;
  2924. }
  2925. }
  2926. const content = this.input.slice(start, pos);
  2927. ++pos;
  2928. let mods = "";
  2929. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  2930. while (pos < this.length) {
  2931. const cp = this.codePointAtPos(pos);
  2932. const char = String.fromCharCode(cp);
  2933. if (VALID_REGEX_FLAGS.has(cp)) {
  2934. if (cp === 118) {
  2935. if (mods.includes("u")) {
  2936. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2937. at: nextPos()
  2938. });
  2939. }
  2940. } else if (cp === 117) {
  2941. if (mods.includes("v")) {
  2942. this.raise(Errors.IncompatibleRegExpUVFlags, {
  2943. at: nextPos()
  2944. });
  2945. }
  2946. }
  2947. if (mods.includes(char)) {
  2948. this.raise(Errors.DuplicateRegExpFlags, {
  2949. at: nextPos()
  2950. });
  2951. }
  2952. } else if (isIdentifierChar(cp) || cp === 92) {
  2953. this.raise(Errors.MalformedRegExpFlags, {
  2954. at: nextPos()
  2955. });
  2956. } else {
  2957. break;
  2958. }
  2959. ++pos;
  2960. mods += char;
  2961. }
  2962. this.state.pos = pos;
  2963. this.finishToken(137, {
  2964. pattern: content,
  2965. flags: mods
  2966. });
  2967. }
  2968. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  2969. const {
  2970. n,
  2971. pos
  2972. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  2973. this.state.pos = pos;
  2974. return n;
  2975. }
  2976. readRadixNumber(radix) {
  2977. const startLoc = this.state.curPosition();
  2978. let isBigInt = false;
  2979. this.state.pos += 2;
  2980. const val = this.readInt(radix);
  2981. if (val == null) {
  2982. this.raise(Errors.InvalidDigit, {
  2983. at: createPositionWithColumnOffset(startLoc, 2),
  2984. radix
  2985. });
  2986. }
  2987. const next = this.input.charCodeAt(this.state.pos);
  2988. if (next === 110) {
  2989. ++this.state.pos;
  2990. isBigInt = true;
  2991. } else if (next === 109) {
  2992. throw this.raise(Errors.InvalidDecimal, {
  2993. at: startLoc
  2994. });
  2995. }
  2996. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  2997. throw this.raise(Errors.NumberIdentifier, {
  2998. at: this.state.curPosition()
  2999. });
  3000. }
  3001. if (isBigInt) {
  3002. const str = this.input.slice(startLoc.index, this.state.pos).replace(/[_n]/g, "");
  3003. this.finishToken(135, str);
  3004. return;
  3005. }
  3006. this.finishToken(134, val);
  3007. }
  3008. readNumber(startsWithDot) {
  3009. const start = this.state.pos;
  3010. const startLoc = this.state.curPosition();
  3011. let isFloat = false;
  3012. let isBigInt = false;
  3013. let isDecimal = false;
  3014. let hasExponent = false;
  3015. let isOctal = false;
  3016. if (!startsWithDot && this.readInt(10) === null) {
  3017. this.raise(Errors.InvalidNumber, {
  3018. at: this.state.curPosition()
  3019. });
  3020. }
  3021. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  3022. if (hasLeadingZero) {
  3023. const integer = this.input.slice(start, this.state.pos);
  3024. this.recordStrictModeErrors(Errors.StrictOctalLiteral, {
  3025. at: startLoc
  3026. });
  3027. if (!this.state.strict) {
  3028. const underscorePos = integer.indexOf("_");
  3029. if (underscorePos > 0) {
  3030. this.raise(Errors.ZeroDigitNumericSeparator, {
  3031. at: createPositionWithColumnOffset(startLoc, underscorePos)
  3032. });
  3033. }
  3034. }
  3035. isOctal = hasLeadingZero && !/[89]/.test(integer);
  3036. }
  3037. let next = this.input.charCodeAt(this.state.pos);
  3038. if (next === 46 && !isOctal) {
  3039. ++this.state.pos;
  3040. this.readInt(10);
  3041. isFloat = true;
  3042. next = this.input.charCodeAt(this.state.pos);
  3043. }
  3044. if ((next === 69 || next === 101) && !isOctal) {
  3045. next = this.input.charCodeAt(++this.state.pos);
  3046. if (next === 43 || next === 45) {
  3047. ++this.state.pos;
  3048. }
  3049. if (this.readInt(10) === null) {
  3050. this.raise(Errors.InvalidOrMissingExponent, {
  3051. at: startLoc
  3052. });
  3053. }
  3054. isFloat = true;
  3055. hasExponent = true;
  3056. next = this.input.charCodeAt(this.state.pos);
  3057. }
  3058. if (next === 110) {
  3059. if (isFloat || hasLeadingZero) {
  3060. this.raise(Errors.InvalidBigIntLiteral, {
  3061. at: startLoc
  3062. });
  3063. }
  3064. ++this.state.pos;
  3065. isBigInt = true;
  3066. }
  3067. if (next === 109) {
  3068. this.expectPlugin("decimal", this.state.curPosition());
  3069. if (hasExponent || hasLeadingZero) {
  3070. this.raise(Errors.InvalidDecimal, {
  3071. at: startLoc
  3072. });
  3073. }
  3074. ++this.state.pos;
  3075. isDecimal = true;
  3076. }
  3077. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  3078. throw this.raise(Errors.NumberIdentifier, {
  3079. at: this.state.curPosition()
  3080. });
  3081. }
  3082. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  3083. if (isBigInt) {
  3084. this.finishToken(135, str);
  3085. return;
  3086. }
  3087. if (isDecimal) {
  3088. this.finishToken(136, str);
  3089. return;
  3090. }
  3091. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  3092. this.finishToken(134, val);
  3093. }
  3094. readCodePoint(throwOnInvalid) {
  3095. const {
  3096. code,
  3097. pos
  3098. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  3099. this.state.pos = pos;
  3100. return code;
  3101. }
  3102. readString(quote) {
  3103. const {
  3104. str,
  3105. pos,
  3106. curLine,
  3107. lineStart
  3108. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  3109. this.state.pos = pos + 1;
  3110. this.state.lineStart = lineStart;
  3111. this.state.curLine = curLine;
  3112. this.finishToken(133, str);
  3113. }
  3114. readTemplateContinuation() {
  3115. if (!this.match(8)) {
  3116. this.unexpected(null, 8);
  3117. }
  3118. this.state.pos--;
  3119. this.readTemplateToken();
  3120. }
  3121. readTemplateToken() {
  3122. const opening = this.input[this.state.pos];
  3123. const {
  3124. str,
  3125. firstInvalidLoc,
  3126. pos,
  3127. curLine,
  3128. lineStart
  3129. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  3130. this.state.pos = pos + 1;
  3131. this.state.lineStart = lineStart;
  3132. this.state.curLine = curLine;
  3133. if (firstInvalidLoc) {
  3134. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, firstInvalidLoc.pos);
  3135. }
  3136. if (this.input.codePointAt(pos) === 96) {
  3137. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  3138. } else {
  3139. this.state.pos++;
  3140. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  3141. }
  3142. }
  3143. recordStrictModeErrors(toParseError, {
  3144. at
  3145. }) {
  3146. const index = at.index;
  3147. if (this.state.strict && !this.state.strictErrors.has(index)) {
  3148. this.raise(toParseError, {
  3149. at
  3150. });
  3151. } else {
  3152. this.state.strictErrors.set(index, [toParseError, at]);
  3153. }
  3154. }
  3155. readWord1(firstCode) {
  3156. this.state.containsEsc = false;
  3157. let word = "";
  3158. const start = this.state.pos;
  3159. let chunkStart = this.state.pos;
  3160. if (firstCode !== undefined) {
  3161. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  3162. }
  3163. while (this.state.pos < this.length) {
  3164. const ch = this.codePointAtPos(this.state.pos);
  3165. if (isIdentifierChar(ch)) {
  3166. this.state.pos += ch <= 0xffff ? 1 : 2;
  3167. } else if (ch === 92) {
  3168. this.state.containsEsc = true;
  3169. word += this.input.slice(chunkStart, this.state.pos);
  3170. const escStart = this.state.curPosition();
  3171. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  3172. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  3173. this.raise(Errors.MissingUnicodeEscape, {
  3174. at: this.state.curPosition()
  3175. });
  3176. chunkStart = this.state.pos - 1;
  3177. continue;
  3178. }
  3179. ++this.state.pos;
  3180. const esc = this.readCodePoint(true);
  3181. if (esc !== null) {
  3182. if (!identifierCheck(esc)) {
  3183. this.raise(Errors.EscapedCharNotAnIdentifier, {
  3184. at: escStart
  3185. });
  3186. }
  3187. word += String.fromCodePoint(esc);
  3188. }
  3189. chunkStart = this.state.pos;
  3190. } else {
  3191. break;
  3192. }
  3193. }
  3194. return word + this.input.slice(chunkStart, this.state.pos);
  3195. }
  3196. readWord(firstCode) {
  3197. const word = this.readWord1(firstCode);
  3198. const type = keywords$1.get(word);
  3199. if (type !== undefined) {
  3200. this.finishToken(type, tokenLabelName(type));
  3201. } else {
  3202. this.finishToken(132, word);
  3203. }
  3204. }
  3205. checkKeywordEscapes() {
  3206. const {
  3207. type
  3208. } = this.state;
  3209. if (tokenIsKeyword(type) && this.state.containsEsc) {
  3210. this.raise(Errors.InvalidEscapedReservedWord, {
  3211. at: this.state.startLoc,
  3212. reservedWord: tokenLabelName(type)
  3213. });
  3214. }
  3215. }
  3216. raise(toParseError, raiseProperties) {
  3217. const {
  3218. at
  3219. } = raiseProperties,
  3220. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded);
  3221. const loc = at instanceof Position ? at : at.loc.start;
  3222. const error = toParseError({
  3223. loc,
  3224. details
  3225. });
  3226. if (!this.options.errorRecovery) throw error;
  3227. if (!this.isLookahead) this.state.errors.push(error);
  3228. return error;
  3229. }
  3230. raiseOverwrite(toParseError, raiseProperties) {
  3231. const {
  3232. at
  3233. } = raiseProperties,
  3234. details = _objectWithoutPropertiesLoose(raiseProperties, _excluded2);
  3235. const loc = at instanceof Position ? at : at.loc.start;
  3236. const pos = loc.index;
  3237. const errors = this.state.errors;
  3238. for (let i = errors.length - 1; i >= 0; i--) {
  3239. const error = errors[i];
  3240. if (error.loc.index === pos) {
  3241. return errors[i] = toParseError({
  3242. loc,
  3243. details
  3244. });
  3245. }
  3246. if (error.loc.index < pos) break;
  3247. }
  3248. return this.raise(toParseError, raiseProperties);
  3249. }
  3250. updateContext(prevType) {}
  3251. unexpected(loc, type) {
  3252. throw this.raise(Errors.UnexpectedToken, {
  3253. expected: type ? tokenLabelName(type) : null,
  3254. at: loc != null ? loc : this.state.startLoc
  3255. });
  3256. }
  3257. expectPlugin(pluginName, loc) {
  3258. if (this.hasPlugin(pluginName)) {
  3259. return true;
  3260. }
  3261. throw this.raise(Errors.MissingPlugin, {
  3262. at: loc != null ? loc : this.state.startLoc,
  3263. missingPlugin: [pluginName]
  3264. });
  3265. }
  3266. expectOnePlugin(pluginNames) {
  3267. if (!pluginNames.some(name => this.hasPlugin(name))) {
  3268. throw this.raise(Errors.MissingOneOfPlugins, {
  3269. at: this.state.startLoc,
  3270. missingPlugin: pluginNames
  3271. });
  3272. }
  3273. }
  3274. errorBuilder(error) {
  3275. return (pos, lineStart, curLine) => {
  3276. this.raise(error, {
  3277. at: buildPosition(pos, lineStart, curLine)
  3278. });
  3279. };
  3280. }
  3281. }
  3282. class ClassScope {
  3283. constructor() {
  3284. this.privateNames = new Set();
  3285. this.loneAccessors = new Map();
  3286. this.undefinedPrivateNames = new Map();
  3287. }
  3288. }
  3289. class ClassScopeHandler {
  3290. constructor(parser) {
  3291. this.parser = void 0;
  3292. this.stack = [];
  3293. this.undefinedPrivateNames = new Map();
  3294. this.parser = parser;
  3295. }
  3296. current() {
  3297. return this.stack[this.stack.length - 1];
  3298. }
  3299. enter() {
  3300. this.stack.push(new ClassScope());
  3301. }
  3302. exit() {
  3303. const oldClassScope = this.stack.pop();
  3304. const current = this.current();
  3305. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  3306. if (current) {
  3307. if (!current.undefinedPrivateNames.has(name)) {
  3308. current.undefinedPrivateNames.set(name, loc);
  3309. }
  3310. } else {
  3311. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3312. at: loc,
  3313. identifierName: name
  3314. });
  3315. }
  3316. }
  3317. }
  3318. declarePrivateName(name, elementType, loc) {
  3319. const {
  3320. privateNames,
  3321. loneAccessors,
  3322. undefinedPrivateNames
  3323. } = this.current();
  3324. let redefined = privateNames.has(name);
  3325. if (elementType & 3) {
  3326. const accessor = redefined && loneAccessors.get(name);
  3327. if (accessor) {
  3328. const oldStatic = accessor & 4;
  3329. const newStatic = elementType & 4;
  3330. const oldKind = accessor & 3;
  3331. const newKind = elementType & 3;
  3332. redefined = oldKind === newKind || oldStatic !== newStatic;
  3333. if (!redefined) loneAccessors.delete(name);
  3334. } else if (!redefined) {
  3335. loneAccessors.set(name, elementType);
  3336. }
  3337. }
  3338. if (redefined) {
  3339. this.parser.raise(Errors.PrivateNameRedeclaration, {
  3340. at: loc,
  3341. identifierName: name
  3342. });
  3343. }
  3344. privateNames.add(name);
  3345. undefinedPrivateNames.delete(name);
  3346. }
  3347. usePrivateName(name, loc) {
  3348. let classScope;
  3349. for (classScope of this.stack) {
  3350. if (classScope.privateNames.has(name)) return;
  3351. }
  3352. if (classScope) {
  3353. classScope.undefinedPrivateNames.set(name, loc);
  3354. } else {
  3355. this.parser.raise(Errors.InvalidPrivateFieldResolution, {
  3356. at: loc,
  3357. identifierName: name
  3358. });
  3359. }
  3360. }
  3361. }
  3362. class ExpressionScope {
  3363. constructor(type = 0) {
  3364. this.type = type;
  3365. }
  3366. canBeArrowParameterDeclaration() {
  3367. return this.type === 2 || this.type === 1;
  3368. }
  3369. isCertainlyParameterDeclaration() {
  3370. return this.type === 3;
  3371. }
  3372. }
  3373. class ArrowHeadParsingScope extends ExpressionScope {
  3374. constructor(type) {
  3375. super(type);
  3376. this.declarationErrors = new Map();
  3377. }
  3378. recordDeclarationError(ParsingErrorClass, {
  3379. at
  3380. }) {
  3381. const index = at.index;
  3382. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  3383. }
  3384. clearDeclarationError(index) {
  3385. this.declarationErrors.delete(index);
  3386. }
  3387. iterateErrors(iterator) {
  3388. this.declarationErrors.forEach(iterator);
  3389. }
  3390. }
  3391. class ExpressionScopeHandler {
  3392. constructor(parser) {
  3393. this.parser = void 0;
  3394. this.stack = [new ExpressionScope()];
  3395. this.parser = parser;
  3396. }
  3397. enter(scope) {
  3398. this.stack.push(scope);
  3399. }
  3400. exit() {
  3401. this.stack.pop();
  3402. }
  3403. recordParameterInitializerError(toParseError, {
  3404. at: node
  3405. }) {
  3406. const origin = {
  3407. at: node.loc.start
  3408. };
  3409. const {
  3410. stack
  3411. } = this;
  3412. let i = stack.length - 1;
  3413. let scope = stack[i];
  3414. while (!scope.isCertainlyParameterDeclaration()) {
  3415. if (scope.canBeArrowParameterDeclaration()) {
  3416. scope.recordDeclarationError(toParseError, origin);
  3417. } else {
  3418. return;
  3419. }
  3420. scope = stack[--i];
  3421. }
  3422. this.parser.raise(toParseError, origin);
  3423. }
  3424. recordArrowParameterBindingError(error, {
  3425. at: node
  3426. }) {
  3427. const {
  3428. stack
  3429. } = this;
  3430. const scope = stack[stack.length - 1];
  3431. const origin = {
  3432. at: node.loc.start
  3433. };
  3434. if (scope.isCertainlyParameterDeclaration()) {
  3435. this.parser.raise(error, origin);
  3436. } else if (scope.canBeArrowParameterDeclaration()) {
  3437. scope.recordDeclarationError(error, origin);
  3438. } else {
  3439. return;
  3440. }
  3441. }
  3442. recordAsyncArrowParametersError({
  3443. at
  3444. }) {
  3445. const {
  3446. stack
  3447. } = this;
  3448. let i = stack.length - 1;
  3449. let scope = stack[i];
  3450. while (scope.canBeArrowParameterDeclaration()) {
  3451. if (scope.type === 2) {
  3452. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, {
  3453. at
  3454. });
  3455. }
  3456. scope = stack[--i];
  3457. }
  3458. }
  3459. validateAsPattern() {
  3460. const {
  3461. stack
  3462. } = this;
  3463. const currentScope = stack[stack.length - 1];
  3464. if (!currentScope.canBeArrowParameterDeclaration()) return;
  3465. currentScope.iterateErrors(([toParseError, loc]) => {
  3466. this.parser.raise(toParseError, {
  3467. at: loc
  3468. });
  3469. let i = stack.length - 2;
  3470. let scope = stack[i];
  3471. while (scope.canBeArrowParameterDeclaration()) {
  3472. scope.clearDeclarationError(loc.index);
  3473. scope = stack[--i];
  3474. }
  3475. });
  3476. }
  3477. }
  3478. function newParameterDeclarationScope() {
  3479. return new ExpressionScope(3);
  3480. }
  3481. function newArrowHeadScope() {
  3482. return new ArrowHeadParsingScope(1);
  3483. }
  3484. function newAsyncArrowScope() {
  3485. return new ArrowHeadParsingScope(2);
  3486. }
  3487. function newExpressionScope() {
  3488. return new ExpressionScope();
  3489. }
  3490. const PARAM = 0b0000,
  3491. PARAM_YIELD = 0b0001,
  3492. PARAM_AWAIT = 0b0010,
  3493. PARAM_RETURN = 0b0100,
  3494. PARAM_IN = 0b1000;
  3495. class ProductionParameterHandler {
  3496. constructor() {
  3497. this.stacks = [];
  3498. }
  3499. enter(flags) {
  3500. this.stacks.push(flags);
  3501. }
  3502. exit() {
  3503. this.stacks.pop();
  3504. }
  3505. currentFlags() {
  3506. return this.stacks[this.stacks.length - 1];
  3507. }
  3508. get hasAwait() {
  3509. return (this.currentFlags() & PARAM_AWAIT) > 0;
  3510. }
  3511. get hasYield() {
  3512. return (this.currentFlags() & PARAM_YIELD) > 0;
  3513. }
  3514. get hasReturn() {
  3515. return (this.currentFlags() & PARAM_RETURN) > 0;
  3516. }
  3517. get hasIn() {
  3518. return (this.currentFlags() & PARAM_IN) > 0;
  3519. }
  3520. }
  3521. function functionFlags(isAsync, isGenerator) {
  3522. return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);
  3523. }
  3524. class UtilParser extends Tokenizer {
  3525. addExtra(node, key, value, enumerable = true) {
  3526. if (!node) return;
  3527. const extra = node.extra = node.extra || {};
  3528. if (enumerable) {
  3529. extra[key] = value;
  3530. } else {
  3531. Object.defineProperty(extra, key, {
  3532. enumerable,
  3533. value
  3534. });
  3535. }
  3536. }
  3537. isContextual(token) {
  3538. return this.state.type === token && !this.state.containsEsc;
  3539. }
  3540. isUnparsedContextual(nameStart, name) {
  3541. const nameEnd = nameStart + name.length;
  3542. if (this.input.slice(nameStart, nameEnd) === name) {
  3543. const nextCh = this.input.charCodeAt(nameEnd);
  3544. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  3545. }
  3546. return false;
  3547. }
  3548. isLookaheadContextual(name) {
  3549. const next = this.nextTokenStart();
  3550. return this.isUnparsedContextual(next, name);
  3551. }
  3552. eatContextual(token) {
  3553. if (this.isContextual(token)) {
  3554. this.next();
  3555. return true;
  3556. }
  3557. return false;
  3558. }
  3559. expectContextual(token, toParseError) {
  3560. if (!this.eatContextual(token)) {
  3561. if (toParseError != null) {
  3562. throw this.raise(toParseError, {
  3563. at: this.state.startLoc
  3564. });
  3565. }
  3566. this.unexpected(null, token);
  3567. }
  3568. }
  3569. canInsertSemicolon() {
  3570. return this.match(139) || this.match(8) || this.hasPrecedingLineBreak();
  3571. }
  3572. hasPrecedingLineBreak() {
  3573. return lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start));
  3574. }
  3575. hasFollowingLineBreak() {
  3576. skipWhiteSpaceToLineBreak.lastIndex = this.state.end;
  3577. return skipWhiteSpaceToLineBreak.test(this.input);
  3578. }
  3579. isLineTerminator() {
  3580. return this.eat(13) || this.canInsertSemicolon();
  3581. }
  3582. semicolon(allowAsi = true) {
  3583. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  3584. this.raise(Errors.MissingSemicolon, {
  3585. at: this.state.lastTokEndLoc
  3586. });
  3587. }
  3588. expect(type, loc) {
  3589. this.eat(type) || this.unexpected(loc, type);
  3590. }
  3591. tryParse(fn, oldState = this.state.clone()) {
  3592. const abortSignal = {
  3593. node: null
  3594. };
  3595. try {
  3596. const node = fn((node = null) => {
  3597. abortSignal.node = node;
  3598. throw abortSignal;
  3599. });
  3600. if (this.state.errors.length > oldState.errors.length) {
  3601. const failState = this.state;
  3602. this.state = oldState;
  3603. this.state.tokensLength = failState.tokensLength;
  3604. return {
  3605. node,
  3606. error: failState.errors[oldState.errors.length],
  3607. thrown: false,
  3608. aborted: false,
  3609. failState
  3610. };
  3611. }
  3612. return {
  3613. node,
  3614. error: null,
  3615. thrown: false,
  3616. aborted: false,
  3617. failState: null
  3618. };
  3619. } catch (error) {
  3620. const failState = this.state;
  3621. this.state = oldState;
  3622. if (error instanceof SyntaxError) {
  3623. return {
  3624. node: null,
  3625. error,
  3626. thrown: true,
  3627. aborted: false,
  3628. failState
  3629. };
  3630. }
  3631. if (error === abortSignal) {
  3632. return {
  3633. node: abortSignal.node,
  3634. error: null,
  3635. thrown: false,
  3636. aborted: true,
  3637. failState
  3638. };
  3639. }
  3640. throw error;
  3641. }
  3642. }
  3643. checkExpressionErrors(refExpressionErrors, andThrow) {
  3644. if (!refExpressionErrors) return false;
  3645. const {
  3646. shorthandAssignLoc,
  3647. doubleProtoLoc,
  3648. privateKeyLoc,
  3649. optionalParametersLoc
  3650. } = refExpressionErrors;
  3651. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc;
  3652. if (!andThrow) {
  3653. return hasErrors;
  3654. }
  3655. if (shorthandAssignLoc != null) {
  3656. this.raise(Errors.InvalidCoverInitializedName, {
  3657. at: shorthandAssignLoc
  3658. });
  3659. }
  3660. if (doubleProtoLoc != null) {
  3661. this.raise(Errors.DuplicateProto, {
  3662. at: doubleProtoLoc
  3663. });
  3664. }
  3665. if (privateKeyLoc != null) {
  3666. this.raise(Errors.UnexpectedPrivateField, {
  3667. at: privateKeyLoc
  3668. });
  3669. }
  3670. if (optionalParametersLoc != null) {
  3671. this.unexpected(optionalParametersLoc);
  3672. }
  3673. }
  3674. isLiteralPropertyName() {
  3675. return tokenIsLiteralPropertyName(this.state.type);
  3676. }
  3677. isPrivateName(node) {
  3678. return node.type === "PrivateName";
  3679. }
  3680. getPrivateNameSV(node) {
  3681. return node.id.name;
  3682. }
  3683. hasPropertyAsPrivateName(node) {
  3684. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  3685. }
  3686. isObjectProperty(node) {
  3687. return node.type === "ObjectProperty";
  3688. }
  3689. isObjectMethod(node) {
  3690. return node.type === "ObjectMethod";
  3691. }
  3692. initializeScopes(inModule = this.options.sourceType === "module") {
  3693. const oldLabels = this.state.labels;
  3694. this.state.labels = [];
  3695. const oldExportedIdentifiers = this.exportedIdentifiers;
  3696. this.exportedIdentifiers = new Set();
  3697. const oldInModule = this.inModule;
  3698. this.inModule = inModule;
  3699. const oldScope = this.scope;
  3700. const ScopeHandler = this.getScopeHandler();
  3701. this.scope = new ScopeHandler(this, inModule);
  3702. const oldProdParam = this.prodParam;
  3703. this.prodParam = new ProductionParameterHandler();
  3704. const oldClassScope = this.classScope;
  3705. this.classScope = new ClassScopeHandler(this);
  3706. const oldExpressionScope = this.expressionScope;
  3707. this.expressionScope = new ExpressionScopeHandler(this);
  3708. return () => {
  3709. this.state.labels = oldLabels;
  3710. this.exportedIdentifiers = oldExportedIdentifiers;
  3711. this.inModule = oldInModule;
  3712. this.scope = oldScope;
  3713. this.prodParam = oldProdParam;
  3714. this.classScope = oldClassScope;
  3715. this.expressionScope = oldExpressionScope;
  3716. };
  3717. }
  3718. enterInitialScopes() {
  3719. let paramFlags = PARAM;
  3720. if (this.inModule) {
  3721. paramFlags |= PARAM_AWAIT;
  3722. }
  3723. this.scope.enter(1);
  3724. this.prodParam.enter(paramFlags);
  3725. }
  3726. checkDestructuringPrivate(refExpressionErrors) {
  3727. const {
  3728. privateKeyLoc
  3729. } = refExpressionErrors;
  3730. if (privateKeyLoc !== null) {
  3731. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  3732. }
  3733. }
  3734. }
  3735. class ExpressionErrors {
  3736. constructor() {
  3737. this.shorthandAssignLoc = null;
  3738. this.doubleProtoLoc = null;
  3739. this.privateKeyLoc = null;
  3740. this.optionalParametersLoc = null;
  3741. }
  3742. }
  3743. class Node {
  3744. constructor(parser, pos, loc) {
  3745. this.type = "";
  3746. this.start = pos;
  3747. this.end = 0;
  3748. this.loc = new SourceLocation(loc);
  3749. if (parser != null && parser.options.ranges) this.range = [pos, 0];
  3750. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  3751. }
  3752. }
  3753. const NodePrototype = Node.prototype;
  3754. {
  3755. NodePrototype.__clone = function () {
  3756. const newNode = new Node(undefined, this.start, this.loc.start);
  3757. const keys = Object.keys(this);
  3758. for (let i = 0, length = keys.length; i < length; i++) {
  3759. const key = keys[i];
  3760. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  3761. newNode[key] = this[key];
  3762. }
  3763. }
  3764. return newNode;
  3765. };
  3766. }
  3767. function clonePlaceholder(node) {
  3768. return cloneIdentifier(node);
  3769. }
  3770. function cloneIdentifier(node) {
  3771. const {
  3772. type,
  3773. start,
  3774. end,
  3775. loc,
  3776. range,
  3777. extra,
  3778. name
  3779. } = node;
  3780. const cloned = Object.create(NodePrototype);
  3781. cloned.type = type;
  3782. cloned.start = start;
  3783. cloned.end = end;
  3784. cloned.loc = loc;
  3785. cloned.range = range;
  3786. cloned.extra = extra;
  3787. cloned.name = name;
  3788. if (type === "Placeholder") {
  3789. cloned.expectedNode = node.expectedNode;
  3790. }
  3791. return cloned;
  3792. }
  3793. function cloneStringLiteral(node) {
  3794. const {
  3795. type,
  3796. start,
  3797. end,
  3798. loc,
  3799. range,
  3800. extra
  3801. } = node;
  3802. if (type === "Placeholder") {
  3803. return clonePlaceholder(node);
  3804. }
  3805. const cloned = Object.create(NodePrototype);
  3806. cloned.type = type;
  3807. cloned.start = start;
  3808. cloned.end = end;
  3809. cloned.loc = loc;
  3810. cloned.range = range;
  3811. if (node.raw !== undefined) {
  3812. cloned.raw = node.raw;
  3813. } else {
  3814. cloned.extra = extra;
  3815. }
  3816. cloned.value = node.value;
  3817. return cloned;
  3818. }
  3819. class NodeUtils extends UtilParser {
  3820. startNode() {
  3821. return new Node(this, this.state.start, this.state.startLoc);
  3822. }
  3823. startNodeAt(loc) {
  3824. return new Node(this, loc.index, loc);
  3825. }
  3826. startNodeAtNode(type) {
  3827. return this.startNodeAt(type.loc.start);
  3828. }
  3829. finishNode(node, type) {
  3830. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  3831. }
  3832. finishNodeAt(node, type, endLoc) {
  3833. node.type = type;
  3834. node.end = endLoc.index;
  3835. node.loc.end = endLoc;
  3836. if (this.options.ranges) node.range[1] = endLoc.index;
  3837. if (this.options.attachComment) this.processComment(node);
  3838. return node;
  3839. }
  3840. resetStartLocation(node, startLoc) {
  3841. node.start = startLoc.index;
  3842. node.loc.start = startLoc;
  3843. if (this.options.ranges) node.range[0] = startLoc.index;
  3844. }
  3845. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3846. node.end = endLoc.index;
  3847. node.loc.end = endLoc;
  3848. if (this.options.ranges) node.range[1] = endLoc.index;
  3849. }
  3850. resetStartLocationFromNode(node, locationNode) {
  3851. this.resetStartLocation(node, locationNode.loc.start);
  3852. }
  3853. }
  3854. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  3855. const FlowErrors = ParseErrorEnum`flow`({
  3856. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  3857. 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.",
  3858. AssignReservedType: ({
  3859. reservedType
  3860. }) => `Cannot overwrite reserved type ${reservedType}.`,
  3861. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  3862. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  3863. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  3864. EnumBooleanMemberNotInitialized: ({
  3865. memberName,
  3866. enumName
  3867. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  3868. EnumDuplicateMemberName: ({
  3869. memberName,
  3870. enumName
  3871. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  3872. EnumInconsistentMemberValues: ({
  3873. enumName
  3874. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  3875. EnumInvalidExplicitType: ({
  3876. invalidEnumType,
  3877. enumName
  3878. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3879. EnumInvalidExplicitTypeUnknownSupplied: ({
  3880. enumName
  3881. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  3882. EnumInvalidMemberInitializerPrimaryType: ({
  3883. enumName,
  3884. memberName,
  3885. explicitType
  3886. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  3887. EnumInvalidMemberInitializerSymbolType: ({
  3888. enumName,
  3889. memberName
  3890. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  3891. EnumInvalidMemberInitializerUnknownType: ({
  3892. enumName,
  3893. memberName
  3894. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  3895. EnumInvalidMemberName: ({
  3896. enumName,
  3897. memberName,
  3898. suggestion
  3899. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  3900. EnumNumberMemberNotInitialized: ({
  3901. enumName,
  3902. memberName
  3903. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  3904. EnumStringMemberInconsistentlyInitialized: ({
  3905. enumName
  3906. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  3907. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  3908. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  3909. 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.",
  3910. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  3911. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  3912. InexactVariance: "Explicit inexact syntax cannot have variance.",
  3913. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  3914. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  3915. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  3916. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  3917. PatternIsOptional: Object.assign({
  3918. message: "A binding pattern parameter cannot be optional in an implementation signature."
  3919. }, {
  3920. reasonCode: "OptionalBindingPattern"
  3921. }),
  3922. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  3923. SpreadVariance: "Spread properties cannot have variance.",
  3924. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  3925. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  3926. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  3927. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  3928. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  3929. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  3930. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  3931. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  3932. UnexpectedReservedType: ({
  3933. reservedType
  3934. }) => `Unexpected reserved type ${reservedType}.`,
  3935. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  3936. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  3937. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  3938. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  3939. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  3940. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  3941. UnsupportedDeclareExportKind: ({
  3942. unsupportedExportKind,
  3943. suggestion
  3944. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  3945. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  3946. UnterminatedFlowComment: "Unterminated flow-comment."
  3947. });
  3948. function isEsModuleType(bodyElement) {
  3949. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  3950. }
  3951. function hasTypeImportKind(node) {
  3952. return node.importKind === "type" || node.importKind === "typeof";
  3953. }
  3954. const exportSuggestions = {
  3955. const: "declare export var",
  3956. let: "declare export var",
  3957. type: "export type",
  3958. interface: "export interface"
  3959. };
  3960. function partition(list, test) {
  3961. const list1 = [];
  3962. const list2 = [];
  3963. for (let i = 0; i < list.length; i++) {
  3964. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  3965. }
  3966. return [list1, list2];
  3967. }
  3968. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  3969. var flow = superClass => class FlowParserMixin extends superClass {
  3970. constructor(...args) {
  3971. super(...args);
  3972. this.flowPragma = undefined;
  3973. }
  3974. getScopeHandler() {
  3975. return FlowScopeHandler;
  3976. }
  3977. shouldParseTypes() {
  3978. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  3979. }
  3980. shouldParseEnums() {
  3981. return !!this.getPluginOption("flow", "enums");
  3982. }
  3983. finishToken(type, val) {
  3984. if (type !== 133 && type !== 13 && type !== 28) {
  3985. if (this.flowPragma === undefined) {
  3986. this.flowPragma = null;
  3987. }
  3988. }
  3989. super.finishToken(type, val);
  3990. }
  3991. addComment(comment) {
  3992. if (this.flowPragma === undefined) {
  3993. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  3994. if (!matches) ;else if (matches[1] === "flow") {
  3995. this.flowPragma = "flow";
  3996. } else if (matches[1] === "noflow") {
  3997. this.flowPragma = "noflow";
  3998. } else {
  3999. throw new Error("Unexpected flow pragma");
  4000. }
  4001. }
  4002. super.addComment(comment);
  4003. }
  4004. flowParseTypeInitialiser(tok) {
  4005. const oldInType = this.state.inType;
  4006. this.state.inType = true;
  4007. this.expect(tok || 14);
  4008. const type = this.flowParseType();
  4009. this.state.inType = oldInType;
  4010. return type;
  4011. }
  4012. flowParsePredicate() {
  4013. const node = this.startNode();
  4014. const moduloLoc = this.state.startLoc;
  4015. this.next();
  4016. this.expectContextual(110);
  4017. if (this.state.lastTokStart > moduloLoc.index + 1) {
  4018. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, {
  4019. at: moduloLoc
  4020. });
  4021. }
  4022. if (this.eat(10)) {
  4023. node.value = super.parseExpression();
  4024. this.expect(11);
  4025. return this.finishNode(node, "DeclaredPredicate");
  4026. } else {
  4027. return this.finishNode(node, "InferredPredicate");
  4028. }
  4029. }
  4030. flowParseTypeAndPredicateInitialiser() {
  4031. const oldInType = this.state.inType;
  4032. this.state.inType = true;
  4033. this.expect(14);
  4034. let type = null;
  4035. let predicate = null;
  4036. if (this.match(54)) {
  4037. this.state.inType = oldInType;
  4038. predicate = this.flowParsePredicate();
  4039. } else {
  4040. type = this.flowParseType();
  4041. this.state.inType = oldInType;
  4042. if (this.match(54)) {
  4043. predicate = this.flowParsePredicate();
  4044. }
  4045. }
  4046. return [type, predicate];
  4047. }
  4048. flowParseDeclareClass(node) {
  4049. this.next();
  4050. this.flowParseInterfaceish(node, true);
  4051. return this.finishNode(node, "DeclareClass");
  4052. }
  4053. flowParseDeclareFunction(node) {
  4054. this.next();
  4055. const id = node.id = this.parseIdentifier();
  4056. const typeNode = this.startNode();
  4057. const typeContainer = this.startNode();
  4058. if (this.match(47)) {
  4059. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4060. } else {
  4061. typeNode.typeParameters = null;
  4062. }
  4063. this.expect(10);
  4064. const tmp = this.flowParseFunctionTypeParams();
  4065. typeNode.params = tmp.params;
  4066. typeNode.rest = tmp.rest;
  4067. typeNode.this = tmp._this;
  4068. this.expect(11);
  4069. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4070. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4071. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4072. this.resetEndLocation(id);
  4073. this.semicolon();
  4074. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4075. return this.finishNode(node, "DeclareFunction");
  4076. }
  4077. flowParseDeclare(node, insideModule) {
  4078. if (this.match(80)) {
  4079. return this.flowParseDeclareClass(node);
  4080. } else if (this.match(68)) {
  4081. return this.flowParseDeclareFunction(node);
  4082. } else if (this.match(74)) {
  4083. return this.flowParseDeclareVariable(node);
  4084. } else if (this.eatContextual(127)) {
  4085. if (this.match(16)) {
  4086. return this.flowParseDeclareModuleExports(node);
  4087. } else {
  4088. if (insideModule) {
  4089. this.raise(FlowErrors.NestedDeclareModule, {
  4090. at: this.state.lastTokStartLoc
  4091. });
  4092. }
  4093. return this.flowParseDeclareModule(node);
  4094. }
  4095. } else if (this.isContextual(130)) {
  4096. return this.flowParseDeclareTypeAlias(node);
  4097. } else if (this.isContextual(131)) {
  4098. return this.flowParseDeclareOpaqueType(node);
  4099. } else if (this.isContextual(129)) {
  4100. return this.flowParseDeclareInterface(node);
  4101. } else if (this.match(82)) {
  4102. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4103. } else {
  4104. this.unexpected();
  4105. }
  4106. }
  4107. flowParseDeclareVariable(node) {
  4108. this.next();
  4109. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4110. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4111. this.semicolon();
  4112. return this.finishNode(node, "DeclareVariable");
  4113. }
  4114. flowParseDeclareModule(node) {
  4115. this.scope.enter(0);
  4116. if (this.match(133)) {
  4117. node.id = super.parseExprAtom();
  4118. } else {
  4119. node.id = this.parseIdentifier();
  4120. }
  4121. const bodyNode = node.body = this.startNode();
  4122. const body = bodyNode.body = [];
  4123. this.expect(5);
  4124. while (!this.match(8)) {
  4125. let bodyNode = this.startNode();
  4126. if (this.match(83)) {
  4127. this.next();
  4128. if (!this.isContextual(130) && !this.match(87)) {
  4129. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, {
  4130. at: this.state.lastTokStartLoc
  4131. });
  4132. }
  4133. super.parseImport(bodyNode);
  4134. } else {
  4135. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4136. bodyNode = this.flowParseDeclare(bodyNode, true);
  4137. }
  4138. body.push(bodyNode);
  4139. }
  4140. this.scope.exit();
  4141. this.expect(8);
  4142. this.finishNode(bodyNode, "BlockStatement");
  4143. let kind = null;
  4144. let hasModuleExport = false;
  4145. body.forEach(bodyElement => {
  4146. if (isEsModuleType(bodyElement)) {
  4147. if (kind === "CommonJS") {
  4148. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4149. at: bodyElement
  4150. });
  4151. }
  4152. kind = "ES";
  4153. } else if (bodyElement.type === "DeclareModuleExports") {
  4154. if (hasModuleExport) {
  4155. this.raise(FlowErrors.DuplicateDeclareModuleExports, {
  4156. at: bodyElement
  4157. });
  4158. }
  4159. if (kind === "ES") {
  4160. this.raise(FlowErrors.AmbiguousDeclareModuleKind, {
  4161. at: bodyElement
  4162. });
  4163. }
  4164. kind = "CommonJS";
  4165. hasModuleExport = true;
  4166. }
  4167. });
  4168. node.kind = kind || "CommonJS";
  4169. return this.finishNode(node, "DeclareModule");
  4170. }
  4171. flowParseDeclareExportDeclaration(node, insideModule) {
  4172. this.expect(82);
  4173. if (this.eat(65)) {
  4174. if (this.match(68) || this.match(80)) {
  4175. node.declaration = this.flowParseDeclare(this.startNode());
  4176. } else {
  4177. node.declaration = this.flowParseType();
  4178. this.semicolon();
  4179. }
  4180. node.default = true;
  4181. return this.finishNode(node, "DeclareExportDeclaration");
  4182. } else {
  4183. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4184. const label = this.state.value;
  4185. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, {
  4186. at: this.state.startLoc,
  4187. unsupportedExportKind: label,
  4188. suggestion: exportSuggestions[label]
  4189. });
  4190. }
  4191. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4192. node.declaration = this.flowParseDeclare(this.startNode());
  4193. node.default = false;
  4194. return this.finishNode(node, "DeclareExportDeclaration");
  4195. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4196. node = this.parseExport(node, null);
  4197. if (node.type === "ExportNamedDeclaration") {
  4198. node.type = "ExportDeclaration";
  4199. node.default = false;
  4200. delete node.exportKind;
  4201. }
  4202. node.type = "Declare" + node.type;
  4203. return node;
  4204. }
  4205. }
  4206. this.unexpected();
  4207. }
  4208. flowParseDeclareModuleExports(node) {
  4209. this.next();
  4210. this.expectContextual(111);
  4211. node.typeAnnotation = this.flowParseTypeAnnotation();
  4212. this.semicolon();
  4213. return this.finishNode(node, "DeclareModuleExports");
  4214. }
  4215. flowParseDeclareTypeAlias(node) {
  4216. this.next();
  4217. const finished = this.flowParseTypeAlias(node);
  4218. finished.type = "DeclareTypeAlias";
  4219. return finished;
  4220. }
  4221. flowParseDeclareOpaqueType(node) {
  4222. this.next();
  4223. const finished = this.flowParseOpaqueType(node, true);
  4224. finished.type = "DeclareOpaqueType";
  4225. return finished;
  4226. }
  4227. flowParseDeclareInterface(node) {
  4228. this.next();
  4229. this.flowParseInterfaceish(node, false);
  4230. return this.finishNode(node, "DeclareInterface");
  4231. }
  4232. flowParseInterfaceish(node, isClass) {
  4233. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4234. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4235. if (this.match(47)) {
  4236. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4237. } else {
  4238. node.typeParameters = null;
  4239. }
  4240. node.extends = [];
  4241. if (this.eat(81)) {
  4242. do {
  4243. node.extends.push(this.flowParseInterfaceExtends());
  4244. } while (!isClass && this.eat(12));
  4245. }
  4246. if (isClass) {
  4247. node.implements = [];
  4248. node.mixins = [];
  4249. if (this.eatContextual(117)) {
  4250. do {
  4251. node.mixins.push(this.flowParseInterfaceExtends());
  4252. } while (this.eat(12));
  4253. }
  4254. if (this.eatContextual(113)) {
  4255. do {
  4256. node.implements.push(this.flowParseInterfaceExtends());
  4257. } while (this.eat(12));
  4258. }
  4259. }
  4260. node.body = this.flowParseObjectType({
  4261. allowStatic: isClass,
  4262. allowExact: false,
  4263. allowSpread: false,
  4264. allowProto: isClass,
  4265. allowInexact: false
  4266. });
  4267. }
  4268. flowParseInterfaceExtends() {
  4269. const node = this.startNode();
  4270. node.id = this.flowParseQualifiedTypeIdentifier();
  4271. if (this.match(47)) {
  4272. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4273. } else {
  4274. node.typeParameters = null;
  4275. }
  4276. return this.finishNode(node, "InterfaceExtends");
  4277. }
  4278. flowParseInterface(node) {
  4279. this.flowParseInterfaceish(node, false);
  4280. return this.finishNode(node, "InterfaceDeclaration");
  4281. }
  4282. checkNotUnderscore(word) {
  4283. if (word === "_") {
  4284. this.raise(FlowErrors.UnexpectedReservedUnderscore, {
  4285. at: this.state.startLoc
  4286. });
  4287. }
  4288. }
  4289. checkReservedType(word, startLoc, declaration) {
  4290. if (!reservedTypes.has(word)) return;
  4291. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, {
  4292. at: startLoc,
  4293. reservedType: word
  4294. });
  4295. }
  4296. flowParseRestrictedIdentifier(liberal, declaration) {
  4297. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4298. return this.parseIdentifier(liberal);
  4299. }
  4300. flowParseTypeAlias(node) {
  4301. node.id = this.flowParseRestrictedIdentifier(false, true);
  4302. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4303. if (this.match(47)) {
  4304. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4305. } else {
  4306. node.typeParameters = null;
  4307. }
  4308. node.right = this.flowParseTypeInitialiser(29);
  4309. this.semicolon();
  4310. return this.finishNode(node, "TypeAlias");
  4311. }
  4312. flowParseOpaqueType(node, declare) {
  4313. this.expectContextual(130);
  4314. node.id = this.flowParseRestrictedIdentifier(true, true);
  4315. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4316. if (this.match(47)) {
  4317. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4318. } else {
  4319. node.typeParameters = null;
  4320. }
  4321. node.supertype = null;
  4322. if (this.match(14)) {
  4323. node.supertype = this.flowParseTypeInitialiser(14);
  4324. }
  4325. node.impltype = null;
  4326. if (!declare) {
  4327. node.impltype = this.flowParseTypeInitialiser(29);
  4328. }
  4329. this.semicolon();
  4330. return this.finishNode(node, "OpaqueType");
  4331. }
  4332. flowParseTypeParameter(requireDefault = false) {
  4333. const nodeStartLoc = this.state.startLoc;
  4334. const node = this.startNode();
  4335. const variance = this.flowParseVariance();
  4336. const ident = this.flowParseTypeAnnotatableIdentifier();
  4337. node.name = ident.name;
  4338. node.variance = variance;
  4339. node.bound = ident.typeAnnotation;
  4340. if (this.match(29)) {
  4341. this.eat(29);
  4342. node.default = this.flowParseType();
  4343. } else {
  4344. if (requireDefault) {
  4345. this.raise(FlowErrors.MissingTypeParamDefault, {
  4346. at: nodeStartLoc
  4347. });
  4348. }
  4349. }
  4350. return this.finishNode(node, "TypeParameter");
  4351. }
  4352. flowParseTypeParameterDeclaration() {
  4353. const oldInType = this.state.inType;
  4354. const node = this.startNode();
  4355. node.params = [];
  4356. this.state.inType = true;
  4357. if (this.match(47) || this.match(142)) {
  4358. this.next();
  4359. } else {
  4360. this.unexpected();
  4361. }
  4362. let defaultRequired = false;
  4363. do {
  4364. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4365. node.params.push(typeParameter);
  4366. if (typeParameter.default) {
  4367. defaultRequired = true;
  4368. }
  4369. if (!this.match(48)) {
  4370. this.expect(12);
  4371. }
  4372. } while (!this.match(48));
  4373. this.expect(48);
  4374. this.state.inType = oldInType;
  4375. return this.finishNode(node, "TypeParameterDeclaration");
  4376. }
  4377. flowParseTypeParameterInstantiation() {
  4378. const node = this.startNode();
  4379. const oldInType = this.state.inType;
  4380. node.params = [];
  4381. this.state.inType = true;
  4382. this.expect(47);
  4383. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4384. this.state.noAnonFunctionType = false;
  4385. while (!this.match(48)) {
  4386. node.params.push(this.flowParseType());
  4387. if (!this.match(48)) {
  4388. this.expect(12);
  4389. }
  4390. }
  4391. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4392. this.expect(48);
  4393. this.state.inType = oldInType;
  4394. return this.finishNode(node, "TypeParameterInstantiation");
  4395. }
  4396. flowParseTypeParameterInstantiationCallOrNew() {
  4397. const node = this.startNode();
  4398. const oldInType = this.state.inType;
  4399. node.params = [];
  4400. this.state.inType = true;
  4401. this.expect(47);
  4402. while (!this.match(48)) {
  4403. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4404. if (!this.match(48)) {
  4405. this.expect(12);
  4406. }
  4407. }
  4408. this.expect(48);
  4409. this.state.inType = oldInType;
  4410. return this.finishNode(node, "TypeParameterInstantiation");
  4411. }
  4412. flowParseInterfaceType() {
  4413. const node = this.startNode();
  4414. this.expectContextual(129);
  4415. node.extends = [];
  4416. if (this.eat(81)) {
  4417. do {
  4418. node.extends.push(this.flowParseInterfaceExtends());
  4419. } while (this.eat(12));
  4420. }
  4421. node.body = this.flowParseObjectType({
  4422. allowStatic: false,
  4423. allowExact: false,
  4424. allowSpread: false,
  4425. allowProto: false,
  4426. allowInexact: false
  4427. });
  4428. return this.finishNode(node, "InterfaceTypeAnnotation");
  4429. }
  4430. flowParseObjectPropertyKey() {
  4431. return this.match(134) || this.match(133) ? super.parseExprAtom() : this.parseIdentifier(true);
  4432. }
  4433. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4434. node.static = isStatic;
  4435. if (this.lookahead().type === 14) {
  4436. node.id = this.flowParseObjectPropertyKey();
  4437. node.key = this.flowParseTypeInitialiser();
  4438. } else {
  4439. node.id = null;
  4440. node.key = this.flowParseType();
  4441. }
  4442. this.expect(3);
  4443. node.value = this.flowParseTypeInitialiser();
  4444. node.variance = variance;
  4445. return this.finishNode(node, "ObjectTypeIndexer");
  4446. }
  4447. flowParseObjectTypeInternalSlot(node, isStatic) {
  4448. node.static = isStatic;
  4449. node.id = this.flowParseObjectPropertyKey();
  4450. this.expect(3);
  4451. this.expect(3);
  4452. if (this.match(47) || this.match(10)) {
  4453. node.method = true;
  4454. node.optional = false;
  4455. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4456. } else {
  4457. node.method = false;
  4458. if (this.eat(17)) {
  4459. node.optional = true;
  4460. }
  4461. node.value = this.flowParseTypeInitialiser();
  4462. }
  4463. return this.finishNode(node, "ObjectTypeInternalSlot");
  4464. }
  4465. flowParseObjectTypeMethodish(node) {
  4466. node.params = [];
  4467. node.rest = null;
  4468. node.typeParameters = null;
  4469. node.this = null;
  4470. if (this.match(47)) {
  4471. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4472. }
  4473. this.expect(10);
  4474. if (this.match(78)) {
  4475. node.this = this.flowParseFunctionTypeParam(true);
  4476. node.this.name = null;
  4477. if (!this.match(11)) {
  4478. this.expect(12);
  4479. }
  4480. }
  4481. while (!this.match(11) && !this.match(21)) {
  4482. node.params.push(this.flowParseFunctionTypeParam(false));
  4483. if (!this.match(11)) {
  4484. this.expect(12);
  4485. }
  4486. }
  4487. if (this.eat(21)) {
  4488. node.rest = this.flowParseFunctionTypeParam(false);
  4489. }
  4490. this.expect(11);
  4491. node.returnType = this.flowParseTypeInitialiser();
  4492. return this.finishNode(node, "FunctionTypeAnnotation");
  4493. }
  4494. flowParseObjectTypeCallProperty(node, isStatic) {
  4495. const valueNode = this.startNode();
  4496. node.static = isStatic;
  4497. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4498. return this.finishNode(node, "ObjectTypeCallProperty");
  4499. }
  4500. flowParseObjectType({
  4501. allowStatic,
  4502. allowExact,
  4503. allowSpread,
  4504. allowProto,
  4505. allowInexact
  4506. }) {
  4507. const oldInType = this.state.inType;
  4508. this.state.inType = true;
  4509. const nodeStart = this.startNode();
  4510. nodeStart.callProperties = [];
  4511. nodeStart.properties = [];
  4512. nodeStart.indexers = [];
  4513. nodeStart.internalSlots = [];
  4514. let endDelim;
  4515. let exact;
  4516. let inexact = false;
  4517. if (allowExact && this.match(6)) {
  4518. this.expect(6);
  4519. endDelim = 9;
  4520. exact = true;
  4521. } else {
  4522. this.expect(5);
  4523. endDelim = 8;
  4524. exact = false;
  4525. }
  4526. nodeStart.exact = exact;
  4527. while (!this.match(endDelim)) {
  4528. let isStatic = false;
  4529. let protoStartLoc = null;
  4530. let inexactStartLoc = null;
  4531. const node = this.startNode();
  4532. if (allowProto && this.isContextual(118)) {
  4533. const lookahead = this.lookahead();
  4534. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4535. this.next();
  4536. protoStartLoc = this.state.startLoc;
  4537. allowStatic = false;
  4538. }
  4539. }
  4540. if (allowStatic && this.isContextual(106)) {
  4541. const lookahead = this.lookahead();
  4542. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4543. this.next();
  4544. isStatic = true;
  4545. }
  4546. }
  4547. const variance = this.flowParseVariance();
  4548. if (this.eat(0)) {
  4549. if (protoStartLoc != null) {
  4550. this.unexpected(protoStartLoc);
  4551. }
  4552. if (this.eat(0)) {
  4553. if (variance) {
  4554. this.unexpected(variance.loc.start);
  4555. }
  4556. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4557. } else {
  4558. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4559. }
  4560. } else if (this.match(10) || this.match(47)) {
  4561. if (protoStartLoc != null) {
  4562. this.unexpected(protoStartLoc);
  4563. }
  4564. if (variance) {
  4565. this.unexpected(variance.loc.start);
  4566. }
  4567. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4568. } else {
  4569. let kind = "init";
  4570. if (this.isContextual(99) || this.isContextual(104)) {
  4571. const lookahead = this.lookahead();
  4572. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4573. kind = this.state.value;
  4574. this.next();
  4575. }
  4576. }
  4577. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4578. if (propOrInexact === null) {
  4579. inexact = true;
  4580. inexactStartLoc = this.state.lastTokStartLoc;
  4581. } else {
  4582. nodeStart.properties.push(propOrInexact);
  4583. }
  4584. }
  4585. this.flowObjectTypeSemicolon();
  4586. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4587. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, {
  4588. at: inexactStartLoc
  4589. });
  4590. }
  4591. }
  4592. this.expect(endDelim);
  4593. if (allowSpread) {
  4594. nodeStart.inexact = inexact;
  4595. }
  4596. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4597. this.state.inType = oldInType;
  4598. return out;
  4599. }
  4600. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4601. if (this.eat(21)) {
  4602. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4603. if (isInexactToken) {
  4604. if (!allowSpread) {
  4605. this.raise(FlowErrors.InexactInsideNonObject, {
  4606. at: this.state.lastTokStartLoc
  4607. });
  4608. } else if (!allowInexact) {
  4609. this.raise(FlowErrors.InexactInsideExact, {
  4610. at: this.state.lastTokStartLoc
  4611. });
  4612. }
  4613. if (variance) {
  4614. this.raise(FlowErrors.InexactVariance, {
  4615. at: variance
  4616. });
  4617. }
  4618. return null;
  4619. }
  4620. if (!allowSpread) {
  4621. this.raise(FlowErrors.UnexpectedSpreadType, {
  4622. at: this.state.lastTokStartLoc
  4623. });
  4624. }
  4625. if (protoStartLoc != null) {
  4626. this.unexpected(protoStartLoc);
  4627. }
  4628. if (variance) {
  4629. this.raise(FlowErrors.SpreadVariance, {
  4630. at: variance
  4631. });
  4632. }
  4633. node.argument = this.flowParseType();
  4634. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4635. } else {
  4636. node.key = this.flowParseObjectPropertyKey();
  4637. node.static = isStatic;
  4638. node.proto = protoStartLoc != null;
  4639. node.kind = kind;
  4640. let optional = false;
  4641. if (this.match(47) || this.match(10)) {
  4642. node.method = true;
  4643. if (protoStartLoc != null) {
  4644. this.unexpected(protoStartLoc);
  4645. }
  4646. if (variance) {
  4647. this.unexpected(variance.loc.start);
  4648. }
  4649. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4650. if (kind === "get" || kind === "set") {
  4651. this.flowCheckGetterSetterParams(node);
  4652. }
  4653. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4654. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  4655. at: node.value.this
  4656. });
  4657. }
  4658. } else {
  4659. if (kind !== "init") this.unexpected();
  4660. node.method = false;
  4661. if (this.eat(17)) {
  4662. optional = true;
  4663. }
  4664. node.value = this.flowParseTypeInitialiser();
  4665. node.variance = variance;
  4666. }
  4667. node.optional = optional;
  4668. return this.finishNode(node, "ObjectTypeProperty");
  4669. }
  4670. }
  4671. flowCheckGetterSetterParams(property) {
  4672. const paramCount = property.kind === "get" ? 0 : 1;
  4673. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4674. if (property.value.this) {
  4675. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, {
  4676. at: property.value.this
  4677. });
  4678. }
  4679. if (length !== paramCount) {
  4680. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  4681. at: property
  4682. });
  4683. }
  4684. if (property.kind === "set" && property.value.rest) {
  4685. this.raise(Errors.BadSetterRestParameter, {
  4686. at: property
  4687. });
  4688. }
  4689. }
  4690. flowObjectTypeSemicolon() {
  4691. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4692. this.unexpected();
  4693. }
  4694. }
  4695. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4696. var _startLoc;
  4697. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  4698. let node = id || this.flowParseRestrictedIdentifier(true);
  4699. while (this.eat(16)) {
  4700. const node2 = this.startNodeAt(startLoc);
  4701. node2.qualification = node;
  4702. node2.id = this.flowParseRestrictedIdentifier(true);
  4703. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4704. }
  4705. return node;
  4706. }
  4707. flowParseGenericType(startLoc, id) {
  4708. const node = this.startNodeAt(startLoc);
  4709. node.typeParameters = null;
  4710. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4711. if (this.match(47)) {
  4712. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4713. }
  4714. return this.finishNode(node, "GenericTypeAnnotation");
  4715. }
  4716. flowParseTypeofType() {
  4717. const node = this.startNode();
  4718. this.expect(87);
  4719. node.argument = this.flowParsePrimaryType();
  4720. return this.finishNode(node, "TypeofTypeAnnotation");
  4721. }
  4722. flowParseTupleType() {
  4723. const node = this.startNode();
  4724. node.types = [];
  4725. this.expect(0);
  4726. while (this.state.pos < this.length && !this.match(3)) {
  4727. node.types.push(this.flowParseType());
  4728. if (this.match(3)) break;
  4729. this.expect(12);
  4730. }
  4731. this.expect(3);
  4732. return this.finishNode(node, "TupleTypeAnnotation");
  4733. }
  4734. flowParseFunctionTypeParam(first) {
  4735. let name = null;
  4736. let optional = false;
  4737. let typeAnnotation = null;
  4738. const node = this.startNode();
  4739. const lh = this.lookahead();
  4740. const isThis = this.state.type === 78;
  4741. if (lh.type === 14 || lh.type === 17) {
  4742. if (isThis && !first) {
  4743. this.raise(FlowErrors.ThisParamMustBeFirst, {
  4744. at: node
  4745. });
  4746. }
  4747. name = this.parseIdentifier(isThis);
  4748. if (this.eat(17)) {
  4749. optional = true;
  4750. if (isThis) {
  4751. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  4752. at: node
  4753. });
  4754. }
  4755. }
  4756. typeAnnotation = this.flowParseTypeInitialiser();
  4757. } else {
  4758. typeAnnotation = this.flowParseType();
  4759. }
  4760. node.name = name;
  4761. node.optional = optional;
  4762. node.typeAnnotation = typeAnnotation;
  4763. return this.finishNode(node, "FunctionTypeParam");
  4764. }
  4765. reinterpretTypeAsFunctionTypeParam(type) {
  4766. const node = this.startNodeAt(type.loc.start);
  4767. node.name = null;
  4768. node.optional = false;
  4769. node.typeAnnotation = type;
  4770. return this.finishNode(node, "FunctionTypeParam");
  4771. }
  4772. flowParseFunctionTypeParams(params = []) {
  4773. let rest = null;
  4774. let _this = null;
  4775. if (this.match(78)) {
  4776. _this = this.flowParseFunctionTypeParam(true);
  4777. _this.name = null;
  4778. if (!this.match(11)) {
  4779. this.expect(12);
  4780. }
  4781. }
  4782. while (!this.match(11) && !this.match(21)) {
  4783. params.push(this.flowParseFunctionTypeParam(false));
  4784. if (!this.match(11)) {
  4785. this.expect(12);
  4786. }
  4787. }
  4788. if (this.eat(21)) {
  4789. rest = this.flowParseFunctionTypeParam(false);
  4790. }
  4791. return {
  4792. params,
  4793. rest,
  4794. _this
  4795. };
  4796. }
  4797. flowIdentToTypeAnnotation(startLoc, node, id) {
  4798. switch (id.name) {
  4799. case "any":
  4800. return this.finishNode(node, "AnyTypeAnnotation");
  4801. case "bool":
  4802. case "boolean":
  4803. return this.finishNode(node, "BooleanTypeAnnotation");
  4804. case "mixed":
  4805. return this.finishNode(node, "MixedTypeAnnotation");
  4806. case "empty":
  4807. return this.finishNode(node, "EmptyTypeAnnotation");
  4808. case "number":
  4809. return this.finishNode(node, "NumberTypeAnnotation");
  4810. case "string":
  4811. return this.finishNode(node, "StringTypeAnnotation");
  4812. case "symbol":
  4813. return this.finishNode(node, "SymbolTypeAnnotation");
  4814. default:
  4815. this.checkNotUnderscore(id.name);
  4816. return this.flowParseGenericType(startLoc, id);
  4817. }
  4818. }
  4819. flowParsePrimaryType() {
  4820. const startLoc = this.state.startLoc;
  4821. const node = this.startNode();
  4822. let tmp;
  4823. let type;
  4824. let isGroupedType = false;
  4825. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4826. switch (this.state.type) {
  4827. case 5:
  4828. return this.flowParseObjectType({
  4829. allowStatic: false,
  4830. allowExact: false,
  4831. allowSpread: true,
  4832. allowProto: false,
  4833. allowInexact: true
  4834. });
  4835. case 6:
  4836. return this.flowParseObjectType({
  4837. allowStatic: false,
  4838. allowExact: true,
  4839. allowSpread: true,
  4840. allowProto: false,
  4841. allowInexact: false
  4842. });
  4843. case 0:
  4844. this.state.noAnonFunctionType = false;
  4845. type = this.flowParseTupleType();
  4846. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4847. return type;
  4848. case 47:
  4849. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4850. this.expect(10);
  4851. tmp = this.flowParseFunctionTypeParams();
  4852. node.params = tmp.params;
  4853. node.rest = tmp.rest;
  4854. node.this = tmp._this;
  4855. this.expect(11);
  4856. this.expect(19);
  4857. node.returnType = this.flowParseType();
  4858. return this.finishNode(node, "FunctionTypeAnnotation");
  4859. case 10:
  4860. this.next();
  4861. if (!this.match(11) && !this.match(21)) {
  4862. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  4863. const token = this.lookahead().type;
  4864. isGroupedType = token !== 17 && token !== 14;
  4865. } else {
  4866. isGroupedType = true;
  4867. }
  4868. }
  4869. if (isGroupedType) {
  4870. this.state.noAnonFunctionType = false;
  4871. type = this.flowParseType();
  4872. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4873. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  4874. this.expect(11);
  4875. return type;
  4876. } else {
  4877. this.eat(12);
  4878. }
  4879. }
  4880. if (type) {
  4881. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  4882. } else {
  4883. tmp = this.flowParseFunctionTypeParams();
  4884. }
  4885. node.params = tmp.params;
  4886. node.rest = tmp.rest;
  4887. node.this = tmp._this;
  4888. this.expect(11);
  4889. this.expect(19);
  4890. node.returnType = this.flowParseType();
  4891. node.typeParameters = null;
  4892. return this.finishNode(node, "FunctionTypeAnnotation");
  4893. case 133:
  4894. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  4895. case 85:
  4896. case 86:
  4897. node.value = this.match(85);
  4898. this.next();
  4899. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  4900. case 53:
  4901. if (this.state.value === "-") {
  4902. this.next();
  4903. if (this.match(134)) {
  4904. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  4905. }
  4906. if (this.match(135)) {
  4907. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  4908. }
  4909. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, {
  4910. at: this.state.startLoc
  4911. });
  4912. }
  4913. this.unexpected();
  4914. return;
  4915. case 134:
  4916. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  4917. case 135:
  4918. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  4919. case 88:
  4920. this.next();
  4921. return this.finishNode(node, "VoidTypeAnnotation");
  4922. case 84:
  4923. this.next();
  4924. return this.finishNode(node, "NullLiteralTypeAnnotation");
  4925. case 78:
  4926. this.next();
  4927. return this.finishNode(node, "ThisTypeAnnotation");
  4928. case 55:
  4929. this.next();
  4930. return this.finishNode(node, "ExistsTypeAnnotation");
  4931. case 87:
  4932. return this.flowParseTypeofType();
  4933. default:
  4934. if (tokenIsKeyword(this.state.type)) {
  4935. const label = tokenLabelName(this.state.type);
  4936. this.next();
  4937. return super.createIdentifier(node, label);
  4938. } else if (tokenIsIdentifier(this.state.type)) {
  4939. if (this.isContextual(129)) {
  4940. return this.flowParseInterfaceType();
  4941. }
  4942. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  4943. }
  4944. }
  4945. this.unexpected();
  4946. }
  4947. flowParsePostfixType() {
  4948. const startLoc = this.state.startLoc;
  4949. let type = this.flowParsePrimaryType();
  4950. let seenOptionalIndexedAccess = false;
  4951. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  4952. const node = this.startNodeAt(startLoc);
  4953. const optional = this.eat(18);
  4954. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  4955. this.expect(0);
  4956. if (!optional && this.match(3)) {
  4957. node.elementType = type;
  4958. this.next();
  4959. type = this.finishNode(node, "ArrayTypeAnnotation");
  4960. } else {
  4961. node.objectType = type;
  4962. node.indexType = this.flowParseType();
  4963. this.expect(3);
  4964. if (seenOptionalIndexedAccess) {
  4965. node.optional = optional;
  4966. type = this.finishNode(node, "OptionalIndexedAccessType");
  4967. } else {
  4968. type = this.finishNode(node, "IndexedAccessType");
  4969. }
  4970. }
  4971. }
  4972. return type;
  4973. }
  4974. flowParsePrefixType() {
  4975. const node = this.startNode();
  4976. if (this.eat(17)) {
  4977. node.typeAnnotation = this.flowParsePrefixType();
  4978. return this.finishNode(node, "NullableTypeAnnotation");
  4979. } else {
  4980. return this.flowParsePostfixType();
  4981. }
  4982. }
  4983. flowParseAnonFunctionWithoutParens() {
  4984. const param = this.flowParsePrefixType();
  4985. if (!this.state.noAnonFunctionType && this.eat(19)) {
  4986. const node = this.startNodeAt(param.loc.start);
  4987. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  4988. node.rest = null;
  4989. node.this = null;
  4990. node.returnType = this.flowParseType();
  4991. node.typeParameters = null;
  4992. return this.finishNode(node, "FunctionTypeAnnotation");
  4993. }
  4994. return param;
  4995. }
  4996. flowParseIntersectionType() {
  4997. const node = this.startNode();
  4998. this.eat(45);
  4999. const type = this.flowParseAnonFunctionWithoutParens();
  5000. node.types = [type];
  5001. while (this.eat(45)) {
  5002. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5003. }
  5004. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5005. }
  5006. flowParseUnionType() {
  5007. const node = this.startNode();
  5008. this.eat(43);
  5009. const type = this.flowParseIntersectionType();
  5010. node.types = [type];
  5011. while (this.eat(43)) {
  5012. node.types.push(this.flowParseIntersectionType());
  5013. }
  5014. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5015. }
  5016. flowParseType() {
  5017. const oldInType = this.state.inType;
  5018. this.state.inType = true;
  5019. const type = this.flowParseUnionType();
  5020. this.state.inType = oldInType;
  5021. return type;
  5022. }
  5023. flowParseTypeOrImplicitInstantiation() {
  5024. if (this.state.type === 132 && this.state.value === "_") {
  5025. const startLoc = this.state.startLoc;
  5026. const node = this.parseIdentifier();
  5027. return this.flowParseGenericType(startLoc, node);
  5028. } else {
  5029. return this.flowParseType();
  5030. }
  5031. }
  5032. flowParseTypeAnnotation() {
  5033. const node = this.startNode();
  5034. node.typeAnnotation = this.flowParseTypeInitialiser();
  5035. return this.finishNode(node, "TypeAnnotation");
  5036. }
  5037. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5038. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5039. if (this.match(14)) {
  5040. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5041. this.resetEndLocation(ident);
  5042. }
  5043. return ident;
  5044. }
  5045. typeCastToParameter(node) {
  5046. node.expression.typeAnnotation = node.typeAnnotation;
  5047. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5048. return node.expression;
  5049. }
  5050. flowParseVariance() {
  5051. let variance = null;
  5052. if (this.match(53)) {
  5053. variance = this.startNode();
  5054. if (this.state.value === "+") {
  5055. variance.kind = "plus";
  5056. } else {
  5057. variance.kind = "minus";
  5058. }
  5059. this.next();
  5060. return this.finishNode(variance, "Variance");
  5061. }
  5062. return variance;
  5063. }
  5064. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5065. if (allowExpressionBody) {
  5066. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5067. return;
  5068. }
  5069. super.parseFunctionBody(node, false, isMethod);
  5070. }
  5071. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5072. if (this.match(14)) {
  5073. const typeNode = this.startNode();
  5074. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5075. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5076. }
  5077. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5078. }
  5079. parseStatementLike(flags) {
  5080. if (this.state.strict && this.isContextual(129)) {
  5081. const lookahead = this.lookahead();
  5082. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5083. const node = this.startNode();
  5084. this.next();
  5085. return this.flowParseInterface(node);
  5086. }
  5087. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5088. const node = this.startNode();
  5089. this.next();
  5090. return this.flowParseEnumDeclaration(node);
  5091. }
  5092. const stmt = super.parseStatementLike(flags);
  5093. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5094. this.flowPragma = null;
  5095. }
  5096. return stmt;
  5097. }
  5098. parseExpressionStatement(node, expr, decorators) {
  5099. if (expr.type === "Identifier") {
  5100. if (expr.name === "declare") {
  5101. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5102. return this.flowParseDeclare(node);
  5103. }
  5104. } else if (tokenIsIdentifier(this.state.type)) {
  5105. if (expr.name === "interface") {
  5106. return this.flowParseInterface(node);
  5107. } else if (expr.name === "type") {
  5108. return this.flowParseTypeAlias(node);
  5109. } else if (expr.name === "opaque") {
  5110. return this.flowParseOpaqueType(node, false);
  5111. }
  5112. }
  5113. }
  5114. return super.parseExpressionStatement(node, expr, decorators);
  5115. }
  5116. shouldParseExportDeclaration() {
  5117. const {
  5118. type
  5119. } = this.state;
  5120. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5121. return !this.state.containsEsc;
  5122. }
  5123. return super.shouldParseExportDeclaration();
  5124. }
  5125. isExportDefaultSpecifier() {
  5126. const {
  5127. type
  5128. } = this.state;
  5129. if (tokenIsFlowInterfaceOrTypeOrOpaque(type) || this.shouldParseEnums() && type === 126) {
  5130. return this.state.containsEsc;
  5131. }
  5132. return super.isExportDefaultSpecifier();
  5133. }
  5134. parseExportDefaultExpression() {
  5135. if (this.shouldParseEnums() && this.isContextual(126)) {
  5136. const node = this.startNode();
  5137. this.next();
  5138. return this.flowParseEnumDeclaration(node);
  5139. }
  5140. return super.parseExportDefaultExpression();
  5141. }
  5142. parseConditional(expr, startLoc, refExpressionErrors) {
  5143. if (!this.match(17)) return expr;
  5144. if (this.state.maybeInArrowParameters) {
  5145. const nextCh = this.lookaheadCharCode();
  5146. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5147. this.setOptionalParametersError(refExpressionErrors);
  5148. return expr;
  5149. }
  5150. }
  5151. this.expect(17);
  5152. const state = this.state.clone();
  5153. const originalNoArrowAt = this.state.noArrowAt;
  5154. const node = this.startNodeAt(startLoc);
  5155. let {
  5156. consequent,
  5157. failed
  5158. } = this.tryParseConditionalConsequent();
  5159. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5160. if (failed || invalid.length > 0) {
  5161. const noArrowAt = [...originalNoArrowAt];
  5162. if (invalid.length > 0) {
  5163. this.state = state;
  5164. this.state.noArrowAt = noArrowAt;
  5165. for (let i = 0; i < invalid.length; i++) {
  5166. noArrowAt.push(invalid[i].start);
  5167. }
  5168. ({
  5169. consequent,
  5170. failed
  5171. } = this.tryParseConditionalConsequent());
  5172. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5173. }
  5174. if (failed && valid.length > 1) {
  5175. this.raise(FlowErrors.AmbiguousConditionalArrow, {
  5176. at: state.startLoc
  5177. });
  5178. }
  5179. if (failed && valid.length === 1) {
  5180. this.state = state;
  5181. noArrowAt.push(valid[0].start);
  5182. this.state.noArrowAt = noArrowAt;
  5183. ({
  5184. consequent,
  5185. failed
  5186. } = this.tryParseConditionalConsequent());
  5187. }
  5188. }
  5189. this.getArrowLikeExpressions(consequent, true);
  5190. this.state.noArrowAt = originalNoArrowAt;
  5191. this.expect(14);
  5192. node.test = expr;
  5193. node.consequent = consequent;
  5194. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5195. return this.finishNode(node, "ConditionalExpression");
  5196. }
  5197. tryParseConditionalConsequent() {
  5198. this.state.noArrowParamsConversionAt.push(this.state.start);
  5199. const consequent = this.parseMaybeAssignAllowIn();
  5200. const failed = !this.match(14);
  5201. this.state.noArrowParamsConversionAt.pop();
  5202. return {
  5203. consequent,
  5204. failed
  5205. };
  5206. }
  5207. getArrowLikeExpressions(node, disallowInvalid) {
  5208. const stack = [node];
  5209. const arrows = [];
  5210. while (stack.length !== 0) {
  5211. const node = stack.pop();
  5212. if (node.type === "ArrowFunctionExpression") {
  5213. if (node.typeParameters || !node.returnType) {
  5214. this.finishArrowValidation(node);
  5215. } else {
  5216. arrows.push(node);
  5217. }
  5218. stack.push(node.body);
  5219. } else if (node.type === "ConditionalExpression") {
  5220. stack.push(node.consequent);
  5221. stack.push(node.alternate);
  5222. }
  5223. }
  5224. if (disallowInvalid) {
  5225. arrows.forEach(node => this.finishArrowValidation(node));
  5226. return [arrows, []];
  5227. }
  5228. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5229. }
  5230. finishArrowValidation(node) {
  5231. var _node$extra;
  5232. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5233. this.scope.enter(2 | 4);
  5234. super.checkParams(node, false, true);
  5235. this.scope.exit();
  5236. }
  5237. forwardNoArrowParamsConversionAt(node, parse) {
  5238. let result;
  5239. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5240. this.state.noArrowParamsConversionAt.push(this.state.start);
  5241. result = parse();
  5242. this.state.noArrowParamsConversionAt.pop();
  5243. } else {
  5244. result = parse();
  5245. }
  5246. return result;
  5247. }
  5248. parseParenItem(node, startLoc) {
  5249. node = super.parseParenItem(node, startLoc);
  5250. if (this.eat(17)) {
  5251. node.optional = true;
  5252. this.resetEndLocation(node);
  5253. }
  5254. if (this.match(14)) {
  5255. const typeCastNode = this.startNodeAt(startLoc);
  5256. typeCastNode.expression = node;
  5257. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5258. return this.finishNode(typeCastNode, "TypeCastExpression");
  5259. }
  5260. return node;
  5261. }
  5262. assertModuleNodeAllowed(node) {
  5263. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5264. return;
  5265. }
  5266. super.assertModuleNodeAllowed(node);
  5267. }
  5268. parseExportDeclaration(node) {
  5269. if (this.isContextual(130)) {
  5270. node.exportKind = "type";
  5271. const declarationNode = this.startNode();
  5272. this.next();
  5273. if (this.match(5)) {
  5274. node.specifiers = this.parseExportSpecifiers(true);
  5275. super.parseExportFrom(node);
  5276. return null;
  5277. } else {
  5278. return this.flowParseTypeAlias(declarationNode);
  5279. }
  5280. } else if (this.isContextual(131)) {
  5281. node.exportKind = "type";
  5282. const declarationNode = this.startNode();
  5283. this.next();
  5284. return this.flowParseOpaqueType(declarationNode, false);
  5285. } else if (this.isContextual(129)) {
  5286. node.exportKind = "type";
  5287. const declarationNode = this.startNode();
  5288. this.next();
  5289. return this.flowParseInterface(declarationNode);
  5290. } else if (this.shouldParseEnums() && this.isContextual(126)) {
  5291. node.exportKind = "value";
  5292. const declarationNode = this.startNode();
  5293. this.next();
  5294. return this.flowParseEnumDeclaration(declarationNode);
  5295. } else {
  5296. return super.parseExportDeclaration(node);
  5297. }
  5298. }
  5299. eatExportStar(node) {
  5300. if (super.eatExportStar(node)) return true;
  5301. if (this.isContextual(130) && this.lookahead().type === 55) {
  5302. node.exportKind = "type";
  5303. this.next();
  5304. this.next();
  5305. return true;
  5306. }
  5307. return false;
  5308. }
  5309. maybeParseExportNamespaceSpecifier(node) {
  5310. const {
  5311. startLoc
  5312. } = this.state;
  5313. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5314. if (hasNamespace && node.exportKind === "type") {
  5315. this.unexpected(startLoc);
  5316. }
  5317. return hasNamespace;
  5318. }
  5319. parseClassId(node, isStatement, optionalId) {
  5320. super.parseClassId(node, isStatement, optionalId);
  5321. if (this.match(47)) {
  5322. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5323. }
  5324. }
  5325. parseClassMember(classBody, member, state) {
  5326. const {
  5327. startLoc
  5328. } = this.state;
  5329. if (this.isContextual(125)) {
  5330. if (super.parseClassMemberFromModifier(classBody, member)) {
  5331. return;
  5332. }
  5333. member.declare = true;
  5334. }
  5335. super.parseClassMember(classBody, member, state);
  5336. if (member.declare) {
  5337. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5338. this.raise(FlowErrors.DeclareClassElement, {
  5339. at: startLoc
  5340. });
  5341. } else if (member.value) {
  5342. this.raise(FlowErrors.DeclareClassFieldInitializer, {
  5343. at: member.value
  5344. });
  5345. }
  5346. }
  5347. }
  5348. isIterator(word) {
  5349. return word === "iterator" || word === "asyncIterator";
  5350. }
  5351. readIterator() {
  5352. const word = super.readWord1();
  5353. const fullWord = "@@" + word;
  5354. if (!this.isIterator(word) || !this.state.inType) {
  5355. this.raise(Errors.InvalidIdentifier, {
  5356. at: this.state.curPosition(),
  5357. identifierName: fullWord
  5358. });
  5359. }
  5360. this.finishToken(132, fullWord);
  5361. }
  5362. getTokenFromCode(code) {
  5363. const next = this.input.charCodeAt(this.state.pos + 1);
  5364. if (code === 123 && next === 124) {
  5365. this.finishOp(6, 2);
  5366. } else if (this.state.inType && (code === 62 || code === 60)) {
  5367. this.finishOp(code === 62 ? 48 : 47, 1);
  5368. } else if (this.state.inType && code === 63) {
  5369. if (next === 46) {
  5370. this.finishOp(18, 2);
  5371. } else {
  5372. this.finishOp(17, 1);
  5373. }
  5374. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5375. this.state.pos += 2;
  5376. this.readIterator();
  5377. } else {
  5378. super.getTokenFromCode(code);
  5379. }
  5380. }
  5381. isAssignable(node, isBinding) {
  5382. if (node.type === "TypeCastExpression") {
  5383. return this.isAssignable(node.expression, isBinding);
  5384. } else {
  5385. return super.isAssignable(node, isBinding);
  5386. }
  5387. }
  5388. toAssignable(node, isLHS = false) {
  5389. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5390. node.left = this.typeCastToParameter(node.left);
  5391. }
  5392. super.toAssignable(node, isLHS);
  5393. }
  5394. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5395. for (let i = 0; i < exprList.length; i++) {
  5396. const expr = exprList[i];
  5397. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5398. exprList[i] = this.typeCastToParameter(expr);
  5399. }
  5400. }
  5401. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5402. }
  5403. toReferencedList(exprList, isParenthesizedExpr) {
  5404. for (let i = 0; i < exprList.length; i++) {
  5405. var _expr$extra;
  5406. const expr = exprList[i];
  5407. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5408. this.raise(FlowErrors.TypeCastInPattern, {
  5409. at: expr.typeAnnotation
  5410. });
  5411. }
  5412. }
  5413. return exprList;
  5414. }
  5415. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5416. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5417. if (canBePattern && !this.state.maybeInArrowParameters) {
  5418. this.toReferencedList(node.elements);
  5419. }
  5420. return node;
  5421. }
  5422. isValidLVal(type, isParenthesized, binding) {
  5423. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5424. }
  5425. parseClassProperty(node) {
  5426. if (this.match(14)) {
  5427. node.typeAnnotation = this.flowParseTypeAnnotation();
  5428. }
  5429. return super.parseClassProperty(node);
  5430. }
  5431. parseClassPrivateProperty(node) {
  5432. if (this.match(14)) {
  5433. node.typeAnnotation = this.flowParseTypeAnnotation();
  5434. }
  5435. return super.parseClassPrivateProperty(node);
  5436. }
  5437. isClassMethod() {
  5438. return this.match(47) || super.isClassMethod();
  5439. }
  5440. isClassProperty() {
  5441. return this.match(14) || super.isClassProperty();
  5442. }
  5443. isNonstaticConstructor(method) {
  5444. return !this.match(14) && super.isNonstaticConstructor(method);
  5445. }
  5446. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5447. if (method.variance) {
  5448. this.unexpected(method.variance.loc.start);
  5449. }
  5450. delete method.variance;
  5451. if (this.match(47)) {
  5452. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5453. }
  5454. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5455. if (method.params && isConstructor) {
  5456. const params = method.params;
  5457. if (params.length > 0 && this.isThisParam(params[0])) {
  5458. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5459. at: method
  5460. });
  5461. }
  5462. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5463. const params = method.value.params;
  5464. if (params.length > 0 && this.isThisParam(params[0])) {
  5465. this.raise(FlowErrors.ThisParamBannedInConstructor, {
  5466. at: method
  5467. });
  5468. }
  5469. }
  5470. }
  5471. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5472. if (method.variance) {
  5473. this.unexpected(method.variance.loc.start);
  5474. }
  5475. delete method.variance;
  5476. if (this.match(47)) {
  5477. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5478. }
  5479. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5480. }
  5481. parseClassSuper(node) {
  5482. super.parseClassSuper(node);
  5483. if (node.superClass && this.match(47)) {
  5484. node.superTypeParameters = this.flowParseTypeParameterInstantiation();
  5485. }
  5486. if (this.isContextual(113)) {
  5487. this.next();
  5488. const implemented = node.implements = [];
  5489. do {
  5490. const node = this.startNode();
  5491. node.id = this.flowParseRestrictedIdentifier(true);
  5492. if (this.match(47)) {
  5493. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5494. } else {
  5495. node.typeParameters = null;
  5496. }
  5497. implemented.push(this.finishNode(node, "ClassImplements"));
  5498. } while (this.eat(12));
  5499. }
  5500. }
  5501. checkGetterSetterParams(method) {
  5502. super.checkGetterSetterParams(method);
  5503. const params = this.getObjectOrClassMethodParams(method);
  5504. if (params.length > 0) {
  5505. const param = params[0];
  5506. if (this.isThisParam(param) && method.kind === "get") {
  5507. this.raise(FlowErrors.GetterMayNotHaveThisParam, {
  5508. at: param
  5509. });
  5510. } else if (this.isThisParam(param)) {
  5511. this.raise(FlowErrors.SetterMayNotHaveThisParam, {
  5512. at: param
  5513. });
  5514. }
  5515. }
  5516. }
  5517. parsePropertyNamePrefixOperator(node) {
  5518. node.variance = this.flowParseVariance();
  5519. }
  5520. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5521. if (prop.variance) {
  5522. this.unexpected(prop.variance.loc.start);
  5523. }
  5524. delete prop.variance;
  5525. let typeParameters;
  5526. if (this.match(47) && !isAccessor) {
  5527. typeParameters = this.flowParseTypeParameterDeclaration();
  5528. if (!this.match(10)) this.unexpected();
  5529. }
  5530. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5531. if (typeParameters) {
  5532. (result.value || result).typeParameters = typeParameters;
  5533. }
  5534. return result;
  5535. }
  5536. parseAssignableListItemTypes(param) {
  5537. if (this.eat(17)) {
  5538. if (param.type !== "Identifier") {
  5539. this.raise(FlowErrors.PatternIsOptional, {
  5540. at: param
  5541. });
  5542. }
  5543. if (this.isThisParam(param)) {
  5544. this.raise(FlowErrors.ThisParamMayNotBeOptional, {
  5545. at: param
  5546. });
  5547. }
  5548. param.optional = true;
  5549. }
  5550. if (this.match(14)) {
  5551. param.typeAnnotation = this.flowParseTypeAnnotation();
  5552. } else if (this.isThisParam(param)) {
  5553. this.raise(FlowErrors.ThisParamAnnotationRequired, {
  5554. at: param
  5555. });
  5556. }
  5557. if (this.match(29) && this.isThisParam(param)) {
  5558. this.raise(FlowErrors.ThisParamNoDefault, {
  5559. at: param
  5560. });
  5561. }
  5562. this.resetEndLocation(param);
  5563. return param;
  5564. }
  5565. parseMaybeDefault(startLoc, left) {
  5566. const node = super.parseMaybeDefault(startLoc, left);
  5567. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5568. this.raise(FlowErrors.TypeBeforeInitializer, {
  5569. at: node.typeAnnotation
  5570. });
  5571. }
  5572. return node;
  5573. }
  5574. checkImportReflection(node) {
  5575. super.checkImportReflection(node);
  5576. if (node.module && node.importKind !== "value") {
  5577. this.raise(FlowErrors.ImportReflectionHasImportType, {
  5578. at: node.specifiers[0].loc.start
  5579. });
  5580. }
  5581. }
  5582. parseImportSpecifierLocal(node, specifier, type) {
  5583. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5584. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5585. }
  5586. isPotentialImportPhase(isExport) {
  5587. if (super.isPotentialImportPhase(isExport)) return true;
  5588. if (this.isContextual(130)) {
  5589. if (!isExport) return true;
  5590. const ch = this.lookaheadCharCode();
  5591. return ch === 123 || ch === 42;
  5592. }
  5593. return !isExport && this.isContextual(87);
  5594. }
  5595. applyImportPhase(node, isExport, phase, loc) {
  5596. super.applyImportPhase(node, isExport, phase, loc);
  5597. if (isExport) {
  5598. if (!phase && this.match(65)) {
  5599. return;
  5600. }
  5601. node.exportKind = phase === "type" ? phase : "value";
  5602. } else {
  5603. if (phase === "type" && this.match(55)) this.unexpected();
  5604. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5605. }
  5606. }
  5607. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5608. const firstIdent = specifier.imported;
  5609. let specifierTypeKind = null;
  5610. if (firstIdent.type === "Identifier") {
  5611. if (firstIdent.name === "type") {
  5612. specifierTypeKind = "type";
  5613. } else if (firstIdent.name === "typeof") {
  5614. specifierTypeKind = "typeof";
  5615. }
  5616. }
  5617. let isBinding = false;
  5618. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5619. const as_ident = this.parseIdentifier(true);
  5620. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5621. specifier.imported = as_ident;
  5622. specifier.importKind = specifierTypeKind;
  5623. specifier.local = cloneIdentifier(as_ident);
  5624. } else {
  5625. specifier.imported = firstIdent;
  5626. specifier.importKind = null;
  5627. specifier.local = this.parseIdentifier();
  5628. }
  5629. } else {
  5630. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5631. specifier.imported = this.parseIdentifier(true);
  5632. specifier.importKind = specifierTypeKind;
  5633. } else {
  5634. if (importedIsString) {
  5635. throw this.raise(Errors.ImportBindingIsString, {
  5636. at: specifier,
  5637. importName: firstIdent.value
  5638. });
  5639. }
  5640. specifier.imported = firstIdent;
  5641. specifier.importKind = null;
  5642. }
  5643. if (this.eatContextual(93)) {
  5644. specifier.local = this.parseIdentifier();
  5645. } else {
  5646. isBinding = true;
  5647. specifier.local = cloneIdentifier(specifier.imported);
  5648. }
  5649. }
  5650. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5651. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5652. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, {
  5653. at: specifier
  5654. });
  5655. }
  5656. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5657. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5658. }
  5659. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5660. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5661. }
  5662. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5663. }
  5664. parseBindingAtom() {
  5665. switch (this.state.type) {
  5666. case 78:
  5667. return this.parseIdentifier(true);
  5668. default:
  5669. return super.parseBindingAtom();
  5670. }
  5671. }
  5672. parseFunctionParams(node, isConstructor) {
  5673. const kind = node.kind;
  5674. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5675. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5676. }
  5677. super.parseFunctionParams(node, isConstructor);
  5678. }
  5679. parseVarId(decl, kind) {
  5680. super.parseVarId(decl, kind);
  5681. if (this.match(14)) {
  5682. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5683. this.resetEndLocation(decl.id);
  5684. }
  5685. }
  5686. parseAsyncArrowFromCallExpression(node, call) {
  5687. if (this.match(14)) {
  5688. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5689. this.state.noAnonFunctionType = true;
  5690. node.returnType = this.flowParseTypeAnnotation();
  5691. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5692. }
  5693. return super.parseAsyncArrowFromCallExpression(node, call);
  5694. }
  5695. shouldParseAsyncArrow() {
  5696. return this.match(14) || super.shouldParseAsyncArrow();
  5697. }
  5698. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5699. var _jsx;
  5700. let state = null;
  5701. let jsx;
  5702. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  5703. state = this.state.clone();
  5704. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5705. if (!jsx.error) return jsx.node;
  5706. const {
  5707. context
  5708. } = this.state;
  5709. const currentContext = context[context.length - 1];
  5710. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5711. context.pop();
  5712. }
  5713. }
  5714. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5715. var _jsx2, _jsx3;
  5716. state = state || this.state.clone();
  5717. let typeParameters;
  5718. const arrow = this.tryParse(abort => {
  5719. var _arrowExpression$extr;
  5720. typeParameters = this.flowParseTypeParameterDeclaration();
  5721. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5722. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5723. this.resetStartLocationFromNode(result, typeParameters);
  5724. return result;
  5725. });
  5726. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5727. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5728. if (expr.type !== "ArrowFunctionExpression") abort();
  5729. expr.typeParameters = typeParameters;
  5730. this.resetStartLocationFromNode(expr, typeParameters);
  5731. return arrowExpression;
  5732. }, state);
  5733. let arrowExpression = null;
  5734. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5735. if (!arrow.error && !arrow.aborted) {
  5736. if (arrow.node.async) {
  5737. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, {
  5738. at: typeParameters
  5739. });
  5740. }
  5741. return arrow.node;
  5742. }
  5743. arrowExpression = arrow.node;
  5744. }
  5745. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5746. this.state = jsx.failState;
  5747. return jsx.node;
  5748. }
  5749. if (arrowExpression) {
  5750. this.state = arrow.failState;
  5751. return arrowExpression;
  5752. }
  5753. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5754. if (arrow.thrown) throw arrow.error;
  5755. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, {
  5756. at: typeParameters
  5757. });
  5758. }
  5759. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5760. }
  5761. parseArrow(node) {
  5762. if (this.match(14)) {
  5763. const result = this.tryParse(() => {
  5764. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5765. this.state.noAnonFunctionType = true;
  5766. const typeNode = this.startNode();
  5767. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5768. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5769. if (this.canInsertSemicolon()) this.unexpected();
  5770. if (!this.match(19)) this.unexpected();
  5771. return typeNode;
  5772. });
  5773. if (result.thrown) return null;
  5774. if (result.error) this.state = result.failState;
  5775. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  5776. }
  5777. return super.parseArrow(node);
  5778. }
  5779. shouldParseArrow(params) {
  5780. return this.match(14) || super.shouldParseArrow(params);
  5781. }
  5782. setArrowFunctionParameters(node, params) {
  5783. if (this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5784. node.params = params;
  5785. } else {
  5786. super.setArrowFunctionParameters(node, params);
  5787. }
  5788. }
  5789. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  5790. if (isArrowFunction && this.state.noArrowParamsConversionAt.indexOf(node.start) !== -1) {
  5791. return;
  5792. }
  5793. for (let i = 0; i < node.params.length; i++) {
  5794. if (this.isThisParam(node.params[i]) && i > 0) {
  5795. this.raise(FlowErrors.ThisParamMustBeFirst, {
  5796. at: node.params[i]
  5797. });
  5798. }
  5799. }
  5800. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  5801. }
  5802. parseParenAndDistinguishExpression(canBeArrow) {
  5803. return super.parseParenAndDistinguishExpression(canBeArrow && this.state.noArrowAt.indexOf(this.state.start) === -1);
  5804. }
  5805. parseSubscripts(base, startLoc, noCalls) {
  5806. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.indexOf(startLoc.index) !== -1) {
  5807. this.next();
  5808. const node = this.startNodeAt(startLoc);
  5809. node.callee = base;
  5810. node.arguments = super.parseCallExpressionArguments(11, false);
  5811. base = this.finishNode(node, "CallExpression");
  5812. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  5813. const state = this.state.clone();
  5814. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  5815. if (!arrow.error && !arrow.aborted) return arrow.node;
  5816. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  5817. if (result.node && !result.error) return result.node;
  5818. if (arrow.node) {
  5819. this.state = arrow.failState;
  5820. return arrow.node;
  5821. }
  5822. if (result.node) {
  5823. this.state = result.failState;
  5824. return result.node;
  5825. }
  5826. throw arrow.error || result.error;
  5827. }
  5828. return super.parseSubscripts(base, startLoc, noCalls);
  5829. }
  5830. parseSubscript(base, startLoc, noCalls, subscriptState) {
  5831. if (this.match(18) && this.isLookaheadToken_lt()) {
  5832. subscriptState.optionalChainMember = true;
  5833. if (noCalls) {
  5834. subscriptState.stop = true;
  5835. return base;
  5836. }
  5837. this.next();
  5838. const node = this.startNodeAt(startLoc);
  5839. node.callee = base;
  5840. node.typeArguments = this.flowParseTypeParameterInstantiation();
  5841. this.expect(10);
  5842. node.arguments = this.parseCallExpressionArguments(11, false);
  5843. node.optional = true;
  5844. return this.finishCallExpression(node, true);
  5845. } else if (!noCalls && this.shouldParseTypes() && this.match(47)) {
  5846. const node = this.startNodeAt(startLoc);
  5847. node.callee = base;
  5848. const result = this.tryParse(() => {
  5849. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  5850. this.expect(10);
  5851. node.arguments = super.parseCallExpressionArguments(11, false);
  5852. if (subscriptState.optionalChainMember) {
  5853. node.optional = false;
  5854. }
  5855. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  5856. });
  5857. if (result.node) {
  5858. if (result.error) this.state = result.failState;
  5859. return result.node;
  5860. }
  5861. }
  5862. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  5863. }
  5864. parseNewCallee(node) {
  5865. super.parseNewCallee(node);
  5866. let targs = null;
  5867. if (this.shouldParseTypes() && this.match(47)) {
  5868. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  5869. }
  5870. node.typeArguments = targs;
  5871. }
  5872. parseAsyncArrowWithTypeParameters(startLoc) {
  5873. const node = this.startNodeAt(startLoc);
  5874. this.parseFunctionParams(node, false);
  5875. if (!this.parseArrow(node)) return;
  5876. return super.parseArrowExpression(node, undefined, true);
  5877. }
  5878. readToken_mult_modulo(code) {
  5879. const next = this.input.charCodeAt(this.state.pos + 1);
  5880. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  5881. this.state.hasFlowComment = false;
  5882. this.state.pos += 2;
  5883. this.nextToken();
  5884. return;
  5885. }
  5886. super.readToken_mult_modulo(code);
  5887. }
  5888. readToken_pipe_amp(code) {
  5889. const next = this.input.charCodeAt(this.state.pos + 1);
  5890. if (code === 124 && next === 125) {
  5891. this.finishOp(9, 2);
  5892. return;
  5893. }
  5894. super.readToken_pipe_amp(code);
  5895. }
  5896. parseTopLevel(file, program) {
  5897. const fileNode = super.parseTopLevel(file, program);
  5898. if (this.state.hasFlowComment) {
  5899. this.raise(FlowErrors.UnterminatedFlowComment, {
  5900. at: this.state.curPosition()
  5901. });
  5902. }
  5903. return fileNode;
  5904. }
  5905. skipBlockComment() {
  5906. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  5907. if (this.state.hasFlowComment) {
  5908. throw this.raise(FlowErrors.NestedFlowComment, {
  5909. at: this.state.startLoc
  5910. });
  5911. }
  5912. this.hasFlowCommentCompletion();
  5913. const commentSkip = this.skipFlowComment();
  5914. if (commentSkip) {
  5915. this.state.pos += commentSkip;
  5916. this.state.hasFlowComment = true;
  5917. }
  5918. return;
  5919. }
  5920. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  5921. }
  5922. skipFlowComment() {
  5923. const {
  5924. pos
  5925. } = this.state;
  5926. let shiftToFirstNonWhiteSpace = 2;
  5927. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  5928. shiftToFirstNonWhiteSpace++;
  5929. }
  5930. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  5931. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  5932. if (ch2 === 58 && ch3 === 58) {
  5933. return shiftToFirstNonWhiteSpace + 2;
  5934. }
  5935. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  5936. return shiftToFirstNonWhiteSpace + 12;
  5937. }
  5938. if (ch2 === 58 && ch3 !== 58) {
  5939. return shiftToFirstNonWhiteSpace;
  5940. }
  5941. return false;
  5942. }
  5943. hasFlowCommentCompletion() {
  5944. const end = this.input.indexOf("*/", this.state.pos);
  5945. if (end === -1) {
  5946. throw this.raise(Errors.UnterminatedComment, {
  5947. at: this.state.curPosition()
  5948. });
  5949. }
  5950. }
  5951. flowEnumErrorBooleanMemberNotInitialized(loc, {
  5952. enumName,
  5953. memberName
  5954. }) {
  5955. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, {
  5956. at: loc,
  5957. memberName,
  5958. enumName
  5959. });
  5960. }
  5961. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  5962. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, Object.assign({
  5963. at: loc
  5964. }, enumContext));
  5965. }
  5966. flowEnumErrorNumberMemberNotInitialized(loc, {
  5967. enumName,
  5968. memberName
  5969. }) {
  5970. this.raise(FlowErrors.EnumNumberMemberNotInitialized, {
  5971. at: loc,
  5972. enumName,
  5973. memberName
  5974. });
  5975. }
  5976. flowEnumErrorStringMemberInconsistentlyInitialized(node, {
  5977. enumName
  5978. }) {
  5979. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, {
  5980. at: node,
  5981. enumName
  5982. });
  5983. }
  5984. flowEnumMemberInit() {
  5985. const startLoc = this.state.startLoc;
  5986. const endOfInit = () => this.match(12) || this.match(8);
  5987. switch (this.state.type) {
  5988. case 134:
  5989. {
  5990. const literal = this.parseNumericLiteral(this.state.value);
  5991. if (endOfInit()) {
  5992. return {
  5993. type: "number",
  5994. loc: literal.loc.start,
  5995. value: literal
  5996. };
  5997. }
  5998. return {
  5999. type: "invalid",
  6000. loc: startLoc
  6001. };
  6002. }
  6003. case 133:
  6004. {
  6005. const literal = this.parseStringLiteral(this.state.value);
  6006. if (endOfInit()) {
  6007. return {
  6008. type: "string",
  6009. loc: literal.loc.start,
  6010. value: literal
  6011. };
  6012. }
  6013. return {
  6014. type: "invalid",
  6015. loc: startLoc
  6016. };
  6017. }
  6018. case 85:
  6019. case 86:
  6020. {
  6021. const literal = this.parseBooleanLiteral(this.match(85));
  6022. if (endOfInit()) {
  6023. return {
  6024. type: "boolean",
  6025. loc: literal.loc.start,
  6026. value: literal
  6027. };
  6028. }
  6029. return {
  6030. type: "invalid",
  6031. loc: startLoc
  6032. };
  6033. }
  6034. default:
  6035. return {
  6036. type: "invalid",
  6037. loc: startLoc
  6038. };
  6039. }
  6040. }
  6041. flowEnumMemberRaw() {
  6042. const loc = this.state.startLoc;
  6043. const id = this.parseIdentifier(true);
  6044. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6045. type: "none",
  6046. loc
  6047. };
  6048. return {
  6049. id,
  6050. init
  6051. };
  6052. }
  6053. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6054. const {
  6055. explicitType
  6056. } = context;
  6057. if (explicitType === null) {
  6058. return;
  6059. }
  6060. if (explicitType !== expectedType) {
  6061. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6062. }
  6063. }
  6064. flowEnumMembers({
  6065. enumName,
  6066. explicitType
  6067. }) {
  6068. const seenNames = new Set();
  6069. const members = {
  6070. booleanMembers: [],
  6071. numberMembers: [],
  6072. stringMembers: [],
  6073. defaultedMembers: []
  6074. };
  6075. let hasUnknownMembers = false;
  6076. while (!this.match(8)) {
  6077. if (this.eat(21)) {
  6078. hasUnknownMembers = true;
  6079. break;
  6080. }
  6081. const memberNode = this.startNode();
  6082. const {
  6083. id,
  6084. init
  6085. } = this.flowEnumMemberRaw();
  6086. const memberName = id.name;
  6087. if (memberName === "") {
  6088. continue;
  6089. }
  6090. if (/^[a-z]/.test(memberName)) {
  6091. this.raise(FlowErrors.EnumInvalidMemberName, {
  6092. at: id,
  6093. memberName,
  6094. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6095. enumName
  6096. });
  6097. }
  6098. if (seenNames.has(memberName)) {
  6099. this.raise(FlowErrors.EnumDuplicateMemberName, {
  6100. at: id,
  6101. memberName,
  6102. enumName
  6103. });
  6104. }
  6105. seenNames.add(memberName);
  6106. const context = {
  6107. enumName,
  6108. explicitType,
  6109. memberName
  6110. };
  6111. memberNode.id = id;
  6112. switch (init.type) {
  6113. case "boolean":
  6114. {
  6115. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6116. memberNode.init = init.value;
  6117. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6118. break;
  6119. }
  6120. case "number":
  6121. {
  6122. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6123. memberNode.init = init.value;
  6124. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6125. break;
  6126. }
  6127. case "string":
  6128. {
  6129. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6130. memberNode.init = init.value;
  6131. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6132. break;
  6133. }
  6134. case "invalid":
  6135. {
  6136. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6137. }
  6138. case "none":
  6139. {
  6140. switch (explicitType) {
  6141. case "boolean":
  6142. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6143. break;
  6144. case "number":
  6145. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6146. break;
  6147. default:
  6148. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6149. }
  6150. }
  6151. }
  6152. if (!this.match(8)) {
  6153. this.expect(12);
  6154. }
  6155. }
  6156. return {
  6157. members,
  6158. hasUnknownMembers
  6159. };
  6160. }
  6161. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6162. enumName
  6163. }) {
  6164. if (initializedMembers.length === 0) {
  6165. return defaultedMembers;
  6166. } else if (defaultedMembers.length === 0) {
  6167. return initializedMembers;
  6168. } else if (defaultedMembers.length > initializedMembers.length) {
  6169. for (const member of initializedMembers) {
  6170. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6171. enumName
  6172. });
  6173. }
  6174. return defaultedMembers;
  6175. } else {
  6176. for (const member of defaultedMembers) {
  6177. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6178. enumName
  6179. });
  6180. }
  6181. return initializedMembers;
  6182. }
  6183. }
  6184. flowEnumParseExplicitType({
  6185. enumName
  6186. }) {
  6187. if (!this.eatContextual(102)) return null;
  6188. if (!tokenIsIdentifier(this.state.type)) {
  6189. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, {
  6190. at: this.state.startLoc,
  6191. enumName
  6192. });
  6193. }
  6194. const {
  6195. value
  6196. } = this.state;
  6197. this.next();
  6198. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6199. this.raise(FlowErrors.EnumInvalidExplicitType, {
  6200. at: this.state.startLoc,
  6201. enumName,
  6202. invalidEnumType: value
  6203. });
  6204. }
  6205. return value;
  6206. }
  6207. flowEnumBody(node, id) {
  6208. const enumName = id.name;
  6209. const nameLoc = id.loc.start;
  6210. const explicitType = this.flowEnumParseExplicitType({
  6211. enumName
  6212. });
  6213. this.expect(5);
  6214. const {
  6215. members,
  6216. hasUnknownMembers
  6217. } = this.flowEnumMembers({
  6218. enumName,
  6219. explicitType
  6220. });
  6221. node.hasUnknownMembers = hasUnknownMembers;
  6222. switch (explicitType) {
  6223. case "boolean":
  6224. node.explicitType = true;
  6225. node.members = members.booleanMembers;
  6226. this.expect(8);
  6227. return this.finishNode(node, "EnumBooleanBody");
  6228. case "number":
  6229. node.explicitType = true;
  6230. node.members = members.numberMembers;
  6231. this.expect(8);
  6232. return this.finishNode(node, "EnumNumberBody");
  6233. case "string":
  6234. node.explicitType = true;
  6235. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6236. enumName
  6237. });
  6238. this.expect(8);
  6239. return this.finishNode(node, "EnumStringBody");
  6240. case "symbol":
  6241. node.members = members.defaultedMembers;
  6242. this.expect(8);
  6243. return this.finishNode(node, "EnumSymbolBody");
  6244. default:
  6245. {
  6246. const empty = () => {
  6247. node.members = [];
  6248. this.expect(8);
  6249. return this.finishNode(node, "EnumStringBody");
  6250. };
  6251. node.explicitType = false;
  6252. const boolsLen = members.booleanMembers.length;
  6253. const numsLen = members.numberMembers.length;
  6254. const strsLen = members.stringMembers.length;
  6255. const defaultedLen = members.defaultedMembers.length;
  6256. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6257. return empty();
  6258. } else if (!boolsLen && !numsLen) {
  6259. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6260. enumName
  6261. });
  6262. this.expect(8);
  6263. return this.finishNode(node, "EnumStringBody");
  6264. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6265. for (const member of members.defaultedMembers) {
  6266. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6267. enumName,
  6268. memberName: member.id.name
  6269. });
  6270. }
  6271. node.members = members.booleanMembers;
  6272. this.expect(8);
  6273. return this.finishNode(node, "EnumBooleanBody");
  6274. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6275. for (const member of members.defaultedMembers) {
  6276. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6277. enumName,
  6278. memberName: member.id.name
  6279. });
  6280. }
  6281. node.members = members.numberMembers;
  6282. this.expect(8);
  6283. return this.finishNode(node, "EnumNumberBody");
  6284. } else {
  6285. this.raise(FlowErrors.EnumInconsistentMemberValues, {
  6286. at: nameLoc,
  6287. enumName
  6288. });
  6289. return empty();
  6290. }
  6291. }
  6292. }
  6293. }
  6294. flowParseEnumDeclaration(node) {
  6295. const id = this.parseIdentifier();
  6296. node.id = id;
  6297. node.body = this.flowEnumBody(this.startNode(), id);
  6298. return this.finishNode(node, "EnumDeclaration");
  6299. }
  6300. isLookaheadToken_lt() {
  6301. const next = this.nextTokenStart();
  6302. if (this.input.charCodeAt(next) === 60) {
  6303. const afterNext = this.input.charCodeAt(next + 1);
  6304. return afterNext !== 60 && afterNext !== 61;
  6305. }
  6306. return false;
  6307. }
  6308. maybeUnwrapTypeCastExpression(node) {
  6309. return node.type === "TypeCastExpression" ? node.expression : node;
  6310. }
  6311. };
  6312. const entities = {
  6313. __proto__: null,
  6314. quot: "\u0022",
  6315. amp: "&",
  6316. apos: "\u0027",
  6317. lt: "<",
  6318. gt: ">",
  6319. nbsp: "\u00A0",
  6320. iexcl: "\u00A1",
  6321. cent: "\u00A2",
  6322. pound: "\u00A3",
  6323. curren: "\u00A4",
  6324. yen: "\u00A5",
  6325. brvbar: "\u00A6",
  6326. sect: "\u00A7",
  6327. uml: "\u00A8",
  6328. copy: "\u00A9",
  6329. ordf: "\u00AA",
  6330. laquo: "\u00AB",
  6331. not: "\u00AC",
  6332. shy: "\u00AD",
  6333. reg: "\u00AE",
  6334. macr: "\u00AF",
  6335. deg: "\u00B0",
  6336. plusmn: "\u00B1",
  6337. sup2: "\u00B2",
  6338. sup3: "\u00B3",
  6339. acute: "\u00B4",
  6340. micro: "\u00B5",
  6341. para: "\u00B6",
  6342. middot: "\u00B7",
  6343. cedil: "\u00B8",
  6344. sup1: "\u00B9",
  6345. ordm: "\u00BA",
  6346. raquo: "\u00BB",
  6347. frac14: "\u00BC",
  6348. frac12: "\u00BD",
  6349. frac34: "\u00BE",
  6350. iquest: "\u00BF",
  6351. Agrave: "\u00C0",
  6352. Aacute: "\u00C1",
  6353. Acirc: "\u00C2",
  6354. Atilde: "\u00C3",
  6355. Auml: "\u00C4",
  6356. Aring: "\u00C5",
  6357. AElig: "\u00C6",
  6358. Ccedil: "\u00C7",
  6359. Egrave: "\u00C8",
  6360. Eacute: "\u00C9",
  6361. Ecirc: "\u00CA",
  6362. Euml: "\u00CB",
  6363. Igrave: "\u00CC",
  6364. Iacute: "\u00CD",
  6365. Icirc: "\u00CE",
  6366. Iuml: "\u00CF",
  6367. ETH: "\u00D0",
  6368. Ntilde: "\u00D1",
  6369. Ograve: "\u00D2",
  6370. Oacute: "\u00D3",
  6371. Ocirc: "\u00D4",
  6372. Otilde: "\u00D5",
  6373. Ouml: "\u00D6",
  6374. times: "\u00D7",
  6375. Oslash: "\u00D8",
  6376. Ugrave: "\u00D9",
  6377. Uacute: "\u00DA",
  6378. Ucirc: "\u00DB",
  6379. Uuml: "\u00DC",
  6380. Yacute: "\u00DD",
  6381. THORN: "\u00DE",
  6382. szlig: "\u00DF",
  6383. agrave: "\u00E0",
  6384. aacute: "\u00E1",
  6385. acirc: "\u00E2",
  6386. atilde: "\u00E3",
  6387. auml: "\u00E4",
  6388. aring: "\u00E5",
  6389. aelig: "\u00E6",
  6390. ccedil: "\u00E7",
  6391. egrave: "\u00E8",
  6392. eacute: "\u00E9",
  6393. ecirc: "\u00EA",
  6394. euml: "\u00EB",
  6395. igrave: "\u00EC",
  6396. iacute: "\u00ED",
  6397. icirc: "\u00EE",
  6398. iuml: "\u00EF",
  6399. eth: "\u00F0",
  6400. ntilde: "\u00F1",
  6401. ograve: "\u00F2",
  6402. oacute: "\u00F3",
  6403. ocirc: "\u00F4",
  6404. otilde: "\u00F5",
  6405. ouml: "\u00F6",
  6406. divide: "\u00F7",
  6407. oslash: "\u00F8",
  6408. ugrave: "\u00F9",
  6409. uacute: "\u00FA",
  6410. ucirc: "\u00FB",
  6411. uuml: "\u00FC",
  6412. yacute: "\u00FD",
  6413. thorn: "\u00FE",
  6414. yuml: "\u00FF",
  6415. OElig: "\u0152",
  6416. oelig: "\u0153",
  6417. Scaron: "\u0160",
  6418. scaron: "\u0161",
  6419. Yuml: "\u0178",
  6420. fnof: "\u0192",
  6421. circ: "\u02C6",
  6422. tilde: "\u02DC",
  6423. Alpha: "\u0391",
  6424. Beta: "\u0392",
  6425. Gamma: "\u0393",
  6426. Delta: "\u0394",
  6427. Epsilon: "\u0395",
  6428. Zeta: "\u0396",
  6429. Eta: "\u0397",
  6430. Theta: "\u0398",
  6431. Iota: "\u0399",
  6432. Kappa: "\u039A",
  6433. Lambda: "\u039B",
  6434. Mu: "\u039C",
  6435. Nu: "\u039D",
  6436. Xi: "\u039E",
  6437. Omicron: "\u039F",
  6438. Pi: "\u03A0",
  6439. Rho: "\u03A1",
  6440. Sigma: "\u03A3",
  6441. Tau: "\u03A4",
  6442. Upsilon: "\u03A5",
  6443. Phi: "\u03A6",
  6444. Chi: "\u03A7",
  6445. Psi: "\u03A8",
  6446. Omega: "\u03A9",
  6447. alpha: "\u03B1",
  6448. beta: "\u03B2",
  6449. gamma: "\u03B3",
  6450. delta: "\u03B4",
  6451. epsilon: "\u03B5",
  6452. zeta: "\u03B6",
  6453. eta: "\u03B7",
  6454. theta: "\u03B8",
  6455. iota: "\u03B9",
  6456. kappa: "\u03BA",
  6457. lambda: "\u03BB",
  6458. mu: "\u03BC",
  6459. nu: "\u03BD",
  6460. xi: "\u03BE",
  6461. omicron: "\u03BF",
  6462. pi: "\u03C0",
  6463. rho: "\u03C1",
  6464. sigmaf: "\u03C2",
  6465. sigma: "\u03C3",
  6466. tau: "\u03C4",
  6467. upsilon: "\u03C5",
  6468. phi: "\u03C6",
  6469. chi: "\u03C7",
  6470. psi: "\u03C8",
  6471. omega: "\u03C9",
  6472. thetasym: "\u03D1",
  6473. upsih: "\u03D2",
  6474. piv: "\u03D6",
  6475. ensp: "\u2002",
  6476. emsp: "\u2003",
  6477. thinsp: "\u2009",
  6478. zwnj: "\u200C",
  6479. zwj: "\u200D",
  6480. lrm: "\u200E",
  6481. rlm: "\u200F",
  6482. ndash: "\u2013",
  6483. mdash: "\u2014",
  6484. lsquo: "\u2018",
  6485. rsquo: "\u2019",
  6486. sbquo: "\u201A",
  6487. ldquo: "\u201C",
  6488. rdquo: "\u201D",
  6489. bdquo: "\u201E",
  6490. dagger: "\u2020",
  6491. Dagger: "\u2021",
  6492. bull: "\u2022",
  6493. hellip: "\u2026",
  6494. permil: "\u2030",
  6495. prime: "\u2032",
  6496. Prime: "\u2033",
  6497. lsaquo: "\u2039",
  6498. rsaquo: "\u203A",
  6499. oline: "\u203E",
  6500. frasl: "\u2044",
  6501. euro: "\u20AC",
  6502. image: "\u2111",
  6503. weierp: "\u2118",
  6504. real: "\u211C",
  6505. trade: "\u2122",
  6506. alefsym: "\u2135",
  6507. larr: "\u2190",
  6508. uarr: "\u2191",
  6509. rarr: "\u2192",
  6510. darr: "\u2193",
  6511. harr: "\u2194",
  6512. crarr: "\u21B5",
  6513. lArr: "\u21D0",
  6514. uArr: "\u21D1",
  6515. rArr: "\u21D2",
  6516. dArr: "\u21D3",
  6517. hArr: "\u21D4",
  6518. forall: "\u2200",
  6519. part: "\u2202",
  6520. exist: "\u2203",
  6521. empty: "\u2205",
  6522. nabla: "\u2207",
  6523. isin: "\u2208",
  6524. notin: "\u2209",
  6525. ni: "\u220B",
  6526. prod: "\u220F",
  6527. sum: "\u2211",
  6528. minus: "\u2212",
  6529. lowast: "\u2217",
  6530. radic: "\u221A",
  6531. prop: "\u221D",
  6532. infin: "\u221E",
  6533. ang: "\u2220",
  6534. and: "\u2227",
  6535. or: "\u2228",
  6536. cap: "\u2229",
  6537. cup: "\u222A",
  6538. int: "\u222B",
  6539. there4: "\u2234",
  6540. sim: "\u223C",
  6541. cong: "\u2245",
  6542. asymp: "\u2248",
  6543. ne: "\u2260",
  6544. equiv: "\u2261",
  6545. le: "\u2264",
  6546. ge: "\u2265",
  6547. sub: "\u2282",
  6548. sup: "\u2283",
  6549. nsub: "\u2284",
  6550. sube: "\u2286",
  6551. supe: "\u2287",
  6552. oplus: "\u2295",
  6553. otimes: "\u2297",
  6554. perp: "\u22A5",
  6555. sdot: "\u22C5",
  6556. lceil: "\u2308",
  6557. rceil: "\u2309",
  6558. lfloor: "\u230A",
  6559. rfloor: "\u230B",
  6560. lang: "\u2329",
  6561. rang: "\u232A",
  6562. loz: "\u25CA",
  6563. spades: "\u2660",
  6564. clubs: "\u2663",
  6565. hearts: "\u2665",
  6566. diams: "\u2666"
  6567. };
  6568. const JsxErrors = ParseErrorEnum`jsx`({
  6569. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6570. MissingClosingTagElement: ({
  6571. openingTagName
  6572. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6573. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6574. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6575. UnexpectedToken: ({
  6576. unexpected,
  6577. HTMLEntity
  6578. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6579. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6580. UnterminatedJsxContent: "Unterminated JSX contents.",
  6581. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6582. });
  6583. function isFragment(object) {
  6584. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6585. }
  6586. function getQualifiedJSXName(object) {
  6587. if (object.type === "JSXIdentifier") {
  6588. return object.name;
  6589. }
  6590. if (object.type === "JSXNamespacedName") {
  6591. return object.namespace.name + ":" + object.name.name;
  6592. }
  6593. if (object.type === "JSXMemberExpression") {
  6594. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6595. }
  6596. throw new Error("Node had unexpected type: " + object.type);
  6597. }
  6598. var jsx = superClass => class JSXParserMixin extends superClass {
  6599. jsxReadToken() {
  6600. let out = "";
  6601. let chunkStart = this.state.pos;
  6602. for (;;) {
  6603. if (this.state.pos >= this.length) {
  6604. throw this.raise(JsxErrors.UnterminatedJsxContent, {
  6605. at: this.state.startLoc
  6606. });
  6607. }
  6608. const ch = this.input.charCodeAt(this.state.pos);
  6609. switch (ch) {
  6610. case 60:
  6611. case 123:
  6612. if (this.state.pos === this.state.start) {
  6613. if (ch === 60 && this.state.canStartJSXElement) {
  6614. ++this.state.pos;
  6615. this.finishToken(142);
  6616. } else {
  6617. super.getTokenFromCode(ch);
  6618. }
  6619. return;
  6620. }
  6621. out += this.input.slice(chunkStart, this.state.pos);
  6622. this.finishToken(141, out);
  6623. return;
  6624. case 38:
  6625. out += this.input.slice(chunkStart, this.state.pos);
  6626. out += this.jsxReadEntity();
  6627. chunkStart = this.state.pos;
  6628. break;
  6629. case 62:
  6630. case 125:
  6631. default:
  6632. if (isNewLine(ch)) {
  6633. out += this.input.slice(chunkStart, this.state.pos);
  6634. out += this.jsxReadNewLine(true);
  6635. chunkStart = this.state.pos;
  6636. } else {
  6637. ++this.state.pos;
  6638. }
  6639. }
  6640. }
  6641. }
  6642. jsxReadNewLine(normalizeCRLF) {
  6643. const ch = this.input.charCodeAt(this.state.pos);
  6644. let out;
  6645. ++this.state.pos;
  6646. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6647. ++this.state.pos;
  6648. out = normalizeCRLF ? "\n" : "\r\n";
  6649. } else {
  6650. out = String.fromCharCode(ch);
  6651. }
  6652. ++this.state.curLine;
  6653. this.state.lineStart = this.state.pos;
  6654. return out;
  6655. }
  6656. jsxReadString(quote) {
  6657. let out = "";
  6658. let chunkStart = ++this.state.pos;
  6659. for (;;) {
  6660. if (this.state.pos >= this.length) {
  6661. throw this.raise(Errors.UnterminatedString, {
  6662. at: this.state.startLoc
  6663. });
  6664. }
  6665. const ch = this.input.charCodeAt(this.state.pos);
  6666. if (ch === quote) break;
  6667. if (ch === 38) {
  6668. out += this.input.slice(chunkStart, this.state.pos);
  6669. out += this.jsxReadEntity();
  6670. chunkStart = this.state.pos;
  6671. } else if (isNewLine(ch)) {
  6672. out += this.input.slice(chunkStart, this.state.pos);
  6673. out += this.jsxReadNewLine(false);
  6674. chunkStart = this.state.pos;
  6675. } else {
  6676. ++this.state.pos;
  6677. }
  6678. }
  6679. out += this.input.slice(chunkStart, this.state.pos++);
  6680. this.finishToken(133, out);
  6681. }
  6682. jsxReadEntity() {
  6683. const startPos = ++this.state.pos;
  6684. if (this.codePointAtPos(this.state.pos) === 35) {
  6685. ++this.state.pos;
  6686. let radix = 10;
  6687. if (this.codePointAtPos(this.state.pos) === 120) {
  6688. radix = 16;
  6689. ++this.state.pos;
  6690. }
  6691. const codePoint = this.readInt(radix, undefined, false, "bail");
  6692. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6693. ++this.state.pos;
  6694. return String.fromCodePoint(codePoint);
  6695. }
  6696. } else {
  6697. let count = 0;
  6698. let semi = false;
  6699. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) {
  6700. ++this.state.pos;
  6701. }
  6702. if (semi) {
  6703. const desc = this.input.slice(startPos, this.state.pos);
  6704. const entity = entities[desc];
  6705. ++this.state.pos;
  6706. if (entity) {
  6707. return entity;
  6708. }
  6709. }
  6710. }
  6711. this.state.pos = startPos;
  6712. return "&";
  6713. }
  6714. jsxReadWord() {
  6715. let ch;
  6716. const start = this.state.pos;
  6717. do {
  6718. ch = this.input.charCodeAt(++this.state.pos);
  6719. } while (isIdentifierChar(ch) || ch === 45);
  6720. this.finishToken(140, this.input.slice(start, this.state.pos));
  6721. }
  6722. jsxParseIdentifier() {
  6723. const node = this.startNode();
  6724. if (this.match(140)) {
  6725. node.name = this.state.value;
  6726. } else if (tokenIsKeyword(this.state.type)) {
  6727. node.name = tokenLabelName(this.state.type);
  6728. } else {
  6729. this.unexpected();
  6730. }
  6731. this.next();
  6732. return this.finishNode(node, "JSXIdentifier");
  6733. }
  6734. jsxParseNamespacedName() {
  6735. const startLoc = this.state.startLoc;
  6736. const name = this.jsxParseIdentifier();
  6737. if (!this.eat(14)) return name;
  6738. const node = this.startNodeAt(startLoc);
  6739. node.namespace = name;
  6740. node.name = this.jsxParseIdentifier();
  6741. return this.finishNode(node, "JSXNamespacedName");
  6742. }
  6743. jsxParseElementName() {
  6744. const startLoc = this.state.startLoc;
  6745. let node = this.jsxParseNamespacedName();
  6746. if (node.type === "JSXNamespacedName") {
  6747. return node;
  6748. }
  6749. while (this.eat(16)) {
  6750. const newNode = this.startNodeAt(startLoc);
  6751. newNode.object = node;
  6752. newNode.property = this.jsxParseIdentifier();
  6753. node = this.finishNode(newNode, "JSXMemberExpression");
  6754. }
  6755. return node;
  6756. }
  6757. jsxParseAttributeValue() {
  6758. let node;
  6759. switch (this.state.type) {
  6760. case 5:
  6761. node = this.startNode();
  6762. this.setContext(types.brace);
  6763. this.next();
  6764. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  6765. if (node.expression.type === "JSXEmptyExpression") {
  6766. this.raise(JsxErrors.AttributeIsEmpty, {
  6767. at: node
  6768. });
  6769. }
  6770. return node;
  6771. case 142:
  6772. case 133:
  6773. return this.parseExprAtom();
  6774. default:
  6775. throw this.raise(JsxErrors.UnsupportedJsxValue, {
  6776. at: this.state.startLoc
  6777. });
  6778. }
  6779. }
  6780. jsxParseEmptyExpression() {
  6781. const node = this.startNodeAt(this.state.lastTokEndLoc);
  6782. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  6783. }
  6784. jsxParseSpreadChild(node) {
  6785. this.next();
  6786. node.expression = this.parseExpression();
  6787. this.setContext(types.j_expr);
  6788. this.state.canStartJSXElement = true;
  6789. this.expect(8);
  6790. return this.finishNode(node, "JSXSpreadChild");
  6791. }
  6792. jsxParseExpressionContainer(node, previousContext) {
  6793. if (this.match(8)) {
  6794. node.expression = this.jsxParseEmptyExpression();
  6795. } else {
  6796. const expression = this.parseExpression();
  6797. node.expression = expression;
  6798. }
  6799. this.setContext(previousContext);
  6800. this.state.canStartJSXElement = true;
  6801. this.expect(8);
  6802. return this.finishNode(node, "JSXExpressionContainer");
  6803. }
  6804. jsxParseAttribute() {
  6805. const node = this.startNode();
  6806. if (this.match(5)) {
  6807. this.setContext(types.brace);
  6808. this.next();
  6809. this.expect(21);
  6810. node.argument = this.parseMaybeAssignAllowIn();
  6811. this.setContext(types.j_oTag);
  6812. this.state.canStartJSXElement = true;
  6813. this.expect(8);
  6814. return this.finishNode(node, "JSXSpreadAttribute");
  6815. }
  6816. node.name = this.jsxParseNamespacedName();
  6817. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  6818. return this.finishNode(node, "JSXAttribute");
  6819. }
  6820. jsxParseOpeningElementAt(startLoc) {
  6821. const node = this.startNodeAt(startLoc);
  6822. if (this.eat(143)) {
  6823. return this.finishNode(node, "JSXOpeningFragment");
  6824. }
  6825. node.name = this.jsxParseElementName();
  6826. return this.jsxParseOpeningElementAfterName(node);
  6827. }
  6828. jsxParseOpeningElementAfterName(node) {
  6829. const attributes = [];
  6830. while (!this.match(56) && !this.match(143)) {
  6831. attributes.push(this.jsxParseAttribute());
  6832. }
  6833. node.attributes = attributes;
  6834. node.selfClosing = this.eat(56);
  6835. this.expect(143);
  6836. return this.finishNode(node, "JSXOpeningElement");
  6837. }
  6838. jsxParseClosingElementAt(startLoc) {
  6839. const node = this.startNodeAt(startLoc);
  6840. if (this.eat(143)) {
  6841. return this.finishNode(node, "JSXClosingFragment");
  6842. }
  6843. node.name = this.jsxParseElementName();
  6844. this.expect(143);
  6845. return this.finishNode(node, "JSXClosingElement");
  6846. }
  6847. jsxParseElementAt(startLoc) {
  6848. const node = this.startNodeAt(startLoc);
  6849. const children = [];
  6850. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  6851. let closingElement = null;
  6852. if (!openingElement.selfClosing) {
  6853. contents: for (;;) {
  6854. switch (this.state.type) {
  6855. case 142:
  6856. startLoc = this.state.startLoc;
  6857. this.next();
  6858. if (this.eat(56)) {
  6859. closingElement = this.jsxParseClosingElementAt(startLoc);
  6860. break contents;
  6861. }
  6862. children.push(this.jsxParseElementAt(startLoc));
  6863. break;
  6864. case 141:
  6865. children.push(this.parseExprAtom());
  6866. break;
  6867. case 5:
  6868. {
  6869. const node = this.startNode();
  6870. this.setContext(types.brace);
  6871. this.next();
  6872. if (this.match(21)) {
  6873. children.push(this.jsxParseSpreadChild(node));
  6874. } else {
  6875. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  6876. }
  6877. break;
  6878. }
  6879. default:
  6880. this.unexpected();
  6881. }
  6882. }
  6883. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  6884. this.raise(JsxErrors.MissingClosingTagFragment, {
  6885. at: closingElement
  6886. });
  6887. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  6888. this.raise(JsxErrors.MissingClosingTagElement, {
  6889. at: closingElement,
  6890. openingTagName: getQualifiedJSXName(openingElement.name)
  6891. });
  6892. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  6893. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  6894. this.raise(JsxErrors.MissingClosingTagElement, {
  6895. at: closingElement,
  6896. openingTagName: getQualifiedJSXName(openingElement.name)
  6897. });
  6898. }
  6899. }
  6900. }
  6901. if (isFragment(openingElement)) {
  6902. node.openingFragment = openingElement;
  6903. node.closingFragment = closingElement;
  6904. } else {
  6905. node.openingElement = openingElement;
  6906. node.closingElement = closingElement;
  6907. }
  6908. node.children = children;
  6909. if (this.match(47)) {
  6910. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, {
  6911. at: this.state.startLoc
  6912. });
  6913. }
  6914. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  6915. }
  6916. jsxParseElement() {
  6917. const startLoc = this.state.startLoc;
  6918. this.next();
  6919. return this.jsxParseElementAt(startLoc);
  6920. }
  6921. setContext(newContext) {
  6922. const {
  6923. context
  6924. } = this.state;
  6925. context[context.length - 1] = newContext;
  6926. }
  6927. parseExprAtom(refExpressionErrors) {
  6928. if (this.match(141)) {
  6929. return this.parseLiteral(this.state.value, "JSXText");
  6930. } else if (this.match(142)) {
  6931. return this.jsxParseElement();
  6932. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  6933. this.replaceToken(142);
  6934. return this.jsxParseElement();
  6935. } else {
  6936. return super.parseExprAtom(refExpressionErrors);
  6937. }
  6938. }
  6939. skipSpace() {
  6940. const curContext = this.curContext();
  6941. if (!curContext.preserveSpace) super.skipSpace();
  6942. }
  6943. getTokenFromCode(code) {
  6944. const context = this.curContext();
  6945. if (context === types.j_expr) {
  6946. this.jsxReadToken();
  6947. return;
  6948. }
  6949. if (context === types.j_oTag || context === types.j_cTag) {
  6950. if (isIdentifierStart(code)) {
  6951. this.jsxReadWord();
  6952. return;
  6953. }
  6954. if (code === 62) {
  6955. ++this.state.pos;
  6956. this.finishToken(143);
  6957. return;
  6958. }
  6959. if ((code === 34 || code === 39) && context === types.j_oTag) {
  6960. this.jsxReadString(code);
  6961. return;
  6962. }
  6963. }
  6964. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  6965. ++this.state.pos;
  6966. this.finishToken(142);
  6967. return;
  6968. }
  6969. super.getTokenFromCode(code);
  6970. }
  6971. updateContext(prevType) {
  6972. const {
  6973. context,
  6974. type
  6975. } = this.state;
  6976. if (type === 56 && prevType === 142) {
  6977. context.splice(-2, 2, types.j_cTag);
  6978. this.state.canStartJSXElement = false;
  6979. } else if (type === 142) {
  6980. context.push(types.j_oTag);
  6981. } else if (type === 143) {
  6982. const out = context[context.length - 1];
  6983. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  6984. context.pop();
  6985. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  6986. } else {
  6987. this.setContext(types.j_expr);
  6988. this.state.canStartJSXElement = true;
  6989. }
  6990. } else {
  6991. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  6992. }
  6993. }
  6994. };
  6995. class TypeScriptScope extends Scope {
  6996. constructor(...args) {
  6997. super(...args);
  6998. this.types = new Set();
  6999. this.enums = new Set();
  7000. this.constEnums = new Set();
  7001. this.classes = new Set();
  7002. this.exportOnlyBindings = new Set();
  7003. }
  7004. }
  7005. class TypeScriptScopeHandler extends ScopeHandler {
  7006. constructor(...args) {
  7007. super(...args);
  7008. this.importsStack = [];
  7009. }
  7010. createScope(flags) {
  7011. this.importsStack.push(new Set());
  7012. return new TypeScriptScope(flags);
  7013. }
  7014. enter(flags) {
  7015. if (flags == 256) {
  7016. this.importsStack.push(new Set());
  7017. }
  7018. super.enter(flags);
  7019. }
  7020. exit() {
  7021. const flags = super.exit();
  7022. if (flags == 256) {
  7023. this.importsStack.pop();
  7024. }
  7025. return flags;
  7026. }
  7027. hasImport(name, allowShadow) {
  7028. const len = this.importsStack.length;
  7029. if (this.importsStack[len - 1].has(name)) {
  7030. return true;
  7031. }
  7032. if (!allowShadow && len > 1) {
  7033. for (let i = 0; i < len - 1; i++) {
  7034. if (this.importsStack[i].has(name)) return true;
  7035. }
  7036. }
  7037. return false;
  7038. }
  7039. declareName(name, bindingType, loc) {
  7040. if (bindingType & 4096) {
  7041. if (this.hasImport(name, true)) {
  7042. this.parser.raise(Errors.VarRedeclaration, {
  7043. at: loc,
  7044. identifierName: name
  7045. });
  7046. }
  7047. this.importsStack[this.importsStack.length - 1].add(name);
  7048. return;
  7049. }
  7050. const scope = this.currentScope();
  7051. if (bindingType & 1024) {
  7052. this.maybeExportDefined(scope, name);
  7053. scope.exportOnlyBindings.add(name);
  7054. return;
  7055. }
  7056. super.declareName(name, bindingType, loc);
  7057. if (bindingType & 2) {
  7058. if (!(bindingType & 1)) {
  7059. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7060. this.maybeExportDefined(scope, name);
  7061. }
  7062. scope.types.add(name);
  7063. }
  7064. if (bindingType & 256) scope.enums.add(name);
  7065. if (bindingType & 512) {
  7066. scope.constEnums.add(name);
  7067. }
  7068. if (bindingType & 128) scope.classes.add(name);
  7069. }
  7070. isRedeclaredInScope(scope, name, bindingType) {
  7071. if (scope.enums.has(name)) {
  7072. if (bindingType & 256) {
  7073. const isConst = !!(bindingType & 512);
  7074. const wasConst = scope.constEnums.has(name);
  7075. return isConst !== wasConst;
  7076. }
  7077. return true;
  7078. }
  7079. if (bindingType & 128 && scope.classes.has(name)) {
  7080. if (scope.lexical.has(name)) {
  7081. return !!(bindingType & 1);
  7082. } else {
  7083. return false;
  7084. }
  7085. }
  7086. if (bindingType & 2 && scope.types.has(name)) {
  7087. return true;
  7088. }
  7089. return super.isRedeclaredInScope(scope, name, bindingType);
  7090. }
  7091. checkLocalExport(id) {
  7092. const {
  7093. name
  7094. } = id;
  7095. if (this.hasImport(name)) return;
  7096. const len = this.scopeStack.length;
  7097. for (let i = len - 1; i >= 0; i--) {
  7098. const scope = this.scopeStack[i];
  7099. if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return;
  7100. }
  7101. super.checkLocalExport(id);
  7102. }
  7103. }
  7104. const getOwn$1 = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7105. const unwrapParenthesizedExpression = node => {
  7106. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  7107. };
  7108. class LValParser extends NodeUtils {
  7109. toAssignable(node, isLHS = false) {
  7110. var _node$extra, _node$extra3;
  7111. let parenthesized = undefined;
  7112. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  7113. parenthesized = unwrapParenthesizedExpression(node);
  7114. if (isLHS) {
  7115. if (parenthesized.type === "Identifier") {
  7116. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, {
  7117. at: node
  7118. });
  7119. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  7120. this.raise(Errors.InvalidParenthesizedAssignment, {
  7121. at: node
  7122. });
  7123. }
  7124. } else {
  7125. this.raise(Errors.InvalidParenthesizedAssignment, {
  7126. at: node
  7127. });
  7128. }
  7129. }
  7130. switch (node.type) {
  7131. case "Identifier":
  7132. case "ObjectPattern":
  7133. case "ArrayPattern":
  7134. case "AssignmentPattern":
  7135. case "RestElement":
  7136. break;
  7137. case "ObjectExpression":
  7138. node.type = "ObjectPattern";
  7139. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  7140. var _node$extra2;
  7141. const prop = node.properties[i];
  7142. const isLast = i === last;
  7143. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  7144. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  7145. this.raise(Errors.RestTrailingComma, {
  7146. at: node.extra.trailingCommaLoc
  7147. });
  7148. }
  7149. }
  7150. break;
  7151. case "ObjectProperty":
  7152. {
  7153. const {
  7154. key,
  7155. value
  7156. } = node;
  7157. if (this.isPrivateName(key)) {
  7158. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  7159. }
  7160. this.toAssignable(value, isLHS);
  7161. break;
  7162. }
  7163. case "SpreadElement":
  7164. {
  7165. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  7166. }
  7167. case "ArrayExpression":
  7168. node.type = "ArrayPattern";
  7169. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  7170. break;
  7171. case "AssignmentExpression":
  7172. if (node.operator !== "=") {
  7173. this.raise(Errors.MissingEqInAssignment, {
  7174. at: node.left.loc.end
  7175. });
  7176. }
  7177. node.type = "AssignmentPattern";
  7178. delete node.operator;
  7179. this.toAssignable(node.left, isLHS);
  7180. break;
  7181. case "ParenthesizedExpression":
  7182. this.toAssignable(parenthesized, isLHS);
  7183. break;
  7184. }
  7185. }
  7186. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  7187. if (prop.type === "ObjectMethod") {
  7188. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, {
  7189. at: prop.key
  7190. });
  7191. } else if (prop.type === "SpreadElement") {
  7192. prop.type = "RestElement";
  7193. const arg = prop.argument;
  7194. this.checkToRestConversion(arg, false);
  7195. this.toAssignable(arg, isLHS);
  7196. if (!isLast) {
  7197. this.raise(Errors.RestTrailingComma, {
  7198. at: prop
  7199. });
  7200. }
  7201. } else {
  7202. this.toAssignable(prop, isLHS);
  7203. }
  7204. }
  7205. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7206. const end = exprList.length - 1;
  7207. for (let i = 0; i <= end; i++) {
  7208. const elt = exprList[i];
  7209. if (!elt) continue;
  7210. if (elt.type === "SpreadElement") {
  7211. elt.type = "RestElement";
  7212. const arg = elt.argument;
  7213. this.checkToRestConversion(arg, true);
  7214. this.toAssignable(arg, isLHS);
  7215. } else {
  7216. this.toAssignable(elt, isLHS);
  7217. }
  7218. if (elt.type === "RestElement") {
  7219. if (i < end) {
  7220. this.raise(Errors.RestTrailingComma, {
  7221. at: elt
  7222. });
  7223. } else if (trailingCommaLoc) {
  7224. this.raise(Errors.RestTrailingComma, {
  7225. at: trailingCommaLoc
  7226. });
  7227. }
  7228. }
  7229. }
  7230. }
  7231. isAssignable(node, isBinding) {
  7232. switch (node.type) {
  7233. case "Identifier":
  7234. case "ObjectPattern":
  7235. case "ArrayPattern":
  7236. case "AssignmentPattern":
  7237. case "RestElement":
  7238. return true;
  7239. case "ObjectExpression":
  7240. {
  7241. const last = node.properties.length - 1;
  7242. return node.properties.every((prop, i) => {
  7243. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  7244. });
  7245. }
  7246. case "ObjectProperty":
  7247. return this.isAssignable(node.value);
  7248. case "SpreadElement":
  7249. return this.isAssignable(node.argument);
  7250. case "ArrayExpression":
  7251. return node.elements.every(element => element === null || this.isAssignable(element));
  7252. case "AssignmentExpression":
  7253. return node.operator === "=";
  7254. case "ParenthesizedExpression":
  7255. return this.isAssignable(node.expression);
  7256. case "MemberExpression":
  7257. case "OptionalMemberExpression":
  7258. return !isBinding;
  7259. default:
  7260. return false;
  7261. }
  7262. }
  7263. toReferencedList(exprList, isParenthesizedExpr) {
  7264. return exprList;
  7265. }
  7266. toReferencedListDeep(exprList, isParenthesizedExpr) {
  7267. this.toReferencedList(exprList, isParenthesizedExpr);
  7268. for (const expr of exprList) {
  7269. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  7270. this.toReferencedListDeep(expr.elements);
  7271. }
  7272. }
  7273. }
  7274. parseSpread(refExpressionErrors) {
  7275. const node = this.startNode();
  7276. this.next();
  7277. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  7278. return this.finishNode(node, "SpreadElement");
  7279. }
  7280. parseRestBinding() {
  7281. const node = this.startNode();
  7282. this.next();
  7283. node.argument = this.parseBindingAtom();
  7284. return this.finishNode(node, "RestElement");
  7285. }
  7286. parseBindingAtom() {
  7287. switch (this.state.type) {
  7288. case 0:
  7289. {
  7290. const node = this.startNode();
  7291. this.next();
  7292. node.elements = this.parseBindingList(3, 93, 1);
  7293. return this.finishNode(node, "ArrayPattern");
  7294. }
  7295. case 5:
  7296. return this.parseObjectLike(8, true);
  7297. }
  7298. return this.parseIdentifier();
  7299. }
  7300. parseBindingList(close, closeCharCode, flags) {
  7301. const allowEmpty = flags & 1;
  7302. const elts = [];
  7303. let first = true;
  7304. while (!this.eat(close)) {
  7305. if (first) {
  7306. first = false;
  7307. } else {
  7308. this.expect(12);
  7309. }
  7310. if (allowEmpty && this.match(12)) {
  7311. elts.push(null);
  7312. } else if (this.eat(close)) {
  7313. break;
  7314. } else if (this.match(21)) {
  7315. elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags));
  7316. if (!this.checkCommaAfterRest(closeCharCode)) {
  7317. this.expect(close);
  7318. break;
  7319. }
  7320. } else {
  7321. const decorators = [];
  7322. if (this.match(26) && this.hasPlugin("decorators")) {
  7323. this.raise(Errors.UnsupportedParameterDecorator, {
  7324. at: this.state.startLoc
  7325. });
  7326. }
  7327. while (this.match(26)) {
  7328. decorators.push(this.parseDecorator());
  7329. }
  7330. elts.push(this.parseAssignableListItem(flags, decorators));
  7331. }
  7332. }
  7333. return elts;
  7334. }
  7335. parseBindingRestProperty(prop) {
  7336. this.next();
  7337. prop.argument = this.parseIdentifier();
  7338. this.checkCommaAfterRest(125);
  7339. return this.finishNode(prop, "RestElement");
  7340. }
  7341. parseBindingProperty() {
  7342. const prop = this.startNode();
  7343. const {
  7344. type,
  7345. startLoc
  7346. } = this.state;
  7347. if (type === 21) {
  7348. return this.parseBindingRestProperty(prop);
  7349. } else if (type === 138) {
  7350. this.expectPlugin("destructuringPrivate", startLoc);
  7351. this.classScope.usePrivateName(this.state.value, startLoc);
  7352. prop.key = this.parsePrivateName();
  7353. } else {
  7354. this.parsePropertyName(prop);
  7355. }
  7356. prop.method = false;
  7357. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  7358. }
  7359. parseAssignableListItem(flags, decorators) {
  7360. const left = this.parseMaybeDefault();
  7361. this.parseAssignableListItemTypes(left, flags);
  7362. const elt = this.parseMaybeDefault(left.loc.start, left);
  7363. if (decorators.length) {
  7364. left.decorators = decorators;
  7365. }
  7366. return elt;
  7367. }
  7368. parseAssignableListItemTypes(param, flags) {
  7369. return param;
  7370. }
  7371. parseMaybeDefault(startLoc, left) {
  7372. var _startLoc, _left;
  7373. (_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc;
  7374. left = (_left = left) != null ? _left : this.parseBindingAtom();
  7375. if (!this.eat(29)) return left;
  7376. const node = this.startNodeAt(startLoc);
  7377. node.left = left;
  7378. node.right = this.parseMaybeAssignAllowIn();
  7379. return this.finishNode(node, "AssignmentPattern");
  7380. }
  7381. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  7382. return getOwn$1({
  7383. AssignmentPattern: "left",
  7384. RestElement: "argument",
  7385. ObjectProperty: "value",
  7386. ParenthesizedExpression: "expression",
  7387. ArrayPattern: "elements",
  7388. ObjectPattern: "properties"
  7389. }, type);
  7390. }
  7391. isOptionalMemberExpression(expression) {
  7392. return expression.type === "OptionalMemberExpression";
  7393. }
  7394. checkLVal(expression, {
  7395. in: ancestor,
  7396. binding = 64,
  7397. checkClashes = false,
  7398. strictModeChanged = false,
  7399. hasParenthesizedAncestor = false
  7400. }) {
  7401. var _expression$extra;
  7402. const type = expression.type;
  7403. if (this.isObjectMethod(expression)) return;
  7404. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  7405. if (isOptionalMemberExpression || type === "MemberExpression") {
  7406. if (isOptionalMemberExpression) {
  7407. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  7408. if (ancestor.type !== "AssignmentExpression") {
  7409. this.raise(Errors.InvalidLhsOptionalChaining, {
  7410. at: expression,
  7411. ancestor
  7412. });
  7413. }
  7414. }
  7415. if (binding !== 64) {
  7416. this.raise(Errors.InvalidPropertyBindingPattern, {
  7417. at: expression
  7418. });
  7419. }
  7420. return;
  7421. }
  7422. if (type === "Identifier") {
  7423. this.checkIdentifier(expression, binding, strictModeChanged);
  7424. const {
  7425. name
  7426. } = expression;
  7427. if (checkClashes) {
  7428. if (checkClashes.has(name)) {
  7429. this.raise(Errors.ParamDupe, {
  7430. at: expression
  7431. });
  7432. } else {
  7433. checkClashes.add(name);
  7434. }
  7435. }
  7436. return;
  7437. }
  7438. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  7439. if (validity === true) return;
  7440. if (validity === false) {
  7441. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  7442. this.raise(ParseErrorClass, {
  7443. at: expression,
  7444. ancestor
  7445. });
  7446. return;
  7447. }
  7448. const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"];
  7449. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  7450. type
  7451. } : ancestor;
  7452. for (const child of [].concat(expression[key])) {
  7453. if (child) {
  7454. this.checkLVal(child, {
  7455. in: nextAncestor,
  7456. binding,
  7457. checkClashes,
  7458. strictModeChanged,
  7459. hasParenthesizedAncestor: isParenthesizedExpression
  7460. });
  7461. }
  7462. }
  7463. }
  7464. checkIdentifier(at, bindingType, strictModeChanged = false) {
  7465. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  7466. if (bindingType === 64) {
  7467. this.raise(Errors.StrictEvalArguments, {
  7468. at,
  7469. referenceName: at.name
  7470. });
  7471. } else {
  7472. this.raise(Errors.StrictEvalArgumentsBinding, {
  7473. at,
  7474. bindingName: at.name
  7475. });
  7476. }
  7477. }
  7478. if (bindingType & 8192 && at.name === "let") {
  7479. this.raise(Errors.LetInLexicalBinding, {
  7480. at
  7481. });
  7482. }
  7483. if (!(bindingType & 64)) {
  7484. this.declareNameFromIdentifier(at, bindingType);
  7485. }
  7486. }
  7487. declareNameFromIdentifier(identifier, binding) {
  7488. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  7489. }
  7490. checkToRestConversion(node, allowPattern) {
  7491. switch (node.type) {
  7492. case "ParenthesizedExpression":
  7493. this.checkToRestConversion(node.expression, allowPattern);
  7494. break;
  7495. case "Identifier":
  7496. case "MemberExpression":
  7497. break;
  7498. case "ArrayExpression":
  7499. case "ObjectExpression":
  7500. if (allowPattern) break;
  7501. default:
  7502. this.raise(Errors.InvalidRestAssignmentPattern, {
  7503. at: node
  7504. });
  7505. }
  7506. }
  7507. checkCommaAfterRest(close) {
  7508. if (!this.match(12)) {
  7509. return false;
  7510. }
  7511. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, {
  7512. at: this.state.startLoc
  7513. });
  7514. return true;
  7515. }
  7516. }
  7517. const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key];
  7518. function nonNull(x) {
  7519. if (x == null) {
  7520. throw new Error(`Unexpected ${x} value.`);
  7521. }
  7522. return x;
  7523. }
  7524. function assert(x) {
  7525. if (!x) {
  7526. throw new Error("Assert fail");
  7527. }
  7528. }
  7529. const TSErrors = ParseErrorEnum`typescript`({
  7530. AbstractMethodHasImplementation: ({
  7531. methodName
  7532. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  7533. AbstractPropertyHasInitializer: ({
  7534. propertyName
  7535. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  7536. AccesorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  7537. AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  7538. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  7539. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  7540. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  7541. ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  7542. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  7543. DeclareAccessor: ({
  7544. kind
  7545. }) => `'declare' is not allowed in ${kind}ters.`,
  7546. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  7547. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  7548. DuplicateAccessibilityModifier: ({
  7549. modifier
  7550. }) => `Accessibility modifier already seen.`,
  7551. DuplicateModifier: ({
  7552. modifier
  7553. }) => `Duplicate modifier: '${modifier}'.`,
  7554. EmptyHeritageClauseType: ({
  7555. token
  7556. }) => `'${token}' list cannot be empty.`,
  7557. EmptyTypeArguments: "Type argument list cannot be empty.",
  7558. EmptyTypeParameters: "Type parameter list cannot be empty.",
  7559. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  7560. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  7561. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  7562. IncompatibleModifiers: ({
  7563. modifiers
  7564. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  7565. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  7566. IndexSignatureHasAccessibility: ({
  7567. modifier
  7568. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  7569. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  7570. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  7571. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  7572. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  7573. InvalidModifierOnTypeMember: ({
  7574. modifier
  7575. }) => `'${modifier}' modifier cannot appear on a type member.`,
  7576. InvalidModifierOnTypeParameter: ({
  7577. modifier
  7578. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  7579. InvalidModifierOnTypeParameterPositions: ({
  7580. modifier
  7581. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  7582. InvalidModifiersOrder: ({
  7583. orderedModifiers
  7584. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  7585. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  7586. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  7587. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  7588. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  7589. NonClassMethodPropertyHasAbstractModifer: "'abstract' modifier can only appear on a class, method, or property declaration.",
  7590. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  7591. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  7592. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  7593. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  7594. PrivateElementHasAccessibility: ({
  7595. modifier
  7596. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  7597. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  7598. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  7599. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  7600. SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  7601. SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  7602. SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  7603. SingleTypeParameterWithoutTrailingComma: ({
  7604. typeParameterName
  7605. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  7606. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  7607. 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?`).",
  7608. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  7609. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  7610. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  7611. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  7612. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  7613. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  7614. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  7615. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  7616. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  7617. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  7618. UnsupportedSignatureParameterKind: ({
  7619. type
  7620. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
  7621. });
  7622. function keywordTypeFromName(value) {
  7623. switch (value) {
  7624. case "any":
  7625. return "TSAnyKeyword";
  7626. case "boolean":
  7627. return "TSBooleanKeyword";
  7628. case "bigint":
  7629. return "TSBigIntKeyword";
  7630. case "never":
  7631. return "TSNeverKeyword";
  7632. case "number":
  7633. return "TSNumberKeyword";
  7634. case "object":
  7635. return "TSObjectKeyword";
  7636. case "string":
  7637. return "TSStringKeyword";
  7638. case "symbol":
  7639. return "TSSymbolKeyword";
  7640. case "undefined":
  7641. return "TSUndefinedKeyword";
  7642. case "unknown":
  7643. return "TSUnknownKeyword";
  7644. default:
  7645. return undefined;
  7646. }
  7647. }
  7648. function tsIsAccessModifier(modifier) {
  7649. return modifier === "private" || modifier === "public" || modifier === "protected";
  7650. }
  7651. function tsIsVarianceAnnotations(modifier) {
  7652. return modifier === "in" || modifier === "out";
  7653. }
  7654. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  7655. constructor(...args) {
  7656. super(...args);
  7657. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  7658. allowedModifiers: ["in", "out"],
  7659. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7660. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7661. });
  7662. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  7663. allowedModifiers: ["const"],
  7664. disallowedModifiers: ["in", "out"],
  7665. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  7666. });
  7667. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  7668. allowedModifiers: ["in", "out", "const"],
  7669. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  7670. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  7671. });
  7672. }
  7673. getScopeHandler() {
  7674. return TypeScriptScopeHandler;
  7675. }
  7676. tsIsIdentifier() {
  7677. return tokenIsIdentifier(this.state.type);
  7678. }
  7679. tsTokenCanFollowModifier() {
  7680. return (this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(138) || this.isLiteralPropertyName()) && !this.hasPrecedingLineBreak();
  7681. }
  7682. tsNextTokenCanFollowModifier() {
  7683. this.next();
  7684. return this.tsTokenCanFollowModifier();
  7685. }
  7686. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock) {
  7687. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  7688. return undefined;
  7689. }
  7690. const modifier = this.state.value;
  7691. if (allowedModifiers.indexOf(modifier) !== -1) {
  7692. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  7693. return undefined;
  7694. }
  7695. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  7696. return modifier;
  7697. }
  7698. }
  7699. return undefined;
  7700. }
  7701. tsParseModifiers({
  7702. allowedModifiers,
  7703. disallowedModifiers,
  7704. stopOnStartOfClassStaticBlock,
  7705. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  7706. }, modified) {
  7707. const enforceOrder = (loc, modifier, before, after) => {
  7708. if (modifier === before && modified[after]) {
  7709. this.raise(TSErrors.InvalidModifiersOrder, {
  7710. at: loc,
  7711. orderedModifiers: [before, after]
  7712. });
  7713. }
  7714. };
  7715. const incompatible = (loc, modifier, mod1, mod2) => {
  7716. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  7717. this.raise(TSErrors.IncompatibleModifiers, {
  7718. at: loc,
  7719. modifiers: [mod1, mod2]
  7720. });
  7721. }
  7722. };
  7723. for (;;) {
  7724. const {
  7725. startLoc
  7726. } = this.state;
  7727. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock);
  7728. if (!modifier) break;
  7729. if (tsIsAccessModifier(modifier)) {
  7730. if (modified.accessibility) {
  7731. this.raise(TSErrors.DuplicateAccessibilityModifier, {
  7732. at: startLoc,
  7733. modifier
  7734. });
  7735. } else {
  7736. enforceOrder(startLoc, modifier, modifier, "override");
  7737. enforceOrder(startLoc, modifier, modifier, "static");
  7738. enforceOrder(startLoc, modifier, modifier, "readonly");
  7739. modified.accessibility = modifier;
  7740. }
  7741. } else if (tsIsVarianceAnnotations(modifier)) {
  7742. if (modified[modifier]) {
  7743. this.raise(TSErrors.DuplicateModifier, {
  7744. at: startLoc,
  7745. modifier
  7746. });
  7747. }
  7748. modified[modifier] = true;
  7749. enforceOrder(startLoc, modifier, "in", "out");
  7750. } else {
  7751. if (Object.hasOwnProperty.call(modified, modifier)) {
  7752. this.raise(TSErrors.DuplicateModifier, {
  7753. at: startLoc,
  7754. modifier
  7755. });
  7756. } else {
  7757. enforceOrder(startLoc, modifier, "static", "readonly");
  7758. enforceOrder(startLoc, modifier, "static", "override");
  7759. enforceOrder(startLoc, modifier, "override", "readonly");
  7760. enforceOrder(startLoc, modifier, "abstract", "override");
  7761. incompatible(startLoc, modifier, "declare", "override");
  7762. incompatible(startLoc, modifier, "static", "abstract");
  7763. }
  7764. modified[modifier] = true;
  7765. }
  7766. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  7767. this.raise(errorTemplate, {
  7768. at: startLoc,
  7769. modifier
  7770. });
  7771. }
  7772. }
  7773. }
  7774. tsIsListTerminator(kind) {
  7775. switch (kind) {
  7776. case "EnumMembers":
  7777. case "TypeMembers":
  7778. return this.match(8);
  7779. case "HeritageClauseElement":
  7780. return this.match(5);
  7781. case "TupleElementTypes":
  7782. return this.match(3);
  7783. case "TypeParametersOrArguments":
  7784. return this.match(48);
  7785. }
  7786. }
  7787. tsParseList(kind, parseElement) {
  7788. const result = [];
  7789. while (!this.tsIsListTerminator(kind)) {
  7790. result.push(parseElement());
  7791. }
  7792. return result;
  7793. }
  7794. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  7795. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  7796. }
  7797. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  7798. const result = [];
  7799. let trailingCommaPos = -1;
  7800. for (;;) {
  7801. if (this.tsIsListTerminator(kind)) {
  7802. break;
  7803. }
  7804. trailingCommaPos = -1;
  7805. const element = parseElement();
  7806. if (element == null) {
  7807. return undefined;
  7808. }
  7809. result.push(element);
  7810. if (this.eat(12)) {
  7811. trailingCommaPos = this.state.lastTokStart;
  7812. continue;
  7813. }
  7814. if (this.tsIsListTerminator(kind)) {
  7815. break;
  7816. }
  7817. if (expectSuccess) {
  7818. this.expect(12);
  7819. }
  7820. return undefined;
  7821. }
  7822. if (refTrailingCommaPos) {
  7823. refTrailingCommaPos.value = trailingCommaPos;
  7824. }
  7825. return result;
  7826. }
  7827. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  7828. if (!skipFirstToken) {
  7829. if (bracket) {
  7830. this.expect(0);
  7831. } else {
  7832. this.expect(47);
  7833. }
  7834. }
  7835. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  7836. if (bracket) {
  7837. this.expect(3);
  7838. } else {
  7839. this.expect(48);
  7840. }
  7841. return result;
  7842. }
  7843. tsParseImportType() {
  7844. const node = this.startNode();
  7845. this.expect(83);
  7846. this.expect(10);
  7847. if (!this.match(133)) {
  7848. this.raise(TSErrors.UnsupportedImportTypeArgument, {
  7849. at: this.state.startLoc
  7850. });
  7851. }
  7852. node.argument = super.parseExprAtom();
  7853. this.expect(11);
  7854. if (this.eat(16)) {
  7855. node.qualifier = this.tsParseEntityName();
  7856. }
  7857. if (this.match(47)) {
  7858. node.typeParameters = this.tsParseTypeArguments();
  7859. }
  7860. return this.finishNode(node, "TSImportType");
  7861. }
  7862. tsParseEntityName(allowReservedWords = true) {
  7863. let entity = this.parseIdentifier(allowReservedWords);
  7864. while (this.eat(16)) {
  7865. const node = this.startNodeAtNode(entity);
  7866. node.left = entity;
  7867. node.right = this.parseIdentifier(allowReservedWords);
  7868. entity = this.finishNode(node, "TSQualifiedName");
  7869. }
  7870. return entity;
  7871. }
  7872. tsParseTypeReference() {
  7873. const node = this.startNode();
  7874. node.typeName = this.tsParseEntityName();
  7875. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7876. node.typeParameters = this.tsParseTypeArguments();
  7877. }
  7878. return this.finishNode(node, "TSTypeReference");
  7879. }
  7880. tsParseThisTypePredicate(lhs) {
  7881. this.next();
  7882. const node = this.startNodeAtNode(lhs);
  7883. node.parameterName = lhs;
  7884. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  7885. node.asserts = false;
  7886. return this.finishNode(node, "TSTypePredicate");
  7887. }
  7888. tsParseThisTypeNode() {
  7889. const node = this.startNode();
  7890. this.next();
  7891. return this.finishNode(node, "TSThisType");
  7892. }
  7893. tsParseTypeQuery() {
  7894. const node = this.startNode();
  7895. this.expect(87);
  7896. if (this.match(83)) {
  7897. node.exprName = this.tsParseImportType();
  7898. } else {
  7899. node.exprName = this.tsParseEntityName();
  7900. }
  7901. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  7902. node.typeParameters = this.tsParseTypeArguments();
  7903. }
  7904. return this.finishNode(node, "TSTypeQuery");
  7905. }
  7906. tsParseTypeParameter(parseModifiers) {
  7907. const node = this.startNode();
  7908. parseModifiers(node);
  7909. node.name = this.tsParseTypeParameterName();
  7910. node.constraint = this.tsEatThenParseType(81);
  7911. node.default = this.tsEatThenParseType(29);
  7912. return this.finishNode(node, "TSTypeParameter");
  7913. }
  7914. tsTryParseTypeParameters(parseModifiers) {
  7915. if (this.match(47)) {
  7916. return this.tsParseTypeParameters(parseModifiers);
  7917. }
  7918. }
  7919. tsParseTypeParameters(parseModifiers) {
  7920. const node = this.startNode();
  7921. if (this.match(47) || this.match(142)) {
  7922. this.next();
  7923. } else {
  7924. this.unexpected();
  7925. }
  7926. const refTrailingCommaPos = {
  7927. value: -1
  7928. };
  7929. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  7930. if (node.params.length === 0) {
  7931. this.raise(TSErrors.EmptyTypeParameters, {
  7932. at: node
  7933. });
  7934. }
  7935. if (refTrailingCommaPos.value !== -1) {
  7936. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  7937. }
  7938. return this.finishNode(node, "TSTypeParameterDeclaration");
  7939. }
  7940. tsFillSignature(returnToken, signature) {
  7941. const returnTokenRequired = returnToken === 19;
  7942. const paramsKey = "parameters";
  7943. const returnTypeKey = "typeAnnotation";
  7944. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  7945. this.expect(10);
  7946. signature[paramsKey] = this.tsParseBindingListForSignature();
  7947. if (returnTokenRequired) {
  7948. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7949. } else if (this.match(returnToken)) {
  7950. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  7951. }
  7952. }
  7953. tsParseBindingListForSignature() {
  7954. const list = super.parseBindingList(11, 41, 2);
  7955. for (const pattern of list) {
  7956. const {
  7957. type
  7958. } = pattern;
  7959. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  7960. this.raise(TSErrors.UnsupportedSignatureParameterKind, {
  7961. at: pattern,
  7962. type
  7963. });
  7964. }
  7965. }
  7966. return list;
  7967. }
  7968. tsParseTypeMemberSemicolon() {
  7969. if (!this.eat(12) && !this.isLineTerminator()) {
  7970. this.expect(13);
  7971. }
  7972. }
  7973. tsParseSignatureMember(kind, node) {
  7974. this.tsFillSignature(14, node);
  7975. this.tsParseTypeMemberSemicolon();
  7976. return this.finishNode(node, kind);
  7977. }
  7978. tsIsUnambiguouslyIndexSignature() {
  7979. this.next();
  7980. if (tokenIsIdentifier(this.state.type)) {
  7981. this.next();
  7982. return this.match(14);
  7983. }
  7984. return false;
  7985. }
  7986. tsTryParseIndexSignature(node) {
  7987. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  7988. return;
  7989. }
  7990. this.expect(0);
  7991. const id = this.parseIdentifier();
  7992. id.typeAnnotation = this.tsParseTypeAnnotation();
  7993. this.resetEndLocation(id);
  7994. this.expect(3);
  7995. node.parameters = [id];
  7996. const type = this.tsTryParseTypeAnnotation();
  7997. if (type) node.typeAnnotation = type;
  7998. this.tsParseTypeMemberSemicolon();
  7999. return this.finishNode(node, "TSIndexSignature");
  8000. }
  8001. tsParsePropertyOrMethodSignature(node, readonly) {
  8002. if (this.eat(17)) node.optional = true;
  8003. const nodeAny = node;
  8004. if (this.match(10) || this.match(47)) {
  8005. if (readonly) {
  8006. this.raise(TSErrors.ReadonlyForMethodSignature, {
  8007. at: node
  8008. });
  8009. }
  8010. const method = nodeAny;
  8011. if (method.kind && this.match(47)) {
  8012. this.raise(TSErrors.AccesorCannotHaveTypeParameters, {
  8013. at: this.state.curPosition()
  8014. });
  8015. }
  8016. this.tsFillSignature(14, method);
  8017. this.tsParseTypeMemberSemicolon();
  8018. const paramsKey = "parameters";
  8019. const returnTypeKey = "typeAnnotation";
  8020. if (method.kind === "get") {
  8021. if (method[paramsKey].length > 0) {
  8022. this.raise(Errors.BadGetterArity, {
  8023. at: this.state.curPosition()
  8024. });
  8025. if (this.isThisParam(method[paramsKey][0])) {
  8026. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8027. at: this.state.curPosition()
  8028. });
  8029. }
  8030. }
  8031. } else if (method.kind === "set") {
  8032. if (method[paramsKey].length !== 1) {
  8033. this.raise(Errors.BadSetterArity, {
  8034. at: this.state.curPosition()
  8035. });
  8036. } else {
  8037. const firstParameter = method[paramsKey][0];
  8038. if (this.isThisParam(firstParameter)) {
  8039. this.raise(TSErrors.AccesorCannotDeclareThisParameter, {
  8040. at: this.state.curPosition()
  8041. });
  8042. }
  8043. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  8044. this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, {
  8045. at: this.state.curPosition()
  8046. });
  8047. }
  8048. if (firstParameter.type === "RestElement") {
  8049. this.raise(TSErrors.SetAccesorCannotHaveRestParameter, {
  8050. at: this.state.curPosition()
  8051. });
  8052. }
  8053. }
  8054. if (method[returnTypeKey]) {
  8055. this.raise(TSErrors.SetAccesorCannotHaveReturnType, {
  8056. at: method[returnTypeKey]
  8057. });
  8058. }
  8059. } else {
  8060. method.kind = "method";
  8061. }
  8062. return this.finishNode(method, "TSMethodSignature");
  8063. } else {
  8064. const property = nodeAny;
  8065. if (readonly) property.readonly = true;
  8066. const type = this.tsTryParseTypeAnnotation();
  8067. if (type) property.typeAnnotation = type;
  8068. this.tsParseTypeMemberSemicolon();
  8069. return this.finishNode(property, "TSPropertySignature");
  8070. }
  8071. }
  8072. tsParseTypeMember() {
  8073. const node = this.startNode();
  8074. if (this.match(10) || this.match(47)) {
  8075. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  8076. }
  8077. if (this.match(77)) {
  8078. const id = this.startNode();
  8079. this.next();
  8080. if (this.match(10) || this.match(47)) {
  8081. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  8082. } else {
  8083. node.key = this.createIdentifier(id, "new");
  8084. return this.tsParsePropertyOrMethodSignature(node, false);
  8085. }
  8086. }
  8087. this.tsParseModifiers({
  8088. allowedModifiers: ["readonly"],
  8089. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  8090. }, node);
  8091. const idx = this.tsTryParseIndexSignature(node);
  8092. if (idx) {
  8093. return idx;
  8094. }
  8095. super.parsePropertyName(node);
  8096. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  8097. node.kind = node.key.name;
  8098. super.parsePropertyName(node);
  8099. }
  8100. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  8101. }
  8102. tsParseTypeLiteral() {
  8103. const node = this.startNode();
  8104. node.members = this.tsParseObjectTypeMembers();
  8105. return this.finishNode(node, "TSTypeLiteral");
  8106. }
  8107. tsParseObjectTypeMembers() {
  8108. this.expect(5);
  8109. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  8110. this.expect(8);
  8111. return members;
  8112. }
  8113. tsIsStartOfMappedType() {
  8114. this.next();
  8115. if (this.eat(53)) {
  8116. return this.isContextual(122);
  8117. }
  8118. if (this.isContextual(122)) {
  8119. this.next();
  8120. }
  8121. if (!this.match(0)) {
  8122. return false;
  8123. }
  8124. this.next();
  8125. if (!this.tsIsIdentifier()) {
  8126. return false;
  8127. }
  8128. this.next();
  8129. return this.match(58);
  8130. }
  8131. tsParseMappedTypeParameter() {
  8132. const node = this.startNode();
  8133. node.name = this.tsParseTypeParameterName();
  8134. node.constraint = this.tsExpectThenParseType(58);
  8135. return this.finishNode(node, "TSTypeParameter");
  8136. }
  8137. tsParseMappedType() {
  8138. const node = this.startNode();
  8139. this.expect(5);
  8140. if (this.match(53)) {
  8141. node.readonly = this.state.value;
  8142. this.next();
  8143. this.expectContextual(122);
  8144. } else if (this.eatContextual(122)) {
  8145. node.readonly = true;
  8146. }
  8147. this.expect(0);
  8148. node.typeParameter = this.tsParseMappedTypeParameter();
  8149. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  8150. this.expect(3);
  8151. if (this.match(53)) {
  8152. node.optional = this.state.value;
  8153. this.next();
  8154. this.expect(17);
  8155. } else if (this.eat(17)) {
  8156. node.optional = true;
  8157. }
  8158. node.typeAnnotation = this.tsTryParseType();
  8159. this.semicolon();
  8160. this.expect(8);
  8161. return this.finishNode(node, "TSMappedType");
  8162. }
  8163. tsParseTupleType() {
  8164. const node = this.startNode();
  8165. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  8166. let seenOptionalElement = false;
  8167. node.elementTypes.forEach(elementNode => {
  8168. const {
  8169. type
  8170. } = elementNode;
  8171. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  8172. this.raise(TSErrors.OptionalTypeBeforeRequired, {
  8173. at: elementNode
  8174. });
  8175. }
  8176. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  8177. });
  8178. return this.finishNode(node, "TSTupleType");
  8179. }
  8180. tsParseTupleElementType() {
  8181. const {
  8182. startLoc
  8183. } = this.state;
  8184. const rest = this.eat(21);
  8185. let labeled;
  8186. let label;
  8187. let optional;
  8188. let type;
  8189. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  8190. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  8191. if (chAfterWord === 58) {
  8192. labeled = true;
  8193. optional = false;
  8194. label = this.parseIdentifier(true);
  8195. this.expect(14);
  8196. type = this.tsParseType();
  8197. } else if (chAfterWord === 63) {
  8198. optional = true;
  8199. const startLoc = this.state.startLoc;
  8200. const wordName = this.state.value;
  8201. const typeOrLabel = this.tsParseNonArrayType();
  8202. if (this.lookaheadCharCode() === 58) {
  8203. labeled = true;
  8204. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  8205. this.expect(17);
  8206. this.expect(14);
  8207. type = this.tsParseType();
  8208. } else {
  8209. labeled = false;
  8210. type = typeOrLabel;
  8211. this.expect(17);
  8212. }
  8213. } else {
  8214. type = this.tsParseType();
  8215. optional = this.eat(17);
  8216. labeled = this.eat(14);
  8217. }
  8218. if (labeled) {
  8219. let labeledNode;
  8220. if (label) {
  8221. labeledNode = this.startNodeAtNode(label);
  8222. labeledNode.optional = optional;
  8223. labeledNode.label = label;
  8224. labeledNode.elementType = type;
  8225. if (this.eat(17)) {
  8226. labeledNode.optional = true;
  8227. this.raise(TSErrors.TupleOptionalAfterType, {
  8228. at: this.state.lastTokStartLoc
  8229. });
  8230. }
  8231. } else {
  8232. labeledNode = this.startNodeAtNode(type);
  8233. labeledNode.optional = optional;
  8234. this.raise(TSErrors.InvalidTupleMemberLabel, {
  8235. at: type
  8236. });
  8237. labeledNode.label = type;
  8238. labeledNode.elementType = this.tsParseType();
  8239. }
  8240. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  8241. } else if (optional) {
  8242. const optionalTypeNode = this.startNodeAtNode(type);
  8243. optionalTypeNode.typeAnnotation = type;
  8244. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  8245. }
  8246. if (rest) {
  8247. const restNode = this.startNodeAt(startLoc);
  8248. restNode.typeAnnotation = type;
  8249. type = this.finishNode(restNode, "TSRestType");
  8250. }
  8251. return type;
  8252. }
  8253. tsParseParenthesizedType() {
  8254. const node = this.startNode();
  8255. this.expect(10);
  8256. node.typeAnnotation = this.tsParseType();
  8257. this.expect(11);
  8258. return this.finishNode(node, "TSParenthesizedType");
  8259. }
  8260. tsParseFunctionOrConstructorType(type, abstract) {
  8261. const node = this.startNode();
  8262. if (type === "TSConstructorType") {
  8263. node.abstract = !!abstract;
  8264. if (abstract) this.next();
  8265. this.next();
  8266. }
  8267. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  8268. return this.finishNode(node, type);
  8269. }
  8270. tsParseLiteralTypeNode() {
  8271. const node = this.startNode();
  8272. switch (this.state.type) {
  8273. case 134:
  8274. case 135:
  8275. case 133:
  8276. case 85:
  8277. case 86:
  8278. node.literal = super.parseExprAtom();
  8279. break;
  8280. default:
  8281. this.unexpected();
  8282. }
  8283. return this.finishNode(node, "TSLiteralType");
  8284. }
  8285. tsParseTemplateLiteralType() {
  8286. const node = this.startNode();
  8287. node.literal = super.parseTemplate(false);
  8288. return this.finishNode(node, "TSLiteralType");
  8289. }
  8290. parseTemplateSubstitution() {
  8291. if (this.state.inType) return this.tsParseType();
  8292. return super.parseTemplateSubstitution();
  8293. }
  8294. tsParseThisTypeOrThisTypePredicate() {
  8295. const thisKeyword = this.tsParseThisTypeNode();
  8296. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8297. return this.tsParseThisTypePredicate(thisKeyword);
  8298. } else {
  8299. return thisKeyword;
  8300. }
  8301. }
  8302. tsParseNonArrayType() {
  8303. switch (this.state.type) {
  8304. case 133:
  8305. case 134:
  8306. case 135:
  8307. case 85:
  8308. case 86:
  8309. return this.tsParseLiteralTypeNode();
  8310. case 53:
  8311. if (this.state.value === "-") {
  8312. const node = this.startNode();
  8313. const nextToken = this.lookahead();
  8314. if (nextToken.type !== 134 && nextToken.type !== 135) {
  8315. this.unexpected();
  8316. }
  8317. node.literal = this.parseMaybeUnary();
  8318. return this.finishNode(node, "TSLiteralType");
  8319. }
  8320. break;
  8321. case 78:
  8322. return this.tsParseThisTypeOrThisTypePredicate();
  8323. case 87:
  8324. return this.tsParseTypeQuery();
  8325. case 83:
  8326. return this.tsParseImportType();
  8327. case 5:
  8328. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  8329. case 0:
  8330. return this.tsParseTupleType();
  8331. case 10:
  8332. return this.tsParseParenthesizedType();
  8333. case 25:
  8334. case 24:
  8335. return this.tsParseTemplateLiteralType();
  8336. default:
  8337. {
  8338. const {
  8339. type
  8340. } = this.state;
  8341. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  8342. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  8343. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  8344. const node = this.startNode();
  8345. this.next();
  8346. return this.finishNode(node, nodeType);
  8347. }
  8348. return this.tsParseTypeReference();
  8349. }
  8350. }
  8351. }
  8352. this.unexpected();
  8353. }
  8354. tsParseArrayTypeOrHigher() {
  8355. let type = this.tsParseNonArrayType();
  8356. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  8357. if (this.match(3)) {
  8358. const node = this.startNodeAtNode(type);
  8359. node.elementType = type;
  8360. this.expect(3);
  8361. type = this.finishNode(node, "TSArrayType");
  8362. } else {
  8363. const node = this.startNodeAtNode(type);
  8364. node.objectType = type;
  8365. node.indexType = this.tsParseType();
  8366. this.expect(3);
  8367. type = this.finishNode(node, "TSIndexedAccessType");
  8368. }
  8369. }
  8370. return type;
  8371. }
  8372. tsParseTypeOperator() {
  8373. const node = this.startNode();
  8374. const operator = this.state.value;
  8375. this.next();
  8376. node.operator = operator;
  8377. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  8378. if (operator === "readonly") {
  8379. this.tsCheckTypeAnnotationForReadOnly(node);
  8380. }
  8381. return this.finishNode(node, "TSTypeOperator");
  8382. }
  8383. tsCheckTypeAnnotationForReadOnly(node) {
  8384. switch (node.typeAnnotation.type) {
  8385. case "TSTupleType":
  8386. case "TSArrayType":
  8387. return;
  8388. default:
  8389. this.raise(TSErrors.UnexpectedReadonly, {
  8390. at: node
  8391. });
  8392. }
  8393. }
  8394. tsParseInferType() {
  8395. const node = this.startNode();
  8396. this.expectContextual(115);
  8397. const typeParameter = this.startNode();
  8398. typeParameter.name = this.tsParseTypeParameterName();
  8399. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  8400. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  8401. return this.finishNode(node, "TSInferType");
  8402. }
  8403. tsParseConstraintForInferType() {
  8404. if (this.eat(81)) {
  8405. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  8406. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  8407. return constraint;
  8408. }
  8409. }
  8410. }
  8411. tsParseTypeOperatorOrHigher() {
  8412. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  8413. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  8414. }
  8415. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  8416. const node = this.startNode();
  8417. const hasLeadingOperator = this.eat(operator);
  8418. const types = [];
  8419. do {
  8420. types.push(parseConstituentType());
  8421. } while (this.eat(operator));
  8422. if (types.length === 1 && !hasLeadingOperator) {
  8423. return types[0];
  8424. }
  8425. node.types = types;
  8426. return this.finishNode(node, kind);
  8427. }
  8428. tsParseIntersectionTypeOrHigher() {
  8429. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  8430. }
  8431. tsParseUnionTypeOrHigher() {
  8432. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  8433. }
  8434. tsIsStartOfFunctionType() {
  8435. if (this.match(47)) {
  8436. return true;
  8437. }
  8438. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  8439. }
  8440. tsSkipParameterStart() {
  8441. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  8442. this.next();
  8443. return true;
  8444. }
  8445. if (this.match(5)) {
  8446. const {
  8447. errors
  8448. } = this.state;
  8449. const previousErrorCount = errors.length;
  8450. try {
  8451. this.parseObjectLike(8, true);
  8452. return errors.length === previousErrorCount;
  8453. } catch (_unused) {
  8454. return false;
  8455. }
  8456. }
  8457. if (this.match(0)) {
  8458. this.next();
  8459. const {
  8460. errors
  8461. } = this.state;
  8462. const previousErrorCount = errors.length;
  8463. try {
  8464. super.parseBindingList(3, 93, 1);
  8465. return errors.length === previousErrorCount;
  8466. } catch (_unused2) {
  8467. return false;
  8468. }
  8469. }
  8470. return false;
  8471. }
  8472. tsIsUnambiguouslyStartOfFunctionType() {
  8473. this.next();
  8474. if (this.match(11) || this.match(21)) {
  8475. return true;
  8476. }
  8477. if (this.tsSkipParameterStart()) {
  8478. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  8479. return true;
  8480. }
  8481. if (this.match(11)) {
  8482. this.next();
  8483. if (this.match(19)) {
  8484. return true;
  8485. }
  8486. }
  8487. }
  8488. return false;
  8489. }
  8490. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  8491. return this.tsInType(() => {
  8492. const t = this.startNode();
  8493. this.expect(returnToken);
  8494. const node = this.startNode();
  8495. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  8496. if (asserts && this.match(78)) {
  8497. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  8498. if (thisTypePredicate.type === "TSThisType") {
  8499. node.parameterName = thisTypePredicate;
  8500. node.asserts = true;
  8501. node.typeAnnotation = null;
  8502. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  8503. } else {
  8504. this.resetStartLocationFromNode(thisTypePredicate, node);
  8505. thisTypePredicate.asserts = true;
  8506. }
  8507. t.typeAnnotation = thisTypePredicate;
  8508. return this.finishNode(t, "TSTypeAnnotation");
  8509. }
  8510. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  8511. if (!typePredicateVariable) {
  8512. if (!asserts) {
  8513. return this.tsParseTypeAnnotation(false, t);
  8514. }
  8515. node.parameterName = this.parseIdentifier();
  8516. node.asserts = asserts;
  8517. node.typeAnnotation = null;
  8518. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8519. return this.finishNode(t, "TSTypeAnnotation");
  8520. }
  8521. const type = this.tsParseTypeAnnotation(false);
  8522. node.parameterName = typePredicateVariable;
  8523. node.typeAnnotation = type;
  8524. node.asserts = asserts;
  8525. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  8526. return this.finishNode(t, "TSTypeAnnotation");
  8527. });
  8528. }
  8529. tsTryParseTypeOrTypePredicateAnnotation() {
  8530. if (this.match(14)) {
  8531. return this.tsParseTypeOrTypePredicateAnnotation(14);
  8532. }
  8533. }
  8534. tsTryParseTypeAnnotation() {
  8535. if (this.match(14)) {
  8536. return this.tsParseTypeAnnotation();
  8537. }
  8538. }
  8539. tsTryParseType() {
  8540. return this.tsEatThenParseType(14);
  8541. }
  8542. tsParseTypePredicatePrefix() {
  8543. const id = this.parseIdentifier();
  8544. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  8545. this.next();
  8546. return id;
  8547. }
  8548. }
  8549. tsParseTypePredicateAsserts() {
  8550. if (this.state.type !== 109) {
  8551. return false;
  8552. }
  8553. const containsEsc = this.state.containsEsc;
  8554. this.next();
  8555. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  8556. return false;
  8557. }
  8558. if (containsEsc) {
  8559. this.raise(Errors.InvalidEscapedReservedWord, {
  8560. at: this.state.lastTokStartLoc,
  8561. reservedWord: "asserts"
  8562. });
  8563. }
  8564. return true;
  8565. }
  8566. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  8567. this.tsInType(() => {
  8568. if (eatColon) this.expect(14);
  8569. t.typeAnnotation = this.tsParseType();
  8570. });
  8571. return this.finishNode(t, "TSTypeAnnotation");
  8572. }
  8573. tsParseType() {
  8574. assert(this.state.inType);
  8575. const type = this.tsParseNonConditionalType();
  8576. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  8577. return type;
  8578. }
  8579. const node = this.startNodeAtNode(type);
  8580. node.checkType = type;
  8581. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  8582. this.expect(17);
  8583. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8584. this.expect(14);
  8585. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  8586. return this.finishNode(node, "TSConditionalType");
  8587. }
  8588. isAbstractConstructorSignature() {
  8589. return this.isContextual(124) && this.lookahead().type === 77;
  8590. }
  8591. tsParseNonConditionalType() {
  8592. if (this.tsIsStartOfFunctionType()) {
  8593. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  8594. }
  8595. if (this.match(77)) {
  8596. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  8597. } else if (this.isAbstractConstructorSignature()) {
  8598. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  8599. }
  8600. return this.tsParseUnionTypeOrHigher();
  8601. }
  8602. tsParseTypeAssertion() {
  8603. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  8604. this.raise(TSErrors.ReservedTypeAssertion, {
  8605. at: this.state.startLoc
  8606. });
  8607. }
  8608. const node = this.startNode();
  8609. node.typeAnnotation = this.tsInType(() => {
  8610. this.next();
  8611. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  8612. });
  8613. this.expect(48);
  8614. node.expression = this.parseMaybeUnary();
  8615. return this.finishNode(node, "TSTypeAssertion");
  8616. }
  8617. tsParseHeritageClause(token) {
  8618. const originalStartLoc = this.state.startLoc;
  8619. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  8620. const node = this.startNode();
  8621. node.expression = this.tsParseEntityName();
  8622. if (this.match(47)) {
  8623. node.typeParameters = this.tsParseTypeArguments();
  8624. }
  8625. return this.finishNode(node, "TSExpressionWithTypeArguments");
  8626. });
  8627. if (!delimitedList.length) {
  8628. this.raise(TSErrors.EmptyHeritageClauseType, {
  8629. at: originalStartLoc,
  8630. token
  8631. });
  8632. }
  8633. return delimitedList;
  8634. }
  8635. tsParseInterfaceDeclaration(node, properties = {}) {
  8636. if (this.hasFollowingLineBreak()) return null;
  8637. this.expectContextual(129);
  8638. if (properties.declare) node.declare = true;
  8639. if (tokenIsIdentifier(this.state.type)) {
  8640. node.id = this.parseIdentifier();
  8641. this.checkIdentifier(node.id, 130);
  8642. } else {
  8643. node.id = null;
  8644. this.raise(TSErrors.MissingInterfaceName, {
  8645. at: this.state.startLoc
  8646. });
  8647. }
  8648. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  8649. if (this.eat(81)) {
  8650. node.extends = this.tsParseHeritageClause("extends");
  8651. }
  8652. const body = this.startNode();
  8653. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  8654. node.body = this.finishNode(body, "TSInterfaceBody");
  8655. return this.finishNode(node, "TSInterfaceDeclaration");
  8656. }
  8657. tsParseTypeAliasDeclaration(node) {
  8658. node.id = this.parseIdentifier();
  8659. this.checkIdentifier(node.id, 2);
  8660. node.typeAnnotation = this.tsInType(() => {
  8661. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  8662. this.expect(29);
  8663. if (this.isContextual(114) && this.lookahead().type !== 16) {
  8664. const node = this.startNode();
  8665. this.next();
  8666. return this.finishNode(node, "TSIntrinsicKeyword");
  8667. }
  8668. return this.tsParseType();
  8669. });
  8670. this.semicolon();
  8671. return this.finishNode(node, "TSTypeAliasDeclaration");
  8672. }
  8673. tsInNoContext(cb) {
  8674. const oldContext = this.state.context;
  8675. this.state.context = [oldContext[0]];
  8676. try {
  8677. return cb();
  8678. } finally {
  8679. this.state.context = oldContext;
  8680. }
  8681. }
  8682. tsInType(cb) {
  8683. const oldInType = this.state.inType;
  8684. this.state.inType = true;
  8685. try {
  8686. return cb();
  8687. } finally {
  8688. this.state.inType = oldInType;
  8689. }
  8690. }
  8691. tsInDisallowConditionalTypesContext(cb) {
  8692. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8693. this.state.inDisallowConditionalTypesContext = true;
  8694. try {
  8695. return cb();
  8696. } finally {
  8697. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8698. }
  8699. }
  8700. tsInAllowConditionalTypesContext(cb) {
  8701. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  8702. this.state.inDisallowConditionalTypesContext = false;
  8703. try {
  8704. return cb();
  8705. } finally {
  8706. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  8707. }
  8708. }
  8709. tsEatThenParseType(token) {
  8710. if (this.match(token)) {
  8711. return this.tsNextThenParseType();
  8712. }
  8713. }
  8714. tsExpectThenParseType(token) {
  8715. return this.tsInType(() => {
  8716. this.expect(token);
  8717. return this.tsParseType();
  8718. });
  8719. }
  8720. tsNextThenParseType() {
  8721. return this.tsInType(() => {
  8722. this.next();
  8723. return this.tsParseType();
  8724. });
  8725. }
  8726. tsParseEnumMember() {
  8727. const node = this.startNode();
  8728. node.id = this.match(133) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  8729. if (this.eat(29)) {
  8730. node.initializer = super.parseMaybeAssignAllowIn();
  8731. }
  8732. return this.finishNode(node, "TSEnumMember");
  8733. }
  8734. tsParseEnumDeclaration(node, properties = {}) {
  8735. if (properties.const) node.const = true;
  8736. if (properties.declare) node.declare = true;
  8737. this.expectContextual(126);
  8738. node.id = this.parseIdentifier();
  8739. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  8740. this.expect(5);
  8741. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  8742. this.expect(8);
  8743. return this.finishNode(node, "TSEnumDeclaration");
  8744. }
  8745. tsParseModuleBlock() {
  8746. const node = this.startNode();
  8747. this.scope.enter(0);
  8748. this.expect(5);
  8749. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  8750. this.scope.exit();
  8751. return this.finishNode(node, "TSModuleBlock");
  8752. }
  8753. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  8754. node.id = this.parseIdentifier();
  8755. if (!nested) {
  8756. this.checkIdentifier(node.id, 1024);
  8757. }
  8758. if (this.eat(16)) {
  8759. const inner = this.startNode();
  8760. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  8761. node.body = inner;
  8762. } else {
  8763. this.scope.enter(256);
  8764. this.prodParam.enter(PARAM);
  8765. node.body = this.tsParseModuleBlock();
  8766. this.prodParam.exit();
  8767. this.scope.exit();
  8768. }
  8769. return this.finishNode(node, "TSModuleDeclaration");
  8770. }
  8771. tsParseAmbientExternalModuleDeclaration(node) {
  8772. if (this.isContextual(112)) {
  8773. node.global = true;
  8774. node.id = this.parseIdentifier();
  8775. } else if (this.match(133)) {
  8776. node.id = super.parseStringLiteral(this.state.value);
  8777. } else {
  8778. this.unexpected();
  8779. }
  8780. if (this.match(5)) {
  8781. this.scope.enter(256);
  8782. this.prodParam.enter(PARAM);
  8783. node.body = this.tsParseModuleBlock();
  8784. this.prodParam.exit();
  8785. this.scope.exit();
  8786. } else {
  8787. this.semicolon();
  8788. }
  8789. return this.finishNode(node, "TSModuleDeclaration");
  8790. }
  8791. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  8792. node.isExport = isExport || false;
  8793. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  8794. this.checkIdentifier(node.id, 4096);
  8795. this.expect(29);
  8796. const moduleReference = this.tsParseModuleReference();
  8797. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  8798. this.raise(TSErrors.ImportAliasHasImportType, {
  8799. at: moduleReference
  8800. });
  8801. }
  8802. node.moduleReference = moduleReference;
  8803. this.semicolon();
  8804. return this.finishNode(node, "TSImportEqualsDeclaration");
  8805. }
  8806. tsIsExternalModuleReference() {
  8807. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  8808. }
  8809. tsParseModuleReference() {
  8810. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(false);
  8811. }
  8812. tsParseExternalModuleReference() {
  8813. const node = this.startNode();
  8814. this.expectContextual(119);
  8815. this.expect(10);
  8816. if (!this.match(133)) {
  8817. this.unexpected();
  8818. }
  8819. node.expression = super.parseExprAtom();
  8820. this.expect(11);
  8821. this.sawUnambiguousESM = true;
  8822. return this.finishNode(node, "TSExternalModuleReference");
  8823. }
  8824. tsLookAhead(f) {
  8825. const state = this.state.clone();
  8826. const res = f();
  8827. this.state = state;
  8828. return res;
  8829. }
  8830. tsTryParseAndCatch(f) {
  8831. const result = this.tryParse(abort => f() || abort());
  8832. if (result.aborted || !result.node) return;
  8833. if (result.error) this.state = result.failState;
  8834. return result.node;
  8835. }
  8836. tsTryParse(f) {
  8837. const state = this.state.clone();
  8838. const result = f();
  8839. if (result !== undefined && result !== false) {
  8840. return result;
  8841. }
  8842. this.state = state;
  8843. }
  8844. tsTryParseDeclare(nany) {
  8845. if (this.isLineTerminator()) {
  8846. return;
  8847. }
  8848. let startType = this.state.type;
  8849. let kind;
  8850. if (this.isContextual(100)) {
  8851. startType = 74;
  8852. kind = "let";
  8853. }
  8854. return this.tsInAmbientContext(() => {
  8855. switch (startType) {
  8856. case 68:
  8857. nany.declare = true;
  8858. return super.parseFunctionStatement(nany, false, false);
  8859. case 80:
  8860. nany.declare = true;
  8861. return this.parseClass(nany, true, false);
  8862. case 126:
  8863. return this.tsParseEnumDeclaration(nany, {
  8864. declare: true
  8865. });
  8866. case 112:
  8867. return this.tsParseAmbientExternalModuleDeclaration(nany);
  8868. case 75:
  8869. case 74:
  8870. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  8871. nany.declare = true;
  8872. return this.parseVarStatement(nany, kind || this.state.value, true);
  8873. }
  8874. this.expect(75);
  8875. return this.tsParseEnumDeclaration(nany, {
  8876. const: true,
  8877. declare: true
  8878. });
  8879. case 129:
  8880. {
  8881. const result = this.tsParseInterfaceDeclaration(nany, {
  8882. declare: true
  8883. });
  8884. if (result) return result;
  8885. }
  8886. default:
  8887. if (tokenIsIdentifier(startType)) {
  8888. return this.tsParseDeclaration(nany, this.state.value, true, null);
  8889. }
  8890. }
  8891. });
  8892. }
  8893. tsTryParseExportDeclaration() {
  8894. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  8895. }
  8896. tsParseExpressionStatement(node, expr, decorators) {
  8897. switch (expr.name) {
  8898. case "declare":
  8899. {
  8900. const declaration = this.tsTryParseDeclare(node);
  8901. if (declaration) {
  8902. declaration.declare = true;
  8903. }
  8904. return declaration;
  8905. }
  8906. case "global":
  8907. if (this.match(5)) {
  8908. this.scope.enter(256);
  8909. this.prodParam.enter(PARAM);
  8910. const mod = node;
  8911. mod.global = true;
  8912. mod.id = expr;
  8913. mod.body = this.tsParseModuleBlock();
  8914. this.scope.exit();
  8915. this.prodParam.exit();
  8916. return this.finishNode(mod, "TSModuleDeclaration");
  8917. }
  8918. break;
  8919. default:
  8920. return this.tsParseDeclaration(node, expr.name, false, decorators);
  8921. }
  8922. }
  8923. tsParseDeclaration(node, value, next, decorators) {
  8924. switch (value) {
  8925. case "abstract":
  8926. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  8927. return this.tsParseAbstractDeclaration(node, decorators);
  8928. }
  8929. break;
  8930. case "module":
  8931. if (this.tsCheckLineTerminator(next)) {
  8932. if (this.match(133)) {
  8933. return this.tsParseAmbientExternalModuleDeclaration(node);
  8934. } else if (tokenIsIdentifier(this.state.type)) {
  8935. return this.tsParseModuleOrNamespaceDeclaration(node);
  8936. }
  8937. }
  8938. break;
  8939. case "namespace":
  8940. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8941. return this.tsParseModuleOrNamespaceDeclaration(node);
  8942. }
  8943. break;
  8944. case "type":
  8945. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  8946. return this.tsParseTypeAliasDeclaration(node);
  8947. }
  8948. break;
  8949. }
  8950. }
  8951. tsCheckLineTerminator(next) {
  8952. if (next) {
  8953. if (this.hasFollowingLineBreak()) return false;
  8954. this.next();
  8955. return true;
  8956. }
  8957. return !this.isLineTerminator();
  8958. }
  8959. tsTryParseGenericAsyncArrowFunction(startLoc) {
  8960. if (!this.match(47)) return;
  8961. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  8962. this.state.maybeInArrowParameters = true;
  8963. const res = this.tsTryParseAndCatch(() => {
  8964. const node = this.startNodeAt(startLoc);
  8965. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  8966. super.parseFunctionParams(node);
  8967. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  8968. this.expect(19);
  8969. return node;
  8970. });
  8971. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  8972. if (!res) return;
  8973. return super.parseArrowExpression(res, null, true);
  8974. }
  8975. tsParseTypeArgumentsInExpression() {
  8976. if (this.reScan_lt() !== 47) return;
  8977. return this.tsParseTypeArguments();
  8978. }
  8979. tsParseTypeArguments() {
  8980. const node = this.startNode();
  8981. node.params = this.tsInType(() => this.tsInNoContext(() => {
  8982. this.expect(47);
  8983. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  8984. }));
  8985. if (node.params.length === 0) {
  8986. this.raise(TSErrors.EmptyTypeArguments, {
  8987. at: node
  8988. });
  8989. } else if (!this.state.inType && this.curContext() === types.brace) {
  8990. this.reScan_lt_gt();
  8991. }
  8992. this.expect(48);
  8993. return this.finishNode(node, "TSTypeParameterInstantiation");
  8994. }
  8995. tsIsDeclarationStart() {
  8996. return tokenIsTSDeclarationStart(this.state.type);
  8997. }
  8998. isExportDefaultSpecifier() {
  8999. if (this.tsIsDeclarationStart()) return false;
  9000. return super.isExportDefaultSpecifier();
  9001. }
  9002. parseAssignableListItem(flags, decorators) {
  9003. const startLoc = this.state.startLoc;
  9004. const modified = {};
  9005. this.tsParseModifiers({
  9006. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  9007. }, modified);
  9008. const accessibility = modified.accessibility;
  9009. const override = modified.override;
  9010. const readonly = modified.readonly;
  9011. if (!(flags & 4) && (accessibility || readonly || override)) {
  9012. this.raise(TSErrors.UnexpectedParameterModifier, {
  9013. at: startLoc
  9014. });
  9015. }
  9016. const left = this.parseMaybeDefault();
  9017. this.parseAssignableListItemTypes(left, flags);
  9018. const elt = this.parseMaybeDefault(left.loc.start, left);
  9019. if (accessibility || readonly || override) {
  9020. const pp = this.startNodeAt(startLoc);
  9021. if (decorators.length) {
  9022. pp.decorators = decorators;
  9023. }
  9024. if (accessibility) pp.accessibility = accessibility;
  9025. if (readonly) pp.readonly = readonly;
  9026. if (override) pp.override = override;
  9027. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  9028. this.raise(TSErrors.UnsupportedParameterPropertyKind, {
  9029. at: pp
  9030. });
  9031. }
  9032. pp.parameter = elt;
  9033. return this.finishNode(pp, "TSParameterProperty");
  9034. }
  9035. if (decorators.length) {
  9036. left.decorators = decorators;
  9037. }
  9038. return elt;
  9039. }
  9040. isSimpleParameter(node) {
  9041. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  9042. }
  9043. tsDisallowOptionalPattern(node) {
  9044. for (const param of node.params) {
  9045. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  9046. this.raise(TSErrors.PatternIsOptional, {
  9047. at: param
  9048. });
  9049. }
  9050. }
  9051. }
  9052. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  9053. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  9054. this.tsDisallowOptionalPattern(node);
  9055. }
  9056. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  9057. if (this.match(14)) {
  9058. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9059. }
  9060. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  9061. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  9062. return this.finishNode(node, bodilessType);
  9063. }
  9064. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  9065. this.raise(TSErrors.DeclareFunctionHasImplementation, {
  9066. at: node
  9067. });
  9068. if (node.declare) {
  9069. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  9070. }
  9071. }
  9072. this.tsDisallowOptionalPattern(node);
  9073. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  9074. }
  9075. registerFunctionStatementId(node) {
  9076. if (!node.body && node.id) {
  9077. this.checkIdentifier(node.id, 1024);
  9078. } else {
  9079. super.registerFunctionStatementId(node);
  9080. }
  9081. }
  9082. tsCheckForInvalidTypeCasts(items) {
  9083. items.forEach(node => {
  9084. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  9085. this.raise(TSErrors.UnexpectedTypeAnnotation, {
  9086. at: node.typeAnnotation
  9087. });
  9088. }
  9089. });
  9090. }
  9091. toReferencedList(exprList, isInParens) {
  9092. this.tsCheckForInvalidTypeCasts(exprList);
  9093. return exprList;
  9094. }
  9095. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  9096. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  9097. if (node.type === "ArrayExpression") {
  9098. this.tsCheckForInvalidTypeCasts(node.elements);
  9099. }
  9100. return node;
  9101. }
  9102. parseSubscript(base, startLoc, noCalls, state) {
  9103. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  9104. this.state.canStartJSXElement = false;
  9105. this.next();
  9106. const nonNullExpression = this.startNodeAt(startLoc);
  9107. nonNullExpression.expression = base;
  9108. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  9109. }
  9110. let isOptionalCall = false;
  9111. if (this.match(18) && this.lookaheadCharCode() === 60) {
  9112. if (noCalls) {
  9113. state.stop = true;
  9114. return base;
  9115. }
  9116. state.optionalChainMember = isOptionalCall = true;
  9117. this.next();
  9118. }
  9119. if (this.match(47) || this.match(51)) {
  9120. let missingParenErrorLoc;
  9121. const result = this.tsTryParseAndCatch(() => {
  9122. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  9123. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  9124. if (asyncArrowFn) {
  9125. return asyncArrowFn;
  9126. }
  9127. }
  9128. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9129. if (!typeArguments) return;
  9130. if (isOptionalCall && !this.match(10)) {
  9131. missingParenErrorLoc = this.state.curPosition();
  9132. return;
  9133. }
  9134. if (tokenIsTemplate(this.state.type)) {
  9135. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  9136. result.typeParameters = typeArguments;
  9137. return result;
  9138. }
  9139. if (!noCalls && this.eat(10)) {
  9140. const node = this.startNodeAt(startLoc);
  9141. node.callee = base;
  9142. node.arguments = this.parseCallExpressionArguments(11, false);
  9143. this.tsCheckForInvalidTypeCasts(node.arguments);
  9144. node.typeParameters = typeArguments;
  9145. if (state.optionalChainMember) {
  9146. node.optional = isOptionalCall;
  9147. }
  9148. return this.finishCallExpression(node, state.optionalChainMember);
  9149. }
  9150. const tokenType = this.state.type;
  9151. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  9152. return;
  9153. }
  9154. const node = this.startNodeAt(startLoc);
  9155. node.expression = base;
  9156. node.typeParameters = typeArguments;
  9157. return this.finishNode(node, "TSInstantiationExpression");
  9158. });
  9159. if (missingParenErrorLoc) {
  9160. this.unexpected(missingParenErrorLoc, 10);
  9161. }
  9162. if (result) {
  9163. if (result.type === "TSInstantiationExpression" && (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40)) {
  9164. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, {
  9165. at: this.state.startLoc
  9166. });
  9167. }
  9168. return result;
  9169. }
  9170. }
  9171. return super.parseSubscript(base, startLoc, noCalls, state);
  9172. }
  9173. parseNewCallee(node) {
  9174. var _callee$extra;
  9175. super.parseNewCallee(node);
  9176. const {
  9177. callee
  9178. } = node;
  9179. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  9180. node.typeParameters = callee.typeParameters;
  9181. node.callee = callee.expression;
  9182. }
  9183. }
  9184. parseExprOp(left, leftStartLoc, minPrec) {
  9185. let isSatisfies;
  9186. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  9187. const node = this.startNodeAt(leftStartLoc);
  9188. node.expression = left;
  9189. node.typeAnnotation = this.tsInType(() => {
  9190. this.next();
  9191. if (this.match(75)) {
  9192. if (isSatisfies) {
  9193. this.raise(Errors.UnexpectedKeyword, {
  9194. at: this.state.startLoc,
  9195. keyword: "const"
  9196. });
  9197. }
  9198. return this.tsParseTypeReference();
  9199. }
  9200. return this.tsParseType();
  9201. });
  9202. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  9203. this.reScan_lt_gt();
  9204. return this.parseExprOp(node, leftStartLoc, minPrec);
  9205. }
  9206. return super.parseExprOp(left, leftStartLoc, minPrec);
  9207. }
  9208. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  9209. if (!this.state.isAmbientContext) {
  9210. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  9211. }
  9212. }
  9213. checkImportReflection(node) {
  9214. super.checkImportReflection(node);
  9215. if (node.module && node.importKind !== "value") {
  9216. this.raise(TSErrors.ImportReflectionHasImportType, {
  9217. at: node.specifiers[0].loc.start
  9218. });
  9219. }
  9220. }
  9221. checkDuplicateExports() {}
  9222. isPotentialImportPhase(isExport) {
  9223. if (super.isPotentialImportPhase(isExport)) return true;
  9224. if (this.isContextual(130)) {
  9225. const ch = this.lookaheadCharCode();
  9226. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  9227. }
  9228. return !isExport && this.isContextual(87);
  9229. }
  9230. applyImportPhase(node, isExport, phase, loc) {
  9231. super.applyImportPhase(node, isExport, phase, loc);
  9232. if (isExport) {
  9233. node.exportKind = phase === "type" ? "type" : "value";
  9234. } else {
  9235. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  9236. }
  9237. }
  9238. parseImport(node) {
  9239. if (this.match(133)) {
  9240. node.importKind = "value";
  9241. return super.parseImport(node);
  9242. }
  9243. let importNode;
  9244. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  9245. node.importKind = "value";
  9246. return this.tsParseImportEqualsDeclaration(node);
  9247. } else if (this.isContextual(130)) {
  9248. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9249. if (this.lookaheadCharCode() === 61) {
  9250. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  9251. } else {
  9252. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  9253. }
  9254. } else {
  9255. importNode = super.parseImport(node);
  9256. }
  9257. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  9258. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, {
  9259. at: importNode
  9260. });
  9261. }
  9262. return importNode;
  9263. }
  9264. parseExport(node, decorators) {
  9265. if (this.match(83)) {
  9266. this.next();
  9267. let maybeDefaultIdentifier = null;
  9268. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  9269. maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  9270. } else {
  9271. node.importKind = "value";
  9272. }
  9273. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, true);
  9274. } else if (this.eat(29)) {
  9275. const assign = node;
  9276. assign.expression = super.parseExpression();
  9277. this.semicolon();
  9278. this.sawUnambiguousESM = true;
  9279. return this.finishNode(assign, "TSExportAssignment");
  9280. } else if (this.eatContextual(93)) {
  9281. const decl = node;
  9282. this.expectContextual(128);
  9283. decl.id = this.parseIdentifier();
  9284. this.semicolon();
  9285. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  9286. } else {
  9287. return super.parseExport(node, decorators);
  9288. }
  9289. }
  9290. isAbstractClass() {
  9291. return this.isContextual(124) && this.lookahead().type === 80;
  9292. }
  9293. parseExportDefaultExpression() {
  9294. if (this.isAbstractClass()) {
  9295. const cls = this.startNode();
  9296. this.next();
  9297. cls.abstract = true;
  9298. return this.parseClass(cls, true, true);
  9299. }
  9300. if (this.match(129)) {
  9301. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9302. if (result) return result;
  9303. }
  9304. return super.parseExportDefaultExpression();
  9305. }
  9306. parseVarStatement(node, kind, allowMissingInitializer = false) {
  9307. const {
  9308. isAmbientContext
  9309. } = this.state;
  9310. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  9311. if (!isAmbientContext) return declaration;
  9312. for (const {
  9313. id,
  9314. init
  9315. } of declaration.declarations) {
  9316. if (!init) continue;
  9317. if (kind !== "const" || !!id.typeAnnotation) {
  9318. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, {
  9319. at: init
  9320. });
  9321. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  9322. this.raise(TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, {
  9323. at: init
  9324. });
  9325. }
  9326. }
  9327. return declaration;
  9328. }
  9329. parseStatementContent(flags, decorators) {
  9330. if (this.match(75) && this.isLookaheadContextual("enum")) {
  9331. const node = this.startNode();
  9332. this.expect(75);
  9333. return this.tsParseEnumDeclaration(node, {
  9334. const: true
  9335. });
  9336. }
  9337. if (this.isContextual(126)) {
  9338. return this.tsParseEnumDeclaration(this.startNode());
  9339. }
  9340. if (this.isContextual(129)) {
  9341. const result = this.tsParseInterfaceDeclaration(this.startNode());
  9342. if (result) return result;
  9343. }
  9344. return super.parseStatementContent(flags, decorators);
  9345. }
  9346. parseAccessModifier() {
  9347. return this.tsParseModifier(["public", "protected", "private"]);
  9348. }
  9349. tsHasSomeModifiers(member, modifiers) {
  9350. return modifiers.some(modifier => {
  9351. if (tsIsAccessModifier(modifier)) {
  9352. return member.accessibility === modifier;
  9353. }
  9354. return !!member[modifier];
  9355. });
  9356. }
  9357. tsIsStartOfStaticBlocks() {
  9358. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  9359. }
  9360. parseClassMember(classBody, member, state) {
  9361. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  9362. this.tsParseModifiers({
  9363. allowedModifiers: modifiers,
  9364. disallowedModifiers: ["in", "out"],
  9365. stopOnStartOfClassStaticBlock: true,
  9366. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  9367. }, member);
  9368. const callParseClassMemberWithIsStatic = () => {
  9369. if (this.tsIsStartOfStaticBlocks()) {
  9370. this.next();
  9371. this.next();
  9372. if (this.tsHasSomeModifiers(member, modifiers)) {
  9373. this.raise(TSErrors.StaticBlockCannotHaveModifier, {
  9374. at: this.state.curPosition()
  9375. });
  9376. }
  9377. super.parseClassStaticBlock(classBody, member);
  9378. } else {
  9379. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  9380. }
  9381. };
  9382. if (member.declare) {
  9383. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  9384. } else {
  9385. callParseClassMemberWithIsStatic();
  9386. }
  9387. }
  9388. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  9389. const idx = this.tsTryParseIndexSignature(member);
  9390. if (idx) {
  9391. classBody.body.push(idx);
  9392. if (member.abstract) {
  9393. this.raise(TSErrors.IndexSignatureHasAbstract, {
  9394. at: member
  9395. });
  9396. }
  9397. if (member.accessibility) {
  9398. this.raise(TSErrors.IndexSignatureHasAccessibility, {
  9399. at: member,
  9400. modifier: member.accessibility
  9401. });
  9402. }
  9403. if (member.declare) {
  9404. this.raise(TSErrors.IndexSignatureHasDeclare, {
  9405. at: member
  9406. });
  9407. }
  9408. if (member.override) {
  9409. this.raise(TSErrors.IndexSignatureHasOverride, {
  9410. at: member
  9411. });
  9412. }
  9413. return;
  9414. }
  9415. if (!this.state.inAbstractClass && member.abstract) {
  9416. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, {
  9417. at: member
  9418. });
  9419. }
  9420. if (member.override) {
  9421. if (!state.hadSuperClass) {
  9422. this.raise(TSErrors.OverrideNotInSubClass, {
  9423. at: member
  9424. });
  9425. }
  9426. }
  9427. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  9428. }
  9429. parsePostMemberNameModifiers(methodOrProp) {
  9430. const optional = this.eat(17);
  9431. if (optional) methodOrProp.optional = true;
  9432. if (methodOrProp.readonly && this.match(10)) {
  9433. this.raise(TSErrors.ClassMethodHasReadonly, {
  9434. at: methodOrProp
  9435. });
  9436. }
  9437. if (methodOrProp.declare && this.match(10)) {
  9438. this.raise(TSErrors.ClassMethodHasDeclare, {
  9439. at: methodOrProp
  9440. });
  9441. }
  9442. }
  9443. parseExpressionStatement(node, expr, decorators) {
  9444. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  9445. return decl || super.parseExpressionStatement(node, expr, decorators);
  9446. }
  9447. shouldParseExportDeclaration() {
  9448. if (this.tsIsDeclarationStart()) return true;
  9449. return super.shouldParseExportDeclaration();
  9450. }
  9451. parseConditional(expr, startLoc, refExpressionErrors) {
  9452. if (!this.state.maybeInArrowParameters || !this.match(17)) {
  9453. return super.parseConditional(expr, startLoc, refExpressionErrors);
  9454. }
  9455. const result = this.tryParse(() => super.parseConditional(expr, startLoc));
  9456. if (!result.node) {
  9457. if (result.error) {
  9458. super.setOptionalParametersError(refExpressionErrors, result.error);
  9459. }
  9460. return expr;
  9461. }
  9462. if (result.error) this.state = result.failState;
  9463. return result.node;
  9464. }
  9465. parseParenItem(node, startLoc) {
  9466. node = super.parseParenItem(node, startLoc);
  9467. if (this.eat(17)) {
  9468. node.optional = true;
  9469. this.resetEndLocation(node);
  9470. }
  9471. if (this.match(14)) {
  9472. const typeCastNode = this.startNodeAt(startLoc);
  9473. typeCastNode.expression = node;
  9474. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  9475. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  9476. }
  9477. return node;
  9478. }
  9479. parseExportDeclaration(node) {
  9480. if (!this.state.isAmbientContext && this.isContextual(125)) {
  9481. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  9482. }
  9483. const startLoc = this.state.startLoc;
  9484. const isDeclare = this.eatContextual(125);
  9485. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  9486. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, {
  9487. at: this.state.startLoc
  9488. });
  9489. }
  9490. const isIdentifier = tokenIsIdentifier(this.state.type);
  9491. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  9492. if (!declaration) return null;
  9493. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  9494. node.exportKind = "type";
  9495. }
  9496. if (isDeclare) {
  9497. this.resetStartLocation(declaration, startLoc);
  9498. declaration.declare = true;
  9499. }
  9500. return declaration;
  9501. }
  9502. parseClassId(node, isStatement, optionalId, bindingType) {
  9503. if ((!isStatement || optionalId) && this.isContextual(113)) {
  9504. return;
  9505. }
  9506. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  9507. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  9508. if (typeParameters) node.typeParameters = typeParameters;
  9509. }
  9510. parseClassPropertyAnnotation(node) {
  9511. if (!node.optional) {
  9512. if (this.eat(35)) {
  9513. node.definite = true;
  9514. } else if (this.eat(17)) {
  9515. node.optional = true;
  9516. }
  9517. }
  9518. const type = this.tsTryParseTypeAnnotation();
  9519. if (type) node.typeAnnotation = type;
  9520. }
  9521. parseClassProperty(node) {
  9522. this.parseClassPropertyAnnotation(node);
  9523. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  9524. this.raise(TSErrors.DeclareClassFieldHasInitializer, {
  9525. at: this.state.startLoc
  9526. });
  9527. }
  9528. if (node.abstract && this.match(29)) {
  9529. const {
  9530. key
  9531. } = node;
  9532. this.raise(TSErrors.AbstractPropertyHasInitializer, {
  9533. at: this.state.startLoc,
  9534. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9535. });
  9536. }
  9537. return super.parseClassProperty(node);
  9538. }
  9539. parseClassPrivateProperty(node) {
  9540. if (node.abstract) {
  9541. this.raise(TSErrors.PrivateElementHasAbstract, {
  9542. at: node
  9543. });
  9544. }
  9545. if (node.accessibility) {
  9546. this.raise(TSErrors.PrivateElementHasAccessibility, {
  9547. at: node,
  9548. modifier: node.accessibility
  9549. });
  9550. }
  9551. this.parseClassPropertyAnnotation(node);
  9552. return super.parseClassPrivateProperty(node);
  9553. }
  9554. parseClassAccessorProperty(node) {
  9555. this.parseClassPropertyAnnotation(node);
  9556. if (node.optional) {
  9557. this.raise(TSErrors.AccessorCannotBeOptional, {
  9558. at: node
  9559. });
  9560. }
  9561. return super.parseClassAccessorProperty(node);
  9562. }
  9563. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  9564. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9565. if (typeParameters && isConstructor) {
  9566. this.raise(TSErrors.ConstructorHasTypeParameters, {
  9567. at: typeParameters
  9568. });
  9569. }
  9570. const {
  9571. declare = false,
  9572. kind
  9573. } = method;
  9574. if (declare && (kind === "get" || kind === "set")) {
  9575. this.raise(TSErrors.DeclareAccessor, {
  9576. at: method,
  9577. kind
  9578. });
  9579. }
  9580. if (typeParameters) method.typeParameters = typeParameters;
  9581. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  9582. }
  9583. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  9584. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9585. if (typeParameters) method.typeParameters = typeParameters;
  9586. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  9587. }
  9588. declareClassPrivateMethodInScope(node, kind) {
  9589. if (node.type === "TSDeclareMethod") return;
  9590. if (node.type === "MethodDefinition" && !node.value.body) return;
  9591. super.declareClassPrivateMethodInScope(node, kind);
  9592. }
  9593. parseClassSuper(node) {
  9594. super.parseClassSuper(node);
  9595. if (node.superClass && (this.match(47) || this.match(51))) {
  9596. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  9597. }
  9598. if (this.eatContextual(113)) {
  9599. node.implements = this.tsParseHeritageClause("implements");
  9600. }
  9601. }
  9602. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  9603. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9604. if (typeParameters) prop.typeParameters = typeParameters;
  9605. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  9606. }
  9607. parseFunctionParams(node, isConstructor) {
  9608. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  9609. if (typeParameters) node.typeParameters = typeParameters;
  9610. super.parseFunctionParams(node, isConstructor);
  9611. }
  9612. parseVarId(decl, kind) {
  9613. super.parseVarId(decl, kind);
  9614. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  9615. decl.definite = true;
  9616. }
  9617. const type = this.tsTryParseTypeAnnotation();
  9618. if (type) {
  9619. decl.id.typeAnnotation = type;
  9620. this.resetEndLocation(decl.id);
  9621. }
  9622. }
  9623. parseAsyncArrowFromCallExpression(node, call) {
  9624. if (this.match(14)) {
  9625. node.returnType = this.tsParseTypeAnnotation();
  9626. }
  9627. return super.parseAsyncArrowFromCallExpression(node, call);
  9628. }
  9629. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  9630. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  9631. let state;
  9632. let jsx;
  9633. let typeCast;
  9634. if (this.hasPlugin("jsx") && (this.match(142) || this.match(47))) {
  9635. state = this.state.clone();
  9636. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9637. if (!jsx.error) return jsx.node;
  9638. const {
  9639. context
  9640. } = this.state;
  9641. const currentContext = context[context.length - 1];
  9642. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  9643. context.pop();
  9644. }
  9645. }
  9646. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  9647. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9648. }
  9649. if (!state || state === this.state) state = this.state.clone();
  9650. let typeParameters;
  9651. const arrow = this.tryParse(abort => {
  9652. var _expr$extra, _typeParameters;
  9653. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  9654. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  9655. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  9656. abort();
  9657. }
  9658. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  9659. this.resetStartLocationFromNode(expr, typeParameters);
  9660. }
  9661. expr.typeParameters = typeParameters;
  9662. return expr;
  9663. }, state);
  9664. if (!arrow.error && !arrow.aborted) {
  9665. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9666. return arrow.node;
  9667. }
  9668. if (!jsx) {
  9669. assert(!this.hasPlugin("jsx"));
  9670. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  9671. if (!typeCast.error) return typeCast.node;
  9672. }
  9673. if ((_jsx2 = jsx) != null && _jsx2.node) {
  9674. this.state = jsx.failState;
  9675. return jsx.node;
  9676. }
  9677. if (arrow.node) {
  9678. this.state = arrow.failState;
  9679. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  9680. return arrow.node;
  9681. }
  9682. if ((_typeCast = typeCast) != null && _typeCast.node) {
  9683. this.state = typeCast.failState;
  9684. return typeCast.node;
  9685. }
  9686. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  9687. }
  9688. reportReservedArrowTypeParam(node) {
  9689. var _node$extra;
  9690. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra = node.extra) != null && _node$extra.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  9691. this.raise(TSErrors.ReservedArrowTypeParam, {
  9692. at: node
  9693. });
  9694. }
  9695. }
  9696. parseMaybeUnary(refExpressionErrors, sawUnary) {
  9697. if (!this.hasPlugin("jsx") && this.match(47)) {
  9698. return this.tsParseTypeAssertion();
  9699. }
  9700. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  9701. }
  9702. parseArrow(node) {
  9703. if (this.match(14)) {
  9704. const result = this.tryParse(abort => {
  9705. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  9706. if (this.canInsertSemicolon() || !this.match(19)) abort();
  9707. return returnType;
  9708. });
  9709. if (result.aborted) return;
  9710. if (!result.thrown) {
  9711. if (result.error) this.state = result.failState;
  9712. node.returnType = result.node;
  9713. }
  9714. }
  9715. return super.parseArrow(node);
  9716. }
  9717. parseAssignableListItemTypes(param, flags) {
  9718. if (!(flags & 2)) return param;
  9719. if (this.eat(17)) {
  9720. param.optional = true;
  9721. }
  9722. const type = this.tsTryParseTypeAnnotation();
  9723. if (type) param.typeAnnotation = type;
  9724. this.resetEndLocation(param);
  9725. return param;
  9726. }
  9727. isAssignable(node, isBinding) {
  9728. switch (node.type) {
  9729. case "TSTypeCastExpression":
  9730. return this.isAssignable(node.expression, isBinding);
  9731. case "TSParameterProperty":
  9732. return true;
  9733. default:
  9734. return super.isAssignable(node, isBinding);
  9735. }
  9736. }
  9737. toAssignable(node, isLHS = false) {
  9738. switch (node.type) {
  9739. case "ParenthesizedExpression":
  9740. this.toAssignableParenthesizedExpression(node, isLHS);
  9741. break;
  9742. case "TSAsExpression":
  9743. case "TSSatisfiesExpression":
  9744. case "TSNonNullExpression":
  9745. case "TSTypeAssertion":
  9746. if (isLHS) {
  9747. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, {
  9748. at: node
  9749. });
  9750. } else {
  9751. this.raise(TSErrors.UnexpectedTypeCastInParameter, {
  9752. at: node
  9753. });
  9754. }
  9755. this.toAssignable(node.expression, isLHS);
  9756. break;
  9757. case "AssignmentExpression":
  9758. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  9759. node.left = this.typeCastToParameter(node.left);
  9760. }
  9761. default:
  9762. super.toAssignable(node, isLHS);
  9763. }
  9764. }
  9765. toAssignableParenthesizedExpression(node, isLHS) {
  9766. switch (node.expression.type) {
  9767. case "TSAsExpression":
  9768. case "TSSatisfiesExpression":
  9769. case "TSNonNullExpression":
  9770. case "TSTypeAssertion":
  9771. case "ParenthesizedExpression":
  9772. this.toAssignable(node.expression, isLHS);
  9773. break;
  9774. default:
  9775. super.toAssignable(node, isLHS);
  9776. }
  9777. }
  9778. checkToRestConversion(node, allowPattern) {
  9779. switch (node.type) {
  9780. case "TSAsExpression":
  9781. case "TSSatisfiesExpression":
  9782. case "TSTypeAssertion":
  9783. case "TSNonNullExpression":
  9784. this.checkToRestConversion(node.expression, false);
  9785. break;
  9786. default:
  9787. super.checkToRestConversion(node, allowPattern);
  9788. }
  9789. }
  9790. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9791. return getOwn({
  9792. TSTypeCastExpression: true,
  9793. TSParameterProperty: "parameter",
  9794. TSNonNullExpression: "expression",
  9795. TSAsExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9796. TSSatisfiesExpression: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true],
  9797. TSTypeAssertion: (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true]
  9798. }, type) || super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  9799. }
  9800. parseBindingAtom() {
  9801. if (this.state.type === 78) {
  9802. return this.parseIdentifier(true);
  9803. }
  9804. return super.parseBindingAtom();
  9805. }
  9806. parseMaybeDecoratorArguments(expr) {
  9807. if (this.match(47) || this.match(51)) {
  9808. const typeArguments = this.tsParseTypeArgumentsInExpression();
  9809. if (this.match(10)) {
  9810. const call = super.parseMaybeDecoratorArguments(expr);
  9811. call.typeParameters = typeArguments;
  9812. return call;
  9813. }
  9814. this.unexpected(null, 10);
  9815. }
  9816. return super.parseMaybeDecoratorArguments(expr);
  9817. }
  9818. checkCommaAfterRest(close) {
  9819. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  9820. this.next();
  9821. return false;
  9822. }
  9823. return super.checkCommaAfterRest(close);
  9824. }
  9825. isClassMethod() {
  9826. return this.match(47) || super.isClassMethod();
  9827. }
  9828. isClassProperty() {
  9829. return this.match(35) || this.match(14) || super.isClassProperty();
  9830. }
  9831. parseMaybeDefault(startLoc, left) {
  9832. const node = super.parseMaybeDefault(startLoc, left);
  9833. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  9834. this.raise(TSErrors.TypeAnnotationAfterAssign, {
  9835. at: node.typeAnnotation
  9836. });
  9837. }
  9838. return node;
  9839. }
  9840. getTokenFromCode(code) {
  9841. if (this.state.inType) {
  9842. if (code === 62) {
  9843. this.finishOp(48, 1);
  9844. return;
  9845. }
  9846. if (code === 60) {
  9847. this.finishOp(47, 1);
  9848. return;
  9849. }
  9850. }
  9851. super.getTokenFromCode(code);
  9852. }
  9853. reScan_lt_gt() {
  9854. const {
  9855. type
  9856. } = this.state;
  9857. if (type === 47) {
  9858. this.state.pos -= 1;
  9859. this.readToken_lt();
  9860. } else if (type === 48) {
  9861. this.state.pos -= 1;
  9862. this.readToken_gt();
  9863. }
  9864. }
  9865. reScan_lt() {
  9866. const {
  9867. type
  9868. } = this.state;
  9869. if (type === 51) {
  9870. this.state.pos -= 2;
  9871. this.finishOp(47, 1);
  9872. return 47;
  9873. }
  9874. return type;
  9875. }
  9876. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9877. for (let i = 0; i < exprList.length; i++) {
  9878. const expr = exprList[i];
  9879. if ((expr == null ? void 0 : expr.type) === "TSTypeCastExpression") {
  9880. exprList[i] = this.typeCastToParameter(expr);
  9881. }
  9882. }
  9883. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  9884. }
  9885. typeCastToParameter(node) {
  9886. node.expression.typeAnnotation = node.typeAnnotation;
  9887. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  9888. return node.expression;
  9889. }
  9890. shouldParseArrow(params) {
  9891. if (this.match(14)) {
  9892. return params.every(expr => this.isAssignable(expr, true));
  9893. }
  9894. return super.shouldParseArrow(params);
  9895. }
  9896. shouldParseAsyncArrow() {
  9897. return this.match(14) || super.shouldParseAsyncArrow();
  9898. }
  9899. canHaveLeadingDecorator() {
  9900. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  9901. }
  9902. jsxParseOpeningElementAfterName(node) {
  9903. if (this.match(47) || this.match(51)) {
  9904. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  9905. if (typeArguments) node.typeParameters = typeArguments;
  9906. }
  9907. return super.jsxParseOpeningElementAfterName(node);
  9908. }
  9909. getGetterSetterExpectedParamCount(method) {
  9910. const baseCount = super.getGetterSetterExpectedParamCount(method);
  9911. const params = this.getObjectOrClassMethodParams(method);
  9912. const firstParam = params[0];
  9913. const hasContextParam = firstParam && this.isThisParam(firstParam);
  9914. return hasContextParam ? baseCount + 1 : baseCount;
  9915. }
  9916. parseCatchClauseParam() {
  9917. const param = super.parseCatchClauseParam();
  9918. const type = this.tsTryParseTypeAnnotation();
  9919. if (type) {
  9920. param.typeAnnotation = type;
  9921. this.resetEndLocation(param);
  9922. }
  9923. return param;
  9924. }
  9925. tsInAmbientContext(cb) {
  9926. const oldIsAmbientContext = this.state.isAmbientContext;
  9927. this.state.isAmbientContext = true;
  9928. try {
  9929. return cb();
  9930. } finally {
  9931. this.state.isAmbientContext = oldIsAmbientContext;
  9932. }
  9933. }
  9934. parseClass(node, isStatement, optionalId) {
  9935. const oldInAbstractClass = this.state.inAbstractClass;
  9936. this.state.inAbstractClass = !!node.abstract;
  9937. try {
  9938. return super.parseClass(node, isStatement, optionalId);
  9939. } finally {
  9940. this.state.inAbstractClass = oldInAbstractClass;
  9941. }
  9942. }
  9943. tsParseAbstractDeclaration(node, decorators) {
  9944. if (this.match(80)) {
  9945. node.abstract = true;
  9946. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  9947. } else if (this.isContextual(129)) {
  9948. if (!this.hasFollowingLineBreak()) {
  9949. node.abstract = true;
  9950. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifer, {
  9951. at: node
  9952. });
  9953. return this.tsParseInterfaceDeclaration(node);
  9954. }
  9955. } else {
  9956. this.unexpected(null, 80);
  9957. }
  9958. }
  9959. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  9960. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  9961. if (method.abstract) {
  9962. const hasBody = this.hasPlugin("estree") ? !!method.value.body : !!method.body;
  9963. if (hasBody) {
  9964. const {
  9965. key
  9966. } = method;
  9967. this.raise(TSErrors.AbstractMethodHasImplementation, {
  9968. at: method,
  9969. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(key.start, key.end)}]`
  9970. });
  9971. }
  9972. }
  9973. return method;
  9974. }
  9975. tsParseTypeParameterName() {
  9976. const typeName = this.parseIdentifier();
  9977. return typeName.name;
  9978. }
  9979. shouldParseAsAmbientContext() {
  9980. return !!this.getPluginOption("typescript", "dts");
  9981. }
  9982. parse() {
  9983. if (this.shouldParseAsAmbientContext()) {
  9984. this.state.isAmbientContext = true;
  9985. }
  9986. return super.parse();
  9987. }
  9988. getExpression() {
  9989. if (this.shouldParseAsAmbientContext()) {
  9990. this.state.isAmbientContext = true;
  9991. }
  9992. return super.getExpression();
  9993. }
  9994. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  9995. if (!isString && isMaybeTypeOnly) {
  9996. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  9997. return this.finishNode(node, "ExportSpecifier");
  9998. }
  9999. node.exportKind = "value";
  10000. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  10001. }
  10002. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  10003. if (!importedIsString && isMaybeTypeOnly) {
  10004. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  10005. return this.finishNode(specifier, "ImportSpecifier");
  10006. }
  10007. specifier.importKind = "value";
  10008. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  10009. }
  10010. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  10011. const leftOfAsKey = isImport ? "imported" : "local";
  10012. const rightOfAsKey = isImport ? "local" : "exported";
  10013. let leftOfAs = node[leftOfAsKey];
  10014. let rightOfAs;
  10015. let hasTypeSpecifier = false;
  10016. let canParseAsKeyword = true;
  10017. const loc = leftOfAs.loc.start;
  10018. if (this.isContextual(93)) {
  10019. const firstAs = this.parseIdentifier();
  10020. if (this.isContextual(93)) {
  10021. const secondAs = this.parseIdentifier();
  10022. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10023. hasTypeSpecifier = true;
  10024. leftOfAs = firstAs;
  10025. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10026. canParseAsKeyword = false;
  10027. } else {
  10028. rightOfAs = secondAs;
  10029. canParseAsKeyword = false;
  10030. }
  10031. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10032. canParseAsKeyword = false;
  10033. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10034. } else {
  10035. hasTypeSpecifier = true;
  10036. leftOfAs = firstAs;
  10037. }
  10038. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  10039. hasTypeSpecifier = true;
  10040. if (isImport) {
  10041. leftOfAs = this.parseIdentifier(true);
  10042. if (!this.isContextual(93)) {
  10043. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  10044. }
  10045. } else {
  10046. leftOfAs = this.parseModuleExportName();
  10047. }
  10048. }
  10049. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  10050. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, {
  10051. at: loc
  10052. });
  10053. }
  10054. node[leftOfAsKey] = leftOfAs;
  10055. node[rightOfAsKey] = rightOfAs;
  10056. const kindKey = isImport ? "importKind" : "exportKind";
  10057. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  10058. if (canParseAsKeyword && this.eatContextual(93)) {
  10059. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  10060. }
  10061. if (!node[rightOfAsKey]) {
  10062. node[rightOfAsKey] = cloneIdentifier(node[leftOfAsKey]);
  10063. }
  10064. if (isImport) {
  10065. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  10066. }
  10067. }
  10068. };
  10069. function isPossiblyLiteralEnum(expression) {
  10070. if (expression.type !== "MemberExpression") return false;
  10071. const {
  10072. computed,
  10073. property
  10074. } = expression;
  10075. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  10076. return false;
  10077. }
  10078. return isUncomputedMemberExpressionChain(expression.object);
  10079. }
  10080. function isValidAmbientConstInitializer(expression, estree) {
  10081. var _expression$extra;
  10082. const {
  10083. type
  10084. } = expression;
  10085. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  10086. return false;
  10087. }
  10088. if (estree) {
  10089. if (type === "Literal") {
  10090. const {
  10091. value
  10092. } = expression;
  10093. if (typeof value === "string" || typeof value === "boolean") {
  10094. return true;
  10095. }
  10096. }
  10097. } else {
  10098. if (type === "StringLiteral" || type === "BooleanLiteral") {
  10099. return true;
  10100. }
  10101. }
  10102. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  10103. return true;
  10104. }
  10105. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  10106. return true;
  10107. }
  10108. if (isPossiblyLiteralEnum(expression)) {
  10109. return true;
  10110. }
  10111. return false;
  10112. }
  10113. function isNumber(expression, estree) {
  10114. if (estree) {
  10115. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  10116. }
  10117. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  10118. }
  10119. function isNegativeNumber(expression, estree) {
  10120. if (expression.type === "UnaryExpression") {
  10121. const {
  10122. operator,
  10123. argument
  10124. } = expression;
  10125. if (operator === "-" && isNumber(argument, estree)) {
  10126. return true;
  10127. }
  10128. }
  10129. return false;
  10130. }
  10131. function isUncomputedMemberExpressionChain(expression) {
  10132. if (expression.type === "Identifier") return true;
  10133. if (expression.type !== "MemberExpression" || expression.computed) {
  10134. return false;
  10135. }
  10136. return isUncomputedMemberExpressionChain(expression.object);
  10137. }
  10138. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  10139. ClassNameIsRequired: "A class name is required.",
  10140. UnexpectedSpace: "Unexpected space in placeholder."
  10141. });
  10142. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  10143. parsePlaceholder(expectedNode) {
  10144. if (this.match(144)) {
  10145. const node = this.startNode();
  10146. this.next();
  10147. this.assertNoSpace();
  10148. node.name = super.parseIdentifier(true);
  10149. this.assertNoSpace();
  10150. this.expect(144);
  10151. return this.finishPlaceholder(node, expectedNode);
  10152. }
  10153. }
  10154. finishPlaceholder(node, expectedNode) {
  10155. const isFinished = !!(node.expectedNode && node.type === "Placeholder");
  10156. node.expectedNode = expectedNode;
  10157. return isFinished ? node : this.finishNode(node, "Placeholder");
  10158. }
  10159. getTokenFromCode(code) {
  10160. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  10161. this.finishOp(144, 2);
  10162. } else {
  10163. super.getTokenFromCode(code);
  10164. }
  10165. }
  10166. parseExprAtom(refExpressionErrors) {
  10167. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  10168. }
  10169. parseIdentifier(liberal) {
  10170. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  10171. }
  10172. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  10173. if (word !== undefined) {
  10174. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  10175. }
  10176. }
  10177. parseBindingAtom() {
  10178. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  10179. }
  10180. isValidLVal(type, isParenthesized, binding) {
  10181. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  10182. }
  10183. toAssignable(node, isLHS) {
  10184. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  10185. node.expectedNode = "Pattern";
  10186. } else {
  10187. super.toAssignable(node, isLHS);
  10188. }
  10189. }
  10190. chStartsBindingIdentifier(ch, pos) {
  10191. if (super.chStartsBindingIdentifier(ch, pos)) {
  10192. return true;
  10193. }
  10194. const nextToken = this.lookahead();
  10195. if (nextToken.type === 144) {
  10196. return true;
  10197. }
  10198. return false;
  10199. }
  10200. verifyBreakContinue(node, isBreak) {
  10201. if (node.label && node.label.type === "Placeholder") return;
  10202. super.verifyBreakContinue(node, isBreak);
  10203. }
  10204. parseExpressionStatement(node, expr) {
  10205. var _expr$extra;
  10206. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  10207. return super.parseExpressionStatement(node, expr);
  10208. }
  10209. if (this.match(14)) {
  10210. const stmt = node;
  10211. stmt.label = this.finishPlaceholder(expr, "Identifier");
  10212. this.next();
  10213. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  10214. return this.finishNode(stmt, "LabeledStatement");
  10215. }
  10216. this.semicolon();
  10217. node.name = expr.name;
  10218. return this.finishPlaceholder(node, "Statement");
  10219. }
  10220. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  10221. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  10222. }
  10223. parseFunctionId(requireId) {
  10224. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  10225. }
  10226. parseClass(node, isStatement, optionalId) {
  10227. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  10228. this.next();
  10229. const oldStrict = this.state.strict;
  10230. const placeholder = this.parsePlaceholder("Identifier");
  10231. if (placeholder) {
  10232. if (this.match(81) || this.match(144) || this.match(5)) {
  10233. node.id = placeholder;
  10234. } else if (optionalId || !isStatement) {
  10235. node.id = null;
  10236. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  10237. return this.finishNode(node, type);
  10238. } else {
  10239. throw this.raise(PlaceholderErrors.ClassNameIsRequired, {
  10240. at: this.state.startLoc
  10241. });
  10242. }
  10243. } else {
  10244. this.parseClassId(node, isStatement, optionalId);
  10245. }
  10246. super.parseClassSuper(node);
  10247. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  10248. return this.finishNode(node, type);
  10249. }
  10250. parseExport(node, decorators) {
  10251. const placeholder = this.parsePlaceholder("Identifier");
  10252. if (!placeholder) return super.parseExport(node, decorators);
  10253. if (!this.isContextual(98) && !this.match(12)) {
  10254. node.specifiers = [];
  10255. node.source = null;
  10256. node.declaration = this.finishPlaceholder(placeholder, "Declaration");
  10257. return this.finishNode(node, "ExportNamedDeclaration");
  10258. }
  10259. this.expectPlugin("exportDefaultFrom");
  10260. const specifier = this.startNode();
  10261. specifier.exported = placeholder;
  10262. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  10263. return super.parseExport(node, decorators);
  10264. }
  10265. isExportDefaultSpecifier() {
  10266. if (this.match(65)) {
  10267. const next = this.nextTokenStart();
  10268. if (this.isUnparsedContextual(next, "from")) {
  10269. if (this.input.startsWith(tokenLabelName(144), this.nextTokenStartSince(next + 4))) {
  10270. return true;
  10271. }
  10272. }
  10273. }
  10274. return super.isExportDefaultSpecifier();
  10275. }
  10276. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  10277. var _specifiers;
  10278. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  10279. return true;
  10280. }
  10281. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  10282. }
  10283. checkExport(node) {
  10284. const {
  10285. specifiers
  10286. } = node;
  10287. if (specifiers != null && specifiers.length) {
  10288. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  10289. }
  10290. super.checkExport(node);
  10291. node.specifiers = specifiers;
  10292. }
  10293. parseImport(node) {
  10294. const placeholder = this.parsePlaceholder("Identifier");
  10295. if (!placeholder) return super.parseImport(node);
  10296. node.specifiers = [];
  10297. if (!this.isContextual(98) && !this.match(12)) {
  10298. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  10299. this.semicolon();
  10300. return this.finishNode(node, "ImportDeclaration");
  10301. }
  10302. const specifier = this.startNodeAtNode(placeholder);
  10303. specifier.local = placeholder;
  10304. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  10305. if (this.eat(12)) {
  10306. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  10307. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  10308. }
  10309. this.expectContextual(98);
  10310. node.source = this.parseImportSource();
  10311. this.semicolon();
  10312. return this.finishNode(node, "ImportDeclaration");
  10313. }
  10314. parseImportSource() {
  10315. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  10316. }
  10317. assertNoSpace() {
  10318. if (this.state.start > this.state.lastTokEndLoc.index) {
  10319. this.raise(PlaceholderErrors.UnexpectedSpace, {
  10320. at: this.state.lastTokEndLoc
  10321. });
  10322. }
  10323. }
  10324. };
  10325. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  10326. parseV8Intrinsic() {
  10327. if (this.match(54)) {
  10328. const v8IntrinsicStartLoc = this.state.startLoc;
  10329. const node = this.startNode();
  10330. this.next();
  10331. if (tokenIsIdentifier(this.state.type)) {
  10332. const name = this.parseIdentifierName();
  10333. const identifier = this.createIdentifier(node, name);
  10334. identifier.type = "V8IntrinsicIdentifier";
  10335. if (this.match(10)) {
  10336. return identifier;
  10337. }
  10338. }
  10339. this.unexpected(v8IntrinsicStartLoc);
  10340. }
  10341. }
  10342. parseExprAtom(refExpressionErrors) {
  10343. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  10344. }
  10345. };
  10346. function hasPlugin(plugins, expectedConfig) {
  10347. const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
  10348. const expectedKeys = Object.keys(expectedOptions);
  10349. const expectedOptionsIsEmpty = expectedKeys.length === 0;
  10350. return plugins.some(p => {
  10351. if (typeof p === "string") {
  10352. return expectedOptionsIsEmpty && p === expectedName;
  10353. } else {
  10354. const [pluginName, pluginOptions] = p;
  10355. if (pluginName !== expectedName) {
  10356. return false;
  10357. }
  10358. for (const key of expectedKeys) {
  10359. if (pluginOptions[key] !== expectedOptions[key]) {
  10360. return false;
  10361. }
  10362. }
  10363. return true;
  10364. }
  10365. });
  10366. }
  10367. function getPluginOption(plugins, name, option) {
  10368. const plugin = plugins.find(plugin => {
  10369. if (Array.isArray(plugin)) {
  10370. return plugin[0] === name;
  10371. } else {
  10372. return plugin === name;
  10373. }
  10374. });
  10375. if (plugin && Array.isArray(plugin) && plugin.length > 1) {
  10376. return plugin[1][option];
  10377. }
  10378. return null;
  10379. }
  10380. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  10381. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  10382. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  10383. function validatePlugins(plugins) {
  10384. if (hasPlugin(plugins, "decorators")) {
  10385. if (hasPlugin(plugins, "decorators-legacy")) {
  10386. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  10387. }
  10388. const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
  10389. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  10390. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  10391. }
  10392. const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
  10393. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  10394. throw new Error("'allowCallParenthesized' must be a boolean.");
  10395. }
  10396. }
  10397. if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
  10398. throw new Error("Cannot combine flow and typescript plugins.");
  10399. }
  10400. if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
  10401. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  10402. }
  10403. if (hasPlugin(plugins, "pipelineOperator")) {
  10404. const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
  10405. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  10406. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  10407. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  10408. }
  10409. const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
  10410. syntaxType: "hash"
  10411. }]);
  10412. if (proposal === "hack") {
  10413. if (hasPlugin(plugins, "placeholders")) {
  10414. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  10415. }
  10416. if (hasPlugin(plugins, "v8intrinsic")) {
  10417. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  10418. }
  10419. const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
  10420. if (!TOPIC_TOKENS.includes(topicToken)) {
  10421. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  10422. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  10423. }
  10424. if (topicToken === "#" && tupleSyntaxIsHash) {
  10425. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10426. }
  10427. } else if (proposal === "smart" && tupleSyntaxIsHash) {
  10428. throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
  10429. }
  10430. }
  10431. if (hasPlugin(plugins, "moduleAttributes")) {
  10432. {
  10433. if (hasPlugin(plugins, "importAssertions") || hasPlugin(plugins, "importAttributes")) {
  10434. throw new Error("Cannot combine importAssertions, importAttributes and moduleAttributes plugins.");
  10435. }
  10436. const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
  10437. if (moduleAttributesVersionPluginOption !== "may-2020") {
  10438. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  10439. }
  10440. }
  10441. }
  10442. if (hasPlugin(plugins, "importAssertions") && hasPlugin(plugins, "importAttributes")) {
  10443. throw new Error("Cannot combine importAssertions and importAttributes plugins.");
  10444. }
  10445. if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
  10446. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  10447. }
  10448. if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
  10449. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  10450. error.missingPlugins = "doExpressions";
  10451. throw error;
  10452. }
  10453. if (hasPlugin(plugins, "optionalChainingAssign") && getPluginOption(plugins, "optionalChainingAssign", "version") !== "2023-07") {
  10454. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  10455. }
  10456. }
  10457. const mixinPlugins = {
  10458. estree,
  10459. jsx,
  10460. flow,
  10461. typescript,
  10462. v8intrinsic,
  10463. placeholders
  10464. };
  10465. const mixinPluginNames = Object.keys(mixinPlugins);
  10466. const defaultOptions = {
  10467. sourceType: "script",
  10468. sourceFilename: undefined,
  10469. startColumn: 0,
  10470. startLine: 1,
  10471. allowAwaitOutsideFunction: false,
  10472. allowReturnOutsideFunction: false,
  10473. allowNewTargetOutsideFunction: false,
  10474. allowImportExportEverywhere: false,
  10475. allowSuperOutsideMethod: false,
  10476. allowUndeclaredExports: false,
  10477. plugins: [],
  10478. strictMode: null,
  10479. ranges: false,
  10480. tokens: false,
  10481. createImportExpressions: false,
  10482. createParenthesizedExpressions: false,
  10483. errorRecovery: false,
  10484. attachComment: true,
  10485. annexB: true
  10486. };
  10487. function getOptions(opts) {
  10488. if (opts == null) {
  10489. return Object.assign({}, defaultOptions);
  10490. }
  10491. if (opts.annexB != null && opts.annexB !== false) {
  10492. throw new Error("The `annexB` option can only be set to `false`.");
  10493. }
  10494. const options = {};
  10495. for (const key of Object.keys(defaultOptions)) {
  10496. var _opts$key;
  10497. options[key] = (_opts$key = opts[key]) != null ? _opts$key : defaultOptions[key];
  10498. }
  10499. return options;
  10500. }
  10501. class ExpressionParser extends LValParser {
  10502. checkProto(prop, isRecord, protoRef, refExpressionErrors) {
  10503. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  10504. return;
  10505. }
  10506. const key = prop.key;
  10507. const name = key.type === "Identifier" ? key.name : key.value;
  10508. if (name === "__proto__") {
  10509. if (isRecord) {
  10510. this.raise(Errors.RecordNoProto, {
  10511. at: key
  10512. });
  10513. return;
  10514. }
  10515. if (protoRef.used) {
  10516. if (refExpressionErrors) {
  10517. if (refExpressionErrors.doubleProtoLoc === null) {
  10518. refExpressionErrors.doubleProtoLoc = key.loc.start;
  10519. }
  10520. } else {
  10521. this.raise(Errors.DuplicateProto, {
  10522. at: key
  10523. });
  10524. }
  10525. }
  10526. protoRef.used = true;
  10527. }
  10528. }
  10529. shouldExitDescending(expr, potentialArrowAt) {
  10530. return expr.type === "ArrowFunctionExpression" && expr.start === potentialArrowAt;
  10531. }
  10532. getExpression() {
  10533. this.enterInitialScopes();
  10534. this.nextToken();
  10535. const expr = this.parseExpression();
  10536. if (!this.match(139)) {
  10537. this.unexpected();
  10538. }
  10539. this.finalizeRemainingComments();
  10540. expr.comments = this.state.comments;
  10541. expr.errors = this.state.errors;
  10542. if (this.options.tokens) {
  10543. expr.tokens = this.tokens;
  10544. }
  10545. return expr;
  10546. }
  10547. parseExpression(disallowIn, refExpressionErrors) {
  10548. if (disallowIn) {
  10549. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10550. }
  10551. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  10552. }
  10553. parseExpressionBase(refExpressionErrors) {
  10554. const startLoc = this.state.startLoc;
  10555. const expr = this.parseMaybeAssign(refExpressionErrors);
  10556. if (this.match(12)) {
  10557. const node = this.startNodeAt(startLoc);
  10558. node.expressions = [expr];
  10559. while (this.eat(12)) {
  10560. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  10561. }
  10562. this.toReferencedList(node.expressions);
  10563. return this.finishNode(node, "SequenceExpression");
  10564. }
  10565. return expr;
  10566. }
  10567. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  10568. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10569. }
  10570. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  10571. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  10572. }
  10573. setOptionalParametersError(refExpressionErrors, resultError) {
  10574. var _resultError$loc;
  10575. refExpressionErrors.optionalParametersLoc = (_resultError$loc = resultError == null ? void 0 : resultError.loc) != null ? _resultError$loc : this.state.startLoc;
  10576. }
  10577. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  10578. const startLoc = this.state.startLoc;
  10579. if (this.isContextual(108)) {
  10580. if (this.prodParam.hasYield) {
  10581. let left = this.parseYield();
  10582. if (afterLeftParse) {
  10583. left = afterLeftParse.call(this, left, startLoc);
  10584. }
  10585. return left;
  10586. }
  10587. }
  10588. let ownExpressionErrors;
  10589. if (refExpressionErrors) {
  10590. ownExpressionErrors = false;
  10591. } else {
  10592. refExpressionErrors = new ExpressionErrors();
  10593. ownExpressionErrors = true;
  10594. }
  10595. const {
  10596. type
  10597. } = this.state;
  10598. if (type === 10 || tokenIsIdentifier(type)) {
  10599. this.state.potentialArrowAt = this.state.start;
  10600. }
  10601. let left = this.parseMaybeConditional(refExpressionErrors);
  10602. if (afterLeftParse) {
  10603. left = afterLeftParse.call(this, left, startLoc);
  10604. }
  10605. if (tokenIsAssignment(this.state.type)) {
  10606. const node = this.startNodeAt(startLoc);
  10607. const operator = this.state.value;
  10608. node.operator = operator;
  10609. if (this.match(29)) {
  10610. this.toAssignable(left, true);
  10611. node.left = left;
  10612. const startIndex = startLoc.index;
  10613. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  10614. refExpressionErrors.doubleProtoLoc = null;
  10615. }
  10616. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  10617. refExpressionErrors.shorthandAssignLoc = null;
  10618. }
  10619. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  10620. this.checkDestructuringPrivate(refExpressionErrors);
  10621. refExpressionErrors.privateKeyLoc = null;
  10622. }
  10623. } else {
  10624. node.left = left;
  10625. }
  10626. this.next();
  10627. node.right = this.parseMaybeAssign();
  10628. this.checkLVal(left, {
  10629. in: this.finishNode(node, "AssignmentExpression")
  10630. });
  10631. return node;
  10632. } else if (ownExpressionErrors) {
  10633. this.checkExpressionErrors(refExpressionErrors, true);
  10634. }
  10635. return left;
  10636. }
  10637. parseMaybeConditional(refExpressionErrors) {
  10638. const startLoc = this.state.startLoc;
  10639. const potentialArrowAt = this.state.potentialArrowAt;
  10640. const expr = this.parseExprOps(refExpressionErrors);
  10641. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10642. return expr;
  10643. }
  10644. return this.parseConditional(expr, startLoc, refExpressionErrors);
  10645. }
  10646. parseConditional(expr, startLoc, refExpressionErrors) {
  10647. if (this.eat(17)) {
  10648. const node = this.startNodeAt(startLoc);
  10649. node.test = expr;
  10650. node.consequent = this.parseMaybeAssignAllowIn();
  10651. this.expect(14);
  10652. node.alternate = this.parseMaybeAssign();
  10653. return this.finishNode(node, "ConditionalExpression");
  10654. }
  10655. return expr;
  10656. }
  10657. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  10658. return this.match(138) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  10659. }
  10660. parseExprOps(refExpressionErrors) {
  10661. const startLoc = this.state.startLoc;
  10662. const potentialArrowAt = this.state.potentialArrowAt;
  10663. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  10664. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10665. return expr;
  10666. }
  10667. return this.parseExprOp(expr, startLoc, -1);
  10668. }
  10669. parseExprOp(left, leftStartLoc, minPrec) {
  10670. if (this.isPrivateName(left)) {
  10671. const value = this.getPrivateNameSV(left);
  10672. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  10673. this.raise(Errors.PrivateInExpectedIn, {
  10674. at: left,
  10675. identifierName: value
  10676. });
  10677. }
  10678. this.classScope.usePrivateName(value, left.loc.start);
  10679. }
  10680. const op = this.state.type;
  10681. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  10682. let prec = tokenOperatorPrecedence(op);
  10683. if (prec > minPrec) {
  10684. if (op === 39) {
  10685. this.expectPlugin("pipelineOperator");
  10686. if (this.state.inFSharpPipelineDirectBody) {
  10687. return left;
  10688. }
  10689. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  10690. }
  10691. const node = this.startNodeAt(leftStartLoc);
  10692. node.left = left;
  10693. node.operator = this.state.value;
  10694. const logical = op === 41 || op === 42;
  10695. const coalesce = op === 40;
  10696. if (coalesce) {
  10697. prec = tokenOperatorPrecedence(42);
  10698. }
  10699. this.next();
  10700. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  10701. proposal: "minimal"
  10702. }])) {
  10703. if (this.state.type === 96 && this.prodParam.hasAwait) {
  10704. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, {
  10705. at: this.state.startLoc
  10706. });
  10707. }
  10708. }
  10709. node.right = this.parseExprOpRightExpr(op, prec);
  10710. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  10711. const nextOp = this.state.type;
  10712. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  10713. throw this.raise(Errors.MixingCoalesceWithLogical, {
  10714. at: this.state.startLoc
  10715. });
  10716. }
  10717. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  10718. }
  10719. }
  10720. return left;
  10721. }
  10722. parseExprOpRightExpr(op, prec) {
  10723. const startLoc = this.state.startLoc;
  10724. switch (op) {
  10725. case 39:
  10726. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  10727. case "hack":
  10728. return this.withTopicBindingContext(() => {
  10729. return this.parseHackPipeBody();
  10730. });
  10731. case "smart":
  10732. return this.withTopicBindingContext(() => {
  10733. if (this.prodParam.hasYield && this.isContextual(108)) {
  10734. throw this.raise(Errors.PipeBodyIsTighter, {
  10735. at: this.state.startLoc
  10736. });
  10737. }
  10738. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  10739. });
  10740. case "fsharp":
  10741. return this.withSoloAwaitPermittingContext(() => {
  10742. return this.parseFSharpPipelineBody(prec);
  10743. });
  10744. }
  10745. default:
  10746. return this.parseExprOpBaseRightExpr(op, prec);
  10747. }
  10748. }
  10749. parseExprOpBaseRightExpr(op, prec) {
  10750. const startLoc = this.state.startLoc;
  10751. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  10752. }
  10753. parseHackPipeBody() {
  10754. var _body$extra;
  10755. const {
  10756. startLoc
  10757. } = this.state;
  10758. const body = this.parseMaybeAssign();
  10759. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  10760. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  10761. this.raise(Errors.PipeUnparenthesizedBody, {
  10762. at: startLoc,
  10763. type: body.type
  10764. });
  10765. }
  10766. if (!this.topicReferenceWasUsedInCurrentContext()) {
  10767. this.raise(Errors.PipeTopicUnused, {
  10768. at: startLoc
  10769. });
  10770. }
  10771. return body;
  10772. }
  10773. checkExponentialAfterUnary(node) {
  10774. if (this.match(57)) {
  10775. this.raise(Errors.UnexpectedTokenUnaryExponentiation, {
  10776. at: node.argument
  10777. });
  10778. }
  10779. }
  10780. parseMaybeUnary(refExpressionErrors, sawUnary) {
  10781. const startLoc = this.state.startLoc;
  10782. const isAwait = this.isContextual(96);
  10783. if (isAwait && this.isAwaitAllowed()) {
  10784. this.next();
  10785. const expr = this.parseAwait(startLoc);
  10786. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  10787. return expr;
  10788. }
  10789. const update = this.match(34);
  10790. const node = this.startNode();
  10791. if (tokenIsPrefix(this.state.type)) {
  10792. node.operator = this.state.value;
  10793. node.prefix = true;
  10794. if (this.match(72)) {
  10795. this.expectPlugin("throwExpressions");
  10796. }
  10797. const isDelete = this.match(89);
  10798. this.next();
  10799. node.argument = this.parseMaybeUnary(null, true);
  10800. this.checkExpressionErrors(refExpressionErrors, true);
  10801. if (this.state.strict && isDelete) {
  10802. const arg = node.argument;
  10803. if (arg.type === "Identifier") {
  10804. this.raise(Errors.StrictDelete, {
  10805. at: node
  10806. });
  10807. } else if (this.hasPropertyAsPrivateName(arg)) {
  10808. this.raise(Errors.DeletePrivateField, {
  10809. at: node
  10810. });
  10811. }
  10812. }
  10813. if (!update) {
  10814. if (!sawUnary) {
  10815. this.checkExponentialAfterUnary(node);
  10816. }
  10817. return this.finishNode(node, "UnaryExpression");
  10818. }
  10819. }
  10820. const expr = this.parseUpdate(node, update, refExpressionErrors);
  10821. if (isAwait) {
  10822. const {
  10823. type
  10824. } = this.state;
  10825. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  10826. if (startsExpr && !this.isAmbiguousAwait()) {
  10827. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, {
  10828. at: startLoc
  10829. });
  10830. return this.parseAwait(startLoc);
  10831. }
  10832. }
  10833. return expr;
  10834. }
  10835. parseUpdate(node, update, refExpressionErrors) {
  10836. if (update) {
  10837. const updateExpressionNode = node;
  10838. this.checkLVal(updateExpressionNode.argument, {
  10839. in: this.finishNode(updateExpressionNode, "UpdateExpression")
  10840. });
  10841. return node;
  10842. }
  10843. const startLoc = this.state.startLoc;
  10844. let expr = this.parseExprSubscripts(refExpressionErrors);
  10845. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  10846. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  10847. const node = this.startNodeAt(startLoc);
  10848. node.operator = this.state.value;
  10849. node.prefix = false;
  10850. node.argument = expr;
  10851. this.next();
  10852. this.checkLVal(expr, {
  10853. in: expr = this.finishNode(node, "UpdateExpression")
  10854. });
  10855. }
  10856. return expr;
  10857. }
  10858. parseExprSubscripts(refExpressionErrors) {
  10859. const startLoc = this.state.startLoc;
  10860. const potentialArrowAt = this.state.potentialArrowAt;
  10861. const expr = this.parseExprAtom(refExpressionErrors);
  10862. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  10863. return expr;
  10864. }
  10865. return this.parseSubscripts(expr, startLoc);
  10866. }
  10867. parseSubscripts(base, startLoc, noCalls) {
  10868. const state = {
  10869. optionalChainMember: false,
  10870. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  10871. stop: false
  10872. };
  10873. do {
  10874. base = this.parseSubscript(base, startLoc, noCalls, state);
  10875. state.maybeAsyncArrow = false;
  10876. } while (!state.stop);
  10877. return base;
  10878. }
  10879. parseSubscript(base, startLoc, noCalls, state) {
  10880. const {
  10881. type
  10882. } = this.state;
  10883. if (!noCalls && type === 15) {
  10884. return this.parseBind(base, startLoc, noCalls, state);
  10885. } else if (tokenIsTemplate(type)) {
  10886. return this.parseTaggedTemplateExpression(base, startLoc, state);
  10887. }
  10888. let optional = false;
  10889. if (type === 18) {
  10890. if (noCalls) {
  10891. this.raise(Errors.OptionalChainingNoNew, {
  10892. at: this.state.startLoc
  10893. });
  10894. if (this.lookaheadCharCode() === 40) {
  10895. state.stop = true;
  10896. return base;
  10897. }
  10898. }
  10899. state.optionalChainMember = optional = true;
  10900. this.next();
  10901. }
  10902. if (!noCalls && this.match(10)) {
  10903. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  10904. } else {
  10905. const computed = this.eat(0);
  10906. if (computed || optional || this.eat(16)) {
  10907. return this.parseMember(base, startLoc, state, computed, optional);
  10908. } else {
  10909. state.stop = true;
  10910. return base;
  10911. }
  10912. }
  10913. }
  10914. parseMember(base, startLoc, state, computed, optional) {
  10915. const node = this.startNodeAt(startLoc);
  10916. node.object = base;
  10917. node.computed = computed;
  10918. if (computed) {
  10919. node.property = this.parseExpression();
  10920. this.expect(3);
  10921. } else if (this.match(138)) {
  10922. if (base.type === "Super") {
  10923. this.raise(Errors.SuperPrivateField, {
  10924. at: startLoc
  10925. });
  10926. }
  10927. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  10928. node.property = this.parsePrivateName();
  10929. } else {
  10930. node.property = this.parseIdentifier(true);
  10931. }
  10932. if (state.optionalChainMember) {
  10933. node.optional = optional;
  10934. return this.finishNode(node, "OptionalMemberExpression");
  10935. } else {
  10936. return this.finishNode(node, "MemberExpression");
  10937. }
  10938. }
  10939. parseBind(base, startLoc, noCalls, state) {
  10940. const node = this.startNodeAt(startLoc);
  10941. node.object = base;
  10942. this.next();
  10943. node.callee = this.parseNoCallExpr();
  10944. state.stop = true;
  10945. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  10946. }
  10947. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  10948. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  10949. let refExpressionErrors = null;
  10950. this.state.maybeInArrowParameters = true;
  10951. this.next();
  10952. const node = this.startNodeAt(startLoc);
  10953. node.callee = base;
  10954. const {
  10955. maybeAsyncArrow,
  10956. optionalChainMember
  10957. } = state;
  10958. if (maybeAsyncArrow) {
  10959. this.expressionScope.enter(newAsyncArrowScope());
  10960. refExpressionErrors = new ExpressionErrors();
  10961. }
  10962. if (optionalChainMember) {
  10963. node.optional = optional;
  10964. }
  10965. if (optional) {
  10966. node.arguments = this.parseCallExpressionArguments(11);
  10967. } else {
  10968. node.arguments = this.parseCallExpressionArguments(11, base.type === "Import", base.type !== "Super", node, refExpressionErrors);
  10969. }
  10970. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  10971. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  10972. state.stop = true;
  10973. this.checkDestructuringPrivate(refExpressionErrors);
  10974. this.expressionScope.validateAsPattern();
  10975. this.expressionScope.exit();
  10976. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  10977. } else {
  10978. if (maybeAsyncArrow) {
  10979. this.checkExpressionErrors(refExpressionErrors, true);
  10980. this.expressionScope.exit();
  10981. }
  10982. this.toReferencedArguments(finishedNode);
  10983. }
  10984. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  10985. return finishedNode;
  10986. }
  10987. toReferencedArguments(node, isParenthesizedExpr) {
  10988. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  10989. }
  10990. parseTaggedTemplateExpression(base, startLoc, state) {
  10991. const node = this.startNodeAt(startLoc);
  10992. node.tag = base;
  10993. node.quasi = this.parseTemplate(true);
  10994. if (state.optionalChainMember) {
  10995. this.raise(Errors.OptionalChainingNoTemplate, {
  10996. at: startLoc
  10997. });
  10998. }
  10999. return this.finishNode(node, "TaggedTemplateExpression");
  11000. }
  11001. atPossibleAsyncArrow(base) {
  11002. 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;
  11003. }
  11004. expectImportAttributesPlugin() {
  11005. if (!this.hasPlugin("importAssertions")) {
  11006. this.expectPlugin("importAttributes");
  11007. }
  11008. }
  11009. finishCallExpression(node, optional) {
  11010. if (node.callee.type === "Import") {
  11011. if (node.arguments.length === 2) {
  11012. {
  11013. if (!this.hasPlugin("moduleAttributes")) {
  11014. this.expectImportAttributesPlugin();
  11015. }
  11016. }
  11017. }
  11018. if (node.arguments.length === 0 || node.arguments.length > 2) {
  11019. this.raise(Errors.ImportCallArity, {
  11020. at: node,
  11021. maxArgumentCount: this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions") || this.hasPlugin("moduleAttributes") ? 2 : 1
  11022. });
  11023. } else {
  11024. for (const arg of node.arguments) {
  11025. if (arg.type === "SpreadElement") {
  11026. this.raise(Errors.ImportCallSpreadArgument, {
  11027. at: arg
  11028. });
  11029. }
  11030. }
  11031. }
  11032. }
  11033. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  11034. }
  11035. parseCallExpressionArguments(close, dynamicImport, allowPlaceholder, nodeForExtra, refExpressionErrors) {
  11036. const elts = [];
  11037. let first = true;
  11038. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11039. this.state.inFSharpPipelineDirectBody = false;
  11040. while (!this.eat(close)) {
  11041. if (first) {
  11042. first = false;
  11043. } else {
  11044. this.expect(12);
  11045. if (this.match(close)) {
  11046. if (dynamicImport && !this.hasPlugin("importAttributes") && !this.hasPlugin("importAssertions") && !this.hasPlugin("moduleAttributes")) {
  11047. this.raise(Errors.ImportCallArgumentTrailingComma, {
  11048. at: this.state.lastTokStartLoc
  11049. });
  11050. }
  11051. if (nodeForExtra) {
  11052. this.addTrailingCommaExtraToNode(nodeForExtra);
  11053. }
  11054. this.next();
  11055. break;
  11056. }
  11057. }
  11058. elts.push(this.parseExprListItem(false, refExpressionErrors, allowPlaceholder));
  11059. }
  11060. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11061. return elts;
  11062. }
  11063. shouldParseAsyncArrow() {
  11064. return this.match(19) && !this.canInsertSemicolon();
  11065. }
  11066. parseAsyncArrowFromCallExpression(node, call) {
  11067. var _call$extra;
  11068. this.resetPreviousNodeTrailingComments(call);
  11069. this.expect(19);
  11070. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  11071. if (call.innerComments) {
  11072. setInnerComments(node, call.innerComments);
  11073. }
  11074. if (call.callee.trailingComments) {
  11075. setInnerComments(node, call.callee.trailingComments);
  11076. }
  11077. return node;
  11078. }
  11079. parseNoCallExpr() {
  11080. const startLoc = this.state.startLoc;
  11081. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  11082. }
  11083. parseExprAtom(refExpressionErrors) {
  11084. let node;
  11085. let decorators = null;
  11086. const {
  11087. type
  11088. } = this.state;
  11089. switch (type) {
  11090. case 79:
  11091. return this.parseSuper();
  11092. case 83:
  11093. node = this.startNode();
  11094. this.next();
  11095. if (this.match(16)) {
  11096. return this.parseImportMetaProperty(node);
  11097. }
  11098. if (this.match(10)) {
  11099. if (this.options.createImportExpressions) {
  11100. return this.parseImportCall(node);
  11101. } else {
  11102. return this.finishNode(node, "Import");
  11103. }
  11104. } else {
  11105. this.raise(Errors.UnsupportedImport, {
  11106. at: this.state.lastTokStartLoc
  11107. });
  11108. return this.finishNode(node, "Import");
  11109. }
  11110. case 78:
  11111. node = this.startNode();
  11112. this.next();
  11113. return this.finishNode(node, "ThisExpression");
  11114. case 90:
  11115. {
  11116. return this.parseDo(this.startNode(), false);
  11117. }
  11118. case 56:
  11119. case 31:
  11120. {
  11121. this.readRegexp();
  11122. return this.parseRegExpLiteral(this.state.value);
  11123. }
  11124. case 134:
  11125. return this.parseNumericLiteral(this.state.value);
  11126. case 135:
  11127. return this.parseBigIntLiteral(this.state.value);
  11128. case 136:
  11129. return this.parseDecimalLiteral(this.state.value);
  11130. case 133:
  11131. return this.parseStringLiteral(this.state.value);
  11132. case 84:
  11133. return this.parseNullLiteral();
  11134. case 85:
  11135. return this.parseBooleanLiteral(true);
  11136. case 86:
  11137. return this.parseBooleanLiteral(false);
  11138. case 10:
  11139. {
  11140. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11141. return this.parseParenAndDistinguishExpression(canBeArrow);
  11142. }
  11143. case 2:
  11144. case 1:
  11145. {
  11146. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  11147. }
  11148. case 0:
  11149. {
  11150. return this.parseArrayLike(3, true, false, refExpressionErrors);
  11151. }
  11152. case 6:
  11153. case 7:
  11154. {
  11155. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  11156. }
  11157. case 5:
  11158. {
  11159. return this.parseObjectLike(8, false, false, refExpressionErrors);
  11160. }
  11161. case 68:
  11162. return this.parseFunctionOrFunctionSent();
  11163. case 26:
  11164. decorators = this.parseDecorators();
  11165. case 80:
  11166. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  11167. case 77:
  11168. return this.parseNewOrNewTarget();
  11169. case 25:
  11170. case 24:
  11171. return this.parseTemplate(false);
  11172. case 15:
  11173. {
  11174. node = this.startNode();
  11175. this.next();
  11176. node.object = null;
  11177. const callee = node.callee = this.parseNoCallExpr();
  11178. if (callee.type === "MemberExpression") {
  11179. return this.finishNode(node, "BindExpression");
  11180. } else {
  11181. throw this.raise(Errors.UnsupportedBind, {
  11182. at: callee
  11183. });
  11184. }
  11185. }
  11186. case 138:
  11187. {
  11188. this.raise(Errors.PrivateInExpectedIn, {
  11189. at: this.state.startLoc,
  11190. identifierName: this.state.value
  11191. });
  11192. return this.parsePrivateName();
  11193. }
  11194. case 33:
  11195. {
  11196. return this.parseTopicReferenceThenEqualsSign(54, "%");
  11197. }
  11198. case 32:
  11199. {
  11200. return this.parseTopicReferenceThenEqualsSign(44, "^");
  11201. }
  11202. case 37:
  11203. case 38:
  11204. {
  11205. return this.parseTopicReference("hack");
  11206. }
  11207. case 44:
  11208. case 54:
  11209. case 27:
  11210. {
  11211. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11212. if (pipeProposal) {
  11213. return this.parseTopicReference(pipeProposal);
  11214. }
  11215. this.unexpected();
  11216. break;
  11217. }
  11218. case 47:
  11219. {
  11220. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  11221. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  11222. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  11223. } else {
  11224. this.unexpected();
  11225. }
  11226. break;
  11227. }
  11228. default:
  11229. if (tokenIsIdentifier(type)) {
  11230. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  11231. return this.parseModuleExpression();
  11232. }
  11233. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  11234. const containsEsc = this.state.containsEsc;
  11235. const id = this.parseIdentifier();
  11236. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  11237. const {
  11238. type
  11239. } = this.state;
  11240. if (type === 68) {
  11241. this.resetPreviousNodeTrailingComments(id);
  11242. this.next();
  11243. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  11244. } else if (tokenIsIdentifier(type)) {
  11245. if (this.lookaheadCharCode() === 61) {
  11246. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  11247. } else {
  11248. return id;
  11249. }
  11250. } else if (type === 90) {
  11251. this.resetPreviousNodeTrailingComments(id);
  11252. return this.parseDo(this.startNodeAtNode(id), true);
  11253. }
  11254. }
  11255. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  11256. this.next();
  11257. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  11258. }
  11259. return id;
  11260. } else {
  11261. this.unexpected();
  11262. }
  11263. }
  11264. }
  11265. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  11266. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  11267. if (pipeProposal) {
  11268. this.state.type = topicTokenType;
  11269. this.state.value = topicTokenValue;
  11270. this.state.pos--;
  11271. this.state.end--;
  11272. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  11273. return this.parseTopicReference(pipeProposal);
  11274. } else {
  11275. this.unexpected();
  11276. }
  11277. }
  11278. parseTopicReference(pipeProposal) {
  11279. const node = this.startNode();
  11280. const startLoc = this.state.startLoc;
  11281. const tokenType = this.state.type;
  11282. this.next();
  11283. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  11284. }
  11285. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  11286. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  11287. const nodeType = pipeProposal === "smart" ? "PipelinePrimaryTopicReference" : "TopicReference";
  11288. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  11289. this.raise(pipeProposal === "smart" ? Errors.PrimaryTopicNotAllowed : Errors.PipeTopicUnbound, {
  11290. at: startLoc
  11291. });
  11292. }
  11293. this.registerTopicReference();
  11294. return this.finishNode(node, nodeType);
  11295. } else {
  11296. throw this.raise(Errors.PipeTopicUnconfiguredToken, {
  11297. at: startLoc,
  11298. token: tokenLabelName(tokenType)
  11299. });
  11300. }
  11301. }
  11302. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  11303. switch (pipeProposal) {
  11304. case "hack":
  11305. {
  11306. return this.hasPlugin(["pipelineOperator", {
  11307. topicToken: tokenLabelName(tokenType)
  11308. }]);
  11309. }
  11310. case "smart":
  11311. return tokenType === 27;
  11312. default:
  11313. throw this.raise(Errors.PipeTopicRequiresHackPipes, {
  11314. at: startLoc
  11315. });
  11316. }
  11317. }
  11318. parseAsyncArrowUnaryFunction(node) {
  11319. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  11320. const params = [this.parseIdentifier()];
  11321. this.prodParam.exit();
  11322. if (this.hasPrecedingLineBreak()) {
  11323. this.raise(Errors.LineTerminatorBeforeArrow, {
  11324. at: this.state.curPosition()
  11325. });
  11326. }
  11327. this.expect(19);
  11328. return this.parseArrowExpression(node, params, true);
  11329. }
  11330. parseDo(node, isAsync) {
  11331. this.expectPlugin("doExpressions");
  11332. if (isAsync) {
  11333. this.expectPlugin("asyncDoExpressions");
  11334. }
  11335. node.async = isAsync;
  11336. this.next();
  11337. const oldLabels = this.state.labels;
  11338. this.state.labels = [];
  11339. if (isAsync) {
  11340. this.prodParam.enter(PARAM_AWAIT);
  11341. node.body = this.parseBlock();
  11342. this.prodParam.exit();
  11343. } else {
  11344. node.body = this.parseBlock();
  11345. }
  11346. this.state.labels = oldLabels;
  11347. return this.finishNode(node, "DoExpression");
  11348. }
  11349. parseSuper() {
  11350. const node = this.startNode();
  11351. this.next();
  11352. if (this.match(10) && !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod) {
  11353. this.raise(Errors.SuperNotAllowed, {
  11354. at: node
  11355. });
  11356. } else if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) {
  11357. this.raise(Errors.UnexpectedSuper, {
  11358. at: node
  11359. });
  11360. }
  11361. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  11362. this.raise(Errors.UnsupportedSuper, {
  11363. at: node
  11364. });
  11365. }
  11366. return this.finishNode(node, "Super");
  11367. }
  11368. parsePrivateName() {
  11369. const node = this.startNode();
  11370. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  11371. const name = this.state.value;
  11372. this.next();
  11373. node.id = this.createIdentifier(id, name);
  11374. return this.finishNode(node, "PrivateName");
  11375. }
  11376. parseFunctionOrFunctionSent() {
  11377. const node = this.startNode();
  11378. this.next();
  11379. if (this.prodParam.hasYield && this.match(16)) {
  11380. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  11381. this.next();
  11382. if (this.match(103)) {
  11383. this.expectPlugin("functionSent");
  11384. } else if (!this.hasPlugin("functionSent")) {
  11385. this.unexpected();
  11386. }
  11387. return this.parseMetaProperty(node, meta, "sent");
  11388. }
  11389. return this.parseFunction(node);
  11390. }
  11391. parseMetaProperty(node, meta, propertyName) {
  11392. node.meta = meta;
  11393. const containsEsc = this.state.containsEsc;
  11394. node.property = this.parseIdentifier(true);
  11395. if (node.property.name !== propertyName || containsEsc) {
  11396. this.raise(Errors.UnsupportedMetaProperty, {
  11397. at: node.property,
  11398. target: meta.name,
  11399. onlyValidPropertyName: propertyName
  11400. });
  11401. }
  11402. return this.finishNode(node, "MetaProperty");
  11403. }
  11404. parseImportMetaProperty(node) {
  11405. const id = this.createIdentifier(this.startNodeAtNode(node), "import");
  11406. this.next();
  11407. if (this.isContextual(101)) {
  11408. if (!this.inModule) {
  11409. this.raise(Errors.ImportMetaOutsideModule, {
  11410. at: id
  11411. });
  11412. }
  11413. this.sawUnambiguousESM = true;
  11414. } else if (this.isContextual(105) || this.isContextual(97)) {
  11415. const isSource = this.isContextual(105);
  11416. if (!isSource) this.unexpected();
  11417. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  11418. if (!this.options.createImportExpressions) {
  11419. throw this.raise(Errors.DynamicImportPhaseRequiresImportExpressions, {
  11420. at: this.state.startLoc,
  11421. phase: this.state.value
  11422. });
  11423. }
  11424. this.next();
  11425. node.phase = isSource ? "source" : "defer";
  11426. return this.parseImportCall(node);
  11427. }
  11428. return this.parseMetaProperty(node, id, "meta");
  11429. }
  11430. parseLiteralAtNode(value, type, node) {
  11431. this.addExtra(node, "rawValue", value);
  11432. this.addExtra(node, "raw", this.input.slice(node.start, this.state.end));
  11433. node.value = value;
  11434. this.next();
  11435. return this.finishNode(node, type);
  11436. }
  11437. parseLiteral(value, type) {
  11438. const node = this.startNode();
  11439. return this.parseLiteralAtNode(value, type, node);
  11440. }
  11441. parseStringLiteral(value) {
  11442. return this.parseLiteral(value, "StringLiteral");
  11443. }
  11444. parseNumericLiteral(value) {
  11445. return this.parseLiteral(value, "NumericLiteral");
  11446. }
  11447. parseBigIntLiteral(value) {
  11448. return this.parseLiteral(value, "BigIntLiteral");
  11449. }
  11450. parseDecimalLiteral(value) {
  11451. return this.parseLiteral(value, "DecimalLiteral");
  11452. }
  11453. parseRegExpLiteral(value) {
  11454. const node = this.parseLiteral(value.value, "RegExpLiteral");
  11455. node.pattern = value.pattern;
  11456. node.flags = value.flags;
  11457. return node;
  11458. }
  11459. parseBooleanLiteral(value) {
  11460. const node = this.startNode();
  11461. node.value = value;
  11462. this.next();
  11463. return this.finishNode(node, "BooleanLiteral");
  11464. }
  11465. parseNullLiteral() {
  11466. const node = this.startNode();
  11467. this.next();
  11468. return this.finishNode(node, "NullLiteral");
  11469. }
  11470. parseParenAndDistinguishExpression(canBeArrow) {
  11471. const startLoc = this.state.startLoc;
  11472. let val;
  11473. this.next();
  11474. this.expressionScope.enter(newArrowHeadScope());
  11475. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11476. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11477. this.state.maybeInArrowParameters = true;
  11478. this.state.inFSharpPipelineDirectBody = false;
  11479. const innerStartLoc = this.state.startLoc;
  11480. const exprList = [];
  11481. const refExpressionErrors = new ExpressionErrors();
  11482. let first = true;
  11483. let spreadStartLoc;
  11484. let optionalCommaStartLoc;
  11485. while (!this.match(11)) {
  11486. if (first) {
  11487. first = false;
  11488. } else {
  11489. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  11490. if (this.match(11)) {
  11491. optionalCommaStartLoc = this.state.startLoc;
  11492. break;
  11493. }
  11494. }
  11495. if (this.match(21)) {
  11496. const spreadNodeStartLoc = this.state.startLoc;
  11497. spreadStartLoc = this.state.startLoc;
  11498. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  11499. if (!this.checkCommaAfterRest(41)) {
  11500. break;
  11501. }
  11502. } else {
  11503. exprList.push(this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem));
  11504. }
  11505. }
  11506. const innerEndLoc = this.state.lastTokEndLoc;
  11507. this.expect(11);
  11508. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11509. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11510. let arrowNode = this.startNodeAt(startLoc);
  11511. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  11512. this.checkDestructuringPrivate(refExpressionErrors);
  11513. this.expressionScope.validateAsPattern();
  11514. this.expressionScope.exit();
  11515. this.parseArrowExpression(arrowNode, exprList, false);
  11516. return arrowNode;
  11517. }
  11518. this.expressionScope.exit();
  11519. if (!exprList.length) {
  11520. this.unexpected(this.state.lastTokStartLoc);
  11521. }
  11522. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  11523. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  11524. this.checkExpressionErrors(refExpressionErrors, true);
  11525. this.toReferencedListDeep(exprList, true);
  11526. if (exprList.length > 1) {
  11527. val = this.startNodeAt(innerStartLoc);
  11528. val.expressions = exprList;
  11529. this.finishNode(val, "SequenceExpression");
  11530. this.resetEndLocation(val, innerEndLoc);
  11531. } else {
  11532. val = exprList[0];
  11533. }
  11534. return this.wrapParenthesis(startLoc, val);
  11535. }
  11536. wrapParenthesis(startLoc, expression) {
  11537. if (!this.options.createParenthesizedExpressions) {
  11538. this.addExtra(expression, "parenthesized", true);
  11539. this.addExtra(expression, "parenStart", startLoc.index);
  11540. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  11541. return expression;
  11542. }
  11543. const parenExpression = this.startNodeAt(startLoc);
  11544. parenExpression.expression = expression;
  11545. return this.finishNode(parenExpression, "ParenthesizedExpression");
  11546. }
  11547. shouldParseArrow(params) {
  11548. return !this.canInsertSemicolon();
  11549. }
  11550. parseArrow(node) {
  11551. if (this.eat(19)) {
  11552. return node;
  11553. }
  11554. }
  11555. parseParenItem(node, startLoc) {
  11556. return node;
  11557. }
  11558. parseNewOrNewTarget() {
  11559. const node = this.startNode();
  11560. this.next();
  11561. if (this.match(16)) {
  11562. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  11563. this.next();
  11564. const metaProp = this.parseMetaProperty(node, meta, "target");
  11565. if (!this.scope.inNonArrowFunction && !this.scope.inClass && !this.options.allowNewTargetOutsideFunction) {
  11566. this.raise(Errors.UnexpectedNewTarget, {
  11567. at: metaProp
  11568. });
  11569. }
  11570. return metaProp;
  11571. }
  11572. return this.parseNew(node);
  11573. }
  11574. parseNew(node) {
  11575. this.parseNewCallee(node);
  11576. if (this.eat(10)) {
  11577. const args = this.parseExprList(11);
  11578. this.toReferencedList(args);
  11579. node.arguments = args;
  11580. } else {
  11581. node.arguments = [];
  11582. }
  11583. return this.finishNode(node, "NewExpression");
  11584. }
  11585. parseNewCallee(node) {
  11586. const isImport = this.match(83);
  11587. const callee = this.parseNoCallExpr();
  11588. node.callee = callee;
  11589. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  11590. this.raise(Errors.ImportCallNotNewExpression, {
  11591. at: callee
  11592. });
  11593. }
  11594. }
  11595. parseTemplateElement(isTagged) {
  11596. const {
  11597. start,
  11598. startLoc,
  11599. end,
  11600. value
  11601. } = this.state;
  11602. const elemStart = start + 1;
  11603. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  11604. if (value === null) {
  11605. if (!isTagged) {
  11606. this.raise(Errors.InvalidEscapeSequenceTemplate, {
  11607. at: createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1)
  11608. });
  11609. }
  11610. }
  11611. const isTail = this.match(24);
  11612. const endOffset = isTail ? -1 : -2;
  11613. const elemEnd = end + endOffset;
  11614. elem.value = {
  11615. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  11616. cooked: value === null ? null : value.slice(1, endOffset)
  11617. };
  11618. elem.tail = isTail;
  11619. this.next();
  11620. const finishedNode = this.finishNode(elem, "TemplateElement");
  11621. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  11622. return finishedNode;
  11623. }
  11624. parseTemplate(isTagged) {
  11625. const node = this.startNode();
  11626. node.expressions = [];
  11627. let curElt = this.parseTemplateElement(isTagged);
  11628. node.quasis = [curElt];
  11629. while (!curElt.tail) {
  11630. node.expressions.push(this.parseTemplateSubstitution());
  11631. this.readTemplateContinuation();
  11632. node.quasis.push(curElt = this.parseTemplateElement(isTagged));
  11633. }
  11634. return this.finishNode(node, "TemplateLiteral");
  11635. }
  11636. parseTemplateSubstitution() {
  11637. return this.parseExpression();
  11638. }
  11639. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  11640. if (isRecord) {
  11641. this.expectPlugin("recordAndTuple");
  11642. }
  11643. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11644. this.state.inFSharpPipelineDirectBody = false;
  11645. const propHash = Object.create(null);
  11646. let first = true;
  11647. const node = this.startNode();
  11648. node.properties = [];
  11649. this.next();
  11650. while (!this.match(close)) {
  11651. if (first) {
  11652. first = false;
  11653. } else {
  11654. this.expect(12);
  11655. if (this.match(close)) {
  11656. this.addTrailingCommaExtraToNode(node);
  11657. break;
  11658. }
  11659. }
  11660. let prop;
  11661. if (isPattern) {
  11662. prop = this.parseBindingProperty();
  11663. } else {
  11664. prop = this.parsePropertyDefinition(refExpressionErrors);
  11665. this.checkProto(prop, isRecord, propHash, refExpressionErrors);
  11666. }
  11667. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  11668. this.raise(Errors.InvalidRecordProperty, {
  11669. at: prop
  11670. });
  11671. }
  11672. if (prop.shorthand) {
  11673. this.addExtra(prop, "shorthand", true);
  11674. }
  11675. node.properties.push(prop);
  11676. }
  11677. this.next();
  11678. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11679. let type = "ObjectExpression";
  11680. if (isPattern) {
  11681. type = "ObjectPattern";
  11682. } else if (isRecord) {
  11683. type = "RecordExpression";
  11684. }
  11685. return this.finishNode(node, type);
  11686. }
  11687. addTrailingCommaExtraToNode(node) {
  11688. this.addExtra(node, "trailingComma", this.state.lastTokStart);
  11689. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  11690. }
  11691. maybeAsyncOrAccessorProp(prop) {
  11692. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  11693. }
  11694. parsePropertyDefinition(refExpressionErrors) {
  11695. let decorators = [];
  11696. if (this.match(26)) {
  11697. if (this.hasPlugin("decorators")) {
  11698. this.raise(Errors.UnsupportedPropertyDecorator, {
  11699. at: this.state.startLoc
  11700. });
  11701. }
  11702. while (this.match(26)) {
  11703. decorators.push(this.parseDecorator());
  11704. }
  11705. }
  11706. const prop = this.startNode();
  11707. let isAsync = false;
  11708. let isAccessor = false;
  11709. let startLoc;
  11710. if (this.match(21)) {
  11711. if (decorators.length) this.unexpected();
  11712. return this.parseSpread();
  11713. }
  11714. if (decorators.length) {
  11715. prop.decorators = decorators;
  11716. decorators = [];
  11717. }
  11718. prop.method = false;
  11719. if (refExpressionErrors) {
  11720. startLoc = this.state.startLoc;
  11721. }
  11722. let isGenerator = this.eat(55);
  11723. this.parsePropertyNamePrefixOperator(prop);
  11724. const containsEsc = this.state.containsEsc;
  11725. const key = this.parsePropertyName(prop, refExpressionErrors);
  11726. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  11727. const keyName = key.name;
  11728. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  11729. isAsync = true;
  11730. this.resetPreviousNodeTrailingComments(key);
  11731. isGenerator = this.eat(55);
  11732. this.parsePropertyName(prop);
  11733. }
  11734. if (keyName === "get" || keyName === "set") {
  11735. isAccessor = true;
  11736. this.resetPreviousNodeTrailingComments(key);
  11737. prop.kind = keyName;
  11738. if (this.match(55)) {
  11739. isGenerator = true;
  11740. this.raise(Errors.AccessorIsGenerator, {
  11741. at: this.state.curPosition(),
  11742. kind: keyName
  11743. });
  11744. this.next();
  11745. }
  11746. this.parsePropertyName(prop);
  11747. }
  11748. }
  11749. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  11750. }
  11751. getGetterSetterExpectedParamCount(method) {
  11752. return method.kind === "get" ? 0 : 1;
  11753. }
  11754. getObjectOrClassMethodParams(method) {
  11755. return method.params;
  11756. }
  11757. checkGetterSetterParams(method) {
  11758. var _params;
  11759. const paramCount = this.getGetterSetterExpectedParamCount(method);
  11760. const params = this.getObjectOrClassMethodParams(method);
  11761. if (params.length !== paramCount) {
  11762. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, {
  11763. at: method
  11764. });
  11765. }
  11766. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  11767. this.raise(Errors.BadSetterRestParameter, {
  11768. at: method
  11769. });
  11770. }
  11771. }
  11772. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  11773. if (isAccessor) {
  11774. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  11775. this.checkGetterSetterParams(finishedProp);
  11776. return finishedProp;
  11777. }
  11778. if (isAsync || isGenerator || this.match(10)) {
  11779. if (isPattern) this.unexpected();
  11780. prop.kind = "method";
  11781. prop.method = true;
  11782. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  11783. }
  11784. }
  11785. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  11786. prop.shorthand = false;
  11787. if (this.eat(14)) {
  11788. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowIn(refExpressionErrors);
  11789. return this.finishNode(prop, "ObjectProperty");
  11790. }
  11791. if (!prop.computed && prop.key.type === "Identifier") {
  11792. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  11793. if (isPattern) {
  11794. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11795. } else if (this.match(29)) {
  11796. const shorthandAssignLoc = this.state.startLoc;
  11797. if (refExpressionErrors != null) {
  11798. if (refExpressionErrors.shorthandAssignLoc === null) {
  11799. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  11800. }
  11801. } else {
  11802. this.raise(Errors.InvalidCoverInitializedName, {
  11803. at: shorthandAssignLoc
  11804. });
  11805. }
  11806. prop.value = this.parseMaybeDefault(startLoc, cloneIdentifier(prop.key));
  11807. } else {
  11808. prop.value = cloneIdentifier(prop.key);
  11809. }
  11810. prop.shorthand = true;
  11811. return this.finishNode(prop, "ObjectProperty");
  11812. }
  11813. }
  11814. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  11815. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  11816. if (!node) this.unexpected();
  11817. return node;
  11818. }
  11819. parsePropertyName(prop, refExpressionErrors) {
  11820. if (this.eat(0)) {
  11821. prop.computed = true;
  11822. prop.key = this.parseMaybeAssignAllowIn();
  11823. this.expect(3);
  11824. } else {
  11825. const {
  11826. type,
  11827. value
  11828. } = this.state;
  11829. let key;
  11830. if (tokenIsKeywordOrIdentifier(type)) {
  11831. key = this.parseIdentifier(true);
  11832. } else {
  11833. switch (type) {
  11834. case 134:
  11835. key = this.parseNumericLiteral(value);
  11836. break;
  11837. case 133:
  11838. key = this.parseStringLiteral(value);
  11839. break;
  11840. case 135:
  11841. key = this.parseBigIntLiteral(value);
  11842. break;
  11843. case 136:
  11844. key = this.parseDecimalLiteral(value);
  11845. break;
  11846. case 138:
  11847. {
  11848. const privateKeyLoc = this.state.startLoc;
  11849. if (refExpressionErrors != null) {
  11850. if (refExpressionErrors.privateKeyLoc === null) {
  11851. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  11852. }
  11853. } else {
  11854. this.raise(Errors.UnexpectedPrivateField, {
  11855. at: privateKeyLoc
  11856. });
  11857. }
  11858. key = this.parsePrivateName();
  11859. break;
  11860. }
  11861. default:
  11862. this.unexpected();
  11863. }
  11864. }
  11865. prop.key = key;
  11866. if (type !== 138) {
  11867. prop.computed = false;
  11868. }
  11869. }
  11870. return prop.key;
  11871. }
  11872. initFunction(node, isAsync) {
  11873. node.id = null;
  11874. node.generator = false;
  11875. node.async = isAsync;
  11876. }
  11877. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  11878. this.initFunction(node, isAsync);
  11879. node.generator = isGenerator;
  11880. this.scope.enter(2 | 16 | (inClassScope ? 64 : 0) | (allowDirectSuper ? 32 : 0));
  11881. this.prodParam.enter(functionFlags(isAsync, node.generator));
  11882. this.parseFunctionParams(node, isConstructor);
  11883. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  11884. this.prodParam.exit();
  11885. this.scope.exit();
  11886. return finishedNode;
  11887. }
  11888. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11889. if (isTuple) {
  11890. this.expectPlugin("recordAndTuple");
  11891. }
  11892. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  11893. this.state.inFSharpPipelineDirectBody = false;
  11894. const node = this.startNode();
  11895. this.next();
  11896. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  11897. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  11898. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  11899. }
  11900. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  11901. this.scope.enter(2 | 4);
  11902. let flags = functionFlags(isAsync, false);
  11903. if (!this.match(5) && this.prodParam.hasIn) {
  11904. flags |= PARAM_IN;
  11905. }
  11906. this.prodParam.enter(flags);
  11907. this.initFunction(node, isAsync);
  11908. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11909. if (params) {
  11910. this.state.maybeInArrowParameters = true;
  11911. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11912. }
  11913. this.state.maybeInArrowParameters = false;
  11914. this.parseFunctionBody(node, true);
  11915. this.prodParam.exit();
  11916. this.scope.exit();
  11917. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11918. return this.finishNode(node, "ArrowFunctionExpression");
  11919. }
  11920. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11921. this.toAssignableList(params, trailingCommaLoc, false);
  11922. node.params = params;
  11923. }
  11924. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11925. this.parseFunctionBody(node, false, isMethod);
  11926. return this.finishNode(node, type);
  11927. }
  11928. parseFunctionBody(node, allowExpression, isMethod = false) {
  11929. const isExpression = allowExpression && !this.match(5);
  11930. this.expressionScope.enter(newExpressionScope());
  11931. if (isExpression) {
  11932. node.body = this.parseMaybeAssign();
  11933. this.checkParams(node, false, allowExpression, false);
  11934. } else {
  11935. const oldStrict = this.state.strict;
  11936. const oldLabels = this.state.labels;
  11937. this.state.labels = [];
  11938. this.prodParam.enter(this.prodParam.currentFlags() | PARAM_RETURN);
  11939. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  11940. const nonSimple = !this.isSimpleParamList(node.params);
  11941. if (hasStrictModeDirective && nonSimple) {
  11942. this.raise(Errors.IllegalLanguageModeDirective, {
  11943. at: (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node
  11944. });
  11945. }
  11946. const strictModeChanged = !oldStrict && this.state.strict;
  11947. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  11948. if (this.state.strict && node.id) {
  11949. this.checkIdentifier(node.id, 65, strictModeChanged);
  11950. }
  11951. });
  11952. this.prodParam.exit();
  11953. this.state.labels = oldLabels;
  11954. }
  11955. this.expressionScope.exit();
  11956. }
  11957. isSimpleParameter(node) {
  11958. return node.type === "Identifier";
  11959. }
  11960. isSimpleParamList(params) {
  11961. for (let i = 0, len = params.length; i < len; i++) {
  11962. if (!this.isSimpleParameter(params[i])) return false;
  11963. }
  11964. return true;
  11965. }
  11966. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  11967. const checkClashes = !allowDuplicates && new Set();
  11968. const formalParameters = {
  11969. type: "FormalParameters"
  11970. };
  11971. for (const param of node.params) {
  11972. this.checkLVal(param, {
  11973. in: formalParameters,
  11974. binding: 5,
  11975. checkClashes,
  11976. strictModeChanged
  11977. });
  11978. }
  11979. }
  11980. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  11981. const elts = [];
  11982. let first = true;
  11983. while (!this.eat(close)) {
  11984. if (first) {
  11985. first = false;
  11986. } else {
  11987. this.expect(12);
  11988. if (this.match(close)) {
  11989. if (nodeForExtra) {
  11990. this.addTrailingCommaExtraToNode(nodeForExtra);
  11991. }
  11992. this.next();
  11993. break;
  11994. }
  11995. }
  11996. elts.push(this.parseExprListItem(allowEmpty, refExpressionErrors));
  11997. }
  11998. return elts;
  11999. }
  12000. parseExprListItem(allowEmpty, refExpressionErrors, allowPlaceholder) {
  12001. let elt;
  12002. if (this.match(12)) {
  12003. if (!allowEmpty) {
  12004. this.raise(Errors.UnexpectedToken, {
  12005. at: this.state.curPosition(),
  12006. unexpected: ","
  12007. });
  12008. }
  12009. elt = null;
  12010. } else if (this.match(21)) {
  12011. const spreadNodeStartLoc = this.state.startLoc;
  12012. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  12013. } else if (this.match(17)) {
  12014. this.expectPlugin("partialApplication");
  12015. if (!allowPlaceholder) {
  12016. this.raise(Errors.UnexpectedArgumentPlaceholder, {
  12017. at: this.state.startLoc
  12018. });
  12019. }
  12020. const node = this.startNode();
  12021. this.next();
  12022. elt = this.finishNode(node, "ArgumentPlaceholder");
  12023. } else {
  12024. elt = this.parseMaybeAssignAllowIn(refExpressionErrors, this.parseParenItem);
  12025. }
  12026. return elt;
  12027. }
  12028. parseIdentifier(liberal) {
  12029. const node = this.startNode();
  12030. const name = this.parseIdentifierName(liberal);
  12031. return this.createIdentifier(node, name);
  12032. }
  12033. createIdentifier(node, name) {
  12034. node.name = name;
  12035. node.loc.identifierName = name;
  12036. return this.finishNode(node, "Identifier");
  12037. }
  12038. parseIdentifierName(liberal) {
  12039. let name;
  12040. const {
  12041. startLoc,
  12042. type
  12043. } = this.state;
  12044. if (tokenIsKeywordOrIdentifier(type)) {
  12045. name = this.state.value;
  12046. } else {
  12047. this.unexpected();
  12048. }
  12049. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  12050. if (liberal) {
  12051. if (tokenIsKeyword) {
  12052. this.replaceToken(132);
  12053. }
  12054. } else {
  12055. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  12056. }
  12057. this.next();
  12058. return name;
  12059. }
  12060. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12061. if (word.length > 10) {
  12062. return;
  12063. }
  12064. if (!canBeReservedWord(word)) {
  12065. return;
  12066. }
  12067. if (checkKeywords && isKeyword(word)) {
  12068. this.raise(Errors.UnexpectedKeyword, {
  12069. at: startLoc,
  12070. keyword: word
  12071. });
  12072. return;
  12073. }
  12074. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  12075. if (reservedTest(word, this.inModule)) {
  12076. this.raise(Errors.UnexpectedReservedWord, {
  12077. at: startLoc,
  12078. reservedWord: word
  12079. });
  12080. return;
  12081. } else if (word === "yield") {
  12082. if (this.prodParam.hasYield) {
  12083. this.raise(Errors.YieldBindingIdentifier, {
  12084. at: startLoc
  12085. });
  12086. return;
  12087. }
  12088. } else if (word === "await") {
  12089. if (this.prodParam.hasAwait) {
  12090. this.raise(Errors.AwaitBindingIdentifier, {
  12091. at: startLoc
  12092. });
  12093. return;
  12094. }
  12095. if (this.scope.inStaticBlock) {
  12096. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, {
  12097. at: startLoc
  12098. });
  12099. return;
  12100. }
  12101. this.expressionScope.recordAsyncArrowParametersError({
  12102. at: startLoc
  12103. });
  12104. } else if (word === "arguments") {
  12105. if (this.scope.inClassAndNotInNonArrowFunction) {
  12106. this.raise(Errors.ArgumentsInClass, {
  12107. at: startLoc
  12108. });
  12109. return;
  12110. }
  12111. }
  12112. }
  12113. isAwaitAllowed() {
  12114. if (this.prodParam.hasAwait) return true;
  12115. if (this.options.allowAwaitOutsideFunction && !this.scope.inFunction) {
  12116. return true;
  12117. }
  12118. return false;
  12119. }
  12120. parseAwait(startLoc) {
  12121. const node = this.startNodeAt(startLoc);
  12122. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, {
  12123. at: node
  12124. });
  12125. if (this.eat(55)) {
  12126. this.raise(Errors.ObsoleteAwaitStar, {
  12127. at: node
  12128. });
  12129. }
  12130. if (!this.scope.inFunction && !this.options.allowAwaitOutsideFunction) {
  12131. if (this.isAmbiguousAwait()) {
  12132. this.ambiguousScriptDifferentAst = true;
  12133. } else {
  12134. this.sawUnambiguousESM = true;
  12135. }
  12136. }
  12137. if (!this.state.soloAwait) {
  12138. node.argument = this.parseMaybeUnary(null, true);
  12139. }
  12140. return this.finishNode(node, "AwaitExpression");
  12141. }
  12142. isAmbiguousAwait() {
  12143. if (this.hasPrecedingLineBreak()) return true;
  12144. const {
  12145. type
  12146. } = this.state;
  12147. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 137 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  12148. }
  12149. parseYield() {
  12150. const node = this.startNode();
  12151. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, {
  12152. at: node
  12153. });
  12154. this.next();
  12155. let delegating = false;
  12156. let argument = null;
  12157. if (!this.hasPrecedingLineBreak()) {
  12158. delegating = this.eat(55);
  12159. switch (this.state.type) {
  12160. case 13:
  12161. case 139:
  12162. case 8:
  12163. case 11:
  12164. case 3:
  12165. case 9:
  12166. case 14:
  12167. case 12:
  12168. if (!delegating) break;
  12169. default:
  12170. argument = this.parseMaybeAssign();
  12171. }
  12172. }
  12173. node.delegate = delegating;
  12174. node.argument = argument;
  12175. return this.finishNode(node, "YieldExpression");
  12176. }
  12177. parseImportCall(node) {
  12178. this.next();
  12179. node.source = this.parseMaybeAssignAllowIn();
  12180. if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  12181. node.options = null;
  12182. }
  12183. if (this.eat(12)) {
  12184. this.expectImportAttributesPlugin();
  12185. if (!this.match(11)) {
  12186. node.options = this.parseMaybeAssignAllowIn();
  12187. this.eat(12);
  12188. }
  12189. }
  12190. this.expect(11);
  12191. return this.finishNode(node, "ImportExpression");
  12192. }
  12193. checkPipelineAtInfixOperator(left, leftStartLoc) {
  12194. if (this.hasPlugin(["pipelineOperator", {
  12195. proposal: "smart"
  12196. }])) {
  12197. if (left.type === "SequenceExpression") {
  12198. this.raise(Errors.PipelineHeadSequenceExpression, {
  12199. at: leftStartLoc
  12200. });
  12201. }
  12202. }
  12203. }
  12204. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  12205. if (this.isSimpleReference(childExpr)) {
  12206. const bodyNode = this.startNodeAt(startLoc);
  12207. bodyNode.callee = childExpr;
  12208. return this.finishNode(bodyNode, "PipelineBareFunction");
  12209. } else {
  12210. const bodyNode = this.startNodeAt(startLoc);
  12211. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  12212. bodyNode.expression = childExpr;
  12213. return this.finishNode(bodyNode, "PipelineTopicExpression");
  12214. }
  12215. }
  12216. isSimpleReference(expression) {
  12217. switch (expression.type) {
  12218. case "MemberExpression":
  12219. return !expression.computed && this.isSimpleReference(expression.object);
  12220. case "Identifier":
  12221. return true;
  12222. default:
  12223. return false;
  12224. }
  12225. }
  12226. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  12227. if (this.match(19)) {
  12228. throw this.raise(Errors.PipelineBodyNoArrow, {
  12229. at: this.state.startLoc
  12230. });
  12231. }
  12232. if (!this.topicReferenceWasUsedInCurrentContext()) {
  12233. this.raise(Errors.PipelineTopicUnused, {
  12234. at: startLoc
  12235. });
  12236. }
  12237. }
  12238. withTopicBindingContext(callback) {
  12239. const outerContextTopicState = this.state.topicContext;
  12240. this.state.topicContext = {
  12241. maxNumOfResolvableTopics: 1,
  12242. maxTopicIndex: null
  12243. };
  12244. try {
  12245. return callback();
  12246. } finally {
  12247. this.state.topicContext = outerContextTopicState;
  12248. }
  12249. }
  12250. withSmartMixTopicForbiddingContext(callback) {
  12251. if (this.hasPlugin(["pipelineOperator", {
  12252. proposal: "smart"
  12253. }])) {
  12254. const outerContextTopicState = this.state.topicContext;
  12255. this.state.topicContext = {
  12256. maxNumOfResolvableTopics: 0,
  12257. maxTopicIndex: null
  12258. };
  12259. try {
  12260. return callback();
  12261. } finally {
  12262. this.state.topicContext = outerContextTopicState;
  12263. }
  12264. } else {
  12265. return callback();
  12266. }
  12267. }
  12268. withSoloAwaitPermittingContext(callback) {
  12269. const outerContextSoloAwaitState = this.state.soloAwait;
  12270. this.state.soloAwait = true;
  12271. try {
  12272. return callback();
  12273. } finally {
  12274. this.state.soloAwait = outerContextSoloAwaitState;
  12275. }
  12276. }
  12277. allowInAnd(callback) {
  12278. const flags = this.prodParam.currentFlags();
  12279. const prodParamToSet = PARAM_IN & ~flags;
  12280. if (prodParamToSet) {
  12281. this.prodParam.enter(flags | PARAM_IN);
  12282. try {
  12283. return callback();
  12284. } finally {
  12285. this.prodParam.exit();
  12286. }
  12287. }
  12288. return callback();
  12289. }
  12290. disallowInAnd(callback) {
  12291. const flags = this.prodParam.currentFlags();
  12292. const prodParamToClear = PARAM_IN & flags;
  12293. if (prodParamToClear) {
  12294. this.prodParam.enter(flags & ~PARAM_IN);
  12295. try {
  12296. return callback();
  12297. } finally {
  12298. this.prodParam.exit();
  12299. }
  12300. }
  12301. return callback();
  12302. }
  12303. registerTopicReference() {
  12304. this.state.topicContext.maxTopicIndex = 0;
  12305. }
  12306. topicReferenceIsAllowedInCurrentContext() {
  12307. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  12308. }
  12309. topicReferenceWasUsedInCurrentContext() {
  12310. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  12311. }
  12312. parseFSharpPipelineBody(prec) {
  12313. const startLoc = this.state.startLoc;
  12314. this.state.potentialArrowAt = this.state.start;
  12315. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  12316. this.state.inFSharpPipelineDirectBody = true;
  12317. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  12318. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  12319. return ret;
  12320. }
  12321. parseModuleExpression() {
  12322. this.expectPlugin("moduleBlocks");
  12323. const node = this.startNode();
  12324. this.next();
  12325. if (!this.match(5)) {
  12326. this.unexpected(null, 5);
  12327. }
  12328. const program = this.startNodeAt(this.state.endLoc);
  12329. this.next();
  12330. const revertScopes = this.initializeScopes(true);
  12331. this.enterInitialScopes();
  12332. try {
  12333. node.body = this.parseProgram(program, 8, "module");
  12334. } finally {
  12335. revertScopes();
  12336. }
  12337. return this.finishNode(node, "ModuleExpression");
  12338. }
  12339. parsePropertyNamePrefixOperator(prop) {}
  12340. }
  12341. const loopLabel = {
  12342. kind: "loop"
  12343. },
  12344. switchLabel = {
  12345. kind: "switch"
  12346. };
  12347. const loneSurrogate = /[\uD800-\uDFFF]/u;
  12348. const keywordRelationalOperator = /in(?:stanceof)?/y;
  12349. function babel7CompatTokens(tokens, input) {
  12350. for (let i = 0; i < tokens.length; i++) {
  12351. const token = tokens[i];
  12352. const {
  12353. type
  12354. } = token;
  12355. if (typeof type === "number") {
  12356. {
  12357. if (type === 138) {
  12358. const {
  12359. loc,
  12360. start,
  12361. value,
  12362. end
  12363. } = token;
  12364. const hashEndPos = start + 1;
  12365. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12366. tokens.splice(i, 1, new Token({
  12367. type: getExportedToken(27),
  12368. value: "#",
  12369. start: start,
  12370. end: hashEndPos,
  12371. startLoc: loc.start,
  12372. endLoc: hashEndLoc
  12373. }), new Token({
  12374. type: getExportedToken(132),
  12375. value: value,
  12376. start: hashEndPos,
  12377. end: end,
  12378. startLoc: hashEndLoc,
  12379. endLoc: loc.end
  12380. }));
  12381. i++;
  12382. continue;
  12383. }
  12384. if (tokenIsTemplate(type)) {
  12385. const {
  12386. loc,
  12387. start,
  12388. value,
  12389. end
  12390. } = token;
  12391. const backquoteEnd = start + 1;
  12392. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  12393. let startToken;
  12394. if (input.charCodeAt(start) === 96) {
  12395. startToken = new Token({
  12396. type: getExportedToken(22),
  12397. value: "`",
  12398. start: start,
  12399. end: backquoteEnd,
  12400. startLoc: loc.start,
  12401. endLoc: backquoteEndLoc
  12402. });
  12403. } else {
  12404. startToken = new Token({
  12405. type: getExportedToken(8),
  12406. value: "}",
  12407. start: start,
  12408. end: backquoteEnd,
  12409. startLoc: loc.start,
  12410. endLoc: backquoteEndLoc
  12411. });
  12412. }
  12413. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  12414. if (type === 24) {
  12415. templateElementEnd = end - 1;
  12416. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  12417. templateValue = value === null ? null : value.slice(1, -1);
  12418. endToken = new Token({
  12419. type: getExportedToken(22),
  12420. value: "`",
  12421. start: templateElementEnd,
  12422. end: end,
  12423. startLoc: templateElementEndLoc,
  12424. endLoc: loc.end
  12425. });
  12426. } else {
  12427. templateElementEnd = end - 2;
  12428. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  12429. templateValue = value === null ? null : value.slice(1, -2);
  12430. endToken = new Token({
  12431. type: getExportedToken(23),
  12432. value: "${",
  12433. start: templateElementEnd,
  12434. end: end,
  12435. startLoc: templateElementEndLoc,
  12436. endLoc: loc.end
  12437. });
  12438. }
  12439. tokens.splice(i, 1, startToken, new Token({
  12440. type: getExportedToken(20),
  12441. value: templateValue,
  12442. start: backquoteEnd,
  12443. end: templateElementEnd,
  12444. startLoc: backquoteEndLoc,
  12445. endLoc: templateElementEndLoc
  12446. }), endToken);
  12447. i += 2;
  12448. continue;
  12449. }
  12450. }
  12451. token.type = getExportedToken(type);
  12452. }
  12453. }
  12454. return tokens;
  12455. }
  12456. class StatementParser extends ExpressionParser {
  12457. parseTopLevel(file, program) {
  12458. file.program = this.parseProgram(program);
  12459. file.comments = this.state.comments;
  12460. if (this.options.tokens) {
  12461. file.tokens = babel7CompatTokens(this.tokens, this.input);
  12462. }
  12463. return this.finishNode(file, "File");
  12464. }
  12465. parseProgram(program, end = 139, sourceType = this.options.sourceType) {
  12466. program.sourceType = sourceType;
  12467. program.interpreter = this.parseInterpreterDirective();
  12468. this.parseBlockBody(program, true, true, end);
  12469. if (this.inModule && !this.options.allowUndeclaredExports && this.scope.undefinedExports.size > 0) {
  12470. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  12471. this.raise(Errors.ModuleExportUndefined, {
  12472. at,
  12473. localName
  12474. });
  12475. }
  12476. }
  12477. let finishedProgram;
  12478. if (end === 139) {
  12479. finishedProgram = this.finishNode(program, "Program");
  12480. } else {
  12481. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  12482. }
  12483. return finishedProgram;
  12484. }
  12485. stmtToDirective(stmt) {
  12486. const directive = stmt;
  12487. directive.type = "Directive";
  12488. directive.value = directive.expression;
  12489. delete directive.expression;
  12490. const directiveLiteral = directive.value;
  12491. const expressionValue = directiveLiteral.value;
  12492. const raw = this.input.slice(directiveLiteral.start, directiveLiteral.end);
  12493. const val = directiveLiteral.value = raw.slice(1, -1);
  12494. this.addExtra(directiveLiteral, "raw", raw);
  12495. this.addExtra(directiveLiteral, "rawValue", val);
  12496. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  12497. directiveLiteral.type = "DirectiveLiteral";
  12498. return directive;
  12499. }
  12500. parseInterpreterDirective() {
  12501. if (!this.match(28)) {
  12502. return null;
  12503. }
  12504. const node = this.startNode();
  12505. node.value = this.state.value;
  12506. this.next();
  12507. return this.finishNode(node, "InterpreterDirective");
  12508. }
  12509. isLet() {
  12510. if (!this.isContextual(100)) {
  12511. return false;
  12512. }
  12513. return this.hasFollowingBindingAtom();
  12514. }
  12515. chStartsBindingIdentifier(ch, pos) {
  12516. if (isIdentifierStart(ch)) {
  12517. keywordRelationalOperator.lastIndex = pos;
  12518. if (keywordRelationalOperator.test(this.input)) {
  12519. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  12520. if (!isIdentifierChar(endCh) && endCh !== 92) {
  12521. return false;
  12522. }
  12523. }
  12524. return true;
  12525. } else if (ch === 92) {
  12526. return true;
  12527. } else {
  12528. return false;
  12529. }
  12530. }
  12531. chStartsBindingPattern(ch) {
  12532. return ch === 91 || ch === 123;
  12533. }
  12534. hasFollowingBindingAtom() {
  12535. const next = this.nextTokenStart();
  12536. const nextCh = this.codePointAtPos(next);
  12537. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  12538. }
  12539. hasInLineFollowingBindingIdentifier() {
  12540. const next = this.nextTokenInLineStart();
  12541. const nextCh = this.codePointAtPos(next);
  12542. return this.chStartsBindingIdentifier(nextCh, next);
  12543. }
  12544. startsUsingForOf() {
  12545. const {
  12546. type,
  12547. containsEsc
  12548. } = this.lookahead();
  12549. if (type === 102 && !containsEsc) {
  12550. return false;
  12551. } else if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
  12552. this.expectPlugin("explicitResourceManagement");
  12553. return true;
  12554. }
  12555. }
  12556. startsAwaitUsing() {
  12557. let next = this.nextTokenInLineStart();
  12558. if (this.isUnparsedContextual(next, "using")) {
  12559. next = this.nextTokenInLineStartSince(next + 5);
  12560. const nextCh = this.codePointAtPos(next);
  12561. if (this.chStartsBindingIdentifier(nextCh, next)) {
  12562. this.expectPlugin("explicitResourceManagement");
  12563. return true;
  12564. }
  12565. }
  12566. return false;
  12567. }
  12568. parseModuleItem() {
  12569. return this.parseStatementLike(1 | 2 | 4 | 8);
  12570. }
  12571. parseStatementListItem() {
  12572. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  12573. }
  12574. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  12575. let flags = 0;
  12576. if (this.options.annexB && !this.state.strict) {
  12577. flags |= 4;
  12578. if (allowLabeledFunction) {
  12579. flags |= 8;
  12580. }
  12581. }
  12582. return this.parseStatementLike(flags);
  12583. }
  12584. parseStatement() {
  12585. return this.parseStatementLike(0);
  12586. }
  12587. parseStatementLike(flags) {
  12588. let decorators = null;
  12589. if (this.match(26)) {
  12590. decorators = this.parseDecorators(true);
  12591. }
  12592. return this.parseStatementContent(flags, decorators);
  12593. }
  12594. parseStatementContent(flags, decorators) {
  12595. const starttype = this.state.type;
  12596. const node = this.startNode();
  12597. const allowDeclaration = !!(flags & 2);
  12598. const allowFunctionDeclaration = !!(flags & 4);
  12599. const topLevel = flags & 1;
  12600. switch (starttype) {
  12601. case 60:
  12602. return this.parseBreakContinueStatement(node, true);
  12603. case 63:
  12604. return this.parseBreakContinueStatement(node, false);
  12605. case 64:
  12606. return this.parseDebuggerStatement(node);
  12607. case 90:
  12608. return this.parseDoWhileStatement(node);
  12609. case 91:
  12610. return this.parseForStatement(node);
  12611. case 68:
  12612. if (this.lookaheadCharCode() === 46) break;
  12613. if (!allowFunctionDeclaration) {
  12614. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, {
  12615. at: this.state.startLoc
  12616. });
  12617. }
  12618. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  12619. case 80:
  12620. if (!allowDeclaration) this.unexpected();
  12621. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  12622. case 69:
  12623. return this.parseIfStatement(node);
  12624. case 70:
  12625. return this.parseReturnStatement(node);
  12626. case 71:
  12627. return this.parseSwitchStatement(node);
  12628. case 72:
  12629. return this.parseThrowStatement(node);
  12630. case 73:
  12631. return this.parseTryStatement(node);
  12632. case 96:
  12633. if (!this.state.containsEsc && this.startsAwaitUsing()) {
  12634. if (!this.isAwaitAllowed()) {
  12635. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12636. at: node
  12637. });
  12638. } else if (!allowDeclaration) {
  12639. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12640. at: node
  12641. });
  12642. }
  12643. this.next();
  12644. return this.parseVarStatement(node, "await using");
  12645. }
  12646. break;
  12647. case 107:
  12648. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifier()) {
  12649. break;
  12650. }
  12651. this.expectPlugin("explicitResourceManagement");
  12652. if (!this.scope.inModule && this.scope.inTopLevel) {
  12653. this.raise(Errors.UnexpectedUsingDeclaration, {
  12654. at: this.state.startLoc
  12655. });
  12656. } else if (!allowDeclaration) {
  12657. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12658. at: this.state.startLoc
  12659. });
  12660. }
  12661. return this.parseVarStatement(node, "using");
  12662. case 100:
  12663. {
  12664. if (this.state.containsEsc) {
  12665. break;
  12666. }
  12667. const next = this.nextTokenStart();
  12668. const nextCh = this.codePointAtPos(next);
  12669. if (nextCh !== 91) {
  12670. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  12671. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  12672. break;
  12673. }
  12674. }
  12675. }
  12676. case 75:
  12677. {
  12678. if (!allowDeclaration) {
  12679. this.raise(Errors.UnexpectedLexicalDeclaration, {
  12680. at: this.state.startLoc
  12681. });
  12682. }
  12683. }
  12684. case 74:
  12685. {
  12686. const kind = this.state.value;
  12687. return this.parseVarStatement(node, kind);
  12688. }
  12689. case 92:
  12690. return this.parseWhileStatement(node);
  12691. case 76:
  12692. return this.parseWithStatement(node);
  12693. case 5:
  12694. return this.parseBlock();
  12695. case 13:
  12696. return this.parseEmptyStatement(node);
  12697. case 83:
  12698. {
  12699. const nextTokenCharCode = this.lookaheadCharCode();
  12700. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  12701. break;
  12702. }
  12703. }
  12704. case 82:
  12705. {
  12706. if (!this.options.allowImportExportEverywhere && !topLevel) {
  12707. this.raise(Errors.UnexpectedImportExport, {
  12708. at: this.state.startLoc
  12709. });
  12710. }
  12711. this.next();
  12712. let result;
  12713. if (starttype === 83) {
  12714. result = this.parseImport(node);
  12715. if (result.type === "ImportDeclaration" && (!result.importKind || result.importKind === "value")) {
  12716. this.sawUnambiguousESM = true;
  12717. }
  12718. } else {
  12719. result = this.parseExport(node, decorators);
  12720. if (result.type === "ExportNamedDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportAllDeclaration" && (!result.exportKind || result.exportKind === "value") || result.type === "ExportDefaultDeclaration") {
  12721. this.sawUnambiguousESM = true;
  12722. }
  12723. }
  12724. this.assertModuleNodeAllowed(result);
  12725. return result;
  12726. }
  12727. default:
  12728. {
  12729. if (this.isAsyncFunction()) {
  12730. if (!allowDeclaration) {
  12731. this.raise(Errors.AsyncFunctionInSingleStatementContext, {
  12732. at: this.state.startLoc
  12733. });
  12734. }
  12735. this.next();
  12736. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  12737. }
  12738. }
  12739. }
  12740. const maybeName = this.state.value;
  12741. const expr = this.parseExpression();
  12742. if (tokenIsIdentifier(starttype) && expr.type === "Identifier" && this.eat(14)) {
  12743. return this.parseLabeledStatement(node, maybeName, expr, flags);
  12744. } else {
  12745. return this.parseExpressionStatement(node, expr, decorators);
  12746. }
  12747. }
  12748. assertModuleNodeAllowed(node) {
  12749. if (!this.options.allowImportExportEverywhere && !this.inModule) {
  12750. this.raise(Errors.ImportOutsideModule, {
  12751. at: node
  12752. });
  12753. }
  12754. }
  12755. decoratorsEnabledBeforeExport() {
  12756. if (this.hasPlugin("decorators-legacy")) return true;
  12757. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  12758. }
  12759. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  12760. if (maybeDecorators) {
  12761. if (classNode.decorators && classNode.decorators.length > 0) {
  12762. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  12763. this.raise(Errors.DecoratorsBeforeAfterExport, {
  12764. at: classNode.decorators[0]
  12765. });
  12766. }
  12767. classNode.decorators.unshift(...maybeDecorators);
  12768. } else {
  12769. classNode.decorators = maybeDecorators;
  12770. }
  12771. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  12772. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  12773. }
  12774. return classNode;
  12775. }
  12776. canHaveLeadingDecorator() {
  12777. return this.match(80);
  12778. }
  12779. parseDecorators(allowExport) {
  12780. const decorators = [];
  12781. do {
  12782. decorators.push(this.parseDecorator());
  12783. } while (this.match(26));
  12784. if (this.match(82)) {
  12785. if (!allowExport) {
  12786. this.unexpected();
  12787. }
  12788. if (!this.decoratorsEnabledBeforeExport()) {
  12789. this.raise(Errors.DecoratorExportClass, {
  12790. at: this.state.startLoc
  12791. });
  12792. }
  12793. } else if (!this.canHaveLeadingDecorator()) {
  12794. throw this.raise(Errors.UnexpectedLeadingDecorator, {
  12795. at: this.state.startLoc
  12796. });
  12797. }
  12798. return decorators;
  12799. }
  12800. parseDecorator() {
  12801. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  12802. const node = this.startNode();
  12803. this.next();
  12804. if (this.hasPlugin("decorators")) {
  12805. const startLoc = this.state.startLoc;
  12806. let expr;
  12807. if (this.match(10)) {
  12808. const startLoc = this.state.startLoc;
  12809. this.next();
  12810. expr = this.parseExpression();
  12811. this.expect(11);
  12812. expr = this.wrapParenthesis(startLoc, expr);
  12813. const paramsStartLoc = this.state.startLoc;
  12814. node.expression = this.parseMaybeDecoratorArguments(expr);
  12815. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  12816. this.raise(Errors.DecoratorArgumentsOutsideParentheses, {
  12817. at: paramsStartLoc
  12818. });
  12819. }
  12820. } else {
  12821. expr = this.parseIdentifier(false);
  12822. while (this.eat(16)) {
  12823. const node = this.startNodeAt(startLoc);
  12824. node.object = expr;
  12825. if (this.match(138)) {
  12826. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  12827. node.property = this.parsePrivateName();
  12828. } else {
  12829. node.property = this.parseIdentifier(true);
  12830. }
  12831. node.computed = false;
  12832. expr = this.finishNode(node, "MemberExpression");
  12833. }
  12834. node.expression = this.parseMaybeDecoratorArguments(expr);
  12835. }
  12836. } else {
  12837. node.expression = this.parseExprSubscripts();
  12838. }
  12839. return this.finishNode(node, "Decorator");
  12840. }
  12841. parseMaybeDecoratorArguments(expr) {
  12842. if (this.eat(10)) {
  12843. const node = this.startNodeAtNode(expr);
  12844. node.callee = expr;
  12845. node.arguments = this.parseCallExpressionArguments(11, false);
  12846. this.toReferencedList(node.arguments);
  12847. return this.finishNode(node, "CallExpression");
  12848. }
  12849. return expr;
  12850. }
  12851. parseBreakContinueStatement(node, isBreak) {
  12852. this.next();
  12853. if (this.isLineTerminator()) {
  12854. node.label = null;
  12855. } else {
  12856. node.label = this.parseIdentifier();
  12857. this.semicolon();
  12858. }
  12859. this.verifyBreakContinue(node, isBreak);
  12860. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  12861. }
  12862. verifyBreakContinue(node, isBreak) {
  12863. let i;
  12864. for (i = 0; i < this.state.labels.length; ++i) {
  12865. const lab = this.state.labels[i];
  12866. if (node.label == null || lab.name === node.label.name) {
  12867. if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
  12868. if (node.label && isBreak) break;
  12869. }
  12870. }
  12871. if (i === this.state.labels.length) {
  12872. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  12873. this.raise(Errors.IllegalBreakContinue, {
  12874. at: node,
  12875. type
  12876. });
  12877. }
  12878. }
  12879. parseDebuggerStatement(node) {
  12880. this.next();
  12881. this.semicolon();
  12882. return this.finishNode(node, "DebuggerStatement");
  12883. }
  12884. parseHeaderExpression() {
  12885. this.expect(10);
  12886. const val = this.parseExpression();
  12887. this.expect(11);
  12888. return val;
  12889. }
  12890. parseDoWhileStatement(node) {
  12891. this.next();
  12892. this.state.labels.push(loopLabel);
  12893. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  12894. this.state.labels.pop();
  12895. this.expect(92);
  12896. node.test = this.parseHeaderExpression();
  12897. this.eat(13);
  12898. return this.finishNode(node, "DoWhileStatement");
  12899. }
  12900. parseForStatement(node) {
  12901. this.next();
  12902. this.state.labels.push(loopLabel);
  12903. let awaitAt = null;
  12904. if (this.isAwaitAllowed() && this.eatContextual(96)) {
  12905. awaitAt = this.state.lastTokStartLoc;
  12906. }
  12907. this.scope.enter(0);
  12908. this.expect(10);
  12909. if (this.match(13)) {
  12910. if (awaitAt !== null) {
  12911. this.unexpected(awaitAt);
  12912. }
  12913. return this.parseFor(node, null);
  12914. }
  12915. const startsWithLet = this.isContextual(100);
  12916. {
  12917. const startsWithAwaitUsing = this.isContextual(96) && this.startsAwaitUsing();
  12918. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isContextual(107) && this.startsUsingForOf();
  12919. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  12920. if (this.match(74) || this.match(75) || isLetOrUsing) {
  12921. const initNode = this.startNode();
  12922. let kind;
  12923. if (startsWithAwaitUsing) {
  12924. kind = "await using";
  12925. if (!this.isAwaitAllowed()) {
  12926. this.raise(Errors.AwaitUsingNotInAsyncContext, {
  12927. at: this.state.startLoc
  12928. });
  12929. }
  12930. this.next();
  12931. } else {
  12932. kind = this.state.value;
  12933. }
  12934. this.next();
  12935. this.parseVar(initNode, true, kind);
  12936. const init = this.finishNode(initNode, "VariableDeclaration");
  12937. const isForIn = this.match(58);
  12938. if (isForIn && starsWithUsingDeclaration) {
  12939. this.raise(Errors.ForInUsing, {
  12940. at: init
  12941. });
  12942. }
  12943. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  12944. return this.parseForIn(node, init, awaitAt);
  12945. }
  12946. if (awaitAt !== null) {
  12947. this.unexpected(awaitAt);
  12948. }
  12949. return this.parseFor(node, init);
  12950. }
  12951. }
  12952. const startsWithAsync = this.isContextual(95);
  12953. const refExpressionErrors = new ExpressionErrors();
  12954. const init = this.parseExpression(true, refExpressionErrors);
  12955. const isForOf = this.isContextual(102);
  12956. if (isForOf) {
  12957. if (startsWithLet) {
  12958. this.raise(Errors.ForOfLet, {
  12959. at: init
  12960. });
  12961. }
  12962. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  12963. this.raise(Errors.ForOfAsync, {
  12964. at: init
  12965. });
  12966. }
  12967. }
  12968. if (isForOf || this.match(58)) {
  12969. this.checkDestructuringPrivate(refExpressionErrors);
  12970. this.toAssignable(init, true);
  12971. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  12972. this.checkLVal(init, {
  12973. in: {
  12974. type
  12975. }
  12976. });
  12977. return this.parseForIn(node, init, awaitAt);
  12978. } else {
  12979. this.checkExpressionErrors(refExpressionErrors, true);
  12980. }
  12981. if (awaitAt !== null) {
  12982. this.unexpected(awaitAt);
  12983. }
  12984. return this.parseFor(node, init);
  12985. }
  12986. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  12987. this.next();
  12988. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  12989. }
  12990. parseIfStatement(node) {
  12991. this.next();
  12992. node.test = this.parseHeaderExpression();
  12993. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12994. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  12995. return this.finishNode(node, "IfStatement");
  12996. }
  12997. parseReturnStatement(node) {
  12998. if (!this.prodParam.hasReturn && !this.options.allowReturnOutsideFunction) {
  12999. this.raise(Errors.IllegalReturn, {
  13000. at: this.state.startLoc
  13001. });
  13002. }
  13003. this.next();
  13004. if (this.isLineTerminator()) {
  13005. node.argument = null;
  13006. } else {
  13007. node.argument = this.parseExpression();
  13008. this.semicolon();
  13009. }
  13010. return this.finishNode(node, "ReturnStatement");
  13011. }
  13012. parseSwitchStatement(node) {
  13013. this.next();
  13014. node.discriminant = this.parseHeaderExpression();
  13015. const cases = node.cases = [];
  13016. this.expect(5);
  13017. this.state.labels.push(switchLabel);
  13018. this.scope.enter(0);
  13019. let cur;
  13020. for (let sawDefault; !this.match(8);) {
  13021. if (this.match(61) || this.match(65)) {
  13022. const isCase = this.match(61);
  13023. if (cur) this.finishNode(cur, "SwitchCase");
  13024. cases.push(cur = this.startNode());
  13025. cur.consequent = [];
  13026. this.next();
  13027. if (isCase) {
  13028. cur.test = this.parseExpression();
  13029. } else {
  13030. if (sawDefault) {
  13031. this.raise(Errors.MultipleDefaultsInSwitch, {
  13032. at: this.state.lastTokStartLoc
  13033. });
  13034. }
  13035. sawDefault = true;
  13036. cur.test = null;
  13037. }
  13038. this.expect(14);
  13039. } else {
  13040. if (cur) {
  13041. cur.consequent.push(this.parseStatementListItem());
  13042. } else {
  13043. this.unexpected();
  13044. }
  13045. }
  13046. }
  13047. this.scope.exit();
  13048. if (cur) this.finishNode(cur, "SwitchCase");
  13049. this.next();
  13050. this.state.labels.pop();
  13051. return this.finishNode(node, "SwitchStatement");
  13052. }
  13053. parseThrowStatement(node) {
  13054. this.next();
  13055. if (this.hasPrecedingLineBreak()) {
  13056. this.raise(Errors.NewlineAfterThrow, {
  13057. at: this.state.lastTokEndLoc
  13058. });
  13059. }
  13060. node.argument = this.parseExpression();
  13061. this.semicolon();
  13062. return this.finishNode(node, "ThrowStatement");
  13063. }
  13064. parseCatchClauseParam() {
  13065. const param = this.parseBindingAtom();
  13066. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  13067. this.checkLVal(param, {
  13068. in: {
  13069. type: "CatchClause"
  13070. },
  13071. binding: 9
  13072. });
  13073. return param;
  13074. }
  13075. parseTryStatement(node) {
  13076. this.next();
  13077. node.block = this.parseBlock();
  13078. node.handler = null;
  13079. if (this.match(62)) {
  13080. const clause = this.startNode();
  13081. this.next();
  13082. if (this.match(10)) {
  13083. this.expect(10);
  13084. clause.param = this.parseCatchClauseParam();
  13085. this.expect(11);
  13086. } else {
  13087. clause.param = null;
  13088. this.scope.enter(0);
  13089. }
  13090. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  13091. this.scope.exit();
  13092. node.handler = this.finishNode(clause, "CatchClause");
  13093. }
  13094. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  13095. if (!node.handler && !node.finalizer) {
  13096. this.raise(Errors.NoCatchOrFinally, {
  13097. at: node
  13098. });
  13099. }
  13100. return this.finishNode(node, "TryStatement");
  13101. }
  13102. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13103. this.next();
  13104. this.parseVar(node, false, kind, allowMissingInitializer);
  13105. this.semicolon();
  13106. return this.finishNode(node, "VariableDeclaration");
  13107. }
  13108. parseWhileStatement(node) {
  13109. this.next();
  13110. node.test = this.parseHeaderExpression();
  13111. this.state.labels.push(loopLabel);
  13112. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13113. this.state.labels.pop();
  13114. return this.finishNode(node, "WhileStatement");
  13115. }
  13116. parseWithStatement(node) {
  13117. if (this.state.strict) {
  13118. this.raise(Errors.StrictWith, {
  13119. at: this.state.startLoc
  13120. });
  13121. }
  13122. this.next();
  13123. node.object = this.parseHeaderExpression();
  13124. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13125. return this.finishNode(node, "WithStatement");
  13126. }
  13127. parseEmptyStatement(node) {
  13128. this.next();
  13129. return this.finishNode(node, "EmptyStatement");
  13130. }
  13131. parseLabeledStatement(node, maybeName, expr, flags) {
  13132. for (const label of this.state.labels) {
  13133. if (label.name === maybeName) {
  13134. this.raise(Errors.LabelRedeclaration, {
  13135. at: expr,
  13136. labelName: maybeName
  13137. });
  13138. }
  13139. }
  13140. const kind = tokenIsLoop(this.state.type) ? "loop" : this.match(71) ? "switch" : null;
  13141. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  13142. const label = this.state.labels[i];
  13143. if (label.statementStart === node.start) {
  13144. label.statementStart = this.state.start;
  13145. label.kind = kind;
  13146. } else {
  13147. break;
  13148. }
  13149. }
  13150. this.state.labels.push({
  13151. name: maybeName,
  13152. kind: kind,
  13153. statementStart: this.state.start
  13154. });
  13155. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  13156. this.state.labels.pop();
  13157. node.label = expr;
  13158. return this.finishNode(node, "LabeledStatement");
  13159. }
  13160. parseExpressionStatement(node, expr, decorators) {
  13161. node.expression = expr;
  13162. this.semicolon();
  13163. return this.finishNode(node, "ExpressionStatement");
  13164. }
  13165. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  13166. const node = this.startNode();
  13167. if (allowDirectives) {
  13168. this.state.strictErrors.clear();
  13169. }
  13170. this.expect(5);
  13171. if (createNewLexicalScope) {
  13172. this.scope.enter(0);
  13173. }
  13174. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  13175. if (createNewLexicalScope) {
  13176. this.scope.exit();
  13177. }
  13178. return this.finishNode(node, "BlockStatement");
  13179. }
  13180. isValidDirective(stmt) {
  13181. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  13182. }
  13183. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  13184. const body = node.body = [];
  13185. const directives = node.directives = [];
  13186. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  13187. }
  13188. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  13189. const oldStrict = this.state.strict;
  13190. let hasStrictModeDirective = false;
  13191. let parsedNonDirective = false;
  13192. while (!this.match(end)) {
  13193. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  13194. if (directives && !parsedNonDirective) {
  13195. if (this.isValidDirective(stmt)) {
  13196. const directive = this.stmtToDirective(stmt);
  13197. directives.push(directive);
  13198. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  13199. hasStrictModeDirective = true;
  13200. this.setStrict(true);
  13201. }
  13202. continue;
  13203. }
  13204. parsedNonDirective = true;
  13205. this.state.strictErrors.clear();
  13206. }
  13207. body.push(stmt);
  13208. }
  13209. afterBlockParse == null ? void 0 : afterBlockParse.call(this, hasStrictModeDirective);
  13210. if (!oldStrict) {
  13211. this.setStrict(false);
  13212. }
  13213. this.next();
  13214. }
  13215. parseFor(node, init) {
  13216. node.init = init;
  13217. this.semicolon(false);
  13218. node.test = this.match(13) ? null : this.parseExpression();
  13219. this.semicolon(false);
  13220. node.update = this.match(11) ? null : this.parseExpression();
  13221. this.expect(11);
  13222. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13223. this.scope.exit();
  13224. this.state.labels.pop();
  13225. return this.finishNode(node, "ForStatement");
  13226. }
  13227. parseForIn(node, init, awaitAt) {
  13228. const isForIn = this.match(58);
  13229. this.next();
  13230. if (isForIn) {
  13231. if (awaitAt !== null) this.unexpected(awaitAt);
  13232. } else {
  13233. node.await = awaitAt !== null;
  13234. }
  13235. 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")) {
  13236. this.raise(Errors.ForInOfLoopInitializer, {
  13237. at: init,
  13238. type: isForIn ? "ForInStatement" : "ForOfStatement"
  13239. });
  13240. }
  13241. if (init.type === "AssignmentPattern") {
  13242. this.raise(Errors.InvalidLhs, {
  13243. at: init,
  13244. ancestor: {
  13245. type: "ForStatement"
  13246. }
  13247. });
  13248. }
  13249. node.left = init;
  13250. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  13251. this.expect(11);
  13252. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  13253. this.scope.exit();
  13254. this.state.labels.pop();
  13255. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  13256. }
  13257. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  13258. const declarations = node.declarations = [];
  13259. node.kind = kind;
  13260. for (;;) {
  13261. const decl = this.startNode();
  13262. this.parseVarId(decl, kind);
  13263. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  13264. if (decl.init === null && !allowMissingInitializer) {
  13265. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  13266. this.raise(Errors.DeclarationMissingInitializer, {
  13267. at: this.state.lastTokEndLoc,
  13268. kind: "destructuring"
  13269. });
  13270. } else if (kind === "const" && !(this.match(58) || this.isContextual(102))) {
  13271. this.raise(Errors.DeclarationMissingInitializer, {
  13272. at: this.state.lastTokEndLoc,
  13273. kind: "const"
  13274. });
  13275. }
  13276. }
  13277. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  13278. if (!this.eat(12)) break;
  13279. }
  13280. return node;
  13281. }
  13282. parseVarId(decl, kind) {
  13283. const id = this.parseBindingAtom();
  13284. this.checkLVal(id, {
  13285. in: {
  13286. type: "VariableDeclarator"
  13287. },
  13288. binding: kind === "var" ? 5 : 8201
  13289. });
  13290. decl.id = id;
  13291. }
  13292. parseAsyncFunctionExpression(node) {
  13293. return this.parseFunction(node, 8);
  13294. }
  13295. parseFunction(node, flags = 0) {
  13296. const hangingDeclaration = flags & 2;
  13297. const isDeclaration = !!(flags & 1);
  13298. const requireId = isDeclaration && !(flags & 4);
  13299. const isAsync = !!(flags & 8);
  13300. this.initFunction(node, isAsync);
  13301. if (this.match(55)) {
  13302. if (hangingDeclaration) {
  13303. this.raise(Errors.GeneratorInSingleStatementContext, {
  13304. at: this.state.startLoc
  13305. });
  13306. }
  13307. this.next();
  13308. node.generator = true;
  13309. }
  13310. if (isDeclaration) {
  13311. node.id = this.parseFunctionId(requireId);
  13312. }
  13313. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13314. this.state.maybeInArrowParameters = false;
  13315. this.scope.enter(2);
  13316. this.prodParam.enter(functionFlags(isAsync, node.generator));
  13317. if (!isDeclaration) {
  13318. node.id = this.parseFunctionId();
  13319. }
  13320. this.parseFunctionParams(node, false);
  13321. this.withSmartMixTopicForbiddingContext(() => {
  13322. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  13323. });
  13324. this.prodParam.exit();
  13325. this.scope.exit();
  13326. if (isDeclaration && !hangingDeclaration) {
  13327. this.registerFunctionStatementId(node);
  13328. }
  13329. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13330. return node;
  13331. }
  13332. parseFunctionId(requireId) {
  13333. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  13334. }
  13335. parseFunctionParams(node, isConstructor) {
  13336. this.expect(10);
  13337. this.expressionScope.enter(newParameterDeclarationScope());
  13338. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  13339. this.expressionScope.exit();
  13340. }
  13341. registerFunctionStatementId(node) {
  13342. if (!node.id) return;
  13343. 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);
  13344. }
  13345. parseClass(node, isStatement, optionalId) {
  13346. this.next();
  13347. const oldStrict = this.state.strict;
  13348. this.state.strict = true;
  13349. this.parseClassId(node, isStatement, optionalId);
  13350. this.parseClassSuper(node);
  13351. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  13352. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  13353. }
  13354. isClassProperty() {
  13355. return this.match(29) || this.match(13) || this.match(8);
  13356. }
  13357. isClassMethod() {
  13358. return this.match(10);
  13359. }
  13360. isNonstaticConstructor(method) {
  13361. return !method.computed && !method.static && (method.key.name === "constructor" || method.key.value === "constructor");
  13362. }
  13363. parseClassBody(hadSuperClass, oldStrict) {
  13364. this.classScope.enter();
  13365. const state = {
  13366. hadConstructor: false,
  13367. hadSuperClass
  13368. };
  13369. let decorators = [];
  13370. const classBody = this.startNode();
  13371. classBody.body = [];
  13372. this.expect(5);
  13373. this.withSmartMixTopicForbiddingContext(() => {
  13374. while (!this.match(8)) {
  13375. if (this.eat(13)) {
  13376. if (decorators.length > 0) {
  13377. throw this.raise(Errors.DecoratorSemicolon, {
  13378. at: this.state.lastTokEndLoc
  13379. });
  13380. }
  13381. continue;
  13382. }
  13383. if (this.match(26)) {
  13384. decorators.push(this.parseDecorator());
  13385. continue;
  13386. }
  13387. const member = this.startNode();
  13388. if (decorators.length) {
  13389. member.decorators = decorators;
  13390. this.resetStartLocationFromNode(member, decorators[0]);
  13391. decorators = [];
  13392. }
  13393. this.parseClassMember(classBody, member, state);
  13394. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  13395. this.raise(Errors.DecoratorConstructor, {
  13396. at: member
  13397. });
  13398. }
  13399. }
  13400. });
  13401. this.state.strict = oldStrict;
  13402. this.next();
  13403. if (decorators.length) {
  13404. throw this.raise(Errors.TrailingDecorator, {
  13405. at: this.state.startLoc
  13406. });
  13407. }
  13408. this.classScope.exit();
  13409. return this.finishNode(classBody, "ClassBody");
  13410. }
  13411. parseClassMemberFromModifier(classBody, member) {
  13412. const key = this.parseIdentifier(true);
  13413. if (this.isClassMethod()) {
  13414. const method = member;
  13415. method.kind = "method";
  13416. method.computed = false;
  13417. method.key = key;
  13418. method.static = false;
  13419. this.pushClassMethod(classBody, method, false, false, false, false);
  13420. return true;
  13421. } else if (this.isClassProperty()) {
  13422. const prop = member;
  13423. prop.computed = false;
  13424. prop.key = key;
  13425. prop.static = false;
  13426. classBody.body.push(this.parseClassProperty(prop));
  13427. return true;
  13428. }
  13429. this.resetPreviousNodeTrailingComments(key);
  13430. return false;
  13431. }
  13432. parseClassMember(classBody, member, state) {
  13433. const isStatic = this.isContextual(106);
  13434. if (isStatic) {
  13435. if (this.parseClassMemberFromModifier(classBody, member)) {
  13436. return;
  13437. }
  13438. if (this.eat(5)) {
  13439. this.parseClassStaticBlock(classBody, member);
  13440. return;
  13441. }
  13442. }
  13443. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13444. }
  13445. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13446. const publicMethod = member;
  13447. const privateMethod = member;
  13448. const publicProp = member;
  13449. const privateProp = member;
  13450. const accessorProp = member;
  13451. const method = publicMethod;
  13452. const publicMember = publicMethod;
  13453. member.static = isStatic;
  13454. this.parsePropertyNamePrefixOperator(member);
  13455. if (this.eat(55)) {
  13456. method.kind = "method";
  13457. const isPrivateName = this.match(138);
  13458. this.parseClassElementName(method);
  13459. if (isPrivateName) {
  13460. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  13461. return;
  13462. }
  13463. if (this.isNonstaticConstructor(publicMethod)) {
  13464. this.raise(Errors.ConstructorIsGenerator, {
  13465. at: publicMethod.key
  13466. });
  13467. }
  13468. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  13469. return;
  13470. }
  13471. const isContextual = tokenIsIdentifier(this.state.type) && !this.state.containsEsc;
  13472. const isPrivate = this.match(138);
  13473. const key = this.parseClassElementName(member);
  13474. const maybeQuestionTokenStartLoc = this.state.startLoc;
  13475. this.parsePostMemberNameModifiers(publicMember);
  13476. if (this.isClassMethod()) {
  13477. method.kind = "method";
  13478. if (isPrivate) {
  13479. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13480. return;
  13481. }
  13482. const isConstructor = this.isNonstaticConstructor(publicMethod);
  13483. let allowsDirectSuper = false;
  13484. if (isConstructor) {
  13485. publicMethod.kind = "constructor";
  13486. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  13487. this.raise(Errors.DuplicateConstructor, {
  13488. at: key
  13489. });
  13490. }
  13491. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  13492. this.raise(Errors.OverrideOnConstructor, {
  13493. at: key
  13494. });
  13495. }
  13496. state.hadConstructor = true;
  13497. allowsDirectSuper = state.hadSuperClass;
  13498. }
  13499. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  13500. } else if (this.isClassProperty()) {
  13501. if (isPrivate) {
  13502. this.pushClassPrivateProperty(classBody, privateProp);
  13503. } else {
  13504. this.pushClassProperty(classBody, publicProp);
  13505. }
  13506. } else if (isContextual && key.name === "async" && !this.isLineTerminator()) {
  13507. this.resetPreviousNodeTrailingComments(key);
  13508. const isGenerator = this.eat(55);
  13509. if (publicMember.optional) {
  13510. this.unexpected(maybeQuestionTokenStartLoc);
  13511. }
  13512. method.kind = "method";
  13513. const isPrivate = this.match(138);
  13514. this.parseClassElementName(method);
  13515. this.parsePostMemberNameModifiers(publicMember);
  13516. if (isPrivate) {
  13517. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  13518. } else {
  13519. if (this.isNonstaticConstructor(publicMethod)) {
  13520. this.raise(Errors.ConstructorIsAsync, {
  13521. at: publicMethod.key
  13522. });
  13523. }
  13524. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  13525. }
  13526. } else if (isContextual && (key.name === "get" || key.name === "set") && !(this.match(55) && this.isLineTerminator())) {
  13527. this.resetPreviousNodeTrailingComments(key);
  13528. method.kind = key.name;
  13529. const isPrivate = this.match(138);
  13530. this.parseClassElementName(publicMethod);
  13531. if (isPrivate) {
  13532. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  13533. } else {
  13534. if (this.isNonstaticConstructor(publicMethod)) {
  13535. this.raise(Errors.ConstructorIsAccessor, {
  13536. at: publicMethod.key
  13537. });
  13538. }
  13539. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  13540. }
  13541. this.checkGetterSetterParams(publicMethod);
  13542. } else if (isContextual && key.name === "accessor" && !this.isLineTerminator()) {
  13543. this.expectPlugin("decoratorAutoAccessors");
  13544. this.resetPreviousNodeTrailingComments(key);
  13545. const isPrivate = this.match(138);
  13546. this.parseClassElementName(publicProp);
  13547. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  13548. } else if (this.isLineTerminator()) {
  13549. if (isPrivate) {
  13550. this.pushClassPrivateProperty(classBody, privateProp);
  13551. } else {
  13552. this.pushClassProperty(classBody, publicProp);
  13553. }
  13554. } else {
  13555. this.unexpected();
  13556. }
  13557. }
  13558. parseClassElementName(member) {
  13559. const {
  13560. type,
  13561. value
  13562. } = this.state;
  13563. if ((type === 132 || type === 133) && member.static && value === "prototype") {
  13564. this.raise(Errors.StaticPrototype, {
  13565. at: this.state.startLoc
  13566. });
  13567. }
  13568. if (type === 138) {
  13569. if (value === "constructor") {
  13570. this.raise(Errors.ConstructorClassPrivateField, {
  13571. at: this.state.startLoc
  13572. });
  13573. }
  13574. const key = this.parsePrivateName();
  13575. member.key = key;
  13576. return key;
  13577. }
  13578. return this.parsePropertyName(member);
  13579. }
  13580. parseClassStaticBlock(classBody, member) {
  13581. var _member$decorators;
  13582. this.scope.enter(64 | 128 | 16);
  13583. const oldLabels = this.state.labels;
  13584. this.state.labels = [];
  13585. this.prodParam.enter(PARAM);
  13586. const body = member.body = [];
  13587. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  13588. this.prodParam.exit();
  13589. this.scope.exit();
  13590. this.state.labels = oldLabels;
  13591. classBody.body.push(this.finishNode(member, "StaticBlock"));
  13592. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  13593. this.raise(Errors.DecoratorStaticBlock, {
  13594. at: member
  13595. });
  13596. }
  13597. }
  13598. pushClassProperty(classBody, prop) {
  13599. if (!prop.computed && (prop.key.name === "constructor" || prop.key.value === "constructor")) {
  13600. this.raise(Errors.ConstructorClassField, {
  13601. at: prop.key
  13602. });
  13603. }
  13604. classBody.body.push(this.parseClassProperty(prop));
  13605. }
  13606. pushClassPrivateProperty(classBody, prop) {
  13607. const node = this.parseClassPrivateProperty(prop);
  13608. classBody.body.push(node);
  13609. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13610. }
  13611. pushClassAccessorProperty(classBody, prop, isPrivate) {
  13612. if (!isPrivate && !prop.computed) {
  13613. const key = prop.key;
  13614. if (key.name === "constructor" || key.value === "constructor") {
  13615. this.raise(Errors.ConstructorClassField, {
  13616. at: key
  13617. });
  13618. }
  13619. }
  13620. const node = this.parseClassAccessorProperty(prop);
  13621. classBody.body.push(node);
  13622. if (isPrivate) {
  13623. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  13624. }
  13625. }
  13626. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13627. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  13628. }
  13629. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13630. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  13631. classBody.body.push(node);
  13632. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  13633. this.declareClassPrivateMethodInScope(node, kind);
  13634. }
  13635. declareClassPrivateMethodInScope(node, kind) {
  13636. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  13637. }
  13638. parsePostMemberNameModifiers(methodOrProp) {}
  13639. parseClassPrivateProperty(node) {
  13640. this.parseInitializer(node);
  13641. this.semicolon();
  13642. return this.finishNode(node, "ClassPrivateProperty");
  13643. }
  13644. parseClassProperty(node) {
  13645. this.parseInitializer(node);
  13646. this.semicolon();
  13647. return this.finishNode(node, "ClassProperty");
  13648. }
  13649. parseClassAccessorProperty(node) {
  13650. this.parseInitializer(node);
  13651. this.semicolon();
  13652. return this.finishNode(node, "ClassAccessorProperty");
  13653. }
  13654. parseInitializer(node) {
  13655. this.scope.enter(64 | 16);
  13656. this.expressionScope.enter(newExpressionScope());
  13657. this.prodParam.enter(PARAM);
  13658. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  13659. this.expressionScope.exit();
  13660. this.prodParam.exit();
  13661. this.scope.exit();
  13662. }
  13663. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  13664. if (tokenIsIdentifier(this.state.type)) {
  13665. node.id = this.parseIdentifier();
  13666. if (isStatement) {
  13667. this.declareNameFromIdentifier(node.id, bindingType);
  13668. }
  13669. } else {
  13670. if (optionalId || !isStatement) {
  13671. node.id = null;
  13672. } else {
  13673. throw this.raise(Errors.MissingClassName, {
  13674. at: this.state.startLoc
  13675. });
  13676. }
  13677. }
  13678. }
  13679. parseClassSuper(node) {
  13680. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  13681. }
  13682. parseExport(node, decorators) {
  13683. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  13684. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  13685. const parseAfterDefault = !hasDefault || this.eat(12);
  13686. const hasStar = parseAfterDefault && this.eatExportStar(node);
  13687. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  13688. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  13689. const isFromRequired = hasDefault || hasStar;
  13690. if (hasStar && !hasNamespace) {
  13691. if (hasDefault) this.unexpected();
  13692. if (decorators) {
  13693. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13694. at: node
  13695. });
  13696. }
  13697. this.parseExportFrom(node, true);
  13698. return this.finishNode(node, "ExportAllDeclaration");
  13699. }
  13700. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  13701. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  13702. this.unexpected(null, 5);
  13703. }
  13704. if (hasNamespace && parseAfterNamespace) {
  13705. this.unexpected(null, 98);
  13706. }
  13707. let hasDeclaration;
  13708. if (isFromRequired || hasSpecifiers) {
  13709. hasDeclaration = false;
  13710. if (decorators) {
  13711. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13712. at: node
  13713. });
  13714. }
  13715. this.parseExportFrom(node, isFromRequired);
  13716. } else {
  13717. hasDeclaration = this.maybeParseExportDeclaration(node);
  13718. }
  13719. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  13720. var _node2$declaration;
  13721. const node2 = node;
  13722. this.checkExport(node2, true, false, !!node2.source);
  13723. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  13724. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  13725. } else if (decorators) {
  13726. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13727. at: node
  13728. });
  13729. }
  13730. return this.finishNode(node2, "ExportNamedDeclaration");
  13731. }
  13732. if (this.eat(65)) {
  13733. const node2 = node;
  13734. const decl = this.parseExportDefaultExpression();
  13735. node2.declaration = decl;
  13736. if (decl.type === "ClassDeclaration") {
  13737. this.maybeTakeDecorators(decorators, decl, node2);
  13738. } else if (decorators) {
  13739. throw this.raise(Errors.UnsupportedDecoratorExport, {
  13740. at: node
  13741. });
  13742. }
  13743. this.checkExport(node2, true, true);
  13744. return this.finishNode(node2, "ExportDefaultDeclaration");
  13745. }
  13746. this.unexpected(null, 5);
  13747. }
  13748. eatExportStar(node) {
  13749. return this.eat(55);
  13750. }
  13751. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  13752. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  13753. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  13754. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  13755. const specifier = this.startNodeAtNode(id);
  13756. specifier.exported = id;
  13757. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  13758. return true;
  13759. }
  13760. return false;
  13761. }
  13762. maybeParseExportNamespaceSpecifier(node) {
  13763. if (this.isContextual(93)) {
  13764. if (!node.specifiers) node.specifiers = [];
  13765. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  13766. this.next();
  13767. specifier.exported = this.parseModuleExportName();
  13768. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  13769. return true;
  13770. }
  13771. return false;
  13772. }
  13773. maybeParseExportNamedSpecifiers(node) {
  13774. if (this.match(5)) {
  13775. if (!node.specifiers) node.specifiers = [];
  13776. const isTypeExport = node.exportKind === "type";
  13777. node.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  13778. node.source = null;
  13779. node.declaration = null;
  13780. if (this.hasPlugin("importAssertions")) {
  13781. node.assertions = [];
  13782. }
  13783. return true;
  13784. }
  13785. return false;
  13786. }
  13787. maybeParseExportDeclaration(node) {
  13788. if (this.shouldParseExportDeclaration()) {
  13789. node.specifiers = [];
  13790. node.source = null;
  13791. if (this.hasPlugin("importAssertions")) {
  13792. node.assertions = [];
  13793. }
  13794. node.declaration = this.parseExportDeclaration(node);
  13795. return true;
  13796. }
  13797. return false;
  13798. }
  13799. isAsyncFunction() {
  13800. if (!this.isContextual(95)) return false;
  13801. const next = this.nextTokenInLineStart();
  13802. return this.isUnparsedContextual(next, "function");
  13803. }
  13804. parseExportDefaultExpression() {
  13805. const expr = this.startNode();
  13806. if (this.match(68)) {
  13807. this.next();
  13808. return this.parseFunction(expr, 1 | 4);
  13809. } else if (this.isAsyncFunction()) {
  13810. this.next();
  13811. this.next();
  13812. return this.parseFunction(expr, 1 | 4 | 8);
  13813. }
  13814. if (this.match(80)) {
  13815. return this.parseClass(expr, true, true);
  13816. }
  13817. if (this.match(26)) {
  13818. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13819. this.raise(Errors.DecoratorBeforeExport, {
  13820. at: this.state.startLoc
  13821. });
  13822. }
  13823. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  13824. }
  13825. if (this.match(75) || this.match(74) || this.isLet()) {
  13826. throw this.raise(Errors.UnsupportedDefaultExport, {
  13827. at: this.state.startLoc
  13828. });
  13829. }
  13830. const res = this.parseMaybeAssignAllowIn();
  13831. this.semicolon();
  13832. return res;
  13833. }
  13834. parseExportDeclaration(node) {
  13835. if (this.match(80)) {
  13836. const node = this.parseClass(this.startNode(), true, false);
  13837. return node;
  13838. }
  13839. return this.parseStatementListItem();
  13840. }
  13841. isExportDefaultSpecifier() {
  13842. const {
  13843. type
  13844. } = this.state;
  13845. if (tokenIsIdentifier(type)) {
  13846. if (type === 95 && !this.state.containsEsc || type === 100) {
  13847. return false;
  13848. }
  13849. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  13850. const {
  13851. type: nextType
  13852. } = this.lookahead();
  13853. if (tokenIsIdentifier(nextType) && nextType !== 98 || nextType === 5) {
  13854. this.expectOnePlugin(["flow", "typescript"]);
  13855. return false;
  13856. }
  13857. }
  13858. } else if (!this.match(65)) {
  13859. return false;
  13860. }
  13861. const next = this.nextTokenStart();
  13862. const hasFrom = this.isUnparsedContextual(next, "from");
  13863. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  13864. return true;
  13865. }
  13866. if (this.match(65) && hasFrom) {
  13867. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  13868. return nextAfterFrom === 34 || nextAfterFrom === 39;
  13869. }
  13870. return false;
  13871. }
  13872. parseExportFrom(node, expect) {
  13873. if (this.eatContextual(98)) {
  13874. node.source = this.parseImportSource();
  13875. this.checkExport(node);
  13876. this.maybeParseImportAttributes(node);
  13877. this.checkJSONModuleImport(node);
  13878. } else if (expect) {
  13879. this.unexpected();
  13880. }
  13881. this.semicolon();
  13882. }
  13883. shouldParseExportDeclaration() {
  13884. const {
  13885. type
  13886. } = this.state;
  13887. if (type === 26) {
  13888. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  13889. if (this.hasPlugin("decorators")) {
  13890. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  13891. this.raise(Errors.DecoratorBeforeExport, {
  13892. at: this.state.startLoc
  13893. });
  13894. }
  13895. return true;
  13896. }
  13897. }
  13898. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  13899. }
  13900. checkExport(node, checkNames, isDefault, isFrom) {
  13901. if (checkNames) {
  13902. var _node$specifiers;
  13903. if (isDefault) {
  13904. this.checkDuplicateExports(node, "default");
  13905. if (this.hasPlugin("exportDefaultFrom")) {
  13906. var _declaration$extra;
  13907. const declaration = node.declaration;
  13908. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  13909. this.raise(Errors.ExportDefaultFromAsIdentifier, {
  13910. at: declaration
  13911. });
  13912. }
  13913. }
  13914. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  13915. for (const specifier of node.specifiers) {
  13916. const {
  13917. exported
  13918. } = specifier;
  13919. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  13920. this.checkDuplicateExports(specifier, exportName);
  13921. if (!isFrom && specifier.local) {
  13922. const {
  13923. local
  13924. } = specifier;
  13925. if (local.type !== "Identifier") {
  13926. this.raise(Errors.ExportBindingIsString, {
  13927. at: specifier,
  13928. localName: local.value,
  13929. exportName
  13930. });
  13931. } else {
  13932. this.checkReservedWord(local.name, local.loc.start, true, false);
  13933. this.scope.checkLocalExport(local);
  13934. }
  13935. }
  13936. }
  13937. } else if (node.declaration) {
  13938. if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
  13939. const id = node.declaration.id;
  13940. if (!id) throw new Error("Assertion failure");
  13941. this.checkDuplicateExports(node, id.name);
  13942. } else if (node.declaration.type === "VariableDeclaration") {
  13943. for (const declaration of node.declaration.declarations) {
  13944. this.checkDeclaration(declaration.id);
  13945. }
  13946. }
  13947. }
  13948. }
  13949. }
  13950. checkDeclaration(node) {
  13951. if (node.type === "Identifier") {
  13952. this.checkDuplicateExports(node, node.name);
  13953. } else if (node.type === "ObjectPattern") {
  13954. for (const prop of node.properties) {
  13955. this.checkDeclaration(prop);
  13956. }
  13957. } else if (node.type === "ArrayPattern") {
  13958. for (const elem of node.elements) {
  13959. if (elem) {
  13960. this.checkDeclaration(elem);
  13961. }
  13962. }
  13963. } else if (node.type === "ObjectProperty") {
  13964. this.checkDeclaration(node.value);
  13965. } else if (node.type === "RestElement") {
  13966. this.checkDeclaration(node.argument);
  13967. } else if (node.type === "AssignmentPattern") {
  13968. this.checkDeclaration(node.left);
  13969. }
  13970. }
  13971. checkDuplicateExports(node, exportName) {
  13972. if (this.exportedIdentifiers.has(exportName)) {
  13973. if (exportName === "default") {
  13974. this.raise(Errors.DuplicateDefaultExport, {
  13975. at: node
  13976. });
  13977. } else {
  13978. this.raise(Errors.DuplicateExport, {
  13979. at: node,
  13980. exportName
  13981. });
  13982. }
  13983. }
  13984. this.exportedIdentifiers.add(exportName);
  13985. }
  13986. parseExportSpecifiers(isInTypeExport) {
  13987. const nodes = [];
  13988. let first = true;
  13989. this.expect(5);
  13990. while (!this.eat(8)) {
  13991. if (first) {
  13992. first = false;
  13993. } else {
  13994. this.expect(12);
  13995. if (this.eat(8)) break;
  13996. }
  13997. const isMaybeTypeOnly = this.isContextual(130);
  13998. const isString = this.match(133);
  13999. const node = this.startNode();
  14000. node.local = this.parseModuleExportName();
  14001. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  14002. }
  14003. return nodes;
  14004. }
  14005. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14006. if (this.eatContextual(93)) {
  14007. node.exported = this.parseModuleExportName();
  14008. } else if (isString) {
  14009. node.exported = cloneStringLiteral(node.local);
  14010. } else if (!node.exported) {
  14011. node.exported = cloneIdentifier(node.local);
  14012. }
  14013. return this.finishNode(node, "ExportSpecifier");
  14014. }
  14015. parseModuleExportName() {
  14016. if (this.match(133)) {
  14017. const result = this.parseStringLiteral(this.state.value);
  14018. const surrogate = result.value.match(loneSurrogate);
  14019. if (surrogate) {
  14020. this.raise(Errors.ModuleExportNameHasLoneSurrogate, {
  14021. at: result,
  14022. surrogateCharCode: surrogate[0].charCodeAt(0)
  14023. });
  14024. }
  14025. return result;
  14026. }
  14027. return this.parseIdentifier(true);
  14028. }
  14029. isJSONModuleImport(node) {
  14030. if (node.assertions != null) {
  14031. return node.assertions.some(({
  14032. key,
  14033. value
  14034. }) => {
  14035. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  14036. });
  14037. }
  14038. return false;
  14039. }
  14040. checkImportReflection(node) {
  14041. const {
  14042. specifiers
  14043. } = node;
  14044. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  14045. if (node.phase === "source") {
  14046. if (singleBindingType !== "ImportDefaultSpecifier") {
  14047. this.raise(Errors.SourcePhaseImportRequiresDefault, {
  14048. at: specifiers[0].loc.start
  14049. });
  14050. }
  14051. } else if (node.phase === "defer") {
  14052. if (singleBindingType !== "ImportNamespaceSpecifier") {
  14053. this.raise(Errors.DeferImportRequiresNamespace, {
  14054. at: specifiers[0].loc.start
  14055. });
  14056. }
  14057. } else if (node.module) {
  14058. var _node$assertions;
  14059. if (singleBindingType !== "ImportDefaultSpecifier") {
  14060. this.raise(Errors.ImportReflectionNotBinding, {
  14061. at: specifiers[0].loc.start
  14062. });
  14063. }
  14064. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  14065. this.raise(Errors.ImportReflectionHasAssertion, {
  14066. at: node.specifiers[0].loc.start
  14067. });
  14068. }
  14069. }
  14070. }
  14071. checkJSONModuleImport(node) {
  14072. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  14073. const {
  14074. specifiers
  14075. } = node;
  14076. if (specifiers != null) {
  14077. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  14078. let imported;
  14079. if (specifier.type === "ExportSpecifier") {
  14080. imported = specifier.local;
  14081. } else if (specifier.type === "ImportSpecifier") {
  14082. imported = specifier.imported;
  14083. }
  14084. if (imported !== undefined) {
  14085. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  14086. }
  14087. });
  14088. if (nonDefaultNamedSpecifier !== undefined) {
  14089. this.raise(Errors.ImportJSONBindingNotDefault, {
  14090. at: nonDefaultNamedSpecifier.loc.start
  14091. });
  14092. }
  14093. }
  14094. }
  14095. }
  14096. isPotentialImportPhase(isExport) {
  14097. if (isExport) return false;
  14098. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  14099. }
  14100. applyImportPhase(node, isExport, phase, loc) {
  14101. if (isExport) {
  14102. return;
  14103. }
  14104. if (phase === "module") {
  14105. this.expectPlugin("importReflection", loc);
  14106. node.module = true;
  14107. } else if (this.hasPlugin("importReflection")) {
  14108. node.module = false;
  14109. }
  14110. if (phase === "source") {
  14111. this.expectPlugin("sourcePhaseImports", loc);
  14112. node.phase = "source";
  14113. } else if (phase === "defer") {
  14114. this.expectPlugin("deferredImportEvaluation", loc);
  14115. node.phase = "defer";
  14116. } else if (this.hasPlugin("sourcePhaseImports")) {
  14117. node.phase = null;
  14118. }
  14119. }
  14120. parseMaybeImportPhase(node, isExport) {
  14121. if (!this.isPotentialImportPhase(isExport)) {
  14122. this.applyImportPhase(node, isExport, null);
  14123. return null;
  14124. }
  14125. const phaseIdentifier = this.parseIdentifier(true);
  14126. const {
  14127. type
  14128. } = this.state;
  14129. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14130. if (isImportPhase) {
  14131. this.resetPreviousIdentifierLeadingComments(phaseIdentifier);
  14132. this.applyImportPhase(node, isExport, phaseIdentifier.name, phaseIdentifier.loc.start);
  14133. return null;
  14134. } else {
  14135. this.applyImportPhase(node, isExport, null);
  14136. return phaseIdentifier;
  14137. }
  14138. }
  14139. isPrecedingIdImportPhase(phase) {
  14140. const {
  14141. type
  14142. } = this.state;
  14143. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  14144. }
  14145. parseImport(node) {
  14146. if (this.match(133)) {
  14147. return this.parseImportSourceAndAttributes(node);
  14148. }
  14149. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  14150. }
  14151. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  14152. node.specifiers = [];
  14153. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  14154. const parseNext = !hasDefault || this.eat(12);
  14155. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  14156. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  14157. this.expectContextual(98);
  14158. return this.parseImportSourceAndAttributes(node);
  14159. }
  14160. parseImportSourceAndAttributes(node) {
  14161. var _node$specifiers2;
  14162. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  14163. node.source = this.parseImportSource();
  14164. this.maybeParseImportAttributes(node);
  14165. this.checkImportReflection(node);
  14166. this.checkJSONModuleImport(node);
  14167. this.semicolon();
  14168. return this.finishNode(node, "ImportDeclaration");
  14169. }
  14170. parseImportSource() {
  14171. if (!this.match(133)) this.unexpected();
  14172. return this.parseExprAtom();
  14173. }
  14174. parseImportSpecifierLocal(node, specifier, type) {
  14175. specifier.local = this.parseIdentifier();
  14176. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  14177. }
  14178. finishImportSpecifier(specifier, type, bindingType = 8201) {
  14179. this.checkLVal(specifier.local, {
  14180. in: {
  14181. type
  14182. },
  14183. binding: bindingType
  14184. });
  14185. return this.finishNode(specifier, type);
  14186. }
  14187. parseImportAttributes() {
  14188. this.expect(5);
  14189. const attrs = [];
  14190. const attrNames = new Set();
  14191. do {
  14192. if (this.match(8)) {
  14193. break;
  14194. }
  14195. const node = this.startNode();
  14196. const keyName = this.state.value;
  14197. if (attrNames.has(keyName)) {
  14198. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14199. at: this.state.startLoc,
  14200. key: keyName
  14201. });
  14202. }
  14203. attrNames.add(keyName);
  14204. if (this.match(133)) {
  14205. node.key = this.parseStringLiteral(keyName);
  14206. } else {
  14207. node.key = this.parseIdentifier(true);
  14208. }
  14209. this.expect(14);
  14210. if (!this.match(133)) {
  14211. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14212. at: this.state.startLoc
  14213. });
  14214. }
  14215. node.value = this.parseStringLiteral(this.state.value);
  14216. attrs.push(this.finishNode(node, "ImportAttribute"));
  14217. } while (this.eat(12));
  14218. this.expect(8);
  14219. return attrs;
  14220. }
  14221. parseModuleAttributes() {
  14222. const attrs = [];
  14223. const attributes = new Set();
  14224. do {
  14225. const node = this.startNode();
  14226. node.key = this.parseIdentifier(true);
  14227. if (node.key.name !== "type") {
  14228. this.raise(Errors.ModuleAttributeDifferentFromType, {
  14229. at: node.key
  14230. });
  14231. }
  14232. if (attributes.has(node.key.name)) {
  14233. this.raise(Errors.ModuleAttributesWithDuplicateKeys, {
  14234. at: node.key,
  14235. key: node.key.name
  14236. });
  14237. }
  14238. attributes.add(node.key.name);
  14239. this.expect(14);
  14240. if (!this.match(133)) {
  14241. throw this.raise(Errors.ModuleAttributeInvalidValue, {
  14242. at: this.state.startLoc
  14243. });
  14244. }
  14245. node.value = this.parseStringLiteral(this.state.value);
  14246. attrs.push(this.finishNode(node, "ImportAttribute"));
  14247. } while (this.eat(12));
  14248. return attrs;
  14249. }
  14250. maybeParseImportAttributes(node) {
  14251. let attributes;
  14252. let useWith = false;
  14253. if (this.match(76)) {
  14254. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  14255. return;
  14256. }
  14257. this.next();
  14258. {
  14259. if (this.hasPlugin("moduleAttributes")) {
  14260. attributes = this.parseModuleAttributes();
  14261. } else {
  14262. this.expectImportAttributesPlugin();
  14263. attributes = this.parseImportAttributes();
  14264. }
  14265. }
  14266. useWith = true;
  14267. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  14268. if (this.hasPlugin("importAttributes")) {
  14269. if (this.getPluginOption("importAttributes", "deprecatedAssertSyntax") !== true) {
  14270. this.raise(Errors.ImportAttributesUseAssert, {
  14271. at: this.state.startLoc
  14272. });
  14273. }
  14274. this.addExtra(node, "deprecatedAssertSyntax", true);
  14275. } else {
  14276. this.expectOnePlugin(["importAttributes", "importAssertions"]);
  14277. }
  14278. this.next();
  14279. attributes = this.parseImportAttributes();
  14280. } else if (this.hasPlugin("importAttributes") || this.hasPlugin("importAssertions")) {
  14281. attributes = [];
  14282. } else {
  14283. if (this.hasPlugin("moduleAttributes")) {
  14284. attributes = [];
  14285. } else return;
  14286. }
  14287. if (!useWith && this.hasPlugin("importAssertions")) {
  14288. node.assertions = attributes;
  14289. } else {
  14290. node.attributes = attributes;
  14291. }
  14292. }
  14293. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  14294. if (maybeDefaultIdentifier) {
  14295. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  14296. specifier.local = maybeDefaultIdentifier;
  14297. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  14298. return true;
  14299. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14300. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  14301. return true;
  14302. }
  14303. return false;
  14304. }
  14305. maybeParseStarImportSpecifier(node) {
  14306. if (this.match(55)) {
  14307. const specifier = this.startNode();
  14308. this.next();
  14309. this.expectContextual(93);
  14310. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  14311. return true;
  14312. }
  14313. return false;
  14314. }
  14315. parseNamedImportSpecifiers(node) {
  14316. let first = true;
  14317. this.expect(5);
  14318. while (!this.eat(8)) {
  14319. if (first) {
  14320. first = false;
  14321. } else {
  14322. if (this.eat(14)) {
  14323. throw this.raise(Errors.DestructureNamedImport, {
  14324. at: this.state.startLoc
  14325. });
  14326. }
  14327. this.expect(12);
  14328. if (this.eat(8)) break;
  14329. }
  14330. const specifier = this.startNode();
  14331. const importedIsString = this.match(133);
  14332. const isMaybeTypeOnly = this.isContextual(130);
  14333. specifier.imported = this.parseModuleExportName();
  14334. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  14335. node.specifiers.push(importSpecifier);
  14336. }
  14337. }
  14338. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14339. if (this.eatContextual(93)) {
  14340. specifier.local = this.parseIdentifier();
  14341. } else {
  14342. const {
  14343. imported
  14344. } = specifier;
  14345. if (importedIsString) {
  14346. throw this.raise(Errors.ImportBindingIsString, {
  14347. at: specifier,
  14348. importName: imported.value
  14349. });
  14350. }
  14351. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  14352. if (!specifier.local) {
  14353. specifier.local = cloneIdentifier(imported);
  14354. }
  14355. }
  14356. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  14357. }
  14358. isThisParam(param) {
  14359. return param.type === "Identifier" && param.name === "this";
  14360. }
  14361. }
  14362. class Parser extends StatementParser {
  14363. constructor(options, input) {
  14364. options = getOptions(options);
  14365. super(options, input);
  14366. this.options = options;
  14367. this.initializeScopes();
  14368. this.plugins = pluginsMap(this.options.plugins);
  14369. this.filename = options.sourceFilename;
  14370. }
  14371. getScopeHandler() {
  14372. return ScopeHandler;
  14373. }
  14374. parse() {
  14375. this.enterInitialScopes();
  14376. const file = this.startNode();
  14377. const program = this.startNode();
  14378. this.nextToken();
  14379. file.errors = null;
  14380. this.parseTopLevel(file, program);
  14381. file.errors = this.state.errors;
  14382. return file;
  14383. }
  14384. }
  14385. function pluginsMap(plugins) {
  14386. const pluginMap = new Map();
  14387. for (const plugin of plugins) {
  14388. const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
  14389. if (!pluginMap.has(name)) pluginMap.set(name, options || {});
  14390. }
  14391. return pluginMap;
  14392. }
  14393. function parse(input, options) {
  14394. var _options;
  14395. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  14396. options = Object.assign({}, options);
  14397. try {
  14398. options.sourceType = "module";
  14399. const parser = getParser(options, input);
  14400. const ast = parser.parse();
  14401. if (parser.sawUnambiguousESM) {
  14402. return ast;
  14403. }
  14404. if (parser.ambiguousScriptDifferentAst) {
  14405. try {
  14406. options.sourceType = "script";
  14407. return getParser(options, input).parse();
  14408. } catch (_unused) {}
  14409. } else {
  14410. ast.program.sourceType = "script";
  14411. }
  14412. return ast;
  14413. } catch (moduleError) {
  14414. try {
  14415. options.sourceType = "script";
  14416. return getParser(options, input).parse();
  14417. } catch (_unused2) {}
  14418. throw moduleError;
  14419. }
  14420. } else {
  14421. return getParser(options, input).parse();
  14422. }
  14423. }
  14424. function parseExpression(input, options) {
  14425. const parser = getParser(options, input);
  14426. if (parser.options.strictMode) {
  14427. parser.state.strict = true;
  14428. }
  14429. return parser.getExpression();
  14430. }
  14431. function generateExportedTokenTypes(internalTokenTypes) {
  14432. const tokenTypes = {};
  14433. for (const typeName of Object.keys(internalTokenTypes)) {
  14434. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  14435. }
  14436. return tokenTypes;
  14437. }
  14438. const tokTypes = generateExportedTokenTypes(tt);
  14439. function getParser(options, input) {
  14440. let cls = Parser;
  14441. if (options != null && options.plugins) {
  14442. validatePlugins(options.plugins);
  14443. cls = getParserClass(options.plugins);
  14444. }
  14445. return new cls(options, input);
  14446. }
  14447. const parserClassCache = {};
  14448. function getParserClass(pluginsFromOptions) {
  14449. const pluginList = mixinPluginNames.filter(name => hasPlugin(pluginsFromOptions, name));
  14450. const key = pluginList.join("/");
  14451. let cls = parserClassCache[key];
  14452. if (!cls) {
  14453. cls = Parser;
  14454. for (const plugin of pluginList) {
  14455. cls = mixinPlugins[plugin](cls);
  14456. }
  14457. parserClassCache[key] = cls;
  14458. }
  14459. return cls;
  14460. }
  14461. exports.parse = parse;
  14462. exports.parseExpression = parseExpression;
  14463. exports.tokTypes = tokTypes;
  14464. //# sourceMappingURL=index.js.map