tsc.js 1.3 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385
  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. (function (ExitStatus) {
  16. ExitStatus[ExitStatus["Success"] = 0] = "Success";
  17. ExitStatus[ExitStatus["DiagnosticsPresent_OutputsSkipped"] = 1] = "DiagnosticsPresent_OutputsSkipped";
  18. ExitStatus[ExitStatus["DiagnosticsPresent_OutputsGenerated"] = 2] = "DiagnosticsPresent_OutputsGenerated";
  19. })(ts.ExitStatus || (ts.ExitStatus = {}));
  20. var ExitStatus = ts.ExitStatus;
  21. (function (DiagnosticCategory) {
  22. DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning";
  23. DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error";
  24. DiagnosticCategory[DiagnosticCategory["Message"] = 2] = "Message";
  25. })(ts.DiagnosticCategory || (ts.DiagnosticCategory = {}));
  26. var DiagnosticCategory = ts.DiagnosticCategory;
  27. })(ts || (ts = {}));
  28. /// <reference path="types.ts"/>
  29. var ts;
  30. (function (ts) {
  31. function createFileMap(getCanonicalFileName) {
  32. var files = {};
  33. return {
  34. get: get,
  35. set: set,
  36. contains: contains,
  37. remove: remove,
  38. forEachValue: forEachValueInMap
  39. };
  40. function set(fileName, value) {
  41. files[normalizeKey(fileName)] = value;
  42. }
  43. function get(fileName) {
  44. return files[normalizeKey(fileName)];
  45. }
  46. function contains(fileName) {
  47. return hasProperty(files, normalizeKey(fileName));
  48. }
  49. function remove(fileName) {
  50. var key = normalizeKey(fileName);
  51. delete files[key];
  52. }
  53. function forEachValueInMap(f) {
  54. forEachValue(files, f);
  55. }
  56. function normalizeKey(key) {
  57. return getCanonicalFileName(normalizeSlashes(key));
  58. }
  59. }
  60. ts.createFileMap = createFileMap;
  61. function forEach(array, callback) {
  62. if (array) {
  63. for (var i = 0, len = array.length; i < len; i++) {
  64. var result = callback(array[i], i);
  65. if (result) {
  66. return result;
  67. }
  68. }
  69. }
  70. return undefined;
  71. }
  72. ts.forEach = forEach;
  73. function contains(array, value) {
  74. if (array) {
  75. for (var _i = 0; _i < array.length; _i++) {
  76. var v = array[_i];
  77. if (v === value) {
  78. return true;
  79. }
  80. }
  81. }
  82. return false;
  83. }
  84. ts.contains = contains;
  85. function indexOf(array, value) {
  86. if (array) {
  87. for (var i = 0, len = array.length; i < len; i++) {
  88. if (array[i] === value) {
  89. return i;
  90. }
  91. }
  92. }
  93. return -1;
  94. }
  95. ts.indexOf = indexOf;
  96. function countWhere(array, predicate) {
  97. var count = 0;
  98. if (array) {
  99. for (var _i = 0; _i < array.length; _i++) {
  100. var v = array[_i];
  101. if (predicate(v)) {
  102. count++;
  103. }
  104. }
  105. }
  106. return count;
  107. }
  108. ts.countWhere = countWhere;
  109. function filter(array, f) {
  110. var result;
  111. if (array) {
  112. result = [];
  113. for (var _i = 0; _i < array.length; _i++) {
  114. var item = array[_i];
  115. if (f(item)) {
  116. result.push(item);
  117. }
  118. }
  119. }
  120. return result;
  121. }
  122. ts.filter = filter;
  123. function map(array, f) {
  124. var result;
  125. if (array) {
  126. result = [];
  127. for (var _i = 0; _i < array.length; _i++) {
  128. var v = array[_i];
  129. result.push(f(v));
  130. }
  131. }
  132. return result;
  133. }
  134. ts.map = map;
  135. function concatenate(array1, array2) {
  136. if (!array2 || !array2.length)
  137. return array1;
  138. if (!array1 || !array1.length)
  139. return array2;
  140. return array1.concat(array2);
  141. }
  142. ts.concatenate = concatenate;
  143. function deduplicate(array) {
  144. var result;
  145. if (array) {
  146. result = [];
  147. for (var _i = 0; _i < array.length; _i++) {
  148. var item = array[_i];
  149. if (!contains(result, item)) {
  150. result.push(item);
  151. }
  152. }
  153. }
  154. return result;
  155. }
  156. ts.deduplicate = deduplicate;
  157. function sum(array, prop) {
  158. var result = 0;
  159. for (var _i = 0; _i < array.length; _i++) {
  160. var v = array[_i];
  161. result += v[prop];
  162. }
  163. return result;
  164. }
  165. ts.sum = sum;
  166. function addRange(to, from) {
  167. if (to && from) {
  168. for (var _i = 0; _i < from.length; _i++) {
  169. var v = from[_i];
  170. to.push(v);
  171. }
  172. }
  173. }
  174. ts.addRange = addRange;
  175. function lastOrUndefined(array) {
  176. if (array.length === 0) {
  177. return undefined;
  178. }
  179. return array[array.length - 1];
  180. }
  181. ts.lastOrUndefined = lastOrUndefined;
  182. function binarySearch(array, value) {
  183. var low = 0;
  184. var high = array.length - 1;
  185. while (low <= high) {
  186. var middle = low + ((high - low) >> 1);
  187. var midValue = array[middle];
  188. if (midValue === value) {
  189. return middle;
  190. }
  191. else if (midValue > value) {
  192. high = middle - 1;
  193. }
  194. else {
  195. low = middle + 1;
  196. }
  197. }
  198. return ~low;
  199. }
  200. ts.binarySearch = binarySearch;
  201. function reduceLeft(array, f, initial) {
  202. if (array) {
  203. var count = array.length;
  204. if (count > 0) {
  205. var pos = 0;
  206. var result = arguments.length <= 2 ? array[pos++] : initial;
  207. while (pos < count) {
  208. result = f(result, array[pos++]);
  209. }
  210. return result;
  211. }
  212. }
  213. return initial;
  214. }
  215. ts.reduceLeft = reduceLeft;
  216. function reduceRight(array, f, initial) {
  217. if (array) {
  218. var pos = array.length - 1;
  219. if (pos >= 0) {
  220. var result = arguments.length <= 2 ? array[pos--] : initial;
  221. while (pos >= 0) {
  222. result = f(result, array[pos--]);
  223. }
  224. return result;
  225. }
  226. }
  227. return initial;
  228. }
  229. ts.reduceRight = reduceRight;
  230. var hasOwnProperty = Object.prototype.hasOwnProperty;
  231. function hasProperty(map, key) {
  232. return hasOwnProperty.call(map, key);
  233. }
  234. ts.hasProperty = hasProperty;
  235. function getProperty(map, key) {
  236. return hasOwnProperty.call(map, key) ? map[key] : undefined;
  237. }
  238. ts.getProperty = getProperty;
  239. function isEmpty(map) {
  240. for (var id in map) {
  241. if (hasProperty(map, id)) {
  242. return false;
  243. }
  244. }
  245. return true;
  246. }
  247. ts.isEmpty = isEmpty;
  248. function clone(object) {
  249. var result = {};
  250. for (var id in object) {
  251. result[id] = object[id];
  252. }
  253. return result;
  254. }
  255. ts.clone = clone;
  256. function extend(first, second) {
  257. var result = {};
  258. for (var id in first) {
  259. result[id] = first[id];
  260. }
  261. for (var id in second) {
  262. if (!hasProperty(result, id)) {
  263. result[id] = second[id];
  264. }
  265. }
  266. return result;
  267. }
  268. ts.extend = extend;
  269. function forEachValue(map, callback) {
  270. var result;
  271. for (var id in map) {
  272. if (result = callback(map[id]))
  273. break;
  274. }
  275. return result;
  276. }
  277. ts.forEachValue = forEachValue;
  278. function forEachKey(map, callback) {
  279. var result;
  280. for (var id in map) {
  281. if (result = callback(id))
  282. break;
  283. }
  284. return result;
  285. }
  286. ts.forEachKey = forEachKey;
  287. function lookUp(map, key) {
  288. return hasProperty(map, key) ? map[key] : undefined;
  289. }
  290. ts.lookUp = lookUp;
  291. function copyMap(source, target) {
  292. for (var p in source) {
  293. target[p] = source[p];
  294. }
  295. }
  296. ts.copyMap = copyMap;
  297. function arrayToMap(array, makeKey) {
  298. var result = {};
  299. forEach(array, function (value) {
  300. result[makeKey(value)] = value;
  301. });
  302. return result;
  303. }
  304. ts.arrayToMap = arrayToMap;
  305. function memoize(callback) {
  306. var value;
  307. return function () {
  308. if (callback) {
  309. value = callback();
  310. callback = undefined;
  311. }
  312. return value;
  313. };
  314. }
  315. ts.memoize = memoize;
  316. function formatStringFromArgs(text, args, baseIndex) {
  317. baseIndex = baseIndex || 0;
  318. return text.replace(/{(\d+)}/g, function (match, index) { return args[+index + baseIndex]; });
  319. }
  320. ts.localizedDiagnosticMessages = undefined;
  321. function getLocaleSpecificMessage(message) {
  322. return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message]
  323. ? ts.localizedDiagnosticMessages[message]
  324. : message;
  325. }
  326. ts.getLocaleSpecificMessage = getLocaleSpecificMessage;
  327. function createFileDiagnostic(file, start, length, message) {
  328. var end = start + length;
  329. Debug.assert(start >= 0, "start must be non-negative, is " + start);
  330. Debug.assert(length >= 0, "length must be non-negative, is " + length);
  331. Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length);
  332. Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length);
  333. var text = getLocaleSpecificMessage(message.key);
  334. if (arguments.length > 4) {
  335. text = formatStringFromArgs(text, arguments, 4);
  336. }
  337. return {
  338. file: file,
  339. start: start,
  340. length: length,
  341. messageText: text,
  342. category: message.category,
  343. code: message.code
  344. };
  345. }
  346. ts.createFileDiagnostic = createFileDiagnostic;
  347. function createCompilerDiagnostic(message) {
  348. var text = getLocaleSpecificMessage(message.key);
  349. if (arguments.length > 1) {
  350. text = formatStringFromArgs(text, arguments, 1);
  351. }
  352. return {
  353. file: undefined,
  354. start: undefined,
  355. length: undefined,
  356. messageText: text,
  357. category: message.category,
  358. code: message.code
  359. };
  360. }
  361. ts.createCompilerDiagnostic = createCompilerDiagnostic;
  362. function chainDiagnosticMessages(details, message) {
  363. var text = getLocaleSpecificMessage(message.key);
  364. if (arguments.length > 2) {
  365. text = formatStringFromArgs(text, arguments, 2);
  366. }
  367. return {
  368. messageText: text,
  369. category: message.category,
  370. code: message.code,
  371. next: details
  372. };
  373. }
  374. ts.chainDiagnosticMessages = chainDiagnosticMessages;
  375. function concatenateDiagnosticMessageChains(headChain, tailChain) {
  376. Debug.assert(!headChain.next);
  377. headChain.next = tailChain;
  378. return headChain;
  379. }
  380. ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains;
  381. function compareValues(a, b) {
  382. if (a === b)
  383. return 0;
  384. if (a === undefined)
  385. return -1;
  386. if (b === undefined)
  387. return 1;
  388. return a < b ? -1 : 1;
  389. }
  390. ts.compareValues = compareValues;
  391. function getDiagnosticFileName(diagnostic) {
  392. return diagnostic.file ? diagnostic.file.fileName : undefined;
  393. }
  394. function compareDiagnostics(d1, d2) {
  395. return compareValues(getDiagnosticFileName(d1), getDiagnosticFileName(d2)) ||
  396. compareValues(d1.start, d2.start) ||
  397. compareValues(d1.length, d2.length) ||
  398. compareValues(d1.code, d2.code) ||
  399. compareMessageText(d1.messageText, d2.messageText) ||
  400. 0;
  401. }
  402. ts.compareDiagnostics = compareDiagnostics;
  403. function compareMessageText(text1, text2) {
  404. while (text1 && text2) {
  405. var string1 = typeof text1 === "string" ? text1 : text1.messageText;
  406. var string2 = typeof text2 === "string" ? text2 : text2.messageText;
  407. var res = compareValues(string1, string2);
  408. if (res) {
  409. return res;
  410. }
  411. text1 = typeof text1 === "string" ? undefined : text1.next;
  412. text2 = typeof text2 === "string" ? undefined : text2.next;
  413. }
  414. if (!text1 && !text2) {
  415. return 0;
  416. }
  417. return text1 ? 1 : -1;
  418. }
  419. function sortAndDeduplicateDiagnostics(diagnostics) {
  420. return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics));
  421. }
  422. ts.sortAndDeduplicateDiagnostics = sortAndDeduplicateDiagnostics;
  423. function deduplicateSortedDiagnostics(diagnostics) {
  424. if (diagnostics.length < 2) {
  425. return diagnostics;
  426. }
  427. var newDiagnostics = [diagnostics[0]];
  428. var previousDiagnostic = diagnostics[0];
  429. for (var i = 1; i < diagnostics.length; i++) {
  430. var currentDiagnostic = diagnostics[i];
  431. var isDupe = compareDiagnostics(currentDiagnostic, previousDiagnostic) === 0;
  432. if (!isDupe) {
  433. newDiagnostics.push(currentDiagnostic);
  434. previousDiagnostic = currentDiagnostic;
  435. }
  436. }
  437. return newDiagnostics;
  438. }
  439. ts.deduplicateSortedDiagnostics = deduplicateSortedDiagnostics;
  440. function normalizeSlashes(path) {
  441. return path.replace(/\\/g, "/");
  442. }
  443. ts.normalizeSlashes = normalizeSlashes;
  444. function getRootLength(path) {
  445. if (path.charCodeAt(0) === 47) {
  446. if (path.charCodeAt(1) !== 47)
  447. return 1;
  448. var p1 = path.indexOf("/", 2);
  449. if (p1 < 0)
  450. return 2;
  451. var p2 = path.indexOf("/", p1 + 1);
  452. if (p2 < 0)
  453. return p1 + 1;
  454. return p2 + 1;
  455. }
  456. if (path.charCodeAt(1) === 58) {
  457. if (path.charCodeAt(2) === 47)
  458. return 3;
  459. return 2;
  460. }
  461. if (path.lastIndexOf("file:///", 0) === 0) {
  462. return "file:///".length;
  463. }
  464. var idx = path.indexOf('://');
  465. if (idx !== -1) {
  466. return idx + "://".length;
  467. }
  468. return 0;
  469. }
  470. ts.getRootLength = getRootLength;
  471. ts.directorySeparator = "/";
  472. function getNormalizedParts(normalizedSlashedPath, rootLength) {
  473. var parts = normalizedSlashedPath.substr(rootLength).split(ts.directorySeparator);
  474. var normalized = [];
  475. for (var _i = 0; _i < parts.length; _i++) {
  476. var part = parts[_i];
  477. if (part !== ".") {
  478. if (part === ".." && normalized.length > 0 && lastOrUndefined(normalized) !== "..") {
  479. normalized.pop();
  480. }
  481. else {
  482. if (part) {
  483. normalized.push(part);
  484. }
  485. }
  486. }
  487. }
  488. return normalized;
  489. }
  490. function normalizePath(path) {
  491. path = normalizeSlashes(path);
  492. var rootLength = getRootLength(path);
  493. var normalized = getNormalizedParts(path, rootLength);
  494. return path.substr(0, rootLength) + normalized.join(ts.directorySeparator);
  495. }
  496. ts.normalizePath = normalizePath;
  497. function getDirectoryPath(path) {
  498. return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(ts.directorySeparator)));
  499. }
  500. ts.getDirectoryPath = getDirectoryPath;
  501. function isUrl(path) {
  502. return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
  503. }
  504. ts.isUrl = isUrl;
  505. function isRootedDiskPath(path) {
  506. return getRootLength(path) !== 0;
  507. }
  508. ts.isRootedDiskPath = isRootedDiskPath;
  509. function normalizedPathComponents(path, rootLength) {
  510. var normalizedParts = getNormalizedParts(path, rootLength);
  511. return [path.substr(0, rootLength)].concat(normalizedParts);
  512. }
  513. function getNormalizedPathComponents(path, currentDirectory) {
  514. path = normalizeSlashes(path);
  515. var rootLength = getRootLength(path);
  516. if (rootLength == 0) {
  517. path = combinePaths(normalizeSlashes(currentDirectory), path);
  518. rootLength = getRootLength(path);
  519. }
  520. return normalizedPathComponents(path, rootLength);
  521. }
  522. ts.getNormalizedPathComponents = getNormalizedPathComponents;
  523. function getNormalizedAbsolutePath(fileName, currentDirectory) {
  524. return getNormalizedPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
  525. }
  526. ts.getNormalizedAbsolutePath = getNormalizedAbsolutePath;
  527. function getNormalizedPathFromPathComponents(pathComponents) {
  528. if (pathComponents && pathComponents.length) {
  529. return pathComponents[0] + pathComponents.slice(1).join(ts.directorySeparator);
  530. }
  531. }
  532. ts.getNormalizedPathFromPathComponents = getNormalizedPathFromPathComponents;
  533. function getNormalizedPathComponentsOfUrl(url) {
  534. // Get root length of http://www.website.com/folder1/foler2/
  535. // In this example the root is: http://www.website.com/
  536. // normalized path components should be ["http://www.website.com/", "folder1", "folder2"]
  537. var urlLength = url.length;
  538. var rootLength = url.indexOf("://") + "://".length;
  539. while (rootLength < urlLength) {
  540. if (url.charCodeAt(rootLength) === 47) {
  541. rootLength++;
  542. }
  543. else {
  544. break;
  545. }
  546. }
  547. if (rootLength === urlLength) {
  548. return [url];
  549. }
  550. var indexOfNextSlash = url.indexOf(ts.directorySeparator, rootLength);
  551. if (indexOfNextSlash !== -1) {
  552. rootLength = indexOfNextSlash + 1;
  553. return normalizedPathComponents(url, rootLength);
  554. }
  555. else {
  556. return [url + ts.directorySeparator];
  557. }
  558. }
  559. function getNormalizedPathOrUrlComponents(pathOrUrl, currentDirectory) {
  560. if (isUrl(pathOrUrl)) {
  561. return getNormalizedPathComponentsOfUrl(pathOrUrl);
  562. }
  563. else {
  564. return getNormalizedPathComponents(pathOrUrl, currentDirectory);
  565. }
  566. }
  567. function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) {
  568. var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
  569. var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
  570. if (directoryComponents.length > 1 && lastOrUndefined(directoryComponents) === "") {
  571. directoryComponents.length--;
  572. }
  573. for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) {
  574. if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) {
  575. break;
  576. }
  577. }
  578. if (joinStartIndex) {
  579. var relativePath = "";
  580. var relativePathComponents = pathComponents.slice(joinStartIndex, pathComponents.length);
  581. for (; joinStartIndex < directoryComponents.length; joinStartIndex++) {
  582. if (directoryComponents[joinStartIndex] !== "") {
  583. relativePath = relativePath + ".." + ts.directorySeparator;
  584. }
  585. }
  586. return relativePath + relativePathComponents.join(ts.directorySeparator);
  587. }
  588. var absolutePath = getNormalizedPathFromPathComponents(pathComponents);
  589. if (isAbsolutePathAnUrl && isRootedDiskPath(absolutePath)) {
  590. absolutePath = "file:///" + absolutePath;
  591. }
  592. return absolutePath;
  593. }
  594. ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl;
  595. function getBaseFileName(path) {
  596. var i = path.lastIndexOf(ts.directorySeparator);
  597. return i < 0 ? path : path.substring(i + 1);
  598. }
  599. ts.getBaseFileName = getBaseFileName;
  600. function combinePaths(path1, path2) {
  601. if (!(path1 && path1.length))
  602. return path2;
  603. if (!(path2 && path2.length))
  604. return path1;
  605. if (getRootLength(path2) !== 0)
  606. return path2;
  607. if (path1.charAt(path1.length - 1) === ts.directorySeparator)
  608. return path1 + path2;
  609. return path1 + ts.directorySeparator + path2;
  610. }
  611. ts.combinePaths = combinePaths;
  612. function fileExtensionIs(path, extension) {
  613. var pathLen = path.length;
  614. var extLen = extension.length;
  615. return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
  616. }
  617. ts.fileExtensionIs = fileExtensionIs;
  618. var supportedExtensions = [".d.ts", ".ts", ".js"];
  619. function removeFileExtension(path) {
  620. for (var _i = 0; _i < supportedExtensions.length; _i++) {
  621. var ext = supportedExtensions[_i];
  622. if (fileExtensionIs(path, ext)) {
  623. return path.substr(0, path.length - ext.length);
  624. }
  625. }
  626. return path;
  627. }
  628. ts.removeFileExtension = removeFileExtension;
  629. var backslashOrDoubleQuote = /[\"\\]/g;
  630. var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
  631. var escapedCharsMap = {
  632. "\0": "\\0",
  633. "\t": "\\t",
  634. "\v": "\\v",
  635. "\f": "\\f",
  636. "\b": "\\b",
  637. "\r": "\\r",
  638. "\n": "\\n",
  639. "\\": "\\\\",
  640. "\"": "\\\"",
  641. "\u2028": "\\u2028",
  642. "\u2029": "\\u2029",
  643. "\u0085": "\\u0085"
  644. };
  645. function Symbol(flags, name) {
  646. this.flags = flags;
  647. this.name = name;
  648. this.declarations = undefined;
  649. }
  650. function Type(checker, flags) {
  651. this.flags = flags;
  652. }
  653. function Signature(checker) {
  654. }
  655. ts.objectAllocator = {
  656. getNodeConstructor: function (kind) {
  657. function Node() {
  658. }
  659. Node.prototype = {
  660. kind: kind,
  661. pos: 0,
  662. end: 0,
  663. flags: 0,
  664. parent: undefined
  665. };
  666. return Node;
  667. },
  668. getSymbolConstructor: function () { return Symbol; },
  669. getTypeConstructor: function () { return Type; },
  670. getSignatureConstructor: function () { return Signature; }
  671. };
  672. var Debug;
  673. (function (Debug) {
  674. var currentAssertionLevel = 0;
  675. function shouldAssert(level) {
  676. return currentAssertionLevel >= level;
  677. }
  678. Debug.shouldAssert = shouldAssert;
  679. function assert(expression, message, verboseDebugInfo) {
  680. if (!expression) {
  681. var verboseDebugString = "";
  682. if (verboseDebugInfo) {
  683. verboseDebugString = "\r\nVerbose Debug Information: " + verboseDebugInfo();
  684. }
  685. throw new Error("Debug Failure. False expression: " + (message || "") + verboseDebugString);
  686. }
  687. }
  688. Debug.assert = assert;
  689. function fail(message) {
  690. Debug.assert(false, message);
  691. }
  692. Debug.fail = fail;
  693. })(Debug = ts.Debug || (ts.Debug = {}));
  694. })(ts || (ts = {}));
  695. /// <reference path="core.ts"/>
  696. var ts;
  697. (function (ts) {
  698. ts.sys = (function () {
  699. function getWScriptSystem() {
  700. var fso = new ActiveXObject("Scripting.FileSystemObject");
  701. var fileStream = new ActiveXObject("ADODB.Stream");
  702. fileStream.Type = 2;
  703. var binaryStream = new ActiveXObject("ADODB.Stream");
  704. binaryStream.Type = 1;
  705. var args = [];
  706. for (var i = 0; i < WScript.Arguments.length; i++) {
  707. args[i] = WScript.Arguments.Item(i);
  708. }
  709. function readFile(fileName, encoding) {
  710. if (!fso.FileExists(fileName)) {
  711. return undefined;
  712. }
  713. fileStream.Open();
  714. try {
  715. if (encoding) {
  716. fileStream.Charset = encoding;
  717. fileStream.LoadFromFile(fileName);
  718. }
  719. else {
  720. fileStream.Charset = "x-ansi";
  721. fileStream.LoadFromFile(fileName);
  722. var bom = fileStream.ReadText(2) || "";
  723. fileStream.Position = 0;
  724. fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
  725. }
  726. return fileStream.ReadText();
  727. }
  728. catch (e) {
  729. throw e;
  730. }
  731. finally {
  732. fileStream.Close();
  733. }
  734. }
  735. function writeFile(fileName, data, writeByteOrderMark) {
  736. fileStream.Open();
  737. binaryStream.Open();
  738. try {
  739. fileStream.Charset = "utf-8";
  740. fileStream.WriteText(data);
  741. if (writeByteOrderMark) {
  742. fileStream.Position = 0;
  743. }
  744. else {
  745. fileStream.Position = 3;
  746. }
  747. fileStream.CopyTo(binaryStream);
  748. binaryStream.SaveToFile(fileName, 2);
  749. }
  750. finally {
  751. binaryStream.Close();
  752. fileStream.Close();
  753. }
  754. }
  755. function getNames(collection) {
  756. var result = [];
  757. for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
  758. result.push(e.item().Name);
  759. }
  760. return result.sort();
  761. }
  762. function readDirectory(path, extension) {
  763. var result = [];
  764. visitDirectory(path);
  765. return result;
  766. function visitDirectory(path) {
  767. var folder = fso.GetFolder(path || ".");
  768. var files = getNames(folder.files);
  769. for (var _i = 0; _i < files.length; _i++) {
  770. var name_1 = files[_i];
  771. if (!extension || ts.fileExtensionIs(name_1, extension)) {
  772. result.push(ts.combinePaths(path, name_1));
  773. }
  774. }
  775. var subfolders = getNames(folder.subfolders);
  776. for (var _a = 0; _a < subfolders.length; _a++) {
  777. var current = subfolders[_a];
  778. visitDirectory(ts.combinePaths(path, current));
  779. }
  780. }
  781. }
  782. return {
  783. args: args,
  784. newLine: "\r\n",
  785. useCaseSensitiveFileNames: false,
  786. write: function (s) {
  787. WScript.StdOut.Write(s);
  788. },
  789. readFile: readFile,
  790. writeFile: writeFile,
  791. resolvePath: function (path) {
  792. return fso.GetAbsolutePathName(path);
  793. },
  794. fileExists: function (path) {
  795. return fso.FileExists(path);
  796. },
  797. directoryExists: function (path) {
  798. return fso.FolderExists(path);
  799. },
  800. createDirectory: function (directoryName) {
  801. if (!this.directoryExists(directoryName)) {
  802. fso.CreateFolder(directoryName);
  803. }
  804. },
  805. getExecutingFilePath: function () {
  806. return WScript.ScriptFullName;
  807. },
  808. getCurrentDirectory: function () {
  809. return new ActiveXObject("WScript.Shell").CurrentDirectory;
  810. },
  811. readDirectory: readDirectory,
  812. exit: function (exitCode) {
  813. try {
  814. WScript.Quit(exitCode);
  815. }
  816. catch (e) {
  817. }
  818. }
  819. };
  820. }
  821. function getNodeSystem() {
  822. var _fs = require("fs");
  823. var _path = require("path");
  824. var _os = require('os');
  825. var platform = _os.platform();
  826. var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
  827. function readFile(fileName, encoding) {
  828. if (!_fs.existsSync(fileName)) {
  829. return undefined;
  830. }
  831. var buffer = _fs.readFileSync(fileName);
  832. var len = buffer.length;
  833. if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
  834. len &= ~1;
  835. for (var i = 0; i < len; i += 2) {
  836. var temp = buffer[i];
  837. buffer[i] = buffer[i + 1];
  838. buffer[i + 1] = temp;
  839. }
  840. return buffer.toString("utf16le", 2);
  841. }
  842. if (len >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
  843. return buffer.toString("utf16le", 2);
  844. }
  845. if (len >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
  846. return buffer.toString("utf8", 3);
  847. }
  848. return buffer.toString("utf8");
  849. }
  850. function writeFile(fileName, data, writeByteOrderMark) {
  851. if (writeByteOrderMark) {
  852. data = '\uFEFF' + data;
  853. }
  854. _fs.writeFileSync(fileName, data, "utf8");
  855. }
  856. function readDirectory(path, extension) {
  857. var result = [];
  858. visitDirectory(path);
  859. return result;
  860. function visitDirectory(path) {
  861. var files = _fs.readdirSync(path || ".").sort();
  862. var directories = [];
  863. for (var _i = 0; _i < files.length; _i++) {
  864. var current = files[_i];
  865. var name = ts.combinePaths(path, current);
  866. var stat = _fs.lstatSync(name);
  867. if (stat.isFile()) {
  868. if (!extension || ts.fileExtensionIs(name, extension)) {
  869. result.push(name);
  870. }
  871. }
  872. else if (stat.isDirectory()) {
  873. directories.push(name);
  874. }
  875. }
  876. for (var _a = 0; _a < directories.length; _a++) {
  877. var current = directories[_a];
  878. visitDirectory(current);
  879. }
  880. }
  881. }
  882. return {
  883. args: process.argv.slice(2),
  884. newLine: _os.EOL,
  885. useCaseSensitiveFileNames: useCaseSensitiveFileNames,
  886. write: function (s) {
  887. _fs.writeSync(1, s);
  888. },
  889. readFile: readFile,
  890. writeFile: writeFile,
  891. watchFile: function (fileName, callback) {
  892. _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
  893. return {
  894. close: function () { _fs.unwatchFile(fileName, fileChanged); }
  895. };
  896. function fileChanged(curr, prev) {
  897. if (+curr.mtime <= +prev.mtime) {
  898. return;
  899. }
  900. callback(fileName);
  901. }
  902. ;
  903. },
  904. resolvePath: function (path) {
  905. return _path.resolve(path);
  906. },
  907. fileExists: function (path) {
  908. return _fs.existsSync(path);
  909. },
  910. directoryExists: function (path) {
  911. return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
  912. },
  913. createDirectory: function (directoryName) {
  914. if (!this.directoryExists(directoryName)) {
  915. _fs.mkdirSync(directoryName);
  916. }
  917. },
  918. getExecutingFilePath: function () {
  919. return __filename;
  920. },
  921. getCurrentDirectory: function () {
  922. return process.cwd();
  923. },
  924. readDirectory: readDirectory,
  925. getMemoryUsage: function () {
  926. if (global.gc) {
  927. global.gc();
  928. }
  929. return process.memoryUsage().heapUsed;
  930. },
  931. exit: function (exitCode) {
  932. process.exit(exitCode);
  933. }
  934. };
  935. }
  936. if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
  937. return getWScriptSystem();
  938. }
  939. else if (typeof module !== "undefined" && module.exports) {
  940. return getNodeSystem();
  941. }
  942. else {
  943. return undefined;
  944. }
  945. })();
  946. })(ts || (ts = {}));
  947. /// <reference path="types.ts" />
  948. var ts;
  949. (function (ts) {
  950. ts.Diagnostics = {
  951. Unterminated_string_literal: { code: 1002, category: ts.DiagnosticCategory.Error, key: "Unterminated string literal." },
  952. Identifier_expected: { code: 1003, category: ts.DiagnosticCategory.Error, key: "Identifier expected." },
  953. _0_expected: { code: 1005, category: ts.DiagnosticCategory.Error, key: "'{0}' expected." },
  954. A_file_cannot_have_a_reference_to_itself: { code: 1006, category: ts.DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
  955. Trailing_comma_not_allowed: { code: 1009, category: ts.DiagnosticCategory.Error, key: "Trailing comma not allowed." },
  956. Asterisk_Slash_expected: { code: 1010, category: ts.DiagnosticCategory.Error, key: "'*/' expected." },
  957. Unexpected_token: { code: 1012, category: ts.DiagnosticCategory.Error, key: "Unexpected token." },
  958. 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." },
  959. Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: ts.DiagnosticCategory.Error, key: "Parameter cannot have question mark and initializer." },
  960. A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: ts.DiagnosticCategory.Error, key: "A required parameter cannot follow an optional parameter." },
  961. An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: ts.DiagnosticCategory.Error, key: "An index signature cannot have a rest parameter." },
  962. 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." },
  963. 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." },
  964. An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have an initializer." },
  965. An_index_signature_must_have_a_type_annotation: { code: 1021, category: ts.DiagnosticCategory.Error, key: "An index signature must have a type annotation." },
  966. 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." },
  967. 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'." },
  968. A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: ts.DiagnosticCategory.Error, key: "A class or interface declaration can only have one 'extends' clause." },
  969. An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: ts.DiagnosticCategory.Error, key: "An 'extends' clause must precede an 'implements' clause." },
  970. A_class_can_only_extend_a_single_class: { code: 1026, category: ts.DiagnosticCategory.Error, key: "A class can only extend a single class." },
  971. A_class_declaration_can_only_have_one_implements_clause: { code: 1027, category: ts.DiagnosticCategory.Error, key: "A class declaration can only have one 'implements' clause." },
  972. Accessibility_modifier_already_seen: { code: 1028, category: ts.DiagnosticCategory.Error, key: "Accessibility modifier already seen." },
  973. _0_modifier_must_precede_1_modifier: { code: 1029, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." },
  974. _0_modifier_already_seen: { code: 1030, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier already seen." },
  975. _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." },
  976. An_interface_declaration_cannot_have_an_implements_clause: { code: 1032, category: ts.DiagnosticCategory.Error, key: "An interface declaration cannot have an 'implements' clause." },
  977. 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." },
  978. Only_ambient_modules_can_use_quoted_names: { code: 1035, category: ts.DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." },
  979. Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: ts.DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." },
  980. 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." },
  981. Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: ts.DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." },
  982. _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." },
  983. A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: ts.DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used with an interface declaration." },
  984. 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." },
  985. A_rest_parameter_cannot_be_optional: { code: 1047, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot be optional." },
  986. A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." },
  987. A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor must have exactly one parameter." },
  988. A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have an optional parameter." },
  989. A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor parameter cannot have an initializer." },
  990. A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have rest parameter." },
  991. A_get_accessor_cannot_have_parameters: { code: 1054, category: ts.DiagnosticCategory.Error, key: "A 'get' accessor cannot have parameters." },
  992. 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." },
  993. Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." },
  994. 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." },
  995. 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." },
  996. 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." },
  997. A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used with an import declaration." },
  998. Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." },
  999. 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." },
  1000. 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." },
  1001. _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a constructor declaration." },
  1002. _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a parameter." },
  1003. 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." },
  1004. Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: ts.DiagnosticCategory.Error, key: "Type parameters cannot appear on a constructor declaration." },
  1005. Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: ts.DiagnosticCategory.Error, key: "Type annotation cannot appear on a constructor declaration." },
  1006. An_accessor_cannot_have_type_parameters: { code: 1094, category: ts.DiagnosticCategory.Error, key: "An accessor cannot have type parameters." },
  1007. 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." },
  1008. An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: ts.DiagnosticCategory.Error, key: "An index signature must have exactly one parameter." },
  1009. _0_list_cannot_be_empty: { code: 1097, category: ts.DiagnosticCategory.Error, key: "'{0}' list cannot be empty." },
  1010. Type_parameter_list_cannot_be_empty: { code: 1098, category: ts.DiagnosticCategory.Error, key: "Type parameter list cannot be empty." },
  1011. Type_argument_list_cannot_be_empty: { code: 1099, category: ts.DiagnosticCategory.Error, key: "Type argument list cannot be empty." },
  1012. Invalid_use_of_0_in_strict_mode: { code: 1100, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}' in strict mode." },
  1013. with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in strict mode." },
  1014. 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." },
  1015. 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." },
  1016. 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." },
  1017. Jump_target_cannot_cross_function_boundary: { code: 1107, category: ts.DiagnosticCategory.Error, key: "Jump target cannot cross function boundary." },
  1018. 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." },
  1019. Expression_expected: { code: 1109, category: ts.DiagnosticCategory.Error, key: "Expression expected." },
  1020. Type_expected: { code: 1110, category: ts.DiagnosticCategory.Error, key: "Type expected." },
  1021. A_class_member_cannot_be_declared_optional: { code: 1112, category: ts.DiagnosticCategory.Error, key: "A class member cannot be declared optional." },
  1022. 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." },
  1023. Duplicate_label_0: { code: 1114, category: ts.DiagnosticCategory.Error, key: "Duplicate label '{0}'" },
  1024. 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." },
  1025. 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." },
  1026. 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." },
  1027. 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." },
  1028. 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." },
  1029. An_export_assignment_cannot_have_modifiers: { code: 1120, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot have modifiers." },
  1030. Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: ts.DiagnosticCategory.Error, key: "Octal literals are not allowed in strict mode." },
  1031. A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: ts.DiagnosticCategory.Error, key: "A tuple type element list cannot be empty." },
  1032. Variable_declaration_list_cannot_be_empty: { code: 1123, category: ts.DiagnosticCategory.Error, key: "Variable declaration list cannot be empty." },
  1033. Digit_expected: { code: 1124, category: ts.DiagnosticCategory.Error, key: "Digit expected." },
  1034. Hexadecimal_digit_expected: { code: 1125, category: ts.DiagnosticCategory.Error, key: "Hexadecimal digit expected." },
  1035. Unexpected_end_of_text: { code: 1126, category: ts.DiagnosticCategory.Error, key: "Unexpected end of text." },
  1036. Invalid_character: { code: 1127, category: ts.DiagnosticCategory.Error, key: "Invalid character." },
  1037. Declaration_or_statement_expected: { code: 1128, category: ts.DiagnosticCategory.Error, key: "Declaration or statement expected." },
  1038. Statement_expected: { code: 1129, category: ts.DiagnosticCategory.Error, key: "Statement expected." },
  1039. case_or_default_expected: { code: 1130, category: ts.DiagnosticCategory.Error, key: "'case' or 'default' expected." },
  1040. Property_or_signature_expected: { code: 1131, category: ts.DiagnosticCategory.Error, key: "Property or signature expected." },
  1041. Enum_member_expected: { code: 1132, category: ts.DiagnosticCategory.Error, key: "Enum member expected." },
  1042. Type_reference_expected: { code: 1133, category: ts.DiagnosticCategory.Error, key: "Type reference expected." },
  1043. Variable_declaration_expected: { code: 1134, category: ts.DiagnosticCategory.Error, key: "Variable declaration expected." },
  1044. Argument_expression_expected: { code: 1135, category: ts.DiagnosticCategory.Error, key: "Argument expression expected." },
  1045. Property_assignment_expected: { code: 1136, category: ts.DiagnosticCategory.Error, key: "Property assignment expected." },
  1046. Expression_or_comma_expected: { code: 1137, category: ts.DiagnosticCategory.Error, key: "Expression or comma expected." },
  1047. Parameter_declaration_expected: { code: 1138, category: ts.DiagnosticCategory.Error, key: "Parameter declaration expected." },
  1048. Type_parameter_declaration_expected: { code: 1139, category: ts.DiagnosticCategory.Error, key: "Type parameter declaration expected." },
  1049. Type_argument_expected: { code: 1140, category: ts.DiagnosticCategory.Error, key: "Type argument expected." },
  1050. String_literal_expected: { code: 1141, category: ts.DiagnosticCategory.Error, key: "String literal expected." },
  1051. Line_break_not_permitted_here: { code: 1142, category: ts.DiagnosticCategory.Error, key: "Line break not permitted here." },
  1052. or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "'{' or ';' expected." },
  1053. Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: ts.DiagnosticCategory.Error, key: "Modifiers not permitted on index signature members." },
  1054. Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration expected." },
  1055. 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." },
  1056. 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." },
  1057. 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" },
  1058. 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." },
  1059. var_let_or_const_expected: { code: 1152, category: ts.DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." },
  1060. let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: ts.DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." },
  1061. const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: ts.DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." },
  1062. const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
  1063. 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." },
  1064. 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." },
  1065. Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." },
  1066. Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
  1067. An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
  1068. yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: ts.DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." },
  1069. Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." },
  1070. 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." },
  1071. 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." },
  1072. Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: ts.DiagnosticCategory.Error, key: "Computed property names are only available when targeting ECMAScript 6 and higher." },
  1073. 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." },
  1074. 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." },
  1075. 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." },
  1076. 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." },
  1077. extends_clause_already_seen: { code: 1172, category: ts.DiagnosticCategory.Error, key: "'extends' clause already seen." },
  1078. extends_clause_must_precede_implements_clause: { code: 1173, category: ts.DiagnosticCategory.Error, key: "'extends' clause must precede 'implements' clause." },
  1079. Classes_can_only_extend_a_single_class: { code: 1174, category: ts.DiagnosticCategory.Error, key: "Classes can only extend a single class." },
  1080. implements_clause_already_seen: { code: 1175, category: ts.DiagnosticCategory.Error, key: "'implements' clause already seen." },
  1081. Interface_declaration_cannot_have_implements_clause: { code: 1176, category: ts.DiagnosticCategory.Error, key: "Interface declaration cannot have 'implements' clause." },
  1082. Binary_digit_expected: { code: 1177, category: ts.DiagnosticCategory.Error, key: "Binary digit expected." },
  1083. Octal_digit_expected: { code: 1178, category: ts.DiagnosticCategory.Error, key: "Octal digit expected." },
  1084. Unexpected_token_expected: { code: 1179, category: ts.DiagnosticCategory.Error, key: "Unexpected token. '{' expected." },
  1085. Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." },
  1086. Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." },
  1087. A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." },
  1088. Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: ts.DiagnosticCategory.Error, key: "Destructuring declarations are not allowed in ambient contexts." },
  1089. An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." },
  1090. Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
  1091. Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
  1092. A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." },
  1093. 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." },
  1094. 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." },
  1095. 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." },
  1096. 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." },
  1097. An_import_declaration_cannot_have_modifiers: { code: 1191, category: ts.DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." },
  1098. Module_0_has_no_default_export: { code: 1192, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no default export." },
  1099. An_export_declaration_cannot_have_modifiers: { code: 1193, category: ts.DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." },
  1100. Export_declarations_are_not_permitted_in_a_namespace: { code: 1194, category: ts.DiagnosticCategory.Error, key: "Export declarations are not permitted in a namespace." },
  1101. Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: ts.DiagnosticCategory.Error, key: "Catch clause variable name must be an identifier." },
  1102. Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have a type annotation." },
  1103. Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." },
  1104. 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." },
  1105. Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
  1106. Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
  1107. 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." },
  1108. 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." },
  1109. 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." },
  1110. 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." },
  1111. Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." },
  1112. 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." },
  1113. 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." },
  1114. 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." },
  1115. 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." },
  1116. 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" },
  1117. 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" },
  1118. 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." },
  1119. Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
  1120. Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
  1121. 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'." },
  1122. 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." },
  1123. Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
  1124. 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." },
  1125. Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
  1126. Circular_definition_of_import_alias_0: { code: 2303, category: ts.DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." },
  1127. Cannot_find_name_0: { code: 2304, category: ts.DiagnosticCategory.Error, key: "Cannot find name '{0}'." },
  1128. Module_0_has_no_exported_member_1: { code: 2305, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
  1129. File_0_is_not_a_module: { code: 2306, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not a module." },
  1130. Cannot_find_module_0: { code: 2307, category: ts.DiagnosticCategory.Error, key: "Cannot find module '{0}'." },
  1131. A_module_cannot_have_more_than_one_export_assignment: { code: 2308, category: ts.DiagnosticCategory.Error, key: "A module cannot have more than one export assignment." },
  1132. 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." },
  1133. 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." },
  1134. A_class_may_only_extend_another_class: { code: 2311, category: ts.DiagnosticCategory.Error, key: "A class may only extend another class." },
  1135. 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." },
  1136. 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." },
  1137. Generic_type_0_requires_1_type_argument_s: { code: 2314, category: ts.DiagnosticCategory.Error, key: "Generic type '{0}' requires {1} type argument(s)." },
  1138. Type_0_is_not_generic: { code: 2315, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not generic." },
  1139. 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." },
  1140. 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)." },
  1141. Cannot_find_global_type_0: { code: 2318, category: ts.DiagnosticCategory.Error, key: "Cannot find global type '{0}'." },
  1142. 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." },
  1143. 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}'." },
  1144. Excessive_stack_depth_comparing_types_0_and_1: { code: 2321, category: ts.DiagnosticCategory.Error, key: "Excessive stack depth comparing types '{0}' and '{1}'." },
  1145. Type_0_is_not_assignable_to_type_1: { code: 2322, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}'." },
  1146. Property_0_is_missing_in_type_1: { code: 2324, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is missing in type '{1}'." },
  1147. 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}'." },
  1148. Types_of_property_0_are_incompatible: { code: 2326, category: ts.DiagnosticCategory.Error, key: "Types of property '{0}' are incompatible." },
  1149. 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}'." },
  1150. Types_of_parameters_0_and_1_are_incompatible: { code: 2328, category: ts.DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible." },
  1151. Index_signature_is_missing_in_type_0: { code: 2329, category: ts.DiagnosticCategory.Error, key: "Index signature is missing in type '{0}'." },
  1152. Index_signatures_are_incompatible: { code: 2330, category: ts.DiagnosticCategory.Error, key: "Index signatures are incompatible." },
  1153. 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." },
  1154. this_cannot_be_referenced_in_current_location: { code: 2332, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in current location." },
  1155. this_cannot_be_referenced_in_constructor_arguments: { code: 2333, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in constructor arguments." },
  1156. 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." },
  1157. 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." },
  1158. super_cannot_be_referenced_in_constructor_arguments: { code: 2336, category: ts.DiagnosticCategory.Error, key: "'super' cannot be referenced in constructor arguments." },
  1159. 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" },
  1160. 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" },
  1161. Property_0_does_not_exist_on_type_1: { code: 2339, category: ts.DiagnosticCategory.Error, key: "Property '{0}' does not exist on type '{1}'." },
  1162. 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" },
  1163. 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}'." },
  1164. 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'." },
  1165. Type_0_does_not_satisfy_the_constraint_1: { code: 2344, category: ts.DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}'." },
  1166. 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}'." },
  1167. 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." },
  1168. Untyped_function_calls_may_not_accept_type_arguments: { code: 2347, category: ts.DiagnosticCategory.Error, key: "Untyped function calls may not accept type arguments." },
  1169. 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'?" },
  1170. 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." },
  1171. 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." },
  1172. 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." },
  1173. 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." },
  1174. No_best_common_type_exists_among_return_expressions: { code: 2354, category: ts.DiagnosticCategory.Error, key: "No best common type exists among return expressions." },
  1175. 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." },
  1176. 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." },
  1177. 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." },
  1178. 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." },
  1179. 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." },
  1180. 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'." },
  1181. 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" },
  1182. 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." },
  1183. 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." },
  1184. Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
  1185. 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}'." },
  1186. Type_parameter_name_cannot_be_0: { code: 2368, category: ts.DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" },
  1187. 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." },
  1188. 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." },
  1189. 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." },
  1190. Parameter_0_cannot_be_referenced_in_its_initializer: { code: 2372, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' cannot be referenced in its initializer." },
  1191. 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." },
  1192. Duplicate_string_index_signature: { code: 2374, category: ts.DiagnosticCategory.Error, key: "Duplicate string index signature." },
  1193. Duplicate_number_index_signature: { code: 2375, category: ts.DiagnosticCategory.Error, key: "Duplicate number index signature." },
  1194. 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." },
  1195. 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." },
  1196. 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." },
  1197. 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." },
  1198. 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." },
  1199. 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." },
  1200. 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." },
  1201. 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." },
  1202. 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." },
  1203. 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." },
  1204. Overload_signatures_must_all_be_optional_or_required: { code: 2386, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be optional or required." },
  1205. Function_overload_must_be_static: { code: 2387, category: ts.DiagnosticCategory.Error, key: "Function overload must be static." },
  1206. Function_overload_must_not_be_static: { code: 2388, category: ts.DiagnosticCategory.Error, key: "Function overload must not be static." },
  1207. Function_implementation_name_must_be_0: { code: 2389, category: ts.DiagnosticCategory.Error, key: "Function implementation name must be '{0}'." },
  1208. Constructor_implementation_is_missing: { code: 2390, category: ts.DiagnosticCategory.Error, key: "Constructor implementation is missing." },
  1209. 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." },
  1210. Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: ts.DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },
  1211. Duplicate_function_implementation: { code: 2393, category: ts.DiagnosticCategory.Error, key: "Duplicate function implementation." },
  1212. Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: ts.DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
  1213. 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." },
  1214. 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." },
  1215. 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." },
  1216. 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." },
  1217. 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." },
  1218. 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." },
  1219. 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}'." },
  1220. 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." },
  1221. 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'." },
  1222. Invalid_left_hand_side_in_for_in_statement: { code: 2406, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...in' statement." },
  1223. 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." },
  1224. Setters_cannot_return_a_value: { code: 2408, category: ts.DiagnosticCategory.Error, key: "Setters cannot return a value." },
  1225. 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" },
  1226. 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'." },
  1227. 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}'." },
  1228. 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}'." },
  1229. 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}'." },
  1230. Class_name_cannot_be_0: { code: 2414, category: ts.DiagnosticCategory.Error, key: "Class name cannot be '{0}'" },
  1231. Class_0_incorrectly_extends_base_class_1: { code: 2415, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly extends base class '{1}'." },
  1232. 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}'." },
  1233. 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}'." },
  1234. Class_0_incorrectly_implements_interface_1: { code: 2420, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly implements interface '{1}'." },
  1235. 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." },
  1236. 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." },
  1237. 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." },
  1238. 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." },
  1239. 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." },
  1240. Interface_name_cannot_be_0: { code: 2427, category: ts.DiagnosticCategory.Error, key: "Interface name cannot be '{0}'" },
  1241. 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." },
  1242. Interface_0_incorrectly_extends_interface_1: { code: 2430, category: ts.DiagnosticCategory.Error, key: "Interface '{0}' incorrectly extends interface '{1}'." },
  1243. Enum_name_cannot_be_0: { code: 2431, category: ts.DiagnosticCategory.Error, key: "Enum name cannot be '{0}'" },
  1244. 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." },
  1245. 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" },
  1246. 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" },
  1247. Ambient_modules_cannot_be_nested_in_other_modules: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules." },
  1248. Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." },
  1249. 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" },
  1250. Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" },
  1251. 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." },
  1252. Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: ts.DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
  1253. 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." },
  1254. 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}'." },
  1255. 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}'." },
  1256. 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}'." },
  1257. 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." },
  1258. 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}'." },
  1259. 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." },
  1260. Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: ts.DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." },
  1261. 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." },
  1262. 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." },
  1263. Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'." },
  1264. An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: ts.DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
  1265. 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." },
  1266. 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}'." },
  1267. Type_alias_0_circularly_references_itself: { code: 2456, category: ts.DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
  1268. Type_alias_name_cannot_be_0: { code: 2457, category: ts.DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
  1269. An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: ts.DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
  1270. 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." },
  1271. Type_0_has_no_property_1: { code: 2460, category: ts.DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
  1272. Type_0_is_not_an_array_type: { code: 2461, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
  1273. 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" },
  1274. 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." },
  1275. 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'." },
  1276. 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." },
  1277. 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." },
  1278. 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." },
  1279. Cannot_find_global_value_0: { code: 2468, category: ts.DiagnosticCategory.Error, key: "Cannot find global value '{0}'." },
  1280. 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'." },
  1281. 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." },
  1282. 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'." },
  1283. Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." },
  1284. 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." },
  1285. 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." },
  1286. 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." },
  1287. 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." },
  1288. 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." },
  1289. 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'." },
  1290. 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}'." },
  1291. 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." },
  1292. 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}'." },
  1293. 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." },
  1294. Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: ts.DiagnosticCategory.Error, key: "Export declaration conflicts with exported declaration of '{0}'" },
  1295. 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." },
  1296. 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." },
  1297. Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...of' statement." },
  1298. 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." },
  1299. An_iterator_must_have_a_next_method: { code: 2489, category: ts.DiagnosticCategory.Error, key: "An iterator must have a 'next()' method." },
  1300. 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." },
  1301. 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." },
  1302. Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" },
  1303. 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}'." },
  1304. 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." },
  1305. 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." },
  1306. 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." },
  1307. 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." },
  1308. 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 *'." },
  1309. 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." },
  1310. 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." },
  1311. A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
  1312. _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." },
  1313. Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
  1314. Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
  1315. 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}'." },
  1316. 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}'." },
  1317. 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}'." },
  1318. 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}'." },
  1319. 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}'." },
  1320. 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}'." },
  1321. 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}'." },
  1322. 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}'." },
  1323. 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}'." },
  1324. 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}'." },
  1325. 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}'." },
  1326. 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." },
  1327. 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}'." },
  1328. 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}'." },
  1329. 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." },
  1330. 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}'." },
  1331. 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}'." },
  1332. 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." },
  1333. 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}'." },
  1334. 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}'." },
  1335. 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}'." },
  1336. 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}'." },
  1337. 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}'." },
  1338. 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}'." },
  1339. 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}'." },
  1340. 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}'." },
  1341. 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." },
  1342. 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}'." },
  1343. 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}'." },
  1344. 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." },
  1345. 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}'." },
  1346. 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}'." },
  1347. 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}'." },
  1348. 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}'." },
  1349. 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}'." },
  1350. 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}'." },
  1351. 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}'." },
  1352. 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}'." },
  1353. 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." },
  1354. 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}'." },
  1355. 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}'." },
  1356. 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." },
  1357. 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}'." },
  1358. 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}'." },
  1359. 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}'." },
  1360. 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}'." },
  1361. 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." },
  1362. 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}'." },
  1363. 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}'." },
  1364. 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." },
  1365. 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}'." },
  1366. 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}'." },
  1367. 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}'." },
  1368. 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}'." },
  1369. 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}'." },
  1370. 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}'." },
  1371. 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." },
  1372. 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}'." },
  1373. 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}'." },
  1374. 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." },
  1375. 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}'." },
  1376. 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}'." },
  1377. 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}'." },
  1378. 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}'." },
  1379. 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." },
  1380. 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}'." },
  1381. 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}'." },
  1382. 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}'." },
  1383. 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}'." },
  1384. 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." },
  1385. 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." },
  1386. 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." },
  1387. Cannot_read_file_0_Colon_1: { code: 5012, category: ts.DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
  1388. Unsupported_file_encoding: { code: 5013, category: ts.DiagnosticCategory.Error, key: "Unsupported file encoding." },
  1389. Failed_to_parse_file_0_Colon_1: { code: 5014, category: ts.DiagnosticCategory.Error, key: "Failed to parse file '{0}': {1}." },
  1390. Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
  1391. 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}." },
  1392. Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
  1393. Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." },
  1394. Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." },
  1395. Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
  1396. Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." },
  1397. 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." },
  1398. Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." },
  1399. Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." },
  1400. Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." },
  1401. Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." },
  1402. 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." },
  1403. Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." },
  1404. Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." },
  1405. Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." },
  1406. 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." },
  1407. Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
  1408. Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
  1409. 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." },
  1410. 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." },
  1411. Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
  1412. Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
  1413. 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." },
  1414. Do_not_emit_outputs_if_any_type_checking_errors_were_reported: { code: 6008, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." },
  1415. Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
  1416. Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
  1417. 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)" },
  1418. 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'" },
  1419. Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." },
  1420. Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." },
  1421. Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." },
  1422. Syntax_Colon_0: { code: 6023, category: ts.DiagnosticCategory.Message, key: "Syntax: {0}" },
  1423. options: { code: 6024, category: ts.DiagnosticCategory.Message, key: "options" },
  1424. file: { code: 6025, category: ts.DiagnosticCategory.Message, key: "file" },
  1425. Examples_Colon_0: { code: 6026, category: ts.DiagnosticCategory.Message, key: "Examples: {0}" },
  1426. Options_Colon: { code: 6027, category: ts.DiagnosticCategory.Message, key: "Options:" },
  1427. Version_0: { code: 6029, category: ts.DiagnosticCategory.Message, key: "Version {0}" },
  1428. 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." },
  1429. File_change_detected_Starting_incremental_compilation: { code: 6032, category: ts.DiagnosticCategory.Message, key: "File change detected. Starting incremental compilation..." },
  1430. KIND: { code: 6034, category: ts.DiagnosticCategory.Message, key: "KIND" },
  1431. FILE: { code: 6035, category: ts.DiagnosticCategory.Message, key: "FILE" },
  1432. VERSION: { code: 6036, category: ts.DiagnosticCategory.Message, key: "VERSION" },
  1433. LOCATION: { code: 6037, category: ts.DiagnosticCategory.Message, key: "LOCATION" },
  1434. DIRECTORY: { code: 6038, category: ts.DiagnosticCategory.Message, key: "DIRECTORY" },
  1435. Compilation_complete_Watching_for_file_changes: { code: 6042, category: ts.DiagnosticCategory.Message, key: "Compilation complete. Watching for file changes." },
  1436. Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
  1437. Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
  1438. Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
  1439. 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'." },
  1440. 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'." },
  1441. 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}'." },
  1442. Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
  1443. Unable_to_open_file_0: { code: 6050, category: ts.DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
  1444. Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
  1445. 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." },
  1446. File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
  1447. File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." },
  1448. 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." },
  1449. 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." },
  1450. Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
  1451. 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." },
  1452. 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." },
  1453. 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)." },
  1454. NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" },
  1455. 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'." },
  1456. Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: ts.DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." },
  1457. Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
  1458. 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." },
  1459. Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
  1460. Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
  1461. Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
  1462. 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." },
  1463. _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." },
  1464. 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." },
  1465. 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." },
  1466. 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." },
  1467. 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." },
  1468. 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." },
  1469. Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
  1470. 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." },
  1471. _0_implicitly_has_type_any_because_it_is_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 is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
  1472. _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." },
  1473. 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." },
  1474. You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." },
  1475. 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." },
  1476. 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." },
  1477. 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." },
  1478. 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." },
  1479. 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." },
  1480. 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." },
  1481. 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." },
  1482. 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." },
  1483. _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." },
  1484. 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." },
  1485. 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." },
  1486. 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." },
  1487. can_only_be_used_in_a_ts_file: { code: 8013, category: ts.DiagnosticCategory.Error, key: "'?' can only be used in a .ts file." },
  1488. 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." },
  1489. 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." },
  1490. 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." },
  1491. 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." },
  1492. yield_expressions_are_not_currently_supported: { code: 9000, category: ts.DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." },
  1493. Generators_are_not_currently_supported: { code: 9001, category: ts.DiagnosticCategory.Error, key: "Generators are not currently supported." },
  1494. 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." },
  1495. class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
  1496. class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: ts.DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." }
  1497. };
  1498. })(ts || (ts = {}));
  1499. /// <reference path="core.ts"/>
  1500. /// <reference path="diagnosticInformationMap.generated.ts"/>
  1501. var ts;
  1502. (function (ts) {
  1503. var textToToken = {
  1504. "any": 112,
  1505. "as": 111,
  1506. "boolean": 113,
  1507. "break": 66,
  1508. "case": 67,
  1509. "catch": 68,
  1510. "class": 69,
  1511. "continue": 71,
  1512. "const": 70,
  1513. "constructor": 114,
  1514. "debugger": 72,
  1515. "declare": 115,
  1516. "default": 73,
  1517. "delete": 74,
  1518. "do": 75,
  1519. "else": 76,
  1520. "enum": 77,
  1521. "export": 78,
  1522. "extends": 79,
  1523. "false": 80,
  1524. "finally": 81,
  1525. "for": 82,
  1526. "from": 125,
  1527. "function": 83,
  1528. "get": 116,
  1529. "if": 84,
  1530. "implements": 102,
  1531. "import": 85,
  1532. "in": 86,
  1533. "instanceof": 87,
  1534. "interface": 103,
  1535. "let": 104,
  1536. "module": 117,
  1537. "namespace": 118,
  1538. "new": 88,
  1539. "null": 89,
  1540. "number": 120,
  1541. "package": 105,
  1542. "private": 106,
  1543. "protected": 107,
  1544. "public": 108,
  1545. "require": 119,
  1546. "return": 90,
  1547. "set": 121,
  1548. "static": 109,
  1549. "string": 122,
  1550. "super": 91,
  1551. "switch": 92,
  1552. "symbol": 123,
  1553. "this": 93,
  1554. "throw": 94,
  1555. "true": 95,
  1556. "try": 96,
  1557. "type": 124,
  1558. "typeof": 97,
  1559. "var": 98,
  1560. "void": 99,
  1561. "while": 100,
  1562. "with": 101,
  1563. "yield": 110,
  1564. "of": 126,
  1565. "{": 14,
  1566. "}": 15,
  1567. "(": 16,
  1568. ")": 17,
  1569. "[": 18,
  1570. "]": 19,
  1571. ".": 20,
  1572. "...": 21,
  1573. ";": 22,
  1574. ",": 23,
  1575. "<": 24,
  1576. ">": 25,
  1577. "<=": 26,
  1578. ">=": 27,
  1579. "==": 28,
  1580. "!=": 29,
  1581. "===": 30,
  1582. "!==": 31,
  1583. "=>": 32,
  1584. "+": 33,
  1585. "-": 34,
  1586. "*": 35,
  1587. "/": 36,
  1588. "%": 37,
  1589. "++": 38,
  1590. "--": 39,
  1591. "<<": 40,
  1592. ">>": 41,
  1593. ">>>": 42,
  1594. "&": 43,
  1595. "|": 44,
  1596. "^": 45,
  1597. "!": 46,
  1598. "~": 47,
  1599. "&&": 48,
  1600. "||": 49,
  1601. "?": 50,
  1602. ":": 51,
  1603. "=": 53,
  1604. "+=": 54,
  1605. "-=": 55,
  1606. "*=": 56,
  1607. "/=": 57,
  1608. "%=": 58,
  1609. "<<=": 59,
  1610. ">>=": 60,
  1611. ">>>=": 61,
  1612. "&=": 62,
  1613. "|=": 63,
  1614. "^=": 64,
  1615. "@": 52
  1616. };
  1617. 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,];
  1618. 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,];
  1619. 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,];
  1620. 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,];
  1621. function lookupInUnicodeMap(code, map) {
  1622. if (code < map[0]) {
  1623. return false;
  1624. }
  1625. var lo = 0;
  1626. var hi = map.length;
  1627. var mid;
  1628. while (lo + 1 < hi) {
  1629. mid = lo + (hi - lo) / 2;
  1630. mid -= mid % 2;
  1631. if (map[mid] <= code && code <= map[mid + 1]) {
  1632. return true;
  1633. }
  1634. if (code < map[mid]) {
  1635. hi = mid;
  1636. }
  1637. else {
  1638. lo = mid + 2;
  1639. }
  1640. }
  1641. return false;
  1642. }
  1643. function isUnicodeIdentifierStart(code, languageVersion) {
  1644. return languageVersion >= 1 ?
  1645. lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
  1646. lookupInUnicodeMap(code, unicodeES3IdentifierStart);
  1647. }
  1648. ts.isUnicodeIdentifierStart = isUnicodeIdentifierStart;
  1649. function isUnicodeIdentifierPart(code, languageVersion) {
  1650. return languageVersion >= 1 ?
  1651. lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
  1652. lookupInUnicodeMap(code, unicodeES3IdentifierPart);
  1653. }
  1654. function makeReverseMap(source) {
  1655. var result = [];
  1656. for (var name_2 in source) {
  1657. if (source.hasOwnProperty(name_2)) {
  1658. result[source[name_2]] = name_2;
  1659. }
  1660. }
  1661. return result;
  1662. }
  1663. var tokenStrings = makeReverseMap(textToToken);
  1664. function tokenToString(t) {
  1665. return tokenStrings[t];
  1666. }
  1667. ts.tokenToString = tokenToString;
  1668. function stringToToken(s) {
  1669. return textToToken[s];
  1670. }
  1671. ts.stringToToken = stringToToken;
  1672. function computeLineStarts(text) {
  1673. var result = new Array();
  1674. var pos = 0;
  1675. var lineStart = 0;
  1676. while (pos < text.length) {
  1677. var ch = text.charCodeAt(pos++);
  1678. switch (ch) {
  1679. case 13:
  1680. if (text.charCodeAt(pos) === 10) {
  1681. pos++;
  1682. }
  1683. case 10:
  1684. result.push(lineStart);
  1685. lineStart = pos;
  1686. break;
  1687. default:
  1688. if (ch > 127 && isLineBreak(ch)) {
  1689. result.push(lineStart);
  1690. lineStart = pos;
  1691. }
  1692. break;
  1693. }
  1694. }
  1695. result.push(lineStart);
  1696. return result;
  1697. }
  1698. ts.computeLineStarts = computeLineStarts;
  1699. function getPositionOfLineAndCharacter(sourceFile, line, character) {
  1700. return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character);
  1701. }
  1702. ts.getPositionOfLineAndCharacter = getPositionOfLineAndCharacter;
  1703. function computePositionOfLineAndCharacter(lineStarts, line, character) {
  1704. ts.Debug.assert(line >= 0 && line < lineStarts.length);
  1705. return lineStarts[line] + character;
  1706. }
  1707. ts.computePositionOfLineAndCharacter = computePositionOfLineAndCharacter;
  1708. function getLineStarts(sourceFile) {
  1709. return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
  1710. }
  1711. ts.getLineStarts = getLineStarts;
  1712. function computeLineAndCharacterOfPosition(lineStarts, position) {
  1713. var lineNumber = ts.binarySearch(lineStarts, position);
  1714. if (lineNumber < 0) {
  1715. lineNumber = ~lineNumber - 1;
  1716. }
  1717. return {
  1718. line: lineNumber,
  1719. character: position - lineStarts[lineNumber]
  1720. };
  1721. }
  1722. ts.computeLineAndCharacterOfPosition = computeLineAndCharacterOfPosition;
  1723. function getLineAndCharacterOfPosition(sourceFile, position) {
  1724. return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
  1725. }
  1726. ts.getLineAndCharacterOfPosition = getLineAndCharacterOfPosition;
  1727. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1728. function isWhiteSpace(ch) {
  1729. return ch === 32 ||
  1730. ch === 9 ||
  1731. ch === 11 ||
  1732. ch === 12 ||
  1733. ch === 160 ||
  1734. ch === 133 ||
  1735. ch === 5760 ||
  1736. ch >= 8192 && ch <= 8203 ||
  1737. ch === 8239 ||
  1738. ch === 8287 ||
  1739. ch === 12288 ||
  1740. ch === 65279;
  1741. }
  1742. ts.isWhiteSpace = isWhiteSpace;
  1743. function isLineBreak(ch) {
  1744. // ES5 7.3:
  1745. // The ECMAScript line terminator characters are listed in Table 3.
  1746. // Table 3: Line Terminator Characters
  1747. // Code Unit Value Name Formal Name
  1748. // \u000A Line Feed <LF>
  1749. // \u000D Carriage Return <CR>
  1750. // \u2028 Line separator <LS>
  1751. // \u2029 Paragraph separator <PS>
  1752. // Only the characters in Table 3 are treated as line terminators. Other new line or line
  1753. // breaking characters are treated as white space but not as line terminators.
  1754. return ch === 10 ||
  1755. ch === 13 ||
  1756. ch === 8232 ||
  1757. ch === 8233;
  1758. }
  1759. ts.isLineBreak = isLineBreak;
  1760. function isDigit(ch) {
  1761. return ch >= 48 && ch <= 57;
  1762. }
  1763. function isOctalDigit(ch) {
  1764. return ch >= 48 && ch <= 55;
  1765. }
  1766. ts.isOctalDigit = isOctalDigit;
  1767. function skipTrivia(text, pos, stopAfterLineBreak) {
  1768. while (true) {
  1769. var ch = text.charCodeAt(pos);
  1770. switch (ch) {
  1771. case 13:
  1772. if (text.charCodeAt(pos + 1) === 10) {
  1773. pos++;
  1774. }
  1775. case 10:
  1776. pos++;
  1777. if (stopAfterLineBreak) {
  1778. return pos;
  1779. }
  1780. continue;
  1781. case 9:
  1782. case 11:
  1783. case 12:
  1784. case 32:
  1785. pos++;
  1786. continue;
  1787. case 47:
  1788. if (text.charCodeAt(pos + 1) === 47) {
  1789. pos += 2;
  1790. while (pos < text.length) {
  1791. if (isLineBreak(text.charCodeAt(pos))) {
  1792. break;
  1793. }
  1794. pos++;
  1795. }
  1796. continue;
  1797. }
  1798. if (text.charCodeAt(pos + 1) === 42) {
  1799. pos += 2;
  1800. while (pos < text.length) {
  1801. if (text.charCodeAt(pos) === 42 && text.charCodeAt(pos + 1) === 47) {
  1802. pos += 2;
  1803. break;
  1804. }
  1805. pos++;
  1806. }
  1807. continue;
  1808. }
  1809. break;
  1810. case 60:
  1811. case 61:
  1812. case 62:
  1813. if (isConflictMarkerTrivia(text, pos)) {
  1814. pos = scanConflictMarkerTrivia(text, pos);
  1815. continue;
  1816. }
  1817. break;
  1818. default:
  1819. if (ch > 127 && (isWhiteSpace(ch) || isLineBreak(ch))) {
  1820. pos++;
  1821. continue;
  1822. }
  1823. break;
  1824. }
  1825. return pos;
  1826. }
  1827. }
  1828. ts.skipTrivia = skipTrivia;
  1829. var mergeConflictMarkerLength = "<<<<<<<".length;
  1830. function isConflictMarkerTrivia(text, pos) {
  1831. ts.Debug.assert(pos >= 0);
  1832. if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) {
  1833. var ch = text.charCodeAt(pos);
  1834. if ((pos + mergeConflictMarkerLength) < text.length) {
  1835. for (var i = 0, n = mergeConflictMarkerLength; i < n; i++) {
  1836. if (text.charCodeAt(pos + i) !== ch) {
  1837. return false;
  1838. }
  1839. }
  1840. return ch === 61 ||
  1841. text.charCodeAt(pos + mergeConflictMarkerLength) === 32;
  1842. }
  1843. }
  1844. return false;
  1845. }
  1846. function scanConflictMarkerTrivia(text, pos, error) {
  1847. if (error) {
  1848. error(ts.Diagnostics.Merge_conflict_marker_encountered, mergeConflictMarkerLength);
  1849. }
  1850. var ch = text.charCodeAt(pos);
  1851. var len = text.length;
  1852. if (ch === 60 || ch === 62) {
  1853. while (pos < len && !isLineBreak(text.charCodeAt(pos))) {
  1854. pos++;
  1855. }
  1856. }
  1857. else {
  1858. ts.Debug.assert(ch === 61);
  1859. while (pos < len) {
  1860. var ch_1 = text.charCodeAt(pos);
  1861. if (ch_1 === 62 && isConflictMarkerTrivia(text, pos)) {
  1862. break;
  1863. }
  1864. pos++;
  1865. }
  1866. }
  1867. return pos;
  1868. }
  1869. function getCommentRanges(text, pos, trailing) {
  1870. var result;
  1871. var collecting = trailing || pos === 0;
  1872. while (true) {
  1873. var ch = text.charCodeAt(pos);
  1874. switch (ch) {
  1875. case 13:
  1876. if (text.charCodeAt(pos + 1) === 10) {
  1877. pos++;
  1878. }
  1879. case 10:
  1880. pos++;
  1881. if (trailing) {
  1882. return result;
  1883. }
  1884. collecting = true;
  1885. if (result && result.length) {
  1886. ts.lastOrUndefined(result).hasTrailingNewLine = true;
  1887. }
  1888. continue;
  1889. case 9:
  1890. case 11:
  1891. case 12:
  1892. case 32:
  1893. pos++;
  1894. continue;
  1895. case 47:
  1896. var nextChar = text.charCodeAt(pos + 1);
  1897. var hasTrailingNewLine = false;
  1898. if (nextChar === 47 || nextChar === 42) {
  1899. var kind = nextChar === 47 ? 2 : 3;
  1900. var startPos = pos;
  1901. pos += 2;
  1902. if (nextChar === 47) {
  1903. while (pos < text.length) {
  1904. if (isLineBreak(text.charCodeAt(pos))) {
  1905. hasTrailingNewLine = true;
  1906. break;
  1907. }
  1908. pos++;
  1909. }
  1910. }
  1911. else {
  1912. while (pos < text.length) {
  1913. if (text.charCodeAt(pos) === 42 && text.charCodeAt(pos + 1) === 47) {
  1914. pos += 2;
  1915. break;
  1916. }
  1917. pos++;
  1918. }
  1919. }
  1920. if (collecting) {
  1921. if (!result) {
  1922. result = [];
  1923. }
  1924. result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine, kind: kind });
  1925. }
  1926. continue;
  1927. }
  1928. break;
  1929. default:
  1930. if (ch > 127 && (isWhiteSpace(ch) || isLineBreak(ch))) {
  1931. if (result && result.length && isLineBreak(ch)) {
  1932. ts.lastOrUndefined(result).hasTrailingNewLine = true;
  1933. }
  1934. pos++;
  1935. continue;
  1936. }
  1937. break;
  1938. }
  1939. return result;
  1940. }
  1941. }
  1942. function getLeadingCommentRanges(text, pos) {
  1943. return getCommentRanges(text, pos, false);
  1944. }
  1945. ts.getLeadingCommentRanges = getLeadingCommentRanges;
  1946. function getTrailingCommentRanges(text, pos) {
  1947. return getCommentRanges(text, pos, true);
  1948. }
  1949. ts.getTrailingCommentRanges = getTrailingCommentRanges;
  1950. function isIdentifierStart(ch, languageVersion) {
  1951. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  1952. ch === 36 || ch === 95 ||
  1953. ch > 127 && isUnicodeIdentifierStart(ch, languageVersion);
  1954. }
  1955. ts.isIdentifierStart = isIdentifierStart;
  1956. function isIdentifierPart(ch, languageVersion) {
  1957. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  1958. ch >= 48 && ch <= 57 || ch === 36 || ch === 95 ||
  1959. ch > 127 && isUnicodeIdentifierPart(ch, languageVersion);
  1960. }
  1961. ts.isIdentifierPart = isIdentifierPart;
  1962. function createScanner(languageVersion, skipTrivia, text, onError, start, length) {
  1963. var pos;
  1964. var end;
  1965. var startPos;
  1966. var tokenPos;
  1967. var token;
  1968. var tokenValue;
  1969. var precedingLineBreak;
  1970. var hasExtendedUnicodeEscape;
  1971. var tokenIsUnterminated;
  1972. setText(text, start, length);
  1973. return {
  1974. getStartPos: function () { return startPos; },
  1975. getTextPos: function () { return pos; },
  1976. getToken: function () { return token; },
  1977. getTokenPos: function () { return tokenPos; },
  1978. getTokenText: function () { return text.substring(tokenPos, pos); },
  1979. getTokenValue: function () { return tokenValue; },
  1980. hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; },
  1981. hasPrecedingLineBreak: function () { return precedingLineBreak; },
  1982. isIdentifier: function () { return token === 65 || token > 101; },
  1983. isReservedWord: function () { return token >= 66 && token <= 101; },
  1984. isUnterminated: function () { return tokenIsUnterminated; },
  1985. reScanGreaterToken: reScanGreaterToken,
  1986. reScanSlashToken: reScanSlashToken,
  1987. reScanTemplateToken: reScanTemplateToken,
  1988. scan: scan,
  1989. setText: setText,
  1990. setScriptTarget: setScriptTarget,
  1991. setOnError: setOnError,
  1992. setTextPos: setTextPos,
  1993. tryScan: tryScan,
  1994. lookAhead: lookAhead
  1995. };
  1996. function error(message, length) {
  1997. if (onError) {
  1998. onError(message, length || 0);
  1999. }
  2000. }
  2001. function isIdentifierStart(ch) {
  2002. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2003. ch === 36 || ch === 95 ||
  2004. ch > 127 && isUnicodeIdentifierStart(ch, languageVersion);
  2005. }
  2006. function isIdentifierPart(ch) {
  2007. return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 ||
  2008. ch >= 48 && ch <= 57 || ch === 36 || ch === 95 ||
  2009. ch > 127 && isUnicodeIdentifierPart(ch, languageVersion);
  2010. }
  2011. function scanNumber() {
  2012. var start = pos;
  2013. while (isDigit(text.charCodeAt(pos)))
  2014. pos++;
  2015. if (text.charCodeAt(pos) === 46) {
  2016. pos++;
  2017. while (isDigit(text.charCodeAt(pos)))
  2018. pos++;
  2019. }
  2020. var end = pos;
  2021. if (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101) {
  2022. pos++;
  2023. if (text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45)
  2024. pos++;
  2025. if (isDigit(text.charCodeAt(pos))) {
  2026. pos++;
  2027. while (isDigit(text.charCodeAt(pos)))
  2028. pos++;
  2029. end = pos;
  2030. }
  2031. else {
  2032. error(ts.Diagnostics.Digit_expected);
  2033. }
  2034. }
  2035. return +(text.substring(start, end));
  2036. }
  2037. function scanOctalDigits() {
  2038. var start = pos;
  2039. while (isOctalDigit(text.charCodeAt(pos))) {
  2040. pos++;
  2041. }
  2042. return +(text.substring(start, pos));
  2043. }
  2044. function scanExactNumberOfHexDigits(count) {
  2045. return scanHexDigits(count, false);
  2046. }
  2047. function scanMinimumNumberOfHexDigits(count) {
  2048. return scanHexDigits(count, true);
  2049. }
  2050. function scanHexDigits(minCount, scanAsManyAsPossible) {
  2051. var digits = 0;
  2052. var value = 0;
  2053. while (digits < minCount || scanAsManyAsPossible) {
  2054. var ch = text.charCodeAt(pos);
  2055. if (ch >= 48 && ch <= 57) {
  2056. value = value * 16 + ch - 48;
  2057. }
  2058. else if (ch >= 65 && ch <= 70) {
  2059. value = value * 16 + ch - 65 + 10;
  2060. }
  2061. else if (ch >= 97 && ch <= 102) {
  2062. value = value * 16 + ch - 97 + 10;
  2063. }
  2064. else {
  2065. break;
  2066. }
  2067. pos++;
  2068. digits++;
  2069. }
  2070. if (digits < minCount) {
  2071. value = -1;
  2072. }
  2073. return value;
  2074. }
  2075. function scanString() {
  2076. var quote = text.charCodeAt(pos++);
  2077. var result = "";
  2078. var start = pos;
  2079. while (true) {
  2080. if (pos >= end) {
  2081. result += text.substring(start, pos);
  2082. tokenIsUnterminated = true;
  2083. error(ts.Diagnostics.Unterminated_string_literal);
  2084. break;
  2085. }
  2086. var ch = text.charCodeAt(pos);
  2087. if (ch === quote) {
  2088. result += text.substring(start, pos);
  2089. pos++;
  2090. break;
  2091. }
  2092. if (ch === 92) {
  2093. result += text.substring(start, pos);
  2094. result += scanEscapeSequence();
  2095. start = pos;
  2096. continue;
  2097. }
  2098. if (isLineBreak(ch)) {
  2099. result += text.substring(start, pos);
  2100. tokenIsUnterminated = true;
  2101. error(ts.Diagnostics.Unterminated_string_literal);
  2102. break;
  2103. }
  2104. pos++;
  2105. }
  2106. return result;
  2107. }
  2108. function scanTemplateAndSetTokenValue() {
  2109. var startedWithBacktick = text.charCodeAt(pos) === 96;
  2110. pos++;
  2111. var start = pos;
  2112. var contents = "";
  2113. var resultingToken;
  2114. while (true) {
  2115. if (pos >= end) {
  2116. contents += text.substring(start, pos);
  2117. tokenIsUnterminated = true;
  2118. error(ts.Diagnostics.Unterminated_template_literal);
  2119. resultingToken = startedWithBacktick ? 10 : 13;
  2120. break;
  2121. }
  2122. var currChar = text.charCodeAt(pos);
  2123. if (currChar === 96) {
  2124. contents += text.substring(start, pos);
  2125. pos++;
  2126. resultingToken = startedWithBacktick ? 10 : 13;
  2127. break;
  2128. }
  2129. if (currChar === 36 && pos + 1 < end && text.charCodeAt(pos + 1) === 123) {
  2130. contents += text.substring(start, pos);
  2131. pos += 2;
  2132. resultingToken = startedWithBacktick ? 11 : 12;
  2133. break;
  2134. }
  2135. if (currChar === 92) {
  2136. contents += text.substring(start, pos);
  2137. contents += scanEscapeSequence();
  2138. start = pos;
  2139. continue;
  2140. }
  2141. if (currChar === 13) {
  2142. contents += text.substring(start, pos);
  2143. pos++;
  2144. if (pos < end && text.charCodeAt(pos) === 10) {
  2145. pos++;
  2146. }
  2147. contents += "\n";
  2148. start = pos;
  2149. continue;
  2150. }
  2151. pos++;
  2152. }
  2153. ts.Debug.assert(resultingToken !== undefined);
  2154. tokenValue = contents;
  2155. return resultingToken;
  2156. }
  2157. function scanEscapeSequence() {
  2158. pos++;
  2159. if (pos >= end) {
  2160. error(ts.Diagnostics.Unexpected_end_of_text);
  2161. return "";
  2162. }
  2163. var ch = text.charCodeAt(pos++);
  2164. switch (ch) {
  2165. case 48:
  2166. return "\0";
  2167. case 98:
  2168. return "\b";
  2169. case 116:
  2170. return "\t";
  2171. case 110:
  2172. return "\n";
  2173. case 118:
  2174. return "\v";
  2175. case 102:
  2176. return "\f";
  2177. case 114:
  2178. return "\r";
  2179. case 39:
  2180. return "\'";
  2181. case 34:
  2182. return "\"";
  2183. case 117:
  2184. if (pos < end && text.charCodeAt(pos) === 123) {
  2185. hasExtendedUnicodeEscape = true;
  2186. pos++;
  2187. return scanExtendedUnicodeEscape();
  2188. }
  2189. return scanHexadecimalEscape(4);
  2190. case 120:
  2191. return scanHexadecimalEscape(2);
  2192. case 13:
  2193. if (pos < end && text.charCodeAt(pos) === 10) {
  2194. pos++;
  2195. }
  2196. case 10:
  2197. case 8232:
  2198. case 8233:
  2199. return "";
  2200. default:
  2201. return String.fromCharCode(ch);
  2202. }
  2203. }
  2204. function scanHexadecimalEscape(numDigits) {
  2205. var escapedValue = scanExactNumberOfHexDigits(numDigits);
  2206. if (escapedValue >= 0) {
  2207. return String.fromCharCode(escapedValue);
  2208. }
  2209. else {
  2210. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2211. return "";
  2212. }
  2213. }
  2214. function scanExtendedUnicodeEscape() {
  2215. var escapedValue = scanMinimumNumberOfHexDigits(1);
  2216. var isInvalidExtendedEscape = false;
  2217. if (escapedValue < 0) {
  2218. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2219. isInvalidExtendedEscape = true;
  2220. }
  2221. else if (escapedValue > 0x10FFFF) {
  2222. error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive);
  2223. isInvalidExtendedEscape = true;
  2224. }
  2225. if (pos >= end) {
  2226. error(ts.Diagnostics.Unexpected_end_of_text);
  2227. isInvalidExtendedEscape = true;
  2228. }
  2229. else if (text.charCodeAt(pos) == 125) {
  2230. pos++;
  2231. }
  2232. else {
  2233. error(ts.Diagnostics.Unterminated_Unicode_escape_sequence);
  2234. isInvalidExtendedEscape = true;
  2235. }
  2236. if (isInvalidExtendedEscape) {
  2237. return "";
  2238. }
  2239. return utf16EncodeAsString(escapedValue);
  2240. }
  2241. function utf16EncodeAsString(codePoint) {
  2242. ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF);
  2243. if (codePoint <= 65535) {
  2244. return String.fromCharCode(codePoint);
  2245. }
  2246. var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800;
  2247. var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00;
  2248. return String.fromCharCode(codeUnit1, codeUnit2);
  2249. }
  2250. function peekUnicodeEscape() {
  2251. if (pos + 5 < end && text.charCodeAt(pos + 1) === 117) {
  2252. var start_1 = pos;
  2253. pos += 2;
  2254. var value = scanExactNumberOfHexDigits(4);
  2255. pos = start_1;
  2256. return value;
  2257. }
  2258. return -1;
  2259. }
  2260. function scanIdentifierParts() {
  2261. var result = "";
  2262. var start = pos;
  2263. while (pos < end) {
  2264. var ch = text.charCodeAt(pos);
  2265. if (isIdentifierPart(ch)) {
  2266. pos++;
  2267. }
  2268. else if (ch === 92) {
  2269. ch = peekUnicodeEscape();
  2270. if (!(ch >= 0 && isIdentifierPart(ch))) {
  2271. break;
  2272. }
  2273. result += text.substring(start, pos);
  2274. result += String.fromCharCode(ch);
  2275. pos += 6;
  2276. start = pos;
  2277. }
  2278. else {
  2279. break;
  2280. }
  2281. }
  2282. result += text.substring(start, pos);
  2283. return result;
  2284. }
  2285. function getIdentifierToken() {
  2286. var len = tokenValue.length;
  2287. if (len >= 2 && len <= 11) {
  2288. var ch = tokenValue.charCodeAt(0);
  2289. if (ch >= 97 && ch <= 122 && hasOwnProperty.call(textToToken, tokenValue)) {
  2290. return token = textToToken[tokenValue];
  2291. }
  2292. }
  2293. return token = 65;
  2294. }
  2295. function scanBinaryOrOctalDigits(base) {
  2296. ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8");
  2297. var value = 0;
  2298. var numberOfDigits = 0;
  2299. while (true) {
  2300. var ch = text.charCodeAt(pos);
  2301. var valueOfCh = ch - 48;
  2302. if (!isDigit(ch) || valueOfCh >= base) {
  2303. break;
  2304. }
  2305. value = value * base + valueOfCh;
  2306. pos++;
  2307. numberOfDigits++;
  2308. }
  2309. if (numberOfDigits === 0) {
  2310. return -1;
  2311. }
  2312. return value;
  2313. }
  2314. function scan() {
  2315. startPos = pos;
  2316. hasExtendedUnicodeEscape = false;
  2317. precedingLineBreak = false;
  2318. tokenIsUnterminated = false;
  2319. while (true) {
  2320. tokenPos = pos;
  2321. if (pos >= end) {
  2322. return token = 1;
  2323. }
  2324. var ch = text.charCodeAt(pos);
  2325. switch (ch) {
  2326. case 10:
  2327. case 13:
  2328. precedingLineBreak = true;
  2329. if (skipTrivia) {
  2330. pos++;
  2331. continue;
  2332. }
  2333. else {
  2334. if (ch === 13 && pos + 1 < end && text.charCodeAt(pos + 1) === 10) {
  2335. pos += 2;
  2336. }
  2337. else {
  2338. pos++;
  2339. }
  2340. return token = 4;
  2341. }
  2342. case 9:
  2343. case 11:
  2344. case 12:
  2345. case 32:
  2346. if (skipTrivia) {
  2347. pos++;
  2348. continue;
  2349. }
  2350. else {
  2351. while (pos < end && isWhiteSpace(text.charCodeAt(pos))) {
  2352. pos++;
  2353. }
  2354. return token = 5;
  2355. }
  2356. case 33:
  2357. if (text.charCodeAt(pos + 1) === 61) {
  2358. if (text.charCodeAt(pos + 2) === 61) {
  2359. return pos += 3, token = 31;
  2360. }
  2361. return pos += 2, token = 29;
  2362. }
  2363. return pos++, token = 46;
  2364. case 34:
  2365. case 39:
  2366. tokenValue = scanString();
  2367. return token = 8;
  2368. case 96:
  2369. return token = scanTemplateAndSetTokenValue();
  2370. case 37:
  2371. if (text.charCodeAt(pos + 1) === 61) {
  2372. return pos += 2, token = 58;
  2373. }
  2374. return pos++, token = 37;
  2375. case 38:
  2376. if (text.charCodeAt(pos + 1) === 38) {
  2377. return pos += 2, token = 48;
  2378. }
  2379. if (text.charCodeAt(pos + 1) === 61) {
  2380. return pos += 2, token = 62;
  2381. }
  2382. return pos++, token = 43;
  2383. case 40:
  2384. return pos++, token = 16;
  2385. case 41:
  2386. return pos++, token = 17;
  2387. case 42:
  2388. if (text.charCodeAt(pos + 1) === 61) {
  2389. return pos += 2, token = 56;
  2390. }
  2391. return pos++, token = 35;
  2392. case 43:
  2393. if (text.charCodeAt(pos + 1) === 43) {
  2394. return pos += 2, token = 38;
  2395. }
  2396. if (text.charCodeAt(pos + 1) === 61) {
  2397. return pos += 2, token = 54;
  2398. }
  2399. return pos++, token = 33;
  2400. case 44:
  2401. return pos++, token = 23;
  2402. case 45:
  2403. if (text.charCodeAt(pos + 1) === 45) {
  2404. return pos += 2, token = 39;
  2405. }
  2406. if (text.charCodeAt(pos + 1) === 61) {
  2407. return pos += 2, token = 55;
  2408. }
  2409. return pos++, token = 34;
  2410. case 46:
  2411. if (isDigit(text.charCodeAt(pos + 1))) {
  2412. tokenValue = "" + scanNumber();
  2413. return token = 7;
  2414. }
  2415. if (text.charCodeAt(pos + 1) === 46 && text.charCodeAt(pos + 2) === 46) {
  2416. return pos += 3, token = 21;
  2417. }
  2418. return pos++, token = 20;
  2419. case 47:
  2420. if (text.charCodeAt(pos + 1) === 47) {
  2421. pos += 2;
  2422. while (pos < end) {
  2423. if (isLineBreak(text.charCodeAt(pos))) {
  2424. break;
  2425. }
  2426. pos++;
  2427. }
  2428. if (skipTrivia) {
  2429. continue;
  2430. }
  2431. else {
  2432. return token = 2;
  2433. }
  2434. }
  2435. if (text.charCodeAt(pos + 1) === 42) {
  2436. pos += 2;
  2437. var commentClosed = false;
  2438. while (pos < end) {
  2439. var ch_2 = text.charCodeAt(pos);
  2440. if (ch_2 === 42 && text.charCodeAt(pos + 1) === 47) {
  2441. pos += 2;
  2442. commentClosed = true;
  2443. break;
  2444. }
  2445. if (isLineBreak(ch_2)) {
  2446. precedingLineBreak = true;
  2447. }
  2448. pos++;
  2449. }
  2450. if (!commentClosed) {
  2451. error(ts.Diagnostics.Asterisk_Slash_expected);
  2452. }
  2453. if (skipTrivia) {
  2454. continue;
  2455. }
  2456. else {
  2457. tokenIsUnterminated = !commentClosed;
  2458. return token = 3;
  2459. }
  2460. }
  2461. if (text.charCodeAt(pos + 1) === 61) {
  2462. return pos += 2, token = 57;
  2463. }
  2464. return pos++, token = 36;
  2465. case 48:
  2466. if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) {
  2467. pos += 2;
  2468. var value = scanMinimumNumberOfHexDigits(1);
  2469. if (value < 0) {
  2470. error(ts.Diagnostics.Hexadecimal_digit_expected);
  2471. value = 0;
  2472. }
  2473. tokenValue = "" + value;
  2474. return token = 7;
  2475. }
  2476. else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 || text.charCodeAt(pos + 1) === 98)) {
  2477. pos += 2;
  2478. var value = scanBinaryOrOctalDigits(2);
  2479. if (value < 0) {
  2480. error(ts.Diagnostics.Binary_digit_expected);
  2481. value = 0;
  2482. }
  2483. tokenValue = "" + value;
  2484. return token = 7;
  2485. }
  2486. else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 || text.charCodeAt(pos + 1) === 111)) {
  2487. pos += 2;
  2488. var value = scanBinaryOrOctalDigits(8);
  2489. if (value < 0) {
  2490. error(ts.Diagnostics.Octal_digit_expected);
  2491. value = 0;
  2492. }
  2493. tokenValue = "" + value;
  2494. return token = 7;
  2495. }
  2496. if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) {
  2497. tokenValue = "" + scanOctalDigits();
  2498. return token = 7;
  2499. }
  2500. case 49:
  2501. case 50:
  2502. case 51:
  2503. case 52:
  2504. case 53:
  2505. case 54:
  2506. case 55:
  2507. case 56:
  2508. case 57:
  2509. tokenValue = "" + scanNumber();
  2510. return token = 7;
  2511. case 58:
  2512. return pos++, token = 51;
  2513. case 59:
  2514. return pos++, token = 22;
  2515. case 60:
  2516. if (isConflictMarkerTrivia(text, pos)) {
  2517. pos = scanConflictMarkerTrivia(text, pos, error);
  2518. if (skipTrivia) {
  2519. continue;
  2520. }
  2521. else {
  2522. return token = 6;
  2523. }
  2524. }
  2525. if (text.charCodeAt(pos + 1) === 60) {
  2526. if (text.charCodeAt(pos + 2) === 61) {
  2527. return pos += 3, token = 59;
  2528. }
  2529. return pos += 2, token = 40;
  2530. }
  2531. if (text.charCodeAt(pos + 1) === 61) {
  2532. return pos += 2, token = 26;
  2533. }
  2534. return pos++, token = 24;
  2535. case 61:
  2536. if (isConflictMarkerTrivia(text, pos)) {
  2537. pos = scanConflictMarkerTrivia(text, pos, error);
  2538. if (skipTrivia) {
  2539. continue;
  2540. }
  2541. else {
  2542. return token = 6;
  2543. }
  2544. }
  2545. if (text.charCodeAt(pos + 1) === 61) {
  2546. if (text.charCodeAt(pos + 2) === 61) {
  2547. return pos += 3, token = 30;
  2548. }
  2549. return pos += 2, token = 28;
  2550. }
  2551. if (text.charCodeAt(pos + 1) === 62) {
  2552. return pos += 2, token = 32;
  2553. }
  2554. return pos++, token = 53;
  2555. case 62:
  2556. if (isConflictMarkerTrivia(text, pos)) {
  2557. pos = scanConflictMarkerTrivia(text, pos, error);
  2558. if (skipTrivia) {
  2559. continue;
  2560. }
  2561. else {
  2562. return token = 6;
  2563. }
  2564. }
  2565. return pos++, token = 25;
  2566. case 63:
  2567. return pos++, token = 50;
  2568. case 91:
  2569. return pos++, token = 18;
  2570. case 93:
  2571. return pos++, token = 19;
  2572. case 94:
  2573. if (text.charCodeAt(pos + 1) === 61) {
  2574. return pos += 2, token = 64;
  2575. }
  2576. return pos++, token = 45;
  2577. case 123:
  2578. return pos++, token = 14;
  2579. case 124:
  2580. if (text.charCodeAt(pos + 1) === 124) {
  2581. return pos += 2, token = 49;
  2582. }
  2583. if (text.charCodeAt(pos + 1) === 61) {
  2584. return pos += 2, token = 63;
  2585. }
  2586. return pos++, token = 44;
  2587. case 125:
  2588. return pos++, token = 15;
  2589. case 126:
  2590. return pos++, token = 47;
  2591. case 64:
  2592. return pos++, token = 52;
  2593. case 92:
  2594. var cookedChar = peekUnicodeEscape();
  2595. if (cookedChar >= 0 && isIdentifierStart(cookedChar)) {
  2596. pos += 6;
  2597. tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
  2598. return token = getIdentifierToken();
  2599. }
  2600. error(ts.Diagnostics.Invalid_character);
  2601. return pos++, token = 0;
  2602. default:
  2603. if (isIdentifierStart(ch)) {
  2604. pos++;
  2605. while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos)))
  2606. pos++;
  2607. tokenValue = text.substring(tokenPos, pos);
  2608. if (ch === 92) {
  2609. tokenValue += scanIdentifierParts();
  2610. }
  2611. return token = getIdentifierToken();
  2612. }
  2613. else if (isWhiteSpace(ch)) {
  2614. pos++;
  2615. continue;
  2616. }
  2617. else if (isLineBreak(ch)) {
  2618. precedingLineBreak = true;
  2619. pos++;
  2620. continue;
  2621. }
  2622. error(ts.Diagnostics.Invalid_character);
  2623. return pos++, token = 0;
  2624. }
  2625. }
  2626. }
  2627. function reScanGreaterToken() {
  2628. if (token === 25) {
  2629. if (text.charCodeAt(pos) === 62) {
  2630. if (text.charCodeAt(pos + 1) === 62) {
  2631. if (text.charCodeAt(pos + 2) === 61) {
  2632. return pos += 3, token = 61;
  2633. }
  2634. return pos += 2, token = 42;
  2635. }
  2636. if (text.charCodeAt(pos + 1) === 61) {
  2637. return pos += 2, token = 60;
  2638. }
  2639. return pos++, token = 41;
  2640. }
  2641. if (text.charCodeAt(pos) === 61) {
  2642. return pos++, token = 27;
  2643. }
  2644. }
  2645. return token;
  2646. }
  2647. function reScanSlashToken() {
  2648. if (token === 36 || token === 57) {
  2649. var p = tokenPos + 1;
  2650. var inEscape = false;
  2651. var inCharacterClass = false;
  2652. while (true) {
  2653. if (p >= end) {
  2654. tokenIsUnterminated = true;
  2655. error(ts.Diagnostics.Unterminated_regular_expression_literal);
  2656. break;
  2657. }
  2658. var ch = text.charCodeAt(p);
  2659. if (isLineBreak(ch)) {
  2660. tokenIsUnterminated = true;
  2661. error(ts.Diagnostics.Unterminated_regular_expression_literal);
  2662. break;
  2663. }
  2664. if (inEscape) {
  2665. inEscape = false;
  2666. }
  2667. else if (ch === 47 && !inCharacterClass) {
  2668. p++;
  2669. break;
  2670. }
  2671. else if (ch === 91) {
  2672. inCharacterClass = true;
  2673. }
  2674. else if (ch === 92) {
  2675. inEscape = true;
  2676. }
  2677. else if (ch === 93) {
  2678. inCharacterClass = false;
  2679. }
  2680. p++;
  2681. }
  2682. while (p < end && isIdentifierPart(text.charCodeAt(p))) {
  2683. p++;
  2684. }
  2685. pos = p;
  2686. tokenValue = text.substring(tokenPos, pos);
  2687. token = 9;
  2688. }
  2689. return token;
  2690. }
  2691. function reScanTemplateToken() {
  2692. ts.Debug.assert(token === 15, "'reScanTemplateToken' should only be called on a '}'");
  2693. pos = tokenPos;
  2694. return token = scanTemplateAndSetTokenValue();
  2695. }
  2696. function speculationHelper(callback, isLookahead) {
  2697. var savePos = pos;
  2698. var saveStartPos = startPos;
  2699. var saveTokenPos = tokenPos;
  2700. var saveToken = token;
  2701. var saveTokenValue = tokenValue;
  2702. var savePrecedingLineBreak = precedingLineBreak;
  2703. var result = callback();
  2704. if (!result || isLookahead) {
  2705. pos = savePos;
  2706. startPos = saveStartPos;
  2707. tokenPos = saveTokenPos;
  2708. token = saveToken;
  2709. tokenValue = saveTokenValue;
  2710. precedingLineBreak = savePrecedingLineBreak;
  2711. }
  2712. return result;
  2713. }
  2714. function lookAhead(callback) {
  2715. return speculationHelper(callback, true);
  2716. }
  2717. function tryScan(callback) {
  2718. return speculationHelper(callback, false);
  2719. }
  2720. function setText(newText, start, length) {
  2721. text = newText || "";
  2722. end = length === undefined ? text.length : start + length;
  2723. setTextPos(start || 0);
  2724. }
  2725. function setOnError(errorCallback) {
  2726. onError = errorCallback;
  2727. }
  2728. function setScriptTarget(scriptTarget) {
  2729. languageVersion = scriptTarget;
  2730. }
  2731. function setTextPos(textPos) {
  2732. ts.Debug.assert(textPos >= 0);
  2733. pos = textPos;
  2734. startPos = textPos;
  2735. tokenPos = textPos;
  2736. token = 0;
  2737. precedingLineBreak = false;
  2738. tokenValue = undefined;
  2739. hasExtendedUnicodeEscape = false;
  2740. tokenIsUnterminated = false;
  2741. }
  2742. }
  2743. ts.createScanner = createScanner;
  2744. })(ts || (ts = {}));
  2745. /// <reference path="parser.ts"/>
  2746. var ts;
  2747. (function (ts) {
  2748. ts.bindTime = 0;
  2749. function getModuleInstanceState(node) {
  2750. if (node.kind === 203 || node.kind === 204) {
  2751. return 0;
  2752. }
  2753. else if (ts.isConstEnumDeclaration(node)) {
  2754. return 2;
  2755. }
  2756. else if ((node.kind === 210 || node.kind === 209) && !(node.flags & 1)) {
  2757. return 0;
  2758. }
  2759. else if (node.kind === 207) {
  2760. var state = 0;
  2761. ts.forEachChild(node, function (n) {
  2762. switch (getModuleInstanceState(n)) {
  2763. case 0:
  2764. return false;
  2765. case 2:
  2766. state = 2;
  2767. return false;
  2768. case 1:
  2769. state = 1;
  2770. return true;
  2771. }
  2772. });
  2773. return state;
  2774. }
  2775. else if (node.kind === 206) {
  2776. return getModuleInstanceState(node.body);
  2777. }
  2778. else {
  2779. return 1;
  2780. }
  2781. }
  2782. ts.getModuleInstanceState = getModuleInstanceState;
  2783. function bindSourceFile(file) {
  2784. var start = new Date().getTime();
  2785. bindSourceFileWorker(file);
  2786. ts.bindTime += new Date().getTime() - start;
  2787. }
  2788. ts.bindSourceFile = bindSourceFile;
  2789. function bindSourceFileWorker(file) {
  2790. var parent;
  2791. var container;
  2792. var blockScopeContainer;
  2793. var lastContainer;
  2794. var symbolCount = 0;
  2795. var Symbol = ts.objectAllocator.getSymbolConstructor();
  2796. if (!file.locals) {
  2797. file.locals = {};
  2798. container = file;
  2799. setBlockScopeContainer(file, false);
  2800. bind(file);
  2801. file.symbolCount = symbolCount;
  2802. }
  2803. function createSymbol(flags, name) {
  2804. symbolCount++;
  2805. return new Symbol(flags, name);
  2806. }
  2807. function setBlockScopeContainer(node, cleanLocals) {
  2808. blockScopeContainer = node;
  2809. if (cleanLocals) {
  2810. blockScopeContainer.locals = undefined;
  2811. }
  2812. }
  2813. function addDeclarationToSymbol(symbol, node, symbolKind) {
  2814. symbol.flags |= symbolKind;
  2815. if (!symbol.declarations)
  2816. symbol.declarations = [];
  2817. symbol.declarations.push(node);
  2818. if (symbolKind & 1952 && !symbol.exports)
  2819. symbol.exports = {};
  2820. if (symbolKind & 6240 && !symbol.members)
  2821. symbol.members = {};
  2822. node.symbol = symbol;
  2823. if (symbolKind & 107455 && !symbol.valueDeclaration)
  2824. symbol.valueDeclaration = node;
  2825. }
  2826. function getDeclarationName(node) {
  2827. if (node.name) {
  2828. if (node.kind === 206 && node.name.kind === 8) {
  2829. return '"' + node.name.text + '"';
  2830. }
  2831. if (node.name.kind === 128) {
  2832. var nameExpression = node.name.expression;
  2833. ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression));
  2834. return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text);
  2835. }
  2836. return node.name.text;
  2837. }
  2838. switch (node.kind) {
  2839. case 144:
  2840. case 136:
  2841. return "__constructor";
  2842. case 143:
  2843. case 139:
  2844. return "__call";
  2845. case 140:
  2846. return "__new";
  2847. case 141:
  2848. return "__index";
  2849. case 216:
  2850. return "__export";
  2851. case 215:
  2852. return node.isExportEquals ? "export=" : "default";
  2853. case 201:
  2854. case 202:
  2855. return node.flags & 256 ? "default" : undefined;
  2856. }
  2857. }
  2858. function getDisplayName(node) {
  2859. return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node);
  2860. }
  2861. function declareSymbol(symbols, parent, node, includes, excludes) {
  2862. ts.Debug.assert(!ts.hasDynamicName(node));
  2863. var name = node.flags & 256 && parent ? "default" : getDeclarationName(node);
  2864. var symbol;
  2865. if (name !== undefined) {
  2866. symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name));
  2867. if (symbol.flags & excludes) {
  2868. if (node.name) {
  2869. node.name.parent = node;
  2870. }
  2871. var message = symbol.flags & 2
  2872. ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
  2873. : ts.Diagnostics.Duplicate_identifier_0;
  2874. ts.forEach(symbol.declarations, function (declaration) {
  2875. file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
  2876. });
  2877. file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node)));
  2878. symbol = createSymbol(0, name);
  2879. }
  2880. }
  2881. else {
  2882. symbol = createSymbol(0, "__missing");
  2883. }
  2884. addDeclarationToSymbol(symbol, node, includes);
  2885. symbol.parent = parent;
  2886. if ((node.kind === 202 || node.kind === 175) && symbol.exports) {
  2887. var prototypeSymbol = createSymbol(4 | 134217728, "prototype");
  2888. if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
  2889. if (node.name) {
  2890. node.name.parent = node;
  2891. }
  2892. file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
  2893. }
  2894. symbol.exports[prototypeSymbol.name] = prototypeSymbol;
  2895. prototypeSymbol.parent = symbol;
  2896. }
  2897. return symbol;
  2898. }
  2899. function declareModuleMember(node, symbolKind, symbolExcludes) {
  2900. var hasExportModifier = ts.getCombinedNodeFlags(node) & 1;
  2901. if (symbolKind & 8388608) {
  2902. if (node.kind === 218 || (node.kind === 209 && hasExportModifier)) {
  2903. declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
  2904. }
  2905. else {
  2906. declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
  2907. }
  2908. }
  2909. else {
  2910. if (hasExportModifier || container.flags & 65536) {
  2911. var exportKind = (symbolKind & 107455 ? 1048576 : 0) |
  2912. (symbolKind & 793056 ? 2097152 : 0) |
  2913. (symbolKind & 1536 ? 4194304 : 0);
  2914. var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
  2915. local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
  2916. node.localSymbol = local;
  2917. }
  2918. else {
  2919. declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
  2920. }
  2921. }
  2922. }
  2923. function bindChildren(node, symbolKind, isBlockScopeContainer) {
  2924. if (symbolKind & 255504) {
  2925. node.locals = {};
  2926. }
  2927. var saveParent = parent;
  2928. var saveContainer = container;
  2929. var savedBlockScopeContainer = blockScopeContainer;
  2930. parent = node;
  2931. if (symbolKind & 262128) {
  2932. container = node;
  2933. addToContainerChain(container);
  2934. }
  2935. if (isBlockScopeContainer) {
  2936. setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 228);
  2937. }
  2938. ts.forEachChild(node, bind);
  2939. container = saveContainer;
  2940. parent = saveParent;
  2941. blockScopeContainer = savedBlockScopeContainer;
  2942. }
  2943. function addToContainerChain(node) {
  2944. if (lastContainer) {
  2945. lastContainer.nextContainer = node;
  2946. }
  2947. lastContainer = node;
  2948. }
  2949. function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
  2950. switch (container.kind) {
  2951. case 206:
  2952. declareModuleMember(node, symbolKind, symbolExcludes);
  2953. break;
  2954. case 228:
  2955. if (ts.isExternalModule(container)) {
  2956. declareModuleMember(node, symbolKind, symbolExcludes);
  2957. break;
  2958. }
  2959. case 143:
  2960. case 144:
  2961. case 139:
  2962. case 140:
  2963. case 141:
  2964. case 135:
  2965. case 134:
  2966. case 136:
  2967. case 137:
  2968. case 138:
  2969. case 201:
  2970. case 163:
  2971. case 164:
  2972. declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
  2973. break;
  2974. case 175:
  2975. case 202:
  2976. if (node.flags & 128) {
  2977. declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
  2978. break;
  2979. }
  2980. case 146:
  2981. case 155:
  2982. case 203:
  2983. declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes);
  2984. break;
  2985. case 205:
  2986. declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
  2987. break;
  2988. }
  2989. bindChildren(node, symbolKind, isBlockScopeContainer);
  2990. }
  2991. function isAmbientContext(node) {
  2992. while (node) {
  2993. if (node.flags & 2)
  2994. return true;
  2995. node = node.parent;
  2996. }
  2997. return false;
  2998. }
  2999. function hasExportDeclarations(node) {
  3000. var body = node.kind === 228 ? node : node.body;
  3001. if (body.kind === 228 || body.kind === 207) {
  3002. for (var _i = 0, _a = body.statements; _i < _a.length; _i++) {
  3003. var stat = _a[_i];
  3004. if (stat.kind === 216 || stat.kind === 215) {
  3005. return true;
  3006. }
  3007. }
  3008. }
  3009. return false;
  3010. }
  3011. function setExportContextFlag(node) {
  3012. if (isAmbientContext(node) && !hasExportDeclarations(node)) {
  3013. node.flags |= 65536;
  3014. }
  3015. else {
  3016. node.flags &= ~65536;
  3017. }
  3018. }
  3019. function bindModuleDeclaration(node) {
  3020. setExportContextFlag(node);
  3021. if (node.name.kind === 8) {
  3022. bindDeclaration(node, 512, 106639, true);
  3023. }
  3024. else {
  3025. var state = getModuleInstanceState(node);
  3026. if (state === 0) {
  3027. bindDeclaration(node, 1024, 0, true);
  3028. }
  3029. else {
  3030. bindDeclaration(node, 512, 106639, true);
  3031. var currentModuleIsConstEnumOnly = state === 2;
  3032. if (node.symbol.constEnumOnlyModule === undefined) {
  3033. node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
  3034. }
  3035. else {
  3036. node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
  3037. }
  3038. }
  3039. }
  3040. }
  3041. function bindFunctionOrConstructorType(node) {
  3042. // For a given function symbol "<...>(...) => T" we want to generate a symbol identical
  3043. // to the one we would get for: { <...>(...): T }
  3044. //
  3045. // We do that by making an anonymous type literal symbol, and then setting the function
  3046. // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
  3047. // from an actual type literal symbol you would have gotten had you used the long form.
  3048. var symbol = createSymbol(131072, getDeclarationName(node));
  3049. addDeclarationToSymbol(symbol, node, 131072);
  3050. bindChildren(node, 131072, false);
  3051. var typeLiteralSymbol = createSymbol(2048, "__type");
  3052. addDeclarationToSymbol(typeLiteralSymbol, node, 2048);
  3053. typeLiteralSymbol.members = {};
  3054. typeLiteralSymbol.members[node.kind === 143 ? "__call" : "__new"] = symbol;
  3055. }
  3056. function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) {
  3057. var symbol = createSymbol(symbolKind, name);
  3058. addDeclarationToSymbol(symbol, node, symbolKind);
  3059. bindChildren(node, symbolKind, isBlockScopeContainer);
  3060. }
  3061. function bindCatchVariableDeclaration(node) {
  3062. bindChildren(node, 0, true);
  3063. }
  3064. function bindBlockScopedDeclaration(node, symbolKind, symbolExcludes) {
  3065. switch (blockScopeContainer.kind) {
  3066. case 206:
  3067. declareModuleMember(node, symbolKind, symbolExcludes);
  3068. break;
  3069. case 228:
  3070. if (ts.isExternalModule(container)) {
  3071. declareModuleMember(node, symbolKind, symbolExcludes);
  3072. break;
  3073. }
  3074. default:
  3075. if (!blockScopeContainer.locals) {
  3076. blockScopeContainer.locals = {};
  3077. addToContainerChain(blockScopeContainer);
  3078. }
  3079. declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes);
  3080. }
  3081. bindChildren(node, symbolKind, false);
  3082. }
  3083. function bindBlockScopedVariableDeclaration(node) {
  3084. bindBlockScopedDeclaration(node, 2, 107455);
  3085. }
  3086. function getDestructuringParameterName(node) {
  3087. return "__" + ts.indexOf(node.parent.parameters, node);
  3088. }
  3089. function bind(node) {
  3090. node.parent = parent;
  3091. switch (node.kind) {
  3092. case 129:
  3093. bindDeclaration(node, 262144, 530912, false);
  3094. break;
  3095. case 130:
  3096. bindParameter(node);
  3097. break;
  3098. case 199:
  3099. case 153:
  3100. if (ts.isBindingPattern(node.name)) {
  3101. bindChildren(node, 0, false);
  3102. }
  3103. else if (ts.isBlockOrCatchScoped(node)) {
  3104. bindBlockScopedVariableDeclaration(node);
  3105. }
  3106. else {
  3107. bindDeclaration(node, 1, 107454, false);
  3108. }
  3109. break;
  3110. case 133:
  3111. case 132:
  3112. bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455, false);
  3113. break;
  3114. case 225:
  3115. case 226:
  3116. bindPropertyOrMethodOrAccessor(node, 4, 107455, false);
  3117. break;
  3118. case 227:
  3119. bindPropertyOrMethodOrAccessor(node, 8, 107455, false);
  3120. break;
  3121. case 139:
  3122. case 140:
  3123. case 141:
  3124. bindDeclaration(node, 131072, 0, false);
  3125. break;
  3126. case 135:
  3127. case 134:
  3128. bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263, true);
  3129. break;
  3130. case 201:
  3131. bindDeclaration(node, 16, 106927, true);
  3132. break;
  3133. case 136:
  3134. bindDeclaration(node, 16384, 0, true);
  3135. break;
  3136. case 137:
  3137. bindPropertyOrMethodOrAccessor(node, 32768, 41919, true);
  3138. break;
  3139. case 138:
  3140. bindPropertyOrMethodOrAccessor(node, 65536, 74687, true);
  3141. break;
  3142. case 143:
  3143. case 144:
  3144. bindFunctionOrConstructorType(node);
  3145. break;
  3146. case 146:
  3147. bindAnonymousDeclaration(node, 2048, "__type", false);
  3148. break;
  3149. case 155:
  3150. bindAnonymousDeclaration(node, 4096, "__object", false);
  3151. break;
  3152. case 163:
  3153. case 164:
  3154. bindAnonymousDeclaration(node, 16, "__function", true);
  3155. break;
  3156. case 175:
  3157. bindAnonymousDeclaration(node, 32, "__class", false);
  3158. break;
  3159. case 224:
  3160. bindCatchVariableDeclaration(node);
  3161. break;
  3162. case 202:
  3163. bindBlockScopedDeclaration(node, 32, 899583);
  3164. break;
  3165. case 203:
  3166. bindDeclaration(node, 64, 792992, false);
  3167. break;
  3168. case 204:
  3169. bindDeclaration(node, 524288, 793056, false);
  3170. break;
  3171. case 205:
  3172. if (ts.isConst(node)) {
  3173. bindDeclaration(node, 128, 899967, false);
  3174. }
  3175. else {
  3176. bindDeclaration(node, 256, 899327, false);
  3177. }
  3178. break;
  3179. case 206:
  3180. bindModuleDeclaration(node);
  3181. break;
  3182. case 209:
  3183. case 212:
  3184. case 214:
  3185. case 218:
  3186. bindDeclaration(node, 8388608, 8388608, false);
  3187. break;
  3188. case 211:
  3189. if (node.name) {
  3190. bindDeclaration(node, 8388608, 8388608, false);
  3191. }
  3192. else {
  3193. bindChildren(node, 0, false);
  3194. }
  3195. break;
  3196. case 216:
  3197. if (!node.exportClause) {
  3198. declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0);
  3199. }
  3200. bindChildren(node, 0, false);
  3201. break;
  3202. case 215:
  3203. if (node.expression.kind === 65) {
  3204. declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608);
  3205. }
  3206. else {
  3207. declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608);
  3208. }
  3209. bindChildren(node, 0, false);
  3210. break;
  3211. case 228:
  3212. setExportContextFlag(node);
  3213. if (ts.isExternalModule(node)) {
  3214. bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true);
  3215. break;
  3216. }
  3217. case 180:
  3218. bindChildren(node, 0, !ts.isFunctionLike(node.parent));
  3219. break;
  3220. case 224:
  3221. case 187:
  3222. case 188:
  3223. case 189:
  3224. case 208:
  3225. bindChildren(node, 0, true);
  3226. break;
  3227. default:
  3228. var saveParent = parent;
  3229. parent = node;
  3230. ts.forEachChild(node, bind);
  3231. parent = saveParent;
  3232. }
  3233. }
  3234. function bindParameter(node) {
  3235. if (ts.isBindingPattern(node.name)) {
  3236. bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node), false);
  3237. }
  3238. else {
  3239. bindDeclaration(node, 1, 107455, false);
  3240. }
  3241. if (node.flags & 112 &&
  3242. node.parent.kind === 136 &&
  3243. (node.parent.parent.kind === 202 || node.parent.parent.kind === 175)) {
  3244. var classDeclaration = node.parent.parent;
  3245. declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455);
  3246. }
  3247. }
  3248. function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
  3249. if (ts.hasDynamicName(node)) {
  3250. bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer);
  3251. }
  3252. else {
  3253. bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer);
  3254. }
  3255. }
  3256. }
  3257. })(ts || (ts = {}));
  3258. /// <reference path="binder.ts" />
  3259. var ts;
  3260. (function (ts) {
  3261. function getDeclarationOfKind(symbol, kind) {
  3262. var declarations = symbol.declarations;
  3263. for (var _i = 0; _i < declarations.length; _i++) {
  3264. var declaration = declarations[_i];
  3265. if (declaration.kind === kind) {
  3266. return declaration;
  3267. }
  3268. }
  3269. return undefined;
  3270. }
  3271. ts.getDeclarationOfKind = getDeclarationOfKind;
  3272. var stringWriters = [];
  3273. function getSingleLineStringWriter() {
  3274. if (stringWriters.length == 0) {
  3275. var str = "";
  3276. var writeText = function (text) { return str += text; };
  3277. return {
  3278. string: function () { return str; },
  3279. writeKeyword: writeText,
  3280. writeOperator: writeText,
  3281. writePunctuation: writeText,
  3282. writeSpace: writeText,
  3283. writeStringLiteral: writeText,
  3284. writeParameter: writeText,
  3285. writeSymbol: writeText,
  3286. writeLine: function () { return str += " "; },
  3287. increaseIndent: function () { },
  3288. decreaseIndent: function () { },
  3289. clear: function () { return str = ""; },
  3290. trackSymbol: function () { }
  3291. };
  3292. }
  3293. return stringWriters.pop();
  3294. }
  3295. ts.getSingleLineStringWriter = getSingleLineStringWriter;
  3296. function releaseStringWriter(writer) {
  3297. writer.clear();
  3298. stringWriters.push(writer);
  3299. }
  3300. ts.releaseStringWriter = releaseStringWriter;
  3301. function getFullWidth(node) {
  3302. return node.end - node.pos;
  3303. }
  3304. ts.getFullWidth = getFullWidth;
  3305. function containsParseError(node) {
  3306. aggregateChildData(node);
  3307. return (node.parserContextFlags & 64) !== 0;
  3308. }
  3309. ts.containsParseError = containsParseError;
  3310. function aggregateChildData(node) {
  3311. if (!(node.parserContextFlags & 128)) {
  3312. var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 32) !== 0) ||
  3313. ts.forEachChild(node, containsParseError);
  3314. if (thisNodeOrAnySubNodesHasError) {
  3315. node.parserContextFlags |= 64;
  3316. }
  3317. node.parserContextFlags |= 128;
  3318. }
  3319. }
  3320. function getSourceFileOfNode(node) {
  3321. while (node && node.kind !== 228) {
  3322. node = node.parent;
  3323. }
  3324. return node;
  3325. }
  3326. ts.getSourceFileOfNode = getSourceFileOfNode;
  3327. function getStartPositionOfLine(line, sourceFile) {
  3328. ts.Debug.assert(line >= 0);
  3329. return ts.getLineStarts(sourceFile)[line];
  3330. }
  3331. ts.getStartPositionOfLine = getStartPositionOfLine;
  3332. function nodePosToString(node) {
  3333. var file = getSourceFileOfNode(node);
  3334. var loc = ts.getLineAndCharacterOfPosition(file, node.pos);
  3335. return file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + ")";
  3336. }
  3337. ts.nodePosToString = nodePosToString;
  3338. function getStartPosOfNode(node) {
  3339. return node.pos;
  3340. }
  3341. ts.getStartPosOfNode = getStartPosOfNode;
  3342. function nodeIsMissing(node) {
  3343. if (!node) {
  3344. return true;
  3345. }
  3346. return node.pos === node.end && node.kind !== 1;
  3347. }
  3348. ts.nodeIsMissing = nodeIsMissing;
  3349. function nodeIsPresent(node) {
  3350. return !nodeIsMissing(node);
  3351. }
  3352. ts.nodeIsPresent = nodeIsPresent;
  3353. function getTokenPosOfNode(node, sourceFile) {
  3354. if (nodeIsMissing(node)) {
  3355. return node.pos;
  3356. }
  3357. return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
  3358. }
  3359. ts.getTokenPosOfNode = getTokenPosOfNode;
  3360. function getNonDecoratorTokenPosOfNode(node, sourceFile) {
  3361. if (nodeIsMissing(node) || !node.decorators) {
  3362. return getTokenPosOfNode(node, sourceFile);
  3363. }
  3364. return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
  3365. }
  3366. ts.getNonDecoratorTokenPosOfNode = getNonDecoratorTokenPosOfNode;
  3367. function getSourceTextOfNodeFromSourceFile(sourceFile, node) {
  3368. if (nodeIsMissing(node)) {
  3369. return "";
  3370. }
  3371. var text = sourceFile.text;
  3372. return text.substring(ts.skipTrivia(text, node.pos), node.end);
  3373. }
  3374. ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile;
  3375. function getTextOfNodeFromSourceText(sourceText, node) {
  3376. if (nodeIsMissing(node)) {
  3377. return "";
  3378. }
  3379. return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
  3380. }
  3381. ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText;
  3382. function getTextOfNode(node) {
  3383. return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node);
  3384. }
  3385. ts.getTextOfNode = getTextOfNode;
  3386. function escapeIdentifier(identifier) {
  3387. return identifier.length >= 2 && identifier.charCodeAt(0) === 95 && identifier.charCodeAt(1) === 95 ? "_" + identifier : identifier;
  3388. }
  3389. ts.escapeIdentifier = escapeIdentifier;
  3390. function unescapeIdentifier(identifier) {
  3391. return identifier.length >= 3 && identifier.charCodeAt(0) === 95 && identifier.charCodeAt(1) === 95 && identifier.charCodeAt(2) === 95 ? identifier.substr(1) : identifier;
  3392. }
  3393. ts.unescapeIdentifier = unescapeIdentifier;
  3394. function makeIdentifierFromModuleName(moduleName) {
  3395. return ts.getBaseFileName(moduleName).replace(/\W/g, "_");
  3396. }
  3397. ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName;
  3398. function isBlockOrCatchScoped(declaration) {
  3399. return (getCombinedNodeFlags(declaration) & 12288) !== 0 ||
  3400. isCatchClauseVariableDeclaration(declaration);
  3401. }
  3402. ts.isBlockOrCatchScoped = isBlockOrCatchScoped;
  3403. function getEnclosingBlockScopeContainer(node) {
  3404. var current = node.parent;
  3405. while (current) {
  3406. if (isFunctionLike(current)) {
  3407. return current;
  3408. }
  3409. switch (current.kind) {
  3410. case 228:
  3411. case 208:
  3412. case 224:
  3413. case 206:
  3414. case 187:
  3415. case 188:
  3416. case 189:
  3417. return current;
  3418. case 180:
  3419. if (!isFunctionLike(current.parent)) {
  3420. return current;
  3421. }
  3422. }
  3423. current = current.parent;
  3424. }
  3425. }
  3426. ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer;
  3427. function isCatchClauseVariableDeclaration(declaration) {
  3428. return declaration &&
  3429. declaration.kind === 199 &&
  3430. declaration.parent &&
  3431. declaration.parent.kind === 224;
  3432. }
  3433. ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration;
  3434. function declarationNameToString(name) {
  3435. return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name);
  3436. }
  3437. ts.declarationNameToString = declarationNameToString;
  3438. function createDiagnosticForNode(node, message, arg0, arg1, arg2) {
  3439. var sourceFile = getSourceFileOfNode(node);
  3440. var span = getErrorSpanForNode(sourceFile, node);
  3441. return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
  3442. }
  3443. ts.createDiagnosticForNode = createDiagnosticForNode;
  3444. function createDiagnosticForNodeFromMessageChain(node, messageChain) {
  3445. var sourceFile = getSourceFileOfNode(node);
  3446. var span = getErrorSpanForNode(sourceFile, node);
  3447. return {
  3448. file: sourceFile,
  3449. start: span.start,
  3450. length: span.length,
  3451. code: messageChain.code,
  3452. category: messageChain.category,
  3453. messageText: messageChain.next ? messageChain : messageChain.messageText
  3454. };
  3455. }
  3456. ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain;
  3457. function getSpanOfTokenAtPosition(sourceFile, pos) {
  3458. var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.text, undefined, pos);
  3459. scanner.scan();
  3460. var start = scanner.getTokenPos();
  3461. return ts.createTextSpanFromBounds(start, scanner.getTextPos());
  3462. }
  3463. ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition;
  3464. function getErrorSpanForNode(sourceFile, node) {
  3465. var errorNode = node;
  3466. switch (node.kind) {
  3467. case 228:
  3468. var pos_1 = ts.skipTrivia(sourceFile.text, 0, false);
  3469. if (pos_1 === sourceFile.text.length) {
  3470. return ts.createTextSpan(0, 0);
  3471. }
  3472. return getSpanOfTokenAtPosition(sourceFile, pos_1);
  3473. case 199:
  3474. case 153:
  3475. case 202:
  3476. case 175:
  3477. case 203:
  3478. case 206:
  3479. case 205:
  3480. case 227:
  3481. case 201:
  3482. case 163:
  3483. errorNode = node.name;
  3484. break;
  3485. }
  3486. if (errorNode === undefined) {
  3487. return getSpanOfTokenAtPosition(sourceFile, node.pos);
  3488. }
  3489. var pos = nodeIsMissing(errorNode)
  3490. ? errorNode.pos
  3491. : ts.skipTrivia(sourceFile.text, errorNode.pos);
  3492. return ts.createTextSpanFromBounds(pos, errorNode.end);
  3493. }
  3494. ts.getErrorSpanForNode = getErrorSpanForNode;
  3495. function isExternalModule(file) {
  3496. return file.externalModuleIndicator !== undefined;
  3497. }
  3498. ts.isExternalModule = isExternalModule;
  3499. function isDeclarationFile(file) {
  3500. return (file.flags & 2048) !== 0;
  3501. }
  3502. ts.isDeclarationFile = isDeclarationFile;
  3503. function isConstEnumDeclaration(node) {
  3504. return node.kind === 205 && isConst(node);
  3505. }
  3506. ts.isConstEnumDeclaration = isConstEnumDeclaration;
  3507. function walkUpBindingElementsAndPatterns(node) {
  3508. while (node && (node.kind === 153 || isBindingPattern(node))) {
  3509. node = node.parent;
  3510. }
  3511. return node;
  3512. }
  3513. function getCombinedNodeFlags(node) {
  3514. node = walkUpBindingElementsAndPatterns(node);
  3515. var flags = node.flags;
  3516. if (node.kind === 199) {
  3517. node = node.parent;
  3518. }
  3519. if (node && node.kind === 200) {
  3520. flags |= node.flags;
  3521. node = node.parent;
  3522. }
  3523. if (node && node.kind === 181) {
  3524. flags |= node.flags;
  3525. }
  3526. return flags;
  3527. }
  3528. ts.getCombinedNodeFlags = getCombinedNodeFlags;
  3529. function isConst(node) {
  3530. return !!(getCombinedNodeFlags(node) & 8192);
  3531. }
  3532. ts.isConst = isConst;
  3533. function isLet(node) {
  3534. return !!(getCombinedNodeFlags(node) & 4096);
  3535. }
  3536. ts.isLet = isLet;
  3537. function isPrologueDirective(node) {
  3538. return node.kind === 183 && node.expression.kind === 8;
  3539. }
  3540. ts.isPrologueDirective = isPrologueDirective;
  3541. function getLeadingCommentRangesOfNode(node, sourceFileOfNode) {
  3542. if (node.kind === 130 || node.kind === 129) {
  3543. return ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos));
  3544. }
  3545. else {
  3546. return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos);
  3547. }
  3548. }
  3549. ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode;
  3550. function getJsDocComments(node, sourceFileOfNode) {
  3551. return ts.filter(getLeadingCommentRangesOfNode(node, sourceFileOfNode), isJsDocComment);
  3552. function isJsDocComment(comment) {
  3553. return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 &&
  3554. sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 &&
  3555. sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47;
  3556. }
  3557. }
  3558. ts.getJsDocComments = getJsDocComments;
  3559. ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
  3560. function forEachReturnStatement(body, visitor) {
  3561. return traverse(body);
  3562. function traverse(node) {
  3563. switch (node.kind) {
  3564. case 192:
  3565. return visitor(node);
  3566. case 208:
  3567. case 180:
  3568. case 184:
  3569. case 185:
  3570. case 186:
  3571. case 187:
  3572. case 188:
  3573. case 189:
  3574. case 193:
  3575. case 194:
  3576. case 221:
  3577. case 222:
  3578. case 195:
  3579. case 197:
  3580. case 224:
  3581. return ts.forEachChild(node, traverse);
  3582. }
  3583. }
  3584. }
  3585. ts.forEachReturnStatement = forEachReturnStatement;
  3586. function isVariableLike(node) {
  3587. if (node) {
  3588. switch (node.kind) {
  3589. case 153:
  3590. case 227:
  3591. case 130:
  3592. case 225:
  3593. case 133:
  3594. case 132:
  3595. case 226:
  3596. case 199:
  3597. return true;
  3598. }
  3599. }
  3600. return false;
  3601. }
  3602. ts.isVariableLike = isVariableLike;
  3603. function isAccessor(node) {
  3604. if (node) {
  3605. switch (node.kind) {
  3606. case 137:
  3607. case 138:
  3608. return true;
  3609. }
  3610. }
  3611. return false;
  3612. }
  3613. ts.isAccessor = isAccessor;
  3614. function isFunctionLike(node) {
  3615. if (node) {
  3616. switch (node.kind) {
  3617. case 136:
  3618. case 163:
  3619. case 201:
  3620. case 164:
  3621. case 135:
  3622. case 134:
  3623. case 137:
  3624. case 138:
  3625. case 139:
  3626. case 140:
  3627. case 141:
  3628. case 143:
  3629. case 144:
  3630. case 163:
  3631. case 164:
  3632. case 201:
  3633. return true;
  3634. }
  3635. }
  3636. return false;
  3637. }
  3638. ts.isFunctionLike = isFunctionLike;
  3639. function isFunctionBlock(node) {
  3640. return node && node.kind === 180 && isFunctionLike(node.parent);
  3641. }
  3642. ts.isFunctionBlock = isFunctionBlock;
  3643. function isObjectLiteralMethod(node) {
  3644. return node && node.kind === 135 && node.parent.kind === 155;
  3645. }
  3646. ts.isObjectLiteralMethod = isObjectLiteralMethod;
  3647. function getContainingFunction(node) {
  3648. while (true) {
  3649. node = node.parent;
  3650. if (!node || isFunctionLike(node)) {
  3651. return node;
  3652. }
  3653. }
  3654. }
  3655. ts.getContainingFunction = getContainingFunction;
  3656. function getThisContainer(node, includeArrowFunctions) {
  3657. while (true) {
  3658. node = node.parent;
  3659. if (!node) {
  3660. return undefined;
  3661. }
  3662. switch (node.kind) {
  3663. case 128:
  3664. if (node.parent.parent.kind === 202) {
  3665. return node;
  3666. }
  3667. node = node.parent;
  3668. break;
  3669. case 131:
  3670. if (node.parent.kind === 130 && isClassElement(node.parent.parent)) {
  3671. node = node.parent.parent;
  3672. }
  3673. else if (isClassElement(node.parent)) {
  3674. node = node.parent;
  3675. }
  3676. break;
  3677. case 164:
  3678. if (!includeArrowFunctions) {
  3679. continue;
  3680. }
  3681. case 201:
  3682. case 163:
  3683. case 206:
  3684. case 133:
  3685. case 132:
  3686. case 135:
  3687. case 134:
  3688. case 136:
  3689. case 137:
  3690. case 138:
  3691. case 205:
  3692. case 228:
  3693. return node;
  3694. }
  3695. }
  3696. }
  3697. ts.getThisContainer = getThisContainer;
  3698. function getSuperContainer(node, includeFunctions) {
  3699. while (true) {
  3700. node = node.parent;
  3701. if (!node)
  3702. return node;
  3703. switch (node.kind) {
  3704. case 128:
  3705. if (node.parent.parent.kind === 202) {
  3706. return node;
  3707. }
  3708. node = node.parent;
  3709. break;
  3710. case 131:
  3711. if (node.parent.kind === 130 && isClassElement(node.parent.parent)) {
  3712. node = node.parent.parent;
  3713. }
  3714. else if (isClassElement(node.parent)) {
  3715. node = node.parent;
  3716. }
  3717. break;
  3718. case 201:
  3719. case 163:
  3720. case 164:
  3721. if (!includeFunctions) {
  3722. continue;
  3723. }
  3724. case 133:
  3725. case 132:
  3726. case 135:
  3727. case 134:
  3728. case 136:
  3729. case 137:
  3730. case 138:
  3731. return node;
  3732. }
  3733. }
  3734. }
  3735. ts.getSuperContainer = getSuperContainer;
  3736. function getInvokedExpression(node) {
  3737. if (node.kind === 160) {
  3738. return node.tag;
  3739. }
  3740. return node.expression;
  3741. }
  3742. ts.getInvokedExpression = getInvokedExpression;
  3743. function nodeCanBeDecorated(node) {
  3744. switch (node.kind) {
  3745. case 202:
  3746. return true;
  3747. case 133:
  3748. return node.parent.kind === 202;
  3749. case 130:
  3750. return node.parent.body && node.parent.parent.kind === 202;
  3751. case 137:
  3752. case 138:
  3753. case 135:
  3754. return node.body && node.parent.kind === 202;
  3755. }
  3756. return false;
  3757. }
  3758. ts.nodeCanBeDecorated = nodeCanBeDecorated;
  3759. function nodeIsDecorated(node) {
  3760. switch (node.kind) {
  3761. case 202:
  3762. if (node.decorators) {
  3763. return true;
  3764. }
  3765. return false;
  3766. case 133:
  3767. case 130:
  3768. if (node.decorators) {
  3769. return true;
  3770. }
  3771. return false;
  3772. case 137:
  3773. if (node.body && node.decorators) {
  3774. return true;
  3775. }
  3776. return false;
  3777. case 135:
  3778. case 138:
  3779. if (node.body && node.decorators) {
  3780. return true;
  3781. }
  3782. return false;
  3783. }
  3784. return false;
  3785. }
  3786. ts.nodeIsDecorated = nodeIsDecorated;
  3787. function childIsDecorated(node) {
  3788. switch (node.kind) {
  3789. case 202:
  3790. return ts.forEach(node.members, nodeOrChildIsDecorated);
  3791. case 135:
  3792. case 138:
  3793. return ts.forEach(node.parameters, nodeIsDecorated);
  3794. }
  3795. return false;
  3796. }
  3797. ts.childIsDecorated = childIsDecorated;
  3798. function nodeOrChildIsDecorated(node) {
  3799. return nodeIsDecorated(node) || childIsDecorated(node);
  3800. }
  3801. ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated;
  3802. function isExpression(node) {
  3803. switch (node.kind) {
  3804. case 93:
  3805. case 91:
  3806. case 89:
  3807. case 95:
  3808. case 80:
  3809. case 9:
  3810. case 154:
  3811. case 155:
  3812. case 156:
  3813. case 157:
  3814. case 158:
  3815. case 159:
  3816. case 160:
  3817. case 161:
  3818. case 162:
  3819. case 163:
  3820. case 175:
  3821. case 164:
  3822. case 167:
  3823. case 165:
  3824. case 166:
  3825. case 168:
  3826. case 169:
  3827. case 170:
  3828. case 171:
  3829. case 174:
  3830. case 172:
  3831. case 10:
  3832. case 176:
  3833. return true;
  3834. case 127:
  3835. while (node.parent.kind === 127) {
  3836. node = node.parent;
  3837. }
  3838. return node.parent.kind === 145;
  3839. case 65:
  3840. if (node.parent.kind === 145) {
  3841. return true;
  3842. }
  3843. case 7:
  3844. case 8:
  3845. var parent_1 = node.parent;
  3846. switch (parent_1.kind) {
  3847. case 199:
  3848. case 130:
  3849. case 133:
  3850. case 132:
  3851. case 227:
  3852. case 225:
  3853. case 153:
  3854. return parent_1.initializer === node;
  3855. case 183:
  3856. case 184:
  3857. case 185:
  3858. case 186:
  3859. case 192:
  3860. case 193:
  3861. case 194:
  3862. case 221:
  3863. case 196:
  3864. case 194:
  3865. return parent_1.expression === node;
  3866. case 187:
  3867. var forStatement = parent_1;
  3868. return (forStatement.initializer === node && forStatement.initializer.kind !== 200) ||
  3869. forStatement.condition === node ||
  3870. forStatement.incrementor === node;
  3871. case 188:
  3872. case 189:
  3873. var forInStatement = parent_1;
  3874. return (forInStatement.initializer === node && forInStatement.initializer.kind !== 200) ||
  3875. forInStatement.expression === node;
  3876. case 161:
  3877. return node === parent_1.expression;
  3878. case 178:
  3879. return node === parent_1.expression;
  3880. case 128:
  3881. return node === parent_1.expression;
  3882. case 131:
  3883. return true;
  3884. default:
  3885. if (isExpression(parent_1)) {
  3886. return true;
  3887. }
  3888. }
  3889. }
  3890. return false;
  3891. }
  3892. ts.isExpression = isExpression;
  3893. function isInstantiatedModule(node, preserveConstEnums) {
  3894. var moduleState = ts.getModuleInstanceState(node);
  3895. return moduleState === 1 ||
  3896. (preserveConstEnums && moduleState === 2);
  3897. }
  3898. ts.isInstantiatedModule = isInstantiatedModule;
  3899. function isExternalModuleImportEqualsDeclaration(node) {
  3900. return node.kind === 209 && node.moduleReference.kind === 220;
  3901. }
  3902. ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration;
  3903. function getExternalModuleImportEqualsDeclarationExpression(node) {
  3904. ts.Debug.assert(isExternalModuleImportEqualsDeclaration(node));
  3905. return node.moduleReference.expression;
  3906. }
  3907. ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
  3908. function isInternalModuleImportEqualsDeclaration(node) {
  3909. return node.kind === 209 && node.moduleReference.kind !== 220;
  3910. }
  3911. ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration;
  3912. function getExternalModuleName(node) {
  3913. if (node.kind === 210) {
  3914. return node.moduleSpecifier;
  3915. }
  3916. if (node.kind === 209) {
  3917. var reference = node.moduleReference;
  3918. if (reference.kind === 220) {
  3919. return reference.expression;
  3920. }
  3921. }
  3922. if (node.kind === 216) {
  3923. return node.moduleSpecifier;
  3924. }
  3925. }
  3926. ts.getExternalModuleName = getExternalModuleName;
  3927. function hasDotDotDotToken(node) {
  3928. return node && node.kind === 130 && node.dotDotDotToken !== undefined;
  3929. }
  3930. ts.hasDotDotDotToken = hasDotDotDotToken;
  3931. function hasQuestionToken(node) {
  3932. if (node) {
  3933. switch (node.kind) {
  3934. case 130:
  3935. return node.questionToken !== undefined;
  3936. case 135:
  3937. case 134:
  3938. return node.questionToken !== undefined;
  3939. case 226:
  3940. case 225:
  3941. case 133:
  3942. case 132:
  3943. return node.questionToken !== undefined;
  3944. }
  3945. }
  3946. return false;
  3947. }
  3948. ts.hasQuestionToken = hasQuestionToken;
  3949. function hasRestParameters(s) {
  3950. return s.parameters.length > 0 && ts.lastOrUndefined(s.parameters).dotDotDotToken !== undefined;
  3951. }
  3952. ts.hasRestParameters = hasRestParameters;
  3953. function isLiteralKind(kind) {
  3954. return 7 <= kind && kind <= 10;
  3955. }
  3956. ts.isLiteralKind = isLiteralKind;
  3957. function isTextualLiteralKind(kind) {
  3958. return kind === 8 || kind === 10;
  3959. }
  3960. ts.isTextualLiteralKind = isTextualLiteralKind;
  3961. function isTemplateLiteralKind(kind) {
  3962. return 10 <= kind && kind <= 13;
  3963. }
  3964. ts.isTemplateLiteralKind = isTemplateLiteralKind;
  3965. function isBindingPattern(node) {
  3966. return !!node && (node.kind === 152 || node.kind === 151);
  3967. }
  3968. ts.isBindingPattern = isBindingPattern;
  3969. function isInAmbientContext(node) {
  3970. while (node) {
  3971. if (node.flags & (2 | 2048)) {
  3972. return true;
  3973. }
  3974. node = node.parent;
  3975. }
  3976. return false;
  3977. }
  3978. ts.isInAmbientContext = isInAmbientContext;
  3979. function isDeclaration(node) {
  3980. switch (node.kind) {
  3981. case 164:
  3982. case 153:
  3983. case 202:
  3984. case 136:
  3985. case 205:
  3986. case 227:
  3987. case 218:
  3988. case 201:
  3989. case 163:
  3990. case 137:
  3991. case 211:
  3992. case 209:
  3993. case 214:
  3994. case 203:
  3995. case 135:
  3996. case 134:
  3997. case 206:
  3998. case 212:
  3999. case 130:
  4000. case 225:
  4001. case 133:
  4002. case 132:
  4003. case 138:
  4004. case 226:
  4005. case 204:
  4006. case 129:
  4007. case 199:
  4008. return true;
  4009. }
  4010. return false;
  4011. }
  4012. ts.isDeclaration = isDeclaration;
  4013. function isStatement(n) {
  4014. switch (n.kind) {
  4015. case 191:
  4016. case 190:
  4017. case 198:
  4018. case 185:
  4019. case 183:
  4020. case 182:
  4021. case 188:
  4022. case 189:
  4023. case 187:
  4024. case 184:
  4025. case 195:
  4026. case 192:
  4027. case 194:
  4028. case 94:
  4029. case 197:
  4030. case 181:
  4031. case 186:
  4032. case 193:
  4033. case 215:
  4034. return true;
  4035. default:
  4036. return false;
  4037. }
  4038. }
  4039. ts.isStatement = isStatement;
  4040. function isClassElement(n) {
  4041. switch (n.kind) {
  4042. case 136:
  4043. case 133:
  4044. case 135:
  4045. case 137:
  4046. case 138:
  4047. case 134:
  4048. case 141:
  4049. return true;
  4050. default:
  4051. return false;
  4052. }
  4053. }
  4054. ts.isClassElement = isClassElement;
  4055. function isDeclarationName(name) {
  4056. if (name.kind !== 65 && name.kind !== 8 && name.kind !== 7) {
  4057. return false;
  4058. }
  4059. var parent = name.parent;
  4060. if (parent.kind === 214 || parent.kind === 218) {
  4061. if (parent.propertyName) {
  4062. return true;
  4063. }
  4064. }
  4065. if (isDeclaration(parent)) {
  4066. return parent.name === name;
  4067. }
  4068. return false;
  4069. }
  4070. ts.isDeclarationName = isDeclarationName;
  4071. function isAliasSymbolDeclaration(node) {
  4072. return node.kind === 209 ||
  4073. node.kind === 211 && !!node.name ||
  4074. node.kind === 212 ||
  4075. node.kind === 214 ||
  4076. node.kind === 218 ||
  4077. node.kind === 215 && node.expression.kind === 65;
  4078. }
  4079. ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration;
  4080. function getClassExtendsHeritageClauseElement(node) {
  4081. var heritageClause = getHeritageClause(node.heritageClauses, 79);
  4082. return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined;
  4083. }
  4084. ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement;
  4085. function getClassImplementsHeritageClauseElements(node) {
  4086. var heritageClause = getHeritageClause(node.heritageClauses, 102);
  4087. return heritageClause ? heritageClause.types : undefined;
  4088. }
  4089. ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements;
  4090. function getInterfaceBaseTypeNodes(node) {
  4091. var heritageClause = getHeritageClause(node.heritageClauses, 79);
  4092. return heritageClause ? heritageClause.types : undefined;
  4093. }
  4094. ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes;
  4095. function getHeritageClause(clauses, kind) {
  4096. if (clauses) {
  4097. for (var _i = 0; _i < clauses.length; _i++) {
  4098. var clause = clauses[_i];
  4099. if (clause.token === kind) {
  4100. return clause;
  4101. }
  4102. }
  4103. }
  4104. return undefined;
  4105. }
  4106. ts.getHeritageClause = getHeritageClause;
  4107. function tryResolveScriptReference(host, sourceFile, reference) {
  4108. if (!host.getCompilerOptions().noResolve) {
  4109. var referenceFileName = ts.isRootedDiskPath(reference.fileName) ? reference.fileName : ts.combinePaths(ts.getDirectoryPath(sourceFile.fileName), reference.fileName);
  4110. referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory());
  4111. return host.getSourceFile(referenceFileName);
  4112. }
  4113. }
  4114. ts.tryResolveScriptReference = tryResolveScriptReference;
  4115. function getAncestor(node, kind) {
  4116. while (node) {
  4117. if (node.kind === kind) {
  4118. return node;
  4119. }
  4120. node = node.parent;
  4121. }
  4122. return undefined;
  4123. }
  4124. ts.getAncestor = getAncestor;
  4125. function getFileReferenceFromReferencePath(comment, commentRange) {
  4126. var simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim;
  4127. var isNoDefaultLibRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)('|")(.+?)\2\s*\/>/gim;
  4128. if (simpleReferenceRegEx.exec(comment)) {
  4129. if (isNoDefaultLibRegEx.exec(comment)) {
  4130. return {
  4131. isNoDefaultLib: true
  4132. };
  4133. }
  4134. else {
  4135. var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment);
  4136. if (matchResult) {
  4137. var start = commentRange.pos;
  4138. var end = commentRange.end;
  4139. return {
  4140. fileReference: {
  4141. pos: start,
  4142. end: end,
  4143. fileName: matchResult[3]
  4144. },
  4145. isNoDefaultLib: false
  4146. };
  4147. }
  4148. else {
  4149. return {
  4150. diagnosticMessage: ts.Diagnostics.Invalid_reference_directive_syntax,
  4151. isNoDefaultLib: false
  4152. };
  4153. }
  4154. }
  4155. }
  4156. return undefined;
  4157. }
  4158. ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath;
  4159. function isKeyword(token) {
  4160. return 66 <= token && token <= 126;
  4161. }
  4162. ts.isKeyword = isKeyword;
  4163. function isTrivia(token) {
  4164. return 2 <= token && token <= 6;
  4165. }
  4166. ts.isTrivia = isTrivia;
  4167. function hasDynamicName(declaration) {
  4168. return declaration.name &&
  4169. declaration.name.kind === 128 &&
  4170. !isWellKnownSymbolSyntactically(declaration.name.expression);
  4171. }
  4172. ts.hasDynamicName = hasDynamicName;
  4173. function isWellKnownSymbolSyntactically(node) {
  4174. return node.kind === 156 && isESSymbolIdentifier(node.expression);
  4175. }
  4176. ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically;
  4177. function getPropertyNameForPropertyNameNode(name) {
  4178. if (name.kind === 65 || name.kind === 8 || name.kind === 7) {
  4179. return name.text;
  4180. }
  4181. if (name.kind === 128) {
  4182. var nameExpression = name.expression;
  4183. if (isWellKnownSymbolSyntactically(nameExpression)) {
  4184. var rightHandSideName = nameExpression.name.text;
  4185. return getPropertyNameForKnownSymbolName(rightHandSideName);
  4186. }
  4187. }
  4188. return undefined;
  4189. }
  4190. ts.getPropertyNameForPropertyNameNode = getPropertyNameForPropertyNameNode;
  4191. function getPropertyNameForKnownSymbolName(symbolName) {
  4192. return "__@" + symbolName;
  4193. }
  4194. ts.getPropertyNameForKnownSymbolName = getPropertyNameForKnownSymbolName;
  4195. function isESSymbolIdentifier(node) {
  4196. return node.kind === 65 && node.text === "Symbol";
  4197. }
  4198. ts.isESSymbolIdentifier = isESSymbolIdentifier;
  4199. function isModifier(token) {
  4200. switch (token) {
  4201. case 108:
  4202. case 106:
  4203. case 107:
  4204. case 109:
  4205. case 78:
  4206. case 115:
  4207. case 70:
  4208. case 73:
  4209. return true;
  4210. }
  4211. return false;
  4212. }
  4213. ts.isModifier = isModifier;
  4214. function nodeStartsNewLexicalEnvironment(n) {
  4215. return isFunctionLike(n) || n.kind === 206 || n.kind === 228;
  4216. }
  4217. ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
  4218. function nodeIsSynthesized(node) {
  4219. return node.pos === -1;
  4220. }
  4221. ts.nodeIsSynthesized = nodeIsSynthesized;
  4222. function createSynthesizedNode(kind, startsOnNewLine) {
  4223. var node = ts.createNode(kind);
  4224. node.pos = -1;
  4225. node.end = -1;
  4226. node.startsOnNewLine = startsOnNewLine;
  4227. return node;
  4228. }
  4229. ts.createSynthesizedNode = createSynthesizedNode;
  4230. function createSynthesizedNodeArray() {
  4231. var array = [];
  4232. array.pos = -1;
  4233. array.end = -1;
  4234. return array;
  4235. }
  4236. ts.createSynthesizedNodeArray = createSynthesizedNodeArray;
  4237. function createDiagnosticCollection() {
  4238. var nonFileDiagnostics = [];
  4239. var fileDiagnostics = {};
  4240. var diagnosticsModified = false;
  4241. var modificationCount = 0;
  4242. return {
  4243. add: add,
  4244. getGlobalDiagnostics: getGlobalDiagnostics,
  4245. getDiagnostics: getDiagnostics,
  4246. getModificationCount: getModificationCount
  4247. };
  4248. function getModificationCount() {
  4249. return modificationCount;
  4250. }
  4251. function add(diagnostic) {
  4252. var diagnostics;
  4253. if (diagnostic.file) {
  4254. diagnostics = fileDiagnostics[diagnostic.file.fileName];
  4255. if (!diagnostics) {
  4256. diagnostics = [];
  4257. fileDiagnostics[diagnostic.file.fileName] = diagnostics;
  4258. }
  4259. }
  4260. else {
  4261. diagnostics = nonFileDiagnostics;
  4262. }
  4263. diagnostics.push(diagnostic);
  4264. diagnosticsModified = true;
  4265. modificationCount++;
  4266. }
  4267. function getGlobalDiagnostics() {
  4268. sortAndDeduplicate();
  4269. return nonFileDiagnostics;
  4270. }
  4271. function getDiagnostics(fileName) {
  4272. sortAndDeduplicate();
  4273. if (fileName) {
  4274. return fileDiagnostics[fileName] || [];
  4275. }
  4276. var allDiagnostics = [];
  4277. function pushDiagnostic(d) {
  4278. allDiagnostics.push(d);
  4279. }
  4280. ts.forEach(nonFileDiagnostics, pushDiagnostic);
  4281. for (var key in fileDiagnostics) {
  4282. if (ts.hasProperty(fileDiagnostics, key)) {
  4283. ts.forEach(fileDiagnostics[key], pushDiagnostic);
  4284. }
  4285. }
  4286. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  4287. }
  4288. function sortAndDeduplicate() {
  4289. if (!diagnosticsModified) {
  4290. return;
  4291. }
  4292. diagnosticsModified = false;
  4293. nonFileDiagnostics = ts.sortAndDeduplicateDiagnostics(nonFileDiagnostics);
  4294. for (var key in fileDiagnostics) {
  4295. if (ts.hasProperty(fileDiagnostics, key)) {
  4296. fileDiagnostics[key] = ts.sortAndDeduplicateDiagnostics(fileDiagnostics[key]);
  4297. }
  4298. }
  4299. }
  4300. }
  4301. ts.createDiagnosticCollection = createDiagnosticCollection;
  4302. var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
  4303. var escapedCharsMap = {
  4304. "\0": "\\0",
  4305. "\t": "\\t",
  4306. "\v": "\\v",
  4307. "\f": "\\f",
  4308. "\b": "\\b",
  4309. "\r": "\\r",
  4310. "\n": "\\n",
  4311. "\\": "\\\\",
  4312. "\"": "\\\"",
  4313. "\u2028": "\\u2028",
  4314. "\u2029": "\\u2029",
  4315. "\u0085": "\\u0085"
  4316. };
  4317. function escapeString(s) {
  4318. s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s;
  4319. return s;
  4320. function getReplacement(c) {
  4321. return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0));
  4322. }
  4323. }
  4324. ts.escapeString = escapeString;
  4325. function get16BitUnicodeEscapeSequence(charCode) {
  4326. var hexCharCode = charCode.toString(16).toUpperCase();
  4327. var paddedHexCode = ("0000" + hexCharCode).slice(-4);
  4328. return "\\u" + paddedHexCode;
  4329. }
  4330. var nonAsciiCharacters = /[^\u0000-\u007F]/g;
  4331. function escapeNonAsciiCharacters(s) {
  4332. return nonAsciiCharacters.test(s) ?
  4333. s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) :
  4334. s;
  4335. }
  4336. ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters;
  4337. var indentStrings = ["", " "];
  4338. function getIndentString(level) {
  4339. if (indentStrings[level] === undefined) {
  4340. indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
  4341. }
  4342. return indentStrings[level];
  4343. }
  4344. ts.getIndentString = getIndentString;
  4345. function getIndentSize() {
  4346. return indentStrings[1].length;
  4347. }
  4348. ts.getIndentSize = getIndentSize;
  4349. function createTextWriter(newLine) {
  4350. var output = "";
  4351. var indent = 0;
  4352. var lineStart = true;
  4353. var lineCount = 0;
  4354. var linePos = 0;
  4355. function write(s) {
  4356. if (s && s.length) {
  4357. if (lineStart) {
  4358. output += getIndentString(indent);
  4359. lineStart = false;
  4360. }
  4361. output += s;
  4362. }
  4363. }
  4364. function rawWrite(s) {
  4365. if (s !== undefined) {
  4366. if (lineStart) {
  4367. lineStart = false;
  4368. }
  4369. output += s;
  4370. }
  4371. }
  4372. function writeLiteral(s) {
  4373. if (s && s.length) {
  4374. write(s);
  4375. var lineStartsOfS = ts.computeLineStarts(s);
  4376. if (lineStartsOfS.length > 1) {
  4377. lineCount = lineCount + lineStartsOfS.length - 1;
  4378. linePos = output.length - s.length + ts.lastOrUndefined(lineStartsOfS);
  4379. }
  4380. }
  4381. }
  4382. function writeLine() {
  4383. if (!lineStart) {
  4384. output += newLine;
  4385. lineCount++;
  4386. linePos = output.length;
  4387. lineStart = true;
  4388. }
  4389. }
  4390. function writeTextOfNode(sourceFile, node) {
  4391. write(getSourceTextOfNodeFromSourceFile(sourceFile, node));
  4392. }
  4393. return {
  4394. write: write,
  4395. rawWrite: rawWrite,
  4396. writeTextOfNode: writeTextOfNode,
  4397. writeLiteral: writeLiteral,
  4398. writeLine: writeLine,
  4399. increaseIndent: function () { return indent++; },
  4400. decreaseIndent: function () { return indent--; },
  4401. getIndent: function () { return indent; },
  4402. getTextPos: function () { return output.length; },
  4403. getLine: function () { return lineCount + 1; },
  4404. getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
  4405. getText: function () { return output; }
  4406. };
  4407. }
  4408. ts.createTextWriter = createTextWriter;
  4409. function getOwnEmitOutputFilePath(sourceFile, host, extension) {
  4410. var compilerOptions = host.getCompilerOptions();
  4411. var emitOutputFilePathWithoutExtension;
  4412. if (compilerOptions.outDir) {
  4413. emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
  4414. }
  4415. else {
  4416. emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName);
  4417. }
  4418. return emitOutputFilePathWithoutExtension + extension;
  4419. }
  4420. ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath;
  4421. function getSourceFilePathInNewDir(sourceFile, host, newDirPath) {
  4422. var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory());
  4423. sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), "");
  4424. return ts.combinePaths(newDirPath, sourceFilePath);
  4425. }
  4426. ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir;
  4427. function writeFile(host, diagnostics, fileName, data, writeByteOrderMark) {
  4428. host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) {
  4429. diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
  4430. });
  4431. }
  4432. ts.writeFile = writeFile;
  4433. function getLineOfLocalPosition(currentSourceFile, pos) {
  4434. return ts.getLineAndCharacterOfPosition(currentSourceFile, pos).line;
  4435. }
  4436. ts.getLineOfLocalPosition = getLineOfLocalPosition;
  4437. function getFirstConstructorWithBody(node) {
  4438. return ts.forEach(node.members, function (member) {
  4439. if (member.kind === 136 && nodeIsPresent(member.body)) {
  4440. return member;
  4441. }
  4442. });
  4443. }
  4444. ts.getFirstConstructorWithBody = getFirstConstructorWithBody;
  4445. function shouldEmitToOwnFile(sourceFile, compilerOptions) {
  4446. if (!isDeclarationFile(sourceFile)) {
  4447. if ((isExternalModule(sourceFile) || !compilerOptions.out)) {
  4448. return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js");
  4449. }
  4450. return false;
  4451. }
  4452. return false;
  4453. }
  4454. ts.shouldEmitToOwnFile = shouldEmitToOwnFile;
  4455. function getAllAccessorDeclarations(declarations, accessor) {
  4456. var firstAccessor;
  4457. var secondAccessor;
  4458. var getAccessor;
  4459. var setAccessor;
  4460. if (hasDynamicName(accessor)) {
  4461. firstAccessor = accessor;
  4462. if (accessor.kind === 137) {
  4463. getAccessor = accessor;
  4464. }
  4465. else if (accessor.kind === 138) {
  4466. setAccessor = accessor;
  4467. }
  4468. else {
  4469. ts.Debug.fail("Accessor has wrong kind");
  4470. }
  4471. }
  4472. else {
  4473. ts.forEach(declarations, function (member) {
  4474. if ((member.kind === 137 || member.kind === 138)
  4475. && (member.flags & 128) === (accessor.flags & 128)) {
  4476. var memberName = getPropertyNameForPropertyNameNode(member.name);
  4477. var accessorName = getPropertyNameForPropertyNameNode(accessor.name);
  4478. if (memberName === accessorName) {
  4479. if (!firstAccessor) {
  4480. firstAccessor = member;
  4481. }
  4482. else if (!secondAccessor) {
  4483. secondAccessor = member;
  4484. }
  4485. if (member.kind === 137 && !getAccessor) {
  4486. getAccessor = member;
  4487. }
  4488. if (member.kind === 138 && !setAccessor) {
  4489. setAccessor = member;
  4490. }
  4491. }
  4492. }
  4493. });
  4494. }
  4495. return {
  4496. firstAccessor: firstAccessor,
  4497. secondAccessor: secondAccessor,
  4498. getAccessor: getAccessor,
  4499. setAccessor: setAccessor
  4500. };
  4501. }
  4502. ts.getAllAccessorDeclarations = getAllAccessorDeclarations;
  4503. function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) {
  4504. if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
  4505. getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
  4506. writer.writeLine();
  4507. }
  4508. }
  4509. ts.emitNewLineBeforeLeadingComments = emitNewLineBeforeLeadingComments;
  4510. function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) {
  4511. var emitLeadingSpace = !trailingSeparator;
  4512. ts.forEach(comments, function (comment) {
  4513. if (emitLeadingSpace) {
  4514. writer.write(" ");
  4515. emitLeadingSpace = false;
  4516. }
  4517. writeComment(currentSourceFile, writer, comment, newLine);
  4518. if (comment.hasTrailingNewLine) {
  4519. writer.writeLine();
  4520. }
  4521. else if (trailingSeparator) {
  4522. writer.write(" ");
  4523. }
  4524. else {
  4525. emitLeadingSpace = true;
  4526. }
  4527. });
  4528. }
  4529. ts.emitComments = emitComments;
  4530. function writeCommentRange(currentSourceFile, writer, comment, newLine) {
  4531. if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42) {
  4532. var firstCommentLineAndCharacter = ts.getLineAndCharacterOfPosition(currentSourceFile, comment.pos);
  4533. var lineCount = ts.getLineStarts(currentSourceFile).length;
  4534. var firstCommentLineIndent;
  4535. for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
  4536. var nextLineStart = (currentLine + 1) === lineCount
  4537. ? currentSourceFile.text.length + 1
  4538. : getStartPositionOfLine(currentLine + 1, currentSourceFile);
  4539. if (pos !== comment.pos) {
  4540. if (firstCommentLineIndent === undefined) {
  4541. firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos);
  4542. }
  4543. var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
  4544. var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
  4545. if (spacesToEmit > 0) {
  4546. var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
  4547. var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
  4548. writer.rawWrite(indentSizeSpaceString);
  4549. while (numberOfSingleSpacesToEmit) {
  4550. writer.rawWrite(" ");
  4551. numberOfSingleSpacesToEmit--;
  4552. }
  4553. }
  4554. else {
  4555. writer.rawWrite("");
  4556. }
  4557. }
  4558. writeTrimmedCurrentLine(pos, nextLineStart);
  4559. pos = nextLineStart;
  4560. }
  4561. }
  4562. else {
  4563. writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
  4564. }
  4565. function writeTrimmedCurrentLine(pos, nextLineStart) {
  4566. var end = Math.min(comment.end, nextLineStart - 1);
  4567. var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, '');
  4568. if (currentLineText) {
  4569. writer.write(currentLineText);
  4570. if (end !== comment.end) {
  4571. writer.writeLine();
  4572. }
  4573. }
  4574. else {
  4575. writer.writeLiteral(newLine);
  4576. }
  4577. }
  4578. function calculateIndent(pos, end) {
  4579. var currentLineIndent = 0;
  4580. for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
  4581. if (currentSourceFile.text.charCodeAt(pos) === 9) {
  4582. currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
  4583. }
  4584. else {
  4585. currentLineIndent++;
  4586. }
  4587. }
  4588. return currentLineIndent;
  4589. }
  4590. }
  4591. ts.writeCommentRange = writeCommentRange;
  4592. function modifierToFlag(token) {
  4593. switch (token) {
  4594. case 109: return 128;
  4595. case 108: return 16;
  4596. case 107: return 64;
  4597. case 106: return 32;
  4598. case 78: return 1;
  4599. case 115: return 2;
  4600. case 70: return 8192;
  4601. case 73: return 256;
  4602. }
  4603. return 0;
  4604. }
  4605. ts.modifierToFlag = modifierToFlag;
  4606. function isLeftHandSideExpression(expr) {
  4607. if (expr) {
  4608. switch (expr.kind) {
  4609. case 156:
  4610. case 157:
  4611. case 159:
  4612. case 158:
  4613. case 160:
  4614. case 154:
  4615. case 162:
  4616. case 155:
  4617. case 175:
  4618. case 163:
  4619. case 65:
  4620. case 9:
  4621. case 7:
  4622. case 8:
  4623. case 10:
  4624. case 172:
  4625. case 80:
  4626. case 89:
  4627. case 93:
  4628. case 95:
  4629. case 91:
  4630. return true;
  4631. }
  4632. }
  4633. return false;
  4634. }
  4635. ts.isLeftHandSideExpression = isLeftHandSideExpression;
  4636. function isAssignmentOperator(token) {
  4637. return token >= 53 && token <= 64;
  4638. }
  4639. ts.isAssignmentOperator = isAssignmentOperator;
  4640. function isSupportedExpressionWithTypeArguments(node) {
  4641. return isSupportedExpressionWithTypeArgumentsRest(node.expression);
  4642. }
  4643. ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments;
  4644. function isSupportedExpressionWithTypeArgumentsRest(node) {
  4645. if (node.kind === 65) {
  4646. return true;
  4647. }
  4648. else if (node.kind === 156) {
  4649. return isSupportedExpressionWithTypeArgumentsRest(node.expression);
  4650. }
  4651. else {
  4652. return false;
  4653. }
  4654. }
  4655. function isRightSideOfQualifiedNameOrPropertyAccess(node) {
  4656. return (node.parent.kind === 127 && node.parent.right === node) ||
  4657. (node.parent.kind === 156 && node.parent.name === node);
  4658. }
  4659. ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess;
  4660. function getLocalSymbolForExportDefault(symbol) {
  4661. return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 256) ? symbol.valueDeclaration.localSymbol : undefined;
  4662. }
  4663. ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault;
  4664. function getExpandedCharCodes(input) {
  4665. var output = [];
  4666. var length = input.length;
  4667. var leadSurrogate = undefined;
  4668. for (var i = 0; i < length; i++) {
  4669. var charCode = input.charCodeAt(i);
  4670. if (charCode < 0x80) {
  4671. output.push(charCode);
  4672. }
  4673. else if (charCode < 0x800) {
  4674. output.push((charCode >> 6) | 192);
  4675. output.push((charCode & 63) | 128);
  4676. }
  4677. else if (charCode < 0x10000) {
  4678. output.push((charCode >> 12) | 224);
  4679. output.push(((charCode >> 6) & 63) | 128);
  4680. output.push((charCode & 63) | 128);
  4681. }
  4682. else if (charCode < 0x20000) {
  4683. output.push((charCode >> 18) | 240);
  4684. output.push(((charCode >> 12) & 63) | 128);
  4685. output.push(((charCode >> 6) & 63) | 128);
  4686. output.push((charCode & 63) | 128);
  4687. }
  4688. else {
  4689. ts.Debug.assert(false, "Unexpected code point");
  4690. }
  4691. }
  4692. return output;
  4693. }
  4694. var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  4695. function convertToBase64(input) {
  4696. var result = "";
  4697. var charCodes = getExpandedCharCodes(input);
  4698. var i = 0;
  4699. var length = charCodes.length;
  4700. var byte1, byte2, byte3, byte4;
  4701. while (i < length) {
  4702. byte1 = charCodes[i] >> 2;
  4703. byte2 = (charCodes[i] & 3) << 4 | charCodes[i + 1] >> 4;
  4704. byte3 = (charCodes[i + 1] & 15) << 2 | charCodes[i + 2] >> 6;
  4705. byte4 = charCodes[i + 2] & 63;
  4706. if (i + 1 >= length) {
  4707. byte3 = byte4 = 64;
  4708. }
  4709. else if (i + 2 >= length) {
  4710. byte4 = 64;
  4711. }
  4712. result += base64Digits.charAt(byte1) + base64Digits.charAt(byte2) + base64Digits.charAt(byte3) + base64Digits.charAt(byte4);
  4713. i += 3;
  4714. }
  4715. return result;
  4716. }
  4717. ts.convertToBase64 = convertToBase64;
  4718. var carriageReturnLineFeed = "\r\n";
  4719. var lineFeed = "\n";
  4720. function getNewLineCharacter(options) {
  4721. if (options.newLine === 0) {
  4722. return carriageReturnLineFeed;
  4723. }
  4724. else if (options.newLine === 1) {
  4725. return lineFeed;
  4726. }
  4727. else if (ts.sys) {
  4728. return ts.sys.newLine;
  4729. }
  4730. return carriageReturnLineFeed;
  4731. }
  4732. ts.getNewLineCharacter = getNewLineCharacter;
  4733. })(ts || (ts = {}));
  4734. var ts;
  4735. (function (ts) {
  4736. function getDefaultLibFileName(options) {
  4737. return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts";
  4738. }
  4739. ts.getDefaultLibFileName = getDefaultLibFileName;
  4740. function textSpanEnd(span) {
  4741. return span.start + span.length;
  4742. }
  4743. ts.textSpanEnd = textSpanEnd;
  4744. function textSpanIsEmpty(span) {
  4745. return span.length === 0;
  4746. }
  4747. ts.textSpanIsEmpty = textSpanIsEmpty;
  4748. function textSpanContainsPosition(span, position) {
  4749. return position >= span.start && position < textSpanEnd(span);
  4750. }
  4751. ts.textSpanContainsPosition = textSpanContainsPosition;
  4752. function textSpanContainsTextSpan(span, other) {
  4753. return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span);
  4754. }
  4755. ts.textSpanContainsTextSpan = textSpanContainsTextSpan;
  4756. function textSpanOverlapsWith(span, other) {
  4757. var overlapStart = Math.max(span.start, other.start);
  4758. var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other));
  4759. return overlapStart < overlapEnd;
  4760. }
  4761. ts.textSpanOverlapsWith = textSpanOverlapsWith;
  4762. function textSpanOverlap(span1, span2) {
  4763. var overlapStart = Math.max(span1.start, span2.start);
  4764. var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
  4765. if (overlapStart < overlapEnd) {
  4766. return createTextSpanFromBounds(overlapStart, overlapEnd);
  4767. }
  4768. return undefined;
  4769. }
  4770. ts.textSpanOverlap = textSpanOverlap;
  4771. function textSpanIntersectsWithTextSpan(span, other) {
  4772. return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start;
  4773. }
  4774. ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan;
  4775. function textSpanIntersectsWith(span, start, length) {
  4776. var end = start + length;
  4777. return start <= textSpanEnd(span) && end >= span.start;
  4778. }
  4779. ts.textSpanIntersectsWith = textSpanIntersectsWith;
  4780. function textSpanIntersectsWithPosition(span, position) {
  4781. return position <= textSpanEnd(span) && position >= span.start;
  4782. }
  4783. ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition;
  4784. function textSpanIntersection(span1, span2) {
  4785. var intersectStart = Math.max(span1.start, span2.start);
  4786. var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
  4787. if (intersectStart <= intersectEnd) {
  4788. return createTextSpanFromBounds(intersectStart, intersectEnd);
  4789. }
  4790. return undefined;
  4791. }
  4792. ts.textSpanIntersection = textSpanIntersection;
  4793. function createTextSpan(start, length) {
  4794. if (start < 0) {
  4795. throw new Error("start < 0");
  4796. }
  4797. if (length < 0) {
  4798. throw new Error("length < 0");
  4799. }
  4800. return { start: start, length: length };
  4801. }
  4802. ts.createTextSpan = createTextSpan;
  4803. function createTextSpanFromBounds(start, end) {
  4804. return createTextSpan(start, end - start);
  4805. }
  4806. ts.createTextSpanFromBounds = createTextSpanFromBounds;
  4807. function textChangeRangeNewSpan(range) {
  4808. return createTextSpan(range.span.start, range.newLength);
  4809. }
  4810. ts.textChangeRangeNewSpan = textChangeRangeNewSpan;
  4811. function textChangeRangeIsUnchanged(range) {
  4812. return textSpanIsEmpty(range.span) && range.newLength === 0;
  4813. }
  4814. ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged;
  4815. function createTextChangeRange(span, newLength) {
  4816. if (newLength < 0) {
  4817. throw new Error("newLength < 0");
  4818. }
  4819. return { span: span, newLength: newLength };
  4820. }
  4821. ts.createTextChangeRange = createTextChangeRange;
  4822. ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
  4823. function collapseTextChangeRangesAcrossMultipleVersions(changes) {
  4824. if (changes.length === 0) {
  4825. return ts.unchangedTextChangeRange;
  4826. }
  4827. if (changes.length === 1) {
  4828. return changes[0];
  4829. }
  4830. var change0 = changes[0];
  4831. var oldStartN = change0.span.start;
  4832. var oldEndN = textSpanEnd(change0.span);
  4833. var newEndN = oldStartN + change0.newLength;
  4834. for (var i = 1; i < changes.length; i++) {
  4835. var nextChange = changes[i];
  4836. var oldStart1 = oldStartN;
  4837. var oldEnd1 = oldEndN;
  4838. var newEnd1 = newEndN;
  4839. var oldStart2 = nextChange.span.start;
  4840. var oldEnd2 = textSpanEnd(nextChange.span);
  4841. var newEnd2 = oldStart2 + nextChange.newLength;
  4842. oldStartN = Math.min(oldStart1, oldStart2);
  4843. oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1));
  4844. newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2));
  4845. }
  4846. return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN);
  4847. }
  4848. ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions;
  4849. })(ts || (ts = {}));
  4850. /// <reference path="scanner.ts"/>
  4851. /// <reference path="utilities.ts"/>
  4852. var ts;
  4853. (function (ts) {
  4854. var nodeConstructors = new Array(230);
  4855. ts.parseTime = 0;
  4856. function getNodeConstructor(kind) {
  4857. return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind));
  4858. }
  4859. ts.getNodeConstructor = getNodeConstructor;
  4860. function createNode(kind) {
  4861. return new (getNodeConstructor(kind))();
  4862. }
  4863. ts.createNode = createNode;
  4864. function visitNode(cbNode, node) {
  4865. if (node) {
  4866. return cbNode(node);
  4867. }
  4868. }
  4869. function visitNodeArray(cbNodes, nodes) {
  4870. if (nodes) {
  4871. return cbNodes(nodes);
  4872. }
  4873. }
  4874. function visitEachNode(cbNode, nodes) {
  4875. if (nodes) {
  4876. for (var _i = 0; _i < nodes.length; _i++) {
  4877. var node = nodes[_i];
  4878. var result = cbNode(node);
  4879. if (result) {
  4880. return result;
  4881. }
  4882. }
  4883. }
  4884. }
  4885. function forEachChild(node, cbNode, cbNodeArray) {
  4886. if (!node) {
  4887. return;
  4888. }
  4889. var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode;
  4890. var cbNodes = cbNodeArray || cbNode;
  4891. switch (node.kind) {
  4892. case 127:
  4893. return visitNode(cbNode, node.left) ||
  4894. visitNode(cbNode, node.right);
  4895. case 129:
  4896. return visitNode(cbNode, node.name) ||
  4897. visitNode(cbNode, node.constraint) ||
  4898. visitNode(cbNode, node.expression);
  4899. case 130:
  4900. case 133:
  4901. case 132:
  4902. case 225:
  4903. case 226:
  4904. case 199:
  4905. case 153:
  4906. return visitNodes(cbNodes, node.decorators) ||
  4907. visitNodes(cbNodes, node.modifiers) ||
  4908. visitNode(cbNode, node.propertyName) ||
  4909. visitNode(cbNode, node.dotDotDotToken) ||
  4910. visitNode(cbNode, node.name) ||
  4911. visitNode(cbNode, node.questionToken) ||
  4912. visitNode(cbNode, node.type) ||
  4913. visitNode(cbNode, node.initializer);
  4914. case 143:
  4915. case 144:
  4916. case 139:
  4917. case 140:
  4918. case 141:
  4919. return visitNodes(cbNodes, node.decorators) ||
  4920. visitNodes(cbNodes, node.modifiers) ||
  4921. visitNodes(cbNodes, node.typeParameters) ||
  4922. visitNodes(cbNodes, node.parameters) ||
  4923. visitNode(cbNode, node.type);
  4924. case 135:
  4925. case 134:
  4926. case 136:
  4927. case 137:
  4928. case 138:
  4929. case 163:
  4930. case 201:
  4931. case 164:
  4932. return visitNodes(cbNodes, node.decorators) ||
  4933. visitNodes(cbNodes, node.modifiers) ||
  4934. visitNode(cbNode, node.asteriskToken) ||
  4935. visitNode(cbNode, node.name) ||
  4936. visitNode(cbNode, node.questionToken) ||
  4937. visitNodes(cbNodes, node.typeParameters) ||
  4938. visitNodes(cbNodes, node.parameters) ||
  4939. visitNode(cbNode, node.type) ||
  4940. visitNode(cbNode, node.equalsGreaterThanToken) ||
  4941. visitNode(cbNode, node.body);
  4942. case 142:
  4943. return visitNode(cbNode, node.typeName) ||
  4944. visitNodes(cbNodes, node.typeArguments);
  4945. case 145:
  4946. return visitNode(cbNode, node.exprName);
  4947. case 146:
  4948. return visitNodes(cbNodes, node.members);
  4949. case 147:
  4950. return visitNode(cbNode, node.elementType);
  4951. case 148:
  4952. return visitNodes(cbNodes, node.elementTypes);
  4953. case 149:
  4954. return visitNodes(cbNodes, node.types);
  4955. case 150:
  4956. return visitNode(cbNode, node.type);
  4957. case 151:
  4958. case 152:
  4959. return visitNodes(cbNodes, node.elements);
  4960. case 154:
  4961. return visitNodes(cbNodes, node.elements);
  4962. case 155:
  4963. return visitNodes(cbNodes, node.properties);
  4964. case 156:
  4965. return visitNode(cbNode, node.expression) ||
  4966. visitNode(cbNode, node.dotToken) ||
  4967. visitNode(cbNode, node.name);
  4968. case 157:
  4969. return visitNode(cbNode, node.expression) ||
  4970. visitNode(cbNode, node.argumentExpression);
  4971. case 158:
  4972. case 159:
  4973. return visitNode(cbNode, node.expression) ||
  4974. visitNodes(cbNodes, node.typeArguments) ||
  4975. visitNodes(cbNodes, node.arguments);
  4976. case 160:
  4977. return visitNode(cbNode, node.tag) ||
  4978. visitNode(cbNode, node.template);
  4979. case 161:
  4980. return visitNode(cbNode, node.type) ||
  4981. visitNode(cbNode, node.expression);
  4982. case 162:
  4983. return visitNode(cbNode, node.expression);
  4984. case 165:
  4985. return visitNode(cbNode, node.expression);
  4986. case 166:
  4987. return visitNode(cbNode, node.expression);
  4988. case 167:
  4989. return visitNode(cbNode, node.expression);
  4990. case 168:
  4991. return visitNode(cbNode, node.operand);
  4992. case 173:
  4993. return visitNode(cbNode, node.asteriskToken) ||
  4994. visitNode(cbNode, node.expression);
  4995. case 169:
  4996. return visitNode(cbNode, node.operand);
  4997. case 170:
  4998. return visitNode(cbNode, node.left) ||
  4999. visitNode(cbNode, node.operatorToken) ||
  5000. visitNode(cbNode, node.right);
  5001. case 171:
  5002. return visitNode(cbNode, node.condition) ||
  5003. visitNode(cbNode, node.questionToken) ||
  5004. visitNode(cbNode, node.whenTrue) ||
  5005. visitNode(cbNode, node.colonToken) ||
  5006. visitNode(cbNode, node.whenFalse);
  5007. case 174:
  5008. return visitNode(cbNode, node.expression);
  5009. case 180:
  5010. case 207:
  5011. return visitNodes(cbNodes, node.statements);
  5012. case 228:
  5013. return visitNodes(cbNodes, node.statements) ||
  5014. visitNode(cbNode, node.endOfFileToken);
  5015. case 181:
  5016. return visitNodes(cbNodes, node.decorators) ||
  5017. visitNodes(cbNodes, node.modifiers) ||
  5018. visitNode(cbNode, node.declarationList);
  5019. case 200:
  5020. return visitNodes(cbNodes, node.declarations);
  5021. case 183:
  5022. return visitNode(cbNode, node.expression);
  5023. case 184:
  5024. return visitNode(cbNode, node.expression) ||
  5025. visitNode(cbNode, node.thenStatement) ||
  5026. visitNode(cbNode, node.elseStatement);
  5027. case 185:
  5028. return visitNode(cbNode, node.statement) ||
  5029. visitNode(cbNode, node.expression);
  5030. case 186:
  5031. return visitNode(cbNode, node.expression) ||
  5032. visitNode(cbNode, node.statement);
  5033. case 187:
  5034. return visitNode(cbNode, node.initializer) ||
  5035. visitNode(cbNode, node.condition) ||
  5036. visitNode(cbNode, node.incrementor) ||
  5037. visitNode(cbNode, node.statement);
  5038. case 188:
  5039. return visitNode(cbNode, node.initializer) ||
  5040. visitNode(cbNode, node.expression) ||
  5041. visitNode(cbNode, node.statement);
  5042. case 189:
  5043. return visitNode(cbNode, node.initializer) ||
  5044. visitNode(cbNode, node.expression) ||
  5045. visitNode(cbNode, node.statement);
  5046. case 190:
  5047. case 191:
  5048. return visitNode(cbNode, node.label);
  5049. case 192:
  5050. return visitNode(cbNode, node.expression);
  5051. case 193:
  5052. return visitNode(cbNode, node.expression) ||
  5053. visitNode(cbNode, node.statement);
  5054. case 194:
  5055. return visitNode(cbNode, node.expression) ||
  5056. visitNode(cbNode, node.caseBlock);
  5057. case 208:
  5058. return visitNodes(cbNodes, node.clauses);
  5059. case 221:
  5060. return visitNode(cbNode, node.expression) ||
  5061. visitNodes(cbNodes, node.statements);
  5062. case 222:
  5063. return visitNodes(cbNodes, node.statements);
  5064. case 195:
  5065. return visitNode(cbNode, node.label) ||
  5066. visitNode(cbNode, node.statement);
  5067. case 196:
  5068. return visitNode(cbNode, node.expression);
  5069. case 197:
  5070. return visitNode(cbNode, node.tryBlock) ||
  5071. visitNode(cbNode, node.catchClause) ||
  5072. visitNode(cbNode, node.finallyBlock);
  5073. case 224:
  5074. return visitNode(cbNode, node.variableDeclaration) ||
  5075. visitNode(cbNode, node.block);
  5076. case 131:
  5077. return visitNode(cbNode, node.expression);
  5078. case 202:
  5079. case 175:
  5080. return visitNodes(cbNodes, node.decorators) ||
  5081. visitNodes(cbNodes, node.modifiers) ||
  5082. visitNode(cbNode, node.name) ||
  5083. visitNodes(cbNodes, node.typeParameters) ||
  5084. visitNodes(cbNodes, node.heritageClauses) ||
  5085. visitNodes(cbNodes, node.members);
  5086. case 203:
  5087. return visitNodes(cbNodes, node.decorators) ||
  5088. visitNodes(cbNodes, node.modifiers) ||
  5089. visitNode(cbNode, node.name) ||
  5090. visitNodes(cbNodes, node.typeParameters) ||
  5091. visitNodes(cbNodes, node.heritageClauses) ||
  5092. visitNodes(cbNodes, node.members);
  5093. case 204:
  5094. return visitNodes(cbNodes, node.decorators) ||
  5095. visitNodes(cbNodes, node.modifiers) ||
  5096. visitNode(cbNode, node.name) ||
  5097. visitNode(cbNode, node.type);
  5098. case 205:
  5099. return visitNodes(cbNodes, node.decorators) ||
  5100. visitNodes(cbNodes, node.modifiers) ||
  5101. visitNode(cbNode, node.name) ||
  5102. visitNodes(cbNodes, node.members);
  5103. case 227:
  5104. return visitNode(cbNode, node.name) ||
  5105. visitNode(cbNode, node.initializer);
  5106. case 206:
  5107. return visitNodes(cbNodes, node.decorators) ||
  5108. visitNodes(cbNodes, node.modifiers) ||
  5109. visitNode(cbNode, node.name) ||
  5110. visitNode(cbNode, node.body);
  5111. case 209:
  5112. return visitNodes(cbNodes, node.decorators) ||
  5113. visitNodes(cbNodes, node.modifiers) ||
  5114. visitNode(cbNode, node.name) ||
  5115. visitNode(cbNode, node.moduleReference);
  5116. case 210:
  5117. return visitNodes(cbNodes, node.decorators) ||
  5118. visitNodes(cbNodes, node.modifiers) ||
  5119. visitNode(cbNode, node.importClause) ||
  5120. visitNode(cbNode, node.moduleSpecifier);
  5121. case 211:
  5122. return visitNode(cbNode, node.name) ||
  5123. visitNode(cbNode, node.namedBindings);
  5124. case 212:
  5125. return visitNode(cbNode, node.name);
  5126. case 213:
  5127. case 217:
  5128. return visitNodes(cbNodes, node.elements);
  5129. case 216:
  5130. return visitNodes(cbNodes, node.decorators) ||
  5131. visitNodes(cbNodes, node.modifiers) ||
  5132. visitNode(cbNode, node.exportClause) ||
  5133. visitNode(cbNode, node.moduleSpecifier);
  5134. case 214:
  5135. case 218:
  5136. return visitNode(cbNode, node.propertyName) ||
  5137. visitNode(cbNode, node.name);
  5138. case 215:
  5139. return visitNodes(cbNodes, node.decorators) ||
  5140. visitNodes(cbNodes, node.modifiers) ||
  5141. visitNode(cbNode, node.expression);
  5142. case 172:
  5143. return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans);
  5144. case 178:
  5145. return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal);
  5146. case 128:
  5147. return visitNode(cbNode, node.expression);
  5148. case 223:
  5149. return visitNodes(cbNodes, node.types);
  5150. case 177:
  5151. return visitNode(cbNode, node.expression) ||
  5152. visitNodes(cbNodes, node.typeArguments);
  5153. case 220:
  5154. return visitNode(cbNode, node.expression);
  5155. case 219:
  5156. return visitNodes(cbNodes, node.decorators);
  5157. }
  5158. }
  5159. ts.forEachChild = forEachChild;
  5160. function createSourceFile(fileName, sourceText, languageVersion, setParentNodes) {
  5161. if (setParentNodes === void 0) { setParentNodes = false; }
  5162. var start = new Date().getTime();
  5163. var result = Parser.parseSourceFile(fileName, sourceText, languageVersion, undefined, setParentNodes);
  5164. ts.parseTime += new Date().getTime() - start;
  5165. return result;
  5166. }
  5167. ts.createSourceFile = createSourceFile;
  5168. function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
  5169. return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
  5170. }
  5171. ts.updateSourceFile = updateSourceFile;
  5172. var Parser;
  5173. (function (Parser) {
  5174. var scanner = ts.createScanner(2, true);
  5175. var disallowInAndDecoratorContext = 2 | 16;
  5176. var sourceFile;
  5177. var syntaxCursor;
  5178. var token;
  5179. var sourceText;
  5180. var nodeCount;
  5181. var identifiers;
  5182. var identifierCount;
  5183. var parsingContext;
  5184. var contextFlags = 0;
  5185. var parseErrorBeforeNextFinishedNode = false;
  5186. function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) {
  5187. sourceText = _sourceText;
  5188. syntaxCursor = _syntaxCursor;
  5189. parsingContext = 0;
  5190. identifiers = {};
  5191. identifierCount = 0;
  5192. nodeCount = 0;
  5193. contextFlags = 0;
  5194. parseErrorBeforeNextFinishedNode = false;
  5195. createSourceFile(fileName, languageVersion);
  5196. scanner.setText(sourceText);
  5197. scanner.setOnError(scanError);
  5198. scanner.setScriptTarget(languageVersion);
  5199. token = nextToken();
  5200. processReferenceComments(sourceFile);
  5201. sourceFile.statements = parseList(0, true, parseSourceElement);
  5202. ts.Debug.assert(token === 1);
  5203. sourceFile.endOfFileToken = parseTokenNode();
  5204. setExternalModuleIndicator(sourceFile);
  5205. sourceFile.nodeCount = nodeCount;
  5206. sourceFile.identifierCount = identifierCount;
  5207. sourceFile.identifiers = identifiers;
  5208. if (setParentNodes) {
  5209. fixupParentReferences(sourceFile);
  5210. }
  5211. syntaxCursor = undefined;
  5212. scanner.setText("");
  5213. scanner.setOnError(undefined);
  5214. var result = sourceFile;
  5215. sourceFile = undefined;
  5216. identifiers = undefined;
  5217. syntaxCursor = undefined;
  5218. sourceText = undefined;
  5219. return result;
  5220. }
  5221. Parser.parseSourceFile = parseSourceFile;
  5222. function fixupParentReferences(sourceFile) {
  5223. // normally parent references are set during binding. However, for clients that only need
  5224. // a syntax tree, and no semantic features, then the binding process is an unnecessary
  5225. // overhead. This functions allows us to set all the parents, without all the expense of
  5226. // binding.
  5227. var parent = sourceFile;
  5228. forEachChild(sourceFile, visitNode);
  5229. return;
  5230. function visitNode(n) {
  5231. if (n.parent !== parent) {
  5232. n.parent = parent;
  5233. var saveParent = parent;
  5234. parent = n;
  5235. forEachChild(n, visitNode);
  5236. parent = saveParent;
  5237. }
  5238. }
  5239. }
  5240. function createSourceFile(fileName, languageVersion) {
  5241. sourceFile = createNode(228, 0);
  5242. sourceFile.pos = 0;
  5243. sourceFile.end = sourceText.length;
  5244. sourceFile.text = sourceText;
  5245. sourceFile.parseDiagnostics = [];
  5246. sourceFile.bindDiagnostics = [];
  5247. sourceFile.languageVersion = languageVersion;
  5248. sourceFile.fileName = ts.normalizePath(fileName);
  5249. sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 : 0;
  5250. }
  5251. function setContextFlag(val, flag) {
  5252. if (val) {
  5253. contextFlags |= flag;
  5254. }
  5255. else {
  5256. contextFlags &= ~flag;
  5257. }
  5258. }
  5259. function setStrictModeContext(val) {
  5260. setContextFlag(val, 1);
  5261. }
  5262. function setDisallowInContext(val) {
  5263. setContextFlag(val, 2);
  5264. }
  5265. function setYieldContext(val) {
  5266. setContextFlag(val, 4);
  5267. }
  5268. function setGeneratorParameterContext(val) {
  5269. setContextFlag(val, 8);
  5270. }
  5271. function setDecoratorContext(val) {
  5272. setContextFlag(val, 16);
  5273. }
  5274. function doOutsideOfContext(flags, func) {
  5275. var currentContextFlags = contextFlags & flags;
  5276. if (currentContextFlags) {
  5277. setContextFlag(false, currentContextFlags);
  5278. var result = func();
  5279. setContextFlag(true, currentContextFlags);
  5280. return result;
  5281. }
  5282. return func();
  5283. }
  5284. function allowInAnd(func) {
  5285. if (contextFlags & 2) {
  5286. setDisallowInContext(false);
  5287. var result = func();
  5288. setDisallowInContext(true);
  5289. return result;
  5290. }
  5291. return func();
  5292. }
  5293. function disallowInAnd(func) {
  5294. if (contextFlags & 2) {
  5295. return func();
  5296. }
  5297. setDisallowInContext(true);
  5298. var result = func();
  5299. setDisallowInContext(false);
  5300. return result;
  5301. }
  5302. function doInYieldContext(func) {
  5303. if (contextFlags & 4) {
  5304. return func();
  5305. }
  5306. setYieldContext(true);
  5307. var result = func();
  5308. setYieldContext(false);
  5309. return result;
  5310. }
  5311. function doOutsideOfYieldContext(func) {
  5312. if (contextFlags & 4) {
  5313. setYieldContext(false);
  5314. var result = func();
  5315. setYieldContext(true);
  5316. return result;
  5317. }
  5318. return func();
  5319. }
  5320. function doInDecoratorContext(func) {
  5321. if (contextFlags & 16) {
  5322. return func();
  5323. }
  5324. setDecoratorContext(true);
  5325. var result = func();
  5326. setDecoratorContext(false);
  5327. return result;
  5328. }
  5329. function inYieldContext() {
  5330. return (contextFlags & 4) !== 0;
  5331. }
  5332. function inStrictModeContext() {
  5333. return (contextFlags & 1) !== 0;
  5334. }
  5335. function inGeneratorParameterContext() {
  5336. return (contextFlags & 8) !== 0;
  5337. }
  5338. function inDisallowInContext() {
  5339. return (contextFlags & 2) !== 0;
  5340. }
  5341. function inDecoratorContext() {
  5342. return (contextFlags & 16) !== 0;
  5343. }
  5344. function parseErrorAtCurrentToken(message, arg0) {
  5345. var start = scanner.getTokenPos();
  5346. var length = scanner.getTextPos() - start;
  5347. parseErrorAtPosition(start, length, message, arg0);
  5348. }
  5349. function parseErrorAtPosition(start, length, message, arg0) {
  5350. var lastError = ts.lastOrUndefined(sourceFile.parseDiagnostics);
  5351. if (!lastError || start !== lastError.start) {
  5352. sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0));
  5353. }
  5354. parseErrorBeforeNextFinishedNode = true;
  5355. }
  5356. function scanError(message, length) {
  5357. var pos = scanner.getTextPos();
  5358. parseErrorAtPosition(pos, length || 0, message);
  5359. }
  5360. function getNodePos() {
  5361. return scanner.getStartPos();
  5362. }
  5363. function getNodeEnd() {
  5364. return scanner.getStartPos();
  5365. }
  5366. function nextToken() {
  5367. return token = scanner.scan();
  5368. }
  5369. function getTokenPos(pos) {
  5370. return ts.skipTrivia(sourceText, pos);
  5371. }
  5372. function reScanGreaterToken() {
  5373. return token = scanner.reScanGreaterToken();
  5374. }
  5375. function reScanSlashToken() {
  5376. return token = scanner.reScanSlashToken();
  5377. }
  5378. function reScanTemplateToken() {
  5379. return token = scanner.reScanTemplateToken();
  5380. }
  5381. function speculationHelper(callback, isLookAhead) {
  5382. var saveToken = token;
  5383. var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length;
  5384. var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
  5385. var saveContextFlags = contextFlags;
  5386. var result = isLookAhead
  5387. ? scanner.lookAhead(callback)
  5388. : scanner.tryScan(callback);
  5389. ts.Debug.assert(saveContextFlags === contextFlags);
  5390. if (!result || isLookAhead) {
  5391. token = saveToken;
  5392. sourceFile.parseDiagnostics.length = saveParseDiagnosticsLength;
  5393. parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode;
  5394. }
  5395. return result;
  5396. }
  5397. function lookAhead(callback) {
  5398. return speculationHelper(callback, true);
  5399. }
  5400. function tryParse(callback) {
  5401. return speculationHelper(callback, false);
  5402. }
  5403. function isIdentifier() {
  5404. if (token === 65) {
  5405. return true;
  5406. }
  5407. if (token === 110 && inYieldContext()) {
  5408. return false;
  5409. }
  5410. return token > 101;
  5411. }
  5412. function parseExpected(kind, diagnosticMessage) {
  5413. if (token === kind) {
  5414. nextToken();
  5415. return true;
  5416. }
  5417. if (diagnosticMessage) {
  5418. parseErrorAtCurrentToken(diagnosticMessage);
  5419. }
  5420. else {
  5421. parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(kind));
  5422. }
  5423. return false;
  5424. }
  5425. function parseOptional(t) {
  5426. if (token === t) {
  5427. nextToken();
  5428. return true;
  5429. }
  5430. return false;
  5431. }
  5432. function parseOptionalToken(t) {
  5433. if (token === t) {
  5434. return parseTokenNode();
  5435. }
  5436. return undefined;
  5437. }
  5438. function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) {
  5439. return parseOptionalToken(t) ||
  5440. createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0);
  5441. }
  5442. function parseTokenNode() {
  5443. var node = createNode(token);
  5444. nextToken();
  5445. return finishNode(node);
  5446. }
  5447. function canParseSemicolon() {
  5448. if (token === 22) {
  5449. return true;
  5450. }
  5451. return token === 15 || token === 1 || scanner.hasPrecedingLineBreak();
  5452. }
  5453. function parseSemicolon() {
  5454. if (canParseSemicolon()) {
  5455. if (token === 22) {
  5456. nextToken();
  5457. }
  5458. return true;
  5459. }
  5460. else {
  5461. return parseExpected(22);
  5462. }
  5463. }
  5464. function createNode(kind, pos) {
  5465. nodeCount++;
  5466. var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)))();
  5467. if (!(pos >= 0)) {
  5468. pos = scanner.getStartPos();
  5469. }
  5470. node.pos = pos;
  5471. node.end = pos;
  5472. return node;
  5473. }
  5474. function finishNode(node) {
  5475. node.end = scanner.getStartPos();
  5476. if (contextFlags) {
  5477. node.parserContextFlags = contextFlags;
  5478. }
  5479. if (parseErrorBeforeNextFinishedNode) {
  5480. parseErrorBeforeNextFinishedNode = false;
  5481. node.parserContextFlags |= 32;
  5482. }
  5483. return node;
  5484. }
  5485. function createMissingNode(kind, reportAtCurrentPosition, diagnosticMessage, arg0) {
  5486. if (reportAtCurrentPosition) {
  5487. parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
  5488. }
  5489. else {
  5490. parseErrorAtCurrentToken(diagnosticMessage, arg0);
  5491. }
  5492. var result = createNode(kind, scanner.getStartPos());
  5493. result.text = "";
  5494. return finishNode(result);
  5495. }
  5496. function internIdentifier(text) {
  5497. text = ts.escapeIdentifier(text);
  5498. return ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
  5499. }
  5500. function createIdentifier(isIdentifier, diagnosticMessage) {
  5501. identifierCount++;
  5502. if (isIdentifier) {
  5503. var node = createNode(65);
  5504. if (token !== 65) {
  5505. node.originalKeywordKind = token;
  5506. }
  5507. node.text = internIdentifier(scanner.getTokenValue());
  5508. nextToken();
  5509. return finishNode(node);
  5510. }
  5511. return createMissingNode(65, false, diagnosticMessage || ts.Diagnostics.Identifier_expected);
  5512. }
  5513. function parseIdentifier(diagnosticMessage) {
  5514. return createIdentifier(isIdentifier(), diagnosticMessage);
  5515. }
  5516. function parseIdentifierName() {
  5517. return createIdentifier(isIdentifierOrKeyword());
  5518. }
  5519. function isLiteralPropertyName() {
  5520. return isIdentifierOrKeyword() ||
  5521. token === 8 ||
  5522. token === 7;
  5523. }
  5524. function parsePropertyName() {
  5525. if (token === 8 || token === 7) {
  5526. return parseLiteralNode(true);
  5527. }
  5528. if (token === 18) {
  5529. return parseComputedPropertyName();
  5530. }
  5531. return parseIdentifierName();
  5532. }
  5533. function parseComputedPropertyName() {
  5534. var node = createNode(128);
  5535. parseExpected(18);
  5536. var yieldContext = inYieldContext();
  5537. if (inGeneratorParameterContext()) {
  5538. setYieldContext(false);
  5539. }
  5540. node.expression = allowInAnd(parseExpression);
  5541. if (inGeneratorParameterContext()) {
  5542. setYieldContext(yieldContext);
  5543. }
  5544. parseExpected(19);
  5545. return finishNode(node);
  5546. }
  5547. function parseContextualModifier(t) {
  5548. return token === t && tryParse(nextTokenCanFollowModifier);
  5549. }
  5550. function nextTokenCanFollowModifier() {
  5551. nextToken();
  5552. return canFollowModifier();
  5553. }
  5554. function parseAnyContextualModifier() {
  5555. return ts.isModifier(token) && tryParse(nextTokenCanFollowContextualModifier);
  5556. }
  5557. function nextTokenCanFollowContextualModifier() {
  5558. if (token === 70) {
  5559. return nextToken() === 77;
  5560. }
  5561. if (token === 78) {
  5562. nextToken();
  5563. if (token === 73) {
  5564. return lookAhead(nextTokenIsClassOrFunction);
  5565. }
  5566. return token !== 35 && token !== 14 && canFollowModifier();
  5567. }
  5568. if (token === 73) {
  5569. return nextTokenIsClassOrFunction();
  5570. }
  5571. nextToken();
  5572. return canFollowModifier();
  5573. }
  5574. function canFollowModifier() {
  5575. return token === 18
  5576. || token === 14
  5577. || token === 35
  5578. || isLiteralPropertyName();
  5579. }
  5580. function nextTokenIsClassOrFunction() {
  5581. nextToken();
  5582. return token === 69 || token === 83;
  5583. }
  5584. function isListElement(parsingContext, inErrorRecovery) {
  5585. var node = currentNode(parsingContext);
  5586. if (node) {
  5587. return true;
  5588. }
  5589. switch (parsingContext) {
  5590. case 0:
  5591. case 1:
  5592. return isSourceElement(inErrorRecovery);
  5593. case 2:
  5594. case 4:
  5595. return isStartOfStatement(inErrorRecovery);
  5596. case 3:
  5597. return token === 67 || token === 73;
  5598. case 5:
  5599. return isStartOfTypeMember();
  5600. case 6:
  5601. return lookAhead(isClassMemberStart) || (token === 22 && !inErrorRecovery);
  5602. case 7:
  5603. return token === 18 || isLiteralPropertyName();
  5604. case 13:
  5605. return token === 18 || token === 35 || isLiteralPropertyName();
  5606. case 10:
  5607. return isLiteralPropertyName();
  5608. case 8:
  5609. if (token === 14) {
  5610. return lookAhead(isValidHeritageClauseObjectLiteral);
  5611. }
  5612. if (!inErrorRecovery) {
  5613. return isStartOfLeftHandSideExpression() && !isHeritageClauseExtendsOrImplementsKeyword();
  5614. }
  5615. else {
  5616. return isIdentifier() && !isHeritageClauseExtendsOrImplementsKeyword();
  5617. }
  5618. case 9:
  5619. return isIdentifierOrPattern();
  5620. case 11:
  5621. return token === 23 || token === 21 || isIdentifierOrPattern();
  5622. case 16:
  5623. return isIdentifier();
  5624. case 12:
  5625. case 14:
  5626. return token === 23 || token === 21 || isStartOfExpression();
  5627. case 15:
  5628. return isStartOfParameter();
  5629. case 17:
  5630. case 18:
  5631. return token === 23 || isStartOfType();
  5632. case 19:
  5633. return isHeritageClause();
  5634. case 20:
  5635. return isIdentifierOrKeyword();
  5636. }
  5637. ts.Debug.fail("Non-exhaustive case in 'isListElement'.");
  5638. }
  5639. function isValidHeritageClauseObjectLiteral() {
  5640. ts.Debug.assert(token === 14);
  5641. if (nextToken() === 15) {
  5642. var next = nextToken();
  5643. return next === 23 || next === 14 || next === 79 || next === 102;
  5644. }
  5645. return true;
  5646. }
  5647. function nextTokenIsIdentifier() {
  5648. nextToken();
  5649. return isIdentifier();
  5650. }
  5651. function isHeritageClauseExtendsOrImplementsKeyword() {
  5652. if (token === 102 ||
  5653. token === 79) {
  5654. return lookAhead(nextTokenIsStartOfExpression);
  5655. }
  5656. return false;
  5657. }
  5658. function nextTokenIsStartOfExpression() {
  5659. nextToken();
  5660. return isStartOfExpression();
  5661. }
  5662. function isListTerminator(kind) {
  5663. if (token === 1) {
  5664. return true;
  5665. }
  5666. switch (kind) {
  5667. case 1:
  5668. case 2:
  5669. case 3:
  5670. case 5:
  5671. case 6:
  5672. case 7:
  5673. case 13:
  5674. case 10:
  5675. case 20:
  5676. return token === 15;
  5677. case 4:
  5678. return token === 15 || token === 67 || token === 73;
  5679. case 8:
  5680. return token === 14 || token === 79 || token === 102;
  5681. case 9:
  5682. return isVariableDeclaratorListTerminator();
  5683. case 16:
  5684. return token === 25 || token === 16 || token === 14 || token === 79 || token === 102;
  5685. case 12:
  5686. return token === 17 || token === 22;
  5687. case 14:
  5688. case 18:
  5689. case 11:
  5690. return token === 19;
  5691. case 15:
  5692. return token === 17 || token === 19;
  5693. case 17:
  5694. return token === 25 || token === 16;
  5695. case 19:
  5696. return token === 14 || token === 15;
  5697. }
  5698. }
  5699. function isVariableDeclaratorListTerminator() {
  5700. if (canParseSemicolon()) {
  5701. return true;
  5702. }
  5703. if (isInOrOfKeyword(token)) {
  5704. return true;
  5705. }
  5706. if (token === 32) {
  5707. return true;
  5708. }
  5709. return false;
  5710. }
  5711. function isInSomeParsingContext() {
  5712. for (var kind = 0; kind < 21; kind++) {
  5713. if (parsingContext & (1 << kind)) {
  5714. if (isListElement(kind, true) || isListTerminator(kind)) {
  5715. return true;
  5716. }
  5717. }
  5718. }
  5719. return false;
  5720. }
  5721. function parseList(kind, checkForStrictMode, parseElement) {
  5722. var saveParsingContext = parsingContext;
  5723. parsingContext |= 1 << kind;
  5724. var result = [];
  5725. result.pos = getNodePos();
  5726. var savedStrictModeContext = inStrictModeContext();
  5727. while (!isListTerminator(kind)) {
  5728. if (isListElement(kind, false)) {
  5729. var element = parseListElement(kind, parseElement);
  5730. result.push(element);
  5731. if (checkForStrictMode && !inStrictModeContext()) {
  5732. if (ts.isPrologueDirective(element)) {
  5733. if (isUseStrictPrologueDirective(sourceFile, element)) {
  5734. setStrictModeContext(true);
  5735. checkForStrictMode = false;
  5736. }
  5737. }
  5738. else {
  5739. checkForStrictMode = false;
  5740. }
  5741. }
  5742. continue;
  5743. }
  5744. if (abortParsingListOrMoveToNextToken(kind)) {
  5745. break;
  5746. }
  5747. }
  5748. setStrictModeContext(savedStrictModeContext);
  5749. result.end = getNodeEnd();
  5750. parsingContext = saveParsingContext;
  5751. return result;
  5752. }
  5753. function isUseStrictPrologueDirective(sourceFile, node) {
  5754. ts.Debug.assert(ts.isPrologueDirective(node));
  5755. var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression);
  5756. return nodeText === '"use strict"' || nodeText === "'use strict'";
  5757. }
  5758. function parseListElement(parsingContext, parseElement) {
  5759. var node = currentNode(parsingContext);
  5760. if (node) {
  5761. return consumeNode(node);
  5762. }
  5763. return parseElement();
  5764. }
  5765. function currentNode(parsingContext) {
  5766. if (parseErrorBeforeNextFinishedNode) {
  5767. return undefined;
  5768. }
  5769. if (!syntaxCursor) {
  5770. return undefined;
  5771. }
  5772. var node = syntaxCursor.currentNode(scanner.getStartPos());
  5773. if (ts.nodeIsMissing(node)) {
  5774. return undefined;
  5775. }
  5776. if (node.intersectsChange) {
  5777. return undefined;
  5778. }
  5779. if (ts.containsParseError(node)) {
  5780. return undefined;
  5781. }
  5782. var nodeContextFlags = node.parserContextFlags & 63;
  5783. if (nodeContextFlags !== contextFlags) {
  5784. return undefined;
  5785. }
  5786. if (!canReuseNode(node, parsingContext)) {
  5787. return undefined;
  5788. }
  5789. return node;
  5790. }
  5791. function consumeNode(node) {
  5792. scanner.setTextPos(node.end);
  5793. nextToken();
  5794. return node;
  5795. }
  5796. function canReuseNode(node, parsingContext) {
  5797. switch (parsingContext) {
  5798. case 1:
  5799. return isReusableModuleElement(node);
  5800. case 6:
  5801. return isReusableClassMember(node);
  5802. case 3:
  5803. return isReusableSwitchClause(node);
  5804. case 2:
  5805. case 4:
  5806. return isReusableStatement(node);
  5807. case 7:
  5808. return isReusableEnumMember(node);
  5809. case 5:
  5810. return isReusableTypeMember(node);
  5811. case 9:
  5812. return isReusableVariableDeclaration(node);
  5813. case 15:
  5814. return isReusableParameter(node);
  5815. case 19:
  5816. case 16:
  5817. case 18:
  5818. case 17:
  5819. case 12:
  5820. case 13:
  5821. case 8:
  5822. }
  5823. return false;
  5824. }
  5825. function isReusableModuleElement(node) {
  5826. if (node) {
  5827. switch (node.kind) {
  5828. case 210:
  5829. case 209:
  5830. case 216:
  5831. case 215:
  5832. case 202:
  5833. case 203:
  5834. case 206:
  5835. case 205:
  5836. return true;
  5837. }
  5838. return isReusableStatement(node);
  5839. }
  5840. return false;
  5841. }
  5842. function isReusableClassMember(node) {
  5843. if (node) {
  5844. switch (node.kind) {
  5845. case 136:
  5846. case 141:
  5847. case 135:
  5848. case 137:
  5849. case 138:
  5850. case 133:
  5851. case 179:
  5852. return true;
  5853. }
  5854. }
  5855. return false;
  5856. }
  5857. function isReusableSwitchClause(node) {
  5858. if (node) {
  5859. switch (node.kind) {
  5860. case 221:
  5861. case 222:
  5862. return true;
  5863. }
  5864. }
  5865. return false;
  5866. }
  5867. function isReusableStatement(node) {
  5868. if (node) {
  5869. switch (node.kind) {
  5870. case 201:
  5871. case 181:
  5872. case 180:
  5873. case 184:
  5874. case 183:
  5875. case 196:
  5876. case 192:
  5877. case 194:
  5878. case 191:
  5879. case 190:
  5880. case 188:
  5881. case 189:
  5882. case 187:
  5883. case 186:
  5884. case 193:
  5885. case 182:
  5886. case 197:
  5887. case 195:
  5888. case 185:
  5889. case 198:
  5890. return true;
  5891. }
  5892. }
  5893. return false;
  5894. }
  5895. function isReusableEnumMember(node) {
  5896. return node.kind === 227;
  5897. }
  5898. function isReusableTypeMember(node) {
  5899. if (node) {
  5900. switch (node.kind) {
  5901. case 140:
  5902. case 134:
  5903. case 141:
  5904. case 132:
  5905. case 139:
  5906. return true;
  5907. }
  5908. }
  5909. return false;
  5910. }
  5911. function isReusableVariableDeclaration(node) {
  5912. if (node.kind !== 199) {
  5913. return false;
  5914. }
  5915. var variableDeclarator = node;
  5916. return variableDeclarator.initializer === undefined;
  5917. }
  5918. function isReusableParameter(node) {
  5919. if (node.kind !== 130) {
  5920. return false;
  5921. }
  5922. var parameter = node;
  5923. return parameter.initializer === undefined;
  5924. }
  5925. function abortParsingListOrMoveToNextToken(kind) {
  5926. parseErrorAtCurrentToken(parsingContextErrors(kind));
  5927. if (isInSomeParsingContext()) {
  5928. return true;
  5929. }
  5930. nextToken();
  5931. return false;
  5932. }
  5933. function parsingContextErrors(context) {
  5934. switch (context) {
  5935. case 0: return ts.Diagnostics.Declaration_or_statement_expected;
  5936. case 1: return ts.Diagnostics.Declaration_or_statement_expected;
  5937. case 2: return ts.Diagnostics.Statement_expected;
  5938. case 3: return ts.Diagnostics.case_or_default_expected;
  5939. case 4: return ts.Diagnostics.Statement_expected;
  5940. case 5: return ts.Diagnostics.Property_or_signature_expected;
  5941. case 6: return ts.Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected;
  5942. case 7: return ts.Diagnostics.Enum_member_expected;
  5943. case 8: return ts.Diagnostics.Expression_expected;
  5944. case 9: return ts.Diagnostics.Variable_declaration_expected;
  5945. case 10: return ts.Diagnostics.Property_destructuring_pattern_expected;
  5946. case 11: return ts.Diagnostics.Array_element_destructuring_pattern_expected;
  5947. case 12: return ts.Diagnostics.Argument_expression_expected;
  5948. case 13: return ts.Diagnostics.Property_assignment_expected;
  5949. case 14: return ts.Diagnostics.Expression_or_comma_expected;
  5950. case 15: return ts.Diagnostics.Parameter_declaration_expected;
  5951. case 16: return ts.Diagnostics.Type_parameter_declaration_expected;
  5952. case 17: return ts.Diagnostics.Type_argument_expected;
  5953. case 18: return ts.Diagnostics.Type_expected;
  5954. case 19: return ts.Diagnostics.Unexpected_token_expected;
  5955. case 20: return ts.Diagnostics.Identifier_expected;
  5956. }
  5957. }
  5958. ;
  5959. function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimeter) {
  5960. var saveParsingContext = parsingContext;
  5961. parsingContext |= 1 << kind;
  5962. var result = [];
  5963. result.pos = getNodePos();
  5964. var commaStart = -1;
  5965. while (true) {
  5966. if (isListElement(kind, false)) {
  5967. result.push(parseListElement(kind, parseElement));
  5968. commaStart = scanner.getTokenPos();
  5969. if (parseOptional(23)) {
  5970. continue;
  5971. }
  5972. commaStart = -1;
  5973. if (isListTerminator(kind)) {
  5974. break;
  5975. }
  5976. parseExpected(23);
  5977. if (considerSemicolonAsDelimeter && token === 22 && !scanner.hasPrecedingLineBreak()) {
  5978. nextToken();
  5979. }
  5980. continue;
  5981. }
  5982. if (isListTerminator(kind)) {
  5983. break;
  5984. }
  5985. if (abortParsingListOrMoveToNextToken(kind)) {
  5986. break;
  5987. }
  5988. }
  5989. if (commaStart >= 0) {
  5990. result.hasTrailingComma = true;
  5991. }
  5992. result.end = getNodeEnd();
  5993. parsingContext = saveParsingContext;
  5994. return result;
  5995. }
  5996. function createMissingList() {
  5997. var pos = getNodePos();
  5998. var result = [];
  5999. result.pos = pos;
  6000. result.end = pos;
  6001. return result;
  6002. }
  6003. function parseBracketedList(kind, parseElement, open, close) {
  6004. if (parseExpected(open)) {
  6005. var result = parseDelimitedList(kind, parseElement);
  6006. parseExpected(close);
  6007. return result;
  6008. }
  6009. return createMissingList();
  6010. }
  6011. function parseEntityName(allowReservedWords, diagnosticMessage) {
  6012. var entity = parseIdentifier(diagnosticMessage);
  6013. while (parseOptional(20)) {
  6014. var node = createNode(127, entity.pos);
  6015. node.left = entity;
  6016. node.right = parseRightSideOfDot(allowReservedWords);
  6017. entity = finishNode(node);
  6018. }
  6019. return entity;
  6020. }
  6021. function parseRightSideOfDot(allowIdentifierNames) {
  6022. if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) {
  6023. var matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
  6024. if (matchesPattern) {
  6025. return createMissingNode(65, true, ts.Diagnostics.Identifier_expected);
  6026. }
  6027. }
  6028. return allowIdentifierNames ? parseIdentifierName() : parseIdentifier();
  6029. }
  6030. function parseTemplateExpression() {
  6031. var template = createNode(172);
  6032. template.head = parseLiteralNode();
  6033. ts.Debug.assert(template.head.kind === 11, "Template head has wrong token kind");
  6034. var templateSpans = [];
  6035. templateSpans.pos = getNodePos();
  6036. do {
  6037. templateSpans.push(parseTemplateSpan());
  6038. } while (ts.lastOrUndefined(templateSpans).literal.kind === 12);
  6039. templateSpans.end = getNodeEnd();
  6040. template.templateSpans = templateSpans;
  6041. return finishNode(template);
  6042. }
  6043. function parseTemplateSpan() {
  6044. var span = createNode(178);
  6045. span.expression = allowInAnd(parseExpression);
  6046. var literal;
  6047. if (token === 15) {
  6048. reScanTemplateToken();
  6049. literal = parseLiteralNode();
  6050. }
  6051. else {
  6052. literal = parseExpectedToken(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15));
  6053. }
  6054. span.literal = literal;
  6055. return finishNode(span);
  6056. }
  6057. function parseLiteralNode(internName) {
  6058. var node = createNode(token);
  6059. var text = scanner.getTokenValue();
  6060. node.text = internName ? internIdentifier(text) : text;
  6061. if (scanner.hasExtendedUnicodeEscape()) {
  6062. node.hasExtendedUnicodeEscape = true;
  6063. }
  6064. if (scanner.isUnterminated()) {
  6065. node.isUnterminated = true;
  6066. }
  6067. var tokenPos = scanner.getTokenPos();
  6068. nextToken();
  6069. finishNode(node);
  6070. if (node.kind === 7
  6071. && sourceText.charCodeAt(tokenPos) === 48
  6072. && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
  6073. node.flags |= 16384;
  6074. }
  6075. return node;
  6076. }
  6077. function parseTypeReference() {
  6078. var node = createNode(142);
  6079. node.typeName = parseEntityName(false, ts.Diagnostics.Type_expected);
  6080. if (!scanner.hasPrecedingLineBreak() && token === 24) {
  6081. node.typeArguments = parseBracketedList(17, parseType, 24, 25);
  6082. }
  6083. return finishNode(node);
  6084. }
  6085. function parseTypeQuery() {
  6086. var node = createNode(145);
  6087. parseExpected(97);
  6088. node.exprName = parseEntityName(true);
  6089. return finishNode(node);
  6090. }
  6091. function parseTypeParameter() {
  6092. var node = createNode(129);
  6093. node.name = parseIdentifier();
  6094. if (parseOptional(79)) {
  6095. if (isStartOfType() || !isStartOfExpression()) {
  6096. node.constraint = parseType();
  6097. }
  6098. else {
  6099. node.expression = parseUnaryExpressionOrHigher();
  6100. }
  6101. }
  6102. return finishNode(node);
  6103. }
  6104. function parseTypeParameters() {
  6105. if (token === 24) {
  6106. return parseBracketedList(16, parseTypeParameter, 24, 25);
  6107. }
  6108. }
  6109. function parseParameterType() {
  6110. if (parseOptional(51)) {
  6111. return token === 8
  6112. ? parseLiteralNode(true)
  6113. : parseType();
  6114. }
  6115. return undefined;
  6116. }
  6117. function isStartOfParameter() {
  6118. return token === 21 || isIdentifierOrPattern() || ts.isModifier(token) || token === 52;
  6119. }
  6120. function setModifiers(node, modifiers) {
  6121. if (modifiers) {
  6122. node.flags |= modifiers.flags;
  6123. node.modifiers = modifiers;
  6124. }
  6125. }
  6126. function parseParameter() {
  6127. var node = createNode(130);
  6128. node.decorators = parseDecorators();
  6129. setModifiers(node, parseModifiers());
  6130. node.dotDotDotToken = parseOptionalToken(21);
  6131. node.name = inGeneratorParameterContext() ? doInYieldContext(parseIdentifierOrPattern) : parseIdentifierOrPattern();
  6132. if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(token)) {
  6133. nextToken();
  6134. }
  6135. node.questionToken = parseOptionalToken(50);
  6136. node.type = parseParameterType();
  6137. node.initializer = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseParameterInitializer) : parseParameterInitializer();
  6138. return finishNode(node);
  6139. }
  6140. function parseParameterInitializer() {
  6141. return parseInitializer(true);
  6142. }
  6143. function fillSignature(returnToken, yieldAndGeneratorParameterContext, requireCompleteParameterList, signature) {
  6144. var returnTokenRequired = returnToken === 32;
  6145. signature.typeParameters = parseTypeParameters();
  6146. signature.parameters = parseParameterList(yieldAndGeneratorParameterContext, requireCompleteParameterList);
  6147. if (returnTokenRequired) {
  6148. parseExpected(returnToken);
  6149. signature.type = parseType();
  6150. }
  6151. else if (parseOptional(returnToken)) {
  6152. signature.type = parseType();
  6153. }
  6154. }
  6155. function parseParameterList(yieldAndGeneratorParameterContext, requireCompleteParameterList) {
  6156. if (parseExpected(16)) {
  6157. var savedYieldContext = inYieldContext();
  6158. var savedGeneratorParameterContext = inGeneratorParameterContext();
  6159. setYieldContext(yieldAndGeneratorParameterContext);
  6160. setGeneratorParameterContext(yieldAndGeneratorParameterContext);
  6161. var result = parseDelimitedList(15, parseParameter);
  6162. setYieldContext(savedYieldContext);
  6163. setGeneratorParameterContext(savedGeneratorParameterContext);
  6164. if (!parseExpected(17) && requireCompleteParameterList) {
  6165. return undefined;
  6166. }
  6167. return result;
  6168. }
  6169. return requireCompleteParameterList ? undefined : createMissingList();
  6170. }
  6171. function parseTypeMemberSemicolon() {
  6172. if (parseOptional(23)) {
  6173. return;
  6174. }
  6175. parseSemicolon();
  6176. }
  6177. function parseSignatureMember(kind) {
  6178. var node = createNode(kind);
  6179. if (kind === 140) {
  6180. parseExpected(88);
  6181. }
  6182. fillSignature(51, false, false, node);
  6183. parseTypeMemberSemicolon();
  6184. return finishNode(node);
  6185. }
  6186. function isIndexSignature() {
  6187. if (token !== 18) {
  6188. return false;
  6189. }
  6190. return lookAhead(isUnambiguouslyIndexSignature);
  6191. }
  6192. function isUnambiguouslyIndexSignature() {
  6193. nextToken();
  6194. if (token === 21 || token === 19) {
  6195. return true;
  6196. }
  6197. if (ts.isModifier(token)) {
  6198. nextToken();
  6199. if (isIdentifier()) {
  6200. return true;
  6201. }
  6202. }
  6203. else if (!isIdentifier()) {
  6204. return false;
  6205. }
  6206. else {
  6207. nextToken();
  6208. }
  6209. if (token === 51 || token === 23) {
  6210. return true;
  6211. }
  6212. if (token !== 50) {
  6213. return false;
  6214. }
  6215. nextToken();
  6216. return token === 51 || token === 23 || token === 19;
  6217. }
  6218. function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) {
  6219. var node = createNode(141, fullStart);
  6220. node.decorators = decorators;
  6221. setModifiers(node, modifiers);
  6222. node.parameters = parseBracketedList(15, parseParameter, 18, 19);
  6223. node.type = parseTypeAnnotation();
  6224. parseTypeMemberSemicolon();
  6225. return finishNode(node);
  6226. }
  6227. function parsePropertyOrMethodSignature() {
  6228. var fullStart = scanner.getStartPos();
  6229. var name = parsePropertyName();
  6230. var questionToken = parseOptionalToken(50);
  6231. if (token === 16 || token === 24) {
  6232. var method = createNode(134, fullStart);
  6233. method.name = name;
  6234. method.questionToken = questionToken;
  6235. fillSignature(51, false, false, method);
  6236. parseTypeMemberSemicolon();
  6237. return finishNode(method);
  6238. }
  6239. else {
  6240. var property = createNode(132, fullStart);
  6241. property.name = name;
  6242. property.questionToken = questionToken;
  6243. property.type = parseTypeAnnotation();
  6244. parseTypeMemberSemicolon();
  6245. return finishNode(property);
  6246. }
  6247. }
  6248. function isStartOfTypeMember() {
  6249. switch (token) {
  6250. case 16:
  6251. case 24:
  6252. case 18:
  6253. return true;
  6254. default:
  6255. if (ts.isModifier(token)) {
  6256. var result = lookAhead(isStartOfIndexSignatureDeclaration);
  6257. if (result) {
  6258. return result;
  6259. }
  6260. }
  6261. return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName);
  6262. }
  6263. }
  6264. function isStartOfIndexSignatureDeclaration() {
  6265. while (ts.isModifier(token)) {
  6266. nextToken();
  6267. }
  6268. return isIndexSignature();
  6269. }
  6270. function isTypeMemberWithLiteralPropertyName() {
  6271. nextToken();
  6272. return token === 16 ||
  6273. token === 24 ||
  6274. token === 50 ||
  6275. token === 51 ||
  6276. canParseSemicolon();
  6277. }
  6278. function parseTypeMember() {
  6279. switch (token) {
  6280. case 16:
  6281. case 24:
  6282. return parseSignatureMember(139);
  6283. case 18:
  6284. return isIndexSignature()
  6285. ? parseIndexSignatureDeclaration(scanner.getStartPos(), undefined, undefined)
  6286. : parsePropertyOrMethodSignature();
  6287. case 88:
  6288. if (lookAhead(isStartOfConstructSignature)) {
  6289. return parseSignatureMember(140);
  6290. }
  6291. case 8:
  6292. case 7:
  6293. return parsePropertyOrMethodSignature();
  6294. default:
  6295. if (ts.isModifier(token)) {
  6296. var result = tryParse(parseIndexSignatureWithModifiers);
  6297. if (result) {
  6298. return result;
  6299. }
  6300. }
  6301. if (isIdentifierOrKeyword()) {
  6302. return parsePropertyOrMethodSignature();
  6303. }
  6304. }
  6305. }
  6306. function parseIndexSignatureWithModifiers() {
  6307. var fullStart = scanner.getStartPos();
  6308. var decorators = parseDecorators();
  6309. var modifiers = parseModifiers();
  6310. return isIndexSignature()
  6311. ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers)
  6312. : undefined;
  6313. }
  6314. function isStartOfConstructSignature() {
  6315. nextToken();
  6316. return token === 16 || token === 24;
  6317. }
  6318. function parseTypeLiteral() {
  6319. var node = createNode(146);
  6320. node.members = parseObjectTypeMembers();
  6321. return finishNode(node);
  6322. }
  6323. function parseObjectTypeMembers() {
  6324. var members;
  6325. if (parseExpected(14)) {
  6326. members = parseList(5, false, parseTypeMember);
  6327. parseExpected(15);
  6328. }
  6329. else {
  6330. members = createMissingList();
  6331. }
  6332. return members;
  6333. }
  6334. function parseTupleType() {
  6335. var node = createNode(148);
  6336. node.elementTypes = parseBracketedList(18, parseType, 18, 19);
  6337. return finishNode(node);
  6338. }
  6339. function parseParenthesizedType() {
  6340. var node = createNode(150);
  6341. parseExpected(16);
  6342. node.type = parseType();
  6343. parseExpected(17);
  6344. return finishNode(node);
  6345. }
  6346. function parseFunctionOrConstructorType(kind) {
  6347. var node = createNode(kind);
  6348. if (kind === 144) {
  6349. parseExpected(88);
  6350. }
  6351. fillSignature(32, false, false, node);
  6352. return finishNode(node);
  6353. }
  6354. function parseKeywordAndNoDot() {
  6355. var node = parseTokenNode();
  6356. return token === 20 ? undefined : node;
  6357. }
  6358. function parseNonArrayType() {
  6359. switch (token) {
  6360. case 112:
  6361. case 122:
  6362. case 120:
  6363. case 113:
  6364. case 123:
  6365. var node = tryParse(parseKeywordAndNoDot);
  6366. return node || parseTypeReference();
  6367. case 99:
  6368. return parseTokenNode();
  6369. case 97:
  6370. return parseTypeQuery();
  6371. case 14:
  6372. return parseTypeLiteral();
  6373. case 18:
  6374. return parseTupleType();
  6375. case 16:
  6376. return parseParenthesizedType();
  6377. default:
  6378. return parseTypeReference();
  6379. }
  6380. }
  6381. function isStartOfType() {
  6382. switch (token) {
  6383. case 112:
  6384. case 122:
  6385. case 120:
  6386. case 113:
  6387. case 123:
  6388. case 99:
  6389. case 97:
  6390. case 14:
  6391. case 18:
  6392. case 24:
  6393. case 88:
  6394. return true;
  6395. case 16:
  6396. return lookAhead(isStartOfParenthesizedOrFunctionType);
  6397. default:
  6398. return isIdentifier();
  6399. }
  6400. }
  6401. function isStartOfParenthesizedOrFunctionType() {
  6402. nextToken();
  6403. return token === 17 || isStartOfParameter() || isStartOfType();
  6404. }
  6405. function parseArrayTypeOrHigher() {
  6406. var type = parseNonArrayType();
  6407. while (!scanner.hasPrecedingLineBreak() && parseOptional(18)) {
  6408. parseExpected(19);
  6409. var node = createNode(147, type.pos);
  6410. node.elementType = type;
  6411. type = finishNode(node);
  6412. }
  6413. return type;
  6414. }
  6415. function parseUnionTypeOrHigher() {
  6416. var type = parseArrayTypeOrHigher();
  6417. if (token === 44) {
  6418. var types = [type];
  6419. types.pos = type.pos;
  6420. while (parseOptional(44)) {
  6421. types.push(parseArrayTypeOrHigher());
  6422. }
  6423. types.end = getNodeEnd();
  6424. var node = createNode(149, type.pos);
  6425. node.types = types;
  6426. type = finishNode(node);
  6427. }
  6428. return type;
  6429. }
  6430. function isStartOfFunctionType() {
  6431. if (token === 24) {
  6432. return true;
  6433. }
  6434. return token === 16 && lookAhead(isUnambiguouslyStartOfFunctionType);
  6435. }
  6436. function isUnambiguouslyStartOfFunctionType() {
  6437. nextToken();
  6438. if (token === 17 || token === 21) {
  6439. return true;
  6440. }
  6441. if (isIdentifier() || ts.isModifier(token)) {
  6442. nextToken();
  6443. if (token === 51 || token === 23 ||
  6444. token === 50 || token === 53 ||
  6445. isIdentifier() || ts.isModifier(token)) {
  6446. return true;
  6447. }
  6448. if (token === 17) {
  6449. nextToken();
  6450. if (token === 32) {
  6451. return true;
  6452. }
  6453. }
  6454. }
  6455. return false;
  6456. }
  6457. function parseType() {
  6458. var savedYieldContext = inYieldContext();
  6459. var savedGeneratorParameterContext = inGeneratorParameterContext();
  6460. setYieldContext(false);
  6461. setGeneratorParameterContext(false);
  6462. var result = parseTypeWorker();
  6463. setYieldContext(savedYieldContext);
  6464. setGeneratorParameterContext(savedGeneratorParameterContext);
  6465. return result;
  6466. }
  6467. function parseTypeWorker() {
  6468. if (isStartOfFunctionType()) {
  6469. return parseFunctionOrConstructorType(143);
  6470. }
  6471. if (token === 88) {
  6472. return parseFunctionOrConstructorType(144);
  6473. }
  6474. return parseUnionTypeOrHigher();
  6475. }
  6476. function parseTypeAnnotation() {
  6477. return parseOptional(51) ? parseType() : undefined;
  6478. }
  6479. function isStartOfLeftHandSideExpression() {
  6480. switch (token) {
  6481. case 93:
  6482. case 91:
  6483. case 89:
  6484. case 95:
  6485. case 80:
  6486. case 7:
  6487. case 8:
  6488. case 10:
  6489. case 11:
  6490. case 16:
  6491. case 18:
  6492. case 14:
  6493. case 83:
  6494. case 69:
  6495. case 88:
  6496. case 36:
  6497. case 57:
  6498. case 65:
  6499. return true;
  6500. default:
  6501. return isIdentifier();
  6502. }
  6503. }
  6504. function isStartOfExpression() {
  6505. if (isStartOfLeftHandSideExpression()) {
  6506. return true;
  6507. }
  6508. switch (token) {
  6509. case 33:
  6510. case 34:
  6511. case 47:
  6512. case 46:
  6513. case 74:
  6514. case 97:
  6515. case 99:
  6516. case 38:
  6517. case 39:
  6518. case 24:
  6519. case 110:
  6520. return true;
  6521. default:
  6522. if (isBinaryOperator()) {
  6523. return true;
  6524. }
  6525. return isIdentifier();
  6526. }
  6527. }
  6528. function isStartOfExpressionStatement() {
  6529. return token !== 14 &&
  6530. token !== 83 &&
  6531. token !== 69 &&
  6532. token !== 52 &&
  6533. isStartOfExpression();
  6534. }
  6535. function parseExpression() {
  6536. // Expression[in]:
  6537. // AssignmentExpression[in]
  6538. // Expression[in] , AssignmentExpression[in]
  6539. var saveDecoratorContext = inDecoratorContext();
  6540. if (saveDecoratorContext) {
  6541. setDecoratorContext(false);
  6542. }
  6543. var expr = parseAssignmentExpressionOrHigher();
  6544. var operatorToken;
  6545. while ((operatorToken = parseOptionalToken(23))) {
  6546. expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher());
  6547. }
  6548. if (saveDecoratorContext) {
  6549. setDecoratorContext(true);
  6550. }
  6551. return expr;
  6552. }
  6553. function parseInitializer(inParameter) {
  6554. if (token !== 53) {
  6555. if (scanner.hasPrecedingLineBreak() || (inParameter && token === 14) || !isStartOfExpression()) {
  6556. return undefined;
  6557. }
  6558. }
  6559. parseExpected(53);
  6560. return parseAssignmentExpressionOrHigher();
  6561. }
  6562. function parseAssignmentExpressionOrHigher() {
  6563. // AssignmentExpression[in,yield]:
  6564. // 1) ConditionalExpression[?in,?yield]
  6565. // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
  6566. // 3) LeftHandSideExpression AssignmentOperator AssignmentExpression[?in,?yield]
  6567. // 4) ArrowFunctionExpression[?in,?yield]
  6568. // 5) [+Yield] YieldExpression[?In]
  6569. //
  6570. // Note: for ease of implementation we treat productions '2' and '3' as the same thing.
  6571. // (i.e. they're both BinaryExpressions with an assignment operator in it).
  6572. if (isYieldExpression()) {
  6573. return parseYieldExpression();
  6574. }
  6575. var arrowExpression = tryParseParenthesizedArrowFunctionExpression();
  6576. if (arrowExpression) {
  6577. return arrowExpression;
  6578. }
  6579. var expr = parseBinaryExpressionOrHigher(0);
  6580. if (expr.kind === 65 && token === 32) {
  6581. return parseSimpleArrowFunctionExpression(expr);
  6582. }
  6583. if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
  6584. return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher());
  6585. }
  6586. return parseConditionalExpressionRest(expr);
  6587. }
  6588. function isYieldExpression() {
  6589. if (token === 110) {
  6590. if (inYieldContext()) {
  6591. return true;
  6592. }
  6593. if (inStrictModeContext()) {
  6594. return true;
  6595. }
  6596. return lookAhead(nextTokenIsIdentifierOnSameLine);
  6597. }
  6598. return false;
  6599. }
  6600. function nextTokenIsIdentifierOnSameLine() {
  6601. nextToken();
  6602. return !scanner.hasPrecedingLineBreak() && isIdentifier();
  6603. }
  6604. function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() {
  6605. nextToken();
  6606. return !scanner.hasPrecedingLineBreak() &&
  6607. (isIdentifier() || token === 14 || token === 18);
  6608. }
  6609. function parseYieldExpression() {
  6610. var node = createNode(173);
  6611. nextToken();
  6612. if (!scanner.hasPrecedingLineBreak() &&
  6613. (token === 35 || isStartOfExpression())) {
  6614. node.asteriskToken = parseOptionalToken(35);
  6615. node.expression = parseAssignmentExpressionOrHigher();
  6616. return finishNode(node);
  6617. }
  6618. else {
  6619. return finishNode(node);
  6620. }
  6621. }
  6622. function parseSimpleArrowFunctionExpression(identifier) {
  6623. ts.Debug.assert(token === 32, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
  6624. var node = createNode(164, identifier.pos);
  6625. var parameter = createNode(130, identifier.pos);
  6626. parameter.name = identifier;
  6627. finishNode(parameter);
  6628. node.parameters = [parameter];
  6629. node.parameters.pos = parameter.pos;
  6630. node.parameters.end = parameter.end;
  6631. node.equalsGreaterThanToken = parseExpectedToken(32, false, ts.Diagnostics._0_expected, "=>");
  6632. node.body = parseArrowFunctionExpressionBody();
  6633. return finishNode(node);
  6634. }
  6635. function tryParseParenthesizedArrowFunctionExpression() {
  6636. var triState = isParenthesizedArrowFunctionExpression();
  6637. if (triState === 0) {
  6638. return undefined;
  6639. }
  6640. var arrowFunction = triState === 1
  6641. ? parseParenthesizedArrowFunctionExpressionHead(true)
  6642. : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead);
  6643. if (!arrowFunction) {
  6644. return undefined;
  6645. }
  6646. var lastToken = token;
  6647. arrowFunction.equalsGreaterThanToken = parseExpectedToken(32, false, ts.Diagnostics._0_expected, "=>");
  6648. arrowFunction.body = (lastToken === 32 || lastToken === 14)
  6649. ? parseArrowFunctionExpressionBody()
  6650. : parseIdentifier();
  6651. return finishNode(arrowFunction);
  6652. }
  6653. function isParenthesizedArrowFunctionExpression() {
  6654. if (token === 16 || token === 24) {
  6655. return lookAhead(isParenthesizedArrowFunctionExpressionWorker);
  6656. }
  6657. if (token === 32) {
  6658. return 1;
  6659. }
  6660. return 0;
  6661. }
  6662. function isParenthesizedArrowFunctionExpressionWorker() {
  6663. var first = token;
  6664. var second = nextToken();
  6665. if (first === 16) {
  6666. if (second === 17) {
  6667. var third = nextToken();
  6668. switch (third) {
  6669. case 32:
  6670. case 51:
  6671. case 14:
  6672. return 1;
  6673. default:
  6674. return 0;
  6675. }
  6676. }
  6677. if (second === 18 || second === 14) {
  6678. return 2;
  6679. }
  6680. if (second === 21) {
  6681. return 1;
  6682. }
  6683. if (!isIdentifier()) {
  6684. return 0;
  6685. }
  6686. if (nextToken() === 51) {
  6687. return 1;
  6688. }
  6689. return 2;
  6690. }
  6691. else {
  6692. ts.Debug.assert(first === 24);
  6693. if (!isIdentifier()) {
  6694. return 0;
  6695. }
  6696. return 2;
  6697. }
  6698. }
  6699. function parsePossibleParenthesizedArrowFunctionExpressionHead() {
  6700. return parseParenthesizedArrowFunctionExpressionHead(false);
  6701. }
  6702. function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) {
  6703. var node = createNode(164);
  6704. fillSignature(51, false, !allowAmbiguity, node);
  6705. if (!node.parameters) {
  6706. return undefined;
  6707. }
  6708. if (!allowAmbiguity && token !== 32 && token !== 14) {
  6709. return undefined;
  6710. }
  6711. return node;
  6712. }
  6713. function parseArrowFunctionExpressionBody() {
  6714. if (token === 14) {
  6715. return parseFunctionBlock(false, false);
  6716. }
  6717. if (isStartOfStatement(true) &&
  6718. !isStartOfExpressionStatement() &&
  6719. token !== 83 &&
  6720. token !== 69) {
  6721. return parseFunctionBlock(false, true);
  6722. }
  6723. return parseAssignmentExpressionOrHigher();
  6724. }
  6725. function parseConditionalExpressionRest(leftOperand) {
  6726. var questionToken = parseOptionalToken(50);
  6727. if (!questionToken) {
  6728. return leftOperand;
  6729. }
  6730. var node = createNode(171, leftOperand.pos);
  6731. node.condition = leftOperand;
  6732. node.questionToken = questionToken;
  6733. node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher);
  6734. node.colonToken = parseExpectedToken(51, false, ts.Diagnostics._0_expected, ts.tokenToString(51));
  6735. node.whenFalse = parseAssignmentExpressionOrHigher();
  6736. return finishNode(node);
  6737. }
  6738. function parseBinaryExpressionOrHigher(precedence) {
  6739. var leftOperand = parseUnaryExpressionOrHigher();
  6740. return parseBinaryExpressionRest(precedence, leftOperand);
  6741. }
  6742. function isInOrOfKeyword(t) {
  6743. return t === 86 || t === 126;
  6744. }
  6745. function parseBinaryExpressionRest(precedence, leftOperand) {
  6746. while (true) {
  6747. reScanGreaterToken();
  6748. var newPrecedence = getBinaryOperatorPrecedence();
  6749. if (newPrecedence <= precedence) {
  6750. break;
  6751. }
  6752. if (token === 86 && inDisallowInContext()) {
  6753. break;
  6754. }
  6755. leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
  6756. }
  6757. return leftOperand;
  6758. }
  6759. function isBinaryOperator() {
  6760. if (inDisallowInContext() && token === 86) {
  6761. return false;
  6762. }
  6763. return getBinaryOperatorPrecedence() > 0;
  6764. }
  6765. function getBinaryOperatorPrecedence() {
  6766. switch (token) {
  6767. case 49:
  6768. return 1;
  6769. case 48:
  6770. return 2;
  6771. case 44:
  6772. return 3;
  6773. case 45:
  6774. return 4;
  6775. case 43:
  6776. return 5;
  6777. case 28:
  6778. case 29:
  6779. case 30:
  6780. case 31:
  6781. return 6;
  6782. case 24:
  6783. case 25:
  6784. case 26:
  6785. case 27:
  6786. case 87:
  6787. case 86:
  6788. return 7;
  6789. case 40:
  6790. case 41:
  6791. case 42:
  6792. return 8;
  6793. case 33:
  6794. case 34:
  6795. return 9;
  6796. case 35:
  6797. case 36:
  6798. case 37:
  6799. return 10;
  6800. }
  6801. return -1;
  6802. }
  6803. function makeBinaryExpression(left, operatorToken, right) {
  6804. var node = createNode(170, left.pos);
  6805. node.left = left;
  6806. node.operatorToken = operatorToken;
  6807. node.right = right;
  6808. return finishNode(node);
  6809. }
  6810. function parsePrefixUnaryExpression() {
  6811. var node = createNode(168);
  6812. node.operator = token;
  6813. nextToken();
  6814. node.operand = parseUnaryExpressionOrHigher();
  6815. return finishNode(node);
  6816. }
  6817. function parseDeleteExpression() {
  6818. var node = createNode(165);
  6819. nextToken();
  6820. node.expression = parseUnaryExpressionOrHigher();
  6821. return finishNode(node);
  6822. }
  6823. function parseTypeOfExpression() {
  6824. var node = createNode(166);
  6825. nextToken();
  6826. node.expression = parseUnaryExpressionOrHigher();
  6827. return finishNode(node);
  6828. }
  6829. function parseVoidExpression() {
  6830. var node = createNode(167);
  6831. nextToken();
  6832. node.expression = parseUnaryExpressionOrHigher();
  6833. return finishNode(node);
  6834. }
  6835. function parseUnaryExpressionOrHigher() {
  6836. switch (token) {
  6837. case 33:
  6838. case 34:
  6839. case 47:
  6840. case 46:
  6841. case 38:
  6842. case 39:
  6843. return parsePrefixUnaryExpression();
  6844. case 74:
  6845. return parseDeleteExpression();
  6846. case 97:
  6847. return parseTypeOfExpression();
  6848. case 99:
  6849. return parseVoidExpression();
  6850. case 24:
  6851. return parseTypeAssertion();
  6852. default:
  6853. return parsePostfixExpressionOrHigher();
  6854. }
  6855. }
  6856. function parsePostfixExpressionOrHigher() {
  6857. var expression = parseLeftHandSideExpressionOrHigher();
  6858. ts.Debug.assert(ts.isLeftHandSideExpression(expression));
  6859. if ((token === 38 || token === 39) && !scanner.hasPrecedingLineBreak()) {
  6860. var node = createNode(169, expression.pos);
  6861. node.operand = expression;
  6862. node.operator = token;
  6863. nextToken();
  6864. return finishNode(node);
  6865. }
  6866. return expression;
  6867. }
  6868. function parseLeftHandSideExpressionOrHigher() {
  6869. var expression = token === 91
  6870. ? parseSuperExpression()
  6871. : parseMemberExpressionOrHigher();
  6872. return parseCallExpressionRest(expression);
  6873. }
  6874. function parseMemberExpressionOrHigher() {
  6875. var expression = parsePrimaryExpression();
  6876. return parseMemberExpressionRest(expression);
  6877. }
  6878. function parseSuperExpression() {
  6879. var expression = parseTokenNode();
  6880. if (token === 16 || token === 20) {
  6881. return expression;
  6882. }
  6883. var node = createNode(156, expression.pos);
  6884. node.expression = expression;
  6885. node.dotToken = parseExpectedToken(20, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
  6886. node.name = parseRightSideOfDot(true);
  6887. return finishNode(node);
  6888. }
  6889. function parseTypeAssertion() {
  6890. var node = createNode(161);
  6891. parseExpected(24);
  6892. node.type = parseType();
  6893. parseExpected(25);
  6894. node.expression = parseUnaryExpressionOrHigher();
  6895. return finishNode(node);
  6896. }
  6897. function parseMemberExpressionRest(expression) {
  6898. while (true) {
  6899. var dotToken = parseOptionalToken(20);
  6900. if (dotToken) {
  6901. var propertyAccess = createNode(156, expression.pos);
  6902. propertyAccess.expression = expression;
  6903. propertyAccess.dotToken = dotToken;
  6904. propertyAccess.name = parseRightSideOfDot(true);
  6905. expression = finishNode(propertyAccess);
  6906. continue;
  6907. }
  6908. if (!inDecoratorContext() && parseOptional(18)) {
  6909. var indexedAccess = createNode(157, expression.pos);
  6910. indexedAccess.expression = expression;
  6911. if (token !== 19) {
  6912. indexedAccess.argumentExpression = allowInAnd(parseExpression);
  6913. if (indexedAccess.argumentExpression.kind === 8 || indexedAccess.argumentExpression.kind === 7) {
  6914. var literal = indexedAccess.argumentExpression;
  6915. literal.text = internIdentifier(literal.text);
  6916. }
  6917. }
  6918. parseExpected(19);
  6919. expression = finishNode(indexedAccess);
  6920. continue;
  6921. }
  6922. if (token === 10 || token === 11) {
  6923. var tagExpression = createNode(160, expression.pos);
  6924. tagExpression.tag = expression;
  6925. tagExpression.template = token === 10
  6926. ? parseLiteralNode()
  6927. : parseTemplateExpression();
  6928. expression = finishNode(tagExpression);
  6929. continue;
  6930. }
  6931. return expression;
  6932. }
  6933. }
  6934. function parseCallExpressionRest(expression) {
  6935. while (true) {
  6936. expression = parseMemberExpressionRest(expression);
  6937. if (token === 24) {
  6938. var typeArguments = tryParse(parseTypeArgumentsInExpression);
  6939. if (!typeArguments) {
  6940. return expression;
  6941. }
  6942. var callExpr = createNode(158, expression.pos);
  6943. callExpr.expression = expression;
  6944. callExpr.typeArguments = typeArguments;
  6945. callExpr.arguments = parseArgumentList();
  6946. expression = finishNode(callExpr);
  6947. continue;
  6948. }
  6949. else if (token === 16) {
  6950. var callExpr = createNode(158, expression.pos);
  6951. callExpr.expression = expression;
  6952. callExpr.arguments = parseArgumentList();
  6953. expression = finishNode(callExpr);
  6954. continue;
  6955. }
  6956. return expression;
  6957. }
  6958. }
  6959. function parseArgumentList() {
  6960. parseExpected(16);
  6961. var result = parseDelimitedList(12, parseArgumentExpression);
  6962. parseExpected(17);
  6963. return result;
  6964. }
  6965. function parseTypeArgumentsInExpression() {
  6966. if (!parseOptional(24)) {
  6967. return undefined;
  6968. }
  6969. var typeArguments = parseDelimitedList(17, parseType);
  6970. if (!parseExpected(25)) {
  6971. return undefined;
  6972. }
  6973. return typeArguments && canFollowTypeArgumentsInExpression()
  6974. ? typeArguments
  6975. : undefined;
  6976. }
  6977. function canFollowTypeArgumentsInExpression() {
  6978. switch (token) {
  6979. case 16:
  6980. case 20:
  6981. case 17:
  6982. case 19:
  6983. case 51:
  6984. case 22:
  6985. case 50:
  6986. case 28:
  6987. case 30:
  6988. case 29:
  6989. case 31:
  6990. case 48:
  6991. case 49:
  6992. case 45:
  6993. case 43:
  6994. case 44:
  6995. case 15:
  6996. case 1:
  6997. return true;
  6998. case 23:
  6999. case 14:
  7000. default:
  7001. return false;
  7002. }
  7003. }
  7004. function parsePrimaryExpression() {
  7005. switch (token) {
  7006. case 7:
  7007. case 8:
  7008. case 10:
  7009. return parseLiteralNode();
  7010. case 93:
  7011. case 91:
  7012. case 89:
  7013. case 95:
  7014. case 80:
  7015. return parseTokenNode();
  7016. case 16:
  7017. return parseParenthesizedExpression();
  7018. case 18:
  7019. return parseArrayLiteralExpression();
  7020. case 14:
  7021. return parseObjectLiteralExpression();
  7022. case 69:
  7023. return parseClassExpression();
  7024. case 83:
  7025. return parseFunctionExpression();
  7026. case 88:
  7027. return parseNewExpression();
  7028. case 36:
  7029. case 57:
  7030. if (reScanSlashToken() === 9) {
  7031. return parseLiteralNode();
  7032. }
  7033. break;
  7034. case 11:
  7035. return parseTemplateExpression();
  7036. }
  7037. return parseIdentifier(ts.Diagnostics.Expression_expected);
  7038. }
  7039. function parseParenthesizedExpression() {
  7040. var node = createNode(162);
  7041. parseExpected(16);
  7042. node.expression = allowInAnd(parseExpression);
  7043. parseExpected(17);
  7044. return finishNode(node);
  7045. }
  7046. function parseSpreadElement() {
  7047. var node = createNode(174);
  7048. parseExpected(21);
  7049. node.expression = parseAssignmentExpressionOrHigher();
  7050. return finishNode(node);
  7051. }
  7052. function parseArgumentOrArrayLiteralElement() {
  7053. return token === 21 ? parseSpreadElement() :
  7054. token === 23 ? createNode(176) :
  7055. parseAssignmentExpressionOrHigher();
  7056. }
  7057. function parseArgumentExpression() {
  7058. return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
  7059. }
  7060. function parseArrayLiteralExpression() {
  7061. var node = createNode(154);
  7062. parseExpected(18);
  7063. if (scanner.hasPrecedingLineBreak())
  7064. node.flags |= 512;
  7065. node.elements = parseDelimitedList(14, parseArgumentOrArrayLiteralElement);
  7066. parseExpected(19);
  7067. return finishNode(node);
  7068. }
  7069. function tryParseAccessorDeclaration(fullStart, decorators, modifiers) {
  7070. if (parseContextualModifier(116)) {
  7071. return parseAccessorDeclaration(137, fullStart, decorators, modifiers);
  7072. }
  7073. else if (parseContextualModifier(121)) {
  7074. return parseAccessorDeclaration(138, fullStart, decorators, modifiers);
  7075. }
  7076. return undefined;
  7077. }
  7078. function parseObjectLiteralElement() {
  7079. var fullStart = scanner.getStartPos();
  7080. var decorators = parseDecorators();
  7081. var modifiers = parseModifiers();
  7082. var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
  7083. if (accessor) {
  7084. return accessor;
  7085. }
  7086. var asteriskToken = parseOptionalToken(35);
  7087. var tokenIsIdentifier = isIdentifier();
  7088. var nameToken = token;
  7089. var propertyName = parsePropertyName();
  7090. var questionToken = parseOptionalToken(50);
  7091. if (asteriskToken || token === 16 || token === 24) {
  7092. return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken);
  7093. }
  7094. if ((token === 23 || token === 15) && tokenIsIdentifier) {
  7095. var shorthandDeclaration = createNode(226, fullStart);
  7096. shorthandDeclaration.name = propertyName;
  7097. shorthandDeclaration.questionToken = questionToken;
  7098. return finishNode(shorthandDeclaration);
  7099. }
  7100. else {
  7101. var propertyAssignment = createNode(225, fullStart);
  7102. propertyAssignment.name = propertyName;
  7103. propertyAssignment.questionToken = questionToken;
  7104. parseExpected(51);
  7105. propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
  7106. return finishNode(propertyAssignment);
  7107. }
  7108. }
  7109. function parseObjectLiteralExpression() {
  7110. var node = createNode(155);
  7111. parseExpected(14);
  7112. if (scanner.hasPrecedingLineBreak()) {
  7113. node.flags |= 512;
  7114. }
  7115. node.properties = parseDelimitedList(13, parseObjectLiteralElement, true);
  7116. parseExpected(15);
  7117. return finishNode(node);
  7118. }
  7119. function parseFunctionExpression() {
  7120. var saveDecoratorContext = inDecoratorContext();
  7121. if (saveDecoratorContext) {
  7122. setDecoratorContext(false);
  7123. }
  7124. var node = createNode(163);
  7125. parseExpected(83);
  7126. node.asteriskToken = parseOptionalToken(35);
  7127. node.name = node.asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier();
  7128. fillSignature(51, !!node.asteriskToken, false, node);
  7129. node.body = parseFunctionBlock(!!node.asteriskToken, false);
  7130. if (saveDecoratorContext) {
  7131. setDecoratorContext(true);
  7132. }
  7133. return finishNode(node);
  7134. }
  7135. function parseOptionalIdentifier() {
  7136. return isIdentifier() ? parseIdentifier() : undefined;
  7137. }
  7138. function parseNewExpression() {
  7139. var node = createNode(159);
  7140. parseExpected(88);
  7141. node.expression = parseMemberExpressionOrHigher();
  7142. node.typeArguments = tryParse(parseTypeArgumentsInExpression);
  7143. if (node.typeArguments || token === 16) {
  7144. node.arguments = parseArgumentList();
  7145. }
  7146. return finishNode(node);
  7147. }
  7148. function parseBlock(ignoreMissingOpenBrace, checkForStrictMode, diagnosticMessage) {
  7149. var node = createNode(180);
  7150. if (parseExpected(14, diagnosticMessage) || ignoreMissingOpenBrace) {
  7151. node.statements = parseList(2, checkForStrictMode, parseStatement);
  7152. parseExpected(15);
  7153. }
  7154. else {
  7155. node.statements = createMissingList();
  7156. }
  7157. return finishNode(node);
  7158. }
  7159. function parseFunctionBlock(allowYield, ignoreMissingOpenBrace, diagnosticMessage) {
  7160. var savedYieldContext = inYieldContext();
  7161. setYieldContext(allowYield);
  7162. var saveDecoratorContext = inDecoratorContext();
  7163. if (saveDecoratorContext) {
  7164. setDecoratorContext(false);
  7165. }
  7166. var block = parseBlock(ignoreMissingOpenBrace, true, diagnosticMessage);
  7167. if (saveDecoratorContext) {
  7168. setDecoratorContext(true);
  7169. }
  7170. setYieldContext(savedYieldContext);
  7171. return block;
  7172. }
  7173. function parseEmptyStatement() {
  7174. var node = createNode(182);
  7175. parseExpected(22);
  7176. return finishNode(node);
  7177. }
  7178. function parseIfStatement() {
  7179. var node = createNode(184);
  7180. parseExpected(84);
  7181. parseExpected(16);
  7182. node.expression = allowInAnd(parseExpression);
  7183. parseExpected(17);
  7184. node.thenStatement = parseStatement();
  7185. node.elseStatement = parseOptional(76) ? parseStatement() : undefined;
  7186. return finishNode(node);
  7187. }
  7188. function parseDoStatement() {
  7189. var node = createNode(185);
  7190. parseExpected(75);
  7191. node.statement = parseStatement();
  7192. parseExpected(100);
  7193. parseExpected(16);
  7194. node.expression = allowInAnd(parseExpression);
  7195. parseExpected(17);
  7196. parseOptional(22);
  7197. return finishNode(node);
  7198. }
  7199. function parseWhileStatement() {
  7200. var node = createNode(186);
  7201. parseExpected(100);
  7202. parseExpected(16);
  7203. node.expression = allowInAnd(parseExpression);
  7204. parseExpected(17);
  7205. node.statement = parseStatement();
  7206. return finishNode(node);
  7207. }
  7208. function parseForOrForInOrForOfStatement() {
  7209. var pos = getNodePos();
  7210. parseExpected(82);
  7211. parseExpected(16);
  7212. var initializer = undefined;
  7213. if (token !== 22) {
  7214. if (token === 98 || token === 104 || token === 70) {
  7215. initializer = parseVariableDeclarationList(true);
  7216. }
  7217. else {
  7218. initializer = disallowInAnd(parseExpression);
  7219. }
  7220. }
  7221. var forOrForInOrForOfStatement;
  7222. if (parseOptional(86)) {
  7223. var forInStatement = createNode(188, pos);
  7224. forInStatement.initializer = initializer;
  7225. forInStatement.expression = allowInAnd(parseExpression);
  7226. parseExpected(17);
  7227. forOrForInOrForOfStatement = forInStatement;
  7228. }
  7229. else if (parseOptional(126)) {
  7230. var forOfStatement = createNode(189, pos);
  7231. forOfStatement.initializer = initializer;
  7232. forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher);
  7233. parseExpected(17);
  7234. forOrForInOrForOfStatement = forOfStatement;
  7235. }
  7236. else {
  7237. var forStatement = createNode(187, pos);
  7238. forStatement.initializer = initializer;
  7239. parseExpected(22);
  7240. if (token !== 22 && token !== 17) {
  7241. forStatement.condition = allowInAnd(parseExpression);
  7242. }
  7243. parseExpected(22);
  7244. if (token !== 17) {
  7245. forStatement.incrementor = allowInAnd(parseExpression);
  7246. }
  7247. parseExpected(17);
  7248. forOrForInOrForOfStatement = forStatement;
  7249. }
  7250. forOrForInOrForOfStatement.statement = parseStatement();
  7251. return finishNode(forOrForInOrForOfStatement);
  7252. }
  7253. function parseBreakOrContinueStatement(kind) {
  7254. var node = createNode(kind);
  7255. parseExpected(kind === 191 ? 66 : 71);
  7256. if (!canParseSemicolon()) {
  7257. node.label = parseIdentifier();
  7258. }
  7259. parseSemicolon();
  7260. return finishNode(node);
  7261. }
  7262. function parseReturnStatement() {
  7263. var node = createNode(192);
  7264. parseExpected(90);
  7265. if (!canParseSemicolon()) {
  7266. node.expression = allowInAnd(parseExpression);
  7267. }
  7268. parseSemicolon();
  7269. return finishNode(node);
  7270. }
  7271. function parseWithStatement() {
  7272. var node = createNode(193);
  7273. parseExpected(101);
  7274. parseExpected(16);
  7275. node.expression = allowInAnd(parseExpression);
  7276. parseExpected(17);
  7277. node.statement = parseStatement();
  7278. return finishNode(node);
  7279. }
  7280. function parseCaseClause() {
  7281. var node = createNode(221);
  7282. parseExpected(67);
  7283. node.expression = allowInAnd(parseExpression);
  7284. parseExpected(51);
  7285. node.statements = parseList(4, false, parseStatement);
  7286. return finishNode(node);
  7287. }
  7288. function parseDefaultClause() {
  7289. var node = createNode(222);
  7290. parseExpected(73);
  7291. parseExpected(51);
  7292. node.statements = parseList(4, false, parseStatement);
  7293. return finishNode(node);
  7294. }
  7295. function parseCaseOrDefaultClause() {
  7296. return token === 67 ? parseCaseClause() : parseDefaultClause();
  7297. }
  7298. function parseSwitchStatement() {
  7299. var node = createNode(194);
  7300. parseExpected(92);
  7301. parseExpected(16);
  7302. node.expression = allowInAnd(parseExpression);
  7303. parseExpected(17);
  7304. var caseBlock = createNode(208, scanner.getStartPos());
  7305. parseExpected(14);
  7306. caseBlock.clauses = parseList(3, false, parseCaseOrDefaultClause);
  7307. parseExpected(15);
  7308. node.caseBlock = finishNode(caseBlock);
  7309. return finishNode(node);
  7310. }
  7311. function parseThrowStatement() {
  7312. // ThrowStatement[Yield] :
  7313. // throw [no LineTerminator here]Expression[In, ?Yield];
  7314. var node = createNode(196);
  7315. parseExpected(94);
  7316. node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression);
  7317. parseSemicolon();
  7318. return finishNode(node);
  7319. }
  7320. function parseTryStatement() {
  7321. var node = createNode(197);
  7322. parseExpected(96);
  7323. node.tryBlock = parseBlock(false, false);
  7324. node.catchClause = token === 68 ? parseCatchClause() : undefined;
  7325. if (!node.catchClause || token === 81) {
  7326. parseExpected(81);
  7327. node.finallyBlock = parseBlock(false, false);
  7328. }
  7329. return finishNode(node);
  7330. }
  7331. function parseCatchClause() {
  7332. var result = createNode(224);
  7333. parseExpected(68);
  7334. if (parseExpected(16)) {
  7335. result.variableDeclaration = parseVariableDeclaration();
  7336. }
  7337. parseExpected(17);
  7338. result.block = parseBlock(false, false);
  7339. return finishNode(result);
  7340. }
  7341. function parseDebuggerStatement() {
  7342. var node = createNode(198);
  7343. parseExpected(72);
  7344. parseSemicolon();
  7345. return finishNode(node);
  7346. }
  7347. function parseExpressionOrLabeledStatement() {
  7348. var fullStart = scanner.getStartPos();
  7349. var expression = allowInAnd(parseExpression);
  7350. if (expression.kind === 65 && parseOptional(51)) {
  7351. var labeledStatement = createNode(195, fullStart);
  7352. labeledStatement.label = expression;
  7353. labeledStatement.statement = parseStatement();
  7354. return finishNode(labeledStatement);
  7355. }
  7356. else {
  7357. var expressionStatement = createNode(183, fullStart);
  7358. expressionStatement.expression = expression;
  7359. parseSemicolon();
  7360. return finishNode(expressionStatement);
  7361. }
  7362. }
  7363. function isStartOfStatement(inErrorRecovery) {
  7364. if (ts.isModifier(token)) {
  7365. var result = lookAhead(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers);
  7366. if (result) {
  7367. return true;
  7368. }
  7369. }
  7370. switch (token) {
  7371. case 22:
  7372. return !inErrorRecovery;
  7373. case 14:
  7374. case 98:
  7375. case 104:
  7376. case 83:
  7377. case 69:
  7378. case 84:
  7379. case 75:
  7380. case 100:
  7381. case 82:
  7382. case 71:
  7383. case 66:
  7384. case 90:
  7385. case 101:
  7386. case 92:
  7387. case 94:
  7388. case 96:
  7389. case 72:
  7390. case 68:
  7391. case 81:
  7392. return true;
  7393. case 70:
  7394. var isConstEnum = lookAhead(nextTokenIsEnumKeyword);
  7395. return !isConstEnum;
  7396. case 103:
  7397. case 117:
  7398. case 118:
  7399. case 77:
  7400. case 124:
  7401. if (isDeclarationStart()) {
  7402. return false;
  7403. }
  7404. case 108:
  7405. case 106:
  7406. case 107:
  7407. case 109:
  7408. if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) {
  7409. return false;
  7410. }
  7411. default:
  7412. return isStartOfExpression();
  7413. }
  7414. }
  7415. function nextTokenIsEnumKeyword() {
  7416. nextToken();
  7417. return token === 77;
  7418. }
  7419. function nextTokenIsIdentifierOrKeywordOnSameLine() {
  7420. nextToken();
  7421. return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
  7422. }
  7423. function parseStatement() {
  7424. switch (token) {
  7425. case 14:
  7426. return parseBlock(false, false);
  7427. case 98:
  7428. case 70:
  7429. return parseVariableStatement(scanner.getStartPos(), undefined, undefined);
  7430. case 83:
  7431. return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined);
  7432. case 69:
  7433. return parseClassDeclaration(scanner.getStartPos(), undefined, undefined);
  7434. case 22:
  7435. return parseEmptyStatement();
  7436. case 84:
  7437. return parseIfStatement();
  7438. case 75:
  7439. return parseDoStatement();
  7440. case 100:
  7441. return parseWhileStatement();
  7442. case 82:
  7443. return parseForOrForInOrForOfStatement();
  7444. case 71:
  7445. return parseBreakOrContinueStatement(190);
  7446. case 66:
  7447. return parseBreakOrContinueStatement(191);
  7448. case 90:
  7449. return parseReturnStatement();
  7450. case 101:
  7451. return parseWithStatement();
  7452. case 92:
  7453. return parseSwitchStatement();
  7454. case 94:
  7455. return parseThrowStatement();
  7456. case 96:
  7457. case 68:
  7458. case 81:
  7459. return parseTryStatement();
  7460. case 72:
  7461. return parseDebuggerStatement();
  7462. case 104:
  7463. if (isLetDeclaration()) {
  7464. return parseVariableStatement(scanner.getStartPos(), undefined, undefined);
  7465. }
  7466. default:
  7467. if (ts.isModifier(token) || token === 52) {
  7468. var result = tryParse(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers);
  7469. if (result) {
  7470. return result;
  7471. }
  7472. }
  7473. return parseExpressionOrLabeledStatement();
  7474. }
  7475. }
  7476. function parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers() {
  7477. var start = scanner.getStartPos();
  7478. var decorators = parseDecorators();
  7479. var modifiers = parseModifiers();
  7480. switch (token) {
  7481. case 70:
  7482. var nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword);
  7483. if (nextTokenIsEnum) {
  7484. return undefined;
  7485. }
  7486. return parseVariableStatement(start, decorators, modifiers);
  7487. case 104:
  7488. if (!isLetDeclaration()) {
  7489. return undefined;
  7490. }
  7491. return parseVariableStatement(start, decorators, modifiers);
  7492. case 98:
  7493. return parseVariableStatement(start, decorators, modifiers);
  7494. case 83:
  7495. return parseFunctionDeclaration(start, decorators, modifiers);
  7496. case 69:
  7497. return parseClassDeclaration(start, decorators, modifiers);
  7498. }
  7499. return undefined;
  7500. }
  7501. function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) {
  7502. if (token !== 14 && canParseSemicolon()) {
  7503. parseSemicolon();
  7504. return;
  7505. }
  7506. return parseFunctionBlock(isGenerator, false, diagnosticMessage);
  7507. }
  7508. function parseArrayBindingElement() {
  7509. if (token === 23) {
  7510. return createNode(176);
  7511. }
  7512. var node = createNode(153);
  7513. node.dotDotDotToken = parseOptionalToken(21);
  7514. node.name = parseIdentifierOrPattern();
  7515. node.initializer = parseInitializer(false);
  7516. return finishNode(node);
  7517. }
  7518. function parseObjectBindingElement() {
  7519. var node = createNode(153);
  7520. var tokenIsIdentifier = isIdentifier();
  7521. var propertyName = parsePropertyName();
  7522. if (tokenIsIdentifier && token !== 51) {
  7523. node.name = propertyName;
  7524. }
  7525. else {
  7526. parseExpected(51);
  7527. node.propertyName = propertyName;
  7528. node.name = parseIdentifierOrPattern();
  7529. }
  7530. node.initializer = parseInitializer(false);
  7531. return finishNode(node);
  7532. }
  7533. function parseObjectBindingPattern() {
  7534. var node = createNode(151);
  7535. parseExpected(14);
  7536. node.elements = parseDelimitedList(10, parseObjectBindingElement);
  7537. parseExpected(15);
  7538. return finishNode(node);
  7539. }
  7540. function parseArrayBindingPattern() {
  7541. var node = createNode(152);
  7542. parseExpected(18);
  7543. node.elements = parseDelimitedList(11, parseArrayBindingElement);
  7544. parseExpected(19);
  7545. return finishNode(node);
  7546. }
  7547. function isIdentifierOrPattern() {
  7548. return token === 14 || token === 18 || isIdentifier();
  7549. }
  7550. function parseIdentifierOrPattern() {
  7551. if (token === 18) {
  7552. return parseArrayBindingPattern();
  7553. }
  7554. if (token === 14) {
  7555. return parseObjectBindingPattern();
  7556. }
  7557. return parseIdentifier();
  7558. }
  7559. function parseVariableDeclaration() {
  7560. var node = createNode(199);
  7561. node.name = parseIdentifierOrPattern();
  7562. node.type = parseTypeAnnotation();
  7563. if (!isInOrOfKeyword(token)) {
  7564. node.initializer = parseInitializer(false);
  7565. }
  7566. return finishNode(node);
  7567. }
  7568. function parseVariableDeclarationList(inForStatementInitializer) {
  7569. var node = createNode(200);
  7570. switch (token) {
  7571. case 98:
  7572. break;
  7573. case 104:
  7574. node.flags |= 4096;
  7575. break;
  7576. case 70:
  7577. node.flags |= 8192;
  7578. break;
  7579. default:
  7580. ts.Debug.fail();
  7581. }
  7582. nextToken();
  7583. if (token === 126 && lookAhead(canFollowContextualOfKeyword)) {
  7584. node.declarations = createMissingList();
  7585. }
  7586. else {
  7587. var savedDisallowIn = inDisallowInContext();
  7588. setDisallowInContext(inForStatementInitializer);
  7589. node.declarations = parseDelimitedList(9, parseVariableDeclaration);
  7590. setDisallowInContext(savedDisallowIn);
  7591. }
  7592. return finishNode(node);
  7593. }
  7594. function canFollowContextualOfKeyword() {
  7595. return nextTokenIsIdentifier() && nextToken() === 17;
  7596. }
  7597. function parseVariableStatement(fullStart, decorators, modifiers) {
  7598. var node = createNode(181, fullStart);
  7599. node.decorators = decorators;
  7600. setModifiers(node, modifiers);
  7601. node.declarationList = parseVariableDeclarationList(false);
  7602. parseSemicolon();
  7603. return finishNode(node);
  7604. }
  7605. function parseFunctionDeclaration(fullStart, decorators, modifiers) {
  7606. var node = createNode(201, fullStart);
  7607. node.decorators = decorators;
  7608. setModifiers(node, modifiers);
  7609. parseExpected(83);
  7610. node.asteriskToken = parseOptionalToken(35);
  7611. node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier();
  7612. fillSignature(51, !!node.asteriskToken, false, node);
  7613. node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected);
  7614. return finishNode(node);
  7615. }
  7616. function parseConstructorDeclaration(pos, decorators, modifiers) {
  7617. var node = createNode(136, pos);
  7618. node.decorators = decorators;
  7619. setModifiers(node, modifiers);
  7620. parseExpected(114);
  7621. fillSignature(51, false, false, node);
  7622. node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected);
  7623. return finishNode(node);
  7624. }
  7625. function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) {
  7626. var method = createNode(135, fullStart);
  7627. method.decorators = decorators;
  7628. setModifiers(method, modifiers);
  7629. method.asteriskToken = asteriskToken;
  7630. method.name = name;
  7631. method.questionToken = questionToken;
  7632. fillSignature(51, !!asteriskToken, false, method);
  7633. method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, diagnosticMessage);
  7634. return finishNode(method);
  7635. }
  7636. function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) {
  7637. var property = createNode(133, fullStart);
  7638. property.decorators = decorators;
  7639. setModifiers(property, modifiers);
  7640. property.name = name;
  7641. property.questionToken = questionToken;
  7642. property.type = parseTypeAnnotation();
  7643. property.initializer = allowInAnd(parseNonParameterInitializer);
  7644. parseSemicolon();
  7645. return finishNode(property);
  7646. }
  7647. function parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers) {
  7648. var asteriskToken = parseOptionalToken(35);
  7649. var name = parsePropertyName();
  7650. var questionToken = parseOptionalToken(50);
  7651. if (asteriskToken || token === 16 || token === 24) {
  7652. return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected);
  7653. }
  7654. else {
  7655. return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken);
  7656. }
  7657. }
  7658. function parseNonParameterInitializer() {
  7659. return parseInitializer(false);
  7660. }
  7661. function parseAccessorDeclaration(kind, fullStart, decorators, modifiers) {
  7662. var node = createNode(kind, fullStart);
  7663. node.decorators = decorators;
  7664. setModifiers(node, modifiers);
  7665. node.name = parsePropertyName();
  7666. fillSignature(51, false, false, node);
  7667. node.body = parseFunctionBlockOrSemicolon(false);
  7668. return finishNode(node);
  7669. }
  7670. function isClassMemberModifier(idToken) {
  7671. switch (idToken) {
  7672. case 108:
  7673. case 106:
  7674. case 107:
  7675. case 109:
  7676. return true;
  7677. default:
  7678. return false;
  7679. }
  7680. }
  7681. function isClassMemberStart() {
  7682. var idToken;
  7683. if (token === 52) {
  7684. return true;
  7685. }
  7686. while (ts.isModifier(token)) {
  7687. idToken = token;
  7688. if (isClassMemberModifier(idToken)) {
  7689. return true;
  7690. }
  7691. nextToken();
  7692. }
  7693. if (token === 35) {
  7694. return true;
  7695. }
  7696. if (isLiteralPropertyName()) {
  7697. idToken = token;
  7698. nextToken();
  7699. }
  7700. if (token === 18) {
  7701. return true;
  7702. }
  7703. if (idToken !== undefined) {
  7704. if (!ts.isKeyword(idToken) || idToken === 121 || idToken === 116) {
  7705. return true;
  7706. }
  7707. switch (token) {
  7708. case 16:
  7709. case 24:
  7710. case 51:
  7711. case 53:
  7712. case 50:
  7713. return true;
  7714. default:
  7715. return canParseSemicolon();
  7716. }
  7717. }
  7718. return false;
  7719. }
  7720. function parseDecorators() {
  7721. var decorators;
  7722. while (true) {
  7723. var decoratorStart = getNodePos();
  7724. if (!parseOptional(52)) {
  7725. break;
  7726. }
  7727. if (!decorators) {
  7728. decorators = [];
  7729. decorators.pos = scanner.getStartPos();
  7730. }
  7731. var decorator = createNode(131, decoratorStart);
  7732. decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher);
  7733. decorators.push(finishNode(decorator));
  7734. }
  7735. if (decorators) {
  7736. decorators.end = getNodeEnd();
  7737. }
  7738. return decorators;
  7739. }
  7740. function parseModifiers() {
  7741. var flags = 0;
  7742. var modifiers;
  7743. while (true) {
  7744. var modifierStart = scanner.getStartPos();
  7745. var modifierKind = token;
  7746. if (!parseAnyContextualModifier()) {
  7747. break;
  7748. }
  7749. if (!modifiers) {
  7750. modifiers = [];
  7751. modifiers.pos = modifierStart;
  7752. }
  7753. flags |= ts.modifierToFlag(modifierKind);
  7754. modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
  7755. }
  7756. if (modifiers) {
  7757. modifiers.flags = flags;
  7758. modifiers.end = scanner.getStartPos();
  7759. }
  7760. return modifiers;
  7761. }
  7762. function parseClassElement() {
  7763. if (token === 22) {
  7764. var result = createNode(179);
  7765. nextToken();
  7766. return finishNode(result);
  7767. }
  7768. var fullStart = getNodePos();
  7769. var decorators = parseDecorators();
  7770. var modifiers = parseModifiers();
  7771. var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
  7772. if (accessor) {
  7773. return accessor;
  7774. }
  7775. if (token === 114) {
  7776. return parseConstructorDeclaration(fullStart, decorators, modifiers);
  7777. }
  7778. if (isIndexSignature()) {
  7779. return parseIndexSignatureDeclaration(fullStart, decorators, modifiers);
  7780. }
  7781. if (isIdentifierOrKeyword() ||
  7782. token === 8 ||
  7783. token === 7 ||
  7784. token === 35 ||
  7785. token === 18) {
  7786. return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers);
  7787. }
  7788. if (decorators || modifiers) {
  7789. var name_3 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected);
  7790. return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined);
  7791. }
  7792. ts.Debug.fail("Should not have attempted to parse class member declaration.");
  7793. }
  7794. function parseClassExpression() {
  7795. return parseClassDeclarationOrExpression(scanner.getStartPos(), undefined, undefined, 175);
  7796. }
  7797. function parseClassDeclaration(fullStart, decorators, modifiers) {
  7798. return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 202);
  7799. }
  7800. function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) {
  7801. var savedStrictModeContext = inStrictModeContext();
  7802. setStrictModeContext(true);
  7803. var node = createNode(kind, fullStart);
  7804. node.decorators = decorators;
  7805. setModifiers(node, modifiers);
  7806. parseExpected(69);
  7807. node.name = parseOptionalIdentifier();
  7808. node.typeParameters = parseTypeParameters();
  7809. node.heritageClauses = parseHeritageClauses(true);
  7810. if (parseExpected(14)) {
  7811. node.members = inGeneratorParameterContext()
  7812. ? doOutsideOfYieldContext(parseClassMembers)
  7813. : parseClassMembers();
  7814. parseExpected(15);
  7815. }
  7816. else {
  7817. node.members = createMissingList();
  7818. }
  7819. var finishedNode = finishNode(node);
  7820. setStrictModeContext(savedStrictModeContext);
  7821. return finishedNode;
  7822. }
  7823. function parseHeritageClauses(isClassHeritageClause) {
  7824. // ClassTail[Yield,GeneratorParameter] : See 14.5
  7825. // [~GeneratorParameter]ClassHeritage[?Yield]opt { ClassBody[?Yield]opt }
  7826. // [+GeneratorParameter] ClassHeritageopt { ClassBodyopt }
  7827. if (isHeritageClause()) {
  7828. return isClassHeritageClause && inGeneratorParameterContext()
  7829. ? doOutsideOfYieldContext(parseHeritageClausesWorker)
  7830. : parseHeritageClausesWorker();
  7831. }
  7832. return undefined;
  7833. }
  7834. function parseHeritageClausesWorker() {
  7835. return parseList(19, false, parseHeritageClause);
  7836. }
  7837. function parseHeritageClause() {
  7838. if (token === 79 || token === 102) {
  7839. var node = createNode(223);
  7840. node.token = token;
  7841. nextToken();
  7842. node.types = parseDelimitedList(8, parseExpressionWithTypeArguments);
  7843. return finishNode(node);
  7844. }
  7845. return undefined;
  7846. }
  7847. function parseExpressionWithTypeArguments() {
  7848. var node = createNode(177);
  7849. node.expression = parseLeftHandSideExpressionOrHigher();
  7850. if (token === 24) {
  7851. node.typeArguments = parseBracketedList(17, parseType, 24, 25);
  7852. }
  7853. return finishNode(node);
  7854. }
  7855. function isHeritageClause() {
  7856. return token === 79 || token === 102;
  7857. }
  7858. function parseClassMembers() {
  7859. return parseList(6, false, parseClassElement);
  7860. }
  7861. function parseInterfaceDeclaration(fullStart, decorators, modifiers) {
  7862. var node = createNode(203, fullStart);
  7863. node.decorators = decorators;
  7864. setModifiers(node, modifiers);
  7865. parseExpected(103);
  7866. node.name = parseIdentifier();
  7867. node.typeParameters = parseTypeParameters();
  7868. node.heritageClauses = parseHeritageClauses(false);
  7869. node.members = parseObjectTypeMembers();
  7870. return finishNode(node);
  7871. }
  7872. function parseTypeAliasDeclaration(fullStart, decorators, modifiers) {
  7873. var node = createNode(204, fullStart);
  7874. node.decorators = decorators;
  7875. setModifiers(node, modifiers);
  7876. parseExpected(124);
  7877. node.name = parseIdentifier();
  7878. parseExpected(53);
  7879. node.type = parseType();
  7880. parseSemicolon();
  7881. return finishNode(node);
  7882. }
  7883. function parseEnumMember() {
  7884. var node = createNode(227, scanner.getStartPos());
  7885. node.name = parsePropertyName();
  7886. node.initializer = allowInAnd(parseNonParameterInitializer);
  7887. return finishNode(node);
  7888. }
  7889. function parseEnumDeclaration(fullStart, decorators, modifiers) {
  7890. var node = createNode(205, fullStart);
  7891. node.decorators = decorators;
  7892. setModifiers(node, modifiers);
  7893. parseExpected(77);
  7894. node.name = parseIdentifier();
  7895. if (parseExpected(14)) {
  7896. node.members = parseDelimitedList(7, parseEnumMember);
  7897. parseExpected(15);
  7898. }
  7899. else {
  7900. node.members = createMissingList();
  7901. }
  7902. return finishNode(node);
  7903. }
  7904. function parseModuleBlock() {
  7905. var node = createNode(207, scanner.getStartPos());
  7906. if (parseExpected(14)) {
  7907. node.statements = parseList(1, false, parseModuleElement);
  7908. parseExpected(15);
  7909. }
  7910. else {
  7911. node.statements = createMissingList();
  7912. }
  7913. return finishNode(node);
  7914. }
  7915. function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) {
  7916. var node = createNode(206, fullStart);
  7917. node.decorators = decorators;
  7918. setModifiers(node, modifiers);
  7919. node.flags |= flags;
  7920. node.name = parseIdentifier();
  7921. node.body = parseOptional(20)
  7922. ? parseModuleOrNamespaceDeclaration(getNodePos(), undefined, undefined, 1)
  7923. : parseModuleBlock();
  7924. return finishNode(node);
  7925. }
  7926. function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) {
  7927. var node = createNode(206, fullStart);
  7928. node.decorators = decorators;
  7929. setModifiers(node, modifiers);
  7930. node.name = parseLiteralNode(true);
  7931. node.body = parseModuleBlock();
  7932. return finishNode(node);
  7933. }
  7934. function parseModuleDeclaration(fullStart, decorators, modifiers) {
  7935. var flags = modifiers ? modifiers.flags : 0;
  7936. if (parseOptional(118)) {
  7937. flags |= 32768;
  7938. }
  7939. else {
  7940. parseExpected(117);
  7941. if (token === 8) {
  7942. return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers);
  7943. }
  7944. }
  7945. return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags);
  7946. }
  7947. function isExternalModuleReference() {
  7948. return token === 119 &&
  7949. lookAhead(nextTokenIsOpenParen);
  7950. }
  7951. function nextTokenIsOpenParen() {
  7952. return nextToken() === 16;
  7953. }
  7954. function nextTokenIsCommaOrFromKeyword() {
  7955. nextToken();
  7956. return token === 23 ||
  7957. token === 125;
  7958. }
  7959. function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) {
  7960. parseExpected(85);
  7961. var afterImportPos = scanner.getStartPos();
  7962. var identifier;
  7963. if (isIdentifier()) {
  7964. identifier = parseIdentifier();
  7965. if (token !== 23 && token !== 125) {
  7966. var importEqualsDeclaration = createNode(209, fullStart);
  7967. importEqualsDeclaration.decorators = decorators;
  7968. setModifiers(importEqualsDeclaration, modifiers);
  7969. importEqualsDeclaration.name = identifier;
  7970. parseExpected(53);
  7971. importEqualsDeclaration.moduleReference = parseModuleReference();
  7972. parseSemicolon();
  7973. return finishNode(importEqualsDeclaration);
  7974. }
  7975. }
  7976. var importDeclaration = createNode(210, fullStart);
  7977. importDeclaration.decorators = decorators;
  7978. setModifiers(importDeclaration, modifiers);
  7979. if (identifier ||
  7980. token === 35 ||
  7981. token === 14) {
  7982. importDeclaration.importClause = parseImportClause(identifier, afterImportPos);
  7983. parseExpected(125);
  7984. }
  7985. importDeclaration.moduleSpecifier = parseModuleSpecifier();
  7986. parseSemicolon();
  7987. return finishNode(importDeclaration);
  7988. }
  7989. function parseImportClause(identifier, fullStart) {
  7990. //ImportClause:
  7991. // ImportedDefaultBinding
  7992. // NameSpaceImport
  7993. // NamedImports
  7994. // ImportedDefaultBinding, NameSpaceImport
  7995. // ImportedDefaultBinding, NamedImports
  7996. var importClause = createNode(211, fullStart);
  7997. if (identifier) {
  7998. importClause.name = identifier;
  7999. }
  8000. if (!importClause.name ||
  8001. parseOptional(23)) {
  8002. importClause.namedBindings = token === 35 ? parseNamespaceImport() : parseNamedImportsOrExports(213);
  8003. }
  8004. return finishNode(importClause);
  8005. }
  8006. function parseModuleReference() {
  8007. return isExternalModuleReference()
  8008. ? parseExternalModuleReference()
  8009. : parseEntityName(false);
  8010. }
  8011. function parseExternalModuleReference() {
  8012. var node = createNode(220);
  8013. parseExpected(119);
  8014. parseExpected(16);
  8015. node.expression = parseModuleSpecifier();
  8016. parseExpected(17);
  8017. return finishNode(node);
  8018. }
  8019. function parseModuleSpecifier() {
  8020. var result = parseExpression();
  8021. if (result.kind === 8) {
  8022. internIdentifier(result.text);
  8023. }
  8024. return result;
  8025. }
  8026. function parseNamespaceImport() {
  8027. var namespaceImport = createNode(212);
  8028. parseExpected(35);
  8029. parseExpected(111);
  8030. namespaceImport.name = parseIdentifier();
  8031. return finishNode(namespaceImport);
  8032. }
  8033. function parseNamedImportsOrExports(kind) {
  8034. var node = createNode(kind);
  8035. node.elements = parseBracketedList(20, kind === 213 ? parseImportSpecifier : parseExportSpecifier, 14, 15);
  8036. return finishNode(node);
  8037. }
  8038. function parseExportSpecifier() {
  8039. return parseImportOrExportSpecifier(218);
  8040. }
  8041. function parseImportSpecifier() {
  8042. return parseImportOrExportSpecifier(214);
  8043. }
  8044. function parseImportOrExportSpecifier(kind) {
  8045. var node = createNode(kind);
  8046. var checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
  8047. var checkIdentifierStart = scanner.getTokenPos();
  8048. var checkIdentifierEnd = scanner.getTextPos();
  8049. var identifierName = parseIdentifierName();
  8050. if (token === 111) {
  8051. node.propertyName = identifierName;
  8052. parseExpected(111);
  8053. checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
  8054. checkIdentifierStart = scanner.getTokenPos();
  8055. checkIdentifierEnd = scanner.getTextPos();
  8056. node.name = parseIdentifierName();
  8057. }
  8058. else {
  8059. node.name = identifierName;
  8060. }
  8061. if (kind === 214 && checkIdentifierIsKeyword) {
  8062. parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected);
  8063. }
  8064. return finishNode(node);
  8065. }
  8066. function parseExportDeclaration(fullStart, decorators, modifiers) {
  8067. var node = createNode(216, fullStart);
  8068. node.decorators = decorators;
  8069. setModifiers(node, modifiers);
  8070. if (parseOptional(35)) {
  8071. parseExpected(125);
  8072. node.moduleSpecifier = parseModuleSpecifier();
  8073. }
  8074. else {
  8075. node.exportClause = parseNamedImportsOrExports(217);
  8076. if (parseOptional(125)) {
  8077. node.moduleSpecifier = parseModuleSpecifier();
  8078. }
  8079. }
  8080. parseSemicolon();
  8081. return finishNode(node);
  8082. }
  8083. function parseExportAssignment(fullStart, decorators, modifiers) {
  8084. var node = createNode(215, fullStart);
  8085. node.decorators = decorators;
  8086. setModifiers(node, modifiers);
  8087. if (parseOptional(53)) {
  8088. node.isExportEquals = true;
  8089. }
  8090. else {
  8091. parseExpected(73);
  8092. }
  8093. node.expression = parseAssignmentExpressionOrHigher();
  8094. parseSemicolon();
  8095. return finishNode(node);
  8096. }
  8097. function isLetDeclaration() {
  8098. return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine);
  8099. }
  8100. function isDeclarationStart(followsModifier) {
  8101. switch (token) {
  8102. case 98:
  8103. case 70:
  8104. case 83:
  8105. return true;
  8106. case 104:
  8107. return isLetDeclaration();
  8108. case 69:
  8109. case 103:
  8110. case 77:
  8111. case 124:
  8112. return lookAhead(nextTokenIsIdentifierOrKeyword);
  8113. case 85:
  8114. return lookAhead(nextTokenCanFollowImportKeyword);
  8115. case 117:
  8116. case 118:
  8117. return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral);
  8118. case 78:
  8119. return lookAhead(nextTokenCanFollowExportKeyword);
  8120. case 115:
  8121. case 108:
  8122. case 106:
  8123. case 107:
  8124. case 109:
  8125. return lookAhead(nextTokenIsDeclarationStart);
  8126. case 52:
  8127. return !followsModifier;
  8128. }
  8129. }
  8130. function isIdentifierOrKeyword() {
  8131. return token >= 65;
  8132. }
  8133. function nextTokenIsIdentifierOrKeyword() {
  8134. nextToken();
  8135. return isIdentifierOrKeyword();
  8136. }
  8137. function nextTokenIsIdentifierOrKeywordOrStringLiteral() {
  8138. nextToken();
  8139. return isIdentifierOrKeyword() || token === 8;
  8140. }
  8141. function nextTokenCanFollowImportKeyword() {
  8142. nextToken();
  8143. return isIdentifierOrKeyword() || token === 8 ||
  8144. token === 35 || token === 14;
  8145. }
  8146. function nextTokenCanFollowExportKeyword() {
  8147. nextToken();
  8148. return token === 53 || token === 35 ||
  8149. token === 14 || token === 73 || isDeclarationStart(true);
  8150. }
  8151. function nextTokenIsDeclarationStart() {
  8152. nextToken();
  8153. return isDeclarationStart(true);
  8154. }
  8155. function nextTokenIsAsKeyword() {
  8156. return nextToken() === 111;
  8157. }
  8158. function parseDeclaration() {
  8159. var fullStart = getNodePos();
  8160. var decorators = parseDecorators();
  8161. var modifiers = parseModifiers();
  8162. if (token === 78) {
  8163. nextToken();
  8164. if (token === 73 || token === 53) {
  8165. return parseExportAssignment(fullStart, decorators, modifiers);
  8166. }
  8167. if (token === 35 || token === 14) {
  8168. return parseExportDeclaration(fullStart, decorators, modifiers);
  8169. }
  8170. }
  8171. switch (token) {
  8172. case 98:
  8173. case 104:
  8174. case 70:
  8175. return parseVariableStatement(fullStart, decorators, modifiers);
  8176. case 83:
  8177. return parseFunctionDeclaration(fullStart, decorators, modifiers);
  8178. case 69:
  8179. return parseClassDeclaration(fullStart, decorators, modifiers);
  8180. case 103:
  8181. return parseInterfaceDeclaration(fullStart, decorators, modifiers);
  8182. case 124:
  8183. return parseTypeAliasDeclaration(fullStart, decorators, modifiers);
  8184. case 77:
  8185. return parseEnumDeclaration(fullStart, decorators, modifiers);
  8186. case 117:
  8187. case 118:
  8188. return parseModuleDeclaration(fullStart, decorators, modifiers);
  8189. case 85:
  8190. return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers);
  8191. default:
  8192. if (decorators || modifiers) {
  8193. var node = createMissingNode(219, true, ts.Diagnostics.Declaration_expected);
  8194. node.pos = fullStart;
  8195. node.decorators = decorators;
  8196. setModifiers(node, modifiers);
  8197. return finishNode(node);
  8198. }
  8199. ts.Debug.fail("Mismatch between isDeclarationStart and parseDeclaration");
  8200. }
  8201. }
  8202. function isSourceElement(inErrorRecovery) {
  8203. return isDeclarationStart() || isStartOfStatement(inErrorRecovery);
  8204. }
  8205. function parseSourceElement() {
  8206. return parseSourceElementOrModuleElement();
  8207. }
  8208. function parseModuleElement() {
  8209. return parseSourceElementOrModuleElement();
  8210. }
  8211. function parseSourceElementOrModuleElement() {
  8212. return isDeclarationStart()
  8213. ? parseDeclaration()
  8214. : parseStatement();
  8215. }
  8216. function processReferenceComments(sourceFile) {
  8217. var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText);
  8218. var referencedFiles = [];
  8219. var amdDependencies = [];
  8220. var amdModuleName;
  8221. while (true) {
  8222. var kind = triviaScanner.scan();
  8223. if (kind === 5 || kind === 4 || kind === 3) {
  8224. continue;
  8225. }
  8226. if (kind !== 2) {
  8227. break;
  8228. }
  8229. var range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos(), kind: triviaScanner.getToken() };
  8230. var comment = sourceText.substring(range.pos, range.end);
  8231. var referencePathMatchResult = ts.getFileReferenceFromReferencePath(comment, range);
  8232. if (referencePathMatchResult) {
  8233. var fileReference = referencePathMatchResult.fileReference;
  8234. sourceFile.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
  8235. var diagnosticMessage = referencePathMatchResult.diagnosticMessage;
  8236. if (fileReference) {
  8237. referencedFiles.push(fileReference);
  8238. }
  8239. if (diagnosticMessage) {
  8240. sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
  8241. }
  8242. }
  8243. else {
  8244. var amdModuleNameRegEx = /^\/\/\/\s*<amd-module\s+name\s*=\s*('|")(.+?)\1/gim;
  8245. var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
  8246. if (amdModuleNameMatchResult) {
  8247. if (amdModuleName) {
  8248. sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
  8249. }
  8250. amdModuleName = amdModuleNameMatchResult[2];
  8251. }
  8252. var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s/gim;
  8253. var pathRegex = /\spath\s*=\s*('|")(.+?)\1/gim;
  8254. var nameRegex = /\sname\s*=\s*('|")(.+?)\1/gim;
  8255. var amdDependencyMatchResult = amdDependencyRegEx.exec(comment);
  8256. if (amdDependencyMatchResult) {
  8257. var pathMatchResult = pathRegex.exec(comment);
  8258. var nameMatchResult = nameRegex.exec(comment);
  8259. if (pathMatchResult) {
  8260. var amdDependency = { path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
  8261. amdDependencies.push(amdDependency);
  8262. }
  8263. }
  8264. }
  8265. }
  8266. sourceFile.referencedFiles = referencedFiles;
  8267. sourceFile.amdDependencies = amdDependencies;
  8268. sourceFile.moduleName = amdModuleName;
  8269. }
  8270. function setExternalModuleIndicator(sourceFile) {
  8271. sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) {
  8272. return node.flags & 1
  8273. || node.kind === 209 && node.moduleReference.kind === 220
  8274. || node.kind === 210
  8275. || node.kind === 215
  8276. || node.kind === 216
  8277. ? node
  8278. : undefined;
  8279. });
  8280. }
  8281. })(Parser || (Parser = {}));
  8282. var IncrementalParser;
  8283. (function (IncrementalParser) {
  8284. function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
  8285. aggressiveChecks = aggressiveChecks || ts.Debug.shouldAssert(2);
  8286. checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks);
  8287. if (ts.textChangeRangeIsUnchanged(textChangeRange)) {
  8288. return sourceFile;
  8289. }
  8290. if (sourceFile.statements.length === 0) {
  8291. return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, undefined, true);
  8292. }
  8293. var incrementalSourceFile = sourceFile;
  8294. ts.Debug.assert(!incrementalSourceFile.hasBeenIncrementallyParsed);
  8295. incrementalSourceFile.hasBeenIncrementallyParsed = true;
  8296. var oldText = sourceFile.text;
  8297. var syntaxCursor = createSyntaxCursor(sourceFile);
  8298. var changeRange = extendToAffectedRange(sourceFile, textChangeRange);
  8299. checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks);
  8300. ts.Debug.assert(changeRange.span.start <= textChangeRange.span.start);
  8301. ts.Debug.assert(ts.textSpanEnd(changeRange.span) === ts.textSpanEnd(textChangeRange.span));
  8302. ts.Debug.assert(ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)) === ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)));
  8303. var delta = ts.textChangeRangeNewSpan(changeRange).length - changeRange.span.length;
  8304. updateTokenPositionsAndMarkElements(incrementalSourceFile, changeRange.span.start, ts.textSpanEnd(changeRange.span), ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)), delta, oldText, newText, aggressiveChecks);
  8305. var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, true);
  8306. return result;
  8307. }
  8308. IncrementalParser.updateSourceFile = updateSourceFile;
  8309. function moveElementEntirelyPastChangeRange(element, isArray, delta, oldText, newText, aggressiveChecks) {
  8310. if (isArray) {
  8311. visitArray(element);
  8312. }
  8313. else {
  8314. visitNode(element);
  8315. }
  8316. return;
  8317. function visitNode(node) {
  8318. if (aggressiveChecks && shouldCheckNode(node)) {
  8319. var text = oldText.substring(node.pos, node.end);
  8320. }
  8321. node._children = undefined;
  8322. node.pos += delta;
  8323. node.end += delta;
  8324. if (aggressiveChecks && shouldCheckNode(node)) {
  8325. ts.Debug.assert(text === newText.substring(node.pos, node.end));
  8326. }
  8327. forEachChild(node, visitNode, visitArray);
  8328. checkNodePositions(node, aggressiveChecks);
  8329. }
  8330. function visitArray(array) {
  8331. array._children = undefined;
  8332. array.pos += delta;
  8333. array.end += delta;
  8334. for (var _i = 0; _i < array.length; _i++) {
  8335. var node = array[_i];
  8336. visitNode(node);
  8337. }
  8338. }
  8339. }
  8340. function shouldCheckNode(node) {
  8341. switch (node.kind) {
  8342. case 8:
  8343. case 7:
  8344. case 65:
  8345. return true;
  8346. }
  8347. return false;
  8348. }
  8349. function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) {
  8350. ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
  8351. ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
  8352. ts.Debug.assert(element.pos <= element.end);
  8353. element.pos = Math.min(element.pos, changeRangeNewEnd);
  8354. if (element.end >= changeRangeOldEnd) {
  8355. element.end += delta;
  8356. }
  8357. else {
  8358. element.end = Math.min(element.end, changeRangeNewEnd);
  8359. }
  8360. ts.Debug.assert(element.pos <= element.end);
  8361. if (element.parent) {
  8362. ts.Debug.assert(element.pos >= element.parent.pos);
  8363. ts.Debug.assert(element.end <= element.parent.end);
  8364. }
  8365. }
  8366. function checkNodePositions(node, aggressiveChecks) {
  8367. if (aggressiveChecks) {
  8368. var pos = node.pos;
  8369. forEachChild(node, function (child) {
  8370. ts.Debug.assert(child.pos >= pos);
  8371. pos = child.end;
  8372. });
  8373. ts.Debug.assert(pos <= node.end);
  8374. }
  8375. }
  8376. function updateTokenPositionsAndMarkElements(sourceFile, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta, oldText, newText, aggressiveChecks) {
  8377. visitNode(sourceFile);
  8378. return;
  8379. function visitNode(child) {
  8380. ts.Debug.assert(child.pos <= child.end);
  8381. if (child.pos > changeRangeOldEnd) {
  8382. moveElementEntirelyPastChangeRange(child, false, delta, oldText, newText, aggressiveChecks);
  8383. return;
  8384. }
  8385. var fullEnd = child.end;
  8386. if (fullEnd >= changeStart) {
  8387. child.intersectsChange = true;
  8388. child._children = undefined;
  8389. adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
  8390. forEachChild(child, visitNode, visitArray);
  8391. checkNodePositions(child, aggressiveChecks);
  8392. return;
  8393. }
  8394. ts.Debug.assert(fullEnd < changeStart);
  8395. }
  8396. function visitArray(array) {
  8397. ts.Debug.assert(array.pos <= array.end);
  8398. if (array.pos > changeRangeOldEnd) {
  8399. moveElementEntirelyPastChangeRange(array, true, delta, oldText, newText, aggressiveChecks);
  8400. return;
  8401. }
  8402. var fullEnd = array.end;
  8403. if (fullEnd >= changeStart) {
  8404. array.intersectsChange = true;
  8405. array._children = undefined;
  8406. adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
  8407. for (var _i = 0; _i < array.length; _i++) {
  8408. var node = array[_i];
  8409. visitNode(node);
  8410. }
  8411. return;
  8412. }
  8413. ts.Debug.assert(fullEnd < changeStart);
  8414. }
  8415. }
  8416. function extendToAffectedRange(sourceFile, changeRange) {
  8417. var maxLookahead = 1;
  8418. var start = changeRange.span.start;
  8419. for (var i = 0; start > 0 && i <= maxLookahead; i++) {
  8420. var nearestNode = findNearestNodeStartingBeforeOrAtPosition(sourceFile, start);
  8421. ts.Debug.assert(nearestNode.pos <= start);
  8422. var position = nearestNode.pos;
  8423. start = Math.max(0, position - 1);
  8424. }
  8425. var finalSpan = ts.createTextSpanFromBounds(start, ts.textSpanEnd(changeRange.span));
  8426. var finalLength = changeRange.newLength + (changeRange.span.start - start);
  8427. return ts.createTextChangeRange(finalSpan, finalLength);
  8428. }
  8429. function findNearestNodeStartingBeforeOrAtPosition(sourceFile, position) {
  8430. var bestResult = sourceFile;
  8431. var lastNodeEntirelyBeforePosition;
  8432. forEachChild(sourceFile, visit);
  8433. if (lastNodeEntirelyBeforePosition) {
  8434. var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition);
  8435. if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) {
  8436. bestResult = lastChildOfLastEntireNodeBeforePosition;
  8437. }
  8438. }
  8439. return bestResult;
  8440. function getLastChild(node) {
  8441. while (true) {
  8442. var lastChild = getLastChildWorker(node);
  8443. if (lastChild) {
  8444. node = lastChild;
  8445. }
  8446. else {
  8447. return node;
  8448. }
  8449. }
  8450. }
  8451. function getLastChildWorker(node) {
  8452. var last = undefined;
  8453. forEachChild(node, function (child) {
  8454. if (ts.nodeIsPresent(child)) {
  8455. last = child;
  8456. }
  8457. });
  8458. return last;
  8459. }
  8460. function visit(child) {
  8461. if (ts.nodeIsMissing(child)) {
  8462. return;
  8463. }
  8464. if (child.pos <= position) {
  8465. if (child.pos >= bestResult.pos) {
  8466. bestResult = child;
  8467. }
  8468. if (position < child.end) {
  8469. forEachChild(child, visit);
  8470. return true;
  8471. }
  8472. else {
  8473. ts.Debug.assert(child.end <= position);
  8474. lastNodeEntirelyBeforePosition = child;
  8475. }
  8476. }
  8477. else {
  8478. ts.Debug.assert(child.pos > position);
  8479. return true;
  8480. }
  8481. }
  8482. }
  8483. function checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks) {
  8484. var oldText = sourceFile.text;
  8485. if (textChangeRange) {
  8486. ts.Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length);
  8487. if (aggressiveChecks || ts.Debug.shouldAssert(3)) {
  8488. var oldTextPrefix = oldText.substr(0, textChangeRange.span.start);
  8489. var newTextPrefix = newText.substr(0, textChangeRange.span.start);
  8490. ts.Debug.assert(oldTextPrefix === newTextPrefix);
  8491. var oldTextSuffix = oldText.substring(ts.textSpanEnd(textChangeRange.span), oldText.length);
  8492. var newTextSuffix = newText.substring(ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)), newText.length);
  8493. ts.Debug.assert(oldTextSuffix === newTextSuffix);
  8494. }
  8495. }
  8496. }
  8497. function createSyntaxCursor(sourceFile) {
  8498. var currentArray = sourceFile.statements;
  8499. var currentArrayIndex = 0;
  8500. ts.Debug.assert(currentArrayIndex < currentArray.length);
  8501. var current = currentArray[currentArrayIndex];
  8502. var lastQueriedPosition = -1;
  8503. return {
  8504. currentNode: function (position) {
  8505. if (position !== lastQueriedPosition) {
  8506. if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) {
  8507. currentArrayIndex++;
  8508. current = currentArray[currentArrayIndex];
  8509. }
  8510. if (!current || current.pos !== position) {
  8511. findHighestListElementThatStartsAtPosition(position);
  8512. }
  8513. }
  8514. lastQueriedPosition = position;
  8515. ts.Debug.assert(!current || current.pos === position);
  8516. return current;
  8517. }
  8518. };
  8519. function findHighestListElementThatStartsAtPosition(position) {
  8520. currentArray = undefined;
  8521. currentArrayIndex = -1;
  8522. current = undefined;
  8523. forEachChild(sourceFile, visitNode, visitArray);
  8524. return;
  8525. function visitNode(node) {
  8526. if (position >= node.pos && position < node.end) {
  8527. forEachChild(node, visitNode, visitArray);
  8528. return true;
  8529. }
  8530. return false;
  8531. }
  8532. function visitArray(array) {
  8533. if (position >= array.pos && position < array.end) {
  8534. for (var i = 0, n = array.length; i < n; i++) {
  8535. var child = array[i];
  8536. if (child) {
  8537. if (child.pos === position) {
  8538. currentArray = array;
  8539. currentArrayIndex = i;
  8540. current = child;
  8541. return true;
  8542. }
  8543. else {
  8544. if (child.pos < position && position < child.end) {
  8545. forEachChild(child, visitNode, visitArray);
  8546. return true;
  8547. }
  8548. }
  8549. }
  8550. }
  8551. }
  8552. return false;
  8553. }
  8554. }
  8555. }
  8556. })(IncrementalParser || (IncrementalParser = {}));
  8557. })(ts || (ts = {}));
  8558. /// <reference path="binder.ts"/>
  8559. var ts;
  8560. (function (ts) {
  8561. var nextSymbolId = 1;
  8562. var nextNodeId = 1;
  8563. var nextMergeId = 1;
  8564. function getNodeId(node) {
  8565. if (!node.id)
  8566. node.id = nextNodeId++;
  8567. return node.id;
  8568. }
  8569. ts.getNodeId = getNodeId;
  8570. ts.checkTime = 0;
  8571. function getSymbolId(symbol) {
  8572. if (!symbol.id) {
  8573. symbol.id = nextSymbolId++;
  8574. }
  8575. return symbol.id;
  8576. }
  8577. ts.getSymbolId = getSymbolId;
  8578. function createTypeChecker(host, produceDiagnostics) {
  8579. var Symbol = ts.objectAllocator.getSymbolConstructor();
  8580. var Type = ts.objectAllocator.getTypeConstructor();
  8581. var Signature = ts.objectAllocator.getSignatureConstructor();
  8582. var typeCount = 0;
  8583. var emptyArray = [];
  8584. var emptySymbols = {};
  8585. var compilerOptions = host.getCompilerOptions();
  8586. var languageVersion = compilerOptions.target || 0;
  8587. var emitResolver = createResolver();
  8588. var undefinedSymbol = createSymbol(4 | 67108864, "undefined");
  8589. var argumentsSymbol = createSymbol(4 | 67108864, "arguments");
  8590. var checker = {
  8591. getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); },
  8592. getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); },
  8593. getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); },
  8594. getTypeCount: function () { return typeCount; },
  8595. isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; },
  8596. isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; },
  8597. getDiagnostics: getDiagnostics,
  8598. getGlobalDiagnostics: getGlobalDiagnostics,
  8599. getTypeOfSymbolAtLocation: getTypeOfSymbolAtLocation,
  8600. getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
  8601. getPropertiesOfType: getPropertiesOfType,
  8602. getPropertyOfType: getPropertyOfType,
  8603. getSignaturesOfType: getSignaturesOfType,
  8604. getIndexTypeOfType: getIndexTypeOfType,
  8605. getReturnTypeOfSignature: getReturnTypeOfSignature,
  8606. getSymbolsInScope: getSymbolsInScope,
  8607. getSymbolAtLocation: getSymbolAtLocation,
  8608. getShorthandAssignmentValueSymbol: getShorthandAssignmentValueSymbol,
  8609. getTypeAtLocation: getTypeAtLocation,
  8610. typeToString: typeToString,
  8611. getSymbolDisplayBuilder: getSymbolDisplayBuilder,
  8612. symbolToString: symbolToString,
  8613. getAugmentedPropertiesOfType: getAugmentedPropertiesOfType,
  8614. getRootSymbols: getRootSymbols,
  8615. getContextualType: getContextualType,
  8616. getFullyQualifiedName: getFullyQualifiedName,
  8617. getResolvedSignature: getResolvedSignature,
  8618. getConstantValue: getConstantValue,
  8619. isValidPropertyAccess: isValidPropertyAccess,
  8620. getSignatureFromDeclaration: getSignatureFromDeclaration,
  8621. isImplementationOfOverload: isImplementationOfOverload,
  8622. getAliasedSymbol: resolveAlias,
  8623. getEmitResolver: getEmitResolver,
  8624. getExportsOfModule: getExportsOfModuleAsArray
  8625. };
  8626. var unknownSymbol = createSymbol(4 | 67108864, "unknown");
  8627. var resolvingSymbol = createSymbol(67108864, "__resolving__");
  8628. var anyType = createIntrinsicType(1, "any");
  8629. var stringType = createIntrinsicType(2, "string");
  8630. var numberType = createIntrinsicType(4, "number");
  8631. var booleanType = createIntrinsicType(8, "boolean");
  8632. var esSymbolType = createIntrinsicType(1048576, "symbol");
  8633. var voidType = createIntrinsicType(16, "void");
  8634. var undefinedType = createIntrinsicType(32 | 262144, "undefined");
  8635. var nullType = createIntrinsicType(64 | 262144, "null");
  8636. var unknownType = createIntrinsicType(1, "unknown");
  8637. var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  8638. var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  8639. var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  8640. var anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false);
  8641. var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false);
  8642. var globals = {};
  8643. var globalArraySymbol;
  8644. var globalESSymbolConstructorSymbol;
  8645. var globalObjectType;
  8646. var globalFunctionType;
  8647. var globalArrayType;
  8648. var globalStringType;
  8649. var globalNumberType;
  8650. var globalBooleanType;
  8651. var globalRegExpType;
  8652. var globalTemplateStringsArrayType;
  8653. var globalESSymbolType;
  8654. var globalIterableType;
  8655. var anyArrayType;
  8656. var getGlobalClassDecoratorType;
  8657. var getGlobalParameterDecoratorType;
  8658. var getGlobalPropertyDecoratorType;
  8659. var getGlobalMethodDecoratorType;
  8660. var tupleTypes = {};
  8661. var unionTypes = {};
  8662. var stringLiteralTypes = {};
  8663. var emitExtends = false;
  8664. var emitDecorate = false;
  8665. var emitParam = false;
  8666. var resolutionTargets = [];
  8667. var resolutionResults = [];
  8668. var mergedSymbols = [];
  8669. var symbolLinks = [];
  8670. var nodeLinks = [];
  8671. var potentialThisCollisions = [];
  8672. var diagnostics = ts.createDiagnosticCollection();
  8673. var primitiveTypeInfo = {
  8674. "string": {
  8675. type: stringType,
  8676. flags: 258
  8677. },
  8678. "number": {
  8679. type: numberType,
  8680. flags: 132
  8681. },
  8682. "boolean": {
  8683. type: booleanType,
  8684. flags: 8
  8685. },
  8686. "symbol": {
  8687. type: esSymbolType,
  8688. flags: 1048576
  8689. }
  8690. };
  8691. function getEmitResolver(sourceFile) {
  8692. getDiagnostics(sourceFile);
  8693. return emitResolver;
  8694. }
  8695. function error(location, message, arg0, arg1, arg2) {
  8696. var diagnostic = location
  8697. ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2)
  8698. : ts.createCompilerDiagnostic(message, arg0, arg1, arg2);
  8699. diagnostics.add(diagnostic);
  8700. }
  8701. function createSymbol(flags, name) {
  8702. return new Symbol(flags, name);
  8703. }
  8704. function getExcludedSymbolFlags(flags) {
  8705. var result = 0;
  8706. if (flags & 2)
  8707. result |= 107455;
  8708. if (flags & 1)
  8709. result |= 107454;
  8710. if (flags & 4)
  8711. result |= 107455;
  8712. if (flags & 8)
  8713. result |= 107455;
  8714. if (flags & 16)
  8715. result |= 106927;
  8716. if (flags & 32)
  8717. result |= 899583;
  8718. if (flags & 64)
  8719. result |= 792992;
  8720. if (flags & 256)
  8721. result |= 899327;
  8722. if (flags & 128)
  8723. result |= 899967;
  8724. if (flags & 512)
  8725. result |= 106639;
  8726. if (flags & 8192)
  8727. result |= 99263;
  8728. if (flags & 32768)
  8729. result |= 41919;
  8730. if (flags & 65536)
  8731. result |= 74687;
  8732. if (flags & 262144)
  8733. result |= 530912;
  8734. if (flags & 524288)
  8735. result |= 793056;
  8736. if (flags & 8388608)
  8737. result |= 8388608;
  8738. return result;
  8739. }
  8740. function recordMergedSymbol(target, source) {
  8741. if (!source.mergeId)
  8742. source.mergeId = nextMergeId++;
  8743. mergedSymbols[source.mergeId] = target;
  8744. }
  8745. function cloneSymbol(symbol) {
  8746. var result = createSymbol(symbol.flags | 33554432, symbol.name);
  8747. result.declarations = symbol.declarations.slice(0);
  8748. result.parent = symbol.parent;
  8749. if (symbol.valueDeclaration)
  8750. result.valueDeclaration = symbol.valueDeclaration;
  8751. if (symbol.constEnumOnlyModule)
  8752. result.constEnumOnlyModule = true;
  8753. if (symbol.members)
  8754. result.members = cloneSymbolTable(symbol.members);
  8755. if (symbol.exports)
  8756. result.exports = cloneSymbolTable(symbol.exports);
  8757. recordMergedSymbol(result, symbol);
  8758. return result;
  8759. }
  8760. function mergeSymbol(target, source) {
  8761. if (!(target.flags & getExcludedSymbolFlags(source.flags))) {
  8762. if (source.flags & 512 && target.flags & 512 && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
  8763. target.constEnumOnlyModule = false;
  8764. }
  8765. target.flags |= source.flags;
  8766. if (!target.valueDeclaration && source.valueDeclaration)
  8767. target.valueDeclaration = source.valueDeclaration;
  8768. ts.forEach(source.declarations, function (node) {
  8769. target.declarations.push(node);
  8770. });
  8771. if (source.members) {
  8772. if (!target.members)
  8773. target.members = {};
  8774. mergeSymbolTable(target.members, source.members);
  8775. }
  8776. if (source.exports) {
  8777. if (!target.exports)
  8778. target.exports = {};
  8779. mergeSymbolTable(target.exports, source.exports);
  8780. }
  8781. recordMergedSymbol(target, source);
  8782. }
  8783. else {
  8784. var message = target.flags & 2 || source.flags & 2
  8785. ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0;
  8786. ts.forEach(source.declarations, function (node) {
  8787. error(node.name ? node.name : node, message, symbolToString(source));
  8788. });
  8789. ts.forEach(target.declarations, function (node) {
  8790. error(node.name ? node.name : node, message, symbolToString(source));
  8791. });
  8792. }
  8793. }
  8794. function cloneSymbolTable(symbolTable) {
  8795. var result = {};
  8796. for (var id in symbolTable) {
  8797. if (ts.hasProperty(symbolTable, id)) {
  8798. result[id] = symbolTable[id];
  8799. }
  8800. }
  8801. return result;
  8802. }
  8803. function mergeSymbolTable(target, source) {
  8804. for (var id in source) {
  8805. if (ts.hasProperty(source, id)) {
  8806. if (!ts.hasProperty(target, id)) {
  8807. target[id] = source[id];
  8808. }
  8809. else {
  8810. var symbol = target[id];
  8811. if (!(symbol.flags & 33554432)) {
  8812. target[id] = symbol = cloneSymbol(symbol);
  8813. }
  8814. mergeSymbol(symbol, source[id]);
  8815. }
  8816. }
  8817. }
  8818. }
  8819. function getSymbolLinks(symbol) {
  8820. if (symbol.flags & 67108864)
  8821. return symbol;
  8822. var id = getSymbolId(symbol);
  8823. return symbolLinks[id] || (symbolLinks[id] = {});
  8824. }
  8825. function getNodeLinks(node) {
  8826. var nodeId = getNodeId(node);
  8827. return nodeLinks[nodeId] || (nodeLinks[nodeId] = {});
  8828. }
  8829. function getSourceFile(node) {
  8830. return ts.getAncestor(node, 228);
  8831. }
  8832. function isGlobalSourceFile(node) {
  8833. return node.kind === 228 && !ts.isExternalModule(node);
  8834. }
  8835. function getSymbol(symbols, name, meaning) {
  8836. if (meaning && ts.hasProperty(symbols, name)) {
  8837. var symbol = symbols[name];
  8838. ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here.");
  8839. if (symbol.flags & meaning) {
  8840. return symbol;
  8841. }
  8842. if (symbol.flags & 8388608) {
  8843. var target = resolveAlias(symbol);
  8844. if (target === unknownSymbol || target.flags & meaning) {
  8845. return symbol;
  8846. }
  8847. }
  8848. }
  8849. }
  8850. function isDefinedBefore(node1, node2) {
  8851. var file1 = ts.getSourceFileOfNode(node1);
  8852. var file2 = ts.getSourceFileOfNode(node2);
  8853. if (file1 === file2) {
  8854. return node1.pos <= node2.pos;
  8855. }
  8856. if (!compilerOptions.out) {
  8857. return true;
  8858. }
  8859. var sourceFiles = host.getSourceFiles();
  8860. return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2);
  8861. }
  8862. function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) {
  8863. var result;
  8864. var lastLocation;
  8865. var propertyWithInvalidInitializer;
  8866. var errorLocation = location;
  8867. var grandparent;
  8868. loop: while (location) {
  8869. if (location.locals && !isGlobalSourceFile(location)) {
  8870. if (result = getSymbol(location.locals, name, meaning)) {
  8871. break loop;
  8872. }
  8873. }
  8874. switch (location.kind) {
  8875. case 228:
  8876. if (!ts.isExternalModule(location))
  8877. break;
  8878. case 206:
  8879. var moduleExports = getSymbolOfNode(location).exports;
  8880. if (location.kind === 228 ||
  8881. (location.kind === 206 && location.name.kind === 8)) {
  8882. if (ts.hasProperty(moduleExports, name) &&
  8883. moduleExports[name].flags === 8388608 &&
  8884. ts.getDeclarationOfKind(moduleExports[name], 218)) {
  8885. break;
  8886. }
  8887. result = moduleExports["default"];
  8888. var localSymbol = ts.getLocalSymbolForExportDefault(result);
  8889. if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
  8890. break loop;
  8891. }
  8892. result = undefined;
  8893. }
  8894. if (result = getSymbol(moduleExports, name, meaning & 8914931)) {
  8895. break loop;
  8896. }
  8897. break;
  8898. case 205:
  8899. if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) {
  8900. break loop;
  8901. }
  8902. break;
  8903. case 133:
  8904. case 132:
  8905. if (location.parent.kind === 202 && !(location.flags & 128)) {
  8906. var ctor = findConstructorDeclaration(location.parent);
  8907. if (ctor && ctor.locals) {
  8908. if (getSymbol(ctor.locals, name, meaning & 107455)) {
  8909. propertyWithInvalidInitializer = location;
  8910. }
  8911. }
  8912. }
  8913. break;
  8914. case 202:
  8915. case 203:
  8916. if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) {
  8917. if (lastLocation && lastLocation.flags & 128) {
  8918. error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters);
  8919. return undefined;
  8920. }
  8921. break loop;
  8922. }
  8923. break;
  8924. case 128:
  8925. grandparent = location.parent.parent;
  8926. if (grandparent.kind === 202 || grandparent.kind === 203) {
  8927. if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) {
  8928. error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
  8929. return undefined;
  8930. }
  8931. }
  8932. break;
  8933. case 135:
  8934. case 134:
  8935. case 136:
  8936. case 137:
  8937. case 138:
  8938. case 201:
  8939. case 164:
  8940. if (meaning & 3 && name === "arguments") {
  8941. result = argumentsSymbol;
  8942. break loop;
  8943. }
  8944. break;
  8945. case 163:
  8946. if (meaning & 3 && name === "arguments") {
  8947. result = argumentsSymbol;
  8948. break loop;
  8949. }
  8950. if (meaning & 16) {
  8951. var functionName = location.name;
  8952. if (functionName && name === functionName.text) {
  8953. result = location.symbol;
  8954. break loop;
  8955. }
  8956. }
  8957. break;
  8958. case 175:
  8959. if (meaning & 32) {
  8960. var className = location.name;
  8961. if (className && name === className.text) {
  8962. result = location.symbol;
  8963. break loop;
  8964. }
  8965. }
  8966. break;
  8967. case 131:
  8968. if (location.parent && location.parent.kind === 130) {
  8969. location = location.parent;
  8970. }
  8971. if (location.parent && ts.isClassElement(location.parent)) {
  8972. location = location.parent;
  8973. }
  8974. break;
  8975. }
  8976. lastLocation = location;
  8977. location = location.parent;
  8978. }
  8979. if (!result) {
  8980. result = getSymbol(globals, name, meaning);
  8981. }
  8982. if (!result) {
  8983. if (nameNotFoundMessage) {
  8984. error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg));
  8985. }
  8986. return undefined;
  8987. }
  8988. if (nameNotFoundMessage) {
  8989. if (propertyWithInvalidInitializer) {
  8990. var propertyName = propertyWithInvalidInitializer.name;
  8991. 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));
  8992. return undefined;
  8993. }
  8994. if (result.flags & 2) {
  8995. checkResolvedBlockScopedVariable(result, errorLocation);
  8996. }
  8997. }
  8998. return result;
  8999. }
  9000. function checkResolvedBlockScopedVariable(result, errorLocation) {
  9001. ts.Debug.assert((result.flags & 2) !== 0);
  9002. var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; });
  9003. ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
  9004. var isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation);
  9005. if (!isUsedBeforeDeclaration) {
  9006. var variableDeclaration = ts.getAncestor(declaration, 199);
  9007. var container = ts.getEnclosingBlockScopeContainer(variableDeclaration);
  9008. if (variableDeclaration.parent.parent.kind === 181 ||
  9009. variableDeclaration.parent.parent.kind === 187) {
  9010. isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container);
  9011. }
  9012. else if (variableDeclaration.parent.parent.kind === 189 ||
  9013. variableDeclaration.parent.parent.kind === 188) {
  9014. var expression = variableDeclaration.parent.parent.expression;
  9015. isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container);
  9016. }
  9017. }
  9018. if (isUsedBeforeDeclaration) {
  9019. error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name));
  9020. }
  9021. }
  9022. function isSameScopeDescendentOf(initial, parent, stopAt) {
  9023. if (!parent) {
  9024. return false;
  9025. }
  9026. for (var current = initial; current && current !== stopAt && !ts.isFunctionLike(current); current = current.parent) {
  9027. if (current === parent) {
  9028. return true;
  9029. }
  9030. }
  9031. return false;
  9032. }
  9033. function getAnyImportSyntax(node) {
  9034. if (ts.isAliasSymbolDeclaration(node)) {
  9035. if (node.kind === 209) {
  9036. return node;
  9037. }
  9038. while (node && node.kind !== 210) {
  9039. node = node.parent;
  9040. }
  9041. return node;
  9042. }
  9043. }
  9044. function getDeclarationOfAliasSymbol(symbol) {
  9045. return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; });
  9046. }
  9047. function getTargetOfImportEqualsDeclaration(node) {
  9048. if (node.moduleReference.kind === 220) {
  9049. return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node)));
  9050. }
  9051. return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node);
  9052. }
  9053. function getTargetOfImportClause(node) {
  9054. var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier);
  9055. if (moduleSymbol) {
  9056. var exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]);
  9057. if (!exportDefaultSymbol) {
  9058. error(node.name, ts.Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
  9059. }
  9060. return exportDefaultSymbol;
  9061. }
  9062. }
  9063. function getTargetOfNamespaceImport(node) {
  9064. var moduleSpecifier = node.parent.parent.moduleSpecifier;
  9065. return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
  9066. }
  9067. function getMemberOfModuleVariable(moduleSymbol, name) {
  9068. if (moduleSymbol.flags & 3) {
  9069. var typeAnnotation = moduleSymbol.valueDeclaration.type;
  9070. if (typeAnnotation) {
  9071. return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
  9072. }
  9073. }
  9074. }
  9075. function combineValueAndTypeSymbols(valueSymbol, typeSymbol) {
  9076. if (valueSymbol.flags & (793056 | 1536)) {
  9077. return valueSymbol;
  9078. }
  9079. var result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
  9080. result.declarations = ts.concatenate(valueSymbol.declarations, typeSymbol.declarations);
  9081. result.parent = valueSymbol.parent || typeSymbol.parent;
  9082. if (valueSymbol.valueDeclaration)
  9083. result.valueDeclaration = valueSymbol.valueDeclaration;
  9084. if (typeSymbol.members)
  9085. result.members = typeSymbol.members;
  9086. if (valueSymbol.exports)
  9087. result.exports = valueSymbol.exports;
  9088. return result;
  9089. }
  9090. function getExportOfModule(symbol, name) {
  9091. if (symbol.flags & 1536) {
  9092. var exports = getExportsOfSymbol(symbol);
  9093. if (ts.hasProperty(exports, name)) {
  9094. return resolveSymbol(exports[name]);
  9095. }
  9096. }
  9097. }
  9098. function getPropertyOfVariable(symbol, name) {
  9099. if (symbol.flags & 3) {
  9100. var typeAnnotation = symbol.valueDeclaration.type;
  9101. if (typeAnnotation) {
  9102. return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name));
  9103. }
  9104. }
  9105. }
  9106. function getExternalModuleMember(node, specifier) {
  9107. var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
  9108. var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
  9109. if (targetSymbol) {
  9110. var name_4 = specifier.propertyName || specifier.name;
  9111. if (name_4.text) {
  9112. var symbolFromModule = getExportOfModule(targetSymbol, name_4.text);
  9113. var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_4.text);
  9114. var symbol = symbolFromModule && symbolFromVariable ?
  9115. combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
  9116. symbolFromModule || symbolFromVariable;
  9117. if (!symbol) {
  9118. error(name_4, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_4));
  9119. }
  9120. return symbol;
  9121. }
  9122. }
  9123. }
  9124. function getTargetOfImportSpecifier(node) {
  9125. return getExternalModuleMember(node.parent.parent.parent, node);
  9126. }
  9127. function getTargetOfExportSpecifier(node) {
  9128. return node.parent.parent.moduleSpecifier ?
  9129. getExternalModuleMember(node.parent.parent, node) :
  9130. resolveEntityName(node.propertyName || node.name, 107455 | 793056 | 1536);
  9131. }
  9132. function getTargetOfExportAssignment(node) {
  9133. return resolveEntityName(node.expression, 107455 | 793056 | 1536);
  9134. }
  9135. function getTargetOfAliasDeclaration(node) {
  9136. switch (node.kind) {
  9137. case 209:
  9138. return getTargetOfImportEqualsDeclaration(node);
  9139. case 211:
  9140. return getTargetOfImportClause(node);
  9141. case 212:
  9142. return getTargetOfNamespaceImport(node);
  9143. case 214:
  9144. return getTargetOfImportSpecifier(node);
  9145. case 218:
  9146. return getTargetOfExportSpecifier(node);
  9147. case 215:
  9148. return getTargetOfExportAssignment(node);
  9149. }
  9150. }
  9151. function resolveSymbol(symbol) {
  9152. return symbol && symbol.flags & 8388608 && !(symbol.flags & (107455 | 793056 | 1536)) ? resolveAlias(symbol) : symbol;
  9153. }
  9154. function resolveAlias(symbol) {
  9155. ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Alias here.");
  9156. var links = getSymbolLinks(symbol);
  9157. if (!links.target) {
  9158. links.target = resolvingSymbol;
  9159. var node = getDeclarationOfAliasSymbol(symbol);
  9160. var target = getTargetOfAliasDeclaration(node);
  9161. if (links.target === resolvingSymbol) {
  9162. links.target = target || unknownSymbol;
  9163. }
  9164. else {
  9165. error(node, ts.Diagnostics.Circular_definition_of_import_alias_0, symbolToString(symbol));
  9166. }
  9167. }
  9168. else if (links.target === resolvingSymbol) {
  9169. links.target = unknownSymbol;
  9170. }
  9171. return links.target;
  9172. }
  9173. function markExportAsReferenced(node) {
  9174. var symbol = getSymbolOfNode(node);
  9175. var target = resolveAlias(symbol);
  9176. if (target) {
  9177. var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) ||
  9178. (target !== unknownSymbol && (target.flags & 107455) && !isConstEnumOrConstEnumOnlyModule(target));
  9179. if (markAlias) {
  9180. markAliasSymbolAsReferenced(symbol);
  9181. }
  9182. }
  9183. }
  9184. function markAliasSymbolAsReferenced(symbol) {
  9185. var links = getSymbolLinks(symbol);
  9186. if (!links.referenced) {
  9187. links.referenced = true;
  9188. var node = getDeclarationOfAliasSymbol(symbol);
  9189. if (node.kind === 215) {
  9190. checkExpressionCached(node.expression);
  9191. }
  9192. else if (node.kind === 218) {
  9193. checkExpressionCached(node.propertyName || node.name);
  9194. }
  9195. else if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  9196. checkExpressionCached(node.moduleReference);
  9197. }
  9198. }
  9199. }
  9200. function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) {
  9201. if (!importDeclaration) {
  9202. importDeclaration = ts.getAncestor(entityName, 209);
  9203. ts.Debug.assert(importDeclaration !== undefined);
  9204. }
  9205. if (entityName.kind === 65 && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
  9206. entityName = entityName.parent;
  9207. }
  9208. if (entityName.kind === 65 || entityName.parent.kind === 127) {
  9209. return resolveEntityName(entityName, 1536);
  9210. }
  9211. else {
  9212. ts.Debug.assert(entityName.parent.kind === 209);
  9213. return resolveEntityName(entityName, 107455 | 793056 | 1536);
  9214. }
  9215. }
  9216. function getFullyQualifiedName(symbol) {
  9217. return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
  9218. }
  9219. function resolveEntityName(name, meaning) {
  9220. if (ts.nodeIsMissing(name)) {
  9221. return undefined;
  9222. }
  9223. var symbol;
  9224. if (name.kind === 65) {
  9225. var message = meaning === 1536 ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0;
  9226. symbol = resolveName(name, name.text, meaning, message, name);
  9227. if (!symbol) {
  9228. return undefined;
  9229. }
  9230. }
  9231. else if (name.kind === 127 || name.kind === 156) {
  9232. var left = name.kind === 127 ? name.left : name.expression;
  9233. var right = name.kind === 127 ? name.right : name.name;
  9234. var namespace = resolveEntityName(left, 1536);
  9235. if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) {
  9236. return undefined;
  9237. }
  9238. symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
  9239. if (!symbol) {
  9240. error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right));
  9241. return undefined;
  9242. }
  9243. }
  9244. else {
  9245. ts.Debug.fail("Unknown entity name kind.");
  9246. }
  9247. ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here.");
  9248. return symbol.flags & meaning ? symbol : resolveAlias(symbol);
  9249. }
  9250. function isExternalModuleNameRelative(moduleName) {
  9251. return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
  9252. }
  9253. function resolveExternalModuleName(location, moduleReferenceExpression) {
  9254. if (moduleReferenceExpression.kind !== 8) {
  9255. return;
  9256. }
  9257. var moduleReferenceLiteral = moduleReferenceExpression;
  9258. var searchPath = ts.getDirectoryPath(getSourceFile(location).fileName);
  9259. var moduleName = ts.escapeIdentifier(moduleReferenceLiteral.text);
  9260. if (!moduleName)
  9261. return;
  9262. var isRelative = isExternalModuleNameRelative(moduleName);
  9263. if (!isRelative) {
  9264. var symbol = getSymbol(globals, '"' + moduleName + '"', 512);
  9265. if (symbol) {
  9266. return symbol;
  9267. }
  9268. }
  9269. var sourceFile;
  9270. while (true) {
  9271. var fileName = ts.normalizePath(ts.combinePaths(searchPath, moduleName));
  9272. sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts");
  9273. if (sourceFile || isRelative) {
  9274. break;
  9275. }
  9276. var parentPath = ts.getDirectoryPath(searchPath);
  9277. if (parentPath === searchPath) {
  9278. break;
  9279. }
  9280. searchPath = parentPath;
  9281. }
  9282. if (sourceFile) {
  9283. if (sourceFile.symbol) {
  9284. return sourceFile.symbol;
  9285. }
  9286. error(moduleReferenceLiteral, ts.Diagnostics.File_0_is_not_a_module, sourceFile.fileName);
  9287. return;
  9288. }
  9289. error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_module_0, moduleName);
  9290. }
  9291. function resolveExternalModuleSymbol(moduleSymbol) {
  9292. return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol;
  9293. }
  9294. function resolveESModuleSymbol(moduleSymbol, moduleReferenceExpression) {
  9295. var symbol = resolveExternalModuleSymbol(moduleSymbol);
  9296. if (symbol && !(symbol.flags & (1536 | 3))) {
  9297. error(moduleReferenceExpression, ts.Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
  9298. symbol = undefined;
  9299. }
  9300. return symbol;
  9301. }
  9302. function getExportAssignmentSymbol(moduleSymbol) {
  9303. return moduleSymbol.exports["export="];
  9304. }
  9305. function getExportsOfModuleAsArray(moduleSymbol) {
  9306. return symbolsToArray(getExportsOfModule(moduleSymbol));
  9307. }
  9308. function getExportsOfSymbol(symbol) {
  9309. return symbol.flags & 1536 ? getExportsOfModule(symbol) : symbol.exports || emptySymbols;
  9310. }
  9311. function getExportsOfModule(moduleSymbol) {
  9312. var links = getSymbolLinks(moduleSymbol);
  9313. return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
  9314. }
  9315. function extendExportSymbols(target, source) {
  9316. for (var id in source) {
  9317. if (id !== "default" && !ts.hasProperty(target, id)) {
  9318. target[id] = source[id];
  9319. }
  9320. }
  9321. }
  9322. function getExportsForModule(moduleSymbol) {
  9323. var result;
  9324. var visitedSymbols = [];
  9325. visit(moduleSymbol);
  9326. return result || moduleSymbol.exports;
  9327. function visit(symbol) {
  9328. if (symbol && symbol.flags & 1952 && !ts.contains(visitedSymbols, symbol)) {
  9329. visitedSymbols.push(symbol);
  9330. if (symbol !== moduleSymbol) {
  9331. if (!result) {
  9332. result = cloneSymbolTable(moduleSymbol.exports);
  9333. }
  9334. extendExportSymbols(result, symbol.exports);
  9335. }
  9336. var exportStars = symbol.exports["__export"];
  9337. if (exportStars) {
  9338. for (var _i = 0, _a = exportStars.declarations; _i < _a.length; _i++) {
  9339. var node = _a[_i];
  9340. visit(resolveExternalModuleName(node, node.moduleSpecifier));
  9341. }
  9342. }
  9343. }
  9344. }
  9345. }
  9346. function getMergedSymbol(symbol) {
  9347. var merged;
  9348. return symbol && symbol.mergeId && (merged = mergedSymbols[symbol.mergeId]) ? merged : symbol;
  9349. }
  9350. function getSymbolOfNode(node) {
  9351. return getMergedSymbol(node.symbol);
  9352. }
  9353. function getParentOfSymbol(symbol) {
  9354. return getMergedSymbol(symbol.parent);
  9355. }
  9356. function getExportSymbolOfValueSymbolIfExported(symbol) {
  9357. return symbol && (symbol.flags & 1048576) !== 0
  9358. ? getMergedSymbol(symbol.exportSymbol)
  9359. : symbol;
  9360. }
  9361. function symbolIsValue(symbol) {
  9362. if (symbol.flags & 16777216) {
  9363. return symbolIsValue(getSymbolLinks(symbol).target);
  9364. }
  9365. if (symbol.flags & 107455) {
  9366. return true;
  9367. }
  9368. if (symbol.flags & 8388608) {
  9369. return (resolveAlias(symbol).flags & 107455) !== 0;
  9370. }
  9371. return false;
  9372. }
  9373. function findConstructorDeclaration(node) {
  9374. var members = node.members;
  9375. for (var _i = 0; _i < members.length; _i++) {
  9376. var member = members[_i];
  9377. if (member.kind === 136 && ts.nodeIsPresent(member.body)) {
  9378. return member;
  9379. }
  9380. }
  9381. }
  9382. function createType(flags) {
  9383. var result = new Type(checker, flags);
  9384. result.id = typeCount++;
  9385. return result;
  9386. }
  9387. function createIntrinsicType(kind, intrinsicName) {
  9388. var type = createType(kind);
  9389. type.intrinsicName = intrinsicName;
  9390. return type;
  9391. }
  9392. function createObjectType(kind, symbol) {
  9393. var type = createType(kind);
  9394. type.symbol = symbol;
  9395. return type;
  9396. }
  9397. function isReservedMemberName(name) {
  9398. return name.charCodeAt(0) === 95 &&
  9399. name.charCodeAt(1) === 95 &&
  9400. name.charCodeAt(2) !== 95 &&
  9401. name.charCodeAt(2) !== 64;
  9402. }
  9403. function getNamedMembers(members) {
  9404. var result;
  9405. for (var id in members) {
  9406. if (ts.hasProperty(members, id)) {
  9407. if (!isReservedMemberName(id)) {
  9408. if (!result)
  9409. result = [];
  9410. var symbol = members[id];
  9411. if (symbolIsValue(symbol)) {
  9412. result.push(symbol);
  9413. }
  9414. }
  9415. }
  9416. }
  9417. return result || emptyArray;
  9418. }
  9419. function setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
  9420. type.members = members;
  9421. type.properties = getNamedMembers(members);
  9422. type.callSignatures = callSignatures;
  9423. type.constructSignatures = constructSignatures;
  9424. if (stringIndexType)
  9425. type.stringIndexType = stringIndexType;
  9426. if (numberIndexType)
  9427. type.numberIndexType = numberIndexType;
  9428. return type;
  9429. }
  9430. function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
  9431. return setObjectTypeMembers(createObjectType(32768, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  9432. }
  9433. function forEachSymbolTableInScope(enclosingDeclaration, callback) {
  9434. var result;
  9435. for (var location_1 = enclosingDeclaration; location_1; location_1 = location_1.parent) {
  9436. if (location_1.locals && !isGlobalSourceFile(location_1)) {
  9437. if (result = callback(location_1.locals)) {
  9438. return result;
  9439. }
  9440. }
  9441. switch (location_1.kind) {
  9442. case 228:
  9443. if (!ts.isExternalModule(location_1)) {
  9444. break;
  9445. }
  9446. case 206:
  9447. if (result = callback(getSymbolOfNode(location_1).exports)) {
  9448. return result;
  9449. }
  9450. break;
  9451. case 202:
  9452. case 203:
  9453. if (result = callback(getSymbolOfNode(location_1).members)) {
  9454. return result;
  9455. }
  9456. break;
  9457. }
  9458. }
  9459. return callback(globals);
  9460. }
  9461. function getQualifiedLeftMeaning(rightMeaning) {
  9462. return rightMeaning === 107455 ? 107455 : 1536;
  9463. }
  9464. function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) {
  9465. function getAccessibleSymbolChainFromSymbolTable(symbols) {
  9466. function canQualifySymbol(symbolFromSymbolTable, meaning) {
  9467. if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) {
  9468. return true;
  9469. }
  9470. var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
  9471. return !!accessibleParent;
  9472. }
  9473. function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) {
  9474. if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) {
  9475. return !ts.forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) &&
  9476. canQualifySymbol(symbolFromSymbolTable, meaning);
  9477. }
  9478. }
  9479. if (isAccessible(ts.lookUp(symbols, symbol.name))) {
  9480. return [symbol];
  9481. }
  9482. return ts.forEachValue(symbols, function (symbolFromSymbolTable) {
  9483. if (symbolFromSymbolTable.flags & 8388608 && symbolFromSymbolTable.name !== "export=") {
  9484. if (!useOnlyExternalAliasing ||
  9485. ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) {
  9486. var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable);
  9487. if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) {
  9488. return [symbolFromSymbolTable];
  9489. }
  9490. var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
  9491. if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
  9492. return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
  9493. }
  9494. }
  9495. }
  9496. });
  9497. }
  9498. if (symbol) {
  9499. return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
  9500. }
  9501. }
  9502. function needsQualification(symbol, enclosingDeclaration, meaning) {
  9503. var qualify = false;
  9504. forEachSymbolTableInScope(enclosingDeclaration, function (symbolTable) {
  9505. if (!ts.hasProperty(symbolTable, symbol.name)) {
  9506. return false;
  9507. }
  9508. var symbolFromSymbolTable = symbolTable[symbol.name];
  9509. if (symbolFromSymbolTable === symbol) {
  9510. return true;
  9511. }
  9512. symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
  9513. if (symbolFromSymbolTable.flags & meaning) {
  9514. qualify = true;
  9515. return true;
  9516. }
  9517. return false;
  9518. });
  9519. return qualify;
  9520. }
  9521. function isSymbolAccessible(symbol, enclosingDeclaration, meaning) {
  9522. if (symbol && enclosingDeclaration && !(symbol.flags & 262144)) {
  9523. var initialSymbol = symbol;
  9524. var meaningToLook = meaning;
  9525. while (symbol) {
  9526. var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false);
  9527. if (accessibleSymbolChain) {
  9528. var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
  9529. if (!hasAccessibleDeclarations) {
  9530. return {
  9531. accessibility: 1,
  9532. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
  9533. errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1536) : undefined
  9534. };
  9535. }
  9536. return hasAccessibleDeclarations;
  9537. }
  9538. meaningToLook = getQualifiedLeftMeaning(meaning);
  9539. symbol = getParentOfSymbol(symbol);
  9540. }
  9541. var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer);
  9542. if (symbolExternalModule) {
  9543. var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration);
  9544. if (symbolExternalModule !== enclosingExternalModule) {
  9545. return {
  9546. accessibility: 2,
  9547. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
  9548. errorModuleName: symbolToString(symbolExternalModule)
  9549. };
  9550. }
  9551. }
  9552. return {
  9553. accessibility: 1,
  9554. errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning)
  9555. };
  9556. }
  9557. return { accessibility: 0 };
  9558. function getExternalModuleContainer(declaration) {
  9559. for (; declaration; declaration = declaration.parent) {
  9560. if (hasExternalModuleSymbol(declaration)) {
  9561. return getSymbolOfNode(declaration);
  9562. }
  9563. }
  9564. }
  9565. }
  9566. function hasExternalModuleSymbol(declaration) {
  9567. return (declaration.kind === 206 && declaration.name.kind === 8) ||
  9568. (declaration.kind === 228 && ts.isExternalModule(declaration));
  9569. }
  9570. function hasVisibleDeclarations(symbol) {
  9571. var aliasesToMakeVisible;
  9572. if (ts.forEach(symbol.declarations, function (declaration) { return !getIsDeclarationVisible(declaration); })) {
  9573. return undefined;
  9574. }
  9575. return { accessibility: 0, aliasesToMakeVisible: aliasesToMakeVisible };
  9576. function getIsDeclarationVisible(declaration) {
  9577. if (!isDeclarationVisible(declaration)) {
  9578. var anyImportSyntax = getAnyImportSyntax(declaration);
  9579. if (anyImportSyntax &&
  9580. !(anyImportSyntax.flags & 1) &&
  9581. isDeclarationVisible(anyImportSyntax.parent)) {
  9582. getNodeLinks(declaration).isVisible = true;
  9583. if (aliasesToMakeVisible) {
  9584. if (!ts.contains(aliasesToMakeVisible, anyImportSyntax)) {
  9585. aliasesToMakeVisible.push(anyImportSyntax);
  9586. }
  9587. }
  9588. else {
  9589. aliasesToMakeVisible = [anyImportSyntax];
  9590. }
  9591. return true;
  9592. }
  9593. return false;
  9594. }
  9595. return true;
  9596. }
  9597. }
  9598. function isEntityNameVisible(entityName, enclosingDeclaration) {
  9599. var meaning;
  9600. if (entityName.parent.kind === 145) {
  9601. meaning = 107455 | 1048576;
  9602. }
  9603. else if (entityName.kind === 127 || entityName.kind === 156 ||
  9604. entityName.parent.kind === 209) {
  9605. meaning = 1536;
  9606. }
  9607. else {
  9608. meaning = 793056;
  9609. }
  9610. var firstIdentifier = getFirstIdentifier(entityName);
  9611. var symbol = resolveName(enclosingDeclaration, firstIdentifier.text, meaning, undefined, undefined);
  9612. return (symbol && hasVisibleDeclarations(symbol)) || {
  9613. accessibility: 1,
  9614. errorSymbolName: ts.getTextOfNode(firstIdentifier),
  9615. errorNode: firstIdentifier
  9616. };
  9617. }
  9618. function writeKeyword(writer, kind) {
  9619. writer.writeKeyword(ts.tokenToString(kind));
  9620. }
  9621. function writePunctuation(writer, kind) {
  9622. writer.writePunctuation(ts.tokenToString(kind));
  9623. }
  9624. function writeSpace(writer) {
  9625. writer.writeSpace(" ");
  9626. }
  9627. function symbolToString(symbol, enclosingDeclaration, meaning) {
  9628. var writer = ts.getSingleLineStringWriter();
  9629. getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning);
  9630. var result = writer.string();
  9631. ts.releaseStringWriter(writer);
  9632. return result;
  9633. }
  9634. function typeToString(type, enclosingDeclaration, flags) {
  9635. var writer = ts.getSingleLineStringWriter();
  9636. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  9637. var result = writer.string();
  9638. ts.releaseStringWriter(writer);
  9639. var maxLength = compilerOptions.noErrorTruncation || flags & 4 ? undefined : 100;
  9640. if (maxLength && result.length >= maxLength) {
  9641. result = result.substr(0, maxLength - "...".length) + "...";
  9642. }
  9643. return result;
  9644. }
  9645. function getTypeAliasForTypeLiteral(type) {
  9646. if (type.symbol && type.symbol.flags & 2048) {
  9647. var node = type.symbol.declarations[0].parent;
  9648. while (node.kind === 150) {
  9649. node = node.parent;
  9650. }
  9651. if (node.kind === 204) {
  9652. return getSymbolOfNode(node);
  9653. }
  9654. }
  9655. return undefined;
  9656. }
  9657. var _displayBuilder;
  9658. function getSymbolDisplayBuilder() {
  9659. function appendSymbolNameOnly(symbol, writer) {
  9660. if (symbol.declarations && symbol.declarations.length > 0) {
  9661. var declaration = symbol.declarations[0];
  9662. if (declaration.name) {
  9663. writer.writeSymbol(ts.declarationNameToString(declaration.name), symbol);
  9664. return;
  9665. }
  9666. }
  9667. writer.writeSymbol(symbol.name, symbol);
  9668. }
  9669. function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags, typeFlags) {
  9670. var parentSymbol;
  9671. function appendParentTypeArgumentsAndSymbolName(symbol) {
  9672. if (parentSymbol) {
  9673. if (flags & 1) {
  9674. if (symbol.flags & 16777216) {
  9675. buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration);
  9676. }
  9677. else {
  9678. buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration);
  9679. }
  9680. }
  9681. writePunctuation(writer, 20);
  9682. }
  9683. parentSymbol = symbol;
  9684. appendSymbolNameOnly(symbol, writer);
  9685. }
  9686. writer.trackSymbol(symbol, enclosingDeclaration, meaning);
  9687. function walkSymbol(symbol, meaning) {
  9688. if (symbol) {
  9689. var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2));
  9690. if (!accessibleSymbolChain ||
  9691. needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
  9692. walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning));
  9693. }
  9694. if (accessibleSymbolChain) {
  9695. for (var _i = 0; _i < accessibleSymbolChain.length; _i++) {
  9696. var accessibleSymbol = accessibleSymbolChain[_i];
  9697. appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
  9698. }
  9699. }
  9700. else {
  9701. if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) {
  9702. return;
  9703. }
  9704. if (symbol.flags & 2048 || symbol.flags & 4096) {
  9705. return;
  9706. }
  9707. appendParentTypeArgumentsAndSymbolName(symbol);
  9708. }
  9709. }
  9710. }
  9711. var isTypeParameter = symbol.flags & 262144;
  9712. var typeFormatFlag = 128 & typeFlags;
  9713. if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
  9714. walkSymbol(symbol, meaning);
  9715. return;
  9716. }
  9717. return appendParentTypeArgumentsAndSymbolName(symbol);
  9718. }
  9719. function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) {
  9720. var globalFlagsToPass = globalFlags & 16;
  9721. return writeType(type, globalFlags);
  9722. function writeType(type, flags) {
  9723. if (type.flags & 1048703) {
  9724. writer.writeKeyword(!(globalFlags & 16) &&
  9725. (type.flags & 1) ? "any" : type.intrinsicName);
  9726. }
  9727. else if (type.flags & 4096) {
  9728. writeTypeReference(type, flags);
  9729. }
  9730. else if (type.flags & (1024 | 2048 | 128 | 512)) {
  9731. buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 793056, 0, flags);
  9732. }
  9733. else if (type.flags & 8192) {
  9734. writeTupleType(type);
  9735. }
  9736. else if (type.flags & 16384) {
  9737. writeUnionType(type, flags);
  9738. }
  9739. else if (type.flags & 32768) {
  9740. writeAnonymousType(type, flags);
  9741. }
  9742. else if (type.flags & 256) {
  9743. writer.writeStringLiteral(type.text);
  9744. }
  9745. else {
  9746. writePunctuation(writer, 14);
  9747. writeSpace(writer);
  9748. writePunctuation(writer, 21);
  9749. writeSpace(writer);
  9750. writePunctuation(writer, 15);
  9751. }
  9752. }
  9753. function writeTypeList(types, union) {
  9754. for (var i = 0; i < types.length; i++) {
  9755. if (i > 0) {
  9756. if (union) {
  9757. writeSpace(writer);
  9758. }
  9759. writePunctuation(writer, union ? 44 : 23);
  9760. writeSpace(writer);
  9761. }
  9762. writeType(types[i], union ? 64 : 0);
  9763. }
  9764. }
  9765. function writeTypeReference(type, flags) {
  9766. if (type.target === globalArrayType && !(flags & 1)) {
  9767. writeType(type.typeArguments[0], 64);
  9768. writePunctuation(writer, 18);
  9769. writePunctuation(writer, 19);
  9770. }
  9771. else {
  9772. buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, 793056);
  9773. writePunctuation(writer, 24);
  9774. writeTypeList(type.typeArguments, false);
  9775. writePunctuation(writer, 25);
  9776. }
  9777. }
  9778. function writeTupleType(type) {
  9779. writePunctuation(writer, 18);
  9780. writeTypeList(type.elementTypes, false);
  9781. writePunctuation(writer, 19);
  9782. }
  9783. function writeUnionType(type, flags) {
  9784. if (flags & 64) {
  9785. writePunctuation(writer, 16);
  9786. }
  9787. writeTypeList(type.types, true);
  9788. if (flags & 64) {
  9789. writePunctuation(writer, 17);
  9790. }
  9791. }
  9792. function writeAnonymousType(type, flags) {
  9793. if (type.symbol && type.symbol.flags & (32 | 384 | 512)) {
  9794. writeTypeofSymbol(type, flags);
  9795. }
  9796. else if (shouldWriteTypeOfFunctionSymbol()) {
  9797. writeTypeofSymbol(type, flags);
  9798. }
  9799. else if (typeStack && ts.contains(typeStack, type)) {
  9800. var typeAlias = getTypeAliasForTypeLiteral(type);
  9801. if (typeAlias) {
  9802. buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags);
  9803. }
  9804. else {
  9805. writeKeyword(writer, 112);
  9806. }
  9807. }
  9808. else {
  9809. if (!typeStack) {
  9810. typeStack = [];
  9811. }
  9812. typeStack.push(type);
  9813. writeLiteralType(type, flags);
  9814. typeStack.pop();
  9815. }
  9816. function shouldWriteTypeOfFunctionSymbol() {
  9817. if (type.symbol) {
  9818. var isStaticMethodSymbol = !!(type.symbol.flags & 8192 &&
  9819. ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128; }));
  9820. var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) &&
  9821. (type.symbol.parent ||
  9822. ts.forEach(type.symbol.declarations, function (declaration) {
  9823. return declaration.parent.kind === 228 || declaration.parent.kind === 207;
  9824. }));
  9825. if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
  9826. return !!(flags & 2) ||
  9827. (typeStack && ts.contains(typeStack, type));
  9828. }
  9829. }
  9830. }
  9831. }
  9832. function writeTypeofSymbol(type, typeFormatFlags) {
  9833. writeKeyword(writer, 97);
  9834. writeSpace(writer);
  9835. buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455, 0, typeFormatFlags);
  9836. }
  9837. function getIndexerParameterName(type, indexKind, fallbackName) {
  9838. var declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind);
  9839. if (!declaration) {
  9840. return fallbackName;
  9841. }
  9842. ts.Debug.assert(declaration.parameters.length !== 0);
  9843. return ts.declarationNameToString(declaration.parameters[0].name);
  9844. }
  9845. function writeLiteralType(type, flags) {
  9846. var resolved = resolveObjectOrUnionTypeMembers(type);
  9847. if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) {
  9848. if (!resolved.callSignatures.length && !resolved.constructSignatures.length) {
  9849. writePunctuation(writer, 14);
  9850. writePunctuation(writer, 15);
  9851. return;
  9852. }
  9853. if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
  9854. if (flags & 64) {
  9855. writePunctuation(writer, 16);
  9856. }
  9857. buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack);
  9858. if (flags & 64) {
  9859. writePunctuation(writer, 17);
  9860. }
  9861. return;
  9862. }
  9863. if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
  9864. if (flags & 64) {
  9865. writePunctuation(writer, 16);
  9866. }
  9867. writeKeyword(writer, 88);
  9868. writeSpace(writer);
  9869. buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack);
  9870. if (flags & 64) {
  9871. writePunctuation(writer, 17);
  9872. }
  9873. return;
  9874. }
  9875. }
  9876. writePunctuation(writer, 14);
  9877. writer.writeLine();
  9878. writer.increaseIndent();
  9879. for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) {
  9880. var signature = _a[_i];
  9881. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack);
  9882. writePunctuation(writer, 22);
  9883. writer.writeLine();
  9884. }
  9885. for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) {
  9886. var signature = _c[_b];
  9887. writeKeyword(writer, 88);
  9888. writeSpace(writer);
  9889. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack);
  9890. writePunctuation(writer, 22);
  9891. writer.writeLine();
  9892. }
  9893. if (resolved.stringIndexType) {
  9894. writePunctuation(writer, 18);
  9895. writer.writeParameter(getIndexerParameterName(resolved, 0, "x"));
  9896. writePunctuation(writer, 51);
  9897. writeSpace(writer);
  9898. writeKeyword(writer, 122);
  9899. writePunctuation(writer, 19);
  9900. writePunctuation(writer, 51);
  9901. writeSpace(writer);
  9902. writeType(resolved.stringIndexType, 0);
  9903. writePunctuation(writer, 22);
  9904. writer.writeLine();
  9905. }
  9906. if (resolved.numberIndexType) {
  9907. writePunctuation(writer, 18);
  9908. writer.writeParameter(getIndexerParameterName(resolved, 1, "x"));
  9909. writePunctuation(writer, 51);
  9910. writeSpace(writer);
  9911. writeKeyword(writer, 120);
  9912. writePunctuation(writer, 19);
  9913. writePunctuation(writer, 51);
  9914. writeSpace(writer);
  9915. writeType(resolved.numberIndexType, 0);
  9916. writePunctuation(writer, 22);
  9917. writer.writeLine();
  9918. }
  9919. for (var _d = 0, _e = resolved.properties; _d < _e.length; _d++) {
  9920. var p = _e[_d];
  9921. var t = getTypeOfSymbol(p);
  9922. if (p.flags & (16 | 8192) && !getPropertiesOfObjectType(t).length) {
  9923. var signatures = getSignaturesOfType(t, 0);
  9924. for (var _f = 0; _f < signatures.length; _f++) {
  9925. var signature = signatures[_f];
  9926. buildSymbolDisplay(p, writer);
  9927. if (p.flags & 536870912) {
  9928. writePunctuation(writer, 50);
  9929. }
  9930. buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack);
  9931. writePunctuation(writer, 22);
  9932. writer.writeLine();
  9933. }
  9934. }
  9935. else {
  9936. buildSymbolDisplay(p, writer);
  9937. if (p.flags & 536870912) {
  9938. writePunctuation(writer, 50);
  9939. }
  9940. writePunctuation(writer, 51);
  9941. writeSpace(writer);
  9942. writeType(t, 0);
  9943. writePunctuation(writer, 22);
  9944. writer.writeLine();
  9945. }
  9946. }
  9947. writer.decreaseIndent();
  9948. writePunctuation(writer, 15);
  9949. }
  9950. }
  9951. function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) {
  9952. var targetSymbol = getTargetSymbol(symbol);
  9953. if (targetSymbol.flags & 32 || targetSymbol.flags & 64) {
  9954. buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags);
  9955. }
  9956. }
  9957. function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) {
  9958. appendSymbolNameOnly(tp.symbol, writer);
  9959. var constraint = getConstraintOfTypeParameter(tp);
  9960. if (constraint) {
  9961. writeSpace(writer);
  9962. writeKeyword(writer, 79);
  9963. writeSpace(writer);
  9964. buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack);
  9965. }
  9966. }
  9967. function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) {
  9968. if (ts.hasDotDotDotToken(p.valueDeclaration)) {
  9969. writePunctuation(writer, 21);
  9970. }
  9971. appendSymbolNameOnly(p, writer);
  9972. if (ts.hasQuestionToken(p.valueDeclaration) || p.valueDeclaration.initializer) {
  9973. writePunctuation(writer, 50);
  9974. }
  9975. writePunctuation(writer, 51);
  9976. writeSpace(writer);
  9977. buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack);
  9978. }
  9979. function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) {
  9980. if (typeParameters && typeParameters.length) {
  9981. writePunctuation(writer, 24);
  9982. for (var i = 0; i < typeParameters.length; i++) {
  9983. if (i > 0) {
  9984. writePunctuation(writer, 23);
  9985. writeSpace(writer);
  9986. }
  9987. buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack);
  9988. }
  9989. writePunctuation(writer, 25);
  9990. }
  9991. }
  9992. function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) {
  9993. if (typeParameters && typeParameters.length) {
  9994. writePunctuation(writer, 24);
  9995. for (var i = 0; i < typeParameters.length; i++) {
  9996. if (i > 0) {
  9997. writePunctuation(writer, 23);
  9998. writeSpace(writer);
  9999. }
  10000. buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0);
  10001. }
  10002. writePunctuation(writer, 25);
  10003. }
  10004. }
  10005. function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) {
  10006. writePunctuation(writer, 16);
  10007. for (var i = 0; i < parameters.length; i++) {
  10008. if (i > 0) {
  10009. writePunctuation(writer, 23);
  10010. writeSpace(writer);
  10011. }
  10012. buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack);
  10013. }
  10014. writePunctuation(writer, 17);
  10015. }
  10016. function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) {
  10017. if (flags & 8) {
  10018. writeSpace(writer);
  10019. writePunctuation(writer, 32);
  10020. }
  10021. else {
  10022. writePunctuation(writer, 51);
  10023. }
  10024. writeSpace(writer);
  10025. buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack);
  10026. }
  10027. function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) {
  10028. if (signature.target && (flags & 32)) {
  10029. buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration);
  10030. }
  10031. else {
  10032. buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack);
  10033. }
  10034. buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack);
  10035. buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack);
  10036. }
  10037. return _displayBuilder || (_displayBuilder = {
  10038. symbolToString: symbolToString,
  10039. typeToString: typeToString,
  10040. buildSymbolDisplay: buildSymbolDisplay,
  10041. buildTypeDisplay: buildTypeDisplay,
  10042. buildTypeParameterDisplay: buildTypeParameterDisplay,
  10043. buildParameterDisplay: buildParameterDisplay,
  10044. buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters,
  10045. buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters,
  10046. buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters,
  10047. buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol,
  10048. buildSignatureDisplay: buildSignatureDisplay,
  10049. buildReturnTypeDisplay: buildReturnTypeDisplay
  10050. });
  10051. }
  10052. function isDeclarationVisible(node) {
  10053. function getContainingExternalModule(node) {
  10054. for (; node; node = node.parent) {
  10055. if (node.kind === 206) {
  10056. if (node.name.kind === 8) {
  10057. return node;
  10058. }
  10059. }
  10060. else if (node.kind === 228) {
  10061. return ts.isExternalModule(node) ? node : undefined;
  10062. }
  10063. }
  10064. ts.Debug.fail("getContainingModule cant reach here");
  10065. }
  10066. function isUsedInExportAssignment(node) {
  10067. var externalModule = getContainingExternalModule(node);
  10068. var exportAssignmentSymbol;
  10069. var resolvedExportSymbol;
  10070. if (externalModule) {
  10071. var externalModuleSymbol = getSymbolOfNode(externalModule);
  10072. exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
  10073. var symbolOfNode = getSymbolOfNode(node);
  10074. if (isSymbolUsedInExportAssignment(symbolOfNode)) {
  10075. return true;
  10076. }
  10077. if (symbolOfNode.flags & 8388608) {
  10078. return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode));
  10079. }
  10080. }
  10081. function isSymbolUsedInExportAssignment(symbol) {
  10082. if (exportAssignmentSymbol === symbol) {
  10083. return true;
  10084. }
  10085. if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608)) {
  10086. resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
  10087. if (resolvedExportSymbol === symbol) {
  10088. return true;
  10089. }
  10090. return ts.forEach(resolvedExportSymbol.declarations, function (current) {
  10091. while (current) {
  10092. if (current === node) {
  10093. return true;
  10094. }
  10095. current = current.parent;
  10096. }
  10097. });
  10098. }
  10099. }
  10100. }
  10101. function determineIfDeclarationIsVisible() {
  10102. switch (node.kind) {
  10103. case 153:
  10104. return isDeclarationVisible(node.parent.parent);
  10105. case 199:
  10106. if (ts.isBindingPattern(node.name) &&
  10107. !node.name.elements.length) {
  10108. return false;
  10109. }
  10110. case 206:
  10111. case 202:
  10112. case 203:
  10113. case 204:
  10114. case 201:
  10115. case 205:
  10116. case 209:
  10117. var parent_2 = getDeclarationContainer(node);
  10118. if (!(ts.getCombinedNodeFlags(node) & 1) &&
  10119. !(node.kind !== 209 && parent_2.kind !== 228 && ts.isInAmbientContext(parent_2))) {
  10120. return isGlobalSourceFile(parent_2);
  10121. }
  10122. return isDeclarationVisible(parent_2);
  10123. case 133:
  10124. case 132:
  10125. case 137:
  10126. case 138:
  10127. case 135:
  10128. case 134:
  10129. if (node.flags & (32 | 64)) {
  10130. return false;
  10131. }
  10132. case 136:
  10133. case 140:
  10134. case 139:
  10135. case 141:
  10136. case 130:
  10137. case 207:
  10138. case 143:
  10139. case 144:
  10140. case 146:
  10141. case 142:
  10142. case 147:
  10143. case 148:
  10144. case 149:
  10145. case 150:
  10146. return isDeclarationVisible(node.parent);
  10147. case 211:
  10148. case 212:
  10149. case 214:
  10150. return false;
  10151. case 129:
  10152. case 228:
  10153. return true;
  10154. case 215:
  10155. return false;
  10156. default:
  10157. ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
  10158. }
  10159. }
  10160. if (node) {
  10161. var links = getNodeLinks(node);
  10162. if (links.isVisible === undefined) {
  10163. links.isVisible = !!determineIfDeclarationIsVisible();
  10164. }
  10165. return links.isVisible;
  10166. }
  10167. }
  10168. function collectLinkedAliases(node) {
  10169. var exportSymbol;
  10170. if (node.parent && node.parent.kind === 215) {
  10171. exportSymbol = resolveName(node.parent, node.text, 107455 | 793056 | 1536, ts.Diagnostics.Cannot_find_name_0, node);
  10172. }
  10173. else if (node.parent.kind === 218) {
  10174. exportSymbol = getTargetOfExportSpecifier(node.parent);
  10175. }
  10176. var result = [];
  10177. if (exportSymbol) {
  10178. buildVisibleNodeList(exportSymbol.declarations);
  10179. }
  10180. return result;
  10181. function buildVisibleNodeList(declarations) {
  10182. ts.forEach(declarations, function (declaration) {
  10183. getNodeLinks(declaration).isVisible = true;
  10184. var resultNode = getAnyImportSyntax(declaration) || declaration;
  10185. if (!ts.contains(result, resultNode)) {
  10186. result.push(resultNode);
  10187. }
  10188. if (ts.isInternalModuleImportEqualsDeclaration(declaration)) {
  10189. var internalModuleReference = declaration.moduleReference;
  10190. var firstIdentifier = getFirstIdentifier(internalModuleReference);
  10191. var importSymbol = resolveName(declaration, firstIdentifier.text, 107455 | 793056 | 1536, ts.Diagnostics.Cannot_find_name_0, firstIdentifier);
  10192. buildVisibleNodeList(importSymbol.declarations);
  10193. }
  10194. });
  10195. }
  10196. }
  10197. function pushTypeResolution(target) {
  10198. var i = 0;
  10199. var count = resolutionTargets.length;
  10200. while (i < count && resolutionTargets[i] !== target) {
  10201. i++;
  10202. }
  10203. if (i < count) {
  10204. do {
  10205. resolutionResults[i++] = false;
  10206. } while (i < count);
  10207. return false;
  10208. }
  10209. resolutionTargets.push(target);
  10210. resolutionResults.push(true);
  10211. return true;
  10212. }
  10213. function popTypeResolution() {
  10214. resolutionTargets.pop();
  10215. return resolutionResults.pop();
  10216. }
  10217. function getRootDeclaration(node) {
  10218. while (node.kind === 153) {
  10219. node = node.parent.parent;
  10220. }
  10221. return node;
  10222. }
  10223. function getDeclarationContainer(node) {
  10224. node = getRootDeclaration(node);
  10225. return node.kind === 199 ? node.parent.parent.parent : node.parent;
  10226. }
  10227. function getTypeOfPrototypeProperty(prototype) {
  10228. var classType = getDeclaredTypeOfSymbol(prototype.parent);
  10229. return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType;
  10230. }
  10231. function getTypeOfPropertyOfType(type, name) {
  10232. var prop = getPropertyOfType(type, name);
  10233. return prop ? getTypeOfSymbol(prop) : undefined;
  10234. }
  10235. function getTypeForBindingElement(declaration) {
  10236. var pattern = declaration.parent;
  10237. var parentType = getTypeForVariableLikeDeclaration(pattern.parent);
  10238. if (parentType === unknownType) {
  10239. return unknownType;
  10240. }
  10241. if (!parentType || parentType === anyType) {
  10242. if (declaration.initializer) {
  10243. return checkExpressionCached(declaration.initializer);
  10244. }
  10245. return parentType;
  10246. }
  10247. var type;
  10248. if (pattern.kind === 151) {
  10249. var name_5 = declaration.propertyName || declaration.name;
  10250. type = getTypeOfPropertyOfType(parentType, name_5.text) ||
  10251. isNumericLiteralName(name_5.text) && getIndexTypeOfType(parentType, 1) ||
  10252. getIndexTypeOfType(parentType, 0);
  10253. if (!type) {
  10254. error(name_5, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_5));
  10255. return unknownType;
  10256. }
  10257. }
  10258. else {
  10259. var elementType = checkIteratedTypeOrElementType(parentType, pattern, false);
  10260. if (!declaration.dotDotDotToken) {
  10261. if (elementType.flags & 1) {
  10262. return elementType;
  10263. }
  10264. var propName = "" + ts.indexOf(pattern.elements, declaration);
  10265. type = isTupleLikeType(parentType)
  10266. ? getTypeOfPropertyOfType(parentType, propName)
  10267. : elementType;
  10268. if (!type) {
  10269. if (isTupleType(parentType)) {
  10270. 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);
  10271. }
  10272. else {
  10273. error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName);
  10274. }
  10275. return unknownType;
  10276. }
  10277. }
  10278. else {
  10279. type = createArrayType(elementType);
  10280. }
  10281. }
  10282. return type;
  10283. }
  10284. function getTypeForVariableLikeDeclaration(declaration) {
  10285. if (declaration.parent.parent.kind === 188) {
  10286. return anyType;
  10287. }
  10288. if (declaration.parent.parent.kind === 189) {
  10289. return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType;
  10290. }
  10291. if (ts.isBindingPattern(declaration.parent)) {
  10292. return getTypeForBindingElement(declaration);
  10293. }
  10294. if (declaration.type) {
  10295. return getTypeFromTypeNode(declaration.type);
  10296. }
  10297. if (declaration.kind === 130) {
  10298. var func = declaration.parent;
  10299. if (func.kind === 138 && !ts.hasDynamicName(func)) {
  10300. var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 137);
  10301. if (getter) {
  10302. return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
  10303. }
  10304. }
  10305. var type = getContextuallyTypedParameterType(declaration);
  10306. if (type) {
  10307. return type;
  10308. }
  10309. }
  10310. if (declaration.initializer) {
  10311. return checkExpressionCached(declaration.initializer);
  10312. }
  10313. if (declaration.kind === 226) {
  10314. return checkIdentifier(declaration.name);
  10315. }
  10316. return undefined;
  10317. }
  10318. function getTypeFromBindingElement(element) {
  10319. if (element.initializer) {
  10320. return getWidenedType(checkExpressionCached(element.initializer));
  10321. }
  10322. if (ts.isBindingPattern(element.name)) {
  10323. return getTypeFromBindingPattern(element.name);
  10324. }
  10325. return anyType;
  10326. }
  10327. function getTypeFromObjectBindingPattern(pattern) {
  10328. var members = {};
  10329. ts.forEach(pattern.elements, function (e) {
  10330. var flags = 4 | 67108864 | (e.initializer ? 536870912 : 0);
  10331. var name = e.propertyName || e.name;
  10332. var symbol = createSymbol(flags, name.text);
  10333. symbol.type = getTypeFromBindingElement(e);
  10334. members[symbol.name] = symbol;
  10335. });
  10336. return createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
  10337. }
  10338. function getTypeFromArrayBindingPattern(pattern) {
  10339. var hasSpreadElement = false;
  10340. var elementTypes = [];
  10341. ts.forEach(pattern.elements, function (e) {
  10342. elementTypes.push(e.kind === 176 || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e));
  10343. if (e.dotDotDotToken) {
  10344. hasSpreadElement = true;
  10345. }
  10346. });
  10347. if (!elementTypes.length) {
  10348. return languageVersion >= 2 ? createIterableType(anyType) : anyArrayType;
  10349. }
  10350. else if (hasSpreadElement) {
  10351. var unionOfElements = getUnionType(elementTypes);
  10352. return languageVersion >= 2 ? createIterableType(unionOfElements) : createArrayType(unionOfElements);
  10353. }
  10354. return createTupleType(elementTypes);
  10355. }
  10356. function getTypeFromBindingPattern(pattern) {
  10357. return pattern.kind === 151
  10358. ? getTypeFromObjectBindingPattern(pattern)
  10359. : getTypeFromArrayBindingPattern(pattern);
  10360. }
  10361. function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
  10362. var type = getTypeForVariableLikeDeclaration(declaration);
  10363. if (type) {
  10364. if (reportErrors) {
  10365. reportErrorsFromWidening(declaration, type);
  10366. }
  10367. return declaration.kind !== 225 ? getWidenedType(type) : type;
  10368. }
  10369. if (ts.isBindingPattern(declaration.name)) {
  10370. return getTypeFromBindingPattern(declaration.name);
  10371. }
  10372. type = declaration.dotDotDotToken ? anyArrayType : anyType;
  10373. if (reportErrors && compilerOptions.noImplicitAny) {
  10374. var root = getRootDeclaration(declaration);
  10375. if (!isPrivateWithinAmbient(root) && !(root.kind === 130 && isPrivateWithinAmbient(root.parent))) {
  10376. reportImplicitAnyError(declaration, type);
  10377. }
  10378. }
  10379. return type;
  10380. }
  10381. function getTypeOfVariableOrParameterOrProperty(symbol) {
  10382. var links = getSymbolLinks(symbol);
  10383. if (!links.type) {
  10384. if (symbol.flags & 134217728) {
  10385. return links.type = getTypeOfPrototypeProperty(symbol);
  10386. }
  10387. var declaration = symbol.valueDeclaration;
  10388. if (declaration.parent.kind === 224) {
  10389. return links.type = anyType;
  10390. }
  10391. if (declaration.kind === 215) {
  10392. return links.type = checkExpression(declaration.expression);
  10393. }
  10394. if (!pushTypeResolution(symbol)) {
  10395. return unknownType;
  10396. }
  10397. var type = getWidenedTypeForVariableLikeDeclaration(declaration, true);
  10398. if (!popTypeResolution()) {
  10399. if (symbol.valueDeclaration.type) {
  10400. type = unknownType;
  10401. error(symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
  10402. }
  10403. else {
  10404. type = anyType;
  10405. if (compilerOptions.noImplicitAny) {
  10406. error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol));
  10407. }
  10408. }
  10409. }
  10410. links.type = type;
  10411. }
  10412. return links.type;
  10413. }
  10414. function getSetAccessorTypeAnnotationNode(accessor) {
  10415. return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type;
  10416. }
  10417. function getAnnotatedAccessorType(accessor) {
  10418. if (accessor) {
  10419. if (accessor.kind === 137) {
  10420. return accessor.type && getTypeFromTypeNode(accessor.type);
  10421. }
  10422. else {
  10423. var setterTypeAnnotation = getSetAccessorTypeAnnotationNode(accessor);
  10424. return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation);
  10425. }
  10426. }
  10427. return undefined;
  10428. }
  10429. function getTypeOfAccessors(symbol) {
  10430. var links = getSymbolLinks(symbol);
  10431. if (!links.type) {
  10432. if (!pushTypeResolution(symbol)) {
  10433. return unknownType;
  10434. }
  10435. var getter = ts.getDeclarationOfKind(symbol, 137);
  10436. var setter = ts.getDeclarationOfKind(symbol, 138);
  10437. var type;
  10438. var getterReturnType = getAnnotatedAccessorType(getter);
  10439. if (getterReturnType) {
  10440. type = getterReturnType;
  10441. }
  10442. else {
  10443. var setterParameterType = getAnnotatedAccessorType(setter);
  10444. if (setterParameterType) {
  10445. type = setterParameterType;
  10446. }
  10447. else {
  10448. if (getter && getter.body) {
  10449. type = getReturnTypeFromBody(getter);
  10450. }
  10451. else {
  10452. if (compilerOptions.noImplicitAny) {
  10453. error(setter, ts.Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
  10454. }
  10455. type = anyType;
  10456. }
  10457. }
  10458. }
  10459. if (!popTypeResolution()) {
  10460. type = anyType;
  10461. if (compilerOptions.noImplicitAny) {
  10462. var getter_1 = ts.getDeclarationOfKind(symbol, 137);
  10463. 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));
  10464. }
  10465. }
  10466. links.type = type;
  10467. }
  10468. return links.type;
  10469. }
  10470. function getTypeOfFuncClassEnumModule(symbol) {
  10471. var links = getSymbolLinks(symbol);
  10472. if (!links.type) {
  10473. links.type = createObjectType(32768, symbol);
  10474. }
  10475. return links.type;
  10476. }
  10477. function getTypeOfEnumMember(symbol) {
  10478. var links = getSymbolLinks(symbol);
  10479. if (!links.type) {
  10480. links.type = getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
  10481. }
  10482. return links.type;
  10483. }
  10484. function getTypeOfAlias(symbol) {
  10485. var links = getSymbolLinks(symbol);
  10486. if (!links.type) {
  10487. var targetSymbol = resolveAlias(symbol);
  10488. links.type = targetSymbol.flags & 107455
  10489. ? getTypeOfSymbol(targetSymbol)
  10490. : unknownType;
  10491. }
  10492. return links.type;
  10493. }
  10494. function getTypeOfInstantiatedSymbol(symbol) {
  10495. var links = getSymbolLinks(symbol);
  10496. if (!links.type) {
  10497. links.type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
  10498. }
  10499. return links.type;
  10500. }
  10501. function getTypeOfSymbol(symbol) {
  10502. if (symbol.flags & 16777216) {
  10503. return getTypeOfInstantiatedSymbol(symbol);
  10504. }
  10505. if (symbol.flags & (3 | 4)) {
  10506. return getTypeOfVariableOrParameterOrProperty(symbol);
  10507. }
  10508. if (symbol.flags & (16 | 8192 | 32 | 384 | 512)) {
  10509. return getTypeOfFuncClassEnumModule(symbol);
  10510. }
  10511. if (symbol.flags & 8) {
  10512. return getTypeOfEnumMember(symbol);
  10513. }
  10514. if (symbol.flags & 98304) {
  10515. return getTypeOfAccessors(symbol);
  10516. }
  10517. if (symbol.flags & 8388608) {
  10518. return getTypeOfAlias(symbol);
  10519. }
  10520. return unknownType;
  10521. }
  10522. function getTargetType(type) {
  10523. return type.flags & 4096 ? type.target : type;
  10524. }
  10525. function hasBaseType(type, checkBase) {
  10526. return check(type);
  10527. function check(type) {
  10528. var target = getTargetType(type);
  10529. return target === checkBase || ts.forEach(getBaseTypes(target), check);
  10530. }
  10531. }
  10532. function getTypeParametersOfClassOrInterface(symbol) {
  10533. var result;
  10534. ts.forEach(symbol.declarations, function (node) {
  10535. if (node.kind === 203 || node.kind === 202) {
  10536. var declaration = node;
  10537. if (declaration.typeParameters && declaration.typeParameters.length) {
  10538. ts.forEach(declaration.typeParameters, function (node) {
  10539. var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node));
  10540. if (!result) {
  10541. result = [tp];
  10542. }
  10543. else if (!ts.contains(result, tp)) {
  10544. result.push(tp);
  10545. }
  10546. });
  10547. }
  10548. }
  10549. });
  10550. return result;
  10551. }
  10552. function getBaseTypes(type) {
  10553. var typeWithBaseTypes = type;
  10554. if (!typeWithBaseTypes.baseTypes) {
  10555. if (type.symbol.flags & 32) {
  10556. resolveBaseTypesOfClass(typeWithBaseTypes);
  10557. }
  10558. else if (type.symbol.flags & 64) {
  10559. resolveBaseTypesOfInterface(typeWithBaseTypes);
  10560. }
  10561. else {
  10562. ts.Debug.fail("type must be class or interface");
  10563. }
  10564. }
  10565. return typeWithBaseTypes.baseTypes;
  10566. }
  10567. function resolveBaseTypesOfClass(type) {
  10568. type.baseTypes = [];
  10569. var declaration = ts.getDeclarationOfKind(type.symbol, 202);
  10570. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(declaration);
  10571. if (baseTypeNode) {
  10572. var baseType = getTypeFromTypeNode(baseTypeNode);
  10573. if (baseType !== unknownType) {
  10574. if (getTargetType(baseType).flags & 1024) {
  10575. if (type !== baseType && !hasBaseType(baseType, type)) {
  10576. type.baseTypes.push(baseType);
  10577. }
  10578. else {
  10579. error(declaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, undefined, 1));
  10580. }
  10581. }
  10582. else {
  10583. error(baseTypeNode, ts.Diagnostics.A_class_may_only_extend_another_class);
  10584. }
  10585. }
  10586. }
  10587. }
  10588. function resolveBaseTypesOfInterface(type) {
  10589. type.baseTypes = [];
  10590. for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) {
  10591. var declaration = _a[_i];
  10592. if (declaration.kind === 203 && ts.getInterfaceBaseTypeNodes(declaration)) {
  10593. for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) {
  10594. var node = _c[_b];
  10595. var baseType = getTypeFromTypeNode(node);
  10596. if (baseType !== unknownType) {
  10597. if (getTargetType(baseType).flags & (1024 | 2048)) {
  10598. if (type !== baseType && !hasBaseType(baseType, type)) {
  10599. type.baseTypes.push(baseType);
  10600. }
  10601. else {
  10602. error(declaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, undefined, 1));
  10603. }
  10604. }
  10605. else {
  10606. error(node, ts.Diagnostics.An_interface_may_only_extend_a_class_or_another_interface);
  10607. }
  10608. }
  10609. }
  10610. }
  10611. }
  10612. }
  10613. function getDeclaredTypeOfClassOrInterface(symbol) {
  10614. var links = getSymbolLinks(symbol);
  10615. if (!links.declaredType) {
  10616. var kind = symbol.flags & 32 ? 1024 : 2048;
  10617. var type = links.declaredType = createObjectType(kind, symbol);
  10618. var typeParameters = getTypeParametersOfClassOrInterface(symbol);
  10619. if (typeParameters) {
  10620. type.flags |= 4096;
  10621. type.typeParameters = typeParameters;
  10622. type.instantiations = {};
  10623. type.instantiations[getTypeListId(type.typeParameters)] = type;
  10624. type.target = type;
  10625. type.typeArguments = type.typeParameters;
  10626. }
  10627. }
  10628. return links.declaredType;
  10629. }
  10630. function getDeclaredTypeOfTypeAlias(symbol) {
  10631. var links = getSymbolLinks(symbol);
  10632. if (!links.declaredType) {
  10633. if (!pushTypeResolution(links)) {
  10634. return unknownType;
  10635. }
  10636. var declaration = ts.getDeclarationOfKind(symbol, 204);
  10637. var type = getTypeFromTypeNode(declaration.type);
  10638. if (!popTypeResolution()) {
  10639. type = unknownType;
  10640. error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
  10641. }
  10642. links.declaredType = type;
  10643. }
  10644. return links.declaredType;
  10645. }
  10646. function getDeclaredTypeOfEnum(symbol) {
  10647. var links = getSymbolLinks(symbol);
  10648. if (!links.declaredType) {
  10649. var type = createType(128);
  10650. type.symbol = symbol;
  10651. links.declaredType = type;
  10652. }
  10653. return links.declaredType;
  10654. }
  10655. function getDeclaredTypeOfTypeParameter(symbol) {
  10656. var links = getSymbolLinks(symbol);
  10657. if (!links.declaredType) {
  10658. var type = createType(512);
  10659. type.symbol = symbol;
  10660. if (!ts.getDeclarationOfKind(symbol, 129).constraint) {
  10661. type.constraint = noConstraintType;
  10662. }
  10663. links.declaredType = type;
  10664. }
  10665. return links.declaredType;
  10666. }
  10667. function getDeclaredTypeOfAlias(symbol) {
  10668. var links = getSymbolLinks(symbol);
  10669. if (!links.declaredType) {
  10670. links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol));
  10671. }
  10672. return links.declaredType;
  10673. }
  10674. function getDeclaredTypeOfSymbol(symbol) {
  10675. ts.Debug.assert((symbol.flags & 16777216) === 0);
  10676. if (symbol.flags & (32 | 64)) {
  10677. return getDeclaredTypeOfClassOrInterface(symbol);
  10678. }
  10679. if (symbol.flags & 524288) {
  10680. return getDeclaredTypeOfTypeAlias(symbol);
  10681. }
  10682. if (symbol.flags & 384) {
  10683. return getDeclaredTypeOfEnum(symbol);
  10684. }
  10685. if (symbol.flags & 262144) {
  10686. return getDeclaredTypeOfTypeParameter(symbol);
  10687. }
  10688. if (symbol.flags & 8388608) {
  10689. return getDeclaredTypeOfAlias(symbol);
  10690. }
  10691. return unknownType;
  10692. }
  10693. function createSymbolTable(symbols) {
  10694. var result = {};
  10695. for (var _i = 0; _i < symbols.length; _i++) {
  10696. var symbol = symbols[_i];
  10697. result[symbol.name] = symbol;
  10698. }
  10699. return result;
  10700. }
  10701. function createInstantiatedSymbolTable(symbols, mapper) {
  10702. var result = {};
  10703. for (var _i = 0; _i < symbols.length; _i++) {
  10704. var symbol = symbols[_i];
  10705. result[symbol.name] = instantiateSymbol(symbol, mapper);
  10706. }
  10707. return result;
  10708. }
  10709. function addInheritedMembers(symbols, baseSymbols) {
  10710. for (var _i = 0; _i < baseSymbols.length; _i++) {
  10711. var s = baseSymbols[_i];
  10712. if (!ts.hasProperty(symbols, s.name)) {
  10713. symbols[s.name] = s;
  10714. }
  10715. }
  10716. }
  10717. function addInheritedSignatures(signatures, baseSignatures) {
  10718. if (baseSignatures) {
  10719. for (var _i = 0; _i < baseSignatures.length; _i++) {
  10720. var signature = baseSignatures[_i];
  10721. signatures.push(signature);
  10722. }
  10723. }
  10724. }
  10725. function resolveDeclaredMembers(type) {
  10726. if (!type.declaredProperties) {
  10727. var symbol = type.symbol;
  10728. type.declaredProperties = getNamedMembers(symbol.members);
  10729. type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]);
  10730. type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]);
  10731. type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, 0);
  10732. type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, 1);
  10733. }
  10734. return type;
  10735. }
  10736. function resolveClassOrInterfaceMembers(type) {
  10737. var target = resolveDeclaredMembers(type);
  10738. var members = target.symbol.members;
  10739. var callSignatures = target.declaredCallSignatures;
  10740. var constructSignatures = target.declaredConstructSignatures;
  10741. var stringIndexType = target.declaredStringIndexType;
  10742. var numberIndexType = target.declaredNumberIndexType;
  10743. var baseTypes = getBaseTypes(target);
  10744. if (baseTypes.length) {
  10745. members = createSymbolTable(target.declaredProperties);
  10746. for (var _i = 0; _i < baseTypes.length; _i++) {
  10747. var baseType = baseTypes[_i];
  10748. addInheritedMembers(members, getPropertiesOfObjectType(baseType));
  10749. callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0));
  10750. constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1));
  10751. stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0);
  10752. numberIndexType = numberIndexType || getIndexTypeOfType(baseType, 1);
  10753. }
  10754. }
  10755. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  10756. }
  10757. function resolveTypeReferenceMembers(type) {
  10758. var target = resolveDeclaredMembers(type.target);
  10759. var mapper = createTypeMapper(target.typeParameters, type.typeArguments);
  10760. var members = createInstantiatedSymbolTable(target.declaredProperties, mapper);
  10761. var callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature);
  10762. var constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature);
  10763. var stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined;
  10764. var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined;
  10765. ts.forEach(getBaseTypes(target), function (baseType) {
  10766. var instantiatedBaseType = instantiateType(baseType, mapper);
  10767. addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType));
  10768. callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0));
  10769. constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1));
  10770. stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0);
  10771. numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1);
  10772. });
  10773. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  10774. }
  10775. function createSignature(declaration, typeParameters, parameters, resolvedReturnType, minArgumentCount, hasRestParameter, hasStringLiterals) {
  10776. var sig = new Signature(checker);
  10777. sig.declaration = declaration;
  10778. sig.typeParameters = typeParameters;
  10779. sig.parameters = parameters;
  10780. sig.resolvedReturnType = resolvedReturnType;
  10781. sig.minArgumentCount = minArgumentCount;
  10782. sig.hasRestParameter = hasRestParameter;
  10783. sig.hasStringLiterals = hasStringLiterals;
  10784. return sig;
  10785. }
  10786. function cloneSignature(sig) {
  10787. return createSignature(sig.declaration, sig.typeParameters, sig.parameters, sig.resolvedReturnType, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals);
  10788. }
  10789. function getDefaultConstructSignatures(classType) {
  10790. var baseTypes = getBaseTypes(classType);
  10791. if (baseTypes.length) {
  10792. var baseType = baseTypes[0];
  10793. var baseSignatures = getSignaturesOfType(getTypeOfSymbol(baseType.symbol), 1);
  10794. return ts.map(baseSignatures, function (baseSignature) {
  10795. var signature = baseType.flags & 4096 ?
  10796. getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature);
  10797. signature.typeParameters = classType.typeParameters;
  10798. signature.resolvedReturnType = classType;
  10799. return signature;
  10800. });
  10801. }
  10802. return [createSignature(undefined, classType.typeParameters, emptyArray, classType, 0, false, false)];
  10803. }
  10804. function createTupleTypeMemberSymbols(memberTypes) {
  10805. var members = {};
  10806. for (var i = 0; i < memberTypes.length; i++) {
  10807. var symbol = createSymbol(4 | 67108864, "" + i);
  10808. symbol.type = memberTypes[i];
  10809. members[i] = symbol;
  10810. }
  10811. return members;
  10812. }
  10813. function resolveTupleTypeMembers(type) {
  10814. var arrayType = resolveObjectOrUnionTypeMembers(createArrayType(getUnionType(type.elementTypes)));
  10815. var members = createTupleTypeMemberSymbols(type.elementTypes);
  10816. addInheritedMembers(members, arrayType.properties);
  10817. setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
  10818. }
  10819. function signatureListsIdentical(s, t) {
  10820. if (s.length !== t.length) {
  10821. return false;
  10822. }
  10823. for (var i = 0; i < s.length; i++) {
  10824. if (!compareSignatures(s[i], t[i], false, compareTypes)) {
  10825. return false;
  10826. }
  10827. }
  10828. return true;
  10829. }
  10830. function getUnionSignatures(types, kind) {
  10831. var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); });
  10832. var signatures = signatureLists[0];
  10833. for (var _i = 0; _i < signatures.length; _i++) {
  10834. var signature = signatures[_i];
  10835. if (signature.typeParameters) {
  10836. return emptyArray;
  10837. }
  10838. }
  10839. for (var i_1 = 1; i_1 < signatureLists.length; i_1++) {
  10840. if (!signatureListsIdentical(signatures, signatureLists[i_1])) {
  10841. return emptyArray;
  10842. }
  10843. }
  10844. var result = ts.map(signatures, cloneSignature);
  10845. for (var i = 0; i < result.length; i++) {
  10846. var s = result[i];
  10847. s.resolvedReturnType = undefined;
  10848. s.unionSignatures = ts.map(signatureLists, function (signatures) { return signatures[i]; });
  10849. }
  10850. return result;
  10851. }
  10852. function getUnionIndexType(types, kind) {
  10853. var indexTypes = [];
  10854. for (var _i = 0; _i < types.length; _i++) {
  10855. var type = types[_i];
  10856. var indexType = getIndexTypeOfType(type, kind);
  10857. if (!indexType) {
  10858. return undefined;
  10859. }
  10860. indexTypes.push(indexType);
  10861. }
  10862. return getUnionType(indexTypes);
  10863. }
  10864. function resolveUnionTypeMembers(type) {
  10865. var callSignatures = getUnionSignatures(type.types, 0);
  10866. var constructSignatures = getUnionSignatures(type.types, 1);
  10867. var stringIndexType = getUnionIndexType(type.types, 0);
  10868. var numberIndexType = getUnionIndexType(type.types, 1);
  10869. setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  10870. }
  10871. function resolveAnonymousTypeMembers(type) {
  10872. var symbol = type.symbol;
  10873. var members;
  10874. var callSignatures;
  10875. var constructSignatures;
  10876. var stringIndexType;
  10877. var numberIndexType;
  10878. if (symbol.flags & 2048) {
  10879. members = symbol.members;
  10880. callSignatures = getSignaturesOfSymbol(members["__call"]);
  10881. constructSignatures = getSignaturesOfSymbol(members["__new"]);
  10882. stringIndexType = getIndexTypeOfSymbol(symbol, 0);
  10883. numberIndexType = getIndexTypeOfSymbol(symbol, 1);
  10884. }
  10885. else {
  10886. members = emptySymbols;
  10887. callSignatures = emptyArray;
  10888. constructSignatures = emptyArray;
  10889. if (symbol.flags & 1952) {
  10890. members = getExportsOfSymbol(symbol);
  10891. }
  10892. if (symbol.flags & (16 | 8192)) {
  10893. callSignatures = getSignaturesOfSymbol(symbol);
  10894. }
  10895. if (symbol.flags & 32) {
  10896. var classType = getDeclaredTypeOfClassOrInterface(symbol);
  10897. constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
  10898. if (!constructSignatures.length) {
  10899. constructSignatures = getDefaultConstructSignatures(classType);
  10900. }
  10901. var baseTypes = getBaseTypes(classType);
  10902. if (baseTypes.length) {
  10903. members = createSymbolTable(getNamedMembers(members));
  10904. addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(baseTypes[0].symbol)));
  10905. }
  10906. }
  10907. stringIndexType = undefined;
  10908. numberIndexType = (symbol.flags & 384) ? stringType : undefined;
  10909. }
  10910. setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
  10911. }
  10912. function resolveObjectOrUnionTypeMembers(type) {
  10913. if (!type.members) {
  10914. if (type.flags & (1024 | 2048)) {
  10915. resolveClassOrInterfaceMembers(type);
  10916. }
  10917. else if (type.flags & 32768) {
  10918. resolveAnonymousTypeMembers(type);
  10919. }
  10920. else if (type.flags & 8192) {
  10921. resolveTupleTypeMembers(type);
  10922. }
  10923. else if (type.flags & 16384) {
  10924. resolveUnionTypeMembers(type);
  10925. }
  10926. else {
  10927. resolveTypeReferenceMembers(type);
  10928. }
  10929. }
  10930. return type;
  10931. }
  10932. function getPropertiesOfObjectType(type) {
  10933. if (type.flags & 48128) {
  10934. return resolveObjectOrUnionTypeMembers(type).properties;
  10935. }
  10936. return emptyArray;
  10937. }
  10938. function getPropertyOfObjectType(type, name) {
  10939. if (type.flags & 48128) {
  10940. var resolved = resolveObjectOrUnionTypeMembers(type);
  10941. if (ts.hasProperty(resolved.members, name)) {
  10942. var symbol = resolved.members[name];
  10943. if (symbolIsValue(symbol)) {
  10944. return symbol;
  10945. }
  10946. }
  10947. }
  10948. }
  10949. function getPropertiesOfUnionType(type) {
  10950. var result = [];
  10951. ts.forEach(getPropertiesOfType(type.types[0]), function (prop) {
  10952. var unionProp = getPropertyOfUnionType(type, prop.name);
  10953. if (unionProp) {
  10954. result.push(unionProp);
  10955. }
  10956. });
  10957. return result;
  10958. }
  10959. function getPropertiesOfType(type) {
  10960. type = getApparentType(type);
  10961. return type.flags & 16384 ? getPropertiesOfUnionType(type) : getPropertiesOfObjectType(type);
  10962. }
  10963. function getApparentType(type) {
  10964. if (type.flags & 16384) {
  10965. type = getReducedTypeOfUnionType(type);
  10966. }
  10967. if (type.flags & 512) {
  10968. do {
  10969. type = getConstraintOfTypeParameter(type);
  10970. } while (type && type.flags & 512);
  10971. if (!type) {
  10972. type = emptyObjectType;
  10973. }
  10974. }
  10975. if (type.flags & 258) {
  10976. type = globalStringType;
  10977. }
  10978. else if (type.flags & 132) {
  10979. type = globalNumberType;
  10980. }
  10981. else if (type.flags & 8) {
  10982. type = globalBooleanType;
  10983. }
  10984. else if (type.flags & 1048576) {
  10985. type = globalESSymbolType;
  10986. }
  10987. return type;
  10988. }
  10989. function createUnionProperty(unionType, name) {
  10990. var types = unionType.types;
  10991. var props;
  10992. for (var _i = 0; _i < types.length; _i++) {
  10993. var current = types[_i];
  10994. var type = getApparentType(current);
  10995. if (type !== unknownType) {
  10996. var prop = getPropertyOfType(type, name);
  10997. if (!prop || getDeclarationFlagsFromSymbol(prop) & (32 | 64)) {
  10998. return undefined;
  10999. }
  11000. if (!props) {
  11001. props = [prop];
  11002. }
  11003. else {
  11004. props.push(prop);
  11005. }
  11006. }
  11007. }
  11008. var propTypes = [];
  11009. var declarations = [];
  11010. for (var _a = 0; _a < props.length; _a++) {
  11011. var prop = props[_a];
  11012. if (prop.declarations) {
  11013. declarations.push.apply(declarations, prop.declarations);
  11014. }
  11015. propTypes.push(getTypeOfSymbol(prop));
  11016. }
  11017. var result = createSymbol(4 | 67108864 | 268435456, name);
  11018. result.unionType = unionType;
  11019. result.declarations = declarations;
  11020. result.type = getUnionType(propTypes);
  11021. return result;
  11022. }
  11023. function getPropertyOfUnionType(type, name) {
  11024. var properties = type.resolvedProperties || (type.resolvedProperties = {});
  11025. if (ts.hasProperty(properties, name)) {
  11026. return properties[name];
  11027. }
  11028. var property = createUnionProperty(type, name);
  11029. if (property) {
  11030. properties[name] = property;
  11031. }
  11032. return property;
  11033. }
  11034. function getPropertyOfType(type, name) {
  11035. type = getApparentType(type);
  11036. if (type.flags & 48128) {
  11037. var resolved = resolveObjectOrUnionTypeMembers(type);
  11038. if (ts.hasProperty(resolved.members, name)) {
  11039. var symbol = resolved.members[name];
  11040. if (symbolIsValue(symbol)) {
  11041. return symbol;
  11042. }
  11043. }
  11044. if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) {
  11045. var symbol = getPropertyOfObjectType(globalFunctionType, name);
  11046. if (symbol) {
  11047. return symbol;
  11048. }
  11049. }
  11050. return getPropertyOfObjectType(globalObjectType, name);
  11051. }
  11052. if (type.flags & 16384) {
  11053. return getPropertyOfUnionType(type, name);
  11054. }
  11055. return undefined;
  11056. }
  11057. function getSignaturesOfObjectOrUnionType(type, kind) {
  11058. if (type.flags & (48128 | 16384)) {
  11059. var resolved = resolveObjectOrUnionTypeMembers(type);
  11060. return kind === 0 ? resolved.callSignatures : resolved.constructSignatures;
  11061. }
  11062. return emptyArray;
  11063. }
  11064. function getSignaturesOfType(type, kind) {
  11065. return getSignaturesOfObjectOrUnionType(getApparentType(type), kind);
  11066. }
  11067. function typeHasCallOrConstructSignatures(type) {
  11068. var apparentType = getApparentType(type);
  11069. if (apparentType.flags & (48128 | 16384)) {
  11070. var resolved = resolveObjectOrUnionTypeMembers(type);
  11071. return resolved.callSignatures.length > 0
  11072. || resolved.constructSignatures.length > 0;
  11073. }
  11074. return false;
  11075. }
  11076. function getIndexTypeOfObjectOrUnionType(type, kind) {
  11077. if (type.flags & (48128 | 16384)) {
  11078. var resolved = resolveObjectOrUnionTypeMembers(type);
  11079. return kind === 0 ? resolved.stringIndexType : resolved.numberIndexType;
  11080. }
  11081. }
  11082. function getIndexTypeOfType(type, kind) {
  11083. return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind);
  11084. }
  11085. function getTypeParametersFromDeclaration(typeParameterDeclarations) {
  11086. var result = [];
  11087. ts.forEach(typeParameterDeclarations, function (node) {
  11088. var tp = getDeclaredTypeOfTypeParameter(node.symbol);
  11089. if (!ts.contains(result, tp)) {
  11090. result.push(tp);
  11091. }
  11092. });
  11093. return result;
  11094. }
  11095. function symbolsToArray(symbols) {
  11096. var result = [];
  11097. for (var id in symbols) {
  11098. if (!isReservedMemberName(id)) {
  11099. result.push(symbols[id]);
  11100. }
  11101. }
  11102. return result;
  11103. }
  11104. function getSignatureFromDeclaration(declaration) {
  11105. var links = getNodeLinks(declaration);
  11106. if (!links.resolvedSignature) {
  11107. var classType = declaration.kind === 136 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined;
  11108. var typeParameters = classType ? classType.typeParameters :
  11109. declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined;
  11110. var parameters = [];
  11111. var hasStringLiterals = false;
  11112. var minArgumentCount = -1;
  11113. for (var i = 0, n = declaration.parameters.length; i < n; i++) {
  11114. var param = declaration.parameters[i];
  11115. parameters.push(param.symbol);
  11116. if (param.type && param.type.kind === 8) {
  11117. hasStringLiterals = true;
  11118. }
  11119. if (minArgumentCount < 0) {
  11120. if (param.initializer || param.questionToken || param.dotDotDotToken) {
  11121. minArgumentCount = i;
  11122. }
  11123. }
  11124. }
  11125. if (minArgumentCount < 0) {
  11126. minArgumentCount = declaration.parameters.length;
  11127. }
  11128. var returnType;
  11129. if (classType) {
  11130. returnType = classType;
  11131. }
  11132. else if (declaration.type) {
  11133. returnType = getTypeFromTypeNode(declaration.type);
  11134. }
  11135. else {
  11136. if (declaration.kind === 137 && !ts.hasDynamicName(declaration)) {
  11137. var setter = ts.getDeclarationOfKind(declaration.symbol, 138);
  11138. returnType = getAnnotatedAccessorType(setter);
  11139. }
  11140. if (!returnType && ts.nodeIsMissing(declaration.body)) {
  11141. returnType = anyType;
  11142. }
  11143. }
  11144. links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameters(declaration), hasStringLiterals);
  11145. }
  11146. return links.resolvedSignature;
  11147. }
  11148. function getSignaturesOfSymbol(symbol) {
  11149. if (!symbol)
  11150. return emptyArray;
  11151. var result = [];
  11152. for (var i = 0, len = symbol.declarations.length; i < len; i++) {
  11153. var node = symbol.declarations[i];
  11154. switch (node.kind) {
  11155. case 143:
  11156. case 144:
  11157. case 201:
  11158. case 135:
  11159. case 134:
  11160. case 136:
  11161. case 139:
  11162. case 140:
  11163. case 141:
  11164. case 137:
  11165. case 138:
  11166. case 163:
  11167. case 164:
  11168. if (i > 0 && node.body) {
  11169. var previous = symbol.declarations[i - 1];
  11170. if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) {
  11171. break;
  11172. }
  11173. }
  11174. result.push(getSignatureFromDeclaration(node));
  11175. }
  11176. }
  11177. return result;
  11178. }
  11179. function getReturnTypeOfSignature(signature) {
  11180. if (!signature.resolvedReturnType) {
  11181. if (!pushTypeResolution(signature)) {
  11182. return unknownType;
  11183. }
  11184. var type;
  11185. if (signature.target) {
  11186. type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper);
  11187. }
  11188. else if (signature.unionSignatures) {
  11189. type = getUnionType(ts.map(signature.unionSignatures, getReturnTypeOfSignature));
  11190. }
  11191. else {
  11192. type = getReturnTypeFromBody(signature.declaration);
  11193. }
  11194. if (!popTypeResolution()) {
  11195. type = anyType;
  11196. if (compilerOptions.noImplicitAny) {
  11197. var declaration = signature.declaration;
  11198. if (declaration.name) {
  11199. 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));
  11200. }
  11201. else {
  11202. 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);
  11203. }
  11204. }
  11205. }
  11206. signature.resolvedReturnType = type;
  11207. }
  11208. return signature.resolvedReturnType;
  11209. }
  11210. function getRestTypeOfSignature(signature) {
  11211. if (signature.hasRestParameter) {
  11212. var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
  11213. if (type.flags & 4096 && type.target === globalArrayType) {
  11214. return type.typeArguments[0];
  11215. }
  11216. }
  11217. return anyType;
  11218. }
  11219. function getSignatureInstantiation(signature, typeArguments) {
  11220. return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), true);
  11221. }
  11222. function getErasedSignature(signature) {
  11223. if (!signature.typeParameters)
  11224. return signature;
  11225. if (!signature.erasedSignatureCache) {
  11226. if (signature.target) {
  11227. signature.erasedSignatureCache = instantiateSignature(getErasedSignature(signature.target), signature.mapper);
  11228. }
  11229. else {
  11230. signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), true);
  11231. }
  11232. }
  11233. return signature.erasedSignatureCache;
  11234. }
  11235. function getOrCreateTypeFromSignature(signature) {
  11236. if (!signature.isolatedSignatureType) {
  11237. var isConstructor = signature.declaration.kind === 136 || signature.declaration.kind === 140;
  11238. var type = createObjectType(32768 | 65536);
  11239. type.members = emptySymbols;
  11240. type.properties = emptyArray;
  11241. type.callSignatures = !isConstructor ? [signature] : emptyArray;
  11242. type.constructSignatures = isConstructor ? [signature] : emptyArray;
  11243. signature.isolatedSignatureType = type;
  11244. }
  11245. return signature.isolatedSignatureType;
  11246. }
  11247. function getIndexSymbol(symbol) {
  11248. return symbol.members["__index"];
  11249. }
  11250. function getIndexDeclarationOfSymbol(symbol, kind) {
  11251. var syntaxKind = kind === 1 ? 120 : 122;
  11252. var indexSymbol = getIndexSymbol(symbol);
  11253. if (indexSymbol) {
  11254. var len = indexSymbol.declarations.length;
  11255. for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
  11256. var decl = _a[_i];
  11257. var node = decl;
  11258. if (node.parameters.length === 1) {
  11259. var parameter = node.parameters[0];
  11260. if (parameter && parameter.type && parameter.type.kind === syntaxKind) {
  11261. return node;
  11262. }
  11263. }
  11264. }
  11265. }
  11266. return undefined;
  11267. }
  11268. function getIndexTypeOfSymbol(symbol, kind) {
  11269. var declaration = getIndexDeclarationOfSymbol(symbol, kind);
  11270. return declaration
  11271. ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType
  11272. : undefined;
  11273. }
  11274. function getConstraintOfTypeParameter(type) {
  11275. if (!type.constraint) {
  11276. if (type.target) {
  11277. var targetConstraint = getConstraintOfTypeParameter(type.target);
  11278. type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType;
  11279. }
  11280. else {
  11281. type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 129).constraint);
  11282. }
  11283. }
  11284. return type.constraint === noConstraintType ? undefined : type.constraint;
  11285. }
  11286. function getTypeListId(types) {
  11287. switch (types.length) {
  11288. case 1:
  11289. return "" + types[0].id;
  11290. case 2:
  11291. return types[0].id + "," + types[1].id;
  11292. default:
  11293. var result = "";
  11294. for (var i = 0; i < types.length; i++) {
  11295. if (i > 0) {
  11296. result += ",";
  11297. }
  11298. result += types[i].id;
  11299. }
  11300. return result;
  11301. }
  11302. }
  11303. function getWideningFlagsOfTypes(types) {
  11304. var result = 0;
  11305. for (var _i = 0; _i < types.length; _i++) {
  11306. var type = types[_i];
  11307. result |= type.flags;
  11308. }
  11309. return result & 786432;
  11310. }
  11311. function createTypeReference(target, typeArguments) {
  11312. var id = getTypeListId(typeArguments);
  11313. var type = target.instantiations[id];
  11314. if (!type) {
  11315. var flags = 4096 | getWideningFlagsOfTypes(typeArguments);
  11316. type = target.instantiations[id] = createObjectType(flags, target.symbol);
  11317. type.target = target;
  11318. type.typeArguments = typeArguments;
  11319. }
  11320. return type;
  11321. }
  11322. function isTypeParameterReferenceIllegalInConstraint(typeReferenceNode, typeParameterSymbol) {
  11323. var links = getNodeLinks(typeReferenceNode);
  11324. if (links.isIllegalTypeReferenceInConstraint !== undefined) {
  11325. return links.isIllegalTypeReferenceInConstraint;
  11326. }
  11327. var currentNode = typeReferenceNode;
  11328. while (!ts.forEach(typeParameterSymbol.declarations, function (d) { return d.parent === currentNode.parent; })) {
  11329. currentNode = currentNode.parent;
  11330. }
  11331. links.isIllegalTypeReferenceInConstraint = currentNode.kind === 129;
  11332. return links.isIllegalTypeReferenceInConstraint;
  11333. }
  11334. function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) {
  11335. var typeParameterSymbol;
  11336. function check(n) {
  11337. if (n.kind === 142 && n.typeName.kind === 65) {
  11338. var links = getNodeLinks(n);
  11339. if (links.isIllegalTypeReferenceInConstraint === undefined) {
  11340. var symbol = resolveName(typeParameter, n.typeName.text, 793056, undefined, undefined);
  11341. if (symbol && (symbol.flags & 262144)) {
  11342. links.isIllegalTypeReferenceInConstraint = ts.forEach(symbol.declarations, function (d) { return d.parent == typeParameter.parent; });
  11343. }
  11344. }
  11345. if (links.isIllegalTypeReferenceInConstraint) {
  11346. error(typeParameter, ts.Diagnostics.Constraint_of_a_type_parameter_cannot_reference_any_type_parameter_from_the_same_type_parameter_list);
  11347. }
  11348. }
  11349. ts.forEachChild(n, check);
  11350. }
  11351. if (typeParameter.constraint) {
  11352. typeParameterSymbol = getSymbolOfNode(typeParameter);
  11353. check(typeParameter.constraint);
  11354. }
  11355. }
  11356. function getTypeFromTypeReferenceOrExpressionWithTypeArguments(node) {
  11357. var links = getNodeLinks(node);
  11358. if (!links.resolvedType) {
  11359. var type;
  11360. if (node.kind !== 177 || ts.isSupportedExpressionWithTypeArguments(node)) {
  11361. var typeNameOrExpression = node.kind === 142
  11362. ? node.typeName
  11363. : node.expression;
  11364. var symbol = resolveEntityName(typeNameOrExpression, 793056);
  11365. if (symbol) {
  11366. if ((symbol.flags & 262144) && isTypeParameterReferenceIllegalInConstraint(node, symbol)) {
  11367. type = unknownType;
  11368. }
  11369. else {
  11370. type = getDeclaredTypeOfSymbol(symbol);
  11371. if (type.flags & (1024 | 2048) && type.flags & 4096) {
  11372. var typeParameters = type.typeParameters;
  11373. if (node.typeArguments && node.typeArguments.length === typeParameters.length) {
  11374. type = createTypeReference(type, ts.map(node.typeArguments, getTypeFromTypeNode));
  11375. }
  11376. else {
  11377. error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), typeParameters.length);
  11378. type = undefined;
  11379. }
  11380. }
  11381. else {
  11382. if (node.typeArguments) {
  11383. error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type));
  11384. type = undefined;
  11385. }
  11386. }
  11387. }
  11388. }
  11389. }
  11390. links.resolvedType = type || unknownType;
  11391. }
  11392. return links.resolvedType;
  11393. }
  11394. function getTypeFromTypeQueryNode(node) {
  11395. var links = getNodeLinks(node);
  11396. if (!links.resolvedType) {
  11397. links.resolvedType = getWidenedType(checkExpressionOrQualifiedName(node.exprName));
  11398. }
  11399. return links.resolvedType;
  11400. }
  11401. function getTypeOfGlobalSymbol(symbol, arity) {
  11402. function getTypeDeclaration(symbol) {
  11403. var declarations = symbol.declarations;
  11404. for (var _i = 0; _i < declarations.length; _i++) {
  11405. var declaration = declarations[_i];
  11406. switch (declaration.kind) {
  11407. case 202:
  11408. case 203:
  11409. case 205:
  11410. return declaration;
  11411. }
  11412. }
  11413. }
  11414. if (!symbol) {
  11415. return emptyObjectType;
  11416. }
  11417. var type = getDeclaredTypeOfSymbol(symbol);
  11418. if (!(type.flags & 48128)) {
  11419. error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
  11420. return emptyObjectType;
  11421. }
  11422. if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) {
  11423. error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
  11424. return emptyObjectType;
  11425. }
  11426. return type;
  11427. }
  11428. function getGlobalValueSymbol(name) {
  11429. return getGlobalSymbol(name, 107455, ts.Diagnostics.Cannot_find_global_value_0);
  11430. }
  11431. function getGlobalTypeSymbol(name) {
  11432. return getGlobalSymbol(name, 793056, ts.Diagnostics.Cannot_find_global_type_0);
  11433. }
  11434. function getGlobalSymbol(name, meaning, diagnostic) {
  11435. return resolveName(undefined, name, meaning, diagnostic, name);
  11436. }
  11437. function getGlobalType(name, arity) {
  11438. if (arity === void 0) { arity = 0; }
  11439. return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity);
  11440. }
  11441. function getGlobalESSymbolConstructorSymbol() {
  11442. return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"));
  11443. }
  11444. function createIterableType(elementType) {
  11445. return globalIterableType !== emptyObjectType ? createTypeReference(globalIterableType, [elementType]) : emptyObjectType;
  11446. }
  11447. function createArrayType(elementType) {
  11448. var arrayType = globalArrayType || getDeclaredTypeOfSymbol(globalArraySymbol);
  11449. return arrayType !== emptyObjectType ? createTypeReference(arrayType, [elementType]) : emptyObjectType;
  11450. }
  11451. function getTypeFromArrayTypeNode(node) {
  11452. var links = getNodeLinks(node);
  11453. if (!links.resolvedType) {
  11454. links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType));
  11455. }
  11456. return links.resolvedType;
  11457. }
  11458. function createTupleType(elementTypes) {
  11459. var id = getTypeListId(elementTypes);
  11460. var type = tupleTypes[id];
  11461. if (!type) {
  11462. type = tupleTypes[id] = createObjectType(8192);
  11463. type.elementTypes = elementTypes;
  11464. }
  11465. return type;
  11466. }
  11467. function getTypeFromTupleTypeNode(node) {
  11468. var links = getNodeLinks(node);
  11469. if (!links.resolvedType) {
  11470. links.resolvedType = createTupleType(ts.map(node.elementTypes, getTypeFromTypeNode));
  11471. }
  11472. return links.resolvedType;
  11473. }
  11474. function addTypeToSortedSet(sortedSet, type) {
  11475. if (type.flags & 16384) {
  11476. addTypesToSortedSet(sortedSet, type.types);
  11477. }
  11478. else {
  11479. var i = 0;
  11480. var id = type.id;
  11481. while (i < sortedSet.length && sortedSet[i].id < id) {
  11482. i++;
  11483. }
  11484. if (i === sortedSet.length || sortedSet[i].id !== id) {
  11485. sortedSet.splice(i, 0, type);
  11486. }
  11487. }
  11488. }
  11489. function addTypesToSortedSet(sortedTypes, types) {
  11490. for (var _i = 0; _i < types.length; _i++) {
  11491. var type = types[_i];
  11492. addTypeToSortedSet(sortedTypes, type);
  11493. }
  11494. }
  11495. function isSubtypeOfAny(candidate, types) {
  11496. for (var _i = 0; _i < types.length; _i++) {
  11497. var type = types[_i];
  11498. if (candidate !== type && isTypeSubtypeOf(candidate, type)) {
  11499. return true;
  11500. }
  11501. }
  11502. return false;
  11503. }
  11504. var removeSubtypesStack = [];
  11505. function removeSubtypes(types) {
  11506. var typeListId = getTypeListId(types);
  11507. if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) {
  11508. return;
  11509. }
  11510. removeSubtypesStack.push(typeListId);
  11511. var i = types.length;
  11512. while (i > 0) {
  11513. i--;
  11514. if (isSubtypeOfAny(types[i], types)) {
  11515. types.splice(i, 1);
  11516. }
  11517. }
  11518. removeSubtypesStack.pop();
  11519. }
  11520. function containsAnyType(types) {
  11521. for (var _i = 0; _i < types.length; _i++) {
  11522. var type = types[_i];
  11523. if (type.flags & 1) {
  11524. return true;
  11525. }
  11526. }
  11527. return false;
  11528. }
  11529. function removeAllButLast(types, typeToRemove) {
  11530. var i = types.length;
  11531. while (i > 0 && types.length > 1) {
  11532. i--;
  11533. if (types[i] === typeToRemove) {
  11534. types.splice(i, 1);
  11535. }
  11536. }
  11537. }
  11538. function getUnionType(types, noSubtypeReduction) {
  11539. if (types.length === 0) {
  11540. return emptyObjectType;
  11541. }
  11542. var sortedTypes = [];
  11543. addTypesToSortedSet(sortedTypes, types);
  11544. if (noSubtypeReduction) {
  11545. if (containsAnyType(sortedTypes)) {
  11546. return anyType;
  11547. }
  11548. removeAllButLast(sortedTypes, undefinedType);
  11549. removeAllButLast(sortedTypes, nullType);
  11550. }
  11551. else {
  11552. removeSubtypes(sortedTypes);
  11553. }
  11554. if (sortedTypes.length === 1) {
  11555. return sortedTypes[0];
  11556. }
  11557. var id = getTypeListId(sortedTypes);
  11558. var type = unionTypes[id];
  11559. if (!type) {
  11560. type = unionTypes[id] = createObjectType(16384 | getWideningFlagsOfTypes(sortedTypes));
  11561. type.types = sortedTypes;
  11562. type.reducedType = noSubtypeReduction ? undefined : type;
  11563. }
  11564. return type;
  11565. }
  11566. function getReducedTypeOfUnionType(type) {
  11567. if (!type.reducedType) {
  11568. type.reducedType = getUnionType(type.types, false);
  11569. }
  11570. return type.reducedType;
  11571. }
  11572. function getTypeFromUnionTypeNode(node) {
  11573. var links = getNodeLinks(node);
  11574. if (!links.resolvedType) {
  11575. links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), true);
  11576. }
  11577. return links.resolvedType;
  11578. }
  11579. function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node) {
  11580. var links = getNodeLinks(node);
  11581. if (!links.resolvedType) {
  11582. links.resolvedType = createObjectType(32768, node.symbol);
  11583. }
  11584. return links.resolvedType;
  11585. }
  11586. function getStringLiteralType(node) {
  11587. if (ts.hasProperty(stringLiteralTypes, node.text)) {
  11588. return stringLiteralTypes[node.text];
  11589. }
  11590. var type = stringLiteralTypes[node.text] = createType(256);
  11591. type.text = ts.getTextOfNode(node);
  11592. return type;
  11593. }
  11594. function getTypeFromStringLiteral(node) {
  11595. var links = getNodeLinks(node);
  11596. if (!links.resolvedType) {
  11597. links.resolvedType = getStringLiteralType(node);
  11598. }
  11599. return links.resolvedType;
  11600. }
  11601. function getTypeFromTypeNode(node) {
  11602. switch (node.kind) {
  11603. case 112:
  11604. return anyType;
  11605. case 122:
  11606. return stringType;
  11607. case 120:
  11608. return numberType;
  11609. case 113:
  11610. return booleanType;
  11611. case 123:
  11612. return esSymbolType;
  11613. case 99:
  11614. return voidType;
  11615. case 8:
  11616. return getTypeFromStringLiteral(node);
  11617. case 142:
  11618. return getTypeFromTypeReferenceOrExpressionWithTypeArguments(node);
  11619. case 177:
  11620. return getTypeFromTypeReferenceOrExpressionWithTypeArguments(node);
  11621. case 145:
  11622. return getTypeFromTypeQueryNode(node);
  11623. case 147:
  11624. return getTypeFromArrayTypeNode(node);
  11625. case 148:
  11626. return getTypeFromTupleTypeNode(node);
  11627. case 149:
  11628. return getTypeFromUnionTypeNode(node);
  11629. case 150:
  11630. return getTypeFromTypeNode(node.type);
  11631. case 143:
  11632. case 144:
  11633. case 146:
  11634. return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
  11635. case 65:
  11636. case 127:
  11637. var symbol = getSymbolInfo(node);
  11638. return symbol && getDeclaredTypeOfSymbol(symbol);
  11639. default:
  11640. return unknownType;
  11641. }
  11642. }
  11643. function instantiateList(items, mapper, instantiator) {
  11644. if (items && items.length) {
  11645. var result = [];
  11646. for (var _i = 0; _i < items.length; _i++) {
  11647. var v = items[_i];
  11648. result.push(instantiator(v, mapper));
  11649. }
  11650. return result;
  11651. }
  11652. return items;
  11653. }
  11654. function createUnaryTypeMapper(source, target) {
  11655. return function (t) { return t === source ? target : t; };
  11656. }
  11657. function createBinaryTypeMapper(source1, target1, source2, target2) {
  11658. return function (t) { return t === source1 ? target1 : t === source2 ? target2 : t; };
  11659. }
  11660. function createTypeMapper(sources, targets) {
  11661. switch (sources.length) {
  11662. case 1: return createUnaryTypeMapper(sources[0], targets[0]);
  11663. case 2: return createBinaryTypeMapper(sources[0], targets[0], sources[1], targets[1]);
  11664. }
  11665. return function (t) {
  11666. for (var i = 0; i < sources.length; i++) {
  11667. if (t === sources[i]) {
  11668. return targets[i];
  11669. }
  11670. }
  11671. return t;
  11672. };
  11673. }
  11674. function createUnaryTypeEraser(source) {
  11675. return function (t) { return t === source ? anyType : t; };
  11676. }
  11677. function createBinaryTypeEraser(source1, source2) {
  11678. return function (t) { return t === source1 || t === source2 ? anyType : t; };
  11679. }
  11680. function createTypeEraser(sources) {
  11681. switch (sources.length) {
  11682. case 1: return createUnaryTypeEraser(sources[0]);
  11683. case 2: return createBinaryTypeEraser(sources[0], sources[1]);
  11684. }
  11685. return function (t) {
  11686. for (var _i = 0; _i < sources.length; _i++) {
  11687. var source = sources[_i];
  11688. if (t === source) {
  11689. return anyType;
  11690. }
  11691. }
  11692. return t;
  11693. };
  11694. }
  11695. function createInferenceMapper(context) {
  11696. return function (t) {
  11697. for (var i = 0; i < context.typeParameters.length; i++) {
  11698. if (t === context.typeParameters[i]) {
  11699. context.inferences[i].isFixed = true;
  11700. return getInferredType(context, i);
  11701. }
  11702. }
  11703. return t;
  11704. };
  11705. }
  11706. function identityMapper(type) {
  11707. return type;
  11708. }
  11709. function combineTypeMappers(mapper1, mapper2) {
  11710. return function (t) { return instantiateType(mapper1(t), mapper2); };
  11711. }
  11712. function instantiateTypeParameter(typeParameter, mapper) {
  11713. var result = createType(512);
  11714. result.symbol = typeParameter.symbol;
  11715. if (typeParameter.constraint) {
  11716. result.constraint = instantiateType(typeParameter.constraint, mapper);
  11717. }
  11718. else {
  11719. result.target = typeParameter;
  11720. result.mapper = mapper;
  11721. }
  11722. return result;
  11723. }
  11724. function instantiateSignature(signature, mapper, eraseTypeParameters) {
  11725. var freshTypeParameters;
  11726. if (signature.typeParameters && !eraseTypeParameters) {
  11727. freshTypeParameters = instantiateList(signature.typeParameters, mapper, instantiateTypeParameter);
  11728. mapper = combineTypeMappers(createTypeMapper(signature.typeParameters, freshTypeParameters), mapper);
  11729. }
  11730. var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), signature.resolvedReturnType ? instantiateType(signature.resolvedReturnType, mapper) : undefined, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals);
  11731. result.target = signature;
  11732. result.mapper = mapper;
  11733. return result;
  11734. }
  11735. function instantiateSymbol(symbol, mapper) {
  11736. if (symbol.flags & 16777216) {
  11737. var links = getSymbolLinks(symbol);
  11738. symbol = links.target;
  11739. mapper = combineTypeMappers(links.mapper, mapper);
  11740. }
  11741. var result = createSymbol(16777216 | 67108864 | symbol.flags, symbol.name);
  11742. result.declarations = symbol.declarations;
  11743. result.parent = symbol.parent;
  11744. result.target = symbol;
  11745. result.mapper = mapper;
  11746. if (symbol.valueDeclaration) {
  11747. result.valueDeclaration = symbol.valueDeclaration;
  11748. }
  11749. return result;
  11750. }
  11751. function instantiateAnonymousType(type, mapper) {
  11752. var result = createObjectType(32768, type.symbol);
  11753. result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
  11754. result.members = createSymbolTable(result.properties);
  11755. result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature);
  11756. result.constructSignatures = instantiateList(getSignaturesOfType(type, 1), mapper, instantiateSignature);
  11757. var stringIndexType = getIndexTypeOfType(type, 0);
  11758. var numberIndexType = getIndexTypeOfType(type, 1);
  11759. if (stringIndexType)
  11760. result.stringIndexType = instantiateType(stringIndexType, mapper);
  11761. if (numberIndexType)
  11762. result.numberIndexType = instantiateType(numberIndexType, mapper);
  11763. return result;
  11764. }
  11765. function instantiateType(type, mapper) {
  11766. if (mapper !== identityMapper) {
  11767. if (type.flags & 512) {
  11768. return mapper(type);
  11769. }
  11770. if (type.flags & 32768) {
  11771. return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ?
  11772. instantiateAnonymousType(type, mapper) : type;
  11773. }
  11774. if (type.flags & 4096) {
  11775. return createTypeReference(type.target, instantiateList(type.typeArguments, mapper, instantiateType));
  11776. }
  11777. if (type.flags & 8192) {
  11778. return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType));
  11779. }
  11780. if (type.flags & 16384) {
  11781. return getUnionType(instantiateList(type.types, mapper, instantiateType), true);
  11782. }
  11783. }
  11784. return type;
  11785. }
  11786. function isContextSensitive(node) {
  11787. ts.Debug.assert(node.kind !== 135 || ts.isObjectLiteralMethod(node));
  11788. switch (node.kind) {
  11789. case 163:
  11790. case 164:
  11791. return isContextSensitiveFunctionLikeDeclaration(node);
  11792. case 155:
  11793. return ts.forEach(node.properties, isContextSensitive);
  11794. case 154:
  11795. return ts.forEach(node.elements, isContextSensitive);
  11796. case 171:
  11797. return isContextSensitive(node.whenTrue) ||
  11798. isContextSensitive(node.whenFalse);
  11799. case 170:
  11800. return node.operatorToken.kind === 49 &&
  11801. (isContextSensitive(node.left) || isContextSensitive(node.right));
  11802. case 225:
  11803. return isContextSensitive(node.initializer);
  11804. case 135:
  11805. case 134:
  11806. return isContextSensitiveFunctionLikeDeclaration(node);
  11807. case 162:
  11808. return isContextSensitive(node.expression);
  11809. }
  11810. return false;
  11811. }
  11812. function isContextSensitiveFunctionLikeDeclaration(node) {
  11813. return !node.typeParameters && node.parameters.length && !ts.forEach(node.parameters, function (p) { return p.type; });
  11814. }
  11815. function getTypeWithoutConstructors(type) {
  11816. if (type.flags & 48128) {
  11817. var resolved = resolveObjectOrUnionTypeMembers(type);
  11818. if (resolved.constructSignatures.length) {
  11819. var result = createObjectType(32768, type.symbol);
  11820. result.members = resolved.members;
  11821. result.properties = resolved.properties;
  11822. result.callSignatures = resolved.callSignatures;
  11823. result.constructSignatures = emptyArray;
  11824. type = result;
  11825. }
  11826. }
  11827. return type;
  11828. }
  11829. var subtypeRelation = {};
  11830. var assignableRelation = {};
  11831. var identityRelation = {};
  11832. function isTypeIdenticalTo(source, target) {
  11833. return checkTypeRelatedTo(source, target, identityRelation, undefined);
  11834. }
  11835. function compareTypes(source, target) {
  11836. return checkTypeRelatedTo(source, target, identityRelation, undefined) ? -1 : 0;
  11837. }
  11838. function isTypeSubtypeOf(source, target) {
  11839. return checkTypeSubtypeOf(source, target, undefined);
  11840. }
  11841. function isTypeAssignableTo(source, target) {
  11842. return checkTypeAssignableTo(source, target, undefined);
  11843. }
  11844. function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) {
  11845. return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain);
  11846. }
  11847. function checkTypeAssignableTo(source, target, errorNode, headMessage) {
  11848. return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage);
  11849. }
  11850. function isSignatureAssignableTo(source, target) {
  11851. var sourceType = getOrCreateTypeFromSignature(source);
  11852. var targetType = getOrCreateTypeFromSignature(target);
  11853. return checkTypeRelatedTo(sourceType, targetType, assignableRelation, undefined);
  11854. }
  11855. function checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain) {
  11856. var errorInfo;
  11857. var sourceStack;
  11858. var targetStack;
  11859. var maybeStack;
  11860. var expandingFlags;
  11861. var depth = 0;
  11862. var overflow = false;
  11863. var elaborateErrors = false;
  11864. ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
  11865. var result = isRelatedTo(source, target, errorNode !== undefined, headMessage);
  11866. if (overflow) {
  11867. error(errorNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
  11868. }
  11869. else if (errorInfo) {
  11870. if (errorInfo.next === undefined) {
  11871. errorInfo = undefined;
  11872. elaborateErrors = true;
  11873. isRelatedTo(source, target, errorNode !== undefined, headMessage);
  11874. }
  11875. if (containingMessageChain) {
  11876. errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
  11877. }
  11878. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
  11879. }
  11880. return result !== 0;
  11881. function reportError(message, arg0, arg1, arg2) {
  11882. errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
  11883. }
  11884. function isRelatedTo(source, target, reportErrors, headMessage) {
  11885. var result;
  11886. if (source === target)
  11887. return -1;
  11888. if (relation !== identityRelation) {
  11889. if (target.flags & 1)
  11890. return -1;
  11891. if (source === undefinedType)
  11892. return -1;
  11893. if (source === nullType && target !== undefinedType)
  11894. return -1;
  11895. if (source.flags & 128 && target === numberType)
  11896. return -1;
  11897. if (source.flags & 256 && target === stringType)
  11898. return -1;
  11899. if (relation === assignableRelation) {
  11900. if (source.flags & 1)
  11901. return -1;
  11902. if (source === numberType && target.flags & 128)
  11903. return -1;
  11904. }
  11905. }
  11906. var saveErrorInfo = errorInfo;
  11907. if (source.flags & 16384 || target.flags & 16384) {
  11908. if (relation === identityRelation) {
  11909. if (source.flags & 16384 && target.flags & 16384) {
  11910. if (result = unionTypeRelatedToUnionType(source, target)) {
  11911. if (result &= unionTypeRelatedToUnionType(target, source)) {
  11912. return result;
  11913. }
  11914. }
  11915. }
  11916. else if (source.flags & 16384) {
  11917. if (result = unionTypeRelatedToType(source, target, reportErrors)) {
  11918. return result;
  11919. }
  11920. }
  11921. else {
  11922. if (result = unionTypeRelatedToType(target, source, reportErrors)) {
  11923. return result;
  11924. }
  11925. }
  11926. }
  11927. else {
  11928. if (source.flags & 16384) {
  11929. if (result = unionTypeRelatedToType(source, target, reportErrors)) {
  11930. return result;
  11931. }
  11932. }
  11933. else {
  11934. if (result = typeRelatedToUnionType(source, target, reportErrors)) {
  11935. return result;
  11936. }
  11937. }
  11938. }
  11939. }
  11940. else if (source.flags & 512 && target.flags & 512) {
  11941. if (result = typeParameterRelatedTo(source, target, reportErrors)) {
  11942. return result;
  11943. }
  11944. }
  11945. else if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  11946. if (result = typesRelatedTo(source.typeArguments, target.typeArguments, reportErrors)) {
  11947. return result;
  11948. }
  11949. }
  11950. var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo;
  11951. var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
  11952. if (sourceOrApparentType.flags & 48128 && target.flags & 48128) {
  11953. if (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors)) {
  11954. errorInfo = saveErrorInfo;
  11955. return result;
  11956. }
  11957. }
  11958. else if (source.flags & 512 && sourceOrApparentType.flags & 16384) {
  11959. errorInfo = saveErrorInfo;
  11960. if (result = isRelatedTo(sourceOrApparentType, target, reportErrors)) {
  11961. return result;
  11962. }
  11963. }
  11964. if (reportErrors) {
  11965. headMessage = headMessage || ts.Diagnostics.Type_0_is_not_assignable_to_type_1;
  11966. var sourceType = typeToString(source);
  11967. var targetType = typeToString(target);
  11968. if (sourceType === targetType) {
  11969. sourceType = typeToString(source, undefined, 128);
  11970. targetType = typeToString(target, undefined, 128);
  11971. }
  11972. reportError(headMessage, sourceType, targetType);
  11973. }
  11974. return 0;
  11975. }
  11976. function unionTypeRelatedToUnionType(source, target) {
  11977. var result = -1;
  11978. var sourceTypes = source.types;
  11979. for (var _i = 0; _i < sourceTypes.length; _i++) {
  11980. var sourceType = sourceTypes[_i];
  11981. var related = typeRelatedToUnionType(sourceType, target, false);
  11982. if (!related) {
  11983. return 0;
  11984. }
  11985. result &= related;
  11986. }
  11987. return result;
  11988. }
  11989. function typeRelatedToUnionType(source, target, reportErrors) {
  11990. var targetTypes = target.types;
  11991. for (var i = 0, len = targetTypes.length; i < len; i++) {
  11992. var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1);
  11993. if (related) {
  11994. return related;
  11995. }
  11996. }
  11997. return 0;
  11998. }
  11999. function unionTypeRelatedToType(source, target, reportErrors) {
  12000. var result = -1;
  12001. var sourceTypes = source.types;
  12002. for (var _i = 0; _i < sourceTypes.length; _i++) {
  12003. var sourceType = sourceTypes[_i];
  12004. var related = isRelatedTo(sourceType, target, reportErrors);
  12005. if (!related) {
  12006. return 0;
  12007. }
  12008. result &= related;
  12009. }
  12010. return result;
  12011. }
  12012. function typesRelatedTo(sources, targets, reportErrors) {
  12013. var result = -1;
  12014. for (var i = 0, len = sources.length; i < len; i++) {
  12015. var related = isRelatedTo(sources[i], targets[i], reportErrors);
  12016. if (!related) {
  12017. return 0;
  12018. }
  12019. result &= related;
  12020. }
  12021. return result;
  12022. }
  12023. function typeParameterRelatedTo(source, target, reportErrors) {
  12024. if (relation === identityRelation) {
  12025. if (source.symbol.name !== target.symbol.name) {
  12026. return 0;
  12027. }
  12028. if (source.constraint === target.constraint) {
  12029. return -1;
  12030. }
  12031. if (source.constraint === noConstraintType || target.constraint === noConstraintType) {
  12032. return 0;
  12033. }
  12034. return isRelatedTo(source.constraint, target.constraint, reportErrors);
  12035. }
  12036. else {
  12037. while (true) {
  12038. var constraint = getConstraintOfTypeParameter(source);
  12039. if (constraint === target)
  12040. return -1;
  12041. if (!(constraint && constraint.flags & 512))
  12042. break;
  12043. source = constraint;
  12044. }
  12045. return 0;
  12046. }
  12047. }
  12048. function objectTypeRelatedTo(source, target, reportErrors) {
  12049. if (overflow) {
  12050. return 0;
  12051. }
  12052. var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
  12053. var related = relation[id];
  12054. if (related !== undefined) {
  12055. if (!elaborateErrors || (related === 3)) {
  12056. return related === 1 ? -1 : 0;
  12057. }
  12058. }
  12059. if (depth > 0) {
  12060. for (var i = 0; i < depth; i++) {
  12061. if (maybeStack[i][id]) {
  12062. return 1;
  12063. }
  12064. }
  12065. if (depth === 100) {
  12066. overflow = true;
  12067. return 0;
  12068. }
  12069. }
  12070. else {
  12071. sourceStack = [];
  12072. targetStack = [];
  12073. maybeStack = [];
  12074. expandingFlags = 0;
  12075. }
  12076. sourceStack[depth] = source;
  12077. targetStack[depth] = target;
  12078. maybeStack[depth] = {};
  12079. maybeStack[depth][id] = 1;
  12080. depth++;
  12081. var saveExpandingFlags = expandingFlags;
  12082. if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack))
  12083. expandingFlags |= 1;
  12084. if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack))
  12085. expandingFlags |= 2;
  12086. var result;
  12087. if (expandingFlags === 3) {
  12088. result = 1;
  12089. }
  12090. else {
  12091. result = propertiesRelatedTo(source, target, reportErrors);
  12092. if (result) {
  12093. result &= signaturesRelatedTo(source, target, 0, reportErrors);
  12094. if (result) {
  12095. result &= signaturesRelatedTo(source, target, 1, reportErrors);
  12096. if (result) {
  12097. result &= stringIndexTypesRelatedTo(source, target, reportErrors);
  12098. if (result) {
  12099. result &= numberIndexTypesRelatedTo(source, target, reportErrors);
  12100. }
  12101. }
  12102. }
  12103. }
  12104. }
  12105. expandingFlags = saveExpandingFlags;
  12106. depth--;
  12107. if (result) {
  12108. var maybeCache = maybeStack[depth];
  12109. var destinationCache = (result === -1 || depth === 0) ? relation : maybeStack[depth - 1];
  12110. ts.copyMap(maybeCache, destinationCache);
  12111. }
  12112. else {
  12113. relation[id] = reportErrors ? 3 : 2;
  12114. }
  12115. return result;
  12116. }
  12117. function isDeeplyNestedGeneric(type, stack) {
  12118. if (type.flags & 4096 && depth >= 10) {
  12119. var target_1 = type.target;
  12120. var count = 0;
  12121. for (var i = 0; i < depth; i++) {
  12122. var t = stack[i];
  12123. if (t.flags & 4096 && t.target === target_1) {
  12124. count++;
  12125. if (count >= 10)
  12126. return true;
  12127. }
  12128. }
  12129. }
  12130. return false;
  12131. }
  12132. function propertiesRelatedTo(source, target, reportErrors) {
  12133. if (relation === identityRelation) {
  12134. return propertiesIdenticalTo(source, target);
  12135. }
  12136. var result = -1;
  12137. var properties = getPropertiesOfObjectType(target);
  12138. var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072);
  12139. for (var _i = 0; _i < properties.length; _i++) {
  12140. var targetProp = properties[_i];
  12141. var sourceProp = getPropertyOfType(source, targetProp.name);
  12142. if (sourceProp !== targetProp) {
  12143. if (!sourceProp) {
  12144. if (!(targetProp.flags & 536870912) || requireOptionalProperties) {
  12145. if (reportErrors) {
  12146. reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source));
  12147. }
  12148. return 0;
  12149. }
  12150. }
  12151. else if (!(targetProp.flags & 134217728)) {
  12152. var sourceFlags = getDeclarationFlagsFromSymbol(sourceProp);
  12153. var targetFlags = getDeclarationFlagsFromSymbol(targetProp);
  12154. if (sourceFlags & 32 || targetFlags & 32) {
  12155. if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
  12156. if (reportErrors) {
  12157. if (sourceFlags & 32 && targetFlags & 32) {
  12158. reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp));
  12159. }
  12160. else {
  12161. reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourceFlags & 32 ? source : target), typeToString(sourceFlags & 32 ? target : source));
  12162. }
  12163. }
  12164. return 0;
  12165. }
  12166. }
  12167. else if (targetFlags & 64) {
  12168. var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32;
  12169. var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined;
  12170. var targetClass = getDeclaredTypeOfSymbol(targetProp.parent);
  12171. if (!sourceClass || !hasBaseType(sourceClass, targetClass)) {
  12172. if (reportErrors) {
  12173. reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass));
  12174. }
  12175. return 0;
  12176. }
  12177. }
  12178. else if (sourceFlags & 64) {
  12179. if (reportErrors) {
  12180. reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target));
  12181. }
  12182. return 0;
  12183. }
  12184. var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
  12185. if (!related) {
  12186. if (reportErrors) {
  12187. reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));
  12188. }
  12189. return 0;
  12190. }
  12191. result &= related;
  12192. if (sourceProp.flags & 536870912 && !(targetProp.flags & 536870912)) {
  12193. if (reportErrors) {
  12194. reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target));
  12195. }
  12196. return 0;
  12197. }
  12198. }
  12199. }
  12200. }
  12201. return result;
  12202. }
  12203. function propertiesIdenticalTo(source, target) {
  12204. var sourceProperties = getPropertiesOfObjectType(source);
  12205. var targetProperties = getPropertiesOfObjectType(target);
  12206. if (sourceProperties.length !== targetProperties.length) {
  12207. return 0;
  12208. }
  12209. var result = -1;
  12210. for (var _i = 0; _i < sourceProperties.length; _i++) {
  12211. var sourceProp = sourceProperties[_i];
  12212. var targetProp = getPropertyOfObjectType(target, sourceProp.name);
  12213. if (!targetProp) {
  12214. return 0;
  12215. }
  12216. var related = compareProperties(sourceProp, targetProp, isRelatedTo);
  12217. if (!related) {
  12218. return 0;
  12219. }
  12220. result &= related;
  12221. }
  12222. return result;
  12223. }
  12224. function signaturesRelatedTo(source, target, kind, reportErrors) {
  12225. if (relation === identityRelation) {
  12226. return signaturesIdenticalTo(source, target, kind);
  12227. }
  12228. if (target === anyFunctionType || source === anyFunctionType) {
  12229. return -1;
  12230. }
  12231. var sourceSignatures = getSignaturesOfType(source, kind);
  12232. var targetSignatures = getSignaturesOfType(target, kind);
  12233. var result = -1;
  12234. var saveErrorInfo = errorInfo;
  12235. outer: for (var _i = 0; _i < targetSignatures.length; _i++) {
  12236. var t = targetSignatures[_i];
  12237. if (!t.hasStringLiterals || target.flags & 65536) {
  12238. var localErrors = reportErrors;
  12239. for (var _a = 0; _a < sourceSignatures.length; _a++) {
  12240. var s = sourceSignatures[_a];
  12241. if (!s.hasStringLiterals || source.flags & 65536) {
  12242. var related = signatureRelatedTo(s, t, localErrors);
  12243. if (related) {
  12244. result &= related;
  12245. errorInfo = saveErrorInfo;
  12246. continue outer;
  12247. }
  12248. localErrors = false;
  12249. }
  12250. }
  12251. return 0;
  12252. }
  12253. }
  12254. return result;
  12255. }
  12256. function signatureRelatedTo(source, target, reportErrors) {
  12257. if (source === target) {
  12258. return -1;
  12259. }
  12260. if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) {
  12261. return 0;
  12262. }
  12263. var sourceMax = source.parameters.length;
  12264. var targetMax = target.parameters.length;
  12265. var checkCount;
  12266. if (source.hasRestParameter && target.hasRestParameter) {
  12267. checkCount = sourceMax > targetMax ? sourceMax : targetMax;
  12268. sourceMax--;
  12269. targetMax--;
  12270. }
  12271. else if (source.hasRestParameter) {
  12272. sourceMax--;
  12273. checkCount = targetMax;
  12274. }
  12275. else if (target.hasRestParameter) {
  12276. targetMax--;
  12277. checkCount = sourceMax;
  12278. }
  12279. else {
  12280. checkCount = sourceMax < targetMax ? sourceMax : targetMax;
  12281. }
  12282. source = getErasedSignature(source);
  12283. target = getErasedSignature(target);
  12284. var result = -1;
  12285. for (var i = 0; i < checkCount; i++) {
  12286. var s_1 = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
  12287. var t_1 = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
  12288. var saveErrorInfo = errorInfo;
  12289. var related = isRelatedTo(s_1, t_1, reportErrors);
  12290. if (!related) {
  12291. related = isRelatedTo(t_1, s_1, false);
  12292. if (!related) {
  12293. if (reportErrors) {
  12294. 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);
  12295. }
  12296. return 0;
  12297. }
  12298. errorInfo = saveErrorInfo;
  12299. }
  12300. result &= related;
  12301. }
  12302. var t = getReturnTypeOfSignature(target);
  12303. if (t === voidType)
  12304. return result;
  12305. var s = getReturnTypeOfSignature(source);
  12306. return result & isRelatedTo(s, t, reportErrors);
  12307. }
  12308. function signaturesIdenticalTo(source, target, kind) {
  12309. var sourceSignatures = getSignaturesOfType(source, kind);
  12310. var targetSignatures = getSignaturesOfType(target, kind);
  12311. if (sourceSignatures.length !== targetSignatures.length) {
  12312. return 0;
  12313. }
  12314. var result = -1;
  12315. for (var i = 0, len = sourceSignatures.length; i < len; ++i) {
  12316. var related = compareSignatures(sourceSignatures[i], targetSignatures[i], true, isRelatedTo);
  12317. if (!related) {
  12318. return 0;
  12319. }
  12320. result &= related;
  12321. }
  12322. return result;
  12323. }
  12324. function stringIndexTypesRelatedTo(source, target, reportErrors) {
  12325. if (relation === identityRelation) {
  12326. return indexTypesIdenticalTo(0, source, target);
  12327. }
  12328. var targetType = getIndexTypeOfType(target, 0);
  12329. if (targetType) {
  12330. var sourceType = getIndexTypeOfType(source, 0);
  12331. if (!sourceType) {
  12332. if (reportErrors) {
  12333. reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
  12334. }
  12335. return 0;
  12336. }
  12337. var related = isRelatedTo(sourceType, targetType, reportErrors);
  12338. if (!related) {
  12339. if (reportErrors) {
  12340. reportError(ts.Diagnostics.Index_signatures_are_incompatible);
  12341. }
  12342. return 0;
  12343. }
  12344. return related;
  12345. }
  12346. return -1;
  12347. }
  12348. function numberIndexTypesRelatedTo(source, target, reportErrors) {
  12349. if (relation === identityRelation) {
  12350. return indexTypesIdenticalTo(1, source, target);
  12351. }
  12352. var targetType = getIndexTypeOfType(target, 1);
  12353. if (targetType) {
  12354. var sourceStringType = getIndexTypeOfType(source, 0);
  12355. var sourceNumberType = getIndexTypeOfType(source, 1);
  12356. if (!(sourceStringType || sourceNumberType)) {
  12357. if (reportErrors) {
  12358. reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
  12359. }
  12360. return 0;
  12361. }
  12362. var related;
  12363. if (sourceStringType && sourceNumberType) {
  12364. related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
  12365. }
  12366. else {
  12367. related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
  12368. }
  12369. if (!related) {
  12370. if (reportErrors) {
  12371. reportError(ts.Diagnostics.Index_signatures_are_incompatible);
  12372. }
  12373. return 0;
  12374. }
  12375. return related;
  12376. }
  12377. return -1;
  12378. }
  12379. function indexTypesIdenticalTo(indexKind, source, target) {
  12380. var targetType = getIndexTypeOfType(target, indexKind);
  12381. var sourceType = getIndexTypeOfType(source, indexKind);
  12382. if (!sourceType && !targetType) {
  12383. return -1;
  12384. }
  12385. if (sourceType && targetType) {
  12386. return isRelatedTo(sourceType, targetType);
  12387. }
  12388. return 0;
  12389. }
  12390. }
  12391. function isPropertyIdenticalTo(sourceProp, targetProp) {
  12392. return compareProperties(sourceProp, targetProp, compareTypes) !== 0;
  12393. }
  12394. function compareProperties(sourceProp, targetProp, compareTypes) {
  12395. if (sourceProp === targetProp) {
  12396. return -1;
  12397. }
  12398. var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (32 | 64);
  12399. var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (32 | 64);
  12400. if (sourcePropAccessibility !== targetPropAccessibility) {
  12401. return 0;
  12402. }
  12403. if (sourcePropAccessibility) {
  12404. if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) {
  12405. return 0;
  12406. }
  12407. }
  12408. else {
  12409. if ((sourceProp.flags & 536870912) !== (targetProp.flags & 536870912)) {
  12410. return 0;
  12411. }
  12412. }
  12413. return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
  12414. }
  12415. function compareSignatures(source, target, compareReturnTypes, compareTypes) {
  12416. if (source === target) {
  12417. return -1;
  12418. }
  12419. if (source.parameters.length !== target.parameters.length ||
  12420. source.minArgumentCount !== target.minArgumentCount ||
  12421. source.hasRestParameter !== target.hasRestParameter) {
  12422. return 0;
  12423. }
  12424. var result = -1;
  12425. if (source.typeParameters && target.typeParameters) {
  12426. if (source.typeParameters.length !== target.typeParameters.length) {
  12427. return 0;
  12428. }
  12429. for (var i = 0, len = source.typeParameters.length; i < len; ++i) {
  12430. var related = compareTypes(source.typeParameters[i], target.typeParameters[i]);
  12431. if (!related) {
  12432. return 0;
  12433. }
  12434. result &= related;
  12435. }
  12436. }
  12437. else if (source.typeParameters || target.typeParameters) {
  12438. return 0;
  12439. }
  12440. source = getErasedSignature(source);
  12441. target = getErasedSignature(target);
  12442. for (var i = 0, len = source.parameters.length; i < len; i++) {
  12443. var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
  12444. var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
  12445. var related = compareTypes(s, t);
  12446. if (!related) {
  12447. return 0;
  12448. }
  12449. result &= related;
  12450. }
  12451. if (compareReturnTypes) {
  12452. result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
  12453. }
  12454. return result;
  12455. }
  12456. function isSupertypeOfEach(candidate, types) {
  12457. for (var _i = 0; _i < types.length; _i++) {
  12458. var type = types[_i];
  12459. if (candidate !== type && !isTypeSubtypeOf(type, candidate))
  12460. return false;
  12461. }
  12462. return true;
  12463. }
  12464. function getCommonSupertype(types) {
  12465. return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; });
  12466. }
  12467. function reportNoCommonSupertypeError(types, errorLocation, errorMessageChainHead) {
  12468. var bestSupertype;
  12469. var bestSupertypeDownfallType;
  12470. var bestSupertypeScore = 0;
  12471. for (var i = 0; i < types.length; i++) {
  12472. var score = 0;
  12473. var downfallType = undefined;
  12474. for (var j = 0; j < types.length; j++) {
  12475. if (isTypeSubtypeOf(types[j], types[i])) {
  12476. score++;
  12477. }
  12478. else if (!downfallType) {
  12479. downfallType = types[j];
  12480. }
  12481. }
  12482. ts.Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType");
  12483. if (score > bestSupertypeScore) {
  12484. bestSupertype = types[i];
  12485. bestSupertypeDownfallType = downfallType;
  12486. bestSupertypeScore = score;
  12487. }
  12488. if (bestSupertypeScore === types.length - 1) {
  12489. break;
  12490. }
  12491. }
  12492. 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);
  12493. }
  12494. function isArrayType(type) {
  12495. return type.flags & 4096 && type.target === globalArrayType;
  12496. }
  12497. function isArrayLikeType(type) {
  12498. return !(type.flags & (32 | 64)) && isTypeAssignableTo(type, anyArrayType);
  12499. }
  12500. function isTupleLikeType(type) {
  12501. return !!getPropertyOfType(type, "0");
  12502. }
  12503. function isTupleType(type) {
  12504. return (type.flags & 8192) && !!type.elementTypes;
  12505. }
  12506. function getWidenedTypeOfObjectLiteral(type) {
  12507. var properties = getPropertiesOfObjectType(type);
  12508. var members = {};
  12509. ts.forEach(properties, function (p) {
  12510. var propType = getTypeOfSymbol(p);
  12511. var widenedType = getWidenedType(propType);
  12512. if (propType !== widenedType) {
  12513. var symbol = createSymbol(p.flags | 67108864, p.name);
  12514. symbol.declarations = p.declarations;
  12515. symbol.parent = p.parent;
  12516. symbol.type = widenedType;
  12517. symbol.target = p;
  12518. if (p.valueDeclaration)
  12519. symbol.valueDeclaration = p.valueDeclaration;
  12520. p = symbol;
  12521. }
  12522. members[p.name] = p;
  12523. });
  12524. var stringIndexType = getIndexTypeOfType(type, 0);
  12525. var numberIndexType = getIndexTypeOfType(type, 1);
  12526. if (stringIndexType)
  12527. stringIndexType = getWidenedType(stringIndexType);
  12528. if (numberIndexType)
  12529. numberIndexType = getWidenedType(numberIndexType);
  12530. return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType);
  12531. }
  12532. function getWidenedType(type) {
  12533. if (type.flags & 786432) {
  12534. if (type.flags & (32 | 64)) {
  12535. return anyType;
  12536. }
  12537. if (type.flags & 131072) {
  12538. return getWidenedTypeOfObjectLiteral(type);
  12539. }
  12540. if (type.flags & 16384) {
  12541. return getUnionType(ts.map(type.types, getWidenedType));
  12542. }
  12543. if (isArrayType(type)) {
  12544. return createArrayType(getWidenedType(type.typeArguments[0]));
  12545. }
  12546. }
  12547. return type;
  12548. }
  12549. function reportWideningErrorsInType(type) {
  12550. if (type.flags & 16384) {
  12551. var errorReported = false;
  12552. ts.forEach(type.types, function (t) {
  12553. if (reportWideningErrorsInType(t)) {
  12554. errorReported = true;
  12555. }
  12556. });
  12557. return errorReported;
  12558. }
  12559. if (isArrayType(type)) {
  12560. return reportWideningErrorsInType(type.typeArguments[0]);
  12561. }
  12562. if (type.flags & 131072) {
  12563. var errorReported = false;
  12564. ts.forEach(getPropertiesOfObjectType(type), function (p) {
  12565. var t = getTypeOfSymbol(p);
  12566. if (t.flags & 262144) {
  12567. if (!reportWideningErrorsInType(t)) {
  12568. error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t)));
  12569. }
  12570. errorReported = true;
  12571. }
  12572. });
  12573. return errorReported;
  12574. }
  12575. return false;
  12576. }
  12577. function reportImplicitAnyError(declaration, type) {
  12578. var typeAsString = typeToString(getWidenedType(type));
  12579. var diagnostic;
  12580. switch (declaration.kind) {
  12581. case 133:
  12582. case 132:
  12583. diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type;
  12584. break;
  12585. case 130:
  12586. diagnostic = declaration.dotDotDotToken ?
  12587. ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type :
  12588. ts.Diagnostics.Parameter_0_implicitly_has_an_1_type;
  12589. break;
  12590. case 201:
  12591. case 135:
  12592. case 134:
  12593. case 137:
  12594. case 138:
  12595. case 163:
  12596. case 164:
  12597. if (!declaration.name) {
  12598. error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString);
  12599. return;
  12600. }
  12601. diagnostic = ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
  12602. break;
  12603. default:
  12604. diagnostic = ts.Diagnostics.Variable_0_implicitly_has_an_1_type;
  12605. }
  12606. error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString);
  12607. }
  12608. function reportErrorsFromWidening(declaration, type) {
  12609. if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144) {
  12610. if (!reportWideningErrorsInType(type)) {
  12611. reportImplicitAnyError(declaration, type);
  12612. }
  12613. }
  12614. }
  12615. function forEachMatchingParameterType(source, target, callback) {
  12616. var sourceMax = source.parameters.length;
  12617. var targetMax = target.parameters.length;
  12618. var count;
  12619. if (source.hasRestParameter && target.hasRestParameter) {
  12620. count = sourceMax > targetMax ? sourceMax : targetMax;
  12621. sourceMax--;
  12622. targetMax--;
  12623. }
  12624. else if (source.hasRestParameter) {
  12625. sourceMax--;
  12626. count = targetMax;
  12627. }
  12628. else if (target.hasRestParameter) {
  12629. targetMax--;
  12630. count = sourceMax;
  12631. }
  12632. else {
  12633. count = sourceMax < targetMax ? sourceMax : targetMax;
  12634. }
  12635. for (var i = 0; i < count; i++) {
  12636. var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
  12637. var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
  12638. callback(s, t);
  12639. }
  12640. }
  12641. function createInferenceContext(typeParameters, inferUnionTypes) {
  12642. var inferences = [];
  12643. for (var _i = 0; _i < typeParameters.length; _i++) {
  12644. var unused = typeParameters[_i];
  12645. inferences.push({ primary: undefined, secondary: undefined, isFixed: false });
  12646. }
  12647. return {
  12648. typeParameters: typeParameters,
  12649. inferUnionTypes: inferUnionTypes,
  12650. inferences: inferences,
  12651. inferredTypes: new Array(typeParameters.length)
  12652. };
  12653. }
  12654. function inferTypes(context, source, target) {
  12655. var sourceStack;
  12656. var targetStack;
  12657. var depth = 0;
  12658. var inferiority = 0;
  12659. inferFromTypes(source, target);
  12660. function isInProcess(source, target) {
  12661. for (var i = 0; i < depth; i++) {
  12662. if (source === sourceStack[i] && target === targetStack[i]) {
  12663. return true;
  12664. }
  12665. }
  12666. return false;
  12667. }
  12668. function isWithinDepthLimit(type, stack) {
  12669. if (depth >= 5) {
  12670. var target_2 = type.target;
  12671. var count = 0;
  12672. for (var i = 0; i < depth; i++) {
  12673. var t = stack[i];
  12674. if (t.flags & 4096 && t.target === target_2) {
  12675. count++;
  12676. }
  12677. }
  12678. return count < 5;
  12679. }
  12680. return true;
  12681. }
  12682. function inferFromTypes(source, target) {
  12683. if (source === anyFunctionType) {
  12684. return;
  12685. }
  12686. if (target.flags & 512) {
  12687. var typeParameters = context.typeParameters;
  12688. for (var i = 0; i < typeParameters.length; i++) {
  12689. if (target === typeParameters[i]) {
  12690. var inferences = context.inferences[i];
  12691. if (!inferences.isFixed) {
  12692. var candidates = inferiority ?
  12693. inferences.secondary || (inferences.secondary = []) :
  12694. inferences.primary || (inferences.primary = []);
  12695. if (!ts.contains(candidates, source)) {
  12696. candidates.push(source);
  12697. }
  12698. }
  12699. return;
  12700. }
  12701. }
  12702. }
  12703. else if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) {
  12704. var sourceTypes = source.typeArguments;
  12705. var targetTypes = target.typeArguments;
  12706. for (var i = 0; i < sourceTypes.length; i++) {
  12707. inferFromTypes(sourceTypes[i], targetTypes[i]);
  12708. }
  12709. }
  12710. else if (target.flags & 16384) {
  12711. var targetTypes = target.types;
  12712. var typeParameterCount = 0;
  12713. var typeParameter;
  12714. for (var _i = 0; _i < targetTypes.length; _i++) {
  12715. var t = targetTypes[_i];
  12716. if (t.flags & 512 && ts.contains(context.typeParameters, t)) {
  12717. typeParameter = t;
  12718. typeParameterCount++;
  12719. }
  12720. else {
  12721. inferFromTypes(source, t);
  12722. }
  12723. }
  12724. if (typeParameterCount === 1) {
  12725. inferiority++;
  12726. inferFromTypes(source, typeParameter);
  12727. inferiority--;
  12728. }
  12729. }
  12730. else if (source.flags & 16384) {
  12731. var sourceTypes = source.types;
  12732. for (var _a = 0; _a < sourceTypes.length; _a++) {
  12733. var sourceType = sourceTypes[_a];
  12734. inferFromTypes(sourceType, target);
  12735. }
  12736. }
  12737. else if (source.flags & 48128 && (target.flags & (4096 | 8192) ||
  12738. (target.flags & 32768) && target.symbol && target.symbol.flags & (8192 | 2048))) {
  12739. if (!isInProcess(source, target) && isWithinDepthLimit(source, sourceStack) && isWithinDepthLimit(target, targetStack)) {
  12740. if (depth === 0) {
  12741. sourceStack = [];
  12742. targetStack = [];
  12743. }
  12744. sourceStack[depth] = source;
  12745. targetStack[depth] = target;
  12746. depth++;
  12747. inferFromProperties(source, target);
  12748. inferFromSignatures(source, target, 0);
  12749. inferFromSignatures(source, target, 1);
  12750. inferFromIndexTypes(source, target, 0, 0);
  12751. inferFromIndexTypes(source, target, 1, 1);
  12752. inferFromIndexTypes(source, target, 0, 1);
  12753. depth--;
  12754. }
  12755. }
  12756. }
  12757. function inferFromProperties(source, target) {
  12758. var properties = getPropertiesOfObjectType(target);
  12759. for (var _i = 0; _i < properties.length; _i++) {
  12760. var targetProp = properties[_i];
  12761. var sourceProp = getPropertyOfObjectType(source, targetProp.name);
  12762. if (sourceProp) {
  12763. inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
  12764. }
  12765. }
  12766. }
  12767. function inferFromSignatures(source, target, kind) {
  12768. var sourceSignatures = getSignaturesOfType(source, kind);
  12769. var targetSignatures = getSignaturesOfType(target, kind);
  12770. var sourceLen = sourceSignatures.length;
  12771. var targetLen = targetSignatures.length;
  12772. var len = sourceLen < targetLen ? sourceLen : targetLen;
  12773. for (var i = 0; i < len; i++) {
  12774. inferFromSignature(getErasedSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
  12775. }
  12776. }
  12777. function inferFromSignature(source, target) {
  12778. forEachMatchingParameterType(source, target, inferFromTypes);
  12779. inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
  12780. }
  12781. function inferFromIndexTypes(source, target, sourceKind, targetKind) {
  12782. var targetIndexType = getIndexTypeOfType(target, targetKind);
  12783. if (targetIndexType) {
  12784. var sourceIndexType = getIndexTypeOfType(source, sourceKind);
  12785. if (sourceIndexType) {
  12786. inferFromTypes(sourceIndexType, targetIndexType);
  12787. }
  12788. }
  12789. }
  12790. }
  12791. function getInferenceCandidates(context, index) {
  12792. var inferences = context.inferences[index];
  12793. return inferences.primary || inferences.secondary || emptyArray;
  12794. }
  12795. function getInferredType(context, index) {
  12796. var inferredType = context.inferredTypes[index];
  12797. var inferenceSucceeded;
  12798. if (!inferredType) {
  12799. var inferences = getInferenceCandidates(context, index);
  12800. if (inferences.length) {
  12801. var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences);
  12802. inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType;
  12803. inferenceSucceeded = !!unionOrSuperType;
  12804. }
  12805. else {
  12806. inferredType = emptyObjectType;
  12807. inferenceSucceeded = true;
  12808. }
  12809. if (inferenceSucceeded) {
  12810. var constraint = getConstraintOfTypeParameter(context.typeParameters[index]);
  12811. inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType;
  12812. }
  12813. else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) {
  12814. context.failedTypeParameterIndex = index;
  12815. }
  12816. context.inferredTypes[index] = inferredType;
  12817. }
  12818. return inferredType;
  12819. }
  12820. function getInferredTypes(context) {
  12821. for (var i = 0; i < context.inferredTypes.length; i++) {
  12822. getInferredType(context, i);
  12823. }
  12824. return context.inferredTypes;
  12825. }
  12826. function hasAncestor(node, kind) {
  12827. return ts.getAncestor(node, kind) !== undefined;
  12828. }
  12829. function getResolvedSymbol(node) {
  12830. var links = getNodeLinks(node);
  12831. if (!links.resolvedSymbol) {
  12832. links.resolvedSymbol = (!ts.nodeIsMissing(node) && resolveName(node, node.text, 107455 | 1048576, ts.Diagnostics.Cannot_find_name_0, node)) || unknownSymbol;
  12833. }
  12834. return links.resolvedSymbol;
  12835. }
  12836. function isInTypeQuery(node) {
  12837. while (node) {
  12838. switch (node.kind) {
  12839. case 145:
  12840. return true;
  12841. case 65:
  12842. case 127:
  12843. node = node.parent;
  12844. continue;
  12845. default:
  12846. return false;
  12847. }
  12848. }
  12849. ts.Debug.fail("should not get here");
  12850. }
  12851. function removeTypesFromUnionType(type, typeKind, isOfTypeKind, allowEmptyUnionResult) {
  12852. if (type.flags & 16384) {
  12853. var types = type.types;
  12854. if (ts.forEach(types, function (t) { return !!(t.flags & typeKind) === isOfTypeKind; })) {
  12855. var narrowedType = getUnionType(ts.filter(types, function (t) { return !(t.flags & typeKind) === isOfTypeKind; }));
  12856. if (allowEmptyUnionResult || narrowedType !== emptyObjectType) {
  12857. return narrowedType;
  12858. }
  12859. }
  12860. }
  12861. else if (allowEmptyUnionResult && !!(type.flags & typeKind) === isOfTypeKind) {
  12862. return getUnionType(emptyArray);
  12863. }
  12864. return type;
  12865. }
  12866. function hasInitializer(node) {
  12867. return !!(node.initializer || ts.isBindingPattern(node.parent) && hasInitializer(node.parent.parent));
  12868. }
  12869. function isVariableAssignedWithin(symbol, node) {
  12870. var links = getNodeLinks(node);
  12871. if (links.assignmentChecks) {
  12872. var cachedResult = links.assignmentChecks[symbol.id];
  12873. if (cachedResult !== undefined) {
  12874. return cachedResult;
  12875. }
  12876. }
  12877. else {
  12878. links.assignmentChecks = {};
  12879. }
  12880. return links.assignmentChecks[symbol.id] = isAssignedIn(node);
  12881. function isAssignedInBinaryExpression(node) {
  12882. if (node.operatorToken.kind >= 53 && node.operatorToken.kind <= 64) {
  12883. var n = node.left;
  12884. while (n.kind === 162) {
  12885. n = n.expression;
  12886. }
  12887. if (n.kind === 65 && getResolvedSymbol(n) === symbol) {
  12888. return true;
  12889. }
  12890. }
  12891. return ts.forEachChild(node, isAssignedIn);
  12892. }
  12893. function isAssignedInVariableDeclaration(node) {
  12894. if (!ts.isBindingPattern(node.name) && getSymbolOfNode(node) === symbol && hasInitializer(node)) {
  12895. return true;
  12896. }
  12897. return ts.forEachChild(node, isAssignedIn);
  12898. }
  12899. function isAssignedIn(node) {
  12900. switch (node.kind) {
  12901. case 170:
  12902. return isAssignedInBinaryExpression(node);
  12903. case 199:
  12904. case 153:
  12905. return isAssignedInVariableDeclaration(node);
  12906. case 151:
  12907. case 152:
  12908. case 154:
  12909. case 155:
  12910. case 156:
  12911. case 157:
  12912. case 158:
  12913. case 159:
  12914. case 161:
  12915. case 162:
  12916. case 168:
  12917. case 165:
  12918. case 166:
  12919. case 167:
  12920. case 169:
  12921. case 171:
  12922. case 174:
  12923. case 180:
  12924. case 181:
  12925. case 183:
  12926. case 184:
  12927. case 185:
  12928. case 186:
  12929. case 187:
  12930. case 188:
  12931. case 189:
  12932. case 192:
  12933. case 193:
  12934. case 194:
  12935. case 221:
  12936. case 222:
  12937. case 195:
  12938. case 196:
  12939. case 197:
  12940. case 224:
  12941. return ts.forEachChild(node, isAssignedIn);
  12942. }
  12943. return false;
  12944. }
  12945. }
  12946. function resolveLocation(node) {
  12947. var containerNodes = [];
  12948. for (var parent_3 = node.parent; parent_3; parent_3 = parent_3.parent) {
  12949. if ((ts.isExpression(parent_3) || ts.isObjectLiteralMethod(node)) &&
  12950. isContextSensitive(parent_3)) {
  12951. containerNodes.unshift(parent_3);
  12952. }
  12953. }
  12954. ts.forEach(containerNodes, function (node) { getTypeOfNode(node); });
  12955. }
  12956. function getSymbolAtLocation(node) {
  12957. resolveLocation(node);
  12958. return getSymbolInfo(node);
  12959. }
  12960. function getTypeAtLocation(node) {
  12961. resolveLocation(node);
  12962. return getTypeOfNode(node);
  12963. }
  12964. function getTypeOfSymbolAtLocation(symbol, node) {
  12965. resolveLocation(node);
  12966. return getNarrowedTypeOfSymbol(symbol, node);
  12967. }
  12968. function getNarrowedTypeOfSymbol(symbol, node) {
  12969. var type = getTypeOfSymbol(symbol);
  12970. if (node && symbol.flags & 3 && type.flags & (1 | 48128 | 16384 | 512)) {
  12971. loop: while (node.parent) {
  12972. var child = node;
  12973. node = node.parent;
  12974. var narrowedType = type;
  12975. switch (node.kind) {
  12976. case 184:
  12977. if (child !== node.expression) {
  12978. narrowedType = narrowType(type, node.expression, child === node.thenStatement);
  12979. }
  12980. break;
  12981. case 171:
  12982. if (child !== node.condition) {
  12983. narrowedType = narrowType(type, node.condition, child === node.whenTrue);
  12984. }
  12985. break;
  12986. case 170:
  12987. if (child === node.right) {
  12988. if (node.operatorToken.kind === 48) {
  12989. narrowedType = narrowType(type, node.left, true);
  12990. }
  12991. else if (node.operatorToken.kind === 49) {
  12992. narrowedType = narrowType(type, node.left, false);
  12993. }
  12994. }
  12995. break;
  12996. case 228:
  12997. case 206:
  12998. case 201:
  12999. case 135:
  13000. case 134:
  13001. case 137:
  13002. case 138:
  13003. case 136:
  13004. break loop;
  13005. }
  13006. if (narrowedType !== type) {
  13007. if (isVariableAssignedWithin(symbol, node)) {
  13008. break;
  13009. }
  13010. type = narrowedType;
  13011. }
  13012. }
  13013. }
  13014. return type;
  13015. function narrowTypeByEquality(type, expr, assumeTrue) {
  13016. if (expr.left.kind !== 166 || expr.right.kind !== 8) {
  13017. return type;
  13018. }
  13019. var left = expr.left;
  13020. var right = expr.right;
  13021. if (left.expression.kind !== 65 || getResolvedSymbol(left.expression) !== symbol) {
  13022. return type;
  13023. }
  13024. var typeInfo = primitiveTypeInfo[right.text];
  13025. if (expr.operatorToken.kind === 31) {
  13026. assumeTrue = !assumeTrue;
  13027. }
  13028. if (assumeTrue) {
  13029. if (!typeInfo) {
  13030. return removeTypesFromUnionType(type, 258 | 132 | 8 | 1048576, true, false);
  13031. }
  13032. if (isTypeSubtypeOf(typeInfo.type, type)) {
  13033. return typeInfo.type;
  13034. }
  13035. return removeTypesFromUnionType(type, typeInfo.flags, false, false);
  13036. }
  13037. else {
  13038. if (typeInfo) {
  13039. return removeTypesFromUnionType(type, typeInfo.flags, true, false);
  13040. }
  13041. return type;
  13042. }
  13043. }
  13044. function narrowTypeByAnd(type, expr, assumeTrue) {
  13045. if (assumeTrue) {
  13046. return narrowType(narrowType(type, expr.left, true), expr.right, true);
  13047. }
  13048. else {
  13049. return getUnionType([
  13050. narrowType(type, expr.left, false),
  13051. narrowType(narrowType(type, expr.left, true), expr.right, false)
  13052. ]);
  13053. }
  13054. }
  13055. function narrowTypeByOr(type, expr, assumeTrue) {
  13056. if (assumeTrue) {
  13057. return getUnionType([
  13058. narrowType(type, expr.left, true),
  13059. narrowType(narrowType(type, expr.left, false), expr.right, true)
  13060. ]);
  13061. }
  13062. else {
  13063. return narrowType(narrowType(type, expr.left, false), expr.right, false);
  13064. }
  13065. }
  13066. function narrowTypeByInstanceof(type, expr, assumeTrue) {
  13067. if (type.flags & 1 || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) {
  13068. return type;
  13069. }
  13070. var rightType = checkExpression(expr.right);
  13071. if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
  13072. return type;
  13073. }
  13074. var targetType;
  13075. var prototypeProperty = getPropertyOfType(rightType, "prototype");
  13076. if (prototypeProperty) {
  13077. var prototypePropertyType = getTypeOfSymbol(prototypeProperty);
  13078. if (prototypePropertyType !== anyType) {
  13079. targetType = prototypePropertyType;
  13080. }
  13081. }
  13082. if (!targetType) {
  13083. var constructSignatures;
  13084. if (rightType.flags & 2048) {
  13085. constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
  13086. }
  13087. else if (rightType.flags & 32768) {
  13088. constructSignatures = getSignaturesOfType(rightType, 1);
  13089. }
  13090. if (constructSignatures && constructSignatures.length) {
  13091. targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
  13092. }
  13093. }
  13094. if (targetType) {
  13095. if (isTypeSubtypeOf(targetType, type)) {
  13096. return targetType;
  13097. }
  13098. if (type.flags & 16384) {
  13099. return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
  13100. }
  13101. }
  13102. return type;
  13103. }
  13104. function narrowType(type, expr, assumeTrue) {
  13105. switch (expr.kind) {
  13106. case 162:
  13107. return narrowType(type, expr.expression, assumeTrue);
  13108. case 170:
  13109. var operator = expr.operatorToken.kind;
  13110. if (operator === 30 || operator === 31) {
  13111. return narrowTypeByEquality(type, expr, assumeTrue);
  13112. }
  13113. else if (operator === 48) {
  13114. return narrowTypeByAnd(type, expr, assumeTrue);
  13115. }
  13116. else if (operator === 49) {
  13117. return narrowTypeByOr(type, expr, assumeTrue);
  13118. }
  13119. else if (operator === 87) {
  13120. return narrowTypeByInstanceof(type, expr, assumeTrue);
  13121. }
  13122. break;
  13123. case 168:
  13124. if (expr.operator === 46) {
  13125. return narrowType(type, expr.operand, !assumeTrue);
  13126. }
  13127. break;
  13128. }
  13129. return type;
  13130. }
  13131. }
  13132. function checkIdentifier(node) {
  13133. var symbol = getResolvedSymbol(node);
  13134. if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 164 && languageVersion < 2) {
  13135. error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
  13136. }
  13137. if (symbol.flags & 8388608 && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
  13138. markAliasSymbolAsReferenced(symbol);
  13139. }
  13140. checkCollisionWithCapturedSuperVariable(node, node);
  13141. checkCollisionWithCapturedThisVariable(node, node);
  13142. checkBlockScopedBindingCapturedInLoop(node, symbol);
  13143. return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node);
  13144. }
  13145. function isInsideFunction(node, threshold) {
  13146. var current = node;
  13147. while (current && current !== threshold) {
  13148. if (ts.isFunctionLike(current)) {
  13149. return true;
  13150. }
  13151. current = current.parent;
  13152. }
  13153. return false;
  13154. }
  13155. function checkBlockScopedBindingCapturedInLoop(node, symbol) {
  13156. if (languageVersion >= 2 ||
  13157. (symbol.flags & 2) === 0 ||
  13158. symbol.valueDeclaration.parent.kind === 224) {
  13159. return;
  13160. }
  13161. var container = symbol.valueDeclaration;
  13162. while (container.kind !== 200) {
  13163. container = container.parent;
  13164. }
  13165. container = container.parent;
  13166. if (container.kind === 181) {
  13167. container = container.parent;
  13168. }
  13169. var inFunction = isInsideFunction(node.parent, container);
  13170. var current = container;
  13171. while (current && !ts.nodeStartsNewLexicalEnvironment(current)) {
  13172. if (isIterationStatement(current, false)) {
  13173. if (inFunction) {
  13174. 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));
  13175. }
  13176. getNodeLinks(symbol.valueDeclaration).flags |= 256;
  13177. break;
  13178. }
  13179. current = current.parent;
  13180. }
  13181. }
  13182. function captureLexicalThis(node, container) {
  13183. var classNode = container.parent && container.parent.kind === 202 ? container.parent : undefined;
  13184. getNodeLinks(node).flags |= 2;
  13185. if (container.kind === 133 || container.kind === 136) {
  13186. getNodeLinks(classNode).flags |= 4;
  13187. }
  13188. else {
  13189. getNodeLinks(container).flags |= 4;
  13190. }
  13191. }
  13192. function checkThisExpression(node) {
  13193. var container = ts.getThisContainer(node, true);
  13194. var needToCaptureLexicalThis = false;
  13195. if (container.kind === 164) {
  13196. container = ts.getThisContainer(container, false);
  13197. needToCaptureLexicalThis = (languageVersion < 2);
  13198. }
  13199. switch (container.kind) {
  13200. case 206:
  13201. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body);
  13202. break;
  13203. case 205:
  13204. error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
  13205. break;
  13206. case 136:
  13207. if (isInConstructorArgumentInitializer(node, container)) {
  13208. error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments);
  13209. }
  13210. break;
  13211. case 133:
  13212. case 132:
  13213. if (container.flags & 128) {
  13214. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer);
  13215. }
  13216. break;
  13217. case 128:
  13218. error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name);
  13219. break;
  13220. }
  13221. if (needToCaptureLexicalThis) {
  13222. captureLexicalThis(node, container);
  13223. }
  13224. var classNode = container.parent && container.parent.kind === 202 ? container.parent : undefined;
  13225. if (classNode) {
  13226. var symbol = getSymbolOfNode(classNode);
  13227. return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol);
  13228. }
  13229. return anyType;
  13230. }
  13231. function isInConstructorArgumentInitializer(node, constructorDecl) {
  13232. for (var n = node; n && n !== constructorDecl; n = n.parent) {
  13233. if (n.kind === 130) {
  13234. return true;
  13235. }
  13236. }
  13237. return false;
  13238. }
  13239. function checkSuperExpression(node) {
  13240. var isCallExpression = node.parent.kind === 158 && node.parent.expression === node;
  13241. var enclosingClass = ts.getAncestor(node, 202);
  13242. var baseClass;
  13243. if (enclosingClass && ts.getClassExtendsHeritageClauseElement(enclosingClass)) {
  13244. var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass));
  13245. var baseTypes = getBaseTypes(classType);
  13246. baseClass = baseTypes.length && baseTypes[0];
  13247. }
  13248. if (!baseClass) {
  13249. error(node, ts.Diagnostics.super_can_only_be_referenced_in_a_derived_class);
  13250. return unknownType;
  13251. }
  13252. var container = ts.getSuperContainer(node, true);
  13253. if (container) {
  13254. var canUseSuperExpression = false;
  13255. var needToCaptureLexicalThis;
  13256. if (isCallExpression) {
  13257. canUseSuperExpression = container.kind === 136;
  13258. }
  13259. else {
  13260. needToCaptureLexicalThis = false;
  13261. while (container && container.kind === 164) {
  13262. container = ts.getSuperContainer(container, true);
  13263. needToCaptureLexicalThis = languageVersion < 2;
  13264. }
  13265. if (container && container.parent && container.parent.kind === 202) {
  13266. if (container.flags & 128) {
  13267. canUseSuperExpression =
  13268. container.kind === 135 ||
  13269. container.kind === 134 ||
  13270. container.kind === 137 ||
  13271. container.kind === 138;
  13272. }
  13273. else {
  13274. canUseSuperExpression =
  13275. container.kind === 135 ||
  13276. container.kind === 134 ||
  13277. container.kind === 137 ||
  13278. container.kind === 138 ||
  13279. container.kind === 133 ||
  13280. container.kind === 132 ||
  13281. container.kind === 136;
  13282. }
  13283. }
  13284. }
  13285. if (canUseSuperExpression) {
  13286. var returnType;
  13287. if ((container.flags & 128) || isCallExpression) {
  13288. getNodeLinks(node).flags |= 32;
  13289. returnType = getTypeOfSymbol(baseClass.symbol);
  13290. }
  13291. else {
  13292. getNodeLinks(node).flags |= 16;
  13293. returnType = baseClass;
  13294. }
  13295. if (container.kind === 136 && isInConstructorArgumentInitializer(node, container)) {
  13296. error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments);
  13297. returnType = unknownType;
  13298. }
  13299. if (!isCallExpression && needToCaptureLexicalThis) {
  13300. captureLexicalThis(node.parent, container);
  13301. }
  13302. return returnType;
  13303. }
  13304. }
  13305. if (container && container.kind === 128) {
  13306. error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
  13307. }
  13308. else if (isCallExpression) {
  13309. error(node, ts.Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
  13310. }
  13311. else {
  13312. error(node, ts.Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
  13313. }
  13314. return unknownType;
  13315. }
  13316. function getContextuallyTypedParameterType(parameter) {
  13317. if (isFunctionExpressionOrArrowFunction(parameter.parent)) {
  13318. var func = parameter.parent;
  13319. if (isContextSensitive(func)) {
  13320. var contextualSignature = getContextualSignature(func);
  13321. if (contextualSignature) {
  13322. var funcHasRestParameters = ts.hasRestParameters(func);
  13323. var len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
  13324. var indexOfParameter = ts.indexOf(func.parameters, parameter);
  13325. if (indexOfParameter < len) {
  13326. return getTypeAtPosition(contextualSignature, indexOfParameter);
  13327. }
  13328. if (indexOfParameter === (func.parameters.length - 1) &&
  13329. funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) {
  13330. return getTypeOfSymbol(ts.lastOrUndefined(contextualSignature.parameters));
  13331. }
  13332. }
  13333. }
  13334. }
  13335. return undefined;
  13336. }
  13337. function getContextualTypeForInitializerExpression(node) {
  13338. var declaration = node.parent;
  13339. if (node === declaration.initializer) {
  13340. if (declaration.type) {
  13341. return getTypeFromTypeNode(declaration.type);
  13342. }
  13343. if (declaration.kind === 130) {
  13344. var type = getContextuallyTypedParameterType(declaration);
  13345. if (type) {
  13346. return type;
  13347. }
  13348. }
  13349. if (ts.isBindingPattern(declaration.name)) {
  13350. return getTypeFromBindingPattern(declaration.name);
  13351. }
  13352. }
  13353. return undefined;
  13354. }
  13355. function getContextualTypeForReturnExpression(node) {
  13356. var func = ts.getContainingFunction(node);
  13357. if (func) {
  13358. if (func.type || func.kind === 136 || func.kind === 137 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 138))) {
  13359. return getReturnTypeOfSignature(getSignatureFromDeclaration(func));
  13360. }
  13361. var signature = getContextualSignatureForFunctionLikeDeclaration(func);
  13362. if (signature) {
  13363. return getReturnTypeOfSignature(signature);
  13364. }
  13365. }
  13366. return undefined;
  13367. }
  13368. function getContextualTypeForArgument(callTarget, arg) {
  13369. var args = getEffectiveCallArguments(callTarget);
  13370. var argIndex = ts.indexOf(args, arg);
  13371. if (argIndex >= 0) {
  13372. var signature = getResolvedSignature(callTarget);
  13373. return getTypeAtPosition(signature, argIndex);
  13374. }
  13375. return undefined;
  13376. }
  13377. function getContextualTypeForSubstitutionExpression(template, substitutionExpression) {
  13378. if (template.parent.kind === 160) {
  13379. return getContextualTypeForArgument(template.parent, substitutionExpression);
  13380. }
  13381. return undefined;
  13382. }
  13383. function getContextualTypeForBinaryOperand(node) {
  13384. var binaryExpression = node.parent;
  13385. var operator = binaryExpression.operatorToken.kind;
  13386. if (operator >= 53 && operator <= 64) {
  13387. if (node === binaryExpression.right) {
  13388. return checkExpression(binaryExpression.left);
  13389. }
  13390. }
  13391. else if (operator === 49) {
  13392. var type = getContextualType(binaryExpression);
  13393. if (!type && node === binaryExpression.right) {
  13394. type = checkExpression(binaryExpression.left);
  13395. }
  13396. return type;
  13397. }
  13398. return undefined;
  13399. }
  13400. function applyToContextualType(type, mapper) {
  13401. if (!(type.flags & 16384)) {
  13402. return mapper(type);
  13403. }
  13404. var types = type.types;
  13405. var mappedType;
  13406. var mappedTypes;
  13407. for (var _i = 0; _i < types.length; _i++) {
  13408. var current = types[_i];
  13409. var t = mapper(current);
  13410. if (t) {
  13411. if (!mappedType) {
  13412. mappedType = t;
  13413. }
  13414. else if (!mappedTypes) {
  13415. mappedTypes = [mappedType, t];
  13416. }
  13417. else {
  13418. mappedTypes.push(t);
  13419. }
  13420. }
  13421. }
  13422. return mappedTypes ? getUnionType(mappedTypes) : mappedType;
  13423. }
  13424. function getTypeOfPropertyOfContextualType(type, name) {
  13425. return applyToContextualType(type, function (t) {
  13426. var prop = getPropertyOfObjectType(t, name);
  13427. return prop ? getTypeOfSymbol(prop) : undefined;
  13428. });
  13429. }
  13430. function getIndexTypeOfContextualType(type, kind) {
  13431. return applyToContextualType(type, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); });
  13432. }
  13433. function contextualTypeIsTupleLikeType(type) {
  13434. return !!(type.flags & 16384 ? ts.forEach(type.types, isTupleLikeType) : isTupleLikeType(type));
  13435. }
  13436. function contextualTypeHasIndexSignature(type, kind) {
  13437. return !!(type.flags & 16384 ? ts.forEach(type.types, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }) : getIndexTypeOfObjectOrUnionType(type, kind));
  13438. }
  13439. function getContextualTypeForObjectLiteralMethod(node) {
  13440. ts.Debug.assert(ts.isObjectLiteralMethod(node));
  13441. if (isInsideWithStatementBody(node)) {
  13442. return undefined;
  13443. }
  13444. return getContextualTypeForObjectLiteralElement(node);
  13445. }
  13446. function getContextualTypeForObjectLiteralElement(element) {
  13447. var objectLiteral = element.parent;
  13448. var type = getContextualType(objectLiteral);
  13449. if (type) {
  13450. if (!ts.hasDynamicName(element)) {
  13451. var symbolName = getSymbolOfNode(element).name;
  13452. var propertyType = getTypeOfPropertyOfContextualType(type, symbolName);
  13453. if (propertyType) {
  13454. return propertyType;
  13455. }
  13456. }
  13457. return isNumericName(element.name) && getIndexTypeOfContextualType(type, 1) ||
  13458. getIndexTypeOfContextualType(type, 0);
  13459. }
  13460. return undefined;
  13461. }
  13462. function getContextualTypeForElementExpression(node) {
  13463. var arrayLiteral = node.parent;
  13464. var type = getContextualType(arrayLiteral);
  13465. if (type) {
  13466. var index = ts.indexOf(arrayLiteral.elements, node);
  13467. return getTypeOfPropertyOfContextualType(type, "" + index)
  13468. || getIndexTypeOfContextualType(type, 1)
  13469. || (languageVersion >= 2 ? checkIteratedType(type, undefined) : undefined);
  13470. }
  13471. return undefined;
  13472. }
  13473. function getContextualTypeForConditionalOperand(node) {
  13474. var conditional = node.parent;
  13475. return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined;
  13476. }
  13477. function getContextualType(node) {
  13478. if (isInsideWithStatementBody(node)) {
  13479. return undefined;
  13480. }
  13481. if (node.contextualType) {
  13482. return node.contextualType;
  13483. }
  13484. var parent = node.parent;
  13485. switch (parent.kind) {
  13486. case 199:
  13487. case 130:
  13488. case 133:
  13489. case 132:
  13490. case 153:
  13491. return getContextualTypeForInitializerExpression(node);
  13492. case 164:
  13493. case 192:
  13494. return getContextualTypeForReturnExpression(node);
  13495. case 158:
  13496. case 159:
  13497. return getContextualTypeForArgument(parent, node);
  13498. case 161:
  13499. return getTypeFromTypeNode(parent.type);
  13500. case 170:
  13501. return getContextualTypeForBinaryOperand(node);
  13502. case 225:
  13503. return getContextualTypeForObjectLiteralElement(parent);
  13504. case 154:
  13505. return getContextualTypeForElementExpression(node);
  13506. case 171:
  13507. return getContextualTypeForConditionalOperand(node);
  13508. case 178:
  13509. ts.Debug.assert(parent.parent.kind === 172);
  13510. return getContextualTypeForSubstitutionExpression(parent.parent, node);
  13511. case 162:
  13512. return getContextualType(parent);
  13513. }
  13514. return undefined;
  13515. }
  13516. function getNonGenericSignature(type) {
  13517. var signatures = getSignaturesOfObjectOrUnionType(type, 0);
  13518. if (signatures.length === 1) {
  13519. var signature = signatures[0];
  13520. if (!signature.typeParameters) {
  13521. return signature;
  13522. }
  13523. }
  13524. }
  13525. function isFunctionExpressionOrArrowFunction(node) {
  13526. return node.kind === 163 || node.kind === 164;
  13527. }
  13528. function getContextualSignatureForFunctionLikeDeclaration(node) {
  13529. return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined;
  13530. }
  13531. function getContextualSignature(node) {
  13532. ts.Debug.assert(node.kind !== 135 || ts.isObjectLiteralMethod(node));
  13533. var type = ts.isObjectLiteralMethod(node)
  13534. ? getContextualTypeForObjectLiteralMethod(node)
  13535. : getContextualType(node);
  13536. if (!type) {
  13537. return undefined;
  13538. }
  13539. if (!(type.flags & 16384)) {
  13540. return getNonGenericSignature(type);
  13541. }
  13542. var signatureList;
  13543. var types = type.types;
  13544. for (var _i = 0; _i < types.length; _i++) {
  13545. var current = types[_i];
  13546. if (signatureList &&
  13547. getSignaturesOfObjectOrUnionType(current, 0).length > 1) {
  13548. return undefined;
  13549. }
  13550. var signature = getNonGenericSignature(current);
  13551. if (signature) {
  13552. if (!signatureList) {
  13553. signatureList = [signature];
  13554. }
  13555. else if (!compareSignatures(signatureList[0], signature, false, compareTypes)) {
  13556. return undefined;
  13557. }
  13558. else {
  13559. signatureList.push(signature);
  13560. }
  13561. }
  13562. }
  13563. var result;
  13564. if (signatureList) {
  13565. result = cloneSignature(signatureList[0]);
  13566. result.resolvedReturnType = undefined;
  13567. result.unionSignatures = signatureList;
  13568. }
  13569. return result;
  13570. }
  13571. function isInferentialContext(mapper) {
  13572. return mapper && mapper !== identityMapper;
  13573. }
  13574. function isAssignmentTarget(node) {
  13575. var parent = node.parent;
  13576. if (parent.kind === 170 && parent.operatorToken.kind === 53 && parent.left === node) {
  13577. return true;
  13578. }
  13579. if (parent.kind === 225) {
  13580. return isAssignmentTarget(parent.parent);
  13581. }
  13582. if (parent.kind === 154) {
  13583. return isAssignmentTarget(parent);
  13584. }
  13585. return false;
  13586. }
  13587. function checkSpreadElementExpression(node, contextualMapper) {
  13588. var arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper);
  13589. return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, false);
  13590. }
  13591. function checkArrayLiteral(node, contextualMapper) {
  13592. var elements = node.elements;
  13593. if (!elements.length) {
  13594. return createArrayType(undefinedType);
  13595. }
  13596. var hasSpreadElement = false;
  13597. var elementTypes = [];
  13598. var inDestructuringPattern = isAssignmentTarget(node);
  13599. for (var _i = 0; _i < elements.length; _i++) {
  13600. var e = elements[_i];
  13601. if (inDestructuringPattern && e.kind === 174) {
  13602. var restArrayType = checkExpression(e.expression, contextualMapper);
  13603. var restElementType = getIndexTypeOfType(restArrayType, 1) ||
  13604. (languageVersion >= 2 ? checkIteratedType(restArrayType, undefined) : undefined);
  13605. if (restElementType) {
  13606. elementTypes.push(restElementType);
  13607. }
  13608. }
  13609. else {
  13610. var type = checkExpression(e, contextualMapper);
  13611. elementTypes.push(type);
  13612. }
  13613. hasSpreadElement = hasSpreadElement || e.kind === 174;
  13614. }
  13615. if (!hasSpreadElement) {
  13616. var contextualType = getContextualType(node);
  13617. if (contextualType && contextualTypeIsTupleLikeType(contextualType) || inDestructuringPattern) {
  13618. return createTupleType(elementTypes);
  13619. }
  13620. }
  13621. return createArrayType(getUnionType(elementTypes));
  13622. }
  13623. function isNumericName(name) {
  13624. return name.kind === 128 ? isNumericComputedName(name) : isNumericLiteralName(name.text);
  13625. }
  13626. function isNumericComputedName(name) {
  13627. return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 | 132);
  13628. }
  13629. function isNumericLiteralName(name) {
  13630. return (+name).toString() === name;
  13631. }
  13632. function checkComputedPropertyName(node) {
  13633. var links = getNodeLinks(node.expression);
  13634. if (!links.resolvedType) {
  13635. links.resolvedType = checkExpression(node.expression);
  13636. if (!allConstituentTypesHaveKind(links.resolvedType, 1 | 132 | 258 | 1048576)) {
  13637. error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any);
  13638. }
  13639. else {
  13640. checkThatExpressionIsProperSymbolReference(node.expression, links.resolvedType, true);
  13641. }
  13642. }
  13643. return links.resolvedType;
  13644. }
  13645. function checkObjectLiteral(node, contextualMapper) {
  13646. checkGrammarObjectLiteralExpression(node);
  13647. var propertiesTable = {};
  13648. var propertiesArray = [];
  13649. var contextualType = getContextualType(node);
  13650. var typeFlags;
  13651. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  13652. var memberDecl = _a[_i];
  13653. var member = memberDecl.symbol;
  13654. if (memberDecl.kind === 225 ||
  13655. memberDecl.kind === 226 ||
  13656. ts.isObjectLiteralMethod(memberDecl)) {
  13657. var type = void 0;
  13658. if (memberDecl.kind === 225) {
  13659. type = checkPropertyAssignment(memberDecl, contextualMapper);
  13660. }
  13661. else if (memberDecl.kind === 135) {
  13662. type = checkObjectLiteralMethod(memberDecl, contextualMapper);
  13663. }
  13664. else {
  13665. ts.Debug.assert(memberDecl.kind === 226);
  13666. type = checkExpression(memberDecl.name, contextualMapper);
  13667. }
  13668. typeFlags |= type.flags;
  13669. var prop = createSymbol(4 | 67108864 | member.flags, member.name);
  13670. prop.declarations = member.declarations;
  13671. prop.parent = member.parent;
  13672. if (member.valueDeclaration) {
  13673. prop.valueDeclaration = member.valueDeclaration;
  13674. }
  13675. prop.type = type;
  13676. prop.target = member;
  13677. member = prop;
  13678. }
  13679. else {
  13680. ts.Debug.assert(memberDecl.kind === 137 || memberDecl.kind === 138);
  13681. checkAccessorDeclaration(memberDecl);
  13682. }
  13683. if (!ts.hasDynamicName(memberDecl)) {
  13684. propertiesTable[member.name] = member;
  13685. }
  13686. propertiesArray.push(member);
  13687. }
  13688. var stringIndexType = getIndexType(0);
  13689. var numberIndexType = getIndexType(1);
  13690. var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
  13691. result.flags |= 131072 | 524288 | (typeFlags & 262144);
  13692. return result;
  13693. function getIndexType(kind) {
  13694. if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) {
  13695. var propTypes = [];
  13696. for (var i = 0; i < propertiesArray.length; i++) {
  13697. var propertyDecl = node.properties[i];
  13698. if (kind === 0 || isNumericName(propertyDecl.name)) {
  13699. var type = getTypeOfSymbol(propertiesArray[i]);
  13700. if (!ts.contains(propTypes, type)) {
  13701. propTypes.push(type);
  13702. }
  13703. }
  13704. }
  13705. var result_1 = propTypes.length ? getUnionType(propTypes) : undefinedType;
  13706. typeFlags |= result_1.flags;
  13707. return result_1;
  13708. }
  13709. return undefined;
  13710. }
  13711. }
  13712. function getDeclarationKindFromSymbol(s) {
  13713. return s.valueDeclaration ? s.valueDeclaration.kind : 133;
  13714. }
  13715. function getDeclarationFlagsFromSymbol(s) {
  13716. return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 ? 16 | 128 : 0;
  13717. }
  13718. function checkClassPropertyAccess(node, left, type, prop) {
  13719. var flags = getDeclarationFlagsFromSymbol(prop);
  13720. if (!(flags & (32 | 64))) {
  13721. return;
  13722. }
  13723. var enclosingClassDeclaration = ts.getAncestor(node, 202);
  13724. var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;
  13725. var declaringClass = getDeclaredTypeOfSymbol(prop.parent);
  13726. if (flags & 32) {
  13727. if (declaringClass !== enclosingClass) {
  13728. error(node, ts.Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(declaringClass));
  13729. }
  13730. return;
  13731. }
  13732. if (left.kind === 91) {
  13733. return;
  13734. }
  13735. if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) {
  13736. error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(declaringClass));
  13737. return;
  13738. }
  13739. if (flags & 128) {
  13740. return;
  13741. }
  13742. if (!(getTargetType(type).flags & (1024 | 2048) && hasBaseType(type, enclosingClass))) {
  13743. error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass));
  13744. }
  13745. }
  13746. function checkPropertyAccessExpression(node) {
  13747. return checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name);
  13748. }
  13749. function checkQualifiedName(node) {
  13750. return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right);
  13751. }
  13752. function checkPropertyAccessExpressionOrQualifiedName(node, left, right) {
  13753. var type = checkExpressionOrQualifiedName(left);
  13754. if (type === unknownType)
  13755. return type;
  13756. if (type !== anyType) {
  13757. var apparentType = getApparentType(getWidenedType(type));
  13758. if (apparentType === unknownType) {
  13759. return unknownType;
  13760. }
  13761. var prop = getPropertyOfType(apparentType, right.text);
  13762. if (!prop) {
  13763. if (right.text) {
  13764. error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type));
  13765. }
  13766. return unknownType;
  13767. }
  13768. getNodeLinks(node).resolvedSymbol = prop;
  13769. if (prop.parent && prop.parent.flags & 32) {
  13770. if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) {
  13771. error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
  13772. }
  13773. else {
  13774. checkClassPropertyAccess(node, left, type, prop);
  13775. }
  13776. }
  13777. return getTypeOfSymbol(prop);
  13778. }
  13779. return anyType;
  13780. }
  13781. function isValidPropertyAccess(node, propertyName) {
  13782. var left = node.kind === 156
  13783. ? node.expression
  13784. : node.left;
  13785. var type = checkExpressionOrQualifiedName(left);
  13786. if (type !== unknownType && type !== anyType) {
  13787. var prop = getPropertyOfType(getWidenedType(type), propertyName);
  13788. if (prop && prop.parent && prop.parent.flags & 32) {
  13789. if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) {
  13790. return false;
  13791. }
  13792. else {
  13793. var modificationCount = diagnostics.getModificationCount();
  13794. checkClassPropertyAccess(node, left, type, prop);
  13795. return diagnostics.getModificationCount() === modificationCount;
  13796. }
  13797. }
  13798. }
  13799. return true;
  13800. }
  13801. function checkIndexedAccess(node) {
  13802. if (!node.argumentExpression) {
  13803. var sourceFile = getSourceFile(node);
  13804. if (node.parent.kind === 159 && node.parent.expression === node) {
  13805. var start = ts.skipTrivia(sourceFile.text, node.expression.end);
  13806. var end = node.end;
  13807. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
  13808. }
  13809. else {
  13810. var start = node.end - "]".length;
  13811. var end = node.end;
  13812. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Expression_expected);
  13813. }
  13814. }
  13815. var objectType = getApparentType(checkExpression(node.expression));
  13816. var indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType;
  13817. if (objectType === unknownType) {
  13818. return unknownType;
  13819. }
  13820. var isConstEnum = isConstEnumObjectType(objectType);
  13821. if (isConstEnum &&
  13822. (!node.argumentExpression || node.argumentExpression.kind !== 8)) {
  13823. error(node.argumentExpression, ts.Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
  13824. return unknownType;
  13825. }
  13826. if (node.argumentExpression) {
  13827. var name_6 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType);
  13828. if (name_6 !== undefined) {
  13829. var prop = getPropertyOfType(objectType, name_6);
  13830. if (prop) {
  13831. getNodeLinks(node).resolvedSymbol = prop;
  13832. return getTypeOfSymbol(prop);
  13833. }
  13834. else if (isConstEnum) {
  13835. error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_6, symbolToString(objectType.symbol));
  13836. return unknownType;
  13837. }
  13838. }
  13839. }
  13840. if (allConstituentTypesHaveKind(indexType, 1 | 258 | 132 | 1048576)) {
  13841. if (allConstituentTypesHaveKind(indexType, 1 | 132)) {
  13842. var numberIndexType = getIndexTypeOfType(objectType, 1);
  13843. if (numberIndexType) {
  13844. return numberIndexType;
  13845. }
  13846. }
  13847. var stringIndexType = getIndexTypeOfType(objectType, 0);
  13848. if (stringIndexType) {
  13849. return stringIndexType;
  13850. }
  13851. if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) {
  13852. error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type);
  13853. }
  13854. return anyType;
  13855. }
  13856. error(node, ts.Diagnostics.An_index_expression_argument_must_be_of_type_string_number_symbol_or_any);
  13857. return unknownType;
  13858. }
  13859. function getPropertyNameForIndexedAccess(indexArgumentExpression, indexArgumentType) {
  13860. if (indexArgumentExpression.kind === 8 || indexArgumentExpression.kind === 7) {
  13861. return indexArgumentExpression.text;
  13862. }
  13863. if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, false)) {
  13864. var rightHandSideName = indexArgumentExpression.name.text;
  13865. return ts.getPropertyNameForKnownSymbolName(rightHandSideName);
  13866. }
  13867. return undefined;
  13868. }
  13869. function checkThatExpressionIsProperSymbolReference(expression, expressionType, reportError) {
  13870. if (expressionType === unknownType) {
  13871. return false;
  13872. }
  13873. if (!ts.isWellKnownSymbolSyntactically(expression)) {
  13874. return false;
  13875. }
  13876. if ((expressionType.flags & 1048576) === 0) {
  13877. if (reportError) {
  13878. error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression));
  13879. }
  13880. return false;
  13881. }
  13882. var leftHandSide = expression.expression;
  13883. var leftHandSideSymbol = getResolvedSymbol(leftHandSide);
  13884. if (!leftHandSideSymbol) {
  13885. return false;
  13886. }
  13887. var globalESSymbol = getGlobalESSymbolConstructorSymbol();
  13888. if (!globalESSymbol) {
  13889. return false;
  13890. }
  13891. if (leftHandSideSymbol !== globalESSymbol) {
  13892. if (reportError) {
  13893. error(leftHandSide, ts.Diagnostics.Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object);
  13894. }
  13895. return false;
  13896. }
  13897. return true;
  13898. }
  13899. function resolveUntypedCall(node) {
  13900. if (node.kind === 160) {
  13901. checkExpression(node.template);
  13902. }
  13903. else {
  13904. ts.forEach(node.arguments, function (argument) {
  13905. checkExpression(argument);
  13906. });
  13907. }
  13908. return anySignature;
  13909. }
  13910. function resolveErrorCall(node) {
  13911. resolveUntypedCall(node);
  13912. return unknownSignature;
  13913. }
  13914. function reorderCandidates(signatures, result) {
  13915. var lastParent;
  13916. var lastSymbol;
  13917. var cutoffIndex = 0;
  13918. var index;
  13919. var specializedIndex = -1;
  13920. var spliceIndex;
  13921. ts.Debug.assert(!result.length);
  13922. for (var _i = 0; _i < signatures.length; _i++) {
  13923. var signature = signatures[_i];
  13924. var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
  13925. var parent_4 = signature.declaration && signature.declaration.parent;
  13926. if (!lastSymbol || symbol === lastSymbol) {
  13927. if (lastParent && parent_4 === lastParent) {
  13928. index++;
  13929. }
  13930. else {
  13931. lastParent = parent_4;
  13932. index = cutoffIndex;
  13933. }
  13934. }
  13935. else {
  13936. index = cutoffIndex = result.length;
  13937. lastParent = parent_4;
  13938. }
  13939. lastSymbol = symbol;
  13940. if (signature.hasStringLiterals) {
  13941. specializedIndex++;
  13942. spliceIndex = specializedIndex;
  13943. cutoffIndex++;
  13944. }
  13945. else {
  13946. spliceIndex = index;
  13947. }
  13948. result.splice(spliceIndex, 0, signature);
  13949. }
  13950. }
  13951. function getSpreadArgumentIndex(args) {
  13952. for (var i = 0; i < args.length; i++) {
  13953. if (args[i].kind === 174) {
  13954. return i;
  13955. }
  13956. }
  13957. return -1;
  13958. }
  13959. function hasCorrectArity(node, args, signature) {
  13960. var adjustedArgCount;
  13961. var typeArguments;
  13962. var callIsIncomplete;
  13963. if (node.kind === 160) {
  13964. var tagExpression = node;
  13965. adjustedArgCount = args.length;
  13966. typeArguments = undefined;
  13967. if (tagExpression.template.kind === 172) {
  13968. var templateExpression = tagExpression.template;
  13969. var lastSpan = ts.lastOrUndefined(templateExpression.templateSpans);
  13970. ts.Debug.assert(lastSpan !== undefined);
  13971. callIsIncomplete = ts.nodeIsMissing(lastSpan.literal) || !!lastSpan.literal.isUnterminated;
  13972. }
  13973. else {
  13974. var templateLiteral = tagExpression.template;
  13975. ts.Debug.assert(templateLiteral.kind === 10);
  13976. callIsIncomplete = !!templateLiteral.isUnterminated;
  13977. }
  13978. }
  13979. else {
  13980. var callExpression = node;
  13981. if (!callExpression.arguments) {
  13982. ts.Debug.assert(callExpression.kind === 159);
  13983. return signature.minArgumentCount === 0;
  13984. }
  13985. adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length;
  13986. callIsIncomplete = callExpression.arguments.end === callExpression.end;
  13987. typeArguments = callExpression.typeArguments;
  13988. }
  13989. var hasRightNumberOfTypeArgs = !typeArguments ||
  13990. (signature.typeParameters && typeArguments.length === signature.typeParameters.length);
  13991. if (!hasRightNumberOfTypeArgs) {
  13992. return false;
  13993. }
  13994. var spreadArgIndex = getSpreadArgumentIndex(args);
  13995. if (spreadArgIndex >= 0) {
  13996. return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1;
  13997. }
  13998. if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) {
  13999. return false;
  14000. }
  14001. var hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount;
  14002. return callIsIncomplete || hasEnoughArguments;
  14003. }
  14004. function getSingleCallSignature(type) {
  14005. if (type.flags & 48128) {
  14006. var resolved = resolveObjectOrUnionTypeMembers(type);
  14007. if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 &&
  14008. resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) {
  14009. return resolved.callSignatures[0];
  14010. }
  14011. }
  14012. return undefined;
  14013. }
  14014. function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper) {
  14015. var context = createInferenceContext(signature.typeParameters, true);
  14016. forEachMatchingParameterType(contextualSignature, signature, function (source, target) {
  14017. inferTypes(context, instantiateType(source, contextualMapper), target);
  14018. });
  14019. return getSignatureInstantiation(signature, getInferredTypes(context));
  14020. }
  14021. function inferTypeArguments(signature, args, excludeArgument, context) {
  14022. var typeParameters = signature.typeParameters;
  14023. var inferenceMapper = createInferenceMapper(context);
  14024. for (var i = 0; i < typeParameters.length; i++) {
  14025. if (!context.inferences[i].isFixed) {
  14026. context.inferredTypes[i] = undefined;
  14027. }
  14028. }
  14029. if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) {
  14030. context.failedTypeParameterIndex = undefined;
  14031. }
  14032. for (var i = 0; i < args.length; i++) {
  14033. var arg = args[i];
  14034. if (arg.kind !== 176) {
  14035. var paramType = getTypeAtPosition(signature, i);
  14036. var argType = void 0;
  14037. if (i === 0 && args[i].parent.kind === 160) {
  14038. argType = globalTemplateStringsArrayType;
  14039. }
  14040. else {
  14041. var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
  14042. argType = checkExpressionWithContextualType(arg, paramType, mapper);
  14043. }
  14044. inferTypes(context, argType, paramType);
  14045. }
  14046. }
  14047. if (excludeArgument) {
  14048. for (var i = 0; i < args.length; i++) {
  14049. if (excludeArgument[i] === false) {
  14050. var arg = args[i];
  14051. var paramType = getTypeAtPosition(signature, i);
  14052. inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType);
  14053. }
  14054. }
  14055. }
  14056. getInferredTypes(context);
  14057. }
  14058. function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors) {
  14059. var typeParameters = signature.typeParameters;
  14060. var typeArgumentsAreAssignable = true;
  14061. for (var i = 0; i < typeParameters.length; i++) {
  14062. var typeArgNode = typeArguments[i];
  14063. var typeArgument = getTypeFromTypeNode(typeArgNode);
  14064. typeArgumentResultTypes[i] = typeArgument;
  14065. if (typeArgumentsAreAssignable) {
  14066. var constraint = getConstraintOfTypeParameter(typeParameters[i]);
  14067. if (constraint) {
  14068. typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
  14069. }
  14070. }
  14071. }
  14072. return typeArgumentsAreAssignable;
  14073. }
  14074. function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) {
  14075. for (var i = 0; i < args.length; i++) {
  14076. var arg = args[i];
  14077. if (arg.kind !== 176) {
  14078. var paramType = getTypeAtPosition(signature, i);
  14079. var argType = i === 0 && node.kind === 160
  14080. ? globalTemplateStringsArrayType
  14081. : arg.kind === 8 && !reportErrors
  14082. ? getStringLiteralType(arg)
  14083. : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
  14084. if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) {
  14085. return false;
  14086. }
  14087. }
  14088. }
  14089. return true;
  14090. }
  14091. function getEffectiveCallArguments(node) {
  14092. var args;
  14093. if (node.kind === 160) {
  14094. var template = node.template;
  14095. args = [template];
  14096. if (template.kind === 172) {
  14097. ts.forEach(template.templateSpans, function (span) {
  14098. args.push(span.expression);
  14099. });
  14100. }
  14101. }
  14102. else {
  14103. args = node.arguments || emptyArray;
  14104. }
  14105. return args;
  14106. }
  14107. function getEffectiveTypeArguments(callExpression) {
  14108. if (callExpression.expression.kind === 91) {
  14109. var containingClass = ts.getAncestor(callExpression, 202);
  14110. var baseClassTypeNode = containingClass && ts.getClassExtendsHeritageClauseElement(containingClass);
  14111. return baseClassTypeNode && baseClassTypeNode.typeArguments;
  14112. }
  14113. else {
  14114. return callExpression.typeArguments;
  14115. }
  14116. }
  14117. function resolveCall(node, signatures, candidatesOutArray) {
  14118. var isTaggedTemplate = node.kind === 160;
  14119. var typeArguments;
  14120. if (!isTaggedTemplate) {
  14121. typeArguments = getEffectiveTypeArguments(node);
  14122. if (node.expression.kind !== 91) {
  14123. ts.forEach(typeArguments, checkSourceElement);
  14124. }
  14125. }
  14126. var candidates = candidatesOutArray || [];
  14127. reorderCandidates(signatures, candidates);
  14128. if (!candidates.length) {
  14129. error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
  14130. return resolveErrorCall(node);
  14131. }
  14132. var args = getEffectiveCallArguments(node);
  14133. var excludeArgument;
  14134. for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) {
  14135. if (isContextSensitive(args[i])) {
  14136. if (!excludeArgument) {
  14137. excludeArgument = new Array(args.length);
  14138. }
  14139. excludeArgument[i] = true;
  14140. }
  14141. }
  14142. var candidateForArgumentError;
  14143. var candidateForTypeArgumentError;
  14144. var resultOfFailedInference;
  14145. var result;
  14146. if (candidates.length > 1) {
  14147. result = chooseOverload(candidates, subtypeRelation);
  14148. }
  14149. if (!result) {
  14150. candidateForArgumentError = undefined;
  14151. candidateForTypeArgumentError = undefined;
  14152. resultOfFailedInference = undefined;
  14153. result = chooseOverload(candidates, assignableRelation);
  14154. }
  14155. if (result) {
  14156. return result;
  14157. }
  14158. if (candidateForArgumentError) {
  14159. checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, undefined, true);
  14160. }
  14161. else if (candidateForTypeArgumentError) {
  14162. if (!isTaggedTemplate && node.typeArguments) {
  14163. checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], true);
  14164. }
  14165. else {
  14166. ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);
  14167. var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex];
  14168. var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex);
  14169. 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));
  14170. reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead);
  14171. }
  14172. }
  14173. else {
  14174. error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
  14175. }
  14176. if (!produceDiagnostics) {
  14177. for (var _i = 0; _i < candidates.length; _i++) {
  14178. var candidate = candidates[_i];
  14179. if (hasCorrectArity(node, args, candidate)) {
  14180. return candidate;
  14181. }
  14182. }
  14183. }
  14184. return resolveErrorCall(node);
  14185. function chooseOverload(candidates, relation) {
  14186. for (var _i = 0; _i < candidates.length; _i++) {
  14187. var originalCandidate = candidates[_i];
  14188. if (!hasCorrectArity(node, args, originalCandidate)) {
  14189. continue;
  14190. }
  14191. var candidate = void 0;
  14192. var typeArgumentsAreValid = void 0;
  14193. var inferenceContext = originalCandidate.typeParameters
  14194. ? createInferenceContext(originalCandidate.typeParameters, false)
  14195. : undefined;
  14196. while (true) {
  14197. candidate = originalCandidate;
  14198. if (candidate.typeParameters) {
  14199. var typeArgumentTypes = void 0;
  14200. if (typeArguments) {
  14201. typeArgumentTypes = new Array(candidate.typeParameters.length);
  14202. typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, false);
  14203. }
  14204. else {
  14205. inferTypeArguments(candidate, args, excludeArgument, inferenceContext);
  14206. typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined;
  14207. typeArgumentTypes = inferenceContext.inferredTypes;
  14208. }
  14209. if (!typeArgumentsAreValid) {
  14210. break;
  14211. }
  14212. candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
  14213. }
  14214. if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, false)) {
  14215. break;
  14216. }
  14217. var index = excludeArgument ? ts.indexOf(excludeArgument, true) : -1;
  14218. if (index < 0) {
  14219. return candidate;
  14220. }
  14221. excludeArgument[index] = false;
  14222. }
  14223. if (originalCandidate.typeParameters) {
  14224. var instantiatedCandidate = candidate;
  14225. if (typeArgumentsAreValid) {
  14226. candidateForArgumentError = instantiatedCandidate;
  14227. }
  14228. else {
  14229. candidateForTypeArgumentError = originalCandidate;
  14230. if (!typeArguments) {
  14231. resultOfFailedInference = inferenceContext;
  14232. }
  14233. }
  14234. }
  14235. else {
  14236. ts.Debug.assert(originalCandidate === candidate);
  14237. candidateForArgumentError = originalCandidate;
  14238. }
  14239. }
  14240. return undefined;
  14241. }
  14242. }
  14243. function resolveCallExpression(node, candidatesOutArray) {
  14244. if (node.expression.kind === 91) {
  14245. var superType = checkSuperExpression(node.expression);
  14246. if (superType !== unknownType) {
  14247. return resolveCall(node, getSignaturesOfType(superType, 1), candidatesOutArray);
  14248. }
  14249. return resolveUntypedCall(node);
  14250. }
  14251. var funcType = checkExpression(node.expression);
  14252. var apparentType = getApparentType(funcType);
  14253. if (apparentType === unknownType) {
  14254. return resolveErrorCall(node);
  14255. }
  14256. var callSignatures = getSignaturesOfType(apparentType, 0);
  14257. var constructSignatures = getSignaturesOfType(apparentType, 1);
  14258. if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) {
  14259. if (node.typeArguments) {
  14260. error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
  14261. }
  14262. return resolveUntypedCall(node);
  14263. }
  14264. if (!callSignatures.length) {
  14265. if (constructSignatures.length) {
  14266. error(node, ts.Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
  14267. }
  14268. else {
  14269. error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  14270. }
  14271. return resolveErrorCall(node);
  14272. }
  14273. return resolveCall(node, callSignatures, candidatesOutArray);
  14274. }
  14275. function resolveNewExpression(node, candidatesOutArray) {
  14276. if (node.arguments && languageVersion < 2) {
  14277. var spreadIndex = getSpreadArgumentIndex(node.arguments);
  14278. if (spreadIndex >= 0) {
  14279. error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher);
  14280. }
  14281. }
  14282. var expressionType = checkExpression(node.expression);
  14283. if (expressionType === anyType) {
  14284. if (node.typeArguments) {
  14285. error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments);
  14286. }
  14287. return resolveUntypedCall(node);
  14288. }
  14289. expressionType = getApparentType(expressionType);
  14290. if (expressionType === unknownType) {
  14291. return resolveErrorCall(node);
  14292. }
  14293. var constructSignatures = getSignaturesOfType(expressionType, 1);
  14294. if (constructSignatures.length) {
  14295. return resolveCall(node, constructSignatures, candidatesOutArray);
  14296. }
  14297. var callSignatures = getSignaturesOfType(expressionType, 0);
  14298. if (callSignatures.length) {
  14299. var signature = resolveCall(node, callSignatures, candidatesOutArray);
  14300. if (getReturnTypeOfSignature(signature) !== voidType) {
  14301. error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword);
  14302. }
  14303. return signature;
  14304. }
  14305. error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature);
  14306. return resolveErrorCall(node);
  14307. }
  14308. function resolveTaggedTemplateExpression(node, candidatesOutArray) {
  14309. var tagType = checkExpression(node.tag);
  14310. var apparentType = getApparentType(tagType);
  14311. if (apparentType === unknownType) {
  14312. return resolveErrorCall(node);
  14313. }
  14314. var callSignatures = getSignaturesOfType(apparentType, 0);
  14315. if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) {
  14316. return resolveUntypedCall(node);
  14317. }
  14318. if (!callSignatures.length) {
  14319. error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
  14320. return resolveErrorCall(node);
  14321. }
  14322. return resolveCall(node, callSignatures, candidatesOutArray);
  14323. }
  14324. function getResolvedSignature(node, candidatesOutArray) {
  14325. var links = getNodeLinks(node);
  14326. if (!links.resolvedSignature || candidatesOutArray) {
  14327. links.resolvedSignature = anySignature;
  14328. if (node.kind === 158) {
  14329. links.resolvedSignature = resolveCallExpression(node, candidatesOutArray);
  14330. }
  14331. else if (node.kind === 159) {
  14332. links.resolvedSignature = resolveNewExpression(node, candidatesOutArray);
  14333. }
  14334. else if (node.kind === 160) {
  14335. links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray);
  14336. }
  14337. else {
  14338. ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable.");
  14339. }
  14340. }
  14341. return links.resolvedSignature;
  14342. }
  14343. function checkCallExpression(node) {
  14344. checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments);
  14345. var signature = getResolvedSignature(node);
  14346. if (node.expression.kind === 91) {
  14347. return voidType;
  14348. }
  14349. if (node.kind === 159) {
  14350. var declaration = signature.declaration;
  14351. if (declaration &&
  14352. declaration.kind !== 136 &&
  14353. declaration.kind !== 140 &&
  14354. declaration.kind !== 144) {
  14355. if (compilerOptions.noImplicitAny) {
  14356. error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
  14357. }
  14358. return anyType;
  14359. }
  14360. }
  14361. return getReturnTypeOfSignature(signature);
  14362. }
  14363. function checkTaggedTemplateExpression(node) {
  14364. return getReturnTypeOfSignature(getResolvedSignature(node));
  14365. }
  14366. function checkTypeAssertion(node) {
  14367. var exprType = checkExpression(node.expression);
  14368. var targetType = getTypeFromTypeNode(node.type);
  14369. if (produceDiagnostics && targetType !== unknownType) {
  14370. var widenedType = getWidenedType(exprType);
  14371. if (!(isTypeAssignableTo(targetType, widenedType))) {
  14372. checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other);
  14373. }
  14374. }
  14375. return targetType;
  14376. }
  14377. function getTypeAtPosition(signature, pos) {
  14378. return signature.hasRestParameter ?
  14379. pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
  14380. pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType;
  14381. }
  14382. function assignContextualParameterTypes(signature, context, mapper) {
  14383. var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
  14384. for (var i = 0; i < len; i++) {
  14385. var parameter = signature.parameters[i];
  14386. var links = getSymbolLinks(parameter);
  14387. links.type = instantiateType(getTypeAtPosition(context, i), mapper);
  14388. }
  14389. if (signature.hasRestParameter && context.hasRestParameter && signature.parameters.length >= context.parameters.length) {
  14390. var parameter = ts.lastOrUndefined(signature.parameters);
  14391. var links = getSymbolLinks(parameter);
  14392. links.type = instantiateType(getTypeOfSymbol(ts.lastOrUndefined(context.parameters)), mapper);
  14393. }
  14394. }
  14395. function getReturnTypeFromBody(func, contextualMapper) {
  14396. var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
  14397. if (!func.body) {
  14398. return unknownType;
  14399. }
  14400. var type;
  14401. if (func.body.kind !== 180) {
  14402. type = checkExpressionCached(func.body, contextualMapper);
  14403. }
  14404. else {
  14405. var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper);
  14406. if (types.length === 0) {
  14407. return voidType;
  14408. }
  14409. type = contextualSignature ? getUnionType(types) : getCommonSupertype(types);
  14410. if (!type) {
  14411. error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions);
  14412. return unknownType;
  14413. }
  14414. }
  14415. if (!contextualSignature) {
  14416. reportErrorsFromWidening(func, type);
  14417. }
  14418. return getWidenedType(type);
  14419. }
  14420. function checkAndAggregateReturnExpressionTypes(body, contextualMapper) {
  14421. var aggregatedTypes = [];
  14422. ts.forEachReturnStatement(body, function (returnStatement) {
  14423. var expr = returnStatement.expression;
  14424. if (expr) {
  14425. var type = checkExpressionCached(expr, contextualMapper);
  14426. if (!ts.contains(aggregatedTypes, type)) {
  14427. aggregatedTypes.push(type);
  14428. }
  14429. }
  14430. });
  14431. return aggregatedTypes;
  14432. }
  14433. function bodyContainsAReturnStatement(funcBody) {
  14434. return ts.forEachReturnStatement(funcBody, function (returnStatement) {
  14435. return true;
  14436. });
  14437. }
  14438. function bodyContainsSingleThrowStatement(body) {
  14439. return (body.statements.length === 1) && (body.statements[0].kind === 196);
  14440. }
  14441. function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) {
  14442. if (!produceDiagnostics) {
  14443. return;
  14444. }
  14445. if (returnType === voidType || returnType === anyType) {
  14446. return;
  14447. }
  14448. if (ts.nodeIsMissing(func.body) || func.body.kind !== 180) {
  14449. return;
  14450. }
  14451. var bodyBlock = func.body;
  14452. if (bodyContainsAReturnStatement(bodyBlock)) {
  14453. return;
  14454. }
  14455. if (bodyContainsSingleThrowStatement(bodyBlock)) {
  14456. return;
  14457. }
  14458. 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);
  14459. }
  14460. function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) {
  14461. ts.Debug.assert(node.kind !== 135 || ts.isObjectLiteralMethod(node));
  14462. var hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node);
  14463. if (!hasGrammarError && node.kind === 163) {
  14464. checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node);
  14465. }
  14466. if (contextualMapper === identityMapper && isContextSensitive(node)) {
  14467. return anyFunctionType;
  14468. }
  14469. var links = getNodeLinks(node);
  14470. var type = getTypeOfSymbol(node.symbol);
  14471. if (!(links.flags & 64)) {
  14472. var contextualSignature = getContextualSignature(node);
  14473. if (!(links.flags & 64)) {
  14474. links.flags |= 64;
  14475. if (contextualSignature) {
  14476. var signature = getSignaturesOfType(type, 0)[0];
  14477. if (isContextSensitive(node)) {
  14478. assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper);
  14479. }
  14480. if (!node.type && !signature.resolvedReturnType) {
  14481. var returnType = getReturnTypeFromBody(node, contextualMapper);
  14482. if (!signature.resolvedReturnType) {
  14483. signature.resolvedReturnType = returnType;
  14484. }
  14485. }
  14486. }
  14487. checkSignatureDeclaration(node);
  14488. }
  14489. }
  14490. if (produceDiagnostics && node.kind !== 135 && node.kind !== 134) {
  14491. checkCollisionWithCapturedSuperVariable(node, node.name);
  14492. checkCollisionWithCapturedThisVariable(node, node.name);
  14493. }
  14494. return type;
  14495. }
  14496. function checkFunctionExpressionOrObjectLiteralMethodBody(node) {
  14497. ts.Debug.assert(node.kind !== 135 || ts.isObjectLiteralMethod(node));
  14498. if (node.type && !node.asteriskToken) {
  14499. checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
  14500. }
  14501. if (node.body) {
  14502. if (!node.type) {
  14503. getReturnTypeOfSignature(getSignatureFromDeclaration(node));
  14504. }
  14505. if (node.body.kind === 180) {
  14506. checkSourceElement(node.body);
  14507. }
  14508. else {
  14509. var exprType = checkExpression(node.body);
  14510. if (node.type) {
  14511. checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined);
  14512. }
  14513. checkFunctionExpressionBodies(node.body);
  14514. }
  14515. }
  14516. }
  14517. function checkArithmeticOperandType(operand, type, diagnostic) {
  14518. if (!allConstituentTypesHaveKind(type, 1 | 132)) {
  14519. error(operand, diagnostic);
  14520. return false;
  14521. }
  14522. return true;
  14523. }
  14524. function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) {
  14525. function findSymbol(n) {
  14526. var symbol = getNodeLinks(n).resolvedSymbol;
  14527. return symbol && getExportSymbolOfValueSymbolIfExported(symbol);
  14528. }
  14529. function isReferenceOrErrorExpression(n) {
  14530. switch (n.kind) {
  14531. case 65: {
  14532. var symbol = findSymbol(n);
  14533. return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3) !== 0;
  14534. }
  14535. case 156: {
  14536. var symbol = findSymbol(n);
  14537. return !symbol || symbol === unknownSymbol || (symbol.flags & ~8) !== 0;
  14538. }
  14539. case 157:
  14540. return true;
  14541. case 162:
  14542. return isReferenceOrErrorExpression(n.expression);
  14543. default:
  14544. return false;
  14545. }
  14546. }
  14547. function isConstVariableReference(n) {
  14548. switch (n.kind) {
  14549. case 65:
  14550. case 156: {
  14551. var symbol = findSymbol(n);
  14552. return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 8192) !== 0;
  14553. }
  14554. case 157: {
  14555. var index = n.argumentExpression;
  14556. var symbol = findSymbol(n.expression);
  14557. if (symbol && index && index.kind === 8) {
  14558. var name_7 = index.text;
  14559. var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_7);
  14560. return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0;
  14561. }
  14562. return false;
  14563. }
  14564. case 162:
  14565. return isConstVariableReference(n.expression);
  14566. default:
  14567. return false;
  14568. }
  14569. }
  14570. if (!isReferenceOrErrorExpression(n)) {
  14571. error(n, invalidReferenceMessage);
  14572. return false;
  14573. }
  14574. if (isConstVariableReference(n)) {
  14575. error(n, constantVariableMessage);
  14576. return false;
  14577. }
  14578. return true;
  14579. }
  14580. function checkDeleteExpression(node) {
  14581. if (node.parserContextFlags & 1 && node.expression.kind === 65) {
  14582. grammarErrorOnNode(node.expression, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
  14583. }
  14584. var operandType = checkExpression(node.expression);
  14585. return booleanType;
  14586. }
  14587. function checkTypeOfExpression(node) {
  14588. var operandType = checkExpression(node.expression);
  14589. return stringType;
  14590. }
  14591. function checkVoidExpression(node) {
  14592. var operandType = checkExpression(node.expression);
  14593. return undefinedType;
  14594. }
  14595. function checkPrefixUnaryExpression(node) {
  14596. if ((node.operator === 38 || node.operator === 39)) {
  14597. checkGrammarEvalOrArgumentsInStrictMode(node, node.operand);
  14598. }
  14599. var operandType = checkExpression(node.operand);
  14600. switch (node.operator) {
  14601. case 33:
  14602. case 34:
  14603. case 47:
  14604. if (someConstituentTypeHasKind(operandType, 1048576)) {
  14605. error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator));
  14606. }
  14607. return numberType;
  14608. case 46:
  14609. return booleanType;
  14610. case 38:
  14611. case 39:
  14612. var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
  14613. if (ok) {
  14614. 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);
  14615. }
  14616. return numberType;
  14617. }
  14618. return unknownType;
  14619. }
  14620. function checkPostfixUnaryExpression(node) {
  14621. checkGrammarEvalOrArgumentsInStrictMode(node, node.operand);
  14622. var operandType = checkExpression(node.operand);
  14623. var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
  14624. if (ok) {
  14625. 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);
  14626. }
  14627. return numberType;
  14628. }
  14629. function someConstituentTypeHasKind(type, kind) {
  14630. if (type.flags & kind) {
  14631. return true;
  14632. }
  14633. if (type.flags & 16384) {
  14634. var types = type.types;
  14635. for (var _i = 0; _i < types.length; _i++) {
  14636. var current = types[_i];
  14637. if (current.flags & kind) {
  14638. return true;
  14639. }
  14640. }
  14641. return false;
  14642. }
  14643. return false;
  14644. }
  14645. function allConstituentTypesHaveKind(type, kind) {
  14646. if (type.flags & kind) {
  14647. return true;
  14648. }
  14649. if (type.flags & 16384) {
  14650. var types = type.types;
  14651. for (var _i = 0; _i < types.length; _i++) {
  14652. var current = types[_i];
  14653. if (!(current.flags & kind)) {
  14654. return false;
  14655. }
  14656. }
  14657. return true;
  14658. }
  14659. return false;
  14660. }
  14661. function isConstEnumObjectType(type) {
  14662. return type.flags & (48128 | 32768) && type.symbol && isConstEnumSymbol(type.symbol);
  14663. }
  14664. function isConstEnumSymbol(symbol) {
  14665. return (symbol.flags & 128) !== 0;
  14666. }
  14667. function checkInstanceOfExpression(node, leftType, rightType) {
  14668. if (allConstituentTypesHaveKind(leftType, 1049086)) {
  14669. 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);
  14670. }
  14671. if (!(rightType.flags & 1 || isTypeSubtypeOf(rightType, globalFunctionType))) {
  14672. 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);
  14673. }
  14674. return booleanType;
  14675. }
  14676. function checkInExpression(node, leftType, rightType) {
  14677. if (!allConstituentTypesHaveKind(leftType, 1 | 258 | 132 | 1048576)) {
  14678. error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
  14679. }
  14680. if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) {
  14681. 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);
  14682. }
  14683. return booleanType;
  14684. }
  14685. function checkObjectLiteralAssignment(node, sourceType, contextualMapper) {
  14686. var properties = node.properties;
  14687. for (var _i = 0; _i < properties.length; _i++) {
  14688. var p = properties[_i];
  14689. if (p.kind === 225 || p.kind === 226) {
  14690. var name_8 = p.name;
  14691. var type = sourceType.flags & 1 ? sourceType :
  14692. getTypeOfPropertyOfType(sourceType, name_8.text) ||
  14693. isNumericLiteralName(name_8.text) && getIndexTypeOfType(sourceType, 1) ||
  14694. getIndexTypeOfType(sourceType, 0);
  14695. if (type) {
  14696. checkDestructuringAssignment(p.initializer || name_8, type);
  14697. }
  14698. else {
  14699. error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_8));
  14700. }
  14701. }
  14702. else {
  14703. error(p, ts.Diagnostics.Property_assignment_expected);
  14704. }
  14705. }
  14706. return sourceType;
  14707. }
  14708. function checkArrayLiteralAssignment(node, sourceType, contextualMapper) {
  14709. var elementType = checkIteratedTypeOrElementType(sourceType, node, false) || unknownType;
  14710. var elements = node.elements;
  14711. for (var i = 0; i < elements.length; i++) {
  14712. var e = elements[i];
  14713. if (e.kind !== 176) {
  14714. if (e.kind !== 174) {
  14715. var propName = "" + i;
  14716. var type = sourceType.flags & 1 ? sourceType :
  14717. isTupleLikeType(sourceType)
  14718. ? getTypeOfPropertyOfType(sourceType, propName)
  14719. : elementType;
  14720. if (type) {
  14721. checkDestructuringAssignment(e, type, contextualMapper);
  14722. }
  14723. else {
  14724. if (isTupleType(sourceType)) {
  14725. 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);
  14726. }
  14727. else {
  14728. error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName);
  14729. }
  14730. }
  14731. }
  14732. else {
  14733. if (i < elements.length - 1) {
  14734. error(e, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
  14735. }
  14736. else {
  14737. var restExpression = e.expression;
  14738. if (restExpression.kind === 170 && restExpression.operatorToken.kind === 53) {
  14739. error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer);
  14740. }
  14741. else {
  14742. checkDestructuringAssignment(restExpression, createArrayType(elementType), contextualMapper);
  14743. }
  14744. }
  14745. }
  14746. }
  14747. }
  14748. return sourceType;
  14749. }
  14750. function checkDestructuringAssignment(target, sourceType, contextualMapper) {
  14751. if (target.kind === 170 && target.operatorToken.kind === 53) {
  14752. checkBinaryExpression(target, contextualMapper);
  14753. target = target.left;
  14754. }
  14755. if (target.kind === 155) {
  14756. return checkObjectLiteralAssignment(target, sourceType, contextualMapper);
  14757. }
  14758. if (target.kind === 154) {
  14759. return checkArrayLiteralAssignment(target, sourceType, contextualMapper);
  14760. }
  14761. return checkReferenceAssignment(target, sourceType, contextualMapper);
  14762. }
  14763. function checkReferenceAssignment(target, sourceType, contextualMapper) {
  14764. var targetType = checkExpression(target, contextualMapper);
  14765. if (checkReferenceExpression(target, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant)) {
  14766. checkTypeAssignableTo(sourceType, targetType, target, undefined);
  14767. }
  14768. return sourceType;
  14769. }
  14770. function checkBinaryExpression(node, contextualMapper) {
  14771. if (ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operatorToken.kind)) {
  14772. checkGrammarEvalOrArgumentsInStrictMode(node, node.left);
  14773. }
  14774. var operator = node.operatorToken.kind;
  14775. if (operator === 53 && (node.left.kind === 155 || node.left.kind === 154)) {
  14776. return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper);
  14777. }
  14778. var leftType = checkExpression(node.left, contextualMapper);
  14779. var rightType = checkExpression(node.right, contextualMapper);
  14780. switch (operator) {
  14781. case 35:
  14782. case 56:
  14783. case 36:
  14784. case 57:
  14785. case 37:
  14786. case 58:
  14787. case 34:
  14788. case 55:
  14789. case 40:
  14790. case 59:
  14791. case 41:
  14792. case 60:
  14793. case 42:
  14794. case 61:
  14795. case 44:
  14796. case 63:
  14797. case 45:
  14798. case 64:
  14799. case 43:
  14800. case 62:
  14801. if (leftType.flags & (32 | 64))
  14802. leftType = rightType;
  14803. if (rightType.flags & (32 | 64))
  14804. rightType = leftType;
  14805. var suggestedOperator;
  14806. if ((leftType.flags & 8) &&
  14807. (rightType.flags & 8) &&
  14808. (suggestedOperator = getSuggestedBooleanOperator(node.operatorToken.kind)) !== undefined) {
  14809. 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));
  14810. }
  14811. else {
  14812. 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);
  14813. 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);
  14814. if (leftOk && rightOk) {
  14815. checkAssignmentOperator(numberType);
  14816. }
  14817. }
  14818. return numberType;
  14819. case 33:
  14820. case 54:
  14821. if (leftType.flags & (32 | 64))
  14822. leftType = rightType;
  14823. if (rightType.flags & (32 | 64))
  14824. rightType = leftType;
  14825. var resultType;
  14826. if (allConstituentTypesHaveKind(leftType, 132) && allConstituentTypesHaveKind(rightType, 132)) {
  14827. resultType = numberType;
  14828. }
  14829. else {
  14830. if (allConstituentTypesHaveKind(leftType, 258) || allConstituentTypesHaveKind(rightType, 258)) {
  14831. resultType = stringType;
  14832. }
  14833. else if (leftType.flags & 1 || rightType.flags & 1) {
  14834. resultType = anyType;
  14835. }
  14836. if (resultType && !checkForDisallowedESSymbolOperand(operator)) {
  14837. return resultType;
  14838. }
  14839. }
  14840. if (!resultType) {
  14841. reportOperatorError();
  14842. return anyType;
  14843. }
  14844. if (operator === 54) {
  14845. checkAssignmentOperator(resultType);
  14846. }
  14847. return resultType;
  14848. case 24:
  14849. case 25:
  14850. case 26:
  14851. case 27:
  14852. if (!checkForDisallowedESSymbolOperand(operator)) {
  14853. return booleanType;
  14854. }
  14855. case 28:
  14856. case 29:
  14857. case 30:
  14858. case 31:
  14859. if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) {
  14860. reportOperatorError();
  14861. }
  14862. return booleanType;
  14863. case 87:
  14864. return checkInstanceOfExpression(node, leftType, rightType);
  14865. case 86:
  14866. return checkInExpression(node, leftType, rightType);
  14867. case 48:
  14868. return rightType;
  14869. case 49:
  14870. return getUnionType([leftType, rightType]);
  14871. case 53:
  14872. checkAssignmentOperator(rightType);
  14873. return rightType;
  14874. case 23:
  14875. return rightType;
  14876. }
  14877. function checkForDisallowedESSymbolOperand(operator) {
  14878. var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left :
  14879. someConstituentTypeHasKind(rightType, 1048576) ? node.right :
  14880. undefined;
  14881. if (offendingSymbolOperand) {
  14882. error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator));
  14883. return false;
  14884. }
  14885. return true;
  14886. }
  14887. function getSuggestedBooleanOperator(operator) {
  14888. switch (operator) {
  14889. case 44:
  14890. case 63:
  14891. return 49;
  14892. case 45:
  14893. case 64:
  14894. return 31;
  14895. case 43:
  14896. case 62:
  14897. return 48;
  14898. default:
  14899. return undefined;
  14900. }
  14901. }
  14902. function checkAssignmentOperator(valueType) {
  14903. if (produceDiagnostics && operator >= 53 && operator <= 64) {
  14904. 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);
  14905. if (ok) {
  14906. checkTypeAssignableTo(valueType, leftType, node.left, undefined);
  14907. }
  14908. }
  14909. }
  14910. function reportOperatorError() {
  14911. error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType));
  14912. }
  14913. }
  14914. function checkYieldExpression(node) {
  14915. if (!(node.parserContextFlags & 4)) {
  14916. grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
  14917. }
  14918. else {
  14919. grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported);
  14920. }
  14921. }
  14922. function checkConditionalExpression(node, contextualMapper) {
  14923. checkExpression(node.condition);
  14924. var type1 = checkExpression(node.whenTrue, contextualMapper);
  14925. var type2 = checkExpression(node.whenFalse, contextualMapper);
  14926. return getUnionType([type1, type2]);
  14927. }
  14928. function checkTemplateExpression(node) {
  14929. ts.forEach(node.templateSpans, function (templateSpan) {
  14930. checkExpression(templateSpan.expression);
  14931. });
  14932. return stringType;
  14933. }
  14934. function checkExpressionWithContextualType(node, contextualType, contextualMapper) {
  14935. var saveContextualType = node.contextualType;
  14936. node.contextualType = contextualType;
  14937. var result = checkExpression(node, contextualMapper);
  14938. node.contextualType = saveContextualType;
  14939. return result;
  14940. }
  14941. function checkExpressionCached(node, contextualMapper) {
  14942. var links = getNodeLinks(node);
  14943. if (!links.resolvedType) {
  14944. links.resolvedType = checkExpression(node, contextualMapper);
  14945. }
  14946. return links.resolvedType;
  14947. }
  14948. function checkPropertyAssignment(node, contextualMapper) {
  14949. if (node.name.kind === 128) {
  14950. checkComputedPropertyName(node.name);
  14951. }
  14952. return checkExpression(node.initializer, contextualMapper);
  14953. }
  14954. function checkObjectLiteralMethod(node, contextualMapper) {
  14955. checkGrammarMethod(node);
  14956. if (node.name.kind === 128) {
  14957. checkComputedPropertyName(node.name);
  14958. }
  14959. var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper);
  14960. return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper);
  14961. }
  14962. function instantiateTypeWithSingleGenericCallSignature(node, type, contextualMapper) {
  14963. if (contextualMapper && contextualMapper !== identityMapper) {
  14964. var signature = getSingleCallSignature(type);
  14965. if (signature && signature.typeParameters) {
  14966. var contextualType = getContextualType(node);
  14967. if (contextualType) {
  14968. var contextualSignature = getSingleCallSignature(contextualType);
  14969. if (contextualSignature && !contextualSignature.typeParameters) {
  14970. return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper));
  14971. }
  14972. }
  14973. }
  14974. }
  14975. return type;
  14976. }
  14977. function checkExpression(node, contextualMapper) {
  14978. checkGrammarIdentifierInStrictMode(node);
  14979. return checkExpressionOrQualifiedName(node, contextualMapper);
  14980. }
  14981. function checkExpressionOrQualifiedName(node, contextualMapper) {
  14982. var type;
  14983. if (node.kind == 127) {
  14984. type = checkQualifiedName(node);
  14985. }
  14986. else {
  14987. var uninstantiatedType = checkExpressionWorker(node, contextualMapper);
  14988. type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper);
  14989. }
  14990. if (isConstEnumObjectType(type)) {
  14991. var ok = (node.parent.kind === 156 && node.parent.expression === node) ||
  14992. (node.parent.kind === 157 && node.parent.expression === node) ||
  14993. ((node.kind === 65 || node.kind === 127) && isInRightSideOfImportOrExportAssignment(node));
  14994. if (!ok) {
  14995. 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);
  14996. }
  14997. }
  14998. return type;
  14999. }
  15000. function checkNumericLiteral(node) {
  15001. checkGrammarNumericLiteral(node);
  15002. return numberType;
  15003. }
  15004. function checkExpressionWorker(node, contextualMapper) {
  15005. switch (node.kind) {
  15006. case 65:
  15007. return checkIdentifier(node);
  15008. case 93:
  15009. return checkThisExpression(node);
  15010. case 91:
  15011. return checkSuperExpression(node);
  15012. case 89:
  15013. return nullType;
  15014. case 95:
  15015. case 80:
  15016. return booleanType;
  15017. case 7:
  15018. return checkNumericLiteral(node);
  15019. case 172:
  15020. return checkTemplateExpression(node);
  15021. case 8:
  15022. case 10:
  15023. return stringType;
  15024. case 9:
  15025. return globalRegExpType;
  15026. case 154:
  15027. return checkArrayLiteral(node, contextualMapper);
  15028. case 155:
  15029. return checkObjectLiteral(node, contextualMapper);
  15030. case 156:
  15031. return checkPropertyAccessExpression(node);
  15032. case 157:
  15033. return checkIndexedAccess(node);
  15034. case 158:
  15035. case 159:
  15036. return checkCallExpression(node);
  15037. case 160:
  15038. return checkTaggedTemplateExpression(node);
  15039. case 161:
  15040. return checkTypeAssertion(node);
  15041. case 162:
  15042. return checkExpression(node.expression, contextualMapper);
  15043. case 175:
  15044. return checkClassExpression(node);
  15045. case 163:
  15046. case 164:
  15047. return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper);
  15048. case 166:
  15049. return checkTypeOfExpression(node);
  15050. case 165:
  15051. return checkDeleteExpression(node);
  15052. case 167:
  15053. return checkVoidExpression(node);
  15054. case 168:
  15055. return checkPrefixUnaryExpression(node);
  15056. case 169:
  15057. return checkPostfixUnaryExpression(node);
  15058. case 170:
  15059. return checkBinaryExpression(node, contextualMapper);
  15060. case 171:
  15061. return checkConditionalExpression(node, contextualMapper);
  15062. case 174:
  15063. return checkSpreadElementExpression(node, contextualMapper);
  15064. case 176:
  15065. return undefinedType;
  15066. case 173:
  15067. checkYieldExpression(node);
  15068. return unknownType;
  15069. }
  15070. return unknownType;
  15071. }
  15072. function checkTypeParameter(node) {
  15073. checkGrammarDeclarationNameInStrictMode(node);
  15074. if (node.expression) {
  15075. grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected);
  15076. }
  15077. checkSourceElement(node.constraint);
  15078. if (produceDiagnostics) {
  15079. checkTypeParameterHasIllegalReferencesInConstraint(node);
  15080. checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0);
  15081. }
  15082. }
  15083. function checkParameter(node) {
  15084. // Grammar checking
  15085. // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
  15086. // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
  15087. // or if its FunctionBody is strict code(11.1.5).
  15088. // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
  15089. // strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
  15090. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name);
  15091. checkVariableLikeDeclaration(node);
  15092. var func = ts.getContainingFunction(node);
  15093. if (node.flags & 112) {
  15094. func = ts.getContainingFunction(node);
  15095. if (!(func.kind === 136 && ts.nodeIsPresent(func.body))) {
  15096. error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
  15097. }
  15098. }
  15099. if (node.questionToken && ts.isBindingPattern(node.name) && func.body) {
  15100. error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
  15101. }
  15102. if (node.dotDotDotToken && !ts.isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) {
  15103. error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type);
  15104. }
  15105. }
  15106. function checkSignatureDeclaration(node) {
  15107. if (node.kind === 141) {
  15108. checkGrammarIndexSignature(node);
  15109. }
  15110. else if (node.kind === 143 || node.kind === 201 || node.kind === 144 ||
  15111. node.kind === 139 || node.kind === 136 ||
  15112. node.kind === 140) {
  15113. checkGrammarFunctionLikeDeclaration(node);
  15114. }
  15115. checkTypeParameters(node.typeParameters);
  15116. ts.forEach(node.parameters, checkParameter);
  15117. if (node.type) {
  15118. checkSourceElement(node.type);
  15119. }
  15120. if (produceDiagnostics) {
  15121. checkCollisionWithArgumentsInGeneratedCode(node);
  15122. if (compilerOptions.noImplicitAny && !node.type) {
  15123. switch (node.kind) {
  15124. case 140:
  15125. error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
  15126. break;
  15127. case 139:
  15128. error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type);
  15129. break;
  15130. }
  15131. }
  15132. }
  15133. checkSpecializedSignatureDeclaration(node);
  15134. }
  15135. function checkTypeForDuplicateIndexSignatures(node) {
  15136. if (node.kind === 203) {
  15137. var nodeSymbol = getSymbolOfNode(node);
  15138. if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) {
  15139. return;
  15140. }
  15141. }
  15142. var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
  15143. if (indexSymbol) {
  15144. var seenNumericIndexer = false;
  15145. var seenStringIndexer = false;
  15146. for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
  15147. var decl = _a[_i];
  15148. var declaration = decl;
  15149. if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
  15150. switch (declaration.parameters[0].type.kind) {
  15151. case 122:
  15152. if (!seenStringIndexer) {
  15153. seenStringIndexer = true;
  15154. }
  15155. else {
  15156. error(declaration, ts.Diagnostics.Duplicate_string_index_signature);
  15157. }
  15158. break;
  15159. case 120:
  15160. if (!seenNumericIndexer) {
  15161. seenNumericIndexer = true;
  15162. }
  15163. else {
  15164. error(declaration, ts.Diagnostics.Duplicate_number_index_signature);
  15165. }
  15166. break;
  15167. }
  15168. }
  15169. }
  15170. }
  15171. }
  15172. function checkPropertyDeclaration(node) {
  15173. checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name);
  15174. checkVariableLikeDeclaration(node);
  15175. }
  15176. function checkMethodDeclaration(node) {
  15177. checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name);
  15178. checkFunctionLikeDeclaration(node);
  15179. }
  15180. function checkConstructorDeclaration(node) {
  15181. checkSignatureDeclaration(node);
  15182. checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node);
  15183. checkSourceElement(node.body);
  15184. var symbol = getSymbolOfNode(node);
  15185. var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind);
  15186. if (node === firstDeclaration) {
  15187. checkFunctionOrConstructorSymbol(symbol);
  15188. }
  15189. if (ts.nodeIsMissing(node.body)) {
  15190. return;
  15191. }
  15192. if (!produceDiagnostics) {
  15193. return;
  15194. }
  15195. function isSuperCallExpression(n) {
  15196. return n.kind === 158 && n.expression.kind === 91;
  15197. }
  15198. function containsSuperCall(n) {
  15199. if (isSuperCallExpression(n)) {
  15200. return true;
  15201. }
  15202. switch (n.kind) {
  15203. case 163:
  15204. case 201:
  15205. case 164:
  15206. case 155: return false;
  15207. default: return ts.forEachChild(n, containsSuperCall);
  15208. }
  15209. }
  15210. function markThisReferencesAsErrors(n) {
  15211. if (n.kind === 93) {
  15212. error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
  15213. }
  15214. else if (n.kind !== 163 && n.kind !== 201) {
  15215. ts.forEachChild(n, markThisReferencesAsErrors);
  15216. }
  15217. }
  15218. function isInstancePropertyWithInitializer(n) {
  15219. return n.kind === 133 &&
  15220. !(n.flags & 128) &&
  15221. !!n.initializer;
  15222. }
  15223. if (ts.getClassExtendsHeritageClauseElement(node.parent)) {
  15224. if (containsSuperCall(node.body)) {
  15225. var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) ||
  15226. ts.forEach(node.parameters, function (p) { return p.flags & (16 | 32 | 64); });
  15227. if (superCallShouldBeFirst) {
  15228. var statements = node.body.statements;
  15229. if (!statements.length || statements[0].kind !== 183 || !isSuperCallExpression(statements[0].expression)) {
  15230. 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);
  15231. }
  15232. else {
  15233. markThisReferencesAsErrors(statements[0].expression);
  15234. }
  15235. }
  15236. }
  15237. else {
  15238. error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
  15239. }
  15240. }
  15241. }
  15242. function checkAccessorDeclaration(node) {
  15243. if (produceDiagnostics) {
  15244. checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name);
  15245. if (node.kind === 137) {
  15246. if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) {
  15247. error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement);
  15248. }
  15249. }
  15250. if (!ts.hasDynamicName(node)) {
  15251. var otherKind = node.kind === 137 ? 138 : 137;
  15252. var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind);
  15253. if (otherAccessor) {
  15254. if (((node.flags & 112) !== (otherAccessor.flags & 112))) {
  15255. error(node.name, ts.Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility);
  15256. }
  15257. var currentAccessorType = getAnnotatedAccessorType(node);
  15258. var otherAccessorType = getAnnotatedAccessorType(otherAccessor);
  15259. if (currentAccessorType && otherAccessorType) {
  15260. if (!isTypeIdenticalTo(currentAccessorType, otherAccessorType)) {
  15261. error(node, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type);
  15262. }
  15263. }
  15264. }
  15265. }
  15266. getTypeOfAccessors(getSymbolOfNode(node));
  15267. }
  15268. checkFunctionLikeDeclaration(node);
  15269. }
  15270. function checkMissingDeclaration(node) {
  15271. checkDecorators(node);
  15272. }
  15273. function checkTypeReferenceNode(node) {
  15274. checkGrammarTypeReferenceInStrictMode(node.typeName);
  15275. return checkTypeReferenceOrExpressionWithTypeArguments(node);
  15276. }
  15277. function checkExpressionWithTypeArguments(node) {
  15278. checkGrammarExpressionWithTypeArgumentsInStrictMode(node.expression);
  15279. return checkTypeReferenceOrExpressionWithTypeArguments(node);
  15280. }
  15281. function checkTypeReferenceOrExpressionWithTypeArguments(node) {
  15282. checkGrammarTypeArguments(node, node.typeArguments);
  15283. var type = getTypeFromTypeReferenceOrExpressionWithTypeArguments(node);
  15284. if (type !== unknownType && node.typeArguments) {
  15285. var len = node.typeArguments.length;
  15286. for (var i = 0; i < len; i++) {
  15287. checkSourceElement(node.typeArguments[i]);
  15288. var constraint = getConstraintOfTypeParameter(type.target.typeParameters[i]);
  15289. if (produceDiagnostics && constraint) {
  15290. var typeArgument = type.typeArguments[i];
  15291. checkTypeAssignableTo(typeArgument, constraint, node, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
  15292. }
  15293. }
  15294. }
  15295. }
  15296. function checkTypeQuery(node) {
  15297. getTypeFromTypeQueryNode(node);
  15298. }
  15299. function checkTypeLiteral(node) {
  15300. ts.forEach(node.members, checkSourceElement);
  15301. if (produceDiagnostics) {
  15302. var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
  15303. checkIndexConstraints(type);
  15304. checkTypeForDuplicateIndexSignatures(node);
  15305. }
  15306. }
  15307. function checkArrayType(node) {
  15308. checkSourceElement(node.elementType);
  15309. }
  15310. function checkTupleType(node) {
  15311. var hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes);
  15312. if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) {
  15313. grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty);
  15314. }
  15315. ts.forEach(node.elementTypes, checkSourceElement);
  15316. }
  15317. function checkUnionType(node) {
  15318. ts.forEach(node.types, checkSourceElement);
  15319. }
  15320. function isPrivateWithinAmbient(node) {
  15321. return (node.flags & 32) && ts.isInAmbientContext(node);
  15322. }
  15323. function checkSpecializedSignatureDeclaration(signatureDeclarationNode) {
  15324. if (!produceDiagnostics) {
  15325. return;
  15326. }
  15327. var signature = getSignatureFromDeclaration(signatureDeclarationNode);
  15328. if (!signature.hasStringLiterals) {
  15329. return;
  15330. }
  15331. if (ts.nodeIsPresent(signatureDeclarationNode.body)) {
  15332. error(signatureDeclarationNode, ts.Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type);
  15333. return;
  15334. }
  15335. var signaturesToCheck;
  15336. if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 203) {
  15337. ts.Debug.assert(signatureDeclarationNode.kind === 139 || signatureDeclarationNode.kind === 140);
  15338. var signatureKind = signatureDeclarationNode.kind === 139 ? 0 : 1;
  15339. var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent);
  15340. var containingType = getDeclaredTypeOfSymbol(containingSymbol);
  15341. signaturesToCheck = getSignaturesOfType(containingType, signatureKind);
  15342. }
  15343. else {
  15344. signaturesToCheck = getSignaturesOfSymbol(getSymbolOfNode(signatureDeclarationNode));
  15345. }
  15346. for (var _i = 0; _i < signaturesToCheck.length; _i++) {
  15347. var otherSignature = signaturesToCheck[_i];
  15348. if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) {
  15349. return;
  15350. }
  15351. }
  15352. error(signatureDeclarationNode, ts.Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature);
  15353. }
  15354. function getEffectiveDeclarationFlags(n, flagsToCheck) {
  15355. var flags = ts.getCombinedNodeFlags(n);
  15356. if (n.parent.kind !== 203 && ts.isInAmbientContext(n)) {
  15357. if (!(flags & 2)) {
  15358. flags |= 1;
  15359. }
  15360. flags |= 2;
  15361. }
  15362. return flags & flagsToCheck;
  15363. }
  15364. function checkFunctionOrConstructorSymbol(symbol) {
  15365. if (!produceDiagnostics) {
  15366. return;
  15367. }
  15368. function getCanonicalOverload(overloads, implementation) {
  15369. var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent;
  15370. return implementationSharesContainerWithFirstOverload ? implementation : overloads[0];
  15371. }
  15372. function checkFlagAgreementBetweenOverloads(overloads, implementation, flagsToCheck, someOverloadFlags, allOverloadFlags) {
  15373. var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags;
  15374. if (someButNotAllOverloadFlags !== 0) {
  15375. var canonicalFlags = getEffectiveDeclarationFlags(getCanonicalOverload(overloads, implementation), flagsToCheck);
  15376. ts.forEach(overloads, function (o) {
  15377. var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags;
  15378. if (deviation & 1) {
  15379. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported);
  15380. }
  15381. else if (deviation & 2) {
  15382. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
  15383. }
  15384. else if (deviation & (32 | 64)) {
  15385. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
  15386. }
  15387. });
  15388. }
  15389. }
  15390. function checkQuestionTokenAgreementBetweenOverloads(overloads, implementation, someHaveQuestionToken, allHaveQuestionToken) {
  15391. if (someHaveQuestionToken !== allHaveQuestionToken) {
  15392. var canonicalHasQuestionToken = ts.hasQuestionToken(getCanonicalOverload(overloads, implementation));
  15393. ts.forEach(overloads, function (o) {
  15394. var deviation = ts.hasQuestionToken(o) !== canonicalHasQuestionToken;
  15395. if (deviation) {
  15396. error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_optional_or_required);
  15397. }
  15398. });
  15399. }
  15400. }
  15401. var flagsToCheck = 1 | 2 | 32 | 64;
  15402. var someNodeFlags = 0;
  15403. var allNodeFlags = flagsToCheck;
  15404. var someHaveQuestionToken = false;
  15405. var allHaveQuestionToken = true;
  15406. var hasOverloads = false;
  15407. var bodyDeclaration;
  15408. var lastSeenNonAmbientDeclaration;
  15409. var previousDeclaration;
  15410. var declarations = symbol.declarations;
  15411. var isConstructor = (symbol.flags & 16384) !== 0;
  15412. function reportImplementationExpectedError(node) {
  15413. if (node.name && ts.nodeIsMissing(node.name)) {
  15414. return;
  15415. }
  15416. var seen = false;
  15417. var subsequentNode = ts.forEachChild(node.parent, function (c) {
  15418. if (seen) {
  15419. return c;
  15420. }
  15421. else {
  15422. seen = c === node;
  15423. }
  15424. });
  15425. if (subsequentNode) {
  15426. if (subsequentNode.kind === node.kind) {
  15427. var errorNode_1 = subsequentNode.name || subsequentNode;
  15428. if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) {
  15429. ts.Debug.assert(node.kind === 135 || node.kind === 134);
  15430. ts.Debug.assert((node.flags & 128) !== (subsequentNode.flags & 128));
  15431. var diagnostic = node.flags & 128 ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static;
  15432. error(errorNode_1, diagnostic);
  15433. return;
  15434. }
  15435. else if (ts.nodeIsPresent(subsequentNode.body)) {
  15436. error(errorNode_1, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name));
  15437. return;
  15438. }
  15439. }
  15440. }
  15441. var errorNode = node.name || node;
  15442. if (isConstructor) {
  15443. error(errorNode, ts.Diagnostics.Constructor_implementation_is_missing);
  15444. }
  15445. else {
  15446. error(errorNode, ts.Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration);
  15447. }
  15448. }
  15449. var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & 1536;
  15450. var duplicateFunctionDeclaration = false;
  15451. var multipleConstructorImplementation = false;
  15452. for (var _i = 0; _i < declarations.length; _i++) {
  15453. var current = declarations[_i];
  15454. var node = current;
  15455. var inAmbientContext = ts.isInAmbientContext(node);
  15456. var inAmbientContextOrInterface = node.parent.kind === 203 || node.parent.kind === 146 || inAmbientContext;
  15457. if (inAmbientContextOrInterface) {
  15458. previousDeclaration = undefined;
  15459. }
  15460. if (node.kind === 201 || node.kind === 135 || node.kind === 134 || node.kind === 136) {
  15461. var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
  15462. someNodeFlags |= currentNodeFlags;
  15463. allNodeFlags &= currentNodeFlags;
  15464. someHaveQuestionToken = someHaveQuestionToken || ts.hasQuestionToken(node);
  15465. allHaveQuestionToken = allHaveQuestionToken && ts.hasQuestionToken(node);
  15466. if (ts.nodeIsPresent(node.body) && bodyDeclaration) {
  15467. if (isConstructor) {
  15468. multipleConstructorImplementation = true;
  15469. }
  15470. else {
  15471. duplicateFunctionDeclaration = true;
  15472. }
  15473. }
  15474. else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
  15475. reportImplementationExpectedError(previousDeclaration);
  15476. }
  15477. if (ts.nodeIsPresent(node.body)) {
  15478. if (!bodyDeclaration) {
  15479. bodyDeclaration = node;
  15480. }
  15481. }
  15482. else {
  15483. hasOverloads = true;
  15484. }
  15485. previousDeclaration = node;
  15486. if (!inAmbientContextOrInterface) {
  15487. lastSeenNonAmbientDeclaration = node;
  15488. }
  15489. }
  15490. }
  15491. if (multipleConstructorImplementation) {
  15492. ts.forEach(declarations, function (declaration) {
  15493. error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed);
  15494. });
  15495. }
  15496. if (duplicateFunctionDeclaration) {
  15497. ts.forEach(declarations, function (declaration) {
  15498. error(declaration.name, ts.Diagnostics.Duplicate_function_implementation);
  15499. });
  15500. }
  15501. if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
  15502. reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
  15503. }
  15504. if (hasOverloads) {
  15505. checkFlagAgreementBetweenOverloads(declarations, bodyDeclaration, flagsToCheck, someNodeFlags, allNodeFlags);
  15506. checkQuestionTokenAgreementBetweenOverloads(declarations, bodyDeclaration, someHaveQuestionToken, allHaveQuestionToken);
  15507. if (bodyDeclaration) {
  15508. var signatures = getSignaturesOfSymbol(symbol);
  15509. var bodySignature = getSignatureFromDeclaration(bodyDeclaration);
  15510. if (!bodySignature.hasStringLiterals) {
  15511. for (var _a = 0; _a < signatures.length; _a++) {
  15512. var signature = signatures[_a];
  15513. if (!signature.hasStringLiterals && !isSignatureAssignableTo(bodySignature, signature)) {
  15514. error(signature.declaration, ts.Diagnostics.Overload_signature_is_not_compatible_with_function_implementation);
  15515. break;
  15516. }
  15517. }
  15518. }
  15519. }
  15520. }
  15521. }
  15522. function checkExportsOnMergedDeclarations(node) {
  15523. if (!produceDiagnostics) {
  15524. return;
  15525. }
  15526. var symbol = node.localSymbol;
  15527. if (!symbol) {
  15528. symbol = getSymbolOfNode(node);
  15529. if (!(symbol.flags & 7340032)) {
  15530. return;
  15531. }
  15532. }
  15533. if (ts.getDeclarationOfKind(symbol, node.kind) !== node) {
  15534. return;
  15535. }
  15536. var exportedDeclarationSpaces = 0;
  15537. var nonExportedDeclarationSpaces = 0;
  15538. ts.forEach(symbol.declarations, function (d) {
  15539. var declarationSpaces = getDeclarationSpaces(d);
  15540. if (getEffectiveDeclarationFlags(d, 1)) {
  15541. exportedDeclarationSpaces |= declarationSpaces;
  15542. }
  15543. else {
  15544. nonExportedDeclarationSpaces |= declarationSpaces;
  15545. }
  15546. });
  15547. var commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
  15548. if (commonDeclarationSpace) {
  15549. ts.forEach(symbol.declarations, function (d) {
  15550. if (getDeclarationSpaces(d) & commonDeclarationSpace) {
  15551. error(d.name, ts.Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, ts.declarationNameToString(d.name));
  15552. }
  15553. });
  15554. }
  15555. function getDeclarationSpaces(d) {
  15556. switch (d.kind) {
  15557. case 203:
  15558. return 2097152;
  15559. case 206:
  15560. return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0
  15561. ? 4194304 | 1048576
  15562. : 4194304;
  15563. case 202:
  15564. case 205:
  15565. return 2097152 | 1048576;
  15566. case 209:
  15567. var result = 0;
  15568. var target = resolveAlias(getSymbolOfNode(d));
  15569. ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); });
  15570. return result;
  15571. default:
  15572. return 1048576;
  15573. }
  15574. }
  15575. }
  15576. function checkDecorator(node) {
  15577. var expression = node.expression;
  15578. var exprType = checkExpression(expression);
  15579. switch (node.parent.kind) {
  15580. case 202:
  15581. var classSymbol = getSymbolOfNode(node.parent);
  15582. var classConstructorType = getTypeOfSymbol(classSymbol);
  15583. var classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]);
  15584. checkTypeAssignableTo(exprType, classDecoratorType, node);
  15585. break;
  15586. case 133:
  15587. checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node);
  15588. break;
  15589. case 135:
  15590. case 137:
  15591. case 138:
  15592. var methodType = getTypeOfNode(node.parent);
  15593. var methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]);
  15594. checkTypeAssignableTo(exprType, methodDecoratorType, node);
  15595. break;
  15596. case 130:
  15597. checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node);
  15598. break;
  15599. }
  15600. }
  15601. function checkTypeNodeAsExpression(node) {
  15602. if (node && node.kind === 142) {
  15603. var type = getTypeFromTypeNode(node);
  15604. var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules;
  15605. if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 | 132 | 258))) {
  15606. return;
  15607. }
  15608. if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) {
  15609. checkExpressionOrQualifiedName(node.typeName);
  15610. }
  15611. }
  15612. }
  15613. function checkTypeAnnotationAsExpression(node) {
  15614. switch (node.kind) {
  15615. case 133:
  15616. checkTypeNodeAsExpression(node.type);
  15617. break;
  15618. case 130:
  15619. checkTypeNodeAsExpression(node.type);
  15620. break;
  15621. case 135:
  15622. checkTypeNodeAsExpression(node.type);
  15623. break;
  15624. case 137:
  15625. checkTypeNodeAsExpression(node.type);
  15626. break;
  15627. case 138:
  15628. checkTypeNodeAsExpression(getSetAccessorTypeAnnotationNode(node));
  15629. break;
  15630. }
  15631. }
  15632. function checkParameterTypeAnnotationsAsExpressions(node) {
  15633. for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
  15634. var parameter = _a[_i];
  15635. checkTypeAnnotationAsExpression(parameter);
  15636. }
  15637. }
  15638. function checkDecorators(node) {
  15639. if (!node.decorators) {
  15640. return;
  15641. }
  15642. if (!ts.nodeCanBeDecorated(node)) {
  15643. return;
  15644. }
  15645. if (!compilerOptions.experimentalDecorators) {
  15646. 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);
  15647. }
  15648. if (compilerOptions.emitDecoratorMetadata) {
  15649. switch (node.kind) {
  15650. case 202:
  15651. var constructor = ts.getFirstConstructorWithBody(node);
  15652. if (constructor) {
  15653. checkParameterTypeAnnotationsAsExpressions(constructor);
  15654. }
  15655. break;
  15656. case 135:
  15657. checkParameterTypeAnnotationsAsExpressions(node);
  15658. case 138:
  15659. case 137:
  15660. case 133:
  15661. case 130:
  15662. checkTypeAnnotationAsExpression(node);
  15663. break;
  15664. }
  15665. }
  15666. emitDecorate = true;
  15667. if (node.kind === 130) {
  15668. emitParam = true;
  15669. }
  15670. ts.forEach(node.decorators, checkDecorator);
  15671. }
  15672. function checkFunctionDeclaration(node) {
  15673. if (produceDiagnostics) {
  15674. checkFunctionLikeDeclaration(node) ||
  15675. checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) ||
  15676. checkGrammarFunctionName(node.name) ||
  15677. checkGrammarForGenerator(node);
  15678. checkCollisionWithCapturedSuperVariable(node, node.name);
  15679. checkCollisionWithCapturedThisVariable(node, node.name);
  15680. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  15681. }
  15682. }
  15683. function checkFunctionLikeDeclaration(node) {
  15684. checkGrammarDeclarationNameInStrictMode(node);
  15685. checkDecorators(node);
  15686. checkSignatureDeclaration(node);
  15687. if (node.name && node.name.kind === 128) {
  15688. checkComputedPropertyName(node.name);
  15689. }
  15690. if (!ts.hasDynamicName(node)) {
  15691. var symbol = getSymbolOfNode(node);
  15692. var localSymbol = node.localSymbol || symbol;
  15693. var firstDeclaration = ts.getDeclarationOfKind(localSymbol, node.kind);
  15694. if (node === firstDeclaration) {
  15695. checkFunctionOrConstructorSymbol(localSymbol);
  15696. }
  15697. if (symbol.parent) {
  15698. if (ts.getDeclarationOfKind(symbol, node.kind) === node) {
  15699. checkFunctionOrConstructorSymbol(symbol);
  15700. }
  15701. }
  15702. }
  15703. checkSourceElement(node.body);
  15704. if (node.type && !isAccessor(node.kind) && !node.asteriskToken) {
  15705. checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
  15706. }
  15707. if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) {
  15708. reportImplicitAnyError(node, anyType);
  15709. }
  15710. }
  15711. function checkBlock(node) {
  15712. if (node.kind === 180) {
  15713. checkGrammarStatementInAmbientContext(node);
  15714. }
  15715. ts.forEach(node.statements, checkSourceElement);
  15716. if (ts.isFunctionBlock(node) || node.kind === 207) {
  15717. checkFunctionExpressionBodies(node);
  15718. }
  15719. }
  15720. function checkCollisionWithArgumentsInGeneratedCode(node) {
  15721. if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) {
  15722. return;
  15723. }
  15724. ts.forEach(node.parameters, function (p) {
  15725. if (p.name && !ts.isBindingPattern(p.name) && p.name.text === argumentsSymbol.name) {
  15726. error(p, ts.Diagnostics.Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters);
  15727. }
  15728. });
  15729. }
  15730. function needCollisionCheckForIdentifier(node, identifier, name) {
  15731. if (!(identifier && identifier.text === name)) {
  15732. return false;
  15733. }
  15734. if (node.kind === 133 ||
  15735. node.kind === 132 ||
  15736. node.kind === 135 ||
  15737. node.kind === 134 ||
  15738. node.kind === 137 ||
  15739. node.kind === 138) {
  15740. return false;
  15741. }
  15742. if (ts.isInAmbientContext(node)) {
  15743. return false;
  15744. }
  15745. var root = getRootDeclaration(node);
  15746. if (root.kind === 130 && ts.nodeIsMissing(root.parent.body)) {
  15747. return false;
  15748. }
  15749. return true;
  15750. }
  15751. function checkCollisionWithCapturedThisVariable(node, name) {
  15752. if (needCollisionCheckForIdentifier(node, name, "_this")) {
  15753. potentialThisCollisions.push(node);
  15754. }
  15755. }
  15756. function checkIfThisIsCapturedInEnclosingScope(node) {
  15757. var current = node;
  15758. while (current) {
  15759. if (getNodeCheckFlags(current) & 4) {
  15760. var isDeclaration_1 = node.kind !== 65;
  15761. if (isDeclaration_1) {
  15762. error(node.name, ts.Diagnostics.Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference);
  15763. }
  15764. else {
  15765. error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference);
  15766. }
  15767. return;
  15768. }
  15769. current = current.parent;
  15770. }
  15771. }
  15772. function checkCollisionWithCapturedSuperVariable(node, name) {
  15773. if (!needCollisionCheckForIdentifier(node, name, "_super")) {
  15774. return;
  15775. }
  15776. var enclosingClass = ts.getAncestor(node, 202);
  15777. if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) {
  15778. return;
  15779. }
  15780. if (ts.getClassExtendsHeritageClauseElement(enclosingClass)) {
  15781. var isDeclaration_2 = node.kind !== 65;
  15782. if (isDeclaration_2) {
  15783. error(node, ts.Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference);
  15784. }
  15785. else {
  15786. error(node, ts.Diagnostics.Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference);
  15787. }
  15788. }
  15789. }
  15790. function checkCollisionWithRequireExportsInGeneratedCode(node, name) {
  15791. if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
  15792. return;
  15793. }
  15794. if (node.kind === 206 && ts.getModuleInstanceState(node) !== 1) {
  15795. return;
  15796. }
  15797. var parent = getDeclarationContainer(node);
  15798. if (parent.kind === 228 && ts.isExternalModule(parent)) {
  15799. error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name));
  15800. }
  15801. }
  15802. function checkVarDeclaredNamesNotShadowed(node) {
  15803. // - ScriptBody : StatementList
  15804. // It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList
  15805. // also occurs in the VarDeclaredNames of StatementList.
  15806. if ((ts.getCombinedNodeFlags(node) & 12288) !== 0 || isParameterDeclaration(node)) {
  15807. return;
  15808. }
  15809. if (node.kind === 199 && !node.initializer) {
  15810. return;
  15811. }
  15812. var symbol = getSymbolOfNode(node);
  15813. if (symbol.flags & 1) {
  15814. var localDeclarationSymbol = resolveName(node, node.name.text, 3, undefined, undefined);
  15815. if (localDeclarationSymbol &&
  15816. localDeclarationSymbol !== symbol &&
  15817. localDeclarationSymbol.flags & 2) {
  15818. if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 12288) {
  15819. var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 200);
  15820. var container = varDeclList.parent.kind === 181 && varDeclList.parent.parent
  15821. ? varDeclList.parent.parent
  15822. : undefined;
  15823. var namesShareScope = container &&
  15824. (container.kind === 180 && ts.isFunctionLike(container.parent) ||
  15825. container.kind === 207 ||
  15826. container.kind === 206 ||
  15827. container.kind === 228);
  15828. if (!namesShareScope) {
  15829. var name_9 = symbolToString(localDeclarationSymbol);
  15830. error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_9, name_9);
  15831. }
  15832. }
  15833. }
  15834. }
  15835. }
  15836. function isParameterDeclaration(node) {
  15837. while (node.kind === 153) {
  15838. node = node.parent.parent;
  15839. }
  15840. return node.kind === 130;
  15841. }
  15842. function checkParameterInitializer(node) {
  15843. if (getRootDeclaration(node).kind !== 130) {
  15844. return;
  15845. }
  15846. var func = ts.getContainingFunction(node);
  15847. visit(node.initializer);
  15848. function visit(n) {
  15849. if (n.kind === 65) {
  15850. var referencedSymbol = getNodeLinks(n).resolvedSymbol;
  15851. if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455) === referencedSymbol) {
  15852. if (referencedSymbol.valueDeclaration.kind === 130) {
  15853. if (referencedSymbol.valueDeclaration === node) {
  15854. error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name));
  15855. return;
  15856. }
  15857. if (referencedSymbol.valueDeclaration.pos < node.pos) {
  15858. return;
  15859. }
  15860. }
  15861. error(n, ts.Diagnostics.Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(node.name), ts.declarationNameToString(n));
  15862. }
  15863. }
  15864. else {
  15865. ts.forEachChild(n, visit);
  15866. }
  15867. }
  15868. }
  15869. function checkVariableLikeDeclaration(node) {
  15870. checkGrammarDeclarationNameInStrictMode(node);
  15871. checkDecorators(node);
  15872. checkSourceElement(node.type);
  15873. if (node.name.kind === 128) {
  15874. checkComputedPropertyName(node.name);
  15875. if (node.initializer) {
  15876. checkExpressionCached(node.initializer);
  15877. }
  15878. }
  15879. if (ts.isBindingPattern(node.name)) {
  15880. ts.forEach(node.name.elements, checkSourceElement);
  15881. }
  15882. if (node.initializer && getRootDeclaration(node).kind === 130 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
  15883. error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
  15884. return;
  15885. }
  15886. if (ts.isBindingPattern(node.name)) {
  15887. if (node.initializer) {
  15888. checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, undefined);
  15889. checkParameterInitializer(node);
  15890. }
  15891. return;
  15892. }
  15893. var symbol = getSymbolOfNode(node);
  15894. var type = getTypeOfVariableOrParameterOrProperty(symbol);
  15895. if (node === symbol.valueDeclaration) {
  15896. if (node.initializer) {
  15897. checkTypeAssignableTo(checkExpressionCached(node.initializer), type, node, undefined);
  15898. checkParameterInitializer(node);
  15899. }
  15900. }
  15901. else {
  15902. var declarationType = getWidenedTypeForVariableLikeDeclaration(node);
  15903. if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) {
  15904. 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));
  15905. }
  15906. if (node.initializer) {
  15907. checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined);
  15908. }
  15909. }
  15910. if (node.kind !== 133 && node.kind !== 132) {
  15911. checkExportsOnMergedDeclarations(node);
  15912. if (node.kind === 199 || node.kind === 153) {
  15913. checkVarDeclaredNamesNotShadowed(node);
  15914. }
  15915. checkCollisionWithCapturedSuperVariable(node, node.name);
  15916. checkCollisionWithCapturedThisVariable(node, node.name);
  15917. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  15918. }
  15919. }
  15920. function checkVariableDeclaration(node) {
  15921. checkGrammarVariableDeclaration(node);
  15922. return checkVariableLikeDeclaration(node);
  15923. }
  15924. function checkBindingElement(node) {
  15925. checkGrammarBindingElement(node);
  15926. return checkVariableLikeDeclaration(node);
  15927. }
  15928. function checkVariableStatement(node) {
  15929. checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node);
  15930. ts.forEach(node.declarationList.declarations, checkSourceElement);
  15931. }
  15932. function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) {
  15933. if (node.modifiers) {
  15934. if (inBlockOrObjectLiteralExpression(node)) {
  15935. return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
  15936. }
  15937. }
  15938. }
  15939. function inBlockOrObjectLiteralExpression(node) {
  15940. while (node) {
  15941. if (node.kind === 180 || node.kind === 155) {
  15942. return true;
  15943. }
  15944. node = node.parent;
  15945. }
  15946. }
  15947. function checkExpressionStatement(node) {
  15948. checkGrammarStatementInAmbientContext(node);
  15949. checkExpression(node.expression);
  15950. }
  15951. function checkIfStatement(node) {
  15952. checkGrammarStatementInAmbientContext(node);
  15953. checkExpression(node.expression);
  15954. checkSourceElement(node.thenStatement);
  15955. checkSourceElement(node.elseStatement);
  15956. }
  15957. function checkDoStatement(node) {
  15958. checkGrammarStatementInAmbientContext(node);
  15959. checkSourceElement(node.statement);
  15960. checkExpression(node.expression);
  15961. }
  15962. function checkWhileStatement(node) {
  15963. checkGrammarStatementInAmbientContext(node);
  15964. checkExpression(node.expression);
  15965. checkSourceElement(node.statement);
  15966. }
  15967. function checkForStatement(node) {
  15968. if (!checkGrammarStatementInAmbientContext(node)) {
  15969. if (node.initializer && node.initializer.kind == 200) {
  15970. checkGrammarVariableDeclarationList(node.initializer);
  15971. }
  15972. }
  15973. if (node.initializer) {
  15974. if (node.initializer.kind === 200) {
  15975. ts.forEach(node.initializer.declarations, checkVariableDeclaration);
  15976. }
  15977. else {
  15978. checkExpression(node.initializer);
  15979. }
  15980. }
  15981. if (node.condition)
  15982. checkExpression(node.condition);
  15983. if (node.incrementor)
  15984. checkExpression(node.incrementor);
  15985. checkSourceElement(node.statement);
  15986. }
  15987. function checkForOfStatement(node) {
  15988. checkGrammarForInOrForOfStatement(node);
  15989. if (node.initializer.kind === 200) {
  15990. checkForInOrForOfVariableDeclaration(node);
  15991. }
  15992. else {
  15993. var varExpr = node.initializer;
  15994. var iteratedType = checkRightHandSideOfForOf(node.expression);
  15995. if (varExpr.kind === 154 || varExpr.kind === 155) {
  15996. checkDestructuringAssignment(varExpr, iteratedType || unknownType);
  15997. }
  15998. else {
  15999. var leftType = checkExpression(varExpr);
  16000. 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);
  16001. if (iteratedType) {
  16002. checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined);
  16003. }
  16004. }
  16005. }
  16006. checkSourceElement(node.statement);
  16007. }
  16008. function checkForInStatement(node) {
  16009. checkGrammarForInOrForOfStatement(node);
  16010. if (node.initializer.kind === 200) {
  16011. var variable = node.initializer.declarations[0];
  16012. if (variable && ts.isBindingPattern(variable.name)) {
  16013. error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern);
  16014. }
  16015. checkForInOrForOfVariableDeclaration(node);
  16016. }
  16017. else {
  16018. var varExpr = node.initializer;
  16019. var leftType = checkExpression(varExpr);
  16020. if (varExpr.kind === 154 || varExpr.kind === 155) {
  16021. error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern);
  16022. }
  16023. else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) {
  16024. error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any);
  16025. }
  16026. else {
  16027. 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);
  16028. }
  16029. }
  16030. var rightType = checkExpression(node.expression);
  16031. if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) {
  16032. 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);
  16033. }
  16034. checkSourceElement(node.statement);
  16035. }
  16036. function checkForInOrForOfVariableDeclaration(iterationStatement) {
  16037. var variableDeclarationList = iterationStatement.initializer;
  16038. if (variableDeclarationList.declarations.length >= 1) {
  16039. var decl = variableDeclarationList.declarations[0];
  16040. checkVariableDeclaration(decl);
  16041. }
  16042. }
  16043. function checkRightHandSideOfForOf(rhsExpression) {
  16044. var expressionType = getTypeOfExpression(rhsExpression);
  16045. return checkIteratedTypeOrElementType(expressionType, rhsExpression, true);
  16046. }
  16047. function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) {
  16048. if (inputType.flags & 1) {
  16049. return inputType;
  16050. }
  16051. if (languageVersion >= 2) {
  16052. return checkIteratedType(inputType, errorNode) || anyType;
  16053. }
  16054. if (allowStringInput) {
  16055. return checkElementTypeOfArrayOrString(inputType, errorNode);
  16056. }
  16057. if (isArrayLikeType(inputType)) {
  16058. var indexType = getIndexTypeOfType(inputType, 1);
  16059. if (indexType) {
  16060. return indexType;
  16061. }
  16062. }
  16063. error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType));
  16064. return unknownType;
  16065. }
  16066. function checkIteratedType(iterable, errorNode) {
  16067. ts.Debug.assert(languageVersion >= 2);
  16068. var iteratedType = getIteratedType(iterable, errorNode);
  16069. if (errorNode && iteratedType) {
  16070. checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode);
  16071. }
  16072. return iteratedType;
  16073. function getIteratedType(iterable, errorNode) {
  16074. // We want to treat type as an iterable, and get the type it is an iterable of. The iterable
  16075. // must have the following structure (annotated with the names of the variables below):
  16076. //
  16077. // { // iterable
  16078. // [Symbol.iterator]: { // iteratorFunction
  16079. // (): { // iterator
  16080. // next: { // iteratorNextFunction
  16081. // (): { // iteratorNextResult
  16082. // value: T // iteratorNextValue
  16083. // }
  16084. // }
  16085. // }
  16086. // }
  16087. // }
  16088. //
  16089. // T is the type we are after. At every level that involves analyzing return types
  16090. // of signatures, we union the return types of all the signatures.
  16091. //
  16092. // Another thing to note is that at any step of this process, we could run into a dead end,
  16093. // meaning either the property is missing, or we run into the anyType. If either of these things
  16094. // happens, we return undefined to signal that we could not find the iterated type. If a property
  16095. // is missing, and the previous step did not result in 'any', then we also give an error if the
  16096. // caller requested it. Then the caller can decide what to do in the case where there is no iterated
  16097. // type. This is different from returning anyType, because that would signify that we have matched the
  16098. // whole pattern and that T (above) is 'any'.
  16099. if (allConstituentTypesHaveKind(iterable, 1)) {
  16100. return undefined;
  16101. }
  16102. if ((iterable.flags & 4096) && iterable.target === globalIterableType) {
  16103. return iterable.typeArguments[0];
  16104. }
  16105. var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator"));
  16106. if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1)) {
  16107. return undefined;
  16108. }
  16109. var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray;
  16110. if (iteratorFunctionSignatures.length === 0) {
  16111. if (errorNode) {
  16112. error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
  16113. }
  16114. return undefined;
  16115. }
  16116. var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature));
  16117. if (allConstituentTypesHaveKind(iterator, 1)) {
  16118. return undefined;
  16119. }
  16120. var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next");
  16121. if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1)) {
  16122. return undefined;
  16123. }
  16124. var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray;
  16125. if (iteratorNextFunctionSignatures.length === 0) {
  16126. if (errorNode) {
  16127. error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method);
  16128. }
  16129. return undefined;
  16130. }
  16131. var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
  16132. if (allConstituentTypesHaveKind(iteratorNextResult, 1)) {
  16133. return undefined;
  16134. }
  16135. var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
  16136. if (!iteratorNextValue) {
  16137. if (errorNode) {
  16138. error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
  16139. }
  16140. return undefined;
  16141. }
  16142. return iteratorNextValue;
  16143. }
  16144. }
  16145. function checkElementTypeOfArrayOrString(arrayOrStringType, errorNode) {
  16146. ts.Debug.assert(languageVersion < 2);
  16147. var arrayType = removeTypesFromUnionType(arrayOrStringType, 258, true, true);
  16148. var hasStringConstituent = arrayOrStringType !== arrayType;
  16149. var reportedError = false;
  16150. if (hasStringConstituent) {
  16151. if (languageVersion < 1) {
  16152. error(errorNode, ts.Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
  16153. reportedError = true;
  16154. }
  16155. if (arrayType === emptyObjectType) {
  16156. return stringType;
  16157. }
  16158. }
  16159. if (!isArrayLikeType(arrayType)) {
  16160. if (!reportedError) {
  16161. var diagnostic = hasStringConstituent
  16162. ? ts.Diagnostics.Type_0_is_not_an_array_type
  16163. : ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
  16164. error(errorNode, diagnostic, typeToString(arrayType));
  16165. }
  16166. return hasStringConstituent ? stringType : unknownType;
  16167. }
  16168. var arrayElementType = getIndexTypeOfType(arrayType, 1) || unknownType;
  16169. if (hasStringConstituent) {
  16170. if (arrayElementType.flags & 258) {
  16171. return stringType;
  16172. }
  16173. return getUnionType([arrayElementType, stringType]);
  16174. }
  16175. return arrayElementType;
  16176. }
  16177. function checkBreakOrContinueStatement(node) {
  16178. checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node);
  16179. }
  16180. function isGetAccessorWithAnnotatatedSetAccessor(node) {
  16181. return !!(node.kind === 137 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 138)));
  16182. }
  16183. function checkReturnStatement(node) {
  16184. if (!checkGrammarStatementInAmbientContext(node)) {
  16185. var functionBlock = ts.getContainingFunction(node);
  16186. if (!functionBlock) {
  16187. grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
  16188. }
  16189. }
  16190. if (node.expression) {
  16191. var func = ts.getContainingFunction(node);
  16192. if (func) {
  16193. var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func));
  16194. var exprType = checkExpressionCached(node.expression);
  16195. if (func.kind === 138) {
  16196. error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value);
  16197. }
  16198. else {
  16199. if (func.kind === 136) {
  16200. if (!isTypeAssignableTo(exprType, returnType)) {
  16201. error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
  16202. }
  16203. }
  16204. else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) {
  16205. checkTypeAssignableTo(exprType, returnType, node.expression, undefined);
  16206. }
  16207. }
  16208. }
  16209. }
  16210. }
  16211. function checkWithStatement(node) {
  16212. if (!checkGrammarStatementInAmbientContext(node)) {
  16213. if (node.parserContextFlags & 1) {
  16214. grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
  16215. }
  16216. }
  16217. checkExpression(node.expression);
  16218. error(node.expression, ts.Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
  16219. }
  16220. function checkSwitchStatement(node) {
  16221. checkGrammarStatementInAmbientContext(node);
  16222. var firstDefaultClause;
  16223. var hasDuplicateDefaultClause = false;
  16224. var expressionType = checkExpression(node.expression);
  16225. ts.forEach(node.caseBlock.clauses, function (clause) {
  16226. if (clause.kind === 222 && !hasDuplicateDefaultClause) {
  16227. if (firstDefaultClause === undefined) {
  16228. firstDefaultClause = clause;
  16229. }
  16230. else {
  16231. var sourceFile = ts.getSourceFileOfNode(node);
  16232. var start = ts.skipTrivia(sourceFile.text, clause.pos);
  16233. var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
  16234. grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
  16235. hasDuplicateDefaultClause = true;
  16236. }
  16237. }
  16238. if (produceDiagnostics && clause.kind === 221) {
  16239. var caseClause = clause;
  16240. var caseType = checkExpression(caseClause.expression);
  16241. if (!isTypeAssignableTo(expressionType, caseType)) {
  16242. checkTypeAssignableTo(caseType, expressionType, caseClause.expression, undefined);
  16243. }
  16244. }
  16245. ts.forEach(clause.statements, checkSourceElement);
  16246. });
  16247. }
  16248. function checkLabeledStatement(node) {
  16249. if (!checkGrammarStatementInAmbientContext(node)) {
  16250. var current = node.parent;
  16251. while (current) {
  16252. if (ts.isFunctionLike(current)) {
  16253. break;
  16254. }
  16255. if (current.kind === 195 && current.label.text === node.label.text) {
  16256. var sourceFile = ts.getSourceFileOfNode(node);
  16257. grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label));
  16258. break;
  16259. }
  16260. current = current.parent;
  16261. }
  16262. }
  16263. checkSourceElement(node.statement);
  16264. }
  16265. function checkThrowStatement(node) {
  16266. if (!checkGrammarStatementInAmbientContext(node)) {
  16267. if (node.expression === undefined) {
  16268. grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here);
  16269. }
  16270. }
  16271. if (node.expression) {
  16272. checkExpression(node.expression);
  16273. }
  16274. }
  16275. function checkTryStatement(node) {
  16276. checkGrammarStatementInAmbientContext(node);
  16277. checkBlock(node.tryBlock);
  16278. var catchClause = node.catchClause;
  16279. if (catchClause) {
  16280. if (catchClause.variableDeclaration) {
  16281. if (catchClause.variableDeclaration.name.kind !== 65) {
  16282. grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier);
  16283. }
  16284. else if (catchClause.variableDeclaration.type) {
  16285. grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation);
  16286. }
  16287. else if (catchClause.variableDeclaration.initializer) {
  16288. grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
  16289. }
  16290. else {
  16291. var identifierName = catchClause.variableDeclaration.name.text;
  16292. var locals = catchClause.block.locals;
  16293. if (locals && ts.hasProperty(locals, identifierName)) {
  16294. var localSymbol = locals[identifierName];
  16295. if (localSymbol && (localSymbol.flags & 2) !== 0) {
  16296. grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
  16297. }
  16298. }
  16299. checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.variableDeclaration.name);
  16300. }
  16301. }
  16302. checkBlock(catchClause.block);
  16303. }
  16304. if (node.finallyBlock) {
  16305. checkBlock(node.finallyBlock);
  16306. }
  16307. }
  16308. function checkIndexConstraints(type) {
  16309. var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1);
  16310. var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, 0);
  16311. var stringIndexType = getIndexTypeOfType(type, 0);
  16312. var numberIndexType = getIndexTypeOfType(type, 1);
  16313. if (stringIndexType || numberIndexType) {
  16314. ts.forEach(getPropertiesOfObjectType(type), function (prop) {
  16315. var propType = getTypeOfSymbol(prop);
  16316. checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0);
  16317. checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1);
  16318. });
  16319. if (type.flags & 1024 && type.symbol.valueDeclaration.kind === 202) {
  16320. var classDeclaration = type.symbol.valueDeclaration;
  16321. for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) {
  16322. var member = _a[_i];
  16323. if (!(member.flags & 128) && ts.hasDynamicName(member)) {
  16324. var propType = getTypeOfSymbol(member.symbol);
  16325. checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, 0);
  16326. checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, 1);
  16327. }
  16328. }
  16329. }
  16330. }
  16331. var errorNode;
  16332. if (stringIndexType && numberIndexType) {
  16333. errorNode = declaredNumberIndexer || declaredStringIndexer;
  16334. if (!errorNode && (type.flags & 2048)) {
  16335. var someBaseTypeHasBothIndexers = ts.forEach(getBaseTypes(type), function (base) { return getIndexTypeOfType(base, 0) && getIndexTypeOfType(base, 1); });
  16336. errorNode = someBaseTypeHasBothIndexers ? undefined : type.symbol.declarations[0];
  16337. }
  16338. }
  16339. if (errorNode && !isTypeAssignableTo(numberIndexType, stringIndexType)) {
  16340. error(errorNode, ts.Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, typeToString(numberIndexType), typeToString(stringIndexType));
  16341. }
  16342. function checkIndexConstraintForProperty(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) {
  16343. if (!indexType) {
  16344. return;
  16345. }
  16346. if (indexKind === 1 && !isNumericName(prop.valueDeclaration.name)) {
  16347. return;
  16348. }
  16349. var errorNode;
  16350. if (prop.valueDeclaration.name.kind === 128 || prop.parent === containingType.symbol) {
  16351. errorNode = prop.valueDeclaration;
  16352. }
  16353. else if (indexDeclaration) {
  16354. errorNode = indexDeclaration;
  16355. }
  16356. else if (containingType.flags & 2048) {
  16357. var someBaseClassHasBothPropertyAndIndexer = ts.forEach(getBaseTypes(containingType), function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); });
  16358. errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0];
  16359. }
  16360. if (errorNode && !isTypeAssignableTo(propertyType, indexType)) {
  16361. var errorMessage = indexKind === 0
  16362. ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2
  16363. : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2;
  16364. error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType));
  16365. }
  16366. }
  16367. }
  16368. function checkTypeNameIsReserved(name, message) {
  16369. switch (name.text) {
  16370. case "any":
  16371. case "number":
  16372. case "boolean":
  16373. case "string":
  16374. case "symbol":
  16375. case "void":
  16376. error(name, message, name.text);
  16377. }
  16378. }
  16379. function checkTypeParameters(typeParameterDeclarations) {
  16380. if (typeParameterDeclarations) {
  16381. for (var i = 0, n = typeParameterDeclarations.length; i < n; i++) {
  16382. var node = typeParameterDeclarations[i];
  16383. checkTypeParameter(node);
  16384. if (produceDiagnostics) {
  16385. for (var j = 0; j < i; j++) {
  16386. if (typeParameterDeclarations[j].symbol === node.symbol) {
  16387. error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name));
  16388. }
  16389. }
  16390. }
  16391. }
  16392. }
  16393. }
  16394. function checkClassExpression(node) {
  16395. grammarErrorOnNode(node, ts.Diagnostics.class_expressions_are_not_currently_supported);
  16396. ts.forEach(node.members, checkSourceElement);
  16397. return unknownType;
  16398. }
  16399. function checkClassDeclaration(node) {
  16400. checkGrammarDeclarationNameInStrictMode(node);
  16401. if (node.parent.kind !== 207 && node.parent.kind !== 228) {
  16402. grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration);
  16403. }
  16404. if (!node.name && !(node.flags & 256)) {
  16405. grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
  16406. }
  16407. checkGrammarClassDeclarationHeritageClauses(node);
  16408. checkDecorators(node);
  16409. if (node.name) {
  16410. checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0);
  16411. checkCollisionWithCapturedThisVariable(node, node.name);
  16412. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  16413. }
  16414. checkTypeParameters(node.typeParameters);
  16415. checkExportsOnMergedDeclarations(node);
  16416. var symbol = getSymbolOfNode(node);
  16417. var type = getDeclaredTypeOfSymbol(symbol);
  16418. var staticType = getTypeOfSymbol(symbol);
  16419. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  16420. if (baseTypeNode) {
  16421. if (!ts.isSupportedExpressionWithTypeArguments(baseTypeNode)) {
  16422. error(baseTypeNode.expression, ts.Diagnostics.Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses);
  16423. }
  16424. emitExtends = emitExtends || !ts.isInAmbientContext(node);
  16425. checkExpressionWithTypeArguments(baseTypeNode);
  16426. }
  16427. var baseTypes = getBaseTypes(type);
  16428. if (baseTypes.length) {
  16429. if (produceDiagnostics) {
  16430. var baseType = baseTypes[0];
  16431. checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
  16432. var staticBaseType = getTypeOfSymbol(baseType.symbol);
  16433. checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
  16434. if (baseType.symbol !== resolveEntityName(baseTypeNode.expression, 107455)) {
  16435. error(baseTypeNode, ts.Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType));
  16436. }
  16437. checkKindsOfPropertyMemberOverrides(type, baseType);
  16438. }
  16439. }
  16440. if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) {
  16441. checkExpressionOrQualifiedName(baseTypeNode.expression);
  16442. }
  16443. var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node);
  16444. if (implementedTypeNodes) {
  16445. ts.forEach(implementedTypeNodes, function (typeRefNode) {
  16446. if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) {
  16447. error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
  16448. }
  16449. checkExpressionWithTypeArguments(typeRefNode);
  16450. if (produceDiagnostics) {
  16451. var t = getTypeFromTypeNode(typeRefNode);
  16452. if (t !== unknownType) {
  16453. var declaredType = (t.flags & 4096) ? t.target : t;
  16454. if (declaredType.flags & (1024 | 2048)) {
  16455. checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1);
  16456. }
  16457. else {
  16458. error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface);
  16459. }
  16460. }
  16461. }
  16462. });
  16463. }
  16464. ts.forEach(node.members, checkSourceElement);
  16465. if (produceDiagnostics) {
  16466. checkIndexConstraints(type);
  16467. checkTypeForDuplicateIndexSignatures(node);
  16468. }
  16469. }
  16470. function getTargetSymbol(s) {
  16471. return s.flags & 16777216 ? getSymbolLinks(s).target : s;
  16472. }
  16473. function checkKindsOfPropertyMemberOverrides(type, baseType) {
  16474. // TypeScript 1.0 spec (April 2014): 8.2.3
  16475. // A derived class inherits all members from its base class it doesn't override.
  16476. // Inheritance means that a derived class implicitly contains all non - overridden members of the base class.
  16477. // Both public and private property members are inherited, but only public property members can be overridden.
  16478. // A property member in a derived class is said to override a property member in a base class
  16479. // when the derived class property member has the same name and kind(instance or static)
  16480. // as the base class property member.
  16481. // The type of an overriding property member must be assignable(section 3.8.4)
  16482. // to the type of the overridden property member, or otherwise a compile - time error occurs.
  16483. // Base class instance member functions can be overridden by derived class instance member functions,
  16484. // but not by other kinds of members.
  16485. // Base class instance member variables and accessors can be overridden by
  16486. // derived class instance member variables and accessors, but not by other kinds of members.
  16487. var baseProperties = getPropertiesOfObjectType(baseType);
  16488. for (var _i = 0; _i < baseProperties.length; _i++) {
  16489. var baseProperty = baseProperties[_i];
  16490. var base = getTargetSymbol(baseProperty);
  16491. if (base.flags & 134217728) {
  16492. continue;
  16493. }
  16494. var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name));
  16495. if (derived) {
  16496. var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base);
  16497. var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived);
  16498. if ((baseDeclarationFlags & 32) || (derivedDeclarationFlags & 32)) {
  16499. continue;
  16500. }
  16501. if ((baseDeclarationFlags & 128) !== (derivedDeclarationFlags & 128)) {
  16502. continue;
  16503. }
  16504. if ((base.flags & derived.flags & 8192) || ((base.flags & 98308) && (derived.flags & 98308))) {
  16505. continue;
  16506. }
  16507. var errorMessage = void 0;
  16508. if (base.flags & 8192) {
  16509. if (derived.flags & 98304) {
  16510. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor;
  16511. }
  16512. else {
  16513. ts.Debug.assert((derived.flags & 4) !== 0);
  16514. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property;
  16515. }
  16516. }
  16517. else if (base.flags & 4) {
  16518. ts.Debug.assert((derived.flags & 8192) !== 0);
  16519. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function;
  16520. }
  16521. else {
  16522. ts.Debug.assert((base.flags & 98304) !== 0);
  16523. ts.Debug.assert((derived.flags & 8192) !== 0);
  16524. errorMessage = ts.Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function;
  16525. }
  16526. error(derived.valueDeclaration.name, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
  16527. }
  16528. }
  16529. }
  16530. function isAccessor(kind) {
  16531. return kind === 137 || kind === 138;
  16532. }
  16533. function areTypeParametersIdentical(list1, list2) {
  16534. if (!list1 && !list2) {
  16535. return true;
  16536. }
  16537. if (!list1 || !list2 || list1.length !== list2.length) {
  16538. return false;
  16539. }
  16540. for (var i = 0, len = list1.length; i < len; i++) {
  16541. var tp1 = list1[i];
  16542. var tp2 = list2[i];
  16543. if (tp1.name.text !== tp2.name.text) {
  16544. return false;
  16545. }
  16546. if (!tp1.constraint && !tp2.constraint) {
  16547. continue;
  16548. }
  16549. if (!tp1.constraint || !tp2.constraint) {
  16550. return false;
  16551. }
  16552. if (!isTypeIdenticalTo(getTypeFromTypeNode(tp1.constraint), getTypeFromTypeNode(tp2.constraint))) {
  16553. return false;
  16554. }
  16555. }
  16556. return true;
  16557. }
  16558. function checkInheritedPropertiesAreIdentical(type, typeNode) {
  16559. var baseTypes = getBaseTypes(type);
  16560. if (baseTypes.length < 2) {
  16561. return true;
  16562. }
  16563. var seen = {};
  16564. ts.forEach(resolveDeclaredMembers(type).declaredProperties, function (p) { seen[p.name] = { prop: p, containingType: type }; });
  16565. var ok = true;
  16566. for (var _i = 0; _i < baseTypes.length; _i++) {
  16567. var base = baseTypes[_i];
  16568. var properties = getPropertiesOfObjectType(base);
  16569. for (var _a = 0; _a < properties.length; _a++) {
  16570. var prop = properties[_a];
  16571. if (!ts.hasProperty(seen, prop.name)) {
  16572. seen[prop.name] = { prop: prop, containingType: base };
  16573. }
  16574. else {
  16575. var existing = seen[prop.name];
  16576. var isInheritedProperty = existing.containingType !== type;
  16577. if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) {
  16578. ok = false;
  16579. var typeName1 = typeToString(existing.containingType);
  16580. var typeName2 = typeToString(base);
  16581. var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2);
  16582. errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
  16583. diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
  16584. }
  16585. }
  16586. }
  16587. }
  16588. return ok;
  16589. }
  16590. function checkInterfaceDeclaration(node) {
  16591. checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node);
  16592. checkTypeParameters(node.typeParameters);
  16593. if (produceDiagnostics) {
  16594. checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
  16595. checkExportsOnMergedDeclarations(node);
  16596. var symbol = getSymbolOfNode(node);
  16597. var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 203);
  16598. if (symbol.declarations.length > 1) {
  16599. if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) {
  16600. error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters);
  16601. }
  16602. }
  16603. if (node === firstInterfaceDecl) {
  16604. var type = getDeclaredTypeOfSymbol(symbol);
  16605. if (checkInheritedPropertiesAreIdentical(type, node.name)) {
  16606. ts.forEach(getBaseTypes(type), function (baseType) {
  16607. checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1);
  16608. });
  16609. checkIndexConstraints(type);
  16610. }
  16611. }
  16612. }
  16613. ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) {
  16614. if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) {
  16615. error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
  16616. }
  16617. checkExpressionWithTypeArguments(heritageElement);
  16618. });
  16619. ts.forEach(node.members, checkSourceElement);
  16620. if (produceDiagnostics) {
  16621. checkTypeForDuplicateIndexSignatures(node);
  16622. }
  16623. }
  16624. function checkTypeAliasDeclaration(node) {
  16625. checkGrammarDecorators(node) || checkGrammarModifiers(node);
  16626. checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_alias_name_cannot_be_0);
  16627. checkSourceElement(node.type);
  16628. }
  16629. function computeEnumMemberValues(node) {
  16630. var nodeLinks = getNodeLinks(node);
  16631. if (!(nodeLinks.flags & 128)) {
  16632. var enumSymbol = getSymbolOfNode(node);
  16633. var enumType = getDeclaredTypeOfSymbol(enumSymbol);
  16634. var autoValue = 0;
  16635. var ambient = ts.isInAmbientContext(node);
  16636. var enumIsConst = ts.isConst(node);
  16637. ts.forEach(node.members, function (member) {
  16638. if (member.name.kind !== 128 && isNumericLiteralName(member.name.text)) {
  16639. error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
  16640. }
  16641. var initializer = member.initializer;
  16642. if (initializer) {
  16643. autoValue = getConstantValueForEnumMemberInitializer(initializer);
  16644. if (autoValue === undefined) {
  16645. if (enumIsConst) {
  16646. error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
  16647. }
  16648. else if (!ambient) {
  16649. checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined);
  16650. }
  16651. }
  16652. else if (enumIsConst) {
  16653. if (isNaN(autoValue)) {
  16654. error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN);
  16655. }
  16656. else if (!isFinite(autoValue)) {
  16657. error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value);
  16658. }
  16659. }
  16660. }
  16661. else if (ambient && !enumIsConst) {
  16662. autoValue = undefined;
  16663. }
  16664. if (autoValue !== undefined) {
  16665. getNodeLinks(member).enumMemberValue = autoValue++;
  16666. }
  16667. });
  16668. nodeLinks.flags |= 128;
  16669. }
  16670. function getConstantValueForEnumMemberInitializer(initializer) {
  16671. return evalConstant(initializer);
  16672. function evalConstant(e) {
  16673. switch (e.kind) {
  16674. case 168:
  16675. var value = evalConstant(e.operand);
  16676. if (value === undefined) {
  16677. return undefined;
  16678. }
  16679. switch (e.operator) {
  16680. case 33: return value;
  16681. case 34: return -value;
  16682. case 47: return ~value;
  16683. }
  16684. return undefined;
  16685. case 170:
  16686. var left = evalConstant(e.left);
  16687. if (left === undefined) {
  16688. return undefined;
  16689. }
  16690. var right = evalConstant(e.right);
  16691. if (right === undefined) {
  16692. return undefined;
  16693. }
  16694. switch (e.operatorToken.kind) {
  16695. case 44: return left | right;
  16696. case 43: return left & right;
  16697. case 41: return left >> right;
  16698. case 42: return left >>> right;
  16699. case 40: return left << right;
  16700. case 45: return left ^ right;
  16701. case 35: return left * right;
  16702. case 36: return left / right;
  16703. case 33: return left + right;
  16704. case 34: return left - right;
  16705. case 37: return left % right;
  16706. }
  16707. return undefined;
  16708. case 7:
  16709. return +e.text;
  16710. case 162:
  16711. return evalConstant(e.expression);
  16712. case 65:
  16713. case 157:
  16714. case 156:
  16715. var member = initializer.parent;
  16716. var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent));
  16717. var enumType;
  16718. var propertyName;
  16719. if (e.kind === 65) {
  16720. enumType = currentType;
  16721. propertyName = e.text;
  16722. }
  16723. else {
  16724. var expression;
  16725. if (e.kind === 157) {
  16726. if (e.argumentExpression === undefined ||
  16727. e.argumentExpression.kind !== 8) {
  16728. return undefined;
  16729. }
  16730. expression = e.expression;
  16731. propertyName = e.argumentExpression.text;
  16732. }
  16733. else {
  16734. expression = e.expression;
  16735. propertyName = e.name.text;
  16736. }
  16737. var current = expression;
  16738. while (current) {
  16739. if (current.kind === 65) {
  16740. break;
  16741. }
  16742. else if (current.kind === 156) {
  16743. current = current.expression;
  16744. }
  16745. else {
  16746. return undefined;
  16747. }
  16748. }
  16749. enumType = checkExpression(expression);
  16750. if (!(enumType.symbol && (enumType.symbol.flags & 384))) {
  16751. return undefined;
  16752. }
  16753. }
  16754. if (propertyName === undefined) {
  16755. return undefined;
  16756. }
  16757. var property = getPropertyOfObjectType(enumType, propertyName);
  16758. if (!property || !(property.flags & 8)) {
  16759. return undefined;
  16760. }
  16761. var propertyDecl = property.valueDeclaration;
  16762. if (member === propertyDecl) {
  16763. return undefined;
  16764. }
  16765. if (!isDefinedBefore(propertyDecl, member)) {
  16766. return undefined;
  16767. }
  16768. return getNodeLinks(propertyDecl).enumMemberValue;
  16769. }
  16770. }
  16771. }
  16772. }
  16773. function checkEnumDeclaration(node) {
  16774. if (!produceDiagnostics) {
  16775. return;
  16776. }
  16777. checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node);
  16778. checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0);
  16779. checkCollisionWithCapturedThisVariable(node, node.name);
  16780. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  16781. checkExportsOnMergedDeclarations(node);
  16782. computeEnumMemberValues(node);
  16783. var enumIsConst = ts.isConst(node);
  16784. if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) {
  16785. error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided);
  16786. }
  16787. var enumSymbol = getSymbolOfNode(node);
  16788. var firstDeclaration = ts.getDeclarationOfKind(enumSymbol, node.kind);
  16789. if (node === firstDeclaration) {
  16790. if (enumSymbol.declarations.length > 1) {
  16791. ts.forEach(enumSymbol.declarations, function (decl) {
  16792. if (ts.isConstEnumDeclaration(decl) !== enumIsConst) {
  16793. error(decl.name, ts.Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
  16794. }
  16795. });
  16796. }
  16797. var seenEnumMissingInitialInitializer = false;
  16798. ts.forEach(enumSymbol.declarations, function (declaration) {
  16799. if (declaration.kind !== 205) {
  16800. return false;
  16801. }
  16802. var enumDeclaration = declaration;
  16803. if (!enumDeclaration.members.length) {
  16804. return false;
  16805. }
  16806. var firstEnumMember = enumDeclaration.members[0];
  16807. if (!firstEnumMember.initializer) {
  16808. if (seenEnumMissingInitialInitializer) {
  16809. error(firstEnumMember.name, ts.Diagnostics.In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element);
  16810. }
  16811. else {
  16812. seenEnumMissingInitialInitializer = true;
  16813. }
  16814. }
  16815. });
  16816. }
  16817. }
  16818. function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
  16819. var declarations = symbol.declarations;
  16820. for (var _i = 0; _i < declarations.length; _i++) {
  16821. var declaration = declarations[_i];
  16822. if ((declaration.kind === 202 ||
  16823. (declaration.kind === 201 && ts.nodeIsPresent(declaration.body))) &&
  16824. !ts.isInAmbientContext(declaration)) {
  16825. return declaration;
  16826. }
  16827. }
  16828. return undefined;
  16829. }
  16830. function inSameLexicalScope(node1, node2) {
  16831. var container1 = ts.getEnclosingBlockScopeContainer(node1);
  16832. var container2 = ts.getEnclosingBlockScopeContainer(node2);
  16833. if (isGlobalSourceFile(container1)) {
  16834. return isGlobalSourceFile(container2);
  16835. }
  16836. else if (isGlobalSourceFile(container2)) {
  16837. return false;
  16838. }
  16839. else {
  16840. return container1 === container2;
  16841. }
  16842. }
  16843. function checkModuleDeclaration(node) {
  16844. if (produceDiagnostics) {
  16845. if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) {
  16846. if (!ts.isInAmbientContext(node) && node.name.kind === 8) {
  16847. grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
  16848. }
  16849. }
  16850. checkCollisionWithCapturedThisVariable(node, node.name);
  16851. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  16852. checkExportsOnMergedDeclarations(node);
  16853. var symbol = getSymbolOfNode(node);
  16854. if (symbol.flags & 512
  16855. && symbol.declarations.length > 1
  16856. && !ts.isInAmbientContext(node)
  16857. && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) {
  16858. var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
  16859. if (firstNonAmbientClassOrFunc) {
  16860. if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) {
  16861. error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged);
  16862. }
  16863. else if (node.pos < firstNonAmbientClassOrFunc.pos) {
  16864. error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged);
  16865. }
  16866. }
  16867. var mergedClass = ts.getDeclarationOfKind(symbol, 202);
  16868. if (mergedClass &&
  16869. inSameLexicalScope(node, mergedClass)) {
  16870. getNodeLinks(node).flags |= 2048;
  16871. }
  16872. }
  16873. if (node.name.kind === 8) {
  16874. if (!isGlobalSourceFile(node.parent)) {
  16875. error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules);
  16876. }
  16877. if (isExternalModuleNameRelative(node.name.text)) {
  16878. error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name);
  16879. }
  16880. }
  16881. }
  16882. checkSourceElement(node.body);
  16883. }
  16884. function getFirstIdentifier(node) {
  16885. while (true) {
  16886. if (node.kind === 127) {
  16887. node = node.left;
  16888. }
  16889. else if (node.kind === 156) {
  16890. node = node.expression;
  16891. }
  16892. else {
  16893. break;
  16894. }
  16895. }
  16896. ts.Debug.assert(node.kind === 65);
  16897. return node;
  16898. }
  16899. function checkExternalImportOrExportDeclaration(node) {
  16900. var moduleName = ts.getExternalModuleName(node);
  16901. if (!ts.nodeIsMissing(moduleName) && moduleName.kind !== 8) {
  16902. error(moduleName, ts.Diagnostics.String_literal_expected);
  16903. return false;
  16904. }
  16905. var inAmbientExternalModule = node.parent.kind === 207 && node.parent.parent.name.kind === 8;
  16906. if (node.parent.kind !== 228 && !inAmbientExternalModule) {
  16907. error(moduleName, node.kind === 216 ?
  16908. ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace :
  16909. ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module);
  16910. return false;
  16911. }
  16912. if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) {
  16913. error(node, ts.Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name);
  16914. return false;
  16915. }
  16916. return true;
  16917. }
  16918. function checkAliasSymbol(node) {
  16919. var symbol = getSymbolOfNode(node);
  16920. var target = resolveAlias(symbol);
  16921. if (target !== unknownSymbol) {
  16922. var excludedMeanings = (symbol.flags & 107455 ? 107455 : 0) |
  16923. (symbol.flags & 793056 ? 793056 : 0) |
  16924. (symbol.flags & 1536 ? 1536 : 0);
  16925. if (target.flags & excludedMeanings) {
  16926. var message = node.kind === 218 ?
  16927. ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
  16928. ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
  16929. error(node, message, symbolToString(symbol));
  16930. }
  16931. }
  16932. }
  16933. function checkImportBinding(node) {
  16934. checkCollisionWithCapturedThisVariable(node, node.name);
  16935. checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
  16936. checkAliasSymbol(node);
  16937. }
  16938. function checkImportDeclaration(node) {
  16939. if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499)) {
  16940. grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers);
  16941. }
  16942. if (checkExternalImportOrExportDeclaration(node)) {
  16943. var importClause = node.importClause;
  16944. if (importClause) {
  16945. if (importClause.name) {
  16946. checkImportBinding(importClause);
  16947. }
  16948. if (importClause.namedBindings) {
  16949. if (importClause.namedBindings.kind === 212) {
  16950. checkImportBinding(importClause.namedBindings);
  16951. }
  16952. else {
  16953. ts.forEach(importClause.namedBindings.elements, checkImportBinding);
  16954. }
  16955. }
  16956. }
  16957. }
  16958. }
  16959. function checkImportEqualsDeclaration(node) {
  16960. checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node);
  16961. if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
  16962. checkImportBinding(node);
  16963. if (node.flags & 1) {
  16964. markExportAsReferenced(node);
  16965. }
  16966. if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  16967. var target = resolveAlias(getSymbolOfNode(node));
  16968. if (target !== unknownSymbol) {
  16969. if (target.flags & 107455) {
  16970. var moduleName = getFirstIdentifier(node.moduleReference);
  16971. if (!(resolveEntityName(moduleName, 107455 | 1536).flags & 1536)) {
  16972. error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName));
  16973. }
  16974. }
  16975. if (target.flags & 793056) {
  16976. checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0);
  16977. }
  16978. }
  16979. }
  16980. else {
  16981. if (languageVersion >= 2) {
  16982. 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);
  16983. }
  16984. }
  16985. }
  16986. }
  16987. function checkExportDeclaration(node) {
  16988. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499)) {
  16989. grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers);
  16990. }
  16991. if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) {
  16992. if (node.exportClause) {
  16993. ts.forEach(node.exportClause.elements, checkExportSpecifier);
  16994. var inAmbientExternalModule = node.parent.kind === 207 && node.parent.parent.name.kind === 8;
  16995. if (node.parent.kind !== 228 && !inAmbientExternalModule) {
  16996. error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
  16997. }
  16998. }
  16999. else {
  17000. var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
  17001. if (moduleSymbol && moduleSymbol.exports["export="]) {
  17002. error(node.moduleSpecifier, ts.Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
  17003. }
  17004. }
  17005. }
  17006. }
  17007. function checkExportSpecifier(node) {
  17008. checkAliasSymbol(node);
  17009. if (!node.parent.parent.moduleSpecifier) {
  17010. markExportAsReferenced(node);
  17011. }
  17012. }
  17013. function checkExportAssignment(node) {
  17014. var container = node.parent.kind === 228 ? node.parent : node.parent.parent;
  17015. if (container.kind === 206 && container.name.kind === 65) {
  17016. error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
  17017. return;
  17018. }
  17019. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499)) {
  17020. grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
  17021. }
  17022. if (node.expression.kind === 65) {
  17023. markExportAsReferenced(node);
  17024. }
  17025. else {
  17026. checkExpressionCached(node.expression);
  17027. }
  17028. checkExternalModuleExports(container);
  17029. if (node.isExportEquals && !ts.isInAmbientContext(node)) {
  17030. if (languageVersion >= 2) {
  17031. grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
  17032. }
  17033. else if (compilerOptions.module === 4) {
  17034. grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
  17035. }
  17036. }
  17037. }
  17038. function getModuleStatements(node) {
  17039. if (node.kind === 228) {
  17040. return node.statements;
  17041. }
  17042. if (node.kind === 206 && node.body.kind === 207) {
  17043. return node.body.statements;
  17044. }
  17045. return emptyArray;
  17046. }
  17047. function hasExportedMembers(moduleSymbol) {
  17048. for (var id in moduleSymbol.exports) {
  17049. if (id !== "export=") {
  17050. return true;
  17051. }
  17052. }
  17053. return false;
  17054. }
  17055. function checkExternalModuleExports(node) {
  17056. var moduleSymbol = getSymbolOfNode(node);
  17057. var links = getSymbolLinks(moduleSymbol);
  17058. if (!links.exportsChecked) {
  17059. var exportEqualsSymbol = moduleSymbol.exports["export="];
  17060. if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) {
  17061. var declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration;
  17062. error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
  17063. }
  17064. links.exportsChecked = true;
  17065. }
  17066. }
  17067. function checkSourceElement(node) {
  17068. if (!node)
  17069. return;
  17070. switch (node.kind) {
  17071. case 129:
  17072. return checkTypeParameter(node);
  17073. case 130:
  17074. return checkParameter(node);
  17075. case 133:
  17076. case 132:
  17077. return checkPropertyDeclaration(node);
  17078. case 143:
  17079. case 144:
  17080. case 139:
  17081. case 140:
  17082. return checkSignatureDeclaration(node);
  17083. case 141:
  17084. return checkSignatureDeclaration(node);
  17085. case 135:
  17086. case 134:
  17087. return checkMethodDeclaration(node);
  17088. case 136:
  17089. return checkConstructorDeclaration(node);
  17090. case 137:
  17091. case 138:
  17092. return checkAccessorDeclaration(node);
  17093. case 142:
  17094. return checkTypeReferenceNode(node);
  17095. case 145:
  17096. return checkTypeQuery(node);
  17097. case 146:
  17098. return checkTypeLiteral(node);
  17099. case 147:
  17100. return checkArrayType(node);
  17101. case 148:
  17102. return checkTupleType(node);
  17103. case 149:
  17104. return checkUnionType(node);
  17105. case 150:
  17106. return checkSourceElement(node.type);
  17107. case 201:
  17108. return checkFunctionDeclaration(node);
  17109. case 180:
  17110. case 207:
  17111. return checkBlock(node);
  17112. case 181:
  17113. return checkVariableStatement(node);
  17114. case 183:
  17115. return checkExpressionStatement(node);
  17116. case 184:
  17117. return checkIfStatement(node);
  17118. case 185:
  17119. return checkDoStatement(node);
  17120. case 186:
  17121. return checkWhileStatement(node);
  17122. case 187:
  17123. return checkForStatement(node);
  17124. case 188:
  17125. return checkForInStatement(node);
  17126. case 189:
  17127. return checkForOfStatement(node);
  17128. case 190:
  17129. case 191:
  17130. return checkBreakOrContinueStatement(node);
  17131. case 192:
  17132. return checkReturnStatement(node);
  17133. case 193:
  17134. return checkWithStatement(node);
  17135. case 194:
  17136. return checkSwitchStatement(node);
  17137. case 195:
  17138. return checkLabeledStatement(node);
  17139. case 196:
  17140. return checkThrowStatement(node);
  17141. case 197:
  17142. return checkTryStatement(node);
  17143. case 199:
  17144. return checkVariableDeclaration(node);
  17145. case 153:
  17146. return checkBindingElement(node);
  17147. case 202:
  17148. return checkClassDeclaration(node);
  17149. case 203:
  17150. return checkInterfaceDeclaration(node);
  17151. case 204:
  17152. return checkTypeAliasDeclaration(node);
  17153. case 205:
  17154. return checkEnumDeclaration(node);
  17155. case 206:
  17156. return checkModuleDeclaration(node);
  17157. case 210:
  17158. return checkImportDeclaration(node);
  17159. case 209:
  17160. return checkImportEqualsDeclaration(node);
  17161. case 216:
  17162. return checkExportDeclaration(node);
  17163. case 215:
  17164. return checkExportAssignment(node);
  17165. case 182:
  17166. checkGrammarStatementInAmbientContext(node);
  17167. return;
  17168. case 198:
  17169. checkGrammarStatementInAmbientContext(node);
  17170. return;
  17171. case 219:
  17172. return checkMissingDeclaration(node);
  17173. }
  17174. }
  17175. function checkFunctionExpressionBodies(node) {
  17176. switch (node.kind) {
  17177. case 163:
  17178. case 164:
  17179. ts.forEach(node.parameters, checkFunctionExpressionBodies);
  17180. checkFunctionExpressionOrObjectLiteralMethodBody(node);
  17181. break;
  17182. case 135:
  17183. case 134:
  17184. ts.forEach(node.decorators, checkFunctionExpressionBodies);
  17185. ts.forEach(node.parameters, checkFunctionExpressionBodies);
  17186. if (ts.isObjectLiteralMethod(node)) {
  17187. checkFunctionExpressionOrObjectLiteralMethodBody(node);
  17188. }
  17189. break;
  17190. case 136:
  17191. case 137:
  17192. case 138:
  17193. case 201:
  17194. ts.forEach(node.parameters, checkFunctionExpressionBodies);
  17195. break;
  17196. case 193:
  17197. checkFunctionExpressionBodies(node.expression);
  17198. break;
  17199. case 131:
  17200. case 130:
  17201. case 133:
  17202. case 132:
  17203. case 151:
  17204. case 152:
  17205. case 153:
  17206. case 154:
  17207. case 155:
  17208. case 225:
  17209. case 156:
  17210. case 157:
  17211. case 158:
  17212. case 159:
  17213. case 160:
  17214. case 172:
  17215. case 178:
  17216. case 161:
  17217. case 162:
  17218. case 166:
  17219. case 167:
  17220. case 165:
  17221. case 168:
  17222. case 169:
  17223. case 170:
  17224. case 171:
  17225. case 174:
  17226. case 180:
  17227. case 207:
  17228. case 181:
  17229. case 183:
  17230. case 184:
  17231. case 185:
  17232. case 186:
  17233. case 187:
  17234. case 188:
  17235. case 189:
  17236. case 190:
  17237. case 191:
  17238. case 192:
  17239. case 194:
  17240. case 208:
  17241. case 221:
  17242. case 222:
  17243. case 195:
  17244. case 196:
  17245. case 197:
  17246. case 224:
  17247. case 199:
  17248. case 200:
  17249. case 202:
  17250. case 205:
  17251. case 227:
  17252. case 215:
  17253. case 228:
  17254. ts.forEachChild(node, checkFunctionExpressionBodies);
  17255. break;
  17256. }
  17257. }
  17258. function checkSourceFile(node) {
  17259. var start = new Date().getTime();
  17260. checkSourceFileWorker(node);
  17261. ts.checkTime += new Date().getTime() - start;
  17262. }
  17263. function checkSourceFileWorker(node) {
  17264. var links = getNodeLinks(node);
  17265. if (!(links.flags & 1)) {
  17266. checkGrammarSourceFile(node);
  17267. emitExtends = false;
  17268. emitDecorate = false;
  17269. emitParam = false;
  17270. potentialThisCollisions.length = 0;
  17271. ts.forEach(node.statements, checkSourceElement);
  17272. checkFunctionExpressionBodies(node);
  17273. if (ts.isExternalModule(node)) {
  17274. checkExternalModuleExports(node);
  17275. }
  17276. if (potentialThisCollisions.length) {
  17277. ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope);
  17278. potentialThisCollisions.length = 0;
  17279. }
  17280. if (emitExtends) {
  17281. links.flags |= 8;
  17282. }
  17283. if (emitDecorate) {
  17284. links.flags |= 512;
  17285. }
  17286. if (emitParam) {
  17287. links.flags |= 1024;
  17288. }
  17289. links.flags |= 1;
  17290. }
  17291. }
  17292. function getDiagnostics(sourceFile) {
  17293. throwIfNonDiagnosticsProducing();
  17294. if (sourceFile) {
  17295. checkSourceFile(sourceFile);
  17296. return diagnostics.getDiagnostics(sourceFile.fileName);
  17297. }
  17298. ts.forEach(host.getSourceFiles(), checkSourceFile);
  17299. return diagnostics.getDiagnostics();
  17300. }
  17301. function getGlobalDiagnostics() {
  17302. throwIfNonDiagnosticsProducing();
  17303. return diagnostics.getGlobalDiagnostics();
  17304. }
  17305. function throwIfNonDiagnosticsProducing() {
  17306. if (!produceDiagnostics) {
  17307. throw new Error("Trying to get diagnostics from a type checker that does not produce them.");
  17308. }
  17309. }
  17310. function isInsideWithStatementBody(node) {
  17311. if (node) {
  17312. while (node.parent) {
  17313. if (node.parent.kind === 193 && node.parent.statement === node) {
  17314. return true;
  17315. }
  17316. node = node.parent;
  17317. }
  17318. }
  17319. return false;
  17320. }
  17321. function getSymbolsInScope(location, meaning) {
  17322. var symbols = {};
  17323. var memberFlags = 0;
  17324. if (isInsideWithStatementBody(location)) {
  17325. return [];
  17326. }
  17327. populateSymbols();
  17328. return symbolsToArray(symbols);
  17329. function populateSymbols() {
  17330. while (location) {
  17331. if (location.locals && !isGlobalSourceFile(location)) {
  17332. copySymbols(location.locals, meaning);
  17333. }
  17334. switch (location.kind) {
  17335. case 228:
  17336. if (!ts.isExternalModule(location)) {
  17337. break;
  17338. }
  17339. case 206:
  17340. copySymbols(getSymbolOfNode(location).exports, meaning & 8914931);
  17341. break;
  17342. case 205:
  17343. copySymbols(getSymbolOfNode(location).exports, meaning & 8);
  17344. break;
  17345. case 202:
  17346. case 203:
  17347. if (!(memberFlags & 128)) {
  17348. copySymbols(getSymbolOfNode(location).members, meaning & 793056);
  17349. }
  17350. break;
  17351. case 163:
  17352. if (location.name) {
  17353. copySymbol(location.symbol, meaning);
  17354. }
  17355. break;
  17356. }
  17357. memberFlags = location.flags;
  17358. location = location.parent;
  17359. }
  17360. copySymbols(globals, meaning);
  17361. }
  17362. function copySymbol(symbol, meaning) {
  17363. if (symbol.flags & meaning) {
  17364. var id = symbol.name;
  17365. if (!isReservedMemberName(id) && !ts.hasProperty(symbols, id)) {
  17366. symbols[id] = symbol;
  17367. }
  17368. }
  17369. }
  17370. function copySymbols(source, meaning) {
  17371. if (meaning) {
  17372. for (var id in source) {
  17373. if (ts.hasProperty(source, id)) {
  17374. copySymbol(source[id], meaning);
  17375. }
  17376. }
  17377. }
  17378. }
  17379. if (isInsideWithStatementBody(location)) {
  17380. return [];
  17381. }
  17382. while (location) {
  17383. if (location.locals && !isGlobalSourceFile(location)) {
  17384. copySymbols(location.locals, meaning);
  17385. }
  17386. switch (location.kind) {
  17387. case 228:
  17388. if (!ts.isExternalModule(location))
  17389. break;
  17390. case 206:
  17391. copySymbols(getSymbolOfNode(location).exports, meaning & 8914931);
  17392. break;
  17393. case 205:
  17394. copySymbols(getSymbolOfNode(location).exports, meaning & 8);
  17395. break;
  17396. case 202:
  17397. case 203:
  17398. if (!(memberFlags & 128)) {
  17399. copySymbols(getSymbolOfNode(location).members, meaning & 793056);
  17400. }
  17401. break;
  17402. case 163:
  17403. if (location.name) {
  17404. copySymbol(location.symbol, meaning);
  17405. }
  17406. break;
  17407. }
  17408. memberFlags = location.flags;
  17409. location = location.parent;
  17410. }
  17411. copySymbols(globals, meaning);
  17412. return symbolsToArray(symbols);
  17413. }
  17414. function isTypeDeclarationName(name) {
  17415. return name.kind == 65 &&
  17416. isTypeDeclaration(name.parent) &&
  17417. name.parent.name === name;
  17418. }
  17419. function isTypeDeclaration(node) {
  17420. switch (node.kind) {
  17421. case 129:
  17422. case 202:
  17423. case 203:
  17424. case 204:
  17425. case 205:
  17426. return true;
  17427. }
  17428. }
  17429. function isTypeReferenceIdentifier(entityName) {
  17430. var node = entityName;
  17431. while (node.parent && node.parent.kind === 127) {
  17432. node = node.parent;
  17433. }
  17434. return node.parent && node.parent.kind === 142;
  17435. }
  17436. function isHeritageClauseElementIdentifier(entityName) {
  17437. var node = entityName;
  17438. while (node.parent && node.parent.kind === 156) {
  17439. node = node.parent;
  17440. }
  17441. return node.parent && node.parent.kind === 177;
  17442. }
  17443. function isTypeNode(node) {
  17444. if (142 <= node.kind && node.kind <= 150) {
  17445. return true;
  17446. }
  17447. switch (node.kind) {
  17448. case 112:
  17449. case 120:
  17450. case 122:
  17451. case 113:
  17452. case 123:
  17453. return true;
  17454. case 99:
  17455. return node.parent.kind !== 167;
  17456. case 8:
  17457. return node.parent.kind === 130;
  17458. case 177:
  17459. return true;
  17460. case 65:
  17461. if (node.parent.kind === 127 && node.parent.right === node) {
  17462. node = node.parent;
  17463. }
  17464. else if (node.parent.kind === 156 && node.parent.name === node) {
  17465. node = node.parent;
  17466. }
  17467. case 127:
  17468. case 156:
  17469. ts.Debug.assert(node.kind === 65 || node.kind === 127 || node.kind === 156, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'.");
  17470. var parent_5 = node.parent;
  17471. if (parent_5.kind === 145) {
  17472. return false;
  17473. }
  17474. if (142 <= parent_5.kind && parent_5.kind <= 150) {
  17475. return true;
  17476. }
  17477. switch (parent_5.kind) {
  17478. case 177:
  17479. return true;
  17480. case 129:
  17481. return node === parent_5.constraint;
  17482. case 133:
  17483. case 132:
  17484. case 130:
  17485. case 199:
  17486. return node === parent_5.type;
  17487. case 201:
  17488. case 163:
  17489. case 164:
  17490. case 136:
  17491. case 135:
  17492. case 134:
  17493. case 137:
  17494. case 138:
  17495. return node === parent_5.type;
  17496. case 139:
  17497. case 140:
  17498. case 141:
  17499. return node === parent_5.type;
  17500. case 161:
  17501. return node === parent_5.type;
  17502. case 158:
  17503. case 159:
  17504. return parent_5.typeArguments && ts.indexOf(parent_5.typeArguments, node) >= 0;
  17505. case 160:
  17506. return false;
  17507. }
  17508. }
  17509. return false;
  17510. }
  17511. function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) {
  17512. while (nodeOnRightSide.parent.kind === 127) {
  17513. nodeOnRightSide = nodeOnRightSide.parent;
  17514. }
  17515. if (nodeOnRightSide.parent.kind === 209) {
  17516. return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent;
  17517. }
  17518. if (nodeOnRightSide.parent.kind === 215) {
  17519. return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent;
  17520. }
  17521. return undefined;
  17522. }
  17523. function isInRightSideOfImportOrExportAssignment(node) {
  17524. return getLeftSideOfImportEqualsOrExportAssignment(node) !== undefined;
  17525. }
  17526. function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) {
  17527. if (ts.isDeclarationName(entityName)) {
  17528. return getSymbolOfNode(entityName.parent);
  17529. }
  17530. if (entityName.parent.kind === 215) {
  17531. return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608);
  17532. }
  17533. if (entityName.kind !== 156) {
  17534. if (isInRightSideOfImportOrExportAssignment(entityName)) {
  17535. return getSymbolOfPartOfRightHandSideOfImportEquals(entityName);
  17536. }
  17537. }
  17538. if (ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
  17539. entityName = entityName.parent;
  17540. }
  17541. if (isHeritageClauseElementIdentifier(entityName)) {
  17542. var meaning = entityName.parent.kind === 177 ? 793056 : 1536;
  17543. meaning |= 8388608;
  17544. return resolveEntityName(entityName, meaning);
  17545. }
  17546. else if (ts.isExpression(entityName)) {
  17547. if (ts.nodeIsMissing(entityName)) {
  17548. return undefined;
  17549. }
  17550. if (entityName.kind === 65) {
  17551. var meaning = 107455 | 8388608;
  17552. return resolveEntityName(entityName, meaning);
  17553. }
  17554. else if (entityName.kind === 156) {
  17555. var symbol = getNodeLinks(entityName).resolvedSymbol;
  17556. if (!symbol) {
  17557. checkPropertyAccessExpression(entityName);
  17558. }
  17559. return getNodeLinks(entityName).resolvedSymbol;
  17560. }
  17561. else if (entityName.kind === 127) {
  17562. var symbol = getNodeLinks(entityName).resolvedSymbol;
  17563. if (!symbol) {
  17564. checkQualifiedName(entityName);
  17565. }
  17566. return getNodeLinks(entityName).resolvedSymbol;
  17567. }
  17568. }
  17569. else if (isTypeReferenceIdentifier(entityName)) {
  17570. var meaning = entityName.parent.kind === 142 ? 793056 : 1536;
  17571. meaning |= 8388608;
  17572. return resolveEntityName(entityName, meaning);
  17573. }
  17574. return undefined;
  17575. }
  17576. function getSymbolInfo(node) {
  17577. if (isInsideWithStatementBody(node)) {
  17578. return undefined;
  17579. }
  17580. if (ts.isDeclarationName(node)) {
  17581. return getSymbolOfNode(node.parent);
  17582. }
  17583. if (node.kind === 65 && isInRightSideOfImportOrExportAssignment(node)) {
  17584. return node.parent.kind === 215
  17585. ? getSymbolOfEntityNameOrPropertyAccessExpression(node)
  17586. : getSymbolOfPartOfRightHandSideOfImportEquals(node);
  17587. }
  17588. switch (node.kind) {
  17589. case 65:
  17590. case 156:
  17591. case 127:
  17592. return getSymbolOfEntityNameOrPropertyAccessExpression(node);
  17593. case 93:
  17594. case 91:
  17595. var type = checkExpression(node);
  17596. return type.symbol;
  17597. case 114:
  17598. var constructorDeclaration = node.parent;
  17599. if (constructorDeclaration && constructorDeclaration.kind === 136) {
  17600. return constructorDeclaration.parent.symbol;
  17601. }
  17602. return undefined;
  17603. case 8:
  17604. var moduleName;
  17605. if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
  17606. ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
  17607. ((node.parent.kind === 210 || node.parent.kind === 216) &&
  17608. node.parent.moduleSpecifier === node)) {
  17609. return resolveExternalModuleName(node, node);
  17610. }
  17611. case 7:
  17612. if (node.parent.kind == 157 && node.parent.argumentExpression === node) {
  17613. var objectType = checkExpression(node.parent.expression);
  17614. if (objectType === unknownType)
  17615. return undefined;
  17616. var apparentType = getApparentType(objectType);
  17617. if (apparentType === unknownType)
  17618. return undefined;
  17619. return getPropertyOfType(apparentType, node.text);
  17620. }
  17621. break;
  17622. }
  17623. return undefined;
  17624. }
  17625. function getShorthandAssignmentValueSymbol(location) {
  17626. if (location && location.kind === 226) {
  17627. return resolveEntityName(location.name, 107455);
  17628. }
  17629. return undefined;
  17630. }
  17631. function getTypeOfNode(node) {
  17632. if (isInsideWithStatementBody(node)) {
  17633. return unknownType;
  17634. }
  17635. if (isTypeNode(node)) {
  17636. return getTypeFromTypeNode(node);
  17637. }
  17638. if (ts.isExpression(node)) {
  17639. return getTypeOfExpression(node);
  17640. }
  17641. if (isTypeDeclaration(node)) {
  17642. var symbol = getSymbolOfNode(node);
  17643. return getDeclaredTypeOfSymbol(symbol);
  17644. }
  17645. if (isTypeDeclarationName(node)) {
  17646. var symbol = getSymbolInfo(node);
  17647. return symbol && getDeclaredTypeOfSymbol(symbol);
  17648. }
  17649. if (ts.isDeclaration(node)) {
  17650. var symbol = getSymbolOfNode(node);
  17651. return getTypeOfSymbol(symbol);
  17652. }
  17653. if (ts.isDeclarationName(node)) {
  17654. var symbol = getSymbolInfo(node);
  17655. return symbol && getTypeOfSymbol(symbol);
  17656. }
  17657. if (isInRightSideOfImportOrExportAssignment(node)) {
  17658. var symbol = getSymbolInfo(node);
  17659. var declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
  17660. return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
  17661. }
  17662. return unknownType;
  17663. }
  17664. function getTypeOfExpression(expr) {
  17665. if (ts.isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
  17666. expr = expr.parent;
  17667. }
  17668. return checkExpression(expr);
  17669. }
  17670. function getAugmentedPropertiesOfType(type) {
  17671. type = getApparentType(type);
  17672. var propsByName = createSymbolTable(getPropertiesOfType(type));
  17673. if (getSignaturesOfType(type, 0).length || getSignaturesOfType(type, 1).length) {
  17674. ts.forEach(getPropertiesOfType(globalFunctionType), function (p) {
  17675. if (!ts.hasProperty(propsByName, p.name)) {
  17676. propsByName[p.name] = p;
  17677. }
  17678. });
  17679. }
  17680. return getNamedMembers(propsByName);
  17681. }
  17682. function getRootSymbols(symbol) {
  17683. if (symbol.flags & 268435456) {
  17684. var symbols = [];
  17685. var name_10 = symbol.name;
  17686. ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) {
  17687. symbols.push(getPropertyOfType(t, name_10));
  17688. });
  17689. return symbols;
  17690. }
  17691. else if (symbol.flags & 67108864) {
  17692. var target = getSymbolLinks(symbol).target;
  17693. if (target) {
  17694. return [target];
  17695. }
  17696. }
  17697. return [symbol];
  17698. }
  17699. function isExternalModuleSymbol(symbol) {
  17700. return symbol.flags & 512 && symbol.declarations.length === 1 && symbol.declarations[0].kind === 228;
  17701. }
  17702. function getAliasNameSubstitution(symbol, getGeneratedNameForNode) {
  17703. if (languageVersion >= 2) {
  17704. return undefined;
  17705. }
  17706. var node = getDeclarationOfAliasSymbol(symbol);
  17707. if (node) {
  17708. if (node.kind === 211) {
  17709. var defaultKeyword;
  17710. if (languageVersion === 0) {
  17711. defaultKeyword = "[\"default\"]";
  17712. }
  17713. else {
  17714. defaultKeyword = ".default";
  17715. }
  17716. return getGeneratedNameForNode(node.parent) + defaultKeyword;
  17717. }
  17718. if (node.kind === 214) {
  17719. var moduleName = getGeneratedNameForNode(node.parent.parent.parent);
  17720. var propertyName = node.propertyName || node.name;
  17721. return moduleName + "." + ts.unescapeIdentifier(propertyName.text);
  17722. }
  17723. }
  17724. }
  17725. function getExportNameSubstitution(symbol, location, getGeneratedNameForNode) {
  17726. if (isExternalModuleSymbol(symbol.parent)) {
  17727. if (languageVersion >= 2 || compilerOptions.module === 4) {
  17728. return undefined;
  17729. }
  17730. return "exports." + ts.unescapeIdentifier(symbol.name);
  17731. }
  17732. var node = location;
  17733. var containerSymbol = getParentOfSymbol(symbol);
  17734. while (node) {
  17735. if ((node.kind === 206 || node.kind === 205) && getSymbolOfNode(node) === containerSymbol) {
  17736. return getGeneratedNameForNode(node) + "." + ts.unescapeIdentifier(symbol.name);
  17737. }
  17738. node = node.parent;
  17739. }
  17740. }
  17741. function getExpressionNameSubstitution(node, getGeneratedNameForNode) {
  17742. var symbol = getNodeLinks(node).resolvedSymbol || (ts.isDeclarationName(node) ? getSymbolOfNode(node.parent) : undefined);
  17743. if (symbol) {
  17744. if (symbol.parent) {
  17745. return getExportNameSubstitution(symbol, node.parent, getGeneratedNameForNode);
  17746. }
  17747. var exportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
  17748. if (symbol !== exportSymbol && !(exportSymbol.flags & 944)) {
  17749. return getExportNameSubstitution(exportSymbol, node.parent, getGeneratedNameForNode);
  17750. }
  17751. if (symbol.flags & 8388608) {
  17752. return getAliasNameSubstitution(symbol, getGeneratedNameForNode);
  17753. }
  17754. }
  17755. }
  17756. function isValueAliasDeclaration(node) {
  17757. switch (node.kind) {
  17758. case 209:
  17759. case 211:
  17760. case 212:
  17761. case 214:
  17762. case 218:
  17763. return isAliasResolvedToValue(getSymbolOfNode(node));
  17764. case 216:
  17765. var exportClause = node.exportClause;
  17766. return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration);
  17767. case 215:
  17768. return node.expression && node.expression.kind === 65 ? isAliasResolvedToValue(getSymbolOfNode(node)) : true;
  17769. }
  17770. return false;
  17771. }
  17772. function isTopLevelValueImportEqualsWithEntityName(node) {
  17773. if (node.parent.kind !== 228 || !ts.isInternalModuleImportEqualsDeclaration(node)) {
  17774. return false;
  17775. }
  17776. var isValue = isAliasResolvedToValue(getSymbolOfNode(node));
  17777. return isValue && node.moduleReference && !ts.nodeIsMissing(node.moduleReference);
  17778. }
  17779. function isAliasResolvedToValue(symbol) {
  17780. var target = resolveAlias(symbol);
  17781. if (target === unknownSymbol && compilerOptions.isolatedModules) {
  17782. return true;
  17783. }
  17784. return target !== unknownSymbol && target && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target);
  17785. }
  17786. function isConstEnumOrConstEnumOnlyModule(s) {
  17787. return isConstEnumSymbol(s) || s.constEnumOnlyModule;
  17788. }
  17789. function isReferencedAliasDeclaration(node, checkChildren) {
  17790. if (ts.isAliasSymbolDeclaration(node)) {
  17791. var symbol = getSymbolOfNode(node);
  17792. if (getSymbolLinks(symbol).referenced) {
  17793. return true;
  17794. }
  17795. }
  17796. if (checkChildren) {
  17797. return ts.forEachChild(node, function (node) { return isReferencedAliasDeclaration(node, checkChildren); });
  17798. }
  17799. return false;
  17800. }
  17801. function isImplementationOfOverload(node) {
  17802. if (ts.nodeIsPresent(node.body)) {
  17803. var symbol = getSymbolOfNode(node);
  17804. var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
  17805. return signaturesOfSymbol.length > 1 ||
  17806. (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
  17807. }
  17808. return false;
  17809. }
  17810. function getNodeCheckFlags(node) {
  17811. return getNodeLinks(node).flags;
  17812. }
  17813. function getEnumMemberValue(node) {
  17814. computeEnumMemberValues(node.parent);
  17815. return getNodeLinks(node).enumMemberValue;
  17816. }
  17817. function getConstantValue(node) {
  17818. if (node.kind === 227) {
  17819. return getEnumMemberValue(node);
  17820. }
  17821. var symbol = getNodeLinks(node).resolvedSymbol;
  17822. if (symbol && (symbol.flags & 8)) {
  17823. if (ts.isConstEnumDeclaration(symbol.valueDeclaration.parent)) {
  17824. return getEnumMemberValue(symbol.valueDeclaration);
  17825. }
  17826. }
  17827. return undefined;
  17828. }
  17829. function serializeEntityName(node, getGeneratedNameForNode, fallbackPath) {
  17830. if (node.kind === 65) {
  17831. var substitution = getExpressionNameSubstitution(node, getGeneratedNameForNode);
  17832. var text = substitution || node.text;
  17833. if (fallbackPath) {
  17834. fallbackPath.push(text);
  17835. }
  17836. else {
  17837. return text;
  17838. }
  17839. }
  17840. else {
  17841. var left = serializeEntityName(node.left, getGeneratedNameForNode, fallbackPath);
  17842. var right = serializeEntityName(node.right, getGeneratedNameForNode, fallbackPath);
  17843. if (!fallbackPath) {
  17844. return left + "." + right;
  17845. }
  17846. }
  17847. }
  17848. function serializeTypeReferenceNode(node, getGeneratedNameForNode) {
  17849. var type = getTypeFromTypeNode(node);
  17850. if (type.flags & 16) {
  17851. return "void 0";
  17852. }
  17853. else if (type.flags & 8) {
  17854. return "Boolean";
  17855. }
  17856. else if (type.flags & 132) {
  17857. return "Number";
  17858. }
  17859. else if (type.flags & 258) {
  17860. return "String";
  17861. }
  17862. else if (type.flags & 8192) {
  17863. return "Array";
  17864. }
  17865. else if (type.flags & 1048576) {
  17866. return "Symbol";
  17867. }
  17868. else if (type === unknownType) {
  17869. var fallbackPath = [];
  17870. serializeEntityName(node.typeName, getGeneratedNameForNode, fallbackPath);
  17871. return fallbackPath;
  17872. }
  17873. else if (type.symbol && type.symbol.valueDeclaration) {
  17874. return serializeEntityName(node.typeName, getGeneratedNameForNode);
  17875. }
  17876. else if (typeHasCallOrConstructSignatures(type)) {
  17877. return "Function";
  17878. }
  17879. return "Object";
  17880. }
  17881. function serializeTypeNode(node, getGeneratedNameForNode) {
  17882. if (node) {
  17883. switch (node.kind) {
  17884. case 99:
  17885. return "void 0";
  17886. case 150:
  17887. return serializeTypeNode(node.type, getGeneratedNameForNode);
  17888. case 143:
  17889. case 144:
  17890. return "Function";
  17891. case 147:
  17892. case 148:
  17893. return "Array";
  17894. case 113:
  17895. return "Boolean";
  17896. case 122:
  17897. case 8:
  17898. return "String";
  17899. case 120:
  17900. return "Number";
  17901. case 142:
  17902. return serializeTypeReferenceNode(node, getGeneratedNameForNode);
  17903. case 145:
  17904. case 146:
  17905. case 149:
  17906. case 112:
  17907. break;
  17908. default:
  17909. ts.Debug.fail("Cannot serialize unexpected type node.");
  17910. break;
  17911. }
  17912. }
  17913. return "Object";
  17914. }
  17915. function serializeTypeOfNode(node, getGeneratedNameForNode) {
  17916. switch (node.kind) {
  17917. case 202: return "Function";
  17918. case 133: return serializeTypeNode(node.type, getGeneratedNameForNode);
  17919. case 130: return serializeTypeNode(node.type, getGeneratedNameForNode);
  17920. case 137: return serializeTypeNode(node.type, getGeneratedNameForNode);
  17921. case 138: return serializeTypeNode(getSetAccessorTypeAnnotationNode(node), getGeneratedNameForNode);
  17922. }
  17923. if (ts.isFunctionLike(node)) {
  17924. return "Function";
  17925. }
  17926. return "void 0";
  17927. }
  17928. function serializeParameterTypesOfNode(node, getGeneratedNameForNode) {
  17929. if (node) {
  17930. var valueDeclaration;
  17931. if (node.kind === 202) {
  17932. valueDeclaration = ts.getFirstConstructorWithBody(node);
  17933. }
  17934. else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) {
  17935. valueDeclaration = node;
  17936. }
  17937. if (valueDeclaration) {
  17938. var result;
  17939. var parameters = valueDeclaration.parameters;
  17940. var parameterCount = parameters.length;
  17941. if (parameterCount > 0) {
  17942. result = new Array(parameterCount);
  17943. for (var i = 0; i < parameterCount; i++) {
  17944. if (parameters[i].dotDotDotToken) {
  17945. var parameterType = parameters[i].type;
  17946. if (parameterType.kind === 147) {
  17947. parameterType = parameterType.elementType;
  17948. }
  17949. else if (parameterType.kind === 142 && parameterType.typeArguments && parameterType.typeArguments.length === 1) {
  17950. parameterType = parameterType.typeArguments[0];
  17951. }
  17952. else {
  17953. parameterType = undefined;
  17954. }
  17955. result[i] = serializeTypeNode(parameterType, getGeneratedNameForNode);
  17956. }
  17957. else {
  17958. result[i] = serializeTypeOfNode(parameters[i], getGeneratedNameForNode);
  17959. }
  17960. }
  17961. return result;
  17962. }
  17963. }
  17964. }
  17965. return emptyArray;
  17966. }
  17967. function serializeReturnTypeOfNode(node, getGeneratedNameForNode) {
  17968. if (node && ts.isFunctionLike(node)) {
  17969. return serializeTypeNode(node.type, getGeneratedNameForNode);
  17970. }
  17971. return "void 0";
  17972. }
  17973. function writeTypeOfDeclaration(declaration, enclosingDeclaration, flags, writer) {
  17974. var symbol = getSymbolOfNode(declaration);
  17975. var type = symbol && !(symbol.flags & (2048 | 131072))
  17976. ? getTypeOfSymbol(symbol)
  17977. : unknownType;
  17978. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  17979. }
  17980. function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) {
  17981. var signature = getSignatureFromDeclaration(signatureDeclaration);
  17982. getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
  17983. }
  17984. function writeTypeOfExpression(expr, enclosingDeclaration, flags, writer) {
  17985. var type = getTypeOfExpression(expr);
  17986. getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
  17987. }
  17988. function hasGlobalName(name) {
  17989. return ts.hasProperty(globals, name);
  17990. }
  17991. function resolvesToSomeValue(location, name) {
  17992. ts.Debug.assert(!ts.nodeIsSynthesized(location), "resolvesToSomeValue called with a synthesized location");
  17993. return !!resolveName(location, name, 107455, undefined, undefined);
  17994. }
  17995. function getReferencedValueDeclaration(reference) {
  17996. ts.Debug.assert(!ts.nodeIsSynthesized(reference));
  17997. var symbol = getNodeLinks(reference).resolvedSymbol ||
  17998. resolveName(reference, reference.text, 107455 | 8388608, undefined, undefined);
  17999. return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
  18000. }
  18001. function getBlockScopedVariableId(n) {
  18002. ts.Debug.assert(!ts.nodeIsSynthesized(n));
  18003. var isVariableDeclarationOrBindingElement = n.parent.kind === 153 || (n.parent.kind === 199 && n.parent.name === n);
  18004. var symbol = (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) ||
  18005. getNodeLinks(n).resolvedSymbol ||
  18006. resolveName(n, n.text, 107455 | 8388608, undefined, undefined);
  18007. var isLetOrConst = symbol &&
  18008. (symbol.flags & 2) &&
  18009. symbol.valueDeclaration.parent.kind !== 224;
  18010. if (isLetOrConst) {
  18011. getSymbolLinks(symbol);
  18012. return symbol.id;
  18013. }
  18014. return undefined;
  18015. }
  18016. function instantiateSingleCallFunctionType(functionType, typeArguments) {
  18017. if (functionType === unknownType) {
  18018. return unknownType;
  18019. }
  18020. var signature = getSingleCallSignature(functionType);
  18021. if (!signature) {
  18022. return unknownType;
  18023. }
  18024. var instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
  18025. return getOrCreateTypeFromSignature(instantiatedSignature);
  18026. }
  18027. function createResolver() {
  18028. return {
  18029. getExpressionNameSubstitution: getExpressionNameSubstitution,
  18030. isValueAliasDeclaration: isValueAliasDeclaration,
  18031. hasGlobalName: hasGlobalName,
  18032. isReferencedAliasDeclaration: isReferencedAliasDeclaration,
  18033. getNodeCheckFlags: getNodeCheckFlags,
  18034. isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName,
  18035. isDeclarationVisible: isDeclarationVisible,
  18036. isImplementationOfOverload: isImplementationOfOverload,
  18037. writeTypeOfDeclaration: writeTypeOfDeclaration,
  18038. writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration,
  18039. writeTypeOfExpression: writeTypeOfExpression,
  18040. isSymbolAccessible: isSymbolAccessible,
  18041. isEntityNameVisible: isEntityNameVisible,
  18042. getConstantValue: getConstantValue,
  18043. resolvesToSomeValue: resolvesToSomeValue,
  18044. collectLinkedAliases: collectLinkedAliases,
  18045. getBlockScopedVariableId: getBlockScopedVariableId,
  18046. getReferencedValueDeclaration: getReferencedValueDeclaration,
  18047. serializeTypeOfNode: serializeTypeOfNode,
  18048. serializeParameterTypesOfNode: serializeParameterTypesOfNode,
  18049. serializeReturnTypeOfNode: serializeReturnTypeOfNode
  18050. };
  18051. }
  18052. function initializeTypeChecker() {
  18053. ts.forEach(host.getSourceFiles(), function (file) {
  18054. ts.bindSourceFile(file);
  18055. });
  18056. ts.forEach(host.getSourceFiles(), function (file) {
  18057. if (!ts.isExternalModule(file)) {
  18058. mergeSymbolTable(globals, file.locals);
  18059. }
  18060. });
  18061. getSymbolLinks(undefinedSymbol).type = undefinedType;
  18062. getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
  18063. getSymbolLinks(unknownSymbol).type = unknownType;
  18064. globals[undefinedSymbol.name] = undefinedSymbol;
  18065. globalArraySymbol = getGlobalTypeSymbol("Array");
  18066. globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, 1);
  18067. globalObjectType = getGlobalType("Object");
  18068. globalFunctionType = getGlobalType("Function");
  18069. globalStringType = getGlobalType("String");
  18070. globalNumberType = getGlobalType("Number");
  18071. globalBooleanType = getGlobalType("Boolean");
  18072. globalRegExpType = getGlobalType("RegExp");
  18073. getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); });
  18074. getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); });
  18075. getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); });
  18076. getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); });
  18077. if (languageVersion >= 2) {
  18078. globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray");
  18079. globalESSymbolType = getGlobalType("Symbol");
  18080. globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol");
  18081. globalIterableType = getGlobalType("Iterable", 1);
  18082. }
  18083. else {
  18084. globalTemplateStringsArrayType = unknownType;
  18085. globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
  18086. globalESSymbolConstructorSymbol = undefined;
  18087. }
  18088. anyArrayType = createArrayType(anyType);
  18089. }
  18090. function isReservedWordInStrictMode(node) {
  18091. return (node.parserContextFlags & 1) &&
  18092. (102 <= node.originalKeywordKind && node.originalKeywordKind <= 110);
  18093. }
  18094. function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) {
  18095. if (ts.getAncestor(identifier, 202) || ts.getAncestor(identifier, 175)) {
  18096. return grammarErrorOnNode(identifier, message, arg0);
  18097. }
  18098. return false;
  18099. }
  18100. function checkGrammarImportDeclarationNameInStrictMode(node) {
  18101. if (node.importClause) {
  18102. var impotClause = node.importClause;
  18103. if (impotClause.namedBindings) {
  18104. var nameBindings = impotClause.namedBindings;
  18105. if (nameBindings.kind === 212) {
  18106. var name_11 = nameBindings.name;
  18107. if (isReservedWordInStrictMode(name_11)) {
  18108. var nameText = ts.declarationNameToString(name_11);
  18109. return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
  18110. }
  18111. }
  18112. else if (nameBindings.kind === 213) {
  18113. var reportError = false;
  18114. for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) {
  18115. var element = _a[_i];
  18116. var name_12 = element.name;
  18117. if (isReservedWordInStrictMode(name_12)) {
  18118. var nameText = ts.declarationNameToString(name_12);
  18119. reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
  18120. }
  18121. }
  18122. return reportError;
  18123. }
  18124. }
  18125. }
  18126. return false;
  18127. }
  18128. function checkGrammarDeclarationNameInStrictMode(node) {
  18129. var name = node.name;
  18130. if (name && name.kind === 65 && isReservedWordInStrictMode(name)) {
  18131. var nameText = ts.declarationNameToString(name);
  18132. switch (node.kind) {
  18133. case 130:
  18134. case 199:
  18135. case 201:
  18136. case 129:
  18137. case 153:
  18138. case 203:
  18139. case 204:
  18140. case 205:
  18141. return checkGrammarIdentifierInStrictMode(name);
  18142. case 202:
  18143. return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText);
  18144. case 206:
  18145. return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
  18146. case 209:
  18147. return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
  18148. }
  18149. }
  18150. return false;
  18151. }
  18152. function checkGrammarTypeReferenceInStrictMode(typeName) {
  18153. if (typeName.kind === 65) {
  18154. checkGrammarTypeNameInStrictMode(typeName);
  18155. }
  18156. else if (typeName.kind === 127) {
  18157. checkGrammarTypeNameInStrictMode(typeName.right);
  18158. checkGrammarTypeReferenceInStrictMode(typeName.left);
  18159. }
  18160. }
  18161. function checkGrammarExpressionWithTypeArgumentsInStrictMode(expression) {
  18162. if (expression && expression.kind === 65) {
  18163. return checkGrammarIdentifierInStrictMode(expression);
  18164. }
  18165. else if (expression && expression.kind === 156) {
  18166. checkGrammarExpressionWithTypeArgumentsInStrictMode(expression.expression);
  18167. }
  18168. }
  18169. function checkGrammarIdentifierInStrictMode(node, nameText) {
  18170. if (node && node.kind === 65 && isReservedWordInStrictMode(node)) {
  18171. if (!nameText) {
  18172. nameText = ts.declarationNameToString(node);
  18173. }
  18174. var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
  18175. grammarErrorOnNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
  18176. return errorReport;
  18177. }
  18178. return false;
  18179. }
  18180. function checkGrammarTypeNameInStrictMode(node) {
  18181. if (node && node.kind === 65 && isReservedWordInStrictMode(node)) {
  18182. var nameText = ts.declarationNameToString(node);
  18183. var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
  18184. grammarErrorOnNode(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText);
  18185. return errorReport;
  18186. }
  18187. return false;
  18188. }
  18189. function checkGrammarDecorators(node) {
  18190. if (!node.decorators) {
  18191. return false;
  18192. }
  18193. if (!ts.nodeCanBeDecorated(node)) {
  18194. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here);
  18195. }
  18196. else if (languageVersion < 1) {
  18197. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher);
  18198. }
  18199. else if (node.kind === 137 || node.kind === 138) {
  18200. var accessors = ts.getAllAccessorDeclarations(node.parent.members, node);
  18201. if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) {
  18202. return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name);
  18203. }
  18204. }
  18205. return false;
  18206. }
  18207. function checkGrammarModifiers(node) {
  18208. switch (node.kind) {
  18209. case 137:
  18210. case 138:
  18211. case 136:
  18212. case 133:
  18213. case 132:
  18214. case 135:
  18215. case 134:
  18216. case 141:
  18217. case 202:
  18218. case 203:
  18219. case 206:
  18220. case 205:
  18221. case 181:
  18222. case 201:
  18223. case 204:
  18224. case 210:
  18225. case 209:
  18226. case 216:
  18227. case 215:
  18228. case 130:
  18229. break;
  18230. default:
  18231. return false;
  18232. }
  18233. if (!node.modifiers) {
  18234. return;
  18235. }
  18236. var lastStatic, lastPrivate, lastProtected, lastDeclare;
  18237. var flags = 0;
  18238. for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
  18239. var modifier = _a[_i];
  18240. switch (modifier.kind) {
  18241. case 108:
  18242. case 107:
  18243. case 106:
  18244. var text = void 0;
  18245. if (modifier.kind === 108) {
  18246. text = "public";
  18247. }
  18248. else if (modifier.kind === 107) {
  18249. text = "protected";
  18250. lastProtected = modifier;
  18251. }
  18252. else {
  18253. text = "private";
  18254. lastPrivate = modifier;
  18255. }
  18256. if (flags & 112) {
  18257. return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen);
  18258. }
  18259. else if (flags & 128) {
  18260. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static");
  18261. }
  18262. else if (node.parent.kind === 207 || node.parent.kind === 228) {
  18263. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
  18264. }
  18265. flags |= ts.modifierToFlag(modifier.kind);
  18266. break;
  18267. case 109:
  18268. if (flags & 128) {
  18269. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static");
  18270. }
  18271. else if (node.parent.kind === 207 || node.parent.kind === 228) {
  18272. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
  18273. }
  18274. else if (node.kind === 130) {
  18275. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
  18276. }
  18277. flags |= 128;
  18278. lastStatic = modifier;
  18279. break;
  18280. case 78:
  18281. if (flags & 1) {
  18282. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export");
  18283. }
  18284. else if (flags & 2) {
  18285. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
  18286. }
  18287. else if (node.parent.kind === 202) {
  18288. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
  18289. }
  18290. else if (node.kind === 130) {
  18291. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
  18292. }
  18293. flags |= 1;
  18294. break;
  18295. case 115:
  18296. if (flags & 2) {
  18297. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare");
  18298. }
  18299. else if (node.parent.kind === 202) {
  18300. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
  18301. }
  18302. else if (node.kind === 130) {
  18303. return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
  18304. }
  18305. else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 207) {
  18306. return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
  18307. }
  18308. flags |= 2;
  18309. lastDeclare = modifier;
  18310. break;
  18311. }
  18312. }
  18313. if (node.kind === 136) {
  18314. if (flags & 128) {
  18315. return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
  18316. }
  18317. else if (flags & 64) {
  18318. return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
  18319. }
  18320. else if (flags & 32) {
  18321. return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
  18322. }
  18323. }
  18324. else if ((node.kind === 210 || node.kind === 209) && flags & 2) {
  18325. return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare");
  18326. }
  18327. else if (node.kind === 203 && flags & 2) {
  18328. return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare");
  18329. }
  18330. else if (node.kind === 130 && (flags & 112) && ts.isBindingPattern(node.name)) {
  18331. return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
  18332. }
  18333. }
  18334. function checkGrammarForDisallowedTrailingComma(list) {
  18335. if (list && list.hasTrailingComma) {
  18336. var start = list.end - ",".length;
  18337. var end = list.end;
  18338. var sourceFile = ts.getSourceFileOfNode(list[0]);
  18339. return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Trailing_comma_not_allowed);
  18340. }
  18341. }
  18342. function checkGrammarTypeParameterList(node, typeParameters, file) {
  18343. if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
  18344. return true;
  18345. }
  18346. if (typeParameters && typeParameters.length === 0) {
  18347. var start = typeParameters.pos - "<".length;
  18348. var end = ts.skipTrivia(file.text, typeParameters.end) + ">".length;
  18349. return grammarErrorAtPos(file, start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
  18350. }
  18351. }
  18352. function checkGrammarParameterList(parameters) {
  18353. if (checkGrammarForDisallowedTrailingComma(parameters)) {
  18354. return true;
  18355. }
  18356. var seenOptionalParameter = false;
  18357. var parameterCount = parameters.length;
  18358. for (var i = 0; i < parameterCount; i++) {
  18359. var parameter = parameters[i];
  18360. if (parameter.dotDotDotToken) {
  18361. if (i !== (parameterCount - 1)) {
  18362. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
  18363. }
  18364. if (ts.isBindingPattern(parameter.name)) {
  18365. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
  18366. }
  18367. if (parameter.questionToken) {
  18368. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
  18369. }
  18370. if (parameter.initializer) {
  18371. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
  18372. }
  18373. }
  18374. else if (parameter.questionToken || parameter.initializer) {
  18375. seenOptionalParameter = true;
  18376. if (parameter.questionToken && parameter.initializer) {
  18377. return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
  18378. }
  18379. }
  18380. else {
  18381. if (seenOptionalParameter) {
  18382. return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
  18383. }
  18384. }
  18385. }
  18386. }
  18387. function checkGrammarFunctionLikeDeclaration(node) {
  18388. var file = ts.getSourceFileOfNode(node);
  18389. return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
  18390. checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
  18391. }
  18392. function checkGrammarArrowFunction(node, file) {
  18393. if (node.kind === 164) {
  18394. var arrowFunction = node;
  18395. var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line;
  18396. var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line;
  18397. if (startLine !== endLine) {
  18398. return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, ts.Diagnostics.Line_terminator_not_permitted_before_arrow);
  18399. }
  18400. }
  18401. return false;
  18402. }
  18403. function checkGrammarIndexSignatureParameters(node) {
  18404. var parameter = node.parameters[0];
  18405. if (node.parameters.length !== 1) {
  18406. if (parameter) {
  18407. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
  18408. }
  18409. else {
  18410. return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
  18411. }
  18412. }
  18413. if (parameter.dotDotDotToken) {
  18414. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
  18415. }
  18416. if (parameter.flags & 499) {
  18417. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
  18418. }
  18419. if (parameter.questionToken) {
  18420. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
  18421. }
  18422. if (parameter.initializer) {
  18423. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
  18424. }
  18425. if (!parameter.type) {
  18426. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
  18427. }
  18428. if (parameter.type.kind !== 122 && parameter.type.kind !== 120) {
  18429. return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
  18430. }
  18431. if (!node.type) {
  18432. return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
  18433. }
  18434. }
  18435. function checkGrammarForIndexSignatureModifier(node) {
  18436. if (node.flags & 499) {
  18437. grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
  18438. }
  18439. }
  18440. function checkGrammarIndexSignature(node) {
  18441. return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node);
  18442. }
  18443. function checkGrammarForAtLeastOneTypeArgument(node, typeArguments) {
  18444. if (typeArguments && typeArguments.length === 0) {
  18445. var sourceFile = ts.getSourceFileOfNode(node);
  18446. var start = typeArguments.pos - "<".length;
  18447. var end = ts.skipTrivia(sourceFile.text, typeArguments.end) + ">".length;
  18448. return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
  18449. }
  18450. }
  18451. function checkGrammarTypeArguments(node, typeArguments) {
  18452. return checkGrammarForDisallowedTrailingComma(typeArguments) ||
  18453. checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
  18454. }
  18455. function checkGrammarForOmittedArgument(node, arguments) {
  18456. if (arguments) {
  18457. var sourceFile = ts.getSourceFileOfNode(node);
  18458. for (var _i = 0; _i < arguments.length; _i++) {
  18459. var arg = arguments[_i];
  18460. if (arg.kind === 176) {
  18461. return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected);
  18462. }
  18463. }
  18464. }
  18465. }
  18466. function checkGrammarArguments(node, arguments) {
  18467. return checkGrammarForDisallowedTrailingComma(arguments) ||
  18468. checkGrammarForOmittedArgument(node, arguments);
  18469. }
  18470. function checkGrammarHeritageClause(node) {
  18471. var types = node.types;
  18472. if (checkGrammarForDisallowedTrailingComma(types)) {
  18473. return true;
  18474. }
  18475. if (types && types.length === 0) {
  18476. var listType = ts.tokenToString(node.token);
  18477. var sourceFile = ts.getSourceFileOfNode(node);
  18478. return grammarErrorAtPos(sourceFile, types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType);
  18479. }
  18480. }
  18481. function checkGrammarClassDeclarationHeritageClauses(node) {
  18482. var seenExtendsClause = false;
  18483. var seenImplementsClause = false;
  18484. if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) {
  18485. for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
  18486. var heritageClause = _a[_i];
  18487. if (heritageClause.token === 79) {
  18488. if (seenExtendsClause) {
  18489. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
  18490. }
  18491. if (seenImplementsClause) {
  18492. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause);
  18493. }
  18494. if (heritageClause.types.length > 1) {
  18495. return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class);
  18496. }
  18497. seenExtendsClause = true;
  18498. }
  18499. else {
  18500. ts.Debug.assert(heritageClause.token === 102);
  18501. if (seenImplementsClause) {
  18502. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen);
  18503. }
  18504. seenImplementsClause = true;
  18505. }
  18506. checkGrammarHeritageClause(heritageClause);
  18507. }
  18508. }
  18509. }
  18510. function checkGrammarInterfaceDeclaration(node) {
  18511. var seenExtendsClause = false;
  18512. if (node.heritageClauses) {
  18513. for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
  18514. var heritageClause = _a[_i];
  18515. if (heritageClause.token === 79) {
  18516. if (seenExtendsClause) {
  18517. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
  18518. }
  18519. seenExtendsClause = true;
  18520. }
  18521. else {
  18522. ts.Debug.assert(heritageClause.token === 102);
  18523. return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause);
  18524. }
  18525. checkGrammarHeritageClause(heritageClause);
  18526. }
  18527. }
  18528. return false;
  18529. }
  18530. function checkGrammarComputedPropertyName(node) {
  18531. if (node.kind !== 128) {
  18532. return false;
  18533. }
  18534. var computedPropertyName = node;
  18535. if (computedPropertyName.expression.kind === 170 && computedPropertyName.expression.operatorToken.kind === 23) {
  18536. return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name);
  18537. }
  18538. }
  18539. function checkGrammarForGenerator(node) {
  18540. if (node.asteriskToken) {
  18541. return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported);
  18542. }
  18543. }
  18544. function checkGrammarFunctionName(name) {
  18545. return checkGrammarEvalOrArgumentsInStrictMode(name, name);
  18546. }
  18547. function checkGrammarForInvalidQuestionMark(node, questionToken, message) {
  18548. if (questionToken) {
  18549. return grammarErrorOnNode(questionToken, message);
  18550. }
  18551. }
  18552. function checkGrammarObjectLiteralExpression(node) {
  18553. var seen = {};
  18554. var Property = 1;
  18555. var GetAccessor = 2;
  18556. var SetAccesor = 4;
  18557. var GetOrSetAccessor = GetAccessor | SetAccesor;
  18558. var inStrictMode = (node.parserContextFlags & 1) !== 0;
  18559. for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
  18560. var prop = _a[_i];
  18561. var name_13 = prop.name;
  18562. if (prop.kind === 176 ||
  18563. name_13.kind === 128) {
  18564. checkGrammarComputedPropertyName(name_13);
  18565. continue;
  18566. }
  18567. var currentKind = void 0;
  18568. if (prop.kind === 225 || prop.kind === 226) {
  18569. checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
  18570. if (name_13.kind === 7) {
  18571. checkGrammarNumericLiteral(name_13);
  18572. }
  18573. currentKind = Property;
  18574. }
  18575. else if (prop.kind === 135) {
  18576. currentKind = Property;
  18577. }
  18578. else if (prop.kind === 137) {
  18579. currentKind = GetAccessor;
  18580. }
  18581. else if (prop.kind === 138) {
  18582. currentKind = SetAccesor;
  18583. }
  18584. else {
  18585. ts.Debug.fail("Unexpected syntax kind:" + prop.kind);
  18586. }
  18587. if (!ts.hasProperty(seen, name_13.text)) {
  18588. seen[name_13.text] = currentKind;
  18589. }
  18590. else {
  18591. var existingKind = seen[name_13.text];
  18592. if (currentKind === Property && existingKind === Property) {
  18593. if (inStrictMode) {
  18594. grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode);
  18595. }
  18596. }
  18597. else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
  18598. if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
  18599. seen[name_13.text] = currentKind | existingKind;
  18600. }
  18601. else {
  18602. return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
  18603. }
  18604. }
  18605. else {
  18606. return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
  18607. }
  18608. }
  18609. }
  18610. }
  18611. function checkGrammarForInOrForOfStatement(forInOrOfStatement) {
  18612. if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) {
  18613. return true;
  18614. }
  18615. if (forInOrOfStatement.initializer.kind === 200) {
  18616. var variableList = forInOrOfStatement.initializer;
  18617. if (!checkGrammarVariableDeclarationList(variableList)) {
  18618. if (variableList.declarations.length > 1) {
  18619. var diagnostic = forInOrOfStatement.kind === 188
  18620. ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement
  18621. : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
  18622. return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
  18623. }
  18624. var firstDeclaration = variableList.declarations[0];
  18625. if (firstDeclaration.initializer) {
  18626. var diagnostic = forInOrOfStatement.kind === 188
  18627. ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer
  18628. : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer;
  18629. return grammarErrorOnNode(firstDeclaration.name, diagnostic);
  18630. }
  18631. if (firstDeclaration.type) {
  18632. var diagnostic = forInOrOfStatement.kind === 188
  18633. ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation
  18634. : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation;
  18635. return grammarErrorOnNode(firstDeclaration, diagnostic);
  18636. }
  18637. }
  18638. }
  18639. return false;
  18640. }
  18641. function checkGrammarAccessor(accessor) {
  18642. var kind = accessor.kind;
  18643. if (languageVersion < 1) {
  18644. return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
  18645. }
  18646. else if (ts.isInAmbientContext(accessor)) {
  18647. return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
  18648. }
  18649. else if (accessor.body === undefined) {
  18650. return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
  18651. }
  18652. else if (accessor.typeParameters) {
  18653. return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
  18654. }
  18655. else if (kind === 137 && accessor.parameters.length) {
  18656. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
  18657. }
  18658. else if (kind === 138) {
  18659. if (accessor.type) {
  18660. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
  18661. }
  18662. else if (accessor.parameters.length !== 1) {
  18663. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
  18664. }
  18665. else {
  18666. var parameter = accessor.parameters[0];
  18667. if (parameter.dotDotDotToken) {
  18668. return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
  18669. }
  18670. else if (parameter.flags & 499) {
  18671. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
  18672. }
  18673. else if (parameter.questionToken) {
  18674. return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
  18675. }
  18676. else if (parameter.initializer) {
  18677. return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
  18678. }
  18679. }
  18680. }
  18681. }
  18682. function checkGrammarForNonSymbolComputedProperty(node, message) {
  18683. if (node.kind === 128 && !ts.isWellKnownSymbolSyntactically(node.expression)) {
  18684. return grammarErrorOnNode(node, message);
  18685. }
  18686. }
  18687. function checkGrammarMethod(node) {
  18688. if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) ||
  18689. checkGrammarFunctionLikeDeclaration(node) ||
  18690. checkGrammarForGenerator(node)) {
  18691. return true;
  18692. }
  18693. if (node.parent.kind === 155) {
  18694. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
  18695. return true;
  18696. }
  18697. else if (node.body === undefined) {
  18698. return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
  18699. }
  18700. }
  18701. if (node.parent.kind === 202) {
  18702. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
  18703. return true;
  18704. }
  18705. if (ts.isInAmbientContext(node)) {
  18706. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol);
  18707. }
  18708. else if (!node.body) {
  18709. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol);
  18710. }
  18711. }
  18712. else if (node.parent.kind === 203) {
  18713. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol);
  18714. }
  18715. else if (node.parent.kind === 146) {
  18716. return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol);
  18717. }
  18718. }
  18719. function isIterationStatement(node, lookInLabeledStatements) {
  18720. switch (node.kind) {
  18721. case 187:
  18722. case 188:
  18723. case 189:
  18724. case 185:
  18725. case 186:
  18726. return true;
  18727. case 195:
  18728. return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements);
  18729. }
  18730. return false;
  18731. }
  18732. function checkGrammarBreakOrContinueStatement(node) {
  18733. var current = node;
  18734. while (current) {
  18735. if (ts.isFunctionLike(current)) {
  18736. return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
  18737. }
  18738. switch (current.kind) {
  18739. case 195:
  18740. if (node.label && current.label.text === node.label.text) {
  18741. var isMisplacedContinueLabel = node.kind === 190
  18742. && !isIterationStatement(current.statement, true);
  18743. if (isMisplacedContinueLabel) {
  18744. return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
  18745. }
  18746. return false;
  18747. }
  18748. break;
  18749. case 194:
  18750. if (node.kind === 191 && !node.label) {
  18751. return false;
  18752. }
  18753. break;
  18754. default:
  18755. if (isIterationStatement(current, false) && !node.label) {
  18756. return false;
  18757. }
  18758. break;
  18759. }
  18760. current = current.parent;
  18761. }
  18762. if (node.label) {
  18763. var message = node.kind === 191
  18764. ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement
  18765. : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement;
  18766. return grammarErrorOnNode(node, message);
  18767. }
  18768. else {
  18769. var message = node.kind === 191
  18770. ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement
  18771. : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement;
  18772. return grammarErrorOnNode(node, message);
  18773. }
  18774. }
  18775. function checkGrammarBindingElement(node) {
  18776. if (node.dotDotDotToken) {
  18777. var elements = node.parent.elements;
  18778. if (node !== ts.lastOrUndefined(elements)) {
  18779. return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
  18780. }
  18781. if (node.name.kind === 152 || node.name.kind === 151) {
  18782. return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
  18783. }
  18784. if (node.initializer) {
  18785. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.A_rest_element_cannot_have_an_initializer);
  18786. }
  18787. }
  18788. return checkGrammarEvalOrArgumentsInStrictMode(node, node.name);
  18789. }
  18790. function checkGrammarVariableDeclaration(node) {
  18791. if (node.parent.parent.kind !== 188 && node.parent.parent.kind !== 189) {
  18792. if (ts.isInAmbientContext(node)) {
  18793. if (node.initializer) {
  18794. var equalsTokenLength = "=".length;
  18795. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
  18796. }
  18797. }
  18798. else if (!node.initializer) {
  18799. if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) {
  18800. return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer);
  18801. }
  18802. if (ts.isConst(node)) {
  18803. return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
  18804. }
  18805. }
  18806. }
  18807. var checkLetConstNames = languageVersion >= 2 && (ts.isLet(node) || ts.isConst(node));
  18808. return (checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name)) ||
  18809. checkGrammarEvalOrArgumentsInStrictMode(node, node.name);
  18810. }
  18811. function checkGrammarNameInLetOrConstDeclarations(name) {
  18812. if (name.kind === 65) {
  18813. if (name.text === "let") {
  18814. return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations);
  18815. }
  18816. }
  18817. else {
  18818. var elements = name.elements;
  18819. for (var _i = 0; _i < elements.length; _i++) {
  18820. var element = elements[_i];
  18821. if (element.kind !== 176) {
  18822. checkGrammarNameInLetOrConstDeclarations(element.name);
  18823. }
  18824. }
  18825. }
  18826. }
  18827. function checkGrammarVariableDeclarationList(declarationList) {
  18828. var declarations = declarationList.declarations;
  18829. if (checkGrammarForDisallowedTrailingComma(declarationList.declarations)) {
  18830. return true;
  18831. }
  18832. if (!declarationList.declarations.length) {
  18833. return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
  18834. }
  18835. }
  18836. function allowLetAndConstDeclarations(parent) {
  18837. switch (parent.kind) {
  18838. case 184:
  18839. case 185:
  18840. case 186:
  18841. case 193:
  18842. case 187:
  18843. case 188:
  18844. case 189:
  18845. return false;
  18846. case 195:
  18847. return allowLetAndConstDeclarations(parent.parent);
  18848. }
  18849. return true;
  18850. }
  18851. function checkGrammarForDisallowedLetOrConstStatement(node) {
  18852. if (!allowLetAndConstDeclarations(node.parent)) {
  18853. if (ts.isLet(node.declarationList)) {
  18854. return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
  18855. }
  18856. else if (ts.isConst(node.declarationList)) {
  18857. return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
  18858. }
  18859. }
  18860. }
  18861. function isIntegerLiteral(expression) {
  18862. if (expression.kind === 168) {
  18863. var unaryExpression = expression;
  18864. if (unaryExpression.operator === 33 || unaryExpression.operator === 34) {
  18865. expression = unaryExpression.operand;
  18866. }
  18867. }
  18868. if (expression.kind === 7) {
  18869. return /^[0-9]+([eE]\+?[0-9]+)?$/.test(expression.text);
  18870. }
  18871. return false;
  18872. }
  18873. function checkGrammarEnumDeclaration(enumDecl) {
  18874. var enumIsConst = (enumDecl.flags & 8192) !== 0;
  18875. var hasError = false;
  18876. if (!enumIsConst) {
  18877. var inConstantEnumMemberSection = true;
  18878. var inAmbientContext = ts.isInAmbientContext(enumDecl);
  18879. for (var _i = 0, _a = enumDecl.members; _i < _a.length; _i++) {
  18880. var node = _a[_i];
  18881. if (node.name.kind === 128) {
  18882. hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums);
  18883. }
  18884. else if (inAmbientContext) {
  18885. if (node.initializer && !isIntegerLiteral(node.initializer)) {
  18886. hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError;
  18887. }
  18888. }
  18889. else if (node.initializer) {
  18890. inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
  18891. }
  18892. else if (!inConstantEnumMemberSection) {
  18893. hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError;
  18894. }
  18895. }
  18896. }
  18897. return hasError;
  18898. }
  18899. function hasParseDiagnostics(sourceFile) {
  18900. return sourceFile.parseDiagnostics.length > 0;
  18901. }
  18902. function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
  18903. var sourceFile = ts.getSourceFileOfNode(node);
  18904. if (!hasParseDiagnostics(sourceFile)) {
  18905. var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
  18906. diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2));
  18907. return true;
  18908. }
  18909. }
  18910. function grammarErrorAtPos(sourceFile, start, length, message, arg0, arg1, arg2) {
  18911. if (!hasParseDiagnostics(sourceFile)) {
  18912. diagnostics.add(ts.createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
  18913. return true;
  18914. }
  18915. }
  18916. function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
  18917. var sourceFile = ts.getSourceFileOfNode(node);
  18918. if (!hasParseDiagnostics(sourceFile)) {
  18919. diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2));
  18920. return true;
  18921. }
  18922. }
  18923. function checkGrammarEvalOrArgumentsInStrictMode(contextNode, name) {
  18924. if (name && name.kind === 65) {
  18925. var identifier = name;
  18926. if (contextNode && (contextNode.parserContextFlags & 1) && isEvalOrArgumentsIdentifier(identifier)) {
  18927. var nameText = ts.declarationNameToString(identifier);
  18928. var reportErrorInClassDeclaration = reportStrictModeGrammarErrorInClassDeclaration(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText);
  18929. if (!reportErrorInClassDeclaration) {
  18930. return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText);
  18931. }
  18932. return reportErrorInClassDeclaration;
  18933. }
  18934. }
  18935. }
  18936. function isEvalOrArgumentsIdentifier(node) {
  18937. return node.kind === 65 &&
  18938. (node.text === "eval" || node.text === "arguments");
  18939. }
  18940. function checkGrammarConstructorTypeParameters(node) {
  18941. if (node.typeParameters) {
  18942. return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
  18943. }
  18944. }
  18945. function checkGrammarConstructorTypeAnnotation(node) {
  18946. if (node.type) {
  18947. return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
  18948. }
  18949. }
  18950. function checkGrammarProperty(node) {
  18951. if (node.parent.kind === 202) {
  18952. if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) ||
  18953. checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) {
  18954. return true;
  18955. }
  18956. }
  18957. else if (node.parent.kind === 203) {
  18958. if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) {
  18959. return true;
  18960. }
  18961. }
  18962. else if (node.parent.kind === 146) {
  18963. if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) {
  18964. return true;
  18965. }
  18966. }
  18967. if (ts.isInAmbientContext(node) && node.initializer) {
  18968. return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
  18969. }
  18970. }
  18971. function checkGrammarTopLevelElementForRequiredDeclareModifier(node) {
  18972. if (node.kind === 203 ||
  18973. node.kind === 210 ||
  18974. node.kind === 209 ||
  18975. node.kind === 216 ||
  18976. node.kind === 215 ||
  18977. (node.flags & 2) ||
  18978. (node.flags & (1 | 256))) {
  18979. return false;
  18980. }
  18981. return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
  18982. }
  18983. function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) {
  18984. for (var _i = 0, _a = file.statements; _i < _a.length; _i++) {
  18985. var decl = _a[_i];
  18986. if (ts.isDeclaration(decl) || decl.kind === 181) {
  18987. if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) {
  18988. return true;
  18989. }
  18990. }
  18991. }
  18992. }
  18993. function checkGrammarSourceFile(node) {
  18994. return ts.isInAmbientContext(node) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
  18995. }
  18996. function checkGrammarStatementInAmbientContext(node) {
  18997. if (ts.isInAmbientContext(node)) {
  18998. if (isAccessor(node.parent.kind)) {
  18999. return getNodeLinks(node).hasReportedStatementInAmbientContext = true;
  19000. }
  19001. var links = getNodeLinks(node);
  19002. if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) {
  19003. return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
  19004. }
  19005. if (node.parent.kind === 180 || node.parent.kind === 207 || node.parent.kind === 228) {
  19006. var links_1 = getNodeLinks(node.parent);
  19007. if (!links_1.hasReportedStatementInAmbientContext) {
  19008. return links_1.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
  19009. }
  19010. }
  19011. else {
  19012. }
  19013. }
  19014. }
  19015. function checkGrammarNumericLiteral(node) {
  19016. if (node.flags & 16384) {
  19017. if (node.parserContextFlags & 1) {
  19018. return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
  19019. }
  19020. else if (languageVersion >= 1) {
  19021. return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
  19022. }
  19023. }
  19024. }
  19025. function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) {
  19026. var sourceFile = ts.getSourceFileOfNode(node);
  19027. if (!hasParseDiagnostics(sourceFile)) {
  19028. var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
  19029. diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), 0, message, arg0, arg1, arg2));
  19030. return true;
  19031. }
  19032. }
  19033. initializeTypeChecker();
  19034. return checker;
  19035. }
  19036. ts.createTypeChecker = createTypeChecker;
  19037. })(ts || (ts = {}));
  19038. /// <reference path="checker.ts"/>
  19039. var ts;
  19040. (function (ts) {
  19041. function getDeclarationDiagnostics(host, resolver, targetSourceFile) {
  19042. var diagnostics = [];
  19043. var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
  19044. emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile);
  19045. return diagnostics;
  19046. }
  19047. ts.getDeclarationDiagnostics = getDeclarationDiagnostics;
  19048. function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) {
  19049. var newLine = host.getNewLine();
  19050. var compilerOptions = host.getCompilerOptions();
  19051. var languageVersion = compilerOptions.target || 0;
  19052. var write;
  19053. var writeLine;
  19054. var increaseIndent;
  19055. var decreaseIndent;
  19056. var writeTextOfNode;
  19057. var writer = createAndSetNewTextWriterWithSymbolWriter();
  19058. var enclosingDeclaration;
  19059. var currentSourceFile;
  19060. var reportedDeclarationError = false;
  19061. var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments;
  19062. var emit = compilerOptions.stripInternal ? stripInternal : emitNode;
  19063. var moduleElementDeclarationEmitInfo = [];
  19064. var asynchronousSubModuleDeclarationEmitInfo;
  19065. var referencePathsOutput = "";
  19066. if (root) {
  19067. if (!compilerOptions.noResolve) {
  19068. var addedGlobalFileReference = false;
  19069. ts.forEach(root.referencedFiles, function (fileReference) {
  19070. var referencedFile = ts.tryResolveScriptReference(host, root, fileReference);
  19071. if (referencedFile && ((referencedFile.flags & 2048) ||
  19072. ts.shouldEmitToOwnFile(referencedFile, compilerOptions) ||
  19073. !addedGlobalFileReference)) {
  19074. writeReferencePath(referencedFile);
  19075. if (!ts.isExternalModuleOrDeclarationFile(referencedFile)) {
  19076. addedGlobalFileReference = true;
  19077. }
  19078. }
  19079. });
  19080. }
  19081. emitSourceFile(root);
  19082. if (moduleElementDeclarationEmitInfo.length) {
  19083. var oldWriter = writer;
  19084. ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
  19085. if (aliasEmitInfo.isVisible) {
  19086. ts.Debug.assert(aliasEmitInfo.node.kind === 210);
  19087. createAndSetNewTextWriterWithSymbolWriter();
  19088. ts.Debug.assert(aliasEmitInfo.indent === 0);
  19089. writeImportDeclaration(aliasEmitInfo.node);
  19090. aliasEmitInfo.asynchronousOutput = writer.getText();
  19091. }
  19092. });
  19093. setWriter(oldWriter);
  19094. }
  19095. }
  19096. else {
  19097. var emittedReferencedFiles = [];
  19098. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  19099. if (!ts.isExternalModuleOrDeclarationFile(sourceFile)) {
  19100. if (!compilerOptions.noResolve) {
  19101. ts.forEach(sourceFile.referencedFiles, function (fileReference) {
  19102. var referencedFile = ts.tryResolveScriptReference(host, sourceFile, fileReference);
  19103. if (referencedFile && (ts.isExternalModuleOrDeclarationFile(referencedFile) &&
  19104. !ts.contains(emittedReferencedFiles, referencedFile))) {
  19105. writeReferencePath(referencedFile);
  19106. emittedReferencedFiles.push(referencedFile);
  19107. }
  19108. });
  19109. }
  19110. emitSourceFile(sourceFile);
  19111. }
  19112. });
  19113. }
  19114. return {
  19115. reportedDeclarationError: reportedDeclarationError,
  19116. moduleElementDeclarationEmitInfo: moduleElementDeclarationEmitInfo,
  19117. synchronousDeclarationOutput: writer.getText(),
  19118. referencePathsOutput: referencePathsOutput
  19119. };
  19120. function hasInternalAnnotation(range) {
  19121. var text = currentSourceFile.text;
  19122. var comment = text.substring(range.pos, range.end);
  19123. return comment.indexOf("@internal") >= 0;
  19124. }
  19125. function stripInternal(node) {
  19126. if (node) {
  19127. var leadingCommentRanges = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
  19128. if (ts.forEach(leadingCommentRanges, hasInternalAnnotation)) {
  19129. return;
  19130. }
  19131. emitNode(node);
  19132. }
  19133. }
  19134. function createAndSetNewTextWriterWithSymbolWriter() {
  19135. var writer = ts.createTextWriter(newLine);
  19136. writer.trackSymbol = trackSymbol;
  19137. writer.writeKeyword = writer.write;
  19138. writer.writeOperator = writer.write;
  19139. writer.writePunctuation = writer.write;
  19140. writer.writeSpace = writer.write;
  19141. writer.writeStringLiteral = writer.writeLiteral;
  19142. writer.writeParameter = writer.write;
  19143. writer.writeSymbol = writer.write;
  19144. setWriter(writer);
  19145. return writer;
  19146. }
  19147. function setWriter(newWriter) {
  19148. writer = newWriter;
  19149. write = newWriter.write;
  19150. writeTextOfNode = newWriter.writeTextOfNode;
  19151. writeLine = newWriter.writeLine;
  19152. increaseIndent = newWriter.increaseIndent;
  19153. decreaseIndent = newWriter.decreaseIndent;
  19154. }
  19155. function writeAsynchronousModuleElements(nodes) {
  19156. var oldWriter = writer;
  19157. ts.forEach(nodes, function (declaration) {
  19158. var nodeToCheck;
  19159. if (declaration.kind === 199) {
  19160. nodeToCheck = declaration.parent.parent;
  19161. }
  19162. else if (declaration.kind === 213 || declaration.kind === 214 || declaration.kind === 211) {
  19163. ts.Debug.fail("We should be getting ImportDeclaration instead to write");
  19164. }
  19165. else {
  19166. nodeToCheck = declaration;
  19167. }
  19168. var moduleElementEmitInfo = ts.forEach(moduleElementDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
  19169. if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) {
  19170. moduleElementEmitInfo = ts.forEach(asynchronousSubModuleDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
  19171. }
  19172. if (moduleElementEmitInfo) {
  19173. if (moduleElementEmitInfo.node.kind === 210) {
  19174. moduleElementEmitInfo.isVisible = true;
  19175. }
  19176. else {
  19177. createAndSetNewTextWriterWithSymbolWriter();
  19178. for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) {
  19179. increaseIndent();
  19180. }
  19181. if (nodeToCheck.kind === 206) {
  19182. ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined);
  19183. asynchronousSubModuleDeclarationEmitInfo = [];
  19184. }
  19185. writeModuleElement(nodeToCheck);
  19186. if (nodeToCheck.kind === 206) {
  19187. moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo;
  19188. asynchronousSubModuleDeclarationEmitInfo = undefined;
  19189. }
  19190. moduleElementEmitInfo.asynchronousOutput = writer.getText();
  19191. }
  19192. }
  19193. });
  19194. setWriter(oldWriter);
  19195. }
  19196. function handleSymbolAccessibilityError(symbolAccesibilityResult) {
  19197. if (symbolAccesibilityResult.accessibility === 0) {
  19198. if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
  19199. writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible);
  19200. }
  19201. }
  19202. else {
  19203. reportedDeclarationError = true;
  19204. var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
  19205. if (errorInfo) {
  19206. if (errorInfo.typeName) {
  19207. diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
  19208. }
  19209. else {
  19210. diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
  19211. }
  19212. }
  19213. }
  19214. }
  19215. function trackSymbol(symbol, enclosingDeclaration, meaning) {
  19216. handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
  19217. }
  19218. function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) {
  19219. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  19220. write(": ");
  19221. if (type) {
  19222. emitType(type);
  19223. }
  19224. else {
  19225. resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2, writer);
  19226. }
  19227. }
  19228. function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) {
  19229. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  19230. write(": ");
  19231. if (signature.type) {
  19232. emitType(signature.type);
  19233. }
  19234. else {
  19235. resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2, writer);
  19236. }
  19237. }
  19238. function emitLines(nodes) {
  19239. for (var _i = 0; _i < nodes.length; _i++) {
  19240. var node = nodes[_i];
  19241. emit(node);
  19242. }
  19243. }
  19244. function emitSeparatedList(nodes, separator, eachNodeEmitFn, canEmitFn) {
  19245. var currentWriterPos = writer.getTextPos();
  19246. for (var _i = 0; _i < nodes.length; _i++) {
  19247. var node = nodes[_i];
  19248. if (!canEmitFn || canEmitFn(node)) {
  19249. if (currentWriterPos !== writer.getTextPos()) {
  19250. write(separator);
  19251. }
  19252. currentWriterPos = writer.getTextPos();
  19253. eachNodeEmitFn(node);
  19254. }
  19255. }
  19256. }
  19257. function emitCommaList(nodes, eachNodeEmitFn, canEmitFn) {
  19258. emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn);
  19259. }
  19260. function writeJsDocComments(declaration) {
  19261. if (declaration) {
  19262. var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile);
  19263. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments);
  19264. ts.emitComments(currentSourceFile, writer, jsDocComments, true, newLine, ts.writeCommentRange);
  19265. }
  19266. }
  19267. function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) {
  19268. writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
  19269. emitType(type);
  19270. }
  19271. function emitType(type) {
  19272. switch (type.kind) {
  19273. case 112:
  19274. case 122:
  19275. case 120:
  19276. case 113:
  19277. case 123:
  19278. case 99:
  19279. case 8:
  19280. return writeTextOfNode(currentSourceFile, type);
  19281. case 177:
  19282. return emitExpressionWithTypeArguments(type);
  19283. case 142:
  19284. return emitTypeReference(type);
  19285. case 145:
  19286. return emitTypeQuery(type);
  19287. case 147:
  19288. return emitArrayType(type);
  19289. case 148:
  19290. return emitTupleType(type);
  19291. case 149:
  19292. return emitUnionType(type);
  19293. case 150:
  19294. return emitParenType(type);
  19295. case 143:
  19296. case 144:
  19297. return emitSignatureDeclarationWithJsDocComments(type);
  19298. case 146:
  19299. return emitTypeLiteral(type);
  19300. case 65:
  19301. return emitEntityName(type);
  19302. case 127:
  19303. return emitEntityName(type);
  19304. }
  19305. function emitEntityName(entityName) {
  19306. var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 209 ? entityName.parent : enclosingDeclaration);
  19307. handleSymbolAccessibilityError(visibilityResult);
  19308. writeEntityName(entityName);
  19309. function writeEntityName(entityName) {
  19310. if (entityName.kind === 65) {
  19311. writeTextOfNode(currentSourceFile, entityName);
  19312. }
  19313. else {
  19314. var left = entityName.kind === 127 ? entityName.left : entityName.expression;
  19315. var right = entityName.kind === 127 ? entityName.right : entityName.name;
  19316. writeEntityName(left);
  19317. write(".");
  19318. writeTextOfNode(currentSourceFile, right);
  19319. }
  19320. }
  19321. }
  19322. function emitExpressionWithTypeArguments(node) {
  19323. if (ts.isSupportedExpressionWithTypeArguments(node)) {
  19324. ts.Debug.assert(node.expression.kind === 65 || node.expression.kind === 156);
  19325. emitEntityName(node.expression);
  19326. if (node.typeArguments) {
  19327. write("<");
  19328. emitCommaList(node.typeArguments, emitType);
  19329. write(">");
  19330. }
  19331. }
  19332. }
  19333. function emitTypeReference(type) {
  19334. emitEntityName(type.typeName);
  19335. if (type.typeArguments) {
  19336. write("<");
  19337. emitCommaList(type.typeArguments, emitType);
  19338. write(">");
  19339. }
  19340. }
  19341. function emitTypeQuery(type) {
  19342. write("typeof ");
  19343. emitEntityName(type.exprName);
  19344. }
  19345. function emitArrayType(type) {
  19346. emitType(type.elementType);
  19347. write("[]");
  19348. }
  19349. function emitTupleType(type) {
  19350. write("[");
  19351. emitCommaList(type.elementTypes, emitType);
  19352. write("]");
  19353. }
  19354. function emitUnionType(type) {
  19355. emitSeparatedList(type.types, " | ", emitType);
  19356. }
  19357. function emitParenType(type) {
  19358. write("(");
  19359. emitType(type.type);
  19360. write(")");
  19361. }
  19362. function emitTypeLiteral(type) {
  19363. write("{");
  19364. if (type.members.length) {
  19365. writeLine();
  19366. increaseIndent();
  19367. emitLines(type.members);
  19368. decreaseIndent();
  19369. }
  19370. write("}");
  19371. }
  19372. }
  19373. function emitSourceFile(node) {
  19374. currentSourceFile = node;
  19375. enclosingDeclaration = node;
  19376. emitLines(node.statements);
  19377. }
  19378. function getExportDefaultTempVariableName() {
  19379. var baseName = "_default";
  19380. if (!ts.hasProperty(currentSourceFile.identifiers, baseName)) {
  19381. return baseName;
  19382. }
  19383. var count = 0;
  19384. while (true) {
  19385. var name_14 = baseName + "_" + (++count);
  19386. if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) {
  19387. return name_14;
  19388. }
  19389. }
  19390. }
  19391. function emitExportAssignment(node) {
  19392. if (node.expression.kind === 65) {
  19393. write(node.isExportEquals ? "export = " : "export default ");
  19394. writeTextOfNode(currentSourceFile, node.expression);
  19395. }
  19396. else {
  19397. var tempVarName = getExportDefaultTempVariableName();
  19398. write("declare var ");
  19399. write(tempVarName);
  19400. write(": ");
  19401. writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic;
  19402. resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, 2, writer);
  19403. write(";");
  19404. writeLine();
  19405. write(node.isExportEquals ? "export = " : "export default ");
  19406. write(tempVarName);
  19407. }
  19408. write(";");
  19409. writeLine();
  19410. if (node.expression.kind === 65) {
  19411. var nodes = resolver.collectLinkedAliases(node.expression);
  19412. writeAsynchronousModuleElements(nodes);
  19413. }
  19414. function getDefaultExportAccessibilityDiagnostic(diagnostic) {
  19415. return {
  19416. diagnosticMessage: ts.Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
  19417. errorNode: node
  19418. };
  19419. }
  19420. }
  19421. function isModuleElementVisible(node) {
  19422. return resolver.isDeclarationVisible(node);
  19423. }
  19424. function emitModuleElement(node, isModuleElementVisible) {
  19425. if (isModuleElementVisible) {
  19426. writeModuleElement(node);
  19427. }
  19428. else if (node.kind === 209 ||
  19429. (node.parent.kind === 228 && ts.isExternalModule(currentSourceFile))) {
  19430. var isVisible;
  19431. if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 228) {
  19432. asynchronousSubModuleDeclarationEmitInfo.push({
  19433. node: node,
  19434. outputPos: writer.getTextPos(),
  19435. indent: writer.getIndent(),
  19436. isVisible: isVisible
  19437. });
  19438. }
  19439. else {
  19440. if (node.kind === 210) {
  19441. var importDeclaration = node;
  19442. if (importDeclaration.importClause) {
  19443. isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) ||
  19444. isVisibleNamedBinding(importDeclaration.importClause.namedBindings);
  19445. }
  19446. }
  19447. moduleElementDeclarationEmitInfo.push({
  19448. node: node,
  19449. outputPos: writer.getTextPos(),
  19450. indent: writer.getIndent(),
  19451. isVisible: isVisible
  19452. });
  19453. }
  19454. }
  19455. }
  19456. function writeModuleElement(node) {
  19457. switch (node.kind) {
  19458. case 201:
  19459. return writeFunctionDeclaration(node);
  19460. case 181:
  19461. return writeVariableStatement(node);
  19462. case 203:
  19463. return writeInterfaceDeclaration(node);
  19464. case 202:
  19465. return writeClassDeclaration(node);
  19466. case 204:
  19467. return writeTypeAliasDeclaration(node);
  19468. case 205:
  19469. return writeEnumDeclaration(node);
  19470. case 206:
  19471. return writeModuleDeclaration(node);
  19472. case 209:
  19473. return writeImportEqualsDeclaration(node);
  19474. case 210:
  19475. return writeImportDeclaration(node);
  19476. default:
  19477. ts.Debug.fail("Unknown symbol kind");
  19478. }
  19479. }
  19480. function emitModuleElementDeclarationFlags(node) {
  19481. if (node.parent === currentSourceFile) {
  19482. if (node.flags & 1) {
  19483. write("export ");
  19484. }
  19485. if (node.flags & 256) {
  19486. write("default ");
  19487. }
  19488. else if (node.kind !== 203) {
  19489. write("declare ");
  19490. }
  19491. }
  19492. }
  19493. function emitClassMemberDeclarationFlags(node) {
  19494. if (node.flags & 32) {
  19495. write("private ");
  19496. }
  19497. else if (node.flags & 64) {
  19498. write("protected ");
  19499. }
  19500. if (node.flags & 128) {
  19501. write("static ");
  19502. }
  19503. }
  19504. function writeImportEqualsDeclaration(node) {
  19505. emitJsDocComments(node);
  19506. if (node.flags & 1) {
  19507. write("export ");
  19508. }
  19509. write("import ");
  19510. writeTextOfNode(currentSourceFile, node.name);
  19511. write(" = ");
  19512. if (ts.isInternalModuleImportEqualsDeclaration(node)) {
  19513. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError);
  19514. write(";");
  19515. }
  19516. else {
  19517. write("require(");
  19518. writeTextOfNode(currentSourceFile, ts.getExternalModuleImportEqualsDeclarationExpression(node));
  19519. write(");");
  19520. }
  19521. writer.writeLine();
  19522. function getImportEntityNameVisibilityError(symbolAccesibilityResult) {
  19523. return {
  19524. diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1,
  19525. errorNode: node,
  19526. typeName: node.name
  19527. };
  19528. }
  19529. }
  19530. function isVisibleNamedBinding(namedBindings) {
  19531. if (namedBindings) {
  19532. if (namedBindings.kind === 212) {
  19533. return resolver.isDeclarationVisible(namedBindings);
  19534. }
  19535. else {
  19536. return ts.forEach(namedBindings.elements, function (namedImport) { return resolver.isDeclarationVisible(namedImport); });
  19537. }
  19538. }
  19539. }
  19540. function writeImportDeclaration(node) {
  19541. if (!node.importClause && !(node.flags & 1)) {
  19542. return;
  19543. }
  19544. emitJsDocComments(node);
  19545. if (node.flags & 1) {
  19546. write("export ");
  19547. }
  19548. write("import ");
  19549. if (node.importClause) {
  19550. var currentWriterPos = writer.getTextPos();
  19551. if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) {
  19552. writeTextOfNode(currentSourceFile, node.importClause.name);
  19553. }
  19554. if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) {
  19555. if (currentWriterPos !== writer.getTextPos()) {
  19556. write(", ");
  19557. }
  19558. if (node.importClause.namedBindings.kind === 212) {
  19559. write("* as ");
  19560. writeTextOfNode(currentSourceFile, node.importClause.namedBindings.name);
  19561. }
  19562. else {
  19563. write("{ ");
  19564. emitCommaList(node.importClause.namedBindings.elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible);
  19565. write(" }");
  19566. }
  19567. }
  19568. write(" from ");
  19569. }
  19570. writeTextOfNode(currentSourceFile, node.moduleSpecifier);
  19571. write(";");
  19572. writer.writeLine();
  19573. }
  19574. function emitImportOrExportSpecifier(node) {
  19575. if (node.propertyName) {
  19576. writeTextOfNode(currentSourceFile, node.propertyName);
  19577. write(" as ");
  19578. }
  19579. writeTextOfNode(currentSourceFile, node.name);
  19580. }
  19581. function emitExportSpecifier(node) {
  19582. emitImportOrExportSpecifier(node);
  19583. var nodes = resolver.collectLinkedAliases(node.propertyName || node.name);
  19584. writeAsynchronousModuleElements(nodes);
  19585. }
  19586. function emitExportDeclaration(node) {
  19587. emitJsDocComments(node);
  19588. write("export ");
  19589. if (node.exportClause) {
  19590. write("{ ");
  19591. emitCommaList(node.exportClause.elements, emitExportSpecifier);
  19592. write(" }");
  19593. }
  19594. else {
  19595. write("*");
  19596. }
  19597. if (node.moduleSpecifier) {
  19598. write(" from ");
  19599. writeTextOfNode(currentSourceFile, node.moduleSpecifier);
  19600. }
  19601. write(";");
  19602. writer.writeLine();
  19603. }
  19604. function writeModuleDeclaration(node) {
  19605. emitJsDocComments(node);
  19606. emitModuleElementDeclarationFlags(node);
  19607. write("module ");
  19608. writeTextOfNode(currentSourceFile, node.name);
  19609. while (node.body.kind !== 207) {
  19610. node = node.body;
  19611. write(".");
  19612. writeTextOfNode(currentSourceFile, node.name);
  19613. }
  19614. var prevEnclosingDeclaration = enclosingDeclaration;
  19615. enclosingDeclaration = node;
  19616. write(" {");
  19617. writeLine();
  19618. increaseIndent();
  19619. emitLines(node.body.statements);
  19620. decreaseIndent();
  19621. write("}");
  19622. writeLine();
  19623. enclosingDeclaration = prevEnclosingDeclaration;
  19624. }
  19625. function writeTypeAliasDeclaration(node) {
  19626. emitJsDocComments(node);
  19627. emitModuleElementDeclarationFlags(node);
  19628. write("type ");
  19629. writeTextOfNode(currentSourceFile, node.name);
  19630. write(" = ");
  19631. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError);
  19632. write(";");
  19633. writeLine();
  19634. function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
  19635. return {
  19636. diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
  19637. errorNode: node.type,
  19638. typeName: node.name
  19639. };
  19640. }
  19641. }
  19642. function writeEnumDeclaration(node) {
  19643. emitJsDocComments(node);
  19644. emitModuleElementDeclarationFlags(node);
  19645. if (ts.isConst(node)) {
  19646. write("const ");
  19647. }
  19648. write("enum ");
  19649. writeTextOfNode(currentSourceFile, node.name);
  19650. write(" {");
  19651. writeLine();
  19652. increaseIndent();
  19653. emitLines(node.members);
  19654. decreaseIndent();
  19655. write("}");
  19656. writeLine();
  19657. }
  19658. function emitEnumMemberDeclaration(node) {
  19659. emitJsDocComments(node);
  19660. writeTextOfNode(currentSourceFile, node.name);
  19661. var enumMemberValue = resolver.getConstantValue(node);
  19662. if (enumMemberValue !== undefined) {
  19663. write(" = ");
  19664. write(enumMemberValue.toString());
  19665. }
  19666. write(",");
  19667. writeLine();
  19668. }
  19669. function isPrivateMethodTypeParameter(node) {
  19670. return node.parent.kind === 135 && (node.parent.flags & 32);
  19671. }
  19672. function emitTypeParameters(typeParameters) {
  19673. function emitTypeParameter(node) {
  19674. increaseIndent();
  19675. emitJsDocComments(node);
  19676. decreaseIndent();
  19677. writeTextOfNode(currentSourceFile, node.name);
  19678. if (node.constraint && !isPrivateMethodTypeParameter(node)) {
  19679. write(" extends ");
  19680. if (node.parent.kind === 143 ||
  19681. node.parent.kind === 144 ||
  19682. (node.parent.parent && node.parent.parent.kind === 146)) {
  19683. ts.Debug.assert(node.parent.kind === 135 ||
  19684. node.parent.kind === 134 ||
  19685. node.parent.kind === 143 ||
  19686. node.parent.kind === 144 ||
  19687. node.parent.kind === 139 ||
  19688. node.parent.kind === 140);
  19689. emitType(node.constraint);
  19690. }
  19691. else {
  19692. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError);
  19693. }
  19694. }
  19695. function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
  19696. var diagnosticMessage;
  19697. switch (node.parent.kind) {
  19698. case 202:
  19699. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
  19700. break;
  19701. case 203:
  19702. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
  19703. break;
  19704. case 140:
  19705. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
  19706. break;
  19707. case 139:
  19708. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
  19709. break;
  19710. case 135:
  19711. case 134:
  19712. if (node.parent.flags & 128) {
  19713. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
  19714. }
  19715. else if (node.parent.parent.kind === 202) {
  19716. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
  19717. }
  19718. else {
  19719. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
  19720. }
  19721. break;
  19722. case 201:
  19723. diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
  19724. break;
  19725. default:
  19726. ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
  19727. }
  19728. return {
  19729. diagnosticMessage: diagnosticMessage,
  19730. errorNode: node,
  19731. typeName: node.name
  19732. };
  19733. }
  19734. }
  19735. if (typeParameters) {
  19736. write("<");
  19737. emitCommaList(typeParameters, emitTypeParameter);
  19738. write(">");
  19739. }
  19740. }
  19741. function emitHeritageClause(typeReferences, isImplementsList) {
  19742. if (typeReferences) {
  19743. write(isImplementsList ? " implements " : " extends ");
  19744. emitCommaList(typeReferences, emitTypeOfTypeReference);
  19745. }
  19746. function emitTypeOfTypeReference(node) {
  19747. if (ts.isSupportedExpressionWithTypeArguments(node)) {
  19748. emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError);
  19749. }
  19750. function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
  19751. var diagnosticMessage;
  19752. if (node.parent.parent.kind === 202) {
  19753. diagnosticMessage = isImplementsList ?
  19754. ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
  19755. ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
  19756. }
  19757. else {
  19758. diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
  19759. }
  19760. return {
  19761. diagnosticMessage: diagnosticMessage,
  19762. errorNode: node,
  19763. typeName: node.parent.parent.name
  19764. };
  19765. }
  19766. }
  19767. }
  19768. function writeClassDeclaration(node) {
  19769. function emitParameterProperties(constructorDeclaration) {
  19770. if (constructorDeclaration) {
  19771. ts.forEach(constructorDeclaration.parameters, function (param) {
  19772. if (param.flags & 112) {
  19773. emitPropertyDeclaration(param);
  19774. }
  19775. });
  19776. }
  19777. }
  19778. emitJsDocComments(node);
  19779. emitModuleElementDeclarationFlags(node);
  19780. write("class ");
  19781. writeTextOfNode(currentSourceFile, node.name);
  19782. var prevEnclosingDeclaration = enclosingDeclaration;
  19783. enclosingDeclaration = node;
  19784. emitTypeParameters(node.typeParameters);
  19785. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  19786. if (baseTypeNode) {
  19787. emitHeritageClause([baseTypeNode], false);
  19788. }
  19789. emitHeritageClause(ts.getClassImplementsHeritageClauseElements(node), true);
  19790. write(" {");
  19791. writeLine();
  19792. increaseIndent();
  19793. emitParameterProperties(ts.getFirstConstructorWithBody(node));
  19794. emitLines(node.members);
  19795. decreaseIndent();
  19796. write("}");
  19797. writeLine();
  19798. enclosingDeclaration = prevEnclosingDeclaration;
  19799. }
  19800. function writeInterfaceDeclaration(node) {
  19801. emitJsDocComments(node);
  19802. emitModuleElementDeclarationFlags(node);
  19803. write("interface ");
  19804. writeTextOfNode(currentSourceFile, node.name);
  19805. var prevEnclosingDeclaration = enclosingDeclaration;
  19806. enclosingDeclaration = node;
  19807. emitTypeParameters(node.typeParameters);
  19808. emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), false);
  19809. write(" {");
  19810. writeLine();
  19811. increaseIndent();
  19812. emitLines(node.members);
  19813. decreaseIndent();
  19814. write("}");
  19815. writeLine();
  19816. enclosingDeclaration = prevEnclosingDeclaration;
  19817. }
  19818. function emitPropertyDeclaration(node) {
  19819. if (ts.hasDynamicName(node)) {
  19820. return;
  19821. }
  19822. emitJsDocComments(node);
  19823. emitClassMemberDeclarationFlags(node);
  19824. emitVariableDeclaration(node);
  19825. write(";");
  19826. writeLine();
  19827. }
  19828. function emitVariableDeclaration(node) {
  19829. if (node.kind !== 199 || resolver.isDeclarationVisible(node)) {
  19830. if (ts.isBindingPattern(node.name)) {
  19831. emitBindingPattern(node.name);
  19832. }
  19833. else {
  19834. writeTextOfNode(currentSourceFile, node.name);
  19835. if ((node.kind === 133 || node.kind === 132) && ts.hasQuestionToken(node)) {
  19836. write("?");
  19837. }
  19838. if ((node.kind === 133 || node.kind === 132) && node.parent.kind === 146) {
  19839. emitTypeOfVariableDeclarationFromTypeLiteral(node);
  19840. }
  19841. else if (!(node.flags & 32)) {
  19842. writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError);
  19843. }
  19844. }
  19845. }
  19846. function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
  19847. if (node.kind === 199) {
  19848. return symbolAccesibilityResult.errorModuleName ?
  19849. symbolAccesibilityResult.accessibility === 2 ?
  19850. ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  19851. ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
  19852. ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
  19853. }
  19854. else if (node.kind === 133 || node.kind === 132) {
  19855. if (node.flags & 128) {
  19856. return symbolAccesibilityResult.errorModuleName ?
  19857. symbolAccesibilityResult.accessibility === 2 ?
  19858. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  19859. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
  19860. ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
  19861. }
  19862. else if (node.parent.kind === 202) {
  19863. return symbolAccesibilityResult.errorModuleName ?
  19864. symbolAccesibilityResult.accessibility === 2 ?
  19865. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  19866. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
  19867. ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
  19868. }
  19869. else {
  19870. return symbolAccesibilityResult.errorModuleName ?
  19871. ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  19872. ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
  19873. }
  19874. }
  19875. }
  19876. function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  19877. var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  19878. return diagnosticMessage !== undefined ? {
  19879. diagnosticMessage: diagnosticMessage,
  19880. errorNode: node,
  19881. typeName: node.name
  19882. } : undefined;
  19883. }
  19884. function emitBindingPattern(bindingPattern) {
  19885. var elements = [];
  19886. for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) {
  19887. var element = _a[_i];
  19888. if (element.kind !== 176) {
  19889. elements.push(element);
  19890. }
  19891. }
  19892. emitCommaList(elements, emitBindingElement);
  19893. }
  19894. function emitBindingElement(bindingElement) {
  19895. function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
  19896. var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  19897. return diagnosticMessage !== undefined ? {
  19898. diagnosticMessage: diagnosticMessage,
  19899. errorNode: bindingElement,
  19900. typeName: bindingElement.name
  19901. } : undefined;
  19902. }
  19903. if (bindingElement.name) {
  19904. if (ts.isBindingPattern(bindingElement.name)) {
  19905. emitBindingPattern(bindingElement.name);
  19906. }
  19907. else {
  19908. writeTextOfNode(currentSourceFile, bindingElement.name);
  19909. writeTypeOfDeclaration(bindingElement, undefined, getBindingElementTypeVisibilityError);
  19910. }
  19911. }
  19912. }
  19913. }
  19914. function emitTypeOfVariableDeclarationFromTypeLiteral(node) {
  19915. if (node.type) {
  19916. write(": ");
  19917. emitType(node.type);
  19918. }
  19919. }
  19920. function isVariableStatementVisible(node) {
  19921. return ts.forEach(node.declarationList.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
  19922. }
  19923. function writeVariableStatement(node) {
  19924. emitJsDocComments(node);
  19925. emitModuleElementDeclarationFlags(node);
  19926. if (ts.isLet(node.declarationList)) {
  19927. write("let ");
  19928. }
  19929. else if (ts.isConst(node.declarationList)) {
  19930. write("const ");
  19931. }
  19932. else {
  19933. write("var ");
  19934. }
  19935. emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible);
  19936. write(";");
  19937. writeLine();
  19938. }
  19939. function emitAccessorDeclaration(node) {
  19940. if (ts.hasDynamicName(node)) {
  19941. return;
  19942. }
  19943. var accessors = ts.getAllAccessorDeclarations(node.parent.members, node);
  19944. var accessorWithTypeAnnotation;
  19945. if (node === accessors.firstAccessor) {
  19946. emitJsDocComments(accessors.getAccessor);
  19947. emitJsDocComments(accessors.setAccessor);
  19948. emitClassMemberDeclarationFlags(node);
  19949. writeTextOfNode(currentSourceFile, node.name);
  19950. if (!(node.flags & 32)) {
  19951. accessorWithTypeAnnotation = node;
  19952. var type = getTypeAnnotationFromAccessor(node);
  19953. if (!type) {
  19954. var anotherAccessor = node.kind === 137 ? accessors.setAccessor : accessors.getAccessor;
  19955. type = getTypeAnnotationFromAccessor(anotherAccessor);
  19956. if (type) {
  19957. accessorWithTypeAnnotation = anotherAccessor;
  19958. }
  19959. }
  19960. writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError);
  19961. }
  19962. write(";");
  19963. writeLine();
  19964. }
  19965. function getTypeAnnotationFromAccessor(accessor) {
  19966. if (accessor) {
  19967. return accessor.kind === 137
  19968. ? accessor.type
  19969. : accessor.parameters.length > 0
  19970. ? accessor.parameters[0].type
  19971. : undefined;
  19972. }
  19973. }
  19974. function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  19975. var diagnosticMessage;
  19976. if (accessorWithTypeAnnotation.kind === 138) {
  19977. if (accessorWithTypeAnnotation.parent.flags & 128) {
  19978. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  19979. ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  19980. ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
  19981. }
  19982. else {
  19983. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  19984. ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  19985. ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
  19986. }
  19987. return {
  19988. diagnosticMessage: diagnosticMessage,
  19989. errorNode: accessorWithTypeAnnotation.parameters[0],
  19990. typeName: accessorWithTypeAnnotation.name
  19991. };
  19992. }
  19993. else {
  19994. if (accessorWithTypeAnnotation.flags & 128) {
  19995. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  19996. symbolAccesibilityResult.accessibility === 2 ?
  19997. 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 :
  19998. ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  19999. ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
  20000. }
  20001. else {
  20002. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20003. symbolAccesibilityResult.accessibility === 2 ?
  20004. 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 :
  20005. ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  20006. ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
  20007. }
  20008. return {
  20009. diagnosticMessage: diagnosticMessage,
  20010. errorNode: accessorWithTypeAnnotation.name,
  20011. typeName: undefined
  20012. };
  20013. }
  20014. }
  20015. }
  20016. function writeFunctionDeclaration(node) {
  20017. if (ts.hasDynamicName(node)) {
  20018. return;
  20019. }
  20020. if (!resolver.isImplementationOfOverload(node)) {
  20021. emitJsDocComments(node);
  20022. if (node.kind === 201) {
  20023. emitModuleElementDeclarationFlags(node);
  20024. }
  20025. else if (node.kind === 135) {
  20026. emitClassMemberDeclarationFlags(node);
  20027. }
  20028. if (node.kind === 201) {
  20029. write("function ");
  20030. writeTextOfNode(currentSourceFile, node.name);
  20031. }
  20032. else if (node.kind === 136) {
  20033. write("constructor");
  20034. }
  20035. else {
  20036. writeTextOfNode(currentSourceFile, node.name);
  20037. if (ts.hasQuestionToken(node)) {
  20038. write("?");
  20039. }
  20040. }
  20041. emitSignatureDeclaration(node);
  20042. }
  20043. }
  20044. function emitSignatureDeclarationWithJsDocComments(node) {
  20045. emitJsDocComments(node);
  20046. emitSignatureDeclaration(node);
  20047. }
  20048. function emitSignatureDeclaration(node) {
  20049. if (node.kind === 140 || node.kind === 144) {
  20050. write("new ");
  20051. }
  20052. emitTypeParameters(node.typeParameters);
  20053. if (node.kind === 141) {
  20054. write("[");
  20055. }
  20056. else {
  20057. write("(");
  20058. }
  20059. var prevEnclosingDeclaration = enclosingDeclaration;
  20060. enclosingDeclaration = node;
  20061. emitCommaList(node.parameters, emitParameterDeclaration);
  20062. if (node.kind === 141) {
  20063. write("]");
  20064. }
  20065. else {
  20066. write(")");
  20067. }
  20068. var isFunctionTypeOrConstructorType = node.kind === 143 || node.kind === 144;
  20069. if (isFunctionTypeOrConstructorType || node.parent.kind === 146) {
  20070. if (node.type) {
  20071. write(isFunctionTypeOrConstructorType ? " => " : ": ");
  20072. emitType(node.type);
  20073. }
  20074. }
  20075. else if (node.kind !== 136 && !(node.flags & 32)) {
  20076. writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
  20077. }
  20078. enclosingDeclaration = prevEnclosingDeclaration;
  20079. if (!isFunctionTypeOrConstructorType) {
  20080. write(";");
  20081. writeLine();
  20082. }
  20083. function getReturnTypeVisibilityError(symbolAccesibilityResult) {
  20084. var diagnosticMessage;
  20085. switch (node.kind) {
  20086. case 140:
  20087. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20088. ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  20089. ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
  20090. break;
  20091. case 139:
  20092. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20093. ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  20094. ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
  20095. break;
  20096. case 141:
  20097. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20098. ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  20099. ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
  20100. break;
  20101. case 135:
  20102. case 134:
  20103. if (node.flags & 128) {
  20104. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20105. symbolAccesibilityResult.accessibility === 2 ?
  20106. 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 :
  20107. ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  20108. ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
  20109. }
  20110. else if (node.parent.kind === 202) {
  20111. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20112. symbolAccesibilityResult.accessibility === 2 ?
  20113. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  20114. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
  20115. ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
  20116. }
  20117. else {
  20118. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20119. ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
  20120. ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
  20121. }
  20122. break;
  20123. case 201:
  20124. diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
  20125. symbolAccesibilityResult.accessibility === 2 ?
  20126. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
  20127. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 :
  20128. ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
  20129. break;
  20130. default:
  20131. ts.Debug.fail("This is unknown kind for signature: " + node.kind);
  20132. }
  20133. return {
  20134. diagnosticMessage: diagnosticMessage,
  20135. errorNode: node.name || node
  20136. };
  20137. }
  20138. }
  20139. function emitParameterDeclaration(node) {
  20140. increaseIndent();
  20141. emitJsDocComments(node);
  20142. if (node.dotDotDotToken) {
  20143. write("...");
  20144. }
  20145. if (ts.isBindingPattern(node.name)) {
  20146. emitBindingPattern(node.name);
  20147. }
  20148. else {
  20149. writeTextOfNode(currentSourceFile, node.name);
  20150. }
  20151. if (node.initializer || ts.hasQuestionToken(node)) {
  20152. write("?");
  20153. }
  20154. decreaseIndent();
  20155. if (node.parent.kind === 143 ||
  20156. node.parent.kind === 144 ||
  20157. node.parent.parent.kind === 146) {
  20158. emitTypeOfVariableDeclarationFromTypeLiteral(node);
  20159. }
  20160. else if (!(node.parent.flags & 32)) {
  20161. writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError);
  20162. }
  20163. function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
  20164. var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  20165. return diagnosticMessage !== undefined ? {
  20166. diagnosticMessage: diagnosticMessage,
  20167. errorNode: node,
  20168. typeName: node.name
  20169. } : undefined;
  20170. }
  20171. function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
  20172. switch (node.parent.kind) {
  20173. case 136:
  20174. return symbolAccesibilityResult.errorModuleName ?
  20175. symbolAccesibilityResult.accessibility === 2 ?
  20176. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  20177. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  20178. ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
  20179. case 140:
  20180. return symbolAccesibilityResult.errorModuleName ?
  20181. ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  20182. ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
  20183. case 139:
  20184. return symbolAccesibilityResult.errorModuleName ?
  20185. ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  20186. ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
  20187. case 135:
  20188. case 134:
  20189. if (node.parent.flags & 128) {
  20190. return symbolAccesibilityResult.errorModuleName ?
  20191. symbolAccesibilityResult.accessibility === 2 ?
  20192. 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 :
  20193. ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  20194. ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
  20195. }
  20196. else if (node.parent.parent.kind === 202) {
  20197. return symbolAccesibilityResult.errorModuleName ?
  20198. symbolAccesibilityResult.accessibility === 2 ?
  20199. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  20200. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
  20201. ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
  20202. }
  20203. else {
  20204. return symbolAccesibilityResult.errorModuleName ?
  20205. ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
  20206. ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
  20207. }
  20208. case 201:
  20209. return symbolAccesibilityResult.errorModuleName ?
  20210. symbolAccesibilityResult.accessibility === 2 ?
  20211. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
  20212. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
  20213. ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
  20214. default:
  20215. ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
  20216. }
  20217. }
  20218. function emitBindingPattern(bindingPattern) {
  20219. if (bindingPattern.kind === 151) {
  20220. write("{");
  20221. emitCommaList(bindingPattern.elements, emitBindingElement);
  20222. write("}");
  20223. }
  20224. else if (bindingPattern.kind === 152) {
  20225. write("[");
  20226. var elements = bindingPattern.elements;
  20227. emitCommaList(elements, emitBindingElement);
  20228. if (elements && elements.hasTrailingComma) {
  20229. write(", ");
  20230. }
  20231. write("]");
  20232. }
  20233. }
  20234. function emitBindingElement(bindingElement) {
  20235. function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
  20236. var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
  20237. return diagnosticMessage !== undefined ? {
  20238. diagnosticMessage: diagnosticMessage,
  20239. errorNode: bindingElement,
  20240. typeName: bindingElement.name
  20241. } : undefined;
  20242. }
  20243. if (bindingElement.kind === 176) {
  20244. write(" ");
  20245. }
  20246. else if (bindingElement.kind === 153) {
  20247. if (bindingElement.propertyName) {
  20248. writeTextOfNode(currentSourceFile, bindingElement.propertyName);
  20249. write(": ");
  20250. emitBindingPattern(bindingElement.name);
  20251. }
  20252. else if (bindingElement.name) {
  20253. if (ts.isBindingPattern(bindingElement.name)) {
  20254. emitBindingPattern(bindingElement.name);
  20255. }
  20256. else {
  20257. ts.Debug.assert(bindingElement.name.kind === 65);
  20258. if (bindingElement.dotDotDotToken) {
  20259. write("...");
  20260. }
  20261. writeTextOfNode(currentSourceFile, bindingElement.name);
  20262. }
  20263. }
  20264. }
  20265. }
  20266. }
  20267. function emitNode(node) {
  20268. switch (node.kind) {
  20269. case 201:
  20270. case 206:
  20271. case 209:
  20272. case 203:
  20273. case 202:
  20274. case 204:
  20275. case 205:
  20276. return emitModuleElement(node, isModuleElementVisible(node));
  20277. case 181:
  20278. return emitModuleElement(node, isVariableStatementVisible(node));
  20279. case 210:
  20280. return emitModuleElement(node, !node.importClause);
  20281. case 216:
  20282. return emitExportDeclaration(node);
  20283. case 136:
  20284. case 135:
  20285. case 134:
  20286. return writeFunctionDeclaration(node);
  20287. case 140:
  20288. case 139:
  20289. case 141:
  20290. return emitSignatureDeclarationWithJsDocComments(node);
  20291. case 137:
  20292. case 138:
  20293. return emitAccessorDeclaration(node);
  20294. case 133:
  20295. case 132:
  20296. return emitPropertyDeclaration(node);
  20297. case 227:
  20298. return emitEnumMemberDeclaration(node);
  20299. case 215:
  20300. return emitExportAssignment(node);
  20301. case 228:
  20302. return emitSourceFile(node);
  20303. }
  20304. }
  20305. function writeReferencePath(referencedFile) {
  20306. var declFileName = referencedFile.flags & 2048
  20307. ? referencedFile.fileName
  20308. : ts.shouldEmitToOwnFile(referencedFile, compilerOptions)
  20309. ? ts.getOwnEmitOutputFilePath(referencedFile, host, ".d.ts")
  20310. : ts.removeFileExtension(compilerOptions.out) + ".d.ts";
  20311. declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false);
  20312. referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
  20313. }
  20314. }
  20315. function writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics) {
  20316. var emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile);
  20317. if (!emitDeclarationResult.reportedDeclarationError) {
  20318. var declarationOutput = emitDeclarationResult.referencePathsOutput
  20319. + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo);
  20320. ts.writeFile(host, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, host.getCompilerOptions().emitBOM);
  20321. }
  20322. function getDeclarationOutput(synchronousDeclarationOutput, moduleElementDeclarationEmitInfo) {
  20323. var appliedSyncOutputPos = 0;
  20324. var declarationOutput = "";
  20325. ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
  20326. if (aliasEmitInfo.asynchronousOutput) {
  20327. declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos);
  20328. declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo);
  20329. appliedSyncOutputPos = aliasEmitInfo.outputPos;
  20330. }
  20331. });
  20332. declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos);
  20333. return declarationOutput;
  20334. }
  20335. }
  20336. ts.writeDeclarationFile = writeDeclarationFile;
  20337. })(ts || (ts = {}));
  20338. /// <reference path="checker.ts"/>
  20339. /// <reference path="declarationEmitter.ts"/>
  20340. var ts;
  20341. (function (ts) {
  20342. function isExternalModuleOrDeclarationFile(sourceFile) {
  20343. return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile);
  20344. }
  20345. ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile;
  20346. function emitFiles(resolver, host, targetSourceFile) {
  20347. 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 __.prototype = b.prototype;\n d.prototype = new __();\n};";
  20348. 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};";
  20349. 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};";
  20350. var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};";
  20351. var compilerOptions = host.getCompilerOptions();
  20352. var languageVersion = compilerOptions.target || 0;
  20353. var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined;
  20354. var diagnostics = [];
  20355. var newLine = host.getNewLine();
  20356. if (targetSourceFile === undefined) {
  20357. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  20358. if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) {
  20359. var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, ".js");
  20360. emitFile(jsFilePath, sourceFile);
  20361. }
  20362. });
  20363. if (compilerOptions.out) {
  20364. emitFile(compilerOptions.out);
  20365. }
  20366. }
  20367. else {
  20368. if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
  20369. var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
  20370. emitFile(jsFilePath, targetSourceFile);
  20371. }
  20372. else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) {
  20373. emitFile(compilerOptions.out);
  20374. }
  20375. }
  20376. diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics);
  20377. return {
  20378. emitSkipped: false,
  20379. diagnostics: diagnostics,
  20380. sourceMaps: sourceMapDataList
  20381. };
  20382. function isNodeDescendentOf(node, ancestor) {
  20383. while (node) {
  20384. if (node === ancestor)
  20385. return true;
  20386. node = node.parent;
  20387. }
  20388. return false;
  20389. }
  20390. function isUniqueLocalName(name, container) {
  20391. for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) {
  20392. if (node.locals && ts.hasProperty(node.locals, name)) {
  20393. if (node.locals[name].flags & (107455 | 1048576 | 8388608)) {
  20394. return false;
  20395. }
  20396. }
  20397. }
  20398. return true;
  20399. }
  20400. function emitJavaScript(jsFilePath, root) {
  20401. var writer = ts.createTextWriter(newLine);
  20402. var write = writer.write;
  20403. var writeTextOfNode = writer.writeTextOfNode;
  20404. var writeLine = writer.writeLine;
  20405. var increaseIndent = writer.increaseIndent;
  20406. var decreaseIndent = writer.decreaseIndent;
  20407. var currentSourceFile;
  20408. var exportFunctionForFile;
  20409. var generatedNameSet = {};
  20410. var nodeToGeneratedName = [];
  20411. var blockScopedVariableToGeneratedName;
  20412. var computedPropertyNamesToGeneratedNames;
  20413. var extendsEmitted = false;
  20414. var decorateEmitted = false;
  20415. var paramEmitted = false;
  20416. var tempFlags = 0;
  20417. var tempVariables;
  20418. var tempParameters;
  20419. var externalImports;
  20420. var exportSpecifiers;
  20421. var exportEquals;
  20422. var hasExportStars;
  20423. var writeEmittedFiles = writeJavaScriptFile;
  20424. var detachedCommentsInfo;
  20425. var writeComment = ts.writeCommentRange;
  20426. var emit = emitNodeWithoutSourceMap;
  20427. var emitStart = function (node) { };
  20428. var emitEnd = function (node) { };
  20429. var emitToken = emitTokenText;
  20430. var scopeEmitStart = function (scopeDeclaration, scopeName) { };
  20431. var scopeEmitEnd = function () { };
  20432. var sourceMapData;
  20433. if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) {
  20434. initializeEmitterWithSourceMaps();
  20435. }
  20436. if (root) {
  20437. emitSourceFile(root);
  20438. }
  20439. else {
  20440. ts.forEach(host.getSourceFiles(), function (sourceFile) {
  20441. if (!isExternalModuleOrDeclarationFile(sourceFile)) {
  20442. emitSourceFile(sourceFile);
  20443. }
  20444. });
  20445. }
  20446. writeLine();
  20447. writeEmittedFiles(writer.getText(), compilerOptions.emitBOM);
  20448. return;
  20449. function emitSourceFile(sourceFile) {
  20450. currentSourceFile = sourceFile;
  20451. exportFunctionForFile = undefined;
  20452. emit(sourceFile);
  20453. }
  20454. function isUniqueName(name) {
  20455. return !resolver.hasGlobalName(name) &&
  20456. !ts.hasProperty(currentSourceFile.identifiers, name) &&
  20457. !ts.hasProperty(generatedNameSet, name);
  20458. }
  20459. function makeTempVariableName(flags) {
  20460. if (flags && !(tempFlags & flags)) {
  20461. var name = flags === 268435456 ? "_i" : "_n";
  20462. if (isUniqueName(name)) {
  20463. tempFlags |= flags;
  20464. return name;
  20465. }
  20466. }
  20467. while (true) {
  20468. var count = tempFlags & 268435455;
  20469. tempFlags++;
  20470. if (count !== 8 && count !== 13) {
  20471. var name_15 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26);
  20472. if (isUniqueName(name_15)) {
  20473. return name_15;
  20474. }
  20475. }
  20476. }
  20477. }
  20478. function makeUniqueName(baseName) {
  20479. if (baseName.charCodeAt(baseName.length - 1) !== 95) {
  20480. baseName += "_";
  20481. }
  20482. var i = 1;
  20483. while (true) {
  20484. var generatedName = baseName + i;
  20485. if (isUniqueName(generatedName)) {
  20486. return generatedNameSet[generatedName] = generatedName;
  20487. }
  20488. i++;
  20489. }
  20490. }
  20491. function assignGeneratedName(node, name) {
  20492. nodeToGeneratedName[ts.getNodeId(node)] = ts.unescapeIdentifier(name);
  20493. }
  20494. function generateNameForFunctionOrClassDeclaration(node) {
  20495. if (!node.name) {
  20496. assignGeneratedName(node, makeUniqueName("default"));
  20497. }
  20498. }
  20499. function generateNameForModuleOrEnum(node) {
  20500. if (node.name.kind === 65) {
  20501. var name_16 = node.name.text;
  20502. assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16));
  20503. }
  20504. }
  20505. function generateNameForImportOrExportDeclaration(node) {
  20506. var expr = ts.getExternalModuleName(node);
  20507. var baseName = expr.kind === 8 ?
  20508. ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module";
  20509. assignGeneratedName(node, makeUniqueName(baseName));
  20510. }
  20511. function generateNameForImportDeclaration(node) {
  20512. if (node.importClause) {
  20513. generateNameForImportOrExportDeclaration(node);
  20514. }
  20515. }
  20516. function generateNameForExportDeclaration(node) {
  20517. if (node.moduleSpecifier) {
  20518. generateNameForImportOrExportDeclaration(node);
  20519. }
  20520. }
  20521. function generateNameForExportAssignment(node) {
  20522. if (node.expression && node.expression.kind !== 65) {
  20523. assignGeneratedName(node, makeUniqueName("default"));
  20524. }
  20525. }
  20526. function generateNameForNode(node) {
  20527. switch (node.kind) {
  20528. case 201:
  20529. case 202:
  20530. case 175:
  20531. generateNameForFunctionOrClassDeclaration(node);
  20532. break;
  20533. case 206:
  20534. generateNameForModuleOrEnum(node);
  20535. generateNameForNode(node.body);
  20536. break;
  20537. case 205:
  20538. generateNameForModuleOrEnum(node);
  20539. break;
  20540. case 210:
  20541. generateNameForImportDeclaration(node);
  20542. break;
  20543. case 216:
  20544. generateNameForExportDeclaration(node);
  20545. break;
  20546. case 215:
  20547. generateNameForExportAssignment(node);
  20548. break;
  20549. }
  20550. }
  20551. function getGeneratedNameForNode(node) {
  20552. var nodeId = ts.getNodeId(node);
  20553. if (!nodeToGeneratedName[nodeId]) {
  20554. generateNameForNode(node);
  20555. }
  20556. return nodeToGeneratedName[nodeId];
  20557. }
  20558. function initializeEmitterWithSourceMaps() {
  20559. var sourceMapDir;
  20560. var sourceMapSourceIndex = -1;
  20561. var sourceMapNameIndexMap = {};
  20562. var sourceMapNameIndices = [];
  20563. function getSourceMapNameIndex() {
  20564. return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1;
  20565. }
  20566. var lastRecordedSourceMapSpan;
  20567. var lastEncodedSourceMapSpan = {
  20568. emittedLine: 1,
  20569. emittedColumn: 1,
  20570. sourceLine: 1,
  20571. sourceColumn: 1,
  20572. sourceIndex: 0
  20573. };
  20574. var lastEncodedNameIndex = 0;
  20575. function encodeLastRecordedSourceMapSpan() {
  20576. if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) {
  20577. return;
  20578. }
  20579. var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn;
  20580. if (lastEncodedSourceMapSpan.emittedLine == lastRecordedSourceMapSpan.emittedLine) {
  20581. if (sourceMapData.sourceMapMappings) {
  20582. sourceMapData.sourceMapMappings += ",";
  20583. }
  20584. }
  20585. else {
  20586. for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) {
  20587. sourceMapData.sourceMapMappings += ";";
  20588. }
  20589. prevEncodedEmittedColumn = 1;
  20590. }
  20591. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn);
  20592. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex);
  20593. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine);
  20594. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn);
  20595. if (lastRecordedSourceMapSpan.nameIndex >= 0) {
  20596. sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex);
  20597. lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex;
  20598. }
  20599. lastEncodedSourceMapSpan = lastRecordedSourceMapSpan;
  20600. sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan);
  20601. function base64VLQFormatEncode(inValue) {
  20602. function base64FormatEncode(inValue) {
  20603. if (inValue < 64) {
  20604. return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charAt(inValue);
  20605. }
  20606. throw TypeError(inValue + ": not a 64 based value");
  20607. }
  20608. if (inValue < 0) {
  20609. inValue = ((-inValue) << 1) + 1;
  20610. }
  20611. else {
  20612. inValue = inValue << 1;
  20613. }
  20614. var encodedStr = "";
  20615. do {
  20616. var currentDigit = inValue & 31;
  20617. inValue = inValue >> 5;
  20618. if (inValue > 0) {
  20619. currentDigit = currentDigit | 32;
  20620. }
  20621. encodedStr = encodedStr + base64FormatEncode(currentDigit);
  20622. } while (inValue > 0);
  20623. return encodedStr;
  20624. }
  20625. }
  20626. function recordSourceMapSpan(pos) {
  20627. var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos);
  20628. sourceLinePos.line++;
  20629. sourceLinePos.character++;
  20630. var emittedLine = writer.getLine();
  20631. var emittedColumn = writer.getColumn();
  20632. if (!lastRecordedSourceMapSpan ||
  20633. lastRecordedSourceMapSpan.emittedLine != emittedLine ||
  20634. lastRecordedSourceMapSpan.emittedColumn != emittedColumn ||
  20635. (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex &&
  20636. (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line ||
  20637. (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) {
  20638. encodeLastRecordedSourceMapSpan();
  20639. lastRecordedSourceMapSpan = {
  20640. emittedLine: emittedLine,
  20641. emittedColumn: emittedColumn,
  20642. sourceLine: sourceLinePos.line,
  20643. sourceColumn: sourceLinePos.character,
  20644. nameIndex: getSourceMapNameIndex(),
  20645. sourceIndex: sourceMapSourceIndex
  20646. };
  20647. }
  20648. else {
  20649. lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line;
  20650. lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character;
  20651. lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex;
  20652. }
  20653. }
  20654. function recordEmitNodeStartSpan(node) {
  20655. recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos));
  20656. }
  20657. function recordEmitNodeEndSpan(node) {
  20658. recordSourceMapSpan(node.end);
  20659. }
  20660. function writeTextWithSpanRecord(tokenKind, startPos, emitFn) {
  20661. var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos);
  20662. recordSourceMapSpan(tokenStartPos);
  20663. var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn);
  20664. recordSourceMapSpan(tokenEndPos);
  20665. return tokenEndPos;
  20666. }
  20667. function recordNewSourceFileStart(node) {
  20668. var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir;
  20669. sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, true));
  20670. sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
  20671. sourceMapData.inputSourceFileNames.push(node.fileName);
  20672. if (compilerOptions.inlineSources) {
  20673. if (!sourceMapData.sourceMapSourcesContent) {
  20674. sourceMapData.sourceMapSourcesContent = [];
  20675. }
  20676. sourceMapData.sourceMapSourcesContent.push(node.text);
  20677. }
  20678. }
  20679. function recordScopeNameOfNode(node, scopeName) {
  20680. function recordScopeNameIndex(scopeNameIndex) {
  20681. sourceMapNameIndices.push(scopeNameIndex);
  20682. }
  20683. function recordScopeNameStart(scopeName) {
  20684. var scopeNameIndex = -1;
  20685. if (scopeName) {
  20686. var parentIndex = getSourceMapNameIndex();
  20687. if (parentIndex !== -1) {
  20688. var name_17 = node.name;
  20689. if (!name_17 || name_17.kind !== 128) {
  20690. scopeName = "." + scopeName;
  20691. }
  20692. scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName;
  20693. }
  20694. scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName);
  20695. if (scopeNameIndex === undefined) {
  20696. scopeNameIndex = sourceMapData.sourceMapNames.length;
  20697. sourceMapData.sourceMapNames.push(scopeName);
  20698. sourceMapNameIndexMap[scopeName] = scopeNameIndex;
  20699. }
  20700. }
  20701. recordScopeNameIndex(scopeNameIndex);
  20702. }
  20703. if (scopeName) {
  20704. recordScopeNameStart(scopeName);
  20705. }
  20706. else if (node.kind === 201 ||
  20707. node.kind === 163 ||
  20708. node.kind === 135 ||
  20709. node.kind === 134 ||
  20710. node.kind === 137 ||
  20711. node.kind === 138 ||
  20712. node.kind === 206 ||
  20713. node.kind === 202 ||
  20714. node.kind === 205) {
  20715. if (node.name) {
  20716. var name_18 = node.name;
  20717. scopeName = name_18.kind === 128
  20718. ? ts.getTextOfNode(name_18)
  20719. : node.name.text;
  20720. }
  20721. recordScopeNameStart(scopeName);
  20722. }
  20723. else {
  20724. recordScopeNameIndex(getSourceMapNameIndex());
  20725. }
  20726. }
  20727. function recordScopeNameEnd() {
  20728. sourceMapNameIndices.pop();
  20729. }
  20730. ;
  20731. function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) {
  20732. recordSourceMapSpan(comment.pos);
  20733. ts.writeCommentRange(currentSourceFile, writer, comment, newLine);
  20734. recordSourceMapSpan(comment.end);
  20735. }
  20736. function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) {
  20737. if (typeof JSON !== "undefined") {
  20738. var map_1 = {
  20739. version: version,
  20740. file: file,
  20741. sourceRoot: sourceRoot,
  20742. sources: sources,
  20743. names: names,
  20744. mappings: mappings
  20745. };
  20746. if (sourcesContent !== undefined) {
  20747. map_1.sourcesContent = sourcesContent;
  20748. }
  20749. return JSON.stringify(map_1);
  20750. }
  20751. 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) + "]" : "") + "}";
  20752. function serializeStringArray(list) {
  20753. var output = "";
  20754. for (var i = 0, n = list.length; i < n; i++) {
  20755. if (i) {
  20756. output += ",";
  20757. }
  20758. output += "\"" + ts.escapeString(list[i]) + "\"";
  20759. }
  20760. return output;
  20761. }
  20762. }
  20763. function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) {
  20764. encodeLastRecordedSourceMapSpan();
  20765. var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent);
  20766. sourceMapDataList.push(sourceMapData);
  20767. var sourceMapUrl;
  20768. if (compilerOptions.inlineSourceMap) {
  20769. var base64SourceMapText = ts.convertToBase64(sourceMapText);
  20770. sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText;
  20771. }
  20772. else {
  20773. ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, false);
  20774. sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL;
  20775. }
  20776. writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark);
  20777. }
  20778. var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath));
  20779. sourceMapData = {
  20780. sourceMapFilePath: jsFilePath + ".map",
  20781. jsSourceMappingURL: sourceMapJsFile + ".map",
  20782. sourceMapFile: sourceMapJsFile,
  20783. sourceMapSourceRoot: compilerOptions.sourceRoot || "",
  20784. sourceMapSources: [],
  20785. inputSourceFileNames: [],
  20786. sourceMapNames: [],
  20787. sourceMapMappings: "",
  20788. sourceMapSourcesContent: undefined,
  20789. sourceMapDecodedMappings: []
  20790. };
  20791. sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot);
  20792. if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47) {
  20793. sourceMapData.sourceMapSourceRoot += ts.directorySeparator;
  20794. }
  20795. if (compilerOptions.mapRoot) {
  20796. sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot);
  20797. if (root) {
  20798. sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir));
  20799. }
  20800. if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) {
  20801. sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir);
  20802. sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true);
  20803. }
  20804. else {
  20805. sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL);
  20806. }
  20807. }
  20808. else {
  20809. sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath));
  20810. }
  20811. function emitNodeWithSourceMap(node, allowGeneratedIdentifiers) {
  20812. if (node) {
  20813. if (ts.nodeIsSynthesized(node)) {
  20814. return emitNodeWithoutSourceMap(node, false);
  20815. }
  20816. if (node.kind != 228) {
  20817. recordEmitNodeStartSpan(node);
  20818. emitNodeWithoutSourceMap(node, allowGeneratedIdentifiers);
  20819. recordEmitNodeEndSpan(node);
  20820. }
  20821. else {
  20822. recordNewSourceFileStart(node);
  20823. emitNodeWithoutSourceMap(node, false);
  20824. }
  20825. }
  20826. }
  20827. writeEmittedFiles = writeJavaScriptAndSourceMapFile;
  20828. emit = emitNodeWithSourceMap;
  20829. emitStart = recordEmitNodeStartSpan;
  20830. emitEnd = recordEmitNodeEndSpan;
  20831. emitToken = writeTextWithSpanRecord;
  20832. scopeEmitStart = recordScopeNameOfNode;
  20833. scopeEmitEnd = recordScopeNameEnd;
  20834. writeComment = writeCommentRangeWithMap;
  20835. }
  20836. function writeJavaScriptFile(emitOutput, writeByteOrderMark) {
  20837. ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
  20838. }
  20839. function createTempVariable(flags) {
  20840. var result = ts.createSynthesizedNode(65);
  20841. result.text = makeTempVariableName(flags);
  20842. return result;
  20843. }
  20844. function recordTempDeclaration(name) {
  20845. if (!tempVariables) {
  20846. tempVariables = [];
  20847. }
  20848. tempVariables.push(name);
  20849. }
  20850. function createAndRecordTempVariable(flags) {
  20851. var temp = createTempVariable(flags);
  20852. recordTempDeclaration(temp);
  20853. return temp;
  20854. }
  20855. function emitTempDeclarations(newLine) {
  20856. if (tempVariables) {
  20857. if (newLine) {
  20858. writeLine();
  20859. }
  20860. else {
  20861. write(" ");
  20862. }
  20863. write("var ");
  20864. emitCommaList(tempVariables);
  20865. write(";");
  20866. }
  20867. }
  20868. function emitTokenText(tokenKind, startPos, emitFn) {
  20869. var tokenString = ts.tokenToString(tokenKind);
  20870. if (emitFn) {
  20871. emitFn();
  20872. }
  20873. else {
  20874. write(tokenString);
  20875. }
  20876. return startPos + tokenString.length;
  20877. }
  20878. function emitOptional(prefix, node) {
  20879. if (node) {
  20880. write(prefix);
  20881. emit(node);
  20882. }
  20883. }
  20884. function emitParenthesizedIf(node, parenthesized) {
  20885. if (parenthesized) {
  20886. write("(");
  20887. }
  20888. emit(node);
  20889. if (parenthesized) {
  20890. write(")");
  20891. }
  20892. }
  20893. function emitTrailingCommaIfPresent(nodeList) {
  20894. if (nodeList.hasTrailingComma) {
  20895. write(",");
  20896. }
  20897. }
  20898. function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) {
  20899. ts.Debug.assert(nodes.length > 0);
  20900. increaseIndent();
  20901. if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) {
  20902. if (spacesBetweenBraces) {
  20903. write(" ");
  20904. }
  20905. }
  20906. else {
  20907. writeLine();
  20908. }
  20909. for (var i = 0, n = nodes.length; i < n; i++) {
  20910. if (i) {
  20911. if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) {
  20912. write(", ");
  20913. }
  20914. else {
  20915. write(",");
  20916. writeLine();
  20917. }
  20918. }
  20919. emit(nodes[i]);
  20920. }
  20921. if (nodes.hasTrailingComma && allowTrailingComma) {
  20922. write(",");
  20923. }
  20924. decreaseIndent();
  20925. if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) {
  20926. if (spacesBetweenBraces) {
  20927. write(" ");
  20928. }
  20929. }
  20930. else {
  20931. writeLine();
  20932. }
  20933. }
  20934. function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) {
  20935. if (!emitNode) {
  20936. emitNode = emit;
  20937. }
  20938. for (var i = 0; i < count; i++) {
  20939. if (multiLine) {
  20940. if (i || leadingComma) {
  20941. write(",");
  20942. }
  20943. writeLine();
  20944. }
  20945. else {
  20946. if (i || leadingComma) {
  20947. write(", ");
  20948. }
  20949. }
  20950. emitNode(nodes[start + i]);
  20951. leadingComma = true;
  20952. }
  20953. if (trailingComma) {
  20954. write(",");
  20955. }
  20956. if (multiLine && !noTrailingNewLine) {
  20957. writeLine();
  20958. }
  20959. return count;
  20960. }
  20961. function emitCommaList(nodes) {
  20962. if (nodes) {
  20963. emitList(nodes, 0, nodes.length, false, false);
  20964. }
  20965. }
  20966. function emitLines(nodes) {
  20967. emitLinesStartingAt(nodes, 0);
  20968. }
  20969. function emitLinesStartingAt(nodes, startIndex) {
  20970. for (var i = startIndex; i < nodes.length; i++) {
  20971. writeLine();
  20972. emit(nodes[i]);
  20973. }
  20974. }
  20975. function isBinaryOrOctalIntegerLiteral(node, text) {
  20976. if (node.kind === 7 && text.length > 1) {
  20977. switch (text.charCodeAt(1)) {
  20978. case 98:
  20979. case 66:
  20980. case 111:
  20981. case 79:
  20982. return true;
  20983. }
  20984. }
  20985. return false;
  20986. }
  20987. function emitLiteral(node) {
  20988. var text = getLiteralText(node);
  20989. if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 8 || ts.isTemplateLiteralKind(node.kind))) {
  20990. writer.writeLiteral(text);
  20991. }
  20992. else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) {
  20993. write(node.text);
  20994. }
  20995. else {
  20996. write(text);
  20997. }
  20998. }
  20999. function getLiteralText(node) {
  21000. if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) {
  21001. return getQuotedEscapedLiteralText('"', node.text, '"');
  21002. }
  21003. if (node.parent) {
  21004. return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
  21005. }
  21006. switch (node.kind) {
  21007. case 8:
  21008. return getQuotedEscapedLiteralText('"', node.text, '"');
  21009. case 10:
  21010. return getQuotedEscapedLiteralText('`', node.text, '`');
  21011. case 11:
  21012. return getQuotedEscapedLiteralText('`', node.text, '${');
  21013. case 12:
  21014. return getQuotedEscapedLiteralText('}', node.text, '${');
  21015. case 13:
  21016. return getQuotedEscapedLiteralText('}', node.text, '`');
  21017. case 7:
  21018. return node.text;
  21019. }
  21020. ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for.");
  21021. }
  21022. function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) {
  21023. return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote;
  21024. }
  21025. function emitDownlevelRawTemplateLiteral(node) {
  21026. var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
  21027. var isLast = node.kind === 10 || node.kind === 13;
  21028. text = text.substring(1, text.length - (isLast ? 1 : 2));
  21029. text = text.replace(/\r\n?/g, "\n");
  21030. text = ts.escapeString(text);
  21031. write('"' + text + '"');
  21032. }
  21033. function emitDownlevelTaggedTemplateArray(node, literalEmitter) {
  21034. write("[");
  21035. if (node.template.kind === 10) {
  21036. literalEmitter(node.template);
  21037. }
  21038. else {
  21039. literalEmitter(node.template.head);
  21040. ts.forEach(node.template.templateSpans, function (child) {
  21041. write(", ");
  21042. literalEmitter(child.literal);
  21043. });
  21044. }
  21045. write("]");
  21046. }
  21047. function emitDownlevelTaggedTemplate(node) {
  21048. var tempVariable = createAndRecordTempVariable(0);
  21049. write("(");
  21050. emit(tempVariable);
  21051. write(" = ");
  21052. emitDownlevelTaggedTemplateArray(node, emit);
  21053. write(", ");
  21054. emit(tempVariable);
  21055. write(".raw = ");
  21056. emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral);
  21057. write(", ");
  21058. emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag));
  21059. write("(");
  21060. emit(tempVariable);
  21061. if (node.template.kind === 172) {
  21062. ts.forEach(node.template.templateSpans, function (templateSpan) {
  21063. write(", ");
  21064. var needsParens = templateSpan.expression.kind === 170
  21065. && templateSpan.expression.operatorToken.kind === 23;
  21066. emitParenthesizedIf(templateSpan.expression, needsParens);
  21067. });
  21068. }
  21069. write("))");
  21070. }
  21071. function emitTemplateExpression(node) {
  21072. if (languageVersion >= 2) {
  21073. ts.forEachChild(node, emit);
  21074. return;
  21075. }
  21076. var emitOuterParens = ts.isExpression(node.parent)
  21077. && templateNeedsParens(node, node.parent);
  21078. if (emitOuterParens) {
  21079. write("(");
  21080. }
  21081. var headEmitted = false;
  21082. if (shouldEmitTemplateHead()) {
  21083. emitLiteral(node.head);
  21084. headEmitted = true;
  21085. }
  21086. for (var i = 0, n = node.templateSpans.length; i < n; i++) {
  21087. var templateSpan = node.templateSpans[i];
  21088. var needsParens = templateSpan.expression.kind !== 162
  21089. && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1;
  21090. if (i > 0 || headEmitted) {
  21091. write(" + ");
  21092. }
  21093. emitParenthesizedIf(templateSpan.expression, needsParens);
  21094. if (templateSpan.literal.text.length !== 0) {
  21095. write(" + ");
  21096. emitLiteral(templateSpan.literal);
  21097. }
  21098. }
  21099. if (emitOuterParens) {
  21100. write(")");
  21101. }
  21102. function shouldEmitTemplateHead() {
  21103. // If this expression has an empty head literal and the first template span has a non-empty
  21104. // literal, then emitting the empty head literal is not necessary.
  21105. // `${ foo } and ${ bar }`
  21106. // can be emitted as
  21107. // foo + " and " + bar
  21108. // This is because it is only required that one of the first two operands in the emit
  21109. // output must be a string literal, so that the other operand and all following operands
  21110. // are forced into strings.
  21111. //
  21112. // If the first template span has an empty literal, then the head must still be emitted.
  21113. // `${ foo }${ bar }`
  21114. // must still be emitted as
  21115. // "" + foo + bar
  21116. ts.Debug.assert(node.templateSpans.length !== 0);
  21117. return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0;
  21118. }
  21119. function templateNeedsParens(template, parent) {
  21120. switch (parent.kind) {
  21121. case 158:
  21122. case 159:
  21123. return parent.expression === template;
  21124. case 160:
  21125. case 162:
  21126. return false;
  21127. default:
  21128. return comparePrecedenceToBinaryPlus(parent) !== -1;
  21129. }
  21130. }
  21131. function comparePrecedenceToBinaryPlus(expression) {
  21132. switch (expression.kind) {
  21133. case 170:
  21134. switch (expression.operatorToken.kind) {
  21135. case 35:
  21136. case 36:
  21137. case 37:
  21138. return 1;
  21139. case 33:
  21140. case 34:
  21141. return 0;
  21142. default:
  21143. return -1;
  21144. }
  21145. case 173:
  21146. case 171:
  21147. return -1;
  21148. default:
  21149. return 1;
  21150. }
  21151. }
  21152. }
  21153. function emitTemplateSpan(span) {
  21154. emit(span.expression);
  21155. emit(span.literal);
  21156. }
  21157. function emitExpressionForPropertyName(node) {
  21158. ts.Debug.assert(node.kind !== 153);
  21159. if (node.kind === 8) {
  21160. emitLiteral(node);
  21161. }
  21162. else if (node.kind === 128) {
  21163. if (ts.nodeIsDecorated(node.parent)) {
  21164. if (!computedPropertyNamesToGeneratedNames) {
  21165. computedPropertyNamesToGeneratedNames = [];
  21166. }
  21167. var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)];
  21168. if (generatedName) {
  21169. write(generatedName);
  21170. return;
  21171. }
  21172. generatedName = createAndRecordTempVariable(0).text;
  21173. computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName;
  21174. write(generatedName);
  21175. write(" = ");
  21176. }
  21177. emit(node.expression);
  21178. }
  21179. else {
  21180. write("\"");
  21181. if (node.kind === 7) {
  21182. write(node.text);
  21183. }
  21184. else {
  21185. writeTextOfNode(currentSourceFile, node);
  21186. }
  21187. write("\"");
  21188. }
  21189. }
  21190. function isNotExpressionIdentifier(node) {
  21191. var parent = node.parent;
  21192. switch (parent.kind) {
  21193. case 130:
  21194. case 199:
  21195. case 153:
  21196. case 133:
  21197. case 132:
  21198. case 225:
  21199. case 226:
  21200. case 227:
  21201. case 135:
  21202. case 134:
  21203. case 201:
  21204. case 137:
  21205. case 138:
  21206. case 163:
  21207. case 202:
  21208. case 203:
  21209. case 205:
  21210. case 206:
  21211. case 209:
  21212. case 211:
  21213. case 212:
  21214. return parent.name === node;
  21215. case 214:
  21216. case 218:
  21217. return parent.name === node || parent.propertyName === node;
  21218. case 191:
  21219. case 190:
  21220. case 215:
  21221. return false;
  21222. case 195:
  21223. return node.parent.label === node;
  21224. }
  21225. }
  21226. function emitExpressionIdentifier(node) {
  21227. var substitution = resolver.getExpressionNameSubstitution(node, getGeneratedNameForNode);
  21228. if (substitution) {
  21229. write(substitution);
  21230. }
  21231. else {
  21232. writeTextOfNode(currentSourceFile, node);
  21233. }
  21234. }
  21235. function getGeneratedNameForIdentifier(node) {
  21236. if (ts.nodeIsSynthesized(node) || !blockScopedVariableToGeneratedName) {
  21237. return undefined;
  21238. }
  21239. var variableId = resolver.getBlockScopedVariableId(node);
  21240. if (variableId === undefined) {
  21241. return undefined;
  21242. }
  21243. return blockScopedVariableToGeneratedName[variableId];
  21244. }
  21245. function emitIdentifier(node, allowGeneratedIdentifiers) {
  21246. if (allowGeneratedIdentifiers) {
  21247. var generatedName = getGeneratedNameForIdentifier(node);
  21248. if (generatedName) {
  21249. write(generatedName);
  21250. return;
  21251. }
  21252. }
  21253. if (!node.parent) {
  21254. write(node.text);
  21255. }
  21256. else if (!isNotExpressionIdentifier(node)) {
  21257. emitExpressionIdentifier(node);
  21258. }
  21259. else {
  21260. writeTextOfNode(currentSourceFile, node);
  21261. }
  21262. }
  21263. function emitThis(node) {
  21264. if (resolver.getNodeCheckFlags(node) & 2) {
  21265. write("_this");
  21266. }
  21267. else {
  21268. write("this");
  21269. }
  21270. }
  21271. function emitSuper(node) {
  21272. if (languageVersion >= 2) {
  21273. write("super");
  21274. }
  21275. else {
  21276. var flags = resolver.getNodeCheckFlags(node);
  21277. if (flags & 16) {
  21278. write("_super.prototype");
  21279. }
  21280. else {
  21281. write("_super");
  21282. }
  21283. }
  21284. }
  21285. function emitObjectBindingPattern(node) {
  21286. write("{ ");
  21287. var elements = node.elements;
  21288. emitList(elements, 0, elements.length, false, elements.hasTrailingComma);
  21289. write(" }");
  21290. }
  21291. function emitArrayBindingPattern(node) {
  21292. write("[");
  21293. var elements = node.elements;
  21294. emitList(elements, 0, elements.length, false, elements.hasTrailingComma);
  21295. write("]");
  21296. }
  21297. function emitBindingElement(node) {
  21298. if (node.propertyName) {
  21299. emit(node.propertyName, false);
  21300. write(": ");
  21301. }
  21302. if (node.dotDotDotToken) {
  21303. write("...");
  21304. }
  21305. if (ts.isBindingPattern(node.name)) {
  21306. emit(node.name);
  21307. }
  21308. else {
  21309. emitModuleMemberName(node);
  21310. }
  21311. emitOptional(" = ", node.initializer);
  21312. }
  21313. function emitSpreadElementExpression(node) {
  21314. write("...");
  21315. emit(node.expression);
  21316. }
  21317. function emitYieldExpression(node) {
  21318. write(ts.tokenToString(110));
  21319. if (node.asteriskToken) {
  21320. write("*");
  21321. }
  21322. if (node.expression) {
  21323. write(" ");
  21324. emit(node.expression);
  21325. }
  21326. }
  21327. function needsParenthesisForPropertyAccessOrInvocation(node) {
  21328. switch (node.kind) {
  21329. case 65:
  21330. case 154:
  21331. case 156:
  21332. case 157:
  21333. case 158:
  21334. case 162:
  21335. return false;
  21336. }
  21337. return true;
  21338. }
  21339. function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) {
  21340. var pos = 0;
  21341. var group = 0;
  21342. var length = elements.length;
  21343. while (pos < length) {
  21344. if (group === 1) {
  21345. write(".concat(");
  21346. }
  21347. else if (group > 1) {
  21348. write(", ");
  21349. }
  21350. var e = elements[pos];
  21351. if (e.kind === 174) {
  21352. e = e.expression;
  21353. emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
  21354. pos++;
  21355. if (pos === length && group === 0 && alwaysCopy && e.kind !== 154) {
  21356. write(".slice()");
  21357. }
  21358. }
  21359. else {
  21360. var i = pos;
  21361. while (i < length && elements[i].kind !== 174) {
  21362. i++;
  21363. }
  21364. write("[");
  21365. if (multiLine) {
  21366. increaseIndent();
  21367. }
  21368. emitList(elements, pos, i - pos, multiLine, trailingComma && i === length);
  21369. if (multiLine) {
  21370. decreaseIndent();
  21371. }
  21372. write("]");
  21373. pos = i;
  21374. }
  21375. group++;
  21376. }
  21377. if (group > 1) {
  21378. write(")");
  21379. }
  21380. }
  21381. function isSpreadElementExpression(node) {
  21382. return node.kind === 174;
  21383. }
  21384. function emitArrayLiteral(node) {
  21385. var elements = node.elements;
  21386. if (elements.length === 0) {
  21387. write("[]");
  21388. }
  21389. else if (languageVersion >= 2 || !ts.forEach(elements, isSpreadElementExpression)) {
  21390. write("[");
  21391. emitLinePreservingList(node, node.elements, elements.hasTrailingComma, false);
  21392. write("]");
  21393. }
  21394. else {
  21395. emitListWithSpread(elements, true, (node.flags & 512) !== 0, elements.hasTrailingComma);
  21396. }
  21397. }
  21398. function emitObjectLiteralBody(node, numElements) {
  21399. if (numElements === 0) {
  21400. write("{}");
  21401. return;
  21402. }
  21403. write("{");
  21404. if (numElements > 0) {
  21405. var properties = node.properties;
  21406. if (numElements === properties.length) {
  21407. emitLinePreservingList(node, properties, languageVersion >= 1, true);
  21408. }
  21409. else {
  21410. var multiLine = (node.flags & 512) !== 0;
  21411. if (!multiLine) {
  21412. write(" ");
  21413. }
  21414. else {
  21415. increaseIndent();
  21416. }
  21417. emitList(properties, 0, numElements, multiLine, false);
  21418. if (!multiLine) {
  21419. write(" ");
  21420. }
  21421. else {
  21422. decreaseIndent();
  21423. }
  21424. }
  21425. }
  21426. write("}");
  21427. }
  21428. function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) {
  21429. var multiLine = (node.flags & 512) !== 0;
  21430. var properties = node.properties;
  21431. write("(");
  21432. if (multiLine) {
  21433. increaseIndent();
  21434. }
  21435. var tempVar = createAndRecordTempVariable(0);
  21436. emit(tempVar);
  21437. write(" = ");
  21438. emitObjectLiteralBody(node, firstComputedPropertyIndex);
  21439. for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) {
  21440. writeComma();
  21441. var property = properties[i];
  21442. emitStart(property);
  21443. if (property.kind === 137 || property.kind === 138) {
  21444. var accessors = ts.getAllAccessorDeclarations(node.properties, property);
  21445. if (property !== accessors.firstAccessor) {
  21446. continue;
  21447. }
  21448. write("Object.defineProperty(");
  21449. emit(tempVar);
  21450. write(", ");
  21451. emitStart(node.name);
  21452. emitExpressionForPropertyName(property.name);
  21453. emitEnd(property.name);
  21454. write(", {");
  21455. increaseIndent();
  21456. if (accessors.getAccessor) {
  21457. writeLine();
  21458. emitLeadingComments(accessors.getAccessor);
  21459. write("get: ");
  21460. emitStart(accessors.getAccessor);
  21461. write("function ");
  21462. emitSignatureAndBody(accessors.getAccessor);
  21463. emitEnd(accessors.getAccessor);
  21464. emitTrailingComments(accessors.getAccessor);
  21465. write(",");
  21466. }
  21467. if (accessors.setAccessor) {
  21468. writeLine();
  21469. emitLeadingComments(accessors.setAccessor);
  21470. write("set: ");
  21471. emitStart(accessors.setAccessor);
  21472. write("function ");
  21473. emitSignatureAndBody(accessors.setAccessor);
  21474. emitEnd(accessors.setAccessor);
  21475. emitTrailingComments(accessors.setAccessor);
  21476. write(",");
  21477. }
  21478. writeLine();
  21479. write("enumerable: true,");
  21480. writeLine();
  21481. write("configurable: true");
  21482. decreaseIndent();
  21483. writeLine();
  21484. write("})");
  21485. emitEnd(property);
  21486. }
  21487. else {
  21488. emitLeadingComments(property);
  21489. emitStart(property.name);
  21490. emit(tempVar);
  21491. emitMemberAccessForPropertyName(property.name);
  21492. emitEnd(property.name);
  21493. write(" = ");
  21494. if (property.kind === 225) {
  21495. emit(property.initializer);
  21496. }
  21497. else if (property.kind === 226) {
  21498. emitExpressionIdentifier(property.name);
  21499. }
  21500. else if (property.kind === 135) {
  21501. emitFunctionDeclaration(property);
  21502. }
  21503. else {
  21504. ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind);
  21505. }
  21506. }
  21507. emitEnd(property);
  21508. }
  21509. writeComma();
  21510. emit(tempVar);
  21511. if (multiLine) {
  21512. decreaseIndent();
  21513. writeLine();
  21514. }
  21515. write(")");
  21516. function writeComma() {
  21517. if (multiLine) {
  21518. write(",");
  21519. writeLine();
  21520. }
  21521. else {
  21522. write(", ");
  21523. }
  21524. }
  21525. }
  21526. function emitObjectLiteral(node) {
  21527. var properties = node.properties;
  21528. if (languageVersion < 2) {
  21529. var numProperties = properties.length;
  21530. var numInitialNonComputedProperties = numProperties;
  21531. for (var i = 0, n = properties.length; i < n; i++) {
  21532. if (properties[i].name.kind === 128) {
  21533. numInitialNonComputedProperties = i;
  21534. break;
  21535. }
  21536. }
  21537. var hasComputedProperty = numInitialNonComputedProperties !== properties.length;
  21538. if (hasComputedProperty) {
  21539. emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties);
  21540. return;
  21541. }
  21542. }
  21543. emitObjectLiteralBody(node, properties.length);
  21544. }
  21545. function createBinaryExpression(left, operator, right, startsOnNewLine) {
  21546. var result = ts.createSynthesizedNode(170, startsOnNewLine);
  21547. result.operatorToken = ts.createSynthesizedNode(operator);
  21548. result.left = left;
  21549. result.right = right;
  21550. return result;
  21551. }
  21552. function createPropertyAccessExpression(expression, name) {
  21553. var result = ts.createSynthesizedNode(156);
  21554. result.expression = parenthesizeForAccess(expression);
  21555. result.dotToken = ts.createSynthesizedNode(20);
  21556. result.name = name;
  21557. return result;
  21558. }
  21559. function createElementAccessExpression(expression, argumentExpression) {
  21560. var result = ts.createSynthesizedNode(157);
  21561. result.expression = parenthesizeForAccess(expression);
  21562. result.argumentExpression = argumentExpression;
  21563. return result;
  21564. }
  21565. function parenthesizeForAccess(expr) {
  21566. while (expr.kind === 161) {
  21567. expr = expr.expression;
  21568. }
  21569. if (ts.isLeftHandSideExpression(expr) &&
  21570. expr.kind !== 159 &&
  21571. expr.kind !== 7) {
  21572. return expr;
  21573. }
  21574. var node = ts.createSynthesizedNode(162);
  21575. node.expression = expr;
  21576. return node;
  21577. }
  21578. function emitComputedPropertyName(node) {
  21579. write("[");
  21580. emitExpressionForPropertyName(node);
  21581. write("]");
  21582. }
  21583. function emitMethod(node) {
  21584. if (languageVersion >= 2 && node.asteriskToken) {
  21585. write("*");
  21586. }
  21587. emit(node.name, false);
  21588. if (languageVersion < 2) {
  21589. write(": function ");
  21590. }
  21591. emitSignatureAndBody(node);
  21592. }
  21593. function emitPropertyAssignment(node) {
  21594. emit(node.name, false);
  21595. write(": ");
  21596. emit(node.initializer);
  21597. }
  21598. function emitShorthandPropertyAssignment(node) {
  21599. emit(node.name, false);
  21600. if (languageVersion < 2) {
  21601. write(": ");
  21602. var generatedName = getGeneratedNameForIdentifier(node.name);
  21603. if (generatedName) {
  21604. write(generatedName);
  21605. }
  21606. else {
  21607. emitExpressionIdentifier(node.name);
  21608. }
  21609. }
  21610. else if (resolver.getExpressionNameSubstitution(node.name, getGeneratedNameForNode)) {
  21611. write(": ");
  21612. emitExpressionIdentifier(node.name);
  21613. }
  21614. }
  21615. function tryEmitConstantValue(node) {
  21616. if (compilerOptions.isolatedModules) {
  21617. return false;
  21618. }
  21619. var constantValue = resolver.getConstantValue(node);
  21620. if (constantValue !== undefined) {
  21621. write(constantValue.toString());
  21622. if (!compilerOptions.removeComments) {
  21623. var propertyName = node.kind === 156 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression);
  21624. write(" /* " + propertyName + " */");
  21625. }
  21626. return true;
  21627. }
  21628. return false;
  21629. }
  21630. function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) {
  21631. var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2);
  21632. var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2);
  21633. if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) {
  21634. increaseIndent();
  21635. writeLine();
  21636. return true;
  21637. }
  21638. else {
  21639. if (valueToWriteWhenNotIndenting) {
  21640. write(valueToWriteWhenNotIndenting);
  21641. }
  21642. return false;
  21643. }
  21644. }
  21645. function emitPropertyAccess(node) {
  21646. if (tryEmitConstantValue(node)) {
  21647. return;
  21648. }
  21649. emit(node.expression);
  21650. var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
  21651. write(".");
  21652. var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
  21653. emit(node.name, false);
  21654. decreaseIndentIf(indentedBeforeDot, indentedAfterDot);
  21655. }
  21656. function emitQualifiedName(node) {
  21657. emit(node.left);
  21658. write(".");
  21659. emit(node.right);
  21660. }
  21661. function emitIndexedAccess(node) {
  21662. if (tryEmitConstantValue(node)) {
  21663. return;
  21664. }
  21665. emit(node.expression);
  21666. write("[");
  21667. emit(node.argumentExpression);
  21668. write("]");
  21669. }
  21670. function hasSpreadElement(elements) {
  21671. return ts.forEach(elements, function (e) { return e.kind === 174; });
  21672. }
  21673. function skipParentheses(node) {
  21674. while (node.kind === 162 || node.kind === 161) {
  21675. node = node.expression;
  21676. }
  21677. return node;
  21678. }
  21679. function emitCallTarget(node) {
  21680. if (node.kind === 65 || node.kind === 93 || node.kind === 91) {
  21681. emit(node);
  21682. return node;
  21683. }
  21684. var temp = createAndRecordTempVariable(0);
  21685. write("(");
  21686. emit(temp);
  21687. write(" = ");
  21688. emit(node);
  21689. write(")");
  21690. return temp;
  21691. }
  21692. function emitCallWithSpread(node) {
  21693. var target;
  21694. var expr = skipParentheses(node.expression);
  21695. if (expr.kind === 156) {
  21696. target = emitCallTarget(expr.expression);
  21697. write(".");
  21698. emit(expr.name);
  21699. }
  21700. else if (expr.kind === 157) {
  21701. target = emitCallTarget(expr.expression);
  21702. write("[");
  21703. emit(expr.argumentExpression);
  21704. write("]");
  21705. }
  21706. else if (expr.kind === 91) {
  21707. target = expr;
  21708. write("_super");
  21709. }
  21710. else {
  21711. emit(node.expression);
  21712. }
  21713. write(".apply(");
  21714. if (target) {
  21715. if (target.kind === 91) {
  21716. emitThis(target);
  21717. }
  21718. else {
  21719. emit(target);
  21720. }
  21721. }
  21722. else {
  21723. write("void 0");
  21724. }
  21725. write(", ");
  21726. emitListWithSpread(node.arguments, false, false, false);
  21727. write(")");
  21728. }
  21729. function emitCallExpression(node) {
  21730. if (languageVersion < 2 && hasSpreadElement(node.arguments)) {
  21731. emitCallWithSpread(node);
  21732. return;
  21733. }
  21734. var superCall = false;
  21735. if (node.expression.kind === 91) {
  21736. emitSuper(node.expression);
  21737. superCall = true;
  21738. }
  21739. else {
  21740. emit(node.expression);
  21741. superCall = node.expression.kind === 156 && node.expression.expression.kind === 91;
  21742. }
  21743. if (superCall && languageVersion < 2) {
  21744. write(".call(");
  21745. emitThis(node.expression);
  21746. if (node.arguments.length) {
  21747. write(", ");
  21748. emitCommaList(node.arguments);
  21749. }
  21750. write(")");
  21751. }
  21752. else {
  21753. write("(");
  21754. emitCommaList(node.arguments);
  21755. write(")");
  21756. }
  21757. }
  21758. function emitNewExpression(node) {
  21759. write("new ");
  21760. emit(node.expression);
  21761. if (node.arguments) {
  21762. write("(");
  21763. emitCommaList(node.arguments);
  21764. write(")");
  21765. }
  21766. }
  21767. function emitTaggedTemplateExpression(node) {
  21768. if (languageVersion >= 2) {
  21769. emit(node.tag);
  21770. write(" ");
  21771. emit(node.template);
  21772. }
  21773. else {
  21774. emitDownlevelTaggedTemplate(node);
  21775. }
  21776. }
  21777. function emitParenExpression(node) {
  21778. if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164) {
  21779. if (node.expression.kind === 161) {
  21780. var operand = node.expression.expression;
  21781. while (operand.kind == 161) {
  21782. operand = operand.expression;
  21783. }
  21784. if (operand.kind !== 168 &&
  21785. operand.kind !== 167 &&
  21786. operand.kind !== 166 &&
  21787. operand.kind !== 165 &&
  21788. operand.kind !== 169 &&
  21789. operand.kind !== 159 &&
  21790. !(operand.kind === 158 && node.parent.kind === 159) &&
  21791. !(operand.kind === 163 && node.parent.kind === 158)) {
  21792. emit(operand);
  21793. return;
  21794. }
  21795. }
  21796. }
  21797. write("(");
  21798. emit(node.expression);
  21799. write(")");
  21800. }
  21801. function emitDeleteExpression(node) {
  21802. write(ts.tokenToString(74));
  21803. write(" ");
  21804. emit(node.expression);
  21805. }
  21806. function emitVoidExpression(node) {
  21807. write(ts.tokenToString(99));
  21808. write(" ");
  21809. emit(node.expression);
  21810. }
  21811. function emitTypeOfExpression(node) {
  21812. write(ts.tokenToString(97));
  21813. write(" ");
  21814. emit(node.expression);
  21815. }
  21816. function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) {
  21817. if (!isCurrentFileSystemExternalModule() || node.kind !== 65 || ts.nodeIsSynthesized(node)) {
  21818. return false;
  21819. }
  21820. var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 199 || node.parent.kind === 153);
  21821. var targetDeclaration = isVariableDeclarationOrBindingElement
  21822. ? node.parent
  21823. : resolver.getReferencedValueDeclaration(node);
  21824. return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, true);
  21825. }
  21826. function emitPrefixUnaryExpression(node) {
  21827. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
  21828. if (exportChanged) {
  21829. write(exportFunctionForFile + "(\"");
  21830. emitNodeWithoutSourceMap(node.operand);
  21831. write("\", ");
  21832. }
  21833. write(ts.tokenToString(node.operator));
  21834. if (node.operand.kind === 168) {
  21835. var operand = node.operand;
  21836. if (node.operator === 33 && (operand.operator === 33 || operand.operator === 38)) {
  21837. write(" ");
  21838. }
  21839. else if (node.operator === 34 && (operand.operator === 34 || operand.operator === 39)) {
  21840. write(" ");
  21841. }
  21842. }
  21843. emit(node.operand);
  21844. if (exportChanged) {
  21845. write(")");
  21846. }
  21847. }
  21848. function emitPostfixUnaryExpression(node) {
  21849. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
  21850. if (exportChanged) {
  21851. write("(" + exportFunctionForFile + "(\"");
  21852. emitNodeWithoutSourceMap(node.operand);
  21853. write("\", ");
  21854. write(ts.tokenToString(node.operator));
  21855. emit(node.operand);
  21856. if (node.operator === 38) {
  21857. write(") - 1)");
  21858. }
  21859. else {
  21860. write(") + 1)");
  21861. }
  21862. }
  21863. else {
  21864. emit(node.operand);
  21865. write(ts.tokenToString(node.operator));
  21866. }
  21867. }
  21868. function shouldHoistDeclarationInSystemJsModule(node) {
  21869. return isSourceFileLevelDeclarationInSystemJsModule(node, false);
  21870. }
  21871. function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) {
  21872. if (!node || languageVersion >= 2 || !isCurrentFileSystemExternalModule()) {
  21873. return false;
  21874. }
  21875. var current = node;
  21876. while (current) {
  21877. if (current.kind === 228) {
  21878. return !isExported || ((ts.getCombinedNodeFlags(node) & 1) !== 0);
  21879. }
  21880. else if (ts.isFunctionLike(current) || current.kind === 207) {
  21881. return false;
  21882. }
  21883. else {
  21884. current = current.parent;
  21885. }
  21886. }
  21887. }
  21888. function emitBinaryExpression(node) {
  21889. if (languageVersion < 2 && node.operatorToken.kind === 53 &&
  21890. (node.left.kind === 155 || node.left.kind === 154)) {
  21891. emitDestructuring(node, node.parent.kind === 183);
  21892. }
  21893. else {
  21894. var exportChanged = node.operatorToken.kind >= 53 &&
  21895. node.operatorToken.kind <= 64 &&
  21896. isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left);
  21897. if (exportChanged) {
  21898. write(exportFunctionForFile + "(\"");
  21899. emitNodeWithoutSourceMap(node.left);
  21900. write("\", ");
  21901. }
  21902. emit(node.left);
  21903. var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 23 ? " " : undefined);
  21904. write(ts.tokenToString(node.operatorToken.kind));
  21905. var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " ");
  21906. emit(node.right);
  21907. decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator);
  21908. if (exportChanged) {
  21909. write(")");
  21910. }
  21911. }
  21912. }
  21913. function synthesizedNodeStartsOnNewLine(node) {
  21914. return ts.nodeIsSynthesized(node) && node.startsOnNewLine;
  21915. }
  21916. function emitConditionalExpression(node) {
  21917. emit(node.condition);
  21918. var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " ");
  21919. write("?");
  21920. var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " ");
  21921. emit(node.whenTrue);
  21922. decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion);
  21923. var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " ");
  21924. write(":");
  21925. var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " ");
  21926. emit(node.whenFalse);
  21927. decreaseIndentIf(indentedBeforeColon, indentedAfterColon);
  21928. }
  21929. function decreaseIndentIf(value1, value2) {
  21930. if (value1) {
  21931. decreaseIndent();
  21932. }
  21933. if (value2) {
  21934. decreaseIndent();
  21935. }
  21936. }
  21937. function isSingleLineEmptyBlock(node) {
  21938. if (node && node.kind === 180) {
  21939. var block = node;
  21940. return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block);
  21941. }
  21942. }
  21943. function emitBlock(node) {
  21944. if (isSingleLineEmptyBlock(node)) {
  21945. emitToken(14, node.pos);
  21946. write(" ");
  21947. emitToken(15, node.statements.end);
  21948. return;
  21949. }
  21950. emitToken(14, node.pos);
  21951. increaseIndent();
  21952. scopeEmitStart(node.parent);
  21953. if (node.kind === 207) {
  21954. ts.Debug.assert(node.parent.kind === 206);
  21955. emitCaptureThisForNodeIfNecessary(node.parent);
  21956. }
  21957. emitLines(node.statements);
  21958. if (node.kind === 207) {
  21959. emitTempDeclarations(true);
  21960. }
  21961. decreaseIndent();
  21962. writeLine();
  21963. emitToken(15, node.statements.end);
  21964. scopeEmitEnd();
  21965. }
  21966. function emitEmbeddedStatement(node) {
  21967. if (node.kind === 180) {
  21968. write(" ");
  21969. emit(node);
  21970. }
  21971. else {
  21972. increaseIndent();
  21973. writeLine();
  21974. emit(node);
  21975. decreaseIndent();
  21976. }
  21977. }
  21978. function emitExpressionStatement(node) {
  21979. emitParenthesizedIf(node.expression, node.expression.kind === 164);
  21980. write(";");
  21981. }
  21982. function emitIfStatement(node) {
  21983. var endPos = emitToken(84, node.pos);
  21984. write(" ");
  21985. endPos = emitToken(16, endPos);
  21986. emit(node.expression);
  21987. emitToken(17, node.expression.end);
  21988. emitEmbeddedStatement(node.thenStatement);
  21989. if (node.elseStatement) {
  21990. writeLine();
  21991. emitToken(76, node.thenStatement.end);
  21992. if (node.elseStatement.kind === 184) {
  21993. write(" ");
  21994. emit(node.elseStatement);
  21995. }
  21996. else {
  21997. emitEmbeddedStatement(node.elseStatement);
  21998. }
  21999. }
  22000. }
  22001. function emitDoStatement(node) {
  22002. write("do");
  22003. emitEmbeddedStatement(node.statement);
  22004. if (node.statement.kind === 180) {
  22005. write(" ");
  22006. }
  22007. else {
  22008. writeLine();
  22009. }
  22010. write("while (");
  22011. emit(node.expression);
  22012. write(");");
  22013. }
  22014. function emitWhileStatement(node) {
  22015. write("while (");
  22016. emit(node.expression);
  22017. write(")");
  22018. emitEmbeddedStatement(node.statement);
  22019. }
  22020. function tryEmitStartOfVariableDeclarationList(decl, startPos) {
  22021. if (shouldHoistVariable(decl, true)) {
  22022. return false;
  22023. }
  22024. var tokenKind = 98;
  22025. if (decl && languageVersion >= 2) {
  22026. if (ts.isLet(decl)) {
  22027. tokenKind = 104;
  22028. }
  22029. else if (ts.isConst(decl)) {
  22030. tokenKind = 70;
  22031. }
  22032. }
  22033. if (startPos !== undefined) {
  22034. emitToken(tokenKind, startPos);
  22035. write(" ");
  22036. }
  22037. else {
  22038. switch (tokenKind) {
  22039. case 98:
  22040. write("var ");
  22041. break;
  22042. case 104:
  22043. write("let ");
  22044. break;
  22045. case 70:
  22046. write("const ");
  22047. break;
  22048. }
  22049. }
  22050. return true;
  22051. }
  22052. function emitVariableDeclarationListSkippingUninitializedEntries(list) {
  22053. var started = false;
  22054. for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) {
  22055. var decl = _b[_a];
  22056. if (!decl.initializer) {
  22057. continue;
  22058. }
  22059. if (!started) {
  22060. started = true;
  22061. }
  22062. else {
  22063. write(", ");
  22064. }
  22065. emit(decl);
  22066. }
  22067. return started;
  22068. }
  22069. function emitForStatement(node) {
  22070. var endPos = emitToken(82, node.pos);
  22071. write(" ");
  22072. endPos = emitToken(16, endPos);
  22073. if (node.initializer && node.initializer.kind === 200) {
  22074. var variableDeclarationList = node.initializer;
  22075. var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
  22076. if (startIsEmitted) {
  22077. emitCommaList(variableDeclarationList.declarations);
  22078. }
  22079. else {
  22080. emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList);
  22081. }
  22082. }
  22083. else if (node.initializer) {
  22084. emit(node.initializer);
  22085. }
  22086. write(";");
  22087. emitOptional(" ", node.condition);
  22088. write(";");
  22089. emitOptional(" ", node.incrementor);
  22090. write(")");
  22091. emitEmbeddedStatement(node.statement);
  22092. }
  22093. function emitForInOrForOfStatement(node) {
  22094. if (languageVersion < 2 && node.kind === 189) {
  22095. return emitDownLevelForOfStatement(node);
  22096. }
  22097. var endPos = emitToken(82, node.pos);
  22098. write(" ");
  22099. endPos = emitToken(16, endPos);
  22100. if (node.initializer.kind === 200) {
  22101. var variableDeclarationList = node.initializer;
  22102. if (variableDeclarationList.declarations.length >= 1) {
  22103. tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
  22104. emit(variableDeclarationList.declarations[0]);
  22105. }
  22106. }
  22107. else {
  22108. emit(node.initializer);
  22109. }
  22110. if (node.kind === 188) {
  22111. write(" in ");
  22112. }
  22113. else {
  22114. write(" of ");
  22115. }
  22116. emit(node.expression);
  22117. emitToken(17, node.expression.end);
  22118. emitEmbeddedStatement(node.statement);
  22119. }
  22120. function emitDownLevelForOfStatement(node) {
  22121. // The following ES6 code:
  22122. //
  22123. // for (let v of expr) { }
  22124. //
  22125. // should be emitted as
  22126. //
  22127. // for (let _i = 0, _a = expr; _i < _a.length; _i++) {
  22128. // let v = _a[_i];
  22129. // }
  22130. //
  22131. // where _a and _i are temps emitted to capture the RHS and the counter,
  22132. // respectively.
  22133. // When the left hand side is an expression instead of a let declaration,
  22134. // the "let v" is not emitted.
  22135. // When the left hand side is a let/const, the v is renamed if there is
  22136. // another v in scope.
  22137. // Note that all assignments to the LHS are emitted in the body, including
  22138. // all destructuring.
  22139. // Note also that because an extra statement is needed to assign to the LHS,
  22140. // for-of bodies are always emitted as blocks.
  22141. var endPos = emitToken(82, node.pos);
  22142. write(" ");
  22143. endPos = emitToken(16, endPos);
  22144. var rhsIsIdentifier = node.expression.kind === 65;
  22145. var counter = createTempVariable(268435456);
  22146. var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0);
  22147. emitStart(node.expression);
  22148. write("var ");
  22149. emitNodeWithoutSourceMap(counter);
  22150. write(" = 0");
  22151. emitEnd(node.expression);
  22152. if (!rhsIsIdentifier) {
  22153. write(", ");
  22154. emitStart(node.expression);
  22155. emitNodeWithoutSourceMap(rhsReference);
  22156. write(" = ");
  22157. emitNodeWithoutSourceMap(node.expression);
  22158. emitEnd(node.expression);
  22159. }
  22160. write("; ");
  22161. emitStart(node.initializer);
  22162. emitNodeWithoutSourceMap(counter);
  22163. write(" < ");
  22164. emitNodeWithoutSourceMap(rhsReference);
  22165. write(".length");
  22166. emitEnd(node.initializer);
  22167. write("; ");
  22168. emitStart(node.initializer);
  22169. emitNodeWithoutSourceMap(counter);
  22170. write("++");
  22171. emitEnd(node.initializer);
  22172. emitToken(17, node.expression.end);
  22173. write(" {");
  22174. writeLine();
  22175. increaseIndent();
  22176. var rhsIterationValue = createElementAccessExpression(rhsReference, counter);
  22177. emitStart(node.initializer);
  22178. if (node.initializer.kind === 200) {
  22179. write("var ");
  22180. var variableDeclarationList = node.initializer;
  22181. if (variableDeclarationList.declarations.length > 0) {
  22182. var declaration = variableDeclarationList.declarations[0];
  22183. if (ts.isBindingPattern(declaration.name)) {
  22184. emitDestructuring(declaration, false, rhsIterationValue);
  22185. }
  22186. else {
  22187. emitNodeWithoutSourceMap(declaration);
  22188. write(" = ");
  22189. emitNodeWithoutSourceMap(rhsIterationValue);
  22190. }
  22191. }
  22192. else {
  22193. emitNodeWithoutSourceMap(createTempVariable(0));
  22194. write(" = ");
  22195. emitNodeWithoutSourceMap(rhsIterationValue);
  22196. }
  22197. }
  22198. else {
  22199. var assignmentExpression = createBinaryExpression(node.initializer, 53, rhsIterationValue, false);
  22200. if (node.initializer.kind === 154 || node.initializer.kind === 155) {
  22201. emitDestructuring(assignmentExpression, true, undefined);
  22202. }
  22203. else {
  22204. emitNodeWithoutSourceMap(assignmentExpression);
  22205. }
  22206. }
  22207. emitEnd(node.initializer);
  22208. write(";");
  22209. if (node.statement.kind === 180) {
  22210. emitLines(node.statement.statements);
  22211. }
  22212. else {
  22213. writeLine();
  22214. emit(node.statement);
  22215. }
  22216. writeLine();
  22217. decreaseIndent();
  22218. write("}");
  22219. }
  22220. function emitBreakOrContinueStatement(node) {
  22221. emitToken(node.kind === 191 ? 66 : 71, node.pos);
  22222. emitOptional(" ", node.label);
  22223. write(";");
  22224. }
  22225. function emitReturnStatement(node) {
  22226. emitToken(90, node.pos);
  22227. emitOptional(" ", node.expression);
  22228. write(";");
  22229. }
  22230. function emitWithStatement(node) {
  22231. write("with (");
  22232. emit(node.expression);
  22233. write(")");
  22234. emitEmbeddedStatement(node.statement);
  22235. }
  22236. function emitSwitchStatement(node) {
  22237. var endPos = emitToken(92, node.pos);
  22238. write(" ");
  22239. emitToken(16, endPos);
  22240. emit(node.expression);
  22241. endPos = emitToken(17, node.expression.end);
  22242. write(" ");
  22243. emitCaseBlock(node.caseBlock, endPos);
  22244. }
  22245. function emitCaseBlock(node, startPos) {
  22246. emitToken(14, startPos);
  22247. increaseIndent();
  22248. emitLines(node.clauses);
  22249. decreaseIndent();
  22250. writeLine();
  22251. emitToken(15, node.clauses.end);
  22252. }
  22253. function nodeStartPositionsAreOnSameLine(node1, node2) {
  22254. return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) ===
  22255. ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
  22256. }
  22257. function nodeEndPositionsAreOnSameLine(node1, node2) {
  22258. return ts.getLineOfLocalPosition(currentSourceFile, node1.end) ===
  22259. ts.getLineOfLocalPosition(currentSourceFile, node2.end);
  22260. }
  22261. function nodeEndIsOnSameLineAsNodeStart(node1, node2) {
  22262. return ts.getLineOfLocalPosition(currentSourceFile, node1.end) ===
  22263. ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
  22264. }
  22265. function emitCaseOrDefaultClause(node) {
  22266. if (node.kind === 221) {
  22267. write("case ");
  22268. emit(node.expression);
  22269. write(":");
  22270. }
  22271. else {
  22272. write("default:");
  22273. }
  22274. if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) {
  22275. write(" ");
  22276. emit(node.statements[0]);
  22277. }
  22278. else {
  22279. increaseIndent();
  22280. emitLines(node.statements);
  22281. decreaseIndent();
  22282. }
  22283. }
  22284. function emitThrowStatement(node) {
  22285. write("throw ");
  22286. emit(node.expression);
  22287. write(";");
  22288. }
  22289. function emitTryStatement(node) {
  22290. write("try ");
  22291. emit(node.tryBlock);
  22292. emit(node.catchClause);
  22293. if (node.finallyBlock) {
  22294. writeLine();
  22295. write("finally ");
  22296. emit(node.finallyBlock);
  22297. }
  22298. }
  22299. function emitCatchClause(node) {
  22300. writeLine();
  22301. var endPos = emitToken(68, node.pos);
  22302. write(" ");
  22303. emitToken(16, endPos);
  22304. emit(node.variableDeclaration);
  22305. emitToken(17, node.variableDeclaration ? node.variableDeclaration.end : endPos);
  22306. write(" ");
  22307. emitBlock(node.block);
  22308. }
  22309. function emitDebuggerStatement(node) {
  22310. emitToken(72, node.pos);
  22311. write(";");
  22312. }
  22313. function emitLabelledStatement(node) {
  22314. emit(node.label);
  22315. write(": ");
  22316. emit(node.statement);
  22317. }
  22318. function getContainingModule(node) {
  22319. do {
  22320. node = node.parent;
  22321. } while (node && node.kind !== 206);
  22322. return node;
  22323. }
  22324. function emitContainingModuleName(node) {
  22325. var container = getContainingModule(node);
  22326. write(container ? getGeneratedNameForNode(container) : "exports");
  22327. }
  22328. function emitModuleMemberName(node) {
  22329. emitStart(node.name);
  22330. if (ts.getCombinedNodeFlags(node) & 1) {
  22331. var container = getContainingModule(node);
  22332. if (container) {
  22333. write(getGeneratedNameForNode(container));
  22334. write(".");
  22335. }
  22336. else if (languageVersion < 2 && compilerOptions.module !== 4) {
  22337. write("exports.");
  22338. }
  22339. }
  22340. emitNodeWithoutSourceMap(node.name);
  22341. emitEnd(node.name);
  22342. }
  22343. function createVoidZero() {
  22344. var zero = ts.createSynthesizedNode(7);
  22345. zero.text = "0";
  22346. var result = ts.createSynthesizedNode(167);
  22347. result.expression = zero;
  22348. return result;
  22349. }
  22350. function emitExportMemberAssignment(node) {
  22351. if (node.flags & 1) {
  22352. writeLine();
  22353. emitStart(node);
  22354. if (compilerOptions.module === 4 && node.parent === currentSourceFile) {
  22355. write(exportFunctionForFile + "(\"");
  22356. if (node.flags & 256) {
  22357. write("default");
  22358. }
  22359. else {
  22360. emitNodeWithoutSourceMap(node.name);
  22361. }
  22362. write("\", ");
  22363. emitDeclarationName(node);
  22364. write(")");
  22365. }
  22366. else {
  22367. if (node.flags & 256) {
  22368. if (languageVersion === 0) {
  22369. write("exports[\"default\"]");
  22370. }
  22371. else {
  22372. write("exports.default");
  22373. }
  22374. }
  22375. else {
  22376. emitModuleMemberName(node);
  22377. }
  22378. write(" = ");
  22379. emitDeclarationName(node);
  22380. }
  22381. emitEnd(node);
  22382. write(";");
  22383. }
  22384. }
  22385. function emitExportMemberAssignments(name) {
  22386. if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) {
  22387. for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) {
  22388. var specifier = _b[_a];
  22389. writeLine();
  22390. if (compilerOptions.module === 4) {
  22391. emitStart(specifier.name);
  22392. write(exportFunctionForFile + "(\"");
  22393. emitNodeWithoutSourceMap(specifier.name);
  22394. write("\", ");
  22395. emitExpressionIdentifier(name);
  22396. write(")");
  22397. emitEnd(specifier.name);
  22398. }
  22399. else {
  22400. emitStart(specifier.name);
  22401. emitContainingModuleName(specifier);
  22402. write(".");
  22403. emitNodeWithoutSourceMap(specifier.name);
  22404. emitEnd(specifier.name);
  22405. write(" = ");
  22406. emitExpressionIdentifier(name);
  22407. }
  22408. write(";");
  22409. }
  22410. }
  22411. }
  22412. function emitDestructuring(root, isAssignmentExpressionStatement, value) {
  22413. var emitCount = 0;
  22414. var canDefineTempVariablesInPlace = false;
  22415. if (root.kind === 199) {
  22416. var isExported = ts.getCombinedNodeFlags(root) & 1;
  22417. var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root);
  22418. canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind;
  22419. }
  22420. else if (root.kind === 130) {
  22421. canDefineTempVariablesInPlace = true;
  22422. }
  22423. if (root.kind === 170) {
  22424. emitAssignmentExpression(root);
  22425. }
  22426. else {
  22427. ts.Debug.assert(!isAssignmentExpressionStatement);
  22428. emitBindingElement(root, value);
  22429. }
  22430. function emitAssignment(name, value) {
  22431. if (emitCount++) {
  22432. write(", ");
  22433. }
  22434. renameNonTopLevelLetAndConst(name);
  22435. var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 199 || name.parent.kind === 153);
  22436. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name);
  22437. if (exportChanged) {
  22438. write(exportFunctionForFile + "(\"");
  22439. emitNodeWithoutSourceMap(name);
  22440. write("\", ");
  22441. }
  22442. if (isVariableDeclarationOrBindingElement) {
  22443. emitModuleMemberName(name.parent);
  22444. }
  22445. else {
  22446. emit(name);
  22447. }
  22448. write(" = ");
  22449. emit(value);
  22450. if (exportChanged) {
  22451. write(")");
  22452. }
  22453. }
  22454. function ensureIdentifier(expr) {
  22455. if (expr.kind !== 65) {
  22456. var identifier = createTempVariable(0);
  22457. if (!canDefineTempVariablesInPlace) {
  22458. recordTempDeclaration(identifier);
  22459. }
  22460. emitAssignment(identifier, expr);
  22461. expr = identifier;
  22462. }
  22463. return expr;
  22464. }
  22465. function createDefaultValueCheck(value, defaultValue) {
  22466. value = ensureIdentifier(value);
  22467. var equals = ts.createSynthesizedNode(170);
  22468. equals.left = value;
  22469. equals.operatorToken = ts.createSynthesizedNode(30);
  22470. equals.right = createVoidZero();
  22471. return createConditionalExpression(equals, defaultValue, value);
  22472. }
  22473. function createConditionalExpression(condition, whenTrue, whenFalse) {
  22474. var cond = ts.createSynthesizedNode(171);
  22475. cond.condition = condition;
  22476. cond.questionToken = ts.createSynthesizedNode(50);
  22477. cond.whenTrue = whenTrue;
  22478. cond.colonToken = ts.createSynthesizedNode(51);
  22479. cond.whenFalse = whenFalse;
  22480. return cond;
  22481. }
  22482. function createNumericLiteral(value) {
  22483. var node = ts.createSynthesizedNode(7);
  22484. node.text = "" + value;
  22485. return node;
  22486. }
  22487. function createPropertyAccessForDestructuringProperty(object, propName) {
  22488. if (propName.kind !== 65) {
  22489. return createElementAccessExpression(object, propName);
  22490. }
  22491. return createPropertyAccessExpression(object, propName);
  22492. }
  22493. function createSliceCall(value, sliceIndex) {
  22494. var call = ts.createSynthesizedNode(158);
  22495. var sliceIdentifier = ts.createSynthesizedNode(65);
  22496. sliceIdentifier.text = "slice";
  22497. call.expression = createPropertyAccessExpression(value, sliceIdentifier);
  22498. call.arguments = ts.createSynthesizedNodeArray();
  22499. call.arguments[0] = createNumericLiteral(sliceIndex);
  22500. return call;
  22501. }
  22502. function emitObjectLiteralAssignment(target, value) {
  22503. var properties = target.properties;
  22504. if (properties.length !== 1) {
  22505. value = ensureIdentifier(value);
  22506. }
  22507. for (var _a = 0; _a < properties.length; _a++) {
  22508. var p = properties[_a];
  22509. if (p.kind === 225 || p.kind === 226) {
  22510. var propName = (p.name);
  22511. emitDestructuringAssignment(p.initializer || propName, createPropertyAccessForDestructuringProperty(value, propName));
  22512. }
  22513. }
  22514. }
  22515. function emitArrayLiteralAssignment(target, value) {
  22516. var elements = target.elements;
  22517. if (elements.length !== 1) {
  22518. value = ensureIdentifier(value);
  22519. }
  22520. for (var i = 0; i < elements.length; i++) {
  22521. var e = elements[i];
  22522. if (e.kind !== 176) {
  22523. if (e.kind !== 174) {
  22524. emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i)));
  22525. }
  22526. else if (i === elements.length - 1) {
  22527. emitDestructuringAssignment(e.expression, createSliceCall(value, i));
  22528. }
  22529. }
  22530. }
  22531. }
  22532. function emitDestructuringAssignment(target, value) {
  22533. if (target.kind === 170 && target.operatorToken.kind === 53) {
  22534. value = createDefaultValueCheck(value, target.right);
  22535. target = target.left;
  22536. }
  22537. if (target.kind === 155) {
  22538. emitObjectLiteralAssignment(target, value);
  22539. }
  22540. else if (target.kind === 154) {
  22541. emitArrayLiteralAssignment(target, value);
  22542. }
  22543. else {
  22544. emitAssignment(target, value);
  22545. }
  22546. }
  22547. function emitAssignmentExpression(root) {
  22548. var target = root.left;
  22549. var value = root.right;
  22550. if (isAssignmentExpressionStatement) {
  22551. emitDestructuringAssignment(target, value);
  22552. }
  22553. else {
  22554. if (root.parent.kind !== 162) {
  22555. write("(");
  22556. }
  22557. value = ensureIdentifier(value);
  22558. emitDestructuringAssignment(target, value);
  22559. write(", ");
  22560. emit(value);
  22561. if (root.parent.kind !== 162) {
  22562. write(")");
  22563. }
  22564. }
  22565. }
  22566. function emitBindingElement(target, value) {
  22567. if (target.initializer) {
  22568. value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer;
  22569. }
  22570. else if (!value) {
  22571. value = createVoidZero();
  22572. }
  22573. if (ts.isBindingPattern(target.name)) {
  22574. var pattern = target.name;
  22575. var elements = pattern.elements;
  22576. if (elements.length !== 1) {
  22577. value = ensureIdentifier(value);
  22578. }
  22579. for (var i = 0; i < elements.length; i++) {
  22580. var element = elements[i];
  22581. if (pattern.kind === 151) {
  22582. var propName = element.propertyName || element.name;
  22583. emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName));
  22584. }
  22585. else if (element.kind !== 176) {
  22586. if (!element.dotDotDotToken) {
  22587. emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i)));
  22588. }
  22589. else if (i === elements.length - 1) {
  22590. emitBindingElement(element, createSliceCall(value, i));
  22591. }
  22592. }
  22593. }
  22594. }
  22595. else {
  22596. emitAssignment(target.name, value);
  22597. }
  22598. }
  22599. }
  22600. function emitVariableDeclaration(node) {
  22601. if (ts.isBindingPattern(node.name)) {
  22602. if (languageVersion < 2) {
  22603. emitDestructuring(node, false);
  22604. }
  22605. else {
  22606. emit(node.name);
  22607. emitOptional(" = ", node.initializer);
  22608. }
  22609. }
  22610. else {
  22611. renameNonTopLevelLetAndConst(node.name);
  22612. var initializer = node.initializer;
  22613. if (!initializer && languageVersion < 2) {
  22614. var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 256) &&
  22615. (getCombinedFlagsForIdentifier(node.name) & 4096);
  22616. if (isUninitializedLet &&
  22617. node.parent.parent.kind !== 188 &&
  22618. node.parent.parent.kind !== 189) {
  22619. initializer = createVoidZero();
  22620. }
  22621. }
  22622. var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name);
  22623. if (exportChanged) {
  22624. write(exportFunctionForFile + "(\"");
  22625. emitNodeWithoutSourceMap(node.name);
  22626. write("\", ");
  22627. }
  22628. emitModuleMemberName(node);
  22629. emitOptional(" = ", initializer);
  22630. if (exportChanged) {
  22631. write(")");
  22632. }
  22633. }
  22634. }
  22635. function emitExportVariableAssignments(node) {
  22636. if (node.kind === 176) {
  22637. return;
  22638. }
  22639. var name = node.name;
  22640. if (name.kind === 65) {
  22641. emitExportMemberAssignments(name);
  22642. }
  22643. else if (ts.isBindingPattern(name)) {
  22644. ts.forEach(name.elements, emitExportVariableAssignments);
  22645. }
  22646. }
  22647. function getCombinedFlagsForIdentifier(node) {
  22648. if (!node.parent || (node.parent.kind !== 199 && node.parent.kind !== 153)) {
  22649. return 0;
  22650. }
  22651. return ts.getCombinedNodeFlags(node.parent);
  22652. }
  22653. function renameNonTopLevelLetAndConst(node) {
  22654. if (languageVersion >= 2 ||
  22655. ts.nodeIsSynthesized(node) ||
  22656. node.kind !== 65 ||
  22657. (node.parent.kind !== 199 && node.parent.kind !== 153)) {
  22658. return;
  22659. }
  22660. var combinedFlags = getCombinedFlagsForIdentifier(node);
  22661. if (((combinedFlags & 12288) === 0) || combinedFlags & 1) {
  22662. return;
  22663. }
  22664. var list = ts.getAncestor(node, 200);
  22665. if (list.parent.kind === 181) {
  22666. var isSourceFileLevelBinding = list.parent.parent.kind === 228;
  22667. var isModuleLevelBinding = list.parent.parent.kind === 207;
  22668. var isFunctionLevelBinding = list.parent.parent.kind === 180 && ts.isFunctionLike(list.parent.parent.parent);
  22669. if (isSourceFileLevelBinding || isModuleLevelBinding || isFunctionLevelBinding) {
  22670. return;
  22671. }
  22672. }
  22673. var blockScopeContainer = ts.getEnclosingBlockScopeContainer(node);
  22674. var parent = blockScopeContainer.kind === 228
  22675. ? blockScopeContainer
  22676. : blockScopeContainer.parent;
  22677. if (resolver.resolvesToSomeValue(parent, node.text)) {
  22678. var variableId = resolver.getBlockScopedVariableId(node);
  22679. if (!blockScopedVariableToGeneratedName) {
  22680. blockScopedVariableToGeneratedName = [];
  22681. }
  22682. var generatedName = makeUniqueName(node.text);
  22683. blockScopedVariableToGeneratedName[variableId] = generatedName;
  22684. }
  22685. }
  22686. function isES6ExportedDeclaration(node) {
  22687. return !!(node.flags & 1) &&
  22688. languageVersion >= 2 &&
  22689. node.parent.kind === 228;
  22690. }
  22691. function emitVariableStatement(node) {
  22692. var startIsEmitted = true;
  22693. if (!(node.flags & 1)) {
  22694. startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
  22695. }
  22696. else if (isES6ExportedDeclaration(node)) {
  22697. write("export ");
  22698. startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
  22699. }
  22700. if (startIsEmitted) {
  22701. emitCommaList(node.declarationList.declarations);
  22702. write(";");
  22703. }
  22704. else {
  22705. var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList);
  22706. if (atLeastOneItem) {
  22707. write(";");
  22708. }
  22709. }
  22710. if (languageVersion < 2 && node.parent === currentSourceFile) {
  22711. ts.forEach(node.declarationList.declarations, emitExportVariableAssignments);
  22712. }
  22713. }
  22714. function emitParameter(node) {
  22715. if (languageVersion < 2) {
  22716. if (ts.isBindingPattern(node.name)) {
  22717. var name_19 = createTempVariable(0);
  22718. if (!tempParameters) {
  22719. tempParameters = [];
  22720. }
  22721. tempParameters.push(name_19);
  22722. emit(name_19);
  22723. }
  22724. else {
  22725. emit(node.name);
  22726. }
  22727. }
  22728. else {
  22729. if (node.dotDotDotToken) {
  22730. write("...");
  22731. }
  22732. emit(node.name);
  22733. emitOptional(" = ", node.initializer);
  22734. }
  22735. }
  22736. function emitDefaultValueAssignments(node) {
  22737. if (languageVersion < 2) {
  22738. var tempIndex = 0;
  22739. ts.forEach(node.parameters, function (p) {
  22740. if (p.dotDotDotToken) {
  22741. return;
  22742. }
  22743. if (ts.isBindingPattern(p.name)) {
  22744. writeLine();
  22745. write("var ");
  22746. emitDestructuring(p, false, tempParameters[tempIndex]);
  22747. write(";");
  22748. tempIndex++;
  22749. }
  22750. else if (p.initializer) {
  22751. writeLine();
  22752. emitStart(p);
  22753. write("if (");
  22754. emitNodeWithoutSourceMap(p.name);
  22755. write(" === void 0)");
  22756. emitEnd(p);
  22757. write(" { ");
  22758. emitStart(p);
  22759. emitNodeWithoutSourceMap(p.name);
  22760. write(" = ");
  22761. emitNodeWithoutSourceMap(p.initializer);
  22762. emitEnd(p);
  22763. write("; }");
  22764. }
  22765. });
  22766. }
  22767. }
  22768. function emitRestParameter(node) {
  22769. if (languageVersion < 2 && ts.hasRestParameters(node)) {
  22770. var restIndex = node.parameters.length - 1;
  22771. var restParam = node.parameters[restIndex];
  22772. if (ts.isBindingPattern(restParam.name)) {
  22773. return;
  22774. }
  22775. var tempName = createTempVariable(268435456).text;
  22776. writeLine();
  22777. emitLeadingComments(restParam);
  22778. emitStart(restParam);
  22779. write("var ");
  22780. emitNodeWithoutSourceMap(restParam.name);
  22781. write(" = [];");
  22782. emitEnd(restParam);
  22783. emitTrailingComments(restParam);
  22784. writeLine();
  22785. write("for (");
  22786. emitStart(restParam);
  22787. write("var " + tempName + " = " + restIndex + ";");
  22788. emitEnd(restParam);
  22789. write(" ");
  22790. emitStart(restParam);
  22791. write(tempName + " < arguments.length;");
  22792. emitEnd(restParam);
  22793. write(" ");
  22794. emitStart(restParam);
  22795. write(tempName + "++");
  22796. emitEnd(restParam);
  22797. write(") {");
  22798. increaseIndent();
  22799. writeLine();
  22800. emitStart(restParam);
  22801. emitNodeWithoutSourceMap(restParam.name);
  22802. write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];");
  22803. emitEnd(restParam);
  22804. decreaseIndent();
  22805. writeLine();
  22806. write("}");
  22807. }
  22808. }
  22809. function emitAccessor(node) {
  22810. write(node.kind === 137 ? "get " : "set ");
  22811. emit(node.name, false);
  22812. emitSignatureAndBody(node);
  22813. }
  22814. function shouldEmitAsArrowFunction(node) {
  22815. return node.kind === 164 && languageVersion >= 2;
  22816. }
  22817. function emitDeclarationName(node) {
  22818. if (node.name) {
  22819. emitNodeWithoutSourceMap(node.name);
  22820. }
  22821. else {
  22822. write(getGeneratedNameForNode(node));
  22823. }
  22824. }
  22825. function shouldEmitFunctionName(node) {
  22826. if (node.kind === 163) {
  22827. return !!node.name;
  22828. }
  22829. if (node.kind === 201) {
  22830. return !!node.name || languageVersion < 2;
  22831. }
  22832. }
  22833. function emitFunctionDeclaration(node) {
  22834. if (ts.nodeIsMissing(node.body)) {
  22835. return emitOnlyPinnedOrTripleSlashComments(node);
  22836. }
  22837. if (node.kind !== 135 && node.kind !== 134) {
  22838. emitLeadingComments(node);
  22839. }
  22840. if (!shouldEmitAsArrowFunction(node)) {
  22841. if (isES6ExportedDeclaration(node)) {
  22842. write("export ");
  22843. if (node.flags & 256) {
  22844. write("default ");
  22845. }
  22846. }
  22847. write("function");
  22848. if (languageVersion >= 2 && node.asteriskToken) {
  22849. write("*");
  22850. }
  22851. write(" ");
  22852. }
  22853. if (shouldEmitFunctionName(node)) {
  22854. emitDeclarationName(node);
  22855. }
  22856. emitSignatureAndBody(node);
  22857. if (languageVersion < 2 && node.kind === 201 && node.parent === currentSourceFile && node.name) {
  22858. emitExportMemberAssignments(node.name);
  22859. }
  22860. if (node.kind !== 135 && node.kind !== 134) {
  22861. emitTrailingComments(node);
  22862. }
  22863. }
  22864. function emitCaptureThisForNodeIfNecessary(node) {
  22865. if (resolver.getNodeCheckFlags(node) & 4) {
  22866. writeLine();
  22867. emitStart(node);
  22868. write("var _this = this;");
  22869. emitEnd(node);
  22870. }
  22871. }
  22872. function emitSignatureParameters(node) {
  22873. increaseIndent();
  22874. write("(");
  22875. if (node) {
  22876. var parameters = node.parameters;
  22877. var omitCount = languageVersion < 2 && ts.hasRestParameters(node) ? 1 : 0;
  22878. emitList(parameters, 0, parameters.length - omitCount, false, false);
  22879. }
  22880. write(")");
  22881. decreaseIndent();
  22882. }
  22883. function emitSignatureParametersForArrow(node) {
  22884. if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) {
  22885. emit(node.parameters[0]);
  22886. return;
  22887. }
  22888. emitSignatureParameters(node);
  22889. }
  22890. function emitSignatureAndBody(node) {
  22891. var saveTempFlags = tempFlags;
  22892. var saveTempVariables = tempVariables;
  22893. var saveTempParameters = tempParameters;
  22894. tempFlags = 0;
  22895. tempVariables = undefined;
  22896. tempParameters = undefined;
  22897. if (shouldEmitAsArrowFunction(node)) {
  22898. emitSignatureParametersForArrow(node);
  22899. write(" =>");
  22900. }
  22901. else {
  22902. emitSignatureParameters(node);
  22903. }
  22904. if (!node.body) {
  22905. write(" { }");
  22906. }
  22907. else if (node.body.kind === 180) {
  22908. emitBlockFunctionBody(node, node.body);
  22909. }
  22910. else {
  22911. emitExpressionFunctionBody(node, node.body);
  22912. }
  22913. if (!isES6ExportedDeclaration(node)) {
  22914. emitExportMemberAssignment(node);
  22915. }
  22916. tempFlags = saveTempFlags;
  22917. tempVariables = saveTempVariables;
  22918. tempParameters = saveTempParameters;
  22919. }
  22920. function emitFunctionBodyPreamble(node) {
  22921. emitCaptureThisForNodeIfNecessary(node);
  22922. emitDefaultValueAssignments(node);
  22923. emitRestParameter(node);
  22924. }
  22925. function emitExpressionFunctionBody(node, body) {
  22926. if (languageVersion < 2) {
  22927. emitDownLevelExpressionFunctionBody(node, body);
  22928. return;
  22929. }
  22930. write(" ");
  22931. var current = body;
  22932. while (current.kind === 161) {
  22933. current = current.expression;
  22934. }
  22935. emitParenthesizedIf(body, current.kind === 155);
  22936. }
  22937. function emitDownLevelExpressionFunctionBody(node, body) {
  22938. write(" {");
  22939. scopeEmitStart(node);
  22940. increaseIndent();
  22941. var outPos = writer.getTextPos();
  22942. emitDetachedComments(node.body);
  22943. emitFunctionBodyPreamble(node);
  22944. var preambleEmitted = writer.getTextPos() !== outPos;
  22945. decreaseIndent();
  22946. if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) {
  22947. write(" ");
  22948. emitStart(body);
  22949. write("return ");
  22950. emit(body);
  22951. emitEnd(body);
  22952. write(";");
  22953. emitTempDeclarations(false);
  22954. write(" ");
  22955. }
  22956. else {
  22957. increaseIndent();
  22958. writeLine();
  22959. emitLeadingComments(node.body);
  22960. write("return ");
  22961. emit(body);
  22962. write(";");
  22963. emitTrailingComments(node.body);
  22964. emitTempDeclarations(true);
  22965. decreaseIndent();
  22966. writeLine();
  22967. }
  22968. emitStart(node.body);
  22969. write("}");
  22970. emitEnd(node.body);
  22971. scopeEmitEnd();
  22972. }
  22973. function emitBlockFunctionBody(node, body) {
  22974. write(" {");
  22975. scopeEmitStart(node);
  22976. var initialTextPos = writer.getTextPos();
  22977. increaseIndent();
  22978. emitDetachedComments(body.statements);
  22979. var startIndex = emitDirectivePrologues(body.statements, true);
  22980. emitFunctionBodyPreamble(node);
  22981. decreaseIndent();
  22982. var preambleEmitted = writer.getTextPos() !== initialTextPos;
  22983. if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
  22984. for (var _a = 0, _b = body.statements; _a < _b.length; _a++) {
  22985. var statement = _b[_a];
  22986. write(" ");
  22987. emit(statement);
  22988. }
  22989. emitTempDeclarations(false);
  22990. write(" ");
  22991. emitLeadingCommentsOfPosition(body.statements.end);
  22992. }
  22993. else {
  22994. increaseIndent();
  22995. emitLinesStartingAt(body.statements, startIndex);
  22996. emitTempDeclarations(true);
  22997. writeLine();
  22998. emitLeadingCommentsOfPosition(body.statements.end);
  22999. decreaseIndent();
  23000. }
  23001. emitToken(15, body.statements.end);
  23002. scopeEmitEnd();
  23003. }
  23004. function findInitialSuperCall(ctor) {
  23005. if (ctor.body) {
  23006. var statement = ctor.body.statements[0];
  23007. if (statement && statement.kind === 183) {
  23008. var expr = statement.expression;
  23009. if (expr && expr.kind === 158) {
  23010. var func = expr.expression;
  23011. if (func && func.kind === 91) {
  23012. return statement;
  23013. }
  23014. }
  23015. }
  23016. }
  23017. }
  23018. function emitParameterPropertyAssignments(node) {
  23019. ts.forEach(node.parameters, function (param) {
  23020. if (param.flags & 112) {
  23021. writeLine();
  23022. emitStart(param);
  23023. emitStart(param.name);
  23024. write("this.");
  23025. emitNodeWithoutSourceMap(param.name);
  23026. emitEnd(param.name);
  23027. write(" = ");
  23028. emit(param.name);
  23029. write(";");
  23030. emitEnd(param);
  23031. }
  23032. });
  23033. }
  23034. function emitMemberAccessForPropertyName(memberName) {
  23035. if (memberName.kind === 8 || memberName.kind === 7) {
  23036. write("[");
  23037. emitNodeWithoutSourceMap(memberName);
  23038. write("]");
  23039. }
  23040. else if (memberName.kind === 128) {
  23041. emitComputedPropertyName(memberName);
  23042. }
  23043. else {
  23044. write(".");
  23045. emitNodeWithoutSourceMap(memberName);
  23046. }
  23047. }
  23048. function getInitializedProperties(node, isStatic) {
  23049. var properties = [];
  23050. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  23051. var member = _b[_a];
  23052. if (member.kind === 133 && isStatic === ((member.flags & 128) !== 0) && member.initializer) {
  23053. properties.push(member);
  23054. }
  23055. }
  23056. return properties;
  23057. }
  23058. function emitPropertyDeclarations(node, properties) {
  23059. for (var _a = 0; _a < properties.length; _a++) {
  23060. var property = properties[_a];
  23061. emitPropertyDeclaration(node, property);
  23062. }
  23063. }
  23064. function emitPropertyDeclaration(node, property, receiver, isExpression) {
  23065. writeLine();
  23066. emitLeadingComments(property);
  23067. emitStart(property);
  23068. emitStart(property.name);
  23069. if (receiver) {
  23070. emit(receiver);
  23071. }
  23072. else {
  23073. if (property.flags & 128) {
  23074. emitDeclarationName(node);
  23075. }
  23076. else {
  23077. write("this");
  23078. }
  23079. }
  23080. emitMemberAccessForPropertyName(property.name);
  23081. emitEnd(property.name);
  23082. write(" = ");
  23083. emit(property.initializer);
  23084. if (!isExpression) {
  23085. write(";");
  23086. }
  23087. emitEnd(property);
  23088. emitTrailingComments(property);
  23089. }
  23090. function emitMemberFunctionsForES5AndLower(node) {
  23091. ts.forEach(node.members, function (member) {
  23092. if (member.kind === 179) {
  23093. writeLine();
  23094. write(";");
  23095. }
  23096. else if (member.kind === 135 || node.kind === 134) {
  23097. if (!member.body) {
  23098. return emitOnlyPinnedOrTripleSlashComments(member);
  23099. }
  23100. writeLine();
  23101. emitLeadingComments(member);
  23102. emitStart(member);
  23103. emitStart(member.name);
  23104. emitClassMemberPrefix(node, member);
  23105. emitMemberAccessForPropertyName(member.name);
  23106. emitEnd(member.name);
  23107. write(" = ");
  23108. emitStart(member);
  23109. emitFunctionDeclaration(member);
  23110. emitEnd(member);
  23111. emitEnd(member);
  23112. write(";");
  23113. emitTrailingComments(member);
  23114. }
  23115. else if (member.kind === 137 || member.kind === 138) {
  23116. var accessors = ts.getAllAccessorDeclarations(node.members, member);
  23117. if (member === accessors.firstAccessor) {
  23118. writeLine();
  23119. emitStart(member);
  23120. write("Object.defineProperty(");
  23121. emitStart(member.name);
  23122. emitClassMemberPrefix(node, member);
  23123. write(", ");
  23124. emitExpressionForPropertyName(member.name);
  23125. emitEnd(member.name);
  23126. write(", {");
  23127. increaseIndent();
  23128. if (accessors.getAccessor) {
  23129. writeLine();
  23130. emitLeadingComments(accessors.getAccessor);
  23131. write("get: ");
  23132. emitStart(accessors.getAccessor);
  23133. write("function ");
  23134. emitSignatureAndBody(accessors.getAccessor);
  23135. emitEnd(accessors.getAccessor);
  23136. emitTrailingComments(accessors.getAccessor);
  23137. write(",");
  23138. }
  23139. if (accessors.setAccessor) {
  23140. writeLine();
  23141. emitLeadingComments(accessors.setAccessor);
  23142. write("set: ");
  23143. emitStart(accessors.setAccessor);
  23144. write("function ");
  23145. emitSignatureAndBody(accessors.setAccessor);
  23146. emitEnd(accessors.setAccessor);
  23147. emitTrailingComments(accessors.setAccessor);
  23148. write(",");
  23149. }
  23150. writeLine();
  23151. write("enumerable: true,");
  23152. writeLine();
  23153. write("configurable: true");
  23154. decreaseIndent();
  23155. writeLine();
  23156. write("});");
  23157. emitEnd(member);
  23158. }
  23159. }
  23160. });
  23161. }
  23162. function emitMemberFunctionsForES6AndHigher(node) {
  23163. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  23164. var member = _b[_a];
  23165. if ((member.kind === 135 || node.kind === 134) && !member.body) {
  23166. emitOnlyPinnedOrTripleSlashComments(member);
  23167. }
  23168. else if (member.kind === 135 ||
  23169. member.kind === 137 ||
  23170. member.kind === 138) {
  23171. writeLine();
  23172. emitLeadingComments(member);
  23173. emitStart(member);
  23174. if (member.flags & 128) {
  23175. write("static ");
  23176. }
  23177. if (member.kind === 137) {
  23178. write("get ");
  23179. }
  23180. else if (member.kind === 138) {
  23181. write("set ");
  23182. }
  23183. if (member.asteriskToken) {
  23184. write("*");
  23185. }
  23186. emit(member.name);
  23187. emitSignatureAndBody(member);
  23188. emitEnd(member);
  23189. emitTrailingComments(member);
  23190. }
  23191. else if (member.kind === 179) {
  23192. writeLine();
  23193. write(";");
  23194. }
  23195. }
  23196. }
  23197. function emitConstructor(node, baseTypeElement) {
  23198. var saveTempFlags = tempFlags;
  23199. var saveTempVariables = tempVariables;
  23200. var saveTempParameters = tempParameters;
  23201. tempFlags = 0;
  23202. tempVariables = undefined;
  23203. tempParameters = undefined;
  23204. emitConstructorWorker(node, baseTypeElement);
  23205. tempFlags = saveTempFlags;
  23206. tempVariables = saveTempVariables;
  23207. tempParameters = saveTempParameters;
  23208. }
  23209. function emitConstructorWorker(node, baseTypeElement) {
  23210. var hasInstancePropertyWithInitializer = false;
  23211. ts.forEach(node.members, function (member) {
  23212. if (member.kind === 136 && !member.body) {
  23213. emitOnlyPinnedOrTripleSlashComments(member);
  23214. }
  23215. if (member.kind === 133 && member.initializer && (member.flags & 128) === 0) {
  23216. hasInstancePropertyWithInitializer = true;
  23217. }
  23218. });
  23219. var ctor = ts.getFirstConstructorWithBody(node);
  23220. if (languageVersion >= 2 && !ctor && !hasInstancePropertyWithInitializer) {
  23221. return;
  23222. }
  23223. if (ctor) {
  23224. emitLeadingComments(ctor);
  23225. }
  23226. emitStart(ctor || node);
  23227. if (languageVersion < 2) {
  23228. write("function ");
  23229. emitDeclarationName(node);
  23230. emitSignatureParameters(ctor);
  23231. }
  23232. else {
  23233. write("constructor");
  23234. if (ctor) {
  23235. emitSignatureParameters(ctor);
  23236. }
  23237. else {
  23238. if (baseTypeElement) {
  23239. write("(...args)");
  23240. }
  23241. else {
  23242. write("()");
  23243. }
  23244. }
  23245. }
  23246. write(" {");
  23247. scopeEmitStart(node, "constructor");
  23248. increaseIndent();
  23249. if (ctor) {
  23250. emitDetachedComments(ctor.body.statements);
  23251. }
  23252. emitCaptureThisForNodeIfNecessary(node);
  23253. if (ctor) {
  23254. emitDefaultValueAssignments(ctor);
  23255. emitRestParameter(ctor);
  23256. if (baseTypeElement) {
  23257. var superCall = findInitialSuperCall(ctor);
  23258. if (superCall) {
  23259. writeLine();
  23260. emit(superCall);
  23261. }
  23262. }
  23263. emitParameterPropertyAssignments(ctor);
  23264. }
  23265. else {
  23266. if (baseTypeElement) {
  23267. writeLine();
  23268. emitStart(baseTypeElement);
  23269. if (languageVersion < 2) {
  23270. write("_super.apply(this, arguments);");
  23271. }
  23272. else {
  23273. write("super(...args);");
  23274. }
  23275. emitEnd(baseTypeElement);
  23276. }
  23277. }
  23278. emitPropertyDeclarations(node, getInitializedProperties(node, false));
  23279. if (ctor) {
  23280. var statements = ctor.body.statements;
  23281. if (superCall) {
  23282. statements = statements.slice(1);
  23283. }
  23284. emitLines(statements);
  23285. }
  23286. emitTempDeclarations(true);
  23287. writeLine();
  23288. if (ctor) {
  23289. emitLeadingCommentsOfPosition(ctor.body.statements.end);
  23290. }
  23291. decreaseIndent();
  23292. emitToken(15, ctor ? ctor.body.statements.end : node.members.end);
  23293. scopeEmitEnd();
  23294. emitEnd(ctor || node);
  23295. if (ctor) {
  23296. emitTrailingComments(ctor);
  23297. }
  23298. }
  23299. function emitClassExpression(node) {
  23300. return emitClassLikeDeclaration(node);
  23301. }
  23302. function emitClassDeclaration(node) {
  23303. return emitClassLikeDeclaration(node);
  23304. }
  23305. function emitClassLikeDeclaration(node) {
  23306. if (languageVersion < 2) {
  23307. emitClassLikeDeclarationBelowES6(node);
  23308. }
  23309. else {
  23310. emitClassLikeDeclarationForES6AndHigher(node);
  23311. }
  23312. }
  23313. function emitClassLikeDeclarationForES6AndHigher(node) {
  23314. var thisNodeIsDecorated = ts.nodeIsDecorated(node);
  23315. if (node.kind === 202) {
  23316. if (thisNodeIsDecorated) {
  23317. if (isES6ExportedDeclaration(node) && !(node.flags & 256)) {
  23318. write("export ");
  23319. }
  23320. write("let ");
  23321. emitDeclarationName(node);
  23322. write(" = ");
  23323. }
  23324. else if (isES6ExportedDeclaration(node)) {
  23325. write("export ");
  23326. if (node.flags & 256) {
  23327. write("default ");
  23328. }
  23329. }
  23330. }
  23331. var staticProperties = getInitializedProperties(node, true);
  23332. var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 175;
  23333. var tempVariable;
  23334. if (isClassExpressionWithStaticProperties) {
  23335. tempVariable = createAndRecordTempVariable(0);
  23336. write("(");
  23337. increaseIndent();
  23338. emit(tempVariable);
  23339. write(" = ");
  23340. }
  23341. write("class");
  23342. if ((node.name || !(node.flags & 256)) && !thisNodeIsDecorated) {
  23343. write(" ");
  23344. emitDeclarationName(node);
  23345. }
  23346. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  23347. if (baseTypeNode) {
  23348. write(" extends ");
  23349. emit(baseTypeNode.expression);
  23350. }
  23351. write(" {");
  23352. increaseIndent();
  23353. scopeEmitStart(node);
  23354. writeLine();
  23355. emitConstructor(node, baseTypeNode);
  23356. emitMemberFunctionsForES6AndHigher(node);
  23357. decreaseIndent();
  23358. writeLine();
  23359. emitToken(15, node.members.end);
  23360. scopeEmitEnd();
  23361. if (thisNodeIsDecorated) {
  23362. write(";");
  23363. }
  23364. if (isClassExpressionWithStaticProperties) {
  23365. for (var _a = 0; _a < staticProperties.length; _a++) {
  23366. var property = staticProperties[_a];
  23367. write(",");
  23368. writeLine();
  23369. emitPropertyDeclaration(node, property, tempVariable, true);
  23370. }
  23371. write(",");
  23372. writeLine();
  23373. emit(tempVariable);
  23374. decreaseIndent();
  23375. write(")");
  23376. }
  23377. else {
  23378. writeLine();
  23379. emitPropertyDeclarations(node, staticProperties);
  23380. emitDecoratorsOfClass(node);
  23381. }
  23382. if (!isES6ExportedDeclaration(node) && (node.flags & 1)) {
  23383. writeLine();
  23384. emitStart(node);
  23385. emitModuleMemberName(node);
  23386. write(" = ");
  23387. emitDeclarationName(node);
  23388. emitEnd(node);
  23389. write(";");
  23390. }
  23391. else if (isES6ExportedDeclaration(node) && (node.flags & 256) && thisNodeIsDecorated) {
  23392. writeLine();
  23393. write("export default ");
  23394. emitDeclarationName(node);
  23395. write(";");
  23396. }
  23397. }
  23398. function emitClassLikeDeclarationBelowES6(node) {
  23399. if (node.kind === 202) {
  23400. if (!shouldHoistDeclarationInSystemJsModule(node)) {
  23401. write("var ");
  23402. }
  23403. emitDeclarationName(node);
  23404. write(" = ");
  23405. }
  23406. write("(function (");
  23407. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
  23408. if (baseTypeNode) {
  23409. write("_super");
  23410. }
  23411. write(") {");
  23412. var saveTempFlags = tempFlags;
  23413. var saveTempVariables = tempVariables;
  23414. var saveTempParameters = tempParameters;
  23415. var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames;
  23416. tempFlags = 0;
  23417. tempVariables = undefined;
  23418. tempParameters = undefined;
  23419. computedPropertyNamesToGeneratedNames = undefined;
  23420. increaseIndent();
  23421. scopeEmitStart(node);
  23422. if (baseTypeNode) {
  23423. writeLine();
  23424. emitStart(baseTypeNode);
  23425. write("__extends(");
  23426. emitDeclarationName(node);
  23427. write(", _super);");
  23428. emitEnd(baseTypeNode);
  23429. }
  23430. writeLine();
  23431. emitConstructor(node, baseTypeNode);
  23432. emitMemberFunctionsForES5AndLower(node);
  23433. emitPropertyDeclarations(node, getInitializedProperties(node, true));
  23434. writeLine();
  23435. emitDecoratorsOfClass(node);
  23436. writeLine();
  23437. emitToken(15, node.members.end, function () {
  23438. write("return ");
  23439. emitDeclarationName(node);
  23440. });
  23441. write(";");
  23442. emitTempDeclarations(true);
  23443. tempFlags = saveTempFlags;
  23444. tempVariables = saveTempVariables;
  23445. tempParameters = saveTempParameters;
  23446. computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames;
  23447. decreaseIndent();
  23448. writeLine();
  23449. emitToken(15, node.members.end);
  23450. scopeEmitEnd();
  23451. emitStart(node);
  23452. write(")(");
  23453. if (baseTypeNode) {
  23454. emit(baseTypeNode.expression);
  23455. }
  23456. write(")");
  23457. if (node.kind === 202) {
  23458. write(";");
  23459. }
  23460. emitEnd(node);
  23461. if (node.kind === 202) {
  23462. emitExportMemberAssignment(node);
  23463. }
  23464. if (languageVersion < 2 && node.parent === currentSourceFile && node.name) {
  23465. emitExportMemberAssignments(node.name);
  23466. }
  23467. }
  23468. function emitClassMemberPrefix(node, member) {
  23469. emitDeclarationName(node);
  23470. if (!(member.flags & 128)) {
  23471. write(".prototype");
  23472. }
  23473. }
  23474. function emitDecoratorsOfClass(node) {
  23475. emitDecoratorsOfMembers(node, 0);
  23476. emitDecoratorsOfMembers(node, 128);
  23477. emitDecoratorsOfConstructor(node);
  23478. }
  23479. function emitDecoratorsOfConstructor(node) {
  23480. var decorators = node.decorators;
  23481. var constructor = ts.getFirstConstructorWithBody(node);
  23482. var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated);
  23483. if (!decorators && !hasDecoratedParameters) {
  23484. return;
  23485. }
  23486. writeLine();
  23487. emitStart(node);
  23488. emitDeclarationName(node);
  23489. write(" = __decorate([");
  23490. increaseIndent();
  23491. writeLine();
  23492. var decoratorCount = decorators ? decorators.length : 0;
  23493. var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) {
  23494. emitStart(decorator);
  23495. emit(decorator.expression);
  23496. emitEnd(decorator);
  23497. });
  23498. argumentsWritten += emitDecoratorsOfParameters(constructor, argumentsWritten > 0);
  23499. emitSerializedTypeMetadata(node, argumentsWritten >= 0);
  23500. decreaseIndent();
  23501. writeLine();
  23502. write("], ");
  23503. emitDeclarationName(node);
  23504. write(");");
  23505. emitEnd(node);
  23506. writeLine();
  23507. }
  23508. function emitDecoratorsOfMembers(node, staticFlag) {
  23509. for (var _a = 0, _b = node.members; _a < _b.length; _a++) {
  23510. var member = _b[_a];
  23511. if ((member.flags & 128) !== staticFlag) {
  23512. continue;
  23513. }
  23514. if (!ts.nodeCanBeDecorated(member)) {
  23515. continue;
  23516. }
  23517. if (!ts.nodeOrChildIsDecorated(member)) {
  23518. continue;
  23519. }
  23520. var decorators = void 0;
  23521. var functionLikeMember = void 0;
  23522. if (ts.isAccessor(member)) {
  23523. var accessors = ts.getAllAccessorDeclarations(node.members, member);
  23524. if (member !== accessors.firstAccessor) {
  23525. continue;
  23526. }
  23527. decorators = accessors.firstAccessor.decorators;
  23528. if (!decorators && accessors.secondAccessor) {
  23529. decorators = accessors.secondAccessor.decorators;
  23530. }
  23531. functionLikeMember = accessors.setAccessor;
  23532. }
  23533. else {
  23534. decorators = member.decorators;
  23535. if (member.kind === 135) {
  23536. functionLikeMember = member;
  23537. }
  23538. }
  23539. writeLine();
  23540. emitStart(member);
  23541. if (member.kind !== 133) {
  23542. write("Object.defineProperty(");
  23543. emitStart(member.name);
  23544. emitClassMemberPrefix(node, member);
  23545. write(", ");
  23546. emitExpressionForPropertyName(member.name);
  23547. emitEnd(member.name);
  23548. write(",");
  23549. increaseIndent();
  23550. writeLine();
  23551. }
  23552. write("__decorate([");
  23553. increaseIndent();
  23554. writeLine();
  23555. var decoratorCount = decorators ? decorators.length : 0;
  23556. var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) {
  23557. emitStart(decorator);
  23558. emit(decorator.expression);
  23559. emitEnd(decorator);
  23560. });
  23561. argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0);
  23562. emitSerializedTypeMetadata(member, argumentsWritten > 0);
  23563. decreaseIndent();
  23564. writeLine();
  23565. write("], ");
  23566. emitStart(member.name);
  23567. emitClassMemberPrefix(node, member);
  23568. write(", ");
  23569. emitExpressionForPropertyName(member.name);
  23570. emitEnd(member.name);
  23571. if (member.kind !== 133) {
  23572. write(", Object.getOwnPropertyDescriptor(");
  23573. emitStart(member.name);
  23574. emitClassMemberPrefix(node, member);
  23575. write(", ");
  23576. emitExpressionForPropertyName(member.name);
  23577. emitEnd(member.name);
  23578. write("))");
  23579. decreaseIndent();
  23580. }
  23581. write(");");
  23582. emitEnd(member);
  23583. writeLine();
  23584. }
  23585. }
  23586. function emitDecoratorsOfParameters(node, leadingComma) {
  23587. var argumentsWritten = 0;
  23588. if (node) {
  23589. var parameterIndex = 0;
  23590. for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) {
  23591. var parameter = _b[_a];
  23592. if (ts.nodeIsDecorated(parameter)) {
  23593. var decorators = parameter.decorators;
  23594. argumentsWritten += emitList(decorators, 0, decorators.length, true, false, leadingComma, true, function (decorator) {
  23595. emitStart(decorator);
  23596. write("__param(" + parameterIndex + ", ");
  23597. emit(decorator.expression);
  23598. write(")");
  23599. emitEnd(decorator);
  23600. });
  23601. leadingComma = true;
  23602. }
  23603. ++parameterIndex;
  23604. }
  23605. }
  23606. return argumentsWritten;
  23607. }
  23608. function shouldEmitTypeMetadata(node) {
  23609. switch (node.kind) {
  23610. case 135:
  23611. case 137:
  23612. case 138:
  23613. case 133:
  23614. return true;
  23615. }
  23616. return false;
  23617. }
  23618. function shouldEmitReturnTypeMetadata(node) {
  23619. switch (node.kind) {
  23620. case 135:
  23621. return true;
  23622. }
  23623. return false;
  23624. }
  23625. function shouldEmitParamTypesMetadata(node) {
  23626. switch (node.kind) {
  23627. case 202:
  23628. case 135:
  23629. case 138:
  23630. return true;
  23631. }
  23632. return false;
  23633. }
  23634. function emitSerializedTypeMetadata(node, writeComma) {
  23635. var argumentsWritten = 0;
  23636. if (compilerOptions.emitDecoratorMetadata) {
  23637. if (shouldEmitTypeMetadata(node)) {
  23638. var serializedType = resolver.serializeTypeOfNode(node, getGeneratedNameForNode);
  23639. if (serializedType) {
  23640. if (writeComma) {
  23641. write(", ");
  23642. }
  23643. writeLine();
  23644. write("__metadata('design:type', ");
  23645. emitSerializedType(node, serializedType);
  23646. write(")");
  23647. argumentsWritten++;
  23648. }
  23649. }
  23650. if (shouldEmitParamTypesMetadata(node)) {
  23651. var serializedTypes = resolver.serializeParameterTypesOfNode(node, getGeneratedNameForNode);
  23652. if (serializedTypes) {
  23653. if (writeComma || argumentsWritten) {
  23654. write(", ");
  23655. }
  23656. writeLine();
  23657. write("__metadata('design:paramtypes', [");
  23658. for (var i = 0; i < serializedTypes.length; ++i) {
  23659. if (i > 0) {
  23660. write(", ");
  23661. }
  23662. emitSerializedType(node, serializedTypes[i]);
  23663. }
  23664. write("])");
  23665. argumentsWritten++;
  23666. }
  23667. }
  23668. if (shouldEmitReturnTypeMetadata(node)) {
  23669. var serializedType = resolver.serializeReturnTypeOfNode(node, getGeneratedNameForNode);
  23670. if (serializedType) {
  23671. if (writeComma || argumentsWritten) {
  23672. write(", ");
  23673. }
  23674. writeLine();
  23675. write("__metadata('design:returntype', ");
  23676. emitSerializedType(node, serializedType);
  23677. write(")");
  23678. argumentsWritten++;
  23679. }
  23680. }
  23681. }
  23682. return argumentsWritten;
  23683. }
  23684. function serializeTypeNameSegment(location, path, index) {
  23685. switch (index) {
  23686. case 0:
  23687. return "typeof " + path[index] + " !== 'undefined' && " + path[index];
  23688. case 1:
  23689. return serializeTypeNameSegment(location, path, index - 1) + "." + path[index];
  23690. default:
  23691. var temp = createAndRecordTempVariable(0).text;
  23692. return "(" + temp + " = " + serializeTypeNameSegment(location, path, index - 1) + ") && " + temp + "." + path[index];
  23693. }
  23694. }
  23695. function emitSerializedType(location, name) {
  23696. if (typeof name === "string") {
  23697. write(name);
  23698. return;
  23699. }
  23700. else {
  23701. ts.Debug.assert(name.length > 0, "Invalid serialized type name");
  23702. write("(" + serializeTypeNameSegment(location, name, name.length - 1) + ") || Object");
  23703. }
  23704. }
  23705. function emitInterfaceDeclaration(node) {
  23706. emitOnlyPinnedOrTripleSlashComments(node);
  23707. }
  23708. function shouldEmitEnumDeclaration(node) {
  23709. var isConstEnum = ts.isConst(node);
  23710. return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules;
  23711. }
  23712. function emitEnumDeclaration(node) {
  23713. if (!shouldEmitEnumDeclaration(node)) {
  23714. return;
  23715. }
  23716. if (!shouldHoistDeclarationInSystemJsModule(node)) {
  23717. if (!(node.flags & 1) || isES6ExportedDeclaration(node)) {
  23718. emitStart(node);
  23719. if (isES6ExportedDeclaration(node)) {
  23720. write("export ");
  23721. }
  23722. write("var ");
  23723. emit(node.name);
  23724. emitEnd(node);
  23725. write(";");
  23726. }
  23727. }
  23728. writeLine();
  23729. emitStart(node);
  23730. write("(function (");
  23731. emitStart(node.name);
  23732. write(getGeneratedNameForNode(node));
  23733. emitEnd(node.name);
  23734. write(") {");
  23735. increaseIndent();
  23736. scopeEmitStart(node);
  23737. emitLines(node.members);
  23738. decreaseIndent();
  23739. writeLine();
  23740. emitToken(15, node.members.end);
  23741. scopeEmitEnd();
  23742. write(")(");
  23743. emitModuleMemberName(node);
  23744. write(" || (");
  23745. emitModuleMemberName(node);
  23746. write(" = {}));");
  23747. emitEnd(node);
  23748. if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) {
  23749. writeLine();
  23750. emitStart(node);
  23751. write("var ");
  23752. emit(node.name);
  23753. write(" = ");
  23754. emitModuleMemberName(node);
  23755. emitEnd(node);
  23756. write(";");
  23757. }
  23758. if (languageVersion < 2 && node.parent === currentSourceFile) {
  23759. if (compilerOptions.module === 4 && (node.flags & 1)) {
  23760. writeLine();
  23761. write(exportFunctionForFile + "(\"");
  23762. emitDeclarationName(node);
  23763. write("\", ");
  23764. emitDeclarationName(node);
  23765. write(");");
  23766. }
  23767. emitExportMemberAssignments(node.name);
  23768. }
  23769. }
  23770. function emitEnumMember(node) {
  23771. var enumParent = node.parent;
  23772. emitStart(node);
  23773. write(getGeneratedNameForNode(enumParent));
  23774. write("[");
  23775. write(getGeneratedNameForNode(enumParent));
  23776. write("[");
  23777. emitExpressionForPropertyName(node.name);
  23778. write("] = ");
  23779. writeEnumMemberDeclarationValue(node);
  23780. write("] = ");
  23781. emitExpressionForPropertyName(node.name);
  23782. emitEnd(node);
  23783. write(";");
  23784. }
  23785. function writeEnumMemberDeclarationValue(member) {
  23786. var value = resolver.getConstantValue(member);
  23787. if (value !== undefined) {
  23788. write(value.toString());
  23789. return;
  23790. }
  23791. else if (member.initializer) {
  23792. emit(member.initializer);
  23793. }
  23794. else {
  23795. write("undefined");
  23796. }
  23797. }
  23798. function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) {
  23799. if (moduleDeclaration.body.kind === 206) {
  23800. var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body);
  23801. return recursiveInnerModule || moduleDeclaration.body;
  23802. }
  23803. }
  23804. function shouldEmitModuleDeclaration(node) {
  23805. return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules);
  23806. }
  23807. function isModuleMergedWithES6Class(node) {
  23808. return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 2048);
  23809. }
  23810. function emitModuleDeclaration(node) {
  23811. var shouldEmit = shouldEmitModuleDeclaration(node);
  23812. if (!shouldEmit) {
  23813. return emitOnlyPinnedOrTripleSlashComments(node);
  23814. }
  23815. var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node);
  23816. var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node);
  23817. if (emitVarForModule) {
  23818. emitStart(node);
  23819. if (isES6ExportedDeclaration(node)) {
  23820. write("export ");
  23821. }
  23822. write("var ");
  23823. emit(node.name);
  23824. write(";");
  23825. emitEnd(node);
  23826. writeLine();
  23827. }
  23828. emitStart(node);
  23829. write("(function (");
  23830. emitStart(node.name);
  23831. write(getGeneratedNameForNode(node));
  23832. emitEnd(node.name);
  23833. write(") ");
  23834. if (node.body.kind === 207) {
  23835. var saveTempFlags = tempFlags;
  23836. var saveTempVariables = tempVariables;
  23837. tempFlags = 0;
  23838. tempVariables = undefined;
  23839. emit(node.body);
  23840. tempFlags = saveTempFlags;
  23841. tempVariables = saveTempVariables;
  23842. }
  23843. else {
  23844. write("{");
  23845. increaseIndent();
  23846. scopeEmitStart(node);
  23847. emitCaptureThisForNodeIfNecessary(node);
  23848. writeLine();
  23849. emit(node.body);
  23850. decreaseIndent();
  23851. writeLine();
  23852. var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body;
  23853. emitToken(15, moduleBlock.statements.end);
  23854. scopeEmitEnd();
  23855. }
  23856. write(")(");
  23857. if ((node.flags & 1) && !isES6ExportedDeclaration(node)) {
  23858. emit(node.name);
  23859. write(" = ");
  23860. }
  23861. emitModuleMemberName(node);
  23862. write(" || (");
  23863. emitModuleMemberName(node);
  23864. write(" = {}));");
  23865. emitEnd(node);
  23866. if (!isES6ExportedDeclaration(node) && node.name.kind === 65 && node.parent === currentSourceFile) {
  23867. if (compilerOptions.module === 4 && (node.flags & 1)) {
  23868. writeLine();
  23869. write(exportFunctionForFile + "(\"");
  23870. emitDeclarationName(node);
  23871. write("\", ");
  23872. emitDeclarationName(node);
  23873. write(");");
  23874. }
  23875. emitExportMemberAssignments(node.name);
  23876. }
  23877. }
  23878. function emitRequire(moduleName) {
  23879. if (moduleName.kind === 8) {
  23880. write("require(");
  23881. emitStart(moduleName);
  23882. emitLiteral(moduleName);
  23883. emitEnd(moduleName);
  23884. emitToken(17, moduleName.end);
  23885. }
  23886. else {
  23887. write("require()");
  23888. }
  23889. }
  23890. function getNamespaceDeclarationNode(node) {
  23891. if (node.kind === 209) {
  23892. return node;
  23893. }
  23894. var importClause = node.importClause;
  23895. if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 212) {
  23896. return importClause.namedBindings;
  23897. }
  23898. }
  23899. function isDefaultImport(node) {
  23900. return node.kind === 210 && node.importClause && !!node.importClause.name;
  23901. }
  23902. function emitExportImportAssignments(node) {
  23903. if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) {
  23904. emitExportMemberAssignments(node.name);
  23905. }
  23906. ts.forEachChild(node, emitExportImportAssignments);
  23907. }
  23908. function emitImportDeclaration(node) {
  23909. if (languageVersion < 2) {
  23910. return emitExternalImportDeclaration(node);
  23911. }
  23912. if (node.importClause) {
  23913. var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause);
  23914. var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, true);
  23915. if (shouldEmitDefaultBindings || shouldEmitNamedBindings) {
  23916. write("import ");
  23917. emitStart(node.importClause);
  23918. if (shouldEmitDefaultBindings) {
  23919. emit(node.importClause.name);
  23920. if (shouldEmitNamedBindings) {
  23921. write(", ");
  23922. }
  23923. }
  23924. if (shouldEmitNamedBindings) {
  23925. emitLeadingComments(node.importClause.namedBindings);
  23926. emitStart(node.importClause.namedBindings);
  23927. if (node.importClause.namedBindings.kind === 212) {
  23928. write("* as ");
  23929. emit(node.importClause.namedBindings.name);
  23930. }
  23931. else {
  23932. write("{ ");
  23933. emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration);
  23934. write(" }");
  23935. }
  23936. emitEnd(node.importClause.namedBindings);
  23937. emitTrailingComments(node.importClause.namedBindings);
  23938. }
  23939. emitEnd(node.importClause);
  23940. write(" from ");
  23941. emit(node.moduleSpecifier);
  23942. write(";");
  23943. }
  23944. }
  23945. else {
  23946. write("import ");
  23947. emit(node.moduleSpecifier);
  23948. write(";");
  23949. }
  23950. }
  23951. function emitExternalImportDeclaration(node) {
  23952. if (ts.contains(externalImports, node)) {
  23953. var isExportedImport = node.kind === 209 && (node.flags & 1) !== 0;
  23954. var namespaceDeclaration = getNamespaceDeclarationNode(node);
  23955. if (compilerOptions.module !== 2) {
  23956. emitLeadingComments(node);
  23957. emitStart(node);
  23958. if (namespaceDeclaration && !isDefaultImport(node)) {
  23959. if (!isExportedImport)
  23960. write("var ");
  23961. emitModuleMemberName(namespaceDeclaration);
  23962. write(" = ");
  23963. }
  23964. else {
  23965. var isNakedImport = 210 && !node.importClause;
  23966. if (!isNakedImport) {
  23967. write("var ");
  23968. write(getGeneratedNameForNode(node));
  23969. write(" = ");
  23970. }
  23971. }
  23972. emitRequire(ts.getExternalModuleName(node));
  23973. if (namespaceDeclaration && isDefaultImport(node)) {
  23974. write(", ");
  23975. emitModuleMemberName(namespaceDeclaration);
  23976. write(" = ");
  23977. write(getGeneratedNameForNode(node));
  23978. }
  23979. write(";");
  23980. emitEnd(node);
  23981. emitExportImportAssignments(node);
  23982. emitTrailingComments(node);
  23983. }
  23984. else {
  23985. if (isExportedImport) {
  23986. emitModuleMemberName(namespaceDeclaration);
  23987. write(" = ");
  23988. emit(namespaceDeclaration.name);
  23989. write(";");
  23990. }
  23991. else if (namespaceDeclaration && isDefaultImport(node)) {
  23992. write("var ");
  23993. emitModuleMemberName(namespaceDeclaration);
  23994. write(" = ");
  23995. write(getGeneratedNameForNode(node));
  23996. write(";");
  23997. }
  23998. emitExportImportAssignments(node);
  23999. }
  24000. }
  24001. }
  24002. function emitImportEqualsDeclaration(node) {
  24003. if (ts.isExternalModuleImportEqualsDeclaration(node)) {
  24004. emitExternalImportDeclaration(node);
  24005. return;
  24006. }
  24007. if (resolver.isReferencedAliasDeclaration(node) ||
  24008. (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) {
  24009. emitLeadingComments(node);
  24010. emitStart(node);
  24011. if (isES6ExportedDeclaration(node)) {
  24012. write("export ");
  24013. write("var ");
  24014. }
  24015. else if (!(node.flags & 1)) {
  24016. write("var ");
  24017. }
  24018. emitModuleMemberName(node);
  24019. write(" = ");
  24020. emit(node.moduleReference);
  24021. write(";");
  24022. emitEnd(node);
  24023. emitExportImportAssignments(node);
  24024. emitTrailingComments(node);
  24025. }
  24026. }
  24027. function emitExportDeclaration(node) {
  24028. ts.Debug.assert(compilerOptions.module !== 4);
  24029. if (languageVersion < 2) {
  24030. if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) {
  24031. emitStart(node);
  24032. var generatedName = getGeneratedNameForNode(node);
  24033. if (node.exportClause) {
  24034. if (compilerOptions.module !== 2) {
  24035. write("var ");
  24036. write(generatedName);
  24037. write(" = ");
  24038. emitRequire(ts.getExternalModuleName(node));
  24039. write(";");
  24040. }
  24041. for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) {
  24042. var specifier = _b[_a];
  24043. if (resolver.isValueAliasDeclaration(specifier)) {
  24044. writeLine();
  24045. emitStart(specifier);
  24046. emitContainingModuleName(specifier);
  24047. write(".");
  24048. emitNodeWithoutSourceMap(specifier.name);
  24049. write(" = ");
  24050. write(generatedName);
  24051. write(".");
  24052. emitNodeWithoutSourceMap(specifier.propertyName || specifier.name);
  24053. write(";");
  24054. emitEnd(specifier);
  24055. }
  24056. }
  24057. }
  24058. else {
  24059. writeLine();
  24060. write("__export(");
  24061. if (compilerOptions.module !== 2) {
  24062. emitRequire(ts.getExternalModuleName(node));
  24063. }
  24064. else {
  24065. write(generatedName);
  24066. }
  24067. write(");");
  24068. }
  24069. emitEnd(node);
  24070. }
  24071. }
  24072. else {
  24073. if (!node.exportClause || resolver.isValueAliasDeclaration(node)) {
  24074. emitStart(node);
  24075. write("export ");
  24076. if (node.exportClause) {
  24077. write("{ ");
  24078. emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration);
  24079. write(" }");
  24080. }
  24081. else {
  24082. write("*");
  24083. }
  24084. if (node.moduleSpecifier) {
  24085. write(" from ");
  24086. emitNodeWithoutSourceMap(node.moduleSpecifier);
  24087. }
  24088. write(";");
  24089. emitEnd(node);
  24090. }
  24091. }
  24092. }
  24093. function emitExportOrImportSpecifierList(specifiers, shouldEmit) {
  24094. ts.Debug.assert(languageVersion >= 2);
  24095. var needsComma = false;
  24096. for (var _a = 0; _a < specifiers.length; _a++) {
  24097. var specifier = specifiers[_a];
  24098. if (shouldEmit(specifier)) {
  24099. if (needsComma) {
  24100. write(", ");
  24101. }
  24102. emitStart(specifier);
  24103. if (specifier.propertyName) {
  24104. emitNodeWithoutSourceMap(specifier.propertyName);
  24105. write(" as ");
  24106. }
  24107. emitNodeWithoutSourceMap(specifier.name);
  24108. emitEnd(specifier);
  24109. needsComma = true;
  24110. }
  24111. }
  24112. }
  24113. function emitExportAssignment(node) {
  24114. if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
  24115. if (languageVersion >= 2) {
  24116. writeLine();
  24117. emitStart(node);
  24118. write("export default ");
  24119. var expression = node.expression;
  24120. emit(expression);
  24121. if (expression.kind !== 201 &&
  24122. expression.kind !== 202) {
  24123. write(";");
  24124. }
  24125. emitEnd(node);
  24126. }
  24127. else {
  24128. writeLine();
  24129. emitStart(node);
  24130. if (compilerOptions.module === 4) {
  24131. write(exportFunctionForFile + "(\"default\",");
  24132. emit(node.expression);
  24133. write(")");
  24134. }
  24135. else {
  24136. emitContainingModuleName(node);
  24137. if (languageVersion === 0) {
  24138. write("[\"default\"] = ");
  24139. }
  24140. else {
  24141. write(".default = ");
  24142. }
  24143. emit(node.expression);
  24144. }
  24145. write(";");
  24146. emitEnd(node);
  24147. }
  24148. }
  24149. }
  24150. function collectExternalModuleInfo(sourceFile) {
  24151. externalImports = [];
  24152. exportSpecifiers = {};
  24153. exportEquals = undefined;
  24154. hasExportStars = false;
  24155. for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) {
  24156. var node = _b[_a];
  24157. switch (node.kind) {
  24158. case 210:
  24159. if (!node.importClause ||
  24160. resolver.isReferencedAliasDeclaration(node.importClause, true)) {
  24161. externalImports.push(node);
  24162. }
  24163. break;
  24164. case 209:
  24165. if (node.moduleReference.kind === 220 && resolver.isReferencedAliasDeclaration(node)) {
  24166. externalImports.push(node);
  24167. }
  24168. break;
  24169. case 216:
  24170. if (node.moduleSpecifier) {
  24171. if (!node.exportClause) {
  24172. externalImports.push(node);
  24173. hasExportStars = true;
  24174. }
  24175. else if (resolver.isValueAliasDeclaration(node)) {
  24176. externalImports.push(node);
  24177. }
  24178. }
  24179. else {
  24180. for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) {
  24181. var specifier = _d[_c];
  24182. var name_20 = (specifier.propertyName || specifier.name).text;
  24183. (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier);
  24184. }
  24185. }
  24186. break;
  24187. case 215:
  24188. if (node.isExportEquals && !exportEquals) {
  24189. exportEquals = node;
  24190. }
  24191. break;
  24192. }
  24193. }
  24194. }
  24195. function emitExportStarHelper() {
  24196. if (hasExportStars) {
  24197. writeLine();
  24198. write("function __export(m) {");
  24199. increaseIndent();
  24200. writeLine();
  24201. write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];");
  24202. decreaseIndent();
  24203. writeLine();
  24204. write("}");
  24205. }
  24206. }
  24207. function getLocalNameForExternalImport(importNode) {
  24208. var namespaceDeclaration = getNamespaceDeclarationNode(importNode);
  24209. if (namespaceDeclaration && !isDefaultImport(importNode)) {
  24210. return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
  24211. }
  24212. else {
  24213. return getGeneratedNameForNode(importNode);
  24214. }
  24215. }
  24216. function getExternalModuleNameText(importNode) {
  24217. var moduleName = ts.getExternalModuleName(importNode);
  24218. if (moduleName.kind === 8) {
  24219. return getLiteralText(moduleName);
  24220. }
  24221. return undefined;
  24222. }
  24223. function emitVariableDeclarationsForImports() {
  24224. if (externalImports.length === 0) {
  24225. return;
  24226. }
  24227. writeLine();
  24228. var started = false;
  24229. for (var _a = 0; _a < externalImports.length; _a++) {
  24230. var importNode = externalImports[_a];
  24231. var skipNode = importNode.kind === 216 ||
  24232. (importNode.kind === 210 && !importNode.importClause);
  24233. if (skipNode) {
  24234. continue;
  24235. }
  24236. if (!started) {
  24237. write("var ");
  24238. started = true;
  24239. }
  24240. else {
  24241. write(", ");
  24242. }
  24243. write(getLocalNameForExternalImport(importNode));
  24244. }
  24245. if (started) {
  24246. write(";");
  24247. }
  24248. }
  24249. function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) {
  24250. if (!hasExportStars) {
  24251. return undefined;
  24252. }
  24253. if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) {
  24254. var hasExportDeclarationWithExportClause = false;
  24255. for (var _a = 0; _a < externalImports.length; _a++) {
  24256. var externalImport = externalImports[_a];
  24257. if (externalImport.kind === 216 && externalImport.exportClause) {
  24258. hasExportDeclarationWithExportClause = true;
  24259. break;
  24260. }
  24261. }
  24262. if (!hasExportDeclarationWithExportClause) {
  24263. return emitExportStarFunction(undefined);
  24264. }
  24265. }
  24266. var exportedNamesStorageRef = makeUniqueName("exportedNames");
  24267. writeLine();
  24268. write("var " + exportedNamesStorageRef + " = {");
  24269. increaseIndent();
  24270. var started = false;
  24271. if (exportedDeclarations) {
  24272. for (var i = 0; i < exportedDeclarations.length; ++i) {
  24273. writeExportedName(exportedDeclarations[i]);
  24274. }
  24275. }
  24276. if (exportSpecifiers) {
  24277. for (var n in exportSpecifiers) {
  24278. for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) {
  24279. var specifier = _c[_b];
  24280. writeExportedName(specifier.name);
  24281. }
  24282. }
  24283. }
  24284. for (var _d = 0; _d < externalImports.length; _d++) {
  24285. var externalImport = externalImports[_d];
  24286. if (externalImport.kind !== 216) {
  24287. continue;
  24288. }
  24289. var exportDecl = externalImport;
  24290. if (!exportDecl.exportClause) {
  24291. continue;
  24292. }
  24293. for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) {
  24294. var element = _f[_e];
  24295. writeExportedName(element.name || element.propertyName);
  24296. }
  24297. }
  24298. decreaseIndent();
  24299. writeLine();
  24300. write("};");
  24301. return emitExportStarFunction(exportedNamesStorageRef);
  24302. function emitExportStarFunction(localNames) {
  24303. var exportStarFunction = makeUniqueName("exportStar");
  24304. writeLine();
  24305. write("function " + exportStarFunction + "(m) {");
  24306. increaseIndent();
  24307. writeLine();
  24308. write("for(var n in m) {");
  24309. increaseIndent();
  24310. writeLine();
  24311. write("if (n !== \"default\"");
  24312. if (localNames) {
  24313. write("&& !" + localNames + ".hasOwnProperty(n)");
  24314. }
  24315. write(") " + exportFunctionForFile + "(n, m[n]);");
  24316. decreaseIndent();
  24317. writeLine();
  24318. write("}");
  24319. decreaseIndent();
  24320. writeLine();
  24321. write("}");
  24322. return exportStarFunction;
  24323. }
  24324. function writeExportedName(node) {
  24325. if (node.kind !== 65 && node.flags & 256) {
  24326. return;
  24327. }
  24328. if (started) {
  24329. write(",");
  24330. }
  24331. else {
  24332. started = true;
  24333. }
  24334. writeLine();
  24335. write("'");
  24336. if (node.kind === 65) {
  24337. emitNodeWithoutSourceMap(node);
  24338. }
  24339. else {
  24340. emitDeclarationName(node);
  24341. }
  24342. write("': true");
  24343. }
  24344. }
  24345. function processTopLevelVariableAndFunctionDeclarations(node) {
  24346. var hoistedVars;
  24347. var hoistedFunctionDeclarations;
  24348. var exportedDeclarations;
  24349. visit(node);
  24350. if (hoistedVars) {
  24351. writeLine();
  24352. write("var ");
  24353. var seen = {};
  24354. for (var i = 0; i < hoistedVars.length; ++i) {
  24355. var local = hoistedVars[i];
  24356. var name_21 = local.kind === 65
  24357. ? local
  24358. : local.name;
  24359. if (name_21) {
  24360. var text = ts.unescapeIdentifier(name_21.text);
  24361. if (ts.hasProperty(seen, text)) {
  24362. continue;
  24363. }
  24364. else {
  24365. seen[text] = text;
  24366. }
  24367. }
  24368. if (i !== 0) {
  24369. write(", ");
  24370. }
  24371. if (local.kind === 202 || local.kind === 206 || local.kind === 205) {
  24372. emitDeclarationName(local);
  24373. }
  24374. else {
  24375. emit(local);
  24376. }
  24377. var flags = ts.getCombinedNodeFlags(local.kind === 65 ? local.parent : local);
  24378. if (flags & 1) {
  24379. if (!exportedDeclarations) {
  24380. exportedDeclarations = [];
  24381. }
  24382. exportedDeclarations.push(local);
  24383. }
  24384. }
  24385. write(";");
  24386. }
  24387. if (hoistedFunctionDeclarations) {
  24388. for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) {
  24389. var f = hoistedFunctionDeclarations[_a];
  24390. writeLine();
  24391. emit(f);
  24392. if (f.flags & 1) {
  24393. if (!exportedDeclarations) {
  24394. exportedDeclarations = [];
  24395. }
  24396. exportedDeclarations.push(f);
  24397. }
  24398. }
  24399. }
  24400. return exportedDeclarations;
  24401. function visit(node) {
  24402. if (node.flags & 2) {
  24403. return;
  24404. }
  24405. if (node.kind === 201) {
  24406. if (!hoistedFunctionDeclarations) {
  24407. hoistedFunctionDeclarations = [];
  24408. }
  24409. hoistedFunctionDeclarations.push(node);
  24410. return;
  24411. }
  24412. if (node.kind === 202) {
  24413. if (!hoistedVars) {
  24414. hoistedVars = [];
  24415. }
  24416. hoistedVars.push(node);
  24417. return;
  24418. }
  24419. if (node.kind === 205) {
  24420. if (shouldEmitEnumDeclaration(node)) {
  24421. if (!hoistedVars) {
  24422. hoistedVars = [];
  24423. }
  24424. hoistedVars.push(node);
  24425. }
  24426. return;
  24427. }
  24428. if (node.kind === 206) {
  24429. if (shouldEmitModuleDeclaration(node)) {
  24430. if (!hoistedVars) {
  24431. hoistedVars = [];
  24432. }
  24433. hoistedVars.push(node);
  24434. }
  24435. return;
  24436. }
  24437. if (node.kind === 199 || node.kind === 153) {
  24438. if (shouldHoistVariable(node, false)) {
  24439. var name_22 = node.name;
  24440. if (name_22.kind === 65) {
  24441. if (!hoistedVars) {
  24442. hoistedVars = [];
  24443. }
  24444. hoistedVars.push(name_22);
  24445. }
  24446. else {
  24447. ts.forEachChild(name_22, visit);
  24448. }
  24449. }
  24450. return;
  24451. }
  24452. if (ts.isBindingPattern(node)) {
  24453. ts.forEach(node.elements, visit);
  24454. return;
  24455. }
  24456. if (!ts.isDeclaration(node)) {
  24457. ts.forEachChild(node, visit);
  24458. }
  24459. }
  24460. }
  24461. function shouldHoistVariable(node, checkIfSourceFileLevelDecl) {
  24462. if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) {
  24463. return false;
  24464. }
  24465. return (ts.getCombinedNodeFlags(node) & 12288) === 0 ||
  24466. ts.getEnclosingBlockScopeContainer(node).kind === 228;
  24467. }
  24468. function isCurrentFileSystemExternalModule() {
  24469. return compilerOptions.module === 4 && ts.isExternalModule(currentSourceFile);
  24470. }
  24471. function emitSystemModuleBody(node, startIndex) {
  24472. emitVariableDeclarationsForImports();
  24473. writeLine();
  24474. var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node);
  24475. var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations);
  24476. writeLine();
  24477. write("return {");
  24478. increaseIndent();
  24479. writeLine();
  24480. emitSetters(exportStarFunction);
  24481. writeLine();
  24482. emitExecute(node, startIndex);
  24483. decreaseIndent();
  24484. writeLine();
  24485. write("}");
  24486. emitTempDeclarations(true);
  24487. }
  24488. function emitSetters(exportStarFunction) {
  24489. write("setters:[");
  24490. for (var i = 0; i < externalImports.length; ++i) {
  24491. if (i !== 0) {
  24492. write(",");
  24493. }
  24494. writeLine();
  24495. increaseIndent();
  24496. var importNode = externalImports[i];
  24497. var importVariableName = getLocalNameForExternalImport(importNode) || "";
  24498. var parameterName = "_" + importVariableName;
  24499. write("function (" + parameterName + ") {");
  24500. switch (importNode.kind) {
  24501. case 210:
  24502. if (!importNode.importClause) {
  24503. break;
  24504. }
  24505. case 209:
  24506. ts.Debug.assert(importVariableName !== "");
  24507. increaseIndent();
  24508. writeLine();
  24509. write(importVariableName + " = " + parameterName + ";");
  24510. writeLine();
  24511. var defaultName = importNode.kind === 210
  24512. ? importNode.importClause.name
  24513. : importNode.name;
  24514. if (defaultName) {
  24515. emitExportMemberAssignments(defaultName);
  24516. writeLine();
  24517. }
  24518. if (importNode.kind === 210 &&
  24519. importNode.importClause.namedBindings) {
  24520. var namedBindings = importNode.importClause.namedBindings;
  24521. if (namedBindings.kind === 212) {
  24522. emitExportMemberAssignments(namedBindings.name);
  24523. writeLine();
  24524. }
  24525. else {
  24526. for (var _a = 0, _b = namedBindings.elements; _a < _b.length; _a++) {
  24527. var element = _b[_a];
  24528. emitExportMemberAssignments(element.name || element.propertyName);
  24529. writeLine();
  24530. }
  24531. }
  24532. }
  24533. decreaseIndent();
  24534. break;
  24535. case 216:
  24536. ts.Debug.assert(importVariableName !== "");
  24537. increaseIndent();
  24538. if (importNode.exportClause) {
  24539. for (var _c = 0, _d = importNode.exportClause.elements; _c < _d.length; _c++) {
  24540. var e = _d[_c];
  24541. writeLine();
  24542. write(exportFunctionForFile + "(\"");
  24543. emitNodeWithoutSourceMap(e.name);
  24544. write("\", " + parameterName + "[\"");
  24545. emitNodeWithoutSourceMap(e.propertyName || e.name);
  24546. write("\"]);");
  24547. }
  24548. }
  24549. else {
  24550. writeLine();
  24551. write(exportStarFunction + "(" + parameterName + ");");
  24552. }
  24553. writeLine();
  24554. decreaseIndent();
  24555. break;
  24556. }
  24557. write("}");
  24558. decreaseIndent();
  24559. }
  24560. write("],");
  24561. }
  24562. function emitExecute(node, startIndex) {
  24563. write("execute: function() {");
  24564. increaseIndent();
  24565. writeLine();
  24566. for (var i = startIndex; i < node.statements.length; ++i) {
  24567. var statement = node.statements[i];
  24568. switch (statement.kind) {
  24569. case 216:
  24570. case 210:
  24571. case 209:
  24572. case 201:
  24573. continue;
  24574. }
  24575. writeLine();
  24576. emit(statement);
  24577. }
  24578. decreaseIndent();
  24579. writeLine();
  24580. write("}");
  24581. }
  24582. function emitSystemModule(node, startIndex) {
  24583. collectExternalModuleInfo(node);
  24584. ts.Debug.assert(!exportFunctionForFile);
  24585. exportFunctionForFile = makeUniqueName("exports");
  24586. write("System.register(");
  24587. if (node.moduleName) {
  24588. write("\"" + node.moduleName + "\", ");
  24589. }
  24590. write("[");
  24591. for (var i = 0; i < externalImports.length; ++i) {
  24592. var text = getExternalModuleNameText(externalImports[i]);
  24593. if (i !== 0) {
  24594. write(", ");
  24595. }
  24596. write(text);
  24597. }
  24598. write("], function(" + exportFunctionForFile + ") {");
  24599. writeLine();
  24600. increaseIndent();
  24601. emitCaptureThisForNodeIfNecessary(node);
  24602. emitSystemModuleBody(node, startIndex);
  24603. decreaseIndent();
  24604. writeLine();
  24605. write("});");
  24606. }
  24607. function emitAMDDependencies(node, includeNonAmdDependencies) {
  24608. // An AMD define function has the following shape:
  24609. // define(id?, dependencies?, factory);
  24610. //
  24611. // This has the shape of
  24612. // define(name, ["module1", "module2"], function (module1Alias) {
  24613. // The location of the alias in the parameter list in the factory function needs to
  24614. // match the position of the module name in the dependency list.
  24615. //
  24616. // To ensure this is true in cases of modules with no aliases, e.g.:
  24617. // `import "module"` or `<amd-dependency path= "a.css" />`
  24618. // we need to add modules without alias names to the end of the dependencies list
  24619. var aliasedModuleNames = [];
  24620. var unaliasedModuleNames = [];
  24621. var importAliasNames = [];
  24622. for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) {
  24623. var amdDependency = _b[_a];
  24624. if (amdDependency.name) {
  24625. aliasedModuleNames.push("\"" + amdDependency.path + "\"");
  24626. importAliasNames.push(amdDependency.name);
  24627. }
  24628. else {
  24629. unaliasedModuleNames.push("\"" + amdDependency.path + "\"");
  24630. }
  24631. }
  24632. for (var _c = 0; _c < externalImports.length; _c++) {
  24633. var importNode = externalImports[_c];
  24634. var externalModuleName = getExternalModuleNameText(importNode);
  24635. var importAliasName = getLocalNameForExternalImport(importNode);
  24636. if (includeNonAmdDependencies && importAliasName) {
  24637. aliasedModuleNames.push(externalModuleName);
  24638. importAliasNames.push(importAliasName);
  24639. }
  24640. else {
  24641. unaliasedModuleNames.push(externalModuleName);
  24642. }
  24643. }
  24644. write("[\"require\", \"exports\"");
  24645. if (aliasedModuleNames.length) {
  24646. write(", ");
  24647. write(aliasedModuleNames.join(", "));
  24648. }
  24649. if (unaliasedModuleNames.length) {
  24650. write(", ");
  24651. write(unaliasedModuleNames.join(", "));
  24652. }
  24653. write("], function (require, exports");
  24654. if (importAliasNames.length) {
  24655. write(", ");
  24656. write(importAliasNames.join(", "));
  24657. }
  24658. }
  24659. function emitAMDModule(node, startIndex) {
  24660. collectExternalModuleInfo(node);
  24661. writeLine();
  24662. write("define(");
  24663. if (node.moduleName) {
  24664. write("\"" + node.moduleName + "\", ");
  24665. }
  24666. emitAMDDependencies(node, true);
  24667. write(") {");
  24668. increaseIndent();
  24669. emitExportStarHelper();
  24670. emitCaptureThisForNodeIfNecessary(node);
  24671. emitLinesStartingAt(node.statements, startIndex);
  24672. emitTempDeclarations(true);
  24673. emitExportEquals(true);
  24674. decreaseIndent();
  24675. writeLine();
  24676. write("});");
  24677. }
  24678. function emitCommonJSModule(node, startIndex) {
  24679. collectExternalModuleInfo(node);
  24680. emitExportStarHelper();
  24681. emitCaptureThisForNodeIfNecessary(node);
  24682. emitLinesStartingAt(node.statements, startIndex);
  24683. emitTempDeclarations(true);
  24684. emitExportEquals(false);
  24685. }
  24686. function emitUMDModule(node, startIndex) {
  24687. collectExternalModuleInfo(node);
  24688. 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})(");
  24689. emitAMDDependencies(node, false);
  24690. write(") {");
  24691. increaseIndent();
  24692. emitExportStarHelper();
  24693. emitCaptureThisForNodeIfNecessary(node);
  24694. emitLinesStartingAt(node.statements, startIndex);
  24695. emitTempDeclarations(true);
  24696. emitExportEquals(true);
  24697. decreaseIndent();
  24698. writeLine();
  24699. write("});");
  24700. }
  24701. function emitES6Module(node, startIndex) {
  24702. externalImports = undefined;
  24703. exportSpecifiers = undefined;
  24704. exportEquals = undefined;
  24705. hasExportStars = false;
  24706. emitCaptureThisForNodeIfNecessary(node);
  24707. emitLinesStartingAt(node.statements, startIndex);
  24708. emitTempDeclarations(true);
  24709. }
  24710. function emitExportEquals(emitAsReturn) {
  24711. if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) {
  24712. writeLine();
  24713. emitStart(exportEquals);
  24714. write(emitAsReturn ? "return " : "module.exports = ");
  24715. emit(exportEquals.expression);
  24716. write(";");
  24717. emitEnd(exportEquals);
  24718. }
  24719. }
  24720. function emitDirectivePrologues(statements, startWithNewLine) {
  24721. for (var i = 0; i < statements.length; ++i) {
  24722. if (ts.isPrologueDirective(statements[i])) {
  24723. if (startWithNewLine || i > 0) {
  24724. writeLine();
  24725. }
  24726. emit(statements[i]);
  24727. }
  24728. else {
  24729. return i;
  24730. }
  24731. }
  24732. return statements.length;
  24733. }
  24734. function writeLines(text) {
  24735. var lines = text.split(/\r\n|\r|\n/g);
  24736. for (var i = 0; i < lines.length; ++i) {
  24737. var line = lines[i];
  24738. if (line.length) {
  24739. writeLine();
  24740. write(line);
  24741. }
  24742. }
  24743. }
  24744. function emitSourceFileNode(node) {
  24745. writeLine();
  24746. emitDetachedComments(node);
  24747. var startIndex = emitDirectivePrologues(node.statements, false);
  24748. if (!compilerOptions.noEmitHelpers) {
  24749. if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) {
  24750. writeLines(extendsHelper);
  24751. extendsEmitted = true;
  24752. }
  24753. if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 512) {
  24754. writeLines(decorateHelper);
  24755. if (compilerOptions.emitDecoratorMetadata) {
  24756. writeLines(metadataHelper);
  24757. }
  24758. decorateEmitted = true;
  24759. }
  24760. if (!paramEmitted && resolver.getNodeCheckFlags(node) & 1024) {
  24761. writeLines(paramHelper);
  24762. paramEmitted = true;
  24763. }
  24764. }
  24765. if (ts.isExternalModule(node) || compilerOptions.isolatedModules) {
  24766. if (languageVersion >= 2) {
  24767. emitES6Module(node, startIndex);
  24768. }
  24769. else if (compilerOptions.module === 2) {
  24770. emitAMDModule(node, startIndex);
  24771. }
  24772. else if (compilerOptions.module === 4) {
  24773. emitSystemModule(node, startIndex);
  24774. }
  24775. else if (compilerOptions.module === 3) {
  24776. emitUMDModule(node, startIndex);
  24777. }
  24778. else {
  24779. emitCommonJSModule(node, startIndex);
  24780. }
  24781. }
  24782. else {
  24783. externalImports = undefined;
  24784. exportSpecifiers = undefined;
  24785. exportEquals = undefined;
  24786. hasExportStars = false;
  24787. emitCaptureThisForNodeIfNecessary(node);
  24788. emitLinesStartingAt(node.statements, startIndex);
  24789. emitTempDeclarations(true);
  24790. }
  24791. emitLeadingComments(node.endOfFileToken);
  24792. }
  24793. function emitNodeWithoutSourceMap(node, allowGeneratedIdentifiers) {
  24794. if (!node) {
  24795. return;
  24796. }
  24797. if (node.flags & 2) {
  24798. return emitOnlyPinnedOrTripleSlashComments(node);
  24799. }
  24800. var emitComments = shouldEmitLeadingAndTrailingComments(node);
  24801. if (emitComments) {
  24802. emitLeadingComments(node);
  24803. }
  24804. emitJavaScriptWorker(node, allowGeneratedIdentifiers);
  24805. if (emitComments) {
  24806. emitTrailingComments(node);
  24807. }
  24808. }
  24809. function shouldEmitLeadingAndTrailingComments(node) {
  24810. switch (node.kind) {
  24811. case 203:
  24812. case 201:
  24813. case 210:
  24814. case 209:
  24815. case 204:
  24816. case 215:
  24817. return false;
  24818. case 206:
  24819. return shouldEmitModuleDeclaration(node);
  24820. case 205:
  24821. return shouldEmitEnumDeclaration(node);
  24822. }
  24823. if (node.kind !== 180 &&
  24824. node.parent &&
  24825. node.parent.kind === 164 &&
  24826. node.parent.body === node &&
  24827. compilerOptions.target <= 1) {
  24828. return false;
  24829. }
  24830. return true;
  24831. }
  24832. function emitJavaScriptWorker(node, allowGeneratedIdentifiers) {
  24833. if (allowGeneratedIdentifiers === void 0) { allowGeneratedIdentifiers = true; }
  24834. switch (node.kind) {
  24835. case 65:
  24836. return emitIdentifier(node, allowGeneratedIdentifiers);
  24837. case 130:
  24838. return emitParameter(node);
  24839. case 135:
  24840. case 134:
  24841. return emitMethod(node);
  24842. case 137:
  24843. case 138:
  24844. return emitAccessor(node);
  24845. case 93:
  24846. return emitThis(node);
  24847. case 91:
  24848. return emitSuper(node);
  24849. case 89:
  24850. return write("null");
  24851. case 95:
  24852. return write("true");
  24853. case 80:
  24854. return write("false");
  24855. case 7:
  24856. case 8:
  24857. case 9:
  24858. case 10:
  24859. case 11:
  24860. case 12:
  24861. case 13:
  24862. return emitLiteral(node);
  24863. case 172:
  24864. return emitTemplateExpression(node);
  24865. case 178:
  24866. return emitTemplateSpan(node);
  24867. case 127:
  24868. return emitQualifiedName(node);
  24869. case 151:
  24870. return emitObjectBindingPattern(node);
  24871. case 152:
  24872. return emitArrayBindingPattern(node);
  24873. case 153:
  24874. return emitBindingElement(node);
  24875. case 154:
  24876. return emitArrayLiteral(node);
  24877. case 155:
  24878. return emitObjectLiteral(node);
  24879. case 225:
  24880. return emitPropertyAssignment(node);
  24881. case 226:
  24882. return emitShorthandPropertyAssignment(node);
  24883. case 128:
  24884. return emitComputedPropertyName(node);
  24885. case 156:
  24886. return emitPropertyAccess(node);
  24887. case 157:
  24888. return emitIndexedAccess(node);
  24889. case 158:
  24890. return emitCallExpression(node);
  24891. case 159:
  24892. return emitNewExpression(node);
  24893. case 160:
  24894. return emitTaggedTemplateExpression(node);
  24895. case 161:
  24896. return emit(node.expression);
  24897. case 162:
  24898. return emitParenExpression(node);
  24899. case 201:
  24900. case 163:
  24901. case 164:
  24902. return emitFunctionDeclaration(node);
  24903. case 165:
  24904. return emitDeleteExpression(node);
  24905. case 166:
  24906. return emitTypeOfExpression(node);
  24907. case 167:
  24908. return emitVoidExpression(node);
  24909. case 168:
  24910. return emitPrefixUnaryExpression(node);
  24911. case 169:
  24912. return emitPostfixUnaryExpression(node);
  24913. case 170:
  24914. return emitBinaryExpression(node);
  24915. case 171:
  24916. return emitConditionalExpression(node);
  24917. case 174:
  24918. return emitSpreadElementExpression(node);
  24919. case 173:
  24920. return emitYieldExpression(node);
  24921. case 176:
  24922. return;
  24923. case 180:
  24924. case 207:
  24925. return emitBlock(node);
  24926. case 181:
  24927. return emitVariableStatement(node);
  24928. case 182:
  24929. return write(";");
  24930. case 183:
  24931. return emitExpressionStatement(node);
  24932. case 184:
  24933. return emitIfStatement(node);
  24934. case 185:
  24935. return emitDoStatement(node);
  24936. case 186:
  24937. return emitWhileStatement(node);
  24938. case 187:
  24939. return emitForStatement(node);
  24940. case 189:
  24941. case 188:
  24942. return emitForInOrForOfStatement(node);
  24943. case 190:
  24944. case 191:
  24945. return emitBreakOrContinueStatement(node);
  24946. case 192:
  24947. return emitReturnStatement(node);
  24948. case 193:
  24949. return emitWithStatement(node);
  24950. case 194:
  24951. return emitSwitchStatement(node);
  24952. case 221:
  24953. case 222:
  24954. return emitCaseOrDefaultClause(node);
  24955. case 195:
  24956. return emitLabelledStatement(node);
  24957. case 196:
  24958. return emitThrowStatement(node);
  24959. case 197:
  24960. return emitTryStatement(node);
  24961. case 224:
  24962. return emitCatchClause(node);
  24963. case 198:
  24964. return emitDebuggerStatement(node);
  24965. case 199:
  24966. return emitVariableDeclaration(node);
  24967. case 175:
  24968. return emitClassExpression(node);
  24969. case 202:
  24970. return emitClassDeclaration(node);
  24971. case 203:
  24972. return emitInterfaceDeclaration(node);
  24973. case 205:
  24974. return emitEnumDeclaration(node);
  24975. case 227:
  24976. return emitEnumMember(node);
  24977. case 206:
  24978. return emitModuleDeclaration(node);
  24979. case 210:
  24980. return emitImportDeclaration(node);
  24981. case 209:
  24982. return emitImportEqualsDeclaration(node);
  24983. case 216:
  24984. return emitExportDeclaration(node);
  24985. case 215:
  24986. return emitExportAssignment(node);
  24987. case 228:
  24988. return emitSourceFileNode(node);
  24989. }
  24990. }
  24991. function hasDetachedComments(pos) {
  24992. return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos;
  24993. }
  24994. function getLeadingCommentsWithoutDetachedComments() {
  24995. var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos);
  24996. if (detachedCommentsInfo.length - 1) {
  24997. detachedCommentsInfo.pop();
  24998. }
  24999. else {
  25000. detachedCommentsInfo = undefined;
  25001. }
  25002. return leadingComments;
  25003. }
  25004. function filterComments(ranges, onlyPinnedOrTripleSlashComments) {
  25005. if (ranges && onlyPinnedOrTripleSlashComments) {
  25006. ranges = ts.filter(ranges, isPinnedOrTripleSlashComment);
  25007. if (ranges.length === 0) {
  25008. return undefined;
  25009. }
  25010. }
  25011. return ranges;
  25012. }
  25013. function getLeadingCommentsToEmit(node) {
  25014. if (node.parent) {
  25015. if (node.parent.kind === 228 || node.pos !== node.parent.pos) {
  25016. if (hasDetachedComments(node.pos)) {
  25017. return getLeadingCommentsWithoutDetachedComments();
  25018. }
  25019. else {
  25020. return ts.getLeadingCommentRangesOfNode(node, currentSourceFile);
  25021. }
  25022. }
  25023. }
  25024. }
  25025. function getTrailingCommentsToEmit(node) {
  25026. if (node.parent) {
  25027. if (node.parent.kind === 228 || node.end !== node.parent.end) {
  25028. return ts.getTrailingCommentRanges(currentSourceFile.text, node.end);
  25029. }
  25030. }
  25031. }
  25032. function emitOnlyPinnedOrTripleSlashComments(node) {
  25033. emitLeadingCommentsWorker(node, true);
  25034. }
  25035. function emitLeadingComments(node) {
  25036. return emitLeadingCommentsWorker(node, compilerOptions.removeComments);
  25037. }
  25038. function emitLeadingCommentsWorker(node, onlyPinnedOrTripleSlashComments) {
  25039. var leadingComments = filterComments(getLeadingCommentsToEmit(node), onlyPinnedOrTripleSlashComments);
  25040. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
  25041. ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
  25042. }
  25043. function emitTrailingComments(node) {
  25044. var trailingComments = filterComments(getTrailingCommentsToEmit(node), compilerOptions.removeComments);
  25045. ts.emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment);
  25046. }
  25047. function emitLeadingCommentsOfPosition(pos) {
  25048. var leadingComments;
  25049. if (hasDetachedComments(pos)) {
  25050. leadingComments = getLeadingCommentsWithoutDetachedComments();
  25051. }
  25052. else {
  25053. leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos);
  25054. }
  25055. leadingComments = filterComments(leadingComments, compilerOptions.removeComments);
  25056. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments);
  25057. ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
  25058. }
  25059. function emitDetachedComments(node) {
  25060. var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
  25061. if (leadingComments) {
  25062. var detachedComments = [];
  25063. var lastComment;
  25064. ts.forEach(leadingComments, function (comment) {
  25065. if (lastComment) {
  25066. var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end);
  25067. var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos);
  25068. if (commentLine >= lastCommentLine + 2) {
  25069. return detachedComments;
  25070. }
  25071. }
  25072. detachedComments.push(comment);
  25073. lastComment = comment;
  25074. });
  25075. if (detachedComments.length) {
  25076. var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end);
  25077. var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos));
  25078. if (nodeLine >= lastCommentLine + 2) {
  25079. ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
  25080. ts.emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment);
  25081. var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end };
  25082. if (detachedCommentsInfo) {
  25083. detachedCommentsInfo.push(currentDetachedCommentInfo);
  25084. }
  25085. else {
  25086. detachedCommentsInfo = [currentDetachedCommentInfo];
  25087. }
  25088. }
  25089. }
  25090. }
  25091. }
  25092. function isPinnedOrTripleSlashComment(comment) {
  25093. if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42) {
  25094. return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33;
  25095. }
  25096. else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 &&
  25097. comment.pos + 2 < comment.end &&
  25098. currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 &&
  25099. currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) {
  25100. return true;
  25101. }
  25102. }
  25103. }
  25104. function emitFile(jsFilePath, sourceFile) {
  25105. emitJavaScript(jsFilePath, sourceFile);
  25106. if (compilerOptions.declaration) {
  25107. ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics);
  25108. }
  25109. }
  25110. }
  25111. ts.emitFiles = emitFiles;
  25112. })(ts || (ts = {}));
  25113. /// <reference path="sys.ts" />
  25114. /// <reference path="emitter.ts" />
  25115. var ts;
  25116. (function (ts) {
  25117. ts.programTime = 0;
  25118. ts.emitTime = 0;
  25119. ts.ioReadTime = 0;
  25120. ts.ioWriteTime = 0;
  25121. ts.version = "1.5.3";
  25122. function findConfigFile(searchPath) {
  25123. var fileName = "tsconfig.json";
  25124. while (true) {
  25125. if (ts.sys.fileExists(fileName)) {
  25126. return fileName;
  25127. }
  25128. var parentPath = ts.getDirectoryPath(searchPath);
  25129. if (parentPath === searchPath) {
  25130. break;
  25131. }
  25132. searchPath = parentPath;
  25133. fileName = "../" + fileName;
  25134. }
  25135. return undefined;
  25136. }
  25137. ts.findConfigFile = findConfigFile;
  25138. function createCompilerHost(options, setParentNodes) {
  25139. var currentDirectory;
  25140. var existingDirectories = {};
  25141. function getCanonicalFileName(fileName) {
  25142. return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
  25143. }
  25144. var unsupportedFileEncodingErrorCode = -2147024809;
  25145. function getSourceFile(fileName, languageVersion, onError) {
  25146. var text;
  25147. try {
  25148. var start = new Date().getTime();
  25149. text = ts.sys.readFile(fileName, options.charset);
  25150. ts.ioReadTime += new Date().getTime() - start;
  25151. }
  25152. catch (e) {
  25153. if (onError) {
  25154. onError(e.number === unsupportedFileEncodingErrorCode
  25155. ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText
  25156. : e.message);
  25157. }
  25158. text = "";
  25159. }
  25160. return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined;
  25161. }
  25162. function directoryExists(directoryPath) {
  25163. if (ts.hasProperty(existingDirectories, directoryPath)) {
  25164. return true;
  25165. }
  25166. if (ts.sys.directoryExists(directoryPath)) {
  25167. existingDirectories[directoryPath] = true;
  25168. return true;
  25169. }
  25170. return false;
  25171. }
  25172. function ensureDirectoriesExist(directoryPath) {
  25173. if (directoryPath.length > ts.getRootLength(directoryPath) && !directoryExists(directoryPath)) {
  25174. var parentDirectory = ts.getDirectoryPath(directoryPath);
  25175. ensureDirectoriesExist(parentDirectory);
  25176. ts.sys.createDirectory(directoryPath);
  25177. }
  25178. }
  25179. function writeFile(fileName, data, writeByteOrderMark, onError) {
  25180. try {
  25181. var start = new Date().getTime();
  25182. ensureDirectoriesExist(ts.getDirectoryPath(ts.normalizePath(fileName)));
  25183. ts.sys.writeFile(fileName, data, writeByteOrderMark);
  25184. ts.ioWriteTime += new Date().getTime() - start;
  25185. }
  25186. catch (e) {
  25187. if (onError) {
  25188. onError(e.message);
  25189. }
  25190. }
  25191. }
  25192. var newLine = ts.getNewLineCharacter(options);
  25193. return {
  25194. getSourceFile: getSourceFile,
  25195. getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); },
  25196. writeFile: writeFile,
  25197. getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); },
  25198. useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; },
  25199. getCanonicalFileName: getCanonicalFileName,
  25200. getNewLine: function () { return newLine; }
  25201. };
  25202. }
  25203. ts.createCompilerHost = createCompilerHost;
  25204. function getPreEmitDiagnostics(program, sourceFile) {
  25205. var diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile));
  25206. if (program.getCompilerOptions().declaration) {
  25207. diagnostics.concat(program.getDeclarationDiagnostics(sourceFile));
  25208. }
  25209. return ts.sortAndDeduplicateDiagnostics(diagnostics);
  25210. }
  25211. ts.getPreEmitDiagnostics = getPreEmitDiagnostics;
  25212. function flattenDiagnosticMessageText(messageText, newLine) {
  25213. if (typeof messageText === "string") {
  25214. return messageText;
  25215. }
  25216. else {
  25217. var diagnosticChain = messageText;
  25218. var result = "";
  25219. var indent = 0;
  25220. while (diagnosticChain) {
  25221. if (indent) {
  25222. result += newLine;
  25223. for (var i = 0; i < indent; i++) {
  25224. result += " ";
  25225. }
  25226. }
  25227. result += diagnosticChain.messageText;
  25228. indent++;
  25229. diagnosticChain = diagnosticChain.next;
  25230. }
  25231. return result;
  25232. }
  25233. }
  25234. ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
  25235. function createProgram(rootNames, options, host) {
  25236. var program;
  25237. var files = [];
  25238. var diagnostics = ts.createDiagnosticCollection();
  25239. var seenNoDefaultLib = options.noLib;
  25240. var commonSourceDirectory;
  25241. var diagnosticsProducingTypeChecker;
  25242. var noDiagnosticsTypeChecker;
  25243. var start = new Date().getTime();
  25244. host = host || createCompilerHost(options);
  25245. var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); });
  25246. ts.forEach(rootNames, function (name) { return processRootFile(name, false); });
  25247. if (!seenNoDefaultLib) {
  25248. processRootFile(host.getDefaultLibFileName(options), true);
  25249. }
  25250. verifyCompilerOptions();
  25251. ts.programTime += new Date().getTime() - start;
  25252. program = {
  25253. getSourceFile: getSourceFile,
  25254. getSourceFiles: function () { return files; },
  25255. getCompilerOptions: function () { return options; },
  25256. getSyntacticDiagnostics: getSyntacticDiagnostics,
  25257. getGlobalDiagnostics: getGlobalDiagnostics,
  25258. getSemanticDiagnostics: getSemanticDiagnostics,
  25259. getDeclarationDiagnostics: getDeclarationDiagnostics,
  25260. getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics,
  25261. getTypeChecker: getTypeChecker,
  25262. getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker,
  25263. getCommonSourceDirectory: function () { return commonSourceDirectory; },
  25264. emit: emit,
  25265. getCurrentDirectory: function () { return host.getCurrentDirectory(); },
  25266. getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); },
  25267. getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); },
  25268. getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); },
  25269. getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }
  25270. };
  25271. return program;
  25272. function getEmitHost(writeFileCallback) {
  25273. return {
  25274. getCanonicalFileName: function (fileName) { return host.getCanonicalFileName(fileName); },
  25275. getCommonSourceDirectory: program.getCommonSourceDirectory,
  25276. getCompilerOptions: program.getCompilerOptions,
  25277. getCurrentDirectory: function () { return host.getCurrentDirectory(); },
  25278. getNewLine: function () { return host.getNewLine(); },
  25279. getSourceFile: program.getSourceFile,
  25280. getSourceFiles: program.getSourceFiles,
  25281. writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError) { return host.writeFile(fileName, data, writeByteOrderMark, onError); })
  25282. };
  25283. }
  25284. function getDiagnosticsProducingTypeChecker() {
  25285. return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = ts.createTypeChecker(program, true));
  25286. }
  25287. function getTypeChecker() {
  25288. return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, false));
  25289. }
  25290. function emit(sourceFile, writeFileCallback) {
  25291. if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) {
  25292. return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
  25293. }
  25294. var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
  25295. var start = new Date().getTime();
  25296. var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile);
  25297. ts.emitTime += new Date().getTime() - start;
  25298. return emitResult;
  25299. }
  25300. function getSourceFile(fileName) {
  25301. return filesByName.get(fileName);
  25302. }
  25303. function getDiagnosticsHelper(sourceFile, getDiagnostics) {
  25304. if (sourceFile) {
  25305. return getDiagnostics(sourceFile);
  25306. }
  25307. var allDiagnostics = [];
  25308. ts.forEach(program.getSourceFiles(), function (sourceFile) {
  25309. ts.addRange(allDiagnostics, getDiagnostics(sourceFile));
  25310. });
  25311. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  25312. }
  25313. function getSyntacticDiagnostics(sourceFile) {
  25314. return getDiagnosticsHelper(sourceFile, getSyntacticDiagnosticsForFile);
  25315. }
  25316. function getSemanticDiagnostics(sourceFile) {
  25317. return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile);
  25318. }
  25319. function getDeclarationDiagnostics(sourceFile) {
  25320. return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile);
  25321. }
  25322. function getSyntacticDiagnosticsForFile(sourceFile) {
  25323. return sourceFile.parseDiagnostics;
  25324. }
  25325. function getSemanticDiagnosticsForFile(sourceFile) {
  25326. var typeChecker = getDiagnosticsProducingTypeChecker();
  25327. ts.Debug.assert(!!sourceFile.bindDiagnostics);
  25328. var bindDiagnostics = sourceFile.bindDiagnostics;
  25329. var checkDiagnostics = typeChecker.getDiagnostics(sourceFile);
  25330. var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName);
  25331. return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics);
  25332. }
  25333. function getDeclarationDiagnosticsForFile(sourceFile) {
  25334. if (!ts.isDeclarationFile(sourceFile)) {
  25335. var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile);
  25336. var writeFile = function () { };
  25337. return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile);
  25338. }
  25339. }
  25340. function getCompilerOptionsDiagnostics() {
  25341. var allDiagnostics = [];
  25342. ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
  25343. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  25344. }
  25345. function getGlobalDiagnostics() {
  25346. var typeChecker = getDiagnosticsProducingTypeChecker();
  25347. var allDiagnostics = [];
  25348. ts.addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
  25349. ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
  25350. return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
  25351. }
  25352. function hasExtension(fileName) {
  25353. return ts.getBaseFileName(fileName).indexOf(".") >= 0;
  25354. }
  25355. function processRootFile(fileName, isDefaultLib) {
  25356. processSourceFile(ts.normalizePath(fileName), isDefaultLib);
  25357. }
  25358. function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) {
  25359. var start;
  25360. var length;
  25361. if (refEnd !== undefined && refPos !== undefined) {
  25362. start = refPos;
  25363. length = refEnd - refPos;
  25364. }
  25365. var diagnostic;
  25366. if (hasExtension(fileName)) {
  25367. if (!options.allowNonTsExtensions && !ts.fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) {
  25368. diagnostic = ts.Diagnostics.File_0_must_have_extension_ts_or_d_ts;
  25369. }
  25370. else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
  25371. diagnostic = ts.Diagnostics.File_0_not_found;
  25372. }
  25373. else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) {
  25374. diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself;
  25375. }
  25376. }
  25377. else {
  25378. if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) {
  25379. diagnostic = ts.Diagnostics.File_0_not_found;
  25380. }
  25381. else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) {
  25382. diagnostic = ts.Diagnostics.File_0_not_found;
  25383. fileName += ".ts";
  25384. }
  25385. }
  25386. if (diagnostic) {
  25387. if (refFile) {
  25388. diagnostics.add(ts.createFileDiagnostic(refFile, start, length, diagnostic, fileName));
  25389. }
  25390. else {
  25391. diagnostics.add(ts.createCompilerDiagnostic(diagnostic, fileName));
  25392. }
  25393. }
  25394. }
  25395. function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) {
  25396. var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName));
  25397. if (filesByName.contains(canonicalName)) {
  25398. return getSourceFileFromCache(fileName, canonicalName, false);
  25399. }
  25400. else {
  25401. var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
  25402. var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath);
  25403. if (filesByName.contains(canonicalAbsolutePath)) {
  25404. return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true);
  25405. }
  25406. var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) {
  25407. if (refFile) {
  25408. diagnostics.add(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
  25409. }
  25410. else {
  25411. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
  25412. }
  25413. });
  25414. filesByName.set(canonicalName, file);
  25415. if (file) {
  25416. seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib;
  25417. filesByName.set(canonicalAbsolutePath, file);
  25418. if (!options.noResolve) {
  25419. var basePath = ts.getDirectoryPath(fileName);
  25420. processReferencedFiles(file, basePath);
  25421. processImportedModules(file, basePath);
  25422. }
  25423. if (isDefaultLib) {
  25424. files.unshift(file);
  25425. }
  25426. else {
  25427. files.push(file);
  25428. }
  25429. }
  25430. return file;
  25431. }
  25432. function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) {
  25433. var file = filesByName.get(canonicalName);
  25434. if (file && host.useCaseSensitiveFileNames()) {
  25435. var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
  25436. if (canonicalName !== sourceFileName) {
  25437. diagnostics.add(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
  25438. }
  25439. }
  25440. return file;
  25441. }
  25442. }
  25443. function processReferencedFiles(file, basePath) {
  25444. ts.forEach(file.referencedFiles, function (ref) {
  25445. var referencedFileName = ts.isRootedDiskPath(ref.fileName) ? ref.fileName : ts.combinePaths(basePath, ref.fileName);
  25446. processSourceFile(ts.normalizePath(referencedFileName), false, file, ref.pos, ref.end);
  25447. });
  25448. }
  25449. function processImportedModules(file, basePath) {
  25450. ts.forEach(file.statements, function (node) {
  25451. if (node.kind === 210 || node.kind === 209 || node.kind === 216) {
  25452. var moduleNameExpr = ts.getExternalModuleName(node);
  25453. if (moduleNameExpr && moduleNameExpr.kind === 8) {
  25454. var moduleNameText = moduleNameExpr.text;
  25455. if (moduleNameText) {
  25456. var searchPath = basePath;
  25457. while (true) {
  25458. var searchName = ts.normalizePath(ts.combinePaths(searchPath, moduleNameText));
  25459. if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) {
  25460. break;
  25461. }
  25462. var parentPath = ts.getDirectoryPath(searchPath);
  25463. if (parentPath === searchPath) {
  25464. break;
  25465. }
  25466. searchPath = parentPath;
  25467. }
  25468. }
  25469. }
  25470. }
  25471. else if (node.kind === 206 && node.name.kind === 8 && (node.flags & 2 || ts.isDeclarationFile(file))) {
  25472. ts.forEachChild(node.body, function (node) {
  25473. if (ts.isExternalModuleImportEqualsDeclaration(node) &&
  25474. ts.getExternalModuleImportEqualsDeclarationExpression(node).kind === 8) {
  25475. var nameLiteral = ts.getExternalModuleImportEqualsDeclarationExpression(node);
  25476. var moduleName = nameLiteral.text;
  25477. if (moduleName) {
  25478. var searchName = ts.normalizePath(ts.combinePaths(basePath, moduleName));
  25479. var tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral);
  25480. if (!tsFile) {
  25481. findModuleSourceFile(searchName + ".d.ts", nameLiteral);
  25482. }
  25483. }
  25484. }
  25485. });
  25486. }
  25487. });
  25488. function findModuleSourceFile(fileName, nameLiteral) {
  25489. return findSourceFile(fileName, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos);
  25490. }
  25491. }
  25492. function computeCommonSourceDirectory(sourceFiles) {
  25493. var commonPathComponents;
  25494. var currentDirectory = host.getCurrentDirectory();
  25495. ts.forEach(files, function (sourceFile) {
  25496. if (ts.isDeclarationFile(sourceFile)) {
  25497. return;
  25498. }
  25499. var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, currentDirectory);
  25500. sourcePathComponents.pop();
  25501. if (!commonPathComponents) {
  25502. commonPathComponents = sourcePathComponents;
  25503. return;
  25504. }
  25505. for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) {
  25506. if (commonPathComponents[i] !== sourcePathComponents[i]) {
  25507. if (i === 0) {
  25508. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files));
  25509. return;
  25510. }
  25511. commonPathComponents.length = i;
  25512. break;
  25513. }
  25514. }
  25515. if (sourcePathComponents.length < commonPathComponents.length) {
  25516. commonPathComponents.length = sourcePathComponents.length;
  25517. }
  25518. });
  25519. return ts.getNormalizedPathFromPathComponents(commonPathComponents);
  25520. }
  25521. function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) {
  25522. var allFilesBelongToPath = true;
  25523. if (sourceFiles) {
  25524. var currentDirectory = host.getCurrentDirectory();
  25525. var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory));
  25526. for (var _i = 0; _i < sourceFiles.length; _i++) {
  25527. var sourceFile = sourceFiles[_i];
  25528. if (!ts.isDeclarationFile(sourceFile)) {
  25529. var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
  25530. if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
  25531. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir));
  25532. allFilesBelongToPath = false;
  25533. }
  25534. }
  25535. }
  25536. }
  25537. return allFilesBelongToPath;
  25538. }
  25539. function verifyCompilerOptions() {
  25540. if (options.isolatedModules) {
  25541. if (options.sourceMap) {
  25542. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules));
  25543. }
  25544. if (options.declaration) {
  25545. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules));
  25546. }
  25547. if (options.noEmitOnError) {
  25548. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules));
  25549. }
  25550. if (options.out) {
  25551. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules));
  25552. }
  25553. }
  25554. if (options.inlineSourceMap) {
  25555. if (options.sourceMap) {
  25556. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap));
  25557. }
  25558. if (options.mapRoot) {
  25559. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap));
  25560. }
  25561. if (options.sourceRoot) {
  25562. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap));
  25563. }
  25564. }
  25565. if (options.inlineSources) {
  25566. if (!options.sourceMap && !options.inlineSourceMap) {
  25567. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided));
  25568. }
  25569. }
  25570. if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
  25571. if (options.mapRoot) {
  25572. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option));
  25573. }
  25574. if (options.sourceRoot) {
  25575. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option));
  25576. }
  25577. return;
  25578. }
  25579. var languageVersion = options.target || 0;
  25580. var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; });
  25581. if (options.isolatedModules) {
  25582. if (!options.module && languageVersion < 2) {
  25583. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher));
  25584. }
  25585. var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; });
  25586. if (firstNonExternalModuleSourceFile) {
  25587. var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
  25588. diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
  25589. }
  25590. }
  25591. else if (firstExternalModuleSourceFile && languageVersion < 2 && !options.module) {
  25592. var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
  25593. diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided));
  25594. }
  25595. if (options.module && languageVersion >= 2) {
  25596. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher));
  25597. }
  25598. if (options.outDir ||
  25599. options.sourceRoot ||
  25600. (options.mapRoot &&
  25601. (!options.out || firstExternalModuleSourceFile !== undefined))) {
  25602. if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
  25603. commonSourceDirectory = ts.getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory());
  25604. }
  25605. else {
  25606. commonSourceDirectory = computeCommonSourceDirectory(files);
  25607. }
  25608. if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== ts.directorySeparator) {
  25609. commonSourceDirectory += ts.directorySeparator;
  25610. }
  25611. }
  25612. if (options.noEmit) {
  25613. if (options.out || options.outDir) {
  25614. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
  25615. }
  25616. if (options.declaration) {
  25617. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
  25618. }
  25619. }
  25620. if (options.emitDecoratorMetadata &&
  25621. !options.experimentalDecorators) {
  25622. diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified));
  25623. }
  25624. }
  25625. }
  25626. ts.createProgram = createProgram;
  25627. })(ts || (ts = {}));
  25628. /// <reference path="sys.ts"/>
  25629. /// <reference path="types.ts"/>
  25630. /// <reference path="core.ts"/>
  25631. /// <reference path="scanner.ts"/>
  25632. var ts;
  25633. (function (ts) {
  25634. ts.optionDeclarations = [
  25635. {
  25636. name: "charset",
  25637. type: "string"
  25638. },
  25639. {
  25640. name: "declaration",
  25641. shortName: "d",
  25642. type: "boolean",
  25643. description: ts.Diagnostics.Generates_corresponding_d_ts_file
  25644. },
  25645. {
  25646. name: "diagnostics",
  25647. type: "boolean"
  25648. },
  25649. {
  25650. name: "emitBOM",
  25651. type: "boolean"
  25652. },
  25653. {
  25654. name: "help",
  25655. shortName: "h",
  25656. type: "boolean",
  25657. description: ts.Diagnostics.Print_this_message
  25658. },
  25659. {
  25660. name: "inlineSourceMap",
  25661. type: "boolean"
  25662. },
  25663. {
  25664. name: "inlineSources",
  25665. type: "boolean"
  25666. },
  25667. {
  25668. name: "listFiles",
  25669. type: "boolean"
  25670. },
  25671. {
  25672. name: "locale",
  25673. type: "string"
  25674. },
  25675. {
  25676. name: "mapRoot",
  25677. type: "string",
  25678. isFilePath: true,
  25679. description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
  25680. paramType: ts.Diagnostics.LOCATION
  25681. },
  25682. {
  25683. name: "module",
  25684. shortName: "m",
  25685. type: {
  25686. "commonjs": 1,
  25687. "amd": 2,
  25688. "system": 4,
  25689. "umd": 3
  25690. },
  25691. description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd,
  25692. paramType: ts.Diagnostics.KIND,
  25693. error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
  25694. },
  25695. {
  25696. name: "newLine",
  25697. type: {
  25698. "crlf": 0,
  25699. "lf": 1
  25700. },
  25701. description: ts.Diagnostics.Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
  25702. paramType: ts.Diagnostics.NEWLINE,
  25703. error: ts.Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF
  25704. },
  25705. {
  25706. name: "noEmit",
  25707. type: "boolean",
  25708. description: ts.Diagnostics.Do_not_emit_outputs
  25709. },
  25710. {
  25711. name: "noEmitHelpers",
  25712. type: "boolean"
  25713. },
  25714. {
  25715. name: "noEmitOnError",
  25716. type: "boolean",
  25717. description: ts.Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported
  25718. },
  25719. {
  25720. name: "noImplicitAny",
  25721. type: "boolean",
  25722. description: ts.Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type
  25723. },
  25724. {
  25725. name: "noLib",
  25726. type: "boolean"
  25727. },
  25728. {
  25729. name: "noResolve",
  25730. type: "boolean"
  25731. },
  25732. {
  25733. name: "out",
  25734. type: "string",
  25735. description: ts.Diagnostics.Concatenate_and_emit_output_to_single_file,
  25736. paramType: ts.Diagnostics.FILE
  25737. },
  25738. {
  25739. name: "outDir",
  25740. type: "string",
  25741. isFilePath: true,
  25742. description: ts.Diagnostics.Redirect_output_structure_to_the_directory,
  25743. paramType: ts.Diagnostics.DIRECTORY
  25744. },
  25745. {
  25746. name: "preserveConstEnums",
  25747. type: "boolean",
  25748. description: ts.Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
  25749. },
  25750. {
  25751. name: "project",
  25752. shortName: "p",
  25753. type: "string",
  25754. isFilePath: true,
  25755. description: ts.Diagnostics.Compile_the_project_in_the_given_directory,
  25756. paramType: ts.Diagnostics.DIRECTORY
  25757. },
  25758. {
  25759. name: "removeComments",
  25760. type: "boolean",
  25761. description: ts.Diagnostics.Do_not_emit_comments_to_output
  25762. },
  25763. {
  25764. name: "rootDir",
  25765. type: "string",
  25766. isFilePath: true,
  25767. description: ts.Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
  25768. paramType: ts.Diagnostics.LOCATION
  25769. },
  25770. {
  25771. name: "isolatedModules",
  25772. type: "boolean"
  25773. },
  25774. {
  25775. name: "sourceMap",
  25776. type: "boolean",
  25777. description: ts.Diagnostics.Generates_corresponding_map_file
  25778. },
  25779. {
  25780. name: "sourceRoot",
  25781. type: "string",
  25782. isFilePath: true,
  25783. description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
  25784. paramType: ts.Diagnostics.LOCATION
  25785. },
  25786. {
  25787. name: "suppressImplicitAnyIndexErrors",
  25788. type: "boolean",
  25789. description: ts.Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures
  25790. },
  25791. {
  25792. name: "stripInternal",
  25793. type: "boolean",
  25794. description: ts.Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
  25795. experimental: true
  25796. },
  25797. {
  25798. name: "target",
  25799. shortName: "t",
  25800. type: { "es3": 0, "es5": 1, "es6": 2 },
  25801. description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental,
  25802. paramType: ts.Diagnostics.VERSION,
  25803. error: ts.Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6
  25804. },
  25805. {
  25806. name: "version",
  25807. shortName: "v",
  25808. type: "boolean",
  25809. description: ts.Diagnostics.Print_the_compiler_s_version
  25810. },
  25811. {
  25812. name: "watch",
  25813. shortName: "w",
  25814. type: "boolean",
  25815. description: ts.Diagnostics.Watch_input_files
  25816. },
  25817. {
  25818. name: "experimentalDecorators",
  25819. type: "boolean",
  25820. description: ts.Diagnostics.Enables_experimental_support_for_ES7_decorators
  25821. },
  25822. {
  25823. name: "emitDecoratorMetadata",
  25824. type: "boolean",
  25825. experimental: true,
  25826. description: ts.Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
  25827. }
  25828. ];
  25829. function parseCommandLine(commandLine) {
  25830. var options = {};
  25831. var fileNames = [];
  25832. var errors = [];
  25833. var shortOptionNames = {};
  25834. var optionNameMap = {};
  25835. ts.forEach(ts.optionDeclarations, function (option) {
  25836. optionNameMap[option.name.toLowerCase()] = option;
  25837. if (option.shortName) {
  25838. shortOptionNames[option.shortName] = option.name;
  25839. }
  25840. });
  25841. parseStrings(commandLine);
  25842. return {
  25843. options: options,
  25844. fileNames: fileNames,
  25845. errors: errors
  25846. };
  25847. function parseStrings(args) {
  25848. var i = 0;
  25849. while (i < args.length) {
  25850. var s = args[i++];
  25851. if (s.charCodeAt(0) === 64) {
  25852. parseResponseFile(s.slice(1));
  25853. }
  25854. else if (s.charCodeAt(0) === 45) {
  25855. s = s.slice(s.charCodeAt(1) === 45 ? 2 : 1).toLowerCase();
  25856. if (ts.hasProperty(shortOptionNames, s)) {
  25857. s = shortOptionNames[s];
  25858. }
  25859. if (ts.hasProperty(optionNameMap, s)) {
  25860. var opt = optionNameMap[s];
  25861. if (!args[i] && opt.type !== "boolean") {
  25862. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_expects_an_argument, opt.name));
  25863. }
  25864. switch (opt.type) {
  25865. case "number":
  25866. options[opt.name] = parseInt(args[i++]);
  25867. break;
  25868. case "boolean":
  25869. options[opt.name] = true;
  25870. break;
  25871. case "string":
  25872. options[opt.name] = args[i++] || "";
  25873. break;
  25874. default:
  25875. var map = opt.type;
  25876. var key = (args[i++] || "").toLowerCase();
  25877. if (ts.hasProperty(map, key)) {
  25878. options[opt.name] = map[key];
  25879. }
  25880. else {
  25881. errors.push(ts.createCompilerDiagnostic(opt.error));
  25882. }
  25883. }
  25884. }
  25885. else {
  25886. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, s));
  25887. }
  25888. }
  25889. else {
  25890. fileNames.push(s);
  25891. }
  25892. }
  25893. }
  25894. function parseResponseFile(fileName) {
  25895. var text = ts.sys.readFile(fileName);
  25896. if (!text) {
  25897. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_not_found, fileName));
  25898. return;
  25899. }
  25900. var args = [];
  25901. var pos = 0;
  25902. while (true) {
  25903. while (pos < text.length && text.charCodeAt(pos) <= 32)
  25904. pos++;
  25905. if (pos >= text.length)
  25906. break;
  25907. var start = pos;
  25908. if (text.charCodeAt(start) === 34) {
  25909. pos++;
  25910. while (pos < text.length && text.charCodeAt(pos) !== 34)
  25911. pos++;
  25912. if (pos < text.length) {
  25913. args.push(text.substring(start + 1, pos));
  25914. pos++;
  25915. }
  25916. else {
  25917. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unterminated_quoted_string_in_response_file_0, fileName));
  25918. }
  25919. }
  25920. else {
  25921. while (text.charCodeAt(pos) > 32)
  25922. pos++;
  25923. args.push(text.substring(start, pos));
  25924. }
  25925. }
  25926. parseStrings(args);
  25927. }
  25928. }
  25929. ts.parseCommandLine = parseCommandLine;
  25930. function readConfigFile(fileName) {
  25931. try {
  25932. var text = ts.sys.readFile(fileName);
  25933. }
  25934. catch (e) {
  25935. return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
  25936. }
  25937. return parseConfigFileText(fileName, text);
  25938. }
  25939. ts.readConfigFile = readConfigFile;
  25940. function parseConfigFileText(fileName, jsonText) {
  25941. try {
  25942. return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} };
  25943. }
  25944. catch (e) {
  25945. return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) };
  25946. }
  25947. }
  25948. ts.parseConfigFileText = parseConfigFileText;
  25949. function parseConfigFile(json, host, basePath) {
  25950. var errors = [];
  25951. return {
  25952. options: getCompilerOptions(),
  25953. fileNames: getFiles(),
  25954. errors: errors
  25955. };
  25956. function getCompilerOptions() {
  25957. var options = {};
  25958. var optionNameMap = {};
  25959. ts.forEach(ts.optionDeclarations, function (option) {
  25960. optionNameMap[option.name] = option;
  25961. });
  25962. var jsonOptions = json["compilerOptions"];
  25963. if (jsonOptions) {
  25964. for (var id in jsonOptions) {
  25965. if (ts.hasProperty(optionNameMap, id)) {
  25966. var opt = optionNameMap[id];
  25967. var optType = opt.type;
  25968. var value = jsonOptions[id];
  25969. var expectedType = typeof optType === "string" ? optType : "string";
  25970. if (typeof value === expectedType) {
  25971. if (typeof optType !== "string") {
  25972. var key = value.toLowerCase();
  25973. if (ts.hasProperty(optType, key)) {
  25974. value = optType[key];
  25975. }
  25976. else {
  25977. errors.push(ts.createCompilerDiagnostic(opt.error));
  25978. value = 0;
  25979. }
  25980. }
  25981. if (opt.isFilePath) {
  25982. value = ts.normalizePath(ts.combinePaths(basePath, value));
  25983. }
  25984. options[opt.name] = value;
  25985. }
  25986. else {
  25987. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType));
  25988. }
  25989. }
  25990. else {
  25991. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, id));
  25992. }
  25993. }
  25994. }
  25995. return options;
  25996. }
  25997. function getFiles() {
  25998. var files = [];
  25999. if (ts.hasProperty(json, "files")) {
  26000. if (json["files"] instanceof Array) {
  26001. var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); });
  26002. }
  26003. }
  26004. else {
  26005. var sysFiles = host.readDirectory(basePath, ".ts");
  26006. for (var i = 0; i < sysFiles.length; i++) {
  26007. var name = sysFiles[i];
  26008. if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
  26009. files.push(name);
  26010. }
  26011. }
  26012. }
  26013. return files;
  26014. }
  26015. }
  26016. ts.parseConfigFile = parseConfigFile;
  26017. })(ts || (ts = {}));
  26018. /// <reference path="program.ts"/>
  26019. /// <reference path="commandLineParser.ts"/>
  26020. var ts;
  26021. (function (ts) {
  26022. function validateLocaleAndSetLanguage(locale, errors) {
  26023. var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
  26024. if (!matchResult) {
  26025. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, 'en', 'ja-jp'));
  26026. return false;
  26027. }
  26028. var language = matchResult[1];
  26029. var territory = matchResult[3];
  26030. if (!trySetLanguageAndTerritory(language, territory, errors) &&
  26031. !trySetLanguageAndTerritory(language, undefined, errors)) {
  26032. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_locale_0, locale));
  26033. return false;
  26034. }
  26035. return true;
  26036. }
  26037. function trySetLanguageAndTerritory(language, territory, errors) {
  26038. var compilerFilePath = ts.normalizePath(ts.sys.getExecutingFilePath());
  26039. var containingDirectoryPath = ts.getDirectoryPath(compilerFilePath);
  26040. var filePath = ts.combinePaths(containingDirectoryPath, language);
  26041. if (territory) {
  26042. filePath = filePath + "-" + territory;
  26043. }
  26044. filePath = ts.sys.resolvePath(ts.combinePaths(filePath, "diagnosticMessages.generated.json"));
  26045. if (!ts.sys.fileExists(filePath)) {
  26046. return false;
  26047. }
  26048. try {
  26049. var fileContents = ts.sys.readFile(filePath);
  26050. }
  26051. catch (e) {
  26052. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unable_to_open_file_0, filePath));
  26053. return false;
  26054. }
  26055. try {
  26056. ts.localizedDiagnosticMessages = JSON.parse(fileContents);
  26057. }
  26058. catch (e) {
  26059. errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Corrupted_locale_file_0, filePath));
  26060. return false;
  26061. }
  26062. return true;
  26063. }
  26064. function countLines(program) {
  26065. var count = 0;
  26066. ts.forEach(program.getSourceFiles(), function (file) {
  26067. count += ts.getLineStarts(file).length;
  26068. });
  26069. return count;
  26070. }
  26071. function getDiagnosticText(message) {
  26072. var args = [];
  26073. for (var _i = 1; _i < arguments.length; _i++) {
  26074. args[_i - 1] = arguments[_i];
  26075. }
  26076. var diagnostic = ts.createCompilerDiagnostic.apply(undefined, arguments);
  26077. return diagnostic.messageText;
  26078. }
  26079. function reportDiagnostic(diagnostic) {
  26080. var output = "";
  26081. if (diagnostic.file) {
  26082. var loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
  26083. output += diagnostic.file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + "): ";
  26084. }
  26085. var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase();
  26086. output += category + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
  26087. ts.sys.write(output);
  26088. }
  26089. function reportDiagnostics(diagnostics) {
  26090. for (var i = 0; i < diagnostics.length; i++) {
  26091. reportDiagnostic(diagnostics[i]);
  26092. }
  26093. }
  26094. function padLeft(s, length) {
  26095. while (s.length < length) {
  26096. s = " " + s;
  26097. }
  26098. return s;
  26099. }
  26100. function padRight(s, length) {
  26101. while (s.length < length) {
  26102. s = s + " ";
  26103. }
  26104. return s;
  26105. }
  26106. function reportStatisticalValue(name, value) {
  26107. ts.sys.write(padRight(name + ":", 12) + padLeft(value.toString(), 10) + ts.sys.newLine);
  26108. }
  26109. function reportCountStatistic(name, count) {
  26110. reportStatisticalValue(name, "" + count);
  26111. }
  26112. function reportTimeStatistic(name, time) {
  26113. reportStatisticalValue(name, (time / 1000).toFixed(2) + "s");
  26114. }
  26115. function isJSONSupported() {
  26116. return typeof JSON === "object" && typeof JSON.parse === "function";
  26117. }
  26118. function executeCommandLine(args) {
  26119. var commandLine = ts.parseCommandLine(args);
  26120. var configFileName;
  26121. var configFileWatcher;
  26122. var cachedProgram;
  26123. var rootFileNames;
  26124. var compilerOptions;
  26125. var compilerHost;
  26126. var hostGetSourceFile;
  26127. var timerHandle;
  26128. if (commandLine.options.locale) {
  26129. if (!isJSONSupported()) {
  26130. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"));
  26131. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  26132. }
  26133. validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors);
  26134. }
  26135. if (commandLine.errors.length > 0) {
  26136. reportDiagnostics(commandLine.errors);
  26137. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  26138. }
  26139. if (commandLine.options.version) {
  26140. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Version_0, ts.version));
  26141. return ts.sys.exit(ts.ExitStatus.Success);
  26142. }
  26143. if (commandLine.options.help) {
  26144. printVersion();
  26145. printHelp();
  26146. return ts.sys.exit(ts.ExitStatus.Success);
  26147. }
  26148. if (commandLine.options.project) {
  26149. if (!isJSONSupported()) {
  26150. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--project"));
  26151. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  26152. }
  26153. configFileName = ts.normalizePath(ts.combinePaths(commandLine.options.project, "tsconfig.json"));
  26154. if (commandLine.fileNames.length !== 0) {
  26155. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
  26156. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  26157. }
  26158. }
  26159. else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
  26160. var searchPath = ts.normalizePath(ts.sys.getCurrentDirectory());
  26161. configFileName = ts.findConfigFile(searchPath);
  26162. }
  26163. if (commandLine.fileNames.length === 0 && !configFileName) {
  26164. printVersion();
  26165. printHelp();
  26166. return ts.sys.exit(ts.ExitStatus.Success);
  26167. }
  26168. if (commandLine.options.watch) {
  26169. if (!ts.sys.watchFile) {
  26170. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"));
  26171. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  26172. }
  26173. if (configFileName) {
  26174. configFileWatcher = ts.sys.watchFile(configFileName, configFileChanged);
  26175. }
  26176. }
  26177. performCompilation();
  26178. function performCompilation() {
  26179. if (!cachedProgram) {
  26180. if (configFileName) {
  26181. var result = ts.readConfigFile(configFileName);
  26182. if (result.error) {
  26183. reportDiagnostic(result.error);
  26184. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  26185. }
  26186. var configObject = result.config;
  26187. var configParseResult = ts.parseConfigFile(configObject, ts.sys, ts.getDirectoryPath(configFileName));
  26188. if (configParseResult.errors.length > 0) {
  26189. reportDiagnostics(configParseResult.errors);
  26190. return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped);
  26191. }
  26192. rootFileNames = configParseResult.fileNames;
  26193. compilerOptions = ts.extend(commandLine.options, configParseResult.options);
  26194. }
  26195. else {
  26196. rootFileNames = commandLine.fileNames;
  26197. compilerOptions = commandLine.options;
  26198. }
  26199. compilerHost = ts.createCompilerHost(compilerOptions);
  26200. hostGetSourceFile = compilerHost.getSourceFile;
  26201. compilerHost.getSourceFile = getSourceFile;
  26202. }
  26203. var compileResult = compile(rootFileNames, compilerOptions, compilerHost);
  26204. if (!compilerOptions.watch) {
  26205. return ts.sys.exit(compileResult.exitStatus);
  26206. }
  26207. setCachedProgram(compileResult.program);
  26208. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes));
  26209. }
  26210. function getSourceFile(fileName, languageVersion, onError) {
  26211. if (cachedProgram) {
  26212. var sourceFile = cachedProgram.getSourceFile(fileName);
  26213. if (sourceFile && sourceFile.fileWatcher) {
  26214. return sourceFile;
  26215. }
  26216. }
  26217. var sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
  26218. if (sourceFile && compilerOptions.watch) {
  26219. sourceFile.fileWatcher = ts.sys.watchFile(sourceFile.fileName, function () { return sourceFileChanged(sourceFile); });
  26220. }
  26221. return sourceFile;
  26222. }
  26223. function setCachedProgram(program) {
  26224. if (cachedProgram) {
  26225. var newSourceFiles = program ? program.getSourceFiles() : undefined;
  26226. ts.forEach(cachedProgram.getSourceFiles(), function (sourceFile) {
  26227. if (!(newSourceFiles && ts.contains(newSourceFiles, sourceFile))) {
  26228. if (sourceFile.fileWatcher) {
  26229. sourceFile.fileWatcher.close();
  26230. sourceFile.fileWatcher = undefined;
  26231. }
  26232. }
  26233. });
  26234. }
  26235. cachedProgram = program;
  26236. }
  26237. function sourceFileChanged(sourceFile) {
  26238. sourceFile.fileWatcher.close();
  26239. sourceFile.fileWatcher = undefined;
  26240. startTimer();
  26241. }
  26242. function configFileChanged() {
  26243. setCachedProgram(undefined);
  26244. startTimer();
  26245. }
  26246. function startTimer() {
  26247. if (timerHandle) {
  26248. clearTimeout(timerHandle);
  26249. }
  26250. timerHandle = setTimeout(recompile, 250);
  26251. }
  26252. function recompile() {
  26253. timerHandle = undefined;
  26254. reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation));
  26255. performCompilation();
  26256. }
  26257. }
  26258. ts.executeCommandLine = executeCommandLine;
  26259. function compile(fileNames, compilerOptions, compilerHost) {
  26260. ts.ioReadTime = 0;
  26261. ts.ioWriteTime = 0;
  26262. ts.programTime = 0;
  26263. ts.bindTime = 0;
  26264. ts.checkTime = 0;
  26265. ts.emitTime = 0;
  26266. var program = ts.createProgram(fileNames, compilerOptions, compilerHost);
  26267. var exitStatus = compileProgram();
  26268. if (compilerOptions.listFiles) {
  26269. ts.forEach(program.getSourceFiles(), function (file) {
  26270. ts.sys.write(file.fileName + ts.sys.newLine);
  26271. });
  26272. }
  26273. if (compilerOptions.diagnostics) {
  26274. var memoryUsed = ts.sys.getMemoryUsage ? ts.sys.getMemoryUsage() : -1;
  26275. reportCountStatistic("Files", program.getSourceFiles().length);
  26276. reportCountStatistic("Lines", countLines(program));
  26277. reportCountStatistic("Nodes", program.getNodeCount());
  26278. reportCountStatistic("Identifiers", program.getIdentifierCount());
  26279. reportCountStatistic("Symbols", program.getSymbolCount());
  26280. reportCountStatistic("Types", program.getTypeCount());
  26281. if (memoryUsed >= 0) {
  26282. reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K");
  26283. }
  26284. reportTimeStatistic("I/O read", ts.ioReadTime);
  26285. reportTimeStatistic("I/O write", ts.ioWriteTime);
  26286. reportTimeStatistic("Parse time", ts.programTime);
  26287. reportTimeStatistic("Bind time", ts.bindTime);
  26288. reportTimeStatistic("Check time", ts.checkTime);
  26289. reportTimeStatistic("Emit time", ts.emitTime);
  26290. reportTimeStatistic("Total time", ts.programTime + ts.bindTime + ts.checkTime + ts.emitTime);
  26291. }
  26292. return { program: program, exitStatus: exitStatus };
  26293. function compileProgram() {
  26294. var diagnostics = program.getSyntacticDiagnostics();
  26295. reportDiagnostics(diagnostics);
  26296. if (diagnostics.length === 0) {
  26297. var diagnostics = program.getGlobalDiagnostics();
  26298. reportDiagnostics(diagnostics);
  26299. if (diagnostics.length === 0) {
  26300. var diagnostics = program.getSemanticDiagnostics();
  26301. reportDiagnostics(diagnostics);
  26302. }
  26303. }
  26304. if (compilerOptions.noEmit) {
  26305. return diagnostics.length
  26306. ? ts.ExitStatus.DiagnosticsPresent_OutputsSkipped
  26307. : ts.ExitStatus.Success;
  26308. }
  26309. var emitOutput = program.emit();
  26310. reportDiagnostics(emitOutput.diagnostics);
  26311. if (emitOutput.emitSkipped) {
  26312. return ts.ExitStatus.DiagnosticsPresent_OutputsSkipped;
  26313. }
  26314. if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) {
  26315. return ts.ExitStatus.DiagnosticsPresent_OutputsGenerated;
  26316. }
  26317. return ts.ExitStatus.Success;
  26318. }
  26319. }
  26320. function printVersion() {
  26321. ts.sys.write(getDiagnosticText(ts.Diagnostics.Version_0, ts.version) + ts.sys.newLine);
  26322. }
  26323. function printHelp() {
  26324. var output = "";
  26325. var syntaxLength = getDiagnosticText(ts.Diagnostics.Syntax_Colon_0, "").length;
  26326. var examplesLength = getDiagnosticText(ts.Diagnostics.Examples_Colon_0, "").length;
  26327. var marginLength = Math.max(syntaxLength, examplesLength);
  26328. var syntax = makePadding(marginLength - syntaxLength);
  26329. syntax += "tsc [" + getDiagnosticText(ts.Diagnostics.options) + "] [" + getDiagnosticText(ts.Diagnostics.file) + " ...]";
  26330. output += getDiagnosticText(ts.Diagnostics.Syntax_Colon_0, syntax);
  26331. output += ts.sys.newLine + ts.sys.newLine;
  26332. var padding = makePadding(marginLength);
  26333. output += getDiagnosticText(ts.Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + ts.sys.newLine;
  26334. output += padding + "tsc --out file.js file.ts" + ts.sys.newLine;
  26335. output += padding + "tsc @args.txt" + ts.sys.newLine;
  26336. output += ts.sys.newLine;
  26337. output += getDiagnosticText(ts.Diagnostics.Options_Colon) + ts.sys.newLine;
  26338. var optsList = ts.filter(ts.optionDeclarations.slice(), function (v) { return !v.experimental; });
  26339. optsList.sort(function (a, b) { return ts.compareValues(a.name.toLowerCase(), b.name.toLowerCase()); });
  26340. var marginLength = 0;
  26341. var usageColumn = [];
  26342. var descriptionColumn = [];
  26343. for (var i = 0; i < optsList.length; i++) {
  26344. var option = optsList[i];
  26345. if (!option.description) {
  26346. continue;
  26347. }
  26348. var usageText = " ";
  26349. if (option.shortName) {
  26350. usageText += "-" + option.shortName;
  26351. usageText += getParamType(option);
  26352. usageText += ", ";
  26353. }
  26354. usageText += "--" + option.name;
  26355. usageText += getParamType(option);
  26356. usageColumn.push(usageText);
  26357. descriptionColumn.push(getDiagnosticText(option.description));
  26358. marginLength = Math.max(usageText.length, marginLength);
  26359. }
  26360. var usageText = " @<" + getDiagnosticText(ts.Diagnostics.file) + ">";
  26361. usageColumn.push(usageText);
  26362. descriptionColumn.push(getDiagnosticText(ts.Diagnostics.Insert_command_line_options_and_files_from_a_file));
  26363. marginLength = Math.max(usageText.length, marginLength);
  26364. for (var i = 0; i < usageColumn.length; i++) {
  26365. var usage = usageColumn[i];
  26366. var description = descriptionColumn[i];
  26367. output += usage + makePadding(marginLength - usage.length + 2) + description + ts.sys.newLine;
  26368. }
  26369. ts.sys.write(output);
  26370. return;
  26371. function getParamType(option) {
  26372. if (option.paramType !== undefined) {
  26373. return " " + getDiagnosticText(option.paramType);
  26374. }
  26375. return "";
  26376. }
  26377. function makePadding(paddingLength) {
  26378. return Array(paddingLength + 1).join(" ");
  26379. }
  26380. }
  26381. })(ts || (ts = {}));
  26382. ts.executeCommandLine(ts.sys.args);