esprima.js 283 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. /* istanbul ignore next */
  3. if(typeof exports === 'object' && typeof module === 'object')
  4. module.exports = factory();
  5. else if(typeof define === 'function' && define.amd)
  6. define([], factory);
  7. /* istanbul ignore next */
  8. else if(typeof exports === 'object')
  9. exports["esprima"] = factory();
  10. else
  11. root["esprima"] = factory();
  12. })(this, function() {
  13. return /******/ (function(modules) { // webpackBootstrap
  14. /******/ // The module cache
  15. /******/ var installedModules = {};
  16. /******/ // The require function
  17. /******/ function __webpack_require__(moduleId) {
  18. /******/ // Check if module is in cache
  19. /* istanbul ignore if */
  20. /******/ if(installedModules[moduleId])
  21. /******/ return installedModules[moduleId].exports;
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ exports: {},
  25. /******/ id: moduleId,
  26. /******/ loaded: false
  27. /******/ };
  28. /******/ // Execute the module function
  29. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  30. /******/ // Flag the module as loaded
  31. /******/ module.loaded = true;
  32. /******/ // Return the exports of the module
  33. /******/ return module.exports;
  34. /******/ }
  35. /******/ // expose the modules object (__webpack_modules__)
  36. /******/ __webpack_require__.m = modules;
  37. /******/ // expose the module cache
  38. /******/ __webpack_require__.c = installedModules;
  39. /******/ // __webpack_public_path__
  40. /******/ __webpack_require__.p = "";
  41. /******/ // Load entry module and return exports
  42. /******/ return __webpack_require__(0);
  43. /******/ })
  44. /************************************************************************/
  45. /******/ ([
  46. /* 0 */
  47. /***/ function(module, exports, __webpack_require__) {
  48. "use strict";
  49. /*
  50. Copyright JS Foundation and other contributors, https://js.foundation/
  51. Redistribution and use in source and binary forms, with or without
  52. modification, are permitted provided that the following conditions are met:
  53. * Redistributions of source code must retain the above copyright
  54. notice, this list of conditions and the following disclaimer.
  55. * Redistributions in binary form must reproduce the above copyright
  56. notice, this list of conditions and the following disclaimer in the
  57. documentation and/or other materials provided with the distribution.
  58. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  59. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  60. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  61. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  62. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  64. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  65. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  66. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  67. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  68. */
  69. Object.defineProperty(exports, "__esModule", { value: true });
  70. var comment_handler_1 = __webpack_require__(1);
  71. var jsx_parser_1 = __webpack_require__(3);
  72. var parser_1 = __webpack_require__(8);
  73. var tokenizer_1 = __webpack_require__(15);
  74. function parse(code, options, delegate) {
  75. var commentHandler = null;
  76. var proxyDelegate = function (node, metadata) {
  77. if (delegate) {
  78. delegate(node, metadata);
  79. }
  80. if (commentHandler) {
  81. commentHandler.visit(node, metadata);
  82. }
  83. };
  84. var parserDelegate = (typeof delegate === 'function') ? proxyDelegate : null;
  85. var collectComment = false;
  86. if (options) {
  87. collectComment = (typeof options.comment === 'boolean' && options.comment);
  88. var attachComment = (typeof options.attachComment === 'boolean' && options.attachComment);
  89. if (collectComment || attachComment) {
  90. commentHandler = new comment_handler_1.CommentHandler();
  91. commentHandler.attach = attachComment;
  92. options.comment = true;
  93. parserDelegate = proxyDelegate;
  94. }
  95. }
  96. var isModule = false;
  97. if (options && typeof options.sourceType === 'string') {
  98. isModule = (options.sourceType === 'module');
  99. }
  100. var parser;
  101. if (options && typeof options.jsx === 'boolean' && options.jsx) {
  102. parser = new jsx_parser_1.JSXParser(code, options, parserDelegate);
  103. }
  104. else {
  105. parser = new parser_1.Parser(code, options, parserDelegate);
  106. }
  107. var program = isModule ? parser.parseModule() : parser.parseScript();
  108. var ast = program;
  109. if (collectComment && commentHandler) {
  110. ast.comments = commentHandler.comments;
  111. }
  112. if (parser.config.tokens) {
  113. ast.tokens = parser.tokens;
  114. }
  115. if (parser.config.tolerant) {
  116. ast.errors = parser.errorHandler.errors;
  117. }
  118. return ast;
  119. }
  120. exports.parse = parse;
  121. function parseModule(code, options, delegate) {
  122. var parsingOptions = options || {};
  123. parsingOptions.sourceType = 'module';
  124. return parse(code, parsingOptions, delegate);
  125. }
  126. exports.parseModule = parseModule;
  127. function parseScript(code, options, delegate) {
  128. var parsingOptions = options || {};
  129. parsingOptions.sourceType = 'script';
  130. return parse(code, parsingOptions, delegate);
  131. }
  132. exports.parseScript = parseScript;
  133. function tokenize(code, options, delegate) {
  134. var tokenizer = new tokenizer_1.Tokenizer(code, options);
  135. var tokens;
  136. tokens = [];
  137. try {
  138. while (true) {
  139. var token = tokenizer.getNextToken();
  140. if (!token) {
  141. break;
  142. }
  143. if (delegate) {
  144. token = delegate(token);
  145. }
  146. tokens.push(token);
  147. }
  148. }
  149. catch (e) {
  150. tokenizer.errorHandler.tolerate(e);
  151. }
  152. if (tokenizer.errorHandler.tolerant) {
  153. tokens.errors = tokenizer.errors();
  154. }
  155. return tokens;
  156. }
  157. exports.tokenize = tokenize;
  158. var syntax_1 = __webpack_require__(2);
  159. exports.Syntax = syntax_1.Syntax;
  160. // Sync with *.json manifests.
  161. exports.version = '4.0.0';
  162. /***/ },
  163. /* 1 */
  164. /***/ function(module, exports, __webpack_require__) {
  165. "use strict";
  166. Object.defineProperty(exports, "__esModule", { value: true });
  167. var syntax_1 = __webpack_require__(2);
  168. var CommentHandler = (function () {
  169. function CommentHandler() {
  170. this.attach = false;
  171. this.comments = [];
  172. this.stack = [];
  173. this.leading = [];
  174. this.trailing = [];
  175. }
  176. CommentHandler.prototype.insertInnerComments = function (node, metadata) {
  177. // innnerComments for properties empty block
  178. // `function a() {/** comments **\/}`
  179. if (node.type === syntax_1.Syntax.BlockStatement && node.body.length === 0) {
  180. var innerComments = [];
  181. for (var i = this.leading.length - 1; i >= 0; --i) {
  182. var entry = this.leading[i];
  183. if (metadata.end.offset >= entry.start) {
  184. innerComments.unshift(entry.comment);
  185. this.leading.splice(i, 1);
  186. this.trailing.splice(i, 1);
  187. }
  188. }
  189. if (innerComments.length) {
  190. node.innerComments = innerComments;
  191. }
  192. }
  193. };
  194. CommentHandler.prototype.findTrailingComments = function (metadata) {
  195. var trailingComments = [];
  196. if (this.trailing.length > 0) {
  197. for (var i = this.trailing.length - 1; i >= 0; --i) {
  198. var entry_1 = this.trailing[i];
  199. if (entry_1.start >= metadata.end.offset) {
  200. trailingComments.unshift(entry_1.comment);
  201. }
  202. }
  203. this.trailing.length = 0;
  204. return trailingComments;
  205. }
  206. var entry = this.stack[this.stack.length - 1];
  207. if (entry && entry.node.trailingComments) {
  208. var firstComment = entry.node.trailingComments[0];
  209. if (firstComment && firstComment.range[0] >= metadata.end.offset) {
  210. trailingComments = entry.node.trailingComments;
  211. delete entry.node.trailingComments;
  212. }
  213. }
  214. return trailingComments;
  215. };
  216. CommentHandler.prototype.findLeadingComments = function (metadata) {
  217. var leadingComments = [];
  218. var target;
  219. while (this.stack.length > 0) {
  220. var entry = this.stack[this.stack.length - 1];
  221. if (entry && entry.start >= metadata.start.offset) {
  222. target = entry.node;
  223. this.stack.pop();
  224. }
  225. else {
  226. break;
  227. }
  228. }
  229. if (target) {
  230. var count = target.leadingComments ? target.leadingComments.length : 0;
  231. for (var i = count - 1; i >= 0; --i) {
  232. var comment = target.leadingComments[i];
  233. if (comment.range[1] <= metadata.start.offset) {
  234. leadingComments.unshift(comment);
  235. target.leadingComments.splice(i, 1);
  236. }
  237. }
  238. if (target.leadingComments && target.leadingComments.length === 0) {
  239. delete target.leadingComments;
  240. }
  241. return leadingComments;
  242. }
  243. for (var i = this.leading.length - 1; i >= 0; --i) {
  244. var entry = this.leading[i];
  245. if (entry.start <= metadata.start.offset) {
  246. leadingComments.unshift(entry.comment);
  247. this.leading.splice(i, 1);
  248. }
  249. }
  250. return leadingComments;
  251. };
  252. CommentHandler.prototype.visitNode = function (node, metadata) {
  253. if (node.type === syntax_1.Syntax.Program && node.body.length > 0) {
  254. return;
  255. }
  256. this.insertInnerComments(node, metadata);
  257. var trailingComments = this.findTrailingComments(metadata);
  258. var leadingComments = this.findLeadingComments(metadata);
  259. if (leadingComments.length > 0) {
  260. node.leadingComments = leadingComments;
  261. }
  262. if (trailingComments.length > 0) {
  263. node.trailingComments = trailingComments;
  264. }
  265. this.stack.push({
  266. node: node,
  267. start: metadata.start.offset
  268. });
  269. };
  270. CommentHandler.prototype.visitComment = function (node, metadata) {
  271. var type = (node.type[0] === 'L') ? 'Line' : 'Block';
  272. var comment = {
  273. type: type,
  274. value: node.value
  275. };
  276. if (node.range) {
  277. comment.range = node.range;
  278. }
  279. if (node.loc) {
  280. comment.loc = node.loc;
  281. }
  282. this.comments.push(comment);
  283. if (this.attach) {
  284. var entry = {
  285. comment: {
  286. type: type,
  287. value: node.value,
  288. range: [metadata.start.offset, metadata.end.offset]
  289. },
  290. start: metadata.start.offset
  291. };
  292. if (node.loc) {
  293. entry.comment.loc = node.loc;
  294. }
  295. node.type = type;
  296. this.leading.push(entry);
  297. this.trailing.push(entry);
  298. }
  299. };
  300. CommentHandler.prototype.visit = function (node, metadata) {
  301. if (node.type === 'LineComment') {
  302. this.visitComment(node, metadata);
  303. }
  304. else if (node.type === 'BlockComment') {
  305. this.visitComment(node, metadata);
  306. }
  307. else if (this.attach) {
  308. this.visitNode(node, metadata);
  309. }
  310. };
  311. return CommentHandler;
  312. }());
  313. exports.CommentHandler = CommentHandler;
  314. /***/ },
  315. /* 2 */
  316. /***/ function(module, exports) {
  317. "use strict";
  318. Object.defineProperty(exports, "__esModule", { value: true });
  319. exports.Syntax = {
  320. AssignmentExpression: 'AssignmentExpression',
  321. AssignmentPattern: 'AssignmentPattern',
  322. ArrayExpression: 'ArrayExpression',
  323. ArrayPattern: 'ArrayPattern',
  324. ArrowFunctionExpression: 'ArrowFunctionExpression',
  325. AwaitExpression: 'AwaitExpression',
  326. BlockStatement: 'BlockStatement',
  327. BinaryExpression: 'BinaryExpression',
  328. BreakStatement: 'BreakStatement',
  329. CallExpression: 'CallExpression',
  330. CatchClause: 'CatchClause',
  331. ClassBody: 'ClassBody',
  332. ClassDeclaration: 'ClassDeclaration',
  333. ClassExpression: 'ClassExpression',
  334. ConditionalExpression: 'ConditionalExpression',
  335. ContinueStatement: 'ContinueStatement',
  336. DoWhileStatement: 'DoWhileStatement',
  337. DebuggerStatement: 'DebuggerStatement',
  338. EmptyStatement: 'EmptyStatement',
  339. ExportAllDeclaration: 'ExportAllDeclaration',
  340. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  341. ExportNamedDeclaration: 'ExportNamedDeclaration',
  342. ExportSpecifier: 'ExportSpecifier',
  343. ExpressionStatement: 'ExpressionStatement',
  344. ForStatement: 'ForStatement',
  345. ForOfStatement: 'ForOfStatement',
  346. ForInStatement: 'ForInStatement',
  347. FunctionDeclaration: 'FunctionDeclaration',
  348. FunctionExpression: 'FunctionExpression',
  349. Identifier: 'Identifier',
  350. IfStatement: 'IfStatement',
  351. ImportDeclaration: 'ImportDeclaration',
  352. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  353. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  354. ImportSpecifier: 'ImportSpecifier',
  355. Literal: 'Literal',
  356. LabeledStatement: 'LabeledStatement',
  357. LogicalExpression: 'LogicalExpression',
  358. MemberExpression: 'MemberExpression',
  359. MetaProperty: 'MetaProperty',
  360. MethodDefinition: 'MethodDefinition',
  361. NewExpression: 'NewExpression',
  362. ObjectExpression: 'ObjectExpression',
  363. ObjectPattern: 'ObjectPattern',
  364. Program: 'Program',
  365. Property: 'Property',
  366. RestElement: 'RestElement',
  367. ReturnStatement: 'ReturnStatement',
  368. SequenceExpression: 'SequenceExpression',
  369. SpreadElement: 'SpreadElement',
  370. Super: 'Super',
  371. SwitchCase: 'SwitchCase',
  372. SwitchStatement: 'SwitchStatement',
  373. TaggedTemplateExpression: 'TaggedTemplateExpression',
  374. TemplateElement: 'TemplateElement',
  375. TemplateLiteral: 'TemplateLiteral',
  376. ThisExpression: 'ThisExpression',
  377. ThrowStatement: 'ThrowStatement',
  378. TryStatement: 'TryStatement',
  379. UnaryExpression: 'UnaryExpression',
  380. UpdateExpression: 'UpdateExpression',
  381. VariableDeclaration: 'VariableDeclaration',
  382. VariableDeclarator: 'VariableDeclarator',
  383. WhileStatement: 'WhileStatement',
  384. WithStatement: 'WithStatement',
  385. YieldExpression: 'YieldExpression'
  386. };
  387. /***/ },
  388. /* 3 */
  389. /***/ function(module, exports, __webpack_require__) {
  390. "use strict";
  391. /* istanbul ignore next */
  392. var __extends = (this && this.__extends) || (function () {
  393. var extendStatics = Object.setPrototypeOf ||
  394. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  395. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  396. return function (d, b) {
  397. extendStatics(d, b);
  398. function __() { this.constructor = d; }
  399. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  400. };
  401. })();
  402. Object.defineProperty(exports, "__esModule", { value: true });
  403. var character_1 = __webpack_require__(4);
  404. var JSXNode = __webpack_require__(5);
  405. var jsx_syntax_1 = __webpack_require__(6);
  406. var Node = __webpack_require__(7);
  407. var parser_1 = __webpack_require__(8);
  408. var token_1 = __webpack_require__(13);
  409. var xhtml_entities_1 = __webpack_require__(14);
  410. token_1.TokenName[100 /* Identifier */] = 'JSXIdentifier';
  411. token_1.TokenName[101 /* Text */] = 'JSXText';
  412. // Fully qualified element name, e.g. <svg:path> returns "svg:path"
  413. function getQualifiedElementName(elementName) {
  414. var qualifiedName;
  415. switch (elementName.type) {
  416. case jsx_syntax_1.JSXSyntax.JSXIdentifier:
  417. var id = elementName;
  418. qualifiedName = id.name;
  419. break;
  420. case jsx_syntax_1.JSXSyntax.JSXNamespacedName:
  421. var ns = elementName;
  422. qualifiedName = getQualifiedElementName(ns.namespace) + ':' +
  423. getQualifiedElementName(ns.name);
  424. break;
  425. case jsx_syntax_1.JSXSyntax.JSXMemberExpression:
  426. var expr = elementName;
  427. qualifiedName = getQualifiedElementName(expr.object) + '.' +
  428. getQualifiedElementName(expr.property);
  429. break;
  430. /* istanbul ignore next */
  431. default:
  432. break;
  433. }
  434. return qualifiedName;
  435. }
  436. var JSXParser = (function (_super) {
  437. __extends(JSXParser, _super);
  438. function JSXParser(code, options, delegate) {
  439. return _super.call(this, code, options, delegate) || this;
  440. }
  441. JSXParser.prototype.parsePrimaryExpression = function () {
  442. return this.match('<') ? this.parseJSXRoot() : _super.prototype.parsePrimaryExpression.call(this);
  443. };
  444. JSXParser.prototype.startJSX = function () {
  445. // Unwind the scanner before the lookahead token.
  446. this.scanner.index = this.startMarker.index;
  447. this.scanner.lineNumber = this.startMarker.line;
  448. this.scanner.lineStart = this.startMarker.index - this.startMarker.column;
  449. };
  450. JSXParser.prototype.finishJSX = function () {
  451. // Prime the next lookahead.
  452. this.nextToken();
  453. };
  454. JSXParser.prototype.reenterJSX = function () {
  455. this.startJSX();
  456. this.expectJSX('}');
  457. // Pop the closing '}' added from the lookahead.
  458. if (this.config.tokens) {
  459. this.tokens.pop();
  460. }
  461. };
  462. JSXParser.prototype.createJSXNode = function () {
  463. this.collectComments();
  464. return {
  465. index: this.scanner.index,
  466. line: this.scanner.lineNumber,
  467. column: this.scanner.index - this.scanner.lineStart
  468. };
  469. };
  470. JSXParser.prototype.createJSXChildNode = function () {
  471. return {
  472. index: this.scanner.index,
  473. line: this.scanner.lineNumber,
  474. column: this.scanner.index - this.scanner.lineStart
  475. };
  476. };
  477. JSXParser.prototype.scanXHTMLEntity = function (quote) {
  478. var result = '&';
  479. var valid = true;
  480. var terminated = false;
  481. var numeric = false;
  482. var hex = false;
  483. while (!this.scanner.eof() && valid && !terminated) {
  484. var ch = this.scanner.source[this.scanner.index];
  485. if (ch === quote) {
  486. break;
  487. }
  488. terminated = (ch === ';');
  489. result += ch;
  490. ++this.scanner.index;
  491. if (!terminated) {
  492. switch (result.length) {
  493. case 2:
  494. // e.g. '&#123;'
  495. numeric = (ch === '#');
  496. break;
  497. case 3:
  498. if (numeric) {
  499. // e.g. '&#x41;'
  500. hex = (ch === 'x');
  501. valid = hex || character_1.Character.isDecimalDigit(ch.charCodeAt(0));
  502. numeric = numeric && !hex;
  503. }
  504. break;
  505. default:
  506. valid = valid && !(numeric && !character_1.Character.isDecimalDigit(ch.charCodeAt(0)));
  507. valid = valid && !(hex && !character_1.Character.isHexDigit(ch.charCodeAt(0)));
  508. break;
  509. }
  510. }
  511. }
  512. if (valid && terminated && result.length > 2) {
  513. // e.g. '&#x41;' becomes just '#x41'
  514. var str = result.substr(1, result.length - 2);
  515. if (numeric && str.length > 1) {
  516. result = String.fromCharCode(parseInt(str.substr(1), 10));
  517. }
  518. else if (hex && str.length > 2) {
  519. result = String.fromCharCode(parseInt('0' + str.substr(1), 16));
  520. }
  521. else if (!numeric && !hex && xhtml_entities_1.XHTMLEntities[str]) {
  522. result = xhtml_entities_1.XHTMLEntities[str];
  523. }
  524. }
  525. return result;
  526. };
  527. // Scan the next JSX token. This replaces Scanner#lex when in JSX mode.
  528. JSXParser.prototype.lexJSX = function () {
  529. var cp = this.scanner.source.charCodeAt(this.scanner.index);
  530. // < > / : = { }
  531. if (cp === 60 || cp === 62 || cp === 47 || cp === 58 || cp === 61 || cp === 123 || cp === 125) {
  532. var value = this.scanner.source[this.scanner.index++];
  533. return {
  534. type: 7 /* Punctuator */,
  535. value: value,
  536. lineNumber: this.scanner.lineNumber,
  537. lineStart: this.scanner.lineStart,
  538. start: this.scanner.index - 1,
  539. end: this.scanner.index
  540. };
  541. }
  542. // " '
  543. if (cp === 34 || cp === 39) {
  544. var start = this.scanner.index;
  545. var quote = this.scanner.source[this.scanner.index++];
  546. var str = '';
  547. while (!this.scanner.eof()) {
  548. var ch = this.scanner.source[this.scanner.index++];
  549. if (ch === quote) {
  550. break;
  551. }
  552. else if (ch === '&') {
  553. str += this.scanXHTMLEntity(quote);
  554. }
  555. else {
  556. str += ch;
  557. }
  558. }
  559. return {
  560. type: 8 /* StringLiteral */,
  561. value: str,
  562. lineNumber: this.scanner.lineNumber,
  563. lineStart: this.scanner.lineStart,
  564. start: start,
  565. end: this.scanner.index
  566. };
  567. }
  568. // ... or .
  569. if (cp === 46) {
  570. var n1 = this.scanner.source.charCodeAt(this.scanner.index + 1);
  571. var n2 = this.scanner.source.charCodeAt(this.scanner.index + 2);
  572. var value = (n1 === 46 && n2 === 46) ? '...' : '.';
  573. var start = this.scanner.index;
  574. this.scanner.index += value.length;
  575. return {
  576. type: 7 /* Punctuator */,
  577. value: value,
  578. lineNumber: this.scanner.lineNumber,
  579. lineStart: this.scanner.lineStart,
  580. start: start,
  581. end: this.scanner.index
  582. };
  583. }
  584. // `
  585. if (cp === 96) {
  586. // Only placeholder, since it will be rescanned as a real assignment expression.
  587. return {
  588. type: 10 /* Template */,
  589. value: '',
  590. lineNumber: this.scanner.lineNumber,
  591. lineStart: this.scanner.lineStart,
  592. start: this.scanner.index,
  593. end: this.scanner.index
  594. };
  595. }
  596. // Identifer can not contain backslash (char code 92).
  597. if (character_1.Character.isIdentifierStart(cp) && (cp !== 92)) {
  598. var start = this.scanner.index;
  599. ++this.scanner.index;
  600. while (!this.scanner.eof()) {
  601. var ch = this.scanner.source.charCodeAt(this.scanner.index);
  602. if (character_1.Character.isIdentifierPart(ch) && (ch !== 92)) {
  603. ++this.scanner.index;
  604. }
  605. else if (ch === 45) {
  606. // Hyphen (char code 45) can be part of an identifier.
  607. ++this.scanner.index;
  608. }
  609. else {
  610. break;
  611. }
  612. }
  613. var id = this.scanner.source.slice(start, this.scanner.index);
  614. return {
  615. type: 100 /* Identifier */,
  616. value: id,
  617. lineNumber: this.scanner.lineNumber,
  618. lineStart: this.scanner.lineStart,
  619. start: start,
  620. end: this.scanner.index
  621. };
  622. }
  623. return this.scanner.lex();
  624. };
  625. JSXParser.prototype.nextJSXToken = function () {
  626. this.collectComments();
  627. this.startMarker.index = this.scanner.index;
  628. this.startMarker.line = this.scanner.lineNumber;
  629. this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  630. var token = this.lexJSX();
  631. this.lastMarker.index = this.scanner.index;
  632. this.lastMarker.line = this.scanner.lineNumber;
  633. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  634. if (this.config.tokens) {
  635. this.tokens.push(this.convertToken(token));
  636. }
  637. return token;
  638. };
  639. JSXParser.prototype.nextJSXText = function () {
  640. this.startMarker.index = this.scanner.index;
  641. this.startMarker.line = this.scanner.lineNumber;
  642. this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  643. var start = this.scanner.index;
  644. var text = '';
  645. while (!this.scanner.eof()) {
  646. var ch = this.scanner.source[this.scanner.index];
  647. if (ch === '{' || ch === '<') {
  648. break;
  649. }
  650. ++this.scanner.index;
  651. text += ch;
  652. if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  653. ++this.scanner.lineNumber;
  654. if (ch === '\r' && this.scanner.source[this.scanner.index] === '\n') {
  655. ++this.scanner.index;
  656. }
  657. this.scanner.lineStart = this.scanner.index;
  658. }
  659. }
  660. this.lastMarker.index = this.scanner.index;
  661. this.lastMarker.line = this.scanner.lineNumber;
  662. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  663. var token = {
  664. type: 101 /* Text */,
  665. value: text,
  666. lineNumber: this.scanner.lineNumber,
  667. lineStart: this.scanner.lineStart,
  668. start: start,
  669. end: this.scanner.index
  670. };
  671. if ((text.length > 0) && this.config.tokens) {
  672. this.tokens.push(this.convertToken(token));
  673. }
  674. return token;
  675. };
  676. JSXParser.prototype.peekJSXToken = function () {
  677. var state = this.scanner.saveState();
  678. this.scanner.scanComments();
  679. var next = this.lexJSX();
  680. this.scanner.restoreState(state);
  681. return next;
  682. };
  683. // Expect the next JSX token to match the specified punctuator.
  684. // If not, an exception will be thrown.
  685. JSXParser.prototype.expectJSX = function (value) {
  686. var token = this.nextJSXToken();
  687. if (token.type !== 7 /* Punctuator */ || token.value !== value) {
  688. this.throwUnexpectedToken(token);
  689. }
  690. };
  691. // Return true if the next JSX token matches the specified punctuator.
  692. JSXParser.prototype.matchJSX = function (value) {
  693. var next = this.peekJSXToken();
  694. return next.type === 7 /* Punctuator */ && next.value === value;
  695. };
  696. JSXParser.prototype.parseJSXIdentifier = function () {
  697. var node = this.createJSXNode();
  698. var token = this.nextJSXToken();
  699. if (token.type !== 100 /* Identifier */) {
  700. this.throwUnexpectedToken(token);
  701. }
  702. return this.finalize(node, new JSXNode.JSXIdentifier(token.value));
  703. };
  704. JSXParser.prototype.parseJSXElementName = function () {
  705. var node = this.createJSXNode();
  706. var elementName = this.parseJSXIdentifier();
  707. if (this.matchJSX(':')) {
  708. var namespace = elementName;
  709. this.expectJSX(':');
  710. var name_1 = this.parseJSXIdentifier();
  711. elementName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_1));
  712. }
  713. else if (this.matchJSX('.')) {
  714. while (this.matchJSX('.')) {
  715. var object = elementName;
  716. this.expectJSX('.');
  717. var property = this.parseJSXIdentifier();
  718. elementName = this.finalize(node, new JSXNode.JSXMemberExpression(object, property));
  719. }
  720. }
  721. return elementName;
  722. };
  723. JSXParser.prototype.parseJSXAttributeName = function () {
  724. var node = this.createJSXNode();
  725. var attributeName;
  726. var identifier = this.parseJSXIdentifier();
  727. if (this.matchJSX(':')) {
  728. var namespace = identifier;
  729. this.expectJSX(':');
  730. var name_2 = this.parseJSXIdentifier();
  731. attributeName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_2));
  732. }
  733. else {
  734. attributeName = identifier;
  735. }
  736. return attributeName;
  737. };
  738. JSXParser.prototype.parseJSXStringLiteralAttribute = function () {
  739. var node = this.createJSXNode();
  740. var token = this.nextJSXToken();
  741. if (token.type !== 8 /* StringLiteral */) {
  742. this.throwUnexpectedToken(token);
  743. }
  744. var raw = this.getTokenRaw(token);
  745. return this.finalize(node, new Node.Literal(token.value, raw));
  746. };
  747. JSXParser.prototype.parseJSXExpressionAttribute = function () {
  748. var node = this.createJSXNode();
  749. this.expectJSX('{');
  750. this.finishJSX();
  751. if (this.match('}')) {
  752. this.tolerateError('JSX attributes must only be assigned a non-empty expression');
  753. }
  754. var expression = this.parseAssignmentExpression();
  755. this.reenterJSX();
  756. return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
  757. };
  758. JSXParser.prototype.parseJSXAttributeValue = function () {
  759. return this.matchJSX('{') ? this.parseJSXExpressionAttribute() :
  760. this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
  761. };
  762. JSXParser.prototype.parseJSXNameValueAttribute = function () {
  763. var node = this.createJSXNode();
  764. var name = this.parseJSXAttributeName();
  765. var value = null;
  766. if (this.matchJSX('=')) {
  767. this.expectJSX('=');
  768. value = this.parseJSXAttributeValue();
  769. }
  770. return this.finalize(node, new JSXNode.JSXAttribute(name, value));
  771. };
  772. JSXParser.prototype.parseJSXSpreadAttribute = function () {
  773. var node = this.createJSXNode();
  774. this.expectJSX('{');
  775. this.expectJSX('...');
  776. this.finishJSX();
  777. var argument = this.parseAssignmentExpression();
  778. this.reenterJSX();
  779. return this.finalize(node, new JSXNode.JSXSpreadAttribute(argument));
  780. };
  781. JSXParser.prototype.parseJSXAttributes = function () {
  782. var attributes = [];
  783. while (!this.matchJSX('/') && !this.matchJSX('>')) {
  784. var attribute = this.matchJSX('{') ? this.parseJSXSpreadAttribute() :
  785. this.parseJSXNameValueAttribute();
  786. attributes.push(attribute);
  787. }
  788. return attributes;
  789. };
  790. JSXParser.prototype.parseJSXOpeningElement = function () {
  791. var node = this.createJSXNode();
  792. this.expectJSX('<');
  793. var name = this.parseJSXElementName();
  794. var attributes = this.parseJSXAttributes();
  795. var selfClosing = this.matchJSX('/');
  796. if (selfClosing) {
  797. this.expectJSX('/');
  798. }
  799. this.expectJSX('>');
  800. return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
  801. };
  802. JSXParser.prototype.parseJSXBoundaryElement = function () {
  803. var node = this.createJSXNode();
  804. this.expectJSX('<');
  805. if (this.matchJSX('/')) {
  806. this.expectJSX('/');
  807. var name_3 = this.parseJSXElementName();
  808. this.expectJSX('>');
  809. return this.finalize(node, new JSXNode.JSXClosingElement(name_3));
  810. }
  811. var name = this.parseJSXElementName();
  812. var attributes = this.parseJSXAttributes();
  813. var selfClosing = this.matchJSX('/');
  814. if (selfClosing) {
  815. this.expectJSX('/');
  816. }
  817. this.expectJSX('>');
  818. return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
  819. };
  820. JSXParser.prototype.parseJSXEmptyExpression = function () {
  821. var node = this.createJSXChildNode();
  822. this.collectComments();
  823. this.lastMarker.index = this.scanner.index;
  824. this.lastMarker.line = this.scanner.lineNumber;
  825. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  826. return this.finalize(node, new JSXNode.JSXEmptyExpression());
  827. };
  828. JSXParser.prototype.parseJSXExpressionContainer = function () {
  829. var node = this.createJSXNode();
  830. this.expectJSX('{');
  831. var expression;
  832. if (this.matchJSX('}')) {
  833. expression = this.parseJSXEmptyExpression();
  834. this.expectJSX('}');
  835. }
  836. else {
  837. this.finishJSX();
  838. expression = this.parseAssignmentExpression();
  839. this.reenterJSX();
  840. }
  841. return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
  842. };
  843. JSXParser.prototype.parseJSXChildren = function () {
  844. var children = [];
  845. while (!this.scanner.eof()) {
  846. var node = this.createJSXChildNode();
  847. var token = this.nextJSXText();
  848. if (token.start < token.end) {
  849. var raw = this.getTokenRaw(token);
  850. var child = this.finalize(node, new JSXNode.JSXText(token.value, raw));
  851. children.push(child);
  852. }
  853. if (this.scanner.source[this.scanner.index] === '{') {
  854. var container = this.parseJSXExpressionContainer();
  855. children.push(container);
  856. }
  857. else {
  858. break;
  859. }
  860. }
  861. return children;
  862. };
  863. JSXParser.prototype.parseComplexJSXElement = function (el) {
  864. var stack = [];
  865. while (!this.scanner.eof()) {
  866. el.children = el.children.concat(this.parseJSXChildren());
  867. var node = this.createJSXChildNode();
  868. var element = this.parseJSXBoundaryElement();
  869. if (element.type === jsx_syntax_1.JSXSyntax.JSXOpeningElement) {
  870. var opening = element;
  871. if (opening.selfClosing) {
  872. var child = this.finalize(node, new JSXNode.JSXElement(opening, [], null));
  873. el.children.push(child);
  874. }
  875. else {
  876. stack.push(el);
  877. el = { node: node, opening: opening, closing: null, children: [] };
  878. }
  879. }
  880. if (element.type === jsx_syntax_1.JSXSyntax.JSXClosingElement) {
  881. el.closing = element;
  882. var open_1 = getQualifiedElementName(el.opening.name);
  883. var close_1 = getQualifiedElementName(el.closing.name);
  884. if (open_1 !== close_1) {
  885. this.tolerateError('Expected corresponding JSX closing tag for %0', open_1);
  886. }
  887. if (stack.length > 0) {
  888. var child = this.finalize(el.node, new JSXNode.JSXElement(el.opening, el.children, el.closing));
  889. el = stack[stack.length - 1];
  890. el.children.push(child);
  891. stack.pop();
  892. }
  893. else {
  894. break;
  895. }
  896. }
  897. }
  898. return el;
  899. };
  900. JSXParser.prototype.parseJSXElement = function () {
  901. var node = this.createJSXNode();
  902. var opening = this.parseJSXOpeningElement();
  903. var children = [];
  904. var closing = null;
  905. if (!opening.selfClosing) {
  906. var el = this.parseComplexJSXElement({ node: node, opening: opening, closing: closing, children: children });
  907. children = el.children;
  908. closing = el.closing;
  909. }
  910. return this.finalize(node, new JSXNode.JSXElement(opening, children, closing));
  911. };
  912. JSXParser.prototype.parseJSXRoot = function () {
  913. // Pop the opening '<' added from the lookahead.
  914. if (this.config.tokens) {
  915. this.tokens.pop();
  916. }
  917. this.startJSX();
  918. var element = this.parseJSXElement();
  919. this.finishJSX();
  920. return element;
  921. };
  922. JSXParser.prototype.isStartOfExpression = function () {
  923. return _super.prototype.isStartOfExpression.call(this) || this.match('<');
  924. };
  925. return JSXParser;
  926. }(parser_1.Parser));
  927. exports.JSXParser = JSXParser;
  928. /***/ },
  929. /* 4 */
  930. /***/ function(module, exports) {
  931. "use strict";
  932. Object.defineProperty(exports, "__esModule", { value: true });
  933. // See also tools/generate-unicode-regex.js.
  934. var Regex = {
  935. // Unicode v8.0.0 NonAsciiIdentifierStart:
  936. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,
  937. // Unicode v8.0.0 NonAsciiIdentifierPart:
  938. NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
  939. };
  940. exports.Character = {
  941. /* tslint:disable:no-bitwise */
  942. fromCodePoint: function (cp) {
  943. return (cp < 0x10000) ? String.fromCharCode(cp) :
  944. String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
  945. String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
  946. },
  947. // https://tc39.github.io/ecma262/#sec-white-space
  948. isWhiteSpace: function (cp) {
  949. return (cp === 0x20) || (cp === 0x09) || (cp === 0x0B) || (cp === 0x0C) || (cp === 0xA0) ||
  950. (cp >= 0x1680 && [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(cp) >= 0);
  951. },
  952. // https://tc39.github.io/ecma262/#sec-line-terminators
  953. isLineTerminator: function (cp) {
  954. return (cp === 0x0A) || (cp === 0x0D) || (cp === 0x2028) || (cp === 0x2029);
  955. },
  956. // https://tc39.github.io/ecma262/#sec-names-and-keywords
  957. isIdentifierStart: function (cp) {
  958. return (cp === 0x24) || (cp === 0x5F) ||
  959. (cp >= 0x41 && cp <= 0x5A) ||
  960. (cp >= 0x61 && cp <= 0x7A) ||
  961. (cp === 0x5C) ||
  962. ((cp >= 0x80) && Regex.NonAsciiIdentifierStart.test(exports.Character.fromCodePoint(cp)));
  963. },
  964. isIdentifierPart: function (cp) {
  965. return (cp === 0x24) || (cp === 0x5F) ||
  966. (cp >= 0x41 && cp <= 0x5A) ||
  967. (cp >= 0x61 && cp <= 0x7A) ||
  968. (cp >= 0x30 && cp <= 0x39) ||
  969. (cp === 0x5C) ||
  970. ((cp >= 0x80) && Regex.NonAsciiIdentifierPart.test(exports.Character.fromCodePoint(cp)));
  971. },
  972. // https://tc39.github.io/ecma262/#sec-literals-numeric-literals
  973. isDecimalDigit: function (cp) {
  974. return (cp >= 0x30 && cp <= 0x39); // 0..9
  975. },
  976. isHexDigit: function (cp) {
  977. return (cp >= 0x30 && cp <= 0x39) ||
  978. (cp >= 0x41 && cp <= 0x46) ||
  979. (cp >= 0x61 && cp <= 0x66); // a..f
  980. },
  981. isOctalDigit: function (cp) {
  982. return (cp >= 0x30 && cp <= 0x37); // 0..7
  983. }
  984. };
  985. /***/ },
  986. /* 5 */
  987. /***/ function(module, exports, __webpack_require__) {
  988. "use strict";
  989. Object.defineProperty(exports, "__esModule", { value: true });
  990. var jsx_syntax_1 = __webpack_require__(6);
  991. /* tslint:disable:max-classes-per-file */
  992. var JSXClosingElement = (function () {
  993. function JSXClosingElement(name) {
  994. this.type = jsx_syntax_1.JSXSyntax.JSXClosingElement;
  995. this.name = name;
  996. }
  997. return JSXClosingElement;
  998. }());
  999. exports.JSXClosingElement = JSXClosingElement;
  1000. var JSXElement = (function () {
  1001. function JSXElement(openingElement, children, closingElement) {
  1002. this.type = jsx_syntax_1.JSXSyntax.JSXElement;
  1003. this.openingElement = openingElement;
  1004. this.children = children;
  1005. this.closingElement = closingElement;
  1006. }
  1007. return JSXElement;
  1008. }());
  1009. exports.JSXElement = JSXElement;
  1010. var JSXEmptyExpression = (function () {
  1011. function JSXEmptyExpression() {
  1012. this.type = jsx_syntax_1.JSXSyntax.JSXEmptyExpression;
  1013. }
  1014. return JSXEmptyExpression;
  1015. }());
  1016. exports.JSXEmptyExpression = JSXEmptyExpression;
  1017. var JSXExpressionContainer = (function () {
  1018. function JSXExpressionContainer(expression) {
  1019. this.type = jsx_syntax_1.JSXSyntax.JSXExpressionContainer;
  1020. this.expression = expression;
  1021. }
  1022. return JSXExpressionContainer;
  1023. }());
  1024. exports.JSXExpressionContainer = JSXExpressionContainer;
  1025. var JSXIdentifier = (function () {
  1026. function JSXIdentifier(name) {
  1027. this.type = jsx_syntax_1.JSXSyntax.JSXIdentifier;
  1028. this.name = name;
  1029. }
  1030. return JSXIdentifier;
  1031. }());
  1032. exports.JSXIdentifier = JSXIdentifier;
  1033. var JSXMemberExpression = (function () {
  1034. function JSXMemberExpression(object, property) {
  1035. this.type = jsx_syntax_1.JSXSyntax.JSXMemberExpression;
  1036. this.object = object;
  1037. this.property = property;
  1038. }
  1039. return JSXMemberExpression;
  1040. }());
  1041. exports.JSXMemberExpression = JSXMemberExpression;
  1042. var JSXAttribute = (function () {
  1043. function JSXAttribute(name, value) {
  1044. this.type = jsx_syntax_1.JSXSyntax.JSXAttribute;
  1045. this.name = name;
  1046. this.value = value;
  1047. }
  1048. return JSXAttribute;
  1049. }());
  1050. exports.JSXAttribute = JSXAttribute;
  1051. var JSXNamespacedName = (function () {
  1052. function JSXNamespacedName(namespace, name) {
  1053. this.type = jsx_syntax_1.JSXSyntax.JSXNamespacedName;
  1054. this.namespace = namespace;
  1055. this.name = name;
  1056. }
  1057. return JSXNamespacedName;
  1058. }());
  1059. exports.JSXNamespacedName = JSXNamespacedName;
  1060. var JSXOpeningElement = (function () {
  1061. function JSXOpeningElement(name, selfClosing, attributes) {
  1062. this.type = jsx_syntax_1.JSXSyntax.JSXOpeningElement;
  1063. this.name = name;
  1064. this.selfClosing = selfClosing;
  1065. this.attributes = attributes;
  1066. }
  1067. return JSXOpeningElement;
  1068. }());
  1069. exports.JSXOpeningElement = JSXOpeningElement;
  1070. var JSXSpreadAttribute = (function () {
  1071. function JSXSpreadAttribute(argument) {
  1072. this.type = jsx_syntax_1.JSXSyntax.JSXSpreadAttribute;
  1073. this.argument = argument;
  1074. }
  1075. return JSXSpreadAttribute;
  1076. }());
  1077. exports.JSXSpreadAttribute = JSXSpreadAttribute;
  1078. var JSXText = (function () {
  1079. function JSXText(value, raw) {
  1080. this.type = jsx_syntax_1.JSXSyntax.JSXText;
  1081. this.value = value;
  1082. this.raw = raw;
  1083. }
  1084. return JSXText;
  1085. }());
  1086. exports.JSXText = JSXText;
  1087. /***/ },
  1088. /* 6 */
  1089. /***/ function(module, exports) {
  1090. "use strict";
  1091. Object.defineProperty(exports, "__esModule", { value: true });
  1092. exports.JSXSyntax = {
  1093. JSXAttribute: 'JSXAttribute',
  1094. JSXClosingElement: 'JSXClosingElement',
  1095. JSXElement: 'JSXElement',
  1096. JSXEmptyExpression: 'JSXEmptyExpression',
  1097. JSXExpressionContainer: 'JSXExpressionContainer',
  1098. JSXIdentifier: 'JSXIdentifier',
  1099. JSXMemberExpression: 'JSXMemberExpression',
  1100. JSXNamespacedName: 'JSXNamespacedName',
  1101. JSXOpeningElement: 'JSXOpeningElement',
  1102. JSXSpreadAttribute: 'JSXSpreadAttribute',
  1103. JSXText: 'JSXText'
  1104. };
  1105. /***/ },
  1106. /* 7 */
  1107. /***/ function(module, exports, __webpack_require__) {
  1108. "use strict";
  1109. Object.defineProperty(exports, "__esModule", { value: true });
  1110. var syntax_1 = __webpack_require__(2);
  1111. /* tslint:disable:max-classes-per-file */
  1112. var ArrayExpression = (function () {
  1113. function ArrayExpression(elements) {
  1114. this.type = syntax_1.Syntax.ArrayExpression;
  1115. this.elements = elements;
  1116. }
  1117. return ArrayExpression;
  1118. }());
  1119. exports.ArrayExpression = ArrayExpression;
  1120. var ArrayPattern = (function () {
  1121. function ArrayPattern(elements) {
  1122. this.type = syntax_1.Syntax.ArrayPattern;
  1123. this.elements = elements;
  1124. }
  1125. return ArrayPattern;
  1126. }());
  1127. exports.ArrayPattern = ArrayPattern;
  1128. var ArrowFunctionExpression = (function () {
  1129. function ArrowFunctionExpression(params, body, expression) {
  1130. this.type = syntax_1.Syntax.ArrowFunctionExpression;
  1131. this.id = null;
  1132. this.params = params;
  1133. this.body = body;
  1134. this.generator = false;
  1135. this.expression = expression;
  1136. this.async = false;
  1137. }
  1138. return ArrowFunctionExpression;
  1139. }());
  1140. exports.ArrowFunctionExpression = ArrowFunctionExpression;
  1141. var AssignmentExpression = (function () {
  1142. function AssignmentExpression(operator, left, right) {
  1143. this.type = syntax_1.Syntax.AssignmentExpression;
  1144. this.operator = operator;
  1145. this.left = left;
  1146. this.right = right;
  1147. }
  1148. return AssignmentExpression;
  1149. }());
  1150. exports.AssignmentExpression = AssignmentExpression;
  1151. var AssignmentPattern = (function () {
  1152. function AssignmentPattern(left, right) {
  1153. this.type = syntax_1.Syntax.AssignmentPattern;
  1154. this.left = left;
  1155. this.right = right;
  1156. }
  1157. return AssignmentPattern;
  1158. }());
  1159. exports.AssignmentPattern = AssignmentPattern;
  1160. var AsyncArrowFunctionExpression = (function () {
  1161. function AsyncArrowFunctionExpression(params, body, expression) {
  1162. this.type = syntax_1.Syntax.ArrowFunctionExpression;
  1163. this.id = null;
  1164. this.params = params;
  1165. this.body = body;
  1166. this.generator = false;
  1167. this.expression = expression;
  1168. this.async = true;
  1169. }
  1170. return AsyncArrowFunctionExpression;
  1171. }());
  1172. exports.AsyncArrowFunctionExpression = AsyncArrowFunctionExpression;
  1173. var AsyncFunctionDeclaration = (function () {
  1174. function AsyncFunctionDeclaration(id, params, body) {
  1175. this.type = syntax_1.Syntax.FunctionDeclaration;
  1176. this.id = id;
  1177. this.params = params;
  1178. this.body = body;
  1179. this.generator = false;
  1180. this.expression = false;
  1181. this.async = true;
  1182. }
  1183. return AsyncFunctionDeclaration;
  1184. }());
  1185. exports.AsyncFunctionDeclaration = AsyncFunctionDeclaration;
  1186. var AsyncFunctionExpression = (function () {
  1187. function AsyncFunctionExpression(id, params, body) {
  1188. this.type = syntax_1.Syntax.FunctionExpression;
  1189. this.id = id;
  1190. this.params = params;
  1191. this.body = body;
  1192. this.generator = false;
  1193. this.expression = false;
  1194. this.async = true;
  1195. }
  1196. return AsyncFunctionExpression;
  1197. }());
  1198. exports.AsyncFunctionExpression = AsyncFunctionExpression;
  1199. var AwaitExpression = (function () {
  1200. function AwaitExpression(argument) {
  1201. this.type = syntax_1.Syntax.AwaitExpression;
  1202. this.argument = argument;
  1203. }
  1204. return AwaitExpression;
  1205. }());
  1206. exports.AwaitExpression = AwaitExpression;
  1207. var BinaryExpression = (function () {
  1208. function BinaryExpression(operator, left, right) {
  1209. var logical = (operator === '||' || operator === '&&');
  1210. this.type = logical ? syntax_1.Syntax.LogicalExpression : syntax_1.Syntax.BinaryExpression;
  1211. this.operator = operator;
  1212. this.left = left;
  1213. this.right = right;
  1214. }
  1215. return BinaryExpression;
  1216. }());
  1217. exports.BinaryExpression = BinaryExpression;
  1218. var BlockStatement = (function () {
  1219. function BlockStatement(body) {
  1220. this.type = syntax_1.Syntax.BlockStatement;
  1221. this.body = body;
  1222. }
  1223. return BlockStatement;
  1224. }());
  1225. exports.BlockStatement = BlockStatement;
  1226. var BreakStatement = (function () {
  1227. function BreakStatement(label) {
  1228. this.type = syntax_1.Syntax.BreakStatement;
  1229. this.label = label;
  1230. }
  1231. return BreakStatement;
  1232. }());
  1233. exports.BreakStatement = BreakStatement;
  1234. var CallExpression = (function () {
  1235. function CallExpression(callee, args) {
  1236. this.type = syntax_1.Syntax.CallExpression;
  1237. this.callee = callee;
  1238. this.arguments = args;
  1239. }
  1240. return CallExpression;
  1241. }());
  1242. exports.CallExpression = CallExpression;
  1243. var CatchClause = (function () {
  1244. function CatchClause(param, body) {
  1245. this.type = syntax_1.Syntax.CatchClause;
  1246. this.param = param;
  1247. this.body = body;
  1248. }
  1249. return CatchClause;
  1250. }());
  1251. exports.CatchClause = CatchClause;
  1252. var ClassBody = (function () {
  1253. function ClassBody(body) {
  1254. this.type = syntax_1.Syntax.ClassBody;
  1255. this.body = body;
  1256. }
  1257. return ClassBody;
  1258. }());
  1259. exports.ClassBody = ClassBody;
  1260. var ClassDeclaration = (function () {
  1261. function ClassDeclaration(id, superClass, body) {
  1262. this.type = syntax_1.Syntax.ClassDeclaration;
  1263. this.id = id;
  1264. this.superClass = superClass;
  1265. this.body = body;
  1266. }
  1267. return ClassDeclaration;
  1268. }());
  1269. exports.ClassDeclaration = ClassDeclaration;
  1270. var ClassExpression = (function () {
  1271. function ClassExpression(id, superClass, body) {
  1272. this.type = syntax_1.Syntax.ClassExpression;
  1273. this.id = id;
  1274. this.superClass = superClass;
  1275. this.body = body;
  1276. }
  1277. return ClassExpression;
  1278. }());
  1279. exports.ClassExpression = ClassExpression;
  1280. var ComputedMemberExpression = (function () {
  1281. function ComputedMemberExpression(object, property) {
  1282. this.type = syntax_1.Syntax.MemberExpression;
  1283. this.computed = true;
  1284. this.object = object;
  1285. this.property = property;
  1286. }
  1287. return ComputedMemberExpression;
  1288. }());
  1289. exports.ComputedMemberExpression = ComputedMemberExpression;
  1290. var ConditionalExpression = (function () {
  1291. function ConditionalExpression(test, consequent, alternate) {
  1292. this.type = syntax_1.Syntax.ConditionalExpression;
  1293. this.test = test;
  1294. this.consequent = consequent;
  1295. this.alternate = alternate;
  1296. }
  1297. return ConditionalExpression;
  1298. }());
  1299. exports.ConditionalExpression = ConditionalExpression;
  1300. var ContinueStatement = (function () {
  1301. function ContinueStatement(label) {
  1302. this.type = syntax_1.Syntax.ContinueStatement;
  1303. this.label = label;
  1304. }
  1305. return ContinueStatement;
  1306. }());
  1307. exports.ContinueStatement = ContinueStatement;
  1308. var DebuggerStatement = (function () {
  1309. function DebuggerStatement() {
  1310. this.type = syntax_1.Syntax.DebuggerStatement;
  1311. }
  1312. return DebuggerStatement;
  1313. }());
  1314. exports.DebuggerStatement = DebuggerStatement;
  1315. var Directive = (function () {
  1316. function Directive(expression, directive) {
  1317. this.type = syntax_1.Syntax.ExpressionStatement;
  1318. this.expression = expression;
  1319. this.directive = directive;
  1320. }
  1321. return Directive;
  1322. }());
  1323. exports.Directive = Directive;
  1324. var DoWhileStatement = (function () {
  1325. function DoWhileStatement(body, test) {
  1326. this.type = syntax_1.Syntax.DoWhileStatement;
  1327. this.body = body;
  1328. this.test = test;
  1329. }
  1330. return DoWhileStatement;
  1331. }());
  1332. exports.DoWhileStatement = DoWhileStatement;
  1333. var EmptyStatement = (function () {
  1334. function EmptyStatement() {
  1335. this.type = syntax_1.Syntax.EmptyStatement;
  1336. }
  1337. return EmptyStatement;
  1338. }());
  1339. exports.EmptyStatement = EmptyStatement;
  1340. var ExportAllDeclaration = (function () {
  1341. function ExportAllDeclaration(source) {
  1342. this.type = syntax_1.Syntax.ExportAllDeclaration;
  1343. this.source = source;
  1344. }
  1345. return ExportAllDeclaration;
  1346. }());
  1347. exports.ExportAllDeclaration = ExportAllDeclaration;
  1348. var ExportDefaultDeclaration = (function () {
  1349. function ExportDefaultDeclaration(declaration) {
  1350. this.type = syntax_1.Syntax.ExportDefaultDeclaration;
  1351. this.declaration = declaration;
  1352. }
  1353. return ExportDefaultDeclaration;
  1354. }());
  1355. exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
  1356. var ExportNamedDeclaration = (function () {
  1357. function ExportNamedDeclaration(declaration, specifiers, source) {
  1358. this.type = syntax_1.Syntax.ExportNamedDeclaration;
  1359. this.declaration = declaration;
  1360. this.specifiers = specifiers;
  1361. this.source = source;
  1362. }
  1363. return ExportNamedDeclaration;
  1364. }());
  1365. exports.ExportNamedDeclaration = ExportNamedDeclaration;
  1366. var ExportSpecifier = (function () {
  1367. function ExportSpecifier(local, exported) {
  1368. this.type = syntax_1.Syntax.ExportSpecifier;
  1369. this.exported = exported;
  1370. this.local = local;
  1371. }
  1372. return ExportSpecifier;
  1373. }());
  1374. exports.ExportSpecifier = ExportSpecifier;
  1375. var ExpressionStatement = (function () {
  1376. function ExpressionStatement(expression) {
  1377. this.type = syntax_1.Syntax.ExpressionStatement;
  1378. this.expression = expression;
  1379. }
  1380. return ExpressionStatement;
  1381. }());
  1382. exports.ExpressionStatement = ExpressionStatement;
  1383. var ForInStatement = (function () {
  1384. function ForInStatement(left, right, body) {
  1385. this.type = syntax_1.Syntax.ForInStatement;
  1386. this.left = left;
  1387. this.right = right;
  1388. this.body = body;
  1389. this.each = false;
  1390. }
  1391. return ForInStatement;
  1392. }());
  1393. exports.ForInStatement = ForInStatement;
  1394. var ForOfStatement = (function () {
  1395. function ForOfStatement(left, right, body) {
  1396. this.type = syntax_1.Syntax.ForOfStatement;
  1397. this.left = left;
  1398. this.right = right;
  1399. this.body = body;
  1400. }
  1401. return ForOfStatement;
  1402. }());
  1403. exports.ForOfStatement = ForOfStatement;
  1404. var ForStatement = (function () {
  1405. function ForStatement(init, test, update, body) {
  1406. this.type = syntax_1.Syntax.ForStatement;
  1407. this.init = init;
  1408. this.test = test;
  1409. this.update = update;
  1410. this.body = body;
  1411. }
  1412. return ForStatement;
  1413. }());
  1414. exports.ForStatement = ForStatement;
  1415. var FunctionDeclaration = (function () {
  1416. function FunctionDeclaration(id, params, body, generator) {
  1417. this.type = syntax_1.Syntax.FunctionDeclaration;
  1418. this.id = id;
  1419. this.params = params;
  1420. this.body = body;
  1421. this.generator = generator;
  1422. this.expression = false;
  1423. this.async = false;
  1424. }
  1425. return FunctionDeclaration;
  1426. }());
  1427. exports.FunctionDeclaration = FunctionDeclaration;
  1428. var FunctionExpression = (function () {
  1429. function FunctionExpression(id, params, body, generator) {
  1430. this.type = syntax_1.Syntax.FunctionExpression;
  1431. this.id = id;
  1432. this.params = params;
  1433. this.body = body;
  1434. this.generator = generator;
  1435. this.expression = false;
  1436. this.async = false;
  1437. }
  1438. return FunctionExpression;
  1439. }());
  1440. exports.FunctionExpression = FunctionExpression;
  1441. var Identifier = (function () {
  1442. function Identifier(name) {
  1443. this.type = syntax_1.Syntax.Identifier;
  1444. this.name = name;
  1445. }
  1446. return Identifier;
  1447. }());
  1448. exports.Identifier = Identifier;
  1449. var IfStatement = (function () {
  1450. function IfStatement(test, consequent, alternate) {
  1451. this.type = syntax_1.Syntax.IfStatement;
  1452. this.test = test;
  1453. this.consequent = consequent;
  1454. this.alternate = alternate;
  1455. }
  1456. return IfStatement;
  1457. }());
  1458. exports.IfStatement = IfStatement;
  1459. var ImportDeclaration = (function () {
  1460. function ImportDeclaration(specifiers, source) {
  1461. this.type = syntax_1.Syntax.ImportDeclaration;
  1462. this.specifiers = specifiers;
  1463. this.source = source;
  1464. }
  1465. return ImportDeclaration;
  1466. }());
  1467. exports.ImportDeclaration = ImportDeclaration;
  1468. var ImportDefaultSpecifier = (function () {
  1469. function ImportDefaultSpecifier(local) {
  1470. this.type = syntax_1.Syntax.ImportDefaultSpecifier;
  1471. this.local = local;
  1472. }
  1473. return ImportDefaultSpecifier;
  1474. }());
  1475. exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
  1476. var ImportNamespaceSpecifier = (function () {
  1477. function ImportNamespaceSpecifier(local) {
  1478. this.type = syntax_1.Syntax.ImportNamespaceSpecifier;
  1479. this.local = local;
  1480. }
  1481. return ImportNamespaceSpecifier;
  1482. }());
  1483. exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
  1484. var ImportSpecifier = (function () {
  1485. function ImportSpecifier(local, imported) {
  1486. this.type = syntax_1.Syntax.ImportSpecifier;
  1487. this.local = local;
  1488. this.imported = imported;
  1489. }
  1490. return ImportSpecifier;
  1491. }());
  1492. exports.ImportSpecifier = ImportSpecifier;
  1493. var LabeledStatement = (function () {
  1494. function LabeledStatement(label, body) {
  1495. this.type = syntax_1.Syntax.LabeledStatement;
  1496. this.label = label;
  1497. this.body = body;
  1498. }
  1499. return LabeledStatement;
  1500. }());
  1501. exports.LabeledStatement = LabeledStatement;
  1502. var Literal = (function () {
  1503. function Literal(value, raw) {
  1504. this.type = syntax_1.Syntax.Literal;
  1505. this.value = value;
  1506. this.raw = raw;
  1507. }
  1508. return Literal;
  1509. }());
  1510. exports.Literal = Literal;
  1511. var MetaProperty = (function () {
  1512. function MetaProperty(meta, property) {
  1513. this.type = syntax_1.Syntax.MetaProperty;
  1514. this.meta = meta;
  1515. this.property = property;
  1516. }
  1517. return MetaProperty;
  1518. }());
  1519. exports.MetaProperty = MetaProperty;
  1520. var MethodDefinition = (function () {
  1521. function MethodDefinition(key, computed, value, kind, isStatic) {
  1522. this.type = syntax_1.Syntax.MethodDefinition;
  1523. this.key = key;
  1524. this.computed = computed;
  1525. this.value = value;
  1526. this.kind = kind;
  1527. this.static = isStatic;
  1528. }
  1529. return MethodDefinition;
  1530. }());
  1531. exports.MethodDefinition = MethodDefinition;
  1532. var Module = (function () {
  1533. function Module(body) {
  1534. this.type = syntax_1.Syntax.Program;
  1535. this.body = body;
  1536. this.sourceType = 'module';
  1537. }
  1538. return Module;
  1539. }());
  1540. exports.Module = Module;
  1541. var NewExpression = (function () {
  1542. function NewExpression(callee, args) {
  1543. this.type = syntax_1.Syntax.NewExpression;
  1544. this.callee = callee;
  1545. this.arguments = args;
  1546. }
  1547. return NewExpression;
  1548. }());
  1549. exports.NewExpression = NewExpression;
  1550. var ObjectExpression = (function () {
  1551. function ObjectExpression(properties) {
  1552. this.type = syntax_1.Syntax.ObjectExpression;
  1553. this.properties = properties;
  1554. }
  1555. return ObjectExpression;
  1556. }());
  1557. exports.ObjectExpression = ObjectExpression;
  1558. var ObjectPattern = (function () {
  1559. function ObjectPattern(properties) {
  1560. this.type = syntax_1.Syntax.ObjectPattern;
  1561. this.properties = properties;
  1562. }
  1563. return ObjectPattern;
  1564. }());
  1565. exports.ObjectPattern = ObjectPattern;
  1566. var Property = (function () {
  1567. function Property(kind, key, computed, value, method, shorthand) {
  1568. this.type = syntax_1.Syntax.Property;
  1569. this.key = key;
  1570. this.computed = computed;
  1571. this.value = value;
  1572. this.kind = kind;
  1573. this.method = method;
  1574. this.shorthand = shorthand;
  1575. }
  1576. return Property;
  1577. }());
  1578. exports.Property = Property;
  1579. var RegexLiteral = (function () {
  1580. function RegexLiteral(value, raw, pattern, flags) {
  1581. this.type = syntax_1.Syntax.Literal;
  1582. this.value = value;
  1583. this.raw = raw;
  1584. this.regex = { pattern: pattern, flags: flags };
  1585. }
  1586. return RegexLiteral;
  1587. }());
  1588. exports.RegexLiteral = RegexLiteral;
  1589. var RestElement = (function () {
  1590. function RestElement(argument) {
  1591. this.type = syntax_1.Syntax.RestElement;
  1592. this.argument = argument;
  1593. }
  1594. return RestElement;
  1595. }());
  1596. exports.RestElement = RestElement;
  1597. var ReturnStatement = (function () {
  1598. function ReturnStatement(argument) {
  1599. this.type = syntax_1.Syntax.ReturnStatement;
  1600. this.argument = argument;
  1601. }
  1602. return ReturnStatement;
  1603. }());
  1604. exports.ReturnStatement = ReturnStatement;
  1605. var Script = (function () {
  1606. function Script(body) {
  1607. this.type = syntax_1.Syntax.Program;
  1608. this.body = body;
  1609. this.sourceType = 'script';
  1610. }
  1611. return Script;
  1612. }());
  1613. exports.Script = Script;
  1614. var SequenceExpression = (function () {
  1615. function SequenceExpression(expressions) {
  1616. this.type = syntax_1.Syntax.SequenceExpression;
  1617. this.expressions = expressions;
  1618. }
  1619. return SequenceExpression;
  1620. }());
  1621. exports.SequenceExpression = SequenceExpression;
  1622. var SpreadElement = (function () {
  1623. function SpreadElement(argument) {
  1624. this.type = syntax_1.Syntax.SpreadElement;
  1625. this.argument = argument;
  1626. }
  1627. return SpreadElement;
  1628. }());
  1629. exports.SpreadElement = SpreadElement;
  1630. var StaticMemberExpression = (function () {
  1631. function StaticMemberExpression(object, property) {
  1632. this.type = syntax_1.Syntax.MemberExpression;
  1633. this.computed = false;
  1634. this.object = object;
  1635. this.property = property;
  1636. }
  1637. return StaticMemberExpression;
  1638. }());
  1639. exports.StaticMemberExpression = StaticMemberExpression;
  1640. var Super = (function () {
  1641. function Super() {
  1642. this.type = syntax_1.Syntax.Super;
  1643. }
  1644. return Super;
  1645. }());
  1646. exports.Super = Super;
  1647. var SwitchCase = (function () {
  1648. function SwitchCase(test, consequent) {
  1649. this.type = syntax_1.Syntax.SwitchCase;
  1650. this.test = test;
  1651. this.consequent = consequent;
  1652. }
  1653. return SwitchCase;
  1654. }());
  1655. exports.SwitchCase = SwitchCase;
  1656. var SwitchStatement = (function () {
  1657. function SwitchStatement(discriminant, cases) {
  1658. this.type = syntax_1.Syntax.SwitchStatement;
  1659. this.discriminant = discriminant;
  1660. this.cases = cases;
  1661. }
  1662. return SwitchStatement;
  1663. }());
  1664. exports.SwitchStatement = SwitchStatement;
  1665. var TaggedTemplateExpression = (function () {
  1666. function TaggedTemplateExpression(tag, quasi) {
  1667. this.type = syntax_1.Syntax.TaggedTemplateExpression;
  1668. this.tag = tag;
  1669. this.quasi = quasi;
  1670. }
  1671. return TaggedTemplateExpression;
  1672. }());
  1673. exports.TaggedTemplateExpression = TaggedTemplateExpression;
  1674. var TemplateElement = (function () {
  1675. function TemplateElement(value, tail) {
  1676. this.type = syntax_1.Syntax.TemplateElement;
  1677. this.value = value;
  1678. this.tail = tail;
  1679. }
  1680. return TemplateElement;
  1681. }());
  1682. exports.TemplateElement = TemplateElement;
  1683. var TemplateLiteral = (function () {
  1684. function TemplateLiteral(quasis, expressions) {
  1685. this.type = syntax_1.Syntax.TemplateLiteral;
  1686. this.quasis = quasis;
  1687. this.expressions = expressions;
  1688. }
  1689. return TemplateLiteral;
  1690. }());
  1691. exports.TemplateLiteral = TemplateLiteral;
  1692. var ThisExpression = (function () {
  1693. function ThisExpression() {
  1694. this.type = syntax_1.Syntax.ThisExpression;
  1695. }
  1696. return ThisExpression;
  1697. }());
  1698. exports.ThisExpression = ThisExpression;
  1699. var ThrowStatement = (function () {
  1700. function ThrowStatement(argument) {
  1701. this.type = syntax_1.Syntax.ThrowStatement;
  1702. this.argument = argument;
  1703. }
  1704. return ThrowStatement;
  1705. }());
  1706. exports.ThrowStatement = ThrowStatement;
  1707. var TryStatement = (function () {
  1708. function TryStatement(block, handler, finalizer) {
  1709. this.type = syntax_1.Syntax.TryStatement;
  1710. this.block = block;
  1711. this.handler = handler;
  1712. this.finalizer = finalizer;
  1713. }
  1714. return TryStatement;
  1715. }());
  1716. exports.TryStatement = TryStatement;
  1717. var UnaryExpression = (function () {
  1718. function UnaryExpression(operator, argument) {
  1719. this.type = syntax_1.Syntax.UnaryExpression;
  1720. this.operator = operator;
  1721. this.argument = argument;
  1722. this.prefix = true;
  1723. }
  1724. return UnaryExpression;
  1725. }());
  1726. exports.UnaryExpression = UnaryExpression;
  1727. var UpdateExpression = (function () {
  1728. function UpdateExpression(operator, argument, prefix) {
  1729. this.type = syntax_1.Syntax.UpdateExpression;
  1730. this.operator = operator;
  1731. this.argument = argument;
  1732. this.prefix = prefix;
  1733. }
  1734. return UpdateExpression;
  1735. }());
  1736. exports.UpdateExpression = UpdateExpression;
  1737. var VariableDeclaration = (function () {
  1738. function VariableDeclaration(declarations, kind) {
  1739. this.type = syntax_1.Syntax.VariableDeclaration;
  1740. this.declarations = declarations;
  1741. this.kind = kind;
  1742. }
  1743. return VariableDeclaration;
  1744. }());
  1745. exports.VariableDeclaration = VariableDeclaration;
  1746. var VariableDeclarator = (function () {
  1747. function VariableDeclarator(id, init) {
  1748. this.type = syntax_1.Syntax.VariableDeclarator;
  1749. this.id = id;
  1750. this.init = init;
  1751. }
  1752. return VariableDeclarator;
  1753. }());
  1754. exports.VariableDeclarator = VariableDeclarator;
  1755. var WhileStatement = (function () {
  1756. function WhileStatement(test, body) {
  1757. this.type = syntax_1.Syntax.WhileStatement;
  1758. this.test = test;
  1759. this.body = body;
  1760. }
  1761. return WhileStatement;
  1762. }());
  1763. exports.WhileStatement = WhileStatement;
  1764. var WithStatement = (function () {
  1765. function WithStatement(object, body) {
  1766. this.type = syntax_1.Syntax.WithStatement;
  1767. this.object = object;
  1768. this.body = body;
  1769. }
  1770. return WithStatement;
  1771. }());
  1772. exports.WithStatement = WithStatement;
  1773. var YieldExpression = (function () {
  1774. function YieldExpression(argument, delegate) {
  1775. this.type = syntax_1.Syntax.YieldExpression;
  1776. this.argument = argument;
  1777. this.delegate = delegate;
  1778. }
  1779. return YieldExpression;
  1780. }());
  1781. exports.YieldExpression = YieldExpression;
  1782. /***/ },
  1783. /* 8 */
  1784. /***/ function(module, exports, __webpack_require__) {
  1785. "use strict";
  1786. Object.defineProperty(exports, "__esModule", { value: true });
  1787. var assert_1 = __webpack_require__(9);
  1788. var error_handler_1 = __webpack_require__(10);
  1789. var messages_1 = __webpack_require__(11);
  1790. var Node = __webpack_require__(7);
  1791. var scanner_1 = __webpack_require__(12);
  1792. var syntax_1 = __webpack_require__(2);
  1793. var token_1 = __webpack_require__(13);
  1794. var ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
  1795. var Parser = (function () {
  1796. function Parser(code, options, delegate) {
  1797. if (options === void 0) { options = {}; }
  1798. this.config = {
  1799. range: (typeof options.range === 'boolean') && options.range,
  1800. loc: (typeof options.loc === 'boolean') && options.loc,
  1801. source: null,
  1802. tokens: (typeof options.tokens === 'boolean') && options.tokens,
  1803. comment: (typeof options.comment === 'boolean') && options.comment,
  1804. tolerant: (typeof options.tolerant === 'boolean') && options.tolerant
  1805. };
  1806. if (this.config.loc && options.source && options.source !== null) {
  1807. this.config.source = String(options.source);
  1808. }
  1809. this.delegate = delegate;
  1810. this.errorHandler = new error_handler_1.ErrorHandler();
  1811. this.errorHandler.tolerant = this.config.tolerant;
  1812. this.scanner = new scanner_1.Scanner(code, this.errorHandler);
  1813. this.scanner.trackComment = this.config.comment;
  1814. this.operatorPrecedence = {
  1815. ')': 0,
  1816. ';': 0,
  1817. ',': 0,
  1818. '=': 0,
  1819. ']': 0,
  1820. '||': 1,
  1821. '&&': 2,
  1822. '|': 3,
  1823. '^': 4,
  1824. '&': 5,
  1825. '==': 6,
  1826. '!=': 6,
  1827. '===': 6,
  1828. '!==': 6,
  1829. '<': 7,
  1830. '>': 7,
  1831. '<=': 7,
  1832. '>=': 7,
  1833. '<<': 8,
  1834. '>>': 8,
  1835. '>>>': 8,
  1836. '+': 9,
  1837. '-': 9,
  1838. '*': 11,
  1839. '/': 11,
  1840. '%': 11
  1841. };
  1842. this.lookahead = {
  1843. type: 2 /* EOF */,
  1844. value: '',
  1845. lineNumber: this.scanner.lineNumber,
  1846. lineStart: 0,
  1847. start: 0,
  1848. end: 0
  1849. };
  1850. this.hasLineTerminator = false;
  1851. this.context = {
  1852. isModule: false,
  1853. await: false,
  1854. allowIn: true,
  1855. allowStrictDirective: true,
  1856. allowYield: true,
  1857. firstCoverInitializedNameError: null,
  1858. isAssignmentTarget: false,
  1859. isBindingElement: false,
  1860. inFunctionBody: false,
  1861. inIteration: false,
  1862. inSwitch: false,
  1863. labelSet: {},
  1864. strict: false
  1865. };
  1866. this.tokens = [];
  1867. this.startMarker = {
  1868. index: 0,
  1869. line: this.scanner.lineNumber,
  1870. column: 0
  1871. };
  1872. this.lastMarker = {
  1873. index: 0,
  1874. line: this.scanner.lineNumber,
  1875. column: 0
  1876. };
  1877. this.nextToken();
  1878. this.lastMarker = {
  1879. index: this.scanner.index,
  1880. line: this.scanner.lineNumber,
  1881. column: this.scanner.index - this.scanner.lineStart
  1882. };
  1883. }
  1884. Parser.prototype.throwError = function (messageFormat) {
  1885. var values = [];
  1886. for (var _i = 1; _i < arguments.length; _i++) {
  1887. values[_i - 1] = arguments[_i];
  1888. }
  1889. var args = Array.prototype.slice.call(arguments, 1);
  1890. var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
  1891. assert_1.assert(idx < args.length, 'Message reference must be in range');
  1892. return args[idx];
  1893. });
  1894. var index = this.lastMarker.index;
  1895. var line = this.lastMarker.line;
  1896. var column = this.lastMarker.column + 1;
  1897. throw this.errorHandler.createError(index, line, column, msg);
  1898. };
  1899. Parser.prototype.tolerateError = function (messageFormat) {
  1900. var values = [];
  1901. for (var _i = 1; _i < arguments.length; _i++) {
  1902. values[_i - 1] = arguments[_i];
  1903. }
  1904. var args = Array.prototype.slice.call(arguments, 1);
  1905. var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
  1906. assert_1.assert(idx < args.length, 'Message reference must be in range');
  1907. return args[idx];
  1908. });
  1909. var index = this.lastMarker.index;
  1910. var line = this.scanner.lineNumber;
  1911. var column = this.lastMarker.column + 1;
  1912. this.errorHandler.tolerateError(index, line, column, msg);
  1913. };
  1914. // Throw an exception because of the token.
  1915. Parser.prototype.unexpectedTokenError = function (token, message) {
  1916. var msg = message || messages_1.Messages.UnexpectedToken;
  1917. var value;
  1918. if (token) {
  1919. if (!message) {
  1920. msg = (token.type === 2 /* EOF */) ? messages_1.Messages.UnexpectedEOS :
  1921. (token.type === 3 /* Identifier */) ? messages_1.Messages.UnexpectedIdentifier :
  1922. (token.type === 6 /* NumericLiteral */) ? messages_1.Messages.UnexpectedNumber :
  1923. (token.type === 8 /* StringLiteral */) ? messages_1.Messages.UnexpectedString :
  1924. (token.type === 10 /* Template */) ? messages_1.Messages.UnexpectedTemplate :
  1925. messages_1.Messages.UnexpectedToken;
  1926. if (token.type === 4 /* Keyword */) {
  1927. if (this.scanner.isFutureReservedWord(token.value)) {
  1928. msg = messages_1.Messages.UnexpectedReserved;
  1929. }
  1930. else if (this.context.strict && this.scanner.isStrictModeReservedWord(token.value)) {
  1931. msg = messages_1.Messages.StrictReservedWord;
  1932. }
  1933. }
  1934. }
  1935. value = token.value;
  1936. }
  1937. else {
  1938. value = 'ILLEGAL';
  1939. }
  1940. msg = msg.replace('%0', value);
  1941. if (token && typeof token.lineNumber === 'number') {
  1942. var index = token.start;
  1943. var line = token.lineNumber;
  1944. var lastMarkerLineStart = this.lastMarker.index - this.lastMarker.column;
  1945. var column = token.start - lastMarkerLineStart + 1;
  1946. return this.errorHandler.createError(index, line, column, msg);
  1947. }
  1948. else {
  1949. var index = this.lastMarker.index;
  1950. var line = this.lastMarker.line;
  1951. var column = this.lastMarker.column + 1;
  1952. return this.errorHandler.createError(index, line, column, msg);
  1953. }
  1954. };
  1955. Parser.prototype.throwUnexpectedToken = function (token, message) {
  1956. throw this.unexpectedTokenError(token, message);
  1957. };
  1958. Parser.prototype.tolerateUnexpectedToken = function (token, message) {
  1959. this.errorHandler.tolerate(this.unexpectedTokenError(token, message));
  1960. };
  1961. Parser.prototype.collectComments = function () {
  1962. if (!this.config.comment) {
  1963. this.scanner.scanComments();
  1964. }
  1965. else {
  1966. var comments = this.scanner.scanComments();
  1967. if (comments.length > 0 && this.delegate) {
  1968. for (var i = 0; i < comments.length; ++i) {
  1969. var e = comments[i];
  1970. var node = void 0;
  1971. node = {
  1972. type: e.multiLine ? 'BlockComment' : 'LineComment',
  1973. value: this.scanner.source.slice(e.slice[0], e.slice[1])
  1974. };
  1975. if (this.config.range) {
  1976. node.range = e.range;
  1977. }
  1978. if (this.config.loc) {
  1979. node.loc = e.loc;
  1980. }
  1981. var metadata = {
  1982. start: {
  1983. line: e.loc.start.line,
  1984. column: e.loc.start.column,
  1985. offset: e.range[0]
  1986. },
  1987. end: {
  1988. line: e.loc.end.line,
  1989. column: e.loc.end.column,
  1990. offset: e.range[1]
  1991. }
  1992. };
  1993. this.delegate(node, metadata);
  1994. }
  1995. }
  1996. }
  1997. };
  1998. // From internal representation to an external structure
  1999. Parser.prototype.getTokenRaw = function (token) {
  2000. return this.scanner.source.slice(token.start, token.end);
  2001. };
  2002. Parser.prototype.convertToken = function (token) {
  2003. var t = {
  2004. type: token_1.TokenName[token.type],
  2005. value: this.getTokenRaw(token)
  2006. };
  2007. if (this.config.range) {
  2008. t.range = [token.start, token.end];
  2009. }
  2010. if (this.config.loc) {
  2011. t.loc = {
  2012. start: {
  2013. line: this.startMarker.line,
  2014. column: this.startMarker.column
  2015. },
  2016. end: {
  2017. line: this.scanner.lineNumber,
  2018. column: this.scanner.index - this.scanner.lineStart
  2019. }
  2020. };
  2021. }
  2022. if (token.type === 9 /* RegularExpression */) {
  2023. var pattern = token.pattern;
  2024. var flags = token.flags;
  2025. t.regex = { pattern: pattern, flags: flags };
  2026. }
  2027. return t;
  2028. };
  2029. Parser.prototype.nextToken = function () {
  2030. var token = this.lookahead;
  2031. this.lastMarker.index = this.scanner.index;
  2032. this.lastMarker.line = this.scanner.lineNumber;
  2033. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  2034. this.collectComments();
  2035. if (this.scanner.index !== this.startMarker.index) {
  2036. this.startMarker.index = this.scanner.index;
  2037. this.startMarker.line = this.scanner.lineNumber;
  2038. this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  2039. }
  2040. var next = this.scanner.lex();
  2041. this.hasLineTerminator = (token.lineNumber !== next.lineNumber);
  2042. if (next && this.context.strict && next.type === 3 /* Identifier */) {
  2043. if (this.scanner.isStrictModeReservedWord(next.value)) {
  2044. next.type = 4 /* Keyword */;
  2045. }
  2046. }
  2047. this.lookahead = next;
  2048. if (this.config.tokens && next.type !== 2 /* EOF */) {
  2049. this.tokens.push(this.convertToken(next));
  2050. }
  2051. return token;
  2052. };
  2053. Parser.prototype.nextRegexToken = function () {
  2054. this.collectComments();
  2055. var token = this.scanner.scanRegExp();
  2056. if (this.config.tokens) {
  2057. // Pop the previous token, '/' or '/='
  2058. // This is added from the lookahead token.
  2059. this.tokens.pop();
  2060. this.tokens.push(this.convertToken(token));
  2061. }
  2062. // Prime the next lookahead.
  2063. this.lookahead = token;
  2064. this.nextToken();
  2065. return token;
  2066. };
  2067. Parser.prototype.createNode = function () {
  2068. return {
  2069. index: this.startMarker.index,
  2070. line: this.startMarker.line,
  2071. column: this.startMarker.column
  2072. };
  2073. };
  2074. Parser.prototype.startNode = function (token) {
  2075. return {
  2076. index: token.start,
  2077. line: token.lineNumber,
  2078. column: token.start - token.lineStart
  2079. };
  2080. };
  2081. Parser.prototype.finalize = function (marker, node) {
  2082. if (this.config.range) {
  2083. node.range = [marker.index, this.lastMarker.index];
  2084. }
  2085. if (this.config.loc) {
  2086. node.loc = {
  2087. start: {
  2088. line: marker.line,
  2089. column: marker.column,
  2090. },
  2091. end: {
  2092. line: this.lastMarker.line,
  2093. column: this.lastMarker.column
  2094. }
  2095. };
  2096. if (this.config.source) {
  2097. node.loc.source = this.config.source;
  2098. }
  2099. }
  2100. if (this.delegate) {
  2101. var metadata = {
  2102. start: {
  2103. line: marker.line,
  2104. column: marker.column,
  2105. offset: marker.index
  2106. },
  2107. end: {
  2108. line: this.lastMarker.line,
  2109. column: this.lastMarker.column,
  2110. offset: this.lastMarker.index
  2111. }
  2112. };
  2113. this.delegate(node, metadata);
  2114. }
  2115. return node;
  2116. };
  2117. // Expect the next token to match the specified punctuator.
  2118. // If not, an exception will be thrown.
  2119. Parser.prototype.expect = function (value) {
  2120. var token = this.nextToken();
  2121. if (token.type !== 7 /* Punctuator */ || token.value !== value) {
  2122. this.throwUnexpectedToken(token);
  2123. }
  2124. };
  2125. // Quietly expect a comma when in tolerant mode, otherwise delegates to expect().
  2126. Parser.prototype.expectCommaSeparator = function () {
  2127. if (this.config.tolerant) {
  2128. var token = this.lookahead;
  2129. if (token.type === 7 /* Punctuator */ && token.value === ',') {
  2130. this.nextToken();
  2131. }
  2132. else if (token.type === 7 /* Punctuator */ && token.value === ';') {
  2133. this.nextToken();
  2134. this.tolerateUnexpectedToken(token);
  2135. }
  2136. else {
  2137. this.tolerateUnexpectedToken(token, messages_1.Messages.UnexpectedToken);
  2138. }
  2139. }
  2140. else {
  2141. this.expect(',');
  2142. }
  2143. };
  2144. // Expect the next token to match the specified keyword.
  2145. // If not, an exception will be thrown.
  2146. Parser.prototype.expectKeyword = function (keyword) {
  2147. var token = this.nextToken();
  2148. if (token.type !== 4 /* Keyword */ || token.value !== keyword) {
  2149. this.throwUnexpectedToken(token);
  2150. }
  2151. };
  2152. // Return true if the next token matches the specified punctuator.
  2153. Parser.prototype.match = function (value) {
  2154. return this.lookahead.type === 7 /* Punctuator */ && this.lookahead.value === value;
  2155. };
  2156. // Return true if the next token matches the specified keyword
  2157. Parser.prototype.matchKeyword = function (keyword) {
  2158. return this.lookahead.type === 4 /* Keyword */ && this.lookahead.value === keyword;
  2159. };
  2160. // Return true if the next token matches the specified contextual keyword
  2161. // (where an identifier is sometimes a keyword depending on the context)
  2162. Parser.prototype.matchContextualKeyword = function (keyword) {
  2163. return this.lookahead.type === 3 /* Identifier */ && this.lookahead.value === keyword;
  2164. };
  2165. // Return true if the next token is an assignment operator
  2166. Parser.prototype.matchAssign = function () {
  2167. if (this.lookahead.type !== 7 /* Punctuator */) {
  2168. return false;
  2169. }
  2170. var op = this.lookahead.value;
  2171. return op === '=' ||
  2172. op === '*=' ||
  2173. op === '**=' ||
  2174. op === '/=' ||
  2175. op === '%=' ||
  2176. op === '+=' ||
  2177. op === '-=' ||
  2178. op === '<<=' ||
  2179. op === '>>=' ||
  2180. op === '>>>=' ||
  2181. op === '&=' ||
  2182. op === '^=' ||
  2183. op === '|=';
  2184. };
  2185. // Cover grammar support.
  2186. //
  2187. // When an assignment expression position starts with an left parenthesis, the determination of the type
  2188. // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
  2189. // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
  2190. //
  2191. // There are three productions that can be parsed in a parentheses pair that needs to be determined
  2192. // after the outermost pair is closed. They are:
  2193. //
  2194. // 1. AssignmentExpression
  2195. // 2. BindingElements
  2196. // 3. AssignmentTargets
  2197. //
  2198. // In order to avoid exponential backtracking, we use two flags to denote if the production can be
  2199. // binding element or assignment target.
  2200. //
  2201. // The three productions have the relationship:
  2202. //
  2203. // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
  2204. //
  2205. // with a single exception that CoverInitializedName when used directly in an Expression, generates
  2206. // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
  2207. // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
  2208. //
  2209. // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
  2210. // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
  2211. // the CoverInitializedName check is conducted.
  2212. //
  2213. // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
  2214. // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
  2215. // pattern. The CoverInitializedName check is deferred.
  2216. Parser.prototype.isolateCoverGrammar = function (parseFunction) {
  2217. var previousIsBindingElement = this.context.isBindingElement;
  2218. var previousIsAssignmentTarget = this.context.isAssignmentTarget;
  2219. var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
  2220. this.context.isBindingElement = true;
  2221. this.context.isAssignmentTarget = true;
  2222. this.context.firstCoverInitializedNameError = null;
  2223. var result = parseFunction.call(this);
  2224. if (this.context.firstCoverInitializedNameError !== null) {
  2225. this.throwUnexpectedToken(this.context.firstCoverInitializedNameError);
  2226. }
  2227. this.context.isBindingElement = previousIsBindingElement;
  2228. this.context.isAssignmentTarget = previousIsAssignmentTarget;
  2229. this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError;
  2230. return result;
  2231. };
  2232. Parser.prototype.inheritCoverGrammar = function (parseFunction) {
  2233. var previousIsBindingElement = this.context.isBindingElement;
  2234. var previousIsAssignmentTarget = this.context.isAssignmentTarget;
  2235. var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
  2236. this.context.isBindingElement = true;
  2237. this.context.isAssignmentTarget = true;
  2238. this.context.firstCoverInitializedNameError = null;
  2239. var result = parseFunction.call(this);
  2240. this.context.isBindingElement = this.context.isBindingElement && previousIsBindingElement;
  2241. this.context.isAssignmentTarget = this.context.isAssignmentTarget && previousIsAssignmentTarget;
  2242. this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError || this.context.firstCoverInitializedNameError;
  2243. return result;
  2244. };
  2245. Parser.prototype.consumeSemicolon = function () {
  2246. if (this.match(';')) {
  2247. this.nextToken();
  2248. }
  2249. else if (!this.hasLineTerminator) {
  2250. if (this.lookahead.type !== 2 /* EOF */ && !this.match('}')) {
  2251. this.throwUnexpectedToken(this.lookahead);
  2252. }
  2253. this.lastMarker.index = this.startMarker.index;
  2254. this.lastMarker.line = this.startMarker.line;
  2255. this.lastMarker.column = this.startMarker.column;
  2256. }
  2257. };
  2258. // https://tc39.github.io/ecma262/#sec-primary-expression
  2259. Parser.prototype.parsePrimaryExpression = function () {
  2260. var node = this.createNode();
  2261. var expr;
  2262. var token, raw;
  2263. switch (this.lookahead.type) {
  2264. case 3 /* Identifier */:
  2265. if ((this.context.isModule || this.context.await) && this.lookahead.value === 'await') {
  2266. this.tolerateUnexpectedToken(this.lookahead);
  2267. }
  2268. expr = this.matchAsyncFunction() ? this.parseFunctionExpression() : this.finalize(node, new Node.Identifier(this.nextToken().value));
  2269. break;
  2270. case 6 /* NumericLiteral */:
  2271. case 8 /* StringLiteral */:
  2272. if (this.context.strict && this.lookahead.octal) {
  2273. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.StrictOctalLiteral);
  2274. }
  2275. this.context.isAssignmentTarget = false;
  2276. this.context.isBindingElement = false;
  2277. token = this.nextToken();
  2278. raw = this.getTokenRaw(token);
  2279. expr = this.finalize(node, new Node.Literal(token.value, raw));
  2280. break;
  2281. case 1 /* BooleanLiteral */:
  2282. this.context.isAssignmentTarget = false;
  2283. this.context.isBindingElement = false;
  2284. token = this.nextToken();
  2285. raw = this.getTokenRaw(token);
  2286. expr = this.finalize(node, new Node.Literal(token.value === 'true', raw));
  2287. break;
  2288. case 5 /* NullLiteral */:
  2289. this.context.isAssignmentTarget = false;
  2290. this.context.isBindingElement = false;
  2291. token = this.nextToken();
  2292. raw = this.getTokenRaw(token);
  2293. expr = this.finalize(node, new Node.Literal(null, raw));
  2294. break;
  2295. case 10 /* Template */:
  2296. expr = this.parseTemplateLiteral();
  2297. break;
  2298. case 7 /* Punctuator */:
  2299. switch (this.lookahead.value) {
  2300. case '(':
  2301. this.context.isBindingElement = false;
  2302. expr = this.inheritCoverGrammar(this.parseGroupExpression);
  2303. break;
  2304. case '[':
  2305. expr = this.inheritCoverGrammar(this.parseArrayInitializer);
  2306. break;
  2307. case '{':
  2308. expr = this.inheritCoverGrammar(this.parseObjectInitializer);
  2309. break;
  2310. case '/':
  2311. case '/=':
  2312. this.context.isAssignmentTarget = false;
  2313. this.context.isBindingElement = false;
  2314. this.scanner.index = this.startMarker.index;
  2315. token = this.nextRegexToken();
  2316. raw = this.getTokenRaw(token);
  2317. expr = this.finalize(node, new Node.RegexLiteral(token.regex, raw, token.pattern, token.flags));
  2318. break;
  2319. default:
  2320. expr = this.throwUnexpectedToken(this.nextToken());
  2321. }
  2322. break;
  2323. case 4 /* Keyword */:
  2324. if (!this.context.strict && this.context.allowYield && this.matchKeyword('yield')) {
  2325. expr = this.parseIdentifierName();
  2326. }
  2327. else if (!this.context.strict && this.matchKeyword('let')) {
  2328. expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
  2329. }
  2330. else {
  2331. this.context.isAssignmentTarget = false;
  2332. this.context.isBindingElement = false;
  2333. if (this.matchKeyword('function')) {
  2334. expr = this.parseFunctionExpression();
  2335. }
  2336. else if (this.matchKeyword('this')) {
  2337. this.nextToken();
  2338. expr = this.finalize(node, new Node.ThisExpression());
  2339. }
  2340. else if (this.matchKeyword('class')) {
  2341. expr = this.parseClassExpression();
  2342. }
  2343. else {
  2344. expr = this.throwUnexpectedToken(this.nextToken());
  2345. }
  2346. }
  2347. break;
  2348. default:
  2349. expr = this.throwUnexpectedToken(this.nextToken());
  2350. }
  2351. return expr;
  2352. };
  2353. // https://tc39.github.io/ecma262/#sec-array-initializer
  2354. Parser.prototype.parseSpreadElement = function () {
  2355. var node = this.createNode();
  2356. this.expect('...');
  2357. var arg = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2358. return this.finalize(node, new Node.SpreadElement(arg));
  2359. };
  2360. Parser.prototype.parseArrayInitializer = function () {
  2361. var node = this.createNode();
  2362. var elements = [];
  2363. this.expect('[');
  2364. while (!this.match(']')) {
  2365. if (this.match(',')) {
  2366. this.nextToken();
  2367. elements.push(null);
  2368. }
  2369. else if (this.match('...')) {
  2370. var element = this.parseSpreadElement();
  2371. if (!this.match(']')) {
  2372. this.context.isAssignmentTarget = false;
  2373. this.context.isBindingElement = false;
  2374. this.expect(',');
  2375. }
  2376. elements.push(element);
  2377. }
  2378. else {
  2379. elements.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
  2380. if (!this.match(']')) {
  2381. this.expect(',');
  2382. }
  2383. }
  2384. }
  2385. this.expect(']');
  2386. return this.finalize(node, new Node.ArrayExpression(elements));
  2387. };
  2388. // https://tc39.github.io/ecma262/#sec-object-initializer
  2389. Parser.prototype.parsePropertyMethod = function (params) {
  2390. this.context.isAssignmentTarget = false;
  2391. this.context.isBindingElement = false;
  2392. var previousStrict = this.context.strict;
  2393. var previousAllowStrictDirective = this.context.allowStrictDirective;
  2394. this.context.allowStrictDirective = params.simple;
  2395. var body = this.isolateCoverGrammar(this.parseFunctionSourceElements);
  2396. if (this.context.strict && params.firstRestricted) {
  2397. this.tolerateUnexpectedToken(params.firstRestricted, params.message);
  2398. }
  2399. if (this.context.strict && params.stricted) {
  2400. this.tolerateUnexpectedToken(params.stricted, params.message);
  2401. }
  2402. this.context.strict = previousStrict;
  2403. this.context.allowStrictDirective = previousAllowStrictDirective;
  2404. return body;
  2405. };
  2406. Parser.prototype.parsePropertyMethodFunction = function () {
  2407. var isGenerator = false;
  2408. var node = this.createNode();
  2409. var previousAllowYield = this.context.allowYield;
  2410. this.context.allowYield = false;
  2411. var params = this.parseFormalParameters();
  2412. var method = this.parsePropertyMethod(params);
  2413. this.context.allowYield = previousAllowYield;
  2414. return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
  2415. };
  2416. Parser.prototype.parsePropertyMethodAsyncFunction = function () {
  2417. var node = this.createNode();
  2418. var previousAllowYield = this.context.allowYield;
  2419. var previousAwait = this.context.await;
  2420. this.context.allowYield = false;
  2421. this.context.await = true;
  2422. var params = this.parseFormalParameters();
  2423. var method = this.parsePropertyMethod(params);
  2424. this.context.allowYield = previousAllowYield;
  2425. this.context.await = previousAwait;
  2426. return this.finalize(node, new Node.AsyncFunctionExpression(null, params.params, method));
  2427. };
  2428. Parser.prototype.parseObjectPropertyKey = function () {
  2429. var node = this.createNode();
  2430. var token = this.nextToken();
  2431. var key;
  2432. switch (token.type) {
  2433. case 8 /* StringLiteral */:
  2434. case 6 /* NumericLiteral */:
  2435. if (this.context.strict && token.octal) {
  2436. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictOctalLiteral);
  2437. }
  2438. var raw = this.getTokenRaw(token);
  2439. key = this.finalize(node, new Node.Literal(token.value, raw));
  2440. break;
  2441. case 3 /* Identifier */:
  2442. case 1 /* BooleanLiteral */:
  2443. case 5 /* NullLiteral */:
  2444. case 4 /* Keyword */:
  2445. key = this.finalize(node, new Node.Identifier(token.value));
  2446. break;
  2447. case 7 /* Punctuator */:
  2448. if (token.value === '[') {
  2449. key = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2450. this.expect(']');
  2451. }
  2452. else {
  2453. key = this.throwUnexpectedToken(token);
  2454. }
  2455. break;
  2456. default:
  2457. key = this.throwUnexpectedToken(token);
  2458. }
  2459. return key;
  2460. };
  2461. Parser.prototype.isPropertyKey = function (key, value) {
  2462. return (key.type === syntax_1.Syntax.Identifier && key.name === value) ||
  2463. (key.type === syntax_1.Syntax.Literal && key.value === value);
  2464. };
  2465. Parser.prototype.parseObjectProperty = function (hasProto) {
  2466. var node = this.createNode();
  2467. var token = this.lookahead;
  2468. var kind;
  2469. var key = null;
  2470. var value = null;
  2471. var computed = false;
  2472. var method = false;
  2473. var shorthand = false;
  2474. var isAsync = false;
  2475. if (token.type === 3 /* Identifier */) {
  2476. var id = token.value;
  2477. this.nextToken();
  2478. computed = this.match('[');
  2479. isAsync = !this.hasLineTerminator && (id === 'async') &&
  2480. !this.match(':') && !this.match('(') && !this.match('*');
  2481. key = isAsync ? this.parseObjectPropertyKey() : this.finalize(node, new Node.Identifier(id));
  2482. }
  2483. else if (this.match('*')) {
  2484. this.nextToken();
  2485. }
  2486. else {
  2487. computed = this.match('[');
  2488. key = this.parseObjectPropertyKey();
  2489. }
  2490. var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
  2491. if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'get' && lookaheadPropertyKey) {
  2492. kind = 'get';
  2493. computed = this.match('[');
  2494. key = this.parseObjectPropertyKey();
  2495. this.context.allowYield = false;
  2496. value = this.parseGetterMethod();
  2497. }
  2498. else if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'set' && lookaheadPropertyKey) {
  2499. kind = 'set';
  2500. computed = this.match('[');
  2501. key = this.parseObjectPropertyKey();
  2502. value = this.parseSetterMethod();
  2503. }
  2504. else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
  2505. kind = 'init';
  2506. computed = this.match('[');
  2507. key = this.parseObjectPropertyKey();
  2508. value = this.parseGeneratorMethod();
  2509. method = true;
  2510. }
  2511. else {
  2512. if (!key) {
  2513. this.throwUnexpectedToken(this.lookahead);
  2514. }
  2515. kind = 'init';
  2516. if (this.match(':') && !isAsync) {
  2517. if (!computed && this.isPropertyKey(key, '__proto__')) {
  2518. if (hasProto.value) {
  2519. this.tolerateError(messages_1.Messages.DuplicateProtoProperty);
  2520. }
  2521. hasProto.value = true;
  2522. }
  2523. this.nextToken();
  2524. value = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2525. }
  2526. else if (this.match('(')) {
  2527. value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
  2528. method = true;
  2529. }
  2530. else if (token.type === 3 /* Identifier */) {
  2531. var id = this.finalize(node, new Node.Identifier(token.value));
  2532. if (this.match('=')) {
  2533. this.context.firstCoverInitializedNameError = this.lookahead;
  2534. this.nextToken();
  2535. shorthand = true;
  2536. var init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2537. value = this.finalize(node, new Node.AssignmentPattern(id, init));
  2538. }
  2539. else {
  2540. shorthand = true;
  2541. value = id;
  2542. }
  2543. }
  2544. else {
  2545. this.throwUnexpectedToken(this.nextToken());
  2546. }
  2547. }
  2548. return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand));
  2549. };
  2550. Parser.prototype.parseObjectInitializer = function () {
  2551. var node = this.createNode();
  2552. this.expect('{');
  2553. var properties = [];
  2554. var hasProto = { value: false };
  2555. while (!this.match('}')) {
  2556. properties.push(this.parseObjectProperty(hasProto));
  2557. if (!this.match('}')) {
  2558. this.expectCommaSeparator();
  2559. }
  2560. }
  2561. this.expect('}');
  2562. return this.finalize(node, new Node.ObjectExpression(properties));
  2563. };
  2564. // https://tc39.github.io/ecma262/#sec-template-literals
  2565. Parser.prototype.parseTemplateHead = function () {
  2566. assert_1.assert(this.lookahead.head, 'Template literal must start with a template head');
  2567. var node = this.createNode();
  2568. var token = this.nextToken();
  2569. var raw = token.value;
  2570. var cooked = token.cooked;
  2571. return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
  2572. };
  2573. Parser.prototype.parseTemplateElement = function () {
  2574. if (this.lookahead.type !== 10 /* Template */) {
  2575. this.throwUnexpectedToken();
  2576. }
  2577. var node = this.createNode();
  2578. var token = this.nextToken();
  2579. var raw = token.value;
  2580. var cooked = token.cooked;
  2581. return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
  2582. };
  2583. Parser.prototype.parseTemplateLiteral = function () {
  2584. var node = this.createNode();
  2585. var expressions = [];
  2586. var quasis = [];
  2587. var quasi = this.parseTemplateHead();
  2588. quasis.push(quasi);
  2589. while (!quasi.tail) {
  2590. expressions.push(this.parseExpression());
  2591. quasi = this.parseTemplateElement();
  2592. quasis.push(quasi);
  2593. }
  2594. return this.finalize(node, new Node.TemplateLiteral(quasis, expressions));
  2595. };
  2596. // https://tc39.github.io/ecma262/#sec-grouping-operator
  2597. Parser.prototype.reinterpretExpressionAsPattern = function (expr) {
  2598. switch (expr.type) {
  2599. case syntax_1.Syntax.Identifier:
  2600. case syntax_1.Syntax.MemberExpression:
  2601. case syntax_1.Syntax.RestElement:
  2602. case syntax_1.Syntax.AssignmentPattern:
  2603. break;
  2604. case syntax_1.Syntax.SpreadElement:
  2605. expr.type = syntax_1.Syntax.RestElement;
  2606. this.reinterpretExpressionAsPattern(expr.argument);
  2607. break;
  2608. case syntax_1.Syntax.ArrayExpression:
  2609. expr.type = syntax_1.Syntax.ArrayPattern;
  2610. for (var i = 0; i < expr.elements.length; i++) {
  2611. if (expr.elements[i] !== null) {
  2612. this.reinterpretExpressionAsPattern(expr.elements[i]);
  2613. }
  2614. }
  2615. break;
  2616. case syntax_1.Syntax.ObjectExpression:
  2617. expr.type = syntax_1.Syntax.ObjectPattern;
  2618. for (var i = 0; i < expr.properties.length; i++) {
  2619. this.reinterpretExpressionAsPattern(expr.properties[i].value);
  2620. }
  2621. break;
  2622. case syntax_1.Syntax.AssignmentExpression:
  2623. expr.type = syntax_1.Syntax.AssignmentPattern;
  2624. delete expr.operator;
  2625. this.reinterpretExpressionAsPattern(expr.left);
  2626. break;
  2627. default:
  2628. // Allow other node type for tolerant parsing.
  2629. break;
  2630. }
  2631. };
  2632. Parser.prototype.parseGroupExpression = function () {
  2633. var expr;
  2634. this.expect('(');
  2635. if (this.match(')')) {
  2636. this.nextToken();
  2637. if (!this.match('=>')) {
  2638. this.expect('=>');
  2639. }
  2640. expr = {
  2641. type: ArrowParameterPlaceHolder,
  2642. params: [],
  2643. async: false
  2644. };
  2645. }
  2646. else {
  2647. var startToken = this.lookahead;
  2648. var params = [];
  2649. if (this.match('...')) {
  2650. expr = this.parseRestElement(params);
  2651. this.expect(')');
  2652. if (!this.match('=>')) {
  2653. this.expect('=>');
  2654. }
  2655. expr = {
  2656. type: ArrowParameterPlaceHolder,
  2657. params: [expr],
  2658. async: false
  2659. };
  2660. }
  2661. else {
  2662. var arrow = false;
  2663. this.context.isBindingElement = true;
  2664. expr = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2665. if (this.match(',')) {
  2666. var expressions = [];
  2667. this.context.isAssignmentTarget = false;
  2668. expressions.push(expr);
  2669. while (this.lookahead.type !== 2 /* EOF */) {
  2670. if (!this.match(',')) {
  2671. break;
  2672. }
  2673. this.nextToken();
  2674. if (this.match(')')) {
  2675. this.nextToken();
  2676. for (var i = 0; i < expressions.length; i++) {
  2677. this.reinterpretExpressionAsPattern(expressions[i]);
  2678. }
  2679. arrow = true;
  2680. expr = {
  2681. type: ArrowParameterPlaceHolder,
  2682. params: expressions,
  2683. async: false
  2684. };
  2685. }
  2686. else if (this.match('...')) {
  2687. if (!this.context.isBindingElement) {
  2688. this.throwUnexpectedToken(this.lookahead);
  2689. }
  2690. expressions.push(this.parseRestElement(params));
  2691. this.expect(')');
  2692. if (!this.match('=>')) {
  2693. this.expect('=>');
  2694. }
  2695. this.context.isBindingElement = false;
  2696. for (var i = 0; i < expressions.length; i++) {
  2697. this.reinterpretExpressionAsPattern(expressions[i]);
  2698. }
  2699. arrow = true;
  2700. expr = {
  2701. type: ArrowParameterPlaceHolder,
  2702. params: expressions,
  2703. async: false
  2704. };
  2705. }
  2706. else {
  2707. expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
  2708. }
  2709. if (arrow) {
  2710. break;
  2711. }
  2712. }
  2713. if (!arrow) {
  2714. expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
  2715. }
  2716. }
  2717. if (!arrow) {
  2718. this.expect(')');
  2719. if (this.match('=>')) {
  2720. if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') {
  2721. arrow = true;
  2722. expr = {
  2723. type: ArrowParameterPlaceHolder,
  2724. params: [expr],
  2725. async: false
  2726. };
  2727. }
  2728. if (!arrow) {
  2729. if (!this.context.isBindingElement) {
  2730. this.throwUnexpectedToken(this.lookahead);
  2731. }
  2732. if (expr.type === syntax_1.Syntax.SequenceExpression) {
  2733. for (var i = 0; i < expr.expressions.length; i++) {
  2734. this.reinterpretExpressionAsPattern(expr.expressions[i]);
  2735. }
  2736. }
  2737. else {
  2738. this.reinterpretExpressionAsPattern(expr);
  2739. }
  2740. var parameters = (expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr]);
  2741. expr = {
  2742. type: ArrowParameterPlaceHolder,
  2743. params: parameters,
  2744. async: false
  2745. };
  2746. }
  2747. }
  2748. this.context.isBindingElement = false;
  2749. }
  2750. }
  2751. }
  2752. return expr;
  2753. };
  2754. // https://tc39.github.io/ecma262/#sec-left-hand-side-expressions
  2755. Parser.prototype.parseArguments = function () {
  2756. this.expect('(');
  2757. var args = [];
  2758. if (!this.match(')')) {
  2759. while (true) {
  2760. var expr = this.match('...') ? this.parseSpreadElement() :
  2761. this.isolateCoverGrammar(this.parseAssignmentExpression);
  2762. args.push(expr);
  2763. if (this.match(')')) {
  2764. break;
  2765. }
  2766. this.expectCommaSeparator();
  2767. if (this.match(')')) {
  2768. break;
  2769. }
  2770. }
  2771. }
  2772. this.expect(')');
  2773. return args;
  2774. };
  2775. Parser.prototype.isIdentifierName = function (token) {
  2776. return token.type === 3 /* Identifier */ ||
  2777. token.type === 4 /* Keyword */ ||
  2778. token.type === 1 /* BooleanLiteral */ ||
  2779. token.type === 5 /* NullLiteral */;
  2780. };
  2781. Parser.prototype.parseIdentifierName = function () {
  2782. var node = this.createNode();
  2783. var token = this.nextToken();
  2784. if (!this.isIdentifierName(token)) {
  2785. this.throwUnexpectedToken(token);
  2786. }
  2787. return this.finalize(node, new Node.Identifier(token.value));
  2788. };
  2789. Parser.prototype.parseNewExpression = function () {
  2790. var node = this.createNode();
  2791. var id = this.parseIdentifierName();
  2792. assert_1.assert(id.name === 'new', 'New expression must start with `new`');
  2793. var expr;
  2794. if (this.match('.')) {
  2795. this.nextToken();
  2796. if (this.lookahead.type === 3 /* Identifier */ && this.context.inFunctionBody && this.lookahead.value === 'target') {
  2797. var property = this.parseIdentifierName();
  2798. expr = new Node.MetaProperty(id, property);
  2799. }
  2800. else {
  2801. this.throwUnexpectedToken(this.lookahead);
  2802. }
  2803. }
  2804. else {
  2805. var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
  2806. var args = this.match('(') ? this.parseArguments() : [];
  2807. expr = new Node.NewExpression(callee, args);
  2808. this.context.isAssignmentTarget = false;
  2809. this.context.isBindingElement = false;
  2810. }
  2811. return this.finalize(node, expr);
  2812. };
  2813. Parser.prototype.parseAsyncArgument = function () {
  2814. var arg = this.parseAssignmentExpression();
  2815. this.context.firstCoverInitializedNameError = null;
  2816. return arg;
  2817. };
  2818. Parser.prototype.parseAsyncArguments = function () {
  2819. this.expect('(');
  2820. var args = [];
  2821. if (!this.match(')')) {
  2822. while (true) {
  2823. var expr = this.match('...') ? this.parseSpreadElement() :
  2824. this.isolateCoverGrammar(this.parseAsyncArgument);
  2825. args.push(expr);
  2826. if (this.match(')')) {
  2827. break;
  2828. }
  2829. this.expectCommaSeparator();
  2830. if (this.match(')')) {
  2831. break;
  2832. }
  2833. }
  2834. }
  2835. this.expect(')');
  2836. return args;
  2837. };
  2838. Parser.prototype.parseLeftHandSideExpressionAllowCall = function () {
  2839. var startToken = this.lookahead;
  2840. var maybeAsync = this.matchContextualKeyword('async');
  2841. var previousAllowIn = this.context.allowIn;
  2842. this.context.allowIn = true;
  2843. var expr;
  2844. if (this.matchKeyword('super') && this.context.inFunctionBody) {
  2845. expr = this.createNode();
  2846. this.nextToken();
  2847. expr = this.finalize(expr, new Node.Super());
  2848. if (!this.match('(') && !this.match('.') && !this.match('[')) {
  2849. this.throwUnexpectedToken(this.lookahead);
  2850. }
  2851. }
  2852. else {
  2853. expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
  2854. }
  2855. while (true) {
  2856. if (this.match('.')) {
  2857. this.context.isBindingElement = false;
  2858. this.context.isAssignmentTarget = true;
  2859. this.expect('.');
  2860. var property = this.parseIdentifierName();
  2861. expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property));
  2862. }
  2863. else if (this.match('(')) {
  2864. var asyncArrow = maybeAsync && (startToken.lineNumber === this.lookahead.lineNumber);
  2865. this.context.isBindingElement = false;
  2866. this.context.isAssignmentTarget = false;
  2867. var args = asyncArrow ? this.parseAsyncArguments() : this.parseArguments();
  2868. expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args));
  2869. if (asyncArrow && this.match('=>')) {
  2870. for (var i = 0; i < args.length; ++i) {
  2871. this.reinterpretExpressionAsPattern(args[i]);
  2872. }
  2873. expr = {
  2874. type: ArrowParameterPlaceHolder,
  2875. params: args,
  2876. async: true
  2877. };
  2878. }
  2879. }
  2880. else if (this.match('[')) {
  2881. this.context.isBindingElement = false;
  2882. this.context.isAssignmentTarget = true;
  2883. this.expect('[');
  2884. var property = this.isolateCoverGrammar(this.parseExpression);
  2885. this.expect(']');
  2886. expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property));
  2887. }
  2888. else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
  2889. var quasi = this.parseTemplateLiteral();
  2890. expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi));
  2891. }
  2892. else {
  2893. break;
  2894. }
  2895. }
  2896. this.context.allowIn = previousAllowIn;
  2897. return expr;
  2898. };
  2899. Parser.prototype.parseSuper = function () {
  2900. var node = this.createNode();
  2901. this.expectKeyword('super');
  2902. if (!this.match('[') && !this.match('.')) {
  2903. this.throwUnexpectedToken(this.lookahead);
  2904. }
  2905. return this.finalize(node, new Node.Super());
  2906. };
  2907. Parser.prototype.parseLeftHandSideExpression = function () {
  2908. assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
  2909. var node = this.startNode(this.lookahead);
  2910. var expr = (this.matchKeyword('super') && this.context.inFunctionBody) ? this.parseSuper() :
  2911. this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
  2912. while (true) {
  2913. if (this.match('[')) {
  2914. this.context.isBindingElement = false;
  2915. this.context.isAssignmentTarget = true;
  2916. this.expect('[');
  2917. var property = this.isolateCoverGrammar(this.parseExpression);
  2918. this.expect(']');
  2919. expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property));
  2920. }
  2921. else if (this.match('.')) {
  2922. this.context.isBindingElement = false;
  2923. this.context.isAssignmentTarget = true;
  2924. this.expect('.');
  2925. var property = this.parseIdentifierName();
  2926. expr = this.finalize(node, new Node.StaticMemberExpression(expr, property));
  2927. }
  2928. else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
  2929. var quasi = this.parseTemplateLiteral();
  2930. expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi));
  2931. }
  2932. else {
  2933. break;
  2934. }
  2935. }
  2936. return expr;
  2937. };
  2938. // https://tc39.github.io/ecma262/#sec-update-expressions
  2939. Parser.prototype.parseUpdateExpression = function () {
  2940. var expr;
  2941. var startToken = this.lookahead;
  2942. if (this.match('++') || this.match('--')) {
  2943. var node = this.startNode(startToken);
  2944. var token = this.nextToken();
  2945. expr = this.inheritCoverGrammar(this.parseUnaryExpression);
  2946. if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
  2947. this.tolerateError(messages_1.Messages.StrictLHSPrefix);
  2948. }
  2949. if (!this.context.isAssignmentTarget) {
  2950. this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
  2951. }
  2952. var prefix = true;
  2953. expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
  2954. this.context.isAssignmentTarget = false;
  2955. this.context.isBindingElement = false;
  2956. }
  2957. else {
  2958. expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  2959. if (!this.hasLineTerminator && this.lookahead.type === 7 /* Punctuator */) {
  2960. if (this.match('++') || this.match('--')) {
  2961. if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
  2962. this.tolerateError(messages_1.Messages.StrictLHSPostfix);
  2963. }
  2964. if (!this.context.isAssignmentTarget) {
  2965. this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
  2966. }
  2967. this.context.isAssignmentTarget = false;
  2968. this.context.isBindingElement = false;
  2969. var operator = this.nextToken().value;
  2970. var prefix = false;
  2971. expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix));
  2972. }
  2973. }
  2974. }
  2975. return expr;
  2976. };
  2977. // https://tc39.github.io/ecma262/#sec-unary-operators
  2978. Parser.prototype.parseAwaitExpression = function () {
  2979. var node = this.createNode();
  2980. this.nextToken();
  2981. var argument = this.parseUnaryExpression();
  2982. return this.finalize(node, new Node.AwaitExpression(argument));
  2983. };
  2984. Parser.prototype.parseUnaryExpression = function () {
  2985. var expr;
  2986. if (this.match('+') || this.match('-') || this.match('~') || this.match('!') ||
  2987. this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
  2988. var node = this.startNode(this.lookahead);
  2989. var token = this.nextToken();
  2990. expr = this.inheritCoverGrammar(this.parseUnaryExpression);
  2991. expr = this.finalize(node, new Node.UnaryExpression(token.value, expr));
  2992. if (this.context.strict && expr.operator === 'delete' && expr.argument.type === syntax_1.Syntax.Identifier) {
  2993. this.tolerateError(messages_1.Messages.StrictDelete);
  2994. }
  2995. this.context.isAssignmentTarget = false;
  2996. this.context.isBindingElement = false;
  2997. }
  2998. else if (this.context.await && this.matchContextualKeyword('await')) {
  2999. expr = this.parseAwaitExpression();
  3000. }
  3001. else {
  3002. expr = this.parseUpdateExpression();
  3003. }
  3004. return expr;
  3005. };
  3006. Parser.prototype.parseExponentiationExpression = function () {
  3007. var startToken = this.lookahead;
  3008. var expr = this.inheritCoverGrammar(this.parseUnaryExpression);
  3009. if (expr.type !== syntax_1.Syntax.UnaryExpression && this.match('**')) {
  3010. this.nextToken();
  3011. this.context.isAssignmentTarget = false;
  3012. this.context.isBindingElement = false;
  3013. var left = expr;
  3014. var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
  3015. expr = this.finalize(this.startNode(startToken), new Node.BinaryExpression('**', left, right));
  3016. }
  3017. return expr;
  3018. };
  3019. // https://tc39.github.io/ecma262/#sec-exp-operator
  3020. // https://tc39.github.io/ecma262/#sec-multiplicative-operators
  3021. // https://tc39.github.io/ecma262/#sec-additive-operators
  3022. // https://tc39.github.io/ecma262/#sec-bitwise-shift-operators
  3023. // https://tc39.github.io/ecma262/#sec-relational-operators
  3024. // https://tc39.github.io/ecma262/#sec-equality-operators
  3025. // https://tc39.github.io/ecma262/#sec-binary-bitwise-operators
  3026. // https://tc39.github.io/ecma262/#sec-binary-logical-operators
  3027. Parser.prototype.binaryPrecedence = function (token) {
  3028. var op = token.value;
  3029. var precedence;
  3030. if (token.type === 7 /* Punctuator */) {
  3031. precedence = this.operatorPrecedence[op] || 0;
  3032. }
  3033. else if (token.type === 4 /* Keyword */) {
  3034. precedence = (op === 'instanceof' || (this.context.allowIn && op === 'in')) ? 7 : 0;
  3035. }
  3036. else {
  3037. precedence = 0;
  3038. }
  3039. return precedence;
  3040. };
  3041. Parser.prototype.parseBinaryExpression = function () {
  3042. var startToken = this.lookahead;
  3043. var expr = this.inheritCoverGrammar(this.parseExponentiationExpression);
  3044. var token = this.lookahead;
  3045. var prec = this.binaryPrecedence(token);
  3046. if (prec > 0) {
  3047. this.nextToken();
  3048. this.context.isAssignmentTarget = false;
  3049. this.context.isBindingElement = false;
  3050. var markers = [startToken, this.lookahead];
  3051. var left = expr;
  3052. var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
  3053. var stack = [left, token.value, right];
  3054. var precedences = [prec];
  3055. while (true) {
  3056. prec = this.binaryPrecedence(this.lookahead);
  3057. if (prec <= 0) {
  3058. break;
  3059. }
  3060. // Reduce: make a binary expression from the three topmost entries.
  3061. while ((stack.length > 2) && (prec <= precedences[precedences.length - 1])) {
  3062. right = stack.pop();
  3063. var operator = stack.pop();
  3064. precedences.pop();
  3065. left = stack.pop();
  3066. markers.pop();
  3067. var node = this.startNode(markers[markers.length - 1]);
  3068. stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right)));
  3069. }
  3070. // Shift.
  3071. stack.push(this.nextToken().value);
  3072. precedences.push(prec);
  3073. markers.push(this.lookahead);
  3074. stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
  3075. }
  3076. // Final reduce to clean-up the stack.
  3077. var i = stack.length - 1;
  3078. expr = stack[i];
  3079. markers.pop();
  3080. while (i > 1) {
  3081. var node = this.startNode(markers.pop());
  3082. var operator = stack[i - 1];
  3083. expr = this.finalize(node, new Node.BinaryExpression(operator, stack[i - 2], expr));
  3084. i -= 2;
  3085. }
  3086. }
  3087. return expr;
  3088. };
  3089. // https://tc39.github.io/ecma262/#sec-conditional-operator
  3090. Parser.prototype.parseConditionalExpression = function () {
  3091. var startToken = this.lookahead;
  3092. var expr = this.inheritCoverGrammar(this.parseBinaryExpression);
  3093. if (this.match('?')) {
  3094. this.nextToken();
  3095. var previousAllowIn = this.context.allowIn;
  3096. this.context.allowIn = true;
  3097. var consequent = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3098. this.context.allowIn = previousAllowIn;
  3099. this.expect(':');
  3100. var alternate = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3101. expr = this.finalize(this.startNode(startToken), new Node.ConditionalExpression(expr, consequent, alternate));
  3102. this.context.isAssignmentTarget = false;
  3103. this.context.isBindingElement = false;
  3104. }
  3105. return expr;
  3106. };
  3107. // https://tc39.github.io/ecma262/#sec-assignment-operators
  3108. Parser.prototype.checkPatternParam = function (options, param) {
  3109. switch (param.type) {
  3110. case syntax_1.Syntax.Identifier:
  3111. this.validateParam(options, param, param.name);
  3112. break;
  3113. case syntax_1.Syntax.RestElement:
  3114. this.checkPatternParam(options, param.argument);
  3115. break;
  3116. case syntax_1.Syntax.AssignmentPattern:
  3117. this.checkPatternParam(options, param.left);
  3118. break;
  3119. case syntax_1.Syntax.ArrayPattern:
  3120. for (var i = 0; i < param.elements.length; i++) {
  3121. if (param.elements[i] !== null) {
  3122. this.checkPatternParam(options, param.elements[i]);
  3123. }
  3124. }
  3125. break;
  3126. case syntax_1.Syntax.ObjectPattern:
  3127. for (var i = 0; i < param.properties.length; i++) {
  3128. this.checkPatternParam(options, param.properties[i].value);
  3129. }
  3130. break;
  3131. default:
  3132. break;
  3133. }
  3134. options.simple = options.simple && (param instanceof Node.Identifier);
  3135. };
  3136. Parser.prototype.reinterpretAsCoverFormalsList = function (expr) {
  3137. var params = [expr];
  3138. var options;
  3139. var asyncArrow = false;
  3140. switch (expr.type) {
  3141. case syntax_1.Syntax.Identifier:
  3142. break;
  3143. case ArrowParameterPlaceHolder:
  3144. params = expr.params;
  3145. asyncArrow = expr.async;
  3146. break;
  3147. default:
  3148. return null;
  3149. }
  3150. options = {
  3151. simple: true,
  3152. paramSet: {}
  3153. };
  3154. for (var i = 0; i < params.length; ++i) {
  3155. var param = params[i];
  3156. if (param.type === syntax_1.Syntax.AssignmentPattern) {
  3157. if (param.right.type === syntax_1.Syntax.YieldExpression) {
  3158. if (param.right.argument) {
  3159. this.throwUnexpectedToken(this.lookahead);
  3160. }
  3161. param.right.type = syntax_1.Syntax.Identifier;
  3162. param.right.name = 'yield';
  3163. delete param.right.argument;
  3164. delete param.right.delegate;
  3165. }
  3166. }
  3167. else if (asyncArrow && param.type === syntax_1.Syntax.Identifier && param.name === 'await') {
  3168. this.throwUnexpectedToken(this.lookahead);
  3169. }
  3170. this.checkPatternParam(options, param);
  3171. params[i] = param;
  3172. }
  3173. if (this.context.strict || !this.context.allowYield) {
  3174. for (var i = 0; i < params.length; ++i) {
  3175. var param = params[i];
  3176. if (param.type === syntax_1.Syntax.YieldExpression) {
  3177. this.throwUnexpectedToken(this.lookahead);
  3178. }
  3179. }
  3180. }
  3181. if (options.message === messages_1.Messages.StrictParamDupe) {
  3182. var token = this.context.strict ? options.stricted : options.firstRestricted;
  3183. this.throwUnexpectedToken(token, options.message);
  3184. }
  3185. return {
  3186. simple: options.simple,
  3187. params: params,
  3188. stricted: options.stricted,
  3189. firstRestricted: options.firstRestricted,
  3190. message: options.message
  3191. };
  3192. };
  3193. Parser.prototype.parseAssignmentExpression = function () {
  3194. var expr;
  3195. if (!this.context.allowYield && this.matchKeyword('yield')) {
  3196. expr = this.parseYieldExpression();
  3197. }
  3198. else {
  3199. var startToken = this.lookahead;
  3200. var token = startToken;
  3201. expr = this.parseConditionalExpression();
  3202. if (token.type === 3 /* Identifier */ && (token.lineNumber === this.lookahead.lineNumber) && token.value === 'async') {
  3203. if (this.lookahead.type === 3 /* Identifier */ || this.matchKeyword('yield')) {
  3204. var arg = this.parsePrimaryExpression();
  3205. this.reinterpretExpressionAsPattern(arg);
  3206. expr = {
  3207. type: ArrowParameterPlaceHolder,
  3208. params: [arg],
  3209. async: true
  3210. };
  3211. }
  3212. }
  3213. if (expr.type === ArrowParameterPlaceHolder || this.match('=>')) {
  3214. // https://tc39.github.io/ecma262/#sec-arrow-function-definitions
  3215. this.context.isAssignmentTarget = false;
  3216. this.context.isBindingElement = false;
  3217. var isAsync = expr.async;
  3218. var list = this.reinterpretAsCoverFormalsList(expr);
  3219. if (list) {
  3220. if (this.hasLineTerminator) {
  3221. this.tolerateUnexpectedToken(this.lookahead);
  3222. }
  3223. this.context.firstCoverInitializedNameError = null;
  3224. var previousStrict = this.context.strict;
  3225. var previousAllowStrictDirective = this.context.allowStrictDirective;
  3226. this.context.allowStrictDirective = list.simple;
  3227. var previousAllowYield = this.context.allowYield;
  3228. var previousAwait = this.context.await;
  3229. this.context.allowYield = true;
  3230. this.context.await = isAsync;
  3231. var node = this.startNode(startToken);
  3232. this.expect('=>');
  3233. var body = void 0;
  3234. if (this.match('{')) {
  3235. var previousAllowIn = this.context.allowIn;
  3236. this.context.allowIn = true;
  3237. body = this.parseFunctionSourceElements();
  3238. this.context.allowIn = previousAllowIn;
  3239. }
  3240. else {
  3241. body = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3242. }
  3243. var expression = body.type !== syntax_1.Syntax.BlockStatement;
  3244. if (this.context.strict && list.firstRestricted) {
  3245. this.throwUnexpectedToken(list.firstRestricted, list.message);
  3246. }
  3247. if (this.context.strict && list.stricted) {
  3248. this.tolerateUnexpectedToken(list.stricted, list.message);
  3249. }
  3250. expr = isAsync ? this.finalize(node, new Node.AsyncArrowFunctionExpression(list.params, body, expression)) :
  3251. this.finalize(node, new Node.ArrowFunctionExpression(list.params, body, expression));
  3252. this.context.strict = previousStrict;
  3253. this.context.allowStrictDirective = previousAllowStrictDirective;
  3254. this.context.allowYield = previousAllowYield;
  3255. this.context.await = previousAwait;
  3256. }
  3257. }
  3258. else {
  3259. if (this.matchAssign()) {
  3260. if (!this.context.isAssignmentTarget) {
  3261. this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
  3262. }
  3263. if (this.context.strict && expr.type === syntax_1.Syntax.Identifier) {
  3264. var id = expr;
  3265. if (this.scanner.isRestrictedWord(id.name)) {
  3266. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictLHSAssignment);
  3267. }
  3268. if (this.scanner.isStrictModeReservedWord(id.name)) {
  3269. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
  3270. }
  3271. }
  3272. if (!this.match('=')) {
  3273. this.context.isAssignmentTarget = false;
  3274. this.context.isBindingElement = false;
  3275. }
  3276. else {
  3277. this.reinterpretExpressionAsPattern(expr);
  3278. }
  3279. token = this.nextToken();
  3280. var operator = token.value;
  3281. var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3282. expr = this.finalize(this.startNode(startToken), new Node.AssignmentExpression(operator, expr, right));
  3283. this.context.firstCoverInitializedNameError = null;
  3284. }
  3285. }
  3286. }
  3287. return expr;
  3288. };
  3289. // https://tc39.github.io/ecma262/#sec-comma-operator
  3290. Parser.prototype.parseExpression = function () {
  3291. var startToken = this.lookahead;
  3292. var expr = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3293. if (this.match(',')) {
  3294. var expressions = [];
  3295. expressions.push(expr);
  3296. while (this.lookahead.type !== 2 /* EOF */) {
  3297. if (!this.match(',')) {
  3298. break;
  3299. }
  3300. this.nextToken();
  3301. expressions.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  3302. }
  3303. expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
  3304. }
  3305. return expr;
  3306. };
  3307. // https://tc39.github.io/ecma262/#sec-block
  3308. Parser.prototype.parseStatementListItem = function () {
  3309. var statement;
  3310. this.context.isAssignmentTarget = true;
  3311. this.context.isBindingElement = true;
  3312. if (this.lookahead.type === 4 /* Keyword */) {
  3313. switch (this.lookahead.value) {
  3314. case 'export':
  3315. if (!this.context.isModule) {
  3316. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalExportDeclaration);
  3317. }
  3318. statement = this.parseExportDeclaration();
  3319. break;
  3320. case 'import':
  3321. if (!this.context.isModule) {
  3322. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalImportDeclaration);
  3323. }
  3324. statement = this.parseImportDeclaration();
  3325. break;
  3326. case 'const':
  3327. statement = this.parseLexicalDeclaration({ inFor: false });
  3328. break;
  3329. case 'function':
  3330. statement = this.parseFunctionDeclaration();
  3331. break;
  3332. case 'class':
  3333. statement = this.parseClassDeclaration();
  3334. break;
  3335. case 'let':
  3336. statement = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({ inFor: false }) : this.parseStatement();
  3337. break;
  3338. default:
  3339. statement = this.parseStatement();
  3340. break;
  3341. }
  3342. }
  3343. else {
  3344. statement = this.parseStatement();
  3345. }
  3346. return statement;
  3347. };
  3348. Parser.prototype.parseBlock = function () {
  3349. var node = this.createNode();
  3350. this.expect('{');
  3351. var block = [];
  3352. while (true) {
  3353. if (this.match('}')) {
  3354. break;
  3355. }
  3356. block.push(this.parseStatementListItem());
  3357. }
  3358. this.expect('}');
  3359. return this.finalize(node, new Node.BlockStatement(block));
  3360. };
  3361. // https://tc39.github.io/ecma262/#sec-let-and-const-declarations
  3362. Parser.prototype.parseLexicalBinding = function (kind, options) {
  3363. var node = this.createNode();
  3364. var params = [];
  3365. var id = this.parsePattern(params, kind);
  3366. if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
  3367. if (this.scanner.isRestrictedWord(id.name)) {
  3368. this.tolerateError(messages_1.Messages.StrictVarName);
  3369. }
  3370. }
  3371. var init = null;
  3372. if (kind === 'const') {
  3373. if (!this.matchKeyword('in') && !this.matchContextualKeyword('of')) {
  3374. if (this.match('=')) {
  3375. this.nextToken();
  3376. init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3377. }
  3378. else {
  3379. this.throwError(messages_1.Messages.DeclarationMissingInitializer, 'const');
  3380. }
  3381. }
  3382. }
  3383. else if ((!options.inFor && id.type !== syntax_1.Syntax.Identifier) || this.match('=')) {
  3384. this.expect('=');
  3385. init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3386. }
  3387. return this.finalize(node, new Node.VariableDeclarator(id, init));
  3388. };
  3389. Parser.prototype.parseBindingList = function (kind, options) {
  3390. var list = [this.parseLexicalBinding(kind, options)];
  3391. while (this.match(',')) {
  3392. this.nextToken();
  3393. list.push(this.parseLexicalBinding(kind, options));
  3394. }
  3395. return list;
  3396. };
  3397. Parser.prototype.isLexicalDeclaration = function () {
  3398. var state = this.scanner.saveState();
  3399. this.scanner.scanComments();
  3400. var next = this.scanner.lex();
  3401. this.scanner.restoreState(state);
  3402. return (next.type === 3 /* Identifier */) ||
  3403. (next.type === 7 /* Punctuator */ && next.value === '[') ||
  3404. (next.type === 7 /* Punctuator */ && next.value === '{') ||
  3405. (next.type === 4 /* Keyword */ && next.value === 'let') ||
  3406. (next.type === 4 /* Keyword */ && next.value === 'yield');
  3407. };
  3408. Parser.prototype.parseLexicalDeclaration = function (options) {
  3409. var node = this.createNode();
  3410. var kind = this.nextToken().value;
  3411. assert_1.assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
  3412. var declarations = this.parseBindingList(kind, options);
  3413. this.consumeSemicolon();
  3414. return this.finalize(node, new Node.VariableDeclaration(declarations, kind));
  3415. };
  3416. // https://tc39.github.io/ecma262/#sec-destructuring-binding-patterns
  3417. Parser.prototype.parseBindingRestElement = function (params, kind) {
  3418. var node = this.createNode();
  3419. this.expect('...');
  3420. var arg = this.parsePattern(params, kind);
  3421. return this.finalize(node, new Node.RestElement(arg));
  3422. };
  3423. Parser.prototype.parseArrayPattern = function (params, kind) {
  3424. var node = this.createNode();
  3425. this.expect('[');
  3426. var elements = [];
  3427. while (!this.match(']')) {
  3428. if (this.match(',')) {
  3429. this.nextToken();
  3430. elements.push(null);
  3431. }
  3432. else {
  3433. if (this.match('...')) {
  3434. elements.push(this.parseBindingRestElement(params, kind));
  3435. break;
  3436. }
  3437. else {
  3438. elements.push(this.parsePatternWithDefault(params, kind));
  3439. }
  3440. if (!this.match(']')) {
  3441. this.expect(',');
  3442. }
  3443. }
  3444. }
  3445. this.expect(']');
  3446. return this.finalize(node, new Node.ArrayPattern(elements));
  3447. };
  3448. Parser.prototype.parsePropertyPattern = function (params, kind) {
  3449. var node = this.createNode();
  3450. var computed = false;
  3451. var shorthand = false;
  3452. var method = false;
  3453. var key;
  3454. var value;
  3455. if (this.lookahead.type === 3 /* Identifier */) {
  3456. var keyToken = this.lookahead;
  3457. key = this.parseVariableIdentifier();
  3458. var init = this.finalize(node, new Node.Identifier(keyToken.value));
  3459. if (this.match('=')) {
  3460. params.push(keyToken);
  3461. shorthand = true;
  3462. this.nextToken();
  3463. var expr = this.parseAssignmentExpression();
  3464. value = this.finalize(this.startNode(keyToken), new Node.AssignmentPattern(init, expr));
  3465. }
  3466. else if (!this.match(':')) {
  3467. params.push(keyToken);
  3468. shorthand = true;
  3469. value = init;
  3470. }
  3471. else {
  3472. this.expect(':');
  3473. value = this.parsePatternWithDefault(params, kind);
  3474. }
  3475. }
  3476. else {
  3477. computed = this.match('[');
  3478. key = this.parseObjectPropertyKey();
  3479. this.expect(':');
  3480. value = this.parsePatternWithDefault(params, kind);
  3481. }
  3482. return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand));
  3483. };
  3484. Parser.prototype.parseObjectPattern = function (params, kind) {
  3485. var node = this.createNode();
  3486. var properties = [];
  3487. this.expect('{');
  3488. while (!this.match('}')) {
  3489. properties.push(this.parsePropertyPattern(params, kind));
  3490. if (!this.match('}')) {
  3491. this.expect(',');
  3492. }
  3493. }
  3494. this.expect('}');
  3495. return this.finalize(node, new Node.ObjectPattern(properties));
  3496. };
  3497. Parser.prototype.parsePattern = function (params, kind) {
  3498. var pattern;
  3499. if (this.match('[')) {
  3500. pattern = this.parseArrayPattern(params, kind);
  3501. }
  3502. else if (this.match('{')) {
  3503. pattern = this.parseObjectPattern(params, kind);
  3504. }
  3505. else {
  3506. if (this.matchKeyword('let') && (kind === 'const' || kind === 'let')) {
  3507. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.LetInLexicalBinding);
  3508. }
  3509. params.push(this.lookahead);
  3510. pattern = this.parseVariableIdentifier(kind);
  3511. }
  3512. return pattern;
  3513. };
  3514. Parser.prototype.parsePatternWithDefault = function (params, kind) {
  3515. var startToken = this.lookahead;
  3516. var pattern = this.parsePattern(params, kind);
  3517. if (this.match('=')) {
  3518. this.nextToken();
  3519. var previousAllowYield = this.context.allowYield;
  3520. this.context.allowYield = true;
  3521. var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3522. this.context.allowYield = previousAllowYield;
  3523. pattern = this.finalize(this.startNode(startToken), new Node.AssignmentPattern(pattern, right));
  3524. }
  3525. return pattern;
  3526. };
  3527. // https://tc39.github.io/ecma262/#sec-variable-statement
  3528. Parser.prototype.parseVariableIdentifier = function (kind) {
  3529. var node = this.createNode();
  3530. var token = this.nextToken();
  3531. if (token.type === 4 /* Keyword */ && token.value === 'yield') {
  3532. if (this.context.strict) {
  3533. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
  3534. }
  3535. else if (!this.context.allowYield) {
  3536. this.throwUnexpectedToken(token);
  3537. }
  3538. }
  3539. else if (token.type !== 3 /* Identifier */) {
  3540. if (this.context.strict && token.type === 4 /* Keyword */ && this.scanner.isStrictModeReservedWord(token.value)) {
  3541. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
  3542. }
  3543. else {
  3544. if (this.context.strict || token.value !== 'let' || kind !== 'var') {
  3545. this.throwUnexpectedToken(token);
  3546. }
  3547. }
  3548. }
  3549. else if ((this.context.isModule || this.context.await) && token.type === 3 /* Identifier */ && token.value === 'await') {
  3550. this.tolerateUnexpectedToken(token);
  3551. }
  3552. return this.finalize(node, new Node.Identifier(token.value));
  3553. };
  3554. Parser.prototype.parseVariableDeclaration = function (options) {
  3555. var node = this.createNode();
  3556. var params = [];
  3557. var id = this.parsePattern(params, 'var');
  3558. if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
  3559. if (this.scanner.isRestrictedWord(id.name)) {
  3560. this.tolerateError(messages_1.Messages.StrictVarName);
  3561. }
  3562. }
  3563. var init = null;
  3564. if (this.match('=')) {
  3565. this.nextToken();
  3566. init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3567. }
  3568. else if (id.type !== syntax_1.Syntax.Identifier && !options.inFor) {
  3569. this.expect('=');
  3570. }
  3571. return this.finalize(node, new Node.VariableDeclarator(id, init));
  3572. };
  3573. Parser.prototype.parseVariableDeclarationList = function (options) {
  3574. var opt = { inFor: options.inFor };
  3575. var list = [];
  3576. list.push(this.parseVariableDeclaration(opt));
  3577. while (this.match(',')) {
  3578. this.nextToken();
  3579. list.push(this.parseVariableDeclaration(opt));
  3580. }
  3581. return list;
  3582. };
  3583. Parser.prototype.parseVariableStatement = function () {
  3584. var node = this.createNode();
  3585. this.expectKeyword('var');
  3586. var declarations = this.parseVariableDeclarationList({ inFor: false });
  3587. this.consumeSemicolon();
  3588. return this.finalize(node, new Node.VariableDeclaration(declarations, 'var'));
  3589. };
  3590. // https://tc39.github.io/ecma262/#sec-empty-statement
  3591. Parser.prototype.parseEmptyStatement = function () {
  3592. var node = this.createNode();
  3593. this.expect(';');
  3594. return this.finalize(node, new Node.EmptyStatement());
  3595. };
  3596. // https://tc39.github.io/ecma262/#sec-expression-statement
  3597. Parser.prototype.parseExpressionStatement = function () {
  3598. var node = this.createNode();
  3599. var expr = this.parseExpression();
  3600. this.consumeSemicolon();
  3601. return this.finalize(node, new Node.ExpressionStatement(expr));
  3602. };
  3603. // https://tc39.github.io/ecma262/#sec-if-statement
  3604. Parser.prototype.parseIfClause = function () {
  3605. if (this.context.strict && this.matchKeyword('function')) {
  3606. this.tolerateError(messages_1.Messages.StrictFunction);
  3607. }
  3608. return this.parseStatement();
  3609. };
  3610. Parser.prototype.parseIfStatement = function () {
  3611. var node = this.createNode();
  3612. var consequent;
  3613. var alternate = null;
  3614. this.expectKeyword('if');
  3615. this.expect('(');
  3616. var test = this.parseExpression();
  3617. if (!this.match(')') && this.config.tolerant) {
  3618. this.tolerateUnexpectedToken(this.nextToken());
  3619. consequent = this.finalize(this.createNode(), new Node.EmptyStatement());
  3620. }
  3621. else {
  3622. this.expect(')');
  3623. consequent = this.parseIfClause();
  3624. if (this.matchKeyword('else')) {
  3625. this.nextToken();
  3626. alternate = this.parseIfClause();
  3627. }
  3628. }
  3629. return this.finalize(node, new Node.IfStatement(test, consequent, alternate));
  3630. };
  3631. // https://tc39.github.io/ecma262/#sec-do-while-statement
  3632. Parser.prototype.parseDoWhileStatement = function () {
  3633. var node = this.createNode();
  3634. this.expectKeyword('do');
  3635. var previousInIteration = this.context.inIteration;
  3636. this.context.inIteration = true;
  3637. var body = this.parseStatement();
  3638. this.context.inIteration = previousInIteration;
  3639. this.expectKeyword('while');
  3640. this.expect('(');
  3641. var test = this.parseExpression();
  3642. if (!this.match(')') && this.config.tolerant) {
  3643. this.tolerateUnexpectedToken(this.nextToken());
  3644. }
  3645. else {
  3646. this.expect(')');
  3647. if (this.match(';')) {
  3648. this.nextToken();
  3649. }
  3650. }
  3651. return this.finalize(node, new Node.DoWhileStatement(body, test));
  3652. };
  3653. // https://tc39.github.io/ecma262/#sec-while-statement
  3654. Parser.prototype.parseWhileStatement = function () {
  3655. var node = this.createNode();
  3656. var body;
  3657. this.expectKeyword('while');
  3658. this.expect('(');
  3659. var test = this.parseExpression();
  3660. if (!this.match(')') && this.config.tolerant) {
  3661. this.tolerateUnexpectedToken(this.nextToken());
  3662. body = this.finalize(this.createNode(), new Node.EmptyStatement());
  3663. }
  3664. else {
  3665. this.expect(')');
  3666. var previousInIteration = this.context.inIteration;
  3667. this.context.inIteration = true;
  3668. body = this.parseStatement();
  3669. this.context.inIteration = previousInIteration;
  3670. }
  3671. return this.finalize(node, new Node.WhileStatement(test, body));
  3672. };
  3673. // https://tc39.github.io/ecma262/#sec-for-statement
  3674. // https://tc39.github.io/ecma262/#sec-for-in-and-for-of-statements
  3675. Parser.prototype.parseForStatement = function () {
  3676. var init = null;
  3677. var test = null;
  3678. var update = null;
  3679. var forIn = true;
  3680. var left, right;
  3681. var node = this.createNode();
  3682. this.expectKeyword('for');
  3683. this.expect('(');
  3684. if (this.match(';')) {
  3685. this.nextToken();
  3686. }
  3687. else {
  3688. if (this.matchKeyword('var')) {
  3689. init = this.createNode();
  3690. this.nextToken();
  3691. var previousAllowIn = this.context.allowIn;
  3692. this.context.allowIn = false;
  3693. var declarations = this.parseVariableDeclarationList({ inFor: true });
  3694. this.context.allowIn = previousAllowIn;
  3695. if (declarations.length === 1 && this.matchKeyword('in')) {
  3696. var decl = declarations[0];
  3697. if (decl.init && (decl.id.type === syntax_1.Syntax.ArrayPattern || decl.id.type === syntax_1.Syntax.ObjectPattern || this.context.strict)) {
  3698. this.tolerateError(messages_1.Messages.ForInOfLoopInitializer, 'for-in');
  3699. }
  3700. init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
  3701. this.nextToken();
  3702. left = init;
  3703. right = this.parseExpression();
  3704. init = null;
  3705. }
  3706. else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
  3707. init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
  3708. this.nextToken();
  3709. left = init;
  3710. right = this.parseAssignmentExpression();
  3711. init = null;
  3712. forIn = false;
  3713. }
  3714. else {
  3715. init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
  3716. this.expect(';');
  3717. }
  3718. }
  3719. else if (this.matchKeyword('const') || this.matchKeyword('let')) {
  3720. init = this.createNode();
  3721. var kind = this.nextToken().value;
  3722. if (!this.context.strict && this.lookahead.value === 'in') {
  3723. init = this.finalize(init, new Node.Identifier(kind));
  3724. this.nextToken();
  3725. left = init;
  3726. right = this.parseExpression();
  3727. init = null;
  3728. }
  3729. else {
  3730. var previousAllowIn = this.context.allowIn;
  3731. this.context.allowIn = false;
  3732. var declarations = this.parseBindingList(kind, { inFor: true });
  3733. this.context.allowIn = previousAllowIn;
  3734. if (declarations.length === 1 && declarations[0].init === null && this.matchKeyword('in')) {
  3735. init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
  3736. this.nextToken();
  3737. left = init;
  3738. right = this.parseExpression();
  3739. init = null;
  3740. }
  3741. else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
  3742. init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
  3743. this.nextToken();
  3744. left = init;
  3745. right = this.parseAssignmentExpression();
  3746. init = null;
  3747. forIn = false;
  3748. }
  3749. else {
  3750. this.consumeSemicolon();
  3751. init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
  3752. }
  3753. }
  3754. }
  3755. else {
  3756. var initStartToken = this.lookahead;
  3757. var previousAllowIn = this.context.allowIn;
  3758. this.context.allowIn = false;
  3759. init = this.inheritCoverGrammar(this.parseAssignmentExpression);
  3760. this.context.allowIn = previousAllowIn;
  3761. if (this.matchKeyword('in')) {
  3762. if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
  3763. this.tolerateError(messages_1.Messages.InvalidLHSInForIn);
  3764. }
  3765. this.nextToken();
  3766. this.reinterpretExpressionAsPattern(init);
  3767. left = init;
  3768. right = this.parseExpression();
  3769. init = null;
  3770. }
  3771. else if (this.matchContextualKeyword('of')) {
  3772. if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
  3773. this.tolerateError(messages_1.Messages.InvalidLHSInForLoop);
  3774. }
  3775. this.nextToken();
  3776. this.reinterpretExpressionAsPattern(init);
  3777. left = init;
  3778. right = this.parseAssignmentExpression();
  3779. init = null;
  3780. forIn = false;
  3781. }
  3782. else {
  3783. if (this.match(',')) {
  3784. var initSeq = [init];
  3785. while (this.match(',')) {
  3786. this.nextToken();
  3787. initSeq.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  3788. }
  3789. init = this.finalize(this.startNode(initStartToken), new Node.SequenceExpression(initSeq));
  3790. }
  3791. this.expect(';');
  3792. }
  3793. }
  3794. }
  3795. if (typeof left === 'undefined') {
  3796. if (!this.match(';')) {
  3797. test = this.parseExpression();
  3798. }
  3799. this.expect(';');
  3800. if (!this.match(')')) {
  3801. update = this.parseExpression();
  3802. }
  3803. }
  3804. var body;
  3805. if (!this.match(')') && this.config.tolerant) {
  3806. this.tolerateUnexpectedToken(this.nextToken());
  3807. body = this.finalize(this.createNode(), new Node.EmptyStatement());
  3808. }
  3809. else {
  3810. this.expect(')');
  3811. var previousInIteration = this.context.inIteration;
  3812. this.context.inIteration = true;
  3813. body = this.isolateCoverGrammar(this.parseStatement);
  3814. this.context.inIteration = previousInIteration;
  3815. }
  3816. return (typeof left === 'undefined') ?
  3817. this.finalize(node, new Node.ForStatement(init, test, update, body)) :
  3818. forIn ? this.finalize(node, new Node.ForInStatement(left, right, body)) :
  3819. this.finalize(node, new Node.ForOfStatement(left, right, body));
  3820. };
  3821. // https://tc39.github.io/ecma262/#sec-continue-statement
  3822. Parser.prototype.parseContinueStatement = function () {
  3823. var node = this.createNode();
  3824. this.expectKeyword('continue');
  3825. var label = null;
  3826. if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
  3827. var id = this.parseVariableIdentifier();
  3828. label = id;
  3829. var key = '$' + id.name;
  3830. if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
  3831. this.throwError(messages_1.Messages.UnknownLabel, id.name);
  3832. }
  3833. }
  3834. this.consumeSemicolon();
  3835. if (label === null && !this.context.inIteration) {
  3836. this.throwError(messages_1.Messages.IllegalContinue);
  3837. }
  3838. return this.finalize(node, new Node.ContinueStatement(label));
  3839. };
  3840. // https://tc39.github.io/ecma262/#sec-break-statement
  3841. Parser.prototype.parseBreakStatement = function () {
  3842. var node = this.createNode();
  3843. this.expectKeyword('break');
  3844. var label = null;
  3845. if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
  3846. var id = this.parseVariableIdentifier();
  3847. var key = '$' + id.name;
  3848. if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
  3849. this.throwError(messages_1.Messages.UnknownLabel, id.name);
  3850. }
  3851. label = id;
  3852. }
  3853. this.consumeSemicolon();
  3854. if (label === null && !this.context.inIteration && !this.context.inSwitch) {
  3855. this.throwError(messages_1.Messages.IllegalBreak);
  3856. }
  3857. return this.finalize(node, new Node.BreakStatement(label));
  3858. };
  3859. // https://tc39.github.io/ecma262/#sec-return-statement
  3860. Parser.prototype.parseReturnStatement = function () {
  3861. if (!this.context.inFunctionBody) {
  3862. this.tolerateError(messages_1.Messages.IllegalReturn);
  3863. }
  3864. var node = this.createNode();
  3865. this.expectKeyword('return');
  3866. var hasArgument = !this.match(';') && !this.match('}') &&
  3867. !this.hasLineTerminator && this.lookahead.type !== 2 /* EOF */;
  3868. var argument = hasArgument ? this.parseExpression() : null;
  3869. this.consumeSemicolon();
  3870. return this.finalize(node, new Node.ReturnStatement(argument));
  3871. };
  3872. // https://tc39.github.io/ecma262/#sec-with-statement
  3873. Parser.prototype.parseWithStatement = function () {
  3874. if (this.context.strict) {
  3875. this.tolerateError(messages_1.Messages.StrictModeWith);
  3876. }
  3877. var node = this.createNode();
  3878. var body;
  3879. this.expectKeyword('with');
  3880. this.expect('(');
  3881. var object = this.parseExpression();
  3882. if (!this.match(')') && this.config.tolerant) {
  3883. this.tolerateUnexpectedToken(this.nextToken());
  3884. body = this.finalize(this.createNode(), new Node.EmptyStatement());
  3885. }
  3886. else {
  3887. this.expect(')');
  3888. body = this.parseStatement();
  3889. }
  3890. return this.finalize(node, new Node.WithStatement(object, body));
  3891. };
  3892. // https://tc39.github.io/ecma262/#sec-switch-statement
  3893. Parser.prototype.parseSwitchCase = function () {
  3894. var node = this.createNode();
  3895. var test;
  3896. if (this.matchKeyword('default')) {
  3897. this.nextToken();
  3898. test = null;
  3899. }
  3900. else {
  3901. this.expectKeyword('case');
  3902. test = this.parseExpression();
  3903. }
  3904. this.expect(':');
  3905. var consequent = [];
  3906. while (true) {
  3907. if (this.match('}') || this.matchKeyword('default') || this.matchKeyword('case')) {
  3908. break;
  3909. }
  3910. consequent.push(this.parseStatementListItem());
  3911. }
  3912. return this.finalize(node, new Node.SwitchCase(test, consequent));
  3913. };
  3914. Parser.prototype.parseSwitchStatement = function () {
  3915. var node = this.createNode();
  3916. this.expectKeyword('switch');
  3917. this.expect('(');
  3918. var discriminant = this.parseExpression();
  3919. this.expect(')');
  3920. var previousInSwitch = this.context.inSwitch;
  3921. this.context.inSwitch = true;
  3922. var cases = [];
  3923. var defaultFound = false;
  3924. this.expect('{');
  3925. while (true) {
  3926. if (this.match('}')) {
  3927. break;
  3928. }
  3929. var clause = this.parseSwitchCase();
  3930. if (clause.test === null) {
  3931. if (defaultFound) {
  3932. this.throwError(messages_1.Messages.MultipleDefaultsInSwitch);
  3933. }
  3934. defaultFound = true;
  3935. }
  3936. cases.push(clause);
  3937. }
  3938. this.expect('}');
  3939. this.context.inSwitch = previousInSwitch;
  3940. return this.finalize(node, new Node.SwitchStatement(discriminant, cases));
  3941. };
  3942. // https://tc39.github.io/ecma262/#sec-labelled-statements
  3943. Parser.prototype.parseLabelledStatement = function () {
  3944. var node = this.createNode();
  3945. var expr = this.parseExpression();
  3946. var statement;
  3947. if ((expr.type === syntax_1.Syntax.Identifier) && this.match(':')) {
  3948. this.nextToken();
  3949. var id = expr;
  3950. var key = '$' + id.name;
  3951. if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
  3952. this.throwError(messages_1.Messages.Redeclaration, 'Label', id.name);
  3953. }
  3954. this.context.labelSet[key] = true;
  3955. var body = void 0;
  3956. if (this.matchKeyword('class')) {
  3957. this.tolerateUnexpectedToken(this.lookahead);
  3958. body = this.parseClassDeclaration();
  3959. }
  3960. else if (this.matchKeyword('function')) {
  3961. var token = this.lookahead;
  3962. var declaration = this.parseFunctionDeclaration();
  3963. if (this.context.strict) {
  3964. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunction);
  3965. }
  3966. else if (declaration.generator) {
  3967. this.tolerateUnexpectedToken(token, messages_1.Messages.GeneratorInLegacyContext);
  3968. }
  3969. body = declaration;
  3970. }
  3971. else {
  3972. body = this.parseStatement();
  3973. }
  3974. delete this.context.labelSet[key];
  3975. statement = new Node.LabeledStatement(id, body);
  3976. }
  3977. else {
  3978. this.consumeSemicolon();
  3979. statement = new Node.ExpressionStatement(expr);
  3980. }
  3981. return this.finalize(node, statement);
  3982. };
  3983. // https://tc39.github.io/ecma262/#sec-throw-statement
  3984. Parser.prototype.parseThrowStatement = function () {
  3985. var node = this.createNode();
  3986. this.expectKeyword('throw');
  3987. if (this.hasLineTerminator) {
  3988. this.throwError(messages_1.Messages.NewlineAfterThrow);
  3989. }
  3990. var argument = this.parseExpression();
  3991. this.consumeSemicolon();
  3992. return this.finalize(node, new Node.ThrowStatement(argument));
  3993. };
  3994. // https://tc39.github.io/ecma262/#sec-try-statement
  3995. Parser.prototype.parseCatchClause = function () {
  3996. var node = this.createNode();
  3997. this.expectKeyword('catch');
  3998. this.expect('(');
  3999. if (this.match(')')) {
  4000. this.throwUnexpectedToken(this.lookahead);
  4001. }
  4002. var params = [];
  4003. var param = this.parsePattern(params);
  4004. var paramMap = {};
  4005. for (var i = 0; i < params.length; i++) {
  4006. var key = '$' + params[i].value;
  4007. if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
  4008. this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value);
  4009. }
  4010. paramMap[key] = true;
  4011. }
  4012. if (this.context.strict && param.type === syntax_1.Syntax.Identifier) {
  4013. if (this.scanner.isRestrictedWord(param.name)) {
  4014. this.tolerateError(messages_1.Messages.StrictCatchVariable);
  4015. }
  4016. }
  4017. this.expect(')');
  4018. var body = this.parseBlock();
  4019. return this.finalize(node, new Node.CatchClause(param, body));
  4020. };
  4021. Parser.prototype.parseFinallyClause = function () {
  4022. this.expectKeyword('finally');
  4023. return this.parseBlock();
  4024. };
  4025. Parser.prototype.parseTryStatement = function () {
  4026. var node = this.createNode();
  4027. this.expectKeyword('try');
  4028. var block = this.parseBlock();
  4029. var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null;
  4030. var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
  4031. if (!handler && !finalizer) {
  4032. this.throwError(messages_1.Messages.NoCatchOrFinally);
  4033. }
  4034. return this.finalize(node, new Node.TryStatement(block, handler, finalizer));
  4035. };
  4036. // https://tc39.github.io/ecma262/#sec-debugger-statement
  4037. Parser.prototype.parseDebuggerStatement = function () {
  4038. var node = this.createNode();
  4039. this.expectKeyword('debugger');
  4040. this.consumeSemicolon();
  4041. return this.finalize(node, new Node.DebuggerStatement());
  4042. };
  4043. // https://tc39.github.io/ecma262/#sec-ecmascript-language-statements-and-declarations
  4044. Parser.prototype.parseStatement = function () {
  4045. var statement;
  4046. switch (this.lookahead.type) {
  4047. case 1 /* BooleanLiteral */:
  4048. case 5 /* NullLiteral */:
  4049. case 6 /* NumericLiteral */:
  4050. case 8 /* StringLiteral */:
  4051. case 10 /* Template */:
  4052. case 9 /* RegularExpression */:
  4053. statement = this.parseExpressionStatement();
  4054. break;
  4055. case 7 /* Punctuator */:
  4056. var value = this.lookahead.value;
  4057. if (value === '{') {
  4058. statement = this.parseBlock();
  4059. }
  4060. else if (value === '(') {
  4061. statement = this.parseExpressionStatement();
  4062. }
  4063. else if (value === ';') {
  4064. statement = this.parseEmptyStatement();
  4065. }
  4066. else {
  4067. statement = this.parseExpressionStatement();
  4068. }
  4069. break;
  4070. case 3 /* Identifier */:
  4071. statement = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement();
  4072. break;
  4073. case 4 /* Keyword */:
  4074. switch (this.lookahead.value) {
  4075. case 'break':
  4076. statement = this.parseBreakStatement();
  4077. break;
  4078. case 'continue':
  4079. statement = this.parseContinueStatement();
  4080. break;
  4081. case 'debugger':
  4082. statement = this.parseDebuggerStatement();
  4083. break;
  4084. case 'do':
  4085. statement = this.parseDoWhileStatement();
  4086. break;
  4087. case 'for':
  4088. statement = this.parseForStatement();
  4089. break;
  4090. case 'function':
  4091. statement = this.parseFunctionDeclaration();
  4092. break;
  4093. case 'if':
  4094. statement = this.parseIfStatement();
  4095. break;
  4096. case 'return':
  4097. statement = this.parseReturnStatement();
  4098. break;
  4099. case 'switch':
  4100. statement = this.parseSwitchStatement();
  4101. break;
  4102. case 'throw':
  4103. statement = this.parseThrowStatement();
  4104. break;
  4105. case 'try':
  4106. statement = this.parseTryStatement();
  4107. break;
  4108. case 'var':
  4109. statement = this.parseVariableStatement();
  4110. break;
  4111. case 'while':
  4112. statement = this.parseWhileStatement();
  4113. break;
  4114. case 'with':
  4115. statement = this.parseWithStatement();
  4116. break;
  4117. default:
  4118. statement = this.parseExpressionStatement();
  4119. break;
  4120. }
  4121. break;
  4122. default:
  4123. statement = this.throwUnexpectedToken(this.lookahead);
  4124. }
  4125. return statement;
  4126. };
  4127. // https://tc39.github.io/ecma262/#sec-function-definitions
  4128. Parser.prototype.parseFunctionSourceElements = function () {
  4129. var node = this.createNode();
  4130. this.expect('{');
  4131. var body = this.parseDirectivePrologues();
  4132. var previousLabelSet = this.context.labelSet;
  4133. var previousInIteration = this.context.inIteration;
  4134. var previousInSwitch = this.context.inSwitch;
  4135. var previousInFunctionBody = this.context.inFunctionBody;
  4136. this.context.labelSet = {};
  4137. this.context.inIteration = false;
  4138. this.context.inSwitch = false;
  4139. this.context.inFunctionBody = true;
  4140. while (this.lookahead.type !== 2 /* EOF */) {
  4141. if (this.match('}')) {
  4142. break;
  4143. }
  4144. body.push(this.parseStatementListItem());
  4145. }
  4146. this.expect('}');
  4147. this.context.labelSet = previousLabelSet;
  4148. this.context.inIteration = previousInIteration;
  4149. this.context.inSwitch = previousInSwitch;
  4150. this.context.inFunctionBody = previousInFunctionBody;
  4151. return this.finalize(node, new Node.BlockStatement(body));
  4152. };
  4153. Parser.prototype.validateParam = function (options, param, name) {
  4154. var key = '$' + name;
  4155. if (this.context.strict) {
  4156. if (this.scanner.isRestrictedWord(name)) {
  4157. options.stricted = param;
  4158. options.message = messages_1.Messages.StrictParamName;
  4159. }
  4160. if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  4161. options.stricted = param;
  4162. options.message = messages_1.Messages.StrictParamDupe;
  4163. }
  4164. }
  4165. else if (!options.firstRestricted) {
  4166. if (this.scanner.isRestrictedWord(name)) {
  4167. options.firstRestricted = param;
  4168. options.message = messages_1.Messages.StrictParamName;
  4169. }
  4170. else if (this.scanner.isStrictModeReservedWord(name)) {
  4171. options.firstRestricted = param;
  4172. options.message = messages_1.Messages.StrictReservedWord;
  4173. }
  4174. else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  4175. options.stricted = param;
  4176. options.message = messages_1.Messages.StrictParamDupe;
  4177. }
  4178. }
  4179. /* istanbul ignore next */
  4180. if (typeof Object.defineProperty === 'function') {
  4181. Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true });
  4182. }
  4183. else {
  4184. options.paramSet[key] = true;
  4185. }
  4186. };
  4187. Parser.prototype.parseRestElement = function (params) {
  4188. var node = this.createNode();
  4189. this.expect('...');
  4190. var arg = this.parsePattern(params);
  4191. if (this.match('=')) {
  4192. this.throwError(messages_1.Messages.DefaultRestParameter);
  4193. }
  4194. if (!this.match(')')) {
  4195. this.throwError(messages_1.Messages.ParameterAfterRestParameter);
  4196. }
  4197. return this.finalize(node, new Node.RestElement(arg));
  4198. };
  4199. Parser.prototype.parseFormalParameter = function (options) {
  4200. var params = [];
  4201. var param = this.match('...') ? this.parseRestElement(params) : this.parsePatternWithDefault(params);
  4202. for (var i = 0; i < params.length; i++) {
  4203. this.validateParam(options, params[i], params[i].value);
  4204. }
  4205. options.simple = options.simple && (param instanceof Node.Identifier);
  4206. options.params.push(param);
  4207. };
  4208. Parser.prototype.parseFormalParameters = function (firstRestricted) {
  4209. var options;
  4210. options = {
  4211. simple: true,
  4212. params: [],
  4213. firstRestricted: firstRestricted
  4214. };
  4215. this.expect('(');
  4216. if (!this.match(')')) {
  4217. options.paramSet = {};
  4218. while (this.lookahead.type !== 2 /* EOF */) {
  4219. this.parseFormalParameter(options);
  4220. if (this.match(')')) {
  4221. break;
  4222. }
  4223. this.expect(',');
  4224. if (this.match(')')) {
  4225. break;
  4226. }
  4227. }
  4228. }
  4229. this.expect(')');
  4230. return {
  4231. simple: options.simple,
  4232. params: options.params,
  4233. stricted: options.stricted,
  4234. firstRestricted: options.firstRestricted,
  4235. message: options.message
  4236. };
  4237. };
  4238. Parser.prototype.matchAsyncFunction = function () {
  4239. var match = this.matchContextualKeyword('async');
  4240. if (match) {
  4241. var state = this.scanner.saveState();
  4242. this.scanner.scanComments();
  4243. var next = this.scanner.lex();
  4244. this.scanner.restoreState(state);
  4245. match = (state.lineNumber === next.lineNumber) && (next.type === 4 /* Keyword */) && (next.value === 'function');
  4246. }
  4247. return match;
  4248. };
  4249. Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) {
  4250. var node = this.createNode();
  4251. var isAsync = this.matchContextualKeyword('async');
  4252. if (isAsync) {
  4253. this.nextToken();
  4254. }
  4255. this.expectKeyword('function');
  4256. var isGenerator = isAsync ? false : this.match('*');
  4257. if (isGenerator) {
  4258. this.nextToken();
  4259. }
  4260. var message;
  4261. var id = null;
  4262. var firstRestricted = null;
  4263. if (!identifierIsOptional || !this.match('(')) {
  4264. var token = this.lookahead;
  4265. id = this.parseVariableIdentifier();
  4266. if (this.context.strict) {
  4267. if (this.scanner.isRestrictedWord(token.value)) {
  4268. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
  4269. }
  4270. }
  4271. else {
  4272. if (this.scanner.isRestrictedWord(token.value)) {
  4273. firstRestricted = token;
  4274. message = messages_1.Messages.StrictFunctionName;
  4275. }
  4276. else if (this.scanner.isStrictModeReservedWord(token.value)) {
  4277. firstRestricted = token;
  4278. message = messages_1.Messages.StrictReservedWord;
  4279. }
  4280. }
  4281. }
  4282. var previousAllowAwait = this.context.await;
  4283. var previousAllowYield = this.context.allowYield;
  4284. this.context.await = isAsync;
  4285. this.context.allowYield = !isGenerator;
  4286. var formalParameters = this.parseFormalParameters(firstRestricted);
  4287. var params = formalParameters.params;
  4288. var stricted = formalParameters.stricted;
  4289. firstRestricted = formalParameters.firstRestricted;
  4290. if (formalParameters.message) {
  4291. message = formalParameters.message;
  4292. }
  4293. var previousStrict = this.context.strict;
  4294. var previousAllowStrictDirective = this.context.allowStrictDirective;
  4295. this.context.allowStrictDirective = formalParameters.simple;
  4296. var body = this.parseFunctionSourceElements();
  4297. if (this.context.strict && firstRestricted) {
  4298. this.throwUnexpectedToken(firstRestricted, message);
  4299. }
  4300. if (this.context.strict && stricted) {
  4301. this.tolerateUnexpectedToken(stricted, message);
  4302. }
  4303. this.context.strict = previousStrict;
  4304. this.context.allowStrictDirective = previousAllowStrictDirective;
  4305. this.context.await = previousAllowAwait;
  4306. this.context.allowYield = previousAllowYield;
  4307. return isAsync ? this.finalize(node, new Node.AsyncFunctionDeclaration(id, params, body)) :
  4308. this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator));
  4309. };
  4310. Parser.prototype.parseFunctionExpression = function () {
  4311. var node = this.createNode();
  4312. var isAsync = this.matchContextualKeyword('async');
  4313. if (isAsync) {
  4314. this.nextToken();
  4315. }
  4316. this.expectKeyword('function');
  4317. var isGenerator = isAsync ? false : this.match('*');
  4318. if (isGenerator) {
  4319. this.nextToken();
  4320. }
  4321. var message;
  4322. var id = null;
  4323. var firstRestricted;
  4324. var previousAllowAwait = this.context.await;
  4325. var previousAllowYield = this.context.allowYield;
  4326. this.context.await = isAsync;
  4327. this.context.allowYield = !isGenerator;
  4328. if (!this.match('(')) {
  4329. var token = this.lookahead;
  4330. id = (!this.context.strict && !isGenerator && this.matchKeyword('yield')) ? this.parseIdentifierName() : this.parseVariableIdentifier();
  4331. if (this.context.strict) {
  4332. if (this.scanner.isRestrictedWord(token.value)) {
  4333. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
  4334. }
  4335. }
  4336. else {
  4337. if (this.scanner.isRestrictedWord(token.value)) {
  4338. firstRestricted = token;
  4339. message = messages_1.Messages.StrictFunctionName;
  4340. }
  4341. else if (this.scanner.isStrictModeReservedWord(token.value)) {
  4342. firstRestricted = token;
  4343. message = messages_1.Messages.StrictReservedWord;
  4344. }
  4345. }
  4346. }
  4347. var formalParameters = this.parseFormalParameters(firstRestricted);
  4348. var params = formalParameters.params;
  4349. var stricted = formalParameters.stricted;
  4350. firstRestricted = formalParameters.firstRestricted;
  4351. if (formalParameters.message) {
  4352. message = formalParameters.message;
  4353. }
  4354. var previousStrict = this.context.strict;
  4355. var previousAllowStrictDirective = this.context.allowStrictDirective;
  4356. this.context.allowStrictDirective = formalParameters.simple;
  4357. var body = this.parseFunctionSourceElements();
  4358. if (this.context.strict && firstRestricted) {
  4359. this.throwUnexpectedToken(firstRestricted, message);
  4360. }
  4361. if (this.context.strict && stricted) {
  4362. this.tolerateUnexpectedToken(stricted, message);
  4363. }
  4364. this.context.strict = previousStrict;
  4365. this.context.allowStrictDirective = previousAllowStrictDirective;
  4366. this.context.await = previousAllowAwait;
  4367. this.context.allowYield = previousAllowYield;
  4368. return isAsync ? this.finalize(node, new Node.AsyncFunctionExpression(id, params, body)) :
  4369. this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator));
  4370. };
  4371. // https://tc39.github.io/ecma262/#sec-directive-prologues-and-the-use-strict-directive
  4372. Parser.prototype.parseDirective = function () {
  4373. var token = this.lookahead;
  4374. var node = this.createNode();
  4375. var expr = this.parseExpression();
  4376. var directive = (expr.type === syntax_1.Syntax.Literal) ? this.getTokenRaw(token).slice(1, -1) : null;
  4377. this.consumeSemicolon();
  4378. return this.finalize(node, directive ? new Node.Directive(expr, directive) : new Node.ExpressionStatement(expr));
  4379. };
  4380. Parser.prototype.parseDirectivePrologues = function () {
  4381. var firstRestricted = null;
  4382. var body = [];
  4383. while (true) {
  4384. var token = this.lookahead;
  4385. if (token.type !== 8 /* StringLiteral */) {
  4386. break;
  4387. }
  4388. var statement = this.parseDirective();
  4389. body.push(statement);
  4390. var directive = statement.directive;
  4391. if (typeof directive !== 'string') {
  4392. break;
  4393. }
  4394. if (directive === 'use strict') {
  4395. this.context.strict = true;
  4396. if (firstRestricted) {
  4397. this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral);
  4398. }
  4399. if (!this.context.allowStrictDirective) {
  4400. this.tolerateUnexpectedToken(token, messages_1.Messages.IllegalLanguageModeDirective);
  4401. }
  4402. }
  4403. else {
  4404. if (!firstRestricted && token.octal) {
  4405. firstRestricted = token;
  4406. }
  4407. }
  4408. }
  4409. return body;
  4410. };
  4411. // https://tc39.github.io/ecma262/#sec-method-definitions
  4412. Parser.prototype.qualifiedPropertyName = function (token) {
  4413. switch (token.type) {
  4414. case 3 /* Identifier */:
  4415. case 8 /* StringLiteral */:
  4416. case 1 /* BooleanLiteral */:
  4417. case 5 /* NullLiteral */:
  4418. case 6 /* NumericLiteral */:
  4419. case 4 /* Keyword */:
  4420. return true;
  4421. case 7 /* Punctuator */:
  4422. return token.value === '[';
  4423. default:
  4424. break;
  4425. }
  4426. return false;
  4427. };
  4428. Parser.prototype.parseGetterMethod = function () {
  4429. var node = this.createNode();
  4430. var isGenerator = false;
  4431. var previousAllowYield = this.context.allowYield;
  4432. this.context.allowYield = false;
  4433. var formalParameters = this.parseFormalParameters();
  4434. if (formalParameters.params.length > 0) {
  4435. this.tolerateError(messages_1.Messages.BadGetterArity);
  4436. }
  4437. var method = this.parsePropertyMethod(formalParameters);
  4438. this.context.allowYield = previousAllowYield;
  4439. return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
  4440. };
  4441. Parser.prototype.parseSetterMethod = function () {
  4442. var node = this.createNode();
  4443. var isGenerator = false;
  4444. var previousAllowYield = this.context.allowYield;
  4445. this.context.allowYield = false;
  4446. var formalParameters = this.parseFormalParameters();
  4447. if (formalParameters.params.length !== 1) {
  4448. this.tolerateError(messages_1.Messages.BadSetterArity);
  4449. }
  4450. else if (formalParameters.params[0] instanceof Node.RestElement) {
  4451. this.tolerateError(messages_1.Messages.BadSetterRestParameter);
  4452. }
  4453. var method = this.parsePropertyMethod(formalParameters);
  4454. this.context.allowYield = previousAllowYield;
  4455. return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
  4456. };
  4457. Parser.prototype.parseGeneratorMethod = function () {
  4458. var node = this.createNode();
  4459. var isGenerator = true;
  4460. var previousAllowYield = this.context.allowYield;
  4461. this.context.allowYield = true;
  4462. var params = this.parseFormalParameters();
  4463. this.context.allowYield = false;
  4464. var method = this.parsePropertyMethod(params);
  4465. this.context.allowYield = previousAllowYield;
  4466. return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
  4467. };
  4468. // https://tc39.github.io/ecma262/#sec-generator-function-definitions
  4469. Parser.prototype.isStartOfExpression = function () {
  4470. var start = true;
  4471. var value = this.lookahead.value;
  4472. switch (this.lookahead.type) {
  4473. case 7 /* Punctuator */:
  4474. start = (value === '[') || (value === '(') || (value === '{') ||
  4475. (value === '+') || (value === '-') ||
  4476. (value === '!') || (value === '~') ||
  4477. (value === '++') || (value === '--') ||
  4478. (value === '/') || (value === '/='); // regular expression literal
  4479. break;
  4480. case 4 /* Keyword */:
  4481. start = (value === 'class') || (value === 'delete') ||
  4482. (value === 'function') || (value === 'let') || (value === 'new') ||
  4483. (value === 'super') || (value === 'this') || (value === 'typeof') ||
  4484. (value === 'void') || (value === 'yield');
  4485. break;
  4486. default:
  4487. break;
  4488. }
  4489. return start;
  4490. };
  4491. Parser.prototype.parseYieldExpression = function () {
  4492. var node = this.createNode();
  4493. this.expectKeyword('yield');
  4494. var argument = null;
  4495. var delegate = false;
  4496. if (!this.hasLineTerminator) {
  4497. var previousAllowYield = this.context.allowYield;
  4498. this.context.allowYield = false;
  4499. delegate = this.match('*');
  4500. if (delegate) {
  4501. this.nextToken();
  4502. argument = this.parseAssignmentExpression();
  4503. }
  4504. else if (this.isStartOfExpression()) {
  4505. argument = this.parseAssignmentExpression();
  4506. }
  4507. this.context.allowYield = previousAllowYield;
  4508. }
  4509. return this.finalize(node, new Node.YieldExpression(argument, delegate));
  4510. };
  4511. // https://tc39.github.io/ecma262/#sec-class-definitions
  4512. Parser.prototype.parseClassElement = function (hasConstructor) {
  4513. var token = this.lookahead;
  4514. var node = this.createNode();
  4515. var kind = '';
  4516. var key = null;
  4517. var value = null;
  4518. var computed = false;
  4519. var method = false;
  4520. var isStatic = false;
  4521. var isAsync = false;
  4522. if (this.match('*')) {
  4523. this.nextToken();
  4524. }
  4525. else {
  4526. computed = this.match('[');
  4527. key = this.parseObjectPropertyKey();
  4528. var id = key;
  4529. if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) {
  4530. token = this.lookahead;
  4531. isStatic = true;
  4532. computed = this.match('[');
  4533. if (this.match('*')) {
  4534. this.nextToken();
  4535. }
  4536. else {
  4537. key = this.parseObjectPropertyKey();
  4538. }
  4539. }
  4540. if ((token.type === 3 /* Identifier */) && !this.hasLineTerminator && (token.value === 'async')) {
  4541. var punctuator = this.lookahead.value;
  4542. if (punctuator !== ':' && punctuator !== '(' && punctuator !== '*') {
  4543. isAsync = true;
  4544. token = this.lookahead;
  4545. key = this.parseObjectPropertyKey();
  4546. if (token.type === 3 /* Identifier */) {
  4547. if (token.value === 'get' || token.value === 'set') {
  4548. this.tolerateUnexpectedToken(token);
  4549. }
  4550. else if (token.value === 'constructor') {
  4551. this.tolerateUnexpectedToken(token, messages_1.Messages.ConstructorIsAsync);
  4552. }
  4553. }
  4554. }
  4555. }
  4556. }
  4557. var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
  4558. if (token.type === 3 /* Identifier */) {
  4559. if (token.value === 'get' && lookaheadPropertyKey) {
  4560. kind = 'get';
  4561. computed = this.match('[');
  4562. key = this.parseObjectPropertyKey();
  4563. this.context.allowYield = false;
  4564. value = this.parseGetterMethod();
  4565. }
  4566. else if (token.value === 'set' && lookaheadPropertyKey) {
  4567. kind = 'set';
  4568. computed = this.match('[');
  4569. key = this.parseObjectPropertyKey();
  4570. value = this.parseSetterMethod();
  4571. }
  4572. }
  4573. else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
  4574. kind = 'init';
  4575. computed = this.match('[');
  4576. key = this.parseObjectPropertyKey();
  4577. value = this.parseGeneratorMethod();
  4578. method = true;
  4579. }
  4580. if (!kind && key && this.match('(')) {
  4581. kind = 'init';
  4582. value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
  4583. method = true;
  4584. }
  4585. if (!kind) {
  4586. this.throwUnexpectedToken(this.lookahead);
  4587. }
  4588. if (kind === 'init') {
  4589. kind = 'method';
  4590. }
  4591. if (!computed) {
  4592. if (isStatic && this.isPropertyKey(key, 'prototype')) {
  4593. this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype);
  4594. }
  4595. if (!isStatic && this.isPropertyKey(key, 'constructor')) {
  4596. if (kind !== 'method' || !method || (value && value.generator)) {
  4597. this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod);
  4598. }
  4599. if (hasConstructor.value) {
  4600. this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor);
  4601. }
  4602. else {
  4603. hasConstructor.value = true;
  4604. }
  4605. kind = 'constructor';
  4606. }
  4607. }
  4608. return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic));
  4609. };
  4610. Parser.prototype.parseClassElementList = function () {
  4611. var body = [];
  4612. var hasConstructor = { value: false };
  4613. this.expect('{');
  4614. while (!this.match('}')) {
  4615. if (this.match(';')) {
  4616. this.nextToken();
  4617. }
  4618. else {
  4619. body.push(this.parseClassElement(hasConstructor));
  4620. }
  4621. }
  4622. this.expect('}');
  4623. return body;
  4624. };
  4625. Parser.prototype.parseClassBody = function () {
  4626. var node = this.createNode();
  4627. var elementList = this.parseClassElementList();
  4628. return this.finalize(node, new Node.ClassBody(elementList));
  4629. };
  4630. Parser.prototype.parseClassDeclaration = function (identifierIsOptional) {
  4631. var node = this.createNode();
  4632. var previousStrict = this.context.strict;
  4633. this.context.strict = true;
  4634. this.expectKeyword('class');
  4635. var id = (identifierIsOptional && (this.lookahead.type !== 3 /* Identifier */)) ? null : this.parseVariableIdentifier();
  4636. var superClass = null;
  4637. if (this.matchKeyword('extends')) {
  4638. this.nextToken();
  4639. superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  4640. }
  4641. var classBody = this.parseClassBody();
  4642. this.context.strict = previousStrict;
  4643. return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody));
  4644. };
  4645. Parser.prototype.parseClassExpression = function () {
  4646. var node = this.createNode();
  4647. var previousStrict = this.context.strict;
  4648. this.context.strict = true;
  4649. this.expectKeyword('class');
  4650. var id = (this.lookahead.type === 3 /* Identifier */) ? this.parseVariableIdentifier() : null;
  4651. var superClass = null;
  4652. if (this.matchKeyword('extends')) {
  4653. this.nextToken();
  4654. superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  4655. }
  4656. var classBody = this.parseClassBody();
  4657. this.context.strict = previousStrict;
  4658. return this.finalize(node, new Node.ClassExpression(id, superClass, classBody));
  4659. };
  4660. // https://tc39.github.io/ecma262/#sec-scripts
  4661. // https://tc39.github.io/ecma262/#sec-modules
  4662. Parser.prototype.parseModule = function () {
  4663. this.context.strict = true;
  4664. this.context.isModule = true;
  4665. var node = this.createNode();
  4666. var body = this.parseDirectivePrologues();
  4667. while (this.lookahead.type !== 2 /* EOF */) {
  4668. body.push(this.parseStatementListItem());
  4669. }
  4670. return this.finalize(node, new Node.Module(body));
  4671. };
  4672. Parser.prototype.parseScript = function () {
  4673. var node = this.createNode();
  4674. var body = this.parseDirectivePrologues();
  4675. while (this.lookahead.type !== 2 /* EOF */) {
  4676. body.push(this.parseStatementListItem());
  4677. }
  4678. return this.finalize(node, new Node.Script(body));
  4679. };
  4680. // https://tc39.github.io/ecma262/#sec-imports
  4681. Parser.prototype.parseModuleSpecifier = function () {
  4682. var node = this.createNode();
  4683. if (this.lookahead.type !== 8 /* StringLiteral */) {
  4684. this.throwError(messages_1.Messages.InvalidModuleSpecifier);
  4685. }
  4686. var token = this.nextToken();
  4687. var raw = this.getTokenRaw(token);
  4688. return this.finalize(node, new Node.Literal(token.value, raw));
  4689. };
  4690. // import {<foo as bar>} ...;
  4691. Parser.prototype.parseImportSpecifier = function () {
  4692. var node = this.createNode();
  4693. var imported;
  4694. var local;
  4695. if (this.lookahead.type === 3 /* Identifier */) {
  4696. imported = this.parseVariableIdentifier();
  4697. local = imported;
  4698. if (this.matchContextualKeyword('as')) {
  4699. this.nextToken();
  4700. local = this.parseVariableIdentifier();
  4701. }
  4702. }
  4703. else {
  4704. imported = this.parseIdentifierName();
  4705. local = imported;
  4706. if (this.matchContextualKeyword('as')) {
  4707. this.nextToken();
  4708. local = this.parseVariableIdentifier();
  4709. }
  4710. else {
  4711. this.throwUnexpectedToken(this.nextToken());
  4712. }
  4713. }
  4714. return this.finalize(node, new Node.ImportSpecifier(local, imported));
  4715. };
  4716. // {foo, bar as bas}
  4717. Parser.prototype.parseNamedImports = function () {
  4718. this.expect('{');
  4719. var specifiers = [];
  4720. while (!this.match('}')) {
  4721. specifiers.push(this.parseImportSpecifier());
  4722. if (!this.match('}')) {
  4723. this.expect(',');
  4724. }
  4725. }
  4726. this.expect('}');
  4727. return specifiers;
  4728. };
  4729. // import <foo> ...;
  4730. Parser.prototype.parseImportDefaultSpecifier = function () {
  4731. var node = this.createNode();
  4732. var local = this.parseIdentifierName();
  4733. return this.finalize(node, new Node.ImportDefaultSpecifier(local));
  4734. };
  4735. // import <* as foo> ...;
  4736. Parser.prototype.parseImportNamespaceSpecifier = function () {
  4737. var node = this.createNode();
  4738. this.expect('*');
  4739. if (!this.matchContextualKeyword('as')) {
  4740. this.throwError(messages_1.Messages.NoAsAfterImportNamespace);
  4741. }
  4742. this.nextToken();
  4743. var local = this.parseIdentifierName();
  4744. return this.finalize(node, new Node.ImportNamespaceSpecifier(local));
  4745. };
  4746. Parser.prototype.parseImportDeclaration = function () {
  4747. if (this.context.inFunctionBody) {
  4748. this.throwError(messages_1.Messages.IllegalImportDeclaration);
  4749. }
  4750. var node = this.createNode();
  4751. this.expectKeyword('import');
  4752. var src;
  4753. var specifiers = [];
  4754. if (this.lookahead.type === 8 /* StringLiteral */) {
  4755. // import 'foo';
  4756. src = this.parseModuleSpecifier();
  4757. }
  4758. else {
  4759. if (this.match('{')) {
  4760. // import {bar}
  4761. specifiers = specifiers.concat(this.parseNamedImports());
  4762. }
  4763. else if (this.match('*')) {
  4764. // import * as foo
  4765. specifiers.push(this.parseImportNamespaceSpecifier());
  4766. }
  4767. else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) {
  4768. // import foo
  4769. specifiers.push(this.parseImportDefaultSpecifier());
  4770. if (this.match(',')) {
  4771. this.nextToken();
  4772. if (this.match('*')) {
  4773. // import foo, * as foo
  4774. specifiers.push(this.parseImportNamespaceSpecifier());
  4775. }
  4776. else if (this.match('{')) {
  4777. // import foo, {bar}
  4778. specifiers = specifiers.concat(this.parseNamedImports());
  4779. }
  4780. else {
  4781. this.throwUnexpectedToken(this.lookahead);
  4782. }
  4783. }
  4784. }
  4785. else {
  4786. this.throwUnexpectedToken(this.nextToken());
  4787. }
  4788. if (!this.matchContextualKeyword('from')) {
  4789. var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
  4790. this.throwError(message, this.lookahead.value);
  4791. }
  4792. this.nextToken();
  4793. src = this.parseModuleSpecifier();
  4794. }
  4795. this.consumeSemicolon();
  4796. return this.finalize(node, new Node.ImportDeclaration(specifiers, src));
  4797. };
  4798. // https://tc39.github.io/ecma262/#sec-exports
  4799. Parser.prototype.parseExportSpecifier = function () {
  4800. var node = this.createNode();
  4801. var local = this.parseIdentifierName();
  4802. var exported = local;
  4803. if (this.matchContextualKeyword('as')) {
  4804. this.nextToken();
  4805. exported = this.parseIdentifierName();
  4806. }
  4807. return this.finalize(node, new Node.ExportSpecifier(local, exported));
  4808. };
  4809. Parser.prototype.parseExportDeclaration = function () {
  4810. if (this.context.inFunctionBody) {
  4811. this.throwError(messages_1.Messages.IllegalExportDeclaration);
  4812. }
  4813. var node = this.createNode();
  4814. this.expectKeyword('export');
  4815. var exportDeclaration;
  4816. if (this.matchKeyword('default')) {
  4817. // export default ...
  4818. this.nextToken();
  4819. if (this.matchKeyword('function')) {
  4820. // export default function foo () {}
  4821. // export default function () {}
  4822. var declaration = this.parseFunctionDeclaration(true);
  4823. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4824. }
  4825. else if (this.matchKeyword('class')) {
  4826. // export default class foo {}
  4827. var declaration = this.parseClassDeclaration(true);
  4828. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4829. }
  4830. else if (this.matchContextualKeyword('async')) {
  4831. // export default async function f () {}
  4832. // export default async function () {}
  4833. // export default async x => x
  4834. var declaration = this.matchAsyncFunction() ? this.parseFunctionDeclaration(true) : this.parseAssignmentExpression();
  4835. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4836. }
  4837. else {
  4838. if (this.matchContextualKeyword('from')) {
  4839. this.throwError(messages_1.Messages.UnexpectedToken, this.lookahead.value);
  4840. }
  4841. // export default {};
  4842. // export default [];
  4843. // export default (1 + 2);
  4844. var declaration = this.match('{') ? this.parseObjectInitializer() :
  4845. this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
  4846. this.consumeSemicolon();
  4847. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4848. }
  4849. }
  4850. else if (this.match('*')) {
  4851. // export * from 'foo';
  4852. this.nextToken();
  4853. if (!this.matchContextualKeyword('from')) {
  4854. var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
  4855. this.throwError(message, this.lookahead.value);
  4856. }
  4857. this.nextToken();
  4858. var src = this.parseModuleSpecifier();
  4859. this.consumeSemicolon();
  4860. exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
  4861. }
  4862. else if (this.lookahead.type === 4 /* Keyword */) {
  4863. // export var f = 1;
  4864. var declaration = void 0;
  4865. switch (this.lookahead.value) {
  4866. case 'let':
  4867. case 'const':
  4868. declaration = this.parseLexicalDeclaration({ inFor: false });
  4869. break;
  4870. case 'var':
  4871. case 'class':
  4872. case 'function':
  4873. declaration = this.parseStatementListItem();
  4874. break;
  4875. default:
  4876. this.throwUnexpectedToken(this.lookahead);
  4877. }
  4878. exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
  4879. }
  4880. else if (this.matchAsyncFunction()) {
  4881. var declaration = this.parseFunctionDeclaration();
  4882. exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
  4883. }
  4884. else {
  4885. var specifiers = [];
  4886. var source = null;
  4887. var isExportFromIdentifier = false;
  4888. this.expect('{');
  4889. while (!this.match('}')) {
  4890. isExportFromIdentifier = isExportFromIdentifier || this.matchKeyword('default');
  4891. specifiers.push(this.parseExportSpecifier());
  4892. if (!this.match('}')) {
  4893. this.expect(',');
  4894. }
  4895. }
  4896. this.expect('}');
  4897. if (this.matchContextualKeyword('from')) {
  4898. // export {default} from 'foo';
  4899. // export {foo} from 'foo';
  4900. this.nextToken();
  4901. source = this.parseModuleSpecifier();
  4902. this.consumeSemicolon();
  4903. }
  4904. else if (isExportFromIdentifier) {
  4905. // export {default}; // missing fromClause
  4906. var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
  4907. this.throwError(message, this.lookahead.value);
  4908. }
  4909. else {
  4910. // export {foo};
  4911. this.consumeSemicolon();
  4912. }
  4913. exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(null, specifiers, source));
  4914. }
  4915. return exportDeclaration;
  4916. };
  4917. return Parser;
  4918. }());
  4919. exports.Parser = Parser;
  4920. /***/ },
  4921. /* 9 */
  4922. /***/ function(module, exports) {
  4923. "use strict";
  4924. // Ensure the condition is true, otherwise throw an error.
  4925. // This is only to have a better contract semantic, i.e. another safety net
  4926. // to catch a logic error. The condition shall be fulfilled in normal case.
  4927. // Do NOT use this to enforce a certain condition on any user input.
  4928. Object.defineProperty(exports, "__esModule", { value: true });
  4929. function assert(condition, message) {
  4930. /* istanbul ignore if */
  4931. if (!condition) {
  4932. throw new Error('ASSERT: ' + message);
  4933. }
  4934. }
  4935. exports.assert = assert;
  4936. /***/ },
  4937. /* 10 */
  4938. /***/ function(module, exports) {
  4939. "use strict";
  4940. /* tslint:disable:max-classes-per-file */
  4941. Object.defineProperty(exports, "__esModule", { value: true });
  4942. var ErrorHandler = (function () {
  4943. function ErrorHandler() {
  4944. this.errors = [];
  4945. this.tolerant = false;
  4946. }
  4947. ErrorHandler.prototype.recordError = function (error) {
  4948. this.errors.push(error);
  4949. };
  4950. ErrorHandler.prototype.tolerate = function (error) {
  4951. if (this.tolerant) {
  4952. this.recordError(error);
  4953. }
  4954. else {
  4955. throw error;
  4956. }
  4957. };
  4958. ErrorHandler.prototype.constructError = function (msg, column) {
  4959. var error = new Error(msg);
  4960. try {
  4961. throw error;
  4962. }
  4963. catch (base) {
  4964. /* istanbul ignore else */
  4965. if (Object.create && Object.defineProperty) {
  4966. error = Object.create(base);
  4967. Object.defineProperty(error, 'column', { value: column });
  4968. }
  4969. }
  4970. /* istanbul ignore next */
  4971. return error;
  4972. };
  4973. ErrorHandler.prototype.createError = function (index, line, col, description) {
  4974. var msg = 'Line ' + line + ': ' + description;
  4975. var error = this.constructError(msg, col);
  4976. error.index = index;
  4977. error.lineNumber = line;
  4978. error.description = description;
  4979. return error;
  4980. };
  4981. ErrorHandler.prototype.throwError = function (index, line, col, description) {
  4982. throw this.createError(index, line, col, description);
  4983. };
  4984. ErrorHandler.prototype.tolerateError = function (index, line, col, description) {
  4985. var error = this.createError(index, line, col, description);
  4986. if (this.tolerant) {
  4987. this.recordError(error);
  4988. }
  4989. else {
  4990. throw error;
  4991. }
  4992. };
  4993. return ErrorHandler;
  4994. }());
  4995. exports.ErrorHandler = ErrorHandler;
  4996. /***/ },
  4997. /* 11 */
  4998. /***/ function(module, exports) {
  4999. "use strict";
  5000. Object.defineProperty(exports, "__esModule", { value: true });
  5001. // Error messages should be identical to V8.
  5002. exports.Messages = {
  5003. BadGetterArity: 'Getter must not have any formal parameters',
  5004. BadSetterArity: 'Setter must have exactly one formal parameter',
  5005. BadSetterRestParameter: 'Setter function argument must not be a rest parameter',
  5006. ConstructorIsAsync: 'Class constructor may not be an async method',
  5007. ConstructorSpecialMethod: 'Class constructor may not be an accessor',
  5008. DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
  5009. DefaultRestParameter: 'Unexpected token =',
  5010. DuplicateBinding: 'Duplicate binding %0',
  5011. DuplicateConstructor: 'A class may only have one constructor',
  5012. DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
  5013. ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer',
  5014. GeneratorInLegacyContext: 'Generator declarations are not allowed in legacy contexts',
  5015. IllegalBreak: 'Illegal break statement',
  5016. IllegalContinue: 'Illegal continue statement',
  5017. IllegalExportDeclaration: 'Unexpected token',
  5018. IllegalImportDeclaration: 'Unexpected token',
  5019. IllegalLanguageModeDirective: 'Illegal \'use strict\' directive in function with non-simple parameter list',
  5020. IllegalReturn: 'Illegal return statement',
  5021. InvalidEscapedReservedWord: 'Keyword must not contain escaped characters',
  5022. InvalidHexEscapeSequence: 'Invalid hexadecimal escape sequence',
  5023. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  5024. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  5025. InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
  5026. InvalidModuleSpecifier: 'Unexpected token',
  5027. InvalidRegExp: 'Invalid regular expression',
  5028. LetInLexicalBinding: 'let is disallowed as a lexically bound name',
  5029. MissingFromClause: 'Unexpected token',
  5030. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  5031. NewlineAfterThrow: 'Illegal newline after throw',
  5032. NoAsAfterImportNamespace: 'Unexpected token',
  5033. NoCatchOrFinally: 'Missing catch or finally after try',
  5034. ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
  5035. Redeclaration: '%0 \'%1\' has already been declared',
  5036. StaticPrototype: 'Classes may not have static property named prototype',
  5037. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  5038. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  5039. StrictFunction: 'In strict mode code, functions can only be declared at top level or inside a block',
  5040. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  5041. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  5042. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  5043. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  5044. StrictModeWith: 'Strict mode code may not include a with statement',
  5045. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  5046. StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
  5047. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  5048. StrictReservedWord: 'Use of future reserved word in strict mode',
  5049. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  5050. TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
  5051. UnexpectedEOS: 'Unexpected end of input',
  5052. UnexpectedIdentifier: 'Unexpected identifier',
  5053. UnexpectedNumber: 'Unexpected number',
  5054. UnexpectedReserved: 'Unexpected reserved word',
  5055. UnexpectedString: 'Unexpected string',
  5056. UnexpectedTemplate: 'Unexpected quasi %0',
  5057. UnexpectedToken: 'Unexpected token %0',
  5058. UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
  5059. UnknownLabel: 'Undefined label \'%0\'',
  5060. UnterminatedRegExp: 'Invalid regular expression: missing /'
  5061. };
  5062. /***/ },
  5063. /* 12 */
  5064. /***/ function(module, exports, __webpack_require__) {
  5065. "use strict";
  5066. Object.defineProperty(exports, "__esModule", { value: true });
  5067. var assert_1 = __webpack_require__(9);
  5068. var character_1 = __webpack_require__(4);
  5069. var messages_1 = __webpack_require__(11);
  5070. function hexValue(ch) {
  5071. return '0123456789abcdef'.indexOf(ch.toLowerCase());
  5072. }
  5073. function octalValue(ch) {
  5074. return '01234567'.indexOf(ch);
  5075. }
  5076. var Scanner = (function () {
  5077. function Scanner(code, handler) {
  5078. this.source = code;
  5079. this.errorHandler = handler;
  5080. this.trackComment = false;
  5081. this.length = code.length;
  5082. this.index = 0;
  5083. this.lineNumber = (code.length > 0) ? 1 : 0;
  5084. this.lineStart = 0;
  5085. this.curlyStack = [];
  5086. }
  5087. Scanner.prototype.saveState = function () {
  5088. return {
  5089. index: this.index,
  5090. lineNumber: this.lineNumber,
  5091. lineStart: this.lineStart
  5092. };
  5093. };
  5094. Scanner.prototype.restoreState = function (state) {
  5095. this.index = state.index;
  5096. this.lineNumber = state.lineNumber;
  5097. this.lineStart = state.lineStart;
  5098. };
  5099. Scanner.prototype.eof = function () {
  5100. return this.index >= this.length;
  5101. };
  5102. Scanner.prototype.throwUnexpectedToken = function (message) {
  5103. if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
  5104. return this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
  5105. };
  5106. Scanner.prototype.tolerateUnexpectedToken = function (message) {
  5107. if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
  5108. this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
  5109. };
  5110. // https://tc39.github.io/ecma262/#sec-comments
  5111. Scanner.prototype.skipSingleLineComment = function (offset) {
  5112. var comments = [];
  5113. var start, loc;
  5114. if (this.trackComment) {
  5115. comments = [];
  5116. start = this.index - offset;
  5117. loc = {
  5118. start: {
  5119. line: this.lineNumber,
  5120. column: this.index - this.lineStart - offset
  5121. },
  5122. end: {}
  5123. };
  5124. }
  5125. while (!this.eof()) {
  5126. var ch = this.source.charCodeAt(this.index);
  5127. ++this.index;
  5128. if (character_1.Character.isLineTerminator(ch)) {
  5129. if (this.trackComment) {
  5130. loc.end = {
  5131. line: this.lineNumber,
  5132. column: this.index - this.lineStart - 1
  5133. };
  5134. var entry = {
  5135. multiLine: false,
  5136. slice: [start + offset, this.index - 1],
  5137. range: [start, this.index - 1],
  5138. loc: loc
  5139. };
  5140. comments.push(entry);
  5141. }
  5142. if (ch === 13 && this.source.charCodeAt(this.index) === 10) {
  5143. ++this.index;
  5144. }
  5145. ++this.lineNumber;
  5146. this.lineStart = this.index;
  5147. return comments;
  5148. }
  5149. }
  5150. if (this.trackComment) {
  5151. loc.end = {
  5152. line: this.lineNumber,
  5153. column: this.index - this.lineStart
  5154. };
  5155. var entry = {
  5156. multiLine: false,
  5157. slice: [start + offset, this.index],
  5158. range: [start, this.index],
  5159. loc: loc
  5160. };
  5161. comments.push(entry);
  5162. }
  5163. return comments;
  5164. };
  5165. Scanner.prototype.skipMultiLineComment = function () {
  5166. var comments = [];
  5167. var start, loc;
  5168. if (this.trackComment) {
  5169. comments = [];
  5170. start = this.index - 2;
  5171. loc = {
  5172. start: {
  5173. line: this.lineNumber,
  5174. column: this.index - this.lineStart - 2
  5175. },
  5176. end: {}
  5177. };
  5178. }
  5179. while (!this.eof()) {
  5180. var ch = this.source.charCodeAt(this.index);
  5181. if (character_1.Character.isLineTerminator(ch)) {
  5182. if (ch === 0x0D && this.source.charCodeAt(this.index + 1) === 0x0A) {
  5183. ++this.index;
  5184. }
  5185. ++this.lineNumber;
  5186. ++this.index;
  5187. this.lineStart = this.index;
  5188. }
  5189. else if (ch === 0x2A) {
  5190. // Block comment ends with '*/'.
  5191. if (this.source.charCodeAt(this.index + 1) === 0x2F) {
  5192. this.index += 2;
  5193. if (this.trackComment) {
  5194. loc.end = {
  5195. line: this.lineNumber,
  5196. column: this.index - this.lineStart
  5197. };
  5198. var entry = {
  5199. multiLine: true,
  5200. slice: [start + 2, this.index - 2],
  5201. range: [start, this.index],
  5202. loc: loc
  5203. };
  5204. comments.push(entry);
  5205. }
  5206. return comments;
  5207. }
  5208. ++this.index;
  5209. }
  5210. else {
  5211. ++this.index;
  5212. }
  5213. }
  5214. // Ran off the end of the file - the whole thing is a comment
  5215. if (this.trackComment) {
  5216. loc.end = {
  5217. line: this.lineNumber,
  5218. column: this.index - this.lineStart
  5219. };
  5220. var entry = {
  5221. multiLine: true,
  5222. slice: [start + 2, this.index],
  5223. range: [start, this.index],
  5224. loc: loc
  5225. };
  5226. comments.push(entry);
  5227. }
  5228. this.tolerateUnexpectedToken();
  5229. return comments;
  5230. };
  5231. Scanner.prototype.scanComments = function () {
  5232. var comments;
  5233. if (this.trackComment) {
  5234. comments = [];
  5235. }
  5236. var start = (this.index === 0);
  5237. while (!this.eof()) {
  5238. var ch = this.source.charCodeAt(this.index);
  5239. if (character_1.Character.isWhiteSpace(ch)) {
  5240. ++this.index;
  5241. }
  5242. else if (character_1.Character.isLineTerminator(ch)) {
  5243. ++this.index;
  5244. if (ch === 0x0D && this.source.charCodeAt(this.index) === 0x0A) {
  5245. ++this.index;
  5246. }
  5247. ++this.lineNumber;
  5248. this.lineStart = this.index;
  5249. start = true;
  5250. }
  5251. else if (ch === 0x2F) {
  5252. ch = this.source.charCodeAt(this.index + 1);
  5253. if (ch === 0x2F) {
  5254. this.index += 2;
  5255. var comment = this.skipSingleLineComment(2);
  5256. if (this.trackComment) {
  5257. comments = comments.concat(comment);
  5258. }
  5259. start = true;
  5260. }
  5261. else if (ch === 0x2A) {
  5262. this.index += 2;
  5263. var comment = this.skipMultiLineComment();
  5264. if (this.trackComment) {
  5265. comments = comments.concat(comment);
  5266. }
  5267. }
  5268. else {
  5269. break;
  5270. }
  5271. }
  5272. else if (start && ch === 0x2D) {
  5273. // U+003E is '>'
  5274. if ((this.source.charCodeAt(this.index + 1) === 0x2D) && (this.source.charCodeAt(this.index + 2) === 0x3E)) {
  5275. // '-->' is a single-line comment
  5276. this.index += 3;
  5277. var comment = this.skipSingleLineComment(3);
  5278. if (this.trackComment) {
  5279. comments = comments.concat(comment);
  5280. }
  5281. }
  5282. else {
  5283. break;
  5284. }
  5285. }
  5286. else if (ch === 0x3C) {
  5287. if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
  5288. this.index += 4; // `<!--`
  5289. var comment = this.skipSingleLineComment(4);
  5290. if (this.trackComment) {
  5291. comments = comments.concat(comment);
  5292. }
  5293. }
  5294. else {
  5295. break;
  5296. }
  5297. }
  5298. else {
  5299. break;
  5300. }
  5301. }
  5302. return comments;
  5303. };
  5304. // https://tc39.github.io/ecma262/#sec-future-reserved-words
  5305. Scanner.prototype.isFutureReservedWord = function (id) {
  5306. switch (id) {
  5307. case 'enum':
  5308. case 'export':
  5309. case 'import':
  5310. case 'super':
  5311. return true;
  5312. default:
  5313. return false;
  5314. }
  5315. };
  5316. Scanner.prototype.isStrictModeReservedWord = function (id) {
  5317. switch (id) {
  5318. case 'implements':
  5319. case 'interface':
  5320. case 'package':
  5321. case 'private':
  5322. case 'protected':
  5323. case 'public':
  5324. case 'static':
  5325. case 'yield':
  5326. case 'let':
  5327. return true;
  5328. default:
  5329. return false;
  5330. }
  5331. };
  5332. Scanner.prototype.isRestrictedWord = function (id) {
  5333. return id === 'eval' || id === 'arguments';
  5334. };
  5335. // https://tc39.github.io/ecma262/#sec-keywords
  5336. Scanner.prototype.isKeyword = function (id) {
  5337. switch (id.length) {
  5338. case 2:
  5339. return (id === 'if') || (id === 'in') || (id === 'do');
  5340. case 3:
  5341. return (id === 'var') || (id === 'for') || (id === 'new') ||
  5342. (id === 'try') || (id === 'let');
  5343. case 4:
  5344. return (id === 'this') || (id === 'else') || (id === 'case') ||
  5345. (id === 'void') || (id === 'with') || (id === 'enum');
  5346. case 5:
  5347. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  5348. (id === 'throw') || (id === 'const') || (id === 'yield') ||
  5349. (id === 'class') || (id === 'super');
  5350. case 6:
  5351. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  5352. (id === 'switch') || (id === 'export') || (id === 'import');
  5353. case 7:
  5354. return (id === 'default') || (id === 'finally') || (id === 'extends');
  5355. case 8:
  5356. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  5357. case 10:
  5358. return (id === 'instanceof');
  5359. default:
  5360. return false;
  5361. }
  5362. };
  5363. Scanner.prototype.codePointAt = function (i) {
  5364. var cp = this.source.charCodeAt(i);
  5365. if (cp >= 0xD800 && cp <= 0xDBFF) {
  5366. var second = this.source.charCodeAt(i + 1);
  5367. if (second >= 0xDC00 && second <= 0xDFFF) {
  5368. var first = cp;
  5369. cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  5370. }
  5371. }
  5372. return cp;
  5373. };
  5374. Scanner.prototype.scanHexEscape = function (prefix) {
  5375. var len = (prefix === 'u') ? 4 : 2;
  5376. var code = 0;
  5377. for (var i = 0; i < len; ++i) {
  5378. if (!this.eof() && character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
  5379. code = code * 16 + hexValue(this.source[this.index++]);
  5380. }
  5381. else {
  5382. return null;
  5383. }
  5384. }
  5385. return String.fromCharCode(code);
  5386. };
  5387. Scanner.prototype.scanUnicodeCodePointEscape = function () {
  5388. var ch = this.source[this.index];
  5389. var code = 0;
  5390. // At least, one hex digit is required.
  5391. if (ch === '}') {
  5392. this.throwUnexpectedToken();
  5393. }
  5394. while (!this.eof()) {
  5395. ch = this.source[this.index++];
  5396. if (!character_1.Character.isHexDigit(ch.charCodeAt(0))) {
  5397. break;
  5398. }
  5399. code = code * 16 + hexValue(ch);
  5400. }
  5401. if (code > 0x10FFFF || ch !== '}') {
  5402. this.throwUnexpectedToken();
  5403. }
  5404. return character_1.Character.fromCodePoint(code);
  5405. };
  5406. Scanner.prototype.getIdentifier = function () {
  5407. var start = this.index++;
  5408. while (!this.eof()) {
  5409. var ch = this.source.charCodeAt(this.index);
  5410. if (ch === 0x5C) {
  5411. // Blackslash (U+005C) marks Unicode escape sequence.
  5412. this.index = start;
  5413. return this.getComplexIdentifier();
  5414. }
  5415. else if (ch >= 0xD800 && ch < 0xDFFF) {
  5416. // Need to handle surrogate pairs.
  5417. this.index = start;
  5418. return this.getComplexIdentifier();
  5419. }
  5420. if (character_1.Character.isIdentifierPart(ch)) {
  5421. ++this.index;
  5422. }
  5423. else {
  5424. break;
  5425. }
  5426. }
  5427. return this.source.slice(start, this.index);
  5428. };
  5429. Scanner.prototype.getComplexIdentifier = function () {
  5430. var cp = this.codePointAt(this.index);
  5431. var id = character_1.Character.fromCodePoint(cp);
  5432. this.index += id.length;
  5433. // '\u' (U+005C, U+0075) denotes an escaped character.
  5434. var ch;
  5435. if (cp === 0x5C) {
  5436. if (this.source.charCodeAt(this.index) !== 0x75) {
  5437. this.throwUnexpectedToken();
  5438. }
  5439. ++this.index;
  5440. if (this.source[this.index] === '{') {
  5441. ++this.index;
  5442. ch = this.scanUnicodeCodePointEscape();
  5443. }
  5444. else {
  5445. ch = this.scanHexEscape('u');
  5446. if (ch === null || ch === '\\' || !character_1.Character.isIdentifierStart(ch.charCodeAt(0))) {
  5447. this.throwUnexpectedToken();
  5448. }
  5449. }
  5450. id = ch;
  5451. }
  5452. while (!this.eof()) {
  5453. cp = this.codePointAt(this.index);
  5454. if (!character_1.Character.isIdentifierPart(cp)) {
  5455. break;
  5456. }
  5457. ch = character_1.Character.fromCodePoint(cp);
  5458. id += ch;
  5459. this.index += ch.length;
  5460. // '\u' (U+005C, U+0075) denotes an escaped character.
  5461. if (cp === 0x5C) {
  5462. id = id.substr(0, id.length - 1);
  5463. if (this.source.charCodeAt(this.index) !== 0x75) {
  5464. this.throwUnexpectedToken();
  5465. }
  5466. ++this.index;
  5467. if (this.source[this.index] === '{') {
  5468. ++this.index;
  5469. ch = this.scanUnicodeCodePointEscape();
  5470. }
  5471. else {
  5472. ch = this.scanHexEscape('u');
  5473. if (ch === null || ch === '\\' || !character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
  5474. this.throwUnexpectedToken();
  5475. }
  5476. }
  5477. id += ch;
  5478. }
  5479. }
  5480. return id;
  5481. };
  5482. Scanner.prototype.octalToDecimal = function (ch) {
  5483. // \0 is not octal escape sequence
  5484. var octal = (ch !== '0');
  5485. var code = octalValue(ch);
  5486. if (!this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
  5487. octal = true;
  5488. code = code * 8 + octalValue(this.source[this.index++]);
  5489. // 3 digits are only allowed when string starts
  5490. // with 0, 1, 2, 3
  5491. if ('0123'.indexOf(ch) >= 0 && !this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
  5492. code = code * 8 + octalValue(this.source[this.index++]);
  5493. }
  5494. }
  5495. return {
  5496. code: code,
  5497. octal: octal
  5498. };
  5499. };
  5500. // https://tc39.github.io/ecma262/#sec-names-and-keywords
  5501. Scanner.prototype.scanIdentifier = function () {
  5502. var type;
  5503. var start = this.index;
  5504. // Backslash (U+005C) starts an escaped character.
  5505. var id = (this.source.charCodeAt(start) === 0x5C) ? this.getComplexIdentifier() : this.getIdentifier();
  5506. // There is no keyword or literal with only one character.
  5507. // Thus, it must be an identifier.
  5508. if (id.length === 1) {
  5509. type = 3 /* Identifier */;
  5510. }
  5511. else if (this.isKeyword(id)) {
  5512. type = 4 /* Keyword */;
  5513. }
  5514. else if (id === 'null') {
  5515. type = 5 /* NullLiteral */;
  5516. }
  5517. else if (id === 'true' || id === 'false') {
  5518. type = 1 /* BooleanLiteral */;
  5519. }
  5520. else {
  5521. type = 3 /* Identifier */;
  5522. }
  5523. if (type !== 3 /* Identifier */ && (start + id.length !== this.index)) {
  5524. var restore = this.index;
  5525. this.index = start;
  5526. this.tolerateUnexpectedToken(messages_1.Messages.InvalidEscapedReservedWord);
  5527. this.index = restore;
  5528. }
  5529. return {
  5530. type: type,
  5531. value: id,
  5532. lineNumber: this.lineNumber,
  5533. lineStart: this.lineStart,
  5534. start: start,
  5535. end: this.index
  5536. };
  5537. };
  5538. // https://tc39.github.io/ecma262/#sec-punctuators
  5539. Scanner.prototype.scanPunctuator = function () {
  5540. var start = this.index;
  5541. // Check for most common single-character punctuators.
  5542. var str = this.source[this.index];
  5543. switch (str) {
  5544. case '(':
  5545. case '{':
  5546. if (str === '{') {
  5547. this.curlyStack.push('{');
  5548. }
  5549. ++this.index;
  5550. break;
  5551. case '.':
  5552. ++this.index;
  5553. if (this.source[this.index] === '.' && this.source[this.index + 1] === '.') {
  5554. // Spread operator: ...
  5555. this.index += 2;
  5556. str = '...';
  5557. }
  5558. break;
  5559. case '}':
  5560. ++this.index;
  5561. this.curlyStack.pop();
  5562. break;
  5563. case ')':
  5564. case ';':
  5565. case ',':
  5566. case '[':
  5567. case ']':
  5568. case ':':
  5569. case '?':
  5570. case '~':
  5571. ++this.index;
  5572. break;
  5573. default:
  5574. // 4-character punctuator.
  5575. str = this.source.substr(this.index, 4);
  5576. if (str === '>>>=') {
  5577. this.index += 4;
  5578. }
  5579. else {
  5580. // 3-character punctuators.
  5581. str = str.substr(0, 3);
  5582. if (str === '===' || str === '!==' || str === '>>>' ||
  5583. str === '<<=' || str === '>>=' || str === '**=') {
  5584. this.index += 3;
  5585. }
  5586. else {
  5587. // 2-character punctuators.
  5588. str = str.substr(0, 2);
  5589. if (str === '&&' || str === '||' || str === '==' || str === '!=' ||
  5590. str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
  5591. str === '++' || str === '--' || str === '<<' || str === '>>' ||
  5592. str === '&=' || str === '|=' || str === '^=' || str === '%=' ||
  5593. str === '<=' || str === '>=' || str === '=>' || str === '**') {
  5594. this.index += 2;
  5595. }
  5596. else {
  5597. // 1-character punctuators.
  5598. str = this.source[this.index];
  5599. if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
  5600. ++this.index;
  5601. }
  5602. }
  5603. }
  5604. }
  5605. }
  5606. if (this.index === start) {
  5607. this.throwUnexpectedToken();
  5608. }
  5609. return {
  5610. type: 7 /* Punctuator */,
  5611. value: str,
  5612. lineNumber: this.lineNumber,
  5613. lineStart: this.lineStart,
  5614. start: start,
  5615. end: this.index
  5616. };
  5617. };
  5618. // https://tc39.github.io/ecma262/#sec-literals-numeric-literals
  5619. Scanner.prototype.scanHexLiteral = function (start) {
  5620. var num = '';
  5621. while (!this.eof()) {
  5622. if (!character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
  5623. break;
  5624. }
  5625. num += this.source[this.index++];
  5626. }
  5627. if (num.length === 0) {
  5628. this.throwUnexpectedToken();
  5629. }
  5630. if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
  5631. this.throwUnexpectedToken();
  5632. }
  5633. return {
  5634. type: 6 /* NumericLiteral */,
  5635. value: parseInt('0x' + num, 16),
  5636. lineNumber: this.lineNumber,
  5637. lineStart: this.lineStart,
  5638. start: start,
  5639. end: this.index
  5640. };
  5641. };
  5642. Scanner.prototype.scanBinaryLiteral = function (start) {
  5643. var num = '';
  5644. var ch;
  5645. while (!this.eof()) {
  5646. ch = this.source[this.index];
  5647. if (ch !== '0' && ch !== '1') {
  5648. break;
  5649. }
  5650. num += this.source[this.index++];
  5651. }
  5652. if (num.length === 0) {
  5653. // only 0b or 0B
  5654. this.throwUnexpectedToken();
  5655. }
  5656. if (!this.eof()) {
  5657. ch = this.source.charCodeAt(this.index);
  5658. /* istanbul ignore else */
  5659. if (character_1.Character.isIdentifierStart(ch) || character_1.Character.isDecimalDigit(ch)) {
  5660. this.throwUnexpectedToken();
  5661. }
  5662. }
  5663. return {
  5664. type: 6 /* NumericLiteral */,
  5665. value: parseInt(num, 2),
  5666. lineNumber: this.lineNumber,
  5667. lineStart: this.lineStart,
  5668. start: start,
  5669. end: this.index
  5670. };
  5671. };
  5672. Scanner.prototype.scanOctalLiteral = function (prefix, start) {
  5673. var num = '';
  5674. var octal = false;
  5675. if (character_1.Character.isOctalDigit(prefix.charCodeAt(0))) {
  5676. octal = true;
  5677. num = '0' + this.source[this.index++];
  5678. }
  5679. else {
  5680. ++this.index;
  5681. }
  5682. while (!this.eof()) {
  5683. if (!character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
  5684. break;
  5685. }
  5686. num += this.source[this.index++];
  5687. }
  5688. if (!octal && num.length === 0) {
  5689. // only 0o or 0O
  5690. this.throwUnexpectedToken();
  5691. }
  5692. if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index)) || character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5693. this.throwUnexpectedToken();
  5694. }
  5695. return {
  5696. type: 6 /* NumericLiteral */,
  5697. value: parseInt(num, 8),
  5698. octal: octal,
  5699. lineNumber: this.lineNumber,
  5700. lineStart: this.lineStart,
  5701. start: start,
  5702. end: this.index
  5703. };
  5704. };
  5705. Scanner.prototype.isImplicitOctalLiteral = function () {
  5706. // Implicit octal, unless there is a non-octal digit.
  5707. // (Annex B.1.1 on Numeric Literals)
  5708. for (var i = this.index + 1; i < this.length; ++i) {
  5709. var ch = this.source[i];
  5710. if (ch === '8' || ch === '9') {
  5711. return false;
  5712. }
  5713. if (!character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5714. return true;
  5715. }
  5716. }
  5717. return true;
  5718. };
  5719. Scanner.prototype.scanNumericLiteral = function () {
  5720. var start = this.index;
  5721. var ch = this.source[start];
  5722. assert_1.assert(character_1.Character.isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'), 'Numeric literal must start with a decimal digit or a decimal point');
  5723. var num = '';
  5724. if (ch !== '.') {
  5725. num = this.source[this.index++];
  5726. ch = this.source[this.index];
  5727. // Hex number starts with '0x'.
  5728. // Octal number starts with '0'.
  5729. // Octal number in ES6 starts with '0o'.
  5730. // Binary number in ES6 starts with '0b'.
  5731. if (num === '0') {
  5732. if (ch === 'x' || ch === 'X') {
  5733. ++this.index;
  5734. return this.scanHexLiteral(start);
  5735. }
  5736. if (ch === 'b' || ch === 'B') {
  5737. ++this.index;
  5738. return this.scanBinaryLiteral(start);
  5739. }
  5740. if (ch === 'o' || ch === 'O') {
  5741. return this.scanOctalLiteral(ch, start);
  5742. }
  5743. if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5744. if (this.isImplicitOctalLiteral()) {
  5745. return this.scanOctalLiteral(ch, start);
  5746. }
  5747. }
  5748. }
  5749. while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5750. num += this.source[this.index++];
  5751. }
  5752. ch = this.source[this.index];
  5753. }
  5754. if (ch === '.') {
  5755. num += this.source[this.index++];
  5756. while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5757. num += this.source[this.index++];
  5758. }
  5759. ch = this.source[this.index];
  5760. }
  5761. if (ch === 'e' || ch === 'E') {
  5762. num += this.source[this.index++];
  5763. ch = this.source[this.index];
  5764. if (ch === '+' || ch === '-') {
  5765. num += this.source[this.index++];
  5766. }
  5767. if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5768. while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5769. num += this.source[this.index++];
  5770. }
  5771. }
  5772. else {
  5773. this.throwUnexpectedToken();
  5774. }
  5775. }
  5776. if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
  5777. this.throwUnexpectedToken();
  5778. }
  5779. return {
  5780. type: 6 /* NumericLiteral */,
  5781. value: parseFloat(num),
  5782. lineNumber: this.lineNumber,
  5783. lineStart: this.lineStart,
  5784. start: start,
  5785. end: this.index
  5786. };
  5787. };
  5788. // https://tc39.github.io/ecma262/#sec-literals-string-literals
  5789. Scanner.prototype.scanStringLiteral = function () {
  5790. var start = this.index;
  5791. var quote = this.source[start];
  5792. assert_1.assert((quote === '\'' || quote === '"'), 'String literal must starts with a quote');
  5793. ++this.index;
  5794. var octal = false;
  5795. var str = '';
  5796. while (!this.eof()) {
  5797. var ch = this.source[this.index++];
  5798. if (ch === quote) {
  5799. quote = '';
  5800. break;
  5801. }
  5802. else if (ch === '\\') {
  5803. ch = this.source[this.index++];
  5804. if (!ch || !character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5805. switch (ch) {
  5806. case 'u':
  5807. if (this.source[this.index] === '{') {
  5808. ++this.index;
  5809. str += this.scanUnicodeCodePointEscape();
  5810. }
  5811. else {
  5812. var unescaped_1 = this.scanHexEscape(ch);
  5813. if (unescaped_1 === null) {
  5814. this.throwUnexpectedToken();
  5815. }
  5816. str += unescaped_1;
  5817. }
  5818. break;
  5819. case 'x':
  5820. var unescaped = this.scanHexEscape(ch);
  5821. if (unescaped === null) {
  5822. this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
  5823. }
  5824. str += unescaped;
  5825. break;
  5826. case 'n':
  5827. str += '\n';
  5828. break;
  5829. case 'r':
  5830. str += '\r';
  5831. break;
  5832. case 't':
  5833. str += '\t';
  5834. break;
  5835. case 'b':
  5836. str += '\b';
  5837. break;
  5838. case 'f':
  5839. str += '\f';
  5840. break;
  5841. case 'v':
  5842. str += '\x0B';
  5843. break;
  5844. case '8':
  5845. case '9':
  5846. str += ch;
  5847. this.tolerateUnexpectedToken();
  5848. break;
  5849. default:
  5850. if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5851. var octToDec = this.octalToDecimal(ch);
  5852. octal = octToDec.octal || octal;
  5853. str += String.fromCharCode(octToDec.code);
  5854. }
  5855. else {
  5856. str += ch;
  5857. }
  5858. break;
  5859. }
  5860. }
  5861. else {
  5862. ++this.lineNumber;
  5863. if (ch === '\r' && this.source[this.index] === '\n') {
  5864. ++this.index;
  5865. }
  5866. this.lineStart = this.index;
  5867. }
  5868. }
  5869. else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5870. break;
  5871. }
  5872. else {
  5873. str += ch;
  5874. }
  5875. }
  5876. if (quote !== '') {
  5877. this.index = start;
  5878. this.throwUnexpectedToken();
  5879. }
  5880. return {
  5881. type: 8 /* StringLiteral */,
  5882. value: str,
  5883. octal: octal,
  5884. lineNumber: this.lineNumber,
  5885. lineStart: this.lineStart,
  5886. start: start,
  5887. end: this.index
  5888. };
  5889. };
  5890. // https://tc39.github.io/ecma262/#sec-template-literal-lexical-components
  5891. Scanner.prototype.scanTemplate = function () {
  5892. var cooked = '';
  5893. var terminated = false;
  5894. var start = this.index;
  5895. var head = (this.source[start] === '`');
  5896. var tail = false;
  5897. var rawOffset = 2;
  5898. ++this.index;
  5899. while (!this.eof()) {
  5900. var ch = this.source[this.index++];
  5901. if (ch === '`') {
  5902. rawOffset = 1;
  5903. tail = true;
  5904. terminated = true;
  5905. break;
  5906. }
  5907. else if (ch === '$') {
  5908. if (this.source[this.index] === '{') {
  5909. this.curlyStack.push('${');
  5910. ++this.index;
  5911. terminated = true;
  5912. break;
  5913. }
  5914. cooked += ch;
  5915. }
  5916. else if (ch === '\\') {
  5917. ch = this.source[this.index++];
  5918. if (!character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5919. switch (ch) {
  5920. case 'n':
  5921. cooked += '\n';
  5922. break;
  5923. case 'r':
  5924. cooked += '\r';
  5925. break;
  5926. case 't':
  5927. cooked += '\t';
  5928. break;
  5929. case 'u':
  5930. if (this.source[this.index] === '{') {
  5931. ++this.index;
  5932. cooked += this.scanUnicodeCodePointEscape();
  5933. }
  5934. else {
  5935. var restore = this.index;
  5936. var unescaped_2 = this.scanHexEscape(ch);
  5937. if (unescaped_2 !== null) {
  5938. cooked += unescaped_2;
  5939. }
  5940. else {
  5941. this.index = restore;
  5942. cooked += ch;
  5943. }
  5944. }
  5945. break;
  5946. case 'x':
  5947. var unescaped = this.scanHexEscape(ch);
  5948. if (unescaped === null) {
  5949. this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
  5950. }
  5951. cooked += unescaped;
  5952. break;
  5953. case 'b':
  5954. cooked += '\b';
  5955. break;
  5956. case 'f':
  5957. cooked += '\f';
  5958. break;
  5959. case 'v':
  5960. cooked += '\v';
  5961. break;
  5962. default:
  5963. if (ch === '0') {
  5964. if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5965. // Illegal: \01 \02 and so on
  5966. this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
  5967. }
  5968. cooked += '\0';
  5969. }
  5970. else if (character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5971. // Illegal: \1 \2
  5972. this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
  5973. }
  5974. else {
  5975. cooked += ch;
  5976. }
  5977. break;
  5978. }
  5979. }
  5980. else {
  5981. ++this.lineNumber;
  5982. if (ch === '\r' && this.source[this.index] === '\n') {
  5983. ++this.index;
  5984. }
  5985. this.lineStart = this.index;
  5986. }
  5987. }
  5988. else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5989. ++this.lineNumber;
  5990. if (ch === '\r' && this.source[this.index] === '\n') {
  5991. ++this.index;
  5992. }
  5993. this.lineStart = this.index;
  5994. cooked += '\n';
  5995. }
  5996. else {
  5997. cooked += ch;
  5998. }
  5999. }
  6000. if (!terminated) {
  6001. this.throwUnexpectedToken();
  6002. }
  6003. if (!head) {
  6004. this.curlyStack.pop();
  6005. }
  6006. return {
  6007. type: 10 /* Template */,
  6008. value: this.source.slice(start + 1, this.index - rawOffset),
  6009. cooked: cooked,
  6010. head: head,
  6011. tail: tail,
  6012. lineNumber: this.lineNumber,
  6013. lineStart: this.lineStart,
  6014. start: start,
  6015. end: this.index
  6016. };
  6017. };
  6018. // https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
  6019. Scanner.prototype.testRegExp = function (pattern, flags) {
  6020. // The BMP character to use as a replacement for astral symbols when
  6021. // translating an ES6 "u"-flagged pattern to an ES5-compatible
  6022. // approximation.
  6023. // Note: replacing with '\uFFFF' enables false positives in unlikely
  6024. // scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
  6025. // pattern that would not be detected by this substitution.
  6026. var astralSubstitute = '\uFFFF';
  6027. var tmp = pattern;
  6028. var self = this;
  6029. if (flags.indexOf('u') >= 0) {
  6030. tmp = tmp
  6031. .replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
  6032. var codePoint = parseInt($1 || $2, 16);
  6033. if (codePoint > 0x10FFFF) {
  6034. self.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
  6035. }
  6036. if (codePoint <= 0xFFFF) {
  6037. return String.fromCharCode(codePoint);
  6038. }
  6039. return astralSubstitute;
  6040. })
  6041. .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, astralSubstitute);
  6042. }
  6043. // First, detect invalid regular expressions.
  6044. try {
  6045. RegExp(tmp);
  6046. }
  6047. catch (e) {
  6048. this.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
  6049. }
  6050. // Return a regular expression object for this pattern-flag pair, or
  6051. // `null` in case the current environment doesn't support the flags it
  6052. // uses.
  6053. try {
  6054. return new RegExp(pattern, flags);
  6055. }
  6056. catch (exception) {
  6057. /* istanbul ignore next */
  6058. return null;
  6059. }
  6060. };
  6061. Scanner.prototype.scanRegExpBody = function () {
  6062. var ch = this.source[this.index];
  6063. assert_1.assert(ch === '/', 'Regular expression literal must start with a slash');
  6064. var str = this.source[this.index++];
  6065. var classMarker = false;
  6066. var terminated = false;
  6067. while (!this.eof()) {
  6068. ch = this.source[this.index++];
  6069. str += ch;
  6070. if (ch === '\\') {
  6071. ch = this.source[this.index++];
  6072. // https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
  6073. if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  6074. this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
  6075. }
  6076. str += ch;
  6077. }
  6078. else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  6079. this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
  6080. }
  6081. else if (classMarker) {
  6082. if (ch === ']') {
  6083. classMarker = false;
  6084. }
  6085. }
  6086. else {
  6087. if (ch === '/') {
  6088. terminated = true;
  6089. break;
  6090. }
  6091. else if (ch === '[') {
  6092. classMarker = true;
  6093. }
  6094. }
  6095. }
  6096. if (!terminated) {
  6097. this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
  6098. }
  6099. // Exclude leading and trailing slash.
  6100. return str.substr(1, str.length - 2);
  6101. };
  6102. Scanner.prototype.scanRegExpFlags = function () {
  6103. var str = '';
  6104. var flags = '';
  6105. while (!this.eof()) {
  6106. var ch = this.source[this.index];
  6107. if (!character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
  6108. break;
  6109. }
  6110. ++this.index;
  6111. if (ch === '\\' && !this.eof()) {
  6112. ch = this.source[this.index];
  6113. if (ch === 'u') {
  6114. ++this.index;
  6115. var restore = this.index;
  6116. var char = this.scanHexEscape('u');
  6117. if (char !== null) {
  6118. flags += char;
  6119. for (str += '\\u'; restore < this.index; ++restore) {
  6120. str += this.source[restore];
  6121. }
  6122. }
  6123. else {
  6124. this.index = restore;
  6125. flags += 'u';
  6126. str += '\\u';
  6127. }
  6128. this.tolerateUnexpectedToken();
  6129. }
  6130. else {
  6131. str += '\\';
  6132. this.tolerateUnexpectedToken();
  6133. }
  6134. }
  6135. else {
  6136. flags += ch;
  6137. str += ch;
  6138. }
  6139. }
  6140. return flags;
  6141. };
  6142. Scanner.prototype.scanRegExp = function () {
  6143. var start = this.index;
  6144. var pattern = this.scanRegExpBody();
  6145. var flags = this.scanRegExpFlags();
  6146. var value = this.testRegExp(pattern, flags);
  6147. return {
  6148. type: 9 /* RegularExpression */,
  6149. value: '',
  6150. pattern: pattern,
  6151. flags: flags,
  6152. regex: value,
  6153. lineNumber: this.lineNumber,
  6154. lineStart: this.lineStart,
  6155. start: start,
  6156. end: this.index
  6157. };
  6158. };
  6159. Scanner.prototype.lex = function () {
  6160. if (this.eof()) {
  6161. return {
  6162. type: 2 /* EOF */,
  6163. value: '',
  6164. lineNumber: this.lineNumber,
  6165. lineStart: this.lineStart,
  6166. start: this.index,
  6167. end: this.index
  6168. };
  6169. }
  6170. var cp = this.source.charCodeAt(this.index);
  6171. if (character_1.Character.isIdentifierStart(cp)) {
  6172. return this.scanIdentifier();
  6173. }
  6174. // Very common: ( and ) and ;
  6175. if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
  6176. return this.scanPunctuator();
  6177. }
  6178. // String literal starts with single quote (U+0027) or double quote (U+0022).
  6179. if (cp === 0x27 || cp === 0x22) {
  6180. return this.scanStringLiteral();
  6181. }
  6182. // Dot (.) U+002E can also start a floating-point number, hence the need
  6183. // to check the next character.
  6184. if (cp === 0x2E) {
  6185. if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index + 1))) {
  6186. return this.scanNumericLiteral();
  6187. }
  6188. return this.scanPunctuator();
  6189. }
  6190. if (character_1.Character.isDecimalDigit(cp)) {
  6191. return this.scanNumericLiteral();
  6192. }
  6193. // Template literals start with ` (U+0060) for template head
  6194. // or } (U+007D) for template middle or template tail.
  6195. if (cp === 0x60 || (cp === 0x7D && this.curlyStack[this.curlyStack.length - 1] === '${')) {
  6196. return this.scanTemplate();
  6197. }
  6198. // Possible identifier start in a surrogate pair.
  6199. if (cp >= 0xD800 && cp < 0xDFFF) {
  6200. if (character_1.Character.isIdentifierStart(this.codePointAt(this.index))) {
  6201. return this.scanIdentifier();
  6202. }
  6203. }
  6204. return this.scanPunctuator();
  6205. };
  6206. return Scanner;
  6207. }());
  6208. exports.Scanner = Scanner;
  6209. /***/ },
  6210. /* 13 */
  6211. /***/ function(module, exports) {
  6212. "use strict";
  6213. Object.defineProperty(exports, "__esModule", { value: true });
  6214. exports.TokenName = {};
  6215. exports.TokenName[1 /* BooleanLiteral */] = 'Boolean';
  6216. exports.TokenName[2 /* EOF */] = '<end>';
  6217. exports.TokenName[3 /* Identifier */] = 'Identifier';
  6218. exports.TokenName[4 /* Keyword */] = 'Keyword';
  6219. exports.TokenName[5 /* NullLiteral */] = 'Null';
  6220. exports.TokenName[6 /* NumericLiteral */] = 'Numeric';
  6221. exports.TokenName[7 /* Punctuator */] = 'Punctuator';
  6222. exports.TokenName[8 /* StringLiteral */] = 'String';
  6223. exports.TokenName[9 /* RegularExpression */] = 'RegularExpression';
  6224. exports.TokenName[10 /* Template */] = 'Template';
  6225. /***/ },
  6226. /* 14 */
  6227. /***/ function(module, exports) {
  6228. "use strict";
  6229. // Generated by generate-xhtml-entities.js. DO NOT MODIFY!
  6230. Object.defineProperty(exports, "__esModule", { value: true });
  6231. exports.XHTMLEntities = {
  6232. quot: '\u0022',
  6233. amp: '\u0026',
  6234. apos: '\u0027',
  6235. gt: '\u003E',
  6236. nbsp: '\u00A0',
  6237. iexcl: '\u00A1',
  6238. cent: '\u00A2',
  6239. pound: '\u00A3',
  6240. curren: '\u00A4',
  6241. yen: '\u00A5',
  6242. brvbar: '\u00A6',
  6243. sect: '\u00A7',
  6244. uml: '\u00A8',
  6245. copy: '\u00A9',
  6246. ordf: '\u00AA',
  6247. laquo: '\u00AB',
  6248. not: '\u00AC',
  6249. shy: '\u00AD',
  6250. reg: '\u00AE',
  6251. macr: '\u00AF',
  6252. deg: '\u00B0',
  6253. plusmn: '\u00B1',
  6254. sup2: '\u00B2',
  6255. sup3: '\u00B3',
  6256. acute: '\u00B4',
  6257. micro: '\u00B5',
  6258. para: '\u00B6',
  6259. middot: '\u00B7',
  6260. cedil: '\u00B8',
  6261. sup1: '\u00B9',
  6262. ordm: '\u00BA',
  6263. raquo: '\u00BB',
  6264. frac14: '\u00BC',
  6265. frac12: '\u00BD',
  6266. frac34: '\u00BE',
  6267. iquest: '\u00BF',
  6268. Agrave: '\u00C0',
  6269. Aacute: '\u00C1',
  6270. Acirc: '\u00C2',
  6271. Atilde: '\u00C3',
  6272. Auml: '\u00C4',
  6273. Aring: '\u00C5',
  6274. AElig: '\u00C6',
  6275. Ccedil: '\u00C7',
  6276. Egrave: '\u00C8',
  6277. Eacute: '\u00C9',
  6278. Ecirc: '\u00CA',
  6279. Euml: '\u00CB',
  6280. Igrave: '\u00CC',
  6281. Iacute: '\u00CD',
  6282. Icirc: '\u00CE',
  6283. Iuml: '\u00CF',
  6284. ETH: '\u00D0',
  6285. Ntilde: '\u00D1',
  6286. Ograve: '\u00D2',
  6287. Oacute: '\u00D3',
  6288. Ocirc: '\u00D4',
  6289. Otilde: '\u00D5',
  6290. Ouml: '\u00D6',
  6291. times: '\u00D7',
  6292. Oslash: '\u00D8',
  6293. Ugrave: '\u00D9',
  6294. Uacute: '\u00DA',
  6295. Ucirc: '\u00DB',
  6296. Uuml: '\u00DC',
  6297. Yacute: '\u00DD',
  6298. THORN: '\u00DE',
  6299. szlig: '\u00DF',
  6300. agrave: '\u00E0',
  6301. aacute: '\u00E1',
  6302. acirc: '\u00E2',
  6303. atilde: '\u00E3',
  6304. auml: '\u00E4',
  6305. aring: '\u00E5',
  6306. aelig: '\u00E6',
  6307. ccedil: '\u00E7',
  6308. egrave: '\u00E8',
  6309. eacute: '\u00E9',
  6310. ecirc: '\u00EA',
  6311. euml: '\u00EB',
  6312. igrave: '\u00EC',
  6313. iacute: '\u00ED',
  6314. icirc: '\u00EE',
  6315. iuml: '\u00EF',
  6316. eth: '\u00F0',
  6317. ntilde: '\u00F1',
  6318. ograve: '\u00F2',
  6319. oacute: '\u00F3',
  6320. ocirc: '\u00F4',
  6321. otilde: '\u00F5',
  6322. ouml: '\u00F6',
  6323. divide: '\u00F7',
  6324. oslash: '\u00F8',
  6325. ugrave: '\u00F9',
  6326. uacute: '\u00FA',
  6327. ucirc: '\u00FB',
  6328. uuml: '\u00FC',
  6329. yacute: '\u00FD',
  6330. thorn: '\u00FE',
  6331. yuml: '\u00FF',
  6332. OElig: '\u0152',
  6333. oelig: '\u0153',
  6334. Scaron: '\u0160',
  6335. scaron: '\u0161',
  6336. Yuml: '\u0178',
  6337. fnof: '\u0192',
  6338. circ: '\u02C6',
  6339. tilde: '\u02DC',
  6340. Alpha: '\u0391',
  6341. Beta: '\u0392',
  6342. Gamma: '\u0393',
  6343. Delta: '\u0394',
  6344. Epsilon: '\u0395',
  6345. Zeta: '\u0396',
  6346. Eta: '\u0397',
  6347. Theta: '\u0398',
  6348. Iota: '\u0399',
  6349. Kappa: '\u039A',
  6350. Lambda: '\u039B',
  6351. Mu: '\u039C',
  6352. Nu: '\u039D',
  6353. Xi: '\u039E',
  6354. Omicron: '\u039F',
  6355. Pi: '\u03A0',
  6356. Rho: '\u03A1',
  6357. Sigma: '\u03A3',
  6358. Tau: '\u03A4',
  6359. Upsilon: '\u03A5',
  6360. Phi: '\u03A6',
  6361. Chi: '\u03A7',
  6362. Psi: '\u03A8',
  6363. Omega: '\u03A9',
  6364. alpha: '\u03B1',
  6365. beta: '\u03B2',
  6366. gamma: '\u03B3',
  6367. delta: '\u03B4',
  6368. epsilon: '\u03B5',
  6369. zeta: '\u03B6',
  6370. eta: '\u03B7',
  6371. theta: '\u03B8',
  6372. iota: '\u03B9',
  6373. kappa: '\u03BA',
  6374. lambda: '\u03BB',
  6375. mu: '\u03BC',
  6376. nu: '\u03BD',
  6377. xi: '\u03BE',
  6378. omicron: '\u03BF',
  6379. pi: '\u03C0',
  6380. rho: '\u03C1',
  6381. sigmaf: '\u03C2',
  6382. sigma: '\u03C3',
  6383. tau: '\u03C4',
  6384. upsilon: '\u03C5',
  6385. phi: '\u03C6',
  6386. chi: '\u03C7',
  6387. psi: '\u03C8',
  6388. omega: '\u03C9',
  6389. thetasym: '\u03D1',
  6390. upsih: '\u03D2',
  6391. piv: '\u03D6',
  6392. ensp: '\u2002',
  6393. emsp: '\u2003',
  6394. thinsp: '\u2009',
  6395. zwnj: '\u200C',
  6396. zwj: '\u200D',
  6397. lrm: '\u200E',
  6398. rlm: '\u200F',
  6399. ndash: '\u2013',
  6400. mdash: '\u2014',
  6401. lsquo: '\u2018',
  6402. rsquo: '\u2019',
  6403. sbquo: '\u201A',
  6404. ldquo: '\u201C',
  6405. rdquo: '\u201D',
  6406. bdquo: '\u201E',
  6407. dagger: '\u2020',
  6408. Dagger: '\u2021',
  6409. bull: '\u2022',
  6410. hellip: '\u2026',
  6411. permil: '\u2030',
  6412. prime: '\u2032',
  6413. Prime: '\u2033',
  6414. lsaquo: '\u2039',
  6415. rsaquo: '\u203A',
  6416. oline: '\u203E',
  6417. frasl: '\u2044',
  6418. euro: '\u20AC',
  6419. image: '\u2111',
  6420. weierp: '\u2118',
  6421. real: '\u211C',
  6422. trade: '\u2122',
  6423. alefsym: '\u2135',
  6424. larr: '\u2190',
  6425. uarr: '\u2191',
  6426. rarr: '\u2192',
  6427. darr: '\u2193',
  6428. harr: '\u2194',
  6429. crarr: '\u21B5',
  6430. lArr: '\u21D0',
  6431. uArr: '\u21D1',
  6432. rArr: '\u21D2',
  6433. dArr: '\u21D3',
  6434. hArr: '\u21D4',
  6435. forall: '\u2200',
  6436. part: '\u2202',
  6437. exist: '\u2203',
  6438. empty: '\u2205',
  6439. nabla: '\u2207',
  6440. isin: '\u2208',
  6441. notin: '\u2209',
  6442. ni: '\u220B',
  6443. prod: '\u220F',
  6444. sum: '\u2211',
  6445. minus: '\u2212',
  6446. lowast: '\u2217',
  6447. radic: '\u221A',
  6448. prop: '\u221D',
  6449. infin: '\u221E',
  6450. ang: '\u2220',
  6451. and: '\u2227',
  6452. or: '\u2228',
  6453. cap: '\u2229',
  6454. cup: '\u222A',
  6455. int: '\u222B',
  6456. there4: '\u2234',
  6457. sim: '\u223C',
  6458. cong: '\u2245',
  6459. asymp: '\u2248',
  6460. ne: '\u2260',
  6461. equiv: '\u2261',
  6462. le: '\u2264',
  6463. ge: '\u2265',
  6464. sub: '\u2282',
  6465. sup: '\u2283',
  6466. nsub: '\u2284',
  6467. sube: '\u2286',
  6468. supe: '\u2287',
  6469. oplus: '\u2295',
  6470. otimes: '\u2297',
  6471. perp: '\u22A5',
  6472. sdot: '\u22C5',
  6473. lceil: '\u2308',
  6474. rceil: '\u2309',
  6475. lfloor: '\u230A',
  6476. rfloor: '\u230B',
  6477. loz: '\u25CA',
  6478. spades: '\u2660',
  6479. clubs: '\u2663',
  6480. hearts: '\u2665',
  6481. diams: '\u2666',
  6482. lang: '\u27E8',
  6483. rang: '\u27E9'
  6484. };
  6485. /***/ },
  6486. /* 15 */
  6487. /***/ function(module, exports, __webpack_require__) {
  6488. "use strict";
  6489. Object.defineProperty(exports, "__esModule", { value: true });
  6490. var error_handler_1 = __webpack_require__(10);
  6491. var scanner_1 = __webpack_require__(12);
  6492. var token_1 = __webpack_require__(13);
  6493. var Reader = (function () {
  6494. function Reader() {
  6495. this.values = [];
  6496. this.curly = this.paren = -1;
  6497. }
  6498. // A function following one of those tokens is an expression.
  6499. Reader.prototype.beforeFunctionExpression = function (t) {
  6500. return ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
  6501. 'return', 'case', 'delete', 'throw', 'void',
  6502. // assignment operators
  6503. '=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=',
  6504. '&=', '|=', '^=', ',',
  6505. // binary/unary operators
  6506. '+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
  6507. '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
  6508. '<=', '<', '>', '!=', '!=='].indexOf(t) >= 0;
  6509. };
  6510. // Determine if forward slash (/) is an operator or part of a regular expression
  6511. // https://github.com/mozilla/sweet.js/wiki/design
  6512. Reader.prototype.isRegexStart = function () {
  6513. var previous = this.values[this.values.length - 1];
  6514. var regex = (previous !== null);
  6515. switch (previous) {
  6516. case 'this':
  6517. case ']':
  6518. regex = false;
  6519. break;
  6520. case ')':
  6521. var keyword = this.values[this.paren - 1];
  6522. regex = (keyword === 'if' || keyword === 'while' || keyword === 'for' || keyword === 'with');
  6523. break;
  6524. case '}':
  6525. // Dividing a function by anything makes little sense,
  6526. // but we have to check for that.
  6527. regex = false;
  6528. if (this.values[this.curly - 3] === 'function') {
  6529. // Anonymous function, e.g. function(){} /42
  6530. var check = this.values[this.curly - 4];
  6531. regex = check ? !this.beforeFunctionExpression(check) : false;
  6532. }
  6533. else if (this.values[this.curly - 4] === 'function') {
  6534. // Named function, e.g. function f(){} /42/
  6535. var check = this.values[this.curly - 5];
  6536. regex = check ? !this.beforeFunctionExpression(check) : true;
  6537. }
  6538. break;
  6539. default:
  6540. break;
  6541. }
  6542. return regex;
  6543. };
  6544. Reader.prototype.push = function (token) {
  6545. if (token.type === 7 /* Punctuator */ || token.type === 4 /* Keyword */) {
  6546. if (token.value === '{') {
  6547. this.curly = this.values.length;
  6548. }
  6549. else if (token.value === '(') {
  6550. this.paren = this.values.length;
  6551. }
  6552. this.values.push(token.value);
  6553. }
  6554. else {
  6555. this.values.push(null);
  6556. }
  6557. };
  6558. return Reader;
  6559. }());
  6560. var Tokenizer = (function () {
  6561. function Tokenizer(code, config) {
  6562. this.errorHandler = new error_handler_1.ErrorHandler();
  6563. this.errorHandler.tolerant = config ? (typeof config.tolerant === 'boolean' && config.tolerant) : false;
  6564. this.scanner = new scanner_1.Scanner(code, this.errorHandler);
  6565. this.scanner.trackComment = config ? (typeof config.comment === 'boolean' && config.comment) : false;
  6566. this.trackRange = config ? (typeof config.range === 'boolean' && config.range) : false;
  6567. this.trackLoc = config ? (typeof config.loc === 'boolean' && config.loc) : false;
  6568. this.buffer = [];
  6569. this.reader = new Reader();
  6570. }
  6571. Tokenizer.prototype.errors = function () {
  6572. return this.errorHandler.errors;
  6573. };
  6574. Tokenizer.prototype.getNextToken = function () {
  6575. if (this.buffer.length === 0) {
  6576. var comments = this.scanner.scanComments();
  6577. if (this.scanner.trackComment) {
  6578. for (var i = 0; i < comments.length; ++i) {
  6579. var e = comments[i];
  6580. var value = this.scanner.source.slice(e.slice[0], e.slice[1]);
  6581. var comment = {
  6582. type: e.multiLine ? 'BlockComment' : 'LineComment',
  6583. value: value
  6584. };
  6585. if (this.trackRange) {
  6586. comment.range = e.range;
  6587. }
  6588. if (this.trackLoc) {
  6589. comment.loc = e.loc;
  6590. }
  6591. this.buffer.push(comment);
  6592. }
  6593. }
  6594. if (!this.scanner.eof()) {
  6595. var loc = void 0;
  6596. if (this.trackLoc) {
  6597. loc = {
  6598. start: {
  6599. line: this.scanner.lineNumber,
  6600. column: this.scanner.index - this.scanner.lineStart
  6601. },
  6602. end: {}
  6603. };
  6604. }
  6605. var startRegex = (this.scanner.source[this.scanner.index] === '/') && this.reader.isRegexStart();
  6606. var token = startRegex ? this.scanner.scanRegExp() : this.scanner.lex();
  6607. this.reader.push(token);
  6608. var entry = {
  6609. type: token_1.TokenName[token.type],
  6610. value: this.scanner.source.slice(token.start, token.end)
  6611. };
  6612. if (this.trackRange) {
  6613. entry.range = [token.start, token.end];
  6614. }
  6615. if (this.trackLoc) {
  6616. loc.end = {
  6617. line: this.scanner.lineNumber,
  6618. column: this.scanner.index - this.scanner.lineStart
  6619. };
  6620. entry.loc = loc;
  6621. }
  6622. if (token.type === 9 /* RegularExpression */) {
  6623. var pattern = token.pattern;
  6624. var flags = token.flags;
  6625. entry.regex = { pattern: pattern, flags: flags };
  6626. }
  6627. this.buffer.push(entry);
  6628. }
  6629. }
  6630. return this.buffer.shift();
  6631. };
  6632. return Tokenizer;
  6633. }());
  6634. exports.Tokenizer = Tokenizer;
  6635. /***/ }
  6636. /******/ ])
  6637. });
  6638. ;