tsc.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079
  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. /// <reference path="types.ts"/>
  48. var ts;
  49. (function (ts) {
  50. function createFileMap(getCanonicalFileName) {
  51. var files = {};
  52. return {
  53. get: get,
  54. set: set,
  55. contains: contains,
  56. remove: remove,
  57. clear: clear,
  58. forEachValue: forEachValueInMap
  59. };
  60. function set(fileName, value) {
  61. files[normalizeKey(fileName)] = value;
  62. }
  63. function get(fileName) {
  64. return files[normalizeKey(fileName)];
  65. }
  66. function contains(fileName) {
  67. return hasProperty(files, normalizeKey(fileName));
  68. }
  69. function remove(fileName) {
  70. var key = normalizeKey(fileName);
  71. delete files[key];
  72. }
  73. function forEachValueInMap(f) {
  74. forEachValue(files, f);
  75. }
  76. function normalizeKey(key) {
  77. return getCanonicalFileName(normalizeSlashes(key));
  78. }
  79. function clear() {
  80. files = {};
  81. }
  82. }
  83. ts.createFileMap = createFileMap;
  84. function forEach(array, callback) {
  85. if (array) {
  86. for (var i = 0, len = array.length; i < len; i++) {
  87. var result = callback(array[i], i);
  88. if (result) {
  89. return result;
  90. }
  91. }
  92. }
  93. return undefined;
  94. }
  95. ts.forEach = forEach;
  96. function contains(array, value) {
  97. if (array) {
  98. for (var _i = 0; _i < array.length; _i++) {
  99. var v = array[_i];
  100. if (v === value) {
  101. return true;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. ts.contains = contains;
  108. function indexOf(array, value) {
  109. if (array) {
  110. for (var i = 0, len = array.length; i < len; i++) {
  111. if (array[i] === value) {
  112. return i;
  113. }
  114. }
  115. }
  116. return -1;
  117. }
  118. ts.indexOf = indexOf;
  119. function countWhere(array, predicate) {
  120. var count = 0;
  121. if (array) {
  122. for (var _i = 0; _i < array.length; _i++) {
  123. var v = array[_i];
  124. if (predicate(v)) {
  125. count++;
  126. }
  127. }
  128. }
  129. return count;
  130. }
  131. ts.countWhere = countWhere;
  132. function filter(array, f) {
  133. var result;
  134. if (array) {
  135. result = [];
  136. for (var _i = 0; _i < array.length; _i++) {
  137. var item = array[_i];
  138. if (f(item)) {
  139. result.push(item);
  140. }
  141. }
  142. }
  143. return result;
  144. }
  145. ts.filter = filter;
  146. function map(array, f) {
  147. var result;
  148. if (array) {
  149. result = [];
  150. for (var _i = 0; _i < array.length; _i++) {
  151. var v = array[_i];
  152. result.push(f(v));
  153. }
  154. }
  155. return result;
  156. }
  157. ts.map = map;
  158. function concatenate(array1, array2) {
  159. if (!array2 || !array2.length)
  160. return array1;
  161. if (!array1 || !array1.length)
  162. return array2;
  163. return array1.concat(array2);
  164. }
  165. ts.concatenate = concatenate;
  166. function deduplicate(array) {
  167. var result;
  168. if (array) {
  169. result = [];
  170. for (var _i = 0; _i < array.length; _i++) {
  171. var item = array[_i];
  172. if (!contains(result, item)) {
  173. result.push(item);
  174. }
  175. }
  176. }
  177. return result;
  178. }
  179. ts.deduplicate = deduplicate;
  180. function sum(array, prop) {
  181. var result = 0;
  182. for (var _i = 0; _i < array.length; _i++) {
  183. var v = array[_i];
  184. result += v[prop];
  185. }
  186. return result;
  187. }
  188. ts.sum = sum;
  189. function addRange(to, from) {
  190. if (to && from) {
  191. for (var _i = 0; _i < from.length; _i++) {
  192. var v = from[_i];
  193. to.push(v);
  194. }
  195. }
  196. }
  197. ts.addRange = addRange;
  198. function rangeEquals(array1, array2, pos, end) {
  199. while (pos < end) {
  200. if (array1[pos] !== array2[pos]) {
  201. return false;
  202. }
  203. pos++;
  204. }
  205. return true;
  206. }
  207. ts.rangeEquals = rangeEquals;
  208. function lastOrUndefined(array) {
  209. if (array.length === 0) {
  210. return undefined;
  211. }
  212. return array[array.length - 1];
  213. }
  214. ts.lastOrUndefined = lastOrUndefined;
  215. function binarySearch(array, value) {
  216. var low = 0;
  217. var high = array.length - 1;
  218. while (low <= high) {
  219. var middle = low + ((high - low) >> 1);
  220. var midValue = array[middle];
  221. if (midValue === value) {
  222. return middle;
  223. }
  224. else if (midValue > value) {
  225. high = middle - 1;
  226. }
  227. else {
  228. low = middle + 1;
  229. }
  230. }
  231. return ~low;
  232. }
  233. ts.binarySearch = binarySearch;
  234. function reduceLeft(array, f, initial) {
  235. if (array) {
  236. var count = array.length;
  237. if (count > 0) {
  238. var pos = 0;
  239. var result = arguments.length <= 2 ? array[pos++] : initial;
  240. while (pos < count) {
  241. result = f(result, array[pos++]);
  242. }
  243. return result;
  244. }
  245. }
  246. return initial;
  247. }
  248. ts.reduceLeft = reduceLeft;
  249. function reduceRight(array, f, initial) {
  250. if (array) {
  251. var pos = array.length - 1;
  252. if (pos >= 0) {
  253. var result = arguments.length <= 2 ? array[pos--] : initial;
  254. while (pos >= 0) {
  255. result = f(result, array[pos--]);
  256. }
  257. return result;
  258. }
  259. }
  260. return initial;
  261. }
  262. ts.reduceRight = reduceRight;
  263. var hasOwnProperty = Object.prototype.hasOwnProperty;
  264. function hasProperty(map, key) {
  265. return hasOwnProperty.call(map, key);
  266. }
  267. ts.hasProperty = hasProperty;
  268. function getProperty(map, key) {
  269. return hasOwnProperty.call(map, key) ? map[key] : undefined;
  270. }
  271. ts.getProperty = getProperty;
  272. function isEmpty(map) {
  273. for (var id in map) {
  274. if (hasProperty(map, id)) {
  275. return false;
  276. }
  277. }
  278. return true;
  279. }
  280. ts.isEmpty = isEmpty;
  281. function clone(object) {
  282. var result = {};
  283. for (var id in object) {
  284. result[id] = object[id];
  285. }
  286. return result;
  287. }
  288. ts.clone = clone;
  289. function extend(first, second) {
  290. var result = {};
  291. for (var id in first) {
  292. result[id] = first[id];
  293. }
  294. for (var id in second) {
  295. if (!hasProperty(result, id)) {
  296. result[id] = second[id];
  297. }
  298. }
  299. return result;
  300. }
  301. ts.extend = extend;
  302. function forEachValue(map, callback) {
  303. var result;
  304. for (var id in map) {
  305. if (result = callback(map[id]))
  306. break;
  307. }
  308. return result;
  309. }
  310. ts.forEachValue = forEachValue;
  311. function forEachKey(map, callback) {
  312. var result;
  313. for (var id in map) {
  314. if (result = callback(id))
  315. break;
  316. }
  317. return result;
  318. }
  319. ts.forEachKey = forEachKey;
  320. function lookUp(map, key) {
  321. return hasProperty(map, key) ? map[key] : undefined;
  322. }
  323. ts.lookUp = lookUp;
  324. function copyMap(source, target) {
  325. for (var p in source) {
  326. target[p] = source[p];
  327. }
  328. }
  329. ts.copyMap = copyMap;
  330. function arrayToMap(array, makeKey) {
  331. var result = {};
  332. forEach(array, function (value) {
  333. result[makeKey(value)] = value;
  334. });
  335. return result;
  336. }
  337. ts.arrayToMap = arrayToMap;
  338. function memoize(callback) {
  339. var value;
  340. return function () {
  341. if (callback) {
  342. value = callback();
  343. callback = undefined;
  344. }
  345. return value;
  346. };
  347. }
  348. ts.memoize = memoize;
  349. function formatStringFromArgs(text, args, baseIndex) {
  350. baseIndex = baseIndex || 0;
  351. return text.replace(/{(\d+)}/g, function (match, index) { return args[+index + baseIndex]; });
  352. }
  353. ts.localizedDiagnosticMessages = undefined;
  354. function getLocaleSpecificMessage(message) {
  355. return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message]
  356. ? ts.localizedDiagnosticMessages[message]
  357. : message;
  358. }
  359. ts.getLocaleSpecificMessage = getLocaleSpecificMessage;
  360. function createFileDiagnostic(file, start, length, message) {
  361. var end = start + length;
  362. Debug.assert(start >= 0, "start must be non-negative, is " + start);
  363. Debug.assert(length >= 0, "length must be non-negative, is " + length);
  364. if (file) {
  365. Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length);
  366. Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length);
  367. }
  368. var text = getLocaleSpecificMessage(message.key);
  369. if (arguments.length > 4) {
  370. text = formatStringFromArgs(text, arguments, 4);
  371. }
  372. return {
  373. file: file,
  374. start: start,
  375. length: length,
  376. messageText: text,
  377. category: message.category,
  378. code: message.code
  379. };
  380. }
  381. ts.createFileDiagnostic = createFileDiagnostic;
  382. function createCompilerDiagnostic(message) {
  383. var text = getLocaleSpecificMessage(message.key);
  384. if (arguments.length > 1) {
  385. text = formatStringFromArgs(text, arguments, 1);
  386. }
  387. return {
  388. file: undefined,
  389. start: undefined,
  390. length: undefined,
  391. messageText: text,
  392. category: message.category,
  393. code: message.code
  394. };
  395. }
  396. ts.createCompilerDiagnostic = createCompilerDiagnostic;
  397. function chainDiagnosticMessages(details, message) {
  398. var text = getLocaleSpecificMessage(message.key);
  399. if (arguments.length > 2) {
  400. text = formatStringFromArgs(text, arguments, 2);
  401. }
  402. return {
  403. messageText: text,
  404. category: message.category,
  405. code: message.code,
  406. next: details
  407. };
  408. }
  409. ts.chainDiagnosticMessages = chainDiagnosticMessages;
  410. function concatenateDiagnosticMessageChains(headChain, tailChain) {
  411. Debug.assert(!headChain.next);
  412. headChain.next = tailChain;
  413. return headChain;
  414. }
  415. ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains;
  416. function compareValues(a, b) {
  417. if (a === b)
  418. return 0;
  419. if (a === undefined)
  420. return -1;
  421. if (b === undefined)
  422. return 1;
  423. return a < b ? -1 : 1;
  424. }
  425. ts.compareValues = compareValues;
  426. function getDiagnosticFileName(diagnostic) {
  427. return diagnostic.file ? diagnostic.file.fileName : undefined;
  428. }
  429. function compareDiagnostics(d1, d2) {
  430. return compareValues(getDiagnosticFileName(d1), getDiagnosticFileName(d2)) ||
  431. compareValues(d1.start, d2.start) ||
  432. compareValues(d1.length, d2.length) ||
  433. compareValues(d1.code, d2.code) ||
  434. compareMessageText(d1.messageText, d2.messageText) ||
  435. 0;
  436. }
  437. ts.compareDiagnostics = compareDiagnostics;
  438. function compareMessageText(text1, text2) {
  439. while (text1 && text2) {
  440. var string1 = typeof text1 === "string" ? text1 : text1.messageText;
  441. var string2 = typeof text2 === "string" ? text2 : text2.messageText;
  442. var res = compareValues(string1, string2);
  443. if (res) {
  444. return res;
  445. }
  446. text1 = typeof text1 === "string" ? undefined : text1.next;
  447. text2 = typeof text2 === "string" ? undefined : text2.next;
  448. }
  449. if (!text1 && !text2) {
  450. return 0;
  451. }
  452. return text1 ? 1 : -1;
  453. }
  454. function sortAndDeduplicateDiagnostics(diagnostics) {
  455. return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics));
  456. }
  457. ts.sortAndDeduplicateDiagnostics = sortAndDeduplicateDiagnostics;
  458. function deduplicateSortedDiagnostics(diagnostics) {
  459. if (diagnostics.length < 2) {
  460. return diagnostics;
  461. }
  462. var newDiagnostics = [diagnostics[0]];
  463. var previousDiagnostic = diagnostics[0];
  464. for (var i = 1; i < diagnostics.length; i++) {
  465. var currentDiagnostic = diagnostics[i];
  466. var isDupe = compareDiagnostics(currentDiagnostic, previousDiagnostic) === 0;
  467. if (!isDupe) {
  468. newDiagnostics.push(currentDiagnostic);
  469. previousDiagnostic = currentDiagnostic;
  470. }
  471. }
  472. return newDiagnostics;
  473. }
  474. ts.deduplicateSortedDiagnostics = deduplicateSortedDiagnostics;
  475. function normalizeSlashes(path) {
  476. return path.replace(/\\/g, "/");
  477. }
  478. ts.normalizeSlashes = normalizeSlashes;
  479. function getRootLength(path) {
  480. if (path.charCodeAt(0) === 47) {
  481. if (path.charCodeAt(1) !== 47)
  482. return 1;
  483. var p1 = path.indexOf("/", 2);
  484. if (p1 < 0)
  485. return 2;
  486. var p2 = path.indexOf("/", p1 + 1);
  487. if (p2 < 0)
  488. return p1 + 1;
  489. return p2 + 1;
  490. }
  491. if (path.charCodeAt(1) === 58) {
  492. if (path.charCodeAt(2) === 47)
  493. return 3;
  494. return 2;
  495. }
  496. if (path.lastIndexOf("file:///", 0) === 0) {
  497. return "file:///".length;
  498. }
  499. var idx = path.indexOf("://");
  500. if (idx !== -1) {
  501. return idx + "://".length;
  502. }
  503. return 0;
  504. }
  505. ts.getRootLength = getRootLength;
  506. ts.directorySeparator = "/";
  507. function getNormalizedParts(normalizedSlashedPath, rootLength) {
  508. var parts = normalizedSlashedPath.substr(rootLength).split(ts.directorySeparator);
  509. var normalized = [];
  510. for (var _i = 0; _i < parts.length; _i++) {
  511. var part = parts[_i];
  512. if (part !== ".") {
  513. if (part === ".." && normalized.length > 0 && lastOrUndefined(normalized) !== "..") {
  514. normalized.pop();
  515. }
  516. else {
  517. if (part) {
  518. normalized.push(part);
  519. }
  520. }
  521. }
  522. }
  523. return normalized;
  524. }
  525. function normalizePath(path) {
  526. path = normalizeSlashes(path);
  527. var rootLength = getRootLength(path);
  528. var normalized = getNormalizedParts(path, rootLength);
  529. return path.substr(0, rootLength) + normalized.join(ts.directorySeparator);
  530. }
  531. ts.normalizePath = normalizePath;
  532. function getDirectoryPath(path) {
  533. return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(ts.directorySeparator)));
  534. }
  535. ts.getDirectoryPath = getDirectoryPath;
  536. function isUrl(path) {
  537. return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
  538. }
  539. ts.isUrl = isUrl;
  540. function isRootedDiskPath(path) {
  541. return getRootLength(path) !== 0;
  542. }
  543. ts.isRootedDiskPath = isRootedDiskPath;
  544. function normalizedPathComponents(path, rootLength) {
  545. var normalizedParts = getNormalizedParts(path, rootLength);
  546. return [path.substr(0, rootLength)].concat(normalizedParts);
  547. }
  548. function getNormalizedPathComponents(path, currentDirectory) {
  549. path = normalizeSlashes(path);
  550. var rootLength = getRootLength(path);
  551. if (rootLength === 0) {
  552. path = combinePaths(normalizeSlashes(currentDirectory), path);
  553. rootLength = getRootLength(path);
  554. }
  555. return normalizedPathComponents(path, rootLength);
  556. }
  557. ts.getNormalizedPathComponents = getNormalizedPathComponents;
  558. function getNormalizedAbsolutePath(fileName, currentDirectory) {
  559. return getNormalizedPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
  560. }
  561. ts.getNormalizedAbsolutePath = getNormalizedAbsolutePath;
  562. function getNormalizedPathFromPathComponents(pathComponents) {
  563. if (pathComponents && pathComponents.length) {
  564. return pathComponents[0] + pathComponents.slice(1).join(ts.directorySeparator);
  565. }
  566. }
  567. ts.getNormalizedPathFromPathComponents = getNormalizedPathFromPathComponents;
  568. function getNormalizedPathComponentsOfUrl(url) {
  569. // Get root length of http://www.website.com/folder1/foler2/
  570. // In this example the root is: http://www.website.com/
  571. // normalized path components should be ["http://www.website.com/", "folder1", "folder2"]
  572. var urlLength = url.length;
  573. var rootLength = url.indexOf("://") + "://".length;
  574. while (rootLength < urlLength) {
  575. if (url.charCodeAt(rootLength) === 47) {
  576. rootLength++;
  577. }
  578. else {
  579. break;
  580. }
  581. }
  582. if (rootLength === urlLength) {
  583. return [url];
  584. }
  585. var indexOfNextSlash = url.indexOf(ts.directorySeparator, rootLength);
  586. if (indexOfNextSlash !== -1) {
  587. rootLength = indexOfNextSlash + 1;
  588. return normalizedPathComponents(url, rootLength);
  589. }
  590. else {
  591. return [url + ts.directorySeparator];
  592. }
  593. }
  594. function getNormalizedPathOrUrlComponents(pathOrUrl, currentDirectory) {
  595. if (isUrl(pathOrUrl)) {
  596. return getNormalizedPathComponentsOfUrl(pathOrUrl);
  597. }
  598. else {
  599. return getNormalizedPathComponents(pathOrUrl, currentDirectory);
  600. }
  601. }
  602. function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) {
  603. var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
  604. var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
  605. if (directoryComponents.length > 1 && lastOrUndefined(directoryComponents) === "") {
  606. directoryComponents.length--;
  607. }
  608. for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) {
  609. if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) {
  610. break;
  611. }
  612. }
  613. if (joinStartIndex) {
  614. var relativePath = "";
  615. var relativePathComponents = pathComponents.slice(joinStartIndex, pathComponents.length);
  616. for (; joinStartIndex < directoryComponents.length; joinStartIndex++) {
  617. if (directoryComponents[joinStartIndex] !== "") {
  618. relativePath = relativePath + ".." + ts.directorySeparator;
  619. }
  620. }
  621. return relativePath + relativePathComponents.join(ts.directorySeparator);
  622. }
  623. var absolutePath = getNormalizedPathFromPathComponents(pathComponents);
  624. if (isAbsolutePathAnUrl && isRootedDiskPath(absolutePath)) {
  625. absolutePath = "file:///" + absolutePath;
  626. }
  627. return absolutePath;
  628. }
  629. ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl;
  630. function getBaseFileName(path) {
  631. var i = path.lastIndexOf(ts.directorySeparator);
  632. return i < 0 ? path : path.substring(i + 1);
  633. }
  634. ts.getBaseFileName = getBaseFileName;
  635. function combinePaths(path1, path2) {
  636. if (!(path1 && path1.length))
  637. return path2;
  638. if (!(path2 && path2.length))
  639. return path1;
  640. if (getRootLength(path2) !== 0)
  641. return path2;
  642. if (path1.charAt(path1.length - 1) === ts.directorySeparator)
  643. return path1 + path2;
  644. return path1 + ts.directorySeparator + path2;
  645. }
  646. ts.combinePaths = combinePaths;
  647. function fileExtensionIs(path, extension) {
  648. var pathLen = path.length;
  649. var extLen = extension.length;
  650. return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
  651. }
  652. ts.fileExtensionIs = fileExtensionIs;
  653. ts.supportedExtensions = [".ts", ".tsx", ".d.ts"];
  654. var extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
  655. function removeFileExtension(path) {
  656. for (var _i = 0; _i < extensionsToRemove.length; _i++) {
  657. var ext = extensionsToRemove[_i];
  658. if (fileExtensionIs(path, ext)) {
  659. return path.substr(0, path.length - ext.length);
  660. }
  661. }
  662. return path;
  663. }
  664. ts.removeFileExtension = removeFileExtension;
  665. var backslashOrDoubleQuote = /[\"\\]/g;
  666. var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
  667. var escapedCharsMap = {
  668. "\0": "\\0",
  669. "\t": "\\t",
  670. "\v": "\\v",
  671. "\f": "\\f",
  672. "\b": "\\b",
  673. "\r": "\\r",
  674. "\n": "\\n",
  675. "\\": "\\\\",
  676. "\"": "\\\"",
  677. "\u2028": "\\u2028",
  678. "\u2029": "\\u2029",
  679. "\u0085": "\\u0085"
  680. };
  681. function Symbol(flags, name) {
  682. this.flags = flags;
  683. this.name = name;
  684. this.declarations = undefined;
  685. }
  686. function Type(checker, flags) {
  687. this.flags = flags;
  688. }
  689. function Signature(checker) {
  690. }
  691. ts.objectAllocator = {
  692. getNodeConstructor: function (kind) {
  693. function Node() {
  694. }
  695. Node.prototype = {
  696. kind: kind,
  697. pos: -1,
  698. end: -1,
  699. flags: 0,
  700. parent: undefined
  701. };
  702. return Node;
  703. },
  704. getSymbolConstructor: function () { return Symbol; },
  705. getTypeConstructor: function () { return Type; },
  706. getSignatureConstructor: function () { return Signature; }
  707. };
  708. var Debug;
  709. (function (Debug) {
  710. var currentAssertionLevel = 0;
  711. function shouldAssert(level) {
  712. return currentAssertionLevel >= level;
  713. }
  714. Debug.shouldAssert = shouldAssert;
  715. function assert(expression, message, verboseDebugInfo) {
  716. if (!expression) {
  717. var verboseDebugString = "";
  718. if (verboseDebugInfo) {
  719. verboseDebugString = "\r\nVerbose Debug Information: " + verboseDebugInfo();
  720. }
  721. throw new Error("Debug Failure. False expression: " + (message || "") + verboseDebugString);
  722. }
  723. }
  724. Debug.assert = assert;
  725. function fail(message) {
  726. Debug.assert(false, message);
  727. }
  728. Debug.fail = fail;
  729. })(Debug = ts.Debug || (ts.Debug = {}));
  730. })(ts || (ts = {}));
  731. /// <reference path="core.ts"/>
  732. var ts;
  733. (function (ts) {
  734. ts.sys = (function () {
  735. function getWScriptSystem() {
  736. var fso = new ActiveXObject("Scripting.FileSystemObject");
  737. var fileStream = new ActiveXObject("ADODB.Stream");
  738. fileStream.Type = 2;
  739. var binaryStream = new ActiveXObject("ADODB.Stream");
  740. binaryStream.Type = 1;
  741. var args = [];
  742. for (var i = 0; i < WScript.Arguments.length; i++) {
  743. args[i] = WScript.Arguments.Item(i);
  744. }
  745. function readFile(fileName, encoding) {
  746. if (!fso.FileExists(fileName)) {
  747. return undefined;
  748. }
  749. fileStream.Open();
  750. try {
  751. if (encoding) {
  752. fileStream.Charset = encoding;
  753. fileStream.LoadFromFile(fileName);
  754. }
  755. else {
  756. fileStream.Charset = "x-ansi";
  757. fileStream.LoadFromFile(fileName);
  758. var bom = fileStream.ReadText(2) || "";
  759. fileStream.Position = 0;
  760. fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
  761. }
  762. return fileStream.ReadText();
  763. }
  764. catch (e) {
  765. throw e;
  766. }
  767. finally {
  768. fileStream.Close();
  769. }
  770. }
  771. function writeFile(fileName, data, writeByteOrderMark) {
  772. fileStream.Open();
  773. binaryStream.Open();
  774. try {
  775. fileStream.Charset = "utf-8";
  776. fileStream.WriteText(data);
  777. if (writeByteOrderMark) {
  778. fileStream.Position = 0;
  779. }
  780. else {
  781. fileStream.Position = 3;
  782. }
  783. fileStream.CopyTo(binaryStream);
  784. binaryStream.SaveToFile(fileName, 2);
  785. }
  786. finally {
  787. binaryStream.Close();
  788. fileStream.Close();
  789. }
  790. }
  791. function getCanonicalPath(path) {
  792. return path.toLowerCase();
  793. }
  794. function getNames(collection) {
  795. var result = [];
  796. for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
  797. result.push(e.item().Name);
  798. }
  799. return result.sort();
  800. }
  801. function readDirectory(path, extension, exclude) {
  802. var result = [];
  803. exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); });
  804. visitDirectory(path);
  805. return result;
  806. function visitDirectory(path) {
  807. var folder = fso.GetFolder(path || ".");
  808. var files = getNames(folder.files);
  809. for (var _i = 0; _i < files.length; _i++) {
  810. var current = files[_i];
  811. var name_1 = ts.combinePaths(path, current);
  812. if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) {
  813. result.push(name_1);
  814. }
  815. }
  816. var subfolders = getNames(folder.subfolders);
  817. for (var _a = 0; _a < subfolders.length; _a++) {
  818. var current = subfolders[_a];
  819. var name_2 = ts.combinePaths(path, current);
  820. if (!ts.contains(exclude, getCanonicalPath(name_2))) {
  821. visitDirectory(name_2);
  822. }
  823. }
  824. }
  825. }
  826. return {
  827. args: args,
  828. newLine: "\r\n",
  829. useCaseSensitiveFileNames: false,
  830. write: function (s) {
  831. WScript.StdOut.Write(s);
  832. },
  833. readFile: readFile,
  834. writeFile: writeFile,
  835. resolvePath: function (path) {
  836. return fso.GetAbsolutePathName(path);
  837. },
  838. fileExists: function (path) {
  839. return fso.FileExists(path);
  840. },
  841. directoryExists: function (path) {
  842. return fso.FolderExists(path);
  843. },
  844. createDirectory: function (directoryName) {
  845. if (!this.directoryExists(directoryName)) {
  846. fso.CreateFolder(directoryName);
  847. }
  848. },
  849. getExecutingFilePath: function () {
  850. return WScript.ScriptFullName;
  851. },
  852. getCurrentDirectory: function () {
  853. return new ActiveXObject("WScript.Shell").CurrentDirectory;
  854. },
  855. readDirectory: readDirectory,
  856. exit: function (exitCode) {
  857. try {
  858. WScript.Quit(exitCode);
  859. }
  860. catch (e) {
  861. }
  862. }
  863. };
  864. }
  865. function getNodeSystem() {
  866. var _fs = require("fs");
  867. var _path = require("path");
  868. var _os = require("os");
  869. var platform = _os.platform();
  870. var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
  871. function readFile(fileName, encoding) {
  872. if (!_fs.existsSync(fileName)) {
  873. return undefined;
  874. }
  875. var buffer = _fs.readFileSync(fileName);
  876. var len = buffer.length;
  877. if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
  878. len &= ~1;
  879. for (var i = 0; i < len; i += 2) {
  880. var temp = buffer[i];
  881. buffer[i] = buffer[i + 1];
  882. buffer[i + 1] = temp;
  883. }
  884. return buffer.toString("utf16le", 2);
  885. }
  886. if (len >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
  887. return buffer.toString("utf16le", 2);
  888. }
  889. if (len >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
  890. return buffer.toString("utf8", 3);
  891. }
  892. return buffer.toString("utf8");
  893. }
  894. function writeFile(fileName, data, writeByteOrderMark) {
  895. if (writeByteOrderMark) {
  896. data = "\uFEFF" + data;
  897. }
  898. _fs.writeFileSync(fileName, data, "utf8");
  899. }
  900. function getCanonicalPath(path) {
  901. return useCaseSensitiveFileNames ? path.toLowerCase() : path;
  902. }
  903. function readDirectory(path, extension, exclude) {
  904. var result = [];
  905. exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); });
  906. visitDirectory(path);
  907. return result;
  908. function visitDirectory(path) {
  909. var files = _fs.readdirSync(path || ".").sort();
  910. var directories = [];
  911. for (var _i = 0; _i < files.length; _i++) {
  912. var current = files[_i];
  913. var name_3 = ts.combinePaths(path, current);
  914. if (!ts.contains(exclude, getCanonicalPath(name_3))) {
  915. var stat = _fs.statSync(name_3);
  916. if (stat.isFile()) {
  917. if (!extension || ts.fileExtensionIs(name_3, extension)) {
  918. result.push(name_3);
  919. }
  920. }
  921. else if (stat.isDirectory()) {
  922. directories.push(name_3);
  923. }
  924. }
  925. }
  926. for (var _a = 0; _a < directories.length; _a++) {
  927. var current = directories[_a];
  928. visitDirectory(current);
  929. }
  930. }
  931. }
  932. return {
  933. args: process.argv.slice(2),
  934. newLine: _os.EOL,
  935. useCaseSensitiveFileNames: useCaseSensitiveFileNames,
  936. write: function (s) {
  937. var buffer = new Buffer(s, "utf8");
  938. var offset = 0;
  939. var toWrite = buffer.length;
  940. var written = 0;
  941. while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) {
  942. offset += written;
  943. toWrite -= written;
  944. }
  945. },
  946. readFile: readFile,
  947. writeFile: writeFile,
  948. watchFile: function (fileName, callback) {
  949. _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
  950. return {
  951. close: function () { _fs.unwatchFile(fileName, fileChanged); }
  952. };
  953. function fileChanged(curr, prev) {
  954. if (+curr.mtime <= +prev.mtime) {
  955. return;
  956. }
  957. callback(fileName);
  958. }
  959. },
  960. resolvePath: function (path) {
  961. return _path.resolve(path);
  962. },
  963. fileExists: function (path) {
  964. return _fs.existsSync(path);
  965. },
  966. directoryExists: function (path) {
  967. return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
  968. },
  969. createDirectory: function (directoryName) {
  970. if (!this.directoryExists(directoryName)) {
  971. _fs.mkdirSync(directoryName);
  972. }
  973. },
  974. getExecutingFilePath: function () {
  975. return __filename;
  976. },
  977. getCurrentDirectory: function () {
  978. return process.cwd();
  979. },
  980. readDirectory: readDirectory,
  981. getMemoryUsage: function () {
  982. if (global.gc) {
  983. global.gc();
  984. }
  985. return process.memoryUsage().heapUsed;
  986. },
  987. exit: function (exitCode) {
  988. process.exit(exitCode);
  989. }
  990. };
  991. }
  992. if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
  993. return getWScriptSystem();
  994. }
  995. else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
  996. return getNodeSystem();
  997. }
  998. else {
  999. return undefined;
  1000. }
  1001. })();
  1002. })(ts || (ts = {}));
  1003. /// <reference path="types.ts" />
  1004. var ts;
  1005. (function (ts) {
  1006. ts.Diagnostics = {
  1007. Unterminated_string_literal: { code: 1002, category: ts.DiagnosticCategory.Error, key: "Unterminated string literal." },
  1008. Identifier_expected: { code: 1003, category: ts.DiagnosticCategory.Error, key: "Identifier expected." },
  1009. _0_expected: { code: 1005, category: ts.DiagnosticCategory.Error, key: "'{0}' expected." },
  1010. A_file_cannot_have_a_reference_to_itself: { code: 1006, category: ts.DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
  1011. Trailing_comma_not_allowed: { code: 1009, category: ts.DiagnosticCategory.Error, key: "Trailing comma not allowed." },
  1012. Asterisk_Slash_expected: { code: 1010, category: ts.DiagnosticCategory.Error, key: "'*/' expected." },
  1013. Unexpected_token: { code: 1012, category: ts.DiagnosticCategory.Error, key: "Unexpected token." },
  1014. 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." },
  1015. Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: ts.DiagnosticCategory.Error, key: "Parameter cannot have question mark and initializer." },
  1016. A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: ts.DiagnosticCategory.Error, key: "A required parameter cannot follow an optional parameter." },
  1017. An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: ts.DiagnosticCategory.Error, key: "An index signature cannot have a rest parameter." },
  1018. 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." },
  1019. 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." },
  1020. An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have an initializer." },
  1021. An_index_signature_must_have_a_type_annotation: { code: 1021, category: ts.DiagnosticCategory.Error, key: "An index signature must have a type annotation." },
  1022. 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." },
  1023. 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'." },
  1024. Accessibility_modifier_already_seen: { code: 1028, category: ts.DiagnosticCategory.Error, key: "Accessibility modifier already seen." },
  1025. _0_modifier_must_precede_1_modifier: { code: 1029, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." },
  1026. _0_modifier_already_seen: { code: 1030, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier already seen." },
  1027. _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." },
  1028. 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." },
  1029. Only_ambient_modules_can_use_quoted_names: { code: 1035, category: ts.DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." },
  1030. Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: ts.DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." },
  1031. 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." },
  1032. Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: ts.DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." },
  1033. _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." },
  1034. _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." },
  1035. _0_modifier_cannot_be_used_here: { code: 1042, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used here." },
  1036. _0_modifier_cannot_appear_on_a_data_property: { code: 1043, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a data property." },
  1037. _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." },
  1038. 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." },
  1039. 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." },
  1040. A_rest_parameter_cannot_be_optional: { code: 1047, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot be optional." },
  1041. A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." },
  1042. A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor must have exactly one parameter." },
  1043. A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have an optional parameter." },
  1044. A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor parameter cannot have an initializer." },
  1045. A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have rest parameter." },
  1046. A_get_accessor_cannot_have_parameters: { code: 1054, category: ts.DiagnosticCategory.Error, key: "A 'get' accessor cannot have parameters." },
  1047. 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." },
  1048. 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." },
  1049. 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." },
  1050. 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." },
  1051. 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." },
  1052. 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." },
  1053. Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." },
  1054. _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." },
  1055. 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." },
  1056. Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: ts.DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." },
  1057. 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." },
  1058. 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." },
  1059. Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." },
  1060. 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." },
  1061. 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." },
  1062. _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a constructor declaration." },
  1063. _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a parameter." },
  1064. 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." },
  1065. Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: ts.DiagnosticCategory.Error, key: "Type parameters cannot appear on a constructor declaration." },
  1066. Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: ts.DiagnosticCategory.Error, key: "Type annotation cannot appear on a constructor declaration." },
  1067. An_accessor_cannot_have_type_parameters: { code: 1094, category: ts.DiagnosticCategory.Error, key: "An accessor cannot have type parameters." },
  1068. 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." },
  1069. An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: ts.DiagnosticCategory.Error, key: "An index signature must have exactly one parameter." },
  1070. _0_list_cannot_be_empty: { code: 1097, category: ts.DiagnosticCategory.Error, key: "'{0}' list cannot be empty." },
  1071. Type_parameter_list_cannot_be_empty: { code: 1098, category: ts.DiagnosticCategory.Error, key: "Type parameter list cannot be empty." },
  1072. Type_argument_list_cannot_be_empty: { code: 1099, category: ts.DiagnosticCategory.Error, key: "Type argument list cannot be empty." },
  1073. Invalid_use_of_0_in_strict_mode: { code: 1100, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}' in strict mode." },
  1074. with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in strict mode." },
  1075. 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." },
  1076. 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." },
  1077. 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." },
  1078. Jump_target_cannot_cross_function_boundary: { code: 1107, category: ts.DiagnosticCategory.Error, key: "Jump target cannot cross function boundary." },
  1079. 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." },
  1080. Expression_expected: { code: 1109, category: ts.DiagnosticCategory.Error, key: "Expression expected." },
  1081. Type_expected: { code: 1110, category: ts.DiagnosticCategory.Error, key: "Type expected." },
  1082. A_class_member_cannot_be_declared_optional: { code: 1112, category: ts.DiagnosticCategory.Error, key: "A class member cannot be declared optional." },
  1083. 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." },
  1084. Duplicate_label_0: { code: 1114, category: ts.DiagnosticCategory.Error, key: "Duplicate label '{0}'" },
  1085. 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." },
  1086. 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." },
  1087. 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." },
  1088. 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." },
  1089. 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." },
  1090. An_export_assignment_cannot_have_modifiers: { code: 1120, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot have modifiers." },
  1091. Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: ts.DiagnosticCategory.Error, key: "Octal literals are not allowed in strict mode." },
  1092. A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: ts.DiagnosticCategory.Error, key: "A tuple type element list cannot be empty." },
  1093. Variable_declaration_list_cannot_be_empty: { code: 1123, category: ts.DiagnosticCategory.Error, key: "Variable declaration list cannot be empty." },
  1094. Digit_expected: { code: 1124, category: ts.DiagnosticCategory.Error, key: "Digit expected." },
  1095. Hexadecimal_digit_expected: { code: 1125, category: ts.DiagnosticCategory.Error, key: "Hexadecimal digit expected." },
  1096. Unexpected_end_of_text: { code: 1126, category: ts.DiagnosticCategory.Error, key: "Unexpected end of text." },
  1097. Invalid_character: { code: 1127, category: ts.DiagnosticCategory.Error, key: "Invalid character." },
  1098. Declaration_or_statement_expected: { code: 1128, category: ts.DiagnosticCategory.Error, key: "Declaration or statement expected." },
  1099. Statement_expected: { code: 1129, category: ts.DiagnosticCategory.Error, key: "Statement expected." },
  1100. case_or_default_expected: { code: 1130, category: ts.DiagnosticCategory.Error, key: "'case' or 'default' expected." },
  1101. Property_or_signature_expected: { code: 1131, category: ts.DiagnosticCategory.Error, key: "Property or signature expected." },
  1102. Enum_member_expected: { code: 1132, category: ts.DiagnosticCategory.Error, key: "Enum member expected." },
  1103. Variable_declaration_expected: { code: 1134, category: ts.DiagnosticCategory.Error, key: "Variable declaration expected." },
  1104. Argument_expression_expected: { code: 1135, category: ts.DiagnosticCategory.Error, key: "Argument expression expected." },
  1105. Property_assignment_expected: { code: 1136, category: ts.DiagnosticCategory.Error, key: "Property assignment expected." },
  1106. Expression_or_comma_expected: { code: 1137, category: ts.DiagnosticCategory.Error, key: "Expression or comma expected." },
  1107. Parameter_declaration_expected: { code: 1138, category: ts.DiagnosticCategory.Error, key: "Parameter declaration expected." },
  1108. Type_parameter_declaration_expected: { code: 1139, category: ts.DiagnosticCategory.Error, key: "Type parameter declaration expected." },
  1109. Type_argument_expected: { code: 1140, category: ts.DiagnosticCategory.Error, key: "Type argument expected." },
  1110. String_literal_expected: { code: 1141, category: ts.DiagnosticCategory.Error, key: "String literal expected." },
  1111. Line_break_not_permitted_here: { code: 1142, category: ts.DiagnosticCategory.Error, key: "Line break not permitted here." },
  1112. or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "'{' or ';' expected." },
  1113. Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: ts.DiagnosticCategory.Error, key: "Modifiers not permitted on index signature members." },
  1114. Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration expected." },
  1115. 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." },
  1116. 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." },
  1117. 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" },
  1118. 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." },
  1119. const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
  1120. 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." },
  1121. 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." },
  1122. Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." },
  1123. Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
  1124. An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
  1125. 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." },
  1126. Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." },
  1127. 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." },
  1128. 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." },
  1129. 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." },
  1130. 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." },
  1131. 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." },
  1132. 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." },
  1133. extends_clause_already_seen: { code: 1172, category: ts.DiagnosticCategory.Error, key: "'extends' clause already seen." },
  1134. extends_clause_must_precede_implements_clause: { code: 1173, category: ts.DiagnosticCategory.Error, key: "'extends' clause must precede 'implements' clause." },
  1135. Classes_can_only_extend_a_single_class: { code: 1174, category: ts.DiagnosticCategory.Error, key: "Classes can only extend a single class." },
  1136. implements_clause_already_seen: { code: 1175, category: ts.DiagnosticCategory.Error, key: "'implements' clause already seen." },
  1137. Interface_declaration_cannot_have_implements_clause: { code: 1176, category: ts.DiagnosticCategory.Error, key: "Interface declaration cannot have 'implements' clause." },
  1138. Binary_digit_expected: { code: 1177, category: ts.DiagnosticCategory.Error, key: "Binary digit expected." },
  1139. Octal_digit_expected: { code: 1178, category: ts.DiagnosticCategory.Error, key: "Octal digit expected." },
  1140. Unexpected_token_expected: { code: 1179, category: ts.DiagnosticCategory.Error, key: "Unexpected token. '{' expected." },
  1141. Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." },
  1142. Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." },
  1143. A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." },
  1144. An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." },
  1145. Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
  1146. Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
  1147. A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." },
  1148. 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." },
  1149. 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." },
  1150. 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." },
  1151. 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." },
  1152. An_import_declaration_cannot_have_modifiers: { code: 1191, category: ts.DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." },
  1153. Module_0_has_no_default_export: { code: 1192, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no default export." },
  1154. An_export_declaration_cannot_have_modifiers: { code: 1193, category: ts.DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." },
  1155. Export_declarations_are_not_permitted_in_a_namespace: { code: 1194, category: ts.DiagnosticCategory.Error, key: "Export declarations are not permitted in a namespace." },
  1156. Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: ts.DiagnosticCategory.Error, key: "Catch clause variable name must be an identifier." },
  1157. Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have a type annotation." },
  1158. Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." },
  1159. 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." },
  1160. Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
  1161. Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
  1162. Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." },
  1163. Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." },
  1164. Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." },
  1165. Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." },
  1166. Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." },
  1167. 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." },
  1168. 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." },
  1169. 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." },
  1170. 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." },
  1171. 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" },
  1172. 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" },
  1173. 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." },
  1174. 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." },
  1175. 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." },
  1176. 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'." },
  1177. 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." },
  1178. 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." },
  1179. Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: ts.DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." },
  1180. 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." },
  1181. _0_tag_already_specified: { code: 1223, category: ts.DiagnosticCategory.Error, key: "'{0}' tag already specified." },
  1182. Signature_0_must_have_a_type_predicate: { code: 1224, category: ts.DiagnosticCategory.Error, key: "Signature '{0}' must have a type predicate." },
  1183. Cannot_find_parameter_0: { code: 1225, category: ts.DiagnosticCategory.Error, key: "Cannot find parameter '{0}'." },
  1184. Type_predicate_0_is_not_assignable_to_1: { code: 1226, category: ts.DiagnosticCategory.Error, key: "Type predicate '{0}' is not assignable to '{1}'." },
  1185. 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}'." },
  1186. 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." },
  1187. A_type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: ts.DiagnosticCategory.Error, key: "A type predicate cannot reference a rest parameter." },
  1188. 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." },
  1189. 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." },
  1190. 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." },
  1191. 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." },
  1192. 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." },
  1193. 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." },
  1194. Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning: { code: 1236, category: ts.DiagnosticCategory.Error, key: "Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning." },
  1195. 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." },
  1196. 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." },
  1197. 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." },
  1198. 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'." },
  1199. 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'." },
  1200. 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." },
  1201. 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." },
  1202. 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." },
  1203. 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." },
  1204. 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." },
  1205. _0_modifier_cannot_be_used_with_1_modifier: { code: 1243, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." },
  1206. 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." },
  1207. 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." },
  1208. Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
  1209. 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." },
  1210. Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
  1211. Circular_definition_of_import_alias_0: { code: 2303, category: ts.DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." },
  1212. Cannot_find_name_0: { code: 2304, category: ts.DiagnosticCategory.Error, key: "Cannot find name '{0}'." },
  1213. Module_0_has_no_exported_member_1: { code: 2305, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
  1214. File_0_is_not_a_module: { code: 2306, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not a module." },
  1215. Cannot_find_module_0: { code: 2307, category: ts.DiagnosticCategory.Error, key: "Cannot find module '{0}'." },
  1216. 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." },
  1217. 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." },
  1218. A_class_may_only_extend_another_class: { code: 2311, category: ts.DiagnosticCategory.Error, key: "A class may only extend another class." },
  1219. 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." },
  1220. 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." },
  1221. Generic_type_0_requires_1_type_argument_s: { code: 2314, category: ts.DiagnosticCategory.Error, key: "Generic type '{0}' requires {1} type argument(s)." },
  1222. Type_0_is_not_generic: { code: 2315, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not generic." },
  1223. 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." },
  1224. 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)." },
  1225. Cannot_find_global_type_0: { code: 2318, category: ts.DiagnosticCategory.Error, key: "Cannot find global type '{0}'." },
  1226. 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." },
  1227. 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}'." },
  1228. Excessive_stack_depth_comparing_types_0_and_1: { code: 2321, category: ts.DiagnosticCategory.Error, key: "Excessive stack depth comparing types '{0}' and '{1}'." },
  1229. Type_0_is_not_assignable_to_type_1: { code: 2322, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}'." },
  1230. Property_0_is_missing_in_type_1: { code: 2324, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is missing in type '{1}'." },
  1231. 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}'." },
  1232. Types_of_property_0_are_incompatible: { code: 2326, category: ts.DiagnosticCategory.Error, key: "Types of property '{0}' are incompatible." },
  1233. 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}'." },
  1234. Types_of_parameters_0_and_1_are_incompatible: { code: 2328, category: ts.DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible." },
  1235. Index_signature_is_missing_in_type_0: { code: 2329, category: ts.DiagnosticCategory.Error, key: "Index signature is missing in type '{0}'." },
  1236. Index_signatures_are_incompatible: { code: 2330, category: ts.DiagnosticCategory.Error, key: "Index signatures are incompatible." },
  1237. 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." },
  1238. this_cannot_be_referenced_in_current_location: { code: 2332, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in current location." },
  1239. this_cannot_be_referenced_in_constructor_arguments: { code: 2333, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in constructor arguments." },
  1240. 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." },
  1241. 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." },
  1242. super_cannot_be_referenced_in_constructor_arguments: { code: 2336, category: ts.DiagnosticCategory.Error, key: "'super' cannot be referenced in constructor arguments." },
  1243. 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." },
  1244. 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." },
  1245. Property_0_does_not_exist_on_type_1: { code: 2339, category: ts.DiagnosticCategory.Error, key: "Property '{0}' does not exist on type '{1}'." },
  1246. 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." },
  1247. 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}'." },
  1248. 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'." },
  1249. Type_0_does_not_satisfy_the_constraint_1: { code: 2344, category: ts.DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}'." },
  1250. 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}'." },
  1251. 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." },
  1252. Untyped_function_calls_may_not_accept_type_arguments: { code: 2347, category: ts.DiagnosticCategory.Error, key: "Untyped function calls may not accept type arguments." },
  1253. 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'?" },
  1254. 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." },
  1255. 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." },
  1256. 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." },
  1257. 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." },
  1258. 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}'." },
  1259. No_best_common_type_exists_among_return_expressions: { code: 2354, category: ts.DiagnosticCategory.Error, key: "No best common type exists among return expressions." },
  1260. 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." },
  1261. 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." },
  1262. 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." },
  1263. 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." },
  1264. 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." },
  1265. 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'." },
  1266. 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" },
  1267. 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." },
  1268. 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." },
  1269. Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
  1270. 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}'." },
  1271. Type_parameter_name_cannot_be_0: { code: 2368, category: ts.DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" },
  1272. 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." },
  1273. 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." },
  1274. 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." },
  1275. Parameter_0_cannot_be_referenced_in_its_initializer: { code: 2372, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' cannot be referenced in its initializer." },
  1276. 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." },
  1277. Duplicate_string_index_signature: { code: 2374, category: ts.DiagnosticCategory.Error, key: "Duplicate string index signature." },
  1278. Duplicate_number_index_signature: { code: 2375, category: ts.DiagnosticCategory.Error, key: "Duplicate number index signature." },
  1279. 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." },
  1280. 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." },
  1281. 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." },
  1282. 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." },
  1283. 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." },
  1284. 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." },
  1285. 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." },
  1286. 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." },
  1287. 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." },
  1288. 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." },
  1289. Overload_signatures_must_all_be_optional_or_required: { code: 2386, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be optional or required." },
  1290. Function_overload_must_be_static: { code: 2387, category: ts.DiagnosticCategory.Error, key: "Function overload must be static." },
  1291. Function_overload_must_not_be_static: { code: 2388, category: ts.DiagnosticCategory.Error, key: "Function overload must not be static." },
  1292. Function_implementation_name_must_be_0: { code: 2389, category: ts.DiagnosticCategory.Error, key: "Function implementation name must be '{0}'." },
  1293. Constructor_implementation_is_missing: { code: 2390, category: ts.DiagnosticCategory.Error, key: "Constructor implementation is missing." },
  1294. 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." },
  1295. Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: ts.DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },
  1296. Duplicate_function_implementation: { code: 2393, category: ts.DiagnosticCategory.Error, key: "Duplicate function implementation." },
  1297. Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: ts.DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
  1298. 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." },
  1299. 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." },
  1300. 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." },
  1301. 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." },
  1302. 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." },
  1303. 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." },
  1304. 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}'." },
  1305. 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." },
  1306. 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'." },
  1307. Invalid_left_hand_side_in_for_in_statement: { code: 2406, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...in' statement." },
  1308. 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." },
  1309. Setters_cannot_return_a_value: { code: 2408, category: ts.DiagnosticCategory.Error, key: "Setters cannot return a value." },
  1310. 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" },
  1311. 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'." },
  1312. 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}'." },
  1313. 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}'." },
  1314. 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}'." },
  1315. Class_name_cannot_be_0: { code: 2414, category: ts.DiagnosticCategory.Error, key: "Class name cannot be '{0}'" },
  1316. Class_0_incorrectly_extends_base_class_1: { code: 2415, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly extends base class '{1}'." },
  1317. 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}'." },
  1318. 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}'." },
  1319. Class_0_incorrectly_implements_interface_1: { code: 2420, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly implements interface '{1}'." },
  1320. 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." },
  1321. 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." },
  1322. 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." },
  1323. 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." },
  1324. 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." },
  1325. Interface_name_cannot_be_0: { code: 2427, category: ts.DiagnosticCategory.Error, key: "Interface name cannot be '{0}'" },
  1326. 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." },
  1327. Interface_0_incorrectly_extends_interface_1: { code: 2430, category: ts.DiagnosticCategory.Error, key: "Interface '{0}' incorrectly extends interface '{1}'." },
  1328. Enum_name_cannot_be_0: { code: 2431, category: ts.DiagnosticCategory.Error, key: "Enum name cannot be '{0}'" },
  1329. 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." },
  1330. 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" },
  1331. 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" },
  1332. Ambient_modules_cannot_be_nested_in_other_modules: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules." },
  1333. Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." },
  1334. 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" },
  1335. Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" },
  1336. 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." },
  1337. Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: ts.DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
  1338. 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." },
  1339. 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}'." },
  1340. 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}'." },
  1341. 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}'." },
  1342. 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." },
  1343. 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}'." },
  1344. 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." },
  1345. Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: ts.DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." },
  1346. 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." },
  1347. 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." },
  1348. Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'." },
  1349. An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: ts.DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
  1350. 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." },
  1351. 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}'." },
  1352. Type_alias_0_circularly_references_itself: { code: 2456, category: ts.DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
  1353. Type_alias_name_cannot_be_0: { code: 2457, category: ts.DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
  1354. An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: ts.DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
  1355. 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." },
  1356. Type_0_has_no_property_1: { code: 2460, category: ts.DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
  1357. Type_0_is_not_an_array_type: { code: 2461, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
  1358. 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" },
  1359. 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." },
  1360. 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'." },
  1361. 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." },
  1362. 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." },
  1363. 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." },
  1364. Cannot_find_global_value_0: { code: 2468, category: ts.DiagnosticCategory.Error, key: "Cannot find global value '{0}'." },
  1365. 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'." },
  1366. 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." },
  1367. 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'." },
  1368. 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." },
  1369. 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." },
  1370. 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." },
  1371. 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." },
  1372. 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." },
  1373. 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." },
  1374. 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'." },
  1375. 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}'." },
  1376. 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." },
  1377. 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}'." },
  1378. 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." },
  1379. Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: ts.DiagnosticCategory.Error, key: "Export declaration conflicts with exported declaration of '{0}'" },
  1380. 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." },
  1381. 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." },
  1382. Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...of' statement." },
  1383. 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." },
  1384. An_iterator_must_have_a_next_method: { code: 2489, category: ts.DiagnosticCategory.Error, key: "An iterator must have a 'next()' method." },
  1385. 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." },
  1386. 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." },
  1387. Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" },
  1388. 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}'." },
  1389. 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." },
  1390. 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." },
  1391. 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." },
  1392. 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." },
  1393. 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 *'." },
  1394. 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." },
  1395. 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." },
  1396. A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
  1397. _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." },
  1398. Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
  1399. No_best_common_type_exists_among_yield_expressions: { code: 2504, category: ts.DiagnosticCategory.Error, key: "No best common type exists among yield expressions." },
  1400. A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: ts.DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." },
  1401. _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." },
  1402. Type_0_is_not_a_constructor_function_type: { code: 2507, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not a constructor function type." },
  1403. 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." },
  1404. 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." },
  1405. 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." },
  1406. 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}'." },
  1407. 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." },
  1408. 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." },
  1409. Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: ts.DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." },
  1410. 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}'." },
  1411. 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." },
  1412. 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." },
  1413. Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: ts.DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." },
  1414. 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." },
  1415. 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." },
  1416. 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." },
  1417. 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." },
  1418. 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." },
  1419. 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." },
  1420. 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." },
  1421. 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." },
  1422. 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}'" },
  1423. 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." },
  1424. 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." },
  1425. 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." },
  1426. 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" },
  1427. 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" },
  1428. Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: ts.DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" },
  1429. 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." },
  1430. 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." },
  1431. 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." },
  1432. Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: ts.DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." },
  1433. Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
  1434. 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}'." },
  1435. 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}'." },
  1436. 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}'." },
  1437. 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}'." },
  1438. 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}'." },
  1439. 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}'." },
  1440. 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}'." },
  1441. 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}'." },
  1442. 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}'." },
  1443. 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}'." },
  1444. 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}'." },
  1445. 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." },
  1446. 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}'." },
  1447. 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}'." },
  1448. 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." },
  1449. 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}'." },
  1450. 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}'." },
  1451. 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." },
  1452. 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}'." },
  1453. 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}'." },
  1454. 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}'." },
  1455. 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}'." },
  1456. 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}'." },
  1457. 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}'." },
  1458. 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}'." },
  1459. 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}'." },
  1460. 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." },
  1461. 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}'." },
  1462. 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}'." },
  1463. 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." },
  1464. 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}'." },
  1465. 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}'." },
  1466. 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}'." },
  1467. 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}'." },
  1468. 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}'." },
  1469. 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}'." },
  1470. 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}'." },
  1471. 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}'." },
  1472. 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." },
  1473. 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}'." },
  1474. 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}'." },
  1475. 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." },
  1476. 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}'." },
  1477. 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}'." },
  1478. 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}'." },
  1479. 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}'." },
  1480. 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." },
  1481. 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}'." },
  1482. 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}'." },
  1483. 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." },
  1484. 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}'." },
  1485. 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}'." },
  1486. 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}'." },
  1487. 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}'." },
  1488. 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}'." },
  1489. 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}'." },
  1490. 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." },
  1491. 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}'." },
  1492. 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}'." },
  1493. 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." },
  1494. 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}'." },
  1495. 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}'." },
  1496. 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}'." },
  1497. 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}'." },
  1498. 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." },
  1499. 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}'." },
  1500. 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}'." },
  1501. 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}'." },
  1502. 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}'." },
  1503. 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." },
  1504. 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." },
  1505. 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." },
  1506. Cannot_read_file_0_Colon_1: { code: 5012, category: ts.DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
  1507. Unsupported_file_encoding: { code: 5013, category: ts.DiagnosticCategory.Error, key: "Unsupported file encoding." },
  1508. Failed_to_parse_file_0_Colon_1: { code: 5014, category: ts.DiagnosticCategory.Error, key: "Failed to parse file '{0}': {1}." },
  1509. Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
  1510. 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}." },
  1511. Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
  1512. 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." },
  1513. 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." },
  1514. 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." },
  1515. 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}'." },
  1516. Option_0_cannot_be_specified_with_option_1: { code: 5053, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." },
  1517. A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5053, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." },
  1518. Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
  1519. Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
  1520. 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." },
  1521. 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." },
  1522. Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
  1523. Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
  1524. 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." },
  1525. 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." },
  1526. Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
  1527. Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
  1528. 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)" },
  1529. Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" },
  1530. Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." },
  1531. Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." },
  1532. Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." },
  1533. Syntax_Colon_0: { code: 6023, category: ts.DiagnosticCategory.Message, key: "Syntax: {0}" },
  1534. options: { code: 6024, category: ts.DiagnosticCategory.Message, key: "options" },
  1535. file: { code: 6025, category: ts.DiagnosticCategory.Message, key: "file" },
  1536. Examples_Colon_0: { code: 6026, category: ts.DiagnosticCategory.Message, key: "Examples: {0}" },
  1537. Options_Colon: { code: 6027, category: ts.DiagnosticCategory.Message, key: "Options:" },
  1538. Version_0: { code: 6029, category: ts.DiagnosticCategory.Message, key: "Version {0}" },
  1539. 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." },
  1540. File_change_detected_Starting_incremental_compilation: { code: 6032, category: ts.DiagnosticCategory.Message, key: "File change detected. Starting incremental compilation..." },
  1541. KIND: { code: 6034, category: ts.DiagnosticCategory.Message, key: "KIND" },
  1542. FILE: { code: 6035, category: ts.DiagnosticCategory.Message, key: "FILE" },
  1543. VERSION: { code: 6036, category: ts.DiagnosticCategory.Message, key: "VERSION" },
  1544. LOCATION: { code: 6037, category: ts.DiagnosticCategory.Message, key: "LOCATION" },
  1545. DIRECTORY: { code: 6038, category: ts.DiagnosticCategory.Message, key: "DIRECTORY" },
  1546. Compilation_complete_Watching_for_file_changes: { code: 6042, category: ts.DiagnosticCategory.Message, key: "Compilation complete. Watching for file changes." },
  1547. Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
  1548. Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
  1549. Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
  1550. Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." },
  1551. 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'." },
  1552. 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}'." },
  1553. Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
  1554. Unable_to_open_file_0: { code: 6050, category: ts.DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
  1555. Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
  1556. 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." },
  1557. File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
  1558. 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}." },
  1559. 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." },
  1560. 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." },
  1561. 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." },
  1562. 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." },
  1563. 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)." },
  1564. NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" },
  1565. 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'." },
  1566. 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'." },
  1567. Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
  1568. Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
  1569. Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
  1570. 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." },
  1571. Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." },
  1572. Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
  1573. 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)." },
  1574. 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." },
  1575. Successfully_created_a_tsconfig_json_file: { code: 6071, category: ts.DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." },
  1576. Suppress_excess_property_checks_for_object_literals: { code: 6072, category: ts.DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." },
  1577. Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
  1578. Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
  1579. Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
  1580. 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." },
  1581. _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." },
  1582. 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." },
  1583. 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." },
  1584. 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." },
  1585. 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." },
  1586. 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." },
  1587. Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
  1588. 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." },
  1589. _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." },
  1590. _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." },
  1591. 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." },
  1592. 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." },
  1593. 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" },
  1594. You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." },
  1595. 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." },
  1596. 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." },
  1597. 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." },
  1598. 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." },
  1599. 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." },
  1600. 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." },
  1601. 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." },
  1602. 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." },
  1603. _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." },
  1604. 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." },
  1605. 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." },
  1606. 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." },
  1607. 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." },
  1608. 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." },
  1609. 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." },
  1610. 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." },
  1611. 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." },
  1612. class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
  1613. 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'." },
  1614. 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." },
  1615. Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: ts.DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." },
  1616. JSX_attribute_expected: { code: 17003, category: ts.DiagnosticCategory.Error, key: "JSX attribute expected." },
  1617. 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." },
  1618. 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'" }
  1619. };
  1620. })(ts || (ts = {}));
  1621. /// <reference path="core.ts"/>
  1622. /// <reference path="diagnosticInformationMap.generated.ts"/>
  1623. var ts;
  1624. (function (ts) {
  1625. var textToToken = {
  1626. "abstract": 113,
  1627. "any": 115,
  1628. "as": 114,
  1629. "boolean": 118,
  1630. "break": 68,
  1631. "case": 69,
  1632. "catch": 70,
  1633. "class": 71,
  1634. "continue": 73,
  1635. "const": 72,
  1636. "constructor": 119,
  1637. "debugger": 74,
  1638. "declare": 120,
  1639. "default": 75,
  1640. "delete": 76,
  1641. "do": 77,
  1642. "else": 78,
  1643. "enum": 79,
  1644. "export": 80,
  1645. "extends": 81,
  1646. "false": 82,
  1647. "finally": 83,
  1648. "for": 84,
  1649. "from": 131,
  1650. "function": 85,
  1651. "get": 121,
  1652. "if": 86,
  1653. "implements": 104,
  1654. "import": 87,
  1655. "in": 88,
  1656. "instanceof": 89,
  1657. "interface": 105,
  1658. "is": 122,
  1659. "let": 106,
  1660. "module": 123,
  1661. "namespace": 124,
  1662. "new": 90,
  1663. "null": 91,
  1664. "number": 126,
  1665. "package": 107,
  1666. "private": 108,
  1667. "protected": 109,
  1668. "public": 110,
  1669. "require": 125,
  1670. "return": 92,
  1671. "set": 127,
  1672. "static": 111,
  1673. "string": 128,
  1674. "super": 93,
  1675. "switch": 94,
  1676. "symbol": 129,
  1677. "this": 95,
  1678. "throw": 96,
  1679. "true": 97,
  1680. "try": 98,
  1681. "type": 130,
  1682. "typeof": 99,
  1683. "var": 100,
  1684. "void": 101,
  1685. "while": 102,
  1686. "with": 103,
  1687. "yield": 112,
  1688. "async": 116,
  1689. "await": 117,
  1690. "of": 132,
  1691. "{": 15,
  1692. "}": 16,
  1693. "(": 17,
  1694. ")": 18,
  1695. "[": 19,
  1696. "]": 20,
  1697. ".": 21,
  1698. "...": 22,
  1699. ";": 23,
  1700. ",": 24,
  1701. "<": 25,
  1702. ">": 27,
  1703. "<=": 28,
  1704. ">=": 29,
  1705. "==": 30,
  1706. "!=": 31,
  1707. "===": 32,
  1708. "!==": 33,
  1709. "=>": 34,
  1710. "+": 35,
  1711. "-": 36,
  1712. "*": 37,
  1713. "/": 38,
  1714. "%": 39,
  1715. "++": 40,
  1716. "--": 41,
  1717. "<<": 42,
  1718. "</": 26,
  1719. ">>": 43,
  1720. ">>>": 44,
  1721. "&": 45,
  1722. "|": 46,
  1723. "^": 47,
  1724. "!": 48,
  1725. "~": 49,
  1726. "&&": 50,
  1727. "||": 51,
  1728. "?": 52,
  1729. ":": 53,
  1730. "=": 55,
  1731. "+=": 56,
  1732. "-=": 57,
  1733. "*=": 58,
  1734. "/=": 59,
  1735. "%=": 60,
  1736. "<<=": 61,
  1737. ">>=": 62,
  1738. ">>>=": 63,
  1739. "&=": 64,
  1740. "|=": 65,
  1741. "^=": 66,
  1742. "@": 54
  1743. };
  1744. 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,];
  1745. 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,];
  1746. 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,];
  1747. 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,];
  1748. function lookupInUnicodeMap(code, map) {
  1749. if (code < map[0]) {
  1750. return false;
  1751. }
  1752. var lo = 0;
  1753. var hi = map.length;
  1754. var mid;
  1755. while (lo + 1 < hi) {
  1756. mid = lo + (hi - lo) / 2;
  1757. mid -= mid % 2;
  1758. if (map[mid] <= code && code <= map[mid + 1]) {
  1759. return true;
  1760. }
  1761. if (code < map[mid]) {
  1762. hi = mid;
  1763. }
  1764. else {
  1765. lo = mid + 2;
  1766. }
  1767. }
  1768. return false;
  1769. }
  1770. function isUnicodeIdentifierStart(code, languageVersion) {
  1771. return languageVersion >= 1 ?
  1772. lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
  1773. lookupInUnicodeMap(code, unicodeES3IdentifierStart);
  1774. }
  1775. ts.isUnicodeIdentifierStart = isUnicodeIdentifierStart;
  1776. function isUnicodeIdentifierPart(code, languageVersion) {
  1777. return languageVersion >= 1 ?
  1778. lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
  1779. lookupInUnicodeMap(code, unicodeES3IdentifierPart);
  1780. }
  1781. function makeReverseMap(source) {
  1782. var result = [];
  1783. for (var name_4 in source) {
  1784. if (source.hasOwnProperty(name_4)) {
  1785. result[source[name_4]] = name_4;
  1786. }
  1787. }
  1788. return result;
  1789. }
  1790. var tokenStrings = makeReverseMap(textToToken);
  1791. function tokenToString(t) {
  1792. return tokenStrings[t];
  1793. }
  1794. ts.tokenToString = tokenToString;
  1795. function stringToToken(s) {
  1796. return textToToken[s];
  1797. }
  1798. ts.stringToToken = stringToToken;
  1799. function computeLineStarts(text) {
  1800. var result = new Array();
  1801. var pos = 0;
  1802. var lineStart = 0;
  1803. while (pos < text.length) {
  1804. var ch = text.charCodeAt(pos++);
  1805. switch (ch) {
  1806. case 13:
  1807. if (text.charCodeAt(pos) === 10) {
  1808. pos++;
  1809. }
  1810. case 10:
  1811. result.push(lineStart);
  1812. lineStart = pos;
  1813. break;
  1814. default:
  1815. if (ch > 127 && isLineBreak(ch)) {
  1816. result.push(lineStart);
  1817. lineStart = pos;
  1818. }
  1819. break;
  1820. }
  1821. }
  1822. result.push(lineStart);
  1823. return result;
  1824. }
  1825. ts.computeLineStarts = computeLineStarts;
  1826. function getPositionOfLineAndCharacter(sourceFile, line, character) {
  1827. return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character);
  1828. }
  1829. ts.getPositionOfLineAndCharacter = getPositionOfLineAndCharacter;
  1830. function computePositionOfLineAndCharacter(lineStarts, line, character) {
  1831. ts.Debug.assert(line >= 0 && line < lineStarts.length);
  1832. return lineStarts[line] + character;
  1833. }
  1834. ts.computePositionOfLineAndCharacter = computePositionOfLineAndCharacter;
  1835. function getLineStarts(sourceFile) {
  1836. return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
  1837. }
  1838. ts.getLineStarts = getLineStarts;
  1839. function computeLineAndCharacterOfPosition(lineStarts, position) {
  1840. var lineNumber = ts.binarySearch(lineStarts, position);
  1841. if (lineNumber < 0) {
  1842. lineNumber = ~lineNumber - 1;
  1843. ts.Debug.assert(lineNumber !== -1, "position cannot precede the beginning of the file");
  1844. }
  1845. return {
  1846. line: lineNumber,
  1847. character: position - lineStarts[lineNumber]
  1848. };
  1849. }
  1850. ts.computeLineAndCharacterOfPosition = computeLineAndCharacterOfPosition;
  1851. function getLineAndCharacterOfPosition(sourceFile, position) {
  1852. return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
  1853. }
  1854. ts.getLineAndCharacterOfPosition = getLineAndCharacterOfPosition;
  1855. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1856. function isWhiteSpace(ch) {
  1857. return ch === 32 ||
  1858. ch === 9 ||
  1859. ch === 11 ||
  1860. ch === 12 ||
  1861. ch === 160 ||
  1862. ch === 133 ||
  1863. ch === 5760 ||
  1864. ch >= 8192 && ch <= 8203 ||
  1865. ch === 8239 ||
  1866. ch === 8287 ||
  1867. ch === 12288 ||
  1868. ch === 65279;
  1869. }
  1870. ts.isWhiteSpace = isWhiteSpace;
  1871. function isLineBreak(ch) {
  1872. // ES5 7.3:
  1873. // The ECMAScript line terminator characters are listed in Table 3.
  1874. // Table 3: Line Terminator Characters
  1875. // Code Unit Value Name Formal Name
  1876. // \u000A Line Feed <LF>
  1877. // \u000D Carriage Return <CR>
  1878. // \u2028 Line separator <LS>
  1879. // \u2029 Paragraph separator <PS>
  1880. // Only the characters in Table 3 are treated as line terminators. Other new line or line
  1881. // breaking characters are treated as white space but not as line terminators.
  1882. return ch === 10 ||
  1883. ch === 13 ||
  1884. ch === 8232 ||
  1885. ch === 8233;
  1886. }
  1887. ts.isLineBreak = isLineBreak;
  1888. function isDigit(ch) {
  1889. return ch >= 48 && ch <= 57;
  1890. }
  1891. function isOctalDigit(ch) {
  1892. return ch >= 48 && ch <= 55;
  1893. }
  1894. ts.isOctalDigit = isOctalDigit;
  1895. function couldStartTrivia(text, pos) {
  1896. var ch = text.charCodeAt(pos);
  1897. switch (ch) {
  1898. case 13:
  1899. case 10:
  1900. case 9:
  1901. case 11:
  1902. case 12:
  1903. case 32:
  1904. case 47:
  1905. case 60:
  1906. case 61:
  1907. case 62:
  1908. return true;
  1909. case 35:
  1910. return pos === 0;
  1911. default:
  1912. return ch > 127;
  1913. }
  1914. }
  1915. ts.couldStartTrivia = couldStartTrivia;
  1916. function skipTrivia(text, pos, stopAfterLineBreak) {
  1917. while (true) {
  1918. var ch = text.charCodeAt(pos);
  1919. switch (ch) {
  1920. case 13:
  1921. if (text.charCodeAt(pos + 1) === 10) {
  1922. pos++;
  1923. }
  1924. case 10:
  1925. pos++;
  1926. if (stopAfterLineBreak) {
  1927. return pos;
  1928. }
  1929. continue;
  1930. case 9:
  1931. case 11:
  1932. case 12:
  1933. case 32:
  1934. pos++;
  1935. continue;
  1936. case 47:
  1937. if (text.charCodeAt(pos + 1) === 47) {
  1938. pos += 2;
  1939. while (pos < text.length) {
  1940. if (isLineBreak(text.charCodeAt(pos))) {
  1941. break;
  1942. }
  1943. pos++;
  1944. }
  1945. continue;
  1946. }
  1947. if (text.charCodeAt(pos + 1) === 42) {
  1948. pos += 2;
  1949. while (pos < text.length) {
  1950. if (text.charCodeAt(pos) === 42 && text.charCodeAt(pos + 1) === 47) {
  1951. pos += 2;
  1952. break;
  1953. }
  1954. pos++;
  1955. }
  1956. continue;
  1957. }
  1958. break;
  1959. case 60:
  1960. case 61:
  1961. case 62:
  1962. if (isConflictMarkerTrivia(text, pos)) {
  1963. pos = scanConflictMarkerTrivia(text, pos);
  1964. continue;
  1965. }
  1966. break;
  1967. case 35:
  1968. if (pos === 0 && isShebangTrivia(text, pos)) {
  1969. pos = scanShebangTrivia(text, pos);
  1970. continue;
  1971. }
  1972. break;
  1973. default:
  1974. if (ch > 127 && (isWhiteSpace(ch) || isLineBreak(ch))) {
  1975. pos++;
  1976. continue;
  1977. }
  1978. break;
  1979. }
  1980. return pos;
  1981. }
  1982. }
  1983. ts.skipTrivia = skipTrivia;
  1984. var mergeConflictMarkerLength = "<<<<<<<".length;
  1985. function isConflictMarkerTrivia(text, pos) {
  1986. ts.Debug.assert(pos >= 0);
  1987. if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) {
  1988. var ch = text.charCodeAt(pos);
  1989. if ((pos + mergeConflictMarkerLength) < text.length) {
  1990. for (var i = 0, n = mergeConflictMarkerLength; i < n; i++) {
  1991. if (text.charCodeAt(pos + i) !== ch) {
  1992. return false;
  1993. }
  1994. }
  1995. return ch === 61 ||
  1996. text.charCodeAt(pos + mergeConflictMarkerLength) === 32;
  1997. }
  1998. }
  1999. return false;
  2000. }
  2001. function scanConflictMarkerTrivia(text, pos, error) {
  2002. if (error) {
  2003. error(ts.Diagnostics.Merge_conflict_marker_encountered, mergeConflictMarkerLength);
  2004. }
  2005. var ch = text.charCodeAt(pos);
  2006. var len = text.length;
  2007. if (ch === 60 || ch === 62) {
  2008. while (pos < len && !isLineBreak(text.charCodeAt(pos))) {
  2009. pos++;
  2010. }
  2011. }
  2012. else {
  2013. ts.Debug.assert(ch === 61);
  2014. while (pos < len) {
  2015. var ch_1 = text.charCodeAt(pos);
  2016. if (ch_1 === 62 && isConflictMarkerTrivia(text, pos)) {
  2017. break;
  2018. }
  2019. pos++;
  2020. }
  2021. }
  2022. return pos;
  2023. }
  2024. var shebangTriviaRegex = /^#!.*/;
  2025. function isShebangTrivia(text, pos) {
  2026. ts.Debug.assert(pos === 0);
  2027. return shebangTriviaRegex.test(text);
  2028. }
  2029. function scanShebangTrivia(text, pos) {
  2030. var shebang = shebangTriviaRegex.exec(text)[0];
  2031. pos = pos + shebang.length;
  2032. return pos;
  2033. }
  2034. function getCommentRanges(text, pos, trailing) {
  2035. var result;
  2036. var collecting = trailing || pos === 0;
  2037. while (true) {
  2038. var ch = text.charCodeAt(pos);
  2039. switch (ch) {
  2040. case 13:
  2041. if (text.charCodeAt(pos + 1) === 10) {
  2042. pos++;
  2043. }
  2044. case 10:
  2045. pos++;
  2046. if (trailing) {
  2047. return result;
  2048. }
  2049. collecting = true;
  2050. if (result && result.length) {
  2051. ts.lastOrUndefined(result).hasTrailingNewLine = true;
  2052. }
  2053. continue;
  2054. case 9:
  2055. case 11:
  2056. case 12:
  2057. case 32:
  2058. pos++;
  2059. continue;
  2060. case 47:
  2061. var nextChar = text.charCodeAt(pos + 1);
  2062. var hasTrailingNewLine = false;
  2063. if (nextChar === 47 || nextChar === 42) {
  2064. var kind = nextChar === 47 ? 2 : 3;
  2065. var startPos = pos;
  2066. pos += 2;
  2067. if (nextChar === 47) {
  2068. while (pos < text.length) {
  2069. if (isLineBreak(text.charCodeAt(pos))) {
  2070. hasTrailingNewLine = true;
  2071. break;
  2072. }
  2073. pos++;
  2074. }
  2075. }
  2076. else {
  2077. while (pos < text.length) {
  2078. if (text.charCodeAt(pos) === 42 && text.charCodeAt(pos + 1) === 47) {
  2079. pos += 2;
  2080. break;
  2081. }
  2082. pos++;
  2083. }
  2084. }
  2085. if (collecting) {
  2086. if (!result) {
  2087. result = [];
  2088. }
  2089. result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine, kind: kind });
  2090. }
  2091. continue;
  2092. }
  2093. break;
  2094. default:
  2095. if (ch > 127 && (isWhiteSpace(ch) || isLineBreak(ch))) {
  2096. if (result && result.length && isLineBreak(ch)) {
  2097. ts.lastOrUndefined(result).hasTrailingNewLine = true;
  2098. }
  2099. pos++;
  2100. continue;
  2101. }
  2102. break;
  2103. }
  2104. return result;
  2105. }
  2106. }
  2107. function getLeadingCommentRanges(text, pos) {
  2108. return getCommentRanges(text, pos, false);
  2109. }
  2110. ts.getLeadingCommentRanges = getLeadingCommentRanges;
  2111. function getTrailingCommentRanges(text, pos) {
  2112. return getCommentRanges(text, pos, true);
  2113. }
  2114. ts.getTrailingCommentRanges = getTrailingCommentRanges;
  2115. function getShebang(text) {
  2116. return shebangTriviaRegex.test(text)
  2117. ? shebangTriviaRegex.exec(text)[0]
  2118. : undefined;
  2119. }
  2120. ts.getShebang = getShebang;
  2121. function isIdentifierStart(ch, languageVersion) {
  2122. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2123. ch === 36 || ch === 95 ||
  2124. ch > 127 && isUnicodeIdentifierStart(ch, languageVersion);
  2125. }
  2126. ts.isIdentifierStart = isIdentifierStart;
  2127. function isIdentifierPart(ch, languageVersion) {
  2128. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2129. ch >= 48 && ch <= 57 || ch === 36 || ch === 95 ||
  2130. ch > 127 && isUnicodeIdentifierPart(ch, languageVersion);
  2131. }
  2132. ts.isIdentifierPart = isIdentifierPart;
  2133. function createScanner(languageVersion, skipTrivia, languageVariant, text, onError, start, length) {
  2134. if (languageVariant === void 0) { languageVariant = 0; }
  2135. var pos;
  2136. var end;
  2137. var startPos;
  2138. var tokenPos;
  2139. var token;
  2140. var tokenValue;
  2141. var precedingLineBreak;
  2142. var hasExtendedUnicodeEscape;
  2143. var tokenIsUnterminated;
  2144. setText(text, start, length);
  2145. return {
  2146. getStartPos: function () { return startPos; },
  2147. getTextPos: function () { return pos; },
  2148. getToken: function () { return token; },
  2149. getTokenPos: function () { return tokenPos; },
  2150. getTokenText: function () { return text.substring(tokenPos, pos); },
  2151. getTokenValue: function () { return tokenValue; },
  2152. hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; },
  2153. hasPrecedingLineBreak: function () { return precedingLineBreak; },
  2154. isIdentifier: function () { return token === 67 || token > 103; },
  2155. isReservedWord: function () { return token >= 68 && token <= 103; },
  2156. isUnterminated: function () { return tokenIsUnterminated; },
  2157. reScanGreaterToken: reScanGreaterToken,
  2158. reScanSlashToken: reScanSlashToken,
  2159. reScanTemplateToken: reScanTemplateToken,
  2160. scanJsxIdentifier: scanJsxIdentifier,
  2161. reScanJsxToken: reScanJsxToken,
  2162. scanJsxToken: scanJsxToken,
  2163. scan: scan,
  2164. setText: setText,
  2165. setScriptTarget: setScriptTarget,
  2166. setLanguageVariant: setLanguageVariant,
  2167. setOnError: setOnError,
  2168. setTextPos: setTextPos,
  2169. tryScan: tryScan,
  2170. lookAhead: lookAhead
  2171. };
  2172. function error(message, length) {
  2173. if (onError) {
  2174. onError(message, length || 0);
  2175. }
  2176. }
  2177. function isIdentifierStart(ch) {
  2178. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2179. ch === 36 || ch === 95 ||
  2180. ch > 127 && isUnicodeIdentifierStart(ch, languageVersion);
  2181. }
  2182. function isIdentifierPart(ch) {
  2183. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2184. ch >= 48 && ch <= 57 || ch === 36 || ch === 95 ||
  2185. ch > 127 && isUnicodeIdentifierPart(ch, languageVersion);
  2186. }
  2187. function scanNumber() {
  2188. var start = pos;
  2189. while (isDigit(text.charCodeAt(pos)))
  2190. pos++;
  2191. if (text.charCodeAt(pos) === 46) {
  2192. pos++;
  2193. while (isDigit(text.charCodeAt(pos)))
  2194. pos++;
  2195. }
  2196. var end = pos;
  2197. if (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101) {
  2198. pos++;
  2199. if (text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45)
  2200. pos++;
  2201. if (isDigit(text.charCodeAt(pos))) {
  2202. pos++;
  2203. while (isDigit(text.charCodeAt(pos)))
  2204. pos++;
  2205. end = pos;
  2206. }
  2207. else {
  2208. error(ts.Diagnostics.Digit_expected);
  2209. }
  2210. }
  2211. return +(text.substring(start, end));
  2212. }
  2213. function scanOctalDigits() {
  2214. var start = pos;
  2215. while (isOctalDigit(text.charCodeAt(pos))) {
  2216. pos++;
  2217. }
  2218. return +(text.substring(start, pos));
  2219. }
  2220. function scanExactNumberOfHexDigits(count) {
  2221. return scanHexDigits(count, false);
  2222. }
  2223. function scanMinimumNumberOfHexDigits(count) {
  2224. return scanHexDigits(count, true);
  2225. }
  2226. function scanHexDigits(minCount, scanAsManyAsPossible) {
  2227. var digits = 0;
  2228. var value = 0;
  2229. while (digits < minCount || scanAsManyAsPossible) {
  2230. var ch = text.charCodeAt(pos);
  2231. if (ch >= 48 && ch <= 57) {
  2232. value = value * 16 + ch - 48;
  2233. }
  2234. else if (ch >= 65 && ch <= 70) {
  2235. value = value * 16 + ch - 65 + 10;
  2236. }
  2237. else if (ch >= 97 && ch <= 102) {
  2238. value = value * 16 + ch - 97 + 10;
  2239. }
  2240. else {
  2241. break;
  2242. }
  2243. pos++;
  2244. digits++;
  2245. }
  2246. if (digits < minCount) {
  2247. value = -1;
  2248. }
  2249. return value;
  2250. }
  2251. function scanString() {
  2252. var quote = text.charCodeAt(pos++);
  2253. var result = "";
  2254. var start = pos;
  2255. while (true) {
  2256. if (pos >= end) {
  2257. result += text.substring(start, pos);
  2258. tokenIsUnterminated = true;
  2259. error(ts.Diagnostics.Unterminated_string_literal);
  2260. break;
  2261. }
  2262. var ch = text.charCodeAt(pos);
  2263. if (ch === quote) {
  2264. result += text.substring(start, pos);
  2265. pos++;
  2266. break;
  2267. }
  2268. if (ch === 92) {
  2269. result += text.substring(start, pos);
  2270. result += scanEscapeSequence();
  2271. start = pos;
  2272. continue;
  2273. }
  2274. if (isLineBreak(ch)) {
  2275. result += text.substring(start, pos);
  2276. tokenIsUnterminated = true;
  2277. error(ts.Diagnostics.Unterminated_string_literal);
  2278. break;
  2279. }
  2280. pos++;
  2281. }
  2282. return result;
  2283. }
  2284. function scanTemplateAndSetTokenValue() {
  2285. var startedWithBacktick = text.charCodeAt(pos) === 96;
  2286. pos++;
  2287. var start = pos;
  2288. var contents = "";
  2289. var resultingToken;
  2290. while (true) {
  2291. if (pos >= end) {
  2292. contents += text.substring(start, pos);
  2293. tokenIsUnterminated = true;
  2294. error(ts.Diagnostics.Unterminated_template_literal);
  2295. resultingToken = startedWithBacktick ? 11 : 14;
  2296. break;
  2297. }
  2298. var currChar = text.charCodeAt(pos);
  2299. if (currChar === 96) {
  2300. contents += text.substring(start, pos);
  2301. pos++;
  2302. resultingToken = startedWithBacktick ? 11 : 14;
  2303. break;
  2304. }
  2305. if (currChar === 36 && pos + 1 < end && text.charCodeAt(pos + 1) === 123) {
  2306. contents += text.substring(start, pos);
  2307. pos += 2;
  2308. resultingToken = startedWithBacktick ? 12 : 13;
  2309. break;
  2310. }
  2311. if (currChar === 92) {
  2312. contents += text.substring(start, pos);
  2313. contents += scanEscapeSequence();
  2314. start = pos;
  2315. continue;
  2316. }
  2317. if (currChar === 13) {
  2318. contents += text.substring(start, pos);
  2319. pos++;
  2320. if (pos < end && text.charCodeAt(pos) === 10) {
  2321. pos++;
  2322. }
  2323. contents += "\n";
  2324. start = pos;
  2325. continue;
  2326. }
  2327. pos++;
  2328. }
  2329. ts.Debug.assert(resultingToken !== undefined);
  2330. tokenValue = contents;
  2331. return resultingToken;
  2332. }
  2333. function scanEscapeSequence() {
  2334. pos++;
  2335. if (pos >= end) {
  2336. error(ts.Diagnostics.Unexpected_end_of_text);
  2337. return "";
  2338. }
  2339. var ch = text.charCodeAt(pos++);
  2340. switch (ch) {
  2341. case 48:
  2342. return "\0";
  2343. case 98:
  2344. return "\b";
  2345. case 116:
  2346. return "\t";
  2347. case 110:
  2348. return "\n";
  2349. case 118:
  2350. return "\v";
  2351. case 102:
  2352. return "\f";
  2353. case 114:
  2354. return "\r";
  2355. case 39:
  2356. return "\'";
  2357. case 34:
  2358. return "\"";
  2359. case 117:
  2360. if (pos < end && text.charCodeAt(pos) === 123) {
  2361. hasExtendedUnicodeEscape = true;
  2362. pos++;
  2363. return scanExtendedUnicodeEscape();
  2364. }
  2365. return scanHexadecimalEscape(4);
  2366. case 120:
  2367. return scanHexadecimalEscape(2);
  2368. case 13:
  2369. if (pos < end && text.charCodeAt(pos) === 10) {
  2370. pos++;
  2371. }
  2372. case 10:
  2373. case 8232:
  2374. case 8233:
  2375. return "";
  2376. default:
  2377. return String.fromCharCode(ch);
  2378. }
  2379. }
  2380. function scanHexadecimalEscape(numDigits) {
  2381. var escapedValue = scanExactNumberOfHexDigits(numDigits);
  2382. if (escapedValue >= 0) {
  2383. return String.fromCharCode(escapedValue);
  2384. }
  2385. else {
  2386. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2387. return "";
  2388. }
  2389. }
  2390. function scanExtendedUnicodeEscape() {
  2391. var escapedValue = scanMinimumNumberOfHexDigits(1);
  2392. var isInvalidExtendedEscape = false;
  2393. if (escapedValue < 0) {
  2394. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2395. isInvalidExtendedEscape = true;
  2396. }
  2397. else if (escapedValue > 0x10FFFF) {
  2398. error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive);
  2399. isInvalidExtendedEscape = true;
  2400. }
  2401. if (pos >= end) {
  2402. error(ts.Diagnostics.Unexpected_end_of_text);
  2403. isInvalidExtendedEscape = true;
  2404. }
  2405. else if (text.charCodeAt(pos) === 125) {
  2406. pos++;
  2407. }
  2408. else {
  2409. error(ts.Diagnostics.Unterminated_Unicode_escape_sequence);
  2410. isInvalidExtendedEscape = true;
  2411. }
  2412. if (isInvalidExtendedEscape) {
  2413. return "";
  2414. }
  2415. return utf16EncodeAsString(escapedValue);
  2416. }
  2417. function utf16EncodeAsString(codePoint) {
  2418. ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF);
  2419. if (codePoint <= 65535) {
  2420. return String.fromCharCode(codePoint);
  2421. }
  2422. var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800;
  2423. var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00;
  2424. return String.fromCharCode(codeUnit1, codeUnit2);
  2425. }
  2426. function peekUnicodeEscape() {
  2427. if (pos + 5 < end && text.charCodeAt(pos + 1) === 117) {
  2428. var start_1 = pos;
  2429. pos += 2;
  2430. var value = scanExactNumberOfHexDigits(4);
  2431. pos = start_1;
  2432. return value;
  2433. }
  2434. return -1;
  2435. }
  2436. function scanIdentifierParts() {
  2437. var result = "";
  2438. var start = pos;
  2439. while (pos < end) {
  2440. var ch = text.charCodeAt(pos);
  2441. if (isIdentifierPart(ch)) {
  2442. pos++;
  2443. }
  2444. else if (ch === 92) {
  2445. ch = peekUnicodeEscape();
  2446. if (!(ch >= 0 && isIdentifierPart(ch))) {
  2447. break;
  2448. }
  2449. result += text.substring(start, pos);
  2450. result += String.fromCharCode(ch);
  2451. pos += 6;
  2452. start = pos;
  2453. }
  2454. else {
  2455. break;
  2456. }
  2457. }
  2458. result += text.substring(start, pos);
  2459. return result;
  2460. }
  2461. function getIdentifierToken() {
  2462. var len = tokenValue.length;
  2463. if (len >= 2 && len <= 11) {
  2464. var ch = tokenValue.charCodeAt(0);
  2465. if (ch >= 97 && ch <= 122 && hasOwnProperty.call(textToToken, tokenValue)) {
  2466. return token = textToToken[tokenValue];
  2467. }
  2468. }
  2469. return token = 67;
  2470. }
  2471. function scanBinaryOrOctalDigits(base) {
  2472. ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8");
  2473. var value = 0;
  2474. var numberOfDigits = 0;
  2475. while (true) {
  2476. var ch = text.charCodeAt(pos);
  2477. var valueOfCh = ch - 48;
  2478. if (!isDigit(ch) || valueOfCh >= base) {
  2479. break;
  2480. }
  2481. value = value * base + valueOfCh;
  2482. pos++;
  2483. numberOfDigits++;
  2484. }
  2485. if (numberOfDigits === 0) {
  2486. return -1;
  2487. }
  2488. return value;
  2489. }
  2490. function scan() {
  2491. startPos = pos;
  2492. hasExtendedUnicodeEscape = false;
  2493. precedingLineBreak = false;
  2494. tokenIsUnterminated = false;
  2495. while (true) {
  2496. tokenPos = pos;
  2497. if (pos >= end) {
  2498. return token = 1;
  2499. }
  2500. var ch = text.charCodeAt(pos);
  2501. if (ch === 35 && pos === 0 && isShebangTrivia(text, pos)) {
  2502. pos = scanShebangTrivia(text, pos);
  2503. if (skipTrivia) {
  2504. continue;
  2505. }
  2506. else {
  2507. return token = 6;
  2508. }
  2509. }
  2510. switch (ch) {
  2511. case 10:
  2512. case 13:
  2513. precedingLineBreak = true;
  2514. if (skipTrivia) {
  2515. pos++;
  2516. continue;
  2517. }
  2518. else {
  2519. if (ch === 13 && pos + 1 < end && text.charCodeAt(pos + 1) === 10) {
  2520. pos += 2;
  2521. }
  2522. else {
  2523. pos++;
  2524. }
  2525. return token = 4;
  2526. }
  2527. case 9:
  2528. case 11:
  2529. case 12:
  2530. case 32:
  2531. if (skipTrivia) {
  2532. pos++;
  2533. continue;
  2534. }
  2535. else {
  2536. while (pos < end && isWhiteSpace(text.charCodeAt(pos))) {
  2537. pos++;
  2538. }
  2539. return token = 5;
  2540. }
  2541. case 33:
  2542. if (text.charCodeAt(pos + 1) === 61) {
  2543. if (text.charCodeAt(pos + 2) === 61) {
  2544. return pos += 3, token = 33;
  2545. }
  2546. return pos += 2, token = 31;
  2547. }
  2548. return pos++, token = 48;
  2549. case 34:
  2550. case 39:
  2551. tokenValue = scanString();
  2552. return token = 9;
  2553. case 96:
  2554. return token = scanTemplateAndSetTokenValue();
  2555. case 37:
  2556. if (text.charCodeAt(pos + 1) === 61) {
  2557. return pos += 2, token = 60;
  2558. }
  2559. return pos++, token = 39;
  2560. case 38:
  2561. if (text.charCodeAt(pos + 1) === 38) {
  2562. return pos += 2, token = 50;
  2563. }
  2564. if (text.charCodeAt(pos + 1) === 61) {
  2565. return pos += 2, token = 64;
  2566. }
  2567. return pos++, token = 45;
  2568. case 40:
  2569. return pos++, token = 17;
  2570. case 41:
  2571. return pos++, token = 18;
  2572. case 42:
  2573. if (text.charCodeAt(pos + 1) === 61) {
  2574. return pos += 2, token = 58;
  2575. }
  2576. return pos++, token = 37;
  2577. case 43:
  2578. if (text.charCodeAt(pos + 1) === 43) {
  2579. return pos += 2, token = 40;
  2580. }
  2581. if (text.charCodeAt(pos + 1) === 61) {
  2582. return pos += 2, token = 56;
  2583. }
  2584. return pos++, token = 35;
  2585. case 44:
  2586. return pos++, token = 24;
  2587. case 45:
  2588. if (text.charCodeAt(pos + 1) === 45) {
  2589. return pos += 2, token = 41;
  2590. }
  2591. if (text.charCodeAt(pos + 1) === 61) {
  2592. return pos += 2, token = 57;
  2593. }
  2594. return pos++, token = 36;
  2595. case 46:
  2596. if (isDigit(text.charCodeAt(pos + 1))) {
  2597. tokenValue = "" + scanNumber();
  2598. return token = 8;
  2599. }
  2600. if (text.charCodeAt(pos + 1) === 46 && text.charCodeAt(pos + 2) === 46) {
  2601. return pos += 3, token = 22;
  2602. }
  2603. return pos++, token = 21;
  2604. case 47:
  2605. if (text.charCodeAt(pos + 1) === 47) {
  2606. pos += 2;
  2607. while (pos < end) {
  2608. if (isLineBreak(text.charCodeAt(pos))) {
  2609. break;
  2610. }
  2611. pos++;
  2612. }
  2613. if (skipTrivia) {
  2614. continue;
  2615. }
  2616. else {
  2617. return token = 2;
  2618. }
  2619. }
  2620. if (text.charCodeAt(pos + 1) === 42) {
  2621. pos += 2;
  2622. var commentClosed = false;
  2623. while (pos < end) {
  2624. var ch_2 = text.charCodeAt(pos);
  2625. if (ch_2 === 42 && text.charCodeAt(pos + 1) === 47) {
  2626. pos += 2;
  2627. commentClosed = true;
  2628. break;
  2629. }
  2630. if (isLineBreak(ch_2)) {
  2631. precedingLineBreak = true;
  2632. }
  2633. pos++;
  2634. }
  2635. if (!commentClosed) {
  2636. error(ts.Diagnostics.Asterisk_Slash_expected);
  2637. }
  2638. if (skipTrivia) {
  2639. continue;
  2640. }
  2641. else {
  2642. tokenIsUnterminated = !commentClosed;
  2643. return token = 3;
  2644. }
  2645. }
  2646. if (text.charCodeAt(pos + 1) === 61) {
  2647. return pos += 2, token = 59;
  2648. }
  2649. return pos++, token = 38;
  2650. case 48:
  2651. if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) {
  2652. pos += 2;
  2653. var value = scanMinimumNumberOfHexDigits(1);
  2654. if (value < 0) {
  2655. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2656. value = 0;
  2657. }
  2658. tokenValue = "" + value;
  2659. return token = 8;
  2660. }
  2661. else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 || text.charCodeAt(pos + 1) === 98)) {
  2662. pos += 2;
  2663. var value = scanBinaryOrOctalDigits(2);
  2664. if (value < 0) {
  2665. error(ts.Diagnostics.Binary_digit_expected);
  2666. value = 0;
  2667. }
  2668. tokenValue = "" + value;
  2669. return token = 8;
  2670. }
  2671. else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 || text.charCodeAt(pos + 1) === 111)) {
  2672. pos += 2;
  2673. var value = scanBinaryOrOctalDigits(8);
  2674. if (value < 0) {
  2675. error(ts.Diagnostics.Octal_digit_expected);
  2676. value = 0;
  2677. }
  2678. tokenValue = "" + value;
  2679. return token = 8;
  2680. }
  2681. if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) {
  2682. tokenValue = "" + scanOctalDigits();
  2683. return token = 8;
  2684. }
  2685. case 49:
  2686. case 50:
  2687. case 51:
  2688. case 52:
  2689. case 53:
  2690. case 54:
  2691. case 55:
  2692. case 56:
  2693. case 57:
  2694. tokenValue = "" + scanNumber();
  2695. return token = 8;
  2696. case 58:
  2697. return pos++, token = 53;
  2698. case 59:
  2699. return pos++, token = 23;
  2700. case 60:
  2701. if (isConflictMarkerTrivia(text, pos)) {
  2702. pos = scanConflictMarkerTrivia(text, pos, error);
  2703. if (skipTrivia) {
  2704. continue;
  2705. }
  2706. else {
  2707. return token = 7;
  2708. }
  2709. }
  2710. if (text.charCodeAt(pos + 1) === 60) {
  2711. if (text.charCodeAt(pos + 2) === 61) {
  2712. return pos += 3, token = 61;
  2713. }
  2714. return pos += 2, token = 42;
  2715. }
  2716. if (text.charCodeAt(pos + 1) === 61) {
  2717. return pos += 2, token = 28;
  2718. }
  2719. if (text.charCodeAt(pos + 1) === 47 && languageVariant === 1) {
  2720. return pos += 2, token = 26;
  2721. }
  2722. return pos++, token = 25;
  2723. case 61:
  2724. if (isConflictMarkerTrivia(text, pos)) {
  2725. pos = scanConflictMarkerTrivia(text, pos, error);
  2726. if (skipTrivia) {
  2727. continue;
  2728. }
  2729. else {
  2730. return token = 7;
  2731. }
  2732. }
  2733. if (text.charCodeAt(pos + 1) === 61) {
  2734. if (text.charCodeAt(pos + 2) === 61) {
  2735. return pos += 3, token = 32;
  2736. }
  2737. return pos += 2, token = 30;
  2738. }
  2739. if (text.charCodeAt(pos + 1) === 62) {
  2740. return pos += 2, token = 34;
  2741. }
  2742. return pos++, token = 55;
  2743. case 62:
  2744. if (isConflictMarkerTrivia(text, pos)) {
  2745. pos = scanConflictMarkerTrivia(text, pos, error);
  2746. if (skipTrivia) {
  2747. continue;
  2748. }
  2749. else {
  2750. return token = 7;
  2751. }
  2752. }
  2753. return pos++, token = 27;
  2754. case 63:
  2755. return pos++, token = 52;
  2756. case 91:
  2757. return pos++, token = 19;
  2758. case 93:
  2759. return pos++, token = 20;
  2760. case 94:
  2761. if (text.charCodeAt(pos + 1) === 61) {
  2762. return pos += 2, token = 66;
  2763. }
  2764. return pos++, token = 47;
  2765. case 123:
  2766. return pos++, token = 15;
  2767. case 124:
  2768. if (text.charCodeAt(pos + 1) === 124) {
  2769. return pos += 2, token = 51;
  2770. }
  2771. if (text.charCodeAt(pos + 1) === 61) {
  2772. return pos += 2, token = 65;
  2773. }
  2774. return pos++, token = 46;
  2775. case 125:
  2776. return pos++, token = 16;
  2777. case 126:
  2778. return pos++, token = 49;
  2779. case 64:
  2780. return pos++, token = 54;
  2781. case 92:
  2782. var cookedChar = peekUnicodeEscape();
  2783. if (cookedChar >= 0 && isIdentifierStart(cookedChar)) {
  2784. pos += 6;
  2785. tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
  2786. return token = getIdentifierToken();
  2787. }
  2788. error(ts.Diagnostics.Invalid_character);
  2789. return pos++, token = 0;
  2790. default:
  2791. if (isIdentifierStart(ch)) {
  2792. pos++;
  2793. while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos)))
  2794. pos++;
  2795. tokenValue = text.substring(tokenPos, pos);
  2796. if (ch === 92) {
  2797. tokenValue += scanIdentifierParts();
  2798. }
  2799. return token = getIdentifierToken();
  2800. }
  2801. else if (isWhiteSpace(ch)) {
  2802. pos++;
  2803. continue;
  2804. }
  2805. else if (isLineBreak(ch)) {
  2806. precedingLineBreak = true;
  2807. pos++;
  2808. continue;
  2809. }
  2810. error(ts.Diagnostics.Invalid_character);
  2811. return pos++, token = 0;
  2812. }
  2813. }
  2814. }
  2815. function reScanGreaterToken() {
  2816. if (token === 27) {
  2817. if (text.charCodeAt(pos) === 62) {
  2818. if (text.charCodeAt(pos + 1) === 62) {
  2819. if (text.charCodeAt(pos + 2) === 61) {
  2820. return pos += 3, token = 63;
  2821. }
  2822. return pos += 2, token = 44;
  2823. }
  2824. if (text.charCodeAt(pos + 1) === 61) {
  2825. return pos += 2, token = 62;
  2826. }
  2827. return pos++, token = 43;
  2828. }
  2829. if (text.charCodeAt(pos) === 61) {
  2830. return pos++, token = 29;
  2831. }
  2832. }
  2833. return token;
  2834. }
  2835. function reScanSlashToken() {
  2836. if (token === 38 || token === 59) {
  2837. var p = tokenPos + 1;
  2838. var inEscape = false;
  2839. var inCharacterClass = false;
  2840. while (true) {
  2841. if (p >= end) {
  2842. tokenIsUnterminated = true;
  2843. error(ts.Diagnostics.Unterminated_regular_expression_literal);
  2844. break;
  2845. }
  2846. var ch = text.charCodeAt(p);
  2847. if (isLineBreak(ch)) {
  2848. tokenIsUnterminated = true;
  2849. error(ts.Diagnostics.Unterminated_regular_expression_literal);
  2850. break;
  2851. }
  2852. if (inEscape) {
  2853. inEscape = false;
  2854. }
  2855. else if (ch === 47 && !inCharacterClass) {
  2856. p++;
  2857. break;
  2858. }
  2859. else if (ch === 91) {
  2860. inCharacterClass = true;
  2861. }
  2862. else if (ch === 92) {
  2863. inEscape = true;
  2864. }
  2865. else if (ch === 93) {
  2866. inCharacterClass = false;
  2867. }
  2868. p++;
  2869. }
  2870. while (p < end && isIdentifierPart(text.charCodeAt(p))) {
  2871. p++;
  2872. }
  2873. pos = p;
  2874. tokenValue = text.substring(tokenPos, pos);
  2875. token = 10;
  2876. }
  2877. return token;
  2878. }
  2879. function reScanTemplateToken() {
  2880. ts.Debug.assert(token === 16, "'reScanTemplateToken' should only be called on a '}'");
  2881. pos = tokenPos;
  2882. return token = scanTemplateAndSetTokenValue();
  2883. }
  2884. function reScanJsxToken() {
  2885. pos = tokenPos = startPos;
  2886. return token = scanJsxToken();
  2887. }
  2888. function scanJsxToken() {
  2889. startPos = tokenPos = pos;
  2890. if (pos >= end) {
  2891. return token = 1;
  2892. }
  2893. var char = text.charCodeAt(pos);
  2894. if (char === 60) {
  2895. if (text.charCodeAt(pos + 1) === 47) {
  2896. pos += 2;
  2897. return token = 26;
  2898. }
  2899. pos++;
  2900. return token = 25;
  2901. }
  2902. if (char === 123) {
  2903. pos++;
  2904. return token = 15;
  2905. }
  2906. while (pos < end) {
  2907. pos++;
  2908. char = text.charCodeAt(pos);
  2909. if ((char === 123) || (char === 60)) {
  2910. break;
  2911. }
  2912. }
  2913. return token = 234;
  2914. }
  2915. function scanJsxIdentifier() {
  2916. if (token === 67) {
  2917. var firstCharPosition = pos;
  2918. while (pos < end) {
  2919. var ch = text.charCodeAt(pos);
  2920. if (ch === 45 || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) {
  2921. pos++;
  2922. }
  2923. else {
  2924. break;
  2925. }
  2926. }
  2927. tokenValue += text.substr(firstCharPosition, pos - firstCharPosition);
  2928. }
  2929. return token;
  2930. }
  2931. function speculationHelper(callback, isLookahead) {
  2932. var savePos = pos;
  2933. var saveStartPos = startPos;
  2934. var saveTokenPos = tokenPos;
  2935. var saveToken = token;
  2936. var saveTokenValue = tokenValue;
  2937. var savePrecedingLineBreak = precedingLineBreak;
  2938. var result = callback();
  2939. if (!result || isLookahead) {
  2940. pos = savePos;
  2941. startPos = saveStartPos;
  2942. tokenPos = saveTokenPos;
  2943. token = saveToken;
  2944. tokenValue = saveTokenValue;
  2945. precedingLineBreak = savePrecedingLineBreak;
  2946. }
  2947. return result;
  2948. }
  2949. function lookAhead(callback) {
  2950. return speculationHelper(callback, true);
  2951. }
  2952. function tryScan(callback) {
  2953. return speculationHelper(callback, false);
  2954. }
  2955. function setText(newText, start, length) {
  2956. text = newText || "";
  2957. end = length === undefined ? text.length : start + length;
  2958. setTextPos(start || 0);
  2959. }
  2960. function setOnError(errorCallback) {
  2961. onError = errorCallback;
  2962. }
  2963. function setScriptTarget(scriptTarget) {
  2964. languageVersion = scriptTarget;
  2965. }
  2966. function setLanguageVariant(variant) {
  2967. languageVariant = variant;
  2968. }
  2969. function setTextPos(textPos) {
  2970. ts.Debug.assert(textPos >= 0);
  2971. pos = textPos;
  2972. startPos = textPos;
  2973. tokenPos = textPos;
  2974. token = 0;
  2975. precedingLineBreak = false;
  2976. tokenValue = undefined;
  2977. hasExtendedUnicodeEscape = false;
  2978. tokenIsUnterminated = false;
  2979. }
  2980. }
  2981. ts.createScanner = createScanner;
  2982. })(ts || (ts = {}));
  2983. /// <reference path="parser.ts"/>
  2984. var ts;
  2985. (function (ts) {
  2986. ts.bindTime = 0;
  2987. function getModuleInstanceState(node) {
  2988. if (node.kind === 213 || node.kind === 214) {
  2989. return 0;
  2990. }
  2991. else if (ts.isConstEnumDeclaration(node)) {
  2992. return 2;
  2993. }
  2994. else if ((node.kind === 220 || node.kind === 219) && !(node.flags & 1)) {
  2995. return 0;
  2996. }
  2997. else if (node.kind === 217) {
  2998. var state = 0;
  2999. ts.forEachChild(node, function (n) {
  3000. switch (getModuleInstanceState(n)) {
  3001. case 0:
  3002. return false;
  3003. case 2:
  3004. state = 2;
  3005. return false;
  3006. case 1:
  3007. state = 1;
  3008. return true;
  3009. }
  3010. });
  3011. return state;
  3012. }
  3013. else if (node.kind === 216) {
  3014. return getModuleInstanceState(node.body);
  3015. }
  3016. else {
  3017. return 1;
  3018. }
  3019. }
  3020. ts.getModuleInstanceState = getModuleInstanceState;
  3021. function bindSourceFile(file) {
  3022. var start = new Date().getTime();
  3023. bindSourceFileWorker(file);
  3024. ts.bindTime += new Date().getTime() - start;
  3025. }
  3026. ts.bindSourceFile = bindSourceFile;
  3027. function bindSourceFileWorker(file) {
  3028. var parent;
  3029. var container;
  3030. var blockScopeContainer;
  3031. var lastContainer;
  3032. var inStrictMode = !!file.externalModuleIndicator;
  3033. var symbolCount = 0;
  3034. var Symbol = ts.objectAllocator.getSymbolConstructor();
  3035. var classifiableNames = {};
  3036. if (!file.locals) {
  3037. bind(file);
  3038. file.symbolCount = symbolCount;
  3039. file.classifiableNames = classifiableNames;
  3040. }
  3041. return;
  3042. function createSymbol(flags, name) {
  3043. symbolCount++;
  3044. return new Symbol(flags, name);
  3045. }
  3046. function addDeclarationToSymbol(symbol, node, symbolFlags) {
  3047. symbol.flags |= symbolFlags;
  3048. node.symbol = symbol;
  3049. if (!symbol.declarations) {
  3050. symbol.declarations = [];
  3051. }
  3052. symbol.declarations.push(node);
  3053. if (symbolFlags & 1952 && !symbol.exports) {
  3054. symbol.exports = {};
  3055. }
  3056. if (symbolFlags & 6240 && !symbol.members) {
  3057. symbol.members = {};
  3058. }
  3059. if (symbolFlags & 107455 && !symbol.valueDeclaration) {
  3060. symbol.valueDeclaration = node;
  3061. }
  3062. }
  3063. function getDeclarationName(node) {
  3064. if (node.name) {
  3065. if (node.kind === 216 && node.name.kind === 9) {
  3066. return "\"" + node.name.text + "\"";
  3067. }
  3068. if (node.name.kind === 134) {
  3069. var nameExpression = node.name.expression;
  3070. ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression));
  3071. return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text);
  3072. }
  3073. return node.name.text;
  3074. }
  3075. switch (node.kind) {
  3076. case 142:
  3077. return "__constructor";
  3078. case 150:
  3079. case 145:
  3080. return "__call";
  3081. case 151:
  3082. case 146:
  3083. return "__new";
  3084. case 147:
  3085. return "__index";
  3086. case 226:
  3087. return "__export";
  3088. case 225:
  3089. return node.isExportEquals ? "export=" : "default";
  3090. case 211:
  3091. case 212:
  3092. return node.flags & 1024 ? "default" : undefined;
  3093. }
  3094. }
  3095. function getDisplayName(node) {
  3096. return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node);
  3097. }
  3098. function declareSymbol(symbolTable, parent, node, includes, excludes) {
  3099. ts.Debug.assert(!ts.hasDynamicName(node));
  3100. var name = node.flags & 1024 && parent ? "default" : getDeclarationName(node);
  3101. var symbol;
  3102. if (name !== undefined) {
  3103. symbol = ts.hasProperty(symbolTable, name)
  3104. ? symbolTable[name]
  3105. : (symbolTable[name] = createSymbol(0, name));
  3106. if (name && (includes & 788448)) {
  3107. classifiableNames[name] = name;
  3108. }
  3109. if (symbol.flags & excludes) {
  3110. if (node.name) {
  3111. node.name.parent = node;
  3112. }
  3113. var message = symbol.flags & 2
  3114. ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
  3115. : ts.Diagnostics.Duplicate_identifier_0;
  3116. ts.forEach(symbol.declarations, function (declaration) {
  3117. file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
  3118. });
  3119. file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node)));
  3120. symbol = createSymbol(0, name);
  3121. }
  3122. }
  3123. else {
  3124. symbol = createSymbol(0, "__missing");
  3125. }
  3126. addDeclarationToSymbol(symbol, node, includes);
  3127. symbol.parent = parent;
  3128. return symbol;
  3129. }
  3130. function declareModuleMember(node, symbolFlags, symbolExcludes) {
  3131. var hasExportModifier = ts.getCombinedNodeFlags(node) & 1;
  3132. if (symbolFlags & 8388608) {
  3133. if (node.kind === 228 || (node.kind === 219 && hasExportModifier)) {
  3134. return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
  3135. }
  3136. else {
  3137. return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
  3138. }
  3139. }
  3140. else {
  3141. if (hasExportModifier || container.flags & 262144) {
  3142. var exportKind = (symbolFlags & 107455 ? 1048576 : 0) |
  3143. (symbolFlags & 793056 ? 2097152 : 0) |
  3144. (symbolFlags & 1536 ? 4194304 : 0);
  3145. var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
  3146. local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
  3147. node.localSymbol = local;
  3148. return local;
  3149. }
  3150. else {
  3151. return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
  3152. }
  3153. }
  3154. }
  3155. function bindChildren(node) {
  3156. var saveParent = parent;
  3157. var saveContainer = container;
  3158. var savedBlockScopeContainer = blockScopeContainer;
  3159. parent = node;
  3160. var containerFlags = getContainerFlags(node);
  3161. if (containerFlags & 1) {
  3162. container = blockScopeContainer = node;
  3163. if (containerFlags & 4) {
  3164. container.locals = {};
  3165. }
  3166. addToContainerChain(container);
  3167. }
  3168. else if (containerFlags & 2) {
  3169. blockScopeContainer = node;
  3170. blockScopeContainer.locals = undefined;
  3171. }
  3172. ts.forEachChild(node, bind);
  3173. container = saveContainer;
  3174. parent = saveParent;
  3175. blockScopeContainer = savedBlockScopeContainer;
  3176. }
  3177. function getContainerFlags(node) {
  3178. switch (node.kind) {
  3179. case 184:
  3180. case 212:
  3181. case 213:
  3182. case 215:
  3183. case 153:
  3184. case 163:
  3185. return 1;
  3186. case 145:
  3187. case 146:
  3188. case 147:
  3189. case 141:
  3190. case 140:
  3191. case 211:
  3192. case 142:
  3193. case 143:
  3194. case 144:
  3195. case 150:
  3196. case 151:
  3197. case 171:
  3198. case 172:
  3199. case 216:
  3200. case 246:
  3201. case 214:
  3202. return 5;
  3203. case 242:
  3204. case 197:
  3205. case 198:
  3206. case 199:
  3207. case 218:
  3208. return 2;
  3209. case 190:
  3210. return ts.isFunctionLike(node.parent) ? 0 : 2;
  3211. }
  3212. return 0;
  3213. }
  3214. function addToContainerChain(next) {
  3215. if (lastContainer) {
  3216. lastContainer.nextContainer = next;
  3217. }
  3218. lastContainer = next;
  3219. }
  3220. function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
  3221. declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
  3222. }
  3223. function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) {
  3224. switch (container.kind) {
  3225. case 216:
  3226. return declareModuleMember(node, symbolFlags, symbolExcludes);
  3227. case 246:
  3228. return declareSourceFileMember(node, symbolFlags, symbolExcludes);
  3229. case 184:
  3230. case 212:
  3231. return declareClassMember(node, symbolFlags, symbolExcludes);
  3232. case 215:
  3233. return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
  3234. case 153:
  3235. case 163:
  3236. case 213:
  3237. return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
  3238. case 150:
  3239. case 151:
  3240. case 145:
  3241. case 146:
  3242. case 147:
  3243. case 141:
  3244. case 140:
  3245. case 142:
  3246. case 143:
  3247. case 144:
  3248. case 211:
  3249. case 171:
  3250. case 172:
  3251. case 214:
  3252. return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
  3253. }
  3254. }
  3255. function declareClassMember(node, symbolFlags, symbolExcludes) {
  3256. return node.flags & 128
  3257. ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes)
  3258. : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
  3259. }
  3260. function declareSourceFileMember(node, symbolFlags, symbolExcludes) {
  3261. return ts.isExternalModule(file)
  3262. ? declareModuleMember(node, symbolFlags, symbolExcludes)
  3263. : declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
  3264. }
  3265. function isAmbientContext(node) {
  3266. while (node) {
  3267. if (node.flags & 2) {
  3268. return true;
  3269. }
  3270. node = node.parent;
  3271. }
  3272. return false;
  3273. }
  3274. function hasExportDeclarations(node) {
  3275. var body = node.kind === 246 ? node : node.body;
  3276. if (body.kind === 246 || body.kind === 217) {
  3277. for (var _i = 0, _a = body.statements; _i < _a.length; _i++) {
  3278. var stat = _a[_i];
  3279. if (stat.kind === 226 || stat.kind === 225) {
  3280. return true;
  3281. }
  3282. }
  3283. }
  3284. return false;
  3285. }
  3286. function setExportContextFlag(node) {
  3287. if (isAmbientContext(node) && !hasExportDeclarations(node)) {
  3288. node.flags |= 262144;
  3289. }
  3290. else {
  3291. node.flags &= ~262144;
  3292. }
  3293. }
  3294. function bindModuleDeclaration(node) {
  3295. setExportContextFlag(node);
  3296. if (node.name.kind === 9) {
  3297. declareSymbolAndAddToSymbolTable(node, 512, 106639);
  3298. }
  3299. else {
  3300. var state = getModuleInstanceState(node);
  3301. if (state === 0) {
  3302. declareSymbolAndAddToSymbolTable(node, 1024, 0);
  3303. }
  3304. else {
  3305. declareSymbolAndAddToSymbolTable(node, 512, 106639);
  3306. if (node.symbol.flags & (16 | 32 | 256)) {
  3307. node.symbol.constEnumOnlyModule = false;
  3308. }
  3309. else {
  3310. var currentModuleIsConstEnumOnly = state === 2;
  3311. if (node.symbol.constEnumOnlyModule === undefined) {
  3312. node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
  3313. }
  3314. else {
  3315. node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
  3316. }
  3317. }
  3318. }
  3319. }
  3320. }
  3321. function bindFunctionOrConstructorType(node) {
  3322. var symbol = createSymbol(131072, getDeclarationName(node));
  3323. addDeclarationToSymbol(symbol, node, 131072);
  3324. var typeLiteralSymbol = createSymbol(2048, "__type");
  3325. addDeclarationToSymbol(typeLiteralSymbol, node, 2048);
  3326. typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a);
  3327. var _a;
  3328. }
  3329. function bindObjectLiteralExpression(node) {
  3330. if (inStrictMode) {
  3331. var seen = {};
  3332. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  3333. var prop = _a[_i];
  3334. if (prop.name.kind !== 67) {
  3335. continue;
  3336. }
  3337. var identifier = prop.name;
  3338. var currentKind = prop.kind === 243 || prop.kind === 244 || prop.kind === 141
  3339. ? 1
  3340. : 2;
  3341. var existingKind = seen[identifier.text];
  3342. if (!existingKind) {
  3343. seen[identifier.text] = currentKind;
  3344. continue;
  3345. }
  3346. if (currentKind === 1 && existingKind === 1) {
  3347. var span = ts.getErrorSpanForNode(file, identifier);
  3348. 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));
  3349. }
  3350. }
  3351. }
  3352. return bindAnonymousDeclaration(node, 4096, "__object");
  3353. }
  3354. function bindAnonymousDeclaration(node, symbolFlags, name) {
  3355. var symbol = createSymbol(symbolFlags, name);
  3356. addDeclarationToSymbol(symbol, node, symbolFlags);
  3357. }
  3358. function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
  3359. switch (blockScopeContainer.kind) {
  3360. case 216:
  3361. declareModuleMember(node, symbolFlags, symbolExcludes);
  3362. break;
  3363. case 246:
  3364. if (ts.isExternalModule(container)) {
  3365. declareModuleMember(node, symbolFlags, symbolExcludes);
  3366. break;
  3367. }
  3368. default:
  3369. if (!blockScopeContainer.locals) {
  3370. blockScopeContainer.locals = {};
  3371. addToContainerChain(blockScopeContainer);
  3372. }
  3373. declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
  3374. }
  3375. }
  3376. function bindBlockScopedVariableDeclaration(node) {
  3377. bindBlockScopedDeclaration(node, 2, 107455);
  3378. }
  3379. function checkStrictModeIdentifier(node) {
  3380. if (inStrictMode &&
  3381. node.originalKeywordKind >= 104 &&
  3382. node.originalKeywordKind <= 112 &&
  3383. !ts.isIdentifierName(node)) {
  3384. if (!file.parseDiagnostics.length) {
  3385. file.bindDiagnostics.push(ts.createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node)));
  3386. }
  3387. }
  3388. }
  3389. function getStrictModeIdentifierMessage(node) {
  3390. if (ts.getContainingClass(node)) {
  3391. return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
  3392. }
  3393. if (file.externalModuleIndicator) {
  3394. return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
  3395. }
  3396. return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
  3397. }
  3398. function checkStrictModeBinaryExpression(node) {
  3399. if (inStrictMode && ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operatorToken.kind)) {
  3400. checkStrictModeEvalOrArguments(node, node.left);
  3401. }
  3402. }
  3403. function checkStrictModeCatchClause(node) {
  3404. if (inStrictMode && node.variableDeclaration) {
  3405. checkStrictModeEvalOrArguments(node, node.variableDeclaration.name);
  3406. }
  3407. }
  3408. function checkStrictModeDeleteExpression(node) {
  3409. if (inStrictMode && node.expression.kind === 67) {
  3410. var span = ts.getErrorSpanForNode(file, node.expression);
  3411. file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
  3412. }
  3413. }
  3414. function isEvalOrArgumentsIdentifier(node) {
  3415. return node.kind === 67 &&
  3416. (node.text === "eval" || node.text === "arguments");
  3417. }
  3418. function checkStrictModeEvalOrArguments(contextNode, name) {
  3419. if (name && name.kind === 67) {
  3420. var identifier = name;
  3421. if (isEvalOrArgumentsIdentifier(identifier)) {
  3422. var span = ts.getErrorSpanForNode(file, name);
  3423. file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text));
  3424. }
  3425. }
  3426. }
  3427. function getStrictModeEvalOrArgumentsMessage(node) {
  3428. if (ts.getContainingClass(node)) {
  3429. return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
  3430. }
  3431. if (file.externalModuleIndicator) {
  3432. return ts.Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode;
  3433. }
  3434. return ts.Diagnostics.Invalid_use_of_0_in_strict_mode;
  3435. }
  3436. function checkStrictModeFunctionName(node) {
  3437. if (inStrictMode) {
  3438. checkStrictModeEvalOrArguments(node, node.name);
  3439. }
  3440. }
  3441. function checkStrictModeNumericLiteral(node) {
  3442. if (inStrictMode && node.flags & 65536) {
  3443. file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
  3444. }
  3445. }
  3446. function checkStrictModePostfixUnaryExpression(node) {
  3447. if (inStrictMode) {
  3448. checkStrictModeEvalOrArguments(node, node.operand);
  3449. }
  3450. }
  3451. function checkStrictModePrefixUnaryExpression(node) {
  3452. if (inStrictMode) {
  3453. if (node.operator === 40 || node.operator === 41) {
  3454. checkStrictModeEvalOrArguments(node, node.operand);
  3455. }
  3456. }
  3457. }
  3458. function checkStrictModeWithStatement(node) {
  3459. if (inStrictMode) {
  3460. grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
  3461. }
  3462. }
  3463. function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
  3464. var span = ts.getSpanOfTokenAtPosition(file, node.pos);
  3465. file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
  3466. }
  3467. function getDestructuringParameterName(node) {
  3468. return "__" + ts.indexOf(node.parent.parameters, node);
  3469. }
  3470. function bind(node) {
  3471. node.parent = parent;
  3472. var savedInStrictMode = inStrictMode;
  3473. if (!savedInStrictMode) {
  3474. updateStrictMode(node);
  3475. }
  3476. bindWorker(node);
  3477. bindChildren(node);
  3478. inStrictMode = savedInStrictMode;
  3479. }
  3480. function updateStrictMode(node) {
  3481. switch (node.kind) {
  3482. case 246:
  3483. case 217:
  3484. updateStrictModeStatementList(node.statements);
  3485. return;
  3486. case 190:
  3487. if (ts.isFunctionLike(node.parent)) {
  3488. updateStrictModeStatementList(node.statements);
  3489. }
  3490. return;
  3491. case 212:
  3492. case 184:
  3493. inStrictMode = true;
  3494. return;
  3495. }
  3496. }
  3497. function updateStrictModeStatementList(statements) {
  3498. for (var _i = 0; _i < statements.length; _i++) {
  3499. var statement = statements[_i];
  3500. if (!ts.isPrologueDirective(statement)) {
  3501. return;
  3502. }
  3503. if (isUseStrictPrologueDirective(statement)) {
  3504. inStrictMode = true;
  3505. return;
  3506. }
  3507. }
  3508. }
  3509. function isUseStrictPrologueDirective(node) {
  3510. var nodeText = ts.getTextOfNodeFromSourceText(file.text, node.expression);
  3511. return nodeText === "\"use strict\"" || nodeText === "'use strict'";
  3512. }
  3513. function bindWorker(node) {
  3514. switch (node.kind) {
  3515. case 67:
  3516. return checkStrictModeIdentifier(node);
  3517. case 179:
  3518. return checkStrictModeBinaryExpression(node);
  3519. case 242:
  3520. return checkStrictModeCatchClause(node);
  3521. case 173:
  3522. return checkStrictModeDeleteExpression(node);
  3523. case 8:
  3524. return checkStrictModeNumericLiteral(node);
  3525. case 178:
  3526. return checkStrictModePostfixUnaryExpression(node);
  3527. case 177:
  3528. return checkStrictModePrefixUnaryExpression(node);
  3529. case 203:
  3530. return checkStrictModeWithStatement(node);
  3531. case 135:
  3532. return declareSymbolAndAddToSymbolTable(node, 262144, 530912);
  3533. case 136:
  3534. return bindParameter(node);
  3535. case 209:
  3536. case 161:
  3537. return bindVariableDeclarationOrBindingElement(node);
  3538. case 139:
  3539. case 138:
  3540. return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455);
  3541. case 243:
  3542. case 244:
  3543. return bindPropertyOrMethodOrAccessor(node, 4, 107455);
  3544. case 245:
  3545. return bindPropertyOrMethodOrAccessor(node, 8, 107455);
  3546. case 145:
  3547. case 146:
  3548. case 147:
  3549. return declareSymbolAndAddToSymbolTable(node, 131072, 0);
  3550. case 141:
  3551. case 140:
  3552. return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263);
  3553. case 211:
  3554. checkStrictModeFunctionName(node);
  3555. return declareSymbolAndAddToSymbolTable(node, 16, 106927);
  3556. case 142:
  3557. return declareSymbolAndAddToSymbolTable(node, 16384, 0);
  3558. case 143:
  3559. return bindPropertyOrMethodOrAccessor(node, 32768, 41919);
  3560. case 144:
  3561. return bindPropertyOrMethodOrAccessor(node, 65536, 74687);
  3562. case 150:
  3563. case 151:
  3564. return bindFunctionOrConstructorType(node);
  3565. case 153:
  3566. return bindAnonymousDeclaration(node, 2048, "__type");
  3567. case 163:
  3568. return bindObjectLiteralExpression(node);
  3569. case 171:
  3570. case 172:
  3571. checkStrictModeFunctionName(node);
  3572. var bindingName = node.name ? node.name.text : "__function";
  3573. return bindAnonymousDeclaration(node, 16, bindingName);
  3574. case 184:
  3575. case 212:
  3576. return bindClassLikeDeclaration(node);
  3577. case 213:
  3578. return bindBlockScopedDeclaration(node, 64, 792960);
  3579. case 214:
  3580. return bindBlockScopedDeclaration(node, 524288, 793056);
  3581. case 215:
  3582. return bindEnumDeclaration(node);
  3583. case 216:
  3584. return bindModuleDeclaration(node);
  3585. case 219:
  3586. case 222:
  3587. case 224:
  3588. case 228:
  3589. return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608);
  3590. case 221:
  3591. return bindImportClause(node);
  3592. case 226:
  3593. return bindExportDeclaration(node);
  3594. case 225:
  3595. return bindExportAssignment(node);
  3596. case 246:
  3597. return bindSourceFileIfExternalModule();
  3598. }
  3599. }
  3600. function bindSourceFileIfExternalModule() {
  3601. setExportContextFlag(file);
  3602. if (ts.isExternalModule(file)) {
  3603. bindAnonymousDeclaration(file, 512, "\"" + ts.removeFileExtension(file.fileName) + "\"");
  3604. }
  3605. }
  3606. function bindExportAssignment(node) {
  3607. if (!container.symbol || !container.symbol.exports) {
  3608. bindAnonymousDeclaration(node, 8388608, getDeclarationName(node));
  3609. }
  3610. else if (node.expression.kind === 67) {
  3611. declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608);
  3612. }
  3613. else {
  3614. declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608);
  3615. }
  3616. }
  3617. function bindExportDeclaration(node) {
  3618. if (!container.symbol || !container.symbol.exports) {
  3619. bindAnonymousDeclaration(node, 1073741824, getDeclarationName(node));
  3620. }
  3621. else if (!node.exportClause) {
  3622. declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0);
  3623. }
  3624. }
  3625. function bindImportClause(node) {
  3626. if (node.name) {
  3627. declareSymbolAndAddToSymbolTable(node, 8388608, 8388608);
  3628. }
  3629. }
  3630. function bindClassLikeDeclaration(node) {
  3631. if (node.kind === 212) {
  3632. bindBlockScopedDeclaration(node, 32, 899519);
  3633. }
  3634. else {
  3635. var bindingName = node.name ? node.name.text : "__class";
  3636. bindAnonymousDeclaration(node, 32, bindingName);
  3637. if (node.name) {
  3638. classifiableNames[node.name.text] = node.name.text;
  3639. }
  3640. }
  3641. var symbol = node.symbol;
  3642. var prototypeSymbol = createSymbol(4 | 134217728, "prototype");
  3643. if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
  3644. if (node.name) {
  3645. node.name.parent = node;
  3646. }
  3647. file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
  3648. }
  3649. symbol.exports[prototypeSymbol.name] = prototypeSymbol;
  3650. prototypeSymbol.parent = symbol;
  3651. }
  3652. function bindEnumDeclaration(node) {
  3653. return ts.isConst(node)
  3654. ? bindBlockScopedDeclaration(node, 128, 899967)
  3655. : bindBlockScopedDeclaration(node, 256, 899327);
  3656. }
  3657. function bindVariableDeclarationOrBindingElement(node) {
  3658. if (inStrictMode) {
  3659. checkStrictModeEvalOrArguments(node, node.name);
  3660. }
  3661. if (!ts.isBindingPattern(node.name)) {
  3662. if (ts.isBlockOrCatchScoped(node)) {
  3663. bindBlockScopedVariableDeclaration(node);
  3664. }
  3665. else if (ts.isParameterDeclaration(node)) {
  3666. declareSymbolAndAddToSymbolTable(node, 1, 107455);
  3667. }
  3668. else {
  3669. declareSymbolAndAddToSymbolTable(node, 1, 107454);
  3670. }
  3671. }
  3672. }
  3673. function bindParameter(node) {
  3674. if (inStrictMode) {
  3675. checkStrictModeEvalOrArguments(node, node.name);
  3676. }
  3677. if (ts.isBindingPattern(node.name)) {
  3678. bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node));
  3679. }
  3680. else {
  3681. declareSymbolAndAddToSymbolTable(node, 1, 107455);
  3682. }
  3683. if (node.flags & 112 &&
  3684. node.parent.kind === 142 &&
  3685. ts.isClassLike(node.parent.parent)) {
  3686. var classDeclaration = node.parent.parent;
  3687. declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455);
  3688. }
  3689. }
  3690. function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
  3691. return ts.hasDynamicName(node)
  3692. ? bindAnonymousDeclaration(node, symbolFlags, "__computed")
  3693. : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
  3694. }
  3695. }
  3696. })(ts || (ts = {}));
  3697. /// <reference path="binder.ts" />
  3698. var ts;
  3699. (function (ts) {
  3700. function getDeclarationOfKind(symbol, kind) {
  3701. var declarations = symbol.declarations;
  3702. if (declarations) {
  3703. for (var _i = 0; _i < declarations.length; _i++) {
  3704. var declaration = declarations[_i];
  3705. if (declaration.kind === kind) {
  3706. return declaration;
  3707. }
  3708. }
  3709. }
  3710. return undefined;
  3711. }
  3712. ts.getDeclarationOfKind = getDeclarationOfKind;
  3713. var stringWriters = [];
  3714. function getSingleLineStringWriter() {
  3715. if (stringWriters.length === 0) {
  3716. var str = "";
  3717. var writeText = function (text) { return str += text; };
  3718. return {
  3719. string: function () { return str; },
  3720. writeKeyword: writeText,
  3721. writeOperator: writeText,
  3722. writePunctuation: writeText,
  3723. writeSpace: writeText,
  3724. writeStringLiteral: writeText,
  3725. writeParameter: writeText,
  3726. writeSymbol: writeText,
  3727. writeLine: function () { return str += " "; },
  3728. increaseIndent: function () { },
  3729. decreaseIndent: function () { },
  3730. clear: function () { return str = ""; },
  3731. trackSymbol: function () { }
  3732. };
  3733. }
  3734. return stringWriters.pop();
  3735. }
  3736. ts.getSingleLineStringWriter = getSingleLineStringWriter;
  3737. function releaseStringWriter(writer) {
  3738. writer.clear();
  3739. stringWriters.push(writer);
  3740. }
  3741. ts.releaseStringWriter = releaseStringWriter;
  3742. function getFullWidth(node) {
  3743. return node.end - node.pos;
  3744. }
  3745. ts.getFullWidth = getFullWidth;
  3746. function arrayIsEqualTo(arr1, arr2, comparer) {
  3747. if (!arr1 || !arr2) {
  3748. return arr1 === arr2;
  3749. }
  3750. if (arr1.length !== arr2.length) {
  3751. return false;
  3752. }
  3753. for (var i = 0; i < arr1.length; ++i) {
  3754. var equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i];
  3755. if (!equals) {
  3756. return false;
  3757. }
  3758. }
  3759. return true;
  3760. }
  3761. ts.arrayIsEqualTo = arrayIsEqualTo;
  3762. function hasResolvedModule(sourceFile, moduleNameText) {
  3763. return sourceFile.resolvedModules && ts.hasProperty(sourceFile.resolvedModules, moduleNameText);
  3764. }
  3765. ts.hasResolvedModule = hasResolvedModule;
  3766. function getResolvedModule(sourceFile, moduleNameText) {
  3767. return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined;
  3768. }
  3769. ts.getResolvedModule = getResolvedModule;
  3770. function setResolvedModule(sourceFile, moduleNameText, resolvedModule) {
  3771. if (!sourceFile.resolvedModules) {
  3772. sourceFile.resolvedModules = {};
  3773. }
  3774. sourceFile.resolvedModules[moduleNameText] = resolvedModule;
  3775. }
  3776. ts.setResolvedModule = setResolvedModule;
  3777. function containsParseError(node) {
  3778. aggregateChildData(node);
  3779. return (node.parserContextFlags & 64) !== 0;
  3780. }
  3781. ts.containsParseError = containsParseError;
  3782. function aggregateChildData(node) {
  3783. if (!(node.parserContextFlags & 128)) {
  3784. var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 16) !== 0) ||
  3785. ts.forEachChild(node, containsParseError);
  3786. if (thisNodeOrAnySubNodesHasError) {
  3787. node.parserContextFlags |= 64;
  3788. }
  3789. node.parserContextFlags |= 128;
  3790. }
  3791. }
  3792. function getSourceFileOfNode(node) {
  3793. while (node && node.kind !== 246) {
  3794. node = node.parent;
  3795. }
  3796. return node;
  3797. }
  3798. ts.getSourceFileOfNode = getSourceFileOfNode;
  3799. function getStartPositionOfLine(line, sourceFile) {
  3800. ts.Debug.assert(line >= 0);
  3801. return ts.getLineStarts(sourceFile)[line];
  3802. }
  3803. ts.getStartPositionOfLine = getStartPositionOfLine;
  3804. function nodePosToString(node) {
  3805. var file = getSourceFileOfNode(node);
  3806. var loc = ts.getLineAndCharacterOfPosition(file, node.pos);
  3807. return file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + ")";
  3808. }
  3809. ts.nodePosToString = nodePosToString;
  3810. function getStartPosOfNode(node) {
  3811. return node.pos;
  3812. }
  3813. ts.getStartPosOfNode = getStartPosOfNode;
  3814. function nodeIsMissing(node) {
  3815. if (!node) {
  3816. return true;
  3817. }
  3818. return node.pos === node.end && node.pos >= 0 && node.kind !== 1;
  3819. }
  3820. ts.nodeIsMissing = nodeIsMissing;
  3821. function nodeIsPresent(node) {
  3822. return !nodeIsMissing(node);
  3823. }
  3824. ts.nodeIsPresent = nodeIsPresent;
  3825. function getTokenPosOfNode(node, sourceFile) {
  3826. if (nodeIsMissing(node)) {
  3827. return node.pos;
  3828. }
  3829. return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
  3830. }
  3831. ts.getTokenPosOfNode = getTokenPosOfNode;
  3832. function getNonDecoratorTokenPosOfNode(node, sourceFile) {
  3833. if (nodeIsMissing(node) || !node.decorators) {
  3834. return getTokenPosOfNode(node, sourceFile);
  3835. }
  3836. return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
  3837. }
  3838. ts.getNonDecoratorTokenPosOfNode = getNonDecoratorTokenPosOfNode;
  3839. function getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia) {
  3840. if (includeTrivia === void 0) { includeTrivia = false; }
  3841. if (nodeIsMissing(node)) {
  3842. return "";
  3843. }
  3844. var text = sourceFile.text;
  3845. return text.substring(includeTrivia ? node.pos : ts.skipTrivia(text, node.pos), node.end);
  3846. }
  3847. ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile;
  3848. function getTextOfNodeFromSourceText(sourceText, node) {
  3849. if (nodeIsMissing(node)) {
  3850. return "";
  3851. }
  3852. return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
  3853. }
  3854. ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText;
  3855. function getTextOfNode(node, includeTrivia) {
  3856. if (includeTrivia === void 0) { includeTrivia = false; }
  3857. return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node, includeTrivia);
  3858. }
  3859. ts.getTextOfNode = getTextOfNode;
  3860. function escapeIdentifier(identifier) {
  3861. return identifier.length >= 2 && identifier.charCodeAt(0) === 95 && identifier.charCodeAt(1) === 95 ? "_" + identifier : identifier;
  3862. }
  3863. ts.escapeIdentifier = escapeIdentifier;
  3864. function unescapeIdentifier(identifier) {
  3865. return identifier.length >= 3 && identifier.charCodeAt(0) === 95 && identifier.charCodeAt(1) === 95 && identifier.charCodeAt(2) === 95 ? identifier.substr(1) : identifier;
  3866. }
  3867. ts.unescapeIdentifier = unescapeIdentifier;
  3868. function makeIdentifierFromModuleName(moduleName) {
  3869. return ts.getBaseFileName(moduleName).replace(/^(\d)/, "_$1").replace(/\W/g, "_");
  3870. }
  3871. ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName;
  3872. function isBlockOrCatchScoped(declaration) {
  3873. return (getCombinedNodeFlags(declaration) & 49152) !== 0 ||
  3874. isCatchClauseVariableDeclaration(declaration);
  3875. }
  3876. ts.isBlockOrCatchScoped = isBlockOrCatchScoped;
  3877. function getEnclosingBlockScopeContainer(node) {
  3878. var current = node.parent;
  3879. while (current) {
  3880. if (isFunctionLike(current)) {
  3881. return current;
  3882. }
  3883. switch (current.kind) {
  3884. case 246:
  3885. case 218:
  3886. case 242:
  3887. case 216:
  3888. case 197:
  3889. case 198:
  3890. case 199:
  3891. return current;
  3892. case 190:
  3893. if (!isFunctionLike(current.parent)) {
  3894. return current;
  3895. }
  3896. }
  3897. current = current.parent;
  3898. }
  3899. }
  3900. ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer;
  3901. function isCatchClauseVariableDeclaration(declaration) {
  3902. return declaration &&
  3903. declaration.kind === 209 &&
  3904. declaration.parent &&
  3905. declaration.parent.kind === 242;
  3906. }
  3907. ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration;
  3908. function declarationNameToString(name) {
  3909. return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name);
  3910. }
  3911. ts.declarationNameToString = declarationNameToString;
  3912. function createDiagnosticForNode(node, message, arg0, arg1, arg2) {
  3913. var sourceFile = getSourceFileOfNode(node);
  3914. var span = getErrorSpanForNode(sourceFile, node);
  3915. return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
  3916. }
  3917. ts.createDiagnosticForNode = createDiagnosticForNode;
  3918. function createDiagnosticForNodeFromMessageChain(node, messageChain) {
  3919. var sourceFile = getSourceFileOfNode(node);
  3920. var span = getErrorSpanForNode(sourceFile, node);
  3921. return {
  3922. file: sourceFile,
  3923. start: span.start,
  3924. length: span.length,
  3925. code: messageChain.code,
  3926. category: messageChain.category,
  3927. messageText: messageChain.next ? messageChain : messageChain.messageText
  3928. };
  3929. }
  3930. ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain;
  3931. function getSpanOfTokenAtPosition(sourceFile, pos) {
  3932. var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.languageVariant, sourceFile.text, undefined, pos);
  3933. scanner.scan();
  3934. var start = scanner.getTokenPos();
  3935. return ts.createTextSpanFromBounds(start, scanner.getTextPos());
  3936. }
  3937. ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition;
  3938. function getErrorSpanForNode(sourceFile, node) {
  3939. var errorNode = node;
  3940. switch (node.kind) {
  3941. case 246:
  3942. var pos_1 = ts.skipTrivia(sourceFile.text, 0, false);
  3943. if (pos_1 === sourceFile.text.length) {
  3944. return ts.createTextSpan(0, 0);
  3945. }
  3946. return getSpanOfTokenAtPosition(sourceFile, pos_1);
  3947. case 209:
  3948. case 161:
  3949. case 212:
  3950. case 184:
  3951. case 213:
  3952. case 216:
  3953. case 215:
  3954. case 245:
  3955. case 211:
  3956. case 171:
  3957. errorNode = node.name;
  3958. break;
  3959. }
  3960. if (errorNode === undefined) {
  3961. return getSpanOfTokenAtPosition(sourceFile, node.pos);
  3962. }
  3963. var pos = nodeIsMissing(errorNode)
  3964. ? errorNode.pos
  3965. : ts.skipTrivia(sourceFile.text, errorNode.pos);
  3966. return ts.createTextSpanFromBounds(pos, errorNode.end);
  3967. }
  3968. ts.getErrorSpanForNode = getErrorSpanForNode;
  3969. function isExternalModule(file) {
  3970. return file.externalModuleIndicator !== undefined;
  3971. }
  3972. ts.isExternalModule = isExternalModule;
  3973. function isDeclarationFile(file) {
  3974. return (file.flags & 8192) !== 0;
  3975. }
  3976. ts.isDeclarationFile = isDeclarationFile;
  3977. function isConstEnumDeclaration(node) {
  3978. return node.kind === 215 && isConst(node);
  3979. }
  3980. ts.isConstEnumDeclaration = isConstEnumDeclaration;
  3981. function walkUpBindingElementsAndPatterns(node) {
  3982. while (node && (node.kind === 161 || isBindingPattern(node))) {
  3983. node = node.parent;
  3984. }
  3985. return node;
  3986. }
  3987. function getCombinedNodeFlags(node) {
  3988. node = walkUpBindingElementsAndPatterns(node);
  3989. var flags = node.flags;
  3990. if (node.kind === 209) {
  3991. node = node.parent;
  3992. }
  3993. if (node && node.kind === 210) {
  3994. flags |= node.flags;
  3995. node = node.parent;
  3996. }
  3997. if (node && node.kind === 191) {
  3998. flags |= node.flags;
  3999. }
  4000. return flags;
  4001. }
  4002. ts.getCombinedNodeFlags = getCombinedNodeFlags;
  4003. function isConst(node) {
  4004. return !!(getCombinedNodeFlags(node) & 32768);
  4005. }
  4006. ts.isConst = isConst;
  4007. function isLet(node) {
  4008. return !!(getCombinedNodeFlags(node) & 16384);
  4009. }
  4010. ts.isLet = isLet;
  4011. function isPrologueDirective(node) {
  4012. return node.kind === 193 && node.expression.kind === 9;
  4013. }
  4014. ts.isPrologueDirective = isPrologueDirective;
  4015. function getLeadingCommentRangesOfNode(node, sourceFileOfNode) {
  4016. return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos);
  4017. }
  4018. ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode;
  4019. function getJsDocComments(node, sourceFileOfNode) {
  4020. var commentRanges = (node.kind === 136 || node.kind === 135) ?
  4021. ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) :
  4022. getLeadingCommentRangesOfNode(node, sourceFileOfNode);
  4023. return ts.filter(commentRanges, isJsDocComment);
  4024. function isJsDocComment(comment) {
  4025. return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 &&
  4026. sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 &&
  4027. sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47;
  4028. }
  4029. }
  4030. ts.getJsDocComments = getJsDocComments;
  4031. ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
  4032. function isTypeNode(node) {
  4033. if (149 <= node.kind && node.kind <= 158) {
  4034. return true;
  4035. }
  4036. switch (node.kind) {
  4037. case 115:
  4038. case 126:
  4039. case 128:
  4040. case 118:
  4041. case 129:
  4042. return true;
  4043. case 101:
  4044. return node.parent.kind !== 175;
  4045. case 9:
  4046. return node.parent.kind === 136;
  4047. case 186:
  4048. return !isExpressionWithTypeArgumentsInClassExtendsClause(node);
  4049. case 67:
  4050. if (node.parent.kind === 133 && node.parent.right === node) {
  4051. node = node.parent;
  4052. }
  4053. else if (node.parent.kind === 164 && node.parent.name === node) {
  4054. node = node.parent;
  4055. }
  4056. case 133:
  4057. case 164:
  4058. ts.Debug.assert(node.kind === 67 || node.kind === 133 || node.kind === 164, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'.");
  4059. var parent_1 = node.parent;
  4060. if (parent_1.kind === 152) {
  4061. return false;
  4062. }
  4063. if (149 <= parent_1.kind && parent_1.kind <= 158) {
  4064. return true;
  4065. }
  4066. switch (parent_1.kind) {
  4067. case 186:
  4068. return !isExpressionWithTypeArgumentsInClassExtendsClause(parent_1);
  4069. case 135:
  4070. return node === parent_1.constraint;
  4071. case 139:
  4072. case 138:
  4073. case 136:
  4074. case 209:
  4075. return node === parent_1.type;
  4076. case 211:
  4077. case 171:
  4078. case 172:
  4079. case 142:
  4080. case 141:
  4081. case 140:
  4082. case 143:
  4083. case 144:
  4084. return node === parent_1.type;
  4085. case 145:
  4086. case 146:
  4087. case 147:
  4088. return node === parent_1.type;
  4089. case 169:
  4090. return node === parent_1.type;
  4091. case 166:
  4092. case 167:
  4093. return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0;
  4094. case 168:
  4095. return false;
  4096. }
  4097. }
  4098. return false;
  4099. }
  4100. ts.isTypeNode = isTypeNode;
  4101. function forEachReturnStatement(body, visitor) {
  4102. return traverse(body);
  4103. function traverse(node) {
  4104. switch (node.kind) {
  4105. case 202:
  4106. return visitor(node);
  4107. case 218:
  4108. case 190:
  4109. case 194:
  4110. case 195:
  4111. case 196:
  4112. case 197:
  4113. case 198:
  4114. case 199:
  4115. case 203:
  4116. case 204:
  4117. case 239:
  4118. case 240:
  4119. case 205:
  4120. case 207:
  4121. case 242:
  4122. return ts.forEachChild(node, traverse);
  4123. }
  4124. }
  4125. }
  4126. ts.forEachReturnStatement = forEachReturnStatement;
  4127. function forEachYieldExpression(body, visitor) {
  4128. return traverse(body);
  4129. function traverse(node) {
  4130. switch (node.kind) {
  4131. case 182:
  4132. visitor(node);
  4133. var operand = node.expression;
  4134. if (operand) {
  4135. traverse(operand);
  4136. }
  4137. case 215:
  4138. case 213:
  4139. case 216:
  4140. case 214:
  4141. case 212:
  4142. case 184:
  4143. return;
  4144. default:
  4145. if (isFunctionLike(node)) {
  4146. var name_5 = node.name;
  4147. if (name_5 && name_5.kind === 134) {
  4148. traverse(name_5.expression);
  4149. return;
  4150. }
  4151. }
  4152. else if (!isTypeNode(node)) {
  4153. ts.forEachChild(node, traverse);
  4154. }
  4155. }
  4156. }
  4157. }
  4158. ts.forEachYieldExpression = forEachYieldExpression;
  4159. function isVariableLike(node) {
  4160. if (node) {
  4161. switch (node.kind) {
  4162. case 161:
  4163. case 245:
  4164. case 136:
  4165. case 243:
  4166. case 139:
  4167. case 138:
  4168. case 244:
  4169. case 209:
  4170. return true;
  4171. }
  4172. }
  4173. return false;
  4174. }
  4175. ts.isVariableLike = isVariableLike;
  4176. function isAccessor(node) {
  4177. return node && (node.kind === 143 || node.kind === 144);
  4178. }
  4179. ts.isAccessor = isAccessor;
  4180. function isClassLike(node) {
  4181. return node && (node.kind === 212 || node.kind === 184);
  4182. }
  4183. ts.isClassLike = isClassLike;
  4184. function isFunctionLike(node) {
  4185. if (node) {
  4186. switch (node.kind) {
  4187. case 142:
  4188. case 171:
  4189. case 211:
  4190. case 172:
  4191. case 141:
  4192. case 140:
  4193. case 143:
  4194. case 144:
  4195. case 145:
  4196. case 146:
  4197. case 147:
  4198. case 150:
  4199. case 151:
  4200. return true;
  4201. }
  4202. }
  4203. return false;
  4204. }
  4205. ts.isFunctionLike = isFunctionLike;
  4206. function introducesArgumentsExoticObject(node) {
  4207. switch (node.kind) {
  4208. case 141:
  4209. case 140:
  4210. case 142:
  4211. case 143:
  4212. case 144:
  4213. case 211:
  4214. case 171:
  4215. return true;
  4216. }
  4217. return false;
  4218. }
  4219. ts.introducesArgumentsExoticObject = introducesArgumentsExoticObject;
  4220. function isFunctionBlock(node) {
  4221. return node && node.kind === 190 && isFunctionLike(node.parent);
  4222. }
  4223. ts.isFunctionBlock = isFunctionBlock;
  4224. function isObjectLiteralMethod(node) {
  4225. return node && node.kind === 141 && node.parent.kind === 163;
  4226. }
  4227. ts.isObjectLiteralMethod = isObjectLiteralMethod;
  4228. function getContainingFunction(node) {
  4229. while (true) {
  4230. node = node.parent;
  4231. if (!node || isFunctionLike(node)) {
  4232. return node;
  4233. }
  4234. }
  4235. }
  4236. ts.getContainingFunction = getContainingFunction;
  4237. function getContainingClass(node) {
  4238. while (true) {
  4239. node = node.parent;
  4240. if (!node || isClassLike(node)) {
  4241. return node;
  4242. }
  4243. }
  4244. }
  4245. ts.getContainingClass = getContainingClass;
  4246. function getThisContainer(node, includeArrowFunctions) {
  4247. while (true) {
  4248. node = node.parent;
  4249. if (!node) {
  4250. return undefined;
  4251. }
  4252. switch (node.kind) {
  4253. case 134:
  4254. if (isClassLike(node.parent.parent)) {
  4255. return node;
  4256. }
  4257. node = node.parent;
  4258. break;
  4259. case 137:
  4260. if (node.parent.kind === 136 && isClassElement(node.parent.parent)) {
  4261. node = node.parent.parent;
  4262. }
  4263. else if (isClassElement(node.parent)) {
  4264. node = node.parent;
  4265. }
  4266. break;
  4267. case 172:
  4268. if (!includeArrowFunctions) {
  4269. continue;
  4270. }
  4271. case 211:
  4272. case 171:
  4273. case 216:
  4274. case 139:
  4275. case 138:
  4276. case 141:
  4277. case 140:
  4278. case 142:
  4279. case 143:
  4280. case 144:
  4281. case 215:
  4282. case 246:
  4283. return node;
  4284. }
  4285. }
  4286. }
  4287. ts.getThisContainer = getThisContainer;
  4288. function getSuperContainer(node, includeFunctions) {
  4289. while (true) {
  4290. node = node.parent;
  4291. if (!node)
  4292. return node;
  4293. switch (node.kind) {
  4294. case 134:
  4295. if (isClassLike(node.parent.parent)) {
  4296. return node;
  4297. }
  4298. node = node.parent;
  4299. break;
  4300. case 137:
  4301. if (node.parent.kind === 136 && isClassElement(node.parent.parent)) {
  4302. node = node.parent.parent;
  4303. }
  4304. else if (isClassElement(node.parent)) {
  4305. node = node.parent;
  4306. }
  4307. break;
  4308. case 211:
  4309. case 171:
  4310. case 172:
  4311. if (!includeFunctions) {
  4312. continue;
  4313. }
  4314. case 139:
  4315. case 138:
  4316. case 141:
  4317. case 140:
  4318. case 142:
  4319. case 143:
  4320. case 144:
  4321. return node;
  4322. }
  4323. }
  4324. }
  4325. ts.getSuperContainer = getSuperContainer;
  4326. function getEntityNameFromTypeNode(node) {
  4327. if (node) {
  4328. switch (node.kind) {
  4329. case 149:
  4330. return node.typeName;
  4331. case 186:
  4332. return node.expression;
  4333. case 67:
  4334. case 133:
  4335. return node;
  4336. }
  4337. }
  4338. return undefined;
  4339. }
  4340. ts.getEntityNameFromTypeNode = getEntityNameFromTypeNode;
  4341. function getInvokedExpression(node) {
  4342. if (node.kind === 168) {
  4343. return node.tag;
  4344. }
  4345. return node.expression;
  4346. }
  4347. ts.getInvokedExpression = getInvokedExpression;
  4348. function nodeCanBeDecorated(node) {
  4349. switch (node.kind) {
  4350. case 212:
  4351. return true;
  4352. case 139:
  4353. return node.parent.kind === 212;
  4354. case 136:
  4355. return node.parent.body && node.parent.parent.kind === 212;
  4356. case 143:
  4357. case 144:
  4358. case 141:
  4359. return node.body && node.parent.kind === 212;
  4360. }
  4361. return false;
  4362. }
  4363. ts.nodeCanBeDecorated = nodeCanBeDecorated;
  4364. function nodeIsDecorated(node) {
  4365. switch (node.kind) {
  4366. case 212:
  4367. if (node.decorators) {
  4368. return true;
  4369. }
  4370. return false;
  4371. case 139:
  4372. case 136:
  4373. if (node.decorators) {
  4374. return true;
  4375. }
  4376. return false;
  4377. case 143:
  4378. if (node.body && node.decorators) {
  4379. return true;
  4380. }
  4381. return false;
  4382. case 141:
  4383. case 144:
  4384. if (node.body && node.decorators) {
  4385. return true;
  4386. }
  4387. return false;
  4388. }
  4389. return false;
  4390. }
  4391. ts.nodeIsDecorated = nodeIsDecorated;
  4392. function childIsDecorated(node) {
  4393. switch (node.kind) {
  4394. case 212:
  4395. return ts.forEach(node.members, nodeOrChildIsDecorated);
  4396. case 141:
  4397. case 144:
  4398. return ts.forEach(node.parameters, nodeIsDecorated);
  4399. }
  4400. return false;
  4401. }
  4402. ts.childIsDecorated = childIsDecorated;
  4403. function nodeOrChildIsDecorated(node) {
  4404. return nodeIsDecorated(node) || childIsDecorated(node);
  4405. }
  4406. ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated;
  4407. function isExpression(node) {
  4408. switch (node.kind) {
  4409. case 95:
  4410. case 93:
  4411. case 91:
  4412. case 97:
  4413. case 82:
  4414. case 10:
  4415. case 162:
  4416. case 163:
  4417. case 164:
  4418. case 165:
  4419. case 166:
  4420. case 167:
  4421. case 168:
  4422. case 187:
  4423. case 169:
  4424. case 170:
  4425. case 171:
  4426. case 184:
  4427. case 172:
  4428. case 175:
  4429. case 173:
  4430. case 174:
  4431. case 177:
  4432. case 178:
  4433. case 179:
  4434. case 180:
  4435. case 183:
  4436. case 181:
  4437. case 11:
  4438. case 185:
  4439. case 231:
  4440. case 232:
  4441. case 182:
  4442. return true;
  4443. case 133:
  4444. while (node.parent.kind === 133) {
  4445. node = node.parent;
  4446. }
  4447. return node.parent.kind === 152;
  4448. case 67:
  4449. if (node.parent.kind === 152) {
  4450. return true;
  4451. }
  4452. case 8:
  4453. case 9:
  4454. var parent_2 = node.parent;
  4455. switch (parent_2.kind) {
  4456. case 209:
  4457. case 136:
  4458. case 139:
  4459. case 138:
  4460. case 245:
  4461. case 243:
  4462. case 161:
  4463. return parent_2.initializer === node;
  4464. case 193:
  4465. case 194:
  4466. case 195:
  4467. case 196:
  4468. case 202:
  4469. case 203:
  4470. case 204:
  4471. case 239:
  4472. case 206:
  4473. case 204:
  4474. return parent_2.expression === node;
  4475. case 197:
  4476. var forStatement = parent_2;
  4477. return (forStatement.initializer === node && forStatement.initializer.kind !== 210) ||
  4478. forStatement.condition === node ||
  4479. forStatement.incrementor === node;
  4480. case 198:
  4481. case 199:
  4482. var forInStatement = parent_2;
  4483. return (forInStatement.initializer === node && forInStatement.initializer.kind !== 210) ||
  4484. forInStatement.expression === node;
  4485. case 169:
  4486. case 187:
  4487. return node === parent_2.expression;
  4488. case 188:
  4489. return node === parent_2.expression;
  4490. case 134:
  4491. return node === parent_2.expression;
  4492. case 137:
  4493. case 238:
  4494. return true;
  4495. case 186:
  4496. return parent_2.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent_2);
  4497. default:
  4498. if (isExpression(parent_2)) {
  4499. return true;
  4500. }
  4501. }
  4502. }
  4503. return false;
  4504. }
  4505. ts.isExpression = isExpression;
  4506. function isInstantiatedModule(node, preserveConstEnums) {
  4507. var moduleState = ts.getModuleInstanceState(node);
  4508. return moduleState === 1 ||
  4509. (preserveConstEnums && moduleState === 2);
  4510. }
  4511. ts.isInstantiatedModule = isInstantiatedModule;
  4512. function isExternalModuleImportEqualsDeclaration(node) {
  4513. return node.kind === 219 && node.moduleReference.kind === 230;
  4514. }
  4515. ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration;
  4516. function getExternalModuleImportEqualsDeclarationExpression(node) {
  4517. ts.Debug.assert(isExternalModuleImportEqualsDeclaration(node));
  4518. return node.moduleReference.expression;
  4519. }
  4520. ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
  4521. function isInternalModuleImportEqualsDeclaration(node) {
  4522. return node.kind === 219 && node.moduleReference.kind !== 230;
  4523. }
  4524. ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration;
  4525. function getExternalModuleName(node) {
  4526. if (node.kind === 220) {
  4527. return node.moduleSpecifier;
  4528. }
  4529. if (node.kind === 219) {
  4530. var reference = node.moduleReference;
  4531. if (reference.kind === 230) {
  4532. return reference.expression;
  4533. }
  4534. }
  4535. if (node.kind === 226) {
  4536. return node.moduleSpecifier;
  4537. }
  4538. }
  4539. ts.getExternalModuleName = getExternalModuleName;
  4540. function hasQuestionToken(node) {
  4541. if (node) {
  4542. switch (node.kind) {
  4543. case 136:
  4544. case 141:
  4545. case 140:
  4546. case 244:
  4547. case 243:
  4548. case 139:
  4549. case 138:
  4550. return node.questionToken !== undefined;
  4551. }
  4552. }
  4553. return false;
  4554. }
  4555. ts.hasQuestionToken = hasQuestionToken;
  4556. function isJSDocConstructSignature(node) {
  4557. return node.kind === 259 &&
  4558. node.parameters.length > 0 &&
  4559. node.parameters[0].type.kind === 261;
  4560. }
  4561. ts.isJSDocConstructSignature = isJSDocConstructSignature;
  4562. function getJSDocTag(node, kind) {
  4563. if (node && node.jsDocComment) {
  4564. for (var _i = 0, _a = node.jsDocComment.tags; _i < _a.length; _i++) {
  4565. var tag = _a[_i];
  4566. if (tag.kind === kind) {
  4567. return tag;
  4568. }
  4569. }
  4570. }
  4571. }
  4572. function getJSDocTypeTag(node) {
  4573. return getJSDocTag(node, 267);
  4574. }
  4575. ts.getJSDocTypeTag = getJSDocTypeTag;
  4576. function getJSDocReturnTag(node) {
  4577. return getJSDocTag(node, 266);
  4578. }
  4579. ts.getJSDocReturnTag = getJSDocReturnTag;
  4580. function getJSDocTemplateTag(node) {
  4581. return getJSDocTag(node, 268);
  4582. }
  4583. ts.getJSDocTemplateTag = getJSDocTemplateTag;
  4584. function getCorrespondingJSDocParameterTag(parameter) {
  4585. if (parameter.name && parameter.name.kind === 67) {
  4586. var parameterName = parameter.name.text;
  4587. var docComment = parameter.parent.jsDocComment;
  4588. if (docComment) {
  4589. return ts.forEach(docComment.tags, function (t) {
  4590. if (t.kind === 265) {
  4591. var parameterTag = t;
  4592. var name_6 = parameterTag.preParameterName || parameterTag.postParameterName;
  4593. if (name_6.text === parameterName) {
  4594. return t;
  4595. }
  4596. }
  4597. });
  4598. }
  4599. }
  4600. }
  4601. ts.getCorrespondingJSDocParameterTag = getCorrespondingJSDocParameterTag;
  4602. function hasRestParameter(s) {
  4603. return isRestParameter(ts.lastOrUndefined(s.parameters));
  4604. }
  4605. ts.hasRestParameter = hasRestParameter;
  4606. function isRestParameter(node) {
  4607. if (node) {
  4608. if (node.parserContextFlags & 32) {
  4609. if (node.type && node.type.kind === 260) {
  4610. return true;
  4611. }
  4612. var paramTag = getCorrespondingJSDocParameterTag(node);
  4613. if (paramTag && paramTag.typeExpression) {
  4614. return paramTag.typeExpression.type.kind === 260;
  4615. }
  4616. }
  4617. return node.dotDotDotToken !== undefined;
  4618. }
  4619. return false;
  4620. }
  4621. ts.isRestParameter = isRestParameter;
  4622. function isLiteralKind(kind) {
  4623. return 8 <= kind && kind <= 11;
  4624. }
  4625. ts.isLiteralKind = isLiteralKind;
  4626. function isTextualLiteralKind(kind) {
  4627. return kind === 9 || kind === 11;
  4628. }
  4629. ts.isTextualLiteralKind = isTextualLiteralKind;
  4630. function isTemplateLiteralKind(kind) {
  4631. return 11 <= kind && kind <= 14;
  4632. }
  4633. ts.isTemplateLiteralKind = isTemplateLiteralKind;
  4634. function isBindingPattern(node) {
  4635. return !!node && (node.kind === 160 || node.kind === 159);
  4636. }
  4637. ts.isBindingPattern = isBindingPattern;
  4638. function isInAmbientContext(node) {
  4639. while (node) {
  4640. if (node.flags & (2 | 8192)) {
  4641. return true;
  4642. }
  4643. node = node.parent;
  4644. }
  4645. return false;
  4646. }
  4647. ts.isInAmbientContext = isInAmbientContext;
  4648. function isDeclaration(node) {
  4649. switch (node.kind) {
  4650. case 172:
  4651. case 161:
  4652. case 212:
  4653. case 184:
  4654. case 142:
  4655. case 215:
  4656. case 245:
  4657. case 228:
  4658. case 211:
  4659. case 171:
  4660. case 143:
  4661. case 221:
  4662. case 219:
  4663. case 224:
  4664. case 213:
  4665. case 141:
  4666. case 140:
  4667. case 216:
  4668. case 222:
  4669. case 136:
  4670. case 243:
  4671. case 139:
  4672. case 138:
  4673. case 144:
  4674. case 244:
  4675. case 214:
  4676. case 135:
  4677. case 209:
  4678. return true;
  4679. }
  4680. return false;
  4681. }
  4682. ts.isDeclaration = isDeclaration;
  4683. function isStatement(n) {
  4684. switch (n.kind) {
  4685. case 201:
  4686. case 200:
  4687. case 208:
  4688. case 195:
  4689. case 193:
  4690. case 192:
  4691. case 198:
  4692. case 199:
  4693. case 197:
  4694. case 194:
  4695. case 205:
  4696. case 202:
  4697. case 204:
  4698. case 96:
  4699. case 207:
  4700. case 191:
  4701. case 196:
  4702. case 203:
  4703. case 225:
  4704. return true;
  4705. default:
  4706. return false;
  4707. }
  4708. }
  4709. ts.isStatement = isStatement;
  4710. function isClassElement(n) {
  4711. switch (n.kind) {
  4712. case 142:
  4713. case 139:
  4714. case 141:
  4715. case 143:
  4716. case 144:
  4717. case 140:
  4718. case 147:
  4719. return true;
  4720. default:
  4721. return false;
  4722. }
  4723. }
  4724. ts.isClassElement = isClassElement;
  4725. function isDeclarationName(name) {
  4726. if (name.kind !== 67 && name.kind !== 9 && name.kind !== 8) {
  4727. return false;
  4728. }
  4729. var parent = name.parent;
  4730. if (parent.kind === 224 || parent.kind === 228) {
  4731. if (parent.propertyName) {
  4732. return true;
  4733. }
  4734. }
  4735. if (isDeclaration(parent)) {
  4736. return parent.name === name;
  4737. }
  4738. return false;
  4739. }
  4740. ts.isDeclarationName = isDeclarationName;
  4741. function isIdentifierName(node) {
  4742. var parent = node.parent;
  4743. switch (parent.kind) {
  4744. case 139:
  4745. case 138:
  4746. case 141:
  4747. case 140:
  4748. case 143:
  4749. case 144:
  4750. case 245:
  4751. case 243:
  4752. case 164:
  4753. return parent.name === node;
  4754. case 133:
  4755. if (parent.right === node) {
  4756. while (parent.kind === 133) {
  4757. parent = parent.parent;
  4758. }
  4759. return parent.kind === 152;
  4760. }
  4761. return false;
  4762. case 161:
  4763. case 224:
  4764. return parent.propertyName === node;
  4765. case 228:
  4766. return true;
  4767. }
  4768. return false;
  4769. }
  4770. ts.isIdentifierName = isIdentifierName;
  4771. function isAliasSymbolDeclaration(node) {
  4772. return node.kind === 219 ||
  4773. node.kind === 221 && !!node.name ||
  4774. node.kind === 222 ||
  4775. node.kind === 224 ||
  4776. node.kind === 228 ||
  4777. node.kind === 225 && node.expression.kind === 67;
  4778. }
  4779. ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration;
  4780. function getClassExtendsHeritageClauseElement(node) {
  4781. var heritageClause = getHeritageClause(node.heritageClauses, 81);
  4782. return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined;
  4783. }
  4784. ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement;
  4785. function getClassImplementsHeritageClauseElements(node) {
  4786. var heritageClause = getHeritageClause(node.heritageClauses, 104);
  4787. return heritageClause ? heritageClause.types : undefined;
  4788. }
  4789. ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements;
  4790. function getInterfaceBaseTypeNodes(node) {
  4791. var heritageClause = getHeritageClause(node.heritageClauses, 81);
  4792. return heritageClause ? heritageClause.types : undefined;
  4793. }
  4794. ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes;
  4795. function getHeritageClause(clauses, kind) {
  4796. if (clauses) {
  4797. for (var _i = 0; _i < clauses.length; _i++) {
  4798. var clause = clauses[_i];
  4799. if (clause.token === kind) {
  4800. return clause;
  4801. }
  4802. }
  4803. }
  4804. return undefined;
  4805. }
  4806. ts.getHeritageClause = getHeritageClause;
  4807. function tryResolveScriptReference(host, sourceFile, reference) {
  4808. if (!host.getCompilerOptions().noResolve) {
  4809. var referenceFileName = ts.isRootedDiskPath(reference.fileName) ? reference.fileName : ts.combinePaths(ts.getDirectoryPath(sourceFile.fileName), reference.fileName);
  4810. referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory());
  4811. return host.getSourceFile(referenceFileName);
  4812. }
  4813. }
  4814. ts.tryResolveScriptReference = tryResolveScriptReference;
  4815. function getAncestor(node, kind) {
  4816. while (node) {
  4817. if (node.kind === kind) {
  4818. return node;
  4819. }
  4820. node = node.parent;
  4821. }
  4822. return undefined;
  4823. }
  4824. ts.getAncestor = getAncestor;
  4825. function getFileReferenceFromReferencePath(comment, commentRange) {
  4826. var simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim;
  4827. var isNoDefaultLibRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)('|")(.+?)\2\s*\/>/gim;
  4828. if (simpleReferenceRegEx.exec(comment)) {
  4829. if (isNoDefaultLibRegEx.exec(comment)) {
  4830. return {
  4831. isNoDefaultLib: true
  4832. };
  4833. }
  4834. else {
  4835. var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment);
  4836. if (matchResult) {
  4837. var start = commentRange.pos;
  4838. var end = commentRange.end;
  4839. return {
  4840. fileReference: {
  4841. pos: start,
  4842. end: end,
  4843. fileName: matchResult[3]
  4844. },
  4845. isNoDefaultLib: false
  4846. };
  4847. }
  4848. else {
  4849. return {
  4850. diagnosticMessage: ts.Diagnostics.Invalid_reference_directive_syntax,
  4851. isNoDefaultLib: false
  4852. };
  4853. }
  4854. }
  4855. }
  4856. return undefined;
  4857. }
  4858. ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath;
  4859. function isKeyword(token) {
  4860. return 68 <= token && token <= 132;
  4861. }
  4862. ts.isKeyword = isKeyword;
  4863. function isTrivia(token) {
  4864. return 2 <= token && token <= 7;
  4865. }
  4866. ts.isTrivia = isTrivia;
  4867. function isAsyncFunctionLike(node) {
  4868. return isFunctionLike(node) && (node.flags & 512) !== 0 && !isAccessor(node);
  4869. }
  4870. ts.isAsyncFunctionLike = isAsyncFunctionLike;
  4871. function hasDynamicName(declaration) {
  4872. return declaration.name &&
  4873. declaration.name.kind === 134 &&
  4874. !isWellKnownSymbolSyntactically(declaration.name.expression);
  4875. }
  4876. ts.hasDynamicName = hasDynamicName;
  4877. function isWellKnownSymbolSyntactically(node) {
  4878. return node.kind === 164 && isESSymbolIdentifier(node.expression);
  4879. }
  4880. ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically;
  4881. function getPropertyNameForPropertyNameNode(name) {
  4882. if (name.kind === 67 || name.kind === 9 || name.kind === 8) {
  4883. return name.text;
  4884. }
  4885. if (name.kind === 134) {
  4886. var nameExpression = name.expression;
  4887. if (isWellKnownSymbolSyntactically(nameExpression)) {
  4888. var rightHandSideName = nameExpression.name.text;
  4889. return getPropertyNameForKnownSymbolName(rightHandSideName);
  4890. }
  4891. }
  4892. return undefined;
  4893. }
  4894. ts.getPropertyNameForPropertyNameNode = getPropertyNameForPropertyNameNode;
  4895. function getPropertyNameForKnownSymbolName(symbolName) {
  4896. return "__@" + symbolName;
  4897. }
  4898. ts.getPropertyNameForKnownSymbolName = getPropertyNameForKnownSymbolName;
  4899. function isESSymbolIdentifier(node) {
  4900. return node.kind === 67 && node.text === "Symbol";
  4901. }
  4902. ts.isESSymbolIdentifier = isESSymbolIdentifier;
  4903. function isModifier(token) {
  4904. switch (token) {
  4905. case 113:
  4906. case 116:
  4907. case 72:
  4908. case 120:
  4909. case 75:
  4910. case 80:
  4911. case 110:
  4912. case 108:
  4913. case 109:
  4914. case 111:
  4915. return true;
  4916. }
  4917. return false;
  4918. }
  4919. ts.isModifier = isModifier;
  4920. function isParameterDeclaration(node) {
  4921. var root = getRootDeclaration(node);
  4922. return root.kind === 136;
  4923. }
  4924. ts.isParameterDeclaration = isParameterDeclaration;
  4925. function getRootDeclaration(node) {
  4926. while (node.kind === 161) {
  4927. node = node.parent.parent;
  4928. }
  4929. return node;
  4930. }
  4931. ts.getRootDeclaration = getRootDeclaration;
  4932. function nodeStartsNewLexicalEnvironment(n) {
  4933. return isFunctionLike(n) || n.kind === 216 || n.kind === 246;
  4934. }
  4935. ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
  4936. function cloneEntityName(node) {
  4937. if (node.kind === 67) {
  4938. var clone_1 = createSynthesizedNode(67);
  4939. clone_1.text = node.text;
  4940. return clone_1;
  4941. }
  4942. else {
  4943. var clone_2 = createSynthesizedNode(133);
  4944. clone_2.left = cloneEntityName(node.left);
  4945. clone_2.left.parent = clone_2;
  4946. clone_2.right = cloneEntityName(node.right);
  4947. clone_2.right.parent = clone_2;
  4948. return clone_2;
  4949. }
  4950. }
  4951. ts.cloneEntityName = cloneEntityName;
  4952. function nodeIsSynthesized(node) {
  4953. return node.pos === -1;
  4954. }
  4955. ts.nodeIsSynthesized = nodeIsSynthesized;
  4956. function createSynthesizedNode(kind, startsOnNewLine) {
  4957. var node = ts.createNode(kind);
  4958. node.startsOnNewLine = startsOnNewLine;
  4959. return node;
  4960. }
  4961. ts.createSynthesizedNode = createSynthesizedNode;
  4962. function createSynthesizedNodeArray() {
  4963. var array = [];
  4964. array.pos = -1;
  4965. array.end = -1;
  4966. return array;
  4967. }
  4968. ts.createSynthesizedNodeArray = createSynthesizedNodeArray;
  4969. function createDiagnosticCollection() {
  4970. var nonFileDiagnostics = [];
  4971. var fileDiagnostics = {};
  4972. var diagnosticsModified = false;
  4973. var modificationCount = 0;
  4974. return {
  4975. add: add,
  4976. getGlobalDiagnostics: getGlobalDiagnostics,
  4977. getDiagnostics: getDiagnostics,
  4978. getModificationCount: getModificationCount,
  4979. reattachFileDiagnostics: reattachFileDiagnostics
  4980. };
  4981. function getModificationCount() {
  4982. return modificationCount;
  4983. }
  4984. function reattachFileDiagnostics(newFile) {
  4985. if (!ts.hasProperty(fileDiagnostics, newFile.fileName)) {
  4986. return;
  4987. }
  4988. for (var _i = 0, _a = fileDiagnostics[newFile.fileName]; _i < _a.length; _i++) {
  4989. var diagnostic = _a[_i];
  4990. diagnostic.file = newFile;
  4991. }
  4992. }
  4993. function add(diagnostic) {
  4994. var diagnostics;
  4995. if (diagnostic.file) {
  4996. diagnostics = fileDiagnostics[diagnostic.file.fileName];
  4997. if (!diagnostics) {
  4998. diagnostics = [];
  4999. fileDiagnostics[diagnostic.file.fileName] = diagnostics;
  5000. }
  5001. }
  5002. else {
  5003. diagnostics = nonFileDiagnostics;
  5004. }
  5005. diagnostics.push(diagnostic);
  5006. diagnosticsModified = true;
  5007. modificationCount++;
  5008. }
  5009. function getGlobalDiagnostics() {
  5010. sortAndDeduplicate();
  5011. return nonFileDiagnostics;
  5012. }
  5013. function getDiagnostics(fileName) {
  5014. sortAndDeduplicate();
  5015. if (fileName) {
  5016. return fileDiagnostics[fileName] || [];
  5017. }
  5018. var allDiagnostics = [];
  5019. function pushDiagnostic(d) {
  5020. allDiagnostics.push(d);
  5021. }
  5022. ts.forEach(nonFileDiagnostics, pushDiagnostic);
  5023. for (var key in fileDiagnostics) {
  5024. if (ts.hasProperty(fileDiagnostics, key)) {
  5025. ts.forEach(fileDiagnostics[key], pushDiagnostic);
  5026. }
  5027. }
  5028. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  5029. }
  5030. function sortAndDeduplicate() {
  5031. if (!diagnosticsModified) {
  5032. return;
  5033. }
  5034. diagnosticsModified = false;
  5035. nonFileDiagnostics = ts.sortAndDeduplicateDiagnostics(nonFileDiagnostics);
  5036. for (var key in fileDiagnostics) {
  5037. if (ts.hasProperty(fileDiagnostics, key)) {
  5038. fileDiagnostics[key] = ts.sortAndDeduplicateDiagnostics(fileDiagnostics[key]);
  5039. }
  5040. }
  5041. }
  5042. }
  5043. ts.createDiagnosticCollection = createDiagnosticCollection;
  5044. var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
  5045. var escapedCharsMap = {
  5046. "\0": "\\0",
  5047. "\t": "\\t",
  5048. "\v": "\\v",
  5049. "\f": "\\f",
  5050. "\b": "\\b",
  5051. "\r": "\\r",
  5052. "\n": "\\n",
  5053. "\\": "\\\\",
  5054. "\"": "\\\"",
  5055. "\u2028": "\\u2028",
  5056. "\u2029": "\\u2029",
  5057. "\u0085": "\\u0085"
  5058. };
  5059. function escapeString(s) {
  5060. s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s;
  5061. return s;
  5062. function getReplacement(c) {
  5063. return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0));
  5064. }
  5065. }
  5066. ts.escapeString = escapeString;
  5067. function isIntrinsicJsxName(name) {
  5068. var ch = name.substr(0, 1);
  5069. return ch.toLowerCase() === ch;
  5070. }
  5071. ts.isIntrinsicJsxName = isIntrinsicJsxName;
  5072. function get16BitUnicodeEscapeSequence(charCode) {
  5073. var hexCharCode = charCode.toString(16).toUpperCase();
  5074. var paddedHexCode = ("0000" + hexCharCode).slice(-4);
  5075. return "\\u" + paddedHexCode;
  5076. }
  5077. var nonAsciiCharacters = /[^\u0000-\u007F]/g;
  5078. function escapeNonAsciiCharacters(s) {
  5079. return nonAsciiCharacters.test(s) ?
  5080. s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) :
  5081. s;
  5082. }
  5083. ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters;
  5084. var indentStrings = ["", " "];
  5085. function getIndentString(level) {
  5086. if (indentStrings[level] === undefined) {
  5087. indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
  5088. }
  5089. return indentStrings[level];
  5090. }
  5091. ts.getIndentString = getIndentString;
  5092. function getIndentSize() {
  5093. return indentStrings[1].length;
  5094. }
  5095. ts.getIndentSize = getIndentSize;
  5096. function createTextWriter(newLine) {
  5097. var output = "";
  5098. var indent = 0;
  5099. var lineStart = true;
  5100. var lineCount = 0;
  5101. var linePos = 0;
  5102. function write(s) {
  5103. if (s && s.length) {
  5104. if (lineStart) {
  5105. output += getIndentString(indent);
  5106. lineStart = false;
  5107. }
  5108. output += s;
  5109. }
  5110. }
  5111. function rawWrite(s) {
  5112. if (s !== undefined) {
  5113. if (lineStart) {
  5114. lineStart = false;
  5115. }
  5116. output += s;
  5117. }
  5118. }
  5119. function writeLiteral(s) {
  5120. if (s && s.length) {
  5121. write(s);
  5122. var lineStartsOfS = ts.computeLineStarts(s);
  5123. if (lineStartsOfS.length > 1) {
  5124. lineCount = lineCount + lineStartsOfS.length - 1;
  5125. linePos = output.length - s.length + ts.lastOrUndefined(lineStartsOfS);
  5126. }
  5127. }
  5128. }
  5129. function writeLine() {
  5130. if (!lineStart) {
  5131. output += newLine;
  5132. lineCount++;
  5133. linePos = output.length;
  5134. lineStart = true;
  5135. }
  5136. }
  5137. function writeTextOfNode(sourceFile, node) {
  5138. write(getSourceTextOfNodeFromSourceFile(sourceFile, node));
  5139. }
  5140. return {
  5141. write: write,
  5142. rawWrite: rawWrite,
  5143. writeTextOfNode: writeTextOfNode,
  5144. writeLiteral: writeLiteral,
  5145. writeLine: writeLine,
  5146. increaseIndent: function () { return indent++; },
  5147. decreaseIndent: function () { return indent--; },
  5148. getIndent: function () { return indent; },
  5149. getTextPos: function () { return output.length; },
  5150. getLine: function () { return lineCount + 1; },
  5151. getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
  5152. getText: function () { return output; }
  5153. };
  5154. }
  5155. ts.createTextWriter = createTextWriter;
  5156. function getOwnEmitOutputFilePath(sourceFile, host, extension) {
  5157. var compilerOptions = host.getCompilerOptions();
  5158. var emitOutputFilePathWithoutExtension;
  5159. if (compilerOptions.outDir) {
  5160. emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
  5161. }
  5162. else {
  5163. emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName);
  5164. }
  5165. return emitOutputFilePathWithoutExtension + extension;
  5166. }
  5167. ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath;
  5168. function getSourceFilePathInNewDir(sourceFile, host, newDirPath) {
  5169. var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory());
  5170. sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), "");
  5171. return ts.combinePaths(newDirPath, sourceFilePath);
  5172. }
  5173. ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir;
  5174. function writeFile(host, diagnostics, fileName, data, writeByteOrderMark) {
  5175. host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) {
  5176. diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
  5177. });
  5178. }
  5179. ts.writeFile = writeFile;
  5180. function getLineOfLocalPosition(currentSourceFile, pos) {
  5181. return ts.getLineAndCharacterOfPosition(currentSourceFile, pos).line;
  5182. }
  5183. ts.getLineOfLocalPosition = getLineOfLocalPosition;
  5184. function getFirstConstructorWithBody(node) {
  5185. return ts.forEach(node.members, function (member) {
  5186. if (member.kind === 142 && nodeIsPresent(member.body)) {
  5187. return member;
  5188. }
  5189. });
  5190. }
  5191. ts.getFirstConstructorWithBody = getFirstConstructorWithBody;
  5192. function getSetAccessorTypeAnnotationNode(accessor) {
  5193. return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type;
  5194. }
  5195. ts.getSetAccessorTypeAnnotationNode = getSetAccessorTypeAnnotationNode;
  5196. function shouldEmitToOwnFile(sourceFile, compilerOptions) {
  5197. if (!isDeclarationFile(sourceFile)) {
  5198. if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
  5199. return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js");
  5200. }
  5201. return false;
  5202. }
  5203. return false;
  5204. }
  5205. ts.shouldEmitToOwnFile = shouldEmitToOwnFile;
  5206. function getAllAccessorDeclarations(declarations, accessor) {
  5207. var firstAccessor;
  5208. var secondAccessor;
  5209. var getAccessor;
  5210. var setAccessor;
  5211. if (hasDynamicName(accessor)) {
  5212. firstAccessor = accessor;
  5213. if (accessor.kind === 143) {
  5214. getAccessor = accessor;
  5215. }
  5216. else if (accessor.kind === 144) {
  5217. setAccessor = accessor;
  5218. }
  5219. else {
  5220. ts.Debug.fail("Accessor has wrong kind");
  5221. }
  5222. }
  5223. else {
  5224. ts.forEach(declarations, function (member) {
  5225. if ((member.kind === 143 || member.kind === 144)
  5226. && (member.flags & 128) === (accessor.flags & 128)) {
  5227. var memberName = getPropertyNameForPropertyNameNode(member.name);
  5228. var accessorName = getPropertyNameForPropertyNameNode(accessor.name);
  5229. if (memberName === accessorName) {
  5230. if (!firstAccessor) {
  5231. firstAccessor = member;
  5232. }
  5233. else if (!secondAccessor) {
  5234. secondAccessor = member;
  5235. }
  5236. if (member.kind === 143 && !getAccessor) {
  5237. getAccessor = member;
  5238. }
  5239. if (member.kind === 144 && !setAccessor) {
  5240. setAccessor = member;
  5241. }
  5242. }
  5243. }
  5244. });
  5245. }
  5246. return {
  5247. firstAccessor: firstAccessor,
  5248. secondAccessor: secondAccessor,
  5249. getAccessor: getAccessor,
  5250. setAccessor: setAccessor
  5251. };
  5252. }
  5253. ts.getAllAccessorDeclarations = getAllAccessorDeclarations;
  5254. function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) {
  5255. if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
  5256. getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
  5257. writer.writeLine();
  5258. }
  5259. }
  5260. ts.emitNewLineBeforeLeadingComments = emitNewLineBeforeLeadingComments;
  5261. function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) {
  5262. var emitLeadingSpace = !trailingSeparator;
  5263. ts.forEach(comments, function (comment) {
  5264. if (emitLeadingSpace) {
  5265. writer.write(" ");
  5266. emitLeadingSpace = false;
  5267. }
  5268. writeComment(currentSourceFile, writer, comment, newLine);
  5269. if (comment.hasTrailingNewLine) {
  5270. writer.writeLine();
  5271. }
  5272. else if (trailingSeparator) {
  5273. writer.write(" ");
  5274. }
  5275. else {
  5276. emitLeadingSpace = true;
  5277. }
  5278. });
  5279. }
  5280. ts.emitComments = emitComments;
  5281. function writeCommentRange(currentSourceFile, writer, comment, newLine) {
  5282. if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42) {
  5283. var firstCommentLineAndCharacter = ts.getLineAndCharacterOfPosition(currentSourceFile, comment.pos);
  5284. var lineCount = ts.getLineStarts(currentSourceFile).length;
  5285. var firstCommentLineIndent;
  5286. for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
  5287. var nextLineStart = (currentLine + 1) === lineCount
  5288. ? currentSourceFile.text.length + 1
  5289. : getStartPositionOfLine(currentLine + 1, currentSourceFile);
  5290. if (pos !== comment.pos) {
  5291. if (firstCommentLineIndent === undefined) {
  5292. firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos);
  5293. }
  5294. var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
  5295. var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
  5296. if (spacesToEmit > 0) {
  5297. var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
  5298. var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
  5299. writer.rawWrite(indentSizeSpaceString);
  5300. while (numberOfSingleSpacesToEmit) {
  5301. writer.rawWrite(" ");
  5302. numberOfSingleSpacesToEmit--;
  5303. }
  5304. }
  5305. else {
  5306. writer.rawWrite("");
  5307. }
  5308. }
  5309. writeTrimmedCurrentLine(pos, nextLineStart);
  5310. pos = nextLineStart;
  5311. }
  5312. }
  5313. else {
  5314. writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
  5315. }
  5316. function writeTrimmedCurrentLine(pos, nextLineStart) {
  5317. var end = Math.min(comment.end, nextLineStart - 1);
  5318. var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, "");
  5319. if (currentLineText) {
  5320. writer.write(currentLineText);
  5321. if (end !== comment.end) {
  5322. writer.writeLine();
  5323. }
  5324. }
  5325. else {
  5326. writer.writeLiteral(newLine);
  5327. }
  5328. }
  5329. function calculateIndent(pos, end) {
  5330. var currentLineIndent = 0;
  5331. for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
  5332. if (currentSourceFile.text.charCodeAt(pos) === 9) {
  5333. currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
  5334. }
  5335. else {
  5336. currentLineIndent++;
  5337. }
  5338. }
  5339. return currentLineIndent;
  5340. }
  5341. }
  5342. ts.writeCommentRange = writeCommentRange;
  5343. function modifierToFlag(token) {
  5344. switch (token) {
  5345. case 111: return 128;
  5346. case 110: return 16;
  5347. case 109: return 64;
  5348. case 108: return 32;
  5349. case 113: return 256;
  5350. case 80: return 1;
  5351. case 120: return 2;
  5352. case 72: return 32768;
  5353. case 75: return 1024;
  5354. case 116: return 512;
  5355. }
  5356. return 0;
  5357. }
  5358. ts.modifierToFlag = modifierToFlag;
  5359. function isLeftHandSideExpression(expr) {
  5360. if (expr) {
  5361. switch (expr.kind) {
  5362. case 164:
  5363. case 165:
  5364. case 167:
  5365. case 166:
  5366. case 231:
  5367. case 232:
  5368. case 168:
  5369. case 162:
  5370. case 170:
  5371. case 163:
  5372. case 184:
  5373. case 171:
  5374. case 67:
  5375. case 10:
  5376. case 8:
  5377. case 9:
  5378. case 11:
  5379. case 181:
  5380. case 82:
  5381. case 91:
  5382. case 95:
  5383. case 97:
  5384. case 93:
  5385. return true;
  5386. }
  5387. }
  5388. return false;
  5389. }
  5390. ts.isLeftHandSideExpression = isLeftHandSideExpression;
  5391. function isAssignmentOperator(token) {
  5392. return token >= 55 && token <= 66;
  5393. }
  5394. ts.isAssignmentOperator = isAssignmentOperator;
  5395. function isExpressionWithTypeArgumentsInClassExtendsClause(node) {
  5396. return node.kind === 186 &&
  5397. node.parent.token === 81 &&
  5398. isClassLike(node.parent.parent);
  5399. }
  5400. ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause;
  5401. function isSupportedExpressionWithTypeArguments(node) {
  5402. return isSupportedExpressionWithTypeArgumentsRest(node.expression);
  5403. }
  5404. ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments;
  5405. function isSupportedExpressionWithTypeArgumentsRest(node) {
  5406. if (node.kind === 67) {
  5407. return true;
  5408. }
  5409. else if (node.kind === 164) {
  5410. return isSupportedExpressionWithTypeArgumentsRest(node.expression);
  5411. }
  5412. else {
  5413. return false;
  5414. }
  5415. }
  5416. function isRightSideOfQualifiedNameOrPropertyAccess(node) {
  5417. return (node.parent.kind === 133 && node.parent.right === node) ||
  5418. (node.parent.kind === 164 && node.parent.name === node);
  5419. }
  5420. ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess;
  5421. function isEmptyObjectLiteralOrArrayLiteral(expression) {
  5422. var kind = expression.kind;
  5423. if (kind === 163) {
  5424. return expression.properties.length === 0;
  5425. }
  5426. if (kind === 162) {
  5427. return expression.elements.length === 0;
  5428. }
  5429. return false;
  5430. }
  5431. ts.isEmptyObjectLiteralOrArrayLiteral = isEmptyObjectLiteralOrArrayLiteral;
  5432. function getLocalSymbolForExportDefault(symbol) {
  5433. return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 1024) ? symbol.valueDeclaration.localSymbol : undefined;
  5434. }
  5435. ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault;
  5436. function isJavaScript(fileName) {
  5437. return ts.fileExtensionIs(fileName, ".js");
  5438. }
  5439. ts.isJavaScript = isJavaScript;
  5440. function isTsx(fileName) {
  5441. return ts.fileExtensionIs(fileName, ".tsx");
  5442. }
  5443. ts.isTsx = isTsx;
  5444. function getExpandedCharCodes(input) {
  5445. var output = [];
  5446. var length = input.length;
  5447. for (var i = 0; i < length; i++) {
  5448. var charCode = input.charCodeAt(i);
  5449. if (charCode < 0x80) {
  5450. output.push(charCode);
  5451. }
  5452. else if (charCode < 0x800) {
  5453. output.push((charCode >> 6) | 192);
  5454. output.push((charCode & 63) | 128);
  5455. }
  5456. else if (charCode < 0x10000) {
  5457. output.push((charCode >> 12) | 224);
  5458. output.push(((charCode >> 6) & 63) | 128);
  5459. output.push((charCode & 63) | 128);
  5460. }
  5461. else if (charCode < 0x20000) {
  5462. output.push((charCode >> 18) | 240);
  5463. output.push(((charCode >> 12) & 63) | 128);
  5464. output.push(((charCode >> 6) & 63) | 128);
  5465. output.push((charCode & 63) | 128);
  5466. }
  5467. else {
  5468. ts.Debug.assert(false, "Unexpected code point");
  5469. }
  5470. }
  5471. return output;
  5472. }
  5473. var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  5474. function convertToBase64(input) {
  5475. var result = "";
  5476. var charCodes = getExpandedCharCodes(input);
  5477. var i = 0;
  5478. var length = charCodes.length;
  5479. var byte1, byte2, byte3, byte4;
  5480. while (i < length) {
  5481. byte1 = charCodes[i] >> 2;
  5482. byte2 = (charCodes[i] & 3) << 4 | charCodes[i + 1] >> 4;
  5483. byte3 = (charCodes[i + 1] & 15) << 2 | charCodes[i + 2] >> 6;
  5484. byte4 = charCodes[i + 2] & 63;
  5485. if (i + 1 >= length) {
  5486. byte3 = byte4 = 64;
  5487. }
  5488. else if (i + 2 >= length) {
  5489. byte4 = 64;
  5490. }
  5491. result += base64Digits.charAt(byte1) + base64Digits.charAt(byte2) + base64Digits.charAt(byte3) + base64Digits.charAt(byte4);
  5492. i += 3;
  5493. }
  5494. return result;
  5495. }
  5496. ts.convertToBase64 = convertToBase64;
  5497. var carriageReturnLineFeed = "\r\n";
  5498. var lineFeed = "\n";
  5499. function getNewLineCharacter(options) {
  5500. if (options.newLine === 0) {
  5501. return carriageReturnLineFeed;
  5502. }
  5503. else if (options.newLine === 1) {
  5504. return lineFeed;
  5505. }
  5506. else if (ts.sys) {
  5507. return ts.sys.newLine;
  5508. }
  5509. return carriageReturnLineFeed;
  5510. }
  5511. ts.getNewLineCharacter = getNewLineCharacter;
  5512. })(ts || (ts = {}));
  5513. var ts;
  5514. (function (ts) {
  5515. function getDefaultLibFileName(options) {
  5516. return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts";
  5517. }
  5518. ts.getDefaultLibFileName = getDefaultLibFileName;
  5519. function textSpanEnd(span) {
  5520. return span.start + span.length;
  5521. }
  5522. ts.textSpanEnd = textSpanEnd;
  5523. function textSpanIsEmpty(span) {
  5524. return span.length === 0;
  5525. }
  5526. ts.textSpanIsEmpty = textSpanIsEmpty;
  5527. function textSpanContainsPosition(span, position) {
  5528. return position >= span.start && position < textSpanEnd(span);
  5529. }
  5530. ts.textSpanContainsPosition = textSpanContainsPosition;
  5531. function textSpanContainsTextSpan(span, other) {
  5532. return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span);
  5533. }
  5534. ts.textSpanContainsTextSpan = textSpanContainsTextSpan;
  5535. function textSpanOverlapsWith(span, other) {
  5536. var overlapStart = Math.max(span.start, other.start);
  5537. var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other));
  5538. return overlapStart < overlapEnd;
  5539. }
  5540. ts.textSpanOverlapsWith = textSpanOverlapsWith;
  5541. function textSpanOverlap(span1, span2) {
  5542. var overlapStart = Math.max(span1.start, span2.start);
  5543. var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
  5544. if (overlapStart < overlapEnd) {
  5545. return createTextSpanFromBounds(overlapStart, overlapEnd);
  5546. }
  5547. return undefined;
  5548. }
  5549. ts.textSpanOverlap = textSpanOverlap;
  5550. function textSpanIntersectsWithTextSpan(span, other) {
  5551. return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start;
  5552. }
  5553. ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan;
  5554. function textSpanIntersectsWith(span, start, length) {
  5555. var end = start + length;
  5556. return start <= textSpanEnd(span) && end >= span.start;
  5557. }
  5558. ts.textSpanIntersectsWith = textSpanIntersectsWith;
  5559. function decodedTextSpanIntersectsWith(start1, length1, start2, length2) {
  5560. var end1 = start1 + length1;
  5561. var end2 = start2 + length2;
  5562. return start2 <= end1 && end2 >= start1;
  5563. }
  5564. ts.decodedTextSpanIntersectsWith = decodedTextSpanIntersectsWith;
  5565. function textSpanIntersectsWithPosition(span, position) {
  5566. return position <= textSpanEnd(span) && position >= span.start;
  5567. }
  5568. ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition;
  5569. function textSpanIntersection(span1, span2) {
  5570. var intersectStart = Math.max(span1.start, span2.start);
  5571. var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
  5572. if (intersectStart <= intersectEnd) {
  5573. return createTextSpanFromBounds(intersectStart, intersectEnd);
  5574. }
  5575. return undefined;
  5576. }
  5577. ts.textSpanIntersection = textSpanIntersection;
  5578. function createTextSpan(start, length) {
  5579. if (start < 0) {
  5580. throw new Error("start < 0");
  5581. }
  5582. if (length < 0) {
  5583. throw new Error("length < 0");
  5584. }
  5585. return { start: start, length: length };
  5586. }
  5587. ts.createTextSpan = createTextSpan;
  5588. function createTextSpanFromBounds(start, end) {
  5589. return createTextSpan(start, end - start);
  5590. }
  5591. ts.createTextSpanFromBounds = createTextSpanFromBounds;
  5592. function textChangeRangeNewSpan(range) {
  5593. return createTextSpan(range.span.start, range.newLength);
  5594. }
  5595. ts.textChangeRangeNewSpan = textChangeRangeNewSpan;
  5596. function textChangeRangeIsUnchanged(range) {
  5597. return textSpanIsEmpty(range.span) && range.newLength === 0;
  5598. }
  5599. ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged;
  5600. function createTextChangeRange(span, newLength) {
  5601. if (newLength < 0) {
  5602. throw new Error("newLength < 0");
  5603. }
  5604. return { span: span, newLength: newLength };
  5605. }
  5606. ts.createTextChangeRange = createTextChangeRange;
  5607. ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
  5608. function collapseTextChangeRangesAcrossMultipleVersions(changes) {
  5609. if (changes.length === 0) {
  5610. return ts.unchangedTextChangeRange;
  5611. }
  5612. if (changes.length === 1) {
  5613. return changes[0];
  5614. }
  5615. var change0 = changes[0];
  5616. var oldStartN = change0.span.start;
  5617. var oldEndN = textSpanEnd(change0.span);
  5618. var newEndN = oldStartN + change0.newLength;
  5619. for (var i = 1; i < changes.length; i++) {
  5620. var nextChange = changes[i];
  5621. var oldStart1 = oldStartN;
  5622. var oldEnd1 = oldEndN;
  5623. var newEnd1 = newEndN;
  5624. var oldStart2 = nextChange.span.start;
  5625. var oldEnd2 = textSpanEnd(nextChange.span);
  5626. var newEnd2 = oldStart2 + nextChange.newLength;
  5627. oldStartN = Math.min(oldStart1, oldStart2);
  5628. oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1));
  5629. newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2));
  5630. }
  5631. return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN);
  5632. }
  5633. ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions;
  5634. function getTypeParameterOwner(d) {
  5635. if (d && d.kind === 135) {
  5636. for (var current = d; current; current = current.parent) {
  5637. if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 213) {
  5638. return current;
  5639. }
  5640. }
  5641. }
  5642. }
  5643. ts.getTypeParameterOwner = getTypeParameterOwner;
  5644. })(ts || (ts = {}));
  5645. /// <reference path="scanner.ts"/>
  5646. /// <reference path="utilities.ts"/>
  5647. var ts;
  5648. (function (ts) {
  5649. var nodeConstructors = new Array(270);
  5650. ts.parseTime = 0;
  5651. function getNodeConstructor(kind) {
  5652. return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind));
  5653. }
  5654. ts.getNodeConstructor = getNodeConstructor;
  5655. function createNode(kind) {
  5656. return new (getNodeConstructor(kind))();
  5657. }
  5658. ts.createNode = createNode;
  5659. function visitNode(cbNode, node) {
  5660. if (node) {
  5661. return cbNode(node);
  5662. }
  5663. }
  5664. function visitNodeArray(cbNodes, nodes) {
  5665. if (nodes) {
  5666. return cbNodes(nodes);
  5667. }
  5668. }
  5669. function visitEachNode(cbNode, nodes) {
  5670. if (nodes) {
  5671. for (var _i = 0; _i < nodes.length; _i++) {
  5672. var node = nodes[_i];
  5673. var result = cbNode(node);
  5674. if (result) {
  5675. return result;
  5676. }
  5677. }
  5678. }
  5679. }
  5680. function forEachChild(node, cbNode, cbNodeArray) {
  5681. if (!node) {
  5682. return;
  5683. }
  5684. var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode;
  5685. var cbNodes = cbNodeArray || cbNode;
  5686. switch (node.kind) {
  5687. case 133:
  5688. return visitNode(cbNode, node.left) ||
  5689. visitNode(cbNode, node.right);
  5690. case 135:
  5691. return visitNode(cbNode, node.name) ||
  5692. visitNode(cbNode, node.constraint) ||
  5693. visitNode(cbNode, node.expression);
  5694. case 136:
  5695. case 139:
  5696. case 138:
  5697. case 243:
  5698. case 244:
  5699. case 209:
  5700. case 161:
  5701. return visitNodes(cbNodes, node.decorators) ||
  5702. visitNodes(cbNodes, node.modifiers) ||
  5703. visitNode(cbNode, node.propertyName) ||
  5704. visitNode(cbNode, node.dotDotDotToken) ||
  5705. visitNode(cbNode, node.name) ||
  5706. visitNode(cbNode, node.questionToken) ||
  5707. visitNode(cbNode, node.type) ||
  5708. visitNode(cbNode, node.initializer);
  5709. case 150:
  5710. case 151:
  5711. case 145:
  5712. case 146:
  5713. case 147:
  5714. return visitNodes(cbNodes, node.decorators) ||
  5715. visitNodes(cbNodes, node.modifiers) ||
  5716. visitNodes(cbNodes, node.typeParameters) ||
  5717. visitNodes(cbNodes, node.parameters) ||
  5718. visitNode(cbNode, node.type);
  5719. case 141:
  5720. case 140:
  5721. case 142:
  5722. case 143:
  5723. case 144:
  5724. case 171:
  5725. case 211:
  5726. case 172:
  5727. return visitNodes(cbNodes, node.decorators) ||
  5728. visitNodes(cbNodes, node.modifiers) ||
  5729. visitNode(cbNode, node.asteriskToken) ||
  5730. visitNode(cbNode, node.name) ||
  5731. visitNode(cbNode, node.questionToken) ||
  5732. visitNodes(cbNodes, node.typeParameters) ||
  5733. visitNodes(cbNodes, node.parameters) ||
  5734. visitNode(cbNode, node.type) ||
  5735. visitNode(cbNode, node.equalsGreaterThanToken) ||
  5736. visitNode(cbNode, node.body);
  5737. case 149:
  5738. return visitNode(cbNode, node.typeName) ||
  5739. visitNodes(cbNodes, node.typeArguments);
  5740. case 148:
  5741. return visitNode(cbNode, node.parameterName) ||
  5742. visitNode(cbNode, node.type);
  5743. case 152:
  5744. return visitNode(cbNode, node.exprName);
  5745. case 153:
  5746. return visitNodes(cbNodes, node.members);
  5747. case 154:
  5748. return visitNode(cbNode, node.elementType);
  5749. case 155:
  5750. return visitNodes(cbNodes, node.elementTypes);
  5751. case 156:
  5752. case 157:
  5753. return visitNodes(cbNodes, node.types);
  5754. case 158:
  5755. return visitNode(cbNode, node.type);
  5756. case 159:
  5757. case 160:
  5758. return visitNodes(cbNodes, node.elements);
  5759. case 162:
  5760. return visitNodes(cbNodes, node.elements);
  5761. case 163:
  5762. return visitNodes(cbNodes, node.properties);
  5763. case 164:
  5764. return visitNode(cbNode, node.expression) ||
  5765. visitNode(cbNode, node.dotToken) ||
  5766. visitNode(cbNode, node.name);
  5767. case 165:
  5768. return visitNode(cbNode, node.expression) ||
  5769. visitNode(cbNode, node.argumentExpression);
  5770. case 166:
  5771. case 167:
  5772. return visitNode(cbNode, node.expression) ||
  5773. visitNodes(cbNodes, node.typeArguments) ||
  5774. visitNodes(cbNodes, node.arguments);
  5775. case 168:
  5776. return visitNode(cbNode, node.tag) ||
  5777. visitNode(cbNode, node.template);
  5778. case 169:
  5779. return visitNode(cbNode, node.type) ||
  5780. visitNode(cbNode, node.expression);
  5781. case 170:
  5782. return visitNode(cbNode, node.expression);
  5783. case 173:
  5784. return visitNode(cbNode, node.expression);
  5785. case 174:
  5786. return visitNode(cbNode, node.expression);
  5787. case 175:
  5788. return visitNode(cbNode, node.expression);
  5789. case 177:
  5790. return visitNode(cbNode, node.operand);
  5791. case 182:
  5792. return visitNode(cbNode, node.asteriskToken) ||
  5793. visitNode(cbNode, node.expression);
  5794. case 176:
  5795. return visitNode(cbNode, node.expression);
  5796. case 178:
  5797. return visitNode(cbNode, node.operand);
  5798. case 179:
  5799. return visitNode(cbNode, node.left) ||
  5800. visitNode(cbNode, node.operatorToken) ||
  5801. visitNode(cbNode, node.right);
  5802. case 187:
  5803. return visitNode(cbNode, node.expression) ||
  5804. visitNode(cbNode, node.type);
  5805. case 180:
  5806. return visitNode(cbNode, node.condition) ||
  5807. visitNode(cbNode, node.questionToken) ||
  5808. visitNode(cbNode, node.whenTrue) ||
  5809. visitNode(cbNode, node.colonToken) ||
  5810. visitNode(cbNode, node.whenFalse);
  5811. case 183:
  5812. return visitNode(cbNode, node.expression);
  5813. case 190:
  5814. case 217:
  5815. return visitNodes(cbNodes, node.statements);
  5816. case 246:
  5817. return visitNodes(cbNodes, node.statements) ||
  5818. visitNode(cbNode, node.endOfFileToken);
  5819. case 191:
  5820. return visitNodes(cbNodes, node.decorators) ||
  5821. visitNodes(cbNodes, node.modifiers) ||
  5822. visitNode(cbNode, node.declarationList);
  5823. case 210:
  5824. return visitNodes(cbNodes, node.declarations);
  5825. case 193:
  5826. return visitNode(cbNode, node.expression);
  5827. case 194:
  5828. return visitNode(cbNode, node.expression) ||
  5829. visitNode(cbNode, node.thenStatement) ||
  5830. visitNode(cbNode, node.elseStatement);
  5831. case 195:
  5832. return visitNode(cbNode, node.statement) ||
  5833. visitNode(cbNode, node.expression);
  5834. case 196:
  5835. return visitNode(cbNode, node.expression) ||
  5836. visitNode(cbNode, node.statement);
  5837. case 197:
  5838. return visitNode(cbNode, node.initializer) ||
  5839. visitNode(cbNode, node.condition) ||
  5840. visitNode(cbNode, node.incrementor) ||
  5841. visitNode(cbNode, node.statement);
  5842. case 198:
  5843. return visitNode(cbNode, node.initializer) ||
  5844. visitNode(cbNode, node.expression) ||
  5845. visitNode(cbNode, node.statement);
  5846. case 199:
  5847. return visitNode(cbNode, node.initializer) ||
  5848. visitNode(cbNode, node.expression) ||
  5849. visitNode(cbNode, node.statement);
  5850. case 200:
  5851. case 201:
  5852. return visitNode(cbNode, node.label);
  5853. case 202:
  5854. return visitNode(cbNode, node.expression);
  5855. case 203:
  5856. return visitNode(cbNode, node.expression) ||
  5857. visitNode(cbNode, node.statement);
  5858. case 204:
  5859. return visitNode(cbNode, node.expression) ||
  5860. visitNode(cbNode, node.caseBlock);
  5861. case 218:
  5862. return visitNodes(cbNodes, node.clauses);
  5863. case 239:
  5864. return visitNode(cbNode, node.expression) ||
  5865. visitNodes(cbNodes, node.statements);
  5866. case 240:
  5867. return visitNodes(cbNodes, node.statements);
  5868. case 205:
  5869. return visitNode(cbNode, node.label) ||
  5870. visitNode(cbNode, node.statement);
  5871. case 206:
  5872. return visitNode(cbNode, node.expression);
  5873. case 207:
  5874. return visitNode(cbNode, node.tryBlock) ||
  5875. visitNode(cbNode, node.catchClause) ||
  5876. visitNode(cbNode, node.finallyBlock);
  5877. case 242:
  5878. return visitNode(cbNode, node.variableDeclaration) ||
  5879. visitNode(cbNode, node.block);
  5880. case 137:
  5881. return visitNode(cbNode, node.expression);
  5882. case 212:
  5883. case 184:
  5884. return visitNodes(cbNodes, node.decorators) ||
  5885. visitNodes(cbNodes, node.modifiers) ||
  5886. visitNode(cbNode, node.name) ||
  5887. visitNodes(cbNodes, node.typeParameters) ||
  5888. visitNodes(cbNodes, node.heritageClauses) ||
  5889. visitNodes(cbNodes, node.members);
  5890. case 213:
  5891. return visitNodes(cbNodes, node.decorators) ||
  5892. visitNodes(cbNodes, node.modifiers) ||
  5893. visitNode(cbNode, node.name) ||
  5894. visitNodes(cbNodes, node.typeParameters) ||
  5895. visitNodes(cbNodes, node.heritageClauses) ||
  5896. visitNodes(cbNodes, node.members);
  5897. case 214:
  5898. return visitNodes(cbNodes, node.decorators) ||
  5899. visitNodes(cbNodes, node.modifiers) ||
  5900. visitNode(cbNode, node.name) ||
  5901. visitNodes(cbNodes, node.typeParameters) ||
  5902. visitNode(cbNode, node.type);
  5903. case 215:
  5904. return visitNodes(cbNodes, node.decorators) ||
  5905. visitNodes(cbNodes, node.modifiers) ||
  5906. visitNode(cbNode, node.name) ||
  5907. visitNodes(cbNodes, node.members);
  5908. case 245:
  5909. return visitNode(cbNode, node.name) ||
  5910. visitNode(cbNode, node.initializer);
  5911. case 216:
  5912. return visitNodes(cbNodes, node.decorators) ||
  5913. visitNodes(cbNodes, node.modifiers) ||
  5914. visitNode(cbNode, node.name) ||
  5915. visitNode(cbNode, node.body);
  5916. case 219:
  5917. return visitNodes(cbNodes, node.decorators) ||
  5918. visitNodes(cbNodes, node.modifiers) ||
  5919. visitNode(cbNode, node.name) ||
  5920. visitNode(cbNode, node.moduleReference);
  5921. case 220:
  5922. return visitNodes(cbNodes, node.decorators) ||
  5923. visitNodes(cbNodes, node.modifiers) ||
  5924. visitNode(cbNode, node.importClause) ||
  5925. visitNode(cbNode, node.moduleSpecifier);
  5926. case 221:
  5927. return visitNode(cbNode, node.name) ||
  5928. visitNode(cbNode, node.namedBindings);
  5929. case 222:
  5930. return visitNode(cbNode, node.name);
  5931. case 223:
  5932. case 227:
  5933. return visitNodes(cbNodes, node.elements);
  5934. case 226:
  5935. return visitNodes(cbNodes, node.decorators) ||
  5936. visitNodes(cbNodes, node.modifiers) ||
  5937. visitNode(cbNode, node.exportClause) ||
  5938. visitNode(cbNode, node.moduleSpecifier);
  5939. case 224:
  5940. case 228:
  5941. return visitNode(cbNode, node.propertyName) ||
  5942. visitNode(cbNode, node.name);
  5943. case 225:
  5944. return visitNodes(cbNodes, node.decorators) ||
  5945. visitNodes(cbNodes, node.modifiers) ||
  5946. visitNode(cbNode, node.expression);
  5947. case 181:
  5948. return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans);
  5949. case 188:
  5950. return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal);
  5951. case 134:
  5952. return visitNode(cbNode, node.expression);
  5953. case 241:
  5954. return visitNodes(cbNodes, node.types);
  5955. case 186:
  5956. return visitNode(cbNode, node.expression) ||
  5957. visitNodes(cbNodes, node.typeArguments);
  5958. case 230:
  5959. return visitNode(cbNode, node.expression);
  5960. case 229:
  5961. return visitNodes(cbNodes, node.decorators);
  5962. case 231:
  5963. return visitNode(cbNode, node.openingElement) ||
  5964. visitNodes(cbNodes, node.children) ||
  5965. visitNode(cbNode, node.closingElement);
  5966. case 232:
  5967. case 233:
  5968. return visitNode(cbNode, node.tagName) ||
  5969. visitNodes(cbNodes, node.attributes);
  5970. case 236:
  5971. return visitNode(cbNode, node.name) ||
  5972. visitNode(cbNode, node.initializer);
  5973. case 237:
  5974. return visitNode(cbNode, node.expression);
  5975. case 238:
  5976. return visitNode(cbNode, node.expression);
  5977. case 235:
  5978. return visitNode(cbNode, node.tagName);
  5979. case 247:
  5980. return visitNode(cbNode, node.type);
  5981. case 251:
  5982. return visitNodes(cbNodes, node.types);
  5983. case 252:
  5984. return visitNodes(cbNodes, node.types);
  5985. case 250:
  5986. return visitNode(cbNode, node.elementType);
  5987. case 254:
  5988. return visitNode(cbNode, node.type);
  5989. case 253:
  5990. return visitNode(cbNode, node.type);
  5991. case 255:
  5992. return visitNodes(cbNodes, node.members);
  5993. case 257:
  5994. return visitNode(cbNode, node.name) ||
  5995. visitNodes(cbNodes, node.typeArguments);
  5996. case 258:
  5997. return visitNode(cbNode, node.type);
  5998. case 259:
  5999. return visitNodes(cbNodes, node.parameters) ||
  6000. visitNode(cbNode, node.type);
  6001. case 260:
  6002. return visitNode(cbNode, node.type);
  6003. case 261:
  6004. return visitNode(cbNode, node.type);
  6005. case 262:
  6006. return visitNode(cbNode, node.type);
  6007. case 256:
  6008. return visitNode(cbNode, node.name) ||
  6009. visitNode(cbNode, node.type);
  6010. case 263:
  6011. return visitNodes(cbNodes, node.tags);
  6012. case 265:
  6013. return visitNode(cbNode, node.preParameterName) ||
  6014. visitNode(cbNode, node.typeExpression) ||
  6015. visitNode(cbNode, node.postParameterName);
  6016. case 266:
  6017. return visitNode(cbNode, node.typeExpression);
  6018. case 267:
  6019. return visitNode(cbNode, node.typeExpression);
  6020. case 268:
  6021. return visitNodes(cbNodes, node.typeParameters);
  6022. }
  6023. }
  6024. ts.forEachChild = forEachChild;
  6025. function createSourceFile(fileName, sourceText, languageVersion, setParentNodes) {
  6026. if (setParentNodes === void 0) { setParentNodes = false; }
  6027. var start = new Date().getTime();
  6028. var result = Parser.parseSourceFile(fileName, sourceText, languageVersion, undefined, setParentNodes);
  6029. ts.parseTime += new Date().getTime() - start;
  6030. return result;
  6031. }
  6032. ts.createSourceFile = createSourceFile;
  6033. function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
  6034. return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
  6035. }
  6036. ts.updateSourceFile = updateSourceFile;
  6037. function parseIsolatedJSDocComment(content, start, length) {
  6038. return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length);
  6039. }
  6040. ts.parseIsolatedJSDocComment = parseIsolatedJSDocComment;
  6041. function parseJSDocTypeExpressionForTests(content, start, length) {
  6042. return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length);
  6043. }
  6044. ts.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests;
  6045. var Parser;
  6046. (function (Parser) {
  6047. var scanner = ts.createScanner(2, true);
  6048. var disallowInAndDecoratorContext = 1 | 4;
  6049. var sourceFile;
  6050. var parseDiagnostics;
  6051. var syntaxCursor;
  6052. var token;
  6053. var sourceText;
  6054. var nodeCount;
  6055. var identifiers;
  6056. var identifierCount;
  6057. var parsingContext;
  6058. var contextFlags;
  6059. var parseErrorBeforeNextFinishedNode = false;
  6060. function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) {
  6061. initializeState(fileName, _sourceText, languageVersion, _syntaxCursor);
  6062. var result = parseSourceFileWorker(fileName, languageVersion, setParentNodes);
  6063. clearState();
  6064. return result;
  6065. }
  6066. Parser.parseSourceFile = parseSourceFile;
  6067. function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor) {
  6068. sourceText = _sourceText;
  6069. syntaxCursor = _syntaxCursor;
  6070. parseDiagnostics = [];
  6071. parsingContext = 0;
  6072. identifiers = {};
  6073. identifierCount = 0;
  6074. nodeCount = 0;
  6075. contextFlags = ts.isJavaScript(fileName) ? 32 : 0;
  6076. parseErrorBeforeNextFinishedNode = false;
  6077. scanner.setText(sourceText);
  6078. scanner.setOnError(scanError);
  6079. scanner.setScriptTarget(languageVersion);
  6080. scanner.setLanguageVariant(ts.isTsx(fileName) ? 1 : 0);
  6081. }
  6082. function clearState() {
  6083. scanner.setText("");
  6084. scanner.setOnError(undefined);
  6085. parseDiagnostics = undefined;
  6086. sourceFile = undefined;
  6087. identifiers = undefined;
  6088. syntaxCursor = undefined;
  6089. sourceText = undefined;
  6090. }
  6091. function parseSourceFileWorker(fileName, languageVersion, setParentNodes) {
  6092. sourceFile = createSourceFile(fileName, languageVersion);
  6093. token = nextToken();
  6094. processReferenceComments(sourceFile);
  6095. sourceFile.statements = parseList(0, parseStatement);
  6096. ts.Debug.assert(token === 1);
  6097. sourceFile.endOfFileToken = parseTokenNode();
  6098. setExternalModuleIndicator(sourceFile);
  6099. sourceFile.nodeCount = nodeCount;
  6100. sourceFile.identifierCount = identifierCount;
  6101. sourceFile.identifiers = identifiers;
  6102. sourceFile.parseDiagnostics = parseDiagnostics;
  6103. if (setParentNodes) {
  6104. fixupParentReferences(sourceFile);
  6105. }
  6106. if (ts.isJavaScript(fileName)) {
  6107. addJSDocComments();
  6108. }
  6109. return sourceFile;
  6110. }
  6111. function addJSDocComments() {
  6112. forEachChild(sourceFile, visit);
  6113. return;
  6114. function visit(node) {
  6115. switch (node.kind) {
  6116. case 191:
  6117. case 211:
  6118. case 136:
  6119. addJSDocComment(node);
  6120. }
  6121. forEachChild(node, visit);
  6122. }
  6123. }
  6124. function addJSDocComment(node) {
  6125. var comments = ts.getLeadingCommentRangesOfNode(node, sourceFile);
  6126. if (comments) {
  6127. for (var _i = 0; _i < comments.length; _i++) {
  6128. var comment = comments[_i];
  6129. var jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos);
  6130. if (jsDocComment) {
  6131. node.jsDocComment = jsDocComment;
  6132. }
  6133. }
  6134. }
  6135. }
  6136. function fixupParentReferences(sourceFile) {
  6137. // normally parent references are set during binding. However, for clients that only need
  6138. // a syntax tree, and no semantic features, then the binding process is an unnecessary
  6139. // overhead. This functions allows us to set all the parents, without all the expense of
  6140. // binding.
  6141. var parent = sourceFile;
  6142. forEachChild(sourceFile, visitNode);
  6143. return;
  6144. function visitNode(n) {
  6145. if (n.parent !== parent) {
  6146. n.parent = parent;
  6147. var saveParent = parent;
  6148. parent = n;
  6149. forEachChild(n, visitNode);
  6150. parent = saveParent;
  6151. }
  6152. }
  6153. }
  6154. Parser.fixupParentReferences = fixupParentReferences;
  6155. function createSourceFile(fileName, languageVersion) {
  6156. var sourceFile = createNode(246, 0);
  6157. sourceFile.pos = 0;
  6158. sourceFile.end = sourceText.length;
  6159. sourceFile.text = sourceText;
  6160. sourceFile.bindDiagnostics = [];
  6161. sourceFile.languageVersion = languageVersion;
  6162. sourceFile.fileName = ts.normalizePath(fileName);
  6163. sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 8192 : 0;
  6164. sourceFile.languageVariant = ts.isTsx(sourceFile.fileName) ? 1 : 0;
  6165. return sourceFile;
  6166. }
  6167. function setContextFlag(val, flag) {
  6168. if (val) {
  6169. contextFlags |= flag;
  6170. }
  6171. else {
  6172. contextFlags &= ~flag;
  6173. }
  6174. }
  6175. function setDisallowInContext(val) {
  6176. setContextFlag(val, 1);
  6177. }
  6178. function setYieldContext(val) {
  6179. setContextFlag(val, 2);
  6180. }
  6181. function setDecoratorContext(val) {
  6182. setContextFlag(val, 4);
  6183. }
  6184. function setAwaitContext(val) {
  6185. setContextFlag(val, 8);
  6186. }
  6187. function doOutsideOfContext(context, func) {
  6188. var contextFlagsToClear = context & contextFlags;
  6189. if (contextFlagsToClear) {
  6190. setContextFlag(false, contextFlagsToClear);
  6191. var result = func();
  6192. setContextFlag(true, contextFlagsToClear);
  6193. return result;
  6194. }
  6195. return func();
  6196. }
  6197. function doInsideOfContext(context, func) {
  6198. var contextFlagsToSet = context & ~contextFlags;
  6199. if (contextFlagsToSet) {
  6200. setContextFlag(true, contextFlagsToSet);
  6201. var result = func();
  6202. setContextFlag(false, contextFlagsToSet);
  6203. return result;
  6204. }
  6205. return func();
  6206. }
  6207. function allowInAnd(func) {
  6208. return doOutsideOfContext(1, func);
  6209. }
  6210. function disallowInAnd(func) {
  6211. return doInsideOfContext(1, func);
  6212. }
  6213. function doInYieldContext(func) {
  6214. return doInsideOfContext(2, func);
  6215. }
  6216. function doOutsideOfYieldContext(func) {
  6217. return doOutsideOfContext(2, func);
  6218. }
  6219. function doInDecoratorContext(func) {
  6220. return doInsideOfContext(4, func);
  6221. }
  6222. function doInAwaitContext(func) {
  6223. return doInsideOfContext(8, func);
  6224. }
  6225. function doOutsideOfAwaitContext(func) {
  6226. return doOutsideOfContext(8, func);
  6227. }
  6228. function doInYieldAndAwaitContext(func) {
  6229. return doInsideOfContext(2 | 8, func);
  6230. }
  6231. function doOutsideOfYieldAndAwaitContext(func) {
  6232. return doOutsideOfContext(2 | 8, func);
  6233. }
  6234. function inContext(flags) {
  6235. return (contextFlags & flags) !== 0;
  6236. }
  6237. function inYieldContext() {
  6238. return inContext(2);
  6239. }
  6240. function inDisallowInContext() {
  6241. return inContext(1);
  6242. }
  6243. function inDecoratorContext() {
  6244. return inContext(4);
  6245. }
  6246. function inAwaitContext() {
  6247. return inContext(8);
  6248. }
  6249. function parseErrorAtCurrentToken(message, arg0) {
  6250. var start = scanner.getTokenPos();
  6251. var length = scanner.getTextPos() - start;
  6252. parseErrorAtPosition(start, length, message, arg0);
  6253. }
  6254. function parseErrorAtPosition(start, length, message, arg0) {
  6255. var lastError = ts.lastOrUndefined(parseDiagnostics);
  6256. if (!lastError || start !== lastError.start) {
  6257. parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0));
  6258. }
  6259. parseErrorBeforeNextFinishedNode = true;
  6260. }
  6261. function scanError(message, length) {
  6262. var pos = scanner.getTextPos();
  6263. parseErrorAtPosition(pos, length || 0, message);
  6264. }
  6265. function getNodePos() {
  6266. return scanner.getStartPos();
  6267. }
  6268. function getNodeEnd() {
  6269. return scanner.getStartPos();
  6270. }
  6271. function nextToken() {
  6272. return token = scanner.scan();
  6273. }
  6274. function getTokenPos(pos) {
  6275. return ts.skipTrivia(sourceText, pos);
  6276. }
  6277. function reScanGreaterToken() {
  6278. return token = scanner.reScanGreaterToken();
  6279. }
  6280. function reScanSlashToken() {
  6281. return token = scanner.reScanSlashToken();
  6282. }
  6283. function reScanTemplateToken() {
  6284. return token = scanner.reScanTemplateToken();
  6285. }
  6286. function scanJsxIdentifier() {
  6287. return token = scanner.scanJsxIdentifier();
  6288. }
  6289. function scanJsxText() {
  6290. return token = scanner.scanJsxToken();
  6291. }
  6292. function speculationHelper(callback, isLookAhead) {
  6293. var saveToken = token;
  6294. var saveParseDiagnosticsLength = parseDiagnostics.length;
  6295. var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
  6296. var saveContextFlags = contextFlags;
  6297. var result = isLookAhead
  6298. ? scanner.lookAhead(callback)
  6299. : scanner.tryScan(callback);
  6300. ts.Debug.assert(saveContextFlags === contextFlags);
  6301. if (!result || isLookAhead) {
  6302. token = saveToken;
  6303. parseDiagnostics.length = saveParseDiagnosticsLength;
  6304. parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode;
  6305. }
  6306. return result;
  6307. }
  6308. function lookAhead(callback) {
  6309. return speculationHelper(callback, true);
  6310. }
  6311. function tryParse(callback) {
  6312. return speculationHelper(callback, false);
  6313. }
  6314. function isIdentifier() {
  6315. if (token === 67) {
  6316. return true;
  6317. }
  6318. if (token === 112 && inYieldContext()) {
  6319. return false;
  6320. }
  6321. if (token === 117 && inAwaitContext()) {
  6322. return false;
  6323. }
  6324. return token > 103;
  6325. }
  6326. function parseExpected(kind, diagnosticMessage, shouldAdvance) {
  6327. if (shouldAdvance === void 0) { shouldAdvance = true; }
  6328. if (token === kind) {
  6329. if (shouldAdvance) {
  6330. nextToken();
  6331. }
  6332. return true;
  6333. }
  6334. if (diagnosticMessage) {
  6335. parseErrorAtCurrentToken(diagnosticMessage);
  6336. }
  6337. else {
  6338. parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(kind));
  6339. }
  6340. return false;
  6341. }
  6342. function parseOptional(t) {
  6343. if (token === t) {
  6344. nextToken();
  6345. return true;
  6346. }
  6347. return false;
  6348. }
  6349. function parseOptionalToken(t) {
  6350. if (token === t) {
  6351. return parseTokenNode();
  6352. }
  6353. return undefined;
  6354. }
  6355. function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) {
  6356. return parseOptionalToken(t) ||
  6357. createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0);
  6358. }
  6359. function parseTokenNode() {
  6360. var node = createNode(token);
  6361. nextToken();
  6362. return finishNode(node);
  6363. }
  6364. function canParseSemicolon() {
  6365. if (token === 23) {
  6366. return true;
  6367. }
  6368. return token === 16 || token === 1 || scanner.hasPrecedingLineBreak();
  6369. }
  6370. function parseSemicolon() {
  6371. if (canParseSemicolon()) {
  6372. if (token === 23) {
  6373. nextToken();
  6374. }
  6375. return true;
  6376. }
  6377. else {
  6378. return parseExpected(23);
  6379. }
  6380. }
  6381. function createNode(kind, pos) {
  6382. nodeCount++;
  6383. var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)))();
  6384. if (!(pos >= 0)) {
  6385. pos = scanner.getStartPos();
  6386. }
  6387. node.pos = pos;
  6388. node.end = pos;
  6389. return node;
  6390. }
  6391. function finishNode(node, end) {
  6392. node.end = end === undefined ? scanner.getStartPos() : end;
  6393. if (contextFlags) {
  6394. node.parserContextFlags = contextFlags;
  6395. }
  6396. if (parseErrorBeforeNextFinishedNode) {
  6397. parseErrorBeforeNextFinishedNode = false;
  6398. node.parserContextFlags |= 16;
  6399. }
  6400. return node;
  6401. }
  6402. function createMissingNode(kind, reportAtCurrentPosition, diagnosticMessage, arg0) {
  6403. if (reportAtCurrentPosition) {
  6404. parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
  6405. }
  6406. else {
  6407. parseErrorAtCurrentToken(diagnosticMessage, arg0);
  6408. }
  6409. var result = createNode(kind, scanner.getStartPos());
  6410. result.text = "";
  6411. return finishNode(result);
  6412. }
  6413. function internIdentifier(text) {
  6414. text = ts.escapeIdentifier(text);
  6415. return ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
  6416. }
  6417. function createIdentifier(isIdentifier, diagnosticMessage) {
  6418. identifierCount++;
  6419. if (isIdentifier) {
  6420. var node = createNode(67);
  6421. if (token !== 67) {
  6422. node.originalKeywordKind = token;
  6423. }
  6424. node.text = internIdentifier(scanner.getTokenValue());
  6425. nextToken();
  6426. return finishNode(node);
  6427. }
  6428. return createMissingNode(67, false, diagnosticMessage || ts.Diagnostics.Identifier_expected);
  6429. }
  6430. function parseIdentifier(diagnosticMessage) {
  6431. return createIdentifier(isIdentifier(), diagnosticMessage);
  6432. }
  6433. function parseIdentifierName() {
  6434. return createIdentifier(isIdentifierOrKeyword());
  6435. }
  6436. function isLiteralPropertyName() {
  6437. return isIdentifierOrKeyword() ||
  6438. token === 9 ||
  6439. token === 8;
  6440. }
  6441. function parsePropertyNameWorker(allowComputedPropertyNames) {
  6442. if (token === 9 || token === 8) {
  6443. return parseLiteralNode(true);
  6444. }
  6445. if (allowComputedPropertyNames && token === 19) {
  6446. return parseComputedPropertyName();
  6447. }
  6448. return parseIdentifierName();
  6449. }
  6450. function parsePropertyName() {
  6451. return parsePropertyNameWorker(true);
  6452. }
  6453. function parseSimplePropertyName() {
  6454. return parsePropertyNameWorker(false);
  6455. }
  6456. function isSimplePropertyName() {
  6457. return token === 9 || token === 8 || isIdentifierOrKeyword();
  6458. }
  6459. function parseComputedPropertyName() {
  6460. var node = createNode(134);
  6461. parseExpected(19);
  6462. node.expression = allowInAnd(parseExpression);
  6463. parseExpected(20);
  6464. return finishNode(node);
  6465. }
  6466. function parseContextualModifier(t) {
  6467. return token === t && tryParse(nextTokenCanFollowModifier);
  6468. }
  6469. function nextTokenCanFollowModifier() {
  6470. if (token === 72) {
  6471. return nextToken() === 79;
  6472. }
  6473. if (token === 80) {
  6474. nextToken();
  6475. if (token === 75) {
  6476. return lookAhead(nextTokenIsClassOrFunction);
  6477. }
  6478. return token !== 37 && token !== 15 && canFollowModifier();
  6479. }
  6480. if (token === 75) {
  6481. return nextTokenIsClassOrFunction();
  6482. }
  6483. nextToken();
  6484. return canFollowModifier();
  6485. }
  6486. function parseAnyContextualModifier() {
  6487. return ts.isModifier(token) && tryParse(nextTokenCanFollowModifier);
  6488. }
  6489. function canFollowModifier() {
  6490. return token === 19
  6491. || token === 15
  6492. || token === 37
  6493. || isLiteralPropertyName();
  6494. }
  6495. function nextTokenIsClassOrFunction() {
  6496. nextToken();
  6497. return token === 71 || token === 85;
  6498. }
  6499. function isListElement(parsingContext, inErrorRecovery) {
  6500. var node = currentNode(parsingContext);
  6501. if (node) {
  6502. return true;
  6503. }
  6504. switch (parsingContext) {
  6505. case 0:
  6506. case 1:
  6507. case 3:
  6508. return !(token === 23 && inErrorRecovery) && isStartOfStatement();
  6509. case 2:
  6510. return token === 69 || token === 75;
  6511. case 4:
  6512. return isStartOfTypeMember();
  6513. case 5:
  6514. return lookAhead(isClassMemberStart) || (token === 23 && !inErrorRecovery);
  6515. case 6:
  6516. return token === 19 || isLiteralPropertyName();
  6517. case 12:
  6518. return token === 19 || token === 37 || isLiteralPropertyName();
  6519. case 9:
  6520. return isLiteralPropertyName();
  6521. case 7:
  6522. if (token === 15) {
  6523. return lookAhead(isValidHeritageClauseObjectLiteral);
  6524. }
  6525. if (!inErrorRecovery) {
  6526. return isStartOfLeftHandSideExpression() && !isHeritageClauseExtendsOrImplementsKeyword();
  6527. }
  6528. else {
  6529. return isIdentifier() && !isHeritageClauseExtendsOrImplementsKeyword();
  6530. }
  6531. case 8:
  6532. return isIdentifierOrPattern();
  6533. case 10:
  6534. return token === 24 || token === 22 || isIdentifierOrPattern();
  6535. case 17:
  6536. return isIdentifier();
  6537. case 11:
  6538. case 15:
  6539. return token === 24 || token === 22 || isStartOfExpression();
  6540. case 16:
  6541. return isStartOfParameter();
  6542. case 18:
  6543. case 19:
  6544. return token === 24 || isStartOfType();
  6545. case 20:
  6546. return isHeritageClause();
  6547. case 21:
  6548. return isIdentifierOrKeyword();
  6549. case 13:
  6550. return isIdentifierOrKeyword() || token === 15;
  6551. case 14:
  6552. return true;
  6553. case 22:
  6554. case 23:
  6555. case 25:
  6556. return JSDocParser.isJSDocType();
  6557. case 24:
  6558. return isSimplePropertyName();
  6559. }
  6560. ts.Debug.fail("Non-exhaustive case in 'isListElement'.");
  6561. }
  6562. function isValidHeritageClauseObjectLiteral() {
  6563. ts.Debug.assert(token === 15);
  6564. if (nextToken() === 16) {
  6565. var next = nextToken();
  6566. return next === 24 || next === 15 || next === 81 || next === 104;
  6567. }
  6568. return true;
  6569. }
  6570. function nextTokenIsIdentifier() {
  6571. nextToken();
  6572. return isIdentifier();
  6573. }
  6574. function nextTokenIsIdentifierOrKeyword() {
  6575. nextToken();
  6576. return isIdentifierOrKeyword();
  6577. }
  6578. function isHeritageClauseExtendsOrImplementsKeyword() {
  6579. if (token === 104 ||
  6580. token === 81) {
  6581. return lookAhead(nextTokenIsStartOfExpression);
  6582. }
  6583. return false;
  6584. }
  6585. function nextTokenIsStartOfExpression() {
  6586. nextToken();
  6587. return isStartOfExpression();
  6588. }
  6589. function isListTerminator(kind) {
  6590. if (token === 1) {
  6591. return true;
  6592. }
  6593. switch (kind) {
  6594. case 1:
  6595. case 2:
  6596. case 4:
  6597. case 5:
  6598. case 6:
  6599. case 12:
  6600. case 9:
  6601. case 21:
  6602. return token === 16;
  6603. case 3:
  6604. return token === 16 || token === 69 || token === 75;
  6605. case 7:
  6606. return token === 15 || token === 81 || token === 104;
  6607. case 8:
  6608. return isVariableDeclaratorListTerminator();
  6609. case 17:
  6610. return token === 27 || token === 17 || token === 15 || token === 81 || token === 104;
  6611. case 11:
  6612. return token === 18 || token === 23;
  6613. case 15:
  6614. case 19:
  6615. case 10:
  6616. return token === 20;
  6617. case 16:
  6618. return token === 18 || token === 20;
  6619. case 18:
  6620. return token === 27 || token === 17;
  6621. case 20:
  6622. return token === 15 || token === 16;
  6623. case 13:
  6624. return token === 27 || token === 38;
  6625. case 14:
  6626. return token === 25 && lookAhead(nextTokenIsSlash);
  6627. case 22:
  6628. return token === 18 || token === 53 || token === 16;
  6629. case 23:
  6630. return token === 27 || token === 16;
  6631. case 25:
  6632. return token === 20 || token === 16;
  6633. case 24:
  6634. return token === 16;
  6635. }
  6636. }
  6637. function isVariableDeclaratorListTerminator() {
  6638. if (canParseSemicolon()) {
  6639. return true;
  6640. }
  6641. if (isInOrOfKeyword(token)) {
  6642. return true;
  6643. }
  6644. if (token === 34) {
  6645. return true;
  6646. }
  6647. return false;
  6648. }
  6649. function isInSomeParsingContext() {
  6650. for (var kind = 0; kind < 26; kind++) {
  6651. if (parsingContext & (1 << kind)) {
  6652. if (isListElement(kind, true) || isListTerminator(kind)) {
  6653. return true;
  6654. }
  6655. }
  6656. }
  6657. return false;
  6658. }
  6659. function parseList(kind, parseElement) {
  6660. var saveParsingContext = parsingContext;
  6661. parsingContext |= 1 << kind;
  6662. var result = [];
  6663. result.pos = getNodePos();
  6664. while (!isListTerminator(kind)) {
  6665. if (isListElement(kind, false)) {
  6666. var element = parseListElement(kind, parseElement);
  6667. result.push(element);
  6668. continue;
  6669. }
  6670. if (abortParsingListOrMoveToNextToken(kind)) {
  6671. break;
  6672. }
  6673. }
  6674. result.end = getNodeEnd();
  6675. parsingContext = saveParsingContext;
  6676. return result;
  6677. }
  6678. function parseListElement(parsingContext, parseElement) {
  6679. var node = currentNode(parsingContext);
  6680. if (node) {
  6681. return consumeNode(node);
  6682. }
  6683. return parseElement();
  6684. }
  6685. function currentNode(parsingContext) {
  6686. if (parseErrorBeforeNextFinishedNode) {
  6687. return undefined;
  6688. }
  6689. if (!syntaxCursor) {
  6690. return undefined;
  6691. }
  6692. var node = syntaxCursor.currentNode(scanner.getStartPos());
  6693. if (ts.nodeIsMissing(node)) {
  6694. return undefined;
  6695. }
  6696. if (node.intersectsChange) {
  6697. return undefined;
  6698. }
  6699. if (ts.containsParseError(node)) {
  6700. return undefined;
  6701. }
  6702. var nodeContextFlags = node.parserContextFlags & 31;
  6703. if (nodeContextFlags !== contextFlags) {
  6704. return undefined;
  6705. }
  6706. if (!canReuseNode(node, parsingContext)) {
  6707. return undefined;
  6708. }
  6709. return node;
  6710. }
  6711. function consumeNode(node) {
  6712. scanner.setTextPos(node.end);
  6713. nextToken();
  6714. return node;
  6715. }
  6716. function canReuseNode(node, parsingContext) {
  6717. switch (parsingContext) {
  6718. case 5:
  6719. return isReusableClassMember(node);
  6720. case 2:
  6721. return isReusableSwitchClause(node);
  6722. case 0:
  6723. case 1:
  6724. case 3:
  6725. return isReusableStatement(node);
  6726. case 6:
  6727. return isReusableEnumMember(node);
  6728. case 4:
  6729. return isReusableTypeMember(node);
  6730. case 8:
  6731. return isReusableVariableDeclaration(node);
  6732. case 16:
  6733. return isReusableParameter(node);
  6734. case 20:
  6735. case 17:
  6736. case 19:
  6737. case 18:
  6738. case 11:
  6739. case 12:
  6740. case 7:
  6741. case 13:
  6742. case 14:
  6743. }
  6744. return false;
  6745. }
  6746. function isReusableClassMember(node) {
  6747. if (node) {
  6748. switch (node.kind) {
  6749. case 142:
  6750. case 147:
  6751. case 143:
  6752. case 144:
  6753. case 139:
  6754. case 189:
  6755. return true;
  6756. case 141:
  6757. var methodDeclaration = node;
  6758. var nameIsConstructor = methodDeclaration.name.kind === 67 &&
  6759. methodDeclaration.name.originalKeywordKind === 119;
  6760. return !nameIsConstructor;
  6761. }
  6762. }
  6763. return false;
  6764. }
  6765. function isReusableSwitchClause(node) {
  6766. if (node) {
  6767. switch (node.kind) {
  6768. case 239:
  6769. case 240:
  6770. return true;
  6771. }
  6772. }
  6773. return false;
  6774. }
  6775. function isReusableStatement(node) {
  6776. if (node) {
  6777. switch (node.kind) {
  6778. case 211:
  6779. case 191:
  6780. case 190:
  6781. case 194:
  6782. case 193:
  6783. case 206:
  6784. case 202:
  6785. case 204:
  6786. case 201:
  6787. case 200:
  6788. case 198:
  6789. case 199:
  6790. case 197:
  6791. case 196:
  6792. case 203:
  6793. case 192:
  6794. case 207:
  6795. case 205:
  6796. case 195:
  6797. case 208:
  6798. case 220:
  6799. case 219:
  6800. case 226:
  6801. case 225:
  6802. case 216:
  6803. case 212:
  6804. case 213:
  6805. case 215:
  6806. case 214:
  6807. return true;
  6808. }
  6809. }
  6810. return false;
  6811. }
  6812. function isReusableEnumMember(node) {
  6813. return node.kind === 245;
  6814. }
  6815. function isReusableTypeMember(node) {
  6816. if (node) {
  6817. switch (node.kind) {
  6818. case 146:
  6819. case 140:
  6820. case 147:
  6821. case 138:
  6822. case 145:
  6823. return true;
  6824. }
  6825. }
  6826. return false;
  6827. }
  6828. function isReusableVariableDeclaration(node) {
  6829. if (node.kind !== 209) {
  6830. return false;
  6831. }
  6832. var variableDeclarator = node;
  6833. return variableDeclarator.initializer === undefined;
  6834. }
  6835. function isReusableParameter(node) {
  6836. if (node.kind !== 136) {
  6837. return false;
  6838. }
  6839. var parameter = node;
  6840. return parameter.initializer === undefined;
  6841. }
  6842. function abortParsingListOrMoveToNextToken(kind) {
  6843. parseErrorAtCurrentToken(parsingContextErrors(kind));
  6844. if (isInSomeParsingContext()) {
  6845. return true;
  6846. }
  6847. nextToken();
  6848. return false;
  6849. }
  6850. function parsingContextErrors(context) {
  6851. switch (context) {
  6852. case 0: return ts.Diagnostics.Declaration_or_statement_expected;
  6853. case 1: return ts.Diagnostics.Declaration_or_statement_expected;
  6854. case 2: return ts.Diagnostics.case_or_default_expected;
  6855. case 3: return ts.Diagnostics.Statement_expected;
  6856. case 4: return ts.Diagnostics.Property_or_signature_expected;
  6857. case 5: return ts.Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected;
  6858. case 6: return ts.Diagnostics.Enum_member_expected;
  6859. case 7: return ts.Diagnostics.Expression_expected;
  6860. case 8: return ts.Diagnostics.Variable_declaration_expected;
  6861. case 9: return ts.Diagnostics.Property_destructuring_pattern_expected;
  6862. case 10: return ts.Diagnostics.Array_element_destructuring_pattern_expected;
  6863. case 11: return ts.Diagnostics.Argument_expression_expected;
  6864. case 12: return ts.Diagnostics.Property_assignment_expected;
  6865. case 15: return ts.Diagnostics.Expression_or_comma_expected;
  6866. case 16: return ts.Diagnostics.Parameter_declaration_expected;
  6867. case 17: return ts.Diagnostics.Type_parameter_declaration_expected;
  6868. case 18: return ts.Diagnostics.Type_argument_expected;
  6869. case 19: return ts.Diagnostics.Type_expected;
  6870. case 20: return ts.Diagnostics.Unexpected_token_expected;
  6871. case 21: return ts.Diagnostics.Identifier_expected;
  6872. case 13: return ts.Diagnostics.Identifier_expected;
  6873. case 14: return ts.Diagnostics.Identifier_expected;
  6874. case 22: return ts.Diagnostics.Parameter_declaration_expected;
  6875. case 23: return ts.Diagnostics.Type_argument_expected;
  6876. case 25: return ts.Diagnostics.Type_expected;
  6877. case 24: return ts.Diagnostics.Property_assignment_expected;
  6878. }
  6879. }
  6880. ;
  6881. function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimeter) {
  6882. var saveParsingContext = parsingContext;
  6883. parsingContext |= 1 << kind;
  6884. var result = [];
  6885. result.pos = getNodePos();
  6886. var commaStart = -1;
  6887. while (true) {
  6888. if (isListElement(kind, false)) {
  6889. result.push(parseListElement(kind, parseElement));
  6890. commaStart = scanner.getTokenPos();
  6891. if (parseOptional(24)) {
  6892. continue;
  6893. }
  6894. commaStart = -1;
  6895. if (isListTerminator(kind)) {
  6896. break;
  6897. }
  6898. parseExpected(24);
  6899. if (considerSemicolonAsDelimeter && token === 23 && !scanner.hasPrecedingLineBreak()) {
  6900. nextToken();
  6901. }
  6902. continue;
  6903. }
  6904. if (isListTerminator(kind)) {
  6905. break;
  6906. }
  6907. if (abortParsingListOrMoveToNextToken(kind)) {
  6908. break;
  6909. }
  6910. }
  6911. if (commaStart >= 0) {
  6912. result.hasTrailingComma = true;
  6913. }
  6914. result.end = getNodeEnd();
  6915. parsingContext = saveParsingContext;
  6916. return result;
  6917. }
  6918. function createMissingList() {
  6919. var pos = getNodePos();
  6920. var result = [];
  6921. result.pos = pos;
  6922. result.end = pos;
  6923. return result;
  6924. }
  6925. function parseBracketedList(kind, parseElement, open, close) {
  6926. if (parseExpected(open)) {
  6927. var result = parseDelimitedList(kind, parseElement);
  6928. parseExpected(close);
  6929. return result;
  6930. }
  6931. return createMissingList();
  6932. }
  6933. function parseEntityName(allowReservedWords, diagnosticMessage) {
  6934. var entity = parseIdentifier(diagnosticMessage);
  6935. while (parseOptional(21)) {
  6936. var node = createNode(133, entity.pos);
  6937. node.left = entity;
  6938. node.right = parseRightSideOfDot(allowReservedWords);
  6939. entity = finishNode(node);
  6940. }
  6941. return entity;
  6942. }
  6943. function parseRightSideOfDot(allowIdentifierNames) {
  6944. if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) {
  6945. var matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
  6946. if (matchesPattern) {
  6947. return createMissingNode(67, true, ts.Diagnostics.Identifier_expected);
  6948. }
  6949. }
  6950. return allowIdentifierNames ? parseIdentifierName() : parseIdentifier();
  6951. }
  6952. function parseTemplateExpression() {
  6953. var template = createNode(181);
  6954. template.head = parseLiteralNode();
  6955. ts.Debug.assert(template.head.kind === 12, "Template head has wrong token kind");
  6956. var templateSpans = [];
  6957. templateSpans.pos = getNodePos();
  6958. do {
  6959. templateSpans.push(parseTemplateSpan());
  6960. } while (ts.lastOrUndefined(templateSpans).literal.kind === 13);
  6961. templateSpans.end = getNodeEnd();
  6962. template.templateSpans = templateSpans;
  6963. return finishNode(template);
  6964. }
  6965. function parseTemplateSpan() {
  6966. var span = createNode(188);
  6967. span.expression = allowInAnd(parseExpression);
  6968. var literal;
  6969. if (token === 16) {
  6970. reScanTemplateToken();
  6971. literal = parseLiteralNode();
  6972. }
  6973. else {
  6974. literal = parseExpectedToken(14, false, ts.Diagnostics._0_expected, ts.tokenToString(16));
  6975. }
  6976. span.literal = literal;
  6977. return finishNode(span);
  6978. }
  6979. function parseLiteralNode(internName) {
  6980. var node = createNode(token);
  6981. var text = scanner.getTokenValue();
  6982. node.text = internName ? internIdentifier(text) : text;
  6983. if (scanner.hasExtendedUnicodeEscape()) {
  6984. node.hasExtendedUnicodeEscape = true;
  6985. }
  6986. if (scanner.isUnterminated()) {
  6987. node.isUnterminated = true;
  6988. }
  6989. var tokenPos = scanner.getTokenPos();
  6990. nextToken();
  6991. finishNode(node);
  6992. if (node.kind === 8
  6993. && sourceText.charCodeAt(tokenPos) === 48
  6994. && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
  6995. node.flags |= 65536;
  6996. }
  6997. return node;
  6998. }
  6999. function parseTypeReferenceOrTypePredicate() {
  7000. var typeName = parseEntityName(false, ts.Diagnostics.Type_expected);
  7001. if (typeName.kind === 67 && token === 122 && !scanner.hasPrecedingLineBreak()) {
  7002. nextToken();
  7003. var node_1 = createNode(148, typeName.pos);
  7004. node_1.parameterName = typeName;
  7005. node_1.type = parseType();
  7006. return finishNode(node_1);
  7007. }
  7008. var node = createNode(149, typeName.pos);
  7009. node.typeName = typeName;
  7010. if (!scanner.hasPrecedingLineBreak() && token === 25) {
  7011. node.typeArguments = parseBracketedList(18, parseType, 25, 27);
  7012. }
  7013. return finishNode(node);
  7014. }
  7015. function parseTypeQuery() {
  7016. var node = createNode(152);
  7017. parseExpected(99);
  7018. node.exprName = parseEntityName(true);
  7019. return finishNode(node);
  7020. }
  7021. function parseTypeParameter() {
  7022. var node = createNode(135);
  7023. node.name = parseIdentifier();
  7024. if (parseOptional(81)) {
  7025. if (isStartOfType() || !isStartOfExpression()) {
  7026. node.constraint = parseType();
  7027. }
  7028. else {
  7029. node.expression = parseUnaryExpressionOrHigher();
  7030. }
  7031. }
  7032. return finishNode(node);
  7033. }
  7034. function parseTypeParameters() {
  7035. if (token === 25) {
  7036. return parseBracketedList(17, parseTypeParameter, 25, 27);
  7037. }
  7038. }
  7039. function parseParameterType() {
  7040. if (parseOptional(53)) {
  7041. return token === 9
  7042. ? parseLiteralNode(true)
  7043. : parseType();
  7044. }
  7045. return undefined;
  7046. }
  7047. function isStartOfParameter() {
  7048. return token === 22 || isIdentifierOrPattern() || ts.isModifier(token) || token === 54;
  7049. }
  7050. function setModifiers(node, modifiers) {
  7051. if (modifiers) {
  7052. node.flags |= modifiers.flags;
  7053. node.modifiers = modifiers;
  7054. }
  7055. }
  7056. function parseParameter() {
  7057. var node = createNode(136);
  7058. node.decorators = parseDecorators();
  7059. setModifiers(node, parseModifiers());
  7060. node.dotDotDotToken = parseOptionalToken(22);
  7061. node.name = parseIdentifierOrPattern();
  7062. if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(token)) {
  7063. nextToken();
  7064. }
  7065. node.questionToken = parseOptionalToken(52);
  7066. node.type = parseParameterType();
  7067. node.initializer = parseBindingElementInitializer(true);
  7068. return finishNode(node);
  7069. }
  7070. function parseBindingElementInitializer(inParameter) {
  7071. return inParameter ? parseParameterInitializer() : parseNonParameterInitializer();
  7072. }
  7073. function parseParameterInitializer() {
  7074. return parseInitializer(true);
  7075. }
  7076. function fillSignature(returnToken, yieldContext, awaitContext, requireCompleteParameterList, signature) {
  7077. var returnTokenRequired = returnToken === 34;
  7078. signature.typeParameters = parseTypeParameters();
  7079. signature.parameters = parseParameterList(yieldContext, awaitContext, requireCompleteParameterList);
  7080. if (returnTokenRequired) {
  7081. parseExpected(returnToken);
  7082. signature.type = parseType();
  7083. }
  7084. else if (parseOptional(returnToken)) {
  7085. signature.type = parseType();
  7086. }
  7087. }
  7088. function parseParameterList(yieldContext, awaitContext, requireCompleteParameterList) {
  7089. if (parseExpected(17)) {
  7090. var savedYieldContext = inYieldContext();
  7091. var savedAwaitContext = inAwaitContext();
  7092. setYieldContext(yieldContext);
  7093. setAwaitContext(awaitContext);
  7094. var result = parseDelimitedList(16, parseParameter);
  7095. setYieldContext(savedYieldContext);
  7096. setAwaitContext(savedAwaitContext);
  7097. if (!parseExpected(18) && requireCompleteParameterList) {
  7098. return undefined;
  7099. }
  7100. return result;
  7101. }
  7102. return requireCompleteParameterList ? undefined : createMissingList();
  7103. }
  7104. function parseTypeMemberSemicolon() {
  7105. if (parseOptional(24)) {
  7106. return;
  7107. }
  7108. parseSemicolon();
  7109. }
  7110. function parseSignatureMember(kind) {
  7111. var node = createNode(kind);
  7112. if (kind === 146) {
  7113. parseExpected(90);
  7114. }
  7115. fillSignature(53, false, false, false, node);
  7116. parseTypeMemberSemicolon();
  7117. return finishNode(node);
  7118. }
  7119. function isIndexSignature() {
  7120. if (token !== 19) {
  7121. return false;
  7122. }
  7123. return lookAhead(isUnambiguouslyIndexSignature);
  7124. }
  7125. function isUnambiguouslyIndexSignature() {
  7126. nextToken();
  7127. if (token === 22 || token === 20) {
  7128. return true;
  7129. }
  7130. if (ts.isModifier(token)) {
  7131. nextToken();
  7132. if (isIdentifier()) {
  7133. return true;
  7134. }
  7135. }
  7136. else if (!isIdentifier()) {
  7137. return false;
  7138. }
  7139. else {
  7140. nextToken();
  7141. }
  7142. if (token === 53 || token === 24) {
  7143. return true;
  7144. }
  7145. if (token !== 52) {
  7146. return false;
  7147. }
  7148. nextToken();
  7149. return token === 53 || token === 24 || token === 20;
  7150. }
  7151. function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) {
  7152. var node = createNode(147, fullStart);
  7153. node.decorators = decorators;
  7154. setModifiers(node, modifiers);
  7155. node.parameters = parseBracketedList(16, parseParameter, 19, 20);
  7156. node.type = parseTypeAnnotation();
  7157. parseTypeMemberSemicolon();
  7158. return finishNode(node);
  7159. }
  7160. function parsePropertyOrMethodSignature() {
  7161. var fullStart = scanner.getStartPos();
  7162. var name = parsePropertyName();
  7163. var questionToken = parseOptionalToken(52);
  7164. if (token === 17 || token === 25) {
  7165. var method = createNode(140, fullStart);
  7166. method.name = name;
  7167. method.questionToken = questionToken;
  7168. fillSignature(53, false, false, false, method);
  7169. parseTypeMemberSemicolon();
  7170. return finishNode(method);
  7171. }
  7172. else {
  7173. var property = createNode(138, fullStart);
  7174. property.name = name;
  7175. property.questionToken = questionToken;
  7176. property.type = parseTypeAnnotation();
  7177. parseTypeMemberSemicolon();
  7178. return finishNode(property);
  7179. }
  7180. }
  7181. function isStartOfTypeMember() {
  7182. switch (token) {
  7183. case 17:
  7184. case 25:
  7185. case 19:
  7186. return true;
  7187. default:
  7188. if (ts.isModifier(token)) {
  7189. var result = lookAhead(isStartOfIndexSignatureDeclaration);
  7190. if (result) {
  7191. return result;
  7192. }
  7193. }
  7194. return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName);
  7195. }
  7196. }
  7197. function isStartOfIndexSignatureDeclaration() {
  7198. while (ts.isModifier(token)) {
  7199. nextToken();
  7200. }
  7201. return isIndexSignature();
  7202. }
  7203. function isTypeMemberWithLiteralPropertyName() {
  7204. nextToken();
  7205. return token === 17 ||
  7206. token === 25 ||
  7207. token === 52 ||
  7208. token === 53 ||
  7209. canParseSemicolon();
  7210. }
  7211. function parseTypeMember() {
  7212. switch (token) {
  7213. case 17:
  7214. case 25:
  7215. return parseSignatureMember(145);
  7216. case 19:
  7217. return isIndexSignature()
  7218. ? parseIndexSignatureDeclaration(scanner.getStartPos(), undefined, undefined)
  7219. : parsePropertyOrMethodSignature();
  7220. case 90:
  7221. if (lookAhead(isStartOfConstructSignature)) {
  7222. return parseSignatureMember(146);
  7223. }
  7224. case 9:
  7225. case 8:
  7226. return parsePropertyOrMethodSignature();
  7227. default:
  7228. if (ts.isModifier(token)) {
  7229. var result = tryParse(parseIndexSignatureWithModifiers);
  7230. if (result) {
  7231. return result;
  7232. }
  7233. }
  7234. if (isIdentifierOrKeyword()) {
  7235. return parsePropertyOrMethodSignature();
  7236. }
  7237. }
  7238. }
  7239. function parseIndexSignatureWithModifiers() {
  7240. var fullStart = scanner.getStartPos();
  7241. var decorators = parseDecorators();
  7242. var modifiers = parseModifiers();
  7243. return isIndexSignature()
  7244. ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers)
  7245. : undefined;
  7246. }
  7247. function isStartOfConstructSignature() {
  7248. nextToken();
  7249. return token === 17 || token === 25;
  7250. }
  7251. function parseTypeLiteral() {
  7252. var node = createNode(153);
  7253. node.members = parseObjectTypeMembers();
  7254. return finishNode(node);
  7255. }
  7256. function parseObjectTypeMembers() {
  7257. var members;
  7258. if (parseExpected(15)) {
  7259. members = parseList(4, parseTypeMember);
  7260. parseExpected(16);
  7261. }
  7262. else {
  7263. members = createMissingList();
  7264. }
  7265. return members;
  7266. }
  7267. function parseTupleType() {
  7268. var node = createNode(155);
  7269. node.elementTypes = parseBracketedList(19, parseType, 19, 20);
  7270. return finishNode(node);
  7271. }
  7272. function parseParenthesizedType() {
  7273. var node = createNode(158);
  7274. parseExpected(17);
  7275. node.type = parseType();
  7276. parseExpected(18);
  7277. return finishNode(node);
  7278. }
  7279. function parseFunctionOrConstructorType(kind) {
  7280. var node = createNode(kind);
  7281. if (kind === 151) {
  7282. parseExpected(90);
  7283. }
  7284. fillSignature(34, false, false, false, node);
  7285. return finishNode(node);
  7286. }
  7287. function parseKeywordAndNoDot() {
  7288. var node = parseTokenNode();
  7289. return token === 21 ? undefined : node;
  7290. }
  7291. function parseNonArrayType() {
  7292. switch (token) {
  7293. case 115:
  7294. case 128:
  7295. case 126:
  7296. case 118:
  7297. case 129:
  7298. var node = tryParse(parseKeywordAndNoDot);
  7299. return node || parseTypeReferenceOrTypePredicate();
  7300. case 101:
  7301. return parseTokenNode();
  7302. case 99:
  7303. return parseTypeQuery();
  7304. case 15:
  7305. return parseTypeLiteral();
  7306. case 19:
  7307. return parseTupleType();
  7308. case 17:
  7309. return parseParenthesizedType();
  7310. default:
  7311. return parseTypeReferenceOrTypePredicate();
  7312. }
  7313. }
  7314. function isStartOfType() {
  7315. switch (token) {
  7316. case 115:
  7317. case 128:
  7318. case 126:
  7319. case 118:
  7320. case 129:
  7321. case 101:
  7322. case 99:
  7323. case 15:
  7324. case 19:
  7325. case 25:
  7326. case 90:
  7327. return true;
  7328. case 17:
  7329. return lookAhead(isStartOfParenthesizedOrFunctionType);
  7330. default:
  7331. return isIdentifier();
  7332. }
  7333. }
  7334. function isStartOfParenthesizedOrFunctionType() {
  7335. nextToken();
  7336. return token === 18 || isStartOfParameter() || isStartOfType();
  7337. }
  7338. function parseArrayTypeOrHigher() {
  7339. var type = parseNonArrayType();
  7340. while (!scanner.hasPrecedingLineBreak() && parseOptional(19)) {
  7341. parseExpected(20);
  7342. var node = createNode(154, type.pos);
  7343. node.elementType = type;
  7344. type = finishNode(node);
  7345. }
  7346. return type;
  7347. }
  7348. function parseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  7349. var type = parseConstituentType();
  7350. if (token === operator) {
  7351. var types = [type];
  7352. types.pos = type.pos;
  7353. while (parseOptional(operator)) {
  7354. types.push(parseConstituentType());
  7355. }
  7356. types.end = getNodeEnd();
  7357. var node = createNode(kind, type.pos);
  7358. node.types = types;
  7359. type = finishNode(node);
  7360. }
  7361. return type;
  7362. }
  7363. function parseIntersectionTypeOrHigher() {
  7364. return parseUnionOrIntersectionType(157, parseArrayTypeOrHigher, 45);
  7365. }
  7366. function parseUnionTypeOrHigher() {
  7367. return parseUnionOrIntersectionType(156, parseIntersectionTypeOrHigher, 46);
  7368. }
  7369. function isStartOfFunctionType() {
  7370. if (token === 25) {
  7371. return true;
  7372. }
  7373. return token === 17 && lookAhead(isUnambiguouslyStartOfFunctionType);
  7374. }
  7375. function isUnambiguouslyStartOfFunctionType() {
  7376. nextToken();
  7377. if (token === 18 || token === 22) {
  7378. return true;
  7379. }
  7380. if (isIdentifier() || ts.isModifier(token)) {
  7381. nextToken();
  7382. if (token === 53 || token === 24 ||
  7383. token === 52 || token === 55 ||
  7384. isIdentifier() || ts.isModifier(token)) {
  7385. return true;
  7386. }
  7387. if (token === 18) {
  7388. nextToken();
  7389. if (token === 34) {
  7390. return true;
  7391. }
  7392. }
  7393. }
  7394. return false;
  7395. }
  7396. function parseType() {
  7397. return doOutsideOfContext(10, parseTypeWorker);
  7398. }
  7399. function parseTypeWorker() {
  7400. if (isStartOfFunctionType()) {
  7401. return parseFunctionOrConstructorType(150);
  7402. }
  7403. if (token === 90) {
  7404. return parseFunctionOrConstructorType(151);
  7405. }
  7406. return parseUnionTypeOrHigher();
  7407. }
  7408. function parseTypeAnnotation() {
  7409. return parseOptional(53) ? parseType() : undefined;
  7410. }
  7411. function isStartOfLeftHandSideExpression() {
  7412. switch (token) {
  7413. case 95:
  7414. case 93:
  7415. case 91:
  7416. case 97:
  7417. case 82:
  7418. case 8:
  7419. case 9:
  7420. case 11:
  7421. case 12:
  7422. case 17:
  7423. case 19:
  7424. case 15:
  7425. case 85:
  7426. case 71:
  7427. case 90:
  7428. case 38:
  7429. case 59:
  7430. case 67:
  7431. return true;
  7432. default:
  7433. return isIdentifier();
  7434. }
  7435. }
  7436. function isStartOfExpression() {
  7437. if (isStartOfLeftHandSideExpression()) {
  7438. return true;
  7439. }
  7440. switch (token) {
  7441. case 35:
  7442. case 36:
  7443. case 49:
  7444. case 48:
  7445. case 76:
  7446. case 99:
  7447. case 101:
  7448. case 40:
  7449. case 41:
  7450. case 25:
  7451. case 117:
  7452. case 112:
  7453. return true;
  7454. default:
  7455. if (isBinaryOperator()) {
  7456. return true;
  7457. }
  7458. return isIdentifier();
  7459. }
  7460. }
  7461. function isStartOfExpressionStatement() {
  7462. return token !== 15 &&
  7463. token !== 85 &&
  7464. token !== 71 &&
  7465. token !== 54 &&
  7466. isStartOfExpression();
  7467. }
  7468. function allowInAndParseExpression() {
  7469. return allowInAnd(parseExpression);
  7470. }
  7471. function parseExpression() {
  7472. // Expression[in]:
  7473. // AssignmentExpression[in]
  7474. // Expression[in] , AssignmentExpression[in]
  7475. var saveDecoratorContext = inDecoratorContext();
  7476. if (saveDecoratorContext) {
  7477. setDecoratorContext(false);
  7478. }
  7479. var expr = parseAssignmentExpressionOrHigher();
  7480. var operatorToken;
  7481. while ((operatorToken = parseOptionalToken(24))) {
  7482. expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher());
  7483. }
  7484. if (saveDecoratorContext) {
  7485. setDecoratorContext(true);
  7486. }
  7487. return expr;
  7488. }
  7489. function parseInitializer(inParameter) {
  7490. if (token !== 55) {
  7491. if (scanner.hasPrecedingLineBreak() || (inParameter && token === 15) || !isStartOfExpression()) {
  7492. return undefined;
  7493. }
  7494. }
  7495. parseExpected(55);
  7496. return parseAssignmentExpressionOrHigher();
  7497. }
  7498. function parseAssignmentExpressionOrHigher() {
  7499. // AssignmentExpression[in,yield]:
  7500. // 1) ConditionalExpression[?in,?yield]
  7501. // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
  7502. // 3) LeftHandSideExpression AssignmentOperator AssignmentExpression[?in,?yield]
  7503. // 4) ArrowFunctionExpression[?in,?yield]
  7504. // 5) [+Yield] YieldExpression[?In]
  7505. //
  7506. // Note: for ease of implementation we treat productions '2' and '3' as the same thing.
  7507. // (i.e. they're both BinaryExpressions with an assignment operator in it).
  7508. if (isYieldExpression()) {
  7509. return parseYieldExpression();
  7510. }
  7511. var arrowExpression = tryParseParenthesizedArrowFunctionExpression();
  7512. if (arrowExpression) {
  7513. return arrowExpression;
  7514. }
  7515. var expr = parseBinaryExpressionOrHigher(0);
  7516. if (expr.kind === 67 && token === 34) {
  7517. return parseSimpleArrowFunctionExpression(expr);
  7518. }
  7519. if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
  7520. return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher());
  7521. }
  7522. return parseConditionalExpressionRest(expr);
  7523. }
  7524. function isYieldExpression() {
  7525. if (token === 112) {
  7526. if (inYieldContext()) {
  7527. return true;
  7528. }
  7529. return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine);
  7530. }
  7531. return false;
  7532. }
  7533. function nextTokenIsIdentifierOnSameLine() {
  7534. nextToken();
  7535. return !scanner.hasPrecedingLineBreak() && isIdentifier();
  7536. }
  7537. function parseYieldExpression() {
  7538. var node = createNode(182);
  7539. nextToken();
  7540. if (!scanner.hasPrecedingLineBreak() &&
  7541. (token === 37 || isStartOfExpression())) {
  7542. node.asteriskToken = parseOptionalToken(37);
  7543. node.expression = parseAssignmentExpressionOrHigher();
  7544. return finishNode(node);
  7545. }
  7546. else {
  7547. return finishNode(node);
  7548. }
  7549. }
  7550. function parseSimpleArrowFunctionExpression(identifier) {
  7551. ts.Debug.assert(token === 34, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
  7552. var node = createNode(172, identifier.pos);
  7553. var parameter = createNode(136, identifier.pos);
  7554. parameter.name = identifier;
  7555. finishNode(parameter);
  7556. node.parameters = [parameter];
  7557. node.parameters.pos = parameter.pos;
  7558. node.parameters.end = parameter.end;
  7559. node.equalsGreaterThanToken = parseExpectedToken(34, false, ts.Diagnostics._0_expected, "=>");
  7560. node.body = parseArrowFunctionExpressionBody(false);
  7561. return finishNode(node);
  7562. }
  7563. function tryParseParenthesizedArrowFunctionExpression() {
  7564. var triState = isParenthesizedArrowFunctionExpression();
  7565. if (triState === 0) {
  7566. return undefined;
  7567. }
  7568. var arrowFunction = triState === 1
  7569. ? parseParenthesizedArrowFunctionExpressionHead(true)
  7570. : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead);
  7571. if (!arrowFunction) {
  7572. return undefined;
  7573. }
  7574. var isAsync = !!(arrowFunction.flags & 512);
  7575. var lastToken = token;
  7576. arrowFunction.equalsGreaterThanToken = parseExpectedToken(34, false, ts.Diagnostics._0_expected, "=>");
  7577. arrowFunction.body = (lastToken === 34 || lastToken === 15)
  7578. ? parseArrowFunctionExpressionBody(isAsync)
  7579. : parseIdentifier();
  7580. return finishNode(arrowFunction);
  7581. }
  7582. function isParenthesizedArrowFunctionExpression() {
  7583. if (token === 17 || token === 25 || token === 116) {
  7584. return lookAhead(isParenthesizedArrowFunctionExpressionWorker);
  7585. }
  7586. if (token === 34) {
  7587. return 1;
  7588. }
  7589. return 0;
  7590. }
  7591. function isParenthesizedArrowFunctionExpressionWorker() {
  7592. if (token === 116) {
  7593. nextToken();
  7594. if (scanner.hasPrecedingLineBreak()) {
  7595. return 0;
  7596. }
  7597. if (token !== 17 && token !== 25) {
  7598. return 0;
  7599. }
  7600. }
  7601. var first = token;
  7602. var second = nextToken();
  7603. if (first === 17) {
  7604. if (second === 18) {
  7605. var third = nextToken();
  7606. switch (third) {
  7607. case 34:
  7608. case 53:
  7609. case 15:
  7610. return 1;
  7611. default:
  7612. return 0;
  7613. }
  7614. }
  7615. if (second === 19 || second === 15) {
  7616. return 2;
  7617. }
  7618. if (second === 22) {
  7619. return 1;
  7620. }
  7621. if (!isIdentifier()) {
  7622. return 0;
  7623. }
  7624. if (nextToken() === 53) {
  7625. return 1;
  7626. }
  7627. return 2;
  7628. }
  7629. else {
  7630. ts.Debug.assert(first === 25);
  7631. if (!isIdentifier()) {
  7632. return 0;
  7633. }
  7634. if (sourceFile.languageVariant === 1) {
  7635. var isArrowFunctionInJsx = lookAhead(function () {
  7636. var third = nextToken();
  7637. if (third === 81) {
  7638. var fourth = nextToken();
  7639. switch (fourth) {
  7640. case 55:
  7641. case 27:
  7642. return false;
  7643. default:
  7644. return true;
  7645. }
  7646. }
  7647. else if (third === 24) {
  7648. return true;
  7649. }
  7650. return false;
  7651. });
  7652. if (isArrowFunctionInJsx) {
  7653. return 1;
  7654. }
  7655. return 0;
  7656. }
  7657. return 2;
  7658. }
  7659. }
  7660. function parsePossibleParenthesizedArrowFunctionExpressionHead() {
  7661. return parseParenthesizedArrowFunctionExpressionHead(false);
  7662. }
  7663. function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) {
  7664. var node = createNode(172);
  7665. setModifiers(node, parseModifiersForArrowFunction());
  7666. var isAsync = !!(node.flags & 512);
  7667. fillSignature(53, false, isAsync, !allowAmbiguity, node);
  7668. if (!node.parameters) {
  7669. return undefined;
  7670. }
  7671. if (!allowAmbiguity && token !== 34 && token !== 15) {
  7672. return undefined;
  7673. }
  7674. return node;
  7675. }
  7676. function parseArrowFunctionExpressionBody(isAsync) {
  7677. if (token === 15) {
  7678. return parseFunctionBlock(false, isAsync, false);
  7679. }
  7680. if (token !== 23 &&
  7681. token !== 85 &&
  7682. token !== 71 &&
  7683. isStartOfStatement() &&
  7684. !isStartOfExpressionStatement()) {
  7685. return parseFunctionBlock(false, isAsync, true);
  7686. }
  7687. return isAsync
  7688. ? doInAwaitContext(parseAssignmentExpressionOrHigher)
  7689. : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
  7690. }
  7691. function parseConditionalExpressionRest(leftOperand) {
  7692. var questionToken = parseOptionalToken(52);
  7693. if (!questionToken) {
  7694. return leftOperand;
  7695. }
  7696. var node = createNode(180, leftOperand.pos);
  7697. node.condition = leftOperand;
  7698. node.questionToken = questionToken;
  7699. node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher);
  7700. node.colonToken = parseExpectedToken(53, false, ts.Diagnostics._0_expected, ts.tokenToString(53));
  7701. node.whenFalse = parseAssignmentExpressionOrHigher();
  7702. return finishNode(node);
  7703. }
  7704. function parseBinaryExpressionOrHigher(precedence) {
  7705. var leftOperand = parseUnaryExpressionOrHigher();
  7706. return parseBinaryExpressionRest(precedence, leftOperand);
  7707. }
  7708. function isInOrOfKeyword(t) {
  7709. return t === 88 || t === 132;
  7710. }
  7711. function parseBinaryExpressionRest(precedence, leftOperand) {
  7712. while (true) {
  7713. reScanGreaterToken();
  7714. var newPrecedence = getBinaryOperatorPrecedence();
  7715. if (newPrecedence <= precedence) {
  7716. break;
  7717. }
  7718. if (token === 88 && inDisallowInContext()) {
  7719. break;
  7720. }
  7721. if (token === 114) {
  7722. if (scanner.hasPrecedingLineBreak()) {
  7723. break;
  7724. }
  7725. else {
  7726. nextToken();
  7727. leftOperand = makeAsExpression(leftOperand, parseType());
  7728. }
  7729. }
  7730. else {
  7731. leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
  7732. }
  7733. }
  7734. return leftOperand;
  7735. }
  7736. function isBinaryOperator() {
  7737. if (inDisallowInContext() && token === 88) {
  7738. return false;
  7739. }
  7740. return getBinaryOperatorPrecedence() > 0;
  7741. }
  7742. function getBinaryOperatorPrecedence() {
  7743. switch (token) {
  7744. case 51:
  7745. return 1;
  7746. case 50:
  7747. return 2;
  7748. case 46:
  7749. return 3;
  7750. case 47:
  7751. return 4;
  7752. case 45:
  7753. return 5;
  7754. case 30:
  7755. case 31:
  7756. case 32:
  7757. case 33:
  7758. return 6;
  7759. case 25:
  7760. case 27:
  7761. case 28:
  7762. case 29:
  7763. case 89:
  7764. case 88:
  7765. case 114:
  7766. return 7;
  7767. case 42:
  7768. case 43:
  7769. case 44:
  7770. return 8;
  7771. case 35:
  7772. case 36:
  7773. return 9;
  7774. case 37:
  7775. case 38:
  7776. case 39:
  7777. return 10;
  7778. }
  7779. return -1;
  7780. }
  7781. function makeBinaryExpression(left, operatorToken, right) {
  7782. var node = createNode(179, left.pos);
  7783. node.left = left;
  7784. node.operatorToken = operatorToken;
  7785. node.right = right;
  7786. return finishNode(node);
  7787. }
  7788. function makeAsExpression(left, right) {
  7789. var node = createNode(187, left.pos);
  7790. node.expression = left;
  7791. node.type = right;
  7792. return finishNode(node);
  7793. }
  7794. function parsePrefixUnaryExpression() {
  7795. var node = createNode(177);
  7796. node.operator = token;
  7797. nextToken();
  7798. node.operand = parseUnaryExpressionOrHigher();
  7799. return finishNode(node);
  7800. }
  7801. function parseDeleteExpression() {
  7802. var node = createNode(173);
  7803. nextToken();
  7804. node.expression = parseUnaryExpressionOrHigher();
  7805. return finishNode(node);
  7806. }
  7807. function parseTypeOfExpression() {
  7808. var node = createNode(174);
  7809. nextToken();
  7810. node.expression = parseUnaryExpressionOrHigher();
  7811. return finishNode(node);
  7812. }
  7813. function parseVoidExpression() {
  7814. var node = createNode(175);
  7815. nextToken();
  7816. node.expression = parseUnaryExpressionOrHigher();
  7817. return finishNode(node);
  7818. }
  7819. function isAwaitExpression() {
  7820. if (token === 117) {
  7821. if (inAwaitContext()) {
  7822. return true;
  7823. }
  7824. return lookAhead(nextTokenIsIdentifierOnSameLine);
  7825. }
  7826. return false;
  7827. }
  7828. function parseAwaitExpression() {
  7829. var node = createNode(176);
  7830. nextToken();
  7831. node.expression = parseUnaryExpressionOrHigher();
  7832. return finishNode(node);
  7833. }
  7834. function parseUnaryExpressionOrHigher() {
  7835. if (isAwaitExpression()) {
  7836. return parseAwaitExpression();
  7837. }
  7838. switch (token) {
  7839. case 35:
  7840. case 36:
  7841. case 49:
  7842. case 48:
  7843. case 40:
  7844. case 41:
  7845. return parsePrefixUnaryExpression();
  7846. case 76:
  7847. return parseDeleteExpression();
  7848. case 99:
  7849. return parseTypeOfExpression();
  7850. case 101:
  7851. return parseVoidExpression();
  7852. case 25:
  7853. if (sourceFile.languageVariant !== 1) {
  7854. return parseTypeAssertion();
  7855. }
  7856. if (lookAhead(nextTokenIsIdentifierOrKeyword)) {
  7857. return parseJsxElementOrSelfClosingElement(true);
  7858. }
  7859. default:
  7860. return parsePostfixExpressionOrHigher();
  7861. }
  7862. }
  7863. function parsePostfixExpressionOrHigher() {
  7864. var expression = parseLeftHandSideExpressionOrHigher();
  7865. ts.Debug.assert(ts.isLeftHandSideExpression(expression));
  7866. if ((token === 40 || token === 41) && !scanner.hasPrecedingLineBreak()) {
  7867. var node = createNode(178, expression.pos);
  7868. node.operand = expression;
  7869. node.operator = token;
  7870. nextToken();
  7871. return finishNode(node);
  7872. }
  7873. return expression;
  7874. }
  7875. function parseLeftHandSideExpressionOrHigher() {
  7876. var expression = token === 93
  7877. ? parseSuperExpression()
  7878. : parseMemberExpressionOrHigher();
  7879. return parseCallExpressionRest(expression);
  7880. }
  7881. function parseMemberExpressionOrHigher() {
  7882. var expression = parsePrimaryExpression();
  7883. return parseMemberExpressionRest(expression);
  7884. }
  7885. function parseSuperExpression() {
  7886. var expression = parseTokenNode();
  7887. if (token === 17 || token === 21 || token === 19) {
  7888. return expression;
  7889. }
  7890. var node = createNode(164, expression.pos);
  7891. node.expression = expression;
  7892. node.dotToken = parseExpectedToken(21, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
  7893. node.name = parseRightSideOfDot(true);
  7894. return finishNode(node);
  7895. }
  7896. function parseJsxElementOrSelfClosingElement(inExpressionContext) {
  7897. var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext);
  7898. if (opening.kind === 233) {
  7899. var node = createNode(231, opening.pos);
  7900. node.openingElement = opening;
  7901. node.children = parseJsxChildren(node.openingElement.tagName);
  7902. node.closingElement = parseJsxClosingElement(inExpressionContext);
  7903. return finishNode(node);
  7904. }
  7905. else {
  7906. ts.Debug.assert(opening.kind === 232);
  7907. return opening;
  7908. }
  7909. }
  7910. function parseJsxText() {
  7911. var node = createNode(234, scanner.getStartPos());
  7912. token = scanner.scanJsxToken();
  7913. return finishNode(node);
  7914. }
  7915. function parseJsxChild() {
  7916. switch (token) {
  7917. case 234:
  7918. return parseJsxText();
  7919. case 15:
  7920. return parseJsxExpression(false);
  7921. case 25:
  7922. return parseJsxElementOrSelfClosingElement(false);
  7923. }
  7924. ts.Debug.fail("Unknown JSX child kind " + token);
  7925. }
  7926. function parseJsxChildren(openingTagName) {
  7927. var result = [];
  7928. result.pos = scanner.getStartPos();
  7929. var saveParsingContext = parsingContext;
  7930. parsingContext |= 1 << 14;
  7931. while (true) {
  7932. token = scanner.reScanJsxToken();
  7933. if (token === 26) {
  7934. break;
  7935. }
  7936. else if (token === 1) {
  7937. parseErrorAtCurrentToken(ts.Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, ts.getTextOfNodeFromSourceText(sourceText, openingTagName));
  7938. break;
  7939. }
  7940. result.push(parseJsxChild());
  7941. }
  7942. result.end = scanner.getTokenPos();
  7943. parsingContext = saveParsingContext;
  7944. return result;
  7945. }
  7946. function parseJsxOpeningOrSelfClosingElement(inExpressionContext) {
  7947. var fullStart = scanner.getStartPos();
  7948. parseExpected(25);
  7949. var tagName = parseJsxElementName();
  7950. var attributes = parseList(13, parseJsxAttribute);
  7951. var node;
  7952. if (token === 27) {
  7953. node = createNode(233, fullStart);
  7954. scanJsxText();
  7955. }
  7956. else {
  7957. parseExpected(38);
  7958. if (inExpressionContext) {
  7959. parseExpected(27);
  7960. }
  7961. else {
  7962. parseExpected(27, undefined, false);
  7963. scanJsxText();
  7964. }
  7965. node = createNode(232, fullStart);
  7966. }
  7967. node.tagName = tagName;
  7968. node.attributes = attributes;
  7969. return finishNode(node);
  7970. }
  7971. function parseJsxElementName() {
  7972. scanJsxIdentifier();
  7973. var elementName = parseIdentifierName();
  7974. while (parseOptional(21)) {
  7975. scanJsxIdentifier();
  7976. var node = createNode(133, elementName.pos);
  7977. node.left = elementName;
  7978. node.right = parseIdentifierName();
  7979. elementName = finishNode(node);
  7980. }
  7981. return elementName;
  7982. }
  7983. function parseJsxExpression(inExpressionContext) {
  7984. var node = createNode(238);
  7985. parseExpected(15);
  7986. if (token !== 16) {
  7987. node.expression = parseExpression();
  7988. }
  7989. if (inExpressionContext) {
  7990. parseExpected(16);
  7991. }
  7992. else {
  7993. parseExpected(16, undefined, false);
  7994. scanJsxText();
  7995. }
  7996. return finishNode(node);
  7997. }
  7998. function parseJsxAttribute() {
  7999. if (token === 15) {
  8000. return parseJsxSpreadAttribute();
  8001. }
  8002. scanJsxIdentifier();
  8003. var node = createNode(236);
  8004. node.name = parseIdentifierName();
  8005. if (parseOptional(55)) {
  8006. switch (token) {
  8007. case 9:
  8008. node.initializer = parseLiteralNode();
  8009. break;
  8010. default:
  8011. node.initializer = parseJsxExpression(true);
  8012. break;
  8013. }
  8014. }
  8015. return finishNode(node);
  8016. }
  8017. function parseJsxSpreadAttribute() {
  8018. var node = createNode(237);
  8019. parseExpected(15);
  8020. parseExpected(22);
  8021. node.expression = parseExpression();
  8022. parseExpected(16);
  8023. return finishNode(node);
  8024. }
  8025. function parseJsxClosingElement(inExpressionContext) {
  8026. var node = createNode(235);
  8027. parseExpected(26);
  8028. node.tagName = parseJsxElementName();
  8029. if (inExpressionContext) {
  8030. parseExpected(27);
  8031. }
  8032. else {
  8033. parseExpected(27, undefined, false);
  8034. scanJsxText();
  8035. }
  8036. return finishNode(node);
  8037. }
  8038. function parseTypeAssertion() {
  8039. var node = createNode(169);
  8040. parseExpected(25);
  8041. node.type = parseType();
  8042. parseExpected(27);
  8043. node.expression = parseUnaryExpressionOrHigher();
  8044. return finishNode(node);
  8045. }
  8046. function parseMemberExpressionRest(expression) {
  8047. while (true) {
  8048. var dotToken = parseOptionalToken(21);
  8049. if (dotToken) {
  8050. var propertyAccess = createNode(164, expression.pos);
  8051. propertyAccess.expression = expression;
  8052. propertyAccess.dotToken = dotToken;
  8053. propertyAccess.name = parseRightSideOfDot(true);
  8054. expression = finishNode(propertyAccess);
  8055. continue;
  8056. }
  8057. if (!inDecoratorContext() && parseOptional(19)) {
  8058. var indexedAccess = createNode(165, expression.pos);
  8059. indexedAccess.expression = expression;
  8060. if (token !== 20) {
  8061. indexedAccess.argumentExpression = allowInAnd(parseExpression);
  8062. if (indexedAccess.argumentExpression.kind === 9 || indexedAccess.argumentExpression.kind === 8) {
  8063. var literal = indexedAccess.argumentExpression;
  8064. literal.text = internIdentifier(literal.text);
  8065. }
  8066. }
  8067. parseExpected(20);
  8068. expression = finishNode(indexedAccess);
  8069. continue;
  8070. }
  8071. if (token === 11 || token === 12) {
  8072. var tagExpression = createNode(168, expression.pos);
  8073. tagExpression.tag = expression;
  8074. tagExpression.template = token === 11
  8075. ? parseLiteralNode()
  8076. : parseTemplateExpression();
  8077. expression = finishNode(tagExpression);
  8078. continue;
  8079. }
  8080. return expression;
  8081. }
  8082. }
  8083. function parseCallExpressionRest(expression) {
  8084. while (true) {
  8085. expression = parseMemberExpressionRest(expression);
  8086. if (token === 25) {
  8087. var typeArguments = tryParse(parseTypeArgumentsInExpression);
  8088. if (!typeArguments) {
  8089. return expression;
  8090. }
  8091. var callExpr = createNode(166, expression.pos);
  8092. callExpr.expression = expression;
  8093. callExpr.typeArguments = typeArguments;
  8094. callExpr.arguments = parseArgumentList();
  8095. expression = finishNode(callExpr);
  8096. continue;
  8097. }
  8098. else if (token === 17) {
  8099. var callExpr = createNode(166, expression.pos);
  8100. callExpr.expression = expression;
  8101. callExpr.arguments = parseArgumentList();
  8102. expression = finishNode(callExpr);
  8103. continue;
  8104. }
  8105. return expression;
  8106. }
  8107. }
  8108. function parseArgumentList() {
  8109. parseExpected(17);
  8110. var result = parseDelimitedList(11, parseArgumentExpression);
  8111. parseExpected(18);
  8112. return result;
  8113. }
  8114. function parseTypeArgumentsInExpression() {
  8115. if (!parseOptional(25)) {
  8116. return undefined;
  8117. }
  8118. var typeArguments = parseDelimitedList(18, parseType);
  8119. if (!parseExpected(27)) {
  8120. return undefined;
  8121. }
  8122. return typeArguments && canFollowTypeArgumentsInExpression()
  8123. ? typeArguments
  8124. : undefined;
  8125. }
  8126. function canFollowTypeArgumentsInExpression() {
  8127. switch (token) {
  8128. case 17:
  8129. case 21:
  8130. case 18:
  8131. case 20:
  8132. case 53:
  8133. case 23:
  8134. case 52:
  8135. case 30:
  8136. case 32:
  8137. case 31:
  8138. case 33:
  8139. case 50:
  8140. case 51:
  8141. case 47:
  8142. case 45:
  8143. case 46:
  8144. case 16:
  8145. case 1:
  8146. return true;
  8147. case 24:
  8148. case 15:
  8149. default:
  8150. return false;
  8151. }
  8152. }
  8153. function parsePrimaryExpression() {
  8154. switch (token) {
  8155. case 8:
  8156. case 9:
  8157. case 11:
  8158. return parseLiteralNode();
  8159. case 95:
  8160. case 93:
  8161. case 91:
  8162. case 97:
  8163. case 82:
  8164. return parseTokenNode();
  8165. case 17:
  8166. return parseParenthesizedExpression();
  8167. case 19:
  8168. return parseArrayLiteralExpression();
  8169. case 15:
  8170. return parseObjectLiteralExpression();
  8171. case 116:
  8172. if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) {
  8173. break;
  8174. }
  8175. return parseFunctionExpression();
  8176. case 71:
  8177. return parseClassExpression();
  8178. case 85:
  8179. return parseFunctionExpression();
  8180. case 90:
  8181. return parseNewExpression();
  8182. case 38:
  8183. case 59:
  8184. if (reScanSlashToken() === 10) {
  8185. return parseLiteralNode();
  8186. }
  8187. break;
  8188. case 12:
  8189. return parseTemplateExpression();
  8190. }
  8191. return parseIdentifier(ts.Diagnostics.Expression_expected);
  8192. }
  8193. function parseParenthesizedExpression() {
  8194. var node = createNode(170);
  8195. parseExpected(17);
  8196. node.expression = allowInAnd(parseExpression);
  8197. parseExpected(18);
  8198. return finishNode(node);
  8199. }
  8200. function parseSpreadElement() {
  8201. var node = createNode(183);
  8202. parseExpected(22);
  8203. node.expression = parseAssignmentExpressionOrHigher();
  8204. return finishNode(node);
  8205. }
  8206. function parseArgumentOrArrayLiteralElement() {
  8207. return token === 22 ? parseSpreadElement() :
  8208. token === 24 ? createNode(185) :
  8209. parseAssignmentExpressionOrHigher();
  8210. }
  8211. function parseArgumentExpression() {
  8212. return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
  8213. }
  8214. function parseArrayLiteralExpression() {
  8215. var node = createNode(162);
  8216. parseExpected(19);
  8217. if (scanner.hasPrecedingLineBreak())
  8218. node.flags |= 2048;
  8219. node.elements = parseDelimitedList(15, parseArgumentOrArrayLiteralElement);
  8220. parseExpected(20);
  8221. return finishNode(node);
  8222. }
  8223. function tryParseAccessorDeclaration(fullStart, decorators, modifiers) {
  8224. if (parseContextualModifier(121)) {
  8225. return parseAccessorDeclaration(143, fullStart, decorators, modifiers);
  8226. }
  8227. else if (parseContextualModifier(127)) {
  8228. return parseAccessorDeclaration(144, fullStart, decorators, modifiers);
  8229. }
  8230. return undefined;
  8231. }
  8232. function parseObjectLiteralElement() {
  8233. var fullStart = scanner.getStartPos();
  8234. var decorators = parseDecorators();
  8235. var modifiers = parseModifiers();
  8236. var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
  8237. if (accessor) {
  8238. return accessor;
  8239. }
  8240. var asteriskToken = parseOptionalToken(37);
  8241. var tokenIsIdentifier = isIdentifier();
  8242. var nameToken = token;
  8243. var propertyName = parsePropertyName();
  8244. var questionToken = parseOptionalToken(52);
  8245. if (asteriskToken || token === 17 || token === 25) {
  8246. return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken);
  8247. }
  8248. if ((token === 24 || token === 16) && tokenIsIdentifier) {
  8249. var shorthandDeclaration = createNode(244, fullStart);
  8250. shorthandDeclaration.name = propertyName;
  8251. shorthandDeclaration.questionToken = questionToken;
  8252. return finishNode(shorthandDeclaration);
  8253. }
  8254. else {
  8255. var propertyAssignment = createNode(243, fullStart);
  8256. propertyAssignment.name = propertyName;
  8257. propertyAssignment.questionToken = questionToken;
  8258. parseExpected(53);
  8259. propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
  8260. return finishNode(propertyAssignment);
  8261. }
  8262. }
  8263. function parseObjectLiteralExpression() {
  8264. var node = createNode(163);
  8265. parseExpected(15);
  8266. if (scanner.hasPrecedingLineBreak()) {
  8267. node.flags |= 2048;
  8268. }
  8269. node.properties = parseDelimitedList(12, parseObjectLiteralElement, true);
  8270. parseExpected(16);
  8271. return finishNode(node);
  8272. }
  8273. function parseFunctionExpression() {
  8274. var saveDecoratorContext = inDecoratorContext();
  8275. if (saveDecoratorContext) {
  8276. setDecoratorContext(false);
  8277. }
  8278. var node = createNode(171);
  8279. setModifiers(node, parseModifiers());
  8280. parseExpected(85);
  8281. node.asteriskToken = parseOptionalToken(37);
  8282. var isGenerator = !!node.asteriskToken;
  8283. var isAsync = !!(node.flags & 512);
  8284. node.name =
  8285. isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalIdentifier) :
  8286. isGenerator ? doInYieldContext(parseOptionalIdentifier) :
  8287. isAsync ? doInAwaitContext(parseOptionalIdentifier) :
  8288. parseOptionalIdentifier();
  8289. fillSignature(53, isGenerator, isAsync, false, node);
  8290. node.body = parseFunctionBlock(isGenerator, isAsync, false);
  8291. if (saveDecoratorContext) {
  8292. setDecoratorContext(true);
  8293. }
  8294. return finishNode(node);
  8295. }
  8296. function parseOptionalIdentifier() {
  8297. return isIdentifier() ? parseIdentifier() : undefined;
  8298. }
  8299. function parseNewExpression() {
  8300. var node = createNode(167);
  8301. parseExpected(90);
  8302. node.expression = parseMemberExpressionOrHigher();
  8303. node.typeArguments = tryParse(parseTypeArgumentsInExpression);
  8304. if (node.typeArguments || token === 17) {
  8305. node.arguments = parseArgumentList();
  8306. }
  8307. return finishNode(node);
  8308. }
  8309. function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) {
  8310. var node = createNode(190);
  8311. if (parseExpected(15, diagnosticMessage) || ignoreMissingOpenBrace) {
  8312. node.statements = parseList(1, parseStatement);
  8313. parseExpected(16);
  8314. }
  8315. else {
  8316. node.statements = createMissingList();
  8317. }
  8318. return finishNode(node);
  8319. }
  8320. function parseFunctionBlock(allowYield, allowAwait, ignoreMissingOpenBrace, diagnosticMessage) {
  8321. var savedYieldContext = inYieldContext();
  8322. setYieldContext(allowYield);
  8323. var savedAwaitContext = inAwaitContext();
  8324. setAwaitContext(allowAwait);
  8325. var saveDecoratorContext = inDecoratorContext();
  8326. if (saveDecoratorContext) {
  8327. setDecoratorContext(false);
  8328. }
  8329. var block = parseBlock(ignoreMissingOpenBrace, diagnosticMessage);
  8330. if (saveDecoratorContext) {
  8331. setDecoratorContext(true);
  8332. }
  8333. setYieldContext(savedYieldContext);
  8334. setAwaitContext(savedAwaitContext);
  8335. return block;
  8336. }
  8337. function parseEmptyStatement() {
  8338. var node = createNode(192);
  8339. parseExpected(23);
  8340. return finishNode(node);
  8341. }
  8342. function parseIfStatement() {
  8343. var node = createNode(194);
  8344. parseExpected(86);
  8345. parseExpected(17);
  8346. node.expression = allowInAnd(parseExpression);
  8347. parseExpected(18);
  8348. node.thenStatement = parseStatement();
  8349. node.elseStatement = parseOptional(78) ? parseStatement() : undefined;
  8350. return finishNode(node);
  8351. }
  8352. function parseDoStatement() {
  8353. var node = createNode(195);
  8354. parseExpected(77);
  8355. node.statement = parseStatement();
  8356. parseExpected(102);
  8357. parseExpected(17);
  8358. node.expression = allowInAnd(parseExpression);
  8359. parseExpected(18);
  8360. parseOptional(23);
  8361. return finishNode(node);
  8362. }
  8363. function parseWhileStatement() {
  8364. var node = createNode(196);
  8365. parseExpected(102);
  8366. parseExpected(17);
  8367. node.expression = allowInAnd(parseExpression);
  8368. parseExpected(18);
  8369. node.statement = parseStatement();
  8370. return finishNode(node);
  8371. }
  8372. function parseForOrForInOrForOfStatement() {
  8373. var pos = getNodePos();
  8374. parseExpected(84);
  8375. parseExpected(17);
  8376. var initializer = undefined;
  8377. if (token !== 23) {
  8378. if (token === 100 || token === 106 || token === 72) {
  8379. initializer = parseVariableDeclarationList(true);
  8380. }
  8381. else {
  8382. initializer = disallowInAnd(parseExpression);
  8383. }
  8384. }
  8385. var forOrForInOrForOfStatement;
  8386. if (parseOptional(88)) {
  8387. var forInStatement = createNode(198, pos);
  8388. forInStatement.initializer = initializer;
  8389. forInStatement.expression = allowInAnd(parseExpression);
  8390. parseExpected(18);
  8391. forOrForInOrForOfStatement = forInStatement;
  8392. }
  8393. else if (parseOptional(132)) {
  8394. var forOfStatement = createNode(199, pos);
  8395. forOfStatement.initializer = initializer;
  8396. forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher);
  8397. parseExpected(18);
  8398. forOrForInOrForOfStatement = forOfStatement;
  8399. }
  8400. else {
  8401. var forStatement = createNode(197, pos);
  8402. forStatement.initializer = initializer;
  8403. parseExpected(23);
  8404. if (token !== 23 && token !== 18) {
  8405. forStatement.condition = allowInAnd(parseExpression);
  8406. }
  8407. parseExpected(23);
  8408. if (token !== 18) {
  8409. forStatement.incrementor = allowInAnd(parseExpression);
  8410. }
  8411. parseExpected(18);
  8412. forOrForInOrForOfStatement = forStatement;
  8413. }
  8414. forOrForInOrForOfStatement.statement = parseStatement();
  8415. return finishNode(forOrForInOrForOfStatement);
  8416. }
  8417. function parseBreakOrContinueStatement(kind) {
  8418. var node = createNode(kind);
  8419. parseExpected(kind === 201 ? 68 : 73);
  8420. if (!canParseSemicolon()) {
  8421. node.label = parseIdentifier();
  8422. }
  8423. parseSemicolon();
  8424. return finishNode(node);
  8425. }
  8426. function parseReturnStatement() {
  8427. var node = createNode(202);
  8428. parseExpected(92);
  8429. if (!canParseSemicolon()) {
  8430. node.expression = allowInAnd(parseExpression);
  8431. }
  8432. parseSemicolon();
  8433. return finishNode(node);
  8434. }
  8435. function parseWithStatement() {
  8436. var node = createNode(203);
  8437. parseExpected(103);
  8438. parseExpected(17);
  8439. node.expression = allowInAnd(parseExpression);
  8440. parseExpected(18);
  8441. node.statement = parseStatement();
  8442. return finishNode(node);
  8443. }
  8444. function parseCaseClause() {
  8445. var node = createNode(239);
  8446. parseExpected(69);
  8447. node.expression = allowInAnd(parseExpression);
  8448. parseExpected(53);
  8449. node.statements = parseList(3, parseStatement);
  8450. return finishNode(node);
  8451. }
  8452. function parseDefaultClause() {
  8453. var node = createNode(240);
  8454. parseExpected(75);
  8455. parseExpected(53);
  8456. node.statements = parseList(3, parseStatement);
  8457. return finishNode(node);
  8458. }
  8459. function parseCaseOrDefaultClause() {
  8460. return token === 69 ? parseCaseClause() : parseDefaultClause();
  8461. }
  8462. function parseSwitchStatement() {
  8463. var node = createNode(204);
  8464. parseExpected(94);
  8465. parseExpected(17);
  8466. node.expression = allowInAnd(parseExpression);
  8467. parseExpected(18);
  8468. var caseBlock = createNode(218, scanner.getStartPos());
  8469. parseExpected(15);
  8470. caseBlock.clauses = parseList(2, parseCaseOrDefaultClause);
  8471. parseExpected(16);
  8472. node.caseBlock = finishNode(caseBlock);
  8473. return finishNode(node);
  8474. }
  8475. function parseThrowStatement() {
  8476. // ThrowStatement[Yield] :
  8477. // throw [no LineTerminator here]Expression[In, ?Yield];
  8478. var node = createNode(206);
  8479. parseExpected(96);
  8480. node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression);
  8481. parseSemicolon();
  8482. return finishNode(node);
  8483. }
  8484. function parseTryStatement() {
  8485. var node = createNode(207);
  8486. parseExpected(98);
  8487. node.tryBlock = parseBlock(false);
  8488. node.catchClause = token === 70 ? parseCatchClause() : undefined;
  8489. if (!node.catchClause || token === 83) {
  8490. parseExpected(83);
  8491. node.finallyBlock = parseBlock(false);
  8492. }
  8493. return finishNode(node);
  8494. }
  8495. function parseCatchClause() {
  8496. var result = createNode(242);
  8497. parseExpected(70);
  8498. if (parseExpected(17)) {
  8499. result.variableDeclaration = parseVariableDeclaration();
  8500. }
  8501. parseExpected(18);
  8502. result.block = parseBlock(false);
  8503. return finishNode(result);
  8504. }
  8505. function parseDebuggerStatement() {
  8506. var node = createNode(208);
  8507. parseExpected(74);
  8508. parseSemicolon();
  8509. return finishNode(node);
  8510. }
  8511. function parseExpressionOrLabeledStatement() {
  8512. var fullStart = scanner.getStartPos();
  8513. var expression = allowInAnd(parseExpression);
  8514. if (expression.kind === 67 && parseOptional(53)) {
  8515. var labeledStatement = createNode(205, fullStart);
  8516. labeledStatement.label = expression;
  8517. labeledStatement.statement = parseStatement();
  8518. return finishNode(labeledStatement);
  8519. }
  8520. else {
  8521. var expressionStatement = createNode(193, fullStart);
  8522. expressionStatement.expression = expression;
  8523. parseSemicolon();
  8524. return finishNode(expressionStatement);
  8525. }
  8526. }
  8527. function isIdentifierOrKeyword() {
  8528. return token >= 67;
  8529. }
  8530. function nextTokenIsIdentifierOrKeywordOnSameLine() {
  8531. nextToken();
  8532. return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
  8533. }
  8534. function nextTokenIsFunctionKeywordOnSameLine() {
  8535. nextToken();
  8536. return token === 85 && !scanner.hasPrecedingLineBreak();
  8537. }
  8538. function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
  8539. nextToken();
  8540. return (isIdentifierOrKeyword() || token === 8) && !scanner.hasPrecedingLineBreak();
  8541. }
  8542. function isDeclaration() {
  8543. while (true) {
  8544. switch (token) {
  8545. case 100:
  8546. case 106:
  8547. case 72:
  8548. case 85:
  8549. case 71:
  8550. case 79:
  8551. return true;
  8552. case 105:
  8553. case 130:
  8554. return nextTokenIsIdentifierOnSameLine();
  8555. case 123:
  8556. case 124:
  8557. return nextTokenIsIdentifierOrStringLiteralOnSameLine();
  8558. case 116:
  8559. case 120:
  8560. nextToken();
  8561. if (scanner.hasPrecedingLineBreak()) {
  8562. return false;
  8563. }
  8564. continue;
  8565. case 87:
  8566. nextToken();
  8567. return token === 9 || token === 37 ||
  8568. token === 15 || isIdentifierOrKeyword();
  8569. case 80:
  8570. nextToken();
  8571. if (token === 55 || token === 37 ||
  8572. token === 15 || token === 75) {
  8573. return true;
  8574. }
  8575. continue;
  8576. case 110:
  8577. case 108:
  8578. case 109:
  8579. case 111:
  8580. case 113:
  8581. nextToken();
  8582. continue;
  8583. default:
  8584. return false;
  8585. }
  8586. }
  8587. }
  8588. function isStartOfDeclaration() {
  8589. return lookAhead(isDeclaration);
  8590. }
  8591. function isStartOfStatement() {
  8592. switch (token) {
  8593. case 54:
  8594. case 23:
  8595. case 15:
  8596. case 100:
  8597. case 106:
  8598. case 85:
  8599. case 71:
  8600. case 79:
  8601. case 86:
  8602. case 77:
  8603. case 102:
  8604. case 84:
  8605. case 73:
  8606. case 68:
  8607. case 92:
  8608. case 103:
  8609. case 94:
  8610. case 96:
  8611. case 98:
  8612. case 74:
  8613. case 70:
  8614. case 83:
  8615. return true;
  8616. case 72:
  8617. case 80:
  8618. case 87:
  8619. return isStartOfDeclaration();
  8620. case 116:
  8621. case 120:
  8622. case 105:
  8623. case 123:
  8624. case 124:
  8625. case 130:
  8626. return true;
  8627. case 110:
  8628. case 108:
  8629. case 109:
  8630. case 111:
  8631. return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
  8632. default:
  8633. return isStartOfExpression();
  8634. }
  8635. }
  8636. function nextTokenIsIdentifierOrStartOfDestructuring() {
  8637. nextToken();
  8638. return isIdentifier() || token === 15 || token === 19;
  8639. }
  8640. function isLetDeclaration() {
  8641. return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring);
  8642. }
  8643. function parseStatement() {
  8644. switch (token) {
  8645. case 23:
  8646. return parseEmptyStatement();
  8647. case 15:
  8648. return parseBlock(false);
  8649. case 100:
  8650. return parseVariableStatement(scanner.getStartPos(), undefined, undefined);
  8651. case 106:
  8652. if (isLetDeclaration()) {
  8653. return parseVariableStatement(scanner.getStartPos(), undefined, undefined);
  8654. }
  8655. break;
  8656. case 85:
  8657. return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined);
  8658. case 71:
  8659. return parseClassDeclaration(scanner.getStartPos(), undefined, undefined);
  8660. case 86:
  8661. return parseIfStatement();
  8662. case 77:
  8663. return parseDoStatement();
  8664. case 102:
  8665. return parseWhileStatement();
  8666. case 84:
  8667. return parseForOrForInOrForOfStatement();
  8668. case 73:
  8669. return parseBreakOrContinueStatement(200);
  8670. case 68:
  8671. return parseBreakOrContinueStatement(201);
  8672. case 92:
  8673. return parseReturnStatement();
  8674. case 103:
  8675. return parseWithStatement();
  8676. case 94:
  8677. return parseSwitchStatement();
  8678. case 96:
  8679. return parseThrowStatement();
  8680. case 98:
  8681. case 70:
  8682. case 83:
  8683. return parseTryStatement();
  8684. case 74:
  8685. return parseDebuggerStatement();
  8686. case 54:
  8687. return parseDeclaration();
  8688. case 116:
  8689. case 105:
  8690. case 130:
  8691. case 123:
  8692. case 124:
  8693. case 120:
  8694. case 72:
  8695. case 79:
  8696. case 80:
  8697. case 87:
  8698. case 108:
  8699. case 109:
  8700. case 110:
  8701. case 113:
  8702. case 111:
  8703. if (isStartOfDeclaration()) {
  8704. return parseDeclaration();
  8705. }
  8706. break;
  8707. }
  8708. return parseExpressionOrLabeledStatement();
  8709. }
  8710. function parseDeclaration() {
  8711. var fullStart = getNodePos();
  8712. var decorators = parseDecorators();
  8713. var modifiers = parseModifiers();
  8714. switch (token) {
  8715. case 100:
  8716. case 106:
  8717. case 72:
  8718. return parseVariableStatement(fullStart, decorators, modifiers);
  8719. case 85:
  8720. return parseFunctionDeclaration(fullStart, decorators, modifiers);
  8721. case 71:
  8722. return parseClassDeclaration(fullStart, decorators, modifiers);
  8723. case 105:
  8724. return parseInterfaceDeclaration(fullStart, decorators, modifiers);
  8725. case 130:
  8726. return parseTypeAliasDeclaration(fullStart, decorators, modifiers);
  8727. case 79:
  8728. return parseEnumDeclaration(fullStart, decorators, modifiers);
  8729. case 123:
  8730. case 124:
  8731. return parseModuleDeclaration(fullStart, decorators, modifiers);
  8732. case 87:
  8733. return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers);
  8734. case 80:
  8735. nextToken();
  8736. return token === 75 || token === 55 ?
  8737. parseExportAssignment(fullStart, decorators, modifiers) :
  8738. parseExportDeclaration(fullStart, decorators, modifiers);
  8739. default:
  8740. if (decorators || modifiers) {
  8741. var node = createMissingNode(229, true, ts.Diagnostics.Declaration_expected);
  8742. node.pos = fullStart;
  8743. node.decorators = decorators;
  8744. setModifiers(node, modifiers);
  8745. return finishNode(node);
  8746. }
  8747. }
  8748. }
  8749. function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  8750. nextToken();
  8751. return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === 9);
  8752. }
  8753. function parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage) {
  8754. if (token !== 15 && canParseSemicolon()) {
  8755. parseSemicolon();
  8756. return;
  8757. }
  8758. return parseFunctionBlock(isGenerator, isAsync, false, diagnosticMessage);
  8759. }
  8760. function parseArrayBindingElement() {
  8761. if (token === 24) {
  8762. return createNode(185);
  8763. }
  8764. var node = createNode(161);
  8765. node.dotDotDotToken = parseOptionalToken(22);
  8766. node.name = parseIdentifierOrPattern();
  8767. node.initializer = parseBindingElementInitializer(false);
  8768. return finishNode(node);
  8769. }
  8770. function parseObjectBindingElement() {
  8771. var node = createNode(161);
  8772. var tokenIsIdentifier = isIdentifier();
  8773. var propertyName = parsePropertyName();
  8774. if (tokenIsIdentifier && token !== 53) {
  8775. node.name = propertyName;
  8776. }
  8777. else {
  8778. parseExpected(53);
  8779. node.propertyName = propertyName;
  8780. node.name = parseIdentifierOrPattern();
  8781. }
  8782. node.initializer = parseBindingElementInitializer(false);
  8783. return finishNode(node);
  8784. }
  8785. function parseObjectBindingPattern() {
  8786. var node = createNode(159);
  8787. parseExpected(15);
  8788. node.elements = parseDelimitedList(9, parseObjectBindingElement);
  8789. parseExpected(16);
  8790. return finishNode(node);
  8791. }
  8792. function parseArrayBindingPattern() {
  8793. var node = createNode(160);
  8794. parseExpected(19);
  8795. node.elements = parseDelimitedList(10, parseArrayBindingElement);
  8796. parseExpected(20);
  8797. return finishNode(node);
  8798. }
  8799. function isIdentifierOrPattern() {
  8800. return token === 15 || token === 19 || isIdentifier();
  8801. }
  8802. function parseIdentifierOrPattern() {
  8803. if (token === 19) {
  8804. return parseArrayBindingPattern();
  8805. }
  8806. if (token === 15) {
  8807. return parseObjectBindingPattern();
  8808. }
  8809. return parseIdentifier();
  8810. }
  8811. function parseVariableDeclaration() {
  8812. var node = createNode(209);
  8813. node.name = parseIdentifierOrPattern();
  8814. node.type = parseTypeAnnotation();
  8815. if (!isInOrOfKeyword(token)) {
  8816. node.initializer = parseInitializer(false);
  8817. }
  8818. return finishNode(node);
  8819. }
  8820. function parseVariableDeclarationList(inForStatementInitializer) {
  8821. var node = createNode(210);
  8822. switch (token) {
  8823. case 100:
  8824. break;
  8825. case 106:
  8826. node.flags |= 16384;
  8827. break;
  8828. case 72:
  8829. node.flags |= 32768;
  8830. break;
  8831. default:
  8832. ts.Debug.fail();
  8833. }
  8834. nextToken();
  8835. if (token === 132 && lookAhead(canFollowContextualOfKeyword)) {
  8836. node.declarations = createMissingList();
  8837. }
  8838. else {
  8839. var savedDisallowIn = inDisallowInContext();
  8840. setDisallowInContext(inForStatementInitializer);
  8841. node.declarations = parseDelimitedList(8, parseVariableDeclaration);
  8842. setDisallowInContext(savedDisallowIn);
  8843. }
  8844. return finishNode(node);
  8845. }
  8846. function canFollowContextualOfKeyword() {
  8847. return nextTokenIsIdentifier() && nextToken() === 18;
  8848. }
  8849. function parseVariableStatement(fullStart, decorators, modifiers) {
  8850. var node = createNode(191, fullStart);
  8851. node.decorators = decorators;
  8852. setModifiers(node, modifiers);
  8853. node.declarationList = parseVariableDeclarationList(false);
  8854. parseSemicolon();
  8855. return finishNode(node);
  8856. }
  8857. function parseFunctionDeclaration(fullStart, decorators, modifiers) {
  8858. var node = createNode(211, fullStart);
  8859. node.decorators = decorators;
  8860. setModifiers(node, modifiers);
  8861. parseExpected(85);
  8862. node.asteriskToken = parseOptionalToken(37);
  8863. node.name = node.flags & 1024 ? parseOptionalIdentifier() : parseIdentifier();
  8864. var isGenerator = !!node.asteriskToken;
  8865. var isAsync = !!(node.flags & 512);
  8866. fillSignature(53, isGenerator, isAsync, false, node);
  8867. node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected);
  8868. return finishNode(node);
  8869. }
  8870. function parseConstructorDeclaration(pos, decorators, modifiers) {
  8871. var node = createNode(142, pos);
  8872. node.decorators = decorators;
  8873. setModifiers(node, modifiers);
  8874. parseExpected(119);
  8875. fillSignature(53, false, false, false, node);
  8876. node.body = parseFunctionBlockOrSemicolon(false, false, ts.Diagnostics.or_expected);
  8877. return finishNode(node);
  8878. }
  8879. function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) {
  8880. var method = createNode(141, fullStart);
  8881. method.decorators = decorators;
  8882. setModifiers(method, modifiers);
  8883. method.asteriskToken = asteriskToken;
  8884. method.name = name;
  8885. method.questionToken = questionToken;
  8886. var isGenerator = !!asteriskToken;
  8887. var isAsync = !!(method.flags & 512);
  8888. fillSignature(53, isGenerator, isAsync, false, method);
  8889. method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage);
  8890. return finishNode(method);
  8891. }
  8892. function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) {
  8893. var property = createNode(139, fullStart);
  8894. property.decorators = decorators;
  8895. setModifiers(property, modifiers);
  8896. property.name = name;
  8897. property.questionToken = questionToken;
  8898. property.type = parseTypeAnnotation();
  8899. property.initializer = modifiers && modifiers.flags & 128
  8900. ? allowInAnd(parseNonParameterInitializer)
  8901. : doOutsideOfContext(2 | 1, parseNonParameterInitializer);
  8902. parseSemicolon();
  8903. return finishNode(property);
  8904. }
  8905. function parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers) {
  8906. var asteriskToken = parseOptionalToken(37);
  8907. var name = parsePropertyName();
  8908. var questionToken = parseOptionalToken(52);
  8909. if (asteriskToken || token === 17 || token === 25) {
  8910. return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected);
  8911. }
  8912. else {
  8913. return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken);
  8914. }
  8915. }
  8916. function parseNonParameterInitializer() {
  8917. return parseInitializer(false);
  8918. }
  8919. function parseAccessorDeclaration(kind, fullStart, decorators, modifiers) {
  8920. var node = createNode(kind, fullStart);
  8921. node.decorators = decorators;
  8922. setModifiers(node, modifiers);
  8923. node.name = parsePropertyName();
  8924. fillSignature(53, false, false, false, node);
  8925. node.body = parseFunctionBlockOrSemicolon(false, false);
  8926. return finishNode(node);
  8927. }
  8928. function isClassMemberModifier(idToken) {
  8929. switch (idToken) {
  8930. case 110:
  8931. case 108:
  8932. case 109:
  8933. case 111:
  8934. return true;
  8935. default:
  8936. return false;
  8937. }
  8938. }
  8939. function isClassMemberStart() {
  8940. var idToken;
  8941. if (token === 54) {
  8942. return true;
  8943. }
  8944. while (ts.isModifier(token)) {
  8945. idToken = token;
  8946. if (isClassMemberModifier(idToken)) {
  8947. return true;
  8948. }
  8949. nextToken();
  8950. }
  8951. if (token === 37) {
  8952. return true;
  8953. }
  8954. if (isLiteralPropertyName()) {
  8955. idToken = token;
  8956. nextToken();
  8957. }
  8958. if (token === 19) {
  8959. return true;
  8960. }
  8961. if (idToken !== undefined) {
  8962. if (!ts.isKeyword(idToken) || idToken === 127 || idToken === 121) {
  8963. return true;
  8964. }
  8965. switch (token) {
  8966. case 17:
  8967. case 25:
  8968. case 53:
  8969. case 55:
  8970. case 52:
  8971. return true;
  8972. default:
  8973. return canParseSemicolon();
  8974. }
  8975. }
  8976. return false;
  8977. }
  8978. function parseDecorators() {
  8979. var decorators;
  8980. while (true) {
  8981. var decoratorStart = getNodePos();
  8982. if (!parseOptional(54)) {
  8983. break;
  8984. }
  8985. if (!decorators) {
  8986. decorators = [];
  8987. decorators.pos = scanner.getStartPos();
  8988. }
  8989. var decorator = createNode(137, decoratorStart);
  8990. decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher);
  8991. decorators.push(finishNode(decorator));
  8992. }
  8993. if (decorators) {
  8994. decorators.end = getNodeEnd();
  8995. }
  8996. return decorators;
  8997. }
  8998. function parseModifiers() {
  8999. var flags = 0;
  9000. var modifiers;
  9001. while (true) {
  9002. var modifierStart = scanner.getStartPos();
  9003. var modifierKind = token;
  9004. if (!parseAnyContextualModifier()) {
  9005. break;
  9006. }
  9007. if (!modifiers) {
  9008. modifiers = [];
  9009. modifiers.pos = modifierStart;
  9010. }
  9011. flags |= ts.modifierToFlag(modifierKind);
  9012. modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
  9013. }
  9014. if (modifiers) {
  9015. modifiers.flags = flags;
  9016. modifiers.end = scanner.getStartPos();
  9017. }
  9018. return modifiers;
  9019. }
  9020. function parseModifiersForArrowFunction() {
  9021. var flags = 0;
  9022. var modifiers;
  9023. if (token === 116) {
  9024. var modifierStart = scanner.getStartPos();
  9025. var modifierKind = token;
  9026. nextToken();
  9027. modifiers = [];
  9028. modifiers.pos = modifierStart;
  9029. flags |= ts.modifierToFlag(modifierKind);
  9030. modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
  9031. modifiers.flags = flags;
  9032. modifiers.end = scanner.getStartPos();
  9033. }
  9034. return modifiers;
  9035. }
  9036. function parseClassElement() {
  9037. if (token === 23) {
  9038. var result = createNode(189);
  9039. nextToken();
  9040. return finishNode(result);
  9041. }
  9042. var fullStart = getNodePos();
  9043. var decorators = parseDecorators();
  9044. var modifiers = parseModifiers();
  9045. var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
  9046. if (accessor) {
  9047. return accessor;
  9048. }
  9049. if (token === 119) {
  9050. return parseConstructorDeclaration(fullStart, decorators, modifiers);
  9051. }
  9052. if (isIndexSignature()) {
  9053. return parseIndexSignatureDeclaration(fullStart, decorators, modifiers);
  9054. }
  9055. if (isIdentifierOrKeyword() ||
  9056. token === 9 ||
  9057. token === 8 ||
  9058. token === 37 ||
  9059. token === 19) {
  9060. return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers);
  9061. }
  9062. if (decorators || modifiers) {
  9063. var name_7 = createMissingNode(67, true, ts.Diagnostics.Declaration_expected);
  9064. return parsePropertyDeclaration(fullStart, decorators, modifiers, name_7, undefined);
  9065. }
  9066. ts.Debug.fail("Should not have attempted to parse class member declaration.");
  9067. }
  9068. function parseClassExpression() {
  9069. return parseClassDeclarationOrExpression(scanner.getStartPos(), undefined, undefined, 184);
  9070. }
  9071. function parseClassDeclaration(fullStart, decorators, modifiers) {
  9072. return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 212);
  9073. }
  9074. function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) {
  9075. var node = createNode(kind, fullStart);
  9076. node.decorators = decorators;
  9077. setModifiers(node, modifiers);
  9078. parseExpected(71);
  9079. node.name = parseOptionalIdentifier();
  9080. node.typeParameters = parseTypeParameters();
  9081. node.heritageClauses = parseHeritageClauses(true);
  9082. if (parseExpected(15)) {
  9083. node.members = parseClassMembers();
  9084. parseExpected(16);
  9085. }
  9086. else {
  9087. node.members = createMissingList();
  9088. }
  9089. return finishNode(node);
  9090. }
  9091. function parseHeritageClauses(isClassHeritageClause) {
  9092. // ClassTail[Yield,Await] : (Modified) See 14.5
  9093. // ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt }
  9094. if (isHeritageClause()) {
  9095. return parseList(20, parseHeritageClause);
  9096. }
  9097. return undefined;
  9098. }
  9099. function parseHeritageClausesWorker() {
  9100. return parseList(20, parseHeritageClause);
  9101. }
  9102. function parseHeritageClause() {
  9103. if (token === 81 || token === 104) {
  9104. var node = createNode(241);
  9105. node.token = token;
  9106. nextToken();
  9107. node.types = parseDelimitedList(7, parseExpressionWithTypeArguments);
  9108. return finishNode(node);
  9109. }
  9110. return undefined;
  9111. }
  9112. function parseExpressionWithTypeArguments() {
  9113. var node = createNode(186);
  9114. node.expression = parseLeftHandSideExpressionOrHigher();
  9115. if (token === 25) {
  9116. node.typeArguments = parseBracketedList(18, parseType, 25, 27);
  9117. }
  9118. return finishNode(node);
  9119. }
  9120. function isHeritageClause() {
  9121. return token === 81 || token === 104;
  9122. }
  9123. function parseClassMembers() {
  9124. return parseList(5, parseClassElement);
  9125. }
  9126. function parseInterfaceDeclaration(fullStart, decorators, modifiers) {
  9127. var node = createNode(213, fullStart);
  9128. node.decorators = decorators;
  9129. setModifiers(node, modifiers);
  9130. parseExpected(105);
  9131. node.name = parseIdentifier();
  9132. node.typeParameters = parseTypeParameters();
  9133. node.heritageClauses = parseHeritageClauses(false);
  9134. node.members = parseObjectTypeMembers();
  9135. return finishNode(node);
  9136. }
  9137. function parseTypeAliasDeclaration(fullStart, decorators, modifiers) {
  9138. var node = createNode(214, fullStart);
  9139. node.decorators = decorators;
  9140. setModifiers(node, modifiers);
  9141. parseExpected(130);
  9142. node.name = parseIdentifier();
  9143. node.typeParameters = parseTypeParameters();
  9144. parseExpected(55);
  9145. node.type = parseType();
  9146. parseSemicolon();
  9147. return finishNode(node);
  9148. }
  9149. function parseEnumMember() {
  9150. var node = createNode(245, scanner.getStartPos());
  9151. node.name = parsePropertyName();
  9152. node.initializer = allowInAnd(parseNonParameterInitializer);
  9153. return finishNode(node);
  9154. }
  9155. function parseEnumDeclaration(fullStart, decorators, modifiers) {
  9156. var node = createNode(215, fullStart);
  9157. node.decorators = decorators;
  9158. setModifiers(node, modifiers);
  9159. parseExpected(79);
  9160. node.name = parseIdentifier();
  9161. if (parseExpected(15)) {
  9162. node.members = parseDelimitedList(6, parseEnumMember);
  9163. parseExpected(16);
  9164. }
  9165. else {
  9166. node.members = createMissingList();
  9167. }
  9168. return finishNode(node);
  9169. }
  9170. function parseModuleBlock() {
  9171. var node = createNode(217, scanner.getStartPos());
  9172. if (parseExpected(15)) {
  9173. node.statements = parseList(1, parseStatement);
  9174. parseExpected(16);
  9175. }
  9176. else {
  9177. node.statements = createMissingList();
  9178. }
  9179. return finishNode(node);
  9180. }
  9181. function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) {
  9182. var node = createNode(216, fullStart);
  9183. node.decorators = decorators;
  9184. setModifiers(node, modifiers);
  9185. node.flags |= flags;
  9186. node.name = parseIdentifier();
  9187. node.body = parseOptional(21)
  9188. ? parseModuleOrNamespaceDeclaration(getNodePos(), undefined, undefined, 1)
  9189. : parseModuleBlock();
  9190. return finishNode(node);
  9191. }
  9192. function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) {
  9193. var node = createNode(216, fullStart);
  9194. node.decorators = decorators;
  9195. setModifiers(node, modifiers);
  9196. node.name = parseLiteralNode(true);
  9197. node.body = parseModuleBlock();
  9198. return finishNode(node);
  9199. }
  9200. function parseModuleDeclaration(fullStart, decorators, modifiers) {
  9201. var flags = modifiers ? modifiers.flags : 0;
  9202. if (parseOptional(124)) {
  9203. flags |= 131072;
  9204. }
  9205. else {
  9206. parseExpected(123);
  9207. if (token === 9) {
  9208. return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers);
  9209. }
  9210. }
  9211. return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags);
  9212. }
  9213. function isExternalModuleReference() {
  9214. return token === 125 &&
  9215. lookAhead(nextTokenIsOpenParen);
  9216. }
  9217. function nextTokenIsOpenParen() {
  9218. return nextToken() === 17;
  9219. }
  9220. function nextTokenIsSlash() {
  9221. return nextToken() === 38;
  9222. }
  9223. function nextTokenIsCommaOrFromKeyword() {
  9224. nextToken();
  9225. return token === 24 ||
  9226. token === 131;
  9227. }
  9228. function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) {
  9229. parseExpected(87);
  9230. var afterImportPos = scanner.getStartPos();
  9231. var identifier;
  9232. if (isIdentifier()) {
  9233. identifier = parseIdentifier();
  9234. if (token !== 24 && token !== 131) {
  9235. var importEqualsDeclaration = createNode(219, fullStart);
  9236. importEqualsDeclaration.decorators = decorators;
  9237. setModifiers(importEqualsDeclaration, modifiers);
  9238. importEqualsDeclaration.name = identifier;
  9239. parseExpected(55);
  9240. importEqualsDeclaration.moduleReference = parseModuleReference();
  9241. parseSemicolon();
  9242. return finishNode(importEqualsDeclaration);
  9243. }
  9244. }
  9245. var importDeclaration = createNode(220, fullStart);
  9246. importDeclaration.decorators = decorators;
  9247. setModifiers(importDeclaration, modifiers);
  9248. if (identifier ||
  9249. token === 37 ||
  9250. token === 15) {
  9251. importDeclaration.importClause = parseImportClause(identifier, afterImportPos);
  9252. parseExpected(131);
  9253. }
  9254. importDeclaration.moduleSpecifier = parseModuleSpecifier();
  9255. parseSemicolon();
  9256. return finishNode(importDeclaration);
  9257. }
  9258. function parseImportClause(identifier, fullStart) {
  9259. // ImportClause:
  9260. // ImportedDefaultBinding
  9261. // NameSpaceImport
  9262. // NamedImports
  9263. // ImportedDefaultBinding, NameSpaceImport
  9264. // ImportedDefaultBinding, NamedImports
  9265. var importClause = createNode(221, fullStart);
  9266. if (identifier) {
  9267. importClause.name = identifier;
  9268. }
  9269. if (!importClause.name ||
  9270. parseOptional(24)) {
  9271. importClause.namedBindings = token === 37 ? parseNamespaceImport() : parseNamedImportsOrExports(223);
  9272. }
  9273. return finishNode(importClause);
  9274. }
  9275. function parseModuleReference() {
  9276. return isExternalModuleReference()
  9277. ? parseExternalModuleReference()
  9278. : parseEntityName(false);
  9279. }
  9280. function parseExternalModuleReference() {
  9281. var node = createNode(230);
  9282. parseExpected(125);
  9283. parseExpected(17);
  9284. node.expression = parseModuleSpecifier();
  9285. parseExpected(18);
  9286. return finishNode(node);
  9287. }
  9288. function parseModuleSpecifier() {
  9289. var result = parseExpression();
  9290. if (result.kind === 9) {
  9291. internIdentifier(result.text);
  9292. }
  9293. return result;
  9294. }
  9295. function parseNamespaceImport() {
  9296. var namespaceImport = createNode(222);
  9297. parseExpected(37);
  9298. parseExpected(114);
  9299. namespaceImport.name = parseIdentifier();
  9300. return finishNode(namespaceImport);
  9301. }
  9302. function parseNamedImportsOrExports(kind) {
  9303. var node = createNode(kind);
  9304. node.elements = parseBracketedList(21, kind === 223 ? parseImportSpecifier : parseExportSpecifier, 15, 16);
  9305. return finishNode(node);
  9306. }
  9307. function parseExportSpecifier() {
  9308. return parseImportOrExportSpecifier(228);
  9309. }
  9310. function parseImportSpecifier() {
  9311. return parseImportOrExportSpecifier(224);
  9312. }
  9313. function parseImportOrExportSpecifier(kind) {
  9314. var node = createNode(kind);
  9315. var checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
  9316. var checkIdentifierStart = scanner.getTokenPos();
  9317. var checkIdentifierEnd = scanner.getTextPos();
  9318. var identifierName = parseIdentifierName();
  9319. if (token === 114) {
  9320. node.propertyName = identifierName;
  9321. parseExpected(114);
  9322. checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
  9323. checkIdentifierStart = scanner.getTokenPos();
  9324. checkIdentifierEnd = scanner.getTextPos();
  9325. node.name = parseIdentifierName();
  9326. }
  9327. else {
  9328. node.name = identifierName;
  9329. }
  9330. if (kind === 224 && checkIdentifierIsKeyword) {
  9331. parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected);
  9332. }
  9333. return finishNode(node);
  9334. }
  9335. function parseExportDeclaration(fullStart, decorators, modifiers) {
  9336. var node = createNode(226, fullStart);
  9337. node.decorators = decorators;
  9338. setModifiers(node, modifiers);
  9339. if (parseOptional(37)) {
  9340. parseExpected(131);
  9341. node.moduleSpecifier = parseModuleSpecifier();
  9342. }
  9343. else {
  9344. node.exportClause = parseNamedImportsOrExports(227);
  9345. if (token === 131 || (token === 9 && !scanner.hasPrecedingLineBreak())) {
  9346. parseExpected(131);
  9347. node.moduleSpecifier = parseModuleSpecifier();
  9348. }
  9349. }
  9350. parseSemicolon();
  9351. return finishNode(node);
  9352. }
  9353. function parseExportAssignment(fullStart, decorators, modifiers) {
  9354. var node = createNode(225, fullStart);
  9355. node.decorators = decorators;
  9356. setModifiers(node, modifiers);
  9357. if (parseOptional(55)) {
  9358. node.isExportEquals = true;
  9359. }
  9360. else {
  9361. parseExpected(75);
  9362. }
  9363. node.expression = parseAssignmentExpressionOrHigher();
  9364. parseSemicolon();
  9365. return finishNode(node);
  9366. }
  9367. function processReferenceComments(sourceFile) {
  9368. var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, 0, sourceText);
  9369. var referencedFiles = [];
  9370. var amdDependencies = [];
  9371. var amdModuleName;
  9372. while (true) {
  9373. var kind = triviaScanner.scan();
  9374. if (kind === 5 || kind === 4 || kind === 3) {
  9375. continue;
  9376. }
  9377. if (kind !== 2) {
  9378. break;
  9379. }
  9380. var range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos(), kind: triviaScanner.getToken() };
  9381. var comment = sourceText.substring(range.pos, range.end);
  9382. var referencePathMatchResult = ts.getFileReferenceFromReferencePath(comment, range);
  9383. if (referencePathMatchResult) {
  9384. var fileReference = referencePathMatchResult.fileReference;
  9385. sourceFile.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
  9386. var diagnosticMessage = referencePathMatchResult.diagnosticMessage;
  9387. if (fileReference) {
  9388. referencedFiles.push(fileReference);
  9389. }
  9390. if (diagnosticMessage) {
  9391. parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
  9392. }
  9393. }
  9394. else {
  9395. var amdModuleNameRegEx = /^\/\/\/\s*<amd-module\s+name\s*=\s*('|")(.+?)\1/gim;
  9396. var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
  9397. if (amdModuleNameMatchResult) {
  9398. if (amdModuleName) {
  9399. parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
  9400. }
  9401. amdModuleName = amdModuleNameMatchResult[2];
  9402. }
  9403. var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s/gim;
  9404. var pathRegex = /\spath\s*=\s*('|")(.+?)\1/gim;
  9405. var nameRegex = /\sname\s*=\s*('|")(.+?)\1/gim;
  9406. var amdDependencyMatchResult = amdDependencyRegEx.exec(comment);
  9407. if (amdDependencyMatchResult) {
  9408. var pathMatchResult = pathRegex.exec(comment);
  9409. var nameMatchResult = nameRegex.exec(comment);
  9410. if (pathMatchResult) {
  9411. var amdDependency = { path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
  9412. amdDependencies.push(amdDependency);
  9413. }
  9414. }
  9415. }
  9416. }
  9417. sourceFile.referencedFiles = referencedFiles;
  9418. sourceFile.amdDependencies = amdDependencies;
  9419. sourceFile.moduleName = amdModuleName;
  9420. }
  9421. function setExternalModuleIndicator(sourceFile) {
  9422. sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) {
  9423. return node.flags & 1
  9424. || node.kind === 219 && node.moduleReference.kind === 230
  9425. || node.kind === 220
  9426. || node.kind === 225
  9427. || node.kind === 226
  9428. ? node
  9429. : undefined;
  9430. });
  9431. }
  9432. var JSDocParser;
  9433. (function (JSDocParser) {
  9434. function isJSDocType() {
  9435. switch (token) {
  9436. case 37:
  9437. case 52:
  9438. case 17:
  9439. case 19:
  9440. case 48:
  9441. case 15:
  9442. case 85:
  9443. case 22:
  9444. case 90:
  9445. case 95:
  9446. return true;
  9447. }
  9448. return isIdentifierOrKeyword();
  9449. }
  9450. JSDocParser.isJSDocType = isJSDocType;
  9451. function parseJSDocTypeExpressionForTests(content, start, length) {
  9452. initializeState("file.js", content, 2, undefined);
  9453. var jsDocTypeExpression = parseJSDocTypeExpression(start, length);
  9454. var diagnostics = parseDiagnostics;
  9455. clearState();
  9456. return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined;
  9457. }
  9458. JSDocParser.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests;
  9459. function parseJSDocTypeExpression(start, length) {
  9460. scanner.setText(sourceText, start, length);
  9461. token = nextToken();
  9462. var result = createNode(247);
  9463. parseExpected(15);
  9464. result.type = parseJSDocTopLevelType();
  9465. parseExpected(16);
  9466. fixupParentReferences(result);
  9467. return finishNode(result);
  9468. }
  9469. JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression;
  9470. function parseJSDocTopLevelType() {
  9471. var type = parseJSDocType();
  9472. if (token === 46) {
  9473. var unionType = createNode(251, type.pos);
  9474. unionType.types = parseJSDocTypeList(type);
  9475. type = finishNode(unionType);
  9476. }
  9477. if (token === 55) {
  9478. var optionalType = createNode(258, type.pos);
  9479. nextToken();
  9480. optionalType.type = type;
  9481. type = finishNode(optionalType);
  9482. }
  9483. return type;
  9484. }
  9485. function parseJSDocType() {
  9486. var type = parseBasicTypeExpression();
  9487. while (true) {
  9488. if (token === 19) {
  9489. var arrayType = createNode(250, type.pos);
  9490. arrayType.elementType = type;
  9491. nextToken();
  9492. parseExpected(20);
  9493. type = finishNode(arrayType);
  9494. }
  9495. else if (token === 52) {
  9496. var nullableType = createNode(253, type.pos);
  9497. nullableType.type = type;
  9498. nextToken();
  9499. type = finishNode(nullableType);
  9500. }
  9501. else if (token === 48) {
  9502. var nonNullableType = createNode(254, type.pos);
  9503. nonNullableType.type = type;
  9504. nextToken();
  9505. type = finishNode(nonNullableType);
  9506. }
  9507. else {
  9508. break;
  9509. }
  9510. }
  9511. return type;
  9512. }
  9513. function parseBasicTypeExpression() {
  9514. switch (token) {
  9515. case 37:
  9516. return parseJSDocAllType();
  9517. case 52:
  9518. return parseJSDocUnknownOrNullableType();
  9519. case 17:
  9520. return parseJSDocUnionType();
  9521. case 19:
  9522. return parseJSDocTupleType();
  9523. case 48:
  9524. return parseJSDocNonNullableType();
  9525. case 15:
  9526. return parseJSDocRecordType();
  9527. case 85:
  9528. return parseJSDocFunctionType();
  9529. case 22:
  9530. return parseJSDocVariadicType();
  9531. case 90:
  9532. return parseJSDocConstructorType();
  9533. case 95:
  9534. return parseJSDocThisType();
  9535. case 115:
  9536. case 128:
  9537. case 126:
  9538. case 118:
  9539. case 129:
  9540. case 101:
  9541. return parseTokenNode();
  9542. }
  9543. return parseJSDocTypeReference();
  9544. }
  9545. function parseJSDocThisType() {
  9546. var result = createNode(262);
  9547. nextToken();
  9548. parseExpected(53);
  9549. result.type = parseJSDocType();
  9550. return finishNode(result);
  9551. }
  9552. function parseJSDocConstructorType() {
  9553. var result = createNode(261);
  9554. nextToken();
  9555. parseExpected(53);
  9556. result.type = parseJSDocType();
  9557. return finishNode(result);
  9558. }
  9559. function parseJSDocVariadicType() {
  9560. var result = createNode(260);
  9561. nextToken();
  9562. result.type = parseJSDocType();
  9563. return finishNode(result);
  9564. }
  9565. function parseJSDocFunctionType() {
  9566. var result = createNode(259);
  9567. nextToken();
  9568. parseExpected(17);
  9569. result.parameters = parseDelimitedList(22, parseJSDocParameter);
  9570. checkForTrailingComma(result.parameters);
  9571. parseExpected(18);
  9572. if (token === 53) {
  9573. nextToken();
  9574. result.type = parseJSDocType();
  9575. }
  9576. return finishNode(result);
  9577. }
  9578. function parseJSDocParameter() {
  9579. var parameter = createNode(136);
  9580. parameter.type = parseJSDocType();
  9581. return finishNode(parameter);
  9582. }
  9583. function parseJSDocOptionalType(type) {
  9584. var result = createNode(258, type.pos);
  9585. nextToken();
  9586. result.type = type;
  9587. return finishNode(result);
  9588. }
  9589. function parseJSDocTypeReference() {
  9590. var result = createNode(257);
  9591. result.name = parseSimplePropertyName();
  9592. while (parseOptional(21)) {
  9593. if (token === 25) {
  9594. result.typeArguments = parseTypeArguments();
  9595. break;
  9596. }
  9597. else {
  9598. result.name = parseQualifiedName(result.name);
  9599. }
  9600. }
  9601. return finishNode(result);
  9602. }
  9603. function parseTypeArguments() {
  9604. nextToken();
  9605. var typeArguments = parseDelimitedList(23, parseJSDocType);
  9606. checkForTrailingComma(typeArguments);
  9607. checkForEmptyTypeArgumentList(typeArguments);
  9608. parseExpected(27);
  9609. return typeArguments;
  9610. }
  9611. function checkForEmptyTypeArgumentList(typeArguments) {
  9612. if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) {
  9613. var start = typeArguments.pos - "<".length;
  9614. var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length;
  9615. return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
  9616. }
  9617. }
  9618. function parseQualifiedName(left) {
  9619. var result = createNode(133, left.pos);
  9620. result.left = left;
  9621. result.right = parseIdentifierName();
  9622. return finishNode(result);
  9623. }
  9624. function parseJSDocRecordType() {
  9625. var result = createNode(255);
  9626. nextToken();
  9627. result.members = parseDelimitedList(24, parseJSDocRecordMember);
  9628. checkForTrailingComma(result.members);
  9629. parseExpected(16);
  9630. return finishNode(result);
  9631. }
  9632. function parseJSDocRecordMember() {
  9633. var result = createNode(256);
  9634. result.name = parseSimplePropertyName();
  9635. if (token === 53) {
  9636. nextToken();
  9637. result.type = parseJSDocType();
  9638. }
  9639. return finishNode(result);
  9640. }
  9641. function parseJSDocNonNullableType() {
  9642. var result = createNode(254);
  9643. nextToken();
  9644. result.type = parseJSDocType();
  9645. return finishNode(result);
  9646. }
  9647. function parseJSDocTupleType() {
  9648. var result = createNode(252);
  9649. nextToken();
  9650. result.types = parseDelimitedList(25, parseJSDocType);
  9651. checkForTrailingComma(result.types);
  9652. parseExpected(20);
  9653. return finishNode(result);
  9654. }
  9655. function checkForTrailingComma(list) {
  9656. if (parseDiagnostics.length === 0 && list.hasTrailingComma) {
  9657. var start = list.end - ",".length;
  9658. parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed);
  9659. }
  9660. }
  9661. function parseJSDocUnionType() {
  9662. var result = createNode(251);
  9663. nextToken();
  9664. result.types = parseJSDocTypeList(parseJSDocType());
  9665. parseExpected(18);
  9666. return finishNode(result);
  9667. }
  9668. function parseJSDocTypeList(firstType) {
  9669. ts.Debug.assert(!!firstType);
  9670. var types = [];
  9671. types.pos = firstType.pos;
  9672. types.push(firstType);
  9673. while (parseOptional(46)) {
  9674. types.push(parseJSDocType());
  9675. }
  9676. types.end = scanner.getStartPos();
  9677. return types;
  9678. }
  9679. function parseJSDocAllType() {
  9680. var result = createNode(248);
  9681. nextToken();
  9682. return finishNode(result);
  9683. }
  9684. function parseJSDocUnknownOrNullableType() {
  9685. var pos = scanner.getStartPos();
  9686. nextToken();
  9687. if (token === 24 ||
  9688. token === 16 ||
  9689. token === 18 ||
  9690. token === 27 ||
  9691. token === 55 ||
  9692. token === 46) {
  9693. var result = createNode(249, pos);
  9694. return finishNode(result);
  9695. }
  9696. else {
  9697. var result = createNode(253, pos);
  9698. result.type = parseJSDocType();
  9699. return finishNode(result);
  9700. }
  9701. }
  9702. function parseIsolatedJSDocComment(content, start, length) {
  9703. initializeState("file.js", content, 2, undefined);
  9704. var jsDocComment = parseJSDocComment(undefined, start, length);
  9705. var diagnostics = parseDiagnostics;
  9706. clearState();
  9707. return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined;
  9708. }
  9709. JSDocParser.parseIsolatedJSDocComment = parseIsolatedJSDocComment;
  9710. function parseJSDocComment(parent, start, length) {
  9711. var comment = parseJSDocCommentWorker(start, length);
  9712. if (comment) {
  9713. fixupParentReferences(comment);
  9714. comment.parent = parent;
  9715. }
  9716. return comment;
  9717. }
  9718. JSDocParser.parseJSDocComment = parseJSDocComment;
  9719. function parseJSDocCommentWorker(start, length) {
  9720. var content = sourceText;
  9721. start = start || 0;
  9722. var end = length === undefined ? content.length : start + length;
  9723. length = end - start;
  9724. ts.Debug.assert(start >= 0);
  9725. ts.Debug.assert(start <= end);
  9726. ts.Debug.assert(end <= content.length);
  9727. var tags;
  9728. var pos;
  9729. if (length >= "/** */".length) {
  9730. if (content.charCodeAt(start) === 47 &&
  9731. content.charCodeAt(start + 1) === 42 &&
  9732. content.charCodeAt(start + 2) === 42 &&
  9733. content.charCodeAt(start + 3) !== 42) {
  9734. var canParseTag = true;
  9735. var seenAsterisk = true;
  9736. for (pos = start + "/**".length; pos < end;) {
  9737. var ch = content.charCodeAt(pos);
  9738. pos++;
  9739. if (ch === 64 && canParseTag) {
  9740. parseTag();
  9741. canParseTag = false;
  9742. continue;
  9743. }
  9744. if (ts.isLineBreak(ch)) {
  9745. canParseTag = true;
  9746. seenAsterisk = false;
  9747. continue;
  9748. }
  9749. if (ts.isWhiteSpace(ch)) {
  9750. continue;
  9751. }
  9752. if (ch === 42) {
  9753. if (seenAsterisk) {
  9754. canParseTag = false;
  9755. }
  9756. seenAsterisk = true;
  9757. continue;
  9758. }
  9759. canParseTag = false;
  9760. }
  9761. }
  9762. }
  9763. return createJSDocComment();
  9764. function createJSDocComment() {
  9765. if (!tags) {
  9766. return undefined;
  9767. }
  9768. var result = createNode(263, start);
  9769. result.tags = tags;
  9770. return finishNode(result, end);
  9771. }
  9772. function skipWhitespace() {
  9773. while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) {
  9774. pos++;
  9775. }
  9776. }
  9777. function parseTag() {
  9778. ts.Debug.assert(content.charCodeAt(pos - 1) === 64);
  9779. var atToken = createNode(54, pos - 1);
  9780. atToken.end = pos;
  9781. var tagName = scanIdentifier();
  9782. if (!tagName) {
  9783. return;
  9784. }
  9785. var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName);
  9786. addTag(tag);
  9787. }
  9788. function handleTag(atToken, tagName) {
  9789. if (tagName) {
  9790. switch (tagName.text) {
  9791. case "param":
  9792. return handleParamTag(atToken, tagName);
  9793. case "return":
  9794. case "returns":
  9795. return handleReturnTag(atToken, tagName);
  9796. case "template":
  9797. return handleTemplateTag(atToken, tagName);
  9798. case "type":
  9799. return handleTypeTag(atToken, tagName);
  9800. }
  9801. }
  9802. return undefined;
  9803. }
  9804. function handleUnknownTag(atToken, tagName) {
  9805. var result = createNode(264, atToken.pos);
  9806. result.atToken = atToken;
  9807. result.tagName = tagName;
  9808. return finishNode(result, pos);
  9809. }
  9810. function addTag(tag) {
  9811. if (tag) {
  9812. if (!tags) {
  9813. tags = [];
  9814. tags.pos = tag.pos;
  9815. }
  9816. tags.push(tag);
  9817. tags.end = tag.end;
  9818. }
  9819. }
  9820. function tryParseTypeExpression() {
  9821. skipWhitespace();
  9822. if (content.charCodeAt(pos) !== 123) {
  9823. return undefined;
  9824. }
  9825. var typeExpression = parseJSDocTypeExpression(pos, end - pos);
  9826. pos = typeExpression.end;
  9827. return typeExpression;
  9828. }
  9829. function handleParamTag(atToken, tagName) {
  9830. var typeExpression = tryParseTypeExpression();
  9831. skipWhitespace();
  9832. var name;
  9833. var isBracketed;
  9834. if (content.charCodeAt(pos) === 91) {
  9835. pos++;
  9836. skipWhitespace();
  9837. name = scanIdentifier();
  9838. isBracketed = true;
  9839. }
  9840. else {
  9841. name = scanIdentifier();
  9842. }
  9843. if (!name) {
  9844. parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected);
  9845. }
  9846. var preName, postName;
  9847. if (typeExpression) {
  9848. postName = name;
  9849. }
  9850. else {
  9851. preName = name;
  9852. }
  9853. if (!typeExpression) {
  9854. typeExpression = tryParseTypeExpression();
  9855. }
  9856. var result = createNode(265, atToken.pos);
  9857. result.atToken = atToken;
  9858. result.tagName = tagName;
  9859. result.preParameterName = preName;
  9860. result.typeExpression = typeExpression;
  9861. result.postParameterName = postName;
  9862. result.isBracketed = isBracketed;
  9863. return finishNode(result, pos);
  9864. }
  9865. function handleReturnTag(atToken, tagName) {
  9866. if (ts.forEach(tags, function (t) { return t.kind === 266; })) {
  9867. parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
  9868. }
  9869. var result = createNode(266, atToken.pos);
  9870. result.atToken = atToken;
  9871. result.tagName = tagName;
  9872. result.typeExpression = tryParseTypeExpression();
  9873. return finishNode(result, pos);
  9874. }
  9875. function handleTypeTag(atToken, tagName) {
  9876. if (ts.forEach(tags, function (t) { return t.kind === 267; })) {
  9877. parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
  9878. }
  9879. var result = createNode(267, atToken.pos);
  9880. result.atToken = atToken;
  9881. result.tagName = tagName;
  9882. result.typeExpression = tryParseTypeExpression();
  9883. return finishNode(result, pos);
  9884. }
  9885. function handleTemplateTag(atToken, tagName) {
  9886. if (ts.forEach(tags, function (t) { return t.kind === 268; })) {
  9887. parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
  9888. }
  9889. var typeParameters = [];
  9890. typeParameters.pos = pos;
  9891. while (true) {
  9892. skipWhitespace();
  9893. var startPos = pos;
  9894. var name_8 = scanIdentifier();
  9895. if (!name_8) {
  9896. parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected);
  9897. return undefined;
  9898. }
  9899. var typeParameter = createNode(135, name_8.pos);
  9900. typeParameter.name = name_8;
  9901. finishNode(typeParameter, pos);
  9902. typeParameters.push(typeParameter);
  9903. skipWhitespace();
  9904. if (content.charCodeAt(pos) !== 44) {
  9905. break;
  9906. }
  9907. pos++;
  9908. }
  9909. typeParameters.end = pos;
  9910. var result = createNode(268, atToken.pos);
  9911. result.atToken = atToken;
  9912. result.tagName = tagName;
  9913. result.typeParameters = typeParameters;
  9914. return finishNode(result, pos);
  9915. }
  9916. function scanIdentifier() {
  9917. var startPos = pos;
  9918. for (; pos < end; pos++) {
  9919. var ch = content.charCodeAt(pos);
  9920. if (pos === startPos && ts.isIdentifierStart(ch, 2)) {
  9921. continue;
  9922. }
  9923. else if (pos > startPos && ts.isIdentifierPart(ch, 2)) {
  9924. continue;
  9925. }
  9926. break;
  9927. }
  9928. if (startPos === pos) {
  9929. return undefined;
  9930. }
  9931. var result = createNode(67, startPos);
  9932. result.text = content.substring(startPos, pos);
  9933. return finishNode(result, pos);
  9934. }
  9935. }
  9936. JSDocParser.parseJSDocCommentWorker = parseJSDocCommentWorker;
  9937. })(JSDocParser = Parser.JSDocParser || (Parser.JSDocParser = {}));
  9938. })(Parser || (Parser = {}));
  9939. var IncrementalParser;
  9940. (function (IncrementalParser) {
  9941. function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
  9942. aggressiveChecks = aggressiveChecks || ts.Debug.shouldAssert(2);
  9943. checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks);
  9944. if (ts.textChangeRangeIsUnchanged(textChangeRange)) {
  9945. return sourceFile;
  9946. }
  9947. if (sourceFile.statements.length === 0) {
  9948. return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, undefined, true);
  9949. }
  9950. var incrementalSourceFile = sourceFile;
  9951. ts.Debug.assert(!incrementalSourceFile.hasBeenIncrementallyParsed);
  9952. incrementalSourceFile.hasBeenIncrementallyParsed = true;
  9953. var oldText = sourceFile.text;
  9954. var syntaxCursor = createSyntaxCursor(sourceFile);
  9955. var changeRange = extendToAffectedRange(sourceFile, textChangeRange);
  9956. checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks);
  9957. ts.Debug.assert(changeRange.span.start <= textChangeRange.span.start);
  9958. ts.Debug.assert(ts.textSpanEnd(changeRange.span) === ts.textSpanEnd(textChangeRange.span));
  9959. ts.Debug.assert(ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)) === ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)));
  9960. var delta = ts.textChangeRangeNewSpan(changeRange).length - changeRange.span.length;
  9961. updateTokenPositionsAndMarkElements(incrementalSourceFile, changeRange.span.start, ts.textSpanEnd(changeRange.span), ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)), delta, oldText, newText, aggressiveChecks);
  9962. var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, true);
  9963. return result;
  9964. }
  9965. IncrementalParser.updateSourceFile = updateSourceFile;
  9966. function moveElementEntirelyPastChangeRange(element, isArray, delta, oldText, newText, aggressiveChecks) {
  9967. if (isArray) {
  9968. visitArray(element);
  9969. }
  9970. else {
  9971. visitNode(element);
  9972. }
  9973. return;
  9974. function visitNode(node) {
  9975. var text = "";
  9976. if (aggressiveChecks && shouldCheckNode(node)) {
  9977. text = oldText.substring(node.pos, node.end);
  9978. }
  9979. if (node._children) {
  9980. node._children = undefined;
  9981. }
  9982. if (node.jsDocComment) {
  9983. node.jsDocComment = undefined;
  9984. }
  9985. node.pos += delta;
  9986. node.end += delta;
  9987. if (aggressiveChecks && shouldCheckNode(node)) {
  9988. ts.Debug.assert(text === newText.substring(node.pos, node.end));
  9989. }
  9990. forEachChild(node, visitNode, visitArray);
  9991. checkNodePositions(node, aggressiveChecks);
  9992. }
  9993. function visitArray(array) {
  9994. array._children = undefined;
  9995. array.pos += delta;
  9996. array.end += delta;
  9997. for (var _i = 0; _i < array.length; _i++) {
  9998. var node = array[_i];
  9999. visitNode(node);
  10000. }
  10001. }
  10002. }
  10003. function shouldCheckNode(node) {
  10004. switch (node.kind) {
  10005. case 9:
  10006. case 8:
  10007. case 67:
  10008. return true;
  10009. }
  10010. return false;
  10011. }
  10012. function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) {
  10013. ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
  10014. ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
  10015. ts.Debug.assert(element.pos <= element.end);
  10016. element.pos = Math.min(element.pos, changeRangeNewEnd);
  10017. if (element.end >= changeRangeOldEnd) {
  10018. element.end += delta;
  10019. }
  10020. else {
  10021. element.end = Math.min(element.end, changeRangeNewEnd);
  10022. }
  10023. ts.Debug.assert(element.pos <= element.end);
  10024. if (element.parent) {
  10025. ts.Debug.assert(element.pos >= element.parent.pos);
  10026. ts.Debug.assert(element.end <= element.parent.end);
  10027. }
  10028. }
  10029. function checkNodePositions(node, aggressiveChecks) {
  10030. if (aggressiveChecks) {
  10031. var pos = node.pos;
  10032. forEachChild(node, function (child) {
  10033. ts.Debug.assert(child.pos >= pos);
  10034. pos = child.end;
  10035. });
  10036. ts.Debug.assert(pos <= node.end);
  10037. }
  10038. }
  10039. function updateTokenPositionsAndMarkElements(sourceFile, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta, oldText, newText, aggressiveChecks) {
  10040. visitNode(sourceFile);
  10041. return;
  10042. function visitNode(child) {
  10043. ts.Debug.assert(child.pos <= child.end);
  10044. if (child.pos > changeRangeOldEnd) {
  10045. moveElementEntirelyPastChangeRange(child, false, delta, oldText, newText, aggressiveChecks);
  10046. return;
  10047. }
  10048. var fullEnd = child.end;
  10049. if (fullEnd >= changeStart) {
  10050. child.intersectsChange = true;
  10051. child._children = undefined;
  10052. adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
  10053. forEachChild(child, visitNode, visitArray);
  10054. checkNodePositions(child, aggressiveChecks);
  10055. return;
  10056. }
  10057. ts.Debug.assert(fullEnd < changeStart);
  10058. }
  10059. function visitArray(array) {
  10060. ts.Debug.assert(array.pos <= array.end);
  10061. if (array.pos > changeRangeOldEnd) {
  10062. moveElementEntirelyPastChangeRange(array, true, delta, oldText, newText, aggressiveChecks);
  10063. return;
  10064. }
  10065. var fullEnd = array.end;
  10066. if (fullEnd >= changeStart) {
  10067. array.intersectsChange = true;
  10068. array._children = undefined;
  10069. adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
  10070. for (var _i = 0; _i < array.length; _i++) {
  10071. var node = array[_i];
  10072. visitNode(node);
  10073. }
  10074. return;
  10075. }
  10076. ts.Debug.assert(fullEnd < changeStart);
  10077. }
  10078. }
  10079. function extendToAffectedRange(sourceFile, changeRange) {
  10080. var maxLookahead = 1;
  10081. var start = changeRange.span.start;
  10082. for (var i = 0; start > 0 && i <= maxLookahead; i++) {
  10083. var nearestNode = findNearestNodeStartingBeforeOrAtPosition(sourceFile, start);
  10084. ts.Debug.assert(nearestNode.pos <= start);
  10085. var position = nearestNode.pos;
  10086. start = Math.max(0, position - 1);
  10087. }
  10088. var finalSpan = ts.createTextSpanFromBounds(start, ts.textSpanEnd(changeRange.span));
  10089. var finalLength = changeRange.newLength + (changeRange.span.start - start);
  10090. return ts.createTextChangeRange(finalSpan, finalLength);
  10091. }
  10092. function findNearestNodeStartingBeforeOrAtPosition(sourceFile, position) {
  10093. var bestResult = sourceFile;
  10094. var lastNodeEntirelyBeforePosition;
  10095. forEachChild(sourceFile, visit);
  10096. if (lastNodeEntirelyBeforePosition) {
  10097. var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition);
  10098. if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) {
  10099. bestResult = lastChildOfLastEntireNodeBeforePosition;
  10100. }
  10101. }
  10102. return bestResult;
  10103. function getLastChild(node) {
  10104. while (true) {
  10105. var lastChild = getLastChildWorker(node);
  10106. if (lastChild) {
  10107. node = lastChild;
  10108. }
  10109. else {
  10110. return node;
  10111. }
  10112. }
  10113. }
  10114. function getLastChildWorker(node) {
  10115. var last = undefined;
  10116. forEachChild(node, function (child) {
  10117. if (ts.nodeIsPresent(child)) {
  10118. last = child;
  10119. }
  10120. });
  10121. return last;
  10122. }
  10123. function visit(child) {
  10124. if (ts.nodeIsMissing(child)) {
  10125. return;
  10126. }
  10127. if (child.pos <= position) {
  10128. if (child.pos >= bestResult.pos) {
  10129. bestResult = child;
  10130. }
  10131. if (position < child.end) {
  10132. forEachChild(child, visit);
  10133. return true;
  10134. }
  10135. else {
  10136. ts.Debug.assert(child.end <= position);
  10137. lastNodeEntirelyBeforePosition = child;
  10138. }
  10139. }
  10140. else {
  10141. ts.Debug.assert(child.pos > position);
  10142. return true;
  10143. }
  10144. }
  10145. }
  10146. function checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks) {
  10147. var oldText = sourceFile.text;
  10148. if (textChangeRange) {
  10149. ts.Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length);
  10150. if (aggressiveChecks || ts.Debug.shouldAssert(3)) {
  10151. var oldTextPrefix = oldText.substr(0, textChangeRange.span.start);
  10152. var newTextPrefix = newText.substr(0, textChangeRange.span.start);
  10153. ts.Debug.assert(oldTextPrefix === newTextPrefix);
  10154. var oldTextSuffix = oldText.substring(ts.textSpanEnd(textChangeRange.span), oldText.length);
  10155. var newTextSuffix = newText.substring(ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)), newText.length);
  10156. ts.Debug.assert(oldTextSuffix === newTextSuffix);
  10157. }
  10158. }
  10159. }
  10160. function createSyntaxCursor(sourceFile) {
  10161. var currentArray = sourceFile.statements;
  10162. var currentArrayIndex = 0;
  10163. ts.Debug.assert(currentArrayIndex < currentArray.length);
  10164. var current = currentArray[currentArrayIndex];
  10165. var lastQueriedPosition = -1;
  10166. return {
  10167. currentNode: function (position) {
  10168. if (position !== lastQueriedPosition) {
  10169. if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) {
  10170. currentArrayIndex++;
  10171. current = currentArray[currentArrayIndex];
  10172. }
  10173. if (!current || current.pos !== position) {
  10174. findHighestListElementThatStartsAtPosition(position);
  10175. }
  10176. }
  10177. lastQueriedPosition = position;
  10178. ts.Debug.assert(!current || current.pos === position);
  10179. return current;
  10180. }
  10181. };
  10182. function findHighestListElementThatStartsAtPosition(position) {
  10183. currentArray = undefined;
  10184. currentArrayIndex = -1;
  10185. current = undefined;
  10186. forEachChild(sourceFile, visitNode, visitArray);
  10187. return;
  10188. function visitNode(node) {
  10189. if (position >= node.pos && position < node.end) {
  10190. forEachChild(node, visitNode, visitArray);
  10191. return true;
  10192. }
  10193. return false;
  10194. }
  10195. function visitArray(array) {
  10196. if (position >= array.pos && position < array.end) {
  10197. for (var i = 0, n = array.length; i < n; i++) {
  10198. var child = array[i];
  10199. if (child) {
  10200. if (child.pos === position) {
  10201. currentArray = array;
  10202. currentArrayIndex = i;
  10203. current = child;
  10204. return true;
  10205. }
  10206. else {
  10207. if (child.pos < position && position < child.end) {
  10208. forEachChild(child, visitNode, visitArray);
  10209. return true;
  10210. }
  10211. }
  10212. }
  10213. }
  10214. }
  10215. return false;
  10216. }
  10217. }
  10218. }
  10219. })(IncrementalParser || (IncrementalParser = {}));
  10220. })(ts || (ts = {}));
  10221. /// <reference path="binder.ts"/>
  10222. var ts;
  10223. (function (ts) {
  10224. var nextSymbolId = 1;
  10225. var nextNodeId = 1;
  10226. var nextMergeId = 1;
  10227. function getNodeId(node) {
  10228. if (!node.id)
  10229. node.id = nextNodeId++;
  10230. return node.id;
  10231. }
  10232. ts.getNodeId = getNodeId;
  10233. ts.checkTime = 0;
  10234. function getSymbolId(symbol) {
  10235. if (!symbol.id) {
  10236. symbol.id = nextSymbolId++;
  10237. }
  10238. return symbol.id;
  10239. }
  10240. ts.getSymbolId = getSymbolId;
  10241. function createTypeChecker(host, produceDiagnostics) {
  10242. var cancellationToken;
  10243. var Symbol = ts.objectAllocator.getSymbolConstructor();
  10244. var Type = ts.objectAllocator.getTypeConstructor();
  10245. var Signature = ts.objectAllocator.getSignatureConstructor();
  10246. var typeCount = 0;
  10247. var emptyArray = [];
  10248. var emptySymbols = {};
  10249. var compilerOptions = host.getCompilerOptions();
  10250. var languageVersion = compilerOptions.target || 0;
  10251. var emitResolver = createResolver();
  10252. var undefinedSymbol = createSymbol(4 | 67108864, "undefined");
  10253. var argumentsSymbol = createSymbol(4 | 67108864, "arguments");
  10254. var checker = {
  10255. getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); },
  10256. getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); },
  10257. getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); },
  10258. getTypeCount: function () { return typeCount; },
  10259. isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; },
  10260. isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; },
  10261. getDiagnostics: getDiagnostics,
  10262. getGlobalDiagnostics: getGlobalDiagnostics,
  10263. getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol,
  10264. getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
  10265. getPropertiesOfType: getPropertiesOfType,
  10266. getPropertyOfType: getPropertyOfType,
  10267. getSignaturesOfType: getSignaturesOfType,
  10268. getIndexTypeOfType: getIndexTypeOfType,
  10269. getBaseTypes: getBaseTypes,
  10270. getReturnTypeOfSignature: getReturnTypeOfSignature,
  10271. getSymbolsInScope: getSymbolsInScope,
  10272. getSymbolAtLocation: getSymbolAtLocation,
  10273. getShorthandAssignmentValueSymbol: getShorthandAssignmentValueSymbol,
  10274. getTypeAtLocation: getTypeOfNode,
  10275. typeToString: typeToString,
  10276. getSymbolDisplayBuilder: getSymbolDisplayBuilder,
  10277. symbolToString: symbolToString,
  10278. getAugmentedPropertiesOfType: getAugmentedPropertiesOfType,
  10279. getRootSymbols: getRootSymbols,
  10280. getContextualType: getContextualType,
  10281. getFullyQualifiedName: getFullyQualifiedName,
  10282. getResolvedSignature: getResolvedSignature,
  10283. getConstantValue: getConstantValue,
  10284. isValidPropertyAccess: isValidPropertyAccess,
  10285. getSignatureFromDeclaration: getSignatureFromDeclaration,
  10286. isImplementationOfOverload: isImplementationOfOverload,
  10287. getAliasedSymbol: resolveAlias,
  10288. getEmitResolver: getEmitResolver,
  10289. getExportsOfModule: getExportsOfModuleAsArray,
  10290. getJsxElementAttributesType: getJsxElementAttributesType,
  10291. getJsxIntrinsicTagNames: getJsxIntrinsicTagNames,
  10292. isOptionalParameter: isOptionalParameter
  10293. };
  10294. var unknownSymbol = createSymbol(4 | 67108864, "unknown");
  10295. var resolvingSymbol = createSymbol(67108864, "__resolving__");
  10296. var anyType = createIntrinsicType(1, "any");
  10297. var stringType = createIntrinsicType(2, "string");
  10298. var numberType = createIntrinsicType(4, "number");
  10299. var booleanType = createIntrinsicType(8, "boolean");
  10300. var esSymbolType = createIntrinsicType(16777216, "symbol");
  10301. var voidType = createIntrinsicType(16, "void");
  10302. var undefinedType = createIntrinsicType(32 | 2097152, "undefined");
  10303. var nullType = createIntrinsicType(64 | 2097152, "null");
  10304. var unknownType = createIntrinsicType(1, "unknown");
  10305. var circularType = createIntrinsicType(1, "__circular__");
  10306. var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10307. var emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10308. emptyGenericType.instantiations = {};
  10309. var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10310. anyFunctionType.flags |= 8388608;
  10311. var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  10312. var anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false);
  10313. var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, false, false);
  10314. var globals = {};
  10315. var globalESSymbolConstructorSymbol;
  10316. var getGlobalPromiseConstructorSymbol;
  10317. var globalObjectType;
  10318. var globalFunctionType;
  10319. var globalArrayType;
  10320. var globalStringType;
  10321. var globalNumberType;
  10322. var globalBooleanType;
  10323. var globalRegExpType;
  10324. var globalTemplateStringsArrayType;
  10325. var globalESSymbolType;
  10326. var jsxElementType;
  10327. var jsxIntrinsicElementsType;
  10328. var globalIterableType;
  10329. var globalIteratorType;
  10330. var globalIterableIteratorType;
  10331. var anyArrayType;
  10332. var getGlobalClassDecoratorType;
  10333. var getGlobalParameterDecoratorType;
  10334. var getGlobalPropertyDecoratorType;
  10335. var getGlobalMethodDecoratorType;
  10336. var getGlobalTypedPropertyDescriptorType;
  10337. var getGlobalPromiseType;
  10338. var tryGetGlobalPromiseType;
  10339. var getGlobalPromiseLikeType;
  10340. var getInstantiatedGlobalPromiseLikeType;
  10341. var getGlobalPromiseConstructorLikeType;
  10342. var getGlobalThenableType;
  10343. var tupleTypes = {};
  10344. var unionTypes = {};
  10345. var intersectionTypes = {};
  10346. var stringLiteralTypes = {};
  10347. var emitExtends = false;
  10348. var emitDecorate = false;
  10349. var emitParam = false;
  10350. var emitAwaiter = false;
  10351. var emitGenerator = false;
  10352. var resolutionTargets = [];
  10353. var resolutionResults = [];
  10354. var resolutionPropertyNames = [];
  10355. var mergedSymbols = [];
  10356. var symbolLinks = [];
  10357. var nodeLinks = [];
  10358. var potentialThisCollisions = [];
  10359. var awaitedTypeStack = [];
  10360. var diagnostics = ts.createDiagnosticCollection();
  10361. var primitiveTypeInfo = {
  10362. "string": {
  10363. type: stringType,
  10364. flags: 258
  10365. },
  10366. "number": {
  10367. type: numberType,
  10368. flags: 132
  10369. },
  10370. "boolean": {
  10371. type: booleanType,
  10372. flags: 8
  10373. },
  10374. "symbol": {
  10375. type: esSymbolType,
  10376. flags: 16777216
  10377. }
  10378. };
  10379. var JsxNames = {
  10380. JSX: "JSX",
  10381. IntrinsicElements: "IntrinsicElements",
  10382. ElementClass: "ElementClass",
  10383. ElementAttributesPropertyNameContainer: "ElementAttributesProperty",
  10384. Element: "Element"
  10385. };
  10386. var subtypeRelation = {};
  10387. var assignableRelation = {};
  10388. var identityRelation = {};
  10389. var _displayBuilder;
  10390. initializeTypeChecker();
  10391. return checker;
  10392. function getEmitResolver(sourceFile, cancellationToken) {
  10393. getDiagnostics(sourceFile, cancellationToken);
  10394. return emitResolver;
  10395. }
  10396. function error(location, message, arg0, arg1, arg2) {
  10397. var diagnostic = location
  10398. ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2)
  10399. : ts.createCompilerDiagnostic(message, arg0, arg1, arg2);
  10400. diagnostics.add(diagnostic);
  10401. }
  10402. function createSymbol(flags, name) {
  10403. return new Symbol(flags, name);
  10404. }
  10405. function getExcludedSymbolFlags(flags) {
  10406. var result = 0;
  10407. if (flags & 2)
  10408. result |= 107455;
  10409. if (flags & 1)
  10410. result |= 107454;
  10411. if (flags & 4)
  10412. result |= 107455;
  10413. if (flags & 8)
  10414. result |= 107455;
  10415. if (flags & 16)
  10416. result |= 106927;
  10417. if (flags & 32)
  10418. result |= 899519;
  10419. if (flags & 64)
  10420. result |= 792960;
  10421. if (flags & 256)
  10422. result |= 899327;
  10423. if (flags & 128)
  10424. result |= 899967;
  10425. if (flags & 512)
  10426. result |= 106639;
  10427. if (flags & 8192)
  10428. result |= 99263;
  10429. if (flags & 32768)
  10430. result |= 41919;
  10431. if (flags & 65536)
  10432. result |= 74687;
  10433. if (flags & 262144)
  10434. result |= 530912;
  10435. if (flags & 524288)
  10436. result |= 793056;
  10437. if (flags & 8388608)
  10438. result |= 8388608;
  10439. return result;
  10440. }
  10441. function recordMergedSymbol(target, source) {
  10442. if (!source.mergeId)
  10443. source.mergeId = nextMergeId++;
  10444. mergedSymbols[source.mergeId] = target;
  10445. }
  10446. function cloneSymbol(symbol) {
  10447. var result = createSymbol(symbol.flags | 33554432, symbol.name);
  10448. result.declarations = symbol.declarations.slice(0);
  10449. result.parent = symbol.parent;
  10450. if (symbol.valueDeclaration)
  10451. result.valueDeclaration = symbol.valueDeclaration;
  10452. if (symbol.constEnumOnlyModule)
  10453. result.constEnumOnlyModule = true;
  10454. if (symbol.members)
  10455. result.members = cloneSymbolTable(symbol.members);
  10456. if (symbol.exports)
  10457. result.exports = cloneSymbolTable(symbol.exports);
  10458. recordMergedSymbol(result, symbol);
  10459. return result;
  10460. }
  10461. function mergeSymbol(target, source) {
  10462. if (!(target.flags & getExcludedSymbolFlags(source.flags))) {
  10463. if (source.flags & 512 && target.flags & 512 && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
  10464. target.constEnumOnlyModule = false;
  10465. }
  10466. target.flags |= source.flags;
  10467. if (!target.valueDeclaration && source.valueDeclaration)
  10468. target.valueDeclaration = source.valueDeclaration;
  10469. ts.forEach(source.declarations, function (node) {
  10470. target.declarations.push(node);
  10471. });
  10472. if (source.members) {
  10473. if (!target.members)
  10474. target.members = {};
  10475. mergeSymbolTable(target.members, source.members);
  10476. }
  10477. if (source.exports) {
  10478. if (!target.exports)
  10479. target.exports = {};
  10480. mergeSymbolTable(target.exports, source.exports);
  10481. }
  10482. recordMergedSymbol(target, source);
  10483. }
  10484. else {
  10485. var message = target.flags & 2 || source.flags & 2
  10486. ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0;
  10487. ts.forEach(source.declarations, function (node) {
  10488. error(node.name ? node.name : node, message, symbolToString(source));
  10489. });
  10490. ts.forEach(target.declarations, function (node) {
  10491. error(node.name ? node.name : node, message, symbolToString(source));
  10492. });
  10493. }
  10494. }
  10495. function cloneSymbolTable(symbolTable) {
  10496. var result = {};
  10497. for (var id in symbolTable) {
  10498. if (ts.hasProperty(symbolTable, id)) {
  10499. result[id] = symbolTable[id];
  10500. }
  10501. }
  10502. return result;
  10503. }
  10504. function mergeSymbolTable(target, source) {
  10505. for (var id in source) {
  10506. if (ts.hasProperty(source, id)) {
  10507. if (!ts.hasProperty(target, id)) {
  10508. target[id] = source[id];
  10509. }
  10510. else {
  10511. var symbol = target[id];
  10512. if (!(symbol.flags & 33554432)) {
  10513. target[id] = symbol = cloneSymbol(symbol);
  10514. }
  10515. mergeSymbol(symbol, source[id]);
  10516. }
  10517. }
  10518. }
  10519. }
  10520. function getSymbolLinks(symbol) {
  10521. if (symbol.flags & 67108864)
  10522. return symbol;
  10523. var id = getSymbolId(symbol);
  10524. return symbolLinks[id] || (symbolLinks[id] = {});
  10525. }
  10526. function getNodeLinks(node) {
  10527. var nodeId = getNodeId(node);
  10528. return nodeLinks[nodeId] || (nodeLinks[nodeId] = {});
  10529. }
  10530. function getSourceFile(node) {
  10531. return ts.getAncestor(node, 246);
  10532. }
  10533. function isGlobalSourceFile(node) {
  10534. return node.kind === 246 && !ts.isExternalModule(node);
  10535. }
  10536. function getSymbol(symbols, name, meaning) {
  10537. if (meaning && ts.hasProperty(symbols, name)) {
  10538. var symbol = symbols[name];
  10539. ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here.");
  10540. if (symbol.flags & meaning) {
  10541. return symbol;
  10542. }
  10543. if (symbol.flags & 8388608) {
  10544. var target = resolveAlias(symbol);
  10545. if (target === unknownSymbol || target.flags & meaning) {
  10546. return symbol;
  10547. }
  10548. }
  10549. }
  10550. }
  10551. function isDefinedBefore(node1, node2) {
  10552. var file1 = ts.getSourceFileOfNode(node1);
  10553. var file2 = ts.getSourceFileOfNode(node2);
  10554. if (file1 === file2) {
  10555. return node1.pos <= node2.pos;
  10556. }
  10557. if (!compilerOptions.outFile && !compilerOptions.out) {
  10558. return true;
  10559. }
  10560. var sourceFiles = host.getSourceFiles();
  10561. return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2);
  10562. }
  10563. function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) {
  10564. var result;
  10565. var lastLocation;
  10566. var propertyWithInvalidInitializer;
  10567. var errorLocation = location;
  10568. var grandparent;
  10569. loop: while (location) {
  10570. if (location.locals && !isGlobalSourceFile(location)) {
  10571. if (result = getSymbol(location.locals, name, meaning)) {
  10572. if (!(meaning & 793056) ||
  10573. !(result.flags & (793056 & ~262144)) ||
  10574. !ts.isFunctionLike(location) ||
  10575. lastLocation === location.body) {
  10576. break loop;
  10577. }
  10578. result = undefined;
  10579. }
  10580. }
  10581. switch (location.kind) {
  10582. case 246:
  10583. if (!ts.isExternalModule(location))
  10584. break;
  10585. case 216:
  10586. var moduleExports = getSymbolOfNode(location).exports;
  10587. if (location.kind === 246 ||
  10588. (location.kind === 216 && location.name.kind === 9)) {
  10589. if (ts.hasProperty(moduleExports, name) &&
  10590. moduleExports[name].flags === 8388608 &&
  10591. ts.getDeclarationOfKind(moduleExports[name], 228)) {
  10592. break;
  10593. }
  10594. result = moduleExports["default"];
  10595. var localSymbol = ts.getLocalSymbolForExportDefault(result);
  10596. if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
  10597. break loop;
  10598. }
  10599. result = undefined;
  10600. }
  10601. if (result = getSymbol(moduleExports, name, meaning & 8914931)) {
  10602. break loop;
  10603. }
  10604. break;
  10605. case 215:
  10606. if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) {
  10607. break loop;
  10608. }
  10609. break;
  10610. case 139:
  10611. case 138:
  10612. if (ts.isClassLike(location.parent) && !(location.flags & 128)) {
  10613. var ctor = findConstructorDeclaration(location.parent);
  10614. if (ctor && ctor.locals) {
  10615. if (getSymbol(ctor.locals, name, meaning & 107455)) {
  10616. propertyWithInvalidInitializer = location;
  10617. }
  10618. }
  10619. }
  10620. break;
  10621. case 212:
  10622. case 184:
  10623. case 213:
  10624. if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) {
  10625. if (lastLocation && lastLocation.flags & 128) {
  10626. error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters);
  10627. return undefined;
  10628. }
  10629. break loop;
  10630. }
  10631. if (location.kind === 184 && meaning & 32) {
  10632. var className = location.name;
  10633. if (className && name === className.text) {
  10634. result = location.symbol;
  10635. break loop;
  10636. }
  10637. }
  10638. break;
  10639. case 134:
  10640. grandparent = location.parent.parent;
  10641. if (ts.isClassLike(grandparent) || grandparent.kind === 213) {
  10642. if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) {
  10643. error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
  10644. return undefined;
  10645. }
  10646. }
  10647. break;
  10648. case 141:
  10649. case 140:
  10650. case 142:
  10651. case 143:
  10652. case 144:
  10653. case 211:
  10654. case 172:
  10655. if (meaning & 3 && name === "arguments") {
  10656. result = argumentsSymbol;
  10657. break loop;
  10658. }
  10659. break;
  10660. case 171:
  10661. if (meaning & 3 && name === "arguments") {
  10662. result = argumentsSymbol;
  10663. break loop;
  10664. }
  10665. if (meaning & 16) {
  10666. var functionName = location.name;
  10667. if (functionName && name === functionName.text) {
  10668. result = location.symbol;
  10669. break loop;
  10670. }
  10671. }
  10672. break;
  10673. case 137:
  10674. if (location.parent && location.parent.kind === 136) {
  10675. location = location.parent;
  10676. }
  10677. if (location.parent && ts.isClassElement(location.parent)) {
  10678. location = location.parent;
  10679. }
  10680. break;
  10681. }
  10682. lastLocation = location;
  10683. location = location.parent;
  10684. }
  10685. if (!result) {
  10686. result = getSymbol(globals, name, meaning);
  10687. }
  10688. if (!result) {
  10689. if (nameNotFoundMessage) {
  10690. error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg));
  10691. }
  10692. return undefined;
  10693. }
  10694. if (nameNotFoundMessage) {
  10695. if (propertyWithInvalidInitializer) {
  10696. var propertyName = propertyWithInvalidInitializer.name;
  10697. 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));
  10698. return undefined;
  10699. }
  10700. if (meaning & 2 && result.flags & 2) {
  10701. checkResolvedBlockScopedVariable(result, errorLocation);
  10702. }
  10703. }
  10704. return result;
  10705. }
  10706. function checkResolvedBlockScopedVariable(result, errorLocation) {
  10707. ts.Debug.assert((result.flags & 2) !== 0);
  10708. var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; });
  10709. ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
  10710. var isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation);
  10711. if (!isUsedBeforeDeclaration) {
  10712. var variableDeclaration = ts.getAncestor(declaration, 209);
  10713. var container = ts.getEnclosingBlockScopeContainer(variableDeclaration);
  10714. if (variableDeclaration.parent.parent.kind === 191 ||
  10715. variableDeclaration.parent.parent.kind === 197) {
  10716. isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container);
  10717. }
  10718. else if (variableDeclaration.parent.parent.kind === 199 ||
  10719. variableDeclaration.parent.parent.kind === 198) {
  10720. var expression = variableDeclaration.parent.parent.expression;
  10721. isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container);
  10722. }
  10723. }
  10724. if (isUsedBeforeDeclaration) {
  10725. error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name));
  10726. }
  10727. }
  10728. function isSameScopeDescendentOf(initial, parent, stopAt) {
  10729. if (!parent) {
  10730. return false;
  10731. }
  10732. for (var current = initial; current && current !== stopAt && !ts.isFunctionLike(current); current = current.parent) {
  10733. if (current === parent) {
  10734. return true;
  10735. }
  10736. }
  10737. return false;
  10738. }
  10739. function getAnyImportSyntax(node) {
  10740. if (ts.isAliasSymbolDeclaration(node)) {
  10741. if (node.kind === 219) {
  10742. return node;
  10743. }
  10744. while (node && node.kind !== 220) {
  10745. node = node.parent;
  10746. }
  10747. return node;
  10748. }
  10749. }
  10750. function getDeclarationOfAliasSymbol(symbol) {
  10751. return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; });
  10752. }
  10753. function getTargetOfImportEqualsDeclaration(node) {
  10754. if (node.moduleReference.kind === 230) {
  10755. return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node)));
  10756. }
  10757. return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node);
  10758. }
  10759. function getTargetOfImportClause(node) {
  10760. var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier);
  10761. if (moduleSymbol) {
  10762. var exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]);
  10763. if (!exportDefaultSymbol) {
  10764. error(node.name, ts.Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
  10765. }
  10766. return exportDefaultSymbol;
  10767. }
  10768. }
  10769. function getTargetOfNamespaceImport(node) {
  10770. var moduleSpecifier = node.parent.parent.moduleSpecifier;
  10771. return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
  10772. }
  10773. function getMemberOfModuleVariable(moduleSymbol, name) {
  10774. if (moduleSymbol.flags & 3) {
  10775. var typeAnnotation = moduleSymbol.valueDeclaration.type;
  10776. if (typeAnnotation) {
  10777. return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
  10778. }
  10779. }
  10780. }
  10781. function combineValueAndTypeSymbols(valueSymbol, typeSymbol) {
  10782. if (valueSymbol.flags & (793056 | 1536)) {
  10783. return valueSymbol;
  10784. }
  10785. var result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
  10786. result.declarations = ts.concatenate(valueSymbol.declarations, typeSymbol.declarations);
  10787. result.parent = valueSymbol.parent || typeSymbol.parent;
  10788. if (valueSymbol.valueDeclaration)
  10789. result.valueDeclaration = valueSymbol.valueDeclaration;
  10790. if (typeSymbol.members)
  10791. result.members = typeSymbol.members;
  10792. if (valueSymbol.exports)
  10793. result.exports = valueSymbol.exports;
  10794. return result;
  10795. }
  10796. function getExportOfModule(symbol, name) {
  10797. if (symbol.flags & 1536) {
  10798. var exports = getExportsOfSymbol(symbol);
  10799. if (ts.hasProperty(exports, name)) {
  10800. return resolveSymbol(exports[name]);
  10801. }
  10802. }
  10803. }
  10804. function getPropertyOfVariable(symbol, name) {
  10805. if (symbol.flags & 3) {
  10806. var typeAnnotation = symbol.valueDeclaration.type;
  10807. if (typeAnnotation) {
  10808. return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name));
  10809. }
  10810. }
  10811. }
  10812. function getExternalModuleMember(node, specifier) {
  10813. var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
  10814. var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
  10815. if (targetSymbol) {
  10816. var name_9 = specifier.propertyName || specifier.name;
  10817. if (name_9.text) {
  10818. var symbolFromModule = getExportOfModule(targetSymbol, name_9.text);
  10819. var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_9.text);
  10820. var symbol = symbolFromModule && symbolFromVariable ?
  10821. combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
  10822. symbolFromModule || symbolFromVariable;
  10823. if (!symbol) {
  10824. error(name_9, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_9));
  10825. }
  10826. return symbol;
  10827. }
  10828. }
  10829. }
  10830. function getTargetOfImportSpecifier(node) {
  10831. return getExternalModuleMember(node.parent.parent.parent, node);
  10832. }
  10833. function getTargetOfExportSpecifier(node) {
  10834. return node.parent.parent.moduleSpecifier ?
  10835. getExternalModuleMember(node.parent.parent, node) :
  10836. resolveEntityName(node.propertyName || node.name, 107455 | 793056 | 1536);
  10837. }
  10838. function getTargetOfExportAssignment(node) {
  10839. return resolveEntityName(node.expression, 107455 | 793056 | 1536);
  10840. }
  10841. function getTargetOfAliasDeclaration(node) {
  10842. switch (node.kind) {
  10843. case 219:
  10844. return getTargetOfImportEqualsDeclaration(node);
  10845. case 221:
  10846. return getTargetOfImportClause(node);
  10847. case 222:
  10848. return getTargetOfNamespaceImport(node);
  10849. case 224:
  10850. return getTargetOfImportSpecifier(node);
  10851. case 228:
  10852. return getTargetOfExportSpecifier(node);
  10853. case 225:
  10854. return getTargetOfExportAssignment(node);
  10855. }
  10856. }
  10857. function resolveSymbol(symbol) {
  10858. return symbol && symbol.flags & 8388608 && !(symbol.flags & (107455 | 793056 | 1536)) ? resolveAlias(symbol) : symbol;
  10859. }
  10860. function resolveAlias(symbol) {
  10861. ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Alias here.");
  10862. var links = getSymbolLinks(symbol);
  10863. if (!links.target) {
  10864. links.target = resolvingSymbol;
  10865. var node = getDeclarationOfAliasSymbol(symbol);
  10866. var target = getTargetOfAliasDeclaration(node);
  10867. if (links.target === resolvingSymbol) {
  10868. links.target = target || unknownSymbol;
  10869. }
  10870. else {
  10871. error(node, ts.Diagnostics.Circular_definition_of_import_alias_0, symbolToString(symbol));
  10872. }
  10873. }
  10874. else if (links.target === resolvingSymbol) {
  10875. links.target = unknownSymbol;
  10876. }
  10877. return links.target;
  10878. }
  10879. function markExportAsReferenced(node) {
  10880. var symbol = getSymbolOfNode(node);
  10881. var target = resolveAlias(symbol);
  10882. if (target) {
  10883. var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) ||
  10884. (target !== unknownSymbol && (target.flags & 107455) && !isConstEnumOrConstEnumOnlyModule(target));
  10885. if (markAlias) {
  10886. markAliasSymbolAsReferenced(symbol);
  10887. }
  10888. }
  10889. }
  10890. function markAliasSymbolAsReferenced(symbol) {
  10891. var links = getSymbolLinks(symbol);
  10892. if (!links.referenced) {
  10893. links.referenced = true;
  10894. var node = getDeclarationOfAliasSymbol(symbol);
  10895. if (node.kind === 225) {
  10896. checkExpressionCached(node.expression);
  10897. }
  10898. else if (node.kind === 228) {
  10899. checkExpressionCached(node.propertyName || node.name);
  10900. }
  10901. else if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  10902. checkExpressionCached(node.moduleReference);
  10903. }
  10904. }
  10905. }
  10906. function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) {
  10907. if (!importDeclaration) {
  10908. importDeclaration = ts.getAncestor(entityName, 219);
  10909. ts.Debug.assert(importDeclaration !== undefined);
  10910. }
  10911. if (entityName.kind === 67 && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
  10912. entityName = entityName.parent;
  10913. }
  10914. if (entityName.kind === 67 || entityName.parent.kind === 133) {
  10915. return resolveEntityName(entityName, 1536);
  10916. }
  10917. else {
  10918. ts.Debug.assert(entityName.parent.kind === 219);
  10919. return resolveEntityName(entityName, 107455 | 793056 | 1536);
  10920. }
  10921. }
  10922. function getFullyQualifiedName(symbol) {
  10923. return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
  10924. }
  10925. function resolveEntityName(name, meaning, ignoreErrors) {
  10926. if (ts.nodeIsMissing(name)) {
  10927. return undefined;
  10928. }
  10929. var symbol;
  10930. if (name.kind === 67) {
  10931. var message = meaning === 1536 ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0;
  10932. symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name);
  10933. if (!symbol) {
  10934. return undefined;
  10935. }
  10936. }
  10937. else if (name.kind === 133 || name.kind === 164) {
  10938. var left = name.kind === 133 ? name.left : name.expression;
  10939. var right = name.kind === 133 ? name.right : name.name;
  10940. var namespace = resolveEntityName(left, 1536, ignoreErrors);
  10941. if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) {
  10942. return undefined;
  10943. }
  10944. symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
  10945. if (!symbol) {
  10946. if (!ignoreErrors) {
  10947. error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right));
  10948. }
  10949. return undefined;
  10950. }
  10951. }
  10952. else {
  10953. ts.Debug.fail("Unknown entity name kind.");
  10954. }
  10955. ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here.");
  10956. return symbol.flags & meaning ? symbol : resolveAlias(symbol);
  10957. }
  10958. function isExternalModuleNameRelative(moduleName) {
  10959. return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
  10960. }
  10961. function resolveExternalModuleName(location, moduleReferenceExpression) {
  10962. if (moduleReferenceExpression.kind !== 9) {
  10963. return;
  10964. }
  10965. var moduleReferenceLiteral = moduleReferenceExpression;
  10966. var searchPath = ts.getDirectoryPath(getSourceFile(location).fileName);
  10967. var moduleName = ts.escapeIdentifier(moduleReferenceLiteral.text);
  10968. if (!moduleName) {
  10969. return;
  10970. }
  10971. var isRelative = isExternalModuleNameRelative(moduleName);
  10972. if (!isRelative) {
  10973. var symbol = getSymbol(globals, "\"" + moduleName + "\"", 512);
  10974. if (symbol) {
  10975. return symbol;
  10976. }
  10977. }
  10978. var resolvedModule = ts.getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text);
  10979. var sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName);
  10980. if (sourceFile) {
  10981. if (sourceFile.symbol) {
  10982. return sourceFile.symbol;
  10983. }
  10984. error(moduleReferenceLiteral, ts.Diagnostics.File_0_is_not_a_module, sourceFile.fileName);
  10985. return;
  10986. }
  10987. error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_module_0, moduleName);
  10988. }
  10989. function resolveExternalModuleSymbol(moduleSymbol) {
  10990. return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol;
  10991. }
  10992. function resolveESModuleSymbol(moduleSymbol, moduleReferenceExpression) {
  10993. var symbol = resolveExternalModuleSymbol(moduleSymbol);
  10994. if (symbol && !(symbol.flags & (1536 | 3))) {
  10995. error(moduleReferenceExpression, ts.Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
  10996. symbol = undefined;
  10997. }
  10998. return symbol;
  10999. }
  11000. function getExportAssignmentSymbol(moduleSymbol) {
  11001. return moduleSymbol.exports["export="];
  11002. }
  11003. function getExportsOfModuleAsArray(moduleSymbol) {
  11004. return symbolsToArray(getExportsOfModule(moduleSymbol));
  11005. }
  11006. function getExportsOfSymbol(symbol) {
  11007. return symbol.flags & 1536 ? getExportsOfModule(symbol) : symbol.exports || emptySymbols;
  11008. }
  11009. function getExportsOfModule(moduleSymbol) {
  11010. var links = getSymbolLinks(moduleSymbol);
  11011. return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
  11012. }
  11013. function extendExportSymbols(target, source) {
  11014. for (var id in source) {
  11015. if (id !== "default" && !ts.hasProperty(target, id)) {
  11016. target[id] = source[id];
  11017. }
  11018. }
  11019. }
  11020. function getExportsForModule(moduleSymbol) {
  11021. var result;
  11022. var visitedSymbols = [];
  11023. visit(moduleSymbol);
  11024. return result || moduleSymbol.exports;
  11025. function visit(symbol) {
  11026. if (symbol && symbol.flags & 1952 && !ts.contains(visitedSymbols, symbol)) {
  11027. visitedSymbols.push(symbol);
  11028. if (symbol !== moduleSymbol) {
  11029. if (!result) {
  11030. result = cloneSymbolTable(moduleSymbol.exports);
  11031. }
  11032. extendExportSymbols(result, symbol.exports);
  11033. }
  11034. var exportStars = symbol.exports["__export"];
  11035. if (exportStars) {
  11036. for (var _i = 0, _a = exportStars.declarations; _i < _a.length; _i++) {
  11037. var node = _a[_i];
  11038. visit(resolveExternalModuleName(node, node.moduleSpecifier));
  11039. }
  11040. }
  11041. }
  11042. }
  11043. }
  11044. function getMergedSymbol(symbol) {
  11045. var merged;
  11046. return symbol && symbol.mergeId && (merged = mergedSymbols[symbol.mergeId]) ? merged : symbol;
  11047. }
  11048. function getSymbolOfNode(node) {
  11049. return getMergedSymbol(node.symbol);
  11050. }
  11051. function getParentOfSymbol(symbol) {
  11052. return getMergedSymbol(symbol.parent);
  11053. }
  11054. function getExportSymbolOfValueSymbolIfExported(symbol) {
  11055. return symbol && (symbol.flags & 1048576) !== 0
  11056. ? getMergedSymbol(symbol.exportSymbol)
  11057. : symbol;
  11058. }
  11059. function symbolIsValue(symbol) {
  11060. if (symbol.flags & 16777216) {
  11061. return symbolIsValue(getSymbolLinks(symbol).target);
  11062. }
  11063. if (symbol.flags & 107455) {
  11064. return true;
  11065. }
  11066. if (symbol.flags & 8388608) {
  11067. return (resolveAlias(symbol).flags & 107455) !== 0;
  11068. }
  11069. return false;
  11070. }
  11071. function findConstructorDeclaration(node) {
  11072. var members = node.members;
  11073. for (var _i = 0; _i < members.length; _i++) {
  11074. var member = members[_i];
  11075. if (member.kind === 142 && ts.nodeIsPresent(member.body)) {
  11076. return member;
  11077. }
  11078. }
  11079. }
  11080. function createType(flags) {
  11081. var result = new Type(checker, flags);
  11082. result.id = typeCount++;
  11083. return result;
  11084. }
  11085. function createIntrinsicType(kind, intrinsicName) {
  11086. var type = createType(kind);
  11087. type.intrinsicName = intrinsicName;
  11088. return type;
  11089. }
  11090. function createObjectType(kind, symbol) {
  11091. var type = createType(kind);
  11092. type.symbol = symbol;
  11093. return type;
  11094. }
  11095. function isReservedMemberName(name) {
  11096. return name.charCodeAt(0) === 95 &&
  11097. name.charCodeAt(1) === 95 &&
  11098. name.charCodeAt(2) !== 95 &&
  11099. name.charCodeAt(2) !== 64;
  11100. }
  11101. function getNamedMembers(members) {
  11102. var result;
  11103. for (var id in members) {
  11104. if (ts.hasProperty(members, id)) {
  11105. if (!isReservedMemberName(id)) {
  11106. if (!result)
  11107. result = [];
  11108. var symbol = members[id];
  11109. if (symbolIsValue(symbol)) {
  11110. result.push(symbol);
  11111. }
  11112. }
  11113. }
  11114. }
  11115. return result || emptyArray;
  11116. }
  11117. function setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
  11118. type.members = members;
  11119. type.properties = getNamedMembers(members);
  11120. type.callSignatures = callSignatures;
  11121. type.constructSignatures = constructSignatures;
  11122. if (stringIndexType)
  11123. type.stringIndexType = stringIndexType;
  11124. if (numberIndexType)
  11125. type.numberIndexType = numberIndexType;
  11126. return type;
  11127. }
  11128. function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
  11129. return setObjectTypeMembers(createObjectType(65536, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  11130. }
  11131. function forEachSymbolTableInScope(enclosingDeclaration, callback) {
  11132. var result;
  11133. for (var location_1 = enclosingDeclaration; location_1; location_1 = location_1.parent) {
  11134. if (location_1.locals && !isGlobalSourceFile(location_1)) {
  11135. if (result = callback(location_1.locals)) {
  11136. return result;
  11137. }
  11138. }
  11139. switch (location_1.kind) {
  11140. case 246:
  11141. if (!ts.isExternalModule(location_1)) {
  11142. break;
  11143. }
  11144. case 216:
  11145. if (result = callback(getSymbolOfNode(location_1).exports)) {
  11146. return result;
  11147. }
  11148. break;
  11149. case 212:
  11150. case 213:
  11151. if (result = callback(getSymbolOfNode(location_1).members)) {
  11152. return result;
  11153. }
  11154. break;
  11155. }
  11156. }
  11157. return callback(globals);
  11158. }
  11159. function getQualifiedLeftMeaning(rightMeaning) {
  11160. return rightMeaning === 107455 ? 107455 : 1536;
  11161. }
  11162. function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) {
  11163. function getAccessibleSymbolChainFromSymbolTable(symbols) {
  11164. function canQualifySymbol(symbolFromSymbolTable, meaning) {
  11165. if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) {
  11166. return true;
  11167. }
  11168. var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
  11169. return !!accessibleParent;
  11170. }
  11171. function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) {
  11172. if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) {
  11173. return !ts.forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) &&
  11174. canQualifySymbol(symbolFromSymbolTable, meaning);
  11175. }
  11176. }
  11177. if (isAccessible(ts.lookUp(symbols, symbol.name))) {
  11178. return [symbol];
  11179. }
  11180. return ts.forEachValue(symbols, function (symbolFromSymbolTable) {
  11181. if (symbolFromSymbolTable.flags & 8388608
  11182. && symbolFromSymbolTable.name !== "export="
  11183. && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228)) {
  11184. if (!useOnlyExternalAliasing ||
  11185. ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) {
  11186. var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable);
  11187. if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) {
  11188. return [symbolFromSymbolTable];
  11189. }
  11190. var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
  11191. if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
  11192. return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
  11193. }
  11194. }
  11195. }
  11196. });
  11197. }
  11198. if (symbol) {
  11199. return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
  11200. }
  11201. }
  11202. function needsQualification(symbol, enclosingDeclaration, meaning) {
  11203. var qualify = false;
  11204. forEachSymbolTableInScope(enclosingDeclaration, function (symbolTable) {
  11205. if (!ts.hasProperty(symbolTable, symbol.name)) {
  11206. return false;
  11207. }
  11208. var symbolFromSymbolTable = symbolTable[symbol.name];
  11209. if (symbolFromSymbolTable === symbol) {
  11210. return true;
  11211. }
  11212. symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
  11213. if (symbolFromSymbolTable.flags & meaning) {
  11214. qualify = true;
  11215. return true;
  11216. }
  11217. return false;
  11218. });
  11219. return qualify;
  11220. }
  11221. function isSymbolAccessible(symbol, enclosingDeclaration, meaning) {
  11222. if (symbol && enclosingDeclaration && !(symbol.flags & 262144)) {
  11223. var initialSymbol = symbol;
  11224. var meaningToLook = meaning;
  11225. while (symbol) {
  11226. var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false);
  11227. if (accessibleSymbolChain) {
  11228. var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
  11229. if (!hasAccessibleDeclarations) {
  11230. return {
  11231. accessibility: 1,
  11232. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
  11233. errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1536) : undefined
  11234. };
  11235. }
  11236. return hasAccessibleDeclarations;
  11237. }
  11238. meaningToLook = getQualifiedLeftMeaning(meaning);
  11239. symbol = getParentOfSymbol(symbol);
  11240. }
  11241. var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer);
  11242. if (symbolExternalModule) {
  11243. var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration);
  11244. if (symbolExternalModule !== enclosingExternalModule) {
  11245. return {
  11246. accessibility: 2,
  11247. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
  11248. errorModuleName: symbolToString(symbolExternalModule)
  11249. };
  11250. }
  11251. }
  11252. return {
  11253. accessibility: 1,
  11254. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning)
  11255. };
  11256. }
  11257. return { accessibility: 0 };
  11258. function getExternalModuleContainer(declaration) {
  11259. for (; declaration; declaration = declaration.parent) {
  11260. if (hasExternalModuleSymbol(declaration)) {
  11261. return getSymbolOfNode(declaration);
  11262. }
  11263. }
  11264. }
  11265. }
  11266. function hasExternalModuleSymbol(declaration) {
  11267. return (declaration.kind === 216 && declaration.name.kind === 9) ||
  11268. (declaration.kind === 246 && ts.isExternalModule(declaration));
  11269. }
  11270. function hasVisibleDeclarations(symbol) {
  11271. var aliasesToMakeVisible;
  11272. if (ts.forEach(symbol.declarations, function (declaration) { return !getIsDeclarationVisible(declaration); })) {
  11273. return undefined;
  11274. }
  11275. return { accessibility: 0, aliasesToMakeVisible: aliasesToMakeVisible };
  11276. function getIsDeclarationVisible(declaration) {
  11277. if (!isDeclarationVisible(declaration)) {
  11278. var anyImportSyntax = getAnyImportSyntax(declaration);
  11279. if (anyImportSyntax &&
  11280. !(anyImportSyntax.flags & 1) &&
  11281. isDeclarationVisible(anyImportSyntax.parent)) {
  11282. getNodeLinks(declaration).isVisible = true;
  11283. if (aliasesToMakeVisible) {
  11284. if (!ts.contains(aliasesToMakeVisible, anyImportSyntax)) {
  11285. aliasesToMakeVisible.push(anyImportSyntax);
  11286. }
  11287. }
  11288. else {
  11289. aliasesToMakeVisible = [anyImportSyntax];
  11290. }
  11291. return true;
  11292. }
  11293. return false;
  11294. }
  11295. return true;
  11296. }
  11297. }
  11298. function isEntityNameVisible(entityName, enclosingDeclaration) {
  11299. var meaning;
  11300. if (entityName.parent.kind === 152) {
  11301. meaning = 107455 | 1048576;
  11302. }
  11303. else if (entityName.kind === 133 || entityName.kind === 164 ||
  11304. entityName.parent.kind === 219) {
  11305. meaning = 1536;
  11306. }
  11307. else {
  11308. meaning = 793056;
  11309. }
  11310. var firstIdentifier = getFirstIdentifier(entityName);
  11311. var symbol = resolveName(enclosingDeclaration, firstIdentifier.text, meaning, undefined, undefined);
  11312. return (symbol && hasVisibleDeclarations(symbol)) || {
  11313. accessibility: 1,
  11314. errorSymbolName: ts.getTextOfNode(firstIdentifier),
  11315. errorNode: firstIdentifier
  11316. };
  11317. }
  11318. function writeKeyword(writer, kind) {
  11319. writer.writeKeyword(ts.tokenToString(kind));
  11320. }
  11321. function writePunctuation(writer, kind) {
  11322. writer.writePunctuation(ts.tokenToString(kind));
  11323. }
  11324. function writeSpace(writer) {
  11325. writer.writeSpace(" ");
  11326. }
  11327. function symbolToString(symbol, enclosingDeclaration, meaning) {
  11328. var writer = ts.getSingleLineStringWriter();
  11329. getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning);
  11330. var result = writer.string();
  11331. ts.releaseStringWriter(writer);
  11332. return result;
  11333. }
  11334. function signatureToString(signature, enclosingDeclaration, flags) {
  11335. var writer = ts.getSingleLineStringWriter();
  11336. getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
  11337. var result = writer.string();
  11338. ts.releaseStringWriter(writer);
  11339. return result;
  11340. }
  11341. function typeToString(type, enclosingDeclaration, flags) {
  11342. var writer = ts.getSingleLineStringWriter();
  11343. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  11344. var result = writer.string();
  11345. ts.releaseStringWriter(writer);
  11346. var maxLength = compilerOptions.noErrorTruncation || flags & 4 ? undefined : 100;
  11347. if (maxLength && result.length >= maxLength) {
  11348. result = result.substr(0, maxLength - "...".length) + "...";
  11349. }
  11350. return result;
  11351. }
  11352. function getTypeAliasForTypeLiteral(type) {
  11353. if (type.symbol && type.symbol.flags & 2048) {
  11354. var node = type.symbol.declarations[0].parent;
  11355. while (node.kind === 158) {
  11356. node = node.parent;
  11357. }
  11358. if (node.kind === 214) {
  11359. return getSymbolOfNode(node);
  11360. }
  11361. }
  11362. return undefined;
  11363. }
  11364. function getSymbolDisplayBuilder() {
  11365. function getNameOfSymbol(symbol) {
  11366. if (symbol.declarations && symbol.declarations.length) {
  11367. var declaration = symbol.declarations[0];
  11368. if (declaration.name) {
  11369. return ts.declarationNameToString(declaration.name);
  11370. }
  11371. switch (declaration.kind) {
  11372. case 184:
  11373. return "(Anonymous class)";
  11374. case 171:
  11375. case 172:
  11376. return "(Anonymous function)";
  11377. }
  11378. }
  11379. return symbol.name;
  11380. }
  11381. function appendSymbolNameOnly(symbol, writer) {
  11382. writer.writeSymbol(getNameOfSymbol(symbol), symbol);
  11383. }
  11384. function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags, typeFlags) {
  11385. var parentSymbol;
  11386. function appendParentTypeArgumentsAndSymbolName(symbol) {
  11387. if (parentSymbol) {
  11388. if (flags & 1) {
  11389. if (symbol.flags & 16777216) {
  11390. buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration);
  11391. }
  11392. else {
  11393. buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration);
  11394. }
  11395. }
  11396. writePunctuation(writer, 21);
  11397. }
  11398. parentSymbol = symbol;
  11399. appendSymbolNameOnly(symbol, writer);
  11400. }
  11401. writer.trackSymbol(symbol, enclosingDeclaration, meaning);
  11402. function walkSymbol(symbol, meaning) {
  11403. if (symbol) {
  11404. var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2));
  11405. if (!accessibleSymbolChain ||
  11406. needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
  11407. walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning));
  11408. }
  11409. if (accessibleSymbolChain) {
  11410. for (var _i = 0; _i < accessibleSymbolChain.length; _i++) {
  11411. var accessibleSymbol = accessibleSymbolChain[_i];
  11412. appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
  11413. }
  11414. }
  11415. else {
  11416. if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) {
  11417. return;
  11418. }
  11419. if (symbol.flags & 2048 || symbol.flags & 4096) {
  11420. return;
  11421. }
  11422. appendParentTypeArgumentsAndSymbolName(symbol);
  11423. }
  11424. }
  11425. }
  11426. var isTypeParameter = symbol.flags & 262144;
  11427. var typeFormatFlag = 128 & typeFlags;
  11428. if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
  11429. walkSymbol(symbol, meaning);
  11430. return;
  11431. }
  11432. return appendParentTypeArgumentsAndSymbolName(symbol);
  11433. }
  11434. function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) {
  11435. var globalFlagsToPass = globalFlags & 16;
  11436. return writeType(type, globalFlags);
  11437. function writeType(type, flags) {
  11438. if (type.flags & 16777343) {
  11439. writer.writeKeyword(!(globalFlags & 16) && isTypeAny(type)
  11440. ? "any"
  11441. : type.intrinsicName);
  11442. }
  11443. else if (type.flags & 4096) {
  11444. writeTypeReference(type, flags);
  11445. }
  11446. else if (type.flags & (1024 | 2048 | 128 | 512)) {
  11447. buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 793056, 0, flags);
  11448. }
  11449. else if (type.flags & 8192) {
  11450. writeTupleType(type);
  11451. }
  11452. else if (type.flags & 49152) {
  11453. writeUnionOrIntersectionType(type, flags);
  11454. }
  11455. else if (type.flags & 65536) {
  11456. writeAnonymousType(type, flags);
  11457. }
  11458. else if (type.flags & 256) {
  11459. writer.writeStringLiteral(type.text);
  11460. }
  11461. else {
  11462. writePunctuation(writer, 15);
  11463. writeSpace(writer);
  11464. writePunctuation(writer, 22);
  11465. writeSpace(writer);
  11466. writePunctuation(writer, 16);
  11467. }
  11468. }
  11469. function writeTypeList(types, delimiter) {
  11470. for (var i = 0; i < types.length; i++) {
  11471. if (i > 0) {
  11472. if (delimiter !== 24) {
  11473. writeSpace(writer);
  11474. }
  11475. writePunctuation(writer, delimiter);
  11476. writeSpace(writer);
  11477. }
  11478. writeType(types[i], delimiter === 24 ? 0 : 64);
  11479. }
  11480. }
  11481. function writeSymbolTypeReference(symbol, typeArguments, pos, end) {
  11482. if (!isReservedMemberName(symbol.name)) {
  11483. buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056);
  11484. }
  11485. if (pos < end) {
  11486. writePunctuation(writer, 25);
  11487. writeType(typeArguments[pos++], 0);
  11488. while (pos < end) {
  11489. writePunctuation(writer, 24);
  11490. writeSpace(writer);
  11491. writeType(typeArguments[pos++], 0);
  11492. }
  11493. writePunctuation(writer, 27);
  11494. }
  11495. }
  11496. function writeTypeReference(type, flags) {
  11497. var typeArguments = type.typeArguments;
  11498. if (type.target === globalArrayType && !(flags & 1)) {
  11499. writeType(typeArguments[0], 64);
  11500. writePunctuation(writer, 19);
  11501. writePunctuation(writer, 20);
  11502. }
  11503. else {
  11504. var outerTypeParameters = type.target.outerTypeParameters;
  11505. var i = 0;
  11506. if (outerTypeParameters) {
  11507. var length_1 = outerTypeParameters.length;
  11508. while (i < length_1) {
  11509. var start = i;
  11510. var parent_3 = getParentSymbolOfTypeParameter(outerTypeParameters[i]);
  11511. do {
  11512. i++;
  11513. } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3);
  11514. if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) {
  11515. writeSymbolTypeReference(parent_3, typeArguments, start, i);
  11516. writePunctuation(writer, 21);
  11517. }
  11518. }
  11519. }
  11520. writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length);
  11521. }
  11522. }
  11523. function writeTupleType(type) {
  11524. writePunctuation(writer, 19);
  11525. writeTypeList(type.elementTypes, 24);
  11526. writePunctuation(writer, 20);
  11527. }
  11528. function writeUnionOrIntersectionType(type, flags) {
  11529. if (flags & 64) {
  11530. writePunctuation(writer, 17);
  11531. }
  11532. writeTypeList(type.types, type.flags & 16384 ? 46 : 45);
  11533. if (flags & 64) {
  11534. writePunctuation(writer, 18);
  11535. }
  11536. }
  11537. function writeAnonymousType(type, flags) {
  11538. var symbol = type.symbol;
  11539. if (symbol) {
  11540. if (symbol.flags & (32 | 384 | 512)) {
  11541. writeTypeofSymbol(type, flags);
  11542. }
  11543. else if (shouldWriteTypeOfFunctionSymbol()) {
  11544. writeTypeofSymbol(type, flags);
  11545. }
  11546. else if (ts.contains(symbolStack, symbol)) {
  11547. var typeAlias = getTypeAliasForTypeLiteral(type);
  11548. if (typeAlias) {
  11549. buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags);
  11550. }
  11551. else {
  11552. writeKeyword(writer, 115);
  11553. }
  11554. }
  11555. else {
  11556. if (!symbolStack) {
  11557. symbolStack = [];
  11558. }
  11559. symbolStack.push(symbol);
  11560. writeLiteralType(type, flags);
  11561. symbolStack.pop();
  11562. }
  11563. }
  11564. else {
  11565. writeLiteralType(type, flags);
  11566. }
  11567. function shouldWriteTypeOfFunctionSymbol() {
  11568. var isStaticMethodSymbol = !!(symbol.flags & 8192 &&
  11569. ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128; }));
  11570. var isNonLocalFunctionSymbol = !!(symbol.flags & 16) &&
  11571. (symbol.parent ||
  11572. ts.forEach(symbol.declarations, function (declaration) {
  11573. return declaration.parent.kind === 246 || declaration.parent.kind === 217;
  11574. }));
  11575. if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
  11576. return !!(flags & 2) ||
  11577. (ts.contains(symbolStack, symbol));
  11578. }
  11579. }
  11580. }
  11581. function writeTypeofSymbol(type, typeFormatFlags) {
  11582. writeKeyword(writer, 99);
  11583. writeSpace(writer);
  11584. buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455, 0, typeFormatFlags);
  11585. }
  11586. function getIndexerParameterName(type, indexKind, fallbackName) {
  11587. var declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind);
  11588. if (!declaration) {
  11589. return fallbackName;
  11590. }
  11591. ts.Debug.assert(declaration.parameters.length !== 0);
  11592. return ts.declarationNameToString(declaration.parameters[0].name);
  11593. }
  11594. function writeLiteralType(type, flags) {
  11595. var resolved = resolveStructuredTypeMembers(type);
  11596. if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) {
  11597. if (!resolved.callSignatures.length && !resolved.constructSignatures.length) {
  11598. writePunctuation(writer, 15);
  11599. writePunctuation(writer, 16);
  11600. return;
  11601. }
  11602. if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
  11603. if (flags & 64) {
  11604. writePunctuation(writer, 17);
  11605. }
  11606. buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack);
  11607. if (flags & 64) {
  11608. writePunctuation(writer, 18);
  11609. }
  11610. return;
  11611. }
  11612. if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
  11613. if (flags & 64) {
  11614. writePunctuation(writer, 17);
  11615. }
  11616. writeKeyword(writer, 90);
  11617. writeSpace(writer);
  11618. buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack);
  11619. if (flags & 64) {
  11620. writePunctuation(writer, 18);
  11621. }
  11622. return;
  11623. }
  11624. }
  11625. writePunctuation(writer, 15);
  11626. writer.writeLine();
  11627. writer.increaseIndent();
  11628. for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) {
  11629. var signature = _a[_i];
  11630. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
  11631. writePunctuation(writer, 23);
  11632. writer.writeLine();
  11633. }
  11634. for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) {
  11635. var signature = _c[_b];
  11636. writeKeyword(writer, 90);
  11637. writeSpace(writer);
  11638. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
  11639. writePunctuation(writer, 23);
  11640. writer.writeLine();
  11641. }
  11642. if (resolved.stringIndexType) {
  11643. writePunctuation(writer, 19);
  11644. writer.writeParameter(getIndexerParameterName(resolved, 0, "x"));
  11645. writePunctuation(writer, 53);
  11646. writeSpace(writer);
  11647. writeKeyword(writer, 128);
  11648. writePunctuation(writer, 20);
  11649. writePunctuation(writer, 53);
  11650. writeSpace(writer);
  11651. writeType(resolved.stringIndexType, 0);
  11652. writePunctuation(writer, 23);
  11653. writer.writeLine();
  11654. }
  11655. if (resolved.numberIndexType) {
  11656. writePunctuation(writer, 19);
  11657. writer.writeParameter(getIndexerParameterName(resolved, 1, "x"));
  11658. writePunctuation(writer, 53);
  11659. writeSpace(writer);
  11660. writeKeyword(writer, 126);
  11661. writePunctuation(writer, 20);
  11662. writePunctuation(writer, 53);
  11663. writeSpace(writer);
  11664. writeType(resolved.numberIndexType, 0);
  11665. writePunctuation(writer, 23);
  11666. writer.writeLine();
  11667. }
  11668. for (var _d = 0, _e = resolved.properties; _d < _e.length; _d++) {
  11669. var p = _e[_d];
  11670. var t = getTypeOfSymbol(p);
  11671. if (p.flags & (16 | 8192) && !getPropertiesOfObjectType(t).length) {
  11672. var signatures = getSignaturesOfType(t, 0);
  11673. for (var _f = 0; _f < signatures.length; _f++) {
  11674. var signature = signatures[_f];
  11675. buildSymbolDisplay(p, writer);
  11676. if (p.flags & 536870912) {
  11677. writePunctuation(writer, 52);
  11678. }
  11679. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
  11680. writePunctuation(writer, 23);
  11681. writer.writeLine();
  11682. }
  11683. }
  11684. else {
  11685. buildSymbolDisplay(p, writer);
  11686. if (p.flags & 536870912) {
  11687. writePunctuation(writer, 52);
  11688. }
  11689. writePunctuation(writer, 53);
  11690. writeSpace(writer);
  11691. writeType(t, 0);
  11692. writePunctuation(writer, 23);
  11693. writer.writeLine();
  11694. }
  11695. }
  11696. writer.decreaseIndent();
  11697. writePunctuation(writer, 16);
  11698. }
  11699. }
  11700. function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) {
  11701. var targetSymbol = getTargetSymbol(symbol);
  11702. if (targetSymbol.flags & 32 || targetSymbol.flags & 64 || targetSymbol.flags & 524288) {
  11703. buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaraiton, flags);
  11704. }
  11705. }
  11706. function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) {
  11707. appendSymbolNameOnly(tp.symbol, writer);
  11708. var constraint = getConstraintOfTypeParameter(tp);
  11709. if (constraint) {
  11710. writeSpace(writer);
  11711. writeKeyword(writer, 81);
  11712. writeSpace(writer);
  11713. buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack);
  11714. }
  11715. }
  11716. function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) {
  11717. var parameterNode = p.valueDeclaration;
  11718. if (ts.isRestParameter(parameterNode)) {
  11719. writePunctuation(writer, 22);
  11720. }
  11721. appendSymbolNameOnly(p, writer);
  11722. if (isOptionalParameter(parameterNode)) {
  11723. writePunctuation(writer, 52);
  11724. }
  11725. writePunctuation(writer, 53);
  11726. writeSpace(writer);
  11727. buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack);
  11728. }
  11729. function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) {
  11730. if (typeParameters && typeParameters.length) {
  11731. writePunctuation(writer, 25);
  11732. for (var i = 0; i < typeParameters.length; i++) {
  11733. if (i > 0) {
  11734. writePunctuation(writer, 24);
  11735. writeSpace(writer);
  11736. }
  11737. buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack);
  11738. }
  11739. writePunctuation(writer, 27);
  11740. }
  11741. }
  11742. function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) {
  11743. if (typeParameters && typeParameters.length) {
  11744. writePunctuation(writer, 25);
  11745. for (var i = 0; i < typeParameters.length; i++) {
  11746. if (i > 0) {
  11747. writePunctuation(writer, 24);
  11748. writeSpace(writer);
  11749. }
  11750. buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0);
  11751. }
  11752. writePunctuation(writer, 27);
  11753. }
  11754. }
  11755. function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) {
  11756. writePunctuation(writer, 17);
  11757. for (var i = 0; i < parameters.length; i++) {
  11758. if (i > 0) {
  11759. writePunctuation(writer, 24);
  11760. writeSpace(writer);
  11761. }
  11762. buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack);
  11763. }
  11764. writePunctuation(writer, 18);
  11765. }
  11766. function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) {
  11767. if (flags & 8) {
  11768. writeSpace(writer);
  11769. writePunctuation(writer, 34);
  11770. }
  11771. else {
  11772. writePunctuation(writer, 53);
  11773. }
  11774. writeSpace(writer);
  11775. var returnType;
  11776. if (signature.typePredicate) {
  11777. writer.writeParameter(signature.typePredicate.parameterName);
  11778. writeSpace(writer);
  11779. writeKeyword(writer, 122);
  11780. writeSpace(writer);
  11781. returnType = signature.typePredicate.type;
  11782. }
  11783. else {
  11784. returnType = getReturnTypeOfSignature(signature);
  11785. }
  11786. buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack);
  11787. }
  11788. function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) {
  11789. if (signature.target && (flags & 32)) {
  11790. buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration);
  11791. }
  11792. else {
  11793. buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack);
  11794. }
  11795. buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack);
  11796. buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
  11797. }
  11798. return _displayBuilder || (_displayBuilder = {
  11799. buildSymbolDisplay: buildSymbolDisplay,
  11800. buildTypeDisplay: buildTypeDisplay,
  11801. buildTypeParameterDisplay: buildTypeParameterDisplay,
  11802. buildParameterDisplay: buildParameterDisplay,
  11803. buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters,
  11804. buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters,
  11805. buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol,
  11806. buildSignatureDisplay: buildSignatureDisplay,
  11807. buildReturnTypeDisplay: buildReturnTypeDisplay
  11808. });
  11809. }
  11810. function isDeclarationVisible(node) {
  11811. function getContainingExternalModule(node) {
  11812. for (; node; node = node.parent) {
  11813. if (node.kind === 216) {
  11814. if (node.name.kind === 9) {
  11815. return node;
  11816. }
  11817. }
  11818. else if (node.kind === 246) {
  11819. return ts.isExternalModule(node) ? node : undefined;
  11820. }
  11821. }
  11822. ts.Debug.fail("getContainingModule cant reach here");
  11823. }
  11824. function isUsedInExportAssignment(node) {
  11825. var externalModule = getContainingExternalModule(node);
  11826. var exportAssignmentSymbol;
  11827. var resolvedExportSymbol;
  11828. if (externalModule) {
  11829. var externalModuleSymbol = getSymbolOfNode(externalModule);
  11830. exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
  11831. var symbolOfNode = getSymbolOfNode(node);
  11832. if (isSymbolUsedInExportAssignment(symbolOfNode)) {
  11833. return true;
  11834. }
  11835. if (symbolOfNode.flags & 8388608) {
  11836. return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode));
  11837. }
  11838. }
  11839. function isSymbolUsedInExportAssignment(symbol) {
  11840. if (exportAssignmentSymbol === symbol) {
  11841. return true;
  11842. }
  11843. if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608)) {
  11844. resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
  11845. if (resolvedExportSymbol === symbol) {
  11846. return true;
  11847. }
  11848. return ts.forEach(resolvedExportSymbol.declarations, function (current) {
  11849. while (current) {
  11850. if (current === node) {
  11851. return true;
  11852. }
  11853. current = current.parent;
  11854. }
  11855. });
  11856. }
  11857. }
  11858. }
  11859. function determineIfDeclarationIsVisible() {
  11860. switch (node.kind) {
  11861. case 161:
  11862. return isDeclarationVisible(node.parent.parent);
  11863. case 209:
  11864. if (ts.isBindingPattern(node.name) &&
  11865. !node.name.elements.length) {
  11866. return false;
  11867. }
  11868. case 216:
  11869. case 212:
  11870. case 213:
  11871. case 214:
  11872. case 211:
  11873. case 215:
  11874. case 219:
  11875. var parent_4 = getDeclarationContainer(node);
  11876. if (!(ts.getCombinedNodeFlags(node) & 1) &&
  11877. !(node.kind !== 219 && parent_4.kind !== 246 && ts.isInAmbientContext(parent_4))) {
  11878. return isGlobalSourceFile(parent_4);
  11879. }
  11880. return isDeclarationVisible(parent_4);
  11881. case 139:
  11882. case 138:
  11883. case 143:
  11884. case 144:
  11885. case 141:
  11886. case 140:
  11887. if (node.flags & (32 | 64)) {
  11888. return false;
  11889. }
  11890. case 142:
  11891. case 146:
  11892. case 145:
  11893. case 147:
  11894. case 136:
  11895. case 217:
  11896. case 150:
  11897. case 151:
  11898. case 153:
  11899. case 149:
  11900. case 154:
  11901. case 155:
  11902. case 156:
  11903. case 157:
  11904. case 158:
  11905. return isDeclarationVisible(node.parent);
  11906. case 221:
  11907. case 222:
  11908. case 224:
  11909. return false;
  11910. case 135:
  11911. case 246:
  11912. return true;
  11913. case 225:
  11914. return false;
  11915. default:
  11916. ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
  11917. }
  11918. }
  11919. if (node) {
  11920. var links = getNodeLinks(node);
  11921. if (links.isVisible === undefined) {
  11922. links.isVisible = !!determineIfDeclarationIsVisible();
  11923. }
  11924. return links.isVisible;
  11925. }
  11926. }
  11927. function collectLinkedAliases(node) {
  11928. var exportSymbol;
  11929. if (node.parent && node.parent.kind === 225) {
  11930. exportSymbol = resolveName(node.parent, node.text, 107455 | 793056 | 1536 | 8388608, ts.Diagnostics.Cannot_find_name_0, node);
  11931. }
  11932. else if (node.parent.kind === 228) {
  11933. var exportSpecifier = node.parent;
  11934. exportSymbol = exportSpecifier.parent.parent.moduleSpecifier ?
  11935. getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) :
  11936. resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, 107455 | 793056 | 1536 | 8388608);
  11937. }
  11938. var result = [];
  11939. if (exportSymbol) {
  11940. buildVisibleNodeList(exportSymbol.declarations);
  11941. }
  11942. return result;
  11943. function buildVisibleNodeList(declarations) {
  11944. ts.forEach(declarations, function (declaration) {
  11945. getNodeLinks(declaration).isVisible = true;
  11946. var resultNode = getAnyImportSyntax(declaration) || declaration;
  11947. if (!ts.contains(result, resultNode)) {
  11948. result.push(resultNode);
  11949. }
  11950. if (ts.isInternalModuleImportEqualsDeclaration(declaration)) {
  11951. var internalModuleReference = declaration.moduleReference;
  11952. var firstIdentifier = getFirstIdentifier(internalModuleReference);
  11953. var importSymbol = resolveName(declaration, firstIdentifier.text, 107455 | 793056 | 1536, ts.Diagnostics.Cannot_find_name_0, firstIdentifier);
  11954. buildVisibleNodeList(importSymbol.declarations);
  11955. }
  11956. });
  11957. }
  11958. }
  11959. function pushTypeResolution(target, propertyName) {
  11960. var resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName);
  11961. if (resolutionCycleStartIndex >= 0) {
  11962. var length_2 = resolutionTargets.length;
  11963. for (var i = resolutionCycleStartIndex; i < length_2; i++) {
  11964. resolutionResults[i] = false;
  11965. }
  11966. return false;
  11967. }
  11968. resolutionTargets.push(target);
  11969. resolutionResults.push(true);
  11970. resolutionPropertyNames.push(propertyName);
  11971. return true;
  11972. }
  11973. function findResolutionCycleStartIndex(target, propertyName) {
  11974. for (var i = resolutionTargets.length - 1; i >= 0; i--) {
  11975. if (hasType(resolutionTargets[i], resolutionPropertyNames[i])) {
  11976. return -1;
  11977. }
  11978. if (resolutionTargets[i] === target && resolutionPropertyNames[i] === propertyName) {
  11979. return i;
  11980. }
  11981. }
  11982. return -1;
  11983. }
  11984. function hasType(target, propertyName) {
  11985. if (propertyName === 0) {
  11986. return getSymbolLinks(target).type;
  11987. }
  11988. if (propertyName === 2) {
  11989. return getSymbolLinks(target).declaredType;
  11990. }
  11991. if (propertyName === 1) {
  11992. ts.Debug.assert(!!(target.flags & 1024));
  11993. return target.resolvedBaseConstructorType;
  11994. }
  11995. if (propertyName === 3) {
  11996. return target.resolvedReturnType;
  11997. }
  11998. ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
  11999. }
  12000. function popTypeResolution() {
  12001. resolutionTargets.pop();
  12002. resolutionPropertyNames.pop();
  12003. return resolutionResults.pop();
  12004. }
  12005. function getDeclarationContainer(node) {
  12006. node = ts.getRootDeclaration(node);
  12007. return node.kind === 209 ? node.parent.parent.parent : node.parent;
  12008. }
  12009. function getTypeOfPrototypeProperty(prototype) {
  12010. var classType = getDeclaredTypeOfSymbol(prototype.parent);
  12011. return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType;
  12012. }
  12013. function getTypeOfPropertyOfType(type, name) {
  12014. var prop = getPropertyOfType(type, name);
  12015. return prop ? getTypeOfSymbol(prop) : undefined;
  12016. }
  12017. function isTypeAny(type) {
  12018. return type && (type.flags & 1) !== 0;
  12019. }
  12020. function getTypeForBindingElement(declaration) {
  12021. var pattern = declaration.parent;
  12022. var parentType = getTypeForVariableLikeDeclaration(pattern.parent);
  12023. if (parentType === unknownType) {
  12024. return unknownType;
  12025. }
  12026. if (!parentType || isTypeAny(parentType)) {
  12027. if (declaration.initializer) {
  12028. return checkExpressionCached(declaration.initializer);
  12029. }
  12030. return parentType;
  12031. }
  12032. var type;
  12033. if (pattern.kind === 159) {
  12034. var name_10 = declaration.propertyName || declaration.name;
  12035. type = getTypeOfPropertyOfType(parentType, name_10.text) ||
  12036. isNumericLiteralName(name_10.text) && getIndexTypeOfType(parentType, 1) ||
  12037. getIndexTypeOfType(parentType, 0);
  12038. if (!type) {
  12039. error(name_10, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_10));
  12040. return unknownType;
  12041. }
  12042. }
  12043. else {
  12044. var elementType = checkIteratedTypeOrElementType(parentType, pattern, false);
  12045. if (!declaration.dotDotDotToken) {
  12046. var propName = "" + ts.indexOf(pattern.elements, declaration);
  12047. type = isTupleLikeType(parentType)
  12048. ? getTypeOfPropertyOfType(parentType, propName)
  12049. : elementType;
  12050. if (!type) {
  12051. if (isTupleType(parentType)) {
  12052. 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);
  12053. }
  12054. else {
  12055. error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName);
  12056. }
  12057. return unknownType;
  12058. }
  12059. }
  12060. else {
  12061. type = createArrayType(elementType);
  12062. }
  12063. }
  12064. return type;
  12065. }
  12066. function getTypeForVariableLikeDeclaration(declaration) {
  12067. if (declaration.parent.parent.kind === 198) {
  12068. return anyType;
  12069. }
  12070. if (declaration.parent.parent.kind === 199) {
  12071. return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType;
  12072. }
  12073. if (ts.isBindingPattern(declaration.parent)) {
  12074. return getTypeForBindingElement(declaration);
  12075. }
  12076. if (declaration.type) {
  12077. return getTypeFromTypeNode(declaration.type);
  12078. }
  12079. if (declaration.kind === 136) {
  12080. var func = declaration.parent;
  12081. if (func.kind === 144 && !ts.hasDynamicName(func)) {
  12082. var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 143);
  12083. if (getter) {
  12084. return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
  12085. }
  12086. }
  12087. var type = getContextuallyTypedParameterType(declaration);
  12088. if (type) {
  12089. return type;
  12090. }
  12091. }
  12092. if (declaration.initializer) {
  12093. return checkExpressionCached(declaration.initializer);
  12094. }
  12095. if (declaration.kind === 244) {
  12096. return checkIdentifier(declaration.name);
  12097. }
  12098. if (ts.isBindingPattern(declaration.name)) {
  12099. return getTypeFromBindingPattern(declaration.name);
  12100. }
  12101. return undefined;
  12102. }
  12103. function getTypeFromBindingElement(element) {
  12104. if (element.initializer) {
  12105. return getWidenedType(checkExpressionCached(element.initializer));
  12106. }
  12107. if (ts.isBindingPattern(element.name)) {
  12108. return getTypeFromBindingPattern(element.name);
  12109. }
  12110. return anyType;
  12111. }
  12112. function getTypeFromObjectBindingPattern(pattern) {
  12113. var members = {};
  12114. ts.forEach(pattern.elements, function (e) {
  12115. var flags = 4 | 67108864 | (e.initializer ? 536870912 : 0);
  12116. var name = e.propertyName || e.name;
  12117. var symbol = createSymbol(flags, name.text);
  12118. symbol.type = getTypeFromBindingElement(e);
  12119. members[symbol.name] = symbol;
  12120. });
  12121. return createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
  12122. }
  12123. function getTypeFromArrayBindingPattern(pattern) {
  12124. var hasSpreadElement = false;
  12125. var elementTypes = [];
  12126. ts.forEach(pattern.elements, function (e) {
  12127. elementTypes.push(e.kind === 185 || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e));
  12128. if (e.dotDotDotToken) {
  12129. hasSpreadElement = true;
  12130. }
  12131. });
  12132. if (!elementTypes.length) {
  12133. return languageVersion >= 2 ? createIterableType(anyType) : anyArrayType;
  12134. }
  12135. else if (hasSpreadElement) {
  12136. var unionOfElements = getUnionType(elementTypes);
  12137. return languageVersion >= 2 ? createIterableType(unionOfElements) : createArrayType(unionOfElements);
  12138. }
  12139. return createTupleType(elementTypes);
  12140. }
  12141. function getTypeFromBindingPattern(pattern) {
  12142. return pattern.kind === 159
  12143. ? getTypeFromObjectBindingPattern(pattern)
  12144. : getTypeFromArrayBindingPattern(pattern);
  12145. }
  12146. function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
  12147. var type = getTypeForVariableLikeDeclaration(declaration);
  12148. if (type) {
  12149. if (reportErrors) {
  12150. reportErrorsFromWidening(declaration, type);
  12151. }
  12152. return declaration.kind !== 243 ? getWidenedType(type) : type;
  12153. }
  12154. type = declaration.dotDotDotToken ? anyArrayType : anyType;
  12155. if (reportErrors && compilerOptions.noImplicitAny) {
  12156. var root = ts.getRootDeclaration(declaration);
  12157. if (!isPrivateWithinAmbient(root) && !(root.kind === 136 && isPrivateWithinAmbient(root.parent))) {
  12158. reportImplicitAnyError(declaration, type);
  12159. }
  12160. }
  12161. return type;
  12162. }
  12163. function getTypeOfVariableOrParameterOrProperty(symbol) {
  12164. var links = getSymbolLinks(symbol);
  12165. if (!links.type) {
  12166. if (symbol.flags & 134217728) {
  12167. return links.type = getTypeOfPrototypeProperty(symbol);
  12168. }
  12169. var declaration = symbol.valueDeclaration;
  12170. if (declaration.parent.kind === 242) {
  12171. return links.type = anyType;
  12172. }
  12173. if (declaration.kind === 225) {
  12174. return links.type = checkExpression(declaration.expression);
  12175. }
  12176. if (!pushTypeResolution(symbol, 0)) {
  12177. return unknownType;
  12178. }
  12179. var type = getWidenedTypeForVariableLikeDeclaration(declaration, true);
  12180. if (!popTypeResolution()) {
  12181. if (symbol.valueDeclaration.type) {
  12182. type = unknownType;
  12183. error(symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
  12184. }
  12185. else {
  12186. type = anyType;
  12187. if (compilerOptions.noImplicitAny) {
  12188. 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));
  12189. }
  12190. }
  12191. }
  12192. links.type = type;
  12193. }
  12194. return links.type;
  12195. }
  12196. function getAnnotatedAccessorType(accessor) {
  12197. if (accessor) {
  12198. if (accessor.kind === 143) {
  12199. return accessor.type && getTypeFromTypeNode(accessor.type);
  12200. }
  12201. else {
  12202. var setterTypeAnnotation = ts.getSetAccessorTypeAnnotationNode(accessor);
  12203. return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation);
  12204. }
  12205. }
  12206. return undefined;
  12207. }
  12208. function getTypeOfAccessors(symbol) {
  12209. var links = getSymbolLinks(symbol);
  12210. if (!links.type) {
  12211. if (!pushTypeResolution(symbol, 0)) {
  12212. return unknownType;
  12213. }
  12214. var getter = ts.getDeclarationOfKind(symbol, 143);
  12215. var setter = ts.getDeclarationOfKind(symbol, 144);
  12216. var type;
  12217. var getterReturnType = getAnnotatedAccessorType(getter);
  12218. if (getterReturnType) {
  12219. type = getterReturnType;
  12220. }
  12221. else {
  12222. var setterParameterType = getAnnotatedAccessorType(setter);
  12223. if (setterParameterType) {
  12224. type = setterParameterType;
  12225. }
  12226. else {
  12227. if (getter && getter.body) {
  12228. type = getReturnTypeFromBody(getter);
  12229. }
  12230. else {
  12231. if (compilerOptions.noImplicitAny) {
  12232. error(setter, ts.Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
  12233. }
  12234. type = anyType;
  12235. }
  12236. }
  12237. }
  12238. if (!popTypeResolution()) {
  12239. type = anyType;
  12240. if (compilerOptions.noImplicitAny) {
  12241. var getter_1 = ts.getDeclarationOfKind(symbol, 143);
  12242. 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));
  12243. }
  12244. }
  12245. links.type = type;
  12246. }
  12247. return links.type;
  12248. }
  12249. function getTypeOfFuncClassEnumModule(symbol) {
  12250. var links = getSymbolLinks(symbol);
  12251. if (!links.type) {
  12252. links.type = createObjectType(65536, symbol);
  12253. }
  12254. return links.type;
  12255. }
  12256. function getTypeOfEnumMember(symbol) {
  12257. var links = getSymbolLinks(symbol);
  12258. if (!links.type) {
  12259. links.type = getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
  12260. }
  12261. return links.type;
  12262. }
  12263. function getTypeOfAlias(symbol) {
  12264. var links = getSymbolLinks(symbol);
  12265. if (!links.type) {
  12266. var targetSymbol = resolveAlias(symbol);
  12267. links.type = targetSymbol.flags & 107455
  12268. ? getTypeOfSymbol(targetSymbol)
  12269. : unknownType;
  12270. }
  12271. return links.type;
  12272. }
  12273. function getTypeOfInstantiatedSymbol(symbol) {
  12274. var links = getSymbolLinks(symbol);
  12275. if (!links.type) {
  12276. links.type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
  12277. }
  12278. return links.type;
  12279. }
  12280. function getTypeOfSymbol(symbol) {
  12281. if (symbol.flags & 16777216) {
  12282. return getTypeOfInstantiatedSymbol(symbol);
  12283. }
  12284. if (symbol.flags & (3 | 4)) {
  12285. return getTypeOfVariableOrParameterOrProperty(symbol);
  12286. }
  12287. if (symbol.flags & (16 | 8192 | 32 | 384 | 512)) {
  12288. return getTypeOfFuncClassEnumModule(symbol);
  12289. }
  12290. if (symbol.flags & 8) {
  12291. return getTypeOfEnumMember(symbol);
  12292. }
  12293. if (symbol.flags & 98304) {
  12294. return getTypeOfAccessors(symbol);
  12295. }
  12296. if (symbol.flags & 8388608) {
  12297. return getTypeOfAlias(symbol);
  12298. }
  12299. return unknownType;
  12300. }
  12301. function getTargetType(type) {
  12302. return type.flags & 4096 ? type.target : type;
  12303. }
  12304. function hasBaseType(type, checkBase) {
  12305. return check(type);
  12306. function check(type) {
  12307. var target = getTargetType(type);
  12308. return target === checkBase || ts.forEach(getBaseTypes(target), check);
  12309. }
  12310. }
  12311. function appendTypeParameters(typeParameters, declarations) {
  12312. for (var _i = 0; _i < declarations.length; _i++) {
  12313. var declaration = declarations[_i];
  12314. var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration));
  12315. if (!typeParameters) {
  12316. typeParameters = [tp];
  12317. }
  12318. else if (!ts.contains(typeParameters, tp)) {
  12319. typeParameters.push(tp);
  12320. }
  12321. }
  12322. return typeParameters;
  12323. }
  12324. function appendOuterTypeParameters(typeParameters, node) {
  12325. while (true) {
  12326. node = node.parent;
  12327. if (!node) {
  12328. return typeParameters;
  12329. }
  12330. if (node.kind === 212 || node.kind === 184 ||
  12331. node.kind === 211 || node.kind === 171 ||
  12332. node.kind === 141 || node.kind === 172) {
  12333. var declarations = node.typeParameters;
  12334. if (declarations) {
  12335. return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations);
  12336. }
  12337. }
  12338. }
  12339. }
  12340. function getOuterTypeParametersOfClassOrInterface(symbol) {
  12341. var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 213);
  12342. return appendOuterTypeParameters(undefined, declaration);
  12343. }
  12344. function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) {
  12345. var result;
  12346. for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
  12347. var node = _a[_i];
  12348. if (node.kind === 213 || node.kind === 212 ||
  12349. node.kind === 184 || node.kind === 214) {
  12350. var declaration = node;
  12351. if (declaration.typeParameters) {
  12352. result = appendTypeParameters(result, declaration.typeParameters);
  12353. }
  12354. }
  12355. }
  12356. return result;
  12357. }
  12358. function getTypeParametersOfClassOrInterface(symbol) {
  12359. return ts.concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol));
  12360. }
  12361. function isConstructorType(type) {
  12362. return type.flags & 80896 && getSignaturesOfType(type, 1).length > 0;
  12363. }
  12364. function getBaseTypeNodeOfClass(type) {
  12365. return ts.getClassExtendsHeritageClauseElement(type.symbol.valueDeclaration);
  12366. }
  12367. function getConstructorsForTypeArguments(type, typeArgumentNodes) {
  12368. var typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
  12369. return ts.filter(getSignaturesOfType(type, 1), function (sig) { return (sig.typeParameters ? sig.typeParameters.length : 0) === typeArgCount; });
  12370. }
  12371. function getInstantiatedConstructorsForTypeArguments(type, typeArgumentNodes) {
  12372. var signatures = getConstructorsForTypeArguments(type, typeArgumentNodes);
  12373. if (typeArgumentNodes) {
  12374. var typeArguments = ts.map(typeArgumentNodes, getTypeFromTypeNode);
  12375. signatures = ts.map(signatures, function (sig) { return getSignatureInstantiation(sig, typeArguments); });
  12376. }
  12377. return signatures;
  12378. }
  12379. function getBaseConstructorTypeOfClass(type) {
  12380. if (!type.resolvedBaseConstructorType) {
  12381. var baseTypeNode = getBaseTypeNodeOfClass(type);
  12382. if (!baseTypeNode) {
  12383. return type.resolvedBaseConstructorType = undefinedType;
  12384. }
  12385. if (!pushTypeResolution(type, 1)) {
  12386. return unknownType;
  12387. }
  12388. var baseConstructorType = checkExpression(baseTypeNode.expression);
  12389. if (baseConstructorType.flags & 80896) {
  12390. resolveStructuredTypeMembers(baseConstructorType);
  12391. }
  12392. if (!popTypeResolution()) {
  12393. error(type.symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_base_expression, symbolToString(type.symbol));
  12394. return type.resolvedBaseConstructorType = unknownType;
  12395. }
  12396. if (baseConstructorType !== unknownType && baseConstructorType !== nullType && !isConstructorType(baseConstructorType)) {
  12397. error(baseTypeNode.expression, ts.Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType));
  12398. return type.resolvedBaseConstructorType = unknownType;
  12399. }
  12400. type.resolvedBaseConstructorType = baseConstructorType;
  12401. }
  12402. return type.resolvedBaseConstructorType;
  12403. }
  12404. function getBaseTypes(type) {
  12405. if (!type.resolvedBaseTypes) {
  12406. if (type.symbol.flags & 32) {
  12407. resolveBaseTypesOfClass(type);
  12408. }
  12409. else if (type.symbol.flags & 64) {
  12410. resolveBaseTypesOfInterface(type);
  12411. }
  12412. else {
  12413. ts.Debug.fail("type must be class or interface");
  12414. }
  12415. }
  12416. return type.resolvedBaseTypes;
  12417. }
  12418. function resolveBaseTypesOfClass(type) {
  12419. type.resolvedBaseTypes = emptyArray;
  12420. var baseContructorType = getBaseConstructorTypeOfClass(type);
  12421. if (!(baseContructorType.flags & 80896)) {
  12422. return;
  12423. }
  12424. var baseTypeNode = getBaseTypeNodeOfClass(type);
  12425. var baseType;
  12426. if (baseContructorType.symbol && baseContructorType.symbol.flags & 32) {
  12427. baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseContructorType.symbol);
  12428. }
  12429. else {
  12430. var constructors = getInstantiatedConstructorsForTypeArguments(baseContructorType, baseTypeNode.typeArguments);
  12431. if (!constructors.length) {
  12432. error(baseTypeNode.expression, ts.Diagnostics.No_base_constructor_has_the_specified_number_of_type_arguments);
  12433. return;
  12434. }
  12435. baseType = getReturnTypeOfSignature(constructors[0]);
  12436. }
  12437. if (baseType === unknownType) {
  12438. return;
  12439. }
  12440. if (!(getTargetType(baseType).flags & (1024 | 2048))) {
  12441. error(baseTypeNode.expression, ts.Diagnostics.Base_constructor_return_type_0_is_not_a_class_or_interface_type, typeToString(baseType));
  12442. return;
  12443. }
  12444. if (type === baseType || hasBaseType(baseType, type)) {
  12445. error(type.symbol.valueDeclaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, undefined, 1));
  12446. return;
  12447. }
  12448. type.resolvedBaseTypes = [baseType];
  12449. }
  12450. function resolveBaseTypesOfInterface(type) {
  12451. type.resolvedBaseTypes = [];
  12452. for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) {
  12453. var declaration = _a[_i];
  12454. if (declaration.kind === 213 && ts.getInterfaceBaseTypeNodes(declaration)) {
  12455. for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) {
  12456. var node = _c[_b];
  12457. var baseType = getTypeFromTypeNode(node);
  12458. if (baseType !== unknownType) {
  12459. if (getTargetType(baseType).flags & (1024 | 2048)) {
  12460. if (type !== baseType && !hasBaseType(baseType, type)) {
  12461. type.resolvedBaseTypes.push(baseType);
  12462. }
  12463. else {
  12464. error(declaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, undefined, 1));
  12465. }
  12466. }
  12467. else {
  12468. error(node, ts.Diagnostics.An_interface_may_only_extend_a_class_or_another_interface);
  12469. }
  12470. }
  12471. }
  12472. }
  12473. }
  12474. }
  12475. function getDeclaredTypeOfClassOrInterface(symbol) {
  12476. var links = getSymbolLinks(symbol);
  12477. if (!links.declaredType) {
  12478. var kind = symbol.flags & 32 ? 1024 : 2048;
  12479. var type = links.declaredType = createObjectType(kind, symbol);
  12480. var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol);
  12481. var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
  12482. if (outerTypeParameters || localTypeParameters) {
  12483. type.flags |= 4096;
  12484. type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters);
  12485. type.outerTypeParameters = outerTypeParameters;
  12486. type.localTypeParameters = localTypeParameters;
  12487. type.instantiations = {};
  12488. type.instantiations[getTypeListId(type.typeParameters)] = type;
  12489. type.target = type;
  12490. type.typeArguments = type.typeParameters;
  12491. }
  12492. }
  12493. return links.declaredType;
  12494. }
  12495. function getDeclaredTypeOfTypeAlias(symbol) {
  12496. var links = getSymbolLinks(symbol);
  12497. if (!links.declaredType) {
  12498. if (!pushTypeResolution(symbol, 2)) {
  12499. return unknownType;
  12500. }
  12501. var declaration = ts.getDeclarationOfKind(symbol, 214);
  12502. var type = getTypeFromTypeNode(declaration.type);
  12503. if (popTypeResolution()) {
  12504. links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
  12505. if (links.typeParameters) {
  12506. links.instantiations = {};
  12507. links.instantiations[getTypeListId(links.typeParameters)] = type;
  12508. }
  12509. }
  12510. else {
  12511. type = unknownType;
  12512. error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
  12513. }
  12514. links.declaredType = type;
  12515. }
  12516. return links.declaredType;
  12517. }
  12518. function getDeclaredTypeOfEnum(symbol) {
  12519. var links = getSymbolLinks(symbol);
  12520. if (!links.declaredType) {
  12521. var type = createType(128);
  12522. type.symbol = symbol;
  12523. links.declaredType = type;
  12524. }
  12525. return links.declaredType;
  12526. }
  12527. function getDeclaredTypeOfTypeParameter(symbol) {
  12528. var links = getSymbolLinks(symbol);
  12529. if (!links.declaredType) {
  12530. var type = createType(512);
  12531. type.symbol = symbol;
  12532. if (!ts.getDeclarationOfKind(symbol, 135).constraint) {
  12533. type.constraint = noConstraintType;
  12534. }
  12535. links.declaredType = type;
  12536. }
  12537. return links.declaredType;
  12538. }
  12539. function getDeclaredTypeOfAlias(symbol) {
  12540. var links = getSymbolLinks(symbol);
  12541. if (!links.declaredType) {
  12542. links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol));
  12543. }
  12544. return links.declaredType;
  12545. }
  12546. function getDeclaredTypeOfSymbol(symbol) {
  12547. ts.Debug.assert((symbol.flags & 16777216) === 0);
  12548. if (symbol.flags & (32 | 64)) {
  12549. return getDeclaredTypeOfClassOrInterface(symbol);
  12550. }
  12551. if (symbol.flags & 524288) {
  12552. return getDeclaredTypeOfTypeAlias(symbol);
  12553. }
  12554. if (symbol.flags & 384) {
  12555. return getDeclaredTypeOfEnum(symbol);
  12556. }
  12557. if (symbol.flags & 262144) {
  12558. return getDeclaredTypeOfTypeParameter(symbol);
  12559. }
  12560. if (symbol.flags & 8388608) {
  12561. return getDeclaredTypeOfAlias(symbol);
  12562. }
  12563. return unknownType;
  12564. }
  12565. function createSymbolTable(symbols) {
  12566. var result = {};
  12567. for (var _i = 0; _i < symbols.length; _i++) {
  12568. var symbol = symbols[_i];
  12569. result[symbol.name] = symbol;
  12570. }
  12571. return result;
  12572. }
  12573. function createInstantiatedSymbolTable(symbols, mapper) {
  12574. var result = {};
  12575. for (var _i = 0; _i < symbols.length; _i++) {
  12576. var symbol = symbols[_i];
  12577. result[symbol.name] = instantiateSymbol(symbol, mapper);
  12578. }
  12579. return result;
  12580. }
  12581. function addInheritedMembers(symbols, baseSymbols) {
  12582. for (var _i = 0; _i < baseSymbols.length; _i++) {
  12583. var s = baseSymbols[_i];
  12584. if (!ts.hasProperty(symbols, s.name)) {
  12585. symbols[s.name] = s;
  12586. }
  12587. }
  12588. }
  12589. function addInheritedSignatures(signatures, baseSignatures) {
  12590. if (baseSignatures) {
  12591. for (var _i = 0; _i < baseSignatures.length; _i++) {
  12592. var signature = baseSignatures[_i];
  12593. signatures.push(signature);
  12594. }
  12595. }
  12596. }
  12597. function resolveDeclaredMembers(type) {
  12598. if (!type.declaredProperties) {
  12599. var symbol = type.symbol;
  12600. type.declaredProperties = getNamedMembers(symbol.members);
  12601. type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]);
  12602. type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]);
  12603. type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, 0);
  12604. type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, 1);
  12605. }
  12606. return type;
  12607. }
  12608. function resolveClassOrInterfaceMembers(type) {
  12609. var target = resolveDeclaredMembers(type);
  12610. var members = target.symbol.members;
  12611. var callSignatures = target.declaredCallSignatures;
  12612. var constructSignatures = target.declaredConstructSignatures;
  12613. var stringIndexType = target.declaredStringIndexType;
  12614. var numberIndexType = target.declaredNumberIndexType;
  12615. var baseTypes = getBaseTypes(target);
  12616. if (baseTypes.length) {
  12617. members = createSymbolTable(target.declaredProperties);
  12618. for (var _i = 0; _i < baseTypes.length; _i++) {
  12619. var baseType = baseTypes[_i];
  12620. addInheritedMembers(members, getPropertiesOfObjectType(baseType));
  12621. callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0));
  12622. constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1));
  12623. stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0);
  12624. numberIndexType = numberIndexType || getIndexTypeOfType(baseType, 1);
  12625. }
  12626. }
  12627. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  12628. }
  12629. function resolveTypeReferenceMembers(type) {
  12630. var target = resolveDeclaredMembers(type.target);
  12631. var mapper = createTypeMapper(target.typeParameters, type.typeArguments);
  12632. var members = createInstantiatedSymbolTable(target.declaredProperties, mapper);
  12633. var callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature);
  12634. var constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature);
  12635. var stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined;
  12636. var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined;
  12637. ts.forEach(getBaseTypes(target), function (baseType) {
  12638. var instantiatedBaseType = instantiateType(baseType, mapper);
  12639. addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType));
  12640. callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0));
  12641. constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1));
  12642. stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0);
  12643. numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1);
  12644. });
  12645. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  12646. }
  12647. function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) {
  12648. var sig = new Signature(checker);
  12649. sig.declaration = declaration;
  12650. sig.typeParameters = typeParameters;
  12651. sig.parameters = parameters;
  12652. sig.resolvedReturnType = resolvedReturnType;
  12653. sig.typePredicate = typePredicate;
  12654. sig.minArgumentCount = minArgumentCount;
  12655. sig.hasRestParameter = hasRestParameter;
  12656. sig.hasStringLiterals = hasStringLiterals;
  12657. return sig;
  12658. }
  12659. function cloneSignature(sig) {
  12660. return createSignature(sig.declaration, sig.typeParameters, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals);
  12661. }
  12662. function getDefaultConstructSignatures(classType) {
  12663. if (!getBaseTypes(classType).length) {
  12664. return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)];
  12665. }
  12666. var baseConstructorType = getBaseConstructorTypeOfClass(classType);
  12667. var baseSignatures = getSignaturesOfType(baseConstructorType, 1);
  12668. var baseTypeNode = getBaseTypeNodeOfClass(classType);
  12669. var typeArguments = ts.map(baseTypeNode.typeArguments, getTypeFromTypeNode);
  12670. var typeArgCount = typeArguments ? typeArguments.length : 0;
  12671. var result = [];
  12672. for (var _i = 0; _i < baseSignatures.length; _i++) {
  12673. var baseSig = baseSignatures[_i];
  12674. var typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0;
  12675. if (typeParamCount === typeArgCount) {
  12676. var sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig);
  12677. sig.typeParameters = classType.localTypeParameters;
  12678. sig.resolvedReturnType = classType;
  12679. result.push(sig);
  12680. }
  12681. }
  12682. return result;
  12683. }
  12684. function createTupleTypeMemberSymbols(memberTypes) {
  12685. var members = {};
  12686. for (var i = 0; i < memberTypes.length; i++) {
  12687. var symbol = createSymbol(4 | 67108864, "" + i);
  12688. symbol.type = memberTypes[i];
  12689. members[i] = symbol;
  12690. }
  12691. return members;
  12692. }
  12693. function resolveTupleTypeMembers(type) {
  12694. var arrayType = resolveStructuredTypeMembers(createArrayType(getUnionType(type.elementTypes, true)));
  12695. var members = createTupleTypeMemberSymbols(type.elementTypes);
  12696. addInheritedMembers(members, arrayType.properties);
  12697. setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
  12698. }
  12699. function findMatchingSignature(signatureList, signature, partialMatch, ignoreReturnTypes) {
  12700. for (var _i = 0; _i < signatureList.length; _i++) {
  12701. var s = signatureList[_i];
  12702. if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
  12703. return s;
  12704. }
  12705. }
  12706. }
  12707. function findMatchingSignatures(signatureLists, signature, listIndex) {
  12708. if (signature.typeParameters) {
  12709. if (listIndex > 0) {
  12710. return undefined;
  12711. }
  12712. for (var i = 1; i < signatureLists.length; i++) {
  12713. if (!findMatchingSignature(signatureLists[i], signature, false, false)) {
  12714. return undefined;
  12715. }
  12716. }
  12717. return [signature];
  12718. }
  12719. var result = undefined;
  12720. for (var i = 0; i < signatureLists.length; i++) {
  12721. var match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, true, true);
  12722. if (!match) {
  12723. return undefined;
  12724. }
  12725. if (!ts.contains(result, match)) {
  12726. (result || (result = [])).push(match);
  12727. }
  12728. }
  12729. return result;
  12730. }
  12731. function getUnionSignatures(types, kind) {
  12732. var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); });
  12733. var result = undefined;
  12734. for (var i = 0; i < signatureLists.length; i++) {
  12735. for (var _i = 0, _a = signatureLists[i]; _i < _a.length; _i++) {
  12736. var signature = _a[_i];
  12737. if (!result || !findMatchingSignature(result, signature, false, true)) {
  12738. var unionSignatures = findMatchingSignatures(signatureLists, signature, i);
  12739. if (unionSignatures) {
  12740. var s = signature;
  12741. if (unionSignatures.length > 1) {
  12742. s = cloneSignature(signature);
  12743. s.resolvedReturnType = undefined;
  12744. s.unionSignatures = unionSignatures;
  12745. }
  12746. (result || (result = [])).push(s);
  12747. }
  12748. }
  12749. }
  12750. }
  12751. return result || emptyArray;
  12752. }
  12753. function getUnionIndexType(types, kind) {
  12754. var indexTypes = [];
  12755. for (var _i = 0; _i < types.length; _i++) {
  12756. var type = types[_i];
  12757. var indexType = getIndexTypeOfType(type, kind);
  12758. if (!indexType) {
  12759. return undefined;
  12760. }
  12761. indexTypes.push(indexType);
  12762. }
  12763. return getUnionType(indexTypes);
  12764. }
  12765. function resolveUnionTypeMembers(type) {
  12766. var callSignatures = getUnionSignatures(type.types, 0);
  12767. var constructSignatures = getUnionSignatures(type.types, 1);
  12768. var stringIndexType = getUnionIndexType(type.types, 0);
  12769. var numberIndexType = getUnionIndexType(type.types, 1);
  12770. setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  12771. }
  12772. function intersectTypes(type1, type2) {
  12773. return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]);
  12774. }
  12775. function resolveIntersectionTypeMembers(type) {
  12776. var callSignatures = emptyArray;
  12777. var constructSignatures = emptyArray;
  12778. var stringIndexType = undefined;
  12779. var numberIndexType = undefined;
  12780. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  12781. var t = _a[_i];
  12782. callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(t, 0));
  12783. constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(t, 1));
  12784. stringIndexType = intersectTypes(stringIndexType, getIndexTypeOfType(t, 0));
  12785. numberIndexType = intersectTypes(numberIndexType, getIndexTypeOfType(t, 1));
  12786. }
  12787. setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  12788. }
  12789. function resolveAnonymousTypeMembers(type) {
  12790. var symbol = type.symbol;
  12791. var members;
  12792. var callSignatures;
  12793. var constructSignatures;
  12794. var stringIndexType;
  12795. var numberIndexType;
  12796. if (symbol.flags & 2048) {
  12797. members = symbol.members;
  12798. callSignatures = getSignaturesOfSymbol(members["__call"]);
  12799. constructSignatures = getSignaturesOfSymbol(members["__new"]);
  12800. stringIndexType = getIndexTypeOfSymbol(symbol, 0);
  12801. numberIndexType = getIndexTypeOfSymbol(symbol, 1);
  12802. }
  12803. else {
  12804. members = emptySymbols;
  12805. callSignatures = emptyArray;
  12806. constructSignatures = emptyArray;
  12807. if (symbol.flags & 1952) {
  12808. members = getExportsOfSymbol(symbol);
  12809. }
  12810. if (symbol.flags & (16 | 8192)) {
  12811. callSignatures = getSignaturesOfSymbol(symbol);
  12812. }
  12813. if (symbol.flags & 32) {
  12814. var classType = getDeclaredTypeOfClassOrInterface(symbol);
  12815. constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
  12816. if (!constructSignatures.length) {
  12817. constructSignatures = getDefaultConstructSignatures(classType);
  12818. }
  12819. var baseConstructorType = getBaseConstructorTypeOfClass(classType);
  12820. if (baseConstructorType.flags & 80896) {
  12821. members = createSymbolTable(getNamedMembers(members));
  12822. addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType));
  12823. }
  12824. }
  12825. stringIndexType = undefined;
  12826. numberIndexType = (symbol.flags & 384) ? stringType : undefined;
  12827. }
  12828. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  12829. }
  12830. function resolveStructuredTypeMembers(type) {
  12831. if (!type.members) {
  12832. if (type.flags & (1024 | 2048)) {
  12833. resolveClassOrInterfaceMembers(type);
  12834. }
  12835. else if (type.flags & 65536) {
  12836. resolveAnonymousTypeMembers(type);
  12837. }
  12838. else if (type.flags & 8192) {
  12839. resolveTupleTypeMembers(type);
  12840. }
  12841. else if (type.flags & 16384) {
  12842. resolveUnionTypeMembers(type);
  12843. }
  12844. else if (type.flags & 32768) {
  12845. resolveIntersectionTypeMembers(type);
  12846. }
  12847. else {
  12848. resolveTypeReferenceMembers(type);
  12849. }
  12850. }
  12851. return type;
  12852. }
  12853. function getPropertiesOfObjectType(type) {
  12854. if (type.flags & 80896) {
  12855. return resolveStructuredTypeMembers(type).properties;
  12856. }
  12857. return emptyArray;
  12858. }
  12859. function getPropertyOfObjectType(type, name) {
  12860. if (type.flags & 80896) {
  12861. var resolved = resolveStructuredTypeMembers(type);
  12862. if (ts.hasProperty(resolved.members, name)) {
  12863. var symbol = resolved.members[name];
  12864. if (symbolIsValue(symbol)) {
  12865. return symbol;
  12866. }
  12867. }
  12868. }
  12869. }
  12870. function getPropertiesOfUnionOrIntersectionType(type) {
  12871. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  12872. var current = _a[_i];
  12873. for (var _b = 0, _c = getPropertiesOfType(current); _b < _c.length; _b++) {
  12874. var prop = _c[_b];
  12875. getPropertyOfUnionOrIntersectionType(type, prop.name);
  12876. }
  12877. if (type.flags & 16384) {
  12878. break;
  12879. }
  12880. }
  12881. return type.resolvedProperties ? symbolsToArray(type.resolvedProperties) : emptyArray;
  12882. }
  12883. function getPropertiesOfType(type) {
  12884. type = getApparentType(type);
  12885. return type.flags & 49152 ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type);
  12886. }
  12887. function getApparentType(type) {
  12888. if (type.flags & 512) {
  12889. do {
  12890. type = getConstraintOfTypeParameter(type);
  12891. } while (type && type.flags & 512);
  12892. if (!type) {
  12893. type = emptyObjectType;
  12894. }
  12895. }
  12896. if (type.flags & 258) {
  12897. type = globalStringType;
  12898. }
  12899. else if (type.flags & 132) {
  12900. type = globalNumberType;
  12901. }
  12902. else if (type.flags & 8) {
  12903. type = globalBooleanType;
  12904. }
  12905. else if (type.flags & 16777216) {
  12906. type = globalESSymbolType;
  12907. }
  12908. return type;
  12909. }
  12910. function createUnionOrIntersectionProperty(containingType, name) {
  12911. var types = containingType.types;
  12912. var props;
  12913. for (var _i = 0; _i < types.length; _i++) {
  12914. var current = types[_i];
  12915. var type = getApparentType(current);
  12916. if (type !== unknownType) {
  12917. var prop = getPropertyOfType(type, name);
  12918. if (prop && !(getDeclarationFlagsFromSymbol(prop) & (32 | 64))) {
  12919. if (!props) {
  12920. props = [prop];
  12921. }
  12922. else if (!ts.contains(props, prop)) {
  12923. props.push(prop);
  12924. }
  12925. }
  12926. else if (containingType.flags & 16384) {
  12927. return undefined;
  12928. }
  12929. }
  12930. }
  12931. if (!props) {
  12932. return undefined;
  12933. }
  12934. if (props.length === 1) {
  12935. return props[0];
  12936. }
  12937. var propTypes = [];
  12938. var declarations = [];
  12939. for (var _a = 0; _a < props.length; _a++) {
  12940. var prop = props[_a];
  12941. if (prop.declarations) {
  12942. ts.addRange(declarations, prop.declarations);
  12943. }
  12944. propTypes.push(getTypeOfSymbol(prop));
  12945. }
  12946. var result = createSymbol(4 | 67108864 | 268435456, name);
  12947. result.containingType = containingType;
  12948. result.declarations = declarations;
  12949. result.type = containingType.flags & 16384 ? getUnionType(propTypes) : getIntersectionType(propTypes);
  12950. return result;
  12951. }
  12952. function getPropertyOfUnionOrIntersectionType(type, name) {
  12953. var properties = type.resolvedProperties || (type.resolvedProperties = {});
  12954. if (ts.hasProperty(properties, name)) {
  12955. return properties[name];
  12956. }
  12957. var property = createUnionOrIntersectionProperty(type, name);
  12958. if (property) {
  12959. properties[name] = property;
  12960. }
  12961. return property;
  12962. }
  12963. function getPropertyOfType(type, name) {
  12964. type = getApparentType(type);
  12965. if (type.flags & 80896) {
  12966. var resolved = resolveStructuredTypeMembers(type);
  12967. if (ts.hasProperty(resolved.members, name)) {
  12968. var symbol = resolved.members[name];
  12969. if (symbolIsValue(symbol)) {
  12970. return symbol;
  12971. }
  12972. }
  12973. if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) {
  12974. var symbol = getPropertyOfObjectType(globalFunctionType, name);
  12975. if (symbol) {
  12976. return symbol;
  12977. }
  12978. }
  12979. return getPropertyOfObjectType(globalObjectType, name);
  12980. }
  12981. if (type.flags & 49152) {
  12982. return getPropertyOfUnionOrIntersectionType(type, name);
  12983. }
  12984. return undefined;
  12985. }
  12986. function getSignaturesOfStructuredType(type, kind) {
  12987. if (type.flags & 130048) {
  12988. var resolved = resolveStructuredTypeMembers(type);
  12989. return kind === 0 ? resolved.callSignatures : resolved.constructSignatures;
  12990. }
  12991. return emptyArray;
  12992. }
  12993. function getSignaturesOfType(type, kind) {
  12994. return getSignaturesOfStructuredType(getApparentType(type), kind);
  12995. }
  12996. function typeHasConstructSignatures(type) {
  12997. var apparentType = getApparentType(type);
  12998. if (apparentType.flags & (80896 | 16384)) {
  12999. var resolved = resolveStructuredTypeMembers(type);
  13000. return resolved.constructSignatures.length > 0;
  13001. }
  13002. return false;
  13003. }
  13004. function typeHasCallOrConstructSignatures(type) {
  13005. var apparentType = getApparentType(type);
  13006. if (apparentType.flags & 130048) {
  13007. var resolved = resolveStructuredTypeMembers(type);
  13008. return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0;
  13009. }
  13010. return false;
  13011. }
  13012. function getIndexTypeOfStructuredType(type, kind) {
  13013. if (type.flags & 130048) {
  13014. var resolved = resolveStructuredTypeMembers(type);
  13015. return kind === 0 ? resolved.stringIndexType : resolved.numberIndexType;
  13016. }
  13017. }
  13018. function getIndexTypeOfType(type, kind) {
  13019. return getIndexTypeOfStructuredType(getApparentType(type), kind);
  13020. }
  13021. function getTypeParametersFromDeclaration(typeParameterDeclarations) {
  13022. var result = [];
  13023. ts.forEach(typeParameterDeclarations, function (node) {
  13024. var tp = getDeclaredTypeOfTypeParameter(node.symbol);
  13025. if (!ts.contains(result, tp)) {
  13026. result.push(tp);
  13027. }
  13028. });
  13029. return result;
  13030. }
  13031. function symbolsToArray(symbols) {
  13032. var result = [];
  13033. for (var id in symbols) {
  13034. if (!isReservedMemberName(id)) {
  13035. result.push(symbols[id]);
  13036. }
  13037. }
  13038. return result;
  13039. }
  13040. function isOptionalParameter(node) {
  13041. if (ts.hasQuestionToken(node)) {
  13042. return true;
  13043. }
  13044. if (node.initializer) {
  13045. var signatureDeclaration = node.parent;
  13046. var signature = getSignatureFromDeclaration(signatureDeclaration);
  13047. var parameterIndex = signatureDeclaration.parameters.indexOf(node);
  13048. ts.Debug.assert(parameterIndex >= 0);
  13049. return parameterIndex >= signature.minArgumentCount;
  13050. }
  13051. return false;
  13052. }
  13053. function getSignatureFromDeclaration(declaration) {
  13054. var links = getNodeLinks(declaration);
  13055. if (!links.resolvedSignature) {
  13056. var classType = declaration.kind === 142 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined;
  13057. var typeParameters = classType ? classType.localTypeParameters :
  13058. declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined;
  13059. var parameters = [];
  13060. var hasStringLiterals = false;
  13061. var minArgumentCount = -1;
  13062. for (var i = 0, n = declaration.parameters.length; i < n; i++) {
  13063. var param = declaration.parameters[i];
  13064. parameters.push(param.symbol);
  13065. if (param.type && param.type.kind === 9) {
  13066. hasStringLiterals = true;
  13067. }
  13068. if (param.initializer || param.questionToken || param.dotDotDotToken) {
  13069. if (minArgumentCount < 0) {
  13070. minArgumentCount = i;
  13071. }
  13072. }
  13073. else {
  13074. minArgumentCount = -1;
  13075. }
  13076. }
  13077. if (minArgumentCount < 0) {
  13078. minArgumentCount = declaration.parameters.length;
  13079. }
  13080. var returnType;
  13081. var typePredicate;
  13082. if (classType) {
  13083. returnType = classType;
  13084. }
  13085. else if (declaration.type) {
  13086. returnType = getTypeFromTypeNode(declaration.type);
  13087. if (declaration.type.kind === 148) {
  13088. var typePredicateNode = declaration.type;
  13089. typePredicate = {
  13090. parameterName: typePredicateNode.parameterName ? typePredicateNode.parameterName.text : undefined,
  13091. parameterIndex: typePredicateNode.parameterName ? getTypePredicateParameterIndex(declaration.parameters, typePredicateNode.parameterName) : undefined,
  13092. type: getTypeFromTypeNode(typePredicateNode.type)
  13093. };
  13094. }
  13095. }
  13096. else {
  13097. if (declaration.kind === 143 && !ts.hasDynamicName(declaration)) {
  13098. var setter = ts.getDeclarationOfKind(declaration.symbol, 144);
  13099. returnType = getAnnotatedAccessorType(setter);
  13100. }
  13101. if (!returnType && ts.nodeIsMissing(declaration.body)) {
  13102. returnType = anyType;
  13103. }
  13104. }
  13105. links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals);
  13106. }
  13107. return links.resolvedSignature;
  13108. }
  13109. function getSignaturesOfSymbol(symbol) {
  13110. if (!symbol)
  13111. return emptyArray;
  13112. var result = [];
  13113. for (var i = 0, len = symbol.declarations.length; i < len; i++) {
  13114. var node = symbol.declarations[i];
  13115. switch (node.kind) {
  13116. case 150:
  13117. case 151:
  13118. case 211:
  13119. case 141:
  13120. case 140:
  13121. case 142:
  13122. case 145:
  13123. case 146:
  13124. case 147:
  13125. case 143:
  13126. case 144:
  13127. case 171:
  13128. case 172:
  13129. if (i > 0 && node.body) {
  13130. var previous = symbol.declarations[i - 1];
  13131. if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) {
  13132. break;
  13133. }
  13134. }
  13135. result.push(getSignatureFromDeclaration(node));
  13136. }
  13137. }
  13138. return result;
  13139. }
  13140. function getReturnTypeOfSignature(signature) {
  13141. if (!signature.resolvedReturnType) {
  13142. if (!pushTypeResolution(signature, 3)) {
  13143. return unknownType;
  13144. }
  13145. var type;
  13146. if (signature.target) {
  13147. type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
  13148. }
  13149. else if (signature.unionSignatures) {
  13150. type = getUnionType(ts.map(signature.unionSignatures, getReturnTypeOfSignature));
  13151. }
  13152. else {
  13153. type = getReturnTypeFromBody(signature.declaration);
  13154. }
  13155. if (!popTypeResolution()) {
  13156. type = anyType;
  13157. if (compilerOptions.noImplicitAny) {
  13158. var declaration = signature.declaration;
  13159. if (declaration.name) {
  13160. 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));
  13161. }
  13162. else {
  13163. 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);
  13164. }
  13165. }
  13166. }
  13167. signature.resolvedReturnType = type;
  13168. }
  13169. return signature.resolvedReturnType;
  13170. }
  13171. function getRestTypeOfSignature(signature) {
  13172. if (signature.hasRestParameter) {
  13173. var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
  13174. if (type.flags & 4096 && type.target === globalArrayType) {
  13175. return type.typeArguments[0];
  13176. }
  13177. }
  13178. return anyType;
  13179. }
  13180. function getSignatureInstantiation(signature, typeArguments) {
  13181. return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), true);
  13182. }
  13183. function getErasedSignature(signature) {
  13184. if (!signature.typeParameters)
  13185. return signature;
  13186. if (!signature.erasedSignatureCache) {
  13187. if (signature.target) {
  13188. signature.erasedSignatureCache = instantiateSignature(getErasedSignature(signature.target), signature.mapper);
  13189. }
  13190. else {
  13191. signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), true);
  13192. }
  13193. }
  13194. return signature.erasedSignatureCache;
  13195. }
  13196. function getOrCreateTypeFromSignature(signature) {
  13197. if (!signature.isolatedSignatureType) {
  13198. var isConstructor = signature.declaration.kind === 142 || signature.declaration.kind === 146;
  13199. var type = createObjectType(65536 | 262144);
  13200. type.members = emptySymbols;
  13201. type.properties = emptyArray;
  13202. type.callSignatures = !isConstructor ? [signature] : emptyArray;
  13203. type.constructSignatures = isConstructor ? [signature] : emptyArray;
  13204. signature.isolatedSignatureType = type;
  13205. }
  13206. return signature.isolatedSignatureType;
  13207. }
  13208. function getIndexSymbol(symbol) {
  13209. return symbol.members["__index"];
  13210. }
  13211. function getIndexDeclarationOfSymbol(symbol, kind) {
  13212. var syntaxKind = kind === 1 ? 126 : 128;
  13213. var indexSymbol = getIndexSymbol(symbol);
  13214. if (indexSymbol) {
  13215. for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
  13216. var decl = _a[_i];
  13217. var node = decl;
  13218. if (node.parameters.length === 1) {
  13219. var parameter = node.parameters[0];
  13220. if (parameter && parameter.type && parameter.type.kind === syntaxKind) {
  13221. return node;
  13222. }
  13223. }
  13224. }
  13225. }
  13226. return undefined;
  13227. }
  13228. function getIndexTypeOfSymbol(symbol, kind) {
  13229. var declaration = getIndexDeclarationOfSymbol(symbol, kind);
  13230. return declaration
  13231. ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType
  13232. : undefined;
  13233. }
  13234. function getConstraintOfTypeParameter(type) {
  13235. if (!type.constraint) {
  13236. if (type.target) {
  13237. var targetConstraint = getConstraintOfTypeParameter(type.target);
  13238. type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType;
  13239. }
  13240. else {
  13241. type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 135).constraint);
  13242. }
  13243. }
  13244. return type.constraint === noConstraintType ? undefined : type.constraint;
  13245. }
  13246. function getParentSymbolOfTypeParameter(typeParameter) {
  13247. return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 135).parent);
  13248. }
  13249. function getTypeListId(types) {
  13250. switch (types.length) {
  13251. case 1:
  13252. return "" + types[0].id;
  13253. case 2:
  13254. return types[0].id + "," + types[1].id;
  13255. default:
  13256. var result = "";
  13257. for (var i = 0; i < types.length; i++) {
  13258. if (i > 0) {
  13259. result += ",";
  13260. }
  13261. result += types[i].id;
  13262. }
  13263. return result;
  13264. }
  13265. }
  13266. function getPropagatingFlagsOfTypes(types) {
  13267. var result = 0;
  13268. for (var _i = 0; _i < types.length; _i++) {
  13269. var type = types[_i];
  13270. result |= type.flags;
  13271. }
  13272. return result & 14680064;
  13273. }
  13274. function createTypeReference(target, typeArguments) {
  13275. var id = getTypeListId(typeArguments);
  13276. var type = target.instantiations[id];
  13277. if (!type) {
  13278. var flags = 4096 | getPropagatingFlagsOfTypes(typeArguments);
  13279. type = target.instantiations[id] = createObjectType(flags, target.symbol);
  13280. type.target = target;
  13281. type.typeArguments = typeArguments;
  13282. }
  13283. return type;
  13284. }
  13285. function isTypeParameterReferenceIllegalInConstraint(typeReferenceNode, typeParameterSymbol) {
  13286. var links = getNodeLinks(typeReferenceNode);
  13287. if (links.isIllegalTypeReferenceInConstraint !== undefined) {
  13288. return links.isIllegalTypeReferenceInConstraint;
  13289. }
  13290. var currentNode = typeReferenceNode;
  13291. while (!ts.forEach(typeParameterSymbol.declarations, function (d) { return d.parent === currentNode.parent; })) {
  13292. currentNode = currentNode.parent;
  13293. }
  13294. links.isIllegalTypeReferenceInConstraint = currentNode.kind === 135;
  13295. return links.isIllegalTypeReferenceInConstraint;
  13296. }
  13297. function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) {
  13298. var typeParameterSymbol;
  13299. function check(n) {
  13300. if (n.kind === 149 && n.typeName.kind === 67) {
  13301. var links = getNodeLinks(n);
  13302. if (links.isIllegalTypeReferenceInConstraint === undefined) {
  13303. var symbol = resolveName(typeParameter, n.typeName.text, 793056, undefined, undefined);
  13304. if (symbol && (symbol.flags & 262144)) {
  13305. links.isIllegalTypeReferenceInConstraint = ts.forEach(symbol.declarations, function (d) { return d.parent === typeParameter.parent; });
  13306. }
  13307. }
  13308. if (links.isIllegalTypeReferenceInConstraint) {
  13309. error(typeParameter, ts.Diagnostics.Constraint_of_a_type_parameter_cannot_reference_any_type_parameter_from_the_same_type_parameter_list);
  13310. }
  13311. }
  13312. ts.forEachChild(n, check);
  13313. }
  13314. if (typeParameter.constraint) {
  13315. typeParameterSymbol = getSymbolOfNode(typeParameter);
  13316. check(typeParameter.constraint);
  13317. }
  13318. }
  13319. function getTypeFromClassOrInterfaceReference(node, symbol) {
  13320. var type = getDeclaredTypeOfSymbol(symbol);
  13321. var typeParameters = type.localTypeParameters;
  13322. if (typeParameters) {
  13323. if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
  13324. error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), typeParameters.length);
  13325. return unknownType;
  13326. }
  13327. return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(node.typeArguments, getTypeFromTypeNode)));
  13328. }
  13329. if (node.typeArguments) {
  13330. error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type));
  13331. return unknownType;
  13332. }
  13333. return type;
  13334. }
  13335. function getTypeFromTypeAliasReference(node, symbol) {
  13336. var type = getDeclaredTypeOfSymbol(symbol);
  13337. var links = getSymbolLinks(symbol);
  13338. var typeParameters = links.typeParameters;
  13339. if (typeParameters) {
  13340. if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
  13341. error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length);
  13342. return unknownType;
  13343. }
  13344. var typeArguments = ts.map(node.typeArguments, getTypeFromTypeNode);
  13345. var id = getTypeListId(typeArguments);
  13346. return links.instantiations[id] || (links.instantiations[id] = instantiateType(type, createTypeMapper(typeParameters, typeArguments)));
  13347. }
  13348. if (node.typeArguments) {
  13349. error(node, ts.Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
  13350. return unknownType;
  13351. }
  13352. return type;
  13353. }
  13354. function getTypeFromNonGenericTypeReference(node, symbol) {
  13355. if (symbol.flags & 262144 && isTypeParameterReferenceIllegalInConstraint(node, symbol)) {
  13356. return unknownType;
  13357. }
  13358. if (node.typeArguments) {
  13359. error(node, ts.Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
  13360. return unknownType;
  13361. }
  13362. return getDeclaredTypeOfSymbol(symbol);
  13363. }
  13364. function getTypeFromTypeReference(node) {
  13365. var links = getNodeLinks(node);
  13366. if (!links.resolvedType) {
  13367. var typeNameOrExpression = node.kind === 149 ? node.typeName :
  13368. ts.isSupportedExpressionWithTypeArguments(node) ? node.expression :
  13369. undefined;
  13370. var symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, 793056) || unknownSymbol;
  13371. var type = symbol === unknownSymbol ? unknownType :
  13372. symbol.flags & (32 | 64) ? getTypeFromClassOrInterfaceReference(node, symbol) :
  13373. symbol.flags & 524288 ? getTypeFromTypeAliasReference(node, symbol) :
  13374. getTypeFromNonGenericTypeReference(node, symbol);
  13375. links.resolvedSymbol = symbol;
  13376. links.resolvedType = type;
  13377. }
  13378. return links.resolvedType;
  13379. }
  13380. function getTypeFromTypeQueryNode(node) {
  13381. var links = getNodeLinks(node);
  13382. if (!links.resolvedType) {
  13383. links.resolvedType = getWidenedType(checkExpression(node.exprName));
  13384. }
  13385. return links.resolvedType;
  13386. }
  13387. function getTypeOfGlobalSymbol(symbol, arity) {
  13388. function getTypeDeclaration(symbol) {
  13389. var declarations = symbol.declarations;
  13390. for (var _i = 0; _i < declarations.length; _i++) {
  13391. var declaration = declarations[_i];
  13392. switch (declaration.kind) {
  13393. case 212:
  13394. case 213:
  13395. case 215:
  13396. return declaration;
  13397. }
  13398. }
  13399. }
  13400. if (!symbol) {
  13401. return arity ? emptyGenericType : emptyObjectType;
  13402. }
  13403. var type = getDeclaredTypeOfSymbol(symbol);
  13404. if (!(type.flags & 80896)) {
  13405. error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
  13406. return arity ? emptyGenericType : emptyObjectType;
  13407. }
  13408. if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) {
  13409. error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
  13410. return arity ? emptyGenericType : emptyObjectType;
  13411. }
  13412. return type;
  13413. }
  13414. function getGlobalValueSymbol(name) {
  13415. return getGlobalSymbol(name, 107455, ts.Diagnostics.Cannot_find_global_value_0);
  13416. }
  13417. function getGlobalTypeSymbol(name) {
  13418. return getGlobalSymbol(name, 793056, ts.Diagnostics.Cannot_find_global_type_0);
  13419. }
  13420. function getGlobalSymbol(name, meaning, diagnostic) {
  13421. return resolveName(undefined, name, meaning, diagnostic, name);
  13422. }
  13423. function getGlobalType(name, arity) {
  13424. if (arity === void 0) { arity = 0; }
  13425. return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity);
  13426. }
  13427. function tryGetGlobalType(name, arity) {
  13428. if (arity === void 0) { arity = 0; }
  13429. return getTypeOfGlobalSymbol(getGlobalSymbol(name, 793056, undefined), arity);
  13430. }
  13431. function getExportedTypeFromNamespace(namespace, name) {
  13432. var namespaceSymbol = getGlobalSymbol(namespace, 1536, undefined);
  13433. var typeSymbol = namespaceSymbol && getSymbol(namespaceSymbol.exports, name, 793056);
  13434. return typeSymbol && getDeclaredTypeOfSymbol(typeSymbol);
  13435. }
  13436. function getGlobalESSymbolConstructorSymbol() {
  13437. return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"));
  13438. }
  13439. function createTypedPropertyDescriptorType(propertyType) {
  13440. var globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType();
  13441. return globalTypedPropertyDescriptorType !== emptyGenericType
  13442. ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType])
  13443. : emptyObjectType;
  13444. }
  13445. function createTypeFromGenericGlobalType(genericGlobalType, elementType) {
  13446. return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType;
  13447. }
  13448. function createIterableType(elementType) {
  13449. return createTypeFromGenericGlobalType(globalIterableType, elementType);
  13450. }
  13451. function createIterableIteratorType(elementType) {
  13452. return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType);
  13453. }
  13454. function createArrayType(elementType) {
  13455. return createTypeFromGenericGlobalType(globalArrayType, elementType);
  13456. }
  13457. function getTypeFromArrayTypeNode(node) {
  13458. var links = getNodeLinks(node);
  13459. if (!links.resolvedType) {
  13460. links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType));
  13461. }
  13462. return links.resolvedType;
  13463. }
  13464. function createTupleType(elementTypes) {
  13465. var id = getTypeListId(elementTypes);
  13466. var type = tupleTypes[id];
  13467. if (!type) {
  13468. type = tupleTypes[id] = createObjectType(8192 | getPropagatingFlagsOfTypes(elementTypes));
  13469. type.elementTypes = elementTypes;
  13470. }
  13471. return type;
  13472. }
  13473. function getTypeFromTupleTypeNode(node) {
  13474. var links = getNodeLinks(node);
  13475. if (!links.resolvedType) {
  13476. links.resolvedType = createTupleType(ts.map(node.elementTypes, getTypeFromTypeNode));
  13477. }
  13478. return links.resolvedType;
  13479. }
  13480. function addTypeToSet(typeSet, type, typeSetKind) {
  13481. if (type.flags & typeSetKind) {
  13482. addTypesToSet(typeSet, type.types, typeSetKind);
  13483. }
  13484. else if (!ts.contains(typeSet, type)) {
  13485. typeSet.push(type);
  13486. }
  13487. }
  13488. function addTypesToSet(typeSet, types, typeSetKind) {
  13489. for (var _i = 0; _i < types.length; _i++) {
  13490. var type = types[_i];
  13491. addTypeToSet(typeSet, type, typeSetKind);
  13492. }
  13493. }
  13494. function isSubtypeOfAny(candidate, types) {
  13495. for (var i = 0, len = types.length; i < len; i++) {
  13496. if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) {
  13497. return true;
  13498. }
  13499. }
  13500. return false;
  13501. }
  13502. function removeSubtypes(types) {
  13503. var i = types.length;
  13504. while (i > 0) {
  13505. i--;
  13506. if (isSubtypeOfAny(types[i], types)) {
  13507. types.splice(i, 1);
  13508. }
  13509. }
  13510. }
  13511. function containsTypeAny(types) {
  13512. for (var _i = 0; _i < types.length; _i++) {
  13513. var type = types[_i];
  13514. if (isTypeAny(type)) {
  13515. return true;
  13516. }
  13517. }
  13518. return false;
  13519. }
  13520. function removeAllButLast(types, typeToRemove) {
  13521. var i = types.length;
  13522. while (i > 0 && types.length > 1) {
  13523. i--;
  13524. if (types[i] === typeToRemove) {
  13525. types.splice(i, 1);
  13526. }
  13527. }
  13528. }
  13529. function getUnionType(types, noSubtypeReduction) {
  13530. if (types.length === 0) {
  13531. return emptyObjectType;
  13532. }
  13533. var typeSet = [];
  13534. addTypesToSet(typeSet, types, 16384);
  13535. if (containsTypeAny(typeSet)) {
  13536. return anyType;
  13537. }
  13538. if (noSubtypeReduction) {
  13539. removeAllButLast(typeSet, undefinedType);
  13540. removeAllButLast(typeSet, nullType);
  13541. }
  13542. else {
  13543. removeSubtypes(typeSet);
  13544. }
  13545. if (typeSet.length === 1) {
  13546. return typeSet[0];
  13547. }
  13548. var id = getTypeListId(typeSet);
  13549. var type = unionTypes[id];
  13550. if (!type) {
  13551. type = unionTypes[id] = createObjectType(16384 | getPropagatingFlagsOfTypes(typeSet));
  13552. type.types = typeSet;
  13553. }
  13554. return type;
  13555. }
  13556. function getTypeFromUnionTypeNode(node) {
  13557. var links = getNodeLinks(node);
  13558. if (!links.resolvedType) {
  13559. links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), true);
  13560. }
  13561. return links.resolvedType;
  13562. }
  13563. function getIntersectionType(types) {
  13564. if (types.length === 0) {
  13565. return emptyObjectType;
  13566. }
  13567. var typeSet = [];
  13568. addTypesToSet(typeSet, types, 32768);
  13569. if (containsTypeAny(typeSet)) {
  13570. return anyType;
  13571. }
  13572. if (typeSet.length === 1) {
  13573. return typeSet[0];
  13574. }
  13575. var id = getTypeListId(typeSet);
  13576. var type = intersectionTypes[id];
  13577. if (!type) {
  13578. type = intersectionTypes[id] = createObjectType(32768 | getPropagatingFlagsOfTypes(typeSet));
  13579. type.types = typeSet;
  13580. }
  13581. return type;
  13582. }
  13583. function getTypeFromIntersectionTypeNode(node) {
  13584. var links = getNodeLinks(node);
  13585. if (!links.resolvedType) {
  13586. links.resolvedType = getIntersectionType(ts.map(node.types, getTypeFromTypeNode));
  13587. }
  13588. return links.resolvedType;
  13589. }
  13590. function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node) {
  13591. var links = getNodeLinks(node);
  13592. if (!links.resolvedType) {
  13593. links.resolvedType = createObjectType(65536, node.symbol);
  13594. }
  13595. return links.resolvedType;
  13596. }
  13597. function getStringLiteralType(node) {
  13598. if (ts.hasProperty(stringLiteralTypes, node.text)) {
  13599. return stringLiteralTypes[node.text];
  13600. }
  13601. var type = stringLiteralTypes[node.text] = createType(256);
  13602. type.text = ts.getTextOfNode(node);
  13603. return type;
  13604. }
  13605. function getTypeFromStringLiteral(node) {
  13606. var links = getNodeLinks(node);
  13607. if (!links.resolvedType) {
  13608. links.resolvedType = getStringLiteralType(node);
  13609. }
  13610. return links.resolvedType;
  13611. }
  13612. function getTypeFromTypeNode(node) {
  13613. switch (node.kind) {
  13614. case 115:
  13615. return anyType;
  13616. case 128:
  13617. return stringType;
  13618. case 126:
  13619. return numberType;
  13620. case 118:
  13621. return booleanType;
  13622. case 129:
  13623. return esSymbolType;
  13624. case 101:
  13625. return voidType;
  13626. case 9:
  13627. return getTypeFromStringLiteral(node);
  13628. case 149:
  13629. return getTypeFromTypeReference(node);
  13630. case 148:
  13631. return booleanType;
  13632. case 186:
  13633. return getTypeFromTypeReference(node);
  13634. case 152:
  13635. return getTypeFromTypeQueryNode(node);
  13636. case 154:
  13637. return getTypeFromArrayTypeNode(node);
  13638. case 155:
  13639. return getTypeFromTupleTypeNode(node);
  13640. case 156:
  13641. return getTypeFromUnionTypeNode(node);
  13642. case 157:
  13643. return getTypeFromIntersectionTypeNode(node);
  13644. case 158:
  13645. return getTypeFromTypeNode(node.type);
  13646. case 150:
  13647. case 151:
  13648. case 153:
  13649. return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
  13650. case 67:
  13651. case 133:
  13652. var symbol = getSymbolAtLocation(node);
  13653. return symbol && getDeclaredTypeOfSymbol(symbol);
  13654. default:
  13655. return unknownType;
  13656. }
  13657. }
  13658. function instantiateList(items, mapper, instantiator) {
  13659. if (items && items.length) {
  13660. var result = [];
  13661. for (var _i = 0; _i < items.length; _i++) {
  13662. var v = items[_i];
  13663. result.push(instantiator(v, mapper));
  13664. }
  13665. return result;
  13666. }
  13667. return items;
  13668. }
  13669. function createUnaryTypeMapper(source, target) {
  13670. return function (t) { return t === source ? target : t; };
  13671. }
  13672. function createBinaryTypeMapper(source1, target1, source2, target2) {
  13673. return function (t) { return t === source1 ? target1 : t === source2 ? target2 : t; };
  13674. }
  13675. function createTypeMapper(sources, targets) {
  13676. switch (sources.length) {
  13677. case 1: return createUnaryTypeMapper(sources[0], targets[0]);
  13678. case 2: return createBinaryTypeMapper(sources[0], targets[0], sources[1], targets[1]);
  13679. }
  13680. return function (t) {
  13681. for (var i = 0; i < sources.length; i++) {
  13682. if (t === sources[i]) {
  13683. return targets[i];
  13684. }
  13685. }
  13686. return t;
  13687. };
  13688. }
  13689. function createUnaryTypeEraser(source) {
  13690. return function (t) { return t === source ? anyType : t; };
  13691. }
  13692. function createBinaryTypeEraser(source1, source2) {
  13693. return function (t) { return t === source1 || t === source2 ? anyType : t; };
  13694. }
  13695. function createTypeEraser(sources) {
  13696. switch (sources.length) {
  13697. case 1: return createUnaryTypeEraser(sources[0]);
  13698. case 2: return createBinaryTypeEraser(sources[0], sources[1]);
  13699. }
  13700. return function (t) {
  13701. for (var _i = 0; _i < sources.length; _i++) {
  13702. var source = sources[_i];
  13703. if (t === source) {
  13704. return anyType;
  13705. }
  13706. }
  13707. return t;
  13708. };
  13709. }
  13710. function createInferenceMapper(context) {
  13711. var mapper = function (t) {
  13712. for (var i = 0; i < context.typeParameters.length; i++) {
  13713. if (t === context.typeParameters[i]) {
  13714. context.inferences[i].isFixed = true;
  13715. return getInferredType(context, i);
  13716. }
  13717. }
  13718. return t;
  13719. };
  13720. mapper.context = context;
  13721. return mapper;
  13722. }
  13723. function identityMapper(type) {
  13724. return type;
  13725. }
  13726. function combineTypeMappers(mapper1, mapper2) {
  13727. return function (t) { return instantiateType(mapper1(t), mapper2); };
  13728. }
  13729. function instantiateTypeParameter(typeParameter, mapper) {
  13730. var result = createType(512);
  13731. result.symbol = typeParameter.symbol;
  13732. if (typeParameter.constraint) {
  13733. result.constraint = instantiateType(typeParameter.constraint, mapper);
  13734. }
  13735. else {
  13736. result.target = typeParameter;
  13737. result.mapper = mapper;
  13738. }
  13739. return result;
  13740. }
  13741. function instantiateSignature(signature, mapper, eraseTypeParameters) {
  13742. var freshTypeParameters;
  13743. var freshTypePredicate;
  13744. if (signature.typeParameters && !eraseTypeParameters) {
  13745. freshTypeParameters = instantiateList(signature.typeParameters, mapper, instantiateTypeParameter);
  13746. mapper = combineTypeMappers(createTypeMapper(signature.typeParameters, freshTypeParameters), mapper);
  13747. }
  13748. if (signature.typePredicate) {
  13749. freshTypePredicate = {
  13750. parameterName: signature.typePredicate.parameterName,
  13751. parameterIndex: signature.typePredicate.parameterIndex,
  13752. type: instantiateType(signature.typePredicate.type, mapper)
  13753. };
  13754. }
  13755. var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), signature.resolvedReturnType ? instantiateType(signature.resolvedReturnType, mapper) : undefined, freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals);
  13756. result.target = signature;
  13757. result.mapper = mapper;
  13758. return result;
  13759. }
  13760. function instantiateSymbol(symbol, mapper) {
  13761. if (symbol.flags & 16777216) {
  13762. var links = getSymbolLinks(symbol);
  13763. symbol = links.target;
  13764. mapper = combineTypeMappers(links.mapper, mapper);
  13765. }
  13766. var result = createSymbol(16777216 | 67108864 | symbol.flags, symbol.name);
  13767. result.declarations = symbol.declarations;
  13768. result.parent = symbol.parent;
  13769. result.target = symbol;
  13770. result.mapper = mapper;
  13771. if (symbol.valueDeclaration) {
  13772. result.valueDeclaration = symbol.valueDeclaration;
  13773. }
  13774. return result;
  13775. }
  13776. function instantiateAnonymousType(type, mapper) {
  13777. if (mapper.instantiations) {
  13778. var cachedType = mapper.instantiations[type.id];
  13779. if (cachedType) {
  13780. return cachedType;
  13781. }
  13782. }
  13783. else {
  13784. mapper.instantiations = [];
  13785. }
  13786. var result = createObjectType(65536 | 131072, type.symbol);
  13787. result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
  13788. result.members = createSymbolTable(result.properties);
  13789. result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature);
  13790. result.constructSignatures = instantiateList(getSignaturesOfType(type, 1), mapper, instantiateSignature);
  13791. var stringIndexType = getIndexTypeOfType(type, 0);
  13792. var numberIndexType = getIndexTypeOfType(type, 1);
  13793. if (stringIndexType)
  13794. result.stringIndexType = instantiateType(stringIndexType, mapper);
  13795. if (numberIndexType)
  13796. result.numberIndexType = instantiateType(numberIndexType, mapper);
  13797. mapper.instantiations[type.id] = result;
  13798. return result;
  13799. }
  13800. function instantiateType(type, mapper) {
  13801. if (mapper !== identityMapper) {
  13802. if (type.flags & 512) {
  13803. return mapper(type);
  13804. }
  13805. if (type.flags & 65536) {
  13806. return type.symbol && type.symbol.flags & (16 | 8192 | 32 | 2048 | 4096) ?
  13807. instantiateAnonymousType(type, mapper) : type;
  13808. }
  13809. if (type.flags & 4096) {
  13810. return createTypeReference(type.target, instantiateList(type.typeArguments, mapper, instantiateType));
  13811. }
  13812. if (type.flags & 8192) {
  13813. return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType));
  13814. }
  13815. if (type.flags & 16384) {
  13816. return getUnionType(instantiateList(type.types, mapper, instantiateType), true);
  13817. }
  13818. if (type.flags & 32768) {
  13819. return getIntersectionType(instantiateList(type.types, mapper, instantiateType));
  13820. }
  13821. }
  13822. return type;
  13823. }
  13824. function isContextSensitive(node) {
  13825. ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node));
  13826. switch (node.kind) {
  13827. case 171:
  13828. case 172:
  13829. return isContextSensitiveFunctionLikeDeclaration(node);
  13830. case 163:
  13831. return ts.forEach(node.properties, isContextSensitive);
  13832. case 162:
  13833. return ts.forEach(node.elements, isContextSensitive);
  13834. case 180:
  13835. return isContextSensitive(node.whenTrue) ||
  13836. isContextSensitive(node.whenFalse);
  13837. case 179:
  13838. return node.operatorToken.kind === 51 &&
  13839. (isContextSensitive(node.left) || isContextSensitive(node.right));
  13840. case 243:
  13841. return isContextSensitive(node.initializer);
  13842. case 141:
  13843. case 140:
  13844. return isContextSensitiveFunctionLikeDeclaration(node);
  13845. case 170:
  13846. return isContextSensitive(node.expression);
  13847. }
  13848. return false;
  13849. }
  13850. function isContextSensitiveFunctionLikeDeclaration(node) {
  13851. return !node.typeParameters && node.parameters.length && !ts.forEach(node.parameters, function (p) { return p.type; });
  13852. }
  13853. function getTypeWithoutSignatures(type) {
  13854. if (type.flags & 80896) {
  13855. var resolved = resolveStructuredTypeMembers(type);
  13856. if (resolved.constructSignatures.length) {
  13857. var result = createObjectType(65536, type.symbol);
  13858. result.members = resolved.members;
  13859. result.properties = resolved.properties;
  13860. result.callSignatures = emptyArray;
  13861. result.constructSignatures = emptyArray;
  13862. type = result;
  13863. }
  13864. }
  13865. return type;
  13866. }
  13867. function isTypeIdenticalTo(source, target) {
  13868. return checkTypeRelatedTo(source, target, identityRelation, undefined);
  13869. }
  13870. function compareTypes(source, target) {
  13871. return checkTypeRelatedTo(source, target, identityRelation, undefined) ? -1 : 0;
  13872. }
  13873. function isTypeSubtypeOf(source, target) {
  13874. return checkTypeSubtypeOf(source, target, undefined);
  13875. }
  13876. function isTypeAssignableTo(source, target) {
  13877. return checkTypeAssignableTo(source, target, undefined);
  13878. }
  13879. function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) {
  13880. return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain);
  13881. }
  13882. function checkTypeAssignableTo(source, target, errorNode, headMessage, containingMessageChain) {
  13883. return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain);
  13884. }
  13885. function isSignatureAssignableTo(source, target) {
  13886. var sourceType = getOrCreateTypeFromSignature(source);
  13887. var targetType = getOrCreateTypeFromSignature(target);
  13888. return checkTypeRelatedTo(sourceType, targetType, assignableRelation, undefined);
  13889. }
  13890. function checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain) {
  13891. var errorInfo;
  13892. var sourceStack;
  13893. var targetStack;
  13894. var maybeStack;
  13895. var expandingFlags;
  13896. var depth = 0;
  13897. var overflow = false;
  13898. var elaborateErrors = false;
  13899. ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
  13900. var result = isRelatedTo(source, target, errorNode !== undefined, headMessage);
  13901. if (overflow) {
  13902. error(errorNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
  13903. }
  13904. else if (errorInfo) {
  13905. if (errorInfo.next === undefined) {
  13906. errorInfo = undefined;
  13907. elaborateErrors = true;
  13908. isRelatedTo(source, target, errorNode !== undefined, headMessage);
  13909. }
  13910. if (containingMessageChain) {
  13911. errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
  13912. }
  13913. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
  13914. }
  13915. return result !== 0;
  13916. function reportError(message, arg0, arg1, arg2) {
  13917. errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
  13918. }
  13919. function reportRelationError(message, source, target) {
  13920. var sourceType = typeToString(source);
  13921. var targetType = typeToString(target);
  13922. if (sourceType === targetType) {
  13923. sourceType = typeToString(source, undefined, 128);
  13924. targetType = typeToString(target, undefined, 128);
  13925. }
  13926. reportError(message || ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType);
  13927. }
  13928. function isRelatedTo(source, target, reportErrors, headMessage) {
  13929. var result;
  13930. if (source === target)
  13931. return -1;
  13932. if (relation === identityRelation) {
  13933. return isIdenticalTo(source, target);
  13934. }
  13935. if (isTypeAny(target))
  13936. return -1;
  13937. if (source === undefinedType)
  13938. return -1;
  13939. if (source === nullType && target !== undefinedType)
  13940. return -1;
  13941. if (source.flags & 128 && target === numberType)
  13942. return -1;
  13943. if (source.flags & 256 && target === stringType)
  13944. return -1;
  13945. if (relation === assignableRelation) {
  13946. if (isTypeAny(source))
  13947. return -1;
  13948. if (source === numberType && target.flags & 128)
  13949. return -1;
  13950. }
  13951. if (source.flags & 1048576) {
  13952. if (hasExcessProperties(source, target, reportErrors)) {
  13953. if (reportErrors) {
  13954. reportRelationError(headMessage, source, target);
  13955. }
  13956. return 0;
  13957. }
  13958. source = getRegularTypeOfObjectLiteral(source);
  13959. }
  13960. var saveErrorInfo = errorInfo;
  13961. if (source.flags & 16384) {
  13962. if (result = eachTypeRelatedToType(source, target, reportErrors)) {
  13963. return result;
  13964. }
  13965. }
  13966. else if (target.flags & 32768) {
  13967. if (result = typeRelatedToEachType(source, target, reportErrors)) {
  13968. return result;
  13969. }
  13970. }
  13971. else {
  13972. if (source.flags & 32768) {
  13973. if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & 16384))) {
  13974. return result;
  13975. }
  13976. }
  13977. if (target.flags & 16384) {
  13978. if (result = typeRelatedToSomeType(source, target, reportErrors)) {
  13979. return result;
  13980. }
  13981. }
  13982. }
  13983. if (source.flags & 512) {
  13984. var constraint = getConstraintOfTypeParameter(source);
  13985. if (!constraint || constraint.flags & 1) {
  13986. constraint = emptyObjectType;
  13987. }
  13988. var reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
  13989. if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
  13990. errorInfo = saveErrorInfo;
  13991. return result;
  13992. }
  13993. }
  13994. else {
  13995. if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  13996. if (result = typesRelatedTo(source.typeArguments, target.typeArguments, reportErrors)) {
  13997. return result;
  13998. }
  13999. }
  14000. var apparentType = getApparentType(source);
  14001. if (apparentType.flags & (80896 | 32768) && target.flags & 80896) {
  14002. var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
  14003. if (result = objectTypeRelatedTo(apparentType, target, reportStructuralErrors)) {
  14004. errorInfo = saveErrorInfo;
  14005. return result;
  14006. }
  14007. }
  14008. }
  14009. if (reportErrors) {
  14010. reportRelationError(headMessage, source, target);
  14011. }
  14012. return 0;
  14013. }
  14014. function isIdenticalTo(source, target) {
  14015. var result;
  14016. if (source.flags & 80896 && target.flags & 80896) {
  14017. if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  14018. if (result = typesRelatedTo(source.typeArguments, target.typeArguments, false)) {
  14019. return result;
  14020. }
  14021. }
  14022. return objectTypeRelatedTo(source, target, false);
  14023. }
  14024. if (source.flags & 512 && target.flags & 512) {
  14025. return typeParameterIdenticalTo(source, target);
  14026. }
  14027. if (source.flags & 16384 && target.flags & 16384 ||
  14028. source.flags & 32768 && target.flags & 32768) {
  14029. if (result = eachTypeRelatedToSomeType(source, target)) {
  14030. if (result &= eachTypeRelatedToSomeType(target, source)) {
  14031. return result;
  14032. }
  14033. }
  14034. }
  14035. return 0;
  14036. }
  14037. function isKnownProperty(type, name) {
  14038. if (type.flags & 80896) {
  14039. var resolved = resolveStructuredTypeMembers(type);
  14040. if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) ||
  14041. resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) {
  14042. return true;
  14043. }
  14044. return false;
  14045. }
  14046. if (type.flags & 49152) {
  14047. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  14048. var t = _a[_i];
  14049. if (isKnownProperty(t, name)) {
  14050. return true;
  14051. }
  14052. }
  14053. return false;
  14054. }
  14055. return true;
  14056. }
  14057. function hasExcessProperties(source, target, reportErrors) {
  14058. for (var _i = 0, _a = getPropertiesOfObjectType(source); _i < _a.length; _i++) {
  14059. var prop = _a[_i];
  14060. if (!isKnownProperty(target, prop.name)) {
  14061. if (reportErrors) {
  14062. errorNode = prop.valueDeclaration;
  14063. reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
  14064. }
  14065. return true;
  14066. }
  14067. }
  14068. }
  14069. function eachTypeRelatedToSomeType(source, target) {
  14070. var result = -1;
  14071. var sourceTypes = source.types;
  14072. for (var _i = 0; _i < sourceTypes.length; _i++) {
  14073. var sourceType = sourceTypes[_i];
  14074. var related = typeRelatedToSomeType(sourceType, target, false);
  14075. if (!related) {
  14076. return 0;
  14077. }
  14078. result &= related;
  14079. }
  14080. return result;
  14081. }
  14082. function typeRelatedToSomeType(source, target, reportErrors) {
  14083. var targetTypes = target.types;
  14084. for (var i = 0, len = targetTypes.length; i < len; i++) {
  14085. var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1);
  14086. if (related) {
  14087. return related;
  14088. }
  14089. }
  14090. return 0;
  14091. }
  14092. function typeRelatedToEachType(source, target, reportErrors) {
  14093. var result = -1;
  14094. var targetTypes = target.types;
  14095. for (var _i = 0; _i < targetTypes.length; _i++) {
  14096. var targetType = targetTypes[_i];
  14097. var related = isRelatedTo(source, targetType, reportErrors);
  14098. if (!related) {
  14099. return 0;
  14100. }
  14101. result &= related;
  14102. }
  14103. return result;
  14104. }
  14105. function someTypeRelatedToType(source, target, reportErrors) {
  14106. var sourceTypes = source.types;
  14107. for (var i = 0, len = sourceTypes.length; i < len; i++) {
  14108. var related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1);
  14109. if (related) {
  14110. return related;
  14111. }
  14112. }
  14113. return 0;
  14114. }
  14115. function eachTypeRelatedToType(source, target, reportErrors) {
  14116. var result = -1;
  14117. var sourceTypes = source.types;
  14118. for (var _i = 0; _i < sourceTypes.length; _i++) {
  14119. var sourceType = sourceTypes[_i];
  14120. var related = isRelatedTo(sourceType, target, reportErrors);
  14121. if (!related) {
  14122. return 0;
  14123. }
  14124. result &= related;
  14125. }
  14126. return result;
  14127. }
  14128. function typesRelatedTo(sources, targets, reportErrors) {
  14129. var result = -1;
  14130. for (var i = 0, len = sources.length; i < len; i++) {
  14131. var related = isRelatedTo(sources[i], targets[i], reportErrors);
  14132. if (!related) {
  14133. return 0;
  14134. }
  14135. result &= related;
  14136. }
  14137. return result;
  14138. }
  14139. function typeParameterIdenticalTo(source, target) {
  14140. if (source.symbol.name !== target.symbol.name) {
  14141. return 0;
  14142. }
  14143. if (source.constraint === target.constraint) {
  14144. return -1;
  14145. }
  14146. if (source.constraint === noConstraintType || target.constraint === noConstraintType) {
  14147. return 0;
  14148. }
  14149. return isIdenticalTo(source.constraint, target.constraint);
  14150. }
  14151. function objectTypeRelatedTo(source, target, reportErrors) {
  14152. if (overflow) {
  14153. return 0;
  14154. }
  14155. var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
  14156. var related = relation[id];
  14157. if (related !== undefined) {
  14158. if (!elaborateErrors || (related === 3)) {
  14159. return related === 1 ? -1 : 0;
  14160. }
  14161. }
  14162. if (depth > 0) {
  14163. for (var i = 0; i < depth; i++) {
  14164. if (maybeStack[i][id]) {
  14165. return 1;
  14166. }
  14167. }
  14168. if (depth === 100) {
  14169. overflow = true;
  14170. return 0;
  14171. }
  14172. }
  14173. else {
  14174. sourceStack = [];
  14175. targetStack = [];
  14176. maybeStack = [];
  14177. expandingFlags = 0;
  14178. }
  14179. sourceStack[depth] = source;
  14180. targetStack[depth] = target;
  14181. maybeStack[depth] = {};
  14182. maybeStack[depth][id] = 1;
  14183. depth++;
  14184. var saveExpandingFlags = expandingFlags;
  14185. if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth))
  14186. expandingFlags |= 1;
  14187. if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth))
  14188. expandingFlags |= 2;
  14189. var result;
  14190. if (expandingFlags === 3) {
  14191. result = 1;
  14192. }
  14193. else {
  14194. result = propertiesRelatedTo(source, target, reportErrors);
  14195. if (result) {
  14196. result &= signaturesRelatedTo(source, target, 0, reportErrors);
  14197. if (result) {
  14198. result &= signaturesRelatedTo(source, target, 1, reportErrors);
  14199. if (result) {
  14200. result &= stringIndexTypesRelatedTo(source, target, reportErrors);
  14201. if (result) {
  14202. result &= numberIndexTypesRelatedTo(source, target, reportErrors);
  14203. }
  14204. }
  14205. }
  14206. }
  14207. }
  14208. expandingFlags = saveExpandingFlags;
  14209. depth--;
  14210. if (result) {
  14211. var maybeCache = maybeStack[depth];
  14212. var destinationCache = (result === -1 || depth === 0) ? relation : maybeStack[depth - 1];
  14213. ts.copyMap(maybeCache, destinationCache);
  14214. }
  14215. else {
  14216. relation[id] = reportErrors ? 3 : 2;
  14217. }
  14218. return result;
  14219. }
  14220. function propertiesRelatedTo(source, target, reportErrors) {
  14221. if (relation === identityRelation) {
  14222. return propertiesIdenticalTo(source, target);
  14223. }
  14224. var result = -1;
  14225. var properties = getPropertiesOfObjectType(target);
  14226. var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 524288);
  14227. for (var _i = 0; _i < properties.length; _i++) {
  14228. var targetProp = properties[_i];
  14229. var sourceProp = getPropertyOfType(source, targetProp.name);
  14230. if (sourceProp !== targetProp) {
  14231. if (!sourceProp) {
  14232. if (!(targetProp.flags & 536870912) || requireOptionalProperties) {
  14233. if (reportErrors) {
  14234. reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source));
  14235. }
  14236. return 0;
  14237. }
  14238. }
  14239. else if (!(targetProp.flags & 134217728)) {
  14240. var sourcePropFlags = getDeclarationFlagsFromSymbol(sourceProp);
  14241. var targetPropFlags = getDeclarationFlagsFromSymbol(targetProp);
  14242. if (sourcePropFlags & 32 || targetPropFlags & 32) {
  14243. if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
  14244. if (reportErrors) {
  14245. if (sourcePropFlags & 32 && targetPropFlags & 32) {
  14246. reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp));
  14247. }
  14248. else {
  14249. 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));
  14250. }
  14251. }
  14252. return 0;
  14253. }
  14254. }
  14255. else if (targetPropFlags & 64) {
  14256. var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32;
  14257. var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined;
  14258. var targetClass = getDeclaredTypeOfSymbol(targetProp.parent);
  14259. if (!sourceClass || !hasBaseType(sourceClass, targetClass)) {
  14260. if (reportErrors) {
  14261. reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass));
  14262. }
  14263. return 0;
  14264. }
  14265. }
  14266. else if (sourcePropFlags & 64) {
  14267. if (reportErrors) {
  14268. reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target));
  14269. }
  14270. return 0;
  14271. }
  14272. var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
  14273. if (!related) {
  14274. if (reportErrors) {
  14275. reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));
  14276. }
  14277. return 0;
  14278. }
  14279. result &= related;
  14280. if (sourceProp.flags & 536870912 && !(targetProp.flags & 536870912)) {
  14281. if (reportErrors) {
  14282. reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target));
  14283. }
  14284. return 0;
  14285. }
  14286. }
  14287. }
  14288. }
  14289. return result;
  14290. }
  14291. function propertiesIdenticalTo(source, target) {
  14292. if (!(source.flags & 80896 && target.flags & 80896)) {
  14293. return 0;
  14294. }
  14295. var sourceProperties = getPropertiesOfObjectType(source);
  14296. var targetProperties = getPropertiesOfObjectType(target);
  14297. if (sourceProperties.length !== targetProperties.length) {
  14298. return 0;
  14299. }
  14300. var result = -1;
  14301. for (var _i = 0; _i < sourceProperties.length; _i++) {
  14302. var sourceProp = sourceProperties[_i];
  14303. var targetProp = getPropertyOfObjectType(target, sourceProp.name);
  14304. if (!targetProp) {
  14305. return 0;
  14306. }
  14307. var related = compareProperties(sourceProp, targetProp, isRelatedTo);
  14308. if (!related) {
  14309. return 0;
  14310. }
  14311. result &= related;
  14312. }
  14313. return result;
  14314. }
  14315. function signaturesRelatedTo(source, target, kind, reportErrors) {
  14316. if (relation === identityRelation) {
  14317. return signaturesIdenticalTo(source, target, kind);
  14318. }
  14319. if (target === anyFunctionType || source === anyFunctionType) {
  14320. return -1;
  14321. }
  14322. var sourceSignatures = getSignaturesOfType(source, kind);
  14323. var targetSignatures = getSignaturesOfType(target, kind);
  14324. var result = -1;
  14325. var saveErrorInfo = errorInfo;
  14326. if (kind === 1) {
  14327. var sourceSig = sourceSignatures[0];
  14328. var targetSig = targetSignatures[0];
  14329. result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig);
  14330. if (result !== -1) {
  14331. return result;
  14332. }
  14333. }
  14334. outer: for (var _i = 0; _i < targetSignatures.length; _i++) {
  14335. var t = targetSignatures[_i];
  14336. if (!t.hasStringLiterals || target.flags & 262144) {
  14337. var localErrors = reportErrors;
  14338. var checkedAbstractAssignability = false;
  14339. for (var _a = 0; _a < sourceSignatures.length; _a++) {
  14340. var s = sourceSignatures[_a];
  14341. if (!s.hasStringLiterals || source.flags & 262144) {
  14342. var related = signatureRelatedTo(s, t, localErrors);
  14343. if (related) {
  14344. result &= related;
  14345. errorInfo = saveErrorInfo;
  14346. continue outer;
  14347. }
  14348. localErrors = false;
  14349. }
  14350. }
  14351. return 0;
  14352. }
  14353. }
  14354. return result;
  14355. function abstractSignatureRelatedTo(source, sourceSig, target, targetSig) {
  14356. if (sourceSig && targetSig) {
  14357. var sourceDecl = source.symbol && ts.getDeclarationOfKind(source.symbol, 212);
  14358. var targetDecl = target.symbol && ts.getDeclarationOfKind(target.symbol, 212);
  14359. if (!sourceDecl) {
  14360. return -1;
  14361. }
  14362. var sourceErasedSignature = getErasedSignature(sourceSig);
  14363. var targetErasedSignature = getErasedSignature(targetSig);
  14364. var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature);
  14365. var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature);
  14366. var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && ts.getDeclarationOfKind(sourceReturnType.symbol, 212);
  14367. var targetReturnDecl = targetReturnType && targetReturnType.symbol && ts.getDeclarationOfKind(targetReturnType.symbol, 212);
  14368. var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 256;
  14369. var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 256;
  14370. if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) {
  14371. if (reportErrors) {
  14372. reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type);
  14373. }
  14374. return 0;
  14375. }
  14376. }
  14377. return -1;
  14378. }
  14379. }
  14380. function signatureRelatedTo(source, target, reportErrors) {
  14381. if (source === target) {
  14382. return -1;
  14383. }
  14384. if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) {
  14385. return 0;
  14386. }
  14387. var sourceMax = source.parameters.length;
  14388. var targetMax = target.parameters.length;
  14389. var checkCount;
  14390. if (source.hasRestParameter && target.hasRestParameter) {
  14391. checkCount = sourceMax > targetMax ? sourceMax : targetMax;
  14392. sourceMax--;
  14393. targetMax--;
  14394. }
  14395. else if (source.hasRestParameter) {
  14396. sourceMax--;
  14397. checkCount = targetMax;
  14398. }
  14399. else if (target.hasRestParameter) {
  14400. targetMax--;
  14401. checkCount = sourceMax;
  14402. }
  14403. else {
  14404. checkCount = sourceMax < targetMax ? sourceMax : targetMax;
  14405. }
  14406. source = getErasedSignature(source);
  14407. target = getErasedSignature(target);
  14408. var result = -1;
  14409. for (var i = 0; i < checkCount; i++) {
  14410. var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
  14411. var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
  14412. var saveErrorInfo = errorInfo;
  14413. var related = isRelatedTo(s, t, reportErrors);
  14414. if (!related) {
  14415. related = isRelatedTo(t, s, false);
  14416. if (!related) {
  14417. if (reportErrors) {
  14418. 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);
  14419. }
  14420. return 0;
  14421. }
  14422. errorInfo = saveErrorInfo;
  14423. }
  14424. result &= related;
  14425. }
  14426. if (source.typePredicate && target.typePredicate) {
  14427. var hasDifferentParameterIndex = source.typePredicate.parameterIndex !== target.typePredicate.parameterIndex;
  14428. var hasDifferentTypes;
  14429. if (hasDifferentParameterIndex ||
  14430. (hasDifferentTypes = !isTypeIdenticalTo(source.typePredicate.type, target.typePredicate.type))) {
  14431. if (reportErrors) {
  14432. var sourceParamText = source.typePredicate.parameterName;
  14433. var targetParamText = target.typePredicate.parameterName;
  14434. var sourceTypeText = typeToString(source.typePredicate.type);
  14435. var targetTypeText = typeToString(target.typePredicate.type);
  14436. if (hasDifferentParameterIndex) {
  14437. reportError(ts.Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, sourceParamText, targetParamText);
  14438. }
  14439. else if (hasDifferentTypes) {
  14440. reportError(ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceTypeText, targetTypeText);
  14441. }
  14442. reportError(ts.Diagnostics.Type_predicate_0_is_not_assignable_to_1, sourceParamText + " is " + sourceTypeText, targetParamText + " is " + targetTypeText);
  14443. }
  14444. return 0;
  14445. }
  14446. }
  14447. else if (!source.typePredicate && target.typePredicate) {
  14448. if (reportErrors) {
  14449. reportError(ts.Diagnostics.Signature_0_must_have_a_type_predicate, signatureToString(source));
  14450. }
  14451. return 0;
  14452. }
  14453. var targetReturnType = getReturnTypeOfSignature(target);
  14454. if (targetReturnType === voidType)
  14455. return result;
  14456. var sourceReturnType = getReturnTypeOfSignature(source);
  14457. return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors);
  14458. }
  14459. function signaturesIdenticalTo(source, target, kind) {
  14460. var sourceSignatures = getSignaturesOfType(source, kind);
  14461. var targetSignatures = getSignaturesOfType(target, kind);
  14462. if (sourceSignatures.length !== targetSignatures.length) {
  14463. return 0;
  14464. }
  14465. var result = -1;
  14466. for (var i = 0, len = sourceSignatures.length; i < len; ++i) {
  14467. var related = compareSignatures(sourceSignatures[i], targetSignatures[i], false, false, isRelatedTo);
  14468. if (!related) {
  14469. return 0;
  14470. }
  14471. result &= related;
  14472. }
  14473. return result;
  14474. }
  14475. function stringIndexTypesRelatedTo(source, target, reportErrors) {
  14476. if (relation === identityRelation) {
  14477. return indexTypesIdenticalTo(0, source, target);
  14478. }
  14479. var targetType = getIndexTypeOfType(target, 0);
  14480. if (targetType && !(targetType.flags & 1)) {
  14481. var sourceType = getIndexTypeOfType(source, 0);
  14482. if (!sourceType) {
  14483. if (reportErrors) {
  14484. reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
  14485. }
  14486. return 0;
  14487. }
  14488. var related = isRelatedTo(sourceType, targetType, reportErrors);
  14489. if (!related) {
  14490. if (reportErrors) {
  14491. reportError(ts.Diagnostics.Index_signatures_are_incompatible);
  14492. }
  14493. return 0;
  14494. }
  14495. return related;
  14496. }
  14497. return -1;
  14498. }
  14499. function numberIndexTypesRelatedTo(source, target, reportErrors) {
  14500. if (relation === identityRelation) {
  14501. return indexTypesIdenticalTo(1, source, target);
  14502. }
  14503. var targetType = getIndexTypeOfType(target, 1);
  14504. if (targetType && !(targetType.flags & 1)) {
  14505. var sourceStringType = getIndexTypeOfType(source, 0);
  14506. var sourceNumberType = getIndexTypeOfType(source, 1);
  14507. if (!(sourceStringType || sourceNumberType)) {
  14508. if (reportErrors) {
  14509. reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
  14510. }
  14511. return 0;
  14512. }
  14513. var related;
  14514. if (sourceStringType && sourceNumberType) {
  14515. related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
  14516. }
  14517. else {
  14518. related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
  14519. }
  14520. if (!related) {
  14521. if (reportErrors) {
  14522. reportError(ts.Diagnostics.Index_signatures_are_incompatible);
  14523. }
  14524. return 0;
  14525. }
  14526. return related;
  14527. }
  14528. return -1;
  14529. }
  14530. function indexTypesIdenticalTo(indexKind, source, target) {
  14531. var targetType = getIndexTypeOfType(target, indexKind);
  14532. var sourceType = getIndexTypeOfType(source, indexKind);
  14533. if (!sourceType && !targetType) {
  14534. return -1;
  14535. }
  14536. if (sourceType && targetType) {
  14537. return isRelatedTo(sourceType, targetType);
  14538. }
  14539. return 0;
  14540. }
  14541. }
  14542. function isDeeplyNestedGeneric(type, stack, depth) {
  14543. if (type.flags & (4096 | 131072) && depth >= 5) {
  14544. var symbol = type.symbol;
  14545. var count = 0;
  14546. for (var i = 0; i < depth; i++) {
  14547. var t = stack[i];
  14548. if (t.flags & (4096 | 131072) && t.symbol === symbol) {
  14549. count++;
  14550. if (count >= 5)
  14551. return true;
  14552. }
  14553. }
  14554. }
  14555. return false;
  14556. }
  14557. function isPropertyIdenticalTo(sourceProp, targetProp) {
  14558. return compareProperties(sourceProp, targetProp, compareTypes) !== 0;
  14559. }
  14560. function compareProperties(sourceProp, targetProp, compareTypes) {
  14561. if (sourceProp === targetProp) {
  14562. return -1;
  14563. }
  14564. var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (32 | 64);
  14565. var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (32 | 64);
  14566. if (sourcePropAccessibility !== targetPropAccessibility) {
  14567. return 0;
  14568. }
  14569. if (sourcePropAccessibility) {
  14570. if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) {
  14571. return 0;
  14572. }
  14573. }
  14574. else {
  14575. if ((sourceProp.flags & 536870912) !== (targetProp.flags & 536870912)) {
  14576. return 0;
  14577. }
  14578. }
  14579. return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
  14580. }
  14581. function compareSignatures(source, target, partialMatch, ignoreReturnTypes, compareTypes) {
  14582. if (source === target) {
  14583. return -1;
  14584. }
  14585. if (source.parameters.length !== target.parameters.length ||
  14586. source.minArgumentCount !== target.minArgumentCount ||
  14587. source.hasRestParameter !== target.hasRestParameter) {
  14588. if (!partialMatch ||
  14589. source.parameters.length < target.parameters.length && !source.hasRestParameter ||
  14590. source.minArgumentCount > target.minArgumentCount) {
  14591. return 0;
  14592. }
  14593. }
  14594. var result = -1;
  14595. if (source.typeParameters && target.typeParameters) {
  14596. if (source.typeParameters.length !== target.typeParameters.length) {
  14597. return 0;
  14598. }
  14599. for (var i = 0, len = source.typeParameters.length; i < len; ++i) {
  14600. var related = compareTypes(source.typeParameters[i], target.typeParameters[i]);
  14601. if (!related) {
  14602. return 0;
  14603. }
  14604. result &= related;
  14605. }
  14606. }
  14607. else if (source.typeParameters || target.typeParameters) {
  14608. return 0;
  14609. }
  14610. source = getErasedSignature(source);
  14611. target = getErasedSignature(target);
  14612. var sourceLen = source.parameters.length;
  14613. var targetLen = target.parameters.length;
  14614. for (var i = 0; i < targetLen; i++) {
  14615. var s = source.hasRestParameter && i === sourceLen - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
  14616. var t = target.hasRestParameter && i === targetLen - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
  14617. var related = compareTypes(s, t);
  14618. if (!related) {
  14619. return 0;
  14620. }
  14621. result &= related;
  14622. }
  14623. if (!ignoreReturnTypes) {
  14624. result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
  14625. }
  14626. return result;
  14627. }
  14628. function isSupertypeOfEach(candidate, types) {
  14629. for (var _i = 0; _i < types.length; _i++) {
  14630. var type = types[_i];
  14631. if (candidate !== type && !isTypeSubtypeOf(type, candidate))
  14632. return false;
  14633. }
  14634. return true;
  14635. }
  14636. function getCommonSupertype(types) {
  14637. return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; });
  14638. }
  14639. function reportNoCommonSupertypeError(types, errorLocation, errorMessageChainHead) {
  14640. var bestSupertype;
  14641. var bestSupertypeDownfallType;
  14642. var bestSupertypeScore = 0;
  14643. for (var i = 0; i < types.length; i++) {
  14644. var score = 0;
  14645. var downfallType = undefined;
  14646. for (var j = 0; j < types.length; j++) {
  14647. if (isTypeSubtypeOf(types[j], types[i])) {
  14648. score++;
  14649. }
  14650. else if (!downfallType) {
  14651. downfallType = types[j];
  14652. }
  14653. }
  14654. ts.Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType");
  14655. if (score > bestSupertypeScore) {
  14656. bestSupertype = types[i];
  14657. bestSupertypeDownfallType = downfallType;
  14658. bestSupertypeScore = score;
  14659. }
  14660. if (bestSupertypeScore === types.length - 1) {
  14661. break;
  14662. }
  14663. }
  14664. 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);
  14665. }
  14666. function isArrayType(type) {
  14667. return type.flags & 4096 && type.target === globalArrayType;
  14668. }
  14669. function isArrayLikeType(type) {
  14670. return !(type.flags & (32 | 64)) && isTypeAssignableTo(type, anyArrayType);
  14671. }
  14672. function isTupleLikeType(type) {
  14673. return !!getPropertyOfType(type, "0");
  14674. }
  14675. function isTupleType(type) {
  14676. return !!(type.flags & 8192);
  14677. }
  14678. function getRegularTypeOfObjectLiteral(type) {
  14679. if (type.flags & 1048576) {
  14680. var regularType = type.regularType;
  14681. if (!regularType) {
  14682. regularType = createType(type.flags & ~1048576);
  14683. regularType.symbol = type.symbol;
  14684. regularType.members = type.members;
  14685. regularType.properties = type.properties;
  14686. regularType.callSignatures = type.callSignatures;
  14687. regularType.constructSignatures = type.constructSignatures;
  14688. regularType.stringIndexType = type.stringIndexType;
  14689. regularType.numberIndexType = type.numberIndexType;
  14690. }
  14691. return regularType;
  14692. }
  14693. return type;
  14694. }
  14695. function getWidenedTypeOfObjectLiteral(type) {
  14696. var properties = getPropertiesOfObjectType(type);
  14697. var members = {};
  14698. ts.forEach(properties, function (p) {
  14699. var propType = getTypeOfSymbol(p);
  14700. var widenedType = getWidenedType(propType);
  14701. if (propType !== widenedType) {
  14702. var symbol = createSymbol(p.flags | 67108864, p.name);
  14703. symbol.declarations = p.declarations;
  14704. symbol.parent = p.parent;
  14705. symbol.type = widenedType;
  14706. symbol.target = p;
  14707. if (p.valueDeclaration)
  14708. symbol.valueDeclaration = p.valueDeclaration;
  14709. p = symbol;
  14710. }
  14711. members[p.name] = p;
  14712. });
  14713. var stringIndexType = getIndexTypeOfType(type, 0);
  14714. var numberIndexType = getIndexTypeOfType(type, 1);
  14715. if (stringIndexType)
  14716. stringIndexType = getWidenedType(stringIndexType);
  14717. if (numberIndexType)
  14718. numberIndexType = getWidenedType(numberIndexType);
  14719. return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType);
  14720. }
  14721. function getWidenedType(type) {
  14722. if (type.flags & 6291456) {
  14723. if (type.flags & (32 | 64)) {
  14724. return anyType;
  14725. }
  14726. if (type.flags & 524288) {
  14727. return getWidenedTypeOfObjectLiteral(type);
  14728. }
  14729. if (type.flags & 16384) {
  14730. return getUnionType(ts.map(type.types, getWidenedType), true);
  14731. }
  14732. if (isArrayType(type)) {
  14733. return createArrayType(getWidenedType(type.typeArguments[0]));
  14734. }
  14735. if (isTupleType(type)) {
  14736. return createTupleType(ts.map(type.elementTypes, getWidenedType));
  14737. }
  14738. }
  14739. return type;
  14740. }
  14741. function reportWideningErrorsInType(type) {
  14742. var errorReported = false;
  14743. if (type.flags & 16384) {
  14744. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  14745. var t = _a[_i];
  14746. if (reportWideningErrorsInType(t)) {
  14747. errorReported = true;
  14748. }
  14749. }
  14750. }
  14751. if (isArrayType(type)) {
  14752. return reportWideningErrorsInType(type.typeArguments[0]);
  14753. }
  14754. if (isTupleType(type)) {
  14755. for (var _b = 0, _c = type.elementTypes; _b < _c.length; _b++) {
  14756. var t = _c[_b];
  14757. if (reportWideningErrorsInType(t)) {
  14758. errorReported = true;
  14759. }
  14760. }
  14761. }
  14762. if (type.flags & 524288) {
  14763. for (var _d = 0, _e = getPropertiesOfObjectType(type); _d < _e.length; _d++) {
  14764. var p = _e[_d];
  14765. var t = getTypeOfSymbol(p);
  14766. if (t.flags & 2097152) {
  14767. if (!reportWideningErrorsInType(t)) {
  14768. error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t)));
  14769. }
  14770. errorReported = true;
  14771. }
  14772. }
  14773. }
  14774. return errorReported;
  14775. }
  14776. function reportImplicitAnyError(declaration, type) {
  14777. var typeAsString = typeToString(getWidenedType(type));
  14778. var diagnostic;
  14779. switch (declaration.kind) {
  14780. case 139:
  14781. case 138:
  14782. diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type;
  14783. break;
  14784. case 136:
  14785. diagnostic = declaration.dotDotDotToken ?
  14786. ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type :
  14787. ts.Diagnostics.Parameter_0_implicitly_has_an_1_type;
  14788. break;
  14789. case 211:
  14790. case 141:
  14791. case 140:
  14792. case 143:
  14793. case 144:
  14794. case 171:
  14795. case 172:
  14796. if (!declaration.name) {
  14797. error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString);
  14798. return;
  14799. }
  14800. diagnostic = ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
  14801. break;
  14802. default:
  14803. diagnostic = ts.Diagnostics.Variable_0_implicitly_has_an_1_type;
  14804. }
  14805. error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString);
  14806. }
  14807. function reportErrorsFromWidening(declaration, type) {
  14808. if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 2097152) {
  14809. if (!reportWideningErrorsInType(type)) {
  14810. reportImplicitAnyError(declaration, type);
  14811. }
  14812. }
  14813. }
  14814. function forEachMatchingParameterType(source, target, callback) {
  14815. var sourceMax = source.parameters.length;
  14816. var targetMax = target.parameters.length;
  14817. var count;
  14818. if (source.hasRestParameter && target.hasRestParameter) {
  14819. count = sourceMax > targetMax ? sourceMax : targetMax;
  14820. sourceMax--;
  14821. targetMax--;
  14822. }
  14823. else if (source.hasRestParameter) {
  14824. sourceMax--;
  14825. count = targetMax;
  14826. }
  14827. else if (target.hasRestParameter) {
  14828. targetMax--;
  14829. count = sourceMax;
  14830. }
  14831. else {
  14832. count = sourceMax < targetMax ? sourceMax : targetMax;
  14833. }
  14834. for (var i = 0; i < count; i++) {
  14835. var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
  14836. var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
  14837. callback(s, t);
  14838. }
  14839. }
  14840. function createInferenceContext(typeParameters, inferUnionTypes) {
  14841. var inferences = [];
  14842. for (var _i = 0; _i < typeParameters.length; _i++) {
  14843. var unused = typeParameters[_i];
  14844. inferences.push({
  14845. primary: undefined, secondary: undefined, isFixed: false
  14846. });
  14847. }
  14848. return {
  14849. typeParameters: typeParameters,
  14850. inferUnionTypes: inferUnionTypes,
  14851. inferences: inferences,
  14852. inferredTypes: new Array(typeParameters.length)
  14853. };
  14854. }
  14855. function inferTypes(context, source, target) {
  14856. var sourceStack;
  14857. var targetStack;
  14858. var depth = 0;
  14859. var inferiority = 0;
  14860. inferFromTypes(source, target);
  14861. function isInProcess(source, target) {
  14862. for (var i = 0; i < depth; i++) {
  14863. if (source === sourceStack[i] && target === targetStack[i]) {
  14864. return true;
  14865. }
  14866. }
  14867. return false;
  14868. }
  14869. function inferFromTypes(source, target) {
  14870. if (target.flags & 512) {
  14871. if (source.flags & 8388608) {
  14872. return;
  14873. }
  14874. var typeParameters = context.typeParameters;
  14875. for (var i = 0; i < typeParameters.length; i++) {
  14876. if (target === typeParameters[i]) {
  14877. var inferences = context.inferences[i];
  14878. if (!inferences.isFixed) {
  14879. var candidates = inferiority ?
  14880. inferences.secondary || (inferences.secondary = []) :
  14881. inferences.primary || (inferences.primary = []);
  14882. if (!ts.contains(candidates, source)) {
  14883. candidates.push(source);
  14884. }
  14885. }
  14886. return;
  14887. }
  14888. }
  14889. }
  14890. else if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  14891. var sourceTypes = source.typeArguments;
  14892. var targetTypes = target.typeArguments;
  14893. for (var i = 0; i < sourceTypes.length; i++) {
  14894. inferFromTypes(sourceTypes[i], targetTypes[i]);
  14895. }
  14896. }
  14897. else if (source.flags & 8192 && target.flags & 8192 && source.elementTypes.length === target.elementTypes.length) {
  14898. var sourceTypes = source.elementTypes;
  14899. var targetTypes = target.elementTypes;
  14900. for (var i = 0; i < sourceTypes.length; i++) {
  14901. inferFromTypes(sourceTypes[i], targetTypes[i]);
  14902. }
  14903. }
  14904. else if (target.flags & 49152) {
  14905. var targetTypes = target.types;
  14906. var typeParameterCount = 0;
  14907. var typeParameter;
  14908. for (var _i = 0; _i < targetTypes.length; _i++) {
  14909. var t = targetTypes[_i];
  14910. if (t.flags & 512 && ts.contains(context.typeParameters, t)) {
  14911. typeParameter = t;
  14912. typeParameterCount++;
  14913. }
  14914. else {
  14915. inferFromTypes(source, t);
  14916. }
  14917. }
  14918. if (target.flags & 16384 && typeParameterCount === 1) {
  14919. inferiority++;
  14920. inferFromTypes(source, typeParameter);
  14921. inferiority--;
  14922. }
  14923. }
  14924. else if (source.flags & 49152) {
  14925. var sourceTypes = source.types;
  14926. for (var _a = 0; _a < sourceTypes.length; _a++) {
  14927. var sourceType = sourceTypes[_a];
  14928. inferFromTypes(sourceType, target);
  14929. }
  14930. }
  14931. else {
  14932. source = getApparentType(source);
  14933. if (source.flags & 80896 && (target.flags & (4096 | 8192) ||
  14934. (target.flags & 65536) && target.symbol && target.symbol.flags & (8192 | 2048 | 32))) {
  14935. if (isInProcess(source, target)) {
  14936. return;
  14937. }
  14938. if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) {
  14939. return;
  14940. }
  14941. if (depth === 0) {
  14942. sourceStack = [];
  14943. targetStack = [];
  14944. }
  14945. sourceStack[depth] = source;
  14946. targetStack[depth] = target;
  14947. depth++;
  14948. inferFromProperties(source, target);
  14949. inferFromSignatures(source, target, 0);
  14950. inferFromSignatures(source, target, 1);
  14951. inferFromIndexTypes(source, target, 0, 0);
  14952. inferFromIndexTypes(source, target, 1, 1);
  14953. inferFromIndexTypes(source, target, 0, 1);
  14954. depth--;
  14955. }
  14956. }
  14957. }
  14958. function inferFromProperties(source, target) {
  14959. var properties = getPropertiesOfObjectType(target);
  14960. for (var _i = 0; _i < properties.length; _i++) {
  14961. var targetProp = properties[_i];
  14962. var sourceProp = getPropertyOfObjectType(source, targetProp.name);
  14963. if (sourceProp) {
  14964. inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
  14965. }
  14966. }
  14967. }
  14968. function inferFromSignatures(source, target, kind) {
  14969. var sourceSignatures = getSignaturesOfType(source, kind);
  14970. var targetSignatures = getSignaturesOfType(target, kind);
  14971. var sourceLen = sourceSignatures.length;
  14972. var targetLen = targetSignatures.length;
  14973. var len = sourceLen < targetLen ? sourceLen : targetLen;
  14974. for (var i = 0; i < len; i++) {
  14975. inferFromSignature(getErasedSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
  14976. }
  14977. }
  14978. function inferFromSignature(source, target) {
  14979. forEachMatchingParameterType(source, target, inferFromTypes);
  14980. if (source.typePredicate && target.typePredicate) {
  14981. if (target.typePredicate.parameterIndex === source.typePredicate.parameterIndex) {
  14982. inferFromTypes(source.typePredicate.type, target.typePredicate.type);
  14983. }
  14984. }
  14985. else {
  14986. inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
  14987. }
  14988. }
  14989. function inferFromIndexTypes(source, target, sourceKind, targetKind) {
  14990. var targetIndexType = getIndexTypeOfType(target, targetKind);
  14991. if (targetIndexType) {
  14992. var sourceIndexType = getIndexTypeOfType(source, sourceKind);
  14993. if (sourceIndexType) {
  14994. inferFromTypes(sourceIndexType, targetIndexType);
  14995. }
  14996. }
  14997. }
  14998. }
  14999. function getInferenceCandidates(context, index) {
  15000. var inferences = context.inferences[index];
  15001. return inferences.primary || inferences.secondary || emptyArray;
  15002. }
  15003. function getInferredType(context, index) {
  15004. var inferredType = context.inferredTypes[index];
  15005. var inferenceSucceeded;
  15006. if (!inferredType) {
  15007. var inferences = getInferenceCandidates(context, index);
  15008. if (inferences.length) {
  15009. var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences);
  15010. inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType;
  15011. inferenceSucceeded = !!unionOrSuperType;
  15012. }
  15013. else {
  15014. inferredType = emptyObjectType;
  15015. inferenceSucceeded = true;
  15016. }
  15017. if (inferenceSucceeded) {
  15018. var constraint = getConstraintOfTypeParameter(context.typeParameters[index]);
  15019. inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType;
  15020. }
  15021. else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) {
  15022. context.failedTypeParameterIndex = index;
  15023. }
  15024. context.inferredTypes[index] = inferredType;
  15025. }
  15026. return inferredType;
  15027. }
  15028. function getInferredTypes(context) {
  15029. for (var i = 0; i < context.inferredTypes.length; i++) {
  15030. getInferredType(context, i);
  15031. }
  15032. return context.inferredTypes;
  15033. }
  15034. function hasAncestor(node, kind) {
  15035. return ts.getAncestor(node, kind) !== undefined;
  15036. }
  15037. function getResolvedSymbol(node) {
  15038. var links = getNodeLinks(node);
  15039. if (!links.resolvedSymbol) {
  15040. links.resolvedSymbol = (!ts.nodeIsMissing(node) && resolveName(node, node.text, 107455 | 1048576, ts.Diagnostics.Cannot_find_name_0, node)) || unknownSymbol;
  15041. }
  15042. return links.resolvedSymbol;
  15043. }
  15044. function isInTypeQuery(node) {
  15045. while (node) {
  15046. switch (node.kind) {
  15047. case 152:
  15048. return true;
  15049. case 67:
  15050. case 133:
  15051. node = node.parent;
  15052. continue;
  15053. default:
  15054. return false;
  15055. }
  15056. }
  15057. ts.Debug.fail("should not get here");
  15058. }
  15059. function removeTypesFromUnionType(type, typeKind, isOfTypeKind, allowEmptyUnionResult) {
  15060. if (type.flags & 16384) {
  15061. var types = type.types;
  15062. if (ts.forEach(types, function (t) { return !!(t.flags & typeKind) === isOfTypeKind; })) {
  15063. var narrowedType = getUnionType(ts.filter(types, function (t) { return !(t.flags & typeKind) === isOfTypeKind; }));
  15064. if (allowEmptyUnionResult || narrowedType !== emptyObjectType) {
  15065. return narrowedType;
  15066. }
  15067. }
  15068. }
  15069. else if (allowEmptyUnionResult && !!(type.flags & typeKind) === isOfTypeKind) {
  15070. return getUnionType(emptyArray);
  15071. }
  15072. return type;
  15073. }
  15074. function hasInitializer(node) {
  15075. return !!(node.initializer || ts.isBindingPattern(node.parent) && hasInitializer(node.parent.parent));
  15076. }
  15077. function isVariableAssignedWithin(symbol, node) {
  15078. var links = getNodeLinks(node);
  15079. if (links.assignmentChecks) {
  15080. var cachedResult = links.assignmentChecks[symbol.id];
  15081. if (cachedResult !== undefined) {
  15082. return cachedResult;
  15083. }
  15084. }
  15085. else {
  15086. links.assignmentChecks = {};
  15087. }
  15088. return links.assignmentChecks[symbol.id] = isAssignedIn(node);
  15089. function isAssignedInBinaryExpression(node) {
  15090. if (node.operatorToken.kind >= 55 && node.operatorToken.kind <= 66) {
  15091. var n = node.left;
  15092. while (n.kind === 170) {
  15093. n = n.expression;
  15094. }
  15095. if (n.kind === 67 && getResolvedSymbol(n) === symbol) {
  15096. return true;
  15097. }
  15098. }
  15099. return ts.forEachChild(node, isAssignedIn);
  15100. }
  15101. function isAssignedInVariableDeclaration(node) {
  15102. if (!ts.isBindingPattern(node.name) && getSymbolOfNode(node) === symbol && hasInitializer(node)) {
  15103. return true;
  15104. }
  15105. return ts.forEachChild(node, isAssignedIn);
  15106. }
  15107. function isAssignedIn(node) {
  15108. switch (node.kind) {
  15109. case 179:
  15110. return isAssignedInBinaryExpression(node);
  15111. case 209:
  15112. case 161:
  15113. return isAssignedInVariableDeclaration(node);
  15114. case 159:
  15115. case 160:
  15116. case 162:
  15117. case 163:
  15118. case 164:
  15119. case 165:
  15120. case 166:
  15121. case 167:
  15122. case 169:
  15123. case 187:
  15124. case 170:
  15125. case 177:
  15126. case 173:
  15127. case 176:
  15128. case 174:
  15129. case 175:
  15130. case 178:
  15131. case 182:
  15132. case 180:
  15133. case 183:
  15134. case 190:
  15135. case 191:
  15136. case 193:
  15137. case 194:
  15138. case 195:
  15139. case 196:
  15140. case 197:
  15141. case 198:
  15142. case 199:
  15143. case 202:
  15144. case 203:
  15145. case 204:
  15146. case 239:
  15147. case 240:
  15148. case 205:
  15149. case 206:
  15150. case 207:
  15151. case 242:
  15152. case 231:
  15153. case 232:
  15154. case 236:
  15155. case 237:
  15156. case 233:
  15157. case 238:
  15158. return ts.forEachChild(node, isAssignedIn);
  15159. }
  15160. return false;
  15161. }
  15162. }
  15163. function getNarrowedTypeOfSymbol(symbol, node) {
  15164. var type = getTypeOfSymbol(symbol);
  15165. if (node && symbol.flags & 3) {
  15166. if (isTypeAny(type) || type.flags & (80896 | 16384 | 512)) {
  15167. loop: while (node.parent) {
  15168. var child = node;
  15169. node = node.parent;
  15170. var narrowedType = type;
  15171. switch (node.kind) {
  15172. case 194:
  15173. if (child !== node.expression) {
  15174. narrowedType = narrowType(type, node.expression, child === node.thenStatement);
  15175. }
  15176. break;
  15177. case 180:
  15178. if (child !== node.condition) {
  15179. narrowedType = narrowType(type, node.condition, child === node.whenTrue);
  15180. }
  15181. break;
  15182. case 179:
  15183. if (child === node.right) {
  15184. if (node.operatorToken.kind === 50) {
  15185. narrowedType = narrowType(type, node.left, true);
  15186. }
  15187. else if (node.operatorToken.kind === 51) {
  15188. narrowedType = narrowType(type, node.left, false);
  15189. }
  15190. }
  15191. break;
  15192. case 246:
  15193. case 216:
  15194. case 211:
  15195. case 141:
  15196. case 140:
  15197. case 143:
  15198. case 144:
  15199. case 142:
  15200. break loop;
  15201. }
  15202. if (narrowedType !== type) {
  15203. if (isVariableAssignedWithin(symbol, node)) {
  15204. break;
  15205. }
  15206. type = narrowedType;
  15207. }
  15208. }
  15209. }
  15210. }
  15211. return type;
  15212. function narrowTypeByEquality(type, expr, assumeTrue) {
  15213. if (expr.left.kind !== 174 || expr.right.kind !== 9) {
  15214. return type;
  15215. }
  15216. var left = expr.left;
  15217. var right = expr.right;
  15218. if (left.expression.kind !== 67 || getResolvedSymbol(left.expression) !== symbol) {
  15219. return type;
  15220. }
  15221. var typeInfo = primitiveTypeInfo[right.text];
  15222. if (expr.operatorToken.kind === 33) {
  15223. assumeTrue = !assumeTrue;
  15224. }
  15225. if (assumeTrue) {
  15226. if (!typeInfo) {
  15227. return removeTypesFromUnionType(type, 258 | 132 | 8 | 16777216, true, false);
  15228. }
  15229. if (isTypeSubtypeOf(typeInfo.type, type)) {
  15230. return typeInfo.type;
  15231. }
  15232. return removeTypesFromUnionType(type, typeInfo.flags, false, false);
  15233. }
  15234. else {
  15235. if (typeInfo) {
  15236. return removeTypesFromUnionType(type, typeInfo.flags, true, false);
  15237. }
  15238. return type;
  15239. }
  15240. }
  15241. function narrowTypeByAnd(type, expr, assumeTrue) {
  15242. if (assumeTrue) {
  15243. return narrowType(narrowType(type, expr.left, true), expr.right, true);
  15244. }
  15245. else {
  15246. return getUnionType([
  15247. narrowType(type, expr.left, false),
  15248. narrowType(narrowType(type, expr.left, true), expr.right, false)
  15249. ]);
  15250. }
  15251. }
  15252. function narrowTypeByOr(type, expr, assumeTrue) {
  15253. if (assumeTrue) {
  15254. return getUnionType([
  15255. narrowType(type, expr.left, true),
  15256. narrowType(narrowType(type, expr.left, false), expr.right, true)
  15257. ]);
  15258. }
  15259. else {
  15260. return narrowType(narrowType(type, expr.left, false), expr.right, false);
  15261. }
  15262. }
  15263. function narrowTypeByInstanceof(type, expr, assumeTrue) {
  15264. if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 67 || getResolvedSymbol(expr.left) !== symbol) {
  15265. return type;
  15266. }
  15267. var rightType = checkExpression(expr.right);
  15268. if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
  15269. return type;
  15270. }
  15271. var targetType;
  15272. var prototypeProperty = getPropertyOfType(rightType, "prototype");
  15273. if (prototypeProperty) {
  15274. var prototypePropertyType = getTypeOfSymbol(prototypeProperty);
  15275. if (!isTypeAny(prototypePropertyType)) {
  15276. targetType = prototypePropertyType;
  15277. }
  15278. }
  15279. if (!targetType) {
  15280. var constructSignatures;
  15281. if (rightType.flags & 2048) {
  15282. constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
  15283. }
  15284. else if (rightType.flags & 65536) {
  15285. constructSignatures = getSignaturesOfType(rightType, 1);
  15286. }
  15287. if (constructSignatures && constructSignatures.length) {
  15288. targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
  15289. }
  15290. }
  15291. if (targetType) {
  15292. return getNarrowedType(type, targetType);
  15293. }
  15294. return type;
  15295. }
  15296. function getNarrowedType(originalType, narrowedTypeCandidate) {
  15297. if (originalType.flags & 16384) {
  15298. var assignableConstituents = ts.filter(originalType.types, function (t) { return isTypeAssignableTo(t, narrowedTypeCandidate); });
  15299. if (assignableConstituents.length) {
  15300. return getUnionType(assignableConstituents);
  15301. }
  15302. }
  15303. if (isTypeAssignableTo(narrowedTypeCandidate, originalType)) {
  15304. return narrowedTypeCandidate;
  15305. }
  15306. return originalType;
  15307. }
  15308. function narrowTypeByTypePredicate(type, expr, assumeTrue) {
  15309. if (type.flags & 1) {
  15310. return type;
  15311. }
  15312. var signature = getResolvedSignature(expr);
  15313. if (signature.typePredicate &&
  15314. expr.arguments[signature.typePredicate.parameterIndex] &&
  15315. getSymbolAtLocation(expr.arguments[signature.typePredicate.parameterIndex]) === symbol) {
  15316. if (!assumeTrue) {
  15317. if (type.flags & 16384) {
  15318. return getUnionType(ts.filter(type.types, function (t) { return !isTypeSubtypeOf(t, signature.typePredicate.type); }));
  15319. }
  15320. return type;
  15321. }
  15322. return getNarrowedType(type, signature.typePredicate.type);
  15323. }
  15324. return type;
  15325. }
  15326. function narrowType(type, expr, assumeTrue) {
  15327. switch (expr.kind) {
  15328. case 166:
  15329. return narrowTypeByTypePredicate(type, expr, assumeTrue);
  15330. case 170:
  15331. return narrowType(type, expr.expression, assumeTrue);
  15332. case 179:
  15333. var operator = expr.operatorToken.kind;
  15334. if (operator === 32 || operator === 33) {
  15335. return narrowTypeByEquality(type, expr, assumeTrue);
  15336. }
  15337. else if (operator === 50) {
  15338. return narrowTypeByAnd(type, expr, assumeTrue);
  15339. }
  15340. else if (operator === 51) {
  15341. return narrowTypeByOr(type, expr, assumeTrue);
  15342. }
  15343. else if (operator === 89) {
  15344. return narrowTypeByInstanceof(type, expr, assumeTrue);
  15345. }
  15346. break;
  15347. case 177:
  15348. if (expr.operator === 48) {
  15349. return narrowType(type, expr.operand, !assumeTrue);
  15350. }
  15351. break;
  15352. }
  15353. return type;
  15354. }
  15355. }
  15356. function checkIdentifier(node) {
  15357. var symbol = getResolvedSymbol(node);
  15358. if (symbol === argumentsSymbol) {
  15359. var container = ts.getContainingFunction(node);
  15360. if (container.kind === 172) {
  15361. if (languageVersion < 2) {
  15362. error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
  15363. }
  15364. }
  15365. if (node.parserContextFlags & 8) {
  15366. getNodeLinks(container).flags |= 4096;
  15367. getNodeLinks(node).flags |= 2048;
  15368. }
  15369. }
  15370. if (symbol.flags & 8388608 && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
  15371. markAliasSymbolAsReferenced(symbol);
  15372. }
  15373. checkCollisionWithCapturedSuperVariable(node, node);
  15374. checkCollisionWithCapturedThisVariable(node, node);
  15375. checkBlockScopedBindingCapturedInLoop(node, symbol);
  15376. return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node);
  15377. }
  15378. function isInsideFunction(node, threshold) {
  15379. var current = node;
  15380. while (current && current !== threshold) {
  15381. if (ts.isFunctionLike(current)) {
  15382. return true;
  15383. }
  15384. current = current.parent;
  15385. }
  15386. return false;
  15387. }
  15388. function checkBlockScopedBindingCapturedInLoop(node, symbol) {
  15389. if (languageVersion >= 2 ||
  15390. (symbol.flags & 2) === 0 ||
  15391. symbol.valueDeclaration.parent.kind === 242) {
  15392. return;
  15393. }
  15394. var container = symbol.valueDeclaration;
  15395. while (container.kind !== 210) {
  15396. container = container.parent;
  15397. }
  15398. container = container.parent;
  15399. if (container.kind === 191) {
  15400. container = container.parent;
  15401. }
  15402. var inFunction = isInsideFunction(node.parent, container);
  15403. var current = container;
  15404. while (current && !ts.nodeStartsNewLexicalEnvironment(current)) {
  15405. if (isIterationStatement(current, false)) {
  15406. if (inFunction) {
  15407. 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));
  15408. }
  15409. getNodeLinks(symbol.valueDeclaration).flags |= 16384;
  15410. break;
  15411. }
  15412. current = current.parent;
  15413. }
  15414. }
  15415. function captureLexicalThis(node, container) {
  15416. getNodeLinks(node).flags |= 2;
  15417. if (container.kind === 139 || container.kind === 142) {
  15418. var classNode = container.parent;
  15419. getNodeLinks(classNode).flags |= 4;
  15420. }
  15421. else {
  15422. getNodeLinks(container).flags |= 4;
  15423. }
  15424. }
  15425. function checkThisExpression(node) {
  15426. var container = ts.getThisContainer(node, true);
  15427. var needToCaptureLexicalThis = false;
  15428. if (container.kind === 172) {
  15429. container = ts.getThisContainer(container, false);
  15430. needToCaptureLexicalThis = (languageVersion < 2);
  15431. }
  15432. switch (container.kind) {
  15433. case 216:
  15434. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body);
  15435. break;
  15436. case 215:
  15437. error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
  15438. break;
  15439. case 142:
  15440. if (isInConstructorArgumentInitializer(node, container)) {
  15441. error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments);
  15442. }
  15443. break;
  15444. case 139:
  15445. case 138:
  15446. if (container.flags & 128) {
  15447. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer);
  15448. }
  15449. break;
  15450. case 134:
  15451. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name);
  15452. break;
  15453. }
  15454. if (needToCaptureLexicalThis) {
  15455. captureLexicalThis(node, container);
  15456. }
  15457. if (ts.isClassLike(container.parent)) {
  15458. var symbol = getSymbolOfNode(container.parent);
  15459. return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol);
  15460. }
  15461. return anyType;
  15462. }
  15463. function isInConstructorArgumentInitializer(node, constructorDecl) {
  15464. for (var n = node; n && n !== constructorDecl; n = n.parent) {
  15465. if (n.kind === 136) {
  15466. return true;
  15467. }
  15468. }
  15469. return false;
  15470. }
  15471. function checkSuperExpression(node) {
  15472. var isCallExpression = node.parent.kind === 166 && node.parent.expression === node;
  15473. var classDeclaration = ts.getContainingClass(node);
  15474. var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
  15475. var baseClassType = classType && getBaseTypes(classType)[0];
  15476. var container = ts.getSuperContainer(node, true);
  15477. var needToCaptureLexicalThis = false;
  15478. if (!isCallExpression) {
  15479. while (container && container.kind === 172) {
  15480. container = ts.getSuperContainer(container, true);
  15481. needToCaptureLexicalThis = languageVersion < 2;
  15482. }
  15483. }
  15484. var canUseSuperExpression = isLegalUsageOfSuperExpression(container);
  15485. var nodeCheckFlag = 0;
  15486. if (canUseSuperExpression) {
  15487. if ((container.flags & 128) || isCallExpression) {
  15488. nodeCheckFlag = 512;
  15489. }
  15490. else {
  15491. nodeCheckFlag = 256;
  15492. }
  15493. getNodeLinks(node).flags |= nodeCheckFlag;
  15494. if (needToCaptureLexicalThis) {
  15495. captureLexicalThis(node.parent, container);
  15496. }
  15497. }
  15498. if (!baseClassType) {
  15499. if (!classDeclaration || !ts.getClassExtendsHeritageClauseElement(classDeclaration)) {
  15500. error(node, ts.Diagnostics.super_can_only_be_referenced_in_a_derived_class);
  15501. }
  15502. return unknownType;
  15503. }
  15504. if (!canUseSuperExpression) {
  15505. if (container && container.kind === 134) {
  15506. error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
  15507. }
  15508. else if (isCallExpression) {
  15509. error(node, ts.Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
  15510. }
  15511. else {
  15512. error(node, ts.Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
  15513. }
  15514. return unknownType;
  15515. }
  15516. if (container.kind === 142 && isInConstructorArgumentInitializer(node, container)) {
  15517. error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments);
  15518. return unknownType;
  15519. }
  15520. return nodeCheckFlag === 512
  15521. ? getBaseConstructorTypeOfClass(classType)
  15522. : baseClassType;
  15523. function isLegalUsageOfSuperExpression(container) {
  15524. if (!container) {
  15525. return false;
  15526. }
  15527. if (isCallExpression) {
  15528. return container.kind === 142;
  15529. }
  15530. else {
  15531. if (container && ts.isClassLike(container.parent)) {
  15532. if (container.flags & 128) {
  15533. return container.kind === 141 ||
  15534. container.kind === 140 ||
  15535. container.kind === 143 ||
  15536. container.kind === 144;
  15537. }
  15538. else {
  15539. return container.kind === 141 ||
  15540. container.kind === 140 ||
  15541. container.kind === 143 ||
  15542. container.kind === 144 ||
  15543. container.kind === 139 ||
  15544. container.kind === 138 ||
  15545. container.kind === 142;
  15546. }
  15547. }
  15548. }
  15549. return false;
  15550. }
  15551. }
  15552. function getContextuallyTypedParameterType(parameter) {
  15553. if (isFunctionExpressionOrArrowFunction(parameter.parent)) {
  15554. var func = parameter.parent;
  15555. if (isContextSensitive(func)) {
  15556. var contextualSignature = getContextualSignature(func);
  15557. if (contextualSignature) {
  15558. var funcHasRestParameters = ts.hasRestParameter(func);
  15559. var len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
  15560. var indexOfParameter = ts.indexOf(func.parameters, parameter);
  15561. if (indexOfParameter < len) {
  15562. return getTypeAtPosition(contextualSignature, indexOfParameter);
  15563. }
  15564. if (indexOfParameter === (func.parameters.length - 1) &&
  15565. funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) {
  15566. return getTypeOfSymbol(ts.lastOrUndefined(contextualSignature.parameters));
  15567. }
  15568. }
  15569. }
  15570. }
  15571. return undefined;
  15572. }
  15573. function getContextualTypeForInitializerExpression(node) {
  15574. var declaration = node.parent;
  15575. if (node === declaration.initializer) {
  15576. if (declaration.type) {
  15577. return getTypeFromTypeNode(declaration.type);
  15578. }
  15579. if (declaration.kind === 136) {
  15580. var type = getContextuallyTypedParameterType(declaration);
  15581. if (type) {
  15582. return type;
  15583. }
  15584. }
  15585. if (ts.isBindingPattern(declaration.name)) {
  15586. return getTypeFromBindingPattern(declaration.name);
  15587. }
  15588. }
  15589. return undefined;
  15590. }
  15591. function getContextualTypeForReturnExpression(node) {
  15592. var func = ts.getContainingFunction(node);
  15593. if (func && !func.asteriskToken) {
  15594. return getContextualReturnType(func);
  15595. }
  15596. return undefined;
  15597. }
  15598. function getContextualTypeForYieldOperand(node) {
  15599. var func = ts.getContainingFunction(node);
  15600. if (func) {
  15601. var contextualReturnType = getContextualReturnType(func);
  15602. if (contextualReturnType) {
  15603. return node.asteriskToken
  15604. ? contextualReturnType
  15605. : getElementTypeOfIterableIterator(contextualReturnType);
  15606. }
  15607. }
  15608. return undefined;
  15609. }
  15610. function isInParameterInitializerBeforeContainingFunction(node) {
  15611. while (node.parent && !ts.isFunctionLike(node.parent)) {
  15612. if (node.parent.kind === 136 && node.parent.initializer === node) {
  15613. return true;
  15614. }
  15615. node = node.parent;
  15616. }
  15617. return false;
  15618. }
  15619. function getContextualReturnType(functionDecl) {
  15620. if (functionDecl.type ||
  15621. functionDecl.kind === 142 ||
  15622. functionDecl.kind === 143 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 144))) {
  15623. return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
  15624. }
  15625. var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl);
  15626. if (signature) {
  15627. return getReturnTypeOfSignature(signature);
  15628. }
  15629. return undefined;
  15630. }
  15631. function getContextualTypeForArgument(callTarget, arg) {
  15632. var args = getEffectiveCallArguments(callTarget);
  15633. var argIndex = ts.indexOf(args, arg);
  15634. if (argIndex >= 0) {
  15635. var signature = getResolvedSignature(callTarget);
  15636. return getTypeAtPosition(signature, argIndex);
  15637. }
  15638. return undefined;
  15639. }
  15640. function getContextualTypeForSubstitutionExpression(template, substitutionExpression) {
  15641. if (template.parent.kind === 168) {
  15642. return getContextualTypeForArgument(template.parent, substitutionExpression);
  15643. }
  15644. return undefined;
  15645. }
  15646. function getContextualTypeForBinaryOperand(node) {
  15647. var binaryExpression = node.parent;
  15648. var operator = binaryExpression.operatorToken.kind;
  15649. if (operator >= 55 && operator <= 66) {
  15650. if (node === binaryExpression.right) {
  15651. return checkExpression(binaryExpression.left);
  15652. }
  15653. }
  15654. else if (operator === 51) {
  15655. var type = getContextualType(binaryExpression);
  15656. if (!type && node === binaryExpression.right) {
  15657. type = checkExpression(binaryExpression.left);
  15658. }
  15659. return type;
  15660. }
  15661. return undefined;
  15662. }
  15663. function applyToContextualType(type, mapper) {
  15664. if (!(type.flags & 16384)) {
  15665. return mapper(type);
  15666. }
  15667. var types = type.types;
  15668. var mappedType;
  15669. var mappedTypes;
  15670. for (var _i = 0; _i < types.length; _i++) {
  15671. var current = types[_i];
  15672. var t = mapper(current);
  15673. if (t) {
  15674. if (!mappedType) {
  15675. mappedType = t;
  15676. }
  15677. else if (!mappedTypes) {
  15678. mappedTypes = [mappedType, t];
  15679. }
  15680. else {
  15681. mappedTypes.push(t);
  15682. }
  15683. }
  15684. }
  15685. return mappedTypes ? getUnionType(mappedTypes) : mappedType;
  15686. }
  15687. function getTypeOfPropertyOfContextualType(type, name) {
  15688. return applyToContextualType(type, function (t) {
  15689. var prop = t.flags & 130048 ? getPropertyOfType(t, name) : undefined;
  15690. return prop ? getTypeOfSymbol(prop) : undefined;
  15691. });
  15692. }
  15693. function getIndexTypeOfContextualType(type, kind) {
  15694. return applyToContextualType(type, function (t) { return getIndexTypeOfStructuredType(t, kind); });
  15695. }
  15696. function contextualTypeIsTupleLikeType(type) {
  15697. return !!(type.flags & 16384 ? ts.forEach(type.types, isTupleLikeType) : isTupleLikeType(type));
  15698. }
  15699. function contextualTypeHasIndexSignature(type, kind) {
  15700. return !!(type.flags & 16384 ? ts.forEach(type.types, function (t) { return getIndexTypeOfStructuredType(t, kind); }) : getIndexTypeOfStructuredType(type, kind));
  15701. }
  15702. function getContextualTypeForObjectLiteralMethod(node) {
  15703. ts.Debug.assert(ts.isObjectLiteralMethod(node));
  15704. if (isInsideWithStatementBody(node)) {
  15705. return undefined;
  15706. }
  15707. return getContextualTypeForObjectLiteralElement(node);
  15708. }
  15709. function getContextualTypeForObjectLiteralElement(element) {
  15710. var objectLiteral = element.parent;
  15711. var type = getContextualType(objectLiteral);
  15712. if (type) {
  15713. if (!ts.hasDynamicName(element)) {
  15714. var symbolName = getSymbolOfNode(element).name;
  15715. var propertyType = getTypeOfPropertyOfContextualType(type, symbolName);
  15716. if (propertyType) {
  15717. return propertyType;
  15718. }
  15719. }
  15720. return isNumericName(element.name) && getIndexTypeOfContextualType(type, 1) ||
  15721. getIndexTypeOfContextualType(type, 0);
  15722. }
  15723. return undefined;
  15724. }
  15725. function getContextualTypeForElementExpression(node) {
  15726. var arrayLiteral = node.parent;
  15727. var type = getContextualType(arrayLiteral);
  15728. if (type) {
  15729. var index = ts.indexOf(arrayLiteral.elements, node);
  15730. return getTypeOfPropertyOfContextualType(type, "" + index)
  15731. || getIndexTypeOfContextualType(type, 1)
  15732. || (languageVersion >= 2 ? getElementTypeOfIterable(type, undefined) : undefined);
  15733. }
  15734. return undefined;
  15735. }
  15736. function getContextualTypeForConditionalOperand(node) {
  15737. var conditional = node.parent;
  15738. return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined;
  15739. }
  15740. function getContextualTypeForJsxExpression(expr) {
  15741. if (expr.parent.kind === 236) {
  15742. var attrib = expr.parent;
  15743. var attrsType = getJsxElementAttributesType(attrib.parent);
  15744. if (!attrsType || isTypeAny(attrsType)) {
  15745. return undefined;
  15746. }
  15747. else {
  15748. return getTypeOfPropertyOfType(attrsType, attrib.name.text);
  15749. }
  15750. }
  15751. if (expr.kind === 237) {
  15752. return getJsxElementAttributesType(expr.parent);
  15753. }
  15754. return undefined;
  15755. }
  15756. function getContextualType(node) {
  15757. var type = getContextualTypeWorker(node);
  15758. return type && getApparentType(type);
  15759. }
  15760. function getContextualTypeWorker(node) {
  15761. if (isInsideWithStatementBody(node)) {
  15762. return undefined;
  15763. }
  15764. if (node.contextualType) {
  15765. return node.contextualType;
  15766. }
  15767. var parent = node.parent;
  15768. switch (parent.kind) {
  15769. case 209:
  15770. case 136:
  15771. case 139:
  15772. case 138:
  15773. case 161:
  15774. return getContextualTypeForInitializerExpression(node);
  15775. case 172:
  15776. case 202:
  15777. return getContextualTypeForReturnExpression(node);
  15778. case 182:
  15779. return getContextualTypeForYieldOperand(parent);
  15780. case 166:
  15781. case 167:
  15782. return getContextualTypeForArgument(parent, node);
  15783. case 169:
  15784. case 187:
  15785. return getTypeFromTypeNode(parent.type);
  15786. case 179:
  15787. return getContextualTypeForBinaryOperand(node);
  15788. case 243:
  15789. return getContextualTypeForObjectLiteralElement(parent);
  15790. case 162:
  15791. return getContextualTypeForElementExpression(node);
  15792. case 180:
  15793. return getContextualTypeForConditionalOperand(node);
  15794. case 188:
  15795. ts.Debug.assert(parent.parent.kind === 181);
  15796. return getContextualTypeForSubstitutionExpression(parent.parent, node);
  15797. case 170:
  15798. return getContextualType(parent);
  15799. case 238:
  15800. case 237:
  15801. return getContextualTypeForJsxExpression(parent);
  15802. }
  15803. return undefined;
  15804. }
  15805. function getNonGenericSignature(type) {
  15806. var signatures = getSignaturesOfStructuredType(type, 0);
  15807. if (signatures.length === 1) {
  15808. var signature = signatures[0];
  15809. if (!signature.typeParameters) {
  15810. return signature;
  15811. }
  15812. }
  15813. }
  15814. function isFunctionExpressionOrArrowFunction(node) {
  15815. return node.kind === 171 || node.kind === 172;
  15816. }
  15817. function getContextualSignatureForFunctionLikeDeclaration(node) {
  15818. return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node)
  15819. ? getContextualSignature(node)
  15820. : undefined;
  15821. }
  15822. function getContextualSignature(node) {
  15823. ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node));
  15824. var type = ts.isObjectLiteralMethod(node)
  15825. ? getContextualTypeForObjectLiteralMethod(node)
  15826. : getContextualType(node);
  15827. if (!type) {
  15828. return undefined;
  15829. }
  15830. if (!(type.flags & 16384)) {
  15831. return getNonGenericSignature(type);
  15832. }
  15833. var signatureList;
  15834. var types = type.types;
  15835. for (var _i = 0; _i < types.length; _i++) {
  15836. var current = types[_i];
  15837. var signature = getNonGenericSignature(current);
  15838. if (signature) {
  15839. if (!signatureList) {
  15840. signatureList = [signature];
  15841. }
  15842. else if (!compareSignatures(signatureList[0], signature, false, true, compareTypes)) {
  15843. return undefined;
  15844. }
  15845. else {
  15846. signatureList.push(signature);
  15847. }
  15848. }
  15849. }
  15850. var result;
  15851. if (signatureList) {
  15852. result = cloneSignature(signatureList[0]);
  15853. result.resolvedReturnType = undefined;
  15854. result.unionSignatures = signatureList;
  15855. }
  15856. return result;
  15857. }
  15858. function isInferentialContext(mapper) {
  15859. return mapper && mapper.context;
  15860. }
  15861. function isAssignmentTarget(node) {
  15862. var parent = node.parent;
  15863. if (parent.kind === 179 && parent.operatorToken.kind === 55 && parent.left === node) {
  15864. return true;
  15865. }
  15866. if (parent.kind === 243) {
  15867. return isAssignmentTarget(parent.parent);
  15868. }
  15869. if (parent.kind === 162) {
  15870. return isAssignmentTarget(parent);
  15871. }
  15872. return false;
  15873. }
  15874. function checkSpreadElementExpression(node, contextualMapper) {
  15875. var arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper);
  15876. return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, false);
  15877. }
  15878. function checkArrayLiteral(node, contextualMapper) {
  15879. var elements = node.elements;
  15880. if (!elements.length) {
  15881. return createArrayType(undefinedType);
  15882. }
  15883. var hasSpreadElement = false;
  15884. var elementTypes = [];
  15885. var inDestructuringPattern = isAssignmentTarget(node);
  15886. for (var _i = 0; _i < elements.length; _i++) {
  15887. var e = elements[_i];
  15888. if (inDestructuringPattern && e.kind === 183) {
  15889. var restArrayType = checkExpression(e.expression, contextualMapper);
  15890. var restElementType = getIndexTypeOfType(restArrayType, 1) ||
  15891. (languageVersion >= 2 ? getElementTypeOfIterable(restArrayType, undefined) : undefined);
  15892. if (restElementType) {
  15893. elementTypes.push(restElementType);
  15894. }
  15895. }
  15896. else {
  15897. var type = checkExpression(e, contextualMapper);
  15898. elementTypes.push(type);
  15899. }
  15900. hasSpreadElement = hasSpreadElement || e.kind === 183;
  15901. }
  15902. if (!hasSpreadElement) {
  15903. var contextualType = getContextualType(node);
  15904. if (contextualType && contextualTypeIsTupleLikeType(contextualType) || inDestructuringPattern) {
  15905. return createTupleType(elementTypes);
  15906. }
  15907. }
  15908. return createArrayType(getUnionType(elementTypes));
  15909. }
  15910. function isNumericName(name) {
  15911. return name.kind === 134 ? isNumericComputedName(name) : isNumericLiteralName(name.text);
  15912. }
  15913. function isNumericComputedName(name) {
  15914. return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132);
  15915. }
  15916. function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) {
  15917. return isTypeAny(type) || allConstituentTypesHaveKind(type, kind);
  15918. }
  15919. function isNumericLiteralName(name) {
  15920. return (+name).toString() === name;
  15921. }
  15922. function checkComputedPropertyName(node) {
  15923. var links = getNodeLinks(node.expression);
  15924. if (!links.resolvedType) {
  15925. links.resolvedType = checkExpression(node.expression);
  15926. if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 | 258 | 16777216)) {
  15927. error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any);
  15928. }
  15929. else {
  15930. checkThatExpressionIsProperSymbolReference(node.expression, links.resolvedType, true);
  15931. }
  15932. }
  15933. return links.resolvedType;
  15934. }
  15935. function checkObjectLiteral(node, contextualMapper) {
  15936. checkGrammarObjectLiteralExpression(node);
  15937. var propertiesTable = {};
  15938. var propertiesArray = [];
  15939. var contextualType = getContextualType(node);
  15940. var typeFlags = 0;
  15941. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  15942. var memberDecl = _a[_i];
  15943. var member = memberDecl.symbol;
  15944. if (memberDecl.kind === 243 ||
  15945. memberDecl.kind === 244 ||
  15946. ts.isObjectLiteralMethod(memberDecl)) {
  15947. var type = void 0;
  15948. if (memberDecl.kind === 243) {
  15949. type = checkPropertyAssignment(memberDecl, contextualMapper);
  15950. }
  15951. else if (memberDecl.kind === 141) {
  15952. type = checkObjectLiteralMethod(memberDecl, contextualMapper);
  15953. }
  15954. else {
  15955. ts.Debug.assert(memberDecl.kind === 244);
  15956. type = checkExpression(memberDecl.name, contextualMapper);
  15957. }
  15958. typeFlags |= type.flags;
  15959. var prop = createSymbol(4 | 67108864 | member.flags, member.name);
  15960. prop.declarations = member.declarations;
  15961. prop.parent = member.parent;
  15962. if (member.valueDeclaration) {
  15963. prop.valueDeclaration = member.valueDeclaration;
  15964. }
  15965. prop.type = type;
  15966. prop.target = member;
  15967. member = prop;
  15968. }
  15969. else {
  15970. ts.Debug.assert(memberDecl.kind === 143 || memberDecl.kind === 144);
  15971. checkAccessorDeclaration(memberDecl);
  15972. }
  15973. if (!ts.hasDynamicName(memberDecl)) {
  15974. propertiesTable[member.name] = member;
  15975. }
  15976. propertiesArray.push(member);
  15977. }
  15978. var stringIndexType = getIndexType(0);
  15979. var numberIndexType = getIndexType(1);
  15980. var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
  15981. var freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : 1048576;
  15982. result.flags |= 524288 | 4194304 | freshObjectLiteralFlag | (typeFlags & 14680064);
  15983. return result;
  15984. function getIndexType(kind) {
  15985. if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) {
  15986. var propTypes = [];
  15987. for (var i = 0; i < propertiesArray.length; i++) {
  15988. var propertyDecl = node.properties[i];
  15989. if (kind === 0 || isNumericName(propertyDecl.name)) {
  15990. var type = getTypeOfSymbol(propertiesArray[i]);
  15991. if (!ts.contains(propTypes, type)) {
  15992. propTypes.push(type);
  15993. }
  15994. }
  15995. }
  15996. var result_1 = propTypes.length ? getUnionType(propTypes) : undefinedType;
  15997. typeFlags |= result_1.flags;
  15998. return result_1;
  15999. }
  16000. return undefined;
  16001. }
  16002. }
  16003. function checkJsxSelfClosingElement(node) {
  16004. checkJsxOpeningLikeElement(node);
  16005. return jsxElementType || anyType;
  16006. }
  16007. function tagNamesAreEquivalent(lhs, rhs) {
  16008. if (lhs.kind !== rhs.kind) {
  16009. return false;
  16010. }
  16011. if (lhs.kind === 67) {
  16012. return lhs.text === rhs.text;
  16013. }
  16014. return lhs.right.text === rhs.right.text &&
  16015. tagNamesAreEquivalent(lhs.left, rhs.left);
  16016. }
  16017. function checkJsxElement(node) {
  16018. checkJsxOpeningLikeElement(node.openingElement);
  16019. if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) {
  16020. error(node.closingElement, ts.Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, ts.getTextOfNode(node.openingElement.tagName));
  16021. }
  16022. else {
  16023. getJsxElementTagSymbol(node.closingElement);
  16024. }
  16025. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  16026. var child = _a[_i];
  16027. switch (child.kind) {
  16028. case 238:
  16029. checkJsxExpression(child);
  16030. break;
  16031. case 231:
  16032. checkJsxElement(child);
  16033. break;
  16034. case 232:
  16035. checkJsxSelfClosingElement(child);
  16036. break;
  16037. default:
  16038. ts.Debug.assert(child.kind === 234);
  16039. }
  16040. }
  16041. return jsxElementType || anyType;
  16042. }
  16043. function isUnhyphenatedJsxName(name) {
  16044. return name.indexOf("-") < 0;
  16045. }
  16046. function isJsxIntrinsicIdentifier(tagName) {
  16047. if (tagName.kind === 133) {
  16048. return false;
  16049. }
  16050. else {
  16051. return ts.isIntrinsicJsxName(tagName.text);
  16052. }
  16053. }
  16054. function checkJsxAttribute(node, elementAttributesType, nameTable) {
  16055. var correspondingPropType = undefined;
  16056. if (elementAttributesType === emptyObjectType && isUnhyphenatedJsxName(node.name.text)) {
  16057. error(node.parent, ts.Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, getJsxElementPropertiesName());
  16058. }
  16059. else if (elementAttributesType && !isTypeAny(elementAttributesType)) {
  16060. var correspondingPropSymbol = getPropertyOfType(elementAttributesType, node.name.text);
  16061. correspondingPropType = correspondingPropSymbol && getTypeOfSymbol(correspondingPropSymbol);
  16062. if (isUnhyphenatedJsxName(node.name.text)) {
  16063. var indexerType = getIndexTypeOfType(elementAttributesType, 0);
  16064. if (indexerType) {
  16065. correspondingPropType = indexerType;
  16066. }
  16067. else {
  16068. if (!correspondingPropType) {
  16069. error(node.name, ts.Diagnostics.Property_0_does_not_exist_on_type_1, node.name.text, typeToString(elementAttributesType));
  16070. return unknownType;
  16071. }
  16072. }
  16073. }
  16074. }
  16075. var exprType;
  16076. if (node.initializer) {
  16077. exprType = checkExpression(node.initializer);
  16078. }
  16079. else {
  16080. exprType = booleanType;
  16081. }
  16082. if (correspondingPropType) {
  16083. checkTypeAssignableTo(exprType, correspondingPropType, node);
  16084. }
  16085. nameTable[node.name.text] = true;
  16086. return exprType;
  16087. }
  16088. function checkJsxSpreadAttribute(node, elementAttributesType, nameTable) {
  16089. var type = checkExpression(node.expression);
  16090. var props = getPropertiesOfType(type);
  16091. for (var _i = 0; _i < props.length; _i++) {
  16092. var prop = props[_i];
  16093. if (!nameTable[prop.name]) {
  16094. var targetPropSym = getPropertyOfType(elementAttributesType, prop.name);
  16095. if (targetPropSym) {
  16096. var msg = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property, prop.name);
  16097. checkTypeAssignableTo(getTypeOfSymbol(prop), getTypeOfSymbol(targetPropSym), node, undefined, msg);
  16098. }
  16099. nameTable[prop.name] = true;
  16100. }
  16101. }
  16102. return type;
  16103. }
  16104. function getJsxIntrinsicElementsType() {
  16105. if (!jsxIntrinsicElementsType) {
  16106. jsxIntrinsicElementsType = getExportedTypeFromNamespace(JsxNames.JSX, JsxNames.IntrinsicElements) || unknownType;
  16107. }
  16108. return jsxIntrinsicElementsType;
  16109. }
  16110. function getJsxElementTagSymbol(node) {
  16111. var flags = 8;
  16112. var links = getNodeLinks(node);
  16113. if (!links.resolvedSymbol) {
  16114. if (isJsxIntrinsicIdentifier(node.tagName)) {
  16115. links.resolvedSymbol = lookupIntrinsicTag(node);
  16116. }
  16117. else {
  16118. links.resolvedSymbol = lookupClassTag(node);
  16119. }
  16120. }
  16121. return links.resolvedSymbol;
  16122. function lookupIntrinsicTag(node) {
  16123. var intrinsicElementsType = getJsxIntrinsicElementsType();
  16124. if (intrinsicElementsType !== unknownType) {
  16125. var intrinsicProp = getPropertyOfType(intrinsicElementsType, node.tagName.text);
  16126. if (intrinsicProp) {
  16127. links.jsxFlags |= 1;
  16128. return intrinsicProp;
  16129. }
  16130. var indexSignatureType = getIndexTypeOfType(intrinsicElementsType, 0);
  16131. if (indexSignatureType) {
  16132. links.jsxFlags |= 2;
  16133. return intrinsicElementsType.symbol;
  16134. }
  16135. error(node, ts.Diagnostics.Property_0_does_not_exist_on_type_1, node.tagName.text, "JSX." + JsxNames.IntrinsicElements);
  16136. return unknownSymbol;
  16137. }
  16138. else {
  16139. if (compilerOptions.noImplicitAny) {
  16140. error(node, ts.Diagnostics.JSX_element_implicitly_has_type_any_because_no_interface_JSX_0_exists, JsxNames.IntrinsicElements);
  16141. }
  16142. }
  16143. }
  16144. function lookupClassTag(node) {
  16145. var valueSymbol = resolveJsxTagName(node);
  16146. if (valueSymbol && valueSymbol !== unknownSymbol) {
  16147. links.jsxFlags |= 4;
  16148. getSymbolLinks(valueSymbol).referenced = true;
  16149. }
  16150. return valueSymbol || unknownSymbol;
  16151. }
  16152. function resolveJsxTagName(node) {
  16153. if (node.tagName.kind === 67) {
  16154. var tag = node.tagName;
  16155. var sym = getResolvedSymbol(tag);
  16156. return sym.exportSymbol || sym;
  16157. }
  16158. else {
  16159. return checkQualifiedName(node.tagName).symbol;
  16160. }
  16161. }
  16162. }
  16163. function getJsxElementInstanceType(node) {
  16164. ts.Debug.assert(!!(getNodeLinks(node).jsxFlags & 4), "Should not call getJsxElementInstanceType on non-class Element");
  16165. var classSymbol = getJsxElementTagSymbol(node);
  16166. if (classSymbol === unknownSymbol) {
  16167. return anyType;
  16168. }
  16169. var valueType = getTypeOfSymbol(classSymbol);
  16170. if (isTypeAny(valueType)) {
  16171. return anyType;
  16172. }
  16173. var signatures = getSignaturesOfType(valueType, 1);
  16174. if (signatures.length === 0) {
  16175. signatures = getSignaturesOfType(valueType, 0);
  16176. if (signatures.length === 0) {
  16177. error(node.tagName, ts.Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, ts.getTextOfNode(node.tagName));
  16178. return unknownType;
  16179. }
  16180. }
  16181. var returnType = getUnionType(signatures.map(getReturnTypeOfSignature));
  16182. var elemClassType = getJsxGlobalElementClassType();
  16183. if (elemClassType) {
  16184. checkTypeRelatedTo(returnType, elemClassType, assignableRelation, node, ts.Diagnostics.JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements);
  16185. }
  16186. return returnType;
  16187. }
  16188. function getJsxElementPropertiesName() {
  16189. var jsxNamespace = getGlobalSymbol(JsxNames.JSX, 1536, undefined);
  16190. var attribsPropTypeSym = jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.ElementAttributesPropertyNameContainer, 793056);
  16191. var attribPropType = attribsPropTypeSym && getDeclaredTypeOfSymbol(attribsPropTypeSym);
  16192. var attribProperties = attribPropType && getPropertiesOfType(attribPropType);
  16193. if (attribProperties) {
  16194. if (attribProperties.length === 0) {
  16195. return "";
  16196. }
  16197. else if (attribProperties.length === 1) {
  16198. return attribProperties[0].name;
  16199. }
  16200. else {
  16201. error(attribsPropTypeSym.declarations[0], ts.Diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property, JsxNames.ElementAttributesPropertyNameContainer);
  16202. return undefined;
  16203. }
  16204. }
  16205. else {
  16206. return undefined;
  16207. }
  16208. }
  16209. function getJsxElementAttributesType(node) {
  16210. var links = getNodeLinks(node);
  16211. if (!links.resolvedJsxType) {
  16212. var sym = getJsxElementTagSymbol(node);
  16213. if (links.jsxFlags & 4) {
  16214. var elemInstanceType = getJsxElementInstanceType(node);
  16215. if (isTypeAny(elemInstanceType)) {
  16216. return links.resolvedJsxType = elemInstanceType;
  16217. }
  16218. var propsName = getJsxElementPropertiesName();
  16219. if (propsName === undefined) {
  16220. return links.resolvedJsxType = anyType;
  16221. }
  16222. else if (propsName === "") {
  16223. return links.resolvedJsxType = elemInstanceType;
  16224. }
  16225. else {
  16226. var attributesType = getTypeOfPropertyOfType(elemInstanceType, propsName);
  16227. if (!attributesType) {
  16228. return links.resolvedJsxType = emptyObjectType;
  16229. }
  16230. else if (isTypeAny(attributesType) || (attributesType === unknownType)) {
  16231. return links.resolvedJsxType = attributesType;
  16232. }
  16233. else if (!(attributesType.flags & 80896)) {
  16234. error(node.tagName, ts.Diagnostics.JSX_element_attributes_type_0_must_be_an_object_type, typeToString(attributesType));
  16235. return links.resolvedJsxType = anyType;
  16236. }
  16237. else {
  16238. return links.resolvedJsxType = attributesType;
  16239. }
  16240. }
  16241. }
  16242. else if (links.jsxFlags & 1) {
  16243. return links.resolvedJsxType = getTypeOfSymbol(sym);
  16244. }
  16245. else if (links.jsxFlags & 2) {
  16246. return links.resolvedJsxType = getIndexTypeOfSymbol(sym, 0);
  16247. }
  16248. else {
  16249. return links.resolvedJsxType = anyType;
  16250. }
  16251. }
  16252. return links.resolvedJsxType;
  16253. }
  16254. function getJsxAttributePropertySymbol(attrib) {
  16255. var attributesType = getJsxElementAttributesType(attrib.parent);
  16256. var prop = getPropertyOfType(attributesType, attrib.name.text);
  16257. return prop || unknownSymbol;
  16258. }
  16259. var jsxElementClassType = undefined;
  16260. function getJsxGlobalElementClassType() {
  16261. if (!jsxElementClassType) {
  16262. jsxElementClassType = getExportedTypeFromNamespace(JsxNames.JSX, JsxNames.ElementClass);
  16263. }
  16264. return jsxElementClassType;
  16265. }
  16266. function getJsxIntrinsicTagNames() {
  16267. var intrinsics = getJsxIntrinsicElementsType();
  16268. return intrinsics ? getPropertiesOfType(intrinsics) : emptyArray;
  16269. }
  16270. function checkJsxPreconditions(errorNode) {
  16271. if ((compilerOptions.jsx || 0) === 0) {
  16272. error(errorNode, ts.Diagnostics.Cannot_use_JSX_unless_the_jsx_flag_is_provided);
  16273. }
  16274. if (jsxElementType === undefined) {
  16275. if (compilerOptions.noImplicitAny) {
  16276. error(errorNode, ts.Diagnostics.JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist);
  16277. }
  16278. }
  16279. }
  16280. function checkJsxOpeningLikeElement(node) {
  16281. checkGrammarJsxElement(node);
  16282. checkJsxPreconditions(node);
  16283. if (compilerOptions.jsx === 2) {
  16284. var reactSym = resolveName(node.tagName, "React", 107455, ts.Diagnostics.Cannot_find_name_0, "React");
  16285. if (reactSym) {
  16286. getSymbolLinks(reactSym).referenced = true;
  16287. }
  16288. }
  16289. var targetAttributesType = getJsxElementAttributesType(node);
  16290. var nameTable = {};
  16291. var sawSpreadedAny = false;
  16292. for (var i = node.attributes.length - 1; i >= 0; i--) {
  16293. if (node.attributes[i].kind === 236) {
  16294. checkJsxAttribute((node.attributes[i]), targetAttributesType, nameTable);
  16295. }
  16296. else {
  16297. ts.Debug.assert(node.attributes[i].kind === 237);
  16298. var spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable);
  16299. if (isTypeAny(spreadType)) {
  16300. sawSpreadedAny = true;
  16301. }
  16302. }
  16303. }
  16304. if (targetAttributesType && !sawSpreadedAny) {
  16305. var targetProperties = getPropertiesOfType(targetAttributesType);
  16306. for (var i = 0; i < targetProperties.length; i++) {
  16307. if (!(targetProperties[i].flags & 536870912) &&
  16308. nameTable[targetProperties[i].name] === undefined) {
  16309. error(node, ts.Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
  16310. }
  16311. }
  16312. }
  16313. }
  16314. function checkJsxExpression(node) {
  16315. if (node.expression) {
  16316. return checkExpression(node.expression);
  16317. }
  16318. else {
  16319. return unknownType;
  16320. }
  16321. }
  16322. function getDeclarationKindFromSymbol(s) {
  16323. return s.valueDeclaration ? s.valueDeclaration.kind : 139;
  16324. }
  16325. function getDeclarationFlagsFromSymbol(s) {
  16326. return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 ? 16 | 128 : 0;
  16327. }
  16328. function checkClassPropertyAccess(node, left, type, prop) {
  16329. var flags = getDeclarationFlagsFromSymbol(prop);
  16330. var declaringClass = getDeclaredTypeOfSymbol(prop.parent);
  16331. if (left.kind === 93) {
  16332. var errorNode = node.kind === 164 ?
  16333. node.name :
  16334. node.right;
  16335. if (getDeclarationKindFromSymbol(prop) !== 141) {
  16336. error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
  16337. return false;
  16338. }
  16339. if (flags & 256) {
  16340. error(errorNode, ts.Diagnostics.Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression, symbolToString(prop), typeToString(declaringClass));
  16341. return false;
  16342. }
  16343. }
  16344. if (!(flags & (32 | 64))) {
  16345. return true;
  16346. }
  16347. var enclosingClassDeclaration = ts.getContainingClass(node);
  16348. var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;
  16349. if (flags & 32) {
  16350. if (declaringClass !== enclosingClass) {
  16351. error(node, ts.Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(declaringClass));
  16352. return false;
  16353. }
  16354. return true;
  16355. }
  16356. if (left.kind === 93) {
  16357. return true;
  16358. }
  16359. if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) {
  16360. error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(declaringClass));
  16361. return false;
  16362. }
  16363. if (flags & 128) {
  16364. return true;
  16365. }
  16366. if (!(getTargetType(type).flags & (1024 | 2048) && hasBaseType(type, enclosingClass))) {
  16367. error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass));
  16368. return false;
  16369. }
  16370. return true;
  16371. }
  16372. function checkPropertyAccessExpression(node) {
  16373. return checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name);
  16374. }
  16375. function checkQualifiedName(node) {
  16376. return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right);
  16377. }
  16378. function checkPropertyAccessExpressionOrQualifiedName(node, left, right) {
  16379. var type = checkExpression(left);
  16380. if (isTypeAny(type)) {
  16381. return type;
  16382. }
  16383. var apparentType = getApparentType(getWidenedType(type));
  16384. if (apparentType === unknownType) {
  16385. return unknownType;
  16386. }
  16387. var prop = getPropertyOfType(apparentType, right.text);
  16388. if (!prop) {
  16389. if (right.text) {
  16390. error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type));
  16391. }
  16392. return unknownType;
  16393. }
  16394. getNodeLinks(node).resolvedSymbol = prop;
  16395. if (prop.parent && prop.parent.flags & 32) {
  16396. checkClassPropertyAccess(node, left, type, prop);
  16397. }
  16398. return getTypeOfSymbol(prop);
  16399. }
  16400. function isValidPropertyAccess(node, propertyName) {
  16401. var left = node.kind === 164
  16402. ? node.expression
  16403. : node.left;
  16404. var type = checkExpression(left);
  16405. if (type !== unknownType && !isTypeAny(type)) {
  16406. var prop = getPropertyOfType(getWidenedType(type), propertyName);
  16407. if (prop && prop.parent && prop.parent.flags & 32) {
  16408. return checkClassPropertyAccess(node, left, type, prop);
  16409. }
  16410. }
  16411. return true;
  16412. }
  16413. function checkIndexedAccess(node) {
  16414. if (!node.argumentExpression) {
  16415. var sourceFile = getSourceFile(node);
  16416. if (node.parent.kind === 167 && node.parent.expression === node) {
  16417. var start = ts.skipTrivia(sourceFile.text, node.expression.end);
  16418. var end = node.end;
  16419. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
  16420. }
  16421. else {
  16422. var start = node.end - "]".length;
  16423. var end = node.end;
  16424. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Expression_expected);
  16425. }
  16426. }
  16427. var objectType = getApparentType(checkExpression(node.expression));
  16428. var indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType;
  16429. if (objectType === unknownType) {
  16430. return unknownType;
  16431. }
  16432. var isConstEnum = isConstEnumObjectType(objectType);
  16433. if (isConstEnum &&
  16434. (!node.argumentExpression || node.argumentExpression.kind !== 9)) {
  16435. error(node.argumentExpression, ts.Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
  16436. return unknownType;
  16437. }
  16438. if (node.argumentExpression) {
  16439. var name_11 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType);
  16440. if (name_11 !== undefined) {
  16441. var prop = getPropertyOfType(objectType, name_11);
  16442. if (prop) {
  16443. getNodeLinks(node).resolvedSymbol = prop;
  16444. return getTypeOfSymbol(prop);
  16445. }
  16446. else if (isConstEnum) {
  16447. error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_11, symbolToString(objectType.symbol));
  16448. return unknownType;
  16449. }
  16450. }
  16451. }
  16452. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 | 132 | 16777216)) {
  16453. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132)) {
  16454. var numberIndexType = getIndexTypeOfType(objectType, 1);
  16455. if (numberIndexType) {
  16456. return numberIndexType;
  16457. }
  16458. }
  16459. var stringIndexType = getIndexTypeOfType(objectType, 0);
  16460. if (stringIndexType) {
  16461. return stringIndexType;
  16462. }
  16463. if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) {
  16464. error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type);
  16465. }
  16466. return anyType;
  16467. }
  16468. error(node, ts.Diagnostics.An_index_expression_argument_must_be_of_type_string_number_symbol_or_any);
  16469. return unknownType;
  16470. }
  16471. function getPropertyNameForIndexedAccess(indexArgumentExpression, indexArgumentType) {
  16472. if (indexArgumentExpression.kind === 9 || indexArgumentExpression.kind === 8) {
  16473. return indexArgumentExpression.text;
  16474. }
  16475. if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, false)) {
  16476. var rightHandSideName = indexArgumentExpression.name.text;
  16477. return ts.getPropertyNameForKnownSymbolName(rightHandSideName);
  16478. }
  16479. return undefined;
  16480. }
  16481. function checkThatExpressionIsProperSymbolReference(expression, expressionType, reportError) {
  16482. if (expressionType === unknownType) {
  16483. return false;
  16484. }
  16485. if (!ts.isWellKnownSymbolSyntactically(expression)) {
  16486. return false;
  16487. }
  16488. if ((expressionType.flags & 16777216) === 0) {
  16489. if (reportError) {
  16490. error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression));
  16491. }
  16492. return false;
  16493. }
  16494. var leftHandSide = expression.expression;
  16495. var leftHandSideSymbol = getResolvedSymbol(leftHandSide);
  16496. if (!leftHandSideSymbol) {
  16497. return false;
  16498. }
  16499. var globalESSymbol = getGlobalESSymbolConstructorSymbol();
  16500. if (!globalESSymbol) {
  16501. return false;
  16502. }
  16503. if (leftHandSideSymbol !== globalESSymbol) {
  16504. if (reportError) {
  16505. error(leftHandSide, ts.Diagnostics.Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object);
  16506. }
  16507. return false;
  16508. }
  16509. return true;
  16510. }
  16511. function resolveUntypedCall(node) {
  16512. if (node.kind === 168) {
  16513. checkExpression(node.template);
  16514. }
  16515. else if (node.kind !== 137) {
  16516. ts.forEach(node.arguments, function (argument) {
  16517. checkExpression(argument);
  16518. });
  16519. }
  16520. return anySignature;
  16521. }
  16522. function resolveErrorCall(node) {
  16523. resolveUntypedCall(node);
  16524. return unknownSignature;
  16525. }
  16526. function reorderCandidates(signatures, result) {
  16527. var lastParent;
  16528. var lastSymbol;
  16529. var cutoffIndex = 0;
  16530. var index;
  16531. var specializedIndex = -1;
  16532. var spliceIndex;
  16533. ts.Debug.assert(!result.length);
  16534. for (var _i = 0; _i < signatures.length; _i++) {
  16535. var signature = signatures[_i];
  16536. var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
  16537. var parent_5 = signature.declaration && signature.declaration.parent;
  16538. if (!lastSymbol || symbol === lastSymbol) {
  16539. if (lastParent && parent_5 === lastParent) {
  16540. index++;
  16541. }
  16542. else {
  16543. lastParent = parent_5;
  16544. index = cutoffIndex;
  16545. }
  16546. }
  16547. else {
  16548. index = cutoffIndex = result.length;
  16549. lastParent = parent_5;
  16550. }
  16551. lastSymbol = symbol;
  16552. if (signature.hasStringLiterals) {
  16553. specializedIndex++;
  16554. spliceIndex = specializedIndex;
  16555. cutoffIndex++;
  16556. }
  16557. else {
  16558. spliceIndex = index;
  16559. }
  16560. result.splice(spliceIndex, 0, signature);
  16561. }
  16562. }
  16563. function getSpreadArgumentIndex(args) {
  16564. for (var i = 0; i < args.length; i++) {
  16565. var arg = args[i];
  16566. if (arg && arg.kind === 183) {
  16567. return i;
  16568. }
  16569. }
  16570. return -1;
  16571. }
  16572. function hasCorrectArity(node, args, signature) {
  16573. var adjustedArgCount;
  16574. var typeArguments;
  16575. var callIsIncomplete;
  16576. var isDecorator;
  16577. var spreadArgIndex = -1;
  16578. if (node.kind === 168) {
  16579. var tagExpression = node;
  16580. adjustedArgCount = args.length;
  16581. typeArguments = undefined;
  16582. if (tagExpression.template.kind === 181) {
  16583. var templateExpression = tagExpression.template;
  16584. var lastSpan = ts.lastOrUndefined(templateExpression.templateSpans);
  16585. ts.Debug.assert(lastSpan !== undefined);
  16586. callIsIncomplete = ts.nodeIsMissing(lastSpan.literal) || !!lastSpan.literal.isUnterminated;
  16587. }
  16588. else {
  16589. var templateLiteral = tagExpression.template;
  16590. ts.Debug.assert(templateLiteral.kind === 11);
  16591. callIsIncomplete = !!templateLiteral.isUnterminated;
  16592. }
  16593. }
  16594. else if (node.kind === 137) {
  16595. isDecorator = true;
  16596. typeArguments = undefined;
  16597. adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature);
  16598. }
  16599. else {
  16600. var callExpression = node;
  16601. if (!callExpression.arguments) {
  16602. ts.Debug.assert(callExpression.kind === 167);
  16603. return signature.minArgumentCount === 0;
  16604. }
  16605. adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length;
  16606. callIsIncomplete = callExpression.arguments.end === callExpression.end;
  16607. typeArguments = callExpression.typeArguments;
  16608. spreadArgIndex = getSpreadArgumentIndex(args);
  16609. }
  16610. var hasRightNumberOfTypeArgs = !typeArguments ||
  16611. (signature.typeParameters && typeArguments.length === signature.typeParameters.length);
  16612. if (!hasRightNumberOfTypeArgs) {
  16613. return false;
  16614. }
  16615. if (spreadArgIndex >= 0) {
  16616. return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1;
  16617. }
  16618. if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) {
  16619. return false;
  16620. }
  16621. var hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount;
  16622. return callIsIncomplete || hasEnoughArguments;
  16623. }
  16624. function getSingleCallSignature(type) {
  16625. if (type.flags & 80896) {
  16626. var resolved = resolveStructuredTypeMembers(type);
  16627. if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 &&
  16628. resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) {
  16629. return resolved.callSignatures[0];
  16630. }
  16631. }
  16632. return undefined;
  16633. }
  16634. function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper) {
  16635. var context = createInferenceContext(signature.typeParameters, true);
  16636. forEachMatchingParameterType(contextualSignature, signature, function (source, target) {
  16637. inferTypes(context, instantiateType(source, contextualMapper), target);
  16638. });
  16639. return getSignatureInstantiation(signature, getInferredTypes(context));
  16640. }
  16641. function inferTypeArguments(node, signature, args, excludeArgument, context) {
  16642. var typeParameters = signature.typeParameters;
  16643. var inferenceMapper = createInferenceMapper(context);
  16644. for (var i = 0; i < typeParameters.length; i++) {
  16645. if (!context.inferences[i].isFixed) {
  16646. context.inferredTypes[i] = undefined;
  16647. }
  16648. }
  16649. if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) {
  16650. context.failedTypeParameterIndex = undefined;
  16651. }
  16652. var argCount = getEffectiveArgumentCount(node, args, signature);
  16653. for (var i = 0; i < argCount; i++) {
  16654. var arg = getEffectiveArgument(node, args, i);
  16655. if (arg === undefined || arg.kind !== 185) {
  16656. var paramType = getTypeAtPosition(signature, i);
  16657. var argType = getEffectiveArgumentType(node, i, arg);
  16658. if (argType === undefined) {
  16659. var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
  16660. argType = checkExpressionWithContextualType(arg, paramType, mapper);
  16661. }
  16662. inferTypes(context, argType, paramType);
  16663. }
  16664. }
  16665. if (excludeArgument) {
  16666. for (var i = 0; i < argCount; i++) {
  16667. if (excludeArgument[i] === false) {
  16668. var arg = args[i];
  16669. var paramType = getTypeAtPosition(signature, i);
  16670. inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType);
  16671. }
  16672. }
  16673. }
  16674. getInferredTypes(context);
  16675. }
  16676. function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors, headMessage) {
  16677. var typeParameters = signature.typeParameters;
  16678. var typeArgumentsAreAssignable = true;
  16679. for (var i = 0; i < typeParameters.length; i++) {
  16680. var typeArgNode = typeArguments[i];
  16681. var typeArgument = getTypeFromTypeNode(typeArgNode);
  16682. typeArgumentResultTypes[i] = typeArgument;
  16683. if (typeArgumentsAreAssignable) {
  16684. var constraint = getConstraintOfTypeParameter(typeParameters[i]);
  16685. if (constraint) {
  16686. var errorInfo = void 0;
  16687. var typeArgumentHeadMessage = ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1;
  16688. if (reportErrors && headMessage) {
  16689. errorInfo = ts.chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage);
  16690. typeArgumentHeadMessage = headMessage;
  16691. }
  16692. typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, typeArgumentHeadMessage, errorInfo);
  16693. }
  16694. }
  16695. }
  16696. return typeArgumentsAreAssignable;
  16697. }
  16698. function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) {
  16699. var argCount = getEffectiveArgumentCount(node, args, signature);
  16700. for (var i = 0; i < argCount; i++) {
  16701. var arg = getEffectiveArgument(node, args, i);
  16702. if (arg === undefined || arg.kind !== 185) {
  16703. var paramType = getTypeAtPosition(signature, i);
  16704. var argType = getEffectiveArgumentType(node, i, arg);
  16705. if (argType === undefined) {
  16706. argType = arg.kind === 9 && !reportErrors
  16707. ? getStringLiteralType(arg)
  16708. : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
  16709. }
  16710. var errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined;
  16711. var headMessage = ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1;
  16712. if (!checkTypeRelatedTo(argType, paramType, relation, errorNode, headMessage)) {
  16713. return false;
  16714. }
  16715. }
  16716. }
  16717. return true;
  16718. }
  16719. function getEffectiveCallArguments(node) {
  16720. var args;
  16721. if (node.kind === 168) {
  16722. var template = node.template;
  16723. args = [undefined];
  16724. if (template.kind === 181) {
  16725. ts.forEach(template.templateSpans, function (span) {
  16726. args.push(span.expression);
  16727. });
  16728. }
  16729. }
  16730. else if (node.kind === 137) {
  16731. return undefined;
  16732. }
  16733. else {
  16734. args = node.arguments || emptyArray;
  16735. }
  16736. return args;
  16737. }
  16738. function getEffectiveArgumentCount(node, args, signature) {
  16739. if (node.kind === 137) {
  16740. switch (node.parent.kind) {
  16741. case 212:
  16742. case 184:
  16743. return 1;
  16744. case 139:
  16745. return 2;
  16746. case 141:
  16747. case 143:
  16748. case 144:
  16749. return signature.parameters.length >= 3 ? 3 : 2;
  16750. case 136:
  16751. return 3;
  16752. }
  16753. }
  16754. else {
  16755. return args.length;
  16756. }
  16757. }
  16758. function getEffectiveDecoratorFirstArgumentType(node) {
  16759. switch (node.kind) {
  16760. case 212:
  16761. case 184:
  16762. var classSymbol = getSymbolOfNode(node);
  16763. return getTypeOfSymbol(classSymbol);
  16764. case 136:
  16765. node = node.parent;
  16766. if (node.kind === 142) {
  16767. var classSymbol_1 = getSymbolOfNode(node);
  16768. return getTypeOfSymbol(classSymbol_1);
  16769. }
  16770. case 139:
  16771. case 141:
  16772. case 143:
  16773. case 144:
  16774. return getParentTypeOfClassElement(node);
  16775. default:
  16776. ts.Debug.fail("Unsupported decorator target.");
  16777. return unknownType;
  16778. }
  16779. }
  16780. function getEffectiveDecoratorSecondArgumentType(node) {
  16781. switch (node.kind) {
  16782. case 212:
  16783. ts.Debug.fail("Class decorators should not have a second synthetic argument.");
  16784. return unknownType;
  16785. case 136:
  16786. node = node.parent;
  16787. if (node.kind === 142) {
  16788. return anyType;
  16789. }
  16790. case 139:
  16791. case 141:
  16792. case 143:
  16793. case 144:
  16794. var element = node;
  16795. switch (element.name.kind) {
  16796. case 67:
  16797. case 8:
  16798. case 9:
  16799. return getStringLiteralType(element.name);
  16800. case 134:
  16801. var nameType = checkComputedPropertyName(element.name);
  16802. if (allConstituentTypesHaveKind(nameType, 16777216)) {
  16803. return nameType;
  16804. }
  16805. else {
  16806. return stringType;
  16807. }
  16808. default:
  16809. ts.Debug.fail("Unsupported property name.");
  16810. return unknownType;
  16811. }
  16812. default:
  16813. ts.Debug.fail("Unsupported decorator target.");
  16814. return unknownType;
  16815. }
  16816. }
  16817. function getEffectiveDecoratorThirdArgumentType(node) {
  16818. switch (node.kind) {
  16819. case 212:
  16820. ts.Debug.fail("Class decorators should not have a third synthetic argument.");
  16821. return unknownType;
  16822. case 136:
  16823. return numberType;
  16824. case 139:
  16825. ts.Debug.fail("Property decorators should not have a third synthetic argument.");
  16826. return unknownType;
  16827. case 141:
  16828. case 143:
  16829. case 144:
  16830. var propertyType = getTypeOfNode(node);
  16831. return createTypedPropertyDescriptorType(propertyType);
  16832. default:
  16833. ts.Debug.fail("Unsupported decorator target.");
  16834. return unknownType;
  16835. }
  16836. }
  16837. function getEffectiveDecoratorArgumentType(node, argIndex) {
  16838. if (argIndex === 0) {
  16839. return getEffectiveDecoratorFirstArgumentType(node.parent);
  16840. }
  16841. else if (argIndex === 1) {
  16842. return getEffectiveDecoratorSecondArgumentType(node.parent);
  16843. }
  16844. else if (argIndex === 2) {
  16845. return getEffectiveDecoratorThirdArgumentType(node.parent);
  16846. }
  16847. ts.Debug.fail("Decorators should not have a fourth synthetic argument.");
  16848. return unknownType;
  16849. }
  16850. function getEffectiveArgumentType(node, argIndex, arg) {
  16851. if (node.kind === 137) {
  16852. return getEffectiveDecoratorArgumentType(node, argIndex);
  16853. }
  16854. else if (argIndex === 0 && node.kind === 168) {
  16855. return globalTemplateStringsArrayType;
  16856. }
  16857. return undefined;
  16858. }
  16859. function getEffectiveArgument(node, args, argIndex) {
  16860. if (node.kind === 137 ||
  16861. (argIndex === 0 && node.kind === 168)) {
  16862. return undefined;
  16863. }
  16864. return args[argIndex];
  16865. }
  16866. function getEffectiveArgumentErrorNode(node, argIndex, arg) {
  16867. if (node.kind === 137) {
  16868. return node.expression;
  16869. }
  16870. else if (argIndex === 0 && node.kind === 168) {
  16871. return node.template;
  16872. }
  16873. else {
  16874. return arg;
  16875. }
  16876. }
  16877. function resolveCall(node, signatures, candidatesOutArray, headMessage) {
  16878. var isTaggedTemplate = node.kind === 168;
  16879. var isDecorator = node.kind === 137;
  16880. var typeArguments;
  16881. if (!isTaggedTemplate && !isDecorator) {
  16882. typeArguments = node.typeArguments;
  16883. if (node.expression.kind !== 93) {
  16884. ts.forEach(typeArguments, checkSourceElement);
  16885. }
  16886. }
  16887. var candidates = candidatesOutArray || [];
  16888. reorderCandidates(signatures, candidates);
  16889. if (!candidates.length) {
  16890. reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
  16891. return resolveErrorCall(node);
  16892. }
  16893. var args = getEffectiveCallArguments(node);
  16894. var excludeArgument;
  16895. if (!isDecorator) {
  16896. for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) {
  16897. if (isContextSensitive(args[i])) {
  16898. if (!excludeArgument) {
  16899. excludeArgument = new Array(args.length);
  16900. }
  16901. excludeArgument[i] = true;
  16902. }
  16903. }
  16904. }
  16905. var candidateForArgumentError;
  16906. var candidateForTypeArgumentError;
  16907. var resultOfFailedInference;
  16908. var result;
  16909. if (candidates.length > 1) {
  16910. result = chooseOverload(candidates, subtypeRelation);
  16911. }
  16912. if (!result) {
  16913. candidateForArgumentError = undefined;
  16914. candidateForTypeArgumentError = undefined;
  16915. resultOfFailedInference = undefined;
  16916. result = chooseOverload(candidates, assignableRelation);
  16917. }
  16918. if (result) {
  16919. return result;
  16920. }
  16921. if (candidateForArgumentError) {
  16922. checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, undefined, true);
  16923. }
  16924. else if (candidateForTypeArgumentError) {
  16925. if (!isTaggedTemplate && !isDecorator && typeArguments) {
  16926. checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], true, headMessage);
  16927. }
  16928. else {
  16929. ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);
  16930. var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex];
  16931. var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex);
  16932. 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));
  16933. if (headMessage) {
  16934. diagnosticChainHead = ts.chainDiagnosticMessages(diagnosticChainHead, headMessage);
  16935. }
  16936. reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead);
  16937. }
  16938. }
  16939. else {
  16940. reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
  16941. }
  16942. if (!produceDiagnostics) {
  16943. for (var _i = 0; _i < candidates.length; _i++) {
  16944. var candidate = candidates[_i];
  16945. if (hasCorrectArity(node, args, candidate)) {
  16946. if (candidate.typeParameters && typeArguments) {
  16947. candidate = getSignatureInstantiation(candidate, ts.map(typeArguments, getTypeFromTypeNode));
  16948. }
  16949. return candidate;
  16950. }
  16951. }
  16952. }
  16953. return resolveErrorCall(node);
  16954. function reportError(message, arg0, arg1, arg2) {
  16955. var errorInfo;
  16956. errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
  16957. if (headMessage) {
  16958. errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage);
  16959. }
  16960. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo));
  16961. }
  16962. function chooseOverload(candidates, relation) {
  16963. for (var _i = 0; _i < candidates.length; _i++) {
  16964. var originalCandidate = candidates[_i];
  16965. if (!hasCorrectArity(node, args, originalCandidate)) {
  16966. continue;
  16967. }
  16968. var candidate = void 0;
  16969. var typeArgumentsAreValid = void 0;
  16970. var inferenceContext = originalCandidate.typeParameters
  16971. ? createInferenceContext(originalCandidate.typeParameters, false)
  16972. : undefined;
  16973. while (true) {
  16974. candidate = originalCandidate;
  16975. if (candidate.typeParameters) {
  16976. var typeArgumentTypes = void 0;
  16977. if (typeArguments) {
  16978. typeArgumentTypes = new Array(candidate.typeParameters.length);
  16979. typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, false);
  16980. }
  16981. else {
  16982. inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
  16983. typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined;
  16984. typeArgumentTypes = inferenceContext.inferredTypes;
  16985. }
  16986. if (!typeArgumentsAreValid) {
  16987. break;
  16988. }
  16989. candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
  16990. }
  16991. if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, false)) {
  16992. break;
  16993. }
  16994. var index = excludeArgument ? ts.indexOf(excludeArgument, true) : -1;
  16995. if (index < 0) {
  16996. return candidate;
  16997. }
  16998. excludeArgument[index] = false;
  16999. }
  17000. if (originalCandidate.typeParameters) {
  17001. var instantiatedCandidate = candidate;
  17002. if (typeArgumentsAreValid) {
  17003. candidateForArgumentError = instantiatedCandidate;
  17004. }
  17005. else {
  17006. candidateForTypeArgumentError = originalCandidate;
  17007. if (!typeArguments) {
  17008. resultOfFailedInference = inferenceContext;
  17009. }
  17010. }
  17011. }
  17012. else {
  17013. ts.Debug.assert(originalCandidate === candidate);
  17014. candidateForArgumentError = originalCandidate;
  17015. }
  17016. }
  17017. return undefined;
  17018. }
  17019. }
  17020. function resolveCallExpression(node, candidatesOutArray) {
  17021. if (node.expression.kind === 93) {
  17022. var superType = checkSuperExpression(node.expression);
  17023. if (superType !== unknownType) {
  17024. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node));
  17025. var baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments);
  17026. return resolveCall(node, baseConstructors, candidatesOutArray);
  17027. }
  17028. return resolveUntypedCall(node);
  17029. }
  17030. var funcType = checkExpression(node.expression);
  17031. var apparentType = getApparentType(funcType);
  17032. if (apparentType === unknownType) {
  17033. return resolveErrorCall(node);
  17034. }
  17035. var callSignatures = getSignaturesOfType(apparentType, 0);
  17036. var constructSignatures = getSignaturesOfType(apparentType, 1);
  17037. if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) {
  17038. if (funcType !== unknownType && node.typeArguments) {
  17039. error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
  17040. }
  17041. return resolveUntypedCall(node);
  17042. }
  17043. if (!callSignatures.length) {
  17044. if (constructSignatures.length) {
  17045. error(node, ts.Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
  17046. }
  17047. else {
  17048. error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  17049. }
  17050. return resolveErrorCall(node);
  17051. }
  17052. return resolveCall(node, callSignatures, candidatesOutArray);
  17053. }
  17054. function resolveNewExpression(node, candidatesOutArray) {
  17055. if (node.arguments && languageVersion < 1) {
  17056. var spreadIndex = getSpreadArgumentIndex(node.arguments);
  17057. if (spreadIndex >= 0) {
  17058. error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher);
  17059. }
  17060. }
  17061. var expressionType = checkExpression(node.expression);
  17062. expressionType = getApparentType(expressionType);
  17063. if (expressionType === unknownType) {
  17064. return resolveErrorCall(node);
  17065. }
  17066. var valueDecl = expressionType.symbol && ts.getDeclarationOfKind(expressionType.symbol, 212);
  17067. if (valueDecl && valueDecl.flags & 256) {
  17068. error(node, ts.Diagnostics.Cannot_create_an_instance_of_the_abstract_class_0, ts.declarationNameToString(valueDecl.name));
  17069. return resolveErrorCall(node);
  17070. }
  17071. if (isTypeAny(expressionType)) {
  17072. if (node.typeArguments) {
  17073. error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
  17074. }
  17075. return resolveUntypedCall(node);
  17076. }
  17077. var constructSignatures = getSignaturesOfType(expressionType, 1);
  17078. if (constructSignatures.length) {
  17079. return resolveCall(node, constructSignatures, candidatesOutArray);
  17080. }
  17081. var callSignatures = getSignaturesOfType(expressionType, 0);
  17082. if (callSignatures.length) {
  17083. var signature = resolveCall(node, callSignatures, candidatesOutArray);
  17084. if (getReturnTypeOfSignature(signature) !== voidType) {
  17085. error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword);
  17086. }
  17087. return signature;
  17088. }
  17089. error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature);
  17090. return resolveErrorCall(node);
  17091. }
  17092. function resolveTaggedTemplateExpression(node, candidatesOutArray) {
  17093. var tagType = checkExpression(node.tag);
  17094. var apparentType = getApparentType(tagType);
  17095. if (apparentType === unknownType) {
  17096. return resolveErrorCall(node);
  17097. }
  17098. var callSignatures = getSignaturesOfType(apparentType, 0);
  17099. if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) {
  17100. return resolveUntypedCall(node);
  17101. }
  17102. if (!callSignatures.length) {
  17103. error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  17104. return resolveErrorCall(node);
  17105. }
  17106. return resolveCall(node, callSignatures, candidatesOutArray);
  17107. }
  17108. function getDiagnosticHeadMessageForDecoratorResolution(node) {
  17109. switch (node.parent.kind) {
  17110. case 212:
  17111. case 184:
  17112. return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression;
  17113. case 136:
  17114. return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression;
  17115. case 139:
  17116. return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression;
  17117. case 141:
  17118. case 143:
  17119. case 144:
  17120. return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression;
  17121. }
  17122. }
  17123. function resolveDecorator(node, candidatesOutArray) {
  17124. var funcType = checkExpression(node.expression);
  17125. var apparentType = getApparentType(funcType);
  17126. if (apparentType === unknownType) {
  17127. return resolveErrorCall(node);
  17128. }
  17129. var callSignatures = getSignaturesOfType(apparentType, 0);
  17130. if (funcType === anyType || (!callSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) {
  17131. return resolveUntypedCall(node);
  17132. }
  17133. var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
  17134. if (!callSignatures.length) {
  17135. var errorInfo;
  17136. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  17137. errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage);
  17138. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo));
  17139. return resolveErrorCall(node);
  17140. }
  17141. return resolveCall(node, callSignatures, candidatesOutArray, headMessage);
  17142. }
  17143. function getResolvedSignature(node, candidatesOutArray) {
  17144. var links = getNodeLinks(node);
  17145. if (!links.resolvedSignature || candidatesOutArray) {
  17146. links.resolvedSignature = anySignature;
  17147. if (node.kind === 166) {
  17148. links.resolvedSignature = resolveCallExpression(node, candidatesOutArray);
  17149. }
  17150. else if (node.kind === 167) {
  17151. links.resolvedSignature = resolveNewExpression(node, candidatesOutArray);
  17152. }
  17153. else if (node.kind === 168) {
  17154. links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray);
  17155. }
  17156. else if (node.kind === 137) {
  17157. links.resolvedSignature = resolveDecorator(node, candidatesOutArray);
  17158. }
  17159. else {
  17160. ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable.");
  17161. }
  17162. }
  17163. return links.resolvedSignature;
  17164. }
  17165. function checkCallExpression(node) {
  17166. checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments);
  17167. var signature = getResolvedSignature(node);
  17168. if (node.expression.kind === 93) {
  17169. return voidType;
  17170. }
  17171. if (node.kind === 167) {
  17172. var declaration = signature.declaration;
  17173. if (declaration &&
  17174. declaration.kind !== 142 &&
  17175. declaration.kind !== 146 &&
  17176. declaration.kind !== 151) {
  17177. if (compilerOptions.noImplicitAny) {
  17178. error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
  17179. }
  17180. return anyType;
  17181. }
  17182. }
  17183. return getReturnTypeOfSignature(signature);
  17184. }
  17185. function checkTaggedTemplateExpression(node) {
  17186. return getReturnTypeOfSignature(getResolvedSignature(node));
  17187. }
  17188. function checkAssertion(node) {
  17189. var exprType = getRegularTypeOfObjectLiteral(checkExpression(node.expression));
  17190. var targetType = getTypeFromTypeNode(node.type);
  17191. if (produceDiagnostics && targetType !== unknownType) {
  17192. var widenedType = getWidenedType(exprType);
  17193. if (!(isTypeAssignableTo(targetType, widenedType))) {
  17194. checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
  17195. }
  17196. }
  17197. return targetType;
  17198. }
  17199. function getTypeAtPosition(signature, pos) {
  17200. return signature.hasRestParameter ?
  17201. pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
  17202. pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
  17203. }
  17204. function assignContextualParameterTypes(signature, context, mapper) {
  17205. var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
  17206. for (var i = 0; i < len; i++) {
  17207. var parameter = signature.parameters[i];
  17208. var contextualParameterType = getTypeAtPosition(context, i);
  17209. assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper);
  17210. }
  17211. if (signature.hasRestParameter && context.hasRestParameter && signature.parameters.length >= context.parameters.length) {
  17212. var parameter = ts.lastOrUndefined(signature.parameters);
  17213. var contextualParameterType = getTypeOfSymbol(ts.lastOrUndefined(context.parameters));
  17214. assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper);
  17215. }
  17216. }
  17217. function assignTypeToParameterAndFixTypeParameters(parameter, contextualType, mapper) {
  17218. var links = getSymbolLinks(parameter);
  17219. if (!links.type) {
  17220. links.type = instantiateType(contextualType, mapper);
  17221. }
  17222. else if (isInferentialContext(mapper)) {
  17223. inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper));
  17224. }
  17225. }
  17226. function createPromiseType(promisedType) {
  17227. var globalPromiseType = getGlobalPromiseType();
  17228. if (globalPromiseType !== emptyGenericType) {
  17229. promisedType = getAwaitedType(promisedType);
  17230. return createTypeReference(globalPromiseType, [promisedType]);
  17231. }
  17232. return emptyObjectType;
  17233. }
  17234. function getReturnTypeFromBody(func, contextualMapper) {
  17235. var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
  17236. if (!func.body) {
  17237. return unknownType;
  17238. }
  17239. var isAsync = ts.isAsyncFunctionLike(func);
  17240. var type;
  17241. if (func.body.kind !== 190) {
  17242. type = checkExpressionCached(func.body, contextualMapper);
  17243. if (isAsync) {
  17244. type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
  17245. }
  17246. }
  17247. else {
  17248. var types;
  17249. var funcIsGenerator = !!func.asteriskToken;
  17250. if (funcIsGenerator) {
  17251. types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper);
  17252. if (types.length === 0) {
  17253. var iterableIteratorAny = createIterableIteratorType(anyType);
  17254. if (compilerOptions.noImplicitAny) {
  17255. error(func.asteriskToken, ts.Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny));
  17256. }
  17257. return iterableIteratorAny;
  17258. }
  17259. }
  17260. else {
  17261. types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync);
  17262. if (types.length === 0) {
  17263. if (isAsync) {
  17264. var promiseType = createPromiseType(voidType);
  17265. if (promiseType === emptyObjectType) {
  17266. error(func, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
  17267. return unknownType;
  17268. }
  17269. return promiseType;
  17270. }
  17271. else {
  17272. return voidType;
  17273. }
  17274. }
  17275. }
  17276. type = contextualSignature ? getUnionType(types) : getCommonSupertype(types);
  17277. if (!type) {
  17278. if (funcIsGenerator) {
  17279. error(func, ts.Diagnostics.No_best_common_type_exists_among_yield_expressions);
  17280. return createIterableIteratorType(unknownType);
  17281. }
  17282. else {
  17283. error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions);
  17284. return unknownType;
  17285. }
  17286. }
  17287. if (funcIsGenerator) {
  17288. type = createIterableIteratorType(type);
  17289. }
  17290. }
  17291. if (!contextualSignature) {
  17292. reportErrorsFromWidening(func, type);
  17293. }
  17294. var widenedType = getWidenedType(type);
  17295. if (isAsync) {
  17296. var promiseType = createPromiseType(widenedType);
  17297. if (promiseType === emptyObjectType) {
  17298. error(func, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
  17299. return unknownType;
  17300. }
  17301. return promiseType;
  17302. }
  17303. else {
  17304. return widenedType;
  17305. }
  17306. }
  17307. function checkAndAggregateYieldOperandTypes(body, contextualMapper) {
  17308. var aggregatedTypes = [];
  17309. ts.forEachYieldExpression(body, function (yieldExpression) {
  17310. var expr = yieldExpression.expression;
  17311. if (expr) {
  17312. var type = checkExpressionCached(expr, contextualMapper);
  17313. if (yieldExpression.asteriskToken) {
  17314. type = checkElementTypeOfIterable(type, yieldExpression.expression);
  17315. }
  17316. if (!ts.contains(aggregatedTypes, type)) {
  17317. aggregatedTypes.push(type);
  17318. }
  17319. }
  17320. });
  17321. return aggregatedTypes;
  17322. }
  17323. function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync) {
  17324. var aggregatedTypes = [];
  17325. ts.forEachReturnStatement(body, function (returnStatement) {
  17326. var expr = returnStatement.expression;
  17327. if (expr) {
  17328. var type = checkExpressionCached(expr, contextualMapper);
  17329. if (isAsync) {
  17330. type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
  17331. }
  17332. if (!ts.contains(aggregatedTypes, type)) {
  17333. aggregatedTypes.push(type);
  17334. }
  17335. }
  17336. });
  17337. return aggregatedTypes;
  17338. }
  17339. function bodyContainsAReturnStatement(funcBody) {
  17340. return ts.forEachReturnStatement(funcBody, function (returnStatement) {
  17341. return true;
  17342. });
  17343. }
  17344. function bodyContainsSingleThrowStatement(body) {
  17345. return (body.statements.length === 1) && (body.statements[0].kind === 206);
  17346. }
  17347. function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) {
  17348. if (!produceDiagnostics) {
  17349. return;
  17350. }
  17351. if (returnType === voidType || isTypeAny(returnType)) {
  17352. return;
  17353. }
  17354. if (ts.nodeIsMissing(func.body) || func.body.kind !== 190) {
  17355. return;
  17356. }
  17357. var bodyBlock = func.body;
  17358. if (bodyContainsAReturnStatement(bodyBlock)) {
  17359. return;
  17360. }
  17361. if (bodyContainsSingleThrowStatement(bodyBlock)) {
  17362. return;
  17363. }
  17364. 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);
  17365. }
  17366. function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) {
  17367. ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node));
  17368. var hasGrammarError = checkGrammarFunctionLikeDeclaration(node);
  17369. if (!hasGrammarError && node.kind === 171) {
  17370. checkGrammarForGenerator(node);
  17371. }
  17372. if (contextualMapper === identityMapper && isContextSensitive(node)) {
  17373. return anyFunctionType;
  17374. }
  17375. var isAsync = ts.isAsyncFunctionLike(node);
  17376. if (isAsync) {
  17377. emitAwaiter = true;
  17378. }
  17379. var links = getNodeLinks(node);
  17380. var type = getTypeOfSymbol(node.symbol);
  17381. var contextSensitive = isContextSensitive(node);
  17382. var mightFixTypeParameters = contextSensitive && isInferentialContext(contextualMapper);
  17383. if (mightFixTypeParameters || !(links.flags & 1024)) {
  17384. var contextualSignature = getContextualSignature(node);
  17385. var contextChecked = !!(links.flags & 1024);
  17386. if (mightFixTypeParameters || !contextChecked) {
  17387. links.flags |= 1024;
  17388. if (contextualSignature) {
  17389. var signature = getSignaturesOfType(type, 0)[0];
  17390. if (contextSensitive) {
  17391. assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper);
  17392. }
  17393. if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) {
  17394. var returnType = getReturnTypeFromBody(node, contextualMapper);
  17395. if (!signature.resolvedReturnType) {
  17396. signature.resolvedReturnType = returnType;
  17397. }
  17398. }
  17399. }
  17400. if (!contextChecked) {
  17401. checkSignatureDeclaration(node);
  17402. }
  17403. }
  17404. }
  17405. if (produceDiagnostics && node.kind !== 141 && node.kind !== 140) {
  17406. checkCollisionWithCapturedSuperVariable(node, node.name);
  17407. checkCollisionWithCapturedThisVariable(node, node.name);
  17408. }
  17409. return type;
  17410. }
  17411. function checkFunctionExpressionOrObjectLiteralMethodBody(node) {
  17412. ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node));
  17413. var isAsync = ts.isAsyncFunctionLike(node);
  17414. if (isAsync) {
  17415. emitAwaiter = true;
  17416. }
  17417. var returnType = node.type && getTypeFromTypeNode(node.type);
  17418. var promisedType;
  17419. if (returnType && isAsync) {
  17420. promisedType = checkAsyncFunctionReturnType(node);
  17421. }
  17422. if (returnType && !node.asteriskToken) {
  17423. checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType);
  17424. }
  17425. if (node.body) {
  17426. if (!node.type) {
  17427. getReturnTypeOfSignature(getSignatureFromDeclaration(node));
  17428. }
  17429. if (node.body.kind === 190) {
  17430. checkSourceElement(node.body);
  17431. }
  17432. else {
  17433. var exprType = checkExpression(node.body);
  17434. if (returnType) {
  17435. if (isAsync) {
  17436. var awaitedType = checkAwaitedType(exprType, node.body, ts.Diagnostics.Expression_body_for_async_arrow_function_does_not_have_a_valid_callable_then_member);
  17437. checkTypeAssignableTo(awaitedType, promisedType, node.body);
  17438. }
  17439. else {
  17440. checkTypeAssignableTo(exprType, returnType, node.body);
  17441. }
  17442. }
  17443. checkFunctionAndClassExpressionBodies(node.body);
  17444. }
  17445. }
  17446. }
  17447. function checkArithmeticOperandType(operand, type, diagnostic) {
  17448. if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132)) {
  17449. error(operand, diagnostic);
  17450. return false;
  17451. }
  17452. return true;
  17453. }
  17454. function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) {
  17455. function findSymbol(n) {
  17456. var symbol = getNodeLinks(n).resolvedSymbol;
  17457. return symbol && getExportSymbolOfValueSymbolIfExported(symbol);
  17458. }
  17459. function isReferenceOrErrorExpression(n) {
  17460. switch (n.kind) {
  17461. case 67: {
  17462. var symbol = findSymbol(n);
  17463. return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3) !== 0;
  17464. }
  17465. case 164: {
  17466. var symbol = findSymbol(n);
  17467. return !symbol || symbol === unknownSymbol || (symbol.flags & ~8) !== 0;
  17468. }
  17469. case 165:
  17470. return true;
  17471. case 170:
  17472. return isReferenceOrErrorExpression(n.expression);
  17473. default:
  17474. return false;
  17475. }
  17476. }
  17477. function isConstVariableReference(n) {
  17478. switch (n.kind) {
  17479. case 67:
  17480. case 164: {
  17481. var symbol = findSymbol(n);
  17482. return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 32768) !== 0;
  17483. }
  17484. case 165: {
  17485. var index = n.argumentExpression;
  17486. var symbol = findSymbol(n.expression);
  17487. if (symbol && index && index.kind === 9) {
  17488. var name_12 = index.text;
  17489. var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_12);
  17490. return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 32768) !== 0;
  17491. }
  17492. return false;
  17493. }
  17494. case 170:
  17495. return isConstVariableReference(n.expression);
  17496. default:
  17497. return false;
  17498. }
  17499. }
  17500. if (!isReferenceOrErrorExpression(n)) {
  17501. error(n, invalidReferenceMessage);
  17502. return false;
  17503. }
  17504. if (isConstVariableReference(n)) {
  17505. error(n, constantVariableMessage);
  17506. return false;
  17507. }
  17508. return true;
  17509. }
  17510. function checkDeleteExpression(node) {
  17511. checkExpression(node.expression);
  17512. return booleanType;
  17513. }
  17514. function checkTypeOfExpression(node) {
  17515. checkExpression(node.expression);
  17516. return stringType;
  17517. }
  17518. function checkVoidExpression(node) {
  17519. checkExpression(node.expression);
  17520. return undefinedType;
  17521. }
  17522. function checkAwaitExpression(node) {
  17523. if (produceDiagnostics) {
  17524. if (!(node.parserContextFlags & 8)) {
  17525. grammarErrorOnFirstToken(node, ts.Diagnostics.await_expression_is_only_allowed_within_an_async_function);
  17526. }
  17527. if (isInParameterInitializerBeforeContainingFunction(node)) {
  17528. error(node, ts.Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
  17529. }
  17530. }
  17531. var operandType = checkExpression(node.expression);
  17532. return checkAwaitedType(operandType, node);
  17533. }
  17534. function checkPrefixUnaryExpression(node) {
  17535. var operandType = checkExpression(node.operand);
  17536. switch (node.operator) {
  17537. case 35:
  17538. case 36:
  17539. case 49:
  17540. if (someConstituentTypeHasKind(operandType, 16777216)) {
  17541. error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator));
  17542. }
  17543. return numberType;
  17544. case 48:
  17545. return booleanType;
  17546. case 40:
  17547. case 41:
  17548. var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
  17549. if (ok) {
  17550. 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);
  17551. }
  17552. return numberType;
  17553. }
  17554. return unknownType;
  17555. }
  17556. function checkPostfixUnaryExpression(node) {
  17557. var operandType = checkExpression(node.operand);
  17558. var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
  17559. if (ok) {
  17560. 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);
  17561. }
  17562. return numberType;
  17563. }
  17564. function someConstituentTypeHasKind(type, kind) {
  17565. if (type.flags & kind) {
  17566. return true;
  17567. }
  17568. if (type.flags & 49152) {
  17569. var types = type.types;
  17570. for (var _i = 0; _i < types.length; _i++) {
  17571. var current = types[_i];
  17572. if (current.flags & kind) {
  17573. return true;
  17574. }
  17575. }
  17576. return false;
  17577. }
  17578. return false;
  17579. }
  17580. function allConstituentTypesHaveKind(type, kind) {
  17581. if (type.flags & kind) {
  17582. return true;
  17583. }
  17584. if (type.flags & 49152) {
  17585. var types = type.types;
  17586. for (var _i = 0; _i < types.length; _i++) {
  17587. var current = types[_i];
  17588. if (!(current.flags & kind)) {
  17589. return false;
  17590. }
  17591. }
  17592. return true;
  17593. }
  17594. return false;
  17595. }
  17596. function isConstEnumObjectType(type) {
  17597. return type.flags & (80896 | 65536) && type.symbol && isConstEnumSymbol(type.symbol);
  17598. }
  17599. function isConstEnumSymbol(symbol) {
  17600. return (symbol.flags & 128) !== 0;
  17601. }
  17602. function checkInstanceOfExpression(node, leftType, rightType) {
  17603. if (allConstituentTypesHaveKind(leftType, 16777726)) {
  17604. error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
  17605. }
  17606. if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
  17607. error(node.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);
  17608. }
  17609. return booleanType;
  17610. }
  17611. function checkInExpression(node, leftType, rightType) {
  17612. if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 16777216)) {
  17613. error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
  17614. }
  17615. if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 | 512)) {
  17616. error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
  17617. }
  17618. return booleanType;
  17619. }
  17620. function checkObjectLiteralAssignment(node, sourceType, contextualMapper) {
  17621. var properties = node.properties;
  17622. for (var _i = 0; _i < properties.length; _i++) {
  17623. var p = properties[_i];
  17624. if (p.kind === 243 || p.kind === 244) {
  17625. var name_13 = p.name;
  17626. var type = isTypeAny(sourceType)
  17627. ? sourceType
  17628. : getTypeOfPropertyOfType(sourceType, name_13.text) ||
  17629. isNumericLiteralName(name_13.text) && getIndexTypeOfType(sourceType, 1) ||
  17630. getIndexTypeOfType(sourceType, 0);
  17631. if (type) {
  17632. checkDestructuringAssignment(p.initializer || name_13, type);
  17633. }
  17634. else {
  17635. error(name_13, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_13));
  17636. }
  17637. }
  17638. else {
  17639. error(p, ts.Diagnostics.Property_assignment_expected);
  17640. }
  17641. }
  17642. return sourceType;
  17643. }
  17644. function checkArrayLiteralAssignment(node, sourceType, contextualMapper) {
  17645. var elementType = checkIteratedTypeOrElementType(sourceType, node, false) || unknownType;
  17646. var elements = node.elements;
  17647. for (var i = 0; i < elements.length; i++) {
  17648. var e = elements[i];
  17649. if (e.kind !== 185) {
  17650. if (e.kind !== 183) {
  17651. var propName = "" + i;
  17652. var type = isTypeAny(sourceType)
  17653. ? sourceType
  17654. : isTupleLikeType(sourceType)
  17655. ? getTypeOfPropertyOfType(sourceType, propName)
  17656. : elementType;
  17657. if (type) {
  17658. checkDestructuringAssignment(e, type, contextualMapper);
  17659. }
  17660. else {
  17661. if (isTupleType(sourceType)) {
  17662. 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);
  17663. }
  17664. else {
  17665. error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName);
  17666. }
  17667. }
  17668. }
  17669. else {
  17670. if (i < elements.length - 1) {
  17671. error(e, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
  17672. }
  17673. else {
  17674. var restExpression = e.expression;
  17675. if (restExpression.kind === 179 && restExpression.operatorToken.kind === 55) {
  17676. error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer);
  17677. }
  17678. else {
  17679. checkDestructuringAssignment(restExpression, createArrayType(elementType), contextualMapper);
  17680. }
  17681. }
  17682. }
  17683. }
  17684. }
  17685. return sourceType;
  17686. }
  17687. function checkDestructuringAssignment(target, sourceType, contextualMapper) {
  17688. if (target.kind === 179 && target.operatorToken.kind === 55) {
  17689. checkBinaryExpression(target, contextualMapper);
  17690. target = target.left;
  17691. }
  17692. if (target.kind === 163) {
  17693. return checkObjectLiteralAssignment(target, sourceType, contextualMapper);
  17694. }
  17695. if (target.kind === 162) {
  17696. return checkArrayLiteralAssignment(target, sourceType, contextualMapper);
  17697. }
  17698. return checkReferenceAssignment(target, sourceType, contextualMapper);
  17699. }
  17700. function checkReferenceAssignment(target, sourceType, contextualMapper) {
  17701. var targetType = checkExpression(target, contextualMapper);
  17702. if (checkReferenceExpression(target, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant)) {
  17703. checkTypeAssignableTo(sourceType, targetType, target, undefined);
  17704. }
  17705. return sourceType;
  17706. }
  17707. function checkBinaryExpression(node, contextualMapper) {
  17708. var operator = node.operatorToken.kind;
  17709. if (operator === 55 && (node.left.kind === 163 || node.left.kind === 162)) {
  17710. return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper);
  17711. }
  17712. var leftType = checkExpression(node.left, contextualMapper);
  17713. var rightType = checkExpression(node.right, contextualMapper);
  17714. switch (operator) {
  17715. case 37:
  17716. case 58:
  17717. case 38:
  17718. case 59:
  17719. case 39:
  17720. case 60:
  17721. case 36:
  17722. case 57:
  17723. case 42:
  17724. case 61:
  17725. case 43:
  17726. case 62:
  17727. case 44:
  17728. case 63:
  17729. case 46:
  17730. case 65:
  17731. case 47:
  17732. case 66:
  17733. case 45:
  17734. case 64:
  17735. if (leftType.flags & (32 | 64))
  17736. leftType = rightType;
  17737. if (rightType.flags & (32 | 64))
  17738. rightType = leftType;
  17739. var suggestedOperator;
  17740. if ((leftType.flags & 8) &&
  17741. (rightType.flags & 8) &&
  17742. (suggestedOperator = getSuggestedBooleanOperator(node.operatorToken.kind)) !== undefined) {
  17743. error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operatorToken.kind), ts.tokenToString(suggestedOperator));
  17744. }
  17745. else {
  17746. var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
  17747. var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type);
  17748. if (leftOk && rightOk) {
  17749. checkAssignmentOperator(numberType);
  17750. }
  17751. }
  17752. return numberType;
  17753. case 35:
  17754. case 56:
  17755. if (leftType.flags & (32 | 64))
  17756. leftType = rightType;
  17757. if (rightType.flags & (32 | 64))
  17758. rightType = leftType;
  17759. var resultType;
  17760. if (allConstituentTypesHaveKind(leftType, 132) && allConstituentTypesHaveKind(rightType, 132)) {
  17761. resultType = numberType;
  17762. }
  17763. else {
  17764. if (allConstituentTypesHaveKind(leftType, 258) || allConstituentTypesHaveKind(rightType, 258)) {
  17765. resultType = stringType;
  17766. }
  17767. else if (isTypeAny(leftType) || isTypeAny(rightType)) {
  17768. resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType;
  17769. }
  17770. if (resultType && !checkForDisallowedESSymbolOperand(operator)) {
  17771. return resultType;
  17772. }
  17773. }
  17774. if (!resultType) {
  17775. reportOperatorError();
  17776. return anyType;
  17777. }
  17778. if (operator === 56) {
  17779. checkAssignmentOperator(resultType);
  17780. }
  17781. return resultType;
  17782. case 25:
  17783. case 27:
  17784. case 28:
  17785. case 29:
  17786. if (!checkForDisallowedESSymbolOperand(operator)) {
  17787. return booleanType;
  17788. }
  17789. case 30:
  17790. case 31:
  17791. case 32:
  17792. case 33:
  17793. if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) {
  17794. reportOperatorError();
  17795. }
  17796. return booleanType;
  17797. case 89:
  17798. return checkInstanceOfExpression(node, leftType, rightType);
  17799. case 88:
  17800. return checkInExpression(node, leftType, rightType);
  17801. case 50:
  17802. return rightType;
  17803. case 51:
  17804. return getUnionType([leftType, rightType]);
  17805. case 55:
  17806. checkAssignmentOperator(rightType);
  17807. return getRegularTypeOfObjectLiteral(rightType);
  17808. case 24:
  17809. return rightType;
  17810. }
  17811. function checkForDisallowedESSymbolOperand(operator) {
  17812. var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216) ? node.left :
  17813. someConstituentTypeHasKind(rightType, 16777216) ? node.right :
  17814. undefined;
  17815. if (offendingSymbolOperand) {
  17816. error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator));
  17817. return false;
  17818. }
  17819. return true;
  17820. }
  17821. function getSuggestedBooleanOperator(operator) {
  17822. switch (operator) {
  17823. case 46:
  17824. case 65:
  17825. return 51;
  17826. case 47:
  17827. case 66:
  17828. return 33;
  17829. case 45:
  17830. case 64:
  17831. return 50;
  17832. default:
  17833. return undefined;
  17834. }
  17835. }
  17836. function checkAssignmentOperator(valueType) {
  17837. if (produceDiagnostics && operator >= 55 && operator <= 66) {
  17838. var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant);
  17839. if (ok) {
  17840. checkTypeAssignableTo(valueType, leftType, node.left, undefined);
  17841. }
  17842. }
  17843. }
  17844. function reportOperatorError() {
  17845. error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType));
  17846. }
  17847. }
  17848. function isYieldExpressionInClass(node) {
  17849. var current = node;
  17850. var parent = node.parent;
  17851. while (parent) {
  17852. if (ts.isFunctionLike(parent) && current === parent.body) {
  17853. return false;
  17854. }
  17855. else if (ts.isClassLike(current)) {
  17856. return true;
  17857. }
  17858. current = parent;
  17859. parent = parent.parent;
  17860. }
  17861. return false;
  17862. }
  17863. function checkYieldExpression(node) {
  17864. if (produceDiagnostics) {
  17865. if (!(node.parserContextFlags & 2) || isYieldExpressionInClass(node)) {
  17866. grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
  17867. }
  17868. if (isInParameterInitializerBeforeContainingFunction(node)) {
  17869. error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
  17870. }
  17871. }
  17872. if (node.expression) {
  17873. var func = ts.getContainingFunction(node);
  17874. if (func && func.asteriskToken) {
  17875. var expressionType = checkExpressionCached(node.expression, undefined);
  17876. var expressionElementType;
  17877. var nodeIsYieldStar = !!node.asteriskToken;
  17878. if (nodeIsYieldStar) {
  17879. expressionElementType = checkElementTypeOfIterable(expressionType, node.expression);
  17880. }
  17881. if (func.type) {
  17882. var signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType;
  17883. if (nodeIsYieldStar) {
  17884. checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, undefined);
  17885. }
  17886. else {
  17887. checkTypeAssignableTo(expressionType, signatureElementType, node.expression, undefined);
  17888. }
  17889. }
  17890. }
  17891. }
  17892. return anyType;
  17893. }
  17894. function checkConditionalExpression(node, contextualMapper) {
  17895. checkExpression(node.condition);
  17896. var type1 = checkExpression(node.whenTrue, contextualMapper);
  17897. var type2 = checkExpression(node.whenFalse, contextualMapper);
  17898. return getUnionType([type1, type2]);
  17899. }
  17900. function checkTemplateExpression(node) {
  17901. ts.forEach(node.templateSpans, function (templateSpan) {
  17902. checkExpression(templateSpan.expression);
  17903. });
  17904. return stringType;
  17905. }
  17906. function checkExpressionWithContextualType(node, contextualType, contextualMapper) {
  17907. var saveContextualType = node.contextualType;
  17908. node.contextualType = contextualType;
  17909. var result = checkExpression(node, contextualMapper);
  17910. node.contextualType = saveContextualType;
  17911. return result;
  17912. }
  17913. function checkExpressionCached(node, contextualMapper) {
  17914. var links = getNodeLinks(node);
  17915. if (!links.resolvedType) {
  17916. links.resolvedType = checkExpression(node, contextualMapper);
  17917. }
  17918. return links.resolvedType;
  17919. }
  17920. function checkPropertyAssignment(node, contextualMapper) {
  17921. if (node.name.kind === 134) {
  17922. checkComputedPropertyName(node.name);
  17923. }
  17924. return checkExpression(node.initializer, contextualMapper);
  17925. }
  17926. function checkObjectLiteralMethod(node, contextualMapper) {
  17927. checkGrammarMethod(node);
  17928. if (node.name.kind === 134) {
  17929. checkComputedPropertyName(node.name);
  17930. }
  17931. var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper);
  17932. return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper);
  17933. }
  17934. function instantiateTypeWithSingleGenericCallSignature(node, type, contextualMapper) {
  17935. if (isInferentialContext(contextualMapper)) {
  17936. var signature = getSingleCallSignature(type);
  17937. if (signature && signature.typeParameters) {
  17938. var contextualType = getContextualType(node);
  17939. if (contextualType) {
  17940. var contextualSignature = getSingleCallSignature(contextualType);
  17941. if (contextualSignature && !contextualSignature.typeParameters) {
  17942. return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper));
  17943. }
  17944. }
  17945. }
  17946. }
  17947. return type;
  17948. }
  17949. function checkExpression(node, contextualMapper) {
  17950. var type;
  17951. if (node.kind === 133) {
  17952. type = checkQualifiedName(node);
  17953. }
  17954. else {
  17955. var uninstantiatedType = checkExpressionWorker(node, contextualMapper);
  17956. type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper);
  17957. }
  17958. if (isConstEnumObjectType(type)) {
  17959. var ok = (node.parent.kind === 164 && node.parent.expression === node) ||
  17960. (node.parent.kind === 165 && node.parent.expression === node) ||
  17961. ((node.kind === 67 || node.kind === 133) && isInRightSideOfImportOrExportAssignment(node));
  17962. if (!ok) {
  17963. 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);
  17964. }
  17965. }
  17966. return type;
  17967. }
  17968. function checkNumericLiteral(node) {
  17969. checkGrammarNumericLiteral(node);
  17970. return numberType;
  17971. }
  17972. function checkExpressionWorker(node, contextualMapper) {
  17973. switch (node.kind) {
  17974. case 67:
  17975. return checkIdentifier(node);
  17976. case 95:
  17977. return checkThisExpression(node);
  17978. case 93:
  17979. return checkSuperExpression(node);
  17980. case 91:
  17981. return nullType;
  17982. case 97:
  17983. case 82:
  17984. return booleanType;
  17985. case 8:
  17986. return checkNumericLiteral(node);
  17987. case 181:
  17988. return checkTemplateExpression(node);
  17989. case 9:
  17990. case 11:
  17991. return stringType;
  17992. case 10:
  17993. return globalRegExpType;
  17994. case 162:
  17995. return checkArrayLiteral(node, contextualMapper);
  17996. case 163:
  17997. return checkObjectLiteral(node, contextualMapper);
  17998. case 164:
  17999. return checkPropertyAccessExpression(node);
  18000. case 165:
  18001. return checkIndexedAccess(node);
  18002. case 166:
  18003. case 167:
  18004. return checkCallExpression(node);
  18005. case 168:
  18006. return checkTaggedTemplateExpression(node);
  18007. case 170:
  18008. return checkExpression(node.expression, contextualMapper);
  18009. case 184:
  18010. return checkClassExpression(node);
  18011. case 171:
  18012. case 172:
  18013. return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper);
  18014. case 174:
  18015. return checkTypeOfExpression(node);
  18016. case 169:
  18017. case 187:
  18018. return checkAssertion(node);
  18019. case 173:
  18020. return checkDeleteExpression(node);
  18021. case 175:
  18022. return checkVoidExpression(node);
  18023. case 176:
  18024. return checkAwaitExpression(node);
  18025. case 177:
  18026. return checkPrefixUnaryExpression(node);
  18027. case 178:
  18028. return checkPostfixUnaryExpression(node);
  18029. case 179:
  18030. return checkBinaryExpression(node, contextualMapper);
  18031. case 180:
  18032. return checkConditionalExpression(node, contextualMapper);
  18033. case 183:
  18034. return checkSpreadElementExpression(node, contextualMapper);
  18035. case 185:
  18036. return undefinedType;
  18037. case 182:
  18038. return checkYieldExpression(node);
  18039. case 238:
  18040. return checkJsxExpression(node);
  18041. case 231:
  18042. return checkJsxElement(node);
  18043. case 232:
  18044. return checkJsxSelfClosingElement(node);
  18045. case 233:
  18046. ts.Debug.fail("Shouldn't ever directly check a JsxOpeningElement");
  18047. }
  18048. return unknownType;
  18049. }
  18050. function checkTypeParameter(node) {
  18051. if (node.expression) {
  18052. grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected);
  18053. }
  18054. checkSourceElement(node.constraint);
  18055. if (produceDiagnostics) {
  18056. checkTypeParameterHasIllegalReferencesInConstraint(node);
  18057. checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0);
  18058. }
  18059. }
  18060. function checkParameter(node) {
  18061. // Grammar checking
  18062. // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
  18063. // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
  18064. // or if its FunctionBody is strict code(11.1.5).
  18065. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  18066. checkVariableLikeDeclaration(node);
  18067. var func = ts.getContainingFunction(node);
  18068. if (node.flags & 112) {
  18069. func = ts.getContainingFunction(node);
  18070. if (!(func.kind === 142 && ts.nodeIsPresent(func.body))) {
  18071. error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
  18072. }
  18073. }
  18074. if (node.questionToken && ts.isBindingPattern(node.name) && func.body) {
  18075. error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
  18076. }
  18077. if (node.dotDotDotToken && !ts.isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) {
  18078. error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type);
  18079. }
  18080. }
  18081. function isSyntacticallyValidGenerator(node) {
  18082. if (!node.asteriskToken || !node.body) {
  18083. return false;
  18084. }
  18085. return node.kind === 141 ||
  18086. node.kind === 211 ||
  18087. node.kind === 171;
  18088. }
  18089. function getTypePredicateParameterIndex(parameterList, parameter) {
  18090. if (parameterList) {
  18091. for (var i = 0; i < parameterList.length; i++) {
  18092. var param = parameterList[i];
  18093. if (param.name.kind === 67 &&
  18094. param.name.text === parameter.text) {
  18095. return i;
  18096. }
  18097. }
  18098. }
  18099. return -1;
  18100. }
  18101. function isInLegalTypePredicatePosition(node) {
  18102. switch (node.parent.kind) {
  18103. case 172:
  18104. case 145:
  18105. case 211:
  18106. case 171:
  18107. case 150:
  18108. case 141:
  18109. case 140:
  18110. return node === node.parent.type;
  18111. }
  18112. return false;
  18113. }
  18114. function checkSignatureDeclaration(node) {
  18115. if (node.kind === 147) {
  18116. checkGrammarIndexSignature(node);
  18117. }
  18118. else if (node.kind === 150 || node.kind === 211 || node.kind === 151 ||
  18119. node.kind === 145 || node.kind === 142 ||
  18120. node.kind === 146) {
  18121. checkGrammarFunctionLikeDeclaration(node);
  18122. }
  18123. checkTypeParameters(node.typeParameters);
  18124. ts.forEach(node.parameters, checkParameter);
  18125. if (node.type) {
  18126. if (node.type.kind === 148) {
  18127. var typePredicate = getSignatureFromDeclaration(node).typePredicate;
  18128. var typePredicateNode = node.type;
  18129. if (isInLegalTypePredicatePosition(typePredicateNode)) {
  18130. if (typePredicate.parameterIndex >= 0) {
  18131. if (node.parameters[typePredicate.parameterIndex].dotDotDotToken) {
  18132. error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
  18133. }
  18134. else {
  18135. checkTypeAssignableTo(typePredicate.type, getTypeOfNode(node.parameters[typePredicate.parameterIndex]), typePredicateNode.type);
  18136. }
  18137. }
  18138. else if (typePredicateNode.parameterName) {
  18139. var hasReportedError = false;
  18140. for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
  18141. var param = _a[_i];
  18142. if (hasReportedError) {
  18143. break;
  18144. }
  18145. if (param.name.kind === 159 ||
  18146. param.name.kind === 160) {
  18147. (function checkBindingPattern(pattern) {
  18148. for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
  18149. var element = _a[_i];
  18150. if (element.name.kind === 67 &&
  18151. element.name.text === typePredicate.parameterName) {
  18152. error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName);
  18153. hasReportedError = true;
  18154. break;
  18155. }
  18156. else if (element.name.kind === 160 ||
  18157. element.name.kind === 159) {
  18158. checkBindingPattern(element.name);
  18159. }
  18160. }
  18161. })(param.name);
  18162. }
  18163. }
  18164. if (!hasReportedError) {
  18165. error(typePredicateNode.parameterName, ts.Diagnostics.Cannot_find_parameter_0, typePredicate.parameterName);
  18166. }
  18167. }
  18168. }
  18169. else {
  18170. error(typePredicateNode, ts.Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
  18171. }
  18172. }
  18173. else {
  18174. checkSourceElement(node.type);
  18175. }
  18176. }
  18177. if (produceDiagnostics) {
  18178. checkCollisionWithArgumentsInGeneratedCode(node);
  18179. if (compilerOptions.noImplicitAny && !node.type) {
  18180. switch (node.kind) {
  18181. case 146:
  18182. error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
  18183. break;
  18184. case 145:
  18185. error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
  18186. break;
  18187. }
  18188. }
  18189. if (node.type) {
  18190. if (languageVersion >= 2 && isSyntacticallyValidGenerator(node)) {
  18191. var returnType = getTypeFromTypeNode(node.type);
  18192. if (returnType === voidType) {
  18193. error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation);
  18194. }
  18195. else {
  18196. var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType;
  18197. var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType);
  18198. checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type);
  18199. }
  18200. }
  18201. }
  18202. }
  18203. checkSpecializedSignatureDeclaration(node);
  18204. }
  18205. function checkTypeForDuplicateIndexSignatures(node) {
  18206. if (node.kind === 213) {
  18207. var nodeSymbol = getSymbolOfNode(node);
  18208. if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) {
  18209. return;
  18210. }
  18211. }
  18212. var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
  18213. if (indexSymbol) {
  18214. var seenNumericIndexer = false;
  18215. var seenStringIndexer = false;
  18216. for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
  18217. var decl = _a[_i];
  18218. var declaration = decl;
  18219. if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
  18220. switch (declaration.parameters[0].type.kind) {
  18221. case 128:
  18222. if (!seenStringIndexer) {
  18223. seenStringIndexer = true;
  18224. }
  18225. else {
  18226. error(declaration, ts.Diagnostics.Duplicate_string_index_signature);
  18227. }
  18228. break;
  18229. case 126:
  18230. if (!seenNumericIndexer) {
  18231. seenNumericIndexer = true;
  18232. }
  18233. else {
  18234. error(declaration, ts.Diagnostics.Duplicate_number_index_signature);
  18235. }
  18236. break;
  18237. }
  18238. }
  18239. }
  18240. }
  18241. }
  18242. function checkPropertyDeclaration(node) {
  18243. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name);
  18244. checkVariableLikeDeclaration(node);
  18245. }
  18246. function checkMethodDeclaration(node) {
  18247. checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name);
  18248. checkFunctionLikeDeclaration(node);
  18249. if (node.flags & 256 && node.body) {
  18250. error(node, ts.Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, ts.declarationNameToString(node.name));
  18251. }
  18252. }
  18253. function checkConstructorDeclaration(node) {
  18254. checkSignatureDeclaration(node);
  18255. checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node);
  18256. checkSourceElement(node.body);
  18257. var symbol = getSymbolOfNode(node);
  18258. var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind);
  18259. if (node === firstDeclaration) {
  18260. checkFunctionOrConstructorSymbol(symbol);
  18261. }
  18262. if (ts.nodeIsMissing(node.body)) {
  18263. return;
  18264. }
  18265. if (!produceDiagnostics) {
  18266. return;
  18267. }
  18268. function isSuperCallExpression(n) {
  18269. return n.kind === 166 && n.expression.kind === 93;
  18270. }
  18271. function containsSuperCallAsComputedPropertyName(n) {
  18272. return n.name && containsSuperCall(n.name);
  18273. }
  18274. function containsSuperCall(n) {
  18275. if (isSuperCallExpression(n)) {
  18276. return true;
  18277. }
  18278. else if (ts.isFunctionLike(n)) {
  18279. return false;
  18280. }
  18281. else if (ts.isClassLike(n)) {
  18282. return ts.forEach(n.members, containsSuperCallAsComputedPropertyName);
  18283. }
  18284. return ts.forEachChild(n, containsSuperCall);
  18285. }
  18286. function markThisReferencesAsErrors(n) {
  18287. if (n.kind === 95) {
  18288. error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
  18289. }
  18290. else if (n.kind !== 171 && n.kind !== 211) {
  18291. ts.forEachChild(n, markThisReferencesAsErrors);
  18292. }
  18293. }
  18294. function isInstancePropertyWithInitializer(n) {
  18295. return n.kind === 139 &&
  18296. !(n.flags & 128) &&
  18297. !!n.initializer;
  18298. }
  18299. var containingClassDecl = node.parent;
  18300. if (ts.getClassExtendsHeritageClauseElement(containingClassDecl)) {
  18301. var containingClassSymbol = getSymbolOfNode(containingClassDecl);
  18302. var containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol);
  18303. var baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType);
  18304. if (containsSuperCall(node.body)) {
  18305. if (baseConstructorType === nullType) {
  18306. error(node, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
  18307. }
  18308. var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) ||
  18309. ts.forEach(node.parameters, function (p) { return p.flags & (16 | 32 | 64); });
  18310. if (superCallShouldBeFirst) {
  18311. var statements = node.body.statements;
  18312. var superCallStatement;
  18313. for (var _i = 0; _i < statements.length; _i++) {
  18314. var statement = statements[_i];
  18315. if (statement.kind === 193 && isSuperCallExpression(statement.expression)) {
  18316. superCallStatement = statement;
  18317. break;
  18318. }
  18319. if (!ts.isPrologueDirective(statement)) {
  18320. break;
  18321. }
  18322. }
  18323. if (!superCallStatement) {
  18324. 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);
  18325. }
  18326. else {
  18327. markThisReferencesAsErrors(superCallStatement.expression);
  18328. }
  18329. }
  18330. }
  18331. else if (baseConstructorType !== nullType) {
  18332. error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
  18333. }
  18334. }
  18335. }
  18336. function checkAccessorDeclaration(node) {
  18337. if (produceDiagnostics) {
  18338. checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name);
  18339. if (node.kind === 143) {
  18340. if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) {
  18341. error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement);
  18342. }
  18343. }
  18344. if (!ts.hasDynamicName(node)) {
  18345. var otherKind = node.kind === 143 ? 144 : 143;
  18346. var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind);
  18347. if (otherAccessor) {
  18348. if (((node.flags & 112) !== (otherAccessor.flags & 112))) {
  18349. error(node.name, ts.Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility);
  18350. }
  18351. var currentAccessorType = getAnnotatedAccessorType(node);
  18352. var otherAccessorType = getAnnotatedAccessorType(otherAccessor);
  18353. if (currentAccessorType && otherAccessorType) {
  18354. if (!isTypeIdenticalTo(currentAccessorType, otherAccessorType)) {
  18355. error(node, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type);
  18356. }
  18357. }
  18358. }
  18359. }
  18360. getTypeOfAccessors(getSymbolOfNode(node));
  18361. }
  18362. checkFunctionLikeDeclaration(node);
  18363. }
  18364. function checkMissingDeclaration(node) {
  18365. checkDecorators(node);
  18366. }
  18367. function checkTypeArgumentConstraints(typeParameters, typeArguments) {
  18368. var result = true;
  18369. for (var i = 0; i < typeParameters.length; i++) {
  18370. var constraint = getConstraintOfTypeParameter(typeParameters[i]);
  18371. if (constraint) {
  18372. var typeArgument = typeArguments[i];
  18373. result = result && checkTypeAssignableTo(getTypeFromTypeNode(typeArgument), constraint, typeArgument, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
  18374. }
  18375. }
  18376. return result;
  18377. }
  18378. function checkTypeReferenceNode(node) {
  18379. checkGrammarTypeArguments(node, node.typeArguments);
  18380. var type = getTypeFromTypeReference(node);
  18381. if (type !== unknownType && node.typeArguments) {
  18382. ts.forEach(node.typeArguments, checkSourceElement);
  18383. if (produceDiagnostics) {
  18384. var symbol = getNodeLinks(node).resolvedSymbol;
  18385. var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters;
  18386. checkTypeArgumentConstraints(typeParameters, node.typeArguments);
  18387. }
  18388. }
  18389. }
  18390. function checkTypeQuery(node) {
  18391. getTypeFromTypeQueryNode(node);
  18392. }
  18393. function checkTypeLiteral(node) {
  18394. ts.forEach(node.members, checkSourceElement);
  18395. if (produceDiagnostics) {
  18396. var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
  18397. checkIndexConstraints(type);
  18398. checkTypeForDuplicateIndexSignatures(node);
  18399. }
  18400. }
  18401. function checkArrayType(node) {
  18402. checkSourceElement(node.elementType);
  18403. }
  18404. function checkTupleType(node) {
  18405. var hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes);
  18406. if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) {
  18407. grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty);
  18408. }
  18409. ts.forEach(node.elementTypes, checkSourceElement);
  18410. }
  18411. function checkUnionOrIntersectionType(node) {
  18412. ts.forEach(node.types, checkSourceElement);
  18413. }
  18414. function isPrivateWithinAmbient(node) {
  18415. return (node.flags & 32) && ts.isInAmbientContext(node);
  18416. }
  18417. function checkSpecializedSignatureDeclaration(signatureDeclarationNode) {
  18418. if (!produceDiagnostics) {
  18419. return;
  18420. }
  18421. var signature = getSignatureFromDeclaration(signatureDeclarationNode);
  18422. if (!signature.hasStringLiterals) {
  18423. return;
  18424. }
  18425. if (ts.nodeIsPresent(signatureDeclarationNode.body)) {
  18426. error(signatureDeclarationNode, ts.Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type);
  18427. return;
  18428. }
  18429. var signaturesToCheck;
  18430. if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 213) {
  18431. ts.Debug.assert(signatureDeclarationNode.kind === 145 || signatureDeclarationNode.kind === 146);
  18432. var signatureKind = signatureDeclarationNode.kind === 145 ? 0 : 1;
  18433. var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent);
  18434. var containingType = getDeclaredTypeOfSymbol(containingSymbol);
  18435. signaturesToCheck = getSignaturesOfType(containingType, signatureKind);
  18436. }
  18437. else {
  18438. signaturesToCheck = getSignaturesOfSymbol(getSymbolOfNode(signatureDeclarationNode));
  18439. }
  18440. for (var _i = 0; _i < signaturesToCheck.length; _i++) {
  18441. var otherSignature = signaturesToCheck[_i];
  18442. if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) {
  18443. return;
  18444. }
  18445. }
  18446. error(signatureDeclarationNode, ts.Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature);
  18447. }
  18448. function getEffectiveDeclarationFlags(n, flagsToCheck) {
  18449. var flags = ts.getCombinedNodeFlags(n);
  18450. if (n.parent.kind !== 213 && ts.isInAmbientContext(n)) {
  18451. if (!(flags & 2)) {
  18452. flags |= 1;
  18453. }
  18454. flags |= 2;
  18455. }
  18456. return flags & flagsToCheck;
  18457. }
  18458. function checkFunctionOrConstructorSymbol(symbol) {
  18459. if (!produceDiagnostics) {
  18460. return;
  18461. }
  18462. function getCanonicalOverload(overloads, implementation) {
  18463. var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent;
  18464. return implementationSharesContainerWithFirstOverload ? implementation : overloads[0];
  18465. }
  18466. function checkFlagAgreementBetweenOverloads(overloads, implementation, flagsToCheck, someOverloadFlags, allOverloadFlags) {
  18467. var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags;
  18468. if (someButNotAllOverloadFlags !== 0) {
  18469. var canonicalFlags = getEffectiveDeclarationFlags(getCanonicalOverload(overloads, implementation), flagsToCheck);
  18470. ts.forEach(overloads, function (o) {
  18471. var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags;
  18472. if (deviation & 1) {
  18473. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported);
  18474. }
  18475. else if (deviation & 2) {
  18476. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
  18477. }
  18478. else if (deviation & (32 | 64)) {
  18479. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
  18480. }
  18481. else if (deviation & 256) {
  18482. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract);
  18483. }
  18484. });
  18485. }
  18486. }
  18487. function checkQuestionTokenAgreementBetweenOverloads(overloads, implementation, someHaveQuestionToken, allHaveQuestionToken) {
  18488. if (someHaveQuestionToken !== allHaveQuestionToken) {
  18489. var canonicalHasQuestionToken = ts.hasQuestionToken(getCanonicalOverload(overloads, implementation));
  18490. ts.forEach(overloads, function (o) {
  18491. var deviation = ts.hasQuestionToken(o) !== canonicalHasQuestionToken;
  18492. if (deviation) {
  18493. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_optional_or_required);
  18494. }
  18495. });
  18496. }
  18497. }
  18498. var flagsToCheck = 1 | 2 | 32 | 64 | 256;
  18499. var someNodeFlags = 0;
  18500. var allNodeFlags = flagsToCheck;
  18501. var someHaveQuestionToken = false;
  18502. var allHaveQuestionToken = true;
  18503. var hasOverloads = false;
  18504. var bodyDeclaration;
  18505. var lastSeenNonAmbientDeclaration;
  18506. var previousDeclaration;
  18507. var declarations = symbol.declarations;
  18508. var isConstructor = (symbol.flags & 16384) !== 0;
  18509. function reportImplementationExpectedError(node) {
  18510. if (node.name && ts.nodeIsMissing(node.name)) {
  18511. return;
  18512. }
  18513. var seen = false;
  18514. var subsequentNode = ts.forEachChild(node.parent, function (c) {
  18515. if (seen) {
  18516. return c;
  18517. }
  18518. else {
  18519. seen = c === node;
  18520. }
  18521. });
  18522. if (subsequentNode) {
  18523. if (subsequentNode.kind === node.kind) {
  18524. var errorNode_1 = subsequentNode.name || subsequentNode;
  18525. if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) {
  18526. ts.Debug.assert(node.kind === 141 || node.kind === 140);
  18527. ts.Debug.assert((node.flags & 128) !== (subsequentNode.flags & 128));
  18528. var diagnostic = node.flags & 128 ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static;
  18529. error(errorNode_1, diagnostic);
  18530. return;
  18531. }
  18532. else if (ts.nodeIsPresent(subsequentNode.body)) {
  18533. error(errorNode_1, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name));
  18534. return;
  18535. }
  18536. }
  18537. }
  18538. var errorNode = node.name || node;
  18539. if (isConstructor) {
  18540. error(errorNode, ts.Diagnostics.Constructor_implementation_is_missing);
  18541. }
  18542. else {
  18543. if (node.flags & 256) {
  18544. error(errorNode, ts.Diagnostics.All_declarations_of_an_abstract_method_must_be_consecutive);
  18545. }
  18546. else {
  18547. error(errorNode, ts.Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration);
  18548. }
  18549. }
  18550. }
  18551. var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & 1536;
  18552. var duplicateFunctionDeclaration = false;
  18553. var multipleConstructorImplementation = false;
  18554. for (var _i = 0; _i < declarations.length; _i++) {
  18555. var current = declarations[_i];
  18556. var node = current;
  18557. var inAmbientContext = ts.isInAmbientContext(node);
  18558. var inAmbientContextOrInterface = node.parent.kind === 213 || node.parent.kind === 153 || inAmbientContext;
  18559. if (inAmbientContextOrInterface) {
  18560. previousDeclaration = undefined;
  18561. }
  18562. if (node.kind === 211 || node.kind === 141 || node.kind === 140 || node.kind === 142) {
  18563. var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
  18564. someNodeFlags |= currentNodeFlags;
  18565. allNodeFlags &= currentNodeFlags;
  18566. someHaveQuestionToken = someHaveQuestionToken || ts.hasQuestionToken(node);
  18567. allHaveQuestionToken = allHaveQuestionToken && ts.hasQuestionToken(node);
  18568. if (ts.nodeIsPresent(node.body) && bodyDeclaration) {
  18569. if (isConstructor) {
  18570. multipleConstructorImplementation = true;
  18571. }
  18572. else {
  18573. duplicateFunctionDeclaration = true;
  18574. }
  18575. }
  18576. else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
  18577. reportImplementationExpectedError(previousDeclaration);
  18578. }
  18579. if (ts.nodeIsPresent(node.body)) {
  18580. if (!bodyDeclaration) {
  18581. bodyDeclaration = node;
  18582. }
  18583. }
  18584. else {
  18585. hasOverloads = true;
  18586. }
  18587. previousDeclaration = node;
  18588. if (!inAmbientContextOrInterface) {
  18589. lastSeenNonAmbientDeclaration = node;
  18590. }
  18591. }
  18592. }
  18593. if (multipleConstructorImplementation) {
  18594. ts.forEach(declarations, function (declaration) {
  18595. error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed);
  18596. });
  18597. }
  18598. if (duplicateFunctionDeclaration) {
  18599. ts.forEach(declarations, function (declaration) {
  18600. error(declaration.name, ts.Diagnostics.Duplicate_function_implementation);
  18601. });
  18602. }
  18603. if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
  18604. !(lastSeenNonAmbientDeclaration.flags & 256)) {
  18605. reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
  18606. }
  18607. if (hasOverloads) {
  18608. checkFlagAgreementBetweenOverloads(declarations, bodyDeclaration, flagsToCheck, someNodeFlags, allNodeFlags);
  18609. checkQuestionTokenAgreementBetweenOverloads(declarations, bodyDeclaration, someHaveQuestionToken, allHaveQuestionToken);
  18610. if (bodyDeclaration) {
  18611. var signatures = getSignaturesOfSymbol(symbol);
  18612. var bodySignature = getSignatureFromDeclaration(bodyDeclaration);
  18613. if (!bodySignature.hasStringLiterals) {
  18614. for (var _a = 0; _a < signatures.length; _a++) {
  18615. var signature = signatures[_a];
  18616. if (!signature.hasStringLiterals && !isSignatureAssignableTo(bodySignature, signature)) {
  18617. error(signature.declaration, ts.Diagnostics.Overload_signature_is_not_compatible_with_function_implementation);
  18618. break;
  18619. }
  18620. }
  18621. }
  18622. }
  18623. }
  18624. }
  18625. function checkExportsOnMergedDeclarations(node) {
  18626. if (!produceDiagnostics) {
  18627. return;
  18628. }
  18629. var symbol = node.localSymbol;
  18630. if (!symbol) {
  18631. symbol = getSymbolOfNode(node);
  18632. if (!(symbol.flags & 7340032)) {
  18633. return;
  18634. }
  18635. }
  18636. if (ts.getDeclarationOfKind(symbol, node.kind) !== node) {
  18637. return;
  18638. }
  18639. var exportedDeclarationSpaces = 0;
  18640. var nonExportedDeclarationSpaces = 0;
  18641. var defaultExportedDeclarationSpaces = 0;
  18642. for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
  18643. var d = _a[_i];
  18644. var declarationSpaces = getDeclarationSpaces(d);
  18645. var effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, 1 | 1024);
  18646. if (effectiveDeclarationFlags & 1) {
  18647. if (effectiveDeclarationFlags & 1024) {
  18648. defaultExportedDeclarationSpaces |= declarationSpaces;
  18649. }
  18650. else {
  18651. exportedDeclarationSpaces |= declarationSpaces;
  18652. }
  18653. }
  18654. else {
  18655. nonExportedDeclarationSpaces |= declarationSpaces;
  18656. }
  18657. }
  18658. var nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces;
  18659. var commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
  18660. var commonDeclarationSpacesForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces;
  18661. if (commonDeclarationSpacesForExportsAndLocals || commonDeclarationSpacesForDefaultAndNonDefault) {
  18662. for (var _b = 0, _c = symbol.declarations; _b < _c.length; _b++) {
  18663. var d = _c[_b];
  18664. var declarationSpaces = getDeclarationSpaces(d);
  18665. if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) {
  18666. 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));
  18667. }
  18668. else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) {
  18669. error(d.name, ts.Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, ts.declarationNameToString(d.name));
  18670. }
  18671. }
  18672. }
  18673. function getDeclarationSpaces(d) {
  18674. switch (d.kind) {
  18675. case 213:
  18676. return 2097152;
  18677. case 216:
  18678. return d.name.kind === 9 || ts.getModuleInstanceState(d) !== 0
  18679. ? 4194304 | 1048576
  18680. : 4194304;
  18681. case 212:
  18682. case 215:
  18683. return 2097152 | 1048576;
  18684. case 219:
  18685. var result = 0;
  18686. var target = resolveAlias(getSymbolOfNode(d));
  18687. ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); });
  18688. return result;
  18689. default:
  18690. return 1048576;
  18691. }
  18692. }
  18693. }
  18694. function checkNonThenableType(type, location, message) {
  18695. if (!(type.flags & 1) && isTypeAssignableTo(type, getGlobalThenableType())) {
  18696. if (location) {
  18697. if (!message) {
  18698. message = ts.Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member;
  18699. }
  18700. error(location, message);
  18701. }
  18702. return unknownType;
  18703. }
  18704. return type;
  18705. }
  18706. function getPromisedType(promise) {
  18707. //
  18708. // { // promise
  18709. // then( // thenFunction
  18710. // onfulfilled: ( // onfulfilledParameterType
  18711. // value: T // valueParameterType
  18712. // ) => any
  18713. // ): any;
  18714. // }
  18715. //
  18716. if (promise.flags & 1) {
  18717. return undefined;
  18718. }
  18719. if ((promise.flags & 4096) && promise.target === tryGetGlobalPromiseType()) {
  18720. return promise.typeArguments[0];
  18721. }
  18722. var globalPromiseLikeType = getInstantiatedGlobalPromiseLikeType();
  18723. if (globalPromiseLikeType === emptyObjectType || !isTypeAssignableTo(promise, globalPromiseLikeType)) {
  18724. return undefined;
  18725. }
  18726. var thenFunction = getTypeOfPropertyOfType(promise, "then");
  18727. if (thenFunction && (thenFunction.flags & 1)) {
  18728. return undefined;
  18729. }
  18730. var thenSignatures = thenFunction ? getSignaturesOfType(thenFunction, 0) : emptyArray;
  18731. if (thenSignatures.length === 0) {
  18732. return undefined;
  18733. }
  18734. var onfulfilledParameterType = getUnionType(ts.map(thenSignatures, getTypeOfFirstParameterOfSignature));
  18735. if (onfulfilledParameterType.flags & 1) {
  18736. return undefined;
  18737. }
  18738. var onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, 0);
  18739. if (onfulfilledParameterSignatures.length === 0) {
  18740. return undefined;
  18741. }
  18742. var valueParameterType = getUnionType(ts.map(onfulfilledParameterSignatures, getTypeOfFirstParameterOfSignature));
  18743. return valueParameterType;
  18744. }
  18745. function getTypeOfFirstParameterOfSignature(signature) {
  18746. return getTypeAtPosition(signature, 0);
  18747. }
  18748. function getAwaitedType(type) {
  18749. return checkAwaitedType(type, undefined, undefined);
  18750. }
  18751. function checkAwaitedType(type, location, message) {
  18752. return checkAwaitedTypeWorker(type);
  18753. function checkAwaitedTypeWorker(type) {
  18754. if (type.flags & 16384) {
  18755. var types = [];
  18756. for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
  18757. var constituentType = _a[_i];
  18758. types.push(checkAwaitedTypeWorker(constituentType));
  18759. }
  18760. return getUnionType(types);
  18761. }
  18762. else {
  18763. var promisedType = getPromisedType(type);
  18764. if (promisedType === undefined) {
  18765. return checkNonThenableType(type, location, message);
  18766. }
  18767. else {
  18768. if (type.id === promisedType.id || awaitedTypeStack.indexOf(promisedType.id) >= 0) {
  18769. if (location) {
  18770. error(location, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method, symbolToString(type.symbol));
  18771. }
  18772. return unknownType;
  18773. }
  18774. awaitedTypeStack.push(type.id);
  18775. var awaitedType = checkAwaitedTypeWorker(promisedType);
  18776. awaitedTypeStack.pop();
  18777. return awaitedType;
  18778. }
  18779. }
  18780. }
  18781. }
  18782. function checkAsyncFunctionReturnType(node) {
  18783. var globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType();
  18784. if (globalPromiseConstructorLikeType === emptyObjectType) {
  18785. return unknownType;
  18786. }
  18787. var promiseType = getTypeFromTypeNode(node.type);
  18788. if (promiseType === unknownType && compilerOptions.isolatedModules) {
  18789. return unknownType;
  18790. }
  18791. var promiseConstructor = getMergedSymbol(promiseType.symbol);
  18792. if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
  18793. error(node, ts.Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType));
  18794. return unknownType;
  18795. }
  18796. var promiseConstructorType = getTypeOfSymbol(promiseConstructor);
  18797. if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node, ts.Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
  18798. return unknownType;
  18799. }
  18800. var promiseName = ts.getEntityNameFromTypeNode(node.type);
  18801. var root = getFirstIdentifier(promiseName);
  18802. var rootSymbol = getSymbol(node.locals, root.text, 107455);
  18803. if (rootSymbol) {
  18804. error(rootSymbol.valueDeclaration, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, root.text, getFullyQualifiedName(promiseConstructor));
  18805. return unknownType;
  18806. }
  18807. return checkAwaitedType(promiseType, node, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
  18808. }
  18809. function checkDecorator(node) {
  18810. var signature = getResolvedSignature(node);
  18811. var returnType = getReturnTypeOfSignature(signature);
  18812. if (returnType.flags & 1) {
  18813. return;
  18814. }
  18815. var expectedReturnType;
  18816. var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
  18817. var errorInfo;
  18818. switch (node.parent.kind) {
  18819. case 212:
  18820. var classSymbol = getSymbolOfNode(node.parent);
  18821. var classConstructorType = getTypeOfSymbol(classSymbol);
  18822. expectedReturnType = getUnionType([classConstructorType, voidType]);
  18823. break;
  18824. case 136:
  18825. expectedReturnType = voidType;
  18826. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
  18827. break;
  18828. case 139:
  18829. expectedReturnType = voidType;
  18830. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
  18831. break;
  18832. case 141:
  18833. case 143:
  18834. case 144:
  18835. var methodType = getTypeOfNode(node.parent);
  18836. var descriptorType = createTypedPropertyDescriptorType(methodType);
  18837. expectedReturnType = getUnionType([descriptorType, voidType]);
  18838. break;
  18839. }
  18840. checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo);
  18841. }
  18842. function checkTypeNodeAsExpression(node) {
  18843. if (node && node.kind === 149) {
  18844. var root = getFirstIdentifier(node.typeName);
  18845. var meaning = root.parent.kind === 149 ? 793056 : 1536;
  18846. var rootSymbol = resolveName(root, root.text, meaning | 8388608, undefined, undefined);
  18847. if (rootSymbol && rootSymbol.flags & 8388608) {
  18848. var aliasTarget = resolveAlias(rootSymbol);
  18849. if (aliasTarget.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(resolveAlias(rootSymbol))) {
  18850. markAliasSymbolAsReferenced(rootSymbol);
  18851. }
  18852. }
  18853. }
  18854. }
  18855. function checkTypeAnnotationAsExpression(node) {
  18856. switch (node.kind) {
  18857. case 139:
  18858. checkTypeNodeAsExpression(node.type);
  18859. break;
  18860. case 136:
  18861. checkTypeNodeAsExpression(node.type);
  18862. break;
  18863. case 141:
  18864. checkTypeNodeAsExpression(node.type);
  18865. break;
  18866. case 143:
  18867. checkTypeNodeAsExpression(node.type);
  18868. break;
  18869. case 144:
  18870. checkTypeNodeAsExpression(ts.getSetAccessorTypeAnnotationNode(node));
  18871. break;
  18872. }
  18873. }
  18874. function checkParameterTypeAnnotationsAsExpressions(node) {
  18875. for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
  18876. var parameter = _a[_i];
  18877. checkTypeAnnotationAsExpression(parameter);
  18878. }
  18879. }
  18880. function checkDecorators(node) {
  18881. if (!node.decorators) {
  18882. return;
  18883. }
  18884. if (!ts.nodeCanBeDecorated(node)) {
  18885. return;
  18886. }
  18887. if (!compilerOptions.experimentalDecorators) {
  18888. 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);
  18889. }
  18890. if (compilerOptions.emitDecoratorMetadata) {
  18891. switch (node.kind) {
  18892. case 212:
  18893. var constructor = ts.getFirstConstructorWithBody(node);
  18894. if (constructor) {
  18895. checkParameterTypeAnnotationsAsExpressions(constructor);
  18896. }
  18897. break;
  18898. case 141:
  18899. checkParameterTypeAnnotationsAsExpressions(node);
  18900. case 144:
  18901. case 143:
  18902. case 139:
  18903. case 136:
  18904. checkTypeAnnotationAsExpression(node);
  18905. break;
  18906. }
  18907. }
  18908. emitDecorate = true;
  18909. if (node.kind === 136) {
  18910. emitParam = true;
  18911. }
  18912. ts.forEach(node.decorators, checkDecorator);
  18913. }
  18914. function checkFunctionDeclaration(node) {
  18915. if (produceDiagnostics) {
  18916. checkFunctionLikeDeclaration(node) || checkGrammarForGenerator(node);
  18917. checkCollisionWithCapturedSuperVariable(node, node.name);
  18918. checkCollisionWithCapturedThisVariable(node, node.name);
  18919. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  18920. }
  18921. }
  18922. function checkFunctionLikeDeclaration(node) {
  18923. checkDecorators(node);
  18924. checkSignatureDeclaration(node);
  18925. var isAsync = ts.isAsyncFunctionLike(node);
  18926. if (isAsync) {
  18927. if (!compilerOptions.experimentalAsyncFunctions) {
  18928. error(node, ts.Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning);
  18929. }
  18930. emitAwaiter = true;
  18931. }
  18932. if (node.name && node.name.kind === 134) {
  18933. checkComputedPropertyName(node.name);
  18934. }
  18935. if (!ts.hasDynamicName(node)) {
  18936. var symbol = getSymbolOfNode(node);
  18937. var localSymbol = node.localSymbol || symbol;
  18938. var firstDeclaration = ts.getDeclarationOfKind(localSymbol, node.kind);
  18939. if (node === firstDeclaration) {
  18940. checkFunctionOrConstructorSymbol(localSymbol);
  18941. }
  18942. if (symbol.parent) {
  18943. if (ts.getDeclarationOfKind(symbol, node.kind) === node) {
  18944. checkFunctionOrConstructorSymbol(symbol);
  18945. }
  18946. }
  18947. }
  18948. checkSourceElement(node.body);
  18949. if (node.type && !isAccessor(node.kind) && !node.asteriskToken) {
  18950. var returnType = getTypeFromTypeNode(node.type);
  18951. var promisedType;
  18952. if (isAsync) {
  18953. promisedType = checkAsyncFunctionReturnType(node);
  18954. }
  18955. checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType);
  18956. }
  18957. if (produceDiagnostics && !node.type) {
  18958. if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) {
  18959. reportImplicitAnyError(node, anyType);
  18960. }
  18961. if (node.asteriskToken && ts.nodeIsPresent(node.body)) {
  18962. getReturnTypeOfSignature(getSignatureFromDeclaration(node));
  18963. }
  18964. }
  18965. }
  18966. function checkBlock(node) {
  18967. if (node.kind === 190) {
  18968. checkGrammarStatementInAmbientContext(node);
  18969. }
  18970. ts.forEach(node.statements, checkSourceElement);
  18971. if (ts.isFunctionBlock(node) || node.kind === 217) {
  18972. checkFunctionAndClassExpressionBodies(node);
  18973. }
  18974. }
  18975. function checkCollisionWithArgumentsInGeneratedCode(node) {
  18976. if (!ts.hasRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) {
  18977. return;
  18978. }
  18979. ts.forEach(node.parameters, function (p) {
  18980. if (p.name && !ts.isBindingPattern(p.name) && p.name.text === argumentsSymbol.name) {
  18981. error(p, ts.Diagnostics.Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters);
  18982. }
  18983. });
  18984. }
  18985. function needCollisionCheckForIdentifier(node, identifier, name) {
  18986. if (!(identifier && identifier.text === name)) {
  18987. return false;
  18988. }
  18989. if (node.kind === 139 ||
  18990. node.kind === 138 ||
  18991. node.kind === 141 ||
  18992. node.kind === 140 ||
  18993. node.kind === 143 ||
  18994. node.kind === 144) {
  18995. return false;
  18996. }
  18997. if (ts.isInAmbientContext(node)) {
  18998. return false;
  18999. }
  19000. var root = ts.getRootDeclaration(node);
  19001. if (root.kind === 136 && ts.nodeIsMissing(root.parent.body)) {
  19002. return false;
  19003. }
  19004. return true;
  19005. }
  19006. function checkCollisionWithCapturedThisVariable(node, name) {
  19007. if (needCollisionCheckForIdentifier(node, name, "_this")) {
  19008. potentialThisCollisions.push(node);
  19009. }
  19010. }
  19011. function checkIfThisIsCapturedInEnclosingScope(node) {
  19012. var current = node;
  19013. while (current) {
  19014. if (getNodeCheckFlags(current) & 4) {
  19015. var isDeclaration_1 = node.kind !== 67;
  19016. if (isDeclaration_1) {
  19017. error(node.name, ts.Diagnostics.Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference);
  19018. }
  19019. else {
  19020. error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference);
  19021. }
  19022. return;
  19023. }
  19024. current = current.parent;
  19025. }
  19026. }
  19027. function checkCollisionWithCapturedSuperVariable(node, name) {
  19028. if (!needCollisionCheckForIdentifier(node, name, "_super")) {
  19029. return;
  19030. }
  19031. var enclosingClass = ts.getContainingClass(node);
  19032. if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) {
  19033. return;
  19034. }
  19035. if (ts.getClassExtendsHeritageClauseElement(enclosingClass)) {
  19036. var isDeclaration_2 = node.kind !== 67;
  19037. if (isDeclaration_2) {
  19038. error(node, ts.Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference);
  19039. }
  19040. else {
  19041. error(node, ts.Diagnostics.Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference);
  19042. }
  19043. }
  19044. }
  19045. function checkCollisionWithRequireExportsInGeneratedCode(node, name) {
  19046. if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
  19047. return;
  19048. }
  19049. if (node.kind === 216 && ts.getModuleInstanceState(node) !== 1) {
  19050. return;
  19051. }
  19052. var parent = getDeclarationContainer(node);
  19053. if (parent.kind === 246 && ts.isExternalModule(parent)) {
  19054. error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name));
  19055. }
  19056. }
  19057. function checkVarDeclaredNamesNotShadowed(node) {
  19058. // - ScriptBody : StatementList
  19059. // It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList
  19060. // also occurs in the VarDeclaredNames of StatementList.
  19061. if ((ts.getCombinedNodeFlags(node) & 49152) !== 0 || ts.isParameterDeclaration(node)) {
  19062. return;
  19063. }
  19064. if (node.kind === 209 && !node.initializer) {
  19065. return;
  19066. }
  19067. var symbol = getSymbolOfNode(node);
  19068. if (symbol.flags & 1) {
  19069. var localDeclarationSymbol = resolveName(node, node.name.text, 3, undefined, undefined);
  19070. if (localDeclarationSymbol &&
  19071. localDeclarationSymbol !== symbol &&
  19072. localDeclarationSymbol.flags & 2) {
  19073. if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 49152) {
  19074. var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 210);
  19075. var container = varDeclList.parent.kind === 191 && varDeclList.parent.parent
  19076. ? varDeclList.parent.parent
  19077. : undefined;
  19078. var namesShareScope = container &&
  19079. (container.kind === 190 && ts.isFunctionLike(container.parent) ||
  19080. container.kind === 217 ||
  19081. container.kind === 216 ||
  19082. container.kind === 246);
  19083. if (!namesShareScope) {
  19084. var name_14 = symbolToString(localDeclarationSymbol);
  19085. error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_14, name_14);
  19086. }
  19087. }
  19088. }
  19089. }
  19090. }
  19091. function checkParameterInitializer(node) {
  19092. if (ts.getRootDeclaration(node).kind !== 136) {
  19093. return;
  19094. }
  19095. var func = ts.getContainingFunction(node);
  19096. visit(node.initializer);
  19097. function visit(n) {
  19098. if (n.kind === 67) {
  19099. var referencedSymbol = getNodeLinks(n).resolvedSymbol;
  19100. if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455) === referencedSymbol) {
  19101. if (referencedSymbol.valueDeclaration.kind === 136) {
  19102. if (referencedSymbol.valueDeclaration === node) {
  19103. error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name));
  19104. return;
  19105. }
  19106. if (referencedSymbol.valueDeclaration.pos < node.pos) {
  19107. return;
  19108. }
  19109. }
  19110. error(n, ts.Diagnostics.Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(node.name), ts.declarationNameToString(n));
  19111. }
  19112. }
  19113. else {
  19114. ts.forEachChild(n, visit);
  19115. }
  19116. }
  19117. }
  19118. function checkVariableLikeDeclaration(node) {
  19119. checkDecorators(node);
  19120. checkSourceElement(node.type);
  19121. if (node.name.kind === 134) {
  19122. checkComputedPropertyName(node.name);
  19123. if (node.initializer) {
  19124. checkExpressionCached(node.initializer);
  19125. }
  19126. }
  19127. if (ts.isBindingPattern(node.name)) {
  19128. ts.forEach(node.name.elements, checkSourceElement);
  19129. }
  19130. if (node.initializer && ts.getRootDeclaration(node).kind === 136 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
  19131. error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
  19132. return;
  19133. }
  19134. if (ts.isBindingPattern(node.name)) {
  19135. if (node.initializer) {
  19136. checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, undefined);
  19137. checkParameterInitializer(node);
  19138. }
  19139. return;
  19140. }
  19141. var symbol = getSymbolOfNode(node);
  19142. var type = getTypeOfVariableOrParameterOrProperty(symbol);
  19143. if (node === symbol.valueDeclaration) {
  19144. if (node.initializer) {
  19145. checkTypeAssignableTo(checkExpressionCached(node.initializer), type, node, undefined);
  19146. checkParameterInitializer(node);
  19147. }
  19148. }
  19149. else {
  19150. var declarationType = getWidenedTypeForVariableLikeDeclaration(node);
  19151. if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) {
  19152. 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));
  19153. }
  19154. if (node.initializer) {
  19155. checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined);
  19156. }
  19157. }
  19158. if (node.kind !== 139 && node.kind !== 138) {
  19159. checkExportsOnMergedDeclarations(node);
  19160. if (node.kind === 209 || node.kind === 161) {
  19161. checkVarDeclaredNamesNotShadowed(node);
  19162. }
  19163. checkCollisionWithCapturedSuperVariable(node, node.name);
  19164. checkCollisionWithCapturedThisVariable(node, node.name);
  19165. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  19166. }
  19167. }
  19168. function checkVariableDeclaration(node) {
  19169. checkGrammarVariableDeclaration(node);
  19170. return checkVariableLikeDeclaration(node);
  19171. }
  19172. function checkBindingElement(node) {
  19173. checkGrammarBindingElement(node);
  19174. return checkVariableLikeDeclaration(node);
  19175. }
  19176. function checkVariableStatement(node) {
  19177. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node);
  19178. ts.forEach(node.declarationList.declarations, checkSourceElement);
  19179. }
  19180. function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) {
  19181. if (node.modifiers && node.parent.kind === 163) {
  19182. if (ts.isAsyncFunctionLike(node)) {
  19183. if (node.modifiers.length > 1) {
  19184. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  19185. }
  19186. }
  19187. else {
  19188. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  19189. }
  19190. }
  19191. }
  19192. function checkExpressionStatement(node) {
  19193. checkGrammarStatementInAmbientContext(node);
  19194. checkExpression(node.expression);
  19195. }
  19196. function checkIfStatement(node) {
  19197. checkGrammarStatementInAmbientContext(node);
  19198. checkExpression(node.expression);
  19199. checkSourceElement(node.thenStatement);
  19200. checkSourceElement(node.elseStatement);
  19201. }
  19202. function checkDoStatement(node) {
  19203. checkGrammarStatementInAmbientContext(node);
  19204. checkSourceElement(node.statement);
  19205. checkExpression(node.expression);
  19206. }
  19207. function checkWhileStatement(node) {
  19208. checkGrammarStatementInAmbientContext(node);
  19209. checkExpression(node.expression);
  19210. checkSourceElement(node.statement);
  19211. }
  19212. function checkForStatement(node) {
  19213. if (!checkGrammarStatementInAmbientContext(node)) {
  19214. if (node.initializer && node.initializer.kind === 210) {
  19215. checkGrammarVariableDeclarationList(node.initializer);
  19216. }
  19217. }
  19218. if (node.initializer) {
  19219. if (node.initializer.kind === 210) {
  19220. ts.forEach(node.initializer.declarations, checkVariableDeclaration);
  19221. }
  19222. else {
  19223. checkExpression(node.initializer);
  19224. }
  19225. }
  19226. if (node.condition)
  19227. checkExpression(node.condition);
  19228. if (node.incrementor)
  19229. checkExpression(node.incrementor);
  19230. checkSourceElement(node.statement);
  19231. }
  19232. function checkForOfStatement(node) {
  19233. checkGrammarForInOrForOfStatement(node);
  19234. if (node.initializer.kind === 210) {
  19235. checkForInOrForOfVariableDeclaration(node);
  19236. }
  19237. else {
  19238. var varExpr = node.initializer;
  19239. var iteratedType = checkRightHandSideOfForOf(node.expression);
  19240. if (varExpr.kind === 162 || varExpr.kind === 163) {
  19241. checkDestructuringAssignment(varExpr, iteratedType || unknownType);
  19242. }
  19243. else {
  19244. var leftType = checkExpression(varExpr);
  19245. 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);
  19246. if (iteratedType) {
  19247. checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined);
  19248. }
  19249. }
  19250. }
  19251. checkSourceElement(node.statement);
  19252. }
  19253. function checkForInStatement(node) {
  19254. checkGrammarForInOrForOfStatement(node);
  19255. if (node.initializer.kind === 210) {
  19256. var variable = node.initializer.declarations[0];
  19257. if (variable && ts.isBindingPattern(variable.name)) {
  19258. error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern);
  19259. }
  19260. checkForInOrForOfVariableDeclaration(node);
  19261. }
  19262. else {
  19263. var varExpr = node.initializer;
  19264. var leftType = checkExpression(varExpr);
  19265. if (varExpr.kind === 162 || varExpr.kind === 163) {
  19266. error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern);
  19267. }
  19268. else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) {
  19269. error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any);
  19270. }
  19271. else {
  19272. 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);
  19273. }
  19274. }
  19275. var rightType = checkExpression(node.expression);
  19276. if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 | 512)) {
  19277. 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);
  19278. }
  19279. checkSourceElement(node.statement);
  19280. }
  19281. function checkForInOrForOfVariableDeclaration(iterationStatement) {
  19282. var variableDeclarationList = iterationStatement.initializer;
  19283. if (variableDeclarationList.declarations.length >= 1) {
  19284. var decl = variableDeclarationList.declarations[0];
  19285. checkVariableDeclaration(decl);
  19286. }
  19287. }
  19288. function checkRightHandSideOfForOf(rhsExpression) {
  19289. var expressionType = getTypeOfExpression(rhsExpression);
  19290. return checkIteratedTypeOrElementType(expressionType, rhsExpression, true);
  19291. }
  19292. function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) {
  19293. if (isTypeAny(inputType)) {
  19294. return inputType;
  19295. }
  19296. if (languageVersion >= 2) {
  19297. return checkElementTypeOfIterable(inputType, errorNode);
  19298. }
  19299. if (allowStringInput) {
  19300. return checkElementTypeOfArrayOrString(inputType, errorNode);
  19301. }
  19302. if (isArrayLikeType(inputType)) {
  19303. var indexType = getIndexTypeOfType(inputType, 1);
  19304. if (indexType) {
  19305. return indexType;
  19306. }
  19307. }
  19308. error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType));
  19309. return unknownType;
  19310. }
  19311. function checkElementTypeOfIterable(iterable, errorNode) {
  19312. var elementType = getElementTypeOfIterable(iterable, errorNode);
  19313. if (errorNode && elementType) {
  19314. checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode);
  19315. }
  19316. return elementType || anyType;
  19317. }
  19318. function getElementTypeOfIterable(type, errorNode) {
  19319. if (isTypeAny(type)) {
  19320. return undefined;
  19321. }
  19322. var typeAsIterable = type;
  19323. if (!typeAsIterable.iterableElementType) {
  19324. if ((type.flags & 4096) && type.target === globalIterableType) {
  19325. typeAsIterable.iterableElementType = type.typeArguments[0];
  19326. }
  19327. else {
  19328. var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator"));
  19329. if (isTypeAny(iteratorFunction)) {
  19330. return undefined;
  19331. }
  19332. var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray;
  19333. if (iteratorFunctionSignatures.length === 0) {
  19334. if (errorNode) {
  19335. error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
  19336. }
  19337. return undefined;
  19338. }
  19339. typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode);
  19340. }
  19341. }
  19342. return typeAsIterable.iterableElementType;
  19343. }
  19344. function getElementTypeOfIterator(type, errorNode) {
  19345. if (isTypeAny(type)) {
  19346. return undefined;
  19347. }
  19348. var typeAsIterator = type;
  19349. if (!typeAsIterator.iteratorElementType) {
  19350. if ((type.flags & 4096) && type.target === globalIteratorType) {
  19351. typeAsIterator.iteratorElementType = type.typeArguments[0];
  19352. }
  19353. else {
  19354. var iteratorNextFunction = getTypeOfPropertyOfType(type, "next");
  19355. if (isTypeAny(iteratorNextFunction)) {
  19356. return undefined;
  19357. }
  19358. var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray;
  19359. if (iteratorNextFunctionSignatures.length === 0) {
  19360. if (errorNode) {
  19361. error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method);
  19362. }
  19363. return undefined;
  19364. }
  19365. var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
  19366. if (isTypeAny(iteratorNextResult)) {
  19367. return undefined;
  19368. }
  19369. var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
  19370. if (!iteratorNextValue) {
  19371. if (errorNode) {
  19372. error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
  19373. }
  19374. return undefined;
  19375. }
  19376. typeAsIterator.iteratorElementType = iteratorNextValue;
  19377. }
  19378. }
  19379. return typeAsIterator.iteratorElementType;
  19380. }
  19381. function getElementTypeOfIterableIterator(type) {
  19382. if (isTypeAny(type)) {
  19383. return undefined;
  19384. }
  19385. if ((type.flags & 4096) && type.target === globalIterableIteratorType) {
  19386. return type.typeArguments[0];
  19387. }
  19388. return getElementTypeOfIterable(type, undefined) ||
  19389. getElementTypeOfIterator(type, undefined);
  19390. }
  19391. function checkElementTypeOfArrayOrString(arrayOrStringType, errorNode) {
  19392. ts.Debug.assert(languageVersion < 2);
  19393. var arrayType = removeTypesFromUnionType(arrayOrStringType, 258, true, true);
  19394. var hasStringConstituent = arrayOrStringType !== arrayType;
  19395. var reportedError = false;
  19396. if (hasStringConstituent) {
  19397. if (languageVersion < 1) {
  19398. error(errorNode, ts.Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
  19399. reportedError = true;
  19400. }
  19401. if (arrayType === emptyObjectType) {
  19402. return stringType;
  19403. }
  19404. }
  19405. if (!isArrayLikeType(arrayType)) {
  19406. if (!reportedError) {
  19407. var diagnostic = hasStringConstituent
  19408. ? ts.Diagnostics.Type_0_is_not_an_array_type
  19409. : ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
  19410. error(errorNode, diagnostic, typeToString(arrayType));
  19411. }
  19412. return hasStringConstituent ? stringType : unknownType;
  19413. }
  19414. var arrayElementType = getIndexTypeOfType(arrayType, 1) || unknownType;
  19415. if (hasStringConstituent) {
  19416. if (arrayElementType.flags & 258) {
  19417. return stringType;
  19418. }
  19419. return getUnionType([arrayElementType, stringType]);
  19420. }
  19421. return arrayElementType;
  19422. }
  19423. function checkBreakOrContinueStatement(node) {
  19424. checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node);
  19425. }
  19426. function isGetAccessorWithAnnotatatedSetAccessor(node) {
  19427. return !!(node.kind === 143 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 144)));
  19428. }
  19429. function checkReturnStatement(node) {
  19430. if (!checkGrammarStatementInAmbientContext(node)) {
  19431. var functionBlock = ts.getContainingFunction(node);
  19432. if (!functionBlock) {
  19433. grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
  19434. }
  19435. }
  19436. if (node.expression) {
  19437. var func = ts.getContainingFunction(node);
  19438. if (func) {
  19439. var signature = getSignatureFromDeclaration(func);
  19440. var returnType = getReturnTypeOfSignature(signature);
  19441. var exprType = checkExpressionCached(node.expression);
  19442. if (func.asteriskToken) {
  19443. return;
  19444. }
  19445. if (func.kind === 144) {
  19446. error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value);
  19447. }
  19448. else if (func.kind === 142) {
  19449. if (!isTypeAssignableTo(exprType, returnType)) {
  19450. error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
  19451. }
  19452. }
  19453. else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func) || signature.typePredicate) {
  19454. if (ts.isAsyncFunctionLike(func)) {
  19455. var promisedType = getPromisedType(returnType);
  19456. var awaitedType = checkAwaitedType(exprType, node.expression, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
  19457. checkTypeAssignableTo(awaitedType, promisedType, node.expression);
  19458. }
  19459. else {
  19460. checkTypeAssignableTo(exprType, returnType, node.expression);
  19461. }
  19462. }
  19463. }
  19464. }
  19465. }
  19466. function checkWithStatement(node) {
  19467. if (!checkGrammarStatementInAmbientContext(node)) {
  19468. if (node.parserContextFlags & 8) {
  19469. grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_an_async_function_block);
  19470. }
  19471. }
  19472. checkExpression(node.expression);
  19473. error(node.expression, ts.Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
  19474. }
  19475. function checkSwitchStatement(node) {
  19476. checkGrammarStatementInAmbientContext(node);
  19477. var firstDefaultClause;
  19478. var hasDuplicateDefaultClause = false;
  19479. var expressionType = checkExpression(node.expression);
  19480. ts.forEach(node.caseBlock.clauses, function (clause) {
  19481. if (clause.kind === 240 && !hasDuplicateDefaultClause) {
  19482. if (firstDefaultClause === undefined) {
  19483. firstDefaultClause = clause;
  19484. }
  19485. else {
  19486. var sourceFile = ts.getSourceFileOfNode(node);
  19487. var start = ts.skipTrivia(sourceFile.text, clause.pos);
  19488. var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
  19489. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
  19490. hasDuplicateDefaultClause = true;
  19491. }
  19492. }
  19493. if (produceDiagnostics && clause.kind === 239) {
  19494. var caseClause = clause;
  19495. var caseType = checkExpression(caseClause.expression);
  19496. if (!isTypeAssignableTo(expressionType, caseType)) {
  19497. checkTypeAssignableTo(caseType, expressionType, caseClause.expression, undefined);
  19498. }
  19499. }
  19500. ts.forEach(clause.statements, checkSourceElement);
  19501. });
  19502. }
  19503. function checkLabeledStatement(node) {
  19504. if (!checkGrammarStatementInAmbientContext(node)) {
  19505. var current = node.parent;
  19506. while (current) {
  19507. if (ts.isFunctionLike(current)) {
  19508. break;
  19509. }
  19510. if (current.kind === 205 && current.label.text === node.label.text) {
  19511. var sourceFile = ts.getSourceFileOfNode(node);
  19512. grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label));
  19513. break;
  19514. }
  19515. current = current.parent;
  19516. }
  19517. }
  19518. checkSourceElement(node.statement);
  19519. }
  19520. function checkThrowStatement(node) {
  19521. if (!checkGrammarStatementInAmbientContext(node)) {
  19522. if (node.expression === undefined) {
  19523. grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here);
  19524. }
  19525. }
  19526. if (node.expression) {
  19527. checkExpression(node.expression);
  19528. }
  19529. }
  19530. function checkTryStatement(node) {
  19531. checkGrammarStatementInAmbientContext(node);
  19532. checkBlock(node.tryBlock);
  19533. var catchClause = node.catchClause;
  19534. if (catchClause) {
  19535. if (catchClause.variableDeclaration) {
  19536. if (catchClause.variableDeclaration.name.kind !== 67) {
  19537. grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier);
  19538. }
  19539. else if (catchClause.variableDeclaration.type) {
  19540. grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation);
  19541. }
  19542. else if (catchClause.variableDeclaration.initializer) {
  19543. grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
  19544. }
  19545. else {
  19546. var identifierName = catchClause.variableDeclaration.name.text;
  19547. var locals = catchClause.block.locals;
  19548. if (locals && ts.hasProperty(locals, identifierName)) {
  19549. var localSymbol = locals[identifierName];
  19550. if (localSymbol && (localSymbol.flags & 2) !== 0) {
  19551. grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
  19552. }
  19553. }
  19554. }
  19555. }
  19556. checkBlock(catchClause.block);
  19557. }
  19558. if (node.finallyBlock) {
  19559. checkBlock(node.finallyBlock);
  19560. }
  19561. }
  19562. function checkIndexConstraints(type) {
  19563. var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1);
  19564. var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, 0);
  19565. var stringIndexType = getIndexTypeOfType(type, 0);
  19566. var numberIndexType = getIndexTypeOfType(type, 1);
  19567. if (stringIndexType || numberIndexType) {
  19568. ts.forEach(getPropertiesOfObjectType(type), function (prop) {
  19569. var propType = getTypeOfSymbol(prop);
  19570. checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0);
  19571. checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1);
  19572. });
  19573. if (type.flags & 1024 && ts.isClassLike(type.symbol.valueDeclaration)) {
  19574. var classDeclaration = type.symbol.valueDeclaration;
  19575. for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) {
  19576. var member = _a[_i];
  19577. if (!(member.flags & 128) && ts.hasDynamicName(member)) {
  19578. var propType = getTypeOfSymbol(member.symbol);
  19579. checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, 0);
  19580. checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, 1);
  19581. }
  19582. }
  19583. }
  19584. }
  19585. var errorNode;
  19586. if (stringIndexType && numberIndexType) {
  19587. errorNode = declaredNumberIndexer || declaredStringIndexer;
  19588. if (!errorNode && (type.flags & 2048)) {
  19589. var someBaseTypeHasBothIndexers = ts.forEach(getBaseTypes(type), function (base) { return getIndexTypeOfType(base, 0) && getIndexTypeOfType(base, 1); });
  19590. errorNode = someBaseTypeHasBothIndexers ? undefined : type.symbol.declarations[0];
  19591. }
  19592. }
  19593. if (errorNode && !isTypeAssignableTo(numberIndexType, stringIndexType)) {
  19594. error(errorNode, ts.Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, typeToString(numberIndexType), typeToString(stringIndexType));
  19595. }
  19596. function checkIndexConstraintForProperty(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) {
  19597. if (!indexType) {
  19598. return;
  19599. }
  19600. if (indexKind === 1 && !isNumericName(prop.valueDeclaration.name)) {
  19601. return;
  19602. }
  19603. var errorNode;
  19604. if (prop.valueDeclaration.name.kind === 134 || prop.parent === containingType.symbol) {
  19605. errorNode = prop.valueDeclaration;
  19606. }
  19607. else if (indexDeclaration) {
  19608. errorNode = indexDeclaration;
  19609. }
  19610. else if (containingType.flags & 2048) {
  19611. var someBaseClassHasBothPropertyAndIndexer = ts.forEach(getBaseTypes(containingType), function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); });
  19612. errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0];
  19613. }
  19614. if (errorNode && !isTypeAssignableTo(propertyType, indexType)) {
  19615. var errorMessage = indexKind === 0
  19616. ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2
  19617. : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2;
  19618. error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType));
  19619. }
  19620. }
  19621. }
  19622. function checkTypeNameIsReserved(name, message) {
  19623. switch (name.text) {
  19624. case "any":
  19625. case "number":
  19626. case "boolean":
  19627. case "string":
  19628. case "symbol":
  19629. case "void":
  19630. error(name, message, name.text);
  19631. }
  19632. }
  19633. function checkTypeParameters(typeParameterDeclarations) {
  19634. if (typeParameterDeclarations) {
  19635. for (var i = 0, n = typeParameterDeclarations.length; i < n; i++) {
  19636. var node = typeParameterDeclarations[i];
  19637. checkTypeParameter(node);
  19638. if (produceDiagnostics) {
  19639. for (var j = 0; j < i; j++) {
  19640. if (typeParameterDeclarations[j].symbol === node.symbol) {
  19641. error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name));
  19642. }
  19643. }
  19644. }
  19645. }
  19646. }
  19647. }
  19648. function checkClassExpression(node) {
  19649. checkClassLikeDeclaration(node);
  19650. return getTypeOfSymbol(getSymbolOfNode(node));
  19651. }
  19652. function checkClassDeclaration(node) {
  19653. if (!node.name && !(node.flags & 1024)) {
  19654. grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
  19655. }
  19656. checkClassLikeDeclaration(node);
  19657. if (getSymbolOfNode(node).flags & 64 && !ts.isInAmbientContext(node)) {
  19658. error(node, ts.Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface);
  19659. }
  19660. ts.forEach(node.members, checkSourceElement);
  19661. }
  19662. function checkClassLikeDeclaration(node) {
  19663. checkGrammarClassDeclarationHeritageClauses(node);
  19664. checkDecorators(node);
  19665. if (node.name) {
  19666. checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0);
  19667. checkCollisionWithCapturedThisVariable(node, node.name);
  19668. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  19669. }
  19670. checkTypeParameters(node.typeParameters);
  19671. checkExportsOnMergedDeclarations(node);
  19672. var symbol = getSymbolOfNode(node);
  19673. var type = getDeclaredTypeOfSymbol(symbol);
  19674. var staticType = getTypeOfSymbol(symbol);
  19675. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  19676. if (baseTypeNode) {
  19677. emitExtends = emitExtends || !ts.isInAmbientContext(node);
  19678. var baseTypes = getBaseTypes(type);
  19679. if (baseTypes.length && produceDiagnostics) {
  19680. var baseType = baseTypes[0];
  19681. var staticBaseType = getBaseConstructorTypeOfClass(type);
  19682. checkSourceElement(baseTypeNode.expression);
  19683. if (baseTypeNode.typeArguments) {
  19684. ts.forEach(baseTypeNode.typeArguments, checkSourceElement);
  19685. for (var _i = 0, _a = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments); _i < _a.length; _i++) {
  19686. var constructor = _a[_i];
  19687. if (!checkTypeArgumentConstraints(constructor.typeParameters, baseTypeNode.typeArguments)) {
  19688. break;
  19689. }
  19690. }
  19691. }
  19692. checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
  19693. checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
  19694. if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32)) {
  19695. var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments);
  19696. if (ts.forEach(constructors, function (sig) { return getReturnTypeOfSignature(sig) !== baseType; })) {
  19697. error(baseTypeNode.expression, ts.Diagnostics.Base_constructors_must_all_have_the_same_return_type);
  19698. }
  19699. }
  19700. checkKindsOfPropertyMemberOverrides(type, baseType);
  19701. }
  19702. }
  19703. var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node);
  19704. if (implementedTypeNodes) {
  19705. ts.forEach(implementedTypeNodes, function (typeRefNode) {
  19706. if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) {
  19707. error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
  19708. }
  19709. checkTypeReferenceNode(typeRefNode);
  19710. if (produceDiagnostics) {
  19711. var t = getTypeFromTypeNode(typeRefNode);
  19712. if (t !== unknownType) {
  19713. var declaredType = (t.flags & 4096) ? t.target : t;
  19714. if (declaredType.flags & (1024 | 2048)) {
  19715. checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1);
  19716. }
  19717. else {
  19718. error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface);
  19719. }
  19720. }
  19721. }
  19722. });
  19723. }
  19724. if (produceDiagnostics) {
  19725. checkIndexConstraints(type);
  19726. checkTypeForDuplicateIndexSignatures(node);
  19727. }
  19728. }
  19729. function getTargetSymbol(s) {
  19730. return s.flags & 16777216 ? getSymbolLinks(s).target : s;
  19731. }
  19732. function checkKindsOfPropertyMemberOverrides(type, baseType) {
  19733. // TypeScript 1.0 spec (April 2014): 8.2.3
  19734. // A derived class inherits all members from its base class it doesn't override.
  19735. // Inheritance means that a derived class implicitly contains all non - overridden members of the base class.
  19736. // Both public and private property members are inherited, but only public property members can be overridden.
  19737. // A property member in a derived class is said to override a property member in a base class
  19738. // when the derived class property member has the same name and kind(instance or static)
  19739. // as the base class property member.
  19740. // The type of an overriding property member must be assignable(section 3.8.4)
  19741. // to the type of the overridden property member, or otherwise a compile - time error occurs.
  19742. // Base class instance member functions can be overridden by derived class instance member functions,
  19743. // but not by other kinds of members.
  19744. // Base class instance member variables and accessors can be overridden by
  19745. // derived class instance member variables and accessors, but not by other kinds of members.
  19746. var baseProperties = getPropertiesOfObjectType(baseType);
  19747. for (var _i = 0; _i < baseProperties.length; _i++) {
  19748. var baseProperty = baseProperties[_i];
  19749. var base = getTargetSymbol(baseProperty);
  19750. if (base.flags & 134217728) {
  19751. continue;
  19752. }
  19753. var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name));
  19754. var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base);
  19755. ts.Debug.assert(!!derived, "derived should point to something, even if it is the base class' declaration.");
  19756. if (derived) {
  19757. if (derived === base) {
  19758. var derivedClassDecl = ts.getDeclarationOfKind(type.symbol, 212);
  19759. if (baseDeclarationFlags & 256 && (!derivedClassDecl || !(derivedClassDecl.flags & 256))) {
  19760. error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2, typeToString(type), symbolToString(baseProperty), typeToString(baseType));
  19761. }
  19762. }
  19763. else {
  19764. var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived);
  19765. if ((baseDeclarationFlags & 32) || (derivedDeclarationFlags & 32)) {
  19766. continue;
  19767. }
  19768. if ((baseDeclarationFlags & 128) !== (derivedDeclarationFlags & 128)) {
  19769. continue;
  19770. }
  19771. if ((base.flags & derived.flags & 8192) || ((base.flags & 98308) && (derived.flags & 98308))) {
  19772. continue;
  19773. }
  19774. var errorMessage = void 0;
  19775. if (base.flags & 8192) {
  19776. if (derived.flags & 98304) {
  19777. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor;
  19778. }
  19779. else {
  19780. ts.Debug.assert((derived.flags & 4) !== 0);
  19781. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property;
  19782. }
  19783. }
  19784. else if (base.flags & 4) {
  19785. ts.Debug.assert((derived.flags & 8192) !== 0);
  19786. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function;
  19787. }
  19788. else {
  19789. ts.Debug.assert((base.flags & 98304) !== 0);
  19790. ts.Debug.assert((derived.flags & 8192) !== 0);
  19791. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function;
  19792. }
  19793. error(derived.valueDeclaration.name, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
  19794. }
  19795. }
  19796. }
  19797. }
  19798. function isAccessor(kind) {
  19799. return kind === 143 || kind === 144;
  19800. }
  19801. function areTypeParametersIdentical(list1, list2) {
  19802. if (!list1 && !list2) {
  19803. return true;
  19804. }
  19805. if (!list1 || !list2 || list1.length !== list2.length) {
  19806. return false;
  19807. }
  19808. for (var i = 0, len = list1.length; i < len; i++) {
  19809. var tp1 = list1[i];
  19810. var tp2 = list2[i];
  19811. if (tp1.name.text !== tp2.name.text) {
  19812. return false;
  19813. }
  19814. if (!tp1.constraint && !tp2.constraint) {
  19815. continue;
  19816. }
  19817. if (!tp1.constraint || !tp2.constraint) {
  19818. return false;
  19819. }
  19820. if (!isTypeIdenticalTo(getTypeFromTypeNode(tp1.constraint), getTypeFromTypeNode(tp2.constraint))) {
  19821. return false;
  19822. }
  19823. }
  19824. return true;
  19825. }
  19826. function checkInheritedPropertiesAreIdentical(type, typeNode) {
  19827. var baseTypes = getBaseTypes(type);
  19828. if (baseTypes.length < 2) {
  19829. return true;
  19830. }
  19831. var seen = {};
  19832. ts.forEach(resolveDeclaredMembers(type).declaredProperties, function (p) { seen[p.name] = { prop: p, containingType: type }; });
  19833. var ok = true;
  19834. for (var _i = 0; _i < baseTypes.length; _i++) {
  19835. var base = baseTypes[_i];
  19836. var properties = getPropertiesOfObjectType(base);
  19837. for (var _a = 0; _a < properties.length; _a++) {
  19838. var prop = properties[_a];
  19839. if (!ts.hasProperty(seen, prop.name)) {
  19840. seen[prop.name] = { prop: prop, containingType: base };
  19841. }
  19842. else {
  19843. var existing = seen[prop.name];
  19844. var isInheritedProperty = existing.containingType !== type;
  19845. if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) {
  19846. ok = false;
  19847. var typeName1 = typeToString(existing.containingType);
  19848. var typeName2 = typeToString(base);
  19849. var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2);
  19850. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
  19851. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
  19852. }
  19853. }
  19854. }
  19855. }
  19856. return ok;
  19857. }
  19858. function checkInterfaceDeclaration(node) {
  19859. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node);
  19860. checkTypeParameters(node.typeParameters);
  19861. if (produceDiagnostics) {
  19862. checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
  19863. checkExportsOnMergedDeclarations(node);
  19864. var symbol = getSymbolOfNode(node);
  19865. var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 213);
  19866. if (symbol.declarations.length > 1) {
  19867. if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) {
  19868. error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters);
  19869. }
  19870. }
  19871. if (node === firstInterfaceDecl) {
  19872. var type = getDeclaredTypeOfSymbol(symbol);
  19873. if (checkInheritedPropertiesAreIdentical(type, node.name)) {
  19874. ts.forEach(getBaseTypes(type), function (baseType) {
  19875. checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1);
  19876. });
  19877. checkIndexConstraints(type);
  19878. }
  19879. }
  19880. if (symbol && symbol.declarations) {
  19881. for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
  19882. var declaration = _a[_i];
  19883. if (declaration.kind === 212 && !ts.isInAmbientContext(declaration)) {
  19884. error(node, ts.Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface);
  19885. break;
  19886. }
  19887. }
  19888. }
  19889. }
  19890. ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) {
  19891. if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) {
  19892. error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
  19893. }
  19894. checkTypeReferenceNode(heritageElement);
  19895. });
  19896. ts.forEach(node.members, checkSourceElement);
  19897. if (produceDiagnostics) {
  19898. checkTypeForDuplicateIndexSignatures(node);
  19899. }
  19900. }
  19901. function checkTypeAliasDeclaration(node) {
  19902. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  19903. checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_alias_name_cannot_be_0);
  19904. checkSourceElement(node.type);
  19905. }
  19906. function computeEnumMemberValues(node) {
  19907. var nodeLinks = getNodeLinks(node);
  19908. if (!(nodeLinks.flags & 8192)) {
  19909. var enumSymbol = getSymbolOfNode(node);
  19910. var enumType = getDeclaredTypeOfSymbol(enumSymbol);
  19911. var autoValue = 0;
  19912. var ambient = ts.isInAmbientContext(node);
  19913. var enumIsConst = ts.isConst(node);
  19914. ts.forEach(node.members, function (member) {
  19915. if (member.name.kind !== 134 && isNumericLiteralName(member.name.text)) {
  19916. error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
  19917. }
  19918. var initializer = member.initializer;
  19919. if (initializer) {
  19920. autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient);
  19921. }
  19922. else if (ambient && !enumIsConst) {
  19923. autoValue = undefined;
  19924. }
  19925. if (autoValue !== undefined) {
  19926. getNodeLinks(member).enumMemberValue = autoValue++;
  19927. }
  19928. });
  19929. nodeLinks.flags |= 8192;
  19930. }
  19931. function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) {
  19932. var reportError = true;
  19933. var value = evalConstant(initializer);
  19934. if (reportError) {
  19935. if (value === undefined) {
  19936. if (enumIsConst) {
  19937. error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
  19938. }
  19939. else if (!ambient) {
  19940. checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined);
  19941. }
  19942. }
  19943. else if (enumIsConst) {
  19944. if (isNaN(value)) {
  19945. error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN);
  19946. }
  19947. else if (!isFinite(value)) {
  19948. error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value);
  19949. }
  19950. }
  19951. }
  19952. return value;
  19953. function evalConstant(e) {
  19954. switch (e.kind) {
  19955. case 177:
  19956. var value_1 = evalConstant(e.operand);
  19957. if (value_1 === undefined) {
  19958. return undefined;
  19959. }
  19960. switch (e.operator) {
  19961. case 35: return value_1;
  19962. case 36: return -value_1;
  19963. case 49: return ~value_1;
  19964. }
  19965. return undefined;
  19966. case 179:
  19967. var left = evalConstant(e.left);
  19968. if (left === undefined) {
  19969. return undefined;
  19970. }
  19971. var right = evalConstant(e.right);
  19972. if (right === undefined) {
  19973. return undefined;
  19974. }
  19975. switch (e.operatorToken.kind) {
  19976. case 46: return left | right;
  19977. case 45: return left & right;
  19978. case 43: return left >> right;
  19979. case 44: return left >>> right;
  19980. case 42: return left << right;
  19981. case 47: return left ^ right;
  19982. case 37: return left * right;
  19983. case 38: return left / right;
  19984. case 35: return left + right;
  19985. case 36: return left - right;
  19986. case 39: return left % right;
  19987. }
  19988. return undefined;
  19989. case 8:
  19990. return +e.text;
  19991. case 170:
  19992. return evalConstant(e.expression);
  19993. case 67:
  19994. case 165:
  19995. case 164:
  19996. var member = initializer.parent;
  19997. var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent));
  19998. var enumType_1;
  19999. var propertyName;
  20000. if (e.kind === 67) {
  20001. enumType_1 = currentType;
  20002. propertyName = e.text;
  20003. }
  20004. else {
  20005. var expression;
  20006. if (e.kind === 165) {
  20007. if (e.argumentExpression === undefined ||
  20008. e.argumentExpression.kind !== 9) {
  20009. return undefined;
  20010. }
  20011. expression = e.expression;
  20012. propertyName = e.argumentExpression.text;
  20013. }
  20014. else {
  20015. expression = e.expression;
  20016. propertyName = e.name.text;
  20017. }
  20018. var current = expression;
  20019. while (current) {
  20020. if (current.kind === 67) {
  20021. break;
  20022. }
  20023. else if (current.kind === 164) {
  20024. current = current.expression;
  20025. }
  20026. else {
  20027. return undefined;
  20028. }
  20029. }
  20030. enumType_1 = checkExpression(expression);
  20031. if (!(enumType_1.symbol && (enumType_1.symbol.flags & 384))) {
  20032. return undefined;
  20033. }
  20034. }
  20035. if (propertyName === undefined) {
  20036. return undefined;
  20037. }
  20038. var property = getPropertyOfObjectType(enumType_1, propertyName);
  20039. if (!property || !(property.flags & 8)) {
  20040. return undefined;
  20041. }
  20042. var propertyDecl = property.valueDeclaration;
  20043. if (member === propertyDecl) {
  20044. return undefined;
  20045. }
  20046. if (!isDefinedBefore(propertyDecl, member)) {
  20047. reportError = false;
  20048. error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
  20049. return undefined;
  20050. }
  20051. return getNodeLinks(propertyDecl).enumMemberValue;
  20052. }
  20053. }
  20054. }
  20055. }
  20056. function checkEnumDeclaration(node) {
  20057. if (!produceDiagnostics) {
  20058. return;
  20059. }
  20060. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node);
  20061. checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0);
  20062. checkCollisionWithCapturedThisVariable(node, node.name);
  20063. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  20064. checkExportsOnMergedDeclarations(node);
  20065. computeEnumMemberValues(node);
  20066. var enumIsConst = ts.isConst(node);
  20067. if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) {
  20068. error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided);
  20069. }
  20070. var enumSymbol = getSymbolOfNode(node);
  20071. var firstDeclaration = ts.getDeclarationOfKind(enumSymbol, node.kind);
  20072. if (node === firstDeclaration) {
  20073. if (enumSymbol.declarations.length > 1) {
  20074. ts.forEach(enumSymbol.declarations, function (decl) {
  20075. if (ts.isConstEnumDeclaration(decl) !== enumIsConst) {
  20076. error(decl.name, ts.Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
  20077. }
  20078. });
  20079. }
  20080. var seenEnumMissingInitialInitializer = false;
  20081. ts.forEach(enumSymbol.declarations, function (declaration) {
  20082. if (declaration.kind !== 215) {
  20083. return false;
  20084. }
  20085. var enumDeclaration = declaration;
  20086. if (!enumDeclaration.members.length) {
  20087. return false;
  20088. }
  20089. var firstEnumMember = enumDeclaration.members[0];
  20090. if (!firstEnumMember.initializer) {
  20091. if (seenEnumMissingInitialInitializer) {
  20092. error(firstEnumMember.name, ts.Diagnostics.In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element);
  20093. }
  20094. else {
  20095. seenEnumMissingInitialInitializer = true;
  20096. }
  20097. }
  20098. });
  20099. }
  20100. }
  20101. function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
  20102. var declarations = symbol.declarations;
  20103. for (var _i = 0; _i < declarations.length; _i++) {
  20104. var declaration = declarations[_i];
  20105. if ((declaration.kind === 212 ||
  20106. (declaration.kind === 211 && ts.nodeIsPresent(declaration.body))) &&
  20107. !ts.isInAmbientContext(declaration)) {
  20108. return declaration;
  20109. }
  20110. }
  20111. return undefined;
  20112. }
  20113. function inSameLexicalScope(node1, node2) {
  20114. var container1 = ts.getEnclosingBlockScopeContainer(node1);
  20115. var container2 = ts.getEnclosingBlockScopeContainer(node2);
  20116. if (isGlobalSourceFile(container1)) {
  20117. return isGlobalSourceFile(container2);
  20118. }
  20119. else if (isGlobalSourceFile(container2)) {
  20120. return false;
  20121. }
  20122. else {
  20123. return container1 === container2;
  20124. }
  20125. }
  20126. function checkModuleDeclaration(node) {
  20127. if (produceDiagnostics) {
  20128. var isAmbientExternalModule = node.name.kind === 9;
  20129. var contextErrorMessage = isAmbientExternalModule
  20130. ? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
  20131. : ts.Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
  20132. if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
  20133. return;
  20134. }
  20135. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) {
  20136. if (!ts.isInAmbientContext(node) && node.name.kind === 9) {
  20137. grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
  20138. }
  20139. }
  20140. checkCollisionWithCapturedThisVariable(node, node.name);
  20141. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  20142. checkExportsOnMergedDeclarations(node);
  20143. var symbol = getSymbolOfNode(node);
  20144. if (symbol.flags & 512
  20145. && symbol.declarations.length > 1
  20146. && !ts.isInAmbientContext(node)
  20147. && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) {
  20148. var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
  20149. if (firstNonAmbientClassOrFunc) {
  20150. if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) {
  20151. error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged);
  20152. }
  20153. else if (node.pos < firstNonAmbientClassOrFunc.pos) {
  20154. error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged);
  20155. }
  20156. }
  20157. var mergedClass = ts.getDeclarationOfKind(symbol, 212);
  20158. if (mergedClass &&
  20159. inSameLexicalScope(node, mergedClass)) {
  20160. getNodeLinks(node).flags |= 32768;
  20161. }
  20162. }
  20163. if (isAmbientExternalModule) {
  20164. if (!isGlobalSourceFile(node.parent)) {
  20165. error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules);
  20166. }
  20167. if (isExternalModuleNameRelative(node.name.text)) {
  20168. error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name);
  20169. }
  20170. }
  20171. }
  20172. checkSourceElement(node.body);
  20173. }
  20174. function getFirstIdentifier(node) {
  20175. while (true) {
  20176. if (node.kind === 133) {
  20177. node = node.left;
  20178. }
  20179. else if (node.kind === 164) {
  20180. node = node.expression;
  20181. }
  20182. else {
  20183. break;
  20184. }
  20185. }
  20186. ts.Debug.assert(node.kind === 67);
  20187. return node;
  20188. }
  20189. function checkExternalImportOrExportDeclaration(node) {
  20190. var moduleName = ts.getExternalModuleName(node);
  20191. if (!ts.nodeIsMissing(moduleName) && moduleName.kind !== 9) {
  20192. error(moduleName, ts.Diagnostics.String_literal_expected);
  20193. return false;
  20194. }
  20195. var inAmbientExternalModule = node.parent.kind === 217 && node.parent.parent.name.kind === 9;
  20196. if (node.parent.kind !== 246 && !inAmbientExternalModule) {
  20197. error(moduleName, node.kind === 226 ?
  20198. ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace :
  20199. ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module);
  20200. return false;
  20201. }
  20202. if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) {
  20203. error(node, ts.Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name);
  20204. return false;
  20205. }
  20206. return true;
  20207. }
  20208. function checkAliasSymbol(node) {
  20209. var symbol = getSymbolOfNode(node);
  20210. var target = resolveAlias(symbol);
  20211. if (target !== unknownSymbol) {
  20212. var excludedMeanings = (symbol.flags & 107455 ? 107455 : 0) |
  20213. (symbol.flags & 793056 ? 793056 : 0) |
  20214. (symbol.flags & 1536 ? 1536 : 0);
  20215. if (target.flags & excludedMeanings) {
  20216. var message = node.kind === 228 ?
  20217. ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
  20218. ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
  20219. error(node, message, symbolToString(symbol));
  20220. }
  20221. }
  20222. }
  20223. function checkImportBinding(node) {
  20224. checkCollisionWithCapturedThisVariable(node, node.name);
  20225. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  20226. checkAliasSymbol(node);
  20227. }
  20228. function checkImportDeclaration(node) {
  20229. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
  20230. return;
  20231. }
  20232. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) {
  20233. grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers);
  20234. }
  20235. if (checkExternalImportOrExportDeclaration(node)) {
  20236. var importClause = node.importClause;
  20237. if (importClause) {
  20238. if (importClause.name) {
  20239. checkImportBinding(importClause);
  20240. }
  20241. if (importClause.namedBindings) {
  20242. if (importClause.namedBindings.kind === 222) {
  20243. checkImportBinding(importClause.namedBindings);
  20244. }
  20245. else {
  20246. ts.forEach(importClause.namedBindings.elements, checkImportBinding);
  20247. }
  20248. }
  20249. }
  20250. }
  20251. }
  20252. function checkImportEqualsDeclaration(node) {
  20253. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
  20254. return;
  20255. }
  20256. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  20257. if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
  20258. checkImportBinding(node);
  20259. if (node.flags & 1) {
  20260. markExportAsReferenced(node);
  20261. }
  20262. if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  20263. var target = resolveAlias(getSymbolOfNode(node));
  20264. if (target !== unknownSymbol) {
  20265. if (target.flags & 107455) {
  20266. var moduleName = getFirstIdentifier(node.moduleReference);
  20267. if (!(resolveEntityName(moduleName, 107455 | 1536).flags & 1536)) {
  20268. error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName));
  20269. }
  20270. }
  20271. if (target.flags & 793056) {
  20272. checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0);
  20273. }
  20274. }
  20275. }
  20276. else {
  20277. if (languageVersion >= 2 && !ts.isInAmbientContext(node)) {
  20278. grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead);
  20279. }
  20280. }
  20281. }
  20282. }
  20283. function checkExportDeclaration(node) {
  20284. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
  20285. return;
  20286. }
  20287. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) {
  20288. grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers);
  20289. }
  20290. if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) {
  20291. if (node.exportClause) {
  20292. ts.forEach(node.exportClause.elements, checkExportSpecifier);
  20293. var inAmbientExternalModule = node.parent.kind === 217 && node.parent.parent.name.kind === 9;
  20294. if (node.parent.kind !== 246 && !inAmbientExternalModule) {
  20295. error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
  20296. }
  20297. }
  20298. else {
  20299. var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
  20300. if (moduleSymbol && moduleSymbol.exports["export="]) {
  20301. error(node.moduleSpecifier, ts.Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
  20302. }
  20303. }
  20304. }
  20305. }
  20306. function checkGrammarModuleElementContext(node, errorMessage) {
  20307. if (node.parent.kind !== 246 && node.parent.kind !== 217 && node.parent.kind !== 216) {
  20308. return grammarErrorOnFirstToken(node, errorMessage);
  20309. }
  20310. }
  20311. function checkExportSpecifier(node) {
  20312. checkAliasSymbol(node);
  20313. if (!node.parent.parent.moduleSpecifier) {
  20314. markExportAsReferenced(node);
  20315. }
  20316. }
  20317. function checkExportAssignment(node) {
  20318. if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) {
  20319. return;
  20320. }
  20321. var container = node.parent.kind === 246 ? node.parent : node.parent.parent;
  20322. if (container.kind === 216 && container.name.kind === 67) {
  20323. error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
  20324. return;
  20325. }
  20326. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) {
  20327. grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
  20328. }
  20329. if (node.expression.kind === 67) {
  20330. markExportAsReferenced(node);
  20331. }
  20332. else {
  20333. checkExpressionCached(node.expression);
  20334. }
  20335. checkExternalModuleExports(container);
  20336. if (node.isExportEquals && !ts.isInAmbientContext(node)) {
  20337. if (languageVersion >= 2) {
  20338. grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
  20339. }
  20340. else if (compilerOptions.module === 4) {
  20341. grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
  20342. }
  20343. }
  20344. }
  20345. function getModuleStatements(node) {
  20346. if (node.kind === 246) {
  20347. return node.statements;
  20348. }
  20349. if (node.kind === 216 && node.body.kind === 217) {
  20350. return node.body.statements;
  20351. }
  20352. return emptyArray;
  20353. }
  20354. function hasExportedMembers(moduleSymbol) {
  20355. for (var id in moduleSymbol.exports) {
  20356. if (id !== "export=") {
  20357. return true;
  20358. }
  20359. }
  20360. return false;
  20361. }
  20362. function checkExternalModuleExports(node) {
  20363. var moduleSymbol = getSymbolOfNode(node);
  20364. var links = getSymbolLinks(moduleSymbol);
  20365. if (!links.exportsChecked) {
  20366. var exportEqualsSymbol = moduleSymbol.exports["export="];
  20367. if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) {
  20368. var declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration;
  20369. error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
  20370. }
  20371. links.exportsChecked = true;
  20372. }
  20373. }
  20374. function checkTypePredicate(node) {
  20375. if (!isInLegalTypePredicatePosition(node)) {
  20376. error(node, ts.Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
  20377. }
  20378. }
  20379. function checkSourceElement(node) {
  20380. if (!node) {
  20381. return;
  20382. }
  20383. var kind = node.kind;
  20384. if (cancellationToken) {
  20385. switch (kind) {
  20386. case 216:
  20387. case 212:
  20388. case 213:
  20389. case 211:
  20390. cancellationToken.throwIfCancellationRequested();
  20391. }
  20392. }
  20393. switch (kind) {
  20394. case 135:
  20395. return checkTypeParameter(node);
  20396. case 136:
  20397. return checkParameter(node);
  20398. case 139:
  20399. case 138:
  20400. return checkPropertyDeclaration(node);
  20401. case 150:
  20402. case 151:
  20403. case 145:
  20404. case 146:
  20405. return checkSignatureDeclaration(node);
  20406. case 147:
  20407. return checkSignatureDeclaration(node);
  20408. case 141:
  20409. case 140:
  20410. return checkMethodDeclaration(node);
  20411. case 142:
  20412. return checkConstructorDeclaration(node);
  20413. case 143:
  20414. case 144:
  20415. return checkAccessorDeclaration(node);
  20416. case 149:
  20417. return checkTypeReferenceNode(node);
  20418. case 148:
  20419. return checkTypePredicate(node);
  20420. case 152:
  20421. return checkTypeQuery(node);
  20422. case 153:
  20423. return checkTypeLiteral(node);
  20424. case 154:
  20425. return checkArrayType(node);
  20426. case 155:
  20427. return checkTupleType(node);
  20428. case 156:
  20429. case 157:
  20430. return checkUnionOrIntersectionType(node);
  20431. case 158:
  20432. return checkSourceElement(node.type);
  20433. case 211:
  20434. return checkFunctionDeclaration(node);
  20435. case 190:
  20436. case 217:
  20437. return checkBlock(node);
  20438. case 191:
  20439. return checkVariableStatement(node);
  20440. case 193:
  20441. return checkExpressionStatement(node);
  20442. case 194:
  20443. return checkIfStatement(node);
  20444. case 195:
  20445. return checkDoStatement(node);
  20446. case 196:
  20447. return checkWhileStatement(node);
  20448. case 197:
  20449. return checkForStatement(node);
  20450. case 198:
  20451. return checkForInStatement(node);
  20452. case 199:
  20453. return checkForOfStatement(node);
  20454. case 200:
  20455. case 201:
  20456. return checkBreakOrContinueStatement(node);
  20457. case 202:
  20458. return checkReturnStatement(node);
  20459. case 203:
  20460. return checkWithStatement(node);
  20461. case 204:
  20462. return checkSwitchStatement(node);
  20463. case 205:
  20464. return checkLabeledStatement(node);
  20465. case 206:
  20466. return checkThrowStatement(node);
  20467. case 207:
  20468. return checkTryStatement(node);
  20469. case 209:
  20470. return checkVariableDeclaration(node);
  20471. case 161:
  20472. return checkBindingElement(node);
  20473. case 212:
  20474. return checkClassDeclaration(node);
  20475. case 213:
  20476. return checkInterfaceDeclaration(node);
  20477. case 214:
  20478. return checkTypeAliasDeclaration(node);
  20479. case 215:
  20480. return checkEnumDeclaration(node);
  20481. case 216:
  20482. return checkModuleDeclaration(node);
  20483. case 220:
  20484. return checkImportDeclaration(node);
  20485. case 219:
  20486. return checkImportEqualsDeclaration(node);
  20487. case 226:
  20488. return checkExportDeclaration(node);
  20489. case 225:
  20490. return checkExportAssignment(node);
  20491. case 192:
  20492. checkGrammarStatementInAmbientContext(node);
  20493. return;
  20494. case 208:
  20495. checkGrammarStatementInAmbientContext(node);
  20496. return;
  20497. case 229:
  20498. return checkMissingDeclaration(node);
  20499. }
  20500. }
  20501. function checkFunctionAndClassExpressionBodies(node) {
  20502. switch (node.kind) {
  20503. case 171:
  20504. case 172:
  20505. ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
  20506. checkFunctionExpressionOrObjectLiteralMethodBody(node);
  20507. break;
  20508. case 184:
  20509. ts.forEach(node.members, checkSourceElement);
  20510. break;
  20511. case 141:
  20512. case 140:
  20513. ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies);
  20514. ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
  20515. if (ts.isObjectLiteralMethod(node)) {
  20516. checkFunctionExpressionOrObjectLiteralMethodBody(node);
  20517. }
  20518. break;
  20519. case 142:
  20520. case 143:
  20521. case 144:
  20522. case 211:
  20523. ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
  20524. break;
  20525. case 203:
  20526. checkFunctionAndClassExpressionBodies(node.expression);
  20527. break;
  20528. case 137:
  20529. case 136:
  20530. case 139:
  20531. case 138:
  20532. case 159:
  20533. case 160:
  20534. case 161:
  20535. case 162:
  20536. case 163:
  20537. case 243:
  20538. case 164:
  20539. case 165:
  20540. case 166:
  20541. case 167:
  20542. case 168:
  20543. case 181:
  20544. case 188:
  20545. case 169:
  20546. case 187:
  20547. case 170:
  20548. case 174:
  20549. case 175:
  20550. case 176:
  20551. case 173:
  20552. case 177:
  20553. case 178:
  20554. case 179:
  20555. case 180:
  20556. case 183:
  20557. case 182:
  20558. case 190:
  20559. case 217:
  20560. case 191:
  20561. case 193:
  20562. case 194:
  20563. case 195:
  20564. case 196:
  20565. case 197:
  20566. case 198:
  20567. case 199:
  20568. case 200:
  20569. case 201:
  20570. case 202:
  20571. case 204:
  20572. case 218:
  20573. case 239:
  20574. case 240:
  20575. case 205:
  20576. case 206:
  20577. case 207:
  20578. case 242:
  20579. case 209:
  20580. case 210:
  20581. case 212:
  20582. case 241:
  20583. case 186:
  20584. case 215:
  20585. case 245:
  20586. case 225:
  20587. case 246:
  20588. case 238:
  20589. case 231:
  20590. case 232:
  20591. case 236:
  20592. case 237:
  20593. case 233:
  20594. ts.forEachChild(node, checkFunctionAndClassExpressionBodies);
  20595. break;
  20596. }
  20597. }
  20598. function checkSourceFile(node) {
  20599. var start = new Date().getTime();
  20600. checkSourceFileWorker(node);
  20601. ts.checkTime += new Date().getTime() - start;
  20602. }
  20603. function checkSourceFileWorker(node) {
  20604. var links = getNodeLinks(node);
  20605. if (!(links.flags & 1)) {
  20606. if (node.isDefaultLib && compilerOptions.skipDefaultLibCheck) {
  20607. return;
  20608. }
  20609. checkGrammarSourceFile(node);
  20610. emitExtends = false;
  20611. emitDecorate = false;
  20612. emitParam = false;
  20613. potentialThisCollisions.length = 0;
  20614. ts.forEach(node.statements, checkSourceElement);
  20615. checkFunctionAndClassExpressionBodies(node);
  20616. if (ts.isExternalModule(node)) {
  20617. checkExternalModuleExports(node);
  20618. }
  20619. if (potentialThisCollisions.length) {
  20620. ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope);
  20621. potentialThisCollisions.length = 0;
  20622. }
  20623. if (emitExtends) {
  20624. links.flags |= 8;
  20625. }
  20626. if (emitDecorate) {
  20627. links.flags |= 16;
  20628. }
  20629. if (emitParam) {
  20630. links.flags |= 32;
  20631. }
  20632. if (emitAwaiter) {
  20633. links.flags |= 64;
  20634. }
  20635. if (emitGenerator || (emitAwaiter && languageVersion < 2)) {
  20636. links.flags |= 128;
  20637. }
  20638. links.flags |= 1;
  20639. }
  20640. }
  20641. function getDiagnostics(sourceFile, ct) {
  20642. try {
  20643. cancellationToken = ct;
  20644. return getDiagnosticsWorker(sourceFile);
  20645. }
  20646. finally {
  20647. cancellationToken = undefined;
  20648. }
  20649. }
  20650. function getDiagnosticsWorker(sourceFile) {
  20651. throwIfNonDiagnosticsProducing();
  20652. if (sourceFile) {
  20653. checkSourceFile(sourceFile);
  20654. return diagnostics.getDiagnostics(sourceFile.fileName);
  20655. }
  20656. ts.forEach(host.getSourceFiles(), checkSourceFile);
  20657. return diagnostics.getDiagnostics();
  20658. }
  20659. function getGlobalDiagnostics() {
  20660. throwIfNonDiagnosticsProducing();
  20661. return diagnostics.getGlobalDiagnostics();
  20662. }
  20663. function throwIfNonDiagnosticsProducing() {
  20664. if (!produceDiagnostics) {
  20665. throw new Error("Trying to get diagnostics from a type checker that does not produce them.");
  20666. }
  20667. }
  20668. function isInsideWithStatementBody(node) {
  20669. if (node) {
  20670. while (node.parent) {
  20671. if (node.parent.kind === 203 && node.parent.statement === node) {
  20672. return true;
  20673. }
  20674. node = node.parent;
  20675. }
  20676. }
  20677. return false;
  20678. }
  20679. function getSymbolsInScope(location, meaning) {
  20680. var symbols = {};
  20681. var memberFlags = 0;
  20682. if (isInsideWithStatementBody(location)) {
  20683. return [];
  20684. }
  20685. populateSymbols();
  20686. return symbolsToArray(symbols);
  20687. function populateSymbols() {
  20688. while (location) {
  20689. if (location.locals && !isGlobalSourceFile(location)) {
  20690. copySymbols(location.locals, meaning);
  20691. }
  20692. switch (location.kind) {
  20693. case 246:
  20694. if (!ts.isExternalModule(location)) {
  20695. break;
  20696. }
  20697. case 216:
  20698. copySymbols(getSymbolOfNode(location).exports, meaning & 8914931);
  20699. break;
  20700. case 215:
  20701. copySymbols(getSymbolOfNode(location).exports, meaning & 8);
  20702. break;
  20703. case 184:
  20704. var className = location.name;
  20705. if (className) {
  20706. copySymbol(location.symbol, meaning);
  20707. }
  20708. case 212:
  20709. case 213:
  20710. if (!(memberFlags & 128)) {
  20711. copySymbols(getSymbolOfNode(location).members, meaning & 793056);
  20712. }
  20713. break;
  20714. case 171:
  20715. var funcName = location.name;
  20716. if (funcName) {
  20717. copySymbol(location.symbol, meaning);
  20718. }
  20719. break;
  20720. }
  20721. if (ts.introducesArgumentsExoticObject(location)) {
  20722. copySymbol(argumentsSymbol, meaning);
  20723. }
  20724. memberFlags = location.flags;
  20725. location = location.parent;
  20726. }
  20727. copySymbols(globals, meaning);
  20728. }
  20729. function copySymbol(symbol, meaning) {
  20730. if (symbol.flags & meaning) {
  20731. var id = symbol.name;
  20732. if (!ts.hasProperty(symbols, id)) {
  20733. symbols[id] = symbol;
  20734. }
  20735. }
  20736. }
  20737. function copySymbols(source, meaning) {
  20738. if (meaning) {
  20739. for (var id in source) {
  20740. var symbol = source[id];
  20741. copySymbol(symbol, meaning);
  20742. }
  20743. }
  20744. }
  20745. }
  20746. function isTypeDeclarationName(name) {
  20747. return name.kind === 67 &&
  20748. isTypeDeclaration(name.parent) &&
  20749. name.parent.name === name;
  20750. }
  20751. function isTypeDeclaration(node) {
  20752. switch (node.kind) {
  20753. case 135:
  20754. case 212:
  20755. case 213:
  20756. case 214:
  20757. case 215:
  20758. return true;
  20759. }
  20760. }
  20761. function isTypeReferenceIdentifier(entityName) {
  20762. var node = entityName;
  20763. while (node.parent && node.parent.kind === 133) {
  20764. node = node.parent;
  20765. }
  20766. return node.parent && node.parent.kind === 149;
  20767. }
  20768. function isHeritageClauseElementIdentifier(entityName) {
  20769. var node = entityName;
  20770. while (node.parent && node.parent.kind === 164) {
  20771. node = node.parent;
  20772. }
  20773. return node.parent && node.parent.kind === 186;
  20774. }
  20775. function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) {
  20776. while (nodeOnRightSide.parent.kind === 133) {
  20777. nodeOnRightSide = nodeOnRightSide.parent;
  20778. }
  20779. if (nodeOnRightSide.parent.kind === 219) {
  20780. return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent;
  20781. }
  20782. if (nodeOnRightSide.parent.kind === 225) {
  20783. return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent;
  20784. }
  20785. return undefined;
  20786. }
  20787. function isInRightSideOfImportOrExportAssignment(node) {
  20788. return getLeftSideOfImportEqualsOrExportAssignment(node) !== undefined;
  20789. }
  20790. function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) {
  20791. if (ts.isDeclarationName(entityName)) {
  20792. return getSymbolOfNode(entityName.parent);
  20793. }
  20794. if (entityName.parent.kind === 225) {
  20795. return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608);
  20796. }
  20797. if (entityName.kind !== 164) {
  20798. if (isInRightSideOfImportOrExportAssignment(entityName)) {
  20799. return getSymbolOfPartOfRightHandSideOfImportEquals(entityName);
  20800. }
  20801. }
  20802. if (ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
  20803. entityName = entityName.parent;
  20804. }
  20805. if (isHeritageClauseElementIdentifier(entityName)) {
  20806. var meaning = entityName.parent.kind === 186 ? 793056 : 1536;
  20807. meaning |= 8388608;
  20808. return resolveEntityName(entityName, meaning);
  20809. }
  20810. else if ((entityName.parent.kind === 233) ||
  20811. (entityName.parent.kind === 232) ||
  20812. (entityName.parent.kind === 235)) {
  20813. return getJsxElementTagSymbol(entityName.parent);
  20814. }
  20815. else if (ts.isExpression(entityName)) {
  20816. if (ts.nodeIsMissing(entityName)) {
  20817. return undefined;
  20818. }
  20819. if (entityName.kind === 67) {
  20820. var meaning = 107455 | 8388608;
  20821. return resolveEntityName(entityName, meaning);
  20822. }
  20823. else if (entityName.kind === 164) {
  20824. var symbol = getNodeLinks(entityName).resolvedSymbol;
  20825. if (!symbol) {
  20826. checkPropertyAccessExpression(entityName);
  20827. }
  20828. return getNodeLinks(entityName).resolvedSymbol;
  20829. }
  20830. else if (entityName.kind === 133) {
  20831. var symbol = getNodeLinks(entityName).resolvedSymbol;
  20832. if (!symbol) {
  20833. checkQualifiedName(entityName);
  20834. }
  20835. return getNodeLinks(entityName).resolvedSymbol;
  20836. }
  20837. }
  20838. else if (isTypeReferenceIdentifier(entityName)) {
  20839. var meaning = entityName.parent.kind === 149 ? 793056 : 1536;
  20840. meaning |= 8388608;
  20841. return resolveEntityName(entityName, meaning);
  20842. }
  20843. else if (entityName.parent.kind === 236) {
  20844. return getJsxAttributePropertySymbol(entityName.parent);
  20845. }
  20846. if (entityName.parent.kind === 148) {
  20847. return resolveEntityName(entityName, 1);
  20848. }
  20849. return undefined;
  20850. }
  20851. function getSymbolAtLocation(node) {
  20852. if (isInsideWithStatementBody(node)) {
  20853. return undefined;
  20854. }
  20855. if (ts.isDeclarationName(node)) {
  20856. return getSymbolOfNode(node.parent);
  20857. }
  20858. if (node.kind === 67) {
  20859. if (isInRightSideOfImportOrExportAssignment(node)) {
  20860. return node.parent.kind === 225
  20861. ? getSymbolOfEntityNameOrPropertyAccessExpression(node)
  20862. : getSymbolOfPartOfRightHandSideOfImportEquals(node);
  20863. }
  20864. else if (node.parent.kind === 161 &&
  20865. node.parent.parent.kind === 159 &&
  20866. node === node.parent.propertyName) {
  20867. var typeOfPattern = getTypeOfNode(node.parent.parent);
  20868. var propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, node.text);
  20869. if (propertyDeclaration) {
  20870. return propertyDeclaration;
  20871. }
  20872. }
  20873. }
  20874. switch (node.kind) {
  20875. case 67:
  20876. case 164:
  20877. case 133:
  20878. return getSymbolOfEntityNameOrPropertyAccessExpression(node);
  20879. case 95:
  20880. case 93:
  20881. var type = checkExpression(node);
  20882. return type.symbol;
  20883. case 119:
  20884. var constructorDeclaration = node.parent;
  20885. if (constructorDeclaration && constructorDeclaration.kind === 142) {
  20886. return constructorDeclaration.parent.symbol;
  20887. }
  20888. return undefined;
  20889. case 9:
  20890. if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
  20891. ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
  20892. ((node.parent.kind === 220 || node.parent.kind === 226) &&
  20893. node.parent.moduleSpecifier === node)) {
  20894. return resolveExternalModuleName(node, node);
  20895. }
  20896. case 8:
  20897. if (node.parent.kind === 165 && node.parent.argumentExpression === node) {
  20898. var objectType = checkExpression(node.parent.expression);
  20899. if (objectType === unknownType)
  20900. return undefined;
  20901. var apparentType = getApparentType(objectType);
  20902. if (apparentType === unknownType)
  20903. return undefined;
  20904. return getPropertyOfType(apparentType, node.text);
  20905. }
  20906. break;
  20907. }
  20908. return undefined;
  20909. }
  20910. function getShorthandAssignmentValueSymbol(location) {
  20911. if (location && location.kind === 244) {
  20912. return resolveEntityName(location.name, 107455);
  20913. }
  20914. return undefined;
  20915. }
  20916. function getTypeOfNode(node) {
  20917. if (isInsideWithStatementBody(node)) {
  20918. return unknownType;
  20919. }
  20920. if (ts.isTypeNode(node)) {
  20921. return getTypeFromTypeNode(node);
  20922. }
  20923. if (ts.isExpression(node)) {
  20924. return getTypeOfExpression(node);
  20925. }
  20926. if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(node)) {
  20927. return getBaseTypes(getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0];
  20928. }
  20929. if (isTypeDeclaration(node)) {
  20930. var symbol = getSymbolOfNode(node);
  20931. return getDeclaredTypeOfSymbol(symbol);
  20932. }
  20933. if (isTypeDeclarationName(node)) {
  20934. var symbol = getSymbolAtLocation(node);
  20935. return symbol && getDeclaredTypeOfSymbol(symbol);
  20936. }
  20937. if (ts.isDeclaration(node)) {
  20938. var symbol = getSymbolOfNode(node);
  20939. return getTypeOfSymbol(symbol);
  20940. }
  20941. if (ts.isDeclarationName(node)) {
  20942. var symbol = getSymbolAtLocation(node);
  20943. return symbol && getTypeOfSymbol(symbol);
  20944. }
  20945. if (ts.isBindingPattern(node)) {
  20946. return getTypeForVariableLikeDeclaration(node.parent);
  20947. }
  20948. if (isInRightSideOfImportOrExportAssignment(node)) {
  20949. var symbol = getSymbolAtLocation(node);
  20950. var declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
  20951. return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
  20952. }
  20953. return unknownType;
  20954. }
  20955. function getTypeOfExpression(expr) {
  20956. if (ts.isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
  20957. expr = expr.parent;
  20958. }
  20959. return checkExpression(expr);
  20960. }
  20961. function getParentTypeOfClassElement(node) {
  20962. var classSymbol = getSymbolOfNode(node.parent);
  20963. return node.flags & 128
  20964. ? getTypeOfSymbol(classSymbol)
  20965. : getDeclaredTypeOfSymbol(classSymbol);
  20966. }
  20967. function getAugmentedPropertiesOfType(type) {
  20968. type = getApparentType(type);
  20969. var propsByName = createSymbolTable(getPropertiesOfType(type));
  20970. if (getSignaturesOfType(type, 0).length || getSignaturesOfType(type, 1).length) {
  20971. ts.forEach(getPropertiesOfType(globalFunctionType), function (p) {
  20972. if (!ts.hasProperty(propsByName, p.name)) {
  20973. propsByName[p.name] = p;
  20974. }
  20975. });
  20976. }
  20977. return getNamedMembers(propsByName);
  20978. }
  20979. function getRootSymbols(symbol) {
  20980. if (symbol.flags & 268435456) {
  20981. var symbols = [];
  20982. var name_15 = symbol.name;
  20983. ts.forEach(getSymbolLinks(symbol).containingType.types, function (t) {
  20984. var symbol = getPropertyOfType(t, name_15);
  20985. if (symbol) {
  20986. symbols.push(symbol);
  20987. }
  20988. });
  20989. return symbols;
  20990. }
  20991. else if (symbol.flags & 67108864) {
  20992. var target = getSymbolLinks(symbol).target;
  20993. if (target) {
  20994. return [target];
  20995. }
  20996. }
  20997. return [symbol];
  20998. }
  20999. function getReferencedExportContainer(node) {
  21000. var symbol = getReferencedValueSymbol(node);
  21001. if (symbol) {
  21002. if (symbol.flags & 1048576) {
  21003. var exportSymbol = getMergedSymbol(symbol.exportSymbol);
  21004. if (exportSymbol.flags & 944) {
  21005. return undefined;
  21006. }
  21007. symbol = exportSymbol;
  21008. }
  21009. var parentSymbol = getParentOfSymbol(symbol);
  21010. if (parentSymbol) {
  21011. if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 246) {
  21012. return parentSymbol.valueDeclaration;
  21013. }
  21014. for (var n = node.parent; n; n = n.parent) {
  21015. if ((n.kind === 216 || n.kind === 215) && getSymbolOfNode(n) === parentSymbol) {
  21016. return n;
  21017. }
  21018. }
  21019. }
  21020. }
  21021. }
  21022. function getReferencedImportDeclaration(node) {
  21023. var symbol = getReferencedValueSymbol(node);
  21024. return symbol && symbol.flags & 8388608 ? getDeclarationOfAliasSymbol(symbol) : undefined;
  21025. }
  21026. function isStatementWithLocals(node) {
  21027. switch (node.kind) {
  21028. case 190:
  21029. case 218:
  21030. case 197:
  21031. case 198:
  21032. case 199:
  21033. return true;
  21034. }
  21035. return false;
  21036. }
  21037. function isNestedRedeclarationSymbol(symbol) {
  21038. if (symbol.flags & 418) {
  21039. var links = getSymbolLinks(symbol);
  21040. if (links.isNestedRedeclaration === undefined) {
  21041. var container = ts.getEnclosingBlockScopeContainer(symbol.valueDeclaration);
  21042. links.isNestedRedeclaration = isStatementWithLocals(container) &&
  21043. !!resolveName(container.parent, symbol.name, 107455, undefined, undefined);
  21044. }
  21045. return links.isNestedRedeclaration;
  21046. }
  21047. return false;
  21048. }
  21049. function getReferencedNestedRedeclaration(node) {
  21050. var symbol = getReferencedValueSymbol(node);
  21051. return symbol && isNestedRedeclarationSymbol(symbol) ? symbol.valueDeclaration : undefined;
  21052. }
  21053. function isNestedRedeclaration(node) {
  21054. return isNestedRedeclarationSymbol(getSymbolOfNode(node));
  21055. }
  21056. function isValueAliasDeclaration(node) {
  21057. switch (node.kind) {
  21058. case 219:
  21059. case 221:
  21060. case 222:
  21061. case 224:
  21062. case 228:
  21063. return isAliasResolvedToValue(getSymbolOfNode(node));
  21064. case 226:
  21065. var exportClause = node.exportClause;
  21066. return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration);
  21067. case 225:
  21068. return node.expression && node.expression.kind === 67 ? isAliasResolvedToValue(getSymbolOfNode(node)) : true;
  21069. }
  21070. return false;
  21071. }
  21072. function isTopLevelValueImportEqualsWithEntityName(node) {
  21073. if (node.parent.kind !== 246 || !ts.isInternalModuleImportEqualsDeclaration(node)) {
  21074. return false;
  21075. }
  21076. var isValue = isAliasResolvedToValue(getSymbolOfNode(node));
  21077. return isValue && node.moduleReference && !ts.nodeIsMissing(node.moduleReference);
  21078. }
  21079. function isAliasResolvedToValue(symbol) {
  21080. var target = resolveAlias(symbol);
  21081. if (target === unknownSymbol && compilerOptions.isolatedModules) {
  21082. return true;
  21083. }
  21084. return target !== unknownSymbol &&
  21085. target &&
  21086. target.flags & 107455 &&
  21087. (compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
  21088. }
  21089. function isConstEnumOrConstEnumOnlyModule(s) {
  21090. return isConstEnumSymbol(s) || s.constEnumOnlyModule;
  21091. }
  21092. function isReferencedAliasDeclaration(node, checkChildren) {
  21093. if (ts.isAliasSymbolDeclaration(node)) {
  21094. var symbol = getSymbolOfNode(node);
  21095. if (getSymbolLinks(symbol).referenced) {
  21096. return true;
  21097. }
  21098. }
  21099. if (checkChildren) {
  21100. return ts.forEachChild(node, function (node) { return isReferencedAliasDeclaration(node, checkChildren); });
  21101. }
  21102. return false;
  21103. }
  21104. function isImplementationOfOverload(node) {
  21105. if (ts.nodeIsPresent(node.body)) {
  21106. var symbol = getSymbolOfNode(node);
  21107. var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
  21108. return signaturesOfSymbol.length > 1 ||
  21109. (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
  21110. }
  21111. return false;
  21112. }
  21113. function getNodeCheckFlags(node) {
  21114. return getNodeLinks(node).flags;
  21115. }
  21116. function getEnumMemberValue(node) {
  21117. computeEnumMemberValues(node.parent);
  21118. return getNodeLinks(node).enumMemberValue;
  21119. }
  21120. function getConstantValue(node) {
  21121. if (node.kind === 245) {
  21122. return getEnumMemberValue(node);
  21123. }
  21124. var symbol = getNodeLinks(node).resolvedSymbol;
  21125. if (symbol && (symbol.flags & 8)) {
  21126. if (ts.isConstEnumDeclaration(symbol.valueDeclaration.parent)) {
  21127. return getEnumMemberValue(symbol.valueDeclaration);
  21128. }
  21129. }
  21130. return undefined;
  21131. }
  21132. function isFunctionType(type) {
  21133. return type.flags & 80896 && getSignaturesOfType(type, 0).length > 0;
  21134. }
  21135. function getTypeReferenceSerializationKind(typeName) {
  21136. var valueSymbol = resolveEntityName(typeName, 107455, true);
  21137. var constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
  21138. if (constructorType && isConstructorType(constructorType)) {
  21139. return ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
  21140. }
  21141. var typeSymbol = resolveEntityName(typeName, 793056, true);
  21142. if (!typeSymbol) {
  21143. return ts.TypeReferenceSerializationKind.ObjectType;
  21144. }
  21145. var type = getDeclaredTypeOfSymbol(typeSymbol);
  21146. if (type === unknownType) {
  21147. return ts.TypeReferenceSerializationKind.Unknown;
  21148. }
  21149. else if (type.flags & 1) {
  21150. return ts.TypeReferenceSerializationKind.ObjectType;
  21151. }
  21152. else if (allConstituentTypesHaveKind(type, 16)) {
  21153. return ts.TypeReferenceSerializationKind.VoidType;
  21154. }
  21155. else if (allConstituentTypesHaveKind(type, 8)) {
  21156. return ts.TypeReferenceSerializationKind.BooleanType;
  21157. }
  21158. else if (allConstituentTypesHaveKind(type, 132)) {
  21159. return ts.TypeReferenceSerializationKind.NumberLikeType;
  21160. }
  21161. else if (allConstituentTypesHaveKind(type, 258)) {
  21162. return ts.TypeReferenceSerializationKind.StringLikeType;
  21163. }
  21164. else if (allConstituentTypesHaveKind(type, 8192)) {
  21165. return ts.TypeReferenceSerializationKind.ArrayLikeType;
  21166. }
  21167. else if (allConstituentTypesHaveKind(type, 16777216)) {
  21168. return ts.TypeReferenceSerializationKind.ESSymbolType;
  21169. }
  21170. else if (isFunctionType(type)) {
  21171. return ts.TypeReferenceSerializationKind.TypeWithCallSignature;
  21172. }
  21173. else if (isArrayType(type)) {
  21174. return ts.TypeReferenceSerializationKind.ArrayLikeType;
  21175. }
  21176. else {
  21177. return ts.TypeReferenceSerializationKind.ObjectType;
  21178. }
  21179. }
  21180. function writeTypeOfDeclaration(declaration, enclosingDeclaration, flags, writer) {
  21181. var symbol = getSymbolOfNode(declaration);
  21182. var type = symbol && !(symbol.flags & (2048 | 131072))
  21183. ? getTypeOfSymbol(symbol)
  21184. : unknownType;
  21185. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  21186. }
  21187. function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) {
  21188. var signature = getSignatureFromDeclaration(signatureDeclaration);
  21189. getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
  21190. }
  21191. function writeTypeOfExpression(expr, enclosingDeclaration, flags, writer) {
  21192. var type = getTypeOfExpression(expr);
  21193. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  21194. }
  21195. function hasGlobalName(name) {
  21196. return ts.hasProperty(globals, name);
  21197. }
  21198. function getReferencedValueSymbol(reference) {
  21199. return getNodeLinks(reference).resolvedSymbol ||
  21200. resolveName(reference, reference.text, 107455 | 1048576 | 8388608, undefined, undefined);
  21201. }
  21202. function getReferencedValueDeclaration(reference) {
  21203. ts.Debug.assert(!ts.nodeIsSynthesized(reference));
  21204. var symbol = getReferencedValueSymbol(reference);
  21205. return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
  21206. }
  21207. function getBlockScopedVariableId(n) {
  21208. ts.Debug.assert(!ts.nodeIsSynthesized(n));
  21209. var isVariableDeclarationOrBindingElement = n.parent.kind === 161 || (n.parent.kind === 209 && n.parent.name === n);
  21210. var symbol = (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) ||
  21211. getNodeLinks(n).resolvedSymbol ||
  21212. resolveName(n, n.text, 107455 | 8388608, undefined, undefined);
  21213. var isLetOrConst = symbol &&
  21214. (symbol.flags & 2) &&
  21215. symbol.valueDeclaration.parent.kind !== 242;
  21216. if (isLetOrConst) {
  21217. getSymbolLinks(symbol);
  21218. return symbol.id;
  21219. }
  21220. return undefined;
  21221. }
  21222. function instantiateSingleCallFunctionType(functionType, typeArguments) {
  21223. if (functionType === unknownType) {
  21224. return unknownType;
  21225. }
  21226. var signature = getSingleCallSignature(functionType);
  21227. if (!signature) {
  21228. return unknownType;
  21229. }
  21230. var instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
  21231. return getOrCreateTypeFromSignature(instantiatedSignature);
  21232. }
  21233. function createResolver() {
  21234. return {
  21235. getReferencedExportContainer: getReferencedExportContainer,
  21236. getReferencedImportDeclaration: getReferencedImportDeclaration,
  21237. getReferencedNestedRedeclaration: getReferencedNestedRedeclaration,
  21238. isNestedRedeclaration: isNestedRedeclaration,
  21239. isValueAliasDeclaration: isValueAliasDeclaration,
  21240. hasGlobalName: hasGlobalName,
  21241. isReferencedAliasDeclaration: isReferencedAliasDeclaration,
  21242. getNodeCheckFlags: getNodeCheckFlags,
  21243. isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName,
  21244. isDeclarationVisible: isDeclarationVisible,
  21245. isImplementationOfOverload: isImplementationOfOverload,
  21246. writeTypeOfDeclaration: writeTypeOfDeclaration,
  21247. writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration,
  21248. writeTypeOfExpression: writeTypeOfExpression,
  21249. isSymbolAccessible: isSymbolAccessible,
  21250. isEntityNameVisible: isEntityNameVisible,
  21251. getConstantValue: getConstantValue,
  21252. collectLinkedAliases: collectLinkedAliases,
  21253. getBlockScopedVariableId: getBlockScopedVariableId,
  21254. getReferencedValueDeclaration: getReferencedValueDeclaration,
  21255. getTypeReferenceSerializationKind: getTypeReferenceSerializationKind,
  21256. isOptionalParameter: isOptionalParameter
  21257. };
  21258. }
  21259. function initializeTypeChecker() {
  21260. ts.forEach(host.getSourceFiles(), function (file) {
  21261. ts.bindSourceFile(file);
  21262. });
  21263. ts.forEach(host.getSourceFiles(), function (file) {
  21264. if (!ts.isExternalModule(file)) {
  21265. mergeSymbolTable(globals, file.locals);
  21266. }
  21267. });
  21268. getSymbolLinks(undefinedSymbol).type = undefinedType;
  21269. getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
  21270. getSymbolLinks(unknownSymbol).type = unknownType;
  21271. globals[undefinedSymbol.name] = undefinedSymbol;
  21272. globalArrayType = getGlobalType("Array", 1);
  21273. globalObjectType = getGlobalType("Object");
  21274. globalFunctionType = getGlobalType("Function");
  21275. globalStringType = getGlobalType("String");
  21276. globalNumberType = getGlobalType("Number");
  21277. globalBooleanType = getGlobalType("Boolean");
  21278. globalRegExpType = getGlobalType("RegExp");
  21279. jsxElementType = getExportedTypeFromNamespace("JSX", JsxNames.Element);
  21280. getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); });
  21281. getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); });
  21282. getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); });
  21283. getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); });
  21284. getGlobalTypedPropertyDescriptorType = ts.memoize(function () { return getGlobalType("TypedPropertyDescriptor", 1); });
  21285. getGlobalPromiseType = ts.memoize(function () { return getGlobalType("Promise", 1); });
  21286. tryGetGlobalPromiseType = ts.memoize(function () { return getGlobalSymbol("Promise", 793056, undefined) && getGlobalPromiseType(); });
  21287. getGlobalPromiseLikeType = ts.memoize(function () { return getGlobalType("PromiseLike", 1); });
  21288. getInstantiatedGlobalPromiseLikeType = ts.memoize(createInstantiatedPromiseLikeType);
  21289. getGlobalPromiseConstructorSymbol = ts.memoize(function () { return getGlobalValueSymbol("Promise"); });
  21290. getGlobalPromiseConstructorLikeType = ts.memoize(function () { return getGlobalType("PromiseConstructorLike"); });
  21291. getGlobalThenableType = ts.memoize(createThenableType);
  21292. if (languageVersion >= 2) {
  21293. globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray");
  21294. globalESSymbolType = getGlobalType("Symbol");
  21295. globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol");
  21296. globalIterableType = getGlobalType("Iterable", 1);
  21297. globalIteratorType = getGlobalType("Iterator", 1);
  21298. globalIterableIteratorType = getGlobalType("IterableIterator", 1);
  21299. }
  21300. else {
  21301. globalTemplateStringsArrayType = unknownType;
  21302. globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  21303. globalESSymbolConstructorSymbol = undefined;
  21304. globalIterableType = emptyGenericType;
  21305. globalIteratorType = emptyGenericType;
  21306. globalIterableIteratorType = emptyGenericType;
  21307. }
  21308. anyArrayType = createArrayType(anyType);
  21309. }
  21310. function createInstantiatedPromiseLikeType() {
  21311. var promiseLikeType = getGlobalPromiseLikeType();
  21312. if (promiseLikeType !== emptyGenericType) {
  21313. return createTypeReference(promiseLikeType, [anyType]);
  21314. }
  21315. return emptyObjectType;
  21316. }
  21317. function createThenableType() {
  21318. var thenPropertySymbol = createSymbol(67108864 | 4, "then");
  21319. getSymbolLinks(thenPropertySymbol).type = globalFunctionType;
  21320. var thenableType = createObjectType(65536);
  21321. thenableType.properties = [thenPropertySymbol];
  21322. thenableType.members = createSymbolTable(thenableType.properties);
  21323. thenableType.callSignatures = [];
  21324. thenableType.constructSignatures = [];
  21325. return thenableType;
  21326. }
  21327. function checkGrammarDecorators(node) {
  21328. if (!node.decorators) {
  21329. return false;
  21330. }
  21331. if (!ts.nodeCanBeDecorated(node)) {
  21332. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here);
  21333. }
  21334. else if (languageVersion < 1) {
  21335. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher);
  21336. }
  21337. else if (node.kind === 143 || node.kind === 144) {
  21338. var accessors = ts.getAllAccessorDeclarations(node.parent.members, node);
  21339. if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) {
  21340. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name);
  21341. }
  21342. }
  21343. return false;
  21344. }
  21345. function checkGrammarModifiers(node) {
  21346. switch (node.kind) {
  21347. case 143:
  21348. case 144:
  21349. case 142:
  21350. case 139:
  21351. case 138:
  21352. case 141:
  21353. case 140:
  21354. case 147:
  21355. case 216:
  21356. case 220:
  21357. case 219:
  21358. case 226:
  21359. case 225:
  21360. case 136:
  21361. break;
  21362. case 211:
  21363. if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 116) &&
  21364. node.parent.kind !== 217 && node.parent.kind !== 246) {
  21365. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  21366. }
  21367. break;
  21368. case 212:
  21369. case 213:
  21370. case 191:
  21371. case 214:
  21372. if (node.modifiers && node.parent.kind !== 217 && node.parent.kind !== 246) {
  21373. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  21374. }
  21375. break;
  21376. case 215:
  21377. if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 72) &&
  21378. node.parent.kind !== 217 && node.parent.kind !== 246) {
  21379. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  21380. }
  21381. break;
  21382. default:
  21383. return false;
  21384. }
  21385. if (!node.modifiers) {
  21386. return;
  21387. }
  21388. var lastStatic, lastPrivate, lastProtected, lastDeclare, lastAsync;
  21389. var flags = 0;
  21390. for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
  21391. var modifier = _a[_i];
  21392. switch (modifier.kind) {
  21393. case 110:
  21394. case 109:
  21395. case 108:
  21396. var text = void 0;
  21397. if (modifier.kind === 110) {
  21398. text = "public";
  21399. }
  21400. else if (modifier.kind === 109) {
  21401. text = "protected";
  21402. lastProtected = modifier;
  21403. }
  21404. else {
  21405. text = "private";
  21406. lastPrivate = modifier;
  21407. }
  21408. if (flags & 112) {
  21409. return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen);
  21410. }
  21411. else if (flags & 128) {
  21412. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static");
  21413. }
  21414. else if (flags & 512) {
  21415. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async");
  21416. }
  21417. else if (node.parent.kind === 217 || node.parent.kind === 246) {
  21418. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
  21419. }
  21420. else if (flags & 256) {
  21421. if (modifier.kind === 108) {
  21422. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract");
  21423. }
  21424. else {
  21425. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "abstract");
  21426. }
  21427. }
  21428. flags |= ts.modifierToFlag(modifier.kind);
  21429. break;
  21430. case 111:
  21431. if (flags & 128) {
  21432. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static");
  21433. }
  21434. else if (flags & 512) {
  21435. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async");
  21436. }
  21437. else if (node.parent.kind === 217 || node.parent.kind === 246) {
  21438. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
  21439. }
  21440. else if (node.kind === 136) {
  21441. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
  21442. }
  21443. else if (flags & 256) {
  21444. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract");
  21445. }
  21446. flags |= 128;
  21447. lastStatic = modifier;
  21448. break;
  21449. case 80:
  21450. if (flags & 1) {
  21451. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export");
  21452. }
  21453. else if (flags & 2) {
  21454. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
  21455. }
  21456. else if (flags & 256) {
  21457. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "abstract");
  21458. }
  21459. else if (flags & 512) {
  21460. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async");
  21461. }
  21462. else if (node.parent.kind === 212) {
  21463. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
  21464. }
  21465. else if (node.kind === 136) {
  21466. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
  21467. }
  21468. flags |= 1;
  21469. break;
  21470. case 120:
  21471. if (flags & 2) {
  21472. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare");
  21473. }
  21474. else if (flags & 512) {
  21475. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
  21476. }
  21477. else if (node.parent.kind === 212) {
  21478. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
  21479. }
  21480. else if (node.kind === 136) {
  21481. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
  21482. }
  21483. else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 217) {
  21484. return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
  21485. }
  21486. flags |= 2;
  21487. lastDeclare = modifier;
  21488. break;
  21489. case 113:
  21490. if (flags & 256) {
  21491. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract");
  21492. }
  21493. if (node.kind !== 212) {
  21494. if (node.kind !== 141) {
  21495. return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration);
  21496. }
  21497. if (!(node.parent.kind === 212 && node.parent.flags & 256)) {
  21498. return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class);
  21499. }
  21500. if (flags & 128) {
  21501. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract");
  21502. }
  21503. if (flags & 32) {
  21504. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "private", "abstract");
  21505. }
  21506. }
  21507. flags |= 256;
  21508. break;
  21509. case 116:
  21510. if (flags & 512) {
  21511. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async");
  21512. }
  21513. else if (flags & 2 || ts.isInAmbientContext(node.parent)) {
  21514. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
  21515. }
  21516. else if (node.kind === 136) {
  21517. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async");
  21518. }
  21519. flags |= 512;
  21520. lastAsync = modifier;
  21521. break;
  21522. }
  21523. }
  21524. if (node.kind === 142) {
  21525. if (flags & 128) {
  21526. return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
  21527. }
  21528. if (flags & 256) {
  21529. return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract");
  21530. }
  21531. else if (flags & 64) {
  21532. return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
  21533. }
  21534. else if (flags & 32) {
  21535. return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
  21536. }
  21537. else if (flags & 512) {
  21538. return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async");
  21539. }
  21540. return;
  21541. }
  21542. else if ((node.kind === 220 || node.kind === 219) && flags & 2) {
  21543. return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare");
  21544. }
  21545. else if (node.kind === 136 && (flags & 112) && ts.isBindingPattern(node.name)) {
  21546. return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
  21547. }
  21548. if (flags & 512) {
  21549. return checkGrammarAsyncModifier(node, lastAsync);
  21550. }
  21551. }
  21552. function checkGrammarAsyncModifier(node, asyncModifier) {
  21553. if (languageVersion < 2) {
  21554. return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher);
  21555. }
  21556. switch (node.kind) {
  21557. case 141:
  21558. case 211:
  21559. case 171:
  21560. case 172:
  21561. if (!node.asteriskToken) {
  21562. return false;
  21563. }
  21564. break;
  21565. }
  21566. return grammarErrorOnNode(asyncModifier, ts.Diagnostics._0_modifier_cannot_be_used_here, "async");
  21567. }
  21568. function checkGrammarForDisallowedTrailingComma(list) {
  21569. if (list && list.hasTrailingComma) {
  21570. var start = list.end - ",".length;
  21571. var end = list.end;
  21572. var sourceFile = ts.getSourceFileOfNode(list[0]);
  21573. return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Trailing_comma_not_allowed);
  21574. }
  21575. }
  21576. function checkGrammarTypeParameterList(node, typeParameters, file) {
  21577. if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
  21578. return true;
  21579. }
  21580. if (typeParameters && typeParameters.length === 0) {
  21581. var start = typeParameters.pos - "<".length;
  21582. var end = ts.skipTrivia(file.text, typeParameters.end) + ">".length;
  21583. return grammarErrorAtPos(file, start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
  21584. }
  21585. }
  21586. function checkGrammarParameterList(parameters) {
  21587. if (checkGrammarForDisallowedTrailingComma(parameters)) {
  21588. return true;
  21589. }
  21590. var seenOptionalParameter = false;
  21591. var parameterCount = parameters.length;
  21592. for (var i = 0; i < parameterCount; i++) {
  21593. var parameter = parameters[i];
  21594. if (parameter.dotDotDotToken) {
  21595. if (i !== (parameterCount - 1)) {
  21596. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
  21597. }
  21598. if (ts.isBindingPattern(parameter.name)) {
  21599. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
  21600. }
  21601. if (parameter.questionToken) {
  21602. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
  21603. }
  21604. if (parameter.initializer) {
  21605. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
  21606. }
  21607. }
  21608. else if (parameter.questionToken) {
  21609. seenOptionalParameter = true;
  21610. if (parameter.initializer) {
  21611. return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
  21612. }
  21613. }
  21614. else if (seenOptionalParameter && !parameter.initializer) {
  21615. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
  21616. }
  21617. }
  21618. }
  21619. function checkGrammarFunctionLikeDeclaration(node) {
  21620. var file = ts.getSourceFileOfNode(node);
  21621. return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
  21622. checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
  21623. }
  21624. function checkGrammarArrowFunction(node, file) {
  21625. if (node.kind === 172) {
  21626. var arrowFunction = node;
  21627. var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line;
  21628. var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line;
  21629. if (startLine !== endLine) {
  21630. return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, ts.Diagnostics.Line_terminator_not_permitted_before_arrow);
  21631. }
  21632. }
  21633. return false;
  21634. }
  21635. function checkGrammarIndexSignatureParameters(node) {
  21636. var parameter = node.parameters[0];
  21637. if (node.parameters.length !== 1) {
  21638. if (parameter) {
  21639. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
  21640. }
  21641. else {
  21642. return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
  21643. }
  21644. }
  21645. if (parameter.dotDotDotToken) {
  21646. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
  21647. }
  21648. if (parameter.flags & 2035) {
  21649. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
  21650. }
  21651. if (parameter.questionToken) {
  21652. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
  21653. }
  21654. if (parameter.initializer) {
  21655. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
  21656. }
  21657. if (!parameter.type) {
  21658. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
  21659. }
  21660. if (parameter.type.kind !== 128 && parameter.type.kind !== 126) {
  21661. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
  21662. }
  21663. if (!node.type) {
  21664. return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
  21665. }
  21666. }
  21667. function checkGrammarForIndexSignatureModifier(node) {
  21668. if (node.flags & 2035) {
  21669. grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
  21670. }
  21671. }
  21672. function checkGrammarIndexSignature(node) {
  21673. return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node);
  21674. }
  21675. function checkGrammarForAtLeastOneTypeArgument(node, typeArguments) {
  21676. if (typeArguments && typeArguments.length === 0) {
  21677. var sourceFile = ts.getSourceFileOfNode(node);
  21678. var start = typeArguments.pos - "<".length;
  21679. var end = ts.skipTrivia(sourceFile.text, typeArguments.end) + ">".length;
  21680. return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
  21681. }
  21682. }
  21683. function checkGrammarTypeArguments(node, typeArguments) {
  21684. return checkGrammarForDisallowedTrailingComma(typeArguments) ||
  21685. checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
  21686. }
  21687. function checkGrammarForOmittedArgument(node, args) {
  21688. if (args) {
  21689. var sourceFile = ts.getSourceFileOfNode(node);
  21690. for (var _i = 0; _i < args.length; _i++) {
  21691. var arg = args[_i];
  21692. if (arg.kind === 185) {
  21693. return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected);
  21694. }
  21695. }
  21696. }
  21697. }
  21698. function checkGrammarArguments(node, args) {
  21699. return checkGrammarForDisallowedTrailingComma(args) ||
  21700. checkGrammarForOmittedArgument(node, args);
  21701. }
  21702. function checkGrammarHeritageClause(node) {
  21703. var types = node.types;
  21704. if (checkGrammarForDisallowedTrailingComma(types)) {
  21705. return true;
  21706. }
  21707. if (types && types.length === 0) {
  21708. var listType = ts.tokenToString(node.token);
  21709. var sourceFile = ts.getSourceFileOfNode(node);
  21710. return grammarErrorAtPos(sourceFile, types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType);
  21711. }
  21712. }
  21713. function checkGrammarClassDeclarationHeritageClauses(node) {
  21714. var seenExtendsClause = false;
  21715. var seenImplementsClause = false;
  21716. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) {
  21717. for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
  21718. var heritageClause = _a[_i];
  21719. if (heritageClause.token === 81) {
  21720. if (seenExtendsClause) {
  21721. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
  21722. }
  21723. if (seenImplementsClause) {
  21724. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause);
  21725. }
  21726. if (heritageClause.types.length > 1) {
  21727. return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class);
  21728. }
  21729. seenExtendsClause = true;
  21730. }
  21731. else {
  21732. ts.Debug.assert(heritageClause.token === 104);
  21733. if (seenImplementsClause) {
  21734. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen);
  21735. }
  21736. seenImplementsClause = true;
  21737. }
  21738. checkGrammarHeritageClause(heritageClause);
  21739. }
  21740. }
  21741. }
  21742. function checkGrammarInterfaceDeclaration(node) {
  21743. var seenExtendsClause = false;
  21744. if (node.heritageClauses) {
  21745. for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
  21746. var heritageClause = _a[_i];
  21747. if (heritageClause.token === 81) {
  21748. if (seenExtendsClause) {
  21749. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
  21750. }
  21751. seenExtendsClause = true;
  21752. }
  21753. else {
  21754. ts.Debug.assert(heritageClause.token === 104);
  21755. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause);
  21756. }
  21757. checkGrammarHeritageClause(heritageClause);
  21758. }
  21759. }
  21760. return false;
  21761. }
  21762. function checkGrammarComputedPropertyName(node) {
  21763. if (node.kind !== 134) {
  21764. return false;
  21765. }
  21766. var computedPropertyName = node;
  21767. if (computedPropertyName.expression.kind === 179 && computedPropertyName.expression.operatorToken.kind === 24) {
  21768. return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name);
  21769. }
  21770. }
  21771. function checkGrammarForGenerator(node) {
  21772. if (node.asteriskToken) {
  21773. ts.Debug.assert(node.kind === 211 ||
  21774. node.kind === 171 ||
  21775. node.kind === 141);
  21776. if (ts.isInAmbientContext(node)) {
  21777. return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
  21778. }
  21779. if (!node.body) {
  21780. return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator);
  21781. }
  21782. if (languageVersion < 2) {
  21783. return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
  21784. }
  21785. }
  21786. }
  21787. function checkGrammarForInvalidQuestionMark(node, questionToken, message) {
  21788. if (questionToken) {
  21789. return grammarErrorOnNode(questionToken, message);
  21790. }
  21791. }
  21792. function checkGrammarObjectLiteralExpression(node) {
  21793. var seen = {};
  21794. var Property = 1;
  21795. var GetAccessor = 2;
  21796. var SetAccesor = 4;
  21797. var GetOrSetAccessor = GetAccessor | SetAccesor;
  21798. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  21799. var prop = _a[_i];
  21800. var name_16 = prop.name;
  21801. if (prop.kind === 185 ||
  21802. name_16.kind === 134) {
  21803. checkGrammarComputedPropertyName(name_16);
  21804. continue;
  21805. }
  21806. var currentKind = void 0;
  21807. if (prop.kind === 243 || prop.kind === 244) {
  21808. checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
  21809. if (name_16.kind === 8) {
  21810. checkGrammarNumericLiteral(name_16);
  21811. }
  21812. currentKind = Property;
  21813. }
  21814. else if (prop.kind === 141) {
  21815. currentKind = Property;
  21816. }
  21817. else if (prop.kind === 143) {
  21818. currentKind = GetAccessor;
  21819. }
  21820. else if (prop.kind === 144) {
  21821. currentKind = SetAccesor;
  21822. }
  21823. else {
  21824. ts.Debug.fail("Unexpected syntax kind:" + prop.kind);
  21825. }
  21826. if (!ts.hasProperty(seen, name_16.text)) {
  21827. seen[name_16.text] = currentKind;
  21828. }
  21829. else {
  21830. var existingKind = seen[name_16.text];
  21831. if (currentKind === Property && existingKind === Property) {
  21832. continue;
  21833. }
  21834. else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
  21835. if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
  21836. seen[name_16.text] = currentKind | existingKind;
  21837. }
  21838. else {
  21839. return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
  21840. }
  21841. }
  21842. else {
  21843. return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
  21844. }
  21845. }
  21846. }
  21847. }
  21848. function checkGrammarJsxElement(node) {
  21849. var seen = {};
  21850. for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) {
  21851. var attr = _a[_i];
  21852. if (attr.kind === 237) {
  21853. continue;
  21854. }
  21855. var jsxAttr = attr;
  21856. var name_17 = jsxAttr.name;
  21857. if (!ts.hasProperty(seen, name_17.text)) {
  21858. seen[name_17.text] = true;
  21859. }
  21860. else {
  21861. return grammarErrorOnNode(name_17, ts.Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name);
  21862. }
  21863. var initializer = jsxAttr.initializer;
  21864. if (initializer && initializer.kind === 238 && !initializer.expression) {
  21865. return grammarErrorOnNode(jsxAttr.initializer, ts.Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression);
  21866. }
  21867. }
  21868. }
  21869. function checkGrammarForInOrForOfStatement(forInOrOfStatement) {
  21870. if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) {
  21871. return true;
  21872. }
  21873. if (forInOrOfStatement.initializer.kind === 210) {
  21874. var variableList = forInOrOfStatement.initializer;
  21875. if (!checkGrammarVariableDeclarationList(variableList)) {
  21876. if (variableList.declarations.length > 1) {
  21877. var diagnostic = forInOrOfStatement.kind === 198
  21878. ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement
  21879. : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
  21880. return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
  21881. }
  21882. var firstDeclaration = variableList.declarations[0];
  21883. if (firstDeclaration.initializer) {
  21884. var diagnostic = forInOrOfStatement.kind === 198
  21885. ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer
  21886. : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer;
  21887. return grammarErrorOnNode(firstDeclaration.name, diagnostic);
  21888. }
  21889. if (firstDeclaration.type) {
  21890. var diagnostic = forInOrOfStatement.kind === 198
  21891. ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation
  21892. : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation;
  21893. return grammarErrorOnNode(firstDeclaration, diagnostic);
  21894. }
  21895. }
  21896. }
  21897. return false;
  21898. }
  21899. function checkGrammarAccessor(accessor) {
  21900. var kind = accessor.kind;
  21901. if (languageVersion < 1) {
  21902. return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
  21903. }
  21904. else if (ts.isInAmbientContext(accessor)) {
  21905. return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
  21906. }
  21907. else if (accessor.body === undefined) {
  21908. return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
  21909. }
  21910. else if (accessor.typeParameters) {
  21911. return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
  21912. }
  21913. else if (kind === 143 && accessor.parameters.length) {
  21914. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
  21915. }
  21916. else if (kind === 144) {
  21917. if (accessor.type) {
  21918. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
  21919. }
  21920. else if (accessor.parameters.length !== 1) {
  21921. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
  21922. }
  21923. else {
  21924. var parameter = accessor.parameters[0];
  21925. if (parameter.dotDotDotToken) {
  21926. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
  21927. }
  21928. else if (parameter.flags & 2035) {
  21929. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
  21930. }
  21931. else if (parameter.questionToken) {
  21932. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
  21933. }
  21934. else if (parameter.initializer) {
  21935. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
  21936. }
  21937. }
  21938. }
  21939. }
  21940. function checkGrammarForNonSymbolComputedProperty(node, message) {
  21941. if (node.kind === 134 && !ts.isWellKnownSymbolSyntactically(node.expression)) {
  21942. return grammarErrorOnNode(node, message);
  21943. }
  21944. }
  21945. function checkGrammarMethod(node) {
  21946. if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) ||
  21947. checkGrammarFunctionLikeDeclaration(node) ||
  21948. checkGrammarForGenerator(node)) {
  21949. return true;
  21950. }
  21951. if (node.parent.kind === 163) {
  21952. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
  21953. return true;
  21954. }
  21955. else if (node.body === undefined) {
  21956. return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
  21957. }
  21958. }
  21959. if (ts.isClassLike(node.parent)) {
  21960. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
  21961. return true;
  21962. }
  21963. if (ts.isInAmbientContext(node)) {
  21964. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol);
  21965. }
  21966. else if (!node.body) {
  21967. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol);
  21968. }
  21969. }
  21970. else if (node.parent.kind === 213) {
  21971. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol);
  21972. }
  21973. else if (node.parent.kind === 153) {
  21974. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol);
  21975. }
  21976. }
  21977. function isIterationStatement(node, lookInLabeledStatements) {
  21978. switch (node.kind) {
  21979. case 197:
  21980. case 198:
  21981. case 199:
  21982. case 195:
  21983. case 196:
  21984. return true;
  21985. case 205:
  21986. return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements);
  21987. }
  21988. return false;
  21989. }
  21990. function checkGrammarBreakOrContinueStatement(node) {
  21991. var current = node;
  21992. while (current) {
  21993. if (ts.isFunctionLike(current)) {
  21994. return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
  21995. }
  21996. switch (current.kind) {
  21997. case 205:
  21998. if (node.label && current.label.text === node.label.text) {
  21999. var isMisplacedContinueLabel = node.kind === 200
  22000. && !isIterationStatement(current.statement, true);
  22001. if (isMisplacedContinueLabel) {
  22002. return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
  22003. }
  22004. return false;
  22005. }
  22006. break;
  22007. case 204:
  22008. if (node.kind === 201 && !node.label) {
  22009. return false;
  22010. }
  22011. break;
  22012. default:
  22013. if (isIterationStatement(current, false) && !node.label) {
  22014. return false;
  22015. }
  22016. break;
  22017. }
  22018. current = current.parent;
  22019. }
  22020. if (node.label) {
  22021. var message = node.kind === 201
  22022. ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement
  22023. : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement;
  22024. return grammarErrorOnNode(node, message);
  22025. }
  22026. else {
  22027. var message = node.kind === 201
  22028. ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement
  22029. : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement;
  22030. return grammarErrorOnNode(node, message);
  22031. }
  22032. }
  22033. function checkGrammarBindingElement(node) {
  22034. if (node.dotDotDotToken) {
  22035. var elements = node.parent.elements;
  22036. if (node !== ts.lastOrUndefined(elements)) {
  22037. return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
  22038. }
  22039. if (node.name.kind === 160 || node.name.kind === 159) {
  22040. return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
  22041. }
  22042. if (node.initializer) {
  22043. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.A_rest_element_cannot_have_an_initializer);
  22044. }
  22045. }
  22046. }
  22047. function checkGrammarVariableDeclaration(node) {
  22048. if (node.parent.parent.kind !== 198 && node.parent.parent.kind !== 199) {
  22049. if (ts.isInAmbientContext(node)) {
  22050. if (node.initializer) {
  22051. var equalsTokenLength = "=".length;
  22052. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
  22053. }
  22054. }
  22055. else if (!node.initializer) {
  22056. if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) {
  22057. return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer);
  22058. }
  22059. if (ts.isConst(node)) {
  22060. return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
  22061. }
  22062. }
  22063. }
  22064. var checkLetConstNames = languageVersion >= 2 && (ts.isLet(node) || ts.isConst(node));
  22065. return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name);
  22066. }
  22067. function checkGrammarNameInLetOrConstDeclarations(name) {
  22068. if (name.kind === 67) {
  22069. if (name.text === "let") {
  22070. return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations);
  22071. }
  22072. }
  22073. else {
  22074. var elements = name.elements;
  22075. for (var _i = 0; _i < elements.length; _i++) {
  22076. var element = elements[_i];
  22077. if (element.kind !== 185) {
  22078. checkGrammarNameInLetOrConstDeclarations(element.name);
  22079. }
  22080. }
  22081. }
  22082. }
  22083. function checkGrammarVariableDeclarationList(declarationList) {
  22084. var declarations = declarationList.declarations;
  22085. if (checkGrammarForDisallowedTrailingComma(declarationList.declarations)) {
  22086. return true;
  22087. }
  22088. if (!declarationList.declarations.length) {
  22089. return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
  22090. }
  22091. }
  22092. function allowLetAndConstDeclarations(parent) {
  22093. switch (parent.kind) {
  22094. case 194:
  22095. case 195:
  22096. case 196:
  22097. case 203:
  22098. case 197:
  22099. case 198:
  22100. case 199:
  22101. return false;
  22102. case 205:
  22103. return allowLetAndConstDeclarations(parent.parent);
  22104. }
  22105. return true;
  22106. }
  22107. function checkGrammarForDisallowedLetOrConstStatement(node) {
  22108. if (!allowLetAndConstDeclarations(node.parent)) {
  22109. if (ts.isLet(node.declarationList)) {
  22110. return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
  22111. }
  22112. else if (ts.isConst(node.declarationList)) {
  22113. return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
  22114. }
  22115. }
  22116. }
  22117. function isIntegerLiteral(expression) {
  22118. if (expression.kind === 177) {
  22119. var unaryExpression = expression;
  22120. if (unaryExpression.operator === 35 || unaryExpression.operator === 36) {
  22121. expression = unaryExpression.operand;
  22122. }
  22123. }
  22124. if (expression.kind === 8) {
  22125. return /^[0-9]+([eE]\+?[0-9]+)?$/.test(expression.text);
  22126. }
  22127. return false;
  22128. }
  22129. function checkGrammarEnumDeclaration(enumDecl) {
  22130. var enumIsConst = (enumDecl.flags & 32768) !== 0;
  22131. var hasError = false;
  22132. if (!enumIsConst) {
  22133. var inConstantEnumMemberSection = true;
  22134. var inAmbientContext = ts.isInAmbientContext(enumDecl);
  22135. for (var _i = 0, _a = enumDecl.members; _i < _a.length; _i++) {
  22136. var node = _a[_i];
  22137. if (node.name.kind === 134) {
  22138. hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums);
  22139. }
  22140. else if (inAmbientContext) {
  22141. if (node.initializer && !isIntegerLiteral(node.initializer)) {
  22142. hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError;
  22143. }
  22144. }
  22145. else if (node.initializer) {
  22146. inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
  22147. }
  22148. else if (!inConstantEnumMemberSection) {
  22149. hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError;
  22150. }
  22151. }
  22152. }
  22153. return hasError;
  22154. }
  22155. function hasParseDiagnostics(sourceFile) {
  22156. return sourceFile.parseDiagnostics.length > 0;
  22157. }
  22158. function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
  22159. var sourceFile = ts.getSourceFileOfNode(node);
  22160. if (!hasParseDiagnostics(sourceFile)) {
  22161. var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
  22162. diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2));
  22163. return true;
  22164. }
  22165. }
  22166. function grammarErrorAtPos(sourceFile, start, length, message, arg0, arg1, arg2) {
  22167. if (!hasParseDiagnostics(sourceFile)) {
  22168. diagnostics.add(ts.createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
  22169. return true;
  22170. }
  22171. }
  22172. function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
  22173. var sourceFile = ts.getSourceFileOfNode(node);
  22174. if (!hasParseDiagnostics(sourceFile)) {
  22175. diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2));
  22176. return true;
  22177. }
  22178. }
  22179. function isEvalOrArgumentsIdentifier(node) {
  22180. return node.kind === 67 &&
  22181. (node.text === "eval" || node.text === "arguments");
  22182. }
  22183. function checkGrammarConstructorTypeParameters(node) {
  22184. if (node.typeParameters) {
  22185. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
  22186. }
  22187. }
  22188. function checkGrammarConstructorTypeAnnotation(node) {
  22189. if (node.type) {
  22190. return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
  22191. }
  22192. }
  22193. function checkGrammarProperty(node) {
  22194. if (ts.isClassLike(node.parent)) {
  22195. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) ||
  22196. checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) {
  22197. return true;
  22198. }
  22199. }
  22200. else if (node.parent.kind === 213) {
  22201. if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) {
  22202. return true;
  22203. }
  22204. }
  22205. else if (node.parent.kind === 153) {
  22206. if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) {
  22207. return true;
  22208. }
  22209. }
  22210. if (ts.isInAmbientContext(node) && node.initializer) {
  22211. return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
  22212. }
  22213. }
  22214. function checkGrammarTopLevelElementForRequiredDeclareModifier(node) {
  22215. if (node.kind === 213 ||
  22216. node.kind === 220 ||
  22217. node.kind === 219 ||
  22218. node.kind === 226 ||
  22219. node.kind === 225 ||
  22220. (node.flags & 2) ||
  22221. (node.flags & (1 | 1024))) {
  22222. return false;
  22223. }
  22224. return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
  22225. }
  22226. function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) {
  22227. for (var _i = 0, _a = file.statements; _i < _a.length; _i++) {
  22228. var decl = _a[_i];
  22229. if (ts.isDeclaration(decl) || decl.kind === 191) {
  22230. if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) {
  22231. return true;
  22232. }
  22233. }
  22234. }
  22235. }
  22236. function checkGrammarSourceFile(node) {
  22237. return ts.isInAmbientContext(node) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
  22238. }
  22239. function checkGrammarStatementInAmbientContext(node) {
  22240. if (ts.isInAmbientContext(node)) {
  22241. if (isAccessor(node.parent.kind)) {
  22242. return getNodeLinks(node).hasReportedStatementInAmbientContext = true;
  22243. }
  22244. var links = getNodeLinks(node);
  22245. if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) {
  22246. return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
  22247. }
  22248. if (node.parent.kind === 190 || node.parent.kind === 217 || node.parent.kind === 246) {
  22249. var links_1 = getNodeLinks(node.parent);
  22250. if (!links_1.hasReportedStatementInAmbientContext) {
  22251. return links_1.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
  22252. }
  22253. }
  22254. else {
  22255. }
  22256. }
  22257. }
  22258. function checkGrammarNumericLiteral(node) {
  22259. if (node.flags & 65536 && languageVersion >= 1) {
  22260. return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
  22261. }
  22262. }
  22263. function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) {
  22264. var sourceFile = ts.getSourceFileOfNode(node);
  22265. if (!hasParseDiagnostics(sourceFile)) {
  22266. var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
  22267. diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), 0, message, arg0, arg1, arg2));
  22268. return true;
  22269. }
  22270. }
  22271. }
  22272. ts.createTypeChecker = createTypeChecker;
  22273. })(ts || (ts = {}));
  22274. /// <reference path="checker.ts"/>
  22275. var ts;
  22276. (function (ts) {
  22277. function getDeclarationDiagnostics(host, resolver, targetSourceFile) {
  22278. var diagnostics = [];
  22279. var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
  22280. emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile);
  22281. return diagnostics;
  22282. }
  22283. ts.getDeclarationDiagnostics = getDeclarationDiagnostics;
  22284. function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) {
  22285. var newLine = host.getNewLine();
  22286. var compilerOptions = host.getCompilerOptions();
  22287. var write;
  22288. var writeLine;
  22289. var increaseIndent;
  22290. var decreaseIndent;
  22291. var writeTextOfNode;
  22292. var writer = createAndSetNewTextWriterWithSymbolWriter();
  22293. var enclosingDeclaration;
  22294. var currentSourceFile;
  22295. var reportedDeclarationError = false;
  22296. var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments;
  22297. var emit = compilerOptions.stripInternal ? stripInternal : emitNode;
  22298. var moduleElementDeclarationEmitInfo = [];
  22299. var asynchronousSubModuleDeclarationEmitInfo;
  22300. var referencePathsOutput = "";
  22301. if (root) {
  22302. if (!compilerOptions.noResolve) {
  22303. var addedGlobalFileReference = false;
  22304. ts.forEach(root.referencedFiles, function (fileReference) {
  22305. var referencedFile = ts.tryResolveScriptReference(host, root, fileReference);
  22306. if (referencedFile && ((referencedFile.flags & 8192) ||
  22307. ts.shouldEmitToOwnFile(referencedFile, compilerOptions) ||
  22308. !addedGlobalFileReference)) {
  22309. writeReferencePath(referencedFile);
  22310. if (!ts.isExternalModuleOrDeclarationFile(referencedFile)) {
  22311. addedGlobalFileReference = true;
  22312. }
  22313. }
  22314. });
  22315. }
  22316. emitSourceFile(root);
  22317. if (moduleElementDeclarationEmitInfo.length) {
  22318. var oldWriter = writer;
  22319. ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
  22320. if (aliasEmitInfo.isVisible) {
  22321. ts.Debug.assert(aliasEmitInfo.node.kind === 220);
  22322. createAndSetNewTextWriterWithSymbolWriter();
  22323. ts.Debug.assert(aliasEmitInfo.indent === 0);
  22324. writeImportDeclaration(aliasEmitInfo.node);
  22325. aliasEmitInfo.asynchronousOutput = writer.getText();
  22326. }
  22327. });
  22328. setWriter(oldWriter);
  22329. }
  22330. }
  22331. else {
  22332. var emittedReferencedFiles = [];
  22333. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  22334. if (!ts.isExternalModuleOrDeclarationFile(sourceFile)) {
  22335. if (!compilerOptions.noResolve) {
  22336. ts.forEach(sourceFile.referencedFiles, function (fileReference) {
  22337. var referencedFile = ts.tryResolveScriptReference(host, sourceFile, fileReference);
  22338. if (referencedFile && (ts.isExternalModuleOrDeclarationFile(referencedFile) &&
  22339. !ts.contains(emittedReferencedFiles, referencedFile))) {
  22340. writeReferencePath(referencedFile);
  22341. emittedReferencedFiles.push(referencedFile);
  22342. }
  22343. });
  22344. }
  22345. emitSourceFile(sourceFile);
  22346. }
  22347. });
  22348. }
  22349. return {
  22350. reportedDeclarationError: reportedDeclarationError,
  22351. moduleElementDeclarationEmitInfo: moduleElementDeclarationEmitInfo,
  22352. synchronousDeclarationOutput: writer.getText(),
  22353. referencePathsOutput: referencePathsOutput
  22354. };
  22355. function hasInternalAnnotation(range) {
  22356. var text = currentSourceFile.text;
  22357. var comment = text.substring(range.pos, range.end);
  22358. return comment.indexOf("@internal") >= 0;
  22359. }
  22360. function stripInternal(node) {
  22361. if (node) {
  22362. var leadingCommentRanges = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
  22363. if (ts.forEach(leadingCommentRanges, hasInternalAnnotation)) {
  22364. return;
  22365. }
  22366. emitNode(node);
  22367. }
  22368. }
  22369. function createAndSetNewTextWriterWithSymbolWriter() {
  22370. var writer = ts.createTextWriter(newLine);
  22371. writer.trackSymbol = trackSymbol;
  22372. writer.writeKeyword = writer.write;
  22373. writer.writeOperator = writer.write;
  22374. writer.writePunctuation = writer.write;
  22375. writer.writeSpace = writer.write;
  22376. writer.writeStringLiteral = writer.writeLiteral;
  22377. writer.writeParameter = writer.write;
  22378. writer.writeSymbol = writer.write;
  22379. setWriter(writer);
  22380. return writer;
  22381. }
  22382. function setWriter(newWriter) {
  22383. writer = newWriter;
  22384. write = newWriter.write;
  22385. writeTextOfNode = newWriter.writeTextOfNode;
  22386. writeLine = newWriter.writeLine;
  22387. increaseIndent = newWriter.increaseIndent;
  22388. decreaseIndent = newWriter.decreaseIndent;
  22389. }
  22390. function writeAsynchronousModuleElements(nodes) {
  22391. var oldWriter = writer;
  22392. ts.forEach(nodes, function (declaration) {
  22393. var nodeToCheck;
  22394. if (declaration.kind === 209) {
  22395. nodeToCheck = declaration.parent.parent;
  22396. }
  22397. else if (declaration.kind === 223 || declaration.kind === 224 || declaration.kind === 221) {
  22398. ts.Debug.fail("We should be getting ImportDeclaration instead to write");
  22399. }
  22400. else {
  22401. nodeToCheck = declaration;
  22402. }
  22403. var moduleElementEmitInfo = ts.forEach(moduleElementDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
  22404. if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) {
  22405. moduleElementEmitInfo = ts.forEach(asynchronousSubModuleDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
  22406. }
  22407. if (moduleElementEmitInfo) {
  22408. if (moduleElementEmitInfo.node.kind === 220) {
  22409. moduleElementEmitInfo.isVisible = true;
  22410. }
  22411. else {
  22412. createAndSetNewTextWriterWithSymbolWriter();
  22413. for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) {
  22414. increaseIndent();
  22415. }
  22416. if (nodeToCheck.kind === 216) {
  22417. ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined);
  22418. asynchronousSubModuleDeclarationEmitInfo = [];
  22419. }
  22420. writeModuleElement(nodeToCheck);
  22421. if (nodeToCheck.kind === 216) {
  22422. moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo;
  22423. asynchronousSubModuleDeclarationEmitInfo = undefined;
  22424. }
  22425. moduleElementEmitInfo.asynchronousOutput = writer.getText();
  22426. }
  22427. }
  22428. });
  22429. setWriter(oldWriter);
  22430. }
  22431. function handleSymbolAccessibilityError(symbolAccesibilityResult) {
  22432. if (symbolAccesibilityResult.accessibility === 0) {
  22433. if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
  22434. writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible);
  22435. }
  22436. }
  22437. else {
  22438. reportedDeclarationError = true;
  22439. var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
  22440. if (errorInfo) {
  22441. if (errorInfo.typeName) {
  22442. diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
  22443. }
  22444. else {
  22445. diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
  22446. }
  22447. }
  22448. }
  22449. }
  22450. function trackSymbol(symbol, enclosingDeclaration, meaning) {
  22451. handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
  22452. }
  22453. function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) {
  22454. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  22455. write(": ");
  22456. if (type) {
  22457. emitType(type);
  22458. }
  22459. else {
  22460. resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2, writer);
  22461. }
  22462. }
  22463. function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) {
  22464. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  22465. write(": ");
  22466. if (signature.type) {
  22467. emitType(signature.type);
  22468. }
  22469. else {
  22470. resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2, writer);
  22471. }
  22472. }
  22473. function emitLines(nodes) {
  22474. for (var _i = 0; _i < nodes.length; _i++) {
  22475. var node = nodes[_i];
  22476. emit(node);
  22477. }
  22478. }
  22479. function emitSeparatedList(nodes, separator, eachNodeEmitFn, canEmitFn) {
  22480. var currentWriterPos = writer.getTextPos();
  22481. for (var _i = 0; _i < nodes.length; _i++) {
  22482. var node = nodes[_i];
  22483. if (!canEmitFn || canEmitFn(node)) {
  22484. if (currentWriterPos !== writer.getTextPos()) {
  22485. write(separator);
  22486. }
  22487. currentWriterPos = writer.getTextPos();
  22488. eachNodeEmitFn(node);
  22489. }
  22490. }
  22491. }
  22492. function emitCommaList(nodes, eachNodeEmitFn, canEmitFn) {
  22493. emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn);
  22494. }
  22495. function writeJsDocComments(declaration) {
  22496. if (declaration) {
  22497. var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile);
  22498. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments);
  22499. ts.emitComments(currentSourceFile, writer, jsDocComments, true, newLine, ts.writeCommentRange);
  22500. }
  22501. }
  22502. function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) {
  22503. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  22504. emitType(type);
  22505. }
  22506. function emitType(type) {
  22507. switch (type.kind) {
  22508. case 115:
  22509. case 128:
  22510. case 126:
  22511. case 118:
  22512. case 129:
  22513. case 101:
  22514. case 9:
  22515. return writeTextOfNode(currentSourceFile, type);
  22516. case 186:
  22517. return emitExpressionWithTypeArguments(type);
  22518. case 149:
  22519. return emitTypeReference(type);
  22520. case 152:
  22521. return emitTypeQuery(type);
  22522. case 154:
  22523. return emitArrayType(type);
  22524. case 155:
  22525. return emitTupleType(type);
  22526. case 156:
  22527. return emitUnionType(type);
  22528. case 157:
  22529. return emitIntersectionType(type);
  22530. case 158:
  22531. return emitParenType(type);
  22532. case 150:
  22533. case 151:
  22534. return emitSignatureDeclarationWithJsDocComments(type);
  22535. case 153:
  22536. return emitTypeLiteral(type);
  22537. case 67:
  22538. return emitEntityName(type);
  22539. case 133:
  22540. return emitEntityName(type);
  22541. case 148:
  22542. return emitTypePredicate(type);
  22543. }
  22544. function writeEntityName(entityName) {
  22545. if (entityName.kind === 67) {
  22546. writeTextOfNode(currentSourceFile, entityName);
  22547. }
  22548. else {
  22549. var left = entityName.kind === 133 ? entityName.left : entityName.expression;
  22550. var right = entityName.kind === 133 ? entityName.right : entityName.name;
  22551. writeEntityName(left);
  22552. write(".");
  22553. writeTextOfNode(currentSourceFile, right);
  22554. }
  22555. }
  22556. function emitEntityName(entityName) {
  22557. var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 219 ? entityName.parent : enclosingDeclaration);
  22558. handleSymbolAccessibilityError(visibilityResult);
  22559. writeEntityName(entityName);
  22560. }
  22561. function emitExpressionWithTypeArguments(node) {
  22562. if (ts.isSupportedExpressionWithTypeArguments(node)) {
  22563. ts.Debug.assert(node.expression.kind === 67 || node.expression.kind === 164);
  22564. emitEntityName(node.expression);
  22565. if (node.typeArguments) {
  22566. write("<");
  22567. emitCommaList(node.typeArguments, emitType);
  22568. write(">");
  22569. }
  22570. }
  22571. }
  22572. function emitTypeReference(type) {
  22573. emitEntityName(type.typeName);
  22574. if (type.typeArguments) {
  22575. write("<");
  22576. emitCommaList(type.typeArguments, emitType);
  22577. write(">");
  22578. }
  22579. }
  22580. function emitTypePredicate(type) {
  22581. writeTextOfNode(currentSourceFile, type.parameterName);
  22582. write(" is ");
  22583. emitType(type.type);
  22584. }
  22585. function emitTypeQuery(type) {
  22586. write("typeof ");
  22587. emitEntityName(type.exprName);
  22588. }
  22589. function emitArrayType(type) {
  22590. emitType(type.elementType);
  22591. write("[]");
  22592. }
  22593. function emitTupleType(type) {
  22594. write("[");
  22595. emitCommaList(type.elementTypes, emitType);
  22596. write("]");
  22597. }
  22598. function emitUnionType(type) {
  22599. emitSeparatedList(type.types, " | ", emitType);
  22600. }
  22601. function emitIntersectionType(type) {
  22602. emitSeparatedList(type.types, " & ", emitType);
  22603. }
  22604. function emitParenType(type) {
  22605. write("(");
  22606. emitType(type.type);
  22607. write(")");
  22608. }
  22609. function emitTypeLiteral(type) {
  22610. write("{");
  22611. if (type.members.length) {
  22612. writeLine();
  22613. increaseIndent();
  22614. emitLines(type.members);
  22615. decreaseIndent();
  22616. }
  22617. write("}");
  22618. }
  22619. }
  22620. function emitSourceFile(node) {
  22621. currentSourceFile = node;
  22622. enclosingDeclaration = node;
  22623. emitLines(node.statements);
  22624. }
  22625. function getExportDefaultTempVariableName() {
  22626. var baseName = "_default";
  22627. if (!ts.hasProperty(currentSourceFile.identifiers, baseName)) {
  22628. return baseName;
  22629. }
  22630. var count = 0;
  22631. while (true) {
  22632. var name_18 = baseName + "_" + (++count);
  22633. if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) {
  22634. return name_18;
  22635. }
  22636. }
  22637. }
  22638. function emitExportAssignment(node) {
  22639. if (node.expression.kind === 67) {
  22640. write(node.isExportEquals ? "export = " : "export default ");
  22641. writeTextOfNode(currentSourceFile, node.expression);
  22642. }
  22643. else {
  22644. var tempVarName = getExportDefaultTempVariableName();
  22645. write("declare var ");
  22646. write(tempVarName);
  22647. write(": ");
  22648. writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic;
  22649. resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, 2, writer);
  22650. write(";");
  22651. writeLine();
  22652. write(node.isExportEquals ? "export = " : "export default ");
  22653. write(tempVarName);
  22654. }
  22655. write(";");
  22656. writeLine();
  22657. if (node.expression.kind === 67) {
  22658. var nodes = resolver.collectLinkedAliases(node.expression);
  22659. writeAsynchronousModuleElements(nodes);
  22660. }
  22661. function getDefaultExportAccessibilityDiagnostic(diagnostic) {
  22662. return {
  22663. diagnosticMessage: ts.Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
  22664. errorNode: node
  22665. };
  22666. }
  22667. }
  22668. function isModuleElementVisible(node) {
  22669. return resolver.isDeclarationVisible(node);
  22670. }
  22671. function emitModuleElement(node, isModuleElementVisible) {
  22672. if (isModuleElementVisible) {
  22673. writeModuleElement(node);
  22674. }
  22675. else if (node.kind === 219 ||
  22676. (node.parent.kind === 246 && ts.isExternalModule(currentSourceFile))) {
  22677. var isVisible;
  22678. if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 246) {
  22679. asynchronousSubModuleDeclarationEmitInfo.push({
  22680. node: node,
  22681. outputPos: writer.getTextPos(),
  22682. indent: writer.getIndent(),
  22683. isVisible: isVisible
  22684. });
  22685. }
  22686. else {
  22687. if (node.kind === 220) {
  22688. var importDeclaration = node;
  22689. if (importDeclaration.importClause) {
  22690. isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) ||
  22691. isVisibleNamedBinding(importDeclaration.importClause.namedBindings);
  22692. }
  22693. }
  22694. moduleElementDeclarationEmitInfo.push({
  22695. node: node,
  22696. outputPos: writer.getTextPos(),
  22697. indent: writer.getIndent(),
  22698. isVisible: isVisible
  22699. });
  22700. }
  22701. }
  22702. }
  22703. function writeModuleElement(node) {
  22704. switch (node.kind) {
  22705. case 211:
  22706. return writeFunctionDeclaration(node);
  22707. case 191:
  22708. return writeVariableStatement(node);
  22709. case 213:
  22710. return writeInterfaceDeclaration(node);
  22711. case 212:
  22712. return writeClassDeclaration(node);
  22713. case 214:
  22714. return writeTypeAliasDeclaration(node);
  22715. case 215:
  22716. return writeEnumDeclaration(node);
  22717. case 216:
  22718. return writeModuleDeclaration(node);
  22719. case 219:
  22720. return writeImportEqualsDeclaration(node);
  22721. case 220:
  22722. return writeImportDeclaration(node);
  22723. default:
  22724. ts.Debug.fail("Unknown symbol kind");
  22725. }
  22726. }
  22727. function emitModuleElementDeclarationFlags(node) {
  22728. if (node.parent === currentSourceFile) {
  22729. if (node.flags & 1) {
  22730. write("export ");
  22731. }
  22732. if (node.flags & 1024) {
  22733. write("default ");
  22734. }
  22735. else if (node.kind !== 213) {
  22736. write("declare ");
  22737. }
  22738. }
  22739. }
  22740. function emitClassMemberDeclarationFlags(node) {
  22741. if (node.flags & 32) {
  22742. write("private ");
  22743. }
  22744. else if (node.flags & 64) {
  22745. write("protected ");
  22746. }
  22747. if (node.flags & 128) {
  22748. write("static ");
  22749. }
  22750. if (node.flags & 256) {
  22751. write("abstract ");
  22752. }
  22753. }
  22754. function writeImportEqualsDeclaration(node) {
  22755. emitJsDocComments(node);
  22756. if (node.flags & 1) {
  22757. write("export ");
  22758. }
  22759. write("import ");
  22760. writeTextOfNode(currentSourceFile, node.name);
  22761. write(" = ");
  22762. if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  22763. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError);
  22764. write(";");
  22765. }
  22766. else {
  22767. write("require(");
  22768. writeTextOfNode(currentSourceFile, ts.getExternalModuleImportEqualsDeclarationExpression(node));
  22769. write(");");
  22770. }
  22771. writer.writeLine();
  22772. function getImportEntityNameVisibilityError(symbolAccesibilityResult) {
  22773. return {
  22774. diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1,
  22775. errorNode: node,
  22776. typeName: node.name
  22777. };
  22778. }
  22779. }
  22780. function isVisibleNamedBinding(namedBindings) {
  22781. if (namedBindings) {
  22782. if (namedBindings.kind === 222) {
  22783. return resolver.isDeclarationVisible(namedBindings);
  22784. }
  22785. else {
  22786. return ts.forEach(namedBindings.elements, function (namedImport) { return resolver.isDeclarationVisible(namedImport); });
  22787. }
  22788. }
  22789. }
  22790. function writeImportDeclaration(node) {
  22791. if (!node.importClause && !(node.flags & 1)) {
  22792. return;
  22793. }
  22794. emitJsDocComments(node);
  22795. if (node.flags & 1) {
  22796. write("export ");
  22797. }
  22798. write("import ");
  22799. if (node.importClause) {
  22800. var currentWriterPos = writer.getTextPos();
  22801. if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) {
  22802. writeTextOfNode(currentSourceFile, node.importClause.name);
  22803. }
  22804. if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) {
  22805. if (currentWriterPos !== writer.getTextPos()) {
  22806. write(", ");
  22807. }
  22808. if (node.importClause.namedBindings.kind === 222) {
  22809. write("* as ");
  22810. writeTextOfNode(currentSourceFile, node.importClause.namedBindings.name);
  22811. }
  22812. else {
  22813. write("{ ");
  22814. emitCommaList(node.importClause.namedBindings.elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible);
  22815. write(" }");
  22816. }
  22817. }
  22818. write(" from ");
  22819. }
  22820. writeTextOfNode(currentSourceFile, node.moduleSpecifier);
  22821. write(";");
  22822. writer.writeLine();
  22823. }
  22824. function emitImportOrExportSpecifier(node) {
  22825. if (node.propertyName) {
  22826. writeTextOfNode(currentSourceFile, node.propertyName);
  22827. write(" as ");
  22828. }
  22829. writeTextOfNode(currentSourceFile, node.name);
  22830. }
  22831. function emitExportSpecifier(node) {
  22832. emitImportOrExportSpecifier(node);
  22833. var nodes = resolver.collectLinkedAliases(node.propertyName || node.name);
  22834. writeAsynchronousModuleElements(nodes);
  22835. }
  22836. function emitExportDeclaration(node) {
  22837. emitJsDocComments(node);
  22838. write("export ");
  22839. if (node.exportClause) {
  22840. write("{ ");
  22841. emitCommaList(node.exportClause.elements, emitExportSpecifier);
  22842. write(" }");
  22843. }
  22844. else {
  22845. write("*");
  22846. }
  22847. if (node.moduleSpecifier) {
  22848. write(" from ");
  22849. writeTextOfNode(currentSourceFile, node.moduleSpecifier);
  22850. }
  22851. write(";");
  22852. writer.writeLine();
  22853. }
  22854. function writeModuleDeclaration(node) {
  22855. emitJsDocComments(node);
  22856. emitModuleElementDeclarationFlags(node);
  22857. if (node.flags & 131072) {
  22858. write("namespace ");
  22859. }
  22860. else {
  22861. write("module ");
  22862. }
  22863. writeTextOfNode(currentSourceFile, node.name);
  22864. while (node.body.kind !== 217) {
  22865. node = node.body;
  22866. write(".");
  22867. writeTextOfNode(currentSourceFile, node.name);
  22868. }
  22869. var prevEnclosingDeclaration = enclosingDeclaration;
  22870. enclosingDeclaration = node;
  22871. write(" {");
  22872. writeLine();
  22873. increaseIndent();
  22874. emitLines(node.body.statements);
  22875. decreaseIndent();
  22876. write("}");
  22877. writeLine();
  22878. enclosingDeclaration = prevEnclosingDeclaration;
  22879. }
  22880. function writeTypeAliasDeclaration(node) {
  22881. var prevEnclosingDeclaration = enclosingDeclaration;
  22882. enclosingDeclaration = node;
  22883. emitJsDocComments(node);
  22884. emitModuleElementDeclarationFlags(node);
  22885. write("type ");
  22886. writeTextOfNode(currentSourceFile, node.name);
  22887. emitTypeParameters(node.typeParameters);
  22888. write(" = ");
  22889. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError);
  22890. write(";");
  22891. writeLine();
  22892. enclosingDeclaration = prevEnclosingDeclaration;
  22893. function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
  22894. return {
  22895. diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
  22896. errorNode: node.type,
  22897. typeName: node.name
  22898. };
  22899. }
  22900. }
  22901. function writeEnumDeclaration(node) {
  22902. emitJsDocComments(node);
  22903. emitModuleElementDeclarationFlags(node);
  22904. if (ts.isConst(node)) {
  22905. write("const ");
  22906. }
  22907. write("enum ");
  22908. writeTextOfNode(currentSourceFile, node.name);
  22909. write(" {");
  22910. writeLine();
  22911. increaseIndent();
  22912. emitLines(node.members);
  22913. decreaseIndent();
  22914. write("}");
  22915. writeLine();
  22916. }
  22917. function emitEnumMemberDeclaration(node) {
  22918. emitJsDocComments(node);
  22919. writeTextOfNode(currentSourceFile, node.name);
  22920. var enumMemberValue = resolver.getConstantValue(node);
  22921. if (enumMemberValue !== undefined) {
  22922. write(" = ");
  22923. write(enumMemberValue.toString());
  22924. }
  22925. write(",");
  22926. writeLine();
  22927. }
  22928. function isPrivateMethodTypeParameter(node) {
  22929. return node.parent.kind === 141 && (node.parent.flags & 32);
  22930. }
  22931. function emitTypeParameters(typeParameters) {
  22932. function emitTypeParameter(node) {
  22933. increaseIndent();
  22934. emitJsDocComments(node);
  22935. decreaseIndent();
  22936. writeTextOfNode(currentSourceFile, node.name);
  22937. if (node.constraint && !isPrivateMethodTypeParameter(node)) {
  22938. write(" extends ");
  22939. if (node.parent.kind === 150 ||
  22940. node.parent.kind === 151 ||
  22941. (node.parent.parent && node.parent.parent.kind === 153)) {
  22942. ts.Debug.assert(node.parent.kind === 141 ||
  22943. node.parent.kind === 140 ||
  22944. node.parent.kind === 150 ||
  22945. node.parent.kind === 151 ||
  22946. node.parent.kind === 145 ||
  22947. node.parent.kind === 146);
  22948. emitType(node.constraint);
  22949. }
  22950. else {
  22951. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError);
  22952. }
  22953. }
  22954. function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
  22955. var diagnosticMessage;
  22956. switch (node.parent.kind) {
  22957. case 212:
  22958. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
  22959. break;
  22960. case 213:
  22961. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
  22962. break;
  22963. case 146:
  22964. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
  22965. break;
  22966. case 145:
  22967. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
  22968. break;
  22969. case 141:
  22970. case 140:
  22971. if (node.parent.flags & 128) {
  22972. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
  22973. }
  22974. else if (node.parent.parent.kind === 212) {
  22975. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
  22976. }
  22977. else {
  22978. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
  22979. }
  22980. break;
  22981. case 211:
  22982. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
  22983. break;
  22984. default:
  22985. ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
  22986. }
  22987. return {
  22988. diagnosticMessage: diagnosticMessage,
  22989. errorNode: node,
  22990. typeName: node.name
  22991. };
  22992. }
  22993. }
  22994. if (typeParameters) {
  22995. write("<");
  22996. emitCommaList(typeParameters, emitTypeParameter);
  22997. write(">");
  22998. }
  22999. }
  23000. function emitHeritageClause(typeReferences, isImplementsList) {
  23001. if (typeReferences) {
  23002. write(isImplementsList ? " implements " : " extends ");
  23003. emitCommaList(typeReferences, emitTypeOfTypeReference);
  23004. }
  23005. function emitTypeOfTypeReference(node) {
  23006. if (ts.isSupportedExpressionWithTypeArguments(node)) {
  23007. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError);
  23008. }
  23009. else if (!isImplementsList && node.expression.kind === 91) {
  23010. write("null");
  23011. }
  23012. function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
  23013. var diagnosticMessage;
  23014. if (node.parent.parent.kind === 212) {
  23015. diagnosticMessage = isImplementsList ?
  23016. ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
  23017. ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
  23018. }
  23019. else {
  23020. diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
  23021. }
  23022. return {
  23023. diagnosticMessage: diagnosticMessage,
  23024. errorNode: node,
  23025. typeName: node.parent.parent.name
  23026. };
  23027. }
  23028. }
  23029. }
  23030. function writeClassDeclaration(node) {
  23031. function emitParameterProperties(constructorDeclaration) {
  23032. if (constructorDeclaration) {
  23033. ts.forEach(constructorDeclaration.parameters, function (param) {
  23034. if (param.flags & 112) {
  23035. emitPropertyDeclaration(param);
  23036. }
  23037. });
  23038. }
  23039. }
  23040. emitJsDocComments(node);
  23041. emitModuleElementDeclarationFlags(node);
  23042. if (node.flags & 256) {
  23043. write("abstract ");
  23044. }
  23045. write("class ");
  23046. writeTextOfNode(currentSourceFile, node.name);
  23047. var prevEnclosingDeclaration = enclosingDeclaration;
  23048. enclosingDeclaration = node;
  23049. emitTypeParameters(node.typeParameters);
  23050. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  23051. if (baseTypeNode) {
  23052. emitHeritageClause([baseTypeNode], false);
  23053. }
  23054. emitHeritageClause(ts.getClassImplementsHeritageClauseElements(node), true);
  23055. write(" {");
  23056. writeLine();
  23057. increaseIndent();
  23058. emitParameterProperties(ts.getFirstConstructorWithBody(node));
  23059. emitLines(node.members);
  23060. decreaseIndent();
  23061. write("}");
  23062. writeLine();
  23063. enclosingDeclaration = prevEnclosingDeclaration;
  23064. }
  23065. function writeInterfaceDeclaration(node) {
  23066. emitJsDocComments(node);
  23067. emitModuleElementDeclarationFlags(node);
  23068. write("interface ");
  23069. writeTextOfNode(currentSourceFile, node.name);
  23070. var prevEnclosingDeclaration = enclosingDeclaration;
  23071. enclosingDeclaration = node;
  23072. emitTypeParameters(node.typeParameters);
  23073. emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), false);
  23074. write(" {");
  23075. writeLine();
  23076. increaseIndent();
  23077. emitLines(node.members);
  23078. decreaseIndent();
  23079. write("}");
  23080. writeLine();
  23081. enclosingDeclaration = prevEnclosingDeclaration;
  23082. }
  23083. function emitPropertyDeclaration(node) {
  23084. if (ts.hasDynamicName(node)) {
  23085. return;
  23086. }
  23087. emitJsDocComments(node);
  23088. emitClassMemberDeclarationFlags(node);
  23089. emitVariableDeclaration(node);
  23090. write(";");
  23091. writeLine();
  23092. }
  23093. function emitVariableDeclaration(node) {
  23094. if (node.kind !== 209 || resolver.isDeclarationVisible(node)) {
  23095. if (ts.isBindingPattern(node.name)) {
  23096. emitBindingPattern(node.name);
  23097. }
  23098. else {
  23099. writeTextOfNode(currentSourceFile, node.name);
  23100. if ((node.kind === 139 || node.kind === 138) && ts.hasQuestionToken(node)) {
  23101. write("?");
  23102. }
  23103. if ((node.kind === 139 || node.kind === 138) && node.parent.kind === 153) {
  23104. emitTypeOfVariableDeclarationFromTypeLiteral(node);
  23105. }
  23106. else if (!(node.flags & 32)) {
  23107. writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError);
  23108. }
  23109. }
  23110. }
  23111. function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
  23112. if (node.kind === 209) {
  23113. return symbolAccesibilityResult.errorModuleName ?
  23114. symbolAccesibilityResult.accessibility === 2 ?
  23115. ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23116. ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
  23117. ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
  23118. }
  23119. else if (node.kind === 139 || node.kind === 138) {
  23120. if (node.flags & 128) {
  23121. return symbolAccesibilityResult.errorModuleName ?
  23122. symbolAccesibilityResult.accessibility === 2 ?
  23123. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23124. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23125. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
  23126. }
  23127. else if (node.parent.kind === 212) {
  23128. return symbolAccesibilityResult.errorModuleName ?
  23129. symbolAccesibilityResult.accessibility === 2 ?
  23130. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23131. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23132. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
  23133. }
  23134. else {
  23135. return symbolAccesibilityResult.errorModuleName ?
  23136. ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23137. ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
  23138. }
  23139. }
  23140. }
  23141. function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  23142. var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23143. return diagnosticMessage !== undefined ? {
  23144. diagnosticMessage: diagnosticMessage,
  23145. errorNode: node,
  23146. typeName: node.name
  23147. } : undefined;
  23148. }
  23149. function emitBindingPattern(bindingPattern) {
  23150. var elements = [];
  23151. for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) {
  23152. var element = _a[_i];
  23153. if (element.kind !== 185) {
  23154. elements.push(element);
  23155. }
  23156. }
  23157. emitCommaList(elements, emitBindingElement);
  23158. }
  23159. function emitBindingElement(bindingElement) {
  23160. function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
  23161. var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23162. return diagnosticMessage !== undefined ? {
  23163. diagnosticMessage: diagnosticMessage,
  23164. errorNode: bindingElement,
  23165. typeName: bindingElement.name
  23166. } : undefined;
  23167. }
  23168. if (bindingElement.name) {
  23169. if (ts.isBindingPattern(bindingElement.name)) {
  23170. emitBindingPattern(bindingElement.name);
  23171. }
  23172. else {
  23173. writeTextOfNode(currentSourceFile, bindingElement.name);
  23174. writeTypeOfDeclaration(bindingElement, undefined, getBindingElementTypeVisibilityError);
  23175. }
  23176. }
  23177. }
  23178. }
  23179. function emitTypeOfVariableDeclarationFromTypeLiteral(node) {
  23180. if (node.type) {
  23181. write(": ");
  23182. emitType(node.type);
  23183. }
  23184. }
  23185. function isVariableStatementVisible(node) {
  23186. return ts.forEach(node.declarationList.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
  23187. }
  23188. function writeVariableStatement(node) {
  23189. emitJsDocComments(node);
  23190. emitModuleElementDeclarationFlags(node);
  23191. if (ts.isLet(node.declarationList)) {
  23192. write("let ");
  23193. }
  23194. else if (ts.isConst(node.declarationList)) {
  23195. write("const ");
  23196. }
  23197. else {
  23198. write("var ");
  23199. }
  23200. emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible);
  23201. write(";");
  23202. writeLine();
  23203. }
  23204. function emitAccessorDeclaration(node) {
  23205. if (ts.hasDynamicName(node)) {
  23206. return;
  23207. }
  23208. var accessors = ts.getAllAccessorDeclarations(node.parent.members, node);
  23209. var accessorWithTypeAnnotation;
  23210. if (node === accessors.firstAccessor) {
  23211. emitJsDocComments(accessors.getAccessor);
  23212. emitJsDocComments(accessors.setAccessor);
  23213. emitClassMemberDeclarationFlags(node);
  23214. writeTextOfNode(currentSourceFile, node.name);
  23215. if (!(node.flags & 32)) {
  23216. accessorWithTypeAnnotation = node;
  23217. var type = getTypeAnnotationFromAccessor(node);
  23218. if (!type) {
  23219. var anotherAccessor = node.kind === 143 ? accessors.setAccessor : accessors.getAccessor;
  23220. type = getTypeAnnotationFromAccessor(anotherAccessor);
  23221. if (type) {
  23222. accessorWithTypeAnnotation = anotherAccessor;
  23223. }
  23224. }
  23225. writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError);
  23226. }
  23227. write(";");
  23228. writeLine();
  23229. }
  23230. function getTypeAnnotationFromAccessor(accessor) {
  23231. if (accessor) {
  23232. return accessor.kind === 143
  23233. ? accessor.type
  23234. : accessor.parameters.length > 0
  23235. ? accessor.parameters[0].type
  23236. : undefined;
  23237. }
  23238. }
  23239. function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  23240. var diagnosticMessage;
  23241. if (accessorWithTypeAnnotation.kind === 144) {
  23242. if (accessorWithTypeAnnotation.parent.flags & 128) {
  23243. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23244. ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23245. ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
  23246. }
  23247. else {
  23248. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23249. ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23250. ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
  23251. }
  23252. return {
  23253. diagnosticMessage: diagnosticMessage,
  23254. errorNode: accessorWithTypeAnnotation.parameters[0],
  23255. typeName: accessorWithTypeAnnotation.name
  23256. };
  23257. }
  23258. else {
  23259. if (accessorWithTypeAnnotation.flags & 128) {
  23260. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23261. symbolAccesibilityResult.accessibility === 2 ?
  23262. 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 :
  23263. ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23264. ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
  23265. }
  23266. else {
  23267. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23268. symbolAccesibilityResult.accessibility === 2 ?
  23269. 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 :
  23270. ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23271. ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
  23272. }
  23273. return {
  23274. diagnosticMessage: diagnosticMessage,
  23275. errorNode: accessorWithTypeAnnotation.name,
  23276. typeName: undefined
  23277. };
  23278. }
  23279. }
  23280. }
  23281. function writeFunctionDeclaration(node) {
  23282. if (ts.hasDynamicName(node)) {
  23283. return;
  23284. }
  23285. if (!resolver.isImplementationOfOverload(node)) {
  23286. emitJsDocComments(node);
  23287. if (node.kind === 211) {
  23288. emitModuleElementDeclarationFlags(node);
  23289. }
  23290. else if (node.kind === 141) {
  23291. emitClassMemberDeclarationFlags(node);
  23292. }
  23293. if (node.kind === 211) {
  23294. write("function ");
  23295. writeTextOfNode(currentSourceFile, node.name);
  23296. }
  23297. else if (node.kind === 142) {
  23298. write("constructor");
  23299. }
  23300. else {
  23301. writeTextOfNode(currentSourceFile, node.name);
  23302. if (ts.hasQuestionToken(node)) {
  23303. write("?");
  23304. }
  23305. }
  23306. emitSignatureDeclaration(node);
  23307. }
  23308. }
  23309. function emitSignatureDeclarationWithJsDocComments(node) {
  23310. emitJsDocComments(node);
  23311. emitSignatureDeclaration(node);
  23312. }
  23313. function emitSignatureDeclaration(node) {
  23314. if (node.kind === 146 || node.kind === 151) {
  23315. write("new ");
  23316. }
  23317. emitTypeParameters(node.typeParameters);
  23318. if (node.kind === 147) {
  23319. write("[");
  23320. }
  23321. else {
  23322. write("(");
  23323. }
  23324. var prevEnclosingDeclaration = enclosingDeclaration;
  23325. enclosingDeclaration = node;
  23326. emitCommaList(node.parameters, emitParameterDeclaration);
  23327. if (node.kind === 147) {
  23328. write("]");
  23329. }
  23330. else {
  23331. write(")");
  23332. }
  23333. var isFunctionTypeOrConstructorType = node.kind === 150 || node.kind === 151;
  23334. if (isFunctionTypeOrConstructorType || node.parent.kind === 153) {
  23335. if (node.type) {
  23336. write(isFunctionTypeOrConstructorType ? " => " : ": ");
  23337. emitType(node.type);
  23338. }
  23339. }
  23340. else if (node.kind !== 142 && !(node.flags & 32)) {
  23341. writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
  23342. }
  23343. enclosingDeclaration = prevEnclosingDeclaration;
  23344. if (!isFunctionTypeOrConstructorType) {
  23345. write(";");
  23346. writeLine();
  23347. }
  23348. function getReturnTypeVisibilityError(symbolAccesibilityResult) {
  23349. var diagnosticMessage;
  23350. switch (node.kind) {
  23351. case 146:
  23352. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23353. ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23354. ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
  23355. break;
  23356. case 145:
  23357. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23358. ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23359. ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
  23360. break;
  23361. case 147:
  23362. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23363. ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23364. ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
  23365. break;
  23366. case 141:
  23367. case 140:
  23368. if (node.flags & 128) {
  23369. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23370. symbolAccesibilityResult.accessibility === 2 ?
  23371. 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 :
  23372. ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23373. ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
  23374. }
  23375. else if (node.parent.kind === 212) {
  23376. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23377. symbolAccesibilityResult.accessibility === 2 ?
  23378. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  23379. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  23380. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
  23381. }
  23382. else {
  23383. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23384. ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  23385. ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
  23386. }
  23387. break;
  23388. case 211:
  23389. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  23390. symbolAccesibilityResult.accessibility === 2 ?
  23391. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  23392. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 :
  23393. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
  23394. break;
  23395. default:
  23396. ts.Debug.fail("This is unknown kind for signature: " + node.kind);
  23397. }
  23398. return {
  23399. diagnosticMessage: diagnosticMessage,
  23400. errorNode: node.name || node
  23401. };
  23402. }
  23403. }
  23404. function emitParameterDeclaration(node) {
  23405. increaseIndent();
  23406. emitJsDocComments(node);
  23407. if (node.dotDotDotToken) {
  23408. write("...");
  23409. }
  23410. if (ts.isBindingPattern(node.name)) {
  23411. emitBindingPattern(node.name);
  23412. }
  23413. else {
  23414. writeTextOfNode(currentSourceFile, node.name);
  23415. }
  23416. if (resolver.isOptionalParameter(node)) {
  23417. write("?");
  23418. }
  23419. decreaseIndent();
  23420. if (node.parent.kind === 150 ||
  23421. node.parent.kind === 151 ||
  23422. node.parent.parent.kind === 153) {
  23423. emitTypeOfVariableDeclarationFromTypeLiteral(node);
  23424. }
  23425. else if (!(node.parent.flags & 32)) {
  23426. writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError);
  23427. }
  23428. function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  23429. var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23430. return diagnosticMessage !== undefined ? {
  23431. diagnosticMessage: diagnosticMessage,
  23432. errorNode: node,
  23433. typeName: node.name
  23434. } : undefined;
  23435. }
  23436. function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
  23437. switch (node.parent.kind) {
  23438. case 142:
  23439. return symbolAccesibilityResult.errorModuleName ?
  23440. symbolAccesibilityResult.accessibility === 2 ?
  23441. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23442. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23443. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
  23444. case 146:
  23445. return symbolAccesibilityResult.errorModuleName ?
  23446. ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23447. ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
  23448. case 145:
  23449. return symbolAccesibilityResult.errorModuleName ?
  23450. ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23451. ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
  23452. case 141:
  23453. case 140:
  23454. if (node.parent.flags & 128) {
  23455. return symbolAccesibilityResult.errorModuleName ?
  23456. symbolAccesibilityResult.accessibility === 2 ?
  23457. 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 :
  23458. ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23459. ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
  23460. }
  23461. else if (node.parent.parent.kind === 212) {
  23462. return symbolAccesibilityResult.errorModuleName ?
  23463. symbolAccesibilityResult.accessibility === 2 ?
  23464. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23465. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  23466. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
  23467. }
  23468. else {
  23469. return symbolAccesibilityResult.errorModuleName ?
  23470. ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  23471. ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
  23472. }
  23473. case 211:
  23474. return symbolAccesibilityResult.errorModuleName ?
  23475. symbolAccesibilityResult.accessibility === 2 ?
  23476. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  23477. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
  23478. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
  23479. default:
  23480. ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
  23481. }
  23482. }
  23483. function emitBindingPattern(bindingPattern) {
  23484. if (bindingPattern.kind === 159) {
  23485. write("{");
  23486. emitCommaList(bindingPattern.elements, emitBindingElement);
  23487. write("}");
  23488. }
  23489. else if (bindingPattern.kind === 160) {
  23490. write("[");
  23491. var elements = bindingPattern.elements;
  23492. emitCommaList(elements, emitBindingElement);
  23493. if (elements && elements.hasTrailingComma) {
  23494. write(", ");
  23495. }
  23496. write("]");
  23497. }
  23498. }
  23499. function emitBindingElement(bindingElement) {
  23500. function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
  23501. var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  23502. return diagnosticMessage !== undefined ? {
  23503. diagnosticMessage: diagnosticMessage,
  23504. errorNode: bindingElement,
  23505. typeName: bindingElement.name
  23506. } : undefined;
  23507. }
  23508. if (bindingElement.kind === 185) {
  23509. write(" ");
  23510. }
  23511. else if (bindingElement.kind === 161) {
  23512. if (bindingElement.propertyName) {
  23513. writeTextOfNode(currentSourceFile, bindingElement.propertyName);
  23514. write(": ");
  23515. }
  23516. if (bindingElement.name) {
  23517. if (ts.isBindingPattern(bindingElement.name)) {
  23518. emitBindingPattern(bindingElement.name);
  23519. }
  23520. else {
  23521. ts.Debug.assert(bindingElement.name.kind === 67);
  23522. if (bindingElement.dotDotDotToken) {
  23523. write("...");
  23524. }
  23525. writeTextOfNode(currentSourceFile, bindingElement.name);
  23526. }
  23527. }
  23528. }
  23529. }
  23530. }
  23531. function emitNode(node) {
  23532. switch (node.kind) {
  23533. case 211:
  23534. case 216:
  23535. case 219:
  23536. case 213:
  23537. case 212:
  23538. case 214:
  23539. case 215:
  23540. return emitModuleElement(node, isModuleElementVisible(node));
  23541. case 191:
  23542. return emitModuleElement(node, isVariableStatementVisible(node));
  23543. case 220:
  23544. return emitModuleElement(node, !node.importClause);
  23545. case 226:
  23546. return emitExportDeclaration(node);
  23547. case 142:
  23548. case 141:
  23549. case 140:
  23550. return writeFunctionDeclaration(node);
  23551. case 146:
  23552. case 145:
  23553. case 147:
  23554. return emitSignatureDeclarationWithJsDocComments(node);
  23555. case 143:
  23556. case 144:
  23557. return emitAccessorDeclaration(node);
  23558. case 139:
  23559. case 138:
  23560. return emitPropertyDeclaration(node);
  23561. case 245:
  23562. return emitEnumMemberDeclaration(node);
  23563. case 225:
  23564. return emitExportAssignment(node);
  23565. case 246:
  23566. return emitSourceFile(node);
  23567. }
  23568. }
  23569. function writeReferencePath(referencedFile) {
  23570. var declFileName = referencedFile.flags & 8192
  23571. ? referencedFile.fileName
  23572. : ts.shouldEmitToOwnFile(referencedFile, compilerOptions)
  23573. ? ts.getOwnEmitOutputFilePath(referencedFile, host, ".d.ts")
  23574. : ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts";
  23575. declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false);
  23576. referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
  23577. }
  23578. }
  23579. function writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics) {
  23580. var emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile);
  23581. if (!emitDeclarationResult.reportedDeclarationError) {
  23582. var declarationOutput = emitDeclarationResult.referencePathsOutput
  23583. + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo);
  23584. ts.writeFile(host, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, host.getCompilerOptions().emitBOM);
  23585. }
  23586. function getDeclarationOutput(synchronousDeclarationOutput, moduleElementDeclarationEmitInfo) {
  23587. var appliedSyncOutputPos = 0;
  23588. var declarationOutput = "";
  23589. ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
  23590. if (aliasEmitInfo.asynchronousOutput) {
  23591. declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos);
  23592. declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo);
  23593. appliedSyncOutputPos = aliasEmitInfo.outputPos;
  23594. }
  23595. });
  23596. declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos);
  23597. return declarationOutput;
  23598. }
  23599. }
  23600. ts.writeDeclarationFile = writeDeclarationFile;
  23601. })(ts || (ts = {}));
  23602. /// <reference path="checker.ts"/>
  23603. /// <reference path="declarationEmitter.ts"/>
  23604. var ts;
  23605. (function (ts) {
  23606. function isExternalModuleOrDeclarationFile(sourceFile) {
  23607. return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile);
  23608. }
  23609. ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile;
  23610. function emitFiles(resolver, host, targetSourceFile) {
  23611. 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};";
  23612. var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};";
  23613. 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};";
  23614. var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};";
  23615. 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};";
  23616. var compilerOptions = host.getCompilerOptions();
  23617. var languageVersion = compilerOptions.target || 0;
  23618. var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined;
  23619. var diagnostics = [];
  23620. var newLine = host.getNewLine();
  23621. var jsxDesugaring = host.getCompilerOptions().jsx !== 1;
  23622. var shouldEmitJsx = function (s) { return (s.languageVariant === 1 && !jsxDesugaring); };
  23623. if (targetSourceFile === undefined) {
  23624. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  23625. if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) {
  23626. var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js");
  23627. emitFile(jsFilePath, sourceFile);
  23628. }
  23629. });
  23630. if (compilerOptions.outFile || compilerOptions.out) {
  23631. emitFile(compilerOptions.outFile || compilerOptions.out);
  23632. }
  23633. }
  23634. else {
  23635. if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
  23636. var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js");
  23637. emitFile(jsFilePath, targetSourceFile);
  23638. }
  23639. else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) {
  23640. emitFile(compilerOptions.outFile || compilerOptions.out);
  23641. }
  23642. }
  23643. diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics);
  23644. return {
  23645. emitSkipped: false,
  23646. diagnostics: diagnostics,
  23647. sourceMaps: sourceMapDataList
  23648. };
  23649. function isNodeDescendentOf(node, ancestor) {
  23650. while (node) {
  23651. if (node === ancestor)
  23652. return true;
  23653. node = node.parent;
  23654. }
  23655. return false;
  23656. }
  23657. function isUniqueLocalName(name, container) {
  23658. for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) {
  23659. if (node.locals && ts.hasProperty(node.locals, name)) {
  23660. if (node.locals[name].flags & (107455 | 1048576 | 8388608)) {
  23661. return false;
  23662. }
  23663. }
  23664. }
  23665. return true;
  23666. }
  23667. function emitJavaScript(jsFilePath, root) {
  23668. var writer = ts.createTextWriter(newLine);
  23669. var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent;
  23670. var currentSourceFile;
  23671. var exportFunctionForFile;
  23672. var generatedNameSet = {};
  23673. var nodeToGeneratedName = [];
  23674. var computedPropertyNamesToGeneratedNames;
  23675. var extendsEmitted = false;
  23676. var decorateEmitted = false;
  23677. var paramEmitted = false;
  23678. var awaiterEmitted = false;
  23679. var tempFlags = 0;
  23680. var tempVariables;
  23681. var tempParameters;
  23682. var externalImports;
  23683. var exportSpecifiers;
  23684. var exportEquals;
  23685. var hasExportStars;
  23686. var writeEmittedFiles = writeJavaScriptFile;
  23687. var detachedCommentsInfo;
  23688. var writeComment = ts.writeCommentRange;
  23689. var emit = emitNodeWithCommentsAndWithoutSourcemap;
  23690. var emitStart = function (node) { };
  23691. var emitEnd = function (node) { };
  23692. var emitToken = emitTokenText;
  23693. var scopeEmitStart = function (scopeDeclaration, scopeName) { };
  23694. var scopeEmitEnd = function () { };
  23695. var sourceMapData;
  23696. if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) {
  23697. initializeEmitterWithSourceMaps();
  23698. }
  23699. if (root) {
  23700. emitSourceFile(root);
  23701. }
  23702. else {
  23703. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  23704. if (!isExternalModuleOrDeclarationFile(sourceFile)) {
  23705. emitSourceFile(sourceFile);
  23706. }
  23707. });
  23708. }
  23709. writeLine();
  23710. writeEmittedFiles(writer.getText(), compilerOptions.emitBOM);
  23711. return;
  23712. function emitSourceFile(sourceFile) {
  23713. currentSourceFile = sourceFile;
  23714. exportFunctionForFile = undefined;
  23715. emit(sourceFile);
  23716. }
  23717. function isUniqueName(name) {
  23718. return !resolver.hasGlobalName(name) &&
  23719. !ts.hasProperty(currentSourceFile.identifiers, name) &&
  23720. !ts.hasProperty(generatedNameSet, name);
  23721. }
  23722. function makeTempVariableName(flags) {
  23723. if (flags && !(tempFlags & flags)) {
  23724. var name_19 = flags === 268435456 ? "_i" : "_n";
  23725. if (isUniqueName(name_19)) {
  23726. tempFlags |= flags;
  23727. return name_19;
  23728. }
  23729. }
  23730. while (true) {
  23731. var count = tempFlags & 268435455;
  23732. tempFlags++;
  23733. if (count !== 8 && count !== 13) {
  23734. var name_20 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26);
  23735. if (isUniqueName(name_20)) {
  23736. return name_20;
  23737. }
  23738. }
  23739. }
  23740. }
  23741. function makeUniqueName(baseName) {
  23742. if (baseName.charCodeAt(baseName.length - 1) !== 95) {
  23743. baseName += "_";
  23744. }
  23745. var i = 1;
  23746. while (true) {
  23747. var generatedName = baseName + i;
  23748. if (isUniqueName(generatedName)) {
  23749. return generatedNameSet[generatedName] = generatedName;
  23750. }
  23751. i++;
  23752. }
  23753. }
  23754. function generateNameForModuleOrEnum(node) {
  23755. var name = node.name.text;
  23756. return isUniqueLocalName(name, node) ? name : makeUniqueName(name);
  23757. }
  23758. function generateNameForImportOrExportDeclaration(node) {
  23759. var expr = ts.getExternalModuleName(node);
  23760. var baseName = expr.kind === 9 ?
  23761. ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module";
  23762. return makeUniqueName(baseName);
  23763. }
  23764. function generateNameForExportDefault() {
  23765. return makeUniqueName("default");
  23766. }
  23767. function generateNameForClassExpression() {
  23768. return makeUniqueName("class");
  23769. }
  23770. function generateNameForNode(node) {
  23771. switch (node.kind) {
  23772. case 67:
  23773. return makeUniqueName(node.text);
  23774. case 216:
  23775. case 215:
  23776. return generateNameForModuleOrEnum(node);
  23777. case 220:
  23778. case 226:
  23779. return generateNameForImportOrExportDeclaration(node);
  23780. case 211:
  23781. case 212:
  23782. case 225:
  23783. return generateNameForExportDefault();
  23784. case 184:
  23785. return generateNameForClassExpression();
  23786. }
  23787. }
  23788. function getGeneratedNameForNode(node) {
  23789. var id = ts.getNodeId(node);
  23790. return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node)));
  23791. }
  23792. function initializeEmitterWithSourceMaps() {
  23793. var sourceMapDir;
  23794. var sourceMapSourceIndex = -1;
  23795. var sourceMapNameIndexMap = {};
  23796. var sourceMapNameIndices = [];
  23797. function getSourceMapNameIndex() {
  23798. return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1;
  23799. }
  23800. var lastRecordedSourceMapSpan;
  23801. var lastEncodedSourceMapSpan = {
  23802. emittedLine: 1,
  23803. emittedColumn: 1,
  23804. sourceLine: 1,
  23805. sourceColumn: 1,
  23806. sourceIndex: 0
  23807. };
  23808. var lastEncodedNameIndex = 0;
  23809. function encodeLastRecordedSourceMapSpan() {
  23810. if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) {
  23811. return;
  23812. }
  23813. var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn;
  23814. if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) {
  23815. if (sourceMapData.sourceMapMappings) {
  23816. sourceMapData.sourceMapMappings += ",";
  23817. }
  23818. }
  23819. else {
  23820. for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) {
  23821. sourceMapData.sourceMapMappings += ";";
  23822. }
  23823. prevEncodedEmittedColumn = 1;
  23824. }
  23825. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn);
  23826. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex);
  23827. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine);
  23828. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn);
  23829. if (lastRecordedSourceMapSpan.nameIndex >= 0) {
  23830. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex);
  23831. lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex;
  23832. }
  23833. lastEncodedSourceMapSpan = lastRecordedSourceMapSpan;
  23834. sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan);
  23835. function base64VLQFormatEncode(inValue) {
  23836. function base64FormatEncode(inValue) {
  23837. if (inValue < 64) {
  23838. return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue);
  23839. }
  23840. throw TypeError(inValue + ": not a 64 based value");
  23841. }
  23842. if (inValue < 0) {
  23843. inValue = ((-inValue) << 1) + 1;
  23844. }
  23845. else {
  23846. inValue = inValue << 1;
  23847. }
  23848. var encodedStr = "";
  23849. do {
  23850. var currentDigit = inValue & 31;
  23851. inValue = inValue >> 5;
  23852. if (inValue > 0) {
  23853. currentDigit = currentDigit | 32;
  23854. }
  23855. encodedStr = encodedStr + base64FormatEncode(currentDigit);
  23856. } while (inValue > 0);
  23857. return encodedStr;
  23858. }
  23859. }
  23860. function recordSourceMapSpan(pos) {
  23861. var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos);
  23862. sourceLinePos.line++;
  23863. sourceLinePos.character++;
  23864. var emittedLine = writer.getLine();
  23865. var emittedColumn = writer.getColumn();
  23866. if (!lastRecordedSourceMapSpan ||
  23867. lastRecordedSourceMapSpan.emittedLine !== emittedLine ||
  23868. lastRecordedSourceMapSpan.emittedColumn !== emittedColumn ||
  23869. (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex &&
  23870. (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line ||
  23871. (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) {
  23872. encodeLastRecordedSourceMapSpan();
  23873. lastRecordedSourceMapSpan = {
  23874. emittedLine: emittedLine,
  23875. emittedColumn: emittedColumn,
  23876. sourceLine: sourceLinePos.line,
  23877. sourceColumn: sourceLinePos.character,
  23878. nameIndex: getSourceMapNameIndex(),
  23879. sourceIndex: sourceMapSourceIndex
  23880. };
  23881. }
  23882. else {
  23883. lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line;
  23884. lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character;
  23885. lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex;
  23886. }
  23887. }
  23888. function recordEmitNodeStartSpan(node) {
  23889. recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos));
  23890. }
  23891. function recordEmitNodeEndSpan(node) {
  23892. recordSourceMapSpan(node.end);
  23893. }
  23894. function writeTextWithSpanRecord(tokenKind, startPos, emitFn) {
  23895. var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos);
  23896. recordSourceMapSpan(tokenStartPos);
  23897. var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn);
  23898. recordSourceMapSpan(tokenEndPos);
  23899. return tokenEndPos;
  23900. }
  23901. function recordNewSourceFileStart(node) {
  23902. var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir;
  23903. sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, true));
  23904. sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
  23905. sourceMapData.inputSourceFileNames.push(node.fileName);
  23906. if (compilerOptions.inlineSources) {
  23907. if (!sourceMapData.sourceMapSourcesContent) {
  23908. sourceMapData.sourceMapSourcesContent = [];
  23909. }
  23910. sourceMapData.sourceMapSourcesContent.push(node.text);
  23911. }
  23912. }
  23913. function recordScopeNameOfNode(node, scopeName) {
  23914. function recordScopeNameIndex(scopeNameIndex) {
  23915. sourceMapNameIndices.push(scopeNameIndex);
  23916. }
  23917. function recordScopeNameStart(scopeName) {
  23918. var scopeNameIndex = -1;
  23919. if (scopeName) {
  23920. var parentIndex = getSourceMapNameIndex();
  23921. if (parentIndex !== -1) {
  23922. var name_21 = node.name;
  23923. if (!name_21 || name_21.kind !== 134) {
  23924. scopeName = "." + scopeName;
  23925. }
  23926. scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName;
  23927. }
  23928. scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName);
  23929. if (scopeNameIndex === undefined) {
  23930. scopeNameIndex = sourceMapData.sourceMapNames.length;
  23931. sourceMapData.sourceMapNames.push(scopeName);
  23932. sourceMapNameIndexMap[scopeName] = scopeNameIndex;
  23933. }
  23934. }
  23935. recordScopeNameIndex(scopeNameIndex);
  23936. }
  23937. if (scopeName) {
  23938. recordScopeNameStart(scopeName);
  23939. }
  23940. else if (node.kind === 211 ||
  23941. node.kind === 171 ||
  23942. node.kind === 141 ||
  23943. node.kind === 140 ||
  23944. node.kind === 143 ||
  23945. node.kind === 144 ||
  23946. node.kind === 216 ||
  23947. node.kind === 212 ||
  23948. node.kind === 215) {
  23949. if (node.name) {
  23950. var name_22 = node.name;
  23951. scopeName = name_22.kind === 134
  23952. ? ts.getTextOfNode(name_22)
  23953. : node.name.text;
  23954. }
  23955. recordScopeNameStart(scopeName);
  23956. }
  23957. else {
  23958. recordScopeNameIndex(getSourceMapNameIndex());
  23959. }
  23960. }
  23961. function recordScopeNameEnd() {
  23962. sourceMapNameIndices.pop();
  23963. }
  23964. ;
  23965. function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) {
  23966. recordSourceMapSpan(comment.pos);
  23967. ts.writeCommentRange(currentSourceFile, writer, comment, newLine);
  23968. recordSourceMapSpan(comment.end);
  23969. }
  23970. function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) {
  23971. if (typeof JSON !== "undefined") {
  23972. var map_1 = {
  23973. version: version,
  23974. file: file,
  23975. sourceRoot: sourceRoot,
  23976. sources: sources,
  23977. names: names,
  23978. mappings: mappings
  23979. };
  23980. if (sourcesContent !== undefined) {
  23981. map_1.sourcesContent = sourcesContent;
  23982. }
  23983. return JSON.stringify(map_1);
  23984. }
  23985. 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) + "]" : "") + "}";
  23986. function serializeStringArray(list) {
  23987. var output = "";
  23988. for (var i = 0, n = list.length; i < n; i++) {
  23989. if (i) {
  23990. output += ",";
  23991. }
  23992. output += "\"" + ts.escapeString(list[i]) + "\"";
  23993. }
  23994. return output;
  23995. }
  23996. }
  23997. function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) {
  23998. encodeLastRecordedSourceMapSpan();
  23999. var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent);
  24000. sourceMapDataList.push(sourceMapData);
  24001. var sourceMapUrl;
  24002. if (compilerOptions.inlineSourceMap) {
  24003. var base64SourceMapText = ts.convertToBase64(sourceMapText);
  24004. sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText;
  24005. }
  24006. else {
  24007. ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, false);
  24008. sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL;
  24009. }
  24010. writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark);
  24011. }
  24012. var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath));
  24013. sourceMapData = {
  24014. sourceMapFilePath: jsFilePath + ".map",
  24015. jsSourceMappingURL: sourceMapJsFile + ".map",
  24016. sourceMapFile: sourceMapJsFile,
  24017. sourceMapSourceRoot: compilerOptions.sourceRoot || "",
  24018. sourceMapSources: [],
  24019. inputSourceFileNames: [],
  24020. sourceMapNames: [],
  24021. sourceMapMappings: "",
  24022. sourceMapSourcesContent: undefined,
  24023. sourceMapDecodedMappings: []
  24024. };
  24025. sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot);
  24026. if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47) {
  24027. sourceMapData.sourceMapSourceRoot += ts.directorySeparator;
  24028. }
  24029. if (compilerOptions.mapRoot) {
  24030. sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot);
  24031. if (root) {
  24032. sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir));
  24033. }
  24034. if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) {
  24035. sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir);
  24036. sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true);
  24037. }
  24038. else {
  24039. sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL);
  24040. }
  24041. }
  24042. else {
  24043. sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath));
  24044. }
  24045. function emitNodeWithSourceMap(node) {
  24046. if (node) {
  24047. if (ts.nodeIsSynthesized(node)) {
  24048. return emitNodeWithoutSourceMap(node);
  24049. }
  24050. if (node.kind !== 246) {
  24051. recordEmitNodeStartSpan(node);
  24052. emitNodeWithoutSourceMap(node);
  24053. recordEmitNodeEndSpan(node);
  24054. }
  24055. else {
  24056. recordNewSourceFileStart(node);
  24057. emitNodeWithoutSourceMap(node);
  24058. }
  24059. }
  24060. }
  24061. function emitNodeWithCommentsAndWithSourcemap(node) {
  24062. emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap);
  24063. }
  24064. writeEmittedFiles = writeJavaScriptAndSourceMapFile;
  24065. emit = emitNodeWithCommentsAndWithSourcemap;
  24066. emitStart = recordEmitNodeStartSpan;
  24067. emitEnd = recordEmitNodeEndSpan;
  24068. emitToken = writeTextWithSpanRecord;
  24069. scopeEmitStart = recordScopeNameOfNode;
  24070. scopeEmitEnd = recordScopeNameEnd;
  24071. writeComment = writeCommentRangeWithMap;
  24072. }
  24073. function writeJavaScriptFile(emitOutput, writeByteOrderMark) {
  24074. ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
  24075. }
  24076. function createTempVariable(flags) {
  24077. var result = ts.createSynthesizedNode(67);
  24078. result.text = makeTempVariableName(flags);
  24079. return result;
  24080. }
  24081. function recordTempDeclaration(name) {
  24082. if (!tempVariables) {
  24083. tempVariables = [];
  24084. }
  24085. tempVariables.push(name);
  24086. }
  24087. function createAndRecordTempVariable(flags) {
  24088. var temp = createTempVariable(flags);
  24089. recordTempDeclaration(temp);
  24090. return temp;
  24091. }
  24092. function emitTempDeclarations(newLine) {
  24093. if (tempVariables) {
  24094. if (newLine) {
  24095. writeLine();
  24096. }
  24097. else {
  24098. write(" ");
  24099. }
  24100. write("var ");
  24101. emitCommaList(tempVariables);
  24102. write(";");
  24103. }
  24104. }
  24105. function emitTokenText(tokenKind, startPos, emitFn) {
  24106. var tokenString = ts.tokenToString(tokenKind);
  24107. if (emitFn) {
  24108. emitFn();
  24109. }
  24110. else {
  24111. write(tokenString);
  24112. }
  24113. return startPos + tokenString.length;
  24114. }
  24115. function emitOptional(prefix, node) {
  24116. if (node) {
  24117. write(prefix);
  24118. emit(node);
  24119. }
  24120. }
  24121. function emitParenthesizedIf(node, parenthesized) {
  24122. if (parenthesized) {
  24123. write("(");
  24124. }
  24125. emit(node);
  24126. if (parenthesized) {
  24127. write(")");
  24128. }
  24129. }
  24130. function emitTrailingCommaIfPresent(nodeList) {
  24131. if (nodeList.hasTrailingComma) {
  24132. write(",");
  24133. }
  24134. }
  24135. function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) {
  24136. ts.Debug.assert(nodes.length > 0);
  24137. increaseIndent();
  24138. if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) {
  24139. if (spacesBetweenBraces) {
  24140. write(" ");
  24141. }
  24142. }
  24143. else {
  24144. writeLine();
  24145. }
  24146. for (var i = 0, n = nodes.length; i < n; i++) {
  24147. if (i) {
  24148. if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) {
  24149. write(", ");
  24150. }
  24151. else {
  24152. write(",");
  24153. writeLine();
  24154. }
  24155. }
  24156. emit(nodes[i]);
  24157. }
  24158. if (nodes.hasTrailingComma && allowTrailingComma) {
  24159. write(",");
  24160. }
  24161. decreaseIndent();
  24162. if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) {
  24163. if (spacesBetweenBraces) {
  24164. write(" ");
  24165. }
  24166. }
  24167. else {
  24168. writeLine();
  24169. }
  24170. }
  24171. function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) {
  24172. if (!emitNode) {
  24173. emitNode = emit;
  24174. }
  24175. for (var i = 0; i < count; i++) {
  24176. if (multiLine) {
  24177. if (i || leadingComma) {
  24178. write(",");
  24179. }
  24180. writeLine();
  24181. }
  24182. else {
  24183. if (i || leadingComma) {
  24184. write(", ");
  24185. }
  24186. }
  24187. var node = nodes[start + i];
  24188. emitTrailingCommentsOfPosition(node.pos);
  24189. emitNode(node);
  24190. leadingComma = true;
  24191. }
  24192. if (trailingComma) {
  24193. write(",");
  24194. }
  24195. if (multiLine && !noTrailingNewLine) {
  24196. writeLine();
  24197. }
  24198. return count;
  24199. }
  24200. function emitCommaList(nodes) {
  24201. if (nodes) {
  24202. emitList(nodes, 0, nodes.length, false, false);
  24203. }
  24204. }
  24205. function emitLines(nodes) {
  24206. emitLinesStartingAt(nodes, 0);
  24207. }
  24208. function emitLinesStartingAt(nodes, startIndex) {
  24209. for (var i = startIndex; i < nodes.length; i++) {
  24210. writeLine();
  24211. emit(nodes[i]);
  24212. }
  24213. }
  24214. function isBinaryOrOctalIntegerLiteral(node, text) {
  24215. if (node.kind === 8 && text.length > 1) {
  24216. switch (text.charCodeAt(1)) {
  24217. case 98:
  24218. case 66:
  24219. case 111:
  24220. case 79:
  24221. return true;
  24222. }
  24223. }
  24224. return false;
  24225. }
  24226. function emitLiteral(node) {
  24227. var text = getLiteralText(node);
  24228. if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 || ts.isTemplateLiteralKind(node.kind))) {
  24229. writer.writeLiteral(text);
  24230. }
  24231. else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) {
  24232. write(node.text);
  24233. }
  24234. else {
  24235. write(text);
  24236. }
  24237. }
  24238. function getLiteralText(node) {
  24239. if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) {
  24240. return getQuotedEscapedLiteralText("\"", node.text, "\"");
  24241. }
  24242. if (node.parent) {
  24243. return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
  24244. }
  24245. switch (node.kind) {
  24246. case 9:
  24247. return getQuotedEscapedLiteralText("\"", node.text, "\"");
  24248. case 11:
  24249. return getQuotedEscapedLiteralText("`", node.text, "`");
  24250. case 12:
  24251. return getQuotedEscapedLiteralText("`", node.text, "${");
  24252. case 13:
  24253. return getQuotedEscapedLiteralText("}", node.text, "${");
  24254. case 14:
  24255. return getQuotedEscapedLiteralText("}", node.text, "`");
  24256. case 8:
  24257. return node.text;
  24258. }
  24259. ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for.");
  24260. }
  24261. function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) {
  24262. return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote;
  24263. }
  24264. function emitDownlevelRawTemplateLiteral(node) {
  24265. var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
  24266. var isLast = node.kind === 11 || node.kind === 14;
  24267. text = text.substring(1, text.length - (isLast ? 1 : 2));
  24268. text = text.replace(/\r\n?/g, "\n");
  24269. text = ts.escapeString(text);
  24270. write("\"" + text + "\"");
  24271. }
  24272. function emitDownlevelTaggedTemplateArray(node, literalEmitter) {
  24273. write("[");
  24274. if (node.template.kind === 11) {
  24275. literalEmitter(node.template);
  24276. }
  24277. else {
  24278. literalEmitter(node.template.head);
  24279. ts.forEach(node.template.templateSpans, function (child) {
  24280. write(", ");
  24281. literalEmitter(child.literal);
  24282. });
  24283. }
  24284. write("]");
  24285. }
  24286. function emitDownlevelTaggedTemplate(node) {
  24287. var tempVariable = createAndRecordTempVariable(0);
  24288. write("(");
  24289. emit(tempVariable);
  24290. write(" = ");
  24291. emitDownlevelTaggedTemplateArray(node, emit);
  24292. write(", ");
  24293. emit(tempVariable);
  24294. write(".raw = ");
  24295. emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral);
  24296. write(", ");
  24297. emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag));
  24298. write("(");
  24299. emit(tempVariable);
  24300. if (node.template.kind === 181) {
  24301. ts.forEach(node.template.templateSpans, function (templateSpan) {
  24302. write(", ");
  24303. var needsParens = templateSpan.expression.kind === 179
  24304. && templateSpan.expression.operatorToken.kind === 24;
  24305. emitParenthesizedIf(templateSpan.expression, needsParens);
  24306. });
  24307. }
  24308. write("))");
  24309. }
  24310. function emitTemplateExpression(node) {
  24311. if (languageVersion >= 2) {
  24312. ts.forEachChild(node, emit);
  24313. return;
  24314. }
  24315. var emitOuterParens = ts.isExpression(node.parent)
  24316. && templateNeedsParens(node, node.parent);
  24317. if (emitOuterParens) {
  24318. write("(");
  24319. }
  24320. var headEmitted = false;
  24321. if (shouldEmitTemplateHead()) {
  24322. emitLiteral(node.head);
  24323. headEmitted = true;
  24324. }
  24325. for (var i = 0, n = node.templateSpans.length; i < n; i++) {
  24326. var templateSpan = node.templateSpans[i];
  24327. var needsParens = templateSpan.expression.kind !== 170
  24328. && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1;
  24329. if (i > 0 || headEmitted) {
  24330. write(" + ");
  24331. }
  24332. emitParenthesizedIf(templateSpan.expression, needsParens);
  24333. if (templateSpan.literal.text.length !== 0) {
  24334. write(" + ");
  24335. emitLiteral(templateSpan.literal);
  24336. }
  24337. }
  24338. if (emitOuterParens) {
  24339. write(")");
  24340. }
  24341. function shouldEmitTemplateHead() {
  24342. // If this expression has an empty head literal and the first template span has a non-empty
  24343. // literal, then emitting the empty head literal is not necessary.
  24344. // `${ foo } and ${ bar }`
  24345. // can be emitted as
  24346. // foo + " and " + bar
  24347. // This is because it is only required that one of the first two operands in the emit
  24348. // output must be a string literal, so that the other operand and all following operands
  24349. // are forced into strings.
  24350. //
  24351. // If the first template span has an empty literal, then the head must still be emitted.
  24352. // `${ foo }${ bar }`
  24353. // must still be emitted as
  24354. // "" + foo + bar
  24355. ts.Debug.assert(node.templateSpans.length !== 0);
  24356. return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0;
  24357. }
  24358. function templateNeedsParens(template, parent) {
  24359. switch (parent.kind) {
  24360. case 166:
  24361. case 167:
  24362. return parent.expression === template;
  24363. case 168:
  24364. case 170:
  24365. return false;
  24366. default:
  24367. return comparePrecedenceToBinaryPlus(parent) !== -1;
  24368. }
  24369. }
  24370. function comparePrecedenceToBinaryPlus(expression) {
  24371. switch (expression.kind) {
  24372. case 179:
  24373. switch (expression.operatorToken.kind) {
  24374. case 37:
  24375. case 38:
  24376. case 39:
  24377. return 1;
  24378. case 35:
  24379. case 36:
  24380. return 0;
  24381. default:
  24382. return -1;
  24383. }
  24384. case 182:
  24385. case 180:
  24386. return -1;
  24387. default:
  24388. return 1;
  24389. }
  24390. }
  24391. }
  24392. function emitTemplateSpan(span) {
  24393. emit(span.expression);
  24394. emit(span.literal);
  24395. }
  24396. function jsxEmitReact(node) {
  24397. function emitTagName(name) {
  24398. if (name.kind === 67 && ts.isIntrinsicJsxName(name.text)) {
  24399. write("\"");
  24400. emit(name);
  24401. write("\"");
  24402. }
  24403. else {
  24404. emit(name);
  24405. }
  24406. }
  24407. function emitAttributeName(name) {
  24408. if (/[A-Za-z_]+[\w*]/.test(name.text)) {
  24409. write("\"");
  24410. emit(name);
  24411. write("\"");
  24412. }
  24413. else {
  24414. emit(name);
  24415. }
  24416. }
  24417. function emitJsxAttribute(node) {
  24418. emitAttributeName(node.name);
  24419. write(": ");
  24420. if (node.initializer) {
  24421. emit(node.initializer);
  24422. }
  24423. else {
  24424. write("true");
  24425. }
  24426. }
  24427. function emitJsxElement(openingNode, children) {
  24428. var syntheticReactRef = ts.createSynthesizedNode(67);
  24429. syntheticReactRef.text = 'React';
  24430. syntheticReactRef.parent = openingNode;
  24431. emitLeadingComments(openingNode);
  24432. emitExpressionIdentifier(syntheticReactRef);
  24433. write(".createElement(");
  24434. emitTagName(openingNode.tagName);
  24435. write(", ");
  24436. if (openingNode.attributes.length === 0) {
  24437. write("null");
  24438. }
  24439. else {
  24440. var attrs = openingNode.attributes;
  24441. if (ts.forEach(attrs, function (attr) { return attr.kind === 237; })) {
  24442. emitExpressionIdentifier(syntheticReactRef);
  24443. write(".__spread(");
  24444. var haveOpenedObjectLiteral = false;
  24445. for (var i_1 = 0; i_1 < attrs.length; i_1++) {
  24446. if (attrs[i_1].kind === 237) {
  24447. if (i_1 === 0) {
  24448. write("{}, ");
  24449. }
  24450. if (haveOpenedObjectLiteral) {
  24451. write("}");
  24452. haveOpenedObjectLiteral = false;
  24453. }
  24454. if (i_1 > 0) {
  24455. write(", ");
  24456. }
  24457. emit(attrs[i_1].expression);
  24458. }
  24459. else {
  24460. ts.Debug.assert(attrs[i_1].kind === 236);
  24461. if (haveOpenedObjectLiteral) {
  24462. write(", ");
  24463. }
  24464. else {
  24465. haveOpenedObjectLiteral = true;
  24466. if (i_1 > 0) {
  24467. write(", ");
  24468. }
  24469. write("{");
  24470. }
  24471. emitJsxAttribute(attrs[i_1]);
  24472. }
  24473. }
  24474. if (haveOpenedObjectLiteral)
  24475. write("}");
  24476. write(")");
  24477. }
  24478. else {
  24479. write("{");
  24480. for (var i = 0; i < attrs.length; i++) {
  24481. if (i > 0) {
  24482. write(", ");
  24483. }
  24484. emitJsxAttribute(attrs[i]);
  24485. }
  24486. write("}");
  24487. }
  24488. }
  24489. if (children) {
  24490. for (var i = 0; i < children.length; i++) {
  24491. if (children[i].kind === 238 && !(children[i].expression)) {
  24492. continue;
  24493. }
  24494. if (children[i].kind === 234) {
  24495. var text = getTextToEmit(children[i]);
  24496. if (text !== undefined) {
  24497. write(", \"");
  24498. write(text);
  24499. write("\"");
  24500. }
  24501. }
  24502. else {
  24503. write(", ");
  24504. emit(children[i]);
  24505. }
  24506. }
  24507. }
  24508. write(")");
  24509. emitTrailingComments(openingNode);
  24510. }
  24511. if (node.kind === 231) {
  24512. emitJsxElement(node.openingElement, node.children);
  24513. }
  24514. else {
  24515. ts.Debug.assert(node.kind === 232);
  24516. emitJsxElement(node);
  24517. }
  24518. }
  24519. function jsxEmitPreserve(node) {
  24520. function emitJsxAttribute(node) {
  24521. emit(node.name);
  24522. if (node.initializer) {
  24523. write("=");
  24524. emit(node.initializer);
  24525. }
  24526. }
  24527. function emitJsxSpreadAttribute(node) {
  24528. write("{...");
  24529. emit(node.expression);
  24530. write("}");
  24531. }
  24532. function emitAttributes(attribs) {
  24533. for (var i = 0, n = attribs.length; i < n; i++) {
  24534. if (i > 0) {
  24535. write(" ");
  24536. }
  24537. if (attribs[i].kind === 237) {
  24538. emitJsxSpreadAttribute(attribs[i]);
  24539. }
  24540. else {
  24541. ts.Debug.assert(attribs[i].kind === 236);
  24542. emitJsxAttribute(attribs[i]);
  24543. }
  24544. }
  24545. }
  24546. function emitJsxOpeningOrSelfClosingElement(node) {
  24547. write("<");
  24548. emit(node.tagName);
  24549. if (node.attributes.length > 0 || (node.kind === 232)) {
  24550. write(" ");
  24551. }
  24552. emitAttributes(node.attributes);
  24553. if (node.kind === 232) {
  24554. write("/>");
  24555. }
  24556. else {
  24557. write(">");
  24558. }
  24559. }
  24560. function emitJsxClosingElement(node) {
  24561. write("</");
  24562. emit(node.tagName);
  24563. write(">");
  24564. }
  24565. function emitJsxElement(node) {
  24566. emitJsxOpeningOrSelfClosingElement(node.openingElement);
  24567. for (var i = 0, n = node.children.length; i < n; i++) {
  24568. emit(node.children[i]);
  24569. }
  24570. emitJsxClosingElement(node.closingElement);
  24571. }
  24572. if (node.kind === 231) {
  24573. emitJsxElement(node);
  24574. }
  24575. else {
  24576. ts.Debug.assert(node.kind === 232);
  24577. emitJsxOpeningOrSelfClosingElement(node);
  24578. }
  24579. }
  24580. function emitExpressionForPropertyName(node) {
  24581. ts.Debug.assert(node.kind !== 161);
  24582. if (node.kind === 9) {
  24583. emitLiteral(node);
  24584. }
  24585. else if (node.kind === 134) {
  24586. if (ts.nodeIsDecorated(node.parent)) {
  24587. if (!computedPropertyNamesToGeneratedNames) {
  24588. computedPropertyNamesToGeneratedNames = [];
  24589. }
  24590. var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)];
  24591. if (generatedName) {
  24592. write(generatedName);
  24593. return;
  24594. }
  24595. generatedName = createAndRecordTempVariable(0).text;
  24596. computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName;
  24597. write(generatedName);
  24598. write(" = ");
  24599. }
  24600. emit(node.expression);
  24601. }
  24602. else {
  24603. write("\"");
  24604. if (node.kind === 8) {
  24605. write(node.text);
  24606. }
  24607. else {
  24608. writeTextOfNode(currentSourceFile, node);
  24609. }
  24610. write("\"");
  24611. }
  24612. }
  24613. function isExpressionIdentifier(node) {
  24614. var parent = node.parent;
  24615. switch (parent.kind) {
  24616. case 162:
  24617. case 179:
  24618. case 166:
  24619. case 239:
  24620. case 134:
  24621. case 180:
  24622. case 137:
  24623. case 173:
  24624. case 195:
  24625. case 165:
  24626. case 225:
  24627. case 193:
  24628. case 186:
  24629. case 197:
  24630. case 198:
  24631. case 199:
  24632. case 194:
  24633. case 232:
  24634. case 233:
  24635. case 237:
  24636. case 238:
  24637. case 167:
  24638. case 170:
  24639. case 178:
  24640. case 177:
  24641. case 202:
  24642. case 244:
  24643. case 183:
  24644. case 204:
  24645. case 168:
  24646. case 188:
  24647. case 206:
  24648. case 169:
  24649. case 174:
  24650. case 175:
  24651. case 196:
  24652. case 203:
  24653. case 182:
  24654. return true;
  24655. case 161:
  24656. case 245:
  24657. case 136:
  24658. case 243:
  24659. case 139:
  24660. case 209:
  24661. return parent.initializer === node;
  24662. case 164:
  24663. return parent.expression === node;
  24664. case 172:
  24665. case 171:
  24666. return parent.body === node;
  24667. case 219:
  24668. return parent.moduleReference === node;
  24669. case 133:
  24670. return parent.left === node;
  24671. }
  24672. return false;
  24673. }
  24674. function emitExpressionIdentifier(node) {
  24675. if (resolver.getNodeCheckFlags(node) & 2048) {
  24676. write("_arguments");
  24677. return;
  24678. }
  24679. var container = resolver.getReferencedExportContainer(node);
  24680. if (container) {
  24681. if (container.kind === 246) {
  24682. if (languageVersion < 2 && compilerOptions.module !== 4) {
  24683. write("exports.");
  24684. }
  24685. }
  24686. else {
  24687. write(getGeneratedNameForNode(container));
  24688. write(".");
  24689. }
  24690. }
  24691. else if (languageVersion < 2) {
  24692. var declaration = resolver.getReferencedImportDeclaration(node);
  24693. if (declaration) {
  24694. if (declaration.kind === 221) {
  24695. write(getGeneratedNameForNode(declaration.parent));
  24696. write(languageVersion === 0 ? "[\"default\"]" : ".default");
  24697. return;
  24698. }
  24699. else if (declaration.kind === 224) {
  24700. write(getGeneratedNameForNode(declaration.parent.parent.parent));
  24701. write(".");
  24702. writeTextOfNode(currentSourceFile, declaration.propertyName || declaration.name);
  24703. return;
  24704. }
  24705. }
  24706. declaration = resolver.getReferencedNestedRedeclaration(node);
  24707. if (declaration) {
  24708. write(getGeneratedNameForNode(declaration.name));
  24709. return;
  24710. }
  24711. }
  24712. if (ts.nodeIsSynthesized(node)) {
  24713. write(node.text);
  24714. }
  24715. else {
  24716. writeTextOfNode(currentSourceFile, node);
  24717. }
  24718. }
  24719. function isNameOfNestedRedeclaration(node) {
  24720. if (languageVersion < 2) {
  24721. var parent_6 = node.parent;
  24722. switch (parent_6.kind) {
  24723. case 161:
  24724. case 212:
  24725. case 215:
  24726. case 209:
  24727. return parent_6.name === node && resolver.isNestedRedeclaration(parent_6);
  24728. }
  24729. }
  24730. return false;
  24731. }
  24732. function emitIdentifier(node) {
  24733. if (!node.parent) {
  24734. write(node.text);
  24735. }
  24736. else if (isExpressionIdentifier(node)) {
  24737. emitExpressionIdentifier(node);
  24738. }
  24739. else if (isNameOfNestedRedeclaration(node)) {
  24740. write(getGeneratedNameForNode(node));
  24741. }
  24742. else if (ts.nodeIsSynthesized(node)) {
  24743. write(node.text);
  24744. }
  24745. else {
  24746. writeTextOfNode(currentSourceFile, node);
  24747. }
  24748. }
  24749. function emitThis(node) {
  24750. if (resolver.getNodeCheckFlags(node) & 2) {
  24751. write("_this");
  24752. }
  24753. else {
  24754. write("this");
  24755. }
  24756. }
  24757. function emitSuper(node) {
  24758. if (languageVersion >= 2) {
  24759. write("super");
  24760. }
  24761. else {
  24762. var flags = resolver.getNodeCheckFlags(node);
  24763. if (flags & 256) {
  24764. write("_super.prototype");
  24765. }
  24766. else {
  24767. write("_super");
  24768. }
  24769. }
  24770. }
  24771. function emitObjectBindingPattern(node) {
  24772. write("{ ");
  24773. var elements = node.elements;
  24774. emitList(elements, 0, elements.length, false, elements.hasTrailingComma);
  24775. write(" }");
  24776. }
  24777. function emitArrayBindingPattern(node) {
  24778. write("[");
  24779. var elements = node.elements;
  24780. emitList(elements, 0, elements.length, false, elements.hasTrailingComma);
  24781. write("]");
  24782. }
  24783. function emitBindingElement(node) {
  24784. if (node.propertyName) {
  24785. emit(node.propertyName);
  24786. write(": ");
  24787. }
  24788. if (node.dotDotDotToken) {
  24789. write("...");
  24790. }
  24791. if (ts.isBindingPattern(node.name)) {
  24792. emit(node.name);
  24793. }
  24794. else {
  24795. emitModuleMemberName(node);
  24796. }
  24797. emitOptional(" = ", node.initializer);
  24798. }
  24799. function emitSpreadElementExpression(node) {
  24800. write("...");
  24801. emit(node.expression);
  24802. }
  24803. function emitYieldExpression(node) {
  24804. write(ts.tokenToString(112));
  24805. if (node.asteriskToken) {
  24806. write("*");
  24807. }
  24808. if (node.expression) {
  24809. write(" ");
  24810. emit(node.expression);
  24811. }
  24812. }
  24813. function emitAwaitExpression(node) {
  24814. var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node);
  24815. if (needsParenthesis) {
  24816. write("(");
  24817. }
  24818. write(ts.tokenToString(112));
  24819. write(" ");
  24820. emit(node.expression);
  24821. if (needsParenthesis) {
  24822. write(")");
  24823. }
  24824. }
  24825. function needsParenthesisForAwaitExpressionAsYield(node) {
  24826. if (node.parent.kind === 179 && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) {
  24827. return true;
  24828. }
  24829. else if (node.parent.kind === 180 && node.parent.condition === node) {
  24830. return true;
  24831. }
  24832. return false;
  24833. }
  24834. function needsParenthesisForPropertyAccessOrInvocation(node) {
  24835. switch (node.kind) {
  24836. case 67:
  24837. case 162:
  24838. case 164:
  24839. case 165:
  24840. case 166:
  24841. case 170:
  24842. return false;
  24843. }
  24844. return true;
  24845. }
  24846. function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) {
  24847. var pos = 0;
  24848. var group = 0;
  24849. var length = elements.length;
  24850. while (pos < length) {
  24851. if (group === 1 && useConcat) {
  24852. write(".concat(");
  24853. }
  24854. else if (group > 0) {
  24855. write(", ");
  24856. }
  24857. var e = elements[pos];
  24858. if (e.kind === 183) {
  24859. e = e.expression;
  24860. emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
  24861. pos++;
  24862. if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 162) {
  24863. write(".slice()");
  24864. }
  24865. }
  24866. else {
  24867. var i = pos;
  24868. while (i < length && elements[i].kind !== 183) {
  24869. i++;
  24870. }
  24871. write("[");
  24872. if (multiLine) {
  24873. increaseIndent();
  24874. }
  24875. emitList(elements, pos, i - pos, multiLine, trailingComma && i === length);
  24876. if (multiLine) {
  24877. decreaseIndent();
  24878. }
  24879. write("]");
  24880. pos = i;
  24881. }
  24882. group++;
  24883. }
  24884. if (group > 1) {
  24885. if (useConcat) {
  24886. write(")");
  24887. }
  24888. }
  24889. }
  24890. function isSpreadElementExpression(node) {
  24891. return node.kind === 183;
  24892. }
  24893. function emitArrayLiteral(node) {
  24894. var elements = node.elements;
  24895. if (elements.length === 0) {
  24896. write("[]");
  24897. }
  24898. else if (languageVersion >= 2 || !ts.forEach(elements, isSpreadElementExpression)) {
  24899. write("[");
  24900. emitLinePreservingList(node, node.elements, elements.hasTrailingComma, false);
  24901. write("]");
  24902. }
  24903. else {
  24904. emitListWithSpread(elements, true, (node.flags & 2048) !== 0, elements.hasTrailingComma, true);
  24905. }
  24906. }
  24907. function emitObjectLiteralBody(node, numElements) {
  24908. if (numElements === 0) {
  24909. write("{}");
  24910. return;
  24911. }
  24912. write("{");
  24913. if (numElements > 0) {
  24914. var properties = node.properties;
  24915. if (numElements === properties.length) {
  24916. emitLinePreservingList(node, properties, languageVersion >= 1, true);
  24917. }
  24918. else {
  24919. var multiLine = (node.flags & 2048) !== 0;
  24920. if (!multiLine) {
  24921. write(" ");
  24922. }
  24923. else {
  24924. increaseIndent();
  24925. }
  24926. emitList(properties, 0, numElements, multiLine, false);
  24927. if (!multiLine) {
  24928. write(" ");
  24929. }
  24930. else {
  24931. decreaseIndent();
  24932. }
  24933. }
  24934. }
  24935. write("}");
  24936. }
  24937. function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) {
  24938. var multiLine = (node.flags & 2048) !== 0;
  24939. var properties = node.properties;
  24940. write("(");
  24941. if (multiLine) {
  24942. increaseIndent();
  24943. }
  24944. var tempVar = createAndRecordTempVariable(0);
  24945. emit(tempVar);
  24946. write(" = ");
  24947. emitObjectLiteralBody(node, firstComputedPropertyIndex);
  24948. for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) {
  24949. writeComma();
  24950. var property = properties[i];
  24951. emitStart(property);
  24952. if (property.kind === 143 || property.kind === 144) {
  24953. var accessors = ts.getAllAccessorDeclarations(node.properties, property);
  24954. if (property !== accessors.firstAccessor) {
  24955. continue;
  24956. }
  24957. write("Object.defineProperty(");
  24958. emit(tempVar);
  24959. write(", ");
  24960. emitStart(node.name);
  24961. emitExpressionForPropertyName(property.name);
  24962. emitEnd(property.name);
  24963. write(", {");
  24964. increaseIndent();
  24965. if (accessors.getAccessor) {
  24966. writeLine();
  24967. emitLeadingComments(accessors.getAccessor);
  24968. write("get: ");
  24969. emitStart(accessors.getAccessor);
  24970. write("function ");
  24971. emitSignatureAndBody(accessors.getAccessor);
  24972. emitEnd(accessors.getAccessor);
  24973. emitTrailingComments(accessors.getAccessor);
  24974. write(",");
  24975. }
  24976. if (accessors.setAccessor) {
  24977. writeLine();
  24978. emitLeadingComments(accessors.setAccessor);
  24979. write("set: ");
  24980. emitStart(accessors.setAccessor);
  24981. write("function ");
  24982. emitSignatureAndBody(accessors.setAccessor);
  24983. emitEnd(accessors.setAccessor);
  24984. emitTrailingComments(accessors.setAccessor);
  24985. write(",");
  24986. }
  24987. writeLine();
  24988. write("enumerable: true,");
  24989. writeLine();
  24990. write("configurable: true");
  24991. decreaseIndent();
  24992. writeLine();
  24993. write("})");
  24994. emitEnd(property);
  24995. }
  24996. else {
  24997. emitLeadingComments(property);
  24998. emitStart(property.name);
  24999. emit(tempVar);
  25000. emitMemberAccessForPropertyName(property.name);
  25001. emitEnd(property.name);
  25002. write(" = ");
  25003. if (property.kind === 243) {
  25004. emit(property.initializer);
  25005. }
  25006. else if (property.kind === 244) {
  25007. emitExpressionIdentifier(property.name);
  25008. }
  25009. else if (property.kind === 141) {
  25010. emitFunctionDeclaration(property);
  25011. }
  25012. else {
  25013. ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind);
  25014. }
  25015. }
  25016. emitEnd(property);
  25017. }
  25018. writeComma();
  25019. emit(tempVar);
  25020. if (multiLine) {
  25021. decreaseIndent();
  25022. writeLine();
  25023. }
  25024. write(")");
  25025. function writeComma() {
  25026. if (multiLine) {
  25027. write(",");
  25028. writeLine();
  25029. }
  25030. else {
  25031. write(", ");
  25032. }
  25033. }
  25034. }
  25035. function emitObjectLiteral(node) {
  25036. var properties = node.properties;
  25037. if (languageVersion < 2) {
  25038. var numProperties = properties.length;
  25039. var numInitialNonComputedProperties = numProperties;
  25040. for (var i = 0, n = properties.length; i < n; i++) {
  25041. if (properties[i].name.kind === 134) {
  25042. numInitialNonComputedProperties = i;
  25043. break;
  25044. }
  25045. }
  25046. var hasComputedProperty = numInitialNonComputedProperties !== properties.length;
  25047. if (hasComputedProperty) {
  25048. emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties);
  25049. return;
  25050. }
  25051. }
  25052. emitObjectLiteralBody(node, properties.length);
  25053. }
  25054. function createBinaryExpression(left, operator, right, startsOnNewLine) {
  25055. var result = ts.createSynthesizedNode(179, startsOnNewLine);
  25056. result.operatorToken = ts.createSynthesizedNode(operator);
  25057. result.left = left;
  25058. result.right = right;
  25059. return result;
  25060. }
  25061. function createPropertyAccessExpression(expression, name) {
  25062. var result = ts.createSynthesizedNode(164);
  25063. result.expression = parenthesizeForAccess(expression);
  25064. result.dotToken = ts.createSynthesizedNode(21);
  25065. result.name = name;
  25066. return result;
  25067. }
  25068. function createElementAccessExpression(expression, argumentExpression) {
  25069. var result = ts.createSynthesizedNode(165);
  25070. result.expression = parenthesizeForAccess(expression);
  25071. result.argumentExpression = argumentExpression;
  25072. return result;
  25073. }
  25074. function parenthesizeForAccess(expr) {
  25075. while (expr.kind === 169 || expr.kind === 187) {
  25076. expr = expr.expression;
  25077. }
  25078. if (ts.isLeftHandSideExpression(expr) &&
  25079. expr.kind !== 167 &&
  25080. expr.kind !== 8) {
  25081. return expr;
  25082. }
  25083. var node = ts.createSynthesizedNode(170);
  25084. node.expression = expr;
  25085. return node;
  25086. }
  25087. function emitComputedPropertyName(node) {
  25088. write("[");
  25089. emitExpressionForPropertyName(node);
  25090. write("]");
  25091. }
  25092. function emitMethod(node) {
  25093. if (languageVersion >= 2 && node.asteriskToken) {
  25094. write("*");
  25095. }
  25096. emit(node.name);
  25097. if (languageVersion < 2) {
  25098. write(": function ");
  25099. }
  25100. emitSignatureAndBody(node);
  25101. }
  25102. function emitPropertyAssignment(node) {
  25103. emit(node.name);
  25104. write(": ");
  25105. emitTrailingCommentsOfPosition(node.initializer.pos);
  25106. emit(node.initializer);
  25107. }
  25108. function isNamespaceExportReference(node) {
  25109. var container = resolver.getReferencedExportContainer(node);
  25110. return container && container.kind !== 246;
  25111. }
  25112. function emitShorthandPropertyAssignment(node) {
  25113. writeTextOfNode(currentSourceFile, node.name);
  25114. if (languageVersion < 2 || isNamespaceExportReference(node.name)) {
  25115. write(": ");
  25116. emit(node.name);
  25117. }
  25118. }
  25119. function tryEmitConstantValue(node) {
  25120. var constantValue = tryGetConstEnumValue(node);
  25121. if (constantValue !== undefined) {
  25122. write(constantValue.toString());
  25123. if (!compilerOptions.removeComments) {
  25124. var propertyName = node.kind === 164 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression);
  25125. write(" /* " + propertyName + " */");
  25126. }
  25127. return true;
  25128. }
  25129. return false;
  25130. }
  25131. function tryGetConstEnumValue(node) {
  25132. if (compilerOptions.isolatedModules) {
  25133. return undefined;
  25134. }
  25135. return node.kind === 164 || node.kind === 165
  25136. ? resolver.getConstantValue(node)
  25137. : undefined;
  25138. }
  25139. function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) {
  25140. var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2);
  25141. var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2);
  25142. if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) {
  25143. increaseIndent();
  25144. writeLine();
  25145. return true;
  25146. }
  25147. else {
  25148. if (valueToWriteWhenNotIndenting) {
  25149. write(valueToWriteWhenNotIndenting);
  25150. }
  25151. return false;
  25152. }
  25153. }
  25154. function emitPropertyAccess(node) {
  25155. if (tryEmitConstantValue(node)) {
  25156. return;
  25157. }
  25158. emit(node.expression);
  25159. var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
  25160. var shouldEmitSpace;
  25161. if (!indentedBeforeDot) {
  25162. if (node.expression.kind === 8) {
  25163. var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression);
  25164. shouldEmitSpace = text.indexOf(ts.tokenToString(21)) < 0;
  25165. }
  25166. else {
  25167. var constantValue = tryGetConstEnumValue(node.expression);
  25168. shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue;
  25169. }
  25170. }
  25171. if (shouldEmitSpace) {
  25172. write(" .");
  25173. }
  25174. else {
  25175. write(".");
  25176. }
  25177. var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
  25178. emit(node.name);
  25179. decreaseIndentIf(indentedBeforeDot, indentedAfterDot);
  25180. }
  25181. function emitQualifiedName(node) {
  25182. emit(node.left);
  25183. write(".");
  25184. emit(node.right);
  25185. }
  25186. function emitQualifiedNameAsExpression(node, useFallback) {
  25187. if (node.left.kind === 67) {
  25188. emitEntityNameAsExpression(node.left, useFallback);
  25189. }
  25190. else if (useFallback) {
  25191. var temp = createAndRecordTempVariable(0);
  25192. write("(");
  25193. emitNodeWithoutSourceMap(temp);
  25194. write(" = ");
  25195. emitEntityNameAsExpression(node.left, true);
  25196. write(") && ");
  25197. emitNodeWithoutSourceMap(temp);
  25198. }
  25199. else {
  25200. emitEntityNameAsExpression(node.left, false);
  25201. }
  25202. write(".");
  25203. emit(node.right);
  25204. }
  25205. function emitEntityNameAsExpression(node, useFallback) {
  25206. switch (node.kind) {
  25207. case 67:
  25208. if (useFallback) {
  25209. write("typeof ");
  25210. emitExpressionIdentifier(node);
  25211. write(" !== 'undefined' && ");
  25212. }
  25213. emitExpressionIdentifier(node);
  25214. break;
  25215. case 133:
  25216. emitQualifiedNameAsExpression(node, useFallback);
  25217. break;
  25218. }
  25219. }
  25220. function emitIndexedAccess(node) {
  25221. if (tryEmitConstantValue(node)) {
  25222. return;
  25223. }
  25224. emit(node.expression);
  25225. write("[");
  25226. emit(node.argumentExpression);
  25227. write("]");
  25228. }
  25229. function hasSpreadElement(elements) {
  25230. return ts.forEach(elements, function (e) { return e.kind === 183; });
  25231. }
  25232. function skipParentheses(node) {
  25233. while (node.kind === 170 || node.kind === 169 || node.kind === 187) {
  25234. node = node.expression;
  25235. }
  25236. return node;
  25237. }
  25238. function emitCallTarget(node) {
  25239. if (node.kind === 67 || node.kind === 95 || node.kind === 93) {
  25240. emit(node);
  25241. return node;
  25242. }
  25243. var temp = createAndRecordTempVariable(0);
  25244. write("(");
  25245. emit(temp);
  25246. write(" = ");
  25247. emit(node);
  25248. write(")");
  25249. return temp;
  25250. }
  25251. function emitCallWithSpread(node) {
  25252. var target;
  25253. var expr = skipParentheses(node.expression);
  25254. if (expr.kind === 164) {
  25255. target = emitCallTarget(expr.expression);
  25256. write(".");
  25257. emit(expr.name);
  25258. }
  25259. else if (expr.kind === 165) {
  25260. target = emitCallTarget(expr.expression);
  25261. write("[");
  25262. emit(expr.argumentExpression);
  25263. write("]");
  25264. }
  25265. else if (expr.kind === 93) {
  25266. target = expr;
  25267. write("_super");
  25268. }
  25269. else {
  25270. emit(node.expression);
  25271. }
  25272. write(".apply(");
  25273. if (target) {
  25274. if (target.kind === 93) {
  25275. emitThis(target);
  25276. }
  25277. else {
  25278. emit(target);
  25279. }
  25280. }
  25281. else {
  25282. write("void 0");
  25283. }
  25284. write(", ");
  25285. emitListWithSpread(node.arguments, false, false, false, true);
  25286. write(")");
  25287. }
  25288. function emitCallExpression(node) {
  25289. if (languageVersion < 2 && hasSpreadElement(node.arguments)) {
  25290. emitCallWithSpread(node);
  25291. return;
  25292. }
  25293. var superCall = false;
  25294. if (node.expression.kind === 93) {
  25295. emitSuper(node.expression);
  25296. superCall = true;
  25297. }
  25298. else {
  25299. emit(node.expression);
  25300. superCall = node.expression.kind === 164 && node.expression.expression.kind === 93;
  25301. }
  25302. if (superCall && languageVersion < 2) {
  25303. write(".call(");
  25304. emitThis(node.expression);
  25305. if (node.arguments.length) {
  25306. write(", ");
  25307. emitCommaList(node.arguments);
  25308. }
  25309. write(")");
  25310. }
  25311. else {
  25312. write("(");
  25313. emitCommaList(node.arguments);
  25314. write(")");
  25315. }
  25316. }
  25317. function emitNewExpression(node) {
  25318. write("new ");
  25319. if (languageVersion === 1 &&
  25320. node.arguments &&
  25321. hasSpreadElement(node.arguments)) {
  25322. write("(");
  25323. var target = emitCallTarget(node.expression);
  25324. write(".bind.apply(");
  25325. emit(target);
  25326. write(", [void 0].concat(");
  25327. emitListWithSpread(node.arguments, false, false, false, false);
  25328. write(")))");
  25329. write("()");
  25330. }
  25331. else {
  25332. emit(node.expression);
  25333. if (node.arguments) {
  25334. write("(");
  25335. emitCommaList(node.arguments);
  25336. write(")");
  25337. }
  25338. }
  25339. }
  25340. function emitTaggedTemplateExpression(node) {
  25341. if (languageVersion >= 2) {
  25342. emit(node.tag);
  25343. write(" ");
  25344. emit(node.template);
  25345. }
  25346. else {
  25347. emitDownlevelTaggedTemplate(node);
  25348. }
  25349. }
  25350. function emitParenExpression(node) {
  25351. if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 172) {
  25352. if (node.expression.kind === 169 || node.expression.kind === 187) {
  25353. var operand = node.expression.expression;
  25354. while (operand.kind === 169 || operand.kind === 187) {
  25355. operand = operand.expression;
  25356. }
  25357. if (operand.kind !== 177 &&
  25358. operand.kind !== 175 &&
  25359. operand.kind !== 174 &&
  25360. operand.kind !== 173 &&
  25361. operand.kind !== 178 &&
  25362. operand.kind !== 167 &&
  25363. !(operand.kind === 166 && node.parent.kind === 167) &&
  25364. !(operand.kind === 171 && node.parent.kind === 166)) {
  25365. emit(operand);
  25366. return;
  25367. }
  25368. }
  25369. }
  25370. write("(");
  25371. emit(node.expression);
  25372. write(")");
  25373. }
  25374. function emitDeleteExpression(node) {
  25375. write(ts.tokenToString(76));
  25376. write(" ");
  25377. emit(node.expression);
  25378. }
  25379. function emitVoidExpression(node) {
  25380. write(ts.tokenToString(101));
  25381. write(" ");
  25382. emit(node.expression);
  25383. }
  25384. function emitTypeOfExpression(node) {
  25385. write(ts.tokenToString(99));
  25386. write(" ");
  25387. emit(node.expression);
  25388. }
  25389. function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) {
  25390. if (!isCurrentFileSystemExternalModule() || node.kind !== 67 || ts.nodeIsSynthesized(node)) {
  25391. return false;
  25392. }
  25393. var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 209 || node.parent.kind === 161);
  25394. var targetDeclaration = isVariableDeclarationOrBindingElement
  25395. ? node.parent
  25396. : resolver.getReferencedValueDeclaration(node);
  25397. return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, true);
  25398. }
  25399. function emitPrefixUnaryExpression(node) {
  25400. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
  25401. if (exportChanged) {
  25402. write(exportFunctionForFile + "(\"");
  25403. emitNodeWithoutSourceMap(node.operand);
  25404. write("\", ");
  25405. }
  25406. write(ts.tokenToString(node.operator));
  25407. if (node.operand.kind === 177) {
  25408. var operand = node.operand;
  25409. if (node.operator === 35 && (operand.operator === 35 || operand.operator === 40)) {
  25410. write(" ");
  25411. }
  25412. else if (node.operator === 36 && (operand.operator === 36 || operand.operator === 41)) {
  25413. write(" ");
  25414. }
  25415. }
  25416. emit(node.operand);
  25417. if (exportChanged) {
  25418. write(")");
  25419. }
  25420. }
  25421. function emitPostfixUnaryExpression(node) {
  25422. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
  25423. if (exportChanged) {
  25424. write("(" + exportFunctionForFile + "(\"");
  25425. emitNodeWithoutSourceMap(node.operand);
  25426. write("\", ");
  25427. write(ts.tokenToString(node.operator));
  25428. emit(node.operand);
  25429. if (node.operator === 40) {
  25430. write(") - 1)");
  25431. }
  25432. else {
  25433. write(") + 1)");
  25434. }
  25435. }
  25436. else {
  25437. emit(node.operand);
  25438. write(ts.tokenToString(node.operator));
  25439. }
  25440. }
  25441. function shouldHoistDeclarationInSystemJsModule(node) {
  25442. return isSourceFileLevelDeclarationInSystemJsModule(node, false);
  25443. }
  25444. function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) {
  25445. if (!node || languageVersion >= 2 || !isCurrentFileSystemExternalModule()) {
  25446. return false;
  25447. }
  25448. var current = node;
  25449. while (current) {
  25450. if (current.kind === 246) {
  25451. return !isExported || ((ts.getCombinedNodeFlags(node) & 1) !== 0);
  25452. }
  25453. else if (ts.isFunctionLike(current) || current.kind === 217) {
  25454. return false;
  25455. }
  25456. else {
  25457. current = current.parent;
  25458. }
  25459. }
  25460. }
  25461. function emitBinaryExpression(node) {
  25462. if (languageVersion < 2 && node.operatorToken.kind === 55 &&
  25463. (node.left.kind === 163 || node.left.kind === 162)) {
  25464. emitDestructuring(node, node.parent.kind === 193);
  25465. }
  25466. else {
  25467. var exportChanged = node.operatorToken.kind >= 55 &&
  25468. node.operatorToken.kind <= 66 &&
  25469. isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left);
  25470. if (exportChanged) {
  25471. write(exportFunctionForFile + "(\"");
  25472. emitNodeWithoutSourceMap(node.left);
  25473. write("\", ");
  25474. }
  25475. emit(node.left);
  25476. var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 ? " " : undefined);
  25477. write(ts.tokenToString(node.operatorToken.kind));
  25478. var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " ");
  25479. emit(node.right);
  25480. decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator);
  25481. if (exportChanged) {
  25482. write(")");
  25483. }
  25484. }
  25485. }
  25486. function synthesizedNodeStartsOnNewLine(node) {
  25487. return ts.nodeIsSynthesized(node) && node.startsOnNewLine;
  25488. }
  25489. function emitConditionalExpression(node) {
  25490. emit(node.condition);
  25491. var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " ");
  25492. write("?");
  25493. var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " ");
  25494. emit(node.whenTrue);
  25495. decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion);
  25496. var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " ");
  25497. write(":");
  25498. var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " ");
  25499. emit(node.whenFalse);
  25500. decreaseIndentIf(indentedBeforeColon, indentedAfterColon);
  25501. }
  25502. function decreaseIndentIf(value1, value2) {
  25503. if (value1) {
  25504. decreaseIndent();
  25505. }
  25506. if (value2) {
  25507. decreaseIndent();
  25508. }
  25509. }
  25510. function isSingleLineEmptyBlock(node) {
  25511. if (node && node.kind === 190) {
  25512. var block = node;
  25513. return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block);
  25514. }
  25515. }
  25516. function emitBlock(node) {
  25517. if (isSingleLineEmptyBlock(node)) {
  25518. emitToken(15, node.pos);
  25519. write(" ");
  25520. emitToken(16, node.statements.end);
  25521. return;
  25522. }
  25523. emitToken(15, node.pos);
  25524. increaseIndent();
  25525. scopeEmitStart(node.parent);
  25526. if (node.kind === 217) {
  25527. ts.Debug.assert(node.parent.kind === 216);
  25528. emitCaptureThisForNodeIfNecessary(node.parent);
  25529. }
  25530. emitLines(node.statements);
  25531. if (node.kind === 217) {
  25532. emitTempDeclarations(true);
  25533. }
  25534. decreaseIndent();
  25535. writeLine();
  25536. emitToken(16, node.statements.end);
  25537. scopeEmitEnd();
  25538. }
  25539. function emitEmbeddedStatement(node) {
  25540. if (node.kind === 190) {
  25541. write(" ");
  25542. emit(node);
  25543. }
  25544. else {
  25545. increaseIndent();
  25546. writeLine();
  25547. emit(node);
  25548. decreaseIndent();
  25549. }
  25550. }
  25551. function emitExpressionStatement(node) {
  25552. emitParenthesizedIf(node.expression, node.expression.kind === 172);
  25553. write(";");
  25554. }
  25555. function emitIfStatement(node) {
  25556. var endPos = emitToken(86, node.pos);
  25557. write(" ");
  25558. endPos = emitToken(17, endPos);
  25559. emit(node.expression);
  25560. emitToken(18, node.expression.end);
  25561. emitEmbeddedStatement(node.thenStatement);
  25562. if (node.elseStatement) {
  25563. writeLine();
  25564. emitToken(78, node.thenStatement.end);
  25565. if (node.elseStatement.kind === 194) {
  25566. write(" ");
  25567. emit(node.elseStatement);
  25568. }
  25569. else {
  25570. emitEmbeddedStatement(node.elseStatement);
  25571. }
  25572. }
  25573. }
  25574. function emitDoStatement(node) {
  25575. write("do");
  25576. emitEmbeddedStatement(node.statement);
  25577. if (node.statement.kind === 190) {
  25578. write(" ");
  25579. }
  25580. else {
  25581. writeLine();
  25582. }
  25583. write("while (");
  25584. emit(node.expression);
  25585. write(");");
  25586. }
  25587. function emitWhileStatement(node) {
  25588. write("while (");
  25589. emit(node.expression);
  25590. write(")");
  25591. emitEmbeddedStatement(node.statement);
  25592. }
  25593. function tryEmitStartOfVariableDeclarationList(decl, startPos) {
  25594. if (shouldHoistVariable(decl, true)) {
  25595. return false;
  25596. }
  25597. var tokenKind = 100;
  25598. if (decl && languageVersion >= 2) {
  25599. if (ts.isLet(decl)) {
  25600. tokenKind = 106;
  25601. }
  25602. else if (ts.isConst(decl)) {
  25603. tokenKind = 72;
  25604. }
  25605. }
  25606. if (startPos !== undefined) {
  25607. emitToken(tokenKind, startPos);
  25608. write(" ");
  25609. }
  25610. else {
  25611. switch (tokenKind) {
  25612. case 100:
  25613. write("var ");
  25614. break;
  25615. case 106:
  25616. write("let ");
  25617. break;
  25618. case 72:
  25619. write("const ");
  25620. break;
  25621. }
  25622. }
  25623. return true;
  25624. }
  25625. function emitVariableDeclarationListSkippingUninitializedEntries(list) {
  25626. var started = false;
  25627. for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) {
  25628. var decl = _b[_a];
  25629. if (!decl.initializer) {
  25630. continue;
  25631. }
  25632. if (!started) {
  25633. started = true;
  25634. }
  25635. else {
  25636. write(", ");
  25637. }
  25638. emit(decl);
  25639. }
  25640. return started;
  25641. }
  25642. function emitForStatement(node) {
  25643. var endPos = emitToken(84, node.pos);
  25644. write(" ");
  25645. endPos = emitToken(17, endPos);
  25646. if (node.initializer && node.initializer.kind === 210) {
  25647. var variableDeclarationList = node.initializer;
  25648. var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
  25649. if (startIsEmitted) {
  25650. emitCommaList(variableDeclarationList.declarations);
  25651. }
  25652. else {
  25653. emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList);
  25654. }
  25655. }
  25656. else if (node.initializer) {
  25657. emit(node.initializer);
  25658. }
  25659. write(";");
  25660. emitOptional(" ", node.condition);
  25661. write(";");
  25662. emitOptional(" ", node.incrementor);
  25663. write(")");
  25664. emitEmbeddedStatement(node.statement);
  25665. }
  25666. function emitForInOrForOfStatement(node) {
  25667. if (languageVersion < 2 && node.kind === 199) {
  25668. return emitDownLevelForOfStatement(node);
  25669. }
  25670. var endPos = emitToken(84, node.pos);
  25671. write(" ");
  25672. endPos = emitToken(17, endPos);
  25673. if (node.initializer.kind === 210) {
  25674. var variableDeclarationList = node.initializer;
  25675. if (variableDeclarationList.declarations.length >= 1) {
  25676. tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
  25677. emit(variableDeclarationList.declarations[0]);
  25678. }
  25679. }
  25680. else {
  25681. emit(node.initializer);
  25682. }
  25683. if (node.kind === 198) {
  25684. write(" in ");
  25685. }
  25686. else {
  25687. write(" of ");
  25688. }
  25689. emit(node.expression);
  25690. emitToken(18, node.expression.end);
  25691. emitEmbeddedStatement(node.statement);
  25692. }
  25693. function emitDownLevelForOfStatement(node) {
  25694. // The following ES6 code:
  25695. //
  25696. // for (let v of expr) { }
  25697. //
  25698. // should be emitted as
  25699. //
  25700. // for (let _i = 0, _a = expr; _i < _a.length; _i++) {
  25701. // let v = _a[_i];
  25702. // }
  25703. //
  25704. // where _a and _i are temps emitted to capture the RHS and the counter,
  25705. // respectively.
  25706. // When the left hand side is an expression instead of a let declaration,
  25707. // the "let v" is not emitted.
  25708. // When the left hand side is a let/const, the v is renamed if there is
  25709. // another v in scope.
  25710. // Note that all assignments to the LHS are emitted in the body, including
  25711. // all destructuring.
  25712. // Note also that because an extra statement is needed to assign to the LHS,
  25713. // for-of bodies are always emitted as blocks.
  25714. var endPos = emitToken(84, node.pos);
  25715. write(" ");
  25716. endPos = emitToken(17, endPos);
  25717. var rhsIsIdentifier = node.expression.kind === 67;
  25718. var counter = createTempVariable(268435456);
  25719. var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0);
  25720. emitStart(node.expression);
  25721. write("var ");
  25722. emitNodeWithoutSourceMap(counter);
  25723. write(" = 0");
  25724. emitEnd(node.expression);
  25725. if (!rhsIsIdentifier) {
  25726. write(", ");
  25727. emitStart(node.expression);
  25728. emitNodeWithoutSourceMap(rhsReference);
  25729. write(" = ");
  25730. emitNodeWithoutSourceMap(node.expression);
  25731. emitEnd(node.expression);
  25732. }
  25733. write("; ");
  25734. emitStart(node.initializer);
  25735. emitNodeWithoutSourceMap(counter);
  25736. write(" < ");
  25737. emitNodeWithCommentsAndWithoutSourcemap(rhsReference);
  25738. write(".length");
  25739. emitEnd(node.initializer);
  25740. write("; ");
  25741. emitStart(node.initializer);
  25742. emitNodeWithoutSourceMap(counter);
  25743. write("++");
  25744. emitEnd(node.initializer);
  25745. emitToken(18, node.expression.end);
  25746. write(" {");
  25747. writeLine();
  25748. increaseIndent();
  25749. var rhsIterationValue = createElementAccessExpression(rhsReference, counter);
  25750. emitStart(node.initializer);
  25751. if (node.initializer.kind === 210) {
  25752. write("var ");
  25753. var variableDeclarationList = node.initializer;
  25754. if (variableDeclarationList.declarations.length > 0) {
  25755. var declaration = variableDeclarationList.declarations[0];
  25756. if (ts.isBindingPattern(declaration.name)) {
  25757. emitDestructuring(declaration, false, rhsIterationValue);
  25758. }
  25759. else {
  25760. emitNodeWithCommentsAndWithoutSourcemap(declaration);
  25761. write(" = ");
  25762. emitNodeWithoutSourceMap(rhsIterationValue);
  25763. }
  25764. }
  25765. else {
  25766. emitNodeWithoutSourceMap(createTempVariable(0));
  25767. write(" = ");
  25768. emitNodeWithoutSourceMap(rhsIterationValue);
  25769. }
  25770. }
  25771. else {
  25772. var assignmentExpression = createBinaryExpression(node.initializer, 55, rhsIterationValue, false);
  25773. if (node.initializer.kind === 162 || node.initializer.kind === 163) {
  25774. emitDestructuring(assignmentExpression, true, undefined);
  25775. }
  25776. else {
  25777. emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression);
  25778. }
  25779. }
  25780. emitEnd(node.initializer);
  25781. write(";");
  25782. if (node.statement.kind === 190) {
  25783. emitLines(node.statement.statements);
  25784. }
  25785. else {
  25786. writeLine();
  25787. emit(node.statement);
  25788. }
  25789. writeLine();
  25790. decreaseIndent();
  25791. write("}");
  25792. }
  25793. function emitBreakOrContinueStatement(node) {
  25794. emitToken(node.kind === 201 ? 68 : 73, node.pos);
  25795. emitOptional(" ", node.label);
  25796. write(";");
  25797. }
  25798. function emitReturnStatement(node) {
  25799. emitToken(92, node.pos);
  25800. emitOptional(" ", node.expression);
  25801. write(";");
  25802. }
  25803. function emitWithStatement(node) {
  25804. write("with (");
  25805. emit(node.expression);
  25806. write(")");
  25807. emitEmbeddedStatement(node.statement);
  25808. }
  25809. function emitSwitchStatement(node) {
  25810. var endPos = emitToken(94, node.pos);
  25811. write(" ");
  25812. emitToken(17, endPos);
  25813. emit(node.expression);
  25814. endPos = emitToken(18, node.expression.end);
  25815. write(" ");
  25816. emitCaseBlock(node.caseBlock, endPos);
  25817. }
  25818. function emitCaseBlock(node, startPos) {
  25819. emitToken(15, startPos);
  25820. increaseIndent();
  25821. emitLines(node.clauses);
  25822. decreaseIndent();
  25823. writeLine();
  25824. emitToken(16, node.clauses.end);
  25825. }
  25826. function nodeStartPositionsAreOnSameLine(node1, node2) {
  25827. return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) ===
  25828. ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
  25829. }
  25830. function nodeEndPositionsAreOnSameLine(node1, node2) {
  25831. return ts.getLineOfLocalPosition(currentSourceFile, node1.end) ===
  25832. ts.getLineOfLocalPosition(currentSourceFile, node2.end);
  25833. }
  25834. function nodeEndIsOnSameLineAsNodeStart(node1, node2) {
  25835. return ts.getLineOfLocalPosition(currentSourceFile, node1.end) ===
  25836. ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
  25837. }
  25838. function emitCaseOrDefaultClause(node) {
  25839. if (node.kind === 239) {
  25840. write("case ");
  25841. emit(node.expression);
  25842. write(":");
  25843. }
  25844. else {
  25845. write("default:");
  25846. }
  25847. if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) {
  25848. write(" ");
  25849. emit(node.statements[0]);
  25850. }
  25851. else {
  25852. increaseIndent();
  25853. emitLines(node.statements);
  25854. decreaseIndent();
  25855. }
  25856. }
  25857. function emitThrowStatement(node) {
  25858. write("throw ");
  25859. emit(node.expression);
  25860. write(";");
  25861. }
  25862. function emitTryStatement(node) {
  25863. write("try ");
  25864. emit(node.tryBlock);
  25865. emit(node.catchClause);
  25866. if (node.finallyBlock) {
  25867. writeLine();
  25868. write("finally ");
  25869. emit(node.finallyBlock);
  25870. }
  25871. }
  25872. function emitCatchClause(node) {
  25873. writeLine();
  25874. var endPos = emitToken(70, node.pos);
  25875. write(" ");
  25876. emitToken(17, endPos);
  25877. emit(node.variableDeclaration);
  25878. emitToken(18, node.variableDeclaration ? node.variableDeclaration.end : endPos);
  25879. write(" ");
  25880. emitBlock(node.block);
  25881. }
  25882. function emitDebuggerStatement(node) {
  25883. emitToken(74, node.pos);
  25884. write(";");
  25885. }
  25886. function emitLabelledStatement(node) {
  25887. emit(node.label);
  25888. write(": ");
  25889. emit(node.statement);
  25890. }
  25891. function getContainingModule(node) {
  25892. do {
  25893. node = node.parent;
  25894. } while (node && node.kind !== 216);
  25895. return node;
  25896. }
  25897. function emitContainingModuleName(node) {
  25898. var container = getContainingModule(node);
  25899. write(container ? getGeneratedNameForNode(container) : "exports");
  25900. }
  25901. function emitModuleMemberName(node) {
  25902. emitStart(node.name);
  25903. if (ts.getCombinedNodeFlags(node) & 1) {
  25904. var container = getContainingModule(node);
  25905. if (container) {
  25906. write(getGeneratedNameForNode(container));
  25907. write(".");
  25908. }
  25909. else if (languageVersion < 2 && compilerOptions.module !== 4) {
  25910. write("exports.");
  25911. }
  25912. }
  25913. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  25914. emitEnd(node.name);
  25915. }
  25916. function createVoidZero() {
  25917. var zero = ts.createSynthesizedNode(8);
  25918. zero.text = "0";
  25919. var result = ts.createSynthesizedNode(175);
  25920. result.expression = zero;
  25921. return result;
  25922. }
  25923. function emitEs6ExportDefaultCompat(node) {
  25924. if (node.parent.kind === 246) {
  25925. ts.Debug.assert(!!(node.flags & 1024) || node.kind === 225);
  25926. if (compilerOptions.module === 1 || compilerOptions.module === 2 || compilerOptions.module === 3) {
  25927. if (!currentSourceFile.symbol.exports["___esModule"]) {
  25928. if (languageVersion === 1) {
  25929. write("Object.defineProperty(exports, \"__esModule\", { value: true });");
  25930. writeLine();
  25931. }
  25932. else if (languageVersion === 0) {
  25933. write("exports.__esModule = true;");
  25934. writeLine();
  25935. }
  25936. }
  25937. }
  25938. }
  25939. }
  25940. function emitExportMemberAssignment(node) {
  25941. if (node.flags & 1) {
  25942. writeLine();
  25943. emitStart(node);
  25944. if (compilerOptions.module === 4 && node.parent === currentSourceFile) {
  25945. write(exportFunctionForFile + "(\"");
  25946. if (node.flags & 1024) {
  25947. write("default");
  25948. }
  25949. else {
  25950. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  25951. }
  25952. write("\", ");
  25953. emitDeclarationName(node);
  25954. write(")");
  25955. }
  25956. else {
  25957. if (node.flags & 1024) {
  25958. emitEs6ExportDefaultCompat(node);
  25959. if (languageVersion === 0) {
  25960. write("exports[\"default\"]");
  25961. }
  25962. else {
  25963. write("exports.default");
  25964. }
  25965. }
  25966. else {
  25967. emitModuleMemberName(node);
  25968. }
  25969. write(" = ");
  25970. emitDeclarationName(node);
  25971. }
  25972. emitEnd(node);
  25973. write(";");
  25974. }
  25975. }
  25976. function emitExportMemberAssignments(name) {
  25977. if (compilerOptions.module === 4) {
  25978. return;
  25979. }
  25980. if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) {
  25981. for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) {
  25982. var specifier = _b[_a];
  25983. writeLine();
  25984. emitStart(specifier.name);
  25985. emitContainingModuleName(specifier);
  25986. write(".");
  25987. emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
  25988. emitEnd(specifier.name);
  25989. write(" = ");
  25990. emitExpressionIdentifier(name);
  25991. write(";");
  25992. }
  25993. }
  25994. }
  25995. function emitExportSpecifierInSystemModule(specifier) {
  25996. ts.Debug.assert(compilerOptions.module === 4);
  25997. if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) {
  25998. return;
  25999. }
  26000. writeLine();
  26001. emitStart(specifier.name);
  26002. write(exportFunctionForFile + "(\"");
  26003. emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
  26004. write("\", ");
  26005. emitExpressionIdentifier(specifier.propertyName || specifier.name);
  26006. write(")");
  26007. emitEnd(specifier.name);
  26008. write(";");
  26009. }
  26010. function emitDestructuring(root, isAssignmentExpressionStatement, value) {
  26011. var emitCount = 0;
  26012. var canDefineTempVariablesInPlace = false;
  26013. if (root.kind === 209) {
  26014. var isExported = ts.getCombinedNodeFlags(root) & 1;
  26015. var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root);
  26016. canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind;
  26017. }
  26018. else if (root.kind === 136) {
  26019. canDefineTempVariablesInPlace = true;
  26020. }
  26021. if (root.kind === 179) {
  26022. emitAssignmentExpression(root);
  26023. }
  26024. else {
  26025. ts.Debug.assert(!isAssignmentExpressionStatement);
  26026. emitBindingElement(root, value);
  26027. }
  26028. function emitAssignment(name, value) {
  26029. if (emitCount++) {
  26030. write(", ");
  26031. }
  26032. var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 209 || name.parent.kind === 161);
  26033. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name);
  26034. if (exportChanged) {
  26035. write(exportFunctionForFile + "(\"");
  26036. emitNodeWithCommentsAndWithoutSourcemap(name);
  26037. write("\", ");
  26038. }
  26039. if (isVariableDeclarationOrBindingElement) {
  26040. emitModuleMemberName(name.parent);
  26041. }
  26042. else {
  26043. emit(name);
  26044. }
  26045. write(" = ");
  26046. emit(value);
  26047. if (exportChanged) {
  26048. write(")");
  26049. }
  26050. }
  26051. function ensureIdentifier(expr, reuseIdentifierExpressions) {
  26052. if (expr.kind === 67 && reuseIdentifierExpressions) {
  26053. return expr;
  26054. }
  26055. var identifier = createTempVariable(0);
  26056. if (!canDefineTempVariablesInPlace) {
  26057. recordTempDeclaration(identifier);
  26058. }
  26059. emitAssignment(identifier, expr);
  26060. return identifier;
  26061. }
  26062. function createDefaultValueCheck(value, defaultValue) {
  26063. value = ensureIdentifier(value, true);
  26064. var equals = ts.createSynthesizedNode(179);
  26065. equals.left = value;
  26066. equals.operatorToken = ts.createSynthesizedNode(32);
  26067. equals.right = createVoidZero();
  26068. return createConditionalExpression(equals, defaultValue, value);
  26069. }
  26070. function createConditionalExpression(condition, whenTrue, whenFalse) {
  26071. var cond = ts.createSynthesizedNode(180);
  26072. cond.condition = condition;
  26073. cond.questionToken = ts.createSynthesizedNode(52);
  26074. cond.whenTrue = whenTrue;
  26075. cond.colonToken = ts.createSynthesizedNode(53);
  26076. cond.whenFalse = whenFalse;
  26077. return cond;
  26078. }
  26079. function createNumericLiteral(value) {
  26080. var node = ts.createSynthesizedNode(8);
  26081. node.text = "" + value;
  26082. return node;
  26083. }
  26084. function createPropertyAccessForDestructuringProperty(object, propName) {
  26085. var syntheticName = ts.createSynthesizedNode(propName.kind);
  26086. syntheticName.text = propName.text;
  26087. if (syntheticName.kind !== 67) {
  26088. return createElementAccessExpression(object, syntheticName);
  26089. }
  26090. return createPropertyAccessExpression(object, syntheticName);
  26091. }
  26092. function createSliceCall(value, sliceIndex) {
  26093. var call = ts.createSynthesizedNode(166);
  26094. var sliceIdentifier = ts.createSynthesizedNode(67);
  26095. sliceIdentifier.text = "slice";
  26096. call.expression = createPropertyAccessExpression(value, sliceIdentifier);
  26097. call.arguments = ts.createSynthesizedNodeArray();
  26098. call.arguments[0] = createNumericLiteral(sliceIndex);
  26099. return call;
  26100. }
  26101. function emitObjectLiteralAssignment(target, value) {
  26102. var properties = target.properties;
  26103. if (properties.length !== 1) {
  26104. value = ensureIdentifier(value, true);
  26105. }
  26106. for (var _a = 0; _a < properties.length; _a++) {
  26107. var p = properties[_a];
  26108. if (p.kind === 243 || p.kind === 244) {
  26109. var propName = p.name;
  26110. emitDestructuringAssignment(p.initializer || propName, createPropertyAccessForDestructuringProperty(value, propName));
  26111. }
  26112. }
  26113. }
  26114. function emitArrayLiteralAssignment(target, value) {
  26115. var elements = target.elements;
  26116. if (elements.length !== 1) {
  26117. value = ensureIdentifier(value, true);
  26118. }
  26119. for (var i = 0; i < elements.length; i++) {
  26120. var e = elements[i];
  26121. if (e.kind !== 185) {
  26122. if (e.kind !== 183) {
  26123. emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i)));
  26124. }
  26125. else if (i === elements.length - 1) {
  26126. emitDestructuringAssignment(e.expression, createSliceCall(value, i));
  26127. }
  26128. }
  26129. }
  26130. }
  26131. function emitDestructuringAssignment(target, value) {
  26132. if (target.kind === 179 && target.operatorToken.kind === 55) {
  26133. value = createDefaultValueCheck(value, target.right);
  26134. target = target.left;
  26135. }
  26136. if (target.kind === 163) {
  26137. emitObjectLiteralAssignment(target, value);
  26138. }
  26139. else if (target.kind === 162) {
  26140. emitArrayLiteralAssignment(target, value);
  26141. }
  26142. else {
  26143. emitAssignment(target, value);
  26144. }
  26145. }
  26146. function emitAssignmentExpression(root) {
  26147. var target = root.left;
  26148. var value = root.right;
  26149. if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) {
  26150. emit(value);
  26151. }
  26152. else if (isAssignmentExpressionStatement) {
  26153. emitDestructuringAssignment(target, value);
  26154. }
  26155. else {
  26156. if (root.parent.kind !== 170) {
  26157. write("(");
  26158. }
  26159. value = ensureIdentifier(value, true);
  26160. emitDestructuringAssignment(target, value);
  26161. write(", ");
  26162. emit(value);
  26163. if (root.parent.kind !== 170) {
  26164. write(")");
  26165. }
  26166. }
  26167. }
  26168. function emitBindingElement(target, value) {
  26169. if (target.initializer) {
  26170. value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer;
  26171. }
  26172. else if (!value) {
  26173. value = createVoidZero();
  26174. }
  26175. if (ts.isBindingPattern(target.name)) {
  26176. var pattern = target.name;
  26177. var elements = pattern.elements;
  26178. var numElements = elements.length;
  26179. if (numElements !== 1) {
  26180. value = ensureIdentifier(value, numElements !== 0);
  26181. }
  26182. for (var i = 0; i < numElements; i++) {
  26183. var element = elements[i];
  26184. if (pattern.kind === 159) {
  26185. var propName = element.propertyName || element.name;
  26186. emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName));
  26187. }
  26188. else if (element.kind !== 185) {
  26189. if (!element.dotDotDotToken) {
  26190. emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i)));
  26191. }
  26192. else if (i === numElements - 1) {
  26193. emitBindingElement(element, createSliceCall(value, i));
  26194. }
  26195. }
  26196. }
  26197. }
  26198. else {
  26199. emitAssignment(target.name, value);
  26200. }
  26201. }
  26202. }
  26203. function emitVariableDeclaration(node) {
  26204. if (ts.isBindingPattern(node.name)) {
  26205. if (languageVersion < 2) {
  26206. emitDestructuring(node, false);
  26207. }
  26208. else {
  26209. emit(node.name);
  26210. emitOptional(" = ", node.initializer);
  26211. }
  26212. }
  26213. else {
  26214. var initializer = node.initializer;
  26215. if (!initializer && languageVersion < 2) {
  26216. var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384) &&
  26217. (getCombinedFlagsForIdentifier(node.name) & 16384);
  26218. if (isUninitializedLet &&
  26219. node.parent.parent.kind !== 198 &&
  26220. node.parent.parent.kind !== 199) {
  26221. initializer = createVoidZero();
  26222. }
  26223. }
  26224. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name);
  26225. if (exportChanged) {
  26226. write(exportFunctionForFile + "(\"");
  26227. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  26228. write("\", ");
  26229. }
  26230. emitModuleMemberName(node);
  26231. emitOptional(" = ", initializer);
  26232. if (exportChanged) {
  26233. write(")");
  26234. }
  26235. }
  26236. }
  26237. function emitExportVariableAssignments(node) {
  26238. if (node.kind === 185) {
  26239. return;
  26240. }
  26241. var name = node.name;
  26242. if (name.kind === 67) {
  26243. emitExportMemberAssignments(name);
  26244. }
  26245. else if (ts.isBindingPattern(name)) {
  26246. ts.forEach(name.elements, emitExportVariableAssignments);
  26247. }
  26248. }
  26249. function getCombinedFlagsForIdentifier(node) {
  26250. if (!node.parent || (node.parent.kind !== 209 && node.parent.kind !== 161)) {
  26251. return 0;
  26252. }
  26253. return ts.getCombinedNodeFlags(node.parent);
  26254. }
  26255. function isES6ExportedDeclaration(node) {
  26256. return !!(node.flags & 1) &&
  26257. languageVersion >= 2 &&
  26258. node.parent.kind === 246;
  26259. }
  26260. function emitVariableStatement(node) {
  26261. var startIsEmitted = false;
  26262. if (node.flags & 1) {
  26263. if (isES6ExportedDeclaration(node)) {
  26264. write("export ");
  26265. startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
  26266. }
  26267. }
  26268. else {
  26269. startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
  26270. }
  26271. if (startIsEmitted) {
  26272. emitCommaList(node.declarationList.declarations);
  26273. write(";");
  26274. }
  26275. else {
  26276. var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList);
  26277. if (atLeastOneItem) {
  26278. write(";");
  26279. }
  26280. }
  26281. if (languageVersion < 2 && node.parent === currentSourceFile) {
  26282. ts.forEach(node.declarationList.declarations, emitExportVariableAssignments);
  26283. }
  26284. }
  26285. function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) {
  26286. if (!(node.flags & 1)) {
  26287. return true;
  26288. }
  26289. if (isES6ExportedDeclaration(node)) {
  26290. return true;
  26291. }
  26292. for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) {
  26293. var declaration = _b[_a];
  26294. if (declaration.initializer) {
  26295. return true;
  26296. }
  26297. }
  26298. return false;
  26299. }
  26300. function emitParameter(node) {
  26301. if (languageVersion < 2) {
  26302. if (ts.isBindingPattern(node.name)) {
  26303. var name_23 = createTempVariable(0);
  26304. if (!tempParameters) {
  26305. tempParameters = [];
  26306. }
  26307. tempParameters.push(name_23);
  26308. emit(name_23);
  26309. }
  26310. else {
  26311. emit(node.name);
  26312. }
  26313. }
  26314. else {
  26315. if (node.dotDotDotToken) {
  26316. write("...");
  26317. }
  26318. emit(node.name);
  26319. emitOptional(" = ", node.initializer);
  26320. }
  26321. }
  26322. function emitDefaultValueAssignments(node) {
  26323. if (languageVersion < 2) {
  26324. var tempIndex = 0;
  26325. ts.forEach(node.parameters, function (parameter) {
  26326. if (parameter.dotDotDotToken) {
  26327. return;
  26328. }
  26329. var paramName = parameter.name, initializer = parameter.initializer;
  26330. if (ts.isBindingPattern(paramName)) {
  26331. var hasBindingElements = paramName.elements.length > 0;
  26332. if (hasBindingElements || initializer) {
  26333. writeLine();
  26334. write("var ");
  26335. if (hasBindingElements) {
  26336. emitDestructuring(parameter, false, tempParameters[tempIndex]);
  26337. }
  26338. else {
  26339. emit(tempParameters[tempIndex]);
  26340. write(" = ");
  26341. emit(initializer);
  26342. }
  26343. write(";");
  26344. tempIndex++;
  26345. }
  26346. }
  26347. else if (initializer) {
  26348. writeLine();
  26349. emitStart(parameter);
  26350. write("if (");
  26351. emitNodeWithoutSourceMap(paramName);
  26352. write(" === void 0)");
  26353. emitEnd(parameter);
  26354. write(" { ");
  26355. emitStart(parameter);
  26356. emitNodeWithCommentsAndWithoutSourcemap(paramName);
  26357. write(" = ");
  26358. emitNodeWithCommentsAndWithoutSourcemap(initializer);
  26359. emitEnd(parameter);
  26360. write("; }");
  26361. }
  26362. });
  26363. }
  26364. }
  26365. function emitRestParameter(node) {
  26366. if (languageVersion < 2 && ts.hasRestParameter(node)) {
  26367. var restIndex = node.parameters.length - 1;
  26368. var restParam = node.parameters[restIndex];
  26369. if (ts.isBindingPattern(restParam.name)) {
  26370. return;
  26371. }
  26372. var tempName = createTempVariable(268435456).text;
  26373. writeLine();
  26374. emitLeadingComments(restParam);
  26375. emitStart(restParam);
  26376. write("var ");
  26377. emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
  26378. write(" = [];");
  26379. emitEnd(restParam);
  26380. emitTrailingComments(restParam);
  26381. writeLine();
  26382. write("for (");
  26383. emitStart(restParam);
  26384. write("var " + tempName + " = " + restIndex + ";");
  26385. emitEnd(restParam);
  26386. write(" ");
  26387. emitStart(restParam);
  26388. write(tempName + " < arguments.length;");
  26389. emitEnd(restParam);
  26390. write(" ");
  26391. emitStart(restParam);
  26392. write(tempName + "++");
  26393. emitEnd(restParam);
  26394. write(") {");
  26395. increaseIndent();
  26396. writeLine();
  26397. emitStart(restParam);
  26398. emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
  26399. write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];");
  26400. emitEnd(restParam);
  26401. decreaseIndent();
  26402. writeLine();
  26403. write("}");
  26404. }
  26405. }
  26406. function emitAccessor(node) {
  26407. write(node.kind === 143 ? "get " : "set ");
  26408. emit(node.name);
  26409. emitSignatureAndBody(node);
  26410. }
  26411. function shouldEmitAsArrowFunction(node) {
  26412. return node.kind === 172 && languageVersion >= 2;
  26413. }
  26414. function emitDeclarationName(node) {
  26415. if (node.name) {
  26416. emitNodeWithCommentsAndWithoutSourcemap(node.name);
  26417. }
  26418. else {
  26419. write(getGeneratedNameForNode(node));
  26420. }
  26421. }
  26422. function shouldEmitFunctionName(node) {
  26423. if (node.kind === 171) {
  26424. return !!node.name;
  26425. }
  26426. if (node.kind === 211) {
  26427. return !!node.name || languageVersion < 2;
  26428. }
  26429. }
  26430. function emitFunctionDeclaration(node) {
  26431. if (ts.nodeIsMissing(node.body)) {
  26432. return emitOnlyPinnedOrTripleSlashComments(node);
  26433. }
  26434. if (node.kind !== 141 && node.kind !== 140 &&
  26435. node.parent && node.parent.kind !== 243 &&
  26436. node.parent.kind !== 166) {
  26437. emitLeadingComments(node);
  26438. }
  26439. emitStart(node);
  26440. if (!shouldEmitAsArrowFunction(node)) {
  26441. if (isES6ExportedDeclaration(node)) {
  26442. write("export ");
  26443. if (node.flags & 1024) {
  26444. write("default ");
  26445. }
  26446. }
  26447. write("function");
  26448. if (languageVersion >= 2 && node.asteriskToken) {
  26449. write("*");
  26450. }
  26451. write(" ");
  26452. }
  26453. if (shouldEmitFunctionName(node)) {
  26454. emitDeclarationName(node);
  26455. }
  26456. emitSignatureAndBody(node);
  26457. if (languageVersion < 2 && node.kind === 211 && node.parent === currentSourceFile && node.name) {
  26458. emitExportMemberAssignments(node.name);
  26459. }
  26460. emitEnd(node);
  26461. if (node.kind !== 141 && node.kind !== 140) {
  26462. emitTrailingComments(node);
  26463. }
  26464. }
  26465. function emitCaptureThisForNodeIfNecessary(node) {
  26466. if (resolver.getNodeCheckFlags(node) & 4) {
  26467. writeLine();
  26468. emitStart(node);
  26469. write("var _this = this;");
  26470. emitEnd(node);
  26471. }
  26472. }
  26473. function emitSignatureParameters(node) {
  26474. increaseIndent();
  26475. write("(");
  26476. if (node) {
  26477. var parameters = node.parameters;
  26478. var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0;
  26479. emitList(parameters, 0, parameters.length - omitCount, false, false);
  26480. }
  26481. write(")");
  26482. decreaseIndent();
  26483. }
  26484. function emitSignatureParametersForArrow(node) {
  26485. if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) {
  26486. emit(node.parameters[0]);
  26487. return;
  26488. }
  26489. emitSignatureParameters(node);
  26490. }
  26491. function emitAsyncFunctionBodyForES6(node) {
  26492. var promiseConstructor = ts.getEntityNameFromTypeNode(node.type);
  26493. var isArrowFunction = node.kind === 172;
  26494. var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096) !== 0;
  26495. var args;
  26496. if (!isArrowFunction) {
  26497. write(" {");
  26498. increaseIndent();
  26499. writeLine();
  26500. write("return");
  26501. }
  26502. write(" __awaiter(this");
  26503. if (hasLexicalArguments) {
  26504. write(", arguments");
  26505. }
  26506. else {
  26507. write(", void 0");
  26508. }
  26509. if (promiseConstructor) {
  26510. write(", ");
  26511. emitNodeWithoutSourceMap(promiseConstructor);
  26512. }
  26513. else {
  26514. write(", Promise");
  26515. }
  26516. if (hasLexicalArguments) {
  26517. write(", function* (_arguments)");
  26518. }
  26519. else {
  26520. write(", function* ()");
  26521. }
  26522. emitFunctionBody(node);
  26523. write(")");
  26524. if (!isArrowFunction) {
  26525. write(";");
  26526. decreaseIndent();
  26527. writeLine();
  26528. write("}");
  26529. }
  26530. }
  26531. function emitFunctionBody(node) {
  26532. if (!node.body) {
  26533. write(" { }");
  26534. }
  26535. else {
  26536. if (node.body.kind === 190) {
  26537. emitBlockFunctionBody(node, node.body);
  26538. }
  26539. else {
  26540. emitExpressionFunctionBody(node, node.body);
  26541. }
  26542. }
  26543. }
  26544. function emitSignatureAndBody(node) {
  26545. var saveTempFlags = tempFlags;
  26546. var saveTempVariables = tempVariables;
  26547. var saveTempParameters = tempParameters;
  26548. tempFlags = 0;
  26549. tempVariables = undefined;
  26550. tempParameters = undefined;
  26551. if (shouldEmitAsArrowFunction(node)) {
  26552. emitSignatureParametersForArrow(node);
  26553. write(" =>");
  26554. }
  26555. else {
  26556. emitSignatureParameters(node);
  26557. }
  26558. var isAsync = ts.isAsyncFunctionLike(node);
  26559. if (isAsync && languageVersion === 2) {
  26560. emitAsyncFunctionBodyForES6(node);
  26561. }
  26562. else {
  26563. emitFunctionBody(node);
  26564. }
  26565. if (!isES6ExportedDeclaration(node)) {
  26566. emitExportMemberAssignment(node);
  26567. }
  26568. tempFlags = saveTempFlags;
  26569. tempVariables = saveTempVariables;
  26570. tempParameters = saveTempParameters;
  26571. }
  26572. function emitFunctionBodyPreamble(node) {
  26573. emitCaptureThisForNodeIfNecessary(node);
  26574. emitDefaultValueAssignments(node);
  26575. emitRestParameter(node);
  26576. }
  26577. function emitExpressionFunctionBody(node, body) {
  26578. if (languageVersion < 2 || node.flags & 512) {
  26579. emitDownLevelExpressionFunctionBody(node, body);
  26580. return;
  26581. }
  26582. write(" ");
  26583. var current = body;
  26584. while (current.kind === 169) {
  26585. current = current.expression;
  26586. }
  26587. emitParenthesizedIf(body, current.kind === 163);
  26588. }
  26589. function emitDownLevelExpressionFunctionBody(node, body) {
  26590. write(" {");
  26591. scopeEmitStart(node);
  26592. increaseIndent();
  26593. var outPos = writer.getTextPos();
  26594. emitDetachedComments(node.body);
  26595. emitFunctionBodyPreamble(node);
  26596. var preambleEmitted = writer.getTextPos() !== outPos;
  26597. decreaseIndent();
  26598. if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) {
  26599. write(" ");
  26600. emitStart(body);
  26601. write("return ");
  26602. emit(body);
  26603. emitEnd(body);
  26604. write(";");
  26605. emitTempDeclarations(false);
  26606. write(" ");
  26607. }
  26608. else {
  26609. increaseIndent();
  26610. writeLine();
  26611. emitLeadingComments(node.body);
  26612. write("return ");
  26613. emit(body);
  26614. write(";");
  26615. emitTrailingComments(node.body);
  26616. emitTempDeclarations(true);
  26617. decreaseIndent();
  26618. writeLine();
  26619. }
  26620. emitStart(node.body);
  26621. write("}");
  26622. emitEnd(node.body);
  26623. scopeEmitEnd();
  26624. }
  26625. function emitBlockFunctionBody(node, body) {
  26626. write(" {");
  26627. scopeEmitStart(node);
  26628. var initialTextPos = writer.getTextPos();
  26629. increaseIndent();
  26630. emitDetachedComments(body.statements);
  26631. var startIndex = emitDirectivePrologues(body.statements, true);
  26632. emitFunctionBodyPreamble(node);
  26633. decreaseIndent();
  26634. var preambleEmitted = writer.getTextPos() !== initialTextPos;
  26635. if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
  26636. for (var _a = 0, _b = body.statements; _a < _b.length; _a++) {
  26637. var statement = _b[_a];
  26638. write(" ");
  26639. emit(statement);
  26640. }
  26641. emitTempDeclarations(false);
  26642. write(" ");
  26643. emitLeadingCommentsOfPosition(body.statements.end);
  26644. }
  26645. else {
  26646. increaseIndent();
  26647. emitLinesStartingAt(body.statements, startIndex);
  26648. emitTempDeclarations(true);
  26649. writeLine();
  26650. emitLeadingCommentsOfPosition(body.statements.end);
  26651. decreaseIndent();
  26652. }
  26653. emitToken(16, body.statements.end);
  26654. scopeEmitEnd();
  26655. }
  26656. function findInitialSuperCall(ctor) {
  26657. if (ctor.body) {
  26658. var statement = ctor.body.statements[0];
  26659. if (statement && statement.kind === 193) {
  26660. var expr = statement.expression;
  26661. if (expr && expr.kind === 166) {
  26662. var func = expr.expression;
  26663. if (func && func.kind === 93) {
  26664. return statement;
  26665. }
  26666. }
  26667. }
  26668. }
  26669. }
  26670. function emitParameterPropertyAssignments(node) {
  26671. ts.forEach(node.parameters, function (param) {
  26672. if (param.flags & 112) {
  26673. writeLine();
  26674. emitStart(param);
  26675. emitStart(param.name);
  26676. write("this.");
  26677. emitNodeWithoutSourceMap(param.name);
  26678. emitEnd(param.name);
  26679. write(" = ");
  26680. emit(param.name);
  26681. write(";");
  26682. emitEnd(param);
  26683. }
  26684. });
  26685. }
  26686. function emitMemberAccessForPropertyName(memberName) {
  26687. if (memberName.kind === 9 || memberName.kind === 8) {
  26688. write("[");
  26689. emitNodeWithCommentsAndWithoutSourcemap(memberName);
  26690. write("]");
  26691. }
  26692. else if (memberName.kind === 134) {
  26693. emitComputedPropertyName(memberName);
  26694. }
  26695. else {
  26696. write(".");
  26697. emitNodeWithCommentsAndWithoutSourcemap(memberName);
  26698. }
  26699. }
  26700. function getInitializedProperties(node, isStatic) {
  26701. var properties = [];
  26702. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  26703. var member = _b[_a];
  26704. if (member.kind === 139 && isStatic === ((member.flags & 128) !== 0) && member.initializer) {
  26705. properties.push(member);
  26706. }
  26707. }
  26708. return properties;
  26709. }
  26710. function emitPropertyDeclarations(node, properties) {
  26711. for (var _a = 0; _a < properties.length; _a++) {
  26712. var property = properties[_a];
  26713. emitPropertyDeclaration(node, property);
  26714. }
  26715. }
  26716. function emitPropertyDeclaration(node, property, receiver, isExpression) {
  26717. writeLine();
  26718. emitLeadingComments(property);
  26719. emitStart(property);
  26720. emitStart(property.name);
  26721. if (receiver) {
  26722. emit(receiver);
  26723. }
  26724. else {
  26725. if (property.flags & 128) {
  26726. emitDeclarationName(node);
  26727. }
  26728. else {
  26729. write("this");
  26730. }
  26731. }
  26732. emitMemberAccessForPropertyName(property.name);
  26733. emitEnd(property.name);
  26734. write(" = ");
  26735. emit(property.initializer);
  26736. if (!isExpression) {
  26737. write(";");
  26738. }
  26739. emitEnd(property);
  26740. emitTrailingComments(property);
  26741. }
  26742. function emitMemberFunctionsForES5AndLower(node) {
  26743. ts.forEach(node.members, function (member) {
  26744. if (member.kind === 189) {
  26745. writeLine();
  26746. write(";");
  26747. }
  26748. else if (member.kind === 141 || node.kind === 140) {
  26749. if (!member.body) {
  26750. return emitOnlyPinnedOrTripleSlashComments(member);
  26751. }
  26752. writeLine();
  26753. emitLeadingComments(member);
  26754. emitStart(member);
  26755. emitStart(member.name);
  26756. emitClassMemberPrefix(node, member);
  26757. emitMemberAccessForPropertyName(member.name);
  26758. emitEnd(member.name);
  26759. write(" = ");
  26760. emitFunctionDeclaration(member);
  26761. emitEnd(member);
  26762. write(";");
  26763. emitTrailingComments(member);
  26764. }
  26765. else if (member.kind === 143 || member.kind === 144) {
  26766. var accessors = ts.getAllAccessorDeclarations(node.members, member);
  26767. if (member === accessors.firstAccessor) {
  26768. writeLine();
  26769. emitStart(member);
  26770. write("Object.defineProperty(");
  26771. emitStart(member.name);
  26772. emitClassMemberPrefix(node, member);
  26773. write(", ");
  26774. emitExpressionForPropertyName(member.name);
  26775. emitEnd(member.name);
  26776. write(", {");
  26777. increaseIndent();
  26778. if (accessors.getAccessor) {
  26779. writeLine();
  26780. emitLeadingComments(accessors.getAccessor);
  26781. write("get: ");
  26782. emitStart(accessors.getAccessor);
  26783. write("function ");
  26784. emitSignatureAndBody(accessors.getAccessor);
  26785. emitEnd(accessors.getAccessor);
  26786. emitTrailingComments(accessors.getAccessor);
  26787. write(",");
  26788. }
  26789. if (accessors.setAccessor) {
  26790. writeLine();
  26791. emitLeadingComments(accessors.setAccessor);
  26792. write("set: ");
  26793. emitStart(accessors.setAccessor);
  26794. write("function ");
  26795. emitSignatureAndBody(accessors.setAccessor);
  26796. emitEnd(accessors.setAccessor);
  26797. emitTrailingComments(accessors.setAccessor);
  26798. write(",");
  26799. }
  26800. writeLine();
  26801. write("enumerable: true,");
  26802. writeLine();
  26803. write("configurable: true");
  26804. decreaseIndent();
  26805. writeLine();
  26806. write("});");
  26807. emitEnd(member);
  26808. }
  26809. }
  26810. });
  26811. }
  26812. function emitMemberFunctionsForES6AndHigher(node) {
  26813. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  26814. var member = _b[_a];
  26815. if ((member.kind === 141 || node.kind === 140) && !member.body) {
  26816. emitOnlyPinnedOrTripleSlashComments(member);
  26817. }
  26818. else if (member.kind === 141 ||
  26819. member.kind === 143 ||
  26820. member.kind === 144) {
  26821. writeLine();
  26822. emitLeadingComments(member);
  26823. emitStart(member);
  26824. if (member.flags & 128) {
  26825. write("static ");
  26826. }
  26827. if (member.kind === 143) {
  26828. write("get ");
  26829. }
  26830. else if (member.kind === 144) {
  26831. write("set ");
  26832. }
  26833. if (member.asteriskToken) {
  26834. write("*");
  26835. }
  26836. emit(member.name);
  26837. emitSignatureAndBody(member);
  26838. emitEnd(member);
  26839. emitTrailingComments(member);
  26840. }
  26841. else if (member.kind === 189) {
  26842. writeLine();
  26843. write(";");
  26844. }
  26845. }
  26846. }
  26847. function emitConstructor(node, baseTypeElement) {
  26848. var saveTempFlags = tempFlags;
  26849. var saveTempVariables = tempVariables;
  26850. var saveTempParameters = tempParameters;
  26851. tempFlags = 0;
  26852. tempVariables = undefined;
  26853. tempParameters = undefined;
  26854. emitConstructorWorker(node, baseTypeElement);
  26855. tempFlags = saveTempFlags;
  26856. tempVariables = saveTempVariables;
  26857. tempParameters = saveTempParameters;
  26858. }
  26859. function emitConstructorWorker(node, baseTypeElement) {
  26860. var hasInstancePropertyWithInitializer = false;
  26861. ts.forEach(node.members, function (member) {
  26862. if (member.kind === 142 && !member.body) {
  26863. emitOnlyPinnedOrTripleSlashComments(member);
  26864. }
  26865. if (member.kind === 139 && member.initializer && (member.flags & 128) === 0) {
  26866. hasInstancePropertyWithInitializer = true;
  26867. }
  26868. });
  26869. var ctor = ts.getFirstConstructorWithBody(node);
  26870. if (languageVersion >= 2 && !ctor && !hasInstancePropertyWithInitializer) {
  26871. return;
  26872. }
  26873. if (ctor) {
  26874. emitLeadingComments(ctor);
  26875. }
  26876. emitStart(ctor || node);
  26877. if (languageVersion < 2) {
  26878. write("function ");
  26879. emitDeclarationName(node);
  26880. emitSignatureParameters(ctor);
  26881. }
  26882. else {
  26883. write("constructor");
  26884. if (ctor) {
  26885. emitSignatureParameters(ctor);
  26886. }
  26887. else {
  26888. if (baseTypeElement) {
  26889. write("(...args)");
  26890. }
  26891. else {
  26892. write("()");
  26893. }
  26894. }
  26895. }
  26896. var startIndex = 0;
  26897. write(" {");
  26898. scopeEmitStart(node, "constructor");
  26899. increaseIndent();
  26900. if (ctor) {
  26901. startIndex = emitDirectivePrologues(ctor.body.statements, true);
  26902. emitDetachedComments(ctor.body.statements);
  26903. }
  26904. emitCaptureThisForNodeIfNecessary(node);
  26905. var superCall;
  26906. if (ctor) {
  26907. emitDefaultValueAssignments(ctor);
  26908. emitRestParameter(ctor);
  26909. if (baseTypeElement) {
  26910. superCall = findInitialSuperCall(ctor);
  26911. if (superCall) {
  26912. writeLine();
  26913. emit(superCall);
  26914. }
  26915. }
  26916. emitParameterPropertyAssignments(ctor);
  26917. }
  26918. else {
  26919. if (baseTypeElement) {
  26920. writeLine();
  26921. emitStart(baseTypeElement);
  26922. if (languageVersion < 2) {
  26923. write("_super.apply(this, arguments);");
  26924. }
  26925. else {
  26926. write("super(...args);");
  26927. }
  26928. emitEnd(baseTypeElement);
  26929. }
  26930. }
  26931. emitPropertyDeclarations(node, getInitializedProperties(node, false));
  26932. if (ctor) {
  26933. var statements = ctor.body.statements;
  26934. if (superCall) {
  26935. statements = statements.slice(1);
  26936. }
  26937. emitLinesStartingAt(statements, startIndex);
  26938. }
  26939. emitTempDeclarations(true);
  26940. writeLine();
  26941. if (ctor) {
  26942. emitLeadingCommentsOfPosition(ctor.body.statements.end);
  26943. }
  26944. decreaseIndent();
  26945. emitToken(16, ctor ? ctor.body.statements.end : node.members.end);
  26946. scopeEmitEnd();
  26947. emitEnd(ctor || node);
  26948. if (ctor) {
  26949. emitTrailingComments(ctor);
  26950. }
  26951. }
  26952. function emitClassExpression(node) {
  26953. return emitClassLikeDeclaration(node);
  26954. }
  26955. function emitClassDeclaration(node) {
  26956. return emitClassLikeDeclaration(node);
  26957. }
  26958. function emitClassLikeDeclaration(node) {
  26959. if (languageVersion < 2) {
  26960. emitClassLikeDeclarationBelowES6(node);
  26961. }
  26962. else {
  26963. emitClassLikeDeclarationForES6AndHigher(node);
  26964. }
  26965. }
  26966. function emitClassLikeDeclarationForES6AndHigher(node) {
  26967. var thisNodeIsDecorated = ts.nodeIsDecorated(node);
  26968. if (node.kind === 212) {
  26969. if (thisNodeIsDecorated) {
  26970. if (isES6ExportedDeclaration(node) && !(node.flags & 1024)) {
  26971. write("export ");
  26972. }
  26973. write("let ");
  26974. emitDeclarationName(node);
  26975. write(" = ");
  26976. }
  26977. else if (isES6ExportedDeclaration(node)) {
  26978. write("export ");
  26979. if (node.flags & 1024) {
  26980. write("default ");
  26981. }
  26982. }
  26983. }
  26984. var staticProperties = getInitializedProperties(node, true);
  26985. var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 184;
  26986. var tempVariable;
  26987. if (isClassExpressionWithStaticProperties) {
  26988. tempVariable = createAndRecordTempVariable(0);
  26989. write("(");
  26990. increaseIndent();
  26991. emit(tempVariable);
  26992. write(" = ");
  26993. }
  26994. write("class");
  26995. if ((node.name || !(node.flags & 1024)) && !thisNodeIsDecorated) {
  26996. write(" ");
  26997. emitDeclarationName(node);
  26998. }
  26999. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  27000. if (baseTypeNode) {
  27001. write(" extends ");
  27002. emit(baseTypeNode.expression);
  27003. }
  27004. write(" {");
  27005. increaseIndent();
  27006. scopeEmitStart(node);
  27007. writeLine();
  27008. emitConstructor(node, baseTypeNode);
  27009. emitMemberFunctionsForES6AndHigher(node);
  27010. decreaseIndent();
  27011. writeLine();
  27012. emitToken(16, node.members.end);
  27013. scopeEmitEnd();
  27014. if (thisNodeIsDecorated) {
  27015. write(";");
  27016. }
  27017. if (isClassExpressionWithStaticProperties) {
  27018. for (var _a = 0; _a < staticProperties.length; _a++) {
  27019. var property = staticProperties[_a];
  27020. write(",");
  27021. writeLine();
  27022. emitPropertyDeclaration(node, property, tempVariable, true);
  27023. }
  27024. write(",");
  27025. writeLine();
  27026. emit(tempVariable);
  27027. decreaseIndent();
  27028. write(")");
  27029. }
  27030. else {
  27031. writeLine();
  27032. emitPropertyDeclarations(node, staticProperties);
  27033. emitDecoratorsOfClass(node);
  27034. }
  27035. if (!isES6ExportedDeclaration(node) && (node.flags & 1)) {
  27036. writeLine();
  27037. emitStart(node);
  27038. emitModuleMemberName(node);
  27039. write(" = ");
  27040. emitDeclarationName(node);
  27041. emitEnd(node);
  27042. write(";");
  27043. }
  27044. else if (isES6ExportedDeclaration(node) && (node.flags & 1024) && thisNodeIsDecorated) {
  27045. writeLine();
  27046. write("export default ");
  27047. emitDeclarationName(node);
  27048. write(";");
  27049. }
  27050. }
  27051. function emitClassLikeDeclarationBelowES6(node) {
  27052. if (node.kind === 212) {
  27053. if (!shouldHoistDeclarationInSystemJsModule(node)) {
  27054. write("var ");
  27055. }
  27056. emitDeclarationName(node);
  27057. write(" = ");
  27058. }
  27059. write("(function (");
  27060. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  27061. if (baseTypeNode) {
  27062. write("_super");
  27063. }
  27064. write(") {");
  27065. var saveTempFlags = tempFlags;
  27066. var saveTempVariables = tempVariables;
  27067. var saveTempParameters = tempParameters;
  27068. var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames;
  27069. tempFlags = 0;
  27070. tempVariables = undefined;
  27071. tempParameters = undefined;
  27072. computedPropertyNamesToGeneratedNames = undefined;
  27073. increaseIndent();
  27074. scopeEmitStart(node);
  27075. if (baseTypeNode) {
  27076. writeLine();
  27077. emitStart(baseTypeNode);
  27078. write("__extends(");
  27079. emitDeclarationName(node);
  27080. write(", _super);");
  27081. emitEnd(baseTypeNode);
  27082. }
  27083. writeLine();
  27084. emitConstructor(node, baseTypeNode);
  27085. emitMemberFunctionsForES5AndLower(node);
  27086. emitPropertyDeclarations(node, getInitializedProperties(node, true));
  27087. writeLine();
  27088. emitDecoratorsOfClass(node);
  27089. writeLine();
  27090. emitToken(16, node.members.end, function () {
  27091. write("return ");
  27092. emitDeclarationName(node);
  27093. });
  27094. write(";");
  27095. emitTempDeclarations(true);
  27096. tempFlags = saveTempFlags;
  27097. tempVariables = saveTempVariables;
  27098. tempParameters = saveTempParameters;
  27099. computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames;
  27100. decreaseIndent();
  27101. writeLine();
  27102. emitToken(16, node.members.end);
  27103. scopeEmitEnd();
  27104. emitStart(node);
  27105. write(")(");
  27106. if (baseTypeNode) {
  27107. emit(baseTypeNode.expression);
  27108. }
  27109. write(")");
  27110. if (node.kind === 212) {
  27111. write(";");
  27112. }
  27113. emitEnd(node);
  27114. if (node.kind === 212) {
  27115. emitExportMemberAssignment(node);
  27116. }
  27117. if (languageVersion < 2 && node.parent === currentSourceFile && node.name) {
  27118. emitExportMemberAssignments(node.name);
  27119. }
  27120. }
  27121. function emitClassMemberPrefix(node, member) {
  27122. emitDeclarationName(node);
  27123. if (!(member.flags & 128)) {
  27124. write(".prototype");
  27125. }
  27126. }
  27127. function emitDecoratorsOfClass(node) {
  27128. emitDecoratorsOfMembers(node, 0);
  27129. emitDecoratorsOfMembers(node, 128);
  27130. emitDecoratorsOfConstructor(node);
  27131. }
  27132. function emitDecoratorsOfConstructor(node) {
  27133. var decorators = node.decorators;
  27134. var constructor = ts.getFirstConstructorWithBody(node);
  27135. var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated);
  27136. if (!decorators && !hasDecoratedParameters) {
  27137. return;
  27138. }
  27139. writeLine();
  27140. emitStart(node);
  27141. emitDeclarationName(node);
  27142. write(" = __decorate([");
  27143. increaseIndent();
  27144. writeLine();
  27145. var decoratorCount = decorators ? decorators.length : 0;
  27146. var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) {
  27147. emitStart(decorator);
  27148. emit(decorator.expression);
  27149. emitEnd(decorator);
  27150. });
  27151. argumentsWritten += emitDecoratorsOfParameters(constructor, argumentsWritten > 0);
  27152. emitSerializedTypeMetadata(node, argumentsWritten >= 0);
  27153. decreaseIndent();
  27154. writeLine();
  27155. write("], ");
  27156. emitDeclarationName(node);
  27157. write(");");
  27158. emitEnd(node);
  27159. writeLine();
  27160. }
  27161. function emitDecoratorsOfMembers(node, staticFlag) {
  27162. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  27163. var member = _b[_a];
  27164. if ((member.flags & 128) !== staticFlag) {
  27165. continue;
  27166. }
  27167. if (!ts.nodeCanBeDecorated(member)) {
  27168. continue;
  27169. }
  27170. if (!ts.nodeOrChildIsDecorated(member)) {
  27171. continue;
  27172. }
  27173. var decorators = void 0;
  27174. var functionLikeMember = void 0;
  27175. if (ts.isAccessor(member)) {
  27176. var accessors = ts.getAllAccessorDeclarations(node.members, member);
  27177. if (member !== accessors.firstAccessor) {
  27178. continue;
  27179. }
  27180. decorators = accessors.firstAccessor.decorators;
  27181. if (!decorators && accessors.secondAccessor) {
  27182. decorators = accessors.secondAccessor.decorators;
  27183. }
  27184. functionLikeMember = accessors.setAccessor;
  27185. }
  27186. else {
  27187. decorators = member.decorators;
  27188. if (member.kind === 141) {
  27189. functionLikeMember = member;
  27190. }
  27191. }
  27192. writeLine();
  27193. emitStart(member);
  27194. if (member.kind !== 139) {
  27195. write("Object.defineProperty(");
  27196. emitStart(member.name);
  27197. emitClassMemberPrefix(node, member);
  27198. write(", ");
  27199. emitExpressionForPropertyName(member.name);
  27200. emitEnd(member.name);
  27201. write(",");
  27202. increaseIndent();
  27203. writeLine();
  27204. }
  27205. write("__decorate([");
  27206. increaseIndent();
  27207. writeLine();
  27208. var decoratorCount = decorators ? decorators.length : 0;
  27209. var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) {
  27210. emitStart(decorator);
  27211. emit(decorator.expression);
  27212. emitEnd(decorator);
  27213. });
  27214. argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0);
  27215. emitSerializedTypeMetadata(member, argumentsWritten > 0);
  27216. decreaseIndent();
  27217. writeLine();
  27218. write("], ");
  27219. emitStart(member.name);
  27220. emitClassMemberPrefix(node, member);
  27221. write(", ");
  27222. emitExpressionForPropertyName(member.name);
  27223. emitEnd(member.name);
  27224. if (member.kind !== 139) {
  27225. write(", Object.getOwnPropertyDescriptor(");
  27226. emitStart(member.name);
  27227. emitClassMemberPrefix(node, member);
  27228. write(", ");
  27229. emitExpressionForPropertyName(member.name);
  27230. emitEnd(member.name);
  27231. write("))");
  27232. decreaseIndent();
  27233. }
  27234. write(");");
  27235. emitEnd(member);
  27236. writeLine();
  27237. }
  27238. }
  27239. function emitDecoratorsOfParameters(node, leadingComma) {
  27240. var argumentsWritten = 0;
  27241. if (node) {
  27242. var parameterIndex = 0;
  27243. for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) {
  27244. var parameter = _b[_a];
  27245. if (ts.nodeIsDecorated(parameter)) {
  27246. var decorators = parameter.decorators;
  27247. argumentsWritten += emitList(decorators, 0, decorators.length, true, false, leadingComma, true, function (decorator) {
  27248. emitStart(decorator);
  27249. write("__param(" + parameterIndex + ", ");
  27250. emit(decorator.expression);
  27251. write(")");
  27252. emitEnd(decorator);
  27253. });
  27254. leadingComma = true;
  27255. }
  27256. ++parameterIndex;
  27257. }
  27258. }
  27259. return argumentsWritten;
  27260. }
  27261. function shouldEmitTypeMetadata(node) {
  27262. switch (node.kind) {
  27263. case 141:
  27264. case 143:
  27265. case 144:
  27266. case 139:
  27267. return true;
  27268. }
  27269. return false;
  27270. }
  27271. function shouldEmitReturnTypeMetadata(node) {
  27272. switch (node.kind) {
  27273. case 141:
  27274. return true;
  27275. }
  27276. return false;
  27277. }
  27278. function shouldEmitParamTypesMetadata(node) {
  27279. switch (node.kind) {
  27280. case 212:
  27281. case 141:
  27282. case 144:
  27283. return true;
  27284. }
  27285. return false;
  27286. }
  27287. function emitSerializedTypeOfNode(node) {
  27288. switch (node.kind) {
  27289. case 212:
  27290. write("Function");
  27291. return;
  27292. case 139:
  27293. emitSerializedTypeNode(node.type);
  27294. return;
  27295. case 136:
  27296. emitSerializedTypeNode(node.type);
  27297. return;
  27298. case 143:
  27299. emitSerializedTypeNode(node.type);
  27300. return;
  27301. case 144:
  27302. emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node));
  27303. return;
  27304. }
  27305. if (ts.isFunctionLike(node)) {
  27306. write("Function");
  27307. return;
  27308. }
  27309. write("void 0");
  27310. }
  27311. function emitSerializedTypeNode(node) {
  27312. if (node) {
  27313. switch (node.kind) {
  27314. case 101:
  27315. write("void 0");
  27316. return;
  27317. case 158:
  27318. emitSerializedTypeNode(node.type);
  27319. return;
  27320. case 150:
  27321. case 151:
  27322. write("Function");
  27323. return;
  27324. case 154:
  27325. case 155:
  27326. write("Array");
  27327. return;
  27328. case 148:
  27329. case 118:
  27330. write("Boolean");
  27331. return;
  27332. case 128:
  27333. case 9:
  27334. write("String");
  27335. return;
  27336. case 126:
  27337. write("Number");
  27338. return;
  27339. case 129:
  27340. write("Symbol");
  27341. return;
  27342. case 149:
  27343. emitSerializedTypeReferenceNode(node);
  27344. return;
  27345. case 152:
  27346. case 153:
  27347. case 156:
  27348. case 157:
  27349. case 115:
  27350. break;
  27351. default:
  27352. ts.Debug.fail("Cannot serialize unexpected type node.");
  27353. break;
  27354. }
  27355. }
  27356. write("Object");
  27357. }
  27358. function emitSerializedTypeReferenceNode(node) {
  27359. var location = node.parent;
  27360. while (ts.isDeclaration(location) || ts.isTypeNode(location)) {
  27361. location = location.parent;
  27362. }
  27363. var typeName = ts.cloneEntityName(node.typeName);
  27364. typeName.parent = location;
  27365. var result = resolver.getTypeReferenceSerializationKind(typeName);
  27366. switch (result) {
  27367. case ts.TypeReferenceSerializationKind.Unknown:
  27368. var temp = createAndRecordTempVariable(0);
  27369. write("(typeof (");
  27370. emitNodeWithoutSourceMap(temp);
  27371. write(" = ");
  27372. emitEntityNameAsExpression(typeName, true);
  27373. write(") === 'function' && ");
  27374. emitNodeWithoutSourceMap(temp);
  27375. write(") || Object");
  27376. break;
  27377. case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue:
  27378. emitEntityNameAsExpression(typeName, false);
  27379. break;
  27380. case ts.TypeReferenceSerializationKind.VoidType:
  27381. write("void 0");
  27382. break;
  27383. case ts.TypeReferenceSerializationKind.BooleanType:
  27384. write("Boolean");
  27385. break;
  27386. case ts.TypeReferenceSerializationKind.NumberLikeType:
  27387. write("Number");
  27388. break;
  27389. case ts.TypeReferenceSerializationKind.StringLikeType:
  27390. write("String");
  27391. break;
  27392. case ts.TypeReferenceSerializationKind.ArrayLikeType:
  27393. write("Array");
  27394. break;
  27395. case ts.TypeReferenceSerializationKind.ESSymbolType:
  27396. if (languageVersion < 2) {
  27397. write("typeof Symbol === 'function' ? Symbol : Object");
  27398. }
  27399. else {
  27400. write("Symbol");
  27401. }
  27402. break;
  27403. case ts.TypeReferenceSerializationKind.TypeWithCallSignature:
  27404. write("Function");
  27405. break;
  27406. case ts.TypeReferenceSerializationKind.ObjectType:
  27407. write("Object");
  27408. break;
  27409. }
  27410. }
  27411. function emitSerializedParameterTypesOfNode(node) {
  27412. if (node) {
  27413. var valueDeclaration;
  27414. if (node.kind === 212) {
  27415. valueDeclaration = ts.getFirstConstructorWithBody(node);
  27416. }
  27417. else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) {
  27418. valueDeclaration = node;
  27419. }
  27420. if (valueDeclaration) {
  27421. var parameters = valueDeclaration.parameters;
  27422. var parameterCount = parameters.length;
  27423. if (parameterCount > 0) {
  27424. for (var i = 0; i < parameterCount; i++) {
  27425. if (i > 0) {
  27426. write(", ");
  27427. }
  27428. if (parameters[i].dotDotDotToken) {
  27429. var parameterType = parameters[i].type;
  27430. if (parameterType.kind === 154) {
  27431. parameterType = parameterType.elementType;
  27432. }
  27433. else if (parameterType.kind === 149 && parameterType.typeArguments && parameterType.typeArguments.length === 1) {
  27434. parameterType = parameterType.typeArguments[0];
  27435. }
  27436. else {
  27437. parameterType = undefined;
  27438. }
  27439. emitSerializedTypeNode(parameterType);
  27440. }
  27441. else {
  27442. emitSerializedTypeOfNode(parameters[i]);
  27443. }
  27444. }
  27445. }
  27446. }
  27447. }
  27448. }
  27449. function emitSerializedReturnTypeOfNode(node) {
  27450. if (node && ts.isFunctionLike(node) && node.type) {
  27451. emitSerializedTypeNode(node.type);
  27452. return;
  27453. }
  27454. write("void 0");
  27455. }
  27456. function emitSerializedTypeMetadata(node, writeComma) {
  27457. var argumentsWritten = 0;
  27458. if (compilerOptions.emitDecoratorMetadata) {
  27459. if (shouldEmitTypeMetadata(node)) {
  27460. if (writeComma) {
  27461. write(", ");
  27462. }
  27463. writeLine();
  27464. write("__metadata('design:type', ");
  27465. emitSerializedTypeOfNode(node);
  27466. write(")");
  27467. argumentsWritten++;
  27468. }
  27469. if (shouldEmitParamTypesMetadata(node)) {
  27470. if (writeComma || argumentsWritten) {
  27471. write(", ");
  27472. }
  27473. writeLine();
  27474. write("__metadata('design:paramtypes', [");
  27475. emitSerializedParameterTypesOfNode(node);
  27476. write("])");
  27477. argumentsWritten++;
  27478. }
  27479. if (shouldEmitReturnTypeMetadata(node)) {
  27480. if (writeComma || argumentsWritten) {
  27481. write(", ");
  27482. }
  27483. writeLine();
  27484. write("__metadata('design:returntype', ");
  27485. emitSerializedReturnTypeOfNode(node);
  27486. write(")");
  27487. argumentsWritten++;
  27488. }
  27489. }
  27490. return argumentsWritten;
  27491. }
  27492. function emitInterfaceDeclaration(node) {
  27493. emitOnlyPinnedOrTripleSlashComments(node);
  27494. }
  27495. function shouldEmitEnumDeclaration(node) {
  27496. var isConstEnum = ts.isConst(node);
  27497. return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules;
  27498. }
  27499. function emitEnumDeclaration(node) {
  27500. if (!shouldEmitEnumDeclaration(node)) {
  27501. return;
  27502. }
  27503. if (!shouldHoistDeclarationInSystemJsModule(node)) {
  27504. if (!(node.flags & 1) || isES6ExportedDeclaration(node)) {
  27505. emitStart(node);
  27506. if (isES6ExportedDeclaration(node)) {
  27507. write("export ");
  27508. }
  27509. write("var ");
  27510. emit(node.name);
  27511. emitEnd(node);
  27512. write(";");
  27513. }
  27514. }
  27515. writeLine();
  27516. emitStart(node);
  27517. write("(function (");
  27518. emitStart(node.name);
  27519. write(getGeneratedNameForNode(node));
  27520. emitEnd(node.name);
  27521. write(") {");
  27522. increaseIndent();
  27523. scopeEmitStart(node);
  27524. emitLines(node.members);
  27525. decreaseIndent();
  27526. writeLine();
  27527. emitToken(16, node.members.end);
  27528. scopeEmitEnd();
  27529. write(")(");
  27530. emitModuleMemberName(node);
  27531. write(" || (");
  27532. emitModuleMemberName(node);
  27533. write(" = {}));");
  27534. emitEnd(node);
  27535. if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) {
  27536. writeLine();
  27537. emitStart(node);
  27538. write("var ");
  27539. emit(node.name);
  27540. write(" = ");
  27541. emitModuleMemberName(node);
  27542. emitEnd(node);
  27543. write(";");
  27544. }
  27545. if (languageVersion < 2 && node.parent === currentSourceFile) {
  27546. if (compilerOptions.module === 4 && (node.flags & 1)) {
  27547. writeLine();
  27548. write(exportFunctionForFile + "(\"");
  27549. emitDeclarationName(node);
  27550. write("\", ");
  27551. emitDeclarationName(node);
  27552. write(");");
  27553. }
  27554. emitExportMemberAssignments(node.name);
  27555. }
  27556. }
  27557. function emitEnumMember(node) {
  27558. var enumParent = node.parent;
  27559. emitStart(node);
  27560. write(getGeneratedNameForNode(enumParent));
  27561. write("[");
  27562. write(getGeneratedNameForNode(enumParent));
  27563. write("[");
  27564. emitExpressionForPropertyName(node.name);
  27565. write("] = ");
  27566. writeEnumMemberDeclarationValue(node);
  27567. write("] = ");
  27568. emitExpressionForPropertyName(node.name);
  27569. emitEnd(node);
  27570. write(";");
  27571. }
  27572. function writeEnumMemberDeclarationValue(member) {
  27573. var value = resolver.getConstantValue(member);
  27574. if (value !== undefined) {
  27575. write(value.toString());
  27576. return;
  27577. }
  27578. else if (member.initializer) {
  27579. emit(member.initializer);
  27580. }
  27581. else {
  27582. write("undefined");
  27583. }
  27584. }
  27585. function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) {
  27586. if (moduleDeclaration.body.kind === 216) {
  27587. var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body);
  27588. return recursiveInnerModule || moduleDeclaration.body;
  27589. }
  27590. }
  27591. function shouldEmitModuleDeclaration(node) {
  27592. return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules);
  27593. }
  27594. function isModuleMergedWithES6Class(node) {
  27595. return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 32768);
  27596. }
  27597. function emitModuleDeclaration(node) {
  27598. var shouldEmit = shouldEmitModuleDeclaration(node);
  27599. if (!shouldEmit) {
  27600. return emitOnlyPinnedOrTripleSlashComments(node);
  27601. }
  27602. var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node);
  27603. var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node);
  27604. if (emitVarForModule) {
  27605. emitStart(node);
  27606. if (isES6ExportedDeclaration(node)) {
  27607. write("export ");
  27608. }
  27609. write("var ");
  27610. emit(node.name);
  27611. write(";");
  27612. emitEnd(node);
  27613. writeLine();
  27614. }
  27615. emitStart(node);
  27616. write("(function (");
  27617. emitStart(node.name);
  27618. write(getGeneratedNameForNode(node));
  27619. emitEnd(node.name);
  27620. write(") ");
  27621. if (node.body.kind === 217) {
  27622. var saveTempFlags = tempFlags;
  27623. var saveTempVariables = tempVariables;
  27624. tempFlags = 0;
  27625. tempVariables = undefined;
  27626. emit(node.body);
  27627. tempFlags = saveTempFlags;
  27628. tempVariables = saveTempVariables;
  27629. }
  27630. else {
  27631. write("{");
  27632. increaseIndent();
  27633. scopeEmitStart(node);
  27634. emitCaptureThisForNodeIfNecessary(node);
  27635. writeLine();
  27636. emit(node.body);
  27637. decreaseIndent();
  27638. writeLine();
  27639. var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body;
  27640. emitToken(16, moduleBlock.statements.end);
  27641. scopeEmitEnd();
  27642. }
  27643. write(")(");
  27644. if ((node.flags & 1) && !isES6ExportedDeclaration(node)) {
  27645. emit(node.name);
  27646. write(" = ");
  27647. }
  27648. emitModuleMemberName(node);
  27649. write(" || (");
  27650. emitModuleMemberName(node);
  27651. write(" = {}));");
  27652. emitEnd(node);
  27653. if (!isES6ExportedDeclaration(node) && node.name.kind === 67 && node.parent === currentSourceFile) {
  27654. if (compilerOptions.module === 4 && (node.flags & 1)) {
  27655. writeLine();
  27656. write(exportFunctionForFile + "(\"");
  27657. emitDeclarationName(node);
  27658. write("\", ");
  27659. emitDeclarationName(node);
  27660. write(");");
  27661. }
  27662. emitExportMemberAssignments(node.name);
  27663. }
  27664. }
  27665. function tryRenameExternalModule(moduleName) {
  27666. if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) {
  27667. return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\"";
  27668. }
  27669. return undefined;
  27670. }
  27671. function emitRequire(moduleName) {
  27672. if (moduleName.kind === 9) {
  27673. write("require(");
  27674. var text = tryRenameExternalModule(moduleName);
  27675. if (text) {
  27676. write(text);
  27677. }
  27678. else {
  27679. emitStart(moduleName);
  27680. emitLiteral(moduleName);
  27681. emitEnd(moduleName);
  27682. }
  27683. emitToken(18, moduleName.end);
  27684. }
  27685. else {
  27686. write("require()");
  27687. }
  27688. }
  27689. function getNamespaceDeclarationNode(node) {
  27690. if (node.kind === 219) {
  27691. return node;
  27692. }
  27693. var importClause = node.importClause;
  27694. if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 222) {
  27695. return importClause.namedBindings;
  27696. }
  27697. }
  27698. function isDefaultImport(node) {
  27699. return node.kind === 220 && node.importClause && !!node.importClause.name;
  27700. }
  27701. function emitExportImportAssignments(node) {
  27702. if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) {
  27703. emitExportMemberAssignments(node.name);
  27704. }
  27705. ts.forEachChild(node, emitExportImportAssignments);
  27706. }
  27707. function emitImportDeclaration(node) {
  27708. if (languageVersion < 2) {
  27709. return emitExternalImportDeclaration(node);
  27710. }
  27711. if (node.importClause) {
  27712. var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause);
  27713. var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, true);
  27714. if (shouldEmitDefaultBindings || shouldEmitNamedBindings) {
  27715. write("import ");
  27716. emitStart(node.importClause);
  27717. if (shouldEmitDefaultBindings) {
  27718. emit(node.importClause.name);
  27719. if (shouldEmitNamedBindings) {
  27720. write(", ");
  27721. }
  27722. }
  27723. if (shouldEmitNamedBindings) {
  27724. emitLeadingComments(node.importClause.namedBindings);
  27725. emitStart(node.importClause.namedBindings);
  27726. if (node.importClause.namedBindings.kind === 222) {
  27727. write("* as ");
  27728. emit(node.importClause.namedBindings.name);
  27729. }
  27730. else {
  27731. write("{ ");
  27732. emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration);
  27733. write(" }");
  27734. }
  27735. emitEnd(node.importClause.namedBindings);
  27736. emitTrailingComments(node.importClause.namedBindings);
  27737. }
  27738. emitEnd(node.importClause);
  27739. write(" from ");
  27740. emit(node.moduleSpecifier);
  27741. write(";");
  27742. }
  27743. }
  27744. else {
  27745. write("import ");
  27746. emit(node.moduleSpecifier);
  27747. write(";");
  27748. }
  27749. }
  27750. function emitExternalImportDeclaration(node) {
  27751. if (ts.contains(externalImports, node)) {
  27752. var isExportedImport = node.kind === 219 && (node.flags & 1) !== 0;
  27753. var namespaceDeclaration = getNamespaceDeclarationNode(node);
  27754. if (compilerOptions.module !== 2) {
  27755. emitLeadingComments(node);
  27756. emitStart(node);
  27757. if (namespaceDeclaration && !isDefaultImport(node)) {
  27758. if (!isExportedImport)
  27759. write("var ");
  27760. emitModuleMemberName(namespaceDeclaration);
  27761. write(" = ");
  27762. }
  27763. else {
  27764. var isNakedImport = 220 && !node.importClause;
  27765. if (!isNakedImport) {
  27766. write("var ");
  27767. write(getGeneratedNameForNode(node));
  27768. write(" = ");
  27769. }
  27770. }
  27771. emitRequire(ts.getExternalModuleName(node));
  27772. if (namespaceDeclaration && isDefaultImport(node)) {
  27773. write(", ");
  27774. emitModuleMemberName(namespaceDeclaration);
  27775. write(" = ");
  27776. write(getGeneratedNameForNode(node));
  27777. }
  27778. write(";");
  27779. emitEnd(node);
  27780. emitExportImportAssignments(node);
  27781. emitTrailingComments(node);
  27782. }
  27783. else {
  27784. if (isExportedImport) {
  27785. emitModuleMemberName(namespaceDeclaration);
  27786. write(" = ");
  27787. emit(namespaceDeclaration.name);
  27788. write(";");
  27789. }
  27790. else if (namespaceDeclaration && isDefaultImport(node)) {
  27791. write("var ");
  27792. emitModuleMemberName(namespaceDeclaration);
  27793. write(" = ");
  27794. write(getGeneratedNameForNode(node));
  27795. write(";");
  27796. }
  27797. emitExportImportAssignments(node);
  27798. }
  27799. }
  27800. }
  27801. function emitImportEqualsDeclaration(node) {
  27802. if (ts.isExternalModuleImportEqualsDeclaration(node)) {
  27803. emitExternalImportDeclaration(node);
  27804. return;
  27805. }
  27806. if (resolver.isReferencedAliasDeclaration(node) ||
  27807. (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) {
  27808. emitLeadingComments(node);
  27809. emitStart(node);
  27810. var variableDeclarationIsHoisted = shouldHoistVariable(node, true);
  27811. var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, true);
  27812. if (!variableDeclarationIsHoisted) {
  27813. ts.Debug.assert(!isExported);
  27814. if (isES6ExportedDeclaration(node)) {
  27815. write("export ");
  27816. write("var ");
  27817. }
  27818. else if (!(node.flags & 1)) {
  27819. write("var ");
  27820. }
  27821. }
  27822. if (isExported) {
  27823. write(exportFunctionForFile + "(\"");
  27824. emitNodeWithoutSourceMap(node.name);
  27825. write("\", ");
  27826. }
  27827. emitModuleMemberName(node);
  27828. write(" = ");
  27829. emit(node.moduleReference);
  27830. if (isExported) {
  27831. write(")");
  27832. }
  27833. write(";");
  27834. emitEnd(node);
  27835. emitExportImportAssignments(node);
  27836. emitTrailingComments(node);
  27837. }
  27838. }
  27839. function emitExportDeclaration(node) {
  27840. ts.Debug.assert(compilerOptions.module !== 4);
  27841. if (languageVersion < 2) {
  27842. if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) {
  27843. emitStart(node);
  27844. var generatedName = getGeneratedNameForNode(node);
  27845. if (node.exportClause) {
  27846. if (compilerOptions.module !== 2) {
  27847. write("var ");
  27848. write(generatedName);
  27849. write(" = ");
  27850. emitRequire(ts.getExternalModuleName(node));
  27851. write(";");
  27852. }
  27853. for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) {
  27854. var specifier = _b[_a];
  27855. if (resolver.isValueAliasDeclaration(specifier)) {
  27856. writeLine();
  27857. emitStart(specifier);
  27858. emitContainingModuleName(specifier);
  27859. write(".");
  27860. emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
  27861. write(" = ");
  27862. write(generatedName);
  27863. write(".");
  27864. emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name);
  27865. write(";");
  27866. emitEnd(specifier);
  27867. }
  27868. }
  27869. }
  27870. else {
  27871. writeLine();
  27872. write("__export(");
  27873. if (compilerOptions.module !== 2) {
  27874. emitRequire(ts.getExternalModuleName(node));
  27875. }
  27876. else {
  27877. write(generatedName);
  27878. }
  27879. write(");");
  27880. }
  27881. emitEnd(node);
  27882. }
  27883. }
  27884. else {
  27885. if (!node.exportClause || resolver.isValueAliasDeclaration(node)) {
  27886. write("export ");
  27887. if (node.exportClause) {
  27888. write("{ ");
  27889. emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration);
  27890. write(" }");
  27891. }
  27892. else {
  27893. write("*");
  27894. }
  27895. if (node.moduleSpecifier) {
  27896. write(" from ");
  27897. emit(node.moduleSpecifier);
  27898. }
  27899. write(";");
  27900. }
  27901. }
  27902. }
  27903. function emitExportOrImportSpecifierList(specifiers, shouldEmit) {
  27904. ts.Debug.assert(languageVersion >= 2);
  27905. var needsComma = false;
  27906. for (var _a = 0; _a < specifiers.length; _a++) {
  27907. var specifier = specifiers[_a];
  27908. if (shouldEmit(specifier)) {
  27909. if (needsComma) {
  27910. write(", ");
  27911. }
  27912. if (specifier.propertyName) {
  27913. emit(specifier.propertyName);
  27914. write(" as ");
  27915. }
  27916. emit(specifier.name);
  27917. needsComma = true;
  27918. }
  27919. }
  27920. }
  27921. function emitExportAssignment(node) {
  27922. if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
  27923. if (languageVersion >= 2) {
  27924. writeLine();
  27925. emitStart(node);
  27926. write("export default ");
  27927. var expression = node.expression;
  27928. emit(expression);
  27929. if (expression.kind !== 211 &&
  27930. expression.kind !== 212) {
  27931. write(";");
  27932. }
  27933. emitEnd(node);
  27934. }
  27935. else {
  27936. writeLine();
  27937. emitStart(node);
  27938. if (compilerOptions.module === 4) {
  27939. write(exportFunctionForFile + "(\"default\",");
  27940. emit(node.expression);
  27941. write(")");
  27942. }
  27943. else {
  27944. emitEs6ExportDefaultCompat(node);
  27945. emitContainingModuleName(node);
  27946. if (languageVersion === 0) {
  27947. write("[\"default\"] = ");
  27948. }
  27949. else {
  27950. write(".default = ");
  27951. }
  27952. emit(node.expression);
  27953. }
  27954. write(";");
  27955. emitEnd(node);
  27956. }
  27957. }
  27958. }
  27959. function collectExternalModuleInfo(sourceFile) {
  27960. externalImports = [];
  27961. exportSpecifiers = {};
  27962. exportEquals = undefined;
  27963. hasExportStars = false;
  27964. for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) {
  27965. var node = _b[_a];
  27966. switch (node.kind) {
  27967. case 220:
  27968. if (!node.importClause ||
  27969. resolver.isReferencedAliasDeclaration(node.importClause, true)) {
  27970. externalImports.push(node);
  27971. }
  27972. break;
  27973. case 219:
  27974. if (node.moduleReference.kind === 230 && resolver.isReferencedAliasDeclaration(node)) {
  27975. externalImports.push(node);
  27976. }
  27977. break;
  27978. case 226:
  27979. if (node.moduleSpecifier) {
  27980. if (!node.exportClause) {
  27981. externalImports.push(node);
  27982. hasExportStars = true;
  27983. }
  27984. else if (resolver.isValueAliasDeclaration(node)) {
  27985. externalImports.push(node);
  27986. }
  27987. }
  27988. else {
  27989. for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) {
  27990. var specifier = _d[_c];
  27991. var name_24 = (specifier.propertyName || specifier.name).text;
  27992. (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier);
  27993. }
  27994. }
  27995. break;
  27996. case 225:
  27997. if (node.isExportEquals && !exportEquals) {
  27998. exportEquals = node;
  27999. }
  28000. break;
  28001. }
  28002. }
  28003. }
  28004. function emitExportStarHelper() {
  28005. if (hasExportStars) {
  28006. writeLine();
  28007. write("function __export(m) {");
  28008. increaseIndent();
  28009. writeLine();
  28010. write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];");
  28011. decreaseIndent();
  28012. writeLine();
  28013. write("}");
  28014. }
  28015. }
  28016. function getLocalNameForExternalImport(node) {
  28017. var namespaceDeclaration = getNamespaceDeclarationNode(node);
  28018. if (namespaceDeclaration && !isDefaultImport(node)) {
  28019. return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
  28020. }
  28021. if (node.kind === 220 && node.importClause) {
  28022. return getGeneratedNameForNode(node);
  28023. }
  28024. if (node.kind === 226 && node.moduleSpecifier) {
  28025. return getGeneratedNameForNode(node);
  28026. }
  28027. }
  28028. function getExternalModuleNameText(importNode) {
  28029. var moduleName = ts.getExternalModuleName(importNode);
  28030. if (moduleName.kind === 9) {
  28031. return tryRenameExternalModule(moduleName) || getLiteralText(moduleName);
  28032. }
  28033. return undefined;
  28034. }
  28035. function emitVariableDeclarationsForImports() {
  28036. if (externalImports.length === 0) {
  28037. return;
  28038. }
  28039. writeLine();
  28040. var started = false;
  28041. for (var _a = 0; _a < externalImports.length; _a++) {
  28042. var importNode = externalImports[_a];
  28043. var skipNode = importNode.kind === 226 ||
  28044. (importNode.kind === 220 && !importNode.importClause);
  28045. if (skipNode) {
  28046. continue;
  28047. }
  28048. if (!started) {
  28049. write("var ");
  28050. started = true;
  28051. }
  28052. else {
  28053. write(", ");
  28054. }
  28055. write(getLocalNameForExternalImport(importNode));
  28056. }
  28057. if (started) {
  28058. write(";");
  28059. }
  28060. }
  28061. function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) {
  28062. if (!hasExportStars) {
  28063. return undefined;
  28064. }
  28065. if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) {
  28066. var hasExportDeclarationWithExportClause = false;
  28067. for (var _a = 0; _a < externalImports.length; _a++) {
  28068. var externalImport = externalImports[_a];
  28069. if (externalImport.kind === 226 && externalImport.exportClause) {
  28070. hasExportDeclarationWithExportClause = true;
  28071. break;
  28072. }
  28073. }
  28074. if (!hasExportDeclarationWithExportClause) {
  28075. return emitExportStarFunction(undefined);
  28076. }
  28077. }
  28078. var exportedNamesStorageRef = makeUniqueName("exportedNames");
  28079. writeLine();
  28080. write("var " + exportedNamesStorageRef + " = {");
  28081. increaseIndent();
  28082. var started = false;
  28083. if (exportedDeclarations) {
  28084. for (var i = 0; i < exportedDeclarations.length; ++i) {
  28085. writeExportedName(exportedDeclarations[i]);
  28086. }
  28087. }
  28088. if (exportSpecifiers) {
  28089. for (var n in exportSpecifiers) {
  28090. for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) {
  28091. var specifier = _c[_b];
  28092. writeExportedName(specifier.name);
  28093. }
  28094. }
  28095. }
  28096. for (var _d = 0; _d < externalImports.length; _d++) {
  28097. var externalImport = externalImports[_d];
  28098. if (externalImport.kind !== 226) {
  28099. continue;
  28100. }
  28101. var exportDecl = externalImport;
  28102. if (!exportDecl.exportClause) {
  28103. continue;
  28104. }
  28105. for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) {
  28106. var element = _f[_e];
  28107. writeExportedName(element.name || element.propertyName);
  28108. }
  28109. }
  28110. decreaseIndent();
  28111. writeLine();
  28112. write("};");
  28113. return emitExportStarFunction(exportedNamesStorageRef);
  28114. function emitExportStarFunction(localNames) {
  28115. var exportStarFunction = makeUniqueName("exportStar");
  28116. writeLine();
  28117. write("function " + exportStarFunction + "(m) {");
  28118. increaseIndent();
  28119. writeLine();
  28120. write("var exports = {};");
  28121. writeLine();
  28122. write("for(var n in m) {");
  28123. increaseIndent();
  28124. writeLine();
  28125. write("if (n !== \"default\"");
  28126. if (localNames) {
  28127. write("&& !" + localNames + ".hasOwnProperty(n)");
  28128. }
  28129. write(") exports[n] = m[n];");
  28130. decreaseIndent();
  28131. writeLine();
  28132. write("}");
  28133. writeLine();
  28134. write(exportFunctionForFile + "(exports);");
  28135. decreaseIndent();
  28136. writeLine();
  28137. write("}");
  28138. return exportStarFunction;
  28139. }
  28140. function writeExportedName(node) {
  28141. if (node.kind !== 67 && node.flags & 1024) {
  28142. return;
  28143. }
  28144. if (started) {
  28145. write(",");
  28146. }
  28147. else {
  28148. started = true;
  28149. }
  28150. writeLine();
  28151. write("'");
  28152. if (node.kind === 67) {
  28153. emitNodeWithCommentsAndWithoutSourcemap(node);
  28154. }
  28155. else {
  28156. emitDeclarationName(node);
  28157. }
  28158. write("': true");
  28159. }
  28160. }
  28161. function processTopLevelVariableAndFunctionDeclarations(node) {
  28162. var hoistedVars;
  28163. var hoistedFunctionDeclarations;
  28164. var exportedDeclarations;
  28165. visit(node);
  28166. if (hoistedVars) {
  28167. writeLine();
  28168. write("var ");
  28169. var seen = {};
  28170. for (var i = 0; i < hoistedVars.length; ++i) {
  28171. var local = hoistedVars[i];
  28172. var name_25 = local.kind === 67
  28173. ? local
  28174. : local.name;
  28175. if (name_25) {
  28176. var text = ts.unescapeIdentifier(name_25.text);
  28177. if (ts.hasProperty(seen, text)) {
  28178. continue;
  28179. }
  28180. else {
  28181. seen[text] = text;
  28182. }
  28183. }
  28184. if (i !== 0) {
  28185. write(", ");
  28186. }
  28187. if (local.kind === 212 || local.kind === 216 || local.kind === 215) {
  28188. emitDeclarationName(local);
  28189. }
  28190. else {
  28191. emit(local);
  28192. }
  28193. var flags = ts.getCombinedNodeFlags(local.kind === 67 ? local.parent : local);
  28194. if (flags & 1) {
  28195. if (!exportedDeclarations) {
  28196. exportedDeclarations = [];
  28197. }
  28198. exportedDeclarations.push(local);
  28199. }
  28200. }
  28201. write(";");
  28202. }
  28203. if (hoistedFunctionDeclarations) {
  28204. for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) {
  28205. var f = hoistedFunctionDeclarations[_a];
  28206. writeLine();
  28207. emit(f);
  28208. if (f.flags & 1) {
  28209. if (!exportedDeclarations) {
  28210. exportedDeclarations = [];
  28211. }
  28212. exportedDeclarations.push(f);
  28213. }
  28214. }
  28215. }
  28216. return exportedDeclarations;
  28217. function visit(node) {
  28218. if (node.flags & 2) {
  28219. return;
  28220. }
  28221. if (node.kind === 211) {
  28222. if (!hoistedFunctionDeclarations) {
  28223. hoistedFunctionDeclarations = [];
  28224. }
  28225. hoistedFunctionDeclarations.push(node);
  28226. return;
  28227. }
  28228. if (node.kind === 212) {
  28229. if (!hoistedVars) {
  28230. hoistedVars = [];
  28231. }
  28232. hoistedVars.push(node);
  28233. return;
  28234. }
  28235. if (node.kind === 215) {
  28236. if (shouldEmitEnumDeclaration(node)) {
  28237. if (!hoistedVars) {
  28238. hoistedVars = [];
  28239. }
  28240. hoistedVars.push(node);
  28241. }
  28242. return;
  28243. }
  28244. if (node.kind === 216) {
  28245. if (shouldEmitModuleDeclaration(node)) {
  28246. if (!hoistedVars) {
  28247. hoistedVars = [];
  28248. }
  28249. hoistedVars.push(node);
  28250. }
  28251. return;
  28252. }
  28253. if (node.kind === 209 || node.kind === 161) {
  28254. if (shouldHoistVariable(node, false)) {
  28255. var name_26 = node.name;
  28256. if (name_26.kind === 67) {
  28257. if (!hoistedVars) {
  28258. hoistedVars = [];
  28259. }
  28260. hoistedVars.push(name_26);
  28261. }
  28262. else {
  28263. ts.forEachChild(name_26, visit);
  28264. }
  28265. }
  28266. return;
  28267. }
  28268. if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) {
  28269. if (!hoistedVars) {
  28270. hoistedVars = [];
  28271. }
  28272. hoistedVars.push(node.name);
  28273. return;
  28274. }
  28275. if (ts.isBindingPattern(node)) {
  28276. ts.forEach(node.elements, visit);
  28277. return;
  28278. }
  28279. if (!ts.isDeclaration(node)) {
  28280. ts.forEachChild(node, visit);
  28281. }
  28282. }
  28283. }
  28284. function shouldHoistVariable(node, checkIfSourceFileLevelDecl) {
  28285. if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) {
  28286. return false;
  28287. }
  28288. return (ts.getCombinedNodeFlags(node) & 49152) === 0 ||
  28289. ts.getEnclosingBlockScopeContainer(node).kind === 246;
  28290. }
  28291. function isCurrentFileSystemExternalModule() {
  28292. return compilerOptions.module === 4 && ts.isExternalModule(currentSourceFile);
  28293. }
  28294. function emitSystemModuleBody(node, dependencyGroups, startIndex) {
  28295. emitVariableDeclarationsForImports();
  28296. writeLine();
  28297. var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node);
  28298. var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations);
  28299. writeLine();
  28300. write("return {");
  28301. increaseIndent();
  28302. writeLine();
  28303. emitSetters(exportStarFunction, dependencyGroups);
  28304. writeLine();
  28305. emitExecute(node, startIndex);
  28306. decreaseIndent();
  28307. writeLine();
  28308. write("}");
  28309. emitTempDeclarations(true);
  28310. }
  28311. function emitSetters(exportStarFunction, dependencyGroups) {
  28312. write("setters:[");
  28313. for (var i = 0; i < dependencyGroups.length; ++i) {
  28314. if (i !== 0) {
  28315. write(",");
  28316. }
  28317. writeLine();
  28318. increaseIndent();
  28319. var group = dependencyGroups[i];
  28320. var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || "");
  28321. write("function (" + parameterName + ") {");
  28322. increaseIndent();
  28323. for (var _a = 0; _a < group.length; _a++) {
  28324. var entry = group[_a];
  28325. var importVariableName = getLocalNameForExternalImport(entry) || "";
  28326. switch (entry.kind) {
  28327. case 220:
  28328. if (!entry.importClause) {
  28329. break;
  28330. }
  28331. case 219:
  28332. ts.Debug.assert(importVariableName !== "");
  28333. writeLine();
  28334. write(importVariableName + " = " + parameterName + ";");
  28335. writeLine();
  28336. break;
  28337. case 226:
  28338. ts.Debug.assert(importVariableName !== "");
  28339. if (entry.exportClause) {
  28340. writeLine();
  28341. write(exportFunctionForFile + "({");
  28342. writeLine();
  28343. increaseIndent();
  28344. for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) {
  28345. if (i_2 !== 0) {
  28346. write(",");
  28347. writeLine();
  28348. }
  28349. var e = entry.exportClause.elements[i_2];
  28350. write("\"");
  28351. emitNodeWithCommentsAndWithoutSourcemap(e.name);
  28352. write("\": " + parameterName + "[\"");
  28353. emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name);
  28354. write("\"]");
  28355. }
  28356. decreaseIndent();
  28357. writeLine();
  28358. write("});");
  28359. }
  28360. else {
  28361. writeLine();
  28362. write(exportStarFunction + "(" + parameterName + ");");
  28363. }
  28364. writeLine();
  28365. break;
  28366. }
  28367. }
  28368. decreaseIndent();
  28369. write("}");
  28370. decreaseIndent();
  28371. }
  28372. write("],");
  28373. }
  28374. function emitExecute(node, startIndex) {
  28375. write("execute: function() {");
  28376. increaseIndent();
  28377. writeLine();
  28378. for (var i = startIndex; i < node.statements.length; ++i) {
  28379. var statement = node.statements[i];
  28380. switch (statement.kind) {
  28381. case 211:
  28382. case 220:
  28383. continue;
  28384. case 226:
  28385. if (!statement.moduleSpecifier) {
  28386. for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) {
  28387. var element = _b[_a];
  28388. emitExportSpecifierInSystemModule(element);
  28389. }
  28390. }
  28391. continue;
  28392. case 219:
  28393. if (!ts.isInternalModuleImportEqualsDeclaration(statement)) {
  28394. continue;
  28395. }
  28396. default:
  28397. writeLine();
  28398. emit(statement);
  28399. }
  28400. }
  28401. decreaseIndent();
  28402. writeLine();
  28403. write("}");
  28404. }
  28405. function emitSystemModule(node, startIndex) {
  28406. collectExternalModuleInfo(node);
  28407. ts.Debug.assert(!exportFunctionForFile);
  28408. exportFunctionForFile = makeUniqueName("exports");
  28409. writeLine();
  28410. write("System.register(");
  28411. if (node.moduleName) {
  28412. write("\"" + node.moduleName + "\", ");
  28413. }
  28414. write("[");
  28415. var groupIndices = {};
  28416. var dependencyGroups = [];
  28417. for (var i = 0; i < externalImports.length; ++i) {
  28418. var text = getExternalModuleNameText(externalImports[i]);
  28419. if (ts.hasProperty(groupIndices, text)) {
  28420. var groupIndex = groupIndices[text];
  28421. dependencyGroups[groupIndex].push(externalImports[i]);
  28422. continue;
  28423. }
  28424. else {
  28425. groupIndices[text] = dependencyGroups.length;
  28426. dependencyGroups.push([externalImports[i]]);
  28427. }
  28428. if (i !== 0) {
  28429. write(", ");
  28430. }
  28431. write(text);
  28432. }
  28433. write("], function(" + exportFunctionForFile + ") {");
  28434. writeLine();
  28435. increaseIndent();
  28436. emitEmitHelpers(node);
  28437. emitCaptureThisForNodeIfNecessary(node);
  28438. emitSystemModuleBody(node, dependencyGroups, startIndex);
  28439. decreaseIndent();
  28440. writeLine();
  28441. write("});");
  28442. }
  28443. function emitAMDDependencies(node, includeNonAmdDependencies) {
  28444. // An AMD define function has the following shape:
  28445. // define(id?, dependencies?, factory);
  28446. //
  28447. // This has the shape of
  28448. // define(name, ["module1", "module2"], function (module1Alias) {
  28449. // The location of the alias in the parameter list in the factory function needs to
  28450. // match the position of the module name in the dependency list.
  28451. //
  28452. // To ensure this is true in cases of modules with no aliases, e.g.:
  28453. // `import "module"` or `<amd-dependency path= "a.css" />`
  28454. // we need to add modules without alias names to the end of the dependencies list
  28455. var aliasedModuleNames = [];
  28456. var unaliasedModuleNames = [];
  28457. var importAliasNames = [];
  28458. for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) {
  28459. var amdDependency = _b[_a];
  28460. if (amdDependency.name) {
  28461. aliasedModuleNames.push("\"" + amdDependency.path + "\"");
  28462. importAliasNames.push(amdDependency.name);
  28463. }
  28464. else {
  28465. unaliasedModuleNames.push("\"" + amdDependency.path + "\"");
  28466. }
  28467. }
  28468. for (var _c = 0; _c < externalImports.length; _c++) {
  28469. var importNode = externalImports[_c];
  28470. var externalModuleName = getExternalModuleNameText(importNode);
  28471. var importAliasName = getLocalNameForExternalImport(importNode);
  28472. if (includeNonAmdDependencies && importAliasName) {
  28473. aliasedModuleNames.push(externalModuleName);
  28474. importAliasNames.push(importAliasName);
  28475. }
  28476. else {
  28477. unaliasedModuleNames.push(externalModuleName);
  28478. }
  28479. }
  28480. write("[\"require\", \"exports\"");
  28481. if (aliasedModuleNames.length) {
  28482. write(", ");
  28483. write(aliasedModuleNames.join(", "));
  28484. }
  28485. if (unaliasedModuleNames.length) {
  28486. write(", ");
  28487. write(unaliasedModuleNames.join(", "));
  28488. }
  28489. write("], function (require, exports");
  28490. if (importAliasNames.length) {
  28491. write(", ");
  28492. write(importAliasNames.join(", "));
  28493. }
  28494. }
  28495. function emitAMDModule(node, startIndex) {
  28496. emitEmitHelpers(node);
  28497. collectExternalModuleInfo(node);
  28498. writeLine();
  28499. write("define(");
  28500. if (node.moduleName) {
  28501. write("\"" + node.moduleName + "\", ");
  28502. }
  28503. emitAMDDependencies(node, true);
  28504. write(") {");
  28505. increaseIndent();
  28506. emitExportStarHelper();
  28507. emitCaptureThisForNodeIfNecessary(node);
  28508. emitLinesStartingAt(node.statements, startIndex);
  28509. emitTempDeclarations(true);
  28510. emitExportEquals(true);
  28511. decreaseIndent();
  28512. writeLine();
  28513. write("});");
  28514. }
  28515. function emitCommonJSModule(node, startIndex) {
  28516. emitEmitHelpers(node);
  28517. collectExternalModuleInfo(node);
  28518. emitExportStarHelper();
  28519. emitCaptureThisForNodeIfNecessary(node);
  28520. emitLinesStartingAt(node.statements, startIndex);
  28521. emitTempDeclarations(true);
  28522. emitExportEquals(false);
  28523. }
  28524. function emitUMDModule(node, startIndex) {
  28525. emitEmitHelpers(node);
  28526. collectExternalModuleInfo(node);
  28527. writeLines("(function (deps, 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(deps, factory);\n }\n})(");
  28528. emitAMDDependencies(node, false);
  28529. write(") {");
  28530. increaseIndent();
  28531. emitExportStarHelper();
  28532. emitCaptureThisForNodeIfNecessary(node);
  28533. emitLinesStartingAt(node.statements, startIndex);
  28534. emitTempDeclarations(true);
  28535. emitExportEquals(true);
  28536. decreaseIndent();
  28537. writeLine();
  28538. write("});");
  28539. }
  28540. function emitES6Module(node, startIndex) {
  28541. externalImports = undefined;
  28542. exportSpecifiers = undefined;
  28543. exportEquals = undefined;
  28544. hasExportStars = false;
  28545. emitEmitHelpers(node);
  28546. emitCaptureThisForNodeIfNecessary(node);
  28547. emitLinesStartingAt(node.statements, startIndex);
  28548. emitTempDeclarations(true);
  28549. }
  28550. function emitExportEquals(emitAsReturn) {
  28551. if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) {
  28552. writeLine();
  28553. emitStart(exportEquals);
  28554. write(emitAsReturn ? "return " : "module.exports = ");
  28555. emit(exportEquals.expression);
  28556. write(";");
  28557. emitEnd(exportEquals);
  28558. }
  28559. }
  28560. function emitJsxElement(node) {
  28561. switch (compilerOptions.jsx) {
  28562. case 2:
  28563. jsxEmitReact(node);
  28564. break;
  28565. case 1:
  28566. default:
  28567. jsxEmitPreserve(node);
  28568. break;
  28569. }
  28570. }
  28571. function trimReactWhitespaceAndApplyEntities(node) {
  28572. var result = undefined;
  28573. var text = ts.getTextOfNode(node, true);
  28574. var firstNonWhitespace = 0;
  28575. var lastNonWhitespace = -1;
  28576. for (var i = 0; i < text.length; i++) {
  28577. var c = text.charCodeAt(i);
  28578. if (ts.isLineBreak(c)) {
  28579. if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) {
  28580. var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1);
  28581. result = (result ? result + "\" + ' ' + \"" : "") + part;
  28582. }
  28583. firstNonWhitespace = -1;
  28584. }
  28585. else if (!ts.isWhiteSpace(c)) {
  28586. lastNonWhitespace = i;
  28587. if (firstNonWhitespace === -1) {
  28588. firstNonWhitespace = i;
  28589. }
  28590. }
  28591. }
  28592. if (firstNonWhitespace !== -1) {
  28593. var part = text.substr(firstNonWhitespace);
  28594. result = (result ? result + "\" + ' ' + \"" : "") + part;
  28595. }
  28596. if (result) {
  28597. result = result.replace(/&(\w+);/g, function (s, m) {
  28598. if (entities[m] !== undefined) {
  28599. return String.fromCharCode(entities[m]);
  28600. }
  28601. else {
  28602. return s;
  28603. }
  28604. });
  28605. }
  28606. return result;
  28607. }
  28608. function getTextToEmit(node) {
  28609. switch (compilerOptions.jsx) {
  28610. case 2:
  28611. var text = trimReactWhitespaceAndApplyEntities(node);
  28612. if (text === undefined || text.length === 0) {
  28613. return undefined;
  28614. }
  28615. else {
  28616. return text;
  28617. }
  28618. case 1:
  28619. default:
  28620. return ts.getTextOfNode(node, true);
  28621. }
  28622. }
  28623. function emitJsxText(node) {
  28624. switch (compilerOptions.jsx) {
  28625. case 2:
  28626. write("\"");
  28627. write(trimReactWhitespaceAndApplyEntities(node));
  28628. write("\"");
  28629. break;
  28630. case 1:
  28631. default:
  28632. writer.writeLiteral(ts.getTextOfNode(node, true));
  28633. break;
  28634. }
  28635. }
  28636. function emitJsxExpression(node) {
  28637. if (node.expression) {
  28638. switch (compilerOptions.jsx) {
  28639. case 1:
  28640. default:
  28641. write("{");
  28642. emit(node.expression);
  28643. write("}");
  28644. break;
  28645. case 2:
  28646. emit(node.expression);
  28647. break;
  28648. }
  28649. }
  28650. }
  28651. function emitDirectivePrologues(statements, startWithNewLine) {
  28652. for (var i = 0; i < statements.length; ++i) {
  28653. if (ts.isPrologueDirective(statements[i])) {
  28654. if (startWithNewLine || i > 0) {
  28655. writeLine();
  28656. }
  28657. emit(statements[i]);
  28658. }
  28659. else {
  28660. return i;
  28661. }
  28662. }
  28663. return statements.length;
  28664. }
  28665. function writeLines(text) {
  28666. var lines = text.split(/\r\n|\r|\n/g);
  28667. for (var i = 0; i < lines.length; ++i) {
  28668. var line = lines[i];
  28669. if (line.length) {
  28670. writeLine();
  28671. write(line);
  28672. }
  28673. }
  28674. }
  28675. function emitEmitHelpers(node) {
  28676. if (!compilerOptions.noEmitHelpers) {
  28677. if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) {
  28678. writeLines(extendsHelper);
  28679. extendsEmitted = true;
  28680. }
  28681. if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16) {
  28682. writeLines(decorateHelper);
  28683. if (compilerOptions.emitDecoratorMetadata) {
  28684. writeLines(metadataHelper);
  28685. }
  28686. decorateEmitted = true;
  28687. }
  28688. if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32) {
  28689. writeLines(paramHelper);
  28690. paramEmitted = true;
  28691. }
  28692. if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64) {
  28693. writeLines(awaiterHelper);
  28694. awaiterEmitted = true;
  28695. }
  28696. }
  28697. }
  28698. function emitSourceFileNode(node) {
  28699. writeLine();
  28700. emitShebang();
  28701. emitDetachedComments(node);
  28702. var startIndex = emitDirectivePrologues(node.statements, false);
  28703. if (ts.isExternalModule(node) || compilerOptions.isolatedModules) {
  28704. if (languageVersion >= 2) {
  28705. emitES6Module(node, startIndex);
  28706. }
  28707. else if (compilerOptions.module === 2) {
  28708. emitAMDModule(node, startIndex);
  28709. }
  28710. else if (compilerOptions.module === 4) {
  28711. emitSystemModule(node, startIndex);
  28712. }
  28713. else if (compilerOptions.module === 3) {
  28714. emitUMDModule(node, startIndex);
  28715. }
  28716. else {
  28717. emitCommonJSModule(node, startIndex);
  28718. }
  28719. }
  28720. else {
  28721. externalImports = undefined;
  28722. exportSpecifiers = undefined;
  28723. exportEquals = undefined;
  28724. hasExportStars = false;
  28725. emitEmitHelpers(node);
  28726. emitCaptureThisForNodeIfNecessary(node);
  28727. emitLinesStartingAt(node.statements, startIndex);
  28728. emitTempDeclarations(true);
  28729. }
  28730. emitLeadingComments(node.endOfFileToken);
  28731. }
  28732. function emitNodeWithCommentsAndWithoutSourcemap(node) {
  28733. emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap);
  28734. }
  28735. function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) {
  28736. if (node) {
  28737. if (node.flags & 2) {
  28738. return emitOnlyPinnedOrTripleSlashComments(node);
  28739. }
  28740. if (isSpecializedCommentHandling(node)) {
  28741. return emitNodeWithoutSourceMap(node);
  28742. }
  28743. var emitComments_1 = shouldEmitLeadingAndTrailingComments(node);
  28744. if (emitComments_1) {
  28745. emitLeadingComments(node);
  28746. }
  28747. emitNodeConsideringSourcemap(node);
  28748. if (emitComments_1) {
  28749. emitTrailingComments(node);
  28750. }
  28751. }
  28752. }
  28753. function emitNodeWithoutSourceMap(node) {
  28754. if (node) {
  28755. emitJavaScriptWorker(node);
  28756. }
  28757. }
  28758. function isSpecializedCommentHandling(node) {
  28759. switch (node.kind) {
  28760. case 213:
  28761. case 211:
  28762. case 220:
  28763. case 219:
  28764. case 214:
  28765. case 225:
  28766. return true;
  28767. }
  28768. }
  28769. function shouldEmitLeadingAndTrailingComments(node) {
  28770. switch (node.kind) {
  28771. case 191:
  28772. return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node);
  28773. case 216:
  28774. return shouldEmitModuleDeclaration(node);
  28775. case 215:
  28776. return shouldEmitEnumDeclaration(node);
  28777. }
  28778. ts.Debug.assert(!isSpecializedCommentHandling(node));
  28779. if (node.kind !== 190 &&
  28780. node.parent &&
  28781. node.parent.kind === 172 &&
  28782. node.parent.body === node &&
  28783. compilerOptions.target <= 1) {
  28784. return false;
  28785. }
  28786. return true;
  28787. }
  28788. function emitJavaScriptWorker(node) {
  28789. switch (node.kind) {
  28790. case 67:
  28791. return emitIdentifier(node);
  28792. case 136:
  28793. return emitParameter(node);
  28794. case 141:
  28795. case 140:
  28796. return emitMethod(node);
  28797. case 143:
  28798. case 144:
  28799. return emitAccessor(node);
  28800. case 95:
  28801. return emitThis(node);
  28802. case 93:
  28803. return emitSuper(node);
  28804. case 91:
  28805. return write("null");
  28806. case 97:
  28807. return write("true");
  28808. case 82:
  28809. return write("false");
  28810. case 8:
  28811. case 9:
  28812. case 10:
  28813. case 11:
  28814. case 12:
  28815. case 13:
  28816. case 14:
  28817. return emitLiteral(node);
  28818. case 181:
  28819. return emitTemplateExpression(node);
  28820. case 188:
  28821. return emitTemplateSpan(node);
  28822. case 231:
  28823. case 232:
  28824. return emitJsxElement(node);
  28825. case 234:
  28826. return emitJsxText(node);
  28827. case 238:
  28828. return emitJsxExpression(node);
  28829. case 133:
  28830. return emitQualifiedName(node);
  28831. case 159:
  28832. return emitObjectBindingPattern(node);
  28833. case 160:
  28834. return emitArrayBindingPattern(node);
  28835. case 161:
  28836. return emitBindingElement(node);
  28837. case 162:
  28838. return emitArrayLiteral(node);
  28839. case 163:
  28840. return emitObjectLiteral(node);
  28841. case 243:
  28842. return emitPropertyAssignment(node);
  28843. case 244:
  28844. return emitShorthandPropertyAssignment(node);
  28845. case 134:
  28846. return emitComputedPropertyName(node);
  28847. case 164:
  28848. return emitPropertyAccess(node);
  28849. case 165:
  28850. return emitIndexedAccess(node);
  28851. case 166:
  28852. return emitCallExpression(node);
  28853. case 167:
  28854. return emitNewExpression(node);
  28855. case 168:
  28856. return emitTaggedTemplateExpression(node);
  28857. case 169:
  28858. return emit(node.expression);
  28859. case 187:
  28860. return emit(node.expression);
  28861. case 170:
  28862. return emitParenExpression(node);
  28863. case 211:
  28864. case 171:
  28865. case 172:
  28866. return emitFunctionDeclaration(node);
  28867. case 173:
  28868. return emitDeleteExpression(node);
  28869. case 174:
  28870. return emitTypeOfExpression(node);
  28871. case 175:
  28872. return emitVoidExpression(node);
  28873. case 176:
  28874. return emitAwaitExpression(node);
  28875. case 177:
  28876. return emitPrefixUnaryExpression(node);
  28877. case 178:
  28878. return emitPostfixUnaryExpression(node);
  28879. case 179:
  28880. return emitBinaryExpression(node);
  28881. case 180:
  28882. return emitConditionalExpression(node);
  28883. case 183:
  28884. return emitSpreadElementExpression(node);
  28885. case 182:
  28886. return emitYieldExpression(node);
  28887. case 185:
  28888. return;
  28889. case 190:
  28890. case 217:
  28891. return emitBlock(node);
  28892. case 191:
  28893. return emitVariableStatement(node);
  28894. case 192:
  28895. return write(";");
  28896. case 193:
  28897. return emitExpressionStatement(node);
  28898. case 194:
  28899. return emitIfStatement(node);
  28900. case 195:
  28901. return emitDoStatement(node);
  28902. case 196:
  28903. return emitWhileStatement(node);
  28904. case 197:
  28905. return emitForStatement(node);
  28906. case 199:
  28907. case 198:
  28908. return emitForInOrForOfStatement(node);
  28909. case 200:
  28910. case 201:
  28911. return emitBreakOrContinueStatement(node);
  28912. case 202:
  28913. return emitReturnStatement(node);
  28914. case 203:
  28915. return emitWithStatement(node);
  28916. case 204:
  28917. return emitSwitchStatement(node);
  28918. case 239:
  28919. case 240:
  28920. return emitCaseOrDefaultClause(node);
  28921. case 205:
  28922. return emitLabelledStatement(node);
  28923. case 206:
  28924. return emitThrowStatement(node);
  28925. case 207:
  28926. return emitTryStatement(node);
  28927. case 242:
  28928. return emitCatchClause(node);
  28929. case 208:
  28930. return emitDebuggerStatement(node);
  28931. case 209:
  28932. return emitVariableDeclaration(node);
  28933. case 184:
  28934. return emitClassExpression(node);
  28935. case 212:
  28936. return emitClassDeclaration(node);
  28937. case 213:
  28938. return emitInterfaceDeclaration(node);
  28939. case 215:
  28940. return emitEnumDeclaration(node);
  28941. case 245:
  28942. return emitEnumMember(node);
  28943. case 216:
  28944. return emitModuleDeclaration(node);
  28945. case 220:
  28946. return emitImportDeclaration(node);
  28947. case 219:
  28948. return emitImportEqualsDeclaration(node);
  28949. case 226:
  28950. return emitExportDeclaration(node);
  28951. case 225:
  28952. return emitExportAssignment(node);
  28953. case 246:
  28954. return emitSourceFileNode(node);
  28955. }
  28956. }
  28957. function hasDetachedComments(pos) {
  28958. return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos;
  28959. }
  28960. function getLeadingCommentsWithoutDetachedComments() {
  28961. var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos);
  28962. if (detachedCommentsInfo.length - 1) {
  28963. detachedCommentsInfo.pop();
  28964. }
  28965. else {
  28966. detachedCommentsInfo = undefined;
  28967. }
  28968. return leadingComments;
  28969. }
  28970. function filterComments(ranges, onlyPinnedOrTripleSlashComments) {
  28971. if (ranges && onlyPinnedOrTripleSlashComments) {
  28972. ranges = ts.filter(ranges, isPinnedOrTripleSlashComment);
  28973. if (ranges.length === 0) {
  28974. return undefined;
  28975. }
  28976. }
  28977. return ranges;
  28978. }
  28979. function getLeadingCommentsToEmit(node) {
  28980. if (node.parent) {
  28981. if (node.parent.kind === 246 || node.pos !== node.parent.pos) {
  28982. if (hasDetachedComments(node.pos)) {
  28983. return getLeadingCommentsWithoutDetachedComments();
  28984. }
  28985. else {
  28986. return ts.getLeadingCommentRangesOfNode(node, currentSourceFile);
  28987. }
  28988. }
  28989. }
  28990. }
  28991. function getTrailingCommentsToEmit(node) {
  28992. if (node.parent) {
  28993. if (node.parent.kind === 246 || node.end !== node.parent.end) {
  28994. return ts.getTrailingCommentRanges(currentSourceFile.text, node.end);
  28995. }
  28996. }
  28997. }
  28998. function emitOnlyPinnedOrTripleSlashComments(node) {
  28999. emitLeadingCommentsWorker(node, true);
  29000. }
  29001. function emitLeadingComments(node) {
  29002. return emitLeadingCommentsWorker(node, compilerOptions.removeComments);
  29003. }
  29004. function emitLeadingCommentsWorker(node, onlyPinnedOrTripleSlashComments) {
  29005. var leadingComments = filterComments(getLeadingCommentsToEmit(node), onlyPinnedOrTripleSlashComments);
  29006. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
  29007. ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
  29008. }
  29009. function emitTrailingComments(node) {
  29010. var trailingComments = filterComments(getTrailingCommentsToEmit(node), compilerOptions.removeComments);
  29011. ts.emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment);
  29012. }
  29013. function emitTrailingCommentsOfPosition(pos) {
  29014. var trailingComments = filterComments(ts.getTrailingCommentRanges(currentSourceFile.text, pos), compilerOptions.removeComments);
  29015. ts.emitComments(currentSourceFile, writer, trailingComments, true, newLine, writeComment);
  29016. }
  29017. function emitLeadingCommentsOfPosition(pos) {
  29018. var leadingComments;
  29019. if (hasDetachedComments(pos)) {
  29020. leadingComments = getLeadingCommentsWithoutDetachedComments();
  29021. }
  29022. else {
  29023. leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos);
  29024. }
  29025. leadingComments = filterComments(leadingComments, compilerOptions.removeComments);
  29026. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments);
  29027. ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
  29028. }
  29029. function emitDetachedComments(node) {
  29030. var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
  29031. if (leadingComments) {
  29032. var detachedComments = [];
  29033. var lastComment;
  29034. ts.forEach(leadingComments, function (comment) {
  29035. if (lastComment) {
  29036. var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end);
  29037. var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos);
  29038. if (commentLine >= lastCommentLine + 2) {
  29039. return detachedComments;
  29040. }
  29041. }
  29042. detachedComments.push(comment);
  29043. lastComment = comment;
  29044. });
  29045. if (detachedComments.length) {
  29046. var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end);
  29047. var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos));
  29048. if (nodeLine >= lastCommentLine + 2) {
  29049. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
  29050. ts.emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment);
  29051. var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end };
  29052. if (detachedCommentsInfo) {
  29053. detachedCommentsInfo.push(currentDetachedCommentInfo);
  29054. }
  29055. else {
  29056. detachedCommentsInfo = [currentDetachedCommentInfo];
  29057. }
  29058. }
  29059. }
  29060. }
  29061. }
  29062. function emitShebang() {
  29063. var shebang = ts.getShebang(currentSourceFile.text);
  29064. if (shebang) {
  29065. write(shebang);
  29066. }
  29067. }
  29068. function isPinnedOrTripleSlashComment(comment) {
  29069. if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42) {
  29070. return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33;
  29071. }
  29072. else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 &&
  29073. comment.pos + 2 < comment.end &&
  29074. currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 &&
  29075. currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) {
  29076. return true;
  29077. }
  29078. }
  29079. }
  29080. function emitFile(jsFilePath, sourceFile) {
  29081. emitJavaScript(jsFilePath, sourceFile);
  29082. if (compilerOptions.declaration) {
  29083. ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics);
  29084. }
  29085. }
  29086. }
  29087. ts.emitFiles = emitFiles;
  29088. var entities = {
  29089. "quot": 0x0022,
  29090. "amp": 0x0026,
  29091. "apos": 0x0027,
  29092. "lt": 0x003C,
  29093. "gt": 0x003E,
  29094. "nbsp": 0x00A0,
  29095. "iexcl": 0x00A1,
  29096. "cent": 0x00A2,
  29097. "pound": 0x00A3,
  29098. "curren": 0x00A4,
  29099. "yen": 0x00A5,
  29100. "brvbar": 0x00A6,
  29101. "sect": 0x00A7,
  29102. "uml": 0x00A8,
  29103. "copy": 0x00A9,
  29104. "ordf": 0x00AA,
  29105. "laquo": 0x00AB,
  29106. "not": 0x00AC,
  29107. "shy": 0x00AD,
  29108. "reg": 0x00AE,
  29109. "macr": 0x00AF,
  29110. "deg": 0x00B0,
  29111. "plusmn": 0x00B1,
  29112. "sup2": 0x00B2,
  29113. "sup3": 0x00B3,
  29114. "acute": 0x00B4,
  29115. "micro": 0x00B5,
  29116. "para": 0x00B6,
  29117. "middot": 0x00B7,
  29118. "cedil": 0x00B8,
  29119. "sup1": 0x00B9,
  29120. "ordm": 0x00BA,
  29121. "raquo": 0x00BB,
  29122. "frac14": 0x00BC,
  29123. "frac12": 0x00BD,
  29124. "frac34": 0x00BE,
  29125. "iquest": 0x00BF,
  29126. "Agrave": 0x00C0,
  29127. "Aacute": 0x00C1,
  29128. "Acirc": 0x00C2,
  29129. "Atilde": 0x00C3,
  29130. "Auml": 0x00C4,
  29131. "Aring": 0x00C5,
  29132. "AElig": 0x00C6,
  29133. "Ccedil": 0x00C7,
  29134. "Egrave": 0x00C8,
  29135. "Eacute": 0x00C9,
  29136. "Ecirc": 0x00CA,
  29137. "Euml": 0x00CB,
  29138. "Igrave": 0x00CC,
  29139. "Iacute": 0x00CD,
  29140. "Icirc": 0x00CE,
  29141. "Iuml": 0x00CF,
  29142. "ETH": 0x00D0,
  29143. "Ntilde": 0x00D1,
  29144. "Ograve": 0x00D2,
  29145. "Oacute": 0x00D3,
  29146. "Ocirc": 0x00D4,
  29147. "Otilde": 0x00D5,
  29148. "Ouml": 0x00D6,
  29149. "times": 0x00D7,
  29150. "Oslash": 0x00D8,
  29151. "Ugrave": 0x00D9,
  29152. "Uacute": 0x00DA,
  29153. "Ucirc": 0x00DB,
  29154. "Uuml": 0x00DC,
  29155. "Yacute": 0x00DD,
  29156. "THORN": 0x00DE,
  29157. "szlig": 0x00DF,
  29158. "agrave": 0x00E0,
  29159. "aacute": 0x00E1,
  29160. "acirc": 0x00E2,
  29161. "atilde": 0x00E3,
  29162. "auml": 0x00E4,
  29163. "aring": 0x00E5,
  29164. "aelig": 0x00E6,
  29165. "ccedil": 0x00E7,
  29166. "egrave": 0x00E8,
  29167. "eacute": 0x00E9,
  29168. "ecirc": 0x00EA,
  29169. "euml": 0x00EB,
  29170. "igrave": 0x00EC,
  29171. "iacute": 0x00ED,
  29172. "icirc": 0x00EE,
  29173. "iuml": 0x00EF,
  29174. "eth": 0x00F0,
  29175. "ntilde": 0x00F1,
  29176. "ograve": 0x00F2,
  29177. "oacute": 0x00F3,
  29178. "ocirc": 0x00F4,
  29179. "otilde": 0x00F5,
  29180. "ouml": 0x00F6,
  29181. "divide": 0x00F7,
  29182. "oslash": 0x00F8,
  29183. "ugrave": 0x00F9,
  29184. "uacute": 0x00FA,
  29185. "ucirc": 0x00FB,
  29186. "uuml": 0x00FC,
  29187. "yacute": 0x00FD,
  29188. "thorn": 0x00FE,
  29189. "yuml": 0x00FF,
  29190. "OElig": 0x0152,
  29191. "oelig": 0x0153,
  29192. "Scaron": 0x0160,
  29193. "scaron": 0x0161,
  29194. "Yuml": 0x0178,
  29195. "fnof": 0x0192,
  29196. "circ": 0x02C6,
  29197. "tilde": 0x02DC,
  29198. "Alpha": 0x0391,
  29199. "Beta": 0x0392,
  29200. "Gamma": 0x0393,
  29201. "Delta": 0x0394,
  29202. "Epsilon": 0x0395,
  29203. "Zeta": 0x0396,
  29204. "Eta": 0x0397,
  29205. "Theta": 0x0398,
  29206. "Iota": 0x0399,
  29207. "Kappa": 0x039A,
  29208. "Lambda": 0x039B,
  29209. "Mu": 0x039C,
  29210. "Nu": 0x039D,
  29211. "Xi": 0x039E,
  29212. "Omicron": 0x039F,
  29213. "Pi": 0x03A0,
  29214. "Rho": 0x03A1,
  29215. "Sigma": 0x03A3,
  29216. "Tau": 0x03A4,
  29217. "Upsilon": 0x03A5,
  29218. "Phi": 0x03A6,
  29219. "Chi": 0x03A7,
  29220. "Psi": 0x03A8,
  29221. "Omega": 0x03A9,
  29222. "alpha": 0x03B1,
  29223. "beta": 0x03B2,
  29224. "gamma": 0x03B3,
  29225. "delta": 0x03B4,
  29226. "epsilon": 0x03B5,
  29227. "zeta": 0x03B6,
  29228. "eta": 0x03B7,
  29229. "theta": 0x03B8,
  29230. "iota": 0x03B9,
  29231. "kappa": 0x03BA,
  29232. "lambda": 0x03BB,
  29233. "mu": 0x03BC,
  29234. "nu": 0x03BD,
  29235. "xi": 0x03BE,
  29236. "omicron": 0x03BF,
  29237. "pi": 0x03C0,
  29238. "rho": 0x03C1,
  29239. "sigmaf": 0x03C2,
  29240. "sigma": 0x03C3,
  29241. "tau": 0x03C4,
  29242. "upsilon": 0x03C5,
  29243. "phi": 0x03C6,
  29244. "chi": 0x03C7,
  29245. "psi": 0x03C8,
  29246. "omega": 0x03C9,
  29247. "thetasym": 0x03D1,
  29248. "upsih": 0x03D2,
  29249. "piv": 0x03D6,
  29250. "ensp": 0x2002,
  29251. "emsp": 0x2003,
  29252. "thinsp": 0x2009,
  29253. "zwnj": 0x200C,
  29254. "zwj": 0x200D,
  29255. "lrm": 0x200E,
  29256. "rlm": 0x200F,
  29257. "ndash": 0x2013,
  29258. "mdash": 0x2014,
  29259. "lsquo": 0x2018,
  29260. "rsquo": 0x2019,
  29261. "sbquo": 0x201A,
  29262. "ldquo": 0x201C,
  29263. "rdquo": 0x201D,
  29264. "bdquo": 0x201E,
  29265. "dagger": 0x2020,
  29266. "Dagger": 0x2021,
  29267. "bull": 0x2022,
  29268. "hellip": 0x2026,
  29269. "permil": 0x2030,
  29270. "prime": 0x2032,
  29271. "Prime": 0x2033,
  29272. "lsaquo": 0x2039,
  29273. "rsaquo": 0x203A,
  29274. "oline": 0x203E,
  29275. "frasl": 0x2044,
  29276. "euro": 0x20AC,
  29277. "image": 0x2111,
  29278. "weierp": 0x2118,
  29279. "real": 0x211C,
  29280. "trade": 0x2122,
  29281. "alefsym": 0x2135,
  29282. "larr": 0x2190,
  29283. "uarr": 0x2191,
  29284. "rarr": 0x2192,
  29285. "darr": 0x2193,
  29286. "harr": 0x2194,
  29287. "crarr": 0x21B5,
  29288. "lArr": 0x21D0,
  29289. "uArr": 0x21D1,
  29290. "rArr": 0x21D2,
  29291. "dArr": 0x21D3,
  29292. "hArr": 0x21D4,
  29293. "forall": 0x2200,
  29294. "part": 0x2202,
  29295. "exist": 0x2203,
  29296. "empty": 0x2205,
  29297. "nabla": 0x2207,
  29298. "isin": 0x2208,
  29299. "notin": 0x2209,
  29300. "ni": 0x220B,
  29301. "prod": 0x220F,
  29302. "sum": 0x2211,
  29303. "minus": 0x2212,
  29304. "lowast": 0x2217,
  29305. "radic": 0x221A,
  29306. "prop": 0x221D,
  29307. "infin": 0x221E,
  29308. "ang": 0x2220,
  29309. "and": 0x2227,
  29310. "or": 0x2228,
  29311. "cap": 0x2229,
  29312. "cup": 0x222A,
  29313. "int": 0x222B,
  29314. "there4": 0x2234,
  29315. "sim": 0x223C,
  29316. "cong": 0x2245,
  29317. "asymp": 0x2248,
  29318. "ne": 0x2260,
  29319. "equiv": 0x2261,
  29320. "le": 0x2264,
  29321. "ge": 0x2265,
  29322. "sub": 0x2282,
  29323. "sup": 0x2283,
  29324. "nsub": 0x2284,
  29325. "sube": 0x2286,
  29326. "supe": 0x2287,
  29327. "oplus": 0x2295,
  29328. "otimes": 0x2297,
  29329. "perp": 0x22A5,
  29330. "sdot": 0x22C5,
  29331. "lceil": 0x2308,
  29332. "rceil": 0x2309,
  29333. "lfloor": 0x230A,
  29334. "rfloor": 0x230B,
  29335. "lang": 0x2329,
  29336. "rang": 0x232A,
  29337. "loz": 0x25CA,
  29338. "spades": 0x2660,
  29339. "clubs": 0x2663,
  29340. "hearts": 0x2665,
  29341. "diams": 0x2666
  29342. };
  29343. })(ts || (ts = {}));
  29344. /// <reference path="sys.ts" />
  29345. /// <reference path="emitter.ts" />
  29346. /// <reference path="core.ts" />
  29347. var ts;
  29348. (function (ts) {
  29349. ts.programTime = 0;
  29350. ts.emitTime = 0;
  29351. ts.ioReadTime = 0;
  29352. ts.ioWriteTime = 0;
  29353. var emptyArray = [];
  29354. ts.version = "1.6.2";
  29355. function findConfigFile(searchPath) {
  29356. var fileName = "tsconfig.json";
  29357. while (true) {
  29358. if (ts.sys.fileExists(fileName)) {
  29359. return fileName;
  29360. }
  29361. var parentPath = ts.getDirectoryPath(searchPath);
  29362. if (parentPath === searchPath) {
  29363. break;
  29364. }
  29365. searchPath = parentPath;
  29366. fileName = "../" + fileName;
  29367. }
  29368. return undefined;
  29369. }
  29370. ts.findConfigFile = findConfigFile;
  29371. function resolveTripleslashReference(moduleName, containingFile) {
  29372. var basePath = ts.getDirectoryPath(containingFile);
  29373. var referencedFileName = ts.isRootedDiskPath(moduleName) ? moduleName : ts.combinePaths(basePath, moduleName);
  29374. return ts.normalizePath(referencedFileName);
  29375. }
  29376. ts.resolveTripleslashReference = resolveTripleslashReference;
  29377. function resolveModuleName(moduleName, containingFile, compilerOptions, host) {
  29378. var moduleResolution = compilerOptions.moduleResolution !== undefined
  29379. ? compilerOptions.moduleResolution
  29380. : compilerOptions.module === 1 ? 2 : 1;
  29381. switch (moduleResolution) {
  29382. case 2: return nodeModuleNameResolver(moduleName, containingFile, host);
  29383. case 1: return classicNameResolver(moduleName, containingFile, compilerOptions, host);
  29384. }
  29385. }
  29386. ts.resolveModuleName = resolveModuleName;
  29387. function nodeModuleNameResolver(moduleName, containingFile, host) {
  29388. var containingDirectory = ts.getDirectoryPath(containingFile);
  29389. if (ts.getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) {
  29390. var failedLookupLocations = [];
  29391. var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName));
  29392. var resolvedFileName = loadNodeModuleFromFile(candidate, false, failedLookupLocations, host);
  29393. if (resolvedFileName) {
  29394. return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations };
  29395. }
  29396. resolvedFileName = loadNodeModuleFromDirectory(candidate, false, failedLookupLocations, host);
  29397. return resolvedFileName
  29398. ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }
  29399. : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations };
  29400. }
  29401. else {
  29402. return loadModuleFromNodeModules(moduleName, containingDirectory, host);
  29403. }
  29404. }
  29405. ts.nodeModuleNameResolver = nodeModuleNameResolver;
  29406. function loadNodeModuleFromFile(candidate, loadOnlyDts, failedLookupLocation, host) {
  29407. if (loadOnlyDts) {
  29408. return tryLoad(".d.ts");
  29409. }
  29410. else {
  29411. return ts.forEach(ts.supportedExtensions, tryLoad);
  29412. }
  29413. function tryLoad(ext) {
  29414. var fileName = ts.fileExtensionIs(candidate, ext) ? candidate : candidate + ext;
  29415. if (host.fileExists(fileName)) {
  29416. return fileName;
  29417. }
  29418. else {
  29419. failedLookupLocation.push(fileName);
  29420. return undefined;
  29421. }
  29422. }
  29423. }
  29424. function loadNodeModuleFromDirectory(candidate, loadOnlyDts, failedLookupLocation, host) {
  29425. var packageJsonPath = ts.combinePaths(candidate, "package.json");
  29426. if (host.fileExists(packageJsonPath)) {
  29427. var jsonContent;
  29428. try {
  29429. var jsonText = host.readFile(packageJsonPath);
  29430. jsonContent = jsonText ? JSON.parse(jsonText) : { typings: undefined };
  29431. }
  29432. catch (e) {
  29433. jsonContent = { typings: undefined };
  29434. }
  29435. if (jsonContent.typings) {
  29436. var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), loadOnlyDts, failedLookupLocation, host);
  29437. if (result) {
  29438. return result;
  29439. }
  29440. }
  29441. }
  29442. else {
  29443. failedLookupLocation.push(packageJsonPath);
  29444. }
  29445. return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host);
  29446. }
  29447. function loadModuleFromNodeModules(moduleName, directory, host) {
  29448. var failedLookupLocations = [];
  29449. directory = ts.normalizeSlashes(directory);
  29450. while (true) {
  29451. var baseName = ts.getBaseFileName(directory);
  29452. if (baseName !== "node_modules") {
  29453. var nodeModulesFolder = ts.combinePaths(directory, "node_modules");
  29454. var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName));
  29455. var result = loadNodeModuleFromFile(candidate, true, failedLookupLocations, host);
  29456. if (result) {
  29457. return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations };
  29458. }
  29459. result = loadNodeModuleFromDirectory(candidate, true, failedLookupLocations, host);
  29460. if (result) {
  29461. return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations };
  29462. }
  29463. }
  29464. var parentPath = ts.getDirectoryPath(directory);
  29465. if (parentPath === directory) {
  29466. break;
  29467. }
  29468. directory = parentPath;
  29469. }
  29470. return { resolvedModule: undefined, failedLookupLocations: failedLookupLocations };
  29471. }
  29472. function nameStartsWithDotSlashOrDotDotSlash(name) {
  29473. var i = name.lastIndexOf("./", 1);
  29474. return i === 0 || (i === 1 && name.charCodeAt(0) === 46);
  29475. }
  29476. function classicNameResolver(moduleName, containingFile, compilerOptions, host) {
  29477. if (moduleName.indexOf('!') != -1) {
  29478. return { resolvedModule: undefined, failedLookupLocations: [] };
  29479. }
  29480. var searchPath = ts.getDirectoryPath(containingFile);
  29481. var searchName;
  29482. var failedLookupLocations = [];
  29483. var referencedSourceFile;
  29484. while (true) {
  29485. searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleName));
  29486. referencedSourceFile = ts.forEach(ts.supportedExtensions, function (extension) {
  29487. if (extension === ".tsx" && !compilerOptions.jsx) {
  29488. return undefined;
  29489. }
  29490. var candidate = searchName + extension;
  29491. if (host.fileExists(candidate)) {
  29492. return candidate;
  29493. }
  29494. else {
  29495. failedLookupLocations.push(candidate);
  29496. }
  29497. });
  29498. if (referencedSourceFile) {
  29499. break;
  29500. }
  29501. var parentPath = ts.getDirectoryPath(searchPath);
  29502. if (parentPath === searchPath) {
  29503. break;
  29504. }
  29505. searchPath = parentPath;
  29506. }
  29507. return referencedSourceFile
  29508. ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations: failedLookupLocations }
  29509. : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations };
  29510. }
  29511. ts.classicNameResolver = classicNameResolver;
  29512. ts.defaultInitCompilerOptions = {
  29513. module: 1,
  29514. target: 0,
  29515. noImplicitAny: false,
  29516. outDir: "built",
  29517. rootDir: ".",
  29518. sourceMap: false
  29519. };
  29520. function createCompilerHost(options, setParentNodes) {
  29521. var currentDirectory;
  29522. var existingDirectories = {};
  29523. function getCanonicalFileName(fileName) {
  29524. return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
  29525. }
  29526. var unsupportedFileEncodingErrorCode = -2147024809;
  29527. function getSourceFile(fileName, languageVersion, onError) {
  29528. var text;
  29529. try {
  29530. var start = new Date().getTime();
  29531. text = ts.sys.readFile(fileName, options.charset);
  29532. ts.ioReadTime += new Date().getTime() - start;
  29533. }
  29534. catch (e) {
  29535. if (onError) {
  29536. onError(e.number === unsupportedFileEncodingErrorCode
  29537. ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText
  29538. : e.message);
  29539. }
  29540. text = "";
  29541. }
  29542. return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined;
  29543. }
  29544. function directoryExists(directoryPath) {
  29545. if (ts.hasProperty(existingDirectories, directoryPath)) {
  29546. return true;
  29547. }
  29548. if (ts.sys.directoryExists(directoryPath)) {
  29549. existingDirectories[directoryPath] = true;
  29550. return true;
  29551. }
  29552. return false;
  29553. }
  29554. function ensureDirectoriesExist(directoryPath) {
  29555. if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) {
  29556. var parentDirectory = ts.getDirectoryPath(directoryPath);
  29557. ensureDirectoriesExist(parentDirectory);
  29558. ts.sys.createDirectory(directoryPath);
  29559. }
  29560. }
  29561. function writeFile(fileName, data, writeByteOrderMark, onError) {
  29562. try {
  29563. var start = new Date().getTime();
  29564. ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName)));
  29565. ts.sys.writeFile(fileName, data, writeByteOrderMark);
  29566. ts.ioWriteTime += new Date().getTime() - start;
  29567. }
  29568. catch (e) {
  29569. if (onError) {
  29570. onError(e.message);
  29571. }
  29572. }
  29573. }
  29574. var newLine = ts.getNewLineCharacter(options);
  29575. return {
  29576. getSourceFile: getSourceFile,
  29577. getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); },
  29578. writeFile: writeFile,
  29579. getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); },
  29580. useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; },
  29581. getCanonicalFileName: getCanonicalFileName,
  29582. getNewLine: function () { return newLine; },
  29583. fileExists: function (fileName) { return ts.sys.fileExists(fileName); },
  29584. readFile: function (fileName) { return ts.sys.readFile(fileName); }
  29585. };
  29586. }
  29587. ts.createCompilerHost = createCompilerHost;
  29588. function getPreEmitDiagnostics(program, sourceFile, cancellationToken) {
  29589. var diagnostics = program.getOptionsDiagnostics(cancellationToken).concat(program.getSyntacticDiagnostics(sourceFile, cancellationToken), program.getGlobalDiagnostics(cancellationToken), program.getSemanticDiagnostics(sourceFile, cancellationToken));
  29590. if (program.getCompilerOptions().declaration) {
  29591. diagnostics.concat(program.getDeclarationDiagnostics(sourceFile, cancellationToken));
  29592. }
  29593. return ts.sortAndDeduplicateDiagnostics(diagnostics);
  29594. }
  29595. ts.getPreEmitDiagnostics = getPreEmitDiagnostics;
  29596. function flattenDiagnosticMessageText(messageText, newLine) {
  29597. if (typeof messageText === "string") {
  29598. return messageText;
  29599. }
  29600. else {
  29601. var diagnosticChain = messageText;
  29602. var result = "";
  29603. var indent = 0;
  29604. while (diagnosticChain) {
  29605. if (indent) {
  29606. result += newLine;
  29607. for (var i = 0; i < indent; i++) {
  29608. result += " ";
  29609. }
  29610. }
  29611. result += diagnosticChain.messageText;
  29612. indent++;
  29613. diagnosticChain = diagnosticChain.next;
  29614. }
  29615. return result;
  29616. }
  29617. }
  29618. ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
  29619. function createProgram(rootNames, options, host, oldProgram) {
  29620. var program;
  29621. var files = [];
  29622. var fileProcessingDiagnostics = ts.createDiagnosticCollection();
  29623. var programDiagnostics = ts.createDiagnosticCollection();
  29624. var commonSourceDirectory;
  29625. var diagnosticsProducingTypeChecker;
  29626. var noDiagnosticsTypeChecker;
  29627. var classifiableNames;
  29628. var skipDefaultLib = options.noLib;
  29629. var start = new Date().getTime();
  29630. host = host || createCompilerHost(options);
  29631. var resolveModuleNamesWorker = host.resolveModuleNames
  29632. ? (function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile); })
  29633. : (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }); });
  29634. var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); });
  29635. if (oldProgram) {
  29636. var oldOptions = oldProgram.getCompilerOptions();
  29637. if ((oldOptions.module !== options.module) ||
  29638. (oldOptions.noResolve !== options.noResolve) ||
  29639. (oldOptions.target !== options.target) ||
  29640. (oldOptions.noLib !== options.noLib) ||
  29641. (oldOptions.jsx !== options.jsx)) {
  29642. oldProgram = undefined;
  29643. }
  29644. }
  29645. if (!tryReuseStructureFromOldProgram()) {
  29646. ts.forEach(rootNames, function (name) { return processRootFile(name, false); });
  29647. if (!skipDefaultLib) {
  29648. processRootFile(host.getDefaultLibFileName(options), true);
  29649. }
  29650. }
  29651. verifyCompilerOptions();
  29652. oldProgram = undefined;
  29653. ts.programTime += new Date().getTime() - start;
  29654. program = {
  29655. getRootFileNames: function () { return rootNames; },
  29656. getSourceFile: getSourceFile,
  29657. getSourceFiles: function () { return files; },
  29658. getCompilerOptions: function () { return options; },
  29659. getSyntacticDiagnostics: getSyntacticDiagnostics,
  29660. getOptionsDiagnostics: getOptionsDiagnostics,
  29661. getGlobalDiagnostics: getGlobalDiagnostics,
  29662. getSemanticDiagnostics: getSemanticDiagnostics,
  29663. getDeclarationDiagnostics: getDeclarationDiagnostics,
  29664. getTypeChecker: getTypeChecker,
  29665. getClassifiableNames: getClassifiableNames,
  29666. getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker,
  29667. getCommonSourceDirectory: function () { return commonSourceDirectory; },
  29668. emit: emit,
  29669. getCurrentDirectory: function () { return host.getCurrentDirectory(); },
  29670. getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); },
  29671. getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); },
  29672. getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); },
  29673. getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); },
  29674. getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; }
  29675. };
  29676. return program;
  29677. function getClassifiableNames() {
  29678. if (!classifiableNames) {
  29679. getTypeChecker();
  29680. classifiableNames = {};
  29681. for (var _i = 0; _i < files.length; _i++) {
  29682. var sourceFile = files[_i];
  29683. ts.copyMap(sourceFile.classifiableNames, classifiableNames);
  29684. }
  29685. }
  29686. return classifiableNames;
  29687. }
  29688. function tryReuseStructureFromOldProgram() {
  29689. if (!oldProgram) {
  29690. return false;
  29691. }
  29692. ts.Debug.assert(!oldProgram.structureIsReused);
  29693. var oldRootNames = oldProgram.getRootFileNames();
  29694. if (!ts.arrayIsEqualTo(oldRootNames, rootNames)) {
  29695. return false;
  29696. }
  29697. var newSourceFiles = [];
  29698. var modifiedSourceFiles = [];
  29699. for (var _i = 0, _a = oldProgram.getSourceFiles(); _i < _a.length; _i++) {
  29700. var oldSourceFile = _a[_i];
  29701. var newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target);
  29702. if (!newSourceFile) {
  29703. return false;
  29704. }
  29705. if (oldSourceFile !== newSourceFile) {
  29706. if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
  29707. return false;
  29708. }
  29709. if (!ts.arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
  29710. return false;
  29711. }
  29712. collectExternalModuleReferences(newSourceFile);
  29713. if (!ts.arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
  29714. return false;
  29715. }
  29716. if (resolveModuleNamesWorker) {
  29717. var moduleNames = ts.map(newSourceFile.imports, function (name) { return name.text; });
  29718. var resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName);
  29719. for (var i = 0; i < moduleNames.length; ++i) {
  29720. var newResolution = resolutions[i];
  29721. var oldResolution = ts.getResolvedModule(oldSourceFile, moduleNames[i]);
  29722. var resolutionChanged = oldResolution
  29723. ? !newResolution ||
  29724. oldResolution.resolvedFileName !== newResolution.resolvedFileName ||
  29725. !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport
  29726. : newResolution;
  29727. if (resolutionChanged) {
  29728. return false;
  29729. }
  29730. }
  29731. }
  29732. newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
  29733. modifiedSourceFiles.push(newSourceFile);
  29734. }
  29735. else {
  29736. newSourceFile = oldSourceFile;
  29737. }
  29738. newSourceFiles.push(newSourceFile);
  29739. }
  29740. for (var _b = 0; _b < newSourceFiles.length; _b++) {
  29741. var file = newSourceFiles[_b];
  29742. filesByName.set(file.fileName, file);
  29743. }
  29744. files = newSourceFiles;
  29745. fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics();
  29746. for (var _c = 0; _c < modifiedSourceFiles.length; _c++) {
  29747. var modifiedFile = modifiedSourceFiles[_c];
  29748. fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile);
  29749. }
  29750. oldProgram.structureIsReused = true;
  29751. return true;
  29752. }
  29753. function getEmitHost(writeFileCallback) {
  29754. return {
  29755. getCanonicalFileName: function (fileName) { return host.getCanonicalFileName(fileName); },
  29756. getCommonSourceDirectory: program.getCommonSourceDirectory,
  29757. getCompilerOptions: program.getCompilerOptions,
  29758. getCurrentDirectory: function () { return host.getCurrentDirectory(); },
  29759. getNewLine: function () { return host.getNewLine(); },
  29760. getSourceFile: program.getSourceFile,
  29761. getSourceFiles: program.getSourceFiles,
  29762. writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError) { return host.writeFile(fileName, data, writeByteOrderMark, onError); })
  29763. };
  29764. }
  29765. function getDiagnosticsProducingTypeChecker() {
  29766. return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true));
  29767. }
  29768. function getTypeChecker() {
  29769. return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, false));
  29770. }
  29771. function emit(sourceFile, writeFileCallback, cancellationToken) {
  29772. var _this = this;
  29773. return runWithCancellationToken(function () { return emitWorker(_this, sourceFile, writeFileCallback, cancellationToken); });
  29774. }
  29775. function emitWorker(program, sourceFile, writeFileCallback, cancellationToken) {
  29776. if (options.noEmitOnError && getPreEmitDiagnostics(program, undefined, cancellationToken).length > 0) {
  29777. return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
  29778. }
  29779. var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile);
  29780. var start = new Date().getTime();
  29781. var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile);
  29782. ts.emitTime += new Date().getTime() - start;
  29783. return emitResult;
  29784. }
  29785. function getSourceFile(fileName) {
  29786. return filesByName.get(fileName);
  29787. }
  29788. function getDiagnosticsHelper(sourceFile, getDiagnostics, cancellationToken) {
  29789. if (sourceFile) {
  29790. return getDiagnostics(sourceFile, cancellationToken);
  29791. }
  29792. var allDiagnostics = [];
  29793. ts.forEach(program.getSourceFiles(), function (sourceFile) {
  29794. if (cancellationToken) {
  29795. cancellationToken.throwIfCancellationRequested();
  29796. }
  29797. ts.addRange(allDiagnostics, getDiagnostics(sourceFile, cancellationToken));
  29798. });
  29799. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  29800. }
  29801. function getSyntacticDiagnostics(sourceFile, cancellationToken) {
  29802. return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile, cancellationToken);
  29803. }
  29804. function getSemanticDiagnostics(sourceFile, cancellationToken) {
  29805. return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile, cancellationToken);
  29806. }
  29807. function getDeclarationDiagnostics(sourceFile, cancellationToken) {
  29808. return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile, cancellationToken);
  29809. }
  29810. function getSyntacticDiagnosticsForFile(sourceFile, cancellationToken) {
  29811. return sourceFile.parseDiagnostics;
  29812. }
  29813. function runWithCancellationToken(func) {
  29814. try {
  29815. return func();
  29816. }
  29817. catch (e) {
  29818. if (e instanceof ts.OperationCanceledException) {
  29819. noDiagnosticsTypeChecker = undefined;
  29820. diagnosticsProducingTypeChecker = undefined;
  29821. }
  29822. throw e;
  29823. }
  29824. }
  29825. function getSemanticDiagnosticsForFile(sourceFile, cancellationToken) {
  29826. return runWithCancellationToken(function () {
  29827. var typeChecker = getDiagnosticsProducingTypeChecker();
  29828. ts.Debug.assert(!!sourceFile.bindDiagnostics);
  29829. var bindDiagnostics = sourceFile.bindDiagnostics;
  29830. var checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken);
  29831. var fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName);
  29832. var programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName);
  29833. return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile);
  29834. });
  29835. }
  29836. function getDeclarationDiagnosticsForFile(sourceFile, cancellationToken) {
  29837. return runWithCancellationToken(function () {
  29838. if (!ts.isDeclarationFile(sourceFile)) {
  29839. var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
  29840. var writeFile_1 = function () { };
  29841. return ts.getDeclarationDiagnostics(getEmitHost(writeFile_1), resolver, sourceFile);
  29842. }
  29843. });
  29844. }
  29845. function getOptionsDiagnostics() {
  29846. var allDiagnostics = [];
  29847. ts.addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics());
  29848. ts.addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics());
  29849. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  29850. }
  29851. function getGlobalDiagnostics() {
  29852. var allDiagnostics = [];
  29853. ts.addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics());
  29854. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  29855. }
  29856. function hasExtension(fileName) {
  29857. return ts.getBaseFileName(fileName).indexOf(".") >= 0;
  29858. }
  29859. function processRootFile(fileName, isDefaultLib) {
  29860. processSourceFile(ts.normalizePath(fileName), isDefaultLib);
  29861. }
  29862. function fileReferenceIsEqualTo(a, b) {
  29863. return a.fileName === b.fileName;
  29864. }
  29865. function moduleNameIsEqualTo(a, b) {
  29866. return a.text === b.text;
  29867. }
  29868. function collectExternalModuleReferences(file) {
  29869. if (file.imports) {
  29870. return;
  29871. }
  29872. var imports;
  29873. for (var _i = 0, _a = file.statements; _i < _a.length; _i++) {
  29874. var node = _a[_i];
  29875. switch (node.kind) {
  29876. case 220:
  29877. case 219:
  29878. case 226:
  29879. var moduleNameExpr = ts.getExternalModuleName(node);
  29880. if (!moduleNameExpr || moduleNameExpr.kind !== 9) {
  29881. break;
  29882. }
  29883. if (!moduleNameExpr.text) {
  29884. break;
  29885. }
  29886. (imports || (imports = [])).push(moduleNameExpr);
  29887. break;
  29888. case 216:
  29889. if (node.name.kind === 9 && (node.flags & 2 || ts.isDeclarationFile(file))) {
  29890. ts.forEachChild(node.body, function (node) {
  29891. if (ts.isExternalModuleImportEqualsDeclaration(node) &&
  29892. ts.getExternalModuleImportEqualsDeclarationExpression(node).kind === 9) {
  29893. var moduleName = ts.getExternalModuleImportEqualsDeclarationExpression(node);
  29894. if (moduleName) {
  29895. (imports || (imports = [])).push(moduleName);
  29896. }
  29897. }
  29898. });
  29899. }
  29900. break;
  29901. }
  29902. }
  29903. file.imports = imports || emptyArray;
  29904. }
  29905. function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
  29906. var diagnosticArgument;
  29907. var diagnostic;
  29908. if (hasExtension(fileName)) {
  29909. if (!options.allowNonTsExtensions && !ts.forEach(ts.supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) {
  29910. diagnostic = ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
  29911. diagnosticArgument = [fileName, "'" + ts.supportedExtensions.join("', '") + "'"];
  29912. }
  29913. else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
  29914. diagnostic = ts.Diagnostics.File_0_not_found;
  29915. diagnosticArgument = [fileName];
  29916. }
  29917. else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
  29918. diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself;
  29919. diagnosticArgument = [fileName];
  29920. }
  29921. }
  29922. else {
  29923. var nonTsFile = options.allowNonTsExtensions && findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd);
  29924. if (!nonTsFile) {
  29925. if (options.allowNonTsExtensions) {
  29926. diagnostic = ts.Diagnostics.File_0_not_found;
  29927. diagnosticArgument = [fileName];
  29928. }
  29929. else if (!ts.forEach(ts.supportedExtensions, function (extension) { return findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd); })) {
  29930. diagnostic = ts.Diagnostics.File_0_not_found;
  29931. fileName += ".ts";
  29932. diagnosticArgument = [fileName];
  29933. }
  29934. }
  29935. }
  29936. if (diagnostic) {
  29937. if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) {
  29938. fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument)));
  29939. }
  29940. else {
  29941. fileProcessingDiagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument)));
  29942. }
  29943. }
  29944. }
  29945. function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
  29946. var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
  29947. if (filesByName.contains(canonicalName)) {
  29948. return getSourceFileFromCache(fileName, canonicalName, false);
  29949. }
  29950. else {
  29951. var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
  29952. var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath);
  29953. if (filesByName.contains(canonicalAbsolutePath)) {
  29954. return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true);
  29955. }
  29956. var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) {
  29957. if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
  29958. fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
  29959. }
  29960. else {
  29961. fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
  29962. }
  29963. });
  29964. filesByName.set(canonicalName, file);
  29965. if (file) {
  29966. skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib;
  29967. filesByName.set(canonicalAbsolutePath, file);
  29968. var basePath = ts.getDirectoryPath(fileName);
  29969. if (!options.noResolve) {
  29970. processReferencedFiles(file, basePath);
  29971. }
  29972. processImportedModules(file, basePath);
  29973. if (isDefaultLib) {
  29974. file.isDefaultLib = true;
  29975. files.unshift(file);
  29976. }
  29977. else {
  29978. files.push(file);
  29979. }
  29980. }
  29981. return file;
  29982. }
  29983. function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) {
  29984. var file = filesByName.get(canonicalName);
  29985. if (file && host.useCaseSensitiveFileNames()) {
  29986. var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
  29987. if (canonicalName !== sourceFileName) {
  29988. if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
  29989. 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));
  29990. }
  29991. else {
  29992. fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
  29993. }
  29994. }
  29995. }
  29996. return file;
  29997. }
  29998. }
  29999. function processReferencedFiles(file, basePath) {
  30000. ts.forEach(file.referencedFiles, function (ref) {
  30001. var referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
  30002. processSourceFile(referencedFileName, false, file, ref.pos, ref.end);
  30003. });
  30004. }
  30005. function processImportedModules(file, basePath) {
  30006. collectExternalModuleReferences(file);
  30007. if (file.imports.length) {
  30008. file.resolvedModules = {};
  30009. var moduleNames = ts.map(file.imports, function (name) { return name.text; });
  30010. var resolutions = resolveModuleNamesWorker(moduleNames, file.fileName);
  30011. for (var i = 0; i < file.imports.length; ++i) {
  30012. var resolution = resolutions[i];
  30013. ts.setResolvedModule(file, moduleNames[i], resolution);
  30014. if (resolution && !options.noResolve) {
  30015. var importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]);
  30016. if (importedFile && resolution.isExternalLibraryImport) {
  30017. if (!ts.isExternalModule(importedFile)) {
  30018. var start_2 = ts.getTokenPosOfNode(file.imports[i], file);
  30019. fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_2, file.imports[i].end - start_2, ts.Diagnostics.File_0_is_not_a_module, importedFile.fileName));
  30020. }
  30021. else if (!ts.fileExtensionIs(importedFile.fileName, ".d.ts")) {
  30022. var start_3 = ts.getTokenPosOfNode(file.imports[i], file);
  30023. fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_3, file.imports[i].end - start_3, ts.Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition));
  30024. }
  30025. else if (importedFile.referencedFiles.length) {
  30026. var firstRef = importedFile.referencedFiles[0];
  30027. 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));
  30028. }
  30029. }
  30030. }
  30031. }
  30032. }
  30033. else {
  30034. file.resolvedModules = undefined;
  30035. }
  30036. return;
  30037. function findModuleSourceFile(fileName, nameLiteral) {
  30038. return findSourceFile(fileName, false, file, ts.skipTrivia(file.text, nameLiteral.pos), nameLiteral.end);
  30039. }
  30040. }
  30041. function computeCommonSourceDirectory(sourceFiles) {
  30042. var commonPathComponents;
  30043. var currentDirectory = host.getCurrentDirectory();
  30044. ts.forEach(files, function (sourceFile) {
  30045. if (ts.isDeclarationFile(sourceFile)) {
  30046. return;
  30047. }
  30048. var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, currentDirectory);
  30049. sourcePathComponents.pop();
  30050. if (!commonPathComponents) {
  30051. commonPathComponents = sourcePathComponents;
  30052. return;
  30053. }
  30054. for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) {
  30055. if (commonPathComponents[i] !== sourcePathComponents[i]) {
  30056. if (i === 0) {
  30057. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
  30058. return;
  30059. }
  30060. commonPathComponents.length = i;
  30061. break;
  30062. }
  30063. }
  30064. if (sourcePathComponents.length < commonPathComponents.length) {
  30065. commonPathComponents.length = sourcePathComponents.length;
  30066. }
  30067. });
  30068. return ts.getNormalizedPathFromPathComponents(commonPathComponents);
  30069. }
  30070. function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) {
  30071. var allFilesBelongToPath = true;
  30072. if (sourceFiles) {
  30073. var currentDirectory = host.getCurrentDirectory();
  30074. var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory));
  30075. for (var _i = 0; _i < sourceFiles.length; _i++) {
  30076. var sourceFile = sourceFiles[_i];
  30077. if (!ts.isDeclarationFile(sourceFile)) {
  30078. var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
  30079. if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
  30080. 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));
  30081. allFilesBelongToPath = false;
  30082. }
  30083. }
  30084. }
  30085. }
  30086. return allFilesBelongToPath;
  30087. }
  30088. function verifyCompilerOptions() {
  30089. if (options.isolatedModules) {
  30090. if (options.declaration) {
  30091. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules"));
  30092. }
  30093. if (options.noEmitOnError) {
  30094. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules"));
  30095. }
  30096. if (options.out) {
  30097. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules"));
  30098. }
  30099. if (options.outFile) {
  30100. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules"));
  30101. }
  30102. }
  30103. if (options.inlineSourceMap) {
  30104. if (options.sourceMap) {
  30105. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap"));
  30106. }
  30107. if (options.mapRoot) {
  30108. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap"));
  30109. }
  30110. if (options.sourceRoot) {
  30111. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap"));
  30112. }
  30113. }
  30114. if (options.inlineSources) {
  30115. if (!options.sourceMap && !options.inlineSourceMap) {
  30116. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided));
  30117. }
  30118. }
  30119. if (options.out && options.outFile) {
  30120. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile"));
  30121. }
  30122. if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
  30123. if (options.mapRoot) {
  30124. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap"));
  30125. }
  30126. if (options.sourceRoot) {
  30127. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap"));
  30128. }
  30129. return;
  30130. }
  30131. var languageVersion = options.target || 0;
  30132. var outFile = options.outFile || options.out;
  30133. var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; });
  30134. if (options.isolatedModules) {
  30135. if (!options.module && languageVersion < 2) {
  30136. 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));
  30137. }
  30138. var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; });
  30139. if (firstNonExternalModuleSourceFile) {
  30140. var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
  30141. programDiagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
  30142. }
  30143. }
  30144. else if (firstExternalModuleSourceFile && languageVersion < 2 && !options.module) {
  30145. var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
  30146. programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided));
  30147. }
  30148. if (options.module && languageVersion >= 2) {
  30149. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher));
  30150. }
  30151. if (options.outDir ||
  30152. options.sourceRoot ||
  30153. (options.mapRoot &&
  30154. (!outFile || firstExternalModuleSourceFile !== undefined))) {
  30155. if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
  30156. commonSourceDirectory = ts.getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory());
  30157. }
  30158. else {
  30159. commonSourceDirectory = computeCommonSourceDirectory(files);
  30160. }
  30161. if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== ts.directorySeparator) {
  30162. commonSourceDirectory += ts.directorySeparator;
  30163. }
  30164. }
  30165. if (options.noEmit) {
  30166. if (options.out) {
  30167. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out"));
  30168. }
  30169. if (options.outFile) {
  30170. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile"));
  30171. }
  30172. if (options.outDir) {
  30173. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir"));
  30174. }
  30175. if (options.declaration) {
  30176. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration"));
  30177. }
  30178. }
  30179. if (options.emitDecoratorMetadata &&
  30180. !options.experimentalDecorators) {
  30181. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
  30182. }
  30183. if (options.experimentalAsyncFunctions &&
  30184. options.target !== 2) {
  30185. programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower));
  30186. }
  30187. }
  30188. }
  30189. ts.createProgram = createProgram;
  30190. })(ts || (ts = {}));
  30191. /// <reference path="sys.ts"/>
  30192. /// <reference path="types.ts"/>
  30193. /// <reference path="core.ts"/>
  30194. /// <reference path="scanner.ts"/>
  30195. var ts;
  30196. (function (ts) {
  30197. ts.optionDeclarations = [
  30198. {
  30199. name: "charset",
  30200. type: "string"
  30201. },
  30202. {
  30203. name: "declaration",
  30204. shortName: "d",
  30205. type: "boolean",
  30206. description: ts.Diagnostics.Generates_corresponding_d_ts_file
  30207. },
  30208. {
  30209. name: "diagnostics",
  30210. type: "boolean"
  30211. },
  30212. {
  30213. name: "emitBOM",
  30214. type: "boolean"
  30215. },
  30216. {
  30217. name: "help",
  30218. shortName: "h",
  30219. type: "boolean",
  30220. description: ts.Diagnostics.Print_this_message
  30221. },
  30222. {
  30223. name: "init",
  30224. type: "boolean",
  30225. description: ts.Diagnostics.Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file
  30226. },
  30227. {
  30228. name: "inlineSourceMap",
  30229. type: "boolean"
  30230. },
  30231. {
  30232. name: "inlineSources",
  30233. type: "boolean"
  30234. },
  30235. {
  30236. name: "jsx",
  30237. type: {
  30238. "preserve": 1,
  30239. "react": 2
  30240. },
  30241. paramType: ts.Diagnostics.KIND,
  30242. description: ts.Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
  30243. error: ts.Diagnostics.Argument_for_jsx_must_be_preserve_or_react
  30244. },
  30245. {
  30246. name: "listFiles",
  30247. type: "boolean"
  30248. },
  30249. {
  30250. name: "locale",
  30251. type: "string"
  30252. },
  30253. {
  30254. name: "mapRoot",
  30255. type: "string",
  30256. isFilePath: true,
  30257. description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
  30258. paramType: ts.Diagnostics.LOCATION
  30259. },
  30260. {
  30261. name: "module",
  30262. shortName: "m",
  30263. type: {
  30264. "commonjs": 1,
  30265. "amd": 2,
  30266. "system": 4,
  30267. "umd": 3
  30268. },
  30269. description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd,
  30270. paramType: ts.Diagnostics.KIND,
  30271. error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
  30272. },
  30273. {
  30274. name: "newLine",
  30275. type: {
  30276. "crlf": 0,
  30277. "lf": 1
  30278. },
  30279. description: ts.Diagnostics.Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
  30280. paramType: ts.Diagnostics.NEWLINE,
  30281. error: ts.Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF
  30282. },
  30283. {
  30284. name: "noEmit",
  30285. type: "boolean",
  30286. description: ts.Diagnostics.Do_not_emit_outputs
  30287. },
  30288. {
  30289. name: "noEmitHelpers",
  30290. type: "boolean"
  30291. },
  30292. {
  30293. name: "noEmitOnError",
  30294. type: "boolean",
  30295. description: ts.Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported
  30296. },
  30297. {
  30298. name: "noImplicitAny",
  30299. type: "boolean",
  30300. description: ts.Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type
  30301. },
  30302. {
  30303. name: "noLib",
  30304. type: "boolean"
  30305. },
  30306. {
  30307. name: "noResolve",
  30308. type: "boolean"
  30309. },
  30310. {
  30311. name: "skipDefaultLibCheck",
  30312. type: "boolean"
  30313. },
  30314. {
  30315. name: "out",
  30316. type: "string",
  30317. isFilePath: false,
  30318. paramType: ts.Diagnostics.FILE
  30319. },
  30320. {
  30321. name: "outFile",
  30322. type: "string",
  30323. isFilePath: true,
  30324. description: ts.Diagnostics.Concatenate_and_emit_output_to_single_file,
  30325. paramType: ts.Diagnostics.FILE
  30326. },
  30327. {
  30328. name: "outDir",
  30329. type: "string",
  30330. isFilePath: true,
  30331. description: ts.Diagnostics.Redirect_output_structure_to_the_directory,
  30332. paramType: ts.Diagnostics.DIRECTORY
  30333. },
  30334. {
  30335. name: "preserveConstEnums",
  30336. type: "boolean",
  30337. description: ts.Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
  30338. },
  30339. {
  30340. name: "project",
  30341. shortName: "p",
  30342. type: "string",
  30343. isFilePath: true,
  30344. description: ts.Diagnostics.Compile_the_project_in_the_given_directory,
  30345. paramType: ts.Diagnostics.DIRECTORY
  30346. },
  30347. {
  30348. name: "removeComments",
  30349. type: "boolean",
  30350. description: ts.Diagnostics.Do_not_emit_comments_to_output
  30351. },
  30352. {
  30353. name: "rootDir",
  30354. type: "string",
  30355. isFilePath: true,
  30356. description: ts.Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
  30357. paramType: ts.Diagnostics.LOCATION
  30358. },
  30359. {
  30360. name: "isolatedModules",
  30361. type: "boolean"
  30362. },
  30363. {
  30364. name: "sourceMap",
  30365. type: "boolean",
  30366. description: ts.Diagnostics.Generates_corresponding_map_file
  30367. },
  30368. {
  30369. name: "sourceRoot",
  30370. type: "string",
  30371. isFilePath: true,
  30372. description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
  30373. paramType: ts.Diagnostics.LOCATION
  30374. },
  30375. {
  30376. name: "suppressExcessPropertyErrors",
  30377. type: "boolean",
  30378. description: ts.Diagnostics.Suppress_excess_property_checks_for_object_literals,
  30379. experimental: true
  30380. },
  30381. {
  30382. name: "suppressImplicitAnyIndexErrors",
  30383. type: "boolean",
  30384. description: ts.Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures
  30385. },
  30386. {
  30387. name: "stripInternal",
  30388. type: "boolean",
  30389. description: ts.Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
  30390. experimental: true
  30391. },
  30392. {
  30393. name: "target",
  30394. shortName: "t",
  30395. type: { "es3": 0, "es5": 1, "es6": 2 },
  30396. description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental,
  30397. paramType: ts.Diagnostics.VERSION,
  30398. error: ts.Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6
  30399. },
  30400. {
  30401. name: "version",
  30402. shortName: "v",
  30403. type: "boolean",
  30404. description: ts.Diagnostics.Print_the_compiler_s_version
  30405. },
  30406. {
  30407. name: "watch",
  30408. shortName: "w",
  30409. type: "boolean",
  30410. description: ts.Diagnostics.Watch_input_files
  30411. },
  30412. {
  30413. name: "experimentalAsyncFunctions",
  30414. type: "boolean",
  30415. description: ts.Diagnostics.Enables_experimental_support_for_ES7_async_functions
  30416. },
  30417. {
  30418. name: "experimentalDecorators",
  30419. type: "boolean",
  30420. description: ts.Diagnostics.Enables_experimental_support_for_ES7_decorators
  30421. },
  30422. {
  30423. name: "emitDecoratorMetadata",
  30424. type: "boolean",
  30425. experimental: true,
  30426. description: ts.Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
  30427. },
  30428. {
  30429. name: "moduleResolution",
  30430. type: {
  30431. "node": 2,
  30432. "classic": 1
  30433. },
  30434. description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
  30435. error: ts.Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic
  30436. }
  30437. ];
  30438. var optionNameMapCache;
  30439. function getOptionNameMap() {
  30440. if (optionNameMapCache) {
  30441. return optionNameMapCache;
  30442. }
  30443. var optionNameMap = {};
  30444. var shortOptionNames = {};
  30445. ts.forEach(ts.optionDeclarations, function (option) {
  30446. optionNameMap[option.name.toLowerCase()] = option;
  30447. if (option.shortName) {
  30448. shortOptionNames[option.shortName] = option.name;
  30449. }
  30450. });
  30451. optionNameMapCache = { optionNameMap: optionNameMap, shortOptionNames: shortOptionNames };
  30452. return optionNameMapCache;
  30453. }
  30454. ts.getOptionNameMap = getOptionNameMap;
  30455. function parseCommandLine(commandLine, readFile) {
  30456. var options = {};
  30457. var fileNames = [];
  30458. var errors = [];
  30459. var _a = getOptionNameMap(), optionNameMap = _a.optionNameMap, shortOptionNames = _a.shortOptionNames;
  30460. parseStrings(commandLine);
  30461. return {
  30462. options: options,
  30463. fileNames: fileNames,
  30464. errors: errors
  30465. };
  30466. function parseStrings(args) {
  30467. var i = 0;
  30468. while (i < args.length) {
  30469. var s = args[i++];
  30470. if (s.charCodeAt(0) === 64) {
  30471. parseResponseFile(s.slice(1));
  30472. }
  30473. else if (s.charCodeAt(0) === 45) {
  30474. s = s.slice(s.charCodeAt(1) === 45 ? 2 : 1).toLowerCase();
  30475. if (ts.hasProperty(shortOptionNames, s)) {
  30476. s = shortOptionNames[s];
  30477. }
  30478. if (ts.hasProperty(optionNameMap, s)) {
  30479. var opt = optionNameMap[s];
  30480. if (!args[i] && opt.type !== "boolean") {
  30481. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_expects_an_argument, opt.name));
  30482. }
  30483. switch (opt.type) {
  30484. case "number":
  30485. options[opt.name] = parseInt(args[i++]);
  30486. break;
  30487. case "boolean":
  30488. options[opt.name] = true;
  30489. break;
  30490. case "string":
  30491. options[opt.name] = args[i++] || "";
  30492. break;
  30493. default:
  30494. var map_2 = opt.type;
  30495. var key = (args[i++] || "").toLowerCase();
  30496. if (ts.hasProperty(map_2, key)) {
  30497. options[opt.name] = map_2[key];
  30498. }
  30499. else {
  30500. errors.push(ts.createCompilerDiagnostic(opt.error));
  30501. }
  30502. }
  30503. }
  30504. else {
  30505. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, s));
  30506. }
  30507. }
  30508. else {
  30509. fileNames.push(s);
  30510. }
  30511. }
  30512. }
  30513. function parseResponseFile(fileName) {
  30514. var text = readFile ? readFile(fileName) : ts.sys.readFile(fileName);
  30515. if (!text) {
  30516. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_not_found, fileName));
  30517. return;
  30518. }
  30519. var args = [];
  30520. var pos = 0;
  30521. while (true) {
  30522. while (pos < text.length && text.charCodeAt(pos) <= 32)
  30523. pos++;
  30524. if (pos >= text.length)
  30525. break;
  30526. var start = pos;
  30527. if (text.charCodeAt(start) === 34) {
  30528. pos++;
  30529. while (pos < text.length && text.charCodeAt(pos) !== 34)
  30530. pos++;
  30531. if (pos < text.length) {
  30532. args.push(text.substring(start + 1, pos));
  30533. pos++;
  30534. }
  30535. else {
  30536. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unterminated_quoted_string_in_response_file_0, fileName));
  30537. }
  30538. }
  30539. else {
  30540. while (text.charCodeAt(pos) > 32)
  30541. pos++;
  30542. args.push(text.substring(start, pos));
  30543. }
  30544. }
  30545. parseStrings(args);
  30546. }
  30547. }
  30548. ts.parseCommandLine = parseCommandLine;
  30549. function readConfigFile(fileName) {
  30550. var text = "";
  30551. try {
  30552. text = ts.sys.readFile(fileName);
  30553. }
  30554. catch (e) {
  30555. return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
  30556. }
  30557. return parseConfigFileText(fileName, text);
  30558. }
  30559. ts.readConfigFile = readConfigFile;
  30560. function parseConfigFileText(fileName, jsonText) {
  30561. try {
  30562. return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} };
  30563. }
  30564. catch (e) {
  30565. return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) };
  30566. }
  30567. }
  30568. ts.parseConfigFileText = parseConfigFileText;
  30569. function parseConfigFile(json, host, basePath) {
  30570. var errors = [];
  30571. return {
  30572. options: getCompilerOptions(),
  30573. fileNames: getFileNames(),
  30574. errors: errors
  30575. };
  30576. function getCompilerOptions() {
  30577. var options = {};
  30578. var optionNameMap = {};
  30579. ts.forEach(ts.optionDeclarations, function (option) {
  30580. optionNameMap[option.name] = option;
  30581. });
  30582. var jsonOptions = json["compilerOptions"];
  30583. if (jsonOptions) {
  30584. for (var id in jsonOptions) {
  30585. if (ts.hasProperty(optionNameMap, id)) {
  30586. var opt = optionNameMap[id];
  30587. var optType = opt.type;
  30588. var value = jsonOptions[id];
  30589. var expectedType = typeof optType === "string" ? optType : "string";
  30590. if (typeof value === expectedType) {
  30591. if (typeof optType !== "string") {
  30592. var key = value.toLowerCase();
  30593. if (ts.hasProperty(optType, key)) {
  30594. value = optType[key];
  30595. }
  30596. else {
  30597. errors.push(ts.createCompilerDiagnostic(opt.error));
  30598. value = 0;
  30599. }
  30600. }
  30601. if (opt.isFilePath) {
  30602. value = ts.normalizePath(ts.combinePaths(basePath, value));
  30603. }
  30604. options[opt.name] = value;
  30605. }
  30606. else {
  30607. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType));
  30608. }
  30609. }
  30610. else {
  30611. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, id));
  30612. }
  30613. }
  30614. }
  30615. return options;
  30616. }
  30617. function getFileNames() {
  30618. var fileNames = [];
  30619. if (ts.hasProperty(json, "files")) {
  30620. if (json["files"] instanceof Array) {
  30621. fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); });
  30622. }
  30623. else {
  30624. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "files", "Array"));
  30625. }
  30626. }
  30627. else {
  30628. var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined;
  30629. var sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
  30630. for (var i = 0; i < sysFiles.length; i++) {
  30631. var name_27 = sysFiles[i];
  30632. if (ts.fileExtensionIs(name_27, ".d.ts")) {
  30633. var baseName = name_27.substr(0, name_27.length - ".d.ts".length);
  30634. if (!ts.contains(sysFiles, baseName + ".tsx") && !ts.contains(sysFiles, baseName + ".ts")) {
  30635. fileNames.push(name_27);
  30636. }
  30637. }
  30638. else if (ts.fileExtensionIs(name_27, ".ts")) {
  30639. if (!ts.contains(sysFiles, name_27 + "x")) {
  30640. fileNames.push(name_27);
  30641. }
  30642. }
  30643. else {
  30644. fileNames.push(name_27);
  30645. }
  30646. }
  30647. }
  30648. return fileNames;
  30649. }
  30650. }
  30651. ts.parseConfigFile = parseConfigFile;
  30652. })(ts || (ts = {}));
  30653. /// <reference path="program.ts"/>
  30654. /// <reference path="commandLineParser.ts"/>
  30655. var ts;
  30656. (function (ts) {
  30657. function validateLocaleAndSetLanguage(locale, errors) {
  30658. var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
  30659. if (!matchResult) {
  30660. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, "en", "ja-jp"));
  30661. return false;
  30662. }
  30663. var language = matchResult[1];
  30664. var territory = matchResult[3];
  30665. if (!trySetLanguageAndTerritory(language, territory, errors) &&
  30666. !trySetLanguageAndTerritory(language, undefined, errors)) {
  30667. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_locale_0, locale));
  30668. return false;
  30669. }
  30670. return true;
  30671. }
  30672. function trySetLanguageAndTerritory(language, territory, errors) {
  30673. var compilerFilePath = ts.normalizePath(ts.sys.getExecutingFilePath());
  30674. var containingDirectoryPath = ts.getDirectoryPath(compilerFilePath);
  30675. var filePath = ts.combinePaths(containingDirectoryPath, language);
  30676. if (territory) {
  30677. filePath = filePath + "-" + territory;
  30678. }
  30679. filePath = ts.sys.resolvePath(ts.combinePaths(filePath, "diagnosticMessages.generated.json"));
  30680. if (!ts.sys.fileExists(filePath)) {
  30681. return false;
  30682. }
  30683. var fileContents = "";
  30684. try {
  30685. fileContents = ts.sys.readFile(filePath);
  30686. }
  30687. catch (e) {
  30688. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unable_to_open_file_0, filePath));
  30689. return false;
  30690. }
  30691. try {
  30692. ts.localizedDiagnosticMessages = JSON.parse(fileContents);
  30693. }
  30694. catch (e) {
  30695. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Corrupted_locale_file_0, filePath));
  30696. return false;
  30697. }
  30698. return true;
  30699. }
  30700. function countLines(program) {
  30701. var count = 0;
  30702. ts.forEach(program.getSourceFiles(), function (file) {
  30703. count += ts.getLineStarts(file).length;
  30704. });
  30705. return count;
  30706. }
  30707. function getDiagnosticText(message) {
  30708. var args = [];
  30709. for (var _i = 1; _i < arguments.length; _i++) {
  30710. args[_i - 1] = arguments[_i];
  30711. }
  30712. var diagnostic = ts.createCompilerDiagnostic.apply(undefined, arguments);
  30713. return diagnostic.messageText;
  30714. }
  30715. function reportDiagnostic(diagnostic) {
  30716. var output = "";
  30717. if (diagnostic.file) {
  30718. var loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
  30719. output += diagnostic.file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + "): ";
  30720. }
  30721. var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase();
  30722. output += category + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
  30723. ts.sys.write(output);
  30724. }
  30725. function reportDiagnostics(diagnostics) {
  30726. for (var i = 0; i < diagnostics.length; i++) {
  30727. reportDiagnostic(diagnostics[i]);
  30728. }
  30729. }
  30730. function padLeft(s, length) {
  30731. while (s.length < length) {
  30732. s = " " + s;
  30733. }
  30734. return s;
  30735. }
  30736. function padRight(s, length) {
  30737. while (s.length < length) {
  30738. s = s + " ";
  30739. }
  30740. return s;
  30741. }
  30742. function reportStatisticalValue(name, value) {
  30743. ts.sys.write(padRight(name + ":", 12) + padLeft(value.toString(), 10) + ts.sys.newLine);
  30744. }
  30745. function reportCountStatistic(name, count) {
  30746. reportStatisticalValue(name, "" + count);
  30747. }
  30748. function reportTimeStatistic(name, time) {
  30749. reportStatisticalValue(name, (time / 1000).toFixed(2) + "s");
  30750. }
  30751. function isJSONSupported() {
  30752. return typeof JSON === "object" && typeof JSON.parse === "function";
  30753. }
  30754. function executeCommandLine(args) {
  30755. var commandLine = ts.parseCommandLine(args);
  30756. var configFileName;
  30757. var configFileWatcher;
  30758. var cachedProgram;
  30759. var rootFileNames;
  30760. var compilerOptions;
  30761. var compilerHost;
  30762. var hostGetSourceFile;
  30763. var timerHandle;
  30764. if (commandLine.options.locale) {
  30765. if (!isJSONSupported()) {
  30766. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"));
  30767. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  30768. }
  30769. validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors);
  30770. }
  30771. if (commandLine.errors.length > 0) {
  30772. reportDiagnostics(commandLine.errors);
  30773. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  30774. }
  30775. if (commandLine.options.init) {
  30776. writeConfigFile(commandLine.options, commandLine.fileNames);
  30777. return ts.sys.exit(ts.ExitStatus.Success);
  30778. }
  30779. if (commandLine.options.version) {
  30780. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Version_0, ts.version));
  30781. return ts.sys.exit(ts.ExitStatus.Success);
  30782. }
  30783. if (commandLine.options.help) {
  30784. printVersion();
  30785. printHelp();
  30786. return ts.sys.exit(ts.ExitStatus.Success);
  30787. }
  30788. if (commandLine.options.project) {
  30789. if (!isJSONSupported()) {
  30790. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--project"));
  30791. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  30792. }
  30793. configFileName = ts.normalizePath(ts.combinePaths(commandLine.options.project, "tsconfig.json"));
  30794. if (commandLine.fileNames.length !== 0) {
  30795. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
  30796. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  30797. }
  30798. }
  30799. else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
  30800. var searchPath = ts.normalizePath(ts.sys.getCurrentDirectory());
  30801. configFileName = ts.findConfigFile(searchPath);
  30802. }
  30803. if (commandLine.fileNames.length === 0 && !configFileName) {
  30804. printVersion();
  30805. printHelp();
  30806. return ts.sys.exit(ts.ExitStatus.Success);
  30807. }
  30808. if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) {
  30809. if (!ts.sys.watchFile) {
  30810. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"));
  30811. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  30812. }
  30813. if (configFileName) {
  30814. configFileWatcher = ts.sys.watchFile(configFileName, configFileChanged);
  30815. }
  30816. }
  30817. performCompilation();
  30818. function performCompilation() {
  30819. if (!cachedProgram) {
  30820. if (configFileName) {
  30821. var result = ts.readConfigFile(configFileName);
  30822. if (result.error) {
  30823. reportDiagnostic(result.error);
  30824. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  30825. }
  30826. var configObject = result.config;
  30827. var configParseResult = ts.parseConfigFile(configObject, ts.sys, ts.getDirectoryPath(configFileName));
  30828. if (configParseResult.errors.length > 0) {
  30829. reportDiagnostics(configParseResult.errors);
  30830. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  30831. }
  30832. rootFileNames = configParseResult.fileNames;
  30833. compilerOptions = ts.extend(commandLine.options, configParseResult.options);
  30834. }
  30835. else {
  30836. rootFileNames = commandLine.fileNames;
  30837. compilerOptions = commandLine.options;
  30838. }
  30839. compilerHost = ts.createCompilerHost(compilerOptions);
  30840. hostGetSourceFile = compilerHost.getSourceFile;
  30841. compilerHost.getSourceFile = getSourceFile;
  30842. }
  30843. var compileResult = compile(rootFileNames, compilerOptions, compilerHost);
  30844. if (!compilerOptions.watch) {
  30845. return ts.sys.exit(compileResult.exitStatus);
  30846. }
  30847. setCachedProgram(compileResult.program);
  30848. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes));
  30849. }
  30850. function getSourceFile(fileName, languageVersion, onError) {
  30851. if (cachedProgram) {
  30852. var sourceFile_1 = cachedProgram.getSourceFile(fileName);
  30853. if (sourceFile_1 && sourceFile_1.fileWatcher) {
  30854. return sourceFile_1;
  30855. }
  30856. }
  30857. var sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
  30858. if (sourceFile && compilerOptions.watch) {
  30859. sourceFile.fileWatcher = ts.sys.watchFile(sourceFile.fileName, function () { return sourceFileChanged(sourceFile); });
  30860. }
  30861. return sourceFile;
  30862. }
  30863. function setCachedProgram(program) {
  30864. if (cachedProgram) {
  30865. var newSourceFiles = program ? program.getSourceFiles() : undefined;
  30866. ts.forEach(cachedProgram.getSourceFiles(), function (sourceFile) {
  30867. if (!(newSourceFiles && ts.contains(newSourceFiles, sourceFile))) {
  30868. if (sourceFile.fileWatcher) {
  30869. sourceFile.fileWatcher.close();
  30870. sourceFile.fileWatcher = undefined;
  30871. }
  30872. }
  30873. });
  30874. }
  30875. cachedProgram = program;
  30876. }
  30877. function sourceFileChanged(sourceFile) {
  30878. sourceFile.fileWatcher.close();
  30879. sourceFile.fileWatcher = undefined;
  30880. startTimer();
  30881. }
  30882. function configFileChanged() {
  30883. setCachedProgram(undefined);
  30884. startTimer();
  30885. }
  30886. function startTimer() {
  30887. if (timerHandle) {
  30888. clearTimeout(timerHandle);
  30889. }
  30890. timerHandle = setTimeout(recompile, 250);
  30891. }
  30892. function recompile() {
  30893. timerHandle = undefined;
  30894. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation));
  30895. performCompilation();
  30896. }
  30897. }
  30898. ts.executeCommandLine = executeCommandLine;
  30899. function compile(fileNames, compilerOptions, compilerHost) {
  30900. ts.ioReadTime = 0;
  30901. ts.ioWriteTime = 0;
  30902. ts.programTime = 0;
  30903. ts.bindTime = 0;
  30904. ts.checkTime = 0;
  30905. ts.emitTime = 0;
  30906. var program = ts.createProgram(fileNames, compilerOptions, compilerHost);
  30907. var exitStatus = compileProgram();
  30908. if (compilerOptions.listFiles) {
  30909. ts.forEach(program.getSourceFiles(), function (file) {
  30910. ts.sys.write(file.fileName + ts.sys.newLine);
  30911. });
  30912. }
  30913. if (compilerOptions.diagnostics) {
  30914. var memoryUsed = ts.sys.getMemoryUsage ? ts.sys.getMemoryUsage() : -1;
  30915. reportCountStatistic("Files", program.getSourceFiles().length);
  30916. reportCountStatistic("Lines", countLines(program));
  30917. reportCountStatistic("Nodes", program.getNodeCount());
  30918. reportCountStatistic("Identifiers", program.getIdentifierCount());
  30919. reportCountStatistic("Symbols", program.getSymbolCount());
  30920. reportCountStatistic("Types", program.getTypeCount());
  30921. if (memoryUsed >= 0) {
  30922. reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K");
  30923. }
  30924. reportTimeStatistic("I/O read", ts.ioReadTime);
  30925. reportTimeStatistic("I/O write", ts.ioWriteTime);
  30926. reportTimeStatistic("Parse time", ts.programTime);
  30927. reportTimeStatistic("Bind time", ts.bindTime);
  30928. reportTimeStatistic("Check time", ts.checkTime);
  30929. reportTimeStatistic("Emit time", ts.emitTime);
  30930. reportTimeStatistic("Total time", ts.programTime + ts.bindTime + ts.checkTime + ts.emitTime);
  30931. }
  30932. return { program: program, exitStatus: exitStatus };
  30933. function compileProgram() {
  30934. var diagnostics;
  30935. diagnostics = program.getSyntacticDiagnostics();
  30936. if (diagnostics.length === 0) {
  30937. diagnostics = program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics());
  30938. if (diagnostics.length === 0) {
  30939. diagnostics = program.getSemanticDiagnostics();
  30940. }
  30941. }
  30942. reportDiagnostics(diagnostics);
  30943. if (compilerOptions.noEmit) {
  30944. return diagnostics.length
  30945. ? ts.ExitStatus.DiagnosticsPresent_OutputsSkipped
  30946. : ts.ExitStatus.Success;
  30947. }
  30948. var emitOutput = program.emit();
  30949. reportDiagnostics(emitOutput.diagnostics);
  30950. if (emitOutput.emitSkipped) {
  30951. return ts.ExitStatus.DiagnosticsPresent_OutputsSkipped;
  30952. }
  30953. if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) {
  30954. return ts.ExitStatus.DiagnosticsPresent_OutputsGenerated;
  30955. }
  30956. return ts.ExitStatus.Success;
  30957. }
  30958. }
  30959. function printVersion() {
  30960. ts.sys.write(getDiagnosticText(ts.Diagnostics.Version_0, ts.version) + ts.sys.newLine);
  30961. }
  30962. function printHelp() {
  30963. var output = "";
  30964. var syntaxLength = getDiagnosticText(ts.Diagnostics.Syntax_Colon_0, "").length;
  30965. var examplesLength = getDiagnosticText(ts.Diagnostics.Examples_Colon_0, "").length;
  30966. var marginLength = Math.max(syntaxLength, examplesLength);
  30967. var syntax = makePadding(marginLength - syntaxLength);
  30968. syntax += "tsc [" + getDiagnosticText(ts.Diagnostics.options) + "] [" + getDiagnosticText(ts.Diagnostics.file) + " ...]";
  30969. output += getDiagnosticText(ts.Diagnostics.Syntax_Colon_0, syntax);
  30970. output += ts.sys.newLine + ts.sys.newLine;
  30971. var padding = makePadding(marginLength);
  30972. output += getDiagnosticText(ts.Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + ts.sys.newLine;
  30973. output += padding + "tsc --out file.js file.ts" + ts.sys.newLine;
  30974. output += padding + "tsc @args.txt" + ts.sys.newLine;
  30975. output += ts.sys.newLine;
  30976. output += getDiagnosticText(ts.Diagnostics.Options_Colon) + ts.sys.newLine;
  30977. var optsList = ts.filter(ts.optionDeclarations.slice(), function (v) { return !v.experimental; });
  30978. optsList.sort(function (a, b) { return ts.compareValues(a.name.toLowerCase(), b.name.toLowerCase()); });
  30979. marginLength = 0;
  30980. var usageColumn = [];
  30981. var descriptionColumn = [];
  30982. for (var i = 0; i < optsList.length; i++) {
  30983. var option = optsList[i];
  30984. if (!option.description) {
  30985. continue;
  30986. }
  30987. var usageText_1 = " ";
  30988. if (option.shortName) {
  30989. usageText_1 += "-" + option.shortName;
  30990. usageText_1 += getParamType(option);
  30991. usageText_1 += ", ";
  30992. }
  30993. usageText_1 += "--" + option.name;
  30994. usageText_1 += getParamType(option);
  30995. usageColumn.push(usageText_1);
  30996. descriptionColumn.push(getDiagnosticText(option.description));
  30997. marginLength = Math.max(usageText_1.length, marginLength);
  30998. }
  30999. var usageText = " @<" + getDiagnosticText(ts.Diagnostics.file) + ">";
  31000. usageColumn.push(usageText);
  31001. descriptionColumn.push(getDiagnosticText(ts.Diagnostics.Insert_command_line_options_and_files_from_a_file));
  31002. marginLength = Math.max(usageText.length, marginLength);
  31003. for (var i = 0; i < usageColumn.length; i++) {
  31004. var usage = usageColumn[i];
  31005. var description = descriptionColumn[i];
  31006. output += usage + makePadding(marginLength - usage.length + 2) + description + ts.sys.newLine;
  31007. }
  31008. ts.sys.write(output);
  31009. return;
  31010. function getParamType(option) {
  31011. if (option.paramType !== undefined) {
  31012. return " " + getDiagnosticText(option.paramType);
  31013. }
  31014. return "";
  31015. }
  31016. function makePadding(paddingLength) {
  31017. return Array(paddingLength + 1).join(" ");
  31018. }
  31019. }
  31020. function writeConfigFile(options, fileNames) {
  31021. var currentDirectory = ts.sys.getCurrentDirectory();
  31022. var file = ts.combinePaths(currentDirectory, 'tsconfig.json');
  31023. if (ts.sys.fileExists(file)) {
  31024. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file));
  31025. }
  31026. else {
  31027. var compilerOptions = ts.extend(options, ts.defaultInitCompilerOptions);
  31028. var configurations = {
  31029. compilerOptions: serializeCompilerOptions(compilerOptions),
  31030. exclude: ["node_modules"]
  31031. };
  31032. if (fileNames && fileNames.length) {
  31033. configurations.files = fileNames;
  31034. }
  31035. ts.sys.writeFile(file, JSON.stringify(configurations, undefined, 4));
  31036. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Successfully_created_a_tsconfig_json_file));
  31037. }
  31038. return;
  31039. function serializeCompilerOptions(options) {
  31040. var result = {};
  31041. var optionsNameMap = ts.getOptionNameMap().optionNameMap;
  31042. for (var name_28 in options) {
  31043. if (ts.hasProperty(options, name_28)) {
  31044. var value = options[name_28];
  31045. switch (name_28) {
  31046. case "init":
  31047. case "watch":
  31048. case "version":
  31049. case "help":
  31050. case "project":
  31051. break;
  31052. default:
  31053. var optionDefinition = optionsNameMap[name_28.toLowerCase()];
  31054. if (optionDefinition) {
  31055. if (typeof optionDefinition.type === "string") {
  31056. result[name_28] = value;
  31057. }
  31058. else {
  31059. var typeMap = optionDefinition.type;
  31060. for (var key in typeMap) {
  31061. if (ts.hasProperty(typeMap, key)) {
  31062. if (typeMap[key] === value)
  31063. result[name_28] = key;
  31064. }
  31065. }
  31066. }
  31067. }
  31068. break;
  31069. }
  31070. }
  31071. }
  31072. return result;
  31073. }
  31074. }
  31075. })(ts || (ts = {}));
  31076. ts.executeCommandLine(ts.sys.args);