tsc.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637
  1. /*! *****************************************************************************
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  4. this file except in compliance with the License. You may obtain a copy of the
  5. License at http://www.apache.org/licenses/LICENSE-2.0
  6. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  7. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  8. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  9. MERCHANTABLITY OR NON-INFRINGEMENT.
  10. See the Apache Version 2.0 License for specific language governing permissions
  11. and limitations under the License.
  12. ***************************************************************************** */
  13. var ts;
  14. (function (ts) {
  15. var OperationCanceledException = (function () {
  16. function OperationCanceledException() {
  17. }
  18. return OperationCanceledException;
  19. })();
  20. ts.OperationCanceledException = OperationCanceledException;
  21. (function (ExitStatus) {
  22. ExitStatus[ExitStatus["Success"] = 0] = "Success";
  23. ExitStatus[ExitStatus["DiagnosticsPresent_OutputsSkipped"] = 1] = "DiagnosticsPresent_OutputsSkipped";
  24. ExitStatus[ExitStatus["DiagnosticsPresent_OutputsGenerated"] = 2] = "DiagnosticsPresent_OutputsGenerated";
  25. })(ts.ExitStatus || (ts.ExitStatus = {}));
  26. var ExitStatus = ts.ExitStatus;
  27. (function (TypeReferenceSerializationKind) {
  28. TypeReferenceSerializationKind[TypeReferenceSerializationKind["Unknown"] = 0] = "Unknown";
  29. TypeReferenceSerializationKind[TypeReferenceSerializationKind["TypeWithConstructSignatureAndValue"] = 1] = "TypeWithConstructSignatureAndValue";
  30. TypeReferenceSerializationKind[TypeReferenceSerializationKind["VoidType"] = 2] = "VoidType";
  31. TypeReferenceSerializationKind[TypeReferenceSerializationKind["NumberLikeType"] = 3] = "NumberLikeType";
  32. TypeReferenceSerializationKind[TypeReferenceSerializationKind["StringLikeType"] = 4] = "StringLikeType";
  33. TypeReferenceSerializationKind[TypeReferenceSerializationKind["BooleanType"] = 5] = "BooleanType";
  34. TypeReferenceSerializationKind[TypeReferenceSerializationKind["ArrayLikeType"] = 6] = "ArrayLikeType";
  35. TypeReferenceSerializationKind[TypeReferenceSerializationKind["ESSymbolType"] = 7] = "ESSymbolType";
  36. TypeReferenceSerializationKind[TypeReferenceSerializationKind["TypeWithCallSignature"] = 8] = "TypeWithCallSignature";
  37. TypeReferenceSerializationKind[TypeReferenceSerializationKind["ObjectType"] = 9] = "ObjectType";
  38. })(ts.TypeReferenceSerializationKind || (ts.TypeReferenceSerializationKind = {}));
  39. var TypeReferenceSerializationKind = ts.TypeReferenceSerializationKind;
  40. (function (DiagnosticCategory) {
  41. DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning";
  42. DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error";
  43. DiagnosticCategory[DiagnosticCategory["Message"] = 2] = "Message";
  44. })(ts.DiagnosticCategory || (ts.DiagnosticCategory = {}));
  45. var DiagnosticCategory = ts.DiagnosticCategory;
  46. })(ts || (ts = {}));
  47. var ts;
  48. (function (ts) {
  49. function createFileMap(getCanonicalFileName) {
  50. var files = {};
  51. return {
  52. get: get,
  53. set: set,
  54. contains: contains,
  55. remove: remove,
  56. clear: clear,
  57. forEachValue: forEachValueInMap
  58. };
  59. function set(fileName, value) {
  60. files[normalizeKey(fileName)] = value;
  61. }
  62. function get(fileName) {
  63. return files[normalizeKey(fileName)];
  64. }
  65. function contains(fileName) {
  66. return hasProperty(files, normalizeKey(fileName));
  67. }
  68. function remove(fileName) {
  69. var key = normalizeKey(fileName);
  70. delete files[key];
  71. }
  72. function forEachValueInMap(f) {
  73. forEachValue(files, f);
  74. }
  75. function normalizeKey(key) {
  76. return getCanonicalFileName(normalizeSlashes(key));
  77. }
  78. function clear() {
  79. files = {};
  80. }
  81. }
  82. ts.createFileMap = createFileMap;
  83. function forEach(array, callback) {
  84. if (array) {
  85. for (var i = 0, len = array.length; i < len; i++) {
  86. var result = callback(array[i], i);
  87. if (result) {
  88. return result;
  89. }
  90. }
  91. }
  92. return undefined;
  93. }
  94. ts.forEach = forEach;
  95. function contains(array, value) {
  96. if (array) {
  97. for (var _i = 0; _i < array.length; _i++) {
  98. var v = array[_i];
  99. if (v === value) {
  100. return true;
  101. }
  102. }
  103. }
  104. return false;
  105. }
  106. ts.contains = contains;
  107. function indexOf(array, value) {
  108. if (array) {
  109. for (var i = 0, len = array.length; i < len; i++) {
  110. if (array[i] === value) {
  111. return i;
  112. }
  113. }
  114. }
  115. return -1;
  116. }
  117. ts.indexOf = indexOf;
  118. function countWhere(array, predicate) {
  119. var count = 0;
  120. if (array) {
  121. for (var _i = 0; _i < array.length; _i++) {
  122. var v = array[_i];
  123. if (predicate(v)) {
  124. count++;
  125. }
  126. }
  127. }
  128. return count;
  129. }
  130. ts.countWhere = countWhere;
  131. function filter(array, f) {
  132. var result;
  133. if (array) {
  134. result = [];
  135. for (var _i = 0; _i < array.length; _i++) {
  136. var item = array[_i];
  137. if (f(item)) {
  138. result.push(item);
  139. }
  140. }
  141. }
  142. return result;
  143. }
  144. ts.filter = filter;
  145. function map(array, f) {
  146. var result;
  147. if (array) {
  148. result = [];
  149. for (var _i = 0; _i < array.length; _i++) {
  150. var v = array[_i];
  151. result.push(f(v));
  152. }
  153. }
  154. return result;
  155. }
  156. ts.map = map;
  157. function concatenate(array1, array2) {
  158. if (!array2 || !array2.length)
  159. return array1;
  160. if (!array1 || !array1.length)
  161. return array2;
  162. return array1.concat(array2);
  163. }
  164. ts.concatenate = concatenate;
  165. function deduplicate(array) {
  166. var result;
  167. if (array) {
  168. result = [];
  169. for (var _i = 0; _i < array.length; _i++) {
  170. var item = array[_i];
  171. if (!contains(result, item)) {
  172. result.push(item);
  173. }
  174. }
  175. }
  176. return result;
  177. }
  178. ts.deduplicate = deduplicate;
  179. function sum(array, prop) {
  180. var result = 0;
  181. for (var _i = 0; _i < array.length; _i++) {
  182. var v = array[_i];
  183. result += v[prop];
  184. }
  185. return result;
  186. }
  187. ts.sum = sum;
  188. function addRange(to, from) {
  189. if (to && from) {
  190. for (var _i = 0; _i < from.length; _i++) {
  191. var v = from[_i];
  192. to.push(v);
  193. }
  194. }
  195. }
  196. ts.addRange = addRange;
  197. function rangeEquals(array1, array2, pos, end) {
  198. while (pos < end) {
  199. if (array1[pos] !== array2[pos]) {
  200. return false;
  201. }
  202. pos++;
  203. }
  204. return true;
  205. }
  206. ts.rangeEquals = rangeEquals;
  207. function lastOrUndefined(array) {
  208. if (array.length === 0) {
  209. return undefined;
  210. }
  211. return array[array.length - 1];
  212. }
  213. ts.lastOrUndefined = lastOrUndefined;
  214. function binarySearch(array, value) {
  215. var low = 0;
  216. var high = array.length - 1;
  217. while (low <= high) {
  218. var middle = low + ((high - low) >> 1);
  219. var midValue = array[middle];
  220. if (midValue === value) {
  221. return middle;
  222. }
  223. else if (midValue > value) {
  224. high = middle - 1;
  225. }
  226. else {
  227. low = middle + 1;
  228. }
  229. }
  230. return ~low;
  231. }
  232. ts.binarySearch = binarySearch;
  233. function reduceLeft(array, f, initial) {
  234. if (array) {
  235. var count = array.length;
  236. if (count > 0) {
  237. var pos = 0;
  238. var result = arguments.length <= 2 ? array[pos++] : initial;
  239. while (pos < count) {
  240. result = f(result, array[pos++]);
  241. }
  242. return result;
  243. }
  244. }
  245. return initial;
  246. }
  247. ts.reduceLeft = reduceLeft;
  248. function reduceRight(array, f, initial) {
  249. if (array) {
  250. var pos = array.length - 1;
  251. if (pos >= 0) {
  252. var result = arguments.length <= 2 ? array[pos--] : initial;
  253. while (pos >= 0) {
  254. result = f(result, array[pos--]);
  255. }
  256. return result;
  257. }
  258. }
  259. return initial;
  260. }
  261. ts.reduceRight = reduceRight;
  262. var hasOwnProperty = Object.prototype.hasOwnProperty;
  263. function hasProperty(map, key) {
  264. return hasOwnProperty.call(map, key);
  265. }
  266. ts.hasProperty = hasProperty;
  267. function getProperty(map, key) {
  268. return hasOwnProperty.call(map, key) ? map[key] : undefined;
  269. }
  270. ts.getProperty = getProperty;
  271. function isEmpty(map) {
  272. for (var id in map) {
  273. if (hasProperty(map, id)) {
  274. return false;
  275. }
  276. }
  277. return true;
  278. }
  279. ts.isEmpty = isEmpty;
  280. function clone(object) {
  281. var result = {};
  282. for (var id in object) {
  283. result[id] = object[id];
  284. }
  285. return result;
  286. }
  287. ts.clone = clone;
  288. function extend(first, second) {
  289. var result = {};
  290. for (var id in first) {
  291. result[id] = first[id];
  292. }
  293. for (var id in second) {
  294. if (!hasProperty(result, id)) {
  295. result[id] = second[id];
  296. }
  297. }
  298. return result;
  299. }
  300. ts.extend = extend;
  301. function forEachValue(map, callback) {
  302. var result;
  303. for (var id in map) {
  304. if (result = callback(map[id]))
  305. break;
  306. }
  307. return result;
  308. }
  309. ts.forEachValue = forEachValue;
  310. function forEachKey(map, callback) {
  311. var result;
  312. for (var id in map) {
  313. if (result = callback(id))
  314. break;
  315. }
  316. return result;
  317. }
  318. ts.forEachKey = forEachKey;
  319. function lookUp(map, key) {
  320. return hasProperty(map, key) ? map[key] : undefined;
  321. }
  322. ts.lookUp = lookUp;
  323. function copyMap(source, target) {
  324. for (var p in source) {
  325. target[p] = source[p];
  326. }
  327. }
  328. ts.copyMap = copyMap;
  329. function arrayToMap(array, makeKey) {
  330. var result = {};
  331. forEach(array, function (value) {
  332. result[makeKey(value)] = value;
  333. });
  334. return result;
  335. }
  336. ts.arrayToMap = arrayToMap;
  337. function memoize(callback) {
  338. var value;
  339. return function () {
  340. if (callback) {
  341. value = callback();
  342. callback = undefined;
  343. }
  344. return value;
  345. };
  346. }
  347. ts.memoize = memoize;
  348. function formatStringFromArgs(text, args, baseIndex) {
  349. baseIndex = baseIndex || 0;
  350. return text.replace(/{(\d+)}/g, function (match, index) { return args[+index + baseIndex]; });
  351. }
  352. ts.localizedDiagnosticMessages = undefined;
  353. function getLocaleSpecificMessage(message) {
  354. return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message]
  355. ? ts.localizedDiagnosticMessages[message]
  356. : message;
  357. }
  358. ts.getLocaleSpecificMessage = getLocaleSpecificMessage;
  359. function createFileDiagnostic(file, start, length, message) {
  360. var end = start + length;
  361. Debug.assert(start >= 0, "start must be non-negative, is " + start);
  362. Debug.assert(length >= 0, "length must be non-negative, is " + length);
  363. if (file) {
  364. Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length);
  365. Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length);
  366. }
  367. var text = getLocaleSpecificMessage(message.key);
  368. if (arguments.length > 4) {
  369. text = formatStringFromArgs(text, arguments, 4);
  370. }
  371. return {
  372. file: file,
  373. start: start,
  374. length: length,
  375. messageText: text,
  376. category: message.category,
  377. code: message.code
  378. };
  379. }
  380. ts.createFileDiagnostic = createFileDiagnostic;
  381. function createCompilerDiagnostic(message) {
  382. var text = getLocaleSpecificMessage(message.key);
  383. if (arguments.length > 1) {
  384. text = formatStringFromArgs(text, arguments, 1);
  385. }
  386. return {
  387. file: undefined,
  388. start: undefined,
  389. length: undefined,
  390. messageText: text,
  391. category: message.category,
  392. code: message.code
  393. };
  394. }
  395. ts.createCompilerDiagnostic = createCompilerDiagnostic;
  396. function chainDiagnosticMessages(details, message) {
  397. var text = getLocaleSpecificMessage(message.key);
  398. if (arguments.length > 2) {
  399. text = formatStringFromArgs(text, arguments, 2);
  400. }
  401. return {
  402. messageText: text,
  403. category: message.category,
  404. code: message.code,
  405. next: details
  406. };
  407. }
  408. ts.chainDiagnosticMessages = chainDiagnosticMessages;
  409. function concatenateDiagnosticMessageChains(headChain, tailChain) {
  410. var lastChain = headChain;
  411. while (lastChain.next) {
  412. lastChain = lastChain.next;
  413. }
  414. lastChain.next = tailChain;
  415. return headChain;
  416. }
  417. ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains;
  418. function compareValues(a, b) {
  419. if (a === b)
  420. return 0;
  421. if (a === undefined)
  422. return -1;
  423. if (b === undefined)
  424. return 1;
  425. return a < b ? -1 : 1;
  426. }
  427. ts.compareValues = compareValues;
  428. function getDiagnosticFileName(diagnostic) {
  429. return diagnostic.file ? diagnostic.file.fileName : undefined;
  430. }
  431. function compareDiagnostics(d1, d2) {
  432. return compareValues(getDiagnosticFileName(d1), getDiagnosticFileName(d2)) ||
  433. compareValues(d1.start, d2.start) ||
  434. compareValues(d1.length, d2.length) ||
  435. compareValues(d1.code, d2.code) ||
  436. compareMessageText(d1.messageText, d2.messageText) ||
  437. 0;
  438. }
  439. ts.compareDiagnostics = compareDiagnostics;
  440. function compareMessageText(text1, text2) {
  441. while (text1 && text2) {
  442. var string1 = typeof text1 === "string" ? text1 : text1.messageText;
  443. var string2 = typeof text2 === "string" ? text2 : text2.messageText;
  444. var res = compareValues(string1, string2);
  445. if (res) {
  446. return res;
  447. }
  448. text1 = typeof text1 === "string" ? undefined : text1.next;
  449. text2 = typeof text2 === "string" ? undefined : text2.next;
  450. }
  451. if (!text1 && !text2) {
  452. return 0;
  453. }
  454. return text1 ? 1 : -1;
  455. }
  456. function sortAndDeduplicateDiagnostics(diagnostics) {
  457. return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics));
  458. }
  459. ts.sortAndDeduplicateDiagnostics = sortAndDeduplicateDiagnostics;
  460. function deduplicateSortedDiagnostics(diagnostics) {
  461. if (diagnostics.length < 2) {
  462. return diagnostics;
  463. }
  464. var newDiagnostics = [diagnostics[0]];
  465. var previousDiagnostic = diagnostics[0];
  466. for (var i = 1; i < diagnostics.length; i++) {
  467. var currentDiagnostic = diagnostics[i];
  468. var isDupe = compareDiagnostics(currentDiagnostic, previousDiagnostic) === 0;
  469. if (!isDupe) {
  470. newDiagnostics.push(currentDiagnostic);
  471. previousDiagnostic = currentDiagnostic;
  472. }
  473. }
  474. return newDiagnostics;
  475. }
  476. ts.deduplicateSortedDiagnostics = deduplicateSortedDiagnostics;
  477. function normalizeSlashes(path) {
  478. return path.replace(/\\/g, "/");
  479. }
  480. ts.normalizeSlashes = normalizeSlashes;
  481. function getRootLength(path) {
  482. if (path.charCodeAt(0) === 47) {
  483. if (path.charCodeAt(1) !== 47)
  484. return 1;
  485. var p1 = path.indexOf("/", 2);
  486. if (p1 < 0)
  487. return 2;
  488. var p2 = path.indexOf("/", p1 + 1);
  489. if (p2 < 0)
  490. return p1 + 1;
  491. return p2 + 1;
  492. }
  493. if (path.charCodeAt(1) === 58) {
  494. if (path.charCodeAt(2) === 47)
  495. return 3;
  496. return 2;
  497. }
  498. if (path.lastIndexOf("file:///", 0) === 0) {
  499. return "file:///".length;
  500. }
  501. var idx = path.indexOf("://");
  502. if (idx !== -1) {
  503. return idx + "://".length;
  504. }
  505. return 0;
  506. }
  507. ts.getRootLength = getRootLength;
  508. ts.directorySeparator = "/";
  509. function getNormalizedParts(normalizedSlashedPath, rootLength) {
  510. var parts = normalizedSlashedPath.substr(rootLength).split(ts.directorySeparator);
  511. var normalized = [];
  512. for (var _i = 0; _i < parts.length; _i++) {
  513. var part = parts[_i];
  514. if (part !== ".") {
  515. if (part === ".." && normalized.length > 0 && lastOrUndefined(normalized) !== "..") {
  516. normalized.pop();
  517. }
  518. else {
  519. if (part) {
  520. normalized.push(part);
  521. }
  522. }
  523. }
  524. }
  525. return normalized;
  526. }
  527. function normalizePath(path) {
  528. path = normalizeSlashes(path);
  529. var rootLength = getRootLength(path);
  530. var normalized = getNormalizedParts(path, rootLength);
  531. return path.substr(0, rootLength) + normalized.join(ts.directorySeparator);
  532. }
  533. ts.normalizePath = normalizePath;
  534. function getDirectoryPath(path) {
  535. return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(ts.directorySeparator)));
  536. }
  537. ts.getDirectoryPath = getDirectoryPath;
  538. function isUrl(path) {
  539. return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
  540. }
  541. ts.isUrl = isUrl;
  542. function isRootedDiskPath(path) {
  543. return getRootLength(path) !== 0;
  544. }
  545. ts.isRootedDiskPath = isRootedDiskPath;
  546. function normalizedPathComponents(path, rootLength) {
  547. var normalizedParts = getNormalizedParts(path, rootLength);
  548. return [path.substr(0, rootLength)].concat(normalizedParts);
  549. }
  550. function getNormalizedPathComponents(path, currentDirectory) {
  551. path = normalizeSlashes(path);
  552. var rootLength = getRootLength(path);
  553. if (rootLength === 0) {
  554. path = combinePaths(normalizeSlashes(currentDirectory), path);
  555. rootLength = getRootLength(path);
  556. }
  557. return normalizedPathComponents(path, rootLength);
  558. }
  559. ts.getNormalizedPathComponents = getNormalizedPathComponents;
  560. function getNormalizedAbsolutePath(fileName, currentDirectory) {
  561. return getNormalizedPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
  562. }
  563. ts.getNormalizedAbsolutePath = getNormalizedAbsolutePath;
  564. function getNormalizedPathFromPathComponents(pathComponents) {
  565. if (pathComponents && pathComponents.length) {
  566. return pathComponents[0] + pathComponents.slice(1).join(ts.directorySeparator);
  567. }
  568. }
  569. ts.getNormalizedPathFromPathComponents = getNormalizedPathFromPathComponents;
  570. function getNormalizedPathComponentsOfUrl(url) {
  571. var urlLength = url.length;
  572. var rootLength = url.indexOf("://") + "://".length;
  573. while (rootLength < urlLength) {
  574. if (url.charCodeAt(rootLength) === 47) {
  575. rootLength++;
  576. }
  577. else {
  578. break;
  579. }
  580. }
  581. if (rootLength === urlLength) {
  582. return [url];
  583. }
  584. var indexOfNextSlash = url.indexOf(ts.directorySeparator, rootLength);
  585. if (indexOfNextSlash !== -1) {
  586. rootLength = indexOfNextSlash + 1;
  587. return normalizedPathComponents(url, rootLength);
  588. }
  589. else {
  590. return [url + ts.directorySeparator];
  591. }
  592. }
  593. function getNormalizedPathOrUrlComponents(pathOrUrl, currentDirectory) {
  594. if (isUrl(pathOrUrl)) {
  595. return getNormalizedPathComponentsOfUrl(pathOrUrl);
  596. }
  597. else {
  598. return getNormalizedPathComponents(pathOrUrl, currentDirectory);
  599. }
  600. }
  601. function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) {
  602. var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
  603. var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
  604. if (directoryComponents.length > 1 && lastOrUndefined(directoryComponents) === "") {
  605. directoryComponents.length--;
  606. }
  607. for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) {
  608. if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) {
  609. break;
  610. }
  611. }
  612. if (joinStartIndex) {
  613. var relativePath = "";
  614. var relativePathComponents = pathComponents.slice(joinStartIndex, pathComponents.length);
  615. for (; joinStartIndex < directoryComponents.length; joinStartIndex++) {
  616. if (directoryComponents[joinStartIndex] !== "") {
  617. relativePath = relativePath + ".." + ts.directorySeparator;
  618. }
  619. }
  620. return relativePath + relativePathComponents.join(ts.directorySeparator);
  621. }
  622. var absolutePath = getNormalizedPathFromPathComponents(pathComponents);
  623. if (isAbsolutePathAnUrl && isRootedDiskPath(absolutePath)) {
  624. absolutePath = "file:///" + absolutePath;
  625. }
  626. return absolutePath;
  627. }
  628. ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl;
  629. function getBaseFileName(path) {
  630. if (!path) {
  631. return undefined;
  632. }
  633. var i = path.lastIndexOf(ts.directorySeparator);
  634. return i < 0 ? path : path.substring(i + 1);
  635. }
  636. ts.getBaseFileName = getBaseFileName;
  637. function combinePaths(path1, path2) {
  638. if (!(path1 && path1.length))
  639. return path2;
  640. if (!(path2 && path2.length))
  641. return path1;
  642. if (getRootLength(path2) !== 0)
  643. return path2;
  644. if (path1.charAt(path1.length - 1) === ts.directorySeparator)
  645. return path1 + path2;
  646. return path1 + ts.directorySeparator + path2;
  647. }
  648. ts.combinePaths = combinePaths;
  649. function fileExtensionIs(path, extension) {
  650. var pathLen = path.length;
  651. var extLen = extension.length;
  652. return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
  653. }
  654. ts.fileExtensionIs = fileExtensionIs;
  655. ts.supportedExtensions = [".ts", ".tsx", ".d.ts"];
  656. ts.moduleFileExtensions = ts.supportedExtensions;
  657. function isSupportedSourceFileName(fileName) {
  658. if (!fileName) {
  659. return false;
  660. }
  661. for (var _i = 0; _i < ts.supportedExtensions.length; _i++) {
  662. var extension = ts.supportedExtensions[_i];
  663. if (fileExtensionIs(fileName, extension)) {
  664. return true;
  665. }
  666. }
  667. return false;
  668. }
  669. ts.isSupportedSourceFileName = isSupportedSourceFileName;
  670. var extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
  671. function removeFileExtension(path) {
  672. for (var _i = 0; _i < extensionsToRemove.length; _i++) {
  673. var ext = extensionsToRemove[_i];
  674. if (fileExtensionIs(path, ext)) {
  675. return path.substr(0, path.length - ext.length);
  676. }
  677. }
  678. return path;
  679. }
  680. ts.removeFileExtension = removeFileExtension;
  681. var backslashOrDoubleQuote = /[\"\\]/g;
  682. var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
  683. var escapedCharsMap = {
  684. "\0": "\\0",
  685. "\t": "\\t",
  686. "\v": "\\v",
  687. "\f": "\\f",
  688. "\b": "\\b",
  689. "\r": "\\r",
  690. "\n": "\\n",
  691. "\\": "\\\\",
  692. "\"": "\\\"",
  693. "\u2028": "\\u2028",
  694. "\u2029": "\\u2029",
  695. "\u0085": "\\u0085"
  696. };
  697. function Symbol(flags, name) {
  698. this.flags = flags;
  699. this.name = name;
  700. this.declarations = undefined;
  701. }
  702. function Type(checker, flags) {
  703. this.flags = flags;
  704. }
  705. function Signature(checker) {
  706. }
  707. ts.objectAllocator = {
  708. getNodeConstructor: function (kind) {
  709. function Node() {
  710. }
  711. Node.prototype = {
  712. kind: kind,
  713. pos: -1,
  714. end: -1,
  715. flags: 0,
  716. parent: undefined
  717. };
  718. return Node;
  719. },
  720. getSymbolConstructor: function () { return Symbol; },
  721. getTypeConstructor: function () { return Type; },
  722. getSignatureConstructor: function () { return Signature; }
  723. };
  724. var Debug;
  725. (function (Debug) {
  726. var currentAssertionLevel = 0;
  727. function shouldAssert(level) {
  728. return currentAssertionLevel >= level;
  729. }
  730. Debug.shouldAssert = shouldAssert;
  731. function assert(expression, message, verboseDebugInfo) {
  732. if (!expression) {
  733. var verboseDebugString = "";
  734. if (verboseDebugInfo) {
  735. verboseDebugString = "\r\nVerbose Debug Information: " + verboseDebugInfo();
  736. }
  737. throw new Error("Debug Failure. False expression: " + (message || "") + verboseDebugString);
  738. }
  739. }
  740. Debug.assert = assert;
  741. function fail(message) {
  742. Debug.assert(false, message);
  743. }
  744. Debug.fail = fail;
  745. })(Debug = ts.Debug || (ts.Debug = {}));
  746. function copyListRemovingItem(item, list) {
  747. var copiedList = [];
  748. for (var i = 0, len = list.length; i < len; i++) {
  749. if (list[i] !== item) {
  750. copiedList.push(list[i]);
  751. }
  752. }
  753. return copiedList;
  754. }
  755. ts.copyListRemovingItem = copyListRemovingItem;
  756. })(ts || (ts = {}));
  757. var ts;
  758. (function (ts) {
  759. ts.sys = (function () {
  760. function getWScriptSystem() {
  761. var fso = new ActiveXObject("Scripting.FileSystemObject");
  762. var fileStream = new ActiveXObject("ADODB.Stream");
  763. fileStream.Type = 2;
  764. var binaryStream = new ActiveXObject("ADODB.Stream");
  765. binaryStream.Type = 1;
  766. var args = [];
  767. for (var i = 0; i < WScript.Arguments.length; i++) {
  768. args[i] = WScript.Arguments.Item(i);
  769. }
  770. function readFile(fileName, encoding) {
  771. if (!fso.FileExists(fileName)) {
  772. return undefined;
  773. }
  774. fileStream.Open();
  775. try {
  776. if (encoding) {
  777. fileStream.Charset = encoding;
  778. fileStream.LoadFromFile(fileName);
  779. }
  780. else {
  781. fileStream.Charset = "x-ansi";
  782. fileStream.LoadFromFile(fileName);
  783. var bom = fileStream.ReadText(2) || "";
  784. fileStream.Position = 0;
  785. fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
  786. }
  787. return fileStream.ReadText();
  788. }
  789. catch (e) {
  790. throw e;
  791. }
  792. finally {
  793. fileStream.Close();
  794. }
  795. }
  796. function writeFile(fileName, data, writeByteOrderMark) {
  797. fileStream.Open();
  798. binaryStream.Open();
  799. try {
  800. fileStream.Charset = "utf-8";
  801. fileStream.WriteText(data);
  802. if (writeByteOrderMark) {
  803. fileStream.Position = 0;
  804. }
  805. else {
  806. fileStream.Position = 3;
  807. }
  808. fileStream.CopyTo(binaryStream);
  809. binaryStream.SaveToFile(fileName, 2);
  810. }
  811. finally {
  812. binaryStream.Close();
  813. fileStream.Close();
  814. }
  815. }
  816. function getCanonicalPath(path) {
  817. return path.toLowerCase();
  818. }
  819. function getNames(collection) {
  820. var result = [];
  821. for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
  822. result.push(e.item().Name);
  823. }
  824. return result.sort();
  825. }
  826. function readDirectory(path, extension, exclude) {
  827. var result = [];
  828. exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); });
  829. visitDirectory(path);
  830. return result;
  831. function visitDirectory(path) {
  832. var folder = fso.GetFolder(path || ".");
  833. var files = getNames(folder.files);
  834. for (var _i = 0; _i < files.length; _i++) {
  835. var current = files[_i];
  836. var name_1 = ts.combinePaths(path, current);
  837. if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) {
  838. result.push(name_1);
  839. }
  840. }
  841. var subfolders = getNames(folder.subfolders);
  842. for (var _a = 0; _a < subfolders.length; _a++) {
  843. var current = subfolders[_a];
  844. var name_2 = ts.combinePaths(path, current);
  845. if (!ts.contains(exclude, getCanonicalPath(name_2))) {
  846. visitDirectory(name_2);
  847. }
  848. }
  849. }
  850. }
  851. return {
  852. args: args,
  853. newLine: "\r\n",
  854. useCaseSensitiveFileNames: false,
  855. write: function (s) {
  856. WScript.StdOut.Write(s);
  857. },
  858. readFile: readFile,
  859. writeFile: writeFile,
  860. resolvePath: function (path) {
  861. return fso.GetAbsolutePathName(path);
  862. },
  863. fileExists: function (path) {
  864. return fso.FileExists(path);
  865. },
  866. directoryExists: function (path) {
  867. return fso.FolderExists(path);
  868. },
  869. createDirectory: function (directoryName) {
  870. if (!this.directoryExists(directoryName)) {
  871. fso.CreateFolder(directoryName);
  872. }
  873. },
  874. getExecutingFilePath: function () {
  875. return WScript.ScriptFullName;
  876. },
  877. getCurrentDirectory: function () {
  878. return new ActiveXObject("WScript.Shell").CurrentDirectory;
  879. },
  880. readDirectory: readDirectory,
  881. exit: function (exitCode) {
  882. try {
  883. WScript.Quit(exitCode);
  884. }
  885. catch (e) {
  886. }
  887. }
  888. };
  889. }
  890. function getNodeSystem() {
  891. var _fs = require("fs");
  892. var _path = require("path");
  893. var _os = require("os");
  894. function createWatchedFileSet(interval, chunkSize) {
  895. if (interval === void 0) { interval = 2500; }
  896. if (chunkSize === void 0) { chunkSize = 30; }
  897. var watchedFiles = [];
  898. var nextFileToCheck = 0;
  899. var watchTimer;
  900. function getModifiedTime(fileName) {
  901. return _fs.statSync(fileName).mtime;
  902. }
  903. function poll(checkedIndex) {
  904. var watchedFile = watchedFiles[checkedIndex];
  905. if (!watchedFile) {
  906. return;
  907. }
  908. _fs.stat(watchedFile.fileName, function (err, stats) {
  909. if (err) {
  910. watchedFile.callback(watchedFile.fileName);
  911. }
  912. else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
  913. watchedFile.mtime = getModifiedTime(watchedFile.fileName);
  914. watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
  915. }
  916. });
  917. }
  918. function startWatchTimer() {
  919. watchTimer = setInterval(function () {
  920. var count = 0;
  921. var nextToCheck = nextFileToCheck;
  922. var firstCheck = -1;
  923. while ((count < chunkSize) && (nextToCheck !== firstCheck)) {
  924. poll(nextToCheck);
  925. if (firstCheck < 0) {
  926. firstCheck = nextToCheck;
  927. }
  928. nextToCheck++;
  929. if (nextToCheck === watchedFiles.length) {
  930. nextToCheck = 0;
  931. }
  932. count++;
  933. }
  934. nextFileToCheck = nextToCheck;
  935. }, interval);
  936. }
  937. function addFile(fileName, callback) {
  938. var file = {
  939. fileName: fileName,
  940. callback: callback,
  941. mtime: getModifiedTime(fileName)
  942. };
  943. watchedFiles.push(file);
  944. if (watchedFiles.length === 1) {
  945. startWatchTimer();
  946. }
  947. return file;
  948. }
  949. function removeFile(file) {
  950. watchedFiles = ts.copyListRemovingItem(file, watchedFiles);
  951. }
  952. return {
  953. getModifiedTime: getModifiedTime,
  954. poll: poll,
  955. startWatchTimer: startWatchTimer,
  956. addFile: addFile,
  957. removeFile: removeFile
  958. };
  959. }
  960. var watchedFileSet = createWatchedFileSet();
  961. function isNode4OrLater() {
  962. return parseInt(process.version.charAt(1)) >= 4;
  963. }
  964. var platform = _os.platform();
  965. var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
  966. function readFile(fileName, encoding) {
  967. if (!_fs.existsSync(fileName)) {
  968. return undefined;
  969. }
  970. var buffer = _fs.readFileSync(fileName);
  971. var len = buffer.length;
  972. if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
  973. len &= ~1;
  974. for (var i = 0; i < len; i += 2) {
  975. var temp = buffer[i];
  976. buffer[i] = buffer[i + 1];
  977. buffer[i + 1] = temp;
  978. }
  979. return buffer.toString("utf16le", 2);
  980. }
  981. if (len >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
  982. return buffer.toString("utf16le", 2);
  983. }
  984. if (len >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
  985. return buffer.toString("utf8", 3);
  986. }
  987. return buffer.toString("utf8");
  988. }
  989. function writeFile(fileName, data, writeByteOrderMark) {
  990. if (writeByteOrderMark) {
  991. data = "\uFEFF" + data;
  992. }
  993. _fs.writeFileSync(fileName, data, "utf8");
  994. }
  995. function getCanonicalPath(path) {
  996. return useCaseSensitiveFileNames ? path.toLowerCase() : path;
  997. }
  998. function readDirectory(path, extension, exclude) {
  999. var result = [];
  1000. exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); });
  1001. visitDirectory(path);
  1002. return result;
  1003. function visitDirectory(path) {
  1004. var files = _fs.readdirSync(path || ".").sort();
  1005. var directories = [];
  1006. for (var _i = 0; _i < files.length; _i++) {
  1007. var current = files[_i];
  1008. var name_3 = ts.combinePaths(path, current);
  1009. if (!ts.contains(exclude, getCanonicalPath(name_3))) {
  1010. var stat = _fs.statSync(name_3);
  1011. if (stat.isFile()) {
  1012. if (!extension || ts.fileExtensionIs(name_3, extension)) {
  1013. result.push(name_3);
  1014. }
  1015. }
  1016. else if (stat.isDirectory()) {
  1017. directories.push(name_3);
  1018. }
  1019. }
  1020. }
  1021. for (var _a = 0; _a < directories.length; _a++) {
  1022. var current = directories[_a];
  1023. visitDirectory(current);
  1024. }
  1025. }
  1026. }
  1027. return {
  1028. args: process.argv.slice(2),
  1029. newLine: _os.EOL,
  1030. useCaseSensitiveFileNames: useCaseSensitiveFileNames,
  1031. write: function (s) {
  1032. var buffer = new Buffer(s, "utf8");
  1033. var offset = 0;
  1034. var toWrite = buffer.length;
  1035. var written = 0;
  1036. while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) {
  1037. offset += written;
  1038. toWrite -= written;
  1039. }
  1040. },
  1041. readFile: readFile,
  1042. writeFile: writeFile,
  1043. watchFile: function (fileName, callback) {
  1044. if (isNode4OrLater()) {
  1045. return _fs.watch(fileName, function (eventName, relativeFileName) { return callback(fileName); });
  1046. }
  1047. var watchedFile = watchedFileSet.addFile(fileName, callback);
  1048. return {
  1049. close: function () { return watchedFileSet.removeFile(watchedFile); }
  1050. };
  1051. },
  1052. watchDirectory: function (path, callback, recursive) {
  1053. return _fs.watch(path, { persisten: true, recursive: !!recursive }, function (eventName, relativeFileName) {
  1054. if (eventName === "rename") {
  1055. callback(!relativeFileName ? relativeFileName : ts.normalizePath(ts.combinePaths(path, relativeFileName)));
  1056. }
  1057. ;
  1058. });
  1059. },
  1060. resolvePath: function (path) {
  1061. return _path.resolve(path);
  1062. },
  1063. fileExists: function (path) {
  1064. return _fs.existsSync(path);
  1065. },
  1066. directoryExists: function (path) {
  1067. return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
  1068. },
  1069. createDirectory: function (directoryName) {
  1070. if (!this.directoryExists(directoryName)) {
  1071. _fs.mkdirSync(directoryName);
  1072. }
  1073. },
  1074. getExecutingFilePath: function () {
  1075. return __filename;
  1076. },
  1077. getCurrentDirectory: function () {
  1078. return process.cwd();
  1079. },
  1080. readDirectory: readDirectory,
  1081. getMemoryUsage: function () {
  1082. if (global.gc) {
  1083. global.gc();
  1084. }
  1085. return process.memoryUsage().heapUsed;
  1086. },
  1087. exit: function (exitCode) {
  1088. process.exit(exitCode);
  1089. }
  1090. };
  1091. }
  1092. if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
  1093. return getWScriptSystem();
  1094. }
  1095. else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
  1096. return getNodeSystem();
  1097. }
  1098. else {
  1099. return undefined;
  1100. }
  1101. })();
  1102. })(ts || (ts = {}));
  1103. var ts;
  1104. (function (ts) {
  1105. ts.Diagnostics = {
  1106. Unterminated_string_literal: { code: 1002, category: ts.DiagnosticCategory.Error, key: "Unterminated string literal." },
  1107. Identifier_expected: { code: 1003, category: ts.DiagnosticCategory.Error, key: "Identifier expected." },
  1108. _0_expected: { code: 1005, category: ts.DiagnosticCategory.Error, key: "'{0}' expected." },
  1109. A_file_cannot_have_a_reference_to_itself: { code: 1006, category: ts.DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
  1110. Trailing_comma_not_allowed: { code: 1009, category: ts.DiagnosticCategory.Error, key: "Trailing comma not allowed." },
  1111. Asterisk_Slash_expected: { code: 1010, category: ts.DiagnosticCategory.Error, key: "'*/' expected." },
  1112. Unexpected_token: { code: 1012, category: ts.DiagnosticCategory.Error, key: "Unexpected token." },
  1113. A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: ts.DiagnosticCategory.Error, key: "A rest parameter must be last in a parameter list." },
  1114. Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: ts.DiagnosticCategory.Error, key: "Parameter cannot have question mark and initializer." },
  1115. A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: ts.DiagnosticCategory.Error, key: "A required parameter cannot follow an optional parameter." },
  1116. An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: ts.DiagnosticCategory.Error, key: "An index signature cannot have a rest parameter." },
  1117. An_index_signature_parameter_cannot_have_an_accessibility_modifier: { code: 1018, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have an accessibility modifier." },
  1118. An_index_signature_parameter_cannot_have_a_question_mark: { code: 1019, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have a question mark." },
  1119. An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have an initializer." },
  1120. An_index_signature_must_have_a_type_annotation: { code: 1021, category: ts.DiagnosticCategory.Error, key: "An index signature must have a type annotation." },
  1121. An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: ts.DiagnosticCategory.Error, key: "An index signature parameter must have a type annotation." },
  1122. An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: ts.DiagnosticCategory.Error, key: "An index signature parameter type must be 'string' or 'number'." },
  1123. Accessibility_modifier_already_seen: { code: 1028, category: ts.DiagnosticCategory.Error, key: "Accessibility modifier already seen." },
  1124. _0_modifier_must_precede_1_modifier: { code: 1029, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." },
  1125. _0_modifier_already_seen: { code: 1030, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier already seen." },
  1126. _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." },
  1127. super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: ts.DiagnosticCategory.Error, key: "'super' must be followed by an argument list or member access." },
  1128. Only_ambient_modules_can_use_quoted_names: { code: 1035, category: ts.DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." },
  1129. Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: ts.DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." },
  1130. A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: ts.DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used in an already ambient context." },
  1131. Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: ts.DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." },
  1132. _0_modifier_cannot_be_used_in_an_ambient_context: { code: 1040, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used in an ambient context." },
  1133. _0_modifier_cannot_be_used_with_a_class_declaration: { code: 1041, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with a class declaration." },
  1134. _0_modifier_cannot_be_used_here: { code: 1042, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used here." },
  1135. _0_modifier_cannot_appear_on_a_data_property: { code: 1043, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a data property." },
  1136. _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." },
  1137. A_0_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an interface declaration." },
  1138. A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: ts.DiagnosticCategory.Error, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." },
  1139. A_rest_parameter_cannot_be_optional: { code: 1047, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot be optional." },
  1140. A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." },
  1141. A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor must have exactly one parameter." },
  1142. A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have an optional parameter." },
  1143. A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor parameter cannot have an initializer." },
  1144. A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have rest parameter." },
  1145. A_get_accessor_cannot_have_parameters: { code: 1054, category: ts.DiagnosticCategory.Error, key: "A 'get' accessor cannot have parameters." },
  1146. Type_0_is_not_a_valid_async_function_return_type: { code: 1055, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not a valid async function return type." },
  1147. Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: ts.DiagnosticCategory.Error, key: "Accessors are only available when targeting ECMAScript 5 and higher." },
  1148. An_async_function_or_method_must_have_a_valid_awaitable_return_type: { code: 1057, category: ts.DiagnosticCategory.Error, key: "An async function or method must have a valid awaitable return type." },
  1149. Operand_for_await_does_not_have_a_valid_callable_then_member: { code: 1058, category: ts.DiagnosticCategory.Error, key: "Operand for 'await' does not have a valid callable 'then' member." },
  1150. Return_expression_in_async_function_does_not_have_a_valid_callable_then_member: { code: 1059, category: ts.DiagnosticCategory.Error, key: "Return expression in async function does not have a valid callable 'then' member." },
  1151. Expression_body_for_async_arrow_function_does_not_have_a_valid_callable_then_member: { code: 1060, category: ts.DiagnosticCategory.Error, key: "Expression body for async arrow function does not have a valid callable 'then' member." },
  1152. Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." },
  1153. _0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: { code: 1062, category: ts.DiagnosticCategory.Error, key: "{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method." },
  1154. An_export_assignment_cannot_be_used_in_a_namespace: { code: 1063, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a namespace." },
  1155. In_ambient_enum_declarations_member_initializer_must_be_constant_expression: { code: 1066, category: ts.DiagnosticCategory.Error, key: "In ambient enum declarations member initializer must be constant expression." },
  1156. Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: ts.DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." },
  1157. A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an import declaration." },
  1158. Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." },
  1159. Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal literals are not available when targeting ECMAScript 5 and higher." },
  1160. An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An accessor cannot be declared in an ambient context." },
  1161. _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a constructor declaration." },
  1162. _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a parameter." },
  1163. Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: { code: 1091, category: ts.DiagnosticCategory.Error, key: "Only a single variable declaration is allowed in a 'for...in' statement." },
  1164. Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: ts.DiagnosticCategory.Error, key: "Type parameters cannot appear on a constructor declaration." },
  1165. Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: ts.DiagnosticCategory.Error, key: "Type annotation cannot appear on a constructor declaration." },
  1166. An_accessor_cannot_have_type_parameters: { code: 1094, category: ts.DiagnosticCategory.Error, key: "An accessor cannot have type parameters." },
  1167. A_set_accessor_cannot_have_a_return_type_annotation: { code: 1095, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have a return type annotation." },
  1168. An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: ts.DiagnosticCategory.Error, key: "An index signature must have exactly one parameter." },
  1169. _0_list_cannot_be_empty: { code: 1097, category: ts.DiagnosticCategory.Error, key: "'{0}' list cannot be empty." },
  1170. Type_parameter_list_cannot_be_empty: { code: 1098, category: ts.DiagnosticCategory.Error, key: "Type parameter list cannot be empty." },
  1171. Type_argument_list_cannot_be_empty: { code: 1099, category: ts.DiagnosticCategory.Error, key: "Type argument list cannot be empty." },
  1172. Invalid_use_of_0_in_strict_mode: { code: 1100, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}' in strict mode." },
  1173. with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in strict mode." },
  1174. delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: ts.DiagnosticCategory.Error, key: "'delete' cannot be called on an identifier in strict mode." },
  1175. A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: { code: 1104, category: ts.DiagnosticCategory.Error, key: "A 'continue' statement can only be used within an enclosing iteration statement." },
  1176. A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: { code: 1105, category: ts.DiagnosticCategory.Error, key: "A 'break' statement can only be used within an enclosing iteration or switch statement." },
  1177. Jump_target_cannot_cross_function_boundary: { code: 1107, category: ts.DiagnosticCategory.Error, key: "Jump target cannot cross function boundary." },
  1178. A_return_statement_can_only_be_used_within_a_function_body: { code: 1108, category: ts.DiagnosticCategory.Error, key: "A 'return' statement can only be used within a function body." },
  1179. Expression_expected: { code: 1109, category: ts.DiagnosticCategory.Error, key: "Expression expected." },
  1180. Type_expected: { code: 1110, category: ts.DiagnosticCategory.Error, key: "Type expected." },
  1181. A_class_member_cannot_be_declared_optional: { code: 1112, category: ts.DiagnosticCategory.Error, key: "A class member cannot be declared optional." },
  1182. A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: ts.DiagnosticCategory.Error, key: "A 'default' clause cannot appear more than once in a 'switch' statement." },
  1183. Duplicate_label_0: { code: 1114, category: ts.DiagnosticCategory.Error, key: "Duplicate label '{0}'" },
  1184. A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: { code: 1115, category: ts.DiagnosticCategory.Error, key: "A 'continue' statement can only jump to a label of an enclosing iteration statement." },
  1185. A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: { code: 1116, category: ts.DiagnosticCategory.Error, key: "A 'break' statement can only jump to a label of an enclosing statement." },
  1186. An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1117, category: ts.DiagnosticCategory.Error, key: "An object literal cannot have multiple properties with the same name in strict mode." },
  1187. An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: ts.DiagnosticCategory.Error, key: "An object literal cannot have multiple get/set accessors with the same name." },
  1188. An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: ts.DiagnosticCategory.Error, key: "An object literal cannot have property and accessor with the same name." },
  1189. An_export_assignment_cannot_have_modifiers: { code: 1120, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot have modifiers." },
  1190. Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: ts.DiagnosticCategory.Error, key: "Octal literals are not allowed in strict mode." },
  1191. A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: ts.DiagnosticCategory.Error, key: "A tuple type element list cannot be empty." },
  1192. Variable_declaration_list_cannot_be_empty: { code: 1123, category: ts.DiagnosticCategory.Error, key: "Variable declaration list cannot be empty." },
  1193. Digit_expected: { code: 1124, category: ts.DiagnosticCategory.Error, key: "Digit expected." },
  1194. Hexadecimal_digit_expected: { code: 1125, category: ts.DiagnosticCategory.Error, key: "Hexadecimal digit expected." },
  1195. Unexpected_end_of_text: { code: 1126, category: ts.DiagnosticCategory.Error, key: "Unexpected end of text." },
  1196. Invalid_character: { code: 1127, category: ts.DiagnosticCategory.Error, key: "Invalid character." },
  1197. Declaration_or_statement_expected: { code: 1128, category: ts.DiagnosticCategory.Error, key: "Declaration or statement expected." },
  1198. Statement_expected: { code: 1129, category: ts.DiagnosticCategory.Error, key: "Statement expected." },
  1199. case_or_default_expected: { code: 1130, category: ts.DiagnosticCategory.Error, key: "'case' or 'default' expected." },
  1200. Property_or_signature_expected: { code: 1131, category: ts.DiagnosticCategory.Error, key: "Property or signature expected." },
  1201. Enum_member_expected: { code: 1132, category: ts.DiagnosticCategory.Error, key: "Enum member expected." },
  1202. Variable_declaration_expected: { code: 1134, category: ts.DiagnosticCategory.Error, key: "Variable declaration expected." },
  1203. Argument_expression_expected: { code: 1135, category: ts.DiagnosticCategory.Error, key: "Argument expression expected." },
  1204. Property_assignment_expected: { code: 1136, category: ts.DiagnosticCategory.Error, key: "Property assignment expected." },
  1205. Expression_or_comma_expected: { code: 1137, category: ts.DiagnosticCategory.Error, key: "Expression or comma expected." },
  1206. Parameter_declaration_expected: { code: 1138, category: ts.DiagnosticCategory.Error, key: "Parameter declaration expected." },
  1207. Type_parameter_declaration_expected: { code: 1139, category: ts.DiagnosticCategory.Error, key: "Type parameter declaration expected." },
  1208. Type_argument_expected: { code: 1140, category: ts.DiagnosticCategory.Error, key: "Type argument expected." },
  1209. String_literal_expected: { code: 1141, category: ts.DiagnosticCategory.Error, key: "String literal expected." },
  1210. Line_break_not_permitted_here: { code: 1142, category: ts.DiagnosticCategory.Error, key: "Line break not permitted here." },
  1211. or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "'{' or ';' expected." },
  1212. Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: ts.DiagnosticCategory.Error, key: "Modifiers not permitted on index signature members." },
  1213. Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration expected." },
  1214. Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import declarations in a namespace cannot reference a module." },
  1215. Cannot_compile_modules_unless_the_module_flag_is_provided: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules unless the '--module' flag is provided." },
  1216. File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File name '{0}' differs from already included file name '{1}' only in casing" },
  1217. new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
  1218. const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
  1219. const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: ts.DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." },
  1220. let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: ts.DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
  1221. Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." },
  1222. Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
  1223. An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
  1224. A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: ts.DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." },
  1225. Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." },
  1226. A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: ts.DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." },
  1227. A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: ts.DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." },
  1228. A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol: { code: 1168, category: ts.DiagnosticCategory.Error, key: "A computed property name in a method overload must directly refer to a built-in symbol." },
  1229. A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol: { code: 1169, category: ts.DiagnosticCategory.Error, key: "A computed property name in an interface must directly refer to a built-in symbol." },
  1230. A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol: { code: 1170, category: ts.DiagnosticCategory.Error, key: "A computed property name in a type literal must directly refer to a built-in symbol." },
  1231. A_comma_expression_is_not_allowed_in_a_computed_property_name: { code: 1171, category: ts.DiagnosticCategory.Error, key: "A comma expression is not allowed in a computed property name." },
  1232. extends_clause_already_seen: { code: 1172, category: ts.DiagnosticCategory.Error, key: "'extends' clause already seen." },
  1233. extends_clause_must_precede_implements_clause: { code: 1173, category: ts.DiagnosticCategory.Error, key: "'extends' clause must precede 'implements' clause." },
  1234. Classes_can_only_extend_a_single_class: { code: 1174, category: ts.DiagnosticCategory.Error, key: "Classes can only extend a single class." },
  1235. implements_clause_already_seen: { code: 1175, category: ts.DiagnosticCategory.Error, key: "'implements' clause already seen." },
  1236. Interface_declaration_cannot_have_implements_clause: { code: 1176, category: ts.DiagnosticCategory.Error, key: "Interface declaration cannot have 'implements' clause." },
  1237. Binary_digit_expected: { code: 1177, category: ts.DiagnosticCategory.Error, key: "Binary digit expected." },
  1238. Octal_digit_expected: { code: 1178, category: ts.DiagnosticCategory.Error, key: "Octal digit expected." },
  1239. Unexpected_token_expected: { code: 1179, category: ts.DiagnosticCategory.Error, key: "Unexpected token. '{' expected." },
  1240. Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." },
  1241. Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." },
  1242. A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." },
  1243. An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1183, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." },
  1244. Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
  1245. Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
  1246. A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." },
  1247. A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: ts.DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." },
  1248. Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement: { code: 1188, category: ts.DiagnosticCategory.Error, key: "Only a single variable declaration is allowed in a 'for...of' statement." },
  1249. The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer: { code: 1189, category: ts.DiagnosticCategory.Error, key: "The variable declaration of a 'for...in' statement cannot have an initializer." },
  1250. The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer: { code: 1190, category: ts.DiagnosticCategory.Error, key: "The variable declaration of a 'for...of' statement cannot have an initializer." },
  1251. An_import_declaration_cannot_have_modifiers: { code: 1191, category: ts.DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." },
  1252. Module_0_has_no_default_export: { code: 1192, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no default export." },
  1253. An_export_declaration_cannot_have_modifiers: { code: 1193, category: ts.DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." },
  1254. Export_declarations_are_not_permitted_in_a_namespace: { code: 1194, category: ts.DiagnosticCategory.Error, key: "Export declarations are not permitted in a namespace." },
  1255. Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: ts.DiagnosticCategory.Error, key: "Catch clause variable name must be an identifier." },
  1256. Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have a type annotation." },
  1257. Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." },
  1258. An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: ts.DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." },
  1259. Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
  1260. Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
  1261. Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead." },
  1262. Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead." },
  1263. Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'es6' when targeting 'ES5' or lower." },
  1264. Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." },
  1265. Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." },
  1266. Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." },
  1267. Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--isolatedModules' flag is provided." },
  1268. Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." },
  1269. A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" },
  1270. Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" },
  1271. Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
  1272. Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode: { code: 1214, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Modules are automatically in strict mode." },
  1273. Invalid_use_of_0_Modules_are_automatically_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Modules are automatically in strict mode." },
  1274. Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: ts.DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
  1275. Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: ts.DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." },
  1276. Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: ts.DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." },
  1277. Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: ts.DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." },
  1278. An_overload_signature_cannot_be_declared_as_a_generator: { code: 1222, category: ts.DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." },
  1279. _0_tag_already_specified: { code: 1223, category: ts.DiagnosticCategory.Error, key: "'{0}' tag already specified." },
  1280. Signature_0_must_have_a_type_predicate: { code: 1224, category: ts.DiagnosticCategory.Error, key: "Signature '{0}' must have a type predicate." },
  1281. Cannot_find_parameter_0: { code: 1225, category: ts.DiagnosticCategory.Error, key: "Cannot find parameter '{0}'." },
  1282. Type_predicate_0_is_not_assignable_to_1: { code: 1226, category: ts.DiagnosticCategory.Error, key: "Type predicate '{0}' is not assignable to '{1}'." },
  1283. Parameter_0_is_not_in_the_same_position_as_parameter_1: { code: 1227, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' is not in the same position as parameter '{1}'." },
  1284. A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: ts.DiagnosticCategory.Error, key: "A type predicate is only allowed in return type position for functions and methods." },
  1285. A_type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: ts.DiagnosticCategory.Error, key: "A type predicate cannot reference a rest parameter." },
  1286. A_type_predicate_cannot_reference_element_0_in_a_binding_pattern: { code: 1230, category: ts.DiagnosticCategory.Error, key: "A type predicate cannot reference element '{0}' in a binding pattern." },
  1287. An_export_assignment_can_only_be_used_in_a_module: { code: 1231, category: ts.DiagnosticCategory.Error, key: "An export assignment can only be used in a module." },
  1288. An_import_declaration_can_only_be_used_in_a_namespace_or_module: { code: 1232, category: ts.DiagnosticCategory.Error, key: "An import declaration can only be used in a namespace or module." },
  1289. An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." },
  1290. An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." },
  1291. A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." },
  1292. The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." },
  1293. The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." },
  1294. Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." },
  1295. Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." },
  1296. Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." },
  1297. Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." },
  1298. abstract_modifier_can_only_appear_on_a_class_or_method_declaration: { code: 1242, category: ts.DiagnosticCategory.Error, key: "'abstract' modifier can only appear on a class or method declaration." },
  1299. _0_modifier_cannot_be_used_with_1_modifier: { code: 1243, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." },
  1300. Abstract_methods_can_only_appear_within_an_abstract_class: { code: 1244, category: ts.DiagnosticCategory.Error, key: "Abstract methods can only appear within an abstract class." },
  1301. Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: { code: 1245, category: ts.DiagnosticCategory.Error, key: "Method '{0}' cannot have an implementation because it is marked abstract." },
  1302. with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." },
  1303. await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." },
  1304. Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." },
  1305. can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment: { code: 1312, category: ts.DiagnosticCategory.Error, key: "'=' can only be used in an object literal property inside a destructuring assignment." },
  1306. Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
  1307. Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
  1308. Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
  1309. Circular_definition_of_import_alias_0: { code: 2303, category: ts.DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." },
  1310. Cannot_find_name_0: { code: 2304, category: ts.DiagnosticCategory.Error, key: "Cannot find name '{0}'." },
  1311. Module_0_has_no_exported_member_1: { code: 2305, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
  1312. File_0_is_not_a_module: { code: 2306, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not a module." },
  1313. Cannot_find_module_0: { code: 2307, category: ts.DiagnosticCategory.Error, key: "Cannot find module '{0}'." },
  1314. An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2309, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." },
  1315. Type_0_recursively_references_itself_as_a_base_type: { code: 2310, category: ts.DiagnosticCategory.Error, key: "Type '{0}' recursively references itself as a base type." },
  1316. A_class_may_only_extend_another_class: { code: 2311, category: ts.DiagnosticCategory.Error, key: "A class may only extend another class." },
  1317. An_interface_may_only_extend_a_class_or_another_interface: { code: 2312, category: ts.DiagnosticCategory.Error, key: "An interface may only extend a class or another interface." },
  1318. Constraint_of_a_type_parameter_cannot_reference_any_type_parameter_from_the_same_type_parameter_list: { code: 2313, category: ts.DiagnosticCategory.Error, key: "Constraint of a type parameter cannot reference any type parameter from the same type parameter list." },
  1319. Generic_type_0_requires_1_type_argument_s: { code: 2314, category: ts.DiagnosticCategory.Error, key: "Generic type '{0}' requires {1} type argument(s)." },
  1320. Type_0_is_not_generic: { code: 2315, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not generic." },
  1321. Global_type_0_must_be_a_class_or_interface_type: { code: 2316, category: ts.DiagnosticCategory.Error, key: "Global type '{0}' must be a class or interface type." },
  1322. Global_type_0_must_have_1_type_parameter_s: { code: 2317, category: ts.DiagnosticCategory.Error, key: "Global type '{0}' must have {1} type parameter(s)." },
  1323. Cannot_find_global_type_0: { code: 2318, category: ts.DiagnosticCategory.Error, key: "Cannot find global type '{0}'." },
  1324. Named_property_0_of_types_1_and_2_are_not_identical: { code: 2319, category: ts.DiagnosticCategory.Error, key: "Named property '{0}' of types '{1}' and '{2}' are not identical." },
  1325. Interface_0_cannot_simultaneously_extend_types_1_and_2: { code: 2320, category: ts.DiagnosticCategory.Error, key: "Interface '{0}' cannot simultaneously extend types '{1}' and '{2}'." },
  1326. Excessive_stack_depth_comparing_types_0_and_1: { code: 2321, category: ts.DiagnosticCategory.Error, key: "Excessive stack depth comparing types '{0}' and '{1}'." },
  1327. Type_0_is_not_assignable_to_type_1: { code: 2322, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}'." },
  1328. Property_0_is_missing_in_type_1: { code: 2324, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is missing in type '{1}'." },
  1329. Property_0_is_private_in_type_1_but_not_in_type_2: { code: 2325, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is private in type '{1}' but not in type '{2}'." },
  1330. Types_of_property_0_are_incompatible: { code: 2326, category: ts.DiagnosticCategory.Error, key: "Types of property '{0}' are incompatible." },
  1331. Property_0_is_optional_in_type_1_but_required_in_type_2: { code: 2327, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is optional in type '{1}' but required in type '{2}'." },
  1332. Types_of_parameters_0_and_1_are_incompatible: { code: 2328, category: ts.DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible." },
  1333. Index_signature_is_missing_in_type_0: { code: 2329, category: ts.DiagnosticCategory.Error, key: "Index signature is missing in type '{0}'." },
  1334. Index_signatures_are_incompatible: { code: 2330, category: ts.DiagnosticCategory.Error, key: "Index signatures are incompatible." },
  1335. this_cannot_be_referenced_in_a_module_or_namespace_body: { code: 2331, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in a module or namespace body." },
  1336. this_cannot_be_referenced_in_current_location: { code: 2332, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in current location." },
  1337. this_cannot_be_referenced_in_constructor_arguments: { code: 2333, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in constructor arguments." },
  1338. this_cannot_be_referenced_in_a_static_property_initializer: { code: 2334, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in a static property initializer." },
  1339. super_can_only_be_referenced_in_a_derived_class: { code: 2335, category: ts.DiagnosticCategory.Error, key: "'super' can only be referenced in a derived class." },
  1340. super_cannot_be_referenced_in_constructor_arguments: { code: 2336, category: ts.DiagnosticCategory.Error, key: "'super' cannot be referenced in constructor arguments." },
  1341. Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors: { code: 2337, category: ts.DiagnosticCategory.Error, key: "Super calls are not permitted outside constructors or in nested functions inside constructors." },
  1342. super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class: { code: 2338, category: ts.DiagnosticCategory.Error, key: "'super' property access is permitted only in a constructor, member function, or member accessor of a derived class." },
  1343. Property_0_does_not_exist_on_type_1: { code: 2339, category: ts.DiagnosticCategory.Error, key: "Property '{0}' does not exist on type '{1}'." },
  1344. Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword: { code: 2340, category: ts.DiagnosticCategory.Error, key: "Only public and protected methods of the base class are accessible via the 'super' keyword." },
  1345. Property_0_is_private_and_only_accessible_within_class_1: { code: 2341, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is private and only accessible within class '{1}'." },
  1346. An_index_expression_argument_must_be_of_type_string_number_symbol_or_any: { code: 2342, category: ts.DiagnosticCategory.Error, key: "An index expression argument must be of type 'string', 'number', 'symbol', or 'any'." },
  1347. Type_0_does_not_satisfy_the_constraint_1: { code: 2344, category: ts.DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}'." },
  1348. Argument_of_type_0_is_not_assignable_to_parameter_of_type_1: { code: 2345, category: ts.DiagnosticCategory.Error, key: "Argument of type '{0}' is not assignable to parameter of type '{1}'." },
  1349. Supplied_parameters_do_not_match_any_signature_of_call_target: { code: 2346, category: ts.DiagnosticCategory.Error, key: "Supplied parameters do not match any signature of call target." },
  1350. Untyped_function_calls_may_not_accept_type_arguments: { code: 2347, category: ts.DiagnosticCategory.Error, key: "Untyped function calls may not accept type arguments." },
  1351. Value_of_type_0_is_not_callable_Did_you_mean_to_include_new: { code: 2348, category: ts.DiagnosticCategory.Error, key: "Value of type '{0}' is not callable. Did you mean to include 'new'?" },
  1352. Cannot_invoke_an_expression_whose_type_lacks_a_call_signature: { code: 2349, category: ts.DiagnosticCategory.Error, key: "Cannot invoke an expression whose type lacks a call signature." },
  1353. Only_a_void_function_can_be_called_with_the_new_keyword: { code: 2350, category: ts.DiagnosticCategory.Error, key: "Only a void function can be called with the 'new' keyword." },
  1354. Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature: { code: 2351, category: ts.DiagnosticCategory.Error, key: "Cannot use 'new' with an expression whose type lacks a call or construct signature." },
  1355. Neither_type_0_nor_type_1_is_assignable_to_the_other: { code: 2352, category: ts.DiagnosticCategory.Error, key: "Neither type '{0}' nor type '{1}' is assignable to the other." },
  1356. Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1: { code: 2353, category: ts.DiagnosticCategory.Error, key: "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'." },
  1357. No_best_common_type_exists_among_return_expressions: { code: 2354, category: ts.DiagnosticCategory.Error, key: "No best common type exists among return expressions." },
  1358. A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2355, category: ts.DiagnosticCategory.Error, key: "A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement." },
  1359. An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type: { code: 2356, category: ts.DiagnosticCategory.Error, key: "An arithmetic operand must be of type 'any', 'number' or an enum type." },
  1360. The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer: { code: 2357, category: ts.DiagnosticCategory.Error, key: "The operand of an increment or decrement operator must be a variable, property or indexer." },
  1361. The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2358, category: ts.DiagnosticCategory.Error, key: "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter." },
  1362. The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: { code: 2359, category: ts.DiagnosticCategory.Error, key: "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type." },
  1363. The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: { code: 2360, category: ts.DiagnosticCategory.Error, key: "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'." },
  1364. The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2361, category: ts.DiagnosticCategory.Error, key: "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter" },
  1365. The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2362, category: ts.DiagnosticCategory.Error, key: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
  1366. The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: ts.DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
  1367. Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
  1368. Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: ts.DiagnosticCategory.Error, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." },
  1369. Type_parameter_name_cannot_be_0: { code: 2368, category: ts.DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" },
  1370. A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: ts.DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
  1371. A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: ts.DiagnosticCategory.Error, key: "A rest parameter must be of an array type." },
  1372. A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation: { code: 2371, category: ts.DiagnosticCategory.Error, key: "A parameter initializer is only allowed in a function or constructor implementation." },
  1373. Parameter_0_cannot_be_referenced_in_its_initializer: { code: 2372, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' cannot be referenced in its initializer." },
  1374. Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it: { code: 2373, category: ts.DiagnosticCategory.Error, key: "Initializer of parameter '{0}' cannot reference identifier '{1}' declared after it." },
  1375. Duplicate_string_index_signature: { code: 2374, category: ts.DiagnosticCategory.Error, key: "Duplicate string index signature." },
  1376. Duplicate_number_index_signature: { code: 2375, category: ts.DiagnosticCategory.Error, key: "Duplicate number index signature." },
  1377. A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties: { code: 2376, category: ts.DiagnosticCategory.Error, key: "A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties." },
  1378. Constructors_for_derived_classes_must_contain_a_super_call: { code: 2377, category: ts.DiagnosticCategory.Error, key: "Constructors for derived classes must contain a 'super' call." },
  1379. A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2378, category: ts.DiagnosticCategory.Error, key: "A 'get' accessor must return a value or consist of a single 'throw' statement." },
  1380. Getter_and_setter_accessors_do_not_agree_in_visibility: { code: 2379, category: ts.DiagnosticCategory.Error, key: "Getter and setter accessors do not agree in visibility." },
  1381. get_and_set_accessor_must_have_the_same_type: { code: 2380, category: ts.DiagnosticCategory.Error, key: "'get' and 'set' accessor must have the same type." },
  1382. A_signature_with_an_implementation_cannot_use_a_string_literal_type: { code: 2381, category: ts.DiagnosticCategory.Error, key: "A signature with an implementation cannot use a string literal type." },
  1383. Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: { code: 2382, category: ts.DiagnosticCategory.Error, key: "Specialized overload signature is not assignable to any non-specialized signature." },
  1384. Overload_signatures_must_all_be_exported_or_not_exported: { code: 2383, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be exported or not exported." },
  1385. Overload_signatures_must_all_be_ambient_or_non_ambient: { code: 2384, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be ambient or non-ambient." },
  1386. Overload_signatures_must_all_be_public_private_or_protected: { code: 2385, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be public, private or protected." },
  1387. Overload_signatures_must_all_be_optional_or_required: { code: 2386, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be optional or required." },
  1388. Function_overload_must_be_static: { code: 2387, category: ts.DiagnosticCategory.Error, key: "Function overload must be static." },
  1389. Function_overload_must_not_be_static: { code: 2388, category: ts.DiagnosticCategory.Error, key: "Function overload must not be static." },
  1390. Function_implementation_name_must_be_0: { code: 2389, category: ts.DiagnosticCategory.Error, key: "Function implementation name must be '{0}'." },
  1391. Constructor_implementation_is_missing: { code: 2390, category: ts.DiagnosticCategory.Error, key: "Constructor implementation is missing." },
  1392. Function_implementation_is_missing_or_not_immediately_following_the_declaration: { code: 2391, category: ts.DiagnosticCategory.Error, key: "Function implementation is missing or not immediately following the declaration." },
  1393. Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: ts.DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },
  1394. Duplicate_function_implementation: { code: 2393, category: ts.DiagnosticCategory.Error, key: "Duplicate function implementation." },
  1395. Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: ts.DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
  1396. Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: ts.DiagnosticCategory.Error, key: "Individual declarations in merged declaration '{0}' must be all exported or all local." },
  1397. Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." },
  1398. Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." },
  1399. Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." },
  1400. Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference: { code: 2401, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference." },
  1401. Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference: { code: 2402, category: ts.DiagnosticCategory.Error, key: "Expression resolves to '_super' that compiler uses to capture base class reference." },
  1402. Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: { code: 2403, category: ts.DiagnosticCategory.Error, key: "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'." },
  1403. The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation: { code: 2404, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot use a type annotation." },
  1404. The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any: { code: 2405, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement must be of type 'string' or 'any'." },
  1405. Invalid_left_hand_side_in_for_in_statement: { code: 2406, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...in' statement." },
  1406. The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2407, category: ts.DiagnosticCategory.Error, key: "The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter." },
  1407. Setters_cannot_return_a_value: { code: 2408, category: ts.DiagnosticCategory.Error, key: "Setters cannot return a value." },
  1408. Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class: { code: 2409, category: ts.DiagnosticCategory.Error, key: "Return type of constructor signature must be assignable to the instance type of the class" },
  1409. All_symbols_within_a_with_block_will_be_resolved_to_any: { code: 2410, category: ts.DiagnosticCategory.Error, key: "All symbols within a 'with' block will be resolved to 'any'." },
  1410. Property_0_of_type_1_is_not_assignable_to_string_index_type_2: { code: 2411, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to string index type '{2}'." },
  1411. Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2: { code: 2412, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to numeric index type '{2}'." },
  1412. Numeric_index_type_0_is_not_assignable_to_string_index_type_1: { code: 2413, category: ts.DiagnosticCategory.Error, key: "Numeric index type '{0}' is not assignable to string index type '{1}'." },
  1413. Class_name_cannot_be_0: { code: 2414, category: ts.DiagnosticCategory.Error, key: "Class name cannot be '{0}'" },
  1414. Class_0_incorrectly_extends_base_class_1: { code: 2415, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly extends base class '{1}'." },
  1415. Class_static_side_0_incorrectly_extends_base_class_static_side_1: { code: 2417, category: ts.DiagnosticCategory.Error, key: "Class static side '{0}' incorrectly extends base class static side '{1}'." },
  1416. Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0: { code: 2419, category: ts.DiagnosticCategory.Error, key: "Type name '{0}' in extends clause does not reference constructor function for '{0}'." },
  1417. Class_0_incorrectly_implements_interface_1: { code: 2420, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly implements interface '{1}'." },
  1418. A_class_may_only_implement_another_class_or_interface: { code: 2422, category: ts.DiagnosticCategory.Error, key: "A class may only implement another class or interface." },
  1419. Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor: { code: 2423, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member accessor." },
  1420. Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property: { code: 2424, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member property." },
  1421. Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function: { code: 2425, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member property '{1}', but extended class '{2}' defines it as instance member function." },
  1422. Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function: { code: 2426, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member accessor '{1}', but extended class '{2}' defines it as instance member function." },
  1423. Interface_name_cannot_be_0: { code: 2427, category: ts.DiagnosticCategory.Error, key: "Interface name cannot be '{0}'" },
  1424. All_declarations_of_an_interface_must_have_identical_type_parameters: { code: 2428, category: ts.DiagnosticCategory.Error, key: "All declarations of an interface must have identical type parameters." },
  1425. Interface_0_incorrectly_extends_interface_1: { code: 2430, category: ts.DiagnosticCategory.Error, key: "Interface '{0}' incorrectly extends interface '{1}'." },
  1426. Enum_name_cannot_be_0: { code: 2431, category: ts.DiagnosticCategory.Error, key: "Enum name cannot be '{0}'" },
  1427. In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element: { code: 2432, category: ts.DiagnosticCategory.Error, key: "In an enum with multiple declarations, only one declaration can omit an initializer for its first enum element." },
  1428. A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged: { code: 2433, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be in a different file from a class or function with which it is merged" },
  1429. A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: { code: 2434, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be located prior to a class or function with which it is merged" },
  1430. Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules or namespaces." },
  1431. Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." },
  1432. Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: 2437, category: ts.DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" },
  1433. Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" },
  1434. Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name: { code: 2439, category: ts.DiagnosticCategory.Error, key: "Import or export declaration in an ambient module declaration cannot reference module through relative module name." },
  1435. Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: ts.DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
  1436. Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module: { code: 2441, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of a module." },
  1437. Types_have_separate_declarations_of_a_private_property_0: { code: 2442, category: ts.DiagnosticCategory.Error, key: "Types have separate declarations of a private property '{0}'." },
  1438. Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2: { code: 2443, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected but type '{1}' is not a class derived from '{2}'." },
  1439. Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." },
  1440. Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." },
  1441. Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." },
  1442. The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." },
  1443. Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: ts.DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." },
  1444. The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: ts.DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant." },
  1445. Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: ts.DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant." },
  1446. Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'." },
  1447. An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: ts.DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
  1448. The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly: { code: 2453, category: ts.DiagnosticCategory.Error, key: "The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly." },
  1449. Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0: { code: 2455, category: ts.DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'." },
  1450. Type_alias_0_circularly_references_itself: { code: 2456, category: ts.DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
  1451. Type_alias_name_cannot_be_0: { code: 2457, category: ts.DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
  1452. An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: ts.DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
  1453. Type_0_has_no_property_1_and_no_string_index_signature: { code: 2459, category: ts.DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}' and no string index signature." },
  1454. Type_0_has_no_property_1: { code: 2460, category: ts.DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
  1455. Type_0_is_not_an_array_type: { code: 2461, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
  1456. A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: ts.DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" },
  1457. A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: ts.DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." },
  1458. A_computed_property_name_must_be_of_type_string_number_symbol_or_any: { code: 2464, category: ts.DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', 'symbol', or 'any'." },
  1459. this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." },
  1460. super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: ts.DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." },
  1461. A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2467, category: ts.DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." },
  1462. Cannot_find_global_value_0: { code: 2468, category: ts.DiagnosticCategory.Error, key: "Cannot find global value '{0}'." },
  1463. The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." },
  1464. Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: ts.DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." },
  1465. A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: ts.DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." },
  1466. Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." },
  1467. Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: ts.DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
  1468. In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: ts.DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." },
  1469. const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: ts.DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." },
  1470. A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 2476, category: ts.DiagnosticCategory.Error, key: "A const enum member can only be accessed using a string literal." },
  1471. const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 2477, category: ts.DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." },
  1472. const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 2478, category: ts.DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." },
  1473. Property_0_does_not_exist_on_const_enum_1: { code: 2479, category: ts.DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'." },
  1474. let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 2480, category: ts.DiagnosticCategory.Error, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." },
  1475. Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: { code: 2481, category: ts.DiagnosticCategory.Error, key: "Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'." },
  1476. The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." },
  1477. Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: ts.DiagnosticCategory.Error, key: "Export declaration conflicts with exported declaration of '{0}'" },
  1478. The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." },
  1479. The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." },
  1480. Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...of' statement." },
  1481. Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: ts.DiagnosticCategory.Error, key: "Type must have a '[Symbol.iterator]()' method that returns an iterator." },
  1482. An_iterator_must_have_a_next_method: { code: 2489, category: ts.DiagnosticCategory.Error, key: "An iterator must have a 'next()' method." },
  1483. The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: ts.DiagnosticCategory.Error, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." },
  1484. The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." },
  1485. Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" },
  1486. Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: ts.DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." },
  1487. Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: ts.DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." },
  1488. Type_0_is_not_an_array_type_or_a_string_type: { code: 2495, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." },
  1489. The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression: { code: 2496, category: ts.DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression." },
  1490. Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: { code: 2497, category: ts.DiagnosticCategory.Error, key: "Module '{0}' resolves to a non-module entity and cannot be imported using this construct." },
  1491. Module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2498, category: ts.DiagnosticCategory.Error, key: "Module '{0}' uses 'export =' and cannot be used with 'export *'." },
  1492. An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: ts.DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." },
  1493. A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: ts.DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
  1494. A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
  1495. _0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." },
  1496. Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
  1497. No_best_common_type_exists_among_yield_expressions: { code: 2504, category: ts.DiagnosticCategory.Error, key: "No best common type exists among yield expressions." },
  1498. A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: ts.DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." },
  1499. _0_is_referenced_directly_or_indirectly_in_its_own_base_expression: { code: 2506, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own base expression." },
  1500. Type_0_is_not_a_constructor_function_type: { code: 2507, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not a constructor function type." },
  1501. No_base_constructor_has_the_specified_number_of_type_arguments: { code: 2508, category: ts.DiagnosticCategory.Error, key: "No base constructor has the specified number of type arguments." },
  1502. Base_constructor_return_type_0_is_not_a_class_or_interface_type: { code: 2509, category: ts.DiagnosticCategory.Error, key: "Base constructor return type '{0}' is not a class or interface type." },
  1503. Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: ts.DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
  1504. Cannot_create_an_instance_of_the_abstract_class_0: { code: 2511, category: ts.DiagnosticCategory.Error, key: "Cannot create an instance of the abstract class '{0}'." },
  1505. Overload_signatures_must_all_be_abstract_or_not_abstract: { code: 2512, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be abstract or not abstract." },
  1506. Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression: { code: 2513, category: ts.DiagnosticCategory.Error, key: "Abstract method '{0}' in class '{1}' cannot be accessed via super expression." },
  1507. Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: ts.DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." },
  1508. Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: ts.DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." },
  1509. All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: ts.DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." },
  1510. Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." },
  1511. Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
  1512. Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
  1513. The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: ts.DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." },
  1514. yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: ts.DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." },
  1515. await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: ts.DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." },
  1516. Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: ts.DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value." },
  1517. A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface: { code: 2526, category: ts.DiagnosticCategory.Error, key: "A 'this' type is available only in a non-static member of a class or interface." },
  1518. The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary: { code: 2527, category: ts.DiagnosticCategory.Error, key: "The inferred type of '{0}' references an inaccessible 'this' type. A type annotation is necessary." },
  1519. A_module_cannot_have_multiple_default_exports: { code: 2528, category: ts.DiagnosticCategory.Error, key: "A module cannot have multiple default exports." },
  1520. JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: ts.DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." },
  1521. The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: ts.DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." },
  1522. JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." },
  1523. Property_0_in_type_1_is_not_assignable_to_type_2: { code: 2603, category: ts.DiagnosticCategory.Error, key: "Property '{0}' in type '{1}' is not assignable to type '{2}'" },
  1524. JSX_element_type_0_does_not_have_any_construct_or_call_signatures: { code: 2604, category: ts.DiagnosticCategory.Error, key: "JSX element type '{0}' does not have any construct or call signatures." },
  1525. JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements: { code: 2605, category: ts.DiagnosticCategory.Error, key: "JSX element type '{0}' is not a constructor function for JSX elements." },
  1526. Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property: { code: 2606, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of JSX spread attribute is not assignable to target property." },
  1527. JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: ts.DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" },
  1528. The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: ts.DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" },
  1529. Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: ts.DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" },
  1530. A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: ts.DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." },
  1531. Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: ts.DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." },
  1532. Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1: { code: 2653, category: ts.DiagnosticCategory.Error, key: "Non-abstract class expression does not implement inherited abstract member '{0}' from class '{1}'." },
  1533. Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: ts.DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." },
  1534. Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition: { code: 2656, category: ts.DiagnosticCategory.Error, key: "Exported external package typings file '{0}' is not a module. Please contact the package author to update the package definition." },
  1535. Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
  1536. Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
  1537. Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
  1538. Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4006, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
  1539. Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4008, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
  1540. Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4010, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
  1541. Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4012, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." },
  1542. Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4014, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." },
  1543. Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4016, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." },
  1544. Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4019, category: ts.DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
  1545. Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4020, category: ts.DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
  1546. Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 4022, category: ts.DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
  1547. Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4023, category: ts.DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
  1548. Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 4024, category: ts.DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
  1549. Exported_variable_0_has_or_is_using_private_name_1: { code: 4025, category: ts.DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using private name '{1}'." },
  1550. Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4026, category: ts.DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named." },
  1551. Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4027, category: ts.DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
  1552. Public_static_property_0_of_exported_class_has_or_is_using_private_name_1: { code: 4028, category: ts.DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using private name '{1}'." },
  1553. Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4029, category: ts.DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named." },
  1554. Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4030, category: ts.DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
  1555. Public_property_0_of_exported_class_has_or_is_using_private_name_1: { code: 4031, category: ts.DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using private name '{1}'." },
  1556. Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4032, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
  1557. Property_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4033, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of exported interface has or is using private name '{1}'." },
  1558. Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4034, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static property setter from exported class has or is using name '{1}' from private module '{2}'." },
  1559. Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1: { code: 4035, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static property setter from exported class has or is using private name '{1}'." },
  1560. Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4036, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public property setter from exported class has or is using name '{1}' from private module '{2}'." },
  1561. Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1: { code: 4037, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public property setter from exported class has or is using private name '{1}'." },
  1562. Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4038, category: ts.DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using name '{0}' from external module {1} but cannot be named." },
  1563. Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4039, category: ts.DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using name '{0}' from private module '{1}'." },
  1564. Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0: { code: 4040, category: ts.DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using private name '{0}'." },
  1565. Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4041, category: ts.DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using name '{0}' from external module {1} but cannot be named." },
  1566. Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4042, category: ts.DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using name '{0}' from private module '{1}'." },
  1567. Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0: { code: 4043, category: ts.DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using private name '{0}'." },
  1568. Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4044, category: ts.DiagnosticCategory.Error, key: "Return type of constructor signature from exported interface has or is using name '{0}' from private module '{1}'." },
  1569. Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 4045, category: ts.DiagnosticCategory.Error, key: "Return type of constructor signature from exported interface has or is using private name '{0}'." },
  1570. Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4046, category: ts.DiagnosticCategory.Error, key: "Return type of call signature from exported interface has or is using name '{0}' from private module '{1}'." },
  1571. Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 4047, category: ts.DiagnosticCategory.Error, key: "Return type of call signature from exported interface has or is using private name '{0}'." },
  1572. Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4048, category: ts.DiagnosticCategory.Error, key: "Return type of index signature from exported interface has or is using name '{0}' from private module '{1}'." },
  1573. Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 4049, category: ts.DiagnosticCategory.Error, key: "Return type of index signature from exported interface has or is using private name '{0}'." },
  1574. Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4050, category: ts.DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using name '{0}' from external module {1} but cannot be named." },
  1575. Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4051, category: ts.DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using name '{0}' from private module '{1}'." },
  1576. Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0: { code: 4052, category: ts.DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using private name '{0}'." },
  1577. Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4053, category: ts.DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using name '{0}' from external module {1} but cannot be named." },
  1578. Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4054, category: ts.DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using name '{0}' from private module '{1}'." },
  1579. Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0: { code: 4055, category: ts.DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using private name '{0}'." },
  1580. Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4056, category: ts.DiagnosticCategory.Error, key: "Return type of method from exported interface has or is using name '{0}' from private module '{1}'." },
  1581. Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0: { code: 4057, category: ts.DiagnosticCategory.Error, key: "Return type of method from exported interface has or is using private name '{0}'." },
  1582. Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4058, category: ts.DiagnosticCategory.Error, key: "Return type of exported function has or is using name '{0}' from external module {1} but cannot be named." },
  1583. Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1: { code: 4059, category: ts.DiagnosticCategory.Error, key: "Return type of exported function has or is using name '{0}' from private module '{1}'." },
  1584. Return_type_of_exported_function_has_or_is_using_private_name_0: { code: 4060, category: ts.DiagnosticCategory.Error, key: "Return type of exported function has or is using private name '{0}'." },
  1585. Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4061, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using name '{1}' from external module {2} but cannot be named." },
  1586. Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4062, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using name '{1}' from private module '{2}'." },
  1587. Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1: { code: 4063, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using private name '{1}'." },
  1588. Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4064, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
  1589. Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4065, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
  1590. Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4066, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
  1591. Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4067, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
  1592. Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4068, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using name '{1}' from external module {2} but cannot be named." },
  1593. Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4069, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
  1594. Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4070, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
  1595. Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4071, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using name '{1}' from external module {2} but cannot be named." },
  1596. Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4072, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
  1597. Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4073, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using private name '{1}'." },
  1598. Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4074, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
  1599. Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4075, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of method from exported interface has or is using private name '{1}'." },
  1600. Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
  1601. Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
  1602. Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
  1603. Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: ts.DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
  1604. Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4082, category: ts.DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." },
  1605. Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: ts.DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." },
  1606. The_current_host_does_not_support_the_0_option: { code: 5001, category: ts.DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
  1607. Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: ts.DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
  1608. Cannot_read_file_0_Colon_1: { code: 5012, category: ts.DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
  1609. Unsupported_file_encoding: { code: 5013, category: ts.DiagnosticCategory.Error, key: "Unsupported file encoding." },
  1610. Failed_to_parse_file_0_Colon_1: { code: 5014, category: ts.DiagnosticCategory.Error, key: "Failed to parse file '{0}': {1}." },
  1611. Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
  1612. Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
  1613. Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
  1614. Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
  1615. Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." },
  1616. Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: ts.DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." },
  1617. Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." },
  1618. Option_0_cannot_be_specified_with_option_1: { code: 5053, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." },
  1619. A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5054, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." },
  1620. Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
  1621. Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
  1622. Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },
  1623. Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." },
  1624. Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
  1625. Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
  1626. Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." },
  1627. Do_not_emit_outputs_if_any_errors_were_reported: { code: 6008, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any errors were reported." },
  1628. Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
  1629. Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
  1630. Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
  1631. Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'" },
  1632. Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." },
  1633. Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." },
  1634. Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." },
  1635. Syntax_Colon_0: { code: 6023, category: ts.DiagnosticCategory.Message, key: "Syntax: {0}" },
  1636. options: { code: 6024, category: ts.DiagnosticCategory.Message, key: "options" },
  1637. file: { code: 6025, category: ts.DiagnosticCategory.Message, key: "file" },
  1638. Examples_Colon_0: { code: 6026, category: ts.DiagnosticCategory.Message, key: "Examples: {0}" },
  1639. Options_Colon: { code: 6027, category: ts.DiagnosticCategory.Message, key: "Options:" },
  1640. Version_0: { code: 6029, category: ts.DiagnosticCategory.Message, key: "Version {0}" },
  1641. Insert_command_line_options_and_files_from_a_file: { code: 6030, category: ts.DiagnosticCategory.Message, key: "Insert command line options and files from a file." },
  1642. File_change_detected_Starting_incremental_compilation: { code: 6032, category: ts.DiagnosticCategory.Message, key: "File change detected. Starting incremental compilation..." },
  1643. KIND: { code: 6034, category: ts.DiagnosticCategory.Message, key: "KIND" },
  1644. FILE: { code: 6035, category: ts.DiagnosticCategory.Message, key: "FILE" },
  1645. VERSION: { code: 6036, category: ts.DiagnosticCategory.Message, key: "VERSION" },
  1646. LOCATION: { code: 6037, category: ts.DiagnosticCategory.Message, key: "LOCATION" },
  1647. DIRECTORY: { code: 6038, category: ts.DiagnosticCategory.Message, key: "DIRECTORY" },
  1648. Compilation_complete_Watching_for_file_changes: { code: 6042, category: ts.DiagnosticCategory.Message, key: "Compilation complete. Watching for file changes." },
  1649. Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
  1650. Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
  1651. Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
  1652. Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'." },
  1653. Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: ts.DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." },
  1654. Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: ts.DiagnosticCategory.Error, key: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'." },
  1655. Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
  1656. Unable_to_open_file_0: { code: 6050, category: ts.DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
  1657. Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
  1658. Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
  1659. File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
  1660. File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
  1661. Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
  1662. Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
  1663. Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: ts.DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." },
  1664. File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." },
  1665. Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." },
  1666. NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" },
  1667. Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." },
  1668. Argument_for_moduleResolution_option_must_be_node_or_classic: { code: 6063, category: ts.DiagnosticCategory.Error, key: "Argument for '--moduleResolution' option must be 'node' or 'classic'." },
  1669. Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
  1670. Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
  1671. Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
  1672. Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
  1673. Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
  1674. Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." },
  1675. Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." },
  1676. Successfully_created_a_tsconfig_json_file: { code: 6071, category: ts.DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." },
  1677. Suppress_excess_property_checks_for_object_literals: { code: 6072, category: ts.DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." },
  1678. Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
  1679. Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
  1680. Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
  1681. new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type: { code: 7009, category: ts.DiagnosticCategory.Error, key: "'new' expression, whose target lacks a construct signature, implicitly has an 'any' type." },
  1682. _0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type: { code: 7010, category: ts.DiagnosticCategory.Error, key: "'{0}', which lacks return-type annotation, implicitly has an '{1}' return type." },
  1683. Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type: { code: 7011, category: ts.DiagnosticCategory.Error, key: "Function expression, which lacks return-type annotation, implicitly has an '{0}' return type." },
  1684. Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7013, category: ts.DiagnosticCategory.Error, key: "Construct signature, which lacks return-type annotation, implicitly has an 'any' return type." },
  1685. Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation: { code: 7016, category: ts.DiagnosticCategory.Error, key: "Property '{0}' implicitly has type 'any', because its 'set' accessor lacks a type annotation." },
  1686. Index_signature_of_object_type_implicitly_has_an_any_type: { code: 7017, category: ts.DiagnosticCategory.Error, key: "Index signature of object type implicitly has an 'any' type." },
  1687. Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." },
  1688. Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
  1689. Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." },
  1690. _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." },
  1691. _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
  1692. Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
  1693. Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." },
  1694. JSX_element_implicitly_has_type_any_because_no_interface_JSX_0_exists: { code: 7026, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because no interface 'JSX.{0}' exists" },
  1695. You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." },
  1696. You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: ts.DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." },
  1697. import_can_only_be_used_in_a_ts_file: { code: 8002, category: ts.DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." },
  1698. export_can_only_be_used_in_a_ts_file: { code: 8003, category: ts.DiagnosticCategory.Error, key: "'export=' can only be used in a .ts file." },
  1699. type_parameter_declarations_can_only_be_used_in_a_ts_file: { code: 8004, category: ts.DiagnosticCategory.Error, key: "'type parameter declarations' can only be used in a .ts file." },
  1700. implements_clauses_can_only_be_used_in_a_ts_file: { code: 8005, category: ts.DiagnosticCategory.Error, key: "'implements clauses' can only be used in a .ts file." },
  1701. interface_declarations_can_only_be_used_in_a_ts_file: { code: 8006, category: ts.DiagnosticCategory.Error, key: "'interface declarations' can only be used in a .ts file." },
  1702. module_declarations_can_only_be_used_in_a_ts_file: { code: 8007, category: ts.DiagnosticCategory.Error, key: "'module declarations' can only be used in a .ts file." },
  1703. type_aliases_can_only_be_used_in_a_ts_file: { code: 8008, category: ts.DiagnosticCategory.Error, key: "'type aliases' can only be used in a .ts file." },
  1704. _0_can_only_be_used_in_a_ts_file: { code: 8009, category: ts.DiagnosticCategory.Error, key: "'{0}' can only be used in a .ts file." },
  1705. types_can_only_be_used_in_a_ts_file: { code: 8010, category: ts.DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." },
  1706. type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: ts.DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." },
  1707. parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: ts.DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." },
  1708. property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." },
  1709. enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." },
  1710. type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." },
  1711. decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
  1712. Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." },
  1713. class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
  1714. JSX_attributes_must_only_be_assigned_a_non_empty_expression: { code: 17000, category: ts.DiagnosticCategory.Error, key: "JSX attributes must only be assigned a non-empty 'expression'." },
  1715. JSX_elements_cannot_have_multiple_attributes_with_the_same_name: { code: 17001, category: ts.DiagnosticCategory.Error, key: "JSX elements cannot have multiple attributes with the same name." },
  1716. Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: ts.DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." },
  1717. JSX_attribute_expected: { code: 17003, category: ts.DiagnosticCategory.Error, key: "JSX attribute expected." },
  1718. Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: ts.DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." },
  1719. A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" },
  1720. An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17006, category: ts.DiagnosticCategory.Error, key: "An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." },
  1721. A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }
  1722. };
  1723. })(ts || (ts = {}));
  1724. var ts;
  1725. (function (ts) {
  1726. function tokenIsIdentifierOrKeyword(token) {
  1727. return token >= 69;
  1728. }
  1729. ts.tokenIsIdentifierOrKeyword = tokenIsIdentifierOrKeyword;
  1730. var textToToken = {
  1731. "abstract": 115,
  1732. "any": 117,
  1733. "as": 116,
  1734. "boolean": 120,
  1735. "break": 70,
  1736. "case": 71,
  1737. "catch": 72,
  1738. "class": 73,
  1739. "continue": 75,
  1740. "const": 74,
  1741. "constructor": 121,
  1742. "debugger": 76,
  1743. "declare": 122,
  1744. "default": 77,
  1745. "delete": 78,
  1746. "do": 79,
  1747. "else": 80,
  1748. "enum": 81,
  1749. "export": 82,
  1750. "extends": 83,
  1751. "false": 84,
  1752. "finally": 85,
  1753. "for": 86,
  1754. "from": 133,
  1755. "function": 87,
  1756. "get": 123,
  1757. "if": 88,
  1758. "implements": 106,
  1759. "import": 89,
  1760. "in": 90,
  1761. "instanceof": 91,
  1762. "interface": 107,
  1763. "is": 124,
  1764. "let": 108,
  1765. "module": 125,
  1766. "namespace": 126,
  1767. "new": 92,
  1768. "null": 93,
  1769. "number": 128,
  1770. "package": 109,
  1771. "private": 110,
  1772. "protected": 111,
  1773. "public": 112,
  1774. "require": 127,
  1775. "return": 94,
  1776. "set": 129,
  1777. "static": 113,
  1778. "string": 130,
  1779. "super": 95,
  1780. "switch": 96,
  1781. "symbol": 131,
  1782. "this": 97,
  1783. "throw": 98,
  1784. "true": 99,
  1785. "try": 100,
  1786. "type": 132,
  1787. "typeof": 101,
  1788. "var": 102,
  1789. "void": 103,
  1790. "while": 104,
  1791. "with": 105,
  1792. "yield": 114,
  1793. "async": 118,
  1794. "await": 119,
  1795. "of": 134,
  1796. "{": 15,
  1797. "}": 16,
  1798. "(": 17,
  1799. ")": 18,
  1800. "[": 19,
  1801. "]": 20,
  1802. ".": 21,
  1803. "...": 22,
  1804. ";": 23,
  1805. ",": 24,
  1806. "<": 25,
  1807. ">": 27,
  1808. "<=": 28,
  1809. ">=": 29,
  1810. "==": 30,
  1811. "!=": 31,
  1812. "===": 32,
  1813. "!==": 33,
  1814. "=>": 34,
  1815. "+": 35,
  1816. "-": 36,
  1817. "**": 38,
  1818. "*": 37,
  1819. "/": 39,
  1820. "%": 40,
  1821. "++": 41,
  1822. "--": 42,
  1823. "<<": 43,
  1824. "</": 26,
  1825. ">>": 44,
  1826. ">>>": 45,
  1827. "&": 46,
  1828. "|": 47,
  1829. "^": 48,
  1830. "!": 49,
  1831. "~": 50,
  1832. "&&": 51,
  1833. "||": 52,
  1834. "?": 53,
  1835. ":": 54,
  1836. "=": 56,
  1837. "+=": 57,
  1838. "-=": 58,
  1839. "*=": 59,
  1840. "**=": 60,
  1841. "/=": 61,
  1842. "%=": 62,
  1843. "<<=": 63,
  1844. ">>=": 64,
  1845. ">>>=": 65,
  1846. "&=": 66,
  1847. "|=": 67,
  1848. "^=": 68,
  1849. "@": 55
  1850. };
  1851. var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
  1852. var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
  1853. var unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
  1854. var unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
  1855. function lookupInUnicodeMap(code, map) {
  1856. if (code < map[0]) {
  1857. return false;
  1858. }
  1859. var lo = 0;
  1860. var hi = map.length;
  1861. var mid;
  1862. while (lo + 1 < hi) {
  1863. mid = lo + (hi - lo) / 2;
  1864. mid -= mid % 2;
  1865. if (map[mid] <= code && code <= map[mid + 1]) {
  1866. return true;
  1867. }
  1868. if (code < map[mid]) {
  1869. hi = mid;
  1870. }
  1871. else {
  1872. lo = mid + 2;
  1873. }
  1874. }
  1875. return false;
  1876. }
  1877. function isUnicodeIdentifierStart(code, languageVersion) {
  1878. return languageVersion >= 1 ?
  1879. lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
  1880. lookupInUnicodeMap(code, unicodeES3IdentifierStart);
  1881. }
  1882. ts.isUnicodeIdentifierStart = isUnicodeIdentifierStart;
  1883. function isUnicodeIdentifierPart(code, languageVersion) {
  1884. return languageVersion >= 1 ?
  1885. lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
  1886. lookupInUnicodeMap(code, unicodeES3IdentifierPart);
  1887. }
  1888. function makeReverseMap(source) {
  1889. var result = [];
  1890. for (var name_4 in source) {
  1891. if (source.hasOwnProperty(name_4)) {
  1892. result[source[name_4]] = name_4;
  1893. }
  1894. }
  1895. return result;
  1896. }
  1897. var tokenStrings = makeReverseMap(textToToken);
  1898. function tokenToString(t) {
  1899. return tokenStrings[t];
  1900. }
  1901. ts.tokenToString = tokenToString;
  1902. function stringToToken(s) {
  1903. return textToToken[s];
  1904. }
  1905. ts.stringToToken = stringToToken;
  1906. function computeLineStarts(text) {
  1907. var result = new Array();
  1908. var pos = 0;
  1909. var lineStart = 0;
  1910. while (pos < text.length) {
  1911. var ch = text.charCodeAt(pos++);
  1912. switch (ch) {
  1913. case 13:
  1914. if (text.charCodeAt(pos) === 10) {
  1915. pos++;
  1916. }
  1917. case 10:
  1918. result.push(lineStart);
  1919. lineStart = pos;
  1920. break;
  1921. default:
  1922. if (ch > 127 && isLineBreak(ch)) {
  1923. result.push(lineStart);
  1924. lineStart = pos;
  1925. }
  1926. break;
  1927. }
  1928. }
  1929. result.push(lineStart);
  1930. return result;
  1931. }
  1932. ts.computeLineStarts = computeLineStarts;
  1933. function getPositionOfLineAndCharacter(sourceFile, line, character) {
  1934. return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character);
  1935. }
  1936. ts.getPositionOfLineAndCharacter = getPositionOfLineAndCharacter;
  1937. function computePositionOfLineAndCharacter(lineStarts, line, character) {
  1938. ts.Debug.assert(line >= 0 && line < lineStarts.length);
  1939. return lineStarts[line] + character;
  1940. }
  1941. ts.computePositionOfLineAndCharacter = computePositionOfLineAndCharacter;
  1942. function getLineStarts(sourceFile) {
  1943. return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
  1944. }
  1945. ts.getLineStarts = getLineStarts;
  1946. function computeLineAndCharacterOfPosition(lineStarts, position) {
  1947. var lineNumber = ts.binarySearch(lineStarts, position);
  1948. if (lineNumber < 0) {
  1949. lineNumber = ~lineNumber - 1;
  1950. ts.Debug.assert(lineNumber !== -1, "position cannot precede the beginning of the file");
  1951. }
  1952. return {
  1953. line: lineNumber,
  1954. character: position - lineStarts[lineNumber]
  1955. };
  1956. }
  1957. ts.computeLineAndCharacterOfPosition = computeLineAndCharacterOfPosition;
  1958. function getLineAndCharacterOfPosition(sourceFile, position) {
  1959. return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
  1960. }
  1961. ts.getLineAndCharacterOfPosition = getLineAndCharacterOfPosition;
  1962. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1963. function isWhiteSpace(ch) {
  1964. return ch === 32 ||
  1965. ch === 9 ||
  1966. ch === 11 ||
  1967. ch === 12 ||
  1968. ch === 160 ||
  1969. ch === 133 ||
  1970. ch === 5760 ||
  1971. ch >= 8192 && ch <= 8203 ||
  1972. ch === 8239 ||
  1973. ch === 8287 ||
  1974. ch === 12288 ||
  1975. ch === 65279;
  1976. }
  1977. ts.isWhiteSpace = isWhiteSpace;
  1978. function isLineBreak(ch) {
  1979. return ch === 10 ||
  1980. ch === 13 ||
  1981. ch === 8232 ||
  1982. ch === 8233;
  1983. }
  1984. ts.isLineBreak = isLineBreak;
  1985. function isDigit(ch) {
  1986. return ch >= 48 && ch <= 57;
  1987. }
  1988. function isOctalDigit(ch) {
  1989. return ch >= 48 && ch <= 55;
  1990. }
  1991. ts.isOctalDigit = isOctalDigit;
  1992. function couldStartTrivia(text, pos) {
  1993. var ch = text.charCodeAt(pos);
  1994. switch (ch) {
  1995. case 13:
  1996. case 10:
  1997. case 9:
  1998. case 11:
  1999. case 12:
  2000. case 32:
  2001. case 47:
  2002. case 60:
  2003. case 61:
  2004. case 62:
  2005. return true;
  2006. case 35:
  2007. return pos === 0;
  2008. default:
  2009. return ch > 127;
  2010. }
  2011. }
  2012. ts.couldStartTrivia = couldStartTrivia;
  2013. function skipTrivia(text, pos, stopAfterLineBreak) {
  2014. while (true) {
  2015. var ch = text.charCodeAt(pos);
  2016. switch (ch) {
  2017. case 13:
  2018. if (text.charCodeAt(pos + 1) === 10) {
  2019. pos++;
  2020. }
  2021. case 10:
  2022. pos++;
  2023. if (stopAfterLineBreak) {
  2024. return pos;
  2025. }
  2026. continue;
  2027. case 9:
  2028. case 11:
  2029. case 12:
  2030. case 32:
  2031. pos++;
  2032. continue;
  2033. case 47:
  2034. if (text.charCodeAt(pos + 1) === 47) {
  2035. pos += 2;
  2036. while (pos < text.length) {
  2037. if (isLineBreak(text.charCodeAt(pos))) {
  2038. break;
  2039. }
  2040. pos++;
  2041. }
  2042. continue;
  2043. }
  2044. if (text.charCodeAt(pos + 1) === 42) {
  2045. pos += 2;
  2046. while (pos < text.length) {
  2047. if (text.charCodeAt(pos) === 42 && text.charCodeAt(pos + 1) === 47) {
  2048. pos += 2;
  2049. break;
  2050. }
  2051. pos++;
  2052. }
  2053. continue;
  2054. }
  2055. break;
  2056. case 60:
  2057. case 61:
  2058. case 62:
  2059. if (isConflictMarkerTrivia(text, pos)) {
  2060. pos = scanConflictMarkerTrivia(text, pos);
  2061. continue;
  2062. }
  2063. break;
  2064. case 35:
  2065. if (pos === 0 && isShebangTrivia(text, pos)) {
  2066. pos = scanShebangTrivia(text, pos);
  2067. continue;
  2068. }
  2069. break;
  2070. default:
  2071. if (ch > 127 && (isWhiteSpace(ch) || isLineBreak(ch))) {
  2072. pos++;
  2073. continue;
  2074. }
  2075. break;
  2076. }
  2077. return pos;
  2078. }
  2079. }
  2080. ts.skipTrivia = skipTrivia;
  2081. var mergeConflictMarkerLength = "<<<<<<<".length;
  2082. function isConflictMarkerTrivia(text, pos) {
  2083. ts.Debug.assert(pos >= 0);
  2084. if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) {
  2085. var ch = text.charCodeAt(pos);
  2086. if ((pos + mergeConflictMarkerLength) < text.length) {
  2087. for (var i = 0, n = mergeConflictMarkerLength; i < n; i++) {
  2088. if (text.charCodeAt(pos + i) !== ch) {
  2089. return false;
  2090. }
  2091. }
  2092. return ch === 61 ||
  2093. text.charCodeAt(pos + mergeConflictMarkerLength) === 32;
  2094. }
  2095. }
  2096. return false;
  2097. }
  2098. function scanConflictMarkerTrivia(text, pos, error) {
  2099. if (error) {
  2100. error(ts.Diagnostics.Merge_conflict_marker_encountered, mergeConflictMarkerLength);
  2101. }
  2102. var ch = text.charCodeAt(pos);
  2103. var len = text.length;
  2104. if (ch === 60 || ch === 62) {
  2105. while (pos < len && !isLineBreak(text.charCodeAt(pos))) {
  2106. pos++;
  2107. }
  2108. }
  2109. else {
  2110. ts.Debug.assert(ch === 61);
  2111. while (pos < len) {
  2112. var ch_1 = text.charCodeAt(pos);
  2113. if (ch_1 === 62 && isConflictMarkerTrivia(text, pos)) {
  2114. break;
  2115. }
  2116. pos++;
  2117. }
  2118. }
  2119. return pos;
  2120. }
  2121. var shebangTriviaRegex = /^#!.*/;
  2122. function isShebangTrivia(text, pos) {
  2123. ts.Debug.assert(pos === 0);
  2124. return shebangTriviaRegex.test(text);
  2125. }
  2126. function scanShebangTrivia(text, pos) {
  2127. var shebang = shebangTriviaRegex.exec(text)[0];
  2128. pos = pos + shebang.length;
  2129. return pos;
  2130. }
  2131. function getCommentRanges(text, pos, trailing) {
  2132. var result;
  2133. var collecting = trailing || pos === 0;
  2134. while (true) {
  2135. var ch = text.charCodeAt(pos);
  2136. switch (ch) {
  2137. case 13:
  2138. if (text.charCodeAt(pos + 1) === 10) {
  2139. pos++;
  2140. }
  2141. case 10:
  2142. pos++;
  2143. if (trailing) {
  2144. return result;
  2145. }
  2146. collecting = true;
  2147. if (result && result.length) {
  2148. ts.lastOrUndefined(result).hasTrailingNewLine = true;
  2149. }
  2150. continue;
  2151. case 9:
  2152. case 11:
  2153. case 12:
  2154. case 32:
  2155. pos++;
  2156. continue;
  2157. case 47:
  2158. var nextChar = text.charCodeAt(pos + 1);
  2159. var hasTrailingNewLine = false;
  2160. if (nextChar === 47 || nextChar === 42) {
  2161. var kind = nextChar === 47 ? 2 : 3;
  2162. var startPos = pos;
  2163. pos += 2;
  2164. if (nextChar === 47) {
  2165. while (pos < text.length) {
  2166. if (isLineBreak(text.charCodeAt(pos))) {
  2167. hasTrailingNewLine = true;
  2168. break;
  2169. }
  2170. pos++;
  2171. }
  2172. }
  2173. else {
  2174. while (pos < text.length) {
  2175. if (text.charCodeAt(pos) === 42 && text.charCodeAt(pos + 1) === 47) {
  2176. pos += 2;
  2177. break;
  2178. }
  2179. pos++;
  2180. }
  2181. }
  2182. if (collecting) {
  2183. if (!result) {
  2184. result = [];
  2185. }
  2186. result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine, kind: kind });
  2187. }
  2188. continue;
  2189. }
  2190. break;
  2191. default:
  2192. if (ch > 127 && (isWhiteSpace(ch) || isLineBreak(ch))) {
  2193. if (result && result.length && isLineBreak(ch)) {
  2194. ts.lastOrUndefined(result).hasTrailingNewLine = true;
  2195. }
  2196. pos++;
  2197. continue;
  2198. }
  2199. break;
  2200. }
  2201. return result;
  2202. }
  2203. }
  2204. function getLeadingCommentRanges(text, pos) {
  2205. return getCommentRanges(text, pos, false);
  2206. }
  2207. ts.getLeadingCommentRanges = getLeadingCommentRanges;
  2208. function getTrailingCommentRanges(text, pos) {
  2209. return getCommentRanges(text, pos, true);
  2210. }
  2211. ts.getTrailingCommentRanges = getTrailingCommentRanges;
  2212. function getShebang(text) {
  2213. return shebangTriviaRegex.test(text)
  2214. ? shebangTriviaRegex.exec(text)[0]
  2215. : undefined;
  2216. }
  2217. ts.getShebang = getShebang;
  2218. function isIdentifierStart(ch, languageVersion) {
  2219. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2220. ch === 36 || ch === 95 ||
  2221. ch > 127 && isUnicodeIdentifierStart(ch, languageVersion);
  2222. }
  2223. ts.isIdentifierStart = isIdentifierStart;
  2224. function isIdentifierPart(ch, languageVersion) {
  2225. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2226. ch >= 48 && ch <= 57 || ch === 36 || ch === 95 ||
  2227. ch > 127 && isUnicodeIdentifierPart(ch, languageVersion);
  2228. }
  2229. ts.isIdentifierPart = isIdentifierPart;
  2230. function createScanner(languageVersion, skipTrivia, languageVariant, text, onError, start, length) {
  2231. if (languageVariant === void 0) { languageVariant = 0; }
  2232. var pos;
  2233. var end;
  2234. var startPos;
  2235. var tokenPos;
  2236. var token;
  2237. var tokenValue;
  2238. var precedingLineBreak;
  2239. var hasExtendedUnicodeEscape;
  2240. var tokenIsUnterminated;
  2241. setText(text, start, length);
  2242. return {
  2243. getStartPos: function () { return startPos; },
  2244. getTextPos: function () { return pos; },
  2245. getToken: function () { return token; },
  2246. getTokenPos: function () { return tokenPos; },
  2247. getTokenText: function () { return text.substring(tokenPos, pos); },
  2248. getTokenValue: function () { return tokenValue; },
  2249. hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; },
  2250. hasPrecedingLineBreak: function () { return precedingLineBreak; },
  2251. isIdentifier: function () { return token === 69 || token > 105; },
  2252. isReservedWord: function () { return token >= 70 && token <= 105; },
  2253. isUnterminated: function () { return tokenIsUnterminated; },
  2254. reScanGreaterToken: reScanGreaterToken,
  2255. reScanSlashToken: reScanSlashToken,
  2256. reScanTemplateToken: reScanTemplateToken,
  2257. scanJsxIdentifier: scanJsxIdentifier,
  2258. reScanJsxToken: reScanJsxToken,
  2259. scanJsxToken: scanJsxToken,
  2260. scan: scan,
  2261. setText: setText,
  2262. setScriptTarget: setScriptTarget,
  2263. setLanguageVariant: setLanguageVariant,
  2264. setOnError: setOnError,
  2265. setTextPos: setTextPos,
  2266. tryScan: tryScan,
  2267. lookAhead: lookAhead
  2268. };
  2269. function error(message, length) {
  2270. if (onError) {
  2271. onError(message, length || 0);
  2272. }
  2273. }
  2274. function scanNumber() {
  2275. var start = pos;
  2276. while (isDigit(text.charCodeAt(pos)))
  2277. pos++;
  2278. if (text.charCodeAt(pos) === 46) {
  2279. pos++;
  2280. while (isDigit(text.charCodeAt(pos)))
  2281. pos++;
  2282. }
  2283. var end = pos;
  2284. if (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101) {
  2285. pos++;
  2286. if (text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45)
  2287. pos++;
  2288. if (isDigit(text.charCodeAt(pos))) {
  2289. pos++;
  2290. while (isDigit(text.charCodeAt(pos)))
  2291. pos++;
  2292. end = pos;
  2293. }
  2294. else {
  2295. error(ts.Diagnostics.Digit_expected);
  2296. }
  2297. }
  2298. return +(text.substring(start, end));
  2299. }
  2300. function scanOctalDigits() {
  2301. var start = pos;
  2302. while (isOctalDigit(text.charCodeAt(pos))) {
  2303. pos++;
  2304. }
  2305. return +(text.substring(start, pos));
  2306. }
  2307. function scanExactNumberOfHexDigits(count) {
  2308. return scanHexDigits(count, false);
  2309. }
  2310. function scanMinimumNumberOfHexDigits(count) {
  2311. return scanHexDigits(count, true);
  2312. }
  2313. function scanHexDigits(minCount, scanAsManyAsPossible) {
  2314. var digits = 0;
  2315. var value = 0;
  2316. while (digits < minCount || scanAsManyAsPossible) {
  2317. var ch = text.charCodeAt(pos);
  2318. if (ch >= 48 && ch <= 57) {
  2319. value = value * 16 + ch - 48;
  2320. }
  2321. else if (ch >= 65 && ch <= 70) {
  2322. value = value * 16 + ch - 65 + 10;
  2323. }
  2324. else if (ch >= 97 && ch <= 102) {
  2325. value = value * 16 + ch - 97 + 10;
  2326. }
  2327. else {
  2328. break;
  2329. }
  2330. pos++;
  2331. digits++;
  2332. }
  2333. if (digits < minCount) {
  2334. value = -1;
  2335. }
  2336. return value;
  2337. }
  2338. function scanString() {
  2339. var quote = text.charCodeAt(pos++);
  2340. var result = "";
  2341. var start = pos;
  2342. while (true) {
  2343. if (pos >= end) {
  2344. result += text.substring(start, pos);
  2345. tokenIsUnterminated = true;
  2346. error(ts.Diagnostics.Unterminated_string_literal);
  2347. break;
  2348. }
  2349. var ch = text.charCodeAt(pos);
  2350. if (ch === quote) {
  2351. result += text.substring(start, pos);
  2352. pos++;
  2353. break;
  2354. }
  2355. if (ch === 92) {
  2356. result += text.substring(start, pos);
  2357. result += scanEscapeSequence();
  2358. start = pos;
  2359. continue;
  2360. }
  2361. if (isLineBreak(ch)) {
  2362. result += text.substring(start, pos);
  2363. tokenIsUnterminated = true;
  2364. error(ts.Diagnostics.Unterminated_string_literal);
  2365. break;
  2366. }
  2367. pos++;
  2368. }
  2369. return result;
  2370. }
  2371. function scanTemplateAndSetTokenValue() {
  2372. var startedWithBacktick = text.charCodeAt(pos) === 96;
  2373. pos++;
  2374. var start = pos;
  2375. var contents = "";
  2376. var resultingToken;
  2377. while (true) {
  2378. if (pos >= end) {
  2379. contents += text.substring(start, pos);
  2380. tokenIsUnterminated = true;
  2381. error(ts.Diagnostics.Unterminated_template_literal);
  2382. resultingToken = startedWithBacktick ? 11 : 14;
  2383. break;
  2384. }
  2385. var currChar = text.charCodeAt(pos);
  2386. if (currChar === 96) {
  2387. contents += text.substring(start, pos);
  2388. pos++;
  2389. resultingToken = startedWithBacktick ? 11 : 14;
  2390. break;
  2391. }
  2392. if (currChar === 36 && pos + 1 < end && text.charCodeAt(pos + 1) === 123) {
  2393. contents += text.substring(start, pos);
  2394. pos += 2;
  2395. resultingToken = startedWithBacktick ? 12 : 13;
  2396. break;
  2397. }
  2398. if (currChar === 92) {
  2399. contents += text.substring(start, pos);
  2400. contents += scanEscapeSequence();
  2401. start = pos;
  2402. continue;
  2403. }
  2404. if (currChar === 13) {
  2405. contents += text.substring(start, pos);
  2406. pos++;
  2407. if (pos < end && text.charCodeAt(pos) === 10) {
  2408. pos++;
  2409. }
  2410. contents += "\n";
  2411. start = pos;
  2412. continue;
  2413. }
  2414. pos++;
  2415. }
  2416. ts.Debug.assert(resultingToken !== undefined);
  2417. tokenValue = contents;
  2418. return resultingToken;
  2419. }
  2420. function scanEscapeSequence() {
  2421. pos++;
  2422. if (pos >= end) {
  2423. error(ts.Diagnostics.Unexpected_end_of_text);
  2424. return "";
  2425. }
  2426. var ch = text.charCodeAt(pos++);
  2427. switch (ch) {
  2428. case 48:
  2429. return "\0";
  2430. case 98:
  2431. return "\b";
  2432. case 116:
  2433. return "\t";
  2434. case 110:
  2435. return "\n";
  2436. case 118:
  2437. return "\v";
  2438. case 102:
  2439. return "\f";
  2440. case 114:
  2441. return "\r";
  2442. case 39:
  2443. return "\'";
  2444. case 34:
  2445. return "\"";
  2446. case 117:
  2447. if (pos < end && text.charCodeAt(pos) === 123) {
  2448. hasExtendedUnicodeEscape = true;
  2449. pos++;
  2450. return scanExtendedUnicodeEscape();
  2451. }
  2452. return scanHexadecimalEscape(4);
  2453. case 120:
  2454. return scanHexadecimalEscape(2);
  2455. case 13:
  2456. if (pos < end && text.charCodeAt(pos) === 10) {
  2457. pos++;
  2458. }
  2459. case 10:
  2460. case 8232:
  2461. case 8233:
  2462. return "";
  2463. default:
  2464. return String.fromCharCode(ch);
  2465. }
  2466. }
  2467. function scanHexadecimalEscape(numDigits) {
  2468. var escapedValue = scanExactNumberOfHexDigits(numDigits);
  2469. if (escapedValue >= 0) {
  2470. return String.fromCharCode(escapedValue);
  2471. }
  2472. else {
  2473. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2474. return "";
  2475. }
  2476. }
  2477. function scanExtendedUnicodeEscape() {
  2478. var escapedValue = scanMinimumNumberOfHexDigits(1);
  2479. var isInvalidExtendedEscape = false;
  2480. if (escapedValue < 0) {
  2481. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2482. isInvalidExtendedEscape = true;
  2483. }
  2484. else if (escapedValue > 0x10FFFF) {
  2485. error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive);
  2486. isInvalidExtendedEscape = true;
  2487. }
  2488. if (pos >= end) {
  2489. error(ts.Diagnostics.Unexpected_end_of_text);
  2490. isInvalidExtendedEscape = true;
  2491. }
  2492. else if (text.charCodeAt(pos) === 125) {
  2493. pos++;
  2494. }
  2495. else {
  2496. error(ts.Diagnostics.Unterminated_Unicode_escape_sequence);
  2497. isInvalidExtendedEscape = true;
  2498. }
  2499. if (isInvalidExtendedEscape) {
  2500. return "";
  2501. }
  2502. return utf16EncodeAsString(escapedValue);
  2503. }
  2504. function utf16EncodeAsString(codePoint) {
  2505. ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF);
  2506. if (codePoint <= 65535) {
  2507. return String.fromCharCode(codePoint);
  2508. }
  2509. var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800;
  2510. var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00;
  2511. return String.fromCharCode(codeUnit1, codeUnit2);
  2512. }
  2513. function peekUnicodeEscape() {
  2514. if (pos + 5 < end && text.charCodeAt(pos + 1) === 117) {
  2515. var start_1 = pos;
  2516. pos += 2;
  2517. var value = scanExactNumberOfHexDigits(4);
  2518. pos = start_1;
  2519. return value;
  2520. }
  2521. return -1;
  2522. }
  2523. function scanIdentifierParts() {
  2524. var result = "";
  2525. var start = pos;
  2526. while (pos < end) {
  2527. var ch = text.charCodeAt(pos);
  2528. if (isIdentifierPart(ch, languageVersion)) {
  2529. pos++;
  2530. }
  2531. else if (ch === 92) {
  2532. ch = peekUnicodeEscape();
  2533. if (!(ch >= 0 && isIdentifierPart(ch, languageVersion))) {
  2534. break;
  2535. }
  2536. result += text.substring(start, pos);
  2537. result += String.fromCharCode(ch);
  2538. pos += 6;
  2539. start = pos;
  2540. }
  2541. else {
  2542. break;
  2543. }
  2544. }
  2545. result += text.substring(start, pos);
  2546. return result;
  2547. }
  2548. function getIdentifierToken() {
  2549. var len = tokenValue.length;
  2550. if (len >= 2 && len <= 11) {
  2551. var ch = tokenValue.charCodeAt(0);
  2552. if (ch >= 97 && ch <= 122 && hasOwnProperty.call(textToToken, tokenValue)) {
  2553. return token = textToToken[tokenValue];
  2554. }
  2555. }
  2556. return token = 69;
  2557. }
  2558. function scanBinaryOrOctalDigits(base) {
  2559. ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8");
  2560. var value = 0;
  2561. var numberOfDigits = 0;
  2562. while (true) {
  2563. var ch = text.charCodeAt(pos);
  2564. var valueOfCh = ch - 48;
  2565. if (!isDigit(ch) || valueOfCh >= base) {
  2566. break;
  2567. }
  2568. value = value * base + valueOfCh;
  2569. pos++;
  2570. numberOfDigits++;
  2571. }
  2572. if (numberOfDigits === 0) {
  2573. return -1;
  2574. }
  2575. return value;
  2576. }
  2577. function scan() {
  2578. startPos = pos;
  2579. hasExtendedUnicodeEscape = false;
  2580. precedingLineBreak = false;
  2581. tokenIsUnterminated = false;
  2582. while (true) {
  2583. tokenPos = pos;
  2584. if (pos >= end) {
  2585. return token = 1;
  2586. }
  2587. var ch = text.charCodeAt(pos);
  2588. if (ch === 35 && pos === 0 && isShebangTrivia(text, pos)) {
  2589. pos = scanShebangTrivia(text, pos);
  2590. if (skipTrivia) {
  2591. continue;
  2592. }
  2593. else {
  2594. return token = 6;
  2595. }
  2596. }
  2597. switch (ch) {
  2598. case 10:
  2599. case 13:
  2600. precedingLineBreak = true;
  2601. if (skipTrivia) {
  2602. pos++;
  2603. continue;
  2604. }
  2605. else {
  2606. if (ch === 13 && pos + 1 < end && text.charCodeAt(pos + 1) === 10) {
  2607. pos += 2;
  2608. }
  2609. else {
  2610. pos++;
  2611. }
  2612. return token = 4;
  2613. }
  2614. case 9:
  2615. case 11:
  2616. case 12:
  2617. case 32:
  2618. if (skipTrivia) {
  2619. pos++;
  2620. continue;
  2621. }
  2622. else {
  2623. while (pos < end && isWhiteSpace(text.charCodeAt(pos))) {
  2624. pos++;
  2625. }
  2626. return token = 5;
  2627. }
  2628. case 33:
  2629. if (text.charCodeAt(pos + 1) === 61) {
  2630. if (text.charCodeAt(pos + 2) === 61) {
  2631. return pos += 3, token = 33;
  2632. }
  2633. return pos += 2, token = 31;
  2634. }
  2635. return pos++, token = 49;
  2636. case 34:
  2637. case 39:
  2638. tokenValue = scanString();
  2639. return token = 9;
  2640. case 96:
  2641. return token = scanTemplateAndSetTokenValue();
  2642. case 37:
  2643. if (text.charCodeAt(pos + 1) === 61) {
  2644. return pos += 2, token = 62;
  2645. }
  2646. return pos++, token = 40;
  2647. case 38:
  2648. if (text.charCodeAt(pos + 1) === 38) {
  2649. return pos += 2, token = 51;
  2650. }
  2651. if (text.charCodeAt(pos + 1) === 61) {
  2652. return pos += 2, token = 66;
  2653. }
  2654. return pos++, token = 46;
  2655. case 40:
  2656. return pos++, token = 17;
  2657. case 41:
  2658. return pos++, token = 18;
  2659. case 42:
  2660. if (text.charCodeAt(pos + 1) === 61) {
  2661. return pos += 2, token = 59;
  2662. }
  2663. if (text.charCodeAt(pos + 1) === 42) {
  2664. if (text.charCodeAt(pos + 2) === 61) {
  2665. return pos += 3, token = 60;
  2666. }
  2667. return pos += 2, token = 38;
  2668. }
  2669. return pos++, token = 37;
  2670. case 43:
  2671. if (text.charCodeAt(pos + 1) === 43) {
  2672. return pos += 2, token = 41;
  2673. }
  2674. if (text.charCodeAt(pos + 1) === 61) {
  2675. return pos += 2, token = 57;
  2676. }
  2677. return pos++, token = 35;
  2678. case 44:
  2679. return pos++, token = 24;
  2680. case 45:
  2681. if (text.charCodeAt(pos + 1) === 45) {
  2682. return pos += 2, token = 42;
  2683. }
  2684. if (text.charCodeAt(pos + 1) === 61) {
  2685. return pos += 2, token = 58;
  2686. }
  2687. return pos++, token = 36;
  2688. case 46:
  2689. if (isDigit(text.charCodeAt(pos + 1))) {
  2690. tokenValue = "" + scanNumber();
  2691. return token = 8;
  2692. }
  2693. if (text.charCodeAt(pos + 1) === 46 && text.charCodeAt(pos + 2) === 46) {
  2694. return pos += 3, token = 22;
  2695. }
  2696. return pos++, token = 21;
  2697. case 47:
  2698. if (text.charCodeAt(pos + 1) === 47) {
  2699. pos += 2;
  2700. while (pos < end) {
  2701. if (isLineBreak(text.charCodeAt(pos))) {
  2702. break;
  2703. }
  2704. pos++;
  2705. }
  2706. if (skipTrivia) {
  2707. continue;
  2708. }
  2709. else {
  2710. return token = 2;
  2711. }
  2712. }
  2713. if (text.charCodeAt(pos + 1) === 42) {
  2714. pos += 2;
  2715. var commentClosed = false;
  2716. while (pos < end) {
  2717. var ch_2 = text.charCodeAt(pos);
  2718. if (ch_2 === 42 && text.charCodeAt(pos + 1) === 47) {
  2719. pos += 2;
  2720. commentClosed = true;
  2721. break;
  2722. }
  2723. if (isLineBreak(ch_2)) {
  2724. precedingLineBreak = true;
  2725. }
  2726. pos++;
  2727. }
  2728. if (!commentClosed) {
  2729. error(ts.Diagnostics.Asterisk_Slash_expected);
  2730. }
  2731. if (skipTrivia) {
  2732. continue;
  2733. }
  2734. else {
  2735. tokenIsUnterminated = !commentClosed;
  2736. return token = 3;
  2737. }
  2738. }
  2739. if (text.charCodeAt(pos + 1) === 61) {
  2740. return pos += 2, token = 61;
  2741. }
  2742. return pos++, token = 39;
  2743. case 48:
  2744. if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) {
  2745. pos += 2;
  2746. var value = scanMinimumNumberOfHexDigits(1);
  2747. if (value < 0) {
  2748. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2749. value = 0;
  2750. }
  2751. tokenValue = "" + value;
  2752. return token = 8;
  2753. }
  2754. else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 || text.charCodeAt(pos + 1) === 98)) {
  2755. pos += 2;
  2756. var value = scanBinaryOrOctalDigits(2);
  2757. if (value < 0) {
  2758. error(ts.Diagnostics.Binary_digit_expected);
  2759. value = 0;
  2760. }
  2761. tokenValue = "" + value;
  2762. return token = 8;
  2763. }
  2764. else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 || text.charCodeAt(pos + 1) === 111)) {
  2765. pos += 2;
  2766. var value = scanBinaryOrOctalDigits(8);
  2767. if (value < 0) {
  2768. error(ts.Diagnostics.Octal_digit_expected);
  2769. value = 0;
  2770. }
  2771. tokenValue = "" + value;
  2772. return token = 8;
  2773. }
  2774. if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) {
  2775. tokenValue = "" + scanOctalDigits();
  2776. return token = 8;
  2777. }
  2778. case 49:
  2779. case 50:
  2780. case 51:
  2781. case 52:
  2782. case 53:
  2783. case 54:
  2784. case 55:
  2785. case 56:
  2786. case 57:
  2787. tokenValue = "" + scanNumber();
  2788. return token = 8;
  2789. case 58:
  2790. return pos++, token = 54;
  2791. case 59:
  2792. return pos++, token = 23;
  2793. case 60:
  2794. if (isConflictMarkerTrivia(text, pos)) {
  2795. pos = scanConflictMarkerTrivia(text, pos, error);
  2796. if (skipTrivia) {
  2797. continue;
  2798. }
  2799. else {
  2800. return token = 7;
  2801. }
  2802. }
  2803. if (text.charCodeAt(pos + 1) === 60) {
  2804. if (text.charCodeAt(pos + 2) === 61) {
  2805. return pos += 3, token = 63;
  2806. }
  2807. return pos += 2, token = 43;
  2808. }
  2809. if (text.charCodeAt(pos + 1) === 61) {
  2810. return pos += 2, token = 28;
  2811. }
  2812. if (languageVariant === 1 &&
  2813. text.charCodeAt(pos + 1) === 47 &&
  2814. text.charCodeAt(pos + 2) !== 42) {
  2815. return pos += 2, token = 26;
  2816. }
  2817. return pos++, token = 25;
  2818. case 61:
  2819. if (isConflictMarkerTrivia(text, pos)) {
  2820. pos = scanConflictMarkerTrivia(text, pos, error);
  2821. if (skipTrivia) {
  2822. continue;
  2823. }
  2824. else {
  2825. return token = 7;
  2826. }
  2827. }
  2828. if (text.charCodeAt(pos + 1) === 61) {
  2829. if (text.charCodeAt(pos + 2) === 61) {
  2830. return pos += 3, token = 32;
  2831. }
  2832. return pos += 2, token = 30;
  2833. }
  2834. if (text.charCodeAt(pos + 1) === 62) {
  2835. return pos += 2, token = 34;
  2836. }
  2837. return pos++, token = 56;
  2838. case 62:
  2839. if (isConflictMarkerTrivia(text, pos)) {
  2840. pos = scanConflictMarkerTrivia(text, pos, error);
  2841. if (skipTrivia) {
  2842. continue;
  2843. }
  2844. else {
  2845. return token = 7;
  2846. }
  2847. }
  2848. return pos++, token = 27;
  2849. case 63:
  2850. return pos++, token = 53;
  2851. case 91:
  2852. return pos++, token = 19;
  2853. case 93:
  2854. return pos++, token = 20;
  2855. case 94:
  2856. if (text.charCodeAt(pos + 1) === 61) {
  2857. return pos += 2, token = 68;
  2858. }
  2859. return pos++, token = 48;
  2860. case 123:
  2861. return pos++, token = 15;
  2862. case 124:
  2863. if (text.charCodeAt(pos + 1) === 124) {
  2864. return pos += 2, token = 52;
  2865. }
  2866. if (text.charCodeAt(pos + 1) === 61) {
  2867. return pos += 2, token = 67;
  2868. }
  2869. return pos++, token = 47;
  2870. case 125:
  2871. return pos++, token = 16;
  2872. case 126:
  2873. return pos++, token = 50;
  2874. case 64:
  2875. return pos++, token = 55;
  2876. case 92:
  2877. var cookedChar = peekUnicodeEscape();
  2878. if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) {
  2879. pos += 6;
  2880. tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
  2881. return token = getIdentifierToken();
  2882. }
  2883. error(ts.Diagnostics.Invalid_character);
  2884. return pos++, token = 0;
  2885. default:
  2886. if (isIdentifierStart(ch, languageVersion)) {
  2887. pos++;
  2888. while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion))
  2889. pos++;
  2890. tokenValue = text.substring(tokenPos, pos);
  2891. if (ch === 92) {
  2892. tokenValue += scanIdentifierParts();
  2893. }
  2894. return token = getIdentifierToken();
  2895. }
  2896. else if (isWhiteSpace(ch)) {
  2897. pos++;
  2898. continue;
  2899. }
  2900. else if (isLineBreak(ch)) {
  2901. precedingLineBreak = true;
  2902. pos++;
  2903. continue;
  2904. }
  2905. error(ts.Diagnostics.Invalid_character);
  2906. return pos++, token = 0;
  2907. }
  2908. }
  2909. }
  2910. function reScanGreaterToken() {
  2911. if (token === 27) {
  2912. if (text.charCodeAt(pos) === 62) {
  2913. if (text.charCodeAt(pos + 1) === 62) {
  2914. if (text.charCodeAt(pos + 2) === 61) {
  2915. return pos += 3, token = 65;
  2916. }
  2917. return pos += 2, token = 45;
  2918. }
  2919. if (text.charCodeAt(pos + 1) === 61) {
  2920. return pos += 2, token = 64;
  2921. }
  2922. return pos++, token = 44;
  2923. }
  2924. if (text.charCodeAt(pos) === 61) {
  2925. return pos++, token = 29;
  2926. }
  2927. }
  2928. return token;
  2929. }
  2930. function reScanSlashToken() {
  2931. if (token === 39 || token === 61) {
  2932. var p = tokenPos + 1;
  2933. var inEscape = false;
  2934. var inCharacterClass = false;
  2935. while (true) {
  2936. if (p >= end) {
  2937. tokenIsUnterminated = true;
  2938. error(ts.Diagnostics.Unterminated_regular_expression_literal);
  2939. break;
  2940. }
  2941. var ch = text.charCodeAt(p);
  2942. if (isLineBreak(ch)) {
  2943. tokenIsUnterminated = true;
  2944. error(ts.Diagnostics.Unterminated_regular_expression_literal);
  2945. break;
  2946. }
  2947. if (inEscape) {
  2948. inEscape = false;
  2949. }
  2950. else if (ch === 47 && !inCharacterClass) {
  2951. p++;
  2952. break;
  2953. }
  2954. else if (ch === 91) {
  2955. inCharacterClass = true;
  2956. }
  2957. else if (ch === 92) {
  2958. inEscape = true;
  2959. }
  2960. else if (ch === 93) {
  2961. inCharacterClass = false;
  2962. }
  2963. p++;
  2964. }
  2965. while (p < end && isIdentifierPart(text.charCodeAt(p), languageVersion)) {
  2966. p++;
  2967. }
  2968. pos = p;
  2969. tokenValue = text.substring(tokenPos, pos);
  2970. token = 10;
  2971. }
  2972. return token;
  2973. }
  2974. function reScanTemplateToken() {
  2975. ts.Debug.assert(token === 16, "'reScanTemplateToken' should only be called on a '}'");
  2976. pos = tokenPos;
  2977. return token = scanTemplateAndSetTokenValue();
  2978. }
  2979. function reScanJsxToken() {
  2980. pos = tokenPos = startPos;
  2981. return token = scanJsxToken();
  2982. }
  2983. function scanJsxToken() {
  2984. startPos = tokenPos = pos;
  2985. if (pos >= end) {
  2986. return token = 1;
  2987. }
  2988. var char = text.charCodeAt(pos);
  2989. if (char === 60) {
  2990. if (text.charCodeAt(pos + 1) === 47) {
  2991. pos += 2;
  2992. return token = 26;
  2993. }
  2994. pos++;
  2995. return token = 25;
  2996. }
  2997. if (char === 123) {
  2998. pos++;
  2999. return token = 15;
  3000. }
  3001. while (pos < end) {
  3002. pos++;
  3003. char = text.charCodeAt(pos);
  3004. if ((char === 123) || (char === 60)) {
  3005. break;
  3006. }
  3007. }
  3008. return token = 236;
  3009. }
  3010. function scanJsxIdentifier() {
  3011. if (tokenIsIdentifierOrKeyword(token)) {
  3012. var firstCharPosition = pos;
  3013. while (pos < end) {
  3014. var ch = text.charCodeAt(pos);
  3015. if (ch === 45 || ((firstCharPosition === pos) ? isIdentifierStart(ch, languageVersion) : isIdentifierPart(ch, languageVersion))) {
  3016. pos++;
  3017. }
  3018. else {
  3019. break;
  3020. }
  3021. }
  3022. tokenValue += text.substr(firstCharPosition, pos - firstCharPosition);
  3023. }
  3024. return token;
  3025. }
  3026. function speculationHelper(callback, isLookahead) {
  3027. var savePos = pos;
  3028. var saveStartPos = startPos;
  3029. var saveTokenPos = tokenPos;
  3030. var saveToken = token;
  3031. var saveTokenValue = tokenValue;
  3032. var savePrecedingLineBreak = precedingLineBreak;
  3033. var result = callback();
  3034. if (!result || isLookahead) {
  3035. pos = savePos;
  3036. startPos = saveStartPos;
  3037. tokenPos = saveTokenPos;
  3038. token = saveToken;
  3039. tokenValue = saveTokenValue;
  3040. precedingLineBreak = savePrecedingLineBreak;
  3041. }
  3042. return result;
  3043. }
  3044. function lookAhead(callback) {
  3045. return speculationHelper(callback, true);
  3046. }
  3047. function tryScan(callback) {
  3048. return speculationHelper(callback, false);
  3049. }
  3050. function setText(newText, start, length) {
  3051. text = newText || "";
  3052. end = length === undefined ? text.length : start + length;
  3053. setTextPos(start || 0);
  3054. }
  3055. function setOnError(errorCallback) {
  3056. onError = errorCallback;
  3057. }
  3058. function setScriptTarget(scriptTarget) {
  3059. languageVersion = scriptTarget;
  3060. }
  3061. function setLanguageVariant(variant) {
  3062. languageVariant = variant;
  3063. }
  3064. function setTextPos(textPos) {
  3065. ts.Debug.assert(textPos >= 0);
  3066. pos = textPos;
  3067. startPos = textPos;
  3068. tokenPos = textPos;
  3069. token = 0;
  3070. precedingLineBreak = false;
  3071. tokenValue = undefined;
  3072. hasExtendedUnicodeEscape = false;
  3073. tokenIsUnterminated = false;
  3074. }
  3075. }
  3076. ts.createScanner = createScanner;
  3077. })(ts || (ts = {}));
  3078. var ts;
  3079. (function (ts) {
  3080. ts.bindTime = 0;
  3081. function getModuleInstanceState(node) {
  3082. if (node.kind === 215 || node.kind === 216) {
  3083. return 0;
  3084. }
  3085. else if (ts.isConstEnumDeclaration(node)) {
  3086. return 2;
  3087. }
  3088. else if ((node.kind === 222 || node.kind === 221) && !(node.flags & 1)) {
  3089. return 0;
  3090. }
  3091. else if (node.kind === 219) {
  3092. var state = 0;
  3093. ts.forEachChild(node, function (n) {
  3094. switch (getModuleInstanceState(n)) {
  3095. case 0:
  3096. return false;
  3097. case 2:
  3098. state = 2;
  3099. return false;
  3100. case 1:
  3101. state = 1;
  3102. return true;
  3103. }
  3104. });
  3105. return state;
  3106. }
  3107. else if (node.kind === 218) {
  3108. return getModuleInstanceState(node.body);
  3109. }
  3110. else {
  3111. return 1;
  3112. }
  3113. }
  3114. ts.getModuleInstanceState = getModuleInstanceState;
  3115. function bindSourceFile(file) {
  3116. var start = new Date().getTime();
  3117. bindSourceFileWorker(file);
  3118. ts.bindTime += new Date().getTime() - start;
  3119. }
  3120. ts.bindSourceFile = bindSourceFile;
  3121. function bindSourceFileWorker(file) {
  3122. var parent;
  3123. var container;
  3124. var blockScopeContainer;
  3125. var lastContainer;
  3126. var seenThisKeyword;
  3127. var inStrictMode = !!file.externalModuleIndicator;
  3128. var symbolCount = 0;
  3129. var Symbol = ts.objectAllocator.getSymbolConstructor();
  3130. var classifiableNames = {};
  3131. if (!file.locals) {
  3132. bind(file);
  3133. file.symbolCount = symbolCount;
  3134. file.classifiableNames = classifiableNames;
  3135. }
  3136. return;
  3137. function createSymbol(flags, name) {
  3138. symbolCount++;
  3139. return new Symbol(flags, name);
  3140. }
  3141. function addDeclarationToSymbol(symbol, node, symbolFlags) {
  3142. symbol.flags |= symbolFlags;
  3143. node.symbol = symbol;
  3144. if (!symbol.declarations) {
  3145. symbol.declarations = [];
  3146. }
  3147. symbol.declarations.push(node);
  3148. if (symbolFlags & 1952 && !symbol.exports) {
  3149. symbol.exports = {};
  3150. }
  3151. if (symbolFlags & 6240 && !symbol.members) {
  3152. symbol.members = {};
  3153. }
  3154. if (symbolFlags & 107455 && !symbol.valueDeclaration) {
  3155. symbol.valueDeclaration = node;
  3156. }
  3157. }
  3158. function getDeclarationName(node) {
  3159. if (node.name) {
  3160. if (node.kind === 218 && node.name.kind === 9) {
  3161. return "\"" + node.name.text + "\"";
  3162. }
  3163. if (node.name.kind === 136) {
  3164. var nameExpression = node.name.expression;
  3165. ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression));
  3166. return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text);
  3167. }
  3168. return node.name.text;
  3169. }
  3170. switch (node.kind) {
  3171. case 144:
  3172. return "__constructor";
  3173. case 152:
  3174. case 147:
  3175. return "__call";
  3176. case 153:
  3177. case 148:
  3178. return "__new";
  3179. case 149:
  3180. return "__index";
  3181. case 228:
  3182. return "__export";
  3183. case 227:
  3184. return node.isExportEquals ? "export=" : "default";
  3185. case 213:
  3186. case 214:
  3187. return node.flags & 1024 ? "default" : undefined;
  3188. }
  3189. }
  3190. function getDisplayName(node) {
  3191. return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node);
  3192. }
  3193. function declareSymbol(symbolTable, parent, node, includes, excludes) {
  3194. ts.Debug.assert(!ts.hasDynamicName(node));
  3195. var isDefaultExport = node.flags & 1024;
  3196. var name = isDefaultExport && parent ? "default" : getDeclarationName(node);
  3197. var symbol;
  3198. if (name !== undefined) {
  3199. symbol = ts.hasProperty(symbolTable, name)
  3200. ? symbolTable[name]
  3201. : (symbolTable[name] = createSymbol(0, name));
  3202. if (name && (includes & 788448)) {
  3203. classifiableNames[name] = name;
  3204. }
  3205. if (symbol.flags & excludes) {
  3206. if (node.name) {
  3207. node.name.parent = node;
  3208. }
  3209. var message = symbol.flags & 2
  3210. ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
  3211. : ts.Diagnostics.Duplicate_identifier_0;
  3212. ts.forEach(symbol.declarations, function (declaration) {
  3213. if (declaration.flags & 1024) {
  3214. message = ts.Diagnostics.A_module_cannot_have_multiple_default_exports;
  3215. }
  3216. });
  3217. ts.forEach(symbol.declarations, function (declaration) {
  3218. file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
  3219. });
  3220. file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node)));
  3221. symbol = createSymbol(0, name);
  3222. }
  3223. }
  3224. else {
  3225. symbol = createSymbol(0, "__missing");
  3226. }
  3227. addDeclarationToSymbol(symbol, node, includes);
  3228. symbol.parent = parent;
  3229. return symbol;
  3230. }
  3231. function declareModuleMember(node, symbolFlags, symbolExcludes) {
  3232. var hasExportModifier = ts.getCombinedNodeFlags(node) & 1;
  3233. if (symbolFlags & 8388608) {
  3234. if (node.kind === 230 || (node.kind === 221 && hasExportModifier)) {
  3235. return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
  3236. }
  3237. else {
  3238. return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
  3239. }
  3240. }
  3241. else {
  3242. if (hasExportModifier || container.flags & 262144) {
  3243. var exportKind = (symbolFlags & 107455 ? 1048576 : 0) |
  3244. (symbolFlags & 793056 ? 2097152 : 0) |
  3245. (symbolFlags & 1536 ? 4194304 : 0);
  3246. var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
  3247. local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
  3248. node.localSymbol = local;
  3249. return local;
  3250. }
  3251. else {
  3252. return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
  3253. }
  3254. }
  3255. }
  3256. function bindChildren(node) {
  3257. var saveParent = parent;
  3258. var saveContainer = container;
  3259. var savedBlockScopeContainer = blockScopeContainer;
  3260. parent = node;
  3261. var containerFlags = getContainerFlags(node);
  3262. if (containerFlags & 1) {
  3263. container = blockScopeContainer = node;
  3264. if (containerFlags & 4) {
  3265. container.locals = {};
  3266. }
  3267. addToContainerChain(container);
  3268. }
  3269. else if (containerFlags & 2) {
  3270. blockScopeContainer = node;
  3271. blockScopeContainer.locals = undefined;
  3272. }
  3273. if (node.kind === 215) {
  3274. seenThisKeyword = false;
  3275. ts.forEachChild(node, bind);
  3276. node.flags = seenThisKeyword ? node.flags | 524288 : node.flags & ~524288;
  3277. }
  3278. else {
  3279. ts.forEachChild(node, bind);
  3280. }
  3281. container = saveContainer;
  3282. parent = saveParent;
  3283. blockScopeContainer = savedBlockScopeContainer;
  3284. }
  3285. function getContainerFlags(node) {
  3286. switch (node.kind) {
  3287. case 186:
  3288. case 214:
  3289. case 215:
  3290. case 217:
  3291. case 155:
  3292. case 165:
  3293. return 1;
  3294. case 147:
  3295. case 148:
  3296. case 149:
  3297. case 143:
  3298. case 142:
  3299. case 213:
  3300. case 144:
  3301. case 145:
  3302. case 146:
  3303. case 152:
  3304. case 153:
  3305. case 173:
  3306. case 174:
  3307. case 218:
  3308. case 248:
  3309. case 216:
  3310. return 5;
  3311. case 244:
  3312. case 199:
  3313. case 200:
  3314. case 201:
  3315. case 220:
  3316. return 2;
  3317. case 192:
  3318. return ts.isFunctionLike(node.parent) ? 0 : 2;
  3319. }
  3320. return 0;
  3321. }
  3322. function addToContainerChain(next) {
  3323. if (lastContainer) {
  3324. lastContainer.nextContainer = next;
  3325. }
  3326. lastContainer = next;
  3327. }
  3328. function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
  3329. declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
  3330. }
  3331. function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) {
  3332. switch (container.kind) {
  3333. case 218:
  3334. return declareModuleMember(node, symbolFlags, symbolExcludes);
  3335. case 248:
  3336. return declareSourceFileMember(node, symbolFlags, symbolExcludes);
  3337. case 186:
  3338. case 214:
  3339. return declareClassMember(node, symbolFlags, symbolExcludes);
  3340. case 217:
  3341. return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
  3342. case 155:
  3343. case 165:
  3344. case 215:
  3345. return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
  3346. case 152:
  3347. case 153:
  3348. case 147:
  3349. case 148:
  3350. case 149:
  3351. case 143:
  3352. case 142:
  3353. case 144:
  3354. case 145:
  3355. case 146:
  3356. case 213:
  3357. case 173:
  3358. case 174:
  3359. case 216:
  3360. return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
  3361. }
  3362. }
  3363. function declareClassMember(node, symbolFlags, symbolExcludes) {
  3364. return node.flags & 128
  3365. ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes)
  3366. : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
  3367. }
  3368. function declareSourceFileMember(node, symbolFlags, symbolExcludes) {
  3369. return ts.isExternalModule(file)
  3370. ? declareModuleMember(node, symbolFlags, symbolExcludes)
  3371. : declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
  3372. }
  3373. function isAmbientContext(node) {
  3374. while (node) {
  3375. if (node.flags & 2) {
  3376. return true;
  3377. }
  3378. node = node.parent;
  3379. }
  3380. return false;
  3381. }
  3382. function hasExportDeclarations(node) {
  3383. var body = node.kind === 248 ? node : node.body;
  3384. if (body.kind === 248 || body.kind === 219) {
  3385. for (var _i = 0, _a = body.statements; _i < _a.length; _i++) {
  3386. var stat = _a[_i];
  3387. if (stat.kind === 228 || stat.kind === 227) {
  3388. return true;
  3389. }
  3390. }
  3391. }
  3392. return false;
  3393. }
  3394. function setExportContextFlag(node) {
  3395. if (isAmbientContext(node) && !hasExportDeclarations(node)) {
  3396. node.flags |= 262144;
  3397. }
  3398. else {
  3399. node.flags &= ~262144;
  3400. }
  3401. }
  3402. function bindModuleDeclaration(node) {
  3403. setExportContextFlag(node);
  3404. if (node.name.kind === 9) {
  3405. declareSymbolAndAddToSymbolTable(node, 512, 106639);
  3406. }
  3407. else {
  3408. var state = getModuleInstanceState(node);
  3409. if (state === 0) {
  3410. declareSymbolAndAddToSymbolTable(node, 1024, 0);
  3411. }
  3412. else {
  3413. declareSymbolAndAddToSymbolTable(node, 512, 106639);
  3414. if (node.symbol.flags & (16 | 32 | 256)) {
  3415. node.symbol.constEnumOnlyModule = false;
  3416. }
  3417. else {
  3418. var currentModuleIsConstEnumOnly = state === 2;
  3419. if (node.symbol.constEnumOnlyModule === undefined) {
  3420. node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
  3421. }
  3422. else {
  3423. node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
  3424. }
  3425. }
  3426. }
  3427. }
  3428. }
  3429. function bindFunctionOrConstructorType(node) {
  3430. var symbol = createSymbol(131072, getDeclarationName(node));
  3431. addDeclarationToSymbol(symbol, node, 131072);
  3432. var typeLiteralSymbol = createSymbol(2048, "__type");
  3433. addDeclarationToSymbol(typeLiteralSymbol, node, 2048);
  3434. typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a);
  3435. var _a;
  3436. }
  3437. function bindObjectLiteralExpression(node) {
  3438. if (inStrictMode) {
  3439. var seen = {};
  3440. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  3441. var prop = _a[_i];
  3442. if (prop.name.kind !== 69) {
  3443. continue;
  3444. }
  3445. var identifier = prop.name;
  3446. var currentKind = prop.kind === 245 || prop.kind === 246 || prop.kind === 143
  3447. ? 1
  3448. : 2;
  3449. var existingKind = seen[identifier.text];
  3450. if (!existingKind) {
  3451. seen[identifier.text] = currentKind;
  3452. continue;
  3453. }
  3454. if (currentKind === 1 && existingKind === 1) {
  3455. var span = ts.getErrorSpanForNode(file, identifier);
  3456. file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode));
  3457. }
  3458. }
  3459. }
  3460. return bindAnonymousDeclaration(node, 4096, "__object");
  3461. }
  3462. function bindAnonymousDeclaration(node, symbolFlags, name) {
  3463. var symbol = createSymbol(symbolFlags, name);
  3464. addDeclarationToSymbol(symbol, node, symbolFlags);
  3465. }
  3466. function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
  3467. switch (blockScopeContainer.kind) {
  3468. case 218:
  3469. declareModuleMember(node, symbolFlags, symbolExcludes);
  3470. break;
  3471. case 248:
  3472. if (ts.isExternalModule(container)) {
  3473. declareModuleMember(node, symbolFlags, symbolExcludes);
  3474. break;
  3475. }
  3476. default:
  3477. if (!blockScopeContainer.locals) {
  3478. blockScopeContainer.locals = {};
  3479. addToContainerChain(blockScopeContainer);
  3480. }
  3481. declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
  3482. }
  3483. }
  3484. function bindBlockScopedVariableDeclaration(node) {
  3485. bindBlockScopedDeclaration(node, 2, 107455);
  3486. }
  3487. function checkStrictModeIdentifier(node) {
  3488. if (inStrictMode &&
  3489. node.originalKeywordKind >= 106 &&
  3490. node.originalKeywordKind <= 114 &&
  3491. !ts.isIdentifierName(node)) {
  3492. if (!file.parseDiagnostics.length) {
  3493. file.bindDiagnostics.push(ts.createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node)));
  3494. }
  3495. }
  3496. }
  3497. function getStrictModeIdentifierMessage(node) {
  3498. if (ts.getContainingClass(node)) {
  3499. return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
  3500. }
  3501. if (file.externalModuleIndicator) {
  3502. return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
  3503. }
  3504. return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
  3505. }
  3506. function checkStrictModeBinaryExpression(node) {
  3507. if (inStrictMode && ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operatorToken.kind)) {
  3508. checkStrictModeEvalOrArguments(node, node.left);
  3509. }
  3510. }
  3511. function checkStrictModeCatchClause(node) {
  3512. if (inStrictMode && node.variableDeclaration) {
  3513. checkStrictModeEvalOrArguments(node, node.variableDeclaration.name);
  3514. }
  3515. }
  3516. function checkStrictModeDeleteExpression(node) {
  3517. if (inStrictMode && node.expression.kind === 69) {
  3518. var span = ts.getErrorSpanForNode(file, node.expression);
  3519. file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
  3520. }
  3521. }
  3522. function isEvalOrArgumentsIdentifier(node) {
  3523. return node.kind === 69 &&
  3524. (node.text === "eval" || node.text === "arguments");
  3525. }
  3526. function checkStrictModeEvalOrArguments(contextNode, name) {
  3527. if (name && name.kind === 69) {
  3528. var identifier = name;
  3529. if (isEvalOrArgumentsIdentifier(identifier)) {
  3530. var span = ts.getErrorSpanForNode(file, name);
  3531. file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text));
  3532. }
  3533. }
  3534. }
  3535. function getStrictModeEvalOrArgumentsMessage(node) {
  3536. if (ts.getContainingClass(node)) {
  3537. return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
  3538. }
  3539. if (file.externalModuleIndicator) {
  3540. return ts.Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode;
  3541. }
  3542. return ts.Diagnostics.Invalid_use_of_0_in_strict_mode;
  3543. }
  3544. function checkStrictModeFunctionName(node) {
  3545. if (inStrictMode) {
  3546. checkStrictModeEvalOrArguments(node, node.name);
  3547. }
  3548. }
  3549. function checkStrictModeNumericLiteral(node) {
  3550. if (inStrictMode && node.flags & 65536) {
  3551. file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
  3552. }
  3553. }
  3554. function checkStrictModePostfixUnaryExpression(node) {
  3555. if (inStrictMode) {
  3556. checkStrictModeEvalOrArguments(node, node.operand);
  3557. }
  3558. }
  3559. function checkStrictModePrefixUnaryExpression(node) {
  3560. if (inStrictMode) {
  3561. if (node.operator === 41 || node.operator === 42) {
  3562. checkStrictModeEvalOrArguments(node, node.operand);
  3563. }
  3564. }
  3565. }
  3566. function checkStrictModeWithStatement(node) {
  3567. if (inStrictMode) {
  3568. grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
  3569. }
  3570. }
  3571. function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
  3572. var span = ts.getSpanOfTokenAtPosition(file, node.pos);
  3573. file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
  3574. }
  3575. function getDestructuringParameterName(node) {
  3576. return "__" + ts.indexOf(node.parent.parameters, node);
  3577. }
  3578. function bind(node) {
  3579. node.parent = parent;
  3580. var savedInStrictMode = inStrictMode;
  3581. if (!savedInStrictMode) {
  3582. updateStrictMode(node);
  3583. }
  3584. bindWorker(node);
  3585. bindChildren(node);
  3586. inStrictMode = savedInStrictMode;
  3587. }
  3588. function updateStrictMode(node) {
  3589. switch (node.kind) {
  3590. case 248:
  3591. case 219:
  3592. updateStrictModeStatementList(node.statements);
  3593. return;
  3594. case 192:
  3595. if (ts.isFunctionLike(node.parent)) {
  3596. updateStrictModeStatementList(node.statements);
  3597. }
  3598. return;
  3599. case 214:
  3600. case 186:
  3601. inStrictMode = true;
  3602. return;
  3603. }
  3604. }
  3605. function updateStrictModeStatementList(statements) {
  3606. for (var _i = 0; _i < statements.length; _i++) {
  3607. var statement = statements[_i];
  3608. if (!ts.isPrologueDirective(statement)) {
  3609. return;
  3610. }
  3611. if (isUseStrictPrologueDirective(statement)) {
  3612. inStrictMode = true;
  3613. return;
  3614. }
  3615. }
  3616. }
  3617. function isUseStrictPrologueDirective(node) {
  3618. var nodeText = ts.getTextOfNodeFromSourceText(file.text, node.expression);
  3619. return nodeText === "\"use strict\"" || nodeText === "'use strict'";
  3620. }
  3621. function bindWorker(node) {
  3622. switch (node.kind) {
  3623. case 69:
  3624. return checkStrictModeIdentifier(node);
  3625. case 181:
  3626. return checkStrictModeBinaryExpression(node);
  3627. case 244:
  3628. return checkStrictModeCatchClause(node);
  3629. case 175:
  3630. return checkStrictModeDeleteExpression(node);
  3631. case 8:
  3632. return checkStrictModeNumericLiteral(node);
  3633. case 180:
  3634. return checkStrictModePostfixUnaryExpression(node);
  3635. case 179:
  3636. return checkStrictModePrefixUnaryExpression(node);
  3637. case 205:
  3638. return checkStrictModeWithStatement(node);
  3639. case 97:
  3640. seenThisKeyword = true;
  3641. return;
  3642. case 137:
  3643. return declareSymbolAndAddToSymbolTable(node, 262144, 530912);
  3644. case 138:
  3645. return bindParameter(node);
  3646. case 211:
  3647. case 163:
  3648. return bindVariableDeclarationOrBindingElement(node);
  3649. case 141:
  3650. case 140:
  3651. return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455);
  3652. case 245:
  3653. case 246:
  3654. return bindPropertyOrMethodOrAccessor(node, 4, 107455);
  3655. case 247:
  3656. return bindPropertyOrMethodOrAccessor(node, 8, 107455);
  3657. case 147:
  3658. case 148:
  3659. case 149:
  3660. return declareSymbolAndAddToSymbolTable(node, 131072, 0);
  3661. case 143:
  3662. case 142:
  3663. return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263);
  3664. case 213:
  3665. checkStrictModeFunctionName(node);
  3666. return declareSymbolAndAddToSymbolTable(node, 16, 106927);
  3667. case 144:
  3668. return declareSymbolAndAddToSymbolTable(node, 16384, 0);
  3669. case 145:
  3670. return bindPropertyOrMethodOrAccessor(node, 32768, 41919);
  3671. case 146:
  3672. return bindPropertyOrMethodOrAccessor(node, 65536, 74687);
  3673. case 152:
  3674. case 153:
  3675. return bindFunctionOrConstructorType(node);
  3676. case 155:
  3677. return bindAnonymousDeclaration(node, 2048, "__type");
  3678. case 165:
  3679. return bindObjectLiteralExpression(node);
  3680. case 173:
  3681. case 174:
  3682. checkStrictModeFunctionName(node);
  3683. var bindingName = node.name ? node.name.text : "__function";
  3684. return bindAnonymousDeclaration(node, 16, bindingName);
  3685. case 186:
  3686. case 214:
  3687. return bindClassLikeDeclaration(node);
  3688. case 215:
  3689. return bindBlockScopedDeclaration(node, 64, 792960);
  3690. case 216:
  3691. return bindBlockScopedDeclaration(node, 524288, 793056);
  3692. case 217:
  3693. return bindEnumDeclaration(node);
  3694. case 218:
  3695. return bindModuleDeclaration(node);
  3696. case 221:
  3697. case 224:
  3698. case 226:
  3699. case 230:
  3700. return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608);
  3701. case 223:
  3702. return bindImportClause(node);
  3703. case 228:
  3704. return bindExportDeclaration(node);
  3705. case 227:
  3706. return bindExportAssignment(node);
  3707. case 248:
  3708. return bindSourceFileIfExternalModule();
  3709. }
  3710. }
  3711. function bindSourceFileIfExternalModule() {
  3712. setExportContextFlag(file);
  3713. if (ts.isExternalModule(file)) {
  3714. bindAnonymousDeclaration(file, 512, "\"" + ts.removeFileExtension(file.fileName) + "\"");
  3715. }
  3716. }
  3717. function bindExportAssignment(node) {
  3718. if (!container.symbol || !container.symbol.exports) {
  3719. bindAnonymousDeclaration(node, 8388608, getDeclarationName(node));
  3720. }
  3721. else if (node.expression.kind === 69) {
  3722. declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608);
  3723. }
  3724. else {
  3725. declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608);
  3726. }
  3727. }
  3728. function bindExportDeclaration(node) {
  3729. if (!container.symbol || !container.symbol.exports) {
  3730. bindAnonymousDeclaration(node, 1073741824, getDeclarationName(node));
  3731. }
  3732. else if (!node.exportClause) {
  3733. declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0);
  3734. }
  3735. }
  3736. function bindImportClause(node) {
  3737. if (node.name) {
  3738. declareSymbolAndAddToSymbolTable(node, 8388608, 8388608);
  3739. }
  3740. }
  3741. function bindClassLikeDeclaration(node) {
  3742. if (node.kind === 214) {
  3743. bindBlockScopedDeclaration(node, 32, 899519);
  3744. }
  3745. else {
  3746. var bindingName = node.name ? node.name.text : "__class";
  3747. bindAnonymousDeclaration(node, 32, bindingName);
  3748. if (node.name) {
  3749. classifiableNames[node.name.text] = node.name.text;
  3750. }
  3751. }
  3752. var symbol = node.symbol;
  3753. var prototypeSymbol = createSymbol(4 | 134217728, "prototype");
  3754. if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
  3755. if (node.name) {
  3756. node.name.parent = node;
  3757. }
  3758. file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
  3759. }
  3760. symbol.exports[prototypeSymbol.name] = prototypeSymbol;
  3761. prototypeSymbol.parent = symbol;
  3762. }
  3763. function bindEnumDeclaration(node) {
  3764. return ts.isConst(node)
  3765. ? bindBlockScopedDeclaration(node, 128, 899967)
  3766. : bindBlockScopedDeclaration(node, 256, 899327);
  3767. }
  3768. function bindVariableDeclarationOrBindingElement(node) {
  3769. if (inStrictMode) {
  3770. checkStrictModeEvalOrArguments(node, node.name);
  3771. }
  3772. if (!ts.isBindingPattern(node.name)) {
  3773. if (ts.isBlockOrCatchScoped(node)) {
  3774. bindBlockScopedVariableDeclaration(node);
  3775. }
  3776. else if (ts.isParameterDeclaration(node)) {
  3777. declareSymbolAndAddToSymbolTable(node, 1, 107455);
  3778. }
  3779. else {
  3780. declareSymbolAndAddToSymbolTable(node, 1, 107454);
  3781. }
  3782. }
  3783. }
  3784. function bindParameter(node) {
  3785. if (inStrictMode) {
  3786. checkStrictModeEvalOrArguments(node, node.name);
  3787. }
  3788. if (ts.isBindingPattern(node.name)) {
  3789. bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node));
  3790. }
  3791. else {
  3792. declareSymbolAndAddToSymbolTable(node, 1, 107455);
  3793. }
  3794. if (node.flags & 112 &&
  3795. node.parent.kind === 144 &&
  3796. ts.isClassLike(node.parent.parent)) {
  3797. var classDeclaration = node.parent.parent;
  3798. declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455);
  3799. }
  3800. }
  3801. function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
  3802. return ts.hasDynamicName(node)
  3803. ? bindAnonymousDeclaration(node, symbolFlags, "__computed")
  3804. : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
  3805. }
  3806. }
  3807. })(ts || (ts = {}));
  3808. var ts;
  3809. (function (ts) {
  3810. function getDeclarationOfKind(symbol, kind) {
  3811. var declarations = symbol.declarations;
  3812. if (declarations) {
  3813. for (var _i = 0; _i < declarations.length; _i++) {
  3814. var declaration = declarations[_i];
  3815. if (declaration.kind === kind) {
  3816. return declaration;
  3817. }
  3818. }
  3819. }
  3820. return undefined;
  3821. }
  3822. ts.getDeclarationOfKind = getDeclarationOfKind;
  3823. var stringWriters = [];
  3824. function getSingleLineStringWriter() {
  3825. if (stringWriters.length === 0) {
  3826. var str = "";
  3827. var writeText = function (text) { return str += text; };
  3828. return {
  3829. string: function () { return str; },
  3830. writeKeyword: writeText,
  3831. writeOperator: writeText,
  3832. writePunctuation: writeText,
  3833. writeSpace: writeText,
  3834. writeStringLiteral: writeText,
  3835. writeParameter: writeText,
  3836. writeSymbol: writeText,
  3837. writeLine: function () { return str += " "; },
  3838. increaseIndent: function () { },
  3839. decreaseIndent: function () { },
  3840. clear: function () { return str = ""; },
  3841. trackSymbol: function () { },
  3842. reportInaccessibleThisError: function () { }
  3843. };
  3844. }
  3845. return stringWriters.pop();
  3846. }
  3847. ts.getSingleLineStringWriter = getSingleLineStringWriter;
  3848. function releaseStringWriter(writer) {
  3849. writer.clear();
  3850. stringWriters.push(writer);
  3851. }
  3852. ts.releaseStringWriter = releaseStringWriter;
  3853. function getFullWidth(node) {
  3854. return node.end - node.pos;
  3855. }
  3856. ts.getFullWidth = getFullWidth;
  3857. function arrayIsEqualTo(arr1, arr2, comparer) {
  3858. if (!arr1 || !arr2) {
  3859. return arr1 === arr2;
  3860. }
  3861. if (arr1.length !== arr2.length) {
  3862. return false;
  3863. }
  3864. for (var i = 0; i < arr1.length; ++i) {
  3865. var equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i];
  3866. if (!equals) {
  3867. return false;
  3868. }
  3869. }
  3870. return true;
  3871. }
  3872. ts.arrayIsEqualTo = arrayIsEqualTo;
  3873. function hasResolvedModule(sourceFile, moduleNameText) {
  3874. return sourceFile.resolvedModules && ts.hasProperty(sourceFile.resolvedModules, moduleNameText);
  3875. }
  3876. ts.hasResolvedModule = hasResolvedModule;
  3877. function getResolvedModule(sourceFile, moduleNameText) {
  3878. return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined;
  3879. }
  3880. ts.getResolvedModule = getResolvedModule;
  3881. function setResolvedModule(sourceFile, moduleNameText, resolvedModule) {
  3882. if (!sourceFile.resolvedModules) {
  3883. sourceFile.resolvedModules = {};
  3884. }
  3885. sourceFile.resolvedModules[moduleNameText] = resolvedModule;
  3886. }
  3887. ts.setResolvedModule = setResolvedModule;
  3888. function containsParseError(node) {
  3889. aggregateChildData(node);
  3890. return (node.parserContextFlags & 64) !== 0;
  3891. }
  3892. ts.containsParseError = containsParseError;
  3893. function aggregateChildData(node) {
  3894. if (!(node.parserContextFlags & 128)) {
  3895. var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 16) !== 0) ||
  3896. ts.forEachChild(node, containsParseError);
  3897. if (thisNodeOrAnySubNodesHasError) {
  3898. node.parserContextFlags |= 64;
  3899. }
  3900. node.parserContextFlags |= 128;
  3901. }
  3902. }
  3903. function getSourceFileOfNode(node) {
  3904. while (node && node.kind !== 248) {
  3905. node = node.parent;
  3906. }
  3907. return node;
  3908. }
  3909. ts.getSourceFileOfNode = getSourceFileOfNode;
  3910. function getStartPositionOfLine(line, sourceFile) {
  3911. ts.Debug.assert(line >= 0);
  3912. return ts.getLineStarts(sourceFile)[line];
  3913. }
  3914. ts.getStartPositionOfLine = getStartPositionOfLine;
  3915. function nodePosToString(node) {
  3916. var file = getSourceFileOfNode(node);
  3917. var loc = ts.getLineAndCharacterOfPosition(file, node.pos);
  3918. return file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + ")";
  3919. }
  3920. ts.nodePosToString = nodePosToString;
  3921. function getStartPosOfNode(node) {
  3922. return node.pos;
  3923. }
  3924. ts.getStartPosOfNode = getStartPosOfNode;
  3925. function nodeIsMissing(node) {
  3926. if (!node) {
  3927. return true;
  3928. }
  3929. return node.pos === node.end && node.pos >= 0 && node.kind !== 1;
  3930. }
  3931. ts.nodeIsMissing = nodeIsMissing;
  3932. function nodeIsPresent(node) {
  3933. return !nodeIsMissing(node);
  3934. }
  3935. ts.nodeIsPresent = nodeIsPresent;
  3936. function getTokenPosOfNode(node, sourceFile) {
  3937. if (nodeIsMissing(node)) {
  3938. return node.pos;
  3939. }
  3940. return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
  3941. }
  3942. ts.getTokenPosOfNode = getTokenPosOfNode;
  3943. function getNonDecoratorTokenPosOfNode(node, sourceFile) {
  3944. if (nodeIsMissing(node) || !node.decorators) {
  3945. return getTokenPosOfNode(node, sourceFile);
  3946. }
  3947. return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
  3948. }
  3949. ts.getNonDecoratorTokenPosOfNode = getNonDecoratorTokenPosOfNode;
  3950. function getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia) {
  3951. if (includeTrivia === void 0) { includeTrivia = false; }
  3952. if (nodeIsMissing(node)) {
  3953. return "";
  3954. }
  3955. var text = sourceFile.text;
  3956. return text.substring(includeTrivia ? node.pos : ts.skipTrivia(text, node.pos), node.end);
  3957. }
  3958. ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile;
  3959. function getTextOfNodeFromSourceText(sourceText, node) {
  3960. if (nodeIsMissing(node)) {
  3961. return "";
  3962. }
  3963. return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
  3964. }
  3965. ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText;
  3966. function getTextOfNode(node, includeTrivia) {
  3967. if (includeTrivia === void 0) { includeTrivia = false; }
  3968. return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node, includeTrivia);
  3969. }
  3970. ts.getTextOfNode = getTextOfNode;
  3971. function escapeIdentifier(identifier) {
  3972. return identifier.length >= 2 && identifier.charCodeAt(0) === 95 && identifier.charCodeAt(1) === 95 ? "_" + identifier : identifier;
  3973. }
  3974. ts.escapeIdentifier = escapeIdentifier;
  3975. function unescapeIdentifier(identifier) {
  3976. return identifier.length >= 3 && identifier.charCodeAt(0) === 95 && identifier.charCodeAt(1) === 95 && identifier.charCodeAt(2) === 95 ? identifier.substr(1) : identifier;
  3977. }
  3978. ts.unescapeIdentifier = unescapeIdentifier;
  3979. function makeIdentifierFromModuleName(moduleName) {
  3980. return ts.getBaseFileName(moduleName).replace(/^(\d)/, "_$1").replace(/\W/g, "_");
  3981. }
  3982. ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName;
  3983. function isBlockOrCatchScoped(declaration) {
  3984. return (getCombinedNodeFlags(declaration) & 49152) !== 0 ||
  3985. isCatchClauseVariableDeclaration(declaration);
  3986. }
  3987. ts.isBlockOrCatchScoped = isBlockOrCatchScoped;
  3988. function getEnclosingBlockScopeContainer(node) {
  3989. var current = node.parent;
  3990. while (current) {
  3991. if (isFunctionLike(current)) {
  3992. return current;
  3993. }
  3994. switch (current.kind) {
  3995. case 248:
  3996. case 220:
  3997. case 244:
  3998. case 218:
  3999. case 199:
  4000. case 200:
  4001. case 201:
  4002. return current;
  4003. case 192:
  4004. if (!isFunctionLike(current.parent)) {
  4005. return current;
  4006. }
  4007. }
  4008. current = current.parent;
  4009. }
  4010. }
  4011. ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer;
  4012. function isCatchClauseVariableDeclaration(declaration) {
  4013. return declaration &&
  4014. declaration.kind === 211 &&
  4015. declaration.parent &&
  4016. declaration.parent.kind === 244;
  4017. }
  4018. ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration;
  4019. function declarationNameToString(name) {
  4020. return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name);
  4021. }
  4022. ts.declarationNameToString = declarationNameToString;
  4023. function createDiagnosticForNode(node, message, arg0, arg1, arg2) {
  4024. var sourceFile = getSourceFileOfNode(node);
  4025. var span = getErrorSpanForNode(sourceFile, node);
  4026. return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
  4027. }
  4028. ts.createDiagnosticForNode = createDiagnosticForNode;
  4029. function createDiagnosticForNodeFromMessageChain(node, messageChain) {
  4030. var sourceFile = getSourceFileOfNode(node);
  4031. var span = getErrorSpanForNode(sourceFile, node);
  4032. return {
  4033. file: sourceFile,
  4034. start: span.start,
  4035. length: span.length,
  4036. code: messageChain.code,
  4037. category: messageChain.category,
  4038. messageText: messageChain.next ? messageChain : messageChain.messageText
  4039. };
  4040. }
  4041. ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain;
  4042. function getSpanOfTokenAtPosition(sourceFile, pos) {
  4043. var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.languageVariant, sourceFile.text, undefined, pos);
  4044. scanner.scan();
  4045. var start = scanner.getTokenPos();
  4046. return ts.createTextSpanFromBounds(start, scanner.getTextPos());
  4047. }
  4048. ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition;
  4049. function getErrorSpanForNode(sourceFile, node) {
  4050. var errorNode = node;
  4051. switch (node.kind) {
  4052. case 248:
  4053. var pos_1 = ts.skipTrivia(sourceFile.text, 0, false);
  4054. if (pos_1 === sourceFile.text.length) {
  4055. return ts.createTextSpan(0, 0);
  4056. }
  4057. return getSpanOfTokenAtPosition(sourceFile, pos_1);
  4058. case 211:
  4059. case 163:
  4060. case 214:
  4061. case 186:
  4062. case 215:
  4063. case 218:
  4064. case 217:
  4065. case 247:
  4066. case 213:
  4067. case 173:
  4068. errorNode = node.name;
  4069. break;
  4070. }
  4071. if (errorNode === undefined) {
  4072. return getSpanOfTokenAtPosition(sourceFile, node.pos);
  4073. }
  4074. var pos = nodeIsMissing(errorNode)
  4075. ? errorNode.pos
  4076. : ts.skipTrivia(sourceFile.text, errorNode.pos);
  4077. return ts.createTextSpanFromBounds(pos, errorNode.end);
  4078. }
  4079. ts.getErrorSpanForNode = getErrorSpanForNode;
  4080. function isExternalModule(file) {
  4081. return file.externalModuleIndicator !== undefined;
  4082. }
  4083. ts.isExternalModule = isExternalModule;
  4084. function isDeclarationFile(file) {
  4085. return (file.flags & 8192) !== 0;
  4086. }
  4087. ts.isDeclarationFile = isDeclarationFile;
  4088. function isConstEnumDeclaration(node) {
  4089. return node.kind === 217 && isConst(node);
  4090. }
  4091. ts.isConstEnumDeclaration = isConstEnumDeclaration;
  4092. function walkUpBindingElementsAndPatterns(node) {
  4093. while (node && (node.kind === 163 || isBindingPattern(node))) {
  4094. node = node.parent;
  4095. }
  4096. return node;
  4097. }
  4098. function getCombinedNodeFlags(node) {
  4099. node = walkUpBindingElementsAndPatterns(node);
  4100. var flags = node.flags;
  4101. if (node.kind === 211) {
  4102. node = node.parent;
  4103. }
  4104. if (node && node.kind === 212) {
  4105. flags |= node.flags;
  4106. node = node.parent;
  4107. }
  4108. if (node && node.kind === 193) {
  4109. flags |= node.flags;
  4110. }
  4111. return flags;
  4112. }
  4113. ts.getCombinedNodeFlags = getCombinedNodeFlags;
  4114. function isConst(node) {
  4115. return !!(getCombinedNodeFlags(node) & 32768);
  4116. }
  4117. ts.isConst = isConst;
  4118. function isLet(node) {
  4119. return !!(getCombinedNodeFlags(node) & 16384);
  4120. }
  4121. ts.isLet = isLet;
  4122. function isPrologueDirective(node) {
  4123. return node.kind === 195 && node.expression.kind === 9;
  4124. }
  4125. ts.isPrologueDirective = isPrologueDirective;
  4126. function getLeadingCommentRangesOfNode(node, sourceFileOfNode) {
  4127. return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos);
  4128. }
  4129. ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode;
  4130. function getJsDocComments(node, sourceFileOfNode) {
  4131. var commentRanges = (node.kind === 138 || node.kind === 137) ?
  4132. ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) :
  4133. getLeadingCommentRangesOfNode(node, sourceFileOfNode);
  4134. return ts.filter(commentRanges, isJsDocComment);
  4135. function isJsDocComment(comment) {
  4136. return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 &&
  4137. sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 &&
  4138. sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47;
  4139. }
  4140. }
  4141. ts.getJsDocComments = getJsDocComments;
  4142. ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
  4143. ts.fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
  4144. function isTypeNode(node) {
  4145. if (151 <= node.kind && node.kind <= 160) {
  4146. return true;
  4147. }
  4148. switch (node.kind) {
  4149. case 117:
  4150. case 128:
  4151. case 130:
  4152. case 120:
  4153. case 131:
  4154. return true;
  4155. case 103:
  4156. return node.parent.kind !== 177;
  4157. case 9:
  4158. return node.parent.kind === 138;
  4159. case 188:
  4160. return !isExpressionWithTypeArgumentsInClassExtendsClause(node);
  4161. case 69:
  4162. if (node.parent.kind === 135 && node.parent.right === node) {
  4163. node = node.parent;
  4164. }
  4165. else if (node.parent.kind === 166 && node.parent.name === node) {
  4166. node = node.parent;
  4167. }
  4168. ts.Debug.assert(node.kind === 69 || node.kind === 135 || node.kind === 166, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'.");
  4169. case 135:
  4170. case 166:
  4171. case 97:
  4172. var parent_1 = node.parent;
  4173. if (parent_1.kind === 154) {
  4174. return false;
  4175. }
  4176. if (151 <= parent_1.kind && parent_1.kind <= 160) {
  4177. return true;
  4178. }
  4179. switch (parent_1.kind) {
  4180. case 188:
  4181. return !isExpressionWithTypeArgumentsInClassExtendsClause(parent_1);
  4182. case 137:
  4183. return node === parent_1.constraint;
  4184. case 141:
  4185. case 140:
  4186. case 138:
  4187. case 211:
  4188. return node === parent_1.type;
  4189. case 213:
  4190. case 173:
  4191. case 174:
  4192. case 144:
  4193. case 143:
  4194. case 142:
  4195. case 145:
  4196. case 146:
  4197. return node === parent_1.type;
  4198. case 147:
  4199. case 148:
  4200. case 149:
  4201. return node === parent_1.type;
  4202. case 171:
  4203. return node === parent_1.type;
  4204. case 168:
  4205. case 169:
  4206. return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0;
  4207. case 170:
  4208. return false;
  4209. }
  4210. }
  4211. return false;
  4212. }
  4213. ts.isTypeNode = isTypeNode;
  4214. function forEachReturnStatement(body, visitor) {
  4215. return traverse(body);
  4216. function traverse(node) {
  4217. switch (node.kind) {
  4218. case 204:
  4219. return visitor(node);
  4220. case 220:
  4221. case 192:
  4222. case 196:
  4223. case 197:
  4224. case 198:
  4225. case 199:
  4226. case 200:
  4227. case 201:
  4228. case 205:
  4229. case 206:
  4230. case 241:
  4231. case 242:
  4232. case 207:
  4233. case 209:
  4234. case 244:
  4235. return ts.forEachChild(node, traverse);
  4236. }
  4237. }
  4238. }
  4239. ts.forEachReturnStatement = forEachReturnStatement;
  4240. function forEachYieldExpression(body, visitor) {
  4241. return traverse(body);
  4242. function traverse(node) {
  4243. switch (node.kind) {
  4244. case 184:
  4245. visitor(node);
  4246. var operand = node.expression;
  4247. if (operand) {
  4248. traverse(operand);
  4249. }
  4250. case 217:
  4251. case 215:
  4252. case 218:
  4253. case 216:
  4254. case 214:
  4255. case 186:
  4256. return;
  4257. default:
  4258. if (isFunctionLike(node)) {
  4259. var name_5 = node.name;
  4260. if (name_5 && name_5.kind === 136) {
  4261. traverse(name_5.expression);
  4262. return;
  4263. }
  4264. }
  4265. else if (!isTypeNode(node)) {
  4266. ts.forEachChild(node, traverse);
  4267. }
  4268. }
  4269. }
  4270. }
  4271. ts.forEachYieldExpression = forEachYieldExpression;
  4272. function isVariableLike(node) {
  4273. if (node) {
  4274. switch (node.kind) {
  4275. case 163:
  4276. case 247:
  4277. case 138:
  4278. case 245:
  4279. case 141:
  4280. case 140:
  4281. case 246:
  4282. case 211:
  4283. return true;
  4284. }
  4285. }
  4286. return false;
  4287. }
  4288. ts.isVariableLike = isVariableLike;
  4289. function isAccessor(node) {
  4290. return node && (node.kind === 145 || node.kind === 146);
  4291. }
  4292. ts.isAccessor = isAccessor;
  4293. function isClassLike(node) {
  4294. return node && (node.kind === 214 || node.kind === 186);
  4295. }
  4296. ts.isClassLike = isClassLike;
  4297. function isFunctionLike(node) {
  4298. if (node) {
  4299. switch (node.kind) {
  4300. case 144:
  4301. case 173:
  4302. case 213:
  4303. case 174:
  4304. case 143:
  4305. case 142:
  4306. case 145:
  4307. case 146:
  4308. case 147:
  4309. case 148:
  4310. case 149:
  4311. case 152:
  4312. case 153:
  4313. return true;
  4314. }
  4315. }
  4316. return false;
  4317. }
  4318. ts.isFunctionLike = isFunctionLike;
  4319. function introducesArgumentsExoticObject(node) {
  4320. switch (node.kind) {
  4321. case 143:
  4322. case 142:
  4323. case 144:
  4324. case 145:
  4325. case 146:
  4326. case 213:
  4327. case 173:
  4328. return true;
  4329. }
  4330. return false;
  4331. }
  4332. ts.introducesArgumentsExoticObject = introducesArgumentsExoticObject;
  4333. function isFunctionBlock(node) {
  4334. return node && node.kind === 192 && isFunctionLike(node.parent);
  4335. }
  4336. ts.isFunctionBlock = isFunctionBlock;
  4337. function isObjectLiteralMethod(node) {
  4338. return node && node.kind === 143 && node.parent.kind === 165;
  4339. }
  4340. ts.isObjectLiteralMethod = isObjectLiteralMethod;
  4341. function getContainingFunction(node) {
  4342. while (true) {
  4343. node = node.parent;
  4344. if (!node || isFunctionLike(node)) {
  4345. return node;
  4346. }
  4347. }
  4348. }
  4349. ts.getContainingFunction = getContainingFunction;
  4350. function getContainingClass(node) {
  4351. while (true) {
  4352. node = node.parent;
  4353. if (!node || isClassLike(node)) {
  4354. return node;
  4355. }
  4356. }
  4357. }
  4358. ts.getContainingClass = getContainingClass;
  4359. function getThisContainer(node, includeArrowFunctions) {
  4360. while (true) {
  4361. node = node.parent;
  4362. if (!node) {
  4363. return undefined;
  4364. }
  4365. switch (node.kind) {
  4366. case 136:
  4367. if (isClassLike(node.parent.parent)) {
  4368. return node;
  4369. }
  4370. node = node.parent;
  4371. break;
  4372. case 139:
  4373. if (node.parent.kind === 138 && isClassElement(node.parent.parent)) {
  4374. node = node.parent.parent;
  4375. }
  4376. else if (isClassElement(node.parent)) {
  4377. node = node.parent;
  4378. }
  4379. break;
  4380. case 174:
  4381. if (!includeArrowFunctions) {
  4382. continue;
  4383. }
  4384. case 213:
  4385. case 173:
  4386. case 218:
  4387. case 141:
  4388. case 140:
  4389. case 143:
  4390. case 142:
  4391. case 144:
  4392. case 145:
  4393. case 146:
  4394. case 147:
  4395. case 148:
  4396. case 149:
  4397. case 217:
  4398. case 248:
  4399. return node;
  4400. }
  4401. }
  4402. }
  4403. ts.getThisContainer = getThisContainer;
  4404. function getSuperContainer(node, includeFunctions) {
  4405. while (true) {
  4406. node = node.parent;
  4407. if (!node)
  4408. return node;
  4409. switch (node.kind) {
  4410. case 136:
  4411. if (isClassLike(node.parent.parent)) {
  4412. return node;
  4413. }
  4414. node = node.parent;
  4415. break;
  4416. case 139:
  4417. if (node.parent.kind === 138 && isClassElement(node.parent.parent)) {
  4418. node = node.parent.parent;
  4419. }
  4420. else if (isClassElement(node.parent)) {
  4421. node = node.parent;
  4422. }
  4423. break;
  4424. case 213:
  4425. case 173:
  4426. case 174:
  4427. if (!includeFunctions) {
  4428. continue;
  4429. }
  4430. case 141:
  4431. case 140:
  4432. case 143:
  4433. case 142:
  4434. case 144:
  4435. case 145:
  4436. case 146:
  4437. return node;
  4438. }
  4439. }
  4440. }
  4441. ts.getSuperContainer = getSuperContainer;
  4442. function getEntityNameFromTypeNode(node) {
  4443. if (node) {
  4444. switch (node.kind) {
  4445. case 151:
  4446. return node.typeName;
  4447. case 188:
  4448. return node.expression;
  4449. case 69:
  4450. case 135:
  4451. return node;
  4452. }
  4453. }
  4454. return undefined;
  4455. }
  4456. ts.getEntityNameFromTypeNode = getEntityNameFromTypeNode;
  4457. function getInvokedExpression(node) {
  4458. if (node.kind === 170) {
  4459. return node.tag;
  4460. }
  4461. return node.expression;
  4462. }
  4463. ts.getInvokedExpression = getInvokedExpression;
  4464. function nodeCanBeDecorated(node) {
  4465. switch (node.kind) {
  4466. case 214:
  4467. return true;
  4468. case 141:
  4469. return node.parent.kind === 214;
  4470. case 138:
  4471. return node.parent.body && node.parent.parent.kind === 214;
  4472. case 145:
  4473. case 146:
  4474. case 143:
  4475. return node.body && node.parent.kind === 214;
  4476. }
  4477. return false;
  4478. }
  4479. ts.nodeCanBeDecorated = nodeCanBeDecorated;
  4480. function nodeIsDecorated(node) {
  4481. switch (node.kind) {
  4482. case 214:
  4483. if (node.decorators) {
  4484. return true;
  4485. }
  4486. return false;
  4487. case 141:
  4488. case 138:
  4489. if (node.decorators) {
  4490. return true;
  4491. }
  4492. return false;
  4493. case 145:
  4494. if (node.body && node.decorators) {
  4495. return true;
  4496. }
  4497. return false;
  4498. case 143:
  4499. case 146:
  4500. if (node.body && node.decorators) {
  4501. return true;
  4502. }
  4503. return false;
  4504. }
  4505. return false;
  4506. }
  4507. ts.nodeIsDecorated = nodeIsDecorated;
  4508. function childIsDecorated(node) {
  4509. switch (node.kind) {
  4510. case 214:
  4511. return ts.forEach(node.members, nodeOrChildIsDecorated);
  4512. case 143:
  4513. case 146:
  4514. return ts.forEach(node.parameters, nodeIsDecorated);
  4515. }
  4516. return false;
  4517. }
  4518. ts.childIsDecorated = childIsDecorated;
  4519. function nodeOrChildIsDecorated(node) {
  4520. return nodeIsDecorated(node) || childIsDecorated(node);
  4521. }
  4522. ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated;
  4523. function isPropertyAccessExpression(node) {
  4524. return node.kind === 166;
  4525. }
  4526. ts.isPropertyAccessExpression = isPropertyAccessExpression;
  4527. function isElementAccessExpression(node) {
  4528. return node.kind === 167;
  4529. }
  4530. ts.isElementAccessExpression = isElementAccessExpression;
  4531. function isExpression(node) {
  4532. switch (node.kind) {
  4533. case 95:
  4534. case 93:
  4535. case 99:
  4536. case 84:
  4537. case 10:
  4538. case 164:
  4539. case 165:
  4540. case 166:
  4541. case 167:
  4542. case 168:
  4543. case 169:
  4544. case 170:
  4545. case 189:
  4546. case 171:
  4547. case 172:
  4548. case 173:
  4549. case 186:
  4550. case 174:
  4551. case 177:
  4552. case 175:
  4553. case 176:
  4554. case 179:
  4555. case 180:
  4556. case 181:
  4557. case 182:
  4558. case 185:
  4559. case 183:
  4560. case 11:
  4561. case 187:
  4562. case 233:
  4563. case 234:
  4564. case 184:
  4565. case 178:
  4566. return true;
  4567. case 135:
  4568. while (node.parent.kind === 135) {
  4569. node = node.parent;
  4570. }
  4571. return node.parent.kind === 154;
  4572. case 69:
  4573. if (node.parent.kind === 154) {
  4574. return true;
  4575. }
  4576. case 8:
  4577. case 9:
  4578. case 97:
  4579. var parent_2 = node.parent;
  4580. switch (parent_2.kind) {
  4581. case 211:
  4582. case 138:
  4583. case 141:
  4584. case 140:
  4585. case 247:
  4586. case 245:
  4587. case 163:
  4588. return parent_2.initializer === node;
  4589. case 195:
  4590. case 196:
  4591. case 197:
  4592. case 198:
  4593. case 204:
  4594. case 205:
  4595. case 206:
  4596. case 241:
  4597. case 208:
  4598. case 206:
  4599. return parent_2.expression === node;
  4600. case 199:
  4601. var forStatement = parent_2;
  4602. return (forStatement.initializer === node && forStatement.initializer.kind !== 212) ||
  4603. forStatement.condition === node ||
  4604. forStatement.incrementor === node;
  4605. case 200:
  4606. case 201:
  4607. var forInStatement = parent_2;
  4608. return (forInStatement.initializer === node && forInStatement.initializer.kind !== 212) ||
  4609. forInStatement.expression === node;
  4610. case 171:
  4611. case 189:
  4612. return node === parent_2.expression;
  4613. case 190:
  4614. return node === parent_2.expression;
  4615. case 136:
  4616. return node === parent_2.expression;
  4617. case 139:
  4618. case 240:
  4619. case 239:
  4620. return true;
  4621. case 188:
  4622. return parent_2.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent_2);
  4623. default:
  4624. if (isExpression(parent_2)) {
  4625. return true;
  4626. }
  4627. }
  4628. }
  4629. return false;
  4630. }
  4631. ts.isExpression = isExpression;
  4632. function isExternalModuleNameRelative(moduleName) {
  4633. return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
  4634. }
  4635. ts.isExternalModuleNameRelative = isExternalModuleNameRelative;
  4636. function isInstantiatedModule(node, preserveConstEnums) {
  4637. var moduleState = ts.getModuleInstanceState(node);
  4638. return moduleState === 1 ||
  4639. (preserveConstEnums && moduleState === 2);
  4640. }
  4641. ts.isInstantiatedModule = isInstantiatedModule;
  4642. function isExternalModuleImportEqualsDeclaration(node) {
  4643. return node.kind === 221 && node.moduleReference.kind === 232;
  4644. }
  4645. ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration;
  4646. function getExternalModuleImportEqualsDeclarationExpression(node) {
  4647. ts.Debug.assert(isExternalModuleImportEqualsDeclaration(node));
  4648. return node.moduleReference.expression;
  4649. }
  4650. ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
  4651. function isInternalModuleImportEqualsDeclaration(node) {
  4652. return node.kind === 221 && node.moduleReference.kind !== 232;
  4653. }
  4654. ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration;
  4655. function getExternalModuleName(node) {
  4656. if (node.kind === 222) {
  4657. return node.moduleSpecifier;
  4658. }
  4659. if (node.kind === 221) {
  4660. var reference = node.moduleReference;
  4661. if (reference.kind === 232) {
  4662. return reference.expression;
  4663. }
  4664. }
  4665. if (node.kind === 228) {
  4666. return node.moduleSpecifier;
  4667. }
  4668. }
  4669. ts.getExternalModuleName = getExternalModuleName;
  4670. function hasQuestionToken(node) {
  4671. if (node) {
  4672. switch (node.kind) {
  4673. case 138:
  4674. case 143:
  4675. case 142:
  4676. case 246:
  4677. case 245:
  4678. case 141:
  4679. case 140:
  4680. return node.questionToken !== undefined;
  4681. }
  4682. }
  4683. return false;
  4684. }
  4685. ts.hasQuestionToken = hasQuestionToken;
  4686. function isJSDocConstructSignature(node) {
  4687. return node.kind === 261 &&
  4688. node.parameters.length > 0 &&
  4689. node.parameters[0].type.kind === 263;
  4690. }
  4691. ts.isJSDocConstructSignature = isJSDocConstructSignature;
  4692. function getJSDocTag(node, kind) {
  4693. if (node && node.jsDocComment) {
  4694. for (var _i = 0, _a = node.jsDocComment.tags; _i < _a.length; _i++) {
  4695. var tag = _a[_i];
  4696. if (tag.kind === kind) {
  4697. return tag;
  4698. }
  4699. }
  4700. }
  4701. }
  4702. function getJSDocTypeTag(node) {
  4703. return getJSDocTag(node, 269);
  4704. }
  4705. ts.getJSDocTypeTag = getJSDocTypeTag;
  4706. function getJSDocReturnTag(node) {
  4707. return getJSDocTag(node, 268);
  4708. }
  4709. ts.getJSDocReturnTag = getJSDocReturnTag;
  4710. function getJSDocTemplateTag(node) {
  4711. return getJSDocTag(node, 270);
  4712. }
  4713. ts.getJSDocTemplateTag = getJSDocTemplateTag;
  4714. function getCorrespondingJSDocParameterTag(parameter) {
  4715. if (parameter.name && parameter.name.kind === 69) {
  4716. var parameterName = parameter.name.text;
  4717. var docComment = parameter.parent.jsDocComment;
  4718. if (docComment) {
  4719. return ts.forEach(docComment.tags, function (t) {
  4720. if (t.kind === 267) {
  4721. var parameterTag = t;
  4722. var name_6 = parameterTag.preParameterName || parameterTag.postParameterName;
  4723. if (name_6.text === parameterName) {
  4724. return t;
  4725. }
  4726. }
  4727. });
  4728. }
  4729. }
  4730. }
  4731. ts.getCorrespondingJSDocParameterTag = getCorrespondingJSDocParameterTag;
  4732. function hasRestParameter(s) {
  4733. return isRestParameter(ts.lastOrUndefined(s.parameters));
  4734. }
  4735. ts.hasRestParameter = hasRestParameter;
  4736. function isRestParameter(node) {
  4737. if (node) {
  4738. if (node.parserContextFlags & 32) {
  4739. if (node.type && node.type.kind === 262) {
  4740. return true;
  4741. }
  4742. var paramTag = getCorrespondingJSDocParameterTag(node);
  4743. if (paramTag && paramTag.typeExpression) {
  4744. return paramTag.typeExpression.type.kind === 262;
  4745. }
  4746. }
  4747. return node.dotDotDotToken !== undefined;
  4748. }
  4749. return false;
  4750. }
  4751. ts.isRestParameter = isRestParameter;
  4752. function isLiteralKind(kind) {
  4753. return 8 <= kind && kind <= 11;
  4754. }
  4755. ts.isLiteralKind = isLiteralKind;
  4756. function isTextualLiteralKind(kind) {
  4757. return kind === 9 || kind === 11;
  4758. }
  4759. ts.isTextualLiteralKind = isTextualLiteralKind;
  4760. function isTemplateLiteralKind(kind) {
  4761. return 11 <= kind && kind <= 14;
  4762. }
  4763. ts.isTemplateLiteralKind = isTemplateLiteralKind;
  4764. function isBindingPattern(node) {
  4765. return !!node && (node.kind === 162 || node.kind === 161);
  4766. }
  4767. ts.isBindingPattern = isBindingPattern;
  4768. function isNodeDescendentOf(node, ancestor) {
  4769. while (node) {
  4770. if (node === ancestor)
  4771. return true;
  4772. node = node.parent;
  4773. }
  4774. return false;
  4775. }
  4776. ts.isNodeDescendentOf = isNodeDescendentOf;
  4777. function isInAmbientContext(node) {
  4778. while (node) {
  4779. if (node.flags & (2 | 8192)) {
  4780. return true;
  4781. }
  4782. node = node.parent;
  4783. }
  4784. return false;
  4785. }
  4786. ts.isInAmbientContext = isInAmbientContext;
  4787. function isDeclaration(node) {
  4788. switch (node.kind) {
  4789. case 174:
  4790. case 163:
  4791. case 214:
  4792. case 186:
  4793. case 144:
  4794. case 217:
  4795. case 247:
  4796. case 230:
  4797. case 213:
  4798. case 173:
  4799. case 145:
  4800. case 223:
  4801. case 221:
  4802. case 226:
  4803. case 215:
  4804. case 143:
  4805. case 142:
  4806. case 218:
  4807. case 224:
  4808. case 138:
  4809. case 245:
  4810. case 141:
  4811. case 140:
  4812. case 146:
  4813. case 246:
  4814. case 216:
  4815. case 137:
  4816. case 211:
  4817. return true;
  4818. }
  4819. return false;
  4820. }
  4821. ts.isDeclaration = isDeclaration;
  4822. function isStatement(n) {
  4823. switch (n.kind) {
  4824. case 203:
  4825. case 202:
  4826. case 210:
  4827. case 197:
  4828. case 195:
  4829. case 194:
  4830. case 200:
  4831. case 201:
  4832. case 199:
  4833. case 196:
  4834. case 207:
  4835. case 204:
  4836. case 206:
  4837. case 98:
  4838. case 209:
  4839. case 193:
  4840. case 198:
  4841. case 205:
  4842. case 227:
  4843. return true;
  4844. default:
  4845. return false;
  4846. }
  4847. }
  4848. ts.isStatement = isStatement;
  4849. function isClassElement(n) {
  4850. switch (n.kind) {
  4851. case 144:
  4852. case 141:
  4853. case 143:
  4854. case 145:
  4855. case 146:
  4856. case 142:
  4857. case 149:
  4858. return true;
  4859. default:
  4860. return false;
  4861. }
  4862. }
  4863. ts.isClassElement = isClassElement;
  4864. function isDeclarationName(name) {
  4865. if (name.kind !== 69 && name.kind !== 9 && name.kind !== 8) {
  4866. return false;
  4867. }
  4868. var parent = name.parent;
  4869. if (parent.kind === 226 || parent.kind === 230) {
  4870. if (parent.propertyName) {
  4871. return true;
  4872. }
  4873. }
  4874. if (isDeclaration(parent)) {
  4875. return parent.name === name;
  4876. }
  4877. return false;
  4878. }
  4879. ts.isDeclarationName = isDeclarationName;
  4880. function isIdentifierName(node) {
  4881. var parent = node.parent;
  4882. switch (parent.kind) {
  4883. case 141:
  4884. case 140:
  4885. case 143:
  4886. case 142:
  4887. case 145:
  4888. case 146:
  4889. case 247:
  4890. case 245:
  4891. case 166:
  4892. return parent.name === node;
  4893. case 135:
  4894. if (parent.right === node) {
  4895. while (parent.kind === 135) {
  4896. parent = parent.parent;
  4897. }
  4898. return parent.kind === 154;
  4899. }
  4900. return false;
  4901. case 163:
  4902. case 226:
  4903. return parent.propertyName === node;
  4904. case 230:
  4905. return true;
  4906. }
  4907. return false;
  4908. }
  4909. ts.isIdentifierName = isIdentifierName;
  4910. function isAliasSymbolDeclaration(node) {
  4911. return node.kind === 221 ||
  4912. node.kind === 223 && !!node.name ||
  4913. node.kind === 224 ||
  4914. node.kind === 226 ||
  4915. node.kind === 230 ||
  4916. node.kind === 227 && node.expression.kind === 69;
  4917. }
  4918. ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration;
  4919. function getClassExtendsHeritageClauseElement(node) {
  4920. var heritageClause = getHeritageClause(node.heritageClauses, 83);
  4921. return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined;
  4922. }
  4923. ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement;
  4924. function getClassImplementsHeritageClauseElements(node) {
  4925. var heritageClause = getHeritageClause(node.heritageClauses, 106);
  4926. return heritageClause ? heritageClause.types : undefined;
  4927. }
  4928. ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements;
  4929. function getInterfaceBaseTypeNodes(node) {
  4930. var heritageClause = getHeritageClause(node.heritageClauses, 83);
  4931. return heritageClause ? heritageClause.types : undefined;
  4932. }
  4933. ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes;
  4934. function getHeritageClause(clauses, kind) {
  4935. if (clauses) {
  4936. for (var _i = 0; _i < clauses.length; _i++) {
  4937. var clause = clauses[_i];
  4938. if (clause.token === kind) {
  4939. return clause;
  4940. }
  4941. }
  4942. }
  4943. return undefined;
  4944. }
  4945. ts.getHeritageClause = getHeritageClause;
  4946. function tryResolveScriptReference(host, sourceFile, reference) {
  4947. if (!host.getCompilerOptions().noResolve) {
  4948. var referenceFileName = ts.isRootedDiskPath(reference.fileName) ? reference.fileName : ts.combinePaths(ts.getDirectoryPath(sourceFile.fileName), reference.fileName);
  4949. referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory());
  4950. return host.getSourceFile(referenceFileName);
  4951. }
  4952. }
  4953. ts.tryResolveScriptReference = tryResolveScriptReference;
  4954. function getAncestor(node, kind) {
  4955. while (node) {
  4956. if (node.kind === kind) {
  4957. return node;
  4958. }
  4959. node = node.parent;
  4960. }
  4961. return undefined;
  4962. }
  4963. ts.getAncestor = getAncestor;
  4964. function getFileReferenceFromReferencePath(comment, commentRange) {
  4965. var simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim;
  4966. var isNoDefaultLibRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)('|")(.+?)\2\s*\/>/gim;
  4967. if (simpleReferenceRegEx.exec(comment)) {
  4968. if (isNoDefaultLibRegEx.exec(comment)) {
  4969. return {
  4970. isNoDefaultLib: true
  4971. };
  4972. }
  4973. else {
  4974. var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment);
  4975. if (matchResult) {
  4976. var start = commentRange.pos;
  4977. var end = commentRange.end;
  4978. return {
  4979. fileReference: {
  4980. pos: start,
  4981. end: end,
  4982. fileName: matchResult[3]
  4983. },
  4984. isNoDefaultLib: false
  4985. };
  4986. }
  4987. else {
  4988. return {
  4989. diagnosticMessage: ts.Diagnostics.Invalid_reference_directive_syntax,
  4990. isNoDefaultLib: false
  4991. };
  4992. }
  4993. }
  4994. }
  4995. return undefined;
  4996. }
  4997. ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath;
  4998. function isKeyword(token) {
  4999. return 70 <= token && token <= 134;
  5000. }
  5001. ts.isKeyword = isKeyword;
  5002. function isTrivia(token) {
  5003. return 2 <= token && token <= 7;
  5004. }
  5005. ts.isTrivia = isTrivia;
  5006. function isAsyncFunctionLike(node) {
  5007. return isFunctionLike(node) && (node.flags & 512) !== 0 && !isAccessor(node);
  5008. }
  5009. ts.isAsyncFunctionLike = isAsyncFunctionLike;
  5010. function hasDynamicName(declaration) {
  5011. return declaration.name &&
  5012. declaration.name.kind === 136 &&
  5013. !isWellKnownSymbolSyntactically(declaration.name.expression);
  5014. }
  5015. ts.hasDynamicName = hasDynamicName;
  5016. function isWellKnownSymbolSyntactically(node) {
  5017. return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression);
  5018. }
  5019. ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically;
  5020. function getPropertyNameForPropertyNameNode(name) {
  5021. if (name.kind === 69 || name.kind === 9 || name.kind === 8) {
  5022. return name.text;
  5023. }
  5024. if (name.kind === 136) {
  5025. var nameExpression = name.expression;
  5026. if (isWellKnownSymbolSyntactically(nameExpression)) {
  5027. var rightHandSideName = nameExpression.name.text;
  5028. return getPropertyNameForKnownSymbolName(rightHandSideName);
  5029. }
  5030. }
  5031. return undefined;
  5032. }
  5033. ts.getPropertyNameForPropertyNameNode = getPropertyNameForPropertyNameNode;
  5034. function getPropertyNameForKnownSymbolName(symbolName) {
  5035. return "__@" + symbolName;
  5036. }
  5037. ts.getPropertyNameForKnownSymbolName = getPropertyNameForKnownSymbolName;
  5038. function isESSymbolIdentifier(node) {
  5039. return node.kind === 69 && node.text === "Symbol";
  5040. }
  5041. ts.isESSymbolIdentifier = isESSymbolIdentifier;
  5042. function isModifier(token) {
  5043. switch (token) {
  5044. case 115:
  5045. case 118:
  5046. case 74:
  5047. case 122:
  5048. case 77:
  5049. case 82:
  5050. case 112:
  5051. case 110:
  5052. case 111:
  5053. case 113:
  5054. return true;
  5055. }
  5056. return false;
  5057. }
  5058. ts.isModifier = isModifier;
  5059. function isParameterDeclaration(node) {
  5060. var root = getRootDeclaration(node);
  5061. return root.kind === 138;
  5062. }
  5063. ts.isParameterDeclaration = isParameterDeclaration;
  5064. function getRootDeclaration(node) {
  5065. while (node.kind === 163) {
  5066. node = node.parent.parent;
  5067. }
  5068. return node;
  5069. }
  5070. ts.getRootDeclaration = getRootDeclaration;
  5071. function nodeStartsNewLexicalEnvironment(n) {
  5072. return isFunctionLike(n) || n.kind === 218 || n.kind === 248;
  5073. }
  5074. ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
  5075. function cloneEntityName(node) {
  5076. if (node.kind === 69) {
  5077. var clone_1 = createSynthesizedNode(69);
  5078. clone_1.text = node.text;
  5079. return clone_1;
  5080. }
  5081. else {
  5082. var clone_2 = createSynthesizedNode(135);
  5083. clone_2.left = cloneEntityName(node.left);
  5084. clone_2.left.parent = clone_2;
  5085. clone_2.right = cloneEntityName(node.right);
  5086. clone_2.right.parent = clone_2;
  5087. return clone_2;
  5088. }
  5089. }
  5090. ts.cloneEntityName = cloneEntityName;
  5091. function nodeIsSynthesized(node) {
  5092. return node.pos === -1;
  5093. }
  5094. ts.nodeIsSynthesized = nodeIsSynthesized;
  5095. function createSynthesizedNode(kind, startsOnNewLine) {
  5096. var node = ts.createNode(kind);
  5097. node.startsOnNewLine = startsOnNewLine;
  5098. return node;
  5099. }
  5100. ts.createSynthesizedNode = createSynthesizedNode;
  5101. function createSynthesizedNodeArray() {
  5102. var array = [];
  5103. array.pos = -1;
  5104. array.end = -1;
  5105. return array;
  5106. }
  5107. ts.createSynthesizedNodeArray = createSynthesizedNodeArray;
  5108. function createDiagnosticCollection() {
  5109. var nonFileDiagnostics = [];
  5110. var fileDiagnostics = {};
  5111. var diagnosticsModified = false;
  5112. var modificationCount = 0;
  5113. return {
  5114. add: add,
  5115. getGlobalDiagnostics: getGlobalDiagnostics,
  5116. getDiagnostics: getDiagnostics,
  5117. getModificationCount: getModificationCount,
  5118. reattachFileDiagnostics: reattachFileDiagnostics
  5119. };
  5120. function getModificationCount() {
  5121. return modificationCount;
  5122. }
  5123. function reattachFileDiagnostics(newFile) {
  5124. if (!ts.hasProperty(fileDiagnostics, newFile.fileName)) {
  5125. return;
  5126. }
  5127. for (var _i = 0, _a = fileDiagnostics[newFile.fileName]; _i < _a.length; _i++) {
  5128. var diagnostic = _a[_i];
  5129. diagnostic.file = newFile;
  5130. }
  5131. }
  5132. function add(diagnostic) {
  5133. var diagnostics;
  5134. if (diagnostic.file) {
  5135. diagnostics = fileDiagnostics[diagnostic.file.fileName];
  5136. if (!diagnostics) {
  5137. diagnostics = [];
  5138. fileDiagnostics[diagnostic.file.fileName] = diagnostics;
  5139. }
  5140. }
  5141. else {
  5142. diagnostics = nonFileDiagnostics;
  5143. }
  5144. diagnostics.push(diagnostic);
  5145. diagnosticsModified = true;
  5146. modificationCount++;
  5147. }
  5148. function getGlobalDiagnostics() {
  5149. sortAndDeduplicate();
  5150. return nonFileDiagnostics;
  5151. }
  5152. function getDiagnostics(fileName) {
  5153. sortAndDeduplicate();
  5154. if (fileName) {
  5155. return fileDiagnostics[fileName] || [];
  5156. }
  5157. var allDiagnostics = [];
  5158. function pushDiagnostic(d) {
  5159. allDiagnostics.push(d);
  5160. }
  5161. ts.forEach(nonFileDiagnostics, pushDiagnostic);
  5162. for (var key in fileDiagnostics) {
  5163. if (ts.hasProperty(fileDiagnostics, key)) {
  5164. ts.forEach(fileDiagnostics[key], pushDiagnostic);
  5165. }
  5166. }
  5167. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  5168. }
  5169. function sortAndDeduplicate() {
  5170. if (!diagnosticsModified) {
  5171. return;
  5172. }
  5173. diagnosticsModified = false;
  5174. nonFileDiagnostics = ts.sortAndDeduplicateDiagnostics(nonFileDiagnostics);
  5175. for (var key in fileDiagnostics) {
  5176. if (ts.hasProperty(fileDiagnostics, key)) {
  5177. fileDiagnostics[key] = ts.sortAndDeduplicateDiagnostics(fileDiagnostics[key]);
  5178. }
  5179. }
  5180. }
  5181. }
  5182. ts.createDiagnosticCollection = createDiagnosticCollection;
  5183. var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
  5184. var escapedCharsMap = {
  5185. "\0": "\\0",
  5186. "\t": "\\t",
  5187. "\v": "\\v",
  5188. "\f": "\\f",
  5189. "\b": "\\b",
  5190. "\r": "\\r",
  5191. "\n": "\\n",
  5192. "\\": "\\\\",
  5193. "\"": "\\\"",
  5194. "\u2028": "\\u2028",
  5195. "\u2029": "\\u2029",
  5196. "\u0085": "\\u0085"
  5197. };
  5198. function escapeString(s) {
  5199. s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s;
  5200. return s;
  5201. function getReplacement(c) {
  5202. return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0));
  5203. }
  5204. }
  5205. ts.escapeString = escapeString;
  5206. function isIntrinsicJsxName(name) {
  5207. var ch = name.substr(0, 1);
  5208. return ch.toLowerCase() === ch;
  5209. }
  5210. ts.isIntrinsicJsxName = isIntrinsicJsxName;
  5211. function get16BitUnicodeEscapeSequence(charCode) {
  5212. var hexCharCode = charCode.toString(16).toUpperCase();
  5213. var paddedHexCode = ("0000" + hexCharCode).slice(-4);
  5214. return "\\u" + paddedHexCode;
  5215. }
  5216. var nonAsciiCharacters = /[^\u0000-\u007F]/g;
  5217. function escapeNonAsciiCharacters(s) {
  5218. return nonAsciiCharacters.test(s) ?
  5219. s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) :
  5220. s;
  5221. }
  5222. ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters;
  5223. var indentStrings = ["", " "];
  5224. function getIndentString(level) {
  5225. if (indentStrings[level] === undefined) {
  5226. indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
  5227. }
  5228. return indentStrings[level];
  5229. }
  5230. ts.getIndentString = getIndentString;
  5231. function getIndentSize() {
  5232. return indentStrings[1].length;
  5233. }
  5234. ts.getIndentSize = getIndentSize;
  5235. function createTextWriter(newLine) {
  5236. var output = "";
  5237. var indent = 0;
  5238. var lineStart = true;
  5239. var lineCount = 0;
  5240. var linePos = 0;
  5241. function write(s) {
  5242. if (s && s.length) {
  5243. if (lineStart) {
  5244. output += getIndentString(indent);
  5245. lineStart = false;
  5246. }
  5247. output += s;
  5248. }
  5249. }
  5250. function rawWrite(s) {
  5251. if (s !== undefined) {
  5252. if (lineStart) {
  5253. lineStart = false;
  5254. }
  5255. output += s;
  5256. }
  5257. }
  5258. function writeLiteral(s) {
  5259. if (s && s.length) {
  5260. write(s);
  5261. var lineStartsOfS = ts.computeLineStarts(s);
  5262. if (lineStartsOfS.length > 1) {
  5263. lineCount = lineCount + lineStartsOfS.length - 1;
  5264. linePos = output.length - s.length + ts.lastOrUndefined(lineStartsOfS);
  5265. }
  5266. }
  5267. }
  5268. function writeLine() {
  5269. if (!lineStart) {
  5270. output += newLine;
  5271. lineCount++;
  5272. linePos = output.length;
  5273. lineStart = true;
  5274. }
  5275. }
  5276. function writeTextOfNode(sourceFile, node) {
  5277. write(getSourceTextOfNodeFromSourceFile(sourceFile, node));
  5278. }
  5279. return {
  5280. write: write,
  5281. rawWrite: rawWrite,
  5282. writeTextOfNode: writeTextOfNode,
  5283. writeLiteral: writeLiteral,
  5284. writeLine: writeLine,
  5285. increaseIndent: function () { return indent++; },
  5286. decreaseIndent: function () { return indent--; },
  5287. getIndent: function () { return indent; },
  5288. getTextPos: function () { return output.length; },
  5289. getLine: function () { return lineCount + 1; },
  5290. getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
  5291. getText: function () { return output; }
  5292. };
  5293. }
  5294. ts.createTextWriter = createTextWriter;
  5295. function getOwnEmitOutputFilePath(sourceFile, host, extension) {
  5296. var compilerOptions = host.getCompilerOptions();
  5297. var emitOutputFilePathWithoutExtension;
  5298. if (compilerOptions.outDir) {
  5299. emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
  5300. }
  5301. else {
  5302. emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName);
  5303. }
  5304. return emitOutputFilePathWithoutExtension + extension;
  5305. }
  5306. ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath;
  5307. function getSourceFilePathInNewDir(sourceFile, host, newDirPath) {
  5308. var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory());
  5309. sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), "");
  5310. return ts.combinePaths(newDirPath, sourceFilePath);
  5311. }
  5312. ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir;
  5313. function writeFile(host, diagnostics, fileName, data, writeByteOrderMark) {
  5314. host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) {
  5315. diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
  5316. });
  5317. }
  5318. ts.writeFile = writeFile;
  5319. function getLineOfLocalPosition(currentSourceFile, pos) {
  5320. return ts.getLineAndCharacterOfPosition(currentSourceFile, pos).line;
  5321. }
  5322. ts.getLineOfLocalPosition = getLineOfLocalPosition;
  5323. function getFirstConstructorWithBody(node) {
  5324. return ts.forEach(node.members, function (member) {
  5325. if (member.kind === 144 && nodeIsPresent(member.body)) {
  5326. return member;
  5327. }
  5328. });
  5329. }
  5330. ts.getFirstConstructorWithBody = getFirstConstructorWithBody;
  5331. function getSetAccessorTypeAnnotationNode(accessor) {
  5332. return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type;
  5333. }
  5334. ts.getSetAccessorTypeAnnotationNode = getSetAccessorTypeAnnotationNode;
  5335. function shouldEmitToOwnFile(sourceFile, compilerOptions) {
  5336. if (!isDeclarationFile(sourceFile)) {
  5337. if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
  5338. return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js");
  5339. }
  5340. return false;
  5341. }
  5342. return false;
  5343. }
  5344. ts.shouldEmitToOwnFile = shouldEmitToOwnFile;
  5345. function getAllAccessorDeclarations(declarations, accessor) {
  5346. var firstAccessor;
  5347. var secondAccessor;
  5348. var getAccessor;
  5349. var setAccessor;
  5350. if (hasDynamicName(accessor)) {
  5351. firstAccessor = accessor;
  5352. if (accessor.kind === 145) {
  5353. getAccessor = accessor;
  5354. }
  5355. else if (accessor.kind === 146) {
  5356. setAccessor = accessor;
  5357. }
  5358. else {
  5359. ts.Debug.fail("Accessor has wrong kind");
  5360. }
  5361. }
  5362. else {
  5363. ts.forEach(declarations, function (member) {
  5364. if ((member.kind === 145 || member.kind === 146)
  5365. && (member.flags & 128) === (accessor.flags & 128)) {
  5366. var memberName = getPropertyNameForPropertyNameNode(member.name);
  5367. var accessorName = getPropertyNameForPropertyNameNode(accessor.name);
  5368. if (memberName === accessorName) {
  5369. if (!firstAccessor) {
  5370. firstAccessor = member;
  5371. }
  5372. else if (!secondAccessor) {
  5373. secondAccessor = member;
  5374. }
  5375. if (member.kind === 145 && !getAccessor) {
  5376. getAccessor = member;
  5377. }
  5378. if (member.kind === 146 && !setAccessor) {
  5379. setAccessor = member;
  5380. }
  5381. }
  5382. }
  5383. });
  5384. }
  5385. return {
  5386. firstAccessor: firstAccessor,
  5387. secondAccessor: secondAccessor,
  5388. getAccessor: getAccessor,
  5389. setAccessor: setAccessor
  5390. };
  5391. }
  5392. ts.getAllAccessorDeclarations = getAllAccessorDeclarations;
  5393. function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) {
  5394. if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
  5395. getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
  5396. writer.writeLine();
  5397. }
  5398. }
  5399. ts.emitNewLineBeforeLeadingComments = emitNewLineBeforeLeadingComments;
  5400. function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) {
  5401. var emitLeadingSpace = !trailingSeparator;
  5402. ts.forEach(comments, function (comment) {
  5403. if (emitLeadingSpace) {
  5404. writer.write(" ");
  5405. emitLeadingSpace = false;
  5406. }
  5407. writeComment(currentSourceFile, writer, comment, newLine);
  5408. if (comment.hasTrailingNewLine) {
  5409. writer.writeLine();
  5410. }
  5411. else if (trailingSeparator) {
  5412. writer.write(" ");
  5413. }
  5414. else {
  5415. emitLeadingSpace = true;
  5416. }
  5417. });
  5418. }
  5419. ts.emitComments = emitComments;
  5420. function writeCommentRange(currentSourceFile, writer, comment, newLine) {
  5421. if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42) {
  5422. var firstCommentLineAndCharacter = ts.getLineAndCharacterOfPosition(currentSourceFile, comment.pos);
  5423. var lineCount = ts.getLineStarts(currentSourceFile).length;
  5424. var firstCommentLineIndent;
  5425. for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
  5426. var nextLineStart = (currentLine + 1) === lineCount
  5427. ? currentSourceFile.text.length + 1
  5428. : getStartPositionOfLine(currentLine + 1, currentSourceFile);
  5429. if (pos !== comment.pos) {
  5430. if (firstCommentLineIndent === undefined) {
  5431. firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos);
  5432. }
  5433. var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
  5434. var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
  5435. if (spacesToEmit > 0) {
  5436. var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
  5437. var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
  5438. writer.rawWrite(indentSizeSpaceString);
  5439. while (numberOfSingleSpacesToEmit) {
  5440. writer.rawWrite(" ");
  5441. numberOfSingleSpacesToEmit--;
  5442. }
  5443. }
  5444. else {
  5445. writer.rawWrite("");
  5446. }
  5447. }
  5448. writeTrimmedCurrentLine(pos, nextLineStart);
  5449. pos = nextLineStart;
  5450. }
  5451. }
  5452. else {
  5453. writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
  5454. }
  5455. function writeTrimmedCurrentLine(pos, nextLineStart) {
  5456. var end = Math.min(comment.end, nextLineStart - 1);
  5457. var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, "");
  5458. if (currentLineText) {
  5459. writer.write(currentLineText);
  5460. if (end !== comment.end) {
  5461. writer.writeLine();
  5462. }
  5463. }
  5464. else {
  5465. writer.writeLiteral(newLine);
  5466. }
  5467. }
  5468. function calculateIndent(pos, end) {
  5469. var currentLineIndent = 0;
  5470. for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
  5471. if (currentSourceFile.text.charCodeAt(pos) === 9) {
  5472. currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
  5473. }
  5474. else {
  5475. currentLineIndent++;
  5476. }
  5477. }
  5478. return currentLineIndent;
  5479. }
  5480. }
  5481. ts.writeCommentRange = writeCommentRange;
  5482. function modifierToFlag(token) {
  5483. switch (token) {
  5484. case 113: return 128;
  5485. case 112: return 16;
  5486. case 111: return 64;
  5487. case 110: return 32;
  5488. case 115: return 256;
  5489. case 82: return 1;
  5490. case 122: return 2;
  5491. case 74: return 32768;
  5492. case 77: return 1024;
  5493. case 118: return 512;
  5494. }
  5495. return 0;
  5496. }
  5497. ts.modifierToFlag = modifierToFlag;
  5498. function isLeftHandSideExpression(expr) {
  5499. if (expr) {
  5500. switch (expr.kind) {
  5501. case 166:
  5502. case 167:
  5503. case 169:
  5504. case 168:
  5505. case 233:
  5506. case 234:
  5507. case 170:
  5508. case 164:
  5509. case 172:
  5510. case 165:
  5511. case 186:
  5512. case 173:
  5513. case 69:
  5514. case 10:
  5515. case 8:
  5516. case 9:
  5517. case 11:
  5518. case 183:
  5519. case 84:
  5520. case 93:
  5521. case 97:
  5522. case 99:
  5523. case 95:
  5524. return true;
  5525. }
  5526. }
  5527. return false;
  5528. }
  5529. ts.isLeftHandSideExpression = isLeftHandSideExpression;
  5530. function isAssignmentOperator(token) {
  5531. return token >= 56 && token <= 68;
  5532. }
  5533. ts.isAssignmentOperator = isAssignmentOperator;
  5534. function isExpressionWithTypeArgumentsInClassExtendsClause(node) {
  5535. return node.kind === 188 &&
  5536. node.parent.token === 83 &&
  5537. isClassLike(node.parent.parent);
  5538. }
  5539. ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause;
  5540. function isSupportedExpressionWithTypeArguments(node) {
  5541. return isSupportedExpressionWithTypeArgumentsRest(node.expression);
  5542. }
  5543. ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments;
  5544. function isSupportedExpressionWithTypeArgumentsRest(node) {
  5545. if (node.kind === 69) {
  5546. return true;
  5547. }
  5548. else if (isPropertyAccessExpression(node)) {
  5549. return isSupportedExpressionWithTypeArgumentsRest(node.expression);
  5550. }
  5551. else {
  5552. return false;
  5553. }
  5554. }
  5555. function isRightSideOfQualifiedNameOrPropertyAccess(node) {
  5556. return (node.parent.kind === 135 && node.parent.right === node) ||
  5557. (node.parent.kind === 166 && node.parent.name === node);
  5558. }
  5559. ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess;
  5560. function isEmptyObjectLiteralOrArrayLiteral(expression) {
  5561. var kind = expression.kind;
  5562. if (kind === 165) {
  5563. return expression.properties.length === 0;
  5564. }
  5565. if (kind === 164) {
  5566. return expression.elements.length === 0;
  5567. }
  5568. return false;
  5569. }
  5570. ts.isEmptyObjectLiteralOrArrayLiteral = isEmptyObjectLiteralOrArrayLiteral;
  5571. function getLocalSymbolForExportDefault(symbol) {
  5572. return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 1024) ? symbol.valueDeclaration.localSymbol : undefined;
  5573. }
  5574. ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault;
  5575. function isJavaScript(fileName) {
  5576. return ts.fileExtensionIs(fileName, ".js");
  5577. }
  5578. ts.isJavaScript = isJavaScript;
  5579. function isTsx(fileName) {
  5580. return ts.fileExtensionIs(fileName, ".tsx");
  5581. }
  5582. ts.isTsx = isTsx;
  5583. function getExpandedCharCodes(input) {
  5584. var output = [];
  5585. var length = input.length;
  5586. for (var i = 0; i < length; i++) {
  5587. var charCode = input.charCodeAt(i);
  5588. if (charCode < 0x80) {
  5589. output.push(charCode);
  5590. }
  5591. else if (charCode < 0x800) {
  5592. output.push((charCode >> 6) | 192);
  5593. output.push((charCode & 63) | 128);
  5594. }
  5595. else if (charCode < 0x10000) {
  5596. output.push((charCode >> 12) | 224);
  5597. output.push(((charCode >> 6) & 63) | 128);
  5598. output.push((charCode & 63) | 128);
  5599. }
  5600. else if (charCode < 0x20000) {
  5601. output.push((charCode >> 18) | 240);
  5602. output.push(((charCode >> 12) & 63) | 128);
  5603. output.push(((charCode >> 6) & 63) | 128);
  5604. output.push((charCode & 63) | 128);
  5605. }
  5606. else {
  5607. ts.Debug.assert(false, "Unexpected code point");
  5608. }
  5609. }
  5610. return output;
  5611. }
  5612. var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  5613. function convertToBase64(input) {
  5614. var result = "";
  5615. var charCodes = getExpandedCharCodes(input);
  5616. var i = 0;
  5617. var length = charCodes.length;
  5618. var byte1, byte2, byte3, byte4;
  5619. while (i < length) {
  5620. byte1 = charCodes[i] >> 2;
  5621. byte2 = (charCodes[i] & 3) << 4 | charCodes[i + 1] >> 4;
  5622. byte3 = (charCodes[i + 1] & 15) << 2 | charCodes[i + 2] >> 6;
  5623. byte4 = charCodes[i + 2] & 63;
  5624. if (i + 1 >= length) {
  5625. byte3 = byte4 = 64;
  5626. }
  5627. else if (i + 2 >= length) {
  5628. byte4 = 64;
  5629. }
  5630. result += base64Digits.charAt(byte1) + base64Digits.charAt(byte2) + base64Digits.charAt(byte3) + base64Digits.charAt(byte4);
  5631. i += 3;
  5632. }
  5633. return result;
  5634. }
  5635. ts.convertToBase64 = convertToBase64;
  5636. var carriageReturnLineFeed = "\r\n";
  5637. var lineFeed = "\n";
  5638. function getNewLineCharacter(options) {
  5639. if (options.newLine === 0) {
  5640. return carriageReturnLineFeed;
  5641. }
  5642. else if (options.newLine === 1) {
  5643. return lineFeed;
  5644. }
  5645. else if (ts.sys) {
  5646. return ts.sys.newLine;
  5647. }
  5648. return carriageReturnLineFeed;
  5649. }
  5650. ts.getNewLineCharacter = getNewLineCharacter;
  5651. })(ts || (ts = {}));
  5652. var ts;
  5653. (function (ts) {
  5654. function getDefaultLibFileName(options) {
  5655. return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts";
  5656. }
  5657. ts.getDefaultLibFileName = getDefaultLibFileName;
  5658. function textSpanEnd(span) {
  5659. return span.start + span.length;
  5660. }
  5661. ts.textSpanEnd = textSpanEnd;
  5662. function textSpanIsEmpty(span) {
  5663. return span.length === 0;
  5664. }
  5665. ts.textSpanIsEmpty = textSpanIsEmpty;
  5666. function textSpanContainsPosition(span, position) {
  5667. return position >= span.start && position < textSpanEnd(span);
  5668. }
  5669. ts.textSpanContainsPosition = textSpanContainsPosition;
  5670. function textSpanContainsTextSpan(span, other) {
  5671. return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span);
  5672. }
  5673. ts.textSpanContainsTextSpan = textSpanContainsTextSpan;
  5674. function textSpanOverlapsWith(span, other) {
  5675. var overlapStart = Math.max(span.start, other.start);
  5676. var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other));
  5677. return overlapStart < overlapEnd;
  5678. }
  5679. ts.textSpanOverlapsWith = textSpanOverlapsWith;
  5680. function textSpanOverlap(span1, span2) {
  5681. var overlapStart = Math.max(span1.start, span2.start);
  5682. var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
  5683. if (overlapStart < overlapEnd) {
  5684. return createTextSpanFromBounds(overlapStart, overlapEnd);
  5685. }
  5686. return undefined;
  5687. }
  5688. ts.textSpanOverlap = textSpanOverlap;
  5689. function textSpanIntersectsWithTextSpan(span, other) {
  5690. return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start;
  5691. }
  5692. ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan;
  5693. function textSpanIntersectsWith(span, start, length) {
  5694. var end = start + length;
  5695. return start <= textSpanEnd(span) && end >= span.start;
  5696. }
  5697. ts.textSpanIntersectsWith = textSpanIntersectsWith;
  5698. function decodedTextSpanIntersectsWith(start1, length1, start2, length2) {
  5699. var end1 = start1 + length1;
  5700. var end2 = start2 + length2;
  5701. return start2 <= end1 && end2 >= start1;
  5702. }
  5703. ts.decodedTextSpanIntersectsWith = decodedTextSpanIntersectsWith;
  5704. function textSpanIntersectsWithPosition(span, position) {
  5705. return position <= textSpanEnd(span) && position >= span.start;
  5706. }
  5707. ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition;
  5708. function textSpanIntersection(span1, span2) {
  5709. var intersectStart = Math.max(span1.start, span2.start);
  5710. var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
  5711. if (intersectStart <= intersectEnd) {
  5712. return createTextSpanFromBounds(intersectStart, intersectEnd);
  5713. }
  5714. return undefined;
  5715. }
  5716. ts.textSpanIntersection = textSpanIntersection;
  5717. function createTextSpan(start, length) {
  5718. if (start < 0) {
  5719. throw new Error("start < 0");
  5720. }
  5721. if (length < 0) {
  5722. throw new Error("length < 0");
  5723. }
  5724. return { start: start, length: length };
  5725. }
  5726. ts.createTextSpan = createTextSpan;
  5727. function createTextSpanFromBounds(start, end) {
  5728. return createTextSpan(start, end - start);
  5729. }
  5730. ts.createTextSpanFromBounds = createTextSpanFromBounds;
  5731. function textChangeRangeNewSpan(range) {
  5732. return createTextSpan(range.span.start, range.newLength);
  5733. }
  5734. ts.textChangeRangeNewSpan = textChangeRangeNewSpan;
  5735. function textChangeRangeIsUnchanged(range) {
  5736. return textSpanIsEmpty(range.span) && range.newLength === 0;
  5737. }
  5738. ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged;
  5739. function createTextChangeRange(span, newLength) {
  5740. if (newLength < 0) {
  5741. throw new Error("newLength < 0");
  5742. }
  5743. return { span: span, newLength: newLength };
  5744. }
  5745. ts.createTextChangeRange = createTextChangeRange;
  5746. ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
  5747. function collapseTextChangeRangesAcrossMultipleVersions(changes) {
  5748. if (changes.length === 0) {
  5749. return ts.unchangedTextChangeRange;
  5750. }
  5751. if (changes.length === 1) {
  5752. return changes[0];
  5753. }
  5754. var change0 = changes[0];
  5755. var oldStartN = change0.span.start;
  5756. var oldEndN = textSpanEnd(change0.span);
  5757. var newEndN = oldStartN + change0.newLength;
  5758. for (var i = 1; i < changes.length; i++) {
  5759. var nextChange = changes[i];
  5760. var oldStart1 = oldStartN;
  5761. var oldEnd1 = oldEndN;
  5762. var newEnd1 = newEndN;
  5763. var oldStart2 = nextChange.span.start;
  5764. var oldEnd2 = textSpanEnd(nextChange.span);
  5765. var newEnd2 = oldStart2 + nextChange.newLength;
  5766. oldStartN = Math.min(oldStart1, oldStart2);
  5767. oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1));
  5768. newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2));
  5769. }
  5770. return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN);
  5771. }
  5772. ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions;
  5773. function getTypeParameterOwner(d) {
  5774. if (d && d.kind === 137) {
  5775. for (var current = d; current; current = current.parent) {
  5776. if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 215) {
  5777. return current;
  5778. }
  5779. }
  5780. }
  5781. }
  5782. ts.getTypeParameterOwner = getTypeParameterOwner;
  5783. function arrayStructurallyIsEqualTo(array1, array2) {
  5784. if (!array1 || !array2) {
  5785. return false;
  5786. }
  5787. if (array1.length !== array2.length) {
  5788. return false;
  5789. }
  5790. return ts.arrayIsEqualTo(array1.sort(), array2.sort());
  5791. }
  5792. ts.arrayStructurallyIsEqualTo = arrayStructurallyIsEqualTo;
  5793. })(ts || (ts = {}));
  5794. var ts;
  5795. (function (ts) {
  5796. var nodeConstructors = new Array(272);
  5797. ts.parseTime = 0;
  5798. function getNodeConstructor(kind) {
  5799. return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind));
  5800. }
  5801. ts.getNodeConstructor = getNodeConstructor;
  5802. function createNode(kind) {
  5803. return new (getNodeConstructor(kind))();
  5804. }
  5805. ts.createNode = createNode;
  5806. function visitNode(cbNode, node) {
  5807. if (node) {
  5808. return cbNode(node);
  5809. }
  5810. }
  5811. function visitNodeArray(cbNodes, nodes) {
  5812. if (nodes) {
  5813. return cbNodes(nodes);
  5814. }
  5815. }
  5816. function visitEachNode(cbNode, nodes) {
  5817. if (nodes) {
  5818. for (var _i = 0; _i < nodes.length; _i++) {
  5819. var node = nodes[_i];
  5820. var result = cbNode(node);
  5821. if (result) {
  5822. return result;
  5823. }
  5824. }
  5825. }
  5826. }
  5827. function forEachChild(node, cbNode, cbNodeArray) {
  5828. if (!node) {
  5829. return;
  5830. }
  5831. var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode;
  5832. var cbNodes = cbNodeArray || cbNode;
  5833. switch (node.kind) {
  5834. case 135:
  5835. return visitNode(cbNode, node.left) ||
  5836. visitNode(cbNode, node.right);
  5837. case 137:
  5838. return visitNode(cbNode, node.name) ||
  5839. visitNode(cbNode, node.constraint) ||
  5840. visitNode(cbNode, node.expression);
  5841. case 246:
  5842. return visitNodes(cbNodes, node.decorators) ||
  5843. visitNodes(cbNodes, node.modifiers) ||
  5844. visitNode(cbNode, node.name) ||
  5845. visitNode(cbNode, node.questionToken) ||
  5846. visitNode(cbNode, node.equalsToken) ||
  5847. visitNode(cbNode, node.objectAssignmentInitializer);
  5848. case 138:
  5849. case 141:
  5850. case 140:
  5851. case 245:
  5852. case 211:
  5853. case 163:
  5854. return visitNodes(cbNodes, node.decorators) ||
  5855. visitNodes(cbNodes, node.modifiers) ||
  5856. visitNode(cbNode, node.propertyName) ||
  5857. visitNode(cbNode, node.dotDotDotToken) ||
  5858. visitNode(cbNode, node.name) ||
  5859. visitNode(cbNode, node.questionToken) ||
  5860. visitNode(cbNode, node.type) ||
  5861. visitNode(cbNode, node.initializer);
  5862. case 152:
  5863. case 153:
  5864. case 147:
  5865. case 148:
  5866. case 149:
  5867. return visitNodes(cbNodes, node.decorators) ||
  5868. visitNodes(cbNodes, node.modifiers) ||
  5869. visitNodes(cbNodes, node.typeParameters) ||
  5870. visitNodes(cbNodes, node.parameters) ||
  5871. visitNode(cbNode, node.type);
  5872. case 143:
  5873. case 142:
  5874. case 144:
  5875. case 145:
  5876. case 146:
  5877. case 173:
  5878. case 213:
  5879. case 174:
  5880. return visitNodes(cbNodes, node.decorators) ||
  5881. visitNodes(cbNodes, node.modifiers) ||
  5882. visitNode(cbNode, node.asteriskToken) ||
  5883. visitNode(cbNode, node.name) ||
  5884. visitNode(cbNode, node.questionToken) ||
  5885. visitNodes(cbNodes, node.typeParameters) ||
  5886. visitNodes(cbNodes, node.parameters) ||
  5887. visitNode(cbNode, node.type) ||
  5888. visitNode(cbNode, node.equalsGreaterThanToken) ||
  5889. visitNode(cbNode, node.body);
  5890. case 151:
  5891. return visitNode(cbNode, node.typeName) ||
  5892. visitNodes(cbNodes, node.typeArguments);
  5893. case 150:
  5894. return visitNode(cbNode, node.parameterName) ||
  5895. visitNode(cbNode, node.type);
  5896. case 154:
  5897. return visitNode(cbNode, node.exprName);
  5898. case 155:
  5899. return visitNodes(cbNodes, node.members);
  5900. case 156:
  5901. return visitNode(cbNode, node.elementType);
  5902. case 157:
  5903. return visitNodes(cbNodes, node.elementTypes);
  5904. case 158:
  5905. case 159:
  5906. return visitNodes(cbNodes, node.types);
  5907. case 160:
  5908. return visitNode(cbNode, node.type);
  5909. case 161:
  5910. case 162:
  5911. return visitNodes(cbNodes, node.elements);
  5912. case 164:
  5913. return visitNodes(cbNodes, node.elements);
  5914. case 165:
  5915. return visitNodes(cbNodes, node.properties);
  5916. case 166:
  5917. return visitNode(cbNode, node.expression) ||
  5918. visitNode(cbNode, node.dotToken) ||
  5919. visitNode(cbNode, node.name);
  5920. case 167:
  5921. return visitNode(cbNode, node.expression) ||
  5922. visitNode(cbNode, node.argumentExpression);
  5923. case 168:
  5924. case 169:
  5925. return visitNode(cbNode, node.expression) ||
  5926. visitNodes(cbNodes, node.typeArguments) ||
  5927. visitNodes(cbNodes, node.arguments);
  5928. case 170:
  5929. return visitNode(cbNode, node.tag) ||
  5930. visitNode(cbNode, node.template);
  5931. case 171:
  5932. return visitNode(cbNode, node.type) ||
  5933. visitNode(cbNode, node.expression);
  5934. case 172:
  5935. return visitNode(cbNode, node.expression);
  5936. case 175:
  5937. return visitNode(cbNode, node.expression);
  5938. case 176:
  5939. return visitNode(cbNode, node.expression);
  5940. case 177:
  5941. return visitNode(cbNode, node.expression);
  5942. case 179:
  5943. return visitNode(cbNode, node.operand);
  5944. case 184:
  5945. return visitNode(cbNode, node.asteriskToken) ||
  5946. visitNode(cbNode, node.expression);
  5947. case 178:
  5948. return visitNode(cbNode, node.expression);
  5949. case 180:
  5950. return visitNode(cbNode, node.operand);
  5951. case 181:
  5952. return visitNode(cbNode, node.left) ||
  5953. visitNode(cbNode, node.operatorToken) ||
  5954. visitNode(cbNode, node.right);
  5955. case 189:
  5956. return visitNode(cbNode, node.expression) ||
  5957. visitNode(cbNode, node.type);
  5958. case 182:
  5959. return visitNode(cbNode, node.condition) ||
  5960. visitNode(cbNode, node.questionToken) ||
  5961. visitNode(cbNode, node.whenTrue) ||
  5962. visitNode(cbNode, node.colonToken) ||
  5963. visitNode(cbNode, node.whenFalse);
  5964. case 185:
  5965. return visitNode(cbNode, node.expression);
  5966. case 192:
  5967. case 219:
  5968. return visitNodes(cbNodes, node.statements);
  5969. case 248:
  5970. return visitNodes(cbNodes, node.statements) ||
  5971. visitNode(cbNode, node.endOfFileToken);
  5972. case 193:
  5973. return visitNodes(cbNodes, node.decorators) ||
  5974. visitNodes(cbNodes, node.modifiers) ||
  5975. visitNode(cbNode, node.declarationList);
  5976. case 212:
  5977. return visitNodes(cbNodes, node.declarations);
  5978. case 195:
  5979. return visitNode(cbNode, node.expression);
  5980. case 196:
  5981. return visitNode(cbNode, node.expression) ||
  5982. visitNode(cbNode, node.thenStatement) ||
  5983. visitNode(cbNode, node.elseStatement);
  5984. case 197:
  5985. return visitNode(cbNode, node.statement) ||
  5986. visitNode(cbNode, node.expression);
  5987. case 198:
  5988. return visitNode(cbNode, node.expression) ||
  5989. visitNode(cbNode, node.statement);
  5990. case 199:
  5991. return visitNode(cbNode, node.initializer) ||
  5992. visitNode(cbNode, node.condition) ||
  5993. visitNode(cbNode, node.incrementor) ||
  5994. visitNode(cbNode, node.statement);
  5995. case 200:
  5996. return visitNode(cbNode, node.initializer) ||
  5997. visitNode(cbNode, node.expression) ||
  5998. visitNode(cbNode, node.statement);
  5999. case 201:
  6000. return visitNode(cbNode, node.initializer) ||
  6001. visitNode(cbNode, node.expression) ||
  6002. visitNode(cbNode, node.statement);
  6003. case 202:
  6004. case 203:
  6005. return visitNode(cbNode, node.label);
  6006. case 204:
  6007. return visitNode(cbNode, node.expression);
  6008. case 205:
  6009. return visitNode(cbNode, node.expression) ||
  6010. visitNode(cbNode, node.statement);
  6011. case 206:
  6012. return visitNode(cbNode, node.expression) ||
  6013. visitNode(cbNode, node.caseBlock);
  6014. case 220:
  6015. return visitNodes(cbNodes, node.clauses);
  6016. case 241:
  6017. return visitNode(cbNode, node.expression) ||
  6018. visitNodes(cbNodes, node.statements);
  6019. case 242:
  6020. return visitNodes(cbNodes, node.statements);
  6021. case 207:
  6022. return visitNode(cbNode, node.label) ||
  6023. visitNode(cbNode, node.statement);
  6024. case 208:
  6025. return visitNode(cbNode, node.expression);
  6026. case 209:
  6027. return visitNode(cbNode, node.tryBlock) ||
  6028. visitNode(cbNode, node.catchClause) ||
  6029. visitNode(cbNode, node.finallyBlock);
  6030. case 244:
  6031. return visitNode(cbNode, node.variableDeclaration) ||
  6032. visitNode(cbNode, node.block);
  6033. case 139:
  6034. return visitNode(cbNode, node.expression);
  6035. case 214:
  6036. case 186:
  6037. return visitNodes(cbNodes, node.decorators) ||
  6038. visitNodes(cbNodes, node.modifiers) ||
  6039. visitNode(cbNode, node.name) ||
  6040. visitNodes(cbNodes, node.typeParameters) ||
  6041. visitNodes(cbNodes, node.heritageClauses) ||
  6042. visitNodes(cbNodes, node.members);
  6043. case 215:
  6044. return visitNodes(cbNodes, node.decorators) ||
  6045. visitNodes(cbNodes, node.modifiers) ||
  6046. visitNode(cbNode, node.name) ||
  6047. visitNodes(cbNodes, node.typeParameters) ||
  6048. visitNodes(cbNodes, node.heritageClauses) ||
  6049. visitNodes(cbNodes, node.members);
  6050. case 216:
  6051. return visitNodes(cbNodes, node.decorators) ||
  6052. visitNodes(cbNodes, node.modifiers) ||
  6053. visitNode(cbNode, node.name) ||
  6054. visitNodes(cbNodes, node.typeParameters) ||
  6055. visitNode(cbNode, node.type);
  6056. case 217:
  6057. return visitNodes(cbNodes, node.decorators) ||
  6058. visitNodes(cbNodes, node.modifiers) ||
  6059. visitNode(cbNode, node.name) ||
  6060. visitNodes(cbNodes, node.members);
  6061. case 247:
  6062. return visitNode(cbNode, node.name) ||
  6063. visitNode(cbNode, node.initializer);
  6064. case 218:
  6065. return visitNodes(cbNodes, node.decorators) ||
  6066. visitNodes(cbNodes, node.modifiers) ||
  6067. visitNode(cbNode, node.name) ||
  6068. visitNode(cbNode, node.body);
  6069. case 221:
  6070. return visitNodes(cbNodes, node.decorators) ||
  6071. visitNodes(cbNodes, node.modifiers) ||
  6072. visitNode(cbNode, node.name) ||
  6073. visitNode(cbNode, node.moduleReference);
  6074. case 222:
  6075. return visitNodes(cbNodes, node.decorators) ||
  6076. visitNodes(cbNodes, node.modifiers) ||
  6077. visitNode(cbNode, node.importClause) ||
  6078. visitNode(cbNode, node.moduleSpecifier);
  6079. case 223:
  6080. return visitNode(cbNode, node.name) ||
  6081. visitNode(cbNode, node.namedBindings);
  6082. case 224:
  6083. return visitNode(cbNode, node.name);
  6084. case 225:
  6085. case 229:
  6086. return visitNodes(cbNodes, node.elements);
  6087. case 228:
  6088. return visitNodes(cbNodes, node.decorators) ||
  6089. visitNodes(cbNodes, node.modifiers) ||
  6090. visitNode(cbNode, node.exportClause) ||
  6091. visitNode(cbNode, node.moduleSpecifier);
  6092. case 226:
  6093. case 230:
  6094. return visitNode(cbNode, node.propertyName) ||
  6095. visitNode(cbNode, node.name);
  6096. case 227:
  6097. return visitNodes(cbNodes, node.decorators) ||
  6098. visitNodes(cbNodes, node.modifiers) ||
  6099. visitNode(cbNode, node.expression);
  6100. case 183:
  6101. return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans);
  6102. case 190:
  6103. return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal);
  6104. case 136:
  6105. return visitNode(cbNode, node.expression);
  6106. case 243:
  6107. return visitNodes(cbNodes, node.types);
  6108. case 188:
  6109. return visitNode(cbNode, node.expression) ||
  6110. visitNodes(cbNodes, node.typeArguments);
  6111. case 232:
  6112. return visitNode(cbNode, node.expression);
  6113. case 231:
  6114. return visitNodes(cbNodes, node.decorators);
  6115. case 233:
  6116. return visitNode(cbNode, node.openingElement) ||
  6117. visitNodes(cbNodes, node.children) ||
  6118. visitNode(cbNode, node.closingElement);
  6119. case 234:
  6120. case 235:
  6121. return visitNode(cbNode, node.tagName) ||
  6122. visitNodes(cbNodes, node.attributes);
  6123. case 238:
  6124. return visitNode(cbNode, node.name) ||
  6125. visitNode(cbNode, node.initializer);
  6126. case 239:
  6127. return visitNode(cbNode, node.expression);
  6128. case 240:
  6129. return visitNode(cbNode, node.expression);
  6130. case 237:
  6131. return visitNode(cbNode, node.tagName);
  6132. case 249:
  6133. return visitNode(cbNode, node.type);
  6134. case 253:
  6135. return visitNodes(cbNodes, node.types);
  6136. case 254:
  6137. return visitNodes(cbNodes, node.types);
  6138. case 252:
  6139. return visitNode(cbNode, node.elementType);
  6140. case 256:
  6141. return visitNode(cbNode, node.type);
  6142. case 255:
  6143. return visitNode(cbNode, node.type);
  6144. case 257:
  6145. return visitNodes(cbNodes, node.members);
  6146. case 259:
  6147. return visitNode(cbNode, node.name) ||
  6148. visitNodes(cbNodes, node.typeArguments);
  6149. case 260:
  6150. return visitNode(cbNode, node.type);
  6151. case 261:
  6152. return visitNodes(cbNodes, node.parameters) ||
  6153. visitNode(cbNode, node.type);
  6154. case 262:
  6155. return visitNode(cbNode, node.type);
  6156. case 263:
  6157. return visitNode(cbNode, node.type);
  6158. case 264:
  6159. return visitNode(cbNode, node.type);
  6160. case 258:
  6161. return visitNode(cbNode, node.name) ||
  6162. visitNode(cbNode, node.type);
  6163. case 265:
  6164. return visitNodes(cbNodes, node.tags);
  6165. case 267:
  6166. return visitNode(cbNode, node.preParameterName) ||
  6167. visitNode(cbNode, node.typeExpression) ||
  6168. visitNode(cbNode, node.postParameterName);
  6169. case 268:
  6170. return visitNode(cbNode, node.typeExpression);
  6171. case 269:
  6172. return visitNode(cbNode, node.typeExpression);
  6173. case 270:
  6174. return visitNodes(cbNodes, node.typeParameters);
  6175. }
  6176. }
  6177. ts.forEachChild = forEachChild;
  6178. function createSourceFile(fileName, sourceText, languageVersion, setParentNodes) {
  6179. if (setParentNodes === void 0) { setParentNodes = false; }
  6180. var start = new Date().getTime();
  6181. var result = Parser.parseSourceFile(fileName, sourceText, languageVersion, undefined, setParentNodes);
  6182. ts.parseTime += new Date().getTime() - start;
  6183. return result;
  6184. }
  6185. ts.createSourceFile = createSourceFile;
  6186. function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
  6187. return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
  6188. }
  6189. ts.updateSourceFile = updateSourceFile;
  6190. function parseIsolatedJSDocComment(content, start, length) {
  6191. return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length);
  6192. }
  6193. ts.parseIsolatedJSDocComment = parseIsolatedJSDocComment;
  6194. function parseJSDocTypeExpressionForTests(content, start, length) {
  6195. return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length);
  6196. }
  6197. ts.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests;
  6198. var Parser;
  6199. (function (Parser) {
  6200. var scanner = ts.createScanner(2, true);
  6201. var disallowInAndDecoratorContext = 1 | 4;
  6202. var sourceFile;
  6203. var parseDiagnostics;
  6204. var syntaxCursor;
  6205. var token;
  6206. var sourceText;
  6207. var nodeCount;
  6208. var identifiers;
  6209. var identifierCount;
  6210. var parsingContext;
  6211. var contextFlags;
  6212. var parseErrorBeforeNextFinishedNode = false;
  6213. function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) {
  6214. initializeState(fileName, _sourceText, languageVersion, _syntaxCursor);
  6215. var result = parseSourceFileWorker(fileName, languageVersion, setParentNodes);
  6216. clearState();
  6217. return result;
  6218. }
  6219. Parser.parseSourceFile = parseSourceFile;
  6220. function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor) {
  6221. sourceText = _sourceText;
  6222. syntaxCursor = _syntaxCursor;
  6223. parseDiagnostics = [];
  6224. parsingContext = 0;
  6225. identifiers = {};
  6226. identifierCount = 0;
  6227. nodeCount = 0;
  6228. contextFlags = ts.isJavaScript(fileName) ? 32 : 0;
  6229. parseErrorBeforeNextFinishedNode = false;
  6230. scanner.setText(sourceText);
  6231. scanner.setOnError(scanError);
  6232. scanner.setScriptTarget(languageVersion);
  6233. scanner.setLanguageVariant(ts.isTsx(fileName) ? 1 : 0);
  6234. }
  6235. function clearState() {
  6236. scanner.setText("");
  6237. scanner.setOnError(undefined);
  6238. parseDiagnostics = undefined;
  6239. sourceFile = undefined;
  6240. identifiers = undefined;
  6241. syntaxCursor = undefined;
  6242. sourceText = undefined;
  6243. }
  6244. function parseSourceFileWorker(fileName, languageVersion, setParentNodes) {
  6245. sourceFile = createSourceFile(fileName, languageVersion);
  6246. token = nextToken();
  6247. processReferenceComments(sourceFile);
  6248. sourceFile.statements = parseList(0, parseStatement);
  6249. ts.Debug.assert(token === 1);
  6250. sourceFile.endOfFileToken = parseTokenNode();
  6251. setExternalModuleIndicator(sourceFile);
  6252. sourceFile.nodeCount = nodeCount;
  6253. sourceFile.identifierCount = identifierCount;
  6254. sourceFile.identifiers = identifiers;
  6255. sourceFile.parseDiagnostics = parseDiagnostics;
  6256. if (setParentNodes) {
  6257. fixupParentReferences(sourceFile);
  6258. }
  6259. if (ts.isJavaScript(fileName)) {
  6260. addJSDocComments();
  6261. }
  6262. return sourceFile;
  6263. }
  6264. function addJSDocComments() {
  6265. forEachChild(sourceFile, visit);
  6266. return;
  6267. function visit(node) {
  6268. switch (node.kind) {
  6269. case 193:
  6270. case 213:
  6271. case 138:
  6272. addJSDocComment(node);
  6273. }
  6274. forEachChild(node, visit);
  6275. }
  6276. }
  6277. function addJSDocComment(node) {
  6278. var comments = ts.getLeadingCommentRangesOfNode(node, sourceFile);
  6279. if (comments) {
  6280. for (var _i = 0; _i < comments.length; _i++) {
  6281. var comment = comments[_i];
  6282. var jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos);
  6283. if (jsDocComment) {
  6284. node.jsDocComment = jsDocComment;
  6285. }
  6286. }
  6287. }
  6288. }
  6289. function fixupParentReferences(sourceFile) {
  6290. var parent = sourceFile;
  6291. forEachChild(sourceFile, visitNode);
  6292. return;
  6293. function visitNode(n) {
  6294. if (n.parent !== parent) {
  6295. n.parent = parent;
  6296. var saveParent = parent;
  6297. parent = n;
  6298. forEachChild(n, visitNode);
  6299. parent = saveParent;
  6300. }
  6301. }
  6302. }
  6303. Parser.fixupParentReferences = fixupParentReferences;
  6304. function createSourceFile(fileName, languageVersion) {
  6305. var sourceFile = createNode(248, 0);
  6306. sourceFile.pos = 0;
  6307. sourceFile.end = sourceText.length;
  6308. sourceFile.text = sourceText;
  6309. sourceFile.bindDiagnostics = [];
  6310. sourceFile.languageVersion = languageVersion;
  6311. sourceFile.fileName = ts.normalizePath(fileName);
  6312. sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 8192 : 0;
  6313. sourceFile.languageVariant = ts.isTsx(sourceFile.fileName) ? 1 : 0;
  6314. return sourceFile;
  6315. }
  6316. function setContextFlag(val, flag) {
  6317. if (val) {
  6318. contextFlags |= flag;
  6319. }
  6320. else {
  6321. contextFlags &= ~flag;
  6322. }
  6323. }
  6324. function setDisallowInContext(val) {
  6325. setContextFlag(val, 1);
  6326. }
  6327. function setYieldContext(val) {
  6328. setContextFlag(val, 2);
  6329. }
  6330. function setDecoratorContext(val) {
  6331. setContextFlag(val, 4);
  6332. }
  6333. function setAwaitContext(val) {
  6334. setContextFlag(val, 8);
  6335. }
  6336. function doOutsideOfContext(context, func) {
  6337. var contextFlagsToClear = context & contextFlags;
  6338. if (contextFlagsToClear) {
  6339. setContextFlag(false, contextFlagsToClear);
  6340. var result = func();
  6341. setContextFlag(true, contextFlagsToClear);
  6342. return result;
  6343. }
  6344. return func();
  6345. }
  6346. function doInsideOfContext(context, func) {
  6347. var contextFlagsToSet = context & ~contextFlags;
  6348. if (contextFlagsToSet) {
  6349. setContextFlag(true, contextFlagsToSet);
  6350. var result = func();
  6351. setContextFlag(false, contextFlagsToSet);
  6352. return result;
  6353. }
  6354. return func();
  6355. }
  6356. function allowInAnd(func) {
  6357. return doOutsideOfContext(1, func);
  6358. }
  6359. function disallowInAnd(func) {
  6360. return doInsideOfContext(1, func);
  6361. }
  6362. function doInYieldContext(func) {
  6363. return doInsideOfContext(2, func);
  6364. }
  6365. function doOutsideOfYieldContext(func) {
  6366. return doOutsideOfContext(2, func);
  6367. }
  6368. function doInDecoratorContext(func) {
  6369. return doInsideOfContext(4, func);
  6370. }
  6371. function doInAwaitContext(func) {
  6372. return doInsideOfContext(8, func);
  6373. }
  6374. function doOutsideOfAwaitContext(func) {
  6375. return doOutsideOfContext(8, func);
  6376. }
  6377. function doInYieldAndAwaitContext(func) {
  6378. return doInsideOfContext(2 | 8, func);
  6379. }
  6380. function doOutsideOfYieldAndAwaitContext(func) {
  6381. return doOutsideOfContext(2 | 8, func);
  6382. }
  6383. function inContext(flags) {
  6384. return (contextFlags & flags) !== 0;
  6385. }
  6386. function inYieldContext() {
  6387. return inContext(2);
  6388. }
  6389. function inDisallowInContext() {
  6390. return inContext(1);
  6391. }
  6392. function inDecoratorContext() {
  6393. return inContext(4);
  6394. }
  6395. function inAwaitContext() {
  6396. return inContext(8);
  6397. }
  6398. function parseErrorAtCurrentToken(message, arg0) {
  6399. var start = scanner.getTokenPos();
  6400. var length = scanner.getTextPos() - start;
  6401. parseErrorAtPosition(start, length, message, arg0);
  6402. }
  6403. function parseErrorAtPosition(start, length, message, arg0) {
  6404. var lastError = ts.lastOrUndefined(parseDiagnostics);
  6405. if (!lastError || start !== lastError.start) {
  6406. parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0));
  6407. }
  6408. parseErrorBeforeNextFinishedNode = true;
  6409. }
  6410. function scanError(message, length) {
  6411. var pos = scanner.getTextPos();
  6412. parseErrorAtPosition(pos, length || 0, message);
  6413. }
  6414. function getNodePos() {
  6415. return scanner.getStartPos();
  6416. }
  6417. function getNodeEnd() {
  6418. return scanner.getStartPos();
  6419. }
  6420. function nextToken() {
  6421. return token = scanner.scan();
  6422. }
  6423. function getTokenPos(pos) {
  6424. return ts.skipTrivia(sourceText, pos);
  6425. }
  6426. function reScanGreaterToken() {
  6427. return token = scanner.reScanGreaterToken();
  6428. }
  6429. function reScanSlashToken() {
  6430. return token = scanner.reScanSlashToken();
  6431. }
  6432. function reScanTemplateToken() {
  6433. return token = scanner.reScanTemplateToken();
  6434. }
  6435. function scanJsxIdentifier() {
  6436. return token = scanner.scanJsxIdentifier();
  6437. }
  6438. function scanJsxText() {
  6439. return token = scanner.scanJsxToken();
  6440. }
  6441. function speculationHelper(callback, isLookAhead) {
  6442. var saveToken = token;
  6443. var saveParseDiagnosticsLength = parseDiagnostics.length;
  6444. var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
  6445. var saveContextFlags = contextFlags;
  6446. var result = isLookAhead
  6447. ? scanner.lookAhead(callback)
  6448. : scanner.tryScan(callback);
  6449. ts.Debug.assert(saveContextFlags === contextFlags);
  6450. if (!result || isLookAhead) {
  6451. token = saveToken;
  6452. parseDiagnostics.length = saveParseDiagnosticsLength;
  6453. parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode;
  6454. }
  6455. return result;
  6456. }
  6457. function lookAhead(callback) {
  6458. return speculationHelper(callback, true);
  6459. }
  6460. function tryParse(callback) {
  6461. return speculationHelper(callback, false);
  6462. }
  6463. function isIdentifier() {
  6464. if (token === 69) {
  6465. return true;
  6466. }
  6467. if (token === 114 && inYieldContext()) {
  6468. return false;
  6469. }
  6470. if (token === 119 && inAwaitContext()) {
  6471. return false;
  6472. }
  6473. return token > 105;
  6474. }
  6475. function parseExpected(kind, diagnosticMessage, shouldAdvance) {
  6476. if (shouldAdvance === void 0) { shouldAdvance = true; }
  6477. if (token === kind) {
  6478. if (shouldAdvance) {
  6479. nextToken();
  6480. }
  6481. return true;
  6482. }
  6483. if (diagnosticMessage) {
  6484. parseErrorAtCurrentToken(diagnosticMessage);
  6485. }
  6486. else {
  6487. parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(kind));
  6488. }
  6489. return false;
  6490. }
  6491. function parseOptional(t) {
  6492. if (token === t) {
  6493. nextToken();
  6494. return true;
  6495. }
  6496. return false;
  6497. }
  6498. function parseOptionalToken(t) {
  6499. if (token === t) {
  6500. return parseTokenNode();
  6501. }
  6502. return undefined;
  6503. }
  6504. function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) {
  6505. return parseOptionalToken(t) ||
  6506. createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0);
  6507. }
  6508. function parseTokenNode() {
  6509. var node = createNode(token);
  6510. nextToken();
  6511. return finishNode(node);
  6512. }
  6513. function canParseSemicolon() {
  6514. if (token === 23) {
  6515. return true;
  6516. }
  6517. return token === 16 || token === 1 || scanner.hasPrecedingLineBreak();
  6518. }
  6519. function parseSemicolon() {
  6520. if (canParseSemicolon()) {
  6521. if (token === 23) {
  6522. nextToken();
  6523. }
  6524. return true;
  6525. }
  6526. else {
  6527. return parseExpected(23);
  6528. }
  6529. }
  6530. function createNode(kind, pos) {
  6531. nodeCount++;
  6532. var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)))();
  6533. if (!(pos >= 0)) {
  6534. pos = scanner.getStartPos();
  6535. }
  6536. node.pos = pos;
  6537. node.end = pos;
  6538. return node;
  6539. }
  6540. function finishNode(node, end) {
  6541. node.end = end === undefined ? scanner.getStartPos() : end;
  6542. if (contextFlags) {
  6543. node.parserContextFlags = contextFlags;
  6544. }
  6545. if (parseErrorBeforeNextFinishedNode) {
  6546. parseErrorBeforeNextFinishedNode = false;
  6547. node.parserContextFlags |= 16;
  6548. }
  6549. return node;
  6550. }
  6551. function createMissingNode(kind, reportAtCurrentPosition, diagnosticMessage, arg0) {
  6552. if (reportAtCurrentPosition) {
  6553. parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
  6554. }
  6555. else {
  6556. parseErrorAtCurrentToken(diagnosticMessage, arg0);
  6557. }
  6558. var result = createNode(kind, scanner.getStartPos());
  6559. result.text = "";
  6560. return finishNode(result);
  6561. }
  6562. function internIdentifier(text) {
  6563. text = ts.escapeIdentifier(text);
  6564. return ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
  6565. }
  6566. function createIdentifier(isIdentifier, diagnosticMessage) {
  6567. identifierCount++;
  6568. if (isIdentifier) {
  6569. var node = createNode(69);
  6570. if (token !== 69) {
  6571. node.originalKeywordKind = token;
  6572. }
  6573. node.text = internIdentifier(scanner.getTokenValue());
  6574. nextToken();
  6575. return finishNode(node);
  6576. }
  6577. return createMissingNode(69, false, diagnosticMessage || ts.Diagnostics.Identifier_expected);
  6578. }
  6579. function parseIdentifier(diagnosticMessage) {
  6580. return createIdentifier(isIdentifier(), diagnosticMessage);
  6581. }
  6582. function parseIdentifierName() {
  6583. return createIdentifier(ts.tokenIsIdentifierOrKeyword(token));
  6584. }
  6585. function isLiteralPropertyName() {
  6586. return ts.tokenIsIdentifierOrKeyword(token) ||
  6587. token === 9 ||
  6588. token === 8;
  6589. }
  6590. function parsePropertyNameWorker(allowComputedPropertyNames) {
  6591. if (token === 9 || token === 8) {
  6592. return parseLiteralNode(true);
  6593. }
  6594. if (allowComputedPropertyNames && token === 19) {
  6595. return parseComputedPropertyName();
  6596. }
  6597. return parseIdentifierName();
  6598. }
  6599. function parsePropertyName() {
  6600. return parsePropertyNameWorker(true);
  6601. }
  6602. function parseSimplePropertyName() {
  6603. return parsePropertyNameWorker(false);
  6604. }
  6605. function isSimplePropertyName() {
  6606. return token === 9 || token === 8 || ts.tokenIsIdentifierOrKeyword(token);
  6607. }
  6608. function parseComputedPropertyName() {
  6609. var node = createNode(136);
  6610. parseExpected(19);
  6611. node.expression = allowInAnd(parseExpression);
  6612. parseExpected(20);
  6613. return finishNode(node);
  6614. }
  6615. function parseContextualModifier(t) {
  6616. return token === t && tryParse(nextTokenCanFollowModifier);
  6617. }
  6618. function nextTokenCanFollowModifier() {
  6619. if (token === 74) {
  6620. return nextToken() === 81;
  6621. }
  6622. if (token === 82) {
  6623. nextToken();
  6624. if (token === 77) {
  6625. return lookAhead(nextTokenIsClassOrFunction);
  6626. }
  6627. return token !== 37 && token !== 15 && canFollowModifier();
  6628. }
  6629. if (token === 77) {
  6630. return nextTokenIsClassOrFunction();
  6631. }
  6632. if (token === 113) {
  6633. nextToken();
  6634. return canFollowModifier();
  6635. }
  6636. nextToken();
  6637. if (scanner.hasPrecedingLineBreak()) {
  6638. return false;
  6639. }
  6640. return canFollowModifier();
  6641. }
  6642. function parseAnyContextualModifier() {
  6643. return ts.isModifier(token) && tryParse(nextTokenCanFollowModifier);
  6644. }
  6645. function canFollowModifier() {
  6646. return token === 19
  6647. || token === 15
  6648. || token === 37
  6649. || isLiteralPropertyName();
  6650. }
  6651. function nextTokenIsClassOrFunction() {
  6652. nextToken();
  6653. return token === 73 || token === 87;
  6654. }
  6655. function isListElement(parsingContext, inErrorRecovery) {
  6656. var node = currentNode(parsingContext);
  6657. if (node) {
  6658. return true;
  6659. }
  6660. switch (parsingContext) {
  6661. case 0:
  6662. case 1:
  6663. case 3:
  6664. return !(token === 23 && inErrorRecovery) && isStartOfStatement();
  6665. case 2:
  6666. return token === 71 || token === 77;
  6667. case 4:
  6668. return isStartOfTypeMember();
  6669. case 5:
  6670. return lookAhead(isClassMemberStart) || (token === 23 && !inErrorRecovery);
  6671. case 6:
  6672. return token === 19 || isLiteralPropertyName();
  6673. case 12:
  6674. return token === 19 || token === 37 || isLiteralPropertyName();
  6675. case 9:
  6676. return isLiteralPropertyName();
  6677. case 7:
  6678. if (token === 15) {
  6679. return lookAhead(isValidHeritageClauseObjectLiteral);
  6680. }
  6681. if (!inErrorRecovery) {
  6682. return isStartOfLeftHandSideExpression() && !isHeritageClauseExtendsOrImplementsKeyword();
  6683. }
  6684. else {
  6685. return isIdentifier() && !isHeritageClauseExtendsOrImplementsKeyword();
  6686. }
  6687. case 8:
  6688. return isIdentifierOrPattern();
  6689. case 10:
  6690. return token === 24 || token === 22 || isIdentifierOrPattern();
  6691. case 17:
  6692. return isIdentifier();
  6693. case 11:
  6694. case 15:
  6695. return token === 24 || token === 22 || isStartOfExpression();
  6696. case 16:
  6697. return isStartOfParameter();
  6698. case 18:
  6699. case 19:
  6700. return token === 24 || isStartOfType();
  6701. case 20:
  6702. return isHeritageClause();
  6703. case 21:
  6704. return ts.tokenIsIdentifierOrKeyword(token);
  6705. case 13:
  6706. return ts.tokenIsIdentifierOrKeyword(token) || token === 15;
  6707. case 14:
  6708. return true;
  6709. case 22:
  6710. case 23:
  6711. case 25:
  6712. return JSDocParser.isJSDocType();
  6713. case 24:
  6714. return isSimplePropertyName();
  6715. }
  6716. ts.Debug.fail("Non-exhaustive case in 'isListElement'.");
  6717. }
  6718. function isValidHeritageClauseObjectLiteral() {
  6719. ts.Debug.assert(token === 15);
  6720. if (nextToken() === 16) {
  6721. var next = nextToken();
  6722. return next === 24 || next === 15 || next === 83 || next === 106;
  6723. }
  6724. return true;
  6725. }
  6726. function nextTokenIsIdentifier() {
  6727. nextToken();
  6728. return isIdentifier();
  6729. }
  6730. function nextTokenIsIdentifierOrKeyword() {
  6731. nextToken();
  6732. return ts.tokenIsIdentifierOrKeyword(token);
  6733. }
  6734. function isHeritageClauseExtendsOrImplementsKeyword() {
  6735. if (token === 106 ||
  6736. token === 83) {
  6737. return lookAhead(nextTokenIsStartOfExpression);
  6738. }
  6739. return false;
  6740. }
  6741. function nextTokenIsStartOfExpression() {
  6742. nextToken();
  6743. return isStartOfExpression();
  6744. }
  6745. function isListTerminator(kind) {
  6746. if (token === 1) {
  6747. return true;
  6748. }
  6749. switch (kind) {
  6750. case 1:
  6751. case 2:
  6752. case 4:
  6753. case 5:
  6754. case 6:
  6755. case 12:
  6756. case 9:
  6757. case 21:
  6758. return token === 16;
  6759. case 3:
  6760. return token === 16 || token === 71 || token === 77;
  6761. case 7:
  6762. return token === 15 || token === 83 || token === 106;
  6763. case 8:
  6764. return isVariableDeclaratorListTerminator();
  6765. case 17:
  6766. return token === 27 || token === 17 || token === 15 || token === 83 || token === 106;
  6767. case 11:
  6768. return token === 18 || token === 23;
  6769. case 15:
  6770. case 19:
  6771. case 10:
  6772. return token === 20;
  6773. case 16:
  6774. return token === 18 || token === 20;
  6775. case 18:
  6776. return token === 27 || token === 17;
  6777. case 20:
  6778. return token === 15 || token === 16;
  6779. case 13:
  6780. return token === 27 || token === 39;
  6781. case 14:
  6782. return token === 25 && lookAhead(nextTokenIsSlash);
  6783. case 22:
  6784. return token === 18 || token === 54 || token === 16;
  6785. case 23:
  6786. return token === 27 || token === 16;
  6787. case 25:
  6788. return token === 20 || token === 16;
  6789. case 24:
  6790. return token === 16;
  6791. }
  6792. }
  6793. function isVariableDeclaratorListTerminator() {
  6794. if (canParseSemicolon()) {
  6795. return true;
  6796. }
  6797. if (isInOrOfKeyword(token)) {
  6798. return true;
  6799. }
  6800. if (token === 34) {
  6801. return true;
  6802. }
  6803. return false;
  6804. }
  6805. function isInSomeParsingContext() {
  6806. for (var kind = 0; kind < 26; kind++) {
  6807. if (parsingContext & (1 << kind)) {
  6808. if (isListElement(kind, true) || isListTerminator(kind)) {
  6809. return true;
  6810. }
  6811. }
  6812. }
  6813. return false;
  6814. }
  6815. function parseList(kind, parseElement) {
  6816. var saveParsingContext = parsingContext;
  6817. parsingContext |= 1 << kind;
  6818. var result = [];
  6819. result.pos = getNodePos();
  6820. while (!isListTerminator(kind)) {
  6821. if (isListElement(kind, false)) {
  6822. var element = parseListElement(kind, parseElement);
  6823. result.push(element);
  6824. continue;
  6825. }
  6826. if (abortParsingListOrMoveToNextToken(kind)) {
  6827. break;
  6828. }
  6829. }
  6830. result.end = getNodeEnd();
  6831. parsingContext = saveParsingContext;
  6832. return result;
  6833. }
  6834. function parseListElement(parsingContext, parseElement) {
  6835. var node = currentNode(parsingContext);
  6836. if (node) {
  6837. return consumeNode(node);
  6838. }
  6839. return parseElement();
  6840. }
  6841. function currentNode(parsingContext) {
  6842. if (parseErrorBeforeNextFinishedNode) {
  6843. return undefined;
  6844. }
  6845. if (!syntaxCursor) {
  6846. return undefined;
  6847. }
  6848. var node = syntaxCursor.currentNode(scanner.getStartPos());
  6849. if (ts.nodeIsMissing(node)) {
  6850. return undefined;
  6851. }
  6852. if (node.intersectsChange) {
  6853. return undefined;
  6854. }
  6855. if (ts.containsParseError(node)) {
  6856. return undefined;
  6857. }
  6858. var nodeContextFlags = node.parserContextFlags & 31;
  6859. if (nodeContextFlags !== contextFlags) {
  6860. return undefined;
  6861. }
  6862. if (!canReuseNode(node, parsingContext)) {
  6863. return undefined;
  6864. }
  6865. return node;
  6866. }
  6867. function consumeNode(node) {
  6868. scanner.setTextPos(node.end);
  6869. nextToken();
  6870. return node;
  6871. }
  6872. function canReuseNode(node, parsingContext) {
  6873. switch (parsingContext) {
  6874. case 5:
  6875. return isReusableClassMember(node);
  6876. case 2:
  6877. return isReusableSwitchClause(node);
  6878. case 0:
  6879. case 1:
  6880. case 3:
  6881. return isReusableStatement(node);
  6882. case 6:
  6883. return isReusableEnumMember(node);
  6884. case 4:
  6885. return isReusableTypeMember(node);
  6886. case 8:
  6887. return isReusableVariableDeclaration(node);
  6888. case 16:
  6889. return isReusableParameter(node);
  6890. case 20:
  6891. case 17:
  6892. case 19:
  6893. case 18:
  6894. case 11:
  6895. case 12:
  6896. case 7:
  6897. case 13:
  6898. case 14:
  6899. }
  6900. return false;
  6901. }
  6902. function isReusableClassMember(node) {
  6903. if (node) {
  6904. switch (node.kind) {
  6905. case 144:
  6906. case 149:
  6907. case 145:
  6908. case 146:
  6909. case 141:
  6910. case 191:
  6911. return true;
  6912. case 143:
  6913. var methodDeclaration = node;
  6914. var nameIsConstructor = methodDeclaration.name.kind === 69 &&
  6915. methodDeclaration.name.originalKeywordKind === 121;
  6916. return !nameIsConstructor;
  6917. }
  6918. }
  6919. return false;
  6920. }
  6921. function isReusableSwitchClause(node) {
  6922. if (node) {
  6923. switch (node.kind) {
  6924. case 241:
  6925. case 242:
  6926. return true;
  6927. }
  6928. }
  6929. return false;
  6930. }
  6931. function isReusableStatement(node) {
  6932. if (node) {
  6933. switch (node.kind) {
  6934. case 213:
  6935. case 193:
  6936. case 192:
  6937. case 196:
  6938. case 195:
  6939. case 208:
  6940. case 204:
  6941. case 206:
  6942. case 203:
  6943. case 202:
  6944. case 200:
  6945. case 201:
  6946. case 199:
  6947. case 198:
  6948. case 205:
  6949. case 194:
  6950. case 209:
  6951. case 207:
  6952. case 197:
  6953. case 210:
  6954. case 222:
  6955. case 221:
  6956. case 228:
  6957. case 227:
  6958. case 218:
  6959. case 214:
  6960. case 215:
  6961. case 217:
  6962. case 216:
  6963. return true;
  6964. }
  6965. }
  6966. return false;
  6967. }
  6968. function isReusableEnumMember(node) {
  6969. return node.kind === 247;
  6970. }
  6971. function isReusableTypeMember(node) {
  6972. if (node) {
  6973. switch (node.kind) {
  6974. case 148:
  6975. case 142:
  6976. case 149:
  6977. case 140:
  6978. case 147:
  6979. return true;
  6980. }
  6981. }
  6982. return false;
  6983. }
  6984. function isReusableVariableDeclaration(node) {
  6985. if (node.kind !== 211) {
  6986. return false;
  6987. }
  6988. var variableDeclarator = node;
  6989. return variableDeclarator.initializer === undefined;
  6990. }
  6991. function isReusableParameter(node) {
  6992. if (node.kind !== 138) {
  6993. return false;
  6994. }
  6995. var parameter = node;
  6996. return parameter.initializer === undefined;
  6997. }
  6998. function abortParsingListOrMoveToNextToken(kind) {
  6999. parseErrorAtCurrentToken(parsingContextErrors(kind));
  7000. if (isInSomeParsingContext()) {
  7001. return true;
  7002. }
  7003. nextToken();
  7004. return false;
  7005. }
  7006. function parsingContextErrors(context) {
  7007. switch (context) {
  7008. case 0: return ts.Diagnostics.Declaration_or_statement_expected;
  7009. case 1: return ts.Diagnostics.Declaration_or_statement_expected;
  7010. case 2: return ts.Diagnostics.case_or_default_expected;
  7011. case 3: return ts.Diagnostics.Statement_expected;
  7012. case 4: return ts.Diagnostics.Property_or_signature_expected;
  7013. case 5: return ts.Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected;
  7014. case 6: return ts.Diagnostics.Enum_member_expected;
  7015. case 7: return ts.Diagnostics.Expression_expected;
  7016. case 8: return ts.Diagnostics.Variable_declaration_expected;
  7017. case 9: return ts.Diagnostics.Property_destructuring_pattern_expected;
  7018. case 10: return ts.Diagnostics.Array_element_destructuring_pattern_expected;
  7019. case 11: return ts.Diagnostics.Argument_expression_expected;
  7020. case 12: return ts.Diagnostics.Property_assignment_expected;
  7021. case 15: return ts.Diagnostics.Expression_or_comma_expected;
  7022. case 16: return ts.Diagnostics.Parameter_declaration_expected;
  7023. case 17: return ts.Diagnostics.Type_parameter_declaration_expected;
  7024. case 18: return ts.Diagnostics.Type_argument_expected;
  7025. case 19: return ts.Diagnostics.Type_expected;
  7026. case 20: return ts.Diagnostics.Unexpected_token_expected;
  7027. case 21: return ts.Diagnostics.Identifier_expected;
  7028. case 13: return ts.Diagnostics.Identifier_expected;
  7029. case 14: return ts.Diagnostics.Identifier_expected;
  7030. case 22: return ts.Diagnostics.Parameter_declaration_expected;
  7031. case 23: return ts.Diagnostics.Type_argument_expected;
  7032. case 25: return ts.Diagnostics.Type_expected;
  7033. case 24: return ts.Diagnostics.Property_assignment_expected;
  7034. }
  7035. }
  7036. ;
  7037. function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimeter) {
  7038. var saveParsingContext = parsingContext;
  7039. parsingContext |= 1 << kind;
  7040. var result = [];
  7041. result.pos = getNodePos();
  7042. var commaStart = -1;
  7043. while (true) {
  7044. if (isListElement(kind, false)) {
  7045. result.push(parseListElement(kind, parseElement));
  7046. commaStart = scanner.getTokenPos();
  7047. if (parseOptional(24)) {
  7048. continue;
  7049. }
  7050. commaStart = -1;
  7051. if (isListTerminator(kind)) {
  7052. break;
  7053. }
  7054. parseExpected(24);
  7055. if (considerSemicolonAsDelimeter && token === 23 && !scanner.hasPrecedingLineBreak()) {
  7056. nextToken();
  7057. }
  7058. continue;
  7059. }
  7060. if (isListTerminator(kind)) {
  7061. break;
  7062. }
  7063. if (abortParsingListOrMoveToNextToken(kind)) {
  7064. break;
  7065. }
  7066. }
  7067. if (commaStart >= 0) {
  7068. result.hasTrailingComma = true;
  7069. }
  7070. result.end = getNodeEnd();
  7071. parsingContext = saveParsingContext;
  7072. return result;
  7073. }
  7074. function createMissingList() {
  7075. var pos = getNodePos();
  7076. var result = [];
  7077. result.pos = pos;
  7078. result.end = pos;
  7079. return result;
  7080. }
  7081. function parseBracketedList(kind, parseElement, open, close) {
  7082. if (parseExpected(open)) {
  7083. var result = parseDelimitedList(kind, parseElement);
  7084. parseExpected(close);
  7085. return result;
  7086. }
  7087. return createMissingList();
  7088. }
  7089. function parseEntityName(allowReservedWords, diagnosticMessage) {
  7090. var entity = parseIdentifier(diagnosticMessage);
  7091. while (parseOptional(21)) {
  7092. var node = createNode(135, entity.pos);
  7093. node.left = entity;
  7094. node.right = parseRightSideOfDot(allowReservedWords);
  7095. entity = finishNode(node);
  7096. }
  7097. return entity;
  7098. }
  7099. function parseRightSideOfDot(allowIdentifierNames) {
  7100. if (scanner.hasPrecedingLineBreak() && ts.tokenIsIdentifierOrKeyword(token)) {
  7101. var matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
  7102. if (matchesPattern) {
  7103. return createMissingNode(69, true, ts.Diagnostics.Identifier_expected);
  7104. }
  7105. }
  7106. return allowIdentifierNames ? parseIdentifierName() : parseIdentifier();
  7107. }
  7108. function parseTemplateExpression() {
  7109. var template = createNode(183);
  7110. template.head = parseLiteralNode();
  7111. ts.Debug.assert(template.head.kind === 12, "Template head has wrong token kind");
  7112. var templateSpans = [];
  7113. templateSpans.pos = getNodePos();
  7114. do {
  7115. templateSpans.push(parseTemplateSpan());
  7116. } while (ts.lastOrUndefined(templateSpans).literal.kind === 13);
  7117. templateSpans.end = getNodeEnd();
  7118. template.templateSpans = templateSpans;
  7119. return finishNode(template);
  7120. }
  7121. function parseTemplateSpan() {
  7122. var span = createNode(190);
  7123. span.expression = allowInAnd(parseExpression);
  7124. var literal;
  7125. if (token === 16) {
  7126. reScanTemplateToken();
  7127. literal = parseLiteralNode();
  7128. }
  7129. else {
  7130. literal = parseExpectedToken(14, false, ts.Diagnostics._0_expected, ts.tokenToString(16));
  7131. }
  7132. span.literal = literal;
  7133. return finishNode(span);
  7134. }
  7135. function parseLiteralNode(internName) {
  7136. var node = createNode(token);
  7137. var text = scanner.getTokenValue();
  7138. node.text = internName ? internIdentifier(text) : text;
  7139. if (scanner.hasExtendedUnicodeEscape()) {
  7140. node.hasExtendedUnicodeEscape = true;
  7141. }
  7142. if (scanner.isUnterminated()) {
  7143. node.isUnterminated = true;
  7144. }
  7145. var tokenPos = scanner.getTokenPos();
  7146. nextToken();
  7147. finishNode(node);
  7148. if (node.kind === 8
  7149. && sourceText.charCodeAt(tokenPos) === 48
  7150. && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
  7151. node.flags |= 65536;
  7152. }
  7153. return node;
  7154. }
  7155. function parseTypeReferenceOrTypePredicate() {
  7156. var typeName = parseEntityName(false, ts.Diagnostics.Type_expected);
  7157. if (typeName.kind === 69 && token === 124 && !scanner.hasPrecedingLineBreak()) {
  7158. nextToken();
  7159. var node_1 = createNode(150, typeName.pos);
  7160. node_1.parameterName = typeName;
  7161. node_1.type = parseType();
  7162. return finishNode(node_1);
  7163. }
  7164. var node = createNode(151, typeName.pos);
  7165. node.typeName = typeName;
  7166. if (!scanner.hasPrecedingLineBreak() && token === 25) {
  7167. node.typeArguments = parseBracketedList(18, parseType, 25, 27);
  7168. }
  7169. return finishNode(node);
  7170. }
  7171. function parseTypeQuery() {
  7172. var node = createNode(154);
  7173. parseExpected(101);
  7174. node.exprName = parseEntityName(true);
  7175. return finishNode(node);
  7176. }
  7177. function parseTypeParameter() {
  7178. var node = createNode(137);
  7179. node.name = parseIdentifier();
  7180. if (parseOptional(83)) {
  7181. if (isStartOfType() || !isStartOfExpression()) {
  7182. node.constraint = parseType();
  7183. }
  7184. else {
  7185. node.expression = parseUnaryExpressionOrHigher();
  7186. }
  7187. }
  7188. return finishNode(node);
  7189. }
  7190. function parseTypeParameters() {
  7191. if (token === 25) {
  7192. return parseBracketedList(17, parseTypeParameter, 25, 27);
  7193. }
  7194. }
  7195. function parseParameterType() {
  7196. if (parseOptional(54)) {
  7197. return token === 9
  7198. ? parseLiteralNode(true)
  7199. : parseType();
  7200. }
  7201. return undefined;
  7202. }
  7203. function isStartOfParameter() {
  7204. return token === 22 || isIdentifierOrPattern() || ts.isModifier(token) || token === 55;
  7205. }
  7206. function setModifiers(node, modifiers) {
  7207. if (modifiers) {
  7208. node.flags |= modifiers.flags;
  7209. node.modifiers = modifiers;
  7210. }
  7211. }
  7212. function parseParameter() {
  7213. var node = createNode(138);
  7214. node.decorators = parseDecorators();
  7215. setModifiers(node, parseModifiers());
  7216. node.dotDotDotToken = parseOptionalToken(22);
  7217. node.name = parseIdentifierOrPattern();
  7218. if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(token)) {
  7219. nextToken();
  7220. }
  7221. node.questionToken = parseOptionalToken(53);
  7222. node.type = parseParameterType();
  7223. node.initializer = parseBindingElementInitializer(true);
  7224. return finishNode(node);
  7225. }
  7226. function parseBindingElementInitializer(inParameter) {
  7227. return inParameter ? parseParameterInitializer() : parseNonParameterInitializer();
  7228. }
  7229. function parseParameterInitializer() {
  7230. return parseInitializer(true);
  7231. }
  7232. function fillSignature(returnToken, yieldContext, awaitContext, requireCompleteParameterList, signature) {
  7233. var returnTokenRequired = returnToken === 34;
  7234. signature.typeParameters = parseTypeParameters();
  7235. signature.parameters = parseParameterList(yieldContext, awaitContext, requireCompleteParameterList);
  7236. if (returnTokenRequired) {
  7237. parseExpected(returnToken);
  7238. signature.type = parseType();
  7239. }
  7240. else if (parseOptional(returnToken)) {
  7241. signature.type = parseType();
  7242. }
  7243. }
  7244. function parseParameterList(yieldContext, awaitContext, requireCompleteParameterList) {
  7245. if (parseExpected(17)) {
  7246. var savedYieldContext = inYieldContext();
  7247. var savedAwaitContext = inAwaitContext();
  7248. setYieldContext(yieldContext);
  7249. setAwaitContext(awaitContext);
  7250. var result = parseDelimitedList(16, parseParameter);
  7251. setYieldContext(savedYieldContext);
  7252. setAwaitContext(savedAwaitContext);
  7253. if (!parseExpected(18) && requireCompleteParameterList) {
  7254. return undefined;
  7255. }
  7256. return result;
  7257. }
  7258. return requireCompleteParameterList ? undefined : createMissingList();
  7259. }
  7260. function parseTypeMemberSemicolon() {
  7261. if (parseOptional(24)) {
  7262. return;
  7263. }
  7264. parseSemicolon();
  7265. }
  7266. function parseSignatureMember(kind) {
  7267. var node = createNode(kind);
  7268. if (kind === 148) {
  7269. parseExpected(92);
  7270. }
  7271. fillSignature(54, false, false, false, node);
  7272. parseTypeMemberSemicolon();
  7273. return finishNode(node);
  7274. }
  7275. function isIndexSignature() {
  7276. if (token !== 19) {
  7277. return false;
  7278. }
  7279. return lookAhead(isUnambiguouslyIndexSignature);
  7280. }
  7281. function isUnambiguouslyIndexSignature() {
  7282. nextToken();
  7283. if (token === 22 || token === 20) {
  7284. return true;
  7285. }
  7286. if (ts.isModifier(token)) {
  7287. nextToken();
  7288. if (isIdentifier()) {
  7289. return true;
  7290. }
  7291. }
  7292. else if (!isIdentifier()) {
  7293. return false;
  7294. }
  7295. else {
  7296. nextToken();
  7297. }
  7298. if (token === 54 || token === 24) {
  7299. return true;
  7300. }
  7301. if (token !== 53) {
  7302. return false;
  7303. }
  7304. nextToken();
  7305. return token === 54 || token === 24 || token === 20;
  7306. }
  7307. function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) {
  7308. var node = createNode(149, fullStart);
  7309. node.decorators = decorators;
  7310. setModifiers(node, modifiers);
  7311. node.parameters = parseBracketedList(16, parseParameter, 19, 20);
  7312. node.type = parseTypeAnnotation();
  7313. parseTypeMemberSemicolon();
  7314. return finishNode(node);
  7315. }
  7316. function parsePropertyOrMethodSignature() {
  7317. var fullStart = scanner.getStartPos();
  7318. var name = parsePropertyName();
  7319. var questionToken = parseOptionalToken(53);
  7320. if (token === 17 || token === 25) {
  7321. var method = createNode(142, fullStart);
  7322. method.name = name;
  7323. method.questionToken = questionToken;
  7324. fillSignature(54, false, false, false, method);
  7325. parseTypeMemberSemicolon();
  7326. return finishNode(method);
  7327. }
  7328. else {
  7329. var property = createNode(140, fullStart);
  7330. property.name = name;
  7331. property.questionToken = questionToken;
  7332. property.type = parseTypeAnnotation();
  7333. parseTypeMemberSemicolon();
  7334. return finishNode(property);
  7335. }
  7336. }
  7337. function isStartOfTypeMember() {
  7338. switch (token) {
  7339. case 17:
  7340. case 25:
  7341. case 19:
  7342. return true;
  7343. default:
  7344. if (ts.isModifier(token)) {
  7345. var result = lookAhead(isStartOfIndexSignatureDeclaration);
  7346. if (result) {
  7347. return result;
  7348. }
  7349. }
  7350. return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName);
  7351. }
  7352. }
  7353. function isStartOfIndexSignatureDeclaration() {
  7354. while (ts.isModifier(token)) {
  7355. nextToken();
  7356. }
  7357. return isIndexSignature();
  7358. }
  7359. function isTypeMemberWithLiteralPropertyName() {
  7360. nextToken();
  7361. return token === 17 ||
  7362. token === 25 ||
  7363. token === 53 ||
  7364. token === 54 ||
  7365. canParseSemicolon();
  7366. }
  7367. function parseTypeMember() {
  7368. switch (token) {
  7369. case 17:
  7370. case 25:
  7371. return parseSignatureMember(147);
  7372. case 19:
  7373. return isIndexSignature()
  7374. ? parseIndexSignatureDeclaration(scanner.getStartPos(), undefined, undefined)
  7375. : parsePropertyOrMethodSignature();
  7376. case 92:
  7377. if (lookAhead(isStartOfConstructSignature)) {
  7378. return parseSignatureMember(148);
  7379. }
  7380. case 9:
  7381. case 8:
  7382. return parsePropertyOrMethodSignature();
  7383. default:
  7384. if (ts.isModifier(token)) {
  7385. var result = tryParse(parseIndexSignatureWithModifiers);
  7386. if (result) {
  7387. return result;
  7388. }
  7389. }
  7390. if (ts.tokenIsIdentifierOrKeyword(token)) {
  7391. return parsePropertyOrMethodSignature();
  7392. }
  7393. }
  7394. }
  7395. function parseIndexSignatureWithModifiers() {
  7396. var fullStart = scanner.getStartPos();
  7397. var decorators = parseDecorators();
  7398. var modifiers = parseModifiers();
  7399. return isIndexSignature()
  7400. ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers)
  7401. : undefined;
  7402. }
  7403. function isStartOfConstructSignature() {
  7404. nextToken();
  7405. return token === 17 || token === 25;
  7406. }
  7407. function parseTypeLiteral() {
  7408. var node = createNode(155);
  7409. node.members = parseObjectTypeMembers();
  7410. return finishNode(node);
  7411. }
  7412. function parseObjectTypeMembers() {
  7413. var members;
  7414. if (parseExpected(15)) {
  7415. members = parseList(4, parseTypeMember);
  7416. parseExpected(16);
  7417. }
  7418. else {
  7419. members = createMissingList();
  7420. }
  7421. return members;
  7422. }
  7423. function parseTupleType() {
  7424. var node = createNode(157);
  7425. node.elementTypes = parseBracketedList(19, parseType, 19, 20);
  7426. return finishNode(node);
  7427. }
  7428. function parseParenthesizedType() {
  7429. var node = createNode(160);
  7430. parseExpected(17);
  7431. node.type = parseType();
  7432. parseExpected(18);
  7433. return finishNode(node);
  7434. }
  7435. function parseFunctionOrConstructorType(kind) {
  7436. var node = createNode(kind);
  7437. if (kind === 153) {
  7438. parseExpected(92);
  7439. }
  7440. fillSignature(34, false, false, false, node);
  7441. return finishNode(node);
  7442. }
  7443. function parseKeywordAndNoDot() {
  7444. var node = parseTokenNode();
  7445. return token === 21 ? undefined : node;
  7446. }
  7447. function parseNonArrayType() {
  7448. switch (token) {
  7449. case 117:
  7450. case 130:
  7451. case 128:
  7452. case 120:
  7453. case 131:
  7454. var node = tryParse(parseKeywordAndNoDot);
  7455. return node || parseTypeReferenceOrTypePredicate();
  7456. case 103:
  7457. case 97:
  7458. return parseTokenNode();
  7459. case 101:
  7460. return parseTypeQuery();
  7461. case 15:
  7462. return parseTypeLiteral();
  7463. case 19:
  7464. return parseTupleType();
  7465. case 17:
  7466. return parseParenthesizedType();
  7467. default:
  7468. return parseTypeReferenceOrTypePredicate();
  7469. }
  7470. }
  7471. function isStartOfType() {
  7472. switch (token) {
  7473. case 117:
  7474. case 130:
  7475. case 128:
  7476. case 120:
  7477. case 131:
  7478. case 103:
  7479. case 97:
  7480. case 101:
  7481. case 15:
  7482. case 19:
  7483. case 25:
  7484. case 92:
  7485. return true;
  7486. case 17:
  7487. return lookAhead(isStartOfParenthesizedOrFunctionType);
  7488. default:
  7489. return isIdentifier();
  7490. }
  7491. }
  7492. function isStartOfParenthesizedOrFunctionType() {
  7493. nextToken();
  7494. return token === 18 || isStartOfParameter() || isStartOfType();
  7495. }
  7496. function parseArrayTypeOrHigher() {
  7497. var type = parseNonArrayType();
  7498. while (!scanner.hasPrecedingLineBreak() && parseOptional(19)) {
  7499. parseExpected(20);
  7500. var node = createNode(156, type.pos);
  7501. node.elementType = type;
  7502. type = finishNode(node);
  7503. }
  7504. return type;
  7505. }
  7506. function parseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  7507. var type = parseConstituentType();
  7508. if (token === operator) {
  7509. var types = [type];
  7510. types.pos = type.pos;
  7511. while (parseOptional(operator)) {
  7512. types.push(parseConstituentType());
  7513. }
  7514. types.end = getNodeEnd();
  7515. var node = createNode(kind, type.pos);
  7516. node.types = types;
  7517. type = finishNode(node);
  7518. }
  7519. return type;
  7520. }
  7521. function parseIntersectionTypeOrHigher() {
  7522. return parseUnionOrIntersectionType(159, parseArrayTypeOrHigher, 46);
  7523. }
  7524. function parseUnionTypeOrHigher() {
  7525. return parseUnionOrIntersectionType(158, parseIntersectionTypeOrHigher, 47);
  7526. }
  7527. function isStartOfFunctionType() {
  7528. if (token === 25) {
  7529. return true;
  7530. }
  7531. return token === 17 && lookAhead(isUnambiguouslyStartOfFunctionType);
  7532. }
  7533. function isUnambiguouslyStartOfFunctionType() {
  7534. nextToken();
  7535. if (token === 18 || token === 22) {
  7536. return true;
  7537. }
  7538. if (isIdentifier() || ts.isModifier(token)) {
  7539. nextToken();
  7540. if (token === 54 || token === 24 ||
  7541. token === 53 || token === 56 ||
  7542. isIdentifier() || ts.isModifier(token)) {
  7543. return true;
  7544. }
  7545. if (token === 18) {
  7546. nextToken();
  7547. if (token === 34) {
  7548. return true;
  7549. }
  7550. }
  7551. }
  7552. return false;
  7553. }
  7554. function parseType() {
  7555. return doOutsideOfContext(10, parseTypeWorker);
  7556. }
  7557. function parseTypeWorker() {
  7558. if (isStartOfFunctionType()) {
  7559. return parseFunctionOrConstructorType(152);
  7560. }
  7561. if (token === 92) {
  7562. return parseFunctionOrConstructorType(153);
  7563. }
  7564. return parseUnionTypeOrHigher();
  7565. }
  7566. function parseTypeAnnotation() {
  7567. return parseOptional(54) ? parseType() : undefined;
  7568. }
  7569. function isStartOfLeftHandSideExpression() {
  7570. switch (token) {
  7571. case 97:
  7572. case 95:
  7573. case 93:
  7574. case 99:
  7575. case 84:
  7576. case 8:
  7577. case 9:
  7578. case 11:
  7579. case 12:
  7580. case 17:
  7581. case 19:
  7582. case 15:
  7583. case 87:
  7584. case 73:
  7585. case 92:
  7586. case 39:
  7587. case 61:
  7588. case 69:
  7589. return true;
  7590. default:
  7591. return isIdentifier();
  7592. }
  7593. }
  7594. function isStartOfExpression() {
  7595. if (isStartOfLeftHandSideExpression()) {
  7596. return true;
  7597. }
  7598. switch (token) {
  7599. case 35:
  7600. case 36:
  7601. case 50:
  7602. case 49:
  7603. case 78:
  7604. case 101:
  7605. case 103:
  7606. case 41:
  7607. case 42:
  7608. case 25:
  7609. case 119:
  7610. case 114:
  7611. return true;
  7612. default:
  7613. if (isBinaryOperator()) {
  7614. return true;
  7615. }
  7616. return isIdentifier();
  7617. }
  7618. }
  7619. function isStartOfExpressionStatement() {
  7620. return token !== 15 &&
  7621. token !== 87 &&
  7622. token !== 73 &&
  7623. token !== 55 &&
  7624. isStartOfExpression();
  7625. }
  7626. function allowInAndParseExpression() {
  7627. return allowInAnd(parseExpression);
  7628. }
  7629. function parseExpression() {
  7630. var saveDecoratorContext = inDecoratorContext();
  7631. if (saveDecoratorContext) {
  7632. setDecoratorContext(false);
  7633. }
  7634. var expr = parseAssignmentExpressionOrHigher();
  7635. var operatorToken;
  7636. while ((operatorToken = parseOptionalToken(24))) {
  7637. expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher());
  7638. }
  7639. if (saveDecoratorContext) {
  7640. setDecoratorContext(true);
  7641. }
  7642. return expr;
  7643. }
  7644. function parseInitializer(inParameter) {
  7645. if (token !== 56) {
  7646. if (scanner.hasPrecedingLineBreak() || (inParameter && token === 15) || !isStartOfExpression()) {
  7647. return undefined;
  7648. }
  7649. }
  7650. parseExpected(56);
  7651. return parseAssignmentExpressionOrHigher();
  7652. }
  7653. function parseAssignmentExpressionOrHigher() {
  7654. if (isYieldExpression()) {
  7655. return parseYieldExpression();
  7656. }
  7657. var arrowExpression = tryParseParenthesizedArrowFunctionExpression();
  7658. if (arrowExpression) {
  7659. return arrowExpression;
  7660. }
  7661. var expr = parseBinaryExpressionOrHigher(0);
  7662. if (expr.kind === 69 && token === 34) {
  7663. return parseSimpleArrowFunctionExpression(expr);
  7664. }
  7665. if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
  7666. return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher());
  7667. }
  7668. return parseConditionalExpressionRest(expr);
  7669. }
  7670. function isYieldExpression() {
  7671. if (token === 114) {
  7672. if (inYieldContext()) {
  7673. return true;
  7674. }
  7675. return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine);
  7676. }
  7677. return false;
  7678. }
  7679. function nextTokenIsIdentifierOnSameLine() {
  7680. nextToken();
  7681. return !scanner.hasPrecedingLineBreak() && isIdentifier();
  7682. }
  7683. function parseYieldExpression() {
  7684. var node = createNode(184);
  7685. nextToken();
  7686. if (!scanner.hasPrecedingLineBreak() &&
  7687. (token === 37 || isStartOfExpression())) {
  7688. node.asteriskToken = parseOptionalToken(37);
  7689. node.expression = parseAssignmentExpressionOrHigher();
  7690. return finishNode(node);
  7691. }
  7692. else {
  7693. return finishNode(node);
  7694. }
  7695. }
  7696. function parseSimpleArrowFunctionExpression(identifier) {
  7697. ts.Debug.assert(token === 34, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
  7698. var node = createNode(174, identifier.pos);
  7699. var parameter = createNode(138, identifier.pos);
  7700. parameter.name = identifier;
  7701. finishNode(parameter);
  7702. node.parameters = [parameter];
  7703. node.parameters.pos = parameter.pos;
  7704. node.parameters.end = parameter.end;
  7705. node.equalsGreaterThanToken = parseExpectedToken(34, false, ts.Diagnostics._0_expected, "=>");
  7706. node.body = parseArrowFunctionExpressionBody(false);
  7707. return finishNode(node);
  7708. }
  7709. function tryParseParenthesizedArrowFunctionExpression() {
  7710. var triState = isParenthesizedArrowFunctionExpression();
  7711. if (triState === 0) {
  7712. return undefined;
  7713. }
  7714. var arrowFunction = triState === 1
  7715. ? parseParenthesizedArrowFunctionExpressionHead(true)
  7716. : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead);
  7717. if (!arrowFunction) {
  7718. return undefined;
  7719. }
  7720. var isAsync = !!(arrowFunction.flags & 512);
  7721. var lastToken = token;
  7722. arrowFunction.equalsGreaterThanToken = parseExpectedToken(34, false, ts.Diagnostics._0_expected, "=>");
  7723. arrowFunction.body = (lastToken === 34 || lastToken === 15)
  7724. ? parseArrowFunctionExpressionBody(isAsync)
  7725. : parseIdentifier();
  7726. return finishNode(arrowFunction);
  7727. }
  7728. function isParenthesizedArrowFunctionExpression() {
  7729. if (token === 17 || token === 25 || token === 118) {
  7730. return lookAhead(isParenthesizedArrowFunctionExpressionWorker);
  7731. }
  7732. if (token === 34) {
  7733. return 1;
  7734. }
  7735. return 0;
  7736. }
  7737. function isParenthesizedArrowFunctionExpressionWorker() {
  7738. if (token === 118) {
  7739. nextToken();
  7740. if (scanner.hasPrecedingLineBreak()) {
  7741. return 0;
  7742. }
  7743. if (token !== 17 && token !== 25) {
  7744. return 0;
  7745. }
  7746. }
  7747. var first = token;
  7748. var second = nextToken();
  7749. if (first === 17) {
  7750. if (second === 18) {
  7751. var third = nextToken();
  7752. switch (third) {
  7753. case 34:
  7754. case 54:
  7755. case 15:
  7756. return 1;
  7757. default:
  7758. return 0;
  7759. }
  7760. }
  7761. if (second === 19 || second === 15) {
  7762. return 2;
  7763. }
  7764. if (second === 22) {
  7765. return 1;
  7766. }
  7767. if (!isIdentifier()) {
  7768. return 0;
  7769. }
  7770. if (nextToken() === 54) {
  7771. return 1;
  7772. }
  7773. return 2;
  7774. }
  7775. else {
  7776. ts.Debug.assert(first === 25);
  7777. if (!isIdentifier()) {
  7778. return 0;
  7779. }
  7780. if (sourceFile.languageVariant === 1) {
  7781. var isArrowFunctionInJsx = lookAhead(function () {
  7782. var third = nextToken();
  7783. if (third === 83) {
  7784. var fourth = nextToken();
  7785. switch (fourth) {
  7786. case 56:
  7787. case 27:
  7788. return false;
  7789. default:
  7790. return true;
  7791. }
  7792. }
  7793. else if (third === 24) {
  7794. return true;
  7795. }
  7796. return false;
  7797. });
  7798. if (isArrowFunctionInJsx) {
  7799. return 1;
  7800. }
  7801. return 0;
  7802. }
  7803. return 2;
  7804. }
  7805. }
  7806. function parsePossibleParenthesizedArrowFunctionExpressionHead() {
  7807. return parseParenthesizedArrowFunctionExpressionHead(false);
  7808. }
  7809. function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) {
  7810. var node = createNode(174);
  7811. setModifiers(node, parseModifiersForArrowFunction());
  7812. var isAsync = !!(node.flags & 512);
  7813. fillSignature(54, false, isAsync, !allowAmbiguity, node);
  7814. if (!node.parameters) {
  7815. return undefined;
  7816. }
  7817. if (!allowAmbiguity && token !== 34 && token !== 15) {
  7818. return undefined;
  7819. }
  7820. return node;
  7821. }
  7822. function parseArrowFunctionExpressionBody(isAsync) {
  7823. if (token === 15) {
  7824. return parseFunctionBlock(false, isAsync, false);
  7825. }
  7826. if (token !== 23 &&
  7827. token !== 87 &&
  7828. token !== 73 &&
  7829. isStartOfStatement() &&
  7830. !isStartOfExpressionStatement()) {
  7831. return parseFunctionBlock(false, isAsync, true);
  7832. }
  7833. return isAsync
  7834. ? doInAwaitContext(parseAssignmentExpressionOrHigher)
  7835. : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
  7836. }
  7837. function parseConditionalExpressionRest(leftOperand) {
  7838. var questionToken = parseOptionalToken(53);
  7839. if (!questionToken) {
  7840. return leftOperand;
  7841. }
  7842. var node = createNode(182, leftOperand.pos);
  7843. node.condition = leftOperand;
  7844. node.questionToken = questionToken;
  7845. node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher);
  7846. node.colonToken = parseExpectedToken(54, false, ts.Diagnostics._0_expected, ts.tokenToString(54));
  7847. node.whenFalse = parseAssignmentExpressionOrHigher();
  7848. return finishNode(node);
  7849. }
  7850. function parseBinaryExpressionOrHigher(precedence) {
  7851. var leftOperand = parseUnaryExpressionOrHigher();
  7852. return parseBinaryExpressionRest(precedence, leftOperand);
  7853. }
  7854. function isInOrOfKeyword(t) {
  7855. return t === 90 || t === 134;
  7856. }
  7857. function parseBinaryExpressionRest(precedence, leftOperand) {
  7858. while (true) {
  7859. reScanGreaterToken();
  7860. var newPrecedence = getBinaryOperatorPrecedence();
  7861. var consumeCurrentOperator = token === 38 ?
  7862. newPrecedence >= precedence :
  7863. newPrecedence > precedence;
  7864. if (!consumeCurrentOperator) {
  7865. break;
  7866. }
  7867. if (token === 90 && inDisallowInContext()) {
  7868. break;
  7869. }
  7870. if (token === 116) {
  7871. if (scanner.hasPrecedingLineBreak()) {
  7872. break;
  7873. }
  7874. else {
  7875. nextToken();
  7876. leftOperand = makeAsExpression(leftOperand, parseType());
  7877. }
  7878. }
  7879. else {
  7880. leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
  7881. }
  7882. }
  7883. return leftOperand;
  7884. }
  7885. function isBinaryOperator() {
  7886. if (inDisallowInContext() && token === 90) {
  7887. return false;
  7888. }
  7889. return getBinaryOperatorPrecedence() > 0;
  7890. }
  7891. function getBinaryOperatorPrecedence() {
  7892. switch (token) {
  7893. case 52:
  7894. return 1;
  7895. case 51:
  7896. return 2;
  7897. case 47:
  7898. return 3;
  7899. case 48:
  7900. return 4;
  7901. case 46:
  7902. return 5;
  7903. case 30:
  7904. case 31:
  7905. case 32:
  7906. case 33:
  7907. return 6;
  7908. case 25:
  7909. case 27:
  7910. case 28:
  7911. case 29:
  7912. case 91:
  7913. case 90:
  7914. case 116:
  7915. return 7;
  7916. case 43:
  7917. case 44:
  7918. case 45:
  7919. return 8;
  7920. case 35:
  7921. case 36:
  7922. return 9;
  7923. case 37:
  7924. case 39:
  7925. case 40:
  7926. return 10;
  7927. case 38:
  7928. return 11;
  7929. }
  7930. return -1;
  7931. }
  7932. function makeBinaryExpression(left, operatorToken, right) {
  7933. var node = createNode(181, left.pos);
  7934. node.left = left;
  7935. node.operatorToken = operatorToken;
  7936. node.right = right;
  7937. return finishNode(node);
  7938. }
  7939. function makeAsExpression(left, right) {
  7940. var node = createNode(189, left.pos);
  7941. node.expression = left;
  7942. node.type = right;
  7943. return finishNode(node);
  7944. }
  7945. function parsePrefixUnaryExpression() {
  7946. var node = createNode(179);
  7947. node.operator = token;
  7948. nextToken();
  7949. node.operand = parseSimpleUnaryExpression();
  7950. return finishNode(node);
  7951. }
  7952. function parseDeleteExpression() {
  7953. var node = createNode(175);
  7954. nextToken();
  7955. node.expression = parseSimpleUnaryExpression();
  7956. return finishNode(node);
  7957. }
  7958. function parseTypeOfExpression() {
  7959. var node = createNode(176);
  7960. nextToken();
  7961. node.expression = parseSimpleUnaryExpression();
  7962. return finishNode(node);
  7963. }
  7964. function parseVoidExpression() {
  7965. var node = createNode(177);
  7966. nextToken();
  7967. node.expression = parseSimpleUnaryExpression();
  7968. return finishNode(node);
  7969. }
  7970. function isAwaitExpression() {
  7971. if (token === 119) {
  7972. if (inAwaitContext()) {
  7973. return true;
  7974. }
  7975. return lookAhead(nextTokenIsIdentifierOnSameLine);
  7976. }
  7977. return false;
  7978. }
  7979. function parseAwaitExpression() {
  7980. var node = createNode(178);
  7981. nextToken();
  7982. node.expression = parseSimpleUnaryExpression();
  7983. return finishNode(node);
  7984. }
  7985. function parseUnaryExpressionOrHigher() {
  7986. if (isAwaitExpression()) {
  7987. return parseAwaitExpression();
  7988. }
  7989. if (isIncrementExpression()) {
  7990. var incrementExpression = parseIncrementExpression();
  7991. return token === 38 ?
  7992. parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) :
  7993. incrementExpression;
  7994. }
  7995. var unaryOperator = token;
  7996. var simpleUnaryExpression = parseSimpleUnaryExpression();
  7997. if (token === 38) {
  7998. var diagnostic;
  7999. var start = ts.skipTrivia(sourceText, simpleUnaryExpression.pos);
  8000. if (simpleUnaryExpression.kind === 171) {
  8001. parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses);
  8002. }
  8003. else {
  8004. parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, ts.tokenToString(unaryOperator));
  8005. }
  8006. }
  8007. return simpleUnaryExpression;
  8008. }
  8009. function parseSimpleUnaryExpression() {
  8010. switch (token) {
  8011. case 35:
  8012. case 36:
  8013. case 50:
  8014. case 49:
  8015. return parsePrefixUnaryExpression();
  8016. case 78:
  8017. return parseDeleteExpression();
  8018. case 101:
  8019. return parseTypeOfExpression();
  8020. case 103:
  8021. return parseVoidExpression();
  8022. case 25:
  8023. return parseTypeAssertion();
  8024. default:
  8025. return parseIncrementExpression();
  8026. }
  8027. }
  8028. function isIncrementExpression() {
  8029. switch (token) {
  8030. case 35:
  8031. case 36:
  8032. case 50:
  8033. case 49:
  8034. case 78:
  8035. case 101:
  8036. case 103:
  8037. return false;
  8038. case 25:
  8039. if (sourceFile.languageVariant !== 1) {
  8040. return false;
  8041. }
  8042. default:
  8043. return true;
  8044. }
  8045. }
  8046. function parseIncrementExpression() {
  8047. if (token === 41 || token === 42) {
  8048. var node = createNode(179);
  8049. node.operator = token;
  8050. nextToken();
  8051. node.operand = parseLeftHandSideExpressionOrHigher();
  8052. return finishNode(node);
  8053. }
  8054. else if (sourceFile.languageVariant === 1 && token === 25 && lookAhead(nextTokenIsIdentifierOrKeyword)) {
  8055. return parseJsxElementOrSelfClosingElement(true);
  8056. }
  8057. var expression = parseLeftHandSideExpressionOrHigher();
  8058. ts.Debug.assert(ts.isLeftHandSideExpression(expression));
  8059. if ((token === 41 || token === 42) && !scanner.hasPrecedingLineBreak()) {
  8060. var node = createNode(180, expression.pos);
  8061. node.operand = expression;
  8062. node.operator = token;
  8063. nextToken();
  8064. return finishNode(node);
  8065. }
  8066. return expression;
  8067. }
  8068. function parseLeftHandSideExpressionOrHigher() {
  8069. var expression = token === 95
  8070. ? parseSuperExpression()
  8071. : parseMemberExpressionOrHigher();
  8072. return parseCallExpressionRest(expression);
  8073. }
  8074. function parseMemberExpressionOrHigher() {
  8075. var expression = parsePrimaryExpression();
  8076. return parseMemberExpressionRest(expression);
  8077. }
  8078. function parseSuperExpression() {
  8079. var expression = parseTokenNode();
  8080. if (token === 17 || token === 21 || token === 19) {
  8081. return expression;
  8082. }
  8083. var node = createNode(166, expression.pos);
  8084. node.expression = expression;
  8085. node.dotToken = parseExpectedToken(21, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
  8086. node.name = parseRightSideOfDot(true);
  8087. return finishNode(node);
  8088. }
  8089. function parseJsxElementOrSelfClosingElement(inExpressionContext) {
  8090. var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext);
  8091. if (opening.kind === 235) {
  8092. var node = createNode(233, opening.pos);
  8093. node.openingElement = opening;
  8094. node.children = parseJsxChildren(node.openingElement.tagName);
  8095. node.closingElement = parseJsxClosingElement(inExpressionContext);
  8096. return finishNode(node);
  8097. }
  8098. else {
  8099. ts.Debug.assert(opening.kind === 234);
  8100. return opening;
  8101. }
  8102. }
  8103. function parseJsxText() {
  8104. var node = createNode(236, scanner.getStartPos());
  8105. token = scanner.scanJsxToken();
  8106. return finishNode(node);
  8107. }
  8108. function parseJsxChild() {
  8109. switch (token) {
  8110. case 236:
  8111. return parseJsxText();
  8112. case 15:
  8113. return parseJsxExpression(false);
  8114. case 25:
  8115. return parseJsxElementOrSelfClosingElement(false);
  8116. }
  8117. ts.Debug.fail("Unknown JSX child kind " + token);
  8118. }
  8119. function parseJsxChildren(openingTagName) {
  8120. var result = [];
  8121. result.pos = scanner.getStartPos();
  8122. var saveParsingContext = parsingContext;
  8123. parsingContext |= 1 << 14;
  8124. while (true) {
  8125. token = scanner.reScanJsxToken();
  8126. if (token === 26) {
  8127. break;
  8128. }
  8129. else if (token === 1) {
  8130. parseErrorAtCurrentToken(ts.Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, ts.getTextOfNodeFromSourceText(sourceText, openingTagName));
  8131. break;
  8132. }
  8133. result.push(parseJsxChild());
  8134. }
  8135. result.end = scanner.getTokenPos();
  8136. parsingContext = saveParsingContext;
  8137. return result;
  8138. }
  8139. function parseJsxOpeningOrSelfClosingElement(inExpressionContext) {
  8140. var fullStart = scanner.getStartPos();
  8141. parseExpected(25);
  8142. var tagName = parseJsxElementName();
  8143. var attributes = parseList(13, parseJsxAttribute);
  8144. var node;
  8145. if (token === 27) {
  8146. node = createNode(235, fullStart);
  8147. scanJsxText();
  8148. }
  8149. else {
  8150. parseExpected(39);
  8151. if (inExpressionContext) {
  8152. parseExpected(27);
  8153. }
  8154. else {
  8155. parseExpected(27, undefined, false);
  8156. scanJsxText();
  8157. }
  8158. node = createNode(234, fullStart);
  8159. }
  8160. node.tagName = tagName;
  8161. node.attributes = attributes;
  8162. return finishNode(node);
  8163. }
  8164. function parseJsxElementName() {
  8165. scanJsxIdentifier();
  8166. var elementName = parseIdentifierName();
  8167. while (parseOptional(21)) {
  8168. scanJsxIdentifier();
  8169. var node = createNode(135, elementName.pos);
  8170. node.left = elementName;
  8171. node.right = parseIdentifierName();
  8172. elementName = finishNode(node);
  8173. }
  8174. return elementName;
  8175. }
  8176. function parseJsxExpression(inExpressionContext) {
  8177. var node = createNode(240);
  8178. parseExpected(15);
  8179. if (token !== 16) {
  8180. node.expression = parseExpression();
  8181. }
  8182. if (inExpressionContext) {
  8183. parseExpected(16);
  8184. }
  8185. else {
  8186. parseExpected(16, undefined, false);
  8187. scanJsxText();
  8188. }
  8189. return finishNode(node);
  8190. }
  8191. function parseJsxAttribute() {
  8192. if (token === 15) {
  8193. return parseJsxSpreadAttribute();
  8194. }
  8195. scanJsxIdentifier();
  8196. var node = createNode(238);
  8197. node.name = parseIdentifierName();
  8198. if (parseOptional(56)) {
  8199. switch (token) {
  8200. case 9:
  8201. node.initializer = parseLiteralNode();
  8202. break;
  8203. default:
  8204. node.initializer = parseJsxExpression(true);
  8205. break;
  8206. }
  8207. }
  8208. return finishNode(node);
  8209. }
  8210. function parseJsxSpreadAttribute() {
  8211. var node = createNode(239);
  8212. parseExpected(15);
  8213. parseExpected(22);
  8214. node.expression = parseExpression();
  8215. parseExpected(16);
  8216. return finishNode(node);
  8217. }
  8218. function parseJsxClosingElement(inExpressionContext) {
  8219. var node = createNode(237);
  8220. parseExpected(26);
  8221. node.tagName = parseJsxElementName();
  8222. if (inExpressionContext) {
  8223. parseExpected(27);
  8224. }
  8225. else {
  8226. parseExpected(27, undefined, false);
  8227. scanJsxText();
  8228. }
  8229. return finishNode(node);
  8230. }
  8231. function parseTypeAssertion() {
  8232. var node = createNode(171);
  8233. parseExpected(25);
  8234. node.type = parseType();
  8235. parseExpected(27);
  8236. node.expression = parseSimpleUnaryExpression();
  8237. return finishNode(node);
  8238. }
  8239. function parseMemberExpressionRest(expression) {
  8240. while (true) {
  8241. var dotToken = parseOptionalToken(21);
  8242. if (dotToken) {
  8243. var propertyAccess = createNode(166, expression.pos);
  8244. propertyAccess.expression = expression;
  8245. propertyAccess.dotToken = dotToken;
  8246. propertyAccess.name = parseRightSideOfDot(true);
  8247. expression = finishNode(propertyAccess);
  8248. continue;
  8249. }
  8250. if (!inDecoratorContext() && parseOptional(19)) {
  8251. var indexedAccess = createNode(167, expression.pos);
  8252. indexedAccess.expression = expression;
  8253. if (token !== 20) {
  8254. indexedAccess.argumentExpression = allowInAnd(parseExpression);
  8255. if (indexedAccess.argumentExpression.kind === 9 || indexedAccess.argumentExpression.kind === 8) {
  8256. var literal = indexedAccess.argumentExpression;
  8257. literal.text = internIdentifier(literal.text);
  8258. }
  8259. }
  8260. parseExpected(20);
  8261. expression = finishNode(indexedAccess);
  8262. continue;
  8263. }
  8264. if (token === 11 || token === 12) {
  8265. var tagExpression = createNode(170, expression.pos);
  8266. tagExpression.tag = expression;
  8267. tagExpression.template = token === 11
  8268. ? parseLiteralNode()
  8269. : parseTemplateExpression();
  8270. expression = finishNode(tagExpression);
  8271. continue;
  8272. }
  8273. return expression;
  8274. }
  8275. }
  8276. function parseCallExpressionRest(expression) {
  8277. while (true) {
  8278. expression = parseMemberExpressionRest(expression);
  8279. if (token === 25) {
  8280. var typeArguments = tryParse(parseTypeArgumentsInExpression);
  8281. if (!typeArguments) {
  8282. return expression;
  8283. }
  8284. var callExpr = createNode(168, expression.pos);
  8285. callExpr.expression = expression;
  8286. callExpr.typeArguments = typeArguments;
  8287. callExpr.arguments = parseArgumentList();
  8288. expression = finishNode(callExpr);
  8289. continue;
  8290. }
  8291. else if (token === 17) {
  8292. var callExpr = createNode(168, expression.pos);
  8293. callExpr.expression = expression;
  8294. callExpr.arguments = parseArgumentList();
  8295. expression = finishNode(callExpr);
  8296. continue;
  8297. }
  8298. return expression;
  8299. }
  8300. }
  8301. function parseArgumentList() {
  8302. parseExpected(17);
  8303. var result = parseDelimitedList(11, parseArgumentExpression);
  8304. parseExpected(18);
  8305. return result;
  8306. }
  8307. function parseTypeArgumentsInExpression() {
  8308. if (!parseOptional(25)) {
  8309. return undefined;
  8310. }
  8311. var typeArguments = parseDelimitedList(18, parseType);
  8312. if (!parseExpected(27)) {
  8313. return undefined;
  8314. }
  8315. return typeArguments && canFollowTypeArgumentsInExpression()
  8316. ? typeArguments
  8317. : undefined;
  8318. }
  8319. function canFollowTypeArgumentsInExpression() {
  8320. switch (token) {
  8321. case 17:
  8322. case 21:
  8323. case 18:
  8324. case 20:
  8325. case 54:
  8326. case 23:
  8327. case 53:
  8328. case 30:
  8329. case 32:
  8330. case 31:
  8331. case 33:
  8332. case 51:
  8333. case 52:
  8334. case 48:
  8335. case 46:
  8336. case 47:
  8337. case 16:
  8338. case 1:
  8339. return true;
  8340. case 24:
  8341. case 15:
  8342. default:
  8343. return false;
  8344. }
  8345. }
  8346. function parsePrimaryExpression() {
  8347. switch (token) {
  8348. case 8:
  8349. case 9:
  8350. case 11:
  8351. return parseLiteralNode();
  8352. case 97:
  8353. case 95:
  8354. case 93:
  8355. case 99:
  8356. case 84:
  8357. return parseTokenNode();
  8358. case 17:
  8359. return parseParenthesizedExpression();
  8360. case 19:
  8361. return parseArrayLiteralExpression();
  8362. case 15:
  8363. return parseObjectLiteralExpression();
  8364. case 118:
  8365. if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) {
  8366. break;
  8367. }
  8368. return parseFunctionExpression();
  8369. case 73:
  8370. return parseClassExpression();
  8371. case 87:
  8372. return parseFunctionExpression();
  8373. case 92:
  8374. return parseNewExpression();
  8375. case 39:
  8376. case 61:
  8377. if (reScanSlashToken() === 10) {
  8378. return parseLiteralNode();
  8379. }
  8380. break;
  8381. case 12:
  8382. return parseTemplateExpression();
  8383. }
  8384. return parseIdentifier(ts.Diagnostics.Expression_expected);
  8385. }
  8386. function parseParenthesizedExpression() {
  8387. var node = createNode(172);
  8388. parseExpected(17);
  8389. node.expression = allowInAnd(parseExpression);
  8390. parseExpected(18);
  8391. return finishNode(node);
  8392. }
  8393. function parseSpreadElement() {
  8394. var node = createNode(185);
  8395. parseExpected(22);
  8396. node.expression = parseAssignmentExpressionOrHigher();
  8397. return finishNode(node);
  8398. }
  8399. function parseArgumentOrArrayLiteralElement() {
  8400. return token === 22 ? parseSpreadElement() :
  8401. token === 24 ? createNode(187) :
  8402. parseAssignmentExpressionOrHigher();
  8403. }
  8404. function parseArgumentExpression() {
  8405. return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
  8406. }
  8407. function parseArrayLiteralExpression() {
  8408. var node = createNode(164);
  8409. parseExpected(19);
  8410. if (scanner.hasPrecedingLineBreak())
  8411. node.flags |= 2048;
  8412. node.elements = parseDelimitedList(15, parseArgumentOrArrayLiteralElement);
  8413. parseExpected(20);
  8414. return finishNode(node);
  8415. }
  8416. function tryParseAccessorDeclaration(fullStart, decorators, modifiers) {
  8417. if (parseContextualModifier(123)) {
  8418. return parseAccessorDeclaration(145, fullStart, decorators, modifiers);
  8419. }
  8420. else if (parseContextualModifier(129)) {
  8421. return parseAccessorDeclaration(146, fullStart, decorators, modifiers);
  8422. }
  8423. return undefined;
  8424. }
  8425. function parseObjectLiteralElement() {
  8426. var fullStart = scanner.getStartPos();
  8427. var decorators = parseDecorators();
  8428. var modifiers = parseModifiers();
  8429. var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
  8430. if (accessor) {
  8431. return accessor;
  8432. }
  8433. var asteriskToken = parseOptionalToken(37);
  8434. var tokenIsIdentifier = isIdentifier();
  8435. var nameToken = token;
  8436. var propertyName = parsePropertyName();
  8437. var questionToken = parseOptionalToken(53);
  8438. if (asteriskToken || token === 17 || token === 25) {
  8439. return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken);
  8440. }
  8441. var isShorthandPropertyAssignment = tokenIsIdentifier && (token === 24 || token === 16 || token === 56);
  8442. if (isShorthandPropertyAssignment) {
  8443. var shorthandDeclaration = createNode(246, fullStart);
  8444. shorthandDeclaration.name = propertyName;
  8445. shorthandDeclaration.questionToken = questionToken;
  8446. var equalsToken = parseOptionalToken(56);
  8447. if (equalsToken) {
  8448. shorthandDeclaration.equalsToken = equalsToken;
  8449. shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher);
  8450. }
  8451. return finishNode(shorthandDeclaration);
  8452. }
  8453. else {
  8454. var propertyAssignment = createNode(245, fullStart);
  8455. propertyAssignment.name = propertyName;
  8456. propertyAssignment.questionToken = questionToken;
  8457. parseExpected(54);
  8458. propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
  8459. return finishNode(propertyAssignment);
  8460. }
  8461. }
  8462. function parseObjectLiteralExpression() {
  8463. var node = createNode(165);
  8464. parseExpected(15);
  8465. if (scanner.hasPrecedingLineBreak()) {
  8466. node.flags |= 2048;
  8467. }
  8468. node.properties = parseDelimitedList(12, parseObjectLiteralElement, true);
  8469. parseExpected(16);
  8470. return finishNode(node);
  8471. }
  8472. function parseFunctionExpression() {
  8473. var saveDecoratorContext = inDecoratorContext();
  8474. if (saveDecoratorContext) {
  8475. setDecoratorContext(false);
  8476. }
  8477. var node = createNode(173);
  8478. setModifiers(node, parseModifiers());
  8479. parseExpected(87);
  8480. node.asteriskToken = parseOptionalToken(37);
  8481. var isGenerator = !!node.asteriskToken;
  8482. var isAsync = !!(node.flags & 512);
  8483. node.name =
  8484. isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalIdentifier) :
  8485. isGenerator ? doInYieldContext(parseOptionalIdentifier) :
  8486. isAsync ? doInAwaitContext(parseOptionalIdentifier) :
  8487. parseOptionalIdentifier();
  8488. fillSignature(54, isGenerator, isAsync, false, node);
  8489. node.body = parseFunctionBlock(isGenerator, isAsync, false);
  8490. if (saveDecoratorContext) {
  8491. setDecoratorContext(true);
  8492. }
  8493. return finishNode(node);
  8494. }
  8495. function parseOptionalIdentifier() {
  8496. return isIdentifier() ? parseIdentifier() : undefined;
  8497. }
  8498. function parseNewExpression() {
  8499. var node = createNode(169);
  8500. parseExpected(92);
  8501. node.expression = parseMemberExpressionOrHigher();
  8502. node.typeArguments = tryParse(parseTypeArgumentsInExpression);
  8503. if (node.typeArguments || token === 17) {
  8504. node.arguments = parseArgumentList();
  8505. }
  8506. return finishNode(node);
  8507. }
  8508. function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) {
  8509. var node = createNode(192);
  8510. if (parseExpected(15, diagnosticMessage) || ignoreMissingOpenBrace) {
  8511. node.statements = parseList(1, parseStatement);
  8512. parseExpected(16);
  8513. }
  8514. else {
  8515. node.statements = createMissingList();
  8516. }
  8517. return finishNode(node);
  8518. }
  8519. function parseFunctionBlock(allowYield, allowAwait, ignoreMissingOpenBrace, diagnosticMessage) {
  8520. var savedYieldContext = inYieldContext();
  8521. setYieldContext(allowYield);
  8522. var savedAwaitContext = inAwaitContext();
  8523. setAwaitContext(allowAwait);
  8524. var saveDecoratorContext = inDecoratorContext();
  8525. if (saveDecoratorContext) {
  8526. setDecoratorContext(false);
  8527. }
  8528. var block = parseBlock(ignoreMissingOpenBrace, diagnosticMessage);
  8529. if (saveDecoratorContext) {
  8530. setDecoratorContext(true);
  8531. }
  8532. setYieldContext(savedYieldContext);
  8533. setAwaitContext(savedAwaitContext);
  8534. return block;
  8535. }
  8536. function parseEmptyStatement() {
  8537. var node = createNode(194);
  8538. parseExpected(23);
  8539. return finishNode(node);
  8540. }
  8541. function parseIfStatement() {
  8542. var node = createNode(196);
  8543. parseExpected(88);
  8544. parseExpected(17);
  8545. node.expression = allowInAnd(parseExpression);
  8546. parseExpected(18);
  8547. node.thenStatement = parseStatement();
  8548. node.elseStatement = parseOptional(80) ? parseStatement() : undefined;
  8549. return finishNode(node);
  8550. }
  8551. function parseDoStatement() {
  8552. var node = createNode(197);
  8553. parseExpected(79);
  8554. node.statement = parseStatement();
  8555. parseExpected(104);
  8556. parseExpected(17);
  8557. node.expression = allowInAnd(parseExpression);
  8558. parseExpected(18);
  8559. parseOptional(23);
  8560. return finishNode(node);
  8561. }
  8562. function parseWhileStatement() {
  8563. var node = createNode(198);
  8564. parseExpected(104);
  8565. parseExpected(17);
  8566. node.expression = allowInAnd(parseExpression);
  8567. parseExpected(18);
  8568. node.statement = parseStatement();
  8569. return finishNode(node);
  8570. }
  8571. function parseForOrForInOrForOfStatement() {
  8572. var pos = getNodePos();
  8573. parseExpected(86);
  8574. parseExpected(17);
  8575. var initializer = undefined;
  8576. if (token !== 23) {
  8577. if (token === 102 || token === 108 || token === 74) {
  8578. initializer = parseVariableDeclarationList(true);
  8579. }
  8580. else {
  8581. initializer = disallowInAnd(parseExpression);
  8582. }
  8583. }
  8584. var forOrForInOrForOfStatement;
  8585. if (parseOptional(90)) {
  8586. var forInStatement = createNode(200, pos);
  8587. forInStatement.initializer = initializer;
  8588. forInStatement.expression = allowInAnd(parseExpression);
  8589. parseExpected(18);
  8590. forOrForInOrForOfStatement = forInStatement;
  8591. }
  8592. else if (parseOptional(134)) {
  8593. var forOfStatement = createNode(201, pos);
  8594. forOfStatement.initializer = initializer;
  8595. forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher);
  8596. parseExpected(18);
  8597. forOrForInOrForOfStatement = forOfStatement;
  8598. }
  8599. else {
  8600. var forStatement = createNode(199, pos);
  8601. forStatement.initializer = initializer;
  8602. parseExpected(23);
  8603. if (token !== 23 && token !== 18) {
  8604. forStatement.condition = allowInAnd(parseExpression);
  8605. }
  8606. parseExpected(23);
  8607. if (token !== 18) {
  8608. forStatement.incrementor = allowInAnd(parseExpression);
  8609. }
  8610. parseExpected(18);
  8611. forOrForInOrForOfStatement = forStatement;
  8612. }
  8613. forOrForInOrForOfStatement.statement = parseStatement();
  8614. return finishNode(forOrForInOrForOfStatement);
  8615. }
  8616. function parseBreakOrContinueStatement(kind) {
  8617. var node = createNode(kind);
  8618. parseExpected(kind === 203 ? 70 : 75);
  8619. if (!canParseSemicolon()) {
  8620. node.label = parseIdentifier();
  8621. }
  8622. parseSemicolon();
  8623. return finishNode(node);
  8624. }
  8625. function parseReturnStatement() {
  8626. var node = createNode(204);
  8627. parseExpected(94);
  8628. if (!canParseSemicolon()) {
  8629. node.expression = allowInAnd(parseExpression);
  8630. }
  8631. parseSemicolon();
  8632. return finishNode(node);
  8633. }
  8634. function parseWithStatement() {
  8635. var node = createNode(205);
  8636. parseExpected(105);
  8637. parseExpected(17);
  8638. node.expression = allowInAnd(parseExpression);
  8639. parseExpected(18);
  8640. node.statement = parseStatement();
  8641. return finishNode(node);
  8642. }
  8643. function parseCaseClause() {
  8644. var node = createNode(241);
  8645. parseExpected(71);
  8646. node.expression = allowInAnd(parseExpression);
  8647. parseExpected(54);
  8648. node.statements = parseList(3, parseStatement);
  8649. return finishNode(node);
  8650. }
  8651. function parseDefaultClause() {
  8652. var node = createNode(242);
  8653. parseExpected(77);
  8654. parseExpected(54);
  8655. node.statements = parseList(3, parseStatement);
  8656. return finishNode(node);
  8657. }
  8658. function parseCaseOrDefaultClause() {
  8659. return token === 71 ? parseCaseClause() : parseDefaultClause();
  8660. }
  8661. function parseSwitchStatement() {
  8662. var node = createNode(206);
  8663. parseExpected(96);
  8664. parseExpected(17);
  8665. node.expression = allowInAnd(parseExpression);
  8666. parseExpected(18);
  8667. var caseBlock = createNode(220, scanner.getStartPos());
  8668. parseExpected(15);
  8669. caseBlock.clauses = parseList(2, parseCaseOrDefaultClause);
  8670. parseExpected(16);
  8671. node.caseBlock = finishNode(caseBlock);
  8672. return finishNode(node);
  8673. }
  8674. function parseThrowStatement() {
  8675. var node = createNode(208);
  8676. parseExpected(98);
  8677. node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression);
  8678. parseSemicolon();
  8679. return finishNode(node);
  8680. }
  8681. function parseTryStatement() {
  8682. var node = createNode(209);
  8683. parseExpected(100);
  8684. node.tryBlock = parseBlock(false);
  8685. node.catchClause = token === 72 ? parseCatchClause() : undefined;
  8686. if (!node.catchClause || token === 85) {
  8687. parseExpected(85);
  8688. node.finallyBlock = parseBlock(false);
  8689. }
  8690. return finishNode(node);
  8691. }
  8692. function parseCatchClause() {
  8693. var result = createNode(244);
  8694. parseExpected(72);
  8695. if (parseExpected(17)) {
  8696. result.variableDeclaration = parseVariableDeclaration();
  8697. }
  8698. parseExpected(18);
  8699. result.block = parseBlock(false);
  8700. return finishNode(result);
  8701. }
  8702. function parseDebuggerStatement() {
  8703. var node = createNode(210);
  8704. parseExpected(76);
  8705. parseSemicolon();
  8706. return finishNode(node);
  8707. }
  8708. function parseExpressionOrLabeledStatement() {
  8709. var fullStart = scanner.getStartPos();
  8710. var expression = allowInAnd(parseExpression);
  8711. if (expression.kind === 69 && parseOptional(54)) {
  8712. var labeledStatement = createNode(207, fullStart);
  8713. labeledStatement.label = expression;
  8714. labeledStatement.statement = parseStatement();
  8715. return finishNode(labeledStatement);
  8716. }
  8717. else {
  8718. var expressionStatement = createNode(195, fullStart);
  8719. expressionStatement.expression = expression;
  8720. parseSemicolon();
  8721. return finishNode(expressionStatement);
  8722. }
  8723. }
  8724. function nextTokenIsIdentifierOrKeywordOnSameLine() {
  8725. nextToken();
  8726. return ts.tokenIsIdentifierOrKeyword(token) && !scanner.hasPrecedingLineBreak();
  8727. }
  8728. function nextTokenIsFunctionKeywordOnSameLine() {
  8729. nextToken();
  8730. return token === 87 && !scanner.hasPrecedingLineBreak();
  8731. }
  8732. function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
  8733. nextToken();
  8734. return (ts.tokenIsIdentifierOrKeyword(token) || token === 8) && !scanner.hasPrecedingLineBreak();
  8735. }
  8736. function isDeclaration() {
  8737. while (true) {
  8738. switch (token) {
  8739. case 102:
  8740. case 108:
  8741. case 74:
  8742. case 87:
  8743. case 73:
  8744. case 81:
  8745. return true;
  8746. case 107:
  8747. case 132:
  8748. return nextTokenIsIdentifierOnSameLine();
  8749. case 125:
  8750. case 126:
  8751. return nextTokenIsIdentifierOrStringLiteralOnSameLine();
  8752. case 115:
  8753. case 118:
  8754. case 122:
  8755. case 110:
  8756. case 111:
  8757. case 112:
  8758. nextToken();
  8759. if (scanner.hasPrecedingLineBreak()) {
  8760. return false;
  8761. }
  8762. continue;
  8763. case 89:
  8764. nextToken();
  8765. return token === 9 || token === 37 ||
  8766. token === 15 || ts.tokenIsIdentifierOrKeyword(token);
  8767. case 82:
  8768. nextToken();
  8769. if (token === 56 || token === 37 ||
  8770. token === 15 || token === 77) {
  8771. return true;
  8772. }
  8773. continue;
  8774. case 113:
  8775. nextToken();
  8776. continue;
  8777. default:
  8778. return false;
  8779. }
  8780. }
  8781. }
  8782. function isStartOfDeclaration() {
  8783. return lookAhead(isDeclaration);
  8784. }
  8785. function isStartOfStatement() {
  8786. switch (token) {
  8787. case 55:
  8788. case 23:
  8789. case 15:
  8790. case 102:
  8791. case 108:
  8792. case 87:
  8793. case 73:
  8794. case 81:
  8795. case 88:
  8796. case 79:
  8797. case 104:
  8798. case 86:
  8799. case 75:
  8800. case 70:
  8801. case 94:
  8802. case 105:
  8803. case 96:
  8804. case 98:
  8805. case 100:
  8806. case 76:
  8807. case 72:
  8808. case 85:
  8809. return true;
  8810. case 74:
  8811. case 82:
  8812. case 89:
  8813. return isStartOfDeclaration();
  8814. case 118:
  8815. case 122:
  8816. case 107:
  8817. case 125:
  8818. case 126:
  8819. case 132:
  8820. return true;
  8821. case 112:
  8822. case 110:
  8823. case 111:
  8824. case 113:
  8825. return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
  8826. default:
  8827. return isStartOfExpression();
  8828. }
  8829. }
  8830. function nextTokenIsIdentifierOrStartOfDestructuring() {
  8831. nextToken();
  8832. return isIdentifier() || token === 15 || token === 19;
  8833. }
  8834. function isLetDeclaration() {
  8835. return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring);
  8836. }
  8837. function parseStatement() {
  8838. switch (token) {
  8839. case 23:
  8840. return parseEmptyStatement();
  8841. case 15:
  8842. return parseBlock(false);
  8843. case 102:
  8844. return parseVariableStatement(scanner.getStartPos(), undefined, undefined);
  8845. case 108:
  8846. if (isLetDeclaration()) {
  8847. return parseVariableStatement(scanner.getStartPos(), undefined, undefined);
  8848. }
  8849. break;
  8850. case 87:
  8851. return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined);
  8852. case 73:
  8853. return parseClassDeclaration(scanner.getStartPos(), undefined, undefined);
  8854. case 88:
  8855. return parseIfStatement();
  8856. case 79:
  8857. return parseDoStatement();
  8858. case 104:
  8859. return parseWhileStatement();
  8860. case 86:
  8861. return parseForOrForInOrForOfStatement();
  8862. case 75:
  8863. return parseBreakOrContinueStatement(202);
  8864. case 70:
  8865. return parseBreakOrContinueStatement(203);
  8866. case 94:
  8867. return parseReturnStatement();
  8868. case 105:
  8869. return parseWithStatement();
  8870. case 96:
  8871. return parseSwitchStatement();
  8872. case 98:
  8873. return parseThrowStatement();
  8874. case 100:
  8875. case 72:
  8876. case 85:
  8877. return parseTryStatement();
  8878. case 76:
  8879. return parseDebuggerStatement();
  8880. case 55:
  8881. return parseDeclaration();
  8882. case 118:
  8883. case 107:
  8884. case 132:
  8885. case 125:
  8886. case 126:
  8887. case 122:
  8888. case 74:
  8889. case 81:
  8890. case 82:
  8891. case 89:
  8892. case 110:
  8893. case 111:
  8894. case 112:
  8895. case 115:
  8896. case 113:
  8897. if (isStartOfDeclaration()) {
  8898. return parseDeclaration();
  8899. }
  8900. break;
  8901. }
  8902. return parseExpressionOrLabeledStatement();
  8903. }
  8904. function parseDeclaration() {
  8905. var fullStart = getNodePos();
  8906. var decorators = parseDecorators();
  8907. var modifiers = parseModifiers();
  8908. switch (token) {
  8909. case 102:
  8910. case 108:
  8911. case 74:
  8912. return parseVariableStatement(fullStart, decorators, modifiers);
  8913. case 87:
  8914. return parseFunctionDeclaration(fullStart, decorators, modifiers);
  8915. case 73:
  8916. return parseClassDeclaration(fullStart, decorators, modifiers);
  8917. case 107:
  8918. return parseInterfaceDeclaration(fullStart, decorators, modifiers);
  8919. case 132:
  8920. return parseTypeAliasDeclaration(fullStart, decorators, modifiers);
  8921. case 81:
  8922. return parseEnumDeclaration(fullStart, decorators, modifiers);
  8923. case 125:
  8924. case 126:
  8925. return parseModuleDeclaration(fullStart, decorators, modifiers);
  8926. case 89:
  8927. return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers);
  8928. case 82:
  8929. nextToken();
  8930. return token === 77 || token === 56 ?
  8931. parseExportAssignment(fullStart, decorators, modifiers) :
  8932. parseExportDeclaration(fullStart, decorators, modifiers);
  8933. default:
  8934. if (decorators || modifiers) {
  8935. var node = createMissingNode(231, true, ts.Diagnostics.Declaration_expected);
  8936. node.pos = fullStart;
  8937. node.decorators = decorators;
  8938. setModifiers(node, modifiers);
  8939. return finishNode(node);
  8940. }
  8941. }
  8942. }
  8943. function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  8944. nextToken();
  8945. return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === 9);
  8946. }
  8947. function parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage) {
  8948. if (token !== 15 && canParseSemicolon()) {
  8949. parseSemicolon();
  8950. return;
  8951. }
  8952. return parseFunctionBlock(isGenerator, isAsync, false, diagnosticMessage);
  8953. }
  8954. function parseArrayBindingElement() {
  8955. if (token === 24) {
  8956. return createNode(187);
  8957. }
  8958. var node = createNode(163);
  8959. node.dotDotDotToken = parseOptionalToken(22);
  8960. node.name = parseIdentifierOrPattern();
  8961. node.initializer = parseBindingElementInitializer(false);
  8962. return finishNode(node);
  8963. }
  8964. function parseObjectBindingElement() {
  8965. var node = createNode(163);
  8966. var tokenIsIdentifier = isIdentifier();
  8967. var propertyName = parsePropertyName();
  8968. if (tokenIsIdentifier && token !== 54) {
  8969. node.name = propertyName;
  8970. }
  8971. else {
  8972. parseExpected(54);
  8973. node.propertyName = propertyName;
  8974. node.name = parseIdentifierOrPattern();
  8975. }
  8976. node.initializer = parseBindingElementInitializer(false);
  8977. return finishNode(node);
  8978. }
  8979. function parseObjectBindingPattern() {
  8980. var node = createNode(161);
  8981. parseExpected(15);
  8982. node.elements = parseDelimitedList(9, parseObjectBindingElement);
  8983. parseExpected(16);
  8984. return finishNode(node);
  8985. }
  8986. function parseArrayBindingPattern() {
  8987. var node = createNode(162);
  8988. parseExpected(19);
  8989. node.elements = parseDelimitedList(10, parseArrayBindingElement);
  8990. parseExpected(20);
  8991. return finishNode(node);
  8992. }
  8993. function isIdentifierOrPattern() {
  8994. return token === 15 || token === 19 || isIdentifier();
  8995. }
  8996. function parseIdentifierOrPattern() {
  8997. if (token === 19) {
  8998. return parseArrayBindingPattern();
  8999. }
  9000. if (token === 15) {
  9001. return parseObjectBindingPattern();
  9002. }
  9003. return parseIdentifier();
  9004. }
  9005. function parseVariableDeclaration() {
  9006. var node = createNode(211);
  9007. node.name = parseIdentifierOrPattern();
  9008. node.type = parseTypeAnnotation();
  9009. if (!isInOrOfKeyword(token)) {
  9010. node.initializer = parseInitializer(false);
  9011. }
  9012. return finishNode(node);
  9013. }
  9014. function parseVariableDeclarationList(inForStatementInitializer) {
  9015. var node = createNode(212);
  9016. switch (token) {
  9017. case 102:
  9018. break;
  9019. case 108:
  9020. node.flags |= 16384;
  9021. break;
  9022. case 74:
  9023. node.flags |= 32768;
  9024. break;
  9025. default:
  9026. ts.Debug.fail();
  9027. }
  9028. nextToken();
  9029. if (token === 134 && lookAhead(canFollowContextualOfKeyword)) {
  9030. node.declarations = createMissingList();
  9031. }
  9032. else {
  9033. var savedDisallowIn = inDisallowInContext();
  9034. setDisallowInContext(inForStatementInitializer);
  9035. node.declarations = parseDelimitedList(8, parseVariableDeclaration);
  9036. setDisallowInContext(savedDisallowIn);
  9037. }
  9038. return finishNode(node);
  9039. }
  9040. function canFollowContextualOfKeyword() {
  9041. return nextTokenIsIdentifier() && nextToken() === 18;
  9042. }
  9043. function parseVariableStatement(fullStart, decorators, modifiers) {
  9044. var node = createNode(193, fullStart);
  9045. node.decorators = decorators;
  9046. setModifiers(node, modifiers);
  9047. node.declarationList = parseVariableDeclarationList(false);
  9048. parseSemicolon();
  9049. return finishNode(node);
  9050. }
  9051. function parseFunctionDeclaration(fullStart, decorators, modifiers) {
  9052. var node = createNode(213, fullStart);
  9053. node.decorators = decorators;
  9054. setModifiers(node, modifiers);
  9055. parseExpected(87);
  9056. node.asteriskToken = parseOptionalToken(37);
  9057. node.name = node.flags & 1024 ? parseOptionalIdentifier() : parseIdentifier();
  9058. var isGenerator = !!node.asteriskToken;
  9059. var isAsync = !!(node.flags & 512);
  9060. fillSignature(54, isGenerator, isAsync, false, node);
  9061. node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected);
  9062. return finishNode(node);
  9063. }
  9064. function parseConstructorDeclaration(pos, decorators, modifiers) {
  9065. var node = createNode(144, pos);
  9066. node.decorators = decorators;
  9067. setModifiers(node, modifiers);
  9068. parseExpected(121);
  9069. fillSignature(54, false, false, false, node);
  9070. node.body = parseFunctionBlockOrSemicolon(false, false, ts.Diagnostics.or_expected);
  9071. return finishNode(node);
  9072. }
  9073. function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) {
  9074. var method = createNode(143, fullStart);
  9075. method.decorators = decorators;
  9076. setModifiers(method, modifiers);
  9077. method.asteriskToken = asteriskToken;
  9078. method.name = name;
  9079. method.questionToken = questionToken;
  9080. var isGenerator = !!asteriskToken;
  9081. var isAsync = !!(method.flags & 512);
  9082. fillSignature(54, isGenerator, isAsync, false, method);
  9083. method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage);
  9084. return finishNode(method);
  9085. }
  9086. function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) {
  9087. var property = createNode(141, fullStart);
  9088. property.decorators = decorators;
  9089. setModifiers(property, modifiers);
  9090. property.name = name;
  9091. property.questionToken = questionToken;
  9092. property.type = parseTypeAnnotation();
  9093. property.initializer = modifiers && modifiers.flags & 128
  9094. ? allowInAnd(parseNonParameterInitializer)
  9095. : doOutsideOfContext(2 | 1, parseNonParameterInitializer);
  9096. parseSemicolon();
  9097. return finishNode(property);
  9098. }
  9099. function parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers) {
  9100. var asteriskToken = parseOptionalToken(37);
  9101. var name = parsePropertyName();
  9102. var questionToken = parseOptionalToken(53);
  9103. if (asteriskToken || token === 17 || token === 25) {
  9104. return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected);
  9105. }
  9106. else {
  9107. return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken);
  9108. }
  9109. }
  9110. function parseNonParameterInitializer() {
  9111. return parseInitializer(false);
  9112. }
  9113. function parseAccessorDeclaration(kind, fullStart, decorators, modifiers) {
  9114. var node = createNode(kind, fullStart);
  9115. node.decorators = decorators;
  9116. setModifiers(node, modifiers);
  9117. node.name = parsePropertyName();
  9118. fillSignature(54, false, false, false, node);
  9119. node.body = parseFunctionBlockOrSemicolon(false, false);
  9120. return finishNode(node);
  9121. }
  9122. function isClassMemberModifier(idToken) {
  9123. switch (idToken) {
  9124. case 112:
  9125. case 110:
  9126. case 111:
  9127. case 113:
  9128. return true;
  9129. default:
  9130. return false;
  9131. }
  9132. }
  9133. function isClassMemberStart() {
  9134. var idToken;
  9135. if (token === 55) {
  9136. return true;
  9137. }
  9138. while (ts.isModifier(token)) {
  9139. idToken = token;
  9140. if (isClassMemberModifier(idToken)) {
  9141. return true;
  9142. }
  9143. nextToken();
  9144. }
  9145. if (token === 37) {
  9146. return true;
  9147. }
  9148. if (isLiteralPropertyName()) {
  9149. idToken = token;
  9150. nextToken();
  9151. }
  9152. if (token === 19) {
  9153. return true;
  9154. }
  9155. if (idToken !== undefined) {
  9156. if (!ts.isKeyword(idToken) || idToken === 129 || idToken === 123) {
  9157. return true;
  9158. }
  9159. switch (token) {
  9160. case 17:
  9161. case 25:
  9162. case 54:
  9163. case 56:
  9164. case 53:
  9165. return true;
  9166. default:
  9167. return canParseSemicolon();
  9168. }
  9169. }
  9170. return false;
  9171. }
  9172. function parseDecorators() {
  9173. var decorators;
  9174. while (true) {
  9175. var decoratorStart = getNodePos();
  9176. if (!parseOptional(55)) {
  9177. break;
  9178. }
  9179. if (!decorators) {
  9180. decorators = [];
  9181. decorators.pos = scanner.getStartPos();
  9182. }
  9183. var decorator = createNode(139, decoratorStart);
  9184. decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher);
  9185. decorators.push(finishNode(decorator));
  9186. }
  9187. if (decorators) {
  9188. decorators.end = getNodeEnd();
  9189. }
  9190. return decorators;
  9191. }
  9192. function parseModifiers() {
  9193. var flags = 0;
  9194. var modifiers;
  9195. while (true) {
  9196. var modifierStart = scanner.getStartPos();
  9197. var modifierKind = token;
  9198. if (!parseAnyContextualModifier()) {
  9199. break;
  9200. }
  9201. if (!modifiers) {
  9202. modifiers = [];
  9203. modifiers.pos = modifierStart;
  9204. }
  9205. flags |= ts.modifierToFlag(modifierKind);
  9206. modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
  9207. }
  9208. if (modifiers) {
  9209. modifiers.flags = flags;
  9210. modifiers.end = scanner.getStartPos();
  9211. }
  9212. return modifiers;
  9213. }
  9214. function parseModifiersForArrowFunction() {
  9215. var flags = 0;
  9216. var modifiers;
  9217. if (token === 118) {
  9218. var modifierStart = scanner.getStartPos();
  9219. var modifierKind = token;
  9220. nextToken();
  9221. modifiers = [];
  9222. modifiers.pos = modifierStart;
  9223. flags |= ts.modifierToFlag(modifierKind);
  9224. modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
  9225. modifiers.flags = flags;
  9226. modifiers.end = scanner.getStartPos();
  9227. }
  9228. return modifiers;
  9229. }
  9230. function parseClassElement() {
  9231. if (token === 23) {
  9232. var result = createNode(191);
  9233. nextToken();
  9234. return finishNode(result);
  9235. }
  9236. var fullStart = getNodePos();
  9237. var decorators = parseDecorators();
  9238. var modifiers = parseModifiers();
  9239. var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
  9240. if (accessor) {
  9241. return accessor;
  9242. }
  9243. if (token === 121) {
  9244. return parseConstructorDeclaration(fullStart, decorators, modifiers);
  9245. }
  9246. if (isIndexSignature()) {
  9247. return parseIndexSignatureDeclaration(fullStart, decorators, modifiers);
  9248. }
  9249. if (ts.tokenIsIdentifierOrKeyword(token) ||
  9250. token === 9 ||
  9251. token === 8 ||
  9252. token === 37 ||
  9253. token === 19) {
  9254. return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers);
  9255. }
  9256. if (decorators || modifiers) {
  9257. var name_7 = createMissingNode(69, true, ts.Diagnostics.Declaration_expected);
  9258. return parsePropertyDeclaration(fullStart, decorators, modifiers, name_7, undefined);
  9259. }
  9260. ts.Debug.fail("Should not have attempted to parse class member declaration.");
  9261. }
  9262. function parseClassExpression() {
  9263. return parseClassDeclarationOrExpression(scanner.getStartPos(), undefined, undefined, 186);
  9264. }
  9265. function parseClassDeclaration(fullStart, decorators, modifiers) {
  9266. return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 214);
  9267. }
  9268. function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) {
  9269. var node = createNode(kind, fullStart);
  9270. node.decorators = decorators;
  9271. setModifiers(node, modifiers);
  9272. parseExpected(73);
  9273. node.name = parseNameOfClassDeclarationOrExpression();
  9274. node.typeParameters = parseTypeParameters();
  9275. node.heritageClauses = parseHeritageClauses(true);
  9276. if (parseExpected(15)) {
  9277. node.members = parseClassMembers();
  9278. parseExpected(16);
  9279. }
  9280. else {
  9281. node.members = createMissingList();
  9282. }
  9283. return finishNode(node);
  9284. }
  9285. function parseNameOfClassDeclarationOrExpression() {
  9286. return isIdentifier() && !isImplementsClause()
  9287. ? parseIdentifier()
  9288. : undefined;
  9289. }
  9290. function isImplementsClause() {
  9291. return token === 106 && lookAhead(nextTokenIsIdentifierOrKeyword);
  9292. }
  9293. function parseHeritageClauses(isClassHeritageClause) {
  9294. if (isHeritageClause()) {
  9295. return parseList(20, parseHeritageClause);
  9296. }
  9297. return undefined;
  9298. }
  9299. function parseHeritageClausesWorker() {
  9300. return parseList(20, parseHeritageClause);
  9301. }
  9302. function parseHeritageClause() {
  9303. if (token === 83 || token === 106) {
  9304. var node = createNode(243);
  9305. node.token = token;
  9306. nextToken();
  9307. node.types = parseDelimitedList(7, parseExpressionWithTypeArguments);
  9308. return finishNode(node);
  9309. }
  9310. return undefined;
  9311. }
  9312. function parseExpressionWithTypeArguments() {
  9313. var node = createNode(188);
  9314. node.expression = parseLeftHandSideExpressionOrHigher();
  9315. if (token === 25) {
  9316. node.typeArguments = parseBracketedList(18, parseType, 25, 27);
  9317. }
  9318. return finishNode(node);
  9319. }
  9320. function isHeritageClause() {
  9321. return token === 83 || token === 106;
  9322. }
  9323. function parseClassMembers() {
  9324. return parseList(5, parseClassElement);
  9325. }
  9326. function parseInterfaceDeclaration(fullStart, decorators, modifiers) {
  9327. var node = createNode(215, fullStart);
  9328. node.decorators = decorators;
  9329. setModifiers(node, modifiers);
  9330. parseExpected(107);
  9331. node.name = parseIdentifier();
  9332. node.typeParameters = parseTypeParameters();
  9333. node.heritageClauses = parseHeritageClauses(false);
  9334. node.members = parseObjectTypeMembers();
  9335. return finishNode(node);
  9336. }
  9337. function parseTypeAliasDeclaration(fullStart, decorators, modifiers) {
  9338. var node = createNode(216, fullStart);
  9339. node.decorators = decorators;
  9340. setModifiers(node, modifiers);
  9341. parseExpected(132);
  9342. node.name = parseIdentifier();
  9343. node.typeParameters = parseTypeParameters();
  9344. parseExpected(56);
  9345. node.type = parseType();
  9346. parseSemicolon();
  9347. return finishNode(node);
  9348. }
  9349. function parseEnumMember() {
  9350. var node = createNode(247, scanner.getStartPos());
  9351. node.name = parsePropertyName();
  9352. node.initializer = allowInAnd(parseNonParameterInitializer);
  9353. return finishNode(node);
  9354. }
  9355. function parseEnumDeclaration(fullStart, decorators, modifiers) {
  9356. var node = createNode(217, fullStart);
  9357. node.decorators = decorators;
  9358. setModifiers(node, modifiers);
  9359. parseExpected(81);
  9360. node.name = parseIdentifier();
  9361. if (parseExpected(15)) {
  9362. node.members = parseDelimitedList(6, parseEnumMember);
  9363. parseExpected(16);
  9364. }
  9365. else {
  9366. node.members = createMissingList();
  9367. }
  9368. return finishNode(node);
  9369. }
  9370. function parseModuleBlock() {
  9371. var node = createNode(219, scanner.getStartPos());
  9372. if (parseExpected(15)) {
  9373. node.statements = parseList(1, parseStatement);
  9374. parseExpected(16);
  9375. }
  9376. else {
  9377. node.statements = createMissingList();
  9378. }
  9379. return finishNode(node);
  9380. }
  9381. function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) {
  9382. var node = createNode(218, fullStart);
  9383. var namespaceFlag = flags & 131072;
  9384. node.decorators = decorators;
  9385. setModifiers(node, modifiers);
  9386. node.flags |= flags;
  9387. node.name = parseIdentifier();
  9388. node.body = parseOptional(21)
  9389. ? parseModuleOrNamespaceDeclaration(getNodePos(), undefined, undefined, 1 | namespaceFlag)
  9390. : parseModuleBlock();
  9391. return finishNode(node);
  9392. }
  9393. function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) {
  9394. var node = createNode(218, fullStart);
  9395. node.decorators = decorators;
  9396. setModifiers(node, modifiers);
  9397. node.name = parseLiteralNode(true);
  9398. node.body = parseModuleBlock();
  9399. return finishNode(node);
  9400. }
  9401. function parseModuleDeclaration(fullStart, decorators, modifiers) {
  9402. var flags = modifiers ? modifiers.flags : 0;
  9403. if (parseOptional(126)) {
  9404. flags |= 131072;
  9405. }
  9406. else {
  9407. parseExpected(125);
  9408. if (token === 9) {
  9409. return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers);
  9410. }
  9411. }
  9412. return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags);
  9413. }
  9414. function isExternalModuleReference() {
  9415. return token === 127 &&
  9416. lookAhead(nextTokenIsOpenParen);
  9417. }
  9418. function nextTokenIsOpenParen() {
  9419. return nextToken() === 17;
  9420. }
  9421. function nextTokenIsSlash() {
  9422. return nextToken() === 39;
  9423. }
  9424. function nextTokenIsCommaOrFromKeyword() {
  9425. nextToken();
  9426. return token === 24 ||
  9427. token === 133;
  9428. }
  9429. function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) {
  9430. parseExpected(89);
  9431. var afterImportPos = scanner.getStartPos();
  9432. var identifier;
  9433. if (isIdentifier()) {
  9434. identifier = parseIdentifier();
  9435. if (token !== 24 && token !== 133) {
  9436. var importEqualsDeclaration = createNode(221, fullStart);
  9437. importEqualsDeclaration.decorators = decorators;
  9438. setModifiers(importEqualsDeclaration, modifiers);
  9439. importEqualsDeclaration.name = identifier;
  9440. parseExpected(56);
  9441. importEqualsDeclaration.moduleReference = parseModuleReference();
  9442. parseSemicolon();
  9443. return finishNode(importEqualsDeclaration);
  9444. }
  9445. }
  9446. var importDeclaration = createNode(222, fullStart);
  9447. importDeclaration.decorators = decorators;
  9448. setModifiers(importDeclaration, modifiers);
  9449. if (identifier ||
  9450. token === 37 ||
  9451. token === 15) {
  9452. importDeclaration.importClause = parseImportClause(identifier, afterImportPos);
  9453. parseExpected(133);
  9454. }
  9455. importDeclaration.moduleSpecifier = parseModuleSpecifier();
  9456. parseSemicolon();
  9457. return finishNode(importDeclaration);
  9458. }
  9459. function parseImportClause(identifier, fullStart) {
  9460. var importClause = createNode(223, fullStart);
  9461. if (identifier) {
  9462. importClause.name = identifier;
  9463. }
  9464. if (!importClause.name ||
  9465. parseOptional(24)) {
  9466. importClause.namedBindings = token === 37 ? parseNamespaceImport() : parseNamedImportsOrExports(225);
  9467. }
  9468. return finishNode(importClause);
  9469. }
  9470. function parseModuleReference() {
  9471. return isExternalModuleReference()
  9472. ? parseExternalModuleReference()
  9473. : parseEntityName(false);
  9474. }
  9475. function parseExternalModuleReference() {
  9476. var node = createNode(232);
  9477. parseExpected(127);
  9478. parseExpected(17);
  9479. node.expression = parseModuleSpecifier();
  9480. parseExpected(18);
  9481. return finishNode(node);
  9482. }
  9483. function parseModuleSpecifier() {
  9484. var result = parseExpression();
  9485. if (result.kind === 9) {
  9486. internIdentifier(result.text);
  9487. }
  9488. return result;
  9489. }
  9490. function parseNamespaceImport() {
  9491. var namespaceImport = createNode(224);
  9492. parseExpected(37);
  9493. parseExpected(116);
  9494. namespaceImport.name = parseIdentifier();
  9495. return finishNode(namespaceImport);
  9496. }
  9497. function parseNamedImportsOrExports(kind) {
  9498. var node = createNode(kind);
  9499. node.elements = parseBracketedList(21, kind === 225 ? parseImportSpecifier : parseExportSpecifier, 15, 16);
  9500. return finishNode(node);
  9501. }
  9502. function parseExportSpecifier() {
  9503. return parseImportOrExportSpecifier(230);
  9504. }
  9505. function parseImportSpecifier() {
  9506. return parseImportOrExportSpecifier(226);
  9507. }
  9508. function parseImportOrExportSpecifier(kind) {
  9509. var node = createNode(kind);
  9510. var checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
  9511. var checkIdentifierStart = scanner.getTokenPos();
  9512. var checkIdentifierEnd = scanner.getTextPos();
  9513. var identifierName = parseIdentifierName();
  9514. if (token === 116) {
  9515. node.propertyName = identifierName;
  9516. parseExpected(116);
  9517. checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
  9518. checkIdentifierStart = scanner.getTokenPos();
  9519. checkIdentifierEnd = scanner.getTextPos();
  9520. node.name = parseIdentifierName();
  9521. }
  9522. else {
  9523. node.name = identifierName;
  9524. }
  9525. if (kind === 226 && checkIdentifierIsKeyword) {
  9526. parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected);
  9527. }
  9528. return finishNode(node);
  9529. }
  9530. function parseExportDeclaration(fullStart, decorators, modifiers) {
  9531. var node = createNode(228, fullStart);
  9532. node.decorators = decorators;
  9533. setModifiers(node, modifiers);
  9534. if (parseOptional(37)) {
  9535. parseExpected(133);
  9536. node.moduleSpecifier = parseModuleSpecifier();
  9537. }
  9538. else {
  9539. node.exportClause = parseNamedImportsOrExports(229);
  9540. if (token === 133 || (token === 9 && !scanner.hasPrecedingLineBreak())) {
  9541. parseExpected(133);
  9542. node.moduleSpecifier = parseModuleSpecifier();
  9543. }
  9544. }
  9545. parseSemicolon();
  9546. return finishNode(node);
  9547. }
  9548. function parseExportAssignment(fullStart, decorators, modifiers) {
  9549. var node = createNode(227, fullStart);
  9550. node.decorators = decorators;
  9551. setModifiers(node, modifiers);
  9552. if (parseOptional(56)) {
  9553. node.isExportEquals = true;
  9554. }
  9555. else {
  9556. parseExpected(77);
  9557. }
  9558. node.expression = parseAssignmentExpressionOrHigher();
  9559. parseSemicolon();
  9560. return finishNode(node);
  9561. }
  9562. function processReferenceComments(sourceFile) {
  9563. var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, 0, sourceText);
  9564. var referencedFiles = [];
  9565. var amdDependencies = [];
  9566. var amdModuleName;
  9567. while (true) {
  9568. var kind = triviaScanner.scan();
  9569. if (kind === 5 || kind === 4 || kind === 3) {
  9570. continue;
  9571. }
  9572. if (kind !== 2) {
  9573. break;
  9574. }
  9575. var range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos(), kind: triviaScanner.getToken() };
  9576. var comment = sourceText.substring(range.pos, range.end);
  9577. var referencePathMatchResult = ts.getFileReferenceFromReferencePath(comment, range);
  9578. if (referencePathMatchResult) {
  9579. var fileReference = referencePathMatchResult.fileReference;
  9580. sourceFile.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
  9581. var diagnosticMessage = referencePathMatchResult.diagnosticMessage;
  9582. if (fileReference) {
  9583. referencedFiles.push(fileReference);
  9584. }
  9585. if (diagnosticMessage) {
  9586. parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
  9587. }
  9588. }
  9589. else {
  9590. var amdModuleNameRegEx = /^\/\/\/\s*<amd-module\s+name\s*=\s*('|")(.+?)\1/gim;
  9591. var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
  9592. if (amdModuleNameMatchResult) {
  9593. if (amdModuleName) {
  9594. parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
  9595. }
  9596. amdModuleName = amdModuleNameMatchResult[2];
  9597. }
  9598. var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s/gim;
  9599. var pathRegex = /\spath\s*=\s*('|")(.+?)\1/gim;
  9600. var nameRegex = /\sname\s*=\s*('|")(.+?)\1/gim;
  9601. var amdDependencyMatchResult = amdDependencyRegEx.exec(comment);
  9602. if (amdDependencyMatchResult) {
  9603. var pathMatchResult = pathRegex.exec(comment);
  9604. var nameMatchResult = nameRegex.exec(comment);
  9605. if (pathMatchResult) {
  9606. var amdDependency = { path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
  9607. amdDependencies.push(amdDependency);
  9608. }
  9609. }
  9610. }
  9611. }
  9612. sourceFile.referencedFiles = referencedFiles;
  9613. sourceFile.amdDependencies = amdDependencies;
  9614. sourceFile.moduleName = amdModuleName;
  9615. }
  9616. function setExternalModuleIndicator(sourceFile) {
  9617. sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) {
  9618. return node.flags & 1
  9619. || node.kind === 221 && node.moduleReference.kind === 232
  9620. || node.kind === 222
  9621. || node.kind === 227
  9622. || node.kind === 228
  9623. ? node
  9624. : undefined;
  9625. });
  9626. }
  9627. var JSDocParser;
  9628. (function (JSDocParser) {
  9629. function isJSDocType() {
  9630. switch (token) {
  9631. case 37:
  9632. case 53:
  9633. case 17:
  9634. case 19:
  9635. case 49:
  9636. case 15:
  9637. case 87:
  9638. case 22:
  9639. case 92:
  9640. case 97:
  9641. return true;
  9642. }
  9643. return ts.tokenIsIdentifierOrKeyword(token);
  9644. }
  9645. JSDocParser.isJSDocType = isJSDocType;
  9646. function parseJSDocTypeExpressionForTests(content, start, length) {
  9647. initializeState("file.js", content, 2, undefined);
  9648. var jsDocTypeExpression = parseJSDocTypeExpression(start, length);
  9649. var diagnostics = parseDiagnostics;
  9650. clearState();
  9651. return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined;
  9652. }
  9653. JSDocParser.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests;
  9654. function parseJSDocTypeExpression(start, length) {
  9655. scanner.setText(sourceText, start, length);
  9656. token = nextToken();
  9657. var result = createNode(249);
  9658. parseExpected(15);
  9659. result.type = parseJSDocTopLevelType();
  9660. parseExpected(16);
  9661. fixupParentReferences(result);
  9662. return finishNode(result);
  9663. }
  9664. JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression;
  9665. function parseJSDocTopLevelType() {
  9666. var type = parseJSDocType();
  9667. if (token === 47) {
  9668. var unionType = createNode(253, type.pos);
  9669. unionType.types = parseJSDocTypeList(type);
  9670. type = finishNode(unionType);
  9671. }
  9672. if (token === 56) {
  9673. var optionalType = createNode(260, type.pos);
  9674. nextToken();
  9675. optionalType.type = type;
  9676. type = finishNode(optionalType);
  9677. }
  9678. return type;
  9679. }
  9680. function parseJSDocType() {
  9681. var type = parseBasicTypeExpression();
  9682. while (true) {
  9683. if (token === 19) {
  9684. var arrayType = createNode(252, type.pos);
  9685. arrayType.elementType = type;
  9686. nextToken();
  9687. parseExpected(20);
  9688. type = finishNode(arrayType);
  9689. }
  9690. else if (token === 53) {
  9691. var nullableType = createNode(255, type.pos);
  9692. nullableType.type = type;
  9693. nextToken();
  9694. type = finishNode(nullableType);
  9695. }
  9696. else if (token === 49) {
  9697. var nonNullableType = createNode(256, type.pos);
  9698. nonNullableType.type = type;
  9699. nextToken();
  9700. type = finishNode(nonNullableType);
  9701. }
  9702. else {
  9703. break;
  9704. }
  9705. }
  9706. return type;
  9707. }
  9708. function parseBasicTypeExpression() {
  9709. switch (token) {
  9710. case 37:
  9711. return parseJSDocAllType();
  9712. case 53:
  9713. return parseJSDocUnknownOrNullableType();
  9714. case 17:
  9715. return parseJSDocUnionType();
  9716. case 19:
  9717. return parseJSDocTupleType();
  9718. case 49:
  9719. return parseJSDocNonNullableType();
  9720. case 15:
  9721. return parseJSDocRecordType();
  9722. case 87:
  9723. return parseJSDocFunctionType();
  9724. case 22:
  9725. return parseJSDocVariadicType();
  9726. case 92:
  9727. return parseJSDocConstructorType();
  9728. case 97:
  9729. return parseJSDocThisType();
  9730. case 117:
  9731. case 130:
  9732. case 128:
  9733. case 120:
  9734. case 131:
  9735. case 103:
  9736. return parseTokenNode();
  9737. }
  9738. return parseJSDocTypeReference();
  9739. }
  9740. function parseJSDocThisType() {
  9741. var result = createNode(264);
  9742. nextToken();
  9743. parseExpected(54);
  9744. result.type = parseJSDocType();
  9745. return finishNode(result);
  9746. }
  9747. function parseJSDocConstructorType() {
  9748. var result = createNode(263);
  9749. nextToken();
  9750. parseExpected(54);
  9751. result.type = parseJSDocType();
  9752. return finishNode(result);
  9753. }
  9754. function parseJSDocVariadicType() {
  9755. var result = createNode(262);
  9756. nextToken();
  9757. result.type = parseJSDocType();
  9758. return finishNode(result);
  9759. }
  9760. function parseJSDocFunctionType() {
  9761. var result = createNode(261);
  9762. nextToken();
  9763. parseExpected(17);
  9764. result.parameters = parseDelimitedList(22, parseJSDocParameter);
  9765. checkForTrailingComma(result.parameters);
  9766. parseExpected(18);
  9767. if (token === 54) {
  9768. nextToken();
  9769. result.type = parseJSDocType();
  9770. }
  9771. return finishNode(result);
  9772. }
  9773. function parseJSDocParameter() {
  9774. var parameter = createNode(138);
  9775. parameter.type = parseJSDocType();
  9776. return finishNode(parameter);
  9777. }
  9778. function parseJSDocOptionalType(type) {
  9779. var result = createNode(260, type.pos);
  9780. nextToken();
  9781. result.type = type;
  9782. return finishNode(result);
  9783. }
  9784. function parseJSDocTypeReference() {
  9785. var result = createNode(259);
  9786. result.name = parseSimplePropertyName();
  9787. while (parseOptional(21)) {
  9788. if (token === 25) {
  9789. result.typeArguments = parseTypeArguments();
  9790. break;
  9791. }
  9792. else {
  9793. result.name = parseQualifiedName(result.name);
  9794. }
  9795. }
  9796. return finishNode(result);
  9797. }
  9798. function parseTypeArguments() {
  9799. nextToken();
  9800. var typeArguments = parseDelimitedList(23, parseJSDocType);
  9801. checkForTrailingComma(typeArguments);
  9802. checkForEmptyTypeArgumentList(typeArguments);
  9803. parseExpected(27);
  9804. return typeArguments;
  9805. }
  9806. function checkForEmptyTypeArgumentList(typeArguments) {
  9807. if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) {
  9808. var start = typeArguments.pos - "<".length;
  9809. var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length;
  9810. return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
  9811. }
  9812. }
  9813. function parseQualifiedName(left) {
  9814. var result = createNode(135, left.pos);
  9815. result.left = left;
  9816. result.right = parseIdentifierName();
  9817. return finishNode(result);
  9818. }
  9819. function parseJSDocRecordType() {
  9820. var result = createNode(257);
  9821. nextToken();
  9822. result.members = parseDelimitedList(24, parseJSDocRecordMember);
  9823. checkForTrailingComma(result.members);
  9824. parseExpected(16);
  9825. return finishNode(result);
  9826. }
  9827. function parseJSDocRecordMember() {
  9828. var result = createNode(258);
  9829. result.name = parseSimplePropertyName();
  9830. if (token === 54) {
  9831. nextToken();
  9832. result.type = parseJSDocType();
  9833. }
  9834. return finishNode(result);
  9835. }
  9836. function parseJSDocNonNullableType() {
  9837. var result = createNode(256);
  9838. nextToken();
  9839. result.type = parseJSDocType();
  9840. return finishNode(result);
  9841. }
  9842. function parseJSDocTupleType() {
  9843. var result = createNode(254);
  9844. nextToken();
  9845. result.types = parseDelimitedList(25, parseJSDocType);
  9846. checkForTrailingComma(result.types);
  9847. parseExpected(20);
  9848. return finishNode(result);
  9849. }
  9850. function checkForTrailingComma(list) {
  9851. if (parseDiagnostics.length === 0 && list.hasTrailingComma) {
  9852. var start = list.end - ",".length;
  9853. parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed);
  9854. }
  9855. }
  9856. function parseJSDocUnionType() {
  9857. var result = createNode(253);
  9858. nextToken();
  9859. result.types = parseJSDocTypeList(parseJSDocType());
  9860. parseExpected(18);
  9861. return finishNode(result);
  9862. }
  9863. function parseJSDocTypeList(firstType) {
  9864. ts.Debug.assert(!!firstType);
  9865. var types = [];
  9866. types.pos = firstType.pos;
  9867. types.push(firstType);
  9868. while (parseOptional(47)) {
  9869. types.push(parseJSDocType());
  9870. }
  9871. types.end = scanner.getStartPos();
  9872. return types;
  9873. }
  9874. function parseJSDocAllType() {
  9875. var result = createNode(250);
  9876. nextToken();
  9877. return finishNode(result);
  9878. }
  9879. function parseJSDocUnknownOrNullableType() {
  9880. var pos = scanner.getStartPos();
  9881. nextToken();
  9882. if (token === 24 ||
  9883. token === 16 ||
  9884. token === 18 ||
  9885. token === 27 ||
  9886. token === 56 ||
  9887. token === 47) {
  9888. var result = createNode(251, pos);
  9889. return finishNode(result);
  9890. }
  9891. else {
  9892. var result = createNode(255, pos);
  9893. result.type = parseJSDocType();
  9894. return finishNode(result);
  9895. }
  9896. }
  9897. function parseIsolatedJSDocComment(content, start, length) {
  9898. initializeState("file.js", content, 2, undefined);
  9899. var jsDocComment = parseJSDocComment(undefined, start, length);
  9900. var diagnostics = parseDiagnostics;
  9901. clearState();
  9902. return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined;
  9903. }
  9904. JSDocParser.parseIsolatedJSDocComment = parseIsolatedJSDocComment;
  9905. function parseJSDocComment(parent, start, length) {
  9906. var comment = parseJSDocCommentWorker(start, length);
  9907. if (comment) {
  9908. fixupParentReferences(comment);
  9909. comment.parent = parent;
  9910. }
  9911. return comment;
  9912. }
  9913. JSDocParser.parseJSDocComment = parseJSDocComment;
  9914. function parseJSDocCommentWorker(start, length) {
  9915. var content = sourceText;
  9916. start = start || 0;
  9917. var end = length === undefined ? content.length : start + length;
  9918. length = end - start;
  9919. ts.Debug.assert(start >= 0);
  9920. ts.Debug.assert(start <= end);
  9921. ts.Debug.assert(end <= content.length);
  9922. var tags;
  9923. var pos;
  9924. if (length >= "/** */".length) {
  9925. if (content.charCodeAt(start) === 47 &&
  9926. content.charCodeAt(start + 1) === 42 &&
  9927. content.charCodeAt(start + 2) === 42 &&
  9928. content.charCodeAt(start + 3) !== 42) {
  9929. var canParseTag = true;
  9930. var seenAsterisk = true;
  9931. for (pos = start + "/**".length; pos < end;) {
  9932. var ch = content.charCodeAt(pos);
  9933. pos++;
  9934. if (ch === 64 && canParseTag) {
  9935. parseTag();
  9936. canParseTag = false;
  9937. continue;
  9938. }
  9939. if (ts.isLineBreak(ch)) {
  9940. canParseTag = true;
  9941. seenAsterisk = false;
  9942. continue;
  9943. }
  9944. if (ts.isWhiteSpace(ch)) {
  9945. continue;
  9946. }
  9947. if (ch === 42) {
  9948. if (seenAsterisk) {
  9949. canParseTag = false;
  9950. }
  9951. seenAsterisk = true;
  9952. continue;
  9953. }
  9954. canParseTag = false;
  9955. }
  9956. }
  9957. }
  9958. return createJSDocComment();
  9959. function createJSDocComment() {
  9960. if (!tags) {
  9961. return undefined;
  9962. }
  9963. var result = createNode(265, start);
  9964. result.tags = tags;
  9965. return finishNode(result, end);
  9966. }
  9967. function skipWhitespace() {
  9968. while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) {
  9969. pos++;
  9970. }
  9971. }
  9972. function parseTag() {
  9973. ts.Debug.assert(content.charCodeAt(pos - 1) === 64);
  9974. var atToken = createNode(55, pos - 1);
  9975. atToken.end = pos;
  9976. var tagName = scanIdentifier();
  9977. if (!tagName) {
  9978. return;
  9979. }
  9980. var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName);
  9981. addTag(tag);
  9982. }
  9983. function handleTag(atToken, tagName) {
  9984. if (tagName) {
  9985. switch (tagName.text) {
  9986. case "param":
  9987. return handleParamTag(atToken, tagName);
  9988. case "return":
  9989. case "returns":
  9990. return handleReturnTag(atToken, tagName);
  9991. case "template":
  9992. return handleTemplateTag(atToken, tagName);
  9993. case "type":
  9994. return handleTypeTag(atToken, tagName);
  9995. }
  9996. }
  9997. return undefined;
  9998. }
  9999. function handleUnknownTag(atToken, tagName) {
  10000. var result = createNode(266, atToken.pos);
  10001. result.atToken = atToken;
  10002. result.tagName = tagName;
  10003. return finishNode(result, pos);
  10004. }
  10005. function addTag(tag) {
  10006. if (tag) {
  10007. if (!tags) {
  10008. tags = [];
  10009. tags.pos = tag.pos;
  10010. }
  10011. tags.push(tag);
  10012. tags.end = tag.end;
  10013. }
  10014. }
  10015. function tryParseTypeExpression() {
  10016. skipWhitespace();
  10017. if (content.charCodeAt(pos) !== 123) {
  10018. return undefined;
  10019. }
  10020. var typeExpression = parseJSDocTypeExpression(pos, end - pos);
  10021. pos = typeExpression.end;
  10022. return typeExpression;
  10023. }
  10024. function handleParamTag(atToken, tagName) {
  10025. var typeExpression = tryParseTypeExpression();
  10026. skipWhitespace();
  10027. var name;
  10028. var isBracketed;
  10029. if (content.charCodeAt(pos) === 91) {
  10030. pos++;
  10031. skipWhitespace();
  10032. name = scanIdentifier();
  10033. isBracketed = true;
  10034. }
  10035. else {
  10036. name = scanIdentifier();
  10037. }
  10038. if (!name) {
  10039. parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected);
  10040. }
  10041. var preName, postName;
  10042. if (typeExpression) {
  10043. postName = name;
  10044. }
  10045. else {
  10046. preName = name;
  10047. }
  10048. if (!typeExpression) {
  10049. typeExpression = tryParseTypeExpression();
  10050. }
  10051. var result = createNode(267, atToken.pos);
  10052. result.atToken = atToken;
  10053. result.tagName = tagName;
  10054. result.preParameterName = preName;
  10055. result.typeExpression = typeExpression;
  10056. result.postParameterName = postName;
  10057. result.isBracketed = isBracketed;
  10058. return finishNode(result, pos);
  10059. }
  10060. function handleReturnTag(atToken, tagName) {
  10061. if (ts.forEach(tags, function (t) { return t.kind === 268; })) {
  10062. parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
  10063. }
  10064. var result = createNode(268, atToken.pos);
  10065. result.atToken = atToken;
  10066. result.tagName = tagName;
  10067. result.typeExpression = tryParseTypeExpression();
  10068. return finishNode(result, pos);
  10069. }
  10070. function handleTypeTag(atToken, tagName) {
  10071. if (ts.forEach(tags, function (t) { return t.kind === 269; })) {
  10072. parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
  10073. }
  10074. var result = createNode(269, atToken.pos);
  10075. result.atToken = atToken;
  10076. result.tagName = tagName;
  10077. result.typeExpression = tryParseTypeExpression();
  10078. return finishNode(result, pos);
  10079. }
  10080. function handleTemplateTag(atToken, tagName) {
  10081. if (ts.forEach(tags, function (t) { return t.kind === 270; })) {
  10082. parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
  10083. }
  10084. var typeParameters = [];
  10085. typeParameters.pos = pos;
  10086. while (true) {
  10087. skipWhitespace();
  10088. var startPos = pos;
  10089. var name_8 = scanIdentifier();
  10090. if (!name_8) {
  10091. parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected);
  10092. return undefined;
  10093. }
  10094. var typeParameter = createNode(137, name_8.pos);
  10095. typeParameter.name = name_8;
  10096. finishNode(typeParameter, pos);
  10097. typeParameters.push(typeParameter);
  10098. skipWhitespace();
  10099. if (content.charCodeAt(pos) !== 44) {
  10100. break;
  10101. }
  10102. pos++;
  10103. }
  10104. typeParameters.end = pos;
  10105. var result = createNode(270, atToken.pos);
  10106. result.atToken = atToken;
  10107. result.tagName = tagName;
  10108. result.typeParameters = typeParameters;
  10109. return finishNode(result, pos);
  10110. }
  10111. function scanIdentifier() {
  10112. var startPos = pos;
  10113. for (; pos < end; pos++) {
  10114. var ch = content.charCodeAt(pos);
  10115. if (pos === startPos && ts.isIdentifierStart(ch, 2)) {
  10116. continue;
  10117. }
  10118. else if (pos > startPos && ts.isIdentifierPart(ch, 2)) {
  10119. continue;
  10120. }
  10121. break;
  10122. }
  10123. if (startPos === pos) {
  10124. return undefined;
  10125. }
  10126. var result = createNode(69, startPos);
  10127. result.text = content.substring(startPos, pos);
  10128. return finishNode(result, pos);
  10129. }
  10130. }
  10131. JSDocParser.parseJSDocCommentWorker = parseJSDocCommentWorker;
  10132. })(JSDocParser = Parser.JSDocParser || (Parser.JSDocParser = {}));
  10133. })(Parser || (Parser = {}));
  10134. var IncrementalParser;
  10135. (function (IncrementalParser) {
  10136. function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
  10137. aggressiveChecks = aggressiveChecks || ts.Debug.shouldAssert(2);
  10138. checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks);
  10139. if (ts.textChangeRangeIsUnchanged(textChangeRange)) {
  10140. return sourceFile;
  10141. }
  10142. if (sourceFile.statements.length === 0) {
  10143. return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, undefined, true);
  10144. }
  10145. var incrementalSourceFile = sourceFile;
  10146. ts.Debug.assert(!incrementalSourceFile.hasBeenIncrementallyParsed);
  10147. incrementalSourceFile.hasBeenIncrementallyParsed = true;
  10148. var oldText = sourceFile.text;
  10149. var syntaxCursor = createSyntaxCursor(sourceFile);
  10150. var changeRange = extendToAffectedRange(sourceFile, textChangeRange);
  10151. checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks);
  10152. ts.Debug.assert(changeRange.span.start <= textChangeRange.span.start);
  10153. ts.Debug.assert(ts.textSpanEnd(changeRange.span) === ts.textSpanEnd(textChangeRange.span));
  10154. ts.Debug.assert(ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)) === ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)));
  10155. var delta = ts.textChangeRangeNewSpan(changeRange).length - changeRange.span.length;
  10156. updateTokenPositionsAndMarkElements(incrementalSourceFile, changeRange.span.start, ts.textSpanEnd(changeRange.span), ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)), delta, oldText, newText, aggressiveChecks);
  10157. var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, true);
  10158. return result;
  10159. }
  10160. IncrementalParser.updateSourceFile = updateSourceFile;
  10161. function moveElementEntirelyPastChangeRange(element, isArray, delta, oldText, newText, aggressiveChecks) {
  10162. if (isArray) {
  10163. visitArray(element);
  10164. }
  10165. else {
  10166. visitNode(element);
  10167. }
  10168. return;
  10169. function visitNode(node) {
  10170. var text = "";
  10171. if (aggressiveChecks && shouldCheckNode(node)) {
  10172. text = oldText.substring(node.pos, node.end);
  10173. }
  10174. if (node._children) {
  10175. node._children = undefined;
  10176. }
  10177. if (node.jsDocComment) {
  10178. node.jsDocComment = undefined;
  10179. }
  10180. node.pos += delta;
  10181. node.end += delta;
  10182. if (aggressiveChecks && shouldCheckNode(node)) {
  10183. ts.Debug.assert(text === newText.substring(node.pos, node.end));
  10184. }
  10185. forEachChild(node, visitNode, visitArray);
  10186. checkNodePositions(node, aggressiveChecks);
  10187. }
  10188. function visitArray(array) {
  10189. array._children = undefined;
  10190. array.pos += delta;
  10191. array.end += delta;
  10192. for (var _i = 0; _i < array.length; _i++) {
  10193. var node = array[_i];
  10194. visitNode(node);
  10195. }
  10196. }
  10197. }
  10198. function shouldCheckNode(node) {
  10199. switch (node.kind) {
  10200. case 9:
  10201. case 8:
  10202. case 69:
  10203. return true;
  10204. }
  10205. return false;
  10206. }
  10207. function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) {
  10208. ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
  10209. ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
  10210. ts.Debug.assert(element.pos <= element.end);
  10211. element.pos = Math.min(element.pos, changeRangeNewEnd);
  10212. if (element.end >= changeRangeOldEnd) {
  10213. element.end += delta;
  10214. }
  10215. else {
  10216. element.end = Math.min(element.end, changeRangeNewEnd);
  10217. }
  10218. ts.Debug.assert(element.pos <= element.end);
  10219. if (element.parent) {
  10220. ts.Debug.assert(element.pos >= element.parent.pos);
  10221. ts.Debug.assert(element.end <= element.parent.end);
  10222. }
  10223. }
  10224. function checkNodePositions(node, aggressiveChecks) {
  10225. if (aggressiveChecks) {
  10226. var pos = node.pos;
  10227. forEachChild(node, function (child) {
  10228. ts.Debug.assert(child.pos >= pos);
  10229. pos = child.end;
  10230. });
  10231. ts.Debug.assert(pos <= node.end);
  10232. }
  10233. }
  10234. function updateTokenPositionsAndMarkElements(sourceFile, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta, oldText, newText, aggressiveChecks) {
  10235. visitNode(sourceFile);
  10236. return;
  10237. function visitNode(child) {
  10238. ts.Debug.assert(child.pos <= child.end);
  10239. if (child.pos > changeRangeOldEnd) {
  10240. moveElementEntirelyPastChangeRange(child, false, delta, oldText, newText, aggressiveChecks);
  10241. return;
  10242. }
  10243. var fullEnd = child.end;
  10244. if (fullEnd >= changeStart) {
  10245. child.intersectsChange = true;
  10246. child._children = undefined;
  10247. adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
  10248. forEachChild(child, visitNode, visitArray);
  10249. checkNodePositions(child, aggressiveChecks);
  10250. return;
  10251. }
  10252. ts.Debug.assert(fullEnd < changeStart);
  10253. }
  10254. function visitArray(array) {
  10255. ts.Debug.assert(array.pos <= array.end);
  10256. if (array.pos > changeRangeOldEnd) {
  10257. moveElementEntirelyPastChangeRange(array, true, delta, oldText, newText, aggressiveChecks);
  10258. return;
  10259. }
  10260. var fullEnd = array.end;
  10261. if (fullEnd >= changeStart) {
  10262. array.intersectsChange = true;
  10263. array._children = undefined;
  10264. adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
  10265. for (var _i = 0; _i < array.length; _i++) {
  10266. var node = array[_i];
  10267. visitNode(node);
  10268. }
  10269. return;
  10270. }
  10271. ts.Debug.assert(fullEnd < changeStart);
  10272. }
  10273. }
  10274. function extendToAffectedRange(sourceFile, changeRange) {
  10275. var maxLookahead = 1;
  10276. var start = changeRange.span.start;
  10277. for (var i = 0; start > 0 && i <= maxLookahead; i++) {
  10278. var nearestNode = findNearestNodeStartingBeforeOrAtPosition(sourceFile, start);
  10279. ts.Debug.assert(nearestNode.pos <= start);
  10280. var position = nearestNode.pos;
  10281. start = Math.max(0, position - 1);
  10282. }
  10283. var finalSpan = ts.createTextSpanFromBounds(start, ts.textSpanEnd(changeRange.span));
  10284. var finalLength = changeRange.newLength + (changeRange.span.start - start);
  10285. return ts.createTextChangeRange(finalSpan, finalLength);
  10286. }
  10287. function findNearestNodeStartingBeforeOrAtPosition(sourceFile, position) {
  10288. var bestResult = sourceFile;
  10289. var lastNodeEntirelyBeforePosition;
  10290. forEachChild(sourceFile, visit);
  10291. if (lastNodeEntirelyBeforePosition) {
  10292. var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition);
  10293. if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) {
  10294. bestResult = lastChildOfLastEntireNodeBeforePosition;
  10295. }
  10296. }
  10297. return bestResult;
  10298. function getLastChild(node) {
  10299. while (true) {
  10300. var lastChild = getLastChildWorker(node);
  10301. if (lastChild) {
  10302. node = lastChild;
  10303. }
  10304. else {
  10305. return node;
  10306. }
  10307. }
  10308. }
  10309. function getLastChildWorker(node) {
  10310. var last = undefined;
  10311. forEachChild(node, function (child) {
  10312. if (ts.nodeIsPresent(child)) {
  10313. last = child;
  10314. }
  10315. });
  10316. return last;
  10317. }
  10318. function visit(child) {
  10319. if (ts.nodeIsMissing(child)) {
  10320. return;
  10321. }
  10322. if (child.pos <= position) {
  10323. if (child.pos >= bestResult.pos) {
  10324. bestResult = child;
  10325. }
  10326. if (position < child.end) {
  10327. forEachChild(child, visit);
  10328. return true;
  10329. }
  10330. else {
  10331. ts.Debug.assert(child.end <= position);
  10332. lastNodeEntirelyBeforePosition = child;
  10333. }
  10334. }
  10335. else {
  10336. ts.Debug.assert(child.pos > position);
  10337. return true;
  10338. }
  10339. }
  10340. }
  10341. function checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks) {
  10342. var oldText = sourceFile.text;
  10343. if (textChangeRange) {
  10344. ts.Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length);
  10345. if (aggressiveChecks || ts.Debug.shouldAssert(3)) {
  10346. var oldTextPrefix = oldText.substr(0, textChangeRange.span.start);
  10347. var newTextPrefix = newText.substr(0, textChangeRange.span.start);
  10348. ts.Debug.assert(oldTextPrefix === newTextPrefix);
  10349. var oldTextSuffix = oldText.substring(ts.textSpanEnd(textChangeRange.span), oldText.length);
  10350. var newTextSuffix = newText.substring(ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)), newText.length);
  10351. ts.Debug.assert(oldTextSuffix === newTextSuffix);
  10352. }
  10353. }
  10354. }
  10355. function createSyntaxCursor(sourceFile) {
  10356. var currentArray = sourceFile.statements;
  10357. var currentArrayIndex = 0;
  10358. ts.Debug.assert(currentArrayIndex < currentArray.length);
  10359. var current = currentArray[currentArrayIndex];
  10360. var lastQueriedPosition = -1;
  10361. return {
  10362. currentNode: function (position) {
  10363. if (position !== lastQueriedPosition) {
  10364. if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) {
  10365. currentArrayIndex++;
  10366. current = currentArray[currentArrayIndex];
  10367. }
  10368. if (!current || current.pos !== position) {
  10369. findHighestListElementThatStartsAtPosition(position);
  10370. }
  10371. }
  10372. lastQueriedPosition = position;
  10373. ts.Debug.assert(!current || current.pos === position);
  10374. return current;
  10375. }
  10376. };
  10377. function findHighestListElementThatStartsAtPosition(position) {
  10378. currentArray = undefined;
  10379. currentArrayIndex = -1;
  10380. current = undefined;
  10381. forEachChild(sourceFile, visitNode, visitArray);
  10382. return;
  10383. function visitNode(node) {
  10384. if (position >= node.pos && position < node.end) {
  10385. forEachChild(node, visitNode, visitArray);
  10386. return true;
  10387. }
  10388. return false;
  10389. }
  10390. function visitArray(array) {
  10391. if (position >= array.pos && position < array.end) {
  10392. for (var i = 0, n = array.length; i < n; i++) {
  10393. var child = array[i];
  10394. if (child) {
  10395. if (child.pos === position) {
  10396. currentArray = array;
  10397. currentArrayIndex = i;
  10398. current = child;
  10399. return true;
  10400. }
  10401. else {
  10402. if (child.pos < position && position < child.end) {
  10403. forEachChild(child, visitNode, visitArray);
  10404. return true;
  10405. }
  10406. }
  10407. }
  10408. }
  10409. }
  10410. return false;
  10411. }
  10412. }
  10413. }
  10414. })(IncrementalParser || (IncrementalParser = {}));
  10415. })(ts || (ts = {}));
  10416. var ts;
  10417. (function (ts) {
  10418. var nextSymbolId = 1;
  10419. var nextNodeId = 1;
  10420. var nextMergeId = 1;
  10421. function getNodeId(node) {
  10422. if (!node.id)
  10423. node.id = nextNodeId++;
  10424. return node.id;
  10425. }
  10426. ts.getNodeId = getNodeId;
  10427. ts.checkTime = 0;
  10428. function getSymbolId(symbol) {
  10429. if (!symbol.id) {
  10430. symbol.id = nextSymbolId++;
  10431. }
  10432. return symbol.id;
  10433. }
  10434. ts.getSymbolId = getSymbolId;
  10435. function createTypeChecker(host, produceDiagnostics) {
  10436. var cancellationToken;
  10437. var Symbol = ts.objectAllocator.getSymbolConstructor();
  10438. var Type = ts.objectAllocator.getTypeConstructor();
  10439. var Signature = ts.objectAllocator.getSignatureConstructor();
  10440. var typeCount = 0;
  10441. var symbolCount = 0;
  10442. var emptyArray = [];
  10443. var emptySymbols = {};
  10444. var compilerOptions = host.getCompilerOptions();
  10445. var languageVersion = compilerOptions.target || 0;
  10446. var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 ? 5 : 0;
  10447. var emitResolver = createResolver();
  10448. var undefinedSymbol = createSymbol(4 | 67108864, "undefined");
  10449. var argumentsSymbol = createSymbol(4 | 67108864, "arguments");
  10450. var checker = {
  10451. getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); },
  10452. getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); },
  10453. getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount") + symbolCount; },
  10454. getTypeCount: function () { return typeCount; },
  10455. isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; },
  10456. isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; },
  10457. getDiagnostics: getDiagnostics,
  10458. getGlobalDiagnostics: getGlobalDiagnostics,
  10459. getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol,
  10460. getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
  10461. getPropertiesOfType: getPropertiesOfType,
  10462. getPropertyOfType: getPropertyOfType,
  10463. getSignaturesOfType: getSignaturesOfType,
  10464. getIndexTypeOfType: getIndexTypeOfType,
  10465. getBaseTypes: getBaseTypes,
  10466. getReturnTypeOfSignature: getReturnTypeOfSignature,
  10467. getSymbolsInScope: getSymbolsInScope,
  10468. getSymbolAtLocation: getSymbolAtLocation,
  10469. getShorthandAssignmentValueSymbol: getShorthandAssignmentValueSymbol,
  10470. getTypeAtLocation: getTypeOfNode,
  10471. typeToString: typeToString,
  10472. getSymbolDisplayBuilder: getSymbolDisplayBuilder,
  10473. symbolToString: symbolToString,
  10474. getAugmentedPropertiesOfType: getAugmentedPropertiesOfType,
  10475. getRootSymbols: getRootSymbols,
  10476. getContextualType: getContextualType,
  10477. getFullyQualifiedName: getFullyQualifiedName,
  10478. getResolvedSignature: getResolvedSignature,
  10479. getConstantValue: getConstantValue,
  10480. isValidPropertyAccess: isValidPropertyAccess,
  10481. getSignatureFromDeclaration: getSignatureFromDeclaration,
  10482. isImplementationOfOverload: isImplementationOfOverload,
  10483. getAliasedSymbol: resolveAlias,
  10484. getEmitResolver: getEmitResolver,
  10485. getExportsOfModule: getExportsOfModuleAsArray,
  10486. getJsxElementAttributesType: getJsxElementAttributesType,
  10487. getJsxIntrinsicTagNames: getJsxIntrinsicTagNames,
  10488. isOptionalParameter: isOptionalParameter
  10489. };
  10490. var unknownSymbol = createSymbol(4 | 67108864, "unknown");
  10491. var resolvingSymbol = createSymbol(67108864, "__resolving__");
  10492. var anyType = createIntrinsicType(1, "any");
  10493. var stringType = createIntrinsicType(2, "string");
  10494. var numberType = createIntrinsicType(4, "number");
  10495. var booleanType = createIntrinsicType(8, "boolean");
  10496. var esSymbolType = createIntrinsicType(16777216, "symbol");
  10497. var voidType = createIntrinsicType(16, "void");
  10498. var undefinedType = createIntrinsicType(32 | 2097152, "undefined");
  10499. var nullType = createIntrinsicType(64 | 2097152, "null");
  10500. var unknownType = createIntrinsicType(1, "unknown");
  10501. var circularType = createIntrinsicType(1, "__circular__");
  10502. var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10503. var emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10504. emptyGenericType.instantiations = {};
  10505. var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10506. anyFunctionType.flags |= 8388608;
  10507. var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10508. var anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false);
  10509. var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, false, false);
  10510. var globals = {};
  10511. var globalESSymbolConstructorSymbol;
  10512. var getGlobalPromiseConstructorSymbol;
  10513. var globalObjectType;
  10514. var globalFunctionType;
  10515. var globalArrayType;
  10516. var globalStringType;
  10517. var globalNumberType;
  10518. var globalBooleanType;
  10519. var globalRegExpType;
  10520. var globalTemplateStringsArrayType;
  10521. var globalESSymbolType;
  10522. var jsxElementType;
  10523. var jsxIntrinsicElementsType;
  10524. var globalIterableType;
  10525. var globalIteratorType;
  10526. var globalIterableIteratorType;
  10527. var anyArrayType;
  10528. var getGlobalClassDecoratorType;
  10529. var getGlobalParameterDecoratorType;
  10530. var getGlobalPropertyDecoratorType;
  10531. var getGlobalMethodDecoratorType;
  10532. var getGlobalTypedPropertyDescriptorType;
  10533. var getGlobalPromiseType;
  10534. var tryGetGlobalPromiseType;
  10535. var getGlobalPromiseLikeType;
  10536. var getInstantiatedGlobalPromiseLikeType;
  10537. var getGlobalPromiseConstructorLikeType;
  10538. var getGlobalThenableType;
  10539. var tupleTypes = {};
  10540. var unionTypes = {};
  10541. var intersectionTypes = {};
  10542. var stringLiteralTypes = {};
  10543. var emitExtends = false;
  10544. var emitDecorate = false;
  10545. var emitParam = false;
  10546. var emitAwaiter = false;
  10547. var emitGenerator = false;
  10548. var resolutionTargets = [];
  10549. var resolutionResults = [];
  10550. var resolutionPropertyNames = [];
  10551. var mergedSymbols = [];
  10552. var symbolLinks = [];
  10553. var nodeLinks = [];
  10554. var potentialThisCollisions = [];
  10555. var awaitedTypeStack = [];
  10556. var diagnostics = ts.createDiagnosticCollection();
  10557. var primitiveTypeInfo = {
  10558. "string": {
  10559. type: stringType,
  10560. flags: 258
  10561. },
  10562. "number": {
  10563. type: numberType,
  10564. flags: 132
  10565. },
  10566. "boolean": {
  10567. type: booleanType,
  10568. flags: 8
  10569. },
  10570. "symbol": {
  10571. type: esSymbolType,
  10572. flags: 16777216
  10573. }
  10574. };
  10575. var JsxNames = {
  10576. JSX: "JSX",
  10577. IntrinsicElements: "IntrinsicElements",
  10578. ElementClass: "ElementClass",
  10579. ElementAttributesPropertyNameContainer: "ElementAttributesProperty",
  10580. Element: "Element"
  10581. };
  10582. var subtypeRelation = {};
  10583. var assignableRelation = {};
  10584. var identityRelation = {};
  10585. var _displayBuilder;
  10586. initializeTypeChecker();
  10587. return checker;
  10588. function getEmitResolver(sourceFile, cancellationToken) {
  10589. getDiagnostics(sourceFile, cancellationToken);
  10590. return emitResolver;
  10591. }
  10592. function error(location, message, arg0, arg1, arg2) {
  10593. var diagnostic = location
  10594. ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2)
  10595. : ts.createCompilerDiagnostic(message, arg0, arg1, arg2);
  10596. diagnostics.add(diagnostic);
  10597. }
  10598. function createSymbol(flags, name) {
  10599. symbolCount++;
  10600. return new Symbol(flags, name);
  10601. }
  10602. function getExcludedSymbolFlags(flags) {
  10603. var result = 0;
  10604. if (flags & 2)
  10605. result |= 107455;
  10606. if (flags & 1)
  10607. result |= 107454;
  10608. if (flags & 4)
  10609. result |= 107455;
  10610. if (flags & 8)
  10611. result |= 107455;
  10612. if (flags & 16)
  10613. result |= 106927;
  10614. if (flags & 32)
  10615. result |= 899519;
  10616. if (flags & 64)
  10617. result |= 792960;
  10618. if (flags & 256)
  10619. result |= 899327;
  10620. if (flags & 128)
  10621. result |= 899967;
  10622. if (flags & 512)
  10623. result |= 106639;
  10624. if (flags & 8192)
  10625. result |= 99263;
  10626. if (flags & 32768)
  10627. result |= 41919;
  10628. if (flags & 65536)
  10629. result |= 74687;
  10630. if (flags & 262144)
  10631. result |= 530912;
  10632. if (flags & 524288)
  10633. result |= 793056;
  10634. if (flags & 8388608)
  10635. result |= 8388608;
  10636. return result;
  10637. }
  10638. function recordMergedSymbol(target, source) {
  10639. if (!source.mergeId)
  10640. source.mergeId = nextMergeId++;
  10641. mergedSymbols[source.mergeId] = target;
  10642. }
  10643. function cloneSymbol(symbol) {
  10644. var result = createSymbol(symbol.flags | 33554432, symbol.name);
  10645. result.declarations = symbol.declarations.slice(0);
  10646. result.parent = symbol.parent;
  10647. if (symbol.valueDeclaration)
  10648. result.valueDeclaration = symbol.valueDeclaration;
  10649. if (symbol.constEnumOnlyModule)
  10650. result.constEnumOnlyModule = true;
  10651. if (symbol.members)
  10652. result.members = cloneSymbolTable(symbol.members);
  10653. if (symbol.exports)
  10654. result.exports = cloneSymbolTable(symbol.exports);
  10655. recordMergedSymbol(result, symbol);
  10656. return result;
  10657. }
  10658. function mergeSymbol(target, source) {
  10659. if (!(target.flags & getExcludedSymbolFlags(source.flags))) {
  10660. if (source.flags & 512 && target.flags & 512 && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
  10661. target.constEnumOnlyModule = false;
  10662. }
  10663. target.flags |= source.flags;
  10664. if (!target.valueDeclaration && source.valueDeclaration)
  10665. target.valueDeclaration = source.valueDeclaration;
  10666. ts.forEach(source.declarations, function (node) {
  10667. target.declarations.push(node);
  10668. });
  10669. if (source.members) {
  10670. if (!target.members)
  10671. target.members = {};
  10672. mergeSymbolTable(target.members, source.members);
  10673. }
  10674. if (source.exports) {
  10675. if (!target.exports)
  10676. target.exports = {};
  10677. mergeSymbolTable(target.exports, source.exports);
  10678. }
  10679. recordMergedSymbol(target, source);
  10680. }
  10681. else {
  10682. var message = target.flags & 2 || source.flags & 2
  10683. ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0;
  10684. ts.forEach(source.declarations, function (node) {
  10685. error(node.name ? node.name : node, message, symbolToString(source));
  10686. });
  10687. ts.forEach(target.declarations, function (node) {
  10688. error(node.name ? node.name : node, message, symbolToString(source));
  10689. });
  10690. }
  10691. }
  10692. function cloneSymbolTable(symbolTable) {
  10693. var result = {};
  10694. for (var id in symbolTable) {
  10695. if (ts.hasProperty(symbolTable, id)) {
  10696. result[id] = symbolTable[id];
  10697. }
  10698. }
  10699. return result;
  10700. }
  10701. function mergeSymbolTable(target, source) {
  10702. for (var id in source) {
  10703. if (ts.hasProperty(source, id)) {
  10704. if (!ts.hasProperty(target, id)) {
  10705. target[id] = source[id];
  10706. }
  10707. else {
  10708. var symbol = target[id];
  10709. if (!(symbol.flags & 33554432)) {
  10710. target[id] = symbol = cloneSymbol(symbol);
  10711. }
  10712. mergeSymbol(symbol, source[id]);
  10713. }
  10714. }
  10715. }
  10716. }
  10717. function getSymbolLinks(symbol) {
  10718. if (symbol.flags & 67108864)
  10719. return symbol;
  10720. var id = getSymbolId(symbol);
  10721. return symbolLinks[id] || (symbolLinks[id] = {});
  10722. }
  10723. function getNodeLinks(node) {
  10724. var nodeId = getNodeId(node);
  10725. return nodeLinks[nodeId] || (nodeLinks[nodeId] = {});
  10726. }
  10727. function getSourceFile(node) {
  10728. return ts.getAncestor(node, 248);
  10729. }
  10730. function isGlobalSourceFile(node) {
  10731. return node.kind === 248 && !ts.isExternalModule(node);
  10732. }
  10733. function getSymbol(symbols, name, meaning) {
  10734. if (meaning && ts.hasProperty(symbols, name)) {
  10735. var symbol = symbols[name];
  10736. ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here.");
  10737. if (symbol.flags & meaning) {
  10738. return symbol;
  10739. }
  10740. if (symbol.flags & 8388608) {
  10741. var target = resolveAlias(symbol);
  10742. if (target === unknownSymbol || target.flags & meaning) {
  10743. return symbol;
  10744. }
  10745. }
  10746. }
  10747. }
  10748. function isBlockScopedNameDeclaredBeforeUse(declaration, usage) {
  10749. var declarationFile = ts.getSourceFileOfNode(declaration);
  10750. var useFile = ts.getSourceFileOfNode(usage);
  10751. if (declarationFile !== useFile) {
  10752. if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) {
  10753. return true;
  10754. }
  10755. var sourceFiles = host.getSourceFiles();
  10756. return ts.indexOf(sourceFiles, declarationFile) <= ts.indexOf(sourceFiles, useFile);
  10757. }
  10758. if (declaration.pos <= usage.pos) {
  10759. return declaration.kind !== 211 ||
  10760. !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage);
  10761. }
  10762. return isUsedInFunctionOrNonStaticProperty(declaration, usage);
  10763. function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage) {
  10764. var container = ts.getEnclosingBlockScopeContainer(declaration);
  10765. if (declaration.parent.parent.kind === 193 ||
  10766. declaration.parent.parent.kind === 199) {
  10767. return isSameScopeDescendentOf(usage, declaration, container);
  10768. }
  10769. else if (declaration.parent.parent.kind === 201 ||
  10770. declaration.parent.parent.kind === 200) {
  10771. var expression = declaration.parent.parent.expression;
  10772. return isSameScopeDescendentOf(usage, expression, container);
  10773. }
  10774. }
  10775. function isUsedInFunctionOrNonStaticProperty(declaration, usage) {
  10776. var container = ts.getEnclosingBlockScopeContainer(declaration);
  10777. var current = usage;
  10778. while (current) {
  10779. if (current === container) {
  10780. return false;
  10781. }
  10782. if (ts.isFunctionLike(current)) {
  10783. return true;
  10784. }
  10785. var initializerOfNonStaticProperty = current.parent &&
  10786. current.parent.kind === 141 &&
  10787. (current.parent.flags & 128) === 0 &&
  10788. current.parent.initializer === current;
  10789. if (initializerOfNonStaticProperty) {
  10790. return true;
  10791. }
  10792. current = current.parent;
  10793. }
  10794. return false;
  10795. }
  10796. }
  10797. function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) {
  10798. var result;
  10799. var lastLocation;
  10800. var propertyWithInvalidInitializer;
  10801. var errorLocation = location;
  10802. var grandparent;
  10803. loop: while (location) {
  10804. if (location.locals && !isGlobalSourceFile(location)) {
  10805. if (result = getSymbol(location.locals, name, meaning)) {
  10806. if (!(meaning & 793056) ||
  10807. !(result.flags & (793056 & ~262144)) ||
  10808. !ts.isFunctionLike(location) ||
  10809. lastLocation === location.body) {
  10810. break loop;
  10811. }
  10812. result = undefined;
  10813. }
  10814. }
  10815. switch (location.kind) {
  10816. case 248:
  10817. if (!ts.isExternalModule(location))
  10818. break;
  10819. case 218:
  10820. var moduleExports = getSymbolOfNode(location).exports;
  10821. if (location.kind === 248 ||
  10822. (location.kind === 218 && location.name.kind === 9)) {
  10823. if (ts.hasProperty(moduleExports, name) &&
  10824. moduleExports[name].flags === 8388608 &&
  10825. ts.getDeclarationOfKind(moduleExports[name], 230)) {
  10826. break;
  10827. }
  10828. result = moduleExports["default"];
  10829. var localSymbol = ts.getLocalSymbolForExportDefault(result);
  10830. if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
  10831. break loop;
  10832. }
  10833. result = undefined;
  10834. }
  10835. if (result = getSymbol(moduleExports, name, meaning & 8914931)) {
  10836. break loop;
  10837. }
  10838. break;
  10839. case 217:
  10840. if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) {
  10841. break loop;
  10842. }
  10843. break;
  10844. case 141:
  10845. case 140:
  10846. if (ts.isClassLike(location.parent) && !(location.flags & 128)) {
  10847. var ctor = findConstructorDeclaration(location.parent);
  10848. if (ctor && ctor.locals) {
  10849. if (getSymbol(ctor.locals, name, meaning & 107455)) {
  10850. propertyWithInvalidInitializer = location;
  10851. }
  10852. }
  10853. }
  10854. break;
  10855. case 214:
  10856. case 186:
  10857. case 215:
  10858. if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) {
  10859. if (lastLocation && lastLocation.flags & 128) {
  10860. error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters);
  10861. return undefined;
  10862. }
  10863. break loop;
  10864. }
  10865. if (location.kind === 186 && meaning & 32) {
  10866. var className = location.name;
  10867. if (className && name === className.text) {
  10868. result = location.symbol;
  10869. break loop;
  10870. }
  10871. }
  10872. break;
  10873. case 136:
  10874. grandparent = location.parent.parent;
  10875. if (ts.isClassLike(grandparent) || grandparent.kind === 215) {
  10876. if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) {
  10877. error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
  10878. return undefined;
  10879. }
  10880. }
  10881. break;
  10882. case 143:
  10883. case 142:
  10884. case 144:
  10885. case 145:
  10886. case 146:
  10887. case 213:
  10888. case 174:
  10889. if (meaning & 3 && name === "arguments") {
  10890. result = argumentsSymbol;
  10891. break loop;
  10892. }
  10893. break;
  10894. case 173:
  10895. if (meaning & 3 && name === "arguments") {
  10896. result = argumentsSymbol;
  10897. break loop;
  10898. }
  10899. if (meaning & 16) {
  10900. var functionName = location.name;
  10901. if (functionName && name === functionName.text) {
  10902. result = location.symbol;
  10903. break loop;
  10904. }
  10905. }
  10906. break;
  10907. case 139:
  10908. if (location.parent && location.parent.kind === 138) {
  10909. location = location.parent;
  10910. }
  10911. if (location.parent && ts.isClassElement(location.parent)) {
  10912. location = location.parent;
  10913. }
  10914. break;
  10915. }
  10916. lastLocation = location;
  10917. location = location.parent;
  10918. }
  10919. if (!result) {
  10920. result = getSymbol(globals, name, meaning);
  10921. }
  10922. if (!result) {
  10923. if (nameNotFoundMessage) {
  10924. error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg));
  10925. }
  10926. return undefined;
  10927. }
  10928. if (nameNotFoundMessage) {
  10929. if (propertyWithInvalidInitializer) {
  10930. var propertyName = propertyWithInvalidInitializer.name;
  10931. error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg));
  10932. return undefined;
  10933. }
  10934. if (meaning & 2) {
  10935. var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
  10936. if (exportOrLocalSymbol.flags & 2) {
  10937. checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
  10938. }
  10939. }
  10940. }
  10941. return result;
  10942. }
  10943. function checkResolvedBlockScopedVariable(result, errorLocation) {
  10944. ts.Debug.assert((result.flags & 2) !== 0);
  10945. var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; });
  10946. ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
  10947. if (!isBlockScopedNameDeclaredBeforeUse(ts.getAncestor(declaration, 211), errorLocation)) {
  10948. error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name));
  10949. }
  10950. }
  10951. function isSameScopeDescendentOf(initial, parent, stopAt) {
  10952. if (!parent) {
  10953. return false;
  10954. }
  10955. for (var current = initial; current && current !== stopAt && !ts.isFunctionLike(current); current = current.parent) {
  10956. if (current === parent) {
  10957. return true;
  10958. }
  10959. }
  10960. return false;
  10961. }
  10962. function getAnyImportSyntax(node) {
  10963. if (ts.isAliasSymbolDeclaration(node)) {
  10964. if (node.kind === 221) {
  10965. return node;
  10966. }
  10967. while (node && node.kind !== 222) {
  10968. node = node.parent;
  10969. }
  10970. return node;
  10971. }
  10972. }
  10973. function getDeclarationOfAliasSymbol(symbol) {
  10974. return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; });
  10975. }
  10976. function getTargetOfImportEqualsDeclaration(node) {
  10977. if (node.moduleReference.kind === 232) {
  10978. return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node)));
  10979. }
  10980. return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node);
  10981. }
  10982. function getTargetOfImportClause(node) {
  10983. var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier);
  10984. if (moduleSymbol) {
  10985. var exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]);
  10986. if (!exportDefaultSymbol) {
  10987. error(node.name, ts.Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
  10988. }
  10989. return exportDefaultSymbol;
  10990. }
  10991. }
  10992. function getTargetOfNamespaceImport(node) {
  10993. var moduleSpecifier = node.parent.parent.moduleSpecifier;
  10994. return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
  10995. }
  10996. function getMemberOfModuleVariable(moduleSymbol, name) {
  10997. if (moduleSymbol.flags & 3) {
  10998. var typeAnnotation = moduleSymbol.valueDeclaration.type;
  10999. if (typeAnnotation) {
  11000. return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
  11001. }
  11002. }
  11003. }
  11004. function combineValueAndTypeSymbols(valueSymbol, typeSymbol) {
  11005. if (valueSymbol.flags & (793056 | 1536)) {
  11006. return valueSymbol;
  11007. }
  11008. var result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
  11009. result.declarations = ts.concatenate(valueSymbol.declarations, typeSymbol.declarations);
  11010. result.parent = valueSymbol.parent || typeSymbol.parent;
  11011. if (valueSymbol.valueDeclaration)
  11012. result.valueDeclaration = valueSymbol.valueDeclaration;
  11013. if (typeSymbol.members)
  11014. result.members = typeSymbol.members;
  11015. if (valueSymbol.exports)
  11016. result.exports = valueSymbol.exports;
  11017. return result;
  11018. }
  11019. function getExportOfModule(symbol, name) {
  11020. if (symbol.flags & 1536) {
  11021. var exports = getExportsOfSymbol(symbol);
  11022. if (ts.hasProperty(exports, name)) {
  11023. return resolveSymbol(exports[name]);
  11024. }
  11025. }
  11026. }
  11027. function getPropertyOfVariable(symbol, name) {
  11028. if (symbol.flags & 3) {
  11029. var typeAnnotation = symbol.valueDeclaration.type;
  11030. if (typeAnnotation) {
  11031. return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name));
  11032. }
  11033. }
  11034. }
  11035. function getExternalModuleMember(node, specifier) {
  11036. var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
  11037. var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
  11038. if (targetSymbol) {
  11039. var name_9 = specifier.propertyName || specifier.name;
  11040. if (name_9.text) {
  11041. var symbolFromModule = getExportOfModule(targetSymbol, name_9.text);
  11042. var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_9.text);
  11043. var symbol = symbolFromModule && symbolFromVariable ?
  11044. combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
  11045. symbolFromModule || symbolFromVariable;
  11046. if (!symbol) {
  11047. error(name_9, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_9));
  11048. }
  11049. return symbol;
  11050. }
  11051. }
  11052. }
  11053. function getTargetOfImportSpecifier(node) {
  11054. return getExternalModuleMember(node.parent.parent.parent, node);
  11055. }
  11056. function getTargetOfExportSpecifier(node) {
  11057. return node.parent.parent.moduleSpecifier ?
  11058. getExternalModuleMember(node.parent.parent, node) :
  11059. resolveEntityName(node.propertyName || node.name, 107455 | 793056 | 1536);
  11060. }
  11061. function getTargetOfExportAssignment(node) {
  11062. return resolveEntityName(node.expression, 107455 | 793056 | 1536);
  11063. }
  11064. function getTargetOfAliasDeclaration(node) {
  11065. switch (node.kind) {
  11066. case 221:
  11067. return getTargetOfImportEqualsDeclaration(node);
  11068. case 223:
  11069. return getTargetOfImportClause(node);
  11070. case 224:
  11071. return getTargetOfNamespaceImport(node);
  11072. case 226:
  11073. return getTargetOfImportSpecifier(node);
  11074. case 230:
  11075. return getTargetOfExportSpecifier(node);
  11076. case 227:
  11077. return getTargetOfExportAssignment(node);
  11078. }
  11079. }
  11080. function resolveSymbol(symbol) {
  11081. return symbol && symbol.flags & 8388608 && !(symbol.flags & (107455 | 793056 | 1536)) ? resolveAlias(symbol) : symbol;
  11082. }
  11083. function resolveAlias(symbol) {
  11084. ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Alias here.");
  11085. var links = getSymbolLinks(symbol);
  11086. if (!links.target) {
  11087. links.target = resolvingSymbol;
  11088. var node = getDeclarationOfAliasSymbol(symbol);
  11089. var target = getTargetOfAliasDeclaration(node);
  11090. if (links.target === resolvingSymbol) {
  11091. links.target = target || unknownSymbol;
  11092. }
  11093. else {
  11094. error(node, ts.Diagnostics.Circular_definition_of_import_alias_0, symbolToString(symbol));
  11095. }
  11096. }
  11097. else if (links.target === resolvingSymbol) {
  11098. links.target = unknownSymbol;
  11099. }
  11100. return links.target;
  11101. }
  11102. function markExportAsReferenced(node) {
  11103. var symbol = getSymbolOfNode(node);
  11104. var target = resolveAlias(symbol);
  11105. if (target) {
  11106. var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) ||
  11107. (target !== unknownSymbol && (target.flags & 107455) && !isConstEnumOrConstEnumOnlyModule(target));
  11108. if (markAlias) {
  11109. markAliasSymbolAsReferenced(symbol);
  11110. }
  11111. }
  11112. }
  11113. function markAliasSymbolAsReferenced(symbol) {
  11114. var links = getSymbolLinks(symbol);
  11115. if (!links.referenced) {
  11116. links.referenced = true;
  11117. var node = getDeclarationOfAliasSymbol(symbol);
  11118. if (node.kind === 227) {
  11119. checkExpressionCached(node.expression);
  11120. }
  11121. else if (node.kind === 230) {
  11122. checkExpressionCached(node.propertyName || node.name);
  11123. }
  11124. else if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  11125. checkExpressionCached(node.moduleReference);
  11126. }
  11127. }
  11128. }
  11129. function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) {
  11130. if (!importDeclaration) {
  11131. importDeclaration = ts.getAncestor(entityName, 221);
  11132. ts.Debug.assert(importDeclaration !== undefined);
  11133. }
  11134. if (entityName.kind === 69 && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
  11135. entityName = entityName.parent;
  11136. }
  11137. if (entityName.kind === 69 || entityName.parent.kind === 135) {
  11138. return resolveEntityName(entityName, 1536);
  11139. }
  11140. else {
  11141. ts.Debug.assert(entityName.parent.kind === 221);
  11142. return resolveEntityName(entityName, 107455 | 793056 | 1536);
  11143. }
  11144. }
  11145. function getFullyQualifiedName(symbol) {
  11146. return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
  11147. }
  11148. function resolveEntityName(name, meaning, ignoreErrors) {
  11149. if (ts.nodeIsMissing(name)) {
  11150. return undefined;
  11151. }
  11152. var symbol;
  11153. if (name.kind === 69) {
  11154. var message = meaning === 1536 ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0;
  11155. symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name);
  11156. if (!symbol) {
  11157. return undefined;
  11158. }
  11159. }
  11160. else if (name.kind === 135 || name.kind === 166) {
  11161. var left = name.kind === 135 ? name.left : name.expression;
  11162. var right = name.kind === 135 ? name.right : name.name;
  11163. var namespace = resolveEntityName(left, 1536, ignoreErrors);
  11164. if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) {
  11165. return undefined;
  11166. }
  11167. symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
  11168. if (!symbol) {
  11169. if (!ignoreErrors) {
  11170. error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right));
  11171. }
  11172. return undefined;
  11173. }
  11174. }
  11175. else {
  11176. ts.Debug.fail("Unknown entity name kind.");
  11177. }
  11178. ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here.");
  11179. return symbol.flags & meaning ? symbol : resolveAlias(symbol);
  11180. }
  11181. function resolveExternalModuleName(location, moduleReferenceExpression) {
  11182. if (moduleReferenceExpression.kind !== 9) {
  11183. return;
  11184. }
  11185. var moduleReferenceLiteral = moduleReferenceExpression;
  11186. var searchPath = ts.getDirectoryPath(getSourceFile(location).fileName);
  11187. var moduleName = ts.escapeIdentifier(moduleReferenceLiteral.text);
  11188. if (moduleName === undefined) {
  11189. return;
  11190. }
  11191. var isRelative = ts.isExternalModuleNameRelative(moduleName);
  11192. if (!isRelative) {
  11193. var symbol = getSymbol(globals, "\"" + moduleName + "\"", 512);
  11194. if (symbol) {
  11195. return symbol;
  11196. }
  11197. }
  11198. var resolvedModule = ts.getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text);
  11199. var sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName);
  11200. if (sourceFile) {
  11201. if (sourceFile.symbol) {
  11202. return sourceFile.symbol;
  11203. }
  11204. error(moduleReferenceLiteral, ts.Diagnostics.File_0_is_not_a_module, sourceFile.fileName);
  11205. return;
  11206. }
  11207. error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_module_0, moduleName);
  11208. }
  11209. function resolveExternalModuleSymbol(moduleSymbol) {
  11210. return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol;
  11211. }
  11212. function resolveESModuleSymbol(moduleSymbol, moduleReferenceExpression) {
  11213. var symbol = resolveExternalModuleSymbol(moduleSymbol);
  11214. if (symbol && !(symbol.flags & (1536 | 3))) {
  11215. error(moduleReferenceExpression, ts.Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
  11216. symbol = undefined;
  11217. }
  11218. return symbol;
  11219. }
  11220. function getExportAssignmentSymbol(moduleSymbol) {
  11221. return moduleSymbol.exports["export="];
  11222. }
  11223. function getExportsOfModuleAsArray(moduleSymbol) {
  11224. return symbolsToArray(getExportsOfModule(moduleSymbol));
  11225. }
  11226. function getExportsOfSymbol(symbol) {
  11227. return symbol.flags & 1536 ? getExportsOfModule(symbol) : symbol.exports || emptySymbols;
  11228. }
  11229. function getExportsOfModule(moduleSymbol) {
  11230. var links = getSymbolLinks(moduleSymbol);
  11231. return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
  11232. }
  11233. function extendExportSymbols(target, source) {
  11234. for (var id in source) {
  11235. if (id !== "default" && !ts.hasProperty(target, id)) {
  11236. target[id] = source[id];
  11237. }
  11238. }
  11239. }
  11240. function getExportsForModule(moduleSymbol) {
  11241. var result;
  11242. var visitedSymbols = [];
  11243. visit(moduleSymbol);
  11244. return result || moduleSymbol.exports;
  11245. function visit(symbol) {
  11246. if (symbol && symbol.flags & 1952 && !ts.contains(visitedSymbols, symbol)) {
  11247. visitedSymbols.push(symbol);
  11248. if (symbol !== moduleSymbol) {
  11249. if (!result) {
  11250. result = cloneSymbolTable(moduleSymbol.exports);
  11251. }
  11252. extendExportSymbols(result, symbol.exports);
  11253. }
  11254. var exportStars = symbol.exports["__export"];
  11255. if (exportStars) {
  11256. for (var _i = 0, _a = exportStars.declarations; _i < _a.length; _i++) {
  11257. var node = _a[_i];
  11258. visit(resolveExternalModuleName(node, node.moduleSpecifier));
  11259. }
  11260. }
  11261. }
  11262. }
  11263. }
  11264. function getMergedSymbol(symbol) {
  11265. var merged;
  11266. return symbol && symbol.mergeId && (merged = mergedSymbols[symbol.mergeId]) ? merged : symbol;
  11267. }
  11268. function getSymbolOfNode(node) {
  11269. return getMergedSymbol(node.symbol);
  11270. }
  11271. function getParentOfSymbol(symbol) {
  11272. return getMergedSymbol(symbol.parent);
  11273. }
  11274. function getExportSymbolOfValueSymbolIfExported(symbol) {
  11275. return symbol && (symbol.flags & 1048576) !== 0
  11276. ? getMergedSymbol(symbol.exportSymbol)
  11277. : symbol;
  11278. }
  11279. function symbolIsValue(symbol) {
  11280. if (symbol.flags & 16777216) {
  11281. return symbolIsValue(getSymbolLinks(symbol).target);
  11282. }
  11283. if (symbol.flags & 107455) {
  11284. return true;
  11285. }
  11286. if (symbol.flags & 8388608) {
  11287. return (resolveAlias(symbol).flags & 107455) !== 0;
  11288. }
  11289. return false;
  11290. }
  11291. function findConstructorDeclaration(node) {
  11292. var members = node.members;
  11293. for (var _i = 0; _i < members.length; _i++) {
  11294. var member = members[_i];
  11295. if (member.kind === 144 && ts.nodeIsPresent(member.body)) {
  11296. return member;
  11297. }
  11298. }
  11299. }
  11300. function createType(flags) {
  11301. var result = new Type(checker, flags);
  11302. result.id = typeCount++;
  11303. return result;
  11304. }
  11305. function createIntrinsicType(kind, intrinsicName) {
  11306. var type = createType(kind);
  11307. type.intrinsicName = intrinsicName;
  11308. return type;
  11309. }
  11310. function createObjectType(kind, symbol) {
  11311. var type = createType(kind);
  11312. type.symbol = symbol;
  11313. return type;
  11314. }
  11315. function isReservedMemberName(name) {
  11316. return name.charCodeAt(0) === 95 &&
  11317. name.charCodeAt(1) === 95 &&
  11318. name.charCodeAt(2) !== 95 &&
  11319. name.charCodeAt(2) !== 64;
  11320. }
  11321. function getNamedMembers(members) {
  11322. var result;
  11323. for (var id in members) {
  11324. if (ts.hasProperty(members, id)) {
  11325. if (!isReservedMemberName(id)) {
  11326. if (!result)
  11327. result = [];
  11328. var symbol = members[id];
  11329. if (symbolIsValue(symbol)) {
  11330. result.push(symbol);
  11331. }
  11332. }
  11333. }
  11334. }
  11335. return result || emptyArray;
  11336. }
  11337. function setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
  11338. type.members = members;
  11339. type.properties = getNamedMembers(members);
  11340. type.callSignatures = callSignatures;
  11341. type.constructSignatures = constructSignatures;
  11342. if (stringIndexType)
  11343. type.stringIndexType = stringIndexType;
  11344. if (numberIndexType)
  11345. type.numberIndexType = numberIndexType;
  11346. return type;
  11347. }
  11348. function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
  11349. return setObjectTypeMembers(createObjectType(65536, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  11350. }
  11351. function forEachSymbolTableInScope(enclosingDeclaration, callback) {
  11352. var result;
  11353. for (var location_1 = enclosingDeclaration; location_1; location_1 = location_1.parent) {
  11354. if (location_1.locals && !isGlobalSourceFile(location_1)) {
  11355. if (result = callback(location_1.locals)) {
  11356. return result;
  11357. }
  11358. }
  11359. switch (location_1.kind) {
  11360. case 248:
  11361. if (!ts.isExternalModule(location_1)) {
  11362. break;
  11363. }
  11364. case 218:
  11365. if (result = callback(getSymbolOfNode(location_1).exports)) {
  11366. return result;
  11367. }
  11368. break;
  11369. case 214:
  11370. case 215:
  11371. if (result = callback(getSymbolOfNode(location_1).members)) {
  11372. return result;
  11373. }
  11374. break;
  11375. }
  11376. }
  11377. return callback(globals);
  11378. }
  11379. function getQualifiedLeftMeaning(rightMeaning) {
  11380. return rightMeaning === 107455 ? 107455 : 1536;
  11381. }
  11382. function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) {
  11383. function getAccessibleSymbolChainFromSymbolTable(symbols) {
  11384. function canQualifySymbol(symbolFromSymbolTable, meaning) {
  11385. if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) {
  11386. return true;
  11387. }
  11388. var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
  11389. return !!accessibleParent;
  11390. }
  11391. function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) {
  11392. if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) {
  11393. return !ts.forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) &&
  11394. canQualifySymbol(symbolFromSymbolTable, meaning);
  11395. }
  11396. }
  11397. if (isAccessible(ts.lookUp(symbols, symbol.name))) {
  11398. return [symbol];
  11399. }
  11400. return ts.forEachValue(symbols, function (symbolFromSymbolTable) {
  11401. if (symbolFromSymbolTable.flags & 8388608
  11402. && symbolFromSymbolTable.name !== "export="
  11403. && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230)) {
  11404. if (!useOnlyExternalAliasing ||
  11405. ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) {
  11406. var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable);
  11407. if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) {
  11408. return [symbolFromSymbolTable];
  11409. }
  11410. var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
  11411. if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
  11412. return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
  11413. }
  11414. }
  11415. }
  11416. });
  11417. }
  11418. if (symbol) {
  11419. return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
  11420. }
  11421. }
  11422. function needsQualification(symbol, enclosingDeclaration, meaning) {
  11423. var qualify = false;
  11424. forEachSymbolTableInScope(enclosingDeclaration, function (symbolTable) {
  11425. if (!ts.hasProperty(symbolTable, symbol.name)) {
  11426. return false;
  11427. }
  11428. var symbolFromSymbolTable = symbolTable[symbol.name];
  11429. if (symbolFromSymbolTable === symbol) {
  11430. return true;
  11431. }
  11432. symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
  11433. if (symbolFromSymbolTable.flags & meaning) {
  11434. qualify = true;
  11435. return true;
  11436. }
  11437. return false;
  11438. });
  11439. return qualify;
  11440. }
  11441. function isSymbolAccessible(symbol, enclosingDeclaration, meaning) {
  11442. if (symbol && enclosingDeclaration && !(symbol.flags & 262144)) {
  11443. var initialSymbol = symbol;
  11444. var meaningToLook = meaning;
  11445. while (symbol) {
  11446. var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false);
  11447. if (accessibleSymbolChain) {
  11448. var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
  11449. if (!hasAccessibleDeclarations) {
  11450. return {
  11451. accessibility: 1,
  11452. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
  11453. errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1536) : undefined
  11454. };
  11455. }
  11456. return hasAccessibleDeclarations;
  11457. }
  11458. meaningToLook = getQualifiedLeftMeaning(meaning);
  11459. symbol = getParentOfSymbol(symbol);
  11460. }
  11461. var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer);
  11462. if (symbolExternalModule) {
  11463. var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration);
  11464. if (symbolExternalModule !== enclosingExternalModule) {
  11465. return {
  11466. accessibility: 2,
  11467. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
  11468. errorModuleName: symbolToString(symbolExternalModule)
  11469. };
  11470. }
  11471. }
  11472. return {
  11473. accessibility: 1,
  11474. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning)
  11475. };
  11476. }
  11477. return { accessibility: 0 };
  11478. function getExternalModuleContainer(declaration) {
  11479. for (; declaration; declaration = declaration.parent) {
  11480. if (hasExternalModuleSymbol(declaration)) {
  11481. return getSymbolOfNode(declaration);
  11482. }
  11483. }
  11484. }
  11485. }
  11486. function hasExternalModuleSymbol(declaration) {
  11487. return (declaration.kind === 218 && declaration.name.kind === 9) ||
  11488. (declaration.kind === 248 && ts.isExternalModule(declaration));
  11489. }
  11490. function hasVisibleDeclarations(symbol) {
  11491. var aliasesToMakeVisible;
  11492. if (ts.forEach(symbol.declarations, function (declaration) { return !getIsDeclarationVisible(declaration); })) {
  11493. return undefined;
  11494. }
  11495. return { accessibility: 0, aliasesToMakeVisible: aliasesToMakeVisible };
  11496. function getIsDeclarationVisible(declaration) {
  11497. if (!isDeclarationVisible(declaration)) {
  11498. var anyImportSyntax = getAnyImportSyntax(declaration);
  11499. if (anyImportSyntax &&
  11500. !(anyImportSyntax.flags & 1) &&
  11501. isDeclarationVisible(anyImportSyntax.parent)) {
  11502. getNodeLinks(declaration).isVisible = true;
  11503. if (aliasesToMakeVisible) {
  11504. if (!ts.contains(aliasesToMakeVisible, anyImportSyntax)) {
  11505. aliasesToMakeVisible.push(anyImportSyntax);
  11506. }
  11507. }
  11508. else {
  11509. aliasesToMakeVisible = [anyImportSyntax];
  11510. }
  11511. return true;
  11512. }
  11513. return false;
  11514. }
  11515. return true;
  11516. }
  11517. }
  11518. function isEntityNameVisible(entityName, enclosingDeclaration) {
  11519. var meaning;
  11520. if (entityName.parent.kind === 154) {
  11521. meaning = 107455 | 1048576;
  11522. }
  11523. else if (entityName.kind === 135 || entityName.kind === 166 ||
  11524. entityName.parent.kind === 221) {
  11525. meaning = 1536;
  11526. }
  11527. else {
  11528. meaning = 793056;
  11529. }
  11530. var firstIdentifier = getFirstIdentifier(entityName);
  11531. var symbol = resolveName(enclosingDeclaration, firstIdentifier.text, meaning, undefined, undefined);
  11532. return (symbol && hasVisibleDeclarations(symbol)) || {
  11533. accessibility: 1,
  11534. errorSymbolName: ts.getTextOfNode(firstIdentifier),
  11535. errorNode: firstIdentifier
  11536. };
  11537. }
  11538. function writeKeyword(writer, kind) {
  11539. writer.writeKeyword(ts.tokenToString(kind));
  11540. }
  11541. function writePunctuation(writer, kind) {
  11542. writer.writePunctuation(ts.tokenToString(kind));
  11543. }
  11544. function writeSpace(writer) {
  11545. writer.writeSpace(" ");
  11546. }
  11547. function symbolToString(symbol, enclosingDeclaration, meaning) {
  11548. var writer = ts.getSingleLineStringWriter();
  11549. getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning);
  11550. var result = writer.string();
  11551. ts.releaseStringWriter(writer);
  11552. return result;
  11553. }
  11554. function signatureToString(signature, enclosingDeclaration, flags) {
  11555. var writer = ts.getSingleLineStringWriter();
  11556. getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
  11557. var result = writer.string();
  11558. ts.releaseStringWriter(writer);
  11559. return result;
  11560. }
  11561. function typeToString(type, enclosingDeclaration, flags) {
  11562. var writer = ts.getSingleLineStringWriter();
  11563. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  11564. var result = writer.string();
  11565. ts.releaseStringWriter(writer);
  11566. var maxLength = compilerOptions.noErrorTruncation || flags & 4 ? undefined : 100;
  11567. if (maxLength && result.length >= maxLength) {
  11568. result = result.substr(0, maxLength - "...".length) + "...";
  11569. }
  11570. return result;
  11571. }
  11572. function getTypeAliasForTypeLiteral(type) {
  11573. if (type.symbol && type.symbol.flags & 2048) {
  11574. var node = type.symbol.declarations[0].parent;
  11575. while (node.kind === 160) {
  11576. node = node.parent;
  11577. }
  11578. if (node.kind === 216) {
  11579. return getSymbolOfNode(node);
  11580. }
  11581. }
  11582. return undefined;
  11583. }
  11584. function getSymbolDisplayBuilder() {
  11585. function getNameOfSymbol(symbol) {
  11586. if (symbol.declarations && symbol.declarations.length) {
  11587. var declaration = symbol.declarations[0];
  11588. if (declaration.name) {
  11589. return ts.declarationNameToString(declaration.name);
  11590. }
  11591. switch (declaration.kind) {
  11592. case 186:
  11593. return "(Anonymous class)";
  11594. case 173:
  11595. case 174:
  11596. return "(Anonymous function)";
  11597. }
  11598. }
  11599. return symbol.name;
  11600. }
  11601. function appendSymbolNameOnly(symbol, writer) {
  11602. writer.writeSymbol(getNameOfSymbol(symbol), symbol);
  11603. }
  11604. function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags, typeFlags) {
  11605. var parentSymbol;
  11606. function appendParentTypeArgumentsAndSymbolName(symbol) {
  11607. if (parentSymbol) {
  11608. if (flags & 1) {
  11609. if (symbol.flags & 16777216) {
  11610. buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration);
  11611. }
  11612. else {
  11613. buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration);
  11614. }
  11615. }
  11616. writePunctuation(writer, 21);
  11617. }
  11618. parentSymbol = symbol;
  11619. appendSymbolNameOnly(symbol, writer);
  11620. }
  11621. writer.trackSymbol(symbol, enclosingDeclaration, meaning);
  11622. function walkSymbol(symbol, meaning) {
  11623. if (symbol) {
  11624. var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2));
  11625. if (!accessibleSymbolChain ||
  11626. needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
  11627. walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning));
  11628. }
  11629. if (accessibleSymbolChain) {
  11630. for (var _i = 0; _i < accessibleSymbolChain.length; _i++) {
  11631. var accessibleSymbol = accessibleSymbolChain[_i];
  11632. appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
  11633. }
  11634. }
  11635. else {
  11636. if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) {
  11637. return;
  11638. }
  11639. if (symbol.flags & 2048 || symbol.flags & 4096) {
  11640. return;
  11641. }
  11642. appendParentTypeArgumentsAndSymbolName(symbol);
  11643. }
  11644. }
  11645. }
  11646. var isTypeParameter = symbol.flags & 262144;
  11647. var typeFormatFlag = 128 & typeFlags;
  11648. if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
  11649. walkSymbol(symbol, meaning);
  11650. return;
  11651. }
  11652. return appendParentTypeArgumentsAndSymbolName(symbol);
  11653. }
  11654. function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) {
  11655. var globalFlagsToPass = globalFlags & 16;
  11656. var inObjectTypeLiteral = false;
  11657. return writeType(type, globalFlags);
  11658. function writeType(type, flags) {
  11659. if (type.flags & 16777343) {
  11660. writer.writeKeyword(!(globalFlags & 16) && isTypeAny(type)
  11661. ? "any"
  11662. : type.intrinsicName);
  11663. }
  11664. else if (type.flags & 33554432) {
  11665. if (inObjectTypeLiteral) {
  11666. writer.reportInaccessibleThisError();
  11667. }
  11668. writer.writeKeyword("this");
  11669. }
  11670. else if (type.flags & 4096) {
  11671. writeTypeReference(type, flags);
  11672. }
  11673. else if (type.flags & (1024 | 2048 | 128 | 512)) {
  11674. buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 793056, 0, flags);
  11675. }
  11676. else if (type.flags & 8192) {
  11677. writeTupleType(type);
  11678. }
  11679. else if (type.flags & 49152) {
  11680. writeUnionOrIntersectionType(type, flags);
  11681. }
  11682. else if (type.flags & 65536) {
  11683. writeAnonymousType(type, flags);
  11684. }
  11685. else if (type.flags & 256) {
  11686. writer.writeStringLiteral(type.text);
  11687. }
  11688. else {
  11689. writePunctuation(writer, 15);
  11690. writeSpace(writer);
  11691. writePunctuation(writer, 22);
  11692. writeSpace(writer);
  11693. writePunctuation(writer, 16);
  11694. }
  11695. }
  11696. function writeTypeList(types, delimiter) {
  11697. for (var i = 0; i < types.length; i++) {
  11698. if (i > 0) {
  11699. if (delimiter !== 24) {
  11700. writeSpace(writer);
  11701. }
  11702. writePunctuation(writer, delimiter);
  11703. writeSpace(writer);
  11704. }
  11705. writeType(types[i], delimiter === 24 ? 0 : 64);
  11706. }
  11707. }
  11708. function writeSymbolTypeReference(symbol, typeArguments, pos, end, flags) {
  11709. if (symbol.flags & 32 || !isReservedMemberName(symbol.name)) {
  11710. buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056, 0, flags);
  11711. }
  11712. if (pos < end) {
  11713. writePunctuation(writer, 25);
  11714. writeType(typeArguments[pos++], 0);
  11715. while (pos < end) {
  11716. writePunctuation(writer, 24);
  11717. writeSpace(writer);
  11718. writeType(typeArguments[pos++], 0);
  11719. }
  11720. writePunctuation(writer, 27);
  11721. }
  11722. }
  11723. function writeTypeReference(type, flags) {
  11724. var typeArguments = type.typeArguments || emptyArray;
  11725. if (type.target === globalArrayType && !(flags & 1)) {
  11726. writeType(typeArguments[0], 64);
  11727. writePunctuation(writer, 19);
  11728. writePunctuation(writer, 20);
  11729. }
  11730. else {
  11731. var outerTypeParameters = type.target.outerTypeParameters;
  11732. var i = 0;
  11733. if (outerTypeParameters) {
  11734. var length_1 = outerTypeParameters.length;
  11735. while (i < length_1) {
  11736. var start = i;
  11737. var parent_3 = getParentSymbolOfTypeParameter(outerTypeParameters[i]);
  11738. do {
  11739. i++;
  11740. } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3);
  11741. if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) {
  11742. writeSymbolTypeReference(parent_3, typeArguments, start, i, flags);
  11743. writePunctuation(writer, 21);
  11744. }
  11745. }
  11746. }
  11747. var typeParameterCount = (type.target.typeParameters || emptyArray).length;
  11748. writeSymbolTypeReference(type.symbol, typeArguments, i, typeParameterCount, flags);
  11749. }
  11750. }
  11751. function writeTupleType(type) {
  11752. writePunctuation(writer, 19);
  11753. writeTypeList(type.elementTypes, 24);
  11754. writePunctuation(writer, 20);
  11755. }
  11756. function writeUnionOrIntersectionType(type, flags) {
  11757. if (flags & 64) {
  11758. writePunctuation(writer, 17);
  11759. }
  11760. writeTypeList(type.types, type.flags & 16384 ? 47 : 46);
  11761. if (flags & 64) {
  11762. writePunctuation(writer, 18);
  11763. }
  11764. }
  11765. function writeAnonymousType(type, flags) {
  11766. var symbol = type.symbol;
  11767. if (symbol) {
  11768. if (symbol.flags & (32 | 384 | 512)) {
  11769. writeTypeofSymbol(type, flags);
  11770. }
  11771. else if (shouldWriteTypeOfFunctionSymbol()) {
  11772. writeTypeofSymbol(type, flags);
  11773. }
  11774. else if (ts.contains(symbolStack, symbol)) {
  11775. var typeAlias = getTypeAliasForTypeLiteral(type);
  11776. if (typeAlias) {
  11777. buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags);
  11778. }
  11779. else {
  11780. writeKeyword(writer, 117);
  11781. }
  11782. }
  11783. else {
  11784. if (!symbolStack) {
  11785. symbolStack = [];
  11786. }
  11787. symbolStack.push(symbol);
  11788. writeLiteralType(type, flags);
  11789. symbolStack.pop();
  11790. }
  11791. }
  11792. else {
  11793. writeLiteralType(type, flags);
  11794. }
  11795. function shouldWriteTypeOfFunctionSymbol() {
  11796. var isStaticMethodSymbol = !!(symbol.flags & 8192 &&
  11797. ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128; }));
  11798. var isNonLocalFunctionSymbol = !!(symbol.flags & 16) &&
  11799. (symbol.parent ||
  11800. ts.forEach(symbol.declarations, function (declaration) {
  11801. return declaration.parent.kind === 248 || declaration.parent.kind === 219;
  11802. }));
  11803. if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
  11804. return !!(flags & 2) ||
  11805. (ts.contains(symbolStack, symbol));
  11806. }
  11807. }
  11808. }
  11809. function writeTypeofSymbol(type, typeFormatFlags) {
  11810. writeKeyword(writer, 101);
  11811. writeSpace(writer);
  11812. buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455, 0, typeFormatFlags);
  11813. }
  11814. function getIndexerParameterName(type, indexKind, fallbackName) {
  11815. var declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind);
  11816. if (!declaration) {
  11817. return fallbackName;
  11818. }
  11819. ts.Debug.assert(declaration.parameters.length !== 0);
  11820. return ts.declarationNameToString(declaration.parameters[0].name);
  11821. }
  11822. function writeLiteralType(type, flags) {
  11823. var resolved = resolveStructuredTypeMembers(type);
  11824. if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) {
  11825. if (!resolved.callSignatures.length && !resolved.constructSignatures.length) {
  11826. writePunctuation(writer, 15);
  11827. writePunctuation(writer, 16);
  11828. return;
  11829. }
  11830. if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
  11831. if (flags & 64) {
  11832. writePunctuation(writer, 17);
  11833. }
  11834. buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack);
  11835. if (flags & 64) {
  11836. writePunctuation(writer, 18);
  11837. }
  11838. return;
  11839. }
  11840. if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
  11841. if (flags & 64) {
  11842. writePunctuation(writer, 17);
  11843. }
  11844. writeKeyword(writer, 92);
  11845. writeSpace(writer);
  11846. buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack);
  11847. if (flags & 64) {
  11848. writePunctuation(writer, 18);
  11849. }
  11850. return;
  11851. }
  11852. }
  11853. var saveInObjectTypeLiteral = inObjectTypeLiteral;
  11854. inObjectTypeLiteral = true;
  11855. writePunctuation(writer, 15);
  11856. writer.writeLine();
  11857. writer.increaseIndent();
  11858. for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) {
  11859. var signature = _a[_i];
  11860. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
  11861. writePunctuation(writer, 23);
  11862. writer.writeLine();
  11863. }
  11864. for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) {
  11865. var signature = _c[_b];
  11866. writeKeyword(writer, 92);
  11867. writeSpace(writer);
  11868. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
  11869. writePunctuation(writer, 23);
  11870. writer.writeLine();
  11871. }
  11872. if (resolved.stringIndexType) {
  11873. writePunctuation(writer, 19);
  11874. writer.writeParameter(getIndexerParameterName(resolved, 0, "x"));
  11875. writePunctuation(writer, 54);
  11876. writeSpace(writer);
  11877. writeKeyword(writer, 130);
  11878. writePunctuation(writer, 20);
  11879. writePunctuation(writer, 54);
  11880. writeSpace(writer);
  11881. writeType(resolved.stringIndexType, 0);
  11882. writePunctuation(writer, 23);
  11883. writer.writeLine();
  11884. }
  11885. if (resolved.numberIndexType) {
  11886. writePunctuation(writer, 19);
  11887. writer.writeParameter(getIndexerParameterName(resolved, 1, "x"));
  11888. writePunctuation(writer, 54);
  11889. writeSpace(writer);
  11890. writeKeyword(writer, 128);
  11891. writePunctuation(writer, 20);
  11892. writePunctuation(writer, 54);
  11893. writeSpace(writer);
  11894. writeType(resolved.numberIndexType, 0);
  11895. writePunctuation(writer, 23);
  11896. writer.writeLine();
  11897. }
  11898. for (var _d = 0, _e = resolved.properties; _d < _e.length; _d++) {
  11899. var p = _e[_d];
  11900. var t = getTypeOfSymbol(p);
  11901. if (p.flags & (16 | 8192) && !getPropertiesOfObjectType(t).length) {
  11902. var signatures = getSignaturesOfType(t, 0);
  11903. for (var _f = 0; _f < signatures.length; _f++) {
  11904. var signature = signatures[_f];
  11905. buildSymbolDisplay(p, writer);
  11906. if (p.flags & 536870912) {
  11907. writePunctuation(writer, 53);
  11908. }
  11909. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
  11910. writePunctuation(writer, 23);
  11911. writer.writeLine();
  11912. }
  11913. }
  11914. else {
  11915. buildSymbolDisplay(p, writer);
  11916. if (p.flags & 536870912) {
  11917. writePunctuation(writer, 53);
  11918. }
  11919. writePunctuation(writer, 54);
  11920. writeSpace(writer);
  11921. writeType(t, 0);
  11922. writePunctuation(writer, 23);
  11923. writer.writeLine();
  11924. }
  11925. }
  11926. writer.decreaseIndent();
  11927. writePunctuation(writer, 16);
  11928. inObjectTypeLiteral = saveInObjectTypeLiteral;
  11929. }
  11930. }
  11931. function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) {
  11932. var targetSymbol = getTargetSymbol(symbol);
  11933. if (targetSymbol.flags & 32 || targetSymbol.flags & 64 || targetSymbol.flags & 524288) {
  11934. buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaraiton, flags);
  11935. }
  11936. }
  11937. function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) {
  11938. appendSymbolNameOnly(tp.symbol, writer);
  11939. var constraint = getConstraintOfTypeParameter(tp);
  11940. if (constraint) {
  11941. writeSpace(writer);
  11942. writeKeyword(writer, 83);
  11943. writeSpace(writer);
  11944. buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack);
  11945. }
  11946. }
  11947. function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) {
  11948. var parameterNode = p.valueDeclaration;
  11949. if (ts.isRestParameter(parameterNode)) {
  11950. writePunctuation(writer, 22);
  11951. }
  11952. appendSymbolNameOnly(p, writer);
  11953. if (isOptionalParameter(parameterNode)) {
  11954. writePunctuation(writer, 53);
  11955. }
  11956. writePunctuation(writer, 54);
  11957. writeSpace(writer);
  11958. buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack);
  11959. }
  11960. function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) {
  11961. if (typeParameters && typeParameters.length) {
  11962. writePunctuation(writer, 25);
  11963. for (var i = 0; i < typeParameters.length; i++) {
  11964. if (i > 0) {
  11965. writePunctuation(writer, 24);
  11966. writeSpace(writer);
  11967. }
  11968. buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack);
  11969. }
  11970. writePunctuation(writer, 27);
  11971. }
  11972. }
  11973. function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) {
  11974. if (typeParameters && typeParameters.length) {
  11975. writePunctuation(writer, 25);
  11976. for (var i = 0; i < typeParameters.length; i++) {
  11977. if (i > 0) {
  11978. writePunctuation(writer, 24);
  11979. writeSpace(writer);
  11980. }
  11981. buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0);
  11982. }
  11983. writePunctuation(writer, 27);
  11984. }
  11985. }
  11986. function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) {
  11987. writePunctuation(writer, 17);
  11988. for (var i = 0; i < parameters.length; i++) {
  11989. if (i > 0) {
  11990. writePunctuation(writer, 24);
  11991. writeSpace(writer);
  11992. }
  11993. buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack);
  11994. }
  11995. writePunctuation(writer, 18);
  11996. }
  11997. function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) {
  11998. if (flags & 8) {
  11999. writeSpace(writer);
  12000. writePunctuation(writer, 34);
  12001. }
  12002. else {
  12003. writePunctuation(writer, 54);
  12004. }
  12005. writeSpace(writer);
  12006. var returnType;
  12007. if (signature.typePredicate) {
  12008. writer.writeParameter(signature.typePredicate.parameterName);
  12009. writeSpace(writer);
  12010. writeKeyword(writer, 124);
  12011. writeSpace(writer);
  12012. returnType = signature.typePredicate.type;
  12013. }
  12014. else {
  12015. returnType = getReturnTypeOfSignature(signature);
  12016. }
  12017. buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack);
  12018. }
  12019. function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) {
  12020. if (signature.target && (flags & 32)) {
  12021. buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration);
  12022. }
  12023. else {
  12024. buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack);
  12025. }
  12026. buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack);
  12027. buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
  12028. }
  12029. return _displayBuilder || (_displayBuilder = {
  12030. buildSymbolDisplay: buildSymbolDisplay,
  12031. buildTypeDisplay: buildTypeDisplay,
  12032. buildTypeParameterDisplay: buildTypeParameterDisplay,
  12033. buildParameterDisplay: buildParameterDisplay,
  12034. buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters,
  12035. buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters,
  12036. buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol,
  12037. buildSignatureDisplay: buildSignatureDisplay,
  12038. buildReturnTypeDisplay: buildReturnTypeDisplay
  12039. });
  12040. }
  12041. function isDeclarationVisible(node) {
  12042. function getContainingExternalModule(node) {
  12043. for (; node; node = node.parent) {
  12044. if (node.kind === 218) {
  12045. if (node.name.kind === 9) {
  12046. return node;
  12047. }
  12048. }
  12049. else if (node.kind === 248) {
  12050. return ts.isExternalModule(node) ? node : undefined;
  12051. }
  12052. }
  12053. ts.Debug.fail("getContainingModule cant reach here");
  12054. }
  12055. function isUsedInExportAssignment(node) {
  12056. var externalModule = getContainingExternalModule(node);
  12057. var exportAssignmentSymbol;
  12058. var resolvedExportSymbol;
  12059. if (externalModule) {
  12060. var externalModuleSymbol = getSymbolOfNode(externalModule);
  12061. exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
  12062. var symbolOfNode = getSymbolOfNode(node);
  12063. if (isSymbolUsedInExportAssignment(symbolOfNode)) {
  12064. return true;
  12065. }
  12066. if (symbolOfNode.flags & 8388608) {
  12067. return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode));
  12068. }
  12069. }
  12070. function isSymbolUsedInExportAssignment(symbol) {
  12071. if (exportAssignmentSymbol === symbol) {
  12072. return true;
  12073. }
  12074. if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608)) {
  12075. resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
  12076. if (resolvedExportSymbol === symbol) {
  12077. return true;
  12078. }
  12079. return ts.forEach(resolvedExportSymbol.declarations, function (current) {
  12080. while (current) {
  12081. if (current === node) {
  12082. return true;
  12083. }
  12084. current = current.parent;
  12085. }
  12086. });
  12087. }
  12088. }
  12089. }
  12090. function determineIfDeclarationIsVisible() {
  12091. switch (node.kind) {
  12092. case 163:
  12093. return isDeclarationVisible(node.parent.parent);
  12094. case 211:
  12095. if (ts.isBindingPattern(node.name) &&
  12096. !node.name.elements.length) {
  12097. return false;
  12098. }
  12099. case 218:
  12100. case 214:
  12101. case 215:
  12102. case 216:
  12103. case 213:
  12104. case 217:
  12105. case 221:
  12106. var parent_4 = getDeclarationContainer(node);
  12107. if (!(ts.getCombinedNodeFlags(node) & 1) &&
  12108. !(node.kind !== 221 && parent_4.kind !== 248 && ts.isInAmbientContext(parent_4))) {
  12109. return isGlobalSourceFile(parent_4);
  12110. }
  12111. return isDeclarationVisible(parent_4);
  12112. case 141:
  12113. case 140:
  12114. case 145:
  12115. case 146:
  12116. case 143:
  12117. case 142:
  12118. if (node.flags & (32 | 64)) {
  12119. return false;
  12120. }
  12121. case 144:
  12122. case 148:
  12123. case 147:
  12124. case 149:
  12125. case 138:
  12126. case 219:
  12127. case 152:
  12128. case 153:
  12129. case 155:
  12130. case 151:
  12131. case 156:
  12132. case 157:
  12133. case 158:
  12134. case 159:
  12135. case 160:
  12136. return isDeclarationVisible(node.parent);
  12137. case 223:
  12138. case 224:
  12139. case 226:
  12140. return false;
  12141. case 137:
  12142. case 248:
  12143. return true;
  12144. case 227:
  12145. return false;
  12146. default:
  12147. ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
  12148. }
  12149. }
  12150. if (node) {
  12151. var links = getNodeLinks(node);
  12152. if (links.isVisible === undefined) {
  12153. links.isVisible = !!determineIfDeclarationIsVisible();
  12154. }
  12155. return links.isVisible;
  12156. }
  12157. }
  12158. function collectLinkedAliases(node) {
  12159. var exportSymbol;
  12160. if (node.parent && node.parent.kind === 227) {
  12161. exportSymbol = resolveName(node.parent, node.text, 107455 | 793056 | 1536 | 8388608, ts.Diagnostics.Cannot_find_name_0, node);
  12162. }
  12163. else if (node.parent.kind === 230) {
  12164. var exportSpecifier = node.parent;
  12165. exportSymbol = exportSpecifier.parent.parent.moduleSpecifier ?
  12166. getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) :
  12167. resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, 107455 | 793056 | 1536 | 8388608);
  12168. }
  12169. var result = [];
  12170. if (exportSymbol) {
  12171. buildVisibleNodeList(exportSymbol.declarations);
  12172. }
  12173. return result;
  12174. function buildVisibleNodeList(declarations) {
  12175. ts.forEach(declarations, function (declaration) {
  12176. getNodeLinks(declaration).isVisible = true;
  12177. var resultNode = getAnyImportSyntax(declaration) || declaration;
  12178. if (!ts.contains(result, resultNode)) {
  12179. result.push(resultNode);
  12180. }
  12181. if (ts.isInternalModuleImportEqualsDeclaration(declaration)) {
  12182. var internalModuleReference = declaration.moduleReference;
  12183. var firstIdentifier = getFirstIdentifier(internalModuleReference);
  12184. var importSymbol = resolveName(declaration, firstIdentifier.text, 107455 | 793056 | 1536, ts.Diagnostics.Cannot_find_name_0, firstIdentifier);
  12185. buildVisibleNodeList(importSymbol.declarations);
  12186. }
  12187. });
  12188. }
  12189. }
  12190. function pushTypeResolution(target, propertyName) {
  12191. var resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName);
  12192. if (resolutionCycleStartIndex >= 0) {
  12193. var length_2 = resolutionTargets.length;
  12194. for (var i = resolutionCycleStartIndex; i < length_2; i++) {
  12195. resolutionResults[i] = false;
  12196. }
  12197. return false;
  12198. }
  12199. resolutionTargets.push(target);
  12200. resolutionResults.push(true);
  12201. resolutionPropertyNames.push(propertyName);
  12202. return true;
  12203. }
  12204. function findResolutionCycleStartIndex(target, propertyName) {
  12205. for (var i = resolutionTargets.length - 1; i >= 0; i--) {
  12206. if (hasType(resolutionTargets[i], resolutionPropertyNames[i])) {
  12207. return -1;
  12208. }
  12209. if (resolutionTargets[i] === target && resolutionPropertyNames[i] === propertyName) {
  12210. return i;
  12211. }
  12212. }
  12213. return -1;
  12214. }
  12215. function hasType(target, propertyName) {
  12216. if (propertyName === 0) {
  12217. return getSymbolLinks(target).type;
  12218. }
  12219. if (propertyName === 2) {
  12220. return getSymbolLinks(target).declaredType;
  12221. }
  12222. if (propertyName === 1) {
  12223. ts.Debug.assert(!!(target.flags & 1024));
  12224. return target.resolvedBaseConstructorType;
  12225. }
  12226. if (propertyName === 3) {
  12227. return target.resolvedReturnType;
  12228. }
  12229. ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
  12230. }
  12231. function popTypeResolution() {
  12232. resolutionTargets.pop();
  12233. resolutionPropertyNames.pop();
  12234. return resolutionResults.pop();
  12235. }
  12236. function getDeclarationContainer(node) {
  12237. node = ts.getRootDeclaration(node);
  12238. return node.kind === 211 ? node.parent.parent.parent : node.parent;
  12239. }
  12240. function getTypeOfPrototypeProperty(prototype) {
  12241. var classType = getDeclaredTypeOfSymbol(prototype.parent);
  12242. return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType;
  12243. }
  12244. function getTypeOfPropertyOfType(type, name) {
  12245. var prop = getPropertyOfType(type, name);
  12246. return prop ? getTypeOfSymbol(prop) : undefined;
  12247. }
  12248. function isTypeAny(type) {
  12249. return type && (type.flags & 1) !== 0;
  12250. }
  12251. function getTypeForBindingElementParent(node) {
  12252. var symbol = getSymbolOfNode(node);
  12253. return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node);
  12254. }
  12255. function getTypeForBindingElement(declaration) {
  12256. var pattern = declaration.parent;
  12257. var parentType = getTypeForBindingElementParent(pattern.parent);
  12258. if (parentType === unknownType) {
  12259. return unknownType;
  12260. }
  12261. if (!parentType || isTypeAny(parentType)) {
  12262. if (declaration.initializer) {
  12263. return checkExpressionCached(declaration.initializer);
  12264. }
  12265. return parentType;
  12266. }
  12267. var type;
  12268. if (pattern.kind === 161) {
  12269. var name_10 = declaration.propertyName || declaration.name;
  12270. type = getTypeOfPropertyOfType(parentType, name_10.text) ||
  12271. isNumericLiteralName(name_10.text) && getIndexTypeOfType(parentType, 1) ||
  12272. getIndexTypeOfType(parentType, 0);
  12273. if (!type) {
  12274. error(name_10, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_10));
  12275. return unknownType;
  12276. }
  12277. }
  12278. else {
  12279. var elementType = checkIteratedTypeOrElementType(parentType, pattern, false);
  12280. if (!declaration.dotDotDotToken) {
  12281. var propName = "" + ts.indexOf(pattern.elements, declaration);
  12282. type = isTupleLikeType(parentType)
  12283. ? getTypeOfPropertyOfType(parentType, propName)
  12284. : elementType;
  12285. if (!type) {
  12286. if (isTupleType(parentType)) {
  12287. error(declaration, ts.Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), parentType.elementTypes.length, pattern.elements.length);
  12288. }
  12289. else {
  12290. error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName);
  12291. }
  12292. return unknownType;
  12293. }
  12294. }
  12295. else {
  12296. type = createArrayType(elementType);
  12297. }
  12298. }
  12299. return type;
  12300. }
  12301. function getTypeForVariableLikeDeclaration(declaration) {
  12302. if (declaration.parent.parent.kind === 200) {
  12303. return anyType;
  12304. }
  12305. if (declaration.parent.parent.kind === 201) {
  12306. return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType;
  12307. }
  12308. if (ts.isBindingPattern(declaration.parent)) {
  12309. return getTypeForBindingElement(declaration);
  12310. }
  12311. if (declaration.type) {
  12312. return getTypeFromTypeNode(declaration.type);
  12313. }
  12314. if (declaration.kind === 138) {
  12315. var func = declaration.parent;
  12316. if (func.kind === 146 && !ts.hasDynamicName(func)) {
  12317. var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 145);
  12318. if (getter) {
  12319. return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
  12320. }
  12321. }
  12322. var type = getContextuallyTypedParameterType(declaration);
  12323. if (type) {
  12324. return type;
  12325. }
  12326. }
  12327. if (declaration.initializer) {
  12328. return checkExpressionCached(declaration.initializer);
  12329. }
  12330. if (declaration.kind === 246) {
  12331. return checkIdentifier(declaration.name);
  12332. }
  12333. if (ts.isBindingPattern(declaration.name)) {
  12334. return getTypeFromBindingPattern(declaration.name, false);
  12335. }
  12336. return undefined;
  12337. }
  12338. function getTypeFromBindingElement(element, includePatternInType) {
  12339. if (element.initializer) {
  12340. return getWidenedType(checkExpressionCached(element.initializer));
  12341. }
  12342. if (ts.isBindingPattern(element.name)) {
  12343. return getTypeFromBindingPattern(element.name, includePatternInType);
  12344. }
  12345. return anyType;
  12346. }
  12347. function getTypeFromObjectBindingPattern(pattern, includePatternInType) {
  12348. var members = {};
  12349. ts.forEach(pattern.elements, function (e) {
  12350. var flags = 4 | 67108864 | (e.initializer ? 536870912 : 0);
  12351. var name = e.propertyName || e.name;
  12352. var symbol = createSymbol(flags, name.text);
  12353. symbol.type = getTypeFromBindingElement(e, includePatternInType);
  12354. symbol.bindingElement = e;
  12355. members[symbol.name] = symbol;
  12356. });
  12357. var result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
  12358. if (includePatternInType) {
  12359. result.pattern = pattern;
  12360. }
  12361. return result;
  12362. }
  12363. function getTypeFromArrayBindingPattern(pattern, includePatternInType) {
  12364. var elements = pattern.elements;
  12365. if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) {
  12366. return languageVersion >= 2 ? createIterableType(anyType) : anyArrayType;
  12367. }
  12368. var elementTypes = ts.map(elements, function (e) { return e.kind === 187 ? anyType : getTypeFromBindingElement(e, includePatternInType); });
  12369. if (includePatternInType) {
  12370. var result = createNewTupleType(elementTypes);
  12371. result.pattern = pattern;
  12372. return result;
  12373. }
  12374. return createTupleType(elementTypes);
  12375. }
  12376. function getTypeFromBindingPattern(pattern, includePatternInType) {
  12377. return pattern.kind === 161
  12378. ? getTypeFromObjectBindingPattern(pattern, includePatternInType)
  12379. : getTypeFromArrayBindingPattern(pattern, includePatternInType);
  12380. }
  12381. function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
  12382. var type = getTypeForVariableLikeDeclaration(declaration);
  12383. if (type) {
  12384. if (reportErrors) {
  12385. reportErrorsFromWidening(declaration, type);
  12386. }
  12387. return declaration.kind !== 245 ? getWidenedType(type) : type;
  12388. }
  12389. type = declaration.dotDotDotToken ? anyArrayType : anyType;
  12390. if (reportErrors && compilerOptions.noImplicitAny) {
  12391. var root = ts.getRootDeclaration(declaration);
  12392. if (!isPrivateWithinAmbient(root) && !(root.kind === 138 && isPrivateWithinAmbient(root.parent))) {
  12393. reportImplicitAnyError(declaration, type);
  12394. }
  12395. }
  12396. return type;
  12397. }
  12398. function getTypeOfVariableOrParameterOrProperty(symbol) {
  12399. var links = getSymbolLinks(symbol);
  12400. if (!links.type) {
  12401. if (symbol.flags & 134217728) {
  12402. return links.type = getTypeOfPrototypeProperty(symbol);
  12403. }
  12404. var declaration = symbol.valueDeclaration;
  12405. if (declaration.parent.kind === 244) {
  12406. return links.type = anyType;
  12407. }
  12408. if (declaration.kind === 227) {
  12409. return links.type = checkExpression(declaration.expression);
  12410. }
  12411. if (!pushTypeResolution(symbol, 0)) {
  12412. return unknownType;
  12413. }
  12414. var type = getWidenedTypeForVariableLikeDeclaration(declaration, true);
  12415. if (!popTypeResolution()) {
  12416. if (symbol.valueDeclaration.type) {
  12417. type = unknownType;
  12418. error(symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
  12419. }
  12420. else {
  12421. type = anyType;
  12422. if (compilerOptions.noImplicitAny) {
  12423. error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol));
  12424. }
  12425. }
  12426. }
  12427. links.type = type;
  12428. }
  12429. return links.type;
  12430. }
  12431. function getAnnotatedAccessorType(accessor) {
  12432. if (accessor) {
  12433. if (accessor.kind === 145) {
  12434. return accessor.type && getTypeFromTypeNode(accessor.type);
  12435. }
  12436. else {
  12437. var setterTypeAnnotation = ts.getSetAccessorTypeAnnotationNode(accessor);
  12438. return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation);
  12439. }
  12440. }
  12441. return undefined;
  12442. }
  12443. function getTypeOfAccessors(symbol) {
  12444. var links = getSymbolLinks(symbol);
  12445. if (!links.type) {
  12446. if (!pushTypeResolution(symbol, 0)) {
  12447. return unknownType;
  12448. }
  12449. var getter = ts.getDeclarationOfKind(symbol, 145);
  12450. var setter = ts.getDeclarationOfKind(symbol, 146);
  12451. var type;
  12452. var getterReturnType = getAnnotatedAccessorType(getter);
  12453. if (getterReturnType) {
  12454. type = getterReturnType;
  12455. }
  12456. else {
  12457. var setterParameterType = getAnnotatedAccessorType(setter);
  12458. if (setterParameterType) {
  12459. type = setterParameterType;
  12460. }
  12461. else {
  12462. if (getter && getter.body) {
  12463. type = getReturnTypeFromBody(getter);
  12464. }
  12465. else {
  12466. if (compilerOptions.noImplicitAny) {
  12467. error(setter, ts.Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
  12468. }
  12469. type = anyType;
  12470. }
  12471. }
  12472. }
  12473. if (!popTypeResolution()) {
  12474. type = anyType;
  12475. if (compilerOptions.noImplicitAny) {
  12476. var getter_1 = ts.getDeclarationOfKind(symbol, 145);
  12477. error(getter_1, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
  12478. }
  12479. }
  12480. links.type = type;
  12481. }
  12482. return links.type;
  12483. }
  12484. function getTypeOfFuncClassEnumModule(symbol) {
  12485. var links = getSymbolLinks(symbol);
  12486. if (!links.type) {
  12487. links.type = createObjectType(65536, symbol);
  12488. }
  12489. return links.type;
  12490. }
  12491. function getTypeOfEnumMember(symbol) {
  12492. var links = getSymbolLinks(symbol);
  12493. if (!links.type) {
  12494. links.type = getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
  12495. }
  12496. return links.type;
  12497. }
  12498. function getTypeOfAlias(symbol) {
  12499. var links = getSymbolLinks(symbol);
  12500. if (!links.type) {
  12501. var targetSymbol = resolveAlias(symbol);
  12502. links.type = targetSymbol.flags & 107455
  12503. ? getTypeOfSymbol(targetSymbol)
  12504. : unknownType;
  12505. }
  12506. return links.type;
  12507. }
  12508. function getTypeOfInstantiatedSymbol(symbol) {
  12509. var links = getSymbolLinks(symbol);
  12510. if (!links.type) {
  12511. links.type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
  12512. }
  12513. return links.type;
  12514. }
  12515. function getTypeOfSymbol(symbol) {
  12516. if (symbol.flags & 16777216) {
  12517. return getTypeOfInstantiatedSymbol(symbol);
  12518. }
  12519. if (symbol.flags & (3 | 4)) {
  12520. return getTypeOfVariableOrParameterOrProperty(symbol);
  12521. }
  12522. if (symbol.flags & (16 | 8192 | 32 | 384 | 512)) {
  12523. return getTypeOfFuncClassEnumModule(symbol);
  12524. }
  12525. if (symbol.flags & 8) {
  12526. return getTypeOfEnumMember(symbol);
  12527. }
  12528. if (symbol.flags & 98304) {
  12529. return getTypeOfAccessors(symbol);
  12530. }
  12531. if (symbol.flags & 8388608) {
  12532. return getTypeOfAlias(symbol);
  12533. }
  12534. return unknownType;
  12535. }
  12536. function getTargetType(type) {
  12537. return type.flags & 4096 ? type.target : type;
  12538. }
  12539. function hasBaseType(type, checkBase) {
  12540. return check(type);
  12541. function check(type) {
  12542. var target = getTargetType(type);
  12543. return target === checkBase || ts.forEach(getBaseTypes(target), check);
  12544. }
  12545. }
  12546. function appendTypeParameters(typeParameters, declarations) {
  12547. for (var _i = 0; _i < declarations.length; _i++) {
  12548. var declaration = declarations[_i];
  12549. var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration));
  12550. if (!typeParameters) {
  12551. typeParameters = [tp];
  12552. }
  12553. else if (!ts.contains(typeParameters, tp)) {
  12554. typeParameters.push(tp);
  12555. }
  12556. }
  12557. return typeParameters;
  12558. }
  12559. function appendOuterTypeParameters(typeParameters, node) {
  12560. while (true) {
  12561. node = node.parent;
  12562. if (!node) {
  12563. return typeParameters;
  12564. }
  12565. if (node.kind === 214 || node.kind === 186 ||
  12566. node.kind === 213 || node.kind === 173 ||
  12567. node.kind === 143 || node.kind === 174) {
  12568. var declarations = node.typeParameters;
  12569. if (declarations) {
  12570. return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations);
  12571. }
  12572. }
  12573. }
  12574. }
  12575. function getOuterTypeParametersOfClassOrInterface(symbol) {
  12576. var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 215);
  12577. return appendOuterTypeParameters(undefined, declaration);
  12578. }
  12579. function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) {
  12580. var result;
  12581. for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
  12582. var node = _a[_i];
  12583. if (node.kind === 215 || node.kind === 214 ||
  12584. node.kind === 186 || node.kind === 216) {
  12585. var declaration = node;
  12586. if (declaration.typeParameters) {
  12587. result = appendTypeParameters(result, declaration.typeParameters);
  12588. }
  12589. }
  12590. }
  12591. return result;
  12592. }
  12593. function getTypeParametersOfClassOrInterface(symbol) {
  12594. return ts.concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol));
  12595. }
  12596. function isConstructorType(type) {
  12597. return type.flags & 80896 && getSignaturesOfType(type, 1).length > 0;
  12598. }
  12599. function getBaseTypeNodeOfClass(type) {
  12600. return ts.getClassExtendsHeritageClauseElement(type.symbol.valueDeclaration);
  12601. }
  12602. function getConstructorsForTypeArguments(type, typeArgumentNodes) {
  12603. var typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
  12604. return ts.filter(getSignaturesOfType(type, 1), function (sig) { return (sig.typeParameters ? sig.typeParameters.length : 0) === typeArgCount; });
  12605. }
  12606. function getInstantiatedConstructorsForTypeArguments(type, typeArgumentNodes) {
  12607. var signatures = getConstructorsForTypeArguments(type, typeArgumentNodes);
  12608. if (typeArgumentNodes) {
  12609. var typeArguments = ts.map(typeArgumentNodes, getTypeFromTypeNode);
  12610. signatures = ts.map(signatures, function (sig) { return getSignatureInstantiation(sig, typeArguments); });
  12611. }
  12612. return signatures;
  12613. }
  12614. function getBaseConstructorTypeOfClass(type) {
  12615. if (!type.resolvedBaseConstructorType) {
  12616. var baseTypeNode = getBaseTypeNodeOfClass(type);
  12617. if (!baseTypeNode) {
  12618. return type.resolvedBaseConstructorType = undefinedType;
  12619. }
  12620. if (!pushTypeResolution(type, 1)) {
  12621. return unknownType;
  12622. }
  12623. var baseConstructorType = checkExpression(baseTypeNode.expression);
  12624. if (baseConstructorType.flags & 80896) {
  12625. resolveStructuredTypeMembers(baseConstructorType);
  12626. }
  12627. if (!popTypeResolution()) {
  12628. error(type.symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_base_expression, symbolToString(type.symbol));
  12629. return type.resolvedBaseConstructorType = unknownType;
  12630. }
  12631. if (baseConstructorType !== unknownType && baseConstructorType !== nullType && !isConstructorType(baseConstructorType)) {
  12632. error(baseTypeNode.expression, ts.Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType));
  12633. return type.resolvedBaseConstructorType = unknownType;
  12634. }
  12635. type.resolvedBaseConstructorType = baseConstructorType;
  12636. }
  12637. return type.resolvedBaseConstructorType;
  12638. }
  12639. function hasClassBaseType(type) {
  12640. return !!ts.forEach(getBaseTypes(type), function (t) { return !!(t.symbol.flags & 32); });
  12641. }
  12642. function getBaseTypes(type) {
  12643. var isClass = type.symbol.flags & 32;
  12644. var isInterface = type.symbol.flags & 64;
  12645. if (!type.resolvedBaseTypes) {
  12646. if (!isClass && !isInterface) {
  12647. ts.Debug.fail("type must be class or interface");
  12648. }
  12649. if (isClass) {
  12650. resolveBaseTypesOfClass(type);
  12651. }
  12652. if (isInterface) {
  12653. resolveBaseTypesOfInterface(type);
  12654. }
  12655. }
  12656. return type.resolvedBaseTypes;
  12657. }
  12658. function resolveBaseTypesOfClass(type) {
  12659. type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray;
  12660. var baseContructorType = getBaseConstructorTypeOfClass(type);
  12661. if (!(baseContructorType.flags & 80896)) {
  12662. return;
  12663. }
  12664. var baseTypeNode = getBaseTypeNodeOfClass(type);
  12665. var baseType;
  12666. if (baseContructorType.symbol && baseContructorType.symbol.flags & 32) {
  12667. baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseContructorType.symbol);
  12668. }
  12669. else {
  12670. var constructors = getInstantiatedConstructorsForTypeArguments(baseContructorType, baseTypeNode.typeArguments);
  12671. if (!constructors.length) {
  12672. error(baseTypeNode.expression, ts.Diagnostics.No_base_constructor_has_the_specified_number_of_type_arguments);
  12673. return;
  12674. }
  12675. baseType = getReturnTypeOfSignature(constructors[0]);
  12676. }
  12677. if (baseType === unknownType) {
  12678. return;
  12679. }
  12680. if (!(getTargetType(baseType).flags & (1024 | 2048))) {
  12681. error(baseTypeNode.expression, ts.Diagnostics.Base_constructor_return_type_0_is_not_a_class_or_interface_type, typeToString(baseType));
  12682. return;
  12683. }
  12684. if (type === baseType || hasBaseType(baseType, type)) {
  12685. error(type.symbol.valueDeclaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, undefined, 1));
  12686. return;
  12687. }
  12688. if (type.resolvedBaseTypes === emptyArray) {
  12689. type.resolvedBaseTypes = [baseType];
  12690. }
  12691. else {
  12692. type.resolvedBaseTypes.push(baseType);
  12693. }
  12694. }
  12695. function resolveBaseTypesOfInterface(type) {
  12696. type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray;
  12697. for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) {
  12698. var declaration = _a[_i];
  12699. if (declaration.kind === 215 && ts.getInterfaceBaseTypeNodes(declaration)) {
  12700. for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) {
  12701. var node = _c[_b];
  12702. var baseType = getTypeFromTypeNode(node);
  12703. if (baseType !== unknownType) {
  12704. if (getTargetType(baseType).flags & (1024 | 2048)) {
  12705. if (type !== baseType && !hasBaseType(baseType, type)) {
  12706. if (type.resolvedBaseTypes === emptyArray) {
  12707. type.resolvedBaseTypes = [baseType];
  12708. }
  12709. else {
  12710. type.resolvedBaseTypes.push(baseType);
  12711. }
  12712. }
  12713. else {
  12714. error(declaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, undefined, 1));
  12715. }
  12716. }
  12717. else {
  12718. error(node, ts.Diagnostics.An_interface_may_only_extend_a_class_or_another_interface);
  12719. }
  12720. }
  12721. }
  12722. }
  12723. }
  12724. }
  12725. function isIndependentInterface(symbol) {
  12726. for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
  12727. var declaration = _a[_i];
  12728. if (declaration.kind === 215) {
  12729. if (declaration.flags & 524288) {
  12730. return false;
  12731. }
  12732. var baseTypeNodes = ts.getInterfaceBaseTypeNodes(declaration);
  12733. if (baseTypeNodes) {
  12734. for (var _b = 0; _b < baseTypeNodes.length; _b++) {
  12735. var node = baseTypeNodes[_b];
  12736. if (ts.isSupportedExpressionWithTypeArguments(node)) {
  12737. var baseSymbol = resolveEntityName(node.expression, 793056, true);
  12738. if (!baseSymbol || !(baseSymbol.flags & 64) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) {
  12739. return false;
  12740. }
  12741. }
  12742. }
  12743. }
  12744. }
  12745. }
  12746. return true;
  12747. }
  12748. function getDeclaredTypeOfClassOrInterface(symbol) {
  12749. var links = getSymbolLinks(symbol);
  12750. if (!links.declaredType) {
  12751. var kind = symbol.flags & 32 ? 1024 : 2048;
  12752. var type = links.declaredType = createObjectType(kind, symbol);
  12753. var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol);
  12754. var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
  12755. if (outerTypeParameters || localTypeParameters || kind === 1024 || !isIndependentInterface(symbol)) {
  12756. type.flags |= 4096;
  12757. type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters);
  12758. type.outerTypeParameters = outerTypeParameters;
  12759. type.localTypeParameters = localTypeParameters;
  12760. type.instantiations = {};
  12761. type.instantiations[getTypeListId(type.typeParameters)] = type;
  12762. type.target = type;
  12763. type.typeArguments = type.typeParameters;
  12764. type.thisType = createType(512 | 33554432);
  12765. type.thisType.symbol = symbol;
  12766. type.thisType.constraint = getTypeWithThisArgument(type);
  12767. }
  12768. }
  12769. return links.declaredType;
  12770. }
  12771. function getDeclaredTypeOfTypeAlias(symbol) {
  12772. var links = getSymbolLinks(symbol);
  12773. if (!links.declaredType) {
  12774. if (!pushTypeResolution(symbol, 2)) {
  12775. return unknownType;
  12776. }
  12777. var declaration = ts.getDeclarationOfKind(symbol, 216);
  12778. var type = getTypeFromTypeNode(declaration.type);
  12779. if (popTypeResolution()) {
  12780. links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
  12781. if (links.typeParameters) {
  12782. links.instantiations = {};
  12783. links.instantiations[getTypeListId(links.typeParameters)] = type;
  12784. }
  12785. }
  12786. else {
  12787. type = unknownType;
  12788. error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
  12789. }
  12790. links.declaredType = type;
  12791. }
  12792. return links.declaredType;
  12793. }
  12794. function getDeclaredTypeOfEnum(symbol) {
  12795. var links = getSymbolLinks(symbol);
  12796. if (!links.declaredType) {
  12797. var type = createType(128);
  12798. type.symbol = symbol;
  12799. links.declaredType = type;
  12800. }
  12801. return links.declaredType;
  12802. }
  12803. function getDeclaredTypeOfTypeParameter(symbol) {
  12804. var links = getSymbolLinks(symbol);
  12805. if (!links.declaredType) {
  12806. var type = createType(512);
  12807. type.symbol = symbol;
  12808. if (!ts.getDeclarationOfKind(symbol, 137).constraint) {
  12809. type.constraint = noConstraintType;
  12810. }
  12811. links.declaredType = type;
  12812. }
  12813. return links.declaredType;
  12814. }
  12815. function getDeclaredTypeOfAlias(symbol) {
  12816. var links = getSymbolLinks(symbol);
  12817. if (!links.declaredType) {
  12818. links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol));
  12819. }
  12820. return links.declaredType;
  12821. }
  12822. function getDeclaredTypeOfSymbol(symbol) {
  12823. ts.Debug.assert((symbol.flags & 16777216) === 0);
  12824. if (symbol.flags & (32 | 64)) {
  12825. return getDeclaredTypeOfClassOrInterface(symbol);
  12826. }
  12827. if (symbol.flags & 524288) {
  12828. return getDeclaredTypeOfTypeAlias(symbol);
  12829. }
  12830. if (symbol.flags & 384) {
  12831. return getDeclaredTypeOfEnum(symbol);
  12832. }
  12833. if (symbol.flags & 262144) {
  12834. return getDeclaredTypeOfTypeParameter(symbol);
  12835. }
  12836. if (symbol.flags & 8388608) {
  12837. return getDeclaredTypeOfAlias(symbol);
  12838. }
  12839. return unknownType;
  12840. }
  12841. function isIndependentTypeReference(node) {
  12842. if (node.typeArguments) {
  12843. for (var _i = 0, _a = node.typeArguments; _i < _a.length; _i++) {
  12844. var typeNode = _a[_i];
  12845. if (!isIndependentType(typeNode)) {
  12846. return false;
  12847. }
  12848. }
  12849. }
  12850. return true;
  12851. }
  12852. function isIndependentType(node) {
  12853. switch (node.kind) {
  12854. case 117:
  12855. case 130:
  12856. case 128:
  12857. case 120:
  12858. case 131:
  12859. case 103:
  12860. case 9:
  12861. return true;
  12862. case 156:
  12863. return isIndependentType(node.elementType);
  12864. case 151:
  12865. return isIndependentTypeReference(node);
  12866. }
  12867. return false;
  12868. }
  12869. function isIndependentVariableLikeDeclaration(node) {
  12870. return node.type && isIndependentType(node.type) || !node.type && !node.initializer;
  12871. }
  12872. function isIndependentFunctionLikeDeclaration(node) {
  12873. if (node.kind !== 144 && (!node.type || !isIndependentType(node.type))) {
  12874. return false;
  12875. }
  12876. for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
  12877. var parameter = _a[_i];
  12878. if (!isIndependentVariableLikeDeclaration(parameter)) {
  12879. return false;
  12880. }
  12881. }
  12882. return true;
  12883. }
  12884. function isIndependentMember(symbol) {
  12885. if (symbol.declarations && symbol.declarations.length === 1) {
  12886. var declaration = symbol.declarations[0];
  12887. if (declaration) {
  12888. switch (declaration.kind) {
  12889. case 141:
  12890. case 140:
  12891. return isIndependentVariableLikeDeclaration(declaration);
  12892. case 143:
  12893. case 142:
  12894. case 144:
  12895. return isIndependentFunctionLikeDeclaration(declaration);
  12896. }
  12897. }
  12898. }
  12899. return false;
  12900. }
  12901. function createSymbolTable(symbols) {
  12902. var result = {};
  12903. for (var _i = 0; _i < symbols.length; _i++) {
  12904. var symbol = symbols[_i];
  12905. result[symbol.name] = symbol;
  12906. }
  12907. return result;
  12908. }
  12909. function createInstantiatedSymbolTable(symbols, mapper, mappingThisOnly) {
  12910. var result = {};
  12911. for (var _i = 0; _i < symbols.length; _i++) {
  12912. var symbol = symbols[_i];
  12913. result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper);
  12914. }
  12915. return result;
  12916. }
  12917. function addInheritedMembers(symbols, baseSymbols) {
  12918. for (var _i = 0; _i < baseSymbols.length; _i++) {
  12919. var s = baseSymbols[_i];
  12920. if (!ts.hasProperty(symbols, s.name)) {
  12921. symbols[s.name] = s;
  12922. }
  12923. }
  12924. }
  12925. function addInheritedSignatures(signatures, baseSignatures) {
  12926. if (baseSignatures) {
  12927. for (var _i = 0; _i < baseSignatures.length; _i++) {
  12928. var signature = baseSignatures[_i];
  12929. signatures.push(signature);
  12930. }
  12931. }
  12932. }
  12933. function resolveDeclaredMembers(type) {
  12934. if (!type.declaredProperties) {
  12935. var symbol = type.symbol;
  12936. type.declaredProperties = getNamedMembers(symbol.members);
  12937. type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]);
  12938. type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]);
  12939. type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, 0);
  12940. type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, 1);
  12941. }
  12942. return type;
  12943. }
  12944. function getTypeWithThisArgument(type, thisArgument) {
  12945. if (type.flags & 4096) {
  12946. return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType]));
  12947. }
  12948. return type;
  12949. }
  12950. function resolveObjectTypeMembers(type, source, typeParameters, typeArguments) {
  12951. var mapper = identityMapper;
  12952. var members = source.symbol.members;
  12953. var callSignatures = source.declaredCallSignatures;
  12954. var constructSignatures = source.declaredConstructSignatures;
  12955. var stringIndexType = source.declaredStringIndexType;
  12956. var numberIndexType = source.declaredNumberIndexType;
  12957. if (!ts.rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) {
  12958. mapper = createTypeMapper(typeParameters, typeArguments);
  12959. members = createInstantiatedSymbolTable(source.declaredProperties, mapper, typeParameters.length === 1);
  12960. callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature);
  12961. constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature);
  12962. stringIndexType = instantiateType(source.declaredStringIndexType, mapper);
  12963. numberIndexType = instantiateType(source.declaredNumberIndexType, mapper);
  12964. }
  12965. var baseTypes = getBaseTypes(source);
  12966. if (baseTypes.length) {
  12967. if (members === source.symbol.members) {
  12968. members = createSymbolTable(source.declaredProperties);
  12969. }
  12970. var thisArgument = ts.lastOrUndefined(typeArguments);
  12971. for (var _i = 0; _i < baseTypes.length; _i++) {
  12972. var baseType = baseTypes[_i];
  12973. var instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType;
  12974. addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType));
  12975. callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0));
  12976. constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1));
  12977. stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0);
  12978. numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1);
  12979. }
  12980. }
  12981. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  12982. }
  12983. function resolveClassOrInterfaceMembers(type) {
  12984. resolveObjectTypeMembers(type, resolveDeclaredMembers(type), emptyArray, emptyArray);
  12985. }
  12986. function resolveTypeReferenceMembers(type) {
  12987. var source = resolveDeclaredMembers(type.target);
  12988. var typeParameters = ts.concatenate(source.typeParameters, [source.thisType]);
  12989. var typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ?
  12990. type.typeArguments : ts.concatenate(type.typeArguments, [type]);
  12991. resolveObjectTypeMembers(type, source, typeParameters, typeArguments);
  12992. }
  12993. function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) {
  12994. var sig = new Signature(checker);
  12995. sig.declaration = declaration;
  12996. sig.typeParameters = typeParameters;
  12997. sig.parameters = parameters;
  12998. sig.resolvedReturnType = resolvedReturnType;
  12999. sig.typePredicate = typePredicate;
  13000. sig.minArgumentCount = minArgumentCount;
  13001. sig.hasRestParameter = hasRestParameter;
  13002. sig.hasStringLiterals = hasStringLiterals;
  13003. return sig;
  13004. }
  13005. function cloneSignature(sig) {
  13006. return createSignature(sig.declaration, sig.typeParameters, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals);
  13007. }
  13008. function getDefaultConstructSignatures(classType) {
  13009. if (!hasClassBaseType(classType)) {
  13010. return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)];
  13011. }
  13012. var baseConstructorType = getBaseConstructorTypeOfClass(classType);
  13013. var baseSignatures = getSignaturesOfType(baseConstructorType, 1);
  13014. var baseTypeNode = getBaseTypeNodeOfClass(classType);
  13015. var typeArguments = ts.map(baseTypeNode.typeArguments, getTypeFromTypeNode);
  13016. var typeArgCount = typeArguments ? typeArguments.length : 0;
  13017. var result = [];
  13018. for (var _i = 0; _i < baseSignatures.length; _i++) {
  13019. var baseSig = baseSignatures[_i];
  13020. var typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0;
  13021. if (typeParamCount === typeArgCount) {
  13022. var sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig);
  13023. sig.typeParameters = classType.localTypeParameters;
  13024. sig.resolvedReturnType = classType;
  13025. result.push(sig);
  13026. }
  13027. }
  13028. return result;
  13029. }
  13030. function createTupleTypeMemberSymbols(memberTypes) {
  13031. var members = {};
  13032. for (var i = 0; i < memberTypes.length; i++) {
  13033. var symbol = createSymbol(4 | 67108864, "" + i);
  13034. symbol.type = memberTypes[i];
  13035. members[i] = symbol;
  13036. }
  13037. return members;
  13038. }
  13039. function resolveTupleTypeMembers(type) {
  13040. var arrayElementType = getUnionType(type.elementTypes, true);
  13041. var arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type]));
  13042. var members = createTupleTypeMemberSymbols(type.elementTypes);
  13043. addInheritedMembers(members, arrayType.properties);
  13044. setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
  13045. }
  13046. function findMatchingSignature(signatureList, signature, partialMatch, ignoreReturnTypes) {
  13047. for (var _i = 0; _i < signatureList.length; _i++) {
  13048. var s = signatureList[_i];
  13049. if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
  13050. return s;
  13051. }
  13052. }
  13053. }
  13054. function findMatchingSignatures(signatureLists, signature, listIndex) {
  13055. if (signature.typeParameters) {
  13056. if (listIndex > 0) {
  13057. return undefined;
  13058. }
  13059. for (var i = 1; i < signatureLists.length; i++) {
  13060. if (!findMatchingSignature(signatureLists[i], signature, false, false)) {
  13061. return undefined;
  13062. }
  13063. }
  13064. return [signature];
  13065. }
  13066. var result = undefined;
  13067. for (var i = 0; i < signatureLists.length; i++) {
  13068. var match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, true, true);
  13069. if (!match) {
  13070. return undefined;
  13071. }
  13072. if (!ts.contains(result, match)) {
  13073. (result || (result = [])).push(match);
  13074. }
  13075. }
  13076. return result;
  13077. }
  13078. function getUnionSignatures(types, kind) {
  13079. var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); });
  13080. var result = undefined;
  13081. for (var i = 0; i < signatureLists.length; i++) {
  13082. for (var _i = 0, _a = signatureLists[i]; _i < _a.length; _i++) {
  13083. var signature = _a[_i];
  13084. if (!result || !findMatchingSignature(result, signature, false, true)) {
  13085. var unionSignatures = findMatchingSignatures(signatureLists, signature, i);
  13086. if (unionSignatures) {
  13087. var s = signature;
  13088. if (unionSignatures.length > 1) {
  13089. s = cloneSignature(signature);
  13090. s.resolvedReturnType = undefined;
  13091. s.unionSignatures = unionSignatures;
  13092. }
  13093. (result || (result = [])).push(s);
  13094. }
  13095. }
  13096. }
  13097. }
  13098. return result || emptyArray;
  13099. }
  13100. function getUnionIndexType(types, kind) {
  13101. var indexTypes = [];
  13102. for (var _i = 0; _i < types.length; _i++) {
  13103. var type = types[_i];
  13104. var indexType = getIndexTypeOfType(type, kind);
  13105. if (!indexType) {
  13106. return undefined;
  13107. }
  13108. indexTypes.push(indexType);
  13109. }
  13110. return getUnionType(indexTypes);
  13111. }
  13112. function resolveUnionTypeMembers(type) {
  13113. var callSignatures = getUnionSignatures(type.types, 0);
  13114. var constructSignatures = getUnionSignatures(type.types, 1);
  13115. var stringIndexType = getUnionIndexType(type.types, 0);
  13116. var numberIndexType = getUnionIndexType(type.types, 1);
  13117. setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  13118. }
  13119. function intersectTypes(type1, type2) {
  13120. return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]);
  13121. }
  13122. function resolveIntersectionTypeMembers(type) {
  13123. var callSignatures = emptyArray;
  13124. var constructSignatures = emptyArray;
  13125. var stringIndexType = undefined;
  13126. var numberIndexType = undefined;
  13127. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  13128. var t = _a[_i];
  13129. callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(t, 0));
  13130. constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(t, 1));
  13131. stringIndexType = intersectTypes(stringIndexType, getIndexTypeOfType(t, 0));
  13132. numberIndexType = intersectTypes(numberIndexType, getIndexTypeOfType(t, 1));
  13133. }
  13134. setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  13135. }
  13136. function resolveAnonymousTypeMembers(type) {
  13137. var symbol = type.symbol;
  13138. var members;
  13139. var callSignatures;
  13140. var constructSignatures;
  13141. var stringIndexType;
  13142. var numberIndexType;
  13143. if (type.target) {
  13144. members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, false);
  13145. callSignatures = instantiateList(getSignaturesOfType(type.target, 0), type.mapper, instantiateSignature);
  13146. constructSignatures = instantiateList(getSignaturesOfType(type.target, 1), type.mapper, instantiateSignature);
  13147. stringIndexType = instantiateType(getIndexTypeOfType(type.target, 0), type.mapper);
  13148. numberIndexType = instantiateType(getIndexTypeOfType(type.target, 1), type.mapper);
  13149. }
  13150. else if (symbol.flags & 2048) {
  13151. members = symbol.members;
  13152. callSignatures = getSignaturesOfSymbol(members["__call"]);
  13153. constructSignatures = getSignaturesOfSymbol(members["__new"]);
  13154. stringIndexType = getIndexTypeOfSymbol(symbol, 0);
  13155. numberIndexType = getIndexTypeOfSymbol(symbol, 1);
  13156. }
  13157. else {
  13158. members = emptySymbols;
  13159. callSignatures = emptyArray;
  13160. constructSignatures = emptyArray;
  13161. if (symbol.flags & 1952) {
  13162. members = getExportsOfSymbol(symbol);
  13163. }
  13164. if (symbol.flags & (16 | 8192)) {
  13165. callSignatures = getSignaturesOfSymbol(symbol);
  13166. }
  13167. if (symbol.flags & 32) {
  13168. var classType = getDeclaredTypeOfClassOrInterface(symbol);
  13169. constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
  13170. if (!constructSignatures.length) {
  13171. constructSignatures = getDefaultConstructSignatures(classType);
  13172. }
  13173. var baseConstructorType = getBaseConstructorTypeOfClass(classType);
  13174. if (baseConstructorType.flags & 80896) {
  13175. members = createSymbolTable(getNamedMembers(members));
  13176. addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType));
  13177. }
  13178. }
  13179. stringIndexType = undefined;
  13180. numberIndexType = (symbol.flags & 384) ? stringType : undefined;
  13181. }
  13182. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  13183. }
  13184. function resolveStructuredTypeMembers(type) {
  13185. if (!type.members) {
  13186. if (type.flags & 4096) {
  13187. resolveTypeReferenceMembers(type);
  13188. }
  13189. else if (type.flags & (1024 | 2048)) {
  13190. resolveClassOrInterfaceMembers(type);
  13191. }
  13192. else if (type.flags & 65536) {
  13193. resolveAnonymousTypeMembers(type);
  13194. }
  13195. else if (type.flags & 8192) {
  13196. resolveTupleTypeMembers(type);
  13197. }
  13198. else if (type.flags & 16384) {
  13199. resolveUnionTypeMembers(type);
  13200. }
  13201. else if (type.flags & 32768) {
  13202. resolveIntersectionTypeMembers(type);
  13203. }
  13204. }
  13205. return type;
  13206. }
  13207. function getPropertiesOfObjectType(type) {
  13208. if (type.flags & 80896) {
  13209. return resolveStructuredTypeMembers(type).properties;
  13210. }
  13211. return emptyArray;
  13212. }
  13213. function getPropertyOfObjectType(type, name) {
  13214. if (type.flags & 80896) {
  13215. var resolved = resolveStructuredTypeMembers(type);
  13216. if (ts.hasProperty(resolved.members, name)) {
  13217. var symbol = resolved.members[name];
  13218. if (symbolIsValue(symbol)) {
  13219. return symbol;
  13220. }
  13221. }
  13222. }
  13223. }
  13224. function getPropertiesOfUnionOrIntersectionType(type) {
  13225. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  13226. var current = _a[_i];
  13227. for (var _b = 0, _c = getPropertiesOfType(current); _b < _c.length; _b++) {
  13228. var prop = _c[_b];
  13229. getPropertyOfUnionOrIntersectionType(type, prop.name);
  13230. }
  13231. if (type.flags & 16384) {
  13232. break;
  13233. }
  13234. }
  13235. return type.resolvedProperties ? symbolsToArray(type.resolvedProperties) : emptyArray;
  13236. }
  13237. function getPropertiesOfType(type) {
  13238. type = getApparentType(type);
  13239. return type.flags & 49152 ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type);
  13240. }
  13241. function getApparentType(type) {
  13242. if (type.flags & 512) {
  13243. do {
  13244. type = getConstraintOfTypeParameter(type);
  13245. } while (type && type.flags & 512);
  13246. if (!type) {
  13247. type = emptyObjectType;
  13248. }
  13249. }
  13250. if (type.flags & 258) {
  13251. type = globalStringType;
  13252. }
  13253. else if (type.flags & 132) {
  13254. type = globalNumberType;
  13255. }
  13256. else if (type.flags & 8) {
  13257. type = globalBooleanType;
  13258. }
  13259. else if (type.flags & 16777216) {
  13260. type = globalESSymbolType;
  13261. }
  13262. return type;
  13263. }
  13264. function createUnionOrIntersectionProperty(containingType, name) {
  13265. var types = containingType.types;
  13266. var props;
  13267. for (var _i = 0; _i < types.length; _i++) {
  13268. var current = types[_i];
  13269. var type = getApparentType(current);
  13270. if (type !== unknownType) {
  13271. var prop = getPropertyOfType(type, name);
  13272. if (prop && !(getDeclarationFlagsFromSymbol(prop) & (32 | 64))) {
  13273. if (!props) {
  13274. props = [prop];
  13275. }
  13276. else if (!ts.contains(props, prop)) {
  13277. props.push(prop);
  13278. }
  13279. }
  13280. else if (containingType.flags & 16384) {
  13281. return undefined;
  13282. }
  13283. }
  13284. }
  13285. if (!props) {
  13286. return undefined;
  13287. }
  13288. if (props.length === 1) {
  13289. return props[0];
  13290. }
  13291. var propTypes = [];
  13292. var declarations = [];
  13293. for (var _a = 0; _a < props.length; _a++) {
  13294. var prop = props[_a];
  13295. if (prop.declarations) {
  13296. ts.addRange(declarations, prop.declarations);
  13297. }
  13298. propTypes.push(getTypeOfSymbol(prop));
  13299. }
  13300. var result = createSymbol(4 | 67108864 | 268435456, name);
  13301. result.containingType = containingType;
  13302. result.declarations = declarations;
  13303. result.type = containingType.flags & 16384 ? getUnionType(propTypes) : getIntersectionType(propTypes);
  13304. return result;
  13305. }
  13306. function getPropertyOfUnionOrIntersectionType(type, name) {
  13307. var properties = type.resolvedProperties || (type.resolvedProperties = {});
  13308. if (ts.hasProperty(properties, name)) {
  13309. return properties[name];
  13310. }
  13311. var property = createUnionOrIntersectionProperty(type, name);
  13312. if (property) {
  13313. properties[name] = property;
  13314. }
  13315. return property;
  13316. }
  13317. function getPropertyOfType(type, name) {
  13318. type = getApparentType(type);
  13319. if (type.flags & 80896) {
  13320. var resolved = resolveStructuredTypeMembers(type);
  13321. if (ts.hasProperty(resolved.members, name)) {
  13322. var symbol = resolved.members[name];
  13323. if (symbolIsValue(symbol)) {
  13324. return symbol;
  13325. }
  13326. }
  13327. if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) {
  13328. var symbol = getPropertyOfObjectType(globalFunctionType, name);
  13329. if (symbol) {
  13330. return symbol;
  13331. }
  13332. }
  13333. return getPropertyOfObjectType(globalObjectType, name);
  13334. }
  13335. if (type.flags & 49152) {
  13336. return getPropertyOfUnionOrIntersectionType(type, name);
  13337. }
  13338. return undefined;
  13339. }
  13340. function getSignaturesOfStructuredType(type, kind) {
  13341. if (type.flags & 130048) {
  13342. var resolved = resolveStructuredTypeMembers(type);
  13343. return kind === 0 ? resolved.callSignatures : resolved.constructSignatures;
  13344. }
  13345. return emptyArray;
  13346. }
  13347. function getSignaturesOfType(type, kind) {
  13348. return getSignaturesOfStructuredType(getApparentType(type), kind);
  13349. }
  13350. function typeHasConstructSignatures(type) {
  13351. var apparentType = getApparentType(type);
  13352. if (apparentType.flags & (80896 | 16384)) {
  13353. var resolved = resolveStructuredTypeMembers(type);
  13354. return resolved.constructSignatures.length > 0;
  13355. }
  13356. return false;
  13357. }
  13358. function typeHasCallOrConstructSignatures(type) {
  13359. var apparentType = getApparentType(type);
  13360. if (apparentType.flags & 130048) {
  13361. var resolved = resolveStructuredTypeMembers(type);
  13362. return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0;
  13363. }
  13364. return false;
  13365. }
  13366. function getIndexTypeOfStructuredType(type, kind) {
  13367. if (type.flags & 130048) {
  13368. var resolved = resolveStructuredTypeMembers(type);
  13369. return kind === 0 ? resolved.stringIndexType : resolved.numberIndexType;
  13370. }
  13371. }
  13372. function getIndexTypeOfType(type, kind) {
  13373. return getIndexTypeOfStructuredType(getApparentType(type), kind);
  13374. }
  13375. function getTypeParametersFromDeclaration(typeParameterDeclarations) {
  13376. var result = [];
  13377. ts.forEach(typeParameterDeclarations, function (node) {
  13378. var tp = getDeclaredTypeOfTypeParameter(node.symbol);
  13379. if (!ts.contains(result, tp)) {
  13380. result.push(tp);
  13381. }
  13382. });
  13383. return result;
  13384. }
  13385. function symbolsToArray(symbols) {
  13386. var result = [];
  13387. for (var id in symbols) {
  13388. if (!isReservedMemberName(id)) {
  13389. result.push(symbols[id]);
  13390. }
  13391. }
  13392. return result;
  13393. }
  13394. function isOptionalParameter(node) {
  13395. if (ts.hasQuestionToken(node)) {
  13396. return true;
  13397. }
  13398. if (node.initializer) {
  13399. var signatureDeclaration = node.parent;
  13400. var signature = getSignatureFromDeclaration(signatureDeclaration);
  13401. var parameterIndex = signatureDeclaration.parameters.indexOf(node);
  13402. ts.Debug.assert(parameterIndex >= 0);
  13403. return parameterIndex >= signature.minArgumentCount;
  13404. }
  13405. return false;
  13406. }
  13407. function getSignatureFromDeclaration(declaration) {
  13408. var links = getNodeLinks(declaration);
  13409. if (!links.resolvedSignature) {
  13410. var classType = declaration.kind === 144 ?
  13411. getDeclaredTypeOfClassOrInterface(getMergedSymbol(declaration.parent.symbol))
  13412. : undefined;
  13413. var typeParameters = classType ? classType.localTypeParameters :
  13414. declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined;
  13415. var parameters = [];
  13416. var hasStringLiterals = false;
  13417. var minArgumentCount = -1;
  13418. for (var i = 0, n = declaration.parameters.length; i < n; i++) {
  13419. var param = declaration.parameters[i];
  13420. parameters.push(param.symbol);
  13421. if (param.type && param.type.kind === 9) {
  13422. hasStringLiterals = true;
  13423. }
  13424. if (param.initializer || param.questionToken || param.dotDotDotToken) {
  13425. if (minArgumentCount < 0) {
  13426. minArgumentCount = i;
  13427. }
  13428. }
  13429. else {
  13430. minArgumentCount = -1;
  13431. }
  13432. }
  13433. if (minArgumentCount < 0) {
  13434. minArgumentCount = declaration.parameters.length;
  13435. }
  13436. var returnType;
  13437. var typePredicate;
  13438. if (classType) {
  13439. returnType = classType;
  13440. }
  13441. else if (declaration.type) {
  13442. returnType = getTypeFromTypeNode(declaration.type);
  13443. if (declaration.type.kind === 150) {
  13444. var typePredicateNode = declaration.type;
  13445. typePredicate = {
  13446. parameterName: typePredicateNode.parameterName ? typePredicateNode.parameterName.text : undefined,
  13447. parameterIndex: typePredicateNode.parameterName ? getTypePredicateParameterIndex(declaration.parameters, typePredicateNode.parameterName) : undefined,
  13448. type: getTypeFromTypeNode(typePredicateNode.type)
  13449. };
  13450. }
  13451. }
  13452. else {
  13453. if (declaration.kind === 145 && !ts.hasDynamicName(declaration)) {
  13454. var setter = ts.getDeclarationOfKind(declaration.symbol, 146);
  13455. returnType = getAnnotatedAccessorType(setter);
  13456. }
  13457. if (!returnType && ts.nodeIsMissing(declaration.body)) {
  13458. returnType = anyType;
  13459. }
  13460. }
  13461. links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals);
  13462. }
  13463. return links.resolvedSignature;
  13464. }
  13465. function getSignaturesOfSymbol(symbol) {
  13466. if (!symbol)
  13467. return emptyArray;
  13468. var result = [];
  13469. for (var i = 0, len = symbol.declarations.length; i < len; i++) {
  13470. var node = symbol.declarations[i];
  13471. switch (node.kind) {
  13472. case 152:
  13473. case 153:
  13474. case 213:
  13475. case 143:
  13476. case 142:
  13477. case 144:
  13478. case 147:
  13479. case 148:
  13480. case 149:
  13481. case 145:
  13482. case 146:
  13483. case 173:
  13484. case 174:
  13485. if (i > 0 && node.body) {
  13486. var previous = symbol.declarations[i - 1];
  13487. if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) {
  13488. break;
  13489. }
  13490. }
  13491. result.push(getSignatureFromDeclaration(node));
  13492. }
  13493. }
  13494. return result;
  13495. }
  13496. function getReturnTypeOfSignature(signature) {
  13497. if (!signature.resolvedReturnType) {
  13498. if (!pushTypeResolution(signature, 3)) {
  13499. return unknownType;
  13500. }
  13501. var type;
  13502. if (signature.target) {
  13503. type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
  13504. }
  13505. else if (signature.unionSignatures) {
  13506. type = getUnionType(ts.map(signature.unionSignatures, getReturnTypeOfSignature));
  13507. }
  13508. else {
  13509. type = getReturnTypeFromBody(signature.declaration);
  13510. }
  13511. if (!popTypeResolution()) {
  13512. type = anyType;
  13513. if (compilerOptions.noImplicitAny) {
  13514. var declaration = signature.declaration;
  13515. if (declaration.name) {
  13516. error(declaration.name, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, ts.declarationNameToString(declaration.name));
  13517. }
  13518. else {
  13519. error(declaration, ts.Diagnostics.Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions);
  13520. }
  13521. }
  13522. }
  13523. signature.resolvedReturnType = type;
  13524. }
  13525. return signature.resolvedReturnType;
  13526. }
  13527. function getRestTypeOfSignature(signature) {
  13528. if (signature.hasRestParameter) {
  13529. var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
  13530. if (type.flags & 4096 && type.target === globalArrayType) {
  13531. return type.typeArguments[0];
  13532. }
  13533. }
  13534. return anyType;
  13535. }
  13536. function getSignatureInstantiation(signature, typeArguments) {
  13537. return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), true);
  13538. }
  13539. function getErasedSignature(signature) {
  13540. if (!signature.typeParameters)
  13541. return signature;
  13542. if (!signature.erasedSignatureCache) {
  13543. if (signature.target) {
  13544. signature.erasedSignatureCache = instantiateSignature(getErasedSignature(signature.target), signature.mapper);
  13545. }
  13546. else {
  13547. signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), true);
  13548. }
  13549. }
  13550. return signature.erasedSignatureCache;
  13551. }
  13552. function getOrCreateTypeFromSignature(signature) {
  13553. if (!signature.isolatedSignatureType) {
  13554. var isConstructor = signature.declaration.kind === 144 || signature.declaration.kind === 148;
  13555. var type = createObjectType(65536 | 262144);
  13556. type.members = emptySymbols;
  13557. type.properties = emptyArray;
  13558. type.callSignatures = !isConstructor ? [signature] : emptyArray;
  13559. type.constructSignatures = isConstructor ? [signature] : emptyArray;
  13560. signature.isolatedSignatureType = type;
  13561. }
  13562. return signature.isolatedSignatureType;
  13563. }
  13564. function getIndexSymbol(symbol) {
  13565. return symbol.members["__index"];
  13566. }
  13567. function getIndexDeclarationOfSymbol(symbol, kind) {
  13568. var syntaxKind = kind === 1 ? 128 : 130;
  13569. var indexSymbol = getIndexSymbol(symbol);
  13570. if (indexSymbol) {
  13571. for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
  13572. var decl = _a[_i];
  13573. var node = decl;
  13574. if (node.parameters.length === 1) {
  13575. var parameter = node.parameters[0];
  13576. if (parameter && parameter.type && parameter.type.kind === syntaxKind) {
  13577. return node;
  13578. }
  13579. }
  13580. }
  13581. }
  13582. return undefined;
  13583. }
  13584. function getIndexTypeOfSymbol(symbol, kind) {
  13585. var declaration = getIndexDeclarationOfSymbol(symbol, kind);
  13586. return declaration
  13587. ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType
  13588. : undefined;
  13589. }
  13590. function getConstraintOfTypeParameter(type) {
  13591. if (!type.constraint) {
  13592. if (type.target) {
  13593. var targetConstraint = getConstraintOfTypeParameter(type.target);
  13594. type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType;
  13595. }
  13596. else {
  13597. type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 137).constraint);
  13598. }
  13599. }
  13600. return type.constraint === noConstraintType ? undefined : type.constraint;
  13601. }
  13602. function getParentSymbolOfTypeParameter(typeParameter) {
  13603. return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 137).parent);
  13604. }
  13605. function getTypeListId(types) {
  13606. if (types) {
  13607. switch (types.length) {
  13608. case 1:
  13609. return "" + types[0].id;
  13610. case 2:
  13611. return types[0].id + "," + types[1].id;
  13612. default:
  13613. var result = "";
  13614. for (var i = 0; i < types.length; i++) {
  13615. if (i > 0) {
  13616. result += ",";
  13617. }
  13618. result += types[i].id;
  13619. }
  13620. return result;
  13621. }
  13622. }
  13623. return "";
  13624. }
  13625. function getPropagatingFlagsOfTypes(types) {
  13626. var result = 0;
  13627. for (var _i = 0; _i < types.length; _i++) {
  13628. var type = types[_i];
  13629. result |= type.flags;
  13630. }
  13631. return result & 14680064;
  13632. }
  13633. function createTypeReference(target, typeArguments) {
  13634. var id = getTypeListId(typeArguments);
  13635. var type = target.instantiations[id];
  13636. if (!type) {
  13637. var flags = 4096 | (typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0);
  13638. type = target.instantiations[id] = createObjectType(flags, target.symbol);
  13639. type.target = target;
  13640. type.typeArguments = typeArguments;
  13641. }
  13642. return type;
  13643. }
  13644. function isTypeParameterReferenceIllegalInConstraint(typeReferenceNode, typeParameterSymbol) {
  13645. var links = getNodeLinks(typeReferenceNode);
  13646. if (links.isIllegalTypeReferenceInConstraint !== undefined) {
  13647. return links.isIllegalTypeReferenceInConstraint;
  13648. }
  13649. var currentNode = typeReferenceNode;
  13650. while (!ts.forEach(typeParameterSymbol.declarations, function (d) { return d.parent === currentNode.parent; })) {
  13651. currentNode = currentNode.parent;
  13652. }
  13653. links.isIllegalTypeReferenceInConstraint = currentNode.kind === 137;
  13654. return links.isIllegalTypeReferenceInConstraint;
  13655. }
  13656. function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) {
  13657. var typeParameterSymbol;
  13658. function check(n) {
  13659. if (n.kind === 151 && n.typeName.kind === 69) {
  13660. var links = getNodeLinks(n);
  13661. if (links.isIllegalTypeReferenceInConstraint === undefined) {
  13662. var symbol = resolveName(typeParameter, n.typeName.text, 793056, undefined, undefined);
  13663. if (symbol && (symbol.flags & 262144)) {
  13664. links.isIllegalTypeReferenceInConstraint = ts.forEach(symbol.declarations, function (d) { return d.parent === typeParameter.parent; });
  13665. }
  13666. }
  13667. if (links.isIllegalTypeReferenceInConstraint) {
  13668. error(typeParameter, ts.Diagnostics.Constraint_of_a_type_parameter_cannot_reference_any_type_parameter_from_the_same_type_parameter_list);
  13669. }
  13670. }
  13671. ts.forEachChild(n, check);
  13672. }
  13673. if (typeParameter.constraint) {
  13674. typeParameterSymbol = getSymbolOfNode(typeParameter);
  13675. check(typeParameter.constraint);
  13676. }
  13677. }
  13678. function getTypeFromClassOrInterfaceReference(node, symbol) {
  13679. var type = getDeclaredTypeOfSymbol(symbol);
  13680. var typeParameters = type.localTypeParameters;
  13681. if (typeParameters) {
  13682. if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
  13683. error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), typeParameters.length);
  13684. return unknownType;
  13685. }
  13686. return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(node.typeArguments, getTypeFromTypeNode)));
  13687. }
  13688. if (node.typeArguments) {
  13689. error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type));
  13690. return unknownType;
  13691. }
  13692. return type;
  13693. }
  13694. function getTypeFromTypeAliasReference(node, symbol) {
  13695. var type = getDeclaredTypeOfSymbol(symbol);
  13696. var links = getSymbolLinks(symbol);
  13697. var typeParameters = links.typeParameters;
  13698. if (typeParameters) {
  13699. if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
  13700. error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length);
  13701. return unknownType;
  13702. }
  13703. var typeArguments = ts.map(node.typeArguments, getTypeFromTypeNode);
  13704. var id = getTypeListId(typeArguments);
  13705. return links.instantiations[id] || (links.instantiations[id] = instantiateType(type, createTypeMapper(typeParameters, typeArguments)));
  13706. }
  13707. if (node.typeArguments) {
  13708. error(node, ts.Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
  13709. return unknownType;
  13710. }
  13711. return type;
  13712. }
  13713. function getTypeFromNonGenericTypeReference(node, symbol) {
  13714. if (symbol.flags & 262144 && isTypeParameterReferenceIllegalInConstraint(node, symbol)) {
  13715. return unknownType;
  13716. }
  13717. if (node.typeArguments) {
  13718. error(node, ts.Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
  13719. return unknownType;
  13720. }
  13721. return getDeclaredTypeOfSymbol(symbol);
  13722. }
  13723. function getTypeFromTypeReference(node) {
  13724. var links = getNodeLinks(node);
  13725. if (!links.resolvedType) {
  13726. var typeNameOrExpression = node.kind === 151 ? node.typeName :
  13727. ts.isSupportedExpressionWithTypeArguments(node) ? node.expression :
  13728. undefined;
  13729. var symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, 793056) || unknownSymbol;
  13730. var type = symbol === unknownSymbol ? unknownType :
  13731. symbol.flags & (32 | 64) ? getTypeFromClassOrInterfaceReference(node, symbol) :
  13732. symbol.flags & 524288 ? getTypeFromTypeAliasReference(node, symbol) :
  13733. getTypeFromNonGenericTypeReference(node, symbol);
  13734. links.resolvedSymbol = symbol;
  13735. links.resolvedType = type;
  13736. }
  13737. return links.resolvedType;
  13738. }
  13739. function getTypeFromTypeQueryNode(node) {
  13740. var links = getNodeLinks(node);
  13741. if (!links.resolvedType) {
  13742. links.resolvedType = getWidenedType(checkExpression(node.exprName));
  13743. }
  13744. return links.resolvedType;
  13745. }
  13746. function getTypeOfGlobalSymbol(symbol, arity) {
  13747. function getTypeDeclaration(symbol) {
  13748. var declarations = symbol.declarations;
  13749. for (var _i = 0; _i < declarations.length; _i++) {
  13750. var declaration = declarations[_i];
  13751. switch (declaration.kind) {
  13752. case 214:
  13753. case 215:
  13754. case 217:
  13755. return declaration;
  13756. }
  13757. }
  13758. }
  13759. if (!symbol) {
  13760. return arity ? emptyGenericType : emptyObjectType;
  13761. }
  13762. var type = getDeclaredTypeOfSymbol(symbol);
  13763. if (!(type.flags & 80896)) {
  13764. error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
  13765. return arity ? emptyGenericType : emptyObjectType;
  13766. }
  13767. if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) {
  13768. error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
  13769. return arity ? emptyGenericType : emptyObjectType;
  13770. }
  13771. return type;
  13772. }
  13773. function getGlobalValueSymbol(name) {
  13774. return getGlobalSymbol(name, 107455, ts.Diagnostics.Cannot_find_global_value_0);
  13775. }
  13776. function getGlobalTypeSymbol(name) {
  13777. return getGlobalSymbol(name, 793056, ts.Diagnostics.Cannot_find_global_type_0);
  13778. }
  13779. function getGlobalSymbol(name, meaning, diagnostic) {
  13780. return resolveName(undefined, name, meaning, diagnostic, name);
  13781. }
  13782. function getGlobalType(name, arity) {
  13783. if (arity === void 0) { arity = 0; }
  13784. return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity);
  13785. }
  13786. function tryGetGlobalType(name, arity) {
  13787. if (arity === void 0) { arity = 0; }
  13788. return getTypeOfGlobalSymbol(getGlobalSymbol(name, 793056, undefined), arity);
  13789. }
  13790. function getExportedTypeFromNamespace(namespace, name) {
  13791. var namespaceSymbol = getGlobalSymbol(namespace, 1536, undefined);
  13792. var typeSymbol = namespaceSymbol && getSymbol(namespaceSymbol.exports, name, 793056);
  13793. return typeSymbol && getDeclaredTypeOfSymbol(typeSymbol);
  13794. }
  13795. function getGlobalESSymbolConstructorSymbol() {
  13796. return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"));
  13797. }
  13798. function createTypedPropertyDescriptorType(propertyType) {
  13799. var globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType();
  13800. return globalTypedPropertyDescriptorType !== emptyGenericType
  13801. ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType])
  13802. : emptyObjectType;
  13803. }
  13804. function createTypeFromGenericGlobalType(genericGlobalType, typeArguments) {
  13805. return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, typeArguments) : emptyObjectType;
  13806. }
  13807. function createIterableType(elementType) {
  13808. return createTypeFromGenericGlobalType(globalIterableType, [elementType]);
  13809. }
  13810. function createIterableIteratorType(elementType) {
  13811. return createTypeFromGenericGlobalType(globalIterableIteratorType, [elementType]);
  13812. }
  13813. function createArrayType(elementType) {
  13814. return createTypeFromGenericGlobalType(globalArrayType, [elementType]);
  13815. }
  13816. function getTypeFromArrayTypeNode(node) {
  13817. var links = getNodeLinks(node);
  13818. if (!links.resolvedType) {
  13819. links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType));
  13820. }
  13821. return links.resolvedType;
  13822. }
  13823. function createTupleType(elementTypes) {
  13824. var id = getTypeListId(elementTypes);
  13825. return tupleTypes[id] || (tupleTypes[id] = createNewTupleType(elementTypes));
  13826. }
  13827. function createNewTupleType(elementTypes) {
  13828. var type = createObjectType(8192 | getPropagatingFlagsOfTypes(elementTypes));
  13829. type.elementTypes = elementTypes;
  13830. return type;
  13831. }
  13832. function getTypeFromTupleTypeNode(node) {
  13833. var links = getNodeLinks(node);
  13834. if (!links.resolvedType) {
  13835. links.resolvedType = createTupleType(ts.map(node.elementTypes, getTypeFromTypeNode));
  13836. }
  13837. return links.resolvedType;
  13838. }
  13839. function addTypeToSet(typeSet, type, typeSetKind) {
  13840. if (type.flags & typeSetKind) {
  13841. addTypesToSet(typeSet, type.types, typeSetKind);
  13842. }
  13843. else if (!ts.contains(typeSet, type)) {
  13844. typeSet.push(type);
  13845. }
  13846. }
  13847. function addTypesToSet(typeSet, types, typeSetKind) {
  13848. for (var _i = 0; _i < types.length; _i++) {
  13849. var type = types[_i];
  13850. addTypeToSet(typeSet, type, typeSetKind);
  13851. }
  13852. }
  13853. function isSubtypeOfAny(candidate, types) {
  13854. for (var i = 0, len = types.length; i < len; i++) {
  13855. if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) {
  13856. return true;
  13857. }
  13858. }
  13859. return false;
  13860. }
  13861. function removeSubtypes(types) {
  13862. var i = types.length;
  13863. while (i > 0) {
  13864. i--;
  13865. if (isSubtypeOfAny(types[i], types)) {
  13866. types.splice(i, 1);
  13867. }
  13868. }
  13869. }
  13870. function containsTypeAny(types) {
  13871. for (var _i = 0; _i < types.length; _i++) {
  13872. var type = types[_i];
  13873. if (isTypeAny(type)) {
  13874. return true;
  13875. }
  13876. }
  13877. return false;
  13878. }
  13879. function removeAllButLast(types, typeToRemove) {
  13880. var i = types.length;
  13881. while (i > 0 && types.length > 1) {
  13882. i--;
  13883. if (types[i] === typeToRemove) {
  13884. types.splice(i, 1);
  13885. }
  13886. }
  13887. }
  13888. function getUnionType(types, noSubtypeReduction) {
  13889. if (types.length === 0) {
  13890. return emptyObjectType;
  13891. }
  13892. var typeSet = [];
  13893. addTypesToSet(typeSet, types, 16384);
  13894. if (containsTypeAny(typeSet)) {
  13895. return anyType;
  13896. }
  13897. if (noSubtypeReduction) {
  13898. removeAllButLast(typeSet, undefinedType);
  13899. removeAllButLast(typeSet, nullType);
  13900. }
  13901. else {
  13902. removeSubtypes(typeSet);
  13903. }
  13904. if (typeSet.length === 1) {
  13905. return typeSet[0];
  13906. }
  13907. var id = getTypeListId(typeSet);
  13908. var type = unionTypes[id];
  13909. if (!type) {
  13910. type = unionTypes[id] = createObjectType(16384 | getPropagatingFlagsOfTypes(typeSet));
  13911. type.types = typeSet;
  13912. }
  13913. return type;
  13914. }
  13915. function getTypeFromUnionTypeNode(node) {
  13916. var links = getNodeLinks(node);
  13917. if (!links.resolvedType) {
  13918. links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), true);
  13919. }
  13920. return links.resolvedType;
  13921. }
  13922. function getIntersectionType(types) {
  13923. if (types.length === 0) {
  13924. return emptyObjectType;
  13925. }
  13926. var typeSet = [];
  13927. addTypesToSet(typeSet, types, 32768);
  13928. if (containsTypeAny(typeSet)) {
  13929. return anyType;
  13930. }
  13931. if (typeSet.length === 1) {
  13932. return typeSet[0];
  13933. }
  13934. var id = getTypeListId(typeSet);
  13935. var type = intersectionTypes[id];
  13936. if (!type) {
  13937. type = intersectionTypes[id] = createObjectType(32768 | getPropagatingFlagsOfTypes(typeSet));
  13938. type.types = typeSet;
  13939. }
  13940. return type;
  13941. }
  13942. function getTypeFromIntersectionTypeNode(node) {
  13943. var links = getNodeLinks(node);
  13944. if (!links.resolvedType) {
  13945. links.resolvedType = getIntersectionType(ts.map(node.types, getTypeFromTypeNode));
  13946. }
  13947. return links.resolvedType;
  13948. }
  13949. function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node) {
  13950. var links = getNodeLinks(node);
  13951. if (!links.resolvedType) {
  13952. links.resolvedType = createObjectType(65536, node.symbol);
  13953. }
  13954. return links.resolvedType;
  13955. }
  13956. function getStringLiteralType(node) {
  13957. if (ts.hasProperty(stringLiteralTypes, node.text)) {
  13958. return stringLiteralTypes[node.text];
  13959. }
  13960. var type = stringLiteralTypes[node.text] = createType(256);
  13961. type.text = ts.getTextOfNode(node);
  13962. return type;
  13963. }
  13964. function getTypeFromStringLiteral(node) {
  13965. var links = getNodeLinks(node);
  13966. if (!links.resolvedType) {
  13967. links.resolvedType = getStringLiteralType(node);
  13968. }
  13969. return links.resolvedType;
  13970. }
  13971. function getThisType(node) {
  13972. var container = ts.getThisContainer(node, false);
  13973. var parent = container && container.parent;
  13974. if (parent && (ts.isClassLike(parent) || parent.kind === 215)) {
  13975. if (!(container.flags & 128) &&
  13976. (container.kind !== 144 || ts.isNodeDescendentOf(node, container.body))) {
  13977. return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType;
  13978. }
  13979. }
  13980. error(node, ts.Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface);
  13981. return unknownType;
  13982. }
  13983. function getTypeFromThisTypeNode(node) {
  13984. var links = getNodeLinks(node);
  13985. if (!links.resolvedType) {
  13986. links.resolvedType = getThisType(node);
  13987. }
  13988. return links.resolvedType;
  13989. }
  13990. function getTypeFromTypeNode(node) {
  13991. switch (node.kind) {
  13992. case 117:
  13993. return anyType;
  13994. case 130:
  13995. return stringType;
  13996. case 128:
  13997. return numberType;
  13998. case 120:
  13999. return booleanType;
  14000. case 131:
  14001. return esSymbolType;
  14002. case 103:
  14003. return voidType;
  14004. case 97:
  14005. return getTypeFromThisTypeNode(node);
  14006. case 9:
  14007. return getTypeFromStringLiteral(node);
  14008. case 151:
  14009. return getTypeFromTypeReference(node);
  14010. case 150:
  14011. return booleanType;
  14012. case 188:
  14013. return getTypeFromTypeReference(node);
  14014. case 154:
  14015. return getTypeFromTypeQueryNode(node);
  14016. case 156:
  14017. return getTypeFromArrayTypeNode(node);
  14018. case 157:
  14019. return getTypeFromTupleTypeNode(node);
  14020. case 158:
  14021. return getTypeFromUnionTypeNode(node);
  14022. case 159:
  14023. return getTypeFromIntersectionTypeNode(node);
  14024. case 160:
  14025. return getTypeFromTypeNode(node.type);
  14026. case 152:
  14027. case 153:
  14028. case 155:
  14029. return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
  14030. case 69:
  14031. case 135:
  14032. var symbol = getSymbolAtLocation(node);
  14033. return symbol && getDeclaredTypeOfSymbol(symbol);
  14034. default:
  14035. return unknownType;
  14036. }
  14037. }
  14038. function instantiateList(items, mapper, instantiator) {
  14039. if (items && items.length) {
  14040. var result = [];
  14041. for (var _i = 0; _i < items.length; _i++) {
  14042. var v = items[_i];
  14043. result.push(instantiator(v, mapper));
  14044. }
  14045. return result;
  14046. }
  14047. return items;
  14048. }
  14049. function createUnaryTypeMapper(source, target) {
  14050. return function (t) { return t === source ? target : t; };
  14051. }
  14052. function createBinaryTypeMapper(source1, target1, source2, target2) {
  14053. return function (t) { return t === source1 ? target1 : t === source2 ? target2 : t; };
  14054. }
  14055. function createTypeMapper(sources, targets) {
  14056. switch (sources.length) {
  14057. case 1: return createUnaryTypeMapper(sources[0], targets[0]);
  14058. case 2: return createBinaryTypeMapper(sources[0], targets[0], sources[1], targets[1]);
  14059. }
  14060. return function (t) {
  14061. for (var i = 0; i < sources.length; i++) {
  14062. if (t === sources[i]) {
  14063. return targets[i];
  14064. }
  14065. }
  14066. return t;
  14067. };
  14068. }
  14069. function createUnaryTypeEraser(source) {
  14070. return function (t) { return t === source ? anyType : t; };
  14071. }
  14072. function createBinaryTypeEraser(source1, source2) {
  14073. return function (t) { return t === source1 || t === source2 ? anyType : t; };
  14074. }
  14075. function createTypeEraser(sources) {
  14076. switch (sources.length) {
  14077. case 1: return createUnaryTypeEraser(sources[0]);
  14078. case 2: return createBinaryTypeEraser(sources[0], sources[1]);
  14079. }
  14080. return function (t) {
  14081. for (var _i = 0; _i < sources.length; _i++) {
  14082. var source = sources[_i];
  14083. if (t === source) {
  14084. return anyType;
  14085. }
  14086. }
  14087. return t;
  14088. };
  14089. }
  14090. function createInferenceMapper(context) {
  14091. var mapper = function (t) {
  14092. for (var i = 0; i < context.typeParameters.length; i++) {
  14093. if (t === context.typeParameters[i]) {
  14094. context.inferences[i].isFixed = true;
  14095. return getInferredType(context, i);
  14096. }
  14097. }
  14098. return t;
  14099. };
  14100. mapper.context = context;
  14101. return mapper;
  14102. }
  14103. function identityMapper(type) {
  14104. return type;
  14105. }
  14106. function combineTypeMappers(mapper1, mapper2) {
  14107. return function (t) { return instantiateType(mapper1(t), mapper2); };
  14108. }
  14109. function instantiateTypeParameter(typeParameter, mapper) {
  14110. var result = createType(512);
  14111. result.symbol = typeParameter.symbol;
  14112. if (typeParameter.constraint) {
  14113. result.constraint = instantiateType(typeParameter.constraint, mapper);
  14114. }
  14115. else {
  14116. result.target = typeParameter;
  14117. result.mapper = mapper;
  14118. }
  14119. return result;
  14120. }
  14121. function instantiateSignature(signature, mapper, eraseTypeParameters) {
  14122. var freshTypeParameters;
  14123. var freshTypePredicate;
  14124. if (signature.typeParameters && !eraseTypeParameters) {
  14125. freshTypeParameters = instantiateList(signature.typeParameters, mapper, instantiateTypeParameter);
  14126. mapper = combineTypeMappers(createTypeMapper(signature.typeParameters, freshTypeParameters), mapper);
  14127. }
  14128. if (signature.typePredicate) {
  14129. freshTypePredicate = {
  14130. parameterName: signature.typePredicate.parameterName,
  14131. parameterIndex: signature.typePredicate.parameterIndex,
  14132. type: instantiateType(signature.typePredicate.type, mapper)
  14133. };
  14134. }
  14135. var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals);
  14136. result.target = signature;
  14137. result.mapper = mapper;
  14138. return result;
  14139. }
  14140. function instantiateSymbol(symbol, mapper) {
  14141. if (symbol.flags & 16777216) {
  14142. var links = getSymbolLinks(symbol);
  14143. symbol = links.target;
  14144. mapper = combineTypeMappers(links.mapper, mapper);
  14145. }
  14146. var result = createSymbol(16777216 | 67108864 | symbol.flags, symbol.name);
  14147. result.declarations = symbol.declarations;
  14148. result.parent = symbol.parent;
  14149. result.target = symbol;
  14150. result.mapper = mapper;
  14151. if (symbol.valueDeclaration) {
  14152. result.valueDeclaration = symbol.valueDeclaration;
  14153. }
  14154. return result;
  14155. }
  14156. function instantiateAnonymousType(type, mapper) {
  14157. if (mapper.instantiations) {
  14158. var cachedType = mapper.instantiations[type.id];
  14159. if (cachedType) {
  14160. return cachedType;
  14161. }
  14162. }
  14163. else {
  14164. mapper.instantiations = [];
  14165. }
  14166. var result = createObjectType(65536 | 131072, type.symbol);
  14167. result.target = type;
  14168. result.mapper = mapper;
  14169. mapper.instantiations[type.id] = result;
  14170. return result;
  14171. }
  14172. function instantiateType(type, mapper) {
  14173. if (type && mapper !== identityMapper) {
  14174. if (type.flags & 512) {
  14175. return mapper(type);
  14176. }
  14177. if (type.flags & 65536) {
  14178. return type.symbol && type.symbol.flags & (16 | 8192 | 32 | 2048 | 4096) ?
  14179. instantiateAnonymousType(type, mapper) : type;
  14180. }
  14181. if (type.flags & 4096) {
  14182. return createTypeReference(type.target, instantiateList(type.typeArguments, mapper, instantiateType));
  14183. }
  14184. if (type.flags & 8192) {
  14185. return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType));
  14186. }
  14187. if (type.flags & 16384) {
  14188. return getUnionType(instantiateList(type.types, mapper, instantiateType), true);
  14189. }
  14190. if (type.flags & 32768) {
  14191. return getIntersectionType(instantiateList(type.types, mapper, instantiateType));
  14192. }
  14193. }
  14194. return type;
  14195. }
  14196. function isContextSensitive(node) {
  14197. ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node));
  14198. switch (node.kind) {
  14199. case 173:
  14200. case 174:
  14201. return isContextSensitiveFunctionLikeDeclaration(node);
  14202. case 165:
  14203. return ts.forEach(node.properties, isContextSensitive);
  14204. case 164:
  14205. return ts.forEach(node.elements, isContextSensitive);
  14206. case 182:
  14207. return isContextSensitive(node.whenTrue) ||
  14208. isContextSensitive(node.whenFalse);
  14209. case 181:
  14210. return node.operatorToken.kind === 52 &&
  14211. (isContextSensitive(node.left) || isContextSensitive(node.right));
  14212. case 245:
  14213. return isContextSensitive(node.initializer);
  14214. case 143:
  14215. case 142:
  14216. return isContextSensitiveFunctionLikeDeclaration(node);
  14217. case 172:
  14218. return isContextSensitive(node.expression);
  14219. }
  14220. return false;
  14221. }
  14222. function isContextSensitiveFunctionLikeDeclaration(node) {
  14223. return !node.typeParameters && node.parameters.length && !ts.forEach(node.parameters, function (p) { return p.type; });
  14224. }
  14225. function getTypeWithoutSignatures(type) {
  14226. if (type.flags & 80896) {
  14227. var resolved = resolveStructuredTypeMembers(type);
  14228. if (resolved.constructSignatures.length) {
  14229. var result = createObjectType(65536, type.symbol);
  14230. result.members = resolved.members;
  14231. result.properties = resolved.properties;
  14232. result.callSignatures = emptyArray;
  14233. result.constructSignatures = emptyArray;
  14234. type = result;
  14235. }
  14236. }
  14237. return type;
  14238. }
  14239. function isTypeIdenticalTo(source, target) {
  14240. return checkTypeRelatedTo(source, target, identityRelation, undefined);
  14241. }
  14242. function compareTypes(source, target) {
  14243. return checkTypeRelatedTo(source, target, identityRelation, undefined) ? -1 : 0;
  14244. }
  14245. function isTypeSubtypeOf(source, target) {
  14246. return checkTypeSubtypeOf(source, target, undefined);
  14247. }
  14248. function isTypeAssignableTo(source, target) {
  14249. return checkTypeAssignableTo(source, target, undefined);
  14250. }
  14251. function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) {
  14252. return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain);
  14253. }
  14254. function checkTypeAssignableTo(source, target, errorNode, headMessage, containingMessageChain) {
  14255. return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain);
  14256. }
  14257. function isSignatureAssignableTo(source, target) {
  14258. var sourceType = getOrCreateTypeFromSignature(source);
  14259. var targetType = getOrCreateTypeFromSignature(target);
  14260. return checkTypeRelatedTo(sourceType, targetType, assignableRelation, undefined);
  14261. }
  14262. function checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain) {
  14263. var errorInfo;
  14264. var sourceStack;
  14265. var targetStack;
  14266. var maybeStack;
  14267. var expandingFlags;
  14268. var depth = 0;
  14269. var overflow = false;
  14270. var elaborateErrors = false;
  14271. ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
  14272. var result = isRelatedTo(source, target, errorNode !== undefined, headMessage);
  14273. if (overflow) {
  14274. error(errorNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
  14275. }
  14276. else if (errorInfo) {
  14277. if (errorInfo.next === undefined) {
  14278. errorInfo = undefined;
  14279. elaborateErrors = true;
  14280. isRelatedTo(source, target, errorNode !== undefined, headMessage);
  14281. }
  14282. if (containingMessageChain) {
  14283. errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
  14284. }
  14285. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
  14286. }
  14287. return result !== 0;
  14288. function reportError(message, arg0, arg1, arg2) {
  14289. errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
  14290. }
  14291. function reportRelationError(message, source, target) {
  14292. var sourceType = typeToString(source);
  14293. var targetType = typeToString(target);
  14294. if (sourceType === targetType) {
  14295. sourceType = typeToString(source, undefined, 128);
  14296. targetType = typeToString(target, undefined, 128);
  14297. }
  14298. reportError(message || ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType);
  14299. }
  14300. function isRelatedTo(source, target, reportErrors, headMessage) {
  14301. var result;
  14302. if (source === target)
  14303. return -1;
  14304. if (relation === identityRelation) {
  14305. return isIdenticalTo(source, target);
  14306. }
  14307. if (isTypeAny(target))
  14308. return -1;
  14309. if (source === undefinedType)
  14310. return -1;
  14311. if (source === nullType && target !== undefinedType)
  14312. return -1;
  14313. if (source.flags & 128 && target === numberType)
  14314. return -1;
  14315. if (source.flags & 256 && target === stringType)
  14316. return -1;
  14317. if (relation === assignableRelation) {
  14318. if (isTypeAny(source))
  14319. return -1;
  14320. if (source === numberType && target.flags & 128)
  14321. return -1;
  14322. }
  14323. if (source.flags & 1048576) {
  14324. if (hasExcessProperties(source, target, reportErrors)) {
  14325. if (reportErrors) {
  14326. reportRelationError(headMessage, source, target);
  14327. }
  14328. return 0;
  14329. }
  14330. if (target.flags & 49152) {
  14331. source = getRegularTypeOfObjectLiteral(source);
  14332. }
  14333. }
  14334. var saveErrorInfo = errorInfo;
  14335. if (source.flags & 16384) {
  14336. if (result = eachTypeRelatedToType(source, target, reportErrors)) {
  14337. return result;
  14338. }
  14339. }
  14340. else if (target.flags & 32768) {
  14341. if (result = typeRelatedToEachType(source, target, reportErrors)) {
  14342. return result;
  14343. }
  14344. }
  14345. else {
  14346. if (source.flags & 32768) {
  14347. if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & 16384))) {
  14348. return result;
  14349. }
  14350. }
  14351. if (target.flags & 16384) {
  14352. if (result = typeRelatedToSomeType(source, target, reportErrors)) {
  14353. return result;
  14354. }
  14355. }
  14356. }
  14357. if (source.flags & 512) {
  14358. var constraint = getConstraintOfTypeParameter(source);
  14359. if (!constraint || constraint.flags & 1) {
  14360. constraint = emptyObjectType;
  14361. }
  14362. var reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
  14363. if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
  14364. errorInfo = saveErrorInfo;
  14365. return result;
  14366. }
  14367. }
  14368. else {
  14369. if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  14370. if (result = typeArgumentsRelatedTo(source, target, reportErrors)) {
  14371. return result;
  14372. }
  14373. }
  14374. var apparentType = getApparentType(source);
  14375. if (apparentType.flags & (80896 | 32768) && target.flags & 80896) {
  14376. var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
  14377. if (result = objectTypeRelatedTo(apparentType, target, reportStructuralErrors)) {
  14378. errorInfo = saveErrorInfo;
  14379. return result;
  14380. }
  14381. }
  14382. }
  14383. if (reportErrors) {
  14384. reportRelationError(headMessage, source, target);
  14385. }
  14386. return 0;
  14387. }
  14388. function isIdenticalTo(source, target) {
  14389. var result;
  14390. if (source.flags & 80896 && target.flags & 80896) {
  14391. if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  14392. if (result = typeArgumentsRelatedTo(source, target, false)) {
  14393. return result;
  14394. }
  14395. }
  14396. return objectTypeRelatedTo(source, target, false);
  14397. }
  14398. if (source.flags & 512 && target.flags & 512) {
  14399. return typeParameterIdenticalTo(source, target);
  14400. }
  14401. if (source.flags & 16384 && target.flags & 16384 ||
  14402. source.flags & 32768 && target.flags & 32768) {
  14403. if (result = eachTypeRelatedToSomeType(source, target)) {
  14404. if (result &= eachTypeRelatedToSomeType(target, source)) {
  14405. return result;
  14406. }
  14407. }
  14408. }
  14409. return 0;
  14410. }
  14411. function isKnownProperty(type, name) {
  14412. if (type.flags & 80896) {
  14413. var resolved = resolveStructuredTypeMembers(type);
  14414. if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) ||
  14415. resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) {
  14416. return true;
  14417. }
  14418. return false;
  14419. }
  14420. if (type.flags & 49152) {
  14421. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  14422. var t = _a[_i];
  14423. if (isKnownProperty(t, name)) {
  14424. return true;
  14425. }
  14426. }
  14427. return false;
  14428. }
  14429. return true;
  14430. }
  14431. function hasExcessProperties(source, target, reportErrors) {
  14432. for (var _i = 0, _a = getPropertiesOfObjectType(source); _i < _a.length; _i++) {
  14433. var prop = _a[_i];
  14434. if (!isKnownProperty(target, prop.name)) {
  14435. if (reportErrors) {
  14436. errorNode = prop.valueDeclaration;
  14437. reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
  14438. }
  14439. return true;
  14440. }
  14441. }
  14442. }
  14443. function eachTypeRelatedToSomeType(source, target) {
  14444. var result = -1;
  14445. var sourceTypes = source.types;
  14446. for (var _i = 0; _i < sourceTypes.length; _i++) {
  14447. var sourceType = sourceTypes[_i];
  14448. var related = typeRelatedToSomeType(sourceType, target, false);
  14449. if (!related) {
  14450. return 0;
  14451. }
  14452. result &= related;
  14453. }
  14454. return result;
  14455. }
  14456. function typeRelatedToSomeType(source, target, reportErrors) {
  14457. var targetTypes = target.types;
  14458. for (var i = 0, len = targetTypes.length; i < len; i++) {
  14459. var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1);
  14460. if (related) {
  14461. return related;
  14462. }
  14463. }
  14464. return 0;
  14465. }
  14466. function typeRelatedToEachType(source, target, reportErrors) {
  14467. var result = -1;
  14468. var targetTypes = target.types;
  14469. for (var _i = 0; _i < targetTypes.length; _i++) {
  14470. var targetType = targetTypes[_i];
  14471. var related = isRelatedTo(source, targetType, reportErrors);
  14472. if (!related) {
  14473. return 0;
  14474. }
  14475. result &= related;
  14476. }
  14477. return result;
  14478. }
  14479. function someTypeRelatedToType(source, target, reportErrors) {
  14480. var sourceTypes = source.types;
  14481. for (var i = 0, len = sourceTypes.length; i < len; i++) {
  14482. var related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1);
  14483. if (related) {
  14484. return related;
  14485. }
  14486. }
  14487. return 0;
  14488. }
  14489. function eachTypeRelatedToType(source, target, reportErrors) {
  14490. var result = -1;
  14491. var sourceTypes = source.types;
  14492. for (var _i = 0; _i < sourceTypes.length; _i++) {
  14493. var sourceType = sourceTypes[_i];
  14494. var related = isRelatedTo(sourceType, target, reportErrors);
  14495. if (!related) {
  14496. return 0;
  14497. }
  14498. result &= related;
  14499. }
  14500. return result;
  14501. }
  14502. function typeArgumentsRelatedTo(source, target, reportErrors) {
  14503. var sources = source.typeArguments || emptyArray;
  14504. var targets = target.typeArguments || emptyArray;
  14505. if (sources.length !== targets.length && relation === identityRelation) {
  14506. return 0;
  14507. }
  14508. var result = -1;
  14509. for (var i = 0; i < targets.length; i++) {
  14510. var related = isRelatedTo(sources[i], targets[i], reportErrors);
  14511. if (!related) {
  14512. return 0;
  14513. }
  14514. result &= related;
  14515. }
  14516. return result;
  14517. }
  14518. function typeParameterIdenticalTo(source, target) {
  14519. if (source.symbol.name !== target.symbol.name) {
  14520. return 0;
  14521. }
  14522. if (source.constraint === target.constraint) {
  14523. return -1;
  14524. }
  14525. if (source.constraint === noConstraintType || target.constraint === noConstraintType) {
  14526. return 0;
  14527. }
  14528. return isIdenticalTo(source.constraint, target.constraint);
  14529. }
  14530. function objectTypeRelatedTo(source, target, reportErrors) {
  14531. if (overflow) {
  14532. return 0;
  14533. }
  14534. var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
  14535. var related = relation[id];
  14536. if (related !== undefined) {
  14537. if (!elaborateErrors || (related === 3)) {
  14538. return related === 1 ? -1 : 0;
  14539. }
  14540. }
  14541. if (depth > 0) {
  14542. for (var i = 0; i < depth; i++) {
  14543. if (maybeStack[i][id]) {
  14544. return 1;
  14545. }
  14546. }
  14547. if (depth === 100) {
  14548. overflow = true;
  14549. return 0;
  14550. }
  14551. }
  14552. else {
  14553. sourceStack = [];
  14554. targetStack = [];
  14555. maybeStack = [];
  14556. expandingFlags = 0;
  14557. }
  14558. sourceStack[depth] = source;
  14559. targetStack[depth] = target;
  14560. maybeStack[depth] = {};
  14561. maybeStack[depth][id] = 1;
  14562. depth++;
  14563. var saveExpandingFlags = expandingFlags;
  14564. if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth))
  14565. expandingFlags |= 1;
  14566. if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth))
  14567. expandingFlags |= 2;
  14568. var result;
  14569. if (expandingFlags === 3) {
  14570. result = 1;
  14571. }
  14572. else {
  14573. result = propertiesRelatedTo(source, target, reportErrors);
  14574. if (result) {
  14575. result &= signaturesRelatedTo(source, target, 0, reportErrors);
  14576. if (result) {
  14577. result &= signaturesRelatedTo(source, target, 1, reportErrors);
  14578. if (result) {
  14579. result &= stringIndexTypesRelatedTo(source, target, reportErrors);
  14580. if (result) {
  14581. result &= numberIndexTypesRelatedTo(source, target, reportErrors);
  14582. }
  14583. }
  14584. }
  14585. }
  14586. }
  14587. expandingFlags = saveExpandingFlags;
  14588. depth--;
  14589. if (result) {
  14590. var maybeCache = maybeStack[depth];
  14591. var destinationCache = (result === -1 || depth === 0) ? relation : maybeStack[depth - 1];
  14592. ts.copyMap(maybeCache, destinationCache);
  14593. }
  14594. else {
  14595. relation[id] = reportErrors ? 3 : 2;
  14596. }
  14597. return result;
  14598. }
  14599. function propertiesRelatedTo(source, target, reportErrors) {
  14600. if (relation === identityRelation) {
  14601. return propertiesIdenticalTo(source, target);
  14602. }
  14603. var result = -1;
  14604. var properties = getPropertiesOfObjectType(target);
  14605. var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 524288);
  14606. for (var _i = 0; _i < properties.length; _i++) {
  14607. var targetProp = properties[_i];
  14608. var sourceProp = getPropertyOfType(source, targetProp.name);
  14609. if (sourceProp !== targetProp) {
  14610. if (!sourceProp) {
  14611. if (!(targetProp.flags & 536870912) || requireOptionalProperties) {
  14612. if (reportErrors) {
  14613. reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source));
  14614. }
  14615. return 0;
  14616. }
  14617. }
  14618. else if (!(targetProp.flags & 134217728)) {
  14619. var sourcePropFlags = getDeclarationFlagsFromSymbol(sourceProp);
  14620. var targetPropFlags = getDeclarationFlagsFromSymbol(targetProp);
  14621. if (sourcePropFlags & 32 || targetPropFlags & 32) {
  14622. if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
  14623. if (reportErrors) {
  14624. if (sourcePropFlags & 32 && targetPropFlags & 32) {
  14625. reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp));
  14626. }
  14627. else {
  14628. reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourcePropFlags & 32 ? source : target), typeToString(sourcePropFlags & 32 ? target : source));
  14629. }
  14630. }
  14631. return 0;
  14632. }
  14633. }
  14634. else if (targetPropFlags & 64) {
  14635. var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32;
  14636. var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined;
  14637. var targetClass = getDeclaredTypeOfSymbol(targetProp.parent);
  14638. if (!sourceClass || !hasBaseType(sourceClass, targetClass)) {
  14639. if (reportErrors) {
  14640. reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass));
  14641. }
  14642. return 0;
  14643. }
  14644. }
  14645. else if (sourcePropFlags & 64) {
  14646. if (reportErrors) {
  14647. reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target));
  14648. }
  14649. return 0;
  14650. }
  14651. var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
  14652. if (!related) {
  14653. if (reportErrors) {
  14654. reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));
  14655. }
  14656. return 0;
  14657. }
  14658. result &= related;
  14659. if (sourceProp.flags & 536870912 && !(targetProp.flags & 536870912)) {
  14660. if (reportErrors) {
  14661. reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target));
  14662. }
  14663. return 0;
  14664. }
  14665. }
  14666. }
  14667. }
  14668. return result;
  14669. }
  14670. function propertiesIdenticalTo(source, target) {
  14671. if (!(source.flags & 80896 && target.flags & 80896)) {
  14672. return 0;
  14673. }
  14674. var sourceProperties = getPropertiesOfObjectType(source);
  14675. var targetProperties = getPropertiesOfObjectType(target);
  14676. if (sourceProperties.length !== targetProperties.length) {
  14677. return 0;
  14678. }
  14679. var result = -1;
  14680. for (var _i = 0; _i < sourceProperties.length; _i++) {
  14681. var sourceProp = sourceProperties[_i];
  14682. var targetProp = getPropertyOfObjectType(target, sourceProp.name);
  14683. if (!targetProp) {
  14684. return 0;
  14685. }
  14686. var related = compareProperties(sourceProp, targetProp, isRelatedTo);
  14687. if (!related) {
  14688. return 0;
  14689. }
  14690. result &= related;
  14691. }
  14692. return result;
  14693. }
  14694. function signaturesRelatedTo(source, target, kind, reportErrors) {
  14695. if (relation === identityRelation) {
  14696. return signaturesIdenticalTo(source, target, kind);
  14697. }
  14698. if (target === anyFunctionType || source === anyFunctionType) {
  14699. return -1;
  14700. }
  14701. var sourceSignatures = getSignaturesOfType(source, kind);
  14702. var targetSignatures = getSignaturesOfType(target, kind);
  14703. var result = -1;
  14704. var saveErrorInfo = errorInfo;
  14705. if (kind === 1) {
  14706. var sourceSig = sourceSignatures[0];
  14707. var targetSig = targetSignatures[0];
  14708. result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig);
  14709. if (result !== -1) {
  14710. return result;
  14711. }
  14712. }
  14713. outer: for (var _i = 0; _i < targetSignatures.length; _i++) {
  14714. var t = targetSignatures[_i];
  14715. if (!t.hasStringLiterals || target.flags & 262144) {
  14716. var localErrors = reportErrors;
  14717. var checkedAbstractAssignability = false;
  14718. for (var _a = 0; _a < sourceSignatures.length; _a++) {
  14719. var s = sourceSignatures[_a];
  14720. if (!s.hasStringLiterals || source.flags & 262144) {
  14721. var related = signatureRelatedTo(s, t, localErrors);
  14722. if (related) {
  14723. result &= related;
  14724. errorInfo = saveErrorInfo;
  14725. continue outer;
  14726. }
  14727. localErrors = false;
  14728. }
  14729. }
  14730. return 0;
  14731. }
  14732. }
  14733. return result;
  14734. function abstractSignatureRelatedTo(source, sourceSig, target, targetSig) {
  14735. if (sourceSig && targetSig) {
  14736. var sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol);
  14737. var targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol);
  14738. if (!sourceDecl) {
  14739. return -1;
  14740. }
  14741. var sourceErasedSignature = getErasedSignature(sourceSig);
  14742. var targetErasedSignature = getErasedSignature(targetSig);
  14743. var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
  14744. var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
  14745. var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol);
  14746. var targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol);
  14747. var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 256;
  14748. var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 256;
  14749. if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) {
  14750. if (reportErrors) {
  14751. reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type);
  14752. }
  14753. return 0;
  14754. }
  14755. }
  14756. return -1;
  14757. }
  14758. }
  14759. function signatureRelatedTo(source, target, reportErrors) {
  14760. if (source === target) {
  14761. return -1;
  14762. }
  14763. if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) {
  14764. return 0;
  14765. }
  14766. var sourceMax = source.parameters.length;
  14767. var targetMax = target.parameters.length;
  14768. var checkCount;
  14769. if (source.hasRestParameter && target.hasRestParameter) {
  14770. checkCount = sourceMax > targetMax ? sourceMax : targetMax;
  14771. sourceMax--;
  14772. targetMax--;
  14773. }
  14774. else if (source.hasRestParameter) {
  14775. sourceMax--;
  14776. checkCount = targetMax;
  14777. }
  14778. else if (target.hasRestParameter) {
  14779. targetMax--;
  14780. checkCount = sourceMax;
  14781. }
  14782. else {
  14783. checkCount = sourceMax < targetMax ? sourceMax : targetMax;
  14784. }
  14785. source = getErasedSignature(source);
  14786. target = getErasedSignature(target);
  14787. var result = -1;
  14788. for (var i = 0; i < checkCount; i++) {
  14789. var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
  14790. var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
  14791. var saveErrorInfo = errorInfo;
  14792. var related = isRelatedTo(s, t, reportErrors);
  14793. if (!related) {
  14794. related = isRelatedTo(t, s, false);
  14795. if (!related) {
  14796. if (reportErrors) {
  14797. reportError(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name);
  14798. }
  14799. return 0;
  14800. }
  14801. errorInfo = saveErrorInfo;
  14802. }
  14803. result &= related;
  14804. }
  14805. if (source.typePredicate && target.typePredicate) {
  14806. var hasDifferentParameterIndex = source.typePredicate.parameterIndex !== target.typePredicate.parameterIndex;
  14807. var hasDifferentTypes;
  14808. if (hasDifferentParameterIndex ||
  14809. (hasDifferentTypes = !isTypeIdenticalTo(source.typePredicate.type, target.typePredicate.type))) {
  14810. if (reportErrors) {
  14811. var sourceParamText = source.typePredicate.parameterName;
  14812. var targetParamText = target.typePredicate.parameterName;
  14813. var sourceTypeText = typeToString(source.typePredicate.type);
  14814. var targetTypeText = typeToString(target.typePredicate.type);
  14815. if (hasDifferentParameterIndex) {
  14816. reportError(ts.Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, sourceParamText, targetParamText);
  14817. }
  14818. else if (hasDifferentTypes) {
  14819. reportError(ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceTypeText, targetTypeText);
  14820. }
  14821. reportError(ts.Diagnostics.Type_predicate_0_is_not_assignable_to_1, sourceParamText + " is " + sourceTypeText, targetParamText + " is " + targetTypeText);
  14822. }
  14823. return 0;
  14824. }
  14825. }
  14826. else if (!source.typePredicate && target.typePredicate) {
  14827. if (reportErrors) {
  14828. reportError(ts.Diagnostics.Signature_0_must_have_a_type_predicate, signatureToString(source));
  14829. }
  14830. return 0;
  14831. }
  14832. var targetReturnType = getReturnTypeOfSignature(target);
  14833. if (targetReturnType === voidType)
  14834. return result;
  14835. var sourceReturnType = getReturnTypeOfSignature(source);
  14836. return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors);
  14837. }
  14838. function signaturesIdenticalTo(source, target, kind) {
  14839. var sourceSignatures = getSignaturesOfType(source, kind);
  14840. var targetSignatures = getSignaturesOfType(target, kind);
  14841. if (sourceSignatures.length !== targetSignatures.length) {
  14842. return 0;
  14843. }
  14844. var result = -1;
  14845. for (var i = 0, len = sourceSignatures.length; i < len; ++i) {
  14846. var related = compareSignatures(sourceSignatures[i], targetSignatures[i], false, false, isRelatedTo);
  14847. if (!related) {
  14848. return 0;
  14849. }
  14850. result &= related;
  14851. }
  14852. return result;
  14853. }
  14854. function stringIndexTypesRelatedTo(source, target, reportErrors) {
  14855. if (relation === identityRelation) {
  14856. return indexTypesIdenticalTo(0, source, target);
  14857. }
  14858. var targetType = getIndexTypeOfType(target, 0);
  14859. if (targetType && !(targetType.flags & 1)) {
  14860. var sourceType = getIndexTypeOfType(source, 0);
  14861. if (!sourceType) {
  14862. if (reportErrors) {
  14863. reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
  14864. }
  14865. return 0;
  14866. }
  14867. var related = isRelatedTo(sourceType, targetType, reportErrors);
  14868. if (!related) {
  14869. if (reportErrors) {
  14870. reportError(ts.Diagnostics.Index_signatures_are_incompatible);
  14871. }
  14872. return 0;
  14873. }
  14874. return related;
  14875. }
  14876. return -1;
  14877. }
  14878. function numberIndexTypesRelatedTo(source, target, reportErrors) {
  14879. if (relation === identityRelation) {
  14880. return indexTypesIdenticalTo(1, source, target);
  14881. }
  14882. var targetType = getIndexTypeOfType(target, 1);
  14883. if (targetType && !(targetType.flags & 1)) {
  14884. var sourceStringType = getIndexTypeOfType(source, 0);
  14885. var sourceNumberType = getIndexTypeOfType(source, 1);
  14886. if (!(sourceStringType || sourceNumberType)) {
  14887. if (reportErrors) {
  14888. reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
  14889. }
  14890. return 0;
  14891. }
  14892. var related;
  14893. if (sourceStringType && sourceNumberType) {
  14894. related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
  14895. }
  14896. else {
  14897. related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
  14898. }
  14899. if (!related) {
  14900. if (reportErrors) {
  14901. reportError(ts.Diagnostics.Index_signatures_are_incompatible);
  14902. }
  14903. return 0;
  14904. }
  14905. return related;
  14906. }
  14907. return -1;
  14908. }
  14909. function indexTypesIdenticalTo(indexKind, source, target) {
  14910. var targetType = getIndexTypeOfType(target, indexKind);
  14911. var sourceType = getIndexTypeOfType(source, indexKind);
  14912. if (!sourceType && !targetType) {
  14913. return -1;
  14914. }
  14915. if (sourceType && targetType) {
  14916. return isRelatedTo(sourceType, targetType);
  14917. }
  14918. return 0;
  14919. }
  14920. }
  14921. function isDeeplyNestedGeneric(type, stack, depth) {
  14922. if (type.flags & (4096 | 131072) && depth >= 5) {
  14923. var symbol = type.symbol;
  14924. var count = 0;
  14925. for (var i = 0; i < depth; i++) {
  14926. var t = stack[i];
  14927. if (t.flags & (4096 | 131072) && t.symbol === symbol) {
  14928. count++;
  14929. if (count >= 5)
  14930. return true;
  14931. }
  14932. }
  14933. }
  14934. return false;
  14935. }
  14936. function isPropertyIdenticalTo(sourceProp, targetProp) {
  14937. return compareProperties(sourceProp, targetProp, compareTypes) !== 0;
  14938. }
  14939. function compareProperties(sourceProp, targetProp, compareTypes) {
  14940. if (sourceProp === targetProp) {
  14941. return -1;
  14942. }
  14943. var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (32 | 64);
  14944. var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (32 | 64);
  14945. if (sourcePropAccessibility !== targetPropAccessibility) {
  14946. return 0;
  14947. }
  14948. if (sourcePropAccessibility) {
  14949. if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) {
  14950. return 0;
  14951. }
  14952. }
  14953. else {
  14954. if ((sourceProp.flags & 536870912) !== (targetProp.flags & 536870912)) {
  14955. return 0;
  14956. }
  14957. }
  14958. return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
  14959. }
  14960. function compareSignatures(source, target, partialMatch, ignoreReturnTypes, compareTypes) {
  14961. if (source === target) {
  14962. return -1;
  14963. }
  14964. if (source.parameters.length !== target.parameters.length ||
  14965. source.minArgumentCount !== target.minArgumentCount ||
  14966. source.hasRestParameter !== target.hasRestParameter) {
  14967. if (!partialMatch ||
  14968. source.parameters.length < target.parameters.length && !source.hasRestParameter ||
  14969. source.minArgumentCount > target.minArgumentCount) {
  14970. return 0;
  14971. }
  14972. }
  14973. var result = -1;
  14974. if (source.typeParameters && target.typeParameters) {
  14975. if (source.typeParameters.length !== target.typeParameters.length) {
  14976. return 0;
  14977. }
  14978. for (var i = 0, len = source.typeParameters.length; i < len; ++i) {
  14979. var related = compareTypes(source.typeParameters[i], target.typeParameters[i]);
  14980. if (!related) {
  14981. return 0;
  14982. }
  14983. result &= related;
  14984. }
  14985. }
  14986. else if (source.typeParameters || target.typeParameters) {
  14987. return 0;
  14988. }
  14989. source = getErasedSignature(source);
  14990. target = getErasedSignature(target);
  14991. var targetLen = target.parameters.length;
  14992. for (var i = 0; i < targetLen; i++) {
  14993. var s = isRestParameterIndex(source, i) ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
  14994. var t = isRestParameterIndex(target, i) ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
  14995. var related = compareTypes(s, t);
  14996. if (!related) {
  14997. return 0;
  14998. }
  14999. result &= related;
  15000. }
  15001. if (!ignoreReturnTypes) {
  15002. result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
  15003. }
  15004. return result;
  15005. }
  15006. function isRestParameterIndex(signature, parameterIndex) {
  15007. return signature.hasRestParameter && parameterIndex >= signature.parameters.length - 1;
  15008. }
  15009. function isSupertypeOfEach(candidate, types) {
  15010. for (var _i = 0; _i < types.length; _i++) {
  15011. var type = types[_i];
  15012. if (candidate !== type && !isTypeSubtypeOf(type, candidate))
  15013. return false;
  15014. }
  15015. return true;
  15016. }
  15017. function getCommonSupertype(types) {
  15018. return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; });
  15019. }
  15020. function reportNoCommonSupertypeError(types, errorLocation, errorMessageChainHead) {
  15021. var bestSupertype;
  15022. var bestSupertypeDownfallType;
  15023. var bestSupertypeScore = 0;
  15024. for (var i = 0; i < types.length; i++) {
  15025. var score = 0;
  15026. var downfallType = undefined;
  15027. for (var j = 0; j < types.length; j++) {
  15028. if (isTypeSubtypeOf(types[j], types[i])) {
  15029. score++;
  15030. }
  15031. else if (!downfallType) {
  15032. downfallType = types[j];
  15033. }
  15034. }
  15035. ts.Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType");
  15036. if (score > bestSupertypeScore) {
  15037. bestSupertype = types[i];
  15038. bestSupertypeDownfallType = downfallType;
  15039. bestSupertypeScore = score;
  15040. }
  15041. if (bestSupertypeScore === types.length - 1) {
  15042. break;
  15043. }
  15044. }
  15045. checkTypeSubtypeOf(bestSupertypeDownfallType, bestSupertype, errorLocation, ts.Diagnostics.Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0, errorMessageChainHead);
  15046. }
  15047. function isArrayType(type) {
  15048. return type.flags & 4096 && type.target === globalArrayType;
  15049. }
  15050. function isArrayLikeType(type) {
  15051. return !(type.flags & (32 | 64)) && isTypeAssignableTo(type, anyArrayType);
  15052. }
  15053. function isTupleLikeType(type) {
  15054. return !!getPropertyOfType(type, "0");
  15055. }
  15056. function isTupleType(type) {
  15057. return !!(type.flags & 8192);
  15058. }
  15059. function getRegularTypeOfObjectLiteral(type) {
  15060. if (type.flags & 1048576) {
  15061. var regularType = type.regularType;
  15062. if (!regularType) {
  15063. regularType = createType(type.flags & ~1048576);
  15064. regularType.symbol = type.symbol;
  15065. regularType.members = type.members;
  15066. regularType.properties = type.properties;
  15067. regularType.callSignatures = type.callSignatures;
  15068. regularType.constructSignatures = type.constructSignatures;
  15069. regularType.stringIndexType = type.stringIndexType;
  15070. regularType.numberIndexType = type.numberIndexType;
  15071. type.regularType = regularType;
  15072. }
  15073. return regularType;
  15074. }
  15075. return type;
  15076. }
  15077. function getWidenedTypeOfObjectLiteral(type) {
  15078. var properties = getPropertiesOfObjectType(type);
  15079. var members = {};
  15080. ts.forEach(properties, function (p) {
  15081. var propType = getTypeOfSymbol(p);
  15082. var widenedType = getWidenedType(propType);
  15083. if (propType !== widenedType) {
  15084. var symbol = createSymbol(p.flags | 67108864, p.name);
  15085. symbol.declarations = p.declarations;
  15086. symbol.parent = p.parent;
  15087. symbol.type = widenedType;
  15088. symbol.target = p;
  15089. if (p.valueDeclaration)
  15090. symbol.valueDeclaration = p.valueDeclaration;
  15091. p = symbol;
  15092. }
  15093. members[p.name] = p;
  15094. });
  15095. var stringIndexType = getIndexTypeOfType(type, 0);
  15096. var numberIndexType = getIndexTypeOfType(type, 1);
  15097. if (stringIndexType)
  15098. stringIndexType = getWidenedType(stringIndexType);
  15099. if (numberIndexType)
  15100. numberIndexType = getWidenedType(numberIndexType);
  15101. return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType);
  15102. }
  15103. function getWidenedType(type) {
  15104. if (type.flags & 6291456) {
  15105. if (type.flags & (32 | 64)) {
  15106. return anyType;
  15107. }
  15108. if (type.flags & 524288) {
  15109. return getWidenedTypeOfObjectLiteral(type);
  15110. }
  15111. if (type.flags & 16384) {
  15112. return getUnionType(ts.map(type.types, getWidenedType), true);
  15113. }
  15114. if (isArrayType(type)) {
  15115. return createArrayType(getWidenedType(type.typeArguments[0]));
  15116. }
  15117. if (isTupleType(type)) {
  15118. return createTupleType(ts.map(type.elementTypes, getWidenedType));
  15119. }
  15120. }
  15121. return type;
  15122. }
  15123. function reportWideningErrorsInType(type) {
  15124. var errorReported = false;
  15125. if (type.flags & 16384) {
  15126. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  15127. var t = _a[_i];
  15128. if (reportWideningErrorsInType(t)) {
  15129. errorReported = true;
  15130. }
  15131. }
  15132. }
  15133. if (isArrayType(type)) {
  15134. return reportWideningErrorsInType(type.typeArguments[0]);
  15135. }
  15136. if (isTupleType(type)) {
  15137. for (var _b = 0, _c = type.elementTypes; _b < _c.length; _b++) {
  15138. var t = _c[_b];
  15139. if (reportWideningErrorsInType(t)) {
  15140. errorReported = true;
  15141. }
  15142. }
  15143. }
  15144. if (type.flags & 524288) {
  15145. for (var _d = 0, _e = getPropertiesOfObjectType(type); _d < _e.length; _d++) {
  15146. var p = _e[_d];
  15147. var t = getTypeOfSymbol(p);
  15148. if (t.flags & 2097152) {
  15149. if (!reportWideningErrorsInType(t)) {
  15150. error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t)));
  15151. }
  15152. errorReported = true;
  15153. }
  15154. }
  15155. }
  15156. return errorReported;
  15157. }
  15158. function reportImplicitAnyError(declaration, type) {
  15159. var typeAsString = typeToString(getWidenedType(type));
  15160. var diagnostic;
  15161. switch (declaration.kind) {
  15162. case 141:
  15163. case 140:
  15164. diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type;
  15165. break;
  15166. case 138:
  15167. diagnostic = declaration.dotDotDotToken ?
  15168. ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type :
  15169. ts.Diagnostics.Parameter_0_implicitly_has_an_1_type;
  15170. break;
  15171. case 213:
  15172. case 143:
  15173. case 142:
  15174. case 145:
  15175. case 146:
  15176. case 173:
  15177. case 174:
  15178. if (!declaration.name) {
  15179. error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString);
  15180. return;
  15181. }
  15182. diagnostic = ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
  15183. break;
  15184. default:
  15185. diagnostic = ts.Diagnostics.Variable_0_implicitly_has_an_1_type;
  15186. }
  15187. error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString);
  15188. }
  15189. function reportErrorsFromWidening(declaration, type) {
  15190. if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 2097152) {
  15191. if (!reportWideningErrorsInType(type)) {
  15192. reportImplicitAnyError(declaration, type);
  15193. }
  15194. }
  15195. }
  15196. function forEachMatchingParameterType(source, target, callback) {
  15197. var sourceMax = source.parameters.length;
  15198. var targetMax = target.parameters.length;
  15199. var count;
  15200. if (source.hasRestParameter && target.hasRestParameter) {
  15201. count = sourceMax > targetMax ? sourceMax : targetMax;
  15202. sourceMax--;
  15203. targetMax--;
  15204. }
  15205. else if (source.hasRestParameter) {
  15206. sourceMax--;
  15207. count = targetMax;
  15208. }
  15209. else if (target.hasRestParameter) {
  15210. targetMax--;
  15211. count = sourceMax;
  15212. }
  15213. else {
  15214. count = sourceMax < targetMax ? sourceMax : targetMax;
  15215. }
  15216. for (var i = 0; i < count; i++) {
  15217. var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
  15218. var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
  15219. callback(s, t);
  15220. }
  15221. }
  15222. function createInferenceContext(typeParameters, inferUnionTypes) {
  15223. var inferences = [];
  15224. for (var _i = 0; _i < typeParameters.length; _i++) {
  15225. var unused = typeParameters[_i];
  15226. inferences.push({
  15227. primary: undefined, secondary: undefined, isFixed: false
  15228. });
  15229. }
  15230. return {
  15231. typeParameters: typeParameters,
  15232. inferUnionTypes: inferUnionTypes,
  15233. inferences: inferences,
  15234. inferredTypes: new Array(typeParameters.length)
  15235. };
  15236. }
  15237. function inferTypes(context, source, target) {
  15238. var sourceStack;
  15239. var targetStack;
  15240. var depth = 0;
  15241. var inferiority = 0;
  15242. inferFromTypes(source, target);
  15243. function isInProcess(source, target) {
  15244. for (var i = 0; i < depth; i++) {
  15245. if (source === sourceStack[i] && target === targetStack[i]) {
  15246. return true;
  15247. }
  15248. }
  15249. return false;
  15250. }
  15251. function inferFromTypes(source, target) {
  15252. if (target.flags & 512) {
  15253. if (source.flags & 8388608) {
  15254. return;
  15255. }
  15256. var typeParameters = context.typeParameters;
  15257. for (var i = 0; i < typeParameters.length; i++) {
  15258. if (target === typeParameters[i]) {
  15259. var inferences = context.inferences[i];
  15260. if (!inferences.isFixed) {
  15261. var candidates = inferiority ?
  15262. inferences.secondary || (inferences.secondary = []) :
  15263. inferences.primary || (inferences.primary = []);
  15264. if (!ts.contains(candidates, source)) {
  15265. candidates.push(source);
  15266. }
  15267. }
  15268. return;
  15269. }
  15270. }
  15271. }
  15272. else if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  15273. var sourceTypes = source.typeArguments || emptyArray;
  15274. var targetTypes = target.typeArguments || emptyArray;
  15275. var count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length;
  15276. for (var i = 0; i < count; i++) {
  15277. inferFromTypes(sourceTypes[i], targetTypes[i]);
  15278. }
  15279. }
  15280. else if (source.flags & 8192 && target.flags & 8192 && source.elementTypes.length === target.elementTypes.length) {
  15281. var sourceTypes = source.elementTypes;
  15282. var targetTypes = target.elementTypes;
  15283. for (var i = 0; i < sourceTypes.length; i++) {
  15284. inferFromTypes(sourceTypes[i], targetTypes[i]);
  15285. }
  15286. }
  15287. else if (target.flags & 49152) {
  15288. var targetTypes = target.types;
  15289. var typeParameterCount = 0;
  15290. var typeParameter;
  15291. for (var _i = 0; _i < targetTypes.length; _i++) {
  15292. var t = targetTypes[_i];
  15293. if (t.flags & 512 && ts.contains(context.typeParameters, t)) {
  15294. typeParameter = t;
  15295. typeParameterCount++;
  15296. }
  15297. else {
  15298. inferFromTypes(source, t);
  15299. }
  15300. }
  15301. if (target.flags & 16384 && typeParameterCount === 1) {
  15302. inferiority++;
  15303. inferFromTypes(source, typeParameter);
  15304. inferiority--;
  15305. }
  15306. }
  15307. else if (source.flags & 49152) {
  15308. var sourceTypes = source.types;
  15309. for (var _a = 0; _a < sourceTypes.length; _a++) {
  15310. var sourceType = sourceTypes[_a];
  15311. inferFromTypes(sourceType, target);
  15312. }
  15313. }
  15314. else {
  15315. source = getApparentType(source);
  15316. if (source.flags & 80896 && (target.flags & (4096 | 8192) ||
  15317. (target.flags & 65536) && target.symbol && target.symbol.flags & (8192 | 2048 | 32))) {
  15318. if (isInProcess(source, target)) {
  15319. return;
  15320. }
  15321. if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) {
  15322. return;
  15323. }
  15324. if (depth === 0) {
  15325. sourceStack = [];
  15326. targetStack = [];
  15327. }
  15328. sourceStack[depth] = source;
  15329. targetStack[depth] = target;
  15330. depth++;
  15331. inferFromProperties(source, target);
  15332. inferFromSignatures(source, target, 0);
  15333. inferFromSignatures(source, target, 1);
  15334. inferFromIndexTypes(source, target, 0, 0);
  15335. inferFromIndexTypes(source, target, 1, 1);
  15336. inferFromIndexTypes(source, target, 0, 1);
  15337. depth--;
  15338. }
  15339. }
  15340. }
  15341. function inferFromProperties(source, target) {
  15342. var properties = getPropertiesOfObjectType(target);
  15343. for (var _i = 0; _i < properties.length; _i++) {
  15344. var targetProp = properties[_i];
  15345. var sourceProp = getPropertyOfObjectType(source, targetProp.name);
  15346. if (sourceProp) {
  15347. inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
  15348. }
  15349. }
  15350. }
  15351. function inferFromSignatures(source, target, kind) {
  15352. var sourceSignatures = getSignaturesOfType(source, kind);
  15353. var targetSignatures = getSignaturesOfType(target, kind);
  15354. var sourceLen = sourceSignatures.length;
  15355. var targetLen = targetSignatures.length;
  15356. var len = sourceLen < targetLen ? sourceLen : targetLen;
  15357. for (var i = 0; i < len; i++) {
  15358. inferFromSignature(getErasedSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
  15359. }
  15360. }
  15361. function inferFromSignature(source, target) {
  15362. forEachMatchingParameterType(source, target, inferFromTypes);
  15363. if (source.typePredicate && target.typePredicate) {
  15364. if (target.typePredicate.parameterIndex === source.typePredicate.parameterIndex) {
  15365. inferFromTypes(source.typePredicate.type, target.typePredicate.type);
  15366. }
  15367. }
  15368. else {
  15369. inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
  15370. }
  15371. }
  15372. function inferFromIndexTypes(source, target, sourceKind, targetKind) {
  15373. var targetIndexType = getIndexTypeOfType(target, targetKind);
  15374. if (targetIndexType) {
  15375. var sourceIndexType = getIndexTypeOfType(source, sourceKind);
  15376. if (sourceIndexType) {
  15377. inferFromTypes(sourceIndexType, targetIndexType);
  15378. }
  15379. }
  15380. }
  15381. }
  15382. function getInferenceCandidates(context, index) {
  15383. var inferences = context.inferences[index];
  15384. return inferences.primary || inferences.secondary || emptyArray;
  15385. }
  15386. function getInferredType(context, index) {
  15387. var inferredType = context.inferredTypes[index];
  15388. var inferenceSucceeded;
  15389. if (!inferredType) {
  15390. var inferences = getInferenceCandidates(context, index);
  15391. if (inferences.length) {
  15392. var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences);
  15393. inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType;
  15394. inferenceSucceeded = !!unionOrSuperType;
  15395. }
  15396. else {
  15397. inferredType = emptyObjectType;
  15398. inferenceSucceeded = true;
  15399. }
  15400. if (inferenceSucceeded) {
  15401. var constraint = getConstraintOfTypeParameter(context.typeParameters[index]);
  15402. inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType;
  15403. }
  15404. else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) {
  15405. context.failedTypeParameterIndex = index;
  15406. }
  15407. context.inferredTypes[index] = inferredType;
  15408. }
  15409. return inferredType;
  15410. }
  15411. function getInferredTypes(context) {
  15412. for (var i = 0; i < context.inferredTypes.length; i++) {
  15413. getInferredType(context, i);
  15414. }
  15415. return context.inferredTypes;
  15416. }
  15417. function hasAncestor(node, kind) {
  15418. return ts.getAncestor(node, kind) !== undefined;
  15419. }
  15420. function getResolvedSymbol(node) {
  15421. var links = getNodeLinks(node);
  15422. if (!links.resolvedSymbol) {
  15423. links.resolvedSymbol = (!ts.nodeIsMissing(node) && resolveName(node, node.text, 107455 | 1048576, ts.Diagnostics.Cannot_find_name_0, node)) || unknownSymbol;
  15424. }
  15425. return links.resolvedSymbol;
  15426. }
  15427. function isInTypeQuery(node) {
  15428. while (node) {
  15429. switch (node.kind) {
  15430. case 154:
  15431. return true;
  15432. case 69:
  15433. case 135:
  15434. node = node.parent;
  15435. continue;
  15436. default:
  15437. return false;
  15438. }
  15439. }
  15440. ts.Debug.fail("should not get here");
  15441. }
  15442. function removeTypesFromUnionType(type, typeKind, isOfTypeKind, allowEmptyUnionResult) {
  15443. if (type.flags & 16384) {
  15444. var types = type.types;
  15445. if (ts.forEach(types, function (t) { return !!(t.flags & typeKind) === isOfTypeKind; })) {
  15446. var narrowedType = getUnionType(ts.filter(types, function (t) { return !(t.flags & typeKind) === isOfTypeKind; }));
  15447. if (allowEmptyUnionResult || narrowedType !== emptyObjectType) {
  15448. return narrowedType;
  15449. }
  15450. }
  15451. }
  15452. else if (allowEmptyUnionResult && !!(type.flags & typeKind) === isOfTypeKind) {
  15453. return getUnionType(emptyArray);
  15454. }
  15455. return type;
  15456. }
  15457. function hasInitializer(node) {
  15458. return !!(node.initializer || ts.isBindingPattern(node.parent) && hasInitializer(node.parent.parent));
  15459. }
  15460. function isVariableAssignedWithin(symbol, node) {
  15461. var links = getNodeLinks(node);
  15462. if (links.assignmentChecks) {
  15463. var cachedResult = links.assignmentChecks[symbol.id];
  15464. if (cachedResult !== undefined) {
  15465. return cachedResult;
  15466. }
  15467. }
  15468. else {
  15469. links.assignmentChecks = {};
  15470. }
  15471. return links.assignmentChecks[symbol.id] = isAssignedIn(node);
  15472. function isAssignedInBinaryExpression(node) {
  15473. if (node.operatorToken.kind >= 56 && node.operatorToken.kind <= 68) {
  15474. var n = node.left;
  15475. while (n.kind === 172) {
  15476. n = n.expression;
  15477. }
  15478. if (n.kind === 69 && getResolvedSymbol(n) === symbol) {
  15479. return true;
  15480. }
  15481. }
  15482. return ts.forEachChild(node, isAssignedIn);
  15483. }
  15484. function isAssignedInVariableDeclaration(node) {
  15485. if (!ts.isBindingPattern(node.name) && getSymbolOfNode(node) === symbol && hasInitializer(node)) {
  15486. return true;
  15487. }
  15488. return ts.forEachChild(node, isAssignedIn);
  15489. }
  15490. function isAssignedIn(node) {
  15491. switch (node.kind) {
  15492. case 181:
  15493. return isAssignedInBinaryExpression(node);
  15494. case 211:
  15495. case 163:
  15496. return isAssignedInVariableDeclaration(node);
  15497. case 161:
  15498. case 162:
  15499. case 164:
  15500. case 165:
  15501. case 166:
  15502. case 167:
  15503. case 168:
  15504. case 169:
  15505. case 171:
  15506. case 189:
  15507. case 172:
  15508. case 179:
  15509. case 175:
  15510. case 178:
  15511. case 176:
  15512. case 177:
  15513. case 180:
  15514. case 184:
  15515. case 182:
  15516. case 185:
  15517. case 192:
  15518. case 193:
  15519. case 195:
  15520. case 196:
  15521. case 197:
  15522. case 198:
  15523. case 199:
  15524. case 200:
  15525. case 201:
  15526. case 204:
  15527. case 205:
  15528. case 206:
  15529. case 241:
  15530. case 242:
  15531. case 207:
  15532. case 208:
  15533. case 209:
  15534. case 244:
  15535. case 233:
  15536. case 234:
  15537. case 238:
  15538. case 239:
  15539. case 235:
  15540. case 240:
  15541. return ts.forEachChild(node, isAssignedIn);
  15542. }
  15543. return false;
  15544. }
  15545. }
  15546. function getNarrowedTypeOfSymbol(symbol, node) {
  15547. var type = getTypeOfSymbol(symbol);
  15548. if (node && symbol.flags & 3) {
  15549. if (isTypeAny(type) || type.flags & (80896 | 16384 | 512)) {
  15550. loop: while (node.parent) {
  15551. var child = node;
  15552. node = node.parent;
  15553. var narrowedType = type;
  15554. switch (node.kind) {
  15555. case 196:
  15556. if (child !== node.expression) {
  15557. narrowedType = narrowType(type, node.expression, child === node.thenStatement);
  15558. }
  15559. break;
  15560. case 182:
  15561. if (child !== node.condition) {
  15562. narrowedType = narrowType(type, node.condition, child === node.whenTrue);
  15563. }
  15564. break;
  15565. case 181:
  15566. if (child === node.right) {
  15567. if (node.operatorToken.kind === 51) {
  15568. narrowedType = narrowType(type, node.left, true);
  15569. }
  15570. else if (node.operatorToken.kind === 52) {
  15571. narrowedType = narrowType(type, node.left, false);
  15572. }
  15573. }
  15574. break;
  15575. case 248:
  15576. case 218:
  15577. case 213:
  15578. case 143:
  15579. case 142:
  15580. case 145:
  15581. case 146:
  15582. case 144:
  15583. break loop;
  15584. }
  15585. if (narrowedType !== type) {
  15586. if (isVariableAssignedWithin(symbol, node)) {
  15587. break;
  15588. }
  15589. type = narrowedType;
  15590. }
  15591. }
  15592. }
  15593. }
  15594. return type;
  15595. function narrowTypeByEquality(type, expr, assumeTrue) {
  15596. if (expr.left.kind !== 176 || expr.right.kind !== 9) {
  15597. return type;
  15598. }
  15599. var left = expr.left;
  15600. var right = expr.right;
  15601. if (left.expression.kind !== 69 || getResolvedSymbol(left.expression) !== symbol) {
  15602. return type;
  15603. }
  15604. var typeInfo = primitiveTypeInfo[right.text];
  15605. if (expr.operatorToken.kind === 33) {
  15606. assumeTrue = !assumeTrue;
  15607. }
  15608. if (assumeTrue) {
  15609. if (!typeInfo) {
  15610. return removeTypesFromUnionType(type, 258 | 132 | 8 | 16777216, true, false);
  15611. }
  15612. if (isTypeSubtypeOf(typeInfo.type, type)) {
  15613. return typeInfo.type;
  15614. }
  15615. return removeTypesFromUnionType(type, typeInfo.flags, false, false);
  15616. }
  15617. else {
  15618. if (typeInfo) {
  15619. return removeTypesFromUnionType(type, typeInfo.flags, true, false);
  15620. }
  15621. return type;
  15622. }
  15623. }
  15624. function narrowTypeByAnd(type, expr, assumeTrue) {
  15625. if (assumeTrue) {
  15626. return narrowType(narrowType(type, expr.left, true), expr.right, true);
  15627. }
  15628. else {
  15629. return getUnionType([
  15630. narrowType(type, expr.left, false),
  15631. narrowType(narrowType(type, expr.left, true), expr.right, false)
  15632. ]);
  15633. }
  15634. }
  15635. function narrowTypeByOr(type, expr, assumeTrue) {
  15636. if (assumeTrue) {
  15637. return getUnionType([
  15638. narrowType(type, expr.left, true),
  15639. narrowType(narrowType(type, expr.left, false), expr.right, true)
  15640. ]);
  15641. }
  15642. else {
  15643. return narrowType(narrowType(type, expr.left, false), expr.right, false);
  15644. }
  15645. }
  15646. function narrowTypeByInstanceof(type, expr, assumeTrue) {
  15647. if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 69 || getResolvedSymbol(expr.left) !== symbol) {
  15648. return type;
  15649. }
  15650. var rightType = checkExpression(expr.right);
  15651. if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
  15652. return type;
  15653. }
  15654. var targetType;
  15655. var prototypeProperty = getPropertyOfType(rightType, "prototype");
  15656. if (prototypeProperty) {
  15657. var prototypePropertyType = getTypeOfSymbol(prototypeProperty);
  15658. if (!isTypeAny(prototypePropertyType)) {
  15659. targetType = prototypePropertyType;
  15660. }
  15661. }
  15662. if (!targetType) {
  15663. var constructSignatures;
  15664. if (rightType.flags & 2048) {
  15665. constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
  15666. }
  15667. else if (rightType.flags & 65536) {
  15668. constructSignatures = getSignaturesOfType(rightType, 1);
  15669. }
  15670. if (constructSignatures && constructSignatures.length) {
  15671. targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
  15672. }
  15673. }
  15674. if (targetType) {
  15675. return getNarrowedType(type, targetType);
  15676. }
  15677. return type;
  15678. }
  15679. function getNarrowedType(originalType, narrowedTypeCandidate) {
  15680. if (originalType.flags & 16384) {
  15681. var assignableConstituents = ts.filter(originalType.types, function (t) { return isTypeAssignableTo(t, narrowedTypeCandidate); });
  15682. if (assignableConstituents.length) {
  15683. return getUnionType(assignableConstituents);
  15684. }
  15685. }
  15686. if (isTypeAssignableTo(narrowedTypeCandidate, originalType)) {
  15687. return narrowedTypeCandidate;
  15688. }
  15689. return originalType;
  15690. }
  15691. function narrowTypeByTypePredicate(type, expr, assumeTrue) {
  15692. if (type.flags & 1) {
  15693. return type;
  15694. }
  15695. var signature = getResolvedSignature(expr);
  15696. if (signature.typePredicate &&
  15697. expr.arguments[signature.typePredicate.parameterIndex] &&
  15698. getSymbolAtLocation(expr.arguments[signature.typePredicate.parameterIndex]) === symbol) {
  15699. if (!assumeTrue) {
  15700. if (type.flags & 16384) {
  15701. return getUnionType(ts.filter(type.types, function (t) { return !isTypeSubtypeOf(t, signature.typePredicate.type); }));
  15702. }
  15703. return type;
  15704. }
  15705. return getNarrowedType(type, signature.typePredicate.type);
  15706. }
  15707. return type;
  15708. }
  15709. function narrowType(type, expr, assumeTrue) {
  15710. switch (expr.kind) {
  15711. case 168:
  15712. return narrowTypeByTypePredicate(type, expr, assumeTrue);
  15713. case 172:
  15714. return narrowType(type, expr.expression, assumeTrue);
  15715. case 181:
  15716. var operator = expr.operatorToken.kind;
  15717. if (operator === 32 || operator === 33) {
  15718. return narrowTypeByEquality(type, expr, assumeTrue);
  15719. }
  15720. else if (operator === 51) {
  15721. return narrowTypeByAnd(type, expr, assumeTrue);
  15722. }
  15723. else if (operator === 52) {
  15724. return narrowTypeByOr(type, expr, assumeTrue);
  15725. }
  15726. else if (operator === 91) {
  15727. return narrowTypeByInstanceof(type, expr, assumeTrue);
  15728. }
  15729. break;
  15730. case 179:
  15731. if (expr.operator === 49) {
  15732. return narrowType(type, expr.operand, !assumeTrue);
  15733. }
  15734. break;
  15735. }
  15736. return type;
  15737. }
  15738. }
  15739. function checkIdentifier(node) {
  15740. var symbol = getResolvedSymbol(node);
  15741. if (symbol === argumentsSymbol) {
  15742. var container = ts.getContainingFunction(node);
  15743. if (container.kind === 174) {
  15744. if (languageVersion < 2) {
  15745. error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
  15746. }
  15747. }
  15748. if (node.parserContextFlags & 8) {
  15749. getNodeLinks(container).flags |= 4096;
  15750. getNodeLinks(node).flags |= 2048;
  15751. }
  15752. }
  15753. if (symbol.flags & 8388608 && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
  15754. markAliasSymbolAsReferenced(symbol);
  15755. }
  15756. checkCollisionWithCapturedSuperVariable(node, node);
  15757. checkCollisionWithCapturedThisVariable(node, node);
  15758. checkBlockScopedBindingCapturedInLoop(node, symbol);
  15759. return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node);
  15760. }
  15761. function isInsideFunction(node, threshold) {
  15762. var current = node;
  15763. while (current && current !== threshold) {
  15764. if (ts.isFunctionLike(current)) {
  15765. return true;
  15766. }
  15767. current = current.parent;
  15768. }
  15769. return false;
  15770. }
  15771. function checkBlockScopedBindingCapturedInLoop(node, symbol) {
  15772. if (languageVersion >= 2 ||
  15773. (symbol.flags & 2) === 0 ||
  15774. symbol.valueDeclaration.parent.kind === 244) {
  15775. return;
  15776. }
  15777. var container = symbol.valueDeclaration;
  15778. while (container.kind !== 212) {
  15779. container = container.parent;
  15780. }
  15781. container = container.parent;
  15782. if (container.kind === 193) {
  15783. container = container.parent;
  15784. }
  15785. var inFunction = isInsideFunction(node.parent, container);
  15786. var current = container;
  15787. while (current && !ts.nodeStartsNewLexicalEnvironment(current)) {
  15788. if (isIterationStatement(current, false)) {
  15789. if (inFunction) {
  15790. grammarErrorOnFirstToken(current, ts.Diagnostics.Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher, ts.declarationNameToString(node));
  15791. }
  15792. getNodeLinks(symbol.valueDeclaration).flags |= 16384;
  15793. break;
  15794. }
  15795. current = current.parent;
  15796. }
  15797. }
  15798. function captureLexicalThis(node, container) {
  15799. getNodeLinks(node).flags |= 2;
  15800. if (container.kind === 141 || container.kind === 144) {
  15801. var classNode = container.parent;
  15802. getNodeLinks(classNode).flags |= 4;
  15803. }
  15804. else {
  15805. getNodeLinks(container).flags |= 4;
  15806. }
  15807. }
  15808. function checkThisExpression(node) {
  15809. var container = ts.getThisContainer(node, true);
  15810. var needToCaptureLexicalThis = false;
  15811. if (container.kind === 174) {
  15812. container = ts.getThisContainer(container, false);
  15813. needToCaptureLexicalThis = (languageVersion < 2);
  15814. }
  15815. switch (container.kind) {
  15816. case 218:
  15817. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body);
  15818. break;
  15819. case 217:
  15820. error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
  15821. break;
  15822. case 144:
  15823. if (isInConstructorArgumentInitializer(node, container)) {
  15824. error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments);
  15825. }
  15826. break;
  15827. case 141:
  15828. case 140:
  15829. if (container.flags & 128) {
  15830. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer);
  15831. }
  15832. break;
  15833. case 136:
  15834. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name);
  15835. break;
  15836. }
  15837. if (needToCaptureLexicalThis) {
  15838. captureLexicalThis(node, container);
  15839. }
  15840. if (ts.isClassLike(container.parent)) {
  15841. var symbol = getSymbolOfNode(container.parent);
  15842. return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol).thisType;
  15843. }
  15844. return anyType;
  15845. }
  15846. function isInConstructorArgumentInitializer(node, constructorDecl) {
  15847. for (var n = node; n && n !== constructorDecl; n = n.parent) {
  15848. if (n.kind === 138) {
  15849. return true;
  15850. }
  15851. }
  15852. return false;
  15853. }
  15854. function checkSuperExpression(node) {
  15855. var isCallExpression = node.parent.kind === 168 && node.parent.expression === node;
  15856. var classDeclaration = ts.getContainingClass(node);
  15857. var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
  15858. var baseClassType = classType && getBaseTypes(classType)[0];
  15859. var container = ts.getSuperContainer(node, true);
  15860. var needToCaptureLexicalThis = false;
  15861. if (!isCallExpression) {
  15862. while (container && container.kind === 174) {
  15863. container = ts.getSuperContainer(container, true);
  15864. needToCaptureLexicalThis = languageVersion < 2;
  15865. }
  15866. }
  15867. var canUseSuperExpression = isLegalUsageOfSuperExpression(container);
  15868. var nodeCheckFlag = 0;
  15869. if (canUseSuperExpression) {
  15870. if ((container.flags & 128) || isCallExpression) {
  15871. nodeCheckFlag = 512;
  15872. }
  15873. else {
  15874. nodeCheckFlag = 256;
  15875. }
  15876. getNodeLinks(node).flags |= nodeCheckFlag;
  15877. if (needToCaptureLexicalThis) {
  15878. captureLexicalThis(node.parent, container);
  15879. }
  15880. }
  15881. if (!baseClassType) {
  15882. if (!classDeclaration || !ts.getClassExtendsHeritageClauseElement(classDeclaration)) {
  15883. error(node, ts.Diagnostics.super_can_only_be_referenced_in_a_derived_class);
  15884. }
  15885. return unknownType;
  15886. }
  15887. if (!canUseSuperExpression) {
  15888. if (container && container.kind === 136) {
  15889. error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
  15890. }
  15891. else if (isCallExpression) {
  15892. error(node, ts.Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
  15893. }
  15894. else {
  15895. error(node, ts.Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
  15896. }
  15897. return unknownType;
  15898. }
  15899. if (container.kind === 144 && isInConstructorArgumentInitializer(node, container)) {
  15900. error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments);
  15901. return unknownType;
  15902. }
  15903. return nodeCheckFlag === 512
  15904. ? getBaseConstructorTypeOfClass(classType)
  15905. : baseClassType;
  15906. function isLegalUsageOfSuperExpression(container) {
  15907. if (!container) {
  15908. return false;
  15909. }
  15910. if (isCallExpression) {
  15911. return container.kind === 144;
  15912. }
  15913. else {
  15914. if (container && ts.isClassLike(container.parent)) {
  15915. if (container.flags & 128) {
  15916. return container.kind === 143 ||
  15917. container.kind === 142 ||
  15918. container.kind === 145 ||
  15919. container.kind === 146;
  15920. }
  15921. else {
  15922. return container.kind === 143 ||
  15923. container.kind === 142 ||
  15924. container.kind === 145 ||
  15925. container.kind === 146 ||
  15926. container.kind === 141 ||
  15927. container.kind === 140 ||
  15928. container.kind === 144;
  15929. }
  15930. }
  15931. }
  15932. return false;
  15933. }
  15934. }
  15935. function getContextuallyTypedParameterType(parameter) {
  15936. var func = parameter.parent;
  15937. if (isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) {
  15938. if (isContextSensitive(func)) {
  15939. var contextualSignature = getContextualSignature(func);
  15940. if (contextualSignature) {
  15941. var funcHasRestParameters = ts.hasRestParameter(func);
  15942. var len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
  15943. var indexOfParameter = ts.indexOf(func.parameters, parameter);
  15944. if (indexOfParameter < len) {
  15945. return getTypeAtPosition(contextualSignature, indexOfParameter);
  15946. }
  15947. if (funcHasRestParameters &&
  15948. indexOfParameter === (func.parameters.length - 1) &&
  15949. isRestParameterIndex(contextualSignature, func.parameters.length - 1)) {
  15950. return getTypeOfSymbol(ts.lastOrUndefined(contextualSignature.parameters));
  15951. }
  15952. }
  15953. }
  15954. }
  15955. return undefined;
  15956. }
  15957. function getContextualTypeForInitializerExpression(node) {
  15958. var declaration = node.parent;
  15959. if (node === declaration.initializer) {
  15960. if (declaration.type) {
  15961. return getTypeFromTypeNode(declaration.type);
  15962. }
  15963. if (declaration.kind === 138) {
  15964. var type = getContextuallyTypedParameterType(declaration);
  15965. if (type) {
  15966. return type;
  15967. }
  15968. }
  15969. if (ts.isBindingPattern(declaration.name)) {
  15970. return getTypeFromBindingPattern(declaration.name, true);
  15971. }
  15972. }
  15973. return undefined;
  15974. }
  15975. function getContextualTypeForReturnExpression(node) {
  15976. var func = ts.getContainingFunction(node);
  15977. if (func && !func.asteriskToken) {
  15978. return getContextualReturnType(func);
  15979. }
  15980. return undefined;
  15981. }
  15982. function getContextualTypeForYieldOperand(node) {
  15983. var func = ts.getContainingFunction(node);
  15984. if (func) {
  15985. var contextualReturnType = getContextualReturnType(func);
  15986. if (contextualReturnType) {
  15987. return node.asteriskToken
  15988. ? contextualReturnType
  15989. : getElementTypeOfIterableIterator(contextualReturnType);
  15990. }
  15991. }
  15992. return undefined;
  15993. }
  15994. function isInParameterInitializerBeforeContainingFunction(node) {
  15995. while (node.parent && !ts.isFunctionLike(node.parent)) {
  15996. if (node.parent.kind === 138 && node.parent.initializer === node) {
  15997. return true;
  15998. }
  15999. node = node.parent;
  16000. }
  16001. return false;
  16002. }
  16003. function getContextualReturnType(functionDecl) {
  16004. if (functionDecl.type ||
  16005. functionDecl.kind === 144 ||
  16006. functionDecl.kind === 145 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 146))) {
  16007. return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
  16008. }
  16009. var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl);
  16010. if (signature) {
  16011. return getReturnTypeOfSignature(signature);
  16012. }
  16013. return undefined;
  16014. }
  16015. function getContextualTypeForArgument(callTarget, arg) {
  16016. var args = getEffectiveCallArguments(callTarget);
  16017. var argIndex = ts.indexOf(args, arg);
  16018. if (argIndex >= 0) {
  16019. var signature = getResolvedSignature(callTarget);
  16020. return getTypeAtPosition(signature, argIndex);
  16021. }
  16022. return undefined;
  16023. }
  16024. function getContextualTypeForSubstitutionExpression(template, substitutionExpression) {
  16025. if (template.parent.kind === 170) {
  16026. return getContextualTypeForArgument(template.parent, substitutionExpression);
  16027. }
  16028. return undefined;
  16029. }
  16030. function getContextualTypeForBinaryOperand(node) {
  16031. var binaryExpression = node.parent;
  16032. var operator = binaryExpression.operatorToken.kind;
  16033. if (operator >= 56 && operator <= 68) {
  16034. if (node === binaryExpression.right) {
  16035. return checkExpression(binaryExpression.left);
  16036. }
  16037. }
  16038. else if (operator === 52) {
  16039. var type = getContextualType(binaryExpression);
  16040. if (!type && node === binaryExpression.right) {
  16041. type = checkExpression(binaryExpression.left);
  16042. }
  16043. return type;
  16044. }
  16045. return undefined;
  16046. }
  16047. function applyToContextualType(type, mapper) {
  16048. if (!(type.flags & 16384)) {
  16049. return mapper(type);
  16050. }
  16051. var types = type.types;
  16052. var mappedType;
  16053. var mappedTypes;
  16054. for (var _i = 0; _i < types.length; _i++) {
  16055. var current = types[_i];
  16056. var t = mapper(current);
  16057. if (t) {
  16058. if (!mappedType) {
  16059. mappedType = t;
  16060. }
  16061. else if (!mappedTypes) {
  16062. mappedTypes = [mappedType, t];
  16063. }
  16064. else {
  16065. mappedTypes.push(t);
  16066. }
  16067. }
  16068. }
  16069. return mappedTypes ? getUnionType(mappedTypes) : mappedType;
  16070. }
  16071. function getTypeOfPropertyOfContextualType(type, name) {
  16072. return applyToContextualType(type, function (t) {
  16073. var prop = t.flags & 130048 ? getPropertyOfType(t, name) : undefined;
  16074. return prop ? getTypeOfSymbol(prop) : undefined;
  16075. });
  16076. }
  16077. function getIndexTypeOfContextualType(type, kind) {
  16078. return applyToContextualType(type, function (t) { return getIndexTypeOfStructuredType(t, kind); });
  16079. }
  16080. function contextualTypeIsTupleLikeType(type) {
  16081. return !!(type.flags & 16384 ? ts.forEach(type.types, isTupleLikeType) : isTupleLikeType(type));
  16082. }
  16083. function contextualTypeHasIndexSignature(type, kind) {
  16084. return !!(type.flags & 16384 ? ts.forEach(type.types, function (t) { return getIndexTypeOfStructuredType(t, kind); }) : getIndexTypeOfStructuredType(type, kind));
  16085. }
  16086. function getContextualTypeForObjectLiteralMethod(node) {
  16087. ts.Debug.assert(ts.isObjectLiteralMethod(node));
  16088. if (isInsideWithStatementBody(node)) {
  16089. return undefined;
  16090. }
  16091. return getContextualTypeForObjectLiteralElement(node);
  16092. }
  16093. function getContextualTypeForObjectLiteralElement(element) {
  16094. var objectLiteral = element.parent;
  16095. var type = getContextualType(objectLiteral);
  16096. if (type) {
  16097. if (!ts.hasDynamicName(element)) {
  16098. var symbolName = getSymbolOfNode(element).name;
  16099. var propertyType = getTypeOfPropertyOfContextualType(type, symbolName);
  16100. if (propertyType) {
  16101. return propertyType;
  16102. }
  16103. }
  16104. return isNumericName(element.name) && getIndexTypeOfContextualType(type, 1) ||
  16105. getIndexTypeOfContextualType(type, 0);
  16106. }
  16107. return undefined;
  16108. }
  16109. function getContextualTypeForElementExpression(node) {
  16110. var arrayLiteral = node.parent;
  16111. var type = getContextualType(arrayLiteral);
  16112. if (type) {
  16113. var index = ts.indexOf(arrayLiteral.elements, node);
  16114. return getTypeOfPropertyOfContextualType(type, "" + index)
  16115. || getIndexTypeOfContextualType(type, 1)
  16116. || (languageVersion >= 2 ? getElementTypeOfIterable(type, undefined) : undefined);
  16117. }
  16118. return undefined;
  16119. }
  16120. function getContextualTypeForConditionalOperand(node) {
  16121. var conditional = node.parent;
  16122. return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined;
  16123. }
  16124. function getContextualTypeForJsxExpression(expr) {
  16125. if (expr.parent.kind === 238) {
  16126. var attrib = expr.parent;
  16127. var attrsType = getJsxElementAttributesType(attrib.parent);
  16128. if (!attrsType || isTypeAny(attrsType)) {
  16129. return undefined;
  16130. }
  16131. else {
  16132. return getTypeOfPropertyOfType(attrsType, attrib.name.text);
  16133. }
  16134. }
  16135. if (expr.kind === 239) {
  16136. return getJsxElementAttributesType(expr.parent);
  16137. }
  16138. return undefined;
  16139. }
  16140. function getContextualType(node) {
  16141. var type = getContextualTypeWorker(node);
  16142. return type && getApparentType(type);
  16143. }
  16144. function getContextualTypeWorker(node) {
  16145. if (isInsideWithStatementBody(node)) {
  16146. return undefined;
  16147. }
  16148. if (node.contextualType) {
  16149. return node.contextualType;
  16150. }
  16151. var parent = node.parent;
  16152. switch (parent.kind) {
  16153. case 211:
  16154. case 138:
  16155. case 141:
  16156. case 140:
  16157. case 163:
  16158. return getContextualTypeForInitializerExpression(node);
  16159. case 174:
  16160. case 204:
  16161. return getContextualTypeForReturnExpression(node);
  16162. case 184:
  16163. return getContextualTypeForYieldOperand(parent);
  16164. case 168:
  16165. case 169:
  16166. return getContextualTypeForArgument(parent, node);
  16167. case 171:
  16168. case 189:
  16169. return getTypeFromTypeNode(parent.type);
  16170. case 181:
  16171. return getContextualTypeForBinaryOperand(node);
  16172. case 245:
  16173. return getContextualTypeForObjectLiteralElement(parent);
  16174. case 164:
  16175. return getContextualTypeForElementExpression(node);
  16176. case 182:
  16177. return getContextualTypeForConditionalOperand(node);
  16178. case 190:
  16179. ts.Debug.assert(parent.parent.kind === 183);
  16180. return getContextualTypeForSubstitutionExpression(parent.parent, node);
  16181. case 172:
  16182. return getContextualType(parent);
  16183. case 240:
  16184. case 239:
  16185. return getContextualTypeForJsxExpression(parent);
  16186. }
  16187. return undefined;
  16188. }
  16189. function getNonGenericSignature(type) {
  16190. var signatures = getSignaturesOfStructuredType(type, 0);
  16191. if (signatures.length === 1) {
  16192. var signature = signatures[0];
  16193. if (!signature.typeParameters) {
  16194. return signature;
  16195. }
  16196. }
  16197. }
  16198. function isFunctionExpressionOrArrowFunction(node) {
  16199. return node.kind === 173 || node.kind === 174;
  16200. }
  16201. function getContextualSignatureForFunctionLikeDeclaration(node) {
  16202. return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node)
  16203. ? getContextualSignature(node)
  16204. : undefined;
  16205. }
  16206. function getContextualSignature(node) {
  16207. ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node));
  16208. var type = ts.isObjectLiteralMethod(node)
  16209. ? getContextualTypeForObjectLiteralMethod(node)
  16210. : getContextualType(node);
  16211. if (!type) {
  16212. return undefined;
  16213. }
  16214. if (!(type.flags & 16384)) {
  16215. return getNonGenericSignature(type);
  16216. }
  16217. var signatureList;
  16218. var types = type.types;
  16219. for (var _i = 0; _i < types.length; _i++) {
  16220. var current = types[_i];
  16221. var signature = getNonGenericSignature(current);
  16222. if (signature) {
  16223. if (!signatureList) {
  16224. signatureList = [signature];
  16225. }
  16226. else if (!compareSignatures(signatureList[0], signature, false, true, compareTypes)) {
  16227. return undefined;
  16228. }
  16229. else {
  16230. signatureList.push(signature);
  16231. }
  16232. }
  16233. }
  16234. var result;
  16235. if (signatureList) {
  16236. result = cloneSignature(signatureList[0]);
  16237. result.resolvedReturnType = undefined;
  16238. result.unionSignatures = signatureList;
  16239. }
  16240. return result;
  16241. }
  16242. function isInferentialContext(mapper) {
  16243. return mapper && mapper.context;
  16244. }
  16245. function isAssignmentTarget(node) {
  16246. var parent = node.parent;
  16247. if (parent.kind === 181 && parent.operatorToken.kind === 56 && parent.left === node) {
  16248. return true;
  16249. }
  16250. if (parent.kind === 245) {
  16251. return isAssignmentTarget(parent.parent);
  16252. }
  16253. if (parent.kind === 164) {
  16254. return isAssignmentTarget(parent);
  16255. }
  16256. return false;
  16257. }
  16258. function checkSpreadElementExpression(node, contextualMapper) {
  16259. var arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper);
  16260. return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, false);
  16261. }
  16262. function hasDefaultValue(node) {
  16263. return (node.kind === 163 && !!node.initializer) ||
  16264. (node.kind === 181 && node.operatorToken.kind === 56);
  16265. }
  16266. function checkArrayLiteral(node, contextualMapper) {
  16267. var elements = node.elements;
  16268. var hasSpreadElement = false;
  16269. var elementTypes = [];
  16270. var inDestructuringPattern = isAssignmentTarget(node);
  16271. for (var _i = 0; _i < elements.length; _i++) {
  16272. var e = elements[_i];
  16273. if (inDestructuringPattern && e.kind === 185) {
  16274. var restArrayType = checkExpression(e.expression, contextualMapper);
  16275. var restElementType = getIndexTypeOfType(restArrayType, 1) ||
  16276. (languageVersion >= 2 ? getElementTypeOfIterable(restArrayType, undefined) : undefined);
  16277. if (restElementType) {
  16278. elementTypes.push(restElementType);
  16279. }
  16280. }
  16281. else {
  16282. var type = checkExpression(e, contextualMapper);
  16283. elementTypes.push(type);
  16284. }
  16285. hasSpreadElement = hasSpreadElement || e.kind === 185;
  16286. }
  16287. if (!hasSpreadElement) {
  16288. if (inDestructuringPattern && elementTypes.length) {
  16289. var type = createNewTupleType(elementTypes);
  16290. type.pattern = node;
  16291. return type;
  16292. }
  16293. var contextualType = getContextualType(node);
  16294. if (contextualType && contextualTypeIsTupleLikeType(contextualType)) {
  16295. var pattern = contextualType.pattern;
  16296. if (pattern && (pattern.kind === 162 || pattern.kind === 164)) {
  16297. var patternElements = pattern.elements;
  16298. for (var i = elementTypes.length; i < patternElements.length; i++) {
  16299. var patternElement = patternElements[i];
  16300. if (hasDefaultValue(patternElement)) {
  16301. elementTypes.push(contextualType.elementTypes[i]);
  16302. }
  16303. else {
  16304. if (patternElement.kind !== 187) {
  16305. error(patternElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);
  16306. }
  16307. elementTypes.push(unknownType);
  16308. }
  16309. }
  16310. }
  16311. if (elementTypes.length) {
  16312. return createTupleType(elementTypes);
  16313. }
  16314. }
  16315. }
  16316. return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType);
  16317. }
  16318. function isNumericName(name) {
  16319. return name.kind === 136 ? isNumericComputedName(name) : isNumericLiteralName(name.text);
  16320. }
  16321. function isNumericComputedName(name) {
  16322. return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132);
  16323. }
  16324. function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) {
  16325. return isTypeAny(type) || allConstituentTypesHaveKind(type, kind);
  16326. }
  16327. function isNumericLiteralName(name) {
  16328. return (+name).toString() === name;
  16329. }
  16330. function checkComputedPropertyName(node) {
  16331. var links = getNodeLinks(node.expression);
  16332. if (!links.resolvedType) {
  16333. links.resolvedType = checkExpression(node.expression);
  16334. if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 | 258 | 16777216)) {
  16335. error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any);
  16336. }
  16337. else {
  16338. checkThatExpressionIsProperSymbolReference(node.expression, links.resolvedType, true);
  16339. }
  16340. }
  16341. return links.resolvedType;
  16342. }
  16343. function checkObjectLiteral(node, contextualMapper) {
  16344. var inDestructuringPattern = isAssignmentTarget(node);
  16345. checkGrammarObjectLiteralExpression(node, inDestructuringPattern);
  16346. var propertiesTable = {};
  16347. var propertiesArray = [];
  16348. var contextualType = getContextualType(node);
  16349. var contextualTypeHasPattern = contextualType && contextualType.pattern &&
  16350. (contextualType.pattern.kind === 161 || contextualType.pattern.kind === 165);
  16351. var typeFlags = 0;
  16352. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  16353. var memberDecl = _a[_i];
  16354. var member = memberDecl.symbol;
  16355. if (memberDecl.kind === 245 ||
  16356. memberDecl.kind === 246 ||
  16357. ts.isObjectLiteralMethod(memberDecl)) {
  16358. var type = void 0;
  16359. if (memberDecl.kind === 245) {
  16360. type = checkPropertyAssignment(memberDecl, contextualMapper);
  16361. }
  16362. else if (memberDecl.kind === 143) {
  16363. type = checkObjectLiteralMethod(memberDecl, contextualMapper);
  16364. }
  16365. else {
  16366. ts.Debug.assert(memberDecl.kind === 246);
  16367. type = checkExpression(memberDecl.name, contextualMapper);
  16368. }
  16369. typeFlags |= type.flags;
  16370. var prop = createSymbol(4 | 67108864 | member.flags, member.name);
  16371. if (inDestructuringPattern) {
  16372. var isOptional = (memberDecl.kind === 245 && hasDefaultValue(memberDecl.initializer)) ||
  16373. (memberDecl.kind === 246 && memberDecl.objectAssignmentInitializer);
  16374. if (isOptional) {
  16375. prop.flags |= 536870912;
  16376. }
  16377. }
  16378. else if (contextualTypeHasPattern) {
  16379. var impliedProp = getPropertyOfType(contextualType, member.name);
  16380. if (impliedProp) {
  16381. prop.flags |= impliedProp.flags & 536870912;
  16382. }
  16383. else if (!compilerOptions.suppressExcessPropertyErrors) {
  16384. error(memberDecl.name, ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(member), typeToString(contextualType));
  16385. }
  16386. }
  16387. prop.declarations = member.declarations;
  16388. prop.parent = member.parent;
  16389. if (member.valueDeclaration) {
  16390. prop.valueDeclaration = member.valueDeclaration;
  16391. }
  16392. prop.type = type;
  16393. prop.target = member;
  16394. member = prop;
  16395. }
  16396. else {
  16397. ts.Debug.assert(memberDecl.kind === 145 || memberDecl.kind === 146);
  16398. checkAccessorDeclaration(memberDecl);
  16399. }
  16400. if (!ts.hasDynamicName(memberDecl)) {
  16401. propertiesTable[member.name] = member;
  16402. }
  16403. propertiesArray.push(member);
  16404. }
  16405. if (contextualTypeHasPattern) {
  16406. for (var _b = 0, _c = getPropertiesOfType(contextualType); _b < _c.length; _b++) {
  16407. var prop = _c[_b];
  16408. if (!ts.hasProperty(propertiesTable, prop.name)) {
  16409. if (!(prop.flags & 536870912)) {
  16410. error(prop.valueDeclaration || prop.bindingElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);
  16411. }
  16412. propertiesTable[prop.name] = prop;
  16413. propertiesArray.push(prop);
  16414. }
  16415. }
  16416. }
  16417. var stringIndexType = getIndexType(0);
  16418. var numberIndexType = getIndexType(1);
  16419. var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
  16420. var freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : 1048576;
  16421. result.flags |= 524288 | 4194304 | freshObjectLiteralFlag | (typeFlags & 14680064);
  16422. if (inDestructuringPattern) {
  16423. result.pattern = node;
  16424. }
  16425. return result;
  16426. function getIndexType(kind) {
  16427. if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) {
  16428. var propTypes = [];
  16429. for (var i = 0; i < propertiesArray.length; i++) {
  16430. var propertyDecl = node.properties[i];
  16431. if (kind === 0 || isNumericName(propertyDecl.name)) {
  16432. var type = getTypeOfSymbol(propertiesArray[i]);
  16433. if (!ts.contains(propTypes, type)) {
  16434. propTypes.push(type);
  16435. }
  16436. }
  16437. }
  16438. var result_1 = propTypes.length ? getUnionType(propTypes) : undefinedType;
  16439. typeFlags |= result_1.flags;
  16440. return result_1;
  16441. }
  16442. return undefined;
  16443. }
  16444. }
  16445. function checkJsxSelfClosingElement(node) {
  16446. checkJsxOpeningLikeElement(node);
  16447. return jsxElementType || anyType;
  16448. }
  16449. function tagNamesAreEquivalent(lhs, rhs) {
  16450. if (lhs.kind !== rhs.kind) {
  16451. return false;
  16452. }
  16453. if (lhs.kind === 69) {
  16454. return lhs.text === rhs.text;
  16455. }
  16456. return lhs.right.text === rhs.right.text &&
  16457. tagNamesAreEquivalent(lhs.left, rhs.left);
  16458. }
  16459. function checkJsxElement(node) {
  16460. checkJsxOpeningLikeElement(node.openingElement);
  16461. if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) {
  16462. error(node.closingElement, ts.Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, ts.getTextOfNode(node.openingElement.tagName));
  16463. }
  16464. else {
  16465. getJsxElementTagSymbol(node.closingElement);
  16466. }
  16467. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  16468. var child = _a[_i];
  16469. switch (child.kind) {
  16470. case 240:
  16471. checkJsxExpression(child);
  16472. break;
  16473. case 233:
  16474. checkJsxElement(child);
  16475. break;
  16476. case 234:
  16477. checkJsxSelfClosingElement(child);
  16478. break;
  16479. default:
  16480. ts.Debug.assert(child.kind === 236);
  16481. }
  16482. }
  16483. return jsxElementType || anyType;
  16484. }
  16485. function isUnhyphenatedJsxName(name) {
  16486. return name.indexOf("-") < 0;
  16487. }
  16488. function isJsxIntrinsicIdentifier(tagName) {
  16489. if (tagName.kind === 135) {
  16490. return false;
  16491. }
  16492. else {
  16493. return ts.isIntrinsicJsxName(tagName.text);
  16494. }
  16495. }
  16496. function checkJsxAttribute(node, elementAttributesType, nameTable) {
  16497. var correspondingPropType = undefined;
  16498. if (elementAttributesType === emptyObjectType && isUnhyphenatedJsxName(node.name.text)) {
  16499. error(node.parent, ts.Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, getJsxElementPropertiesName());
  16500. }
  16501. else if (elementAttributesType && !isTypeAny(elementAttributesType)) {
  16502. var correspondingPropSymbol = getPropertyOfType(elementAttributesType, node.name.text);
  16503. correspondingPropType = correspondingPropSymbol && getTypeOfSymbol(correspondingPropSymbol);
  16504. if (isUnhyphenatedJsxName(node.name.text)) {
  16505. var indexerType = getIndexTypeOfType(elementAttributesType, 0);
  16506. if (indexerType) {
  16507. correspondingPropType = indexerType;
  16508. }
  16509. else {
  16510. if (!correspondingPropType) {
  16511. error(node.name, ts.Diagnostics.Property_0_does_not_exist_on_type_1, node.name.text, typeToString(elementAttributesType));
  16512. return unknownType;
  16513. }
  16514. }
  16515. }
  16516. }
  16517. var exprType;
  16518. if (node.initializer) {
  16519. exprType = checkExpression(node.initializer);
  16520. }
  16521. else {
  16522. exprType = booleanType;
  16523. }
  16524. if (correspondingPropType) {
  16525. checkTypeAssignableTo(exprType, correspondingPropType, node);
  16526. }
  16527. nameTable[node.name.text] = true;
  16528. return exprType;
  16529. }
  16530. function checkJsxSpreadAttribute(node, elementAttributesType, nameTable) {
  16531. var type = checkExpression(node.expression);
  16532. var props = getPropertiesOfType(type);
  16533. for (var _i = 0; _i < props.length; _i++) {
  16534. var prop = props[_i];
  16535. if (!nameTable[prop.name]) {
  16536. var targetPropSym = getPropertyOfType(elementAttributesType, prop.name);
  16537. if (targetPropSym) {
  16538. var msg = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property, prop.name);
  16539. checkTypeAssignableTo(getTypeOfSymbol(prop), getTypeOfSymbol(targetPropSym), node, undefined, msg);
  16540. }
  16541. nameTable[prop.name] = true;
  16542. }
  16543. }
  16544. return type;
  16545. }
  16546. function getJsxIntrinsicElementsType() {
  16547. if (!jsxIntrinsicElementsType) {
  16548. jsxIntrinsicElementsType = getExportedTypeFromNamespace(JsxNames.JSX, JsxNames.IntrinsicElements) || unknownType;
  16549. }
  16550. return jsxIntrinsicElementsType;
  16551. }
  16552. function getJsxElementTagSymbol(node) {
  16553. var flags = 8;
  16554. var links = getNodeLinks(node);
  16555. if (!links.resolvedSymbol) {
  16556. if (isJsxIntrinsicIdentifier(node.tagName)) {
  16557. links.resolvedSymbol = lookupIntrinsicTag(node);
  16558. }
  16559. else {
  16560. links.resolvedSymbol = lookupClassTag(node);
  16561. }
  16562. }
  16563. return links.resolvedSymbol;
  16564. function lookupIntrinsicTag(node) {
  16565. var intrinsicElementsType = getJsxIntrinsicElementsType();
  16566. if (intrinsicElementsType !== unknownType) {
  16567. var intrinsicProp = getPropertyOfType(intrinsicElementsType, node.tagName.text);
  16568. if (intrinsicProp) {
  16569. links.jsxFlags |= 1;
  16570. return intrinsicProp;
  16571. }
  16572. var indexSignatureType = getIndexTypeOfType(intrinsicElementsType, 0);
  16573. if (indexSignatureType) {
  16574. links.jsxFlags |= 2;
  16575. return intrinsicElementsType.symbol;
  16576. }
  16577. error(node, ts.Diagnostics.Property_0_does_not_exist_on_type_1, node.tagName.text, "JSX." + JsxNames.IntrinsicElements);
  16578. return unknownSymbol;
  16579. }
  16580. else {
  16581. if (compilerOptions.noImplicitAny) {
  16582. error(node, ts.Diagnostics.JSX_element_implicitly_has_type_any_because_no_interface_JSX_0_exists, JsxNames.IntrinsicElements);
  16583. }
  16584. }
  16585. }
  16586. function lookupClassTag(node) {
  16587. var valueSymbol = resolveJsxTagName(node);
  16588. if (valueSymbol && valueSymbol !== unknownSymbol) {
  16589. links.jsxFlags |= 4;
  16590. if (valueSymbol.flags & 8388608) {
  16591. markAliasSymbolAsReferenced(valueSymbol);
  16592. }
  16593. }
  16594. return valueSymbol || unknownSymbol;
  16595. }
  16596. function resolveJsxTagName(node) {
  16597. if (node.tagName.kind === 69) {
  16598. var tag = node.tagName;
  16599. var sym = getResolvedSymbol(tag);
  16600. return sym.exportSymbol || sym;
  16601. }
  16602. else {
  16603. return checkQualifiedName(node.tagName).symbol;
  16604. }
  16605. }
  16606. }
  16607. function getJsxElementInstanceType(node) {
  16608. ts.Debug.assert(!!(getNodeLinks(node).jsxFlags & 4), "Should not call getJsxElementInstanceType on non-class Element");
  16609. var classSymbol = getJsxElementTagSymbol(node);
  16610. if (classSymbol === unknownSymbol) {
  16611. return anyType;
  16612. }
  16613. var valueType = getTypeOfSymbol(classSymbol);
  16614. if (isTypeAny(valueType)) {
  16615. return anyType;
  16616. }
  16617. var signatures = getSignaturesOfType(valueType, 1);
  16618. if (signatures.length === 0) {
  16619. signatures = getSignaturesOfType(valueType, 0);
  16620. if (signatures.length === 0) {
  16621. error(node.tagName, ts.Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, ts.getTextOfNode(node.tagName));
  16622. return unknownType;
  16623. }
  16624. }
  16625. var returnType = getUnionType(signatures.map(getReturnTypeOfSignature));
  16626. var elemClassType = getJsxGlobalElementClassType();
  16627. if (elemClassType) {
  16628. checkTypeRelatedTo(returnType, elemClassType, assignableRelation, node, ts.Diagnostics.JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements);
  16629. }
  16630. return returnType;
  16631. }
  16632. function getJsxElementPropertiesName() {
  16633. var jsxNamespace = getGlobalSymbol(JsxNames.JSX, 1536, undefined);
  16634. var attribsPropTypeSym = jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.ElementAttributesPropertyNameContainer, 793056);
  16635. var attribPropType = attribsPropTypeSym && getDeclaredTypeOfSymbol(attribsPropTypeSym);
  16636. var attribProperties = attribPropType && getPropertiesOfType(attribPropType);
  16637. if (attribProperties) {
  16638. if (attribProperties.length === 0) {
  16639. return "";
  16640. }
  16641. else if (attribProperties.length === 1) {
  16642. return attribProperties[0].name;
  16643. }
  16644. else {
  16645. error(attribsPropTypeSym.declarations[0], ts.Diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property, JsxNames.ElementAttributesPropertyNameContainer);
  16646. return undefined;
  16647. }
  16648. }
  16649. else {
  16650. return undefined;
  16651. }
  16652. }
  16653. function getJsxElementAttributesType(node) {
  16654. var links = getNodeLinks(node);
  16655. if (!links.resolvedJsxType) {
  16656. var sym = getJsxElementTagSymbol(node);
  16657. if (links.jsxFlags & 4) {
  16658. var elemInstanceType = getJsxElementInstanceType(node);
  16659. if (isTypeAny(elemInstanceType)) {
  16660. return links.resolvedJsxType = elemInstanceType;
  16661. }
  16662. var propsName = getJsxElementPropertiesName();
  16663. if (propsName === undefined) {
  16664. return links.resolvedJsxType = anyType;
  16665. }
  16666. else if (propsName === "") {
  16667. return links.resolvedJsxType = elemInstanceType;
  16668. }
  16669. else {
  16670. var attributesType = getTypeOfPropertyOfType(elemInstanceType, propsName);
  16671. if (!attributesType) {
  16672. return links.resolvedJsxType = emptyObjectType;
  16673. }
  16674. else if (isTypeAny(attributesType) || (attributesType === unknownType)) {
  16675. return links.resolvedJsxType = attributesType;
  16676. }
  16677. else if (!(attributesType.flags & 80896)) {
  16678. error(node.tagName, ts.Diagnostics.JSX_element_attributes_type_0_must_be_an_object_type, typeToString(attributesType));
  16679. return links.resolvedJsxType = anyType;
  16680. }
  16681. else {
  16682. return links.resolvedJsxType = attributesType;
  16683. }
  16684. }
  16685. }
  16686. else if (links.jsxFlags & 1) {
  16687. return links.resolvedJsxType = getTypeOfSymbol(sym);
  16688. }
  16689. else if (links.jsxFlags & 2) {
  16690. return links.resolvedJsxType = getIndexTypeOfSymbol(sym, 0);
  16691. }
  16692. else {
  16693. return links.resolvedJsxType = anyType;
  16694. }
  16695. }
  16696. return links.resolvedJsxType;
  16697. }
  16698. function getJsxAttributePropertySymbol(attrib) {
  16699. var attributesType = getJsxElementAttributesType(attrib.parent);
  16700. var prop = getPropertyOfType(attributesType, attrib.name.text);
  16701. return prop || unknownSymbol;
  16702. }
  16703. var jsxElementClassType = undefined;
  16704. function getJsxGlobalElementClassType() {
  16705. if (!jsxElementClassType) {
  16706. jsxElementClassType = getExportedTypeFromNamespace(JsxNames.JSX, JsxNames.ElementClass);
  16707. }
  16708. return jsxElementClassType;
  16709. }
  16710. function getJsxIntrinsicTagNames() {
  16711. var intrinsics = getJsxIntrinsicElementsType();
  16712. return intrinsics ? getPropertiesOfType(intrinsics) : emptyArray;
  16713. }
  16714. function checkJsxPreconditions(errorNode) {
  16715. if ((compilerOptions.jsx || 0) === 0) {
  16716. error(errorNode, ts.Diagnostics.Cannot_use_JSX_unless_the_jsx_flag_is_provided);
  16717. }
  16718. if (jsxElementType === undefined) {
  16719. if (compilerOptions.noImplicitAny) {
  16720. error(errorNode, ts.Diagnostics.JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist);
  16721. }
  16722. }
  16723. }
  16724. function checkJsxOpeningLikeElement(node) {
  16725. checkGrammarJsxElement(node);
  16726. checkJsxPreconditions(node);
  16727. if (compilerOptions.jsx === 2) {
  16728. var reactSym = resolveName(node.tagName, "React", 107455, ts.Diagnostics.Cannot_find_name_0, "React");
  16729. if (reactSym) {
  16730. getSymbolLinks(reactSym).referenced = true;
  16731. }
  16732. }
  16733. var targetAttributesType = getJsxElementAttributesType(node);
  16734. var nameTable = {};
  16735. var sawSpreadedAny = false;
  16736. for (var i = node.attributes.length - 1; i >= 0; i--) {
  16737. if (node.attributes[i].kind === 238) {
  16738. checkJsxAttribute((node.attributes[i]), targetAttributesType, nameTable);
  16739. }
  16740. else {
  16741. ts.Debug.assert(node.attributes[i].kind === 239);
  16742. var spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable);
  16743. if (isTypeAny(spreadType)) {
  16744. sawSpreadedAny = true;
  16745. }
  16746. }
  16747. }
  16748. if (targetAttributesType && !sawSpreadedAny) {
  16749. var targetProperties = getPropertiesOfType(targetAttributesType);
  16750. for (var i = 0; i < targetProperties.length; i++) {
  16751. if (!(targetProperties[i].flags & 536870912) &&
  16752. nameTable[targetProperties[i].name] === undefined) {
  16753. error(node, ts.Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
  16754. }
  16755. }
  16756. }
  16757. }
  16758. function checkJsxExpression(node) {
  16759. if (node.expression) {
  16760. return checkExpression(node.expression);
  16761. }
  16762. else {
  16763. return unknownType;
  16764. }
  16765. }
  16766. function getDeclarationKindFromSymbol(s) {
  16767. return s.valueDeclaration ? s.valueDeclaration.kind : 141;
  16768. }
  16769. function getDeclarationFlagsFromSymbol(s) {
  16770. return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 ? 16 | 128 : 0;
  16771. }
  16772. function checkClassPropertyAccess(node, left, type, prop) {
  16773. var flags = getDeclarationFlagsFromSymbol(prop);
  16774. var declaringClass = getDeclaredTypeOfSymbol(prop.parent);
  16775. if (left.kind === 95) {
  16776. var errorNode = node.kind === 166 ?
  16777. node.name :
  16778. node.right;
  16779. if (getDeclarationKindFromSymbol(prop) !== 143) {
  16780. error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
  16781. return false;
  16782. }
  16783. if (flags & 256) {
  16784. error(errorNode, ts.Diagnostics.Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression, symbolToString(prop), typeToString(declaringClass));
  16785. return false;
  16786. }
  16787. }
  16788. if (!(flags & (32 | 64))) {
  16789. return true;
  16790. }
  16791. var enclosingClassDeclaration = ts.getContainingClass(node);
  16792. var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;
  16793. if (flags & 32) {
  16794. if (declaringClass !== enclosingClass) {
  16795. error(node, ts.Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(declaringClass));
  16796. return false;
  16797. }
  16798. return true;
  16799. }
  16800. if (left.kind === 95) {
  16801. return true;
  16802. }
  16803. if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) {
  16804. error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(declaringClass));
  16805. return false;
  16806. }
  16807. if (flags & 128) {
  16808. return true;
  16809. }
  16810. if (type.flags & 33554432) {
  16811. type = getConstraintOfTypeParameter(type);
  16812. }
  16813. if (!(getTargetType(type).flags & (1024 | 2048) && hasBaseType(type, enclosingClass))) {
  16814. error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass));
  16815. return false;
  16816. }
  16817. return true;
  16818. }
  16819. function checkPropertyAccessExpression(node) {
  16820. return checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name);
  16821. }
  16822. function checkQualifiedName(node) {
  16823. return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right);
  16824. }
  16825. function checkPropertyAccessExpressionOrQualifiedName(node, left, right) {
  16826. var type = checkExpression(left);
  16827. if (isTypeAny(type)) {
  16828. return type;
  16829. }
  16830. var apparentType = getApparentType(getWidenedType(type));
  16831. if (apparentType === unknownType) {
  16832. return unknownType;
  16833. }
  16834. var prop = getPropertyOfType(apparentType, right.text);
  16835. if (!prop) {
  16836. if (right.text) {
  16837. error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type.flags & 33554432 ? apparentType : type));
  16838. }
  16839. return unknownType;
  16840. }
  16841. getNodeLinks(node).resolvedSymbol = prop;
  16842. if (prop.parent && prop.parent.flags & 32) {
  16843. checkClassPropertyAccess(node, left, apparentType, prop);
  16844. }
  16845. return getTypeOfSymbol(prop);
  16846. }
  16847. function isValidPropertyAccess(node, propertyName) {
  16848. var left = node.kind === 166
  16849. ? node.expression
  16850. : node.left;
  16851. var type = checkExpression(left);
  16852. if (type !== unknownType && !isTypeAny(type)) {
  16853. var prop = getPropertyOfType(getWidenedType(type), propertyName);
  16854. if (prop && prop.parent && prop.parent.flags & 32) {
  16855. return checkClassPropertyAccess(node, left, type, prop);
  16856. }
  16857. }
  16858. return true;
  16859. }
  16860. function checkIndexedAccess(node) {
  16861. if (!node.argumentExpression) {
  16862. var sourceFile = getSourceFile(node);
  16863. if (node.parent.kind === 169 && node.parent.expression === node) {
  16864. var start = ts.skipTrivia(sourceFile.text, node.expression.end);
  16865. var end = node.end;
  16866. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
  16867. }
  16868. else {
  16869. var start = node.end - "]".length;
  16870. var end = node.end;
  16871. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Expression_expected);
  16872. }
  16873. }
  16874. var objectType = getApparentType(checkExpression(node.expression));
  16875. var indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType;
  16876. if (objectType === unknownType) {
  16877. return unknownType;
  16878. }
  16879. var isConstEnum = isConstEnumObjectType(objectType);
  16880. if (isConstEnum &&
  16881. (!node.argumentExpression || node.argumentExpression.kind !== 9)) {
  16882. error(node.argumentExpression, ts.Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
  16883. return unknownType;
  16884. }
  16885. if (node.argumentExpression) {
  16886. var name_11 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType);
  16887. if (name_11 !== undefined) {
  16888. var prop = getPropertyOfType(objectType, name_11);
  16889. if (prop) {
  16890. getNodeLinks(node).resolvedSymbol = prop;
  16891. return getTypeOfSymbol(prop);
  16892. }
  16893. else if (isConstEnum) {
  16894. error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_11, symbolToString(objectType.symbol));
  16895. return unknownType;
  16896. }
  16897. }
  16898. }
  16899. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 | 132 | 16777216)) {
  16900. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132)) {
  16901. var numberIndexType = getIndexTypeOfType(objectType, 1);
  16902. if (numberIndexType) {
  16903. return numberIndexType;
  16904. }
  16905. }
  16906. var stringIndexType = getIndexTypeOfType(objectType, 0);
  16907. if (stringIndexType) {
  16908. return stringIndexType;
  16909. }
  16910. if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) {
  16911. error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type);
  16912. }
  16913. return anyType;
  16914. }
  16915. error(node, ts.Diagnostics.An_index_expression_argument_must_be_of_type_string_number_symbol_or_any);
  16916. return unknownType;
  16917. }
  16918. function getPropertyNameForIndexedAccess(indexArgumentExpression, indexArgumentType) {
  16919. if (indexArgumentExpression.kind === 9 || indexArgumentExpression.kind === 8) {
  16920. return indexArgumentExpression.text;
  16921. }
  16922. if (indexArgumentExpression.kind === 167 || indexArgumentExpression.kind === 166) {
  16923. var value = getConstantValue(indexArgumentExpression);
  16924. if (value !== undefined) {
  16925. return value.toString();
  16926. }
  16927. }
  16928. if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, false)) {
  16929. var rightHandSideName = indexArgumentExpression.name.text;
  16930. return ts.getPropertyNameForKnownSymbolName(rightHandSideName);
  16931. }
  16932. return undefined;
  16933. }
  16934. function checkThatExpressionIsProperSymbolReference(expression, expressionType, reportError) {
  16935. if (expressionType === unknownType) {
  16936. return false;
  16937. }
  16938. if (!ts.isWellKnownSymbolSyntactically(expression)) {
  16939. return false;
  16940. }
  16941. if ((expressionType.flags & 16777216) === 0) {
  16942. if (reportError) {
  16943. error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression));
  16944. }
  16945. return false;
  16946. }
  16947. var leftHandSide = expression.expression;
  16948. var leftHandSideSymbol = getResolvedSymbol(leftHandSide);
  16949. if (!leftHandSideSymbol) {
  16950. return false;
  16951. }
  16952. var globalESSymbol = getGlobalESSymbolConstructorSymbol();
  16953. if (!globalESSymbol) {
  16954. return false;
  16955. }
  16956. if (leftHandSideSymbol !== globalESSymbol) {
  16957. if (reportError) {
  16958. error(leftHandSide, ts.Diagnostics.Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object);
  16959. }
  16960. return false;
  16961. }
  16962. return true;
  16963. }
  16964. function resolveUntypedCall(node) {
  16965. if (node.kind === 170) {
  16966. checkExpression(node.template);
  16967. }
  16968. else if (node.kind !== 139) {
  16969. ts.forEach(node.arguments, function (argument) {
  16970. checkExpression(argument);
  16971. });
  16972. }
  16973. return anySignature;
  16974. }
  16975. function resolveErrorCall(node) {
  16976. resolveUntypedCall(node);
  16977. return unknownSignature;
  16978. }
  16979. function reorderCandidates(signatures, result) {
  16980. var lastParent;
  16981. var lastSymbol;
  16982. var cutoffIndex = 0;
  16983. var index;
  16984. var specializedIndex = -1;
  16985. var spliceIndex;
  16986. ts.Debug.assert(!result.length);
  16987. for (var _i = 0; _i < signatures.length; _i++) {
  16988. var signature = signatures[_i];
  16989. var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
  16990. var parent_5 = signature.declaration && signature.declaration.parent;
  16991. if (!lastSymbol || symbol === lastSymbol) {
  16992. if (lastParent && parent_5 === lastParent) {
  16993. index++;
  16994. }
  16995. else {
  16996. lastParent = parent_5;
  16997. index = cutoffIndex;
  16998. }
  16999. }
  17000. else {
  17001. index = cutoffIndex = result.length;
  17002. lastParent = parent_5;
  17003. }
  17004. lastSymbol = symbol;
  17005. if (signature.hasStringLiterals) {
  17006. specializedIndex++;
  17007. spliceIndex = specializedIndex;
  17008. cutoffIndex++;
  17009. }
  17010. else {
  17011. spliceIndex = index;
  17012. }
  17013. result.splice(spliceIndex, 0, signature);
  17014. }
  17015. }
  17016. function getSpreadArgumentIndex(args) {
  17017. for (var i = 0; i < args.length; i++) {
  17018. var arg = args[i];
  17019. if (arg && arg.kind === 185) {
  17020. return i;
  17021. }
  17022. }
  17023. return -1;
  17024. }
  17025. function hasCorrectArity(node, args, signature) {
  17026. var adjustedArgCount;
  17027. var typeArguments;
  17028. var callIsIncomplete;
  17029. var isDecorator;
  17030. var spreadArgIndex = -1;
  17031. if (node.kind === 170) {
  17032. var tagExpression = node;
  17033. adjustedArgCount = args.length;
  17034. typeArguments = undefined;
  17035. if (tagExpression.template.kind === 183) {
  17036. var templateExpression = tagExpression.template;
  17037. var lastSpan = ts.lastOrUndefined(templateExpression.templateSpans);
  17038. ts.Debug.assert(lastSpan !== undefined);
  17039. callIsIncomplete = ts.nodeIsMissing(lastSpan.literal) || !!lastSpan.literal.isUnterminated;
  17040. }
  17041. else {
  17042. var templateLiteral = tagExpression.template;
  17043. ts.Debug.assert(templateLiteral.kind === 11);
  17044. callIsIncomplete = !!templateLiteral.isUnterminated;
  17045. }
  17046. }
  17047. else if (node.kind === 139) {
  17048. isDecorator = true;
  17049. typeArguments = undefined;
  17050. adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature);
  17051. }
  17052. else {
  17053. var callExpression = node;
  17054. if (!callExpression.arguments) {
  17055. ts.Debug.assert(callExpression.kind === 169);
  17056. return signature.minArgumentCount === 0;
  17057. }
  17058. adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length;
  17059. callIsIncomplete = callExpression.arguments.end === callExpression.end;
  17060. typeArguments = callExpression.typeArguments;
  17061. spreadArgIndex = getSpreadArgumentIndex(args);
  17062. }
  17063. var hasRightNumberOfTypeArgs = !typeArguments ||
  17064. (signature.typeParameters && typeArguments.length === signature.typeParameters.length);
  17065. if (!hasRightNumberOfTypeArgs) {
  17066. return false;
  17067. }
  17068. if (spreadArgIndex >= 0) {
  17069. return isRestParameterIndex(signature, spreadArgIndex);
  17070. }
  17071. if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) {
  17072. return false;
  17073. }
  17074. var hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount;
  17075. return callIsIncomplete || hasEnoughArguments;
  17076. }
  17077. function getSingleCallSignature(type) {
  17078. if (type.flags & 80896) {
  17079. var resolved = resolveStructuredTypeMembers(type);
  17080. if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 &&
  17081. resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) {
  17082. return resolved.callSignatures[0];
  17083. }
  17084. }
  17085. return undefined;
  17086. }
  17087. function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper) {
  17088. var context = createInferenceContext(signature.typeParameters, true);
  17089. forEachMatchingParameterType(contextualSignature, signature, function (source, target) {
  17090. inferTypes(context, instantiateType(source, contextualMapper), target);
  17091. });
  17092. return getSignatureInstantiation(signature, getInferredTypes(context));
  17093. }
  17094. function inferTypeArguments(node, signature, args, excludeArgument, context) {
  17095. var typeParameters = signature.typeParameters;
  17096. var inferenceMapper = createInferenceMapper(context);
  17097. for (var i = 0; i < typeParameters.length; i++) {
  17098. if (!context.inferences[i].isFixed) {
  17099. context.inferredTypes[i] = undefined;
  17100. }
  17101. }
  17102. if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) {
  17103. context.failedTypeParameterIndex = undefined;
  17104. }
  17105. var argCount = getEffectiveArgumentCount(node, args, signature);
  17106. for (var i = 0; i < argCount; i++) {
  17107. var arg = getEffectiveArgument(node, args, i);
  17108. if (arg === undefined || arg.kind !== 187) {
  17109. var paramType = getTypeAtPosition(signature, i);
  17110. var argType = getEffectiveArgumentType(node, i, arg);
  17111. if (argType === undefined) {
  17112. var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
  17113. argType = checkExpressionWithContextualType(arg, paramType, mapper);
  17114. }
  17115. inferTypes(context, argType, paramType);
  17116. }
  17117. }
  17118. if (excludeArgument) {
  17119. for (var i = 0; i < argCount; i++) {
  17120. if (excludeArgument[i] === false) {
  17121. var arg = args[i];
  17122. var paramType = getTypeAtPosition(signature, i);
  17123. inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType);
  17124. }
  17125. }
  17126. }
  17127. getInferredTypes(context);
  17128. }
  17129. function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors, headMessage) {
  17130. var typeParameters = signature.typeParameters;
  17131. var typeArgumentsAreAssignable = true;
  17132. for (var i = 0; i < typeParameters.length; i++) {
  17133. var typeArgNode = typeArguments[i];
  17134. var typeArgument = getTypeFromTypeNode(typeArgNode);
  17135. typeArgumentResultTypes[i] = typeArgument;
  17136. if (typeArgumentsAreAssignable) {
  17137. var constraint = getConstraintOfTypeParameter(typeParameters[i]);
  17138. if (constraint) {
  17139. var errorInfo = void 0;
  17140. var typeArgumentHeadMessage = ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1;
  17141. if (reportErrors && headMessage) {
  17142. errorInfo = ts.chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage);
  17143. typeArgumentHeadMessage = headMessage;
  17144. }
  17145. typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, typeArgumentHeadMessage, errorInfo);
  17146. }
  17147. }
  17148. }
  17149. return typeArgumentsAreAssignable;
  17150. }
  17151. function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) {
  17152. var argCount = getEffectiveArgumentCount(node, args, signature);
  17153. for (var i = 0; i < argCount; i++) {
  17154. var arg = getEffectiveArgument(node, args, i);
  17155. if (arg === undefined || arg.kind !== 187) {
  17156. var paramType = getTypeAtPosition(signature, i);
  17157. var argType = getEffectiveArgumentType(node, i, arg);
  17158. if (argType === undefined) {
  17159. argType = arg.kind === 9 && !reportErrors
  17160. ? getStringLiteralType(arg)
  17161. : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
  17162. }
  17163. var errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined;
  17164. var headMessage = ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1;
  17165. if (!checkTypeRelatedTo(argType, paramType, relation, errorNode, headMessage)) {
  17166. return false;
  17167. }
  17168. }
  17169. }
  17170. return true;
  17171. }
  17172. function getEffectiveCallArguments(node) {
  17173. var args;
  17174. if (node.kind === 170) {
  17175. var template = node.template;
  17176. args = [undefined];
  17177. if (template.kind === 183) {
  17178. ts.forEach(template.templateSpans, function (span) {
  17179. args.push(span.expression);
  17180. });
  17181. }
  17182. }
  17183. else if (node.kind === 139) {
  17184. return undefined;
  17185. }
  17186. else {
  17187. args = node.arguments || emptyArray;
  17188. }
  17189. return args;
  17190. }
  17191. function getEffectiveArgumentCount(node, args, signature) {
  17192. if (node.kind === 139) {
  17193. switch (node.parent.kind) {
  17194. case 214:
  17195. case 186:
  17196. return 1;
  17197. case 141:
  17198. return 2;
  17199. case 143:
  17200. case 145:
  17201. case 146:
  17202. if (languageVersion === 0) {
  17203. return 2;
  17204. }
  17205. return signature.parameters.length >= 3 ? 3 : 2;
  17206. case 138:
  17207. return 3;
  17208. }
  17209. }
  17210. else {
  17211. return args.length;
  17212. }
  17213. }
  17214. function getEffectiveDecoratorFirstArgumentType(node) {
  17215. if (node.kind === 214) {
  17216. var classSymbol = getSymbolOfNode(node);
  17217. return getTypeOfSymbol(classSymbol);
  17218. }
  17219. if (node.kind === 138) {
  17220. node = node.parent;
  17221. if (node.kind === 144) {
  17222. var classSymbol = getSymbolOfNode(node);
  17223. return getTypeOfSymbol(classSymbol);
  17224. }
  17225. }
  17226. if (node.kind === 141 ||
  17227. node.kind === 143 ||
  17228. node.kind === 145 ||
  17229. node.kind === 146) {
  17230. return getParentTypeOfClassElement(node);
  17231. }
  17232. ts.Debug.fail("Unsupported decorator target.");
  17233. return unknownType;
  17234. }
  17235. function getEffectiveDecoratorSecondArgumentType(node) {
  17236. if (node.kind === 214) {
  17237. ts.Debug.fail("Class decorators should not have a second synthetic argument.");
  17238. return unknownType;
  17239. }
  17240. if (node.kind === 138) {
  17241. node = node.parent;
  17242. if (node.kind === 144) {
  17243. return anyType;
  17244. }
  17245. }
  17246. if (node.kind === 141 ||
  17247. node.kind === 143 ||
  17248. node.kind === 145 ||
  17249. node.kind === 146) {
  17250. var element = node;
  17251. switch (element.name.kind) {
  17252. case 69:
  17253. case 8:
  17254. case 9:
  17255. return getStringLiteralType(element.name);
  17256. case 136:
  17257. var nameType = checkComputedPropertyName(element.name);
  17258. if (allConstituentTypesHaveKind(nameType, 16777216)) {
  17259. return nameType;
  17260. }
  17261. else {
  17262. return stringType;
  17263. }
  17264. default:
  17265. ts.Debug.fail("Unsupported property name.");
  17266. return unknownType;
  17267. }
  17268. }
  17269. ts.Debug.fail("Unsupported decorator target.");
  17270. return unknownType;
  17271. }
  17272. function getEffectiveDecoratorThirdArgumentType(node) {
  17273. if (node.kind === 214) {
  17274. ts.Debug.fail("Class decorators should not have a third synthetic argument.");
  17275. return unknownType;
  17276. }
  17277. if (node.kind === 138) {
  17278. return numberType;
  17279. }
  17280. if (node.kind === 141) {
  17281. ts.Debug.fail("Property decorators should not have a third synthetic argument.");
  17282. return unknownType;
  17283. }
  17284. if (node.kind === 143 ||
  17285. node.kind === 145 ||
  17286. node.kind === 146) {
  17287. var propertyType = getTypeOfNode(node);
  17288. return createTypedPropertyDescriptorType(propertyType);
  17289. }
  17290. ts.Debug.fail("Unsupported decorator target.");
  17291. return unknownType;
  17292. }
  17293. function getEffectiveDecoratorArgumentType(node, argIndex) {
  17294. if (argIndex === 0) {
  17295. return getEffectiveDecoratorFirstArgumentType(node.parent);
  17296. }
  17297. else if (argIndex === 1) {
  17298. return getEffectiveDecoratorSecondArgumentType(node.parent);
  17299. }
  17300. else if (argIndex === 2) {
  17301. return getEffectiveDecoratorThirdArgumentType(node.parent);
  17302. }
  17303. ts.Debug.fail("Decorators should not have a fourth synthetic argument.");
  17304. return unknownType;
  17305. }
  17306. function getEffectiveArgumentType(node, argIndex, arg) {
  17307. if (node.kind === 139) {
  17308. return getEffectiveDecoratorArgumentType(node, argIndex);
  17309. }
  17310. else if (argIndex === 0 && node.kind === 170) {
  17311. return globalTemplateStringsArrayType;
  17312. }
  17313. return undefined;
  17314. }
  17315. function getEffectiveArgument(node, args, argIndex) {
  17316. if (node.kind === 139 ||
  17317. (argIndex === 0 && node.kind === 170)) {
  17318. return undefined;
  17319. }
  17320. return args[argIndex];
  17321. }
  17322. function getEffectiveArgumentErrorNode(node, argIndex, arg) {
  17323. if (node.kind === 139) {
  17324. return node.expression;
  17325. }
  17326. else if (argIndex === 0 && node.kind === 170) {
  17327. return node.template;
  17328. }
  17329. else {
  17330. return arg;
  17331. }
  17332. }
  17333. function resolveCall(node, signatures, candidatesOutArray, headMessage) {
  17334. var isTaggedTemplate = node.kind === 170;
  17335. var isDecorator = node.kind === 139;
  17336. var typeArguments;
  17337. if (!isTaggedTemplate && !isDecorator) {
  17338. typeArguments = node.typeArguments;
  17339. if (node.expression.kind !== 95) {
  17340. ts.forEach(typeArguments, checkSourceElement);
  17341. }
  17342. }
  17343. var candidates = candidatesOutArray || [];
  17344. reorderCandidates(signatures, candidates);
  17345. if (!candidates.length) {
  17346. reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
  17347. return resolveErrorCall(node);
  17348. }
  17349. var args = getEffectiveCallArguments(node);
  17350. var excludeArgument;
  17351. if (!isDecorator) {
  17352. for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) {
  17353. if (isContextSensitive(args[i])) {
  17354. if (!excludeArgument) {
  17355. excludeArgument = new Array(args.length);
  17356. }
  17357. excludeArgument[i] = true;
  17358. }
  17359. }
  17360. }
  17361. var candidateForArgumentError;
  17362. var candidateForTypeArgumentError;
  17363. var resultOfFailedInference;
  17364. var result;
  17365. if (candidates.length > 1) {
  17366. result = chooseOverload(candidates, subtypeRelation);
  17367. }
  17368. if (!result) {
  17369. candidateForArgumentError = undefined;
  17370. candidateForTypeArgumentError = undefined;
  17371. resultOfFailedInference = undefined;
  17372. result = chooseOverload(candidates, assignableRelation);
  17373. }
  17374. if (result) {
  17375. return result;
  17376. }
  17377. if (candidateForArgumentError) {
  17378. checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, undefined, true);
  17379. }
  17380. else if (candidateForTypeArgumentError) {
  17381. if (!isTaggedTemplate && !isDecorator && typeArguments) {
  17382. checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], true, headMessage);
  17383. }
  17384. else {
  17385. ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);
  17386. var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex];
  17387. var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex);
  17388. var diagnosticChainHead = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter));
  17389. if (headMessage) {
  17390. diagnosticChainHead = ts.chainDiagnosticMessages(diagnosticChainHead, headMessage);
  17391. }
  17392. reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead);
  17393. }
  17394. }
  17395. else {
  17396. reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
  17397. }
  17398. if (!produceDiagnostics) {
  17399. for (var _i = 0; _i < candidates.length; _i++) {
  17400. var candidate = candidates[_i];
  17401. if (hasCorrectArity(node, args, candidate)) {
  17402. if (candidate.typeParameters && typeArguments) {
  17403. candidate = getSignatureInstantiation(candidate, ts.map(typeArguments, getTypeFromTypeNode));
  17404. }
  17405. return candidate;
  17406. }
  17407. }
  17408. }
  17409. return resolveErrorCall(node);
  17410. function reportError(message, arg0, arg1, arg2) {
  17411. var errorInfo;
  17412. errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
  17413. if (headMessage) {
  17414. errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage);
  17415. }
  17416. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo));
  17417. }
  17418. function chooseOverload(candidates, relation) {
  17419. for (var _i = 0; _i < candidates.length; _i++) {
  17420. var originalCandidate = candidates[_i];
  17421. if (!hasCorrectArity(node, args, originalCandidate)) {
  17422. continue;
  17423. }
  17424. var candidate = void 0;
  17425. var typeArgumentsAreValid = void 0;
  17426. var inferenceContext = originalCandidate.typeParameters
  17427. ? createInferenceContext(originalCandidate.typeParameters, false)
  17428. : undefined;
  17429. while (true) {
  17430. candidate = originalCandidate;
  17431. if (candidate.typeParameters) {
  17432. var typeArgumentTypes = void 0;
  17433. if (typeArguments) {
  17434. typeArgumentTypes = new Array(candidate.typeParameters.length);
  17435. typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, false);
  17436. }
  17437. else {
  17438. inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
  17439. typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined;
  17440. typeArgumentTypes = inferenceContext.inferredTypes;
  17441. }
  17442. if (!typeArgumentsAreValid) {
  17443. break;
  17444. }
  17445. candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
  17446. }
  17447. if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, false)) {
  17448. break;
  17449. }
  17450. var index = excludeArgument ? ts.indexOf(excludeArgument, true) : -1;
  17451. if (index < 0) {
  17452. return candidate;
  17453. }
  17454. excludeArgument[index] = false;
  17455. }
  17456. if (originalCandidate.typeParameters) {
  17457. var instantiatedCandidate = candidate;
  17458. if (typeArgumentsAreValid) {
  17459. candidateForArgumentError = instantiatedCandidate;
  17460. }
  17461. else {
  17462. candidateForTypeArgumentError = originalCandidate;
  17463. if (!typeArguments) {
  17464. resultOfFailedInference = inferenceContext;
  17465. }
  17466. }
  17467. }
  17468. else {
  17469. ts.Debug.assert(originalCandidate === candidate);
  17470. candidateForArgumentError = originalCandidate;
  17471. }
  17472. }
  17473. return undefined;
  17474. }
  17475. }
  17476. function resolveCallExpression(node, candidatesOutArray) {
  17477. if (node.expression.kind === 95) {
  17478. var superType = checkSuperExpression(node.expression);
  17479. if (superType !== unknownType) {
  17480. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node));
  17481. var baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments);
  17482. return resolveCall(node, baseConstructors, candidatesOutArray);
  17483. }
  17484. return resolveUntypedCall(node);
  17485. }
  17486. var funcType = checkExpression(node.expression);
  17487. var apparentType = getApparentType(funcType);
  17488. if (apparentType === unknownType) {
  17489. return resolveErrorCall(node);
  17490. }
  17491. var callSignatures = getSignaturesOfType(apparentType, 0);
  17492. var constructSignatures = getSignaturesOfType(apparentType, 1);
  17493. if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) {
  17494. if (funcType !== unknownType && node.typeArguments) {
  17495. error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
  17496. }
  17497. return resolveUntypedCall(node);
  17498. }
  17499. if (!callSignatures.length) {
  17500. if (constructSignatures.length) {
  17501. error(node, ts.Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
  17502. }
  17503. else {
  17504. error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  17505. }
  17506. return resolveErrorCall(node);
  17507. }
  17508. return resolveCall(node, callSignatures, candidatesOutArray);
  17509. }
  17510. function resolveNewExpression(node, candidatesOutArray) {
  17511. if (node.arguments && languageVersion < 1) {
  17512. var spreadIndex = getSpreadArgumentIndex(node.arguments);
  17513. if (spreadIndex >= 0) {
  17514. error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher);
  17515. }
  17516. }
  17517. var expressionType = checkExpression(node.expression);
  17518. expressionType = getApparentType(expressionType);
  17519. if (expressionType === unknownType) {
  17520. return resolveErrorCall(node);
  17521. }
  17522. var valueDecl = expressionType.symbol && getClassLikeDeclarationOfSymbol(expressionType.symbol);
  17523. if (valueDecl && valueDecl.flags & 256) {
  17524. error(node, ts.Diagnostics.Cannot_create_an_instance_of_the_abstract_class_0, ts.declarationNameToString(valueDecl.name));
  17525. return resolveErrorCall(node);
  17526. }
  17527. if (isTypeAny(expressionType)) {
  17528. if (node.typeArguments) {
  17529. error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
  17530. }
  17531. return resolveUntypedCall(node);
  17532. }
  17533. var constructSignatures = getSignaturesOfType(expressionType, 1);
  17534. if (constructSignatures.length) {
  17535. return resolveCall(node, constructSignatures, candidatesOutArray);
  17536. }
  17537. var callSignatures = getSignaturesOfType(expressionType, 0);
  17538. if (callSignatures.length) {
  17539. var signature = resolveCall(node, callSignatures, candidatesOutArray);
  17540. if (getReturnTypeOfSignature(signature) !== voidType) {
  17541. error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword);
  17542. }
  17543. return signature;
  17544. }
  17545. error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature);
  17546. return resolveErrorCall(node);
  17547. }
  17548. function resolveTaggedTemplateExpression(node, candidatesOutArray) {
  17549. var tagType = checkExpression(node.tag);
  17550. var apparentType = getApparentType(tagType);
  17551. if (apparentType === unknownType) {
  17552. return resolveErrorCall(node);
  17553. }
  17554. var callSignatures = getSignaturesOfType(apparentType, 0);
  17555. if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) {
  17556. return resolveUntypedCall(node);
  17557. }
  17558. if (!callSignatures.length) {
  17559. error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  17560. return resolveErrorCall(node);
  17561. }
  17562. return resolveCall(node, callSignatures, candidatesOutArray);
  17563. }
  17564. function getDiagnosticHeadMessageForDecoratorResolution(node) {
  17565. switch (node.parent.kind) {
  17566. case 214:
  17567. case 186:
  17568. return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression;
  17569. case 138:
  17570. return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression;
  17571. case 141:
  17572. return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression;
  17573. case 143:
  17574. case 145:
  17575. case 146:
  17576. return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression;
  17577. }
  17578. }
  17579. function resolveDecorator(node, candidatesOutArray) {
  17580. var funcType = checkExpression(node.expression);
  17581. var apparentType = getApparentType(funcType);
  17582. if (apparentType === unknownType) {
  17583. return resolveErrorCall(node);
  17584. }
  17585. var callSignatures = getSignaturesOfType(apparentType, 0);
  17586. if (funcType === anyType || (!callSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) {
  17587. return resolveUntypedCall(node);
  17588. }
  17589. var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
  17590. if (!callSignatures.length) {
  17591. var errorInfo;
  17592. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  17593. errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage);
  17594. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo));
  17595. return resolveErrorCall(node);
  17596. }
  17597. return resolveCall(node, callSignatures, candidatesOutArray, headMessage);
  17598. }
  17599. function getResolvedSignature(node, candidatesOutArray) {
  17600. var links = getNodeLinks(node);
  17601. if (!links.resolvedSignature || candidatesOutArray) {
  17602. links.resolvedSignature = anySignature;
  17603. if (node.kind === 168) {
  17604. links.resolvedSignature = resolveCallExpression(node, candidatesOutArray);
  17605. }
  17606. else if (node.kind === 169) {
  17607. links.resolvedSignature = resolveNewExpression(node, candidatesOutArray);
  17608. }
  17609. else if (node.kind === 170) {
  17610. links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray);
  17611. }
  17612. else if (node.kind === 139) {
  17613. links.resolvedSignature = resolveDecorator(node, candidatesOutArray);
  17614. }
  17615. else {
  17616. ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable.");
  17617. }
  17618. }
  17619. return links.resolvedSignature;
  17620. }
  17621. function checkCallExpression(node) {
  17622. checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments);
  17623. var signature = getResolvedSignature(node);
  17624. if (node.expression.kind === 95) {
  17625. return voidType;
  17626. }
  17627. if (node.kind === 169) {
  17628. var declaration = signature.declaration;
  17629. if (declaration &&
  17630. declaration.kind !== 144 &&
  17631. declaration.kind !== 148 &&
  17632. declaration.kind !== 153) {
  17633. if (compilerOptions.noImplicitAny) {
  17634. error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
  17635. }
  17636. return anyType;
  17637. }
  17638. }
  17639. return getReturnTypeOfSignature(signature);
  17640. }
  17641. function checkTaggedTemplateExpression(node) {
  17642. return getReturnTypeOfSignature(getResolvedSignature(node));
  17643. }
  17644. function checkAssertion(node) {
  17645. var exprType = getRegularTypeOfObjectLiteral(checkExpression(node.expression));
  17646. var targetType = getTypeFromTypeNode(node.type);
  17647. if (produceDiagnostics && targetType !== unknownType) {
  17648. var widenedType = getWidenedType(exprType);
  17649. if (!(isTypeAssignableTo(targetType, widenedType))) {
  17650. checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
  17651. }
  17652. }
  17653. return targetType;
  17654. }
  17655. function getTypeAtPosition(signature, pos) {
  17656. return signature.hasRestParameter ?
  17657. pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
  17658. pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
  17659. }
  17660. function assignContextualParameterTypes(signature, context, mapper) {
  17661. var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
  17662. for (var i = 0; i < len; i++) {
  17663. var parameter = signature.parameters[i];
  17664. var contextualParameterType = getTypeAtPosition(context, i);
  17665. assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper);
  17666. }
  17667. if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) {
  17668. var parameter = ts.lastOrUndefined(signature.parameters);
  17669. var contextualParameterType = getTypeOfSymbol(ts.lastOrUndefined(context.parameters));
  17670. assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper);
  17671. }
  17672. }
  17673. function assignBindingElementTypes(node) {
  17674. if (ts.isBindingPattern(node.name)) {
  17675. for (var _i = 0, _a = node.name.elements; _i < _a.length; _i++) {
  17676. var element = _a[_i];
  17677. if (element.kind !== 187) {
  17678. if (element.name.kind === 69) {
  17679. getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
  17680. }
  17681. assignBindingElementTypes(element);
  17682. }
  17683. }
  17684. }
  17685. }
  17686. function assignTypeToParameterAndFixTypeParameters(parameter, contextualType, mapper) {
  17687. var links = getSymbolLinks(parameter);
  17688. if (!links.type) {
  17689. links.type = instantiateType(contextualType, mapper);
  17690. assignBindingElementTypes(parameter.valueDeclaration);
  17691. }
  17692. else if (isInferentialContext(mapper)) {
  17693. inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper));
  17694. }
  17695. }
  17696. function createPromiseType(promisedType) {
  17697. var globalPromiseType = getGlobalPromiseType();
  17698. if (globalPromiseType !== emptyGenericType) {
  17699. promisedType = getAwaitedType(promisedType);
  17700. return createTypeReference(globalPromiseType, [promisedType]);
  17701. }
  17702. return emptyObjectType;
  17703. }
  17704. function getReturnTypeFromBody(func, contextualMapper) {
  17705. var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
  17706. if (!func.body) {
  17707. return unknownType;
  17708. }
  17709. var isAsync = ts.isAsyncFunctionLike(func);
  17710. var type;
  17711. if (func.body.kind !== 192) {
  17712. type = checkExpressionCached(func.body, contextualMapper);
  17713. if (isAsync) {
  17714. type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
  17715. }
  17716. }
  17717. else {
  17718. var types;
  17719. var funcIsGenerator = !!func.asteriskToken;
  17720. if (funcIsGenerator) {
  17721. types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper);
  17722. if (types.length === 0) {
  17723. var iterableIteratorAny = createIterableIteratorType(anyType);
  17724. if (compilerOptions.noImplicitAny) {
  17725. error(func.asteriskToken, ts.Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny));
  17726. }
  17727. return iterableIteratorAny;
  17728. }
  17729. }
  17730. else {
  17731. types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync);
  17732. if (types.length === 0) {
  17733. if (isAsync) {
  17734. var promiseType = createPromiseType(voidType);
  17735. if (promiseType === emptyObjectType) {
  17736. error(func, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
  17737. return unknownType;
  17738. }
  17739. return promiseType;
  17740. }
  17741. else {
  17742. return voidType;
  17743. }
  17744. }
  17745. }
  17746. type = contextualSignature ? getUnionType(types) : getCommonSupertype(types);
  17747. if (!type) {
  17748. if (funcIsGenerator) {
  17749. error(func, ts.Diagnostics.No_best_common_type_exists_among_yield_expressions);
  17750. return createIterableIteratorType(unknownType);
  17751. }
  17752. else {
  17753. error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions);
  17754. return unknownType;
  17755. }
  17756. }
  17757. if (funcIsGenerator) {
  17758. type = createIterableIteratorType(type);
  17759. }
  17760. }
  17761. if (!contextualSignature) {
  17762. reportErrorsFromWidening(func, type);
  17763. }
  17764. var widenedType = getWidenedType(type);
  17765. if (isAsync) {
  17766. var promiseType = createPromiseType(widenedType);
  17767. if (promiseType === emptyObjectType) {
  17768. error(func, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
  17769. return unknownType;
  17770. }
  17771. return promiseType;
  17772. }
  17773. else {
  17774. return widenedType;
  17775. }
  17776. }
  17777. function checkAndAggregateYieldOperandTypes(body, contextualMapper) {
  17778. var aggregatedTypes = [];
  17779. ts.forEachYieldExpression(body, function (yieldExpression) {
  17780. var expr = yieldExpression.expression;
  17781. if (expr) {
  17782. var type = checkExpressionCached(expr, contextualMapper);
  17783. if (yieldExpression.asteriskToken) {
  17784. type = checkElementTypeOfIterable(type, yieldExpression.expression);
  17785. }
  17786. if (!ts.contains(aggregatedTypes, type)) {
  17787. aggregatedTypes.push(type);
  17788. }
  17789. }
  17790. });
  17791. return aggregatedTypes;
  17792. }
  17793. function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync) {
  17794. var aggregatedTypes = [];
  17795. ts.forEachReturnStatement(body, function (returnStatement) {
  17796. var expr = returnStatement.expression;
  17797. if (expr) {
  17798. var type = checkExpressionCached(expr, contextualMapper);
  17799. if (isAsync) {
  17800. type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
  17801. }
  17802. if (!ts.contains(aggregatedTypes, type)) {
  17803. aggregatedTypes.push(type);
  17804. }
  17805. }
  17806. });
  17807. return aggregatedTypes;
  17808. }
  17809. function bodyContainsAReturnStatement(funcBody) {
  17810. return ts.forEachReturnStatement(funcBody, function (returnStatement) {
  17811. return true;
  17812. });
  17813. }
  17814. function bodyContainsSingleThrowStatement(body) {
  17815. return (body.statements.length === 1) && (body.statements[0].kind === 208);
  17816. }
  17817. function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) {
  17818. if (!produceDiagnostics) {
  17819. return;
  17820. }
  17821. if (returnType === voidType || isTypeAny(returnType)) {
  17822. return;
  17823. }
  17824. if (ts.nodeIsMissing(func.body) || func.body.kind !== 192) {
  17825. return;
  17826. }
  17827. var bodyBlock = func.body;
  17828. if (bodyContainsAReturnStatement(bodyBlock)) {
  17829. return;
  17830. }
  17831. if (bodyContainsSingleThrowStatement(bodyBlock)) {
  17832. return;
  17833. }
  17834. error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement);
  17835. }
  17836. function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) {
  17837. ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node));
  17838. var hasGrammarError = checkGrammarFunctionLikeDeclaration(node);
  17839. if (!hasGrammarError && node.kind === 173) {
  17840. checkGrammarForGenerator(node);
  17841. }
  17842. if (contextualMapper === identityMapper && isContextSensitive(node)) {
  17843. return anyFunctionType;
  17844. }
  17845. var isAsync = ts.isAsyncFunctionLike(node);
  17846. if (isAsync) {
  17847. emitAwaiter = true;
  17848. }
  17849. var links = getNodeLinks(node);
  17850. var type = getTypeOfSymbol(node.symbol);
  17851. var contextSensitive = isContextSensitive(node);
  17852. var mightFixTypeParameters = contextSensitive && isInferentialContext(contextualMapper);
  17853. if (mightFixTypeParameters || !(links.flags & 1024)) {
  17854. var contextualSignature = getContextualSignature(node);
  17855. var contextChecked = !!(links.flags & 1024);
  17856. if (mightFixTypeParameters || !contextChecked) {
  17857. links.flags |= 1024;
  17858. if (contextualSignature) {
  17859. var signature = getSignaturesOfType(type, 0)[0];
  17860. if (contextSensitive) {
  17861. assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper);
  17862. }
  17863. if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) {
  17864. var returnType = getReturnTypeFromBody(node, contextualMapper);
  17865. if (!signature.resolvedReturnType) {
  17866. signature.resolvedReturnType = returnType;
  17867. }
  17868. }
  17869. }
  17870. if (!contextChecked) {
  17871. checkSignatureDeclaration(node);
  17872. }
  17873. }
  17874. }
  17875. if (produceDiagnostics && node.kind !== 143 && node.kind !== 142) {
  17876. checkCollisionWithCapturedSuperVariable(node, node.name);
  17877. checkCollisionWithCapturedThisVariable(node, node.name);
  17878. }
  17879. return type;
  17880. }
  17881. function checkFunctionExpressionOrObjectLiteralMethodBody(node) {
  17882. ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node));
  17883. var isAsync = ts.isAsyncFunctionLike(node);
  17884. if (isAsync) {
  17885. emitAwaiter = true;
  17886. }
  17887. var returnType = node.type && getTypeFromTypeNode(node.type);
  17888. var promisedType;
  17889. if (returnType && isAsync) {
  17890. promisedType = checkAsyncFunctionReturnType(node);
  17891. }
  17892. if (returnType && !node.asteriskToken) {
  17893. checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType);
  17894. }
  17895. if (node.body) {
  17896. if (!node.type) {
  17897. getReturnTypeOfSignature(getSignatureFromDeclaration(node));
  17898. }
  17899. if (node.body.kind === 192) {
  17900. checkSourceElement(node.body);
  17901. }
  17902. else {
  17903. var exprType = checkExpression(node.body);
  17904. if (returnType) {
  17905. if (isAsync) {
  17906. var awaitedType = checkAwaitedType(exprType, node.body, ts.Diagnostics.Expression_body_for_async_arrow_function_does_not_have_a_valid_callable_then_member);
  17907. checkTypeAssignableTo(awaitedType, promisedType, node.body);
  17908. }
  17909. else {
  17910. checkTypeAssignableTo(exprType, returnType, node.body);
  17911. }
  17912. }
  17913. checkFunctionAndClassExpressionBodies(node.body);
  17914. }
  17915. }
  17916. }
  17917. function checkArithmeticOperandType(operand, type, diagnostic) {
  17918. if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132)) {
  17919. error(operand, diagnostic);
  17920. return false;
  17921. }
  17922. return true;
  17923. }
  17924. function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) {
  17925. function findSymbol(n) {
  17926. var symbol = getNodeLinks(n).resolvedSymbol;
  17927. return symbol && getExportSymbolOfValueSymbolIfExported(symbol);
  17928. }
  17929. function isReferenceOrErrorExpression(n) {
  17930. switch (n.kind) {
  17931. case 69: {
  17932. var symbol = findSymbol(n);
  17933. return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3) !== 0;
  17934. }
  17935. case 166: {
  17936. var symbol = findSymbol(n);
  17937. return !symbol || symbol === unknownSymbol || (symbol.flags & ~8) !== 0;
  17938. }
  17939. case 167:
  17940. return true;
  17941. case 172:
  17942. return isReferenceOrErrorExpression(n.expression);
  17943. default:
  17944. return false;
  17945. }
  17946. }
  17947. function isConstVariableReference(n) {
  17948. switch (n.kind) {
  17949. case 69:
  17950. case 166: {
  17951. var symbol = findSymbol(n);
  17952. return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 32768) !== 0;
  17953. }
  17954. case 167: {
  17955. var index = n.argumentExpression;
  17956. var symbol = findSymbol(n.expression);
  17957. if (symbol && index && index.kind === 9) {
  17958. var name_12 = index.text;
  17959. var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_12);
  17960. return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 32768) !== 0;
  17961. }
  17962. return false;
  17963. }
  17964. case 172:
  17965. return isConstVariableReference(n.expression);
  17966. default:
  17967. return false;
  17968. }
  17969. }
  17970. if (!isReferenceOrErrorExpression(n)) {
  17971. error(n, invalidReferenceMessage);
  17972. return false;
  17973. }
  17974. if (isConstVariableReference(n)) {
  17975. error(n, constantVariableMessage);
  17976. return false;
  17977. }
  17978. return true;
  17979. }
  17980. function checkDeleteExpression(node) {
  17981. checkExpression(node.expression);
  17982. return booleanType;
  17983. }
  17984. function checkTypeOfExpression(node) {
  17985. checkExpression(node.expression);
  17986. return stringType;
  17987. }
  17988. function checkVoidExpression(node) {
  17989. checkExpression(node.expression);
  17990. return undefinedType;
  17991. }
  17992. function checkAwaitExpression(node) {
  17993. if (produceDiagnostics) {
  17994. if (!(node.parserContextFlags & 8)) {
  17995. grammarErrorOnFirstToken(node, ts.Diagnostics.await_expression_is_only_allowed_within_an_async_function);
  17996. }
  17997. if (isInParameterInitializerBeforeContainingFunction(node)) {
  17998. error(node, ts.Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
  17999. }
  18000. }
  18001. var operandType = checkExpression(node.expression);
  18002. return checkAwaitedType(operandType, node);
  18003. }
  18004. function checkPrefixUnaryExpression(node) {
  18005. var operandType = checkExpression(node.operand);
  18006. switch (node.operator) {
  18007. case 35:
  18008. case 36:
  18009. case 50:
  18010. if (someConstituentTypeHasKind(operandType, 16777216)) {
  18011. error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator));
  18012. }
  18013. return numberType;
  18014. case 49:
  18015. return booleanType;
  18016. case 41:
  18017. case 42:
  18018. var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
  18019. if (ok) {
  18020. checkReferenceExpression(node.operand, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant);
  18021. }
  18022. return numberType;
  18023. }
  18024. return unknownType;
  18025. }
  18026. function checkPostfixUnaryExpression(node) {
  18027. var operandType = checkExpression(node.operand);
  18028. var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
  18029. if (ok) {
  18030. checkReferenceExpression(node.operand, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant);
  18031. }
  18032. return numberType;
  18033. }
  18034. function someConstituentTypeHasKind(type, kind) {
  18035. if (type.flags & kind) {
  18036. return true;
  18037. }
  18038. if (type.flags & 49152) {
  18039. var types = type.types;
  18040. for (var _i = 0; _i < types.length; _i++) {
  18041. var current = types[_i];
  18042. if (current.flags & kind) {
  18043. return true;
  18044. }
  18045. }
  18046. return false;
  18047. }
  18048. return false;
  18049. }
  18050. function allConstituentTypesHaveKind(type, kind) {
  18051. if (type.flags & kind) {
  18052. return true;
  18053. }
  18054. if (type.flags & 49152) {
  18055. var types = type.types;
  18056. for (var _i = 0; _i < types.length; _i++) {
  18057. var current = types[_i];
  18058. if (!(current.flags & kind)) {
  18059. return false;
  18060. }
  18061. }
  18062. return true;
  18063. }
  18064. return false;
  18065. }
  18066. function isConstEnumObjectType(type) {
  18067. return type.flags & (80896 | 65536) && type.symbol && isConstEnumSymbol(type.symbol);
  18068. }
  18069. function isConstEnumSymbol(symbol) {
  18070. return (symbol.flags & 128) !== 0;
  18071. }
  18072. function checkInstanceOfExpression(left, right, leftType, rightType) {
  18073. if (allConstituentTypesHaveKind(leftType, 16777726)) {
  18074. error(left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
  18075. }
  18076. if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
  18077. error(right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type);
  18078. }
  18079. return booleanType;
  18080. }
  18081. function checkInExpression(left, right, leftType, rightType) {
  18082. if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 16777216)) {
  18083. error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
  18084. }
  18085. if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 | 512)) {
  18086. error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
  18087. }
  18088. return booleanType;
  18089. }
  18090. function checkObjectLiteralAssignment(node, sourceType, contextualMapper) {
  18091. var properties = node.properties;
  18092. for (var _i = 0; _i < properties.length; _i++) {
  18093. var p = properties[_i];
  18094. if (p.kind === 245 || p.kind === 246) {
  18095. var name_13 = p.name;
  18096. var type = isTypeAny(sourceType)
  18097. ? sourceType
  18098. : getTypeOfPropertyOfType(sourceType, name_13.text) ||
  18099. isNumericLiteralName(name_13.text) && getIndexTypeOfType(sourceType, 1) ||
  18100. getIndexTypeOfType(sourceType, 0);
  18101. if (type) {
  18102. if (p.kind === 246) {
  18103. checkDestructuringAssignment(p, type);
  18104. }
  18105. else {
  18106. checkDestructuringAssignment(p.initializer || name_13, type);
  18107. }
  18108. }
  18109. else {
  18110. error(name_13, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_13));
  18111. }
  18112. }
  18113. else {
  18114. error(p, ts.Diagnostics.Property_assignment_expected);
  18115. }
  18116. }
  18117. return sourceType;
  18118. }
  18119. function checkArrayLiteralAssignment(node, sourceType, contextualMapper) {
  18120. var elementType = checkIteratedTypeOrElementType(sourceType, node, false) || unknownType;
  18121. var elements = node.elements;
  18122. for (var i = 0; i < elements.length; i++) {
  18123. var e = elements[i];
  18124. if (e.kind !== 187) {
  18125. if (e.kind !== 185) {
  18126. var propName = "" + i;
  18127. var type = isTypeAny(sourceType)
  18128. ? sourceType
  18129. : isTupleLikeType(sourceType)
  18130. ? getTypeOfPropertyOfType(sourceType, propName)
  18131. : elementType;
  18132. if (type) {
  18133. checkDestructuringAssignment(e, type, contextualMapper);
  18134. }
  18135. else {
  18136. if (isTupleType(sourceType)) {
  18137. error(e, ts.Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), sourceType.elementTypes.length, elements.length);
  18138. }
  18139. else {
  18140. error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName);
  18141. }
  18142. }
  18143. }
  18144. else {
  18145. if (i < elements.length - 1) {
  18146. error(e, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
  18147. }
  18148. else {
  18149. var restExpression = e.expression;
  18150. if (restExpression.kind === 181 && restExpression.operatorToken.kind === 56) {
  18151. error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer);
  18152. }
  18153. else {
  18154. checkDestructuringAssignment(restExpression, createArrayType(elementType), contextualMapper);
  18155. }
  18156. }
  18157. }
  18158. }
  18159. }
  18160. return sourceType;
  18161. }
  18162. function checkDestructuringAssignment(exprOrAssignment, sourceType, contextualMapper) {
  18163. var target;
  18164. if (exprOrAssignment.kind === 246) {
  18165. var prop = exprOrAssignment;
  18166. if (prop.objectAssignmentInitializer) {
  18167. checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper);
  18168. }
  18169. target = exprOrAssignment.name;
  18170. }
  18171. else {
  18172. target = exprOrAssignment;
  18173. }
  18174. if (target.kind === 181 && target.operatorToken.kind === 56) {
  18175. checkBinaryExpression(target, contextualMapper);
  18176. target = target.left;
  18177. }
  18178. if (target.kind === 165) {
  18179. return checkObjectLiteralAssignment(target, sourceType, contextualMapper);
  18180. }
  18181. if (target.kind === 164) {
  18182. return checkArrayLiteralAssignment(target, sourceType, contextualMapper);
  18183. }
  18184. return checkReferenceAssignment(target, sourceType, contextualMapper);
  18185. }
  18186. function checkReferenceAssignment(target, sourceType, contextualMapper) {
  18187. var targetType = checkExpression(target, contextualMapper);
  18188. if (checkReferenceExpression(target, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant)) {
  18189. checkTypeAssignableTo(sourceType, targetType, target, undefined);
  18190. }
  18191. return sourceType;
  18192. }
  18193. function checkBinaryExpression(node, contextualMapper) {
  18194. return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node);
  18195. }
  18196. function checkBinaryLikeExpression(left, operatorToken, right, contextualMapper, errorNode) {
  18197. var operator = operatorToken.kind;
  18198. if (operator === 56 && (left.kind === 165 || left.kind === 164)) {
  18199. return checkDestructuringAssignment(left, checkExpression(right, contextualMapper), contextualMapper);
  18200. }
  18201. var leftType = checkExpression(left, contextualMapper);
  18202. var rightType = checkExpression(right, contextualMapper);
  18203. switch (operator) {
  18204. case 37:
  18205. case 38:
  18206. case 59:
  18207. case 60:
  18208. case 39:
  18209. case 61:
  18210. case 40:
  18211. case 62:
  18212. case 36:
  18213. case 58:
  18214. case 43:
  18215. case 63:
  18216. case 44:
  18217. case 64:
  18218. case 45:
  18219. case 65:
  18220. case 47:
  18221. case 67:
  18222. case 48:
  18223. case 68:
  18224. case 46:
  18225. case 66:
  18226. if (leftType.flags & (32 | 64))
  18227. leftType = rightType;
  18228. if (rightType.flags & (32 | 64))
  18229. rightType = leftType;
  18230. var suggestedOperator;
  18231. if ((leftType.flags & 8) &&
  18232. (rightType.flags & 8) &&
  18233. (suggestedOperator = getSuggestedBooleanOperator(operatorToken.kind)) !== undefined) {
  18234. error(errorNode || operatorToken, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(operatorToken.kind), ts.tokenToString(suggestedOperator));
  18235. }
  18236. else {
  18237. var leftOk = checkArithmeticOperandType(left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
  18238. var rightOk = checkArithmeticOperandType(right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
  18239. if (leftOk && rightOk) {
  18240. checkAssignmentOperator(numberType);
  18241. }
  18242. }
  18243. return numberType;
  18244. case 35:
  18245. case 57:
  18246. if (leftType.flags & (32 | 64))
  18247. leftType = rightType;
  18248. if (rightType.flags & (32 | 64))
  18249. rightType = leftType;
  18250. var resultType;
  18251. if (allConstituentTypesHaveKind(leftType, 132) && allConstituentTypesHaveKind(rightType, 132)) {
  18252. resultType = numberType;
  18253. }
  18254. else {
  18255. if (allConstituentTypesHaveKind(leftType, 258) || allConstituentTypesHaveKind(rightType, 258)) {
  18256. resultType = stringType;
  18257. }
  18258. else if (isTypeAny(leftType) || isTypeAny(rightType)) {
  18259. resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType;
  18260. }
  18261. if (resultType && !checkForDisallowedESSymbolOperand(operator)) {
  18262. return resultType;
  18263. }
  18264. }
  18265. if (!resultType) {
  18266. reportOperatorError();
  18267. return anyType;
  18268. }
  18269. if (operator === 57) {
  18270. checkAssignmentOperator(resultType);
  18271. }
  18272. return resultType;
  18273. case 25:
  18274. case 27:
  18275. case 28:
  18276. case 29:
  18277. if (!checkForDisallowedESSymbolOperand(operator)) {
  18278. return booleanType;
  18279. }
  18280. case 30:
  18281. case 31:
  18282. case 32:
  18283. case 33:
  18284. if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) {
  18285. reportOperatorError();
  18286. }
  18287. return booleanType;
  18288. case 91:
  18289. return checkInstanceOfExpression(left, right, leftType, rightType);
  18290. case 90:
  18291. return checkInExpression(left, right, leftType, rightType);
  18292. case 51:
  18293. return rightType;
  18294. case 52:
  18295. return getUnionType([leftType, rightType]);
  18296. case 56:
  18297. checkAssignmentOperator(rightType);
  18298. return getRegularTypeOfObjectLiteral(rightType);
  18299. case 24:
  18300. return rightType;
  18301. }
  18302. function checkForDisallowedESSymbolOperand(operator) {
  18303. var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216) ? left :
  18304. someConstituentTypeHasKind(rightType, 16777216) ? right :
  18305. undefined;
  18306. if (offendingSymbolOperand) {
  18307. error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator));
  18308. return false;
  18309. }
  18310. return true;
  18311. }
  18312. function getSuggestedBooleanOperator(operator) {
  18313. switch (operator) {
  18314. case 47:
  18315. case 67:
  18316. return 52;
  18317. case 48:
  18318. case 68:
  18319. return 33;
  18320. case 46:
  18321. case 66:
  18322. return 51;
  18323. default:
  18324. return undefined;
  18325. }
  18326. }
  18327. function checkAssignmentOperator(valueType) {
  18328. if (produceDiagnostics && operator >= 56 && operator <= 68) {
  18329. var ok = checkReferenceExpression(left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant);
  18330. if (ok) {
  18331. checkTypeAssignableTo(valueType, leftType, left, undefined);
  18332. }
  18333. }
  18334. }
  18335. function reportOperatorError() {
  18336. error(errorNode || operatorToken, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType));
  18337. }
  18338. }
  18339. function isYieldExpressionInClass(node) {
  18340. var current = node;
  18341. var parent = node.parent;
  18342. while (parent) {
  18343. if (ts.isFunctionLike(parent) && current === parent.body) {
  18344. return false;
  18345. }
  18346. else if (ts.isClassLike(current)) {
  18347. return true;
  18348. }
  18349. current = parent;
  18350. parent = parent.parent;
  18351. }
  18352. return false;
  18353. }
  18354. function checkYieldExpression(node) {
  18355. if (produceDiagnostics) {
  18356. if (!(node.parserContextFlags & 2) || isYieldExpressionInClass(node)) {
  18357. grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
  18358. }
  18359. if (isInParameterInitializerBeforeContainingFunction(node)) {
  18360. error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
  18361. }
  18362. }
  18363. if (node.expression) {
  18364. var func = ts.getContainingFunction(node);
  18365. if (func && func.asteriskToken) {
  18366. var expressionType = checkExpressionCached(node.expression, undefined);
  18367. var expressionElementType;
  18368. var nodeIsYieldStar = !!node.asteriskToken;
  18369. if (nodeIsYieldStar) {
  18370. expressionElementType = checkElementTypeOfIterable(expressionType, node.expression);
  18371. }
  18372. if (func.type) {
  18373. var signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType;
  18374. if (nodeIsYieldStar) {
  18375. checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, undefined);
  18376. }
  18377. else {
  18378. checkTypeAssignableTo(expressionType, signatureElementType, node.expression, undefined);
  18379. }
  18380. }
  18381. }
  18382. }
  18383. return anyType;
  18384. }
  18385. function checkConditionalExpression(node, contextualMapper) {
  18386. checkExpression(node.condition);
  18387. var type1 = checkExpression(node.whenTrue, contextualMapper);
  18388. var type2 = checkExpression(node.whenFalse, contextualMapper);
  18389. return getUnionType([type1, type2]);
  18390. }
  18391. function checkTemplateExpression(node) {
  18392. ts.forEach(node.templateSpans, function (templateSpan) {
  18393. checkExpression(templateSpan.expression);
  18394. });
  18395. return stringType;
  18396. }
  18397. function checkExpressionWithContextualType(node, contextualType, contextualMapper) {
  18398. var saveContextualType = node.contextualType;
  18399. node.contextualType = contextualType;
  18400. var result = checkExpression(node, contextualMapper);
  18401. node.contextualType = saveContextualType;
  18402. return result;
  18403. }
  18404. function checkExpressionCached(node, contextualMapper) {
  18405. var links = getNodeLinks(node);
  18406. if (!links.resolvedType) {
  18407. links.resolvedType = checkExpression(node, contextualMapper);
  18408. }
  18409. return links.resolvedType;
  18410. }
  18411. function checkPropertyAssignment(node, contextualMapper) {
  18412. if (node.name.kind === 136) {
  18413. checkComputedPropertyName(node.name);
  18414. }
  18415. return checkExpression(node.initializer, contextualMapper);
  18416. }
  18417. function checkObjectLiteralMethod(node, contextualMapper) {
  18418. checkGrammarMethod(node);
  18419. if (node.name.kind === 136) {
  18420. checkComputedPropertyName(node.name);
  18421. }
  18422. var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper);
  18423. return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper);
  18424. }
  18425. function instantiateTypeWithSingleGenericCallSignature(node, type, contextualMapper) {
  18426. if (isInferentialContext(contextualMapper)) {
  18427. var signature = getSingleCallSignature(type);
  18428. if (signature && signature.typeParameters) {
  18429. var contextualType = getContextualType(node);
  18430. if (contextualType) {
  18431. var contextualSignature = getSingleCallSignature(contextualType);
  18432. if (contextualSignature && !contextualSignature.typeParameters) {
  18433. return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper));
  18434. }
  18435. }
  18436. }
  18437. }
  18438. return type;
  18439. }
  18440. function checkExpression(node, contextualMapper) {
  18441. var type;
  18442. if (node.kind === 135) {
  18443. type = checkQualifiedName(node);
  18444. }
  18445. else {
  18446. var uninstantiatedType = checkExpressionWorker(node, contextualMapper);
  18447. type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper);
  18448. }
  18449. if (isConstEnumObjectType(type)) {
  18450. var ok = (node.parent.kind === 166 && node.parent.expression === node) ||
  18451. (node.parent.kind === 167 && node.parent.expression === node) ||
  18452. ((node.kind === 69 || node.kind === 135) && isInRightSideOfImportOrExportAssignment(node));
  18453. if (!ok) {
  18454. error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment);
  18455. }
  18456. }
  18457. return type;
  18458. }
  18459. function checkNumericLiteral(node) {
  18460. checkGrammarNumericLiteral(node);
  18461. return numberType;
  18462. }
  18463. function checkExpressionWorker(node, contextualMapper) {
  18464. switch (node.kind) {
  18465. case 69:
  18466. return checkIdentifier(node);
  18467. case 97:
  18468. return checkThisExpression(node);
  18469. case 95:
  18470. return checkSuperExpression(node);
  18471. case 93:
  18472. return nullType;
  18473. case 99:
  18474. case 84:
  18475. return booleanType;
  18476. case 8:
  18477. return checkNumericLiteral(node);
  18478. case 183:
  18479. return checkTemplateExpression(node);
  18480. case 9:
  18481. case 11:
  18482. return stringType;
  18483. case 10:
  18484. return globalRegExpType;
  18485. case 164:
  18486. return checkArrayLiteral(node, contextualMapper);
  18487. case 165:
  18488. return checkObjectLiteral(node, contextualMapper);
  18489. case 166:
  18490. return checkPropertyAccessExpression(node);
  18491. case 167:
  18492. return checkIndexedAccess(node);
  18493. case 168:
  18494. case 169:
  18495. return checkCallExpression(node);
  18496. case 170:
  18497. return checkTaggedTemplateExpression(node);
  18498. case 172:
  18499. return checkExpression(node.expression, contextualMapper);
  18500. case 186:
  18501. return checkClassExpression(node);
  18502. case 173:
  18503. case 174:
  18504. return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper);
  18505. case 176:
  18506. return checkTypeOfExpression(node);
  18507. case 171:
  18508. case 189:
  18509. return checkAssertion(node);
  18510. case 175:
  18511. return checkDeleteExpression(node);
  18512. case 177:
  18513. return checkVoidExpression(node);
  18514. case 178:
  18515. return checkAwaitExpression(node);
  18516. case 179:
  18517. return checkPrefixUnaryExpression(node);
  18518. case 180:
  18519. return checkPostfixUnaryExpression(node);
  18520. case 181:
  18521. return checkBinaryExpression(node, contextualMapper);
  18522. case 182:
  18523. return checkConditionalExpression(node, contextualMapper);
  18524. case 185:
  18525. return checkSpreadElementExpression(node, contextualMapper);
  18526. case 187:
  18527. return undefinedType;
  18528. case 184:
  18529. return checkYieldExpression(node);
  18530. case 240:
  18531. return checkJsxExpression(node);
  18532. case 233:
  18533. return checkJsxElement(node);
  18534. case 234:
  18535. return checkJsxSelfClosingElement(node);
  18536. case 235:
  18537. ts.Debug.fail("Shouldn't ever directly check a JsxOpeningElement");
  18538. }
  18539. return unknownType;
  18540. }
  18541. function checkTypeParameter(node) {
  18542. if (node.expression) {
  18543. grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected);
  18544. }
  18545. checkSourceElement(node.constraint);
  18546. if (produceDiagnostics) {
  18547. checkTypeParameterHasIllegalReferencesInConstraint(node);
  18548. checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0);
  18549. }
  18550. }
  18551. function checkParameter(node) {
  18552. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  18553. checkVariableLikeDeclaration(node);
  18554. var func = ts.getContainingFunction(node);
  18555. if (node.flags & 112) {
  18556. func = ts.getContainingFunction(node);
  18557. if (!(func.kind === 144 && ts.nodeIsPresent(func.body))) {
  18558. error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
  18559. }
  18560. }
  18561. if (node.questionToken && ts.isBindingPattern(node.name) && func.body) {
  18562. error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
  18563. }
  18564. if (node.dotDotDotToken && !ts.isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) {
  18565. error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type);
  18566. }
  18567. }
  18568. function isSyntacticallyValidGenerator(node) {
  18569. if (!node.asteriskToken || !node.body) {
  18570. return false;
  18571. }
  18572. return node.kind === 143 ||
  18573. node.kind === 213 ||
  18574. node.kind === 173;
  18575. }
  18576. function getTypePredicateParameterIndex(parameterList, parameter) {
  18577. if (parameterList) {
  18578. for (var i = 0; i < parameterList.length; i++) {
  18579. var param = parameterList[i];
  18580. if (param.name.kind === 69 &&
  18581. param.name.text === parameter.text) {
  18582. return i;
  18583. }
  18584. }
  18585. }
  18586. return -1;
  18587. }
  18588. function isInLegalTypePredicatePosition(node) {
  18589. switch (node.parent.kind) {
  18590. case 174:
  18591. case 147:
  18592. case 213:
  18593. case 173:
  18594. case 152:
  18595. case 143:
  18596. case 142:
  18597. return node === node.parent.type;
  18598. }
  18599. return false;
  18600. }
  18601. function checkSignatureDeclaration(node) {
  18602. if (node.kind === 149) {
  18603. checkGrammarIndexSignature(node);
  18604. }
  18605. else if (node.kind === 152 || node.kind === 213 || node.kind === 153 ||
  18606. node.kind === 147 || node.kind === 144 ||
  18607. node.kind === 148) {
  18608. checkGrammarFunctionLikeDeclaration(node);
  18609. }
  18610. checkTypeParameters(node.typeParameters);
  18611. ts.forEach(node.parameters, checkParameter);
  18612. if (node.type) {
  18613. if (node.type.kind === 150) {
  18614. var typePredicate = getSignatureFromDeclaration(node).typePredicate;
  18615. var typePredicateNode = node.type;
  18616. if (isInLegalTypePredicatePosition(typePredicateNode)) {
  18617. if (typePredicate.parameterIndex >= 0) {
  18618. if (node.parameters[typePredicate.parameterIndex].dotDotDotToken) {
  18619. error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
  18620. }
  18621. else {
  18622. checkTypeAssignableTo(typePredicate.type, getTypeOfNode(node.parameters[typePredicate.parameterIndex]), typePredicateNode.type);
  18623. }
  18624. }
  18625. else if (typePredicateNode.parameterName) {
  18626. var hasReportedError = false;
  18627. for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
  18628. var param = _a[_i];
  18629. if (hasReportedError) {
  18630. break;
  18631. }
  18632. if (param.name.kind === 161 ||
  18633. param.name.kind === 162) {
  18634. (function checkBindingPattern(pattern) {
  18635. for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
  18636. var element = _a[_i];
  18637. if (element.name.kind === 69 &&
  18638. element.name.text === typePredicate.parameterName) {
  18639. error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName);
  18640. hasReportedError = true;
  18641. break;
  18642. }
  18643. else if (element.name.kind === 162 ||
  18644. element.name.kind === 161) {
  18645. checkBindingPattern(element.name);
  18646. }
  18647. }
  18648. })(param.name);
  18649. }
  18650. }
  18651. if (!hasReportedError) {
  18652. error(typePredicateNode.parameterName, ts.Diagnostics.Cannot_find_parameter_0, typePredicate.parameterName);
  18653. }
  18654. }
  18655. }
  18656. else {
  18657. error(typePredicateNode, ts.Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
  18658. }
  18659. }
  18660. else {
  18661. checkSourceElement(node.type);
  18662. }
  18663. }
  18664. if (produceDiagnostics) {
  18665. checkCollisionWithArgumentsInGeneratedCode(node);
  18666. if (compilerOptions.noImplicitAny && !node.type) {
  18667. switch (node.kind) {
  18668. case 148:
  18669. error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
  18670. break;
  18671. case 147:
  18672. error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
  18673. break;
  18674. }
  18675. }
  18676. if (node.type) {
  18677. if (languageVersion >= 2 && isSyntacticallyValidGenerator(node)) {
  18678. var returnType = getTypeFromTypeNode(node.type);
  18679. if (returnType === voidType) {
  18680. error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation);
  18681. }
  18682. else {
  18683. var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType;
  18684. var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType);
  18685. checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type);
  18686. }
  18687. }
  18688. }
  18689. }
  18690. checkSpecializedSignatureDeclaration(node);
  18691. }
  18692. function checkTypeForDuplicateIndexSignatures(node) {
  18693. if (node.kind === 215) {
  18694. var nodeSymbol = getSymbolOfNode(node);
  18695. if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) {
  18696. return;
  18697. }
  18698. }
  18699. var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
  18700. if (indexSymbol) {
  18701. var seenNumericIndexer = false;
  18702. var seenStringIndexer = false;
  18703. for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
  18704. var decl = _a[_i];
  18705. var declaration = decl;
  18706. if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
  18707. switch (declaration.parameters[0].type.kind) {
  18708. case 130:
  18709. if (!seenStringIndexer) {
  18710. seenStringIndexer = true;
  18711. }
  18712. else {
  18713. error(declaration, ts.Diagnostics.Duplicate_string_index_signature);
  18714. }
  18715. break;
  18716. case 128:
  18717. if (!seenNumericIndexer) {
  18718. seenNumericIndexer = true;
  18719. }
  18720. else {
  18721. error(declaration, ts.Diagnostics.Duplicate_number_index_signature);
  18722. }
  18723. break;
  18724. }
  18725. }
  18726. }
  18727. }
  18728. }
  18729. function checkPropertyDeclaration(node) {
  18730. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name);
  18731. checkVariableLikeDeclaration(node);
  18732. }
  18733. function checkMethodDeclaration(node) {
  18734. checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name);
  18735. checkFunctionLikeDeclaration(node);
  18736. if (node.flags & 256 && node.body) {
  18737. error(node, ts.Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, ts.declarationNameToString(node.name));
  18738. }
  18739. }
  18740. function checkConstructorDeclaration(node) {
  18741. checkSignatureDeclaration(node);
  18742. checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node);
  18743. checkSourceElement(node.body);
  18744. var symbol = getSymbolOfNode(node);
  18745. var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind);
  18746. if (node === firstDeclaration) {
  18747. checkFunctionOrConstructorSymbol(symbol);
  18748. }
  18749. if (ts.nodeIsMissing(node.body)) {
  18750. return;
  18751. }
  18752. if (!produceDiagnostics) {
  18753. return;
  18754. }
  18755. function isSuperCallExpression(n) {
  18756. return n.kind === 168 && n.expression.kind === 95;
  18757. }
  18758. function containsSuperCallAsComputedPropertyName(n) {
  18759. return n.name && containsSuperCall(n.name);
  18760. }
  18761. function containsSuperCall(n) {
  18762. if (isSuperCallExpression(n)) {
  18763. return true;
  18764. }
  18765. else if (ts.isFunctionLike(n)) {
  18766. return false;
  18767. }
  18768. else if (ts.isClassLike(n)) {
  18769. return ts.forEach(n.members, containsSuperCallAsComputedPropertyName);
  18770. }
  18771. return ts.forEachChild(n, containsSuperCall);
  18772. }
  18773. function markThisReferencesAsErrors(n) {
  18774. if (n.kind === 97) {
  18775. error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
  18776. }
  18777. else if (n.kind !== 173 && n.kind !== 213) {
  18778. ts.forEachChild(n, markThisReferencesAsErrors);
  18779. }
  18780. }
  18781. function isInstancePropertyWithInitializer(n) {
  18782. return n.kind === 141 &&
  18783. !(n.flags & 128) &&
  18784. !!n.initializer;
  18785. }
  18786. var containingClassDecl = node.parent;
  18787. if (ts.getClassExtendsHeritageClauseElement(containingClassDecl)) {
  18788. var containingClassSymbol = getSymbolOfNode(containingClassDecl);
  18789. var containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol);
  18790. var baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType);
  18791. if (containsSuperCall(node.body)) {
  18792. if (baseConstructorType === nullType) {
  18793. error(node, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
  18794. }
  18795. var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) ||
  18796. ts.forEach(node.parameters, function (p) { return p.flags & (16 | 32 | 64); });
  18797. if (superCallShouldBeFirst) {
  18798. var statements = node.body.statements;
  18799. var superCallStatement;
  18800. for (var _i = 0; _i < statements.length; _i++) {
  18801. var statement = statements[_i];
  18802. if (statement.kind === 195 && isSuperCallExpression(statement.expression)) {
  18803. superCallStatement = statement;
  18804. break;
  18805. }
  18806. if (!ts.isPrologueDirective(statement)) {
  18807. break;
  18808. }
  18809. }
  18810. if (!superCallStatement) {
  18811. error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
  18812. }
  18813. else {
  18814. markThisReferencesAsErrors(superCallStatement.expression);
  18815. }
  18816. }
  18817. }
  18818. else if (baseConstructorType !== nullType) {
  18819. error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
  18820. }
  18821. }
  18822. }
  18823. function checkAccessorDeclaration(node) {
  18824. if (produceDiagnostics) {
  18825. checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name);
  18826. if (node.kind === 145) {
  18827. if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) {
  18828. error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement);
  18829. }
  18830. }
  18831. if (!ts.hasDynamicName(node)) {
  18832. var otherKind = node.kind === 145 ? 146 : 145;
  18833. var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind);
  18834. if (otherAccessor) {
  18835. if (((node.flags & 112) !== (otherAccessor.flags & 112))) {
  18836. error(node.name, ts.Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility);
  18837. }
  18838. var currentAccessorType = getAnnotatedAccessorType(node);
  18839. var otherAccessorType = getAnnotatedAccessorType(otherAccessor);
  18840. if (currentAccessorType && otherAccessorType) {
  18841. if (!isTypeIdenticalTo(currentAccessorType, otherAccessorType)) {
  18842. error(node, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type);
  18843. }
  18844. }
  18845. }
  18846. }
  18847. getTypeOfAccessors(getSymbolOfNode(node));
  18848. }
  18849. checkFunctionLikeDeclaration(node);
  18850. }
  18851. function checkMissingDeclaration(node) {
  18852. checkDecorators(node);
  18853. }
  18854. function checkTypeArgumentConstraints(typeParameters, typeArguments) {
  18855. var result = true;
  18856. for (var i = 0; i < typeParameters.length; i++) {
  18857. var constraint = getConstraintOfTypeParameter(typeParameters[i]);
  18858. if (constraint) {
  18859. var typeArgument = typeArguments[i];
  18860. result = result && checkTypeAssignableTo(getTypeFromTypeNode(typeArgument), constraint, typeArgument, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
  18861. }
  18862. }
  18863. return result;
  18864. }
  18865. function checkTypeReferenceNode(node) {
  18866. checkGrammarTypeArguments(node, node.typeArguments);
  18867. var type = getTypeFromTypeReference(node);
  18868. if (type !== unknownType && node.typeArguments) {
  18869. ts.forEach(node.typeArguments, checkSourceElement);
  18870. if (produceDiagnostics) {
  18871. var symbol = getNodeLinks(node).resolvedSymbol;
  18872. var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters;
  18873. checkTypeArgumentConstraints(typeParameters, node.typeArguments);
  18874. }
  18875. }
  18876. }
  18877. function checkTypeQuery(node) {
  18878. getTypeFromTypeQueryNode(node);
  18879. }
  18880. function checkTypeLiteral(node) {
  18881. ts.forEach(node.members, checkSourceElement);
  18882. if (produceDiagnostics) {
  18883. var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
  18884. checkIndexConstraints(type);
  18885. checkTypeForDuplicateIndexSignatures(node);
  18886. }
  18887. }
  18888. function checkArrayType(node) {
  18889. checkSourceElement(node.elementType);
  18890. }
  18891. function checkTupleType(node) {
  18892. var hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes);
  18893. if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) {
  18894. grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty);
  18895. }
  18896. ts.forEach(node.elementTypes, checkSourceElement);
  18897. }
  18898. function checkUnionOrIntersectionType(node) {
  18899. ts.forEach(node.types, checkSourceElement);
  18900. }
  18901. function isPrivateWithinAmbient(node) {
  18902. return (node.flags & 32) && ts.isInAmbientContext(node);
  18903. }
  18904. function checkSpecializedSignatureDeclaration(signatureDeclarationNode) {
  18905. if (!produceDiagnostics) {
  18906. return;
  18907. }
  18908. var signature = getSignatureFromDeclaration(signatureDeclarationNode);
  18909. if (!signature.hasStringLiterals) {
  18910. return;
  18911. }
  18912. if (ts.nodeIsPresent(signatureDeclarationNode.body)) {
  18913. error(signatureDeclarationNode, ts.Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type);
  18914. return;
  18915. }
  18916. var signaturesToCheck;
  18917. if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 215) {
  18918. ts.Debug.assert(signatureDeclarationNode.kind === 147 || signatureDeclarationNode.kind === 148);
  18919. var signatureKind = signatureDeclarationNode.kind === 147 ? 0 : 1;
  18920. var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent);
  18921. var containingType = getDeclaredTypeOfSymbol(containingSymbol);
  18922. signaturesToCheck = getSignaturesOfType(containingType, signatureKind);
  18923. }
  18924. else {
  18925. signaturesToCheck = getSignaturesOfSymbol(getSymbolOfNode(signatureDeclarationNode));
  18926. }
  18927. for (var _i = 0; _i < signaturesToCheck.length; _i++) {
  18928. var otherSignature = signaturesToCheck[_i];
  18929. if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) {
  18930. return;
  18931. }
  18932. }
  18933. error(signatureDeclarationNode, ts.Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature);
  18934. }
  18935. function getEffectiveDeclarationFlags(n, flagsToCheck) {
  18936. var flags = ts.getCombinedNodeFlags(n);
  18937. if (n.parent.kind !== 215 &&
  18938. n.parent.kind !== 214 &&
  18939. n.parent.kind !== 186 &&
  18940. ts.isInAmbientContext(n)) {
  18941. if (!(flags & 2)) {
  18942. flags |= 1;
  18943. }
  18944. flags |= 2;
  18945. }
  18946. return flags & flagsToCheck;
  18947. }
  18948. function checkFunctionOrConstructorSymbol(symbol) {
  18949. if (!produceDiagnostics) {
  18950. return;
  18951. }
  18952. function getCanonicalOverload(overloads, implementation) {
  18953. var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent;
  18954. return implementationSharesContainerWithFirstOverload ? implementation : overloads[0];
  18955. }
  18956. function checkFlagAgreementBetweenOverloads(overloads, implementation, flagsToCheck, someOverloadFlags, allOverloadFlags) {
  18957. var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags;
  18958. if (someButNotAllOverloadFlags !== 0) {
  18959. var canonicalFlags = getEffectiveDeclarationFlags(getCanonicalOverload(overloads, implementation), flagsToCheck);
  18960. ts.forEach(overloads, function (o) {
  18961. var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags;
  18962. if (deviation & 1) {
  18963. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported);
  18964. }
  18965. else if (deviation & 2) {
  18966. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
  18967. }
  18968. else if (deviation & (32 | 64)) {
  18969. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
  18970. }
  18971. else if (deviation & 256) {
  18972. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract);
  18973. }
  18974. });
  18975. }
  18976. }
  18977. function checkQuestionTokenAgreementBetweenOverloads(overloads, implementation, someHaveQuestionToken, allHaveQuestionToken) {
  18978. if (someHaveQuestionToken !== allHaveQuestionToken) {
  18979. var canonicalHasQuestionToken = ts.hasQuestionToken(getCanonicalOverload(overloads, implementation));
  18980. ts.forEach(overloads, function (o) {
  18981. var deviation = ts.hasQuestionToken(o) !== canonicalHasQuestionToken;
  18982. if (deviation) {
  18983. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_optional_or_required);
  18984. }
  18985. });
  18986. }
  18987. }
  18988. var flagsToCheck = 1 | 2 | 32 | 64 | 256;
  18989. var someNodeFlags = 0;
  18990. var allNodeFlags = flagsToCheck;
  18991. var someHaveQuestionToken = false;
  18992. var allHaveQuestionToken = true;
  18993. var hasOverloads = false;
  18994. var bodyDeclaration;
  18995. var lastSeenNonAmbientDeclaration;
  18996. var previousDeclaration;
  18997. var declarations = symbol.declarations;
  18998. var isConstructor = (symbol.flags & 16384) !== 0;
  18999. function reportImplementationExpectedError(node) {
  19000. if (node.name && ts.nodeIsMissing(node.name)) {
  19001. return;
  19002. }
  19003. var seen = false;
  19004. var subsequentNode = ts.forEachChild(node.parent, function (c) {
  19005. if (seen) {
  19006. return c;
  19007. }
  19008. else {
  19009. seen = c === node;
  19010. }
  19011. });
  19012. if (subsequentNode) {
  19013. if (subsequentNode.kind === node.kind) {
  19014. var errorNode_1 = subsequentNode.name || subsequentNode;
  19015. if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) {
  19016. var reportError = (node.kind === 143 || node.kind === 142) &&
  19017. (node.flags & 128) !== (subsequentNode.flags & 128);
  19018. if (reportError) {
  19019. var diagnostic = node.flags & 128 ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static;
  19020. error(errorNode_1, diagnostic);
  19021. }
  19022. return;
  19023. }
  19024. else if (ts.nodeIsPresent(subsequentNode.body)) {
  19025. error(errorNode_1, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name));
  19026. return;
  19027. }
  19028. }
  19029. }
  19030. var errorNode = node.name || node;
  19031. if (isConstructor) {
  19032. error(errorNode, ts.Diagnostics.Constructor_implementation_is_missing);
  19033. }
  19034. else {
  19035. if (node.flags & 256) {
  19036. error(errorNode, ts.Diagnostics.All_declarations_of_an_abstract_method_must_be_consecutive);
  19037. }
  19038. else {
  19039. error(errorNode, ts.Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration);
  19040. }
  19041. }
  19042. }
  19043. var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & 1536;
  19044. var duplicateFunctionDeclaration = false;
  19045. var multipleConstructorImplementation = false;
  19046. for (var _i = 0; _i < declarations.length; _i++) {
  19047. var current = declarations[_i];
  19048. var node = current;
  19049. var inAmbientContext = ts.isInAmbientContext(node);
  19050. var inAmbientContextOrInterface = node.parent.kind === 215 || node.parent.kind === 155 || inAmbientContext;
  19051. if (inAmbientContextOrInterface) {
  19052. previousDeclaration = undefined;
  19053. }
  19054. if (node.kind === 213 || node.kind === 143 || node.kind === 142 || node.kind === 144) {
  19055. var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
  19056. someNodeFlags |= currentNodeFlags;
  19057. allNodeFlags &= currentNodeFlags;
  19058. someHaveQuestionToken = someHaveQuestionToken || ts.hasQuestionToken(node);
  19059. allHaveQuestionToken = allHaveQuestionToken && ts.hasQuestionToken(node);
  19060. if (ts.nodeIsPresent(node.body) && bodyDeclaration) {
  19061. if (isConstructor) {
  19062. multipleConstructorImplementation = true;
  19063. }
  19064. else {
  19065. duplicateFunctionDeclaration = true;
  19066. }
  19067. }
  19068. else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
  19069. reportImplementationExpectedError(previousDeclaration);
  19070. }
  19071. if (ts.nodeIsPresent(node.body)) {
  19072. if (!bodyDeclaration) {
  19073. bodyDeclaration = node;
  19074. }
  19075. }
  19076. else {
  19077. hasOverloads = true;
  19078. }
  19079. previousDeclaration = node;
  19080. if (!inAmbientContextOrInterface) {
  19081. lastSeenNonAmbientDeclaration = node;
  19082. }
  19083. }
  19084. }
  19085. if (multipleConstructorImplementation) {
  19086. ts.forEach(declarations, function (declaration) {
  19087. error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed);
  19088. });
  19089. }
  19090. if (duplicateFunctionDeclaration) {
  19091. ts.forEach(declarations, function (declaration) {
  19092. error(declaration.name, ts.Diagnostics.Duplicate_function_implementation);
  19093. });
  19094. }
  19095. if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
  19096. !(lastSeenNonAmbientDeclaration.flags & 256)) {
  19097. reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
  19098. }
  19099. if (hasOverloads) {
  19100. checkFlagAgreementBetweenOverloads(declarations, bodyDeclaration, flagsToCheck, someNodeFlags, allNodeFlags);
  19101. checkQuestionTokenAgreementBetweenOverloads(declarations, bodyDeclaration, someHaveQuestionToken, allHaveQuestionToken);
  19102. if (bodyDeclaration) {
  19103. var signatures = getSignaturesOfSymbol(symbol);
  19104. var bodySignature = getSignatureFromDeclaration(bodyDeclaration);
  19105. if (!bodySignature.hasStringLiterals) {
  19106. for (var _a = 0; _a < signatures.length; _a++) {
  19107. var signature = signatures[_a];
  19108. if (!signature.hasStringLiterals && !isSignatureAssignableTo(bodySignature, signature)) {
  19109. error(signature.declaration, ts.Diagnostics.Overload_signature_is_not_compatible_with_function_implementation);
  19110. break;
  19111. }
  19112. }
  19113. }
  19114. }
  19115. }
  19116. }
  19117. function checkExportsOnMergedDeclarations(node) {
  19118. if (!produceDiagnostics) {
  19119. return;
  19120. }
  19121. var symbol = node.localSymbol;
  19122. if (!symbol) {
  19123. symbol = getSymbolOfNode(node);
  19124. if (!(symbol.flags & 7340032)) {
  19125. return;
  19126. }
  19127. }
  19128. if (ts.getDeclarationOfKind(symbol, node.kind) !== node) {
  19129. return;
  19130. }
  19131. var exportedDeclarationSpaces = 0;
  19132. var nonExportedDeclarationSpaces = 0;
  19133. var defaultExportedDeclarationSpaces = 0;
  19134. for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
  19135. var d = _a[_i];
  19136. var declarationSpaces = getDeclarationSpaces(d);
  19137. var effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, 1 | 1024);
  19138. if (effectiveDeclarationFlags & 1) {
  19139. if (effectiveDeclarationFlags & 1024) {
  19140. defaultExportedDeclarationSpaces |= declarationSpaces;
  19141. }
  19142. else {
  19143. exportedDeclarationSpaces |= declarationSpaces;
  19144. }
  19145. }
  19146. else {
  19147. nonExportedDeclarationSpaces |= declarationSpaces;
  19148. }
  19149. }
  19150. var nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces;
  19151. var commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
  19152. var commonDeclarationSpacesForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces;
  19153. if (commonDeclarationSpacesForExportsAndLocals || commonDeclarationSpacesForDefaultAndNonDefault) {
  19154. for (var _b = 0, _c = symbol.declarations; _b < _c.length; _b++) {
  19155. var d = _c[_b];
  19156. var declarationSpaces = getDeclarationSpaces(d);
  19157. if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) {
  19158. error(d.name, ts.Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead, ts.declarationNameToString(d.name));
  19159. }
  19160. else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) {
  19161. error(d.name, ts.Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, ts.declarationNameToString(d.name));
  19162. }
  19163. }
  19164. }
  19165. function getDeclarationSpaces(d) {
  19166. switch (d.kind) {
  19167. case 215:
  19168. return 2097152;
  19169. case 218:
  19170. return d.name.kind === 9 || ts.getModuleInstanceState(d) !== 0
  19171. ? 4194304 | 1048576
  19172. : 4194304;
  19173. case 214:
  19174. case 217:
  19175. return 2097152 | 1048576;
  19176. case 221:
  19177. var result = 0;
  19178. var target = resolveAlias(getSymbolOfNode(d));
  19179. ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); });
  19180. return result;
  19181. default:
  19182. return 1048576;
  19183. }
  19184. }
  19185. }
  19186. function checkNonThenableType(type, location, message) {
  19187. type = getWidenedType(type);
  19188. if (!isTypeAny(type) && isTypeAssignableTo(type, getGlobalThenableType())) {
  19189. if (location) {
  19190. if (!message) {
  19191. message = ts.Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member;
  19192. }
  19193. error(location, message);
  19194. }
  19195. return unknownType;
  19196. }
  19197. return type;
  19198. }
  19199. function getPromisedType(promise) {
  19200. if (promise.flags & 1) {
  19201. return undefined;
  19202. }
  19203. if ((promise.flags & 4096) && promise.target === tryGetGlobalPromiseType()) {
  19204. return promise.typeArguments[0];
  19205. }
  19206. var globalPromiseLikeType = getInstantiatedGlobalPromiseLikeType();
  19207. if (globalPromiseLikeType === emptyObjectType || !isTypeAssignableTo(promise, globalPromiseLikeType)) {
  19208. return undefined;
  19209. }
  19210. var thenFunction = getTypeOfPropertyOfType(promise, "then");
  19211. if (thenFunction && (thenFunction.flags & 1)) {
  19212. return undefined;
  19213. }
  19214. var thenSignatures = thenFunction ? getSignaturesOfType(thenFunction, 0) : emptyArray;
  19215. if (thenSignatures.length === 0) {
  19216. return undefined;
  19217. }
  19218. var onfulfilledParameterType = getUnionType(ts.map(thenSignatures, getTypeOfFirstParameterOfSignature));
  19219. if (onfulfilledParameterType.flags & 1) {
  19220. return undefined;
  19221. }
  19222. var onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, 0);
  19223. if (onfulfilledParameterSignatures.length === 0) {
  19224. return undefined;
  19225. }
  19226. var valueParameterType = getUnionType(ts.map(onfulfilledParameterSignatures, getTypeOfFirstParameterOfSignature));
  19227. return valueParameterType;
  19228. }
  19229. function getTypeOfFirstParameterOfSignature(signature) {
  19230. return getTypeAtPosition(signature, 0);
  19231. }
  19232. function getAwaitedType(type) {
  19233. return checkAwaitedType(type, undefined, undefined);
  19234. }
  19235. function checkAwaitedType(type, location, message) {
  19236. return checkAwaitedTypeWorker(type);
  19237. function checkAwaitedTypeWorker(type) {
  19238. if (type.flags & 16384) {
  19239. var types = [];
  19240. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  19241. var constituentType = _a[_i];
  19242. types.push(checkAwaitedTypeWorker(constituentType));
  19243. }
  19244. return getUnionType(types);
  19245. }
  19246. else {
  19247. var promisedType = getPromisedType(type);
  19248. if (promisedType === undefined) {
  19249. return checkNonThenableType(type, location, message);
  19250. }
  19251. else {
  19252. if (type.id === promisedType.id || awaitedTypeStack.indexOf(promisedType.id) >= 0) {
  19253. if (location) {
  19254. error(location, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method, symbolToString(type.symbol));
  19255. }
  19256. return unknownType;
  19257. }
  19258. awaitedTypeStack.push(type.id);
  19259. var awaitedType = checkAwaitedTypeWorker(promisedType);
  19260. awaitedTypeStack.pop();
  19261. return awaitedType;
  19262. }
  19263. }
  19264. }
  19265. }
  19266. function checkAsyncFunctionReturnType(node) {
  19267. var globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType();
  19268. if (globalPromiseConstructorLikeType === emptyObjectType) {
  19269. return unknownType;
  19270. }
  19271. var promiseType = getTypeFromTypeNode(node.type);
  19272. if (promiseType === unknownType && compilerOptions.isolatedModules) {
  19273. return unknownType;
  19274. }
  19275. var promiseConstructor = getNodeLinks(node.type).resolvedSymbol;
  19276. if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
  19277. var typeName = promiseConstructor
  19278. ? symbolToString(promiseConstructor)
  19279. : typeToString(promiseType);
  19280. error(node, ts.Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName);
  19281. return unknownType;
  19282. }
  19283. var promiseConstructorType = getTypeOfSymbol(promiseConstructor);
  19284. if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node, ts.Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
  19285. return unknownType;
  19286. }
  19287. var promiseName = ts.getEntityNameFromTypeNode(node.type);
  19288. var root = getFirstIdentifier(promiseName);
  19289. var rootSymbol = getSymbol(node.locals, root.text, 107455);
  19290. if (rootSymbol) {
  19291. error(rootSymbol.valueDeclaration, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, root.text, getFullyQualifiedName(promiseConstructor));
  19292. return unknownType;
  19293. }
  19294. return checkAwaitedType(promiseType, node, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
  19295. }
  19296. function checkDecorator(node) {
  19297. var signature = getResolvedSignature(node);
  19298. var returnType = getReturnTypeOfSignature(signature);
  19299. if (returnType.flags & 1) {
  19300. return;
  19301. }
  19302. var expectedReturnType;
  19303. var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
  19304. var errorInfo;
  19305. switch (node.parent.kind) {
  19306. case 214:
  19307. var classSymbol = getSymbolOfNode(node.parent);
  19308. var classConstructorType = getTypeOfSymbol(classSymbol);
  19309. expectedReturnType = getUnionType([classConstructorType, voidType]);
  19310. break;
  19311. case 138:
  19312. expectedReturnType = voidType;
  19313. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
  19314. break;
  19315. case 141:
  19316. expectedReturnType = voidType;
  19317. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
  19318. break;
  19319. case 143:
  19320. case 145:
  19321. case 146:
  19322. var methodType = getTypeOfNode(node.parent);
  19323. var descriptorType = createTypedPropertyDescriptorType(methodType);
  19324. expectedReturnType = getUnionType([descriptorType, voidType]);
  19325. break;
  19326. }
  19327. checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo);
  19328. }
  19329. function checkTypeNodeAsExpression(node) {
  19330. if (node && node.kind === 151) {
  19331. var root = getFirstIdentifier(node.typeName);
  19332. var meaning = root.parent.kind === 151 ? 793056 : 1536;
  19333. var rootSymbol = resolveName(root, root.text, meaning | 8388608, undefined, undefined);
  19334. if (rootSymbol && rootSymbol.flags & 8388608) {
  19335. var aliasTarget = resolveAlias(rootSymbol);
  19336. if (aliasTarget.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(resolveAlias(rootSymbol))) {
  19337. markAliasSymbolAsReferenced(rootSymbol);
  19338. }
  19339. }
  19340. }
  19341. }
  19342. function checkTypeAnnotationAsExpression(node) {
  19343. switch (node.kind) {
  19344. case 141:
  19345. checkTypeNodeAsExpression(node.type);
  19346. break;
  19347. case 138:
  19348. checkTypeNodeAsExpression(node.type);
  19349. break;
  19350. case 143:
  19351. checkTypeNodeAsExpression(node.type);
  19352. break;
  19353. case 145:
  19354. checkTypeNodeAsExpression(node.type);
  19355. break;
  19356. case 146:
  19357. checkTypeNodeAsExpression(ts.getSetAccessorTypeAnnotationNode(node));
  19358. break;
  19359. }
  19360. }
  19361. function checkParameterTypeAnnotationsAsExpressions(node) {
  19362. for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
  19363. var parameter = _a[_i];
  19364. checkTypeAnnotationAsExpression(parameter);
  19365. }
  19366. }
  19367. function checkDecorators(node) {
  19368. if (!node.decorators) {
  19369. return;
  19370. }
  19371. if (!ts.nodeCanBeDecorated(node)) {
  19372. return;
  19373. }
  19374. if (!compilerOptions.experimentalDecorators) {
  19375. error(node, ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning);
  19376. }
  19377. if (compilerOptions.emitDecoratorMetadata) {
  19378. switch (node.kind) {
  19379. case 214:
  19380. var constructor = ts.getFirstConstructorWithBody(node);
  19381. if (constructor) {
  19382. checkParameterTypeAnnotationsAsExpressions(constructor);
  19383. }
  19384. break;
  19385. case 143:
  19386. checkParameterTypeAnnotationsAsExpressions(node);
  19387. case 146:
  19388. case 145:
  19389. case 141:
  19390. case 138:
  19391. checkTypeAnnotationAsExpression(node);
  19392. break;
  19393. }
  19394. }
  19395. emitDecorate = true;
  19396. if (node.kind === 138) {
  19397. emitParam = true;
  19398. }
  19399. ts.forEach(node.decorators, checkDecorator);
  19400. }
  19401. function checkFunctionDeclaration(node) {
  19402. if (produceDiagnostics) {
  19403. checkFunctionLikeDeclaration(node) || checkGrammarForGenerator(node);
  19404. checkCollisionWithCapturedSuperVariable(node, node.name);
  19405. checkCollisionWithCapturedThisVariable(node, node.name);
  19406. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  19407. }
  19408. }
  19409. function checkFunctionLikeDeclaration(node) {
  19410. checkDecorators(node);
  19411. checkSignatureDeclaration(node);
  19412. var isAsync = ts.isAsyncFunctionLike(node);
  19413. if (isAsync) {
  19414. emitAwaiter = true;
  19415. }
  19416. if (node.name && node.name.kind === 136) {
  19417. checkComputedPropertyName(node.name);
  19418. }
  19419. if (!ts.hasDynamicName(node)) {
  19420. var symbol = getSymbolOfNode(node);
  19421. var localSymbol = node.localSymbol || symbol;
  19422. var firstDeclaration = ts.getDeclarationOfKind(localSymbol, node.kind);
  19423. if (node === firstDeclaration) {
  19424. checkFunctionOrConstructorSymbol(localSymbol);
  19425. }
  19426. if (symbol.parent) {
  19427. if (ts.getDeclarationOfKind(symbol, node.kind) === node) {
  19428. checkFunctionOrConstructorSymbol(symbol);
  19429. }
  19430. }
  19431. }
  19432. checkSourceElement(node.body);
  19433. if (node.type && !isAccessor(node.kind) && !node.asteriskToken) {
  19434. var returnType = getTypeFromTypeNode(node.type);
  19435. var promisedType;
  19436. if (isAsync) {
  19437. promisedType = checkAsyncFunctionReturnType(node);
  19438. }
  19439. checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType);
  19440. }
  19441. if (produceDiagnostics && !node.type) {
  19442. if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) {
  19443. reportImplicitAnyError(node, anyType);
  19444. }
  19445. if (node.asteriskToken && ts.nodeIsPresent(node.body)) {
  19446. getReturnTypeOfSignature(getSignatureFromDeclaration(node));
  19447. }
  19448. }
  19449. }
  19450. function checkBlock(node) {
  19451. if (node.kind === 192) {
  19452. checkGrammarStatementInAmbientContext(node);
  19453. }
  19454. ts.forEach(node.statements, checkSourceElement);
  19455. if (ts.isFunctionBlock(node) || node.kind === 219) {
  19456. checkFunctionAndClassExpressionBodies(node);
  19457. }
  19458. }
  19459. function checkCollisionWithArgumentsInGeneratedCode(node) {
  19460. if (!ts.hasRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) {
  19461. return;
  19462. }
  19463. ts.forEach(node.parameters, function (p) {
  19464. if (p.name && !ts.isBindingPattern(p.name) && p.name.text === argumentsSymbol.name) {
  19465. error(p, ts.Diagnostics.Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters);
  19466. }
  19467. });
  19468. }
  19469. function needCollisionCheckForIdentifier(node, identifier, name) {
  19470. if (!(identifier && identifier.text === name)) {
  19471. return false;
  19472. }
  19473. if (node.kind === 141 ||
  19474. node.kind === 140 ||
  19475. node.kind === 143 ||
  19476. node.kind === 142 ||
  19477. node.kind === 145 ||
  19478. node.kind === 146) {
  19479. return false;
  19480. }
  19481. if (ts.isInAmbientContext(node)) {
  19482. return false;
  19483. }
  19484. var root = ts.getRootDeclaration(node);
  19485. if (root.kind === 138 && ts.nodeIsMissing(root.parent.body)) {
  19486. return false;
  19487. }
  19488. return true;
  19489. }
  19490. function checkCollisionWithCapturedThisVariable(node, name) {
  19491. if (needCollisionCheckForIdentifier(node, name, "_this")) {
  19492. potentialThisCollisions.push(node);
  19493. }
  19494. }
  19495. function checkIfThisIsCapturedInEnclosingScope(node) {
  19496. var current = node;
  19497. while (current) {
  19498. if (getNodeCheckFlags(current) & 4) {
  19499. var isDeclaration_1 = node.kind !== 69;
  19500. if (isDeclaration_1) {
  19501. error(node.name, ts.Diagnostics.Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference);
  19502. }
  19503. else {
  19504. error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference);
  19505. }
  19506. return;
  19507. }
  19508. current = current.parent;
  19509. }
  19510. }
  19511. function checkCollisionWithCapturedSuperVariable(node, name) {
  19512. if (!needCollisionCheckForIdentifier(node, name, "_super")) {
  19513. return;
  19514. }
  19515. var enclosingClass = ts.getContainingClass(node);
  19516. if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) {
  19517. return;
  19518. }
  19519. if (ts.getClassExtendsHeritageClauseElement(enclosingClass)) {
  19520. var isDeclaration_2 = node.kind !== 69;
  19521. if (isDeclaration_2) {
  19522. error(node, ts.Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference);
  19523. }
  19524. else {
  19525. error(node, ts.Diagnostics.Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference);
  19526. }
  19527. }
  19528. }
  19529. function checkCollisionWithRequireExportsInGeneratedCode(node, name) {
  19530. if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
  19531. return;
  19532. }
  19533. if (node.kind === 218 && ts.getModuleInstanceState(node) !== 1) {
  19534. return;
  19535. }
  19536. var parent = getDeclarationContainer(node);
  19537. if (parent.kind === 248 && ts.isExternalModule(parent)) {
  19538. error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name));
  19539. }
  19540. }
  19541. function checkVarDeclaredNamesNotShadowed(node) {
  19542. if ((ts.getCombinedNodeFlags(node) & 49152) !== 0 || ts.isParameterDeclaration(node)) {
  19543. return;
  19544. }
  19545. if (node.kind === 211 && !node.initializer) {
  19546. return;
  19547. }
  19548. var symbol = getSymbolOfNode(node);
  19549. if (symbol.flags & 1) {
  19550. var localDeclarationSymbol = resolveName(node, node.name.text, 3, undefined, undefined);
  19551. if (localDeclarationSymbol &&
  19552. localDeclarationSymbol !== symbol &&
  19553. localDeclarationSymbol.flags & 2) {
  19554. if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 49152) {
  19555. var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 212);
  19556. var container = varDeclList.parent.kind === 193 && varDeclList.parent.parent
  19557. ? varDeclList.parent.parent
  19558. : undefined;
  19559. var namesShareScope = container &&
  19560. (container.kind === 192 && ts.isFunctionLike(container.parent) ||
  19561. container.kind === 219 ||
  19562. container.kind === 218 ||
  19563. container.kind === 248);
  19564. if (!namesShareScope) {
  19565. var name_14 = symbolToString(localDeclarationSymbol);
  19566. error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_14, name_14);
  19567. }
  19568. }
  19569. }
  19570. }
  19571. }
  19572. function checkParameterInitializer(node) {
  19573. if (ts.getRootDeclaration(node).kind !== 138) {
  19574. return;
  19575. }
  19576. var func = ts.getContainingFunction(node);
  19577. visit(node.initializer);
  19578. function visit(n) {
  19579. if (n.kind === 69) {
  19580. var referencedSymbol = getNodeLinks(n).resolvedSymbol;
  19581. if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455) === referencedSymbol) {
  19582. if (referencedSymbol.valueDeclaration.kind === 138) {
  19583. if (referencedSymbol.valueDeclaration === node) {
  19584. error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name));
  19585. return;
  19586. }
  19587. if (referencedSymbol.valueDeclaration.pos < node.pos) {
  19588. return;
  19589. }
  19590. }
  19591. error(n, ts.Diagnostics.Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(node.name), ts.declarationNameToString(n));
  19592. }
  19593. }
  19594. else {
  19595. ts.forEachChild(n, visit);
  19596. }
  19597. }
  19598. }
  19599. function checkVariableLikeDeclaration(node) {
  19600. checkDecorators(node);
  19601. checkSourceElement(node.type);
  19602. if (node.name.kind === 136) {
  19603. checkComputedPropertyName(node.name);
  19604. if (node.initializer) {
  19605. checkExpressionCached(node.initializer);
  19606. }
  19607. }
  19608. if (ts.isBindingPattern(node.name)) {
  19609. ts.forEach(node.name.elements, checkSourceElement);
  19610. }
  19611. if (node.initializer && ts.getRootDeclaration(node).kind === 138 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
  19612. error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
  19613. return;
  19614. }
  19615. if (ts.isBindingPattern(node.name)) {
  19616. if (node.initializer) {
  19617. checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, undefined);
  19618. checkParameterInitializer(node);
  19619. }
  19620. return;
  19621. }
  19622. var symbol = getSymbolOfNode(node);
  19623. var type = getTypeOfVariableOrParameterOrProperty(symbol);
  19624. if (node === symbol.valueDeclaration) {
  19625. if (node.initializer) {
  19626. checkTypeAssignableTo(checkExpressionCached(node.initializer), type, node, undefined);
  19627. checkParameterInitializer(node);
  19628. }
  19629. }
  19630. else {
  19631. var declarationType = getWidenedTypeForVariableLikeDeclaration(node);
  19632. if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) {
  19633. error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.declarationNameToString(node.name), typeToString(type), typeToString(declarationType));
  19634. }
  19635. if (node.initializer) {
  19636. checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined);
  19637. }
  19638. }
  19639. if (node.kind !== 141 && node.kind !== 140) {
  19640. checkExportsOnMergedDeclarations(node);
  19641. if (node.kind === 211 || node.kind === 163) {
  19642. checkVarDeclaredNamesNotShadowed(node);
  19643. }
  19644. checkCollisionWithCapturedSuperVariable(node, node.name);
  19645. checkCollisionWithCapturedThisVariable(node, node.name);
  19646. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  19647. }
  19648. }
  19649. function checkVariableDeclaration(node) {
  19650. checkGrammarVariableDeclaration(node);
  19651. return checkVariableLikeDeclaration(node);
  19652. }
  19653. function checkBindingElement(node) {
  19654. checkGrammarBindingElement(node);
  19655. return checkVariableLikeDeclaration(node);
  19656. }
  19657. function checkVariableStatement(node) {
  19658. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node);
  19659. ts.forEach(node.declarationList.declarations, checkSourceElement);
  19660. }
  19661. function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) {
  19662. if (node.modifiers && node.parent.kind === 165) {
  19663. if (ts.isAsyncFunctionLike(node)) {
  19664. if (node.modifiers.length > 1) {
  19665. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  19666. }
  19667. }
  19668. else {
  19669. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  19670. }
  19671. }
  19672. }
  19673. function checkExpressionStatement(node) {
  19674. checkGrammarStatementInAmbientContext(node);
  19675. checkExpression(node.expression);
  19676. }
  19677. function checkIfStatement(node) {
  19678. checkGrammarStatementInAmbientContext(node);
  19679. checkExpression(node.expression);
  19680. checkSourceElement(node.thenStatement);
  19681. checkSourceElement(node.elseStatement);
  19682. }
  19683. function checkDoStatement(node) {
  19684. checkGrammarStatementInAmbientContext(node);
  19685. checkSourceElement(node.statement);
  19686. checkExpression(node.expression);
  19687. }
  19688. function checkWhileStatement(node) {
  19689. checkGrammarStatementInAmbientContext(node);
  19690. checkExpression(node.expression);
  19691. checkSourceElement(node.statement);
  19692. }
  19693. function checkForStatement(node) {
  19694. if (!checkGrammarStatementInAmbientContext(node)) {
  19695. if (node.initializer && node.initializer.kind === 212) {
  19696. checkGrammarVariableDeclarationList(node.initializer);
  19697. }
  19698. }
  19699. if (node.initializer) {
  19700. if (node.initializer.kind === 212) {
  19701. ts.forEach(node.initializer.declarations, checkVariableDeclaration);
  19702. }
  19703. else {
  19704. checkExpression(node.initializer);
  19705. }
  19706. }
  19707. if (node.condition)
  19708. checkExpression(node.condition);
  19709. if (node.incrementor)
  19710. checkExpression(node.incrementor);
  19711. checkSourceElement(node.statement);
  19712. }
  19713. function checkForOfStatement(node) {
  19714. checkGrammarForInOrForOfStatement(node);
  19715. if (node.initializer.kind === 212) {
  19716. checkForInOrForOfVariableDeclaration(node);
  19717. }
  19718. else {
  19719. var varExpr = node.initializer;
  19720. var iteratedType = checkRightHandSideOfForOf(node.expression);
  19721. if (varExpr.kind === 164 || varExpr.kind === 165) {
  19722. checkDestructuringAssignment(varExpr, iteratedType || unknownType);
  19723. }
  19724. else {
  19725. var leftType = checkExpression(varExpr);
  19726. checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_of_statement, ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant);
  19727. if (iteratedType) {
  19728. checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined);
  19729. }
  19730. }
  19731. }
  19732. checkSourceElement(node.statement);
  19733. }
  19734. function checkForInStatement(node) {
  19735. checkGrammarForInOrForOfStatement(node);
  19736. if (node.initializer.kind === 212) {
  19737. var variable = node.initializer.declarations[0];
  19738. if (variable && ts.isBindingPattern(variable.name)) {
  19739. error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern);
  19740. }
  19741. checkForInOrForOfVariableDeclaration(node);
  19742. }
  19743. else {
  19744. var varExpr = node.initializer;
  19745. var leftType = checkExpression(varExpr);
  19746. if (varExpr.kind === 164 || varExpr.kind === 165) {
  19747. error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern);
  19748. }
  19749. else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) {
  19750. error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any);
  19751. }
  19752. else {
  19753. checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant);
  19754. }
  19755. }
  19756. var rightType = checkExpression(node.expression);
  19757. if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 | 512)) {
  19758. error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
  19759. }
  19760. checkSourceElement(node.statement);
  19761. }
  19762. function checkForInOrForOfVariableDeclaration(iterationStatement) {
  19763. var variableDeclarationList = iterationStatement.initializer;
  19764. if (variableDeclarationList.declarations.length >= 1) {
  19765. var decl = variableDeclarationList.declarations[0];
  19766. checkVariableDeclaration(decl);
  19767. }
  19768. }
  19769. function checkRightHandSideOfForOf(rhsExpression) {
  19770. var expressionType = getTypeOfExpression(rhsExpression);
  19771. return checkIteratedTypeOrElementType(expressionType, rhsExpression, true);
  19772. }
  19773. function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) {
  19774. if (isTypeAny(inputType)) {
  19775. return inputType;
  19776. }
  19777. if (languageVersion >= 2) {
  19778. return checkElementTypeOfIterable(inputType, errorNode);
  19779. }
  19780. if (allowStringInput) {
  19781. return checkElementTypeOfArrayOrString(inputType, errorNode);
  19782. }
  19783. if (isArrayLikeType(inputType)) {
  19784. var indexType = getIndexTypeOfType(inputType, 1);
  19785. if (indexType) {
  19786. return indexType;
  19787. }
  19788. }
  19789. error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType));
  19790. return unknownType;
  19791. }
  19792. function checkElementTypeOfIterable(iterable, errorNode) {
  19793. var elementType = getElementTypeOfIterable(iterable, errorNode);
  19794. if (errorNode && elementType) {
  19795. checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode);
  19796. }
  19797. return elementType || anyType;
  19798. }
  19799. function getElementTypeOfIterable(type, errorNode) {
  19800. if (isTypeAny(type)) {
  19801. return undefined;
  19802. }
  19803. var typeAsIterable = type;
  19804. if (!typeAsIterable.iterableElementType) {
  19805. if ((type.flags & 4096) && type.target === globalIterableType) {
  19806. typeAsIterable.iterableElementType = type.typeArguments[0];
  19807. }
  19808. else {
  19809. var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator"));
  19810. if (isTypeAny(iteratorFunction)) {
  19811. return undefined;
  19812. }
  19813. var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray;
  19814. if (iteratorFunctionSignatures.length === 0) {
  19815. if (errorNode) {
  19816. error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
  19817. }
  19818. return undefined;
  19819. }
  19820. typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode);
  19821. }
  19822. }
  19823. return typeAsIterable.iterableElementType;
  19824. }
  19825. function getElementTypeOfIterator(type, errorNode) {
  19826. if (isTypeAny(type)) {
  19827. return undefined;
  19828. }
  19829. var typeAsIterator = type;
  19830. if (!typeAsIterator.iteratorElementType) {
  19831. if ((type.flags & 4096) && type.target === globalIteratorType) {
  19832. typeAsIterator.iteratorElementType = type.typeArguments[0];
  19833. }
  19834. else {
  19835. var iteratorNextFunction = getTypeOfPropertyOfType(type, "next");
  19836. if (isTypeAny(iteratorNextFunction)) {
  19837. return undefined;
  19838. }
  19839. var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray;
  19840. if (iteratorNextFunctionSignatures.length === 0) {
  19841. if (errorNode) {
  19842. error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method);
  19843. }
  19844. return undefined;
  19845. }
  19846. var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
  19847. if (isTypeAny(iteratorNextResult)) {
  19848. return undefined;
  19849. }
  19850. var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
  19851. if (!iteratorNextValue) {
  19852. if (errorNode) {
  19853. error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
  19854. }
  19855. return undefined;
  19856. }
  19857. typeAsIterator.iteratorElementType = iteratorNextValue;
  19858. }
  19859. }
  19860. return typeAsIterator.iteratorElementType;
  19861. }
  19862. function getElementTypeOfIterableIterator(type) {
  19863. if (isTypeAny(type)) {
  19864. return undefined;
  19865. }
  19866. if ((type.flags & 4096) && type.target === globalIterableIteratorType) {
  19867. return type.typeArguments[0];
  19868. }
  19869. return getElementTypeOfIterable(type, undefined) ||
  19870. getElementTypeOfIterator(type, undefined);
  19871. }
  19872. function checkElementTypeOfArrayOrString(arrayOrStringType, errorNode) {
  19873. ts.Debug.assert(languageVersion < 2);
  19874. var arrayType = removeTypesFromUnionType(arrayOrStringType, 258, true, true);
  19875. var hasStringConstituent = arrayOrStringType !== arrayType;
  19876. var reportedError = false;
  19877. if (hasStringConstituent) {
  19878. if (languageVersion < 1) {
  19879. error(errorNode, ts.Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
  19880. reportedError = true;
  19881. }
  19882. if (arrayType === emptyObjectType) {
  19883. return stringType;
  19884. }
  19885. }
  19886. if (!isArrayLikeType(arrayType)) {
  19887. if (!reportedError) {
  19888. var diagnostic = hasStringConstituent
  19889. ? ts.Diagnostics.Type_0_is_not_an_array_type
  19890. : ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
  19891. error(errorNode, diagnostic, typeToString(arrayType));
  19892. }
  19893. return hasStringConstituent ? stringType : unknownType;
  19894. }
  19895. var arrayElementType = getIndexTypeOfType(arrayType, 1) || unknownType;
  19896. if (hasStringConstituent) {
  19897. if (arrayElementType.flags & 258) {
  19898. return stringType;
  19899. }
  19900. return getUnionType([arrayElementType, stringType]);
  19901. }
  19902. return arrayElementType;
  19903. }
  19904. function checkBreakOrContinueStatement(node) {
  19905. checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node);
  19906. }
  19907. function isGetAccessorWithAnnotatatedSetAccessor(node) {
  19908. return !!(node.kind === 145 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 146)));
  19909. }
  19910. function checkReturnStatement(node) {
  19911. if (!checkGrammarStatementInAmbientContext(node)) {
  19912. var functionBlock = ts.getContainingFunction(node);
  19913. if (!functionBlock) {
  19914. grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
  19915. }
  19916. }
  19917. if (node.expression) {
  19918. var func = ts.getContainingFunction(node);
  19919. if (func) {
  19920. var signature = getSignatureFromDeclaration(func);
  19921. var returnType = getReturnTypeOfSignature(signature);
  19922. var exprType = checkExpressionCached(node.expression);
  19923. if (func.asteriskToken) {
  19924. return;
  19925. }
  19926. if (func.kind === 146) {
  19927. error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value);
  19928. }
  19929. else if (func.kind === 144) {
  19930. if (!isTypeAssignableTo(exprType, returnType)) {
  19931. error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
  19932. }
  19933. }
  19934. else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func) || signature.typePredicate) {
  19935. if (ts.isAsyncFunctionLike(func)) {
  19936. var promisedType = getPromisedType(returnType);
  19937. var awaitedType = checkAwaitedType(exprType, node.expression, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
  19938. if (promisedType) {
  19939. checkTypeAssignableTo(awaitedType, promisedType, node.expression);
  19940. }
  19941. }
  19942. else {
  19943. checkTypeAssignableTo(exprType, returnType, node.expression);
  19944. }
  19945. }
  19946. }
  19947. }
  19948. }
  19949. function checkWithStatement(node) {
  19950. if (!checkGrammarStatementInAmbientContext(node)) {
  19951. if (node.parserContextFlags & 8) {
  19952. grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_an_async_function_block);
  19953. }
  19954. }
  19955. checkExpression(node.expression);
  19956. error(node.expression, ts.Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
  19957. }
  19958. function checkSwitchStatement(node) {
  19959. checkGrammarStatementInAmbientContext(node);
  19960. var firstDefaultClause;
  19961. var hasDuplicateDefaultClause = false;
  19962. var expressionType = checkExpression(node.expression);
  19963. ts.forEach(node.caseBlock.clauses, function (clause) {
  19964. if (clause.kind === 242 && !hasDuplicateDefaultClause) {
  19965. if (firstDefaultClause === undefined) {
  19966. firstDefaultClause = clause;
  19967. }
  19968. else {
  19969. var sourceFile = ts.getSourceFileOfNode(node);
  19970. var start = ts.skipTrivia(sourceFile.text, clause.pos);
  19971. var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
  19972. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
  19973. hasDuplicateDefaultClause = true;
  19974. }
  19975. }
  19976. if (produceDiagnostics && clause.kind === 241) {
  19977. var caseClause = clause;
  19978. var caseType = checkExpression(caseClause.expression);
  19979. if (!isTypeAssignableTo(expressionType, caseType)) {
  19980. checkTypeAssignableTo(caseType, expressionType, caseClause.expression, undefined);
  19981. }
  19982. }
  19983. ts.forEach(clause.statements, checkSourceElement);
  19984. });
  19985. }
  19986. function checkLabeledStatement(node) {
  19987. if (!checkGrammarStatementInAmbientContext(node)) {
  19988. var current = node.parent;
  19989. while (current) {
  19990. if (ts.isFunctionLike(current)) {
  19991. break;
  19992. }
  19993. if (current.kind === 207 && current.label.text === node.label.text) {
  19994. var sourceFile = ts.getSourceFileOfNode(node);
  19995. grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label));
  19996. break;
  19997. }
  19998. current = current.parent;
  19999. }
  20000. }
  20001. checkSourceElement(node.statement);
  20002. }
  20003. function checkThrowStatement(node) {
  20004. if (!checkGrammarStatementInAmbientContext(node)) {
  20005. if (node.expression === undefined) {
  20006. grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here);
  20007. }
  20008. }
  20009. if (node.expression) {
  20010. checkExpression(node.expression);
  20011. }
  20012. }
  20013. function checkTryStatement(node) {
  20014. checkGrammarStatementInAmbientContext(node);
  20015. checkBlock(node.tryBlock);
  20016. var catchClause = node.catchClause;
  20017. if (catchClause) {
  20018. if (catchClause.variableDeclaration) {
  20019. if (catchClause.variableDeclaration.name.kind !== 69) {
  20020. grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier);
  20021. }
  20022. else if (catchClause.variableDeclaration.type) {
  20023. grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation);
  20024. }
  20025. else if (catchClause.variableDeclaration.initializer) {
  20026. grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
  20027. }
  20028. else {
  20029. var identifierName = catchClause.variableDeclaration.name.text;
  20030. var locals = catchClause.block.locals;
  20031. if (locals && ts.hasProperty(locals, identifierName)) {
  20032. var localSymbol = locals[identifierName];
  20033. if (localSymbol && (localSymbol.flags & 2) !== 0) {
  20034. grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
  20035. }
  20036. }
  20037. }
  20038. }
  20039. checkBlock(catchClause.block);
  20040. }
  20041. if (node.finallyBlock) {
  20042. checkBlock(node.finallyBlock);
  20043. }
  20044. }
  20045. function checkIndexConstraints(type) {
  20046. var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1);
  20047. var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, 0);
  20048. var stringIndexType = getIndexTypeOfType(type, 0);
  20049. var numberIndexType = getIndexTypeOfType(type, 1);
  20050. if (stringIndexType || numberIndexType) {
  20051. ts.forEach(getPropertiesOfObjectType(type), function (prop) {
  20052. var propType = getTypeOfSymbol(prop);
  20053. checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0);
  20054. checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1);
  20055. });
  20056. if (type.flags & 1024 && ts.isClassLike(type.symbol.valueDeclaration)) {
  20057. var classDeclaration = type.symbol.valueDeclaration;
  20058. for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) {
  20059. var member = _a[_i];
  20060. if (!(member.flags & 128) && ts.hasDynamicName(member)) {
  20061. var propType = getTypeOfSymbol(member.symbol);
  20062. checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, 0);
  20063. checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, 1);
  20064. }
  20065. }
  20066. }
  20067. }
  20068. var errorNode;
  20069. if (stringIndexType && numberIndexType) {
  20070. errorNode = declaredNumberIndexer || declaredStringIndexer;
  20071. if (!errorNode && (type.flags & 2048)) {
  20072. var someBaseTypeHasBothIndexers = ts.forEach(getBaseTypes(type), function (base) { return getIndexTypeOfType(base, 0) && getIndexTypeOfType(base, 1); });
  20073. errorNode = someBaseTypeHasBothIndexers ? undefined : type.symbol.declarations[0];
  20074. }
  20075. }
  20076. if (errorNode && !isTypeAssignableTo(numberIndexType, stringIndexType)) {
  20077. error(errorNode, ts.Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, typeToString(numberIndexType), typeToString(stringIndexType));
  20078. }
  20079. function checkIndexConstraintForProperty(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) {
  20080. if (!indexType) {
  20081. return;
  20082. }
  20083. if (indexKind === 1 && !isNumericName(prop.valueDeclaration.name)) {
  20084. return;
  20085. }
  20086. var errorNode;
  20087. if (prop.valueDeclaration.name.kind === 136 || prop.parent === containingType.symbol) {
  20088. errorNode = prop.valueDeclaration;
  20089. }
  20090. else if (indexDeclaration) {
  20091. errorNode = indexDeclaration;
  20092. }
  20093. else if (containingType.flags & 2048) {
  20094. var someBaseClassHasBothPropertyAndIndexer = ts.forEach(getBaseTypes(containingType), function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); });
  20095. errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0];
  20096. }
  20097. if (errorNode && !isTypeAssignableTo(propertyType, indexType)) {
  20098. var errorMessage = indexKind === 0
  20099. ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2
  20100. : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2;
  20101. error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType));
  20102. }
  20103. }
  20104. }
  20105. function checkTypeNameIsReserved(name, message) {
  20106. switch (name.text) {
  20107. case "any":
  20108. case "number":
  20109. case "boolean":
  20110. case "string":
  20111. case "symbol":
  20112. case "void":
  20113. error(name, message, name.text);
  20114. }
  20115. }
  20116. function checkTypeParameters(typeParameterDeclarations) {
  20117. if (typeParameterDeclarations) {
  20118. for (var i = 0, n = typeParameterDeclarations.length; i < n; i++) {
  20119. var node = typeParameterDeclarations[i];
  20120. checkTypeParameter(node);
  20121. if (produceDiagnostics) {
  20122. for (var j = 0; j < i; j++) {
  20123. if (typeParameterDeclarations[j].symbol === node.symbol) {
  20124. error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name));
  20125. }
  20126. }
  20127. }
  20128. }
  20129. }
  20130. }
  20131. function checkClassExpression(node) {
  20132. checkClassLikeDeclaration(node);
  20133. return getTypeOfSymbol(getSymbolOfNode(node));
  20134. }
  20135. function checkClassDeclaration(node) {
  20136. if (!node.name && !(node.flags & 1024)) {
  20137. grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
  20138. }
  20139. checkClassLikeDeclaration(node);
  20140. ts.forEach(node.members, checkSourceElement);
  20141. }
  20142. function checkClassLikeDeclaration(node) {
  20143. checkGrammarClassDeclarationHeritageClauses(node);
  20144. checkDecorators(node);
  20145. if (node.name) {
  20146. checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0);
  20147. checkCollisionWithCapturedThisVariable(node, node.name);
  20148. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  20149. }
  20150. checkTypeParameters(node.typeParameters);
  20151. checkExportsOnMergedDeclarations(node);
  20152. var symbol = getSymbolOfNode(node);
  20153. var type = getDeclaredTypeOfSymbol(symbol);
  20154. var typeWithThis = getTypeWithThisArgument(type);
  20155. var staticType = getTypeOfSymbol(symbol);
  20156. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  20157. if (baseTypeNode) {
  20158. emitExtends = emitExtends || !ts.isInAmbientContext(node);
  20159. var baseTypes = getBaseTypes(type);
  20160. if (baseTypes.length && produceDiagnostics) {
  20161. var baseType = baseTypes[0];
  20162. var staticBaseType = getBaseConstructorTypeOfClass(type);
  20163. checkSourceElement(baseTypeNode.expression);
  20164. if (baseTypeNode.typeArguments) {
  20165. ts.forEach(baseTypeNode.typeArguments, checkSourceElement);
  20166. for (var _i = 0, _a = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments); _i < _a.length; _i++) {
  20167. var constructor = _a[_i];
  20168. if (!checkTypeArgumentConstraints(constructor.typeParameters, baseTypeNode.typeArguments)) {
  20169. break;
  20170. }
  20171. }
  20172. }
  20173. checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
  20174. checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
  20175. if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32)) {
  20176. var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments);
  20177. if (ts.forEach(constructors, function (sig) { return getReturnTypeOfSignature(sig) !== baseType; })) {
  20178. error(baseTypeNode.expression, ts.Diagnostics.Base_constructors_must_all_have_the_same_return_type);
  20179. }
  20180. }
  20181. checkKindsOfPropertyMemberOverrides(type, baseType);
  20182. }
  20183. }
  20184. var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node);
  20185. if (implementedTypeNodes) {
  20186. for (var _b = 0; _b < implementedTypeNodes.length; _b++) {
  20187. var typeRefNode = implementedTypeNodes[_b];
  20188. if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) {
  20189. error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
  20190. }
  20191. checkTypeReferenceNode(typeRefNode);
  20192. if (produceDiagnostics) {
  20193. var t = getTypeFromTypeNode(typeRefNode);
  20194. if (t !== unknownType) {
  20195. var declaredType = (t.flags & 4096) ? t.target : t;
  20196. if (declaredType.flags & (1024 | 2048)) {
  20197. checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(t, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1);
  20198. }
  20199. else {
  20200. error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface);
  20201. }
  20202. }
  20203. }
  20204. }
  20205. }
  20206. if (produceDiagnostics) {
  20207. checkIndexConstraints(type);
  20208. checkTypeForDuplicateIndexSignatures(node);
  20209. }
  20210. }
  20211. function getTargetSymbol(s) {
  20212. return s.flags & 16777216 ? getSymbolLinks(s).target : s;
  20213. }
  20214. function getClassLikeDeclarationOfSymbol(symbol) {
  20215. return ts.forEach(symbol.declarations, function (d) { return ts.isClassLike(d) ? d : undefined; });
  20216. }
  20217. function checkKindsOfPropertyMemberOverrides(type, baseType) {
  20218. var baseProperties = getPropertiesOfObjectType(baseType);
  20219. for (var _i = 0; _i < baseProperties.length; _i++) {
  20220. var baseProperty = baseProperties[_i];
  20221. var base = getTargetSymbol(baseProperty);
  20222. if (base.flags & 134217728) {
  20223. continue;
  20224. }
  20225. var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name));
  20226. var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base);
  20227. ts.Debug.assert(!!derived, "derived should point to something, even if it is the base class' declaration.");
  20228. if (derived) {
  20229. if (derived === base) {
  20230. var derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol);
  20231. if (baseDeclarationFlags & 256 && (!derivedClassDecl || !(derivedClassDecl.flags & 256))) {
  20232. if (derivedClassDecl.kind === 186) {
  20233. error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, symbolToString(baseProperty), typeToString(baseType));
  20234. }
  20235. else {
  20236. error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2, typeToString(type), symbolToString(baseProperty), typeToString(baseType));
  20237. }
  20238. }
  20239. }
  20240. else {
  20241. var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived);
  20242. if ((baseDeclarationFlags & 32) || (derivedDeclarationFlags & 32)) {
  20243. continue;
  20244. }
  20245. if ((baseDeclarationFlags & 128) !== (derivedDeclarationFlags & 128)) {
  20246. continue;
  20247. }
  20248. if ((base.flags & derived.flags & 8192) || ((base.flags & 98308) && (derived.flags & 98308))) {
  20249. continue;
  20250. }
  20251. var errorMessage = void 0;
  20252. if (base.flags & 8192) {
  20253. if (derived.flags & 98304) {
  20254. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor;
  20255. }
  20256. else {
  20257. ts.Debug.assert((derived.flags & 4) !== 0);
  20258. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property;
  20259. }
  20260. }
  20261. else if (base.flags & 4) {
  20262. ts.Debug.assert((derived.flags & 8192) !== 0);
  20263. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function;
  20264. }
  20265. else {
  20266. ts.Debug.assert((base.flags & 98304) !== 0);
  20267. ts.Debug.assert((derived.flags & 8192) !== 0);
  20268. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function;
  20269. }
  20270. error(derived.valueDeclaration.name, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
  20271. }
  20272. }
  20273. }
  20274. }
  20275. function isAccessor(kind) {
  20276. return kind === 145 || kind === 146;
  20277. }
  20278. function areTypeParametersIdentical(list1, list2) {
  20279. if (!list1 && !list2) {
  20280. return true;
  20281. }
  20282. if (!list1 || !list2 || list1.length !== list2.length) {
  20283. return false;
  20284. }
  20285. for (var i = 0, len = list1.length; i < len; i++) {
  20286. var tp1 = list1[i];
  20287. var tp2 = list2[i];
  20288. if (tp1.name.text !== tp2.name.text) {
  20289. return false;
  20290. }
  20291. if (!tp1.constraint && !tp2.constraint) {
  20292. continue;
  20293. }
  20294. if (!tp1.constraint || !tp2.constraint) {
  20295. return false;
  20296. }
  20297. if (!isTypeIdenticalTo(getTypeFromTypeNode(tp1.constraint), getTypeFromTypeNode(tp2.constraint))) {
  20298. return false;
  20299. }
  20300. }
  20301. return true;
  20302. }
  20303. function checkInheritedPropertiesAreIdentical(type, typeNode) {
  20304. var baseTypes = getBaseTypes(type);
  20305. if (baseTypes.length < 2) {
  20306. return true;
  20307. }
  20308. var seen = {};
  20309. ts.forEach(resolveDeclaredMembers(type).declaredProperties, function (p) { seen[p.name] = { prop: p, containingType: type }; });
  20310. var ok = true;
  20311. for (var _i = 0; _i < baseTypes.length; _i++) {
  20312. var base = baseTypes[_i];
  20313. var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType));
  20314. for (var _a = 0; _a < properties.length; _a++) {
  20315. var prop = properties[_a];
  20316. if (!ts.hasProperty(seen, prop.name)) {
  20317. seen[prop.name] = { prop: prop, containingType: base };
  20318. }
  20319. else {
  20320. var existing = seen[prop.name];
  20321. var isInheritedProperty = existing.containingType !== type;
  20322. if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) {
  20323. ok = false;
  20324. var typeName1 = typeToString(existing.containingType);
  20325. var typeName2 = typeToString(base);
  20326. var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2);
  20327. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
  20328. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
  20329. }
  20330. }
  20331. }
  20332. }
  20333. return ok;
  20334. }
  20335. function checkInterfaceDeclaration(node) {
  20336. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node);
  20337. checkTypeParameters(node.typeParameters);
  20338. if (produceDiagnostics) {
  20339. checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
  20340. checkExportsOnMergedDeclarations(node);
  20341. var symbol = getSymbolOfNode(node);
  20342. var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 215);
  20343. if (symbol.declarations.length > 1) {
  20344. if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) {
  20345. error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters);
  20346. }
  20347. }
  20348. if (node === firstInterfaceDecl) {
  20349. var type = getDeclaredTypeOfSymbol(symbol);
  20350. var typeWithThis = getTypeWithThisArgument(type);
  20351. if (checkInheritedPropertiesAreIdentical(type, node.name)) {
  20352. for (var _i = 0, _a = getBaseTypes(type); _i < _a.length; _i++) {
  20353. var baseType = _a[_i];
  20354. checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1);
  20355. }
  20356. checkIndexConstraints(type);
  20357. }
  20358. }
  20359. }
  20360. ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) {
  20361. if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) {
  20362. error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
  20363. }
  20364. checkTypeReferenceNode(heritageElement);
  20365. });
  20366. ts.forEach(node.members, checkSourceElement);
  20367. if (produceDiagnostics) {
  20368. checkTypeForDuplicateIndexSignatures(node);
  20369. }
  20370. }
  20371. function checkTypeAliasDeclaration(node) {
  20372. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  20373. checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_alias_name_cannot_be_0);
  20374. checkSourceElement(node.type);
  20375. }
  20376. function computeEnumMemberValues(node) {
  20377. var nodeLinks = getNodeLinks(node);
  20378. if (!(nodeLinks.flags & 8192)) {
  20379. var enumSymbol = getSymbolOfNode(node);
  20380. var enumType = getDeclaredTypeOfSymbol(enumSymbol);
  20381. var autoValue = 0;
  20382. var ambient = ts.isInAmbientContext(node);
  20383. var enumIsConst = ts.isConst(node);
  20384. for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
  20385. var member = _a[_i];
  20386. if (member.name.kind === 136) {
  20387. error(member.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums);
  20388. }
  20389. else if (isNumericLiteralName(member.name.text)) {
  20390. error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
  20391. }
  20392. var previousEnumMemberIsNonConstant = autoValue === undefined;
  20393. var initializer = member.initializer;
  20394. if (initializer) {
  20395. autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient);
  20396. }
  20397. else if (ambient && !enumIsConst) {
  20398. autoValue = undefined;
  20399. }
  20400. else if (previousEnumMemberIsNonConstant) {
  20401. error(member.name, ts.Diagnostics.Enum_member_must_have_initializer);
  20402. }
  20403. if (autoValue !== undefined) {
  20404. getNodeLinks(member).enumMemberValue = autoValue++;
  20405. }
  20406. }
  20407. nodeLinks.flags |= 8192;
  20408. }
  20409. function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) {
  20410. var reportError = true;
  20411. var value = evalConstant(initializer);
  20412. if (reportError) {
  20413. if (value === undefined) {
  20414. if (enumIsConst) {
  20415. error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
  20416. }
  20417. else if (ambient) {
  20418. error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
  20419. }
  20420. else {
  20421. checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined);
  20422. }
  20423. }
  20424. else if (enumIsConst) {
  20425. if (isNaN(value)) {
  20426. error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN);
  20427. }
  20428. else if (!isFinite(value)) {
  20429. error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value);
  20430. }
  20431. }
  20432. }
  20433. return value;
  20434. function evalConstant(e) {
  20435. switch (e.kind) {
  20436. case 179:
  20437. var value_1 = evalConstant(e.operand);
  20438. if (value_1 === undefined) {
  20439. return undefined;
  20440. }
  20441. switch (e.operator) {
  20442. case 35: return value_1;
  20443. case 36: return -value_1;
  20444. case 50: return ~value_1;
  20445. }
  20446. return undefined;
  20447. case 181:
  20448. var left = evalConstant(e.left);
  20449. if (left === undefined) {
  20450. return undefined;
  20451. }
  20452. var right = evalConstant(e.right);
  20453. if (right === undefined) {
  20454. return undefined;
  20455. }
  20456. switch (e.operatorToken.kind) {
  20457. case 47: return left | right;
  20458. case 46: return left & right;
  20459. case 44: return left >> right;
  20460. case 45: return left >>> right;
  20461. case 43: return left << right;
  20462. case 48: return left ^ right;
  20463. case 37: return left * right;
  20464. case 39: return left / right;
  20465. case 35: return left + right;
  20466. case 36: return left - right;
  20467. case 40: return left % right;
  20468. }
  20469. return undefined;
  20470. case 8:
  20471. return +e.text;
  20472. case 172:
  20473. return evalConstant(e.expression);
  20474. case 69:
  20475. case 167:
  20476. case 166:
  20477. var member = initializer.parent;
  20478. var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent));
  20479. var enumType_1;
  20480. var propertyName;
  20481. if (e.kind === 69) {
  20482. enumType_1 = currentType;
  20483. propertyName = e.text;
  20484. }
  20485. else {
  20486. var expression;
  20487. if (e.kind === 167) {
  20488. if (e.argumentExpression === undefined ||
  20489. e.argumentExpression.kind !== 9) {
  20490. return undefined;
  20491. }
  20492. expression = e.expression;
  20493. propertyName = e.argumentExpression.text;
  20494. }
  20495. else {
  20496. expression = e.expression;
  20497. propertyName = e.name.text;
  20498. }
  20499. var current = expression;
  20500. while (current) {
  20501. if (current.kind === 69) {
  20502. break;
  20503. }
  20504. else if (current.kind === 166) {
  20505. current = current.expression;
  20506. }
  20507. else {
  20508. return undefined;
  20509. }
  20510. }
  20511. enumType_1 = checkExpression(expression);
  20512. if (!(enumType_1.symbol && (enumType_1.symbol.flags & 384))) {
  20513. return undefined;
  20514. }
  20515. }
  20516. if (propertyName === undefined) {
  20517. return undefined;
  20518. }
  20519. var property = getPropertyOfObjectType(enumType_1, propertyName);
  20520. if (!property || !(property.flags & 8)) {
  20521. return undefined;
  20522. }
  20523. var propertyDecl = property.valueDeclaration;
  20524. if (member === propertyDecl) {
  20525. return undefined;
  20526. }
  20527. if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) {
  20528. reportError = false;
  20529. error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
  20530. return undefined;
  20531. }
  20532. return getNodeLinks(propertyDecl).enumMemberValue;
  20533. }
  20534. }
  20535. }
  20536. }
  20537. function checkEnumDeclaration(node) {
  20538. if (!produceDiagnostics) {
  20539. return;
  20540. }
  20541. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  20542. checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0);
  20543. checkCollisionWithCapturedThisVariable(node, node.name);
  20544. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  20545. checkExportsOnMergedDeclarations(node);
  20546. computeEnumMemberValues(node);
  20547. var enumIsConst = ts.isConst(node);
  20548. if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) {
  20549. error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided);
  20550. }
  20551. var enumSymbol = getSymbolOfNode(node);
  20552. var firstDeclaration = ts.getDeclarationOfKind(enumSymbol, node.kind);
  20553. if (node === firstDeclaration) {
  20554. if (enumSymbol.declarations.length > 1) {
  20555. ts.forEach(enumSymbol.declarations, function (decl) {
  20556. if (ts.isConstEnumDeclaration(decl) !== enumIsConst) {
  20557. error(decl.name, ts.Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
  20558. }
  20559. });
  20560. }
  20561. var seenEnumMissingInitialInitializer = false;
  20562. ts.forEach(enumSymbol.declarations, function (declaration) {
  20563. if (declaration.kind !== 217) {
  20564. return false;
  20565. }
  20566. var enumDeclaration = declaration;
  20567. if (!enumDeclaration.members.length) {
  20568. return false;
  20569. }
  20570. var firstEnumMember = enumDeclaration.members[0];
  20571. if (!firstEnumMember.initializer) {
  20572. if (seenEnumMissingInitialInitializer) {
  20573. error(firstEnumMember.name, ts.Diagnostics.In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element);
  20574. }
  20575. else {
  20576. seenEnumMissingInitialInitializer = true;
  20577. }
  20578. }
  20579. });
  20580. }
  20581. }
  20582. function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
  20583. var declarations = symbol.declarations;
  20584. for (var _i = 0; _i < declarations.length; _i++) {
  20585. var declaration = declarations[_i];
  20586. if ((declaration.kind === 214 ||
  20587. (declaration.kind === 213 && ts.nodeIsPresent(declaration.body))) &&
  20588. !ts.isInAmbientContext(declaration)) {
  20589. return declaration;
  20590. }
  20591. }
  20592. return undefined;
  20593. }
  20594. function inSameLexicalScope(node1, node2) {
  20595. var container1 = ts.getEnclosingBlockScopeContainer(node1);
  20596. var container2 = ts.getEnclosingBlockScopeContainer(node2);
  20597. if (isGlobalSourceFile(container1)) {
  20598. return isGlobalSourceFile(container2);
  20599. }
  20600. else if (isGlobalSourceFile(container2)) {
  20601. return false;
  20602. }
  20603. else {
  20604. return container1 === container2;
  20605. }
  20606. }
  20607. function checkModuleDeclaration(node) {
  20608. if (produceDiagnostics) {
  20609. var isAmbientExternalModule = node.name.kind === 9;
  20610. var contextErrorMessage = isAmbientExternalModule
  20611. ? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
  20612. : ts.Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
  20613. if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
  20614. return;
  20615. }
  20616. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) {
  20617. if (!ts.isInAmbientContext(node) && node.name.kind === 9) {
  20618. grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
  20619. }
  20620. }
  20621. checkCollisionWithCapturedThisVariable(node, node.name);
  20622. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  20623. checkExportsOnMergedDeclarations(node);
  20624. var symbol = getSymbolOfNode(node);
  20625. if (symbol.flags & 512
  20626. && symbol.declarations.length > 1
  20627. && !ts.isInAmbientContext(node)
  20628. && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) {
  20629. var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
  20630. if (firstNonAmbientClassOrFunc) {
  20631. if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) {
  20632. error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged);
  20633. }
  20634. else if (node.pos < firstNonAmbientClassOrFunc.pos) {
  20635. error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged);
  20636. }
  20637. }
  20638. var mergedClass = ts.getDeclarationOfKind(symbol, 214);
  20639. if (mergedClass &&
  20640. inSameLexicalScope(node, mergedClass)) {
  20641. getNodeLinks(node).flags |= 32768;
  20642. }
  20643. }
  20644. if (isAmbientExternalModule) {
  20645. if (!isGlobalSourceFile(node.parent)) {
  20646. error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces);
  20647. }
  20648. if (ts.isExternalModuleNameRelative(node.name.text)) {
  20649. error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name);
  20650. }
  20651. }
  20652. }
  20653. checkSourceElement(node.body);
  20654. }
  20655. function getFirstIdentifier(node) {
  20656. while (true) {
  20657. if (node.kind === 135) {
  20658. node = node.left;
  20659. }
  20660. else if (node.kind === 166) {
  20661. node = node.expression;
  20662. }
  20663. else {
  20664. break;
  20665. }
  20666. }
  20667. ts.Debug.assert(node.kind === 69);
  20668. return node;
  20669. }
  20670. function checkExternalImportOrExportDeclaration(node) {
  20671. var moduleName = ts.getExternalModuleName(node);
  20672. if (!ts.nodeIsMissing(moduleName) && moduleName.kind !== 9) {
  20673. error(moduleName, ts.Diagnostics.String_literal_expected);
  20674. return false;
  20675. }
  20676. var inAmbientExternalModule = node.parent.kind === 219 && node.parent.parent.name.kind === 9;
  20677. if (node.parent.kind !== 248 && !inAmbientExternalModule) {
  20678. error(moduleName, node.kind === 228 ?
  20679. ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace :
  20680. ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module);
  20681. return false;
  20682. }
  20683. if (inAmbientExternalModule && ts.isExternalModuleNameRelative(moduleName.text)) {
  20684. error(node, ts.Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name);
  20685. return false;
  20686. }
  20687. return true;
  20688. }
  20689. function checkAliasSymbol(node) {
  20690. var symbol = getSymbolOfNode(node);
  20691. var target = resolveAlias(symbol);
  20692. if (target !== unknownSymbol) {
  20693. var excludedMeanings = (symbol.flags & 107455 ? 107455 : 0) |
  20694. (symbol.flags & 793056 ? 793056 : 0) |
  20695. (symbol.flags & 1536 ? 1536 : 0);
  20696. if (target.flags & excludedMeanings) {
  20697. var message = node.kind === 230 ?
  20698. ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
  20699. ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
  20700. error(node, message, symbolToString(symbol));
  20701. }
  20702. }
  20703. }
  20704. function checkImportBinding(node) {
  20705. checkCollisionWithCapturedThisVariable(node, node.name);
  20706. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  20707. checkAliasSymbol(node);
  20708. }
  20709. function checkImportDeclaration(node) {
  20710. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
  20711. return;
  20712. }
  20713. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) {
  20714. grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers);
  20715. }
  20716. if (checkExternalImportOrExportDeclaration(node)) {
  20717. var importClause = node.importClause;
  20718. if (importClause) {
  20719. if (importClause.name) {
  20720. checkImportBinding(importClause);
  20721. }
  20722. if (importClause.namedBindings) {
  20723. if (importClause.namedBindings.kind === 224) {
  20724. checkImportBinding(importClause.namedBindings);
  20725. }
  20726. else {
  20727. ts.forEach(importClause.namedBindings.elements, checkImportBinding);
  20728. }
  20729. }
  20730. }
  20731. }
  20732. }
  20733. function checkImportEqualsDeclaration(node) {
  20734. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
  20735. return;
  20736. }
  20737. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  20738. if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
  20739. checkImportBinding(node);
  20740. if (node.flags & 1) {
  20741. markExportAsReferenced(node);
  20742. }
  20743. if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  20744. var target = resolveAlias(getSymbolOfNode(node));
  20745. if (target !== unknownSymbol) {
  20746. if (target.flags & 107455) {
  20747. var moduleName = getFirstIdentifier(node.moduleReference);
  20748. if (!(resolveEntityName(moduleName, 107455 | 1536).flags & 1536)) {
  20749. error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName));
  20750. }
  20751. }
  20752. if (target.flags & 793056) {
  20753. checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0);
  20754. }
  20755. }
  20756. }
  20757. else {
  20758. if (modulekind === 5 && !ts.isInAmbientContext(node)) {
  20759. grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
  20760. }
  20761. }
  20762. }
  20763. }
  20764. function checkExportDeclaration(node) {
  20765. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
  20766. return;
  20767. }
  20768. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) {
  20769. grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers);
  20770. }
  20771. if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) {
  20772. if (node.exportClause) {
  20773. ts.forEach(node.exportClause.elements, checkExportSpecifier);
  20774. var inAmbientExternalModule = node.parent.kind === 219 && node.parent.parent.name.kind === 9;
  20775. if (node.parent.kind !== 248 && !inAmbientExternalModule) {
  20776. error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
  20777. }
  20778. }
  20779. else {
  20780. var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
  20781. if (moduleSymbol && moduleSymbol.exports["export="]) {
  20782. error(node.moduleSpecifier, ts.Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
  20783. }
  20784. }
  20785. }
  20786. }
  20787. function checkGrammarModuleElementContext(node, errorMessage) {
  20788. if (node.parent.kind !== 248 && node.parent.kind !== 219 && node.parent.kind !== 218) {
  20789. return grammarErrorOnFirstToken(node, errorMessage);
  20790. }
  20791. }
  20792. function checkExportSpecifier(node) {
  20793. checkAliasSymbol(node);
  20794. if (!node.parent.parent.moduleSpecifier) {
  20795. markExportAsReferenced(node);
  20796. }
  20797. }
  20798. function checkExportAssignment(node) {
  20799. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) {
  20800. return;
  20801. }
  20802. var container = node.parent.kind === 248 ? node.parent : node.parent.parent;
  20803. if (container.kind === 218 && container.name.kind === 69) {
  20804. error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
  20805. return;
  20806. }
  20807. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) {
  20808. grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
  20809. }
  20810. if (node.expression.kind === 69) {
  20811. markExportAsReferenced(node);
  20812. }
  20813. else {
  20814. checkExpressionCached(node.expression);
  20815. }
  20816. checkExternalModuleExports(container);
  20817. if (node.isExportEquals && !ts.isInAmbientContext(node)) {
  20818. if (modulekind === 5) {
  20819. grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead);
  20820. }
  20821. else if (modulekind === 4) {
  20822. grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
  20823. }
  20824. }
  20825. }
  20826. function getModuleStatements(node) {
  20827. if (node.kind === 248) {
  20828. return node.statements;
  20829. }
  20830. if (node.kind === 218 && node.body.kind === 219) {
  20831. return node.body.statements;
  20832. }
  20833. return emptyArray;
  20834. }
  20835. function hasExportedMembers(moduleSymbol) {
  20836. for (var id in moduleSymbol.exports) {
  20837. if (id !== "export=") {
  20838. return true;
  20839. }
  20840. }
  20841. return false;
  20842. }
  20843. function checkExternalModuleExports(node) {
  20844. var moduleSymbol = getSymbolOfNode(node);
  20845. var links = getSymbolLinks(moduleSymbol);
  20846. if (!links.exportsChecked) {
  20847. var exportEqualsSymbol = moduleSymbol.exports["export="];
  20848. if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) {
  20849. var declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration;
  20850. error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
  20851. }
  20852. links.exportsChecked = true;
  20853. }
  20854. }
  20855. function checkTypePredicate(node) {
  20856. if (!isInLegalTypePredicatePosition(node)) {
  20857. error(node, ts.Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
  20858. }
  20859. }
  20860. function checkSourceElement(node) {
  20861. if (!node) {
  20862. return;
  20863. }
  20864. var kind = node.kind;
  20865. if (cancellationToken) {
  20866. switch (kind) {
  20867. case 218:
  20868. case 214:
  20869. case 215:
  20870. case 213:
  20871. cancellationToken.throwIfCancellationRequested();
  20872. }
  20873. }
  20874. switch (kind) {
  20875. case 137:
  20876. return checkTypeParameter(node);
  20877. case 138:
  20878. return checkParameter(node);
  20879. case 141:
  20880. case 140:
  20881. return checkPropertyDeclaration(node);
  20882. case 152:
  20883. case 153:
  20884. case 147:
  20885. case 148:
  20886. return checkSignatureDeclaration(node);
  20887. case 149:
  20888. return checkSignatureDeclaration(node);
  20889. case 143:
  20890. case 142:
  20891. return checkMethodDeclaration(node);
  20892. case 144:
  20893. return checkConstructorDeclaration(node);
  20894. case 145:
  20895. case 146:
  20896. return checkAccessorDeclaration(node);
  20897. case 151:
  20898. return checkTypeReferenceNode(node);
  20899. case 150:
  20900. return checkTypePredicate(node);
  20901. case 154:
  20902. return checkTypeQuery(node);
  20903. case 155:
  20904. return checkTypeLiteral(node);
  20905. case 156:
  20906. return checkArrayType(node);
  20907. case 157:
  20908. return checkTupleType(node);
  20909. case 158:
  20910. case 159:
  20911. return checkUnionOrIntersectionType(node);
  20912. case 160:
  20913. return checkSourceElement(node.type);
  20914. case 213:
  20915. return checkFunctionDeclaration(node);
  20916. case 192:
  20917. case 219:
  20918. return checkBlock(node);
  20919. case 193:
  20920. return checkVariableStatement(node);
  20921. case 195:
  20922. return checkExpressionStatement(node);
  20923. case 196:
  20924. return checkIfStatement(node);
  20925. case 197:
  20926. return checkDoStatement(node);
  20927. case 198:
  20928. return checkWhileStatement(node);
  20929. case 199:
  20930. return checkForStatement(node);
  20931. case 200:
  20932. return checkForInStatement(node);
  20933. case 201:
  20934. return checkForOfStatement(node);
  20935. case 202:
  20936. case 203:
  20937. return checkBreakOrContinueStatement(node);
  20938. case 204:
  20939. return checkReturnStatement(node);
  20940. case 205:
  20941. return checkWithStatement(node);
  20942. case 206:
  20943. return checkSwitchStatement(node);
  20944. case 207:
  20945. return checkLabeledStatement(node);
  20946. case 208:
  20947. return checkThrowStatement(node);
  20948. case 209:
  20949. return checkTryStatement(node);
  20950. case 211:
  20951. return checkVariableDeclaration(node);
  20952. case 163:
  20953. return checkBindingElement(node);
  20954. case 214:
  20955. return checkClassDeclaration(node);
  20956. case 215:
  20957. return checkInterfaceDeclaration(node);
  20958. case 216:
  20959. return checkTypeAliasDeclaration(node);
  20960. case 217:
  20961. return checkEnumDeclaration(node);
  20962. case 218:
  20963. return checkModuleDeclaration(node);
  20964. case 222:
  20965. return checkImportDeclaration(node);
  20966. case 221:
  20967. return checkImportEqualsDeclaration(node);
  20968. case 228:
  20969. return checkExportDeclaration(node);
  20970. case 227:
  20971. return checkExportAssignment(node);
  20972. case 194:
  20973. checkGrammarStatementInAmbientContext(node);
  20974. return;
  20975. case 210:
  20976. checkGrammarStatementInAmbientContext(node);
  20977. return;
  20978. case 231:
  20979. return checkMissingDeclaration(node);
  20980. }
  20981. }
  20982. function checkFunctionAndClassExpressionBodies(node) {
  20983. switch (node.kind) {
  20984. case 173:
  20985. case 174:
  20986. ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
  20987. checkFunctionExpressionOrObjectLiteralMethodBody(node);
  20988. break;
  20989. case 186:
  20990. ts.forEach(node.members, checkSourceElement);
  20991. ts.forEachChild(node, checkFunctionAndClassExpressionBodies);
  20992. break;
  20993. case 143:
  20994. case 142:
  20995. ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies);
  20996. ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
  20997. if (ts.isObjectLiteralMethod(node)) {
  20998. checkFunctionExpressionOrObjectLiteralMethodBody(node);
  20999. }
  21000. break;
  21001. case 144:
  21002. case 145:
  21003. case 146:
  21004. case 213:
  21005. ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
  21006. break;
  21007. case 205:
  21008. checkFunctionAndClassExpressionBodies(node.expression);
  21009. break;
  21010. case 139:
  21011. case 138:
  21012. case 141:
  21013. case 140:
  21014. case 161:
  21015. case 162:
  21016. case 163:
  21017. case 164:
  21018. case 165:
  21019. case 245:
  21020. case 166:
  21021. case 167:
  21022. case 168:
  21023. case 169:
  21024. case 170:
  21025. case 183:
  21026. case 190:
  21027. case 171:
  21028. case 189:
  21029. case 172:
  21030. case 176:
  21031. case 177:
  21032. case 178:
  21033. case 175:
  21034. case 179:
  21035. case 180:
  21036. case 181:
  21037. case 182:
  21038. case 185:
  21039. case 184:
  21040. case 192:
  21041. case 219:
  21042. case 193:
  21043. case 195:
  21044. case 196:
  21045. case 197:
  21046. case 198:
  21047. case 199:
  21048. case 200:
  21049. case 201:
  21050. case 202:
  21051. case 203:
  21052. case 204:
  21053. case 206:
  21054. case 220:
  21055. case 241:
  21056. case 242:
  21057. case 207:
  21058. case 208:
  21059. case 209:
  21060. case 244:
  21061. case 211:
  21062. case 212:
  21063. case 214:
  21064. case 243:
  21065. case 188:
  21066. case 217:
  21067. case 247:
  21068. case 227:
  21069. case 248:
  21070. case 240:
  21071. case 233:
  21072. case 234:
  21073. case 238:
  21074. case 239:
  21075. case 235:
  21076. ts.forEachChild(node, checkFunctionAndClassExpressionBodies);
  21077. break;
  21078. }
  21079. }
  21080. function checkSourceFile(node) {
  21081. var start = new Date().getTime();
  21082. checkSourceFileWorker(node);
  21083. ts.checkTime += new Date().getTime() - start;
  21084. }
  21085. function checkSourceFileWorker(node) {
  21086. var links = getNodeLinks(node);
  21087. if (!(links.flags & 1)) {
  21088. if (node.isDefaultLib && compilerOptions.skipDefaultLibCheck) {
  21089. return;
  21090. }
  21091. checkGrammarSourceFile(node);
  21092. emitExtends = false;
  21093. emitDecorate = false;
  21094. emitParam = false;
  21095. potentialThisCollisions.length = 0;
  21096. ts.forEach(node.statements, checkSourceElement);
  21097. checkFunctionAndClassExpressionBodies(node);
  21098. if (ts.isExternalModule(node)) {
  21099. checkExternalModuleExports(node);
  21100. }
  21101. if (potentialThisCollisions.length) {
  21102. ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope);
  21103. potentialThisCollisions.length = 0;
  21104. }
  21105. if (emitExtends) {
  21106. links.flags |= 8;
  21107. }
  21108. if (emitDecorate) {
  21109. links.flags |= 16;
  21110. }
  21111. if (emitParam) {
  21112. links.flags |= 32;
  21113. }
  21114. if (emitAwaiter) {
  21115. links.flags |= 64;
  21116. }
  21117. if (emitGenerator || (emitAwaiter && languageVersion < 2)) {
  21118. links.flags |= 128;
  21119. }
  21120. links.flags |= 1;
  21121. }
  21122. }
  21123. function getDiagnostics(sourceFile, ct) {
  21124. try {
  21125. cancellationToken = ct;
  21126. return getDiagnosticsWorker(sourceFile);
  21127. }
  21128. finally {
  21129. cancellationToken = undefined;
  21130. }
  21131. }
  21132. function getDiagnosticsWorker(sourceFile) {
  21133. throwIfNonDiagnosticsProducing();
  21134. if (sourceFile) {
  21135. checkSourceFile(sourceFile);
  21136. return diagnostics.getDiagnostics(sourceFile.fileName);
  21137. }
  21138. ts.forEach(host.getSourceFiles(), checkSourceFile);
  21139. return diagnostics.getDiagnostics();
  21140. }
  21141. function getGlobalDiagnostics() {
  21142. throwIfNonDiagnosticsProducing();
  21143. return diagnostics.getGlobalDiagnostics();
  21144. }
  21145. function throwIfNonDiagnosticsProducing() {
  21146. if (!produceDiagnostics) {
  21147. throw new Error("Trying to get diagnostics from a type checker that does not produce them.");
  21148. }
  21149. }
  21150. function isInsideWithStatementBody(node) {
  21151. if (node) {
  21152. while (node.parent) {
  21153. if (node.parent.kind === 205 && node.parent.statement === node) {
  21154. return true;
  21155. }
  21156. node = node.parent;
  21157. }
  21158. }
  21159. return false;
  21160. }
  21161. function getSymbolsInScope(location, meaning) {
  21162. var symbols = {};
  21163. var memberFlags = 0;
  21164. if (isInsideWithStatementBody(location)) {
  21165. return [];
  21166. }
  21167. populateSymbols();
  21168. return symbolsToArray(symbols);
  21169. function populateSymbols() {
  21170. while (location) {
  21171. if (location.locals && !isGlobalSourceFile(location)) {
  21172. copySymbols(location.locals, meaning);
  21173. }
  21174. switch (location.kind) {
  21175. case 248:
  21176. if (!ts.isExternalModule(location)) {
  21177. break;
  21178. }
  21179. case 218:
  21180. copySymbols(getSymbolOfNode(location).exports, meaning & 8914931);
  21181. break;
  21182. case 217:
  21183. copySymbols(getSymbolOfNode(location).exports, meaning & 8);
  21184. break;
  21185. case 186:
  21186. var className = location.name;
  21187. if (className) {
  21188. copySymbol(location.symbol, meaning);
  21189. }
  21190. case 214:
  21191. case 215:
  21192. if (!(memberFlags & 128)) {
  21193. copySymbols(getSymbolOfNode(location).members, meaning & 793056);
  21194. }
  21195. break;
  21196. case 173:
  21197. var funcName = location.name;
  21198. if (funcName) {
  21199. copySymbol(location.symbol, meaning);
  21200. }
  21201. break;
  21202. }
  21203. if (ts.introducesArgumentsExoticObject(location)) {
  21204. copySymbol(argumentsSymbol, meaning);
  21205. }
  21206. memberFlags = location.flags;
  21207. location = location.parent;
  21208. }
  21209. copySymbols(globals, meaning);
  21210. }
  21211. function copySymbol(symbol, meaning) {
  21212. if (symbol.flags & meaning) {
  21213. var id = symbol.name;
  21214. if (!ts.hasProperty(symbols, id)) {
  21215. symbols[id] = symbol;
  21216. }
  21217. }
  21218. }
  21219. function copySymbols(source, meaning) {
  21220. if (meaning) {
  21221. for (var id in source) {
  21222. var symbol = source[id];
  21223. copySymbol(symbol, meaning);
  21224. }
  21225. }
  21226. }
  21227. }
  21228. function isTypeDeclarationName(name) {
  21229. return name.kind === 69 &&
  21230. isTypeDeclaration(name.parent) &&
  21231. name.parent.name === name;
  21232. }
  21233. function isTypeDeclaration(node) {
  21234. switch (node.kind) {
  21235. case 137:
  21236. case 214:
  21237. case 215:
  21238. case 216:
  21239. case 217:
  21240. return true;
  21241. }
  21242. }
  21243. function isTypeReferenceIdentifier(entityName) {
  21244. var node = entityName;
  21245. while (node.parent && node.parent.kind === 135) {
  21246. node = node.parent;
  21247. }
  21248. return node.parent && node.parent.kind === 151;
  21249. }
  21250. function isHeritageClauseElementIdentifier(entityName) {
  21251. var node = entityName;
  21252. while (node.parent && node.parent.kind === 166) {
  21253. node = node.parent;
  21254. }
  21255. return node.parent && node.parent.kind === 188;
  21256. }
  21257. function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) {
  21258. while (nodeOnRightSide.parent.kind === 135) {
  21259. nodeOnRightSide = nodeOnRightSide.parent;
  21260. }
  21261. if (nodeOnRightSide.parent.kind === 221) {
  21262. return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent;
  21263. }
  21264. if (nodeOnRightSide.parent.kind === 227) {
  21265. return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent;
  21266. }
  21267. return undefined;
  21268. }
  21269. function isInRightSideOfImportOrExportAssignment(node) {
  21270. return getLeftSideOfImportEqualsOrExportAssignment(node) !== undefined;
  21271. }
  21272. function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) {
  21273. if (ts.isDeclarationName(entityName)) {
  21274. return getSymbolOfNode(entityName.parent);
  21275. }
  21276. if (entityName.parent.kind === 227) {
  21277. return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608);
  21278. }
  21279. if (entityName.kind !== 166) {
  21280. if (isInRightSideOfImportOrExportAssignment(entityName)) {
  21281. return getSymbolOfPartOfRightHandSideOfImportEquals(entityName);
  21282. }
  21283. }
  21284. if (ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
  21285. entityName = entityName.parent;
  21286. }
  21287. if (isHeritageClauseElementIdentifier(entityName)) {
  21288. var meaning = 0;
  21289. if (entityName.parent.kind === 188) {
  21290. meaning = 793056;
  21291. if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent)) {
  21292. meaning |= 107455;
  21293. }
  21294. }
  21295. else {
  21296. meaning = 1536;
  21297. }
  21298. meaning |= 8388608;
  21299. return resolveEntityName(entityName, meaning);
  21300. }
  21301. else if ((entityName.parent.kind === 235) ||
  21302. (entityName.parent.kind === 234) ||
  21303. (entityName.parent.kind === 237)) {
  21304. return getJsxElementTagSymbol(entityName.parent);
  21305. }
  21306. else if (ts.isExpression(entityName)) {
  21307. if (ts.nodeIsMissing(entityName)) {
  21308. return undefined;
  21309. }
  21310. if (entityName.kind === 69) {
  21311. var meaning = 107455 | 8388608;
  21312. return resolveEntityName(entityName, meaning);
  21313. }
  21314. else if (entityName.kind === 166) {
  21315. var symbol = getNodeLinks(entityName).resolvedSymbol;
  21316. if (!symbol) {
  21317. checkPropertyAccessExpression(entityName);
  21318. }
  21319. return getNodeLinks(entityName).resolvedSymbol;
  21320. }
  21321. else if (entityName.kind === 135) {
  21322. var symbol = getNodeLinks(entityName).resolvedSymbol;
  21323. if (!symbol) {
  21324. checkQualifiedName(entityName);
  21325. }
  21326. return getNodeLinks(entityName).resolvedSymbol;
  21327. }
  21328. }
  21329. else if (isTypeReferenceIdentifier(entityName)) {
  21330. var meaning = entityName.parent.kind === 151 ? 793056 : 1536;
  21331. meaning |= 8388608;
  21332. return resolveEntityName(entityName, meaning);
  21333. }
  21334. else if (entityName.parent.kind === 238) {
  21335. return getJsxAttributePropertySymbol(entityName.parent);
  21336. }
  21337. if (entityName.parent.kind === 150) {
  21338. return resolveEntityName(entityName, 1);
  21339. }
  21340. return undefined;
  21341. }
  21342. function getSymbolAtLocation(node) {
  21343. if (isInsideWithStatementBody(node)) {
  21344. return undefined;
  21345. }
  21346. if (ts.isDeclarationName(node)) {
  21347. return getSymbolOfNode(node.parent);
  21348. }
  21349. if (node.kind === 69) {
  21350. if (isInRightSideOfImportOrExportAssignment(node)) {
  21351. return node.parent.kind === 227
  21352. ? getSymbolOfEntityNameOrPropertyAccessExpression(node)
  21353. : getSymbolOfPartOfRightHandSideOfImportEquals(node);
  21354. }
  21355. else if (node.parent.kind === 163 &&
  21356. node.parent.parent.kind === 161 &&
  21357. node === node.parent.propertyName) {
  21358. var typeOfPattern = getTypeOfNode(node.parent.parent);
  21359. var propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, node.text);
  21360. if (propertyDeclaration) {
  21361. return propertyDeclaration;
  21362. }
  21363. }
  21364. }
  21365. switch (node.kind) {
  21366. case 69:
  21367. case 166:
  21368. case 135:
  21369. return getSymbolOfEntityNameOrPropertyAccessExpression(node);
  21370. case 97:
  21371. case 95:
  21372. var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node);
  21373. return type.symbol;
  21374. case 121:
  21375. var constructorDeclaration = node.parent;
  21376. if (constructorDeclaration && constructorDeclaration.kind === 144) {
  21377. return constructorDeclaration.parent.symbol;
  21378. }
  21379. return undefined;
  21380. case 9:
  21381. if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
  21382. ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
  21383. ((node.parent.kind === 222 || node.parent.kind === 228) &&
  21384. node.parent.moduleSpecifier === node)) {
  21385. return resolveExternalModuleName(node, node);
  21386. }
  21387. case 8:
  21388. if (node.parent.kind === 167 && node.parent.argumentExpression === node) {
  21389. var objectType = checkExpression(node.parent.expression);
  21390. if (objectType === unknownType)
  21391. return undefined;
  21392. var apparentType = getApparentType(objectType);
  21393. if (apparentType === unknownType)
  21394. return undefined;
  21395. return getPropertyOfType(apparentType, node.text);
  21396. }
  21397. break;
  21398. }
  21399. return undefined;
  21400. }
  21401. function getShorthandAssignmentValueSymbol(location) {
  21402. if (location && location.kind === 246) {
  21403. return resolveEntityName(location.name, 107455);
  21404. }
  21405. return undefined;
  21406. }
  21407. function getTypeOfNode(node) {
  21408. if (isInsideWithStatementBody(node)) {
  21409. return unknownType;
  21410. }
  21411. if (ts.isTypeNode(node)) {
  21412. return getTypeFromTypeNode(node);
  21413. }
  21414. if (ts.isExpression(node)) {
  21415. return getTypeOfExpression(node);
  21416. }
  21417. if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(node)) {
  21418. return getBaseTypes(getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0];
  21419. }
  21420. if (isTypeDeclaration(node)) {
  21421. var symbol = getSymbolOfNode(node);
  21422. return getDeclaredTypeOfSymbol(symbol);
  21423. }
  21424. if (isTypeDeclarationName(node)) {
  21425. var symbol = getSymbolAtLocation(node);
  21426. return symbol && getDeclaredTypeOfSymbol(symbol);
  21427. }
  21428. if (ts.isDeclaration(node)) {
  21429. var symbol = getSymbolOfNode(node);
  21430. return getTypeOfSymbol(symbol);
  21431. }
  21432. if (ts.isDeclarationName(node)) {
  21433. var symbol = getSymbolAtLocation(node);
  21434. return symbol && getTypeOfSymbol(symbol);
  21435. }
  21436. if (ts.isBindingPattern(node)) {
  21437. return getTypeForVariableLikeDeclaration(node.parent);
  21438. }
  21439. if (isInRightSideOfImportOrExportAssignment(node)) {
  21440. var symbol = getSymbolAtLocation(node);
  21441. var declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
  21442. return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
  21443. }
  21444. return unknownType;
  21445. }
  21446. function getTypeOfExpression(expr) {
  21447. if (ts.isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
  21448. expr = expr.parent;
  21449. }
  21450. return checkExpression(expr);
  21451. }
  21452. function getParentTypeOfClassElement(node) {
  21453. var classSymbol = getSymbolOfNode(node.parent);
  21454. return node.flags & 128
  21455. ? getTypeOfSymbol(classSymbol)
  21456. : getDeclaredTypeOfSymbol(classSymbol);
  21457. }
  21458. function getAugmentedPropertiesOfType(type) {
  21459. type = getApparentType(type);
  21460. var propsByName = createSymbolTable(getPropertiesOfType(type));
  21461. if (getSignaturesOfType(type, 0).length || getSignaturesOfType(type, 1).length) {
  21462. ts.forEach(getPropertiesOfType(globalFunctionType), function (p) {
  21463. if (!ts.hasProperty(propsByName, p.name)) {
  21464. propsByName[p.name] = p;
  21465. }
  21466. });
  21467. }
  21468. return getNamedMembers(propsByName);
  21469. }
  21470. function getRootSymbols(symbol) {
  21471. if (symbol.flags & 268435456) {
  21472. var symbols = [];
  21473. var name_15 = symbol.name;
  21474. ts.forEach(getSymbolLinks(symbol).containingType.types, function (t) {
  21475. var symbol = getPropertyOfType(t, name_15);
  21476. if (symbol) {
  21477. symbols.push(symbol);
  21478. }
  21479. });
  21480. return symbols;
  21481. }
  21482. else if (symbol.flags & 67108864) {
  21483. var target = getSymbolLinks(symbol).target;
  21484. if (target) {
  21485. return [target];
  21486. }
  21487. }
  21488. return [symbol];
  21489. }
  21490. function getReferencedExportContainer(node) {
  21491. var symbol = getReferencedValueSymbol(node);
  21492. if (symbol) {
  21493. if (symbol.flags & 1048576) {
  21494. var exportSymbol = getMergedSymbol(symbol.exportSymbol);
  21495. if (exportSymbol.flags & 944) {
  21496. return undefined;
  21497. }
  21498. symbol = exportSymbol;
  21499. }
  21500. var parentSymbol = getParentOfSymbol(symbol);
  21501. if (parentSymbol) {
  21502. if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 248) {
  21503. return parentSymbol.valueDeclaration;
  21504. }
  21505. for (var n = node.parent; n; n = n.parent) {
  21506. if ((n.kind === 218 || n.kind === 217) && getSymbolOfNode(n) === parentSymbol) {
  21507. return n;
  21508. }
  21509. }
  21510. }
  21511. }
  21512. }
  21513. function getReferencedImportDeclaration(node) {
  21514. var symbol = getReferencedValueSymbol(node);
  21515. return symbol && symbol.flags & 8388608 ? getDeclarationOfAliasSymbol(symbol) : undefined;
  21516. }
  21517. function isStatementWithLocals(node) {
  21518. switch (node.kind) {
  21519. case 192:
  21520. case 220:
  21521. case 199:
  21522. case 200:
  21523. case 201:
  21524. return true;
  21525. }
  21526. return false;
  21527. }
  21528. function isNestedRedeclarationSymbol(symbol) {
  21529. if (symbol.flags & 418) {
  21530. var links = getSymbolLinks(symbol);
  21531. if (links.isNestedRedeclaration === undefined) {
  21532. var container = ts.getEnclosingBlockScopeContainer(symbol.valueDeclaration);
  21533. links.isNestedRedeclaration = isStatementWithLocals(container) &&
  21534. !!resolveName(container.parent, symbol.name, 107455, undefined, undefined);
  21535. }
  21536. return links.isNestedRedeclaration;
  21537. }
  21538. return false;
  21539. }
  21540. function getReferencedNestedRedeclaration(node) {
  21541. var symbol = getReferencedValueSymbol(node);
  21542. return symbol && isNestedRedeclarationSymbol(symbol) ? symbol.valueDeclaration : undefined;
  21543. }
  21544. function isNestedRedeclaration(node) {
  21545. return isNestedRedeclarationSymbol(getSymbolOfNode(node));
  21546. }
  21547. function isValueAliasDeclaration(node) {
  21548. switch (node.kind) {
  21549. case 221:
  21550. case 223:
  21551. case 224:
  21552. case 226:
  21553. case 230:
  21554. return isAliasResolvedToValue(getSymbolOfNode(node));
  21555. case 228:
  21556. var exportClause = node.exportClause;
  21557. return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration);
  21558. case 227:
  21559. return node.expression && node.expression.kind === 69 ? isAliasResolvedToValue(getSymbolOfNode(node)) : true;
  21560. }
  21561. return false;
  21562. }
  21563. function isTopLevelValueImportEqualsWithEntityName(node) {
  21564. if (node.parent.kind !== 248 || !ts.isInternalModuleImportEqualsDeclaration(node)) {
  21565. return false;
  21566. }
  21567. var isValue = isAliasResolvedToValue(getSymbolOfNode(node));
  21568. return isValue && node.moduleReference && !ts.nodeIsMissing(node.moduleReference);
  21569. }
  21570. function isAliasResolvedToValue(symbol) {
  21571. var target = resolveAlias(symbol);
  21572. if (target === unknownSymbol && compilerOptions.isolatedModules) {
  21573. return true;
  21574. }
  21575. return target !== unknownSymbol &&
  21576. target &&
  21577. target.flags & 107455 &&
  21578. (compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
  21579. }
  21580. function isConstEnumOrConstEnumOnlyModule(s) {
  21581. return isConstEnumSymbol(s) || s.constEnumOnlyModule;
  21582. }
  21583. function isReferencedAliasDeclaration(node, checkChildren) {
  21584. if (ts.isAliasSymbolDeclaration(node)) {
  21585. var symbol = getSymbolOfNode(node);
  21586. if (getSymbolLinks(symbol).referenced) {
  21587. return true;
  21588. }
  21589. }
  21590. if (checkChildren) {
  21591. return ts.forEachChild(node, function (node) { return isReferencedAliasDeclaration(node, checkChildren); });
  21592. }
  21593. return false;
  21594. }
  21595. function isImplementationOfOverload(node) {
  21596. if (ts.nodeIsPresent(node.body)) {
  21597. var symbol = getSymbolOfNode(node);
  21598. var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
  21599. return signaturesOfSymbol.length > 1 ||
  21600. (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
  21601. }
  21602. return false;
  21603. }
  21604. function getNodeCheckFlags(node) {
  21605. return getNodeLinks(node).flags;
  21606. }
  21607. function getEnumMemberValue(node) {
  21608. computeEnumMemberValues(node.parent);
  21609. return getNodeLinks(node).enumMemberValue;
  21610. }
  21611. function getConstantValue(node) {
  21612. if (node.kind === 247) {
  21613. return getEnumMemberValue(node);
  21614. }
  21615. var symbol = getNodeLinks(node).resolvedSymbol;
  21616. if (symbol && (symbol.flags & 8)) {
  21617. if (ts.isConstEnumDeclaration(symbol.valueDeclaration.parent)) {
  21618. return getEnumMemberValue(symbol.valueDeclaration);
  21619. }
  21620. }
  21621. return undefined;
  21622. }
  21623. function isFunctionType(type) {
  21624. return type.flags & 80896 && getSignaturesOfType(type, 0).length > 0;
  21625. }
  21626. function getTypeReferenceSerializationKind(typeName) {
  21627. var valueSymbol = resolveEntityName(typeName, 107455, true);
  21628. var constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
  21629. if (constructorType && isConstructorType(constructorType)) {
  21630. return ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
  21631. }
  21632. var typeSymbol = resolveEntityName(typeName, 793056, true);
  21633. if (!typeSymbol) {
  21634. return ts.TypeReferenceSerializationKind.ObjectType;
  21635. }
  21636. var type = getDeclaredTypeOfSymbol(typeSymbol);
  21637. if (type === unknownType) {
  21638. return ts.TypeReferenceSerializationKind.Unknown;
  21639. }
  21640. else if (type.flags & 1) {
  21641. return ts.TypeReferenceSerializationKind.ObjectType;
  21642. }
  21643. else if (allConstituentTypesHaveKind(type, 16)) {
  21644. return ts.TypeReferenceSerializationKind.VoidType;
  21645. }
  21646. else if (allConstituentTypesHaveKind(type, 8)) {
  21647. return ts.TypeReferenceSerializationKind.BooleanType;
  21648. }
  21649. else if (allConstituentTypesHaveKind(type, 132)) {
  21650. return ts.TypeReferenceSerializationKind.NumberLikeType;
  21651. }
  21652. else if (allConstituentTypesHaveKind(type, 258)) {
  21653. return ts.TypeReferenceSerializationKind.StringLikeType;
  21654. }
  21655. else if (allConstituentTypesHaveKind(type, 8192)) {
  21656. return ts.TypeReferenceSerializationKind.ArrayLikeType;
  21657. }
  21658. else if (allConstituentTypesHaveKind(type, 16777216)) {
  21659. return ts.TypeReferenceSerializationKind.ESSymbolType;
  21660. }
  21661. else if (isFunctionType(type)) {
  21662. return ts.TypeReferenceSerializationKind.TypeWithCallSignature;
  21663. }
  21664. else if (isArrayType(type)) {
  21665. return ts.TypeReferenceSerializationKind.ArrayLikeType;
  21666. }
  21667. else {
  21668. return ts.TypeReferenceSerializationKind.ObjectType;
  21669. }
  21670. }
  21671. function writeTypeOfDeclaration(declaration, enclosingDeclaration, flags, writer) {
  21672. var symbol = getSymbolOfNode(declaration);
  21673. var type = symbol && !(symbol.flags & (2048 | 131072))
  21674. ? getTypeOfSymbol(symbol)
  21675. : unknownType;
  21676. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  21677. }
  21678. function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) {
  21679. var signature = getSignatureFromDeclaration(signatureDeclaration);
  21680. getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
  21681. }
  21682. function writeTypeOfExpression(expr, enclosingDeclaration, flags, writer) {
  21683. var type = getTypeOfExpression(expr);
  21684. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  21685. }
  21686. function hasGlobalName(name) {
  21687. return ts.hasProperty(globals, name);
  21688. }
  21689. function getReferencedValueSymbol(reference) {
  21690. return getNodeLinks(reference).resolvedSymbol ||
  21691. resolveName(reference, reference.text, 107455 | 1048576 | 8388608, undefined, undefined);
  21692. }
  21693. function getReferencedValueDeclaration(reference) {
  21694. ts.Debug.assert(!ts.nodeIsSynthesized(reference));
  21695. var symbol = getReferencedValueSymbol(reference);
  21696. return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
  21697. }
  21698. function instantiateSingleCallFunctionType(functionType, typeArguments) {
  21699. if (functionType === unknownType) {
  21700. return unknownType;
  21701. }
  21702. var signature = getSingleCallSignature(functionType);
  21703. if (!signature) {
  21704. return unknownType;
  21705. }
  21706. var instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
  21707. return getOrCreateTypeFromSignature(instantiatedSignature);
  21708. }
  21709. function createResolver() {
  21710. return {
  21711. getReferencedExportContainer: getReferencedExportContainer,
  21712. getReferencedImportDeclaration: getReferencedImportDeclaration,
  21713. getReferencedNestedRedeclaration: getReferencedNestedRedeclaration,
  21714. isNestedRedeclaration: isNestedRedeclaration,
  21715. isValueAliasDeclaration: isValueAliasDeclaration,
  21716. hasGlobalName: hasGlobalName,
  21717. isReferencedAliasDeclaration: isReferencedAliasDeclaration,
  21718. getNodeCheckFlags: getNodeCheckFlags,
  21719. isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName,
  21720. isDeclarationVisible: isDeclarationVisible,
  21721. isImplementationOfOverload: isImplementationOfOverload,
  21722. writeTypeOfDeclaration: writeTypeOfDeclaration,
  21723. writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration,
  21724. writeTypeOfExpression: writeTypeOfExpression,
  21725. isSymbolAccessible: isSymbolAccessible,
  21726. isEntityNameVisible: isEntityNameVisible,
  21727. getConstantValue: getConstantValue,
  21728. collectLinkedAliases: collectLinkedAliases,
  21729. getReferencedValueDeclaration: getReferencedValueDeclaration,
  21730. getTypeReferenceSerializationKind: getTypeReferenceSerializationKind,
  21731. isOptionalParameter: isOptionalParameter
  21732. };
  21733. }
  21734. function initializeTypeChecker() {
  21735. ts.forEach(host.getSourceFiles(), function (file) {
  21736. ts.bindSourceFile(file);
  21737. });
  21738. ts.forEach(host.getSourceFiles(), function (file) {
  21739. if (!ts.isExternalModule(file)) {
  21740. mergeSymbolTable(globals, file.locals);
  21741. }
  21742. });
  21743. getSymbolLinks(undefinedSymbol).type = undefinedType;
  21744. getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
  21745. getSymbolLinks(unknownSymbol).type = unknownType;
  21746. globals[undefinedSymbol.name] = undefinedSymbol;
  21747. globalArrayType = getGlobalType("Array", 1);
  21748. globalObjectType = getGlobalType("Object");
  21749. globalFunctionType = getGlobalType("Function");
  21750. globalStringType = getGlobalType("String");
  21751. globalNumberType = getGlobalType("Number");
  21752. globalBooleanType = getGlobalType("Boolean");
  21753. globalRegExpType = getGlobalType("RegExp");
  21754. jsxElementType = getExportedTypeFromNamespace("JSX", JsxNames.Element);
  21755. getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); });
  21756. getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); });
  21757. getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); });
  21758. getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); });
  21759. getGlobalTypedPropertyDescriptorType = ts.memoize(function () { return getGlobalType("TypedPropertyDescriptor", 1); });
  21760. getGlobalPromiseType = ts.memoize(function () { return getGlobalType("Promise", 1); });
  21761. tryGetGlobalPromiseType = ts.memoize(function () { return getGlobalSymbol("Promise", 793056, undefined) && getGlobalPromiseType(); });
  21762. getGlobalPromiseLikeType = ts.memoize(function () { return getGlobalType("PromiseLike", 1); });
  21763. getInstantiatedGlobalPromiseLikeType = ts.memoize(createInstantiatedPromiseLikeType);
  21764. getGlobalPromiseConstructorSymbol = ts.memoize(function () { return getGlobalValueSymbol("Promise"); });
  21765. getGlobalPromiseConstructorLikeType = ts.memoize(function () { return getGlobalType("PromiseConstructorLike"); });
  21766. getGlobalThenableType = ts.memoize(createThenableType);
  21767. if (languageVersion >= 2) {
  21768. globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray");
  21769. globalESSymbolType = getGlobalType("Symbol");
  21770. globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol");
  21771. globalIterableType = getGlobalType("Iterable", 1);
  21772. globalIteratorType = getGlobalType("Iterator", 1);
  21773. globalIterableIteratorType = getGlobalType("IterableIterator", 1);
  21774. }
  21775. else {
  21776. globalTemplateStringsArrayType = unknownType;
  21777. globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  21778. globalESSymbolConstructorSymbol = undefined;
  21779. globalIterableType = emptyGenericType;
  21780. globalIteratorType = emptyGenericType;
  21781. globalIterableIteratorType = emptyGenericType;
  21782. }
  21783. anyArrayType = createArrayType(anyType);
  21784. }
  21785. function createInstantiatedPromiseLikeType() {
  21786. var promiseLikeType = getGlobalPromiseLikeType();
  21787. if (promiseLikeType !== emptyGenericType) {
  21788. return createTypeReference(promiseLikeType, [anyType]);
  21789. }
  21790. return emptyObjectType;
  21791. }
  21792. function createThenableType() {
  21793. var thenPropertySymbol = createSymbol(67108864 | 4, "then");
  21794. getSymbolLinks(thenPropertySymbol).type = globalFunctionType;
  21795. var thenableType = createObjectType(65536);
  21796. thenableType.properties = [thenPropertySymbol];
  21797. thenableType.members = createSymbolTable(thenableType.properties);
  21798. thenableType.callSignatures = [];
  21799. thenableType.constructSignatures = [];
  21800. return thenableType;
  21801. }
  21802. function checkGrammarDecorators(node) {
  21803. if (!node.decorators) {
  21804. return false;
  21805. }
  21806. if (!ts.nodeCanBeDecorated(node)) {
  21807. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here);
  21808. }
  21809. else if (node.kind === 145 || node.kind === 146) {
  21810. var accessors = ts.getAllAccessorDeclarations(node.parent.members, node);
  21811. if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) {
  21812. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name);
  21813. }
  21814. }
  21815. return false;
  21816. }
  21817. function checkGrammarModifiers(node) {
  21818. switch (node.kind) {
  21819. case 145:
  21820. case 146:
  21821. case 144:
  21822. case 141:
  21823. case 140:
  21824. case 143:
  21825. case 142:
  21826. case 149:
  21827. case 218:
  21828. case 222:
  21829. case 221:
  21830. case 228:
  21831. case 227:
  21832. case 138:
  21833. break;
  21834. case 213:
  21835. if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 118) &&
  21836. node.parent.kind !== 219 && node.parent.kind !== 248) {
  21837. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  21838. }
  21839. break;
  21840. case 214:
  21841. case 215:
  21842. case 193:
  21843. case 216:
  21844. if (node.modifiers && node.parent.kind !== 219 && node.parent.kind !== 248) {
  21845. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  21846. }
  21847. break;
  21848. case 217:
  21849. if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 74) &&
  21850. node.parent.kind !== 219 && node.parent.kind !== 248) {
  21851. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  21852. }
  21853. break;
  21854. default:
  21855. return false;
  21856. }
  21857. if (!node.modifiers) {
  21858. return;
  21859. }
  21860. var lastStatic, lastPrivate, lastProtected, lastDeclare, lastAsync;
  21861. var flags = 0;
  21862. for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
  21863. var modifier = _a[_i];
  21864. switch (modifier.kind) {
  21865. case 112:
  21866. case 111:
  21867. case 110:
  21868. var text = void 0;
  21869. if (modifier.kind === 112) {
  21870. text = "public";
  21871. }
  21872. else if (modifier.kind === 111) {
  21873. text = "protected";
  21874. lastProtected = modifier;
  21875. }
  21876. else {
  21877. text = "private";
  21878. lastPrivate = modifier;
  21879. }
  21880. if (flags & 112) {
  21881. return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen);
  21882. }
  21883. else if (flags & 128) {
  21884. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static");
  21885. }
  21886. else if (flags & 512) {
  21887. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async");
  21888. }
  21889. else if (node.parent.kind === 219 || node.parent.kind === 248) {
  21890. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
  21891. }
  21892. else if (flags & 256) {
  21893. if (modifier.kind === 110) {
  21894. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract");
  21895. }
  21896. else {
  21897. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "abstract");
  21898. }
  21899. }
  21900. flags |= ts.modifierToFlag(modifier.kind);
  21901. break;
  21902. case 113:
  21903. if (flags & 128) {
  21904. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static");
  21905. }
  21906. else if (flags & 512) {
  21907. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async");
  21908. }
  21909. else if (node.parent.kind === 219 || node.parent.kind === 248) {
  21910. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
  21911. }
  21912. else if (node.kind === 138) {
  21913. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
  21914. }
  21915. else if (flags & 256) {
  21916. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract");
  21917. }
  21918. flags |= 128;
  21919. lastStatic = modifier;
  21920. break;
  21921. case 82:
  21922. if (flags & 1) {
  21923. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export");
  21924. }
  21925. else if (flags & 2) {
  21926. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
  21927. }
  21928. else if (flags & 256) {
  21929. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "abstract");
  21930. }
  21931. else if (flags & 512) {
  21932. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async");
  21933. }
  21934. else if (node.parent.kind === 214) {
  21935. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
  21936. }
  21937. else if (node.kind === 138) {
  21938. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
  21939. }
  21940. flags |= 1;
  21941. break;
  21942. case 122:
  21943. if (flags & 2) {
  21944. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare");
  21945. }
  21946. else if (flags & 512) {
  21947. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
  21948. }
  21949. else if (node.parent.kind === 214) {
  21950. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
  21951. }
  21952. else if (node.kind === 138) {
  21953. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
  21954. }
  21955. else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 219) {
  21956. return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
  21957. }
  21958. flags |= 2;
  21959. lastDeclare = modifier;
  21960. break;
  21961. case 115:
  21962. if (flags & 256) {
  21963. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract");
  21964. }
  21965. if (node.kind !== 214) {
  21966. if (node.kind !== 143) {
  21967. return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration);
  21968. }
  21969. if (!(node.parent.kind === 214 && node.parent.flags & 256)) {
  21970. return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class);
  21971. }
  21972. if (flags & 128) {
  21973. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract");
  21974. }
  21975. if (flags & 32) {
  21976. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "private", "abstract");
  21977. }
  21978. }
  21979. flags |= 256;
  21980. break;
  21981. case 118:
  21982. if (flags & 512) {
  21983. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async");
  21984. }
  21985. else if (flags & 2 || ts.isInAmbientContext(node.parent)) {
  21986. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
  21987. }
  21988. else if (node.kind === 138) {
  21989. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async");
  21990. }
  21991. flags |= 512;
  21992. lastAsync = modifier;
  21993. break;
  21994. }
  21995. }
  21996. if (node.kind === 144) {
  21997. if (flags & 128) {
  21998. return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
  21999. }
  22000. if (flags & 256) {
  22001. return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract");
  22002. }
  22003. else if (flags & 64) {
  22004. return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
  22005. }
  22006. else if (flags & 32) {
  22007. return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
  22008. }
  22009. else if (flags & 512) {
  22010. return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async");
  22011. }
  22012. return;
  22013. }
  22014. else if ((node.kind === 222 || node.kind === 221) && flags & 2) {
  22015. return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare");
  22016. }
  22017. else if (node.kind === 138 && (flags & 112) && ts.isBindingPattern(node.name)) {
  22018. return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
  22019. }
  22020. if (flags & 512) {
  22021. return checkGrammarAsyncModifier(node, lastAsync);
  22022. }
  22023. }
  22024. function checkGrammarAsyncModifier(node, asyncModifier) {
  22025. if (languageVersion < 2) {
  22026. return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher);
  22027. }
  22028. switch (node.kind) {
  22029. case 143:
  22030. case 213:
  22031. case 173:
  22032. case 174:
  22033. if (!node.asteriskToken) {
  22034. return false;
  22035. }
  22036. break;
  22037. }
  22038. return grammarErrorOnNode(asyncModifier, ts.Diagnostics._0_modifier_cannot_be_used_here, "async");
  22039. }
  22040. function checkGrammarForDisallowedTrailingComma(list) {
  22041. if (list && list.hasTrailingComma) {
  22042. var start = list.end - ",".length;
  22043. var end = list.end;
  22044. var sourceFile = ts.getSourceFileOfNode(list[0]);
  22045. return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Trailing_comma_not_allowed);
  22046. }
  22047. }
  22048. function checkGrammarTypeParameterList(node, typeParameters, file) {
  22049. if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
  22050. return true;
  22051. }
  22052. if (typeParameters && typeParameters.length === 0) {
  22053. var start = typeParameters.pos - "<".length;
  22054. var end = ts.skipTrivia(file.text, typeParameters.end) + ">".length;
  22055. return grammarErrorAtPos(file, start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
  22056. }
  22057. }
  22058. function checkGrammarParameterList(parameters) {
  22059. if (checkGrammarForDisallowedTrailingComma(parameters)) {
  22060. return true;
  22061. }
  22062. var seenOptionalParameter = false;
  22063. var parameterCount = parameters.length;
  22064. for (var i = 0; i < parameterCount; i++) {
  22065. var parameter = parameters[i];
  22066. if (parameter.dotDotDotToken) {
  22067. if (i !== (parameterCount - 1)) {
  22068. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
  22069. }
  22070. if (ts.isBindingPattern(parameter.name)) {
  22071. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
  22072. }
  22073. if (parameter.questionToken) {
  22074. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
  22075. }
  22076. if (parameter.initializer) {
  22077. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
  22078. }
  22079. }
  22080. else if (parameter.questionToken) {
  22081. seenOptionalParameter = true;
  22082. if (parameter.initializer) {
  22083. return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
  22084. }
  22085. }
  22086. else if (seenOptionalParameter && !parameter.initializer) {
  22087. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
  22088. }
  22089. }
  22090. }
  22091. function checkGrammarFunctionLikeDeclaration(node) {
  22092. var file = ts.getSourceFileOfNode(node);
  22093. return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
  22094. checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
  22095. }
  22096. function checkGrammarArrowFunction(node, file) {
  22097. if (node.kind === 174) {
  22098. var arrowFunction = node;
  22099. var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line;
  22100. var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line;
  22101. if (startLine !== endLine) {
  22102. return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, ts.Diagnostics.Line_terminator_not_permitted_before_arrow);
  22103. }
  22104. }
  22105. return false;
  22106. }
  22107. function checkGrammarIndexSignatureParameters(node) {
  22108. var parameter = node.parameters[0];
  22109. if (node.parameters.length !== 1) {
  22110. if (parameter) {
  22111. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
  22112. }
  22113. else {
  22114. return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
  22115. }
  22116. }
  22117. if (parameter.dotDotDotToken) {
  22118. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
  22119. }
  22120. if (parameter.flags & 2035) {
  22121. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
  22122. }
  22123. if (parameter.questionToken) {
  22124. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
  22125. }
  22126. if (parameter.initializer) {
  22127. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
  22128. }
  22129. if (!parameter.type) {
  22130. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
  22131. }
  22132. if (parameter.type.kind !== 130 && parameter.type.kind !== 128) {
  22133. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
  22134. }
  22135. if (!node.type) {
  22136. return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
  22137. }
  22138. }
  22139. function checkGrammarForIndexSignatureModifier(node) {
  22140. if (node.flags & 2035) {
  22141. grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
  22142. }
  22143. }
  22144. function checkGrammarIndexSignature(node) {
  22145. return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node);
  22146. }
  22147. function checkGrammarForAtLeastOneTypeArgument(node, typeArguments) {
  22148. if (typeArguments && typeArguments.length === 0) {
  22149. var sourceFile = ts.getSourceFileOfNode(node);
  22150. var start = typeArguments.pos - "<".length;
  22151. var end = ts.skipTrivia(sourceFile.text, typeArguments.end) + ">".length;
  22152. return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
  22153. }
  22154. }
  22155. function checkGrammarTypeArguments(node, typeArguments) {
  22156. return checkGrammarForDisallowedTrailingComma(typeArguments) ||
  22157. checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
  22158. }
  22159. function checkGrammarForOmittedArgument(node, args) {
  22160. if (args) {
  22161. var sourceFile = ts.getSourceFileOfNode(node);
  22162. for (var _i = 0; _i < args.length; _i++) {
  22163. var arg = args[_i];
  22164. if (arg.kind === 187) {
  22165. return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected);
  22166. }
  22167. }
  22168. }
  22169. }
  22170. function checkGrammarArguments(node, args) {
  22171. return checkGrammarForDisallowedTrailingComma(args) ||
  22172. checkGrammarForOmittedArgument(node, args);
  22173. }
  22174. function checkGrammarHeritageClause(node) {
  22175. var types = node.types;
  22176. if (checkGrammarForDisallowedTrailingComma(types)) {
  22177. return true;
  22178. }
  22179. if (types && types.length === 0) {
  22180. var listType = ts.tokenToString(node.token);
  22181. var sourceFile = ts.getSourceFileOfNode(node);
  22182. return grammarErrorAtPos(sourceFile, types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType);
  22183. }
  22184. }
  22185. function checkGrammarClassDeclarationHeritageClauses(node) {
  22186. var seenExtendsClause = false;
  22187. var seenImplementsClause = false;
  22188. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) {
  22189. for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
  22190. var heritageClause = _a[_i];
  22191. if (heritageClause.token === 83) {
  22192. if (seenExtendsClause) {
  22193. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
  22194. }
  22195. if (seenImplementsClause) {
  22196. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause);
  22197. }
  22198. if (heritageClause.types.length > 1) {
  22199. return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class);
  22200. }
  22201. seenExtendsClause = true;
  22202. }
  22203. else {
  22204. ts.Debug.assert(heritageClause.token === 106);
  22205. if (seenImplementsClause) {
  22206. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen);
  22207. }
  22208. seenImplementsClause = true;
  22209. }
  22210. checkGrammarHeritageClause(heritageClause);
  22211. }
  22212. }
  22213. }
  22214. function checkGrammarInterfaceDeclaration(node) {
  22215. var seenExtendsClause = false;
  22216. if (node.heritageClauses) {
  22217. for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
  22218. var heritageClause = _a[_i];
  22219. if (heritageClause.token === 83) {
  22220. if (seenExtendsClause) {
  22221. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
  22222. }
  22223. seenExtendsClause = true;
  22224. }
  22225. else {
  22226. ts.Debug.assert(heritageClause.token === 106);
  22227. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause);
  22228. }
  22229. checkGrammarHeritageClause(heritageClause);
  22230. }
  22231. }
  22232. return false;
  22233. }
  22234. function checkGrammarComputedPropertyName(node) {
  22235. if (node.kind !== 136) {
  22236. return false;
  22237. }
  22238. var computedPropertyName = node;
  22239. if (computedPropertyName.expression.kind === 181 && computedPropertyName.expression.operatorToken.kind === 24) {
  22240. return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name);
  22241. }
  22242. }
  22243. function checkGrammarForGenerator(node) {
  22244. if (node.asteriskToken) {
  22245. ts.Debug.assert(node.kind === 213 ||
  22246. node.kind === 173 ||
  22247. node.kind === 143);
  22248. if (ts.isInAmbientContext(node)) {
  22249. return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
  22250. }
  22251. if (!node.body) {
  22252. return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator);
  22253. }
  22254. if (languageVersion < 2) {
  22255. return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
  22256. }
  22257. }
  22258. }
  22259. function checkGrammarForInvalidQuestionMark(node, questionToken, message) {
  22260. if (questionToken) {
  22261. return grammarErrorOnNode(questionToken, message);
  22262. }
  22263. }
  22264. function checkGrammarObjectLiteralExpression(node, inDestructuring) {
  22265. var seen = {};
  22266. var Property = 1;
  22267. var GetAccessor = 2;
  22268. var SetAccesor = 4;
  22269. var GetOrSetAccessor = GetAccessor | SetAccesor;
  22270. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  22271. var prop = _a[_i];
  22272. var name_16 = prop.name;
  22273. if (prop.kind === 187 ||
  22274. name_16.kind === 136) {
  22275. checkGrammarComputedPropertyName(name_16);
  22276. continue;
  22277. }
  22278. if (prop.kind === 246 && !inDestructuring && prop.objectAssignmentInitializer) {
  22279. return grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment);
  22280. }
  22281. var currentKind = void 0;
  22282. if (prop.kind === 245 || prop.kind === 246) {
  22283. checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
  22284. if (name_16.kind === 8) {
  22285. checkGrammarNumericLiteral(name_16);
  22286. }
  22287. currentKind = Property;
  22288. }
  22289. else if (prop.kind === 143) {
  22290. currentKind = Property;
  22291. }
  22292. else if (prop.kind === 145) {
  22293. currentKind = GetAccessor;
  22294. }
  22295. else if (prop.kind === 146) {
  22296. currentKind = SetAccesor;
  22297. }
  22298. else {
  22299. ts.Debug.fail("Unexpected syntax kind:" + prop.kind);
  22300. }
  22301. if (!ts.hasProperty(seen, name_16.text)) {
  22302. seen[name_16.text] = currentKind;
  22303. }
  22304. else {
  22305. var existingKind = seen[name_16.text];
  22306. if (currentKind === Property && existingKind === Property) {
  22307. continue;
  22308. }
  22309. else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
  22310. if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
  22311. seen[name_16.text] = currentKind | existingKind;
  22312. }
  22313. else {
  22314. return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
  22315. }
  22316. }
  22317. else {
  22318. return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
  22319. }
  22320. }
  22321. }
  22322. }
  22323. function checkGrammarJsxElement(node) {
  22324. var seen = {};
  22325. for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) {
  22326. var attr = _a[_i];
  22327. if (attr.kind === 239) {
  22328. continue;
  22329. }
  22330. var jsxAttr = attr;
  22331. var name_17 = jsxAttr.name;
  22332. if (!ts.hasProperty(seen, name_17.text)) {
  22333. seen[name_17.text] = true;
  22334. }
  22335. else {
  22336. return grammarErrorOnNode(name_17, ts.Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name);
  22337. }
  22338. var initializer = jsxAttr.initializer;
  22339. if (initializer && initializer.kind === 240 && !initializer.expression) {
  22340. return grammarErrorOnNode(jsxAttr.initializer, ts.Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression);
  22341. }
  22342. }
  22343. }
  22344. function checkGrammarForInOrForOfStatement(forInOrOfStatement) {
  22345. if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) {
  22346. return true;
  22347. }
  22348. if (forInOrOfStatement.initializer.kind === 212) {
  22349. var variableList = forInOrOfStatement.initializer;
  22350. if (!checkGrammarVariableDeclarationList(variableList)) {
  22351. if (variableList.declarations.length > 1) {
  22352. var diagnostic = forInOrOfStatement.kind === 200
  22353. ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement
  22354. : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
  22355. return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
  22356. }
  22357. var firstDeclaration = variableList.declarations[0];
  22358. if (firstDeclaration.initializer) {
  22359. var diagnostic = forInOrOfStatement.kind === 200
  22360. ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer
  22361. : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer;
  22362. return grammarErrorOnNode(firstDeclaration.name, diagnostic);
  22363. }
  22364. if (firstDeclaration.type) {
  22365. var diagnostic = forInOrOfStatement.kind === 200
  22366. ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation
  22367. : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation;
  22368. return grammarErrorOnNode(firstDeclaration, diagnostic);
  22369. }
  22370. }
  22371. }
  22372. return false;
  22373. }
  22374. function checkGrammarAccessor(accessor) {
  22375. var kind = accessor.kind;
  22376. if (languageVersion < 1) {
  22377. return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
  22378. }
  22379. else if (ts.isInAmbientContext(accessor)) {
  22380. return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
  22381. }
  22382. else if (accessor.body === undefined) {
  22383. return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
  22384. }
  22385. else if (accessor.typeParameters) {
  22386. return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
  22387. }
  22388. else if (kind === 145 && accessor.parameters.length) {
  22389. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
  22390. }
  22391. else if (kind === 146) {
  22392. if (accessor.type) {
  22393. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
  22394. }
  22395. else if (accessor.parameters.length !== 1) {
  22396. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
  22397. }
  22398. else {
  22399. var parameter = accessor.parameters[0];
  22400. if (parameter.dotDotDotToken) {
  22401. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
  22402. }
  22403. else if (parameter.flags & 2035) {
  22404. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
  22405. }
  22406. else if (parameter.questionToken) {
  22407. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
  22408. }
  22409. else if (parameter.initializer) {
  22410. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
  22411. }
  22412. }
  22413. }
  22414. }
  22415. function checkGrammarForNonSymbolComputedProperty(node, message) {
  22416. if (node.kind === 136 && !ts.isWellKnownSymbolSyntactically(node.expression)) {
  22417. return grammarErrorOnNode(node, message);
  22418. }
  22419. }
  22420. function checkGrammarMethod(node) {
  22421. if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) ||
  22422. checkGrammarFunctionLikeDeclaration(node) ||
  22423. checkGrammarForGenerator(node)) {
  22424. return true;
  22425. }
  22426. if (node.parent.kind === 165) {
  22427. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
  22428. return true;
  22429. }
  22430. else if (node.body === undefined) {
  22431. return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
  22432. }
  22433. }
  22434. if (ts.isClassLike(node.parent)) {
  22435. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
  22436. return true;
  22437. }
  22438. if (ts.isInAmbientContext(node)) {
  22439. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol);
  22440. }
  22441. else if (!node.body) {
  22442. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol);
  22443. }
  22444. }
  22445. else if (node.parent.kind === 215) {
  22446. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol);
  22447. }
  22448. else if (node.parent.kind === 155) {
  22449. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol);
  22450. }
  22451. }
  22452. function isIterationStatement(node, lookInLabeledStatements) {
  22453. switch (node.kind) {
  22454. case 199:
  22455. case 200:
  22456. case 201:
  22457. case 197:
  22458. case 198:
  22459. return true;
  22460. case 207:
  22461. return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements);
  22462. }
  22463. return false;
  22464. }
  22465. function checkGrammarBreakOrContinueStatement(node) {
  22466. var current = node;
  22467. while (current) {
  22468. if (ts.isFunctionLike(current)) {
  22469. return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
  22470. }
  22471. switch (current.kind) {
  22472. case 207:
  22473. if (node.label && current.label.text === node.label.text) {
  22474. var isMisplacedContinueLabel = node.kind === 202
  22475. && !isIterationStatement(current.statement, true);
  22476. if (isMisplacedContinueLabel) {
  22477. return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
  22478. }
  22479. return false;
  22480. }
  22481. break;
  22482. case 206:
  22483. if (node.kind === 203 && !node.label) {
  22484. return false;
  22485. }
  22486. break;
  22487. default:
  22488. if (isIterationStatement(current, false) && !node.label) {
  22489. return false;
  22490. }
  22491. break;
  22492. }
  22493. current = current.parent;
  22494. }
  22495. if (node.label) {
  22496. var message = node.kind === 203
  22497. ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement
  22498. : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement;
  22499. return grammarErrorOnNode(node, message);
  22500. }
  22501. else {
  22502. var message = node.kind === 203
  22503. ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement
  22504. : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement;
  22505. return grammarErrorOnNode(node, message);
  22506. }
  22507. }
  22508. function checkGrammarBindingElement(node) {
  22509. if (node.dotDotDotToken) {
  22510. var elements = node.parent.elements;
  22511. if (node !== ts.lastOrUndefined(elements)) {
  22512. return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
  22513. }
  22514. if (node.name.kind === 162 || node.name.kind === 161) {
  22515. return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
  22516. }
  22517. if (node.initializer) {
  22518. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.A_rest_element_cannot_have_an_initializer);
  22519. }
  22520. }
  22521. }
  22522. function checkGrammarVariableDeclaration(node) {
  22523. if (node.parent.parent.kind !== 200 && node.parent.parent.kind !== 201) {
  22524. if (ts.isInAmbientContext(node)) {
  22525. if (node.initializer) {
  22526. var equalsTokenLength = "=".length;
  22527. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
  22528. }
  22529. }
  22530. else if (!node.initializer) {
  22531. if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) {
  22532. return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer);
  22533. }
  22534. if (ts.isConst(node)) {
  22535. return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
  22536. }
  22537. }
  22538. }
  22539. var checkLetConstNames = languageVersion >= 2 && (ts.isLet(node) || ts.isConst(node));
  22540. return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name);
  22541. }
  22542. function checkGrammarNameInLetOrConstDeclarations(name) {
  22543. if (name.kind === 69) {
  22544. if (name.text === "let") {
  22545. return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations);
  22546. }
  22547. }
  22548. else {
  22549. var elements = name.elements;
  22550. for (var _i = 0; _i < elements.length; _i++) {
  22551. var element = elements[_i];
  22552. if (element.kind !== 187) {
  22553. checkGrammarNameInLetOrConstDeclarations(element.name);
  22554. }
  22555. }
  22556. }
  22557. }
  22558. function checkGrammarVariableDeclarationList(declarationList) {
  22559. var declarations = declarationList.declarations;
  22560. if (checkGrammarForDisallowedTrailingComma(declarationList.declarations)) {
  22561. return true;
  22562. }
  22563. if (!declarationList.declarations.length) {
  22564. return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
  22565. }
  22566. }
  22567. function allowLetAndConstDeclarations(parent) {
  22568. switch (parent.kind) {
  22569. case 196:
  22570. case 197:
  22571. case 198:
  22572. case 205:
  22573. case 199:
  22574. case 200:
  22575. case 201:
  22576. return false;
  22577. case 207:
  22578. return allowLetAndConstDeclarations(parent.parent);
  22579. }
  22580. return true;
  22581. }
  22582. function checkGrammarForDisallowedLetOrConstStatement(node) {
  22583. if (!allowLetAndConstDeclarations(node.parent)) {
  22584. if (ts.isLet(node.declarationList)) {
  22585. return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
  22586. }
  22587. else if (ts.isConst(node.declarationList)) {
  22588. return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
  22589. }
  22590. }
  22591. }
  22592. function isIntegerLiteral(expression) {
  22593. if (expression.kind === 179) {
  22594. var unaryExpression = expression;
  22595. if (unaryExpression.operator === 35 || unaryExpression.operator === 36) {
  22596. expression = unaryExpression.operand;
  22597. }
  22598. }
  22599. if (expression.kind === 8) {
  22600. return /^[0-9]+([eE]\+?[0-9]+)?$/.test(expression.text);
  22601. }
  22602. return false;
  22603. }
  22604. function hasParseDiagnostics(sourceFile) {
  22605. return sourceFile.parseDiagnostics.length > 0;
  22606. }
  22607. function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
  22608. var sourceFile = ts.getSourceFileOfNode(node);
  22609. if (!hasParseDiagnostics(sourceFile)) {
  22610. var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
  22611. diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2));
  22612. return true;
  22613. }
  22614. }
  22615. function grammarErrorAtPos(sourceFile, start, length, message, arg0, arg1, arg2) {
  22616. if (!hasParseDiagnostics(sourceFile)) {
  22617. diagnostics.add(ts.createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
  22618. return true;
  22619. }
  22620. }
  22621. function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
  22622. var sourceFile = ts.getSourceFileOfNode(node);
  22623. if (!hasParseDiagnostics(sourceFile)) {
  22624. diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2));
  22625. return true;
  22626. }
  22627. }
  22628. function isEvalOrArgumentsIdentifier(node) {
  22629. return node.kind === 69 &&
  22630. (node.text === "eval" || node.text === "arguments");
  22631. }
  22632. function checkGrammarConstructorTypeParameters(node) {
  22633. if (node.typeParameters) {
  22634. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
  22635. }
  22636. }
  22637. function checkGrammarConstructorTypeAnnotation(node) {
  22638. if (node.type) {
  22639. return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
  22640. }
  22641. }
  22642. function checkGrammarProperty(node) {
  22643. if (ts.isClassLike(node.parent)) {
  22644. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) ||
  22645. checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) {
  22646. return true;
  22647. }
  22648. }
  22649. else if (node.parent.kind === 215) {
  22650. if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) {
  22651. return true;
  22652. }
  22653. }
  22654. else if (node.parent.kind === 155) {
  22655. if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) {
  22656. return true;
  22657. }
  22658. }
  22659. if (ts.isInAmbientContext(node) && node.initializer) {
  22660. return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
  22661. }
  22662. }
  22663. function checkGrammarTopLevelElementForRequiredDeclareModifier(node) {
  22664. if (node.kind === 215 ||
  22665. node.kind === 222 ||
  22666. node.kind === 221 ||
  22667. node.kind === 228 ||
  22668. node.kind === 227 ||
  22669. (node.flags & 2) ||
  22670. (node.flags & (1 | 1024))) {
  22671. return false;
  22672. }
  22673. return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
  22674. }
  22675. function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) {
  22676. for (var _i = 0, _a = file.statements; _i < _a.length; _i++) {
  22677. var decl = _a[_i];
  22678. if (ts.isDeclaration(decl) || decl.kind === 193) {
  22679. if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) {
  22680. return true;
  22681. }
  22682. }
  22683. }
  22684. }
  22685. function checkGrammarSourceFile(node) {
  22686. return ts.isInAmbientContext(node) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
  22687. }
  22688. function checkGrammarStatementInAmbientContext(node) {
  22689. if (ts.isInAmbientContext(node)) {
  22690. if (isAccessor(node.parent.kind)) {
  22691. return getNodeLinks(node).hasReportedStatementInAmbientContext = true;
  22692. }
  22693. var links = getNodeLinks(node);
  22694. if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) {
  22695. return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
  22696. }
  22697. if (node.parent.kind === 192 || node.parent.kind === 219 || node.parent.kind === 248) {
  22698. var links_1 = getNodeLinks(node.parent);
  22699. if (!links_1.hasReportedStatementInAmbientContext) {
  22700. return links_1.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
  22701. }
  22702. }
  22703. else {
  22704. }
  22705. }
  22706. }
  22707. function checkGrammarNumericLiteral(node) {
  22708. if (node.flags & 65536 && languageVersion >= 1) {
  22709. return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
  22710. }
  22711. }
  22712. function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) {
  22713. var sourceFile = ts.getSourceFileOfNode(node);
  22714. if (!hasParseDiagnostics(sourceFile)) {
  22715. var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
  22716. diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), 0, message, arg0, arg1, arg2));
  22717. return true;
  22718. }
  22719. }
  22720. }
  22721. ts.createTypeChecker = createTypeChecker;
  22722. })(ts || (ts = {}));
  22723. var ts;
  22724. (function (ts) {
  22725. function getDeclarationDiagnostics(host, resolver, targetSourceFile) {
  22726. var diagnostics = [];
  22727. var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
  22728. emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile);
  22729. return diagnostics;
  22730. }
  22731. ts.getDeclarationDiagnostics = getDeclarationDiagnostics;
  22732. function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) {
  22733. var newLine = host.getNewLine();
  22734. var compilerOptions = host.getCompilerOptions();
  22735. var write;
  22736. var writeLine;
  22737. var increaseIndent;
  22738. var decreaseIndent;
  22739. var writeTextOfNode;
  22740. var writer = createAndSetNewTextWriterWithSymbolWriter();
  22741. var enclosingDeclaration;
  22742. var currentSourceFile;
  22743. var reportedDeclarationError = false;
  22744. var errorNameNode;
  22745. var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments;
  22746. var emit = compilerOptions.stripInternal ? stripInternal : emitNode;
  22747. var moduleElementDeclarationEmitInfo = [];
  22748. var asynchronousSubModuleDeclarationEmitInfo;
  22749. var referencePathsOutput = "";
  22750. if (root) {
  22751. if (!compilerOptions.noResolve) {
  22752. var addedGlobalFileReference = false;
  22753. ts.forEach(root.referencedFiles, function (fileReference) {
  22754. var referencedFile = ts.tryResolveScriptReference(host, root, fileReference);
  22755. if (referencedFile && ((referencedFile.flags & 8192) ||
  22756. ts.shouldEmitToOwnFile(referencedFile, compilerOptions) ||
  22757. !addedGlobalFileReference)) {
  22758. writeReferencePath(referencedFile);
  22759. if (!ts.isExternalModuleOrDeclarationFile(referencedFile)) {
  22760. addedGlobalFileReference = true;
  22761. }
  22762. }
  22763. });
  22764. }
  22765. emitSourceFile(root);
  22766. if (moduleElementDeclarationEmitInfo.length) {
  22767. var oldWriter = writer;
  22768. ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
  22769. if (aliasEmitInfo.isVisible) {
  22770. ts.Debug.assert(aliasEmitInfo.node.kind === 222);
  22771. createAndSetNewTextWriterWithSymbolWriter();
  22772. ts.Debug.assert(aliasEmitInfo.indent === 0);
  22773. writeImportDeclaration(aliasEmitInfo.node);
  22774. aliasEmitInfo.asynchronousOutput = writer.getText();
  22775. }
  22776. });
  22777. setWriter(oldWriter);
  22778. }
  22779. }
  22780. else {
  22781. var emittedReferencedFiles = [];
  22782. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  22783. if (!ts.isExternalModuleOrDeclarationFile(sourceFile)) {
  22784. if (!compilerOptions.noResolve) {
  22785. ts.forEach(sourceFile.referencedFiles, function (fileReference) {
  22786. var referencedFile = ts.tryResolveScriptReference(host, sourceFile, fileReference);
  22787. if (referencedFile && (ts.isExternalModuleOrDeclarationFile(referencedFile) &&
  22788. !ts.contains(emittedReferencedFiles, referencedFile))) {
  22789. writeReferencePath(referencedFile);
  22790. emittedReferencedFiles.push(referencedFile);
  22791. }
  22792. });
  22793. }
  22794. emitSourceFile(sourceFile);
  22795. }
  22796. });
  22797. }
  22798. return {
  22799. reportedDeclarationError: reportedDeclarationError,
  22800. moduleElementDeclarationEmitInfo: moduleElementDeclarationEmitInfo,
  22801. synchronousDeclarationOutput: writer.getText(),
  22802. referencePathsOutput: referencePathsOutput
  22803. };
  22804. function hasInternalAnnotation(range) {
  22805. var text = currentSourceFile.text;
  22806. var comment = text.substring(range.pos, range.end);
  22807. return comment.indexOf("@internal") >= 0;
  22808. }
  22809. function stripInternal(node) {
  22810. if (node) {
  22811. var leadingCommentRanges = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
  22812. if (ts.forEach(leadingCommentRanges, hasInternalAnnotation)) {
  22813. return;
  22814. }
  22815. emitNode(node);
  22816. }
  22817. }
  22818. function createAndSetNewTextWriterWithSymbolWriter() {
  22819. var writer = ts.createTextWriter(newLine);
  22820. writer.trackSymbol = trackSymbol;
  22821. writer.reportInaccessibleThisError = reportInaccessibleThisError;
  22822. writer.writeKeyword = writer.write;
  22823. writer.writeOperator = writer.write;
  22824. writer.writePunctuation = writer.write;
  22825. writer.writeSpace = writer.write;
  22826. writer.writeStringLiteral = writer.writeLiteral;
  22827. writer.writeParameter = writer.write;
  22828. writer.writeSymbol = writer.write;
  22829. setWriter(writer);
  22830. return writer;
  22831. }
  22832. function setWriter(newWriter) {
  22833. writer = newWriter;
  22834. write = newWriter.write;
  22835. writeTextOfNode = newWriter.writeTextOfNode;
  22836. writeLine = newWriter.writeLine;
  22837. increaseIndent = newWriter.increaseIndent;
  22838. decreaseIndent = newWriter.decreaseIndent;
  22839. }
  22840. function writeAsynchronousModuleElements(nodes) {
  22841. var oldWriter = writer;
  22842. ts.forEach(nodes, function (declaration) {
  22843. var nodeToCheck;
  22844. if (declaration.kind === 211) {
  22845. nodeToCheck = declaration.parent.parent;
  22846. }
  22847. else if (declaration.kind === 225 || declaration.kind === 226 || declaration.kind === 223) {
  22848. ts.Debug.fail("We should be getting ImportDeclaration instead to write");
  22849. }
  22850. else {
  22851. nodeToCheck = declaration;
  22852. }
  22853. var moduleElementEmitInfo = ts.forEach(moduleElementDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
  22854. if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) {
  22855. moduleElementEmitInfo = ts.forEach(asynchronousSubModuleDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
  22856. }
  22857. if (moduleElementEmitInfo) {
  22858. if (moduleElementEmitInfo.node.kind === 222) {
  22859. moduleElementEmitInfo.isVisible = true;
  22860. }
  22861. else {
  22862. createAndSetNewTextWriterWithSymbolWriter();
  22863. for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) {
  22864. increaseIndent();
  22865. }
  22866. if (nodeToCheck.kind === 218) {
  22867. ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined);
  22868. asynchronousSubModuleDeclarationEmitInfo = [];
  22869. }
  22870. writeModuleElement(nodeToCheck);
  22871. if (nodeToCheck.kind === 218) {
  22872. moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo;
  22873. asynchronousSubModuleDeclarationEmitInfo = undefined;
  22874. }
  22875. moduleElementEmitInfo.asynchronousOutput = writer.getText();
  22876. }
  22877. }
  22878. });
  22879. setWriter(oldWriter);
  22880. }
  22881. function handleSymbolAccessibilityError(symbolAccesibilityResult) {
  22882. if (symbolAccesibilityResult.accessibility === 0) {
  22883. if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
  22884. writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible);
  22885. }
  22886. }
  22887. else {
  22888. reportedDeclarationError = true;
  22889. var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
  22890. if (errorInfo) {
  22891. if (errorInfo.typeName) {
  22892. diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
  22893. }
  22894. else {
  22895. diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
  22896. }
  22897. }
  22898. }
  22899. }
  22900. function trackSymbol(symbol, enclosingDeclaration, meaning) {
  22901. handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
  22902. }
  22903. function reportInaccessibleThisError() {
  22904. if (errorNameNode) {
  22905. diagnostics.push(ts.createDiagnosticForNode(errorNameNode, ts.Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, ts.declarationNameToString(errorNameNode)));
  22906. }
  22907. }
  22908. function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) {
  22909. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  22910. write(": ");
  22911. if (type) {
  22912. emitType(type);
  22913. }
  22914. else {
  22915. errorNameNode = declaration.name;
  22916. resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2, writer);
  22917. errorNameNode = undefined;
  22918. }
  22919. }
  22920. function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) {
  22921. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  22922. write(": ");
  22923. if (signature.type) {
  22924. emitType(signature.type);
  22925. }
  22926. else {
  22927. errorNameNode = signature.name;
  22928. resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2, writer);
  22929. errorNameNode = undefined;
  22930. }
  22931. }
  22932. function emitLines(nodes) {
  22933. for (var _i = 0; _i < nodes.length; _i++) {
  22934. var node = nodes[_i];
  22935. emit(node);
  22936. }
  22937. }
  22938. function emitSeparatedList(nodes, separator, eachNodeEmitFn, canEmitFn) {
  22939. var currentWriterPos = writer.getTextPos();
  22940. for (var _i = 0; _i < nodes.length; _i++) {
  22941. var node = nodes[_i];
  22942. if (!canEmitFn || canEmitFn(node)) {
  22943. if (currentWriterPos !== writer.getTextPos()) {
  22944. write(separator);
  22945. }
  22946. currentWriterPos = writer.getTextPos();
  22947. eachNodeEmitFn(node);
  22948. }
  22949. }
  22950. }
  22951. function emitCommaList(nodes, eachNodeEmitFn, canEmitFn) {
  22952. emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn);
  22953. }
  22954. function writeJsDocComments(declaration) {
  22955. if (declaration) {
  22956. var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile);
  22957. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments);
  22958. ts.emitComments(currentSourceFile, writer, jsDocComments, true, newLine, ts.writeCommentRange);
  22959. }
  22960. }
  22961. function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) {
  22962. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  22963. emitType(type);
  22964. }
  22965. function emitType(type) {
  22966. switch (type.kind) {
  22967. case 117:
  22968. case 130:
  22969. case 128:
  22970. case 120:
  22971. case 131:
  22972. case 103:
  22973. case 97:
  22974. case 9:
  22975. return writeTextOfNode(currentSourceFile, type);
  22976. case 188:
  22977. return emitExpressionWithTypeArguments(type);
  22978. case 151:
  22979. return emitTypeReference(type);
  22980. case 154:
  22981. return emitTypeQuery(type);
  22982. case 156:
  22983. return emitArrayType(type);
  22984. case 157:
  22985. return emitTupleType(type);
  22986. case 158:
  22987. return emitUnionType(type);
  22988. case 159:
  22989. return emitIntersectionType(type);
  22990. case 160:
  22991. return emitParenType(type);
  22992. case 152:
  22993. case 153:
  22994. return emitSignatureDeclarationWithJsDocComments(type);
  22995. case 155:
  22996. return emitTypeLiteral(type);
  22997. case 69:
  22998. return emitEntityName(type);
  22999. case 135:
  23000. return emitEntityName(type);
  23001. case 150:
  23002. return emitTypePredicate(type);
  23003. }
  23004. function writeEntityName(entityName) {
  23005. if (entityName.kind === 69) {
  23006. writeTextOfNode(currentSourceFile, entityName);
  23007. }
  23008. else {
  23009. var left = entityName.kind === 135 ? entityName.left : entityName.expression;
  23010. var right = entityName.kind === 135 ? entityName.right : entityName.name;
  23011. writeEntityName(left);
  23012. write(".");
  23013. writeTextOfNode(currentSourceFile, right);
  23014. }
  23015. }
  23016. function emitEntityName(entityName) {
  23017. var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 221 ? entityName.parent : enclosingDeclaration);
  23018. handleSymbolAccessibilityError(visibilityResult);
  23019. writeEntityName(entityName);
  23020. }
  23021. function emitExpressionWithTypeArguments(node) {
  23022. if (ts.isSupportedExpressionWithTypeArguments(node)) {
  23023. ts.Debug.assert(node.expression.kind === 69 || node.expression.kind === 166);
  23024. emitEntityName(node.expression);
  23025. if (node.typeArguments) {
  23026. write("<");
  23027. emitCommaList(node.typeArguments, emitType);
  23028. write(">");
  23029. }
  23030. }
  23031. }
  23032. function emitTypeReference(type) {
  23033. emitEntityName(type.typeName);
  23034. if (type.typeArguments) {
  23035. write("<");
  23036. emitCommaList(type.typeArguments, emitType);
  23037. write(">");
  23038. }
  23039. }
  23040. function emitTypePredicate(type) {
  23041. writeTextOfNode(currentSourceFile, type.parameterName);
  23042. write(" is ");
  23043. emitType(type.type);
  23044. }
  23045. function emitTypeQuery(type) {
  23046. write("typeof ");
  23047. emitEntityName(type.exprName);
  23048. }
  23049. function emitArrayType(type) {
  23050. emitType(type.elementType);
  23051. write("[]");
  23052. }
  23053. function emitTupleType(type) {
  23054. write("[");
  23055. emitCommaList(type.elementTypes, emitType);
  23056. write("]");
  23057. }
  23058. function emitUnionType(type) {
  23059. emitSeparatedList(type.types, " | ", emitType);
  23060. }
  23061. function emitIntersectionType(type) {
  23062. emitSeparatedList(type.types, " & ", emitType);
  23063. }
  23064. function emitParenType(type) {
  23065. write("(");
  23066. emitType(type.type);
  23067. write(")");
  23068. }
  23069. function emitTypeLiteral(type) {
  23070. write("{");
  23071. if (type.members.length) {
  23072. writeLine();
  23073. increaseIndent();
  23074. emitLines(type.members);
  23075. decreaseIndent();
  23076. }
  23077. write("}");
  23078. }
  23079. }
  23080. function emitSourceFile(node) {
  23081. currentSourceFile = node;
  23082. enclosingDeclaration = node;
  23083. emitLines(node.statements);
  23084. }
  23085. function getExportDefaultTempVariableName() {
  23086. var baseName = "_default";
  23087. if (!ts.hasProperty(currentSourceFile.identifiers, baseName)) {
  23088. return baseName;
  23089. }
  23090. var count = 0;
  23091. while (true) {
  23092. var name_18 = baseName + "_" + (++count);
  23093. if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) {
  23094. return name_18;
  23095. }
  23096. }
  23097. }
  23098. function emitExportAssignment(node) {
  23099. if (node.expression.kind === 69) {
  23100. write(node.isExportEquals ? "export = " : "export default ");
  23101. writeTextOfNode(currentSourceFile, node.expression);
  23102. }
  23103. else {
  23104. var tempVarName = getExportDefaultTempVariableName();
  23105. write("declare var ");
  23106. write(tempVarName);
  23107. write(": ");
  23108. writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic;
  23109. resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, 2, writer);
  23110. write(";");
  23111. writeLine();
  23112. write(node.isExportEquals ? "export = " : "export default ");
  23113. write(tempVarName);
  23114. }
  23115. write(";");
  23116. writeLine();
  23117. if (node.expression.kind === 69) {
  23118. var nodes = resolver.collectLinkedAliases(node.expression);
  23119. writeAsynchronousModuleElements(nodes);
  23120. }
  23121. function getDefaultExportAccessibilityDiagnostic(diagnostic) {
  23122. return {
  23123. diagnosticMessage: ts.Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
  23124. errorNode: node
  23125. };
  23126. }
  23127. }
  23128. function isModuleElementVisible(node) {
  23129. return resolver.isDeclarationVisible(node);
  23130. }
  23131. function emitModuleElement(node, isModuleElementVisible) {
  23132. if (isModuleElementVisible) {
  23133. writeModuleElement(node);
  23134. }
  23135. else if (node.kind === 221 ||
  23136. (node.parent.kind === 248 && ts.isExternalModule(currentSourceFile))) {
  23137. var isVisible;
  23138. if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 248) {
  23139. asynchronousSubModuleDeclarationEmitInfo.push({
  23140. node: node,
  23141. outputPos: writer.getTextPos(),
  23142. indent: writer.getIndent(),
  23143. isVisible: isVisible
  23144. });
  23145. }
  23146. else {
  23147. if (node.kind === 222) {
  23148. var importDeclaration = node;
  23149. if (importDeclaration.importClause) {
  23150. isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) ||
  23151. isVisibleNamedBinding(importDeclaration.importClause.namedBindings);
  23152. }
  23153. }
  23154. moduleElementDeclarationEmitInfo.push({
  23155. node: node,
  23156. outputPos: writer.getTextPos(),
  23157. indent: writer.getIndent(),
  23158. isVisible: isVisible
  23159. });
  23160. }
  23161. }
  23162. }
  23163. function writeModuleElement(node) {
  23164. switch (node.kind) {
  23165. case 213:
  23166. return writeFunctionDeclaration(node);
  23167. case 193:
  23168. return writeVariableStatement(node);
  23169. case 215:
  23170. return writeInterfaceDeclaration(node);
  23171. case 214:
  23172. return writeClassDeclaration(node);
  23173. case 216:
  23174. return writeTypeAliasDeclaration(node);
  23175. case 217:
  23176. return writeEnumDeclaration(node);
  23177. case 218:
  23178. return writeModuleDeclaration(node);
  23179. case 221:
  23180. return writeImportEqualsDeclaration(node);
  23181. case 222:
  23182. return writeImportDeclaration(node);
  23183. default:
  23184. ts.Debug.fail("Unknown symbol kind");
  23185. }
  23186. }
  23187. function emitModuleElementDeclarationFlags(node) {
  23188. if (node.parent === currentSourceFile) {
  23189. if (node.flags & 1) {
  23190. write("export ");
  23191. }
  23192. if (node.flags & 1024) {
  23193. write("default ");
  23194. }
  23195. else if (node.kind !== 215) {
  23196. write("declare ");
  23197. }
  23198. }
  23199. }
  23200. function emitClassMemberDeclarationFlags(node) {
  23201. if (node.flags & 32) {
  23202. write("private ");
  23203. }
  23204. else if (node.flags & 64) {
  23205. write("protected ");
  23206. }
  23207. if (node.flags & 128) {
  23208. write("static ");
  23209. }
  23210. if (node.flags & 256) {
  23211. write("abstract ");
  23212. }
  23213. }
  23214. function writeImportEqualsDeclaration(node) {
  23215. emitJsDocComments(node);
  23216. if (node.flags & 1) {
  23217. write("export ");
  23218. }
  23219. write("import ");
  23220. writeTextOfNode(currentSourceFile, node.name);
  23221. write(" = ");
  23222. if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  23223. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError);
  23224. write(";");
  23225. }
  23226. else {
  23227. write("require(");
  23228. writeTextOfNode(currentSourceFile, ts.getExternalModuleImportEqualsDeclarationExpression(node));
  23229. write(");");
  23230. }
  23231. writer.writeLine();
  23232. function getImportEntityNameVisibilityError(symbolAccesibilityResult) {
  23233. return {
  23234. diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1,
  23235. errorNode: node,
  23236. typeName: node.name
  23237. };
  23238. }
  23239. }
  23240. function isVisibleNamedBinding(namedBindings) {
  23241. if (namedBindings) {
  23242. if (namedBindings.kind === 224) {
  23243. return resolver.isDeclarationVisible(namedBindings);
  23244. }
  23245. else {
  23246. return ts.forEach(namedBindings.elements, function (namedImport) { return resolver.isDeclarationVisible(namedImport); });
  23247. }
  23248. }
  23249. }
  23250. function writeImportDeclaration(node) {
  23251. if (!node.importClause && !(node.flags & 1)) {
  23252. return;
  23253. }
  23254. emitJsDocComments(node);
  23255. if (node.flags & 1) {
  23256. write("export ");
  23257. }
  23258. write("import ");
  23259. if (node.importClause) {
  23260. var currentWriterPos = writer.getTextPos();
  23261. if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) {
  23262. writeTextOfNode(currentSourceFile, node.importClause.name);
  23263. }
  23264. if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) {
  23265. if (currentWriterPos !== writer.getTextPos()) {
  23266. write(", ");
  23267. }
  23268. if (node.importClause.namedBindings.kind === 224) {
  23269. write("* as ");
  23270. writeTextOfNode(currentSourceFile, node.importClause.namedBindings.name);
  23271. }
  23272. else {
  23273. write("{ ");
  23274. emitCommaList(node.importClause.namedBindings.elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible);
  23275. write(" }");
  23276. }
  23277. }
  23278. write(" from ");
  23279. }
  23280. writeTextOfNode(currentSourceFile, node.moduleSpecifier);
  23281. write(";");
  23282. writer.writeLine();
  23283. }
  23284. function emitImportOrExportSpecifier(node) {
  23285. if (node.propertyName) {
  23286. writeTextOfNode(currentSourceFile, node.propertyName);
  23287. write(" as ");
  23288. }
  23289. writeTextOfNode(currentSourceFile, node.name);
  23290. }
  23291. function emitExportSpecifier(node) {
  23292. emitImportOrExportSpecifier(node);
  23293. var nodes = resolver.collectLinkedAliases(node.propertyName || node.name);
  23294. writeAsynchronousModuleElements(nodes);
  23295. }
  23296. function emitExportDeclaration(node) {
  23297. emitJsDocComments(node);
  23298. write("export ");
  23299. if (node.exportClause) {
  23300. write("{ ");
  23301. emitCommaList(node.exportClause.elements, emitExportSpecifier);
  23302. write(" }");
  23303. }
  23304. else {
  23305. write("*");
  23306. }
  23307. if (node.moduleSpecifier) {
  23308. write(" from ");
  23309. writeTextOfNode(currentSourceFile, node.moduleSpecifier);
  23310. }
  23311. write(";");
  23312. writer.writeLine();
  23313. }
  23314. function writeModuleDeclaration(node) {
  23315. emitJsDocComments(node);
  23316. emitModuleElementDeclarationFlags(node);
  23317. if (node.flags & 131072) {
  23318. write("namespace ");
  23319. }
  23320. else {
  23321. write("module ");
  23322. }
  23323. writeTextOfNode(currentSourceFile, node.name);
  23324. while (node.body.kind !== 219) {
  23325. node = node.body;
  23326. write(".");
  23327. writeTextOfNode(currentSourceFile, node.name);
  23328. }
  23329. var prevEnclosingDeclaration = enclosingDeclaration;
  23330. enclosingDeclaration = node;
  23331. write(" {");
  23332. writeLine();
  23333. increaseIndent();
  23334. emitLines(node.body.statements);
  23335. decreaseIndent();
  23336. write("}");
  23337. writeLine();
  23338. enclosingDeclaration = prevEnclosingDeclaration;
  23339. }
  23340. function writeTypeAliasDeclaration(node) {
  23341. var prevEnclosingDeclaration = enclosingDeclaration;
  23342. enclosingDeclaration = node;
  23343. emitJsDocComments(node);
  23344. emitModuleElementDeclarationFlags(node);
  23345. write("type ");
  23346. writeTextOfNode(currentSourceFile, node.name);
  23347. emitTypeParameters(node.typeParameters);
  23348. write(" = ");
  23349. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError);
  23350. write(";");
  23351. writeLine();
  23352. enclosingDeclaration = prevEnclosingDeclaration;
  23353. function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
  23354. return {
  23355. diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
  23356. errorNode: node.type,
  23357. typeName: node.name
  23358. };
  23359. }
  23360. }
  23361. function writeEnumDeclaration(node) {
  23362. emitJsDocComments(node);
  23363. emitModuleElementDeclarationFlags(node);
  23364. if (ts.isConst(node)) {
  23365. write("const ");
  23366. }
  23367. write("enum ");
  23368. writeTextOfNode(currentSourceFile, node.name);
  23369. write(" {");
  23370. writeLine();
  23371. increaseIndent();
  23372. emitLines(node.members);
  23373. decreaseIndent();
  23374. write("}");
  23375. writeLine();
  23376. }
  23377. function emitEnumMemberDeclaration(node) {
  23378. emitJsDocComments(node);
  23379. writeTextOfNode(currentSourceFile, node.name);
  23380. var enumMemberValue = resolver.getConstantValue(node);
  23381. if (enumMemberValue !== undefined) {
  23382. write(" = ");
  23383. write(enumMemberValue.toString());
  23384. }
  23385. write(",");
  23386. writeLine();
  23387. }
  23388. function isPrivateMethodTypeParameter(node) {
  23389. return node.parent.kind === 143 && (node.parent.flags & 32);
  23390. }
  23391. function emitTypeParameters(typeParameters) {
  23392. function emitTypeParameter(node) {
  23393. increaseIndent();
  23394. emitJsDocComments(node);
  23395. decreaseIndent();
  23396. writeTextOfNode(currentSourceFile, node.name);
  23397. if (node.constraint && !isPrivateMethodTypeParameter(node)) {
  23398. write(" extends ");
  23399. if (node.parent.kind === 152 ||
  23400. node.parent.kind === 153 ||
  23401. (node.parent.parent && node.parent.parent.kind === 155)) {
  23402. ts.Debug.assert(node.parent.kind === 143 ||
  23403. node.parent.kind === 142 ||
  23404. node.parent.kind === 152 ||
  23405. node.parent.kind === 153 ||
  23406. node.parent.kind === 147 ||
  23407. node.parent.kind === 148);
  23408. emitType(node.constraint);
  23409. }
  23410. else {
  23411. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError);
  23412. }
  23413. }
  23414. function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
  23415. var diagnosticMessage;
  23416. switch (node.parent.kind) {
  23417. case 214:
  23418. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
  23419. break;
  23420. case 215:
  23421. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
  23422. break;
  23423. case 148:
  23424. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
  23425. break;
  23426. case 147:
  23427. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
  23428. break;
  23429. case 143:
  23430. case 142:
  23431. if (node.parent.flags & 128) {
  23432. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
  23433. }
  23434. else if (node.parent.parent.kind === 214) {
  23435. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
  23436. }
  23437. else {
  23438. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
  23439. }
  23440. break;
  23441. case 213:
  23442. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
  23443. break;
  23444. default:
  23445. ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
  23446. }
  23447. return {
  23448. diagnosticMessage: diagnosticMessage,
  23449. errorNode: node,
  23450. typeName: node.name
  23451. };
  23452. }
  23453. }
  23454. if (typeParameters) {
  23455. write("<");
  23456. emitCommaList(typeParameters, emitTypeParameter);
  23457. write(">");
  23458. }
  23459. }
  23460. function emitHeritageClause(typeReferences, isImplementsList) {
  23461. if (typeReferences) {
  23462. write(isImplementsList ? " implements " : " extends ");
  23463. emitCommaList(typeReferences, emitTypeOfTypeReference);
  23464. }
  23465. function emitTypeOfTypeReference(node) {
  23466. if (ts.isSupportedExpressionWithTypeArguments(node)) {
  23467. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError);
  23468. }
  23469. else if (!isImplementsList && node.expression.kind === 93) {
  23470. write("null");
  23471. }
  23472. function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
  23473. var diagnosticMessage;
  23474. if (node.parent.parent.kind === 214) {
  23475. diagnosticMessage = isImplementsList ?
  23476. ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
  23477. ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
  23478. }
  23479. else {
  23480. diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
  23481. }
  23482. return {
  23483. diagnosticMessage: diagnosticMessage,
  23484. errorNode: node,
  23485. typeName: node.parent.parent.name
  23486. };
  23487. }
  23488. }
  23489. }
  23490. function writeClassDeclaration(node) {
  23491. function emitParameterProperties(constructorDeclaration) {
  23492. if (constructorDeclaration) {
  23493. ts.forEach(constructorDeclaration.parameters, function (param) {
  23494. if (param.flags & 112) {
  23495. emitPropertyDeclaration(param);
  23496. }
  23497. });
  23498. }
  23499. }
  23500. emitJsDocComments(node);
  23501. emitModuleElementDeclarationFlags(node);
  23502. if (node.flags & 256) {
  23503. write("abstract ");
  23504. }
  23505. write("class ");
  23506. writeTextOfNode(currentSourceFile, node.name);
  23507. var prevEnclosingDeclaration = enclosingDeclaration;
  23508. enclosingDeclaration = node;
  23509. emitTypeParameters(node.typeParameters);
  23510. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  23511. if (baseTypeNode) {
  23512. emitHeritageClause([baseTypeNode], false);
  23513. }
  23514. emitHeritageClause(ts.getClassImplementsHeritageClauseElements(node), true);
  23515. write(" {");
  23516. writeLine();
  23517. increaseIndent();
  23518. emitParameterProperties(ts.getFirstConstructorWithBody(node));
  23519. emitLines(node.members);
  23520. decreaseIndent();
  23521. write("}");
  23522. writeLine();
  23523. enclosingDeclaration = prevEnclosingDeclaration;
  23524. }
  23525. function writeInterfaceDeclaration(node) {
  23526. emitJsDocComments(node);
  23527. emitModuleElementDeclarationFlags(node);
  23528. write("interface ");
  23529. writeTextOfNode(currentSourceFile, node.name);
  23530. var prevEnclosingDeclaration = enclosingDeclaration;
  23531. enclosingDeclaration = node;
  23532. emitTypeParameters(node.typeParameters);
  23533. emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), false);
  23534. write(" {");
  23535. writeLine();
  23536. increaseIndent();
  23537. emitLines(node.members);
  23538. decreaseIndent();
  23539. write("}");
  23540. writeLine();
  23541. enclosingDeclaration = prevEnclosingDeclaration;
  23542. }
  23543. function emitPropertyDeclaration(node) {
  23544. if (ts.hasDynamicName(node)) {
  23545. return;
  23546. }
  23547. emitJsDocComments(node);
  23548. emitClassMemberDeclarationFlags(node);
  23549. emitVariableDeclaration(node);
  23550. write(";");
  23551. writeLine();
  23552. }
  23553. function emitVariableDeclaration(node) {
  23554. if (node.kind !== 211 || resolver.isDeclarationVisible(node)) {
  23555. if (ts.isBindingPattern(node.name)) {
  23556. emitBindingPattern(node.name);
  23557. }
  23558. else {
  23559. writeTextOfNode(currentSourceFile, node.name);
  23560. if ((node.kind === 141 || node.kind === 140) && ts.hasQuestionToken(node)) {
  23561. write("?");
  23562. }
  23563. if ((node.kind === 141 || node.kind === 140) && node.parent.kind === 155) {
  23564. emitTypeOfVariableDeclarationFromTypeLiteral(node);
  23565. }
  23566. else if (!(node.flags & 32)) {
  23567. writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError);
  23568. }
  23569. }
  23570. }
  23571. function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
  23572. if (node.kind === 211) {
  23573. return symbolAccesibilityResult.errorModuleName ?
  23574. symbolAccesibilityResult.accessibility === 2 ?
  23575. ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23576. ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
  23577. ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
  23578. }
  23579. else if (node.kind === 141 || node.kind === 140) {
  23580. if (node.flags & 128) {
  23581. return symbolAccesibilityResult.errorModuleName ?
  23582. symbolAccesibilityResult.accessibility === 2 ?
  23583. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23584. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23585. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
  23586. }
  23587. else if (node.parent.kind === 214) {
  23588. return symbolAccesibilityResult.errorModuleName ?
  23589. symbolAccesibilityResult.accessibility === 2 ?
  23590. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23591. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23592. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
  23593. }
  23594. else {
  23595. return symbolAccesibilityResult.errorModuleName ?
  23596. ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23597. ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
  23598. }
  23599. }
  23600. }
  23601. function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  23602. var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23603. return diagnosticMessage !== undefined ? {
  23604. diagnosticMessage: diagnosticMessage,
  23605. errorNode: node,
  23606. typeName: node.name
  23607. } : undefined;
  23608. }
  23609. function emitBindingPattern(bindingPattern) {
  23610. var elements = [];
  23611. for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) {
  23612. var element = _a[_i];
  23613. if (element.kind !== 187) {
  23614. elements.push(element);
  23615. }
  23616. }
  23617. emitCommaList(elements, emitBindingElement);
  23618. }
  23619. function emitBindingElement(bindingElement) {
  23620. function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
  23621. var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23622. return diagnosticMessage !== undefined ? {
  23623. diagnosticMessage: diagnosticMessage,
  23624. errorNode: bindingElement,
  23625. typeName: bindingElement.name
  23626. } : undefined;
  23627. }
  23628. if (bindingElement.name) {
  23629. if (ts.isBindingPattern(bindingElement.name)) {
  23630. emitBindingPattern(bindingElement.name);
  23631. }
  23632. else {
  23633. writeTextOfNode(currentSourceFile, bindingElement.name);
  23634. writeTypeOfDeclaration(bindingElement, undefined, getBindingElementTypeVisibilityError);
  23635. }
  23636. }
  23637. }
  23638. }
  23639. function emitTypeOfVariableDeclarationFromTypeLiteral(node) {
  23640. if (node.type) {
  23641. write(": ");
  23642. emitType(node.type);
  23643. }
  23644. }
  23645. function isVariableStatementVisible(node) {
  23646. return ts.forEach(node.declarationList.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
  23647. }
  23648. function writeVariableStatement(node) {
  23649. emitJsDocComments(node);
  23650. emitModuleElementDeclarationFlags(node);
  23651. if (ts.isLet(node.declarationList)) {
  23652. write("let ");
  23653. }
  23654. else if (ts.isConst(node.declarationList)) {
  23655. write("const ");
  23656. }
  23657. else {
  23658. write("var ");
  23659. }
  23660. emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible);
  23661. write(";");
  23662. writeLine();
  23663. }
  23664. function emitAccessorDeclaration(node) {
  23665. if (ts.hasDynamicName(node)) {
  23666. return;
  23667. }
  23668. var accessors = ts.getAllAccessorDeclarations(node.parent.members, node);
  23669. var accessorWithTypeAnnotation;
  23670. if (node === accessors.firstAccessor) {
  23671. emitJsDocComments(accessors.getAccessor);
  23672. emitJsDocComments(accessors.setAccessor);
  23673. emitClassMemberDeclarationFlags(node);
  23674. writeTextOfNode(currentSourceFile, node.name);
  23675. if (!(node.flags & 32)) {
  23676. accessorWithTypeAnnotation = node;
  23677. var type = getTypeAnnotationFromAccessor(node);
  23678. if (!type) {
  23679. var anotherAccessor = node.kind === 145 ? accessors.setAccessor : accessors.getAccessor;
  23680. type = getTypeAnnotationFromAccessor(anotherAccessor);
  23681. if (type) {
  23682. accessorWithTypeAnnotation = anotherAccessor;
  23683. }
  23684. }
  23685. writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError);
  23686. }
  23687. write(";");
  23688. writeLine();
  23689. }
  23690. function getTypeAnnotationFromAccessor(accessor) {
  23691. if (accessor) {
  23692. return accessor.kind === 145
  23693. ? accessor.type
  23694. : accessor.parameters.length > 0
  23695. ? accessor.parameters[0].type
  23696. : undefined;
  23697. }
  23698. }
  23699. function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  23700. var diagnosticMessage;
  23701. if (accessorWithTypeAnnotation.kind === 146) {
  23702. if (accessorWithTypeAnnotation.parent.flags & 128) {
  23703. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23704. ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23705. ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
  23706. }
  23707. else {
  23708. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23709. ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23710. ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
  23711. }
  23712. return {
  23713. diagnosticMessage: diagnosticMessage,
  23714. errorNode: accessorWithTypeAnnotation.parameters[0],
  23715. typeName: accessorWithTypeAnnotation.name
  23716. };
  23717. }
  23718. else {
  23719. if (accessorWithTypeAnnotation.flags & 128) {
  23720. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23721. symbolAccesibilityResult.accessibility === 2 ?
  23722. ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  23723. ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23724. ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
  23725. }
  23726. else {
  23727. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23728. symbolAccesibilityResult.accessibility === 2 ?
  23729. ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  23730. ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23731. ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
  23732. }
  23733. return {
  23734. diagnosticMessage: diagnosticMessage,
  23735. errorNode: accessorWithTypeAnnotation.name,
  23736. typeName: undefined
  23737. };
  23738. }
  23739. }
  23740. }
  23741. function writeFunctionDeclaration(node) {
  23742. if (ts.hasDynamicName(node)) {
  23743. return;
  23744. }
  23745. if (!resolver.isImplementationOfOverload(node)) {
  23746. emitJsDocComments(node);
  23747. if (node.kind === 213) {
  23748. emitModuleElementDeclarationFlags(node);
  23749. }
  23750. else if (node.kind === 143) {
  23751. emitClassMemberDeclarationFlags(node);
  23752. }
  23753. if (node.kind === 213) {
  23754. write("function ");
  23755. writeTextOfNode(currentSourceFile, node.name);
  23756. }
  23757. else if (node.kind === 144) {
  23758. write("constructor");
  23759. }
  23760. else {
  23761. writeTextOfNode(currentSourceFile, node.name);
  23762. if (ts.hasQuestionToken(node)) {
  23763. write("?");
  23764. }
  23765. }
  23766. emitSignatureDeclaration(node);
  23767. }
  23768. }
  23769. function emitSignatureDeclarationWithJsDocComments(node) {
  23770. emitJsDocComments(node);
  23771. emitSignatureDeclaration(node);
  23772. }
  23773. function emitSignatureDeclaration(node) {
  23774. if (node.kind === 148 || node.kind === 153) {
  23775. write("new ");
  23776. }
  23777. emitTypeParameters(node.typeParameters);
  23778. if (node.kind === 149) {
  23779. write("[");
  23780. }
  23781. else {
  23782. write("(");
  23783. }
  23784. var prevEnclosingDeclaration = enclosingDeclaration;
  23785. enclosingDeclaration = node;
  23786. emitCommaList(node.parameters, emitParameterDeclaration);
  23787. if (node.kind === 149) {
  23788. write("]");
  23789. }
  23790. else {
  23791. write(")");
  23792. }
  23793. var isFunctionTypeOrConstructorType = node.kind === 152 || node.kind === 153;
  23794. if (isFunctionTypeOrConstructorType || node.parent.kind === 155) {
  23795. if (node.type) {
  23796. write(isFunctionTypeOrConstructorType ? " => " : ": ");
  23797. emitType(node.type);
  23798. }
  23799. }
  23800. else if (node.kind !== 144 && !(node.flags & 32)) {
  23801. writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
  23802. }
  23803. enclosingDeclaration = prevEnclosingDeclaration;
  23804. if (!isFunctionTypeOrConstructorType) {
  23805. write(";");
  23806. writeLine();
  23807. }
  23808. function getReturnTypeVisibilityError(symbolAccesibilityResult) {
  23809. var diagnosticMessage;
  23810. switch (node.kind) {
  23811. case 148:
  23812. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23813. ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23814. ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
  23815. break;
  23816. case 147:
  23817. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23818. ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23819. ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
  23820. break;
  23821. case 149:
  23822. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23823. ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23824. ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
  23825. break;
  23826. case 143:
  23827. case 142:
  23828. if (node.flags & 128) {
  23829. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23830. symbolAccesibilityResult.accessibility === 2 ?
  23831. ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  23832. ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23833. ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
  23834. }
  23835. else if (node.parent.kind === 214) {
  23836. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23837. symbolAccesibilityResult.accessibility === 2 ?
  23838. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  23839. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23840. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
  23841. }
  23842. else {
  23843. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23844. ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23845. ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
  23846. }
  23847. break;
  23848. case 213:
  23849. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23850. symbolAccesibilityResult.accessibility === 2 ?
  23851. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  23852. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 :
  23853. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
  23854. break;
  23855. default:
  23856. ts.Debug.fail("This is unknown kind for signature: " + node.kind);
  23857. }
  23858. return {
  23859. diagnosticMessage: diagnosticMessage,
  23860. errorNode: node.name || node
  23861. };
  23862. }
  23863. }
  23864. function emitParameterDeclaration(node) {
  23865. increaseIndent();
  23866. emitJsDocComments(node);
  23867. if (node.dotDotDotToken) {
  23868. write("...");
  23869. }
  23870. if (ts.isBindingPattern(node.name)) {
  23871. emitBindingPattern(node.name);
  23872. }
  23873. else {
  23874. writeTextOfNode(currentSourceFile, node.name);
  23875. }
  23876. if (resolver.isOptionalParameter(node)) {
  23877. write("?");
  23878. }
  23879. decreaseIndent();
  23880. if (node.parent.kind === 152 ||
  23881. node.parent.kind === 153 ||
  23882. node.parent.parent.kind === 155) {
  23883. emitTypeOfVariableDeclarationFromTypeLiteral(node);
  23884. }
  23885. else if (!(node.parent.flags & 32)) {
  23886. writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError);
  23887. }
  23888. function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  23889. var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23890. return diagnosticMessage !== undefined ? {
  23891. diagnosticMessage: diagnosticMessage,
  23892. errorNode: node,
  23893. typeName: node.name
  23894. } : undefined;
  23895. }
  23896. function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
  23897. switch (node.parent.kind) {
  23898. case 144:
  23899. return symbolAccesibilityResult.errorModuleName ?
  23900. symbolAccesibilityResult.accessibility === 2 ?
  23901. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23902. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23903. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
  23904. case 148:
  23905. return symbolAccesibilityResult.errorModuleName ?
  23906. ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23907. ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
  23908. case 147:
  23909. return symbolAccesibilityResult.errorModuleName ?
  23910. ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23911. ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
  23912. case 143:
  23913. case 142:
  23914. if (node.parent.flags & 128) {
  23915. return symbolAccesibilityResult.errorModuleName ?
  23916. symbolAccesibilityResult.accessibility === 2 ?
  23917. ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23918. ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23919. ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
  23920. }
  23921. else if (node.parent.parent.kind === 214) {
  23922. return symbolAccesibilityResult.errorModuleName ?
  23923. symbolAccesibilityResult.accessibility === 2 ?
  23924. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23925. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23926. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
  23927. }
  23928. else {
  23929. return symbolAccesibilityResult.errorModuleName ?
  23930. ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23931. ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
  23932. }
  23933. case 213:
  23934. return symbolAccesibilityResult.errorModuleName ?
  23935. symbolAccesibilityResult.accessibility === 2 ?
  23936. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23937. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
  23938. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
  23939. default:
  23940. ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
  23941. }
  23942. }
  23943. function emitBindingPattern(bindingPattern) {
  23944. if (bindingPattern.kind === 161) {
  23945. write("{");
  23946. emitCommaList(bindingPattern.elements, emitBindingElement);
  23947. write("}");
  23948. }
  23949. else if (bindingPattern.kind === 162) {
  23950. write("[");
  23951. var elements = bindingPattern.elements;
  23952. emitCommaList(elements, emitBindingElement);
  23953. if (elements && elements.hasTrailingComma) {
  23954. write(", ");
  23955. }
  23956. write("]");
  23957. }
  23958. }
  23959. function emitBindingElement(bindingElement) {
  23960. function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
  23961. var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23962. return diagnosticMessage !== undefined ? {
  23963. diagnosticMessage: diagnosticMessage,
  23964. errorNode: bindingElement,
  23965. typeName: bindingElement.name
  23966. } : undefined;
  23967. }
  23968. if (bindingElement.kind === 187) {
  23969. write(" ");
  23970. }
  23971. else if (bindingElement.kind === 163) {
  23972. if (bindingElement.propertyName) {
  23973. writeTextOfNode(currentSourceFile, bindingElement.propertyName);
  23974. write(": ");
  23975. }
  23976. if (bindingElement.name) {
  23977. if (ts.isBindingPattern(bindingElement.name)) {
  23978. emitBindingPattern(bindingElement.name);
  23979. }
  23980. else {
  23981. ts.Debug.assert(bindingElement.name.kind === 69);
  23982. if (bindingElement.dotDotDotToken) {
  23983. write("...");
  23984. }
  23985. writeTextOfNode(currentSourceFile, bindingElement.name);
  23986. }
  23987. }
  23988. }
  23989. }
  23990. }
  23991. function emitNode(node) {
  23992. switch (node.kind) {
  23993. case 213:
  23994. case 218:
  23995. case 221:
  23996. case 215:
  23997. case 214:
  23998. case 216:
  23999. case 217:
  24000. return emitModuleElement(node, isModuleElementVisible(node));
  24001. case 193:
  24002. return emitModuleElement(node, isVariableStatementVisible(node));
  24003. case 222:
  24004. return emitModuleElement(node, !node.importClause);
  24005. case 228:
  24006. return emitExportDeclaration(node);
  24007. case 144:
  24008. case 143:
  24009. case 142:
  24010. return writeFunctionDeclaration(node);
  24011. case 148:
  24012. case 147:
  24013. case 149:
  24014. return emitSignatureDeclarationWithJsDocComments(node);
  24015. case 145:
  24016. case 146:
  24017. return emitAccessorDeclaration(node);
  24018. case 141:
  24019. case 140:
  24020. return emitPropertyDeclaration(node);
  24021. case 247:
  24022. return emitEnumMemberDeclaration(node);
  24023. case 227:
  24024. return emitExportAssignment(node);
  24025. case 248:
  24026. return emitSourceFile(node);
  24027. }
  24028. }
  24029. function writeReferencePath(referencedFile) {
  24030. var declFileName = referencedFile.flags & 8192
  24031. ? referencedFile.fileName
  24032. : ts.shouldEmitToOwnFile(referencedFile, compilerOptions)
  24033. ? ts.getOwnEmitOutputFilePath(referencedFile, host, ".d.ts")
  24034. : ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts";
  24035. declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false);
  24036. referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
  24037. }
  24038. }
  24039. function writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics) {
  24040. var emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile);
  24041. if (!emitDeclarationResult.reportedDeclarationError) {
  24042. var declarationOutput = emitDeclarationResult.referencePathsOutput
  24043. + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo);
  24044. ts.writeFile(host, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, host.getCompilerOptions().emitBOM);
  24045. }
  24046. function getDeclarationOutput(synchronousDeclarationOutput, moduleElementDeclarationEmitInfo) {
  24047. var appliedSyncOutputPos = 0;
  24048. var declarationOutput = "";
  24049. ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
  24050. if (aliasEmitInfo.asynchronousOutput) {
  24051. declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos);
  24052. declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo);
  24053. appliedSyncOutputPos = aliasEmitInfo.outputPos;
  24054. }
  24055. });
  24056. declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos);
  24057. return declarationOutput;
  24058. }
  24059. }
  24060. ts.writeDeclarationFile = writeDeclarationFile;
  24061. })(ts || (ts = {}));
  24062. var ts;
  24063. (function (ts) {
  24064. function isExternalModuleOrDeclarationFile(sourceFile) {
  24065. return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile);
  24066. }
  24067. ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile;
  24068. var entities = {
  24069. "quot": 0x0022,
  24070. "amp": 0x0026,
  24071. "apos": 0x0027,
  24072. "lt": 0x003C,
  24073. "gt": 0x003E,
  24074. "nbsp": 0x00A0,
  24075. "iexcl": 0x00A1,
  24076. "cent": 0x00A2,
  24077. "pound": 0x00A3,
  24078. "curren": 0x00A4,
  24079. "yen": 0x00A5,
  24080. "brvbar": 0x00A6,
  24081. "sect": 0x00A7,
  24082. "uml": 0x00A8,
  24083. "copy": 0x00A9,
  24084. "ordf": 0x00AA,
  24085. "laquo": 0x00AB,
  24086. "not": 0x00AC,
  24087. "shy": 0x00AD,
  24088. "reg": 0x00AE,
  24089. "macr": 0x00AF,
  24090. "deg": 0x00B0,
  24091. "plusmn": 0x00B1,
  24092. "sup2": 0x00B2,
  24093. "sup3": 0x00B3,
  24094. "acute": 0x00B4,
  24095. "micro": 0x00B5,
  24096. "para": 0x00B6,
  24097. "middot": 0x00B7,
  24098. "cedil": 0x00B8,
  24099. "sup1": 0x00B9,
  24100. "ordm": 0x00BA,
  24101. "raquo": 0x00BB,
  24102. "frac14": 0x00BC,
  24103. "frac12": 0x00BD,
  24104. "frac34": 0x00BE,
  24105. "iquest": 0x00BF,
  24106. "Agrave": 0x00C0,
  24107. "Aacute": 0x00C1,
  24108. "Acirc": 0x00C2,
  24109. "Atilde": 0x00C3,
  24110. "Auml": 0x00C4,
  24111. "Aring": 0x00C5,
  24112. "AElig": 0x00C6,
  24113. "Ccedil": 0x00C7,
  24114. "Egrave": 0x00C8,
  24115. "Eacute": 0x00C9,
  24116. "Ecirc": 0x00CA,
  24117. "Euml": 0x00CB,
  24118. "Igrave": 0x00CC,
  24119. "Iacute": 0x00CD,
  24120. "Icirc": 0x00CE,
  24121. "Iuml": 0x00CF,
  24122. "ETH": 0x00D0,
  24123. "Ntilde": 0x00D1,
  24124. "Ograve": 0x00D2,
  24125. "Oacute": 0x00D3,
  24126. "Ocirc": 0x00D4,
  24127. "Otilde": 0x00D5,
  24128. "Ouml": 0x00D6,
  24129. "times": 0x00D7,
  24130. "Oslash": 0x00D8,
  24131. "Ugrave": 0x00D9,
  24132. "Uacute": 0x00DA,
  24133. "Ucirc": 0x00DB,
  24134. "Uuml": 0x00DC,
  24135. "Yacute": 0x00DD,
  24136. "THORN": 0x00DE,
  24137. "szlig": 0x00DF,
  24138. "agrave": 0x00E0,
  24139. "aacute": 0x00E1,
  24140. "acirc": 0x00E2,
  24141. "atilde": 0x00E3,
  24142. "auml": 0x00E4,
  24143. "aring": 0x00E5,
  24144. "aelig": 0x00E6,
  24145. "ccedil": 0x00E7,
  24146. "egrave": 0x00E8,
  24147. "eacute": 0x00E9,
  24148. "ecirc": 0x00EA,
  24149. "euml": 0x00EB,
  24150. "igrave": 0x00EC,
  24151. "iacute": 0x00ED,
  24152. "icirc": 0x00EE,
  24153. "iuml": 0x00EF,
  24154. "eth": 0x00F0,
  24155. "ntilde": 0x00F1,
  24156. "ograve": 0x00F2,
  24157. "oacute": 0x00F3,
  24158. "ocirc": 0x00F4,
  24159. "otilde": 0x00F5,
  24160. "ouml": 0x00F6,
  24161. "divide": 0x00F7,
  24162. "oslash": 0x00F8,
  24163. "ugrave": 0x00F9,
  24164. "uacute": 0x00FA,
  24165. "ucirc": 0x00FB,
  24166. "uuml": 0x00FC,
  24167. "yacute": 0x00FD,
  24168. "thorn": 0x00FE,
  24169. "yuml": 0x00FF,
  24170. "OElig": 0x0152,
  24171. "oelig": 0x0153,
  24172. "Scaron": 0x0160,
  24173. "scaron": 0x0161,
  24174. "Yuml": 0x0178,
  24175. "fnof": 0x0192,
  24176. "circ": 0x02C6,
  24177. "tilde": 0x02DC,
  24178. "Alpha": 0x0391,
  24179. "Beta": 0x0392,
  24180. "Gamma": 0x0393,
  24181. "Delta": 0x0394,
  24182. "Epsilon": 0x0395,
  24183. "Zeta": 0x0396,
  24184. "Eta": 0x0397,
  24185. "Theta": 0x0398,
  24186. "Iota": 0x0399,
  24187. "Kappa": 0x039A,
  24188. "Lambda": 0x039B,
  24189. "Mu": 0x039C,
  24190. "Nu": 0x039D,
  24191. "Xi": 0x039E,
  24192. "Omicron": 0x039F,
  24193. "Pi": 0x03A0,
  24194. "Rho": 0x03A1,
  24195. "Sigma": 0x03A3,
  24196. "Tau": 0x03A4,
  24197. "Upsilon": 0x03A5,
  24198. "Phi": 0x03A6,
  24199. "Chi": 0x03A7,
  24200. "Psi": 0x03A8,
  24201. "Omega": 0x03A9,
  24202. "alpha": 0x03B1,
  24203. "beta": 0x03B2,
  24204. "gamma": 0x03B3,
  24205. "delta": 0x03B4,
  24206. "epsilon": 0x03B5,
  24207. "zeta": 0x03B6,
  24208. "eta": 0x03B7,
  24209. "theta": 0x03B8,
  24210. "iota": 0x03B9,
  24211. "kappa": 0x03BA,
  24212. "lambda": 0x03BB,
  24213. "mu": 0x03BC,
  24214. "nu": 0x03BD,
  24215. "xi": 0x03BE,
  24216. "omicron": 0x03BF,
  24217. "pi": 0x03C0,
  24218. "rho": 0x03C1,
  24219. "sigmaf": 0x03C2,
  24220. "sigma": 0x03C3,
  24221. "tau": 0x03C4,
  24222. "upsilon": 0x03C5,
  24223. "phi": 0x03C6,
  24224. "chi": 0x03C7,
  24225. "psi": 0x03C8,
  24226. "omega": 0x03C9,
  24227. "thetasym": 0x03D1,
  24228. "upsih": 0x03D2,
  24229. "piv": 0x03D6,
  24230. "ensp": 0x2002,
  24231. "emsp": 0x2003,
  24232. "thinsp": 0x2009,
  24233. "zwnj": 0x200C,
  24234. "zwj": 0x200D,
  24235. "lrm": 0x200E,
  24236. "rlm": 0x200F,
  24237. "ndash": 0x2013,
  24238. "mdash": 0x2014,
  24239. "lsquo": 0x2018,
  24240. "rsquo": 0x2019,
  24241. "sbquo": 0x201A,
  24242. "ldquo": 0x201C,
  24243. "rdquo": 0x201D,
  24244. "bdquo": 0x201E,
  24245. "dagger": 0x2020,
  24246. "Dagger": 0x2021,
  24247. "bull": 0x2022,
  24248. "hellip": 0x2026,
  24249. "permil": 0x2030,
  24250. "prime": 0x2032,
  24251. "Prime": 0x2033,
  24252. "lsaquo": 0x2039,
  24253. "rsaquo": 0x203A,
  24254. "oline": 0x203E,
  24255. "frasl": 0x2044,
  24256. "euro": 0x20AC,
  24257. "image": 0x2111,
  24258. "weierp": 0x2118,
  24259. "real": 0x211C,
  24260. "trade": 0x2122,
  24261. "alefsym": 0x2135,
  24262. "larr": 0x2190,
  24263. "uarr": 0x2191,
  24264. "rarr": 0x2192,
  24265. "darr": 0x2193,
  24266. "harr": 0x2194,
  24267. "crarr": 0x21B5,
  24268. "lArr": 0x21D0,
  24269. "uArr": 0x21D1,
  24270. "rArr": 0x21D2,
  24271. "dArr": 0x21D3,
  24272. "hArr": 0x21D4,
  24273. "forall": 0x2200,
  24274. "part": 0x2202,
  24275. "exist": 0x2203,
  24276. "empty": 0x2205,
  24277. "nabla": 0x2207,
  24278. "isin": 0x2208,
  24279. "notin": 0x2209,
  24280. "ni": 0x220B,
  24281. "prod": 0x220F,
  24282. "sum": 0x2211,
  24283. "minus": 0x2212,
  24284. "lowast": 0x2217,
  24285. "radic": 0x221A,
  24286. "prop": 0x221D,
  24287. "infin": 0x221E,
  24288. "ang": 0x2220,
  24289. "and": 0x2227,
  24290. "or": 0x2228,
  24291. "cap": 0x2229,
  24292. "cup": 0x222A,
  24293. "int": 0x222B,
  24294. "there4": 0x2234,
  24295. "sim": 0x223C,
  24296. "cong": 0x2245,
  24297. "asymp": 0x2248,
  24298. "ne": 0x2260,
  24299. "equiv": 0x2261,
  24300. "le": 0x2264,
  24301. "ge": 0x2265,
  24302. "sub": 0x2282,
  24303. "sup": 0x2283,
  24304. "nsub": 0x2284,
  24305. "sube": 0x2286,
  24306. "supe": 0x2287,
  24307. "oplus": 0x2295,
  24308. "otimes": 0x2297,
  24309. "perp": 0x22A5,
  24310. "sdot": 0x22C5,
  24311. "lceil": 0x2308,
  24312. "rceil": 0x2309,
  24313. "lfloor": 0x230A,
  24314. "rfloor": 0x230B,
  24315. "lang": 0x2329,
  24316. "rang": 0x232A,
  24317. "loz": 0x25CA,
  24318. "spades": 0x2660,
  24319. "clubs": 0x2663,
  24320. "hearts": 0x2665,
  24321. "diams": 0x2666
  24322. };
  24323. function emitFiles(resolver, host, targetSourceFile) {
  24324. var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};";
  24325. var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};";
  24326. var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};";
  24327. var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};";
  24328. var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};";
  24329. var compilerOptions = host.getCompilerOptions();
  24330. var languageVersion = compilerOptions.target || 0;
  24331. var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 ? 5 : 0;
  24332. var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined;
  24333. var diagnostics = [];
  24334. var newLine = host.getNewLine();
  24335. var jsxDesugaring = host.getCompilerOptions().jsx !== 1;
  24336. var shouldEmitJsx = function (s) { return (s.languageVariant === 1 && !jsxDesugaring); };
  24337. if (targetSourceFile === undefined) {
  24338. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  24339. if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) {
  24340. var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js");
  24341. emitFile(jsFilePath, sourceFile);
  24342. }
  24343. });
  24344. if (compilerOptions.outFile || compilerOptions.out) {
  24345. emitFile(compilerOptions.outFile || compilerOptions.out);
  24346. }
  24347. }
  24348. else {
  24349. if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
  24350. var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js");
  24351. emitFile(jsFilePath, targetSourceFile);
  24352. }
  24353. else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) {
  24354. emitFile(compilerOptions.outFile || compilerOptions.out);
  24355. }
  24356. }
  24357. diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics);
  24358. return {
  24359. emitSkipped: false,
  24360. diagnostics: diagnostics,
  24361. sourceMaps: sourceMapDataList
  24362. };
  24363. function isUniqueLocalName(name, container) {
  24364. for (var node = container; ts.isNodeDescendentOf(node, container); node = node.nextContainer) {
  24365. if (node.locals && ts.hasProperty(node.locals, name)) {
  24366. if (node.locals[name].flags & (107455 | 1048576 | 8388608)) {
  24367. return false;
  24368. }
  24369. }
  24370. }
  24371. return true;
  24372. }
  24373. function emitJavaScript(jsFilePath, root) {
  24374. var writer = ts.createTextWriter(newLine);
  24375. var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent;
  24376. var currentSourceFile;
  24377. var exportFunctionForFile;
  24378. var generatedNameSet = {};
  24379. var nodeToGeneratedName = [];
  24380. var computedPropertyNamesToGeneratedNames;
  24381. var extendsEmitted = false;
  24382. var decorateEmitted = false;
  24383. var paramEmitted = false;
  24384. var awaiterEmitted = false;
  24385. var tempFlags = 0;
  24386. var tempVariables;
  24387. var tempParameters;
  24388. var externalImports;
  24389. var exportSpecifiers;
  24390. var exportEquals;
  24391. var hasExportStars;
  24392. var writeEmittedFiles = writeJavaScriptFile;
  24393. var detachedCommentsInfo;
  24394. var writeComment = ts.writeCommentRange;
  24395. var emit = emitNodeWithCommentsAndWithoutSourcemap;
  24396. var emitStart = function (node) { };
  24397. var emitEnd = function (node) { };
  24398. var emitToken = emitTokenText;
  24399. var scopeEmitStart = function (scopeDeclaration, scopeName) { };
  24400. var scopeEmitEnd = function () { };
  24401. var sourceMapData;
  24402. var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker;
  24403. var moduleEmitDelegates = (_a = {},
  24404. _a[5] = emitES6Module,
  24405. _a[2] = emitAMDModule,
  24406. _a[4] = emitSystemModule,
  24407. _a[3] = emitUMDModule,
  24408. _a[1] = emitCommonJSModule,
  24409. _a
  24410. );
  24411. if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) {
  24412. initializeEmitterWithSourceMaps();
  24413. }
  24414. if (root) {
  24415. emitSourceFile(root);
  24416. }
  24417. else {
  24418. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  24419. if (!isExternalModuleOrDeclarationFile(sourceFile)) {
  24420. emitSourceFile(sourceFile);
  24421. }
  24422. });
  24423. }
  24424. writeLine();
  24425. writeEmittedFiles(writer.getText(), compilerOptions.emitBOM);
  24426. return;
  24427. function emitSourceFile(sourceFile) {
  24428. currentSourceFile = sourceFile;
  24429. exportFunctionForFile = undefined;
  24430. emit(sourceFile);
  24431. }
  24432. function isUniqueName(name) {
  24433. return !resolver.hasGlobalName(name) &&
  24434. !ts.hasProperty(currentSourceFile.identifiers, name) &&
  24435. !ts.hasProperty(generatedNameSet, name);
  24436. }
  24437. function makeTempVariableName(flags) {
  24438. if (flags && !(tempFlags & flags)) {
  24439. var name_19 = flags === 268435456 ? "_i" : "_n";
  24440. if (isUniqueName(name_19)) {
  24441. tempFlags |= flags;
  24442. return name_19;
  24443. }
  24444. }
  24445. while (true) {
  24446. var count = tempFlags & 268435455;
  24447. tempFlags++;
  24448. if (count !== 8 && count !== 13) {
  24449. var name_20 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26);
  24450. if (isUniqueName(name_20)) {
  24451. return name_20;
  24452. }
  24453. }
  24454. }
  24455. }
  24456. function makeUniqueName(baseName) {
  24457. if (baseName.charCodeAt(baseName.length - 1) !== 95) {
  24458. baseName += "_";
  24459. }
  24460. var i = 1;
  24461. while (true) {
  24462. var generatedName = baseName + i;
  24463. if (isUniqueName(generatedName)) {
  24464. return generatedNameSet[generatedName] = generatedName;
  24465. }
  24466. i++;
  24467. }
  24468. }
  24469. function generateNameForModuleOrEnum(node) {
  24470. var name = node.name.text;
  24471. return isUniqueLocalName(name, node) ? name : makeUniqueName(name);
  24472. }
  24473. function generateNameForImportOrExportDeclaration(node) {
  24474. var expr = ts.getExternalModuleName(node);
  24475. var baseName = expr.kind === 9 ?
  24476. ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module";
  24477. return makeUniqueName(baseName);
  24478. }
  24479. function generateNameForExportDefault() {
  24480. return makeUniqueName("default");
  24481. }
  24482. function generateNameForClassExpression() {
  24483. return makeUniqueName("class");
  24484. }
  24485. function generateNameForNode(node) {
  24486. switch (node.kind) {
  24487. case 69:
  24488. return makeUniqueName(node.text);
  24489. case 218:
  24490. case 217:
  24491. return generateNameForModuleOrEnum(node);
  24492. case 222:
  24493. case 228:
  24494. return generateNameForImportOrExportDeclaration(node);
  24495. case 213:
  24496. case 214:
  24497. case 227:
  24498. return generateNameForExportDefault();
  24499. case 186:
  24500. return generateNameForClassExpression();
  24501. }
  24502. }
  24503. function getGeneratedNameForNode(node) {
  24504. var id = ts.getNodeId(node);
  24505. return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node)));
  24506. }
  24507. function initializeEmitterWithSourceMaps() {
  24508. var sourceMapDir;
  24509. var sourceMapSourceIndex = -1;
  24510. var sourceMapNameIndexMap = {};
  24511. var sourceMapNameIndices = [];
  24512. function getSourceMapNameIndex() {
  24513. return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1;
  24514. }
  24515. var lastRecordedSourceMapSpan;
  24516. var lastEncodedSourceMapSpan = {
  24517. emittedLine: 1,
  24518. emittedColumn: 1,
  24519. sourceLine: 1,
  24520. sourceColumn: 1,
  24521. sourceIndex: 0
  24522. };
  24523. var lastEncodedNameIndex = 0;
  24524. function encodeLastRecordedSourceMapSpan() {
  24525. if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) {
  24526. return;
  24527. }
  24528. var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn;
  24529. if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) {
  24530. if (sourceMapData.sourceMapMappings) {
  24531. sourceMapData.sourceMapMappings += ",";
  24532. }
  24533. }
  24534. else {
  24535. for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) {
  24536. sourceMapData.sourceMapMappings += ";";
  24537. }
  24538. prevEncodedEmittedColumn = 1;
  24539. }
  24540. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn);
  24541. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex);
  24542. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine);
  24543. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn);
  24544. if (lastRecordedSourceMapSpan.nameIndex >= 0) {
  24545. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex);
  24546. lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex;
  24547. }
  24548. lastEncodedSourceMapSpan = lastRecordedSourceMapSpan;
  24549. sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan);
  24550. function base64VLQFormatEncode(inValue) {
  24551. function base64FormatEncode(inValue) {
  24552. if (inValue < 64) {
  24553. return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue);
  24554. }
  24555. throw TypeError(inValue + ": not a 64 based value");
  24556. }
  24557. if (inValue < 0) {
  24558. inValue = ((-inValue) << 1) + 1;
  24559. }
  24560. else {
  24561. inValue = inValue << 1;
  24562. }
  24563. var encodedStr = "";
  24564. do {
  24565. var currentDigit = inValue & 31;
  24566. inValue = inValue >> 5;
  24567. if (inValue > 0) {
  24568. currentDigit = currentDigit | 32;
  24569. }
  24570. encodedStr = encodedStr + base64FormatEncode(currentDigit);
  24571. } while (inValue > 0);
  24572. return encodedStr;
  24573. }
  24574. }
  24575. function recordSourceMapSpan(pos) {
  24576. var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos);
  24577. sourceLinePos.line++;
  24578. sourceLinePos.character++;
  24579. var emittedLine = writer.getLine();
  24580. var emittedColumn = writer.getColumn();
  24581. if (!lastRecordedSourceMapSpan ||
  24582. lastRecordedSourceMapSpan.emittedLine !== emittedLine ||
  24583. lastRecordedSourceMapSpan.emittedColumn !== emittedColumn ||
  24584. (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex &&
  24585. (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line ||
  24586. (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) {
  24587. encodeLastRecordedSourceMapSpan();
  24588. lastRecordedSourceMapSpan = {
  24589. emittedLine: emittedLine,
  24590. emittedColumn: emittedColumn,
  24591. sourceLine: sourceLinePos.line,
  24592. sourceColumn: sourceLinePos.character,
  24593. nameIndex: getSourceMapNameIndex(),
  24594. sourceIndex: sourceMapSourceIndex
  24595. };
  24596. }
  24597. else {
  24598. lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line;
  24599. lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character;
  24600. lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex;
  24601. }
  24602. }
  24603. function recordEmitNodeStartSpan(node) {
  24604. recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos));
  24605. }
  24606. function recordEmitNodeEndSpan(node) {
  24607. recordSourceMapSpan(node.end);
  24608. }
  24609. function writeTextWithSpanRecord(tokenKind, startPos, emitFn) {
  24610. var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos);
  24611. recordSourceMapSpan(tokenStartPos);
  24612. var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn);
  24613. recordSourceMapSpan(tokenEndPos);
  24614. return tokenEndPos;
  24615. }
  24616. function recordNewSourceFileStart(node) {
  24617. var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir;
  24618. sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, true));
  24619. sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
  24620. sourceMapData.inputSourceFileNames.push(node.fileName);
  24621. if (compilerOptions.inlineSources) {
  24622. if (!sourceMapData.sourceMapSourcesContent) {
  24623. sourceMapData.sourceMapSourcesContent = [];
  24624. }
  24625. sourceMapData.sourceMapSourcesContent.push(node.text);
  24626. }
  24627. }
  24628. function recordScopeNameOfNode(node, scopeName) {
  24629. function recordScopeNameIndex(scopeNameIndex) {
  24630. sourceMapNameIndices.push(scopeNameIndex);
  24631. }
  24632. function recordScopeNameStart(scopeName) {
  24633. var scopeNameIndex = -1;
  24634. if (scopeName) {
  24635. var parentIndex = getSourceMapNameIndex();
  24636. if (parentIndex !== -1) {
  24637. var name_21 = node.name;
  24638. if (!name_21 || name_21.kind !== 136) {
  24639. scopeName = "." + scopeName;
  24640. }
  24641. scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName;
  24642. }
  24643. scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName);
  24644. if (scopeNameIndex === undefined) {
  24645. scopeNameIndex = sourceMapData.sourceMapNames.length;
  24646. sourceMapData.sourceMapNames.push(scopeName);
  24647. sourceMapNameIndexMap[scopeName] = scopeNameIndex;
  24648. }
  24649. }
  24650. recordScopeNameIndex(scopeNameIndex);
  24651. }
  24652. if (scopeName) {
  24653. recordScopeNameStart(scopeName);
  24654. }
  24655. else if (node.kind === 213 ||
  24656. node.kind === 173 ||
  24657. node.kind === 143 ||
  24658. node.kind === 142 ||
  24659. node.kind === 145 ||
  24660. node.kind === 146 ||
  24661. node.kind === 218 ||
  24662. node.kind === 214 ||
  24663. node.kind === 217) {
  24664. if (node.name) {
  24665. var name_22 = node.name;
  24666. scopeName = name_22.kind === 136
  24667. ? ts.getTextOfNode(name_22)
  24668. : node.name.text;
  24669. }
  24670. recordScopeNameStart(scopeName);
  24671. }
  24672. else {
  24673. recordScopeNameIndex(getSourceMapNameIndex());
  24674. }
  24675. }
  24676. function recordScopeNameEnd() {
  24677. sourceMapNameIndices.pop();
  24678. }
  24679. ;
  24680. function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) {
  24681. recordSourceMapSpan(comment.pos);
  24682. ts.writeCommentRange(currentSourceFile, writer, comment, newLine);
  24683. recordSourceMapSpan(comment.end);
  24684. }
  24685. function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) {
  24686. if (typeof JSON !== "undefined") {
  24687. var map_1 = {
  24688. version: version,
  24689. file: file,
  24690. sourceRoot: sourceRoot,
  24691. sources: sources,
  24692. names: names,
  24693. mappings: mappings
  24694. };
  24695. if (sourcesContent !== undefined) {
  24696. map_1.sourcesContent = sourcesContent;
  24697. }
  24698. return JSON.stringify(map_1);
  24699. }
  24700. return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}";
  24701. function serializeStringArray(list) {
  24702. var output = "";
  24703. for (var i = 0, n = list.length; i < n; i++) {
  24704. if (i) {
  24705. output += ",";
  24706. }
  24707. output += "\"" + ts.escapeString(list[i]) + "\"";
  24708. }
  24709. return output;
  24710. }
  24711. }
  24712. function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) {
  24713. encodeLastRecordedSourceMapSpan();
  24714. var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent);
  24715. sourceMapDataList.push(sourceMapData);
  24716. var sourceMapUrl;
  24717. if (compilerOptions.inlineSourceMap) {
  24718. var base64SourceMapText = ts.convertToBase64(sourceMapText);
  24719. sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText;
  24720. }
  24721. else {
  24722. ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, false);
  24723. sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL;
  24724. }
  24725. writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark);
  24726. }
  24727. var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath));
  24728. sourceMapData = {
  24729. sourceMapFilePath: jsFilePath + ".map",
  24730. jsSourceMappingURL: sourceMapJsFile + ".map",
  24731. sourceMapFile: sourceMapJsFile,
  24732. sourceMapSourceRoot: compilerOptions.sourceRoot || "",
  24733. sourceMapSources: [],
  24734. inputSourceFileNames: [],
  24735. sourceMapNames: [],
  24736. sourceMapMappings: "",
  24737. sourceMapSourcesContent: undefined,
  24738. sourceMapDecodedMappings: []
  24739. };
  24740. sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot);
  24741. if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47) {
  24742. sourceMapData.sourceMapSourceRoot += ts.directorySeparator;
  24743. }
  24744. if (compilerOptions.mapRoot) {
  24745. sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot);
  24746. if (root) {
  24747. sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir));
  24748. }
  24749. if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) {
  24750. sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir);
  24751. sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true);
  24752. }
  24753. else {
  24754. sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL);
  24755. }
  24756. }
  24757. else {
  24758. sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath));
  24759. }
  24760. function emitNodeWithSourceMap(node) {
  24761. if (node) {
  24762. if (ts.nodeIsSynthesized(node)) {
  24763. return emitNodeWithoutSourceMap(node);
  24764. }
  24765. if (node.kind !== 248) {
  24766. recordEmitNodeStartSpan(node);
  24767. emitNodeWithoutSourceMap(node);
  24768. recordEmitNodeEndSpan(node);
  24769. }
  24770. else {
  24771. recordNewSourceFileStart(node);
  24772. emitNodeWithoutSourceMap(node);
  24773. }
  24774. }
  24775. }
  24776. function emitNodeWithCommentsAndWithSourcemap(node) {
  24777. emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap);
  24778. }
  24779. writeEmittedFiles = writeJavaScriptAndSourceMapFile;
  24780. emit = emitNodeWithCommentsAndWithSourcemap;
  24781. emitStart = recordEmitNodeStartSpan;
  24782. emitEnd = recordEmitNodeEndSpan;
  24783. emitToken = writeTextWithSpanRecord;
  24784. scopeEmitStart = recordScopeNameOfNode;
  24785. scopeEmitEnd = recordScopeNameEnd;
  24786. writeComment = writeCommentRangeWithMap;
  24787. }
  24788. function writeJavaScriptFile(emitOutput, writeByteOrderMark) {
  24789. ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
  24790. }
  24791. function createTempVariable(flags) {
  24792. var result = ts.createSynthesizedNode(69);
  24793. result.text = makeTempVariableName(flags);
  24794. return result;
  24795. }
  24796. function recordTempDeclaration(name) {
  24797. if (!tempVariables) {
  24798. tempVariables = [];
  24799. }
  24800. tempVariables.push(name);
  24801. }
  24802. function createAndRecordTempVariable(flags) {
  24803. var temp = createTempVariable(flags);
  24804. recordTempDeclaration(temp);
  24805. return temp;
  24806. }
  24807. function emitTempDeclarations(newLine) {
  24808. if (tempVariables) {
  24809. if (newLine) {
  24810. writeLine();
  24811. }
  24812. else {
  24813. write(" ");
  24814. }
  24815. write("var ");
  24816. emitCommaList(tempVariables);
  24817. write(";");
  24818. }
  24819. }
  24820. function emitTokenText(tokenKind, startPos, emitFn) {
  24821. var tokenString = ts.tokenToString(tokenKind);
  24822. if (emitFn) {
  24823. emitFn();
  24824. }
  24825. else {
  24826. write(tokenString);
  24827. }
  24828. return startPos + tokenString.length;
  24829. }
  24830. function emitOptional(prefix, node) {
  24831. if (node) {
  24832. write(prefix);
  24833. emit(node);
  24834. }
  24835. }
  24836. function emitParenthesizedIf(node, parenthesized) {
  24837. if (parenthesized) {
  24838. write("(");
  24839. }
  24840. emit(node);
  24841. if (parenthesized) {
  24842. write(")");
  24843. }
  24844. }
  24845. function emitTrailingCommaIfPresent(nodeList) {
  24846. if (nodeList.hasTrailingComma) {
  24847. write(",");
  24848. }
  24849. }
  24850. function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) {
  24851. ts.Debug.assert(nodes.length > 0);
  24852. increaseIndent();
  24853. if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) {
  24854. if (spacesBetweenBraces) {
  24855. write(" ");
  24856. }
  24857. }
  24858. else {
  24859. writeLine();
  24860. }
  24861. for (var i = 0, n = nodes.length; i < n; i++) {
  24862. if (i) {
  24863. if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) {
  24864. write(", ");
  24865. }
  24866. else {
  24867. write(",");
  24868. writeLine();
  24869. }
  24870. }
  24871. emit(nodes[i]);
  24872. }
  24873. if (nodes.hasTrailingComma && allowTrailingComma) {
  24874. write(",");
  24875. }
  24876. decreaseIndent();
  24877. if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) {
  24878. if (spacesBetweenBraces) {
  24879. write(" ");
  24880. }
  24881. }
  24882. else {
  24883. writeLine();
  24884. }
  24885. }
  24886. function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) {
  24887. if (!emitNode) {
  24888. emitNode = emit;
  24889. }
  24890. for (var i = 0; i < count; i++) {
  24891. if (multiLine) {
  24892. if (i || leadingComma) {
  24893. write(",");
  24894. }
  24895. writeLine();
  24896. }
  24897. else {
  24898. if (i || leadingComma) {
  24899. write(", ");
  24900. }
  24901. }
  24902. var node = nodes[start + i];
  24903. emitTrailingCommentsOfPosition(node.pos);
  24904. emitNode(node);
  24905. leadingComma = true;
  24906. }
  24907. if (trailingComma) {
  24908. write(",");
  24909. }
  24910. if (multiLine && !noTrailingNewLine) {
  24911. writeLine();
  24912. }
  24913. return count;
  24914. }
  24915. function emitCommaList(nodes) {
  24916. if (nodes) {
  24917. emitList(nodes, 0, nodes.length, false, false);
  24918. }
  24919. }
  24920. function emitLines(nodes) {
  24921. emitLinesStartingAt(nodes, 0);
  24922. }
  24923. function emitLinesStartingAt(nodes, startIndex) {
  24924. for (var i = startIndex; i < nodes.length; i++) {
  24925. writeLine();
  24926. emit(nodes[i]);
  24927. }
  24928. }
  24929. function isBinaryOrOctalIntegerLiteral(node, text) {
  24930. if (node.kind === 8 && text.length > 1) {
  24931. switch (text.charCodeAt(1)) {
  24932. case 98:
  24933. case 66:
  24934. case 111:
  24935. case 79:
  24936. return true;
  24937. }
  24938. }
  24939. return false;
  24940. }
  24941. function emitLiteral(node) {
  24942. var text = getLiteralText(node);
  24943. if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 || ts.isTemplateLiteralKind(node.kind))) {
  24944. writer.writeLiteral(text);
  24945. }
  24946. else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) {
  24947. write(node.text);
  24948. }
  24949. else {
  24950. write(text);
  24951. }
  24952. }
  24953. function getLiteralText(node) {
  24954. if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) {
  24955. return getQuotedEscapedLiteralText("\"", node.text, "\"");
  24956. }
  24957. if (node.parent) {
  24958. return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
  24959. }
  24960. switch (node.kind) {
  24961. case 9:
  24962. return getQuotedEscapedLiteralText("\"", node.text, "\"");
  24963. case 11:
  24964. return getQuotedEscapedLiteralText("`", node.text, "`");
  24965. case 12:
  24966. return getQuotedEscapedLiteralText("`", node.text, "${");
  24967. case 13:
  24968. return getQuotedEscapedLiteralText("}", node.text, "${");
  24969. case 14:
  24970. return getQuotedEscapedLiteralText("}", node.text, "`");
  24971. case 8:
  24972. return node.text;
  24973. }
  24974. ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for.");
  24975. }
  24976. function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) {
  24977. return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote;
  24978. }
  24979. function emitDownlevelRawTemplateLiteral(node) {
  24980. var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
  24981. var isLast = node.kind === 11 || node.kind === 14;
  24982. text = text.substring(1, text.length - (isLast ? 1 : 2));
  24983. text = text.replace(/\r\n?/g, "\n");
  24984. text = ts.escapeString(text);
  24985. write("\"" + text + "\"");
  24986. }
  24987. function emitDownlevelTaggedTemplateArray(node, literalEmitter) {
  24988. write("[");
  24989. if (node.template.kind === 11) {
  24990. literalEmitter(node.template);
  24991. }
  24992. else {
  24993. literalEmitter(node.template.head);
  24994. ts.forEach(node.template.templateSpans, function (child) {
  24995. write(", ");
  24996. literalEmitter(child.literal);
  24997. });
  24998. }
  24999. write("]");
  25000. }
  25001. function emitDownlevelTaggedTemplate(node) {
  25002. var tempVariable = createAndRecordTempVariable(0);
  25003. write("(");
  25004. emit(tempVariable);
  25005. write(" = ");
  25006. emitDownlevelTaggedTemplateArray(node, emit);
  25007. write(", ");
  25008. emit(tempVariable);
  25009. write(".raw = ");
  25010. emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral);
  25011. write(", ");
  25012. emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag));
  25013. write("(");
  25014. emit(tempVariable);
  25015. if (node.template.kind === 183) {
  25016. ts.forEach(node.template.templateSpans, function (templateSpan) {
  25017. write(", ");
  25018. var needsParens = templateSpan.expression.kind === 181
  25019. && templateSpan.expression.operatorToken.kind === 24;
  25020. emitParenthesizedIf(templateSpan.expression, needsParens);
  25021. });
  25022. }
  25023. write("))");
  25024. }
  25025. function emitTemplateExpression(node) {
  25026. if (languageVersion >= 2) {
  25027. ts.forEachChild(node, emit);
  25028. return;
  25029. }
  25030. var emitOuterParens = ts.isExpression(node.parent)
  25031. && templateNeedsParens(node, node.parent);
  25032. if (emitOuterParens) {
  25033. write("(");
  25034. }
  25035. var headEmitted = false;
  25036. if (shouldEmitTemplateHead()) {
  25037. emitLiteral(node.head);
  25038. headEmitted = true;
  25039. }
  25040. for (var i = 0, n = node.templateSpans.length; i < n; i++) {
  25041. var templateSpan = node.templateSpans[i];
  25042. var needsParens = templateSpan.expression.kind !== 172
  25043. && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1;
  25044. if (i > 0 || headEmitted) {
  25045. write(" + ");
  25046. }
  25047. emitParenthesizedIf(templateSpan.expression, needsParens);
  25048. if (templateSpan.literal.text.length !== 0) {
  25049. write(" + ");
  25050. emitLiteral(templateSpan.literal);
  25051. }
  25052. }
  25053. if (emitOuterParens) {
  25054. write(")");
  25055. }
  25056. function shouldEmitTemplateHead() {
  25057. ts.Debug.assert(node.templateSpans.length !== 0);
  25058. return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0;
  25059. }
  25060. function templateNeedsParens(template, parent) {
  25061. switch (parent.kind) {
  25062. case 168:
  25063. case 169:
  25064. return parent.expression === template;
  25065. case 170:
  25066. case 172:
  25067. return false;
  25068. default:
  25069. return comparePrecedenceToBinaryPlus(parent) !== -1;
  25070. }
  25071. }
  25072. function comparePrecedenceToBinaryPlus(expression) {
  25073. switch (expression.kind) {
  25074. case 181:
  25075. switch (expression.operatorToken.kind) {
  25076. case 37:
  25077. case 39:
  25078. case 40:
  25079. return 1;
  25080. case 35:
  25081. case 36:
  25082. return 0;
  25083. default:
  25084. return -1;
  25085. }
  25086. case 184:
  25087. case 182:
  25088. return -1;
  25089. default:
  25090. return 1;
  25091. }
  25092. }
  25093. }
  25094. function emitTemplateSpan(span) {
  25095. emit(span.expression);
  25096. emit(span.literal);
  25097. }
  25098. function jsxEmitReact(node) {
  25099. function emitTagName(name) {
  25100. if (name.kind === 69 && ts.isIntrinsicJsxName(name.text)) {
  25101. write("\"");
  25102. emit(name);
  25103. write("\"");
  25104. }
  25105. else {
  25106. emit(name);
  25107. }
  25108. }
  25109. function emitAttributeName(name) {
  25110. if (/[A-Za-z_]+[\w*]/.test(name.text)) {
  25111. write("\"");
  25112. emit(name);
  25113. write("\"");
  25114. }
  25115. else {
  25116. emit(name);
  25117. }
  25118. }
  25119. function emitJsxAttribute(node) {
  25120. emitAttributeName(node.name);
  25121. write(": ");
  25122. if (node.initializer) {
  25123. emit(node.initializer);
  25124. }
  25125. else {
  25126. write("true");
  25127. }
  25128. }
  25129. function emitJsxElement(openingNode, children) {
  25130. var syntheticReactRef = ts.createSynthesizedNode(69);
  25131. syntheticReactRef.text = "React";
  25132. syntheticReactRef.parent = openingNode;
  25133. emitLeadingComments(openingNode);
  25134. emitExpressionIdentifier(syntheticReactRef);
  25135. write(".createElement(");
  25136. emitTagName(openingNode.tagName);
  25137. write(", ");
  25138. if (openingNode.attributes.length === 0) {
  25139. write("null");
  25140. }
  25141. else {
  25142. var attrs = openingNode.attributes;
  25143. if (ts.forEach(attrs, function (attr) { return attr.kind === 239; })) {
  25144. emitExpressionIdentifier(syntheticReactRef);
  25145. write(".__spread(");
  25146. var haveOpenedObjectLiteral = false;
  25147. for (var i_1 = 0; i_1 < attrs.length; i_1++) {
  25148. if (attrs[i_1].kind === 239) {
  25149. if (i_1 === 0) {
  25150. write("{}, ");
  25151. }
  25152. if (haveOpenedObjectLiteral) {
  25153. write("}");
  25154. haveOpenedObjectLiteral = false;
  25155. }
  25156. if (i_1 > 0) {
  25157. write(", ");
  25158. }
  25159. emit(attrs[i_1].expression);
  25160. }
  25161. else {
  25162. ts.Debug.assert(attrs[i_1].kind === 238);
  25163. if (haveOpenedObjectLiteral) {
  25164. write(", ");
  25165. }
  25166. else {
  25167. haveOpenedObjectLiteral = true;
  25168. if (i_1 > 0) {
  25169. write(", ");
  25170. }
  25171. write("{");
  25172. }
  25173. emitJsxAttribute(attrs[i_1]);
  25174. }
  25175. }
  25176. if (haveOpenedObjectLiteral)
  25177. write("}");
  25178. write(")");
  25179. }
  25180. else {
  25181. write("{");
  25182. for (var i = 0; i < attrs.length; i++) {
  25183. if (i > 0) {
  25184. write(", ");
  25185. }
  25186. emitJsxAttribute(attrs[i]);
  25187. }
  25188. write("}");
  25189. }
  25190. }
  25191. if (children) {
  25192. for (var i = 0; i < children.length; i++) {
  25193. if (children[i].kind === 240 && !(children[i].expression)) {
  25194. continue;
  25195. }
  25196. if (children[i].kind === 236) {
  25197. var text = getTextToEmit(children[i]);
  25198. if (text !== undefined) {
  25199. write(", \"");
  25200. write(text);
  25201. write("\"");
  25202. }
  25203. }
  25204. else {
  25205. write(", ");
  25206. emit(children[i]);
  25207. }
  25208. }
  25209. }
  25210. write(")");
  25211. emitTrailingComments(openingNode);
  25212. }
  25213. if (node.kind === 233) {
  25214. emitJsxElement(node.openingElement, node.children);
  25215. }
  25216. else {
  25217. ts.Debug.assert(node.kind === 234);
  25218. emitJsxElement(node);
  25219. }
  25220. }
  25221. function jsxEmitPreserve(node) {
  25222. function emitJsxAttribute(node) {
  25223. emit(node.name);
  25224. if (node.initializer) {
  25225. write("=");
  25226. emit(node.initializer);
  25227. }
  25228. }
  25229. function emitJsxSpreadAttribute(node) {
  25230. write("{...");
  25231. emit(node.expression);
  25232. write("}");
  25233. }
  25234. function emitAttributes(attribs) {
  25235. for (var i = 0, n = attribs.length; i < n; i++) {
  25236. if (i > 0) {
  25237. write(" ");
  25238. }
  25239. if (attribs[i].kind === 239) {
  25240. emitJsxSpreadAttribute(attribs[i]);
  25241. }
  25242. else {
  25243. ts.Debug.assert(attribs[i].kind === 238);
  25244. emitJsxAttribute(attribs[i]);
  25245. }
  25246. }
  25247. }
  25248. function emitJsxOpeningOrSelfClosingElement(node) {
  25249. write("<");
  25250. emit(node.tagName);
  25251. if (node.attributes.length > 0 || (node.kind === 234)) {
  25252. write(" ");
  25253. }
  25254. emitAttributes(node.attributes);
  25255. if (node.kind === 234) {
  25256. write("/>");
  25257. }
  25258. else {
  25259. write(">");
  25260. }
  25261. }
  25262. function emitJsxClosingElement(node) {
  25263. write("</");
  25264. emit(node.tagName);
  25265. write(">");
  25266. }
  25267. function emitJsxElement(node) {
  25268. emitJsxOpeningOrSelfClosingElement(node.openingElement);
  25269. for (var i = 0, n = node.children.length; i < n; i++) {
  25270. emit(node.children[i]);
  25271. }
  25272. emitJsxClosingElement(node.closingElement);
  25273. }
  25274. if (node.kind === 233) {
  25275. emitJsxElement(node);
  25276. }
  25277. else {
  25278. ts.Debug.assert(node.kind === 234);
  25279. emitJsxOpeningOrSelfClosingElement(node);
  25280. }
  25281. }
  25282. function emitExpressionForPropertyName(node) {
  25283. ts.Debug.assert(node.kind !== 163);
  25284. if (node.kind === 9) {
  25285. emitLiteral(node);
  25286. }
  25287. else if (node.kind === 136) {
  25288. if (ts.nodeIsDecorated(node.parent)) {
  25289. if (!computedPropertyNamesToGeneratedNames) {
  25290. computedPropertyNamesToGeneratedNames = [];
  25291. }
  25292. var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)];
  25293. if (generatedName) {
  25294. write(generatedName);
  25295. return;
  25296. }
  25297. generatedName = createAndRecordTempVariable(0).text;
  25298. computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName;
  25299. write(generatedName);
  25300. write(" = ");
  25301. }
  25302. emit(node.expression);
  25303. }
  25304. else {
  25305. write("\"");
  25306. if (node.kind === 8) {
  25307. write(node.text);
  25308. }
  25309. else {
  25310. writeTextOfNode(currentSourceFile, node);
  25311. }
  25312. write("\"");
  25313. }
  25314. }
  25315. function isExpressionIdentifier(node) {
  25316. var parent = node.parent;
  25317. switch (parent.kind) {
  25318. case 164:
  25319. case 189:
  25320. case 181:
  25321. case 168:
  25322. case 241:
  25323. case 136:
  25324. case 182:
  25325. case 139:
  25326. case 175:
  25327. case 197:
  25328. case 167:
  25329. case 227:
  25330. case 195:
  25331. case 188:
  25332. case 199:
  25333. case 200:
  25334. case 201:
  25335. case 196:
  25336. case 234:
  25337. case 235:
  25338. case 239:
  25339. case 240:
  25340. case 169:
  25341. case 172:
  25342. case 180:
  25343. case 179:
  25344. case 204:
  25345. case 246:
  25346. case 185:
  25347. case 206:
  25348. case 170:
  25349. case 190:
  25350. case 208:
  25351. case 171:
  25352. case 176:
  25353. case 177:
  25354. case 198:
  25355. case 205:
  25356. case 184:
  25357. return true;
  25358. case 163:
  25359. case 247:
  25360. case 138:
  25361. case 245:
  25362. case 141:
  25363. case 211:
  25364. return parent.initializer === node;
  25365. case 166:
  25366. return parent.expression === node;
  25367. case 174:
  25368. case 173:
  25369. return parent.body === node;
  25370. case 221:
  25371. return parent.moduleReference === node;
  25372. case 135:
  25373. return parent.left === node;
  25374. }
  25375. return false;
  25376. }
  25377. function emitExpressionIdentifier(node) {
  25378. if (resolver.getNodeCheckFlags(node) & 2048) {
  25379. write("_arguments");
  25380. return;
  25381. }
  25382. var container = resolver.getReferencedExportContainer(node);
  25383. if (container) {
  25384. if (container.kind === 248) {
  25385. if (modulekind !== 5 && modulekind !== 4) {
  25386. write("exports.");
  25387. }
  25388. }
  25389. else {
  25390. write(getGeneratedNameForNode(container));
  25391. write(".");
  25392. }
  25393. }
  25394. else {
  25395. if (modulekind !== 5) {
  25396. var declaration = resolver.getReferencedImportDeclaration(node);
  25397. if (declaration) {
  25398. if (declaration.kind === 223) {
  25399. write(getGeneratedNameForNode(declaration.parent));
  25400. write(languageVersion === 0 ? "[\"default\"]" : ".default");
  25401. return;
  25402. }
  25403. else if (declaration.kind === 226) {
  25404. write(getGeneratedNameForNode(declaration.parent.parent.parent));
  25405. var name_23 = declaration.propertyName || declaration.name;
  25406. var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name_23);
  25407. if (languageVersion === 0 && identifier === "default") {
  25408. write("[\"default\"]");
  25409. }
  25410. else {
  25411. write(".");
  25412. write(identifier);
  25413. }
  25414. return;
  25415. }
  25416. }
  25417. }
  25418. if (languageVersion !== 2) {
  25419. var declaration = resolver.getReferencedNestedRedeclaration(node);
  25420. if (declaration) {
  25421. write(getGeneratedNameForNode(declaration.name));
  25422. return;
  25423. }
  25424. }
  25425. }
  25426. if (ts.nodeIsSynthesized(node)) {
  25427. write(node.text);
  25428. }
  25429. else {
  25430. writeTextOfNode(currentSourceFile, node);
  25431. }
  25432. }
  25433. function isNameOfNestedRedeclaration(node) {
  25434. if (languageVersion < 2) {
  25435. var parent_6 = node.parent;
  25436. switch (parent_6.kind) {
  25437. case 163:
  25438. case 214:
  25439. case 217:
  25440. case 211:
  25441. return parent_6.name === node && resolver.isNestedRedeclaration(parent_6);
  25442. }
  25443. }
  25444. return false;
  25445. }
  25446. function emitIdentifier(node) {
  25447. if (!node.parent) {
  25448. write(node.text);
  25449. }
  25450. else if (isExpressionIdentifier(node)) {
  25451. emitExpressionIdentifier(node);
  25452. }
  25453. else if (isNameOfNestedRedeclaration(node)) {
  25454. write(getGeneratedNameForNode(node));
  25455. }
  25456. else if (ts.nodeIsSynthesized(node)) {
  25457. write(node.text);
  25458. }
  25459. else {
  25460. writeTextOfNode(currentSourceFile, node);
  25461. }
  25462. }
  25463. function emitThis(node) {
  25464. if (resolver.getNodeCheckFlags(node) & 2) {
  25465. write("_this");
  25466. }
  25467. else {
  25468. write("this");
  25469. }
  25470. }
  25471. function emitSuper(node) {
  25472. if (languageVersion >= 2) {
  25473. write("super");
  25474. }
  25475. else {
  25476. var flags = resolver.getNodeCheckFlags(node);
  25477. if (flags & 256) {
  25478. write("_super.prototype");
  25479. }
  25480. else {
  25481. write("_super");
  25482. }
  25483. }
  25484. }
  25485. function emitObjectBindingPattern(node) {
  25486. write("{ ");
  25487. var elements = node.elements;
  25488. emitList(elements, 0, elements.length, false, elements.hasTrailingComma);
  25489. write(" }");
  25490. }
  25491. function emitArrayBindingPattern(node) {
  25492. write("[");
  25493. var elements = node.elements;
  25494. emitList(elements, 0, elements.length, false, elements.hasTrailingComma);
  25495. write("]");
  25496. }
  25497. function emitBindingElement(node) {
  25498. if (node.propertyName) {
  25499. emit(node.propertyName);
  25500. write(": ");
  25501. }
  25502. if (node.dotDotDotToken) {
  25503. write("...");
  25504. }
  25505. if (ts.isBindingPattern(node.name)) {
  25506. emit(node.name);
  25507. }
  25508. else {
  25509. emitModuleMemberName(node);
  25510. }
  25511. emitOptional(" = ", node.initializer);
  25512. }
  25513. function emitSpreadElementExpression(node) {
  25514. write("...");
  25515. emit(node.expression);
  25516. }
  25517. function emitYieldExpression(node) {
  25518. write(ts.tokenToString(114));
  25519. if (node.asteriskToken) {
  25520. write("*");
  25521. }
  25522. if (node.expression) {
  25523. write(" ");
  25524. emit(node.expression);
  25525. }
  25526. }
  25527. function emitAwaitExpression(node) {
  25528. var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node);
  25529. if (needsParenthesis) {
  25530. write("(");
  25531. }
  25532. write(ts.tokenToString(114));
  25533. write(" ");
  25534. emit(node.expression);
  25535. if (needsParenthesis) {
  25536. write(")");
  25537. }
  25538. }
  25539. function needsParenthesisForAwaitExpressionAsYield(node) {
  25540. if (node.parent.kind === 181 && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) {
  25541. return true;
  25542. }
  25543. else if (node.parent.kind === 182 && node.parent.condition === node) {
  25544. return true;
  25545. }
  25546. return false;
  25547. }
  25548. function needsParenthesisForPropertyAccessOrInvocation(node) {
  25549. switch (node.kind) {
  25550. case 69:
  25551. case 164:
  25552. case 166:
  25553. case 167:
  25554. case 168:
  25555. case 172:
  25556. return false;
  25557. }
  25558. return true;
  25559. }
  25560. function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) {
  25561. var pos = 0;
  25562. var group = 0;
  25563. var length = elements.length;
  25564. while (pos < length) {
  25565. if (group === 1 && useConcat) {
  25566. write(".concat(");
  25567. }
  25568. else if (group > 0) {
  25569. write(", ");
  25570. }
  25571. var e = elements[pos];
  25572. if (e.kind === 185) {
  25573. e = e.expression;
  25574. emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
  25575. pos++;
  25576. if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 164) {
  25577. write(".slice()");
  25578. }
  25579. }
  25580. else {
  25581. var i = pos;
  25582. while (i < length && elements[i].kind !== 185) {
  25583. i++;
  25584. }
  25585. write("[");
  25586. if (multiLine) {
  25587. increaseIndent();
  25588. }
  25589. emitList(elements, pos, i - pos, multiLine, trailingComma && i === length);
  25590. if (multiLine) {
  25591. decreaseIndent();
  25592. }
  25593. write("]");
  25594. pos = i;
  25595. }
  25596. group++;
  25597. }
  25598. if (group > 1) {
  25599. if (useConcat) {
  25600. write(")");
  25601. }
  25602. }
  25603. }
  25604. function isSpreadElementExpression(node) {
  25605. return node.kind === 185;
  25606. }
  25607. function emitArrayLiteral(node) {
  25608. var elements = node.elements;
  25609. if (elements.length === 0) {
  25610. write("[]");
  25611. }
  25612. else if (languageVersion >= 2 || !ts.forEach(elements, isSpreadElementExpression)) {
  25613. write("[");
  25614. emitLinePreservingList(node, node.elements, elements.hasTrailingComma, false);
  25615. write("]");
  25616. }
  25617. else {
  25618. emitListWithSpread(elements, true, (node.flags & 2048) !== 0, elements.hasTrailingComma, true);
  25619. }
  25620. }
  25621. function emitObjectLiteralBody(node, numElements) {
  25622. if (numElements === 0) {
  25623. write("{}");
  25624. return;
  25625. }
  25626. write("{");
  25627. if (numElements > 0) {
  25628. var properties = node.properties;
  25629. if (numElements === properties.length) {
  25630. emitLinePreservingList(node, properties, languageVersion >= 1, true);
  25631. }
  25632. else {
  25633. var multiLine = (node.flags & 2048) !== 0;
  25634. if (!multiLine) {
  25635. write(" ");
  25636. }
  25637. else {
  25638. increaseIndent();
  25639. }
  25640. emitList(properties, 0, numElements, multiLine, false);
  25641. if (!multiLine) {
  25642. write(" ");
  25643. }
  25644. else {
  25645. decreaseIndent();
  25646. }
  25647. }
  25648. }
  25649. write("}");
  25650. }
  25651. function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) {
  25652. var multiLine = (node.flags & 2048) !== 0;
  25653. var properties = node.properties;
  25654. write("(");
  25655. if (multiLine) {
  25656. increaseIndent();
  25657. }
  25658. var tempVar = createAndRecordTempVariable(0);
  25659. emit(tempVar);
  25660. write(" = ");
  25661. emitObjectLiteralBody(node, firstComputedPropertyIndex);
  25662. for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) {
  25663. writeComma();
  25664. var property = properties[i];
  25665. emitStart(property);
  25666. if (property.kind === 145 || property.kind === 146) {
  25667. var accessors = ts.getAllAccessorDeclarations(node.properties, property);
  25668. if (property !== accessors.firstAccessor) {
  25669. continue;
  25670. }
  25671. write("Object.defineProperty(");
  25672. emit(tempVar);
  25673. write(", ");
  25674. emitStart(node.name);
  25675. emitExpressionForPropertyName(property.name);
  25676. emitEnd(property.name);
  25677. write(", {");
  25678. increaseIndent();
  25679. if (accessors.getAccessor) {
  25680. writeLine();
  25681. emitLeadingComments(accessors.getAccessor);
  25682. write("get: ");
  25683. emitStart(accessors.getAccessor);
  25684. write("function ");
  25685. emitSignatureAndBody(accessors.getAccessor);
  25686. emitEnd(accessors.getAccessor);
  25687. emitTrailingComments(accessors.getAccessor);
  25688. write(",");
  25689. }
  25690. if (accessors.setAccessor) {
  25691. writeLine();
  25692. emitLeadingComments(accessors.setAccessor);
  25693. write("set: ");
  25694. emitStart(accessors.setAccessor);
  25695. write("function ");
  25696. emitSignatureAndBody(accessors.setAccessor);
  25697. emitEnd(accessors.setAccessor);
  25698. emitTrailingComments(accessors.setAccessor);
  25699. write(",");
  25700. }
  25701. writeLine();
  25702. write("enumerable: true,");
  25703. writeLine();
  25704. write("configurable: true");
  25705. decreaseIndent();
  25706. writeLine();
  25707. write("})");
  25708. emitEnd(property);
  25709. }
  25710. else {
  25711. emitLeadingComments(property);
  25712. emitStart(property.name);
  25713. emit(tempVar);
  25714. emitMemberAccessForPropertyName(property.name);
  25715. emitEnd(property.name);
  25716. write(" = ");
  25717. if (property.kind === 245) {
  25718. emit(property.initializer);
  25719. }
  25720. else if (property.kind === 246) {
  25721. emitExpressionIdentifier(property.name);
  25722. }
  25723. else if (property.kind === 143) {
  25724. emitFunctionDeclaration(property);
  25725. }
  25726. else {
  25727. ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind);
  25728. }
  25729. }
  25730. emitEnd(property);
  25731. }
  25732. writeComma();
  25733. emit(tempVar);
  25734. if (multiLine) {
  25735. decreaseIndent();
  25736. writeLine();
  25737. }
  25738. write(")");
  25739. function writeComma() {
  25740. if (multiLine) {
  25741. write(",");
  25742. writeLine();
  25743. }
  25744. else {
  25745. write(", ");
  25746. }
  25747. }
  25748. }
  25749. function emitObjectLiteral(node) {
  25750. var properties = node.properties;
  25751. if (languageVersion < 2) {
  25752. var numProperties = properties.length;
  25753. var numInitialNonComputedProperties = numProperties;
  25754. for (var i = 0, n = properties.length; i < n; i++) {
  25755. if (properties[i].name.kind === 136) {
  25756. numInitialNonComputedProperties = i;
  25757. break;
  25758. }
  25759. }
  25760. var hasComputedProperty = numInitialNonComputedProperties !== properties.length;
  25761. if (hasComputedProperty) {
  25762. emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties);
  25763. return;
  25764. }
  25765. }
  25766. emitObjectLiteralBody(node, properties.length);
  25767. }
  25768. function createBinaryExpression(left, operator, right, startsOnNewLine) {
  25769. var result = ts.createSynthesizedNode(181, startsOnNewLine);
  25770. result.operatorToken = ts.createSynthesizedNode(operator);
  25771. result.left = left;
  25772. result.right = right;
  25773. return result;
  25774. }
  25775. function createPropertyAccessExpression(expression, name) {
  25776. var result = ts.createSynthesizedNode(166);
  25777. result.expression = parenthesizeForAccess(expression);
  25778. result.dotToken = ts.createSynthesizedNode(21);
  25779. result.name = name;
  25780. return result;
  25781. }
  25782. function createElementAccessExpression(expression, argumentExpression) {
  25783. var result = ts.createSynthesizedNode(167);
  25784. result.expression = parenthesizeForAccess(expression);
  25785. result.argumentExpression = argumentExpression;
  25786. return result;
  25787. }
  25788. function parenthesizeForAccess(expr) {
  25789. while (expr.kind === 171 || expr.kind === 189) {
  25790. expr = expr.expression;
  25791. }
  25792. if (ts.isLeftHandSideExpression(expr) &&
  25793. expr.kind !== 169 &&
  25794. expr.kind !== 8) {
  25795. return expr;
  25796. }
  25797. var node = ts.createSynthesizedNode(172);
  25798. node.expression = expr;
  25799. return node;
  25800. }
  25801. function emitComputedPropertyName(node) {
  25802. write("[");
  25803. emitExpressionForPropertyName(node);
  25804. write("]");
  25805. }
  25806. function emitMethod(node) {
  25807. if (languageVersion >= 2 && node.asteriskToken) {
  25808. write("*");
  25809. }
  25810. emit(node.name);
  25811. if (languageVersion < 2) {
  25812. write(": function ");
  25813. }
  25814. emitSignatureAndBody(node);
  25815. }
  25816. function emitPropertyAssignment(node) {
  25817. emit(node.name);
  25818. write(": ");
  25819. emitTrailingCommentsOfPosition(node.initializer.pos);
  25820. emit(node.initializer);
  25821. }
  25822. function isNamespaceExportReference(node) {
  25823. var container = resolver.getReferencedExportContainer(node);
  25824. return container && container.kind !== 248;
  25825. }
  25826. function emitShorthandPropertyAssignment(node) {
  25827. writeTextOfNode(currentSourceFile, node.name);
  25828. if (languageVersion < 2 || isNamespaceExportReference(node.name)) {
  25829. write(": ");
  25830. emit(node.name);
  25831. }
  25832. if (languageVersion >= 2 && node.objectAssignmentInitializer) {
  25833. write(" = ");
  25834. emit(node.objectAssignmentInitializer);
  25835. }
  25836. }
  25837. function tryEmitConstantValue(node) {
  25838. var constantValue = tryGetConstEnumValue(node);
  25839. if (constantValue !== undefined) {
  25840. write(constantValue.toString());
  25841. if (!compilerOptions.removeComments) {
  25842. var propertyName = node.kind === 166 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression);
  25843. write(" /* " + propertyName + " */");
  25844. }
  25845. return true;
  25846. }
  25847. return false;
  25848. }
  25849. function tryGetConstEnumValue(node) {
  25850. if (compilerOptions.isolatedModules) {
  25851. return undefined;
  25852. }
  25853. return node.kind === 166 || node.kind === 167
  25854. ? resolver.getConstantValue(node)
  25855. : undefined;
  25856. }
  25857. function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) {
  25858. var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2);
  25859. var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2);
  25860. if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) {
  25861. increaseIndent();
  25862. writeLine();
  25863. return true;
  25864. }
  25865. else {
  25866. if (valueToWriteWhenNotIndenting) {
  25867. write(valueToWriteWhenNotIndenting);
  25868. }
  25869. return false;
  25870. }
  25871. }
  25872. function emitPropertyAccess(node) {
  25873. if (tryEmitConstantValue(node)) {
  25874. return;
  25875. }
  25876. emit(node.expression);
  25877. var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
  25878. var shouldEmitSpace;
  25879. if (!indentedBeforeDot) {
  25880. if (node.expression.kind === 8) {
  25881. var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression);
  25882. shouldEmitSpace = text.indexOf(ts.tokenToString(21)) < 0;
  25883. }
  25884. else {
  25885. var constantValue = tryGetConstEnumValue(node.expression);
  25886. shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue;
  25887. }
  25888. }
  25889. if (shouldEmitSpace) {
  25890. write(" .");
  25891. }
  25892. else {
  25893. write(".");
  25894. }
  25895. var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
  25896. emit(node.name);
  25897. decreaseIndentIf(indentedBeforeDot, indentedAfterDot);
  25898. }
  25899. function emitQualifiedName(node) {
  25900. emit(node.left);
  25901. write(".");
  25902. emit(node.right);
  25903. }
  25904. function emitQualifiedNameAsExpression(node, useFallback) {
  25905. if (node.left.kind === 69) {
  25906. emitEntityNameAsExpression(node.left, useFallback);
  25907. }
  25908. else if (useFallback) {
  25909. var temp = createAndRecordTempVariable(0);
  25910. write("(");
  25911. emitNodeWithoutSourceMap(temp);
  25912. write(" = ");
  25913. emitEntityNameAsExpression(node.left, true);
  25914. write(") && ");
  25915. emitNodeWithoutSourceMap(temp);
  25916. }
  25917. else {
  25918. emitEntityNameAsExpression(node.left, false);
  25919. }
  25920. write(".");
  25921. emit(node.right);
  25922. }
  25923. function emitEntityNameAsExpression(node, useFallback) {
  25924. switch (node.kind) {
  25925. case 69:
  25926. if (useFallback) {
  25927. write("typeof ");
  25928. emitExpressionIdentifier(node);
  25929. write(" !== 'undefined' && ");
  25930. }
  25931. emitExpressionIdentifier(node);
  25932. break;
  25933. case 135:
  25934. emitQualifiedNameAsExpression(node, useFallback);
  25935. break;
  25936. }
  25937. }
  25938. function emitIndexedAccess(node) {
  25939. if (tryEmitConstantValue(node)) {
  25940. return;
  25941. }
  25942. emit(node.expression);
  25943. write("[");
  25944. emit(node.argumentExpression);
  25945. write("]");
  25946. }
  25947. function hasSpreadElement(elements) {
  25948. return ts.forEach(elements, function (e) { return e.kind === 185; });
  25949. }
  25950. function skipParentheses(node) {
  25951. while (node.kind === 172 || node.kind === 171 || node.kind === 189) {
  25952. node = node.expression;
  25953. }
  25954. return node;
  25955. }
  25956. function emitCallTarget(node) {
  25957. if (node.kind === 69 || node.kind === 97 || node.kind === 95) {
  25958. emit(node);
  25959. return node;
  25960. }
  25961. var temp = createAndRecordTempVariable(0);
  25962. write("(");
  25963. emit(temp);
  25964. write(" = ");
  25965. emit(node);
  25966. write(")");
  25967. return temp;
  25968. }
  25969. function emitCallWithSpread(node) {
  25970. var target;
  25971. var expr = skipParentheses(node.expression);
  25972. if (expr.kind === 166) {
  25973. target = emitCallTarget(expr.expression);
  25974. write(".");
  25975. emit(expr.name);
  25976. }
  25977. else if (expr.kind === 167) {
  25978. target = emitCallTarget(expr.expression);
  25979. write("[");
  25980. emit(expr.argumentExpression);
  25981. write("]");
  25982. }
  25983. else if (expr.kind === 95) {
  25984. target = expr;
  25985. write("_super");
  25986. }
  25987. else {
  25988. emit(node.expression);
  25989. }
  25990. write(".apply(");
  25991. if (target) {
  25992. if (target.kind === 95) {
  25993. emitThis(target);
  25994. }
  25995. else {
  25996. emit(target);
  25997. }
  25998. }
  25999. else {
  26000. write("void 0");
  26001. }
  26002. write(", ");
  26003. emitListWithSpread(node.arguments, false, false, false, true);
  26004. write(")");
  26005. }
  26006. function emitCallExpression(node) {
  26007. if (languageVersion < 2 && hasSpreadElement(node.arguments)) {
  26008. emitCallWithSpread(node);
  26009. return;
  26010. }
  26011. var superCall = false;
  26012. if (node.expression.kind === 95) {
  26013. emitSuper(node.expression);
  26014. superCall = true;
  26015. }
  26016. else {
  26017. emit(node.expression);
  26018. superCall = node.expression.kind === 166 && node.expression.expression.kind === 95;
  26019. }
  26020. if (superCall && languageVersion < 2) {
  26021. write(".call(");
  26022. emitThis(node.expression);
  26023. if (node.arguments.length) {
  26024. write(", ");
  26025. emitCommaList(node.arguments);
  26026. }
  26027. write(")");
  26028. }
  26029. else {
  26030. write("(");
  26031. emitCommaList(node.arguments);
  26032. write(")");
  26033. }
  26034. }
  26035. function emitNewExpression(node) {
  26036. write("new ");
  26037. if (languageVersion === 1 &&
  26038. node.arguments &&
  26039. hasSpreadElement(node.arguments)) {
  26040. write("(");
  26041. var target = emitCallTarget(node.expression);
  26042. write(".bind.apply(");
  26043. emit(target);
  26044. write(", [void 0].concat(");
  26045. emitListWithSpread(node.arguments, false, false, false, false);
  26046. write(")))");
  26047. write("()");
  26048. }
  26049. else {
  26050. emit(node.expression);
  26051. if (node.arguments) {
  26052. write("(");
  26053. emitCommaList(node.arguments);
  26054. write(")");
  26055. }
  26056. }
  26057. }
  26058. function emitTaggedTemplateExpression(node) {
  26059. if (languageVersion >= 2) {
  26060. emit(node.tag);
  26061. write(" ");
  26062. emit(node.template);
  26063. }
  26064. else {
  26065. emitDownlevelTaggedTemplate(node);
  26066. }
  26067. }
  26068. function emitParenExpression(node) {
  26069. if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 174) {
  26070. if (node.expression.kind === 171 || node.expression.kind === 189) {
  26071. var operand = node.expression.expression;
  26072. while (operand.kind === 171 || operand.kind === 189) {
  26073. operand = operand.expression;
  26074. }
  26075. if (operand.kind !== 179 &&
  26076. operand.kind !== 177 &&
  26077. operand.kind !== 176 &&
  26078. operand.kind !== 175 &&
  26079. operand.kind !== 180 &&
  26080. operand.kind !== 169 &&
  26081. !(operand.kind === 168 && node.parent.kind === 169) &&
  26082. !(operand.kind === 173 && node.parent.kind === 168) &&
  26083. !(operand.kind === 8 && node.parent.kind === 166)) {
  26084. emit(operand);
  26085. return;
  26086. }
  26087. }
  26088. }
  26089. write("(");
  26090. emit(node.expression);
  26091. write(")");
  26092. }
  26093. function emitDeleteExpression(node) {
  26094. write(ts.tokenToString(78));
  26095. write(" ");
  26096. emit(node.expression);
  26097. }
  26098. function emitVoidExpression(node) {
  26099. write(ts.tokenToString(103));
  26100. write(" ");
  26101. emit(node.expression);
  26102. }
  26103. function emitTypeOfExpression(node) {
  26104. write(ts.tokenToString(101));
  26105. write(" ");
  26106. emit(node.expression);
  26107. }
  26108. function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) {
  26109. if (!isCurrentFileSystemExternalModule() || node.kind !== 69 || ts.nodeIsSynthesized(node)) {
  26110. return false;
  26111. }
  26112. var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 211 || node.parent.kind === 163);
  26113. var targetDeclaration = isVariableDeclarationOrBindingElement
  26114. ? node.parent
  26115. : resolver.getReferencedValueDeclaration(node);
  26116. return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, true);
  26117. }
  26118. function emitPrefixUnaryExpression(node) {
  26119. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
  26120. if (exportChanged) {
  26121. write(exportFunctionForFile + "(\"");
  26122. emitNodeWithoutSourceMap(node.operand);
  26123. write("\", ");
  26124. }
  26125. write(ts.tokenToString(node.operator));
  26126. if (node.operand.kind === 179) {
  26127. var operand = node.operand;
  26128. if (node.operator === 35 && (operand.operator === 35 || operand.operator === 41)) {
  26129. write(" ");
  26130. }
  26131. else if (node.operator === 36 && (operand.operator === 36 || operand.operator === 42)) {
  26132. write(" ");
  26133. }
  26134. }
  26135. emit(node.operand);
  26136. if (exportChanged) {
  26137. write(")");
  26138. }
  26139. }
  26140. function emitPostfixUnaryExpression(node) {
  26141. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
  26142. if (exportChanged) {
  26143. write("(" + exportFunctionForFile + "(\"");
  26144. emitNodeWithoutSourceMap(node.operand);
  26145. write("\", ");
  26146. write(ts.tokenToString(node.operator));
  26147. emit(node.operand);
  26148. if (node.operator === 41) {
  26149. write(") - 1)");
  26150. }
  26151. else {
  26152. write(") + 1)");
  26153. }
  26154. }
  26155. else {
  26156. emit(node.operand);
  26157. write(ts.tokenToString(node.operator));
  26158. }
  26159. }
  26160. function shouldHoistDeclarationInSystemJsModule(node) {
  26161. return isSourceFileLevelDeclarationInSystemJsModule(node, false);
  26162. }
  26163. function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) {
  26164. if (!node || languageVersion >= 2 || !isCurrentFileSystemExternalModule()) {
  26165. return false;
  26166. }
  26167. var current = node;
  26168. while (current) {
  26169. if (current.kind === 248) {
  26170. return !isExported || ((ts.getCombinedNodeFlags(node) & 1) !== 0);
  26171. }
  26172. else if (ts.isFunctionLike(current) || current.kind === 219) {
  26173. return false;
  26174. }
  26175. else {
  26176. current = current.parent;
  26177. }
  26178. }
  26179. }
  26180. function emitExponentiationOperator(node) {
  26181. var leftHandSideExpression = node.left;
  26182. if (node.operatorToken.kind === 60) {
  26183. var synthesizedLHS;
  26184. var shouldEmitParentheses = false;
  26185. if (ts.isElementAccessExpression(leftHandSideExpression)) {
  26186. shouldEmitParentheses = true;
  26187. write("(");
  26188. synthesizedLHS = ts.createSynthesizedNode(167, false);
  26189. var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, false, false);
  26190. synthesizedLHS.expression = identifier;
  26191. if (leftHandSideExpression.argumentExpression.kind !== 8 &&
  26192. leftHandSideExpression.argumentExpression.kind !== 9) {
  26193. var tempArgumentExpression = createAndRecordTempVariable(268435456);
  26194. synthesizedLHS.argumentExpression = tempArgumentExpression;
  26195. emitAssignment(tempArgumentExpression, leftHandSideExpression.argumentExpression, true);
  26196. }
  26197. else {
  26198. synthesizedLHS.argumentExpression = leftHandSideExpression.argumentExpression;
  26199. }
  26200. write(", ");
  26201. }
  26202. else if (ts.isPropertyAccessExpression(leftHandSideExpression)) {
  26203. shouldEmitParentheses = true;
  26204. write("(");
  26205. synthesizedLHS = ts.createSynthesizedNode(166, false);
  26206. var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, false, false);
  26207. synthesizedLHS.expression = identifier;
  26208. synthesizedLHS.dotToken = leftHandSideExpression.dotToken;
  26209. synthesizedLHS.name = leftHandSideExpression.name;
  26210. write(", ");
  26211. }
  26212. emit(synthesizedLHS || leftHandSideExpression);
  26213. write(" = ");
  26214. write("Math.pow(");
  26215. emit(synthesizedLHS || leftHandSideExpression);
  26216. write(", ");
  26217. emit(node.right);
  26218. write(")");
  26219. if (shouldEmitParentheses) {
  26220. write(")");
  26221. }
  26222. }
  26223. else {
  26224. write("Math.pow(");
  26225. emit(leftHandSideExpression);
  26226. write(", ");
  26227. emit(node.right);
  26228. write(")");
  26229. }
  26230. }
  26231. function emitBinaryExpression(node) {
  26232. if (languageVersion < 2 && node.operatorToken.kind === 56 &&
  26233. (node.left.kind === 165 || node.left.kind === 164)) {
  26234. emitDestructuring(node, node.parent.kind === 195);
  26235. }
  26236. else {
  26237. var exportChanged = node.operatorToken.kind >= 56 &&
  26238. node.operatorToken.kind <= 68 &&
  26239. isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left);
  26240. if (exportChanged) {
  26241. write(exportFunctionForFile + "(\"");
  26242. emitNodeWithoutSourceMap(node.left);
  26243. write("\", ");
  26244. }
  26245. if (node.operatorToken.kind === 38 || node.operatorToken.kind === 60) {
  26246. emitExponentiationOperator(node);
  26247. }
  26248. else {
  26249. emit(node.left);
  26250. var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 ? " " : undefined);
  26251. write(ts.tokenToString(node.operatorToken.kind));
  26252. var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " ");
  26253. emit(node.right);
  26254. decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator);
  26255. }
  26256. if (exportChanged) {
  26257. write(")");
  26258. }
  26259. }
  26260. }
  26261. function synthesizedNodeStartsOnNewLine(node) {
  26262. return ts.nodeIsSynthesized(node) && node.startsOnNewLine;
  26263. }
  26264. function emitConditionalExpression(node) {
  26265. emit(node.condition);
  26266. var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " ");
  26267. write("?");
  26268. var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " ");
  26269. emit(node.whenTrue);
  26270. decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion);
  26271. var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " ");
  26272. write(":");
  26273. var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " ");
  26274. emit(node.whenFalse);
  26275. decreaseIndentIf(indentedBeforeColon, indentedAfterColon);
  26276. }
  26277. function decreaseIndentIf(value1, value2) {
  26278. if (value1) {
  26279. decreaseIndent();
  26280. }
  26281. if (value2) {
  26282. decreaseIndent();
  26283. }
  26284. }
  26285. function isSingleLineEmptyBlock(node) {
  26286. if (node && node.kind === 192) {
  26287. var block = node;
  26288. return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block);
  26289. }
  26290. }
  26291. function emitBlock(node) {
  26292. if (isSingleLineEmptyBlock(node)) {
  26293. emitToken(15, node.pos);
  26294. write(" ");
  26295. emitToken(16, node.statements.end);
  26296. return;
  26297. }
  26298. emitToken(15, node.pos);
  26299. increaseIndent();
  26300. scopeEmitStart(node.parent);
  26301. if (node.kind === 219) {
  26302. ts.Debug.assert(node.parent.kind === 218);
  26303. emitCaptureThisForNodeIfNecessary(node.parent);
  26304. }
  26305. emitLines(node.statements);
  26306. if (node.kind === 219) {
  26307. emitTempDeclarations(true);
  26308. }
  26309. decreaseIndent();
  26310. writeLine();
  26311. emitToken(16, node.statements.end);
  26312. scopeEmitEnd();
  26313. }
  26314. function emitEmbeddedStatement(node) {
  26315. if (node.kind === 192) {
  26316. write(" ");
  26317. emit(node);
  26318. }
  26319. else {
  26320. increaseIndent();
  26321. writeLine();
  26322. emit(node);
  26323. decreaseIndent();
  26324. }
  26325. }
  26326. function emitExpressionStatement(node) {
  26327. emitParenthesizedIf(node.expression, node.expression.kind === 174);
  26328. write(";");
  26329. }
  26330. function emitIfStatement(node) {
  26331. var endPos = emitToken(88, node.pos);
  26332. write(" ");
  26333. endPos = emitToken(17, endPos);
  26334. emit(node.expression);
  26335. emitToken(18, node.expression.end);
  26336. emitEmbeddedStatement(node.thenStatement);
  26337. if (node.elseStatement) {
  26338. writeLine();
  26339. emitToken(80, node.thenStatement.end);
  26340. if (node.elseStatement.kind === 196) {
  26341. write(" ");
  26342. emit(node.elseStatement);
  26343. }
  26344. else {
  26345. emitEmbeddedStatement(node.elseStatement);
  26346. }
  26347. }
  26348. }
  26349. function emitDoStatement(node) {
  26350. write("do");
  26351. emitEmbeddedStatement(node.statement);
  26352. if (node.statement.kind === 192) {
  26353. write(" ");
  26354. }
  26355. else {
  26356. writeLine();
  26357. }
  26358. write("while (");
  26359. emit(node.expression);
  26360. write(");");
  26361. }
  26362. function emitWhileStatement(node) {
  26363. write("while (");
  26364. emit(node.expression);
  26365. write(")");
  26366. emitEmbeddedStatement(node.statement);
  26367. }
  26368. function tryEmitStartOfVariableDeclarationList(decl, startPos) {
  26369. if (shouldHoistVariable(decl, true)) {
  26370. return false;
  26371. }
  26372. var tokenKind = 102;
  26373. if (decl && languageVersion >= 2) {
  26374. if (ts.isLet(decl)) {
  26375. tokenKind = 108;
  26376. }
  26377. else if (ts.isConst(decl)) {
  26378. tokenKind = 74;
  26379. }
  26380. }
  26381. if (startPos !== undefined) {
  26382. emitToken(tokenKind, startPos);
  26383. write(" ");
  26384. }
  26385. else {
  26386. switch (tokenKind) {
  26387. case 102:
  26388. write("var ");
  26389. break;
  26390. case 108:
  26391. write("let ");
  26392. break;
  26393. case 74:
  26394. write("const ");
  26395. break;
  26396. }
  26397. }
  26398. return true;
  26399. }
  26400. function emitVariableDeclarationListSkippingUninitializedEntries(list) {
  26401. var started = false;
  26402. for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) {
  26403. var decl = _b[_a];
  26404. if (!decl.initializer) {
  26405. continue;
  26406. }
  26407. if (!started) {
  26408. started = true;
  26409. }
  26410. else {
  26411. write(", ");
  26412. }
  26413. emit(decl);
  26414. }
  26415. return started;
  26416. }
  26417. function emitForStatement(node) {
  26418. var endPos = emitToken(86, node.pos);
  26419. write(" ");
  26420. endPos = emitToken(17, endPos);
  26421. if (node.initializer && node.initializer.kind === 212) {
  26422. var variableDeclarationList = node.initializer;
  26423. var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
  26424. if (startIsEmitted) {
  26425. emitCommaList(variableDeclarationList.declarations);
  26426. }
  26427. else {
  26428. emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList);
  26429. }
  26430. }
  26431. else if (node.initializer) {
  26432. emit(node.initializer);
  26433. }
  26434. write(";");
  26435. emitOptional(" ", node.condition);
  26436. write(";");
  26437. emitOptional(" ", node.incrementor);
  26438. write(")");
  26439. emitEmbeddedStatement(node.statement);
  26440. }
  26441. function emitForInOrForOfStatement(node) {
  26442. if (languageVersion < 2 && node.kind === 201) {
  26443. return emitDownLevelForOfStatement(node);
  26444. }
  26445. var endPos = emitToken(86, node.pos);
  26446. write(" ");
  26447. endPos = emitToken(17, endPos);
  26448. if (node.initializer.kind === 212) {
  26449. var variableDeclarationList = node.initializer;
  26450. if (variableDeclarationList.declarations.length >= 1) {
  26451. tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
  26452. emit(variableDeclarationList.declarations[0]);
  26453. }
  26454. }
  26455. else {
  26456. emit(node.initializer);
  26457. }
  26458. if (node.kind === 200) {
  26459. write(" in ");
  26460. }
  26461. else {
  26462. write(" of ");
  26463. }
  26464. emit(node.expression);
  26465. emitToken(18, node.expression.end);
  26466. emitEmbeddedStatement(node.statement);
  26467. }
  26468. function emitDownLevelForOfStatement(node) {
  26469. var endPos = emitToken(86, node.pos);
  26470. write(" ");
  26471. endPos = emitToken(17, endPos);
  26472. var rhsIsIdentifier = node.expression.kind === 69;
  26473. var counter = createTempVariable(268435456);
  26474. var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0);
  26475. emitStart(node.expression);
  26476. write("var ");
  26477. emitNodeWithoutSourceMap(counter);
  26478. write(" = 0");
  26479. emitEnd(node.expression);
  26480. if (!rhsIsIdentifier) {
  26481. write(", ");
  26482. emitStart(node.expression);
  26483. emitNodeWithoutSourceMap(rhsReference);
  26484. write(" = ");
  26485. emitNodeWithoutSourceMap(node.expression);
  26486. emitEnd(node.expression);
  26487. }
  26488. write("; ");
  26489. emitStart(node.initializer);
  26490. emitNodeWithoutSourceMap(counter);
  26491. write(" < ");
  26492. emitNodeWithCommentsAndWithoutSourcemap(rhsReference);
  26493. write(".length");
  26494. emitEnd(node.initializer);
  26495. write("; ");
  26496. emitStart(node.initializer);
  26497. emitNodeWithoutSourceMap(counter);
  26498. write("++");
  26499. emitEnd(node.initializer);
  26500. emitToken(18, node.expression.end);
  26501. write(" {");
  26502. writeLine();
  26503. increaseIndent();
  26504. var rhsIterationValue = createElementAccessExpression(rhsReference, counter);
  26505. emitStart(node.initializer);
  26506. if (node.initializer.kind === 212) {
  26507. write("var ");
  26508. var variableDeclarationList = node.initializer;
  26509. if (variableDeclarationList.declarations.length > 0) {
  26510. var declaration = variableDeclarationList.declarations[0];
  26511. if (ts.isBindingPattern(declaration.name)) {
  26512. emitDestructuring(declaration, false, rhsIterationValue);
  26513. }
  26514. else {
  26515. emitNodeWithCommentsAndWithoutSourcemap(declaration);
  26516. write(" = ");
  26517. emitNodeWithoutSourceMap(rhsIterationValue);
  26518. }
  26519. }
  26520. else {
  26521. emitNodeWithoutSourceMap(createTempVariable(0));
  26522. write(" = ");
  26523. emitNodeWithoutSourceMap(rhsIterationValue);
  26524. }
  26525. }
  26526. else {
  26527. var assignmentExpression = createBinaryExpression(node.initializer, 56, rhsIterationValue, false);
  26528. if (node.initializer.kind === 164 || node.initializer.kind === 165) {
  26529. emitDestructuring(assignmentExpression, true, undefined);
  26530. }
  26531. else {
  26532. emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression);
  26533. }
  26534. }
  26535. emitEnd(node.initializer);
  26536. write(";");
  26537. if (node.statement.kind === 192) {
  26538. emitLines(node.statement.statements);
  26539. }
  26540. else {
  26541. writeLine();
  26542. emit(node.statement);
  26543. }
  26544. writeLine();
  26545. decreaseIndent();
  26546. write("}");
  26547. }
  26548. function emitBreakOrContinueStatement(node) {
  26549. emitToken(node.kind === 203 ? 70 : 75, node.pos);
  26550. emitOptional(" ", node.label);
  26551. write(";");
  26552. }
  26553. function emitReturnStatement(node) {
  26554. emitToken(94, node.pos);
  26555. emitOptional(" ", node.expression);
  26556. write(";");
  26557. }
  26558. function emitWithStatement(node) {
  26559. write("with (");
  26560. emit(node.expression);
  26561. write(")");
  26562. emitEmbeddedStatement(node.statement);
  26563. }
  26564. function emitSwitchStatement(node) {
  26565. var endPos = emitToken(96, node.pos);
  26566. write(" ");
  26567. emitToken(17, endPos);
  26568. emit(node.expression);
  26569. endPos = emitToken(18, node.expression.end);
  26570. write(" ");
  26571. emitCaseBlock(node.caseBlock, endPos);
  26572. }
  26573. function emitCaseBlock(node, startPos) {
  26574. emitToken(15, startPos);
  26575. increaseIndent();
  26576. emitLines(node.clauses);
  26577. decreaseIndent();
  26578. writeLine();
  26579. emitToken(16, node.clauses.end);
  26580. }
  26581. function nodeStartPositionsAreOnSameLine(node1, node2) {
  26582. return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) ===
  26583. ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
  26584. }
  26585. function nodeEndPositionsAreOnSameLine(node1, node2) {
  26586. return ts.getLineOfLocalPosition(currentSourceFile, node1.end) ===
  26587. ts.getLineOfLocalPosition(currentSourceFile, node2.end);
  26588. }
  26589. function nodeEndIsOnSameLineAsNodeStart(node1, node2) {
  26590. return ts.getLineOfLocalPosition(currentSourceFile, node1.end) ===
  26591. ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
  26592. }
  26593. function emitCaseOrDefaultClause(node) {
  26594. if (node.kind === 241) {
  26595. write("case ");
  26596. emit(node.expression);
  26597. write(":");
  26598. }
  26599. else {
  26600. write("default:");
  26601. }
  26602. if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) {
  26603. write(" ");
  26604. emit(node.statements[0]);
  26605. }
  26606. else {
  26607. increaseIndent();
  26608. emitLines(node.statements);
  26609. decreaseIndent();
  26610. }
  26611. }
  26612. function emitThrowStatement(node) {
  26613. write("throw ");
  26614. emit(node.expression);
  26615. write(";");
  26616. }
  26617. function emitTryStatement(node) {
  26618. write("try ");
  26619. emit(node.tryBlock);
  26620. emit(node.catchClause);
  26621. if (node.finallyBlock) {
  26622. writeLine();
  26623. write("finally ");
  26624. emit(node.finallyBlock);
  26625. }
  26626. }
  26627. function emitCatchClause(node) {
  26628. writeLine();
  26629. var endPos = emitToken(72, node.pos);
  26630. write(" ");
  26631. emitToken(17, endPos);
  26632. emit(node.variableDeclaration);
  26633. emitToken(18, node.variableDeclaration ? node.variableDeclaration.end : endPos);
  26634. write(" ");
  26635. emitBlock(node.block);
  26636. }
  26637. function emitDebuggerStatement(node) {
  26638. emitToken(76, node.pos);
  26639. write(";");
  26640. }
  26641. function emitLabelledStatement(node) {
  26642. emit(node.label);
  26643. write(": ");
  26644. emit(node.statement);
  26645. }
  26646. function getContainingModule(node) {
  26647. do {
  26648. node = node.parent;
  26649. } while (node && node.kind !== 218);
  26650. return node;
  26651. }
  26652. function emitContainingModuleName(node) {
  26653. var container = getContainingModule(node);
  26654. write(container ? getGeneratedNameForNode(container) : "exports");
  26655. }
  26656. function emitModuleMemberName(node) {
  26657. emitStart(node.name);
  26658. if (ts.getCombinedNodeFlags(node) & 1) {
  26659. var container = getContainingModule(node);
  26660. if (container) {
  26661. write(getGeneratedNameForNode(container));
  26662. write(".");
  26663. }
  26664. else if (modulekind !== 5 && modulekind !== 4) {
  26665. write("exports.");
  26666. }
  26667. }
  26668. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  26669. emitEnd(node.name);
  26670. }
  26671. function createVoidZero() {
  26672. var zero = ts.createSynthesizedNode(8);
  26673. zero.text = "0";
  26674. var result = ts.createSynthesizedNode(177);
  26675. result.expression = zero;
  26676. return result;
  26677. }
  26678. function emitEs6ExportDefaultCompat(node) {
  26679. if (node.parent.kind === 248) {
  26680. ts.Debug.assert(!!(node.flags & 1024) || node.kind === 227);
  26681. if (modulekind === 1 || modulekind === 2 || modulekind === 3) {
  26682. if (!currentSourceFile.symbol.exports["___esModule"]) {
  26683. if (languageVersion === 1) {
  26684. write("Object.defineProperty(exports, \"__esModule\", { value: true });");
  26685. writeLine();
  26686. }
  26687. else if (languageVersion === 0) {
  26688. write("exports.__esModule = true;");
  26689. writeLine();
  26690. }
  26691. }
  26692. }
  26693. }
  26694. }
  26695. function emitExportMemberAssignment(node) {
  26696. if (node.flags & 1) {
  26697. writeLine();
  26698. emitStart(node);
  26699. if (modulekind === 4 && node.parent === currentSourceFile) {
  26700. write(exportFunctionForFile + "(\"");
  26701. if (node.flags & 1024) {
  26702. write("default");
  26703. }
  26704. else {
  26705. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  26706. }
  26707. write("\", ");
  26708. emitDeclarationName(node);
  26709. write(")");
  26710. }
  26711. else {
  26712. if (node.flags & 1024) {
  26713. emitEs6ExportDefaultCompat(node);
  26714. if (languageVersion === 0) {
  26715. write("exports[\"default\"]");
  26716. }
  26717. else {
  26718. write("exports.default");
  26719. }
  26720. }
  26721. else {
  26722. emitModuleMemberName(node);
  26723. }
  26724. write(" = ");
  26725. emitDeclarationName(node);
  26726. }
  26727. emitEnd(node);
  26728. write(";");
  26729. }
  26730. }
  26731. function emitExportMemberAssignments(name) {
  26732. if (modulekind === 4) {
  26733. return;
  26734. }
  26735. if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) {
  26736. for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) {
  26737. var specifier = _b[_a];
  26738. writeLine();
  26739. emitStart(specifier.name);
  26740. emitContainingModuleName(specifier);
  26741. write(".");
  26742. emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
  26743. emitEnd(specifier.name);
  26744. write(" = ");
  26745. emitExpressionIdentifier(name);
  26746. write(";");
  26747. }
  26748. }
  26749. }
  26750. function emitExportSpecifierInSystemModule(specifier) {
  26751. ts.Debug.assert(modulekind === 4);
  26752. if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) {
  26753. return;
  26754. }
  26755. writeLine();
  26756. emitStart(specifier.name);
  26757. write(exportFunctionForFile + "(\"");
  26758. emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
  26759. write("\", ");
  26760. emitExpressionIdentifier(specifier.propertyName || specifier.name);
  26761. write(")");
  26762. emitEnd(specifier.name);
  26763. write(";");
  26764. }
  26765. function emitAssignment(name, value, shouldEmitCommaBeforeAssignment) {
  26766. if (shouldEmitCommaBeforeAssignment) {
  26767. write(", ");
  26768. }
  26769. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name);
  26770. if (exportChanged) {
  26771. write(exportFunctionForFile + "(\"");
  26772. emitNodeWithCommentsAndWithoutSourcemap(name);
  26773. write("\", ");
  26774. }
  26775. var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 211 || name.parent.kind === 163);
  26776. if (isVariableDeclarationOrBindingElement) {
  26777. emitModuleMemberName(name.parent);
  26778. }
  26779. else {
  26780. emit(name);
  26781. }
  26782. write(" = ");
  26783. emit(value);
  26784. if (exportChanged) {
  26785. write(")");
  26786. }
  26787. }
  26788. function emitTempVariableAssignment(expression, canDefineTempVariablesInPlace, shouldEmitCommaBeforeAssignment) {
  26789. var identifier = createTempVariable(0);
  26790. if (!canDefineTempVariablesInPlace) {
  26791. recordTempDeclaration(identifier);
  26792. }
  26793. emitAssignment(identifier, expression, shouldEmitCommaBeforeAssignment);
  26794. return identifier;
  26795. }
  26796. function emitDestructuring(root, isAssignmentExpressionStatement, value) {
  26797. var emitCount = 0;
  26798. var canDefineTempVariablesInPlace = false;
  26799. if (root.kind === 211) {
  26800. var isExported = ts.getCombinedNodeFlags(root) & 1;
  26801. var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root);
  26802. canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind;
  26803. }
  26804. else if (root.kind === 138) {
  26805. canDefineTempVariablesInPlace = true;
  26806. }
  26807. if (root.kind === 181) {
  26808. emitAssignmentExpression(root);
  26809. }
  26810. else {
  26811. ts.Debug.assert(!isAssignmentExpressionStatement);
  26812. emitBindingElement(root, value);
  26813. }
  26814. function ensureIdentifier(expr, reuseIdentifierExpressions) {
  26815. if (expr.kind === 69 && reuseIdentifierExpressions) {
  26816. return expr;
  26817. }
  26818. var identifier = emitTempVariableAssignment(expr, canDefineTempVariablesInPlace, emitCount > 0);
  26819. emitCount++;
  26820. return identifier;
  26821. }
  26822. function createDefaultValueCheck(value, defaultValue) {
  26823. value = ensureIdentifier(value, true);
  26824. var equals = ts.createSynthesizedNode(181);
  26825. equals.left = value;
  26826. equals.operatorToken = ts.createSynthesizedNode(32);
  26827. equals.right = createVoidZero();
  26828. return createConditionalExpression(equals, defaultValue, value);
  26829. }
  26830. function createConditionalExpression(condition, whenTrue, whenFalse) {
  26831. var cond = ts.createSynthesizedNode(182);
  26832. cond.condition = condition;
  26833. cond.questionToken = ts.createSynthesizedNode(53);
  26834. cond.whenTrue = whenTrue;
  26835. cond.colonToken = ts.createSynthesizedNode(54);
  26836. cond.whenFalse = whenFalse;
  26837. return cond;
  26838. }
  26839. function createNumericLiteral(value) {
  26840. var node = ts.createSynthesizedNode(8);
  26841. node.text = "" + value;
  26842. return node;
  26843. }
  26844. function createPropertyAccessForDestructuringProperty(object, propName) {
  26845. var syntheticName = ts.createSynthesizedNode(propName.kind);
  26846. syntheticName.text = propName.text;
  26847. if (syntheticName.kind !== 69) {
  26848. return createElementAccessExpression(object, syntheticName);
  26849. }
  26850. return createPropertyAccessExpression(object, syntheticName);
  26851. }
  26852. function createSliceCall(value, sliceIndex) {
  26853. var call = ts.createSynthesizedNode(168);
  26854. var sliceIdentifier = ts.createSynthesizedNode(69);
  26855. sliceIdentifier.text = "slice";
  26856. call.expression = createPropertyAccessExpression(value, sliceIdentifier);
  26857. call.arguments = ts.createSynthesizedNodeArray();
  26858. call.arguments[0] = createNumericLiteral(sliceIndex);
  26859. return call;
  26860. }
  26861. function emitObjectLiteralAssignment(target, value) {
  26862. var properties = target.properties;
  26863. if (properties.length !== 1) {
  26864. value = ensureIdentifier(value, true);
  26865. }
  26866. for (var _a = 0; _a < properties.length; _a++) {
  26867. var p = properties[_a];
  26868. if (p.kind === 245 || p.kind === 246) {
  26869. var propName = p.name;
  26870. var target_1 = p.kind === 246 ? p : p.initializer || propName;
  26871. emitDestructuringAssignment(target_1, createPropertyAccessForDestructuringProperty(value, propName));
  26872. }
  26873. }
  26874. }
  26875. function emitArrayLiteralAssignment(target, value) {
  26876. var elements = target.elements;
  26877. if (elements.length !== 1) {
  26878. value = ensureIdentifier(value, true);
  26879. }
  26880. for (var i = 0; i < elements.length; i++) {
  26881. var e = elements[i];
  26882. if (e.kind !== 187) {
  26883. if (e.kind !== 185) {
  26884. emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i)));
  26885. }
  26886. else if (i === elements.length - 1) {
  26887. emitDestructuringAssignment(e.expression, createSliceCall(value, i));
  26888. }
  26889. }
  26890. }
  26891. }
  26892. function emitDestructuringAssignment(target, value) {
  26893. if (target.kind === 246) {
  26894. if (target.objectAssignmentInitializer) {
  26895. value = createDefaultValueCheck(value, target.objectAssignmentInitializer);
  26896. }
  26897. target = target.name;
  26898. }
  26899. else if (target.kind === 181 && target.operatorToken.kind === 56) {
  26900. value = createDefaultValueCheck(value, target.right);
  26901. target = target.left;
  26902. }
  26903. if (target.kind === 165) {
  26904. emitObjectLiteralAssignment(target, value);
  26905. }
  26906. else if (target.kind === 164) {
  26907. emitArrayLiteralAssignment(target, value);
  26908. }
  26909. else {
  26910. emitAssignment(target, value, emitCount > 0);
  26911. emitCount++;
  26912. }
  26913. }
  26914. function emitAssignmentExpression(root) {
  26915. var target = root.left;
  26916. var value = root.right;
  26917. if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) {
  26918. emit(value);
  26919. }
  26920. else if (isAssignmentExpressionStatement) {
  26921. emitDestructuringAssignment(target, value);
  26922. }
  26923. else {
  26924. if (root.parent.kind !== 172) {
  26925. write("(");
  26926. }
  26927. value = ensureIdentifier(value, true);
  26928. emitDestructuringAssignment(target, value);
  26929. write(", ");
  26930. emit(value);
  26931. if (root.parent.kind !== 172) {
  26932. write(")");
  26933. }
  26934. }
  26935. }
  26936. function emitBindingElement(target, value) {
  26937. if (target.initializer) {
  26938. value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer;
  26939. }
  26940. else if (!value) {
  26941. value = createVoidZero();
  26942. }
  26943. if (ts.isBindingPattern(target.name)) {
  26944. var pattern = target.name;
  26945. var elements = pattern.elements;
  26946. var numElements = elements.length;
  26947. if (numElements !== 1) {
  26948. value = ensureIdentifier(value, numElements !== 0);
  26949. }
  26950. for (var i = 0; i < numElements; i++) {
  26951. var element = elements[i];
  26952. if (pattern.kind === 161) {
  26953. var propName = element.propertyName || element.name;
  26954. emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName));
  26955. }
  26956. else if (element.kind !== 187) {
  26957. if (!element.dotDotDotToken) {
  26958. emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i)));
  26959. }
  26960. else if (i === numElements - 1) {
  26961. emitBindingElement(element, createSliceCall(value, i));
  26962. }
  26963. }
  26964. }
  26965. }
  26966. else {
  26967. emitAssignment(target.name, value, emitCount > 0);
  26968. emitCount++;
  26969. }
  26970. }
  26971. }
  26972. function emitVariableDeclaration(node) {
  26973. if (ts.isBindingPattern(node.name)) {
  26974. if (languageVersion < 2) {
  26975. emitDestructuring(node, false);
  26976. }
  26977. else {
  26978. emit(node.name);
  26979. emitOptional(" = ", node.initializer);
  26980. }
  26981. }
  26982. else {
  26983. var initializer = node.initializer;
  26984. if (!initializer && languageVersion < 2) {
  26985. var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384) &&
  26986. (getCombinedFlagsForIdentifier(node.name) & 16384);
  26987. if (isUninitializedLet &&
  26988. node.parent.parent.kind !== 200 &&
  26989. node.parent.parent.kind !== 201) {
  26990. initializer = createVoidZero();
  26991. }
  26992. }
  26993. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name);
  26994. if (exportChanged) {
  26995. write(exportFunctionForFile + "(\"");
  26996. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  26997. write("\", ");
  26998. }
  26999. emitModuleMemberName(node);
  27000. emitOptional(" = ", initializer);
  27001. if (exportChanged) {
  27002. write(")");
  27003. }
  27004. }
  27005. }
  27006. function emitExportVariableAssignments(node) {
  27007. if (node.kind === 187) {
  27008. return;
  27009. }
  27010. var name = node.name;
  27011. if (name.kind === 69) {
  27012. emitExportMemberAssignments(name);
  27013. }
  27014. else if (ts.isBindingPattern(name)) {
  27015. ts.forEach(name.elements, emitExportVariableAssignments);
  27016. }
  27017. }
  27018. function getCombinedFlagsForIdentifier(node) {
  27019. if (!node.parent || (node.parent.kind !== 211 && node.parent.kind !== 163)) {
  27020. return 0;
  27021. }
  27022. return ts.getCombinedNodeFlags(node.parent);
  27023. }
  27024. function isES6ExportedDeclaration(node) {
  27025. return !!(node.flags & 1) &&
  27026. modulekind === 5 &&
  27027. node.parent.kind === 248;
  27028. }
  27029. function emitVariableStatement(node) {
  27030. var startIsEmitted = false;
  27031. if (node.flags & 1) {
  27032. if (isES6ExportedDeclaration(node)) {
  27033. write("export ");
  27034. startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
  27035. }
  27036. }
  27037. else {
  27038. startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
  27039. }
  27040. if (startIsEmitted) {
  27041. emitCommaList(node.declarationList.declarations);
  27042. write(";");
  27043. }
  27044. else {
  27045. var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList);
  27046. if (atLeastOneItem) {
  27047. write(";");
  27048. }
  27049. }
  27050. if (modulekind !== 5 && node.parent === currentSourceFile) {
  27051. ts.forEach(node.declarationList.declarations, emitExportVariableAssignments);
  27052. }
  27053. }
  27054. function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) {
  27055. if (!(node.flags & 1)) {
  27056. return true;
  27057. }
  27058. if (isES6ExportedDeclaration(node)) {
  27059. return true;
  27060. }
  27061. for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) {
  27062. var declaration = _b[_a];
  27063. if (declaration.initializer) {
  27064. return true;
  27065. }
  27066. }
  27067. return false;
  27068. }
  27069. function emitParameter(node) {
  27070. if (languageVersion < 2) {
  27071. if (ts.isBindingPattern(node.name)) {
  27072. var name_24 = createTempVariable(0);
  27073. if (!tempParameters) {
  27074. tempParameters = [];
  27075. }
  27076. tempParameters.push(name_24);
  27077. emit(name_24);
  27078. }
  27079. else {
  27080. emit(node.name);
  27081. }
  27082. }
  27083. else {
  27084. if (node.dotDotDotToken) {
  27085. write("...");
  27086. }
  27087. emit(node.name);
  27088. emitOptional(" = ", node.initializer);
  27089. }
  27090. }
  27091. function emitDefaultValueAssignments(node) {
  27092. if (languageVersion < 2) {
  27093. var tempIndex = 0;
  27094. ts.forEach(node.parameters, function (parameter) {
  27095. if (parameter.dotDotDotToken) {
  27096. return;
  27097. }
  27098. var paramName = parameter.name, initializer = parameter.initializer;
  27099. if (ts.isBindingPattern(paramName)) {
  27100. var hasBindingElements = paramName.elements.length > 0;
  27101. if (hasBindingElements || initializer) {
  27102. writeLine();
  27103. write("var ");
  27104. if (hasBindingElements) {
  27105. emitDestructuring(parameter, false, tempParameters[tempIndex]);
  27106. }
  27107. else {
  27108. emit(tempParameters[tempIndex]);
  27109. write(" = ");
  27110. emit(initializer);
  27111. }
  27112. write(";");
  27113. tempIndex++;
  27114. }
  27115. }
  27116. else if (initializer) {
  27117. writeLine();
  27118. emitStart(parameter);
  27119. write("if (");
  27120. emitNodeWithoutSourceMap(paramName);
  27121. write(" === void 0)");
  27122. emitEnd(parameter);
  27123. write(" { ");
  27124. emitStart(parameter);
  27125. emitNodeWithCommentsAndWithoutSourcemap(paramName);
  27126. write(" = ");
  27127. emitNodeWithCommentsAndWithoutSourcemap(initializer);
  27128. emitEnd(parameter);
  27129. write("; }");
  27130. }
  27131. });
  27132. }
  27133. }
  27134. function emitRestParameter(node) {
  27135. if (languageVersion < 2 && ts.hasRestParameter(node)) {
  27136. var restIndex = node.parameters.length - 1;
  27137. var restParam = node.parameters[restIndex];
  27138. if (ts.isBindingPattern(restParam.name)) {
  27139. return;
  27140. }
  27141. var tempName = createTempVariable(268435456).text;
  27142. writeLine();
  27143. emitLeadingComments(restParam);
  27144. emitStart(restParam);
  27145. write("var ");
  27146. emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
  27147. write(" = [];");
  27148. emitEnd(restParam);
  27149. emitTrailingComments(restParam);
  27150. writeLine();
  27151. write("for (");
  27152. emitStart(restParam);
  27153. write("var " + tempName + " = " + restIndex + ";");
  27154. emitEnd(restParam);
  27155. write(" ");
  27156. emitStart(restParam);
  27157. write(tempName + " < arguments.length;");
  27158. emitEnd(restParam);
  27159. write(" ");
  27160. emitStart(restParam);
  27161. write(tempName + "++");
  27162. emitEnd(restParam);
  27163. write(") {");
  27164. increaseIndent();
  27165. writeLine();
  27166. emitStart(restParam);
  27167. emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
  27168. write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];");
  27169. emitEnd(restParam);
  27170. decreaseIndent();
  27171. writeLine();
  27172. write("}");
  27173. }
  27174. }
  27175. function emitAccessor(node) {
  27176. write(node.kind === 145 ? "get " : "set ");
  27177. emit(node.name);
  27178. emitSignatureAndBody(node);
  27179. }
  27180. function shouldEmitAsArrowFunction(node) {
  27181. return node.kind === 174 && languageVersion >= 2;
  27182. }
  27183. function emitDeclarationName(node) {
  27184. if (node.name) {
  27185. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  27186. }
  27187. else {
  27188. write(getGeneratedNameForNode(node));
  27189. }
  27190. }
  27191. function shouldEmitFunctionName(node) {
  27192. if (node.kind === 173) {
  27193. return !!node.name;
  27194. }
  27195. if (node.kind === 213) {
  27196. return !!node.name || languageVersion < 2;
  27197. }
  27198. }
  27199. function emitFunctionDeclaration(node) {
  27200. if (ts.nodeIsMissing(node.body)) {
  27201. return emitCommentsOnNotEmittedNode(node);
  27202. }
  27203. if (node.kind !== 143 && node.kind !== 142 &&
  27204. node.parent && node.parent.kind !== 245 &&
  27205. node.parent.kind !== 168) {
  27206. emitLeadingComments(node);
  27207. }
  27208. emitStart(node);
  27209. if (!shouldEmitAsArrowFunction(node)) {
  27210. if (isES6ExportedDeclaration(node)) {
  27211. write("export ");
  27212. if (node.flags & 1024) {
  27213. write("default ");
  27214. }
  27215. }
  27216. write("function");
  27217. if (languageVersion >= 2 && node.asteriskToken) {
  27218. write("*");
  27219. }
  27220. write(" ");
  27221. }
  27222. if (shouldEmitFunctionName(node)) {
  27223. emitDeclarationName(node);
  27224. }
  27225. emitSignatureAndBody(node);
  27226. if (modulekind !== 5 && node.kind === 213 && node.parent === currentSourceFile && node.name) {
  27227. emitExportMemberAssignments(node.name);
  27228. }
  27229. emitEnd(node);
  27230. if (node.kind !== 143 && node.kind !== 142) {
  27231. emitTrailingComments(node);
  27232. }
  27233. }
  27234. function emitCaptureThisForNodeIfNecessary(node) {
  27235. if (resolver.getNodeCheckFlags(node) & 4) {
  27236. writeLine();
  27237. emitStart(node);
  27238. write("var _this = this;");
  27239. emitEnd(node);
  27240. }
  27241. }
  27242. function emitSignatureParameters(node) {
  27243. increaseIndent();
  27244. write("(");
  27245. if (node) {
  27246. var parameters = node.parameters;
  27247. var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0;
  27248. emitList(parameters, 0, parameters.length - omitCount, false, false);
  27249. }
  27250. write(")");
  27251. decreaseIndent();
  27252. }
  27253. function emitSignatureParametersForArrow(node) {
  27254. if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) {
  27255. emit(node.parameters[0]);
  27256. return;
  27257. }
  27258. emitSignatureParameters(node);
  27259. }
  27260. function emitAsyncFunctionBodyForES6(node) {
  27261. var promiseConstructor = ts.getEntityNameFromTypeNode(node.type);
  27262. var isArrowFunction = node.kind === 174;
  27263. var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096) !== 0;
  27264. var args;
  27265. if (!isArrowFunction) {
  27266. write(" {");
  27267. increaseIndent();
  27268. writeLine();
  27269. write("return");
  27270. }
  27271. write(" __awaiter(this");
  27272. if (hasLexicalArguments) {
  27273. write(", arguments");
  27274. }
  27275. else {
  27276. write(", void 0");
  27277. }
  27278. if (promiseConstructor) {
  27279. write(", ");
  27280. emitNodeWithoutSourceMap(promiseConstructor);
  27281. }
  27282. else {
  27283. write(", Promise");
  27284. }
  27285. if (hasLexicalArguments) {
  27286. write(", function* (_arguments)");
  27287. }
  27288. else {
  27289. write(", function* ()");
  27290. }
  27291. emitFunctionBody(node);
  27292. write(")");
  27293. if (!isArrowFunction) {
  27294. write(";");
  27295. decreaseIndent();
  27296. writeLine();
  27297. write("}");
  27298. }
  27299. }
  27300. function emitFunctionBody(node) {
  27301. if (!node.body) {
  27302. write(" { }");
  27303. }
  27304. else {
  27305. if (node.body.kind === 192) {
  27306. emitBlockFunctionBody(node, node.body);
  27307. }
  27308. else {
  27309. emitExpressionFunctionBody(node, node.body);
  27310. }
  27311. }
  27312. }
  27313. function emitSignatureAndBody(node) {
  27314. var saveTempFlags = tempFlags;
  27315. var saveTempVariables = tempVariables;
  27316. var saveTempParameters = tempParameters;
  27317. tempFlags = 0;
  27318. tempVariables = undefined;
  27319. tempParameters = undefined;
  27320. if (shouldEmitAsArrowFunction(node)) {
  27321. emitSignatureParametersForArrow(node);
  27322. write(" =>");
  27323. }
  27324. else {
  27325. emitSignatureParameters(node);
  27326. }
  27327. var isAsync = ts.isAsyncFunctionLike(node);
  27328. if (isAsync && languageVersion === 2) {
  27329. emitAsyncFunctionBodyForES6(node);
  27330. }
  27331. else {
  27332. emitFunctionBody(node);
  27333. }
  27334. if (!isES6ExportedDeclaration(node)) {
  27335. emitExportMemberAssignment(node);
  27336. }
  27337. tempFlags = saveTempFlags;
  27338. tempVariables = saveTempVariables;
  27339. tempParameters = saveTempParameters;
  27340. }
  27341. function emitFunctionBodyPreamble(node) {
  27342. emitCaptureThisForNodeIfNecessary(node);
  27343. emitDefaultValueAssignments(node);
  27344. emitRestParameter(node);
  27345. }
  27346. function emitExpressionFunctionBody(node, body) {
  27347. if (languageVersion < 2 || node.flags & 512) {
  27348. emitDownLevelExpressionFunctionBody(node, body);
  27349. return;
  27350. }
  27351. write(" ");
  27352. var current = body;
  27353. while (current.kind === 171) {
  27354. current = current.expression;
  27355. }
  27356. emitParenthesizedIf(body, current.kind === 165);
  27357. }
  27358. function emitDownLevelExpressionFunctionBody(node, body) {
  27359. write(" {");
  27360. scopeEmitStart(node);
  27361. increaseIndent();
  27362. var outPos = writer.getTextPos();
  27363. emitDetachedComments(node.body);
  27364. emitFunctionBodyPreamble(node);
  27365. var preambleEmitted = writer.getTextPos() !== outPos;
  27366. decreaseIndent();
  27367. if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) {
  27368. write(" ");
  27369. emitStart(body);
  27370. write("return ");
  27371. emit(body);
  27372. emitEnd(body);
  27373. write(";");
  27374. emitTempDeclarations(false);
  27375. write(" ");
  27376. }
  27377. else {
  27378. increaseIndent();
  27379. writeLine();
  27380. emitLeadingComments(node.body);
  27381. write("return ");
  27382. emit(body);
  27383. write(";");
  27384. emitTrailingComments(node.body);
  27385. emitTempDeclarations(true);
  27386. decreaseIndent();
  27387. writeLine();
  27388. }
  27389. emitStart(node.body);
  27390. write("}");
  27391. emitEnd(node.body);
  27392. scopeEmitEnd();
  27393. }
  27394. function emitBlockFunctionBody(node, body) {
  27395. write(" {");
  27396. scopeEmitStart(node);
  27397. var initialTextPos = writer.getTextPos();
  27398. increaseIndent();
  27399. emitDetachedComments(body.statements);
  27400. var startIndex = emitDirectivePrologues(body.statements, true);
  27401. emitFunctionBodyPreamble(node);
  27402. decreaseIndent();
  27403. var preambleEmitted = writer.getTextPos() !== initialTextPos;
  27404. if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
  27405. for (var _a = 0, _b = body.statements; _a < _b.length; _a++) {
  27406. var statement = _b[_a];
  27407. write(" ");
  27408. emit(statement);
  27409. }
  27410. emitTempDeclarations(false);
  27411. write(" ");
  27412. emitLeadingCommentsOfPosition(body.statements.end);
  27413. }
  27414. else {
  27415. increaseIndent();
  27416. emitLinesStartingAt(body.statements, startIndex);
  27417. emitTempDeclarations(true);
  27418. writeLine();
  27419. emitLeadingCommentsOfPosition(body.statements.end);
  27420. decreaseIndent();
  27421. }
  27422. emitToken(16, body.statements.end);
  27423. scopeEmitEnd();
  27424. }
  27425. function findInitialSuperCall(ctor) {
  27426. if (ctor.body) {
  27427. var statement = ctor.body.statements[0];
  27428. if (statement && statement.kind === 195) {
  27429. var expr = statement.expression;
  27430. if (expr && expr.kind === 168) {
  27431. var func = expr.expression;
  27432. if (func && func.kind === 95) {
  27433. return statement;
  27434. }
  27435. }
  27436. }
  27437. }
  27438. }
  27439. function emitParameterPropertyAssignments(node) {
  27440. ts.forEach(node.parameters, function (param) {
  27441. if (param.flags & 112) {
  27442. writeLine();
  27443. emitStart(param);
  27444. emitStart(param.name);
  27445. write("this.");
  27446. emitNodeWithoutSourceMap(param.name);
  27447. emitEnd(param.name);
  27448. write(" = ");
  27449. emit(param.name);
  27450. write(";");
  27451. emitEnd(param);
  27452. }
  27453. });
  27454. }
  27455. function emitMemberAccessForPropertyName(memberName) {
  27456. if (memberName.kind === 9 || memberName.kind === 8) {
  27457. write("[");
  27458. emitNodeWithCommentsAndWithoutSourcemap(memberName);
  27459. write("]");
  27460. }
  27461. else if (memberName.kind === 136) {
  27462. emitComputedPropertyName(memberName);
  27463. }
  27464. else {
  27465. write(".");
  27466. emitNodeWithCommentsAndWithoutSourcemap(memberName);
  27467. }
  27468. }
  27469. function getInitializedProperties(node, isStatic) {
  27470. var properties = [];
  27471. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  27472. var member = _b[_a];
  27473. if (member.kind === 141 && isStatic === ((member.flags & 128) !== 0) && member.initializer) {
  27474. properties.push(member);
  27475. }
  27476. }
  27477. return properties;
  27478. }
  27479. function emitPropertyDeclarations(node, properties) {
  27480. for (var _a = 0; _a < properties.length; _a++) {
  27481. var property = properties[_a];
  27482. emitPropertyDeclaration(node, property);
  27483. }
  27484. }
  27485. function emitPropertyDeclaration(node, property, receiver, isExpression) {
  27486. writeLine();
  27487. emitLeadingComments(property);
  27488. emitStart(property);
  27489. emitStart(property.name);
  27490. if (receiver) {
  27491. emit(receiver);
  27492. }
  27493. else {
  27494. if (property.flags & 128) {
  27495. emitDeclarationName(node);
  27496. }
  27497. else {
  27498. write("this");
  27499. }
  27500. }
  27501. emitMemberAccessForPropertyName(property.name);
  27502. emitEnd(property.name);
  27503. write(" = ");
  27504. emit(property.initializer);
  27505. if (!isExpression) {
  27506. write(";");
  27507. }
  27508. emitEnd(property);
  27509. emitTrailingComments(property);
  27510. }
  27511. function emitMemberFunctionsForES5AndLower(node) {
  27512. ts.forEach(node.members, function (member) {
  27513. if (member.kind === 191) {
  27514. writeLine();
  27515. write(";");
  27516. }
  27517. else if (member.kind === 143 || node.kind === 142) {
  27518. if (!member.body) {
  27519. return emitCommentsOnNotEmittedNode(member);
  27520. }
  27521. writeLine();
  27522. emitLeadingComments(member);
  27523. emitStart(member);
  27524. emitStart(member.name);
  27525. emitClassMemberPrefix(node, member);
  27526. emitMemberAccessForPropertyName(member.name);
  27527. emitEnd(member.name);
  27528. write(" = ");
  27529. emitFunctionDeclaration(member);
  27530. emitEnd(member);
  27531. write(";");
  27532. emitTrailingComments(member);
  27533. }
  27534. else if (member.kind === 145 || member.kind === 146) {
  27535. var accessors = ts.getAllAccessorDeclarations(node.members, member);
  27536. if (member === accessors.firstAccessor) {
  27537. writeLine();
  27538. emitStart(member);
  27539. write("Object.defineProperty(");
  27540. emitStart(member.name);
  27541. emitClassMemberPrefix(node, member);
  27542. write(", ");
  27543. emitExpressionForPropertyName(member.name);
  27544. emitEnd(member.name);
  27545. write(", {");
  27546. increaseIndent();
  27547. if (accessors.getAccessor) {
  27548. writeLine();
  27549. emitLeadingComments(accessors.getAccessor);
  27550. write("get: ");
  27551. emitStart(accessors.getAccessor);
  27552. write("function ");
  27553. emitSignatureAndBody(accessors.getAccessor);
  27554. emitEnd(accessors.getAccessor);
  27555. emitTrailingComments(accessors.getAccessor);
  27556. write(",");
  27557. }
  27558. if (accessors.setAccessor) {
  27559. writeLine();
  27560. emitLeadingComments(accessors.setAccessor);
  27561. write("set: ");
  27562. emitStart(accessors.setAccessor);
  27563. write("function ");
  27564. emitSignatureAndBody(accessors.setAccessor);
  27565. emitEnd(accessors.setAccessor);
  27566. emitTrailingComments(accessors.setAccessor);
  27567. write(",");
  27568. }
  27569. writeLine();
  27570. write("enumerable: true,");
  27571. writeLine();
  27572. write("configurable: true");
  27573. decreaseIndent();
  27574. writeLine();
  27575. write("});");
  27576. emitEnd(member);
  27577. }
  27578. }
  27579. });
  27580. }
  27581. function emitMemberFunctionsForES6AndHigher(node) {
  27582. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  27583. var member = _b[_a];
  27584. if ((member.kind === 143 || node.kind === 142) && !member.body) {
  27585. emitCommentsOnNotEmittedNode(member);
  27586. }
  27587. else if (member.kind === 143 ||
  27588. member.kind === 145 ||
  27589. member.kind === 146) {
  27590. writeLine();
  27591. emitLeadingComments(member);
  27592. emitStart(member);
  27593. if (member.flags & 128) {
  27594. write("static ");
  27595. }
  27596. if (member.kind === 145) {
  27597. write("get ");
  27598. }
  27599. else if (member.kind === 146) {
  27600. write("set ");
  27601. }
  27602. if (member.asteriskToken) {
  27603. write("*");
  27604. }
  27605. emit(member.name);
  27606. emitSignatureAndBody(member);
  27607. emitEnd(member);
  27608. emitTrailingComments(member);
  27609. }
  27610. else if (member.kind === 191) {
  27611. writeLine();
  27612. write(";");
  27613. }
  27614. }
  27615. }
  27616. function emitConstructor(node, baseTypeElement) {
  27617. var saveTempFlags = tempFlags;
  27618. var saveTempVariables = tempVariables;
  27619. var saveTempParameters = tempParameters;
  27620. tempFlags = 0;
  27621. tempVariables = undefined;
  27622. tempParameters = undefined;
  27623. emitConstructorWorker(node, baseTypeElement);
  27624. tempFlags = saveTempFlags;
  27625. tempVariables = saveTempVariables;
  27626. tempParameters = saveTempParameters;
  27627. }
  27628. function emitConstructorWorker(node, baseTypeElement) {
  27629. var hasInstancePropertyWithInitializer = false;
  27630. ts.forEach(node.members, function (member) {
  27631. if (member.kind === 144 && !member.body) {
  27632. emitCommentsOnNotEmittedNode(member);
  27633. }
  27634. if (member.kind === 141 && member.initializer && (member.flags & 128) === 0) {
  27635. hasInstancePropertyWithInitializer = true;
  27636. }
  27637. });
  27638. var ctor = ts.getFirstConstructorWithBody(node);
  27639. if (languageVersion >= 2 && !ctor && !hasInstancePropertyWithInitializer) {
  27640. return;
  27641. }
  27642. if (ctor) {
  27643. emitLeadingComments(ctor);
  27644. }
  27645. emitStart(ctor || node);
  27646. if (languageVersion < 2) {
  27647. write("function ");
  27648. emitDeclarationName(node);
  27649. emitSignatureParameters(ctor);
  27650. }
  27651. else {
  27652. write("constructor");
  27653. if (ctor) {
  27654. emitSignatureParameters(ctor);
  27655. }
  27656. else {
  27657. if (baseTypeElement) {
  27658. write("(...args)");
  27659. }
  27660. else {
  27661. write("()");
  27662. }
  27663. }
  27664. }
  27665. var startIndex = 0;
  27666. write(" {");
  27667. scopeEmitStart(node, "constructor");
  27668. increaseIndent();
  27669. if (ctor) {
  27670. startIndex = emitDirectivePrologues(ctor.body.statements, true);
  27671. emitDetachedComments(ctor.body.statements);
  27672. }
  27673. emitCaptureThisForNodeIfNecessary(node);
  27674. var superCall;
  27675. if (ctor) {
  27676. emitDefaultValueAssignments(ctor);
  27677. emitRestParameter(ctor);
  27678. if (baseTypeElement) {
  27679. superCall = findInitialSuperCall(ctor);
  27680. if (superCall) {
  27681. writeLine();
  27682. emit(superCall);
  27683. }
  27684. }
  27685. emitParameterPropertyAssignments(ctor);
  27686. }
  27687. else {
  27688. if (baseTypeElement) {
  27689. writeLine();
  27690. emitStart(baseTypeElement);
  27691. if (languageVersion < 2) {
  27692. write("_super.apply(this, arguments);");
  27693. }
  27694. else {
  27695. write("super(...args);");
  27696. }
  27697. emitEnd(baseTypeElement);
  27698. }
  27699. }
  27700. emitPropertyDeclarations(node, getInitializedProperties(node, false));
  27701. if (ctor) {
  27702. var statements = ctor.body.statements;
  27703. if (superCall) {
  27704. statements = statements.slice(1);
  27705. }
  27706. emitLinesStartingAt(statements, startIndex);
  27707. }
  27708. emitTempDeclarations(true);
  27709. writeLine();
  27710. if (ctor) {
  27711. emitLeadingCommentsOfPosition(ctor.body.statements.end);
  27712. }
  27713. decreaseIndent();
  27714. emitToken(16, ctor ? ctor.body.statements.end : node.members.end);
  27715. scopeEmitEnd();
  27716. emitEnd(ctor || node);
  27717. if (ctor) {
  27718. emitTrailingComments(ctor);
  27719. }
  27720. }
  27721. function emitClassExpression(node) {
  27722. return emitClassLikeDeclaration(node);
  27723. }
  27724. function emitClassDeclaration(node) {
  27725. return emitClassLikeDeclaration(node);
  27726. }
  27727. function emitClassLikeDeclaration(node) {
  27728. if (languageVersion < 2) {
  27729. emitClassLikeDeclarationBelowES6(node);
  27730. }
  27731. else {
  27732. emitClassLikeDeclarationForES6AndHigher(node);
  27733. }
  27734. if (modulekind !== 5 && node.parent === currentSourceFile && node.name) {
  27735. emitExportMemberAssignments(node.name);
  27736. }
  27737. }
  27738. function emitClassLikeDeclarationForES6AndHigher(node) {
  27739. var thisNodeIsDecorated = ts.nodeIsDecorated(node);
  27740. if (node.kind === 214) {
  27741. if (thisNodeIsDecorated) {
  27742. if (isES6ExportedDeclaration(node) && !(node.flags & 1024)) {
  27743. write("export ");
  27744. }
  27745. write("let ");
  27746. emitDeclarationName(node);
  27747. write(" = ");
  27748. }
  27749. else if (isES6ExportedDeclaration(node)) {
  27750. write("export ");
  27751. if (node.flags & 1024) {
  27752. write("default ");
  27753. }
  27754. }
  27755. }
  27756. var staticProperties = getInitializedProperties(node, true);
  27757. var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 186;
  27758. var tempVariable;
  27759. if (isClassExpressionWithStaticProperties) {
  27760. tempVariable = createAndRecordTempVariable(0);
  27761. write("(");
  27762. increaseIndent();
  27763. emit(tempVariable);
  27764. write(" = ");
  27765. }
  27766. write("class");
  27767. if ((node.name || (node.flags & 1024 && staticProperties.length > 0)) && !thisNodeIsDecorated) {
  27768. write(" ");
  27769. emitDeclarationName(node);
  27770. }
  27771. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  27772. if (baseTypeNode) {
  27773. write(" extends ");
  27774. emit(baseTypeNode.expression);
  27775. }
  27776. write(" {");
  27777. increaseIndent();
  27778. scopeEmitStart(node);
  27779. writeLine();
  27780. emitConstructor(node, baseTypeNode);
  27781. emitMemberFunctionsForES6AndHigher(node);
  27782. decreaseIndent();
  27783. writeLine();
  27784. emitToken(16, node.members.end);
  27785. scopeEmitEnd();
  27786. if (thisNodeIsDecorated) {
  27787. write(";");
  27788. }
  27789. if (isClassExpressionWithStaticProperties) {
  27790. for (var _a = 0; _a < staticProperties.length; _a++) {
  27791. var property = staticProperties[_a];
  27792. write(",");
  27793. writeLine();
  27794. emitPropertyDeclaration(node, property, tempVariable, true);
  27795. }
  27796. write(",");
  27797. writeLine();
  27798. emit(tempVariable);
  27799. decreaseIndent();
  27800. write(")");
  27801. }
  27802. else {
  27803. writeLine();
  27804. emitPropertyDeclarations(node, staticProperties);
  27805. emitDecoratorsOfClass(node);
  27806. }
  27807. if (!isES6ExportedDeclaration(node) && (node.flags & 1)) {
  27808. writeLine();
  27809. emitStart(node);
  27810. emitModuleMemberName(node);
  27811. write(" = ");
  27812. emitDeclarationName(node);
  27813. emitEnd(node);
  27814. write(";");
  27815. }
  27816. else if (isES6ExportedDeclaration(node) && (node.flags & 1024) && thisNodeIsDecorated) {
  27817. writeLine();
  27818. write("export default ");
  27819. emitDeclarationName(node);
  27820. write(";");
  27821. }
  27822. }
  27823. function emitClassLikeDeclarationBelowES6(node) {
  27824. if (node.kind === 214) {
  27825. if (!shouldHoistDeclarationInSystemJsModule(node)) {
  27826. write("var ");
  27827. }
  27828. emitDeclarationName(node);
  27829. write(" = ");
  27830. }
  27831. write("(function (");
  27832. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  27833. if (baseTypeNode) {
  27834. write("_super");
  27835. }
  27836. write(") {");
  27837. var saveTempFlags = tempFlags;
  27838. var saveTempVariables = tempVariables;
  27839. var saveTempParameters = tempParameters;
  27840. var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames;
  27841. tempFlags = 0;
  27842. tempVariables = undefined;
  27843. tempParameters = undefined;
  27844. computedPropertyNamesToGeneratedNames = undefined;
  27845. increaseIndent();
  27846. scopeEmitStart(node);
  27847. if (baseTypeNode) {
  27848. writeLine();
  27849. emitStart(baseTypeNode);
  27850. write("__extends(");
  27851. emitDeclarationName(node);
  27852. write(", _super);");
  27853. emitEnd(baseTypeNode);
  27854. }
  27855. writeLine();
  27856. emitConstructor(node, baseTypeNode);
  27857. emitMemberFunctionsForES5AndLower(node);
  27858. emitPropertyDeclarations(node, getInitializedProperties(node, true));
  27859. writeLine();
  27860. emitDecoratorsOfClass(node);
  27861. writeLine();
  27862. emitToken(16, node.members.end, function () {
  27863. write("return ");
  27864. emitDeclarationName(node);
  27865. });
  27866. write(";");
  27867. emitTempDeclarations(true);
  27868. tempFlags = saveTempFlags;
  27869. tempVariables = saveTempVariables;
  27870. tempParameters = saveTempParameters;
  27871. computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames;
  27872. decreaseIndent();
  27873. writeLine();
  27874. emitToken(16, node.members.end);
  27875. scopeEmitEnd();
  27876. emitStart(node);
  27877. write(")(");
  27878. if (baseTypeNode) {
  27879. emit(baseTypeNode.expression);
  27880. }
  27881. write(")");
  27882. if (node.kind === 214) {
  27883. write(";");
  27884. }
  27885. emitEnd(node);
  27886. if (node.kind === 214) {
  27887. emitExportMemberAssignment(node);
  27888. }
  27889. }
  27890. function emitClassMemberPrefix(node, member) {
  27891. emitDeclarationName(node);
  27892. if (!(member.flags & 128)) {
  27893. write(".prototype");
  27894. }
  27895. }
  27896. function emitDecoratorsOfClass(node) {
  27897. emitDecoratorsOfMembers(node, 0);
  27898. emitDecoratorsOfMembers(node, 128);
  27899. emitDecoratorsOfConstructor(node);
  27900. }
  27901. function emitDecoratorsOfConstructor(node) {
  27902. var decorators = node.decorators;
  27903. var constructor = ts.getFirstConstructorWithBody(node);
  27904. var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated);
  27905. if (!decorators && !hasDecoratedParameters) {
  27906. return;
  27907. }
  27908. writeLine();
  27909. emitStart(node);
  27910. emitDeclarationName(node);
  27911. write(" = __decorate([");
  27912. increaseIndent();
  27913. writeLine();
  27914. var decoratorCount = decorators ? decorators.length : 0;
  27915. var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) {
  27916. emitStart(decorator);
  27917. emit(decorator.expression);
  27918. emitEnd(decorator);
  27919. });
  27920. argumentsWritten += emitDecoratorsOfParameters(constructor, argumentsWritten > 0);
  27921. emitSerializedTypeMetadata(node, argumentsWritten >= 0);
  27922. decreaseIndent();
  27923. writeLine();
  27924. write("], ");
  27925. emitDeclarationName(node);
  27926. write(");");
  27927. emitEnd(node);
  27928. writeLine();
  27929. }
  27930. function emitDecoratorsOfMembers(node, staticFlag) {
  27931. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  27932. var member = _b[_a];
  27933. if ((member.flags & 128) !== staticFlag) {
  27934. continue;
  27935. }
  27936. if (!ts.nodeCanBeDecorated(member)) {
  27937. continue;
  27938. }
  27939. if (!ts.nodeOrChildIsDecorated(member)) {
  27940. continue;
  27941. }
  27942. var decorators = void 0;
  27943. var functionLikeMember = void 0;
  27944. if (ts.isAccessor(member)) {
  27945. var accessors = ts.getAllAccessorDeclarations(node.members, member);
  27946. if (member !== accessors.firstAccessor) {
  27947. continue;
  27948. }
  27949. decorators = accessors.firstAccessor.decorators;
  27950. if (!decorators && accessors.secondAccessor) {
  27951. decorators = accessors.secondAccessor.decorators;
  27952. }
  27953. functionLikeMember = accessors.setAccessor;
  27954. }
  27955. else {
  27956. decorators = member.decorators;
  27957. if (member.kind === 143) {
  27958. functionLikeMember = member;
  27959. }
  27960. }
  27961. writeLine();
  27962. emitStart(member);
  27963. write("__decorate([");
  27964. increaseIndent();
  27965. writeLine();
  27966. var decoratorCount = decorators ? decorators.length : 0;
  27967. var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) {
  27968. emitStart(decorator);
  27969. emit(decorator.expression);
  27970. emitEnd(decorator);
  27971. });
  27972. argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0);
  27973. emitSerializedTypeMetadata(member, argumentsWritten > 0);
  27974. decreaseIndent();
  27975. writeLine();
  27976. write("], ");
  27977. emitStart(member.name);
  27978. emitClassMemberPrefix(node, member);
  27979. write(", ");
  27980. emitExpressionForPropertyName(member.name);
  27981. emitEnd(member.name);
  27982. if (languageVersion > 0) {
  27983. if (member.kind !== 141) {
  27984. write(", null");
  27985. }
  27986. else {
  27987. write(", void 0");
  27988. }
  27989. }
  27990. write(");");
  27991. emitEnd(member);
  27992. writeLine();
  27993. }
  27994. }
  27995. function emitDecoratorsOfParameters(node, leadingComma) {
  27996. var argumentsWritten = 0;
  27997. if (node) {
  27998. var parameterIndex = 0;
  27999. for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) {
  28000. var parameter = _b[_a];
  28001. if (ts.nodeIsDecorated(parameter)) {
  28002. var decorators = parameter.decorators;
  28003. argumentsWritten += emitList(decorators, 0, decorators.length, true, false, leadingComma, true, function (decorator) {
  28004. emitStart(decorator);
  28005. write("__param(" + parameterIndex + ", ");
  28006. emit(decorator.expression);
  28007. write(")");
  28008. emitEnd(decorator);
  28009. });
  28010. leadingComma = true;
  28011. }
  28012. ++parameterIndex;
  28013. }
  28014. }
  28015. return argumentsWritten;
  28016. }
  28017. function shouldEmitTypeMetadata(node) {
  28018. switch (node.kind) {
  28019. case 143:
  28020. case 145:
  28021. case 146:
  28022. case 141:
  28023. return true;
  28024. }
  28025. return false;
  28026. }
  28027. function shouldEmitReturnTypeMetadata(node) {
  28028. switch (node.kind) {
  28029. case 143:
  28030. return true;
  28031. }
  28032. return false;
  28033. }
  28034. function shouldEmitParamTypesMetadata(node) {
  28035. switch (node.kind) {
  28036. case 214:
  28037. case 143:
  28038. case 146:
  28039. return true;
  28040. }
  28041. return false;
  28042. }
  28043. function emitSerializedTypeOfNode(node) {
  28044. switch (node.kind) {
  28045. case 214:
  28046. write("Function");
  28047. return;
  28048. case 141:
  28049. emitSerializedTypeNode(node.type);
  28050. return;
  28051. case 138:
  28052. emitSerializedTypeNode(node.type);
  28053. return;
  28054. case 145:
  28055. emitSerializedTypeNode(node.type);
  28056. return;
  28057. case 146:
  28058. emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node));
  28059. return;
  28060. }
  28061. if (ts.isFunctionLike(node)) {
  28062. write("Function");
  28063. return;
  28064. }
  28065. write("void 0");
  28066. }
  28067. function emitSerializedTypeNode(node) {
  28068. if (node) {
  28069. switch (node.kind) {
  28070. case 103:
  28071. write("void 0");
  28072. return;
  28073. case 160:
  28074. emitSerializedTypeNode(node.type);
  28075. return;
  28076. case 152:
  28077. case 153:
  28078. write("Function");
  28079. return;
  28080. case 156:
  28081. case 157:
  28082. write("Array");
  28083. return;
  28084. case 150:
  28085. case 120:
  28086. write("Boolean");
  28087. return;
  28088. case 130:
  28089. case 9:
  28090. write("String");
  28091. return;
  28092. case 128:
  28093. write("Number");
  28094. return;
  28095. case 131:
  28096. write("Symbol");
  28097. return;
  28098. case 151:
  28099. emitSerializedTypeReferenceNode(node);
  28100. return;
  28101. case 154:
  28102. case 155:
  28103. case 158:
  28104. case 159:
  28105. case 117:
  28106. break;
  28107. default:
  28108. ts.Debug.fail("Cannot serialize unexpected type node.");
  28109. break;
  28110. }
  28111. }
  28112. write("Object");
  28113. }
  28114. function emitSerializedTypeReferenceNode(node) {
  28115. var location = node.parent;
  28116. while (ts.isDeclaration(location) || ts.isTypeNode(location)) {
  28117. location = location.parent;
  28118. }
  28119. var typeName = ts.cloneEntityName(node.typeName);
  28120. typeName.parent = location;
  28121. var result = resolver.getTypeReferenceSerializationKind(typeName);
  28122. switch (result) {
  28123. case ts.TypeReferenceSerializationKind.Unknown:
  28124. var temp = createAndRecordTempVariable(0);
  28125. write("(typeof (");
  28126. emitNodeWithoutSourceMap(temp);
  28127. write(" = ");
  28128. emitEntityNameAsExpression(typeName, true);
  28129. write(") === 'function' && ");
  28130. emitNodeWithoutSourceMap(temp);
  28131. write(") || Object");
  28132. break;
  28133. case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue:
  28134. emitEntityNameAsExpression(typeName, false);
  28135. break;
  28136. case ts.TypeReferenceSerializationKind.VoidType:
  28137. write("void 0");
  28138. break;
  28139. case ts.TypeReferenceSerializationKind.BooleanType:
  28140. write("Boolean");
  28141. break;
  28142. case ts.TypeReferenceSerializationKind.NumberLikeType:
  28143. write("Number");
  28144. break;
  28145. case ts.TypeReferenceSerializationKind.StringLikeType:
  28146. write("String");
  28147. break;
  28148. case ts.TypeReferenceSerializationKind.ArrayLikeType:
  28149. write("Array");
  28150. break;
  28151. case ts.TypeReferenceSerializationKind.ESSymbolType:
  28152. if (languageVersion < 2) {
  28153. write("typeof Symbol === 'function' ? Symbol : Object");
  28154. }
  28155. else {
  28156. write("Symbol");
  28157. }
  28158. break;
  28159. case ts.TypeReferenceSerializationKind.TypeWithCallSignature:
  28160. write("Function");
  28161. break;
  28162. case ts.TypeReferenceSerializationKind.ObjectType:
  28163. write("Object");
  28164. break;
  28165. }
  28166. }
  28167. function emitSerializedParameterTypesOfNode(node) {
  28168. if (node) {
  28169. var valueDeclaration;
  28170. if (node.kind === 214) {
  28171. valueDeclaration = ts.getFirstConstructorWithBody(node);
  28172. }
  28173. else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) {
  28174. valueDeclaration = node;
  28175. }
  28176. if (valueDeclaration) {
  28177. var parameters = valueDeclaration.parameters;
  28178. var parameterCount = parameters.length;
  28179. if (parameterCount > 0) {
  28180. for (var i = 0; i < parameterCount; i++) {
  28181. if (i > 0) {
  28182. write(", ");
  28183. }
  28184. if (parameters[i].dotDotDotToken) {
  28185. var parameterType = parameters[i].type;
  28186. if (parameterType.kind === 156) {
  28187. parameterType = parameterType.elementType;
  28188. }
  28189. else if (parameterType.kind === 151 && parameterType.typeArguments && parameterType.typeArguments.length === 1) {
  28190. parameterType = parameterType.typeArguments[0];
  28191. }
  28192. else {
  28193. parameterType = undefined;
  28194. }
  28195. emitSerializedTypeNode(parameterType);
  28196. }
  28197. else {
  28198. emitSerializedTypeOfNode(parameters[i]);
  28199. }
  28200. }
  28201. }
  28202. }
  28203. }
  28204. }
  28205. function emitSerializedReturnTypeOfNode(node) {
  28206. if (node && ts.isFunctionLike(node) && node.type) {
  28207. emitSerializedTypeNode(node.type);
  28208. return;
  28209. }
  28210. write("void 0");
  28211. }
  28212. function emitSerializedTypeMetadata(node, writeComma) {
  28213. var argumentsWritten = 0;
  28214. if (compilerOptions.emitDecoratorMetadata) {
  28215. if (shouldEmitTypeMetadata(node)) {
  28216. if (writeComma) {
  28217. write(", ");
  28218. }
  28219. writeLine();
  28220. write("__metadata('design:type', ");
  28221. emitSerializedTypeOfNode(node);
  28222. write(")");
  28223. argumentsWritten++;
  28224. }
  28225. if (shouldEmitParamTypesMetadata(node)) {
  28226. if (writeComma || argumentsWritten) {
  28227. write(", ");
  28228. }
  28229. writeLine();
  28230. write("__metadata('design:paramtypes', [");
  28231. emitSerializedParameterTypesOfNode(node);
  28232. write("])");
  28233. argumentsWritten++;
  28234. }
  28235. if (shouldEmitReturnTypeMetadata(node)) {
  28236. if (writeComma || argumentsWritten) {
  28237. write(", ");
  28238. }
  28239. writeLine();
  28240. write("__metadata('design:returntype', ");
  28241. emitSerializedReturnTypeOfNode(node);
  28242. write(")");
  28243. argumentsWritten++;
  28244. }
  28245. }
  28246. return argumentsWritten;
  28247. }
  28248. function emitInterfaceDeclaration(node) {
  28249. emitCommentsOnNotEmittedNode(node);
  28250. }
  28251. function shouldEmitEnumDeclaration(node) {
  28252. var isConstEnum = ts.isConst(node);
  28253. return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules;
  28254. }
  28255. function emitEnumDeclaration(node) {
  28256. if (!shouldEmitEnumDeclaration(node)) {
  28257. return;
  28258. }
  28259. if (!shouldHoistDeclarationInSystemJsModule(node)) {
  28260. if (!(node.flags & 1) || isES6ExportedDeclaration(node)) {
  28261. emitStart(node);
  28262. if (isES6ExportedDeclaration(node)) {
  28263. write("export ");
  28264. }
  28265. write("var ");
  28266. emit(node.name);
  28267. emitEnd(node);
  28268. write(";");
  28269. }
  28270. }
  28271. writeLine();
  28272. emitStart(node);
  28273. write("(function (");
  28274. emitStart(node.name);
  28275. write(getGeneratedNameForNode(node));
  28276. emitEnd(node.name);
  28277. write(") {");
  28278. increaseIndent();
  28279. scopeEmitStart(node);
  28280. emitLines(node.members);
  28281. decreaseIndent();
  28282. writeLine();
  28283. emitToken(16, node.members.end);
  28284. scopeEmitEnd();
  28285. write(")(");
  28286. emitModuleMemberName(node);
  28287. write(" || (");
  28288. emitModuleMemberName(node);
  28289. write(" = {}));");
  28290. emitEnd(node);
  28291. if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) {
  28292. writeLine();
  28293. emitStart(node);
  28294. write("var ");
  28295. emit(node.name);
  28296. write(" = ");
  28297. emitModuleMemberName(node);
  28298. emitEnd(node);
  28299. write(";");
  28300. }
  28301. if (modulekind !== 5 && node.parent === currentSourceFile) {
  28302. if (modulekind === 4 && (node.flags & 1)) {
  28303. writeLine();
  28304. write(exportFunctionForFile + "(\"");
  28305. emitDeclarationName(node);
  28306. write("\", ");
  28307. emitDeclarationName(node);
  28308. write(");");
  28309. }
  28310. emitExportMemberAssignments(node.name);
  28311. }
  28312. }
  28313. function emitEnumMember(node) {
  28314. var enumParent = node.parent;
  28315. emitStart(node);
  28316. write(getGeneratedNameForNode(enumParent));
  28317. write("[");
  28318. write(getGeneratedNameForNode(enumParent));
  28319. write("[");
  28320. emitExpressionForPropertyName(node.name);
  28321. write("] = ");
  28322. writeEnumMemberDeclarationValue(node);
  28323. write("] = ");
  28324. emitExpressionForPropertyName(node.name);
  28325. emitEnd(node);
  28326. write(";");
  28327. }
  28328. function writeEnumMemberDeclarationValue(member) {
  28329. var value = resolver.getConstantValue(member);
  28330. if (value !== undefined) {
  28331. write(value.toString());
  28332. return;
  28333. }
  28334. else if (member.initializer) {
  28335. emit(member.initializer);
  28336. }
  28337. else {
  28338. write("undefined");
  28339. }
  28340. }
  28341. function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) {
  28342. if (moduleDeclaration.body.kind === 218) {
  28343. var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body);
  28344. return recursiveInnerModule || moduleDeclaration.body;
  28345. }
  28346. }
  28347. function shouldEmitModuleDeclaration(node) {
  28348. return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules);
  28349. }
  28350. function isModuleMergedWithES6Class(node) {
  28351. return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 32768);
  28352. }
  28353. function emitModuleDeclaration(node) {
  28354. var shouldEmit = shouldEmitModuleDeclaration(node);
  28355. if (!shouldEmit) {
  28356. return emitCommentsOnNotEmittedNode(node);
  28357. }
  28358. var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node);
  28359. var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node);
  28360. if (emitVarForModule) {
  28361. emitStart(node);
  28362. if (isES6ExportedDeclaration(node)) {
  28363. write("export ");
  28364. }
  28365. write("var ");
  28366. emit(node.name);
  28367. write(";");
  28368. emitEnd(node);
  28369. writeLine();
  28370. }
  28371. emitStart(node);
  28372. write("(function (");
  28373. emitStart(node.name);
  28374. write(getGeneratedNameForNode(node));
  28375. emitEnd(node.name);
  28376. write(") ");
  28377. if (node.body.kind === 219) {
  28378. var saveTempFlags = tempFlags;
  28379. var saveTempVariables = tempVariables;
  28380. tempFlags = 0;
  28381. tempVariables = undefined;
  28382. emit(node.body);
  28383. tempFlags = saveTempFlags;
  28384. tempVariables = saveTempVariables;
  28385. }
  28386. else {
  28387. write("{");
  28388. increaseIndent();
  28389. scopeEmitStart(node);
  28390. emitCaptureThisForNodeIfNecessary(node);
  28391. writeLine();
  28392. emit(node.body);
  28393. decreaseIndent();
  28394. writeLine();
  28395. var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body;
  28396. emitToken(16, moduleBlock.statements.end);
  28397. scopeEmitEnd();
  28398. }
  28399. write(")(");
  28400. if ((node.flags & 1) && !isES6ExportedDeclaration(node)) {
  28401. emit(node.name);
  28402. write(" = ");
  28403. }
  28404. emitModuleMemberName(node);
  28405. write(" || (");
  28406. emitModuleMemberName(node);
  28407. write(" = {}));");
  28408. emitEnd(node);
  28409. if (!isES6ExportedDeclaration(node) && node.name.kind === 69 && node.parent === currentSourceFile) {
  28410. if (modulekind === 4 && (node.flags & 1)) {
  28411. writeLine();
  28412. write(exportFunctionForFile + "(\"");
  28413. emitDeclarationName(node);
  28414. write("\", ");
  28415. emitDeclarationName(node);
  28416. write(");");
  28417. }
  28418. emitExportMemberAssignments(node.name);
  28419. }
  28420. }
  28421. function tryRenameExternalModule(moduleName) {
  28422. if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) {
  28423. return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\"";
  28424. }
  28425. return undefined;
  28426. }
  28427. function emitRequire(moduleName) {
  28428. if (moduleName.kind === 9) {
  28429. write("require(");
  28430. var text = tryRenameExternalModule(moduleName);
  28431. if (text) {
  28432. write(text);
  28433. }
  28434. else {
  28435. emitStart(moduleName);
  28436. emitLiteral(moduleName);
  28437. emitEnd(moduleName);
  28438. }
  28439. emitToken(18, moduleName.end);
  28440. }
  28441. else {
  28442. write("require()");
  28443. }
  28444. }
  28445. function getNamespaceDeclarationNode(node) {
  28446. if (node.kind === 221) {
  28447. return node;
  28448. }
  28449. var importClause = node.importClause;
  28450. if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 224) {
  28451. return importClause.namedBindings;
  28452. }
  28453. }
  28454. function isDefaultImport(node) {
  28455. return node.kind === 222 && node.importClause && !!node.importClause.name;
  28456. }
  28457. function emitExportImportAssignments(node) {
  28458. if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) {
  28459. emitExportMemberAssignments(node.name);
  28460. }
  28461. ts.forEachChild(node, emitExportImportAssignments);
  28462. }
  28463. function emitImportDeclaration(node) {
  28464. if (modulekind !== 5) {
  28465. return emitExternalImportDeclaration(node);
  28466. }
  28467. if (node.importClause) {
  28468. var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause);
  28469. var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, true);
  28470. if (shouldEmitDefaultBindings || shouldEmitNamedBindings) {
  28471. write("import ");
  28472. emitStart(node.importClause);
  28473. if (shouldEmitDefaultBindings) {
  28474. emit(node.importClause.name);
  28475. if (shouldEmitNamedBindings) {
  28476. write(", ");
  28477. }
  28478. }
  28479. if (shouldEmitNamedBindings) {
  28480. emitLeadingComments(node.importClause.namedBindings);
  28481. emitStart(node.importClause.namedBindings);
  28482. if (node.importClause.namedBindings.kind === 224) {
  28483. write("* as ");
  28484. emit(node.importClause.namedBindings.name);
  28485. }
  28486. else {
  28487. write("{ ");
  28488. emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration);
  28489. write(" }");
  28490. }
  28491. emitEnd(node.importClause.namedBindings);
  28492. emitTrailingComments(node.importClause.namedBindings);
  28493. }
  28494. emitEnd(node.importClause);
  28495. write(" from ");
  28496. emit(node.moduleSpecifier);
  28497. write(";");
  28498. }
  28499. }
  28500. else {
  28501. write("import ");
  28502. emit(node.moduleSpecifier);
  28503. write(";");
  28504. }
  28505. }
  28506. function emitExternalImportDeclaration(node) {
  28507. if (ts.contains(externalImports, node)) {
  28508. var isExportedImport = node.kind === 221 && (node.flags & 1) !== 0;
  28509. var namespaceDeclaration = getNamespaceDeclarationNode(node);
  28510. if (modulekind !== 2) {
  28511. emitLeadingComments(node);
  28512. emitStart(node);
  28513. if (namespaceDeclaration && !isDefaultImport(node)) {
  28514. if (!isExportedImport)
  28515. write("var ");
  28516. emitModuleMemberName(namespaceDeclaration);
  28517. write(" = ");
  28518. }
  28519. else {
  28520. var isNakedImport = 222 && !node.importClause;
  28521. if (!isNakedImport) {
  28522. write("var ");
  28523. write(getGeneratedNameForNode(node));
  28524. write(" = ");
  28525. }
  28526. }
  28527. emitRequire(ts.getExternalModuleName(node));
  28528. if (namespaceDeclaration && isDefaultImport(node)) {
  28529. write(", ");
  28530. emitModuleMemberName(namespaceDeclaration);
  28531. write(" = ");
  28532. write(getGeneratedNameForNode(node));
  28533. }
  28534. write(";");
  28535. emitEnd(node);
  28536. emitExportImportAssignments(node);
  28537. emitTrailingComments(node);
  28538. }
  28539. else {
  28540. if (isExportedImport) {
  28541. emitModuleMemberName(namespaceDeclaration);
  28542. write(" = ");
  28543. emit(namespaceDeclaration.name);
  28544. write(";");
  28545. }
  28546. else if (namespaceDeclaration && isDefaultImport(node)) {
  28547. write("var ");
  28548. emitModuleMemberName(namespaceDeclaration);
  28549. write(" = ");
  28550. write(getGeneratedNameForNode(node));
  28551. write(";");
  28552. }
  28553. emitExportImportAssignments(node);
  28554. }
  28555. }
  28556. }
  28557. function emitImportEqualsDeclaration(node) {
  28558. if (ts.isExternalModuleImportEqualsDeclaration(node)) {
  28559. emitExternalImportDeclaration(node);
  28560. return;
  28561. }
  28562. if (resolver.isReferencedAliasDeclaration(node) ||
  28563. (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) {
  28564. emitLeadingComments(node);
  28565. emitStart(node);
  28566. var variableDeclarationIsHoisted = shouldHoistVariable(node, true);
  28567. var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, true);
  28568. if (!variableDeclarationIsHoisted) {
  28569. ts.Debug.assert(!isExported);
  28570. if (isES6ExportedDeclaration(node)) {
  28571. write("export ");
  28572. write("var ");
  28573. }
  28574. else if (!(node.flags & 1)) {
  28575. write("var ");
  28576. }
  28577. }
  28578. if (isExported) {
  28579. write(exportFunctionForFile + "(\"");
  28580. emitNodeWithoutSourceMap(node.name);
  28581. write("\", ");
  28582. }
  28583. emitModuleMemberName(node);
  28584. write(" = ");
  28585. emit(node.moduleReference);
  28586. if (isExported) {
  28587. write(")");
  28588. }
  28589. write(";");
  28590. emitEnd(node);
  28591. emitExportImportAssignments(node);
  28592. emitTrailingComments(node);
  28593. }
  28594. }
  28595. function emitExportDeclaration(node) {
  28596. ts.Debug.assert(modulekind !== 4);
  28597. if (modulekind !== 5) {
  28598. if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) {
  28599. emitStart(node);
  28600. var generatedName = getGeneratedNameForNode(node);
  28601. if (node.exportClause) {
  28602. if (modulekind !== 2) {
  28603. write("var ");
  28604. write(generatedName);
  28605. write(" = ");
  28606. emitRequire(ts.getExternalModuleName(node));
  28607. write(";");
  28608. }
  28609. for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) {
  28610. var specifier = _b[_a];
  28611. if (resolver.isValueAliasDeclaration(specifier)) {
  28612. writeLine();
  28613. emitStart(specifier);
  28614. emitContainingModuleName(specifier);
  28615. write(".");
  28616. emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
  28617. write(" = ");
  28618. write(generatedName);
  28619. write(".");
  28620. emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name);
  28621. write(";");
  28622. emitEnd(specifier);
  28623. }
  28624. }
  28625. }
  28626. else {
  28627. writeLine();
  28628. write("__export(");
  28629. if (modulekind !== 2) {
  28630. emitRequire(ts.getExternalModuleName(node));
  28631. }
  28632. else {
  28633. write(generatedName);
  28634. }
  28635. write(");");
  28636. }
  28637. emitEnd(node);
  28638. }
  28639. }
  28640. else {
  28641. if (!node.exportClause || resolver.isValueAliasDeclaration(node)) {
  28642. write("export ");
  28643. if (node.exportClause) {
  28644. write("{ ");
  28645. emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration);
  28646. write(" }");
  28647. }
  28648. else {
  28649. write("*");
  28650. }
  28651. if (node.moduleSpecifier) {
  28652. write(" from ");
  28653. emit(node.moduleSpecifier);
  28654. }
  28655. write(";");
  28656. }
  28657. }
  28658. }
  28659. function emitExportOrImportSpecifierList(specifiers, shouldEmit) {
  28660. ts.Debug.assert(modulekind === 5);
  28661. var needsComma = false;
  28662. for (var _a = 0; _a < specifiers.length; _a++) {
  28663. var specifier = specifiers[_a];
  28664. if (shouldEmit(specifier)) {
  28665. if (needsComma) {
  28666. write(", ");
  28667. }
  28668. if (specifier.propertyName) {
  28669. emit(specifier.propertyName);
  28670. write(" as ");
  28671. }
  28672. emit(specifier.name);
  28673. needsComma = true;
  28674. }
  28675. }
  28676. }
  28677. function emitExportAssignment(node) {
  28678. if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
  28679. if (modulekind === 5) {
  28680. writeLine();
  28681. emitStart(node);
  28682. write("export default ");
  28683. var expression = node.expression;
  28684. emit(expression);
  28685. if (expression.kind !== 213 &&
  28686. expression.kind !== 214) {
  28687. write(";");
  28688. }
  28689. emitEnd(node);
  28690. }
  28691. else {
  28692. writeLine();
  28693. emitStart(node);
  28694. if (modulekind === 4) {
  28695. write(exportFunctionForFile + "(\"default\",");
  28696. emit(node.expression);
  28697. write(")");
  28698. }
  28699. else {
  28700. emitEs6ExportDefaultCompat(node);
  28701. emitContainingModuleName(node);
  28702. if (languageVersion === 0) {
  28703. write("[\"default\"] = ");
  28704. }
  28705. else {
  28706. write(".default = ");
  28707. }
  28708. emit(node.expression);
  28709. }
  28710. write(";");
  28711. emitEnd(node);
  28712. }
  28713. }
  28714. }
  28715. function collectExternalModuleInfo(sourceFile) {
  28716. externalImports = [];
  28717. exportSpecifiers = {};
  28718. exportEquals = undefined;
  28719. hasExportStars = false;
  28720. for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) {
  28721. var node = _b[_a];
  28722. switch (node.kind) {
  28723. case 222:
  28724. if (!node.importClause ||
  28725. resolver.isReferencedAliasDeclaration(node.importClause, true)) {
  28726. externalImports.push(node);
  28727. }
  28728. break;
  28729. case 221:
  28730. if (node.moduleReference.kind === 232 && resolver.isReferencedAliasDeclaration(node)) {
  28731. externalImports.push(node);
  28732. }
  28733. break;
  28734. case 228:
  28735. if (node.moduleSpecifier) {
  28736. if (!node.exportClause) {
  28737. externalImports.push(node);
  28738. hasExportStars = true;
  28739. }
  28740. else if (resolver.isValueAliasDeclaration(node)) {
  28741. externalImports.push(node);
  28742. }
  28743. }
  28744. else {
  28745. for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) {
  28746. var specifier = _d[_c];
  28747. var name_25 = (specifier.propertyName || specifier.name).text;
  28748. (exportSpecifiers[name_25] || (exportSpecifiers[name_25] = [])).push(specifier);
  28749. }
  28750. }
  28751. break;
  28752. case 227:
  28753. if (node.isExportEquals && !exportEquals) {
  28754. exportEquals = node;
  28755. }
  28756. break;
  28757. }
  28758. }
  28759. }
  28760. function emitExportStarHelper() {
  28761. if (hasExportStars) {
  28762. writeLine();
  28763. write("function __export(m) {");
  28764. increaseIndent();
  28765. writeLine();
  28766. write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];");
  28767. decreaseIndent();
  28768. writeLine();
  28769. write("}");
  28770. }
  28771. }
  28772. function getLocalNameForExternalImport(node) {
  28773. var namespaceDeclaration = getNamespaceDeclarationNode(node);
  28774. if (namespaceDeclaration && !isDefaultImport(node)) {
  28775. return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
  28776. }
  28777. if (node.kind === 222 && node.importClause) {
  28778. return getGeneratedNameForNode(node);
  28779. }
  28780. if (node.kind === 228 && node.moduleSpecifier) {
  28781. return getGeneratedNameForNode(node);
  28782. }
  28783. }
  28784. function getExternalModuleNameText(importNode) {
  28785. var moduleName = ts.getExternalModuleName(importNode);
  28786. if (moduleName.kind === 9) {
  28787. return tryRenameExternalModule(moduleName) || getLiteralText(moduleName);
  28788. }
  28789. return undefined;
  28790. }
  28791. function emitVariableDeclarationsForImports() {
  28792. if (externalImports.length === 0) {
  28793. return;
  28794. }
  28795. writeLine();
  28796. var started = false;
  28797. for (var _a = 0; _a < externalImports.length; _a++) {
  28798. var importNode = externalImports[_a];
  28799. var skipNode = importNode.kind === 228 ||
  28800. (importNode.kind === 222 && !importNode.importClause);
  28801. if (skipNode) {
  28802. continue;
  28803. }
  28804. if (!started) {
  28805. write("var ");
  28806. started = true;
  28807. }
  28808. else {
  28809. write(", ");
  28810. }
  28811. write(getLocalNameForExternalImport(importNode));
  28812. }
  28813. if (started) {
  28814. write(";");
  28815. }
  28816. }
  28817. function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) {
  28818. if (!hasExportStars) {
  28819. return undefined;
  28820. }
  28821. if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) {
  28822. var hasExportDeclarationWithExportClause = false;
  28823. for (var _a = 0; _a < externalImports.length; _a++) {
  28824. var externalImport = externalImports[_a];
  28825. if (externalImport.kind === 228 && externalImport.exportClause) {
  28826. hasExportDeclarationWithExportClause = true;
  28827. break;
  28828. }
  28829. }
  28830. if (!hasExportDeclarationWithExportClause) {
  28831. return emitExportStarFunction(undefined);
  28832. }
  28833. }
  28834. var exportedNamesStorageRef = makeUniqueName("exportedNames");
  28835. writeLine();
  28836. write("var " + exportedNamesStorageRef + " = {");
  28837. increaseIndent();
  28838. var started = false;
  28839. if (exportedDeclarations) {
  28840. for (var i = 0; i < exportedDeclarations.length; ++i) {
  28841. writeExportedName(exportedDeclarations[i]);
  28842. }
  28843. }
  28844. if (exportSpecifiers) {
  28845. for (var n in exportSpecifiers) {
  28846. for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) {
  28847. var specifier = _c[_b];
  28848. writeExportedName(specifier.name);
  28849. }
  28850. }
  28851. }
  28852. for (var _d = 0; _d < externalImports.length; _d++) {
  28853. var externalImport = externalImports[_d];
  28854. if (externalImport.kind !== 228) {
  28855. continue;
  28856. }
  28857. var exportDecl = externalImport;
  28858. if (!exportDecl.exportClause) {
  28859. continue;
  28860. }
  28861. for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) {
  28862. var element = _f[_e];
  28863. writeExportedName(element.name || element.propertyName);
  28864. }
  28865. }
  28866. decreaseIndent();
  28867. writeLine();
  28868. write("};");
  28869. return emitExportStarFunction(exportedNamesStorageRef);
  28870. function emitExportStarFunction(localNames) {
  28871. var exportStarFunction = makeUniqueName("exportStar");
  28872. writeLine();
  28873. write("function " + exportStarFunction + "(m) {");
  28874. increaseIndent();
  28875. writeLine();
  28876. write("var exports = {};");
  28877. writeLine();
  28878. write("for(var n in m) {");
  28879. increaseIndent();
  28880. writeLine();
  28881. write("if (n !== \"default\"");
  28882. if (localNames) {
  28883. write("&& !" + localNames + ".hasOwnProperty(n)");
  28884. }
  28885. write(") exports[n] = m[n];");
  28886. decreaseIndent();
  28887. writeLine();
  28888. write("}");
  28889. writeLine();
  28890. write(exportFunctionForFile + "(exports);");
  28891. decreaseIndent();
  28892. writeLine();
  28893. write("}");
  28894. return exportStarFunction;
  28895. }
  28896. function writeExportedName(node) {
  28897. if (node.kind !== 69 && node.flags & 1024) {
  28898. return;
  28899. }
  28900. if (started) {
  28901. write(",");
  28902. }
  28903. else {
  28904. started = true;
  28905. }
  28906. writeLine();
  28907. write("'");
  28908. if (node.kind === 69) {
  28909. emitNodeWithCommentsAndWithoutSourcemap(node);
  28910. }
  28911. else {
  28912. emitDeclarationName(node);
  28913. }
  28914. write("': true");
  28915. }
  28916. }
  28917. function processTopLevelVariableAndFunctionDeclarations(node) {
  28918. var hoistedVars;
  28919. var hoistedFunctionDeclarations;
  28920. var exportedDeclarations;
  28921. visit(node);
  28922. if (hoistedVars) {
  28923. writeLine();
  28924. write("var ");
  28925. var seen = {};
  28926. for (var i = 0; i < hoistedVars.length; ++i) {
  28927. var local = hoistedVars[i];
  28928. var name_26 = local.kind === 69
  28929. ? local
  28930. : local.name;
  28931. if (name_26) {
  28932. var text = ts.unescapeIdentifier(name_26.text);
  28933. if (ts.hasProperty(seen, text)) {
  28934. continue;
  28935. }
  28936. else {
  28937. seen[text] = text;
  28938. }
  28939. }
  28940. if (i !== 0) {
  28941. write(", ");
  28942. }
  28943. if (local.kind === 214 || local.kind === 218 || local.kind === 217) {
  28944. emitDeclarationName(local);
  28945. }
  28946. else {
  28947. emit(local);
  28948. }
  28949. var flags = ts.getCombinedNodeFlags(local.kind === 69 ? local.parent : local);
  28950. if (flags & 1) {
  28951. if (!exportedDeclarations) {
  28952. exportedDeclarations = [];
  28953. }
  28954. exportedDeclarations.push(local);
  28955. }
  28956. }
  28957. write(";");
  28958. }
  28959. if (hoistedFunctionDeclarations) {
  28960. for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) {
  28961. var f = hoistedFunctionDeclarations[_a];
  28962. writeLine();
  28963. emit(f);
  28964. if (f.flags & 1) {
  28965. if (!exportedDeclarations) {
  28966. exportedDeclarations = [];
  28967. }
  28968. exportedDeclarations.push(f);
  28969. }
  28970. }
  28971. }
  28972. return exportedDeclarations;
  28973. function visit(node) {
  28974. if (node.flags & 2) {
  28975. return;
  28976. }
  28977. if (node.kind === 213) {
  28978. if (!hoistedFunctionDeclarations) {
  28979. hoistedFunctionDeclarations = [];
  28980. }
  28981. hoistedFunctionDeclarations.push(node);
  28982. return;
  28983. }
  28984. if (node.kind === 214) {
  28985. if (!hoistedVars) {
  28986. hoistedVars = [];
  28987. }
  28988. hoistedVars.push(node);
  28989. return;
  28990. }
  28991. if (node.kind === 217) {
  28992. if (shouldEmitEnumDeclaration(node)) {
  28993. if (!hoistedVars) {
  28994. hoistedVars = [];
  28995. }
  28996. hoistedVars.push(node);
  28997. }
  28998. return;
  28999. }
  29000. if (node.kind === 218) {
  29001. if (shouldEmitModuleDeclaration(node)) {
  29002. if (!hoistedVars) {
  29003. hoistedVars = [];
  29004. }
  29005. hoistedVars.push(node);
  29006. }
  29007. return;
  29008. }
  29009. if (node.kind === 211 || node.kind === 163) {
  29010. if (shouldHoistVariable(node, false)) {
  29011. var name_27 = node.name;
  29012. if (name_27.kind === 69) {
  29013. if (!hoistedVars) {
  29014. hoistedVars = [];
  29015. }
  29016. hoistedVars.push(name_27);
  29017. }
  29018. else {
  29019. ts.forEachChild(name_27, visit);
  29020. }
  29021. }
  29022. return;
  29023. }
  29024. if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) {
  29025. if (!hoistedVars) {
  29026. hoistedVars = [];
  29027. }
  29028. hoistedVars.push(node.name);
  29029. return;
  29030. }
  29031. if (ts.isBindingPattern(node)) {
  29032. ts.forEach(node.elements, visit);
  29033. return;
  29034. }
  29035. if (!ts.isDeclaration(node)) {
  29036. ts.forEachChild(node, visit);
  29037. }
  29038. }
  29039. }
  29040. function shouldHoistVariable(node, checkIfSourceFileLevelDecl) {
  29041. if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) {
  29042. return false;
  29043. }
  29044. return (ts.getCombinedNodeFlags(node) & 49152) === 0 ||
  29045. ts.getEnclosingBlockScopeContainer(node).kind === 248;
  29046. }
  29047. function isCurrentFileSystemExternalModule() {
  29048. return modulekind === 4 && ts.isExternalModule(currentSourceFile);
  29049. }
  29050. function emitSystemModuleBody(node, dependencyGroups, startIndex) {
  29051. emitVariableDeclarationsForImports();
  29052. writeLine();
  29053. var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node);
  29054. var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations);
  29055. writeLine();
  29056. write("return {");
  29057. increaseIndent();
  29058. writeLine();
  29059. emitSetters(exportStarFunction, dependencyGroups);
  29060. writeLine();
  29061. emitExecute(node, startIndex);
  29062. decreaseIndent();
  29063. writeLine();
  29064. write("}");
  29065. emitTempDeclarations(true);
  29066. }
  29067. function emitSetters(exportStarFunction, dependencyGroups) {
  29068. write("setters:[");
  29069. for (var i = 0; i < dependencyGroups.length; ++i) {
  29070. if (i !== 0) {
  29071. write(",");
  29072. }
  29073. writeLine();
  29074. increaseIndent();
  29075. var group = dependencyGroups[i];
  29076. var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || "");
  29077. write("function (" + parameterName + ") {");
  29078. increaseIndent();
  29079. for (var _a = 0; _a < group.length; _a++) {
  29080. var entry = group[_a];
  29081. var importVariableName = getLocalNameForExternalImport(entry) || "";
  29082. switch (entry.kind) {
  29083. case 222:
  29084. if (!entry.importClause) {
  29085. break;
  29086. }
  29087. case 221:
  29088. ts.Debug.assert(importVariableName !== "");
  29089. writeLine();
  29090. write(importVariableName + " = " + parameterName + ";");
  29091. writeLine();
  29092. break;
  29093. case 228:
  29094. ts.Debug.assert(importVariableName !== "");
  29095. if (entry.exportClause) {
  29096. writeLine();
  29097. write(exportFunctionForFile + "({");
  29098. writeLine();
  29099. increaseIndent();
  29100. for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) {
  29101. if (i_2 !== 0) {
  29102. write(",");
  29103. writeLine();
  29104. }
  29105. var e = entry.exportClause.elements[i_2];
  29106. write("\"");
  29107. emitNodeWithCommentsAndWithoutSourcemap(e.name);
  29108. write("\": " + parameterName + "[\"");
  29109. emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name);
  29110. write("\"]");
  29111. }
  29112. decreaseIndent();
  29113. writeLine();
  29114. write("});");
  29115. }
  29116. else {
  29117. writeLine();
  29118. write(exportStarFunction + "(" + parameterName + ");");
  29119. }
  29120. writeLine();
  29121. break;
  29122. }
  29123. }
  29124. decreaseIndent();
  29125. write("}");
  29126. decreaseIndent();
  29127. }
  29128. write("],");
  29129. }
  29130. function emitExecute(node, startIndex) {
  29131. write("execute: function() {");
  29132. increaseIndent();
  29133. writeLine();
  29134. for (var i = startIndex; i < node.statements.length; ++i) {
  29135. var statement = node.statements[i];
  29136. switch (statement.kind) {
  29137. case 213:
  29138. case 222:
  29139. continue;
  29140. case 228:
  29141. if (!statement.moduleSpecifier) {
  29142. for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) {
  29143. var element = _b[_a];
  29144. emitExportSpecifierInSystemModule(element);
  29145. }
  29146. }
  29147. continue;
  29148. case 221:
  29149. if (!ts.isInternalModuleImportEqualsDeclaration(statement)) {
  29150. continue;
  29151. }
  29152. default:
  29153. writeLine();
  29154. emit(statement);
  29155. }
  29156. }
  29157. decreaseIndent();
  29158. writeLine();
  29159. write("}");
  29160. }
  29161. function emitSystemModule(node) {
  29162. collectExternalModuleInfo(node);
  29163. ts.Debug.assert(!exportFunctionForFile);
  29164. exportFunctionForFile = makeUniqueName("exports");
  29165. writeLine();
  29166. write("System.register(");
  29167. if (node.moduleName) {
  29168. write("\"" + node.moduleName + "\", ");
  29169. }
  29170. write("[");
  29171. var groupIndices = {};
  29172. var dependencyGroups = [];
  29173. for (var i = 0; i < externalImports.length; ++i) {
  29174. var text = getExternalModuleNameText(externalImports[i]);
  29175. if (ts.hasProperty(groupIndices, text)) {
  29176. var groupIndex = groupIndices[text];
  29177. dependencyGroups[groupIndex].push(externalImports[i]);
  29178. continue;
  29179. }
  29180. else {
  29181. groupIndices[text] = dependencyGroups.length;
  29182. dependencyGroups.push([externalImports[i]]);
  29183. }
  29184. if (i !== 0) {
  29185. write(", ");
  29186. }
  29187. write(text);
  29188. }
  29189. write("], function(" + exportFunctionForFile + ") {");
  29190. writeLine();
  29191. increaseIndent();
  29192. var startIndex = emitDirectivePrologues(node.statements, true);
  29193. emitEmitHelpers(node);
  29194. emitCaptureThisForNodeIfNecessary(node);
  29195. emitSystemModuleBody(node, dependencyGroups, startIndex);
  29196. decreaseIndent();
  29197. writeLine();
  29198. write("});");
  29199. }
  29200. function getAMDDependencyNames(node, includeNonAmdDependencies) {
  29201. var aliasedModuleNames = [];
  29202. var unaliasedModuleNames = [];
  29203. var importAliasNames = [];
  29204. for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) {
  29205. var amdDependency = _b[_a];
  29206. if (amdDependency.name) {
  29207. aliasedModuleNames.push("\"" + amdDependency.path + "\"");
  29208. importAliasNames.push(amdDependency.name);
  29209. }
  29210. else {
  29211. unaliasedModuleNames.push("\"" + amdDependency.path + "\"");
  29212. }
  29213. }
  29214. for (var _c = 0; _c < externalImports.length; _c++) {
  29215. var importNode = externalImports[_c];
  29216. var externalModuleName = getExternalModuleNameText(importNode);
  29217. var importAliasName = getLocalNameForExternalImport(importNode);
  29218. if (includeNonAmdDependencies && importAliasName) {
  29219. aliasedModuleNames.push(externalModuleName);
  29220. importAliasNames.push(importAliasName);
  29221. }
  29222. else {
  29223. unaliasedModuleNames.push(externalModuleName);
  29224. }
  29225. }
  29226. return { aliasedModuleNames: aliasedModuleNames, unaliasedModuleNames: unaliasedModuleNames, importAliasNames: importAliasNames };
  29227. }
  29228. function emitAMDDependencies(node, includeNonAmdDependencies) {
  29229. var dependencyNames = getAMDDependencyNames(node, includeNonAmdDependencies);
  29230. emitAMDDependencyList(dependencyNames);
  29231. write(", ");
  29232. emitAMDFactoryHeader(dependencyNames);
  29233. }
  29234. function emitAMDDependencyList(_a) {
  29235. var aliasedModuleNames = _a.aliasedModuleNames, unaliasedModuleNames = _a.unaliasedModuleNames;
  29236. write("[\"require\", \"exports\"");
  29237. if (aliasedModuleNames.length) {
  29238. write(", ");
  29239. write(aliasedModuleNames.join(", "));
  29240. }
  29241. if (unaliasedModuleNames.length) {
  29242. write(", ");
  29243. write(unaliasedModuleNames.join(", "));
  29244. }
  29245. write("]");
  29246. }
  29247. function emitAMDFactoryHeader(_a) {
  29248. var importAliasNames = _a.importAliasNames;
  29249. write("function (require, exports");
  29250. if (importAliasNames.length) {
  29251. write(", ");
  29252. write(importAliasNames.join(", "));
  29253. }
  29254. write(") {");
  29255. }
  29256. function emitAMDModule(node) {
  29257. emitEmitHelpers(node);
  29258. collectExternalModuleInfo(node);
  29259. writeLine();
  29260. write("define(");
  29261. if (node.moduleName) {
  29262. write("\"" + node.moduleName + "\", ");
  29263. }
  29264. emitAMDDependencies(node, true);
  29265. increaseIndent();
  29266. var startIndex = emitDirectivePrologues(node.statements, true);
  29267. emitExportStarHelper();
  29268. emitCaptureThisForNodeIfNecessary(node);
  29269. emitLinesStartingAt(node.statements, startIndex);
  29270. emitTempDeclarations(true);
  29271. emitExportEquals(true);
  29272. decreaseIndent();
  29273. writeLine();
  29274. write("});");
  29275. }
  29276. function emitCommonJSModule(node) {
  29277. var startIndex = emitDirectivePrologues(node.statements, false);
  29278. emitEmitHelpers(node);
  29279. collectExternalModuleInfo(node);
  29280. emitExportStarHelper();
  29281. emitCaptureThisForNodeIfNecessary(node);
  29282. emitLinesStartingAt(node.statements, startIndex);
  29283. emitTempDeclarations(true);
  29284. emitExportEquals(false);
  29285. }
  29286. function emitUMDModule(node) {
  29287. emitEmitHelpers(node);
  29288. collectExternalModuleInfo(node);
  29289. var dependencyNames = getAMDDependencyNames(node, false);
  29290. writeLines("(function (factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define(");
  29291. emitAMDDependencyList(dependencyNames);
  29292. write(", factory);");
  29293. writeLines(" }\n})(");
  29294. emitAMDFactoryHeader(dependencyNames);
  29295. increaseIndent();
  29296. var startIndex = emitDirectivePrologues(node.statements, true);
  29297. emitExportStarHelper();
  29298. emitCaptureThisForNodeIfNecessary(node);
  29299. emitLinesStartingAt(node.statements, startIndex);
  29300. emitTempDeclarations(true);
  29301. emitExportEquals(true);
  29302. decreaseIndent();
  29303. writeLine();
  29304. write("});");
  29305. }
  29306. function emitES6Module(node) {
  29307. externalImports = undefined;
  29308. exportSpecifiers = undefined;
  29309. exportEquals = undefined;
  29310. hasExportStars = false;
  29311. var startIndex = emitDirectivePrologues(node.statements, false);
  29312. emitEmitHelpers(node);
  29313. emitCaptureThisForNodeIfNecessary(node);
  29314. emitLinesStartingAt(node.statements, startIndex);
  29315. emitTempDeclarations(true);
  29316. }
  29317. function emitExportEquals(emitAsReturn) {
  29318. if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) {
  29319. writeLine();
  29320. emitStart(exportEquals);
  29321. write(emitAsReturn ? "return " : "module.exports = ");
  29322. emit(exportEquals.expression);
  29323. write(";");
  29324. emitEnd(exportEquals);
  29325. }
  29326. }
  29327. function emitJsxElement(node) {
  29328. switch (compilerOptions.jsx) {
  29329. case 2:
  29330. jsxEmitReact(node);
  29331. break;
  29332. case 1:
  29333. default:
  29334. jsxEmitPreserve(node);
  29335. break;
  29336. }
  29337. }
  29338. function trimReactWhitespaceAndApplyEntities(node) {
  29339. var result = undefined;
  29340. var text = ts.getTextOfNode(node, true);
  29341. var firstNonWhitespace = 0;
  29342. var lastNonWhitespace = -1;
  29343. for (var i = 0; i < text.length; i++) {
  29344. var c = text.charCodeAt(i);
  29345. if (ts.isLineBreak(c)) {
  29346. if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) {
  29347. var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1);
  29348. result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part);
  29349. }
  29350. firstNonWhitespace = -1;
  29351. }
  29352. else if (!ts.isWhiteSpace(c)) {
  29353. lastNonWhitespace = i;
  29354. if (firstNonWhitespace === -1) {
  29355. firstNonWhitespace = i;
  29356. }
  29357. }
  29358. }
  29359. if (firstNonWhitespace !== -1) {
  29360. var part = text.substr(firstNonWhitespace);
  29361. result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part);
  29362. }
  29363. if (result) {
  29364. result = result.replace(/&(\w+);/g, function (s, m) {
  29365. if (entities[m] !== undefined) {
  29366. return String.fromCharCode(entities[m]);
  29367. }
  29368. else {
  29369. return s;
  29370. }
  29371. });
  29372. }
  29373. return result;
  29374. }
  29375. function getTextToEmit(node) {
  29376. switch (compilerOptions.jsx) {
  29377. case 2:
  29378. var text = trimReactWhitespaceAndApplyEntities(node);
  29379. if (text === undefined || text.length === 0) {
  29380. return undefined;
  29381. }
  29382. else {
  29383. return text;
  29384. }
  29385. case 1:
  29386. default:
  29387. return ts.getTextOfNode(node, true);
  29388. }
  29389. }
  29390. function emitJsxText(node) {
  29391. switch (compilerOptions.jsx) {
  29392. case 2:
  29393. write("\"");
  29394. write(trimReactWhitespaceAndApplyEntities(node));
  29395. write("\"");
  29396. break;
  29397. case 1:
  29398. default:
  29399. writer.writeLiteral(ts.getTextOfNode(node, true));
  29400. break;
  29401. }
  29402. }
  29403. function emitJsxExpression(node) {
  29404. if (node.expression) {
  29405. switch (compilerOptions.jsx) {
  29406. case 1:
  29407. default:
  29408. write("{");
  29409. emit(node.expression);
  29410. write("}");
  29411. break;
  29412. case 2:
  29413. emit(node.expression);
  29414. break;
  29415. }
  29416. }
  29417. }
  29418. function emitDirectivePrologues(statements, startWithNewLine) {
  29419. for (var i = 0; i < statements.length; ++i) {
  29420. if (ts.isPrologueDirective(statements[i])) {
  29421. if (startWithNewLine || i > 0) {
  29422. writeLine();
  29423. }
  29424. emit(statements[i]);
  29425. }
  29426. else {
  29427. return i;
  29428. }
  29429. }
  29430. return statements.length;
  29431. }
  29432. function writeLines(text) {
  29433. var lines = text.split(/\r\n|\r|\n/g);
  29434. for (var i = 0; i < lines.length; ++i) {
  29435. var line = lines[i];
  29436. if (line.length) {
  29437. writeLine();
  29438. write(line);
  29439. }
  29440. }
  29441. }
  29442. function emitEmitHelpers(node) {
  29443. if (!compilerOptions.noEmitHelpers) {
  29444. if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) {
  29445. writeLines(extendsHelper);
  29446. extendsEmitted = true;
  29447. }
  29448. if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16) {
  29449. writeLines(decorateHelper);
  29450. if (compilerOptions.emitDecoratorMetadata) {
  29451. writeLines(metadataHelper);
  29452. }
  29453. decorateEmitted = true;
  29454. }
  29455. if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32) {
  29456. writeLines(paramHelper);
  29457. paramEmitted = true;
  29458. }
  29459. if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64) {
  29460. writeLines(awaiterHelper);
  29461. awaiterEmitted = true;
  29462. }
  29463. }
  29464. }
  29465. function emitSourceFileNode(node) {
  29466. writeLine();
  29467. emitShebang();
  29468. emitDetachedComments(node);
  29469. if (ts.isExternalModule(node) || compilerOptions.isolatedModules) {
  29470. var emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[1];
  29471. emitModule(node);
  29472. }
  29473. else {
  29474. var startIndex = emitDirectivePrologues(node.statements, false);
  29475. externalImports = undefined;
  29476. exportSpecifiers = undefined;
  29477. exportEquals = undefined;
  29478. hasExportStars = false;
  29479. emitEmitHelpers(node);
  29480. emitCaptureThisForNodeIfNecessary(node);
  29481. emitLinesStartingAt(node.statements, startIndex);
  29482. emitTempDeclarations(true);
  29483. }
  29484. emitLeadingComments(node.endOfFileToken);
  29485. }
  29486. function emitNodeWithCommentsAndWithoutSourcemap(node) {
  29487. emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap);
  29488. }
  29489. function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) {
  29490. if (node) {
  29491. if (node.flags & 2) {
  29492. return emitCommentsOnNotEmittedNode(node);
  29493. }
  29494. if (isSpecializedCommentHandling(node)) {
  29495. return emitNodeWithoutSourceMap(node);
  29496. }
  29497. var emitComments_1 = shouldEmitLeadingAndTrailingComments(node);
  29498. if (emitComments_1) {
  29499. emitLeadingComments(node);
  29500. }
  29501. emitNodeConsideringSourcemap(node);
  29502. if (emitComments_1) {
  29503. emitTrailingComments(node);
  29504. }
  29505. }
  29506. }
  29507. function emitNodeWithoutSourceMap(node) {
  29508. if (node) {
  29509. emitJavaScriptWorker(node);
  29510. }
  29511. }
  29512. function isSpecializedCommentHandling(node) {
  29513. switch (node.kind) {
  29514. case 215:
  29515. case 213:
  29516. case 222:
  29517. case 221:
  29518. case 216:
  29519. case 227:
  29520. return true;
  29521. }
  29522. }
  29523. function shouldEmitLeadingAndTrailingComments(node) {
  29524. switch (node.kind) {
  29525. case 193:
  29526. return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node);
  29527. case 218:
  29528. return shouldEmitModuleDeclaration(node);
  29529. case 217:
  29530. return shouldEmitEnumDeclaration(node);
  29531. }
  29532. ts.Debug.assert(!isSpecializedCommentHandling(node));
  29533. if (node.kind !== 192 &&
  29534. node.parent &&
  29535. node.parent.kind === 174 &&
  29536. node.parent.body === node &&
  29537. compilerOptions.target <= 1) {
  29538. return false;
  29539. }
  29540. return true;
  29541. }
  29542. function emitJavaScriptWorker(node) {
  29543. switch (node.kind) {
  29544. case 69:
  29545. return emitIdentifier(node);
  29546. case 138:
  29547. return emitParameter(node);
  29548. case 143:
  29549. case 142:
  29550. return emitMethod(node);
  29551. case 145:
  29552. case 146:
  29553. return emitAccessor(node);
  29554. case 97:
  29555. return emitThis(node);
  29556. case 95:
  29557. return emitSuper(node);
  29558. case 93:
  29559. return write("null");
  29560. case 99:
  29561. return write("true");
  29562. case 84:
  29563. return write("false");
  29564. case 8:
  29565. case 9:
  29566. case 10:
  29567. case 11:
  29568. case 12:
  29569. case 13:
  29570. case 14:
  29571. return emitLiteral(node);
  29572. case 183:
  29573. return emitTemplateExpression(node);
  29574. case 190:
  29575. return emitTemplateSpan(node);
  29576. case 233:
  29577. case 234:
  29578. return emitJsxElement(node);
  29579. case 236:
  29580. return emitJsxText(node);
  29581. case 240:
  29582. return emitJsxExpression(node);
  29583. case 135:
  29584. return emitQualifiedName(node);
  29585. case 161:
  29586. return emitObjectBindingPattern(node);
  29587. case 162:
  29588. return emitArrayBindingPattern(node);
  29589. case 163:
  29590. return emitBindingElement(node);
  29591. case 164:
  29592. return emitArrayLiteral(node);
  29593. case 165:
  29594. return emitObjectLiteral(node);
  29595. case 245:
  29596. return emitPropertyAssignment(node);
  29597. case 246:
  29598. return emitShorthandPropertyAssignment(node);
  29599. case 136:
  29600. return emitComputedPropertyName(node);
  29601. case 166:
  29602. return emitPropertyAccess(node);
  29603. case 167:
  29604. return emitIndexedAccess(node);
  29605. case 168:
  29606. return emitCallExpression(node);
  29607. case 169:
  29608. return emitNewExpression(node);
  29609. case 170:
  29610. return emitTaggedTemplateExpression(node);
  29611. case 171:
  29612. return emit(node.expression);
  29613. case 189:
  29614. return emit(node.expression);
  29615. case 172:
  29616. return emitParenExpression(node);
  29617. case 213:
  29618. case 173:
  29619. case 174:
  29620. return emitFunctionDeclaration(node);
  29621. case 175:
  29622. return emitDeleteExpression(node);
  29623. case 176:
  29624. return emitTypeOfExpression(node);
  29625. case 177:
  29626. return emitVoidExpression(node);
  29627. case 178:
  29628. return emitAwaitExpression(node);
  29629. case 179:
  29630. return emitPrefixUnaryExpression(node);
  29631. case 180:
  29632. return emitPostfixUnaryExpression(node);
  29633. case 181:
  29634. return emitBinaryExpression(node);
  29635. case 182:
  29636. return emitConditionalExpression(node);
  29637. case 185:
  29638. return emitSpreadElementExpression(node);
  29639. case 184:
  29640. return emitYieldExpression(node);
  29641. case 187:
  29642. return;
  29643. case 192:
  29644. case 219:
  29645. return emitBlock(node);
  29646. case 193:
  29647. return emitVariableStatement(node);
  29648. case 194:
  29649. return write(";");
  29650. case 195:
  29651. return emitExpressionStatement(node);
  29652. case 196:
  29653. return emitIfStatement(node);
  29654. case 197:
  29655. return emitDoStatement(node);
  29656. case 198:
  29657. return emitWhileStatement(node);
  29658. case 199:
  29659. return emitForStatement(node);
  29660. case 201:
  29661. case 200:
  29662. return emitForInOrForOfStatement(node);
  29663. case 202:
  29664. case 203:
  29665. return emitBreakOrContinueStatement(node);
  29666. case 204:
  29667. return emitReturnStatement(node);
  29668. case 205:
  29669. return emitWithStatement(node);
  29670. case 206:
  29671. return emitSwitchStatement(node);
  29672. case 241:
  29673. case 242:
  29674. return emitCaseOrDefaultClause(node);
  29675. case 207:
  29676. return emitLabelledStatement(node);
  29677. case 208:
  29678. return emitThrowStatement(node);
  29679. case 209:
  29680. return emitTryStatement(node);
  29681. case 244:
  29682. return emitCatchClause(node);
  29683. case 210:
  29684. return emitDebuggerStatement(node);
  29685. case 211:
  29686. return emitVariableDeclaration(node);
  29687. case 186:
  29688. return emitClassExpression(node);
  29689. case 214:
  29690. return emitClassDeclaration(node);
  29691. case 215:
  29692. return emitInterfaceDeclaration(node);
  29693. case 217:
  29694. return emitEnumDeclaration(node);
  29695. case 247:
  29696. return emitEnumMember(node);
  29697. case 218:
  29698. return emitModuleDeclaration(node);
  29699. case 222:
  29700. return emitImportDeclaration(node);
  29701. case 221:
  29702. return emitImportEqualsDeclaration(node);
  29703. case 228:
  29704. return emitExportDeclaration(node);
  29705. case 227:
  29706. return emitExportAssignment(node);
  29707. case 248:
  29708. return emitSourceFileNode(node);
  29709. }
  29710. }
  29711. function hasDetachedComments(pos) {
  29712. return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos;
  29713. }
  29714. function getLeadingCommentsWithoutDetachedComments() {
  29715. var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos);
  29716. if (detachedCommentsInfo.length - 1) {
  29717. detachedCommentsInfo.pop();
  29718. }
  29719. else {
  29720. detachedCommentsInfo = undefined;
  29721. }
  29722. return leadingComments;
  29723. }
  29724. function isPinnedComments(comment) {
  29725. return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 &&
  29726. currentSourceFile.text.charCodeAt(comment.pos + 2) === 33;
  29727. }
  29728. function isTripleSlashComment(comment) {
  29729. if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 &&
  29730. comment.pos + 2 < comment.end &&
  29731. currentSourceFile.text.charCodeAt(comment.pos + 2) === 47) {
  29732. var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end);
  29733. return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) ||
  29734. textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ?
  29735. true : false;
  29736. }
  29737. return false;
  29738. }
  29739. function getLeadingCommentsToEmit(node) {
  29740. if (node.parent) {
  29741. if (node.parent.kind === 248 || node.pos !== node.parent.pos) {
  29742. if (hasDetachedComments(node.pos)) {
  29743. return getLeadingCommentsWithoutDetachedComments();
  29744. }
  29745. else {
  29746. return ts.getLeadingCommentRangesOfNode(node, currentSourceFile);
  29747. }
  29748. }
  29749. }
  29750. }
  29751. function getTrailingCommentsToEmit(node) {
  29752. if (node.parent) {
  29753. if (node.parent.kind === 248 || node.end !== node.parent.end) {
  29754. return ts.getTrailingCommentRanges(currentSourceFile.text, node.end);
  29755. }
  29756. }
  29757. }
  29758. function emitCommentsOnNotEmittedNode(node) {
  29759. emitLeadingCommentsWorker(node, false);
  29760. }
  29761. function emitLeadingComments(node) {
  29762. return emitLeadingCommentsWorker(node, true);
  29763. }
  29764. function emitLeadingCommentsWorker(node, isEmittedNode) {
  29765. if (compilerOptions.removeComments) {
  29766. return;
  29767. }
  29768. var leadingComments;
  29769. if (isEmittedNode) {
  29770. leadingComments = getLeadingCommentsToEmit(node);
  29771. }
  29772. else {
  29773. if (node.pos === 0) {
  29774. leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment);
  29775. }
  29776. }
  29777. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
  29778. ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
  29779. }
  29780. function emitTrailingComments(node) {
  29781. if (compilerOptions.removeComments) {
  29782. return;
  29783. }
  29784. var trailingComments = getTrailingCommentsToEmit(node);
  29785. ts.emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment);
  29786. }
  29787. function emitTrailingCommentsOfPosition(pos) {
  29788. if (compilerOptions.removeComments) {
  29789. return;
  29790. }
  29791. var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos);
  29792. ts.emitComments(currentSourceFile, writer, trailingComments, true, newLine, writeComment);
  29793. }
  29794. function emitLeadingCommentsOfPositionWorker(pos) {
  29795. if (compilerOptions.removeComments) {
  29796. return;
  29797. }
  29798. var leadingComments;
  29799. if (hasDetachedComments(pos)) {
  29800. leadingComments = getLeadingCommentsWithoutDetachedComments();
  29801. }
  29802. else {
  29803. leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos);
  29804. }
  29805. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments);
  29806. ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
  29807. }
  29808. function emitDetachedComments(node) {
  29809. var leadingComments;
  29810. if (compilerOptions.removeComments) {
  29811. if (node.pos === 0) {
  29812. leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments);
  29813. }
  29814. }
  29815. else {
  29816. leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
  29817. }
  29818. if (leadingComments) {
  29819. var detachedComments = [];
  29820. var lastComment;
  29821. ts.forEach(leadingComments, function (comment) {
  29822. if (lastComment) {
  29823. var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end);
  29824. var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos);
  29825. if (commentLine >= lastCommentLine + 2) {
  29826. return detachedComments;
  29827. }
  29828. }
  29829. detachedComments.push(comment);
  29830. lastComment = comment;
  29831. });
  29832. if (detachedComments.length) {
  29833. var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end);
  29834. var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos));
  29835. if (nodeLine >= lastCommentLine + 2) {
  29836. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
  29837. ts.emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment);
  29838. var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end };
  29839. if (detachedCommentsInfo) {
  29840. detachedCommentsInfo.push(currentDetachedCommentInfo);
  29841. }
  29842. else {
  29843. detachedCommentsInfo = [currentDetachedCommentInfo];
  29844. }
  29845. }
  29846. }
  29847. }
  29848. }
  29849. function emitShebang() {
  29850. var shebang = ts.getShebang(currentSourceFile.text);
  29851. if (shebang) {
  29852. write(shebang);
  29853. }
  29854. }
  29855. var _a;
  29856. }
  29857. function emitFile(jsFilePath, sourceFile) {
  29858. emitJavaScript(jsFilePath, sourceFile);
  29859. if (compilerOptions.declaration) {
  29860. ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics);
  29861. }
  29862. }
  29863. }
  29864. ts.emitFiles = emitFiles;
  29865. })(ts || (ts = {}));
  29866. var ts;
  29867. (function (ts) {
  29868. ts.programTime = 0;
  29869. ts.emitTime = 0;
  29870. ts.ioReadTime = 0;
  29871. ts.ioWriteTime = 0;
  29872. var emptyArray = [];
  29873. ts.version = "1.7.3";
  29874. function findConfigFile(searchPath) {
  29875. var fileName = "tsconfig.json";
  29876. while (true) {
  29877. if (ts.sys.fileExists(fileName)) {
  29878. return fileName;
  29879. }
  29880. var parentPath = ts.getDirectoryPath(searchPath);
  29881. if (parentPath === searchPath) {
  29882. break;
  29883. }
  29884. searchPath = parentPath;
  29885. fileName = "../" + fileName;
  29886. }
  29887. return undefined;
  29888. }
  29889. ts.findConfigFile = findConfigFile;
  29890. function resolveTripleslashReference(moduleName, containingFile) {
  29891. var basePath = ts.getDirectoryPath(containingFile);
  29892. var referencedFileName = ts.isRootedDiskPath(moduleName) ? moduleName : ts.combinePaths(basePath, moduleName);
  29893. return ts.normalizePath(referencedFileName);
  29894. }
  29895. ts.resolveTripleslashReference = resolveTripleslashReference;
  29896. function resolveModuleName(moduleName, containingFile, compilerOptions, host) {
  29897. var moduleResolution = compilerOptions.moduleResolution !== undefined
  29898. ? compilerOptions.moduleResolution
  29899. : compilerOptions.module === 1 ? 2 : 1;
  29900. switch (moduleResolution) {
  29901. case 2: return nodeModuleNameResolver(moduleName, containingFile, host);
  29902. case 1: return classicNameResolver(moduleName, containingFile, compilerOptions, host);
  29903. }
  29904. }
  29905. ts.resolveModuleName = resolveModuleName;
  29906. function nodeModuleNameResolver(moduleName, containingFile, host) {
  29907. var containingDirectory = ts.getDirectoryPath(containingFile);
  29908. if (ts.getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) {
  29909. var failedLookupLocations = [];
  29910. var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName));
  29911. var resolvedFileName = loadNodeModuleFromFile(candidate, failedLookupLocations, host);
  29912. if (resolvedFileName) {
  29913. return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations };
  29914. }
  29915. resolvedFileName = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host);
  29916. return resolvedFileName
  29917. ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }
  29918. : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations };
  29919. }
  29920. else {
  29921. return loadModuleFromNodeModules(moduleName, containingDirectory, host);
  29922. }
  29923. }
  29924. ts.nodeModuleNameResolver = nodeModuleNameResolver;
  29925. function loadNodeModuleFromFile(candidate, failedLookupLocation, host) {
  29926. return ts.forEach(ts.moduleFileExtensions, tryLoad);
  29927. function tryLoad(ext) {
  29928. var fileName = ts.fileExtensionIs(candidate, ext) ? candidate : candidate + ext;
  29929. if (host.fileExists(fileName)) {
  29930. return fileName;
  29931. }
  29932. else {
  29933. failedLookupLocation.push(fileName);
  29934. return undefined;
  29935. }
  29936. }
  29937. }
  29938. function loadNodeModuleFromDirectory(candidate, failedLookupLocation, host) {
  29939. var packageJsonPath = ts.combinePaths(candidate, "package.json");
  29940. if (host.fileExists(packageJsonPath)) {
  29941. var jsonContent;
  29942. try {
  29943. var jsonText = host.readFile(packageJsonPath);
  29944. jsonContent = jsonText ? JSON.parse(jsonText) : { typings: undefined };
  29945. }
  29946. catch (e) {
  29947. jsonContent = { typings: undefined };
  29948. }
  29949. if (jsonContent.typings) {
  29950. var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), failedLookupLocation, host);
  29951. if (result) {
  29952. return result;
  29953. }
  29954. }
  29955. }
  29956. else {
  29957. failedLookupLocation.push(packageJsonPath);
  29958. }
  29959. return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), failedLookupLocation, host);
  29960. }
  29961. function loadModuleFromNodeModules(moduleName, directory, host) {
  29962. var failedLookupLocations = [];
  29963. directory = ts.normalizeSlashes(directory);
  29964. while (true) {
  29965. var baseName = ts.getBaseFileName(directory);
  29966. if (baseName !== "node_modules") {
  29967. var nodeModulesFolder = ts.combinePaths(directory, "node_modules");
  29968. var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName));
  29969. var result = loadNodeModuleFromFile(candidate, failedLookupLocations, host);
  29970. if (result) {
  29971. return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations };
  29972. }
  29973. result = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host);
  29974. if (result) {
  29975. return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations };
  29976. }
  29977. }
  29978. var parentPath = ts.getDirectoryPath(directory);
  29979. if (parentPath === directory) {
  29980. break;
  29981. }
  29982. directory = parentPath;
  29983. }
  29984. return { resolvedModule: undefined, failedLookupLocations: failedLookupLocations };
  29985. }
  29986. function nameStartsWithDotSlashOrDotDotSlash(name) {
  29987. var i = name.lastIndexOf("./", 1);
  29988. return i === 0 || (i === 1 && name.charCodeAt(0) === 46);
  29989. }
  29990. function classicNameResolver(moduleName, containingFile, compilerOptions, host) {
  29991. if (moduleName.indexOf("!") != -1) {
  29992. return { resolvedModule: undefined, failedLookupLocations: [] };
  29993. }
  29994. var searchPath = ts.getDirectoryPath(containingFile);
  29995. var searchName;
  29996. var failedLookupLocations = [];
  29997. var referencedSourceFile;
  29998. while (true) {
  29999. searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleName));
  30000. referencedSourceFile = ts.forEach(ts.supportedExtensions, function (extension) {
  30001. if (extension === ".tsx" && !compilerOptions.jsx) {
  30002. return undefined;
  30003. }
  30004. var candidate = searchName + extension;
  30005. if (host.fileExists(candidate)) {
  30006. return candidate;
  30007. }
  30008. else {
  30009. failedLookupLocations.push(candidate);
  30010. }
  30011. });
  30012. if (referencedSourceFile) {
  30013. break;
  30014. }
  30015. var parentPath = ts.getDirectoryPath(searchPath);
  30016. if (parentPath === searchPath) {
  30017. break;
  30018. }
  30019. searchPath = parentPath;
  30020. }
  30021. return referencedSourceFile
  30022. ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations: failedLookupLocations }
  30023. : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations };
  30024. }
  30025. ts.classicNameResolver = classicNameResolver;
  30026. ts.defaultInitCompilerOptions = {
  30027. module: 1,
  30028. target: 0,
  30029. noImplicitAny: false,
  30030. outDir: "built",
  30031. rootDir: ".",
  30032. sourceMap: false
  30033. };
  30034. function createCompilerHost(options, setParentNodes) {
  30035. var currentDirectory;
  30036. var existingDirectories = {};
  30037. function getCanonicalFileName(fileName) {
  30038. return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
  30039. }
  30040. var unsupportedFileEncodingErrorCode = -2147024809;
  30041. function getSourceFile(fileName, languageVersion, onError) {
  30042. var text;
  30043. try {
  30044. var start = new Date().getTime();
  30045. text = ts.sys.readFile(fileName, options.charset);
  30046. ts.ioReadTime += new Date().getTime() - start;
  30047. }
  30048. catch (e) {
  30049. if (onError) {
  30050. onError(e.number === unsupportedFileEncodingErrorCode
  30051. ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText
  30052. : e.message);
  30053. }
  30054. text = "";
  30055. }
  30056. return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined;
  30057. }
  30058. function directoryExists(directoryPath) {
  30059. if (ts.hasProperty(existingDirectories, directoryPath)) {
  30060. return true;
  30061. }
  30062. if (ts.sys.directoryExists(directoryPath)) {
  30063. existingDirectories[directoryPath] = true;
  30064. return true;
  30065. }
  30066. return false;
  30067. }
  30068. function ensureDirectoriesExist(directoryPath) {
  30069. if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) {
  30070. var parentDirectory = ts.getDirectoryPath(directoryPath);
  30071. ensureDirectoriesExist(parentDirectory);
  30072. ts.sys.createDirectory(directoryPath);
  30073. }
  30074. }
  30075. function writeFile(fileName, data, writeByteOrderMark, onError) {
  30076. try {
  30077. var start = new Date().getTime();
  30078. ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName)));
  30079. ts.sys.writeFile(fileName, data, writeByteOrderMark);
  30080. ts.ioWriteTime += new Date().getTime() - start;
  30081. }
  30082. catch (e) {
  30083. if (onError) {
  30084. onError(e.message);
  30085. }
  30086. }
  30087. }
  30088. var newLine = ts.getNewLineCharacter(options);
  30089. return {
  30090. getSourceFile: getSourceFile,
  30091. getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); },
  30092. writeFile: writeFile,
  30093. getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); },
  30094. useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; },
  30095. getCanonicalFileName: getCanonicalFileName,
  30096. getNewLine: function () { return newLine; },
  30097. fileExists: function (fileName) { return ts.sys.fileExists(fileName); },
  30098. readFile: function (fileName) { return ts.sys.readFile(fileName); }
  30099. };
  30100. }
  30101. ts.createCompilerHost = createCompilerHost;
  30102. function getPreEmitDiagnostics(program, sourceFile, cancellationToken) {
  30103. var diagnostics = program.getOptionsDiagnostics(cancellationToken).concat(program.getSyntacticDiagnostics(sourceFile, cancellationToken), program.getGlobalDiagnostics(cancellationToken), program.getSemanticDiagnostics(sourceFile, cancellationToken));
  30104. if (program.getCompilerOptions().declaration) {
  30105. diagnostics.concat(program.getDeclarationDiagnostics(sourceFile, cancellationToken));
  30106. }
  30107. return ts.sortAndDeduplicateDiagnostics(diagnostics);
  30108. }
  30109. ts.getPreEmitDiagnostics = getPreEmitDiagnostics;
  30110. function flattenDiagnosticMessageText(messageText, newLine) {
  30111. if (typeof messageText === "string") {
  30112. return messageText;
  30113. }
  30114. else {
  30115. var diagnosticChain = messageText;
  30116. var result = "";
  30117. var indent = 0;
  30118. while (diagnosticChain) {
  30119. if (indent) {
  30120. result += newLine;
  30121. for (var i = 0; i < indent; i++) {
  30122. result += " ";
  30123. }
  30124. }
  30125. result += diagnosticChain.messageText;
  30126. indent++;
  30127. diagnosticChain = diagnosticChain.next;
  30128. }
  30129. return result;
  30130. }
  30131. }
  30132. ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
  30133. function createProgram(rootNames, options, host, oldProgram) {
  30134. var program;
  30135. var files = [];
  30136. var fileProcessingDiagnostics = ts.createDiagnosticCollection();
  30137. var programDiagnostics = ts.createDiagnosticCollection();
  30138. var commonSourceDirectory;
  30139. var diagnosticsProducingTypeChecker;
  30140. var noDiagnosticsTypeChecker;
  30141. var classifiableNames;
  30142. var skipDefaultLib = options.noLib;
  30143. var start = new Date().getTime();
  30144. host = host || createCompilerHost(options);
  30145. var resolveModuleNamesWorker = host.resolveModuleNames
  30146. ? (function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile); })
  30147. : (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }); });
  30148. var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); });
  30149. if (oldProgram) {
  30150. var oldOptions = oldProgram.getCompilerOptions();
  30151. if ((oldOptions.module !== options.module) ||
  30152. (oldOptions.noResolve !== options.noResolve) ||
  30153. (oldOptions.target !== options.target) ||
  30154. (oldOptions.noLib !== options.noLib) ||
  30155. (oldOptions.jsx !== options.jsx)) {
  30156. oldProgram = undefined;
  30157. }
  30158. }
  30159. if (!tryReuseStructureFromOldProgram()) {
  30160. ts.forEach(rootNames, function (name) { return processRootFile(name, false); });
  30161. if (!skipDefaultLib) {
  30162. processRootFile(host.getDefaultLibFileName(options), true);
  30163. }
  30164. }
  30165. verifyCompilerOptions();
  30166. oldProgram = undefined;
  30167. ts.programTime += new Date().getTime() - start;
  30168. program = {
  30169. getRootFileNames: function () { return rootNames; },
  30170. getSourceFile: getSourceFile,
  30171. getSourceFiles: function () { return files; },
  30172. getCompilerOptions: function () { return options; },
  30173. getSyntacticDiagnostics: getSyntacticDiagnostics,
  30174. getOptionsDiagnostics: getOptionsDiagnostics,
  30175. getGlobalDiagnostics: getGlobalDiagnostics,
  30176. getSemanticDiagnostics: getSemanticDiagnostics,
  30177. getDeclarationDiagnostics: getDeclarationDiagnostics,
  30178. getTypeChecker: getTypeChecker,
  30179. getClassifiableNames: getClassifiableNames,
  30180. getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker,
  30181. getCommonSourceDirectory: function () { return commonSourceDirectory; },
  30182. emit: emit,
  30183. getCurrentDirectory: function () { return host.getCurrentDirectory(); },
  30184. getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); },
  30185. getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); },
  30186. getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); },
  30187. getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); },
  30188. getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; }
  30189. };
  30190. return program;
  30191. function getClassifiableNames() {
  30192. if (!classifiableNames) {
  30193. getTypeChecker();
  30194. classifiableNames = {};
  30195. for (var _i = 0; _i < files.length; _i++) {
  30196. var sourceFile = files[_i];
  30197. ts.copyMap(sourceFile.classifiableNames, classifiableNames);
  30198. }
  30199. }
  30200. return classifiableNames;
  30201. }
  30202. function tryReuseStructureFromOldProgram() {
  30203. if (!oldProgram) {
  30204. return false;
  30205. }
  30206. ts.Debug.assert(!oldProgram.structureIsReused);
  30207. var oldRootNames = oldProgram.getRootFileNames();
  30208. if (!ts.arrayIsEqualTo(oldRootNames, rootNames)) {
  30209. return false;
  30210. }
  30211. var newSourceFiles = [];
  30212. var modifiedSourceFiles = [];
  30213. for (var _i = 0, _a = oldProgram.getSourceFiles(); _i < _a.length; _i++) {
  30214. var oldSourceFile = _a[_i];
  30215. var newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target);
  30216. if (!newSourceFile) {
  30217. return false;
  30218. }
  30219. if (oldSourceFile !== newSourceFile) {
  30220. if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
  30221. return false;
  30222. }
  30223. if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
  30224. return false;
  30225. }
  30226. collectExternalModuleReferences(newSourceFile);
  30227. if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
  30228. return false;
  30229. }
  30230. if (resolveModuleNamesWorker) {
  30231. var moduleNames = ts.map(newSourceFile.imports, function (name) { return name.text; });
  30232. var resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName);
  30233. for (var i = 0; i < moduleNames.length; ++i) {
  30234. var newResolution = resolutions[i];
  30235. var oldResolution = ts.getResolvedModule(oldSourceFile, moduleNames[i]);
  30236. var resolutionChanged = oldResolution
  30237. ? !newResolution ||
  30238. oldResolution.resolvedFileName !== newResolution.resolvedFileName ||
  30239. !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport
  30240. : newResolution;
  30241. if (resolutionChanged) {
  30242. return false;
  30243. }
  30244. }
  30245. }
  30246. newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
  30247. modifiedSourceFiles.push(newSourceFile);
  30248. }
  30249. else {
  30250. newSourceFile = oldSourceFile;
  30251. }
  30252. newSourceFiles.push(newSourceFile);
  30253. }
  30254. for (var _b = 0; _b < newSourceFiles.length; _b++) {
  30255. var file = newSourceFiles[_b];
  30256. filesByName.set(file.fileName, file);
  30257. }
  30258. files = newSourceFiles;
  30259. fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics();
  30260. for (var _c = 0; _c < modifiedSourceFiles.length; _c++) {
  30261. var modifiedFile = modifiedSourceFiles[_c];
  30262. fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile);
  30263. }
  30264. oldProgram.structureIsReused = true;
  30265. return true;
  30266. }
  30267. function getEmitHost(writeFileCallback) {
  30268. return {
  30269. getCanonicalFileName: function (fileName) { return host.getCanonicalFileName(fileName); },
  30270. getCommonSourceDirectory: program.getCommonSourceDirectory,
  30271. getCompilerOptions: program.getCompilerOptions,
  30272. getCurrentDirectory: function () { return host.getCurrentDirectory(); },
  30273. getNewLine: function () { return host.getNewLine(); },
  30274. getSourceFile: program.getSourceFile,
  30275. getSourceFiles: program.getSourceFiles,
  30276. writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError) { return host.writeFile(fileName, data, writeByteOrderMark, onError); })
  30277. };
  30278. }
  30279. function getDiagnosticsProducingTypeChecker() {
  30280. return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true));
  30281. }
  30282. function getTypeChecker() {
  30283. return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, false));
  30284. }
  30285. function emit(sourceFile, writeFileCallback, cancellationToken) {
  30286. var _this = this;
  30287. return runWithCancellationToken(function () { return emitWorker(_this, sourceFile, writeFileCallback, cancellationToken); });
  30288. }
  30289. function emitWorker(program, sourceFile, writeFileCallback, cancellationToken) {
  30290. if (options.noEmitOnError && getPreEmitDiagnostics(program, undefined, cancellationToken).length > 0) {
  30291. return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
  30292. }
  30293. var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile);
  30294. var start = new Date().getTime();
  30295. var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile);
  30296. ts.emitTime += new Date().getTime() - start;
  30297. return emitResult;
  30298. }
  30299. function getSourceFile(fileName) {
  30300. return filesByName.get(fileName) || filesByName.get(ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()));
  30301. }
  30302. function getDiagnosticsHelper(sourceFile, getDiagnostics, cancellationToken) {
  30303. if (sourceFile) {
  30304. return getDiagnostics(sourceFile, cancellationToken);
  30305. }
  30306. var allDiagnostics = [];
  30307. ts.forEach(program.getSourceFiles(), function (sourceFile) {
  30308. if (cancellationToken) {
  30309. cancellationToken.throwIfCancellationRequested();
  30310. }
  30311. ts.addRange(allDiagnostics, getDiagnostics(sourceFile, cancellationToken));
  30312. });
  30313. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  30314. }
  30315. function getSyntacticDiagnostics(sourceFile, cancellationToken) {
  30316. return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile, cancellationToken);
  30317. }
  30318. function getSemanticDiagnostics(sourceFile, cancellationToken) {
  30319. return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile, cancellationToken);
  30320. }
  30321. function getDeclarationDiagnostics(sourceFile, cancellationToken) {
  30322. return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile, cancellationToken);
  30323. }
  30324. function getSyntacticDiagnosticsForFile(sourceFile, cancellationToken) {
  30325. return sourceFile.parseDiagnostics;
  30326. }
  30327. function runWithCancellationToken(func) {
  30328. try {
  30329. return func();
  30330. }
  30331. catch (e) {
  30332. if (e instanceof ts.OperationCanceledException) {
  30333. noDiagnosticsTypeChecker = undefined;
  30334. diagnosticsProducingTypeChecker = undefined;
  30335. }
  30336. throw e;
  30337. }
  30338. }
  30339. function getSemanticDiagnosticsForFile(sourceFile, cancellationToken) {
  30340. return runWithCancellationToken(function () {
  30341. var typeChecker = getDiagnosticsProducingTypeChecker();
  30342. ts.Debug.assert(!!sourceFile.bindDiagnostics);
  30343. var bindDiagnostics = sourceFile.bindDiagnostics;
  30344. var checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken);
  30345. var fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
  30346. var programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName);
  30347. return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile);
  30348. });
  30349. }
  30350. function getDeclarationDiagnosticsForFile(sourceFile, cancellationToken) {
  30351. return runWithCancellationToken(function () {
  30352. if (!ts.isDeclarationFile(sourceFile)) {
  30353. var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
  30354. var writeFile_1 = function () { };
  30355. return ts.getDeclarationDiagnostics(getEmitHost(writeFile_1), resolver, sourceFile);
  30356. }
  30357. });
  30358. }
  30359. function getOptionsDiagnostics() {
  30360. var allDiagnostics = [];
  30361. ts.addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics());
  30362. ts.addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics());
  30363. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  30364. }
  30365. function getGlobalDiagnostics() {
  30366. var allDiagnostics = [];
  30367. ts.addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics());
  30368. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  30369. }
  30370. function hasExtension(fileName) {
  30371. return ts.getBaseFileName(fileName).indexOf(".") >= 0;
  30372. }
  30373. function processRootFile(fileName, isDefaultLib) {
  30374. processSourceFile(ts.normalizePath(fileName), isDefaultLib);
  30375. }
  30376. function fileReferenceIsEqualTo(a, b) {
  30377. return a.fileName === b.fileName;
  30378. }
  30379. function moduleNameIsEqualTo(a, b) {
  30380. return a.text === b.text;
  30381. }
  30382. function collectExternalModuleReferences(file) {
  30383. if (file.imports) {
  30384. return;
  30385. }
  30386. var imports;
  30387. for (var _i = 0, _a = file.statements; _i < _a.length; _i++) {
  30388. var node = _a[_i];
  30389. collect(node, true);
  30390. }
  30391. file.imports = imports || emptyArray;
  30392. function collect(node, allowRelativeModuleNames) {
  30393. switch (node.kind) {
  30394. case 222:
  30395. case 221:
  30396. case 228:
  30397. var moduleNameExpr = ts.getExternalModuleName(node);
  30398. if (!moduleNameExpr || moduleNameExpr.kind !== 9) {
  30399. break;
  30400. }
  30401. if (!moduleNameExpr.text) {
  30402. break;
  30403. }
  30404. if (allowRelativeModuleNames || !ts.isExternalModuleNameRelative(moduleNameExpr.text)) {
  30405. (imports || (imports = [])).push(moduleNameExpr);
  30406. }
  30407. break;
  30408. case 218:
  30409. if (node.name.kind === 9 && (node.flags & 2 || ts.isDeclarationFile(file))) {
  30410. ts.forEachChild(node.body, function (node) {
  30411. collect(node, false);
  30412. });
  30413. }
  30414. break;
  30415. }
  30416. }
  30417. }
  30418. function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
  30419. var diagnosticArgument;
  30420. var diagnostic;
  30421. if (hasExtension(fileName)) {
  30422. if (!options.allowNonTsExtensions && !ts.forEach(ts.supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) {
  30423. diagnostic = ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
  30424. diagnosticArgument = [fileName, "'" + ts.supportedExtensions.join("', '") + "'"];
  30425. }
  30426. else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
  30427. diagnostic = ts.Diagnostics.File_0_not_found;
  30428. diagnosticArgument = [fileName];
  30429. }
  30430. else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
  30431. diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself;
  30432. diagnosticArgument = [fileName];
  30433. }
  30434. }
  30435. else {
  30436. var nonTsFile = options.allowNonTsExtensions && findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd);
  30437. if (!nonTsFile) {
  30438. if (options.allowNonTsExtensions) {
  30439. diagnostic = ts.Diagnostics.File_0_not_found;
  30440. diagnosticArgument = [fileName];
  30441. }
  30442. else if (!ts.forEach(ts.supportedExtensions, function (extension) { return findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd); })) {
  30443. diagnostic = ts.Diagnostics.File_0_not_found;
  30444. fileName += ".ts";
  30445. diagnosticArgument = [fileName];
  30446. }
  30447. }
  30448. }
  30449. if (diagnostic) {
  30450. if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) {
  30451. fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument)));
  30452. }
  30453. else {
  30454. fileProcessingDiagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument)));
  30455. }
  30456. }
  30457. }
  30458. function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
  30459. if (filesByName.contains(fileName)) {
  30460. return getSourceFileFromCache(fileName, false);
  30461. }
  30462. var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
  30463. if (filesByName.contains(normalizedAbsolutePath)) {
  30464. var file_1 = getSourceFileFromCache(normalizedAbsolutePath, true);
  30465. filesByName.set(fileName, file_1);
  30466. return file_1;
  30467. }
  30468. var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) {
  30469. if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
  30470. fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
  30471. }
  30472. else {
  30473. fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
  30474. }
  30475. });
  30476. filesByName.set(fileName, file);
  30477. if (file) {
  30478. skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib;
  30479. filesByName.set(normalizedAbsolutePath, file);
  30480. var basePath = ts.getDirectoryPath(fileName);
  30481. if (!options.noResolve) {
  30482. processReferencedFiles(file, basePath);
  30483. }
  30484. processImportedModules(file, basePath);
  30485. if (isDefaultLib) {
  30486. file.isDefaultLib = true;
  30487. files.unshift(file);
  30488. }
  30489. else {
  30490. files.push(file);
  30491. }
  30492. }
  30493. return file;
  30494. function getSourceFileFromCache(fileName, useAbsolutePath) {
  30495. var file = filesByName.get(fileName);
  30496. if (file && host.useCaseSensitiveFileNames()) {
  30497. var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
  30498. if (ts.normalizeSlashes(fileName) !== ts.normalizeSlashes(sourceFileName)) {
  30499. if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
  30500. fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
  30501. }
  30502. else {
  30503. fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
  30504. }
  30505. }
  30506. }
  30507. return file;
  30508. }
  30509. }
  30510. function processReferencedFiles(file, basePath) {
  30511. ts.forEach(file.referencedFiles, function (ref) {
  30512. var referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
  30513. processSourceFile(referencedFileName, false, file, ref.pos, ref.end);
  30514. });
  30515. }
  30516. function processImportedModules(file, basePath) {
  30517. collectExternalModuleReferences(file);
  30518. if (file.imports.length) {
  30519. file.resolvedModules = {};
  30520. var moduleNames = ts.map(file.imports, function (name) { return name.text; });
  30521. var resolutions = resolveModuleNamesWorker(moduleNames, file.fileName);
  30522. for (var i = 0; i < file.imports.length; ++i) {
  30523. var resolution = resolutions[i];
  30524. ts.setResolvedModule(file, moduleNames[i], resolution);
  30525. if (resolution && !options.noResolve) {
  30526. var importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]);
  30527. if (importedFile && resolution.isExternalLibraryImport) {
  30528. if (!ts.isExternalModule(importedFile)) {
  30529. var start_2 = ts.getTokenPosOfNode(file.imports[i], file);
  30530. fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_2, file.imports[i].end - start_2, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName));
  30531. }
  30532. else if (importedFile.referencedFiles.length) {
  30533. var firstRef = importedFile.referencedFiles[0];
  30534. fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition));
  30535. }
  30536. }
  30537. }
  30538. }
  30539. }
  30540. else {
  30541. file.resolvedModules = undefined;
  30542. }
  30543. return;
  30544. function findModuleSourceFile(fileName, nameLiteral) {
  30545. return findSourceFile(fileName, false, file, ts.skipTrivia(file.text, nameLiteral.pos), nameLiteral.end);
  30546. }
  30547. }
  30548. function computeCommonSourceDirectory(sourceFiles) {
  30549. var commonPathComponents;
  30550. var currentDirectory = host.getCurrentDirectory();
  30551. ts.forEach(files, function (sourceFile) {
  30552. if (ts.isDeclarationFile(sourceFile)) {
  30553. return;
  30554. }
  30555. var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, currentDirectory);
  30556. sourcePathComponents.pop();
  30557. if (!commonPathComponents) {
  30558. commonPathComponents = sourcePathComponents;
  30559. return;
  30560. }
  30561. for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) {
  30562. if (commonPathComponents[i] !== sourcePathComponents[i]) {
  30563. if (i === 0) {
  30564. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
  30565. return;
  30566. }
  30567. commonPathComponents.length = i;
  30568. break;
  30569. }
  30570. }
  30571. if (sourcePathComponents.length < commonPathComponents.length) {
  30572. commonPathComponents.length = sourcePathComponents.length;
  30573. }
  30574. });
  30575. return ts.getNormalizedPathFromPathComponents(commonPathComponents);
  30576. }
  30577. function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) {
  30578. var allFilesBelongToPath = true;
  30579. if (sourceFiles) {
  30580. var currentDirectory = host.getCurrentDirectory();
  30581. var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory));
  30582. for (var _i = 0; _i < sourceFiles.length; _i++) {
  30583. var sourceFile = sourceFiles[_i];
  30584. if (!ts.isDeclarationFile(sourceFile)) {
  30585. var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
  30586. if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
  30587. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir));
  30588. allFilesBelongToPath = false;
  30589. }
  30590. }
  30591. }
  30592. }
  30593. return allFilesBelongToPath;
  30594. }
  30595. function verifyCompilerOptions() {
  30596. if (options.isolatedModules) {
  30597. if (options.declaration) {
  30598. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules"));
  30599. }
  30600. if (options.noEmitOnError) {
  30601. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules"));
  30602. }
  30603. if (options.out) {
  30604. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules"));
  30605. }
  30606. if (options.outFile) {
  30607. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules"));
  30608. }
  30609. }
  30610. if (options.inlineSourceMap) {
  30611. if (options.sourceMap) {
  30612. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap"));
  30613. }
  30614. if (options.mapRoot) {
  30615. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap"));
  30616. }
  30617. if (options.sourceRoot) {
  30618. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap"));
  30619. }
  30620. }
  30621. if (options.inlineSources) {
  30622. if (!options.sourceMap && !options.inlineSourceMap) {
  30623. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided));
  30624. }
  30625. }
  30626. if (options.out && options.outFile) {
  30627. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile"));
  30628. }
  30629. if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
  30630. if (options.mapRoot) {
  30631. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap"));
  30632. }
  30633. if (options.sourceRoot) {
  30634. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap"));
  30635. }
  30636. return;
  30637. }
  30638. var languageVersion = options.target || 0;
  30639. var outFile = options.outFile || options.out;
  30640. var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; });
  30641. if (options.isolatedModules) {
  30642. if (!options.module && languageVersion < 2) {
  30643. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher));
  30644. }
  30645. var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; });
  30646. if (firstNonExternalModuleSourceFile) {
  30647. var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
  30648. programDiagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
  30649. }
  30650. }
  30651. else if (firstExternalModuleSourceFile && languageVersion < 2 && !options.module) {
  30652. var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
  30653. programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided));
  30654. }
  30655. if (options.module === 5 && languageVersion < 2) {
  30656. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower));
  30657. }
  30658. if (options.outDir ||
  30659. options.sourceRoot ||
  30660. (options.mapRoot &&
  30661. (!outFile || firstExternalModuleSourceFile !== undefined))) {
  30662. if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
  30663. commonSourceDirectory = ts.getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory());
  30664. }
  30665. else {
  30666. commonSourceDirectory = computeCommonSourceDirectory(files);
  30667. }
  30668. if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== ts.directorySeparator) {
  30669. commonSourceDirectory += ts.directorySeparator;
  30670. }
  30671. }
  30672. if (options.noEmit) {
  30673. if (options.out) {
  30674. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out"));
  30675. }
  30676. if (options.outFile) {
  30677. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile"));
  30678. }
  30679. if (options.outDir) {
  30680. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir"));
  30681. }
  30682. if (options.declaration) {
  30683. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration"));
  30684. }
  30685. }
  30686. if (options.emitDecoratorMetadata &&
  30687. !options.experimentalDecorators) {
  30688. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
  30689. }
  30690. }
  30691. }
  30692. ts.createProgram = createProgram;
  30693. })(ts || (ts = {}));
  30694. var ts;
  30695. (function (ts) {
  30696. ts.optionDeclarations = [
  30697. {
  30698. name: "charset",
  30699. type: "string"
  30700. },
  30701. {
  30702. name: "declaration",
  30703. shortName: "d",
  30704. type: "boolean",
  30705. description: ts.Diagnostics.Generates_corresponding_d_ts_file
  30706. },
  30707. {
  30708. name: "diagnostics",
  30709. type: "boolean"
  30710. },
  30711. {
  30712. name: "emitBOM",
  30713. type: "boolean"
  30714. },
  30715. {
  30716. name: "help",
  30717. shortName: "h",
  30718. type: "boolean",
  30719. description: ts.Diagnostics.Print_this_message
  30720. },
  30721. {
  30722. name: "init",
  30723. type: "boolean",
  30724. description: ts.Diagnostics.Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file
  30725. },
  30726. {
  30727. name: "inlineSourceMap",
  30728. type: "boolean"
  30729. },
  30730. {
  30731. name: "inlineSources",
  30732. type: "boolean"
  30733. },
  30734. {
  30735. name: "jsx",
  30736. type: {
  30737. "preserve": 1,
  30738. "react": 2
  30739. },
  30740. paramType: ts.Diagnostics.KIND,
  30741. description: ts.Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
  30742. error: ts.Diagnostics.Argument_for_jsx_must_be_preserve_or_react
  30743. },
  30744. {
  30745. name: "listFiles",
  30746. type: "boolean"
  30747. },
  30748. {
  30749. name: "locale",
  30750. type: "string"
  30751. },
  30752. {
  30753. name: "mapRoot",
  30754. type: "string",
  30755. isFilePath: true,
  30756. description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
  30757. paramType: ts.Diagnostics.LOCATION
  30758. },
  30759. {
  30760. name: "module",
  30761. shortName: "m",
  30762. type: {
  30763. "commonjs": 1,
  30764. "amd": 2,
  30765. "system": 4,
  30766. "umd": 3,
  30767. "es6": 5,
  30768. "es2015": 5
  30769. },
  30770. description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6,
  30771. paramType: ts.Diagnostics.KIND,
  30772. error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6
  30773. },
  30774. {
  30775. name: "newLine",
  30776. type: {
  30777. "crlf": 0,
  30778. "lf": 1
  30779. },
  30780. description: ts.Diagnostics.Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
  30781. paramType: ts.Diagnostics.NEWLINE,
  30782. error: ts.Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF
  30783. },
  30784. {
  30785. name: "noEmit",
  30786. type: "boolean",
  30787. description: ts.Diagnostics.Do_not_emit_outputs
  30788. },
  30789. {
  30790. name: "noEmitHelpers",
  30791. type: "boolean"
  30792. },
  30793. {
  30794. name: "noEmitOnError",
  30795. type: "boolean",
  30796. description: ts.Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported
  30797. },
  30798. {
  30799. name: "noImplicitAny",
  30800. type: "boolean",
  30801. description: ts.Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type
  30802. },
  30803. {
  30804. name: "noLib",
  30805. type: "boolean"
  30806. },
  30807. {
  30808. name: "noResolve",
  30809. type: "boolean"
  30810. },
  30811. {
  30812. name: "skipDefaultLibCheck",
  30813. type: "boolean"
  30814. },
  30815. {
  30816. name: "out",
  30817. type: "string",
  30818. isFilePath: false,
  30819. paramType: ts.Diagnostics.FILE
  30820. },
  30821. {
  30822. name: "outFile",
  30823. type: "string",
  30824. isFilePath: true,
  30825. description: ts.Diagnostics.Concatenate_and_emit_output_to_single_file,
  30826. paramType: ts.Diagnostics.FILE
  30827. },
  30828. {
  30829. name: "outDir",
  30830. type: "string",
  30831. isFilePath: true,
  30832. description: ts.Diagnostics.Redirect_output_structure_to_the_directory,
  30833. paramType: ts.Diagnostics.DIRECTORY
  30834. },
  30835. {
  30836. name: "preserveConstEnums",
  30837. type: "boolean",
  30838. description: ts.Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
  30839. },
  30840. {
  30841. name: "project",
  30842. shortName: "p",
  30843. type: "string",
  30844. isFilePath: true,
  30845. description: ts.Diagnostics.Compile_the_project_in_the_given_directory,
  30846. paramType: ts.Diagnostics.DIRECTORY
  30847. },
  30848. {
  30849. name: "removeComments",
  30850. type: "boolean",
  30851. description: ts.Diagnostics.Do_not_emit_comments_to_output
  30852. },
  30853. {
  30854. name: "rootDir",
  30855. type: "string",
  30856. isFilePath: true,
  30857. description: ts.Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
  30858. paramType: ts.Diagnostics.LOCATION
  30859. },
  30860. {
  30861. name: "isolatedModules",
  30862. type: "boolean"
  30863. },
  30864. {
  30865. name: "sourceMap",
  30866. type: "boolean",
  30867. description: ts.Diagnostics.Generates_corresponding_map_file
  30868. },
  30869. {
  30870. name: "sourceRoot",
  30871. type: "string",
  30872. isFilePath: true,
  30873. description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
  30874. paramType: ts.Diagnostics.LOCATION
  30875. },
  30876. {
  30877. name: "suppressExcessPropertyErrors",
  30878. type: "boolean",
  30879. description: ts.Diagnostics.Suppress_excess_property_checks_for_object_literals,
  30880. experimental: true
  30881. },
  30882. {
  30883. name: "suppressImplicitAnyIndexErrors",
  30884. type: "boolean",
  30885. description: ts.Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures
  30886. },
  30887. {
  30888. name: "stripInternal",
  30889. type: "boolean",
  30890. description: ts.Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
  30891. experimental: true
  30892. },
  30893. {
  30894. name: "target",
  30895. shortName: "t",
  30896. type: {
  30897. "es3": 0,
  30898. "es5": 1,
  30899. "es6": 2,
  30900. "es2015": 2
  30901. },
  30902. description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental,
  30903. paramType: ts.Diagnostics.VERSION,
  30904. error: ts.Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6
  30905. },
  30906. {
  30907. name: "version",
  30908. shortName: "v",
  30909. type: "boolean",
  30910. description: ts.Diagnostics.Print_the_compiler_s_version
  30911. },
  30912. {
  30913. name: "watch",
  30914. shortName: "w",
  30915. type: "boolean",
  30916. description: ts.Diagnostics.Watch_input_files
  30917. },
  30918. {
  30919. name: "experimentalDecorators",
  30920. type: "boolean",
  30921. description: ts.Diagnostics.Enables_experimental_support_for_ES7_decorators
  30922. },
  30923. {
  30924. name: "emitDecoratorMetadata",
  30925. type: "boolean",
  30926. experimental: true,
  30927. description: ts.Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
  30928. },
  30929. {
  30930. name: "moduleResolution",
  30931. type: {
  30932. "node": 2,
  30933. "classic": 1
  30934. },
  30935. description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
  30936. error: ts.Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic
  30937. }
  30938. ];
  30939. var optionNameMapCache;
  30940. function getOptionNameMap() {
  30941. if (optionNameMapCache) {
  30942. return optionNameMapCache;
  30943. }
  30944. var optionNameMap = {};
  30945. var shortOptionNames = {};
  30946. ts.forEach(ts.optionDeclarations, function (option) {
  30947. optionNameMap[option.name.toLowerCase()] = option;
  30948. if (option.shortName) {
  30949. shortOptionNames[option.shortName] = option.name;
  30950. }
  30951. });
  30952. optionNameMapCache = { optionNameMap: optionNameMap, shortOptionNames: shortOptionNames };
  30953. return optionNameMapCache;
  30954. }
  30955. ts.getOptionNameMap = getOptionNameMap;
  30956. function parseCommandLine(commandLine, readFile) {
  30957. var options = {};
  30958. var fileNames = [];
  30959. var errors = [];
  30960. var _a = getOptionNameMap(), optionNameMap = _a.optionNameMap, shortOptionNames = _a.shortOptionNames;
  30961. parseStrings(commandLine);
  30962. return {
  30963. options: options,
  30964. fileNames: fileNames,
  30965. errors: errors
  30966. };
  30967. function parseStrings(args) {
  30968. var i = 0;
  30969. while (i < args.length) {
  30970. var s = args[i++];
  30971. if (s.charCodeAt(0) === 64) {
  30972. parseResponseFile(s.slice(1));
  30973. }
  30974. else if (s.charCodeAt(0) === 45) {
  30975. s = s.slice(s.charCodeAt(1) === 45 ? 2 : 1).toLowerCase();
  30976. if (ts.hasProperty(shortOptionNames, s)) {
  30977. s = shortOptionNames[s];
  30978. }
  30979. if (ts.hasProperty(optionNameMap, s)) {
  30980. var opt = optionNameMap[s];
  30981. if (!args[i] && opt.type !== "boolean") {
  30982. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_expects_an_argument, opt.name));
  30983. }
  30984. switch (opt.type) {
  30985. case "number":
  30986. options[opt.name] = parseInt(args[i++]);
  30987. break;
  30988. case "boolean":
  30989. options[opt.name] = true;
  30990. break;
  30991. case "string":
  30992. options[opt.name] = args[i++] || "";
  30993. break;
  30994. default:
  30995. var map_2 = opt.type;
  30996. var key = (args[i++] || "").toLowerCase();
  30997. if (ts.hasProperty(map_2, key)) {
  30998. options[opt.name] = map_2[key];
  30999. }
  31000. else {
  31001. errors.push(ts.createCompilerDiagnostic(opt.error));
  31002. }
  31003. }
  31004. }
  31005. else {
  31006. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, s));
  31007. }
  31008. }
  31009. else {
  31010. fileNames.push(s);
  31011. }
  31012. }
  31013. }
  31014. function parseResponseFile(fileName) {
  31015. var text = readFile ? readFile(fileName) : ts.sys.readFile(fileName);
  31016. if (!text) {
  31017. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_not_found, fileName));
  31018. return;
  31019. }
  31020. var args = [];
  31021. var pos = 0;
  31022. while (true) {
  31023. while (pos < text.length && text.charCodeAt(pos) <= 32)
  31024. pos++;
  31025. if (pos >= text.length)
  31026. break;
  31027. var start = pos;
  31028. if (text.charCodeAt(start) === 34) {
  31029. pos++;
  31030. while (pos < text.length && text.charCodeAt(pos) !== 34)
  31031. pos++;
  31032. if (pos < text.length) {
  31033. args.push(text.substring(start + 1, pos));
  31034. pos++;
  31035. }
  31036. else {
  31037. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unterminated_quoted_string_in_response_file_0, fileName));
  31038. }
  31039. }
  31040. else {
  31041. while (text.charCodeAt(pos) > 32)
  31042. pos++;
  31043. args.push(text.substring(start, pos));
  31044. }
  31045. }
  31046. parseStrings(args);
  31047. }
  31048. }
  31049. ts.parseCommandLine = parseCommandLine;
  31050. function readConfigFile(fileName, readFile) {
  31051. var text = "";
  31052. try {
  31053. text = readFile(fileName);
  31054. }
  31055. catch (e) {
  31056. return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
  31057. }
  31058. return parseConfigFileTextToJson(fileName, text);
  31059. }
  31060. ts.readConfigFile = readConfigFile;
  31061. function parseConfigFileTextToJson(fileName, jsonText) {
  31062. try {
  31063. return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} };
  31064. }
  31065. catch (e) {
  31066. return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) };
  31067. }
  31068. }
  31069. ts.parseConfigFileTextToJson = parseConfigFileTextToJson;
  31070. function parseJsonConfigFileContent(json, host, basePath) {
  31071. var errors = [];
  31072. return {
  31073. options: getCompilerOptions(),
  31074. fileNames: getFileNames(),
  31075. errors: errors
  31076. };
  31077. function getCompilerOptions() {
  31078. var options = {};
  31079. var optionNameMap = {};
  31080. ts.forEach(ts.optionDeclarations, function (option) {
  31081. optionNameMap[option.name] = option;
  31082. });
  31083. var jsonOptions = json["compilerOptions"];
  31084. if (jsonOptions) {
  31085. for (var id in jsonOptions) {
  31086. if (ts.hasProperty(optionNameMap, id)) {
  31087. var opt = optionNameMap[id];
  31088. var optType = opt.type;
  31089. var value = jsonOptions[id];
  31090. var expectedType = typeof optType === "string" ? optType : "string";
  31091. if (typeof value === expectedType) {
  31092. if (typeof optType !== "string") {
  31093. var key = value.toLowerCase();
  31094. if (ts.hasProperty(optType, key)) {
  31095. value = optType[key];
  31096. }
  31097. else {
  31098. errors.push(ts.createCompilerDiagnostic(opt.error));
  31099. value = 0;
  31100. }
  31101. }
  31102. if (opt.isFilePath) {
  31103. value = ts.normalizePath(ts.combinePaths(basePath, value));
  31104. if (value === "") {
  31105. value = ".";
  31106. }
  31107. }
  31108. options[opt.name] = value;
  31109. }
  31110. else {
  31111. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType));
  31112. }
  31113. }
  31114. else {
  31115. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, id));
  31116. }
  31117. }
  31118. }
  31119. return options;
  31120. }
  31121. function getFileNames() {
  31122. var fileNames = [];
  31123. if (ts.hasProperty(json, "files")) {
  31124. if (json["files"] instanceof Array) {
  31125. fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); });
  31126. }
  31127. else {
  31128. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "files", "Array"));
  31129. }
  31130. }
  31131. else {
  31132. var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined;
  31133. var sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
  31134. for (var i = 0; i < sysFiles.length; i++) {
  31135. var name_28 = sysFiles[i];
  31136. if (ts.fileExtensionIs(name_28, ".d.ts")) {
  31137. var baseName = name_28.substr(0, name_28.length - ".d.ts".length);
  31138. if (!ts.contains(sysFiles, baseName + ".tsx") && !ts.contains(sysFiles, baseName + ".ts")) {
  31139. fileNames.push(name_28);
  31140. }
  31141. }
  31142. else if (ts.fileExtensionIs(name_28, ".ts")) {
  31143. if (!ts.contains(sysFiles, name_28 + "x")) {
  31144. fileNames.push(name_28);
  31145. }
  31146. }
  31147. else {
  31148. fileNames.push(name_28);
  31149. }
  31150. }
  31151. }
  31152. return fileNames;
  31153. }
  31154. }
  31155. ts.parseJsonConfigFileContent = parseJsonConfigFileContent;
  31156. })(ts || (ts = {}));
  31157. var ts;
  31158. (function (ts) {
  31159. function validateLocaleAndSetLanguage(locale, errors) {
  31160. var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
  31161. if (!matchResult) {
  31162. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, "en", "ja-jp"));
  31163. return false;
  31164. }
  31165. var language = matchResult[1];
  31166. var territory = matchResult[3];
  31167. if (!trySetLanguageAndTerritory(language, territory, errors) &&
  31168. !trySetLanguageAndTerritory(language, undefined, errors)) {
  31169. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_locale_0, locale));
  31170. return false;
  31171. }
  31172. return true;
  31173. }
  31174. function trySetLanguageAndTerritory(language, territory, errors) {
  31175. var compilerFilePath = ts.normalizePath(ts.sys.getExecutingFilePath());
  31176. var containingDirectoryPath = ts.getDirectoryPath(compilerFilePath);
  31177. var filePath = ts.combinePaths(containingDirectoryPath, language);
  31178. if (territory) {
  31179. filePath = filePath + "-" + territory;
  31180. }
  31181. filePath = ts.sys.resolvePath(ts.combinePaths(filePath, "diagnosticMessages.generated.json"));
  31182. if (!ts.sys.fileExists(filePath)) {
  31183. return false;
  31184. }
  31185. var fileContents = "";
  31186. try {
  31187. fileContents = ts.sys.readFile(filePath);
  31188. }
  31189. catch (e) {
  31190. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unable_to_open_file_0, filePath));
  31191. return false;
  31192. }
  31193. try {
  31194. ts.localizedDiagnosticMessages = JSON.parse(fileContents);
  31195. }
  31196. catch (e) {
  31197. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Corrupted_locale_file_0, filePath));
  31198. return false;
  31199. }
  31200. return true;
  31201. }
  31202. function countLines(program) {
  31203. var count = 0;
  31204. ts.forEach(program.getSourceFiles(), function (file) {
  31205. count += ts.getLineStarts(file).length;
  31206. });
  31207. return count;
  31208. }
  31209. function getDiagnosticText(message) {
  31210. var args = [];
  31211. for (var _i = 1; _i < arguments.length; _i++) {
  31212. args[_i - 1] = arguments[_i];
  31213. }
  31214. var diagnostic = ts.createCompilerDiagnostic.apply(undefined, arguments);
  31215. return diagnostic.messageText;
  31216. }
  31217. function reportDiagnostic(diagnostic) {
  31218. var output = "";
  31219. if (diagnostic.file) {
  31220. var loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
  31221. output += diagnostic.file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + "): ";
  31222. }
  31223. var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase();
  31224. output += category + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
  31225. ts.sys.write(output);
  31226. }
  31227. function reportDiagnostics(diagnostics) {
  31228. for (var i = 0; i < diagnostics.length; i++) {
  31229. reportDiagnostic(diagnostics[i]);
  31230. }
  31231. }
  31232. function reportWatchDiagnostic(diagnostic) {
  31233. var output = new Date().toLocaleTimeString() + " - ";
  31234. if (diagnostic.file) {
  31235. var loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
  31236. output += diagnostic.file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + "): ";
  31237. }
  31238. output += "" + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
  31239. ts.sys.write(output);
  31240. }
  31241. function padLeft(s, length) {
  31242. while (s.length < length) {
  31243. s = " " + s;
  31244. }
  31245. return s;
  31246. }
  31247. function padRight(s, length) {
  31248. while (s.length < length) {
  31249. s = s + " ";
  31250. }
  31251. return s;
  31252. }
  31253. function reportStatisticalValue(name, value) {
  31254. ts.sys.write(padRight(name + ":", 12) + padLeft(value.toString(), 10) + ts.sys.newLine);
  31255. }
  31256. function reportCountStatistic(name, count) {
  31257. reportStatisticalValue(name, "" + count);
  31258. }
  31259. function reportTimeStatistic(name, time) {
  31260. reportStatisticalValue(name, (time / 1000).toFixed(2) + "s");
  31261. }
  31262. function isJSONSupported() {
  31263. return typeof JSON === "object" && typeof JSON.parse === "function";
  31264. }
  31265. function executeCommandLine(args) {
  31266. var commandLine = ts.parseCommandLine(args);
  31267. var configFileName;
  31268. var cachedConfigFileText;
  31269. var configFileWatcher;
  31270. var directoryWatcher;
  31271. var cachedProgram;
  31272. var rootFileNames;
  31273. var compilerOptions;
  31274. var compilerHost;
  31275. var hostGetSourceFile;
  31276. var timerHandleForRecompilation;
  31277. var timerHandleForDirectoryChanges;
  31278. if (commandLine.options.locale) {
  31279. if (!isJSONSupported()) {
  31280. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"));
  31281. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  31282. }
  31283. validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors);
  31284. }
  31285. if (commandLine.errors.length > 0) {
  31286. reportDiagnostics(commandLine.errors);
  31287. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  31288. }
  31289. if (commandLine.options.init) {
  31290. writeConfigFile(commandLine.options, commandLine.fileNames);
  31291. return ts.sys.exit(ts.ExitStatus.Success);
  31292. }
  31293. if (commandLine.options.version) {
  31294. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Version_0, ts.version));
  31295. return ts.sys.exit(ts.ExitStatus.Success);
  31296. }
  31297. if (commandLine.options.help) {
  31298. printVersion();
  31299. printHelp();
  31300. return ts.sys.exit(ts.ExitStatus.Success);
  31301. }
  31302. if (commandLine.options.project) {
  31303. if (!isJSONSupported()) {
  31304. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--project"));
  31305. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  31306. }
  31307. configFileName = ts.normalizePath(ts.combinePaths(commandLine.options.project, "tsconfig.json"));
  31308. if (commandLine.fileNames.length !== 0) {
  31309. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
  31310. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  31311. }
  31312. }
  31313. else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
  31314. var searchPath = ts.normalizePath(ts.sys.getCurrentDirectory());
  31315. configFileName = ts.findConfigFile(searchPath);
  31316. }
  31317. if (commandLine.fileNames.length === 0 && !configFileName) {
  31318. printVersion();
  31319. printHelp();
  31320. return ts.sys.exit(ts.ExitStatus.Success);
  31321. }
  31322. if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) {
  31323. if (!ts.sys.watchFile) {
  31324. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"));
  31325. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  31326. }
  31327. if (configFileName) {
  31328. configFileWatcher = ts.sys.watchFile(configFileName, configFileChanged);
  31329. }
  31330. if (ts.sys.watchDirectory && configFileName) {
  31331. var directory = ts.getDirectoryPath(configFileName);
  31332. directoryWatcher = ts.sys.watchDirectory(directory == "" ? "." : directory, watchedDirectoryChanged, true);
  31333. }
  31334. }
  31335. performCompilation();
  31336. function parseConfigFile() {
  31337. if (!cachedConfigFileText) {
  31338. try {
  31339. cachedConfigFileText = ts.sys.readFile(configFileName);
  31340. }
  31341. catch (e) {
  31342. var error = ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, configFileName, e.message);
  31343. reportWatchDiagnostic(error);
  31344. ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  31345. return;
  31346. }
  31347. }
  31348. var result = ts.parseConfigFileTextToJson(configFileName, cachedConfigFileText);
  31349. var configObject = result.config;
  31350. var configParseResult = ts.parseJsonConfigFileContent(configObject, ts.sys, ts.getDirectoryPath(configFileName));
  31351. if (configParseResult.errors.length > 0) {
  31352. reportDiagnostics(configParseResult.errors);
  31353. ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  31354. return;
  31355. }
  31356. return configParseResult;
  31357. }
  31358. function performCompilation() {
  31359. if (!cachedProgram) {
  31360. if (configFileName) {
  31361. var configParseResult = parseConfigFile();
  31362. rootFileNames = configParseResult.fileNames;
  31363. compilerOptions = ts.extend(commandLine.options, configParseResult.options);
  31364. }
  31365. else {
  31366. rootFileNames = commandLine.fileNames;
  31367. compilerOptions = commandLine.options;
  31368. }
  31369. compilerHost = ts.createCompilerHost(compilerOptions);
  31370. hostGetSourceFile = compilerHost.getSourceFile;
  31371. compilerHost.getSourceFile = getSourceFile;
  31372. }
  31373. var compileResult = compile(rootFileNames, compilerOptions, compilerHost);
  31374. if (!compilerOptions.watch) {
  31375. return ts.sys.exit(compileResult.exitStatus);
  31376. }
  31377. setCachedProgram(compileResult.program);
  31378. reportWatchDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes));
  31379. }
  31380. function getSourceFile(fileName, languageVersion, onError) {
  31381. if (cachedProgram) {
  31382. var sourceFile_1 = cachedProgram.getSourceFile(fileName);
  31383. if (sourceFile_1 && sourceFile_1.fileWatcher) {
  31384. return sourceFile_1;
  31385. }
  31386. }
  31387. var sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
  31388. if (sourceFile && compilerOptions.watch) {
  31389. sourceFile.fileWatcher = ts.sys.watchFile(sourceFile.fileName, function (fileName, removed) { return sourceFileChanged(sourceFile, removed); });
  31390. }
  31391. return sourceFile;
  31392. }
  31393. function setCachedProgram(program) {
  31394. if (cachedProgram) {
  31395. var newSourceFiles = program ? program.getSourceFiles() : undefined;
  31396. ts.forEach(cachedProgram.getSourceFiles(), function (sourceFile) {
  31397. if (!(newSourceFiles && ts.contains(newSourceFiles, sourceFile))) {
  31398. if (sourceFile.fileWatcher) {
  31399. sourceFile.fileWatcher.close();
  31400. sourceFile.fileWatcher = undefined;
  31401. }
  31402. }
  31403. });
  31404. }
  31405. cachedProgram = program;
  31406. }
  31407. function sourceFileChanged(sourceFile, removed) {
  31408. sourceFile.fileWatcher.close();
  31409. sourceFile.fileWatcher = undefined;
  31410. if (removed) {
  31411. var index = rootFileNames.indexOf(sourceFile.fileName);
  31412. if (index >= 0) {
  31413. rootFileNames.splice(index, 1);
  31414. }
  31415. }
  31416. startTimerForRecompilation();
  31417. }
  31418. function configFileChanged() {
  31419. setCachedProgram(undefined);
  31420. cachedConfigFileText = undefined;
  31421. startTimerForRecompilation();
  31422. }
  31423. function watchedDirectoryChanged(fileName) {
  31424. if (fileName && !ts.isSupportedSourceFileName(fileName)) {
  31425. return;
  31426. }
  31427. startTimerForHandlingDirectoryChanges();
  31428. }
  31429. function startTimerForHandlingDirectoryChanges() {
  31430. if (timerHandleForDirectoryChanges) {
  31431. clearTimeout(timerHandleForDirectoryChanges);
  31432. }
  31433. timerHandleForDirectoryChanges = setTimeout(directoryChangeHandler, 250);
  31434. }
  31435. function directoryChangeHandler() {
  31436. var parsedCommandLine = parseConfigFile();
  31437. var newFileNames = ts.map(parsedCommandLine.fileNames, compilerHost.getCanonicalFileName);
  31438. var canonicalRootFileNames = ts.map(rootFileNames, compilerHost.getCanonicalFileName);
  31439. if (!ts.arrayStructurallyIsEqualTo(newFileNames, canonicalRootFileNames)) {
  31440. setCachedProgram(undefined);
  31441. startTimerForRecompilation();
  31442. }
  31443. }
  31444. function startTimerForRecompilation() {
  31445. if (timerHandleForRecompilation) {
  31446. clearTimeout(timerHandleForRecompilation);
  31447. }
  31448. timerHandleForRecompilation = setTimeout(recompile, 250);
  31449. }
  31450. function recompile() {
  31451. timerHandleForRecompilation = undefined;
  31452. reportWatchDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation));
  31453. performCompilation();
  31454. }
  31455. }
  31456. ts.executeCommandLine = executeCommandLine;
  31457. function compile(fileNames, compilerOptions, compilerHost) {
  31458. ts.ioReadTime = 0;
  31459. ts.ioWriteTime = 0;
  31460. ts.programTime = 0;
  31461. ts.bindTime = 0;
  31462. ts.checkTime = 0;
  31463. ts.emitTime = 0;
  31464. var program = ts.createProgram(fileNames, compilerOptions, compilerHost);
  31465. var exitStatus = compileProgram();
  31466. if (compilerOptions.listFiles) {
  31467. ts.forEach(program.getSourceFiles(), function (file) {
  31468. ts.sys.write(file.fileName + ts.sys.newLine);
  31469. });
  31470. }
  31471. if (compilerOptions.diagnostics) {
  31472. var memoryUsed = ts.sys.getMemoryUsage ? ts.sys.getMemoryUsage() : -1;
  31473. reportCountStatistic("Files", program.getSourceFiles().length);
  31474. reportCountStatistic("Lines", countLines(program));
  31475. reportCountStatistic("Nodes", program.getNodeCount());
  31476. reportCountStatistic("Identifiers", program.getIdentifierCount());
  31477. reportCountStatistic("Symbols", program.getSymbolCount());
  31478. reportCountStatistic("Types", program.getTypeCount());
  31479. if (memoryUsed >= 0) {
  31480. reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K");
  31481. }
  31482. reportTimeStatistic("I/O read", ts.ioReadTime);
  31483. reportTimeStatistic("I/O write", ts.ioWriteTime);
  31484. reportTimeStatistic("Parse time", ts.programTime);
  31485. reportTimeStatistic("Bind time", ts.bindTime);
  31486. reportTimeStatistic("Check time", ts.checkTime);
  31487. reportTimeStatistic("Emit time", ts.emitTime);
  31488. reportTimeStatistic("Total time", ts.programTime + ts.bindTime + ts.checkTime + ts.emitTime);
  31489. }
  31490. return { program: program, exitStatus: exitStatus };
  31491. function compileProgram() {
  31492. var diagnostics;
  31493. diagnostics = program.getSyntacticDiagnostics();
  31494. if (diagnostics.length === 0) {
  31495. diagnostics = program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics());
  31496. if (diagnostics.length === 0) {
  31497. diagnostics = program.getSemanticDiagnostics();
  31498. }
  31499. }
  31500. reportDiagnostics(diagnostics);
  31501. if (compilerOptions.noEmit) {
  31502. return diagnostics.length
  31503. ? ts.ExitStatus.DiagnosticsPresent_OutputsSkipped
  31504. : ts.ExitStatus.Success;
  31505. }
  31506. var emitOutput = program.emit();
  31507. reportDiagnostics(emitOutput.diagnostics);
  31508. if (emitOutput.emitSkipped) {
  31509. return ts.ExitStatus.DiagnosticsPresent_OutputsSkipped;
  31510. }
  31511. if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) {
  31512. return ts.ExitStatus.DiagnosticsPresent_OutputsGenerated;
  31513. }
  31514. return ts.ExitStatus.Success;
  31515. }
  31516. }
  31517. function printVersion() {
  31518. ts.sys.write(getDiagnosticText(ts.Diagnostics.Version_0, ts.version) + ts.sys.newLine);
  31519. }
  31520. function printHelp() {
  31521. var output = "";
  31522. var syntaxLength = getDiagnosticText(ts.Diagnostics.Syntax_Colon_0, "").length;
  31523. var examplesLength = getDiagnosticText(ts.Diagnostics.Examples_Colon_0, "").length;
  31524. var marginLength = Math.max(syntaxLength, examplesLength);
  31525. var syntax = makePadding(marginLength - syntaxLength);
  31526. syntax += "tsc [" + getDiagnosticText(ts.Diagnostics.options) + "] [" + getDiagnosticText(ts.Diagnostics.file) + " ...]";
  31527. output += getDiagnosticText(ts.Diagnostics.Syntax_Colon_0, syntax);
  31528. output += ts.sys.newLine + ts.sys.newLine;
  31529. var padding = makePadding(marginLength);
  31530. output += getDiagnosticText(ts.Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + ts.sys.newLine;
  31531. output += padding + "tsc --out file.js file.ts" + ts.sys.newLine;
  31532. output += padding + "tsc @args.txt" + ts.sys.newLine;
  31533. output += ts.sys.newLine;
  31534. output += getDiagnosticText(ts.Diagnostics.Options_Colon) + ts.sys.newLine;
  31535. var optsList = ts.filter(ts.optionDeclarations.slice(), function (v) { return !v.experimental; });
  31536. optsList.sort(function (a, b) { return ts.compareValues(a.name.toLowerCase(), b.name.toLowerCase()); });
  31537. marginLength = 0;
  31538. var usageColumn = [];
  31539. var descriptionColumn = [];
  31540. for (var i = 0; i < optsList.length; i++) {
  31541. var option = optsList[i];
  31542. if (!option.description) {
  31543. continue;
  31544. }
  31545. var usageText_1 = " ";
  31546. if (option.shortName) {
  31547. usageText_1 += "-" + option.shortName;
  31548. usageText_1 += getParamType(option);
  31549. usageText_1 += ", ";
  31550. }
  31551. usageText_1 += "--" + option.name;
  31552. usageText_1 += getParamType(option);
  31553. usageColumn.push(usageText_1);
  31554. descriptionColumn.push(getDiagnosticText(option.description));
  31555. marginLength = Math.max(usageText_1.length, marginLength);
  31556. }
  31557. var usageText = " @<" + getDiagnosticText(ts.Diagnostics.file) + ">";
  31558. usageColumn.push(usageText);
  31559. descriptionColumn.push(getDiagnosticText(ts.Diagnostics.Insert_command_line_options_and_files_from_a_file));
  31560. marginLength = Math.max(usageText.length, marginLength);
  31561. for (var i = 0; i < usageColumn.length; i++) {
  31562. var usage = usageColumn[i];
  31563. var description = descriptionColumn[i];
  31564. output += usage + makePadding(marginLength - usage.length + 2) + description + ts.sys.newLine;
  31565. }
  31566. ts.sys.write(output);
  31567. return;
  31568. function getParamType(option) {
  31569. if (option.paramType !== undefined) {
  31570. return " " + getDiagnosticText(option.paramType);
  31571. }
  31572. return "";
  31573. }
  31574. function makePadding(paddingLength) {
  31575. return Array(paddingLength + 1).join(" ");
  31576. }
  31577. }
  31578. function writeConfigFile(options, fileNames) {
  31579. var currentDirectory = ts.sys.getCurrentDirectory();
  31580. var file = ts.combinePaths(currentDirectory, "tsconfig.json");
  31581. if (ts.sys.fileExists(file)) {
  31582. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file));
  31583. }
  31584. else {
  31585. var compilerOptions = ts.extend(options, ts.defaultInitCompilerOptions);
  31586. var configurations = {
  31587. compilerOptions: serializeCompilerOptions(compilerOptions),
  31588. exclude: ["node_modules"]
  31589. };
  31590. if (fileNames && fileNames.length) {
  31591. configurations.files = fileNames;
  31592. }
  31593. ts.sys.writeFile(file, JSON.stringify(configurations, undefined, 4));
  31594. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Successfully_created_a_tsconfig_json_file));
  31595. }
  31596. return;
  31597. function serializeCompilerOptions(options) {
  31598. var result = {};
  31599. var optionsNameMap = ts.getOptionNameMap().optionNameMap;
  31600. for (var name_29 in options) {
  31601. if (ts.hasProperty(options, name_29)) {
  31602. var value = options[name_29];
  31603. switch (name_29) {
  31604. case "init":
  31605. case "watch":
  31606. case "version":
  31607. case "help":
  31608. case "project":
  31609. break;
  31610. default:
  31611. var optionDefinition = optionsNameMap[name_29.toLowerCase()];
  31612. if (optionDefinition) {
  31613. if (typeof optionDefinition.type === "string") {
  31614. result[name_29] = value;
  31615. }
  31616. else {
  31617. var typeMap = optionDefinition.type;
  31618. for (var key in typeMap) {
  31619. if (ts.hasProperty(typeMap, key)) {
  31620. if (typeMap[key] === value)
  31621. result[name_29] = key;
  31622. }
  31623. }
  31624. }
  31625. }
  31626. break;
  31627. }
  31628. }
  31629. }
  31630. return result;
  31631. }
  31632. }
  31633. })(ts || (ts = {}));
  31634. ts.executeCommandLine(ts.sys.args);