Front end of the Slack clone application.

compiler.js 983KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes} checked by tsc
  9. */
  10. /**
  11. * @license
  12. * Copyright Google Inc. All Rights Reserved.
  13. *
  14. * Use of this source code is governed by an MIT-style license that can be
  15. * found in the LICENSE file at https://angular.io/license
  16. */
  17. // Attention:
  18. // This file duplicates types and values from @angular/core
  19. // so that we are able to make @angular/compiler independent of @angular/core.
  20. // This is important to prevent a build cycle, as @angular/core needs to
  21. // be compiled with the compiler.
  22. /**
  23. * @record
  24. */
  25. function Inject() { }
  26. const createInject = makeMetadataFactory('Inject', (token) => ({ token }));
  27. const createInjectionToken = makeMetadataFactory('InjectionToken', (desc) => ({ _desc: desc }));
  28. /**
  29. * @record
  30. */
  31. function Attribute() { }
  32. const createAttribute = makeMetadataFactory('Attribute', (attributeName) => ({ attributeName }));
  33. /**
  34. * @record
  35. */
  36. function Query() { }
  37. const createContentChildren = makeMetadataFactory('ContentChildren', (selector, data = {}) => (Object.assign({ selector, first: false, isViewQuery: false, descendants: false }, data)));
  38. const createContentChild = makeMetadataFactory('ContentChild', (selector, data = {}) => (Object.assign({ selector, first: true, isViewQuery: false, descendants: true }, data)));
  39. const createViewChildren = makeMetadataFactory('ViewChildren', (selector, data = {}) => (Object.assign({ selector, first: false, isViewQuery: true, descendants: true }, data)));
  40. const createViewChild = makeMetadataFactory('ViewChild', (selector, data) => (Object.assign({ selector, first: true, isViewQuery: true, descendants: true }, data)));
  41. /**
  42. * @record
  43. */
  44. function Directive() { }
  45. const createDirective = makeMetadataFactory('Directive', (dir = {}) => dir);
  46. /**
  47. * @record
  48. */
  49. function Component() { }
  50. /** @enum {number} */
  51. const ViewEncapsulation = {
  52. Emulated: 0,
  53. Native: 1,
  54. None: 2,
  55. };
  56. ViewEncapsulation[ViewEncapsulation.Emulated] = "Emulated";
  57. ViewEncapsulation[ViewEncapsulation.Native] = "Native";
  58. ViewEncapsulation[ViewEncapsulation.None] = "None";
  59. /** @enum {number} */
  60. const ChangeDetectionStrategy = {
  61. OnPush: 0,
  62. Default: 1,
  63. };
  64. ChangeDetectionStrategy[ChangeDetectionStrategy.OnPush] = "OnPush";
  65. ChangeDetectionStrategy[ChangeDetectionStrategy.Default] = "Default";
  66. const createComponent = makeMetadataFactory('Component', (c = {}) => (Object.assign({ changeDetection: ChangeDetectionStrategy.Default }, c)));
  67. /**
  68. * @record
  69. */
  70. function Pipe() { }
  71. const createPipe = makeMetadataFactory('Pipe', (p) => (Object.assign({ pure: true }, p)));
  72. /**
  73. * @record
  74. */
  75. function Input() { }
  76. const createInput = makeMetadataFactory('Input', (bindingPropertyName) => ({ bindingPropertyName }));
  77. /**
  78. * @record
  79. */
  80. function Output() { }
  81. const createOutput = makeMetadataFactory('Output', (bindingPropertyName) => ({ bindingPropertyName }));
  82. /**
  83. * @record
  84. */
  85. function HostBinding() { }
  86. const createHostBinding = makeMetadataFactory('HostBinding', (hostPropertyName) => ({ hostPropertyName }));
  87. /**
  88. * @record
  89. */
  90. function HostListener() { }
  91. const createHostListener = makeMetadataFactory('HostListener', (eventName, args) => ({ eventName, args }));
  92. /**
  93. * @record
  94. */
  95. function NgModule() { }
  96. const createNgModule = makeMetadataFactory('NgModule', (ngModule) => ngModule);
  97. /**
  98. * @record
  99. */
  100. function ModuleWithProviders() { }
  101. /**
  102. * @record
  103. */
  104. function SchemaMetadata() { }
  105. const CUSTOM_ELEMENTS_SCHEMA = {
  106. name: 'custom-elements'
  107. };
  108. const NO_ERRORS_SCHEMA = {
  109. name: 'no-errors-schema'
  110. };
  111. const createOptional = makeMetadataFactory('Optional');
  112. const createInjectable = makeMetadataFactory('Injectable');
  113. const createSelf = makeMetadataFactory('Self');
  114. const createSkipSelf = makeMetadataFactory('SkipSelf');
  115. const createHost = makeMetadataFactory('Host');
  116. const Type = Function;
  117. /** @enum {number} */
  118. const SecurityContext = {
  119. NONE: 0,
  120. HTML: 1,
  121. STYLE: 2,
  122. SCRIPT: 3,
  123. URL: 4,
  124. RESOURCE_URL: 5,
  125. };
  126. SecurityContext[SecurityContext.NONE] = "NONE";
  127. SecurityContext[SecurityContext.HTML] = "HTML";
  128. SecurityContext[SecurityContext.STYLE] = "STYLE";
  129. SecurityContext[SecurityContext.SCRIPT] = "SCRIPT";
  130. SecurityContext[SecurityContext.URL] = "URL";
  131. SecurityContext[SecurityContext.RESOURCE_URL] = "RESOURCE_URL";
  132. /** @enum {number} */
  133. const NodeFlags = {
  134. None: 0,
  135. TypeElement: 1,
  136. TypeText: 2,
  137. ProjectedTemplate: 4,
  138. CatRenderNode: 3,
  139. TypeNgContent: 8,
  140. TypePipe: 16,
  141. TypePureArray: 32,
  142. TypePureObject: 64,
  143. TypePurePipe: 128,
  144. CatPureExpression: 224,
  145. TypeValueProvider: 256,
  146. TypeClassProvider: 512,
  147. TypeFactoryProvider: 1024,
  148. TypeUseExistingProvider: 2048,
  149. LazyProvider: 4096,
  150. PrivateProvider: 8192,
  151. TypeDirective: 16384,
  152. Component: 32768,
  153. CatProviderNoDirective: 3840,
  154. CatProvider: 20224,
  155. OnInit: 65536,
  156. OnDestroy: 131072,
  157. DoCheck: 262144,
  158. OnChanges: 524288,
  159. AfterContentInit: 1048576,
  160. AfterContentChecked: 2097152,
  161. AfterViewInit: 4194304,
  162. AfterViewChecked: 8388608,
  163. EmbeddedViews: 16777216,
  164. ComponentView: 33554432,
  165. TypeContentQuery: 67108864,
  166. TypeViewQuery: 134217728,
  167. StaticQuery: 268435456,
  168. DynamicQuery: 536870912,
  169. CatQuery: 201326592,
  170. // mutually exclusive values...
  171. Types: 201347067,
  172. };
  173. /** @enum {number} */
  174. const DepFlags = {
  175. None: 0,
  176. SkipSelf: 1,
  177. Optional: 2,
  178. Value: 8,
  179. };
  180. /** @enum {number} */
  181. const ArgumentType = { Inline: 0, Dynamic: 1, };
  182. /** @enum {number} */
  183. const BindingFlags = {
  184. TypeElementAttribute: 1,
  185. TypeElementClass: 2,
  186. TypeElementStyle: 4,
  187. TypeProperty: 8,
  188. SyntheticProperty: 16,
  189. SyntheticHostProperty: 32,
  190. CatSyntheticProperty: 48,
  191. // mutually exclusive values...
  192. Types: 15,
  193. };
  194. /** @enum {number} */
  195. const QueryBindingType = { First: 0, All: 1, };
  196. /** @enum {number} */
  197. const QueryValueType = {
  198. ElementRef: 0,
  199. RenderElement: 1,
  200. TemplateRef: 2,
  201. ViewContainerRef: 3,
  202. Provider: 4,
  203. };
  204. /** @enum {number} */
  205. const ViewFlags = {
  206. None: 0,
  207. OnPush: 2,
  208. };
  209. /** @enum {number} */
  210. const MissingTranslationStrategy = {
  211. Error: 0,
  212. Warning: 1,
  213. Ignore: 2,
  214. };
  215. MissingTranslationStrategy[MissingTranslationStrategy.Error] = "Error";
  216. MissingTranslationStrategy[MissingTranslationStrategy.Warning] = "Warning";
  217. MissingTranslationStrategy[MissingTranslationStrategy.Ignore] = "Ignore";
  218. /**
  219. * @record
  220. * @template T
  221. */
  222. function MetadataFactory() { }
  223. /**
  224. * @template T
  225. * @param {?} name
  226. * @param {?=} props
  227. * @return {?}
  228. */
  229. function makeMetadataFactory(name, props) {
  230. const /** @type {?} */ factory = (...args) => {
  231. const /** @type {?} */ values = props ? props(...args) : {};
  232. return Object.assign({ ngMetadataName: name }, values);
  233. };
  234. factory.isTypeOf = (obj) => obj && obj.ngMetadataName === name;
  235. factory.ngMetadataName = name;
  236. return factory;
  237. }
  238. /**
  239. * @record
  240. */
  241. function Route() { }
  242. var core = Object.freeze({
  243. Inject: Inject,
  244. createInject: createInject,
  245. createInjectionToken: createInjectionToken,
  246. Attribute: Attribute,
  247. createAttribute: createAttribute,
  248. Query: Query,
  249. createContentChildren: createContentChildren,
  250. createContentChild: createContentChild,
  251. createViewChildren: createViewChildren,
  252. createViewChild: createViewChild,
  253. Directive: Directive,
  254. createDirective: createDirective,
  255. Component: Component,
  256. ViewEncapsulation: ViewEncapsulation,
  257. ChangeDetectionStrategy: ChangeDetectionStrategy,
  258. createComponent: createComponent,
  259. Pipe: Pipe,
  260. createPipe: createPipe,
  261. Input: Input,
  262. createInput: createInput,
  263. Output: Output,
  264. createOutput: createOutput,
  265. HostBinding: HostBinding,
  266. createHostBinding: createHostBinding,
  267. HostListener: HostListener,
  268. createHostListener: createHostListener,
  269. NgModule: NgModule,
  270. createNgModule: createNgModule,
  271. ModuleWithProviders: ModuleWithProviders,
  272. SchemaMetadata: SchemaMetadata,
  273. CUSTOM_ELEMENTS_SCHEMA: CUSTOM_ELEMENTS_SCHEMA,
  274. NO_ERRORS_SCHEMA: NO_ERRORS_SCHEMA,
  275. createOptional: createOptional,
  276. createInjectable: createInjectable,
  277. createSelf: createSelf,
  278. createSkipSelf: createSkipSelf,
  279. createHost: createHost,
  280. Type: Type,
  281. SecurityContext: SecurityContext,
  282. NodeFlags: NodeFlags,
  283. DepFlags: DepFlags,
  284. ArgumentType: ArgumentType,
  285. BindingFlags: BindingFlags,
  286. QueryBindingType: QueryBindingType,
  287. QueryValueType: QueryValueType,
  288. ViewFlags: ViewFlags,
  289. MissingTranslationStrategy: MissingTranslationStrategy,
  290. MetadataFactory: MetadataFactory,
  291. Route: Route
  292. });
  293. /**
  294. * @fileoverview added by tsickle
  295. * @suppress {checkTypes} checked by tsc
  296. */
  297. /**
  298. * @license
  299. * Copyright Google Inc. All Rights Reserved.
  300. *
  301. * Use of this source code is governed by an MIT-style license that can be
  302. * found in the LICENSE file at https://angular.io/license
  303. */
  304. const DASH_CASE_REGEXP = /-+([a-z0-9])/g;
  305. /**
  306. * @param {?} input
  307. * @return {?}
  308. */
  309. function dashCaseToCamelCase(input) {
  310. return input.replace(DASH_CASE_REGEXP, (...m) => m[1].toUpperCase());
  311. }
  312. /**
  313. * @param {?} input
  314. * @param {?} defaultValues
  315. * @return {?}
  316. */
  317. function splitAtColon(input, defaultValues) {
  318. return _splitAt(input, ':', defaultValues);
  319. }
  320. /**
  321. * @param {?} input
  322. * @param {?} defaultValues
  323. * @return {?}
  324. */
  325. function splitAtPeriod(input, defaultValues) {
  326. return _splitAt(input, '.', defaultValues);
  327. }
  328. /**
  329. * @param {?} input
  330. * @param {?} character
  331. * @param {?} defaultValues
  332. * @return {?}
  333. */
  334. function _splitAt(input, character, defaultValues) {
  335. const /** @type {?} */ characterIndex = input.indexOf(character);
  336. if (characterIndex == -1)
  337. return defaultValues;
  338. return [input.slice(0, characterIndex).trim(), input.slice(characterIndex + 1).trim()];
  339. }
  340. /**
  341. * @param {?} value
  342. * @param {?} visitor
  343. * @param {?} context
  344. * @return {?}
  345. */
  346. function visitValue(value, visitor, context) {
  347. if (Array.isArray(value)) {
  348. return visitor.visitArray(/** @type {?} */ (value), context);
  349. }
  350. if (isStrictStringMap(value)) {
  351. return visitor.visitStringMap(/** @type {?} */ (value), context);
  352. }
  353. if (value == null || typeof value == 'string' || typeof value == 'number' ||
  354. typeof value == 'boolean') {
  355. return visitor.visitPrimitive(value, context);
  356. }
  357. return visitor.visitOther(value, context);
  358. }
  359. /**
  360. * @param {?} val
  361. * @return {?}
  362. */
  363. function isDefined(val) {
  364. return val !== null && val !== undefined;
  365. }
  366. /**
  367. * @template T
  368. * @param {?} val
  369. * @return {?}
  370. */
  371. function noUndefined(val) {
  372. return val === undefined ? /** @type {?} */ ((null)) : val;
  373. }
  374. /**
  375. * @record
  376. */
  377. class ValueTransformer {
  378. /**
  379. * @param {?} arr
  380. * @param {?} context
  381. * @return {?}
  382. */
  383. visitArray(arr, context) {
  384. return arr.map(value => visitValue(value, this, context));
  385. }
  386. /**
  387. * @param {?} map
  388. * @param {?} context
  389. * @return {?}
  390. */
  391. visitStringMap(map, context) {
  392. const /** @type {?} */ result = {};
  393. Object.keys(map).forEach(key => { result[key] = visitValue(map[key], this, context); });
  394. return result;
  395. }
  396. /**
  397. * @param {?} value
  398. * @param {?} context
  399. * @return {?}
  400. */
  401. visitPrimitive(value, context) { return value; }
  402. /**
  403. * @param {?} value
  404. * @param {?} context
  405. * @return {?}
  406. */
  407. visitOther(value, context) { return value; }
  408. }
  409. const SyncAsync = {
  410. assertSync: (value) => {
  411. if (isPromise(value)) {
  412. throw new Error(`Illegal state: value cannot be a promise`);
  413. }
  414. return value;
  415. },
  416. then: (value, cb) => { return isPromise(value) ? value.then(cb) : cb(value); },
  417. all: (syncAsyncValues) => {
  418. return syncAsyncValues.some(isPromise) ? Promise.all(syncAsyncValues) : /** @type {?} */ (syncAsyncValues);
  419. }
  420. };
  421. /**
  422. * @param {?} msg
  423. * @param {?=} parseErrors
  424. * @return {?}
  425. */
  426. function syntaxError(msg, parseErrors) {
  427. const /** @type {?} */ error = Error(msg);
  428. (/** @type {?} */ (error))[ERROR_SYNTAX_ERROR] = true;
  429. if (parseErrors)
  430. (/** @type {?} */ (error))[ERROR_PARSE_ERRORS] = parseErrors;
  431. return error;
  432. }
  433. const ERROR_SYNTAX_ERROR = 'ngSyntaxError';
  434. const ERROR_PARSE_ERRORS = 'ngParseErrors';
  435. /**
  436. * @param {?} error
  437. * @return {?}
  438. */
  439. function isSyntaxError(error) {
  440. return (/** @type {?} */ (error))[ERROR_SYNTAX_ERROR];
  441. }
  442. /**
  443. * @param {?} error
  444. * @return {?}
  445. */
  446. function getParseErrors(error) {
  447. return (/** @type {?} */ (error))[ERROR_PARSE_ERRORS] || [];
  448. }
  449. /**
  450. * @param {?} s
  451. * @return {?}
  452. */
  453. function escapeRegExp(s) {
  454. return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
  455. }
  456. const STRING_MAP_PROTO = Object.getPrototypeOf({});
  457. /**
  458. * @param {?} obj
  459. * @return {?}
  460. */
  461. function isStrictStringMap(obj) {
  462. return typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === STRING_MAP_PROTO;
  463. }
  464. /**
  465. * @param {?} str
  466. * @return {?}
  467. */
  468. function utf8Encode(str) {
  469. let /** @type {?} */ encoded = '';
  470. for (let /** @type {?} */ index = 0; index < str.length; index++) {
  471. let /** @type {?} */ codePoint = str.charCodeAt(index);
  472. // decode surrogate
  473. // see https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  474. if (codePoint >= 0xd800 && codePoint <= 0xdbff && str.length > (index + 1)) {
  475. const /** @type {?} */ low = str.charCodeAt(index + 1);
  476. if (low >= 0xdc00 && low <= 0xdfff) {
  477. index++;
  478. codePoint = ((codePoint - 0xd800) << 10) + low - 0xdc00 + 0x10000;
  479. }
  480. }
  481. if (codePoint <= 0x7f) {
  482. encoded += String.fromCharCode(codePoint);
  483. }
  484. else if (codePoint <= 0x7ff) {
  485. encoded += String.fromCharCode(((codePoint >> 6) & 0x1F) | 0xc0, (codePoint & 0x3f) | 0x80);
  486. }
  487. else if (codePoint <= 0xffff) {
  488. encoded += String.fromCharCode((codePoint >> 12) | 0xe0, ((codePoint >> 6) & 0x3f) | 0x80, (codePoint & 0x3f) | 0x80);
  489. }
  490. else if (codePoint <= 0x1fffff) {
  491. encoded += String.fromCharCode(((codePoint >> 18) & 0x07) | 0xf0, ((codePoint >> 12) & 0x3f) | 0x80, ((codePoint >> 6) & 0x3f) | 0x80, (codePoint & 0x3f) | 0x80);
  492. }
  493. }
  494. return encoded;
  495. }
  496. /**
  497. * @record
  498. */
  499. /**
  500. * @param {?} token
  501. * @return {?}
  502. */
  503. function stringify(token) {
  504. if (typeof token === 'string') {
  505. return token;
  506. }
  507. if (token instanceof Array) {
  508. return '[' + token.map(stringify).join(', ') + ']';
  509. }
  510. if (token == null) {
  511. return '' + token;
  512. }
  513. if (token.overriddenName) {
  514. return `${token.overriddenName}`;
  515. }
  516. if (token.name) {
  517. return `${token.name}`;
  518. }
  519. const /** @type {?} */ res = token.toString();
  520. if (res == null) {
  521. return '' + res;
  522. }
  523. const /** @type {?} */ newLineIndex = res.indexOf('\n');
  524. return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
  525. }
  526. /**
  527. * Lazily retrieves the reference value from a forwardRef.
  528. * @param {?} type
  529. * @return {?}
  530. */
  531. function resolveForwardRef(type) {
  532. if (typeof type === 'function' && type.hasOwnProperty('__forward_ref__')) {
  533. return type();
  534. }
  535. else {
  536. return type;
  537. }
  538. }
  539. /**
  540. * Determine if the argument is shaped like a Promise
  541. * @param {?} obj
  542. * @return {?}
  543. */
  544. function isPromise(obj) {
  545. // allow any Promise/A+ compliant thenable.
  546. // It's up to the caller to ensure that obj.then conforms to the spec
  547. return !!obj && typeof obj.then === 'function';
  548. }
  549. class Version {
  550. /**
  551. * @param {?} full
  552. */
  553. constructor(full) {
  554. this.full = full;
  555. const /** @type {?} */ splits = full.split('.');
  556. this.major = splits[0];
  557. this.minor = splits[1];
  558. this.patch = splits.slice(2).join('.');
  559. }
  560. }
  561. /**
  562. * @record
  563. */
  564. /**
  565. * @fileoverview added by tsickle
  566. * @suppress {checkTypes} checked by tsc
  567. */
  568. /**
  569. * @license
  570. * Copyright Google Inc. All Rights Reserved.
  571. *
  572. * Use of this source code is governed by an MIT-style license that can be
  573. * found in the LICENSE file at https://angular.io/license
  574. */
  575. /**
  576. * \@stable
  577. */
  578. const VERSION = new Version('5.2.11');
  579. /**
  580. * @fileoverview added by tsickle
  581. * @suppress {checkTypes} checked by tsc
  582. */
  583. /**
  584. * @license
  585. * Copyright Google Inc. All Rights Reserved.
  586. *
  587. * Use of this source code is governed by an MIT-style license that can be
  588. * found in the LICENSE file at https://angular.io/license
  589. */
  590. /**
  591. * An Abstract Syntax Tree node representing part of a parsed Angular template.
  592. * @record
  593. */
  594. /**
  595. * A segment of text within the template.
  596. */
  597. class TextAst {
  598. /**
  599. * @param {?} value
  600. * @param {?} ngContentIndex
  601. * @param {?} sourceSpan
  602. */
  603. constructor(value, ngContentIndex, sourceSpan) {
  604. this.value = value;
  605. this.ngContentIndex = ngContentIndex;
  606. this.sourceSpan = sourceSpan;
  607. }
  608. /**
  609. * @param {?} visitor
  610. * @param {?} context
  611. * @return {?}
  612. */
  613. visit(visitor, context) { return visitor.visitText(this, context); }
  614. }
  615. /**
  616. * A bound expression within the text of a template.
  617. */
  618. class BoundTextAst {
  619. /**
  620. * @param {?} value
  621. * @param {?} ngContentIndex
  622. * @param {?} sourceSpan
  623. */
  624. constructor(value, ngContentIndex, sourceSpan) {
  625. this.value = value;
  626. this.ngContentIndex = ngContentIndex;
  627. this.sourceSpan = sourceSpan;
  628. }
  629. /**
  630. * @param {?} visitor
  631. * @param {?} context
  632. * @return {?}
  633. */
  634. visit(visitor, context) {
  635. return visitor.visitBoundText(this, context);
  636. }
  637. }
  638. /**
  639. * A plain attribute on an element.
  640. */
  641. class AttrAst {
  642. /**
  643. * @param {?} name
  644. * @param {?} value
  645. * @param {?} sourceSpan
  646. */
  647. constructor(name, value, sourceSpan) {
  648. this.name = name;
  649. this.value = value;
  650. this.sourceSpan = sourceSpan;
  651. }
  652. /**
  653. * @param {?} visitor
  654. * @param {?} context
  655. * @return {?}
  656. */
  657. visit(visitor, context) { return visitor.visitAttr(this, context); }
  658. }
  659. /**
  660. * A binding for an element property (e.g. `[property]="expression"`) or an animation trigger (e.g.
  661. * `[\@trigger]="stateExp"`)
  662. */
  663. class BoundElementPropertyAst {
  664. /**
  665. * @param {?} name
  666. * @param {?} type
  667. * @param {?} securityContext
  668. * @param {?} value
  669. * @param {?} unit
  670. * @param {?} sourceSpan
  671. */
  672. constructor(name, type, securityContext, value, unit, sourceSpan) {
  673. this.name = name;
  674. this.type = type;
  675. this.securityContext = securityContext;
  676. this.value = value;
  677. this.unit = unit;
  678. this.sourceSpan = sourceSpan;
  679. this.isAnimation = this.type === PropertyBindingType.Animation;
  680. }
  681. /**
  682. * @param {?} visitor
  683. * @param {?} context
  684. * @return {?}
  685. */
  686. visit(visitor, context) {
  687. return visitor.visitElementProperty(this, context);
  688. }
  689. }
  690. /**
  691. * A binding for an element event (e.g. `(event)="handler()"`) or an animation trigger event (e.g.
  692. * `(\@trigger.phase)="callback($event)"`).
  693. */
  694. class BoundEventAst {
  695. /**
  696. * @param {?} name
  697. * @param {?} target
  698. * @param {?} phase
  699. * @param {?} handler
  700. * @param {?} sourceSpan
  701. */
  702. constructor(name, target, phase, handler, sourceSpan) {
  703. this.name = name;
  704. this.target = target;
  705. this.phase = phase;
  706. this.handler = handler;
  707. this.sourceSpan = sourceSpan;
  708. this.fullName = BoundEventAst.calcFullName(this.name, this.target, this.phase);
  709. this.isAnimation = !!this.phase;
  710. }
  711. /**
  712. * @param {?} name
  713. * @param {?} target
  714. * @param {?} phase
  715. * @return {?}
  716. */
  717. static calcFullName(name, target, phase) {
  718. if (target) {
  719. return `${target}:${name}`;
  720. }
  721. else if (phase) {
  722. return `@${name}.${phase}`;
  723. }
  724. else {
  725. return name;
  726. }
  727. }
  728. /**
  729. * @param {?} visitor
  730. * @param {?} context
  731. * @return {?}
  732. */
  733. visit(visitor, context) {
  734. return visitor.visitEvent(this, context);
  735. }
  736. }
  737. /**
  738. * A reference declaration on an element (e.g. `let someName="expression"`).
  739. */
  740. class ReferenceAst {
  741. /**
  742. * @param {?} name
  743. * @param {?} value
  744. * @param {?} sourceSpan
  745. */
  746. constructor(name, value, sourceSpan) {
  747. this.name = name;
  748. this.value = value;
  749. this.sourceSpan = sourceSpan;
  750. }
  751. /**
  752. * @param {?} visitor
  753. * @param {?} context
  754. * @return {?}
  755. */
  756. visit(visitor, context) {
  757. return visitor.visitReference(this, context);
  758. }
  759. }
  760. /**
  761. * A variable declaration on a <ng-template> (e.g. `var-someName="someLocalName"`).
  762. */
  763. class VariableAst {
  764. /**
  765. * @param {?} name
  766. * @param {?} value
  767. * @param {?} sourceSpan
  768. */
  769. constructor(name, value, sourceSpan) {
  770. this.name = name;
  771. this.value = value;
  772. this.sourceSpan = sourceSpan;
  773. }
  774. /**
  775. * @param {?} visitor
  776. * @param {?} context
  777. * @return {?}
  778. */
  779. visit(visitor, context) {
  780. return visitor.visitVariable(this, context);
  781. }
  782. }
  783. /**
  784. * An element declaration in a template.
  785. */
  786. class ElementAst {
  787. /**
  788. * @param {?} name
  789. * @param {?} attrs
  790. * @param {?} inputs
  791. * @param {?} outputs
  792. * @param {?} references
  793. * @param {?} directives
  794. * @param {?} providers
  795. * @param {?} hasViewContainer
  796. * @param {?} queryMatches
  797. * @param {?} children
  798. * @param {?} ngContentIndex
  799. * @param {?} sourceSpan
  800. * @param {?} endSourceSpan
  801. */
  802. constructor(name, attrs, inputs, outputs, references, directives, providers, hasViewContainer, queryMatches, children, ngContentIndex, sourceSpan, endSourceSpan) {
  803. this.name = name;
  804. this.attrs = attrs;
  805. this.inputs = inputs;
  806. this.outputs = outputs;
  807. this.references = references;
  808. this.directives = directives;
  809. this.providers = providers;
  810. this.hasViewContainer = hasViewContainer;
  811. this.queryMatches = queryMatches;
  812. this.children = children;
  813. this.ngContentIndex = ngContentIndex;
  814. this.sourceSpan = sourceSpan;
  815. this.endSourceSpan = endSourceSpan;
  816. }
  817. /**
  818. * @param {?} visitor
  819. * @param {?} context
  820. * @return {?}
  821. */
  822. visit(visitor, context) {
  823. return visitor.visitElement(this, context);
  824. }
  825. }
  826. /**
  827. * A `<ng-template>` element included in an Angular template.
  828. */
  829. class EmbeddedTemplateAst {
  830. /**
  831. * @param {?} attrs
  832. * @param {?} outputs
  833. * @param {?} references
  834. * @param {?} variables
  835. * @param {?} directives
  836. * @param {?} providers
  837. * @param {?} hasViewContainer
  838. * @param {?} queryMatches
  839. * @param {?} children
  840. * @param {?} ngContentIndex
  841. * @param {?} sourceSpan
  842. */
  843. constructor(attrs, outputs, references, variables, directives, providers, hasViewContainer, queryMatches, children, ngContentIndex, sourceSpan) {
  844. this.attrs = attrs;
  845. this.outputs = outputs;
  846. this.references = references;
  847. this.variables = variables;
  848. this.directives = directives;
  849. this.providers = providers;
  850. this.hasViewContainer = hasViewContainer;
  851. this.queryMatches = queryMatches;
  852. this.children = children;
  853. this.ngContentIndex = ngContentIndex;
  854. this.sourceSpan = sourceSpan;
  855. }
  856. /**
  857. * @param {?} visitor
  858. * @param {?} context
  859. * @return {?}
  860. */
  861. visit(visitor, context) {
  862. return visitor.visitEmbeddedTemplate(this, context);
  863. }
  864. }
  865. /**
  866. * A directive property with a bound value (e.g. `*ngIf="condition").
  867. */
  868. class BoundDirectivePropertyAst {
  869. /**
  870. * @param {?} directiveName
  871. * @param {?} templateName
  872. * @param {?} value
  873. * @param {?} sourceSpan
  874. */
  875. constructor(directiveName, templateName, value, sourceSpan) {
  876. this.directiveName = directiveName;
  877. this.templateName = templateName;
  878. this.value = value;
  879. this.sourceSpan = sourceSpan;
  880. }
  881. /**
  882. * @param {?} visitor
  883. * @param {?} context
  884. * @return {?}
  885. */
  886. visit(visitor, context) {
  887. return visitor.visitDirectiveProperty(this, context);
  888. }
  889. }
  890. /**
  891. * A directive declared on an element.
  892. */
  893. class DirectiveAst {
  894. /**
  895. * @param {?} directive
  896. * @param {?} inputs
  897. * @param {?} hostProperties
  898. * @param {?} hostEvents
  899. * @param {?} contentQueryStartId
  900. * @param {?} sourceSpan
  901. */
  902. constructor(directive, inputs, hostProperties, hostEvents, contentQueryStartId, sourceSpan) {
  903. this.directive = directive;
  904. this.inputs = inputs;
  905. this.hostProperties = hostProperties;
  906. this.hostEvents = hostEvents;
  907. this.contentQueryStartId = contentQueryStartId;
  908. this.sourceSpan = sourceSpan;
  909. }
  910. /**
  911. * @param {?} visitor
  912. * @param {?} context
  913. * @return {?}
  914. */
  915. visit(visitor, context) {
  916. return visitor.visitDirective(this, context);
  917. }
  918. }
  919. /**
  920. * A provider declared on an element
  921. */
  922. class ProviderAst {
  923. /**
  924. * @param {?} token
  925. * @param {?} multiProvider
  926. * @param {?} eager
  927. * @param {?} providers
  928. * @param {?} providerType
  929. * @param {?} lifecycleHooks
  930. * @param {?} sourceSpan
  931. */
  932. constructor(token, multiProvider, eager, providers, providerType, lifecycleHooks, sourceSpan) {
  933. this.token = token;
  934. this.multiProvider = multiProvider;
  935. this.eager = eager;
  936. this.providers = providers;
  937. this.providerType = providerType;
  938. this.lifecycleHooks = lifecycleHooks;
  939. this.sourceSpan = sourceSpan;
  940. }
  941. /**
  942. * @param {?} visitor
  943. * @param {?} context
  944. * @return {?}
  945. */
  946. visit(visitor, context) {
  947. // No visit method in the visitor for now...
  948. return null;
  949. }
  950. }
  951. /** @enum {number} */
  952. const ProviderAstType = {
  953. PublicService: 0,
  954. PrivateService: 1,
  955. Component: 2,
  956. Directive: 3,
  957. Builtin: 4,
  958. };
  959. ProviderAstType[ProviderAstType.PublicService] = "PublicService";
  960. ProviderAstType[ProviderAstType.PrivateService] = "PrivateService";
  961. ProviderAstType[ProviderAstType.Component] = "Component";
  962. ProviderAstType[ProviderAstType.Directive] = "Directive";
  963. ProviderAstType[ProviderAstType.Builtin] = "Builtin";
  964. /**
  965. * Position where content is to be projected (instance of `<ng-content>` in a template).
  966. */
  967. class NgContentAst {
  968. /**
  969. * @param {?} index
  970. * @param {?} ngContentIndex
  971. * @param {?} sourceSpan
  972. */
  973. constructor(index, ngContentIndex, sourceSpan) {
  974. this.index = index;
  975. this.ngContentIndex = ngContentIndex;
  976. this.sourceSpan = sourceSpan;
  977. }
  978. /**
  979. * @param {?} visitor
  980. * @param {?} context
  981. * @return {?}
  982. */
  983. visit(visitor, context) {
  984. return visitor.visitNgContent(this, context);
  985. }
  986. }
  987. /** @enum {number} */
  988. const PropertyBindingType = {
  989. /**
  990. * A normal binding to a property (e.g. `[property]="expression"`).
  991. */
  992. Property: 0,
  993. /**
  994. * A binding to an element attribute (e.g. `[attr.name]="expression"`).
  995. */
  996. Attribute: 1,
  997. /**
  998. * A binding to a CSS class (e.g. `[class.name]="condition"`).
  999. */
  1000. Class: 2,
  1001. /**
  1002. * A binding to a style rule (e.g. `[style.rule]="expression"`).
  1003. */
  1004. Style: 3,
  1005. /**
  1006. * A binding to an animation reference (e.g. `[animate.key]="expression"`).
  1007. */
  1008. Animation: 4,
  1009. };
  1010. PropertyBindingType[PropertyBindingType.Property] = "Property";
  1011. PropertyBindingType[PropertyBindingType.Attribute] = "Attribute";
  1012. PropertyBindingType[PropertyBindingType.Class] = "Class";
  1013. PropertyBindingType[PropertyBindingType.Style] = "Style";
  1014. PropertyBindingType[PropertyBindingType.Animation] = "Animation";
  1015. /**
  1016. * @record
  1017. */
  1018. /**
  1019. * A visitor for {\@link TemplateAst} trees that will process each node.
  1020. * @record
  1021. */
  1022. /**
  1023. * A visitor that accepts each node but doesn't do anything. It is intended to be used
  1024. * as the base class for a visitor that is only interested in a subset of the node types.
  1025. */
  1026. class NullTemplateVisitor {
  1027. /**
  1028. * @param {?} ast
  1029. * @param {?} context
  1030. * @return {?}
  1031. */
  1032. visitNgContent(ast, context) { }
  1033. /**
  1034. * @param {?} ast
  1035. * @param {?} context
  1036. * @return {?}
  1037. */
  1038. visitEmbeddedTemplate(ast, context) { }
  1039. /**
  1040. * @param {?} ast
  1041. * @param {?} context
  1042. * @return {?}
  1043. */
  1044. visitElement(ast, context) { }
  1045. /**
  1046. * @param {?} ast
  1047. * @param {?} context
  1048. * @return {?}
  1049. */
  1050. visitReference(ast, context) { }
  1051. /**
  1052. * @param {?} ast
  1053. * @param {?} context
  1054. * @return {?}
  1055. */
  1056. visitVariable(ast, context) { }
  1057. /**
  1058. * @param {?} ast
  1059. * @param {?} context
  1060. * @return {?}
  1061. */
  1062. visitEvent(ast, context) { }
  1063. /**
  1064. * @param {?} ast
  1065. * @param {?} context
  1066. * @return {?}
  1067. */
  1068. visitElementProperty(ast, context) { }
  1069. /**
  1070. * @param {?} ast
  1071. * @param {?} context
  1072. * @return {?}
  1073. */
  1074. visitAttr(ast, context) { }
  1075. /**
  1076. * @param {?} ast
  1077. * @param {?} context
  1078. * @return {?}
  1079. */
  1080. visitBoundText(ast, context) { }
  1081. /**
  1082. * @param {?} ast
  1083. * @param {?} context
  1084. * @return {?}
  1085. */
  1086. visitText(ast, context) { }
  1087. /**
  1088. * @param {?} ast
  1089. * @param {?} context
  1090. * @return {?}
  1091. */
  1092. visitDirective(ast, context) { }
  1093. /**
  1094. * @param {?} ast
  1095. * @param {?} context
  1096. * @return {?}
  1097. */
  1098. visitDirectiveProperty(ast, context) { }
  1099. }
  1100. /**
  1101. * Base class that can be used to build a visitor that visits each node
  1102. * in an template ast recursively.
  1103. */
  1104. class RecursiveTemplateAstVisitor extends NullTemplateVisitor {
  1105. constructor() { super(); }
  1106. /**
  1107. * @param {?} ast
  1108. * @param {?} context
  1109. * @return {?}
  1110. */
  1111. visitEmbeddedTemplate(ast, context) {
  1112. return this.visitChildren(context, visit => {
  1113. visit(ast.attrs);
  1114. visit(ast.references);
  1115. visit(ast.variables);
  1116. visit(ast.directives);
  1117. visit(ast.providers);
  1118. visit(ast.children);
  1119. });
  1120. }
  1121. /**
  1122. * @param {?} ast
  1123. * @param {?} context
  1124. * @return {?}
  1125. */
  1126. visitElement(ast, context) {
  1127. return this.visitChildren(context, visit => {
  1128. visit(ast.attrs);
  1129. visit(ast.inputs);
  1130. visit(ast.outputs);
  1131. visit(ast.references);
  1132. visit(ast.directives);
  1133. visit(ast.providers);
  1134. visit(ast.children);
  1135. });
  1136. }
  1137. /**
  1138. * @param {?} ast
  1139. * @param {?} context
  1140. * @return {?}
  1141. */
  1142. visitDirective(ast, context) {
  1143. return this.visitChildren(context, visit => {
  1144. visit(ast.inputs);
  1145. visit(ast.hostProperties);
  1146. visit(ast.hostEvents);
  1147. });
  1148. }
  1149. /**
  1150. * @template T
  1151. * @param {?} context
  1152. * @param {?} cb
  1153. * @return {?}
  1154. */
  1155. visitChildren(context, cb) {
  1156. let /** @type {?} */ results = [];
  1157. let /** @type {?} */ t = this;
  1158. /**
  1159. * @template T
  1160. * @param {?} children
  1161. * @return {?}
  1162. */
  1163. function visit(children) {
  1164. if (children && children.length)
  1165. results.push(templateVisitAll(t, children, context));
  1166. }
  1167. cb(visit);
  1168. return [].concat.apply([], results);
  1169. }
  1170. }
  1171. /**
  1172. * Visit every node in a list of {\@link TemplateAst}s with the given {\@link TemplateAstVisitor}.
  1173. * @param {?} visitor
  1174. * @param {?} asts
  1175. * @param {?=} context
  1176. * @return {?}
  1177. */
  1178. function templateVisitAll(visitor, asts, context = null) {
  1179. const /** @type {?} */ result = [];
  1180. const /** @type {?} */ visit = visitor.visit ?
  1181. (ast) => /** @type {?} */ ((visitor.visit))(ast, context) || ast.visit(visitor, context) :
  1182. (ast) => ast.visit(visitor, context);
  1183. asts.forEach(ast => {
  1184. const /** @type {?} */ astResult = visit(ast);
  1185. if (astResult) {
  1186. result.push(astResult);
  1187. }
  1188. });
  1189. return result;
  1190. }
  1191. /**
  1192. * @fileoverview added by tsickle
  1193. * @suppress {checkTypes} checked by tsc
  1194. */
  1195. /**
  1196. * @license
  1197. * Copyright Google Inc. All Rights Reserved.
  1198. *
  1199. * Use of this source code is governed by an MIT-style license that can be
  1200. * found in the LICENSE file at https://angular.io/license
  1201. */
  1202. class CompilerConfig {
  1203. /**
  1204. * @param {?=} __0
  1205. */
  1206. constructor({ defaultEncapsulation = ViewEncapsulation.Emulated, useJit = true, jitDevMode = false, missingTranslation = null, enableLegacyTemplate, preserveWhitespaces, strictInjectionParameters } = {}) {
  1207. this.defaultEncapsulation = defaultEncapsulation;
  1208. this.useJit = !!useJit;
  1209. this.jitDevMode = !!jitDevMode;
  1210. this.missingTranslation = missingTranslation;
  1211. this.enableLegacyTemplate = enableLegacyTemplate === true;
  1212. this.preserveWhitespaces = preserveWhitespacesDefault(noUndefined(preserveWhitespaces));
  1213. this.strictInjectionParameters = strictInjectionParameters === true;
  1214. }
  1215. }
  1216. /**
  1217. * @param {?} preserveWhitespacesOption
  1218. * @param {?=} defaultSetting
  1219. * @return {?}
  1220. */
  1221. function preserveWhitespacesDefault(preserveWhitespacesOption, defaultSetting = true) {
  1222. return preserveWhitespacesOption === null ? defaultSetting : preserveWhitespacesOption;
  1223. }
  1224. /**
  1225. * @fileoverview added by tsickle
  1226. * @suppress {checkTypes} checked by tsc
  1227. */
  1228. /**
  1229. * @license
  1230. * Copyright Google Inc. All Rights Reserved.
  1231. *
  1232. * Use of this source code is governed by an MIT-style license that can be
  1233. * found in the LICENSE file at https://angular.io/license
  1234. */
  1235. /**
  1236. * A token representing the a reference to a static type.
  1237. *
  1238. * This token is unique for a filePath and name and can be used as a hash table key.
  1239. */
  1240. class StaticSymbol {
  1241. /**
  1242. * @param {?} filePath
  1243. * @param {?} name
  1244. * @param {?} members
  1245. */
  1246. constructor(filePath, name, members) {
  1247. this.filePath = filePath;
  1248. this.name = name;
  1249. this.members = members;
  1250. }
  1251. /**
  1252. * @return {?}
  1253. */
  1254. assertNoMembers() {
  1255. if (this.members.length) {
  1256. throw new Error(`Illegal state: symbol without members expected, but got ${JSON.stringify(this)}.`);
  1257. }
  1258. }
  1259. }
  1260. /**
  1261. * A cache of static symbol used by the StaticReflector to return the same symbol for the
  1262. * same symbol values.
  1263. */
  1264. class StaticSymbolCache {
  1265. constructor() {
  1266. this.cache = new Map();
  1267. }
  1268. /**
  1269. * @param {?} declarationFile
  1270. * @param {?} name
  1271. * @param {?=} members
  1272. * @return {?}
  1273. */
  1274. get(declarationFile, name, members) {
  1275. members = members || [];
  1276. const /** @type {?} */ memberSuffix = members.length ? `.${members.join('.')}` : '';
  1277. const /** @type {?} */ key = `"${declarationFile}".${name}${memberSuffix}`;
  1278. let /** @type {?} */ result = this.cache.get(key);
  1279. if (!result) {
  1280. result = new StaticSymbol(declarationFile, name, members);
  1281. this.cache.set(key, result);
  1282. }
  1283. return result;
  1284. }
  1285. }
  1286. /**
  1287. * @fileoverview added by tsickle
  1288. * @suppress {checkTypes} checked by tsc
  1289. */
  1290. /**
  1291. * @license
  1292. * Copyright Google Inc. All Rights Reserved.
  1293. *
  1294. * Use of this source code is governed by an MIT-style license that can be
  1295. * found in the LICENSE file at https://angular.io/license
  1296. */
  1297. // group 0: "[prop] or (event) or @trigger"
  1298. // group 1: "prop" from "[prop]"
  1299. // group 2: "event" from "(event)"
  1300. // group 3: "@trigger" from "@trigger"
  1301. const HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))|(\@[-\w]+)$/;
  1302. /**
  1303. * @param {?} name
  1304. * @return {?}
  1305. */
  1306. function _sanitizeIdentifier(name) {
  1307. return name.replace(/\W/g, '_');
  1308. }
  1309. let _anonymousTypeIndex = 0;
  1310. /**
  1311. * @param {?} compileIdentifier
  1312. * @return {?}
  1313. */
  1314. function identifierName(compileIdentifier) {
  1315. if (!compileIdentifier || !compileIdentifier.reference) {
  1316. return null;
  1317. }
  1318. const /** @type {?} */ ref = compileIdentifier.reference;
  1319. if (ref instanceof StaticSymbol) {
  1320. return ref.name;
  1321. }
  1322. if (ref['__anonymousType']) {
  1323. return ref['__anonymousType'];
  1324. }
  1325. let /** @type {?} */ identifier = stringify(ref);
  1326. if (identifier.indexOf('(') >= 0) {
  1327. // case: anonymous functions!
  1328. identifier = `anonymous_${_anonymousTypeIndex++}`;
  1329. ref['__anonymousType'] = identifier;
  1330. }
  1331. else {
  1332. identifier = _sanitizeIdentifier(identifier);
  1333. }
  1334. return identifier;
  1335. }
  1336. /**
  1337. * @param {?} compileIdentifier
  1338. * @return {?}
  1339. */
  1340. function identifierModuleUrl(compileIdentifier) {
  1341. const /** @type {?} */ ref = compileIdentifier.reference;
  1342. if (ref instanceof StaticSymbol) {
  1343. return ref.filePath;
  1344. }
  1345. // Runtime type
  1346. return `./${stringify(ref)}`;
  1347. }
  1348. /**
  1349. * @param {?} compType
  1350. * @param {?} embeddedTemplateIndex
  1351. * @return {?}
  1352. */
  1353. function viewClassName(compType, embeddedTemplateIndex) {
  1354. return `View_${identifierName({ reference: compType })}_${embeddedTemplateIndex}`;
  1355. }
  1356. /**
  1357. * @param {?} compType
  1358. * @return {?}
  1359. */
  1360. function rendererTypeName(compType) {
  1361. return `RenderType_${identifierName({ reference: compType })}`;
  1362. }
  1363. /**
  1364. * @param {?} compType
  1365. * @return {?}
  1366. */
  1367. function hostViewClassName(compType) {
  1368. return `HostView_${identifierName({ reference: compType })}`;
  1369. }
  1370. /**
  1371. * @param {?} compType
  1372. * @return {?}
  1373. */
  1374. function componentFactoryName(compType) {
  1375. return `${identifierName({ reference: compType })}NgFactory`;
  1376. }
  1377. /**
  1378. * @record
  1379. */
  1380. /**
  1381. * @record
  1382. */
  1383. /** @enum {number} */
  1384. const CompileSummaryKind = {
  1385. Pipe: 0,
  1386. Directive: 1,
  1387. NgModule: 2,
  1388. Injectable: 3,
  1389. };
  1390. CompileSummaryKind[CompileSummaryKind.Pipe] = "Pipe";
  1391. CompileSummaryKind[CompileSummaryKind.Directive] = "Directive";
  1392. CompileSummaryKind[CompileSummaryKind.NgModule] = "NgModule";
  1393. CompileSummaryKind[CompileSummaryKind.Injectable] = "Injectable";
  1394. /**
  1395. * A CompileSummary is the data needed to use a directive / pipe / module
  1396. * in other modules / components. However, this data is not enough to compile
  1397. * the directive / module itself.
  1398. * @record
  1399. */
  1400. /**
  1401. * @record
  1402. */
  1403. /**
  1404. * @record
  1405. */
  1406. /**
  1407. * @record
  1408. */
  1409. /**
  1410. * @param {?} token
  1411. * @return {?}
  1412. */
  1413. function tokenName(token) {
  1414. return token.value != null ? _sanitizeIdentifier(token.value) : identifierName(token.identifier);
  1415. }
  1416. /**
  1417. * @param {?} token
  1418. * @return {?}
  1419. */
  1420. function tokenReference(token) {
  1421. if (token.identifier != null) {
  1422. return token.identifier.reference;
  1423. }
  1424. else {
  1425. return token.value;
  1426. }
  1427. }
  1428. /**
  1429. * @record
  1430. */
  1431. /**
  1432. * Metadata regarding compilation of a type.
  1433. * @record
  1434. */
  1435. /**
  1436. * @record
  1437. */
  1438. /**
  1439. * Metadata about a stylesheet
  1440. */
  1441. class CompileStylesheetMetadata {
  1442. /**
  1443. * @param {?=} __0
  1444. */
  1445. constructor({ moduleUrl, styles, styleUrls } = {}) {
  1446. this.moduleUrl = moduleUrl || null;
  1447. this.styles = _normalizeArray(styles);
  1448. this.styleUrls = _normalizeArray(styleUrls);
  1449. }
  1450. }
  1451. /**
  1452. * Summary Metadata regarding compilation of a template.
  1453. * @record
  1454. */
  1455. /**
  1456. * Metadata regarding compilation of a template.
  1457. */
  1458. class CompileTemplateMetadata {
  1459. /**
  1460. * @param {?} __0
  1461. */
  1462. constructor({ encapsulation, template, templateUrl, htmlAst, styles, styleUrls, externalStylesheets, animations, ngContentSelectors, interpolation, isInline, preserveWhitespaces }) {
  1463. this.encapsulation = encapsulation;
  1464. this.template = template;
  1465. this.templateUrl = templateUrl;
  1466. this.htmlAst = htmlAst;
  1467. this.styles = _normalizeArray(styles);
  1468. this.styleUrls = _normalizeArray(styleUrls);
  1469. this.externalStylesheets = _normalizeArray(externalStylesheets);
  1470. this.animations = animations ? flatten(animations) : [];
  1471. this.ngContentSelectors = ngContentSelectors || [];
  1472. if (interpolation && interpolation.length != 2) {
  1473. throw new Error(`'interpolation' should have a start and an end symbol.`);
  1474. }
  1475. this.interpolation = interpolation;
  1476. this.isInline = isInline;
  1477. this.preserveWhitespaces = preserveWhitespaces;
  1478. }
  1479. /**
  1480. * @return {?}
  1481. */
  1482. toSummary() {
  1483. return {
  1484. ngContentSelectors: this.ngContentSelectors,
  1485. encapsulation: this.encapsulation,
  1486. };
  1487. }
  1488. }
  1489. /**
  1490. * @record
  1491. */
  1492. /**
  1493. * @record
  1494. */
  1495. /**
  1496. * Metadata regarding compilation of a directive.
  1497. */
  1498. class CompileDirectiveMetadata {
  1499. /**
  1500. * @param {?} __0
  1501. * @return {?}
  1502. */
  1503. static create({ isHost, type, isComponent, selector, exportAs, changeDetection, inputs, outputs, host, providers, viewProviders, queries, guards, viewQueries, entryComponents, template, componentViewType, rendererType, componentFactory }) {
  1504. const /** @type {?} */ hostListeners = {};
  1505. const /** @type {?} */ hostProperties = {};
  1506. const /** @type {?} */ hostAttributes = {};
  1507. if (host != null) {
  1508. Object.keys(host).forEach(key => {
  1509. const /** @type {?} */ value = host[key];
  1510. const /** @type {?} */ matches = key.match(HOST_REG_EXP);
  1511. if (matches === null) {
  1512. hostAttributes[key] = value;
  1513. }
  1514. else if (matches[1] != null) {
  1515. hostProperties[matches[1]] = value;
  1516. }
  1517. else if (matches[2] != null) {
  1518. hostListeners[matches[2]] = value;
  1519. }
  1520. });
  1521. }
  1522. const /** @type {?} */ inputsMap = {};
  1523. if (inputs != null) {
  1524. inputs.forEach((bindConfig) => {
  1525. // canonical syntax: `dirProp: elProp`
  1526. // if there is no `:`, use dirProp = elProp
  1527. const /** @type {?} */ parts = splitAtColon(bindConfig, [bindConfig, bindConfig]);
  1528. inputsMap[parts[0]] = parts[1];
  1529. });
  1530. }
  1531. const /** @type {?} */ outputsMap = {};
  1532. if (outputs != null) {
  1533. outputs.forEach((bindConfig) => {
  1534. // canonical syntax: `dirProp: elProp`
  1535. // if there is no `:`, use dirProp = elProp
  1536. const /** @type {?} */ parts = splitAtColon(bindConfig, [bindConfig, bindConfig]);
  1537. outputsMap[parts[0]] = parts[1];
  1538. });
  1539. }
  1540. return new CompileDirectiveMetadata({
  1541. isHost,
  1542. type,
  1543. isComponent: !!isComponent, selector, exportAs, changeDetection,
  1544. inputs: inputsMap,
  1545. outputs: outputsMap,
  1546. hostListeners,
  1547. hostProperties,
  1548. hostAttributes,
  1549. providers,
  1550. viewProviders,
  1551. queries,
  1552. guards,
  1553. viewQueries,
  1554. entryComponents,
  1555. template,
  1556. componentViewType,
  1557. rendererType,
  1558. componentFactory,
  1559. });
  1560. }
  1561. /**
  1562. * @param {?} __0
  1563. */
  1564. constructor({ isHost, type, isComponent, selector, exportAs, changeDetection, inputs, outputs, hostListeners, hostProperties, hostAttributes, providers, viewProviders, queries, guards, viewQueries, entryComponents, template, componentViewType, rendererType, componentFactory }) {
  1565. this.isHost = !!isHost;
  1566. this.type = type;
  1567. this.isComponent = isComponent;
  1568. this.selector = selector;
  1569. this.exportAs = exportAs;
  1570. this.changeDetection = changeDetection;
  1571. this.inputs = inputs;
  1572. this.outputs = outputs;
  1573. this.hostListeners = hostListeners;
  1574. this.hostProperties = hostProperties;
  1575. this.hostAttributes = hostAttributes;
  1576. this.providers = _normalizeArray(providers);
  1577. this.viewProviders = _normalizeArray(viewProviders);
  1578. this.queries = _normalizeArray(queries);
  1579. this.guards = guards;
  1580. this.viewQueries = _normalizeArray(viewQueries);
  1581. this.entryComponents = _normalizeArray(entryComponents);
  1582. this.template = template;
  1583. this.componentViewType = componentViewType;
  1584. this.rendererType = rendererType;
  1585. this.componentFactory = componentFactory;
  1586. }
  1587. /**
  1588. * @return {?}
  1589. */
  1590. toSummary() {
  1591. return {
  1592. summaryKind: CompileSummaryKind.Directive,
  1593. type: this.type,
  1594. isComponent: this.isComponent,
  1595. selector: this.selector,
  1596. exportAs: this.exportAs,
  1597. inputs: this.inputs,
  1598. outputs: this.outputs,
  1599. hostListeners: this.hostListeners,
  1600. hostProperties: this.hostProperties,
  1601. hostAttributes: this.hostAttributes,
  1602. providers: this.providers,
  1603. viewProviders: this.viewProviders,
  1604. queries: this.queries,
  1605. guards: this.guards,
  1606. viewQueries: this.viewQueries,
  1607. entryComponents: this.entryComponents,
  1608. changeDetection: this.changeDetection,
  1609. template: this.template && this.template.toSummary(),
  1610. componentViewType: this.componentViewType,
  1611. rendererType: this.rendererType,
  1612. componentFactory: this.componentFactory
  1613. };
  1614. }
  1615. }
  1616. /**
  1617. * @record
  1618. */
  1619. class CompilePipeMetadata {
  1620. /**
  1621. * @param {?} __0
  1622. */
  1623. constructor({ type, name, pure }) {
  1624. this.type = type;
  1625. this.name = name;
  1626. this.pure = !!pure;
  1627. }
  1628. /**
  1629. * @return {?}
  1630. */
  1631. toSummary() {
  1632. return {
  1633. summaryKind: CompileSummaryKind.Pipe,
  1634. type: this.type,
  1635. name: this.name,
  1636. pure: this.pure
  1637. };
  1638. }
  1639. }
  1640. /**
  1641. * @record
  1642. */
  1643. /**
  1644. * Metadata regarding compilation of a module.
  1645. */
  1646. class CompileNgModuleMetadata {
  1647. /**
  1648. * @param {?} __0
  1649. */
  1650. constructor({ type, providers, declaredDirectives, exportedDirectives, declaredPipes, exportedPipes, entryComponents, bootstrapComponents, importedModules, exportedModules, schemas, transitiveModule, id }) {
  1651. this.type = type || null;
  1652. this.declaredDirectives = _normalizeArray(declaredDirectives);
  1653. this.exportedDirectives = _normalizeArray(exportedDirectives);
  1654. this.declaredPipes = _normalizeArray(declaredPipes);
  1655. this.exportedPipes = _normalizeArray(exportedPipes);
  1656. this.providers = _normalizeArray(providers);
  1657. this.entryComponents = _normalizeArray(entryComponents);
  1658. this.bootstrapComponents = _normalizeArray(bootstrapComponents);
  1659. this.importedModules = _normalizeArray(importedModules);
  1660. this.exportedModules = _normalizeArray(exportedModules);
  1661. this.schemas = _normalizeArray(schemas);
  1662. this.id = id || null;
  1663. this.transitiveModule = transitiveModule || null;
  1664. }
  1665. /**
  1666. * @return {?}
  1667. */
  1668. toSummary() {
  1669. const /** @type {?} */ module = /** @type {?} */ ((this.transitiveModule));
  1670. return {
  1671. summaryKind: CompileSummaryKind.NgModule,
  1672. type: this.type,
  1673. entryComponents: module.entryComponents,
  1674. providers: module.providers,
  1675. modules: module.modules,
  1676. exportedDirectives: module.exportedDirectives,
  1677. exportedPipes: module.exportedPipes
  1678. };
  1679. }
  1680. }
  1681. class TransitiveCompileNgModuleMetadata {
  1682. constructor() {
  1683. this.directivesSet = new Set();
  1684. this.directives = [];
  1685. this.exportedDirectivesSet = new Set();
  1686. this.exportedDirectives = [];
  1687. this.pipesSet = new Set();
  1688. this.pipes = [];
  1689. this.exportedPipesSet = new Set();
  1690. this.exportedPipes = [];
  1691. this.modulesSet = new Set();
  1692. this.modules = [];
  1693. this.entryComponentsSet = new Set();
  1694. this.entryComponents = [];
  1695. this.providers = [];
  1696. }
  1697. /**
  1698. * @param {?} provider
  1699. * @param {?} module
  1700. * @return {?}
  1701. */
  1702. addProvider(provider, module) {
  1703. this.providers.push({ provider: provider, module: module });
  1704. }
  1705. /**
  1706. * @param {?} id
  1707. * @return {?}
  1708. */
  1709. addDirective(id) {
  1710. if (!this.directivesSet.has(id.reference)) {
  1711. this.directivesSet.add(id.reference);
  1712. this.directives.push(id);
  1713. }
  1714. }
  1715. /**
  1716. * @param {?} id
  1717. * @return {?}
  1718. */
  1719. addExportedDirective(id) {
  1720. if (!this.exportedDirectivesSet.has(id.reference)) {
  1721. this.exportedDirectivesSet.add(id.reference);
  1722. this.exportedDirectives.push(id);
  1723. }
  1724. }
  1725. /**
  1726. * @param {?} id
  1727. * @return {?}
  1728. */
  1729. addPipe(id) {
  1730. if (!this.pipesSet.has(id.reference)) {
  1731. this.pipesSet.add(id.reference);
  1732. this.pipes.push(id);
  1733. }
  1734. }
  1735. /**
  1736. * @param {?} id
  1737. * @return {?}
  1738. */
  1739. addExportedPipe(id) {
  1740. if (!this.exportedPipesSet.has(id.reference)) {
  1741. this.exportedPipesSet.add(id.reference);
  1742. this.exportedPipes.push(id);
  1743. }
  1744. }
  1745. /**
  1746. * @param {?} id
  1747. * @return {?}
  1748. */
  1749. addModule(id) {
  1750. if (!this.modulesSet.has(id.reference)) {
  1751. this.modulesSet.add(id.reference);
  1752. this.modules.push(id);
  1753. }
  1754. }
  1755. /**
  1756. * @param {?} ec
  1757. * @return {?}
  1758. */
  1759. addEntryComponent(ec) {
  1760. if (!this.entryComponentsSet.has(ec.componentType)) {
  1761. this.entryComponentsSet.add(ec.componentType);
  1762. this.entryComponents.push(ec);
  1763. }
  1764. }
  1765. }
  1766. /**
  1767. * @param {?} obj
  1768. * @return {?}
  1769. */
  1770. function _normalizeArray(obj) {
  1771. return obj || [];
  1772. }
  1773. class ProviderMeta {
  1774. /**
  1775. * @param {?} token
  1776. * @param {?} __1
  1777. */
  1778. constructor(token, { useClass, useValue, useExisting, useFactory, deps, multi }) {
  1779. this.token = token;
  1780. this.useClass = useClass || null;
  1781. this.useValue = useValue;
  1782. this.useExisting = useExisting;
  1783. this.useFactory = useFactory || null;
  1784. this.dependencies = deps || null;
  1785. this.multi = !!multi;
  1786. }
  1787. }
  1788. /**
  1789. * @template T
  1790. * @param {?} list
  1791. * @return {?}
  1792. */
  1793. function flatten(list) {
  1794. return list.reduce((flat, item) => {
  1795. const /** @type {?} */ flatItem = Array.isArray(item) ? flatten(item) : item;
  1796. return (/** @type {?} */ (flat)).concat(flatItem);
  1797. }, []);
  1798. }
  1799. /**
  1800. * @param {?} url
  1801. * @return {?}
  1802. */
  1803. function jitSourceUrl(url) {
  1804. // Note: We need 3 "/" so that ng shows up as a separate domain
  1805. // in the chrome dev tools.
  1806. return url.replace(/(\w+:\/\/[\w:-]+)?(\/+)?/, 'ng:///');
  1807. }
  1808. /**
  1809. * @param {?} ngModuleType
  1810. * @param {?} compMeta
  1811. * @param {?} templateMeta
  1812. * @return {?}
  1813. */
  1814. function templateSourceUrl(ngModuleType, compMeta, templateMeta) {
  1815. let /** @type {?} */ url;
  1816. if (templateMeta.isInline) {
  1817. if (compMeta.type.reference instanceof StaticSymbol) {
  1818. // Note: a .ts file might contain multiple components with inline templates,
  1819. // so we need to give them unique urls, as these will be used for sourcemaps.
  1820. url = `${compMeta.type.reference.filePath}.${compMeta.type.reference.name}.html`;
  1821. }
  1822. else {
  1823. url = `${identifierName(ngModuleType)}/${identifierName(compMeta.type)}.html`;
  1824. }
  1825. }
  1826. else {
  1827. url = /** @type {?} */ ((templateMeta.templateUrl));
  1828. }
  1829. return compMeta.type.reference instanceof StaticSymbol ? url : jitSourceUrl(url);
  1830. }
  1831. /**
  1832. * @param {?} meta
  1833. * @param {?} id
  1834. * @return {?}
  1835. */
  1836. function sharedStylesheetJitUrl(meta, id) {
  1837. const /** @type {?} */ pathParts = /** @type {?} */ ((meta.moduleUrl)).split(/\/\\/g);
  1838. const /** @type {?} */ baseName = pathParts[pathParts.length - 1];
  1839. return jitSourceUrl(`css/${id}${baseName}.ngstyle.js`);
  1840. }
  1841. /**
  1842. * @param {?} moduleMeta
  1843. * @return {?}
  1844. */
  1845. function ngModuleJitUrl(moduleMeta) {
  1846. return jitSourceUrl(`${identifierName(moduleMeta.type)}/module.ngfactory.js`);
  1847. }
  1848. /**
  1849. * @param {?} ngModuleType
  1850. * @param {?} compMeta
  1851. * @return {?}
  1852. */
  1853. function templateJitUrl(ngModuleType, compMeta) {
  1854. return jitSourceUrl(`${identifierName(ngModuleType)}/${identifierName(compMeta.type)}.ngfactory.js`);
  1855. }
  1856. /**
  1857. * @fileoverview added by tsickle
  1858. * @suppress {checkTypes} checked by tsc
  1859. */
  1860. /**
  1861. * @license
  1862. * Copyright Google Inc. All Rights Reserved.
  1863. *
  1864. * Use of this source code is governed by an MIT-style license that can be
  1865. * found in the LICENSE file at https://angular.io/license
  1866. */
  1867. /**
  1868. * A path is an ordered set of elements. Typically a path is to a
  1869. * particular offset in a source file. The head of the list is the top
  1870. * most node. The tail is the node that contains the offset directly.
  1871. *
  1872. * For example, the expresion `a + b + c` might have an ast that looks
  1873. * like:
  1874. * +
  1875. * / \
  1876. * a +
  1877. * / \
  1878. * b c
  1879. *
  1880. * The path to the node at offset 9 would be `['+' at 1-10, '+' at 7-10,
  1881. * 'c' at 9-10]` and the path the node at offset 1 would be
  1882. * `['+' at 1-10, 'a' at 1-2]`.
  1883. * @template T
  1884. */
  1885. class AstPath {
  1886. /**
  1887. * @param {?} path
  1888. * @param {?=} position
  1889. */
  1890. constructor(path, position = -1) {
  1891. this.path = path;
  1892. this.position = position;
  1893. }
  1894. /**
  1895. * @return {?}
  1896. */
  1897. get empty() { return !this.path || !this.path.length; }
  1898. /**
  1899. * @return {?}
  1900. */
  1901. get head() { return this.path[0]; }
  1902. /**
  1903. * @return {?}
  1904. */
  1905. get tail() { return this.path[this.path.length - 1]; }
  1906. /**
  1907. * @param {?} node
  1908. * @return {?}
  1909. */
  1910. parentOf(node) {
  1911. return node && this.path[this.path.indexOf(node) - 1];
  1912. }
  1913. /**
  1914. * @param {?} node
  1915. * @return {?}
  1916. */
  1917. childOf(node) { return this.path[this.path.indexOf(node) + 1]; }
  1918. /**
  1919. * @template N
  1920. * @param {?} ctor
  1921. * @return {?}
  1922. */
  1923. first(ctor) {
  1924. for (let /** @type {?} */ i = this.path.length - 1; i >= 0; i--) {
  1925. let /** @type {?} */ item = this.path[i];
  1926. if (item instanceof ctor)
  1927. return /** @type {?} */ (item);
  1928. }
  1929. }
  1930. /**
  1931. * @param {?} node
  1932. * @return {?}
  1933. */
  1934. push(node) { this.path.push(node); }
  1935. /**
  1936. * @return {?}
  1937. */
  1938. pop() { return /** @type {?} */ ((this.path.pop())); }
  1939. }
  1940. /**
  1941. * @fileoverview added by tsickle
  1942. * @suppress {checkTypes} checked by tsc
  1943. */
  1944. /**
  1945. * @license
  1946. * Copyright Google Inc. All Rights Reserved.
  1947. *
  1948. * Use of this source code is governed by an MIT-style license that can be
  1949. * found in the LICENSE file at https://angular.io/license
  1950. */
  1951. /**
  1952. * @record
  1953. */
  1954. class Text {
  1955. /**
  1956. * @param {?} value
  1957. * @param {?} sourceSpan
  1958. */
  1959. constructor(value, sourceSpan) {
  1960. this.value = value;
  1961. this.sourceSpan = sourceSpan;
  1962. }
  1963. /**
  1964. * @param {?} visitor
  1965. * @param {?} context
  1966. * @return {?}
  1967. */
  1968. visit(visitor, context) { return visitor.visitText(this, context); }
  1969. }
  1970. class Expansion {
  1971. /**
  1972. * @param {?} switchValue
  1973. * @param {?} type
  1974. * @param {?} cases
  1975. * @param {?} sourceSpan
  1976. * @param {?} switchValueSourceSpan
  1977. */
  1978. constructor(switchValue, type, cases, sourceSpan, switchValueSourceSpan) {
  1979. this.switchValue = switchValue;
  1980. this.type = type;
  1981. this.cases = cases;
  1982. this.sourceSpan = sourceSpan;
  1983. this.switchValueSourceSpan = switchValueSourceSpan;
  1984. }
  1985. /**
  1986. * @param {?} visitor
  1987. * @param {?} context
  1988. * @return {?}
  1989. */
  1990. visit(visitor, context) { return visitor.visitExpansion(this, context); }
  1991. }
  1992. class ExpansionCase {
  1993. /**
  1994. * @param {?} value
  1995. * @param {?} expression
  1996. * @param {?} sourceSpan
  1997. * @param {?} valueSourceSpan
  1998. * @param {?} expSourceSpan
  1999. */
  2000. constructor(value, expression, sourceSpan, valueSourceSpan, expSourceSpan) {
  2001. this.value = value;
  2002. this.expression = expression;
  2003. this.sourceSpan = sourceSpan;
  2004. this.valueSourceSpan = valueSourceSpan;
  2005. this.expSourceSpan = expSourceSpan;
  2006. }
  2007. /**
  2008. * @param {?} visitor
  2009. * @param {?} context
  2010. * @return {?}
  2011. */
  2012. visit(visitor, context) { return visitor.visitExpansionCase(this, context); }
  2013. }
  2014. class Attribute$1 {
  2015. /**
  2016. * @param {?} name
  2017. * @param {?} value
  2018. * @param {?} sourceSpan
  2019. * @param {?=} valueSpan
  2020. */
  2021. constructor(name, value, sourceSpan, valueSpan) {
  2022. this.name = name;
  2023. this.value = value;
  2024. this.sourceSpan = sourceSpan;
  2025. this.valueSpan = valueSpan;
  2026. }
  2027. /**
  2028. * @param {?} visitor
  2029. * @param {?} context
  2030. * @return {?}
  2031. */
  2032. visit(visitor, context) { return visitor.visitAttribute(this, context); }
  2033. }
  2034. class Element {
  2035. /**
  2036. * @param {?} name
  2037. * @param {?} attrs
  2038. * @param {?} children
  2039. * @param {?} sourceSpan
  2040. * @param {?=} startSourceSpan
  2041. * @param {?=} endSourceSpan
  2042. */
  2043. constructor(name, attrs, children, sourceSpan, startSourceSpan = null, endSourceSpan = null) {
  2044. this.name = name;
  2045. this.attrs = attrs;
  2046. this.children = children;
  2047. this.sourceSpan = sourceSpan;
  2048. this.startSourceSpan = startSourceSpan;
  2049. this.endSourceSpan = endSourceSpan;
  2050. }
  2051. /**
  2052. * @param {?} visitor
  2053. * @param {?} context
  2054. * @return {?}
  2055. */
  2056. visit(visitor, context) { return visitor.visitElement(this, context); }
  2057. }
  2058. class Comment {
  2059. /**
  2060. * @param {?} value
  2061. * @param {?} sourceSpan
  2062. */
  2063. constructor(value, sourceSpan) {
  2064. this.value = value;
  2065. this.sourceSpan = sourceSpan;
  2066. }
  2067. /**
  2068. * @param {?} visitor
  2069. * @param {?} context
  2070. * @return {?}
  2071. */
  2072. visit(visitor, context) { return visitor.visitComment(this, context); }
  2073. }
  2074. /**
  2075. * @record
  2076. */
  2077. /**
  2078. * @param {?} visitor
  2079. * @param {?} nodes
  2080. * @param {?=} context
  2081. * @return {?}
  2082. */
  2083. function visitAll(visitor, nodes, context = null) {
  2084. const /** @type {?} */ result = [];
  2085. const /** @type {?} */ visit = visitor.visit ?
  2086. (ast) => /** @type {?} */ ((visitor.visit))(ast, context) || ast.visit(visitor, context) :
  2087. (ast) => ast.visit(visitor, context);
  2088. nodes.forEach(ast => {
  2089. const /** @type {?} */ astResult = visit(ast);
  2090. if (astResult) {
  2091. result.push(astResult);
  2092. }
  2093. });
  2094. return result;
  2095. }
  2096. class RecursiveVisitor {
  2097. constructor() { }
  2098. /**
  2099. * @param {?} ast
  2100. * @param {?} context
  2101. * @return {?}
  2102. */
  2103. visitElement(ast, context) {
  2104. this.visitChildren(context, visit => {
  2105. visit(ast.attrs);
  2106. visit(ast.children);
  2107. });
  2108. }
  2109. /**
  2110. * @param {?} ast
  2111. * @param {?} context
  2112. * @return {?}
  2113. */
  2114. visitAttribute(ast, context) { }
  2115. /**
  2116. * @param {?} ast
  2117. * @param {?} context
  2118. * @return {?}
  2119. */
  2120. visitText(ast, context) { }
  2121. /**
  2122. * @param {?} ast
  2123. * @param {?} context
  2124. * @return {?}
  2125. */
  2126. visitComment(ast, context) { }
  2127. /**
  2128. * @param {?} ast
  2129. * @param {?} context
  2130. * @return {?}
  2131. */
  2132. visitExpansion(ast, context) {
  2133. return this.visitChildren(context, visit => { visit(ast.cases); });
  2134. }
  2135. /**
  2136. * @param {?} ast
  2137. * @param {?} context
  2138. * @return {?}
  2139. */
  2140. visitExpansionCase(ast, context) { }
  2141. /**
  2142. * @template T
  2143. * @param {?} context
  2144. * @param {?} cb
  2145. * @return {?}
  2146. */
  2147. visitChildren(context, cb) {
  2148. let /** @type {?} */ results = [];
  2149. let /** @type {?} */ t = this;
  2150. /**
  2151. * @template T
  2152. * @param {?} children
  2153. * @return {?}
  2154. */
  2155. function visit(children) {
  2156. if (children)
  2157. results.push(visitAll(t, children, context));
  2158. }
  2159. cb(visit);
  2160. return [].concat.apply([], results);
  2161. }
  2162. }
  2163. /**
  2164. * @param {?} ast
  2165. * @return {?}
  2166. */
  2167. function spanOf(ast) {
  2168. const /** @type {?} */ start = ast.sourceSpan.start.offset;
  2169. let /** @type {?} */ end = ast.sourceSpan.end.offset;
  2170. if (ast instanceof Element) {
  2171. if (ast.endSourceSpan) {
  2172. end = ast.endSourceSpan.end.offset;
  2173. }
  2174. else if (ast.children && ast.children.length) {
  2175. end = spanOf(ast.children[ast.children.length - 1]).end;
  2176. }
  2177. }
  2178. return { start, end };
  2179. }
  2180. /**
  2181. * @param {?} nodes
  2182. * @param {?} position
  2183. * @return {?}
  2184. */
  2185. function findNode(nodes, position) {
  2186. const /** @type {?} */ path = [];
  2187. const /** @type {?} */ visitor = new class extends RecursiveVisitor {
  2188. /**
  2189. * @param {?} ast
  2190. * @param {?} context
  2191. * @return {?}
  2192. */
  2193. visit(ast, context) {
  2194. const /** @type {?} */ span = spanOf(ast);
  2195. if (span.start <= position && position < span.end) {
  2196. path.push(ast);
  2197. }
  2198. else {
  2199. // Returning a value here will result in the children being skipped.
  2200. return true;
  2201. }
  2202. }
  2203. };
  2204. visitAll(visitor, nodes);
  2205. return new AstPath(path, position);
  2206. }
  2207. /**
  2208. * @fileoverview added by tsickle
  2209. * @suppress {checkTypes} checked by tsc
  2210. */
  2211. /**
  2212. * @license
  2213. * Copyright Google Inc. All Rights Reserved.
  2214. *
  2215. * Use of this source code is governed by an MIT-style license that can be
  2216. * found in the LICENSE file at https://angular.io/license
  2217. */
  2218. /**
  2219. * @param {?} identifier
  2220. * @param {?} value
  2221. * @return {?}
  2222. */
  2223. function assertArrayOfStrings(identifier, value) {
  2224. if (value == null) {
  2225. return;
  2226. }
  2227. if (!Array.isArray(value)) {
  2228. throw new Error(`Expected '${identifier}' to be an array of strings.`);
  2229. }
  2230. for (let /** @type {?} */ i = 0; i < value.length; i += 1) {
  2231. if (typeof value[i] !== 'string') {
  2232. throw new Error(`Expected '${identifier}' to be an array of strings.`);
  2233. }
  2234. }
  2235. }
  2236. const INTERPOLATION_BLACKLIST_REGEXPS = [
  2237. /^\s*$/,
  2238. /[<>]/,
  2239. /^[{}]$/,
  2240. /&(#|[a-z])/i,
  2241. /^\/\//,
  2242. ];
  2243. /**
  2244. * @param {?} identifier
  2245. * @param {?} value
  2246. * @return {?}
  2247. */
  2248. function assertInterpolationSymbols(identifier, value) {
  2249. if (value != null && !(Array.isArray(value) && value.length == 2)) {
  2250. throw new Error(`Expected '${identifier}' to be an array, [start, end].`);
  2251. }
  2252. else if (value != null) {
  2253. const /** @type {?} */ start = /** @type {?} */ (value[0]);
  2254. const /** @type {?} */ end = /** @type {?} */ (value[1]);
  2255. // black list checking
  2256. INTERPOLATION_BLACKLIST_REGEXPS.forEach(regexp => {
  2257. if (regexp.test(start) || regexp.test(end)) {
  2258. throw new Error(`['${start}', '${end}'] contains unusable interpolation symbol.`);
  2259. }
  2260. });
  2261. }
  2262. }
  2263. /**
  2264. * @fileoverview added by tsickle
  2265. * @suppress {checkTypes} checked by tsc
  2266. */
  2267. /**
  2268. * @license
  2269. * Copyright Google Inc. All Rights Reserved.
  2270. *
  2271. * Use of this source code is governed by an MIT-style license that can be
  2272. * found in the LICENSE file at https://angular.io/license
  2273. */
  2274. class InterpolationConfig {
  2275. /**
  2276. * @param {?} start
  2277. * @param {?} end
  2278. */
  2279. constructor(start, end) {
  2280. this.start = start;
  2281. this.end = end;
  2282. }
  2283. /**
  2284. * @param {?} markers
  2285. * @return {?}
  2286. */
  2287. static fromArray(markers) {
  2288. if (!markers) {
  2289. return DEFAULT_INTERPOLATION_CONFIG;
  2290. }
  2291. assertInterpolationSymbols('interpolation', markers);
  2292. return new InterpolationConfig(markers[0], markers[1]);
  2293. }
  2294. }
  2295. const DEFAULT_INTERPOLATION_CONFIG = new InterpolationConfig('{{', '}}');
  2296. /**
  2297. * @fileoverview added by tsickle
  2298. * @suppress {checkTypes} checked by tsc
  2299. */
  2300. /**
  2301. * @license
  2302. * Copyright Google Inc. All Rights Reserved.
  2303. *
  2304. * Use of this source code is governed by an MIT-style license that can be
  2305. * found in the LICENSE file at https://angular.io/license
  2306. */
  2307. class StyleWithImports {
  2308. /**
  2309. * @param {?} style
  2310. * @param {?} styleUrls
  2311. */
  2312. constructor(style, styleUrls) {
  2313. this.style = style;
  2314. this.styleUrls = styleUrls;
  2315. }
  2316. }
  2317. /**
  2318. * @param {?} url
  2319. * @return {?}
  2320. */
  2321. function isStyleUrlResolvable(url) {
  2322. if (url == null || url.length === 0 || url[0] == '/')
  2323. return false;
  2324. const /** @type {?} */ schemeMatch = url.match(URL_WITH_SCHEMA_REGEXP);
  2325. return schemeMatch === null || schemeMatch[1] == 'package' || schemeMatch[1] == 'asset';
  2326. }
  2327. /**
  2328. * Rewrites stylesheets by resolving and removing the \@import urls that
  2329. * are either relative or don't have a `package:` scheme
  2330. * @param {?} resolver
  2331. * @param {?} baseUrl
  2332. * @param {?} cssText
  2333. * @return {?}
  2334. */
  2335. function extractStyleUrls(resolver, baseUrl, cssText) {
  2336. const /** @type {?} */ foundUrls = [];
  2337. const /** @type {?} */ modifiedCssText = cssText.replace(CSS_STRIPPABLE_COMMENT_REGEXP, '')
  2338. .replace(CSS_IMPORT_REGEXP, (...m) => {
  2339. const /** @type {?} */ url = m[1] || m[2];
  2340. if (!isStyleUrlResolvable(url)) {
  2341. // Do not attempt to resolve non-package absolute URLs with URI
  2342. // scheme
  2343. return m[0];
  2344. }
  2345. foundUrls.push(resolver.resolve(baseUrl, url));
  2346. return '';
  2347. });
  2348. return new StyleWithImports(modifiedCssText, foundUrls);
  2349. }
  2350. const CSS_IMPORT_REGEXP = /@import\s+(?:url\()?\s*(?:(?:['"]([^'"]*))|([^;\)\s]*))[^;]*;?/g;
  2351. const CSS_STRIPPABLE_COMMENT_REGEXP = /\/\*(?!#\s*(?:sourceURL|sourceMappingURL)=)[\s\S]+?\*\//g;
  2352. const URL_WITH_SCHEMA_REGEXP = /^([^:/?#]+):/;
  2353. /**
  2354. * @fileoverview added by tsickle
  2355. * @suppress {checkTypes} checked by tsc
  2356. */
  2357. /**
  2358. * @license
  2359. * Copyright Google Inc. All Rights Reserved.
  2360. *
  2361. * Use of this source code is governed by an MIT-style license that can be
  2362. * found in the LICENSE file at https://angular.io/license
  2363. */
  2364. /** @enum {number} */
  2365. const TagContentType = {
  2366. RAW_TEXT: 0,
  2367. ESCAPABLE_RAW_TEXT: 1,
  2368. PARSABLE_DATA: 2,
  2369. };
  2370. TagContentType[TagContentType.RAW_TEXT] = "RAW_TEXT";
  2371. TagContentType[TagContentType.ESCAPABLE_RAW_TEXT] = "ESCAPABLE_RAW_TEXT";
  2372. TagContentType[TagContentType.PARSABLE_DATA] = "PARSABLE_DATA";
  2373. /**
  2374. * @record
  2375. */
  2376. /**
  2377. * @param {?} elementName
  2378. * @return {?}
  2379. */
  2380. function splitNsName(elementName) {
  2381. if (elementName[0] != ':') {
  2382. return [null, elementName];
  2383. }
  2384. const /** @type {?} */ colonIndex = elementName.indexOf(':', 1);
  2385. if (colonIndex == -1) {
  2386. throw new Error(`Unsupported format "${elementName}" expecting ":namespace:name"`);
  2387. }
  2388. return [elementName.slice(1, colonIndex), elementName.slice(colonIndex + 1)];
  2389. }
  2390. /**
  2391. * @param {?} tagName
  2392. * @return {?}
  2393. */
  2394. function isNgContainer(tagName) {
  2395. return splitNsName(tagName)[1] === 'ng-container';
  2396. }
  2397. /**
  2398. * @param {?} tagName
  2399. * @return {?}
  2400. */
  2401. function isNgContent(tagName) {
  2402. return splitNsName(tagName)[1] === 'ng-content';
  2403. }
  2404. /**
  2405. * @param {?} tagName
  2406. * @return {?}
  2407. */
  2408. function isNgTemplate(tagName) {
  2409. return splitNsName(tagName)[1] === 'ng-template';
  2410. }
  2411. /**
  2412. * @param {?} fullName
  2413. * @return {?}
  2414. */
  2415. function getNsPrefix(fullName) {
  2416. return fullName === null ? null : splitNsName(fullName)[0];
  2417. }
  2418. /**
  2419. * @param {?} prefix
  2420. * @param {?} localName
  2421. * @return {?}
  2422. */
  2423. function mergeNsAndName(prefix, localName) {
  2424. return prefix ? `:${prefix}:${localName}` : localName;
  2425. }
  2426. // see http://www.w3.org/TR/html51/syntax.html#named-character-references
  2427. // see https://html.spec.whatwg.org/multipage/entities.json
  2428. // This list is not exhaustive to keep the compiler footprint low.
  2429. // The `&#123;` / `&#x1ab;` syntax should be used when the named character reference does not
  2430. // exist.
  2431. const NAMED_ENTITIES = {
  2432. 'Aacute': '\u00C1',
  2433. 'aacute': '\u00E1',
  2434. 'Acirc': '\u00C2',
  2435. 'acirc': '\u00E2',
  2436. 'acute': '\u00B4',
  2437. 'AElig': '\u00C6',
  2438. 'aelig': '\u00E6',
  2439. 'Agrave': '\u00C0',
  2440. 'agrave': '\u00E0',
  2441. 'alefsym': '\u2135',
  2442. 'Alpha': '\u0391',
  2443. 'alpha': '\u03B1',
  2444. 'amp': '&',
  2445. 'and': '\u2227',
  2446. 'ang': '\u2220',
  2447. 'apos': '\u0027',
  2448. 'Aring': '\u00C5',
  2449. 'aring': '\u00E5',
  2450. 'asymp': '\u2248',
  2451. 'Atilde': '\u00C3',
  2452. 'atilde': '\u00E3',
  2453. 'Auml': '\u00C4',
  2454. 'auml': '\u00E4',
  2455. 'bdquo': '\u201E',
  2456. 'Beta': '\u0392',
  2457. 'beta': '\u03B2',
  2458. 'brvbar': '\u00A6',
  2459. 'bull': '\u2022',
  2460. 'cap': '\u2229',
  2461. 'Ccedil': '\u00C7',
  2462. 'ccedil': '\u00E7',
  2463. 'cedil': '\u00B8',
  2464. 'cent': '\u00A2',
  2465. 'Chi': '\u03A7',
  2466. 'chi': '\u03C7',
  2467. 'circ': '\u02C6',
  2468. 'clubs': '\u2663',
  2469. 'cong': '\u2245',
  2470. 'copy': '\u00A9',
  2471. 'crarr': '\u21B5',
  2472. 'cup': '\u222A',
  2473. 'curren': '\u00A4',
  2474. 'dagger': '\u2020',
  2475. 'Dagger': '\u2021',
  2476. 'darr': '\u2193',
  2477. 'dArr': '\u21D3',
  2478. 'deg': '\u00B0',
  2479. 'Delta': '\u0394',
  2480. 'delta': '\u03B4',
  2481. 'diams': '\u2666',
  2482. 'divide': '\u00F7',
  2483. 'Eacute': '\u00C9',
  2484. 'eacute': '\u00E9',
  2485. 'Ecirc': '\u00CA',
  2486. 'ecirc': '\u00EA',
  2487. 'Egrave': '\u00C8',
  2488. 'egrave': '\u00E8',
  2489. 'empty': '\u2205',
  2490. 'emsp': '\u2003',
  2491. 'ensp': '\u2002',
  2492. 'Epsilon': '\u0395',
  2493. 'epsilon': '\u03B5',
  2494. 'equiv': '\u2261',
  2495. 'Eta': '\u0397',
  2496. 'eta': '\u03B7',
  2497. 'ETH': '\u00D0',
  2498. 'eth': '\u00F0',
  2499. 'Euml': '\u00CB',
  2500. 'euml': '\u00EB',
  2501. 'euro': '\u20AC',
  2502. 'exist': '\u2203',
  2503. 'fnof': '\u0192',
  2504. 'forall': '\u2200',
  2505. 'frac12': '\u00BD',
  2506. 'frac14': '\u00BC',
  2507. 'frac34': '\u00BE',
  2508. 'frasl': '\u2044',
  2509. 'Gamma': '\u0393',
  2510. 'gamma': '\u03B3',
  2511. 'ge': '\u2265',
  2512. 'gt': '>',
  2513. 'harr': '\u2194',
  2514. 'hArr': '\u21D4',
  2515. 'hearts': '\u2665',
  2516. 'hellip': '\u2026',
  2517. 'Iacute': '\u00CD',
  2518. 'iacute': '\u00ED',
  2519. 'Icirc': '\u00CE',
  2520. 'icirc': '\u00EE',
  2521. 'iexcl': '\u00A1',
  2522. 'Igrave': '\u00CC',
  2523. 'igrave': '\u00EC',
  2524. 'image': '\u2111',
  2525. 'infin': '\u221E',
  2526. 'int': '\u222B',
  2527. 'Iota': '\u0399',
  2528. 'iota': '\u03B9',
  2529. 'iquest': '\u00BF',
  2530. 'isin': '\u2208',
  2531. 'Iuml': '\u00CF',
  2532. 'iuml': '\u00EF',
  2533. 'Kappa': '\u039A',
  2534. 'kappa': '\u03BA',
  2535. 'Lambda': '\u039B',
  2536. 'lambda': '\u03BB',
  2537. 'lang': '\u27E8',
  2538. 'laquo': '\u00AB',
  2539. 'larr': '\u2190',
  2540. 'lArr': '\u21D0',
  2541. 'lceil': '\u2308',
  2542. 'ldquo': '\u201C',
  2543. 'le': '\u2264',
  2544. 'lfloor': '\u230A',
  2545. 'lowast': '\u2217',
  2546. 'loz': '\u25CA',
  2547. 'lrm': '\u200E',
  2548. 'lsaquo': '\u2039',
  2549. 'lsquo': '\u2018',
  2550. 'lt': '<',
  2551. 'macr': '\u00AF',
  2552. 'mdash': '\u2014',
  2553. 'micro': '\u00B5',
  2554. 'middot': '\u00B7',
  2555. 'minus': '\u2212',
  2556. 'Mu': '\u039C',
  2557. 'mu': '\u03BC',
  2558. 'nabla': '\u2207',
  2559. 'nbsp': '\u00A0',
  2560. 'ndash': '\u2013',
  2561. 'ne': '\u2260',
  2562. 'ni': '\u220B',
  2563. 'not': '\u00AC',
  2564. 'notin': '\u2209',
  2565. 'nsub': '\u2284',
  2566. 'Ntilde': '\u00D1',
  2567. 'ntilde': '\u00F1',
  2568. 'Nu': '\u039D',
  2569. 'nu': '\u03BD',
  2570. 'Oacute': '\u00D3',
  2571. 'oacute': '\u00F3',
  2572. 'Ocirc': '\u00D4',
  2573. 'ocirc': '\u00F4',
  2574. 'OElig': '\u0152',
  2575. 'oelig': '\u0153',
  2576. 'Ograve': '\u00D2',
  2577. 'ograve': '\u00F2',
  2578. 'oline': '\u203E',
  2579. 'Omega': '\u03A9',
  2580. 'omega': '\u03C9',
  2581. 'Omicron': '\u039F',
  2582. 'omicron': '\u03BF',
  2583. 'oplus': '\u2295',
  2584. 'or': '\u2228',
  2585. 'ordf': '\u00AA',
  2586. 'ordm': '\u00BA',
  2587. 'Oslash': '\u00D8',
  2588. 'oslash': '\u00F8',
  2589. 'Otilde': '\u00D5',
  2590. 'otilde': '\u00F5',
  2591. 'otimes': '\u2297',
  2592. 'Ouml': '\u00D6',
  2593. 'ouml': '\u00F6',
  2594. 'para': '\u00B6',
  2595. 'permil': '\u2030',
  2596. 'perp': '\u22A5',
  2597. 'Phi': '\u03A6',
  2598. 'phi': '\u03C6',
  2599. 'Pi': '\u03A0',
  2600. 'pi': '\u03C0',
  2601. 'piv': '\u03D6',
  2602. 'plusmn': '\u00B1',
  2603. 'pound': '\u00A3',
  2604. 'prime': '\u2032',
  2605. 'Prime': '\u2033',
  2606. 'prod': '\u220F',
  2607. 'prop': '\u221D',
  2608. 'Psi': '\u03A8',
  2609. 'psi': '\u03C8',
  2610. 'quot': '\u0022',
  2611. 'radic': '\u221A',
  2612. 'rang': '\u27E9',
  2613. 'raquo': '\u00BB',
  2614. 'rarr': '\u2192',
  2615. 'rArr': '\u21D2',
  2616. 'rceil': '\u2309',
  2617. 'rdquo': '\u201D',
  2618. 'real': '\u211C',
  2619. 'reg': '\u00AE',
  2620. 'rfloor': '\u230B',
  2621. 'Rho': '\u03A1',
  2622. 'rho': '\u03C1',
  2623. 'rlm': '\u200F',
  2624. 'rsaquo': '\u203A',
  2625. 'rsquo': '\u2019',
  2626. 'sbquo': '\u201A',
  2627. 'Scaron': '\u0160',
  2628. 'scaron': '\u0161',
  2629. 'sdot': '\u22C5',
  2630. 'sect': '\u00A7',
  2631. 'shy': '\u00AD',
  2632. 'Sigma': '\u03A3',
  2633. 'sigma': '\u03C3',
  2634. 'sigmaf': '\u03C2',
  2635. 'sim': '\u223C',
  2636. 'spades': '\u2660',
  2637. 'sub': '\u2282',
  2638. 'sube': '\u2286',
  2639. 'sum': '\u2211',
  2640. 'sup': '\u2283',
  2641. 'sup1': '\u00B9',
  2642. 'sup2': '\u00B2',
  2643. 'sup3': '\u00B3',
  2644. 'supe': '\u2287',
  2645. 'szlig': '\u00DF',
  2646. 'Tau': '\u03A4',
  2647. 'tau': '\u03C4',
  2648. 'there4': '\u2234',
  2649. 'Theta': '\u0398',
  2650. 'theta': '\u03B8',
  2651. 'thetasym': '\u03D1',
  2652. 'thinsp': '\u2009',
  2653. 'THORN': '\u00DE',
  2654. 'thorn': '\u00FE',
  2655. 'tilde': '\u02DC',
  2656. 'times': '\u00D7',
  2657. 'trade': '\u2122',
  2658. 'Uacute': '\u00DA',
  2659. 'uacute': '\u00FA',
  2660. 'uarr': '\u2191',
  2661. 'uArr': '\u21D1',
  2662. 'Ucirc': '\u00DB',
  2663. 'ucirc': '\u00FB',
  2664. 'Ugrave': '\u00D9',
  2665. 'ugrave': '\u00F9',
  2666. 'uml': '\u00A8',
  2667. 'upsih': '\u03D2',
  2668. 'Upsilon': '\u03A5',
  2669. 'upsilon': '\u03C5',
  2670. 'Uuml': '\u00DC',
  2671. 'uuml': '\u00FC',
  2672. 'weierp': '\u2118',
  2673. 'Xi': '\u039E',
  2674. 'xi': '\u03BE',
  2675. 'Yacute': '\u00DD',
  2676. 'yacute': '\u00FD',
  2677. 'yen': '\u00A5',
  2678. 'yuml': '\u00FF',
  2679. 'Yuml': '\u0178',
  2680. 'Zeta': '\u0396',
  2681. 'zeta': '\u03B6',
  2682. 'zwj': '\u200D',
  2683. 'zwnj': '\u200C',
  2684. };
  2685. // The &ngsp; pseudo-entity is denoting a space. see:
  2686. // https://github.com/dart-lang/angular/blob/0bb611387d29d65b5af7f9d2515ab571fd3fbee4/_tests/test/compiler/preserve_whitespace_test.dart
  2687. const NGSP_UNICODE = '\uE500';
  2688. NAMED_ENTITIES['ngsp'] = NGSP_UNICODE;
  2689. /**
  2690. * @fileoverview added by tsickle
  2691. * @suppress {checkTypes} checked by tsc
  2692. */
  2693. /**
  2694. * @license
  2695. * Copyright Google Inc. All Rights Reserved.
  2696. *
  2697. * Use of this source code is governed by an MIT-style license that can be
  2698. * found in the LICENSE file at https://angular.io/license
  2699. */
  2700. const NG_CONTENT_SELECT_ATTR = 'select';
  2701. const LINK_ELEMENT = 'link';
  2702. const LINK_STYLE_REL_ATTR = 'rel';
  2703. const LINK_STYLE_HREF_ATTR = 'href';
  2704. const LINK_STYLE_REL_VALUE = 'stylesheet';
  2705. const STYLE_ELEMENT = 'style';
  2706. const SCRIPT_ELEMENT = 'script';
  2707. const NG_NON_BINDABLE_ATTR = 'ngNonBindable';
  2708. const NG_PROJECT_AS = 'ngProjectAs';
  2709. /**
  2710. * @param {?} ast
  2711. * @return {?}
  2712. */
  2713. function preparseElement(ast) {
  2714. let /** @type {?} */ selectAttr = /** @type {?} */ ((null));
  2715. let /** @type {?} */ hrefAttr = /** @type {?} */ ((null));
  2716. let /** @type {?} */ relAttr = /** @type {?} */ ((null));
  2717. let /** @type {?} */ nonBindable = false;
  2718. let /** @type {?} */ projectAs = /** @type {?} */ ((null));
  2719. ast.attrs.forEach(attr => {
  2720. const /** @type {?} */ lcAttrName = attr.name.toLowerCase();
  2721. if (lcAttrName == NG_CONTENT_SELECT_ATTR) {
  2722. selectAttr = attr.value;
  2723. }
  2724. else if (lcAttrName == LINK_STYLE_HREF_ATTR) {
  2725. hrefAttr = attr.value;
  2726. }
  2727. else if (lcAttrName == LINK_STYLE_REL_ATTR) {
  2728. relAttr = attr.value;
  2729. }
  2730. else if (attr.name == NG_NON_BINDABLE_ATTR) {
  2731. nonBindable = true;
  2732. }
  2733. else if (attr.name == NG_PROJECT_AS) {
  2734. if (attr.value.length > 0) {
  2735. projectAs = attr.value;
  2736. }
  2737. }
  2738. });
  2739. selectAttr = normalizeNgContentSelect(selectAttr);
  2740. const /** @type {?} */ nodeName = ast.name.toLowerCase();
  2741. let /** @type {?} */ type = PreparsedElementType.OTHER;
  2742. if (isNgContent(nodeName)) {
  2743. type = PreparsedElementType.NG_CONTENT;
  2744. }
  2745. else if (nodeName == STYLE_ELEMENT) {
  2746. type = PreparsedElementType.STYLE;
  2747. }
  2748. else if (nodeName == SCRIPT_ELEMENT) {
  2749. type = PreparsedElementType.SCRIPT;
  2750. }
  2751. else if (nodeName == LINK_ELEMENT && relAttr == LINK_STYLE_REL_VALUE) {
  2752. type = PreparsedElementType.STYLESHEET;
  2753. }
  2754. return new PreparsedElement(type, selectAttr, hrefAttr, nonBindable, projectAs);
  2755. }
  2756. /** @enum {number} */
  2757. const PreparsedElementType = {
  2758. NG_CONTENT: 0,
  2759. STYLE: 1,
  2760. STYLESHEET: 2,
  2761. SCRIPT: 3,
  2762. OTHER: 4,
  2763. };
  2764. PreparsedElementType[PreparsedElementType.NG_CONTENT] = "NG_CONTENT";
  2765. PreparsedElementType[PreparsedElementType.STYLE] = "STYLE";
  2766. PreparsedElementType[PreparsedElementType.STYLESHEET] = "STYLESHEET";
  2767. PreparsedElementType[PreparsedElementType.SCRIPT] = "SCRIPT";
  2768. PreparsedElementType[PreparsedElementType.OTHER] = "OTHER";
  2769. class PreparsedElement {
  2770. /**
  2771. * @param {?} type
  2772. * @param {?} selectAttr
  2773. * @param {?} hrefAttr
  2774. * @param {?} nonBindable
  2775. * @param {?} projectAs
  2776. */
  2777. constructor(type, selectAttr, hrefAttr, nonBindable, projectAs) {
  2778. this.type = type;
  2779. this.selectAttr = selectAttr;
  2780. this.hrefAttr = hrefAttr;
  2781. this.nonBindable = nonBindable;
  2782. this.projectAs = projectAs;
  2783. }
  2784. }
  2785. /**
  2786. * @param {?} selectAttr
  2787. * @return {?}
  2788. */
  2789. function normalizeNgContentSelect(selectAttr) {
  2790. if (selectAttr === null || selectAttr.length === 0) {
  2791. return '*';
  2792. }
  2793. return selectAttr;
  2794. }
  2795. /**
  2796. * @fileoverview added by tsickle
  2797. * @suppress {checkTypes} checked by tsc
  2798. */
  2799. /**
  2800. * @license
  2801. * Copyright Google Inc. All Rights Reserved.
  2802. *
  2803. * Use of this source code is governed by an MIT-style license that can be
  2804. * found in the LICENSE file at https://angular.io/license
  2805. */
  2806. /**
  2807. * @record
  2808. */
  2809. class DirectiveNormalizer {
  2810. /**
  2811. * @param {?} _resourceLoader
  2812. * @param {?} _urlResolver
  2813. * @param {?} _htmlParser
  2814. * @param {?} _config
  2815. */
  2816. constructor(_resourceLoader, _urlResolver, _htmlParser, _config) {
  2817. this._resourceLoader = _resourceLoader;
  2818. this._urlResolver = _urlResolver;
  2819. this._htmlParser = _htmlParser;
  2820. this._config = _config;
  2821. this._resourceLoaderCache = new Map();
  2822. }
  2823. /**
  2824. * @return {?}
  2825. */
  2826. clearCache() { this._resourceLoaderCache.clear(); }
  2827. /**
  2828. * @param {?} normalizedDirective
  2829. * @return {?}
  2830. */
  2831. clearCacheFor(normalizedDirective) {
  2832. if (!normalizedDirective.isComponent) {
  2833. return;
  2834. }
  2835. const /** @type {?} */ template = /** @type {?} */ ((normalizedDirective.template));
  2836. this._resourceLoaderCache.delete(/** @type {?} */ ((template.templateUrl)));
  2837. template.externalStylesheets.forEach((stylesheet) => { this._resourceLoaderCache.delete(/** @type {?} */ ((stylesheet.moduleUrl))); });
  2838. }
  2839. /**
  2840. * @param {?} url
  2841. * @return {?}
  2842. */
  2843. _fetch(url) {
  2844. let /** @type {?} */ result = this._resourceLoaderCache.get(url);
  2845. if (!result) {
  2846. result = this._resourceLoader.get(url);
  2847. this._resourceLoaderCache.set(url, result);
  2848. }
  2849. return result;
  2850. }
  2851. /**
  2852. * @param {?} prenormData
  2853. * @return {?}
  2854. */
  2855. normalizeTemplate(prenormData) {
  2856. if (isDefined(prenormData.template)) {
  2857. if (isDefined(prenormData.templateUrl)) {
  2858. throw syntaxError(`'${stringify(prenormData.componentType)}' component cannot define both template and templateUrl`);
  2859. }
  2860. if (typeof prenormData.template !== 'string') {
  2861. throw syntaxError(`The template specified for component ${stringify(prenormData.componentType)} is not a string`);
  2862. }
  2863. }
  2864. else if (isDefined(prenormData.templateUrl)) {
  2865. if (typeof prenormData.templateUrl !== 'string') {
  2866. throw syntaxError(`The templateUrl specified for component ${stringify(prenormData.componentType)} is not a string`);
  2867. }
  2868. }
  2869. else {
  2870. throw syntaxError(`No template specified for component ${stringify(prenormData.componentType)}`);
  2871. }
  2872. if (isDefined(prenormData.preserveWhitespaces) &&
  2873. typeof prenormData.preserveWhitespaces !== 'boolean') {
  2874. throw syntaxError(`The preserveWhitespaces option for component ${stringify(prenormData.componentType)} must be a boolean`);
  2875. }
  2876. return SyncAsync.then(this._preParseTemplate(prenormData), (preparsedTemplate) => this._normalizeTemplateMetadata(prenormData, preparsedTemplate));
  2877. }
  2878. /**
  2879. * @param {?} prenomData
  2880. * @return {?}
  2881. */
  2882. _preParseTemplate(prenomData) {
  2883. let /** @type {?} */ template;
  2884. let /** @type {?} */ templateUrl;
  2885. if (prenomData.template != null) {
  2886. template = prenomData.template;
  2887. templateUrl = prenomData.moduleUrl;
  2888. }
  2889. else {
  2890. templateUrl = this._urlResolver.resolve(prenomData.moduleUrl, /** @type {?} */ ((prenomData.templateUrl)));
  2891. template = this._fetch(templateUrl);
  2892. }
  2893. return SyncAsync.then(template, (template) => this._preparseLoadedTemplate(prenomData, template, templateUrl));
  2894. }
  2895. /**
  2896. * @param {?} prenormData
  2897. * @param {?} template
  2898. * @param {?} templateAbsUrl
  2899. * @return {?}
  2900. */
  2901. _preparseLoadedTemplate(prenormData, template, templateAbsUrl) {
  2902. const /** @type {?} */ isInline = !!prenormData.template;
  2903. const /** @type {?} */ interpolationConfig = InterpolationConfig.fromArray(/** @type {?} */ ((prenormData.interpolation)));
  2904. const /** @type {?} */ rootNodesAndErrors = this._htmlParser.parse(template, templateSourceUrl({ reference: prenormData.ngModuleType }, { type: { reference: prenormData.componentType } }, { isInline, templateUrl: templateAbsUrl }), true, interpolationConfig);
  2905. if (rootNodesAndErrors.errors.length > 0) {
  2906. const /** @type {?} */ errorString = rootNodesAndErrors.errors.join('\n');
  2907. throw syntaxError(`Template parse errors:\n${errorString}`);
  2908. }
  2909. const /** @type {?} */ templateMetadataStyles = this._normalizeStylesheet(new CompileStylesheetMetadata({ styles: prenormData.styles, moduleUrl: prenormData.moduleUrl }));
  2910. const /** @type {?} */ visitor = new TemplatePreparseVisitor();
  2911. visitAll(visitor, rootNodesAndErrors.rootNodes);
  2912. const /** @type {?} */ templateStyles = this._normalizeStylesheet(new CompileStylesheetMetadata({ styles: visitor.styles, styleUrls: visitor.styleUrls, moduleUrl: templateAbsUrl }));
  2913. const /** @type {?} */ styles = templateMetadataStyles.styles.concat(templateStyles.styles);
  2914. const /** @type {?} */ inlineStyleUrls = templateMetadataStyles.styleUrls.concat(templateStyles.styleUrls);
  2915. const /** @type {?} */ styleUrls = this
  2916. ._normalizeStylesheet(new CompileStylesheetMetadata({ styleUrls: prenormData.styleUrls, moduleUrl: prenormData.moduleUrl }))
  2917. .styleUrls;
  2918. return {
  2919. template,
  2920. templateUrl: templateAbsUrl, isInline,
  2921. htmlAst: rootNodesAndErrors, styles, inlineStyleUrls, styleUrls,
  2922. ngContentSelectors: visitor.ngContentSelectors,
  2923. };
  2924. }
  2925. /**
  2926. * @param {?} prenormData
  2927. * @param {?} preparsedTemplate
  2928. * @return {?}
  2929. */
  2930. _normalizeTemplateMetadata(prenormData, preparsedTemplate) {
  2931. return SyncAsync.then(this._loadMissingExternalStylesheets(preparsedTemplate.styleUrls.concat(preparsedTemplate.inlineStyleUrls)), (externalStylesheets) => this._normalizeLoadedTemplateMetadata(prenormData, preparsedTemplate, externalStylesheets));
  2932. }
  2933. /**
  2934. * @param {?} prenormData
  2935. * @param {?} preparsedTemplate
  2936. * @param {?} stylesheets
  2937. * @return {?}
  2938. */
  2939. _normalizeLoadedTemplateMetadata(prenormData, preparsedTemplate, stylesheets) {
  2940. // Algorithm:
  2941. // - produce exactly 1 entry per original styleUrl in
  2942. // CompileTemplateMetadata.externalStylesheets whith all styles inlined
  2943. // - inline all styles that are referenced by the template into CompileTemplateMetadata.styles.
  2944. // Reason: be able to determine how many stylesheets there are even without loading
  2945. // the template nor the stylesheets, so we can create a stub for TypeScript always synchronously
  2946. // (as resouce loading may be async)
  2947. const /** @type {?} */ styles = [...preparsedTemplate.styles];
  2948. this._inlineStyles(preparsedTemplate.inlineStyleUrls, stylesheets, styles);
  2949. const /** @type {?} */ styleUrls = preparsedTemplate.styleUrls;
  2950. const /** @type {?} */ externalStylesheets = styleUrls.map(styleUrl => {
  2951. const /** @type {?} */ stylesheet = /** @type {?} */ ((stylesheets.get(styleUrl)));
  2952. const /** @type {?} */ styles = [...stylesheet.styles];
  2953. this._inlineStyles(stylesheet.styleUrls, stylesheets, styles);
  2954. return new CompileStylesheetMetadata({ moduleUrl: styleUrl, styles: styles });
  2955. });
  2956. let /** @type {?} */ encapsulation = prenormData.encapsulation;
  2957. if (encapsulation == null) {
  2958. encapsulation = this._config.defaultEncapsulation;
  2959. }
  2960. if (encapsulation === ViewEncapsulation.Emulated && styles.length === 0 &&
  2961. styleUrls.length === 0) {
  2962. encapsulation = ViewEncapsulation.None;
  2963. }
  2964. return new CompileTemplateMetadata({
  2965. encapsulation,
  2966. template: preparsedTemplate.template,
  2967. templateUrl: preparsedTemplate.templateUrl,
  2968. htmlAst: preparsedTemplate.htmlAst, styles, styleUrls,
  2969. ngContentSelectors: preparsedTemplate.ngContentSelectors,
  2970. animations: prenormData.animations,
  2971. interpolation: prenormData.interpolation,
  2972. isInline: preparsedTemplate.isInline, externalStylesheets,
  2973. preserveWhitespaces: preserveWhitespacesDefault(prenormData.preserveWhitespaces, this._config.preserveWhitespaces),
  2974. });
  2975. }
  2976. /**
  2977. * @param {?} styleUrls
  2978. * @param {?} stylesheets
  2979. * @param {?} targetStyles
  2980. * @return {?}
  2981. */
  2982. _inlineStyles(styleUrls, stylesheets, targetStyles) {
  2983. styleUrls.forEach(styleUrl => {
  2984. const /** @type {?} */ stylesheet = /** @type {?} */ ((stylesheets.get(styleUrl)));
  2985. stylesheet.styles.forEach(style => targetStyles.push(style));
  2986. this._inlineStyles(stylesheet.styleUrls, stylesheets, targetStyles);
  2987. });
  2988. }
  2989. /**
  2990. * @param {?} styleUrls
  2991. * @param {?=} loadedStylesheets
  2992. * @return {?}
  2993. */
  2994. _loadMissingExternalStylesheets(styleUrls, loadedStylesheets = new Map()) {
  2995. return SyncAsync.then(SyncAsync.all(styleUrls.filter((styleUrl) => !loadedStylesheets.has(styleUrl))
  2996. .map(styleUrl => SyncAsync.then(this._fetch(styleUrl), (loadedStyle) => {
  2997. const /** @type {?} */ stylesheet = this._normalizeStylesheet(new CompileStylesheetMetadata({ styles: [loadedStyle], moduleUrl: styleUrl }));
  2998. loadedStylesheets.set(styleUrl, stylesheet);
  2999. return this._loadMissingExternalStylesheets(stylesheet.styleUrls, loadedStylesheets);
  3000. }))), (_) => loadedStylesheets);
  3001. }
  3002. /**
  3003. * @param {?} stylesheet
  3004. * @return {?}
  3005. */
  3006. _normalizeStylesheet(stylesheet) {
  3007. const /** @type {?} */ moduleUrl = /** @type {?} */ ((stylesheet.moduleUrl));
  3008. const /** @type {?} */ allStyleUrls = stylesheet.styleUrls.filter(isStyleUrlResolvable)
  3009. .map(url => this._urlResolver.resolve(moduleUrl, url));
  3010. const /** @type {?} */ allStyles = stylesheet.styles.map(style => {
  3011. const /** @type {?} */ styleWithImports = extractStyleUrls(this._urlResolver, moduleUrl, style);
  3012. allStyleUrls.push(...styleWithImports.styleUrls);
  3013. return styleWithImports.style;
  3014. });
  3015. return new CompileStylesheetMetadata({ styles: allStyles, styleUrls: allStyleUrls, moduleUrl: moduleUrl });
  3016. }
  3017. }
  3018. class TemplatePreparseVisitor {
  3019. constructor() {
  3020. this.ngContentSelectors = [];
  3021. this.styles = [];
  3022. this.styleUrls = [];
  3023. this.ngNonBindableStackCount = 0;
  3024. }
  3025. /**
  3026. * @param {?} ast
  3027. * @param {?} context
  3028. * @return {?}
  3029. */
  3030. visitElement(ast, context) {
  3031. const /** @type {?} */ preparsedElement = preparseElement(ast);
  3032. switch (preparsedElement.type) {
  3033. case PreparsedElementType.NG_CONTENT:
  3034. if (this.ngNonBindableStackCount === 0) {
  3035. this.ngContentSelectors.push(preparsedElement.selectAttr);
  3036. }
  3037. break;
  3038. case PreparsedElementType.STYLE:
  3039. let /** @type {?} */ textContent = '';
  3040. ast.children.forEach(child => {
  3041. if (child instanceof Text) {
  3042. textContent += child.value;
  3043. }
  3044. });
  3045. this.styles.push(textContent);
  3046. break;
  3047. case PreparsedElementType.STYLESHEET:
  3048. this.styleUrls.push(preparsedElement.hrefAttr);
  3049. break;
  3050. default:
  3051. break;
  3052. }
  3053. if (preparsedElement.nonBindable) {
  3054. this.ngNonBindableStackCount++;
  3055. }
  3056. visitAll(this, ast.children);
  3057. if (preparsedElement.nonBindable) {
  3058. this.ngNonBindableStackCount--;
  3059. }
  3060. return null;
  3061. }
  3062. /**
  3063. * @param {?} ast
  3064. * @param {?} context
  3065. * @return {?}
  3066. */
  3067. visitExpansion(ast, context) { visitAll(this, ast.cases); }
  3068. /**
  3069. * @param {?} ast
  3070. * @param {?} context
  3071. * @return {?}
  3072. */
  3073. visitExpansionCase(ast, context) {
  3074. visitAll(this, ast.expression);
  3075. }
  3076. /**
  3077. * @param {?} ast
  3078. * @param {?} context
  3079. * @return {?}
  3080. */
  3081. visitComment(ast, context) { return null; }
  3082. /**
  3083. * @param {?} ast
  3084. * @param {?} context
  3085. * @return {?}
  3086. */
  3087. visitAttribute(ast, context) { return null; }
  3088. /**
  3089. * @param {?} ast
  3090. * @param {?} context
  3091. * @return {?}
  3092. */
  3093. visitText(ast, context) { return null; }
  3094. }
  3095. /**
  3096. * @fileoverview added by tsickle
  3097. * @suppress {checkTypes} checked by tsc
  3098. */
  3099. /**
  3100. * @license
  3101. * Copyright Google Inc. All Rights Reserved.
  3102. *
  3103. * Use of this source code is governed by an MIT-style license that can be
  3104. * found in the LICENSE file at https://angular.io/license
  3105. */
  3106. const QUERY_METADATA_IDENTIFIERS = [
  3107. createViewChild,
  3108. createViewChildren,
  3109. createContentChild,
  3110. createContentChildren,
  3111. ];
  3112. class DirectiveResolver {
  3113. /**
  3114. * @param {?} _reflector
  3115. */
  3116. constructor(_reflector) {
  3117. this._reflector = _reflector;
  3118. }
  3119. /**
  3120. * @param {?} type
  3121. * @return {?}
  3122. */
  3123. isDirective(type) {
  3124. const /** @type {?} */ typeMetadata = this._reflector.annotations(resolveForwardRef(type));
  3125. return typeMetadata && typeMetadata.some(isDirectiveMetadata);
  3126. }
  3127. /**
  3128. * @param {?} type
  3129. * @param {?=} throwIfNotFound
  3130. * @return {?}
  3131. */
  3132. resolve(type, throwIfNotFound = true) {
  3133. const /** @type {?} */ typeMetadata = this._reflector.annotations(resolveForwardRef(type));
  3134. if (typeMetadata) {
  3135. const /** @type {?} */ metadata = findLast(typeMetadata, isDirectiveMetadata);
  3136. if (metadata) {
  3137. const /** @type {?} */ propertyMetadata = this._reflector.propMetadata(type);
  3138. const /** @type {?} */ guards = this._reflector.guards(type);
  3139. return this._mergeWithPropertyMetadata(metadata, propertyMetadata, guards, type);
  3140. }
  3141. }
  3142. if (throwIfNotFound) {
  3143. throw new Error(`No Directive annotation found on ${stringify(type)}`);
  3144. }
  3145. return null;
  3146. }
  3147. /**
  3148. * @param {?} dm
  3149. * @param {?} propertyMetadata
  3150. * @param {?} guards
  3151. * @param {?} directiveType
  3152. * @return {?}
  3153. */
  3154. _mergeWithPropertyMetadata(dm, propertyMetadata, guards, directiveType) {
  3155. const /** @type {?} */ inputs = [];
  3156. const /** @type {?} */ outputs = [];
  3157. const /** @type {?} */ host = {};
  3158. const /** @type {?} */ queries = {};
  3159. Object.keys(propertyMetadata).forEach((propName) => {
  3160. const /** @type {?} */ input = findLast(propertyMetadata[propName], (a) => createInput.isTypeOf(a));
  3161. if (input) {
  3162. if (input.bindingPropertyName) {
  3163. inputs.push(`${propName}: ${input.bindingPropertyName}`);
  3164. }
  3165. else {
  3166. inputs.push(propName);
  3167. }
  3168. }
  3169. const /** @type {?} */ output = findLast(propertyMetadata[propName], (a) => createOutput.isTypeOf(a));
  3170. if (output) {
  3171. if (output.bindingPropertyName) {
  3172. outputs.push(`${propName}: ${output.bindingPropertyName}`);
  3173. }
  3174. else {
  3175. outputs.push(propName);
  3176. }
  3177. }
  3178. const /** @type {?} */ hostBindings = propertyMetadata[propName].filter(a => createHostBinding.isTypeOf(a));
  3179. hostBindings.forEach(hostBinding => {
  3180. if (hostBinding.hostPropertyName) {
  3181. const /** @type {?} */ startWith = hostBinding.hostPropertyName[0];
  3182. if (startWith === '(') {
  3183. throw new Error(`@HostBinding can not bind to events. Use @HostListener instead.`);
  3184. }
  3185. else if (startWith === '[') {
  3186. throw new Error(`@HostBinding parameter should be a property name, 'class.<name>', or 'attr.<name>'.`);
  3187. }
  3188. host[`[${hostBinding.hostPropertyName}]`] = propName;
  3189. }
  3190. else {
  3191. host[`[${propName}]`] = propName;
  3192. }
  3193. });
  3194. const /** @type {?} */ hostListeners = propertyMetadata[propName].filter(a => createHostListener.isTypeOf(a));
  3195. hostListeners.forEach(hostListener => {
  3196. const /** @type {?} */ args = hostListener.args || [];
  3197. host[`(${hostListener.eventName})`] = `${propName}(${args.join(',')})`;
  3198. });
  3199. const /** @type {?} */ query = findLast(propertyMetadata[propName], (a) => QUERY_METADATA_IDENTIFIERS.some(i => i.isTypeOf(a)));
  3200. if (query) {
  3201. queries[propName] = query;
  3202. }
  3203. });
  3204. return this._merge(dm, inputs, outputs, host, queries, guards, directiveType);
  3205. }
  3206. /**
  3207. * @param {?} def
  3208. * @return {?}
  3209. */
  3210. _extractPublicName(def) { return splitAtColon(def, [/** @type {?} */ ((null)), def])[1].trim(); }
  3211. /**
  3212. * @param {?} bindings
  3213. * @return {?}
  3214. */
  3215. _dedupeBindings(bindings) {
  3216. const /** @type {?} */ names = new Set();
  3217. const /** @type {?} */ publicNames = new Set();
  3218. const /** @type {?} */ reversedResult = [];
  3219. // go last to first to allow later entries to overwrite previous entries
  3220. for (let /** @type {?} */ i = bindings.length - 1; i >= 0; i--) {
  3221. const /** @type {?} */ binding = bindings[i];
  3222. const /** @type {?} */ name = this._extractPublicName(binding);
  3223. publicNames.add(name);
  3224. if (!names.has(name)) {
  3225. names.add(name);
  3226. reversedResult.push(binding);
  3227. }
  3228. }
  3229. return reversedResult.reverse();
  3230. }
  3231. /**
  3232. * @param {?} directive
  3233. * @param {?} inputs
  3234. * @param {?} outputs
  3235. * @param {?} host
  3236. * @param {?} queries
  3237. * @param {?} guards
  3238. * @param {?} directiveType
  3239. * @return {?}
  3240. */
  3241. _merge(directive, inputs, outputs, host, queries, guards, directiveType) {
  3242. const /** @type {?} */ mergedInputs = this._dedupeBindings(directive.inputs ? directive.inputs.concat(inputs) : inputs);
  3243. const /** @type {?} */ mergedOutputs = this._dedupeBindings(directive.outputs ? directive.outputs.concat(outputs) : outputs);
  3244. const /** @type {?} */ mergedHost = directive.host ? Object.assign({}, directive.host, host) : host;
  3245. const /** @type {?} */ mergedQueries = directive.queries ? Object.assign({}, directive.queries, queries) : queries;
  3246. if (createComponent.isTypeOf(directive)) {
  3247. const /** @type {?} */ comp = /** @type {?} */ (directive);
  3248. return createComponent({
  3249. selector: comp.selector,
  3250. inputs: mergedInputs,
  3251. outputs: mergedOutputs,
  3252. host: mergedHost,
  3253. exportAs: comp.exportAs,
  3254. moduleId: comp.moduleId,
  3255. queries: mergedQueries,
  3256. changeDetection: comp.changeDetection,
  3257. providers: comp.providers,
  3258. viewProviders: comp.viewProviders,
  3259. entryComponents: comp.entryComponents,
  3260. template: comp.template,
  3261. templateUrl: comp.templateUrl,
  3262. styles: comp.styles,
  3263. styleUrls: comp.styleUrls,
  3264. encapsulation: comp.encapsulation,
  3265. animations: comp.animations,
  3266. interpolation: comp.interpolation,
  3267. preserveWhitespaces: directive.preserveWhitespaces,
  3268. });
  3269. }
  3270. else {
  3271. return createDirective({
  3272. selector: directive.selector,
  3273. inputs: mergedInputs,
  3274. outputs: mergedOutputs,
  3275. host: mergedHost,
  3276. exportAs: directive.exportAs,
  3277. queries: mergedQueries,
  3278. providers: directive.providers, guards
  3279. });
  3280. }
  3281. }
  3282. }
  3283. /**
  3284. * @param {?} type
  3285. * @return {?}
  3286. */
  3287. function isDirectiveMetadata(type) {
  3288. return createDirective.isTypeOf(type) || createComponent.isTypeOf(type);
  3289. }
  3290. /**
  3291. * @template T
  3292. * @param {?} arr
  3293. * @param {?} condition
  3294. * @return {?}
  3295. */
  3296. function findLast(arr, condition) {
  3297. for (let /** @type {?} */ i = arr.length - 1; i >= 0; i--) {
  3298. if (condition(arr[i])) {
  3299. return arr[i];
  3300. }
  3301. }
  3302. return null;
  3303. }
  3304. /**
  3305. * @fileoverview added by tsickle
  3306. * @suppress {checkTypes} checked by tsc
  3307. */
  3308. /**
  3309. * @license
  3310. * Copyright Google Inc. All Rights Reserved.
  3311. *
  3312. * Use of this source code is governed by an MIT-style license that can be
  3313. * found in the LICENSE file at https://angular.io/license
  3314. */
  3315. const $EOF = 0;
  3316. const $TAB = 9;
  3317. const $LF = 10;
  3318. const $VTAB = 11;
  3319. const $FF = 12;
  3320. const $CR = 13;
  3321. const $SPACE = 32;
  3322. const $BANG = 33;
  3323. const $DQ = 34;
  3324. const $HASH = 35;
  3325. const $$ = 36;
  3326. const $PERCENT = 37;
  3327. const $AMPERSAND = 38;
  3328. const $SQ = 39;
  3329. const $LPAREN = 40;
  3330. const $RPAREN = 41;
  3331. const $STAR = 42;
  3332. const $PLUS = 43;
  3333. const $COMMA = 44;
  3334. const $MINUS = 45;
  3335. const $PERIOD = 46;
  3336. const $SLASH = 47;
  3337. const $COLON = 58;
  3338. const $SEMICOLON = 59;
  3339. const $LT = 60;
  3340. const $EQ = 61;
  3341. const $GT = 62;
  3342. const $QUESTION = 63;
  3343. const $0 = 48;
  3344. const $9 = 57;
  3345. const $A = 65;
  3346. const $E = 69;
  3347. const $F = 70;
  3348. const $X = 88;
  3349. const $Z = 90;
  3350. const $LBRACKET = 91;
  3351. const $BACKSLASH = 92;
  3352. const $RBRACKET = 93;
  3353. const $CARET = 94;
  3354. const $_ = 95;
  3355. const $a = 97;
  3356. const $e = 101;
  3357. const $f = 102;
  3358. const $n = 110;
  3359. const $r = 114;
  3360. const $t = 116;
  3361. const $u = 117;
  3362. const $v = 118;
  3363. const $x = 120;
  3364. const $z = 122;
  3365. const $LBRACE = 123;
  3366. const $BAR = 124;
  3367. const $RBRACE = 125;
  3368. const $NBSP = 160;
  3369. const $BT = 96;
  3370. /**
  3371. * @param {?} code
  3372. * @return {?}
  3373. */
  3374. function isWhitespace(code) {
  3375. return (code >= $TAB && code <= $SPACE) || (code == $NBSP);
  3376. }
  3377. /**
  3378. * @param {?} code
  3379. * @return {?}
  3380. */
  3381. function isDigit(code) {
  3382. return $0 <= code && code <= $9;
  3383. }
  3384. /**
  3385. * @param {?} code
  3386. * @return {?}
  3387. */
  3388. function isAsciiLetter(code) {
  3389. return code >= $a && code <= $z || code >= $A && code <= $Z;
  3390. }
  3391. /**
  3392. * @param {?} code
  3393. * @return {?}
  3394. */
  3395. function isAsciiHexDigit(code) {
  3396. return code >= $a && code <= $f || code >= $A && code <= $F || isDigit(code);
  3397. }
  3398. /**
  3399. * @fileoverview added by tsickle
  3400. * @suppress {checkTypes} checked by tsc
  3401. */
  3402. /**
  3403. * @license
  3404. * Copyright Google Inc. All Rights Reserved.
  3405. *
  3406. * Use of this source code is governed by an MIT-style license that can be
  3407. * found in the LICENSE file at https://angular.io/license
  3408. */
  3409. /** @enum {number} */
  3410. const TokenType = {
  3411. Character: 0,
  3412. Identifier: 1,
  3413. Keyword: 2,
  3414. String: 3,
  3415. Operator: 4,
  3416. Number: 5,
  3417. Error: 6,
  3418. };
  3419. TokenType[TokenType.Character] = "Character";
  3420. TokenType[TokenType.Identifier] = "Identifier";
  3421. TokenType[TokenType.Keyword] = "Keyword";
  3422. TokenType[TokenType.String] = "String";
  3423. TokenType[TokenType.Operator] = "Operator";
  3424. TokenType[TokenType.Number] = "Number";
  3425. TokenType[TokenType.Error] = "Error";
  3426. const KEYWORDS = ['var', 'let', 'as', 'null', 'undefined', 'true', 'false', 'if', 'else', 'this'];
  3427. class Lexer {
  3428. /**
  3429. * @param {?} text
  3430. * @return {?}
  3431. */
  3432. tokenize(text) {
  3433. const /** @type {?} */ scanner = new _Scanner(text);
  3434. const /** @type {?} */ tokens = [];
  3435. let /** @type {?} */ token = scanner.scanToken();
  3436. while (token != null) {
  3437. tokens.push(token);
  3438. token = scanner.scanToken();
  3439. }
  3440. return tokens;
  3441. }
  3442. }
  3443. class Token {
  3444. /**
  3445. * @param {?} index
  3446. * @param {?} type
  3447. * @param {?} numValue
  3448. * @param {?} strValue
  3449. */
  3450. constructor(index, type, numValue, strValue) {
  3451. this.index = index;
  3452. this.type = type;
  3453. this.numValue = numValue;
  3454. this.strValue = strValue;
  3455. }
  3456. /**
  3457. * @param {?} code
  3458. * @return {?}
  3459. */
  3460. isCharacter(code) {
  3461. return this.type == TokenType.Character && this.numValue == code;
  3462. }
  3463. /**
  3464. * @return {?}
  3465. */
  3466. isNumber() { return this.type == TokenType.Number; }
  3467. /**
  3468. * @return {?}
  3469. */
  3470. isString() { return this.type == TokenType.String; }
  3471. /**
  3472. * @param {?} operater
  3473. * @return {?}
  3474. */
  3475. isOperator(operater) {
  3476. return this.type == TokenType.Operator && this.strValue == operater;
  3477. }
  3478. /**
  3479. * @return {?}
  3480. */
  3481. isIdentifier() { return this.type == TokenType.Identifier; }
  3482. /**
  3483. * @return {?}
  3484. */
  3485. isKeyword() { return this.type == TokenType.Keyword; }
  3486. /**
  3487. * @return {?}
  3488. */
  3489. isKeywordLet() { return this.type == TokenType.Keyword && this.strValue == 'let'; }
  3490. /**
  3491. * @return {?}
  3492. */
  3493. isKeywordAs() { return this.type == TokenType.Keyword && this.strValue == 'as'; }
  3494. /**
  3495. * @return {?}
  3496. */
  3497. isKeywordNull() { return this.type == TokenType.Keyword && this.strValue == 'null'; }
  3498. /**
  3499. * @return {?}
  3500. */
  3501. isKeywordUndefined() {
  3502. return this.type == TokenType.Keyword && this.strValue == 'undefined';
  3503. }
  3504. /**
  3505. * @return {?}
  3506. */
  3507. isKeywordTrue() { return this.type == TokenType.Keyword && this.strValue == 'true'; }
  3508. /**
  3509. * @return {?}
  3510. */
  3511. isKeywordFalse() { return this.type == TokenType.Keyword && this.strValue == 'false'; }
  3512. /**
  3513. * @return {?}
  3514. */
  3515. isKeywordThis() { return this.type == TokenType.Keyword && this.strValue == 'this'; }
  3516. /**
  3517. * @return {?}
  3518. */
  3519. isError() { return this.type == TokenType.Error; }
  3520. /**
  3521. * @return {?}
  3522. */
  3523. toNumber() { return this.type == TokenType.Number ? this.numValue : -1; }
  3524. /**
  3525. * @return {?}
  3526. */
  3527. toString() {
  3528. switch (this.type) {
  3529. case TokenType.Character:
  3530. case TokenType.Identifier:
  3531. case TokenType.Keyword:
  3532. case TokenType.Operator:
  3533. case TokenType.String:
  3534. case TokenType.Error:
  3535. return this.strValue;
  3536. case TokenType.Number:
  3537. return this.numValue.toString();
  3538. default:
  3539. return null;
  3540. }
  3541. }
  3542. }
  3543. /**
  3544. * @param {?} index
  3545. * @param {?} code
  3546. * @return {?}
  3547. */
  3548. function newCharacterToken(index, code) {
  3549. return new Token(index, TokenType.Character, code, String.fromCharCode(code));
  3550. }
  3551. /**
  3552. * @param {?} index
  3553. * @param {?} text
  3554. * @return {?}
  3555. */
  3556. function newIdentifierToken(index, text) {
  3557. return new Token(index, TokenType.Identifier, 0, text);
  3558. }
  3559. /**
  3560. * @param {?} index
  3561. * @param {?} text
  3562. * @return {?}
  3563. */
  3564. function newKeywordToken(index, text) {
  3565. return new Token(index, TokenType.Keyword, 0, text);
  3566. }
  3567. /**
  3568. * @param {?} index
  3569. * @param {?} text
  3570. * @return {?}
  3571. */
  3572. function newOperatorToken(index, text) {
  3573. return new Token(index, TokenType.Operator, 0, text);
  3574. }
  3575. /**
  3576. * @param {?} index
  3577. * @param {?} text
  3578. * @return {?}
  3579. */
  3580. function newStringToken(index, text) {
  3581. return new Token(index, TokenType.String, 0, text);
  3582. }
  3583. /**
  3584. * @param {?} index
  3585. * @param {?} n
  3586. * @return {?}
  3587. */
  3588. function newNumberToken(index, n) {
  3589. return new Token(index, TokenType.Number, n, '');
  3590. }
  3591. /**
  3592. * @param {?} index
  3593. * @param {?} message
  3594. * @return {?}
  3595. */
  3596. function newErrorToken(index, message) {
  3597. return new Token(index, TokenType.Error, 0, message);
  3598. }
  3599. const EOF = new Token(-1, TokenType.Character, 0, '');
  3600. class _Scanner {
  3601. /**
  3602. * @param {?} input
  3603. */
  3604. constructor(input) {
  3605. this.input = input;
  3606. this.peek = 0;
  3607. this.index = -1;
  3608. this.length = input.length;
  3609. this.advance();
  3610. }
  3611. /**
  3612. * @return {?}
  3613. */
  3614. advance() {
  3615. this.peek = ++this.index >= this.length ? $EOF : this.input.charCodeAt(this.index);
  3616. }
  3617. /**
  3618. * @return {?}
  3619. */
  3620. scanToken() {
  3621. const /** @type {?} */ input = this.input, /** @type {?} */ length = this.length;
  3622. let /** @type {?} */ peek = this.peek, /** @type {?} */ index = this.index;
  3623. // Skip whitespace.
  3624. while (peek <= $SPACE) {
  3625. if (++index >= length) {
  3626. peek = $EOF;
  3627. break;
  3628. }
  3629. else {
  3630. peek = input.charCodeAt(index);
  3631. }
  3632. }
  3633. this.peek = peek;
  3634. this.index = index;
  3635. if (index >= length) {
  3636. return null;
  3637. }
  3638. // Handle identifiers and numbers.
  3639. if (isIdentifierStart(peek))
  3640. return this.scanIdentifier();
  3641. if (isDigit(peek))
  3642. return this.scanNumber(index);
  3643. const /** @type {?} */ start = index;
  3644. switch (peek) {
  3645. case $PERIOD:
  3646. this.advance();
  3647. return isDigit(this.peek) ? this.scanNumber(start) :
  3648. newCharacterToken(start, $PERIOD);
  3649. case $LPAREN:
  3650. case $RPAREN:
  3651. case $LBRACE:
  3652. case $RBRACE:
  3653. case $LBRACKET:
  3654. case $RBRACKET:
  3655. case $COMMA:
  3656. case $COLON:
  3657. case $SEMICOLON:
  3658. return this.scanCharacter(start, peek);
  3659. case $SQ:
  3660. case $DQ:
  3661. return this.scanString();
  3662. case $HASH:
  3663. case $PLUS:
  3664. case $MINUS:
  3665. case $STAR:
  3666. case $SLASH:
  3667. case $PERCENT:
  3668. case $CARET:
  3669. return this.scanOperator(start, String.fromCharCode(peek));
  3670. case $QUESTION:
  3671. return this.scanComplexOperator(start, '?', $PERIOD, '.');
  3672. case $LT:
  3673. case $GT:
  3674. return this.scanComplexOperator(start, String.fromCharCode(peek), $EQ, '=');
  3675. case $BANG:
  3676. case $EQ:
  3677. return this.scanComplexOperator(start, String.fromCharCode(peek), $EQ, '=', $EQ, '=');
  3678. case $AMPERSAND:
  3679. return this.scanComplexOperator(start, '&', $AMPERSAND, '&');
  3680. case $BAR:
  3681. return this.scanComplexOperator(start, '|', $BAR, '|');
  3682. case $NBSP:
  3683. while (isWhitespace(this.peek))
  3684. this.advance();
  3685. return this.scanToken();
  3686. }
  3687. this.advance();
  3688. return this.error(`Unexpected character [${String.fromCharCode(peek)}]`, 0);
  3689. }
  3690. /**
  3691. * @param {?} start
  3692. * @param {?} code
  3693. * @return {?}
  3694. */
  3695. scanCharacter(start, code) {
  3696. this.advance();
  3697. return newCharacterToken(start, code);
  3698. }
  3699. /**
  3700. * @param {?} start
  3701. * @param {?} str
  3702. * @return {?}
  3703. */
  3704. scanOperator(start, str) {
  3705. this.advance();
  3706. return newOperatorToken(start, str);
  3707. }
  3708. /**
  3709. * Tokenize a 2/3 char long operator
  3710. *
  3711. * @param {?} start start index in the expression
  3712. * @param {?} one first symbol (always part of the operator)
  3713. * @param {?} twoCode code point for the second symbol
  3714. * @param {?} two second symbol (part of the operator when the second code point matches)
  3715. * @param {?=} threeCode code point for the third symbol
  3716. * @param {?=} three third symbol (part of the operator when provided and matches source expression)
  3717. * @return {?}
  3718. */
  3719. scanComplexOperator(start, one, twoCode, two, threeCode, three) {
  3720. this.advance();
  3721. let /** @type {?} */ str = one;
  3722. if (this.peek == twoCode) {
  3723. this.advance();
  3724. str += two;
  3725. }
  3726. if (threeCode != null && this.peek == threeCode) {
  3727. this.advance();
  3728. str += three;
  3729. }
  3730. return newOperatorToken(start, str);
  3731. }
  3732. /**
  3733. * @return {?}
  3734. */
  3735. scanIdentifier() {
  3736. const /** @type {?} */ start = this.index;
  3737. this.advance();
  3738. while (isIdentifierPart(this.peek))
  3739. this.advance();
  3740. const /** @type {?} */ str = this.input.substring(start, this.index);
  3741. return KEYWORDS.indexOf(str) > -1 ? newKeywordToken(start, str) :
  3742. newIdentifierToken(start, str);
  3743. }
  3744. /**
  3745. * @param {?} start
  3746. * @return {?}
  3747. */
  3748. scanNumber(start) {
  3749. let /** @type {?} */ simple = (this.index === start);
  3750. this.advance(); // Skip initial digit.
  3751. while (true) {
  3752. if (isDigit(this.peek)) {
  3753. // Do nothing.
  3754. }
  3755. else if (this.peek == $PERIOD) {
  3756. simple = false;
  3757. }
  3758. else if (isExponentStart(this.peek)) {
  3759. this.advance();
  3760. if (isExponentSign(this.peek))
  3761. this.advance();
  3762. if (!isDigit(this.peek))
  3763. return this.error('Invalid exponent', -1);
  3764. simple = false;
  3765. }
  3766. else {
  3767. break;
  3768. }
  3769. this.advance();
  3770. }
  3771. const /** @type {?} */ str = this.input.substring(start, this.index);
  3772. const /** @type {?} */ value = simple ? parseIntAutoRadix(str) : parseFloat(str);
  3773. return newNumberToken(start, value);
  3774. }
  3775. /**
  3776. * @return {?}
  3777. */
  3778. scanString() {
  3779. const /** @type {?} */ start = this.index;
  3780. const /** @type {?} */ quote = this.peek;
  3781. this.advance(); // Skip initial quote.
  3782. let /** @type {?} */ buffer = '';
  3783. let /** @type {?} */ marker = this.index;
  3784. const /** @type {?} */ input = this.input;
  3785. while (this.peek != quote) {
  3786. if (this.peek == $BACKSLASH) {
  3787. buffer += input.substring(marker, this.index);
  3788. this.advance();
  3789. let /** @type {?} */ unescapedCode;
  3790. // Workaround for TS2.1-introduced type strictness
  3791. this.peek = this.peek;
  3792. if (this.peek == $u) {
  3793. // 4 character hex code for unicode character.
  3794. const /** @type {?} */ hex = input.substring(this.index + 1, this.index + 5);
  3795. if (/^[0-9a-f]+$/i.test(hex)) {
  3796. unescapedCode = parseInt(hex, 16);
  3797. }
  3798. else {
  3799. return this.error(`Invalid unicode escape [\\u${hex}]`, 0);
  3800. }
  3801. for (let /** @type {?} */ i = 0; i < 5; i++) {
  3802. this.advance();
  3803. }
  3804. }
  3805. else {
  3806. unescapedCode = unescape(this.peek);
  3807. this.advance();
  3808. }
  3809. buffer += String.fromCharCode(unescapedCode);
  3810. marker = this.index;
  3811. }
  3812. else if (this.peek == $EOF) {
  3813. return this.error('Unterminated quote', 0);
  3814. }
  3815. else {
  3816. this.advance();
  3817. }
  3818. }
  3819. const /** @type {?} */ last = input.substring(marker, this.index);
  3820. this.advance(); // Skip terminating quote.
  3821. return newStringToken(start, buffer + last);
  3822. }
  3823. /**
  3824. * @param {?} message
  3825. * @param {?} offset
  3826. * @return {?}
  3827. */
  3828. error(message, offset) {
  3829. const /** @type {?} */ position = this.index + offset;
  3830. return newErrorToken(position, `Lexer Error: ${message} at column ${position} in expression [${this.input}]`);
  3831. }
  3832. }
  3833. /**
  3834. * @param {?} code
  3835. * @return {?}
  3836. */
  3837. function isIdentifierStart(code) {
  3838. return ($a <= code && code <= $z) || ($A <= code && code <= $Z) ||
  3839. (code == $_) || (code == $$);
  3840. }
  3841. /**
  3842. * @param {?} input
  3843. * @return {?}
  3844. */
  3845. function isIdentifier(input) {
  3846. if (input.length == 0)
  3847. return false;
  3848. const /** @type {?} */ scanner = new _Scanner(input);
  3849. if (!isIdentifierStart(scanner.peek))
  3850. return false;
  3851. scanner.advance();
  3852. while (scanner.peek !== $EOF) {
  3853. if (!isIdentifierPart(scanner.peek))
  3854. return false;
  3855. scanner.advance();
  3856. }
  3857. return true;
  3858. }
  3859. /**
  3860. * @param {?} code
  3861. * @return {?}
  3862. */
  3863. function isIdentifierPart(code) {
  3864. return isAsciiLetter(code) || isDigit(code) || (code == $_) ||
  3865. (code == $$);
  3866. }
  3867. /**
  3868. * @param {?} code
  3869. * @return {?}
  3870. */
  3871. function isExponentStart(code) {
  3872. return code == $e || code == $E;
  3873. }
  3874. /**
  3875. * @param {?} code
  3876. * @return {?}
  3877. */
  3878. function isExponentSign(code) {
  3879. return code == $MINUS || code == $PLUS;
  3880. }
  3881. /**
  3882. * @param {?} code
  3883. * @return {?}
  3884. */
  3885. function isQuote(code) {
  3886. return code === $SQ || code === $DQ || code === $BT;
  3887. }
  3888. /**
  3889. * @param {?} code
  3890. * @return {?}
  3891. */
  3892. function unescape(code) {
  3893. switch (code) {
  3894. case $n:
  3895. return $LF;
  3896. case $f:
  3897. return $FF;
  3898. case $r:
  3899. return $CR;
  3900. case $t:
  3901. return $TAB;
  3902. case $v:
  3903. return $VTAB;
  3904. default:
  3905. return code;
  3906. }
  3907. }
  3908. /**
  3909. * @param {?} text
  3910. * @return {?}
  3911. */
  3912. function parseIntAutoRadix(text) {
  3913. const /** @type {?} */ result = parseInt(text);
  3914. if (isNaN(result)) {
  3915. throw new Error('Invalid integer literal when parsing ' + text);
  3916. }
  3917. return result;
  3918. }
  3919. /**
  3920. * @fileoverview added by tsickle
  3921. * @suppress {checkTypes} checked by tsc
  3922. */
  3923. /**
  3924. * @license
  3925. * Copyright Google Inc. All Rights Reserved.
  3926. *
  3927. * Use of this source code is governed by an MIT-style license that can be
  3928. * found in the LICENSE file at https://angular.io/license
  3929. */
  3930. class ParserError {
  3931. /**
  3932. * @param {?} message
  3933. * @param {?} input
  3934. * @param {?} errLocation
  3935. * @param {?=} ctxLocation
  3936. */
  3937. constructor(message, input, errLocation, ctxLocation) {
  3938. this.input = input;
  3939. this.errLocation = errLocation;
  3940. this.ctxLocation = ctxLocation;
  3941. this.message = `Parser Error: ${message} ${errLocation} [${input}] in ${ctxLocation}`;
  3942. }
  3943. }
  3944. class ParseSpan {
  3945. /**
  3946. * @param {?} start
  3947. * @param {?} end
  3948. */
  3949. constructor(start, end) {
  3950. this.start = start;
  3951. this.end = end;
  3952. }
  3953. }
  3954. class AST {
  3955. /**
  3956. * @param {?} span
  3957. */
  3958. constructor(span) {
  3959. this.span = span;
  3960. }
  3961. /**
  3962. * @param {?} visitor
  3963. * @param {?=} context
  3964. * @return {?}
  3965. */
  3966. visit(visitor, context = null) { return null; }
  3967. /**
  3968. * @return {?}
  3969. */
  3970. toString() { return 'AST'; }
  3971. }
  3972. /**
  3973. * Represents a quoted expression of the form:
  3974. *
  3975. * quote = prefix `:` uninterpretedExpression
  3976. * prefix = identifier
  3977. * uninterpretedExpression = arbitrary string
  3978. *
  3979. * A quoted expression is meant to be pre-processed by an AST transformer that
  3980. * converts it into another AST that no longer contains quoted expressions.
  3981. * It is meant to allow third-party developers to extend Angular template
  3982. * expression language. The `uninterpretedExpression` part of the quote is
  3983. * therefore not interpreted by the Angular's own expression parser.
  3984. */
  3985. class Quote extends AST {
  3986. /**
  3987. * @param {?} span
  3988. * @param {?} prefix
  3989. * @param {?} uninterpretedExpression
  3990. * @param {?} location
  3991. */
  3992. constructor(span, prefix, uninterpretedExpression, location) {
  3993. super(span);
  3994. this.prefix = prefix;
  3995. this.uninterpretedExpression = uninterpretedExpression;
  3996. this.location = location;
  3997. }
  3998. /**
  3999. * @param {?} visitor
  4000. * @param {?=} context
  4001. * @return {?}
  4002. */
  4003. visit(visitor, context = null) { return visitor.visitQuote(this, context); }
  4004. /**
  4005. * @return {?}
  4006. */
  4007. toString() { return 'Quote'; }
  4008. }
  4009. class EmptyExpr extends AST {
  4010. /**
  4011. * @param {?} visitor
  4012. * @param {?=} context
  4013. * @return {?}
  4014. */
  4015. visit(visitor, context = null) {
  4016. // do nothing
  4017. }
  4018. }
  4019. class ImplicitReceiver extends AST {
  4020. /**
  4021. * @param {?} visitor
  4022. * @param {?=} context
  4023. * @return {?}
  4024. */
  4025. visit(visitor, context = null) {
  4026. return visitor.visitImplicitReceiver(this, context);
  4027. }
  4028. }
  4029. /**
  4030. * Multiple expressions separated by a semicolon.
  4031. */
  4032. class Chain extends AST {
  4033. /**
  4034. * @param {?} span
  4035. * @param {?} expressions
  4036. */
  4037. constructor(span, expressions) {
  4038. super(span);
  4039. this.expressions = expressions;
  4040. }
  4041. /**
  4042. * @param {?} visitor
  4043. * @param {?=} context
  4044. * @return {?}
  4045. */
  4046. visit(visitor, context = null) { return visitor.visitChain(this, context); }
  4047. }
  4048. class Conditional extends AST {
  4049. /**
  4050. * @param {?} span
  4051. * @param {?} condition
  4052. * @param {?} trueExp
  4053. * @param {?} falseExp
  4054. */
  4055. constructor(span, condition, trueExp, falseExp) {
  4056. super(span);
  4057. this.condition = condition;
  4058. this.trueExp = trueExp;
  4059. this.falseExp = falseExp;
  4060. }
  4061. /**
  4062. * @param {?} visitor
  4063. * @param {?=} context
  4064. * @return {?}
  4065. */
  4066. visit(visitor, context = null) {
  4067. return visitor.visitConditional(this, context);
  4068. }
  4069. }
  4070. class PropertyRead extends AST {
  4071. /**
  4072. * @param {?} span
  4073. * @param {?} receiver
  4074. * @param {?} name
  4075. */
  4076. constructor(span, receiver, name) {
  4077. super(span);
  4078. this.receiver = receiver;
  4079. this.name = name;
  4080. }
  4081. /**
  4082. * @param {?} visitor
  4083. * @param {?=} context
  4084. * @return {?}
  4085. */
  4086. visit(visitor, context = null) {
  4087. return visitor.visitPropertyRead(this, context);
  4088. }
  4089. }
  4090. class PropertyWrite extends AST {
  4091. /**
  4092. * @param {?} span
  4093. * @param {?} receiver
  4094. * @param {?} name
  4095. * @param {?} value
  4096. */
  4097. constructor(span, receiver, name, value) {
  4098. super(span);
  4099. this.receiver = receiver;
  4100. this.name = name;
  4101. this.value = value;
  4102. }
  4103. /**
  4104. * @param {?} visitor
  4105. * @param {?=} context
  4106. * @return {?}
  4107. */
  4108. visit(visitor, context = null) {
  4109. return visitor.visitPropertyWrite(this, context);
  4110. }
  4111. }
  4112. class SafePropertyRead extends AST {
  4113. /**
  4114. * @param {?} span
  4115. * @param {?} receiver
  4116. * @param {?} name
  4117. */
  4118. constructor(span, receiver, name) {
  4119. super(span);
  4120. this.receiver = receiver;
  4121. this.name = name;
  4122. }
  4123. /**
  4124. * @param {?} visitor
  4125. * @param {?=} context
  4126. * @return {?}
  4127. */
  4128. visit(visitor, context = null) {
  4129. return visitor.visitSafePropertyRead(this, context);
  4130. }
  4131. }
  4132. class KeyedRead extends AST {
  4133. /**
  4134. * @param {?} span
  4135. * @param {?} obj
  4136. * @param {?} key
  4137. */
  4138. constructor(span, obj, key) {
  4139. super(span);
  4140. this.obj = obj;
  4141. this.key = key;
  4142. }
  4143. /**
  4144. * @param {?} visitor
  4145. * @param {?=} context
  4146. * @return {?}
  4147. */
  4148. visit(visitor, context = null) {
  4149. return visitor.visitKeyedRead(this, context);
  4150. }
  4151. }
  4152. class KeyedWrite extends AST {
  4153. /**
  4154. * @param {?} span
  4155. * @param {?} obj
  4156. * @param {?} key
  4157. * @param {?} value
  4158. */
  4159. constructor(span, obj, key, value) {
  4160. super(span);
  4161. this.obj = obj;
  4162. this.key = key;
  4163. this.value = value;
  4164. }
  4165. /**
  4166. * @param {?} visitor
  4167. * @param {?=} context
  4168. * @return {?}
  4169. */
  4170. visit(visitor, context = null) {
  4171. return visitor.visitKeyedWrite(this, context);
  4172. }
  4173. }
  4174. class BindingPipe extends AST {
  4175. /**
  4176. * @param {?} span
  4177. * @param {?} exp
  4178. * @param {?} name
  4179. * @param {?} args
  4180. */
  4181. constructor(span, exp, name, args) {
  4182. super(span);
  4183. this.exp = exp;
  4184. this.name = name;
  4185. this.args = args;
  4186. }
  4187. /**
  4188. * @param {?} visitor
  4189. * @param {?=} context
  4190. * @return {?}
  4191. */
  4192. visit(visitor, context = null) { return visitor.visitPipe(this, context); }
  4193. }
  4194. class LiteralPrimitive extends AST {
  4195. /**
  4196. * @param {?} span
  4197. * @param {?} value
  4198. */
  4199. constructor(span, value) {
  4200. super(span);
  4201. this.value = value;
  4202. }
  4203. /**
  4204. * @param {?} visitor
  4205. * @param {?=} context
  4206. * @return {?}
  4207. */
  4208. visit(visitor, context = null) {
  4209. return visitor.visitLiteralPrimitive(this, context);
  4210. }
  4211. }
  4212. class LiteralArray extends AST {
  4213. /**
  4214. * @param {?} span
  4215. * @param {?} expressions
  4216. */
  4217. constructor(span, expressions) {
  4218. super(span);
  4219. this.expressions = expressions;
  4220. }
  4221. /**
  4222. * @param {?} visitor
  4223. * @param {?=} context
  4224. * @return {?}
  4225. */
  4226. visit(visitor, context = null) {
  4227. return visitor.visitLiteralArray(this, context);
  4228. }
  4229. }
  4230. class LiteralMap extends AST {
  4231. /**
  4232. * @param {?} span
  4233. * @param {?} keys
  4234. * @param {?} values
  4235. */
  4236. constructor(span, keys, values) {
  4237. super(span);
  4238. this.keys = keys;
  4239. this.values = values;
  4240. }
  4241. /**
  4242. * @param {?} visitor
  4243. * @param {?=} context
  4244. * @return {?}
  4245. */
  4246. visit(visitor, context = null) {
  4247. return visitor.visitLiteralMap(this, context);
  4248. }
  4249. }
  4250. class Interpolation extends AST {
  4251. /**
  4252. * @param {?} span
  4253. * @param {?} strings
  4254. * @param {?} expressions
  4255. */
  4256. constructor(span, strings, expressions) {
  4257. super(span);
  4258. this.strings = strings;
  4259. this.expressions = expressions;
  4260. }
  4261. /**
  4262. * @param {?} visitor
  4263. * @param {?=} context
  4264. * @return {?}
  4265. */
  4266. visit(visitor, context = null) {
  4267. return visitor.visitInterpolation(this, context);
  4268. }
  4269. }
  4270. class Binary extends AST {
  4271. /**
  4272. * @param {?} span
  4273. * @param {?} operation
  4274. * @param {?} left
  4275. * @param {?} right
  4276. */
  4277. constructor(span, operation, left, right) {
  4278. super(span);
  4279. this.operation = operation;
  4280. this.left = left;
  4281. this.right = right;
  4282. }
  4283. /**
  4284. * @param {?} visitor
  4285. * @param {?=} context
  4286. * @return {?}
  4287. */
  4288. visit(visitor, context = null) {
  4289. return visitor.visitBinary(this, context);
  4290. }
  4291. }
  4292. class PrefixNot extends AST {
  4293. /**
  4294. * @param {?} span
  4295. * @param {?} expression
  4296. */
  4297. constructor(span, expression) {
  4298. super(span);
  4299. this.expression = expression;
  4300. }
  4301. /**
  4302. * @param {?} visitor
  4303. * @param {?=} context
  4304. * @return {?}
  4305. */
  4306. visit(visitor, context = null) {
  4307. return visitor.visitPrefixNot(this, context);
  4308. }
  4309. }
  4310. class NonNullAssert extends AST {
  4311. /**
  4312. * @param {?} span
  4313. * @param {?} expression
  4314. */
  4315. constructor(span, expression) {
  4316. super(span);
  4317. this.expression = expression;
  4318. }
  4319. /**
  4320. * @param {?} visitor
  4321. * @param {?=} context
  4322. * @return {?}
  4323. */
  4324. visit(visitor, context = null) {
  4325. return visitor.visitNonNullAssert(this, context);
  4326. }
  4327. }
  4328. class MethodCall extends AST {
  4329. /**
  4330. * @param {?} span
  4331. * @param {?} receiver
  4332. * @param {?} name
  4333. * @param {?} args
  4334. */
  4335. constructor(span, receiver, name, args) {
  4336. super(span);
  4337. this.receiver = receiver;
  4338. this.name = name;
  4339. this.args = args;
  4340. }
  4341. /**
  4342. * @param {?} visitor
  4343. * @param {?=} context
  4344. * @return {?}
  4345. */
  4346. visit(visitor, context = null) {
  4347. return visitor.visitMethodCall(this, context);
  4348. }
  4349. }
  4350. class SafeMethodCall extends AST {
  4351. /**
  4352. * @param {?} span
  4353. * @param {?} receiver
  4354. * @param {?} name
  4355. * @param {?} args
  4356. */
  4357. constructor(span, receiver, name, args) {
  4358. super(span);
  4359. this.receiver = receiver;
  4360. this.name = name;
  4361. this.args = args;
  4362. }
  4363. /**
  4364. * @param {?} visitor
  4365. * @param {?=} context
  4366. * @return {?}
  4367. */
  4368. visit(visitor, context = null) {
  4369. return visitor.visitSafeMethodCall(this, context);
  4370. }
  4371. }
  4372. class FunctionCall extends AST {
  4373. /**
  4374. * @param {?} span
  4375. * @param {?} target
  4376. * @param {?} args
  4377. */
  4378. constructor(span, target, args) {
  4379. super(span);
  4380. this.target = target;
  4381. this.args = args;
  4382. }
  4383. /**
  4384. * @param {?} visitor
  4385. * @param {?=} context
  4386. * @return {?}
  4387. */
  4388. visit(visitor, context = null) {
  4389. return visitor.visitFunctionCall(this, context);
  4390. }
  4391. }
  4392. class ASTWithSource extends AST {
  4393. /**
  4394. * @param {?} ast
  4395. * @param {?} source
  4396. * @param {?} location
  4397. * @param {?} errors
  4398. */
  4399. constructor(ast, source, location, errors) {
  4400. super(new ParseSpan(0, source == null ? 0 : source.length));
  4401. this.ast = ast;
  4402. this.source = source;
  4403. this.location = location;
  4404. this.errors = errors;
  4405. }
  4406. /**
  4407. * @param {?} visitor
  4408. * @param {?=} context
  4409. * @return {?}
  4410. */
  4411. visit(visitor, context = null) { return this.ast.visit(visitor, context); }
  4412. /**
  4413. * @return {?}
  4414. */
  4415. toString() { return `${this.source} in ${this.location}`; }
  4416. }
  4417. class TemplateBinding {
  4418. /**
  4419. * @param {?} span
  4420. * @param {?} key
  4421. * @param {?} keyIsVar
  4422. * @param {?} name
  4423. * @param {?} expression
  4424. */
  4425. constructor(span, key, keyIsVar, name, expression) {
  4426. this.span = span;
  4427. this.key = key;
  4428. this.keyIsVar = keyIsVar;
  4429. this.name = name;
  4430. this.expression = expression;
  4431. }
  4432. }
  4433. /**
  4434. * @record
  4435. */
  4436. class NullAstVisitor {
  4437. /**
  4438. * @param {?} ast
  4439. * @param {?} context
  4440. * @return {?}
  4441. */
  4442. visitBinary(ast, context) { }
  4443. /**
  4444. * @param {?} ast
  4445. * @param {?} context
  4446. * @return {?}
  4447. */
  4448. visitChain(ast, context) { }
  4449. /**
  4450. * @param {?} ast
  4451. * @param {?} context
  4452. * @return {?}
  4453. */
  4454. visitConditional(ast, context) { }
  4455. /**
  4456. * @param {?} ast
  4457. * @param {?} context
  4458. * @return {?}
  4459. */
  4460. visitFunctionCall(ast, context) { }
  4461. /**
  4462. * @param {?} ast
  4463. * @param {?} context
  4464. * @return {?}
  4465. */
  4466. visitImplicitReceiver(ast, context) { }
  4467. /**
  4468. * @param {?} ast
  4469. * @param {?} context
  4470. * @return {?}
  4471. */
  4472. visitInterpolation(ast, context) { }
  4473. /**
  4474. * @param {?} ast
  4475. * @param {?} context
  4476. * @return {?}
  4477. */
  4478. visitKeyedRead(ast, context) { }
  4479. /**
  4480. * @param {?} ast
  4481. * @param {?} context
  4482. * @return {?}
  4483. */
  4484. visitKeyedWrite(ast, context) { }
  4485. /**
  4486. * @param {?} ast
  4487. * @param {?} context
  4488. * @return {?}
  4489. */
  4490. visitLiteralArray(ast, context) { }
  4491. /**
  4492. * @param {?} ast
  4493. * @param {?} context
  4494. * @return {?}
  4495. */
  4496. visitLiteralMap(ast, context) { }
  4497. /**
  4498. * @param {?} ast
  4499. * @param {?} context
  4500. * @return {?}
  4501. */
  4502. visitLiteralPrimitive(ast, context) { }
  4503. /**
  4504. * @param {?} ast
  4505. * @param {?} context
  4506. * @return {?}
  4507. */
  4508. visitMethodCall(ast, context) { }
  4509. /**
  4510. * @param {?} ast
  4511. * @param {?} context
  4512. * @return {?}
  4513. */
  4514. visitPipe(ast, context) { }
  4515. /**
  4516. * @param {?} ast
  4517. * @param {?} context
  4518. * @return {?}
  4519. */
  4520. visitPrefixNot(ast, context) { }
  4521. /**
  4522. * @param {?} ast
  4523. * @param {?} context
  4524. * @return {?}
  4525. */
  4526. visitNonNullAssert(ast, context) { }
  4527. /**
  4528. * @param {?} ast
  4529. * @param {?} context
  4530. * @return {?}
  4531. */
  4532. visitPropertyRead(ast, context) { }
  4533. /**
  4534. * @param {?} ast
  4535. * @param {?} context
  4536. * @return {?}
  4537. */
  4538. visitPropertyWrite(ast, context) { }
  4539. /**
  4540. * @param {?} ast
  4541. * @param {?} context
  4542. * @return {?}
  4543. */
  4544. visitQuote(ast, context) { }
  4545. /**
  4546. * @param {?} ast
  4547. * @param {?} context
  4548. * @return {?}
  4549. */
  4550. visitSafeMethodCall(ast, context) { }
  4551. /**
  4552. * @param {?} ast
  4553. * @param {?} context
  4554. * @return {?}
  4555. */
  4556. visitSafePropertyRead(ast, context) { }
  4557. }
  4558. class RecursiveAstVisitor {
  4559. /**
  4560. * @param {?} ast
  4561. * @param {?} context
  4562. * @return {?}
  4563. */
  4564. visitBinary(ast, context) {
  4565. ast.left.visit(this);
  4566. ast.right.visit(this);
  4567. return null;
  4568. }
  4569. /**
  4570. * @param {?} ast
  4571. * @param {?} context
  4572. * @return {?}
  4573. */
  4574. visitChain(ast, context) { return this.visitAll(ast.expressions, context); }
  4575. /**
  4576. * @param {?} ast
  4577. * @param {?} context
  4578. * @return {?}
  4579. */
  4580. visitConditional(ast, context) {
  4581. ast.condition.visit(this);
  4582. ast.trueExp.visit(this);
  4583. ast.falseExp.visit(this);
  4584. return null;
  4585. }
  4586. /**
  4587. * @param {?} ast
  4588. * @param {?} context
  4589. * @return {?}
  4590. */
  4591. visitPipe(ast, context) {
  4592. ast.exp.visit(this);
  4593. this.visitAll(ast.args, context);
  4594. return null;
  4595. }
  4596. /**
  4597. * @param {?} ast
  4598. * @param {?} context
  4599. * @return {?}
  4600. */
  4601. visitFunctionCall(ast, context) {
  4602. /** @type {?} */ ((ast.target)).visit(this);
  4603. this.visitAll(ast.args, context);
  4604. return null;
  4605. }
  4606. /**
  4607. * @param {?} ast
  4608. * @param {?} context
  4609. * @return {?}
  4610. */
  4611. visitImplicitReceiver(ast, context) { return null; }
  4612. /**
  4613. * @param {?} ast
  4614. * @param {?} context
  4615. * @return {?}
  4616. */
  4617. visitInterpolation(ast, context) {
  4618. return this.visitAll(ast.expressions, context);
  4619. }
  4620. /**
  4621. * @param {?} ast
  4622. * @param {?} context
  4623. * @return {?}
  4624. */
  4625. visitKeyedRead(ast, context) {
  4626. ast.obj.visit(this);
  4627. ast.key.visit(this);
  4628. return null;
  4629. }
  4630. /**
  4631. * @param {?} ast
  4632. * @param {?} context
  4633. * @return {?}
  4634. */
  4635. visitKeyedWrite(ast, context) {
  4636. ast.obj.visit(this);
  4637. ast.key.visit(this);
  4638. ast.value.visit(this);
  4639. return null;
  4640. }
  4641. /**
  4642. * @param {?} ast
  4643. * @param {?} context
  4644. * @return {?}
  4645. */
  4646. visitLiteralArray(ast, context) {
  4647. return this.visitAll(ast.expressions, context);
  4648. }
  4649. /**
  4650. * @param {?} ast
  4651. * @param {?} context
  4652. * @return {?}
  4653. */
  4654. visitLiteralMap(ast, context) { return this.visitAll(ast.values, context); }
  4655. /**
  4656. * @param {?} ast
  4657. * @param {?} context
  4658. * @return {?}
  4659. */
  4660. visitLiteralPrimitive(ast, context) { return null; }
  4661. /**
  4662. * @param {?} ast
  4663. * @param {?} context
  4664. * @return {?}
  4665. */
  4666. visitMethodCall(ast, context) {
  4667. ast.receiver.visit(this);
  4668. return this.visitAll(ast.args, context);
  4669. }
  4670. /**
  4671. * @param {?} ast
  4672. * @param {?} context
  4673. * @return {?}
  4674. */
  4675. visitPrefixNot(ast, context) {
  4676. ast.expression.visit(this);
  4677. return null;
  4678. }
  4679. /**
  4680. * @param {?} ast
  4681. * @param {?} context
  4682. * @return {?}
  4683. */
  4684. visitNonNullAssert(ast, context) {
  4685. ast.expression.visit(this);
  4686. return null;
  4687. }
  4688. /**
  4689. * @param {?} ast
  4690. * @param {?} context
  4691. * @return {?}
  4692. */
  4693. visitPropertyRead(ast, context) {
  4694. ast.receiver.visit(this);
  4695. return null;
  4696. }
  4697. /**
  4698. * @param {?} ast
  4699. * @param {?} context
  4700. * @return {?}
  4701. */
  4702. visitPropertyWrite(ast, context) {
  4703. ast.receiver.visit(this);
  4704. ast.value.visit(this);
  4705. return null;
  4706. }
  4707. /**
  4708. * @param {?} ast
  4709. * @param {?} context
  4710. * @return {?}
  4711. */
  4712. visitSafePropertyRead(ast, context) {
  4713. ast.receiver.visit(this);
  4714. return null;
  4715. }
  4716. /**
  4717. * @param {?} ast
  4718. * @param {?} context
  4719. * @return {?}
  4720. */
  4721. visitSafeMethodCall(ast, context) {
  4722. ast.receiver.visit(this);
  4723. return this.visitAll(ast.args, context);
  4724. }
  4725. /**
  4726. * @param {?} asts
  4727. * @param {?} context
  4728. * @return {?}
  4729. */
  4730. visitAll(asts, context) {
  4731. asts.forEach(ast => ast.visit(this, context));
  4732. return null;
  4733. }
  4734. /**
  4735. * @param {?} ast
  4736. * @param {?} context
  4737. * @return {?}
  4738. */
  4739. visitQuote(ast, context) { return null; }
  4740. }
  4741. class AstTransformer {
  4742. /**
  4743. * @param {?} ast
  4744. * @param {?} context
  4745. * @return {?}
  4746. */
  4747. visitImplicitReceiver(ast, context) { return ast; }
  4748. /**
  4749. * @param {?} ast
  4750. * @param {?} context
  4751. * @return {?}
  4752. */
  4753. visitInterpolation(ast, context) {
  4754. return new Interpolation(ast.span, ast.strings, this.visitAll(ast.expressions));
  4755. }
  4756. /**
  4757. * @param {?} ast
  4758. * @param {?} context
  4759. * @return {?}
  4760. */
  4761. visitLiteralPrimitive(ast, context) {
  4762. return new LiteralPrimitive(ast.span, ast.value);
  4763. }
  4764. /**
  4765. * @param {?} ast
  4766. * @param {?} context
  4767. * @return {?}
  4768. */
  4769. visitPropertyRead(ast, context) {
  4770. return new PropertyRead(ast.span, ast.receiver.visit(this), ast.name);
  4771. }
  4772. /**
  4773. * @param {?} ast
  4774. * @param {?} context
  4775. * @return {?}
  4776. */
  4777. visitPropertyWrite(ast, context) {
  4778. return new PropertyWrite(ast.span, ast.receiver.visit(this), ast.name, ast.value.visit(this));
  4779. }
  4780. /**
  4781. * @param {?} ast
  4782. * @param {?} context
  4783. * @return {?}
  4784. */
  4785. visitSafePropertyRead(ast, context) {
  4786. return new SafePropertyRead(ast.span, ast.receiver.visit(this), ast.name);
  4787. }
  4788. /**
  4789. * @param {?} ast
  4790. * @param {?} context
  4791. * @return {?}
  4792. */
  4793. visitMethodCall(ast, context) {
  4794. return new MethodCall(ast.span, ast.receiver.visit(this), ast.name, this.visitAll(ast.args));
  4795. }
  4796. /**
  4797. * @param {?} ast
  4798. * @param {?} context
  4799. * @return {?}
  4800. */
  4801. visitSafeMethodCall(ast, context) {
  4802. return new SafeMethodCall(ast.span, ast.receiver.visit(this), ast.name, this.visitAll(ast.args));
  4803. }
  4804. /**
  4805. * @param {?} ast
  4806. * @param {?} context
  4807. * @return {?}
  4808. */
  4809. visitFunctionCall(ast, context) {
  4810. return new FunctionCall(ast.span, /** @type {?} */ ((ast.target)).visit(this), this.visitAll(ast.args));
  4811. }
  4812. /**
  4813. * @param {?} ast
  4814. * @param {?} context
  4815. * @return {?}
  4816. */
  4817. visitLiteralArray(ast, context) {
  4818. return new LiteralArray(ast.span, this.visitAll(ast.expressions));
  4819. }
  4820. /**
  4821. * @param {?} ast
  4822. * @param {?} context
  4823. * @return {?}
  4824. */
  4825. visitLiteralMap(ast, context) {
  4826. return new LiteralMap(ast.span, ast.keys, this.visitAll(ast.values));
  4827. }
  4828. /**
  4829. * @param {?} ast
  4830. * @param {?} context
  4831. * @return {?}
  4832. */
  4833. visitBinary(ast, context) {
  4834. return new Binary(ast.span, ast.operation, ast.left.visit(this), ast.right.visit(this));
  4835. }
  4836. /**
  4837. * @param {?} ast
  4838. * @param {?} context
  4839. * @return {?}
  4840. */
  4841. visitPrefixNot(ast, context) {
  4842. return new PrefixNot(ast.span, ast.expression.visit(this));
  4843. }
  4844. /**
  4845. * @param {?} ast
  4846. * @param {?} context
  4847. * @return {?}
  4848. */
  4849. visitNonNullAssert(ast, context) {
  4850. return new NonNullAssert(ast.span, ast.expression.visit(this));
  4851. }
  4852. /**
  4853. * @param {?} ast
  4854. * @param {?} context
  4855. * @return {?}
  4856. */
  4857. visitConditional(ast, context) {
  4858. return new Conditional(ast.span, ast.condition.visit(this), ast.trueExp.visit(this), ast.falseExp.visit(this));
  4859. }
  4860. /**
  4861. * @param {?} ast
  4862. * @param {?} context
  4863. * @return {?}
  4864. */
  4865. visitPipe(ast, context) {
  4866. return new BindingPipe(ast.span, ast.exp.visit(this), ast.name, this.visitAll(ast.args));
  4867. }
  4868. /**
  4869. * @param {?} ast
  4870. * @param {?} context
  4871. * @return {?}
  4872. */
  4873. visitKeyedRead(ast, context) {
  4874. return new KeyedRead(ast.span, ast.obj.visit(this), ast.key.visit(this));
  4875. }
  4876. /**
  4877. * @param {?} ast
  4878. * @param {?} context
  4879. * @return {?}
  4880. */
  4881. visitKeyedWrite(ast, context) {
  4882. return new KeyedWrite(ast.span, ast.obj.visit(this), ast.key.visit(this), ast.value.visit(this));
  4883. }
  4884. /**
  4885. * @param {?} asts
  4886. * @return {?}
  4887. */
  4888. visitAll(asts) {
  4889. const /** @type {?} */ res = new Array(asts.length);
  4890. for (let /** @type {?} */ i = 0; i < asts.length; ++i) {
  4891. res[i] = asts[i].visit(this);
  4892. }
  4893. return res;
  4894. }
  4895. /**
  4896. * @param {?} ast
  4897. * @param {?} context
  4898. * @return {?}
  4899. */
  4900. visitChain(ast, context) {
  4901. return new Chain(ast.span, this.visitAll(ast.expressions));
  4902. }
  4903. /**
  4904. * @param {?} ast
  4905. * @param {?} context
  4906. * @return {?}
  4907. */
  4908. visitQuote(ast, context) {
  4909. return new Quote(ast.span, ast.prefix, ast.uninterpretedExpression, ast.location);
  4910. }
  4911. }
  4912. /**
  4913. * @param {?} ast
  4914. * @param {?} visitor
  4915. * @param {?=} context
  4916. * @return {?}
  4917. */
  4918. function visitAstChildren(ast, visitor, context) {
  4919. /**
  4920. * @param {?} ast
  4921. * @return {?}
  4922. */
  4923. function visit(ast) {
  4924. visitor.visit && visitor.visit(ast, context) || ast.visit(visitor, context);
  4925. }
  4926. /**
  4927. * @template T
  4928. * @param {?} asts
  4929. * @return {?}
  4930. */
  4931. function visitAll(asts) { asts.forEach(visit); }
  4932. ast.visit({
  4933. /**
  4934. * @param {?} ast
  4935. * @return {?}
  4936. */
  4937. visitBinary(ast) {
  4938. visit(ast.left);
  4939. visit(ast.right);
  4940. },
  4941. /**
  4942. * @param {?} ast
  4943. * @return {?}
  4944. */
  4945. visitChain(ast) { visitAll(ast.expressions); },
  4946. /**
  4947. * @param {?} ast
  4948. * @return {?}
  4949. */
  4950. visitConditional(ast) {
  4951. visit(ast.condition);
  4952. visit(ast.trueExp);
  4953. visit(ast.falseExp);
  4954. },
  4955. /**
  4956. * @param {?} ast
  4957. * @return {?}
  4958. */
  4959. visitFunctionCall(ast) {
  4960. if (ast.target) {
  4961. visit(ast.target);
  4962. }
  4963. visitAll(ast.args);
  4964. },
  4965. /**
  4966. * @param {?} ast
  4967. * @return {?}
  4968. */
  4969. visitImplicitReceiver(ast) { },
  4970. /**
  4971. * @param {?} ast
  4972. * @return {?}
  4973. */
  4974. visitInterpolation(ast) { visitAll(ast.expressions); },
  4975. /**
  4976. * @param {?} ast
  4977. * @return {?}
  4978. */
  4979. visitKeyedRead(ast) {
  4980. visit(ast.obj);
  4981. visit(ast.key);
  4982. },
  4983. /**
  4984. * @param {?} ast
  4985. * @return {?}
  4986. */
  4987. visitKeyedWrite(ast) {
  4988. visit(ast.obj);
  4989. visit(ast.key);
  4990. visit(ast.obj);
  4991. },
  4992. /**
  4993. * @param {?} ast
  4994. * @return {?}
  4995. */
  4996. visitLiteralArray(ast) { visitAll(ast.expressions); },
  4997. /**
  4998. * @param {?} ast
  4999. * @return {?}
  5000. */
  5001. visitLiteralMap(ast) { },
  5002. /**
  5003. * @param {?} ast
  5004. * @return {?}
  5005. */
  5006. visitLiteralPrimitive(ast) { },
  5007. /**
  5008. * @param {?} ast
  5009. * @return {?}
  5010. */
  5011. visitMethodCall(ast) {
  5012. visit(ast.receiver);
  5013. visitAll(ast.args);
  5014. },
  5015. /**
  5016. * @param {?} ast
  5017. * @return {?}
  5018. */
  5019. visitPipe(ast) {
  5020. visit(ast.exp);
  5021. visitAll(ast.args);
  5022. },
  5023. /**
  5024. * @param {?} ast
  5025. * @return {?}
  5026. */
  5027. visitPrefixNot(ast) { visit(ast.expression); },
  5028. /**
  5029. * @param {?} ast
  5030. * @return {?}
  5031. */
  5032. visitNonNullAssert(ast) { visit(ast.expression); },
  5033. /**
  5034. * @param {?} ast
  5035. * @return {?}
  5036. */
  5037. visitPropertyRead(ast) { visit(ast.receiver); },
  5038. /**
  5039. * @param {?} ast
  5040. * @return {?}
  5041. */
  5042. visitPropertyWrite(ast) {
  5043. visit(ast.receiver);
  5044. visit(ast.value);
  5045. },
  5046. /**
  5047. * @param {?} ast
  5048. * @return {?}
  5049. */
  5050. visitQuote(ast) { },
  5051. /**
  5052. * @param {?} ast
  5053. * @return {?}
  5054. */
  5055. visitSafeMethodCall(ast) {
  5056. visit(ast.receiver);
  5057. visitAll(ast.args);
  5058. },
  5059. /**
  5060. * @param {?} ast
  5061. * @return {?}
  5062. */
  5063. visitSafePropertyRead(ast) { visit(ast.receiver); },
  5064. });
  5065. }
  5066. /**
  5067. * @fileoverview added by tsickle
  5068. * @suppress {checkTypes} checked by tsc
  5069. */
  5070. /**
  5071. * @license
  5072. * Copyright Google Inc. All Rights Reserved.
  5073. *
  5074. * Use of this source code is governed by an MIT-style license that can be
  5075. * found in the LICENSE file at https://angular.io/license
  5076. */
  5077. class SplitInterpolation {
  5078. /**
  5079. * @param {?} strings
  5080. * @param {?} expressions
  5081. * @param {?} offsets
  5082. */
  5083. constructor(strings, expressions, offsets) {
  5084. this.strings = strings;
  5085. this.expressions = expressions;
  5086. this.offsets = offsets;
  5087. }
  5088. }
  5089. class TemplateBindingParseResult {
  5090. /**
  5091. * @param {?} templateBindings
  5092. * @param {?} warnings
  5093. * @param {?} errors
  5094. */
  5095. constructor(templateBindings, warnings, errors) {
  5096. this.templateBindings = templateBindings;
  5097. this.warnings = warnings;
  5098. this.errors = errors;
  5099. }
  5100. }
  5101. /**
  5102. * @param {?} config
  5103. * @return {?}
  5104. */
  5105. function _createInterpolateRegExp(config) {
  5106. const /** @type {?} */ pattern = escapeRegExp(config.start) + '([\\s\\S]*?)' + escapeRegExp(config.end);
  5107. return new RegExp(pattern, 'g');
  5108. }
  5109. class Parser {
  5110. /**
  5111. * @param {?} _lexer
  5112. */
  5113. constructor(_lexer) {
  5114. this._lexer = _lexer;
  5115. this.errors = [];
  5116. }
  5117. /**
  5118. * @param {?} input
  5119. * @param {?} location
  5120. * @param {?=} interpolationConfig
  5121. * @return {?}
  5122. */
  5123. parseAction(input, location, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  5124. this._checkNoInterpolation(input, location, interpolationConfig);
  5125. const /** @type {?} */ sourceToLex = this._stripComments(input);
  5126. const /** @type {?} */ tokens = this._lexer.tokenize(this._stripComments(input));
  5127. const /** @type {?} */ ast = new _ParseAST(input, location, tokens, sourceToLex.length, true, this.errors, input.length - sourceToLex.length)
  5128. .parseChain();
  5129. return new ASTWithSource(ast, input, location, this.errors);
  5130. }
  5131. /**
  5132. * @param {?} input
  5133. * @param {?} location
  5134. * @param {?=} interpolationConfig
  5135. * @return {?}
  5136. */
  5137. parseBinding(input, location, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  5138. const /** @type {?} */ ast = this._parseBindingAst(input, location, interpolationConfig);
  5139. return new ASTWithSource(ast, input, location, this.errors);
  5140. }
  5141. /**
  5142. * @param {?} input
  5143. * @param {?} location
  5144. * @param {?=} interpolationConfig
  5145. * @return {?}
  5146. */
  5147. parseSimpleBinding(input, location, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  5148. const /** @type {?} */ ast = this._parseBindingAst(input, location, interpolationConfig);
  5149. const /** @type {?} */ errors = SimpleExpressionChecker.check(ast);
  5150. if (errors.length > 0) {
  5151. this._reportError(`Host binding expression cannot contain ${errors.join(' ')}`, input, location);
  5152. }
  5153. return new ASTWithSource(ast, input, location, this.errors);
  5154. }
  5155. /**
  5156. * @param {?} message
  5157. * @param {?} input
  5158. * @param {?} errLocation
  5159. * @param {?=} ctxLocation
  5160. * @return {?}
  5161. */
  5162. _reportError(message, input, errLocation, ctxLocation) {
  5163. this.errors.push(new ParserError(message, input, errLocation, ctxLocation));
  5164. }
  5165. /**
  5166. * @param {?} input
  5167. * @param {?} location
  5168. * @param {?} interpolationConfig
  5169. * @return {?}
  5170. */
  5171. _parseBindingAst(input, location, interpolationConfig) {
  5172. // Quotes expressions use 3rd-party expression language. We don't want to use
  5173. // our lexer or parser for that, so we check for that ahead of time.
  5174. const /** @type {?} */ quote = this._parseQuote(input, location);
  5175. if (quote != null) {
  5176. return quote;
  5177. }
  5178. this._checkNoInterpolation(input, location, interpolationConfig);
  5179. const /** @type {?} */ sourceToLex = this._stripComments(input);
  5180. const /** @type {?} */ tokens = this._lexer.tokenize(sourceToLex);
  5181. return new _ParseAST(input, location, tokens, sourceToLex.length, false, this.errors, input.length - sourceToLex.length)
  5182. .parseChain();
  5183. }
  5184. /**
  5185. * @param {?} input
  5186. * @param {?} location
  5187. * @return {?}
  5188. */
  5189. _parseQuote(input, location) {
  5190. if (input == null)
  5191. return null;
  5192. const /** @type {?} */ prefixSeparatorIndex = input.indexOf(':');
  5193. if (prefixSeparatorIndex == -1)
  5194. return null;
  5195. const /** @type {?} */ prefix = input.substring(0, prefixSeparatorIndex).trim();
  5196. if (!isIdentifier(prefix))
  5197. return null;
  5198. const /** @type {?} */ uninterpretedExpression = input.substring(prefixSeparatorIndex + 1);
  5199. return new Quote(new ParseSpan(0, input.length), prefix, uninterpretedExpression, location);
  5200. }
  5201. /**
  5202. * @param {?} prefixToken
  5203. * @param {?} input
  5204. * @param {?} location
  5205. * @return {?}
  5206. */
  5207. parseTemplateBindings(prefixToken, input, location) {
  5208. const /** @type {?} */ tokens = this._lexer.tokenize(input);
  5209. if (prefixToken) {
  5210. // Prefix the tokens with the tokens from prefixToken but have them take no space (0 index).
  5211. const /** @type {?} */ prefixTokens = this._lexer.tokenize(prefixToken).map(t => {
  5212. t.index = 0;
  5213. return t;
  5214. });
  5215. tokens.unshift(...prefixTokens);
  5216. }
  5217. return new _ParseAST(input, location, tokens, input.length, false, this.errors, 0)
  5218. .parseTemplateBindings();
  5219. }
  5220. /**
  5221. * @param {?} input
  5222. * @param {?} location
  5223. * @param {?=} interpolationConfig
  5224. * @return {?}
  5225. */
  5226. parseInterpolation(input, location, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  5227. const /** @type {?} */ split = this.splitInterpolation(input, location, interpolationConfig);
  5228. if (split == null)
  5229. return null;
  5230. const /** @type {?} */ expressions = [];
  5231. for (let /** @type {?} */ i = 0; i < split.expressions.length; ++i) {
  5232. const /** @type {?} */ expressionText = split.expressions[i];
  5233. const /** @type {?} */ sourceToLex = this._stripComments(expressionText);
  5234. const /** @type {?} */ tokens = this._lexer.tokenize(sourceToLex);
  5235. const /** @type {?} */ ast = new _ParseAST(input, location, tokens, sourceToLex.length, false, this.errors, split.offsets[i] + (expressionText.length - sourceToLex.length))
  5236. .parseChain();
  5237. expressions.push(ast);
  5238. }
  5239. return new ASTWithSource(new Interpolation(new ParseSpan(0, input == null ? 0 : input.length), split.strings, expressions), input, location, this.errors);
  5240. }
  5241. /**
  5242. * @param {?} input
  5243. * @param {?} location
  5244. * @param {?=} interpolationConfig
  5245. * @return {?}
  5246. */
  5247. splitInterpolation(input, location, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  5248. const /** @type {?} */ regexp = _createInterpolateRegExp(interpolationConfig);
  5249. const /** @type {?} */ parts = input.split(regexp);
  5250. if (parts.length <= 1) {
  5251. return null;
  5252. }
  5253. const /** @type {?} */ strings = [];
  5254. const /** @type {?} */ expressions = [];
  5255. const /** @type {?} */ offsets = [];
  5256. let /** @type {?} */ offset = 0;
  5257. for (let /** @type {?} */ i = 0; i < parts.length; i++) {
  5258. const /** @type {?} */ part = parts[i];
  5259. if (i % 2 === 0) {
  5260. // fixed string
  5261. strings.push(part);
  5262. offset += part.length;
  5263. }
  5264. else if (part.trim().length > 0) {
  5265. offset += interpolationConfig.start.length;
  5266. expressions.push(part);
  5267. offsets.push(offset);
  5268. offset += part.length + interpolationConfig.end.length;
  5269. }
  5270. else {
  5271. this._reportError('Blank expressions are not allowed in interpolated strings', input, `at column ${this._findInterpolationErrorColumn(parts, i, interpolationConfig)} in`, location);
  5272. expressions.push('$implict');
  5273. offsets.push(offset);
  5274. }
  5275. }
  5276. return new SplitInterpolation(strings, expressions, offsets);
  5277. }
  5278. /**
  5279. * @param {?} input
  5280. * @param {?} location
  5281. * @return {?}
  5282. */
  5283. wrapLiteralPrimitive(input, location) {
  5284. return new ASTWithSource(new LiteralPrimitive(new ParseSpan(0, input == null ? 0 : input.length), input), input, location, this.errors);
  5285. }
  5286. /**
  5287. * @param {?} input
  5288. * @return {?}
  5289. */
  5290. _stripComments(input) {
  5291. const /** @type {?} */ i = this._commentStart(input);
  5292. return i != null ? input.substring(0, i).trim() : input;
  5293. }
  5294. /**
  5295. * @param {?} input
  5296. * @return {?}
  5297. */
  5298. _commentStart(input) {
  5299. let /** @type {?} */ outerQuote = null;
  5300. for (let /** @type {?} */ i = 0; i < input.length - 1; i++) {
  5301. const /** @type {?} */ char = input.charCodeAt(i);
  5302. const /** @type {?} */ nextChar = input.charCodeAt(i + 1);
  5303. if (char === $SLASH && nextChar == $SLASH && outerQuote == null)
  5304. return i;
  5305. if (outerQuote === char) {
  5306. outerQuote = null;
  5307. }
  5308. else if (outerQuote == null && isQuote(char)) {
  5309. outerQuote = char;
  5310. }
  5311. }
  5312. return null;
  5313. }
  5314. /**
  5315. * @param {?} input
  5316. * @param {?} location
  5317. * @param {?} interpolationConfig
  5318. * @return {?}
  5319. */
  5320. _checkNoInterpolation(input, location, interpolationConfig) {
  5321. const /** @type {?} */ regexp = _createInterpolateRegExp(interpolationConfig);
  5322. const /** @type {?} */ parts = input.split(regexp);
  5323. if (parts.length > 1) {
  5324. this._reportError(`Got interpolation (${interpolationConfig.start}${interpolationConfig.end}) where expression was expected`, input, `at column ${this._findInterpolationErrorColumn(parts, 1, interpolationConfig)} in`, location);
  5325. }
  5326. }
  5327. /**
  5328. * @param {?} parts
  5329. * @param {?} partInErrIdx
  5330. * @param {?} interpolationConfig
  5331. * @return {?}
  5332. */
  5333. _findInterpolationErrorColumn(parts, partInErrIdx, interpolationConfig) {
  5334. let /** @type {?} */ errLocation = '';
  5335. for (let /** @type {?} */ j = 0; j < partInErrIdx; j++) {
  5336. errLocation += j % 2 === 0 ?
  5337. parts[j] :
  5338. `${interpolationConfig.start}${parts[j]}${interpolationConfig.end}`;
  5339. }
  5340. return errLocation.length;
  5341. }
  5342. }
  5343. class _ParseAST {
  5344. /**
  5345. * @param {?} input
  5346. * @param {?} location
  5347. * @param {?} tokens
  5348. * @param {?} inputLength
  5349. * @param {?} parseAction
  5350. * @param {?} errors
  5351. * @param {?} offset
  5352. */
  5353. constructor(input, location, tokens, inputLength, parseAction, errors, offset) {
  5354. this.input = input;
  5355. this.location = location;
  5356. this.tokens = tokens;
  5357. this.inputLength = inputLength;
  5358. this.parseAction = parseAction;
  5359. this.errors = errors;
  5360. this.offset = offset;
  5361. this.rparensExpected = 0;
  5362. this.rbracketsExpected = 0;
  5363. this.rbracesExpected = 0;
  5364. this.index = 0;
  5365. }
  5366. /**
  5367. * @param {?} offset
  5368. * @return {?}
  5369. */
  5370. peek(offset) {
  5371. const /** @type {?} */ i = this.index + offset;
  5372. return i < this.tokens.length ? this.tokens[i] : EOF;
  5373. }
  5374. /**
  5375. * @return {?}
  5376. */
  5377. get next() { return this.peek(0); }
  5378. /**
  5379. * @return {?}
  5380. */
  5381. get inputIndex() {
  5382. return (this.index < this.tokens.length) ? this.next.index + this.offset :
  5383. this.inputLength + this.offset;
  5384. }
  5385. /**
  5386. * @param {?} start
  5387. * @return {?}
  5388. */
  5389. span(start) { return new ParseSpan(start, this.inputIndex); }
  5390. /**
  5391. * @return {?}
  5392. */
  5393. advance() { this.index++; }
  5394. /**
  5395. * @param {?} code
  5396. * @return {?}
  5397. */
  5398. optionalCharacter(code) {
  5399. if (this.next.isCharacter(code)) {
  5400. this.advance();
  5401. return true;
  5402. }
  5403. else {
  5404. return false;
  5405. }
  5406. }
  5407. /**
  5408. * @return {?}
  5409. */
  5410. peekKeywordLet() { return this.next.isKeywordLet(); }
  5411. /**
  5412. * @return {?}
  5413. */
  5414. peekKeywordAs() { return this.next.isKeywordAs(); }
  5415. /**
  5416. * @param {?} code
  5417. * @return {?}
  5418. */
  5419. expectCharacter(code) {
  5420. if (this.optionalCharacter(code))
  5421. return;
  5422. this.error(`Missing expected ${String.fromCharCode(code)}`);
  5423. }
  5424. /**
  5425. * @param {?} op
  5426. * @return {?}
  5427. */
  5428. optionalOperator(op) {
  5429. if (this.next.isOperator(op)) {
  5430. this.advance();
  5431. return true;
  5432. }
  5433. else {
  5434. return false;
  5435. }
  5436. }
  5437. /**
  5438. * @param {?} operator
  5439. * @return {?}
  5440. */
  5441. expectOperator(operator) {
  5442. if (this.optionalOperator(operator))
  5443. return;
  5444. this.error(`Missing expected operator ${operator}`);
  5445. }
  5446. /**
  5447. * @return {?}
  5448. */
  5449. expectIdentifierOrKeyword() {
  5450. const /** @type {?} */ n = this.next;
  5451. if (!n.isIdentifier() && !n.isKeyword()) {
  5452. this.error(`Unexpected token ${n}, expected identifier or keyword`);
  5453. return '';
  5454. }
  5455. this.advance();
  5456. return /** @type {?} */ (n.toString());
  5457. }
  5458. /**
  5459. * @return {?}
  5460. */
  5461. expectIdentifierOrKeywordOrString() {
  5462. const /** @type {?} */ n = this.next;
  5463. if (!n.isIdentifier() && !n.isKeyword() && !n.isString()) {
  5464. this.error(`Unexpected token ${n}, expected identifier, keyword, or string`);
  5465. return '';
  5466. }
  5467. this.advance();
  5468. return /** @type {?} */ (n.toString());
  5469. }
  5470. /**
  5471. * @return {?}
  5472. */
  5473. parseChain() {
  5474. const /** @type {?} */ exprs = [];
  5475. const /** @type {?} */ start = this.inputIndex;
  5476. while (this.index < this.tokens.length) {
  5477. const /** @type {?} */ expr = this.parsePipe();
  5478. exprs.push(expr);
  5479. if (this.optionalCharacter($SEMICOLON)) {
  5480. if (!this.parseAction) {
  5481. this.error('Binding expression cannot contain chained expression');
  5482. }
  5483. while (this.optionalCharacter($SEMICOLON)) {
  5484. } // read all semicolons
  5485. }
  5486. else if (this.index < this.tokens.length) {
  5487. this.error(`Unexpected token '${this.next}'`);
  5488. }
  5489. }
  5490. if (exprs.length == 0)
  5491. return new EmptyExpr(this.span(start));
  5492. if (exprs.length == 1)
  5493. return exprs[0];
  5494. return new Chain(this.span(start), exprs);
  5495. }
  5496. /**
  5497. * @return {?}
  5498. */
  5499. parsePipe() {
  5500. let /** @type {?} */ result = this.parseExpression();
  5501. if (this.optionalOperator('|')) {
  5502. if (this.parseAction) {
  5503. this.error('Cannot have a pipe in an action expression');
  5504. }
  5505. do {
  5506. const /** @type {?} */ name = this.expectIdentifierOrKeyword();
  5507. const /** @type {?} */ args = [];
  5508. while (this.optionalCharacter($COLON)) {
  5509. args.push(this.parseExpression());
  5510. }
  5511. result = new BindingPipe(this.span(result.span.start), result, name, args);
  5512. } while (this.optionalOperator('|'));
  5513. }
  5514. return result;
  5515. }
  5516. /**
  5517. * @return {?}
  5518. */
  5519. parseExpression() { return this.parseConditional(); }
  5520. /**
  5521. * @return {?}
  5522. */
  5523. parseConditional() {
  5524. const /** @type {?} */ start = this.inputIndex;
  5525. const /** @type {?} */ result = this.parseLogicalOr();
  5526. if (this.optionalOperator('?')) {
  5527. const /** @type {?} */ yes = this.parsePipe();
  5528. let /** @type {?} */ no;
  5529. if (!this.optionalCharacter($COLON)) {
  5530. const /** @type {?} */ end = this.inputIndex;
  5531. const /** @type {?} */ expression = this.input.substring(start, end);
  5532. this.error(`Conditional expression ${expression} requires all 3 expressions`);
  5533. no = new EmptyExpr(this.span(start));
  5534. }
  5535. else {
  5536. no = this.parsePipe();
  5537. }
  5538. return new Conditional(this.span(start), result, yes, no);
  5539. }
  5540. else {
  5541. return result;
  5542. }
  5543. }
  5544. /**
  5545. * @return {?}
  5546. */
  5547. parseLogicalOr() {
  5548. // '||'
  5549. let /** @type {?} */ result = this.parseLogicalAnd();
  5550. while (this.optionalOperator('||')) {
  5551. const /** @type {?} */ right = this.parseLogicalAnd();
  5552. result = new Binary(this.span(result.span.start), '||', result, right);
  5553. }
  5554. return result;
  5555. }
  5556. /**
  5557. * @return {?}
  5558. */
  5559. parseLogicalAnd() {
  5560. // '&&'
  5561. let /** @type {?} */ result = this.parseEquality();
  5562. while (this.optionalOperator('&&')) {
  5563. const /** @type {?} */ right = this.parseEquality();
  5564. result = new Binary(this.span(result.span.start), '&&', result, right);
  5565. }
  5566. return result;
  5567. }
  5568. /**
  5569. * @return {?}
  5570. */
  5571. parseEquality() {
  5572. // '==','!=','===','!=='
  5573. let /** @type {?} */ result = this.parseRelational();
  5574. while (this.next.type == TokenType.Operator) {
  5575. const /** @type {?} */ operator = this.next.strValue;
  5576. switch (operator) {
  5577. case '==':
  5578. case '===':
  5579. case '!=':
  5580. case '!==':
  5581. this.advance();
  5582. const /** @type {?} */ right = this.parseRelational();
  5583. result = new Binary(this.span(result.span.start), operator, result, right);
  5584. continue;
  5585. }
  5586. break;
  5587. }
  5588. return result;
  5589. }
  5590. /**
  5591. * @return {?}
  5592. */
  5593. parseRelational() {
  5594. // '<', '>', '<=', '>='
  5595. let /** @type {?} */ result = this.parseAdditive();
  5596. while (this.next.type == TokenType.Operator) {
  5597. const /** @type {?} */ operator = this.next.strValue;
  5598. switch (operator) {
  5599. case '<':
  5600. case '>':
  5601. case '<=':
  5602. case '>=':
  5603. this.advance();
  5604. const /** @type {?} */ right = this.parseAdditive();
  5605. result = new Binary(this.span(result.span.start), operator, result, right);
  5606. continue;
  5607. }
  5608. break;
  5609. }
  5610. return result;
  5611. }
  5612. /**
  5613. * @return {?}
  5614. */
  5615. parseAdditive() {
  5616. // '+', '-'
  5617. let /** @type {?} */ result = this.parseMultiplicative();
  5618. while (this.next.type == TokenType.Operator) {
  5619. const /** @type {?} */ operator = this.next.strValue;
  5620. switch (operator) {
  5621. case '+':
  5622. case '-':
  5623. this.advance();
  5624. let /** @type {?} */ right = this.parseMultiplicative();
  5625. result = new Binary(this.span(result.span.start), operator, result, right);
  5626. continue;
  5627. }
  5628. break;
  5629. }
  5630. return result;
  5631. }
  5632. /**
  5633. * @return {?}
  5634. */
  5635. parseMultiplicative() {
  5636. // '*', '%', '/'
  5637. let /** @type {?} */ result = this.parsePrefix();
  5638. while (this.next.type == TokenType.Operator) {
  5639. const /** @type {?} */ operator = this.next.strValue;
  5640. switch (operator) {
  5641. case '*':
  5642. case '%':
  5643. case '/':
  5644. this.advance();
  5645. let /** @type {?} */ right = this.parsePrefix();
  5646. result = new Binary(this.span(result.span.start), operator, result, right);
  5647. continue;
  5648. }
  5649. break;
  5650. }
  5651. return result;
  5652. }
  5653. /**
  5654. * @return {?}
  5655. */
  5656. parsePrefix() {
  5657. if (this.next.type == TokenType.Operator) {
  5658. const /** @type {?} */ start = this.inputIndex;
  5659. const /** @type {?} */ operator = this.next.strValue;
  5660. let /** @type {?} */ result;
  5661. switch (operator) {
  5662. case '+':
  5663. this.advance();
  5664. result = this.parsePrefix();
  5665. return new Binary(this.span(start), '-', result, new LiteralPrimitive(new ParseSpan(start, start), 0));
  5666. case '-':
  5667. this.advance();
  5668. result = this.parsePrefix();
  5669. return new Binary(this.span(start), operator, new LiteralPrimitive(new ParseSpan(start, start), 0), result);
  5670. case '!':
  5671. this.advance();
  5672. result = this.parsePrefix();
  5673. return new PrefixNot(this.span(start), result);
  5674. }
  5675. }
  5676. return this.parseCallChain();
  5677. }
  5678. /**
  5679. * @return {?}
  5680. */
  5681. parseCallChain() {
  5682. let /** @type {?} */ result = this.parsePrimary();
  5683. while (true) {
  5684. if (this.optionalCharacter($PERIOD)) {
  5685. result = this.parseAccessMemberOrMethodCall(result, false);
  5686. }
  5687. else if (this.optionalOperator('?.')) {
  5688. result = this.parseAccessMemberOrMethodCall(result, true);
  5689. }
  5690. else if (this.optionalCharacter($LBRACKET)) {
  5691. this.rbracketsExpected++;
  5692. const /** @type {?} */ key = this.parsePipe();
  5693. this.rbracketsExpected--;
  5694. this.expectCharacter($RBRACKET);
  5695. if (this.optionalOperator('=')) {
  5696. const /** @type {?} */ value = this.parseConditional();
  5697. result = new KeyedWrite(this.span(result.span.start), result, key, value);
  5698. }
  5699. else {
  5700. result = new KeyedRead(this.span(result.span.start), result, key);
  5701. }
  5702. }
  5703. else if (this.optionalCharacter($LPAREN)) {
  5704. this.rparensExpected++;
  5705. const /** @type {?} */ args = this.parseCallArguments();
  5706. this.rparensExpected--;
  5707. this.expectCharacter($RPAREN);
  5708. result = new FunctionCall(this.span(result.span.start), result, args);
  5709. }
  5710. else if (this.optionalOperator('!')) {
  5711. result = new NonNullAssert(this.span(result.span.start), result);
  5712. }
  5713. else {
  5714. return result;
  5715. }
  5716. }
  5717. }
  5718. /**
  5719. * @return {?}
  5720. */
  5721. parsePrimary() {
  5722. const /** @type {?} */ start = this.inputIndex;
  5723. if (this.optionalCharacter($LPAREN)) {
  5724. this.rparensExpected++;
  5725. const /** @type {?} */ result = this.parsePipe();
  5726. this.rparensExpected--;
  5727. this.expectCharacter($RPAREN);
  5728. return result;
  5729. }
  5730. else if (this.next.isKeywordNull()) {
  5731. this.advance();
  5732. return new LiteralPrimitive(this.span(start), null);
  5733. }
  5734. else if (this.next.isKeywordUndefined()) {
  5735. this.advance();
  5736. return new LiteralPrimitive(this.span(start), void 0);
  5737. }
  5738. else if (this.next.isKeywordTrue()) {
  5739. this.advance();
  5740. return new LiteralPrimitive(this.span(start), true);
  5741. }
  5742. else if (this.next.isKeywordFalse()) {
  5743. this.advance();
  5744. return new LiteralPrimitive(this.span(start), false);
  5745. }
  5746. else if (this.next.isKeywordThis()) {
  5747. this.advance();
  5748. return new ImplicitReceiver(this.span(start));
  5749. }
  5750. else if (this.optionalCharacter($LBRACKET)) {
  5751. this.rbracketsExpected++;
  5752. const /** @type {?} */ elements = this.parseExpressionList($RBRACKET);
  5753. this.rbracketsExpected--;
  5754. this.expectCharacter($RBRACKET);
  5755. return new LiteralArray(this.span(start), elements);
  5756. }
  5757. else if (this.next.isCharacter($LBRACE)) {
  5758. return this.parseLiteralMap();
  5759. }
  5760. else if (this.next.isIdentifier()) {
  5761. return this.parseAccessMemberOrMethodCall(new ImplicitReceiver(this.span(start)), false);
  5762. }
  5763. else if (this.next.isNumber()) {
  5764. const /** @type {?} */ value = this.next.toNumber();
  5765. this.advance();
  5766. return new LiteralPrimitive(this.span(start), value);
  5767. }
  5768. else if (this.next.isString()) {
  5769. const /** @type {?} */ literalValue = this.next.toString();
  5770. this.advance();
  5771. return new LiteralPrimitive(this.span(start), literalValue);
  5772. }
  5773. else if (this.index >= this.tokens.length) {
  5774. this.error(`Unexpected end of expression: ${this.input}`);
  5775. return new EmptyExpr(this.span(start));
  5776. }
  5777. else {
  5778. this.error(`Unexpected token ${this.next}`);
  5779. return new EmptyExpr(this.span(start));
  5780. }
  5781. }
  5782. /**
  5783. * @param {?} terminator
  5784. * @return {?}
  5785. */
  5786. parseExpressionList(terminator) {
  5787. const /** @type {?} */ result = [];
  5788. if (!this.next.isCharacter(terminator)) {
  5789. do {
  5790. result.push(this.parsePipe());
  5791. } while (this.optionalCharacter($COMMA));
  5792. }
  5793. return result;
  5794. }
  5795. /**
  5796. * @return {?}
  5797. */
  5798. parseLiteralMap() {
  5799. const /** @type {?} */ keys = [];
  5800. const /** @type {?} */ values = [];
  5801. const /** @type {?} */ start = this.inputIndex;
  5802. this.expectCharacter($LBRACE);
  5803. if (!this.optionalCharacter($RBRACE)) {
  5804. this.rbracesExpected++;
  5805. do {
  5806. const /** @type {?} */ quoted = this.next.isString();
  5807. const /** @type {?} */ key = this.expectIdentifierOrKeywordOrString();
  5808. keys.push({ key, quoted });
  5809. this.expectCharacter($COLON);
  5810. values.push(this.parsePipe());
  5811. } while (this.optionalCharacter($COMMA));
  5812. this.rbracesExpected--;
  5813. this.expectCharacter($RBRACE);
  5814. }
  5815. return new LiteralMap(this.span(start), keys, values);
  5816. }
  5817. /**
  5818. * @param {?} receiver
  5819. * @param {?=} isSafe
  5820. * @return {?}
  5821. */
  5822. parseAccessMemberOrMethodCall(receiver, isSafe = false) {
  5823. const /** @type {?} */ start = receiver.span.start;
  5824. const /** @type {?} */ id = this.expectIdentifierOrKeyword();
  5825. if (this.optionalCharacter($LPAREN)) {
  5826. this.rparensExpected++;
  5827. const /** @type {?} */ args = this.parseCallArguments();
  5828. this.expectCharacter($RPAREN);
  5829. this.rparensExpected--;
  5830. const /** @type {?} */ span = this.span(start);
  5831. return isSafe ? new SafeMethodCall(span, receiver, id, args) :
  5832. new MethodCall(span, receiver, id, args);
  5833. }
  5834. else {
  5835. if (isSafe) {
  5836. if (this.optionalOperator('=')) {
  5837. this.error('The \'?.\' operator cannot be used in the assignment');
  5838. return new EmptyExpr(this.span(start));
  5839. }
  5840. else {
  5841. return new SafePropertyRead(this.span(start), receiver, id);
  5842. }
  5843. }
  5844. else {
  5845. if (this.optionalOperator('=')) {
  5846. if (!this.parseAction) {
  5847. this.error('Bindings cannot contain assignments');
  5848. return new EmptyExpr(this.span(start));
  5849. }
  5850. const /** @type {?} */ value = this.parseConditional();
  5851. return new PropertyWrite(this.span(start), receiver, id, value);
  5852. }
  5853. else {
  5854. return new PropertyRead(this.span(start), receiver, id);
  5855. }
  5856. }
  5857. }
  5858. }
  5859. /**
  5860. * @return {?}
  5861. */
  5862. parseCallArguments() {
  5863. if (this.next.isCharacter($RPAREN))
  5864. return [];
  5865. const /** @type {?} */ positionals = [];
  5866. do {
  5867. positionals.push(this.parsePipe());
  5868. } while (this.optionalCharacter($COMMA));
  5869. return /** @type {?} */ (positionals);
  5870. }
  5871. /**
  5872. * An identifier, a keyword, a string with an optional `-` inbetween.
  5873. * @return {?}
  5874. */
  5875. expectTemplateBindingKey() {
  5876. let /** @type {?} */ result = '';
  5877. let /** @type {?} */ operatorFound = false;
  5878. do {
  5879. result += this.expectIdentifierOrKeywordOrString();
  5880. operatorFound = this.optionalOperator('-');
  5881. if (operatorFound) {
  5882. result += '-';
  5883. }
  5884. } while (operatorFound);
  5885. return result.toString();
  5886. }
  5887. /**
  5888. * @return {?}
  5889. */
  5890. parseTemplateBindings() {
  5891. const /** @type {?} */ bindings = [];
  5892. let /** @type {?} */ prefix = /** @type {?} */ ((null));
  5893. const /** @type {?} */ warnings = [];
  5894. while (this.index < this.tokens.length) {
  5895. const /** @type {?} */ start = this.inputIndex;
  5896. let /** @type {?} */ keyIsVar = this.peekKeywordLet();
  5897. if (keyIsVar) {
  5898. this.advance();
  5899. }
  5900. let /** @type {?} */ rawKey = this.expectTemplateBindingKey();
  5901. let /** @type {?} */ key = rawKey;
  5902. if (!keyIsVar) {
  5903. if (prefix == null) {
  5904. prefix = key;
  5905. }
  5906. else {
  5907. key = prefix + key[0].toUpperCase() + key.substring(1);
  5908. }
  5909. }
  5910. this.optionalCharacter($COLON);
  5911. let /** @type {?} */ name = /** @type {?} */ ((null));
  5912. let /** @type {?} */ expression = /** @type {?} */ ((null));
  5913. if (keyIsVar) {
  5914. if (this.optionalOperator('=')) {
  5915. name = this.expectTemplateBindingKey();
  5916. }
  5917. else {
  5918. name = '\$implicit';
  5919. }
  5920. }
  5921. else if (this.peekKeywordAs()) {
  5922. const /** @type {?} */ letStart = this.inputIndex;
  5923. this.advance(); // consume `as`
  5924. name = rawKey;
  5925. key = this.expectTemplateBindingKey(); // read local var name
  5926. keyIsVar = true;
  5927. }
  5928. else if (this.next !== EOF && !this.peekKeywordLet()) {
  5929. const /** @type {?} */ start = this.inputIndex;
  5930. const /** @type {?} */ ast = this.parsePipe();
  5931. const /** @type {?} */ source = this.input.substring(start - this.offset, this.inputIndex - this.offset);
  5932. expression = new ASTWithSource(ast, source, this.location, this.errors);
  5933. }
  5934. bindings.push(new TemplateBinding(this.span(start), key, keyIsVar, name, expression));
  5935. if (this.peekKeywordAs() && !keyIsVar) {
  5936. const /** @type {?} */ letStart = this.inputIndex;
  5937. this.advance(); // consume `as`
  5938. const /** @type {?} */ letName = this.expectTemplateBindingKey(); // read local var name
  5939. bindings.push(new TemplateBinding(this.span(letStart), letName, true, key, /** @type {?} */ ((null))));
  5940. }
  5941. if (!this.optionalCharacter($SEMICOLON)) {
  5942. this.optionalCharacter($COMMA);
  5943. }
  5944. }
  5945. return new TemplateBindingParseResult(bindings, warnings, this.errors);
  5946. }
  5947. /**
  5948. * @param {?} message
  5949. * @param {?=} index
  5950. * @return {?}
  5951. */
  5952. error(message, index = null) {
  5953. this.errors.push(new ParserError(message, this.input, this.locationText(index), this.location));
  5954. this.skip();
  5955. }
  5956. /**
  5957. * @param {?=} index
  5958. * @return {?}
  5959. */
  5960. locationText(index = null) {
  5961. if (index == null)
  5962. index = this.index;
  5963. return (index < this.tokens.length) ? `at column ${this.tokens[index].index + 1} in` :
  5964. `at the end of the expression`;
  5965. }
  5966. /**
  5967. * @return {?}
  5968. */
  5969. skip() {
  5970. let /** @type {?} */ n = this.next;
  5971. while (this.index < this.tokens.length && !n.isCharacter($SEMICOLON) &&
  5972. (this.rparensExpected <= 0 || !n.isCharacter($RPAREN)) &&
  5973. (this.rbracesExpected <= 0 || !n.isCharacter($RBRACE)) &&
  5974. (this.rbracketsExpected <= 0 || !n.isCharacter($RBRACKET))) {
  5975. if (this.next.isError()) {
  5976. this.errors.push(new ParserError(/** @type {?} */ ((this.next.toString())), this.input, this.locationText(), this.location));
  5977. }
  5978. this.advance();
  5979. n = this.next;
  5980. }
  5981. }
  5982. }
  5983. class SimpleExpressionChecker {
  5984. constructor() {
  5985. this.errors = [];
  5986. }
  5987. /**
  5988. * @param {?} ast
  5989. * @return {?}
  5990. */
  5991. static check(ast) {
  5992. const /** @type {?} */ s = new SimpleExpressionChecker();
  5993. ast.visit(s);
  5994. return s.errors;
  5995. }
  5996. /**
  5997. * @param {?} ast
  5998. * @param {?} context
  5999. * @return {?}
  6000. */
  6001. visitImplicitReceiver(ast, context) { }
  6002. /**
  6003. * @param {?} ast
  6004. * @param {?} context
  6005. * @return {?}
  6006. */
  6007. visitInterpolation(ast, context) { }
  6008. /**
  6009. * @param {?} ast
  6010. * @param {?} context
  6011. * @return {?}
  6012. */
  6013. visitLiteralPrimitive(ast, context) { }
  6014. /**
  6015. * @param {?} ast
  6016. * @param {?} context
  6017. * @return {?}
  6018. */
  6019. visitPropertyRead(ast, context) { }
  6020. /**
  6021. * @param {?} ast
  6022. * @param {?} context
  6023. * @return {?}
  6024. */
  6025. visitPropertyWrite(ast, context) { }
  6026. /**
  6027. * @param {?} ast
  6028. * @param {?} context
  6029. * @return {?}
  6030. */
  6031. visitSafePropertyRead(ast, context) { }
  6032. /**
  6033. * @param {?} ast
  6034. * @param {?} context
  6035. * @return {?}
  6036. */
  6037. visitMethodCall(ast, context) { }
  6038. /**
  6039. * @param {?} ast
  6040. * @param {?} context
  6041. * @return {?}
  6042. */
  6043. visitSafeMethodCall(ast, context) { }
  6044. /**
  6045. * @param {?} ast
  6046. * @param {?} context
  6047. * @return {?}
  6048. */
  6049. visitFunctionCall(ast, context) { }
  6050. /**
  6051. * @param {?} ast
  6052. * @param {?} context
  6053. * @return {?}
  6054. */
  6055. visitLiteralArray(ast, context) { this.visitAll(ast.expressions); }
  6056. /**
  6057. * @param {?} ast
  6058. * @param {?} context
  6059. * @return {?}
  6060. */
  6061. visitLiteralMap(ast, context) { this.visitAll(ast.values); }
  6062. /**
  6063. * @param {?} ast
  6064. * @param {?} context
  6065. * @return {?}
  6066. */
  6067. visitBinary(ast, context) { }
  6068. /**
  6069. * @param {?} ast
  6070. * @param {?} context
  6071. * @return {?}
  6072. */
  6073. visitPrefixNot(ast, context) { }
  6074. /**
  6075. * @param {?} ast
  6076. * @param {?} context
  6077. * @return {?}
  6078. */
  6079. visitNonNullAssert(ast, context) { }
  6080. /**
  6081. * @param {?} ast
  6082. * @param {?} context
  6083. * @return {?}
  6084. */
  6085. visitConditional(ast, context) { }
  6086. /**
  6087. * @param {?} ast
  6088. * @param {?} context
  6089. * @return {?}
  6090. */
  6091. visitPipe(ast, context) { this.errors.push('pipes'); }
  6092. /**
  6093. * @param {?} ast
  6094. * @param {?} context
  6095. * @return {?}
  6096. */
  6097. visitKeyedRead(ast, context) { }
  6098. /**
  6099. * @param {?} ast
  6100. * @param {?} context
  6101. * @return {?}
  6102. */
  6103. visitKeyedWrite(ast, context) { }
  6104. /**
  6105. * @param {?} asts
  6106. * @return {?}
  6107. */
  6108. visitAll(asts) { return asts.map(node => node.visit(this)); }
  6109. /**
  6110. * @param {?} ast
  6111. * @param {?} context
  6112. * @return {?}
  6113. */
  6114. visitChain(ast, context) { }
  6115. /**
  6116. * @param {?} ast
  6117. * @param {?} context
  6118. * @return {?}
  6119. */
  6120. visitQuote(ast, context) { }
  6121. }
  6122. /**
  6123. * @fileoverview added by tsickle
  6124. * @suppress {checkTypes} checked by tsc
  6125. */
  6126. class ParseLocation {
  6127. /**
  6128. * @param {?} file
  6129. * @param {?} offset
  6130. * @param {?} line
  6131. * @param {?} col
  6132. */
  6133. constructor(file, offset, line, col) {
  6134. this.file = file;
  6135. this.offset = offset;
  6136. this.line = line;
  6137. this.col = col;
  6138. }
  6139. /**
  6140. * @return {?}
  6141. */
  6142. toString() {
  6143. return this.offset != null ? `${this.file.url}@${this.line}:${this.col}` : this.file.url;
  6144. }
  6145. /**
  6146. * @param {?} delta
  6147. * @return {?}
  6148. */
  6149. moveBy(delta) {
  6150. const /** @type {?} */ source = this.file.content;
  6151. const /** @type {?} */ len = source.length;
  6152. let /** @type {?} */ offset = this.offset;
  6153. let /** @type {?} */ line = this.line;
  6154. let /** @type {?} */ col = this.col;
  6155. while (offset > 0 && delta < 0) {
  6156. offset--;
  6157. delta++;
  6158. const /** @type {?} */ ch = source.charCodeAt(offset);
  6159. if (ch == $LF) {
  6160. line--;
  6161. const /** @type {?} */ priorLine = source.substr(0, offset - 1).lastIndexOf(String.fromCharCode($LF));
  6162. col = priorLine > 0 ? offset - priorLine : offset;
  6163. }
  6164. else {
  6165. col--;
  6166. }
  6167. }
  6168. while (offset < len && delta > 0) {
  6169. const /** @type {?} */ ch = source.charCodeAt(offset);
  6170. offset++;
  6171. delta--;
  6172. if (ch == $LF) {
  6173. line++;
  6174. col = 0;
  6175. }
  6176. else {
  6177. col++;
  6178. }
  6179. }
  6180. return new ParseLocation(this.file, offset, line, col);
  6181. }
  6182. /**
  6183. * @param {?} maxChars
  6184. * @param {?} maxLines
  6185. * @return {?}
  6186. */
  6187. getContext(maxChars, maxLines) {
  6188. const /** @type {?} */ content = this.file.content;
  6189. let /** @type {?} */ startOffset = this.offset;
  6190. if (startOffset != null) {
  6191. if (startOffset > content.length - 1) {
  6192. startOffset = content.length - 1;
  6193. }
  6194. let /** @type {?} */ endOffset = startOffset;
  6195. let /** @type {?} */ ctxChars = 0;
  6196. let /** @type {?} */ ctxLines = 0;
  6197. while (ctxChars < maxChars && startOffset > 0) {
  6198. startOffset--;
  6199. ctxChars++;
  6200. if (content[startOffset] == '\n') {
  6201. if (++ctxLines == maxLines) {
  6202. break;
  6203. }
  6204. }
  6205. }
  6206. ctxChars = 0;
  6207. ctxLines = 0;
  6208. while (ctxChars < maxChars && endOffset < content.length - 1) {
  6209. endOffset++;
  6210. ctxChars++;
  6211. if (content[endOffset] == '\n') {
  6212. if (++ctxLines == maxLines) {
  6213. break;
  6214. }
  6215. }
  6216. }
  6217. return {
  6218. before: content.substring(startOffset, this.offset),
  6219. after: content.substring(this.offset, endOffset + 1),
  6220. };
  6221. }
  6222. return null;
  6223. }
  6224. }
  6225. class ParseSourceFile {
  6226. /**
  6227. * @param {?} content
  6228. * @param {?} url
  6229. */
  6230. constructor(content, url) {
  6231. this.content = content;
  6232. this.url = url;
  6233. }
  6234. }
  6235. class ParseSourceSpan {
  6236. /**
  6237. * @param {?} start
  6238. * @param {?} end
  6239. * @param {?=} details
  6240. */
  6241. constructor(start, end, details = null) {
  6242. this.start = start;
  6243. this.end = end;
  6244. this.details = details;
  6245. }
  6246. /**
  6247. * @return {?}
  6248. */
  6249. toString() {
  6250. return this.start.file.content.substring(this.start.offset, this.end.offset);
  6251. }
  6252. }
  6253. /** @enum {number} */
  6254. const ParseErrorLevel = {
  6255. WARNING: 0,
  6256. ERROR: 1,
  6257. };
  6258. ParseErrorLevel[ParseErrorLevel.WARNING] = "WARNING";
  6259. ParseErrorLevel[ParseErrorLevel.ERROR] = "ERROR";
  6260. class ParseError {
  6261. /**
  6262. * @param {?} span
  6263. * @param {?} msg
  6264. * @param {?=} level
  6265. */
  6266. constructor(span, msg, level = ParseErrorLevel.ERROR) {
  6267. this.span = span;
  6268. this.msg = msg;
  6269. this.level = level;
  6270. }
  6271. /**
  6272. * @return {?}
  6273. */
  6274. contextualMessage() {
  6275. const /** @type {?} */ ctx = this.span.start.getContext(100, 3);
  6276. return ctx ? `${this.msg} ("${ctx.before}[${ParseErrorLevel[this.level]} ->]${ctx.after}")` :
  6277. this.msg;
  6278. }
  6279. /**
  6280. * @return {?}
  6281. */
  6282. toString() {
  6283. const /** @type {?} */ details = this.span.details ? `, ${this.span.details}` : '';
  6284. return `${this.contextualMessage()}: ${this.span.start}${details}`;
  6285. }
  6286. }
  6287. /**
  6288. * @param {?} kind
  6289. * @param {?} type
  6290. * @return {?}
  6291. */
  6292. function typeSourceSpan(kind, type) {
  6293. const /** @type {?} */ moduleUrl = identifierModuleUrl(type);
  6294. const /** @type {?} */ sourceFileName = moduleUrl != null ? `in ${kind} ${identifierName(type)} in ${moduleUrl}` :
  6295. `in ${kind} ${identifierName(type)}`;
  6296. const /** @type {?} */ sourceFile = new ParseSourceFile('', sourceFileName);
  6297. return new ParseSourceSpan(new ParseLocation(sourceFile, -1, -1, -1), new ParseLocation(sourceFile, -1, -1, -1));
  6298. }
  6299. /**
  6300. * @fileoverview added by tsickle
  6301. * @suppress {checkTypes} checked by tsc
  6302. */
  6303. /**
  6304. * @license
  6305. * Copyright Google Inc. All Rights Reserved.
  6306. *
  6307. * Use of this source code is governed by an MIT-style license that can be
  6308. * found in the LICENSE file at https://angular.io/license
  6309. */
  6310. /** @enum {number} */
  6311. const TokenType$1 = {
  6312. TAG_OPEN_START: 0,
  6313. TAG_OPEN_END: 1,
  6314. TAG_OPEN_END_VOID: 2,
  6315. TAG_CLOSE: 3,
  6316. TEXT: 4,
  6317. ESCAPABLE_RAW_TEXT: 5,
  6318. RAW_TEXT: 6,
  6319. COMMENT_START: 7,
  6320. COMMENT_END: 8,
  6321. CDATA_START: 9,
  6322. CDATA_END: 10,
  6323. ATTR_NAME: 11,
  6324. ATTR_VALUE: 12,
  6325. DOC_TYPE: 13,
  6326. EXPANSION_FORM_START: 14,
  6327. EXPANSION_CASE_VALUE: 15,
  6328. EXPANSION_CASE_EXP_START: 16,
  6329. EXPANSION_CASE_EXP_END: 17,
  6330. EXPANSION_FORM_END: 18,
  6331. EOF: 19,
  6332. };
  6333. TokenType$1[TokenType$1.TAG_OPEN_START] = "TAG_OPEN_START";
  6334. TokenType$1[TokenType$1.TAG_OPEN_END] = "TAG_OPEN_END";
  6335. TokenType$1[TokenType$1.TAG_OPEN_END_VOID] = "TAG_OPEN_END_VOID";
  6336. TokenType$1[TokenType$1.TAG_CLOSE] = "TAG_CLOSE";
  6337. TokenType$1[TokenType$1.TEXT] = "TEXT";
  6338. TokenType$1[TokenType$1.ESCAPABLE_RAW_TEXT] = "ESCAPABLE_RAW_TEXT";
  6339. TokenType$1[TokenType$1.RAW_TEXT] = "RAW_TEXT";
  6340. TokenType$1[TokenType$1.COMMENT_START] = "COMMENT_START";
  6341. TokenType$1[TokenType$1.COMMENT_END] = "COMMENT_END";
  6342. TokenType$1[TokenType$1.CDATA_START] = "CDATA_START";
  6343. TokenType$1[TokenType$1.CDATA_END] = "CDATA_END";
  6344. TokenType$1[TokenType$1.ATTR_NAME] = "ATTR_NAME";
  6345. TokenType$1[TokenType$1.ATTR_VALUE] = "ATTR_VALUE";
  6346. TokenType$1[TokenType$1.DOC_TYPE] = "DOC_TYPE";
  6347. TokenType$1[TokenType$1.EXPANSION_FORM_START] = "EXPANSION_FORM_START";
  6348. TokenType$1[TokenType$1.EXPANSION_CASE_VALUE] = "EXPANSION_CASE_VALUE";
  6349. TokenType$1[TokenType$1.EXPANSION_CASE_EXP_START] = "EXPANSION_CASE_EXP_START";
  6350. TokenType$1[TokenType$1.EXPANSION_CASE_EXP_END] = "EXPANSION_CASE_EXP_END";
  6351. TokenType$1[TokenType$1.EXPANSION_FORM_END] = "EXPANSION_FORM_END";
  6352. TokenType$1[TokenType$1.EOF] = "EOF";
  6353. class Token$1 {
  6354. /**
  6355. * @param {?} type
  6356. * @param {?} parts
  6357. * @param {?} sourceSpan
  6358. */
  6359. constructor(type, parts, sourceSpan) {
  6360. this.type = type;
  6361. this.parts = parts;
  6362. this.sourceSpan = sourceSpan;
  6363. }
  6364. }
  6365. class TokenError extends ParseError {
  6366. /**
  6367. * @param {?} errorMsg
  6368. * @param {?} tokenType
  6369. * @param {?} span
  6370. */
  6371. constructor(errorMsg, tokenType, span) {
  6372. super(span, errorMsg);
  6373. this.tokenType = tokenType;
  6374. }
  6375. }
  6376. class TokenizeResult {
  6377. /**
  6378. * @param {?} tokens
  6379. * @param {?} errors
  6380. */
  6381. constructor(tokens, errors) {
  6382. this.tokens = tokens;
  6383. this.errors = errors;
  6384. }
  6385. }
  6386. /**
  6387. * @param {?} source
  6388. * @param {?} url
  6389. * @param {?} getTagDefinition
  6390. * @param {?=} tokenizeExpansionForms
  6391. * @param {?=} interpolationConfig
  6392. * @return {?}
  6393. */
  6394. function tokenize(source, url, getTagDefinition, tokenizeExpansionForms = false, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  6395. return new _Tokenizer(new ParseSourceFile(source, url), getTagDefinition, tokenizeExpansionForms, interpolationConfig)
  6396. .tokenize();
  6397. }
  6398. const _CR_OR_CRLF_REGEXP = /\r\n?/g;
  6399. /**
  6400. * @param {?} charCode
  6401. * @return {?}
  6402. */
  6403. function _unexpectedCharacterErrorMsg(charCode) {
  6404. const /** @type {?} */ char = charCode === $EOF ? 'EOF' : String.fromCharCode(charCode);
  6405. return `Unexpected character "${char}"`;
  6406. }
  6407. /**
  6408. * @param {?} entitySrc
  6409. * @return {?}
  6410. */
  6411. function _unknownEntityErrorMsg(entitySrc) {
  6412. return `Unknown entity "${entitySrc}" - use the "&#<decimal>;" or "&#x<hex>;" syntax`;
  6413. }
  6414. class _ControlFlowError {
  6415. /**
  6416. * @param {?} error
  6417. */
  6418. constructor(error) {
  6419. this.error = error;
  6420. }
  6421. }
  6422. class _Tokenizer {
  6423. /**
  6424. * @param {?} _file The html source
  6425. * @param {?} _getTagDefinition
  6426. * @param {?} _tokenizeIcu Whether to tokenize ICU messages (considered as text nodes when false)
  6427. * @param {?=} _interpolationConfig
  6428. */
  6429. constructor(_file, _getTagDefinition, _tokenizeIcu, _interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  6430. this._file = _file;
  6431. this._getTagDefinition = _getTagDefinition;
  6432. this._tokenizeIcu = _tokenizeIcu;
  6433. this._interpolationConfig = _interpolationConfig;
  6434. this._peek = -1;
  6435. this._nextPeek = -1;
  6436. this._index = -1;
  6437. this._line = 0;
  6438. this._column = -1;
  6439. this._expansionCaseStack = [];
  6440. this._inInterpolation = false;
  6441. this.tokens = [];
  6442. this.errors = [];
  6443. this._input = _file.content;
  6444. this._length = _file.content.length;
  6445. this._advance();
  6446. }
  6447. /**
  6448. * @param {?} content
  6449. * @return {?}
  6450. */
  6451. _processCarriageReturns(content) {
  6452. // http://www.w3.org/TR/html5/syntax.html#preprocessing-the-input-stream
  6453. // In order to keep the original position in the source, we can not
  6454. // pre-process it.
  6455. // Instead CRs are processed right before instantiating the tokens.
  6456. return content.replace(_CR_OR_CRLF_REGEXP, '\n');
  6457. }
  6458. /**
  6459. * @return {?}
  6460. */
  6461. tokenize() {
  6462. while (this._peek !== $EOF) {
  6463. const /** @type {?} */ start = this._getLocation();
  6464. try {
  6465. if (this._attemptCharCode($LT)) {
  6466. if (this._attemptCharCode($BANG)) {
  6467. if (this._attemptCharCode($LBRACKET)) {
  6468. this._consumeCdata(start);
  6469. }
  6470. else if (this._attemptCharCode($MINUS)) {
  6471. this._consumeComment(start);
  6472. }
  6473. else {
  6474. this._consumeDocType(start);
  6475. }
  6476. }
  6477. else if (this._attemptCharCode($SLASH)) {
  6478. this._consumeTagClose(start);
  6479. }
  6480. else {
  6481. this._consumeTagOpen(start);
  6482. }
  6483. }
  6484. else if (!(this._tokenizeIcu && this._tokenizeExpansionForm())) {
  6485. this._consumeText();
  6486. }
  6487. }
  6488. catch (/** @type {?} */ e) {
  6489. if (e instanceof _ControlFlowError) {
  6490. this.errors.push(e.error);
  6491. }
  6492. else {
  6493. throw e;
  6494. }
  6495. }
  6496. }
  6497. this._beginToken(TokenType$1.EOF);
  6498. this._endToken([]);
  6499. return new TokenizeResult(mergeTextTokens(this.tokens), this.errors);
  6500. }
  6501. /**
  6502. * \@internal
  6503. * @return {?} whether an ICU token has been created
  6504. */
  6505. _tokenizeExpansionForm() {
  6506. if (isExpansionFormStart(this._input, this._index, this._interpolationConfig)) {
  6507. this._consumeExpansionFormStart();
  6508. return true;
  6509. }
  6510. if (isExpansionCaseStart(this._peek) && this._isInExpansionForm()) {
  6511. this._consumeExpansionCaseStart();
  6512. return true;
  6513. }
  6514. if (this._peek === $RBRACE) {
  6515. if (this._isInExpansionCase()) {
  6516. this._consumeExpansionCaseEnd();
  6517. return true;
  6518. }
  6519. if (this._isInExpansionForm()) {
  6520. this._consumeExpansionFormEnd();
  6521. return true;
  6522. }
  6523. }
  6524. return false;
  6525. }
  6526. /**
  6527. * @return {?}
  6528. */
  6529. _getLocation() {
  6530. return new ParseLocation(this._file, this._index, this._line, this._column);
  6531. }
  6532. /**
  6533. * @param {?=} start
  6534. * @param {?=} end
  6535. * @return {?}
  6536. */
  6537. _getSpan(start = this._getLocation(), end = this._getLocation()) {
  6538. return new ParseSourceSpan(start, end);
  6539. }
  6540. /**
  6541. * @param {?} type
  6542. * @param {?=} start
  6543. * @return {?}
  6544. */
  6545. _beginToken(type, start = this._getLocation()) {
  6546. this._currentTokenStart = start;
  6547. this._currentTokenType = type;
  6548. }
  6549. /**
  6550. * @param {?} parts
  6551. * @param {?=} end
  6552. * @return {?}
  6553. */
  6554. _endToken(parts, end = this._getLocation()) {
  6555. const /** @type {?} */ token = new Token$1(this._currentTokenType, parts, new ParseSourceSpan(this._currentTokenStart, end));
  6556. this.tokens.push(token);
  6557. this._currentTokenStart = /** @type {?} */ ((null));
  6558. this._currentTokenType = /** @type {?} */ ((null));
  6559. return token;
  6560. }
  6561. /**
  6562. * @param {?} msg
  6563. * @param {?} span
  6564. * @return {?}
  6565. */
  6566. _createError(msg, span) {
  6567. if (this._isInExpansionForm()) {
  6568. msg += ` (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)`;
  6569. }
  6570. const /** @type {?} */ error = new TokenError(msg, this._currentTokenType, span);
  6571. this._currentTokenStart = /** @type {?} */ ((null));
  6572. this._currentTokenType = /** @type {?} */ ((null));
  6573. return new _ControlFlowError(error);
  6574. }
  6575. /**
  6576. * @return {?}
  6577. */
  6578. _advance() {
  6579. if (this._index >= this._length) {
  6580. throw this._createError(_unexpectedCharacterErrorMsg($EOF), this._getSpan());
  6581. }
  6582. if (this._peek === $LF) {
  6583. this._line++;
  6584. this._column = 0;
  6585. }
  6586. else if (this._peek !== $LF && this._peek !== $CR) {
  6587. this._column++;
  6588. }
  6589. this._index++;
  6590. this._peek = this._index >= this._length ? $EOF : this._input.charCodeAt(this._index);
  6591. this._nextPeek =
  6592. this._index + 1 >= this._length ? $EOF : this._input.charCodeAt(this._index + 1);
  6593. }
  6594. /**
  6595. * @param {?} charCode
  6596. * @return {?}
  6597. */
  6598. _attemptCharCode(charCode) {
  6599. if (this._peek === charCode) {
  6600. this._advance();
  6601. return true;
  6602. }
  6603. return false;
  6604. }
  6605. /**
  6606. * @param {?} charCode
  6607. * @return {?}
  6608. */
  6609. _attemptCharCodeCaseInsensitive(charCode) {
  6610. if (compareCharCodeCaseInsensitive(this._peek, charCode)) {
  6611. this._advance();
  6612. return true;
  6613. }
  6614. return false;
  6615. }
  6616. /**
  6617. * @param {?} charCode
  6618. * @return {?}
  6619. */
  6620. _requireCharCode(charCode) {
  6621. const /** @type {?} */ location = this._getLocation();
  6622. if (!this._attemptCharCode(charCode)) {
  6623. throw this._createError(_unexpectedCharacterErrorMsg(this._peek), this._getSpan(location, location));
  6624. }
  6625. }
  6626. /**
  6627. * @param {?} chars
  6628. * @return {?}
  6629. */
  6630. _attemptStr(chars) {
  6631. const /** @type {?} */ len = chars.length;
  6632. if (this._index + len > this._length) {
  6633. return false;
  6634. }
  6635. const /** @type {?} */ initialPosition = this._savePosition();
  6636. for (let /** @type {?} */ i = 0; i < len; i++) {
  6637. if (!this._attemptCharCode(chars.charCodeAt(i))) {
  6638. // If attempting to parse the string fails, we want to reset the parser
  6639. // to where it was before the attempt
  6640. this._restorePosition(initialPosition);
  6641. return false;
  6642. }
  6643. }
  6644. return true;
  6645. }
  6646. /**
  6647. * @param {?} chars
  6648. * @return {?}
  6649. */
  6650. _attemptStrCaseInsensitive(chars) {
  6651. for (let /** @type {?} */ i = 0; i < chars.length; i++) {
  6652. if (!this._attemptCharCodeCaseInsensitive(chars.charCodeAt(i))) {
  6653. return false;
  6654. }
  6655. }
  6656. return true;
  6657. }
  6658. /**
  6659. * @param {?} chars
  6660. * @return {?}
  6661. */
  6662. _requireStr(chars) {
  6663. const /** @type {?} */ location = this._getLocation();
  6664. if (!this._attemptStr(chars)) {
  6665. throw this._createError(_unexpectedCharacterErrorMsg(this._peek), this._getSpan(location));
  6666. }
  6667. }
  6668. /**
  6669. * @param {?} predicate
  6670. * @return {?}
  6671. */
  6672. _attemptCharCodeUntilFn(predicate) {
  6673. while (!predicate(this._peek)) {
  6674. this._advance();
  6675. }
  6676. }
  6677. /**
  6678. * @param {?} predicate
  6679. * @param {?} len
  6680. * @return {?}
  6681. */
  6682. _requireCharCodeUntilFn(predicate, len) {
  6683. const /** @type {?} */ start = this._getLocation();
  6684. this._attemptCharCodeUntilFn(predicate);
  6685. if (this._index - start.offset < len) {
  6686. throw this._createError(_unexpectedCharacterErrorMsg(this._peek), this._getSpan(start, start));
  6687. }
  6688. }
  6689. /**
  6690. * @param {?} char
  6691. * @return {?}
  6692. */
  6693. _attemptUntilChar(char) {
  6694. while (this._peek !== char) {
  6695. this._advance();
  6696. }
  6697. }
  6698. /**
  6699. * @param {?} decodeEntities
  6700. * @return {?}
  6701. */
  6702. _readChar(decodeEntities) {
  6703. if (decodeEntities && this._peek === $AMPERSAND) {
  6704. return this._decodeEntity();
  6705. }
  6706. else {
  6707. const /** @type {?} */ index = this._index;
  6708. this._advance();
  6709. return this._input[index];
  6710. }
  6711. }
  6712. /**
  6713. * @return {?}
  6714. */
  6715. _decodeEntity() {
  6716. const /** @type {?} */ start = this._getLocation();
  6717. this._advance();
  6718. if (this._attemptCharCode($HASH)) {
  6719. const /** @type {?} */ isHex = this._attemptCharCode($x) || this._attemptCharCode($X);
  6720. const /** @type {?} */ numberStart = this._getLocation().offset;
  6721. this._attemptCharCodeUntilFn(isDigitEntityEnd);
  6722. if (this._peek != $SEMICOLON) {
  6723. throw this._createError(_unexpectedCharacterErrorMsg(this._peek), this._getSpan());
  6724. }
  6725. this._advance();
  6726. const /** @type {?} */ strNum = this._input.substring(numberStart, this._index - 1);
  6727. try {
  6728. const /** @type {?} */ charCode = parseInt(strNum, isHex ? 16 : 10);
  6729. return String.fromCharCode(charCode);
  6730. }
  6731. catch (/** @type {?} */ e) {
  6732. const /** @type {?} */ entity = this._input.substring(start.offset + 1, this._index - 1);
  6733. throw this._createError(_unknownEntityErrorMsg(entity), this._getSpan(start));
  6734. }
  6735. }
  6736. else {
  6737. const /** @type {?} */ startPosition = this._savePosition();
  6738. this._attemptCharCodeUntilFn(isNamedEntityEnd);
  6739. if (this._peek != $SEMICOLON) {
  6740. this._restorePosition(startPosition);
  6741. return '&';
  6742. }
  6743. this._advance();
  6744. const /** @type {?} */ name = this._input.substring(start.offset + 1, this._index - 1);
  6745. const /** @type {?} */ char = NAMED_ENTITIES[name];
  6746. if (!char) {
  6747. throw this._createError(_unknownEntityErrorMsg(name), this._getSpan(start));
  6748. }
  6749. return char;
  6750. }
  6751. }
  6752. /**
  6753. * @param {?} decodeEntities
  6754. * @param {?} firstCharOfEnd
  6755. * @param {?} attemptEndRest
  6756. * @return {?}
  6757. */
  6758. _consumeRawText(decodeEntities, firstCharOfEnd, attemptEndRest) {
  6759. let /** @type {?} */ tagCloseStart;
  6760. const /** @type {?} */ textStart = this._getLocation();
  6761. this._beginToken(decodeEntities ? TokenType$1.ESCAPABLE_RAW_TEXT : TokenType$1.RAW_TEXT, textStart);
  6762. const /** @type {?} */ parts = [];
  6763. while (true) {
  6764. tagCloseStart = this._getLocation();
  6765. if (this._attemptCharCode(firstCharOfEnd) && attemptEndRest()) {
  6766. break;
  6767. }
  6768. if (this._index > tagCloseStart.offset) {
  6769. // add the characters consumed by the previous if statement to the output
  6770. parts.push(this._input.substring(tagCloseStart.offset, this._index));
  6771. }
  6772. while (this._peek !== firstCharOfEnd) {
  6773. parts.push(this._readChar(decodeEntities));
  6774. }
  6775. }
  6776. return this._endToken([this._processCarriageReturns(parts.join(''))], tagCloseStart);
  6777. }
  6778. /**
  6779. * @param {?} start
  6780. * @return {?}
  6781. */
  6782. _consumeComment(start) {
  6783. this._beginToken(TokenType$1.COMMENT_START, start);
  6784. this._requireCharCode($MINUS);
  6785. this._endToken([]);
  6786. const /** @type {?} */ textToken = this._consumeRawText(false, $MINUS, () => this._attemptStr('->'));
  6787. this._beginToken(TokenType$1.COMMENT_END, textToken.sourceSpan.end);
  6788. this._endToken([]);
  6789. }
  6790. /**
  6791. * @param {?} start
  6792. * @return {?}
  6793. */
  6794. _consumeCdata(start) {
  6795. this._beginToken(TokenType$1.CDATA_START, start);
  6796. this._requireStr('CDATA[');
  6797. this._endToken([]);
  6798. const /** @type {?} */ textToken = this._consumeRawText(false, $RBRACKET, () => this._attemptStr(']>'));
  6799. this._beginToken(TokenType$1.CDATA_END, textToken.sourceSpan.end);
  6800. this._endToken([]);
  6801. }
  6802. /**
  6803. * @param {?} start
  6804. * @return {?}
  6805. */
  6806. _consumeDocType(start) {
  6807. this._beginToken(TokenType$1.DOC_TYPE, start);
  6808. this._attemptUntilChar($GT);
  6809. this._advance();
  6810. this._endToken([this._input.substring(start.offset + 2, this._index - 1)]);
  6811. }
  6812. /**
  6813. * @return {?}
  6814. */
  6815. _consumePrefixAndName() {
  6816. const /** @type {?} */ nameOrPrefixStart = this._index;
  6817. let /** @type {?} */ prefix = /** @type {?} */ ((null));
  6818. while (this._peek !== $COLON && !isPrefixEnd(this._peek)) {
  6819. this._advance();
  6820. }
  6821. let /** @type {?} */ nameStart;
  6822. if (this._peek === $COLON) {
  6823. this._advance();
  6824. prefix = this._input.substring(nameOrPrefixStart, this._index - 1);
  6825. nameStart = this._index;
  6826. }
  6827. else {
  6828. nameStart = nameOrPrefixStart;
  6829. }
  6830. this._requireCharCodeUntilFn(isNameEnd, this._index === nameStart ? 1 : 0);
  6831. const /** @type {?} */ name = this._input.substring(nameStart, this._index);
  6832. return [prefix, name];
  6833. }
  6834. /**
  6835. * @param {?} start
  6836. * @return {?}
  6837. */
  6838. _consumeTagOpen(start) {
  6839. const /** @type {?} */ savedPos = this._savePosition();
  6840. let /** @type {?} */ tagName;
  6841. let /** @type {?} */ lowercaseTagName;
  6842. try {
  6843. if (!isAsciiLetter(this._peek)) {
  6844. throw this._createError(_unexpectedCharacterErrorMsg(this._peek), this._getSpan());
  6845. }
  6846. const /** @type {?} */ nameStart = this._index;
  6847. this._consumeTagOpenStart(start);
  6848. tagName = this._input.substring(nameStart, this._index);
  6849. lowercaseTagName = tagName.toLowerCase();
  6850. this._attemptCharCodeUntilFn(isNotWhitespace);
  6851. while (this._peek !== $SLASH && this._peek !== $GT) {
  6852. this._consumeAttributeName();
  6853. this._attemptCharCodeUntilFn(isNotWhitespace);
  6854. if (this._attemptCharCode($EQ)) {
  6855. this._attemptCharCodeUntilFn(isNotWhitespace);
  6856. this._consumeAttributeValue();
  6857. }
  6858. this._attemptCharCodeUntilFn(isNotWhitespace);
  6859. }
  6860. this._consumeTagOpenEnd();
  6861. }
  6862. catch (/** @type {?} */ e) {
  6863. if (e instanceof _ControlFlowError) {
  6864. // When the start tag is invalid, assume we want a "<"
  6865. this._restorePosition(savedPos);
  6866. // Back to back text tokens are merged at the end
  6867. this._beginToken(TokenType$1.TEXT, start);
  6868. this._endToken(['<']);
  6869. return;
  6870. }
  6871. throw e;
  6872. }
  6873. const /** @type {?} */ contentTokenType = this._getTagDefinition(tagName).contentType;
  6874. if (contentTokenType === TagContentType.RAW_TEXT) {
  6875. this._consumeRawTextWithTagClose(lowercaseTagName, false);
  6876. }
  6877. else if (contentTokenType === TagContentType.ESCAPABLE_RAW_TEXT) {
  6878. this._consumeRawTextWithTagClose(lowercaseTagName, true);
  6879. }
  6880. }
  6881. /**
  6882. * @param {?} lowercaseTagName
  6883. * @param {?} decodeEntities
  6884. * @return {?}
  6885. */
  6886. _consumeRawTextWithTagClose(lowercaseTagName, decodeEntities) {
  6887. const /** @type {?} */ textToken = this._consumeRawText(decodeEntities, $LT, () => {
  6888. if (!this._attemptCharCode($SLASH))
  6889. return false;
  6890. this._attemptCharCodeUntilFn(isNotWhitespace);
  6891. if (!this._attemptStrCaseInsensitive(lowercaseTagName))
  6892. return false;
  6893. this._attemptCharCodeUntilFn(isNotWhitespace);
  6894. return this._attemptCharCode($GT);
  6895. });
  6896. this._beginToken(TokenType$1.TAG_CLOSE, textToken.sourceSpan.end);
  6897. this._endToken([/** @type {?} */ ((null)), lowercaseTagName]);
  6898. }
  6899. /**
  6900. * @param {?} start
  6901. * @return {?}
  6902. */
  6903. _consumeTagOpenStart(start) {
  6904. this._beginToken(TokenType$1.TAG_OPEN_START, start);
  6905. const /** @type {?} */ parts = this._consumePrefixAndName();
  6906. this._endToken(parts);
  6907. }
  6908. /**
  6909. * @return {?}
  6910. */
  6911. _consumeAttributeName() {
  6912. this._beginToken(TokenType$1.ATTR_NAME);
  6913. const /** @type {?} */ prefixAndName = this._consumePrefixAndName();
  6914. this._endToken(prefixAndName);
  6915. }
  6916. /**
  6917. * @return {?}
  6918. */
  6919. _consumeAttributeValue() {
  6920. this._beginToken(TokenType$1.ATTR_VALUE);
  6921. let /** @type {?} */ value;
  6922. if (this._peek === $SQ || this._peek === $DQ) {
  6923. const /** @type {?} */ quoteChar = this._peek;
  6924. this._advance();
  6925. const /** @type {?} */ parts = [];
  6926. while (this._peek !== quoteChar) {
  6927. parts.push(this._readChar(true));
  6928. }
  6929. value = parts.join('');
  6930. this._advance();
  6931. }
  6932. else {
  6933. const /** @type {?} */ valueStart = this._index;
  6934. this._requireCharCodeUntilFn(isNameEnd, 1);
  6935. value = this._input.substring(valueStart, this._index);
  6936. }
  6937. this._endToken([this._processCarriageReturns(value)]);
  6938. }
  6939. /**
  6940. * @return {?}
  6941. */
  6942. _consumeTagOpenEnd() {
  6943. const /** @type {?} */ tokenType = this._attemptCharCode($SLASH) ? TokenType$1.TAG_OPEN_END_VOID : TokenType$1.TAG_OPEN_END;
  6944. this._beginToken(tokenType);
  6945. this._requireCharCode($GT);
  6946. this._endToken([]);
  6947. }
  6948. /**
  6949. * @param {?} start
  6950. * @return {?}
  6951. */
  6952. _consumeTagClose(start) {
  6953. this._beginToken(TokenType$1.TAG_CLOSE, start);
  6954. this._attemptCharCodeUntilFn(isNotWhitespace);
  6955. const /** @type {?} */ prefixAndName = this._consumePrefixAndName();
  6956. this._attemptCharCodeUntilFn(isNotWhitespace);
  6957. this._requireCharCode($GT);
  6958. this._endToken(prefixAndName);
  6959. }
  6960. /**
  6961. * @return {?}
  6962. */
  6963. _consumeExpansionFormStart() {
  6964. this._beginToken(TokenType$1.EXPANSION_FORM_START, this._getLocation());
  6965. this._requireCharCode($LBRACE);
  6966. this._endToken([]);
  6967. this._expansionCaseStack.push(TokenType$1.EXPANSION_FORM_START);
  6968. this._beginToken(TokenType$1.RAW_TEXT, this._getLocation());
  6969. const /** @type {?} */ condition = this._readUntil($COMMA);
  6970. this._endToken([condition], this._getLocation());
  6971. this._requireCharCode($COMMA);
  6972. this._attemptCharCodeUntilFn(isNotWhitespace);
  6973. this._beginToken(TokenType$1.RAW_TEXT, this._getLocation());
  6974. const /** @type {?} */ type = this._readUntil($COMMA);
  6975. this._endToken([type], this._getLocation());
  6976. this._requireCharCode($COMMA);
  6977. this._attemptCharCodeUntilFn(isNotWhitespace);
  6978. }
  6979. /**
  6980. * @return {?}
  6981. */
  6982. _consumeExpansionCaseStart() {
  6983. this._beginToken(TokenType$1.EXPANSION_CASE_VALUE, this._getLocation());
  6984. const /** @type {?} */ value = this._readUntil($LBRACE).trim();
  6985. this._endToken([value], this._getLocation());
  6986. this._attemptCharCodeUntilFn(isNotWhitespace);
  6987. this._beginToken(TokenType$1.EXPANSION_CASE_EXP_START, this._getLocation());
  6988. this._requireCharCode($LBRACE);
  6989. this._endToken([], this._getLocation());
  6990. this._attemptCharCodeUntilFn(isNotWhitespace);
  6991. this._expansionCaseStack.push(TokenType$1.EXPANSION_CASE_EXP_START);
  6992. }
  6993. /**
  6994. * @return {?}
  6995. */
  6996. _consumeExpansionCaseEnd() {
  6997. this._beginToken(TokenType$1.EXPANSION_CASE_EXP_END, this._getLocation());
  6998. this._requireCharCode($RBRACE);
  6999. this._endToken([], this._getLocation());
  7000. this._attemptCharCodeUntilFn(isNotWhitespace);
  7001. this._expansionCaseStack.pop();
  7002. }
  7003. /**
  7004. * @return {?}
  7005. */
  7006. _consumeExpansionFormEnd() {
  7007. this._beginToken(TokenType$1.EXPANSION_FORM_END, this._getLocation());
  7008. this._requireCharCode($RBRACE);
  7009. this._endToken([]);
  7010. this._expansionCaseStack.pop();
  7011. }
  7012. /**
  7013. * @return {?}
  7014. */
  7015. _consumeText() {
  7016. const /** @type {?} */ start = this._getLocation();
  7017. this._beginToken(TokenType$1.TEXT, start);
  7018. const /** @type {?} */ parts = [];
  7019. do {
  7020. if (this._interpolationConfig && this._attemptStr(this._interpolationConfig.start)) {
  7021. parts.push(this._interpolationConfig.start);
  7022. this._inInterpolation = true;
  7023. }
  7024. else if (this._interpolationConfig && this._inInterpolation &&
  7025. this._attemptStr(this._interpolationConfig.end)) {
  7026. parts.push(this._interpolationConfig.end);
  7027. this._inInterpolation = false;
  7028. }
  7029. else {
  7030. parts.push(this._readChar(true));
  7031. }
  7032. } while (!this._isTextEnd());
  7033. this._endToken([this._processCarriageReturns(parts.join(''))]);
  7034. }
  7035. /**
  7036. * @return {?}
  7037. */
  7038. _isTextEnd() {
  7039. if (this._peek === $LT || this._peek === $EOF) {
  7040. return true;
  7041. }
  7042. if (this._tokenizeIcu && !this._inInterpolation) {
  7043. if (isExpansionFormStart(this._input, this._index, this._interpolationConfig)) {
  7044. // start of an expansion form
  7045. return true;
  7046. }
  7047. if (this._peek === $RBRACE && this._isInExpansionCase()) {
  7048. // end of and expansion case
  7049. return true;
  7050. }
  7051. }
  7052. return false;
  7053. }
  7054. /**
  7055. * @return {?}
  7056. */
  7057. _savePosition() {
  7058. return [this._peek, this._index, this._column, this._line, this.tokens.length];
  7059. }
  7060. /**
  7061. * @param {?} char
  7062. * @return {?}
  7063. */
  7064. _readUntil(char) {
  7065. const /** @type {?} */ start = this._index;
  7066. this._attemptUntilChar(char);
  7067. return this._input.substring(start, this._index);
  7068. }
  7069. /**
  7070. * @param {?} position
  7071. * @return {?}
  7072. */
  7073. _restorePosition(position) {
  7074. this._peek = position[0];
  7075. this._index = position[1];
  7076. this._column = position[2];
  7077. this._line = position[3];
  7078. const /** @type {?} */ nbTokens = position[4];
  7079. if (nbTokens < this.tokens.length) {
  7080. // remove any extra tokens
  7081. this.tokens = this.tokens.slice(0, nbTokens);
  7082. }
  7083. }
  7084. /**
  7085. * @return {?}
  7086. */
  7087. _isInExpansionCase() {
  7088. return this._expansionCaseStack.length > 0 &&
  7089. this._expansionCaseStack[this._expansionCaseStack.length - 1] ===
  7090. TokenType$1.EXPANSION_CASE_EXP_START;
  7091. }
  7092. /**
  7093. * @return {?}
  7094. */
  7095. _isInExpansionForm() {
  7096. return this._expansionCaseStack.length > 0 &&
  7097. this._expansionCaseStack[this._expansionCaseStack.length - 1] ===
  7098. TokenType$1.EXPANSION_FORM_START;
  7099. }
  7100. }
  7101. /**
  7102. * @param {?} code
  7103. * @return {?}
  7104. */
  7105. function isNotWhitespace(code) {
  7106. return !isWhitespace(code) || code === $EOF;
  7107. }
  7108. /**
  7109. * @param {?} code
  7110. * @return {?}
  7111. */
  7112. function isNameEnd(code) {
  7113. return isWhitespace(code) || code === $GT || code === $SLASH ||
  7114. code === $SQ || code === $DQ || code === $EQ;
  7115. }
  7116. /**
  7117. * @param {?} code
  7118. * @return {?}
  7119. */
  7120. function isPrefixEnd(code) {
  7121. return (code < $a || $z < code) && (code < $A || $Z < code) &&
  7122. (code < $0 || code > $9);
  7123. }
  7124. /**
  7125. * @param {?} code
  7126. * @return {?}
  7127. */
  7128. function isDigitEntityEnd(code) {
  7129. return code == $SEMICOLON || code == $EOF || !isAsciiHexDigit(code);
  7130. }
  7131. /**
  7132. * @param {?} code
  7133. * @return {?}
  7134. */
  7135. function isNamedEntityEnd(code) {
  7136. return code == $SEMICOLON || code == $EOF || !isAsciiLetter(code);
  7137. }
  7138. /**
  7139. * @param {?} input
  7140. * @param {?} offset
  7141. * @param {?} interpolationConfig
  7142. * @return {?}
  7143. */
  7144. function isExpansionFormStart(input, offset, interpolationConfig) {
  7145. const /** @type {?} */ isInterpolationStart = interpolationConfig ? input.indexOf(interpolationConfig.start, offset) == offset : false;
  7146. return input.charCodeAt(offset) == $LBRACE && !isInterpolationStart;
  7147. }
  7148. /**
  7149. * @param {?} peek
  7150. * @return {?}
  7151. */
  7152. function isExpansionCaseStart(peek) {
  7153. return peek === $EQ || isAsciiLetter(peek) || isDigit(peek);
  7154. }
  7155. /**
  7156. * @param {?} code1
  7157. * @param {?} code2
  7158. * @return {?}
  7159. */
  7160. function compareCharCodeCaseInsensitive(code1, code2) {
  7161. return toUpperCaseCharCode(code1) == toUpperCaseCharCode(code2);
  7162. }
  7163. /**
  7164. * @param {?} code
  7165. * @return {?}
  7166. */
  7167. function toUpperCaseCharCode(code) {
  7168. return code >= $a && code <= $z ? code - $a + $A : code;
  7169. }
  7170. /**
  7171. * @param {?} srcTokens
  7172. * @return {?}
  7173. */
  7174. function mergeTextTokens(srcTokens) {
  7175. const /** @type {?} */ dstTokens = [];
  7176. let /** @type {?} */ lastDstToken = undefined;
  7177. for (let /** @type {?} */ i = 0; i < srcTokens.length; i++) {
  7178. const /** @type {?} */ token = srcTokens[i];
  7179. if (lastDstToken && lastDstToken.type == TokenType$1.TEXT && token.type == TokenType$1.TEXT) {
  7180. lastDstToken.parts[0] += token.parts[0];
  7181. lastDstToken.sourceSpan.end = token.sourceSpan.end;
  7182. }
  7183. else {
  7184. lastDstToken = token;
  7185. dstTokens.push(lastDstToken);
  7186. }
  7187. }
  7188. return dstTokens;
  7189. }
  7190. /**
  7191. * @fileoverview added by tsickle
  7192. * @suppress {checkTypes} checked by tsc
  7193. */
  7194. /**
  7195. * @license
  7196. * Copyright Google Inc. All Rights Reserved.
  7197. *
  7198. * Use of this source code is governed by an MIT-style license that can be
  7199. * found in the LICENSE file at https://angular.io/license
  7200. */
  7201. class TreeError extends ParseError {
  7202. /**
  7203. * @param {?} elementName
  7204. * @param {?} span
  7205. * @param {?} msg
  7206. */
  7207. constructor(elementName, span, msg) {
  7208. super(span, msg);
  7209. this.elementName = elementName;
  7210. }
  7211. /**
  7212. * @param {?} elementName
  7213. * @param {?} span
  7214. * @param {?} msg
  7215. * @return {?}
  7216. */
  7217. static create(elementName, span, msg) {
  7218. return new TreeError(elementName, span, msg);
  7219. }
  7220. }
  7221. class ParseTreeResult {
  7222. /**
  7223. * @param {?} rootNodes
  7224. * @param {?} errors
  7225. */
  7226. constructor(rootNodes, errors) {
  7227. this.rootNodes = rootNodes;
  7228. this.errors = errors;
  7229. }
  7230. }
  7231. class Parser$1 {
  7232. /**
  7233. * @param {?} getTagDefinition
  7234. */
  7235. constructor(getTagDefinition) {
  7236. this.getTagDefinition = getTagDefinition;
  7237. }
  7238. /**
  7239. * @param {?} source
  7240. * @param {?} url
  7241. * @param {?=} parseExpansionForms
  7242. * @param {?=} interpolationConfig
  7243. * @return {?}
  7244. */
  7245. parse(source, url, parseExpansionForms = false, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  7246. const /** @type {?} */ tokensAndErrors = tokenize(source, url, this.getTagDefinition, parseExpansionForms, interpolationConfig);
  7247. const /** @type {?} */ treeAndErrors = new _TreeBuilder(tokensAndErrors.tokens, this.getTagDefinition).build();
  7248. return new ParseTreeResult(treeAndErrors.rootNodes, (/** @type {?} */ (tokensAndErrors.errors)).concat(treeAndErrors.errors));
  7249. }
  7250. }
  7251. class _TreeBuilder {
  7252. /**
  7253. * @param {?} tokens
  7254. * @param {?} getTagDefinition
  7255. */
  7256. constructor(tokens, getTagDefinition) {
  7257. this.tokens = tokens;
  7258. this.getTagDefinition = getTagDefinition;
  7259. this._index = -1;
  7260. this._rootNodes = [];
  7261. this._errors = [];
  7262. this._elementStack = [];
  7263. this._advance();
  7264. }
  7265. /**
  7266. * @return {?}
  7267. */
  7268. build() {
  7269. while (this._peek.type !== TokenType$1.EOF) {
  7270. if (this._peek.type === TokenType$1.TAG_OPEN_START) {
  7271. this._consumeStartTag(this._advance());
  7272. }
  7273. else if (this._peek.type === TokenType$1.TAG_CLOSE) {
  7274. this._consumeEndTag(this._advance());
  7275. }
  7276. else if (this._peek.type === TokenType$1.CDATA_START) {
  7277. this._closeVoidElement();
  7278. this._consumeCdata(this._advance());
  7279. }
  7280. else if (this._peek.type === TokenType$1.COMMENT_START) {
  7281. this._closeVoidElement();
  7282. this._consumeComment(this._advance());
  7283. }
  7284. else if (this._peek.type === TokenType$1.TEXT || this._peek.type === TokenType$1.RAW_TEXT ||
  7285. this._peek.type === TokenType$1.ESCAPABLE_RAW_TEXT) {
  7286. this._closeVoidElement();
  7287. this._consumeText(this._advance());
  7288. }
  7289. else if (this._peek.type === TokenType$1.EXPANSION_FORM_START) {
  7290. this._consumeExpansion(this._advance());
  7291. }
  7292. else {
  7293. // Skip all other tokens...
  7294. this._advance();
  7295. }
  7296. }
  7297. return new ParseTreeResult(this._rootNodes, this._errors);
  7298. }
  7299. /**
  7300. * @return {?}
  7301. */
  7302. _advance() {
  7303. const /** @type {?} */ prev = this._peek;
  7304. if (this._index < this.tokens.length - 1) {
  7305. // Note: there is always an EOF token at the end
  7306. this._index++;
  7307. }
  7308. this._peek = this.tokens[this._index];
  7309. return prev;
  7310. }
  7311. /**
  7312. * @param {?} type
  7313. * @return {?}
  7314. */
  7315. _advanceIf(type) {
  7316. if (this._peek.type === type) {
  7317. return this._advance();
  7318. }
  7319. return null;
  7320. }
  7321. /**
  7322. * @param {?} startToken
  7323. * @return {?}
  7324. */
  7325. _consumeCdata(startToken) {
  7326. this._consumeText(this._advance());
  7327. this._advanceIf(TokenType$1.CDATA_END);
  7328. }
  7329. /**
  7330. * @param {?} token
  7331. * @return {?}
  7332. */
  7333. _consumeComment(token) {
  7334. const /** @type {?} */ text = this._advanceIf(TokenType$1.RAW_TEXT);
  7335. this._advanceIf(TokenType$1.COMMENT_END);
  7336. const /** @type {?} */ value = text != null ? text.parts[0].trim() : null;
  7337. this._addToParent(new Comment(value, token.sourceSpan));
  7338. }
  7339. /**
  7340. * @param {?} token
  7341. * @return {?}
  7342. */
  7343. _consumeExpansion(token) {
  7344. const /** @type {?} */ switchValue = this._advance();
  7345. const /** @type {?} */ type = this._advance();
  7346. const /** @type {?} */ cases = [];
  7347. // read =
  7348. while (this._peek.type === TokenType$1.EXPANSION_CASE_VALUE) {
  7349. const /** @type {?} */ expCase = this._parseExpansionCase();
  7350. if (!expCase)
  7351. return; // error
  7352. cases.push(expCase);
  7353. }
  7354. // read the final }
  7355. if (this._peek.type !== TokenType$1.EXPANSION_FORM_END) {
  7356. this._errors.push(TreeError.create(null, this._peek.sourceSpan, `Invalid ICU message. Missing '}'.`));
  7357. return;
  7358. }
  7359. const /** @type {?} */ sourceSpan = new ParseSourceSpan(token.sourceSpan.start, this._peek.sourceSpan.end);
  7360. this._addToParent(new Expansion(switchValue.parts[0], type.parts[0], cases, sourceSpan, switchValue.sourceSpan));
  7361. this._advance();
  7362. }
  7363. /**
  7364. * @return {?}
  7365. */
  7366. _parseExpansionCase() {
  7367. const /** @type {?} */ value = this._advance();
  7368. // read {
  7369. if (this._peek.type !== TokenType$1.EXPANSION_CASE_EXP_START) {
  7370. this._errors.push(TreeError.create(null, this._peek.sourceSpan, `Invalid ICU message. Missing '{'.`));
  7371. return null;
  7372. }
  7373. // read until }
  7374. const /** @type {?} */ start = this._advance();
  7375. const /** @type {?} */ exp = this._collectExpansionExpTokens(start);
  7376. if (!exp)
  7377. return null;
  7378. const /** @type {?} */ end = this._advance();
  7379. exp.push(new Token$1(TokenType$1.EOF, [], end.sourceSpan));
  7380. // parse everything in between { and }
  7381. const /** @type {?} */ parsedExp = new _TreeBuilder(exp, this.getTagDefinition).build();
  7382. if (parsedExp.errors.length > 0) {
  7383. this._errors = this._errors.concat(/** @type {?} */ (parsedExp.errors));
  7384. return null;
  7385. }
  7386. const /** @type {?} */ sourceSpan = new ParseSourceSpan(value.sourceSpan.start, end.sourceSpan.end);
  7387. const /** @type {?} */ expSourceSpan = new ParseSourceSpan(start.sourceSpan.start, end.sourceSpan.end);
  7388. return new ExpansionCase(value.parts[0], parsedExp.rootNodes, sourceSpan, value.sourceSpan, expSourceSpan);
  7389. }
  7390. /**
  7391. * @param {?} start
  7392. * @return {?}
  7393. */
  7394. _collectExpansionExpTokens(start) {
  7395. const /** @type {?} */ exp = [];
  7396. const /** @type {?} */ expansionFormStack = [TokenType$1.EXPANSION_CASE_EXP_START];
  7397. while (true) {
  7398. if (this._peek.type === TokenType$1.EXPANSION_FORM_START ||
  7399. this._peek.type === TokenType$1.EXPANSION_CASE_EXP_START) {
  7400. expansionFormStack.push(this._peek.type);
  7401. }
  7402. if (this._peek.type === TokenType$1.EXPANSION_CASE_EXP_END) {
  7403. if (lastOnStack(expansionFormStack, TokenType$1.EXPANSION_CASE_EXP_START)) {
  7404. expansionFormStack.pop();
  7405. if (expansionFormStack.length == 0)
  7406. return exp;
  7407. }
  7408. else {
  7409. this._errors.push(TreeError.create(null, start.sourceSpan, `Invalid ICU message. Missing '}'.`));
  7410. return null;
  7411. }
  7412. }
  7413. if (this._peek.type === TokenType$1.EXPANSION_FORM_END) {
  7414. if (lastOnStack(expansionFormStack, TokenType$1.EXPANSION_FORM_START)) {
  7415. expansionFormStack.pop();
  7416. }
  7417. else {
  7418. this._errors.push(TreeError.create(null, start.sourceSpan, `Invalid ICU message. Missing '}'.`));
  7419. return null;
  7420. }
  7421. }
  7422. if (this._peek.type === TokenType$1.EOF) {
  7423. this._errors.push(TreeError.create(null, start.sourceSpan, `Invalid ICU message. Missing '}'.`));
  7424. return null;
  7425. }
  7426. exp.push(this._advance());
  7427. }
  7428. }
  7429. /**
  7430. * @param {?} token
  7431. * @return {?}
  7432. */
  7433. _consumeText(token) {
  7434. let /** @type {?} */ text = token.parts[0];
  7435. if (text.length > 0 && text[0] == '\n') {
  7436. const /** @type {?} */ parent = this._getParentElement();
  7437. if (parent != null && parent.children.length == 0 &&
  7438. this.getTagDefinition(parent.name).ignoreFirstLf) {
  7439. text = text.substring(1);
  7440. }
  7441. }
  7442. if (text.length > 0) {
  7443. this._addToParent(new Text(text, token.sourceSpan));
  7444. }
  7445. }
  7446. /**
  7447. * @return {?}
  7448. */
  7449. _closeVoidElement() {
  7450. const /** @type {?} */ el = this._getParentElement();
  7451. if (el && this.getTagDefinition(el.name).isVoid) {
  7452. this._elementStack.pop();
  7453. }
  7454. }
  7455. /**
  7456. * @param {?} startTagToken
  7457. * @return {?}
  7458. */
  7459. _consumeStartTag(startTagToken) {
  7460. const /** @type {?} */ prefix = startTagToken.parts[0];
  7461. const /** @type {?} */ name = startTagToken.parts[1];
  7462. const /** @type {?} */ attrs = [];
  7463. while (this._peek.type === TokenType$1.ATTR_NAME) {
  7464. attrs.push(this._consumeAttr(this._advance()));
  7465. }
  7466. const /** @type {?} */ fullName = this._getElementFullName(prefix, name, this._getParentElement());
  7467. let /** @type {?} */ selfClosing = false;
  7468. // Note: There could have been a tokenizer error
  7469. // so that we don't get a token for the end tag...
  7470. if (this._peek.type === TokenType$1.TAG_OPEN_END_VOID) {
  7471. this._advance();
  7472. selfClosing = true;
  7473. const /** @type {?} */ tagDef = this.getTagDefinition(fullName);
  7474. if (!(tagDef.canSelfClose || getNsPrefix(fullName) !== null || tagDef.isVoid)) {
  7475. this._errors.push(TreeError.create(fullName, startTagToken.sourceSpan, `Only void and foreign elements can be self closed "${startTagToken.parts[1]}"`));
  7476. }
  7477. }
  7478. else if (this._peek.type === TokenType$1.TAG_OPEN_END) {
  7479. this._advance();
  7480. selfClosing = false;
  7481. }
  7482. const /** @type {?} */ end = this._peek.sourceSpan.start;
  7483. const /** @type {?} */ span = new ParseSourceSpan(startTagToken.sourceSpan.start, end);
  7484. const /** @type {?} */ el = new Element(fullName, attrs, [], span, span, undefined);
  7485. this._pushElement(el);
  7486. if (selfClosing) {
  7487. this._popElement(fullName);
  7488. el.endSourceSpan = span;
  7489. }
  7490. }
  7491. /**
  7492. * @param {?} el
  7493. * @return {?}
  7494. */
  7495. _pushElement(el) {
  7496. const /** @type {?} */ parentEl = this._getParentElement();
  7497. if (parentEl && this.getTagDefinition(parentEl.name).isClosedByChild(el.name)) {
  7498. this._elementStack.pop();
  7499. }
  7500. const /** @type {?} */ tagDef = this.getTagDefinition(el.name);
  7501. const { parent, container } = this._getParentElementSkippingContainers();
  7502. if (parent && tagDef.requireExtraParent(parent.name)) {
  7503. const /** @type {?} */ newParent = new Element(tagDef.parentToAdd, [], [], el.sourceSpan, el.startSourceSpan, el.endSourceSpan);
  7504. this._insertBeforeContainer(parent, container, newParent);
  7505. }
  7506. this._addToParent(el);
  7507. this._elementStack.push(el);
  7508. }
  7509. /**
  7510. * @param {?} endTagToken
  7511. * @return {?}
  7512. */
  7513. _consumeEndTag(endTagToken) {
  7514. const /** @type {?} */ fullName = this._getElementFullName(endTagToken.parts[0], endTagToken.parts[1], this._getParentElement());
  7515. if (this._getParentElement()) {
  7516. /** @type {?} */ ((this._getParentElement())).endSourceSpan = endTagToken.sourceSpan;
  7517. }
  7518. if (this.getTagDefinition(fullName).isVoid) {
  7519. this._errors.push(TreeError.create(fullName, endTagToken.sourceSpan, `Void elements do not have end tags "${endTagToken.parts[1]}"`));
  7520. }
  7521. else if (!this._popElement(fullName)) {
  7522. const /** @type {?} */ errMsg = `Unexpected closing tag "${fullName}". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags`;
  7523. this._errors.push(TreeError.create(fullName, endTagToken.sourceSpan, errMsg));
  7524. }
  7525. }
  7526. /**
  7527. * @param {?} fullName
  7528. * @return {?}
  7529. */
  7530. _popElement(fullName) {
  7531. for (let /** @type {?} */ stackIndex = this._elementStack.length - 1; stackIndex >= 0; stackIndex--) {
  7532. const /** @type {?} */ el = this._elementStack[stackIndex];
  7533. if (el.name == fullName) {
  7534. this._elementStack.splice(stackIndex, this._elementStack.length - stackIndex);
  7535. return true;
  7536. }
  7537. if (!this.getTagDefinition(el.name).closedByParent) {
  7538. return false;
  7539. }
  7540. }
  7541. return false;
  7542. }
  7543. /**
  7544. * @param {?} attrName
  7545. * @return {?}
  7546. */
  7547. _consumeAttr(attrName) {
  7548. const /** @type {?} */ fullName = mergeNsAndName(attrName.parts[0], attrName.parts[1]);
  7549. let /** @type {?} */ end = attrName.sourceSpan.end;
  7550. let /** @type {?} */ value = '';
  7551. let /** @type {?} */ valueSpan = /** @type {?} */ ((undefined));
  7552. if (this._peek.type === TokenType$1.ATTR_VALUE) {
  7553. const /** @type {?} */ valueToken = this._advance();
  7554. value = valueToken.parts[0];
  7555. end = valueToken.sourceSpan.end;
  7556. valueSpan = valueToken.sourceSpan;
  7557. }
  7558. return new Attribute$1(fullName, value, new ParseSourceSpan(attrName.sourceSpan.start, end), valueSpan);
  7559. }
  7560. /**
  7561. * @return {?}
  7562. */
  7563. _getParentElement() {
  7564. return this._elementStack.length > 0 ? this._elementStack[this._elementStack.length - 1] : null;
  7565. }
  7566. /**
  7567. * Returns the parent in the DOM and the container.
  7568. *
  7569. * `<ng-container>` elements are skipped as they are not rendered as DOM element.
  7570. * @return {?}
  7571. */
  7572. _getParentElementSkippingContainers() {
  7573. let /** @type {?} */ container = null;
  7574. for (let /** @type {?} */ i = this._elementStack.length - 1; i >= 0; i--) {
  7575. if (!isNgContainer(this._elementStack[i].name)) {
  7576. return { parent: this._elementStack[i], container };
  7577. }
  7578. container = this._elementStack[i];
  7579. }
  7580. return { parent: null, container };
  7581. }
  7582. /**
  7583. * @param {?} node
  7584. * @return {?}
  7585. */
  7586. _addToParent(node) {
  7587. const /** @type {?} */ parent = this._getParentElement();
  7588. if (parent != null) {
  7589. parent.children.push(node);
  7590. }
  7591. else {
  7592. this._rootNodes.push(node);
  7593. }
  7594. }
  7595. /**
  7596. * Insert a node between the parent and the container.
  7597. * When no container is given, the node is appended as a child of the parent.
  7598. * Also updates the element stack accordingly.
  7599. *
  7600. * \@internal
  7601. * @param {?} parent
  7602. * @param {?} container
  7603. * @param {?} node
  7604. * @return {?}
  7605. */
  7606. _insertBeforeContainer(parent, container, node) {
  7607. if (!container) {
  7608. this._addToParent(node);
  7609. this._elementStack.push(node);
  7610. }
  7611. else {
  7612. if (parent) {
  7613. // replace the container with the new node in the children
  7614. const /** @type {?} */ index = parent.children.indexOf(container);
  7615. parent.children[index] = node;
  7616. }
  7617. else {
  7618. this._rootNodes.push(node);
  7619. }
  7620. node.children.push(container);
  7621. this._elementStack.splice(this._elementStack.indexOf(container), 0, node);
  7622. }
  7623. }
  7624. /**
  7625. * @param {?} prefix
  7626. * @param {?} localName
  7627. * @param {?} parentElement
  7628. * @return {?}
  7629. */
  7630. _getElementFullName(prefix, localName, parentElement) {
  7631. if (prefix == null) {
  7632. prefix = /** @type {?} */ ((this.getTagDefinition(localName).implicitNamespacePrefix));
  7633. if (prefix == null && parentElement != null) {
  7634. prefix = getNsPrefix(parentElement.name);
  7635. }
  7636. }
  7637. return mergeNsAndName(prefix, localName);
  7638. }
  7639. }
  7640. /**
  7641. * @param {?} stack
  7642. * @param {?} element
  7643. * @return {?}
  7644. */
  7645. function lastOnStack(stack, element) {
  7646. return stack.length > 0 && stack[stack.length - 1] === element;
  7647. }
  7648. /**
  7649. * @fileoverview added by tsickle
  7650. * @suppress {checkTypes} checked by tsc
  7651. */
  7652. /**
  7653. * @license
  7654. * Copyright Google Inc. All Rights Reserved.
  7655. *
  7656. * Use of this source code is governed by an MIT-style license that can be
  7657. * found in the LICENSE file at https://angular.io/license
  7658. */
  7659. /**
  7660. * @param {?} message
  7661. * @return {?}
  7662. */
  7663. function digest(message) {
  7664. return message.id || sha1(serializeNodes(message.nodes).join('') + `[${message.meaning}]`);
  7665. }
  7666. /**
  7667. * @param {?} message
  7668. * @return {?}
  7669. */
  7670. function decimalDigest(message) {
  7671. if (message.id) {
  7672. return message.id;
  7673. }
  7674. const /** @type {?} */ visitor = new _SerializerIgnoreIcuExpVisitor();
  7675. const /** @type {?} */ parts = message.nodes.map(a => a.visit(visitor, null));
  7676. return computeMsgId(parts.join(''), message.meaning);
  7677. }
  7678. /**
  7679. * Serialize the i18n ast to something xml-like in order to generate an UID.
  7680. *
  7681. * The visitor is also used in the i18n parser tests
  7682. *
  7683. * \@internal
  7684. */
  7685. class _SerializerVisitor {
  7686. /**
  7687. * @param {?} text
  7688. * @param {?} context
  7689. * @return {?}
  7690. */
  7691. visitText(text, context) { return text.value; }
  7692. /**
  7693. * @param {?} container
  7694. * @param {?} context
  7695. * @return {?}
  7696. */
  7697. visitContainer(container, context) {
  7698. return `[${container.children.map(child => child.visit(this)).join(', ')}]`;
  7699. }
  7700. /**
  7701. * @param {?} icu
  7702. * @param {?} context
  7703. * @return {?}
  7704. */
  7705. visitIcu(icu, context) {
  7706. const /** @type {?} */ strCases = Object.keys(icu.cases).map((k) => `${k} {${icu.cases[k].visit(this)}}`);
  7707. return `{${icu.expression}, ${icu.type}, ${strCases.join(', ')}}`;
  7708. }
  7709. /**
  7710. * @param {?} ph
  7711. * @param {?} context
  7712. * @return {?}
  7713. */
  7714. visitTagPlaceholder(ph, context) {
  7715. return ph.isVoid ?
  7716. `<ph tag name="${ph.startName}"/>` :
  7717. `<ph tag name="${ph.startName}">${ph.children.map(child => child.visit(this)).join(', ')}</ph name="${ph.closeName}">`;
  7718. }
  7719. /**
  7720. * @param {?} ph
  7721. * @param {?} context
  7722. * @return {?}
  7723. */
  7724. visitPlaceholder(ph, context) {
  7725. return ph.value ? `<ph name="${ph.name}">${ph.value}</ph>` : `<ph name="${ph.name}"/>`;
  7726. }
  7727. /**
  7728. * @param {?} ph
  7729. * @param {?=} context
  7730. * @return {?}
  7731. */
  7732. visitIcuPlaceholder(ph, context) {
  7733. return `<ph icu name="${ph.name}">${ph.value.visit(this)}</ph>`;
  7734. }
  7735. }
  7736. const serializerVisitor = new _SerializerVisitor();
  7737. /**
  7738. * @param {?} nodes
  7739. * @return {?}
  7740. */
  7741. function serializeNodes(nodes) {
  7742. return nodes.map(a => a.visit(serializerVisitor, null));
  7743. }
  7744. /**
  7745. * Serialize the i18n ast to something xml-like in order to generate an UID.
  7746. *
  7747. * Ignore the ICU expressions so that message IDs stays identical if only the expression changes.
  7748. *
  7749. * \@internal
  7750. */
  7751. class _SerializerIgnoreIcuExpVisitor extends _SerializerVisitor {
  7752. /**
  7753. * @param {?} icu
  7754. * @param {?} context
  7755. * @return {?}
  7756. */
  7757. visitIcu(icu, context) {
  7758. let /** @type {?} */ strCases = Object.keys(icu.cases).map((k) => `${k} {${icu.cases[k].visit(this)}}`);
  7759. // Do not take the expression into account
  7760. return `{${icu.type}, ${strCases.join(', ')}}`;
  7761. }
  7762. }
  7763. /**
  7764. * Compute the SHA1 of the given string
  7765. *
  7766. * see http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
  7767. *
  7768. * WARNING: this function has not been designed not tested with security in mind.
  7769. * DO NOT USE IT IN A SECURITY SENSITIVE CONTEXT.
  7770. * @param {?} str
  7771. * @return {?}
  7772. */
  7773. function sha1(str) {
  7774. const /** @type {?} */ utf8 = utf8Encode(str);
  7775. const /** @type {?} */ words32 = stringToWords32(utf8, Endian.Big);
  7776. const /** @type {?} */ len = utf8.length * 8;
  7777. const /** @type {?} */ w = new Array(80);
  7778. let [a, b, c, d, e] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  7779. words32[len >> 5] |= 0x80 << (24 - len % 32);
  7780. words32[((len + 64 >> 9) << 4) + 15] = len;
  7781. for (let /** @type {?} */ i = 0; i < words32.length; i += 16) {
  7782. const [h0, h1, h2, h3, h4] = [a, b, c, d, e];
  7783. for (let /** @type {?} */ j = 0; j < 80; j++) {
  7784. if (j < 16) {
  7785. w[j] = words32[i + j];
  7786. }
  7787. else {
  7788. w[j] = rol32(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
  7789. }
  7790. const [f, k] = fk(j, b, c, d);
  7791. const /** @type {?} */ temp = [rol32(a, 5), f, e, k, w[j]].reduce(add32);
  7792. [e, d, c, b, a] = [d, c, rol32(b, 30), a, temp];
  7793. }
  7794. [a, b, c, d, e] = [add32(a, h0), add32(b, h1), add32(c, h2), add32(d, h3), add32(e, h4)];
  7795. }
  7796. return byteStringToHexString(words32ToByteString([a, b, c, d, e]));
  7797. }
  7798. /**
  7799. * @param {?} index
  7800. * @param {?} b
  7801. * @param {?} c
  7802. * @param {?} d
  7803. * @return {?}
  7804. */
  7805. function fk(index, b, c, d) {
  7806. if (index < 20) {
  7807. return [(b & c) | (~b & d), 0x5a827999];
  7808. }
  7809. if (index < 40) {
  7810. return [b ^ c ^ d, 0x6ed9eba1];
  7811. }
  7812. if (index < 60) {
  7813. return [(b & c) | (b & d) | (c & d), 0x8f1bbcdc];
  7814. }
  7815. return [b ^ c ^ d, 0xca62c1d6];
  7816. }
  7817. /**
  7818. * Compute the fingerprint of the given string
  7819. *
  7820. * The output is 64 bit number encoded as a decimal string
  7821. *
  7822. * based on:
  7823. * https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/GoogleJsMessageIdGenerator.java
  7824. * @param {?} str
  7825. * @return {?}
  7826. */
  7827. function fingerprint(str) {
  7828. const /** @type {?} */ utf8 = utf8Encode(str);
  7829. let [hi, lo] = [hash32(utf8, 0), hash32(utf8, 102072)];
  7830. if (hi == 0 && (lo == 0 || lo == 1)) {
  7831. hi = hi ^ 0x130f9bef;
  7832. lo = lo ^ -0x6b5f56d8;
  7833. }
  7834. return [hi, lo];
  7835. }
  7836. /**
  7837. * @param {?} msg
  7838. * @param {?} meaning
  7839. * @return {?}
  7840. */
  7841. function computeMsgId(msg, meaning) {
  7842. let [hi, lo] = fingerprint(msg);
  7843. if (meaning) {
  7844. const [him, lom] = fingerprint(meaning);
  7845. [hi, lo] = add64(rol64([hi, lo], 1), [him, lom]);
  7846. }
  7847. return byteStringToDecString(words32ToByteString([hi & 0x7fffffff, lo]));
  7848. }
  7849. /**
  7850. * @param {?} str
  7851. * @param {?} c
  7852. * @return {?}
  7853. */
  7854. function hash32(str, c) {
  7855. let [a, b] = [0x9e3779b9, 0x9e3779b9];
  7856. let /** @type {?} */ i;
  7857. const /** @type {?} */ len = str.length;
  7858. for (i = 0; i + 12 <= len; i += 12) {
  7859. a = add32(a, wordAt(str, i, Endian.Little));
  7860. b = add32(b, wordAt(str, i + 4, Endian.Little));
  7861. c = add32(c, wordAt(str, i + 8, Endian.Little));
  7862. [a, b, c] = mix([a, b, c]);
  7863. }
  7864. a = add32(a, wordAt(str, i, Endian.Little));
  7865. b = add32(b, wordAt(str, i + 4, Endian.Little));
  7866. // the first byte of c is reserved for the length
  7867. c = add32(c, len);
  7868. c = add32(c, wordAt(str, i + 8, Endian.Little) << 8);
  7869. return mix([a, b, c])[2];
  7870. }
  7871. /**
  7872. * @param {?} __0
  7873. * @return {?}
  7874. */
  7875. function mix([a, b, c]) {
  7876. a = sub32(a, b);
  7877. a = sub32(a, c);
  7878. a ^= c >>> 13;
  7879. b = sub32(b, c);
  7880. b = sub32(b, a);
  7881. b ^= a << 8;
  7882. c = sub32(c, a);
  7883. c = sub32(c, b);
  7884. c ^= b >>> 13;
  7885. a = sub32(a, b);
  7886. a = sub32(a, c);
  7887. a ^= c >>> 12;
  7888. b = sub32(b, c);
  7889. b = sub32(b, a);
  7890. b ^= a << 16;
  7891. c = sub32(c, a);
  7892. c = sub32(c, b);
  7893. c ^= b >>> 5;
  7894. a = sub32(a, b);
  7895. a = sub32(a, c);
  7896. a ^= c >>> 3;
  7897. b = sub32(b, c);
  7898. b = sub32(b, a);
  7899. b ^= a << 10;
  7900. c = sub32(c, a);
  7901. c = sub32(c, b);
  7902. c ^= b >>> 15;
  7903. return [a, b, c];
  7904. }
  7905. /** @enum {number} */
  7906. const Endian = {
  7907. Little: 0,
  7908. Big: 1,
  7909. };
  7910. Endian[Endian.Little] = "Little";
  7911. Endian[Endian.Big] = "Big";
  7912. /**
  7913. * @param {?} a
  7914. * @param {?} b
  7915. * @return {?}
  7916. */
  7917. function add32(a, b) {
  7918. return add32to64(a, b)[1];
  7919. }
  7920. /**
  7921. * @param {?} a
  7922. * @param {?} b
  7923. * @return {?}
  7924. */
  7925. function add32to64(a, b) {
  7926. const /** @type {?} */ low = (a & 0xffff) + (b & 0xffff);
  7927. const /** @type {?} */ high = (a >>> 16) + (b >>> 16) + (low >>> 16);
  7928. return [high >>> 16, (high << 16) | (low & 0xffff)];
  7929. }
  7930. /**
  7931. * @param {?} __0
  7932. * @param {?} __1
  7933. * @return {?}
  7934. */
  7935. function add64([ah, al], [bh, bl]) {
  7936. const [carry, l] = add32to64(al, bl);
  7937. const /** @type {?} */ h = add32(add32(ah, bh), carry);
  7938. return [h, l];
  7939. }
  7940. /**
  7941. * @param {?} a
  7942. * @param {?} b
  7943. * @return {?}
  7944. */
  7945. function sub32(a, b) {
  7946. const /** @type {?} */ low = (a & 0xffff) - (b & 0xffff);
  7947. const /** @type {?} */ high = (a >> 16) - (b >> 16) + (low >> 16);
  7948. return (high << 16) | (low & 0xffff);
  7949. }
  7950. /**
  7951. * @param {?} a
  7952. * @param {?} count
  7953. * @return {?}
  7954. */
  7955. function rol32(a, count) {
  7956. return (a << count) | (a >>> (32 - count));
  7957. }
  7958. /**
  7959. * @param {?} __0
  7960. * @param {?} count
  7961. * @return {?}
  7962. */
  7963. function rol64([hi, lo], count) {
  7964. const /** @type {?} */ h = (hi << count) | (lo >>> (32 - count));
  7965. const /** @type {?} */ l = (lo << count) | (hi >>> (32 - count));
  7966. return [h, l];
  7967. }
  7968. /**
  7969. * @param {?} str
  7970. * @param {?} endian
  7971. * @return {?}
  7972. */
  7973. function stringToWords32(str, endian) {
  7974. const /** @type {?} */ words32 = Array((str.length + 3) >>> 2);
  7975. for (let /** @type {?} */ i = 0; i < words32.length; i++) {
  7976. words32[i] = wordAt(str, i * 4, endian);
  7977. }
  7978. return words32;
  7979. }
  7980. /**
  7981. * @param {?} str
  7982. * @param {?} index
  7983. * @return {?}
  7984. */
  7985. function byteAt(str, index) {
  7986. return index >= str.length ? 0 : str.charCodeAt(index) & 0xff;
  7987. }
  7988. /**
  7989. * @param {?} str
  7990. * @param {?} index
  7991. * @param {?} endian
  7992. * @return {?}
  7993. */
  7994. function wordAt(str, index, endian) {
  7995. let /** @type {?} */ word = 0;
  7996. if (endian === Endian.Big) {
  7997. for (let /** @type {?} */ i = 0; i < 4; i++) {
  7998. word += byteAt(str, index + i) << (24 - 8 * i);
  7999. }
  8000. }
  8001. else {
  8002. for (let /** @type {?} */ i = 0; i < 4; i++) {
  8003. word += byteAt(str, index + i) << 8 * i;
  8004. }
  8005. }
  8006. return word;
  8007. }
  8008. /**
  8009. * @param {?} words32
  8010. * @return {?}
  8011. */
  8012. function words32ToByteString(words32) {
  8013. return words32.reduce((str, word) => str + word32ToByteString(word), '');
  8014. }
  8015. /**
  8016. * @param {?} word
  8017. * @return {?}
  8018. */
  8019. function word32ToByteString(word) {
  8020. let /** @type {?} */ str = '';
  8021. for (let /** @type {?} */ i = 0; i < 4; i++) {
  8022. str += String.fromCharCode((word >>> 8 * (3 - i)) & 0xff);
  8023. }
  8024. return str;
  8025. }
  8026. /**
  8027. * @param {?} str
  8028. * @return {?}
  8029. */
  8030. function byteStringToHexString(str) {
  8031. let /** @type {?} */ hex = '';
  8032. for (let /** @type {?} */ i = 0; i < str.length; i++) {
  8033. const /** @type {?} */ b = byteAt(str, i);
  8034. hex += (b >>> 4).toString(16) + (b & 0x0f).toString(16);
  8035. }
  8036. return hex.toLowerCase();
  8037. }
  8038. /**
  8039. * @param {?} str
  8040. * @return {?}
  8041. */
  8042. function byteStringToDecString(str) {
  8043. let /** @type {?} */ decimal = '';
  8044. let /** @type {?} */ toThePower = '1';
  8045. for (let /** @type {?} */ i = str.length - 1; i >= 0; i--) {
  8046. decimal = addBigInt(decimal, numberTimesBigInt(byteAt(str, i), toThePower));
  8047. toThePower = numberTimesBigInt(256, toThePower);
  8048. }
  8049. return decimal.split('').reverse().join('');
  8050. }
  8051. /**
  8052. * @param {?} x
  8053. * @param {?} y
  8054. * @return {?}
  8055. */
  8056. function addBigInt(x, y) {
  8057. let /** @type {?} */ sum = '';
  8058. const /** @type {?} */ len = Math.max(x.length, y.length);
  8059. for (let /** @type {?} */ i = 0, /** @type {?} */ carry = 0; i < len || carry; i++) {
  8060. const /** @type {?} */ tmpSum = carry + +(x[i] || 0) + +(y[i] || 0);
  8061. if (tmpSum >= 10) {
  8062. carry = 1;
  8063. sum += tmpSum - 10;
  8064. }
  8065. else {
  8066. carry = 0;
  8067. sum += tmpSum;
  8068. }
  8069. }
  8070. return sum;
  8071. }
  8072. /**
  8073. * @param {?} num
  8074. * @param {?} b
  8075. * @return {?}
  8076. */
  8077. function numberTimesBigInt(num, b) {
  8078. let /** @type {?} */ product = '';
  8079. let /** @type {?} */ bToThePower = b;
  8080. for (; num !== 0; num = num >>> 1) {
  8081. if (num & 1)
  8082. product = addBigInt(product, bToThePower);
  8083. bToThePower = addBigInt(bToThePower, bToThePower);
  8084. }
  8085. return product;
  8086. }
  8087. /**
  8088. * @fileoverview added by tsickle
  8089. * @suppress {checkTypes} checked by tsc
  8090. */
  8091. /**
  8092. * @license
  8093. * Copyright Google Inc. All Rights Reserved.
  8094. *
  8095. * Use of this source code is governed by an MIT-style license that can be
  8096. * found in the LICENSE file at https://angular.io/license
  8097. */
  8098. class Message {
  8099. /**
  8100. * @param {?} nodes message AST
  8101. * @param {?} placeholders maps placeholder names to static content
  8102. * @param {?} placeholderToMessage maps placeholder names to messages (used for nested ICU messages)
  8103. * @param {?} meaning
  8104. * @param {?} description
  8105. * @param {?} id
  8106. */
  8107. constructor(nodes, placeholders, placeholderToMessage, meaning, description, id) {
  8108. this.nodes = nodes;
  8109. this.placeholders = placeholders;
  8110. this.placeholderToMessage = placeholderToMessage;
  8111. this.meaning = meaning;
  8112. this.description = description;
  8113. this.id = id;
  8114. if (nodes.length) {
  8115. this.sources = [{
  8116. filePath: nodes[0].sourceSpan.start.file.url,
  8117. startLine: nodes[0].sourceSpan.start.line + 1,
  8118. startCol: nodes[0].sourceSpan.start.col + 1,
  8119. endLine: nodes[nodes.length - 1].sourceSpan.end.line + 1,
  8120. endCol: nodes[0].sourceSpan.start.col + 1
  8121. }];
  8122. }
  8123. else {
  8124. this.sources = [];
  8125. }
  8126. }
  8127. }
  8128. /**
  8129. * @record
  8130. */
  8131. /**
  8132. * @record
  8133. */
  8134. class Text$1 {
  8135. /**
  8136. * @param {?} value
  8137. * @param {?} sourceSpan
  8138. */
  8139. constructor(value, sourceSpan) {
  8140. this.value = value;
  8141. this.sourceSpan = sourceSpan;
  8142. }
  8143. /**
  8144. * @param {?} visitor
  8145. * @param {?=} context
  8146. * @return {?}
  8147. */
  8148. visit(visitor, context) { return visitor.visitText(this, context); }
  8149. }
  8150. class Container {
  8151. /**
  8152. * @param {?} children
  8153. * @param {?} sourceSpan
  8154. */
  8155. constructor(children, sourceSpan) {
  8156. this.children = children;
  8157. this.sourceSpan = sourceSpan;
  8158. }
  8159. /**
  8160. * @param {?} visitor
  8161. * @param {?=} context
  8162. * @return {?}
  8163. */
  8164. visit(visitor, context) { return visitor.visitContainer(this, context); }
  8165. }
  8166. class Icu {
  8167. /**
  8168. * @param {?} expression
  8169. * @param {?} type
  8170. * @param {?} cases
  8171. * @param {?} sourceSpan
  8172. */
  8173. constructor(expression, type, cases, sourceSpan) {
  8174. this.expression = expression;
  8175. this.type = type;
  8176. this.cases = cases;
  8177. this.sourceSpan = sourceSpan;
  8178. }
  8179. /**
  8180. * @param {?} visitor
  8181. * @param {?=} context
  8182. * @return {?}
  8183. */
  8184. visit(visitor, context) { return visitor.visitIcu(this, context); }
  8185. }
  8186. class TagPlaceholder {
  8187. /**
  8188. * @param {?} tag
  8189. * @param {?} attrs
  8190. * @param {?} startName
  8191. * @param {?} closeName
  8192. * @param {?} children
  8193. * @param {?} isVoid
  8194. * @param {?} sourceSpan
  8195. */
  8196. constructor(tag, attrs, startName, closeName, children, isVoid, sourceSpan) {
  8197. this.tag = tag;
  8198. this.attrs = attrs;
  8199. this.startName = startName;
  8200. this.closeName = closeName;
  8201. this.children = children;
  8202. this.isVoid = isVoid;
  8203. this.sourceSpan = sourceSpan;
  8204. }
  8205. /**
  8206. * @param {?} visitor
  8207. * @param {?=} context
  8208. * @return {?}
  8209. */
  8210. visit(visitor, context) { return visitor.visitTagPlaceholder(this, context); }
  8211. }
  8212. class Placeholder {
  8213. /**
  8214. * @param {?} value
  8215. * @param {?} name
  8216. * @param {?} sourceSpan
  8217. */
  8218. constructor(value, name, sourceSpan) {
  8219. this.value = value;
  8220. this.name = name;
  8221. this.sourceSpan = sourceSpan;
  8222. }
  8223. /**
  8224. * @param {?} visitor
  8225. * @param {?=} context
  8226. * @return {?}
  8227. */
  8228. visit(visitor, context) { return visitor.visitPlaceholder(this, context); }
  8229. }
  8230. class IcuPlaceholder {
  8231. /**
  8232. * @param {?} value
  8233. * @param {?} name
  8234. * @param {?} sourceSpan
  8235. */
  8236. constructor(value, name, sourceSpan) {
  8237. this.value = value;
  8238. this.name = name;
  8239. this.sourceSpan = sourceSpan;
  8240. }
  8241. /**
  8242. * @param {?} visitor
  8243. * @param {?=} context
  8244. * @return {?}
  8245. */
  8246. visit(visitor, context) { return visitor.visitIcuPlaceholder(this, context); }
  8247. }
  8248. /**
  8249. * @record
  8250. */
  8251. class CloneVisitor {
  8252. /**
  8253. * @param {?} text
  8254. * @param {?=} context
  8255. * @return {?}
  8256. */
  8257. visitText(text, context) { return new Text$1(text.value, text.sourceSpan); }
  8258. /**
  8259. * @param {?} container
  8260. * @param {?=} context
  8261. * @return {?}
  8262. */
  8263. visitContainer(container, context) {
  8264. const /** @type {?} */ children = container.children.map(n => n.visit(this, context));
  8265. return new Container(children, container.sourceSpan);
  8266. }
  8267. /**
  8268. * @param {?} icu
  8269. * @param {?=} context
  8270. * @return {?}
  8271. */
  8272. visitIcu(icu, context) {
  8273. const /** @type {?} */ cases = {};
  8274. Object.keys(icu.cases).forEach(key => cases[key] = icu.cases[key].visit(this, context));
  8275. const /** @type {?} */ msg = new Icu(icu.expression, icu.type, cases, icu.sourceSpan);
  8276. msg.expressionPlaceholder = icu.expressionPlaceholder;
  8277. return msg;
  8278. }
  8279. /**
  8280. * @param {?} ph
  8281. * @param {?=} context
  8282. * @return {?}
  8283. */
  8284. visitTagPlaceholder(ph, context) {
  8285. const /** @type {?} */ children = ph.children.map(n => n.visit(this, context));
  8286. return new TagPlaceholder(ph.tag, ph.attrs, ph.startName, ph.closeName, children, ph.isVoid, ph.sourceSpan);
  8287. }
  8288. /**
  8289. * @param {?} ph
  8290. * @param {?=} context
  8291. * @return {?}
  8292. */
  8293. visitPlaceholder(ph, context) {
  8294. return new Placeholder(ph.value, ph.name, ph.sourceSpan);
  8295. }
  8296. /**
  8297. * @param {?} ph
  8298. * @param {?=} context
  8299. * @return {?}
  8300. */
  8301. visitIcuPlaceholder(ph, context) {
  8302. return new IcuPlaceholder(ph.value, ph.name, ph.sourceSpan);
  8303. }
  8304. }
  8305. class RecurseVisitor {
  8306. /**
  8307. * @param {?} text
  8308. * @param {?=} context
  8309. * @return {?}
  8310. */
  8311. visitText(text, context) { }
  8312. /**
  8313. * @param {?} container
  8314. * @param {?=} context
  8315. * @return {?}
  8316. */
  8317. visitContainer(container, context) {
  8318. container.children.forEach(child => child.visit(this));
  8319. }
  8320. /**
  8321. * @param {?} icu
  8322. * @param {?=} context
  8323. * @return {?}
  8324. */
  8325. visitIcu(icu, context) {
  8326. Object.keys(icu.cases).forEach(k => { icu.cases[k].visit(this); });
  8327. }
  8328. /**
  8329. * @param {?} ph
  8330. * @param {?=} context
  8331. * @return {?}
  8332. */
  8333. visitTagPlaceholder(ph, context) {
  8334. ph.children.forEach(child => child.visit(this));
  8335. }
  8336. /**
  8337. * @param {?} ph
  8338. * @param {?=} context
  8339. * @return {?}
  8340. */
  8341. visitPlaceholder(ph, context) { }
  8342. /**
  8343. * @param {?} ph
  8344. * @param {?=} context
  8345. * @return {?}
  8346. */
  8347. visitIcuPlaceholder(ph, context) { }
  8348. }
  8349. /**
  8350. * @fileoverview added by tsickle
  8351. * @suppress {checkTypes} checked by tsc
  8352. */
  8353. /**
  8354. * @license
  8355. * Copyright Google Inc. All Rights Reserved.
  8356. *
  8357. * Use of this source code is governed by an MIT-style license that can be
  8358. * found in the LICENSE file at https://angular.io/license
  8359. */
  8360. class HtmlTagDefinition {
  8361. /**
  8362. * @param {?=} __0
  8363. */
  8364. constructor({ closedByChildren, requiredParents, implicitNamespacePrefix, contentType = TagContentType.PARSABLE_DATA, closedByParent = false, isVoid = false, ignoreFirstLf = false } = {}) {
  8365. this.closedByChildren = {};
  8366. this.closedByParent = false;
  8367. this.canSelfClose = false;
  8368. if (closedByChildren && closedByChildren.length > 0) {
  8369. closedByChildren.forEach(tagName => this.closedByChildren[tagName] = true);
  8370. }
  8371. this.isVoid = isVoid;
  8372. this.closedByParent = closedByParent || isVoid;
  8373. if (requiredParents && requiredParents.length > 0) {
  8374. this.requiredParents = {};
  8375. // The first parent is the list is automatically when none of the listed parents are present
  8376. this.parentToAdd = requiredParents[0];
  8377. requiredParents.forEach(tagName => this.requiredParents[tagName] = true);
  8378. }
  8379. this.implicitNamespacePrefix = implicitNamespacePrefix || null;
  8380. this.contentType = contentType;
  8381. this.ignoreFirstLf = ignoreFirstLf;
  8382. }
  8383. /**
  8384. * @param {?} currentParent
  8385. * @return {?}
  8386. */
  8387. requireExtraParent(currentParent) {
  8388. if (!this.requiredParents) {
  8389. return false;
  8390. }
  8391. if (!currentParent) {
  8392. return true;
  8393. }
  8394. const /** @type {?} */ lcParent = currentParent.toLowerCase();
  8395. const /** @type {?} */ isParentTemplate = lcParent === 'template' || currentParent === 'ng-template';
  8396. return !isParentTemplate && this.requiredParents[lcParent] != true;
  8397. }
  8398. /**
  8399. * @param {?} name
  8400. * @return {?}
  8401. */
  8402. isClosedByChild(name) {
  8403. return this.isVoid || name.toLowerCase() in this.closedByChildren;
  8404. }
  8405. }
  8406. // see http://www.w3.org/TR/html51/syntax.html#optional-tags
  8407. // This implementation does not fully conform to the HTML5 spec.
  8408. const TAG_DEFINITIONS = {
  8409. 'base': new HtmlTagDefinition({ isVoid: true }),
  8410. 'meta': new HtmlTagDefinition({ isVoid: true }),
  8411. 'area': new HtmlTagDefinition({ isVoid: true }),
  8412. 'embed': new HtmlTagDefinition({ isVoid: true }),
  8413. 'link': new HtmlTagDefinition({ isVoid: true }),
  8414. 'img': new HtmlTagDefinition({ isVoid: true }),
  8415. 'input': new HtmlTagDefinition({ isVoid: true }),
  8416. 'param': new HtmlTagDefinition({ isVoid: true }),
  8417. 'hr': new HtmlTagDefinition({ isVoid: true }),
  8418. 'br': new HtmlTagDefinition({ isVoid: true }),
  8419. 'source': new HtmlTagDefinition({ isVoid: true }),
  8420. 'track': new HtmlTagDefinition({ isVoid: true }),
  8421. 'wbr': new HtmlTagDefinition({ isVoid: true }),
  8422. 'p': new HtmlTagDefinition({
  8423. closedByChildren: [
  8424. 'address', 'article', 'aside', 'blockquote', 'div', 'dl', 'fieldset', 'footer', 'form',
  8425. 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr',
  8426. 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'
  8427. ],
  8428. closedByParent: true
  8429. }),
  8430. 'thead': new HtmlTagDefinition({ closedByChildren: ['tbody', 'tfoot'] }),
  8431. 'tbody': new HtmlTagDefinition({ closedByChildren: ['tbody', 'tfoot'], closedByParent: true }),
  8432. 'tfoot': new HtmlTagDefinition({ closedByChildren: ['tbody'], closedByParent: true }),
  8433. 'tr': new HtmlTagDefinition({
  8434. closedByChildren: ['tr'],
  8435. requiredParents: ['tbody', 'tfoot', 'thead'],
  8436. closedByParent: true
  8437. }),
  8438. 'td': new HtmlTagDefinition({ closedByChildren: ['td', 'th'], closedByParent: true }),
  8439. 'th': new HtmlTagDefinition({ closedByChildren: ['td', 'th'], closedByParent: true }),
  8440. 'col': new HtmlTagDefinition({ requiredParents: ['colgroup'], isVoid: true }),
  8441. 'svg': new HtmlTagDefinition({ implicitNamespacePrefix: 'svg' }),
  8442. 'math': new HtmlTagDefinition({ implicitNamespacePrefix: 'math' }),
  8443. 'li': new HtmlTagDefinition({ closedByChildren: ['li'], closedByParent: true }),
  8444. 'dt': new HtmlTagDefinition({ closedByChildren: ['dt', 'dd'] }),
  8445. 'dd': new HtmlTagDefinition({ closedByChildren: ['dt', 'dd'], closedByParent: true }),
  8446. 'rb': new HtmlTagDefinition({ closedByChildren: ['rb', 'rt', 'rtc', 'rp'], closedByParent: true }),
  8447. 'rt': new HtmlTagDefinition({ closedByChildren: ['rb', 'rt', 'rtc', 'rp'], closedByParent: true }),
  8448. 'rtc': new HtmlTagDefinition({ closedByChildren: ['rb', 'rtc', 'rp'], closedByParent: true }),
  8449. 'rp': new HtmlTagDefinition({ closedByChildren: ['rb', 'rt', 'rtc', 'rp'], closedByParent: true }),
  8450. 'optgroup': new HtmlTagDefinition({ closedByChildren: ['optgroup'], closedByParent: true }),
  8451. 'option': new HtmlTagDefinition({ closedByChildren: ['option', 'optgroup'], closedByParent: true }),
  8452. 'pre': new HtmlTagDefinition({ ignoreFirstLf: true }),
  8453. 'listing': new HtmlTagDefinition({ ignoreFirstLf: true }),
  8454. 'style': new HtmlTagDefinition({ contentType: TagContentType.RAW_TEXT }),
  8455. 'script': new HtmlTagDefinition({ contentType: TagContentType.RAW_TEXT }),
  8456. 'title': new HtmlTagDefinition({ contentType: TagContentType.ESCAPABLE_RAW_TEXT }),
  8457. 'textarea': new HtmlTagDefinition({ contentType: TagContentType.ESCAPABLE_RAW_TEXT, ignoreFirstLf: true }),
  8458. };
  8459. const _DEFAULT_TAG_DEFINITION = new HtmlTagDefinition();
  8460. /**
  8461. * @param {?} tagName
  8462. * @return {?}
  8463. */
  8464. function getHtmlTagDefinition(tagName) {
  8465. return TAG_DEFINITIONS[tagName.toLowerCase()] || _DEFAULT_TAG_DEFINITION;
  8466. }
  8467. /**
  8468. * @fileoverview added by tsickle
  8469. * @suppress {checkTypes} checked by tsc
  8470. */
  8471. /**
  8472. * @license
  8473. * Copyright Google Inc. All Rights Reserved.
  8474. *
  8475. * Use of this source code is governed by an MIT-style license that can be
  8476. * found in the LICENSE file at https://angular.io/license
  8477. */
  8478. const TAG_TO_PLACEHOLDER_NAMES = {
  8479. 'A': 'LINK',
  8480. 'B': 'BOLD_TEXT',
  8481. 'BR': 'LINE_BREAK',
  8482. 'EM': 'EMPHASISED_TEXT',
  8483. 'H1': 'HEADING_LEVEL1',
  8484. 'H2': 'HEADING_LEVEL2',
  8485. 'H3': 'HEADING_LEVEL3',
  8486. 'H4': 'HEADING_LEVEL4',
  8487. 'H5': 'HEADING_LEVEL5',
  8488. 'H6': 'HEADING_LEVEL6',
  8489. 'HR': 'HORIZONTAL_RULE',
  8490. 'I': 'ITALIC_TEXT',
  8491. 'LI': 'LIST_ITEM',
  8492. 'LINK': 'MEDIA_LINK',
  8493. 'OL': 'ORDERED_LIST',
  8494. 'P': 'PARAGRAPH',
  8495. 'Q': 'QUOTATION',
  8496. 'S': 'STRIKETHROUGH_TEXT',
  8497. 'SMALL': 'SMALL_TEXT',
  8498. 'SUB': 'SUBSTRIPT',
  8499. 'SUP': 'SUPERSCRIPT',
  8500. 'TBODY': 'TABLE_BODY',
  8501. 'TD': 'TABLE_CELL',
  8502. 'TFOOT': 'TABLE_FOOTER',
  8503. 'TH': 'TABLE_HEADER_CELL',
  8504. 'THEAD': 'TABLE_HEADER',
  8505. 'TR': 'TABLE_ROW',
  8506. 'TT': 'MONOSPACED_TEXT',
  8507. 'U': 'UNDERLINED_TEXT',
  8508. 'UL': 'UNORDERED_LIST',
  8509. };
  8510. /**
  8511. * Creates unique names for placeholder with different content.
  8512. *
  8513. * Returns the same placeholder name when the content is identical.
  8514. */
  8515. class PlaceholderRegistry {
  8516. constructor() {
  8517. this._placeHolderNameCounts = {};
  8518. this._signatureToName = {};
  8519. }
  8520. /**
  8521. * @param {?} tag
  8522. * @param {?} attrs
  8523. * @param {?} isVoid
  8524. * @return {?}
  8525. */
  8526. getStartTagPlaceholderName(tag, attrs, isVoid) {
  8527. const /** @type {?} */ signature = this._hashTag(tag, attrs, isVoid);
  8528. if (this._signatureToName[signature]) {
  8529. return this._signatureToName[signature];
  8530. }
  8531. const /** @type {?} */ upperTag = tag.toUpperCase();
  8532. const /** @type {?} */ baseName = TAG_TO_PLACEHOLDER_NAMES[upperTag] || `TAG_${upperTag}`;
  8533. const /** @type {?} */ name = this._generateUniqueName(isVoid ? baseName : `START_${baseName}`);
  8534. this._signatureToName[signature] = name;
  8535. return name;
  8536. }
  8537. /**
  8538. * @param {?} tag
  8539. * @return {?}
  8540. */
  8541. getCloseTagPlaceholderName(tag) {
  8542. const /** @type {?} */ signature = this._hashClosingTag(tag);
  8543. if (this._signatureToName[signature]) {
  8544. return this._signatureToName[signature];
  8545. }
  8546. const /** @type {?} */ upperTag = tag.toUpperCase();
  8547. const /** @type {?} */ baseName = TAG_TO_PLACEHOLDER_NAMES[upperTag] || `TAG_${upperTag}`;
  8548. const /** @type {?} */ name = this._generateUniqueName(`CLOSE_${baseName}`);
  8549. this._signatureToName[signature] = name;
  8550. return name;
  8551. }
  8552. /**
  8553. * @param {?} name
  8554. * @param {?} content
  8555. * @return {?}
  8556. */
  8557. getPlaceholderName(name, content) {
  8558. const /** @type {?} */ upperName = name.toUpperCase();
  8559. const /** @type {?} */ signature = `PH: ${upperName}=${content}`;
  8560. if (this._signatureToName[signature]) {
  8561. return this._signatureToName[signature];
  8562. }
  8563. const /** @type {?} */ uniqueName = this._generateUniqueName(upperName);
  8564. this._signatureToName[signature] = uniqueName;
  8565. return uniqueName;
  8566. }
  8567. /**
  8568. * @param {?} name
  8569. * @return {?}
  8570. */
  8571. getUniquePlaceholder(name) {
  8572. return this._generateUniqueName(name.toUpperCase());
  8573. }
  8574. /**
  8575. * @param {?} tag
  8576. * @param {?} attrs
  8577. * @param {?} isVoid
  8578. * @return {?}
  8579. */
  8580. _hashTag(tag, attrs, isVoid) {
  8581. const /** @type {?} */ start = `<${tag}`;
  8582. const /** @type {?} */ strAttrs = Object.keys(attrs).sort().map((name) => ` ${name}=${attrs[name]}`).join('');
  8583. const /** @type {?} */ end = isVoid ? '/>' : `></${tag}>`;
  8584. return start + strAttrs + end;
  8585. }
  8586. /**
  8587. * @param {?} tag
  8588. * @return {?}
  8589. */
  8590. _hashClosingTag(tag) { return this._hashTag(`/${tag}`, {}, false); }
  8591. /**
  8592. * @param {?} base
  8593. * @return {?}
  8594. */
  8595. _generateUniqueName(base) {
  8596. const /** @type {?} */ seen = this._placeHolderNameCounts.hasOwnProperty(base);
  8597. if (!seen) {
  8598. this._placeHolderNameCounts[base] = 1;
  8599. return base;
  8600. }
  8601. const /** @type {?} */ id = this._placeHolderNameCounts[base];
  8602. this._placeHolderNameCounts[base] = id + 1;
  8603. return `${base}_${id}`;
  8604. }
  8605. }
  8606. /**
  8607. * @fileoverview added by tsickle
  8608. * @suppress {checkTypes} checked by tsc
  8609. */
  8610. /**
  8611. * @license
  8612. * Copyright Google Inc. All Rights Reserved.
  8613. *
  8614. * Use of this source code is governed by an MIT-style license that can be
  8615. * found in the LICENSE file at https://angular.io/license
  8616. */
  8617. const _expParser = new Parser(new Lexer());
  8618. /**
  8619. * Returns a function converting html nodes to an i18n Message given an interpolationConfig
  8620. * @param {?} interpolationConfig
  8621. * @return {?}
  8622. */
  8623. function createI18nMessageFactory(interpolationConfig) {
  8624. const /** @type {?} */ visitor = new _I18nVisitor(_expParser, interpolationConfig);
  8625. return (nodes, meaning, description, id) => visitor.toI18nMessage(nodes, meaning, description, id);
  8626. }
  8627. class _I18nVisitor {
  8628. /**
  8629. * @param {?} _expressionParser
  8630. * @param {?} _interpolationConfig
  8631. */
  8632. constructor(_expressionParser, _interpolationConfig) {
  8633. this._expressionParser = _expressionParser;
  8634. this._interpolationConfig = _interpolationConfig;
  8635. }
  8636. /**
  8637. * @param {?} nodes
  8638. * @param {?} meaning
  8639. * @param {?} description
  8640. * @param {?} id
  8641. * @return {?}
  8642. */
  8643. toI18nMessage(nodes, meaning, description, id) {
  8644. this._isIcu = nodes.length == 1 && nodes[0] instanceof Expansion;
  8645. this._icuDepth = 0;
  8646. this._placeholderRegistry = new PlaceholderRegistry();
  8647. this._placeholderToContent = {};
  8648. this._placeholderToMessage = {};
  8649. const /** @type {?} */ i18nodes = visitAll(this, nodes, {});
  8650. return new Message(i18nodes, this._placeholderToContent, this._placeholderToMessage, meaning, description, id);
  8651. }
  8652. /**
  8653. * @param {?} el
  8654. * @param {?} context
  8655. * @return {?}
  8656. */
  8657. visitElement(el, context) {
  8658. const /** @type {?} */ children = visitAll(this, el.children);
  8659. const /** @type {?} */ attrs = {};
  8660. el.attrs.forEach(attr => {
  8661. // Do not visit the attributes, translatable ones are top-level ASTs
  8662. attrs[attr.name] = attr.value;
  8663. });
  8664. const /** @type {?} */ isVoid = getHtmlTagDefinition(el.name).isVoid;
  8665. const /** @type {?} */ startPhName = this._placeholderRegistry.getStartTagPlaceholderName(el.name, attrs, isVoid);
  8666. this._placeholderToContent[startPhName] = /** @type {?} */ ((el.sourceSpan)).toString();
  8667. let /** @type {?} */ closePhName = '';
  8668. if (!isVoid) {
  8669. closePhName = this._placeholderRegistry.getCloseTagPlaceholderName(el.name);
  8670. this._placeholderToContent[closePhName] = `</${el.name}>`;
  8671. }
  8672. return new TagPlaceholder(el.name, attrs, startPhName, closePhName, children, isVoid, /** @type {?} */ ((el.sourceSpan)));
  8673. }
  8674. /**
  8675. * @param {?} attribute
  8676. * @param {?} context
  8677. * @return {?}
  8678. */
  8679. visitAttribute(attribute, context) {
  8680. return this._visitTextWithInterpolation(attribute.value, attribute.sourceSpan);
  8681. }
  8682. /**
  8683. * @param {?} text
  8684. * @param {?} context
  8685. * @return {?}
  8686. */
  8687. visitText(text, context) {
  8688. return this._visitTextWithInterpolation(text.value, /** @type {?} */ ((text.sourceSpan)));
  8689. }
  8690. /**
  8691. * @param {?} comment
  8692. * @param {?} context
  8693. * @return {?}
  8694. */
  8695. visitComment(comment, context) { return null; }
  8696. /**
  8697. * @param {?} icu
  8698. * @param {?} context
  8699. * @return {?}
  8700. */
  8701. visitExpansion(icu, context) {
  8702. this._icuDepth++;
  8703. const /** @type {?} */ i18nIcuCases = {};
  8704. const /** @type {?} */ i18nIcu = new Icu(icu.switchValue, icu.type, i18nIcuCases, icu.sourceSpan);
  8705. icu.cases.forEach((caze) => {
  8706. i18nIcuCases[caze.value] = new Container(caze.expression.map((node) => node.visit(this, {})), caze.expSourceSpan);
  8707. });
  8708. this._icuDepth--;
  8709. if (this._isIcu || this._icuDepth > 0) {
  8710. // Returns an ICU node when:
  8711. // - the message (vs a part of the message) is an ICU message, or
  8712. // - the ICU message is nested.
  8713. const /** @type {?} */ expPh = this._placeholderRegistry.getUniquePlaceholder(`VAR_${icu.type}`);
  8714. i18nIcu.expressionPlaceholder = expPh;
  8715. this._placeholderToContent[expPh] = icu.switchValue;
  8716. return i18nIcu;
  8717. }
  8718. // Else returns a placeholder
  8719. // ICU placeholders should not be replaced with their original content but with the their
  8720. // translations. We need to create a new visitor (they are not re-entrant) to compute the
  8721. // message id.
  8722. // TODO(vicb): add a html.Node -> i18n.Message cache to avoid having to re-create the msg
  8723. const /** @type {?} */ phName = this._placeholderRegistry.getPlaceholderName('ICU', icu.sourceSpan.toString());
  8724. const /** @type {?} */ visitor = new _I18nVisitor(this._expressionParser, this._interpolationConfig);
  8725. this._placeholderToMessage[phName] = visitor.toI18nMessage([icu], '', '', '');
  8726. return new IcuPlaceholder(i18nIcu, phName, icu.sourceSpan);
  8727. }
  8728. /**
  8729. * @param {?} icuCase
  8730. * @param {?} context
  8731. * @return {?}
  8732. */
  8733. visitExpansionCase(icuCase, context) {
  8734. throw new Error('Unreachable code');
  8735. }
  8736. /**
  8737. * @param {?} text
  8738. * @param {?} sourceSpan
  8739. * @return {?}
  8740. */
  8741. _visitTextWithInterpolation(text, sourceSpan) {
  8742. const /** @type {?} */ splitInterpolation = this._expressionParser.splitInterpolation(text, sourceSpan.start.toString(), this._interpolationConfig);
  8743. if (!splitInterpolation) {
  8744. // No expression, return a single text
  8745. return new Text$1(text, sourceSpan);
  8746. }
  8747. // Return a group of text + expressions
  8748. const /** @type {?} */ nodes = [];
  8749. const /** @type {?} */ container = new Container(nodes, sourceSpan);
  8750. const { start: sDelimiter, end: eDelimiter } = this._interpolationConfig;
  8751. for (let /** @type {?} */ i = 0; i < splitInterpolation.strings.length - 1; i++) {
  8752. const /** @type {?} */ expression = splitInterpolation.expressions[i];
  8753. const /** @type {?} */ baseName = _extractPlaceholderName(expression) || 'INTERPOLATION';
  8754. const /** @type {?} */ phName = this._placeholderRegistry.getPlaceholderName(baseName, expression);
  8755. if (splitInterpolation.strings[i].length) {
  8756. // No need to add empty strings
  8757. nodes.push(new Text$1(splitInterpolation.strings[i], sourceSpan));
  8758. }
  8759. nodes.push(new Placeholder(expression, phName, sourceSpan));
  8760. this._placeholderToContent[phName] = sDelimiter + expression + eDelimiter;
  8761. }
  8762. // The last index contains no expression
  8763. const /** @type {?} */ lastStringIdx = splitInterpolation.strings.length - 1;
  8764. if (splitInterpolation.strings[lastStringIdx].length) {
  8765. nodes.push(new Text$1(splitInterpolation.strings[lastStringIdx], sourceSpan));
  8766. }
  8767. return container;
  8768. }
  8769. }
  8770. const _CUSTOM_PH_EXP = /\/\/[\s\S]*i18n[\s\S]*\([\s\S]*ph[\s\S]*=[\s\S]*("|')([\s\S]*?)\1[\s\S]*\)/g;
  8771. /**
  8772. * @param {?} input
  8773. * @return {?}
  8774. */
  8775. function _extractPlaceholderName(input) {
  8776. return input.split(_CUSTOM_PH_EXP)[2];
  8777. }
  8778. /**
  8779. * @fileoverview added by tsickle
  8780. * @suppress {checkTypes} checked by tsc
  8781. */
  8782. /**
  8783. * @license
  8784. * Copyright Google Inc. All Rights Reserved.
  8785. *
  8786. * Use of this source code is governed by an MIT-style license that can be
  8787. * found in the LICENSE file at https://angular.io/license
  8788. */
  8789. /**
  8790. * An i18n error.
  8791. */
  8792. class I18nError extends ParseError {
  8793. /**
  8794. * @param {?} span
  8795. * @param {?} msg
  8796. */
  8797. constructor(span, msg) { super(span, msg); }
  8798. }
  8799. /**
  8800. * @fileoverview added by tsickle
  8801. * @suppress {checkTypes} checked by tsc
  8802. */
  8803. /**
  8804. * @license
  8805. * Copyright Google Inc. All Rights Reserved.
  8806. *
  8807. * Use of this source code is governed by an MIT-style license that can be
  8808. * found in the LICENSE file at https://angular.io/license
  8809. */
  8810. const _I18N_ATTR = 'i18n';
  8811. const _I18N_ATTR_PREFIX = 'i18n-';
  8812. const _I18N_COMMENT_PREFIX_REGEXP = /^i18n:?/;
  8813. const MEANING_SEPARATOR = '|';
  8814. const ID_SEPARATOR = '@@';
  8815. let i18nCommentsWarned = false;
  8816. /**
  8817. * Extract translatable messages from an html AST
  8818. * @param {?} nodes
  8819. * @param {?} interpolationConfig
  8820. * @param {?} implicitTags
  8821. * @param {?} implicitAttrs
  8822. * @return {?}
  8823. */
  8824. function extractMessages(nodes, interpolationConfig, implicitTags, implicitAttrs) {
  8825. const /** @type {?} */ visitor = new _Visitor(implicitTags, implicitAttrs);
  8826. return visitor.extract(nodes, interpolationConfig);
  8827. }
  8828. /**
  8829. * @param {?} nodes
  8830. * @param {?} translations
  8831. * @param {?} interpolationConfig
  8832. * @param {?} implicitTags
  8833. * @param {?} implicitAttrs
  8834. * @return {?}
  8835. */
  8836. function mergeTranslations(nodes, translations, interpolationConfig, implicitTags, implicitAttrs) {
  8837. const /** @type {?} */ visitor = new _Visitor(implicitTags, implicitAttrs);
  8838. return visitor.merge(nodes, translations, interpolationConfig);
  8839. }
  8840. class ExtractionResult {
  8841. /**
  8842. * @param {?} messages
  8843. * @param {?} errors
  8844. */
  8845. constructor(messages, errors) {
  8846. this.messages = messages;
  8847. this.errors = errors;
  8848. }
  8849. }
  8850. /** @enum {number} */
  8851. const _VisitorMode = {
  8852. Extract: 0,
  8853. Merge: 1,
  8854. };
  8855. _VisitorMode[_VisitorMode.Extract] = "Extract";
  8856. _VisitorMode[_VisitorMode.Merge] = "Merge";
  8857. /**
  8858. * This Visitor is used:
  8859. * 1. to extract all the translatable strings from an html AST (see `extract()`),
  8860. * 2. to replace the translatable strings with the actual translations (see `merge()`)
  8861. *
  8862. * \@internal
  8863. */
  8864. class _Visitor {
  8865. /**
  8866. * @param {?} _implicitTags
  8867. * @param {?} _implicitAttrs
  8868. */
  8869. constructor(_implicitTags, _implicitAttrs) {
  8870. this._implicitTags = _implicitTags;
  8871. this._implicitAttrs = _implicitAttrs;
  8872. }
  8873. /**
  8874. * Extracts the messages from the tree
  8875. * @param {?} nodes
  8876. * @param {?} interpolationConfig
  8877. * @return {?}
  8878. */
  8879. extract(nodes, interpolationConfig) {
  8880. this._init(_VisitorMode.Extract, interpolationConfig);
  8881. nodes.forEach(node => node.visit(this, null));
  8882. if (this._inI18nBlock) {
  8883. this._reportError(nodes[nodes.length - 1], 'Unclosed block');
  8884. }
  8885. return new ExtractionResult(this._messages, this._errors);
  8886. }
  8887. /**
  8888. * Returns a tree where all translatable nodes are translated
  8889. * @param {?} nodes
  8890. * @param {?} translations
  8891. * @param {?} interpolationConfig
  8892. * @return {?}
  8893. */
  8894. merge(nodes, translations, interpolationConfig) {
  8895. this._init(_VisitorMode.Merge, interpolationConfig);
  8896. this._translations = translations;
  8897. // Construct a single fake root element
  8898. const /** @type {?} */ wrapper = new Element('wrapper', [], nodes, /** @type {?} */ ((undefined)), undefined, undefined);
  8899. const /** @type {?} */ translatedNode = wrapper.visit(this, null);
  8900. if (this._inI18nBlock) {
  8901. this._reportError(nodes[nodes.length - 1], 'Unclosed block');
  8902. }
  8903. return new ParseTreeResult(translatedNode.children, this._errors);
  8904. }
  8905. /**
  8906. * @param {?} icuCase
  8907. * @param {?} context
  8908. * @return {?}
  8909. */
  8910. visitExpansionCase(icuCase, context) {
  8911. // Parse cases for translatable html attributes
  8912. const /** @type {?} */ expression = visitAll(this, icuCase.expression, context);
  8913. if (this._mode === _VisitorMode.Merge) {
  8914. return new ExpansionCase(icuCase.value, expression, icuCase.sourceSpan, icuCase.valueSourceSpan, icuCase.expSourceSpan);
  8915. }
  8916. }
  8917. /**
  8918. * @param {?} icu
  8919. * @param {?} context
  8920. * @return {?}
  8921. */
  8922. visitExpansion(icu, context) {
  8923. this._mayBeAddBlockChildren(icu);
  8924. const /** @type {?} */ wasInIcu = this._inIcu;
  8925. if (!this._inIcu) {
  8926. // nested ICU messages should not be extracted but top-level translated as a whole
  8927. if (this._isInTranslatableSection) {
  8928. this._addMessage([icu]);
  8929. }
  8930. this._inIcu = true;
  8931. }
  8932. const /** @type {?} */ cases = visitAll(this, icu.cases, context);
  8933. if (this._mode === _VisitorMode.Merge) {
  8934. icu = new Expansion(icu.switchValue, icu.type, cases, icu.sourceSpan, icu.switchValueSourceSpan);
  8935. }
  8936. this._inIcu = wasInIcu;
  8937. return icu;
  8938. }
  8939. /**
  8940. * @param {?} comment
  8941. * @param {?} context
  8942. * @return {?}
  8943. */
  8944. visitComment(comment, context) {
  8945. const /** @type {?} */ isOpening = _isOpeningComment(comment);
  8946. if (isOpening && this._isInTranslatableSection) {
  8947. this._reportError(comment, 'Could not start a block inside a translatable section');
  8948. return;
  8949. }
  8950. const /** @type {?} */ isClosing = _isClosingComment(comment);
  8951. if (isClosing && !this._inI18nBlock) {
  8952. this._reportError(comment, 'Trying to close an unopened block');
  8953. return;
  8954. }
  8955. if (!this._inI18nNode && !this._inIcu) {
  8956. if (!this._inI18nBlock) {
  8957. if (isOpening) {
  8958. // deprecated from v5 you should use <ng-container i18n> instead of i18n comments
  8959. if (!i18nCommentsWarned && /** @type {?} */ (console) && /** @type {?} */ (console.warn)) {
  8960. i18nCommentsWarned = true;
  8961. const /** @type {?} */ details = comment.sourceSpan.details ? `, ${comment.sourceSpan.details}` : '';
  8962. // TODO(ocombe): use a log service once there is a public one available
  8963. console.warn(`I18n comments are deprecated, use an <ng-container> element instead (${comment.sourceSpan.start}${details})`);
  8964. }
  8965. this._inI18nBlock = true;
  8966. this._blockStartDepth = this._depth;
  8967. this._blockChildren = [];
  8968. this._blockMeaningAndDesc = /** @type {?} */ ((comment.value)).replace(_I18N_COMMENT_PREFIX_REGEXP, '').trim();
  8969. this._openTranslatableSection(comment);
  8970. }
  8971. }
  8972. else {
  8973. if (isClosing) {
  8974. if (this._depth == this._blockStartDepth) {
  8975. this._closeTranslatableSection(comment, this._blockChildren);
  8976. this._inI18nBlock = false;
  8977. const /** @type {?} */ message = /** @type {?} */ ((this._addMessage(this._blockChildren, this._blockMeaningAndDesc)));
  8978. // merge attributes in sections
  8979. const /** @type {?} */ nodes = this._translateMessage(comment, message);
  8980. return visitAll(this, nodes);
  8981. }
  8982. else {
  8983. this._reportError(comment, 'I18N blocks should not cross element boundaries');
  8984. return;
  8985. }
  8986. }
  8987. }
  8988. }
  8989. }
  8990. /**
  8991. * @param {?} text
  8992. * @param {?} context
  8993. * @return {?}
  8994. */
  8995. visitText(text, context) {
  8996. if (this._isInTranslatableSection) {
  8997. this._mayBeAddBlockChildren(text);
  8998. }
  8999. return text;
  9000. }
  9001. /**
  9002. * @param {?} el
  9003. * @param {?} context
  9004. * @return {?}
  9005. */
  9006. visitElement(el, context) {
  9007. this._mayBeAddBlockChildren(el);
  9008. this._depth++;
  9009. const /** @type {?} */ wasInI18nNode = this._inI18nNode;
  9010. const /** @type {?} */ wasInImplicitNode = this._inImplicitNode;
  9011. let /** @type {?} */ childNodes = [];
  9012. let /** @type {?} */ translatedChildNodes = /** @type {?} */ ((undefined));
  9013. // Extract:
  9014. // - top level nodes with the (implicit) "i18n" attribute if not already in a section
  9015. // - ICU messages
  9016. const /** @type {?} */ i18nAttr = _getI18nAttr(el);
  9017. const /** @type {?} */ i18nMeta = i18nAttr ? i18nAttr.value : '';
  9018. const /** @type {?} */ isImplicit = this._implicitTags.some(tag => el.name === tag) && !this._inIcu &&
  9019. !this._isInTranslatableSection;
  9020. const /** @type {?} */ isTopLevelImplicit = !wasInImplicitNode && isImplicit;
  9021. this._inImplicitNode = wasInImplicitNode || isImplicit;
  9022. if (!this._isInTranslatableSection && !this._inIcu) {
  9023. if (i18nAttr || isTopLevelImplicit) {
  9024. this._inI18nNode = true;
  9025. const /** @type {?} */ message = /** @type {?} */ ((this._addMessage(el.children, i18nMeta)));
  9026. translatedChildNodes = this._translateMessage(el, message);
  9027. }
  9028. if (this._mode == _VisitorMode.Extract) {
  9029. const /** @type {?} */ isTranslatable = i18nAttr || isTopLevelImplicit;
  9030. if (isTranslatable)
  9031. this._openTranslatableSection(el);
  9032. visitAll(this, el.children);
  9033. if (isTranslatable)
  9034. this._closeTranslatableSection(el, el.children);
  9035. }
  9036. }
  9037. else {
  9038. if (i18nAttr || isTopLevelImplicit) {
  9039. this._reportError(el, 'Could not mark an element as translatable inside a translatable section');
  9040. }
  9041. if (this._mode == _VisitorMode.Extract) {
  9042. // Descend into child nodes for extraction
  9043. visitAll(this, el.children);
  9044. }
  9045. }
  9046. if (this._mode === _VisitorMode.Merge) {
  9047. const /** @type {?} */ visitNodes = translatedChildNodes || el.children;
  9048. visitNodes.forEach(child => {
  9049. const /** @type {?} */ visited = child.visit(this, context);
  9050. if (visited && !this._isInTranslatableSection) {
  9051. // Do not add the children from translatable sections (= i18n blocks here)
  9052. // They will be added later in this loop when the block closes (i.e. on `<!-- /i18n -->`)
  9053. childNodes = childNodes.concat(visited);
  9054. }
  9055. });
  9056. }
  9057. this._visitAttributesOf(el);
  9058. this._depth--;
  9059. this._inI18nNode = wasInI18nNode;
  9060. this._inImplicitNode = wasInImplicitNode;
  9061. if (this._mode === _VisitorMode.Merge) {
  9062. const /** @type {?} */ translatedAttrs = this._translateAttributes(el);
  9063. return new Element(el.name, translatedAttrs, childNodes, el.sourceSpan, el.startSourceSpan, el.endSourceSpan);
  9064. }
  9065. return null;
  9066. }
  9067. /**
  9068. * @param {?} attribute
  9069. * @param {?} context
  9070. * @return {?}
  9071. */
  9072. visitAttribute(attribute, context) {
  9073. throw new Error('unreachable code');
  9074. }
  9075. /**
  9076. * @param {?} mode
  9077. * @param {?} interpolationConfig
  9078. * @return {?}
  9079. */
  9080. _init(mode, interpolationConfig) {
  9081. this._mode = mode;
  9082. this._inI18nBlock = false;
  9083. this._inI18nNode = false;
  9084. this._depth = 0;
  9085. this._inIcu = false;
  9086. this._msgCountAtSectionStart = undefined;
  9087. this._errors = [];
  9088. this._messages = [];
  9089. this._inImplicitNode = false;
  9090. this._createI18nMessage = createI18nMessageFactory(interpolationConfig);
  9091. }
  9092. /**
  9093. * @param {?} el
  9094. * @return {?}
  9095. */
  9096. _visitAttributesOf(el) {
  9097. const /** @type {?} */ explicitAttrNameToValue = {};
  9098. const /** @type {?} */ implicitAttrNames = this._implicitAttrs[el.name] || [];
  9099. el.attrs.filter(attr => attr.name.startsWith(_I18N_ATTR_PREFIX))
  9100. .forEach(attr => explicitAttrNameToValue[attr.name.slice(_I18N_ATTR_PREFIX.length)] =
  9101. attr.value);
  9102. el.attrs.forEach(attr => {
  9103. if (attr.name in explicitAttrNameToValue) {
  9104. this._addMessage([attr], explicitAttrNameToValue[attr.name]);
  9105. }
  9106. else if (implicitAttrNames.some(name => attr.name === name)) {
  9107. this._addMessage([attr]);
  9108. }
  9109. });
  9110. }
  9111. /**
  9112. * @param {?} ast
  9113. * @param {?=} msgMeta
  9114. * @return {?}
  9115. */
  9116. _addMessage(ast, msgMeta) {
  9117. if (ast.length == 0 ||
  9118. ast.length == 1 && ast[0] instanceof Attribute$1 && !(/** @type {?} */ (ast[0])).value) {
  9119. // Do not create empty messages
  9120. return null;
  9121. }
  9122. const { meaning, description, id } = _parseMessageMeta(msgMeta);
  9123. const /** @type {?} */ message = this._createI18nMessage(ast, meaning, description, id);
  9124. this._messages.push(message);
  9125. return message;
  9126. }
  9127. /**
  9128. * @param {?} el
  9129. * @param {?} message
  9130. * @return {?}
  9131. */
  9132. _translateMessage(el, message) {
  9133. if (message && this._mode === _VisitorMode.Merge) {
  9134. const /** @type {?} */ nodes = this._translations.get(message);
  9135. if (nodes) {
  9136. return nodes;
  9137. }
  9138. this._reportError(el, `Translation unavailable for message id="${this._translations.digest(message)}"`);
  9139. }
  9140. return [];
  9141. }
  9142. /**
  9143. * @param {?} el
  9144. * @return {?}
  9145. */
  9146. _translateAttributes(el) {
  9147. const /** @type {?} */ attributes = el.attrs;
  9148. const /** @type {?} */ i18nParsedMessageMeta = {};
  9149. attributes.forEach(attr => {
  9150. if (attr.name.startsWith(_I18N_ATTR_PREFIX)) {
  9151. i18nParsedMessageMeta[attr.name.slice(_I18N_ATTR_PREFIX.length)] =
  9152. _parseMessageMeta(attr.value);
  9153. }
  9154. });
  9155. const /** @type {?} */ translatedAttributes = [];
  9156. attributes.forEach((attr) => {
  9157. if (attr.name === _I18N_ATTR || attr.name.startsWith(_I18N_ATTR_PREFIX)) {
  9158. // strip i18n specific attributes
  9159. return;
  9160. }
  9161. if (attr.value && attr.value != '' && i18nParsedMessageMeta.hasOwnProperty(attr.name)) {
  9162. const { meaning, description, id } = i18nParsedMessageMeta[attr.name];
  9163. const /** @type {?} */ message = this._createI18nMessage([attr], meaning, description, id);
  9164. const /** @type {?} */ nodes = this._translations.get(message);
  9165. if (nodes) {
  9166. if (nodes.length == 0) {
  9167. translatedAttributes.push(new Attribute$1(attr.name, '', attr.sourceSpan));
  9168. }
  9169. else if (nodes[0] instanceof Text) {
  9170. const /** @type {?} */ value = (/** @type {?} */ (nodes[0])).value;
  9171. translatedAttributes.push(new Attribute$1(attr.name, value, attr.sourceSpan));
  9172. }
  9173. else {
  9174. this._reportError(el, `Unexpected translation for attribute "${attr.name}" (id="${id || this._translations.digest(message)}")`);
  9175. }
  9176. }
  9177. else {
  9178. this._reportError(el, `Translation unavailable for attribute "${attr.name}" (id="${id || this._translations.digest(message)}")`);
  9179. }
  9180. }
  9181. else {
  9182. translatedAttributes.push(attr);
  9183. }
  9184. });
  9185. return translatedAttributes;
  9186. }
  9187. /**
  9188. * Add the node as a child of the block when:
  9189. * - we are in a block,
  9190. * - we are not inside a ICU message (those are handled separately),
  9191. * - the node is a "direct child" of the block
  9192. * @param {?} node
  9193. * @return {?}
  9194. */
  9195. _mayBeAddBlockChildren(node) {
  9196. if (this._inI18nBlock && !this._inIcu && this._depth == this._blockStartDepth) {
  9197. this._blockChildren.push(node);
  9198. }
  9199. }
  9200. /**
  9201. * Marks the start of a section, see `_closeTranslatableSection`
  9202. * @param {?} node
  9203. * @return {?}
  9204. */
  9205. _openTranslatableSection(node) {
  9206. if (this._isInTranslatableSection) {
  9207. this._reportError(node, 'Unexpected section start');
  9208. }
  9209. else {
  9210. this._msgCountAtSectionStart = this._messages.length;
  9211. }
  9212. }
  9213. /**
  9214. * A translatable section could be:
  9215. * - the content of translatable element,
  9216. * - nodes between `<!-- i18n -->` and `<!-- /i18n -->` comments
  9217. * @return {?}
  9218. */
  9219. get _isInTranslatableSection() {
  9220. return this._msgCountAtSectionStart !== void 0;
  9221. }
  9222. /**
  9223. * Terminates a section.
  9224. *
  9225. * If a section has only one significant children (comments not significant) then we should not
  9226. * keep the message from this children:
  9227. *
  9228. * `<p i18n="meaning|description">{ICU message}</p>` would produce two messages:
  9229. * - one for the <p> content with meaning and description,
  9230. * - another one for the ICU message.
  9231. *
  9232. * In this case the last message is discarded as it contains less information (the AST is
  9233. * otherwise identical).
  9234. *
  9235. * Note that we should still keep messages extracted from attributes inside the section (ie in the
  9236. * ICU message here)
  9237. * @param {?} node
  9238. * @param {?} directChildren
  9239. * @return {?}
  9240. */
  9241. _closeTranslatableSection(node, directChildren) {
  9242. if (!this._isInTranslatableSection) {
  9243. this._reportError(node, 'Unexpected section end');
  9244. return;
  9245. }
  9246. const /** @type {?} */ startIndex = this._msgCountAtSectionStart;
  9247. const /** @type {?} */ significantChildren = directChildren.reduce((count, node) => count + (node instanceof Comment ? 0 : 1), 0);
  9248. if (significantChildren == 1) {
  9249. for (let /** @type {?} */ i = this._messages.length - 1; i >= /** @type {?} */ ((startIndex)); i--) {
  9250. const /** @type {?} */ ast = this._messages[i].nodes;
  9251. if (!(ast.length == 1 && ast[0] instanceof Text$1)) {
  9252. this._messages.splice(i, 1);
  9253. break;
  9254. }
  9255. }
  9256. }
  9257. this._msgCountAtSectionStart = undefined;
  9258. }
  9259. /**
  9260. * @param {?} node
  9261. * @param {?} msg
  9262. * @return {?}
  9263. */
  9264. _reportError(node, msg) {
  9265. this._errors.push(new I18nError(/** @type {?} */ ((node.sourceSpan)), msg));
  9266. }
  9267. }
  9268. /**
  9269. * @param {?} n
  9270. * @return {?}
  9271. */
  9272. function _isOpeningComment(n) {
  9273. return !!(n instanceof Comment && n.value && n.value.startsWith('i18n'));
  9274. }
  9275. /**
  9276. * @param {?} n
  9277. * @return {?}
  9278. */
  9279. function _isClosingComment(n) {
  9280. return !!(n instanceof Comment && n.value && n.value === '/i18n');
  9281. }
  9282. /**
  9283. * @param {?} p
  9284. * @return {?}
  9285. */
  9286. function _getI18nAttr(p) {
  9287. return p.attrs.find(attr => attr.name === _I18N_ATTR) || null;
  9288. }
  9289. /**
  9290. * @param {?=} i18n
  9291. * @return {?}
  9292. */
  9293. function _parseMessageMeta(i18n) {
  9294. if (!i18n)
  9295. return { meaning: '', description: '', id: '' };
  9296. const /** @type {?} */ idIndex = i18n.indexOf(ID_SEPARATOR);
  9297. const /** @type {?} */ descIndex = i18n.indexOf(MEANING_SEPARATOR);
  9298. const [meaningAndDesc, id] = (idIndex > -1) ? [i18n.slice(0, idIndex), i18n.slice(idIndex + 2)] : [i18n, ''];
  9299. const [meaning, description] = (descIndex > -1) ?
  9300. [meaningAndDesc.slice(0, descIndex), meaningAndDesc.slice(descIndex + 1)] :
  9301. ['', meaningAndDesc];
  9302. return { meaning, description, id };
  9303. }
  9304. /**
  9305. * @fileoverview added by tsickle
  9306. * @suppress {checkTypes} checked by tsc
  9307. */
  9308. /**
  9309. * @license
  9310. * Copyright Google Inc. All Rights Reserved.
  9311. *
  9312. * Use of this source code is governed by an MIT-style license that can be
  9313. * found in the LICENSE file at https://angular.io/license
  9314. */
  9315. class XmlTagDefinition {
  9316. constructor() {
  9317. this.closedByParent = false;
  9318. this.contentType = TagContentType.PARSABLE_DATA;
  9319. this.isVoid = false;
  9320. this.ignoreFirstLf = false;
  9321. this.canSelfClose = true;
  9322. }
  9323. /**
  9324. * @param {?} currentParent
  9325. * @return {?}
  9326. */
  9327. requireExtraParent(currentParent) { return false; }
  9328. /**
  9329. * @param {?} name
  9330. * @return {?}
  9331. */
  9332. isClosedByChild(name) { return false; }
  9333. }
  9334. const _TAG_DEFINITION = new XmlTagDefinition();
  9335. /**
  9336. * @param {?} tagName
  9337. * @return {?}
  9338. */
  9339. function getXmlTagDefinition(tagName) {
  9340. return _TAG_DEFINITION;
  9341. }
  9342. /**
  9343. * @fileoverview added by tsickle
  9344. * @suppress {checkTypes} checked by tsc
  9345. */
  9346. /**
  9347. * @license
  9348. * Copyright Google Inc. All Rights Reserved.
  9349. *
  9350. * Use of this source code is governed by an MIT-style license that can be
  9351. * found in the LICENSE file at https://angular.io/license
  9352. */
  9353. class XmlParser extends Parser$1 {
  9354. constructor() { super(getXmlTagDefinition); }
  9355. /**
  9356. * @param {?} source
  9357. * @param {?} url
  9358. * @param {?=} parseExpansionForms
  9359. * @return {?}
  9360. */
  9361. parse(source, url, parseExpansionForms = false) {
  9362. return super.parse(source, url, parseExpansionForms);
  9363. }
  9364. }
  9365. /**
  9366. * @fileoverview added by tsickle
  9367. * @suppress {checkTypes} checked by tsc
  9368. */
  9369. /**
  9370. * @license
  9371. * Copyright Google Inc. All Rights Reserved.
  9372. *
  9373. * Use of this source code is governed by an MIT-style license that can be
  9374. * found in the LICENSE file at https://angular.io/license
  9375. */
  9376. /**
  9377. * @abstract
  9378. */
  9379. class Serializer {
  9380. /**
  9381. * @param {?} message
  9382. * @return {?}
  9383. */
  9384. createNameMapper(message) { return null; }
  9385. }
  9386. /**
  9387. * A `PlaceholderMapper` converts placeholder names from internal to serialized representation and
  9388. * back.
  9389. *
  9390. * It should be used for serialization format that put constraints on the placeholder names.
  9391. * @record
  9392. */
  9393. /**
  9394. * A simple mapper that take a function to transform an internal name to a public name
  9395. */
  9396. class SimplePlaceholderMapper extends RecurseVisitor {
  9397. /**
  9398. * @param {?} message
  9399. * @param {?} mapName
  9400. */
  9401. constructor(message, mapName) {
  9402. super();
  9403. this.mapName = mapName;
  9404. this.internalToPublic = {};
  9405. this.publicToNextId = {};
  9406. this.publicToInternal = {};
  9407. message.nodes.forEach(node => node.visit(this));
  9408. }
  9409. /**
  9410. * @param {?} internalName
  9411. * @return {?}
  9412. */
  9413. toPublicName(internalName) {
  9414. return this.internalToPublic.hasOwnProperty(internalName) ?
  9415. this.internalToPublic[internalName] :
  9416. null;
  9417. }
  9418. /**
  9419. * @param {?} publicName
  9420. * @return {?}
  9421. */
  9422. toInternalName(publicName) {
  9423. return this.publicToInternal.hasOwnProperty(publicName) ? this.publicToInternal[publicName] :
  9424. null;
  9425. }
  9426. /**
  9427. * @param {?} text
  9428. * @param {?=} context
  9429. * @return {?}
  9430. */
  9431. visitText(text, context) { return null; }
  9432. /**
  9433. * @param {?} ph
  9434. * @param {?=} context
  9435. * @return {?}
  9436. */
  9437. visitTagPlaceholder(ph, context) {
  9438. this.visitPlaceholderName(ph.startName);
  9439. super.visitTagPlaceholder(ph, context);
  9440. this.visitPlaceholderName(ph.closeName);
  9441. }
  9442. /**
  9443. * @param {?} ph
  9444. * @param {?=} context
  9445. * @return {?}
  9446. */
  9447. visitPlaceholder(ph, context) { this.visitPlaceholderName(ph.name); }
  9448. /**
  9449. * @param {?} ph
  9450. * @param {?=} context
  9451. * @return {?}
  9452. */
  9453. visitIcuPlaceholder(ph, context) {
  9454. this.visitPlaceholderName(ph.name);
  9455. }
  9456. /**
  9457. * @param {?} internalName
  9458. * @return {?}
  9459. */
  9460. visitPlaceholderName(internalName) {
  9461. if (!internalName || this.internalToPublic.hasOwnProperty(internalName)) {
  9462. return;
  9463. }
  9464. let /** @type {?} */ publicName = this.mapName(internalName);
  9465. if (this.publicToInternal.hasOwnProperty(publicName)) {
  9466. // Create a new XMB when it has already been used
  9467. const /** @type {?} */ nextId = this.publicToNextId[publicName];
  9468. this.publicToNextId[publicName] = nextId + 1;
  9469. publicName = `${publicName}_${nextId}`;
  9470. }
  9471. else {
  9472. this.publicToNextId[publicName] = 1;
  9473. }
  9474. this.internalToPublic[internalName] = publicName;
  9475. this.publicToInternal[publicName] = internalName;
  9476. }
  9477. }
  9478. /**
  9479. * @fileoverview added by tsickle
  9480. * @suppress {checkTypes} checked by tsc
  9481. */
  9482. /**
  9483. * @license
  9484. * Copyright Google Inc. All Rights Reserved.
  9485. *
  9486. * Use of this source code is governed by an MIT-style license that can be
  9487. * found in the LICENSE file at https://angular.io/license
  9488. */
  9489. /**
  9490. * @record
  9491. */
  9492. class _Visitor$1 {
  9493. /**
  9494. * @param {?} tag
  9495. * @return {?}
  9496. */
  9497. visitTag(tag) {
  9498. const /** @type {?} */ strAttrs = this._serializeAttributes(tag.attrs);
  9499. if (tag.children.length == 0) {
  9500. return `<${tag.name}${strAttrs}/>`;
  9501. }
  9502. const /** @type {?} */ strChildren = tag.children.map(node => node.visit(this));
  9503. return `<${tag.name}${strAttrs}>${strChildren.join('')}</${tag.name}>`;
  9504. }
  9505. /**
  9506. * @param {?} text
  9507. * @return {?}
  9508. */
  9509. visitText(text) { return text.value; }
  9510. /**
  9511. * @param {?} decl
  9512. * @return {?}
  9513. */
  9514. visitDeclaration(decl) {
  9515. return `<?xml${this._serializeAttributes(decl.attrs)} ?>`;
  9516. }
  9517. /**
  9518. * @param {?} attrs
  9519. * @return {?}
  9520. */
  9521. _serializeAttributes(attrs) {
  9522. const /** @type {?} */ strAttrs = Object.keys(attrs).map((name) => `${name}="${attrs[name]}"`).join(' ');
  9523. return strAttrs.length > 0 ? ' ' + strAttrs : '';
  9524. }
  9525. /**
  9526. * @param {?} doctype
  9527. * @return {?}
  9528. */
  9529. visitDoctype(doctype) {
  9530. return `<!DOCTYPE ${doctype.rootTag} [\n${doctype.dtd}\n]>`;
  9531. }
  9532. }
  9533. const _visitor = new _Visitor$1();
  9534. /**
  9535. * @param {?} nodes
  9536. * @return {?}
  9537. */
  9538. function serialize(nodes) {
  9539. return nodes.map((node) => node.visit(_visitor)).join('');
  9540. }
  9541. /**
  9542. * @record
  9543. */
  9544. class Declaration {
  9545. /**
  9546. * @param {?} unescapedAttrs
  9547. */
  9548. constructor(unescapedAttrs) {
  9549. this.attrs = {};
  9550. Object.keys(unescapedAttrs).forEach((k) => {
  9551. this.attrs[k] = escapeXml(unescapedAttrs[k]);
  9552. });
  9553. }
  9554. /**
  9555. * @param {?} visitor
  9556. * @return {?}
  9557. */
  9558. visit(visitor) { return visitor.visitDeclaration(this); }
  9559. }
  9560. class Doctype {
  9561. /**
  9562. * @param {?} rootTag
  9563. * @param {?} dtd
  9564. */
  9565. constructor(rootTag, dtd) {
  9566. this.rootTag = rootTag;
  9567. this.dtd = dtd;
  9568. }
  9569. /**
  9570. * @param {?} visitor
  9571. * @return {?}
  9572. */
  9573. visit(visitor) { return visitor.visitDoctype(this); }
  9574. }
  9575. class Tag {
  9576. /**
  9577. * @param {?} name
  9578. * @param {?=} unescapedAttrs
  9579. * @param {?=} children
  9580. */
  9581. constructor(name, unescapedAttrs = {}, children = []) {
  9582. this.name = name;
  9583. this.children = children;
  9584. this.attrs = {};
  9585. Object.keys(unescapedAttrs).forEach((k) => {
  9586. this.attrs[k] = escapeXml(unescapedAttrs[k]);
  9587. });
  9588. }
  9589. /**
  9590. * @param {?} visitor
  9591. * @return {?}
  9592. */
  9593. visit(visitor) { return visitor.visitTag(this); }
  9594. }
  9595. class Text$2 {
  9596. /**
  9597. * @param {?} unescapedValue
  9598. */
  9599. constructor(unescapedValue) { this.value = escapeXml(unescapedValue); }
  9600. /**
  9601. * @param {?} visitor
  9602. * @return {?}
  9603. */
  9604. visit(visitor) { return visitor.visitText(this); }
  9605. }
  9606. class CR extends Text$2 {
  9607. /**
  9608. * @param {?=} ws
  9609. */
  9610. constructor(ws = 0) { super(`\n${new Array(ws + 1).join(' ')}`); }
  9611. }
  9612. const _ESCAPED_CHARS = [
  9613. [/&/g, '&amp;'],
  9614. [/"/g, '&quot;'],
  9615. [/'/g, '&apos;'],
  9616. [/</g, '&lt;'],
  9617. [/>/g, '&gt;'],
  9618. ];
  9619. /**
  9620. * @param {?} text
  9621. * @return {?}
  9622. */
  9623. function escapeXml(text) {
  9624. return _ESCAPED_CHARS.reduce((text, entry) => text.replace(entry[0], entry[1]), text);
  9625. }
  9626. /**
  9627. * @fileoverview added by tsickle
  9628. * @suppress {checkTypes} checked by tsc
  9629. */
  9630. /**
  9631. * @license
  9632. * Copyright Google Inc. All Rights Reserved.
  9633. *
  9634. * Use of this source code is governed by an MIT-style license that can be
  9635. * found in the LICENSE file at https://angular.io/license
  9636. */
  9637. const _VERSION = '1.2';
  9638. const _XMLNS = 'urn:oasis:names:tc:xliff:document:1.2';
  9639. // TODO(vicb): make this a param (s/_/-/)
  9640. const _DEFAULT_SOURCE_LANG = 'en';
  9641. const _PLACEHOLDER_TAG = 'x';
  9642. const _MARKER_TAG = 'mrk';
  9643. const _FILE_TAG = 'file';
  9644. const _SOURCE_TAG = 'source';
  9645. const _SEGMENT_SOURCE_TAG = 'seg-source';
  9646. const _TARGET_TAG = 'target';
  9647. const _UNIT_TAG = 'trans-unit';
  9648. const _CONTEXT_GROUP_TAG = 'context-group';
  9649. const _CONTEXT_TAG = 'context';
  9650. class Xliff extends Serializer {
  9651. /**
  9652. * @param {?} messages
  9653. * @param {?} locale
  9654. * @return {?}
  9655. */
  9656. write(messages, locale) {
  9657. const /** @type {?} */ visitor = new _WriteVisitor();
  9658. const /** @type {?} */ transUnits = [];
  9659. messages.forEach(message => {
  9660. let /** @type {?} */ contextTags = [];
  9661. message.sources.forEach((source) => {
  9662. let /** @type {?} */ contextGroupTag = new Tag(_CONTEXT_GROUP_TAG, { purpose: 'location' });
  9663. contextGroupTag.children.push(new CR(10), new Tag(_CONTEXT_TAG, { 'context-type': 'sourcefile' }, [new Text$2(source.filePath)]), new CR(10), new Tag(_CONTEXT_TAG, { 'context-type': 'linenumber' }, [new Text$2(`${source.startLine}`)]), new CR(8));
  9664. contextTags.push(new CR(8), contextGroupTag);
  9665. });
  9666. const /** @type {?} */ transUnit = new Tag(_UNIT_TAG, { id: message.id, datatype: 'html' });
  9667. transUnit.children.push(new CR(8), new Tag(_SOURCE_TAG, {}, visitor.serialize(message.nodes)), ...contextTags);
  9668. if (message.description) {
  9669. transUnit.children.push(new CR(8), new Tag('note', { priority: '1', from: 'description' }, [new Text$2(message.description)]));
  9670. }
  9671. if (message.meaning) {
  9672. transUnit.children.push(new CR(8), new Tag('note', { priority: '1', from: 'meaning' }, [new Text$2(message.meaning)]));
  9673. }
  9674. transUnit.children.push(new CR(6));
  9675. transUnits.push(new CR(6), transUnit);
  9676. });
  9677. const /** @type {?} */ body = new Tag('body', {}, [...transUnits, new CR(4)]);
  9678. const /** @type {?} */ file = new Tag('file', {
  9679. 'source-language': locale || _DEFAULT_SOURCE_LANG,
  9680. datatype: 'plaintext',
  9681. original: 'ng2.template',
  9682. }, [new CR(4), body, new CR(2)]);
  9683. const /** @type {?} */ xliff = new Tag('xliff', { version: _VERSION, xmlns: _XMLNS }, [new CR(2), file, new CR()]);
  9684. return serialize([
  9685. new Declaration({ version: '1.0', encoding: 'UTF-8' }), new CR(), xliff, new CR()
  9686. ]);
  9687. }
  9688. /**
  9689. * @param {?} content
  9690. * @param {?} url
  9691. * @return {?}
  9692. */
  9693. load(content, url) {
  9694. // xliff to xml nodes
  9695. const /** @type {?} */ xliffParser = new XliffParser();
  9696. const { locale, msgIdToHtml, errors } = xliffParser.parse(content, url);
  9697. // xml nodes to i18n nodes
  9698. const /** @type {?} */ i18nNodesByMsgId = {};
  9699. const /** @type {?} */ converter = new XmlToI18n();
  9700. Object.keys(msgIdToHtml).forEach(msgId => {
  9701. const { i18nNodes, errors: e } = converter.convert(msgIdToHtml[msgId], url);
  9702. errors.push(...e);
  9703. i18nNodesByMsgId[msgId] = i18nNodes;
  9704. });
  9705. if (errors.length) {
  9706. throw new Error(`xliff parse errors:\n${errors.join('\n')}`);
  9707. }
  9708. return { locale: /** @type {?} */ ((locale)), i18nNodesByMsgId };
  9709. }
  9710. /**
  9711. * @param {?} message
  9712. * @return {?}
  9713. */
  9714. digest(message) { return digest(message); }
  9715. }
  9716. class _WriteVisitor {
  9717. /**
  9718. * @param {?} text
  9719. * @param {?=} context
  9720. * @return {?}
  9721. */
  9722. visitText(text, context) { return [new Text$2(text.value)]; }
  9723. /**
  9724. * @param {?} container
  9725. * @param {?=} context
  9726. * @return {?}
  9727. */
  9728. visitContainer(container, context) {
  9729. const /** @type {?} */ nodes = [];
  9730. container.children.forEach((node) => nodes.push(...node.visit(this)));
  9731. return nodes;
  9732. }
  9733. /**
  9734. * @param {?} icu
  9735. * @param {?=} context
  9736. * @return {?}
  9737. */
  9738. visitIcu(icu, context) {
  9739. const /** @type {?} */ nodes = [new Text$2(`{${icu.expressionPlaceholder}, ${icu.type}, `)];
  9740. Object.keys(icu.cases).forEach((c) => {
  9741. nodes.push(new Text$2(`${c} {`), ...icu.cases[c].visit(this), new Text$2(`} `));
  9742. });
  9743. nodes.push(new Text$2(`}`));
  9744. return nodes;
  9745. }
  9746. /**
  9747. * @param {?} ph
  9748. * @param {?=} context
  9749. * @return {?}
  9750. */
  9751. visitTagPlaceholder(ph, context) {
  9752. const /** @type {?} */ ctype = getCtypeForTag(ph.tag);
  9753. if (ph.isVoid) {
  9754. // void tags have no children nor closing tags
  9755. return [new Tag(_PLACEHOLDER_TAG, { id: ph.startName, ctype, 'equiv-text': `<${ph.tag}/>` })];
  9756. }
  9757. const /** @type {?} */ startTagPh = new Tag(_PLACEHOLDER_TAG, { id: ph.startName, ctype, 'equiv-text': `<${ph.tag}>` });
  9758. const /** @type {?} */ closeTagPh = new Tag(_PLACEHOLDER_TAG, { id: ph.closeName, ctype, 'equiv-text': `</${ph.tag}>` });
  9759. return [startTagPh, ...this.serialize(ph.children), closeTagPh];
  9760. }
  9761. /**
  9762. * @param {?} ph
  9763. * @param {?=} context
  9764. * @return {?}
  9765. */
  9766. visitPlaceholder(ph, context) {
  9767. return [new Tag(_PLACEHOLDER_TAG, { id: ph.name, 'equiv-text': `{{${ph.value}}}` })];
  9768. }
  9769. /**
  9770. * @param {?} ph
  9771. * @param {?=} context
  9772. * @return {?}
  9773. */
  9774. visitIcuPlaceholder(ph, context) {
  9775. const /** @type {?} */ equivText = `{${ph.value.expression}, ${ph.value.type}, ${Object.keys(ph.value.cases).map((value) => value + ' {...}').join(' ')}}`;
  9776. return [new Tag(_PLACEHOLDER_TAG, { id: ph.name, 'equiv-text': equivText })];
  9777. }
  9778. /**
  9779. * @param {?} nodes
  9780. * @return {?}
  9781. */
  9782. serialize(nodes) {
  9783. return [].concat(...nodes.map(node => node.visit(this)));
  9784. }
  9785. }
  9786. class XliffParser {
  9787. constructor() {
  9788. this._locale = null;
  9789. }
  9790. /**
  9791. * @param {?} xliff
  9792. * @param {?} url
  9793. * @return {?}
  9794. */
  9795. parse(xliff, url) {
  9796. this._unitMlString = null;
  9797. this._msgIdToHtml = {};
  9798. const /** @type {?} */ xml = new XmlParser().parse(xliff, url, false);
  9799. this._errors = xml.errors;
  9800. visitAll(this, xml.rootNodes, null);
  9801. return {
  9802. msgIdToHtml: this._msgIdToHtml,
  9803. errors: this._errors,
  9804. locale: this._locale,
  9805. };
  9806. }
  9807. /**
  9808. * @param {?} element
  9809. * @param {?} context
  9810. * @return {?}
  9811. */
  9812. visitElement(element, context) {
  9813. switch (element.name) {
  9814. case _UNIT_TAG:
  9815. this._unitMlString = /** @type {?} */ ((null));
  9816. const /** @type {?} */ idAttr = element.attrs.find((attr) => attr.name === 'id');
  9817. if (!idAttr) {
  9818. this._addError(element, `<${_UNIT_TAG}> misses the "id" attribute`);
  9819. }
  9820. else {
  9821. const /** @type {?} */ id = idAttr.value;
  9822. if (this._msgIdToHtml.hasOwnProperty(id)) {
  9823. this._addError(element, `Duplicated translations for msg ${id}`);
  9824. }
  9825. else {
  9826. visitAll(this, element.children, null);
  9827. if (typeof this._unitMlString === 'string') {
  9828. this._msgIdToHtml[id] = this._unitMlString;
  9829. }
  9830. else {
  9831. this._addError(element, `Message ${id} misses a translation`);
  9832. }
  9833. }
  9834. }
  9835. break;
  9836. // ignore those tags
  9837. case _SOURCE_TAG:
  9838. case _SEGMENT_SOURCE_TAG:
  9839. break;
  9840. case _TARGET_TAG:
  9841. const /** @type {?} */ innerTextStart = /** @type {?} */ ((element.startSourceSpan)).end.offset;
  9842. const /** @type {?} */ innerTextEnd = /** @type {?} */ ((element.endSourceSpan)).start.offset;
  9843. const /** @type {?} */ content = /** @type {?} */ ((element.startSourceSpan)).start.file.content;
  9844. const /** @type {?} */ innerText = content.slice(innerTextStart, innerTextEnd);
  9845. this._unitMlString = innerText;
  9846. break;
  9847. case _FILE_TAG:
  9848. const /** @type {?} */ localeAttr = element.attrs.find((attr) => attr.name === 'target-language');
  9849. if (localeAttr) {
  9850. this._locale = localeAttr.value;
  9851. }
  9852. visitAll(this, element.children, null);
  9853. break;
  9854. default:
  9855. // TODO(vicb): assert file structure, xliff version
  9856. // For now only recurse on unhandled nodes
  9857. visitAll(this, element.children, null);
  9858. }
  9859. }
  9860. /**
  9861. * @param {?} attribute
  9862. * @param {?} context
  9863. * @return {?}
  9864. */
  9865. visitAttribute(attribute, context) { }
  9866. /**
  9867. * @param {?} text
  9868. * @param {?} context
  9869. * @return {?}
  9870. */
  9871. visitText(text, context) { }
  9872. /**
  9873. * @param {?} comment
  9874. * @param {?} context
  9875. * @return {?}
  9876. */
  9877. visitComment(comment, context) { }
  9878. /**
  9879. * @param {?} expansion
  9880. * @param {?} context
  9881. * @return {?}
  9882. */
  9883. visitExpansion(expansion, context) { }
  9884. /**
  9885. * @param {?} expansionCase
  9886. * @param {?} context
  9887. * @return {?}
  9888. */
  9889. visitExpansionCase(expansionCase, context) { }
  9890. /**
  9891. * @param {?} node
  9892. * @param {?} message
  9893. * @return {?}
  9894. */
  9895. _addError(node, message) {
  9896. this._errors.push(new I18nError(/** @type {?} */ ((node.sourceSpan)), message));
  9897. }
  9898. }
  9899. class XmlToI18n {
  9900. /**
  9901. * @param {?} message
  9902. * @param {?} url
  9903. * @return {?}
  9904. */
  9905. convert(message, url) {
  9906. const /** @type {?} */ xmlIcu = new XmlParser().parse(message, url, true);
  9907. this._errors = xmlIcu.errors;
  9908. const /** @type {?} */ i18nNodes = this._errors.length > 0 || xmlIcu.rootNodes.length == 0 ?
  9909. [] :
  9910. [].concat(...visitAll(this, xmlIcu.rootNodes));
  9911. return {
  9912. i18nNodes: i18nNodes,
  9913. errors: this._errors,
  9914. };
  9915. }
  9916. /**
  9917. * @param {?} text
  9918. * @param {?} context
  9919. * @return {?}
  9920. */
  9921. visitText(text, context) { return new Text$1(text.value, /** @type {?} */ ((text.sourceSpan))); }
  9922. /**
  9923. * @param {?} el
  9924. * @param {?} context
  9925. * @return {?}
  9926. */
  9927. visitElement(el, context) {
  9928. if (el.name === _PLACEHOLDER_TAG) {
  9929. const /** @type {?} */ nameAttr = el.attrs.find((attr) => attr.name === 'id');
  9930. if (nameAttr) {
  9931. return new Placeholder('', nameAttr.value, /** @type {?} */ ((el.sourceSpan)));
  9932. }
  9933. this._addError(el, `<${_PLACEHOLDER_TAG}> misses the "id" attribute`);
  9934. return null;
  9935. }
  9936. if (el.name === _MARKER_TAG) {
  9937. return [].concat(...visitAll(this, el.children));
  9938. }
  9939. this._addError(el, `Unexpected tag`);
  9940. return null;
  9941. }
  9942. /**
  9943. * @param {?} icu
  9944. * @param {?} context
  9945. * @return {?}
  9946. */
  9947. visitExpansion(icu, context) {
  9948. const /** @type {?} */ caseMap = {};
  9949. visitAll(this, icu.cases).forEach((c) => {
  9950. caseMap[c.value] = new Container(c.nodes, icu.sourceSpan);
  9951. });
  9952. return new Icu(icu.switchValue, icu.type, caseMap, icu.sourceSpan);
  9953. }
  9954. /**
  9955. * @param {?} icuCase
  9956. * @param {?} context
  9957. * @return {?}
  9958. */
  9959. visitExpansionCase(icuCase, context) {
  9960. return {
  9961. value: icuCase.value,
  9962. nodes: visitAll(this, icuCase.expression),
  9963. };
  9964. }
  9965. /**
  9966. * @param {?} comment
  9967. * @param {?} context
  9968. * @return {?}
  9969. */
  9970. visitComment(comment, context) { }
  9971. /**
  9972. * @param {?} attribute
  9973. * @param {?} context
  9974. * @return {?}
  9975. */
  9976. visitAttribute(attribute, context) { }
  9977. /**
  9978. * @param {?} node
  9979. * @param {?} message
  9980. * @return {?}
  9981. */
  9982. _addError(node, message) {
  9983. this._errors.push(new I18nError(/** @type {?} */ ((node.sourceSpan)), message));
  9984. }
  9985. }
  9986. /**
  9987. * @param {?} tag
  9988. * @return {?}
  9989. */
  9990. function getCtypeForTag(tag) {
  9991. switch (tag.toLowerCase()) {
  9992. case 'br':
  9993. return 'lb';
  9994. case 'img':
  9995. return 'image';
  9996. default:
  9997. return `x-${tag}`;
  9998. }
  9999. }
  10000. /**
  10001. * @fileoverview added by tsickle
  10002. * @suppress {checkTypes} checked by tsc
  10003. */
  10004. /**
  10005. * @license
  10006. * Copyright Google Inc. All Rights Reserved.
  10007. *
  10008. * Use of this source code is governed by an MIT-style license that can be
  10009. * found in the LICENSE file at https://angular.io/license
  10010. */
  10011. const _VERSION$1 = '2.0';
  10012. const _XMLNS$1 = 'urn:oasis:names:tc:xliff:document:2.0';
  10013. // TODO(vicb): make this a param (s/_/-/)
  10014. const _DEFAULT_SOURCE_LANG$1 = 'en';
  10015. const _PLACEHOLDER_TAG$1 = 'ph';
  10016. const _PLACEHOLDER_SPANNING_TAG = 'pc';
  10017. const _MARKER_TAG$1 = 'mrk';
  10018. const _XLIFF_TAG = 'xliff';
  10019. const _SOURCE_TAG$1 = 'source';
  10020. const _TARGET_TAG$1 = 'target';
  10021. const _UNIT_TAG$1 = 'unit';
  10022. class Xliff2 extends Serializer {
  10023. /**
  10024. * @param {?} messages
  10025. * @param {?} locale
  10026. * @return {?}
  10027. */
  10028. write(messages, locale) {
  10029. const /** @type {?} */ visitor = new _WriteVisitor$1();
  10030. const /** @type {?} */ units = [];
  10031. messages.forEach(message => {
  10032. const /** @type {?} */ unit = new Tag(_UNIT_TAG$1, { id: message.id });
  10033. const /** @type {?} */ notes = new Tag('notes');
  10034. if (message.description || message.meaning) {
  10035. if (message.description) {
  10036. notes.children.push(new CR(8), new Tag('note', { category: 'description' }, [new Text$2(message.description)]));
  10037. }
  10038. if (message.meaning) {
  10039. notes.children.push(new CR(8), new Tag('note', { category: 'meaning' }, [new Text$2(message.meaning)]));
  10040. }
  10041. }
  10042. message.sources.forEach((source) => {
  10043. notes.children.push(new CR(8), new Tag('note', { category: 'location' }, [
  10044. new Text$2(`${source.filePath}:${source.startLine}${source.endLine !== source.startLine ? ',' + source.endLine : ''}`)
  10045. ]));
  10046. });
  10047. notes.children.push(new CR(6));
  10048. unit.children.push(new CR(6), notes);
  10049. const /** @type {?} */ segment = new Tag('segment');
  10050. segment.children.push(new CR(8), new Tag(_SOURCE_TAG$1, {}, visitor.serialize(message.nodes)), new CR(6));
  10051. unit.children.push(new CR(6), segment, new CR(4));
  10052. units.push(new CR(4), unit);
  10053. });
  10054. const /** @type {?} */ file = new Tag('file', { 'original': 'ng.template', id: 'ngi18n' }, [...units, new CR(2)]);
  10055. const /** @type {?} */ xliff = new Tag(_XLIFF_TAG, { version: _VERSION$1, xmlns: _XMLNS$1, srcLang: locale || _DEFAULT_SOURCE_LANG$1 }, [new CR(2), file, new CR()]);
  10056. return serialize([
  10057. new Declaration({ version: '1.0', encoding: 'UTF-8' }), new CR(), xliff, new CR()
  10058. ]);
  10059. }
  10060. /**
  10061. * @param {?} content
  10062. * @param {?} url
  10063. * @return {?}
  10064. */
  10065. load(content, url) {
  10066. // xliff to xml nodes
  10067. const /** @type {?} */ xliff2Parser = new Xliff2Parser();
  10068. const { locale, msgIdToHtml, errors } = xliff2Parser.parse(content, url);
  10069. // xml nodes to i18n nodes
  10070. const /** @type {?} */ i18nNodesByMsgId = {};
  10071. const /** @type {?} */ converter = new XmlToI18n$1();
  10072. Object.keys(msgIdToHtml).forEach(msgId => {
  10073. const { i18nNodes, errors: e } = converter.convert(msgIdToHtml[msgId], url);
  10074. errors.push(...e);
  10075. i18nNodesByMsgId[msgId] = i18nNodes;
  10076. });
  10077. if (errors.length) {
  10078. throw new Error(`xliff2 parse errors:\n${errors.join('\n')}`);
  10079. }
  10080. return { locale: /** @type {?} */ ((locale)), i18nNodesByMsgId };
  10081. }
  10082. /**
  10083. * @param {?} message
  10084. * @return {?}
  10085. */
  10086. digest(message) { return decimalDigest(message); }
  10087. }
  10088. class _WriteVisitor$1 {
  10089. /**
  10090. * @param {?} text
  10091. * @param {?=} context
  10092. * @return {?}
  10093. */
  10094. visitText(text, context) { return [new Text$2(text.value)]; }
  10095. /**
  10096. * @param {?} container
  10097. * @param {?=} context
  10098. * @return {?}
  10099. */
  10100. visitContainer(container, context) {
  10101. const /** @type {?} */ nodes = [];
  10102. container.children.forEach((node) => nodes.push(...node.visit(this)));
  10103. return nodes;
  10104. }
  10105. /**
  10106. * @param {?} icu
  10107. * @param {?=} context
  10108. * @return {?}
  10109. */
  10110. visitIcu(icu, context) {
  10111. const /** @type {?} */ nodes = [new Text$2(`{${icu.expressionPlaceholder}, ${icu.type}, `)];
  10112. Object.keys(icu.cases).forEach((c) => {
  10113. nodes.push(new Text$2(`${c} {`), ...icu.cases[c].visit(this), new Text$2(`} `));
  10114. });
  10115. nodes.push(new Text$2(`}`));
  10116. return nodes;
  10117. }
  10118. /**
  10119. * @param {?} ph
  10120. * @param {?=} context
  10121. * @return {?}
  10122. */
  10123. visitTagPlaceholder(ph, context) {
  10124. const /** @type {?} */ type = getTypeForTag(ph.tag);
  10125. if (ph.isVoid) {
  10126. const /** @type {?} */ tagPh = new Tag(_PLACEHOLDER_TAG$1, {
  10127. id: (this._nextPlaceholderId++).toString(),
  10128. equiv: ph.startName,
  10129. type: type,
  10130. disp: `<${ph.tag}/>`,
  10131. });
  10132. return [tagPh];
  10133. }
  10134. const /** @type {?} */ tagPc = new Tag(_PLACEHOLDER_SPANNING_TAG, {
  10135. id: (this._nextPlaceholderId++).toString(),
  10136. equivStart: ph.startName,
  10137. equivEnd: ph.closeName,
  10138. type: type,
  10139. dispStart: `<${ph.tag}>`,
  10140. dispEnd: `</${ph.tag}>`,
  10141. });
  10142. const /** @type {?} */ nodes = [].concat(...ph.children.map(node => node.visit(this)));
  10143. if (nodes.length) {
  10144. nodes.forEach((node) => tagPc.children.push(node));
  10145. }
  10146. else {
  10147. tagPc.children.push(new Text$2(''));
  10148. }
  10149. return [tagPc];
  10150. }
  10151. /**
  10152. * @param {?} ph
  10153. * @param {?=} context
  10154. * @return {?}
  10155. */
  10156. visitPlaceholder(ph, context) {
  10157. const /** @type {?} */ idStr = (this._nextPlaceholderId++).toString();
  10158. return [new Tag(_PLACEHOLDER_TAG$1, {
  10159. id: idStr,
  10160. equiv: ph.name,
  10161. disp: `{{${ph.value}}}`,
  10162. })];
  10163. }
  10164. /**
  10165. * @param {?} ph
  10166. * @param {?=} context
  10167. * @return {?}
  10168. */
  10169. visitIcuPlaceholder(ph, context) {
  10170. const /** @type {?} */ cases = Object.keys(ph.value.cases).map((value) => value + ' {...}').join(' ');
  10171. const /** @type {?} */ idStr = (this._nextPlaceholderId++).toString();
  10172. return [new Tag(_PLACEHOLDER_TAG$1, { id: idStr, equiv: ph.name, disp: `{${ph.value.expression}, ${ph.value.type}, ${cases}}` })];
  10173. }
  10174. /**
  10175. * @param {?} nodes
  10176. * @return {?}
  10177. */
  10178. serialize(nodes) {
  10179. this._nextPlaceholderId = 0;
  10180. return [].concat(...nodes.map(node => node.visit(this)));
  10181. }
  10182. }
  10183. class Xliff2Parser {
  10184. constructor() {
  10185. this._locale = null;
  10186. }
  10187. /**
  10188. * @param {?} xliff
  10189. * @param {?} url
  10190. * @return {?}
  10191. */
  10192. parse(xliff, url) {
  10193. this._unitMlString = null;
  10194. this._msgIdToHtml = {};
  10195. const /** @type {?} */ xml = new XmlParser().parse(xliff, url, false);
  10196. this._errors = xml.errors;
  10197. visitAll(this, xml.rootNodes, null);
  10198. return {
  10199. msgIdToHtml: this._msgIdToHtml,
  10200. errors: this._errors,
  10201. locale: this._locale,
  10202. };
  10203. }
  10204. /**
  10205. * @param {?} element
  10206. * @param {?} context
  10207. * @return {?}
  10208. */
  10209. visitElement(element, context) {
  10210. switch (element.name) {
  10211. case _UNIT_TAG$1:
  10212. this._unitMlString = null;
  10213. const /** @type {?} */ idAttr = element.attrs.find((attr) => attr.name === 'id');
  10214. if (!idAttr) {
  10215. this._addError(element, `<${_UNIT_TAG$1}> misses the "id" attribute`);
  10216. }
  10217. else {
  10218. const /** @type {?} */ id = idAttr.value;
  10219. if (this._msgIdToHtml.hasOwnProperty(id)) {
  10220. this._addError(element, `Duplicated translations for msg ${id}`);
  10221. }
  10222. else {
  10223. visitAll(this, element.children, null);
  10224. if (typeof this._unitMlString === 'string') {
  10225. this._msgIdToHtml[id] = this._unitMlString;
  10226. }
  10227. else {
  10228. this._addError(element, `Message ${id} misses a translation`);
  10229. }
  10230. }
  10231. }
  10232. break;
  10233. case _SOURCE_TAG$1:
  10234. // ignore source message
  10235. break;
  10236. case _TARGET_TAG$1:
  10237. const /** @type {?} */ innerTextStart = /** @type {?} */ ((element.startSourceSpan)).end.offset;
  10238. const /** @type {?} */ innerTextEnd = /** @type {?} */ ((element.endSourceSpan)).start.offset;
  10239. const /** @type {?} */ content = /** @type {?} */ ((element.startSourceSpan)).start.file.content;
  10240. const /** @type {?} */ innerText = content.slice(innerTextStart, innerTextEnd);
  10241. this._unitMlString = innerText;
  10242. break;
  10243. case _XLIFF_TAG:
  10244. const /** @type {?} */ localeAttr = element.attrs.find((attr) => attr.name === 'trgLang');
  10245. if (localeAttr) {
  10246. this._locale = localeAttr.value;
  10247. }
  10248. const /** @type {?} */ versionAttr = element.attrs.find((attr) => attr.name === 'version');
  10249. if (versionAttr) {
  10250. const /** @type {?} */ version = versionAttr.value;
  10251. if (version !== '2.0') {
  10252. this._addError(element, `The XLIFF file version ${version} is not compatible with XLIFF 2.0 serializer`);
  10253. }
  10254. else {
  10255. visitAll(this, element.children, null);
  10256. }
  10257. }
  10258. break;
  10259. default:
  10260. visitAll(this, element.children, null);
  10261. }
  10262. }
  10263. /**
  10264. * @param {?} attribute
  10265. * @param {?} context
  10266. * @return {?}
  10267. */
  10268. visitAttribute(attribute, context) { }
  10269. /**
  10270. * @param {?} text
  10271. * @param {?} context
  10272. * @return {?}
  10273. */
  10274. visitText(text, context) { }
  10275. /**
  10276. * @param {?} comment
  10277. * @param {?} context
  10278. * @return {?}
  10279. */
  10280. visitComment(comment, context) { }
  10281. /**
  10282. * @param {?} expansion
  10283. * @param {?} context
  10284. * @return {?}
  10285. */
  10286. visitExpansion(expansion, context) { }
  10287. /**
  10288. * @param {?} expansionCase
  10289. * @param {?} context
  10290. * @return {?}
  10291. */
  10292. visitExpansionCase(expansionCase, context) { }
  10293. /**
  10294. * @param {?} node
  10295. * @param {?} message
  10296. * @return {?}
  10297. */
  10298. _addError(node, message) {
  10299. this._errors.push(new I18nError(node.sourceSpan, message));
  10300. }
  10301. }
  10302. class XmlToI18n$1 {
  10303. /**
  10304. * @param {?} message
  10305. * @param {?} url
  10306. * @return {?}
  10307. */
  10308. convert(message, url) {
  10309. const /** @type {?} */ xmlIcu = new XmlParser().parse(message, url, true);
  10310. this._errors = xmlIcu.errors;
  10311. const /** @type {?} */ i18nNodes = this._errors.length > 0 || xmlIcu.rootNodes.length == 0 ?
  10312. [] :
  10313. [].concat(...visitAll(this, xmlIcu.rootNodes));
  10314. return {
  10315. i18nNodes,
  10316. errors: this._errors,
  10317. };
  10318. }
  10319. /**
  10320. * @param {?} text
  10321. * @param {?} context
  10322. * @return {?}
  10323. */
  10324. visitText(text, context) { return new Text$1(text.value, text.sourceSpan); }
  10325. /**
  10326. * @param {?} el
  10327. * @param {?} context
  10328. * @return {?}
  10329. */
  10330. visitElement(el, context) {
  10331. switch (el.name) {
  10332. case _PLACEHOLDER_TAG$1:
  10333. const /** @type {?} */ nameAttr = el.attrs.find((attr) => attr.name === 'equiv');
  10334. if (nameAttr) {
  10335. return [new Placeholder('', nameAttr.value, el.sourceSpan)];
  10336. }
  10337. this._addError(el, `<${_PLACEHOLDER_TAG$1}> misses the "equiv" attribute`);
  10338. break;
  10339. case _PLACEHOLDER_SPANNING_TAG:
  10340. const /** @type {?} */ startAttr = el.attrs.find((attr) => attr.name === 'equivStart');
  10341. const /** @type {?} */ endAttr = el.attrs.find((attr) => attr.name === 'equivEnd');
  10342. if (!startAttr) {
  10343. this._addError(el, `<${_PLACEHOLDER_TAG$1}> misses the "equivStart" attribute`);
  10344. }
  10345. else if (!endAttr) {
  10346. this._addError(el, `<${_PLACEHOLDER_TAG$1}> misses the "equivEnd" attribute`);
  10347. }
  10348. else {
  10349. const /** @type {?} */ startId = startAttr.value;
  10350. const /** @type {?} */ endId = endAttr.value;
  10351. const /** @type {?} */ nodes = [];
  10352. return nodes.concat(new Placeholder('', startId, el.sourceSpan), ...el.children.map(node => node.visit(this, null)), new Placeholder('', endId, el.sourceSpan));
  10353. }
  10354. break;
  10355. case _MARKER_TAG$1:
  10356. return [].concat(...visitAll(this, el.children));
  10357. default:
  10358. this._addError(el, `Unexpected tag`);
  10359. }
  10360. return null;
  10361. }
  10362. /**
  10363. * @param {?} icu
  10364. * @param {?} context
  10365. * @return {?}
  10366. */
  10367. visitExpansion(icu, context) {
  10368. const /** @type {?} */ caseMap = {};
  10369. visitAll(this, icu.cases).forEach((c) => {
  10370. caseMap[c.value] = new Container(c.nodes, icu.sourceSpan);
  10371. });
  10372. return new Icu(icu.switchValue, icu.type, caseMap, icu.sourceSpan);
  10373. }
  10374. /**
  10375. * @param {?} icuCase
  10376. * @param {?} context
  10377. * @return {?}
  10378. */
  10379. visitExpansionCase(icuCase, context) {
  10380. return {
  10381. value: icuCase.value,
  10382. nodes: [].concat(...visitAll(this, icuCase.expression)),
  10383. };
  10384. }
  10385. /**
  10386. * @param {?} comment
  10387. * @param {?} context
  10388. * @return {?}
  10389. */
  10390. visitComment(comment, context) { }
  10391. /**
  10392. * @param {?} attribute
  10393. * @param {?} context
  10394. * @return {?}
  10395. */
  10396. visitAttribute(attribute, context) { }
  10397. /**
  10398. * @param {?} node
  10399. * @param {?} message
  10400. * @return {?}
  10401. */
  10402. _addError(node, message) {
  10403. this._errors.push(new I18nError(node.sourceSpan, message));
  10404. }
  10405. }
  10406. /**
  10407. * @param {?} tag
  10408. * @return {?}
  10409. */
  10410. function getTypeForTag(tag) {
  10411. switch (tag.toLowerCase()) {
  10412. case 'br':
  10413. case 'b':
  10414. case 'i':
  10415. case 'u':
  10416. return 'fmt';
  10417. case 'img':
  10418. return 'image';
  10419. case 'a':
  10420. return 'link';
  10421. default:
  10422. return 'other';
  10423. }
  10424. }
  10425. /**
  10426. * @fileoverview added by tsickle
  10427. * @suppress {checkTypes} checked by tsc
  10428. */
  10429. /**
  10430. * @license
  10431. * Copyright Google Inc. All Rights Reserved.
  10432. *
  10433. * Use of this source code is governed by an MIT-style license that can be
  10434. * found in the LICENSE file at https://angular.io/license
  10435. */
  10436. const _MESSAGES_TAG = 'messagebundle';
  10437. const _MESSAGE_TAG = 'msg';
  10438. const _PLACEHOLDER_TAG$2 = 'ph';
  10439. const _EXEMPLE_TAG = 'ex';
  10440. const _SOURCE_TAG$2 = 'source';
  10441. const _DOCTYPE = `<!ELEMENT messagebundle (msg)*>
  10442. <!ATTLIST messagebundle class CDATA #IMPLIED>
  10443. <!ELEMENT msg (#PCDATA|ph|source)*>
  10444. <!ATTLIST msg id CDATA #IMPLIED>
  10445. <!ATTLIST msg seq CDATA #IMPLIED>
  10446. <!ATTLIST msg name CDATA #IMPLIED>
  10447. <!ATTLIST msg desc CDATA #IMPLIED>
  10448. <!ATTLIST msg meaning CDATA #IMPLIED>
  10449. <!ATTLIST msg obsolete (obsolete) #IMPLIED>
  10450. <!ATTLIST msg xml:space (default|preserve) "default">
  10451. <!ATTLIST msg is_hidden CDATA #IMPLIED>
  10452. <!ELEMENT source (#PCDATA)>
  10453. <!ELEMENT ph (#PCDATA|ex)*>
  10454. <!ATTLIST ph name CDATA #REQUIRED>
  10455. <!ELEMENT ex (#PCDATA)>`;
  10456. class Xmb extends Serializer {
  10457. /**
  10458. * @param {?} messages
  10459. * @param {?} locale
  10460. * @return {?}
  10461. */
  10462. write(messages, locale) {
  10463. const /** @type {?} */ exampleVisitor = new ExampleVisitor();
  10464. const /** @type {?} */ visitor = new _Visitor$2();
  10465. let /** @type {?} */ rootNode = new Tag(_MESSAGES_TAG);
  10466. messages.forEach(message => {
  10467. const /** @type {?} */ attrs = { id: message.id };
  10468. if (message.description) {
  10469. attrs['desc'] = message.description;
  10470. }
  10471. if (message.meaning) {
  10472. attrs['meaning'] = message.meaning;
  10473. }
  10474. let /** @type {?} */ sourceTags = [];
  10475. message.sources.forEach((source) => {
  10476. sourceTags.push(new Tag(_SOURCE_TAG$2, {}, [
  10477. new Text$2(`${source.filePath}:${source.startLine}${source.endLine !== source.startLine ? ',' + source.endLine : ''}`)
  10478. ]));
  10479. });
  10480. rootNode.children.push(new CR(2), new Tag(_MESSAGE_TAG, attrs, [...sourceTags, ...visitor.serialize(message.nodes)]));
  10481. });
  10482. rootNode.children.push(new CR());
  10483. return serialize([
  10484. new Declaration({ version: '1.0', encoding: 'UTF-8' }),
  10485. new CR(),
  10486. new Doctype(_MESSAGES_TAG, _DOCTYPE),
  10487. new CR(),
  10488. exampleVisitor.addDefaultExamples(rootNode),
  10489. new CR(),
  10490. ]);
  10491. }
  10492. /**
  10493. * @param {?} content
  10494. * @param {?} url
  10495. * @return {?}
  10496. */
  10497. load(content, url) {
  10498. throw new Error('Unsupported');
  10499. }
  10500. /**
  10501. * @param {?} message
  10502. * @return {?}
  10503. */
  10504. digest(message) { return digest$1(message); }
  10505. /**
  10506. * @param {?} message
  10507. * @return {?}
  10508. */
  10509. createNameMapper(message) {
  10510. return new SimplePlaceholderMapper(message, toPublicName);
  10511. }
  10512. }
  10513. class _Visitor$2 {
  10514. /**
  10515. * @param {?} text
  10516. * @param {?=} context
  10517. * @return {?}
  10518. */
  10519. visitText(text, context) { return [new Text$2(text.value)]; }
  10520. /**
  10521. * @param {?} container
  10522. * @param {?} context
  10523. * @return {?}
  10524. */
  10525. visitContainer(container, context) {
  10526. const /** @type {?} */ nodes = [];
  10527. container.children.forEach((node) => nodes.push(...node.visit(this)));
  10528. return nodes;
  10529. }
  10530. /**
  10531. * @param {?} icu
  10532. * @param {?=} context
  10533. * @return {?}
  10534. */
  10535. visitIcu(icu, context) {
  10536. const /** @type {?} */ nodes = [new Text$2(`{${icu.expressionPlaceholder}, ${icu.type}, `)];
  10537. Object.keys(icu.cases).forEach((c) => {
  10538. nodes.push(new Text$2(`${c} {`), ...icu.cases[c].visit(this), new Text$2(`} `));
  10539. });
  10540. nodes.push(new Text$2(`}`));
  10541. return nodes;
  10542. }
  10543. /**
  10544. * @param {?} ph
  10545. * @param {?=} context
  10546. * @return {?}
  10547. */
  10548. visitTagPlaceholder(ph, context) {
  10549. const /** @type {?} */ startEx = new Tag(_EXEMPLE_TAG, {}, [new Text$2(`<${ph.tag}>`)]);
  10550. const /** @type {?} */ startTagPh = new Tag(_PLACEHOLDER_TAG$2, { name: ph.startName }, [startEx]);
  10551. if (ph.isVoid) {
  10552. // void tags have no children nor closing tags
  10553. return [startTagPh];
  10554. }
  10555. const /** @type {?} */ closeEx = new Tag(_EXEMPLE_TAG, {}, [new Text$2(`</${ph.tag}>`)]);
  10556. const /** @type {?} */ closeTagPh = new Tag(_PLACEHOLDER_TAG$2, { name: ph.closeName }, [closeEx]);
  10557. return [startTagPh, ...this.serialize(ph.children), closeTagPh];
  10558. }
  10559. /**
  10560. * @param {?} ph
  10561. * @param {?=} context
  10562. * @return {?}
  10563. */
  10564. visitPlaceholder(ph, context) {
  10565. const /** @type {?} */ exTag = new Tag(_EXEMPLE_TAG, {}, [new Text$2(`{{${ph.value}}}`)]);
  10566. return [new Tag(_PLACEHOLDER_TAG$2, { name: ph.name }, [exTag])];
  10567. }
  10568. /**
  10569. * @param {?} ph
  10570. * @param {?=} context
  10571. * @return {?}
  10572. */
  10573. visitIcuPlaceholder(ph, context) {
  10574. const /** @type {?} */ exTag = new Tag(_EXEMPLE_TAG, {}, [
  10575. new Text$2(`{${ph.value.expression}, ${ph.value.type}, ${Object.keys(ph.value.cases).map((value) => value + ' {...}').join(' ')}}`)
  10576. ]);
  10577. return [new Tag(_PLACEHOLDER_TAG$2, { name: ph.name }, [exTag])];
  10578. }
  10579. /**
  10580. * @param {?} nodes
  10581. * @return {?}
  10582. */
  10583. serialize(nodes) {
  10584. return [].concat(...nodes.map(node => node.visit(this)));
  10585. }
  10586. }
  10587. /**
  10588. * @param {?} message
  10589. * @return {?}
  10590. */
  10591. function digest$1(message) {
  10592. return decimalDigest(message);
  10593. }
  10594. class ExampleVisitor {
  10595. /**
  10596. * @param {?} node
  10597. * @return {?}
  10598. */
  10599. addDefaultExamples(node) {
  10600. node.visit(this);
  10601. return node;
  10602. }
  10603. /**
  10604. * @param {?} tag
  10605. * @return {?}
  10606. */
  10607. visitTag(tag) {
  10608. if (tag.name === _PLACEHOLDER_TAG$2) {
  10609. if (!tag.children || tag.children.length == 0) {
  10610. const /** @type {?} */ exText = new Text$2(tag.attrs['name'] || '...');
  10611. tag.children = [new Tag(_EXEMPLE_TAG, {}, [exText])];
  10612. }
  10613. }
  10614. else if (tag.children) {
  10615. tag.children.forEach(node => node.visit(this));
  10616. }
  10617. }
  10618. /**
  10619. * @param {?} text
  10620. * @return {?}
  10621. */
  10622. visitText(text) { }
  10623. /**
  10624. * @param {?} decl
  10625. * @return {?}
  10626. */
  10627. visitDeclaration(decl) { }
  10628. /**
  10629. * @param {?} doctype
  10630. * @return {?}
  10631. */
  10632. visitDoctype(doctype) { }
  10633. }
  10634. /**
  10635. * @param {?} internalName
  10636. * @return {?}
  10637. */
  10638. function toPublicName(internalName) {
  10639. return internalName.toUpperCase().replace(/[^A-Z0-9_]/g, '_');
  10640. }
  10641. /**
  10642. * @fileoverview added by tsickle
  10643. * @suppress {checkTypes} checked by tsc
  10644. */
  10645. /**
  10646. * @license
  10647. * Copyright Google Inc. All Rights Reserved.
  10648. *
  10649. * Use of this source code is governed by an MIT-style license that can be
  10650. * found in the LICENSE file at https://angular.io/license
  10651. */
  10652. const _TRANSLATIONS_TAG = 'translationbundle';
  10653. const _TRANSLATION_TAG = 'translation';
  10654. const _PLACEHOLDER_TAG$3 = 'ph';
  10655. class Xtb extends Serializer {
  10656. /**
  10657. * @param {?} messages
  10658. * @param {?} locale
  10659. * @return {?}
  10660. */
  10661. write(messages, locale) { throw new Error('Unsupported'); }
  10662. /**
  10663. * @param {?} content
  10664. * @param {?} url
  10665. * @return {?}
  10666. */
  10667. load(content, url) {
  10668. // xtb to xml nodes
  10669. const /** @type {?} */ xtbParser = new XtbParser();
  10670. const { locale, msgIdToHtml, errors } = xtbParser.parse(content, url);
  10671. // xml nodes to i18n nodes
  10672. const /** @type {?} */ i18nNodesByMsgId = {};
  10673. const /** @type {?} */ converter = new XmlToI18n$2();
  10674. // Because we should be able to load xtb files that rely on features not supported by angular,
  10675. // we need to delay the conversion of html to i18n nodes so that non angular messages are not
  10676. // converted
  10677. Object.keys(msgIdToHtml).forEach(msgId => {
  10678. const /** @type {?} */ valueFn = function () {
  10679. const { i18nNodes, errors } = converter.convert(msgIdToHtml[msgId], url);
  10680. if (errors.length) {
  10681. throw new Error(`xtb parse errors:\n${errors.join('\n')}`);
  10682. }
  10683. return i18nNodes;
  10684. };
  10685. createLazyProperty(i18nNodesByMsgId, msgId, valueFn);
  10686. });
  10687. if (errors.length) {
  10688. throw new Error(`xtb parse errors:\n${errors.join('\n')}`);
  10689. }
  10690. return { locale: /** @type {?} */ ((locale)), i18nNodesByMsgId };
  10691. }
  10692. /**
  10693. * @param {?} message
  10694. * @return {?}
  10695. */
  10696. digest(message) { return digest$1(message); }
  10697. /**
  10698. * @param {?} message
  10699. * @return {?}
  10700. */
  10701. createNameMapper(message) {
  10702. return new SimplePlaceholderMapper(message, toPublicName);
  10703. }
  10704. }
  10705. /**
  10706. * @param {?} messages
  10707. * @param {?} id
  10708. * @param {?} valueFn
  10709. * @return {?}
  10710. */
  10711. function createLazyProperty(messages, id, valueFn) {
  10712. Object.defineProperty(messages, id, {
  10713. configurable: true,
  10714. enumerable: true,
  10715. get: function () {
  10716. const /** @type {?} */ value = valueFn();
  10717. Object.defineProperty(messages, id, { enumerable: true, value });
  10718. return value;
  10719. },
  10720. set: _ => { throw new Error('Could not overwrite an XTB translation'); },
  10721. });
  10722. }
  10723. class XtbParser {
  10724. constructor() {
  10725. this._locale = null;
  10726. }
  10727. /**
  10728. * @param {?} xtb
  10729. * @param {?} url
  10730. * @return {?}
  10731. */
  10732. parse(xtb, url) {
  10733. this._bundleDepth = 0;
  10734. this._msgIdToHtml = {};
  10735. // We can not parse the ICU messages at this point as some messages might not originate
  10736. // from Angular that could not be lex'd.
  10737. const /** @type {?} */ xml = new XmlParser().parse(xtb, url, false);
  10738. this._errors = xml.errors;
  10739. visitAll(this, xml.rootNodes);
  10740. return {
  10741. msgIdToHtml: this._msgIdToHtml,
  10742. errors: this._errors,
  10743. locale: this._locale,
  10744. };
  10745. }
  10746. /**
  10747. * @param {?} element
  10748. * @param {?} context
  10749. * @return {?}
  10750. */
  10751. visitElement(element, context) {
  10752. switch (element.name) {
  10753. case _TRANSLATIONS_TAG:
  10754. this._bundleDepth++;
  10755. if (this._bundleDepth > 1) {
  10756. this._addError(element, `<${_TRANSLATIONS_TAG}> elements can not be nested`);
  10757. }
  10758. const /** @type {?} */ langAttr = element.attrs.find((attr) => attr.name === 'lang');
  10759. if (langAttr) {
  10760. this._locale = langAttr.value;
  10761. }
  10762. visitAll(this, element.children, null);
  10763. this._bundleDepth--;
  10764. break;
  10765. case _TRANSLATION_TAG:
  10766. const /** @type {?} */ idAttr = element.attrs.find((attr) => attr.name === 'id');
  10767. if (!idAttr) {
  10768. this._addError(element, `<${_TRANSLATION_TAG}> misses the "id" attribute`);
  10769. }
  10770. else {
  10771. const /** @type {?} */ id = idAttr.value;
  10772. if (this._msgIdToHtml.hasOwnProperty(id)) {
  10773. this._addError(element, `Duplicated translations for msg ${id}`);
  10774. }
  10775. else {
  10776. const /** @type {?} */ innerTextStart = /** @type {?} */ ((element.startSourceSpan)).end.offset;
  10777. const /** @type {?} */ innerTextEnd = /** @type {?} */ ((element.endSourceSpan)).start.offset;
  10778. const /** @type {?} */ content = /** @type {?} */ ((element.startSourceSpan)).start.file.content;
  10779. const /** @type {?} */ innerText = content.slice(/** @type {?} */ ((innerTextStart)), /** @type {?} */ ((innerTextEnd)));
  10780. this._msgIdToHtml[id] = innerText;
  10781. }
  10782. }
  10783. break;
  10784. default:
  10785. this._addError(element, 'Unexpected tag');
  10786. }
  10787. }
  10788. /**
  10789. * @param {?} attribute
  10790. * @param {?} context
  10791. * @return {?}
  10792. */
  10793. visitAttribute(attribute, context) { }
  10794. /**
  10795. * @param {?} text
  10796. * @param {?} context
  10797. * @return {?}
  10798. */
  10799. visitText(text, context) { }
  10800. /**
  10801. * @param {?} comment
  10802. * @param {?} context
  10803. * @return {?}
  10804. */
  10805. visitComment(comment, context) { }
  10806. /**
  10807. * @param {?} expansion
  10808. * @param {?} context
  10809. * @return {?}
  10810. */
  10811. visitExpansion(expansion, context) { }
  10812. /**
  10813. * @param {?} expansionCase
  10814. * @param {?} context
  10815. * @return {?}
  10816. */
  10817. visitExpansionCase(expansionCase, context) { }
  10818. /**
  10819. * @param {?} node
  10820. * @param {?} message
  10821. * @return {?}
  10822. */
  10823. _addError(node, message) {
  10824. this._errors.push(new I18nError(/** @type {?} */ ((node.sourceSpan)), message));
  10825. }
  10826. }
  10827. class XmlToI18n$2 {
  10828. /**
  10829. * @param {?} message
  10830. * @param {?} url
  10831. * @return {?}
  10832. */
  10833. convert(message, url) {
  10834. const /** @type {?} */ xmlIcu = new XmlParser().parse(message, url, true);
  10835. this._errors = xmlIcu.errors;
  10836. const /** @type {?} */ i18nNodes = this._errors.length > 0 || xmlIcu.rootNodes.length == 0 ?
  10837. [] :
  10838. visitAll(this, xmlIcu.rootNodes);
  10839. return {
  10840. i18nNodes,
  10841. errors: this._errors,
  10842. };
  10843. }
  10844. /**
  10845. * @param {?} text
  10846. * @param {?} context
  10847. * @return {?}
  10848. */
  10849. visitText(text, context) { return new Text$1(text.value, /** @type {?} */ ((text.sourceSpan))); }
  10850. /**
  10851. * @param {?} icu
  10852. * @param {?} context
  10853. * @return {?}
  10854. */
  10855. visitExpansion(icu, context) {
  10856. const /** @type {?} */ caseMap = {};
  10857. visitAll(this, icu.cases).forEach(c => {
  10858. caseMap[c.value] = new Container(c.nodes, icu.sourceSpan);
  10859. });
  10860. return new Icu(icu.switchValue, icu.type, caseMap, icu.sourceSpan);
  10861. }
  10862. /**
  10863. * @param {?} icuCase
  10864. * @param {?} context
  10865. * @return {?}
  10866. */
  10867. visitExpansionCase(icuCase, context) {
  10868. return {
  10869. value: icuCase.value,
  10870. nodes: visitAll(this, icuCase.expression),
  10871. };
  10872. }
  10873. /**
  10874. * @param {?} el
  10875. * @param {?} context
  10876. * @return {?}
  10877. */
  10878. visitElement(el, context) {
  10879. if (el.name === _PLACEHOLDER_TAG$3) {
  10880. const /** @type {?} */ nameAttr = el.attrs.find((attr) => attr.name === 'name');
  10881. if (nameAttr) {
  10882. return new Placeholder('', nameAttr.value, /** @type {?} */ ((el.sourceSpan)));
  10883. }
  10884. this._addError(el, `<${_PLACEHOLDER_TAG$3}> misses the "name" attribute`);
  10885. }
  10886. else {
  10887. this._addError(el, `Unexpected tag`);
  10888. }
  10889. return null;
  10890. }
  10891. /**
  10892. * @param {?} comment
  10893. * @param {?} context
  10894. * @return {?}
  10895. */
  10896. visitComment(comment, context) { }
  10897. /**
  10898. * @param {?} attribute
  10899. * @param {?} context
  10900. * @return {?}
  10901. */
  10902. visitAttribute(attribute, context) { }
  10903. /**
  10904. * @param {?} node
  10905. * @param {?} message
  10906. * @return {?}
  10907. */
  10908. _addError(node, message) {
  10909. this._errors.push(new I18nError(/** @type {?} */ ((node.sourceSpan)), message));
  10910. }
  10911. }
  10912. /**
  10913. * @fileoverview added by tsickle
  10914. * @suppress {checkTypes} checked by tsc
  10915. */
  10916. /**
  10917. * @license
  10918. * Copyright Google Inc. All Rights Reserved.
  10919. *
  10920. * Use of this source code is governed by an MIT-style license that can be
  10921. * found in the LICENSE file at https://angular.io/license
  10922. */
  10923. class HtmlParser extends Parser$1 {
  10924. constructor() { super(getHtmlTagDefinition); }
  10925. /**
  10926. * @param {?} source
  10927. * @param {?} url
  10928. * @param {?=} parseExpansionForms
  10929. * @param {?=} interpolationConfig
  10930. * @return {?}
  10931. */
  10932. parse(source, url, parseExpansionForms = false, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  10933. return super.parse(source, url, parseExpansionForms, interpolationConfig);
  10934. }
  10935. }
  10936. /**
  10937. * @fileoverview added by tsickle
  10938. * @suppress {checkTypes} checked by tsc
  10939. */
  10940. /**
  10941. * @license
  10942. * Copyright Google Inc. All Rights Reserved.
  10943. *
  10944. * Use of this source code is governed by an MIT-style license that can be
  10945. * found in the LICENSE file at https://angular.io/license
  10946. */
  10947. /**
  10948. * A container for translated messages
  10949. */
  10950. class TranslationBundle {
  10951. /**
  10952. * @param {?=} _i18nNodesByMsgId
  10953. * @param {?=} locale
  10954. * @param {?=} digest
  10955. * @param {?=} mapperFactory
  10956. * @param {?=} missingTranslationStrategy
  10957. * @param {?=} console
  10958. */
  10959. constructor(_i18nNodesByMsgId = {}, locale, digest, mapperFactory, missingTranslationStrategy = MissingTranslationStrategy.Warning, console) {
  10960. this._i18nNodesByMsgId = _i18nNodesByMsgId;
  10961. this.digest = digest;
  10962. this.mapperFactory = mapperFactory;
  10963. this._i18nToHtml = new I18nToHtmlVisitor(_i18nNodesByMsgId, locale, digest, /** @type {?} */ ((mapperFactory)), missingTranslationStrategy, console);
  10964. }
  10965. /**
  10966. * @param {?} content
  10967. * @param {?} url
  10968. * @param {?} serializer
  10969. * @param {?} missingTranslationStrategy
  10970. * @param {?=} console
  10971. * @return {?}
  10972. */
  10973. static load(content, url, serializer, missingTranslationStrategy, console) {
  10974. const { locale, i18nNodesByMsgId } = serializer.load(content, url);
  10975. const /** @type {?} */ digestFn = (m) => serializer.digest(m);
  10976. const /** @type {?} */ mapperFactory = (m) => /** @type {?} */ ((serializer.createNameMapper(m)));
  10977. return new TranslationBundle(i18nNodesByMsgId, locale, digestFn, mapperFactory, missingTranslationStrategy, console);
  10978. }
  10979. /**
  10980. * @param {?} srcMsg
  10981. * @return {?}
  10982. */
  10983. get(srcMsg) {
  10984. const /** @type {?} */ html = this._i18nToHtml.convert(srcMsg);
  10985. if (html.errors.length) {
  10986. throw new Error(html.errors.join('\n'));
  10987. }
  10988. return html.nodes;
  10989. }
  10990. /**
  10991. * @param {?} srcMsg
  10992. * @return {?}
  10993. */
  10994. has(srcMsg) { return this.digest(srcMsg) in this._i18nNodesByMsgId; }
  10995. }
  10996. class I18nToHtmlVisitor {
  10997. /**
  10998. * @param {?=} _i18nNodesByMsgId
  10999. * @param {?=} _locale
  11000. * @param {?=} _digest
  11001. * @param {?=} _mapperFactory
  11002. * @param {?=} _missingTranslationStrategy
  11003. * @param {?=} _console
  11004. */
  11005. constructor(_i18nNodesByMsgId = {}, _locale, _digest, _mapperFactory, _missingTranslationStrategy, _console) {
  11006. this._i18nNodesByMsgId = _i18nNodesByMsgId;
  11007. this._locale = _locale;
  11008. this._digest = _digest;
  11009. this._mapperFactory = _mapperFactory;
  11010. this._missingTranslationStrategy = _missingTranslationStrategy;
  11011. this._console = _console;
  11012. this._contextStack = [];
  11013. this._errors = [];
  11014. }
  11015. /**
  11016. * @param {?} srcMsg
  11017. * @return {?}
  11018. */
  11019. convert(srcMsg) {
  11020. this._contextStack.length = 0;
  11021. this._errors.length = 0;
  11022. // i18n to text
  11023. const /** @type {?} */ text = this._convertToText(srcMsg);
  11024. // text to html
  11025. const /** @type {?} */ url = srcMsg.nodes[0].sourceSpan.start.file.url;
  11026. const /** @type {?} */ html = new HtmlParser().parse(text, url, true);
  11027. return {
  11028. nodes: html.rootNodes,
  11029. errors: [...this._errors, ...html.errors],
  11030. };
  11031. }
  11032. /**
  11033. * @param {?} text
  11034. * @param {?=} context
  11035. * @return {?}
  11036. */
  11037. visitText(text, context) {
  11038. // `convert()` uses an `HtmlParser` to return `html.Node`s
  11039. // we should then make sure that any special characters are escaped
  11040. return escapeXml(text.value);
  11041. }
  11042. /**
  11043. * @param {?} container
  11044. * @param {?=} context
  11045. * @return {?}
  11046. */
  11047. visitContainer(container, context) {
  11048. return container.children.map(n => n.visit(this)).join('');
  11049. }
  11050. /**
  11051. * @param {?} icu
  11052. * @param {?=} context
  11053. * @return {?}
  11054. */
  11055. visitIcu(icu, context) {
  11056. const /** @type {?} */ cases = Object.keys(icu.cases).map(k => `${k} {${icu.cases[k].visit(this)}}`);
  11057. // TODO(vicb): Once all format switch to using expression placeholders
  11058. // we should throw when the placeholder is not in the source message
  11059. const /** @type {?} */ exp = this._srcMsg.placeholders.hasOwnProperty(icu.expression) ?
  11060. this._srcMsg.placeholders[icu.expression] :
  11061. icu.expression;
  11062. return `{${exp}, ${icu.type}, ${cases.join(' ')}}`;
  11063. }
  11064. /**
  11065. * @param {?} ph
  11066. * @param {?=} context
  11067. * @return {?}
  11068. */
  11069. visitPlaceholder(ph, context) {
  11070. const /** @type {?} */ phName = this._mapper(ph.name);
  11071. if (this._srcMsg.placeholders.hasOwnProperty(phName)) {
  11072. return this._srcMsg.placeholders[phName];
  11073. }
  11074. if (this._srcMsg.placeholderToMessage.hasOwnProperty(phName)) {
  11075. return this._convertToText(this._srcMsg.placeholderToMessage[phName]);
  11076. }
  11077. this._addError(ph, `Unknown placeholder "${ph.name}"`);
  11078. return '';
  11079. }
  11080. /**
  11081. * @param {?} ph
  11082. * @param {?=} context
  11083. * @return {?}
  11084. */
  11085. visitTagPlaceholder(ph, context) {
  11086. const /** @type {?} */ tag = `${ph.tag}`;
  11087. const /** @type {?} */ attrs = Object.keys(ph.attrs).map(name => `${name}="${ph.attrs[name]}"`).join(' ');
  11088. if (ph.isVoid) {
  11089. return `<${tag} ${attrs}/>`;
  11090. }
  11091. const /** @type {?} */ children = ph.children.map((c) => c.visit(this)).join('');
  11092. return `<${tag} ${attrs}>${children}</${tag}>`;
  11093. }
  11094. /**
  11095. * @param {?} ph
  11096. * @param {?=} context
  11097. * @return {?}
  11098. */
  11099. visitIcuPlaceholder(ph, context) {
  11100. // An ICU placeholder references the source message to be serialized
  11101. return this._convertToText(this._srcMsg.placeholderToMessage[ph.name]);
  11102. }
  11103. /**
  11104. * Convert a source message to a translated text string:
  11105. * - text nodes are replaced with their translation,
  11106. * - placeholders are replaced with their content,
  11107. * - ICU nodes are converted to ICU expressions.
  11108. * @param {?} srcMsg
  11109. * @return {?}
  11110. */
  11111. _convertToText(srcMsg) {
  11112. const /** @type {?} */ id = this._digest(srcMsg);
  11113. const /** @type {?} */ mapper = this._mapperFactory ? this._mapperFactory(srcMsg) : null;
  11114. let /** @type {?} */ nodes;
  11115. this._contextStack.push({ msg: this._srcMsg, mapper: this._mapper });
  11116. this._srcMsg = srcMsg;
  11117. if (this._i18nNodesByMsgId.hasOwnProperty(id)) {
  11118. // When there is a translation use its nodes as the source
  11119. // And create a mapper to convert serialized placeholder names to internal names
  11120. nodes = this._i18nNodesByMsgId[id];
  11121. this._mapper = (name) => mapper ? /** @type {?} */ ((mapper.toInternalName(name))) : name;
  11122. }
  11123. else {
  11124. // When no translation has been found
  11125. // - report an error / a warning / nothing,
  11126. // - use the nodes from the original message
  11127. // - placeholders are already internal and need no mapper
  11128. if (this._missingTranslationStrategy === MissingTranslationStrategy.Error) {
  11129. const /** @type {?} */ ctx = this._locale ? ` for locale "${this._locale}"` : '';
  11130. this._addError(srcMsg.nodes[0], `Missing translation for message "${id}"${ctx}`);
  11131. }
  11132. else if (this._console &&
  11133. this._missingTranslationStrategy === MissingTranslationStrategy.Warning) {
  11134. const /** @type {?} */ ctx = this._locale ? ` for locale "${this._locale}"` : '';
  11135. this._console.warn(`Missing translation for message "${id}"${ctx}`);
  11136. }
  11137. nodes = srcMsg.nodes;
  11138. this._mapper = (name) => name;
  11139. }
  11140. const /** @type {?} */ text = nodes.map(node => node.visit(this)).join('');
  11141. const /** @type {?} */ context = /** @type {?} */ ((this._contextStack.pop()));
  11142. this._srcMsg = context.msg;
  11143. this._mapper = context.mapper;
  11144. return text;
  11145. }
  11146. /**
  11147. * @param {?} el
  11148. * @param {?} msg
  11149. * @return {?}
  11150. */
  11151. _addError(el, msg) {
  11152. this._errors.push(new I18nError(el.sourceSpan, msg));
  11153. }
  11154. }
  11155. /**
  11156. * @fileoverview added by tsickle
  11157. * @suppress {checkTypes} checked by tsc
  11158. */
  11159. /**
  11160. * @license
  11161. * Copyright Google Inc. All Rights Reserved.
  11162. *
  11163. * Use of this source code is governed by an MIT-style license that can be
  11164. * found in the LICENSE file at https://angular.io/license
  11165. */
  11166. class I18NHtmlParser {
  11167. /**
  11168. * @param {?} _htmlParser
  11169. * @param {?=} translations
  11170. * @param {?=} translationsFormat
  11171. * @param {?=} missingTranslation
  11172. * @param {?=} console
  11173. */
  11174. constructor(_htmlParser, translations, translationsFormat, missingTranslation = MissingTranslationStrategy.Warning, console) {
  11175. this._htmlParser = _htmlParser;
  11176. if (translations) {
  11177. const /** @type {?} */ serializer = createSerializer(translationsFormat);
  11178. this._translationBundle =
  11179. TranslationBundle.load(translations, 'i18n', serializer, missingTranslation, console);
  11180. }
  11181. else {
  11182. this._translationBundle =
  11183. new TranslationBundle({}, null, digest, undefined, missingTranslation, console);
  11184. }
  11185. }
  11186. /**
  11187. * @param {?} source
  11188. * @param {?} url
  11189. * @param {?=} parseExpansionForms
  11190. * @param {?=} interpolationConfig
  11191. * @return {?}
  11192. */
  11193. parse(source, url, parseExpansionForms = false, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
  11194. const /** @type {?} */ parseResult = this._htmlParser.parse(source, url, parseExpansionForms, interpolationConfig);
  11195. if (parseResult.errors.length) {
  11196. return new ParseTreeResult(parseResult.rootNodes, parseResult.errors);
  11197. }
  11198. return mergeTranslations(parseResult.rootNodes, this._translationBundle, interpolationConfig, [], {});
  11199. }
  11200. }
  11201. /**
  11202. * @param {?=} format
  11203. * @return {?}
  11204. */
  11205. function createSerializer(format) {
  11206. format = (format || 'xlf').toLowerCase();
  11207. switch (format) {
  11208. case 'xmb':
  11209. return new Xmb();
  11210. case 'xtb':
  11211. return new Xtb();
  11212. case 'xliff2':
  11213. case 'xlf2':
  11214. return new Xliff2();
  11215. case 'xliff':
  11216. case 'xlf':
  11217. default:
  11218. return new Xliff();
  11219. }
  11220. }
  11221. /**
  11222. * @fileoverview added by tsickle
  11223. * @suppress {checkTypes} checked by tsc
  11224. */
  11225. /**
  11226. * @license
  11227. * Copyright Google Inc. All Rights Reserved.
  11228. *
  11229. * Use of this source code is governed by an MIT-style license that can be
  11230. * found in the LICENSE file at https://angular.io/license
  11231. */
  11232. const STRIP_SRC_FILE_SUFFIXES = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
  11233. const GENERATED_FILE = /\.ngfactory\.|\.ngsummary\./;
  11234. const JIT_SUMMARY_FILE = /\.ngsummary\./;
  11235. const JIT_SUMMARY_NAME = /NgSummary$/;
  11236. /**
  11237. * @param {?} filePath
  11238. * @param {?=} forceSourceFile
  11239. * @return {?}
  11240. */
  11241. function ngfactoryFilePath(filePath, forceSourceFile = false) {
  11242. const /** @type {?} */ urlWithSuffix = splitTypescriptSuffix(filePath, forceSourceFile);
  11243. return `${urlWithSuffix[0]}.ngfactory${normalizeGenFileSuffix(urlWithSuffix[1])}`;
  11244. }
  11245. /**
  11246. * @param {?} filePath
  11247. * @return {?}
  11248. */
  11249. function stripGeneratedFileSuffix(filePath) {
  11250. return filePath.replace(GENERATED_FILE, '.');
  11251. }
  11252. /**
  11253. * @param {?} filePath
  11254. * @return {?}
  11255. */
  11256. function isGeneratedFile(filePath) {
  11257. return GENERATED_FILE.test(filePath);
  11258. }
  11259. /**
  11260. * @param {?} path
  11261. * @param {?=} forceSourceFile
  11262. * @return {?}
  11263. */
  11264. function splitTypescriptSuffix(path, forceSourceFile = false) {
  11265. if (path.endsWith('.d.ts')) {
  11266. return [path.slice(0, -5), forceSourceFile ? '.ts' : '.d.ts'];
  11267. }
  11268. const /** @type {?} */ lastDot = path.lastIndexOf('.');
  11269. if (lastDot !== -1) {
  11270. return [path.substring(0, lastDot), path.substring(lastDot)];
  11271. }
  11272. return [path, ''];
  11273. }
  11274. /**
  11275. * @param {?} srcFileSuffix
  11276. * @return {?}
  11277. */
  11278. function normalizeGenFileSuffix(srcFileSuffix) {
  11279. return srcFileSuffix === '.tsx' ? '.ts' : srcFileSuffix;
  11280. }
  11281. /**
  11282. * @param {?} fileName
  11283. * @return {?}
  11284. */
  11285. function summaryFileName(fileName) {
  11286. const /** @type {?} */ fileNameWithoutSuffix = fileName.replace(STRIP_SRC_FILE_SUFFIXES, '');
  11287. return `${fileNameWithoutSuffix}.ngsummary.json`;
  11288. }
  11289. /**
  11290. * @param {?} fileName
  11291. * @param {?=} forceSourceFile
  11292. * @return {?}
  11293. */
  11294. function summaryForJitFileName(fileName, forceSourceFile = false) {
  11295. const /** @type {?} */ urlWithSuffix = splitTypescriptSuffix(stripGeneratedFileSuffix(fileName), forceSourceFile);
  11296. return `${urlWithSuffix[0]}.ngsummary${urlWithSuffix[1]}`;
  11297. }
  11298. /**
  11299. * @param {?} filePath
  11300. * @return {?}
  11301. */
  11302. function stripSummaryForJitFileSuffix(filePath) {
  11303. return filePath.replace(JIT_SUMMARY_FILE, '.');
  11304. }
  11305. /**
  11306. * @param {?} symbolName
  11307. * @return {?}
  11308. */
  11309. function summaryForJitName(symbolName) {
  11310. return `${symbolName}NgSummary`;
  11311. }
  11312. /**
  11313. * @param {?} symbolName
  11314. * @return {?}
  11315. */
  11316. function stripSummaryForJitNameSuffix(symbolName) {
  11317. return symbolName.replace(JIT_SUMMARY_NAME, '');
  11318. }
  11319. const LOWERED_SYMBOL = /\u0275\d+/;
  11320. /**
  11321. * @param {?} name
  11322. * @return {?}
  11323. */
  11324. function isLoweredSymbol(name) {
  11325. return LOWERED_SYMBOL.test(name);
  11326. }
  11327. /**
  11328. * @param {?} id
  11329. * @return {?}
  11330. */
  11331. function createLoweredSymbol(id) {
  11332. return `\u0275${id}`;
  11333. }
  11334. /**
  11335. * @fileoverview added by tsickle
  11336. * @suppress {checkTypes} checked by tsc
  11337. */
  11338. /**
  11339. * @license
  11340. * Copyright Google Inc. All Rights Reserved.
  11341. *
  11342. * Use of this source code is governed by an MIT-style license that can be
  11343. * found in the LICENSE file at https://angular.io/license
  11344. */
  11345. const CORE = '@angular/core';
  11346. class Identifiers {
  11347. }
  11348. Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS = {
  11349. name: 'ANALYZE_FOR_ENTRY_COMPONENTS',
  11350. moduleName: CORE,
  11351. };
  11352. Identifiers.ElementRef = { name: 'ElementRef', moduleName: CORE };
  11353. Identifiers.NgModuleRef = { name: 'NgModuleRef', moduleName: CORE };
  11354. Identifiers.ViewContainerRef = { name: 'ViewContainerRef', moduleName: CORE };
  11355. Identifiers.ChangeDetectorRef = {
  11356. name: 'ChangeDetectorRef',
  11357. moduleName: CORE,
  11358. };
  11359. Identifiers.QueryList = { name: 'QueryList', moduleName: CORE };
  11360. Identifiers.TemplateRef = { name: 'TemplateRef', moduleName: CORE };
  11361. Identifiers.CodegenComponentFactoryResolver = {
  11362. name: 'ɵCodegenComponentFactoryResolver',
  11363. moduleName: CORE,
  11364. };
  11365. Identifiers.ComponentFactoryResolver = {
  11366. name: 'ComponentFactoryResolver',
  11367. moduleName: CORE,
  11368. };
  11369. Identifiers.ComponentFactory = { name: 'ComponentFactory', moduleName: CORE };
  11370. Identifiers.ComponentRef = { name: 'ComponentRef', moduleName: CORE };
  11371. Identifiers.NgModuleFactory = { name: 'NgModuleFactory', moduleName: CORE };
  11372. Identifiers.createModuleFactory = {
  11373. name: 'ɵcmf',
  11374. moduleName: CORE,
  11375. };
  11376. Identifiers.moduleDef = {
  11377. name: 'ɵmod',
  11378. moduleName: CORE,
  11379. };
  11380. Identifiers.moduleProviderDef = {
  11381. name: 'ɵmpd',
  11382. moduleName: CORE,
  11383. };
  11384. Identifiers.RegisterModuleFactoryFn = {
  11385. name: 'ɵregisterModuleFactory',
  11386. moduleName: CORE,
  11387. };
  11388. Identifiers.Injector = { name: 'Injector', moduleName: CORE };
  11389. Identifiers.ViewEncapsulation = {
  11390. name: 'ViewEncapsulation',
  11391. moduleName: CORE,
  11392. };
  11393. Identifiers.ChangeDetectionStrategy = {
  11394. name: 'ChangeDetectionStrategy',
  11395. moduleName: CORE,
  11396. };
  11397. Identifiers.SecurityContext = {
  11398. name: 'SecurityContext',
  11399. moduleName: CORE,
  11400. };
  11401. Identifiers.LOCALE_ID = { name: 'LOCALE_ID', moduleName: CORE };
  11402. Identifiers.TRANSLATIONS_FORMAT = {
  11403. name: 'TRANSLATIONS_FORMAT',
  11404. moduleName: CORE,
  11405. };
  11406. Identifiers.inlineInterpolate = {
  11407. name: 'ɵinlineInterpolate',
  11408. moduleName: CORE,
  11409. };
  11410. Identifiers.interpolate = { name: 'ɵinterpolate', moduleName: CORE };
  11411. Identifiers.EMPTY_ARRAY = { name: 'ɵEMPTY_ARRAY', moduleName: CORE };
  11412. Identifiers.EMPTY_MAP = { name: 'ɵEMPTY_MAP', moduleName: CORE };
  11413. Identifiers.Renderer = { name: 'Renderer', moduleName: CORE };
  11414. Identifiers.viewDef = { name: 'ɵvid', moduleName: CORE };
  11415. Identifiers.elementDef = { name: 'ɵeld', moduleName: CORE };
  11416. Identifiers.anchorDef = { name: 'ɵand', moduleName: CORE };
  11417. Identifiers.textDef = { name: 'ɵted', moduleName: CORE };
  11418. Identifiers.directiveDef = { name: 'ɵdid', moduleName: CORE };
  11419. Identifiers.providerDef = { name: 'ɵprd', moduleName: CORE };
  11420. Identifiers.queryDef = { name: 'ɵqud', moduleName: CORE };
  11421. Identifiers.pureArrayDef = { name: 'ɵpad', moduleName: CORE };
  11422. Identifiers.pureObjectDef = { name: 'ɵpod', moduleName: CORE };
  11423. Identifiers.purePipeDef = { name: 'ɵppd', moduleName: CORE };
  11424. Identifiers.pipeDef = { name: 'ɵpid', moduleName: CORE };
  11425. Identifiers.nodeValue = { name: 'ɵnov', moduleName: CORE };
  11426. Identifiers.ngContentDef = { name: 'ɵncd', moduleName: CORE };
  11427. Identifiers.unwrapValue = { name: 'ɵunv', moduleName: CORE };
  11428. Identifiers.createRendererType2 = { name: 'ɵcrt', moduleName: CORE };
  11429. // type only
  11430. Identifiers.RendererType2 = {
  11431. name: 'RendererType2',
  11432. moduleName: CORE,
  11433. };
  11434. // type only
  11435. Identifiers.ViewDefinition = {
  11436. name: 'ɵViewDefinition',
  11437. moduleName: CORE,
  11438. };
  11439. Identifiers.createComponentFactory = { name: 'ɵccf', moduleName: CORE };
  11440. /**
  11441. * @param {?} reference
  11442. * @return {?}
  11443. */
  11444. function createTokenForReference(reference) {
  11445. return { identifier: { reference: reference } };
  11446. }
  11447. /**
  11448. * @param {?} reflector
  11449. * @param {?} reference
  11450. * @return {?}
  11451. */
  11452. function createTokenForExternalReference(reflector, reference) {
  11453. return createTokenForReference(reflector.resolveExternalReference(reference));
  11454. }
  11455. /**
  11456. * @fileoverview added by tsickle
  11457. * @suppress {checkTypes} checked by tsc
  11458. */
  11459. /**
  11460. * @license
  11461. * Copyright Google Inc. All Rights Reserved.
  11462. *
  11463. * Use of this source code is governed by an MIT-style license that can be
  11464. * found in the LICENSE file at https://angular.io/license
  11465. */
  11466. /** @enum {number} */
  11467. const LifecycleHooks = {
  11468. OnInit: 0,
  11469. OnDestroy: 1,
  11470. DoCheck: 2,
  11471. OnChanges: 3,
  11472. AfterContentInit: 4,
  11473. AfterContentChecked: 5,
  11474. AfterViewInit: 6,
  11475. AfterViewChecked: 7,
  11476. };
  11477. LifecycleHooks[LifecycleHooks.OnInit] = "OnInit";
  11478. LifecycleHooks[LifecycleHooks.OnDestroy] = "OnDestroy";
  11479. LifecycleHooks[LifecycleHooks.DoCheck] = "DoCheck";
  11480. LifecycleHooks[LifecycleHooks.OnChanges] = "OnChanges";
  11481. LifecycleHooks[LifecycleHooks.AfterContentInit] = "AfterContentInit";
  11482. LifecycleHooks[LifecycleHooks.AfterContentChecked] = "AfterContentChecked";
  11483. LifecycleHooks[LifecycleHooks.AfterViewInit] = "AfterViewInit";
  11484. LifecycleHooks[LifecycleHooks.AfterViewChecked] = "AfterViewChecked";
  11485. const LIFECYCLE_HOOKS_VALUES = [
  11486. LifecycleHooks.OnInit, LifecycleHooks.OnDestroy, LifecycleHooks.DoCheck, LifecycleHooks.OnChanges,
  11487. LifecycleHooks.AfterContentInit, LifecycleHooks.AfterContentChecked, LifecycleHooks.AfterViewInit,
  11488. LifecycleHooks.AfterViewChecked
  11489. ];
  11490. /**
  11491. * @param {?} reflector
  11492. * @param {?} hook
  11493. * @param {?} token
  11494. * @return {?}
  11495. */
  11496. function hasLifecycleHook(reflector, hook, token) {
  11497. return reflector.hasLifecycleHook(token, getHookName(hook));
  11498. }
  11499. /**
  11500. * @param {?} reflector
  11501. * @param {?} token
  11502. * @return {?}
  11503. */
  11504. function getAllLifecycleHooks(reflector, token) {
  11505. return LIFECYCLE_HOOKS_VALUES.filter(hook => hasLifecycleHook(reflector, hook, token));
  11506. }
  11507. /**
  11508. * @param {?} hook
  11509. * @return {?}
  11510. */
  11511. function getHookName(hook) {
  11512. switch (hook) {
  11513. case LifecycleHooks.OnInit:
  11514. return 'ngOnInit';
  11515. case LifecycleHooks.OnDestroy:
  11516. return 'ngOnDestroy';
  11517. case LifecycleHooks.DoCheck:
  11518. return 'ngDoCheck';
  11519. case LifecycleHooks.OnChanges:
  11520. return 'ngOnChanges';
  11521. case LifecycleHooks.AfterContentInit:
  11522. return 'ngAfterContentInit';
  11523. case LifecycleHooks.AfterContentChecked:
  11524. return 'ngAfterContentChecked';
  11525. case LifecycleHooks.AfterViewInit:
  11526. return 'ngAfterViewInit';
  11527. case LifecycleHooks.AfterViewChecked:
  11528. return 'ngAfterViewChecked';
  11529. }
  11530. }
  11531. /**
  11532. * @fileoverview added by tsickle
  11533. * @suppress {checkTypes} checked by tsc
  11534. */
  11535. /**
  11536. * @license
  11537. * Copyright Google Inc. All Rights Reserved.
  11538. *
  11539. * Use of this source code is governed by an MIT-style license that can be
  11540. * found in the LICENSE file at https://angular.io/license
  11541. */
  11542. const _SELECTOR_REGEXP = new RegExp('(\\:not\\()|' + //":not("
  11543. '([-\\w]+)|' + // "tag"
  11544. '(?:\\.([-\\w]+))|' + // ".class"
  11545. '(?:\\[([-.\\w*]+)(?:=([\"\']?)([^\\]\"\']*)\\5)?\\])|' + // "[name]", "[name=value]",
  11546. '(\\))|' + // ")"
  11547. '(\\s*,\\s*)', // ","
  11548. 'g');
  11549. /**
  11550. * A css selector contains an element name,
  11551. * css classes and attribute/value pairs with the purpose
  11552. * of selecting subsets out of them.
  11553. */
  11554. class CssSelector {
  11555. constructor() {
  11556. this.element = null;
  11557. this.classNames = [];
  11558. this.attrs = [];
  11559. this.notSelectors = [];
  11560. }
  11561. /**
  11562. * @param {?} selector
  11563. * @return {?}
  11564. */
  11565. static parse(selector) {
  11566. const /** @type {?} */ results = [];
  11567. const /** @type {?} */ _addResult = (res, cssSel) => {
  11568. if (cssSel.notSelectors.length > 0 && !cssSel.element && cssSel.classNames.length == 0 &&
  11569. cssSel.attrs.length == 0) {
  11570. cssSel.element = '*';
  11571. }
  11572. res.push(cssSel);
  11573. };
  11574. let /** @type {?} */ cssSelector = new CssSelector();
  11575. let /** @type {?} */ match;
  11576. let /** @type {?} */ current = cssSelector;
  11577. let /** @type {?} */ inNot = false;
  11578. _SELECTOR_REGEXP.lastIndex = 0;
  11579. while (match = _SELECTOR_REGEXP.exec(selector)) {
  11580. if (match[1]) {
  11581. if (inNot) {
  11582. throw new Error('Nesting :not is not allowed in a selector');
  11583. }
  11584. inNot = true;
  11585. current = new CssSelector();
  11586. cssSelector.notSelectors.push(current);
  11587. }
  11588. if (match[2]) {
  11589. current.setElement(match[2]);
  11590. }
  11591. if (match[3]) {
  11592. current.addClassName(match[3]);
  11593. }
  11594. if (match[4]) {
  11595. current.addAttribute(match[4], match[6]);
  11596. }
  11597. if (match[7]) {
  11598. inNot = false;
  11599. current = cssSelector;
  11600. }
  11601. if (match[8]) {
  11602. if (inNot) {
  11603. throw new Error('Multiple selectors in :not are not supported');
  11604. }
  11605. _addResult(results, cssSelector);
  11606. cssSelector = current = new CssSelector();
  11607. }
  11608. }
  11609. _addResult(results, cssSelector);
  11610. return results;
  11611. }
  11612. /**
  11613. * @return {?}
  11614. */
  11615. isElementSelector() {
  11616. return this.hasElementSelector() && this.classNames.length == 0 && this.attrs.length == 0 &&
  11617. this.notSelectors.length === 0;
  11618. }
  11619. /**
  11620. * @return {?}
  11621. */
  11622. hasElementSelector() { return !!this.element; }
  11623. /**
  11624. * @param {?=} element
  11625. * @return {?}
  11626. */
  11627. setElement(element = null) { this.element = element; }
  11628. /**
  11629. * Gets a template string for an element that matches the selector.
  11630. * @return {?}
  11631. */
  11632. getMatchingElementTemplate() {
  11633. const /** @type {?} */ tagName = this.element || 'div';
  11634. const /** @type {?} */ classAttr = this.classNames.length > 0 ? ` class="${this.classNames.join(' ')}"` : '';
  11635. let /** @type {?} */ attrs = '';
  11636. for (let /** @type {?} */ i = 0; i < this.attrs.length; i += 2) {
  11637. const /** @type {?} */ attrName = this.attrs[i];
  11638. const /** @type {?} */ attrValue = this.attrs[i + 1] !== '' ? `="${this.attrs[i + 1]}"` : '';
  11639. attrs += ` ${attrName}${attrValue}`;
  11640. }
  11641. return getHtmlTagDefinition(tagName).isVoid ? `<${tagName}${classAttr}${attrs}/>` :
  11642. `<${tagName}${classAttr}${attrs}></${tagName}>`;
  11643. }
  11644. /**
  11645. * @param {?} name
  11646. * @param {?=} value
  11647. * @return {?}
  11648. */
  11649. addAttribute(name, value = '') {
  11650. this.attrs.push(name, value && value.toLowerCase() || '');
  11651. }
  11652. /**
  11653. * @param {?} name
  11654. * @return {?}
  11655. */
  11656. addClassName(name) { this.classNames.push(name.toLowerCase()); }
  11657. /**
  11658. * @return {?}
  11659. */
  11660. toString() {
  11661. let /** @type {?} */ res = this.element || '';
  11662. if (this.classNames) {
  11663. this.classNames.forEach(klass => res += `.${klass}`);
  11664. }
  11665. if (this.attrs) {
  11666. for (let /** @type {?} */ i = 0; i < this.attrs.length; i += 2) {
  11667. const /** @type {?} */ name = this.attrs[i];
  11668. const /** @type {?} */ value = this.attrs[i + 1];
  11669. res += `[${name}${value ? '=' + value : ''}]`;
  11670. }
  11671. }
  11672. this.notSelectors.forEach(notSelector => res += `:not(${notSelector})`);
  11673. return res;
  11674. }
  11675. }
  11676. /**
  11677. * Reads a list of CssSelectors and allows to calculate which ones
  11678. * are contained in a given CssSelector.
  11679. */
  11680. class SelectorMatcher {
  11681. constructor() {
  11682. this._elementMap = new Map();
  11683. this._elementPartialMap = new Map();
  11684. this._classMap = new Map();
  11685. this._classPartialMap = new Map();
  11686. this._attrValueMap = new Map();
  11687. this._attrValuePartialMap = new Map();
  11688. this._listContexts = [];
  11689. }
  11690. /**
  11691. * @param {?} notSelectors
  11692. * @return {?}
  11693. */
  11694. static createNotMatcher(notSelectors) {
  11695. const /** @type {?} */ notMatcher = new SelectorMatcher();
  11696. notMatcher.addSelectables(notSelectors, null);
  11697. return notMatcher;
  11698. }
  11699. /**
  11700. * @param {?} cssSelectors
  11701. * @param {?=} callbackCtxt
  11702. * @return {?}
  11703. */
  11704. addSelectables(cssSelectors, callbackCtxt) {
  11705. let /** @type {?} */ listContext = /** @type {?} */ ((null));
  11706. if (cssSelectors.length > 1) {
  11707. listContext = new SelectorListContext(cssSelectors);
  11708. this._listContexts.push(listContext);
  11709. }
  11710. for (let /** @type {?} */ i = 0; i < cssSelectors.length; i++) {
  11711. this._addSelectable(cssSelectors[i], callbackCtxt, listContext);
  11712. }
  11713. }
  11714. /**
  11715. * Add an object that can be found later on by calling `match`.
  11716. * @param {?} cssSelector A css selector
  11717. * @param {?} callbackCtxt An opaque object that will be given to the callback of the `match` function
  11718. * @param {?} listContext
  11719. * @return {?}
  11720. */
  11721. _addSelectable(cssSelector, callbackCtxt, listContext) {
  11722. let /** @type {?} */ matcher = this;
  11723. const /** @type {?} */ element = cssSelector.element;
  11724. const /** @type {?} */ classNames = cssSelector.classNames;
  11725. const /** @type {?} */ attrs = cssSelector.attrs;
  11726. const /** @type {?} */ selectable = new SelectorContext(cssSelector, callbackCtxt, listContext);
  11727. if (element) {
  11728. const /** @type {?} */ isTerminal = attrs.length === 0 && classNames.length === 0;
  11729. if (isTerminal) {
  11730. this._addTerminal(matcher._elementMap, element, selectable);
  11731. }
  11732. else {
  11733. matcher = this._addPartial(matcher._elementPartialMap, element);
  11734. }
  11735. }
  11736. if (classNames) {
  11737. for (let /** @type {?} */ i = 0; i < classNames.length; i++) {
  11738. const /** @type {?} */ isTerminal = attrs.length === 0 && i === classNames.length - 1;
  11739. const /** @type {?} */ className = classNames[i];
  11740. if (isTerminal) {
  11741. this._addTerminal(matcher._classMap, className, selectable);
  11742. }
  11743. else {
  11744. matcher = this._addPartial(matcher._classPartialMap, className);
  11745. }
  11746. }
  11747. }
  11748. if (attrs) {
  11749. for (let /** @type {?} */ i = 0; i < attrs.length; i += 2) {
  11750. const /** @type {?} */ isTerminal = i === attrs.length - 2;
  11751. const /** @type {?} */ name = attrs[i];
  11752. const /** @type {?} */ value = attrs[i + 1];
  11753. if (isTerminal) {
  11754. const /** @type {?} */ terminalMap = matcher._attrValueMap;
  11755. let /** @type {?} */ terminalValuesMap = terminalMap.get(name);
  11756. if (!terminalValuesMap) {
  11757. terminalValuesMap = new Map();
  11758. terminalMap.set(name, terminalValuesMap);
  11759. }
  11760. this._addTerminal(terminalValuesMap, value, selectable);
  11761. }
  11762. else {
  11763. const /** @type {?} */ partialMap = matcher._attrValuePartialMap;
  11764. let /** @type {?} */ partialValuesMap = partialMap.get(name);
  11765. if (!partialValuesMap) {
  11766. partialValuesMap = new Map();
  11767. partialMap.set(name, partialValuesMap);
  11768. }
  11769. matcher = this._addPartial(partialValuesMap, value);
  11770. }
  11771. }
  11772. }
  11773. }
  11774. /**
  11775. * @param {?} map
  11776. * @param {?} name
  11777. * @param {?} selectable
  11778. * @return {?}
  11779. */
  11780. _addTerminal(map, name, selectable) {
  11781. let /** @type {?} */ terminalList = map.get(name);
  11782. if (!terminalList) {
  11783. terminalList = [];
  11784. map.set(name, terminalList);
  11785. }
  11786. terminalList.push(selectable);
  11787. }
  11788. /**
  11789. * @param {?} map
  11790. * @param {?} name
  11791. * @return {?}
  11792. */
  11793. _addPartial(map, name) {
  11794. let /** @type {?} */ matcher = map.get(name);
  11795. if (!matcher) {
  11796. matcher = new SelectorMatcher();
  11797. map.set(name, matcher);
  11798. }
  11799. return matcher;
  11800. }
  11801. /**
  11802. * Find the objects that have been added via `addSelectable`
  11803. * whose css selector is contained in the given css selector.
  11804. * @param {?} cssSelector A css selector
  11805. * @param {?} matchedCallback This callback will be called with the object handed into `addSelectable`
  11806. * @return {?} boolean true if a match was found
  11807. */
  11808. match(cssSelector, matchedCallback) {
  11809. let /** @type {?} */ result = false;
  11810. const /** @type {?} */ element = /** @type {?} */ ((cssSelector.element));
  11811. const /** @type {?} */ classNames = cssSelector.classNames;
  11812. const /** @type {?} */ attrs = cssSelector.attrs;
  11813. for (let /** @type {?} */ i = 0; i < this._listContexts.length; i++) {
  11814. this._listContexts[i].alreadyMatched = false;
  11815. }
  11816. result = this._matchTerminal(this._elementMap, element, cssSelector, matchedCallback) || result;
  11817. result = this._matchPartial(this._elementPartialMap, element, cssSelector, matchedCallback) ||
  11818. result;
  11819. if (classNames) {
  11820. for (let /** @type {?} */ i = 0; i < classNames.length; i++) {
  11821. const /** @type {?} */ className = classNames[i];
  11822. result =
  11823. this._matchTerminal(this._classMap, className, cssSelector, matchedCallback) || result;
  11824. result =
  11825. this._matchPartial(this._classPartialMap, className, cssSelector, matchedCallback) ||
  11826. result;
  11827. }
  11828. }
  11829. if (attrs) {
  11830. for (let /** @type {?} */ i = 0; i < attrs.length; i += 2) {
  11831. const /** @type {?} */ name = attrs[i];
  11832. const /** @type {?} */ value = attrs[i + 1];
  11833. const /** @type {?} */ terminalValuesMap = /** @type {?} */ ((this._attrValueMap.get(name)));
  11834. if (value) {
  11835. result =
  11836. this._matchTerminal(terminalValuesMap, '', cssSelector, matchedCallback) || result;
  11837. }
  11838. result =
  11839. this._matchTerminal(terminalValuesMap, value, cssSelector, matchedCallback) || result;
  11840. const /** @type {?} */ partialValuesMap = /** @type {?} */ ((this._attrValuePartialMap.get(name)));
  11841. if (value) {
  11842. result = this._matchPartial(partialValuesMap, '', cssSelector, matchedCallback) || result;
  11843. }
  11844. result =
  11845. this._matchPartial(partialValuesMap, value, cssSelector, matchedCallback) || result;
  11846. }
  11847. }
  11848. return result;
  11849. }
  11850. /**
  11851. * \@internal
  11852. * @param {?} map
  11853. * @param {?} name
  11854. * @param {?} cssSelector
  11855. * @param {?} matchedCallback
  11856. * @return {?}
  11857. */
  11858. _matchTerminal(map, name, cssSelector, matchedCallback) {
  11859. if (!map || typeof name !== 'string') {
  11860. return false;
  11861. }
  11862. let /** @type {?} */ selectables = map.get(name) || [];
  11863. const /** @type {?} */ starSelectables = /** @type {?} */ ((map.get('*')));
  11864. if (starSelectables) {
  11865. selectables = selectables.concat(starSelectables);
  11866. }
  11867. if (selectables.length === 0) {
  11868. return false;
  11869. }
  11870. let /** @type {?} */ selectable;
  11871. let /** @type {?} */ result = false;
  11872. for (let /** @type {?} */ i = 0; i < selectables.length; i++) {
  11873. selectable = selectables[i];
  11874. result = selectable.finalize(cssSelector, matchedCallback) || result;
  11875. }
  11876. return result;
  11877. }
  11878. /**
  11879. * \@internal
  11880. * @param {?} map
  11881. * @param {?} name
  11882. * @param {?} cssSelector
  11883. * @param {?} matchedCallback
  11884. * @return {?}
  11885. */
  11886. _matchPartial(map, name, cssSelector, matchedCallback) {
  11887. if (!map || typeof name !== 'string') {
  11888. return false;
  11889. }
  11890. const /** @type {?} */ nestedSelector = map.get(name);
  11891. if (!nestedSelector) {
  11892. return false;
  11893. }
  11894. // TODO(perf): get rid of recursion and measure again
  11895. // TODO(perf): don't pass the whole selector into the recursion,
  11896. // but only the not processed parts
  11897. return nestedSelector.match(cssSelector, matchedCallback);
  11898. }
  11899. }
  11900. class SelectorListContext {
  11901. /**
  11902. * @param {?} selectors
  11903. */
  11904. constructor(selectors) {
  11905. this.selectors = selectors;
  11906. this.alreadyMatched = false;
  11907. }
  11908. }
  11909. class SelectorContext {
  11910. /**
  11911. * @param {?} selector
  11912. * @param {?} cbContext
  11913. * @param {?} listContext
  11914. */
  11915. constructor(selector, cbContext, listContext) {
  11916. this.selector = selector;
  11917. this.cbContext = cbContext;
  11918. this.listContext = listContext;
  11919. this.notSelectors = selector.notSelectors;
  11920. }
  11921. /**
  11922. * @param {?} cssSelector
  11923. * @param {?} callback
  11924. * @return {?}
  11925. */
  11926. finalize(cssSelector, callback) {
  11927. let /** @type {?} */ result = true;
  11928. if (this.notSelectors.length > 0 && (!this.listContext || !this.listContext.alreadyMatched)) {
  11929. const /** @type {?} */ notMatcher = SelectorMatcher.createNotMatcher(this.notSelectors);
  11930. result = !notMatcher.match(cssSelector, null);
  11931. }
  11932. if (result && callback && (!this.listContext || !this.listContext.alreadyMatched)) {
  11933. if (this.listContext) {
  11934. this.listContext.alreadyMatched = true;
  11935. }
  11936. callback(this.selector, this.cbContext);
  11937. }
  11938. return result;
  11939. }
  11940. }
  11941. /**
  11942. * @fileoverview added by tsickle
  11943. * @suppress {checkTypes} checked by tsc
  11944. */
  11945. /**
  11946. * @license
  11947. * Copyright Google Inc. All Rights Reserved.
  11948. *
  11949. * Use of this source code is governed by an MIT-style license that can be
  11950. * found in the LICENSE file at https://angular.io/license
  11951. */
  11952. const ERROR_COMPONENT_TYPE = 'ngComponentType';
  11953. class CompileMetadataResolver {
  11954. /**
  11955. * @param {?} _config
  11956. * @param {?} _htmlParser
  11957. * @param {?} _ngModuleResolver
  11958. * @param {?} _directiveResolver
  11959. * @param {?} _pipeResolver
  11960. * @param {?} _summaryResolver
  11961. * @param {?} _schemaRegistry
  11962. * @param {?} _directiveNormalizer
  11963. * @param {?} _console
  11964. * @param {?} _staticSymbolCache
  11965. * @param {?} _reflector
  11966. * @param {?=} _errorCollector
  11967. */
  11968. constructor(_config, _htmlParser, _ngModuleResolver, _directiveResolver, _pipeResolver, _summaryResolver, _schemaRegistry, _directiveNormalizer, _console, _staticSymbolCache, _reflector, _errorCollector) {
  11969. this._config = _config;
  11970. this._htmlParser = _htmlParser;
  11971. this._ngModuleResolver = _ngModuleResolver;
  11972. this._directiveResolver = _directiveResolver;
  11973. this._pipeResolver = _pipeResolver;
  11974. this._summaryResolver = _summaryResolver;
  11975. this._schemaRegistry = _schemaRegistry;
  11976. this._directiveNormalizer = _directiveNormalizer;
  11977. this._console = _console;
  11978. this._staticSymbolCache = _staticSymbolCache;
  11979. this._reflector = _reflector;
  11980. this._errorCollector = _errorCollector;
  11981. this._nonNormalizedDirectiveCache = new Map();
  11982. this._directiveCache = new Map();
  11983. this._summaryCache = new Map();
  11984. this._pipeCache = new Map();
  11985. this._ngModuleCache = new Map();
  11986. this._ngModuleOfTypes = new Map();
  11987. }
  11988. /**
  11989. * @return {?}
  11990. */
  11991. getReflector() { return this._reflector; }
  11992. /**
  11993. * @param {?} type
  11994. * @return {?}
  11995. */
  11996. clearCacheFor(type) {
  11997. const /** @type {?} */ dirMeta = this._directiveCache.get(type);
  11998. this._directiveCache.delete(type);
  11999. this._nonNormalizedDirectiveCache.delete(type);
  12000. this._summaryCache.delete(type);
  12001. this._pipeCache.delete(type);
  12002. this._ngModuleOfTypes.delete(type);
  12003. // Clear all of the NgModule as they contain transitive information!
  12004. this._ngModuleCache.clear();
  12005. if (dirMeta) {
  12006. this._directiveNormalizer.clearCacheFor(dirMeta);
  12007. }
  12008. }
  12009. /**
  12010. * @return {?}
  12011. */
  12012. clearCache() {
  12013. this._directiveCache.clear();
  12014. this._nonNormalizedDirectiveCache.clear();
  12015. this._summaryCache.clear();
  12016. this._pipeCache.clear();
  12017. this._ngModuleCache.clear();
  12018. this._ngModuleOfTypes.clear();
  12019. this._directiveNormalizer.clearCache();
  12020. }
  12021. /**
  12022. * @param {?} baseType
  12023. * @param {?} name
  12024. * @return {?}
  12025. */
  12026. _createProxyClass(baseType, name) {
  12027. let /** @type {?} */ delegate = null;
  12028. const /** @type {?} */ proxyClass = /** @type {?} */ (function () {
  12029. if (!delegate) {
  12030. throw new Error(`Illegal state: Class ${name} for type ${stringify(baseType)} is not compiled yet!`);
  12031. }
  12032. return delegate.apply(this, arguments);
  12033. });
  12034. proxyClass.setDelegate = (d) => {
  12035. delegate = d;
  12036. (/** @type {?} */ (proxyClass)).prototype = d.prototype;
  12037. };
  12038. // Make stringify work correctly
  12039. (/** @type {?} */ (proxyClass)).overriddenName = name;
  12040. return proxyClass;
  12041. }
  12042. /**
  12043. * @param {?} dirType
  12044. * @param {?} name
  12045. * @return {?}
  12046. */
  12047. getGeneratedClass(dirType, name) {
  12048. if (dirType instanceof StaticSymbol) {
  12049. return this._staticSymbolCache.get(ngfactoryFilePath(dirType.filePath), name);
  12050. }
  12051. else {
  12052. return this._createProxyClass(dirType, name);
  12053. }
  12054. }
  12055. /**
  12056. * @param {?} dirType
  12057. * @return {?}
  12058. */
  12059. getComponentViewClass(dirType) {
  12060. return this.getGeneratedClass(dirType, viewClassName(dirType, 0));
  12061. }
  12062. /**
  12063. * @param {?} dirType
  12064. * @return {?}
  12065. */
  12066. getHostComponentViewClass(dirType) {
  12067. return this.getGeneratedClass(dirType, hostViewClassName(dirType));
  12068. }
  12069. /**
  12070. * @param {?} dirType
  12071. * @return {?}
  12072. */
  12073. getHostComponentType(dirType) {
  12074. const /** @type {?} */ name = `${identifierName({ reference: dirType })}_Host`;
  12075. if (dirType instanceof StaticSymbol) {
  12076. return this._staticSymbolCache.get(dirType.filePath, name);
  12077. }
  12078. else {
  12079. const /** @type {?} */ HostClass = /** @type {?} */ (function HostClass() { });
  12080. HostClass.overriddenName = name;
  12081. return HostClass;
  12082. }
  12083. }
  12084. /**
  12085. * @param {?} dirType
  12086. * @return {?}
  12087. */
  12088. getRendererType(dirType) {
  12089. if (dirType instanceof StaticSymbol) {
  12090. return this._staticSymbolCache.get(ngfactoryFilePath(dirType.filePath), rendererTypeName(dirType));
  12091. }
  12092. else {
  12093. // returning an object as proxy,
  12094. // that we fill later during runtime compilation.
  12095. return /** @type {?} */ ({});
  12096. }
  12097. }
  12098. /**
  12099. * @param {?} selector
  12100. * @param {?} dirType
  12101. * @param {?} inputs
  12102. * @param {?} outputs
  12103. * @return {?}
  12104. */
  12105. getComponentFactory(selector, dirType, inputs, outputs) {
  12106. if (dirType instanceof StaticSymbol) {
  12107. return this._staticSymbolCache.get(ngfactoryFilePath(dirType.filePath), componentFactoryName(dirType));
  12108. }
  12109. else {
  12110. const /** @type {?} */ hostView = this.getHostComponentViewClass(dirType);
  12111. // Note: ngContentSelectors will be filled later once the template is
  12112. // loaded.
  12113. const /** @type {?} */ createComponentFactory = this._reflector.resolveExternalReference(Identifiers.createComponentFactory);
  12114. return createComponentFactory(selector, dirType, /** @type {?} */ (hostView), inputs, outputs, []);
  12115. }
  12116. }
  12117. /**
  12118. * @param {?} factory
  12119. * @param {?} ngContentSelectors
  12120. * @return {?}
  12121. */
  12122. initComponentFactory(factory, ngContentSelectors) {
  12123. if (!(factory instanceof StaticSymbol)) {
  12124. (/** @type {?} */ (factory)).ngContentSelectors.push(...ngContentSelectors);
  12125. }
  12126. }
  12127. /**
  12128. * @param {?} type
  12129. * @param {?} kind
  12130. * @return {?}
  12131. */
  12132. _loadSummary(type, kind) {
  12133. let /** @type {?} */ typeSummary = this._summaryCache.get(type);
  12134. if (!typeSummary) {
  12135. const /** @type {?} */ summary = this._summaryResolver.resolveSummary(type);
  12136. typeSummary = summary ? summary.type : null;
  12137. this._summaryCache.set(type, typeSummary || null);
  12138. }
  12139. return typeSummary && typeSummary.summaryKind === kind ? typeSummary : null;
  12140. }
  12141. /**
  12142. * @param {?} compMeta
  12143. * @param {?=} hostViewType
  12144. * @return {?}
  12145. */
  12146. getHostComponentMetadata(compMeta, hostViewType) {
  12147. const /** @type {?} */ hostType = this.getHostComponentType(compMeta.type.reference);
  12148. if (!hostViewType) {
  12149. hostViewType = this.getHostComponentViewClass(hostType);
  12150. }
  12151. // Note: ! is ok here as this method should only be called with normalized directive
  12152. // metadata, which always fills in the selector.
  12153. const /** @type {?} */ template = CssSelector.parse(/** @type {?} */ ((compMeta.selector)))[0].getMatchingElementTemplate();
  12154. const /** @type {?} */ templateUrl = '';
  12155. const /** @type {?} */ htmlAst = this._htmlParser.parse(template, templateUrl);
  12156. return CompileDirectiveMetadata.create({
  12157. isHost: true,
  12158. type: { reference: hostType, diDeps: [], lifecycleHooks: [] },
  12159. template: new CompileTemplateMetadata({
  12160. encapsulation: ViewEncapsulation.None,
  12161. template,
  12162. templateUrl,
  12163. htmlAst,
  12164. styles: [],
  12165. styleUrls: [],
  12166. ngContentSelectors: [],
  12167. animations: [],
  12168. isInline: true,
  12169. externalStylesheets: [],
  12170. interpolation: null,
  12171. preserveWhitespaces: false,
  12172. }),
  12173. exportAs: null,
  12174. changeDetection: ChangeDetectionStrategy.Default,
  12175. inputs: [],
  12176. outputs: [],
  12177. host: {},
  12178. isComponent: true,
  12179. selector: '*',
  12180. providers: [],
  12181. viewProviders: [],
  12182. queries: [],
  12183. guards: {},
  12184. viewQueries: [],
  12185. componentViewType: hostViewType,
  12186. rendererType: /** @type {?} */ ({ id: '__Host__', encapsulation: ViewEncapsulation.None, styles: [], data: {} }),
  12187. entryComponents: [],
  12188. componentFactory: null
  12189. });
  12190. }
  12191. /**
  12192. * @param {?} ngModuleType
  12193. * @param {?} directiveType
  12194. * @param {?} isSync
  12195. * @return {?}
  12196. */
  12197. loadDirectiveMetadata(ngModuleType, directiveType, isSync) {
  12198. if (this._directiveCache.has(directiveType)) {
  12199. return null;
  12200. }
  12201. directiveType = resolveForwardRef(directiveType);
  12202. const { annotation, metadata } = /** @type {?} */ ((this.getNonNormalizedDirectiveMetadata(directiveType)));
  12203. const /** @type {?} */ createDirectiveMetadata = (templateMetadata) => {
  12204. const /** @type {?} */ normalizedDirMeta = new CompileDirectiveMetadata({
  12205. isHost: false,
  12206. type: metadata.type,
  12207. isComponent: metadata.isComponent,
  12208. selector: metadata.selector,
  12209. exportAs: metadata.exportAs,
  12210. changeDetection: metadata.changeDetection,
  12211. inputs: metadata.inputs,
  12212. outputs: metadata.outputs,
  12213. hostListeners: metadata.hostListeners,
  12214. hostProperties: metadata.hostProperties,
  12215. hostAttributes: metadata.hostAttributes,
  12216. providers: metadata.providers,
  12217. viewProviders: metadata.viewProviders,
  12218. queries: metadata.queries,
  12219. guards: metadata.guards,
  12220. viewQueries: metadata.viewQueries,
  12221. entryComponents: metadata.entryComponents,
  12222. componentViewType: metadata.componentViewType,
  12223. rendererType: metadata.rendererType,
  12224. componentFactory: metadata.componentFactory,
  12225. template: templateMetadata
  12226. });
  12227. if (templateMetadata) {
  12228. this.initComponentFactory(/** @type {?} */ ((metadata.componentFactory)), templateMetadata.ngContentSelectors);
  12229. }
  12230. this._directiveCache.set(directiveType, normalizedDirMeta);
  12231. this._summaryCache.set(directiveType, normalizedDirMeta.toSummary());
  12232. return null;
  12233. };
  12234. if (metadata.isComponent) {
  12235. const /** @type {?} */ template = /** @type {?} */ ((metadata.template));
  12236. const /** @type {?} */ templateMeta = this._directiveNormalizer.normalizeTemplate({
  12237. ngModuleType,
  12238. componentType: directiveType,
  12239. moduleUrl: this._reflector.componentModuleUrl(directiveType, annotation),
  12240. encapsulation: template.encapsulation,
  12241. template: template.template,
  12242. templateUrl: template.templateUrl,
  12243. styles: template.styles,
  12244. styleUrls: template.styleUrls,
  12245. animations: template.animations,
  12246. interpolation: template.interpolation,
  12247. preserveWhitespaces: template.preserveWhitespaces
  12248. });
  12249. if (isPromise(templateMeta) && isSync) {
  12250. this._reportError(componentStillLoadingError(directiveType), directiveType);
  12251. return null;
  12252. }
  12253. return SyncAsync.then(templateMeta, createDirectiveMetadata);
  12254. }
  12255. else {
  12256. // directive
  12257. createDirectiveMetadata(null);
  12258. return null;
  12259. }
  12260. }
  12261. /**
  12262. * @param {?} directiveType
  12263. * @return {?}
  12264. */
  12265. getNonNormalizedDirectiveMetadata(directiveType) {
  12266. directiveType = resolveForwardRef(directiveType);
  12267. if (!directiveType) {
  12268. return null;
  12269. }
  12270. let /** @type {?} */ cacheEntry = this._nonNormalizedDirectiveCache.get(directiveType);
  12271. if (cacheEntry) {
  12272. return cacheEntry;
  12273. }
  12274. const /** @type {?} */ dirMeta = this._directiveResolver.resolve(directiveType, false);
  12275. if (!dirMeta) {
  12276. return null;
  12277. }
  12278. let /** @type {?} */ nonNormalizedTemplateMetadata = /** @type {?} */ ((undefined));
  12279. if (createComponent.isTypeOf(dirMeta)) {
  12280. // component
  12281. const /** @type {?} */ compMeta = /** @type {?} */ (dirMeta);
  12282. assertArrayOfStrings('styles', compMeta.styles);
  12283. assertArrayOfStrings('styleUrls', compMeta.styleUrls);
  12284. assertInterpolationSymbols('interpolation', compMeta.interpolation);
  12285. const /** @type {?} */ animations = compMeta.animations;
  12286. nonNormalizedTemplateMetadata = new CompileTemplateMetadata({
  12287. encapsulation: noUndefined(compMeta.encapsulation),
  12288. template: noUndefined(compMeta.template),
  12289. templateUrl: noUndefined(compMeta.templateUrl),
  12290. htmlAst: null,
  12291. styles: compMeta.styles || [],
  12292. styleUrls: compMeta.styleUrls || [],
  12293. animations: animations || [],
  12294. interpolation: noUndefined(compMeta.interpolation),
  12295. isInline: !!compMeta.template,
  12296. externalStylesheets: [],
  12297. ngContentSelectors: [],
  12298. preserveWhitespaces: noUndefined(dirMeta.preserveWhitespaces),
  12299. });
  12300. }
  12301. let /** @type {?} */ changeDetectionStrategy = /** @type {?} */ ((null));
  12302. let /** @type {?} */ viewProviders = [];
  12303. let /** @type {?} */ entryComponentMetadata = [];
  12304. let /** @type {?} */ selector = dirMeta.selector;
  12305. if (createComponent.isTypeOf(dirMeta)) {
  12306. // Component
  12307. const /** @type {?} */ compMeta = /** @type {?} */ (dirMeta);
  12308. changeDetectionStrategy = /** @type {?} */ ((compMeta.changeDetection));
  12309. if (compMeta.viewProviders) {
  12310. viewProviders = this._getProvidersMetadata(compMeta.viewProviders, entryComponentMetadata, `viewProviders for "${stringifyType(directiveType)}"`, [], directiveType);
  12311. }
  12312. if (compMeta.entryComponents) {
  12313. entryComponentMetadata = flattenAndDedupeArray(compMeta.entryComponents)
  12314. .map((type) => /** @type {?} */ ((this._getEntryComponentMetadata(type))))
  12315. .concat(entryComponentMetadata);
  12316. }
  12317. if (!selector) {
  12318. selector = this._schemaRegistry.getDefaultComponentElementName();
  12319. }
  12320. }
  12321. else {
  12322. // Directive
  12323. if (!selector) {
  12324. this._reportError(syntaxError(`Directive ${stringifyType(directiveType)} has no selector, please add it!`), directiveType);
  12325. selector = 'error';
  12326. }
  12327. }
  12328. let /** @type {?} */ providers = [];
  12329. if (dirMeta.providers != null) {
  12330. providers = this._getProvidersMetadata(dirMeta.providers, entryComponentMetadata, `providers for "${stringifyType(directiveType)}"`, [], directiveType);
  12331. }
  12332. let /** @type {?} */ queries = [];
  12333. let /** @type {?} */ viewQueries = [];
  12334. if (dirMeta.queries != null) {
  12335. queries = this._getQueriesMetadata(dirMeta.queries, false, directiveType);
  12336. viewQueries = this._getQueriesMetadata(dirMeta.queries, true, directiveType);
  12337. }
  12338. const /** @type {?} */ metadata = CompileDirectiveMetadata.create({
  12339. isHost: false,
  12340. selector: selector,
  12341. exportAs: noUndefined(dirMeta.exportAs),
  12342. isComponent: !!nonNormalizedTemplateMetadata,
  12343. type: this._getTypeMetadata(directiveType),
  12344. template: nonNormalizedTemplateMetadata,
  12345. changeDetection: changeDetectionStrategy,
  12346. inputs: dirMeta.inputs || [],
  12347. outputs: dirMeta.outputs || [],
  12348. host: dirMeta.host || {},
  12349. providers: providers || [],
  12350. viewProviders: viewProviders || [],
  12351. queries: queries || [],
  12352. guards: dirMeta.guards || {},
  12353. viewQueries: viewQueries || [],
  12354. entryComponents: entryComponentMetadata,
  12355. componentViewType: nonNormalizedTemplateMetadata ? this.getComponentViewClass(directiveType) :
  12356. null,
  12357. rendererType: nonNormalizedTemplateMetadata ? this.getRendererType(directiveType) : null,
  12358. componentFactory: null
  12359. });
  12360. if (nonNormalizedTemplateMetadata) {
  12361. metadata.componentFactory =
  12362. this.getComponentFactory(selector, directiveType, metadata.inputs, metadata.outputs);
  12363. }
  12364. cacheEntry = { metadata, annotation: dirMeta };
  12365. this._nonNormalizedDirectiveCache.set(directiveType, cacheEntry);
  12366. return cacheEntry;
  12367. }
  12368. /**
  12369. * Gets the metadata for the given directive.
  12370. * This assumes `loadNgModuleDirectiveAndPipeMetadata` has been called first.
  12371. * @param {?} directiveType
  12372. * @return {?}
  12373. */
  12374. getDirectiveMetadata(directiveType) {
  12375. const /** @type {?} */ dirMeta = /** @type {?} */ ((this._directiveCache.get(directiveType)));
  12376. if (!dirMeta) {
  12377. this._reportError(syntaxError(`Illegal state: getDirectiveMetadata can only be called after loadNgModuleDirectiveAndPipeMetadata for a module that declares it. Directive ${stringifyType(directiveType)}.`), directiveType);
  12378. }
  12379. return dirMeta;
  12380. }
  12381. /**
  12382. * @param {?} dirType
  12383. * @return {?}
  12384. */
  12385. getDirectiveSummary(dirType) {
  12386. const /** @type {?} */ dirSummary = /** @type {?} */ (this._loadSummary(dirType, CompileSummaryKind.Directive));
  12387. if (!dirSummary) {
  12388. this._reportError(syntaxError(`Illegal state: Could not load the summary for directive ${stringifyType(dirType)}.`), dirType);
  12389. }
  12390. return dirSummary;
  12391. }
  12392. /**
  12393. * @param {?} type
  12394. * @return {?}
  12395. */
  12396. isDirective(type) {
  12397. return !!this._loadSummary(type, CompileSummaryKind.Directive) ||
  12398. this._directiveResolver.isDirective(type);
  12399. }
  12400. /**
  12401. * @param {?} type
  12402. * @return {?}
  12403. */
  12404. isPipe(type) {
  12405. return !!this._loadSummary(type, CompileSummaryKind.Pipe) ||
  12406. this._pipeResolver.isPipe(type);
  12407. }
  12408. /**
  12409. * @param {?} type
  12410. * @return {?}
  12411. */
  12412. isNgModule(type) {
  12413. return !!this._loadSummary(type, CompileSummaryKind.NgModule) ||
  12414. this._ngModuleResolver.isNgModule(type);
  12415. }
  12416. /**
  12417. * @param {?} moduleType
  12418. * @param {?=} alreadyCollecting
  12419. * @return {?}
  12420. */
  12421. getNgModuleSummary(moduleType, alreadyCollecting = null) {
  12422. let /** @type {?} */ moduleSummary = /** @type {?} */ (this._loadSummary(moduleType, CompileSummaryKind.NgModule));
  12423. if (!moduleSummary) {
  12424. const /** @type {?} */ moduleMeta = this.getNgModuleMetadata(moduleType, false, alreadyCollecting);
  12425. moduleSummary = moduleMeta ? moduleMeta.toSummary() : null;
  12426. if (moduleSummary) {
  12427. this._summaryCache.set(moduleType, moduleSummary);
  12428. }
  12429. }
  12430. return moduleSummary;
  12431. }
  12432. /**
  12433. * Loads the declared directives and pipes of an NgModule.
  12434. * @param {?} moduleType
  12435. * @param {?} isSync
  12436. * @param {?=} throwIfNotFound
  12437. * @return {?}
  12438. */
  12439. loadNgModuleDirectiveAndPipeMetadata(moduleType, isSync, throwIfNotFound = true) {
  12440. const /** @type {?} */ ngModule = this.getNgModuleMetadata(moduleType, throwIfNotFound);
  12441. const /** @type {?} */ loading = [];
  12442. if (ngModule) {
  12443. ngModule.declaredDirectives.forEach((id) => {
  12444. const /** @type {?} */ promise = this.loadDirectiveMetadata(moduleType, id.reference, isSync);
  12445. if (promise) {
  12446. loading.push(promise);
  12447. }
  12448. });
  12449. ngModule.declaredPipes.forEach((id) => this._loadPipeMetadata(id.reference));
  12450. }
  12451. return Promise.all(loading);
  12452. }
  12453. /**
  12454. * @param {?} moduleType
  12455. * @param {?=} throwIfNotFound
  12456. * @param {?=} alreadyCollecting
  12457. * @return {?}
  12458. */
  12459. getNgModuleMetadata(moduleType, throwIfNotFound = true, alreadyCollecting = null) {
  12460. moduleType = resolveForwardRef(moduleType);
  12461. let /** @type {?} */ compileMeta = this._ngModuleCache.get(moduleType);
  12462. if (compileMeta) {
  12463. return compileMeta;
  12464. }
  12465. const /** @type {?} */ meta = this._ngModuleResolver.resolve(moduleType, throwIfNotFound);
  12466. if (!meta) {
  12467. return null;
  12468. }
  12469. const /** @type {?} */ declaredDirectives = [];
  12470. const /** @type {?} */ exportedNonModuleIdentifiers = [];
  12471. const /** @type {?} */ declaredPipes = [];
  12472. const /** @type {?} */ importedModules = [];
  12473. const /** @type {?} */ exportedModules = [];
  12474. const /** @type {?} */ providers = [];
  12475. const /** @type {?} */ entryComponents = [];
  12476. const /** @type {?} */ bootstrapComponents = [];
  12477. const /** @type {?} */ schemas = [];
  12478. if (meta.imports) {
  12479. flattenAndDedupeArray(meta.imports).forEach((importedType) => {
  12480. let /** @type {?} */ importedModuleType = /** @type {?} */ ((undefined));
  12481. if (isValidType(importedType)) {
  12482. importedModuleType = importedType;
  12483. }
  12484. else if (importedType && importedType.ngModule) {
  12485. const /** @type {?} */ moduleWithProviders = importedType;
  12486. importedModuleType = moduleWithProviders.ngModule;
  12487. if (moduleWithProviders.providers) {
  12488. providers.push(...this._getProvidersMetadata(moduleWithProviders.providers, entryComponents, `provider for the NgModule '${stringifyType(importedModuleType)}'`, [], importedType));
  12489. }
  12490. }
  12491. if (importedModuleType) {
  12492. if (this._checkSelfImport(moduleType, importedModuleType))
  12493. return;
  12494. if (!alreadyCollecting)
  12495. alreadyCollecting = new Set();
  12496. if (alreadyCollecting.has(importedModuleType)) {
  12497. this._reportError(syntaxError(`${this._getTypeDescriptor(importedModuleType)} '${stringifyType(importedType)}' is imported recursively by the module '${stringifyType(moduleType)}'.`), moduleType);
  12498. return;
  12499. }
  12500. alreadyCollecting.add(importedModuleType);
  12501. const /** @type {?} */ importedModuleSummary = this.getNgModuleSummary(importedModuleType, alreadyCollecting);
  12502. alreadyCollecting.delete(importedModuleType);
  12503. if (!importedModuleSummary) {
  12504. this._reportError(syntaxError(`Unexpected ${this._getTypeDescriptor(importedType)} '${stringifyType(importedType)}' imported by the module '${stringifyType(moduleType)}'. Please add a @NgModule annotation.`), moduleType);
  12505. return;
  12506. }
  12507. importedModules.push(importedModuleSummary);
  12508. }
  12509. else {
  12510. this._reportError(syntaxError(`Unexpected value '${stringifyType(importedType)}' imported by the module '${stringifyType(moduleType)}'`), moduleType);
  12511. return;
  12512. }
  12513. });
  12514. }
  12515. if (meta.exports) {
  12516. flattenAndDedupeArray(meta.exports).forEach((exportedType) => {
  12517. if (!isValidType(exportedType)) {
  12518. this._reportError(syntaxError(`Unexpected value '${stringifyType(exportedType)}' exported by the module '${stringifyType(moduleType)}'`), moduleType);
  12519. return;
  12520. }
  12521. if (!alreadyCollecting)
  12522. alreadyCollecting = new Set();
  12523. if (alreadyCollecting.has(exportedType)) {
  12524. this._reportError(syntaxError(`${this._getTypeDescriptor(exportedType)} '${stringify(exportedType)}' is exported recursively by the module '${stringifyType(moduleType)}'`), moduleType);
  12525. return;
  12526. }
  12527. alreadyCollecting.add(exportedType);
  12528. const /** @type {?} */ exportedModuleSummary = this.getNgModuleSummary(exportedType, alreadyCollecting);
  12529. alreadyCollecting.delete(exportedType);
  12530. if (exportedModuleSummary) {
  12531. exportedModules.push(exportedModuleSummary);
  12532. }
  12533. else {
  12534. exportedNonModuleIdentifiers.push(this._getIdentifierMetadata(exportedType));
  12535. }
  12536. });
  12537. }
  12538. // Note: This will be modified later, so we rely on
  12539. // getting a new instance every time!
  12540. const /** @type {?} */ transitiveModule = this._getTransitiveNgModuleMetadata(importedModules, exportedModules);
  12541. if (meta.declarations) {
  12542. flattenAndDedupeArray(meta.declarations).forEach((declaredType) => {
  12543. if (!isValidType(declaredType)) {
  12544. this._reportError(syntaxError(`Unexpected value '${stringifyType(declaredType)}' declared by the module '${stringifyType(moduleType)}'`), moduleType);
  12545. return;
  12546. }
  12547. const /** @type {?} */ declaredIdentifier = this._getIdentifierMetadata(declaredType);
  12548. if (this.isDirective(declaredType)) {
  12549. transitiveModule.addDirective(declaredIdentifier);
  12550. declaredDirectives.push(declaredIdentifier);
  12551. this._addTypeToModule(declaredType, moduleType);
  12552. }
  12553. else if (this.isPipe(declaredType)) {
  12554. transitiveModule.addPipe(declaredIdentifier);
  12555. transitiveModule.pipes.push(declaredIdentifier);
  12556. declaredPipes.push(declaredIdentifier);
  12557. this._addTypeToModule(declaredType, moduleType);
  12558. }
  12559. else {
  12560. this._reportError(syntaxError(`Unexpected ${this._getTypeDescriptor(declaredType)} '${stringifyType(declaredType)}' declared by the module '${stringifyType(moduleType)}'. Please add a @Pipe/@Directive/@Component annotation.`), moduleType);
  12561. return;
  12562. }
  12563. });
  12564. }
  12565. const /** @type {?} */ exportedDirectives = [];
  12566. const /** @type {?} */ exportedPipes = [];
  12567. exportedNonModuleIdentifiers.forEach((exportedId) => {
  12568. if (transitiveModule.directivesSet.has(exportedId.reference)) {
  12569. exportedDirectives.push(exportedId);
  12570. transitiveModule.addExportedDirective(exportedId);
  12571. }
  12572. else if (transitiveModule.pipesSet.has(exportedId.reference)) {
  12573. exportedPipes.push(exportedId);
  12574. transitiveModule.addExportedPipe(exportedId);
  12575. }
  12576. else {
  12577. this._reportError(syntaxError(`Can't export ${this._getTypeDescriptor(exportedId.reference)} ${stringifyType(exportedId.reference)} from ${stringifyType(moduleType)} as it was neither declared nor imported!`), moduleType);
  12578. return;
  12579. }
  12580. });
  12581. // The providers of the module have to go last
  12582. // so that they overwrite any other provider we already added.
  12583. if (meta.providers) {
  12584. providers.push(...this._getProvidersMetadata(meta.providers, entryComponents, `provider for the NgModule '${stringifyType(moduleType)}'`, [], moduleType));
  12585. }
  12586. if (meta.entryComponents) {
  12587. entryComponents.push(...flattenAndDedupeArray(meta.entryComponents)
  12588. .map(type => /** @type {?} */ ((this._getEntryComponentMetadata(type)))));
  12589. }
  12590. if (meta.bootstrap) {
  12591. flattenAndDedupeArray(meta.bootstrap).forEach(type => {
  12592. if (!isValidType(type)) {
  12593. this._reportError(syntaxError(`Unexpected value '${stringifyType(type)}' used in the bootstrap property of module '${stringifyType(moduleType)}'`), moduleType);
  12594. return;
  12595. }
  12596. bootstrapComponents.push(this._getIdentifierMetadata(type));
  12597. });
  12598. }
  12599. entryComponents.push(...bootstrapComponents.map(type => /** @type {?} */ ((this._getEntryComponentMetadata(type.reference)))));
  12600. if (meta.schemas) {
  12601. schemas.push(...flattenAndDedupeArray(meta.schemas));
  12602. }
  12603. compileMeta = new CompileNgModuleMetadata({
  12604. type: this._getTypeMetadata(moduleType),
  12605. providers,
  12606. entryComponents,
  12607. bootstrapComponents,
  12608. schemas,
  12609. declaredDirectives,
  12610. exportedDirectives,
  12611. declaredPipes,
  12612. exportedPipes,
  12613. importedModules,
  12614. exportedModules,
  12615. transitiveModule,
  12616. id: meta.id || null,
  12617. });
  12618. entryComponents.forEach((id) => transitiveModule.addEntryComponent(id));
  12619. providers.forEach((provider) => transitiveModule.addProvider(provider, /** @type {?} */ ((compileMeta)).type));
  12620. transitiveModule.addModule(compileMeta.type);
  12621. this._ngModuleCache.set(moduleType, compileMeta);
  12622. return compileMeta;
  12623. }
  12624. /**
  12625. * @param {?} moduleType
  12626. * @param {?} importedModuleType
  12627. * @return {?}
  12628. */
  12629. _checkSelfImport(moduleType, importedModuleType) {
  12630. if (moduleType === importedModuleType) {
  12631. this._reportError(syntaxError(`'${stringifyType(moduleType)}' module can't import itself`), moduleType);
  12632. return true;
  12633. }
  12634. return false;
  12635. }
  12636. /**
  12637. * @param {?} type
  12638. * @return {?}
  12639. */
  12640. _getTypeDescriptor(type) {
  12641. if (isValidType(type)) {
  12642. if (this.isDirective(type)) {
  12643. return 'directive';
  12644. }
  12645. if (this.isPipe(type)) {
  12646. return 'pipe';
  12647. }
  12648. if (this.isNgModule(type)) {
  12649. return 'module';
  12650. }
  12651. }
  12652. if ((/** @type {?} */ (type)).provide) {
  12653. return 'provider';
  12654. }
  12655. return 'value';
  12656. }
  12657. /**
  12658. * @param {?} type
  12659. * @param {?} moduleType
  12660. * @return {?}
  12661. */
  12662. _addTypeToModule(type, moduleType) {
  12663. const /** @type {?} */ oldModule = this._ngModuleOfTypes.get(type);
  12664. if (oldModule && oldModule !== moduleType) {
  12665. this._reportError(syntaxError(`Type ${stringifyType(type)} is part of the declarations of 2 modules: ${stringifyType(oldModule)} and ${stringifyType(moduleType)}! ` +
  12666. `Please consider moving ${stringifyType(type)} to a higher module that imports ${stringifyType(oldModule)} and ${stringifyType(moduleType)}. ` +
  12667. `You can also create a new NgModule that exports and includes ${stringifyType(type)} then import that NgModule in ${stringifyType(oldModule)} and ${stringifyType(moduleType)}.`), moduleType);
  12668. return;
  12669. }
  12670. this._ngModuleOfTypes.set(type, moduleType);
  12671. }
  12672. /**
  12673. * @param {?} importedModules
  12674. * @param {?} exportedModules
  12675. * @return {?}
  12676. */
  12677. _getTransitiveNgModuleMetadata(importedModules, exportedModules) {
  12678. // collect `providers` / `entryComponents` from all imported and all exported modules
  12679. const /** @type {?} */ result = new TransitiveCompileNgModuleMetadata();
  12680. const /** @type {?} */ modulesByToken = new Map();
  12681. importedModules.concat(exportedModules).forEach((modSummary) => {
  12682. modSummary.modules.forEach((mod) => result.addModule(mod));
  12683. modSummary.entryComponents.forEach((comp) => result.addEntryComponent(comp));
  12684. const /** @type {?} */ addedTokens = new Set();
  12685. modSummary.providers.forEach((entry) => {
  12686. const /** @type {?} */ tokenRef = tokenReference(entry.provider.token);
  12687. let /** @type {?} */ prevModules = modulesByToken.get(tokenRef);
  12688. if (!prevModules) {
  12689. prevModules = new Set();
  12690. modulesByToken.set(tokenRef, prevModules);
  12691. }
  12692. const /** @type {?} */ moduleRef = entry.module.reference;
  12693. // Note: the providers of one module may still contain multiple providers
  12694. // per token (e.g. for multi providers), and we need to preserve these.
  12695. if (addedTokens.has(tokenRef) || !prevModules.has(moduleRef)) {
  12696. prevModules.add(moduleRef);
  12697. addedTokens.add(tokenRef);
  12698. result.addProvider(entry.provider, entry.module);
  12699. }
  12700. });
  12701. });
  12702. exportedModules.forEach((modSummary) => {
  12703. modSummary.exportedDirectives.forEach((id) => result.addExportedDirective(id));
  12704. modSummary.exportedPipes.forEach((id) => result.addExportedPipe(id));
  12705. });
  12706. importedModules.forEach((modSummary) => {
  12707. modSummary.exportedDirectives.forEach((id) => result.addDirective(id));
  12708. modSummary.exportedPipes.forEach((id) => result.addPipe(id));
  12709. });
  12710. return result;
  12711. }
  12712. /**
  12713. * @param {?} type
  12714. * @return {?}
  12715. */
  12716. _getIdentifierMetadata(type) {
  12717. type = resolveForwardRef(type);
  12718. return { reference: type };
  12719. }
  12720. /**
  12721. * @param {?} type
  12722. * @return {?}
  12723. */
  12724. isInjectable(type) {
  12725. const /** @type {?} */ annotations = this._reflector.annotations(type);
  12726. return annotations.some(ann => createInjectable.isTypeOf(ann));
  12727. }
  12728. /**
  12729. * @param {?} type
  12730. * @return {?}
  12731. */
  12732. getInjectableSummary(type) {
  12733. return {
  12734. summaryKind: CompileSummaryKind.Injectable,
  12735. type: this._getTypeMetadata(type, null, false)
  12736. };
  12737. }
  12738. /**
  12739. * @param {?} type
  12740. * @param {?=} dependencies
  12741. * @return {?}
  12742. */
  12743. _getInjectableMetadata(type, dependencies = null) {
  12744. const /** @type {?} */ typeSummary = this._loadSummary(type, CompileSummaryKind.Injectable);
  12745. if (typeSummary) {
  12746. return typeSummary.type;
  12747. }
  12748. return this._getTypeMetadata(type, dependencies);
  12749. }
  12750. /**
  12751. * @param {?} type
  12752. * @param {?=} dependencies
  12753. * @param {?=} throwOnUnknownDeps
  12754. * @return {?}
  12755. */
  12756. _getTypeMetadata(type, dependencies = null, throwOnUnknownDeps = true) {
  12757. const /** @type {?} */ identifier = this._getIdentifierMetadata(type);
  12758. return {
  12759. reference: identifier.reference,
  12760. diDeps: this._getDependenciesMetadata(identifier.reference, dependencies, throwOnUnknownDeps),
  12761. lifecycleHooks: getAllLifecycleHooks(this._reflector, identifier.reference),
  12762. };
  12763. }
  12764. /**
  12765. * @param {?} factory
  12766. * @param {?=} dependencies
  12767. * @return {?}
  12768. */
  12769. _getFactoryMetadata(factory, dependencies = null) {
  12770. factory = resolveForwardRef(factory);
  12771. return { reference: factory, diDeps: this._getDependenciesMetadata(factory, dependencies) };
  12772. }
  12773. /**
  12774. * Gets the metadata for the given pipe.
  12775. * This assumes `loadNgModuleDirectiveAndPipeMetadata` has been called first.
  12776. * @param {?} pipeType
  12777. * @return {?}
  12778. */
  12779. getPipeMetadata(pipeType) {
  12780. const /** @type {?} */ pipeMeta = this._pipeCache.get(pipeType);
  12781. if (!pipeMeta) {
  12782. this._reportError(syntaxError(`Illegal state: getPipeMetadata can only be called after loadNgModuleDirectiveAndPipeMetadata for a module that declares it. Pipe ${stringifyType(pipeType)}.`), pipeType);
  12783. }
  12784. return pipeMeta || null;
  12785. }
  12786. /**
  12787. * @param {?} pipeType
  12788. * @return {?}
  12789. */
  12790. getPipeSummary(pipeType) {
  12791. const /** @type {?} */ pipeSummary = /** @type {?} */ (this._loadSummary(pipeType, CompileSummaryKind.Pipe));
  12792. if (!pipeSummary) {
  12793. this._reportError(syntaxError(`Illegal state: Could not load the summary for pipe ${stringifyType(pipeType)}.`), pipeType);
  12794. }
  12795. return pipeSummary;
  12796. }
  12797. /**
  12798. * @param {?} pipeType
  12799. * @return {?}
  12800. */
  12801. getOrLoadPipeMetadata(pipeType) {
  12802. let /** @type {?} */ pipeMeta = this._pipeCache.get(pipeType);
  12803. if (!pipeMeta) {
  12804. pipeMeta = this._loadPipeMetadata(pipeType);
  12805. }
  12806. return pipeMeta;
  12807. }
  12808. /**
  12809. * @param {?} pipeType
  12810. * @return {?}
  12811. */
  12812. _loadPipeMetadata(pipeType) {
  12813. pipeType = resolveForwardRef(pipeType);
  12814. const /** @type {?} */ pipeAnnotation = /** @type {?} */ ((this._pipeResolver.resolve(pipeType)));
  12815. const /** @type {?} */ pipeMeta = new CompilePipeMetadata({
  12816. type: this._getTypeMetadata(pipeType),
  12817. name: pipeAnnotation.name,
  12818. pure: !!pipeAnnotation.pure
  12819. });
  12820. this._pipeCache.set(pipeType, pipeMeta);
  12821. this._summaryCache.set(pipeType, pipeMeta.toSummary());
  12822. return pipeMeta;
  12823. }
  12824. /**
  12825. * @param {?} typeOrFunc
  12826. * @param {?} dependencies
  12827. * @param {?=} throwOnUnknownDeps
  12828. * @return {?}
  12829. */
  12830. _getDependenciesMetadata(typeOrFunc, dependencies, throwOnUnknownDeps = true) {
  12831. let /** @type {?} */ hasUnknownDeps = false;
  12832. const /** @type {?} */ params = dependencies || this._reflector.parameters(typeOrFunc) || [];
  12833. const /** @type {?} */ dependenciesMetadata = params.map((param) => {
  12834. let /** @type {?} */ isAttribute = false;
  12835. let /** @type {?} */ isHost = false;
  12836. let /** @type {?} */ isSelf = false;
  12837. let /** @type {?} */ isSkipSelf = false;
  12838. let /** @type {?} */ isOptional = false;
  12839. let /** @type {?} */ token = null;
  12840. if (Array.isArray(param)) {
  12841. param.forEach((paramEntry) => {
  12842. if (createHost.isTypeOf(paramEntry)) {
  12843. isHost = true;
  12844. }
  12845. else if (createSelf.isTypeOf(paramEntry)) {
  12846. isSelf = true;
  12847. }
  12848. else if (createSkipSelf.isTypeOf(paramEntry)) {
  12849. isSkipSelf = true;
  12850. }
  12851. else if (createOptional.isTypeOf(paramEntry)) {
  12852. isOptional = true;
  12853. }
  12854. else if (createAttribute.isTypeOf(paramEntry)) {
  12855. isAttribute = true;
  12856. token = paramEntry.attributeName;
  12857. }
  12858. else if (createInject.isTypeOf(paramEntry)) {
  12859. token = paramEntry.token;
  12860. }
  12861. else if (createInjectionToken.isTypeOf(paramEntry) || paramEntry instanceof StaticSymbol) {
  12862. token = paramEntry;
  12863. }
  12864. else if (isValidType(paramEntry) && token == null) {
  12865. token = paramEntry;
  12866. }
  12867. });
  12868. }
  12869. else {
  12870. token = param;
  12871. }
  12872. if (token == null) {
  12873. hasUnknownDeps = true;
  12874. return /** @type {?} */ ((null));
  12875. }
  12876. return {
  12877. isAttribute,
  12878. isHost,
  12879. isSelf,
  12880. isSkipSelf,
  12881. isOptional,
  12882. token: this._getTokenMetadata(token)
  12883. };
  12884. });
  12885. if (hasUnknownDeps) {
  12886. const /** @type {?} */ depsTokens = dependenciesMetadata.map((dep) => dep ? stringifyType(dep.token) : '?').join(', ');
  12887. const /** @type {?} */ message = `Can't resolve all parameters for ${stringifyType(typeOrFunc)}: (${depsTokens}).`;
  12888. if (throwOnUnknownDeps || this._config.strictInjectionParameters) {
  12889. this._reportError(syntaxError(message), typeOrFunc);
  12890. }
  12891. else {
  12892. this._console.warn(`Warning: ${message} This will become an error in Angular v6.x`);
  12893. }
  12894. }
  12895. return dependenciesMetadata;
  12896. }
  12897. /**
  12898. * @param {?} token
  12899. * @return {?}
  12900. */
  12901. _getTokenMetadata(token) {
  12902. token = resolveForwardRef(token);
  12903. let /** @type {?} */ compileToken;
  12904. if (typeof token === 'string') {
  12905. compileToken = { value: token };
  12906. }
  12907. else {
  12908. compileToken = { identifier: { reference: token } };
  12909. }
  12910. return compileToken;
  12911. }
  12912. /**
  12913. * @param {?} providers
  12914. * @param {?} targetEntryComponents
  12915. * @param {?=} debugInfo
  12916. * @param {?=} compileProviders
  12917. * @param {?=} type
  12918. * @return {?}
  12919. */
  12920. _getProvidersMetadata(providers, targetEntryComponents, debugInfo, compileProviders = [], type) {
  12921. providers.forEach((provider, providerIdx) => {
  12922. if (Array.isArray(provider)) {
  12923. this._getProvidersMetadata(provider, targetEntryComponents, debugInfo, compileProviders);
  12924. }
  12925. else {
  12926. provider = resolveForwardRef(provider);
  12927. let /** @type {?} */ providerMeta = /** @type {?} */ ((undefined));
  12928. if (provider && typeof provider === 'object' && provider.hasOwnProperty('provide')) {
  12929. this._validateProvider(provider);
  12930. providerMeta = new ProviderMeta(provider.provide, provider);
  12931. }
  12932. else if (isValidType(provider)) {
  12933. providerMeta = new ProviderMeta(provider, { useClass: provider });
  12934. }
  12935. else if (provider === void 0) {
  12936. this._reportError(syntaxError(`Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.`));
  12937. return;
  12938. }
  12939. else {
  12940. const /** @type {?} */ providersInfo = (/** @type {?} */ (providers.reduce((soFar, seenProvider, seenProviderIdx) => {
  12941. if (seenProviderIdx < providerIdx) {
  12942. soFar.push(`${stringifyType(seenProvider)}`);
  12943. }
  12944. else if (seenProviderIdx == providerIdx) {
  12945. soFar.push(`?${stringifyType(seenProvider)}?`);
  12946. }
  12947. else if (seenProviderIdx == providerIdx + 1) {
  12948. soFar.push('...');
  12949. }
  12950. return soFar;
  12951. }, [])))
  12952. .join(', ');
  12953. this._reportError(syntaxError(`Invalid ${debugInfo ? debugInfo : 'provider'} - only instances of Provider and Type are allowed, got: [${providersInfo}]`), type);
  12954. return;
  12955. }
  12956. if (providerMeta.token ===
  12957. this._reflector.resolveExternalReference(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS)) {
  12958. targetEntryComponents.push(...this._getEntryComponentsFromProvider(providerMeta, type));
  12959. }
  12960. else {
  12961. compileProviders.push(this.getProviderMetadata(providerMeta));
  12962. }
  12963. }
  12964. });
  12965. return compileProviders;
  12966. }
  12967. /**
  12968. * @param {?} provider
  12969. * @return {?}
  12970. */
  12971. _validateProvider(provider) {
  12972. if (provider.hasOwnProperty('useClass') && provider.useClass == null) {
  12973. this._reportError(syntaxError(`Invalid provider for ${stringifyType(provider.provide)}. useClass cannot be ${provider.useClass}.
  12974. Usually it happens when:
  12975. 1. There's a circular dependency (might be caused by using index.ts (barrel) files).
  12976. 2. Class was used before it was declared. Use forwardRef in this case.`));
  12977. }
  12978. }
  12979. /**
  12980. * @param {?} provider
  12981. * @param {?=} type
  12982. * @return {?}
  12983. */
  12984. _getEntryComponentsFromProvider(provider, type) {
  12985. const /** @type {?} */ components = [];
  12986. const /** @type {?} */ collectedIdentifiers = [];
  12987. if (provider.useFactory || provider.useExisting || provider.useClass) {
  12988. this._reportError(syntaxError(`The ANALYZE_FOR_ENTRY_COMPONENTS token only supports useValue!`), type);
  12989. return [];
  12990. }
  12991. if (!provider.multi) {
  12992. this._reportError(syntaxError(`The ANALYZE_FOR_ENTRY_COMPONENTS token only supports 'multi = true'!`), type);
  12993. return [];
  12994. }
  12995. extractIdentifiers(provider.useValue, collectedIdentifiers);
  12996. collectedIdentifiers.forEach((identifier) => {
  12997. const /** @type {?} */ entry = this._getEntryComponentMetadata(identifier.reference, false);
  12998. if (entry) {
  12999. components.push(entry);
  13000. }
  13001. });
  13002. return components;
  13003. }
  13004. /**
  13005. * @param {?} dirType
  13006. * @param {?=} throwIfNotFound
  13007. * @return {?}
  13008. */
  13009. _getEntryComponentMetadata(dirType, throwIfNotFound = true) {
  13010. const /** @type {?} */ dirMeta = this.getNonNormalizedDirectiveMetadata(dirType);
  13011. if (dirMeta && dirMeta.metadata.isComponent) {
  13012. return { componentType: dirType, componentFactory: /** @type {?} */ ((dirMeta.metadata.componentFactory)) };
  13013. }
  13014. const /** @type {?} */ dirSummary = /** @type {?} */ (this._loadSummary(dirType, CompileSummaryKind.Directive));
  13015. if (dirSummary && dirSummary.isComponent) {
  13016. return { componentType: dirType, componentFactory: /** @type {?} */ ((dirSummary.componentFactory)) };
  13017. }
  13018. if (throwIfNotFound) {
  13019. throw syntaxError(`${dirType.name} cannot be used as an entry component.`);
  13020. }
  13021. return null;
  13022. }
  13023. /**
  13024. * @param {?} provider
  13025. * @return {?}
  13026. */
  13027. getProviderMetadata(provider) {
  13028. let /** @type {?} */ compileDeps = /** @type {?} */ ((undefined));
  13029. let /** @type {?} */ compileTypeMetadata = /** @type {?} */ ((null));
  13030. let /** @type {?} */ compileFactoryMetadata = /** @type {?} */ ((null));
  13031. let /** @type {?} */ token = this._getTokenMetadata(provider.token);
  13032. if (provider.useClass) {
  13033. compileTypeMetadata = this._getInjectableMetadata(provider.useClass, provider.dependencies);
  13034. compileDeps = compileTypeMetadata.diDeps;
  13035. if (provider.token === provider.useClass) {
  13036. // use the compileTypeMetadata as it contains information about lifecycleHooks...
  13037. token = { identifier: compileTypeMetadata };
  13038. }
  13039. }
  13040. else if (provider.useFactory) {
  13041. compileFactoryMetadata = this._getFactoryMetadata(provider.useFactory, provider.dependencies);
  13042. compileDeps = compileFactoryMetadata.diDeps;
  13043. }
  13044. return {
  13045. token: token,
  13046. useClass: compileTypeMetadata,
  13047. useValue: provider.useValue,
  13048. useFactory: compileFactoryMetadata,
  13049. useExisting: provider.useExisting ? this._getTokenMetadata(provider.useExisting) : undefined,
  13050. deps: compileDeps,
  13051. multi: provider.multi
  13052. };
  13053. }
  13054. /**
  13055. * @param {?} queries
  13056. * @param {?} isViewQuery
  13057. * @param {?} directiveType
  13058. * @return {?}
  13059. */
  13060. _getQueriesMetadata(queries, isViewQuery, directiveType) {
  13061. const /** @type {?} */ res = [];
  13062. Object.keys(queries).forEach((propertyName) => {
  13063. const /** @type {?} */ query = queries[propertyName];
  13064. if (query.isViewQuery === isViewQuery) {
  13065. res.push(this._getQueryMetadata(query, propertyName, directiveType));
  13066. }
  13067. });
  13068. return res;
  13069. }
  13070. /**
  13071. * @param {?} selector
  13072. * @return {?}
  13073. */
  13074. _queryVarBindings(selector) { return selector.split(/\s*,\s*/); }
  13075. /**
  13076. * @param {?} q
  13077. * @param {?} propertyName
  13078. * @param {?} typeOrFunc
  13079. * @return {?}
  13080. */
  13081. _getQueryMetadata(q, propertyName, typeOrFunc) {
  13082. let /** @type {?} */ selectors;
  13083. if (typeof q.selector === 'string') {
  13084. selectors =
  13085. this._queryVarBindings(q.selector).map(varName => this._getTokenMetadata(varName));
  13086. }
  13087. else {
  13088. if (!q.selector) {
  13089. this._reportError(syntaxError(`Can't construct a query for the property "${propertyName}" of "${stringifyType(typeOrFunc)}" since the query selector wasn't defined.`), typeOrFunc);
  13090. selectors = [];
  13091. }
  13092. else {
  13093. selectors = [this._getTokenMetadata(q.selector)];
  13094. }
  13095. }
  13096. return {
  13097. selectors,
  13098. first: q.first,
  13099. descendants: q.descendants, propertyName,
  13100. read: q.read ? this._getTokenMetadata(q.read) : /** @type {?} */ ((null))
  13101. };
  13102. }
  13103. /**
  13104. * @param {?} error
  13105. * @param {?=} type
  13106. * @param {?=} otherType
  13107. * @return {?}
  13108. */
  13109. _reportError(error, type, otherType) {
  13110. if (this._errorCollector) {
  13111. this._errorCollector(error, type);
  13112. if (otherType) {
  13113. this._errorCollector(error, otherType);
  13114. }
  13115. }
  13116. else {
  13117. throw error;
  13118. }
  13119. }
  13120. }
  13121. /**
  13122. * @param {?} tree
  13123. * @param {?=} out
  13124. * @return {?}
  13125. */
  13126. function flattenArray(tree, out = []) {
  13127. if (tree) {
  13128. for (let /** @type {?} */ i = 0; i < tree.length; i++) {
  13129. const /** @type {?} */ item = resolveForwardRef(tree[i]);
  13130. if (Array.isArray(item)) {
  13131. flattenArray(item, out);
  13132. }
  13133. else {
  13134. out.push(item);
  13135. }
  13136. }
  13137. }
  13138. return out;
  13139. }
  13140. /**
  13141. * @param {?} array
  13142. * @return {?}
  13143. */
  13144. function dedupeArray(array) {
  13145. if (array) {
  13146. return Array.from(new Set(array));
  13147. }
  13148. return [];
  13149. }
  13150. /**
  13151. * @param {?} tree
  13152. * @return {?}
  13153. */
  13154. function flattenAndDedupeArray(tree) {
  13155. return dedupeArray(flattenArray(tree));
  13156. }
  13157. /**
  13158. * @param {?} value
  13159. * @return {?}
  13160. */
  13161. function isValidType(value) {
  13162. return (value instanceof StaticSymbol) || (value instanceof Type);
  13163. }
  13164. /**
  13165. * @param {?} value
  13166. * @param {?} targetIdentifiers
  13167. * @return {?}
  13168. */
  13169. function extractIdentifiers(value, targetIdentifiers) {
  13170. visitValue(value, new _CompileValueConverter(), targetIdentifiers);
  13171. }
  13172. class _CompileValueConverter extends ValueTransformer {
  13173. /**
  13174. * @param {?} value
  13175. * @param {?} targetIdentifiers
  13176. * @return {?}
  13177. */
  13178. visitOther(value, targetIdentifiers) {
  13179. targetIdentifiers.push({ reference: value });
  13180. }
  13181. }
  13182. /**
  13183. * @param {?} type
  13184. * @return {?}
  13185. */
  13186. function stringifyType(type) {
  13187. if (type instanceof StaticSymbol) {
  13188. return `${type.name} in ${type.filePath}`;
  13189. }
  13190. else {
  13191. return stringify(type);
  13192. }
  13193. }
  13194. /**
  13195. * Indicates that a component is still being loaded in a synchronous compile.
  13196. * @param {?} compType
  13197. * @return {?}
  13198. */
  13199. function componentStillLoadingError(compType) {
  13200. const /** @type {?} */ error = Error(`Can't compile synchronously as ${stringify(compType)} is still being loaded!`);
  13201. (/** @type {?} */ (error))[ERROR_COMPONENT_TYPE] = compType;
  13202. return error;
  13203. }
  13204. /**
  13205. * @fileoverview added by tsickle
  13206. * @suppress {checkTypes} checked by tsc
  13207. */
  13208. /**
  13209. * @license
  13210. * Copyright Google Inc. All Rights Reserved.
  13211. *
  13212. * Use of this source code is governed by an MIT-style license that can be
  13213. * found in the LICENSE file at https://angular.io/license
  13214. */
  13215. /** @enum {number} */
  13216. const TypeModifier = {
  13217. Const: 0,
  13218. };
  13219. TypeModifier[TypeModifier.Const] = "Const";
  13220. /**
  13221. * @abstract
  13222. */
  13223. class Type$1 {
  13224. /**
  13225. * @param {?=} modifiers
  13226. */
  13227. constructor(modifiers = null) {
  13228. this.modifiers = modifiers;
  13229. if (!modifiers) {
  13230. this.modifiers = [];
  13231. }
  13232. }
  13233. /**
  13234. * @param {?} modifier
  13235. * @return {?}
  13236. */
  13237. hasModifier(modifier) { return /** @type {?} */ ((this.modifiers)).indexOf(modifier) !== -1; }
  13238. }
  13239. /** @enum {number} */
  13240. const BuiltinTypeName = {
  13241. Dynamic: 0,
  13242. Bool: 1,
  13243. String: 2,
  13244. Int: 3,
  13245. Number: 4,
  13246. Function: 5,
  13247. Inferred: 6,
  13248. };
  13249. BuiltinTypeName[BuiltinTypeName.Dynamic] = "Dynamic";
  13250. BuiltinTypeName[BuiltinTypeName.Bool] = "Bool";
  13251. BuiltinTypeName[BuiltinTypeName.String] = "String";
  13252. BuiltinTypeName[BuiltinTypeName.Int] = "Int";
  13253. BuiltinTypeName[BuiltinTypeName.Number] = "Number";
  13254. BuiltinTypeName[BuiltinTypeName.Function] = "Function";
  13255. BuiltinTypeName[BuiltinTypeName.Inferred] = "Inferred";
  13256. class BuiltinType extends Type$1 {
  13257. /**
  13258. * @param {?} name
  13259. * @param {?=} modifiers
  13260. */
  13261. constructor(name, modifiers = null) {
  13262. super(modifiers);
  13263. this.name = name;
  13264. }
  13265. /**
  13266. * @param {?} visitor
  13267. * @param {?} context
  13268. * @return {?}
  13269. */
  13270. visitType(visitor, context) {
  13271. return visitor.visitBuiltintType(this, context);
  13272. }
  13273. }
  13274. class ExpressionType extends Type$1 {
  13275. /**
  13276. * @param {?} value
  13277. * @param {?=} modifiers
  13278. */
  13279. constructor(value, modifiers = null) {
  13280. super(modifiers);
  13281. this.value = value;
  13282. }
  13283. /**
  13284. * @param {?} visitor
  13285. * @param {?} context
  13286. * @return {?}
  13287. */
  13288. visitType(visitor, context) {
  13289. return visitor.visitExpressionType(this, context);
  13290. }
  13291. }
  13292. class ArrayType extends Type$1 {
  13293. /**
  13294. * @param {?} of
  13295. * @param {?=} modifiers
  13296. */
  13297. constructor(of, modifiers = null) {
  13298. super(modifiers);
  13299. this.of = of;
  13300. }
  13301. /**
  13302. * @param {?} visitor
  13303. * @param {?} context
  13304. * @return {?}
  13305. */
  13306. visitType(visitor, context) {
  13307. return visitor.visitArrayType(this, context);
  13308. }
  13309. }
  13310. class MapType extends Type$1 {
  13311. /**
  13312. * @param {?} valueType
  13313. * @param {?=} modifiers
  13314. */
  13315. constructor(valueType, modifiers = null) {
  13316. super(modifiers);
  13317. this.valueType = valueType || null;
  13318. }
  13319. /**
  13320. * @param {?} visitor
  13321. * @param {?} context
  13322. * @return {?}
  13323. */
  13324. visitType(visitor, context) { return visitor.visitMapType(this, context); }
  13325. }
  13326. const DYNAMIC_TYPE = new BuiltinType(BuiltinTypeName.Dynamic);
  13327. const INFERRED_TYPE = new BuiltinType(BuiltinTypeName.Inferred);
  13328. const BOOL_TYPE = new BuiltinType(BuiltinTypeName.Bool);
  13329. const INT_TYPE = new BuiltinType(BuiltinTypeName.Int);
  13330. const NUMBER_TYPE = new BuiltinType(BuiltinTypeName.Number);
  13331. const STRING_TYPE = new BuiltinType(BuiltinTypeName.String);
  13332. const FUNCTION_TYPE = new BuiltinType(BuiltinTypeName.Function);
  13333. /**
  13334. * @record
  13335. */
  13336. /** @enum {number} */
  13337. const BinaryOperator = {
  13338. Equals: 0,
  13339. NotEquals: 1,
  13340. Identical: 2,
  13341. NotIdentical: 3,
  13342. Minus: 4,
  13343. Plus: 5,
  13344. Divide: 6,
  13345. Multiply: 7,
  13346. Modulo: 8,
  13347. And: 9,
  13348. Or: 10,
  13349. Lower: 11,
  13350. LowerEquals: 12,
  13351. Bigger: 13,
  13352. BiggerEquals: 14,
  13353. };
  13354. BinaryOperator[BinaryOperator.Equals] = "Equals";
  13355. BinaryOperator[BinaryOperator.NotEquals] = "NotEquals";
  13356. BinaryOperator[BinaryOperator.Identical] = "Identical";
  13357. BinaryOperator[BinaryOperator.NotIdentical] = "NotIdentical";
  13358. BinaryOperator[BinaryOperator.Minus] = "Minus";
  13359. BinaryOperator[BinaryOperator.Plus] = "Plus";
  13360. BinaryOperator[BinaryOperator.Divide] = "Divide";
  13361. BinaryOperator[BinaryOperator.Multiply] = "Multiply";
  13362. BinaryOperator[BinaryOperator.Modulo] = "Modulo";
  13363. BinaryOperator[BinaryOperator.And] = "And";
  13364. BinaryOperator[BinaryOperator.Or] = "Or";
  13365. BinaryOperator[BinaryOperator.Lower] = "Lower";
  13366. BinaryOperator[BinaryOperator.LowerEquals] = "LowerEquals";
  13367. BinaryOperator[BinaryOperator.Bigger] = "Bigger";
  13368. BinaryOperator[BinaryOperator.BiggerEquals] = "BiggerEquals";
  13369. /**
  13370. * @template T
  13371. * @param {?} base
  13372. * @param {?} other
  13373. * @return {?}
  13374. */
  13375. function nullSafeIsEquivalent(base, other) {
  13376. if (base == null || other == null) {
  13377. return base == other;
  13378. }
  13379. return base.isEquivalent(other);
  13380. }
  13381. /**
  13382. * @template T
  13383. * @param {?} base
  13384. * @param {?} other
  13385. * @return {?}
  13386. */
  13387. function areAllEquivalent(base, other) {
  13388. const /** @type {?} */ len = base.length;
  13389. if (len !== other.length) {
  13390. return false;
  13391. }
  13392. for (let /** @type {?} */ i = 0; i < len; i++) {
  13393. if (!base[i].isEquivalent(other[i])) {
  13394. return false;
  13395. }
  13396. }
  13397. return true;
  13398. }
  13399. /**
  13400. * @abstract
  13401. */
  13402. class Expression {
  13403. /**
  13404. * @param {?} type
  13405. * @param {?=} sourceSpan
  13406. */
  13407. constructor(type, sourceSpan) {
  13408. this.type = type || null;
  13409. this.sourceSpan = sourceSpan || null;
  13410. }
  13411. /**
  13412. * @param {?} name
  13413. * @param {?=} sourceSpan
  13414. * @return {?}
  13415. */
  13416. prop(name, sourceSpan) {
  13417. return new ReadPropExpr(this, name, null, sourceSpan);
  13418. }
  13419. /**
  13420. * @param {?} index
  13421. * @param {?=} type
  13422. * @param {?=} sourceSpan
  13423. * @return {?}
  13424. */
  13425. key(index, type, sourceSpan) {
  13426. return new ReadKeyExpr(this, index, type, sourceSpan);
  13427. }
  13428. /**
  13429. * @param {?} name
  13430. * @param {?} params
  13431. * @param {?=} sourceSpan
  13432. * @return {?}
  13433. */
  13434. callMethod(name, params, sourceSpan) {
  13435. return new InvokeMethodExpr(this, name, params, null, sourceSpan);
  13436. }
  13437. /**
  13438. * @param {?} params
  13439. * @param {?=} sourceSpan
  13440. * @return {?}
  13441. */
  13442. callFn(params, sourceSpan) {
  13443. return new InvokeFunctionExpr(this, params, null, sourceSpan);
  13444. }
  13445. /**
  13446. * @param {?} params
  13447. * @param {?=} type
  13448. * @param {?=} sourceSpan
  13449. * @return {?}
  13450. */
  13451. instantiate(params, type, sourceSpan) {
  13452. return new InstantiateExpr(this, params, type, sourceSpan);
  13453. }
  13454. /**
  13455. * @param {?} trueCase
  13456. * @param {?=} falseCase
  13457. * @param {?=} sourceSpan
  13458. * @return {?}
  13459. */
  13460. conditional(trueCase, falseCase = null, sourceSpan) {
  13461. return new ConditionalExpr(this, trueCase, falseCase, null, sourceSpan);
  13462. }
  13463. /**
  13464. * @param {?} rhs
  13465. * @param {?=} sourceSpan
  13466. * @return {?}
  13467. */
  13468. equals(rhs, sourceSpan) {
  13469. return new BinaryOperatorExpr(BinaryOperator.Equals, this, rhs, null, sourceSpan);
  13470. }
  13471. /**
  13472. * @param {?} rhs
  13473. * @param {?=} sourceSpan
  13474. * @return {?}
  13475. */
  13476. notEquals(rhs, sourceSpan) {
  13477. return new BinaryOperatorExpr(BinaryOperator.NotEquals, this, rhs, null, sourceSpan);
  13478. }
  13479. /**
  13480. * @param {?} rhs
  13481. * @param {?=} sourceSpan
  13482. * @return {?}
  13483. */
  13484. identical(rhs, sourceSpan) {
  13485. return new BinaryOperatorExpr(BinaryOperator.Identical, this, rhs, null, sourceSpan);
  13486. }
  13487. /**
  13488. * @param {?} rhs
  13489. * @param {?=} sourceSpan
  13490. * @return {?}
  13491. */
  13492. notIdentical(rhs, sourceSpan) {
  13493. return new BinaryOperatorExpr(BinaryOperator.NotIdentical, this, rhs, null, sourceSpan);
  13494. }
  13495. /**
  13496. * @param {?} rhs
  13497. * @param {?=} sourceSpan
  13498. * @return {?}
  13499. */
  13500. minus(rhs, sourceSpan) {
  13501. return new BinaryOperatorExpr(BinaryOperator.Minus, this, rhs, null, sourceSpan);
  13502. }
  13503. /**
  13504. * @param {?} rhs
  13505. * @param {?=} sourceSpan
  13506. * @return {?}
  13507. */
  13508. plus(rhs, sourceSpan) {
  13509. return new BinaryOperatorExpr(BinaryOperator.Plus, this, rhs, null, sourceSpan);
  13510. }
  13511. /**
  13512. * @param {?} rhs
  13513. * @param {?=} sourceSpan
  13514. * @return {?}
  13515. */
  13516. divide(rhs, sourceSpan) {
  13517. return new BinaryOperatorExpr(BinaryOperator.Divide, this, rhs, null, sourceSpan);
  13518. }
  13519. /**
  13520. * @param {?} rhs
  13521. * @param {?=} sourceSpan
  13522. * @return {?}
  13523. */
  13524. multiply(rhs, sourceSpan) {
  13525. return new BinaryOperatorExpr(BinaryOperator.Multiply, this, rhs, null, sourceSpan);
  13526. }
  13527. /**
  13528. * @param {?} rhs
  13529. * @param {?=} sourceSpan
  13530. * @return {?}
  13531. */
  13532. modulo(rhs, sourceSpan) {
  13533. return new BinaryOperatorExpr(BinaryOperator.Modulo, this, rhs, null, sourceSpan);
  13534. }
  13535. /**
  13536. * @param {?} rhs
  13537. * @param {?=} sourceSpan
  13538. * @return {?}
  13539. */
  13540. and(rhs, sourceSpan) {
  13541. return new BinaryOperatorExpr(BinaryOperator.And, this, rhs, null, sourceSpan);
  13542. }
  13543. /**
  13544. * @param {?} rhs
  13545. * @param {?=} sourceSpan
  13546. * @return {?}
  13547. */
  13548. or(rhs, sourceSpan) {
  13549. return new BinaryOperatorExpr(BinaryOperator.Or, this, rhs, null, sourceSpan);
  13550. }
  13551. /**
  13552. * @param {?} rhs
  13553. * @param {?=} sourceSpan
  13554. * @return {?}
  13555. */
  13556. lower(rhs, sourceSpan) {
  13557. return new BinaryOperatorExpr(BinaryOperator.Lower, this, rhs, null, sourceSpan);
  13558. }
  13559. /**
  13560. * @param {?} rhs
  13561. * @param {?=} sourceSpan
  13562. * @return {?}
  13563. */
  13564. lowerEquals(rhs, sourceSpan) {
  13565. return new BinaryOperatorExpr(BinaryOperator.LowerEquals, this, rhs, null, sourceSpan);
  13566. }
  13567. /**
  13568. * @param {?} rhs
  13569. * @param {?=} sourceSpan
  13570. * @return {?}
  13571. */
  13572. bigger(rhs, sourceSpan) {
  13573. return new BinaryOperatorExpr(BinaryOperator.Bigger, this, rhs, null, sourceSpan);
  13574. }
  13575. /**
  13576. * @param {?} rhs
  13577. * @param {?=} sourceSpan
  13578. * @return {?}
  13579. */
  13580. biggerEquals(rhs, sourceSpan) {
  13581. return new BinaryOperatorExpr(BinaryOperator.BiggerEquals, this, rhs, null, sourceSpan);
  13582. }
  13583. /**
  13584. * @param {?=} sourceSpan
  13585. * @return {?}
  13586. */
  13587. isBlank(sourceSpan) {
  13588. // Note: We use equals by purpose here to compare to null and undefined in JS.
  13589. // We use the typed null to allow strictNullChecks to narrow types.
  13590. return this.equals(TYPED_NULL_EXPR, sourceSpan);
  13591. }
  13592. /**
  13593. * @param {?} type
  13594. * @param {?=} sourceSpan
  13595. * @return {?}
  13596. */
  13597. cast(type, sourceSpan) {
  13598. return new CastExpr(this, type, sourceSpan);
  13599. }
  13600. /**
  13601. * @return {?}
  13602. */
  13603. toStmt() { return new ExpressionStatement(this, null); }
  13604. }
  13605. /** @enum {number} */
  13606. const BuiltinVar = {
  13607. This: 0,
  13608. Super: 1,
  13609. CatchError: 2,
  13610. CatchStack: 3,
  13611. };
  13612. BuiltinVar[BuiltinVar.This] = "This";
  13613. BuiltinVar[BuiltinVar.Super] = "Super";
  13614. BuiltinVar[BuiltinVar.CatchError] = "CatchError";
  13615. BuiltinVar[BuiltinVar.CatchStack] = "CatchStack";
  13616. class ReadVarExpr extends Expression {
  13617. /**
  13618. * @param {?} name
  13619. * @param {?=} type
  13620. * @param {?=} sourceSpan
  13621. */
  13622. constructor(name, type, sourceSpan) {
  13623. super(type, sourceSpan);
  13624. if (typeof name === 'string') {
  13625. this.name = name;
  13626. this.builtin = null;
  13627. }
  13628. else {
  13629. this.name = null;
  13630. this.builtin = /** @type {?} */ (name);
  13631. }
  13632. }
  13633. /**
  13634. * @param {?} e
  13635. * @return {?}
  13636. */
  13637. isEquivalent(e) {
  13638. return e instanceof ReadVarExpr && this.name === e.name && this.builtin === e.builtin;
  13639. }
  13640. /**
  13641. * @param {?} visitor
  13642. * @param {?} context
  13643. * @return {?}
  13644. */
  13645. visitExpression(visitor, context) {
  13646. return visitor.visitReadVarExpr(this, context);
  13647. }
  13648. /**
  13649. * @param {?} value
  13650. * @return {?}
  13651. */
  13652. set(value) {
  13653. if (!this.name) {
  13654. throw new Error(`Built in variable ${this.builtin} can not be assigned to.`);
  13655. }
  13656. return new WriteVarExpr(this.name, value, null, this.sourceSpan);
  13657. }
  13658. }
  13659. class WriteVarExpr extends Expression {
  13660. /**
  13661. * @param {?} name
  13662. * @param {?} value
  13663. * @param {?=} type
  13664. * @param {?=} sourceSpan
  13665. */
  13666. constructor(name, value, type, sourceSpan) {
  13667. super(type || value.type, sourceSpan);
  13668. this.name = name;
  13669. this.value = value;
  13670. }
  13671. /**
  13672. * @param {?} e
  13673. * @return {?}
  13674. */
  13675. isEquivalent(e) {
  13676. return e instanceof WriteVarExpr && this.name === e.name && this.value.isEquivalent(e.value);
  13677. }
  13678. /**
  13679. * @param {?} visitor
  13680. * @param {?} context
  13681. * @return {?}
  13682. */
  13683. visitExpression(visitor, context) {
  13684. return visitor.visitWriteVarExpr(this, context);
  13685. }
  13686. /**
  13687. * @param {?=} type
  13688. * @param {?=} modifiers
  13689. * @return {?}
  13690. */
  13691. toDeclStmt(type, modifiers) {
  13692. return new DeclareVarStmt(this.name, this.value, type, modifiers, this.sourceSpan);
  13693. }
  13694. }
  13695. class WriteKeyExpr extends Expression {
  13696. /**
  13697. * @param {?} receiver
  13698. * @param {?} index
  13699. * @param {?} value
  13700. * @param {?=} type
  13701. * @param {?=} sourceSpan
  13702. */
  13703. constructor(receiver, index, value, type, sourceSpan) {
  13704. super(type || value.type, sourceSpan);
  13705. this.receiver = receiver;
  13706. this.index = index;
  13707. this.value = value;
  13708. }
  13709. /**
  13710. * @param {?} e
  13711. * @return {?}
  13712. */
  13713. isEquivalent(e) {
  13714. return e instanceof WriteKeyExpr && this.receiver.isEquivalent(e.receiver) &&
  13715. this.index.isEquivalent(e.index) && this.value.isEquivalent(e.value);
  13716. }
  13717. /**
  13718. * @param {?} visitor
  13719. * @param {?} context
  13720. * @return {?}
  13721. */
  13722. visitExpression(visitor, context) {
  13723. return visitor.visitWriteKeyExpr(this, context);
  13724. }
  13725. }
  13726. class WritePropExpr extends Expression {
  13727. /**
  13728. * @param {?} receiver
  13729. * @param {?} name
  13730. * @param {?} value
  13731. * @param {?=} type
  13732. * @param {?=} sourceSpan
  13733. */
  13734. constructor(receiver, name, value, type, sourceSpan) {
  13735. super(type || value.type, sourceSpan);
  13736. this.receiver = receiver;
  13737. this.name = name;
  13738. this.value = value;
  13739. }
  13740. /**
  13741. * @param {?} e
  13742. * @return {?}
  13743. */
  13744. isEquivalent(e) {
  13745. return e instanceof WritePropExpr && this.receiver.isEquivalent(e.receiver) &&
  13746. this.name === e.name && this.value.isEquivalent(e.value);
  13747. }
  13748. /**
  13749. * @param {?} visitor
  13750. * @param {?} context
  13751. * @return {?}
  13752. */
  13753. visitExpression(visitor, context) {
  13754. return visitor.visitWritePropExpr(this, context);
  13755. }
  13756. }
  13757. /** @enum {number} */
  13758. const BuiltinMethod = {
  13759. ConcatArray: 0,
  13760. SubscribeObservable: 1,
  13761. Bind: 2,
  13762. };
  13763. BuiltinMethod[BuiltinMethod.ConcatArray] = "ConcatArray";
  13764. BuiltinMethod[BuiltinMethod.SubscribeObservable] = "SubscribeObservable";
  13765. BuiltinMethod[BuiltinMethod.Bind] = "Bind";
  13766. class InvokeMethodExpr extends Expression {
  13767. /**
  13768. * @param {?} receiver
  13769. * @param {?} method
  13770. * @param {?} args
  13771. * @param {?=} type
  13772. * @param {?=} sourceSpan
  13773. */
  13774. constructor(receiver, method, args, type, sourceSpan) {
  13775. super(type, sourceSpan);
  13776. this.receiver = receiver;
  13777. this.args = args;
  13778. if (typeof method === 'string') {
  13779. this.name = method;
  13780. this.builtin = null;
  13781. }
  13782. else {
  13783. this.name = null;
  13784. this.builtin = /** @type {?} */ (method);
  13785. }
  13786. }
  13787. /**
  13788. * @param {?} e
  13789. * @return {?}
  13790. */
  13791. isEquivalent(e) {
  13792. return e instanceof InvokeMethodExpr && this.receiver.isEquivalent(e.receiver) &&
  13793. this.name === e.name && this.builtin === e.builtin && areAllEquivalent(this.args, e.args);
  13794. }
  13795. /**
  13796. * @param {?} visitor
  13797. * @param {?} context
  13798. * @return {?}
  13799. */
  13800. visitExpression(visitor, context) {
  13801. return visitor.visitInvokeMethodExpr(this, context);
  13802. }
  13803. }
  13804. class InvokeFunctionExpr extends Expression {
  13805. /**
  13806. * @param {?} fn
  13807. * @param {?} args
  13808. * @param {?=} type
  13809. * @param {?=} sourceSpan
  13810. */
  13811. constructor(fn, args, type, sourceSpan) {
  13812. super(type, sourceSpan);
  13813. this.fn = fn;
  13814. this.args = args;
  13815. }
  13816. /**
  13817. * @param {?} e
  13818. * @return {?}
  13819. */
  13820. isEquivalent(e) {
  13821. return e instanceof InvokeFunctionExpr && this.fn.isEquivalent(e.fn) &&
  13822. areAllEquivalent(this.args, e.args);
  13823. }
  13824. /**
  13825. * @param {?} visitor
  13826. * @param {?} context
  13827. * @return {?}
  13828. */
  13829. visitExpression(visitor, context) {
  13830. return visitor.visitInvokeFunctionExpr(this, context);
  13831. }
  13832. }
  13833. class InstantiateExpr extends Expression {
  13834. /**
  13835. * @param {?} classExpr
  13836. * @param {?} args
  13837. * @param {?=} type
  13838. * @param {?=} sourceSpan
  13839. */
  13840. constructor(classExpr, args, type, sourceSpan) {
  13841. super(type, sourceSpan);
  13842. this.classExpr = classExpr;
  13843. this.args = args;
  13844. }
  13845. /**
  13846. * @param {?} e
  13847. * @return {?}
  13848. */
  13849. isEquivalent(e) {
  13850. return e instanceof InstantiateExpr && this.classExpr.isEquivalent(e.classExpr) &&
  13851. areAllEquivalent(this.args, e.args);
  13852. }
  13853. /**
  13854. * @param {?} visitor
  13855. * @param {?} context
  13856. * @return {?}
  13857. */
  13858. visitExpression(visitor, context) {
  13859. return visitor.visitInstantiateExpr(this, context);
  13860. }
  13861. }
  13862. class LiteralExpr extends Expression {
  13863. /**
  13864. * @param {?} value
  13865. * @param {?=} type
  13866. * @param {?=} sourceSpan
  13867. */
  13868. constructor(value, type, sourceSpan) {
  13869. super(type, sourceSpan);
  13870. this.value = value;
  13871. }
  13872. /**
  13873. * @param {?} e
  13874. * @return {?}
  13875. */
  13876. isEquivalent(e) {
  13877. return e instanceof LiteralExpr && this.value === e.value;
  13878. }
  13879. /**
  13880. * @param {?} visitor
  13881. * @param {?} context
  13882. * @return {?}
  13883. */
  13884. visitExpression(visitor, context) {
  13885. return visitor.visitLiteralExpr(this, context);
  13886. }
  13887. }
  13888. class ExternalExpr extends Expression {
  13889. /**
  13890. * @param {?} value
  13891. * @param {?=} type
  13892. * @param {?=} typeParams
  13893. * @param {?=} sourceSpan
  13894. */
  13895. constructor(value, type, typeParams = null, sourceSpan) {
  13896. super(type, sourceSpan);
  13897. this.value = value;
  13898. this.typeParams = typeParams;
  13899. }
  13900. /**
  13901. * @param {?} e
  13902. * @return {?}
  13903. */
  13904. isEquivalent(e) {
  13905. return e instanceof ExternalExpr && this.value.name === e.value.name &&
  13906. this.value.moduleName === e.value.moduleName && this.value.runtime === e.value.runtime;
  13907. }
  13908. /**
  13909. * @param {?} visitor
  13910. * @param {?} context
  13911. * @return {?}
  13912. */
  13913. visitExpression(visitor, context) {
  13914. return visitor.visitExternalExpr(this, context);
  13915. }
  13916. }
  13917. class ExternalReference {
  13918. /**
  13919. * @param {?} moduleName
  13920. * @param {?} name
  13921. * @param {?=} runtime
  13922. */
  13923. constructor(moduleName, name, runtime) {
  13924. this.moduleName = moduleName;
  13925. this.name = name;
  13926. this.runtime = runtime;
  13927. }
  13928. }
  13929. class ConditionalExpr extends Expression {
  13930. /**
  13931. * @param {?} condition
  13932. * @param {?} trueCase
  13933. * @param {?=} falseCase
  13934. * @param {?=} type
  13935. * @param {?=} sourceSpan
  13936. */
  13937. constructor(condition, trueCase, falseCase = null, type, sourceSpan) {
  13938. super(type || trueCase.type, sourceSpan);
  13939. this.condition = condition;
  13940. this.falseCase = falseCase;
  13941. this.trueCase = trueCase;
  13942. }
  13943. /**
  13944. * @param {?} e
  13945. * @return {?}
  13946. */
  13947. isEquivalent(e) {
  13948. return e instanceof ConditionalExpr && this.condition.isEquivalent(e.condition) &&
  13949. this.trueCase.isEquivalent(e.trueCase) && nullSafeIsEquivalent(this.falseCase, e.falseCase);
  13950. }
  13951. /**
  13952. * @param {?} visitor
  13953. * @param {?} context
  13954. * @return {?}
  13955. */
  13956. visitExpression(visitor, context) {
  13957. return visitor.visitConditionalExpr(this, context);
  13958. }
  13959. }
  13960. class NotExpr extends Expression {
  13961. /**
  13962. * @param {?} condition
  13963. * @param {?=} sourceSpan
  13964. */
  13965. constructor(condition, sourceSpan) {
  13966. super(BOOL_TYPE, sourceSpan);
  13967. this.condition = condition;
  13968. }
  13969. /**
  13970. * @param {?} e
  13971. * @return {?}
  13972. */
  13973. isEquivalent(e) {
  13974. return e instanceof NotExpr && this.condition.isEquivalent(e.condition);
  13975. }
  13976. /**
  13977. * @param {?} visitor
  13978. * @param {?} context
  13979. * @return {?}
  13980. */
  13981. visitExpression(visitor, context) {
  13982. return visitor.visitNotExpr(this, context);
  13983. }
  13984. }
  13985. class AssertNotNull extends Expression {
  13986. /**
  13987. * @param {?} condition
  13988. * @param {?=} sourceSpan
  13989. */
  13990. constructor(condition, sourceSpan) {
  13991. super(condition.type, sourceSpan);
  13992. this.condition = condition;
  13993. }
  13994. /**
  13995. * @param {?} e
  13996. * @return {?}
  13997. */
  13998. isEquivalent(e) {
  13999. return e instanceof AssertNotNull && this.condition.isEquivalent(e.condition);
  14000. }
  14001. /**
  14002. * @param {?} visitor
  14003. * @param {?} context
  14004. * @return {?}
  14005. */
  14006. visitExpression(visitor, context) {
  14007. return visitor.visitAssertNotNullExpr(this, context);
  14008. }
  14009. }
  14010. class CastExpr extends Expression {
  14011. /**
  14012. * @param {?} value
  14013. * @param {?=} type
  14014. * @param {?=} sourceSpan
  14015. */
  14016. constructor(value, type, sourceSpan) {
  14017. super(type, sourceSpan);
  14018. this.value = value;
  14019. }
  14020. /**
  14021. * @param {?} e
  14022. * @return {?}
  14023. */
  14024. isEquivalent(e) {
  14025. return e instanceof CastExpr && this.value.isEquivalent(e.value);
  14026. }
  14027. /**
  14028. * @param {?} visitor
  14029. * @param {?} context
  14030. * @return {?}
  14031. */
  14032. visitExpression(visitor, context) {
  14033. return visitor.visitCastExpr(this, context);
  14034. }
  14035. }
  14036. class FnParam {
  14037. /**
  14038. * @param {?} name
  14039. * @param {?=} type
  14040. */
  14041. constructor(name, type = null) {
  14042. this.name = name;
  14043. this.type = type;
  14044. }
  14045. /**
  14046. * @param {?} param
  14047. * @return {?}
  14048. */
  14049. isEquivalent(param) { return this.name === param.name; }
  14050. }
  14051. class FunctionExpr extends Expression {
  14052. /**
  14053. * @param {?} params
  14054. * @param {?} statements
  14055. * @param {?=} type
  14056. * @param {?=} sourceSpan
  14057. */
  14058. constructor(params, statements, type, sourceSpan) {
  14059. super(type, sourceSpan);
  14060. this.params = params;
  14061. this.statements = statements;
  14062. }
  14063. /**
  14064. * @param {?} e
  14065. * @return {?}
  14066. */
  14067. isEquivalent(e) {
  14068. return e instanceof FunctionExpr && areAllEquivalent(this.params, e.params) &&
  14069. areAllEquivalent(this.statements, e.statements);
  14070. }
  14071. /**
  14072. * @param {?} visitor
  14073. * @param {?} context
  14074. * @return {?}
  14075. */
  14076. visitExpression(visitor, context) {
  14077. return visitor.visitFunctionExpr(this, context);
  14078. }
  14079. /**
  14080. * @param {?} name
  14081. * @param {?=} modifiers
  14082. * @return {?}
  14083. */
  14084. toDeclStmt(name, modifiers = null) {
  14085. return new DeclareFunctionStmt(name, this.params, this.statements, this.type, modifiers, this.sourceSpan);
  14086. }
  14087. }
  14088. class BinaryOperatorExpr extends Expression {
  14089. /**
  14090. * @param {?} operator
  14091. * @param {?} lhs
  14092. * @param {?} rhs
  14093. * @param {?=} type
  14094. * @param {?=} sourceSpan
  14095. */
  14096. constructor(operator, lhs, rhs, type, sourceSpan) {
  14097. super(type || lhs.type, sourceSpan);
  14098. this.operator = operator;
  14099. this.rhs = rhs;
  14100. this.lhs = lhs;
  14101. }
  14102. /**
  14103. * @param {?} e
  14104. * @return {?}
  14105. */
  14106. isEquivalent(e) {
  14107. return e instanceof BinaryOperatorExpr && this.operator === e.operator &&
  14108. this.lhs.isEquivalent(e.lhs) && this.rhs.isEquivalent(e.rhs);
  14109. }
  14110. /**
  14111. * @param {?} visitor
  14112. * @param {?} context
  14113. * @return {?}
  14114. */
  14115. visitExpression(visitor, context) {
  14116. return visitor.visitBinaryOperatorExpr(this, context);
  14117. }
  14118. }
  14119. class ReadPropExpr extends Expression {
  14120. /**
  14121. * @param {?} receiver
  14122. * @param {?} name
  14123. * @param {?=} type
  14124. * @param {?=} sourceSpan
  14125. */
  14126. constructor(receiver, name, type, sourceSpan) {
  14127. super(type, sourceSpan);
  14128. this.receiver = receiver;
  14129. this.name = name;
  14130. }
  14131. /**
  14132. * @param {?} e
  14133. * @return {?}
  14134. */
  14135. isEquivalent(e) {
  14136. return e instanceof ReadPropExpr && this.receiver.isEquivalent(e.receiver) &&
  14137. this.name === e.name;
  14138. }
  14139. /**
  14140. * @param {?} visitor
  14141. * @param {?} context
  14142. * @return {?}
  14143. */
  14144. visitExpression(visitor, context) {
  14145. return visitor.visitReadPropExpr(this, context);
  14146. }
  14147. /**
  14148. * @param {?} value
  14149. * @return {?}
  14150. */
  14151. set(value) {
  14152. return new WritePropExpr(this.receiver, this.name, value, null, this.sourceSpan);
  14153. }
  14154. }
  14155. class ReadKeyExpr extends Expression {
  14156. /**
  14157. * @param {?} receiver
  14158. * @param {?} index
  14159. * @param {?=} type
  14160. * @param {?=} sourceSpan
  14161. */
  14162. constructor(receiver, index, type, sourceSpan) {
  14163. super(type, sourceSpan);
  14164. this.receiver = receiver;
  14165. this.index = index;
  14166. }
  14167. /**
  14168. * @param {?} e
  14169. * @return {?}
  14170. */
  14171. isEquivalent(e) {
  14172. return e instanceof ReadKeyExpr && this.receiver.isEquivalent(e.receiver) &&
  14173. this.index.isEquivalent(e.index);
  14174. }
  14175. /**
  14176. * @param {?} visitor
  14177. * @param {?} context
  14178. * @return {?}
  14179. */
  14180. visitExpression(visitor, context) {
  14181. return visitor.visitReadKeyExpr(this, context);
  14182. }
  14183. /**
  14184. * @param {?} value
  14185. * @return {?}
  14186. */
  14187. set(value) {
  14188. return new WriteKeyExpr(this.receiver, this.index, value, null, this.sourceSpan);
  14189. }
  14190. }
  14191. class LiteralArrayExpr extends Expression {
  14192. /**
  14193. * @param {?} entries
  14194. * @param {?=} type
  14195. * @param {?=} sourceSpan
  14196. */
  14197. constructor(entries, type, sourceSpan) {
  14198. super(type, sourceSpan);
  14199. this.entries = entries;
  14200. }
  14201. /**
  14202. * @param {?} e
  14203. * @return {?}
  14204. */
  14205. isEquivalent(e) {
  14206. return e instanceof LiteralArrayExpr && areAllEquivalent(this.entries, e.entries);
  14207. }
  14208. /**
  14209. * @param {?} visitor
  14210. * @param {?} context
  14211. * @return {?}
  14212. */
  14213. visitExpression(visitor, context) {
  14214. return visitor.visitLiteralArrayExpr(this, context);
  14215. }
  14216. }
  14217. class LiteralMapEntry {
  14218. /**
  14219. * @param {?} key
  14220. * @param {?} value
  14221. * @param {?} quoted
  14222. */
  14223. constructor(key, value, quoted) {
  14224. this.key = key;
  14225. this.value = value;
  14226. this.quoted = quoted;
  14227. }
  14228. /**
  14229. * @param {?} e
  14230. * @return {?}
  14231. */
  14232. isEquivalent(e) {
  14233. return this.key === e.key && this.value.isEquivalent(e.value);
  14234. }
  14235. }
  14236. class LiteralMapExpr extends Expression {
  14237. /**
  14238. * @param {?} entries
  14239. * @param {?=} type
  14240. * @param {?=} sourceSpan
  14241. */
  14242. constructor(entries, type, sourceSpan) {
  14243. super(type, sourceSpan);
  14244. this.entries = entries;
  14245. this.valueType = null;
  14246. if (type) {
  14247. this.valueType = type.valueType;
  14248. }
  14249. }
  14250. /**
  14251. * @param {?} e
  14252. * @return {?}
  14253. */
  14254. isEquivalent(e) {
  14255. return e instanceof LiteralMapExpr && areAllEquivalent(this.entries, e.entries);
  14256. }
  14257. /**
  14258. * @param {?} visitor
  14259. * @param {?} context
  14260. * @return {?}
  14261. */
  14262. visitExpression(visitor, context) {
  14263. return visitor.visitLiteralMapExpr(this, context);
  14264. }
  14265. }
  14266. class CommaExpr extends Expression {
  14267. /**
  14268. * @param {?} parts
  14269. * @param {?=} sourceSpan
  14270. */
  14271. constructor(parts, sourceSpan) {
  14272. super(parts[parts.length - 1].type, sourceSpan);
  14273. this.parts = parts;
  14274. }
  14275. /**
  14276. * @param {?} e
  14277. * @return {?}
  14278. */
  14279. isEquivalent(e) {
  14280. return e instanceof CommaExpr && areAllEquivalent(this.parts, e.parts);
  14281. }
  14282. /**
  14283. * @param {?} visitor
  14284. * @param {?} context
  14285. * @return {?}
  14286. */
  14287. visitExpression(visitor, context) {
  14288. return visitor.visitCommaExpr(this, context);
  14289. }
  14290. }
  14291. /**
  14292. * @record
  14293. */
  14294. const THIS_EXPR = new ReadVarExpr(BuiltinVar.This, null, null);
  14295. const SUPER_EXPR = new ReadVarExpr(BuiltinVar.Super, null, null);
  14296. const CATCH_ERROR_VAR = new ReadVarExpr(BuiltinVar.CatchError, null, null);
  14297. const CATCH_STACK_VAR = new ReadVarExpr(BuiltinVar.CatchStack, null, null);
  14298. const NULL_EXPR = new LiteralExpr(null, null, null);
  14299. const TYPED_NULL_EXPR = new LiteralExpr(null, INFERRED_TYPE, null);
  14300. /** @enum {number} */
  14301. const StmtModifier = {
  14302. Final: 0,
  14303. Private: 1,
  14304. Exported: 2,
  14305. };
  14306. StmtModifier[StmtModifier.Final] = "Final";
  14307. StmtModifier[StmtModifier.Private] = "Private";
  14308. StmtModifier[StmtModifier.Exported] = "Exported";
  14309. /**
  14310. * @abstract
  14311. */
  14312. class Statement {
  14313. /**
  14314. * @param {?=} modifiers
  14315. * @param {?=} sourceSpan
  14316. */
  14317. constructor(modifiers, sourceSpan) {
  14318. this.modifiers = modifiers || [];
  14319. this.sourceSpan = sourceSpan || null;
  14320. }
  14321. /**
  14322. * @param {?} modifier
  14323. * @return {?}
  14324. */
  14325. hasModifier(modifier) { return /** @type {?} */ ((this.modifiers)).indexOf(modifier) !== -1; }
  14326. }
  14327. class DeclareVarStmt extends Statement {
  14328. /**
  14329. * @param {?} name
  14330. * @param {?} value
  14331. * @param {?=} type
  14332. * @param {?=} modifiers
  14333. * @param {?=} sourceSpan
  14334. */
  14335. constructor(name, value, type, modifiers = null, sourceSpan) {
  14336. super(modifiers, sourceSpan);
  14337. this.name = name;
  14338. this.value = value;
  14339. this.type = type || value.type;
  14340. }
  14341. /**
  14342. * @param {?} stmt
  14343. * @return {?}
  14344. */
  14345. isEquivalent(stmt) {
  14346. return stmt instanceof DeclareVarStmt && this.name === stmt.name &&
  14347. this.value.isEquivalent(stmt.value);
  14348. }
  14349. /**
  14350. * @param {?} visitor
  14351. * @param {?} context
  14352. * @return {?}
  14353. */
  14354. visitStatement(visitor, context) {
  14355. return visitor.visitDeclareVarStmt(this, context);
  14356. }
  14357. }
  14358. class DeclareFunctionStmt extends Statement {
  14359. /**
  14360. * @param {?} name
  14361. * @param {?} params
  14362. * @param {?} statements
  14363. * @param {?=} type
  14364. * @param {?=} modifiers
  14365. * @param {?=} sourceSpan
  14366. */
  14367. constructor(name, params, statements, type, modifiers = null, sourceSpan) {
  14368. super(modifiers, sourceSpan);
  14369. this.name = name;
  14370. this.params = params;
  14371. this.statements = statements;
  14372. this.type = type || null;
  14373. }
  14374. /**
  14375. * @param {?} stmt
  14376. * @return {?}
  14377. */
  14378. isEquivalent(stmt) {
  14379. return stmt instanceof DeclareFunctionStmt && areAllEquivalent(this.params, stmt.params) &&
  14380. areAllEquivalent(this.statements, stmt.statements);
  14381. }
  14382. /**
  14383. * @param {?} visitor
  14384. * @param {?} context
  14385. * @return {?}
  14386. */
  14387. visitStatement(visitor, context) {
  14388. return visitor.visitDeclareFunctionStmt(this, context);
  14389. }
  14390. }
  14391. class ExpressionStatement extends Statement {
  14392. /**
  14393. * @param {?} expr
  14394. * @param {?=} sourceSpan
  14395. */
  14396. constructor(expr, sourceSpan) {
  14397. super(null, sourceSpan);
  14398. this.expr = expr;
  14399. }
  14400. /**
  14401. * @param {?} stmt
  14402. * @return {?}
  14403. */
  14404. isEquivalent(stmt) {
  14405. return stmt instanceof ExpressionStatement && this.expr.isEquivalent(stmt.expr);
  14406. }
  14407. /**
  14408. * @param {?} visitor
  14409. * @param {?} context
  14410. * @return {?}
  14411. */
  14412. visitStatement(visitor, context) {
  14413. return visitor.visitExpressionStmt(this, context);
  14414. }
  14415. }
  14416. class ReturnStatement extends Statement {
  14417. /**
  14418. * @param {?} value
  14419. * @param {?=} sourceSpan
  14420. */
  14421. constructor(value, sourceSpan) {
  14422. super(null, sourceSpan);
  14423. this.value = value;
  14424. }
  14425. /**
  14426. * @param {?} stmt
  14427. * @return {?}
  14428. */
  14429. isEquivalent(stmt) {
  14430. return stmt instanceof ReturnStatement && this.value.isEquivalent(stmt.value);
  14431. }
  14432. /**
  14433. * @param {?} visitor
  14434. * @param {?} context
  14435. * @return {?}
  14436. */
  14437. visitStatement(visitor, context) {
  14438. return visitor.visitReturnStmt(this, context);
  14439. }
  14440. }
  14441. class AbstractClassPart {
  14442. /**
  14443. * @param {?} type
  14444. * @param {?} modifiers
  14445. */
  14446. constructor(type, modifiers) {
  14447. this.modifiers = modifiers;
  14448. if (!modifiers) {
  14449. this.modifiers = [];
  14450. }
  14451. this.type = type || null;
  14452. }
  14453. /**
  14454. * @param {?} modifier
  14455. * @return {?}
  14456. */
  14457. hasModifier(modifier) { return /** @type {?} */ ((this.modifiers)).indexOf(modifier) !== -1; }
  14458. }
  14459. class ClassMethod extends AbstractClassPart {
  14460. /**
  14461. * @param {?} name
  14462. * @param {?} params
  14463. * @param {?} body
  14464. * @param {?=} type
  14465. * @param {?=} modifiers
  14466. */
  14467. constructor(name, params, body, type, modifiers = null) {
  14468. super(type, modifiers);
  14469. this.name = name;
  14470. this.params = params;
  14471. this.body = body;
  14472. }
  14473. /**
  14474. * @param {?} m
  14475. * @return {?}
  14476. */
  14477. isEquivalent(m) {
  14478. return this.name === m.name && areAllEquivalent(this.body, m.body);
  14479. }
  14480. }
  14481. class ClassGetter extends AbstractClassPart {
  14482. /**
  14483. * @param {?} name
  14484. * @param {?} body
  14485. * @param {?=} type
  14486. * @param {?=} modifiers
  14487. */
  14488. constructor(name, body, type, modifiers = null) {
  14489. super(type, modifiers);
  14490. this.name = name;
  14491. this.body = body;
  14492. }
  14493. /**
  14494. * @param {?} m
  14495. * @return {?}
  14496. */
  14497. isEquivalent(m) {
  14498. return this.name === m.name && areAllEquivalent(this.body, m.body);
  14499. }
  14500. }
  14501. class ClassStmt extends Statement {
  14502. /**
  14503. * @param {?} name
  14504. * @param {?} parent
  14505. * @param {?} fields
  14506. * @param {?} getters
  14507. * @param {?} constructorMethod
  14508. * @param {?} methods
  14509. * @param {?=} modifiers
  14510. * @param {?=} sourceSpan
  14511. */
  14512. constructor(name, parent, fields, getters, constructorMethod, methods, modifiers = null, sourceSpan) {
  14513. super(modifiers, sourceSpan);
  14514. this.name = name;
  14515. this.parent = parent;
  14516. this.fields = fields;
  14517. this.getters = getters;
  14518. this.constructorMethod = constructorMethod;
  14519. this.methods = methods;
  14520. }
  14521. /**
  14522. * @param {?} stmt
  14523. * @return {?}
  14524. */
  14525. isEquivalent(stmt) {
  14526. return stmt instanceof ClassStmt && this.name === stmt.name &&
  14527. nullSafeIsEquivalent(this.parent, stmt.parent) &&
  14528. areAllEquivalent(this.fields, stmt.fields) &&
  14529. areAllEquivalent(this.getters, stmt.getters) &&
  14530. this.constructorMethod.isEquivalent(stmt.constructorMethod) &&
  14531. areAllEquivalent(this.methods, stmt.methods);
  14532. }
  14533. /**
  14534. * @param {?} visitor
  14535. * @param {?} context
  14536. * @return {?}
  14537. */
  14538. visitStatement(visitor, context) {
  14539. return visitor.visitDeclareClassStmt(this, context);
  14540. }
  14541. }
  14542. class IfStmt extends Statement {
  14543. /**
  14544. * @param {?} condition
  14545. * @param {?} trueCase
  14546. * @param {?=} falseCase
  14547. * @param {?=} sourceSpan
  14548. */
  14549. constructor(condition, trueCase, falseCase = [], sourceSpan) {
  14550. super(null, sourceSpan);
  14551. this.condition = condition;
  14552. this.trueCase = trueCase;
  14553. this.falseCase = falseCase;
  14554. }
  14555. /**
  14556. * @param {?} stmt
  14557. * @return {?}
  14558. */
  14559. isEquivalent(stmt) {
  14560. return stmt instanceof IfStmt && this.condition.isEquivalent(stmt.condition) &&
  14561. areAllEquivalent(this.trueCase, stmt.trueCase) &&
  14562. areAllEquivalent(this.falseCase, stmt.falseCase);
  14563. }
  14564. /**
  14565. * @param {?} visitor
  14566. * @param {?} context
  14567. * @return {?}
  14568. */
  14569. visitStatement(visitor, context) {
  14570. return visitor.visitIfStmt(this, context);
  14571. }
  14572. }
  14573. class CommentStmt extends Statement {
  14574. /**
  14575. * @param {?} comment
  14576. * @param {?=} sourceSpan
  14577. */
  14578. constructor(comment, sourceSpan) {
  14579. super(null, sourceSpan);
  14580. this.comment = comment;
  14581. }
  14582. /**
  14583. * @param {?} stmt
  14584. * @return {?}
  14585. */
  14586. isEquivalent(stmt) { return stmt instanceof CommentStmt; }
  14587. /**
  14588. * @param {?} visitor
  14589. * @param {?} context
  14590. * @return {?}
  14591. */
  14592. visitStatement(visitor, context) {
  14593. return visitor.visitCommentStmt(this, context);
  14594. }
  14595. }
  14596. class TryCatchStmt extends Statement {
  14597. /**
  14598. * @param {?} bodyStmts
  14599. * @param {?} catchStmts
  14600. * @param {?=} sourceSpan
  14601. */
  14602. constructor(bodyStmts, catchStmts, sourceSpan) {
  14603. super(null, sourceSpan);
  14604. this.bodyStmts = bodyStmts;
  14605. this.catchStmts = catchStmts;
  14606. }
  14607. /**
  14608. * @param {?} stmt
  14609. * @return {?}
  14610. */
  14611. isEquivalent(stmt) {
  14612. return stmt instanceof TryCatchStmt && areAllEquivalent(this.bodyStmts, stmt.bodyStmts) &&
  14613. areAllEquivalent(this.catchStmts, stmt.catchStmts);
  14614. }
  14615. /**
  14616. * @param {?} visitor
  14617. * @param {?} context
  14618. * @return {?}
  14619. */
  14620. visitStatement(visitor, context) {
  14621. return visitor.visitTryCatchStmt(this, context);
  14622. }
  14623. }
  14624. class ThrowStmt extends Statement {
  14625. /**
  14626. * @param {?} error
  14627. * @param {?=} sourceSpan
  14628. */
  14629. constructor(error, sourceSpan) {
  14630. super(null, sourceSpan);
  14631. this.error = error;
  14632. }
  14633. /**
  14634. * @param {?} stmt
  14635. * @return {?}
  14636. */
  14637. isEquivalent(stmt) {
  14638. return stmt instanceof TryCatchStmt && this.error.isEquivalent(stmt.error);
  14639. }
  14640. /**
  14641. * @param {?} visitor
  14642. * @param {?} context
  14643. * @return {?}
  14644. */
  14645. visitStatement(visitor, context) {
  14646. return visitor.visitThrowStmt(this, context);
  14647. }
  14648. }
  14649. /**
  14650. * @record
  14651. */
  14652. class AstTransformer$1 {
  14653. /**
  14654. * @param {?} expr
  14655. * @param {?} context
  14656. * @return {?}
  14657. */
  14658. transformExpr(expr, context) { return expr; }
  14659. /**
  14660. * @param {?} stmt
  14661. * @param {?} context
  14662. * @return {?}
  14663. */
  14664. transformStmt(stmt, context) { return stmt; }
  14665. /**
  14666. * @param {?} ast
  14667. * @param {?} context
  14668. * @return {?}
  14669. */
  14670. visitReadVarExpr(ast, context) { return this.transformExpr(ast, context); }
  14671. /**
  14672. * @param {?} expr
  14673. * @param {?} context
  14674. * @return {?}
  14675. */
  14676. visitWriteVarExpr(expr, context) {
  14677. return this.transformExpr(new WriteVarExpr(expr.name, expr.value.visitExpression(this, context), expr.type, expr.sourceSpan), context);
  14678. }
  14679. /**
  14680. * @param {?} expr
  14681. * @param {?} context
  14682. * @return {?}
  14683. */
  14684. visitWriteKeyExpr(expr, context) {
  14685. return this.transformExpr(new WriteKeyExpr(expr.receiver.visitExpression(this, context), expr.index.visitExpression(this, context), expr.value.visitExpression(this, context), expr.type, expr.sourceSpan), context);
  14686. }
  14687. /**
  14688. * @param {?} expr
  14689. * @param {?} context
  14690. * @return {?}
  14691. */
  14692. visitWritePropExpr(expr, context) {
  14693. return this.transformExpr(new WritePropExpr(expr.receiver.visitExpression(this, context), expr.name, expr.value.visitExpression(this, context), expr.type, expr.sourceSpan), context);
  14694. }
  14695. /**
  14696. * @param {?} ast
  14697. * @param {?} context
  14698. * @return {?}
  14699. */
  14700. visitInvokeMethodExpr(ast, context) {
  14701. const /** @type {?} */ method = ast.builtin || ast.name;
  14702. return this.transformExpr(new InvokeMethodExpr(ast.receiver.visitExpression(this, context), /** @type {?} */ ((method)), this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan), context);
  14703. }
  14704. /**
  14705. * @param {?} ast
  14706. * @param {?} context
  14707. * @return {?}
  14708. */
  14709. visitInvokeFunctionExpr(ast, context) {
  14710. return this.transformExpr(new InvokeFunctionExpr(ast.fn.visitExpression(this, context), this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan), context);
  14711. }
  14712. /**
  14713. * @param {?} ast
  14714. * @param {?} context
  14715. * @return {?}
  14716. */
  14717. visitInstantiateExpr(ast, context) {
  14718. return this.transformExpr(new InstantiateExpr(ast.classExpr.visitExpression(this, context), this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan), context);
  14719. }
  14720. /**
  14721. * @param {?} ast
  14722. * @param {?} context
  14723. * @return {?}
  14724. */
  14725. visitLiteralExpr(ast, context) { return this.transformExpr(ast, context); }
  14726. /**
  14727. * @param {?} ast
  14728. * @param {?} context
  14729. * @return {?}
  14730. */
  14731. visitExternalExpr(ast, context) {
  14732. return this.transformExpr(ast, context);
  14733. }
  14734. /**
  14735. * @param {?} ast
  14736. * @param {?} context
  14737. * @return {?}
  14738. */
  14739. visitConditionalExpr(ast, context) {
  14740. return this.transformExpr(new ConditionalExpr(ast.condition.visitExpression(this, context), ast.trueCase.visitExpression(this, context), /** @type {?} */ ((ast.falseCase)).visitExpression(this, context), ast.type, ast.sourceSpan), context);
  14741. }
  14742. /**
  14743. * @param {?} ast
  14744. * @param {?} context
  14745. * @return {?}
  14746. */
  14747. visitNotExpr(ast, context) {
  14748. return this.transformExpr(new NotExpr(ast.condition.visitExpression(this, context), ast.sourceSpan), context);
  14749. }
  14750. /**
  14751. * @param {?} ast
  14752. * @param {?} context
  14753. * @return {?}
  14754. */
  14755. visitAssertNotNullExpr(ast, context) {
  14756. return this.transformExpr(new AssertNotNull(ast.condition.visitExpression(this, context), ast.sourceSpan), context);
  14757. }
  14758. /**
  14759. * @param {?} ast
  14760. * @param {?} context
  14761. * @return {?}
  14762. */
  14763. visitCastExpr(ast, context) {
  14764. return this.transformExpr(new CastExpr(ast.value.visitExpression(this, context), ast.type, ast.sourceSpan), context);
  14765. }
  14766. /**
  14767. * @param {?} ast
  14768. * @param {?} context
  14769. * @return {?}
  14770. */
  14771. visitFunctionExpr(ast, context) {
  14772. return this.transformExpr(new FunctionExpr(ast.params, this.visitAllStatements(ast.statements, context), ast.type, ast.sourceSpan), context);
  14773. }
  14774. /**
  14775. * @param {?} ast
  14776. * @param {?} context
  14777. * @return {?}
  14778. */
  14779. visitBinaryOperatorExpr(ast, context) {
  14780. return this.transformExpr(new BinaryOperatorExpr(ast.operator, ast.lhs.visitExpression(this, context), ast.rhs.visitExpression(this, context), ast.type, ast.sourceSpan), context);
  14781. }
  14782. /**
  14783. * @param {?} ast
  14784. * @param {?} context
  14785. * @return {?}
  14786. */
  14787. visitReadPropExpr(ast, context) {
  14788. return this.transformExpr(new ReadPropExpr(ast.receiver.visitExpression(this, context), ast.name, ast.type, ast.sourceSpan), context);
  14789. }
  14790. /**
  14791. * @param {?} ast
  14792. * @param {?} context
  14793. * @return {?}
  14794. */
  14795. visitReadKeyExpr(ast, context) {
  14796. return this.transformExpr(new ReadKeyExpr(ast.receiver.visitExpression(this, context), ast.index.visitExpression(this, context), ast.type, ast.sourceSpan), context);
  14797. }
  14798. /**
  14799. * @param {?} ast
  14800. * @param {?} context
  14801. * @return {?}
  14802. */
  14803. visitLiteralArrayExpr(ast, context) {
  14804. return this.transformExpr(new LiteralArrayExpr(this.visitAllExpressions(ast.entries, context), ast.type, ast.sourceSpan), context);
  14805. }
  14806. /**
  14807. * @param {?} ast
  14808. * @param {?} context
  14809. * @return {?}
  14810. */
  14811. visitLiteralMapExpr(ast, context) {
  14812. const /** @type {?} */ entries = ast.entries.map((entry) => new LiteralMapEntry(entry.key, entry.value.visitExpression(this, context), entry.quoted));
  14813. const /** @type {?} */ mapType = new MapType(ast.valueType, null);
  14814. return this.transformExpr(new LiteralMapExpr(entries, mapType, ast.sourceSpan), context);
  14815. }
  14816. /**
  14817. * @param {?} ast
  14818. * @param {?} context
  14819. * @return {?}
  14820. */
  14821. visitCommaExpr(ast, context) {
  14822. return this.transformExpr(new CommaExpr(this.visitAllExpressions(ast.parts, context), ast.sourceSpan), context);
  14823. }
  14824. /**
  14825. * @param {?} exprs
  14826. * @param {?} context
  14827. * @return {?}
  14828. */
  14829. visitAllExpressions(exprs, context) {
  14830. return exprs.map(expr => expr.visitExpression(this, context));
  14831. }
  14832. /**
  14833. * @param {?} stmt
  14834. * @param {?} context
  14835. * @return {?}
  14836. */
  14837. visitDeclareVarStmt(stmt, context) {
  14838. return this.transformStmt(new DeclareVarStmt(stmt.name, stmt.value.visitExpression(this, context), stmt.type, stmt.modifiers, stmt.sourceSpan), context);
  14839. }
  14840. /**
  14841. * @param {?} stmt
  14842. * @param {?} context
  14843. * @return {?}
  14844. */
  14845. visitDeclareFunctionStmt(stmt, context) {
  14846. return this.transformStmt(new DeclareFunctionStmt(stmt.name, stmt.params, this.visitAllStatements(stmt.statements, context), stmt.type, stmt.modifiers, stmt.sourceSpan), context);
  14847. }
  14848. /**
  14849. * @param {?} stmt
  14850. * @param {?} context
  14851. * @return {?}
  14852. */
  14853. visitExpressionStmt(stmt, context) {
  14854. return this.transformStmt(new ExpressionStatement(stmt.expr.visitExpression(this, context), stmt.sourceSpan), context);
  14855. }
  14856. /**
  14857. * @param {?} stmt
  14858. * @param {?} context
  14859. * @return {?}
  14860. */
  14861. visitReturnStmt(stmt, context) {
  14862. return this.transformStmt(new ReturnStatement(stmt.value.visitExpression(this, context), stmt.sourceSpan), context);
  14863. }
  14864. /**
  14865. * @param {?} stmt
  14866. * @param {?} context
  14867. * @return {?}
  14868. */
  14869. visitDeclareClassStmt(stmt, context) {
  14870. const /** @type {?} */ parent = /** @type {?} */ ((stmt.parent)).visitExpression(this, context);
  14871. const /** @type {?} */ getters = stmt.getters.map(getter => new ClassGetter(getter.name, this.visitAllStatements(getter.body, context), getter.type, getter.modifiers));
  14872. const /** @type {?} */ ctorMethod = stmt.constructorMethod &&
  14873. new ClassMethod(stmt.constructorMethod.name, stmt.constructorMethod.params, this.visitAllStatements(stmt.constructorMethod.body, context), stmt.constructorMethod.type, stmt.constructorMethod.modifiers);
  14874. const /** @type {?} */ methods = stmt.methods.map(method => new ClassMethod(method.name, method.params, this.visitAllStatements(method.body, context), method.type, method.modifiers));
  14875. return this.transformStmt(new ClassStmt(stmt.name, parent, stmt.fields, getters, ctorMethod, methods, stmt.modifiers, stmt.sourceSpan), context);
  14876. }
  14877. /**
  14878. * @param {?} stmt
  14879. * @param {?} context
  14880. * @return {?}
  14881. */
  14882. visitIfStmt(stmt, context) {
  14883. return this.transformStmt(new IfStmt(stmt.condition.visitExpression(this, context), this.visitAllStatements(stmt.trueCase, context), this.visitAllStatements(stmt.falseCase, context), stmt.sourceSpan), context);
  14884. }
  14885. /**
  14886. * @param {?} stmt
  14887. * @param {?} context
  14888. * @return {?}
  14889. */
  14890. visitTryCatchStmt(stmt, context) {
  14891. return this.transformStmt(new TryCatchStmt(this.visitAllStatements(stmt.bodyStmts, context), this.visitAllStatements(stmt.catchStmts, context), stmt.sourceSpan), context);
  14892. }
  14893. /**
  14894. * @param {?} stmt
  14895. * @param {?} context
  14896. * @return {?}
  14897. */
  14898. visitThrowStmt(stmt, context) {
  14899. return this.transformStmt(new ThrowStmt(stmt.error.visitExpression(this, context), stmt.sourceSpan), context);
  14900. }
  14901. /**
  14902. * @param {?} stmt
  14903. * @param {?} context
  14904. * @return {?}
  14905. */
  14906. visitCommentStmt(stmt, context) {
  14907. return this.transformStmt(stmt, context);
  14908. }
  14909. /**
  14910. * @param {?} stmts
  14911. * @param {?} context
  14912. * @return {?}
  14913. */
  14914. visitAllStatements(stmts, context) {
  14915. return stmts.map(stmt => stmt.visitStatement(this, context));
  14916. }
  14917. }
  14918. class RecursiveAstVisitor$1 {
  14919. /**
  14920. * @param {?} ast
  14921. * @param {?} context
  14922. * @return {?}
  14923. */
  14924. visitType(ast, context) { return ast; }
  14925. /**
  14926. * @param {?} ast
  14927. * @param {?} context
  14928. * @return {?}
  14929. */
  14930. visitExpression(ast, context) {
  14931. if (ast.type) {
  14932. ast.type.visitType(this, context);
  14933. }
  14934. return ast;
  14935. }
  14936. /**
  14937. * @param {?} type
  14938. * @param {?} context
  14939. * @return {?}
  14940. */
  14941. visitBuiltintType(type, context) { return this.visitType(type, context); }
  14942. /**
  14943. * @param {?} type
  14944. * @param {?} context
  14945. * @return {?}
  14946. */
  14947. visitExpressionType(type, context) {
  14948. type.value.visitExpression(this, context);
  14949. return this.visitType(type, context);
  14950. }
  14951. /**
  14952. * @param {?} type
  14953. * @param {?} context
  14954. * @return {?}
  14955. */
  14956. visitArrayType(type, context) { return this.visitType(type, context); }
  14957. /**
  14958. * @param {?} type
  14959. * @param {?} context
  14960. * @return {?}
  14961. */
  14962. visitMapType(type, context) { return this.visitType(type, context); }
  14963. /**
  14964. * @param {?} ast
  14965. * @param {?} context
  14966. * @return {?}
  14967. */
  14968. visitReadVarExpr(ast, context) {
  14969. return this.visitExpression(ast, context);
  14970. }
  14971. /**
  14972. * @param {?} ast
  14973. * @param {?} context
  14974. * @return {?}
  14975. */
  14976. visitWriteVarExpr(ast, context) {
  14977. ast.value.visitExpression(this, context);
  14978. return this.visitExpression(ast, context);
  14979. }
  14980. /**
  14981. * @param {?} ast
  14982. * @param {?} context
  14983. * @return {?}
  14984. */
  14985. visitWriteKeyExpr(ast, context) {
  14986. ast.receiver.visitExpression(this, context);
  14987. ast.index.visitExpression(this, context);
  14988. ast.value.visitExpression(this, context);
  14989. return this.visitExpression(ast, context);
  14990. }
  14991. /**
  14992. * @param {?} ast
  14993. * @param {?} context
  14994. * @return {?}
  14995. */
  14996. visitWritePropExpr(ast, context) {
  14997. ast.receiver.visitExpression(this, context);
  14998. ast.value.visitExpression(this, context);
  14999. return this.visitExpression(ast, context);
  15000. }
  15001. /**
  15002. * @param {?} ast
  15003. * @param {?} context
  15004. * @return {?}
  15005. */
  15006. visitInvokeMethodExpr(ast, context) {
  15007. ast.receiver.visitExpression(this, context);
  15008. this.visitAllExpressions(ast.args, context);
  15009. return this.visitExpression(ast, context);
  15010. }
  15011. /**
  15012. * @param {?} ast
  15013. * @param {?} context
  15014. * @return {?}
  15015. */
  15016. visitInvokeFunctionExpr(ast, context) {
  15017. ast.fn.visitExpression(this, context);
  15018. this.visitAllExpressions(ast.args, context);
  15019. return this.visitExpression(ast, context);
  15020. }
  15021. /**
  15022. * @param {?} ast
  15023. * @param {?} context
  15024. * @return {?}
  15025. */
  15026. visitInstantiateExpr(ast, context) {
  15027. ast.classExpr.visitExpression(this, context);
  15028. this.visitAllExpressions(ast.args, context);
  15029. return this.visitExpression(ast, context);
  15030. }
  15031. /**
  15032. * @param {?} ast
  15033. * @param {?} context
  15034. * @return {?}
  15035. */
  15036. visitLiteralExpr(ast, context) {
  15037. return this.visitExpression(ast, context);
  15038. }
  15039. /**
  15040. * @param {?} ast
  15041. * @param {?} context
  15042. * @return {?}
  15043. */
  15044. visitExternalExpr(ast, context) {
  15045. if (ast.typeParams) {
  15046. ast.typeParams.forEach(type => type.visitType(this, context));
  15047. }
  15048. return this.visitExpression(ast, context);
  15049. }
  15050. /**
  15051. * @param {?} ast
  15052. * @param {?} context
  15053. * @return {?}
  15054. */
  15055. visitConditionalExpr(ast, context) {
  15056. ast.condition.visitExpression(this, context);
  15057. ast.trueCase.visitExpression(this, context); /** @type {?} */
  15058. ((ast.falseCase)).visitExpression(this, context);
  15059. return this.visitExpression(ast, context);
  15060. }
  15061. /**
  15062. * @param {?} ast
  15063. * @param {?} context
  15064. * @return {?}
  15065. */
  15066. visitNotExpr(ast, context) {
  15067. ast.condition.visitExpression(this, context);
  15068. return this.visitExpression(ast, context);
  15069. }
  15070. /**
  15071. * @param {?} ast
  15072. * @param {?} context
  15073. * @return {?}
  15074. */
  15075. visitAssertNotNullExpr(ast, context) {
  15076. ast.condition.visitExpression(this, context);
  15077. return this.visitExpression(ast, context);
  15078. }
  15079. /**
  15080. * @param {?} ast
  15081. * @param {?} context
  15082. * @return {?}
  15083. */
  15084. visitCastExpr(ast, context) {
  15085. ast.value.visitExpression(this, context);
  15086. return this.visitExpression(ast, context);
  15087. }
  15088. /**
  15089. * @param {?} ast
  15090. * @param {?} context
  15091. * @return {?}
  15092. */
  15093. visitFunctionExpr(ast, context) {
  15094. this.visitAllStatements(ast.statements, context);
  15095. return this.visitExpression(ast, context);
  15096. }
  15097. /**
  15098. * @param {?} ast
  15099. * @param {?} context
  15100. * @return {?}
  15101. */
  15102. visitBinaryOperatorExpr(ast, context) {
  15103. ast.lhs.visitExpression(this, context);
  15104. ast.rhs.visitExpression(this, context);
  15105. return this.visitExpression(ast, context);
  15106. }
  15107. /**
  15108. * @param {?} ast
  15109. * @param {?} context
  15110. * @return {?}
  15111. */
  15112. visitReadPropExpr(ast, context) {
  15113. ast.receiver.visitExpression(this, context);
  15114. return this.visitExpression(ast, context);
  15115. }
  15116. /**
  15117. * @param {?} ast
  15118. * @param {?} context
  15119. * @return {?}
  15120. */
  15121. visitReadKeyExpr(ast, context) {
  15122. ast.receiver.visitExpression(this, context);
  15123. ast.index.visitExpression(this, context);
  15124. return this.visitExpression(ast, context);
  15125. }
  15126. /**
  15127. * @param {?} ast
  15128. * @param {?} context
  15129. * @return {?}
  15130. */
  15131. visitLiteralArrayExpr(ast, context) {
  15132. this.visitAllExpressions(ast.entries, context);
  15133. return this.visitExpression(ast, context);
  15134. }
  15135. /**
  15136. * @param {?} ast
  15137. * @param {?} context
  15138. * @return {?}
  15139. */
  15140. visitLiteralMapExpr(ast, context) {
  15141. ast.entries.forEach((entry) => entry.value.visitExpression(this, context));
  15142. return this.visitExpression(ast, context);
  15143. }
  15144. /**
  15145. * @param {?} ast
  15146. * @param {?} context
  15147. * @return {?}
  15148. */
  15149. visitCommaExpr(ast, context) {
  15150. this.visitAllExpressions(ast.parts, context);
  15151. return this.visitExpression(ast, context);
  15152. }
  15153. /**
  15154. * @param {?} exprs
  15155. * @param {?} context
  15156. * @return {?}
  15157. */
  15158. visitAllExpressions(exprs, context) {
  15159. exprs.forEach(expr => expr.visitExpression(this, context));
  15160. }
  15161. /**
  15162. * @param {?} stmt
  15163. * @param {?} context
  15164. * @return {?}
  15165. */
  15166. visitDeclareVarStmt(stmt, context) {
  15167. stmt.value.visitExpression(this, context);
  15168. if (stmt.type) {
  15169. stmt.type.visitType(this, context);
  15170. }
  15171. return stmt;
  15172. }
  15173. /**
  15174. * @param {?} stmt
  15175. * @param {?} context
  15176. * @return {?}
  15177. */
  15178. visitDeclareFunctionStmt(stmt, context) {
  15179. this.visitAllStatements(stmt.statements, context);
  15180. if (stmt.type) {
  15181. stmt.type.visitType(this, context);
  15182. }
  15183. return stmt;
  15184. }
  15185. /**
  15186. * @param {?} stmt
  15187. * @param {?} context
  15188. * @return {?}
  15189. */
  15190. visitExpressionStmt(stmt, context) {
  15191. stmt.expr.visitExpression(this, context);
  15192. return stmt;
  15193. }
  15194. /**
  15195. * @param {?} stmt
  15196. * @param {?} context
  15197. * @return {?}
  15198. */
  15199. visitReturnStmt(stmt, context) {
  15200. stmt.value.visitExpression(this, context);
  15201. return stmt;
  15202. }
  15203. /**
  15204. * @param {?} stmt
  15205. * @param {?} context
  15206. * @return {?}
  15207. */
  15208. visitDeclareClassStmt(stmt, context) {
  15209. /** @type {?} */ ((stmt.parent)).visitExpression(this, context);
  15210. stmt.getters.forEach(getter => this.visitAllStatements(getter.body, context));
  15211. if (stmt.constructorMethod) {
  15212. this.visitAllStatements(stmt.constructorMethod.body, context);
  15213. }
  15214. stmt.methods.forEach(method => this.visitAllStatements(method.body, context));
  15215. return stmt;
  15216. }
  15217. /**
  15218. * @param {?} stmt
  15219. * @param {?} context
  15220. * @return {?}
  15221. */
  15222. visitIfStmt(stmt, context) {
  15223. stmt.condition.visitExpression(this, context);
  15224. this.visitAllStatements(stmt.trueCase, context);
  15225. this.visitAllStatements(stmt.falseCase, context);
  15226. return stmt;
  15227. }
  15228. /**
  15229. * @param {?} stmt
  15230. * @param {?} context
  15231. * @return {?}
  15232. */
  15233. visitTryCatchStmt(stmt, context) {
  15234. this.visitAllStatements(stmt.bodyStmts, context);
  15235. this.visitAllStatements(stmt.catchStmts, context);
  15236. return stmt;
  15237. }
  15238. /**
  15239. * @param {?} stmt
  15240. * @param {?} context
  15241. * @return {?}
  15242. */
  15243. visitThrowStmt(stmt, context) {
  15244. stmt.error.visitExpression(this, context);
  15245. return stmt;
  15246. }
  15247. /**
  15248. * @param {?} stmt
  15249. * @param {?} context
  15250. * @return {?}
  15251. */
  15252. visitCommentStmt(stmt, context) { return stmt; }
  15253. /**
  15254. * @param {?} stmts
  15255. * @param {?} context
  15256. * @return {?}
  15257. */
  15258. visitAllStatements(stmts, context) {
  15259. stmts.forEach(stmt => stmt.visitStatement(this, context));
  15260. }
  15261. }
  15262. /**
  15263. * @param {?} stmts
  15264. * @return {?}
  15265. */
  15266. function findReadVarNames(stmts) {
  15267. const /** @type {?} */ visitor = new _ReadVarVisitor();
  15268. visitor.visitAllStatements(stmts, null);
  15269. return visitor.varNames;
  15270. }
  15271. class _ReadVarVisitor extends RecursiveAstVisitor$1 {
  15272. constructor() {
  15273. super(...arguments);
  15274. this.varNames = new Set();
  15275. }
  15276. /**
  15277. * @param {?} stmt
  15278. * @param {?} context
  15279. * @return {?}
  15280. */
  15281. visitDeclareFunctionStmt(stmt, context) {
  15282. // Don't descend into nested functions
  15283. return stmt;
  15284. }
  15285. /**
  15286. * @param {?} stmt
  15287. * @param {?} context
  15288. * @return {?}
  15289. */
  15290. visitDeclareClassStmt(stmt, context) {
  15291. // Don't descend into nested classes
  15292. return stmt;
  15293. }
  15294. /**
  15295. * @param {?} ast
  15296. * @param {?} context
  15297. * @return {?}
  15298. */
  15299. visitReadVarExpr(ast, context) {
  15300. if (ast.name) {
  15301. this.varNames.add(ast.name);
  15302. }
  15303. return null;
  15304. }
  15305. }
  15306. /**
  15307. * @param {?} stmts
  15308. * @return {?}
  15309. */
  15310. function collectExternalReferences(stmts) {
  15311. const /** @type {?} */ visitor = new _FindExternalReferencesVisitor();
  15312. visitor.visitAllStatements(stmts, null);
  15313. return visitor.externalReferences;
  15314. }
  15315. class _FindExternalReferencesVisitor extends RecursiveAstVisitor$1 {
  15316. constructor() {
  15317. super(...arguments);
  15318. this.externalReferences = [];
  15319. }
  15320. /**
  15321. * @param {?} e
  15322. * @param {?} context
  15323. * @return {?}
  15324. */
  15325. visitExternalExpr(e, context) {
  15326. this.externalReferences.push(e.value);
  15327. return super.visitExternalExpr(e, context);
  15328. }
  15329. }
  15330. /**
  15331. * @param {?} stmt
  15332. * @param {?} sourceSpan
  15333. * @return {?}
  15334. */
  15335. function applySourceSpanToStatementIfNeeded(stmt, sourceSpan) {
  15336. if (!sourceSpan) {
  15337. return stmt;
  15338. }
  15339. const /** @type {?} */ transformer = new _ApplySourceSpanTransformer(sourceSpan);
  15340. return stmt.visitStatement(transformer, null);
  15341. }
  15342. /**
  15343. * @param {?} expr
  15344. * @param {?} sourceSpan
  15345. * @return {?}
  15346. */
  15347. function applySourceSpanToExpressionIfNeeded(expr, sourceSpan) {
  15348. if (!sourceSpan) {
  15349. return expr;
  15350. }
  15351. const /** @type {?} */ transformer = new _ApplySourceSpanTransformer(sourceSpan);
  15352. return expr.visitExpression(transformer, null);
  15353. }
  15354. class _ApplySourceSpanTransformer extends AstTransformer$1 {
  15355. /**
  15356. * @param {?} sourceSpan
  15357. */
  15358. constructor(sourceSpan) {
  15359. super();
  15360. this.sourceSpan = sourceSpan;
  15361. }
  15362. /**
  15363. * @param {?} obj
  15364. * @return {?}
  15365. */
  15366. _clone(obj) {
  15367. const /** @type {?} */ clone = Object.create(obj.constructor.prototype);
  15368. for (let /** @type {?} */ prop in obj) {
  15369. clone[prop] = obj[prop];
  15370. }
  15371. return clone;
  15372. }
  15373. /**
  15374. * @param {?} expr
  15375. * @param {?} context
  15376. * @return {?}
  15377. */
  15378. transformExpr(expr, context) {
  15379. if (!expr.sourceSpan) {
  15380. expr = this._clone(expr);
  15381. expr.sourceSpan = this.sourceSpan;
  15382. }
  15383. return expr;
  15384. }
  15385. /**
  15386. * @param {?} stmt
  15387. * @param {?} context
  15388. * @return {?}
  15389. */
  15390. transformStmt(stmt, context) {
  15391. if (!stmt.sourceSpan) {
  15392. stmt = this._clone(stmt);
  15393. stmt.sourceSpan = this.sourceSpan;
  15394. }
  15395. return stmt;
  15396. }
  15397. }
  15398. /**
  15399. * @param {?} name
  15400. * @param {?=} type
  15401. * @param {?=} sourceSpan
  15402. * @return {?}
  15403. */
  15404. function variable(name, type, sourceSpan) {
  15405. return new ReadVarExpr(name, type, sourceSpan);
  15406. }
  15407. /**
  15408. * @param {?} id
  15409. * @param {?=} typeParams
  15410. * @param {?=} sourceSpan
  15411. * @return {?}
  15412. */
  15413. function importExpr(id, typeParams = null, sourceSpan) {
  15414. return new ExternalExpr(id, null, typeParams, sourceSpan);
  15415. }
  15416. /**
  15417. * @param {?} id
  15418. * @param {?=} typeParams
  15419. * @param {?=} typeModifiers
  15420. * @return {?}
  15421. */
  15422. function importType(id, typeParams = null, typeModifiers = null) {
  15423. return id != null ? expressionType(importExpr(id, typeParams, null), typeModifiers) : null;
  15424. }
  15425. /**
  15426. * @param {?} expr
  15427. * @param {?=} typeModifiers
  15428. * @return {?}
  15429. */
  15430. function expressionType(expr, typeModifiers = null) {
  15431. return new ExpressionType(expr, typeModifiers);
  15432. }
  15433. /**
  15434. * @param {?} values
  15435. * @param {?=} type
  15436. * @param {?=} sourceSpan
  15437. * @return {?}
  15438. */
  15439. function literalArr(values, type, sourceSpan) {
  15440. return new LiteralArrayExpr(values, type, sourceSpan);
  15441. }
  15442. /**
  15443. * @param {?} values
  15444. * @param {?=} type
  15445. * @return {?}
  15446. */
  15447. function literalMap(values, type = null) {
  15448. return new LiteralMapExpr(values.map(e => new LiteralMapEntry(e.key, e.value, e.quoted)), type, null);
  15449. }
  15450. /**
  15451. * @param {?} expr
  15452. * @param {?=} sourceSpan
  15453. * @return {?}
  15454. */
  15455. function not(expr, sourceSpan) {
  15456. return new NotExpr(expr, sourceSpan);
  15457. }
  15458. /**
  15459. * @param {?} expr
  15460. * @param {?=} sourceSpan
  15461. * @return {?}
  15462. */
  15463. function assertNotNull(expr, sourceSpan) {
  15464. return new AssertNotNull(expr, sourceSpan);
  15465. }
  15466. /**
  15467. * @param {?} params
  15468. * @param {?} body
  15469. * @param {?=} type
  15470. * @param {?=} sourceSpan
  15471. * @return {?}
  15472. */
  15473. function fn(params, body, type, sourceSpan) {
  15474. return new FunctionExpr(params, body, type, sourceSpan);
  15475. }
  15476. /**
  15477. * @param {?} value
  15478. * @param {?=} type
  15479. * @param {?=} sourceSpan
  15480. * @return {?}
  15481. */
  15482. function literal(value, type, sourceSpan) {
  15483. return new LiteralExpr(value, type, sourceSpan);
  15484. }
  15485. /**
  15486. * @fileoverview added by tsickle
  15487. * @suppress {checkTypes} checked by tsc
  15488. */
  15489. /**
  15490. * @license
  15491. * Copyright Google Inc. All Rights Reserved.
  15492. *
  15493. * Use of this source code is governed by an MIT-style license that can be
  15494. * found in the LICENSE file at https://angular.io/license
  15495. */
  15496. class ProviderError extends ParseError {
  15497. /**
  15498. * @param {?} message
  15499. * @param {?} span
  15500. */
  15501. constructor(message, span) { super(span, message); }
  15502. }
  15503. /**
  15504. * @record
  15505. */
  15506. class ProviderViewContext {
  15507. /**
  15508. * @param {?} reflector
  15509. * @param {?} component
  15510. */
  15511. constructor(reflector, component) {
  15512. this.reflector = reflector;
  15513. this.component = component;
  15514. this.errors = [];
  15515. this.viewQueries = _getViewQueries(component);
  15516. this.viewProviders = new Map();
  15517. component.viewProviders.forEach((provider) => {
  15518. if (this.viewProviders.get(tokenReference(provider.token)) == null) {
  15519. this.viewProviders.set(tokenReference(provider.token), true);
  15520. }
  15521. });
  15522. }
  15523. }
  15524. class ProviderElementContext {
  15525. /**
  15526. * @param {?} viewContext
  15527. * @param {?} _parent
  15528. * @param {?} _isViewRoot
  15529. * @param {?} _directiveAsts
  15530. * @param {?} attrs
  15531. * @param {?} refs
  15532. * @param {?} isTemplate
  15533. * @param {?} contentQueryStartId
  15534. * @param {?} _sourceSpan
  15535. */
  15536. constructor(viewContext, _parent, _isViewRoot, _directiveAsts, attrs, refs, isTemplate, contentQueryStartId, _sourceSpan) {
  15537. this.viewContext = viewContext;
  15538. this._parent = _parent;
  15539. this._isViewRoot = _isViewRoot;
  15540. this._directiveAsts = _directiveAsts;
  15541. this._sourceSpan = _sourceSpan;
  15542. this._transformedProviders = new Map();
  15543. this._seenProviders = new Map();
  15544. this._queriedTokens = new Map();
  15545. this.transformedHasViewContainer = false;
  15546. this._attrs = {};
  15547. attrs.forEach((attrAst) => this._attrs[attrAst.name] = attrAst.value);
  15548. const /** @type {?} */ directivesMeta = _directiveAsts.map(directiveAst => directiveAst.directive);
  15549. this._allProviders =
  15550. _resolveProvidersFromDirectives(directivesMeta, _sourceSpan, viewContext.errors);
  15551. this._contentQueries = _getContentQueries(contentQueryStartId, directivesMeta);
  15552. Array.from(this._allProviders.values()).forEach((provider) => {
  15553. this._addQueryReadsTo(provider.token, provider.token, this._queriedTokens);
  15554. });
  15555. if (isTemplate) {
  15556. const /** @type {?} */ templateRefId = createTokenForExternalReference(this.viewContext.reflector, Identifiers.TemplateRef);
  15557. this._addQueryReadsTo(templateRefId, templateRefId, this._queriedTokens);
  15558. }
  15559. refs.forEach((refAst) => {
  15560. let /** @type {?} */ defaultQueryValue = refAst.value ||
  15561. createTokenForExternalReference(this.viewContext.reflector, Identifiers.ElementRef);
  15562. this._addQueryReadsTo({ value: refAst.name }, defaultQueryValue, this._queriedTokens);
  15563. });
  15564. if (this._queriedTokens.get(this.viewContext.reflector.resolveExternalReference(Identifiers.ViewContainerRef))) {
  15565. this.transformedHasViewContainer = true;
  15566. }
  15567. // create the providers that we know are eager first
  15568. Array.from(this._allProviders.values()).forEach((provider) => {
  15569. const /** @type {?} */ eager = provider.eager || this._queriedTokens.get(tokenReference(provider.token));
  15570. if (eager) {
  15571. this._getOrCreateLocalProvider(provider.providerType, provider.token, true);
  15572. }
  15573. });
  15574. }
  15575. /**
  15576. * @return {?}
  15577. */
  15578. afterElement() {
  15579. // collect lazy providers
  15580. Array.from(this._allProviders.values()).forEach((provider) => {
  15581. this._getOrCreateLocalProvider(provider.providerType, provider.token, false);
  15582. });
  15583. }
  15584. /**
  15585. * @return {?}
  15586. */
  15587. get transformProviders() {
  15588. // Note: Maps keep their insertion order.
  15589. const /** @type {?} */ lazyProviders = [];
  15590. const /** @type {?} */ eagerProviders = [];
  15591. this._transformedProviders.forEach(provider => {
  15592. if (provider.eager) {
  15593. eagerProviders.push(provider);
  15594. }
  15595. else {
  15596. lazyProviders.push(provider);
  15597. }
  15598. });
  15599. return lazyProviders.concat(eagerProviders);
  15600. }
  15601. /**
  15602. * @return {?}
  15603. */
  15604. get transformedDirectiveAsts() {
  15605. const /** @type {?} */ sortedProviderTypes = this.transformProviders.map(provider => provider.token.identifier);
  15606. const /** @type {?} */ sortedDirectives = this._directiveAsts.slice();
  15607. sortedDirectives.sort((dir1, dir2) => sortedProviderTypes.indexOf(dir1.directive.type) -
  15608. sortedProviderTypes.indexOf(dir2.directive.type));
  15609. return sortedDirectives;
  15610. }
  15611. /**
  15612. * @return {?}
  15613. */
  15614. get queryMatches() {
  15615. const /** @type {?} */ allMatches = [];
  15616. this._queriedTokens.forEach((matches) => { allMatches.push(...matches); });
  15617. return allMatches;
  15618. }
  15619. /**
  15620. * @param {?} token
  15621. * @param {?} defaultValue
  15622. * @param {?} queryReadTokens
  15623. * @return {?}
  15624. */
  15625. _addQueryReadsTo(token, defaultValue, queryReadTokens) {
  15626. this._getQueriesFor(token).forEach((query) => {
  15627. const /** @type {?} */ queryValue = query.meta.read || defaultValue;
  15628. const /** @type {?} */ tokenRef = tokenReference(queryValue);
  15629. let /** @type {?} */ queryMatches = queryReadTokens.get(tokenRef);
  15630. if (!queryMatches) {
  15631. queryMatches = [];
  15632. queryReadTokens.set(tokenRef, queryMatches);
  15633. }
  15634. queryMatches.push({ queryId: query.queryId, value: queryValue });
  15635. });
  15636. }
  15637. /**
  15638. * @param {?} token
  15639. * @return {?}
  15640. */
  15641. _getQueriesFor(token) {
  15642. const /** @type {?} */ result = [];
  15643. let /** @type {?} */ currentEl = this;
  15644. let /** @type {?} */ distance = 0;
  15645. let /** @type {?} */ queries;
  15646. while (currentEl !== null) {
  15647. queries = currentEl._contentQueries.get(tokenReference(token));
  15648. if (queries) {
  15649. result.push(...queries.filter((query) => query.meta.descendants || distance <= 1));
  15650. }
  15651. if (currentEl._directiveAsts.length > 0) {
  15652. distance++;
  15653. }
  15654. currentEl = currentEl._parent;
  15655. }
  15656. queries = this.viewContext.viewQueries.get(tokenReference(token));
  15657. if (queries) {
  15658. result.push(...queries);
  15659. }
  15660. return result;
  15661. }
  15662. /**
  15663. * @param {?} requestingProviderType
  15664. * @param {?} token
  15665. * @param {?} eager
  15666. * @return {?}
  15667. */
  15668. _getOrCreateLocalProvider(requestingProviderType, token, eager) {
  15669. const /** @type {?} */ resolvedProvider = this._allProviders.get(tokenReference(token));
  15670. if (!resolvedProvider || ((requestingProviderType === ProviderAstType.Directive ||
  15671. requestingProviderType === ProviderAstType.PublicService) &&
  15672. resolvedProvider.providerType === ProviderAstType.PrivateService) ||
  15673. ((requestingProviderType === ProviderAstType.PrivateService ||
  15674. requestingProviderType === ProviderAstType.PublicService) &&
  15675. resolvedProvider.providerType === ProviderAstType.Builtin)) {
  15676. return null;
  15677. }
  15678. let /** @type {?} */ transformedProviderAst = this._transformedProviders.get(tokenReference(token));
  15679. if (transformedProviderAst) {
  15680. return transformedProviderAst;
  15681. }
  15682. if (this._seenProviders.get(tokenReference(token)) != null) {
  15683. this.viewContext.errors.push(new ProviderError(`Cannot instantiate cyclic dependency! ${tokenName(token)}`, this._sourceSpan));
  15684. return null;
  15685. }
  15686. this._seenProviders.set(tokenReference(token), true);
  15687. const /** @type {?} */ transformedProviders = resolvedProvider.providers.map((provider) => {
  15688. let /** @type {?} */ transformedUseValue = provider.useValue;
  15689. let /** @type {?} */ transformedUseExisting = /** @type {?} */ ((provider.useExisting));
  15690. let /** @type {?} */ transformedDeps = /** @type {?} */ ((undefined));
  15691. if (provider.useExisting != null) {
  15692. const /** @type {?} */ existingDiDep = /** @type {?} */ ((this._getDependency(resolvedProvider.providerType, { token: provider.useExisting }, eager)));
  15693. if (existingDiDep.token != null) {
  15694. transformedUseExisting = existingDiDep.token;
  15695. }
  15696. else {
  15697. transformedUseExisting = /** @type {?} */ ((null));
  15698. transformedUseValue = existingDiDep.value;
  15699. }
  15700. }
  15701. else if (provider.useFactory) {
  15702. const /** @type {?} */ deps = provider.deps || provider.useFactory.diDeps;
  15703. transformedDeps =
  15704. deps.map((dep) => /** @type {?} */ ((this._getDependency(resolvedProvider.providerType, dep, eager))));
  15705. }
  15706. else if (provider.useClass) {
  15707. const /** @type {?} */ deps = provider.deps || provider.useClass.diDeps;
  15708. transformedDeps =
  15709. deps.map((dep) => /** @type {?} */ ((this._getDependency(resolvedProvider.providerType, dep, eager))));
  15710. }
  15711. return _transformProvider(provider, {
  15712. useExisting: transformedUseExisting,
  15713. useValue: transformedUseValue,
  15714. deps: transformedDeps
  15715. });
  15716. });
  15717. transformedProviderAst =
  15718. _transformProviderAst(resolvedProvider, { eager: eager, providers: transformedProviders });
  15719. this._transformedProviders.set(tokenReference(token), transformedProviderAst);
  15720. return transformedProviderAst;
  15721. }
  15722. /**
  15723. * @param {?} requestingProviderType
  15724. * @param {?} dep
  15725. * @param {?=} eager
  15726. * @return {?}
  15727. */
  15728. _getLocalDependency(requestingProviderType, dep, eager = false) {
  15729. if (dep.isAttribute) {
  15730. const /** @type {?} */ attrValue = this._attrs[/** @type {?} */ ((dep.token)).value];
  15731. return { isValue: true, value: attrValue == null ? null : attrValue };
  15732. }
  15733. if (dep.token != null) {
  15734. // access builtints
  15735. if ((requestingProviderType === ProviderAstType.Directive ||
  15736. requestingProviderType === ProviderAstType.Component)) {
  15737. if (tokenReference(dep.token) ===
  15738. this.viewContext.reflector.resolveExternalReference(Identifiers.Renderer) ||
  15739. tokenReference(dep.token) ===
  15740. this.viewContext.reflector.resolveExternalReference(Identifiers.ElementRef) ||
  15741. tokenReference(dep.token) ===
  15742. this.viewContext.reflector.resolveExternalReference(Identifiers.ChangeDetectorRef) ||
  15743. tokenReference(dep.token) ===
  15744. this.viewContext.reflector.resolveExternalReference(Identifiers.TemplateRef)) {
  15745. return dep;
  15746. }
  15747. if (tokenReference(dep.token) ===
  15748. this.viewContext.reflector.resolveExternalReference(Identifiers.ViewContainerRef)) {
  15749. (/** @type {?} */ (this)).transformedHasViewContainer = true;
  15750. }
  15751. }
  15752. // access the injector
  15753. if (tokenReference(dep.token) ===
  15754. this.viewContext.reflector.resolveExternalReference(Identifiers.Injector)) {
  15755. return dep;
  15756. }
  15757. // access providers
  15758. if (this._getOrCreateLocalProvider(requestingProviderType, dep.token, eager) != null) {
  15759. return dep;
  15760. }
  15761. }
  15762. return null;
  15763. }
  15764. /**
  15765. * @param {?} requestingProviderType
  15766. * @param {?} dep
  15767. * @param {?=} eager
  15768. * @return {?}
  15769. */
  15770. _getDependency(requestingProviderType, dep, eager = false) {
  15771. let /** @type {?} */ currElement = this;
  15772. let /** @type {?} */ currEager = eager;
  15773. let /** @type {?} */ result = null;
  15774. if (!dep.isSkipSelf) {
  15775. result = this._getLocalDependency(requestingProviderType, dep, eager);
  15776. }
  15777. if (dep.isSelf) {
  15778. if (!result && dep.isOptional) {
  15779. result = { isValue: true, value: null };
  15780. }
  15781. }
  15782. else {
  15783. // check parent elements
  15784. while (!result && currElement._parent) {
  15785. const /** @type {?} */ prevElement = currElement;
  15786. currElement = currElement._parent;
  15787. if (prevElement._isViewRoot) {
  15788. currEager = false;
  15789. }
  15790. result = currElement._getLocalDependency(ProviderAstType.PublicService, dep, currEager);
  15791. }
  15792. // check @Host restriction
  15793. if (!result) {
  15794. if (!dep.isHost || this.viewContext.component.isHost ||
  15795. this.viewContext.component.type.reference === tokenReference(/** @type {?} */ ((dep.token))) ||
  15796. this.viewContext.viewProviders.get(tokenReference(/** @type {?} */ ((dep.token)))) != null) {
  15797. result = dep;
  15798. }
  15799. else {
  15800. result = dep.isOptional ? result = { isValue: true, value: null } : null;
  15801. }
  15802. }
  15803. }
  15804. if (!result) {
  15805. this.viewContext.errors.push(new ProviderError(`No provider for ${tokenName((/** @type {?} */ ((dep.token))))}`, this._sourceSpan));
  15806. }
  15807. return result;
  15808. }
  15809. }
  15810. class NgModuleProviderAnalyzer {
  15811. /**
  15812. * @param {?} reflector
  15813. * @param {?} ngModule
  15814. * @param {?} extraProviders
  15815. * @param {?} sourceSpan
  15816. */
  15817. constructor(reflector, ngModule, extraProviders, sourceSpan) {
  15818. this.reflector = reflector;
  15819. this._transformedProviders = new Map();
  15820. this._seenProviders = new Map();
  15821. this._errors = [];
  15822. this._allProviders = new Map();
  15823. ngModule.transitiveModule.modules.forEach((ngModuleType) => {
  15824. const /** @type {?} */ ngModuleProvider = { token: { identifier: ngModuleType }, useClass: ngModuleType };
  15825. _resolveProviders([ngModuleProvider], ProviderAstType.PublicService, true, sourceSpan, this._errors, this._allProviders);
  15826. });
  15827. _resolveProviders(ngModule.transitiveModule.providers.map(entry => entry.provider).concat(extraProviders), ProviderAstType.PublicService, false, sourceSpan, this._errors, this._allProviders);
  15828. }
  15829. /**
  15830. * @return {?}
  15831. */
  15832. parse() {
  15833. Array.from(this._allProviders.values()).forEach((provider) => {
  15834. this._getOrCreateLocalProvider(provider.token, provider.eager);
  15835. });
  15836. if (this._errors.length > 0) {
  15837. const /** @type {?} */ errorString = this._errors.join('\n');
  15838. throw new Error(`Provider parse errors:\n${errorString}`);
  15839. }
  15840. // Note: Maps keep their insertion order.
  15841. const /** @type {?} */ lazyProviders = [];
  15842. const /** @type {?} */ eagerProviders = [];
  15843. this._transformedProviders.forEach(provider => {
  15844. if (provider.eager) {
  15845. eagerProviders.push(provider);
  15846. }
  15847. else {
  15848. lazyProviders.push(provider);
  15849. }
  15850. });
  15851. return lazyProviders.concat(eagerProviders);
  15852. }
  15853. /**
  15854. * @param {?} token
  15855. * @param {?} eager
  15856. * @return {?}
  15857. */
  15858. _getOrCreateLocalProvider(token, eager) {
  15859. const /** @type {?} */ resolvedProvider = this._allProviders.get(tokenReference(token));
  15860. if (!resolvedProvider) {
  15861. return null;
  15862. }
  15863. let /** @type {?} */ transformedProviderAst = this._transformedProviders.get(tokenReference(token));
  15864. if (transformedProviderAst) {
  15865. return transformedProviderAst;
  15866. }
  15867. if (this._seenProviders.get(tokenReference(token)) != null) {
  15868. this._errors.push(new ProviderError(`Cannot instantiate cyclic dependency! ${tokenName(token)}`, resolvedProvider.sourceSpan));
  15869. return null;
  15870. }
  15871. this._seenProviders.set(tokenReference(token), true);
  15872. const /** @type {?} */ transformedProviders = resolvedProvider.providers.map((provider) => {
  15873. let /** @type {?} */ transformedUseValue = provider.useValue;
  15874. let /** @type {?} */ transformedUseExisting = /** @type {?} */ ((provider.useExisting));
  15875. let /** @type {?} */ transformedDeps = /** @type {?} */ ((undefined));
  15876. if (provider.useExisting != null) {
  15877. const /** @type {?} */ existingDiDep = this._getDependency({ token: provider.useExisting }, eager, resolvedProvider.sourceSpan);
  15878. if (existingDiDep.token != null) {
  15879. transformedUseExisting = existingDiDep.token;
  15880. }
  15881. else {
  15882. transformedUseExisting = /** @type {?} */ ((null));
  15883. transformedUseValue = existingDiDep.value;
  15884. }
  15885. }
  15886. else if (provider.useFactory) {
  15887. const /** @type {?} */ deps = provider.deps || provider.useFactory.diDeps;
  15888. transformedDeps =
  15889. deps.map((dep) => this._getDependency(dep, eager, resolvedProvider.sourceSpan));
  15890. }
  15891. else if (provider.useClass) {
  15892. const /** @type {?} */ deps = provider.deps || provider.useClass.diDeps;
  15893. transformedDeps =
  15894. deps.map((dep) => this._getDependency(dep, eager, resolvedProvider.sourceSpan));
  15895. }
  15896. return _transformProvider(provider, {
  15897. useExisting: transformedUseExisting,
  15898. useValue: transformedUseValue,
  15899. deps: transformedDeps
  15900. });
  15901. });
  15902. transformedProviderAst =
  15903. _transformProviderAst(resolvedProvider, { eager: eager, providers: transformedProviders });
  15904. this._transformedProviders.set(tokenReference(token), transformedProviderAst);
  15905. return transformedProviderAst;
  15906. }
  15907. /**
  15908. * @param {?} dep
  15909. * @param {?=} eager
  15910. * @param {?=} requestorSourceSpan
  15911. * @return {?}
  15912. */
  15913. _getDependency(dep, eager = false, requestorSourceSpan) {
  15914. let /** @type {?} */ foundLocal = false;
  15915. if (!dep.isSkipSelf && dep.token != null) {
  15916. // access the injector
  15917. if (tokenReference(dep.token) ===
  15918. this.reflector.resolveExternalReference(Identifiers.Injector) ||
  15919. tokenReference(dep.token) ===
  15920. this.reflector.resolveExternalReference(Identifiers.ComponentFactoryResolver)) {
  15921. foundLocal = true;
  15922. // access providers
  15923. }
  15924. else if (this._getOrCreateLocalProvider(dep.token, eager) != null) {
  15925. foundLocal = true;
  15926. }
  15927. }
  15928. let /** @type {?} */ result = dep;
  15929. if (dep.isSelf && !foundLocal) {
  15930. if (dep.isOptional) {
  15931. result = { isValue: true, value: null };
  15932. }
  15933. else {
  15934. this._errors.push(new ProviderError(`No provider for ${tokenName((/** @type {?} */ ((dep.token))))}`, requestorSourceSpan));
  15935. }
  15936. }
  15937. return result;
  15938. }
  15939. }
  15940. /**
  15941. * @param {?} provider
  15942. * @param {?} __1
  15943. * @return {?}
  15944. */
  15945. function _transformProvider(provider, { useExisting, useValue, deps }) {
  15946. return {
  15947. token: provider.token,
  15948. useClass: provider.useClass,
  15949. useExisting: useExisting,
  15950. useFactory: provider.useFactory,
  15951. useValue: useValue,
  15952. deps: deps,
  15953. multi: provider.multi
  15954. };
  15955. }
  15956. /**
  15957. * @param {?} provider
  15958. * @param {?} __1
  15959. * @return {?}
  15960. */
  15961. function _transformProviderAst(provider, { eager, providers }) {
  15962. return new ProviderAst(provider.token, provider.multiProvider, provider.eager || eager, providers, provider.providerType, provider.lifecycleHooks, provider.sourceSpan);
  15963. }
  15964. /**
  15965. * @param {?} directives
  15966. * @param {?} sourceSpan
  15967. * @param {?} targetErrors
  15968. * @return {?}
  15969. */
  15970. function _resolveProvidersFromDirectives(directives, sourceSpan, targetErrors) {
  15971. const /** @type {?} */ providersByToken = new Map();
  15972. directives.forEach((directive) => {
  15973. const /** @type {?} */ dirProvider = { token: { identifier: directive.type }, useClass: directive.type };
  15974. _resolveProviders([dirProvider], directive.isComponent ? ProviderAstType.Component : ProviderAstType.Directive, true, sourceSpan, targetErrors, providersByToken);
  15975. });
  15976. // Note: directives need to be able to overwrite providers of a component!
  15977. const /** @type {?} */ directivesWithComponentFirst = directives.filter(dir => dir.isComponent).concat(directives.filter(dir => !dir.isComponent));
  15978. directivesWithComponentFirst.forEach((directive) => {
  15979. _resolveProviders(directive.providers, ProviderAstType.PublicService, false, sourceSpan, targetErrors, providersByToken);
  15980. _resolveProviders(directive.viewProviders, ProviderAstType.PrivateService, false, sourceSpan, targetErrors, providersByToken);
  15981. });
  15982. return providersByToken;
  15983. }
  15984. /**
  15985. * @param {?} providers
  15986. * @param {?} providerType
  15987. * @param {?} eager
  15988. * @param {?} sourceSpan
  15989. * @param {?} targetErrors
  15990. * @param {?} targetProvidersByToken
  15991. * @return {?}
  15992. */
  15993. function _resolveProviders(providers, providerType, eager, sourceSpan, targetErrors, targetProvidersByToken) {
  15994. providers.forEach((provider) => {
  15995. let /** @type {?} */ resolvedProvider = targetProvidersByToken.get(tokenReference(provider.token));
  15996. if (resolvedProvider != null && !!resolvedProvider.multiProvider !== !!provider.multi) {
  15997. targetErrors.push(new ProviderError(`Mixing multi and non multi provider is not possible for token ${tokenName(resolvedProvider.token)}`, sourceSpan));
  15998. }
  15999. if (!resolvedProvider) {
  16000. const /** @type {?} */ lifecycleHooks = provider.token.identifier &&
  16001. (/** @type {?} */ (provider.token.identifier)).lifecycleHooks ?
  16002. (/** @type {?} */ (provider.token.identifier)).lifecycleHooks :
  16003. [];
  16004. const /** @type {?} */ isUseValue = !(provider.useClass || provider.useExisting || provider.useFactory);
  16005. resolvedProvider = new ProviderAst(provider.token, !!provider.multi, eager || isUseValue, [provider], providerType, lifecycleHooks, sourceSpan);
  16006. targetProvidersByToken.set(tokenReference(provider.token), resolvedProvider);
  16007. }
  16008. else {
  16009. if (!provider.multi) {
  16010. resolvedProvider.providers.length = 0;
  16011. }
  16012. resolvedProvider.providers.push(provider);
  16013. }
  16014. });
  16015. }
  16016. /**
  16017. * @param {?} component
  16018. * @return {?}
  16019. */
  16020. function _getViewQueries(component) {
  16021. // Note: queries start with id 1 so we can use the number in a Bloom filter!
  16022. let /** @type {?} */ viewQueryId = 1;
  16023. const /** @type {?} */ viewQueries = new Map();
  16024. if (component.viewQueries) {
  16025. component.viewQueries.forEach((query) => _addQueryToTokenMap(viewQueries, { meta: query, queryId: viewQueryId++ }));
  16026. }
  16027. return viewQueries;
  16028. }
  16029. /**
  16030. * @param {?} contentQueryStartId
  16031. * @param {?} directives
  16032. * @return {?}
  16033. */
  16034. function _getContentQueries(contentQueryStartId, directives) {
  16035. let /** @type {?} */ contentQueryId = contentQueryStartId;
  16036. const /** @type {?} */ contentQueries = new Map();
  16037. directives.forEach((directive, directiveIndex) => {
  16038. if (directive.queries) {
  16039. directive.queries.forEach((query) => _addQueryToTokenMap(contentQueries, { meta: query, queryId: contentQueryId++ }));
  16040. }
  16041. });
  16042. return contentQueries;
  16043. }
  16044. /**
  16045. * @param {?} map
  16046. * @param {?} query
  16047. * @return {?}
  16048. */
  16049. function _addQueryToTokenMap(map, query) {
  16050. query.meta.selectors.forEach((token) => {
  16051. let /** @type {?} */ entry = map.get(tokenReference(token));
  16052. if (!entry) {
  16053. entry = [];
  16054. map.set(tokenReference(token), entry);
  16055. }
  16056. entry.push(query);
  16057. });
  16058. }
  16059. /**
  16060. * @fileoverview added by tsickle
  16061. * @suppress {checkTypes} checked by tsc
  16062. */
  16063. /**
  16064. * @license
  16065. * Copyright Google Inc. All Rights Reserved.
  16066. *
  16067. * Use of this source code is governed by an MIT-style license that can be
  16068. * found in the LICENSE file at https://angular.io/license
  16069. */
  16070. const QUOTED_KEYS = '$quoted$';
  16071. /**
  16072. * @param {?} ctx
  16073. * @param {?} value
  16074. * @param {?=} type
  16075. * @return {?}
  16076. */
  16077. function convertValueToOutputAst(ctx, value, type = null) {
  16078. return visitValue(value, new _ValueOutputAstTransformer(ctx), type);
  16079. }
  16080. class _ValueOutputAstTransformer {
  16081. /**
  16082. * @param {?} ctx
  16083. */
  16084. constructor(ctx) {
  16085. this.ctx = ctx;
  16086. }
  16087. /**
  16088. * @param {?} arr
  16089. * @param {?} type
  16090. * @return {?}
  16091. */
  16092. visitArray(arr, type) {
  16093. return literalArr(arr.map(value => visitValue(value, this, null)), type);
  16094. }
  16095. /**
  16096. * @param {?} map
  16097. * @param {?} type
  16098. * @return {?}
  16099. */
  16100. visitStringMap(map, type) {
  16101. const /** @type {?} */ entries = [];
  16102. const /** @type {?} */ quotedSet = new Set(map && map[QUOTED_KEYS]);
  16103. Object.keys(map).forEach(key => {
  16104. entries.push(new LiteralMapEntry(key, visitValue(map[key], this, null), quotedSet.has(key)));
  16105. });
  16106. return new LiteralMapExpr(entries, type);
  16107. }
  16108. /**
  16109. * @param {?} value
  16110. * @param {?} type
  16111. * @return {?}
  16112. */
  16113. visitPrimitive(value, type) { return literal(value, type); }
  16114. /**
  16115. * @param {?} value
  16116. * @param {?} type
  16117. * @return {?}
  16118. */
  16119. visitOther(value, type) {
  16120. if (value instanceof Expression) {
  16121. return value;
  16122. }
  16123. else {
  16124. return this.ctx.importExpr(value);
  16125. }
  16126. }
  16127. }
  16128. /**
  16129. * @fileoverview added by tsickle
  16130. * @suppress {checkTypes} checked by tsc
  16131. */
  16132. /**
  16133. * @license
  16134. * Copyright Google Inc. All Rights Reserved.
  16135. *
  16136. * Use of this source code is governed by an MIT-style license that can be
  16137. * found in the LICENSE file at https://angular.io/license
  16138. */
  16139. /**
  16140. * @param {?} ctx
  16141. * @param {?} providerAst
  16142. * @return {?}
  16143. */
  16144. function providerDef(ctx, providerAst) {
  16145. let /** @type {?} */ flags = 0;
  16146. if (!providerAst.eager) {
  16147. flags |= 4096 /* LazyProvider */;
  16148. }
  16149. if (providerAst.providerType === ProviderAstType.PrivateService) {
  16150. flags |= 8192 /* PrivateProvider */;
  16151. }
  16152. providerAst.lifecycleHooks.forEach((lifecycleHook) => {
  16153. // for regular providers, we only support ngOnDestroy
  16154. if (lifecycleHook === LifecycleHooks.OnDestroy ||
  16155. providerAst.providerType === ProviderAstType.Directive ||
  16156. providerAst.providerType === ProviderAstType.Component) {
  16157. flags |= lifecycleHookToNodeFlag(lifecycleHook);
  16158. }
  16159. });
  16160. const { providerExpr, flags: providerFlags, depsExpr } = providerAst.multiProvider ?
  16161. multiProviderDef(ctx, flags, providerAst.providers) :
  16162. singleProviderDef(ctx, flags, providerAst.providerType, providerAst.providers[0]);
  16163. return {
  16164. providerExpr,
  16165. flags: providerFlags, depsExpr,
  16166. tokenExpr: tokenExpr(ctx, providerAst.token),
  16167. };
  16168. }
  16169. /**
  16170. * @param {?} ctx
  16171. * @param {?} flags
  16172. * @param {?} providers
  16173. * @return {?}
  16174. */
  16175. function multiProviderDef(ctx, flags, providers) {
  16176. const /** @type {?} */ allDepDefs = [];
  16177. const /** @type {?} */ allParams = [];
  16178. const /** @type {?} */ exprs = providers.map((provider, providerIndex) => {
  16179. let /** @type {?} */ expr;
  16180. if (provider.useClass) {
  16181. const /** @type {?} */ depExprs = convertDeps(providerIndex, provider.deps || provider.useClass.diDeps);
  16182. expr = ctx.importExpr(provider.useClass.reference).instantiate(depExprs);
  16183. }
  16184. else if (provider.useFactory) {
  16185. const /** @type {?} */ depExprs = convertDeps(providerIndex, provider.deps || provider.useFactory.diDeps);
  16186. expr = ctx.importExpr(provider.useFactory.reference).callFn(depExprs);
  16187. }
  16188. else if (provider.useExisting) {
  16189. const /** @type {?} */ depExprs = convertDeps(providerIndex, [{ token: provider.useExisting }]);
  16190. expr = depExprs[0];
  16191. }
  16192. else {
  16193. expr = convertValueToOutputAst(ctx, provider.useValue);
  16194. }
  16195. return expr;
  16196. });
  16197. const /** @type {?} */ providerExpr = fn(allParams, [new ReturnStatement(literalArr(exprs))], INFERRED_TYPE);
  16198. return {
  16199. providerExpr,
  16200. flags: flags | 1024 /* TypeFactoryProvider */,
  16201. depsExpr: literalArr(allDepDefs)
  16202. };
  16203. /**
  16204. * @param {?} providerIndex
  16205. * @param {?} deps
  16206. * @return {?}
  16207. */
  16208. function convertDeps(providerIndex, deps) {
  16209. return deps.map((dep, depIndex) => {
  16210. const /** @type {?} */ paramName = `p${providerIndex}_${depIndex}`;
  16211. allParams.push(new FnParam(paramName, DYNAMIC_TYPE));
  16212. allDepDefs.push(depDef(ctx, dep));
  16213. return variable(paramName);
  16214. });
  16215. }
  16216. }
  16217. /**
  16218. * @param {?} ctx
  16219. * @param {?} flags
  16220. * @param {?} providerType
  16221. * @param {?} providerMeta
  16222. * @return {?}
  16223. */
  16224. function singleProviderDef(ctx, flags, providerType, providerMeta) {
  16225. let /** @type {?} */ providerExpr;
  16226. let /** @type {?} */ deps;
  16227. if (providerType === ProviderAstType.Directive || providerType === ProviderAstType.Component) {
  16228. providerExpr = ctx.importExpr(/** @type {?} */ ((providerMeta.useClass)).reference);
  16229. flags |= 16384 /* TypeDirective */;
  16230. deps = providerMeta.deps || /** @type {?} */ ((providerMeta.useClass)).diDeps;
  16231. }
  16232. else {
  16233. if (providerMeta.useClass) {
  16234. providerExpr = ctx.importExpr(providerMeta.useClass.reference);
  16235. flags |= 512 /* TypeClassProvider */;
  16236. deps = providerMeta.deps || providerMeta.useClass.diDeps;
  16237. }
  16238. else if (providerMeta.useFactory) {
  16239. providerExpr = ctx.importExpr(providerMeta.useFactory.reference);
  16240. flags |= 1024 /* TypeFactoryProvider */;
  16241. deps = providerMeta.deps || providerMeta.useFactory.diDeps;
  16242. }
  16243. else if (providerMeta.useExisting) {
  16244. providerExpr = NULL_EXPR;
  16245. flags |= 2048 /* TypeUseExistingProvider */;
  16246. deps = [{ token: providerMeta.useExisting }];
  16247. }
  16248. else {
  16249. providerExpr = convertValueToOutputAst(ctx, providerMeta.useValue);
  16250. flags |= 256 /* TypeValueProvider */;
  16251. deps = [];
  16252. }
  16253. }
  16254. const /** @type {?} */ depsExpr = literalArr(deps.map(dep => depDef(ctx, dep)));
  16255. return { providerExpr, flags, depsExpr };
  16256. }
  16257. /**
  16258. * @param {?} ctx
  16259. * @param {?} tokenMeta
  16260. * @return {?}
  16261. */
  16262. function tokenExpr(ctx, tokenMeta) {
  16263. return tokenMeta.identifier ? ctx.importExpr(tokenMeta.identifier.reference) :
  16264. literal(tokenMeta.value);
  16265. }
  16266. /**
  16267. * @param {?} ctx
  16268. * @param {?} dep
  16269. * @return {?}
  16270. */
  16271. function depDef(ctx, dep) {
  16272. // Note: the following fields have already been normalized out by provider_analyzer:
  16273. // - isAttribute, isSelf, isHost
  16274. const /** @type {?} */ expr = dep.isValue ? convertValueToOutputAst(ctx, dep.value) : tokenExpr(ctx, /** @type {?} */ ((dep.token)));
  16275. let /** @type {?} */ flags = 0;
  16276. if (dep.isSkipSelf) {
  16277. flags |= 1 /* SkipSelf */;
  16278. }
  16279. if (dep.isOptional) {
  16280. flags |= 2 /* Optional */;
  16281. }
  16282. if (dep.isValue) {
  16283. flags |= 8 /* Value */;
  16284. }
  16285. return flags === 0 /* None */ ? expr : literalArr([literal(flags), expr]);
  16286. }
  16287. /**
  16288. * @param {?} lifecycleHook
  16289. * @return {?}
  16290. */
  16291. function lifecycleHookToNodeFlag(lifecycleHook) {
  16292. let /** @type {?} */ nodeFlag = 0;
  16293. switch (lifecycleHook) {
  16294. case LifecycleHooks.AfterContentChecked:
  16295. nodeFlag = 2097152 /* AfterContentChecked */;
  16296. break;
  16297. case LifecycleHooks.AfterContentInit:
  16298. nodeFlag = 1048576 /* AfterContentInit */;
  16299. break;
  16300. case LifecycleHooks.AfterViewChecked:
  16301. nodeFlag = 8388608 /* AfterViewChecked */;
  16302. break;
  16303. case LifecycleHooks.AfterViewInit:
  16304. nodeFlag = 4194304 /* AfterViewInit */;
  16305. break;
  16306. case LifecycleHooks.DoCheck:
  16307. nodeFlag = 262144 /* DoCheck */;
  16308. break;
  16309. case LifecycleHooks.OnChanges:
  16310. nodeFlag = 524288 /* OnChanges */;
  16311. break;
  16312. case LifecycleHooks.OnDestroy:
  16313. nodeFlag = 131072 /* OnDestroy */;
  16314. break;
  16315. case LifecycleHooks.OnInit:
  16316. nodeFlag = 65536 /* OnInit */;
  16317. break;
  16318. }
  16319. return nodeFlag;
  16320. }
  16321. /**
  16322. * @param {?} reflector
  16323. * @param {?} ctx
  16324. * @param {?} flags
  16325. * @param {?} entryComponents
  16326. * @return {?}
  16327. */
  16328. function componentFactoryResolverProviderDef(reflector, ctx, flags, entryComponents) {
  16329. const /** @type {?} */ entryComponentFactories = entryComponents.map((entryComponent) => ctx.importExpr(entryComponent.componentFactory));
  16330. const /** @type {?} */ token = createTokenForExternalReference(reflector, Identifiers.ComponentFactoryResolver);
  16331. const /** @type {?} */ classMeta = {
  16332. diDeps: [
  16333. { isValue: true, value: literalArr(entryComponentFactories) },
  16334. { token: token, isSkipSelf: true, isOptional: true },
  16335. { token: createTokenForExternalReference(reflector, Identifiers.NgModuleRef) },
  16336. ],
  16337. lifecycleHooks: [],
  16338. reference: reflector.resolveExternalReference(Identifiers.CodegenComponentFactoryResolver)
  16339. };
  16340. const { providerExpr, flags: providerFlags, depsExpr } = singleProviderDef(ctx, flags, ProviderAstType.PrivateService, {
  16341. token,
  16342. multi: false,
  16343. useClass: classMeta,
  16344. });
  16345. return { providerExpr, flags: providerFlags, depsExpr, tokenExpr: tokenExpr(ctx, token) };
  16346. }
  16347. /**
  16348. * @fileoverview added by tsickle
  16349. * @suppress {checkTypes} checked by tsc
  16350. */
  16351. /**
  16352. * @license
  16353. * Copyright Google Inc. All Rights Reserved.
  16354. *
  16355. * Use of this source code is governed by an MIT-style license that can be
  16356. * found in the LICENSE file at https://angular.io/license
  16357. */
  16358. class NgModuleCompileResult {
  16359. /**
  16360. * @param {?} ngModuleFactoryVar
  16361. */
  16362. constructor(ngModuleFactoryVar) {
  16363. this.ngModuleFactoryVar = ngModuleFactoryVar;
  16364. }
  16365. }
  16366. const LOG_VAR = variable('_l');
  16367. class NgModuleCompiler {
  16368. /**
  16369. * @param {?} reflector
  16370. */
  16371. constructor(reflector) {
  16372. this.reflector = reflector;
  16373. }
  16374. /**
  16375. * @param {?} ctx
  16376. * @param {?} ngModuleMeta
  16377. * @param {?} extraProviders
  16378. * @return {?}
  16379. */
  16380. compile(ctx, ngModuleMeta, extraProviders) {
  16381. const /** @type {?} */ sourceSpan = typeSourceSpan('NgModule', ngModuleMeta.type);
  16382. const /** @type {?} */ entryComponentFactories = ngModuleMeta.transitiveModule.entryComponents;
  16383. const /** @type {?} */ bootstrapComponents = ngModuleMeta.bootstrapComponents;
  16384. const /** @type {?} */ providerParser = new NgModuleProviderAnalyzer(this.reflector, ngModuleMeta, extraProviders, sourceSpan);
  16385. const /** @type {?} */ providerDefs = [componentFactoryResolverProviderDef(this.reflector, ctx, 0 /* None */, entryComponentFactories)]
  16386. .concat(providerParser.parse().map((provider) => providerDef(ctx, provider)))
  16387. .map(({ providerExpr, depsExpr, flags, tokenExpr }) => {
  16388. return importExpr(Identifiers.moduleProviderDef).callFn([
  16389. literal(flags), tokenExpr, providerExpr, depsExpr
  16390. ]);
  16391. });
  16392. const /** @type {?} */ ngModuleDef = importExpr(Identifiers.moduleDef).callFn([literalArr(providerDefs)]);
  16393. const /** @type {?} */ ngModuleDefFactory = fn([new FnParam(/** @type {?} */ ((LOG_VAR.name)))], [new ReturnStatement(ngModuleDef)], INFERRED_TYPE);
  16394. const /** @type {?} */ ngModuleFactoryVar = `${identifierName(ngModuleMeta.type)}NgFactory`;
  16395. this._createNgModuleFactory(ctx, ngModuleMeta.type.reference, importExpr(Identifiers.createModuleFactory).callFn([
  16396. ctx.importExpr(ngModuleMeta.type.reference),
  16397. literalArr(bootstrapComponents.map(id => ctx.importExpr(id.reference))),
  16398. ngModuleDefFactory
  16399. ]));
  16400. if (ngModuleMeta.id) {
  16401. const /** @type {?} */ registerFactoryStmt = importExpr(Identifiers.RegisterModuleFactoryFn)
  16402. .callFn([literal(ngModuleMeta.id), variable(ngModuleFactoryVar)])
  16403. .toStmt();
  16404. ctx.statements.push(registerFactoryStmt);
  16405. }
  16406. return new NgModuleCompileResult(ngModuleFactoryVar);
  16407. }
  16408. /**
  16409. * @param {?} ctx
  16410. * @param {?} ngModuleReference
  16411. * @return {?}
  16412. */
  16413. createStub(ctx, ngModuleReference) {
  16414. this._createNgModuleFactory(ctx, ngModuleReference, NULL_EXPR);
  16415. }
  16416. /**
  16417. * @param {?} ctx
  16418. * @param {?} reference
  16419. * @param {?} value
  16420. * @return {?}
  16421. */
  16422. _createNgModuleFactory(ctx, reference, value) {
  16423. const /** @type {?} */ ngModuleFactoryVar = `${identifierName({ reference: reference })}NgFactory`;
  16424. const /** @type {?} */ ngModuleFactoryStmt = variable(ngModuleFactoryVar)
  16425. .set(value)
  16426. .toDeclStmt(importType(Identifiers.NgModuleFactory, [/** @type {?} */ ((expressionType(ctx.importExpr(reference))))], [TypeModifier.Const]), [StmtModifier.Final, StmtModifier.Exported]);
  16427. ctx.statements.push(ngModuleFactoryStmt);
  16428. }
  16429. }
  16430. /**
  16431. * @fileoverview added by tsickle
  16432. * @suppress {checkTypes} checked by tsc
  16433. */
  16434. /**
  16435. * @license
  16436. * Copyright Google Inc. All Rights Reserved.
  16437. *
  16438. * Use of this source code is governed by an MIT-style license that can be
  16439. * found in the LICENSE file at https://angular.io/license
  16440. */
  16441. /**
  16442. * Resolves types to {\@link NgModule}.
  16443. */
  16444. class NgModuleResolver {
  16445. /**
  16446. * @param {?} _reflector
  16447. */
  16448. constructor(_reflector) {
  16449. this._reflector = _reflector;
  16450. }
  16451. /**
  16452. * @param {?} type
  16453. * @return {?}
  16454. */
  16455. isNgModule(type) { return this._reflector.annotations(type).some(createNgModule.isTypeOf); }
  16456. /**
  16457. * @param {?} type
  16458. * @param {?=} throwIfNotFound
  16459. * @return {?}
  16460. */
  16461. resolve(type, throwIfNotFound = true) {
  16462. const /** @type {?} */ ngModuleMeta = findLast(this._reflector.annotations(type), createNgModule.isTypeOf);
  16463. if (ngModuleMeta) {
  16464. return ngModuleMeta;
  16465. }
  16466. else {
  16467. if (throwIfNotFound) {
  16468. throw new Error(`No NgModule metadata found for '${stringify(type)}'.`);
  16469. }
  16470. return null;
  16471. }
  16472. }
  16473. }
  16474. /**
  16475. * @fileoverview added by tsickle
  16476. * @suppress {checkTypes} checked by tsc
  16477. */
  16478. /**
  16479. * @license
  16480. * Copyright Google Inc. All Rights Reserved.
  16481. *
  16482. * Use of this source code is governed by an MIT-style license that can be
  16483. * found in the LICENSE file at https://angular.io/license
  16484. */
  16485. // https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
  16486. const VERSION$1 = 3;
  16487. const JS_B64_PREFIX = '# sourceMappingURL=data:application/json;base64,';
  16488. class SourceMapGenerator {
  16489. /**
  16490. * @param {?=} file
  16491. */
  16492. constructor(file = null) {
  16493. this.file = file;
  16494. this.sourcesContent = new Map();
  16495. this.lines = [];
  16496. this.lastCol0 = 0;
  16497. this.hasMappings = false;
  16498. }
  16499. /**
  16500. * @param {?} url
  16501. * @param {?=} content
  16502. * @return {?}
  16503. */
  16504. addSource(url, content = null) {
  16505. if (!this.sourcesContent.has(url)) {
  16506. this.sourcesContent.set(url, content);
  16507. }
  16508. return this;
  16509. }
  16510. /**
  16511. * @return {?}
  16512. */
  16513. addLine() {
  16514. this.lines.push([]);
  16515. this.lastCol0 = 0;
  16516. return this;
  16517. }
  16518. /**
  16519. * @param {?} col0
  16520. * @param {?=} sourceUrl
  16521. * @param {?=} sourceLine0
  16522. * @param {?=} sourceCol0
  16523. * @return {?}
  16524. */
  16525. addMapping(col0, sourceUrl, sourceLine0, sourceCol0) {
  16526. if (!this.currentLine) {
  16527. throw new Error(`A line must be added before mappings can be added`);
  16528. }
  16529. if (sourceUrl != null && !this.sourcesContent.has(sourceUrl)) {
  16530. throw new Error(`Unknown source file "${sourceUrl}"`);
  16531. }
  16532. if (col0 == null) {
  16533. throw new Error(`The column in the generated code must be provided`);
  16534. }
  16535. if (col0 < this.lastCol0) {
  16536. throw new Error(`Mapping should be added in output order`);
  16537. }
  16538. if (sourceUrl && (sourceLine0 == null || sourceCol0 == null)) {
  16539. throw new Error(`The source location must be provided when a source url is provided`);
  16540. }
  16541. this.hasMappings = true;
  16542. this.lastCol0 = col0;
  16543. this.currentLine.push({ col0, sourceUrl, sourceLine0, sourceCol0 });
  16544. return this;
  16545. }
  16546. /**
  16547. * @return {?}
  16548. */
  16549. get currentLine() { return this.lines.slice(-1)[0]; }
  16550. /**
  16551. * @return {?}
  16552. */
  16553. toJSON() {
  16554. if (!this.hasMappings) {
  16555. return null;
  16556. }
  16557. const /** @type {?} */ sourcesIndex = new Map();
  16558. const /** @type {?} */ sources = [];
  16559. const /** @type {?} */ sourcesContent = [];
  16560. Array.from(this.sourcesContent.keys()).forEach((url, i) => {
  16561. sourcesIndex.set(url, i);
  16562. sources.push(url);
  16563. sourcesContent.push(this.sourcesContent.get(url) || null);
  16564. });
  16565. let /** @type {?} */ mappings = '';
  16566. let /** @type {?} */ lastCol0 = 0;
  16567. let /** @type {?} */ lastSourceIndex = 0;
  16568. let /** @type {?} */ lastSourceLine0 = 0;
  16569. let /** @type {?} */ lastSourceCol0 = 0;
  16570. this.lines.forEach(segments => {
  16571. lastCol0 = 0;
  16572. mappings += segments
  16573. .map(segment => {
  16574. // zero-based starting column of the line in the generated code
  16575. let /** @type {?} */ segAsStr = toBase64VLQ(segment.col0 - lastCol0);
  16576. lastCol0 = segment.col0;
  16577. if (segment.sourceUrl != null) {
  16578. // zero-based index into the “sources” list
  16579. segAsStr +=
  16580. toBase64VLQ(/** @type {?} */ ((sourcesIndex.get(segment.sourceUrl))) - lastSourceIndex);
  16581. lastSourceIndex = /** @type {?} */ ((sourcesIndex.get(segment.sourceUrl)));
  16582. // the zero-based starting line in the original source
  16583. segAsStr += toBase64VLQ(/** @type {?} */ ((segment.sourceLine0)) - lastSourceLine0);
  16584. lastSourceLine0 = /** @type {?} */ ((segment.sourceLine0));
  16585. // the zero-based starting column in the original source
  16586. segAsStr += toBase64VLQ(/** @type {?} */ ((segment.sourceCol0)) - lastSourceCol0);
  16587. lastSourceCol0 = /** @type {?} */ ((segment.sourceCol0));
  16588. }
  16589. return segAsStr;
  16590. })
  16591. .join(',');
  16592. mappings += ';';
  16593. });
  16594. mappings = mappings.slice(0, -1);
  16595. return {
  16596. 'file': this.file || '',
  16597. 'version': VERSION$1,
  16598. 'sourceRoot': '',
  16599. 'sources': sources,
  16600. 'sourcesContent': sourcesContent,
  16601. 'mappings': mappings,
  16602. };
  16603. }
  16604. /**
  16605. * @return {?}
  16606. */
  16607. toJsComment() {
  16608. return this.hasMappings ? '//' + JS_B64_PREFIX + toBase64String(JSON.stringify(this, null, 0)) :
  16609. '';
  16610. }
  16611. }
  16612. /**
  16613. * @param {?} value
  16614. * @return {?}
  16615. */
  16616. function toBase64String(value) {
  16617. let /** @type {?} */ b64 = '';
  16618. value = utf8Encode(value);
  16619. for (let /** @type {?} */ i = 0; i < value.length;) {
  16620. const /** @type {?} */ i1 = value.charCodeAt(i++);
  16621. const /** @type {?} */ i2 = value.charCodeAt(i++);
  16622. const /** @type {?} */ i3 = value.charCodeAt(i++);
  16623. b64 += toBase64Digit(i1 >> 2);
  16624. b64 += toBase64Digit(((i1 & 3) << 4) | (isNaN(i2) ? 0 : i2 >> 4));
  16625. b64 += isNaN(i2) ? '=' : toBase64Digit(((i2 & 15) << 2) | (i3 >> 6));
  16626. b64 += isNaN(i2) || isNaN(i3) ? '=' : toBase64Digit(i3 & 63);
  16627. }
  16628. return b64;
  16629. }
  16630. /**
  16631. * @param {?} value
  16632. * @return {?}
  16633. */
  16634. function toBase64VLQ(value) {
  16635. value = value < 0 ? ((-value) << 1) + 1 : value << 1;
  16636. let /** @type {?} */ out = '';
  16637. do {
  16638. let /** @type {?} */ digit = value & 31;
  16639. value = value >> 5;
  16640. if (value > 0) {
  16641. digit = digit | 32;
  16642. }
  16643. out += toBase64Digit(digit);
  16644. } while (value > 0);
  16645. return out;
  16646. }
  16647. const B64_DIGITS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  16648. /**
  16649. * @param {?} value
  16650. * @return {?}
  16651. */
  16652. function toBase64Digit(value) {
  16653. if (value < 0 || value >= 64) {
  16654. throw new Error(`Can only encode value in the range [0, 63]`);
  16655. }
  16656. return B64_DIGITS[value];
  16657. }
  16658. /**
  16659. * @fileoverview added by tsickle
  16660. * @suppress {checkTypes} checked by tsc
  16661. */
  16662. /**
  16663. * @license
  16664. * Copyright Google Inc. All Rights Reserved.
  16665. *
  16666. * Use of this source code is governed by an MIT-style license that can be
  16667. * found in the LICENSE file at https://angular.io/license
  16668. */
  16669. const _SINGLE_QUOTE_ESCAPE_STRING_RE = /'|\\|\n|\r|\$/g;
  16670. const _LEGAL_IDENTIFIER_RE = /^[$A-Z_][0-9A-Z_$]*$/i;
  16671. const _INDENT_WITH = ' ';
  16672. const CATCH_ERROR_VAR$1 = variable('error', null, null);
  16673. const CATCH_STACK_VAR$1 = variable('stack', null, null);
  16674. /**
  16675. * @record
  16676. */
  16677. class _EmittedLine {
  16678. /**
  16679. * @param {?} indent
  16680. */
  16681. constructor(indent) {
  16682. this.indent = indent;
  16683. this.partsLength = 0;
  16684. this.parts = [];
  16685. this.srcSpans = [];
  16686. }
  16687. }
  16688. class EmitterVisitorContext {
  16689. /**
  16690. * @param {?} _indent
  16691. */
  16692. constructor(_indent) {
  16693. this._indent = _indent;
  16694. this._classes = [];
  16695. this._preambleLineCount = 0;
  16696. this._lines = [new _EmittedLine(_indent)];
  16697. }
  16698. /**
  16699. * @return {?}
  16700. */
  16701. static createRoot() { return new EmitterVisitorContext(0); }
  16702. /**
  16703. * @return {?}
  16704. */
  16705. get _currentLine() { return this._lines[this._lines.length - 1]; }
  16706. /**
  16707. * @param {?=} from
  16708. * @param {?=} lastPart
  16709. * @return {?}
  16710. */
  16711. println(from, lastPart = '') {
  16712. this.print(from || null, lastPart, true);
  16713. }
  16714. /**
  16715. * @return {?}
  16716. */
  16717. lineIsEmpty() { return this._currentLine.parts.length === 0; }
  16718. /**
  16719. * @return {?}
  16720. */
  16721. lineLength() {
  16722. return this._currentLine.indent * _INDENT_WITH.length + this._currentLine.partsLength;
  16723. }
  16724. /**
  16725. * @param {?} from
  16726. * @param {?} part
  16727. * @param {?=} newLine
  16728. * @return {?}
  16729. */
  16730. print(from, part, newLine = false) {
  16731. if (part.length > 0) {
  16732. this._currentLine.parts.push(part);
  16733. this._currentLine.partsLength += part.length;
  16734. this._currentLine.srcSpans.push(from && from.sourceSpan || null);
  16735. }
  16736. if (newLine) {
  16737. this._lines.push(new _EmittedLine(this._indent));
  16738. }
  16739. }
  16740. /**
  16741. * @return {?}
  16742. */
  16743. removeEmptyLastLine() {
  16744. if (this.lineIsEmpty()) {
  16745. this._lines.pop();
  16746. }
  16747. }
  16748. /**
  16749. * @return {?}
  16750. */
  16751. incIndent() {
  16752. this._indent++;
  16753. if (this.lineIsEmpty()) {
  16754. this._currentLine.indent = this._indent;
  16755. }
  16756. }
  16757. /**
  16758. * @return {?}
  16759. */
  16760. decIndent() {
  16761. this._indent--;
  16762. if (this.lineIsEmpty()) {
  16763. this._currentLine.indent = this._indent;
  16764. }
  16765. }
  16766. /**
  16767. * @param {?} clazz
  16768. * @return {?}
  16769. */
  16770. pushClass(clazz) { this._classes.push(clazz); }
  16771. /**
  16772. * @return {?}
  16773. */
  16774. popClass() { return /** @type {?} */ ((this._classes.pop())); }
  16775. /**
  16776. * @return {?}
  16777. */
  16778. get currentClass() {
  16779. return this._classes.length > 0 ? this._classes[this._classes.length - 1] : null;
  16780. }
  16781. /**
  16782. * @return {?}
  16783. */
  16784. toSource() {
  16785. return this.sourceLines
  16786. .map(l => l.parts.length > 0 ? _createIndent(l.indent) + l.parts.join('') : '')
  16787. .join('\n');
  16788. }
  16789. /**
  16790. * @param {?} genFilePath
  16791. * @param {?=} startsAtLine
  16792. * @return {?}
  16793. */
  16794. toSourceMapGenerator(genFilePath, startsAtLine = 0) {
  16795. const /** @type {?} */ map = new SourceMapGenerator(genFilePath);
  16796. let /** @type {?} */ firstOffsetMapped = false;
  16797. const /** @type {?} */ mapFirstOffsetIfNeeded = () => {
  16798. if (!firstOffsetMapped) {
  16799. // Add a single space so that tools won't try to load the file from disk.
  16800. // Note: We are using virtual urls like `ng:///`, so we have to
  16801. // provide a content here.
  16802. map.addSource(genFilePath, ' ').addMapping(0, genFilePath, 0, 0);
  16803. firstOffsetMapped = true;
  16804. }
  16805. };
  16806. for (let /** @type {?} */ i = 0; i < startsAtLine; i++) {
  16807. map.addLine();
  16808. mapFirstOffsetIfNeeded();
  16809. }
  16810. this.sourceLines.forEach((line, lineIdx) => {
  16811. map.addLine();
  16812. const /** @type {?} */ spans = line.srcSpans;
  16813. const /** @type {?} */ parts = line.parts;
  16814. let /** @type {?} */ col0 = line.indent * _INDENT_WITH.length;
  16815. let /** @type {?} */ spanIdx = 0;
  16816. // skip leading parts without source spans
  16817. while (spanIdx < spans.length && !spans[spanIdx]) {
  16818. col0 += parts[spanIdx].length;
  16819. spanIdx++;
  16820. }
  16821. if (spanIdx < spans.length && lineIdx === 0 && col0 === 0) {
  16822. firstOffsetMapped = true;
  16823. }
  16824. else {
  16825. mapFirstOffsetIfNeeded();
  16826. }
  16827. while (spanIdx < spans.length) {
  16828. const /** @type {?} */ span = /** @type {?} */ ((spans[spanIdx]));
  16829. const /** @type {?} */ source = span.start.file;
  16830. const /** @type {?} */ sourceLine = span.start.line;
  16831. const /** @type {?} */ sourceCol = span.start.col;
  16832. map.addSource(source.url, source.content)
  16833. .addMapping(col0, source.url, sourceLine, sourceCol);
  16834. col0 += parts[spanIdx].length;
  16835. spanIdx++;
  16836. // assign parts without span or the same span to the previous segment
  16837. while (spanIdx < spans.length && (span === spans[spanIdx] || !spans[spanIdx])) {
  16838. col0 += parts[spanIdx].length;
  16839. spanIdx++;
  16840. }
  16841. }
  16842. });
  16843. return map;
  16844. }
  16845. /**
  16846. * @param {?} count
  16847. * @return {?}
  16848. */
  16849. setPreambleLineCount(count) { return this._preambleLineCount = count; }
  16850. /**
  16851. * @param {?} line
  16852. * @param {?} column
  16853. * @return {?}
  16854. */
  16855. spanOf(line, column) {
  16856. const /** @type {?} */ emittedLine = this._lines[line - this._preambleLineCount];
  16857. if (emittedLine) {
  16858. let /** @type {?} */ columnsLeft = column - _createIndent(emittedLine.indent).length;
  16859. for (let /** @type {?} */ partIndex = 0; partIndex < emittedLine.parts.length; partIndex++) {
  16860. const /** @type {?} */ part = emittedLine.parts[partIndex];
  16861. if (part.length > columnsLeft) {
  16862. return emittedLine.srcSpans[partIndex];
  16863. }
  16864. columnsLeft -= part.length;
  16865. }
  16866. }
  16867. return null;
  16868. }
  16869. /**
  16870. * @return {?}
  16871. */
  16872. get sourceLines() {
  16873. if (this._lines.length && this._lines[this._lines.length - 1].parts.length === 0) {
  16874. return this._lines.slice(0, -1);
  16875. }
  16876. return this._lines;
  16877. }
  16878. }
  16879. /**
  16880. * @abstract
  16881. */
  16882. class AbstractEmitterVisitor {
  16883. /**
  16884. * @param {?} _escapeDollarInStrings
  16885. */
  16886. constructor(_escapeDollarInStrings) {
  16887. this._escapeDollarInStrings = _escapeDollarInStrings;
  16888. }
  16889. /**
  16890. * @param {?} stmt
  16891. * @param {?} ctx
  16892. * @return {?}
  16893. */
  16894. visitExpressionStmt(stmt, ctx) {
  16895. stmt.expr.visitExpression(this, ctx);
  16896. ctx.println(stmt, ';');
  16897. return null;
  16898. }
  16899. /**
  16900. * @param {?} stmt
  16901. * @param {?} ctx
  16902. * @return {?}
  16903. */
  16904. visitReturnStmt(stmt, ctx) {
  16905. ctx.print(stmt, `return `);
  16906. stmt.value.visitExpression(this, ctx);
  16907. ctx.println(stmt, ';');
  16908. return null;
  16909. }
  16910. /**
  16911. * @param {?} stmt
  16912. * @param {?} ctx
  16913. * @return {?}
  16914. */
  16915. visitIfStmt(stmt, ctx) {
  16916. ctx.print(stmt, `if (`);
  16917. stmt.condition.visitExpression(this, ctx);
  16918. ctx.print(stmt, `) {`);
  16919. const /** @type {?} */ hasElseCase = stmt.falseCase != null && stmt.falseCase.length > 0;
  16920. if (stmt.trueCase.length <= 1 && !hasElseCase) {
  16921. ctx.print(stmt, ` `);
  16922. this.visitAllStatements(stmt.trueCase, ctx);
  16923. ctx.removeEmptyLastLine();
  16924. ctx.print(stmt, ` `);
  16925. }
  16926. else {
  16927. ctx.println();
  16928. ctx.incIndent();
  16929. this.visitAllStatements(stmt.trueCase, ctx);
  16930. ctx.decIndent();
  16931. if (hasElseCase) {
  16932. ctx.println(stmt, `} else {`);
  16933. ctx.incIndent();
  16934. this.visitAllStatements(stmt.falseCase, ctx);
  16935. ctx.decIndent();
  16936. }
  16937. }
  16938. ctx.println(stmt, `}`);
  16939. return null;
  16940. }
  16941. /**
  16942. * @param {?} stmt
  16943. * @param {?} ctx
  16944. * @return {?}
  16945. */
  16946. visitThrowStmt(stmt, ctx) {
  16947. ctx.print(stmt, `throw `);
  16948. stmt.error.visitExpression(this, ctx);
  16949. ctx.println(stmt, `;`);
  16950. return null;
  16951. }
  16952. /**
  16953. * @param {?} stmt
  16954. * @param {?} ctx
  16955. * @return {?}
  16956. */
  16957. visitCommentStmt(stmt, ctx) {
  16958. const /** @type {?} */ lines = stmt.comment.split('\n');
  16959. lines.forEach((line) => { ctx.println(stmt, `// ${line}`); });
  16960. return null;
  16961. }
  16962. /**
  16963. * @param {?} expr
  16964. * @param {?} ctx
  16965. * @return {?}
  16966. */
  16967. visitWriteVarExpr(expr, ctx) {
  16968. const /** @type {?} */ lineWasEmpty = ctx.lineIsEmpty();
  16969. if (!lineWasEmpty) {
  16970. ctx.print(expr, '(');
  16971. }
  16972. ctx.print(expr, `${expr.name} = `);
  16973. expr.value.visitExpression(this, ctx);
  16974. if (!lineWasEmpty) {
  16975. ctx.print(expr, ')');
  16976. }
  16977. return null;
  16978. }
  16979. /**
  16980. * @param {?} expr
  16981. * @param {?} ctx
  16982. * @return {?}
  16983. */
  16984. visitWriteKeyExpr(expr, ctx) {
  16985. const /** @type {?} */ lineWasEmpty = ctx.lineIsEmpty();
  16986. if (!lineWasEmpty) {
  16987. ctx.print(expr, '(');
  16988. }
  16989. expr.receiver.visitExpression(this, ctx);
  16990. ctx.print(expr, `[`);
  16991. expr.index.visitExpression(this, ctx);
  16992. ctx.print(expr, `] = `);
  16993. expr.value.visitExpression(this, ctx);
  16994. if (!lineWasEmpty) {
  16995. ctx.print(expr, ')');
  16996. }
  16997. return null;
  16998. }
  16999. /**
  17000. * @param {?} expr
  17001. * @param {?} ctx
  17002. * @return {?}
  17003. */
  17004. visitWritePropExpr(expr, ctx) {
  17005. const /** @type {?} */ lineWasEmpty = ctx.lineIsEmpty();
  17006. if (!lineWasEmpty) {
  17007. ctx.print(expr, '(');
  17008. }
  17009. expr.receiver.visitExpression(this, ctx);
  17010. ctx.print(expr, `.${expr.name} = `);
  17011. expr.value.visitExpression(this, ctx);
  17012. if (!lineWasEmpty) {
  17013. ctx.print(expr, ')');
  17014. }
  17015. return null;
  17016. }
  17017. /**
  17018. * @param {?} expr
  17019. * @param {?} ctx
  17020. * @return {?}
  17021. */
  17022. visitInvokeMethodExpr(expr, ctx) {
  17023. expr.receiver.visitExpression(this, ctx);
  17024. let /** @type {?} */ name = expr.name;
  17025. if (expr.builtin != null) {
  17026. name = this.getBuiltinMethodName(expr.builtin);
  17027. if (name == null) {
  17028. // some builtins just mean to skip the call.
  17029. return null;
  17030. }
  17031. }
  17032. ctx.print(expr, `.${name}(`);
  17033. this.visitAllExpressions(expr.args, ctx, `,`);
  17034. ctx.print(expr, `)`);
  17035. return null;
  17036. }
  17037. /**
  17038. * @param {?} expr
  17039. * @param {?} ctx
  17040. * @return {?}
  17041. */
  17042. visitInvokeFunctionExpr(expr, ctx) {
  17043. expr.fn.visitExpression(this, ctx);
  17044. ctx.print(expr, `(`);
  17045. this.visitAllExpressions(expr.args, ctx, ',');
  17046. ctx.print(expr, `)`);
  17047. return null;
  17048. }
  17049. /**
  17050. * @param {?} ast
  17051. * @param {?} ctx
  17052. * @return {?}
  17053. */
  17054. visitReadVarExpr(ast, ctx) {
  17055. let /** @type {?} */ varName = /** @type {?} */ ((ast.name));
  17056. if (ast.builtin != null) {
  17057. switch (ast.builtin) {
  17058. case BuiltinVar.Super:
  17059. varName = 'super';
  17060. break;
  17061. case BuiltinVar.This:
  17062. varName = 'this';
  17063. break;
  17064. case BuiltinVar.CatchError:
  17065. varName = /** @type {?} */ ((CATCH_ERROR_VAR$1.name));
  17066. break;
  17067. case BuiltinVar.CatchStack:
  17068. varName = /** @type {?} */ ((CATCH_STACK_VAR$1.name));
  17069. break;
  17070. default:
  17071. throw new Error(`Unknown builtin variable ${ast.builtin}`);
  17072. }
  17073. }
  17074. ctx.print(ast, varName);
  17075. return null;
  17076. }
  17077. /**
  17078. * @param {?} ast
  17079. * @param {?} ctx
  17080. * @return {?}
  17081. */
  17082. visitInstantiateExpr(ast, ctx) {
  17083. ctx.print(ast, `new `);
  17084. ast.classExpr.visitExpression(this, ctx);
  17085. ctx.print(ast, `(`);
  17086. this.visitAllExpressions(ast.args, ctx, ',');
  17087. ctx.print(ast, `)`);
  17088. return null;
  17089. }
  17090. /**
  17091. * @param {?} ast
  17092. * @param {?} ctx
  17093. * @return {?}
  17094. */
  17095. visitLiteralExpr(ast, ctx) {
  17096. const /** @type {?} */ value = ast.value;
  17097. if (typeof value === 'string') {
  17098. ctx.print(ast, escapeIdentifier(value, this._escapeDollarInStrings));
  17099. }
  17100. else {
  17101. ctx.print(ast, `${value}`);
  17102. }
  17103. return null;
  17104. }
  17105. /**
  17106. * @param {?} ast
  17107. * @param {?} ctx
  17108. * @return {?}
  17109. */
  17110. visitConditionalExpr(ast, ctx) {
  17111. ctx.print(ast, `(`);
  17112. ast.condition.visitExpression(this, ctx);
  17113. ctx.print(ast, '? ');
  17114. ast.trueCase.visitExpression(this, ctx);
  17115. ctx.print(ast, ': '); /** @type {?} */
  17116. ((ast.falseCase)).visitExpression(this, ctx);
  17117. ctx.print(ast, `)`);
  17118. return null;
  17119. }
  17120. /**
  17121. * @param {?} ast
  17122. * @param {?} ctx
  17123. * @return {?}
  17124. */
  17125. visitNotExpr(ast, ctx) {
  17126. ctx.print(ast, '!');
  17127. ast.condition.visitExpression(this, ctx);
  17128. return null;
  17129. }
  17130. /**
  17131. * @param {?} ast
  17132. * @param {?} ctx
  17133. * @return {?}
  17134. */
  17135. visitAssertNotNullExpr(ast, ctx) {
  17136. ast.condition.visitExpression(this, ctx);
  17137. return null;
  17138. }
  17139. /**
  17140. * @param {?} ast
  17141. * @param {?} ctx
  17142. * @return {?}
  17143. */
  17144. visitBinaryOperatorExpr(ast, ctx) {
  17145. let /** @type {?} */ opStr;
  17146. switch (ast.operator) {
  17147. case BinaryOperator.Equals:
  17148. opStr = '==';
  17149. break;
  17150. case BinaryOperator.Identical:
  17151. opStr = '===';
  17152. break;
  17153. case BinaryOperator.NotEquals:
  17154. opStr = '!=';
  17155. break;
  17156. case BinaryOperator.NotIdentical:
  17157. opStr = '!==';
  17158. break;
  17159. case BinaryOperator.And:
  17160. opStr = '&&';
  17161. break;
  17162. case BinaryOperator.Or:
  17163. opStr = '||';
  17164. break;
  17165. case BinaryOperator.Plus:
  17166. opStr = '+';
  17167. break;
  17168. case BinaryOperator.Minus:
  17169. opStr = '-';
  17170. break;
  17171. case BinaryOperator.Divide:
  17172. opStr = '/';
  17173. break;
  17174. case BinaryOperator.Multiply:
  17175. opStr = '*';
  17176. break;
  17177. case BinaryOperator.Modulo:
  17178. opStr = '%';
  17179. break;
  17180. case BinaryOperator.Lower:
  17181. opStr = '<';
  17182. break;
  17183. case BinaryOperator.LowerEquals:
  17184. opStr = '<=';
  17185. break;
  17186. case BinaryOperator.Bigger:
  17187. opStr = '>';
  17188. break;
  17189. case BinaryOperator.BiggerEquals:
  17190. opStr = '>=';
  17191. break;
  17192. default:
  17193. throw new Error(`Unknown operator ${ast.operator}`);
  17194. }
  17195. ctx.print(ast, `(`);
  17196. ast.lhs.visitExpression(this, ctx);
  17197. ctx.print(ast, ` ${opStr} `);
  17198. ast.rhs.visitExpression(this, ctx);
  17199. ctx.print(ast, `)`);
  17200. return null;
  17201. }
  17202. /**
  17203. * @param {?} ast
  17204. * @param {?} ctx
  17205. * @return {?}
  17206. */
  17207. visitReadPropExpr(ast, ctx) {
  17208. ast.receiver.visitExpression(this, ctx);
  17209. ctx.print(ast, `.`);
  17210. ctx.print(ast, ast.name);
  17211. return null;
  17212. }
  17213. /**
  17214. * @param {?} ast
  17215. * @param {?} ctx
  17216. * @return {?}
  17217. */
  17218. visitReadKeyExpr(ast, ctx) {
  17219. ast.receiver.visitExpression(this, ctx);
  17220. ctx.print(ast, `[`);
  17221. ast.index.visitExpression(this, ctx);
  17222. ctx.print(ast, `]`);
  17223. return null;
  17224. }
  17225. /**
  17226. * @param {?} ast
  17227. * @param {?} ctx
  17228. * @return {?}
  17229. */
  17230. visitLiteralArrayExpr(ast, ctx) {
  17231. ctx.print(ast, `[`);
  17232. this.visitAllExpressions(ast.entries, ctx, ',');
  17233. ctx.print(ast, `]`);
  17234. return null;
  17235. }
  17236. /**
  17237. * @param {?} ast
  17238. * @param {?} ctx
  17239. * @return {?}
  17240. */
  17241. visitLiteralMapExpr(ast, ctx) {
  17242. ctx.print(ast, `{`);
  17243. this.visitAllObjects(entry => {
  17244. ctx.print(ast, `${escapeIdentifier(entry.key, this._escapeDollarInStrings, entry.quoted)}:`);
  17245. entry.value.visitExpression(this, ctx);
  17246. }, ast.entries, ctx, ',');
  17247. ctx.print(ast, `}`);
  17248. return null;
  17249. }
  17250. /**
  17251. * @param {?} ast
  17252. * @param {?} ctx
  17253. * @return {?}
  17254. */
  17255. visitCommaExpr(ast, ctx) {
  17256. ctx.print(ast, '(');
  17257. this.visitAllExpressions(ast.parts, ctx, ',');
  17258. ctx.print(ast, ')');
  17259. return null;
  17260. }
  17261. /**
  17262. * @param {?} expressions
  17263. * @param {?} ctx
  17264. * @param {?} separator
  17265. * @return {?}
  17266. */
  17267. visitAllExpressions(expressions, ctx, separator) {
  17268. this.visitAllObjects(expr => expr.visitExpression(this, ctx), expressions, ctx, separator);
  17269. }
  17270. /**
  17271. * @template T
  17272. * @param {?} handler
  17273. * @param {?} expressions
  17274. * @param {?} ctx
  17275. * @param {?} separator
  17276. * @return {?}
  17277. */
  17278. visitAllObjects(handler, expressions, ctx, separator) {
  17279. let /** @type {?} */ incrementedIndent = false;
  17280. for (let /** @type {?} */ i = 0; i < expressions.length; i++) {
  17281. if (i > 0) {
  17282. if (ctx.lineLength() > 80) {
  17283. ctx.print(null, separator, true);
  17284. if (!incrementedIndent) {
  17285. // continuation are marked with double indent.
  17286. ctx.incIndent();
  17287. ctx.incIndent();
  17288. incrementedIndent = true;
  17289. }
  17290. }
  17291. else {
  17292. ctx.print(null, separator, false);
  17293. }
  17294. }
  17295. handler(expressions[i]);
  17296. }
  17297. if (incrementedIndent) {
  17298. // continuation are marked with double indent.
  17299. ctx.decIndent();
  17300. ctx.decIndent();
  17301. }
  17302. }
  17303. /**
  17304. * @param {?} statements
  17305. * @param {?} ctx
  17306. * @return {?}
  17307. */
  17308. visitAllStatements(statements, ctx) {
  17309. statements.forEach((stmt) => stmt.visitStatement(this, ctx));
  17310. }
  17311. }
  17312. /**
  17313. * @param {?} input
  17314. * @param {?} escapeDollar
  17315. * @param {?=} alwaysQuote
  17316. * @return {?}
  17317. */
  17318. function escapeIdentifier(input, escapeDollar, alwaysQuote = true) {
  17319. if (input == null) {
  17320. return null;
  17321. }
  17322. const /** @type {?} */ body = input.replace(_SINGLE_QUOTE_ESCAPE_STRING_RE, (...match) => {
  17323. if (match[0] == '$') {
  17324. return escapeDollar ? '\\$' : '$';
  17325. }
  17326. else if (match[0] == '\n') {
  17327. return '\\n';
  17328. }
  17329. else if (match[0] == '\r') {
  17330. return '\\r';
  17331. }
  17332. else {
  17333. return `\\${match[0]}`;
  17334. }
  17335. });
  17336. const /** @type {?} */ requiresQuotes = alwaysQuote || !_LEGAL_IDENTIFIER_RE.test(body);
  17337. return requiresQuotes ? `'${body}'` : body;
  17338. }
  17339. /**
  17340. * @param {?} count
  17341. * @return {?}
  17342. */
  17343. function _createIndent(count) {
  17344. let /** @type {?} */ res = '';
  17345. for (let /** @type {?} */ i = 0; i < count; i++) {
  17346. res += _INDENT_WITH;
  17347. }
  17348. return res;
  17349. }
  17350. /**
  17351. * @fileoverview added by tsickle
  17352. * @suppress {checkTypes} checked by tsc
  17353. */
  17354. /**
  17355. * @license
  17356. * Copyright Google Inc. All Rights Reserved.
  17357. *
  17358. * Use of this source code is governed by an MIT-style license that can be
  17359. * found in the LICENSE file at https://angular.io/license
  17360. */
  17361. /**
  17362. * @param {?} ast
  17363. * @return {?}
  17364. */
  17365. function debugOutputAstAsTypeScript(ast) {
  17366. const /** @type {?} */ converter = new _TsEmitterVisitor();
  17367. const /** @type {?} */ ctx = EmitterVisitorContext.createRoot();
  17368. const /** @type {?} */ asts = Array.isArray(ast) ? ast : [ast];
  17369. asts.forEach((ast) => {
  17370. if (ast instanceof Statement) {
  17371. ast.visitStatement(converter, ctx);
  17372. }
  17373. else if (ast instanceof Expression) {
  17374. ast.visitExpression(converter, ctx);
  17375. }
  17376. else if (ast instanceof Type$1) {
  17377. ast.visitType(converter, ctx);
  17378. }
  17379. else {
  17380. throw new Error(`Don't know how to print debug info for ${ast}`);
  17381. }
  17382. });
  17383. return ctx.toSource();
  17384. }
  17385. class TypeScriptEmitter {
  17386. /**
  17387. * @param {?} genFilePath
  17388. * @param {?} stmts
  17389. * @param {?=} preamble
  17390. * @param {?=} emitSourceMaps
  17391. * @param {?=} referenceFilter
  17392. * @return {?}
  17393. */
  17394. emitStatementsAndContext(genFilePath, stmts, preamble = '', emitSourceMaps = true, referenceFilter) {
  17395. const /** @type {?} */ converter = new _TsEmitterVisitor(referenceFilter);
  17396. const /** @type {?} */ ctx = EmitterVisitorContext.createRoot();
  17397. converter.visitAllStatements(stmts, ctx);
  17398. const /** @type {?} */ preambleLines = preamble ? preamble.split('\n') : [];
  17399. converter.reexports.forEach((reexports, exportedModuleName) => {
  17400. const /** @type {?} */ reexportsCode = reexports.map(reexport => `${reexport.name} as ${reexport.as}`).join(',');
  17401. preambleLines.push(`export {${reexportsCode}} from '${exportedModuleName}';`);
  17402. });
  17403. converter.importsWithPrefixes.forEach((prefix, importedModuleName) => {
  17404. // Note: can't write the real word for import as it screws up system.js auto detection...
  17405. preambleLines.push(`imp` +
  17406. `ort * as ${prefix} from '${importedModuleName}';`);
  17407. });
  17408. const /** @type {?} */ sm = emitSourceMaps ?
  17409. ctx.toSourceMapGenerator(genFilePath, preambleLines.length).toJsComment() :
  17410. '';
  17411. const /** @type {?} */ lines = [...preambleLines, ctx.toSource(), sm];
  17412. if (sm) {
  17413. // always add a newline at the end, as some tools have bugs without it.
  17414. lines.push('');
  17415. }
  17416. ctx.setPreambleLineCount(preambleLines.length);
  17417. return { sourceText: lines.join('\n'), context: ctx };
  17418. }
  17419. /**
  17420. * @param {?} genFilePath
  17421. * @param {?} stmts
  17422. * @param {?=} preamble
  17423. * @return {?}
  17424. */
  17425. emitStatements(genFilePath, stmts, preamble = '') {
  17426. return this.emitStatementsAndContext(genFilePath, stmts, preamble).sourceText;
  17427. }
  17428. }
  17429. class _TsEmitterVisitor extends AbstractEmitterVisitor {
  17430. /**
  17431. * @param {?=} referenceFilter
  17432. */
  17433. constructor(referenceFilter) {
  17434. super(false);
  17435. this.referenceFilter = referenceFilter;
  17436. this.typeExpression = 0;
  17437. this.importsWithPrefixes = new Map();
  17438. this.reexports = new Map();
  17439. }
  17440. /**
  17441. * @param {?} t
  17442. * @param {?} ctx
  17443. * @param {?=} defaultType
  17444. * @return {?}
  17445. */
  17446. visitType(t, ctx, defaultType = 'any') {
  17447. if (t) {
  17448. this.typeExpression++;
  17449. t.visitType(this, ctx);
  17450. this.typeExpression--;
  17451. }
  17452. else {
  17453. ctx.print(null, defaultType);
  17454. }
  17455. }
  17456. /**
  17457. * @param {?} ast
  17458. * @param {?} ctx
  17459. * @return {?}
  17460. */
  17461. visitLiteralExpr(ast, ctx) {
  17462. const /** @type {?} */ value = ast.value;
  17463. if (value == null && ast.type != INFERRED_TYPE) {
  17464. ctx.print(ast, `(${value} as any)`);
  17465. return null;
  17466. }
  17467. return super.visitLiteralExpr(ast, ctx);
  17468. }
  17469. /**
  17470. * @param {?} ast
  17471. * @param {?} ctx
  17472. * @return {?}
  17473. */
  17474. visitLiteralArrayExpr(ast, ctx) {
  17475. if (ast.entries.length === 0) {
  17476. ctx.print(ast, '(');
  17477. }
  17478. const /** @type {?} */ result = super.visitLiteralArrayExpr(ast, ctx);
  17479. if (ast.entries.length === 0) {
  17480. ctx.print(ast, ' as any[])');
  17481. }
  17482. return result;
  17483. }
  17484. /**
  17485. * @param {?} ast
  17486. * @param {?} ctx
  17487. * @return {?}
  17488. */
  17489. visitExternalExpr(ast, ctx) {
  17490. this._visitIdentifier(ast.value, ast.typeParams, ctx);
  17491. return null;
  17492. }
  17493. /**
  17494. * @param {?} ast
  17495. * @param {?} ctx
  17496. * @return {?}
  17497. */
  17498. visitAssertNotNullExpr(ast, ctx) {
  17499. const /** @type {?} */ result = super.visitAssertNotNullExpr(ast, ctx);
  17500. ctx.print(ast, '!');
  17501. return result;
  17502. }
  17503. /**
  17504. * @param {?} stmt
  17505. * @param {?} ctx
  17506. * @return {?}
  17507. */
  17508. visitDeclareVarStmt(stmt, ctx) {
  17509. if (stmt.hasModifier(StmtModifier.Exported) && stmt.value instanceof ExternalExpr &&
  17510. !stmt.type) {
  17511. // check for a reexport
  17512. const { name, moduleName } = stmt.value.value;
  17513. if (moduleName) {
  17514. let /** @type {?} */ reexports = this.reexports.get(moduleName);
  17515. if (!reexports) {
  17516. reexports = [];
  17517. this.reexports.set(moduleName, reexports);
  17518. }
  17519. reexports.push({ name: /** @type {?} */ ((name)), as: stmt.name });
  17520. return null;
  17521. }
  17522. }
  17523. if (stmt.hasModifier(StmtModifier.Exported)) {
  17524. ctx.print(stmt, `export `);
  17525. }
  17526. if (stmt.hasModifier(StmtModifier.Final)) {
  17527. ctx.print(stmt, `const`);
  17528. }
  17529. else {
  17530. ctx.print(stmt, `var`);
  17531. }
  17532. ctx.print(stmt, ` ${stmt.name}`);
  17533. this._printColonType(stmt.type, ctx);
  17534. ctx.print(stmt, ` = `);
  17535. stmt.value.visitExpression(this, ctx);
  17536. ctx.println(stmt, `;`);
  17537. return null;
  17538. }
  17539. /**
  17540. * @param {?} ast
  17541. * @param {?} ctx
  17542. * @return {?}
  17543. */
  17544. visitCastExpr(ast, ctx) {
  17545. ctx.print(ast, `(<`); /** @type {?} */
  17546. ((ast.type)).visitType(this, ctx);
  17547. ctx.print(ast, `>`);
  17548. ast.value.visitExpression(this, ctx);
  17549. ctx.print(ast, `)`);
  17550. return null;
  17551. }
  17552. /**
  17553. * @param {?} ast
  17554. * @param {?} ctx
  17555. * @return {?}
  17556. */
  17557. visitInstantiateExpr(ast, ctx) {
  17558. ctx.print(ast, `new `);
  17559. this.typeExpression++;
  17560. ast.classExpr.visitExpression(this, ctx);
  17561. this.typeExpression--;
  17562. ctx.print(ast, `(`);
  17563. this.visitAllExpressions(ast.args, ctx, ',');
  17564. ctx.print(ast, `)`);
  17565. return null;
  17566. }
  17567. /**
  17568. * @param {?} stmt
  17569. * @param {?} ctx
  17570. * @return {?}
  17571. */
  17572. visitDeclareClassStmt(stmt, ctx) {
  17573. ctx.pushClass(stmt);
  17574. if (stmt.hasModifier(StmtModifier.Exported)) {
  17575. ctx.print(stmt, `export `);
  17576. }
  17577. ctx.print(stmt, `class ${stmt.name}`);
  17578. if (stmt.parent != null) {
  17579. ctx.print(stmt, ` extends `);
  17580. this.typeExpression++;
  17581. stmt.parent.visitExpression(this, ctx);
  17582. this.typeExpression--;
  17583. }
  17584. ctx.println(stmt, ` {`);
  17585. ctx.incIndent();
  17586. stmt.fields.forEach((field) => this._visitClassField(field, ctx));
  17587. if (stmt.constructorMethod != null) {
  17588. this._visitClassConstructor(stmt, ctx);
  17589. }
  17590. stmt.getters.forEach((getter) => this._visitClassGetter(getter, ctx));
  17591. stmt.methods.forEach((method) => this._visitClassMethod(method, ctx));
  17592. ctx.decIndent();
  17593. ctx.println(stmt, `}`);
  17594. ctx.popClass();
  17595. return null;
  17596. }
  17597. /**
  17598. * @param {?} field
  17599. * @param {?} ctx
  17600. * @return {?}
  17601. */
  17602. _visitClassField(field, ctx) {
  17603. if (field.hasModifier(StmtModifier.Private)) {
  17604. // comment out as a workaround for #10967
  17605. ctx.print(null, `/*private*/ `);
  17606. }
  17607. ctx.print(null, field.name);
  17608. this._printColonType(field.type, ctx);
  17609. ctx.println(null, `;`);
  17610. }
  17611. /**
  17612. * @param {?} getter
  17613. * @param {?} ctx
  17614. * @return {?}
  17615. */
  17616. _visitClassGetter(getter, ctx) {
  17617. if (getter.hasModifier(StmtModifier.Private)) {
  17618. ctx.print(null, `private `);
  17619. }
  17620. ctx.print(null, `get ${getter.name}()`);
  17621. this._printColonType(getter.type, ctx);
  17622. ctx.println(null, ` {`);
  17623. ctx.incIndent();
  17624. this.visitAllStatements(getter.body, ctx);
  17625. ctx.decIndent();
  17626. ctx.println(null, `}`);
  17627. }
  17628. /**
  17629. * @param {?} stmt
  17630. * @param {?} ctx
  17631. * @return {?}
  17632. */
  17633. _visitClassConstructor(stmt, ctx) {
  17634. ctx.print(stmt, `constructor(`);
  17635. this._visitParams(stmt.constructorMethod.params, ctx);
  17636. ctx.println(stmt, `) {`);
  17637. ctx.incIndent();
  17638. this.visitAllStatements(stmt.constructorMethod.body, ctx);
  17639. ctx.decIndent();
  17640. ctx.println(stmt, `}`);
  17641. }
  17642. /**
  17643. * @param {?} method
  17644. * @param {?} ctx
  17645. * @return {?}
  17646. */
  17647. _visitClassMethod(method, ctx) {
  17648. if (method.hasModifier(StmtModifier.Private)) {
  17649. ctx.print(null, `private `);
  17650. }
  17651. ctx.print(null, `${method.name}(`);
  17652. this._visitParams(method.params, ctx);
  17653. ctx.print(null, `)`);
  17654. this._printColonType(method.type, ctx, 'void');
  17655. ctx.println(null, ` {`);
  17656. ctx.incIndent();
  17657. this.visitAllStatements(method.body, ctx);
  17658. ctx.decIndent();
  17659. ctx.println(null, `}`);
  17660. }
  17661. /**
  17662. * @param {?} ast
  17663. * @param {?} ctx
  17664. * @return {?}
  17665. */
  17666. visitFunctionExpr(ast, ctx) {
  17667. ctx.print(ast, `(`);
  17668. this._visitParams(ast.params, ctx);
  17669. ctx.print(ast, `)`);
  17670. this._printColonType(ast.type, ctx, 'void');
  17671. ctx.println(ast, ` => {`);
  17672. ctx.incIndent();
  17673. this.visitAllStatements(ast.statements, ctx);
  17674. ctx.decIndent();
  17675. ctx.print(ast, `}`);
  17676. return null;
  17677. }
  17678. /**
  17679. * @param {?} stmt
  17680. * @param {?} ctx
  17681. * @return {?}
  17682. */
  17683. visitDeclareFunctionStmt(stmt, ctx) {
  17684. if (stmt.hasModifier(StmtModifier.Exported)) {
  17685. ctx.print(stmt, `export `);
  17686. }
  17687. ctx.print(stmt, `function ${stmt.name}(`);
  17688. this._visitParams(stmt.params, ctx);
  17689. ctx.print(stmt, `)`);
  17690. this._printColonType(stmt.type, ctx, 'void');
  17691. ctx.println(stmt, ` {`);
  17692. ctx.incIndent();
  17693. this.visitAllStatements(stmt.statements, ctx);
  17694. ctx.decIndent();
  17695. ctx.println(stmt, `}`);
  17696. return null;
  17697. }
  17698. /**
  17699. * @param {?} stmt
  17700. * @param {?} ctx
  17701. * @return {?}
  17702. */
  17703. visitTryCatchStmt(stmt, ctx) {
  17704. ctx.println(stmt, `try {`);
  17705. ctx.incIndent();
  17706. this.visitAllStatements(stmt.bodyStmts, ctx);
  17707. ctx.decIndent();
  17708. ctx.println(stmt, `} catch (${CATCH_ERROR_VAR$1.name}) {`);
  17709. ctx.incIndent();
  17710. const /** @type {?} */ catchStmts = [/** @type {?} */ (CATCH_STACK_VAR$1.set(CATCH_ERROR_VAR$1.prop('stack', null)).toDeclStmt(null, [
  17711. StmtModifier.Final
  17712. ]))].concat(stmt.catchStmts);
  17713. this.visitAllStatements(catchStmts, ctx);
  17714. ctx.decIndent();
  17715. ctx.println(stmt, `}`);
  17716. return null;
  17717. }
  17718. /**
  17719. * @param {?} type
  17720. * @param {?} ctx
  17721. * @return {?}
  17722. */
  17723. visitBuiltintType(type, ctx) {
  17724. let /** @type {?} */ typeStr;
  17725. switch (type.name) {
  17726. case BuiltinTypeName.Bool:
  17727. typeStr = 'boolean';
  17728. break;
  17729. case BuiltinTypeName.Dynamic:
  17730. typeStr = 'any';
  17731. break;
  17732. case BuiltinTypeName.Function:
  17733. typeStr = 'Function';
  17734. break;
  17735. case BuiltinTypeName.Number:
  17736. typeStr = 'number';
  17737. break;
  17738. case BuiltinTypeName.Int:
  17739. typeStr = 'number';
  17740. break;
  17741. case BuiltinTypeName.String:
  17742. typeStr = 'string';
  17743. break;
  17744. default:
  17745. throw new Error(`Unsupported builtin type ${type.name}`);
  17746. }
  17747. ctx.print(null, typeStr);
  17748. return null;
  17749. }
  17750. /**
  17751. * @param {?} ast
  17752. * @param {?} ctx
  17753. * @return {?}
  17754. */
  17755. visitExpressionType(ast, ctx) {
  17756. ast.value.visitExpression(this, ctx);
  17757. return null;
  17758. }
  17759. /**
  17760. * @param {?} type
  17761. * @param {?} ctx
  17762. * @return {?}
  17763. */
  17764. visitArrayType(type, ctx) {
  17765. this.visitType(type.of, ctx);
  17766. ctx.print(null, `[]`);
  17767. return null;
  17768. }
  17769. /**
  17770. * @param {?} type
  17771. * @param {?} ctx
  17772. * @return {?}
  17773. */
  17774. visitMapType(type, ctx) {
  17775. ctx.print(null, `{[key: string]:`);
  17776. this.visitType(type.valueType, ctx);
  17777. ctx.print(null, `}`);
  17778. return null;
  17779. }
  17780. /**
  17781. * @param {?} method
  17782. * @return {?}
  17783. */
  17784. getBuiltinMethodName(method) {
  17785. let /** @type {?} */ name;
  17786. switch (method) {
  17787. case BuiltinMethod.ConcatArray:
  17788. name = 'concat';
  17789. break;
  17790. case BuiltinMethod.SubscribeObservable:
  17791. name = 'subscribe';
  17792. break;
  17793. case BuiltinMethod.Bind:
  17794. name = 'bind';
  17795. break;
  17796. default:
  17797. throw new Error(`Unknown builtin method: ${method}`);
  17798. }
  17799. return name;
  17800. }
  17801. /**
  17802. * @param {?} params
  17803. * @param {?} ctx
  17804. * @return {?}
  17805. */
  17806. _visitParams(params, ctx) {
  17807. this.visitAllObjects(param => {
  17808. ctx.print(null, param.name);
  17809. this._printColonType(param.type, ctx);
  17810. }, params, ctx, ',');
  17811. }
  17812. /**
  17813. * @param {?} value
  17814. * @param {?} typeParams
  17815. * @param {?} ctx
  17816. * @return {?}
  17817. */
  17818. _visitIdentifier(value, typeParams, ctx) {
  17819. const { name, moduleName } = value;
  17820. if (this.referenceFilter && this.referenceFilter(value)) {
  17821. ctx.print(null, '(null as any)');
  17822. return;
  17823. }
  17824. if (moduleName) {
  17825. let /** @type {?} */ prefix = this.importsWithPrefixes.get(moduleName);
  17826. if (prefix == null) {
  17827. prefix = `i${this.importsWithPrefixes.size}`;
  17828. this.importsWithPrefixes.set(moduleName, prefix);
  17829. }
  17830. ctx.print(null, `${prefix}.`);
  17831. }
  17832. ctx.print(null, /** @type {?} */ ((name)));
  17833. if (this.typeExpression > 0) {
  17834. // If we are in a type expression that refers to a generic type then supply
  17835. // the required type parameters. If there were not enough type parameters
  17836. // supplied, supply any as the type. Outside a type expression the reference
  17837. // should not supply type parameters and be treated as a simple value reference
  17838. // to the constructor function itself.
  17839. const /** @type {?} */ suppliedParameters = typeParams || [];
  17840. if (suppliedParameters.length > 0) {
  17841. ctx.print(null, `<`);
  17842. this.visitAllObjects(type => type.visitType(this, ctx), /** @type {?} */ ((typeParams)), ctx, ',');
  17843. ctx.print(null, `>`);
  17844. }
  17845. }
  17846. }
  17847. /**
  17848. * @param {?} type
  17849. * @param {?} ctx
  17850. * @param {?=} defaultType
  17851. * @return {?}
  17852. */
  17853. _printColonType(type, ctx, defaultType) {
  17854. if (type !== INFERRED_TYPE) {
  17855. ctx.print(null, ':');
  17856. this.visitType(type, ctx, defaultType);
  17857. }
  17858. }
  17859. }
  17860. /**
  17861. * @fileoverview added by tsickle
  17862. * @suppress {checkTypes} checked by tsc
  17863. */
  17864. /**
  17865. * @license
  17866. * Copyright Google Inc. All Rights Reserved.
  17867. *
  17868. * Use of this source code is governed by an MIT-style license that can be
  17869. * found in the LICENSE file at https://angular.io/license
  17870. */
  17871. /**
  17872. * Resolve a `Type` for {\@link Pipe}.
  17873. *
  17874. * This interface can be overridden by the application developer to create custom behavior.
  17875. *
  17876. * See {\@link Compiler}
  17877. */
  17878. class PipeResolver {
  17879. /**
  17880. * @param {?} _reflector
  17881. */
  17882. constructor(_reflector) {
  17883. this._reflector = _reflector;
  17884. }
  17885. /**
  17886. * @param {?} type
  17887. * @return {?}
  17888. */
  17889. isPipe(type) {
  17890. const /** @type {?} */ typeMetadata = this._reflector.annotations(resolveForwardRef(type));
  17891. return typeMetadata && typeMetadata.some(createPipe.isTypeOf);
  17892. }
  17893. /**
  17894. * Return {\@link Pipe} for a given `Type`.
  17895. * @param {?} type
  17896. * @param {?=} throwIfNotFound
  17897. * @return {?}
  17898. */
  17899. resolve(type, throwIfNotFound = true) {
  17900. const /** @type {?} */ metas = this._reflector.annotations(resolveForwardRef(type));
  17901. if (metas) {
  17902. const /** @type {?} */ annotation = findLast(metas, createPipe.isTypeOf);
  17903. if (annotation) {
  17904. return annotation;
  17905. }
  17906. }
  17907. if (throwIfNotFound) {
  17908. throw new Error(`No Pipe decorator found on ${stringify(type)}`);
  17909. }
  17910. return null;
  17911. }
  17912. }
  17913. /**
  17914. * @fileoverview added by tsickle
  17915. * @suppress {checkTypes} checked by tsc
  17916. */
  17917. /**
  17918. * @license
  17919. * Copyright Google Inc. All Rights Reserved.
  17920. *
  17921. * Use of this source code is governed by an MIT-style license that can be
  17922. * found in the LICENSE file at https://angular.io/license
  17923. */
  17924. /**
  17925. * Map from tagName|propertyName SecurityContext. Properties applying to all tags use '*'.
  17926. */
  17927. const SECURITY_SCHEMA = {};
  17928. /**
  17929. * @param {?} ctx
  17930. * @param {?} specs
  17931. * @return {?}
  17932. */
  17933. function registerContext(ctx, specs) {
  17934. for (const /** @type {?} */ spec of specs)
  17935. SECURITY_SCHEMA[spec.toLowerCase()] = ctx;
  17936. }
  17937. // Case is insignificant below, all element and attribute names are lower-cased for lookup.
  17938. registerContext(SecurityContext.HTML, [
  17939. 'iframe|srcdoc',
  17940. '*|innerHTML',
  17941. '*|outerHTML',
  17942. ]);
  17943. registerContext(SecurityContext.STYLE, ['*|style']);
  17944. // NB: no SCRIPT contexts here, they are never allowed due to the parser stripping them.
  17945. registerContext(SecurityContext.URL, [
  17946. '*|formAction', 'area|href', 'area|ping', 'audio|src', 'a|href',
  17947. 'a|ping', 'blockquote|cite', 'body|background', 'del|cite', 'form|action',
  17948. 'img|src', 'img|srcset', 'input|src', 'ins|cite', 'q|cite',
  17949. 'source|src', 'source|srcset', 'track|src', 'video|poster', 'video|src',
  17950. ]);
  17951. registerContext(SecurityContext.RESOURCE_URL, [
  17952. 'applet|code',
  17953. 'applet|codebase',
  17954. 'base|href',
  17955. 'embed|src',
  17956. 'frame|src',
  17957. 'head|profile',
  17958. 'html|manifest',
  17959. 'iframe|src',
  17960. 'link|href',
  17961. 'media|src',
  17962. 'object|codebase',
  17963. 'object|data',
  17964. 'script|src',
  17965. ]);
  17966. /**
  17967. * @fileoverview added by tsickle
  17968. * @suppress {checkTypes} checked by tsc
  17969. */
  17970. /**
  17971. * @license
  17972. * Copyright Google Inc. All Rights Reserved.
  17973. *
  17974. * Use of this source code is governed by an MIT-style license that can be
  17975. * found in the LICENSE file at https://angular.io/license
  17976. */
  17977. /**
  17978. * @abstract
  17979. */
  17980. class ElementSchemaRegistry {
  17981. }
  17982. /**
  17983. * @fileoverview added by tsickle
  17984. * @suppress {checkTypes} checked by tsc
  17985. */
  17986. /**
  17987. * @license
  17988. * Copyright Google Inc. All Rights Reserved.
  17989. *
  17990. * Use of this source code is governed by an MIT-style license that can be
  17991. * found in the LICENSE file at https://angular.io/license
  17992. */
  17993. const BOOLEAN = 'boolean';
  17994. const NUMBER = 'number';
  17995. const STRING = 'string';
  17996. const OBJECT = 'object';
  17997. /**
  17998. * This array represents the DOM schema. It encodes inheritance, properties, and events.
  17999. *
  18000. * ## Overview
  18001. *
  18002. * Each line represents one kind of element. The `element_inheritance` and properties are joined
  18003. * using `element_inheritance|properties` syntax.
  18004. *
  18005. * ## Element Inheritance
  18006. *
  18007. * The `element_inheritance` can be further subdivided as `element1,element2,...^parentElement`.
  18008. * Here the individual elements are separated by `,` (commas). Every element in the list
  18009. * has identical properties.
  18010. *
  18011. * An `element` may inherit additional properties from `parentElement` If no `^parentElement` is
  18012. * specified then `""` (blank) element is assumed.
  18013. *
  18014. * NOTE: The blank element inherits from root `[Element]` element, the super element of all
  18015. * elements.
  18016. *
  18017. * NOTE an element prefix such as `:svg:` has no special meaning to the schema.
  18018. *
  18019. * ## Properties
  18020. *
  18021. * Each element has a set of properties separated by `,` (commas). Each property can be prefixed
  18022. * by a special character designating its type:
  18023. *
  18024. * - (no prefix): property is a string.
  18025. * - `*`: property represents an event.
  18026. * - `!`: property is a boolean.
  18027. * - `#`: property is a number.
  18028. * - `%`: property is an object.
  18029. *
  18030. * ## Query
  18031. *
  18032. * The class creates an internal squas representation which allows to easily answer the query of
  18033. * if a given property exist on a given element.
  18034. *
  18035. * NOTE: We don't yet support querying for types or events.
  18036. * NOTE: This schema is auto extracted from `schema_extractor.ts` located in the test folder,
  18037. * see dom_element_schema_registry_spec.ts
  18038. */
  18039. const SCHEMA = [
  18040. '[Element]|textContent,%classList,className,id,innerHTML,*beforecopy,*beforecut,*beforepaste,*copy,*cut,*paste,*search,*selectstart,*webkitfullscreenchange,*webkitfullscreenerror,*wheel,outerHTML,#scrollLeft,#scrollTop,slot' +
  18041. ',*message,*mozfullscreenchange,*mozfullscreenerror,*mozpointerlockchange,*mozpointerlockerror,*webglcontextcreationerror,*webglcontextlost,*webglcontextrestored',
  18042. '[HTMLElement]^[Element]|accessKey,contentEditable,dir,!draggable,!hidden,innerText,lang,*abort,*auxclick,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*cuechange,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*gotpointercapture,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*lostpointercapture,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*pause,*play,*playing,*pointercancel,*pointerdown,*pointerenter,*pointerleave,*pointermove,*pointerout,*pointerover,*pointerup,*progress,*ratechange,*reset,*resize,*scroll,*seeked,*seeking,*select,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,outerText,!spellcheck,%style,#tabIndex,title,!translate',
  18043. 'abbr,address,article,aside,b,bdi,bdo,cite,code,dd,dfn,dt,em,figcaption,figure,footer,header,i,kbd,main,mark,nav,noscript,rb,rp,rt,rtc,ruby,s,samp,section,small,strong,sub,sup,u,var,wbr^[HTMLElement]|accessKey,contentEditable,dir,!draggable,!hidden,innerText,lang,*abort,*auxclick,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*cuechange,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*gotpointercapture,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*lostpointercapture,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*pause,*play,*playing,*pointercancel,*pointerdown,*pointerenter,*pointerleave,*pointermove,*pointerout,*pointerover,*pointerup,*progress,*ratechange,*reset,*resize,*scroll,*seeked,*seeking,*select,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,outerText,!spellcheck,%style,#tabIndex,title,!translate',
  18044. 'media^[HTMLElement]|!autoplay,!controls,%controlsList,%crossOrigin,#currentTime,!defaultMuted,#defaultPlaybackRate,!disableRemotePlayback,!loop,!muted,*encrypted,*waitingforkey,#playbackRate,preload,src,%srcObject,#volume',
  18045. ':svg:^[HTMLElement]|*abort,*auxclick,*blur,*cancel,*canplay,*canplaythrough,*change,*click,*close,*contextmenu,*cuechange,*dblclick,*drag,*dragend,*dragenter,*dragleave,*dragover,*dragstart,*drop,*durationchange,*emptied,*ended,*error,*focus,*gotpointercapture,*input,*invalid,*keydown,*keypress,*keyup,*load,*loadeddata,*loadedmetadata,*loadstart,*lostpointercapture,*mousedown,*mouseenter,*mouseleave,*mousemove,*mouseout,*mouseover,*mouseup,*mousewheel,*pause,*play,*playing,*pointercancel,*pointerdown,*pointerenter,*pointerleave,*pointermove,*pointerout,*pointerover,*pointerup,*progress,*ratechange,*reset,*resize,*scroll,*seeked,*seeking,*select,*show,*stalled,*submit,*suspend,*timeupdate,*toggle,*volumechange,*waiting,%style,#tabIndex',
  18046. ':svg:graphics^:svg:|',
  18047. ':svg:animation^:svg:|*begin,*end,*repeat',
  18048. ':svg:geometry^:svg:|',
  18049. ':svg:componentTransferFunction^:svg:|',
  18050. ':svg:gradient^:svg:|',
  18051. ':svg:textContent^:svg:graphics|',
  18052. ':svg:textPositioning^:svg:textContent|',
  18053. 'a^[HTMLElement]|charset,coords,download,hash,host,hostname,href,hreflang,name,password,pathname,ping,port,protocol,referrerPolicy,rel,rev,search,shape,target,text,type,username',
  18054. 'area^[HTMLElement]|alt,coords,download,hash,host,hostname,href,!noHref,password,pathname,ping,port,protocol,referrerPolicy,rel,search,shape,target,username',
  18055. 'audio^media|',
  18056. 'br^[HTMLElement]|clear',
  18057. 'base^[HTMLElement]|href,target',
  18058. 'body^[HTMLElement]|aLink,background,bgColor,link,*beforeunload,*blur,*error,*focus,*hashchange,*languagechange,*load,*message,*offline,*online,*pagehide,*pageshow,*popstate,*rejectionhandled,*resize,*scroll,*storage,*unhandledrejection,*unload,text,vLink',
  18059. 'button^[HTMLElement]|!autofocus,!disabled,formAction,formEnctype,formMethod,!formNoValidate,formTarget,name,type,value',
  18060. 'canvas^[HTMLElement]|#height,#width',
  18061. 'content^[HTMLElement]|select',
  18062. 'dl^[HTMLElement]|!compact',
  18063. 'datalist^[HTMLElement]|',
  18064. 'details^[HTMLElement]|!open',
  18065. 'dialog^[HTMLElement]|!open,returnValue',
  18066. 'dir^[HTMLElement]|!compact',
  18067. 'div^[HTMLElement]|align',
  18068. 'embed^[HTMLElement]|align,height,name,src,type,width',
  18069. 'fieldset^[HTMLElement]|!disabled,name',
  18070. 'font^[HTMLElement]|color,face,size',
  18071. 'form^[HTMLElement]|acceptCharset,action,autocomplete,encoding,enctype,method,name,!noValidate,target',
  18072. 'frame^[HTMLElement]|frameBorder,longDesc,marginHeight,marginWidth,name,!noResize,scrolling,src',
  18073. 'frameset^[HTMLElement]|cols,*beforeunload,*blur,*error,*focus,*hashchange,*languagechange,*load,*message,*offline,*online,*pagehide,*pageshow,*popstate,*rejectionhandled,*resize,*scroll,*storage,*unhandledrejection,*unload,rows',
  18074. 'hr^[HTMLElement]|align,color,!noShade,size,width',
  18075. 'head^[HTMLElement]|',
  18076. 'h1,h2,h3,h4,h5,h6^[HTMLElement]|align',
  18077. 'html^[HTMLElement]|version',
  18078. 'iframe^[HTMLElement]|align,!allowFullscreen,frameBorder,height,longDesc,marginHeight,marginWidth,name,referrerPolicy,%sandbox,scrolling,src,srcdoc,width',
  18079. 'img^[HTMLElement]|align,alt,border,%crossOrigin,#height,#hspace,!isMap,longDesc,lowsrc,name,referrerPolicy,sizes,src,srcset,useMap,#vspace,#width',
  18080. 'input^[HTMLElement]|accept,align,alt,autocapitalize,autocomplete,!autofocus,!checked,!defaultChecked,defaultValue,dirName,!disabled,%files,formAction,formEnctype,formMethod,!formNoValidate,formTarget,#height,!incremental,!indeterminate,max,#maxLength,min,#minLength,!multiple,name,pattern,placeholder,!readOnly,!required,selectionDirection,#selectionEnd,#selectionStart,#size,src,step,type,useMap,value,%valueAsDate,#valueAsNumber,#width',
  18081. 'li^[HTMLElement]|type,#value',
  18082. 'label^[HTMLElement]|htmlFor',
  18083. 'legend^[HTMLElement]|align',
  18084. 'link^[HTMLElement]|as,charset,%crossOrigin,!disabled,href,hreflang,integrity,media,referrerPolicy,rel,%relList,rev,%sizes,target,type',
  18085. 'map^[HTMLElement]|name',
  18086. 'marquee^[HTMLElement]|behavior,bgColor,direction,height,#hspace,#loop,#scrollAmount,#scrollDelay,!trueSpeed,#vspace,width',
  18087. 'menu^[HTMLElement]|!compact',
  18088. 'meta^[HTMLElement]|content,httpEquiv,name,scheme',
  18089. 'meter^[HTMLElement]|#high,#low,#max,#min,#optimum,#value',
  18090. 'ins,del^[HTMLElement]|cite,dateTime',
  18091. 'ol^[HTMLElement]|!compact,!reversed,#start,type',
  18092. 'object^[HTMLElement]|align,archive,border,code,codeBase,codeType,data,!declare,height,#hspace,name,standby,type,useMap,#vspace,width',
  18093. 'optgroup^[HTMLElement]|!disabled,label',
  18094. 'option^[HTMLElement]|!defaultSelected,!disabled,label,!selected,text,value',
  18095. 'output^[HTMLElement]|defaultValue,%htmlFor,name,value',
  18096. 'p^[HTMLElement]|align',
  18097. 'param^[HTMLElement]|name,type,value,valueType',
  18098. 'picture^[HTMLElement]|',
  18099. 'pre^[HTMLElement]|#width',
  18100. 'progress^[HTMLElement]|#max,#value',
  18101. 'q,blockquote,cite^[HTMLElement]|',
  18102. 'script^[HTMLElement]|!async,charset,%crossOrigin,!defer,event,htmlFor,integrity,src,text,type',
  18103. 'select^[HTMLElement]|!autofocus,!disabled,#length,!multiple,name,!required,#selectedIndex,#size,value',
  18104. 'shadow^[HTMLElement]|',
  18105. 'slot^[HTMLElement]|name',
  18106. 'source^[HTMLElement]|media,sizes,src,srcset,type',
  18107. 'span^[HTMLElement]|',
  18108. 'style^[HTMLElement]|!disabled,media,type',
  18109. 'caption^[HTMLElement]|align',
  18110. 'th,td^[HTMLElement]|abbr,align,axis,bgColor,ch,chOff,#colSpan,headers,height,!noWrap,#rowSpan,scope,vAlign,width',
  18111. 'col,colgroup^[HTMLElement]|align,ch,chOff,#span,vAlign,width',
  18112. 'table^[HTMLElement]|align,bgColor,border,%caption,cellPadding,cellSpacing,frame,rules,summary,%tFoot,%tHead,width',
  18113. 'tr^[HTMLElement]|align,bgColor,ch,chOff,vAlign',
  18114. 'tfoot,thead,tbody^[HTMLElement]|align,ch,chOff,vAlign',
  18115. 'template^[HTMLElement]|',
  18116. 'textarea^[HTMLElement]|autocapitalize,!autofocus,#cols,defaultValue,dirName,!disabled,#maxLength,#minLength,name,placeholder,!readOnly,!required,#rows,selectionDirection,#selectionEnd,#selectionStart,value,wrap',
  18117. 'title^[HTMLElement]|text',
  18118. 'track^[HTMLElement]|!default,kind,label,src,srclang',
  18119. 'ul^[HTMLElement]|!compact,type',
  18120. 'unknown^[HTMLElement]|',
  18121. 'video^media|#height,poster,#width',
  18122. ':svg:a^:svg:graphics|',
  18123. ':svg:animate^:svg:animation|',
  18124. ':svg:animateMotion^:svg:animation|',
  18125. ':svg:animateTransform^:svg:animation|',
  18126. ':svg:circle^:svg:geometry|',
  18127. ':svg:clipPath^:svg:graphics|',
  18128. ':svg:defs^:svg:graphics|',
  18129. ':svg:desc^:svg:|',
  18130. ':svg:discard^:svg:|',
  18131. ':svg:ellipse^:svg:geometry|',
  18132. ':svg:feBlend^:svg:|',
  18133. ':svg:feColorMatrix^:svg:|',
  18134. ':svg:feComponentTransfer^:svg:|',
  18135. ':svg:feComposite^:svg:|',
  18136. ':svg:feConvolveMatrix^:svg:|',
  18137. ':svg:feDiffuseLighting^:svg:|',
  18138. ':svg:feDisplacementMap^:svg:|',
  18139. ':svg:feDistantLight^:svg:|',
  18140. ':svg:feDropShadow^:svg:|',
  18141. ':svg:feFlood^:svg:|',
  18142. ':svg:feFuncA^:svg:componentTransferFunction|',
  18143. ':svg:feFuncB^:svg:componentTransferFunction|',
  18144. ':svg:feFuncG^:svg:componentTransferFunction|',
  18145. ':svg:feFuncR^:svg:componentTransferFunction|',
  18146. ':svg:feGaussianBlur^:svg:|',
  18147. ':svg:feImage^:svg:|',
  18148. ':svg:feMerge^:svg:|',
  18149. ':svg:feMergeNode^:svg:|',
  18150. ':svg:feMorphology^:svg:|',
  18151. ':svg:feOffset^:svg:|',
  18152. ':svg:fePointLight^:svg:|',
  18153. ':svg:feSpecularLighting^:svg:|',
  18154. ':svg:feSpotLight^:svg:|',
  18155. ':svg:feTile^:svg:|',
  18156. ':svg:feTurbulence^:svg:|',
  18157. ':svg:filter^:svg:|',
  18158. ':svg:foreignObject^:svg:graphics|',
  18159. ':svg:g^:svg:graphics|',
  18160. ':svg:image^:svg:graphics|',
  18161. ':svg:line^:svg:geometry|',
  18162. ':svg:linearGradient^:svg:gradient|',
  18163. ':svg:mpath^:svg:|',
  18164. ':svg:marker^:svg:|',
  18165. ':svg:mask^:svg:|',
  18166. ':svg:metadata^:svg:|',
  18167. ':svg:path^:svg:geometry|',
  18168. ':svg:pattern^:svg:|',
  18169. ':svg:polygon^:svg:geometry|',
  18170. ':svg:polyline^:svg:geometry|',
  18171. ':svg:radialGradient^:svg:gradient|',
  18172. ':svg:rect^:svg:geometry|',
  18173. ':svg:svg^:svg:graphics|#currentScale,#zoomAndPan',
  18174. ':svg:script^:svg:|type',
  18175. ':svg:set^:svg:animation|',
  18176. ':svg:stop^:svg:|',
  18177. ':svg:style^:svg:|!disabled,media,title,type',
  18178. ':svg:switch^:svg:graphics|',
  18179. ':svg:symbol^:svg:|',
  18180. ':svg:tspan^:svg:textPositioning|',
  18181. ':svg:text^:svg:textPositioning|',
  18182. ':svg:textPath^:svg:textContent|',
  18183. ':svg:title^:svg:|',
  18184. ':svg:use^:svg:graphics|',
  18185. ':svg:view^:svg:|#zoomAndPan',
  18186. 'data^[HTMLElement]|value',
  18187. 'keygen^[HTMLElement]|!autofocus,challenge,!disabled,form,keytype,name',
  18188. 'menuitem^[HTMLElement]|type,label,icon,!disabled,!checked,radiogroup,!default',
  18189. 'summary^[HTMLElement]|',
  18190. 'time^[HTMLElement]|dateTime',
  18191. ':svg:cursor^:svg:|',
  18192. ];
  18193. const _ATTR_TO_PROP = {
  18194. 'class': 'className',
  18195. 'for': 'htmlFor',
  18196. 'formaction': 'formAction',
  18197. 'innerHtml': 'innerHTML',
  18198. 'readonly': 'readOnly',
  18199. 'tabindex': 'tabIndex',
  18200. };
  18201. class DomElementSchemaRegistry extends ElementSchemaRegistry {
  18202. constructor() {
  18203. super();
  18204. this._schema = {};
  18205. SCHEMA.forEach(encodedType => {
  18206. const /** @type {?} */ type = {};
  18207. const [strType, strProperties] = encodedType.split('|');
  18208. const /** @type {?} */ properties = strProperties.split(',');
  18209. const [typeNames, superName] = strType.split('^');
  18210. typeNames.split(',').forEach(tag => this._schema[tag.toLowerCase()] = type);
  18211. const /** @type {?} */ superType = superName && this._schema[superName.toLowerCase()];
  18212. if (superType) {
  18213. Object.keys(superType).forEach((prop) => { type[prop] = superType[prop]; });
  18214. }
  18215. properties.forEach((property) => {
  18216. if (property.length > 0) {
  18217. switch (property[0]) {
  18218. case '*':
  18219. // We don't yet support events.
  18220. // If ever allowing to bind to events, GO THROUGH A SECURITY REVIEW, allowing events
  18221. // will
  18222. // almost certainly introduce bad XSS vulnerabilities.
  18223. // type[property.substring(1)] = EVENT;
  18224. break;
  18225. case '!':
  18226. type[property.substring(1)] = BOOLEAN;
  18227. break;
  18228. case '#':
  18229. type[property.substring(1)] = NUMBER;
  18230. break;
  18231. case '%':
  18232. type[property.substring(1)] = OBJECT;
  18233. break;
  18234. default:
  18235. type[property] = STRING;
  18236. }
  18237. }
  18238. });
  18239. });
  18240. }
  18241. /**
  18242. * @param {?} tagName
  18243. * @param {?} propName
  18244. * @param {?} schemaMetas
  18245. * @return {?}
  18246. */
  18247. hasProperty(tagName, propName, schemaMetas) {
  18248. if (schemaMetas.some((schema) => schema.name === NO_ERRORS_SCHEMA.name)) {
  18249. return true;
  18250. }
  18251. if (tagName.indexOf('-') > -1) {
  18252. if (isNgContainer(tagName) || isNgContent(tagName)) {
  18253. return false;
  18254. }
  18255. if (schemaMetas.some((schema) => schema.name === CUSTOM_ELEMENTS_SCHEMA.name)) {
  18256. // Can't tell now as we don't know which properties a custom element will get
  18257. // once it is instantiated
  18258. return true;
  18259. }
  18260. }
  18261. const /** @type {?} */ elementProperties = this._schema[tagName.toLowerCase()] || this._schema['unknown'];
  18262. return !!elementProperties[propName];
  18263. }
  18264. /**
  18265. * @param {?} tagName
  18266. * @param {?} schemaMetas
  18267. * @return {?}
  18268. */
  18269. hasElement(tagName, schemaMetas) {
  18270. if (schemaMetas.some((schema) => schema.name === NO_ERRORS_SCHEMA.name)) {
  18271. return true;
  18272. }
  18273. if (tagName.indexOf('-') > -1) {
  18274. if (isNgContainer(tagName) || isNgContent(tagName)) {
  18275. return true;
  18276. }
  18277. if (schemaMetas.some((schema) => schema.name === CUSTOM_ELEMENTS_SCHEMA.name)) {
  18278. // Allow any custom elements
  18279. return true;
  18280. }
  18281. }
  18282. return !!this._schema[tagName.toLowerCase()];
  18283. }
  18284. /**
  18285. * securityContext returns the security context for the given property on the given DOM tag.
  18286. *
  18287. * Tag and property name are statically known and cannot change at runtime, i.e. it is not
  18288. * possible to bind a value into a changing attribute or tag name.
  18289. *
  18290. * The filtering is white list based. All attributes in the schema above are assumed to have the
  18291. * 'NONE' security context, i.e. that they are safe inert string values. Only specific well known
  18292. * attack vectors are assigned their appropriate context.
  18293. * @param {?} tagName
  18294. * @param {?} propName
  18295. * @param {?} isAttribute
  18296. * @return {?}
  18297. */
  18298. securityContext(tagName, propName, isAttribute) {
  18299. if (isAttribute) {
  18300. // NB: For security purposes, use the mapped property name, not the attribute name.
  18301. propName = this.getMappedPropName(propName);
  18302. }
  18303. // Make sure comparisons are case insensitive, so that case differences between attribute and
  18304. // property names do not have a security impact.
  18305. tagName = tagName.toLowerCase();
  18306. propName = propName.toLowerCase();
  18307. let /** @type {?} */ ctx = SECURITY_SCHEMA[tagName + '|' + propName];
  18308. if (ctx) {
  18309. return ctx;
  18310. }
  18311. ctx = SECURITY_SCHEMA['*|' + propName];
  18312. return ctx ? ctx : SecurityContext.NONE;
  18313. }
  18314. /**
  18315. * @param {?} propName
  18316. * @return {?}
  18317. */
  18318. getMappedPropName(propName) { return _ATTR_TO_PROP[propName] || propName; }
  18319. /**
  18320. * @return {?}
  18321. */
  18322. getDefaultComponentElementName() { return 'ng-component'; }
  18323. /**
  18324. * @param {?} name
  18325. * @return {?}
  18326. */
  18327. validateProperty(name) {
  18328. if (name.toLowerCase().startsWith('on')) {
  18329. const /** @type {?} */ msg = `Binding to event property '${name}' is disallowed for security reasons, ` +
  18330. `please use (${name.slice(2)})=...` +
  18331. `\nIf '${name}' is a directive input, make sure the directive is imported by the` +
  18332. ` current module.`;
  18333. return { error: true, msg: msg };
  18334. }
  18335. else {
  18336. return { error: false };
  18337. }
  18338. }
  18339. /**
  18340. * @param {?} name
  18341. * @return {?}
  18342. */
  18343. validateAttribute(name) {
  18344. if (name.toLowerCase().startsWith('on')) {
  18345. const /** @type {?} */ msg = `Binding to event attribute '${name}' is disallowed for security reasons, ` +
  18346. `please use (${name.slice(2)})=...`;
  18347. return { error: true, msg: msg };
  18348. }
  18349. else {
  18350. return { error: false };
  18351. }
  18352. }
  18353. /**
  18354. * @return {?}
  18355. */
  18356. allKnownElementNames() { return Object.keys(this._schema); }
  18357. /**
  18358. * @param {?} propName
  18359. * @return {?}
  18360. */
  18361. normalizeAnimationStyleProperty(propName) {
  18362. return dashCaseToCamelCase(propName);
  18363. }
  18364. /**
  18365. * @param {?} camelCaseProp
  18366. * @param {?} userProvidedProp
  18367. * @param {?} val
  18368. * @return {?}
  18369. */
  18370. normalizeAnimationStyleValue(camelCaseProp, userProvidedProp, val) {
  18371. let /** @type {?} */ unit = '';
  18372. const /** @type {?} */ strVal = val.toString().trim();
  18373. let /** @type {?} */ errorMsg = /** @type {?} */ ((null));
  18374. if (_isPixelDimensionStyle(camelCaseProp) && val !== 0 && val !== '0') {
  18375. if (typeof val === 'number') {
  18376. unit = 'px';
  18377. }
  18378. else {
  18379. const /** @type {?} */ valAndSuffixMatch = val.match(/^[+-]?[\d\.]+([a-z]*)$/);
  18380. if (valAndSuffixMatch && valAndSuffixMatch[1].length == 0) {
  18381. errorMsg = `Please provide a CSS unit value for ${userProvidedProp}:${val}`;
  18382. }
  18383. }
  18384. }
  18385. return { error: errorMsg, value: strVal + unit };
  18386. }
  18387. }
  18388. /**
  18389. * @param {?} prop
  18390. * @return {?}
  18391. */
  18392. function _isPixelDimensionStyle(prop) {
  18393. switch (prop) {
  18394. case 'width':
  18395. case 'height':
  18396. case 'minWidth':
  18397. case 'minHeight':
  18398. case 'maxWidth':
  18399. case 'maxHeight':
  18400. case 'left':
  18401. case 'top':
  18402. case 'bottom':
  18403. case 'right':
  18404. case 'fontSize':
  18405. case 'outlineWidth':
  18406. case 'outlineOffset':
  18407. case 'paddingTop':
  18408. case 'paddingLeft':
  18409. case 'paddingBottom':
  18410. case 'paddingRight':
  18411. case 'marginTop':
  18412. case 'marginLeft':
  18413. case 'marginBottom':
  18414. case 'marginRight':
  18415. case 'borderRadius':
  18416. case 'borderWidth':
  18417. case 'borderTopWidth':
  18418. case 'borderLeftWidth':
  18419. case 'borderRightWidth':
  18420. case 'borderBottomWidth':
  18421. case 'textIndent':
  18422. return true;
  18423. default:
  18424. return false;
  18425. }
  18426. }
  18427. /**
  18428. * @fileoverview added by tsickle
  18429. * @suppress {checkTypes} checked by tsc
  18430. */
  18431. /**
  18432. * @license
  18433. * Copyright Google Inc. All Rights Reserved.
  18434. *
  18435. * Use of this source code is governed by an MIT-style license that can be
  18436. * found in the LICENSE file at https://angular.io/license
  18437. */
  18438. /**
  18439. * This file is a port of shadowCSS from webcomponents.js to TypeScript.
  18440. *
  18441. * Please make sure to keep to edits in sync with the source file.
  18442. *
  18443. * Source:
  18444. * https://github.com/webcomponents/webcomponentsjs/blob/4efecd7e0e/src/ShadowCSS/ShadowCSS.js
  18445. *
  18446. * The original file level comment is reproduced below
  18447. */
  18448. /*
  18449. This is a limited shim for ShadowDOM css styling.
  18450. https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#styles
  18451. The intention here is to support only the styling features which can be
  18452. relatively simply implemented. The goal is to allow users to avoid the
  18453. most obvious pitfalls and do so without compromising performance significantly.
  18454. For ShadowDOM styling that's not covered here, a set of best practices
  18455. can be provided that should allow users to accomplish more complex styling.
  18456. The following is a list of specific ShadowDOM styling features and a brief
  18457. discussion of the approach used to shim.
  18458. Shimmed features:
  18459. * :host, :host-context: ShadowDOM allows styling of the shadowRoot's host
  18460. element using the :host rule. To shim this feature, the :host styles are
  18461. reformatted and prefixed with a given scope name and promoted to a
  18462. document level stylesheet.
  18463. For example, given a scope name of .foo, a rule like this:
  18464. :host {
  18465. background: red;
  18466. }
  18467. }
  18468. becomes:
  18469. .foo {
  18470. background: red;
  18471. }
  18472. * encapsulation: Styles defined within ShadowDOM, apply only to
  18473. dom inside the ShadowDOM. Polymer uses one of two techniques to implement
  18474. this feature.
  18475. By default, rules are prefixed with the host element tag name
  18476. as a descendant selector. This ensures styling does not leak out of the 'top'
  18477. of the element's ShadowDOM. For example,
  18478. div {
  18479. font-weight: bold;
  18480. }
  18481. becomes:
  18482. x-foo div {
  18483. font-weight: bold;
  18484. }
  18485. becomes:
  18486. Alternatively, if WebComponents.ShadowCSS.strictStyling is set to true then
  18487. selectors are scoped by adding an attribute selector suffix to each
  18488. simple selector that contains the host element tag name. Each element
  18489. in the element's ShadowDOM template is also given the scope attribute.
  18490. Thus, these rules match only elements that have the scope attribute.
  18491. For example, given a scope name of x-foo, a rule like this:
  18492. div {
  18493. font-weight: bold;
  18494. }
  18495. becomes:
  18496. div[x-foo] {
  18497. font-weight: bold;
  18498. }
  18499. Note that elements that are dynamically added to a scope must have the scope
  18500. selector added to them manually.
  18501. * upper/lower bound encapsulation: Styles which are defined outside a
  18502. shadowRoot should not cross the ShadowDOM boundary and should not apply
  18503. inside a shadowRoot.
  18504. This styling behavior is not emulated. Some possible ways to do this that
  18505. were rejected due to complexity and/or performance concerns include: (1) reset
  18506. every possible property for every possible selector for a given scope name;
  18507. (2) re-implement css in javascript.
  18508. As an alternative, users should make sure to use selectors
  18509. specific to the scope in which they are working.
  18510. * ::distributed: This behavior is not emulated. It's often not necessary
  18511. to style the contents of a specific insertion point and instead, descendants
  18512. of the host element can be styled selectively. Users can also create an
  18513. extra node around an insertion point and style that node's contents
  18514. via descendent selectors. For example, with a shadowRoot like this:
  18515. <style>
  18516. ::content(div) {
  18517. background: red;
  18518. }
  18519. </style>
  18520. <content></content>
  18521. could become:
  18522. <style>
  18523. / *@polyfill .content-container div * /
  18524. ::content(div) {
  18525. background: red;
  18526. }
  18527. </style>
  18528. <div class="content-container">
  18529. <content></content>
  18530. </div>
  18531. Note the use of @polyfill in the comment above a ShadowDOM specific style
  18532. declaration. This is a directive to the styling shim to use the selector
  18533. in comments in lieu of the next selector when running under polyfill.
  18534. */
  18535. class ShadowCss {
  18536. constructor() {
  18537. this.strictStyling = true;
  18538. }
  18539. /**
  18540. * @param {?} cssText
  18541. * @param {?} selector
  18542. * @param {?=} hostSelector
  18543. * @return {?}
  18544. */
  18545. shimCssText(cssText, selector, hostSelector = '') {
  18546. const /** @type {?} */ commentsWithHash = extractCommentsWithHash(cssText);
  18547. cssText = stripComments(cssText);
  18548. cssText = this._insertDirectives(cssText);
  18549. const /** @type {?} */ scopedCssText = this._scopeCssText(cssText, selector, hostSelector);
  18550. return [scopedCssText, ...commentsWithHash].join('\n');
  18551. }
  18552. /**
  18553. * @param {?} cssText
  18554. * @return {?}
  18555. */
  18556. _insertDirectives(cssText) {
  18557. cssText = this._insertPolyfillDirectivesInCssText(cssText);
  18558. return this._insertPolyfillRulesInCssText(cssText);
  18559. }
  18560. /**
  18561. * @param {?} cssText
  18562. * @return {?}
  18563. */
  18564. _insertPolyfillDirectivesInCssText(cssText) {
  18565. // Difference with webcomponents.js: does not handle comments
  18566. return cssText.replace(_cssContentNextSelectorRe, function (...m) { return m[2] + '{'; });
  18567. }
  18568. /**
  18569. * @param {?} cssText
  18570. * @return {?}
  18571. */
  18572. _insertPolyfillRulesInCssText(cssText) {
  18573. // Difference with webcomponents.js: does not handle comments
  18574. return cssText.replace(_cssContentRuleRe, (...m) => {
  18575. const /** @type {?} */ rule = m[0].replace(m[1], '').replace(m[2], '');
  18576. return m[4] + rule;
  18577. });
  18578. }
  18579. /**
  18580. * @param {?} cssText
  18581. * @param {?} scopeSelector
  18582. * @param {?} hostSelector
  18583. * @return {?}
  18584. */
  18585. _scopeCssText(cssText, scopeSelector, hostSelector) {
  18586. const /** @type {?} */ unscopedRules = this._extractUnscopedRulesFromCssText(cssText);
  18587. // replace :host and :host-context -shadowcsshost and -shadowcsshost respectively
  18588. cssText = this._insertPolyfillHostInCssText(cssText);
  18589. cssText = this._convertColonHost(cssText);
  18590. cssText = this._convertColonHostContext(cssText);
  18591. cssText = this._convertShadowDOMSelectors(cssText);
  18592. if (scopeSelector) {
  18593. cssText = this._scopeSelectors(cssText, scopeSelector, hostSelector);
  18594. }
  18595. cssText = cssText + '\n' + unscopedRules;
  18596. return cssText.trim();
  18597. }
  18598. /**
  18599. * @param {?} cssText
  18600. * @return {?}
  18601. */
  18602. _extractUnscopedRulesFromCssText(cssText) {
  18603. // Difference with webcomponents.js: does not handle comments
  18604. let /** @type {?} */ r = '';
  18605. let /** @type {?} */ m;
  18606. _cssContentUnscopedRuleRe.lastIndex = 0;
  18607. while ((m = _cssContentUnscopedRuleRe.exec(cssText)) !== null) {
  18608. const /** @type {?} */ rule = m[0].replace(m[2], '').replace(m[1], m[4]);
  18609. r += rule + '\n\n';
  18610. }
  18611. return r;
  18612. }
  18613. /**
  18614. * @param {?} cssText
  18615. * @return {?}
  18616. */
  18617. _convertColonHost(cssText) {
  18618. return this._convertColonRule(cssText, _cssColonHostRe, this._colonHostPartReplacer);
  18619. }
  18620. /**
  18621. * @param {?} cssText
  18622. * @return {?}
  18623. */
  18624. _convertColonHostContext(cssText) {
  18625. return this._convertColonRule(cssText, _cssColonHostContextRe, this._colonHostContextPartReplacer);
  18626. }
  18627. /**
  18628. * @param {?} cssText
  18629. * @param {?} regExp
  18630. * @param {?} partReplacer
  18631. * @return {?}
  18632. */
  18633. _convertColonRule(cssText, regExp, partReplacer) {
  18634. // m[1] = :host(-context), m[2] = contents of (), m[3] rest of rule
  18635. return cssText.replace(regExp, function (...m) {
  18636. if (m[2]) {
  18637. const /** @type {?} */ parts = m[2].split(',');
  18638. const /** @type {?} */ r = [];
  18639. for (let /** @type {?} */ i = 0; i < parts.length; i++) {
  18640. const /** @type {?} */ p = parts[i].trim();
  18641. if (!p)
  18642. break;
  18643. r.push(partReplacer(_polyfillHostNoCombinator, p, m[3]));
  18644. }
  18645. return r.join(',');
  18646. }
  18647. else {
  18648. return _polyfillHostNoCombinator + m[3];
  18649. }
  18650. });
  18651. }
  18652. /**
  18653. * @param {?} host
  18654. * @param {?} part
  18655. * @param {?} suffix
  18656. * @return {?}
  18657. */
  18658. _colonHostContextPartReplacer(host, part, suffix) {
  18659. if (part.indexOf(_polyfillHost) > -1) {
  18660. return this._colonHostPartReplacer(host, part, suffix);
  18661. }
  18662. else {
  18663. return host + part + suffix + ', ' + part + ' ' + host + suffix;
  18664. }
  18665. }
  18666. /**
  18667. * @param {?} host
  18668. * @param {?} part
  18669. * @param {?} suffix
  18670. * @return {?}
  18671. */
  18672. _colonHostPartReplacer(host, part, suffix) {
  18673. return host + part.replace(_polyfillHost, '') + suffix;
  18674. }
  18675. /**
  18676. * @param {?} cssText
  18677. * @return {?}
  18678. */
  18679. _convertShadowDOMSelectors(cssText) {
  18680. return _shadowDOMSelectorsRe.reduce((result, pattern) => result.replace(pattern, ' '), cssText);
  18681. }
  18682. /**
  18683. * @param {?} cssText
  18684. * @param {?} scopeSelector
  18685. * @param {?} hostSelector
  18686. * @return {?}
  18687. */
  18688. _scopeSelectors(cssText, scopeSelector, hostSelector) {
  18689. return processRules(cssText, (rule) => {
  18690. let /** @type {?} */ selector = rule.selector;
  18691. let /** @type {?} */ content = rule.content;
  18692. if (rule.selector[0] != '@') {
  18693. selector =
  18694. this._scopeSelector(rule.selector, scopeSelector, hostSelector, this.strictStyling);
  18695. }
  18696. else if (rule.selector.startsWith('@media') || rule.selector.startsWith('@supports') ||
  18697. rule.selector.startsWith('@page') || rule.selector.startsWith('@document')) {
  18698. content = this._scopeSelectors(rule.content, scopeSelector, hostSelector);
  18699. }
  18700. return new CssRule(selector, content);
  18701. });
  18702. }
  18703. /**
  18704. * @param {?} selector
  18705. * @param {?} scopeSelector
  18706. * @param {?} hostSelector
  18707. * @param {?} strict
  18708. * @return {?}
  18709. */
  18710. _scopeSelector(selector, scopeSelector, hostSelector, strict) {
  18711. return selector.split(',')
  18712. .map(part => part.trim().split(_shadowDeepSelectors))
  18713. .map((deepParts) => {
  18714. const [shallowPart, ...otherParts] = deepParts;
  18715. const /** @type {?} */ applyScope = (shallowPart) => {
  18716. if (this._selectorNeedsScoping(shallowPart, scopeSelector)) {
  18717. return strict ?
  18718. this._applyStrictSelectorScope(shallowPart, scopeSelector, hostSelector) :
  18719. this._applySelectorScope(shallowPart, scopeSelector, hostSelector);
  18720. }
  18721. else {
  18722. return shallowPart;
  18723. }
  18724. };
  18725. return [applyScope(shallowPart), ...otherParts].join(' ');
  18726. })
  18727. .join(', ');
  18728. }
  18729. /**
  18730. * @param {?} selector
  18731. * @param {?} scopeSelector
  18732. * @return {?}
  18733. */
  18734. _selectorNeedsScoping(selector, scopeSelector) {
  18735. const /** @type {?} */ re = this._makeScopeMatcher(scopeSelector);
  18736. return !re.test(selector);
  18737. }
  18738. /**
  18739. * @param {?} scopeSelector
  18740. * @return {?}
  18741. */
  18742. _makeScopeMatcher(scopeSelector) {
  18743. const /** @type {?} */ lre = /\[/g;
  18744. const /** @type {?} */ rre = /\]/g;
  18745. scopeSelector = scopeSelector.replace(lre, '\\[').replace(rre, '\\]');
  18746. return new RegExp('^(' + scopeSelector + ')' + _selectorReSuffix, 'm');
  18747. }
  18748. /**
  18749. * @param {?} selector
  18750. * @param {?} scopeSelector
  18751. * @param {?} hostSelector
  18752. * @return {?}
  18753. */
  18754. _applySelectorScope(selector, scopeSelector, hostSelector) {
  18755. // Difference from webcomponents.js: scopeSelector could not be an array
  18756. return this._applySimpleSelectorScope(selector, scopeSelector, hostSelector);
  18757. }
  18758. /**
  18759. * @param {?} selector
  18760. * @param {?} scopeSelector
  18761. * @param {?} hostSelector
  18762. * @return {?}
  18763. */
  18764. _applySimpleSelectorScope(selector, scopeSelector, hostSelector) {
  18765. // In Android browser, the lastIndex is not reset when the regex is used in String.replace()
  18766. _polyfillHostRe.lastIndex = 0;
  18767. if (_polyfillHostRe.test(selector)) {
  18768. const /** @type {?} */ replaceBy = this.strictStyling ? `[${hostSelector}]` : scopeSelector;
  18769. return selector
  18770. .replace(_polyfillHostNoCombinatorRe, (hnc, selector) => {
  18771. return selector.replace(/([^:]*)(:*)(.*)/, (_, before, colon, after) => {
  18772. return before + replaceBy + colon + after;
  18773. });
  18774. })
  18775. .replace(_polyfillHostRe, replaceBy + ' ');
  18776. }
  18777. return scopeSelector + ' ' + selector;
  18778. }
  18779. /**
  18780. * @param {?} selector
  18781. * @param {?} scopeSelector
  18782. * @param {?} hostSelector
  18783. * @return {?}
  18784. */
  18785. _applyStrictSelectorScope(selector, scopeSelector, hostSelector) {
  18786. const /** @type {?} */ isRe = /\[is=([^\]]*)\]/g;
  18787. scopeSelector = scopeSelector.replace(isRe, (_, ...parts) => parts[0]);
  18788. const /** @type {?} */ attrName = '[' + scopeSelector + ']';
  18789. const /** @type {?} */ _scopeSelectorPart = (p) => {
  18790. let /** @type {?} */ scopedP = p.trim();
  18791. if (!scopedP) {
  18792. return '';
  18793. }
  18794. if (p.indexOf(_polyfillHostNoCombinator) > -1) {
  18795. scopedP = this._applySimpleSelectorScope(p, scopeSelector, hostSelector);
  18796. }
  18797. else {
  18798. // remove :host since it should be unnecessary
  18799. const /** @type {?} */ t = p.replace(_polyfillHostRe, '');
  18800. if (t.length > 0) {
  18801. const /** @type {?} */ matches = t.match(/([^:]*)(:*)(.*)/);
  18802. if (matches) {
  18803. scopedP = matches[1] + attrName + matches[2] + matches[3];
  18804. }
  18805. }
  18806. }
  18807. return scopedP;
  18808. };
  18809. const /** @type {?} */ safeContent = new SafeSelector(selector);
  18810. selector = safeContent.content();
  18811. let /** @type {?} */ scopedSelector = '';
  18812. let /** @type {?} */ startIndex = 0;
  18813. let /** @type {?} */ res;
  18814. const /** @type {?} */ sep = /( |>|\+|~(?!=))\s*/g;
  18815. // If a selector appears before :host it should not be shimmed as it
  18816. // matches on ancestor elements and not on elements in the host's shadow
  18817. // `:host-context(div)` is transformed to
  18818. // `-shadowcsshost-no-combinatordiv, div -shadowcsshost-no-combinator`
  18819. // the `div` is not part of the component in the 2nd selectors and should not be scoped.
  18820. // Historically `component-tag:host` was matching the component so we also want to preserve
  18821. // this behavior to avoid breaking legacy apps (it should not match).
  18822. // The behavior should be:
  18823. // - `tag:host` -> `tag[h]` (this is to avoid breaking legacy apps, should not match anything)
  18824. // - `tag :host` -> `tag [h]` (`tag` is not scoped because it's considered part of a
  18825. // `:host-context(tag)`)
  18826. const /** @type {?} */ hasHost = selector.indexOf(_polyfillHostNoCombinator) > -1;
  18827. // Only scope parts after the first `-shadowcsshost-no-combinator` when it is present
  18828. let /** @type {?} */ shouldScope = !hasHost;
  18829. while ((res = sep.exec(selector)) !== null) {
  18830. const /** @type {?} */ separator = res[1];
  18831. const /** @type {?} */ part = selector.slice(startIndex, res.index).trim();
  18832. shouldScope = shouldScope || part.indexOf(_polyfillHostNoCombinator) > -1;
  18833. const /** @type {?} */ scopedPart = shouldScope ? _scopeSelectorPart(part) : part;
  18834. scopedSelector += `${scopedPart} ${separator} `;
  18835. startIndex = sep.lastIndex;
  18836. }
  18837. const /** @type {?} */ part = selector.substring(startIndex);
  18838. shouldScope = shouldScope || part.indexOf(_polyfillHostNoCombinator) > -1;
  18839. scopedSelector += shouldScope ? _scopeSelectorPart(part) : part;
  18840. // replace the placeholders with their original values
  18841. return safeContent.restore(scopedSelector);
  18842. }
  18843. /**
  18844. * @param {?} selector
  18845. * @return {?}
  18846. */
  18847. _insertPolyfillHostInCssText(selector) {
  18848. return selector.replace(_colonHostContextRe, _polyfillHostContext)
  18849. .replace(_colonHostRe, _polyfillHost);
  18850. }
  18851. }
  18852. class SafeSelector {
  18853. /**
  18854. * @param {?} selector
  18855. */
  18856. constructor(selector) {
  18857. this.placeholders = [];
  18858. this.index = 0;
  18859. // Replaces attribute selectors with placeholders.
  18860. // The WS in [attr="va lue"] would otherwise be interpreted as a selector separator.
  18861. selector = selector.replace(/(\[[^\]]*\])/g, (_, keep) => {
  18862. const /** @type {?} */ replaceBy = `__ph-${this.index}__`;
  18863. this.placeholders.push(keep);
  18864. this.index++;
  18865. return replaceBy;
  18866. });
  18867. // Replaces the expression in `:nth-child(2n + 1)` with a placeholder.
  18868. // WS and "+" would otherwise be interpreted as selector separators.
  18869. this._content = selector.replace(/(:nth-[-\w]+)(\([^)]+\))/g, (_, pseudo, exp) => {
  18870. const /** @type {?} */ replaceBy = `__ph-${this.index}__`;
  18871. this.placeholders.push(exp);
  18872. this.index++;
  18873. return pseudo + replaceBy;
  18874. });
  18875. }
  18876. /**
  18877. * @param {?} content
  18878. * @return {?}
  18879. */
  18880. restore(content) {
  18881. return content.replace(/__ph-(\d+)__/g, (ph, index) => this.placeholders[+index]);
  18882. }
  18883. /**
  18884. * @return {?}
  18885. */
  18886. content() { return this._content; }
  18887. }
  18888. const _cssContentNextSelectorRe = /polyfill-next-selector[^}]*content:[\s]*?(['"])(.*?)\1[;\s]*}([^{]*?){/gim;
  18889. const _cssContentRuleRe = /(polyfill-rule)[^}]*(content:[\s]*(['"])(.*?)\3)[;\s]*[^}]*}/gim;
  18890. const _cssContentUnscopedRuleRe = /(polyfill-unscoped-rule)[^}]*(content:[\s]*(['"])(.*?)\3)[;\s]*[^}]*}/gim;
  18891. const _polyfillHost = '-shadowcsshost';
  18892. // note: :host-context pre-processed to -shadowcsshostcontext.
  18893. const _polyfillHostContext = '-shadowcsscontext';
  18894. const _parenSuffix = ')(?:\\((' +
  18895. '(?:\\([^)(]*\\)|[^)(]*)+?' +
  18896. ')\\))?([^,{]*)';
  18897. const _cssColonHostRe = new RegExp('(' + _polyfillHost + _parenSuffix, 'gim');
  18898. const _cssColonHostContextRe = new RegExp('(' + _polyfillHostContext + _parenSuffix, 'gim');
  18899. const _polyfillHostNoCombinator = _polyfillHost + '-no-combinator';
  18900. const _polyfillHostNoCombinatorRe = /-shadowcsshost-no-combinator([^\s]*)/;
  18901. const _shadowDOMSelectorsRe = [
  18902. /::shadow/g,
  18903. /::content/g,
  18904. /\/shadow-deep\//g,
  18905. /\/shadow\//g,
  18906. ];
  18907. // The deep combinator is deprecated in the CSS spec
  18908. // Support for `>>>`, `deep`, `::ng-deep` is then also deprecated and will be removed in the future.
  18909. // see https://github.com/angular/angular/pull/17677
  18910. const _shadowDeepSelectors = /(?:>>>)|(?:\/deep\/)|(?:::ng-deep)/g;
  18911. const _selectorReSuffix = '([>\\s~+\[.,{:][\\s\\S]*)?$';
  18912. const _polyfillHostRe = /-shadowcsshost/gim;
  18913. const _colonHostRe = /:host/gim;
  18914. const _colonHostContextRe = /:host-context/gim;
  18915. const _commentRe = /\/\*\s*[\s\S]*?\*\//g;
  18916. /**
  18917. * @param {?} input
  18918. * @return {?}
  18919. */
  18920. function stripComments(input) {
  18921. return input.replace(_commentRe, '');
  18922. }
  18923. const _commentWithHashRe = /\/\*\s*#\s*source(Mapping)?URL=[\s\S]+?\*\//g;
  18924. /**
  18925. * @param {?} input
  18926. * @return {?}
  18927. */
  18928. function extractCommentsWithHash(input) {
  18929. return input.match(_commentWithHashRe) || [];
  18930. }
  18931. const _ruleRe = /(\s*)([^;\{\}]+?)(\s*)((?:{%BLOCK%}?\s*;?)|(?:\s*;))/g;
  18932. const _curlyRe = /([{}])/g;
  18933. const OPEN_CURLY = '{';
  18934. const CLOSE_CURLY = '}';
  18935. const BLOCK_PLACEHOLDER = '%BLOCK%';
  18936. class CssRule {
  18937. /**
  18938. * @param {?} selector
  18939. * @param {?} content
  18940. */
  18941. constructor(selector, content) {
  18942. this.selector = selector;
  18943. this.content = content;
  18944. }
  18945. }
  18946. /**
  18947. * @param {?} input
  18948. * @param {?} ruleCallback
  18949. * @return {?}
  18950. */
  18951. function processRules(input, ruleCallback) {
  18952. const /** @type {?} */ inputWithEscapedBlocks = escapeBlocks(input);
  18953. let /** @type {?} */ nextBlockIndex = 0;
  18954. return inputWithEscapedBlocks.escapedString.replace(_ruleRe, function (...m) {
  18955. const /** @type {?} */ selector = m[2];
  18956. let /** @type {?} */ content = '';
  18957. let /** @type {?} */ suffix = m[4];
  18958. let /** @type {?} */ contentPrefix = '';
  18959. if (suffix && suffix.startsWith('{' + BLOCK_PLACEHOLDER)) {
  18960. content = inputWithEscapedBlocks.blocks[nextBlockIndex++];
  18961. suffix = suffix.substring(BLOCK_PLACEHOLDER.length + 1);
  18962. contentPrefix = '{';
  18963. }
  18964. const /** @type {?} */ rule = ruleCallback(new CssRule(selector, content));
  18965. return `${m[1]}${rule.selector}${m[3]}${contentPrefix}${rule.content}${suffix}`;
  18966. });
  18967. }
  18968. class StringWithEscapedBlocks {
  18969. /**
  18970. * @param {?} escapedString
  18971. * @param {?} blocks
  18972. */
  18973. constructor(escapedString, blocks) {
  18974. this.escapedString = escapedString;
  18975. this.blocks = blocks;
  18976. }
  18977. }
  18978. /**
  18979. * @param {?} input
  18980. * @return {?}
  18981. */
  18982. function escapeBlocks(input) {
  18983. const /** @type {?} */ inputParts = input.split(_curlyRe);
  18984. const /** @type {?} */ resultParts = [];
  18985. const /** @type {?} */ escapedBlocks = [];
  18986. let /** @type {?} */ bracketCount = 0;
  18987. let /** @type {?} */ currentBlockParts = [];
  18988. for (let /** @type {?} */ partIndex = 0; partIndex < inputParts.length; partIndex++) {
  18989. const /** @type {?} */ part = inputParts[partIndex];
  18990. if (part == CLOSE_CURLY) {
  18991. bracketCount--;
  18992. }
  18993. if (bracketCount > 0) {
  18994. currentBlockParts.push(part);
  18995. }
  18996. else {
  18997. if (currentBlockParts.length > 0) {
  18998. escapedBlocks.push(currentBlockParts.join(''));
  18999. resultParts.push(BLOCK_PLACEHOLDER);
  19000. currentBlockParts = [];
  19001. }
  19002. resultParts.push(part);
  19003. }
  19004. if (part == OPEN_CURLY) {
  19005. bracketCount++;
  19006. }
  19007. }
  19008. if (currentBlockParts.length > 0) {
  19009. escapedBlocks.push(currentBlockParts.join(''));
  19010. resultParts.push(BLOCK_PLACEHOLDER);
  19011. }
  19012. return new StringWithEscapedBlocks(resultParts.join(''), escapedBlocks);
  19013. }
  19014. /**
  19015. * @fileoverview added by tsickle
  19016. * @suppress {checkTypes} checked by tsc
  19017. */
  19018. /**
  19019. * @license
  19020. * Copyright Google Inc. All Rights Reserved.
  19021. *
  19022. * Use of this source code is governed by an MIT-style license that can be
  19023. * found in the LICENSE file at https://angular.io/license
  19024. */
  19025. const COMPONENT_VARIABLE = '%COMP%';
  19026. const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
  19027. const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
  19028. class StylesCompileDependency {
  19029. /**
  19030. * @param {?} name
  19031. * @param {?} moduleUrl
  19032. * @param {?} setValue
  19033. */
  19034. constructor(name, moduleUrl, setValue) {
  19035. this.name = name;
  19036. this.moduleUrl = moduleUrl;
  19037. this.setValue = setValue;
  19038. }
  19039. }
  19040. class CompiledStylesheet {
  19041. /**
  19042. * @param {?} outputCtx
  19043. * @param {?} stylesVar
  19044. * @param {?} dependencies
  19045. * @param {?} isShimmed
  19046. * @param {?} meta
  19047. */
  19048. constructor(outputCtx, stylesVar, dependencies, isShimmed, meta) {
  19049. this.outputCtx = outputCtx;
  19050. this.stylesVar = stylesVar;
  19051. this.dependencies = dependencies;
  19052. this.isShimmed = isShimmed;
  19053. this.meta = meta;
  19054. }
  19055. }
  19056. class StyleCompiler {
  19057. /**
  19058. * @param {?} _urlResolver
  19059. */
  19060. constructor(_urlResolver) {
  19061. this._urlResolver = _urlResolver;
  19062. this._shadowCss = new ShadowCss();
  19063. }
  19064. /**
  19065. * @param {?} outputCtx
  19066. * @param {?} comp
  19067. * @return {?}
  19068. */
  19069. compileComponent(outputCtx, comp) {
  19070. const /** @type {?} */ template = /** @type {?} */ ((comp.template));
  19071. return this._compileStyles(outputCtx, comp, new CompileStylesheetMetadata({
  19072. styles: template.styles,
  19073. styleUrls: template.styleUrls,
  19074. moduleUrl: identifierModuleUrl(comp.type)
  19075. }), this.needsStyleShim(comp), true);
  19076. }
  19077. /**
  19078. * @param {?} outputCtx
  19079. * @param {?} comp
  19080. * @param {?} stylesheet
  19081. * @param {?=} shim
  19082. * @return {?}
  19083. */
  19084. compileStyles(outputCtx, comp, stylesheet, shim = this.needsStyleShim(comp)) {
  19085. return this._compileStyles(outputCtx, comp, stylesheet, shim, false);
  19086. }
  19087. /**
  19088. * @param {?} comp
  19089. * @return {?}
  19090. */
  19091. needsStyleShim(comp) {
  19092. return /** @type {?} */ ((comp.template)).encapsulation === ViewEncapsulation.Emulated;
  19093. }
  19094. /**
  19095. * @param {?} outputCtx
  19096. * @param {?} comp
  19097. * @param {?} stylesheet
  19098. * @param {?} shim
  19099. * @param {?} isComponentStylesheet
  19100. * @return {?}
  19101. */
  19102. _compileStyles(outputCtx, comp, stylesheet, shim, isComponentStylesheet) {
  19103. const /** @type {?} */ styleExpressions = stylesheet.styles.map(plainStyle => literal(this._shimIfNeeded(plainStyle, shim)));
  19104. const /** @type {?} */ dependencies = [];
  19105. stylesheet.styleUrls.forEach((styleUrl) => {
  19106. const /** @type {?} */ exprIndex = styleExpressions.length;
  19107. // Note: This placeholder will be filled later.
  19108. styleExpressions.push(/** @type {?} */ ((null)));
  19109. dependencies.push(new StylesCompileDependency(getStylesVarName(null), styleUrl, (value) => styleExpressions[exprIndex] = outputCtx.importExpr(value)));
  19110. });
  19111. // styles variable contains plain strings and arrays of other styles arrays (recursive),
  19112. // so we set its type to dynamic.
  19113. const /** @type {?} */ stylesVar = getStylesVarName(isComponentStylesheet ? comp : null);
  19114. const /** @type {?} */ stmt = variable(stylesVar)
  19115. .set(literalArr(styleExpressions, new ArrayType(DYNAMIC_TYPE, [TypeModifier.Const])))
  19116. .toDeclStmt(null, isComponentStylesheet ? [StmtModifier.Final] : [
  19117. StmtModifier.Final, StmtModifier.Exported
  19118. ]);
  19119. outputCtx.statements.push(stmt);
  19120. return new CompiledStylesheet(outputCtx, stylesVar, dependencies, shim, stylesheet);
  19121. }
  19122. /**
  19123. * @param {?} style
  19124. * @param {?} shim
  19125. * @return {?}
  19126. */
  19127. _shimIfNeeded(style, shim) {
  19128. return shim ? this._shadowCss.shimCssText(style, CONTENT_ATTR, HOST_ATTR) : style;
  19129. }
  19130. }
  19131. /**
  19132. * @param {?} component
  19133. * @return {?}
  19134. */
  19135. function getStylesVarName(component) {
  19136. let /** @type {?} */ result = `styles`;
  19137. if (component) {
  19138. result += `_${identifierName(component.type)}`;
  19139. }
  19140. return result;
  19141. }
  19142. /**
  19143. * @fileoverview added by tsickle
  19144. * @suppress {checkTypes} checked by tsc
  19145. */
  19146. /**
  19147. * @license
  19148. * Copyright Google Inc. All Rights Reserved.
  19149. *
  19150. * Use of this source code is governed by an MIT-style license that can be
  19151. * found in the LICENSE file at https://angular.io/license
  19152. */
  19153. const PRESERVE_WS_ATTR_NAME = 'ngPreserveWhitespaces';
  19154. const SKIP_WS_TRIM_TAGS = new Set(['pre', 'template', 'textarea', 'script', 'style']);
  19155. // Equivalent to \s with \u00a0 (non-breaking space) excluded.
  19156. // Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
  19157. const WS_CHARS = ' \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
  19158. const NO_WS_REGEXP = new RegExp(`[^${WS_CHARS}]`);
  19159. const WS_REPLACE_REGEXP = new RegExp(`[${WS_CHARS}]{2,}`, 'g');
  19160. /**
  19161. * @param {?} attrs
  19162. * @return {?}
  19163. */
  19164. function hasPreserveWhitespacesAttr(attrs) {
  19165. return attrs.some((attr) => attr.name === PRESERVE_WS_ATTR_NAME);
  19166. }
  19167. /**
  19168. * Angular Dart introduced &ngsp; as a placeholder for non-removable space, see:
  19169. * https://github.com/dart-lang/angular/blob/0bb611387d29d65b5af7f9d2515ab571fd3fbee4/_tests/test/compiler/preserve_whitespace_test.dart#L25-L32
  19170. * In Angular Dart &ngsp; is converted to the 0xE500 PUA (Private Use Areas) unicode character
  19171. * and later on replaced by a space. We are re-implementing the same idea here.
  19172. * @param {?} value
  19173. * @return {?}
  19174. */
  19175. function replaceNgsp(value) {
  19176. // lexer is replacing the &ngsp; pseudo-entity with NGSP_UNICODE
  19177. return value.replace(new RegExp(NGSP_UNICODE, 'g'), ' ');
  19178. }
  19179. /**
  19180. * This visitor can walk HTML parse tree and remove / trim text nodes using the following rules:
  19181. * - consider spaces, tabs and new lines as whitespace characters;
  19182. * - drop text nodes consisting of whitespace characters only;
  19183. * - for all other text nodes replace consecutive whitespace characters with one space;
  19184. * - convert &ngsp; pseudo-entity to a single space;
  19185. *
  19186. * Removal and trimming of whitespaces have positive performance impact (less code to generate
  19187. * while compiling templates, faster view creation). At the same time it can be "destructive"
  19188. * in some cases (whitespaces can influence layout). Because of the potential of breaking layout
  19189. * this visitor is not activated by default in Angular 5 and people need to explicitly opt-in for
  19190. * whitespace removal. The default option for whitespace removal will be revisited in Angular 6
  19191. * and might be changed to "on" by default.
  19192. */
  19193. class WhitespaceVisitor {
  19194. /**
  19195. * @param {?} element
  19196. * @param {?} context
  19197. * @return {?}
  19198. */
  19199. visitElement(element, context) {
  19200. if (SKIP_WS_TRIM_TAGS.has(element.name) || hasPreserveWhitespacesAttr(element.attrs)) {
  19201. // don't descent into elements where we need to preserve whitespaces
  19202. // but still visit all attributes to eliminate one used as a market to preserve WS
  19203. return new Element(element.name, visitAll(this, element.attrs), element.children, element.sourceSpan, element.startSourceSpan, element.endSourceSpan);
  19204. }
  19205. return new Element(element.name, element.attrs, visitAll(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan);
  19206. }
  19207. /**
  19208. * @param {?} attribute
  19209. * @param {?} context
  19210. * @return {?}
  19211. */
  19212. visitAttribute(attribute, context) {
  19213. return attribute.name !== PRESERVE_WS_ATTR_NAME ? attribute : null;
  19214. }
  19215. /**
  19216. * @param {?} text
  19217. * @param {?} context
  19218. * @return {?}
  19219. */
  19220. visitText(text, context) {
  19221. const /** @type {?} */ isNotBlank = text.value.match(NO_WS_REGEXP);
  19222. if (isNotBlank) {
  19223. return new Text(replaceNgsp(text.value).replace(WS_REPLACE_REGEXP, ' '), text.sourceSpan);
  19224. }
  19225. return null;
  19226. }
  19227. /**
  19228. * @param {?} comment
  19229. * @param {?} context
  19230. * @return {?}
  19231. */
  19232. visitComment(comment, context) { return comment; }
  19233. /**
  19234. * @param {?} expansion
  19235. * @param {?} context
  19236. * @return {?}
  19237. */
  19238. visitExpansion(expansion, context) { return expansion; }
  19239. /**
  19240. * @param {?} expansionCase
  19241. * @param {?} context
  19242. * @return {?}
  19243. */
  19244. visitExpansionCase(expansionCase, context) { return expansionCase; }
  19245. }
  19246. /**
  19247. * @param {?} htmlAstWithErrors
  19248. * @return {?}
  19249. */
  19250. function removeWhitespaces(htmlAstWithErrors) {
  19251. return new ParseTreeResult(visitAll(new WhitespaceVisitor(), htmlAstWithErrors.rootNodes), htmlAstWithErrors.errors);
  19252. }
  19253. /**
  19254. * @fileoverview added by tsickle
  19255. * @suppress {checkTypes} checked by tsc
  19256. */
  19257. /**
  19258. * @license
  19259. * Copyright Google Inc. All Rights Reserved.
  19260. *
  19261. * Use of this source code is governed by an MIT-style license that can be
  19262. * found in the LICENSE file at https://angular.io/license
  19263. */
  19264. // http://cldr.unicode.org/index/cldr-spec/plural-rules
  19265. const PLURAL_CASES = ['zero', 'one', 'two', 'few', 'many', 'other'];
  19266. /**
  19267. * Expands special forms into elements.
  19268. *
  19269. * For example,
  19270. *
  19271. * ```
  19272. * { messages.length, plural,
  19273. * =0 {zero}
  19274. * =1 {one}
  19275. * other {more than one}
  19276. * }
  19277. * ```
  19278. *
  19279. * will be expanded into
  19280. *
  19281. * ```
  19282. * <ng-container [ngPlural]="messages.length">
  19283. * <ng-template ngPluralCase="=0">zero</ng-template>
  19284. * <ng-template ngPluralCase="=1">one</ng-template>
  19285. * <ng-template ngPluralCase="other">more than one</ng-template>
  19286. * </ng-container>
  19287. * ```
  19288. * @param {?} nodes
  19289. * @return {?}
  19290. */
  19291. function expandNodes(nodes) {
  19292. const /** @type {?} */ expander = new _Expander();
  19293. return new ExpansionResult(visitAll(expander, nodes), expander.isExpanded, expander.errors);
  19294. }
  19295. class ExpansionResult {
  19296. /**
  19297. * @param {?} nodes
  19298. * @param {?} expanded
  19299. * @param {?} errors
  19300. */
  19301. constructor(nodes, expanded, errors) {
  19302. this.nodes = nodes;
  19303. this.expanded = expanded;
  19304. this.errors = errors;
  19305. }
  19306. }
  19307. class ExpansionError extends ParseError {
  19308. /**
  19309. * @param {?} span
  19310. * @param {?} errorMsg
  19311. */
  19312. constructor(span, errorMsg) { super(span, errorMsg); }
  19313. }
  19314. /**
  19315. * Expand expansion forms (plural, select) to directives
  19316. *
  19317. * \@internal
  19318. */
  19319. class _Expander {
  19320. constructor() {
  19321. this.isExpanded = false;
  19322. this.errors = [];
  19323. }
  19324. /**
  19325. * @param {?} element
  19326. * @param {?} context
  19327. * @return {?}
  19328. */
  19329. visitElement(element, context) {
  19330. return new Element(element.name, element.attrs, visitAll(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan);
  19331. }
  19332. /**
  19333. * @param {?} attribute
  19334. * @param {?} context
  19335. * @return {?}
  19336. */
  19337. visitAttribute(attribute, context) { return attribute; }
  19338. /**
  19339. * @param {?} text
  19340. * @param {?} context
  19341. * @return {?}
  19342. */
  19343. visitText(text, context) { return text; }
  19344. /**
  19345. * @param {?} comment
  19346. * @param {?} context
  19347. * @return {?}
  19348. */
  19349. visitComment(comment, context) { return comment; }
  19350. /**
  19351. * @param {?} icu
  19352. * @param {?} context
  19353. * @return {?}
  19354. */
  19355. visitExpansion(icu, context) {
  19356. this.isExpanded = true;
  19357. return icu.type == 'plural' ? _expandPluralForm(icu, this.errors) :
  19358. _expandDefaultForm(icu, this.errors);
  19359. }
  19360. /**
  19361. * @param {?} icuCase
  19362. * @param {?} context
  19363. * @return {?}
  19364. */
  19365. visitExpansionCase(icuCase, context) {
  19366. throw new Error('Should not be reached');
  19367. }
  19368. }
  19369. /**
  19370. * @param {?} ast
  19371. * @param {?} errors
  19372. * @return {?}
  19373. */
  19374. function _expandPluralForm(ast, errors) {
  19375. const /** @type {?} */ children = ast.cases.map(c => {
  19376. if (PLURAL_CASES.indexOf(c.value) == -1 && !c.value.match(/^=\d+$/)) {
  19377. errors.push(new ExpansionError(c.valueSourceSpan, `Plural cases should be "=<number>" or one of ${PLURAL_CASES.join(", ")}`));
  19378. }
  19379. const /** @type {?} */ expansionResult = expandNodes(c.expression);
  19380. errors.push(...expansionResult.errors);
  19381. return new Element(`ng-template`, [new Attribute$1('ngPluralCase', `${c.value}`, c.valueSourceSpan)], expansionResult.nodes, c.sourceSpan, c.sourceSpan, c.sourceSpan);
  19382. });
  19383. const /** @type {?} */ switchAttr = new Attribute$1('[ngPlural]', ast.switchValue, ast.switchValueSourceSpan);
  19384. return new Element('ng-container', [switchAttr], children, ast.sourceSpan, ast.sourceSpan, ast.sourceSpan);
  19385. }
  19386. /**
  19387. * @param {?} ast
  19388. * @param {?} errors
  19389. * @return {?}
  19390. */
  19391. function _expandDefaultForm(ast, errors) {
  19392. const /** @type {?} */ children = ast.cases.map(c => {
  19393. const /** @type {?} */ expansionResult = expandNodes(c.expression);
  19394. errors.push(...expansionResult.errors);
  19395. if (c.value === 'other') {
  19396. // other is the default case when no values match
  19397. return new Element(`ng-template`, [new Attribute$1('ngSwitchDefault', '', c.valueSourceSpan)], expansionResult.nodes, c.sourceSpan, c.sourceSpan, c.sourceSpan);
  19398. }
  19399. return new Element(`ng-template`, [new Attribute$1('ngSwitchCase', `${c.value}`, c.valueSourceSpan)], expansionResult.nodes, c.sourceSpan, c.sourceSpan, c.sourceSpan);
  19400. });
  19401. const /** @type {?} */ switchAttr = new Attribute$1('[ngSwitch]', ast.switchValue, ast.switchValueSourceSpan);
  19402. return new Element('ng-container', [switchAttr], children, ast.sourceSpan, ast.sourceSpan, ast.sourceSpan);
  19403. }
  19404. /**
  19405. * @fileoverview added by tsickle
  19406. * @suppress {checkTypes} checked by tsc
  19407. */
  19408. /**
  19409. * @license
  19410. * Copyright Google Inc. All Rights Reserved.
  19411. *
  19412. * Use of this source code is governed by an MIT-style license that can be
  19413. * found in the LICENSE file at https://angular.io/license
  19414. */
  19415. const PROPERTY_PARTS_SEPARATOR = '.';
  19416. const ATTRIBUTE_PREFIX = 'attr';
  19417. const CLASS_PREFIX = 'class';
  19418. const STYLE_PREFIX = 'style';
  19419. const ANIMATE_PROP_PREFIX = 'animate-';
  19420. /** @enum {number} */
  19421. const BoundPropertyType = {
  19422. DEFAULT: 0,
  19423. LITERAL_ATTR: 1,
  19424. ANIMATION: 2,
  19425. };
  19426. BoundPropertyType[BoundPropertyType.DEFAULT] = "DEFAULT";
  19427. BoundPropertyType[BoundPropertyType.LITERAL_ATTR] = "LITERAL_ATTR";
  19428. BoundPropertyType[BoundPropertyType.ANIMATION] = "ANIMATION";
  19429. /**
  19430. * Represents a parsed property.
  19431. */
  19432. class BoundProperty {
  19433. /**
  19434. * @param {?} name
  19435. * @param {?} expression
  19436. * @param {?} type
  19437. * @param {?} sourceSpan
  19438. */
  19439. constructor(name, expression, type, sourceSpan) {
  19440. this.name = name;
  19441. this.expression = expression;
  19442. this.type = type;
  19443. this.sourceSpan = sourceSpan;
  19444. this.isLiteral = this.type === BoundPropertyType.LITERAL_ATTR;
  19445. this.isAnimation = this.type === BoundPropertyType.ANIMATION;
  19446. }
  19447. }
  19448. /**
  19449. * Parses bindings in templates and in the directive host area.
  19450. */
  19451. class BindingParser {
  19452. /**
  19453. * @param {?} _exprParser
  19454. * @param {?} _interpolationConfig
  19455. * @param {?} _schemaRegistry
  19456. * @param {?} pipes
  19457. * @param {?} _targetErrors
  19458. */
  19459. constructor(_exprParser, _interpolationConfig, _schemaRegistry, pipes, _targetErrors) {
  19460. this._exprParser = _exprParser;
  19461. this._interpolationConfig = _interpolationConfig;
  19462. this._schemaRegistry = _schemaRegistry;
  19463. this._targetErrors = _targetErrors;
  19464. this.pipesByName = new Map();
  19465. this._usedPipes = new Map();
  19466. pipes.forEach(pipe => this.pipesByName.set(pipe.name, pipe));
  19467. }
  19468. /**
  19469. * @return {?}
  19470. */
  19471. getUsedPipes() { return Array.from(this._usedPipes.values()); }
  19472. /**
  19473. * @param {?} dirMeta
  19474. * @param {?} elementSelector
  19475. * @param {?} sourceSpan
  19476. * @return {?}
  19477. */
  19478. createDirectiveHostPropertyAsts(dirMeta, elementSelector, sourceSpan) {
  19479. if (dirMeta.hostProperties) {
  19480. const /** @type {?} */ boundProps = [];
  19481. Object.keys(dirMeta.hostProperties).forEach(propName => {
  19482. const /** @type {?} */ expression = dirMeta.hostProperties[propName];
  19483. if (typeof expression === 'string') {
  19484. this.parsePropertyBinding(propName, expression, true, sourceSpan, [], boundProps);
  19485. }
  19486. else {
  19487. this._reportError(`Value of the host property binding "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
  19488. }
  19489. });
  19490. return boundProps.map((prop) => this.createElementPropertyAst(elementSelector, prop));
  19491. }
  19492. return null;
  19493. }
  19494. /**
  19495. * @param {?} dirMeta
  19496. * @param {?} sourceSpan
  19497. * @return {?}
  19498. */
  19499. createDirectiveHostEventAsts(dirMeta, sourceSpan) {
  19500. if (dirMeta.hostListeners) {
  19501. const /** @type {?} */ targetEventAsts = [];
  19502. Object.keys(dirMeta.hostListeners).forEach(propName => {
  19503. const /** @type {?} */ expression = dirMeta.hostListeners[propName];
  19504. if (typeof expression === 'string') {
  19505. this.parseEvent(propName, expression, sourceSpan, [], targetEventAsts);
  19506. }
  19507. else {
  19508. this._reportError(`Value of the host listener "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
  19509. }
  19510. });
  19511. return targetEventAsts;
  19512. }
  19513. return null;
  19514. }
  19515. /**
  19516. * @param {?} value
  19517. * @param {?} sourceSpan
  19518. * @return {?}
  19519. */
  19520. parseInterpolation(value, sourceSpan) {
  19521. const /** @type {?} */ sourceInfo = sourceSpan.start.toString();
  19522. try {
  19523. const /** @type {?} */ ast = /** @type {?} */ ((this._exprParser.parseInterpolation(value, sourceInfo, this._interpolationConfig)));
  19524. if (ast)
  19525. this._reportExpressionParserErrors(ast.errors, sourceSpan);
  19526. this._checkPipes(ast, sourceSpan);
  19527. return ast;
  19528. }
  19529. catch (/** @type {?} */ e) {
  19530. this._reportError(`${e}`, sourceSpan);
  19531. return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo);
  19532. }
  19533. }
  19534. /**
  19535. * @param {?} prefixToken
  19536. * @param {?} value
  19537. * @param {?} sourceSpan
  19538. * @param {?} targetMatchableAttrs
  19539. * @param {?} targetProps
  19540. * @param {?} targetVars
  19541. * @return {?}
  19542. */
  19543. parseInlineTemplateBinding(prefixToken, value, sourceSpan, targetMatchableAttrs, targetProps, targetVars) {
  19544. const /** @type {?} */ bindings = this._parseTemplateBindings(prefixToken, value, sourceSpan);
  19545. for (let /** @type {?} */ i = 0; i < bindings.length; i++) {
  19546. const /** @type {?} */ binding = bindings[i];
  19547. if (binding.keyIsVar) {
  19548. targetVars.push(new VariableAst(binding.key, binding.name, sourceSpan));
  19549. }
  19550. else if (binding.expression) {
  19551. this._parsePropertyAst(binding.key, binding.expression, sourceSpan, targetMatchableAttrs, targetProps);
  19552. }
  19553. else {
  19554. targetMatchableAttrs.push([binding.key, '']);
  19555. this.parseLiteralAttr(binding.key, null, sourceSpan, targetMatchableAttrs, targetProps);
  19556. }
  19557. }
  19558. }
  19559. /**
  19560. * @param {?} prefixToken
  19561. * @param {?} value
  19562. * @param {?} sourceSpan
  19563. * @return {?}
  19564. */
  19565. _parseTemplateBindings(prefixToken, value, sourceSpan) {
  19566. const /** @type {?} */ sourceInfo = sourceSpan.start.toString();
  19567. try {
  19568. const /** @type {?} */ bindingsResult = this._exprParser.parseTemplateBindings(prefixToken, value, sourceInfo);
  19569. this._reportExpressionParserErrors(bindingsResult.errors, sourceSpan);
  19570. bindingsResult.templateBindings.forEach((binding) => {
  19571. if (binding.expression) {
  19572. this._checkPipes(binding.expression, sourceSpan);
  19573. }
  19574. });
  19575. bindingsResult.warnings.forEach((warning) => { this._reportError(warning, sourceSpan, ParseErrorLevel.WARNING); });
  19576. return bindingsResult.templateBindings;
  19577. }
  19578. catch (/** @type {?} */ e) {
  19579. this._reportError(`${e}`, sourceSpan);
  19580. return [];
  19581. }
  19582. }
  19583. /**
  19584. * @param {?} name
  19585. * @param {?} value
  19586. * @param {?} sourceSpan
  19587. * @param {?} targetMatchableAttrs
  19588. * @param {?} targetProps
  19589. * @return {?}
  19590. */
  19591. parseLiteralAttr(name, value, sourceSpan, targetMatchableAttrs, targetProps) {
  19592. if (_isAnimationLabel(name)) {
  19593. name = name.substring(1);
  19594. if (value) {
  19595. this._reportError(`Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
  19596. ` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.`, sourceSpan, ParseErrorLevel.ERROR);
  19597. }
  19598. this._parseAnimation(name, value, sourceSpan, targetMatchableAttrs, targetProps);
  19599. }
  19600. else {
  19601. targetProps.push(new BoundProperty(name, this._exprParser.wrapLiteralPrimitive(value, ''), BoundPropertyType.LITERAL_ATTR, sourceSpan));
  19602. }
  19603. }
  19604. /**
  19605. * @param {?} name
  19606. * @param {?} expression
  19607. * @param {?} isHost
  19608. * @param {?} sourceSpan
  19609. * @param {?} targetMatchableAttrs
  19610. * @param {?} targetProps
  19611. * @return {?}
  19612. */
  19613. parsePropertyBinding(name, expression, isHost, sourceSpan, targetMatchableAttrs, targetProps) {
  19614. let /** @type {?} */ isAnimationProp = false;
  19615. if (name.startsWith(ANIMATE_PROP_PREFIX)) {
  19616. isAnimationProp = true;
  19617. name = name.substring(ANIMATE_PROP_PREFIX.length);
  19618. }
  19619. else if (_isAnimationLabel(name)) {
  19620. isAnimationProp = true;
  19621. name = name.substring(1);
  19622. }
  19623. if (isAnimationProp) {
  19624. this._parseAnimation(name, expression, sourceSpan, targetMatchableAttrs, targetProps);
  19625. }
  19626. else {
  19627. this._parsePropertyAst(name, this._parseBinding(expression, isHost, sourceSpan), sourceSpan, targetMatchableAttrs, targetProps);
  19628. }
  19629. }
  19630. /**
  19631. * @param {?} name
  19632. * @param {?} value
  19633. * @param {?} sourceSpan
  19634. * @param {?} targetMatchableAttrs
  19635. * @param {?} targetProps
  19636. * @return {?}
  19637. */
  19638. parsePropertyInterpolation(name, value, sourceSpan, targetMatchableAttrs, targetProps) {
  19639. const /** @type {?} */ expr = this.parseInterpolation(value, sourceSpan);
  19640. if (expr) {
  19641. this._parsePropertyAst(name, expr, sourceSpan, targetMatchableAttrs, targetProps);
  19642. return true;
  19643. }
  19644. return false;
  19645. }
  19646. /**
  19647. * @param {?} name
  19648. * @param {?} ast
  19649. * @param {?} sourceSpan
  19650. * @param {?} targetMatchableAttrs
  19651. * @param {?} targetProps
  19652. * @return {?}
  19653. */
  19654. _parsePropertyAst(name, ast, sourceSpan, targetMatchableAttrs, targetProps) {
  19655. targetMatchableAttrs.push([name, /** @type {?} */ ((ast.source))]);
  19656. targetProps.push(new BoundProperty(name, ast, BoundPropertyType.DEFAULT, sourceSpan));
  19657. }
  19658. /**
  19659. * @param {?} name
  19660. * @param {?} expression
  19661. * @param {?} sourceSpan
  19662. * @param {?} targetMatchableAttrs
  19663. * @param {?} targetProps
  19664. * @return {?}
  19665. */
  19666. _parseAnimation(name, expression, sourceSpan, targetMatchableAttrs, targetProps) {
  19667. // This will occur when a @trigger is not paired with an expression.
  19668. // For animations it is valid to not have an expression since */void
  19669. // states will be applied by angular when the element is attached/detached
  19670. const /** @type {?} */ ast = this._parseBinding(expression || 'undefined', false, sourceSpan);
  19671. targetMatchableAttrs.push([name, /** @type {?} */ ((ast.source))]);
  19672. targetProps.push(new BoundProperty(name, ast, BoundPropertyType.ANIMATION, sourceSpan));
  19673. }
  19674. /**
  19675. * @param {?} value
  19676. * @param {?} isHostBinding
  19677. * @param {?} sourceSpan
  19678. * @return {?}
  19679. */
  19680. _parseBinding(value, isHostBinding, sourceSpan) {
  19681. const /** @type {?} */ sourceInfo = sourceSpan.start.toString();
  19682. try {
  19683. const /** @type {?} */ ast = isHostBinding ?
  19684. this._exprParser.parseSimpleBinding(value, sourceInfo, this._interpolationConfig) :
  19685. this._exprParser.parseBinding(value, sourceInfo, this._interpolationConfig);
  19686. if (ast)
  19687. this._reportExpressionParserErrors(ast.errors, sourceSpan);
  19688. this._checkPipes(ast, sourceSpan);
  19689. return ast;
  19690. }
  19691. catch (/** @type {?} */ e) {
  19692. this._reportError(`${e}`, sourceSpan);
  19693. return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo);
  19694. }
  19695. }
  19696. /**
  19697. * @param {?} elementSelector
  19698. * @param {?} boundProp
  19699. * @return {?}
  19700. */
  19701. createElementPropertyAst(elementSelector, boundProp) {
  19702. if (boundProp.isAnimation) {
  19703. return new BoundElementPropertyAst(boundProp.name, PropertyBindingType.Animation, SecurityContext.NONE, boundProp.expression, null, boundProp.sourceSpan);
  19704. }
  19705. let /** @type {?} */ unit = null;
  19706. let /** @type {?} */ bindingType = /** @type {?} */ ((undefined));
  19707. let /** @type {?} */ boundPropertyName = null;
  19708. const /** @type {?} */ parts = boundProp.name.split(PROPERTY_PARTS_SEPARATOR);
  19709. let /** @type {?} */ securityContexts = /** @type {?} */ ((undefined));
  19710. // Check check for special cases (prefix style, attr, class)
  19711. if (parts.length > 1) {
  19712. if (parts[0] == ATTRIBUTE_PREFIX) {
  19713. boundPropertyName = parts[1];
  19714. this._validatePropertyOrAttributeName(boundPropertyName, boundProp.sourceSpan, true);
  19715. securityContexts = calcPossibleSecurityContexts(this._schemaRegistry, elementSelector, boundPropertyName, true);
  19716. const /** @type {?} */ nsSeparatorIdx = boundPropertyName.indexOf(':');
  19717. if (nsSeparatorIdx > -1) {
  19718. const /** @type {?} */ ns = boundPropertyName.substring(0, nsSeparatorIdx);
  19719. const /** @type {?} */ name = boundPropertyName.substring(nsSeparatorIdx + 1);
  19720. boundPropertyName = mergeNsAndName(ns, name);
  19721. }
  19722. bindingType = PropertyBindingType.Attribute;
  19723. }
  19724. else if (parts[0] == CLASS_PREFIX) {
  19725. boundPropertyName = parts[1];
  19726. bindingType = PropertyBindingType.Class;
  19727. securityContexts = [SecurityContext.NONE];
  19728. }
  19729. else if (parts[0] == STYLE_PREFIX) {
  19730. unit = parts.length > 2 ? parts[2] : null;
  19731. boundPropertyName = parts[1];
  19732. bindingType = PropertyBindingType.Style;
  19733. securityContexts = [SecurityContext.STYLE];
  19734. }
  19735. }
  19736. // If not a special case, use the full property name
  19737. if (boundPropertyName === null) {
  19738. boundPropertyName = this._schemaRegistry.getMappedPropName(boundProp.name);
  19739. securityContexts = calcPossibleSecurityContexts(this._schemaRegistry, elementSelector, boundPropertyName, false);
  19740. bindingType = PropertyBindingType.Property;
  19741. this._validatePropertyOrAttributeName(boundPropertyName, boundProp.sourceSpan, false);
  19742. }
  19743. return new BoundElementPropertyAst(boundPropertyName, bindingType, securityContexts[0], boundProp.expression, unit, boundProp.sourceSpan);
  19744. }
  19745. /**
  19746. * @param {?} name
  19747. * @param {?} expression
  19748. * @param {?} sourceSpan
  19749. * @param {?} targetMatchableAttrs
  19750. * @param {?} targetEvents
  19751. * @return {?}
  19752. */
  19753. parseEvent(name, expression, sourceSpan, targetMatchableAttrs, targetEvents) {
  19754. if (_isAnimationLabel(name)) {
  19755. name = name.substr(1);
  19756. this._parseAnimationEvent(name, expression, sourceSpan, targetEvents);
  19757. }
  19758. else {
  19759. this._parseEvent(name, expression, sourceSpan, targetMatchableAttrs, targetEvents);
  19760. }
  19761. }
  19762. /**
  19763. * @param {?} name
  19764. * @param {?} expression
  19765. * @param {?} sourceSpan
  19766. * @param {?} targetEvents
  19767. * @return {?}
  19768. */
  19769. _parseAnimationEvent(name, expression, sourceSpan, targetEvents) {
  19770. const /** @type {?} */ matches = splitAtPeriod(name, [name, '']);
  19771. const /** @type {?} */ eventName = matches[0];
  19772. const /** @type {?} */ phase = matches[1].toLowerCase();
  19773. if (phase) {
  19774. switch (phase) {
  19775. case 'start':
  19776. case 'done':
  19777. const /** @type {?} */ ast = this._parseAction(expression, sourceSpan);
  19778. targetEvents.push(new BoundEventAst(eventName, null, phase, ast, sourceSpan));
  19779. break;
  19780. default:
  19781. this._reportError(`The provided animation output phase value "${phase}" for "@${eventName}" is not supported (use start or done)`, sourceSpan);
  19782. break;
  19783. }
  19784. }
  19785. else {
  19786. this._reportError(`The animation trigger output event (@${eventName}) is missing its phase value name (start or done are currently supported)`, sourceSpan);
  19787. }
  19788. }
  19789. /**
  19790. * @param {?} name
  19791. * @param {?} expression
  19792. * @param {?} sourceSpan
  19793. * @param {?} targetMatchableAttrs
  19794. * @param {?} targetEvents
  19795. * @return {?}
  19796. */
  19797. _parseEvent(name, expression, sourceSpan, targetMatchableAttrs, targetEvents) {
  19798. // long format: 'target: eventName'
  19799. const [target, eventName] = splitAtColon(name, [/** @type {?} */ ((null)), name]);
  19800. const /** @type {?} */ ast = this._parseAction(expression, sourceSpan);
  19801. targetMatchableAttrs.push([/** @type {?} */ ((name)), /** @type {?} */ ((ast.source))]);
  19802. targetEvents.push(new BoundEventAst(eventName, target, null, ast, sourceSpan));
  19803. // Don't detect directives for event names for now,
  19804. // so don't add the event name to the matchableAttrs
  19805. }
  19806. /**
  19807. * @param {?} value
  19808. * @param {?} sourceSpan
  19809. * @return {?}
  19810. */
  19811. _parseAction(value, sourceSpan) {
  19812. const /** @type {?} */ sourceInfo = sourceSpan.start.toString();
  19813. try {
  19814. const /** @type {?} */ ast = this._exprParser.parseAction(value, sourceInfo, this._interpolationConfig);
  19815. if (ast) {
  19816. this._reportExpressionParserErrors(ast.errors, sourceSpan);
  19817. }
  19818. if (!ast || ast.ast instanceof EmptyExpr) {
  19819. this._reportError(`Empty expressions are not allowed`, sourceSpan);
  19820. return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo);
  19821. }
  19822. this._checkPipes(ast, sourceSpan);
  19823. return ast;
  19824. }
  19825. catch (/** @type {?} */ e) {
  19826. this._reportError(`${e}`, sourceSpan);
  19827. return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo);
  19828. }
  19829. }
  19830. /**
  19831. * @param {?} message
  19832. * @param {?} sourceSpan
  19833. * @param {?=} level
  19834. * @return {?}
  19835. */
  19836. _reportError(message, sourceSpan, level = ParseErrorLevel.ERROR) {
  19837. this._targetErrors.push(new ParseError(sourceSpan, message, level));
  19838. }
  19839. /**
  19840. * @param {?} errors
  19841. * @param {?} sourceSpan
  19842. * @return {?}
  19843. */
  19844. _reportExpressionParserErrors(errors, sourceSpan) {
  19845. for (const /** @type {?} */ error of errors) {
  19846. this._reportError(error.message, sourceSpan);
  19847. }
  19848. }
  19849. /**
  19850. * @param {?} ast
  19851. * @param {?} sourceSpan
  19852. * @return {?}
  19853. */
  19854. _checkPipes(ast, sourceSpan) {
  19855. if (ast) {
  19856. const /** @type {?} */ collector = new PipeCollector();
  19857. ast.visit(collector);
  19858. collector.pipes.forEach((ast, pipeName) => {
  19859. const /** @type {?} */ pipeMeta = this.pipesByName.get(pipeName);
  19860. if (!pipeMeta) {
  19861. this._reportError(`The pipe '${pipeName}' could not be found`, new ParseSourceSpan(sourceSpan.start.moveBy(ast.span.start), sourceSpan.start.moveBy(ast.span.end)));
  19862. }
  19863. else {
  19864. this._usedPipes.set(pipeName, pipeMeta);
  19865. }
  19866. });
  19867. }
  19868. }
  19869. /**
  19870. * @param {?} propName the name of the property / attribute
  19871. * @param {?} sourceSpan
  19872. * @param {?} isAttr true when binding to an attribute
  19873. * @return {?}
  19874. */
  19875. _validatePropertyOrAttributeName(propName, sourceSpan, isAttr) {
  19876. const /** @type {?} */ report = isAttr ? this._schemaRegistry.validateAttribute(propName) :
  19877. this._schemaRegistry.validateProperty(propName);
  19878. if (report.error) {
  19879. this._reportError(/** @type {?} */ ((report.msg)), sourceSpan, ParseErrorLevel.ERROR);
  19880. }
  19881. }
  19882. }
  19883. class PipeCollector extends RecursiveAstVisitor {
  19884. constructor() {
  19885. super(...arguments);
  19886. this.pipes = new Map();
  19887. }
  19888. /**
  19889. * @param {?} ast
  19890. * @param {?} context
  19891. * @return {?}
  19892. */
  19893. visitPipe(ast, context) {
  19894. this.pipes.set(ast.name, ast);
  19895. ast.exp.visit(this);
  19896. this.visitAll(ast.args, context);
  19897. return null;
  19898. }
  19899. }
  19900. /**
  19901. * @param {?} name
  19902. * @return {?}
  19903. */
  19904. function _isAnimationLabel(name) {
  19905. return name[0] == '@';
  19906. }
  19907. /**
  19908. * @param {?} registry
  19909. * @param {?} selector
  19910. * @param {?} propName
  19911. * @param {?} isAttribute
  19912. * @return {?}
  19913. */
  19914. function calcPossibleSecurityContexts(registry, selector, propName, isAttribute) {
  19915. const /** @type {?} */ ctxs = [];
  19916. CssSelector.parse(selector).forEach((selector) => {
  19917. const /** @type {?} */ elementNames = selector.element ? [selector.element] : registry.allKnownElementNames();
  19918. const /** @type {?} */ notElementNames = new Set(selector.notSelectors.filter(selector => selector.isElementSelector())
  19919. .map((selector) => selector.element));
  19920. const /** @type {?} */ possibleElementNames = elementNames.filter(elementName => !notElementNames.has(elementName));
  19921. ctxs.push(...possibleElementNames.map(elementName => registry.securityContext(elementName, propName, isAttribute)));
  19922. });
  19923. return ctxs.length === 0 ? [SecurityContext.NONE] : Array.from(new Set(ctxs)).sort();
  19924. }
  19925. /**
  19926. * @fileoverview added by tsickle
  19927. * @suppress {checkTypes} checked by tsc
  19928. */
  19929. /**
  19930. * @license
  19931. * Copyright Google Inc. All Rights Reserved.
  19932. *
  19933. * Use of this source code is governed by an MIT-style license that can be
  19934. * found in the LICENSE file at https://angular.io/license
  19935. */
  19936. const BIND_NAME_REGEXP = /^(?:(?:(?:(bind-)|(let-)|(ref-|#)|(on-)|(bindon-)|(@))(.+))|\[\(([^\)]+)\)\]|\[([^\]]+)\]|\(([^\)]+)\))$/;
  19937. // Group 1 = "bind-"
  19938. const KW_BIND_IDX = 1;
  19939. // Group 2 = "let-"
  19940. const KW_LET_IDX = 2;
  19941. // Group 3 = "ref-/#"
  19942. const KW_REF_IDX = 3;
  19943. // Group 4 = "on-"
  19944. const KW_ON_IDX = 4;
  19945. // Group 5 = "bindon-"
  19946. const KW_BINDON_IDX = 5;
  19947. // Group 6 = "@"
  19948. const KW_AT_IDX = 6;
  19949. // Group 7 = the identifier after "bind-", "let-", "ref-/#", "on-", "bindon-" or "@"
  19950. const IDENT_KW_IDX = 7;
  19951. // Group 8 = identifier inside [()]
  19952. const IDENT_BANANA_BOX_IDX = 8;
  19953. // Group 9 = identifier inside []
  19954. const IDENT_PROPERTY_IDX = 9;
  19955. // Group 10 = identifier inside ()
  19956. const IDENT_EVENT_IDX = 10;
  19957. // deprecated in 4.x
  19958. const TEMPLATE_ELEMENT = 'template';
  19959. // deprecated in 4.x
  19960. const TEMPLATE_ATTR = 'template';
  19961. const TEMPLATE_ATTR_PREFIX = '*';
  19962. const CLASS_ATTR = 'class';
  19963. const TEXT_CSS_SELECTOR = CssSelector.parse('*')[0];
  19964. const TEMPLATE_ELEMENT_DEPRECATION_WARNING = 'The <template> element is deprecated. Use <ng-template> instead';
  19965. const TEMPLATE_ATTR_DEPRECATION_WARNING = 'The template attribute is deprecated. Use an ng-template element instead.';
  19966. let warningCounts = {};
  19967. /**
  19968. * @param {?} warnings
  19969. * @return {?}
  19970. */
  19971. function warnOnlyOnce(warnings) {
  19972. return (error) => {
  19973. if (warnings.indexOf(error.msg) !== -1) {
  19974. warningCounts[error.msg] = (warningCounts[error.msg] || 0) + 1;
  19975. return warningCounts[error.msg] <= 1;
  19976. }
  19977. return true;
  19978. };
  19979. }
  19980. class TemplateParseError extends ParseError {
  19981. /**
  19982. * @param {?} message
  19983. * @param {?} span
  19984. * @param {?} level
  19985. */
  19986. constructor(message, span, level) {
  19987. super(span, message, level);
  19988. }
  19989. }
  19990. class TemplateParseResult {
  19991. /**
  19992. * @param {?=} templateAst
  19993. * @param {?=} usedPipes
  19994. * @param {?=} errors
  19995. */
  19996. constructor(templateAst, usedPipes, errors) {
  19997. this.templateAst = templateAst;
  19998. this.usedPipes = usedPipes;
  19999. this.errors = errors;
  20000. }
  20001. }
  20002. class TemplateParser {
  20003. /**
  20004. * @param {?} _config
  20005. * @param {?} _reflector
  20006. * @param {?} _exprParser
  20007. * @param {?} _schemaRegistry
  20008. * @param {?} _htmlParser
  20009. * @param {?} _console
  20010. * @param {?} transforms
  20011. */
  20012. constructor(_config, _reflector, _exprParser, _schemaRegistry, _htmlParser, _console, transforms) {
  20013. this._config = _config;
  20014. this._reflector = _reflector;
  20015. this._exprParser = _exprParser;
  20016. this._schemaRegistry = _schemaRegistry;
  20017. this._htmlParser = _htmlParser;
  20018. this._console = _console;
  20019. this.transforms = transforms;
  20020. }
  20021. /**
  20022. * @param {?} component
  20023. * @param {?} template
  20024. * @param {?} directives
  20025. * @param {?} pipes
  20026. * @param {?} schemas
  20027. * @param {?} templateUrl
  20028. * @param {?} preserveWhitespaces
  20029. * @return {?}
  20030. */
  20031. parse(component, template, directives, pipes, schemas, templateUrl, preserveWhitespaces) {
  20032. const /** @type {?} */ result = this.tryParse(component, template, directives, pipes, schemas, templateUrl, preserveWhitespaces);
  20033. const /** @type {?} */ warnings = /** @type {?} */ ((result.errors)).filter(error => error.level === ParseErrorLevel.WARNING).filter(warnOnlyOnce([TEMPLATE_ATTR_DEPRECATION_WARNING, TEMPLATE_ELEMENT_DEPRECATION_WARNING]));
  20034. const /** @type {?} */ errors = /** @type {?} */ ((result.errors)).filter(error => error.level === ParseErrorLevel.ERROR);
  20035. if (warnings.length > 0) {
  20036. this._console.warn(`Template parse warnings:\n${warnings.join('\n')}`);
  20037. }
  20038. if (errors.length > 0) {
  20039. const /** @type {?} */ errorString = errors.join('\n');
  20040. throw syntaxError(`Template parse errors:\n${errorString}`, errors);
  20041. }
  20042. return { template: /** @type {?} */ ((result.templateAst)), pipes: /** @type {?} */ ((result.usedPipes)) };
  20043. }
  20044. /**
  20045. * @param {?} component
  20046. * @param {?} template
  20047. * @param {?} directives
  20048. * @param {?} pipes
  20049. * @param {?} schemas
  20050. * @param {?} templateUrl
  20051. * @param {?} preserveWhitespaces
  20052. * @return {?}
  20053. */
  20054. tryParse(component, template, directives, pipes, schemas, templateUrl, preserveWhitespaces) {
  20055. let /** @type {?} */ htmlParseResult = typeof template === 'string' ? /** @type {?} */ ((this._htmlParser)).parse(template, templateUrl, true, this.getInterpolationConfig(component)) :
  20056. template;
  20057. if (!preserveWhitespaces) {
  20058. htmlParseResult = removeWhitespaces(htmlParseResult);
  20059. }
  20060. return this.tryParseHtml(this.expandHtml(htmlParseResult), component, directives, pipes, schemas);
  20061. }
  20062. /**
  20063. * @param {?} htmlAstWithErrors
  20064. * @param {?} component
  20065. * @param {?} directives
  20066. * @param {?} pipes
  20067. * @param {?} schemas
  20068. * @return {?}
  20069. */
  20070. tryParseHtml(htmlAstWithErrors, component, directives, pipes, schemas) {
  20071. let /** @type {?} */ result;
  20072. const /** @type {?} */ errors = htmlAstWithErrors.errors;
  20073. const /** @type {?} */ usedPipes = [];
  20074. if (htmlAstWithErrors.rootNodes.length > 0) {
  20075. const /** @type {?} */ uniqDirectives = removeSummaryDuplicates(directives);
  20076. const /** @type {?} */ uniqPipes = removeSummaryDuplicates(pipes);
  20077. const /** @type {?} */ providerViewContext = new ProviderViewContext(this._reflector, component);
  20078. let /** @type {?} */ interpolationConfig = /** @type {?} */ ((undefined));
  20079. if (component.template && component.template.interpolation) {
  20080. interpolationConfig = {
  20081. start: component.template.interpolation[0],
  20082. end: component.template.interpolation[1]
  20083. };
  20084. }
  20085. const /** @type {?} */ bindingParser = new BindingParser(this._exprParser, /** @type {?} */ ((interpolationConfig)), this._schemaRegistry, uniqPipes, errors);
  20086. const /** @type {?} */ parseVisitor = new TemplateParseVisitor(this._reflector, this._config, providerViewContext, uniqDirectives, bindingParser, this._schemaRegistry, schemas, errors);
  20087. result = visitAll(parseVisitor, htmlAstWithErrors.rootNodes, EMPTY_ELEMENT_CONTEXT);
  20088. errors.push(...providerViewContext.errors);
  20089. usedPipes.push(...bindingParser.getUsedPipes());
  20090. }
  20091. else {
  20092. result = [];
  20093. }
  20094. this._assertNoReferenceDuplicationOnTemplate(result, errors);
  20095. if (errors.length > 0) {
  20096. return new TemplateParseResult(result, usedPipes, errors);
  20097. }
  20098. if (this.transforms) {
  20099. this.transforms.forEach((transform) => { result = templateVisitAll(transform, result); });
  20100. }
  20101. return new TemplateParseResult(result, usedPipes, errors);
  20102. }
  20103. /**
  20104. * @param {?} htmlAstWithErrors
  20105. * @param {?=} forced
  20106. * @return {?}
  20107. */
  20108. expandHtml(htmlAstWithErrors, forced = false) {
  20109. const /** @type {?} */ errors = htmlAstWithErrors.errors;
  20110. if (errors.length == 0 || forced) {
  20111. // Transform ICU messages to angular directives
  20112. const /** @type {?} */ expandedHtmlAst = expandNodes(htmlAstWithErrors.rootNodes);
  20113. errors.push(...expandedHtmlAst.errors);
  20114. htmlAstWithErrors = new ParseTreeResult(expandedHtmlAst.nodes, errors);
  20115. }
  20116. return htmlAstWithErrors;
  20117. }
  20118. /**
  20119. * @param {?} component
  20120. * @return {?}
  20121. */
  20122. getInterpolationConfig(component) {
  20123. if (component.template) {
  20124. return InterpolationConfig.fromArray(component.template.interpolation);
  20125. }
  20126. return undefined;
  20127. }
  20128. /**
  20129. * \@internal
  20130. * @param {?} result
  20131. * @param {?} errors
  20132. * @return {?}
  20133. */
  20134. _assertNoReferenceDuplicationOnTemplate(result, errors) {
  20135. const /** @type {?} */ existingReferences = [];
  20136. result.filter(element => !!(/** @type {?} */ (element)).references)
  20137. .forEach(element => (/** @type {?} */ (element)).references.forEach((reference) => {
  20138. const /** @type {?} */ name = reference.name;
  20139. if (existingReferences.indexOf(name) < 0) {
  20140. existingReferences.push(name);
  20141. }
  20142. else {
  20143. const /** @type {?} */ error = new TemplateParseError(`Reference "#${name}" is defined several times`, reference.sourceSpan, ParseErrorLevel.ERROR);
  20144. errors.push(error);
  20145. }
  20146. }));
  20147. }
  20148. }
  20149. class TemplateParseVisitor {
  20150. /**
  20151. * @param {?} reflector
  20152. * @param {?} config
  20153. * @param {?} providerViewContext
  20154. * @param {?} directives
  20155. * @param {?} _bindingParser
  20156. * @param {?} _schemaRegistry
  20157. * @param {?} _schemas
  20158. * @param {?} _targetErrors
  20159. */
  20160. constructor(reflector, config, providerViewContext, directives, _bindingParser, _schemaRegistry, _schemas, _targetErrors) {
  20161. this.reflector = reflector;
  20162. this.config = config;
  20163. this.providerViewContext = providerViewContext;
  20164. this._bindingParser = _bindingParser;
  20165. this._schemaRegistry = _schemaRegistry;
  20166. this._schemas = _schemas;
  20167. this._targetErrors = _targetErrors;
  20168. this.selectorMatcher = new SelectorMatcher();
  20169. this.directivesIndex = new Map();
  20170. this.ngContentCount = 0;
  20171. // Note: queries start with id 1 so we can use the number in a Bloom filter!
  20172. this.contentQueryStartId = providerViewContext.component.viewQueries.length + 1;
  20173. directives.forEach((directive, index) => {
  20174. const /** @type {?} */ selector = CssSelector.parse(/** @type {?} */ ((directive.selector)));
  20175. this.selectorMatcher.addSelectables(selector, directive);
  20176. this.directivesIndex.set(directive, index);
  20177. });
  20178. }
  20179. /**
  20180. * @param {?} expansion
  20181. * @param {?} context
  20182. * @return {?}
  20183. */
  20184. visitExpansion(expansion, context) { return null; }
  20185. /**
  20186. * @param {?} expansionCase
  20187. * @param {?} context
  20188. * @return {?}
  20189. */
  20190. visitExpansionCase(expansionCase, context) { return null; }
  20191. /**
  20192. * @param {?} text
  20193. * @param {?} parent
  20194. * @return {?}
  20195. */
  20196. visitText(text, parent) {
  20197. const /** @type {?} */ ngContentIndex = /** @type {?} */ ((parent.findNgContentIndex(TEXT_CSS_SELECTOR)));
  20198. const /** @type {?} */ valueNoNgsp = replaceNgsp(text.value);
  20199. const /** @type {?} */ expr = this._bindingParser.parseInterpolation(valueNoNgsp, /** @type {?} */ ((text.sourceSpan)));
  20200. return expr ? new BoundTextAst(expr, ngContentIndex, /** @type {?} */ ((text.sourceSpan))) :
  20201. new TextAst(valueNoNgsp, ngContentIndex, /** @type {?} */ ((text.sourceSpan)));
  20202. }
  20203. /**
  20204. * @param {?} attribute
  20205. * @param {?} context
  20206. * @return {?}
  20207. */
  20208. visitAttribute(attribute, context) {
  20209. return new AttrAst(attribute.name, attribute.value, attribute.sourceSpan);
  20210. }
  20211. /**
  20212. * @param {?} comment
  20213. * @param {?} context
  20214. * @return {?}
  20215. */
  20216. visitComment(comment, context) { return null; }
  20217. /**
  20218. * @param {?} element
  20219. * @param {?} parent
  20220. * @return {?}
  20221. */
  20222. visitElement(element, parent) {
  20223. const /** @type {?} */ queryStartIndex = this.contentQueryStartId;
  20224. const /** @type {?} */ nodeName = element.name;
  20225. const /** @type {?} */ preparsedElement = preparseElement(element);
  20226. if (preparsedElement.type === PreparsedElementType.SCRIPT ||
  20227. preparsedElement.type === PreparsedElementType.STYLE) {
  20228. // Skipping <script> for security reasons
  20229. // Skipping <style> as we already processed them
  20230. // in the StyleCompiler
  20231. return null;
  20232. }
  20233. if (preparsedElement.type === PreparsedElementType.STYLESHEET &&
  20234. isStyleUrlResolvable(preparsedElement.hrefAttr)) {
  20235. // Skipping stylesheets with either relative urls or package scheme as we already processed
  20236. // them in the StyleCompiler
  20237. return null;
  20238. }
  20239. const /** @type {?} */ matchableAttrs = [];
  20240. const /** @type {?} */ elementOrDirectiveProps = [];
  20241. const /** @type {?} */ elementOrDirectiveRefs = [];
  20242. const /** @type {?} */ elementVars = [];
  20243. const /** @type {?} */ events = [];
  20244. const /** @type {?} */ templateElementOrDirectiveProps = [];
  20245. const /** @type {?} */ templateMatchableAttrs = [];
  20246. const /** @type {?} */ templateElementVars = [];
  20247. let /** @type {?} */ hasInlineTemplates = false;
  20248. const /** @type {?} */ attrs = [];
  20249. const /** @type {?} */ isTemplateElement = isTemplate(element, this.config.enableLegacyTemplate, (m, span) => this._reportError(m, span, ParseErrorLevel.WARNING));
  20250. element.attrs.forEach(attr => {
  20251. const /** @type {?} */ hasBinding = this._parseAttr(isTemplateElement, attr, matchableAttrs, elementOrDirectiveProps, events, elementOrDirectiveRefs, elementVars);
  20252. let /** @type {?} */ templateBindingsSource;
  20253. let /** @type {?} */ prefixToken;
  20254. let /** @type {?} */ normalizedName = this._normalizeAttributeName(attr.name);
  20255. if (this.config.enableLegacyTemplate && normalizedName == TEMPLATE_ATTR) {
  20256. this._reportError(TEMPLATE_ATTR_DEPRECATION_WARNING, attr.sourceSpan, ParseErrorLevel.WARNING);
  20257. templateBindingsSource = attr.value;
  20258. }
  20259. else if (normalizedName.startsWith(TEMPLATE_ATTR_PREFIX)) {
  20260. templateBindingsSource = attr.value;
  20261. prefixToken = normalizedName.substring(TEMPLATE_ATTR_PREFIX.length) + ':';
  20262. }
  20263. const /** @type {?} */ hasTemplateBinding = templateBindingsSource != null;
  20264. if (hasTemplateBinding) {
  20265. if (hasInlineTemplates) {
  20266. this._reportError(`Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with *`, attr.sourceSpan);
  20267. }
  20268. hasInlineTemplates = true;
  20269. this._bindingParser.parseInlineTemplateBinding(/** @type {?} */ ((prefixToken)), /** @type {?} */ ((templateBindingsSource)), attr.sourceSpan, templateMatchableAttrs, templateElementOrDirectiveProps, templateElementVars);
  20270. }
  20271. if (!hasBinding && !hasTemplateBinding) {
  20272. // don't include the bindings as attributes as well in the AST
  20273. attrs.push(this.visitAttribute(attr, null));
  20274. matchableAttrs.push([attr.name, attr.value]);
  20275. }
  20276. });
  20277. const /** @type {?} */ elementCssSelector = createElementCssSelector(nodeName, matchableAttrs);
  20278. const { directives: directiveMetas, matchElement } = this._parseDirectives(this.selectorMatcher, elementCssSelector);
  20279. const /** @type {?} */ references = [];
  20280. const /** @type {?} */ boundDirectivePropNames = new Set();
  20281. const /** @type {?} */ directiveAsts = this._createDirectiveAsts(isTemplateElement, element.name, directiveMetas, elementOrDirectiveProps, elementOrDirectiveRefs, /** @type {?} */ ((element.sourceSpan)), references, boundDirectivePropNames);
  20282. const /** @type {?} */ elementProps = this._createElementPropertyAsts(element.name, elementOrDirectiveProps, boundDirectivePropNames);
  20283. const /** @type {?} */ isViewRoot = parent.isTemplateElement || hasInlineTemplates;
  20284. const /** @type {?} */ providerContext = new ProviderElementContext(this.providerViewContext, /** @type {?} */ ((parent.providerContext)), isViewRoot, directiveAsts, attrs, references, isTemplateElement, queryStartIndex, /** @type {?} */ ((element.sourceSpan)));
  20285. const /** @type {?} */ children = visitAll(preparsedElement.nonBindable ? NON_BINDABLE_VISITOR : this, element.children, ElementContext.create(isTemplateElement, directiveAsts, isTemplateElement ? /** @type {?} */ ((parent.providerContext)) : providerContext));
  20286. providerContext.afterElement();
  20287. // Override the actual selector when the `ngProjectAs` attribute is provided
  20288. const /** @type {?} */ projectionSelector = preparsedElement.projectAs != null ?
  20289. CssSelector.parse(preparsedElement.projectAs)[0] :
  20290. elementCssSelector;
  20291. const /** @type {?} */ ngContentIndex = /** @type {?} */ ((parent.findNgContentIndex(projectionSelector)));
  20292. let /** @type {?} */ parsedElement;
  20293. if (preparsedElement.type === PreparsedElementType.NG_CONTENT) {
  20294. if (element.children && !element.children.every(_isEmptyTextNode)) {
  20295. this._reportError(`<ng-content> element cannot have content.`, /** @type {?} */ ((element.sourceSpan)));
  20296. }
  20297. parsedElement = new NgContentAst(this.ngContentCount++, hasInlineTemplates ? /** @type {?} */ ((null)) : ngContentIndex, /** @type {?} */ ((element.sourceSpan)));
  20298. }
  20299. else if (isTemplateElement) {
  20300. this._assertAllEventsPublishedByDirectives(directiveAsts, events);
  20301. this._assertNoComponentsNorElementBindingsOnTemplate(directiveAsts, elementProps, /** @type {?} */ ((element.sourceSpan)));
  20302. parsedElement = new EmbeddedTemplateAst(attrs, events, references, elementVars, providerContext.transformedDirectiveAsts, providerContext.transformProviders, providerContext.transformedHasViewContainer, providerContext.queryMatches, children, hasInlineTemplates ? /** @type {?} */ ((null)) : ngContentIndex, /** @type {?} */ ((element.sourceSpan)));
  20303. }
  20304. else {
  20305. this._assertElementExists(matchElement, element);
  20306. this._assertOnlyOneComponent(directiveAsts, /** @type {?} */ ((element.sourceSpan)));
  20307. const /** @type {?} */ ngContentIndex = hasInlineTemplates ? null : parent.findNgContentIndex(projectionSelector);
  20308. parsedElement = new ElementAst(nodeName, attrs, elementProps, events, references, providerContext.transformedDirectiveAsts, providerContext.transformProviders, providerContext.transformedHasViewContainer, providerContext.queryMatches, children, hasInlineTemplates ? null : ngContentIndex, element.sourceSpan, element.endSourceSpan || null);
  20309. }
  20310. if (hasInlineTemplates) {
  20311. const /** @type {?} */ templateQueryStartIndex = this.contentQueryStartId;
  20312. const /** @type {?} */ templateSelector = createElementCssSelector(TEMPLATE_ELEMENT, templateMatchableAttrs);
  20313. const { directives: templateDirectiveMetas } = this._parseDirectives(this.selectorMatcher, templateSelector);
  20314. const /** @type {?} */ templateBoundDirectivePropNames = new Set();
  20315. const /** @type {?} */ templateDirectiveAsts = this._createDirectiveAsts(true, element.name, templateDirectiveMetas, templateElementOrDirectiveProps, [], /** @type {?} */ ((element.sourceSpan)), [], templateBoundDirectivePropNames);
  20316. const /** @type {?} */ templateElementProps = this._createElementPropertyAsts(element.name, templateElementOrDirectiveProps, templateBoundDirectivePropNames);
  20317. this._assertNoComponentsNorElementBindingsOnTemplate(templateDirectiveAsts, templateElementProps, /** @type {?} */ ((element.sourceSpan)));
  20318. const /** @type {?} */ templateProviderContext = new ProviderElementContext(this.providerViewContext, /** @type {?} */ ((parent.providerContext)), parent.isTemplateElement, templateDirectiveAsts, [], [], true, templateQueryStartIndex, /** @type {?} */ ((element.sourceSpan)));
  20319. templateProviderContext.afterElement();
  20320. parsedElement = new EmbeddedTemplateAst([], [], [], templateElementVars, templateProviderContext.transformedDirectiveAsts, templateProviderContext.transformProviders, templateProviderContext.transformedHasViewContainer, templateProviderContext.queryMatches, [parsedElement], ngContentIndex, /** @type {?} */ ((element.sourceSpan)));
  20321. }
  20322. return parsedElement;
  20323. }
  20324. /**
  20325. * @param {?} isTemplateElement
  20326. * @param {?} attr
  20327. * @param {?} targetMatchableAttrs
  20328. * @param {?} targetProps
  20329. * @param {?} targetEvents
  20330. * @param {?} targetRefs
  20331. * @param {?} targetVars
  20332. * @return {?}
  20333. */
  20334. _parseAttr(isTemplateElement, attr, targetMatchableAttrs, targetProps, targetEvents, targetRefs, targetVars) {
  20335. const /** @type {?} */ name = this._normalizeAttributeName(attr.name);
  20336. const /** @type {?} */ value = attr.value;
  20337. const /** @type {?} */ srcSpan = attr.sourceSpan;
  20338. const /** @type {?} */ bindParts = name.match(BIND_NAME_REGEXP);
  20339. let /** @type {?} */ hasBinding = false;
  20340. if (bindParts !== null) {
  20341. hasBinding = true;
  20342. if (bindParts[KW_BIND_IDX] != null) {
  20343. this._bindingParser.parsePropertyBinding(bindParts[IDENT_KW_IDX], value, false, srcSpan, targetMatchableAttrs, targetProps);
  20344. }
  20345. else if (bindParts[KW_LET_IDX]) {
  20346. if (isTemplateElement) {
  20347. const /** @type {?} */ identifier = bindParts[IDENT_KW_IDX];
  20348. this._parseVariable(identifier, value, srcSpan, targetVars);
  20349. }
  20350. else {
  20351. this._reportError(`"let-" is only supported on ng-template elements.`, srcSpan);
  20352. }
  20353. }
  20354. else if (bindParts[KW_REF_IDX]) {
  20355. const /** @type {?} */ identifier = bindParts[IDENT_KW_IDX];
  20356. this._parseReference(identifier, value, srcSpan, targetRefs);
  20357. }
  20358. else if (bindParts[KW_ON_IDX]) {
  20359. this._bindingParser.parseEvent(bindParts[IDENT_KW_IDX], value, srcSpan, targetMatchableAttrs, targetEvents);
  20360. }
  20361. else if (bindParts[KW_BINDON_IDX]) {
  20362. this._bindingParser.parsePropertyBinding(bindParts[IDENT_KW_IDX], value, false, srcSpan, targetMatchableAttrs, targetProps);
  20363. this._parseAssignmentEvent(bindParts[IDENT_KW_IDX], value, srcSpan, targetMatchableAttrs, targetEvents);
  20364. }
  20365. else if (bindParts[KW_AT_IDX]) {
  20366. this._bindingParser.parseLiteralAttr(name, value, srcSpan, targetMatchableAttrs, targetProps);
  20367. }
  20368. else if (bindParts[IDENT_BANANA_BOX_IDX]) {
  20369. this._bindingParser.parsePropertyBinding(bindParts[IDENT_BANANA_BOX_IDX], value, false, srcSpan, targetMatchableAttrs, targetProps);
  20370. this._parseAssignmentEvent(bindParts[IDENT_BANANA_BOX_IDX], value, srcSpan, targetMatchableAttrs, targetEvents);
  20371. }
  20372. else if (bindParts[IDENT_PROPERTY_IDX]) {
  20373. this._bindingParser.parsePropertyBinding(bindParts[IDENT_PROPERTY_IDX], value, false, srcSpan, targetMatchableAttrs, targetProps);
  20374. }
  20375. else if (bindParts[IDENT_EVENT_IDX]) {
  20376. this._bindingParser.parseEvent(bindParts[IDENT_EVENT_IDX], value, srcSpan, targetMatchableAttrs, targetEvents);
  20377. }
  20378. }
  20379. else {
  20380. hasBinding = this._bindingParser.parsePropertyInterpolation(name, value, srcSpan, targetMatchableAttrs, targetProps);
  20381. }
  20382. if (!hasBinding) {
  20383. this._bindingParser.parseLiteralAttr(name, value, srcSpan, targetMatchableAttrs, targetProps);
  20384. }
  20385. return hasBinding;
  20386. }
  20387. /**
  20388. * @param {?} attrName
  20389. * @return {?}
  20390. */
  20391. _normalizeAttributeName(attrName) {
  20392. return /^data-/i.test(attrName) ? attrName.substring(5) : attrName;
  20393. }
  20394. /**
  20395. * @param {?} identifier
  20396. * @param {?} value
  20397. * @param {?} sourceSpan
  20398. * @param {?} targetVars
  20399. * @return {?}
  20400. */
  20401. _parseVariable(identifier, value, sourceSpan, targetVars) {
  20402. if (identifier.indexOf('-') > -1) {
  20403. this._reportError(`"-" is not allowed in variable names`, sourceSpan);
  20404. }
  20405. targetVars.push(new VariableAst(identifier, value, sourceSpan));
  20406. }
  20407. /**
  20408. * @param {?} identifier
  20409. * @param {?} value
  20410. * @param {?} sourceSpan
  20411. * @param {?} targetRefs
  20412. * @return {?}
  20413. */
  20414. _parseReference(identifier, value, sourceSpan, targetRefs) {
  20415. if (identifier.indexOf('-') > -1) {
  20416. this._reportError(`"-" is not allowed in reference names`, sourceSpan);
  20417. }
  20418. targetRefs.push(new ElementOrDirectiveRef(identifier, value, sourceSpan));
  20419. }
  20420. /**
  20421. * @param {?} name
  20422. * @param {?} expression
  20423. * @param {?} sourceSpan
  20424. * @param {?} targetMatchableAttrs
  20425. * @param {?} targetEvents
  20426. * @return {?}
  20427. */
  20428. _parseAssignmentEvent(name, expression, sourceSpan, targetMatchableAttrs, targetEvents) {
  20429. this._bindingParser.parseEvent(`${name}Change`, `${expression}=$event`, sourceSpan, targetMatchableAttrs, targetEvents);
  20430. }
  20431. /**
  20432. * @param {?} selectorMatcher
  20433. * @param {?} elementCssSelector
  20434. * @return {?}
  20435. */
  20436. _parseDirectives(selectorMatcher, elementCssSelector) {
  20437. // Need to sort the directives so that we get consistent results throughout,
  20438. // as selectorMatcher uses Maps inside.
  20439. // Also deduplicate directives as they might match more than one time!
  20440. const /** @type {?} */ directives = new Array(this.directivesIndex.size);
  20441. // Whether any directive selector matches on the element name
  20442. let /** @type {?} */ matchElement = false;
  20443. selectorMatcher.match(elementCssSelector, (selector, directive) => {
  20444. directives[/** @type {?} */ ((this.directivesIndex.get(directive)))] = directive;
  20445. matchElement = matchElement || selector.hasElementSelector();
  20446. });
  20447. return {
  20448. directives: directives.filter(dir => !!dir),
  20449. matchElement,
  20450. };
  20451. }
  20452. /**
  20453. * @param {?} isTemplateElement
  20454. * @param {?} elementName
  20455. * @param {?} directives
  20456. * @param {?} props
  20457. * @param {?} elementOrDirectiveRefs
  20458. * @param {?} elementSourceSpan
  20459. * @param {?} targetReferences
  20460. * @param {?} targetBoundDirectivePropNames
  20461. * @return {?}
  20462. */
  20463. _createDirectiveAsts(isTemplateElement, elementName, directives, props, elementOrDirectiveRefs, elementSourceSpan, targetReferences, targetBoundDirectivePropNames) {
  20464. const /** @type {?} */ matchedReferences = new Set();
  20465. let /** @type {?} */ component = /** @type {?} */ ((null));
  20466. const /** @type {?} */ directiveAsts = directives.map((directive) => {
  20467. const /** @type {?} */ sourceSpan = new ParseSourceSpan(elementSourceSpan.start, elementSourceSpan.end, `Directive ${identifierName(directive.type)}`);
  20468. if (directive.isComponent) {
  20469. component = directive;
  20470. }
  20471. const /** @type {?} */ directiveProperties = [];
  20472. let /** @type {?} */ hostProperties = /** @type {?} */ ((this._bindingParser.createDirectiveHostPropertyAsts(directive, elementName, sourceSpan)));
  20473. // Note: We need to check the host properties here as well,
  20474. // as we don't know the element name in the DirectiveWrapperCompiler yet.
  20475. hostProperties = this._checkPropertiesInSchema(elementName, hostProperties);
  20476. const /** @type {?} */ hostEvents = /** @type {?} */ ((this._bindingParser.createDirectiveHostEventAsts(directive, sourceSpan)));
  20477. this._createDirectivePropertyAsts(directive.inputs, props, directiveProperties, targetBoundDirectivePropNames);
  20478. elementOrDirectiveRefs.forEach((elOrDirRef) => {
  20479. if ((elOrDirRef.value.length === 0 && directive.isComponent) ||
  20480. (elOrDirRef.isReferenceToDirective(directive))) {
  20481. targetReferences.push(new ReferenceAst(elOrDirRef.name, createTokenForReference(directive.type.reference), elOrDirRef.sourceSpan));
  20482. matchedReferences.add(elOrDirRef.name);
  20483. }
  20484. });
  20485. const /** @type {?} */ contentQueryStartId = this.contentQueryStartId;
  20486. this.contentQueryStartId += directive.queries.length;
  20487. return new DirectiveAst(directive, directiveProperties, hostProperties, hostEvents, contentQueryStartId, sourceSpan);
  20488. });
  20489. elementOrDirectiveRefs.forEach((elOrDirRef) => {
  20490. if (elOrDirRef.value.length > 0) {
  20491. if (!matchedReferences.has(elOrDirRef.name)) {
  20492. this._reportError(`There is no directive with "exportAs" set to "${elOrDirRef.value}"`, elOrDirRef.sourceSpan);
  20493. }
  20494. }
  20495. else if (!component) {
  20496. let /** @type {?} */ refToken = /** @type {?} */ ((null));
  20497. if (isTemplateElement) {
  20498. refToken = createTokenForExternalReference(this.reflector, Identifiers.TemplateRef);
  20499. }
  20500. targetReferences.push(new ReferenceAst(elOrDirRef.name, refToken, elOrDirRef.sourceSpan));
  20501. }
  20502. });
  20503. return directiveAsts;
  20504. }
  20505. /**
  20506. * @param {?} directiveProperties
  20507. * @param {?} boundProps
  20508. * @param {?} targetBoundDirectiveProps
  20509. * @param {?} targetBoundDirectivePropNames
  20510. * @return {?}
  20511. */
  20512. _createDirectivePropertyAsts(directiveProperties, boundProps, targetBoundDirectiveProps, targetBoundDirectivePropNames) {
  20513. if (directiveProperties) {
  20514. const /** @type {?} */ boundPropsByName = new Map();
  20515. boundProps.forEach(boundProp => {
  20516. const /** @type {?} */ prevValue = boundPropsByName.get(boundProp.name);
  20517. if (!prevValue || prevValue.isLiteral) {
  20518. // give [a]="b" a higher precedence than a="b" on the same element
  20519. boundPropsByName.set(boundProp.name, boundProp);
  20520. }
  20521. });
  20522. Object.keys(directiveProperties).forEach(dirProp => {
  20523. const /** @type {?} */ elProp = directiveProperties[dirProp];
  20524. const /** @type {?} */ boundProp = boundPropsByName.get(elProp);
  20525. // Bindings are optional, so this binding only needs to be set up if an expression is given.
  20526. if (boundProp) {
  20527. targetBoundDirectivePropNames.add(boundProp.name);
  20528. if (!isEmptyExpression(boundProp.expression)) {
  20529. targetBoundDirectiveProps.push(new BoundDirectivePropertyAst(dirProp, boundProp.name, boundProp.expression, boundProp.sourceSpan));
  20530. }
  20531. }
  20532. });
  20533. }
  20534. }
  20535. /**
  20536. * @param {?} elementName
  20537. * @param {?} props
  20538. * @param {?} boundDirectivePropNames
  20539. * @return {?}
  20540. */
  20541. _createElementPropertyAsts(elementName, props, boundDirectivePropNames) {
  20542. const /** @type {?} */ boundElementProps = [];
  20543. props.forEach((prop) => {
  20544. if (!prop.isLiteral && !boundDirectivePropNames.has(prop.name)) {
  20545. boundElementProps.push(this._bindingParser.createElementPropertyAst(elementName, prop));
  20546. }
  20547. });
  20548. return this._checkPropertiesInSchema(elementName, boundElementProps);
  20549. }
  20550. /**
  20551. * @param {?} directives
  20552. * @return {?}
  20553. */
  20554. _findComponentDirectives(directives) {
  20555. return directives.filter(directive => directive.directive.isComponent);
  20556. }
  20557. /**
  20558. * @param {?} directives
  20559. * @return {?}
  20560. */
  20561. _findComponentDirectiveNames(directives) {
  20562. return this._findComponentDirectives(directives)
  20563. .map(directive => /** @type {?} */ ((identifierName(directive.directive.type))));
  20564. }
  20565. /**
  20566. * @param {?} directives
  20567. * @param {?} sourceSpan
  20568. * @return {?}
  20569. */
  20570. _assertOnlyOneComponent(directives, sourceSpan) {
  20571. const /** @type {?} */ componentTypeNames = this._findComponentDirectiveNames(directives);
  20572. if (componentTypeNames.length > 1) {
  20573. this._reportError(`More than one component matched on this element.\n` +
  20574. `Make sure that only one component's selector can match a given element.\n` +
  20575. `Conflicting components: ${componentTypeNames.join(',')}`, sourceSpan);
  20576. }
  20577. }
  20578. /**
  20579. * Make sure that non-angular tags conform to the schemas.
  20580. *
  20581. * Note: An element is considered an angular tag when at least one directive selector matches the
  20582. * tag name.
  20583. *
  20584. * @param {?} matchElement Whether any directive has matched on the tag name
  20585. * @param {?} element the html element
  20586. * @return {?}
  20587. */
  20588. _assertElementExists(matchElement, element) {
  20589. const /** @type {?} */ elName = element.name.replace(/^:xhtml:/, '');
  20590. if (!matchElement && !this._schemaRegistry.hasElement(elName, this._schemas)) {
  20591. let /** @type {?} */ errorMsg = `'${elName}' is not a known element:\n`;
  20592. errorMsg +=
  20593. `1. If '${elName}' is an Angular component, then verify that it is part of this module.\n`;
  20594. if (elName.indexOf('-') > -1) {
  20595. errorMsg +=
  20596. `2. If '${elName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.`;
  20597. }
  20598. else {
  20599. errorMsg +=
  20600. `2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.`;
  20601. }
  20602. this._reportError(errorMsg, /** @type {?} */ ((element.sourceSpan)));
  20603. }
  20604. }
  20605. /**
  20606. * @param {?} directives
  20607. * @param {?} elementProps
  20608. * @param {?} sourceSpan
  20609. * @return {?}
  20610. */
  20611. _assertNoComponentsNorElementBindingsOnTemplate(directives, elementProps, sourceSpan) {
  20612. const /** @type {?} */ componentTypeNames = this._findComponentDirectiveNames(directives);
  20613. if (componentTypeNames.length > 0) {
  20614. this._reportError(`Components on an embedded template: ${componentTypeNames.join(',')}`, sourceSpan);
  20615. }
  20616. elementProps.forEach(prop => {
  20617. this._reportError(`Property binding ${prop.name} not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".`, sourceSpan);
  20618. });
  20619. }
  20620. /**
  20621. * @param {?} directives
  20622. * @param {?} events
  20623. * @return {?}
  20624. */
  20625. _assertAllEventsPublishedByDirectives(directives, events) {
  20626. const /** @type {?} */ allDirectiveEvents = new Set();
  20627. directives.forEach(directive => {
  20628. Object.keys(directive.directive.outputs).forEach(k => {
  20629. const /** @type {?} */ eventName = directive.directive.outputs[k];
  20630. allDirectiveEvents.add(eventName);
  20631. });
  20632. });
  20633. events.forEach(event => {
  20634. if (event.target != null || !allDirectiveEvents.has(event.name)) {
  20635. this._reportError(`Event binding ${event.fullName} not emitted by any directive on an embedded template. Make sure that the event name is spelled correctly and all directives are listed in the "@NgModule.declarations".`, event.sourceSpan);
  20636. }
  20637. });
  20638. }
  20639. /**
  20640. * @param {?} elementName
  20641. * @param {?} boundProps
  20642. * @return {?}
  20643. */
  20644. _checkPropertiesInSchema(elementName, boundProps) {
  20645. // Note: We can't filter out empty expressions before this method,
  20646. // as we still want to validate them!
  20647. return boundProps.filter((boundProp) => {
  20648. if (boundProp.type === PropertyBindingType.Property &&
  20649. !this._schemaRegistry.hasProperty(elementName, boundProp.name, this._schemas)) {
  20650. let /** @type {?} */ errorMsg = `Can't bind to '${boundProp.name}' since it isn't a known property of '${elementName}'.`;
  20651. if (elementName.startsWith('ng-')) {
  20652. errorMsg +=
  20653. `\n1. If '${boundProp.name}' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.` +
  20654. `\n2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.`;
  20655. }
  20656. else if (elementName.indexOf('-') > -1) {
  20657. errorMsg +=
  20658. `\n1. If '${elementName}' is an Angular component and it has '${boundProp.name}' input, then verify that it is part of this module.` +
  20659. `\n2. If '${elementName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.` +
  20660. `\n3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.`;
  20661. }
  20662. this._reportError(errorMsg, boundProp.sourceSpan);
  20663. }
  20664. return !isEmptyExpression(boundProp.value);
  20665. });
  20666. }
  20667. /**
  20668. * @param {?} message
  20669. * @param {?} sourceSpan
  20670. * @param {?=} level
  20671. * @return {?}
  20672. */
  20673. _reportError(message, sourceSpan, level = ParseErrorLevel.ERROR) {
  20674. this._targetErrors.push(new ParseError(sourceSpan, message, level));
  20675. }
  20676. }
  20677. class NonBindableVisitor {
  20678. /**
  20679. * @param {?} ast
  20680. * @param {?} parent
  20681. * @return {?}
  20682. */
  20683. visitElement(ast, parent) {
  20684. const /** @type {?} */ preparsedElement = preparseElement(ast);
  20685. if (preparsedElement.type === PreparsedElementType.SCRIPT ||
  20686. preparsedElement.type === PreparsedElementType.STYLE ||
  20687. preparsedElement.type === PreparsedElementType.STYLESHEET) {
  20688. // Skipping <script> for security reasons
  20689. // Skipping <style> and stylesheets as we already processed them
  20690. // in the StyleCompiler
  20691. return null;
  20692. }
  20693. const /** @type {?} */ attrNameAndValues = ast.attrs.map((attr) => [attr.name, attr.value]);
  20694. const /** @type {?} */ selector = createElementCssSelector(ast.name, attrNameAndValues);
  20695. const /** @type {?} */ ngContentIndex = parent.findNgContentIndex(selector);
  20696. const /** @type {?} */ children = visitAll(this, ast.children, EMPTY_ELEMENT_CONTEXT);
  20697. return new ElementAst(ast.name, visitAll(this, ast.attrs), [], [], [], [], [], false, [], children, ngContentIndex, ast.sourceSpan, ast.endSourceSpan);
  20698. }
  20699. /**
  20700. * @param {?} comment
  20701. * @param {?} context
  20702. * @return {?}
  20703. */
  20704. visitComment(comment, context) { return null; }
  20705. /**
  20706. * @param {?} attribute
  20707. * @param {?} context
  20708. * @return {?}
  20709. */
  20710. visitAttribute(attribute, context) {
  20711. return new AttrAst(attribute.name, attribute.value, attribute.sourceSpan);
  20712. }
  20713. /**
  20714. * @param {?} text
  20715. * @param {?} parent
  20716. * @return {?}
  20717. */
  20718. visitText(text, parent) {
  20719. const /** @type {?} */ ngContentIndex = /** @type {?} */ ((parent.findNgContentIndex(TEXT_CSS_SELECTOR)));
  20720. return new TextAst(text.value, ngContentIndex, /** @type {?} */ ((text.sourceSpan)));
  20721. }
  20722. /**
  20723. * @param {?} expansion
  20724. * @param {?} context
  20725. * @return {?}
  20726. */
  20727. visitExpansion(expansion, context) { return expansion; }
  20728. /**
  20729. * @param {?} expansionCase
  20730. * @param {?} context
  20731. * @return {?}
  20732. */
  20733. visitExpansionCase(expansionCase, context) { return expansionCase; }
  20734. }
  20735. /**
  20736. * A reference to an element or directive in a template. E.g., the reference in this template:
  20737. *
  20738. * <div #myMenu="coolMenu">
  20739. *
  20740. * would be {name: 'myMenu', value: 'coolMenu', sourceSpan: ...}
  20741. */
  20742. class ElementOrDirectiveRef {
  20743. /**
  20744. * @param {?} name
  20745. * @param {?} value
  20746. * @param {?} sourceSpan
  20747. */
  20748. constructor(name, value, sourceSpan) {
  20749. this.name = name;
  20750. this.value = value;
  20751. this.sourceSpan = sourceSpan;
  20752. }
  20753. /**
  20754. * Gets whether this is a reference to the given directive.
  20755. * @param {?} directive
  20756. * @return {?}
  20757. */
  20758. isReferenceToDirective(directive) {
  20759. return splitExportAs(directive.exportAs).indexOf(this.value) !== -1;
  20760. }
  20761. }
  20762. /**
  20763. * Splits a raw, potentially comma-delimted `exportAs` value into an array of names.
  20764. * @param {?} exportAs
  20765. * @return {?}
  20766. */
  20767. function splitExportAs(exportAs) {
  20768. return exportAs ? exportAs.split(',').map(e => e.trim()) : [];
  20769. }
  20770. /**
  20771. * @param {?} classAttrValue
  20772. * @return {?}
  20773. */
  20774. function splitClasses(classAttrValue) {
  20775. return classAttrValue.trim().split(/\s+/g);
  20776. }
  20777. class ElementContext {
  20778. /**
  20779. * @param {?} isTemplateElement
  20780. * @param {?} _ngContentIndexMatcher
  20781. * @param {?} _wildcardNgContentIndex
  20782. * @param {?} providerContext
  20783. */
  20784. constructor(isTemplateElement, _ngContentIndexMatcher, _wildcardNgContentIndex, providerContext) {
  20785. this.isTemplateElement = isTemplateElement;
  20786. this._ngContentIndexMatcher = _ngContentIndexMatcher;
  20787. this._wildcardNgContentIndex = _wildcardNgContentIndex;
  20788. this.providerContext = providerContext;
  20789. }
  20790. /**
  20791. * @param {?} isTemplateElement
  20792. * @param {?} directives
  20793. * @param {?} providerContext
  20794. * @return {?}
  20795. */
  20796. static create(isTemplateElement, directives, providerContext) {
  20797. const /** @type {?} */ matcher = new SelectorMatcher();
  20798. let /** @type {?} */ wildcardNgContentIndex = /** @type {?} */ ((null));
  20799. const /** @type {?} */ component = directives.find(directive => directive.directive.isComponent);
  20800. if (component) {
  20801. const /** @type {?} */ ngContentSelectors = /** @type {?} */ ((component.directive.template)).ngContentSelectors;
  20802. for (let /** @type {?} */ i = 0; i < ngContentSelectors.length; i++) {
  20803. const /** @type {?} */ selector = ngContentSelectors[i];
  20804. if (selector === '*') {
  20805. wildcardNgContentIndex = i;
  20806. }
  20807. else {
  20808. matcher.addSelectables(CssSelector.parse(ngContentSelectors[i]), i);
  20809. }
  20810. }
  20811. }
  20812. return new ElementContext(isTemplateElement, matcher, wildcardNgContentIndex, providerContext);
  20813. }
  20814. /**
  20815. * @param {?} selector
  20816. * @return {?}
  20817. */
  20818. findNgContentIndex(selector) {
  20819. const /** @type {?} */ ngContentIndices = [];
  20820. this._ngContentIndexMatcher.match(selector, (selector, ngContentIndex) => { ngContentIndices.push(ngContentIndex); });
  20821. ngContentIndices.sort();
  20822. if (this._wildcardNgContentIndex != null) {
  20823. ngContentIndices.push(this._wildcardNgContentIndex);
  20824. }
  20825. return ngContentIndices.length > 0 ? ngContentIndices[0] : null;
  20826. }
  20827. }
  20828. /**
  20829. * @param {?} elementName
  20830. * @param {?} attributes
  20831. * @return {?}
  20832. */
  20833. function createElementCssSelector(elementName, attributes) {
  20834. const /** @type {?} */ cssSelector = new CssSelector();
  20835. const /** @type {?} */ elNameNoNs = splitNsName(elementName)[1];
  20836. cssSelector.setElement(elNameNoNs);
  20837. for (let /** @type {?} */ i = 0; i < attributes.length; i++) {
  20838. const /** @type {?} */ attrName = attributes[i][0];
  20839. const /** @type {?} */ attrNameNoNs = splitNsName(attrName)[1];
  20840. const /** @type {?} */ attrValue = attributes[i][1];
  20841. cssSelector.addAttribute(attrNameNoNs, attrValue);
  20842. if (attrName.toLowerCase() == CLASS_ATTR) {
  20843. const /** @type {?} */ classes = splitClasses(attrValue);
  20844. classes.forEach(className => cssSelector.addClassName(className));
  20845. }
  20846. }
  20847. return cssSelector;
  20848. }
  20849. const EMPTY_ELEMENT_CONTEXT = new ElementContext(true, new SelectorMatcher(), null, null);
  20850. const NON_BINDABLE_VISITOR = new NonBindableVisitor();
  20851. /**
  20852. * @param {?} node
  20853. * @return {?}
  20854. */
  20855. function _isEmptyTextNode(node) {
  20856. return node instanceof Text && node.value.trim().length == 0;
  20857. }
  20858. /**
  20859. * @template T
  20860. * @param {?} items
  20861. * @return {?}
  20862. */
  20863. function removeSummaryDuplicates(items) {
  20864. const /** @type {?} */ map = new Map();
  20865. items.forEach((item) => {
  20866. if (!map.get(item.type.reference)) {
  20867. map.set(item.type.reference, item);
  20868. }
  20869. });
  20870. return Array.from(map.values());
  20871. }
  20872. /**
  20873. * @param {?} ast
  20874. * @return {?}
  20875. */
  20876. function isEmptyExpression(ast) {
  20877. if (ast instanceof ASTWithSource) {
  20878. ast = ast.ast;
  20879. }
  20880. return ast instanceof EmptyExpr;
  20881. }
  20882. /**
  20883. * @param {?} el
  20884. * @param {?} enableLegacyTemplate
  20885. * @param {?} reportDeprecation
  20886. * @return {?}
  20887. */
  20888. function isTemplate(el, enableLegacyTemplate, reportDeprecation) {
  20889. if (isNgTemplate(el.name))
  20890. return true;
  20891. const /** @type {?} */ tagNoNs = splitNsName(el.name)[1];
  20892. // `<template>` is HTML and case insensitive
  20893. if (tagNoNs.toLowerCase() === TEMPLATE_ELEMENT) {
  20894. if (enableLegacyTemplate && tagNoNs.toLowerCase() === TEMPLATE_ELEMENT) {
  20895. reportDeprecation(TEMPLATE_ELEMENT_DEPRECATION_WARNING, /** @type {?} */ ((el.sourceSpan)));
  20896. return true;
  20897. }
  20898. }
  20899. return false;
  20900. }
  20901. /**
  20902. * @fileoverview added by tsickle
  20903. * @suppress {checkTypes} checked by tsc
  20904. */
  20905. /**
  20906. * @license
  20907. * Copyright Google Inc. All Rights Reserved.
  20908. *
  20909. * Use of this source code is governed by an MIT-style license that can be
  20910. * found in the LICENSE file at https://angular.io/license
  20911. */
  20912. class EventHandlerVars {
  20913. }
  20914. EventHandlerVars.event = variable('$event');
  20915. /**
  20916. * @record
  20917. */
  20918. class ConvertActionBindingResult {
  20919. /**
  20920. * @param {?} stmts
  20921. * @param {?} allowDefault
  20922. */
  20923. constructor(stmts, allowDefault) {
  20924. this.stmts = stmts;
  20925. this.allowDefault = allowDefault;
  20926. }
  20927. }
  20928. /**
  20929. * Converts the given expression AST into an executable output AST, assuming the expression is
  20930. * used in an action binding (e.g. an event handler).
  20931. * @param {?} localResolver
  20932. * @param {?} implicitReceiver
  20933. * @param {?} action
  20934. * @param {?} bindingId
  20935. * @return {?}
  20936. */
  20937. function convertActionBinding(localResolver, implicitReceiver, action, bindingId) {
  20938. if (!localResolver) {
  20939. localResolver = new DefaultLocalResolver();
  20940. }
  20941. const /** @type {?} */ actionWithoutBuiltins = convertPropertyBindingBuiltins({
  20942. createLiteralArrayConverter: (argCount) => {
  20943. // Note: no caching for literal arrays in actions.
  20944. return (args) => literalArr(args);
  20945. },
  20946. createLiteralMapConverter: (keys) => {
  20947. // Note: no caching for literal maps in actions.
  20948. return (values) => {
  20949. const /** @type {?} */ entries = keys.map((k, i) => ({
  20950. key: k.key,
  20951. value: values[i],
  20952. quoted: k.quoted,
  20953. }));
  20954. return literalMap(entries);
  20955. };
  20956. },
  20957. createPipeConverter: (name) => {
  20958. throw new Error(`Illegal State: Actions are not allowed to contain pipes. Pipe: ${name}`);
  20959. }
  20960. }, action);
  20961. const /** @type {?} */ visitor = new _AstToIrVisitor(localResolver, implicitReceiver, bindingId);
  20962. const /** @type {?} */ actionStmts = [];
  20963. flattenStatements(actionWithoutBuiltins.visit(visitor, _Mode.Statement), actionStmts);
  20964. prependTemporaryDecls(visitor.temporaryCount, bindingId, actionStmts);
  20965. const /** @type {?} */ lastIndex = actionStmts.length - 1;
  20966. let /** @type {?} */ preventDefaultVar = /** @type {?} */ ((null));
  20967. if (lastIndex >= 0) {
  20968. const /** @type {?} */ lastStatement = actionStmts[lastIndex];
  20969. const /** @type {?} */ returnExpr = convertStmtIntoExpression(lastStatement);
  20970. if (returnExpr) {
  20971. // Note: We need to cast the result of the method call to dynamic,
  20972. // as it might be a void method!
  20973. preventDefaultVar = createPreventDefaultVar(bindingId);
  20974. actionStmts[lastIndex] =
  20975. preventDefaultVar.set(returnExpr.cast(DYNAMIC_TYPE).notIdentical(literal(false)))
  20976. .toDeclStmt(null, [StmtModifier.Final]);
  20977. }
  20978. }
  20979. return new ConvertActionBindingResult(actionStmts, preventDefaultVar);
  20980. }
  20981. /**
  20982. * @record
  20983. */
  20984. /**
  20985. * @record
  20986. */
  20987. /**
  20988. * @param {?} converterFactory
  20989. * @param {?} ast
  20990. * @return {?}
  20991. */
  20992. function convertPropertyBindingBuiltins(converterFactory, ast) {
  20993. return convertBuiltins(converterFactory, ast);
  20994. }
  20995. class ConvertPropertyBindingResult {
  20996. /**
  20997. * @param {?} stmts
  20998. * @param {?} currValExpr
  20999. */
  21000. constructor(stmts, currValExpr) {
  21001. this.stmts = stmts;
  21002. this.currValExpr = currValExpr;
  21003. }
  21004. }
  21005. /** @enum {number} */
  21006. const BindingForm = {
  21007. // The general form of binding expression, supports all expressions.
  21008. General: 0,
  21009. // Try to generate a simple binding (no temporaries or statements)
  21010. // otherise generate a general binding
  21011. TrySimple: 1,
  21012. };
  21013. BindingForm[BindingForm.General] = "General";
  21014. BindingForm[BindingForm.TrySimple] = "TrySimple";
  21015. /**
  21016. * Converts the given expression AST into an executable output AST, assuming the expression
  21017. * is used in property binding. The expression has to be preprocessed via
  21018. * `convertPropertyBindingBuiltins`.
  21019. * @param {?} localResolver
  21020. * @param {?} implicitReceiver
  21021. * @param {?} expressionWithoutBuiltins
  21022. * @param {?} bindingId
  21023. * @param {?} form
  21024. * @return {?}
  21025. */
  21026. function convertPropertyBinding(localResolver, implicitReceiver, expressionWithoutBuiltins, bindingId, form) {
  21027. if (!localResolver) {
  21028. localResolver = new DefaultLocalResolver();
  21029. }
  21030. const /** @type {?} */ currValExpr = createCurrValueExpr(bindingId);
  21031. const /** @type {?} */ stmts = [];
  21032. const /** @type {?} */ visitor = new _AstToIrVisitor(localResolver, implicitReceiver, bindingId);
  21033. const /** @type {?} */ outputExpr = expressionWithoutBuiltins.visit(visitor, _Mode.Expression);
  21034. if (visitor.temporaryCount) {
  21035. for (let /** @type {?} */ i = 0; i < visitor.temporaryCount; i++) {
  21036. stmts.push(temporaryDeclaration(bindingId, i));
  21037. }
  21038. }
  21039. else if (form == BindingForm.TrySimple) {
  21040. return new ConvertPropertyBindingResult([], outputExpr);
  21041. }
  21042. stmts.push(currValExpr.set(outputExpr).toDeclStmt(DYNAMIC_TYPE, [StmtModifier.Final]));
  21043. return new ConvertPropertyBindingResult(stmts, currValExpr);
  21044. }
  21045. /**
  21046. * @param {?} converterFactory
  21047. * @param {?} ast
  21048. * @return {?}
  21049. */
  21050. function convertBuiltins(converterFactory, ast) {
  21051. const /** @type {?} */ visitor = new _BuiltinAstConverter(converterFactory);
  21052. return ast.visit(visitor);
  21053. }
  21054. /**
  21055. * @param {?} bindingId
  21056. * @param {?} temporaryNumber
  21057. * @return {?}
  21058. */
  21059. function temporaryName(bindingId, temporaryNumber) {
  21060. return `tmp_${bindingId}_${temporaryNumber}`;
  21061. }
  21062. /**
  21063. * @param {?} bindingId
  21064. * @param {?} temporaryNumber
  21065. * @return {?}
  21066. */
  21067. function temporaryDeclaration(bindingId, temporaryNumber) {
  21068. return new DeclareVarStmt(temporaryName(bindingId, temporaryNumber), NULL_EXPR);
  21069. }
  21070. /**
  21071. * @param {?} temporaryCount
  21072. * @param {?} bindingId
  21073. * @param {?} statements
  21074. * @return {?}
  21075. */
  21076. function prependTemporaryDecls(temporaryCount, bindingId, statements) {
  21077. for (let /** @type {?} */ i = temporaryCount - 1; i >= 0; i--) {
  21078. statements.unshift(temporaryDeclaration(bindingId, i));
  21079. }
  21080. }
  21081. /** @enum {number} */
  21082. const _Mode = {
  21083. Statement: 0,
  21084. Expression: 1,
  21085. };
  21086. _Mode[_Mode.Statement] = "Statement";
  21087. _Mode[_Mode.Expression] = "Expression";
  21088. /**
  21089. * @param {?} mode
  21090. * @param {?} ast
  21091. * @return {?}
  21092. */
  21093. function ensureStatementMode(mode, ast) {
  21094. if (mode !== _Mode.Statement) {
  21095. throw new Error(`Expected a statement, but saw ${ast}`);
  21096. }
  21097. }
  21098. /**
  21099. * @param {?} mode
  21100. * @param {?} ast
  21101. * @return {?}
  21102. */
  21103. function ensureExpressionMode(mode, ast) {
  21104. if (mode !== _Mode.Expression) {
  21105. throw new Error(`Expected an expression, but saw ${ast}`);
  21106. }
  21107. }
  21108. /**
  21109. * @param {?} mode
  21110. * @param {?} expr
  21111. * @return {?}
  21112. */
  21113. function convertToStatementIfNeeded(mode, expr) {
  21114. if (mode === _Mode.Statement) {
  21115. return expr.toStmt();
  21116. }
  21117. else {
  21118. return expr;
  21119. }
  21120. }
  21121. class _BuiltinAstConverter extends AstTransformer {
  21122. /**
  21123. * @param {?} _converterFactory
  21124. */
  21125. constructor(_converterFactory) {
  21126. super();
  21127. this._converterFactory = _converterFactory;
  21128. }
  21129. /**
  21130. * @param {?} ast
  21131. * @param {?} context
  21132. * @return {?}
  21133. */
  21134. visitPipe(ast, context) {
  21135. const /** @type {?} */ args = [ast.exp, ...ast.args].map(ast => ast.visit(this, context));
  21136. return new BuiltinFunctionCall(ast.span, args, this._converterFactory.createPipeConverter(ast.name, args.length));
  21137. }
  21138. /**
  21139. * @param {?} ast
  21140. * @param {?} context
  21141. * @return {?}
  21142. */
  21143. visitLiteralArray(ast, context) {
  21144. const /** @type {?} */ args = ast.expressions.map(ast => ast.visit(this, context));
  21145. return new BuiltinFunctionCall(ast.span, args, this._converterFactory.createLiteralArrayConverter(ast.expressions.length));
  21146. }
  21147. /**
  21148. * @param {?} ast
  21149. * @param {?} context
  21150. * @return {?}
  21151. */
  21152. visitLiteralMap(ast, context) {
  21153. const /** @type {?} */ args = ast.values.map(ast => ast.visit(this, context));
  21154. return new BuiltinFunctionCall(ast.span, args, this._converterFactory.createLiteralMapConverter(ast.keys));
  21155. }
  21156. }
  21157. class _AstToIrVisitor {
  21158. /**
  21159. * @param {?} _localResolver
  21160. * @param {?} _implicitReceiver
  21161. * @param {?} bindingId
  21162. */
  21163. constructor(_localResolver, _implicitReceiver, bindingId) {
  21164. this._localResolver = _localResolver;
  21165. this._implicitReceiver = _implicitReceiver;
  21166. this.bindingId = bindingId;
  21167. this._nodeMap = new Map();
  21168. this._resultMap = new Map();
  21169. this._currentTemporary = 0;
  21170. this.temporaryCount = 0;
  21171. }
  21172. /**
  21173. * @param {?} ast
  21174. * @param {?} mode
  21175. * @return {?}
  21176. */
  21177. visitBinary(ast, mode) {
  21178. let /** @type {?} */ op;
  21179. switch (ast.operation) {
  21180. case '+':
  21181. op = BinaryOperator.Plus;
  21182. break;
  21183. case '-':
  21184. op = BinaryOperator.Minus;
  21185. break;
  21186. case '*':
  21187. op = BinaryOperator.Multiply;
  21188. break;
  21189. case '/':
  21190. op = BinaryOperator.Divide;
  21191. break;
  21192. case '%':
  21193. op = BinaryOperator.Modulo;
  21194. break;
  21195. case '&&':
  21196. op = BinaryOperator.And;
  21197. break;
  21198. case '||':
  21199. op = BinaryOperator.Or;
  21200. break;
  21201. case '==':
  21202. op = BinaryOperator.Equals;
  21203. break;
  21204. case '!=':
  21205. op = BinaryOperator.NotEquals;
  21206. break;
  21207. case '===':
  21208. op = BinaryOperator.Identical;
  21209. break;
  21210. case '!==':
  21211. op = BinaryOperator.NotIdentical;
  21212. break;
  21213. case '<':
  21214. op = BinaryOperator.Lower;
  21215. break;
  21216. case '>':
  21217. op = BinaryOperator.Bigger;
  21218. break;
  21219. case '<=':
  21220. op = BinaryOperator.LowerEquals;
  21221. break;
  21222. case '>=':
  21223. op = BinaryOperator.BiggerEquals;
  21224. break;
  21225. default:
  21226. throw new Error(`Unsupported operation ${ast.operation}`);
  21227. }
  21228. return convertToStatementIfNeeded(mode, new BinaryOperatorExpr(op, this._visit(ast.left, _Mode.Expression), this._visit(ast.right, _Mode.Expression)));
  21229. }
  21230. /**
  21231. * @param {?} ast
  21232. * @param {?} mode
  21233. * @return {?}
  21234. */
  21235. visitChain(ast, mode) {
  21236. ensureStatementMode(mode, ast);
  21237. return this.visitAll(ast.expressions, mode);
  21238. }
  21239. /**
  21240. * @param {?} ast
  21241. * @param {?} mode
  21242. * @return {?}
  21243. */
  21244. visitConditional(ast, mode) {
  21245. const /** @type {?} */ value = this._visit(ast.condition, _Mode.Expression);
  21246. return convertToStatementIfNeeded(mode, value.conditional(this._visit(ast.trueExp, _Mode.Expression), this._visit(ast.falseExp, _Mode.Expression)));
  21247. }
  21248. /**
  21249. * @param {?} ast
  21250. * @param {?} mode
  21251. * @return {?}
  21252. */
  21253. visitPipe(ast, mode) {
  21254. throw new Error(`Illegal state: Pipes should have been converted into functions. Pipe: ${ast.name}`);
  21255. }
  21256. /**
  21257. * @param {?} ast
  21258. * @param {?} mode
  21259. * @return {?}
  21260. */
  21261. visitFunctionCall(ast, mode) {
  21262. const /** @type {?} */ convertedArgs = this.visitAll(ast.args, _Mode.Expression);
  21263. let /** @type {?} */ fnResult;
  21264. if (ast instanceof BuiltinFunctionCall) {
  21265. fnResult = ast.converter(convertedArgs);
  21266. }
  21267. else {
  21268. fnResult = this._visit(/** @type {?} */ ((ast.target)), _Mode.Expression).callFn(convertedArgs);
  21269. }
  21270. return convertToStatementIfNeeded(mode, fnResult);
  21271. }
  21272. /**
  21273. * @param {?} ast
  21274. * @param {?} mode
  21275. * @return {?}
  21276. */
  21277. visitImplicitReceiver(ast, mode) {
  21278. ensureExpressionMode(mode, ast);
  21279. return this._implicitReceiver;
  21280. }
  21281. /**
  21282. * @param {?} ast
  21283. * @param {?} mode
  21284. * @return {?}
  21285. */
  21286. visitInterpolation(ast, mode) {
  21287. ensureExpressionMode(mode, ast);
  21288. const /** @type {?} */ args = [literal(ast.expressions.length)];
  21289. for (let /** @type {?} */ i = 0; i < ast.strings.length - 1; i++) {
  21290. args.push(literal(ast.strings[i]));
  21291. args.push(this._visit(ast.expressions[i], _Mode.Expression));
  21292. }
  21293. args.push(literal(ast.strings[ast.strings.length - 1]));
  21294. return ast.expressions.length <= 9 ?
  21295. importExpr(Identifiers.inlineInterpolate).callFn(args) :
  21296. importExpr(Identifiers.interpolate).callFn([args[0], literalArr(args.slice(1))]);
  21297. }
  21298. /**
  21299. * @param {?} ast
  21300. * @param {?} mode
  21301. * @return {?}
  21302. */
  21303. visitKeyedRead(ast, mode) {
  21304. const /** @type {?} */ leftMostSafe = this.leftMostSafeNode(ast);
  21305. if (leftMostSafe) {
  21306. return this.convertSafeAccess(ast, leftMostSafe, mode);
  21307. }
  21308. else {
  21309. return convertToStatementIfNeeded(mode, this._visit(ast.obj, _Mode.Expression).key(this._visit(ast.key, _Mode.Expression)));
  21310. }
  21311. }
  21312. /**
  21313. * @param {?} ast
  21314. * @param {?} mode
  21315. * @return {?}
  21316. */
  21317. visitKeyedWrite(ast, mode) {
  21318. const /** @type {?} */ obj = this._visit(ast.obj, _Mode.Expression);
  21319. const /** @type {?} */ key = this._visit(ast.key, _Mode.Expression);
  21320. const /** @type {?} */ value = this._visit(ast.value, _Mode.Expression);
  21321. return convertToStatementIfNeeded(mode, obj.key(key).set(value));
  21322. }
  21323. /**
  21324. * @param {?} ast
  21325. * @param {?} mode
  21326. * @return {?}
  21327. */
  21328. visitLiteralArray(ast, mode) {
  21329. throw new Error(`Illegal State: literal arrays should have been converted into functions`);
  21330. }
  21331. /**
  21332. * @param {?} ast
  21333. * @param {?} mode
  21334. * @return {?}
  21335. */
  21336. visitLiteralMap(ast, mode) {
  21337. throw new Error(`Illegal State: literal maps should have been converted into functions`);
  21338. }
  21339. /**
  21340. * @param {?} ast
  21341. * @param {?} mode
  21342. * @return {?}
  21343. */
  21344. visitLiteralPrimitive(ast, mode) {
  21345. // For literal values of null, undefined, true, or false allow type inteference
  21346. // to infer the type.
  21347. const /** @type {?} */ type = ast.value === null || ast.value === undefined || ast.value === true || ast.value === true ?
  21348. INFERRED_TYPE :
  21349. undefined;
  21350. return convertToStatementIfNeeded(mode, literal(ast.value, type));
  21351. }
  21352. /**
  21353. * @param {?} name
  21354. * @return {?}
  21355. */
  21356. _getLocal(name) { return this._localResolver.getLocal(name); }
  21357. /**
  21358. * @param {?} ast
  21359. * @param {?} mode
  21360. * @return {?}
  21361. */
  21362. visitMethodCall(ast, mode) {
  21363. if (ast.receiver instanceof ImplicitReceiver && ast.name == '$any') {
  21364. const /** @type {?} */ args = /** @type {?} */ (this.visitAll(ast.args, _Mode.Expression));
  21365. if (args.length != 1) {
  21366. throw new Error(`Invalid call to $any, expected 1 argument but received ${args.length || 'none'}`);
  21367. }
  21368. return (/** @type {?} */ (args[0])).cast(DYNAMIC_TYPE);
  21369. }
  21370. const /** @type {?} */ leftMostSafe = this.leftMostSafeNode(ast);
  21371. if (leftMostSafe) {
  21372. return this.convertSafeAccess(ast, leftMostSafe, mode);
  21373. }
  21374. else {
  21375. const /** @type {?} */ args = this.visitAll(ast.args, _Mode.Expression);
  21376. let /** @type {?} */ result = null;
  21377. const /** @type {?} */ receiver = this._visit(ast.receiver, _Mode.Expression);
  21378. if (receiver === this._implicitReceiver) {
  21379. const /** @type {?} */ varExpr = this._getLocal(ast.name);
  21380. if (varExpr) {
  21381. result = varExpr.callFn(args);
  21382. }
  21383. }
  21384. if (result == null) {
  21385. result = receiver.callMethod(ast.name, args);
  21386. }
  21387. return convertToStatementIfNeeded(mode, result);
  21388. }
  21389. }
  21390. /**
  21391. * @param {?} ast
  21392. * @param {?} mode
  21393. * @return {?}
  21394. */
  21395. visitPrefixNot(ast, mode) {
  21396. return convertToStatementIfNeeded(mode, not(this._visit(ast.expression, _Mode.Expression)));
  21397. }
  21398. /**
  21399. * @param {?} ast
  21400. * @param {?} mode
  21401. * @return {?}
  21402. */
  21403. visitNonNullAssert(ast, mode) {
  21404. return convertToStatementIfNeeded(mode, assertNotNull(this._visit(ast.expression, _Mode.Expression)));
  21405. }
  21406. /**
  21407. * @param {?} ast
  21408. * @param {?} mode
  21409. * @return {?}
  21410. */
  21411. visitPropertyRead(ast, mode) {
  21412. const /** @type {?} */ leftMostSafe = this.leftMostSafeNode(ast);
  21413. if (leftMostSafe) {
  21414. return this.convertSafeAccess(ast, leftMostSafe, mode);
  21415. }
  21416. else {
  21417. let /** @type {?} */ result = null;
  21418. const /** @type {?} */ receiver = this._visit(ast.receiver, _Mode.Expression);
  21419. if (receiver === this._implicitReceiver) {
  21420. result = this._getLocal(ast.name);
  21421. }
  21422. if (result == null) {
  21423. result = receiver.prop(ast.name);
  21424. }
  21425. return convertToStatementIfNeeded(mode, result);
  21426. }
  21427. }
  21428. /**
  21429. * @param {?} ast
  21430. * @param {?} mode
  21431. * @return {?}
  21432. */
  21433. visitPropertyWrite(ast, mode) {
  21434. const /** @type {?} */ receiver = this._visit(ast.receiver, _Mode.Expression);
  21435. if (receiver === this._implicitReceiver) {
  21436. const /** @type {?} */ varExpr = this._getLocal(ast.name);
  21437. if (varExpr) {
  21438. throw new Error('Cannot assign to a reference or variable!');
  21439. }
  21440. }
  21441. return convertToStatementIfNeeded(mode, receiver.prop(ast.name).set(this._visit(ast.value, _Mode.Expression)));
  21442. }
  21443. /**
  21444. * @param {?} ast
  21445. * @param {?} mode
  21446. * @return {?}
  21447. */
  21448. visitSafePropertyRead(ast, mode) {
  21449. return this.convertSafeAccess(ast, this.leftMostSafeNode(ast), mode);
  21450. }
  21451. /**
  21452. * @param {?} ast
  21453. * @param {?} mode
  21454. * @return {?}
  21455. */
  21456. visitSafeMethodCall(ast, mode) {
  21457. return this.convertSafeAccess(ast, this.leftMostSafeNode(ast), mode);
  21458. }
  21459. /**
  21460. * @param {?} asts
  21461. * @param {?} mode
  21462. * @return {?}
  21463. */
  21464. visitAll(asts, mode) { return asts.map(ast => this._visit(ast, mode)); }
  21465. /**
  21466. * @param {?} ast
  21467. * @param {?} mode
  21468. * @return {?}
  21469. */
  21470. visitQuote(ast, mode) {
  21471. throw new Error(`Quotes are not supported for evaluation!
  21472. Statement: ${ast.uninterpretedExpression} located at ${ast.location}`);
  21473. }
  21474. /**
  21475. * @param {?} ast
  21476. * @param {?} mode
  21477. * @return {?}
  21478. */
  21479. _visit(ast, mode) {
  21480. const /** @type {?} */ result = this._resultMap.get(ast);
  21481. if (result)
  21482. return result;
  21483. return (this._nodeMap.get(ast) || ast).visit(this, mode);
  21484. }
  21485. /**
  21486. * @param {?} ast
  21487. * @param {?} leftMostSafe
  21488. * @param {?} mode
  21489. * @return {?}
  21490. */
  21491. convertSafeAccess(ast, leftMostSafe, mode) {
  21492. // If the expression contains a safe access node on the left it needs to be converted to
  21493. // an expression that guards the access to the member by checking the receiver for blank. As
  21494. // execution proceeds from left to right, the left most part of the expression must be guarded
  21495. // first but, because member access is left associative, the right side of the expression is at
  21496. // the top of the AST. The desired result requires lifting a copy of the the left part of the
  21497. // expression up to test it for blank before generating the unguarded version.
  21498. // Consider, for example the following expression: a?.b.c?.d.e
  21499. // This results in the ast:
  21500. // .
  21501. // / \
  21502. // ?. e
  21503. // / \
  21504. // . d
  21505. // / \
  21506. // ?. c
  21507. // / \
  21508. // a b
  21509. // The following tree should be generated:
  21510. //
  21511. // /---- ? ----\
  21512. // / | \
  21513. // a /--- ? ---\ null
  21514. // / | \
  21515. // . . null
  21516. // / \ / \
  21517. // . c . e
  21518. // / \ / \
  21519. // a b , d
  21520. // / \
  21521. // . c
  21522. // / \
  21523. // a b
  21524. //
  21525. // Notice that the first guard condition is the left hand of the left most safe access node
  21526. // which comes in as leftMostSafe to this routine.
  21527. let /** @type {?} */ guardedExpression = this._visit(leftMostSafe.receiver, _Mode.Expression);
  21528. let /** @type {?} */ temporary = /** @type {?} */ ((undefined));
  21529. if (this.needsTemporary(leftMostSafe.receiver)) {
  21530. // If the expression has method calls or pipes then we need to save the result into a
  21531. // temporary variable to avoid calling stateful or impure code more than once.
  21532. temporary = this.allocateTemporary();
  21533. // Preserve the result in the temporary variable
  21534. guardedExpression = temporary.set(guardedExpression);
  21535. // Ensure all further references to the guarded expression refer to the temporary instead.
  21536. this._resultMap.set(leftMostSafe.receiver, temporary);
  21537. }
  21538. const /** @type {?} */ condition = guardedExpression.isBlank();
  21539. // Convert the ast to an unguarded access to the receiver's member. The map will substitute
  21540. // leftMostNode with its unguarded version in the call to `this.visit()`.
  21541. if (leftMostSafe instanceof SafeMethodCall) {
  21542. this._nodeMap.set(leftMostSafe, new MethodCall(leftMostSafe.span, leftMostSafe.receiver, leftMostSafe.name, leftMostSafe.args));
  21543. }
  21544. else {
  21545. this._nodeMap.set(leftMostSafe, new PropertyRead(leftMostSafe.span, leftMostSafe.receiver, leftMostSafe.name));
  21546. }
  21547. // Recursively convert the node now without the guarded member access.
  21548. const /** @type {?} */ access = this._visit(ast, _Mode.Expression);
  21549. // Remove the mapping. This is not strictly required as the converter only traverses each node
  21550. // once but is safer if the conversion is changed to traverse the nodes more than once.
  21551. this._nodeMap.delete(leftMostSafe);
  21552. // If we allocated a temporary, release it.
  21553. if (temporary) {
  21554. this.releaseTemporary(temporary);
  21555. }
  21556. // Produce the conditional
  21557. return convertToStatementIfNeeded(mode, condition.conditional(literal(null), access));
  21558. }
  21559. /**
  21560. * @param {?} ast
  21561. * @return {?}
  21562. */
  21563. leftMostSafeNode(ast) {
  21564. const /** @type {?} */ visit = (visitor, ast) => {
  21565. return (this._nodeMap.get(ast) || ast).visit(visitor);
  21566. };
  21567. return ast.visit({
  21568. /**
  21569. * @param {?} ast
  21570. * @return {?}
  21571. */
  21572. visitBinary(ast) { return null; },
  21573. /**
  21574. * @param {?} ast
  21575. * @return {?}
  21576. */
  21577. visitChain(ast) { return null; },
  21578. /**
  21579. * @param {?} ast
  21580. * @return {?}
  21581. */
  21582. visitConditional(ast) { return null; },
  21583. /**
  21584. * @param {?} ast
  21585. * @return {?}
  21586. */
  21587. visitFunctionCall(ast) { return null; },
  21588. /**
  21589. * @param {?} ast
  21590. * @return {?}
  21591. */
  21592. visitImplicitReceiver(ast) { return null; },
  21593. /**
  21594. * @param {?} ast
  21595. * @return {?}
  21596. */
  21597. visitInterpolation(ast) { return null; },
  21598. /**
  21599. * @param {?} ast
  21600. * @return {?}
  21601. */
  21602. visitKeyedRead(ast) { return visit(this, ast.obj); },
  21603. /**
  21604. * @param {?} ast
  21605. * @return {?}
  21606. */
  21607. visitKeyedWrite(ast) { return null; },
  21608. /**
  21609. * @param {?} ast
  21610. * @return {?}
  21611. */
  21612. visitLiteralArray(ast) { return null; },
  21613. /**
  21614. * @param {?} ast
  21615. * @return {?}
  21616. */
  21617. visitLiteralMap(ast) { return null; },
  21618. /**
  21619. * @param {?} ast
  21620. * @return {?}
  21621. */
  21622. visitLiteralPrimitive(ast) { return null; },
  21623. /**
  21624. * @param {?} ast
  21625. * @return {?}
  21626. */
  21627. visitMethodCall(ast) { return visit(this, ast.receiver); },
  21628. /**
  21629. * @param {?} ast
  21630. * @return {?}
  21631. */
  21632. visitPipe(ast) { return null; },
  21633. /**
  21634. * @param {?} ast
  21635. * @return {?}
  21636. */
  21637. visitPrefixNot(ast) { return null; },
  21638. /**
  21639. * @param {?} ast
  21640. * @return {?}
  21641. */
  21642. visitNonNullAssert(ast) { return null; },
  21643. /**
  21644. * @param {?} ast
  21645. * @return {?}
  21646. */
  21647. visitPropertyRead(ast) { return visit(this, ast.receiver); },
  21648. /**
  21649. * @param {?} ast
  21650. * @return {?}
  21651. */
  21652. visitPropertyWrite(ast) { return null; },
  21653. /**
  21654. * @param {?} ast
  21655. * @return {?}
  21656. */
  21657. visitQuote(ast) { return null; },
  21658. /**
  21659. * @param {?} ast
  21660. * @return {?}
  21661. */
  21662. visitSafeMethodCall(ast) { return visit(this, ast.receiver) || ast; },
  21663. /**
  21664. * @param {?} ast
  21665. * @return {?}
  21666. */
  21667. visitSafePropertyRead(ast) {
  21668. return visit(this, ast.receiver) || ast;
  21669. }
  21670. });
  21671. }
  21672. /**
  21673. * @param {?} ast
  21674. * @return {?}
  21675. */
  21676. needsTemporary(ast) {
  21677. const /** @type {?} */ visit = (visitor, ast) => {
  21678. return ast && (this._nodeMap.get(ast) || ast).visit(visitor);
  21679. };
  21680. const /** @type {?} */ visitSome = (visitor, ast) => {
  21681. return ast.some(ast => visit(visitor, ast));
  21682. };
  21683. return ast.visit({
  21684. /**
  21685. * @param {?} ast
  21686. * @return {?}
  21687. */
  21688. visitBinary(ast) { return visit(this, ast.left) || visit(this, ast.right); },
  21689. /**
  21690. * @param {?} ast
  21691. * @return {?}
  21692. */
  21693. visitChain(ast) { return false; },
  21694. /**
  21695. * @param {?} ast
  21696. * @return {?}
  21697. */
  21698. visitConditional(ast) {
  21699. return visit(this, ast.condition) || visit(this, ast.trueExp) ||
  21700. visit(this, ast.falseExp);
  21701. },
  21702. /**
  21703. * @param {?} ast
  21704. * @return {?}
  21705. */
  21706. visitFunctionCall(ast) { return true; },
  21707. /**
  21708. * @param {?} ast
  21709. * @return {?}
  21710. */
  21711. visitImplicitReceiver(ast) { return false; },
  21712. /**
  21713. * @param {?} ast
  21714. * @return {?}
  21715. */
  21716. visitInterpolation(ast) { return visitSome(this, ast.expressions); },
  21717. /**
  21718. * @param {?} ast
  21719. * @return {?}
  21720. */
  21721. visitKeyedRead(ast) { return false; },
  21722. /**
  21723. * @param {?} ast
  21724. * @return {?}
  21725. */
  21726. visitKeyedWrite(ast) { return false; },
  21727. /**
  21728. * @param {?} ast
  21729. * @return {?}
  21730. */
  21731. visitLiteralArray(ast) { return true; },
  21732. /**
  21733. * @param {?} ast
  21734. * @return {?}
  21735. */
  21736. visitLiteralMap(ast) { return true; },
  21737. /**
  21738. * @param {?} ast
  21739. * @return {?}
  21740. */
  21741. visitLiteralPrimitive(ast) { return false; },
  21742. /**
  21743. * @param {?} ast
  21744. * @return {?}
  21745. */
  21746. visitMethodCall(ast) { return true; },
  21747. /**
  21748. * @param {?} ast
  21749. * @return {?}
  21750. */
  21751. visitPipe(ast) { return true; },
  21752. /**
  21753. * @param {?} ast
  21754. * @return {?}
  21755. */
  21756. visitPrefixNot(ast) { return visit(this, ast.expression); },
  21757. /**
  21758. * @param {?} ast
  21759. * @return {?}
  21760. */
  21761. visitNonNullAssert(ast) { return visit(this, ast.expression); },
  21762. /**
  21763. * @param {?} ast
  21764. * @return {?}
  21765. */
  21766. visitPropertyRead(ast) { return false; },
  21767. /**
  21768. * @param {?} ast
  21769. * @return {?}
  21770. */
  21771. visitPropertyWrite(ast) { return false; },
  21772. /**
  21773. * @param {?} ast
  21774. * @return {?}
  21775. */
  21776. visitQuote(ast) { return false; },
  21777. /**
  21778. * @param {?} ast
  21779. * @return {?}
  21780. */
  21781. visitSafeMethodCall(ast) { return true; },
  21782. /**
  21783. * @param {?} ast
  21784. * @return {?}
  21785. */
  21786. visitSafePropertyRead(ast) { return false; }
  21787. });
  21788. }
  21789. /**
  21790. * @return {?}
  21791. */
  21792. allocateTemporary() {
  21793. const /** @type {?} */ tempNumber = this._currentTemporary++;
  21794. this.temporaryCount = Math.max(this._currentTemporary, this.temporaryCount);
  21795. return new ReadVarExpr(temporaryName(this.bindingId, tempNumber));
  21796. }
  21797. /**
  21798. * @param {?} temporary
  21799. * @return {?}
  21800. */
  21801. releaseTemporary(temporary) {
  21802. this._currentTemporary--;
  21803. if (temporary.name != temporaryName(this.bindingId, this._currentTemporary)) {
  21804. throw new Error(`Temporary ${temporary.name} released out of order`);
  21805. }
  21806. }
  21807. }
  21808. /**
  21809. * @param {?} arg
  21810. * @param {?} output
  21811. * @return {?}
  21812. */
  21813. function flattenStatements(arg, output) {
  21814. if (Array.isArray(arg)) {
  21815. (/** @type {?} */ (arg)).forEach((entry) => flattenStatements(entry, output));
  21816. }
  21817. else {
  21818. output.push(arg);
  21819. }
  21820. }
  21821. class DefaultLocalResolver {
  21822. /**
  21823. * @param {?} name
  21824. * @return {?}
  21825. */
  21826. getLocal(name) {
  21827. if (name === EventHandlerVars.event.name) {
  21828. return EventHandlerVars.event;
  21829. }
  21830. return null;
  21831. }
  21832. }
  21833. /**
  21834. * @param {?} bindingId
  21835. * @return {?}
  21836. */
  21837. function createCurrValueExpr(bindingId) {
  21838. return variable(`currVal_${bindingId}`); // fix syntax highlighting: `
  21839. }
  21840. /**
  21841. * @param {?} bindingId
  21842. * @return {?}
  21843. */
  21844. function createPreventDefaultVar(bindingId) {
  21845. return variable(`pd_${bindingId}`);
  21846. }
  21847. /**
  21848. * @param {?} stmt
  21849. * @return {?}
  21850. */
  21851. function convertStmtIntoExpression(stmt) {
  21852. if (stmt instanceof ExpressionStatement) {
  21853. return stmt.expr;
  21854. }
  21855. else if (stmt instanceof ReturnStatement) {
  21856. return stmt.value;
  21857. }
  21858. return null;
  21859. }
  21860. class BuiltinFunctionCall extends FunctionCall {
  21861. /**
  21862. * @param {?} span
  21863. * @param {?} args
  21864. * @param {?} converter
  21865. */
  21866. constructor(span, args, converter) {
  21867. super(span, null, args);
  21868. this.args = args;
  21869. this.converter = converter;
  21870. }
  21871. }
  21872. /**
  21873. * @fileoverview added by tsickle
  21874. * @suppress {checkTypes} checked by tsc
  21875. */
  21876. /**
  21877. * @license
  21878. * Copyright Google Inc. All Rights Reserved.
  21879. *
  21880. * Use of this source code is governed by an MIT-style license that can be
  21881. * found in the LICENSE file at https://angular.io/license
  21882. */
  21883. /**
  21884. * Generates code that is used to type check templates.
  21885. */
  21886. class TypeCheckCompiler {
  21887. /**
  21888. * @param {?} options
  21889. * @param {?} reflector
  21890. */
  21891. constructor(options, reflector) {
  21892. this.options = options;
  21893. this.reflector = reflector;
  21894. }
  21895. /**
  21896. * Important notes:
  21897. * - This must not produce new `import` statements, but only refer to types outside
  21898. * of the file via the variables provided via externalReferenceVars.
  21899. * This allows Typescript to reuse the old program's structure as no imports have changed.
  21900. * - This must not produce any exports, as this would pollute the .d.ts file
  21901. * and also violate the point above.
  21902. * @param {?} componentId
  21903. * @param {?} component
  21904. * @param {?} template
  21905. * @param {?} usedPipes
  21906. * @param {?} externalReferenceVars
  21907. * @param {?} ctx
  21908. * @return {?}
  21909. */
  21910. compileComponent(componentId, component, template, usedPipes, externalReferenceVars, ctx) {
  21911. const /** @type {?} */ pipes = new Map();
  21912. usedPipes.forEach(p => pipes.set(p.name, p.type.reference));
  21913. let /** @type {?} */ embeddedViewCount = 0;
  21914. const /** @type {?} */ viewBuilderFactory = (parent, guards) => {
  21915. const /** @type {?} */ embeddedViewIndex = embeddedViewCount++;
  21916. return new ViewBuilder(this.options, this.reflector, externalReferenceVars, parent, component.type.reference, component.isHost, embeddedViewIndex, pipes, guards, ctx, viewBuilderFactory);
  21917. };
  21918. const /** @type {?} */ visitor = viewBuilderFactory(null, []);
  21919. visitor.visitAll([], template);
  21920. return visitor.build(componentId);
  21921. }
  21922. }
  21923. const DYNAMIC_VAR_NAME = '_any';
  21924. class TypeCheckLocalResolver {
  21925. /**
  21926. * @param {?} name
  21927. * @return {?}
  21928. */
  21929. getLocal(name) {
  21930. if (name === EventHandlerVars.event.name) {
  21931. // References to the event should not be type-checked.
  21932. // TODO(chuckj): determine a better type for the event.
  21933. return variable(DYNAMIC_VAR_NAME);
  21934. }
  21935. return null;
  21936. }
  21937. }
  21938. const defaultResolver = new TypeCheckLocalResolver();
  21939. class ViewBuilder {
  21940. /**
  21941. * @param {?} options
  21942. * @param {?} reflector
  21943. * @param {?} externalReferenceVars
  21944. * @param {?} parent
  21945. * @param {?} component
  21946. * @param {?} isHostComponent
  21947. * @param {?} embeddedViewIndex
  21948. * @param {?} pipes
  21949. * @param {?} guards
  21950. * @param {?} ctx
  21951. * @param {?} viewBuilderFactory
  21952. */
  21953. constructor(options, reflector, externalReferenceVars, parent, component, isHostComponent, embeddedViewIndex, pipes, guards, ctx, viewBuilderFactory) {
  21954. this.options = options;
  21955. this.reflector = reflector;
  21956. this.externalReferenceVars = externalReferenceVars;
  21957. this.parent = parent;
  21958. this.component = component;
  21959. this.isHostComponent = isHostComponent;
  21960. this.embeddedViewIndex = embeddedViewIndex;
  21961. this.pipes = pipes;
  21962. this.guards = guards;
  21963. this.ctx = ctx;
  21964. this.viewBuilderFactory = viewBuilderFactory;
  21965. this.refOutputVars = new Map();
  21966. this.variables = [];
  21967. this.children = [];
  21968. this.updates = [];
  21969. this.actions = [];
  21970. }
  21971. /**
  21972. * @param {?} type
  21973. * @return {?}
  21974. */
  21975. getOutputVar(type) {
  21976. let /** @type {?} */ varName;
  21977. if (type === this.component && this.isHostComponent) {
  21978. varName = DYNAMIC_VAR_NAME;
  21979. }
  21980. else if (type instanceof StaticSymbol) {
  21981. varName = this.externalReferenceVars.get(type);
  21982. }
  21983. else {
  21984. varName = DYNAMIC_VAR_NAME;
  21985. }
  21986. if (!varName) {
  21987. throw new Error(`Illegal State: referring to a type without a variable ${JSON.stringify(type)}`);
  21988. }
  21989. return varName;
  21990. }
  21991. /**
  21992. * @param {?} ast
  21993. * @return {?}
  21994. */
  21995. getTypeGuardExpressions(ast) {
  21996. const /** @type {?} */ result = [...this.guards];
  21997. for (let /** @type {?} */ directive of ast.directives) {
  21998. for (let /** @type {?} */ input of directive.inputs) {
  21999. const /** @type {?} */ guard = directive.directive.guards[input.directiveName];
  22000. if (guard) {
  22001. const /** @type {?} */ useIf = guard === 'UseIf';
  22002. result.push({
  22003. guard,
  22004. useIf,
  22005. expression: /** @type {?} */ ({ context: this.component, value: input.value })
  22006. });
  22007. }
  22008. }
  22009. }
  22010. return result;
  22011. }
  22012. /**
  22013. * @param {?} variables
  22014. * @param {?} astNodes
  22015. * @return {?}
  22016. */
  22017. visitAll(variables, astNodes) {
  22018. this.variables = variables;
  22019. templateVisitAll(this, astNodes);
  22020. }
  22021. /**
  22022. * @param {?} componentId
  22023. * @param {?=} targetStatements
  22024. * @return {?}
  22025. */
  22026. build(componentId, targetStatements = []) {
  22027. this.children.forEach((child) => child.build(componentId, targetStatements));
  22028. let /** @type {?} */ viewStmts = [variable(DYNAMIC_VAR_NAME).set(NULL_EXPR).toDeclStmt(DYNAMIC_TYPE)];
  22029. let /** @type {?} */ bindingCount = 0;
  22030. this.updates.forEach((expression) => {
  22031. const { sourceSpan, context, value } = this.preprocessUpdateExpression(expression);
  22032. const /** @type {?} */ bindingId = `${bindingCount++}`;
  22033. const /** @type {?} */ nameResolver = context === this.component ? this : defaultResolver;
  22034. const { stmts, currValExpr } = convertPropertyBinding(nameResolver, variable(this.getOutputVar(context)), value, bindingId, BindingForm.General);
  22035. stmts.push(new ExpressionStatement(currValExpr));
  22036. viewStmts.push(...stmts.map((stmt) => applySourceSpanToStatementIfNeeded(stmt, sourceSpan)));
  22037. });
  22038. this.actions.forEach(({ sourceSpan, context, value }) => {
  22039. const /** @type {?} */ bindingId = `${bindingCount++}`;
  22040. const /** @type {?} */ nameResolver = context === this.component ? this : defaultResolver;
  22041. const { stmts } = convertActionBinding(nameResolver, variable(this.getOutputVar(context)), value, bindingId);
  22042. viewStmts.push(...stmts.map((stmt) => applySourceSpanToStatementIfNeeded(stmt, sourceSpan)));
  22043. });
  22044. if (this.guards.length) {
  22045. let /** @type {?} */ guardExpression = undefined;
  22046. for (const /** @type {?} */ guard of this.guards) {
  22047. const { context, value } = this.preprocessUpdateExpression(guard.expression);
  22048. const /** @type {?} */ bindingId = `${bindingCount++}`;
  22049. const /** @type {?} */ nameResolver = context === this.component ? this : defaultResolver;
  22050. // We only support support simple expressions and ignore others as they
  22051. // are unlikely to affect type narrowing.
  22052. const { stmts, currValExpr } = convertPropertyBinding(nameResolver, variable(this.getOutputVar(context)), value, bindingId, BindingForm.TrySimple);
  22053. if (stmts.length == 0) {
  22054. const /** @type {?} */ guardClause = guard.useIf ? currValExpr : this.ctx.importExpr(guard.guard).callFn([currValExpr]);
  22055. guardExpression = guardExpression ? guardExpression.and(guardClause) : guardClause;
  22056. }
  22057. }
  22058. if (guardExpression) {
  22059. viewStmts = [new IfStmt(guardExpression, viewStmts)];
  22060. }
  22061. }
  22062. const /** @type {?} */ viewName = `_View_${componentId}_${this.embeddedViewIndex}`;
  22063. const /** @type {?} */ viewFactory = new DeclareFunctionStmt(viewName, [], viewStmts);
  22064. targetStatements.push(viewFactory);
  22065. return targetStatements;
  22066. }
  22067. /**
  22068. * @param {?} ast
  22069. * @param {?} context
  22070. * @return {?}
  22071. */
  22072. visitBoundText(ast, context) {
  22073. const /** @type {?} */ astWithSource = /** @type {?} */ (ast.value);
  22074. const /** @type {?} */ inter = /** @type {?} */ (astWithSource.ast);
  22075. inter.expressions.forEach((expr) => this.updates.push({ context: this.component, value: expr, sourceSpan: ast.sourceSpan }));
  22076. }
  22077. /**
  22078. * @param {?} ast
  22079. * @param {?} context
  22080. * @return {?}
  22081. */
  22082. visitEmbeddedTemplate(ast, context) {
  22083. this.visitElementOrTemplate(ast);
  22084. // Note: The old view compiler used to use an `any` type
  22085. // for the context in any embedded view.
  22086. // We keep this behaivor behind a flag for now.
  22087. if (this.options.fullTemplateTypeCheck) {
  22088. // Find any applicable type guards. For example, NgIf has a type guard on ngIf
  22089. // (see NgIf.ngIfTypeGuard) that can be used to indicate that a template is only
  22090. // stamped out if ngIf is truthy so any bindings in the template can assume that,
  22091. // if a nullable type is used for ngIf, that expression is not null or undefined.
  22092. const /** @type {?} */ guards = this.getTypeGuardExpressions(ast);
  22093. const /** @type {?} */ childVisitor = this.viewBuilderFactory(this, guards);
  22094. this.children.push(childVisitor);
  22095. childVisitor.visitAll(ast.variables, ast.children);
  22096. }
  22097. }
  22098. /**
  22099. * @param {?} ast
  22100. * @param {?} context
  22101. * @return {?}
  22102. */
  22103. visitElement(ast, context) {
  22104. this.visitElementOrTemplate(ast);
  22105. let /** @type {?} */ inputDefs = [];
  22106. let /** @type {?} */ updateRendererExpressions = [];
  22107. let /** @type {?} */ outputDefs = [];
  22108. ast.inputs.forEach((inputAst) => {
  22109. this.updates.push({ context: this.component, value: inputAst.value, sourceSpan: inputAst.sourceSpan });
  22110. });
  22111. templateVisitAll(this, ast.children);
  22112. }
  22113. /**
  22114. * @param {?} ast
  22115. * @return {?}
  22116. */
  22117. visitElementOrTemplate(ast) {
  22118. ast.directives.forEach((dirAst) => { this.visitDirective(dirAst); });
  22119. ast.references.forEach((ref) => {
  22120. let /** @type {?} */ outputVarType = /** @type {?} */ ((null));
  22121. // Note: The old view compiler used to use an `any` type
  22122. // for directives exposed via `exportAs`.
  22123. // We keep this behaivor behind a flag for now.
  22124. if (ref.value && ref.value.identifier && this.options.fullTemplateTypeCheck) {
  22125. outputVarType = ref.value.identifier.reference;
  22126. }
  22127. else {
  22128. outputVarType = BuiltinTypeName.Dynamic;
  22129. }
  22130. this.refOutputVars.set(ref.name, outputVarType);
  22131. });
  22132. ast.outputs.forEach((outputAst) => {
  22133. this.actions.push({ context: this.component, value: outputAst.handler, sourceSpan: outputAst.sourceSpan });
  22134. });
  22135. }
  22136. /**
  22137. * @param {?} dirAst
  22138. * @return {?}
  22139. */
  22140. visitDirective(dirAst) {
  22141. const /** @type {?} */ dirType = dirAst.directive.type.reference;
  22142. dirAst.inputs.forEach((input) => this.updates.push({ context: this.component, value: input.value, sourceSpan: input.sourceSpan }));
  22143. // Note: The old view compiler used to use an `any` type
  22144. // for expressions in host properties / events.
  22145. // We keep this behaivor behind a flag for now.
  22146. if (this.options.fullTemplateTypeCheck) {
  22147. dirAst.hostProperties.forEach((inputAst) => this.updates.push({ context: dirType, value: inputAst.value, sourceSpan: inputAst.sourceSpan }));
  22148. dirAst.hostEvents.forEach((hostEventAst) => this.actions.push({
  22149. context: dirType,
  22150. value: hostEventAst.handler,
  22151. sourceSpan: hostEventAst.sourceSpan
  22152. }));
  22153. }
  22154. }
  22155. /**
  22156. * @param {?} name
  22157. * @return {?}
  22158. */
  22159. getLocal(name) {
  22160. if (name == EventHandlerVars.event.name) {
  22161. return variable(this.getOutputVar(BuiltinTypeName.Dynamic));
  22162. }
  22163. for (let /** @type {?} */ currBuilder = this; currBuilder; currBuilder = currBuilder.parent) {
  22164. let /** @type {?} */ outputVarType;
  22165. // check references
  22166. outputVarType = currBuilder.refOutputVars.get(name);
  22167. if (outputVarType == null) {
  22168. // check variables
  22169. const /** @type {?} */ varAst = currBuilder.variables.find((varAst) => varAst.name === name);
  22170. if (varAst) {
  22171. outputVarType = BuiltinTypeName.Dynamic;
  22172. }
  22173. }
  22174. if (outputVarType != null) {
  22175. return variable(this.getOutputVar(outputVarType));
  22176. }
  22177. }
  22178. return null;
  22179. }
  22180. /**
  22181. * @param {?} name
  22182. * @return {?}
  22183. */
  22184. pipeOutputVar(name) {
  22185. const /** @type {?} */ pipe = this.pipes.get(name);
  22186. if (!pipe) {
  22187. throw new Error(`Illegal State: Could not find pipe ${name} in template of ${this.component}`);
  22188. }
  22189. return this.getOutputVar(pipe);
  22190. }
  22191. /**
  22192. * @param {?} expression
  22193. * @return {?}
  22194. */
  22195. preprocessUpdateExpression(expression) {
  22196. return {
  22197. sourceSpan: expression.sourceSpan,
  22198. context: expression.context,
  22199. value: convertPropertyBindingBuiltins({
  22200. createLiteralArrayConverter: (argCount) => (args) => {
  22201. const /** @type {?} */ arr = literalArr(args);
  22202. // Note: The old view compiler used to use an `any` type
  22203. // for arrays.
  22204. return this.options.fullTemplateTypeCheck ? arr : arr.cast(DYNAMIC_TYPE);
  22205. },
  22206. createLiteralMapConverter: (keys) => (values) => {
  22207. const /** @type {?} */ entries = keys.map((k, i) => ({
  22208. key: k.key,
  22209. value: values[i],
  22210. quoted: k.quoted,
  22211. }));
  22212. const /** @type {?} */ map = literalMap(entries);
  22213. // Note: The old view compiler used to use an `any` type
  22214. // for maps.
  22215. return this.options.fullTemplateTypeCheck ? map : map.cast(DYNAMIC_TYPE);
  22216. },
  22217. createPipeConverter: (name, argCount) => (args) => {
  22218. // Note: The old view compiler used to use an `any` type
  22219. // for pipes.
  22220. const /** @type {?} */ pipeExpr = this.options.fullTemplateTypeCheck ?
  22221. variable(this.pipeOutputVar(name)) :
  22222. variable(this.getOutputVar(BuiltinTypeName.Dynamic));
  22223. return pipeExpr.callMethod('transform', args);
  22224. },
  22225. }, expression.value)
  22226. };
  22227. }
  22228. /**
  22229. * @param {?} ast
  22230. * @param {?} context
  22231. * @return {?}
  22232. */
  22233. visitNgContent(ast, context) { }
  22234. /**
  22235. * @param {?} ast
  22236. * @param {?} context
  22237. * @return {?}
  22238. */
  22239. visitText(ast, context) { }
  22240. /**
  22241. * @param {?} ast
  22242. * @param {?} context
  22243. * @return {?}
  22244. */
  22245. visitDirectiveProperty(ast, context) { }
  22246. /**
  22247. * @param {?} ast
  22248. * @param {?} context
  22249. * @return {?}
  22250. */
  22251. visitReference(ast, context) { }
  22252. /**
  22253. * @param {?} ast
  22254. * @param {?} context
  22255. * @return {?}
  22256. */
  22257. visitVariable(ast, context) { }
  22258. /**
  22259. * @param {?} ast
  22260. * @param {?} context
  22261. * @return {?}
  22262. */
  22263. visitEvent(ast, context) { }
  22264. /**
  22265. * @param {?} ast
  22266. * @param {?} context
  22267. * @return {?}
  22268. */
  22269. visitElementProperty(ast, context) { }
  22270. /**
  22271. * @param {?} ast
  22272. * @param {?} context
  22273. * @return {?}
  22274. */
  22275. visitAttr(ast, context) { }
  22276. }
  22277. /**
  22278. * @fileoverview added by tsickle
  22279. * @suppress {checkTypes} checked by tsc
  22280. */
  22281. /**
  22282. * @license
  22283. * Copyright Google Inc. All Rights Reserved.
  22284. *
  22285. * Use of this source code is governed by an MIT-style license that can be
  22286. * found in the LICENSE file at https://angular.io/license
  22287. */
  22288. const CLASS_ATTR$1 = 'class';
  22289. const STYLE_ATTR = 'style';
  22290. const IMPLICIT_TEMPLATE_VAR = '\$implicit';
  22291. class ViewCompileResult {
  22292. /**
  22293. * @param {?} viewClassVar
  22294. * @param {?} rendererTypeVar
  22295. */
  22296. constructor(viewClassVar, rendererTypeVar) {
  22297. this.viewClassVar = viewClassVar;
  22298. this.rendererTypeVar = rendererTypeVar;
  22299. }
  22300. }
  22301. class ViewCompiler {
  22302. /**
  22303. * @param {?} _reflector
  22304. */
  22305. constructor(_reflector) {
  22306. this._reflector = _reflector;
  22307. }
  22308. /**
  22309. * @param {?} outputCtx
  22310. * @param {?} component
  22311. * @param {?} template
  22312. * @param {?} styles
  22313. * @param {?} usedPipes
  22314. * @return {?}
  22315. */
  22316. compileComponent(outputCtx, component, template, styles, usedPipes) {
  22317. let /** @type {?} */ embeddedViewCount = 0;
  22318. const /** @type {?} */ staticQueryIds = findStaticQueryIds(template);
  22319. let /** @type {?} */ renderComponentVarName = /** @type {?} */ ((undefined));
  22320. if (!component.isHost) {
  22321. const /** @type {?} */ template = /** @type {?} */ ((component.template));
  22322. const /** @type {?} */ customRenderData = [];
  22323. if (template.animations && template.animations.length) {
  22324. customRenderData.push(new LiteralMapEntry('animation', convertValueToOutputAst(outputCtx, template.animations), true));
  22325. }
  22326. const /** @type {?} */ renderComponentVar = variable(rendererTypeName(component.type.reference));
  22327. renderComponentVarName = /** @type {?} */ ((renderComponentVar.name));
  22328. outputCtx.statements.push(renderComponentVar
  22329. .set(importExpr(Identifiers.createRendererType2).callFn([new LiteralMapExpr([
  22330. new LiteralMapEntry('encapsulation', literal(template.encapsulation), false),
  22331. new LiteralMapEntry('styles', styles, false),
  22332. new LiteralMapEntry('data', new LiteralMapExpr(customRenderData), false)
  22333. ])]))
  22334. .toDeclStmt(importType(Identifiers.RendererType2), [StmtModifier.Final, StmtModifier.Exported]));
  22335. }
  22336. const /** @type {?} */ viewBuilderFactory = (parent) => {
  22337. const /** @type {?} */ embeddedViewIndex = embeddedViewCount++;
  22338. return new ViewBuilder$1(this._reflector, outputCtx, parent, component, embeddedViewIndex, usedPipes, staticQueryIds, viewBuilderFactory);
  22339. };
  22340. const /** @type {?} */ visitor = viewBuilderFactory(null);
  22341. visitor.visitAll([], template);
  22342. outputCtx.statements.push(...visitor.build());
  22343. return new ViewCompileResult(visitor.viewName, renderComponentVarName);
  22344. }
  22345. }
  22346. const LOG_VAR$1 = variable('_l');
  22347. const VIEW_VAR = variable('_v');
  22348. const CHECK_VAR = variable('_ck');
  22349. const COMP_VAR = variable('_co');
  22350. const EVENT_NAME_VAR = variable('en');
  22351. const ALLOW_DEFAULT_VAR = variable(`ad`);
  22352. class ViewBuilder$1 {
  22353. /**
  22354. * @param {?} reflector
  22355. * @param {?} outputCtx
  22356. * @param {?} parent
  22357. * @param {?} component
  22358. * @param {?} embeddedViewIndex
  22359. * @param {?} usedPipes
  22360. * @param {?} staticQueryIds
  22361. * @param {?} viewBuilderFactory
  22362. */
  22363. constructor(reflector, outputCtx, parent, component, embeddedViewIndex, usedPipes, staticQueryIds, viewBuilderFactory) {
  22364. this.reflector = reflector;
  22365. this.outputCtx = outputCtx;
  22366. this.parent = parent;
  22367. this.component = component;
  22368. this.embeddedViewIndex = embeddedViewIndex;
  22369. this.usedPipes = usedPipes;
  22370. this.staticQueryIds = staticQueryIds;
  22371. this.viewBuilderFactory = viewBuilderFactory;
  22372. this.nodes = [];
  22373. this.purePipeNodeIndices = Object.create(null);
  22374. this.refNodeIndices = Object.create(null);
  22375. this.variables = [];
  22376. this.children = [];
  22377. // TODO(tbosch): The old view compiler used to use an `any` type
  22378. // for the context in any embedded view. We keep this behaivor for now
  22379. // to be able to introduce the new view compiler without too many errors.
  22380. this.compType = this.embeddedViewIndex > 0 ?
  22381. DYNAMIC_TYPE : /** @type {?} */
  22382. ((expressionType(outputCtx.importExpr(this.component.type.reference))));
  22383. this.viewName = viewClassName(this.component.type.reference, this.embeddedViewIndex);
  22384. }
  22385. /**
  22386. * @param {?} variables
  22387. * @param {?} astNodes
  22388. * @return {?}
  22389. */
  22390. visitAll(variables, astNodes) {
  22391. this.variables = variables;
  22392. // create the pipes for the pure pipes immediately, so that we know their indices.
  22393. if (!this.parent) {
  22394. this.usedPipes.forEach((pipe) => {
  22395. if (pipe.pure) {
  22396. this.purePipeNodeIndices[pipe.name] = this._createPipe(null, pipe);
  22397. }
  22398. });
  22399. }
  22400. if (!this.parent) {
  22401. const /** @type {?} */ queryIds = staticViewQueryIds(this.staticQueryIds);
  22402. this.component.viewQueries.forEach((query, queryIndex) => {
  22403. // Note: queries start with id 1 so we can use the number in a Bloom filter!
  22404. const /** @type {?} */ queryId = queryIndex + 1;
  22405. const /** @type {?} */ bindingType = query.first ? 0 /* First */ : 1;
  22406. const /** @type {?} */ flags = 134217728 /* TypeViewQuery */ | calcStaticDynamicQueryFlags(queryIds, queryId, query.first);
  22407. this.nodes.push(() => ({
  22408. sourceSpan: null,
  22409. nodeFlags: flags,
  22410. nodeDef: importExpr(Identifiers.queryDef).callFn([
  22411. literal(flags), literal(queryId),
  22412. new LiteralMapExpr([new LiteralMapEntry(query.propertyName, literal(bindingType), false)])
  22413. ])
  22414. }));
  22415. });
  22416. }
  22417. templateVisitAll(this, astNodes);
  22418. if (this.parent && (astNodes.length === 0 || needsAdditionalRootNode(astNodes))) {
  22419. // if the view is an embedded view, then we need to add an additional root node in some cases
  22420. this.nodes.push(() => ({
  22421. sourceSpan: null,
  22422. nodeFlags: 1 /* TypeElement */,
  22423. nodeDef: importExpr(Identifiers.anchorDef).callFn([
  22424. literal(0 /* None */), NULL_EXPR, NULL_EXPR, literal(0)
  22425. ])
  22426. }));
  22427. }
  22428. }
  22429. /**
  22430. * @param {?=} targetStatements
  22431. * @return {?}
  22432. */
  22433. build(targetStatements = []) {
  22434. this.children.forEach((child) => child.build(targetStatements));
  22435. const { updateRendererStmts, updateDirectivesStmts, nodeDefExprs } = this._createNodeExpressions();
  22436. const /** @type {?} */ updateRendererFn = this._createUpdateFn(updateRendererStmts);
  22437. const /** @type {?} */ updateDirectivesFn = this._createUpdateFn(updateDirectivesStmts);
  22438. let /** @type {?} */ viewFlags = 0;
  22439. if (!this.parent && this.component.changeDetection === ChangeDetectionStrategy.OnPush) {
  22440. viewFlags |= 2 /* OnPush */;
  22441. }
  22442. const /** @type {?} */ viewFactory = new DeclareFunctionStmt(this.viewName, [new FnParam(/** @type {?} */ ((LOG_VAR$1.name)))], [new ReturnStatement(importExpr(Identifiers.viewDef).callFn([
  22443. literal(viewFlags),
  22444. literalArr(nodeDefExprs),
  22445. updateDirectivesFn,
  22446. updateRendererFn,
  22447. ]))], importType(Identifiers.ViewDefinition), this.embeddedViewIndex === 0 ? [StmtModifier.Exported] : []);
  22448. targetStatements.push(viewFactory);
  22449. return targetStatements;
  22450. }
  22451. /**
  22452. * @param {?} updateStmts
  22453. * @return {?}
  22454. */
  22455. _createUpdateFn(updateStmts) {
  22456. let /** @type {?} */ updateFn;
  22457. if (updateStmts.length > 0) {
  22458. const /** @type {?} */ preStmts = [];
  22459. if (!this.component.isHost && findReadVarNames(updateStmts).has(/** @type {?} */ ((COMP_VAR.name)))) {
  22460. preStmts.push(COMP_VAR.set(VIEW_VAR.prop('component')).toDeclStmt(this.compType));
  22461. }
  22462. updateFn = fn([
  22463. new FnParam(/** @type {?} */ ((CHECK_VAR.name)), INFERRED_TYPE),
  22464. new FnParam(/** @type {?} */ ((VIEW_VAR.name)), INFERRED_TYPE)
  22465. ], [...preStmts, ...updateStmts], INFERRED_TYPE);
  22466. }
  22467. else {
  22468. updateFn = NULL_EXPR;
  22469. }
  22470. return updateFn;
  22471. }
  22472. /**
  22473. * @param {?} ast
  22474. * @param {?} context
  22475. * @return {?}
  22476. */
  22477. visitNgContent(ast, context) {
  22478. // ngContentDef(ngContentIndex: number, index: number): NodeDef;
  22479. this.nodes.push(() => ({
  22480. sourceSpan: ast.sourceSpan,
  22481. nodeFlags: 8 /* TypeNgContent */,
  22482. nodeDef: importExpr(Identifiers.ngContentDef).callFn([
  22483. literal(ast.ngContentIndex), literal(ast.index)
  22484. ])
  22485. }));
  22486. }
  22487. /**
  22488. * @param {?} ast
  22489. * @param {?} context
  22490. * @return {?}
  22491. */
  22492. visitText(ast, context) {
  22493. // Static text nodes have no check function
  22494. const /** @type {?} */ checkIndex = -1;
  22495. this.nodes.push(() => ({
  22496. sourceSpan: ast.sourceSpan,
  22497. nodeFlags: 2 /* TypeText */,
  22498. nodeDef: importExpr(Identifiers.textDef).callFn([
  22499. literal(checkIndex),
  22500. literal(ast.ngContentIndex),
  22501. literalArr([literal(ast.value)]),
  22502. ])
  22503. }));
  22504. }
  22505. /**
  22506. * @param {?} ast
  22507. * @param {?} context
  22508. * @return {?}
  22509. */
  22510. visitBoundText(ast, context) {
  22511. const /** @type {?} */ nodeIndex = this.nodes.length;
  22512. // reserve the space in the nodeDefs array
  22513. this.nodes.push(/** @type {?} */ ((null)));
  22514. const /** @type {?} */ astWithSource = /** @type {?} */ (ast.value);
  22515. const /** @type {?} */ inter = /** @type {?} */ (astWithSource.ast);
  22516. const /** @type {?} */ updateRendererExpressions = inter.expressions.map((expr, bindingIndex) => this._preprocessUpdateExpression({ nodeIndex, bindingIndex, sourceSpan: ast.sourceSpan, context: COMP_VAR, value: expr }));
  22517. // Check index is the same as the node index during compilation
  22518. // They might only differ at runtime
  22519. const /** @type {?} */ checkIndex = nodeIndex;
  22520. this.nodes[nodeIndex] = () => ({
  22521. sourceSpan: ast.sourceSpan,
  22522. nodeFlags: 2 /* TypeText */,
  22523. nodeDef: importExpr(Identifiers.textDef).callFn([
  22524. literal(checkIndex),
  22525. literal(ast.ngContentIndex),
  22526. literalArr(inter.strings.map(s => literal(s))),
  22527. ]),
  22528. updateRenderer: updateRendererExpressions
  22529. });
  22530. }
  22531. /**
  22532. * @param {?} ast
  22533. * @param {?} context
  22534. * @return {?}
  22535. */
  22536. visitEmbeddedTemplate(ast, context) {
  22537. const /** @type {?} */ nodeIndex = this.nodes.length;
  22538. // reserve the space in the nodeDefs array
  22539. this.nodes.push(/** @type {?} */ ((null)));
  22540. const { flags, queryMatchesExpr, hostEvents } = this._visitElementOrTemplate(nodeIndex, ast);
  22541. const /** @type {?} */ childVisitor = this.viewBuilderFactory(this);
  22542. this.children.push(childVisitor);
  22543. childVisitor.visitAll(ast.variables, ast.children);
  22544. const /** @type {?} */ childCount = this.nodes.length - nodeIndex - 1;
  22545. // anchorDef(
  22546. // flags: NodeFlags, matchedQueries: [string, QueryValueType][], ngContentIndex: number,
  22547. // childCount: number, handleEventFn?: ElementHandleEventFn, templateFactory?:
  22548. // ViewDefinitionFactory): NodeDef;
  22549. this.nodes[nodeIndex] = () => ({
  22550. sourceSpan: ast.sourceSpan,
  22551. nodeFlags: 1 /* TypeElement */ | flags,
  22552. nodeDef: importExpr(Identifiers.anchorDef).callFn([
  22553. literal(flags),
  22554. queryMatchesExpr,
  22555. literal(ast.ngContentIndex),
  22556. literal(childCount),
  22557. this._createElementHandleEventFn(nodeIndex, hostEvents),
  22558. variable(childVisitor.viewName),
  22559. ])
  22560. });
  22561. }
  22562. /**
  22563. * @param {?} ast
  22564. * @param {?} context
  22565. * @return {?}
  22566. */
  22567. visitElement(ast, context) {
  22568. const /** @type {?} */ nodeIndex = this.nodes.length;
  22569. // reserve the space in the nodeDefs array so we can add children
  22570. this.nodes.push(/** @type {?} */ ((null)));
  22571. // Using a null element name creates an anchor.
  22572. const /** @type {?} */ elName = isNgContainer(ast.name) ? null : ast.name;
  22573. const { flags, usedEvents, queryMatchesExpr, hostBindings: dirHostBindings, hostEvents } = this._visitElementOrTemplate(nodeIndex, ast);
  22574. let /** @type {?} */ inputDefs = [];
  22575. let /** @type {?} */ updateRendererExpressions = [];
  22576. let /** @type {?} */ outputDefs = [];
  22577. if (elName) {
  22578. const /** @type {?} */ hostBindings = ast.inputs
  22579. .map((inputAst) => ({
  22580. context: /** @type {?} */ (COMP_VAR),
  22581. inputAst,
  22582. dirAst: /** @type {?} */ (null),
  22583. }))
  22584. .concat(dirHostBindings);
  22585. if (hostBindings.length) {
  22586. updateRendererExpressions =
  22587. hostBindings.map((hostBinding, bindingIndex) => this._preprocessUpdateExpression({
  22588. context: hostBinding.context,
  22589. nodeIndex,
  22590. bindingIndex,
  22591. sourceSpan: hostBinding.inputAst.sourceSpan,
  22592. value: hostBinding.inputAst.value
  22593. }));
  22594. inputDefs = hostBindings.map(hostBinding => elementBindingDef(hostBinding.inputAst, hostBinding.dirAst));
  22595. }
  22596. outputDefs = usedEvents.map(([target, eventName]) => literalArr([literal(target), literal(eventName)]));
  22597. }
  22598. templateVisitAll(this, ast.children);
  22599. const /** @type {?} */ childCount = this.nodes.length - nodeIndex - 1;
  22600. const /** @type {?} */ compAst = ast.directives.find(dirAst => dirAst.directive.isComponent);
  22601. let /** @type {?} */ compRendererType = /** @type {?} */ (NULL_EXPR);
  22602. let /** @type {?} */ compView = /** @type {?} */ (NULL_EXPR);
  22603. if (compAst) {
  22604. compView = this.outputCtx.importExpr(compAst.directive.componentViewType);
  22605. compRendererType = this.outputCtx.importExpr(compAst.directive.rendererType);
  22606. }
  22607. // Check index is the same as the node index during compilation
  22608. // They might only differ at runtime
  22609. const /** @type {?} */ checkIndex = nodeIndex;
  22610. this.nodes[nodeIndex] = () => ({
  22611. sourceSpan: ast.sourceSpan,
  22612. nodeFlags: 1 /* TypeElement */ | flags,
  22613. nodeDef: importExpr(Identifiers.elementDef).callFn([
  22614. literal(checkIndex),
  22615. literal(flags),
  22616. queryMatchesExpr,
  22617. literal(ast.ngContentIndex),
  22618. literal(childCount),
  22619. literal(elName),
  22620. elName ? fixedAttrsDef(ast) : NULL_EXPR,
  22621. inputDefs.length ? literalArr(inputDefs) : NULL_EXPR,
  22622. outputDefs.length ? literalArr(outputDefs) : NULL_EXPR,
  22623. this._createElementHandleEventFn(nodeIndex, hostEvents),
  22624. compView,
  22625. compRendererType,
  22626. ]),
  22627. updateRenderer: updateRendererExpressions
  22628. });
  22629. }
  22630. /**
  22631. * @param {?} nodeIndex
  22632. * @param {?} ast
  22633. * @return {?}
  22634. */
  22635. _visitElementOrTemplate(nodeIndex, ast) {
  22636. let /** @type {?} */ flags = 0;
  22637. if (ast.hasViewContainer) {
  22638. flags |= 16777216 /* EmbeddedViews */;
  22639. }
  22640. const /** @type {?} */ usedEvents = new Map();
  22641. ast.outputs.forEach((event) => {
  22642. const { name, target } = elementEventNameAndTarget(event, null);
  22643. usedEvents.set(elementEventFullName(target, name), [target, name]);
  22644. });
  22645. ast.directives.forEach((dirAst) => {
  22646. dirAst.hostEvents.forEach((event) => {
  22647. const { name, target } = elementEventNameAndTarget(event, dirAst);
  22648. usedEvents.set(elementEventFullName(target, name), [target, name]);
  22649. });
  22650. });
  22651. const /** @type {?} */ hostBindings = [];
  22652. const /** @type {?} */ hostEvents = [];
  22653. this._visitComponentFactoryResolverProvider(ast.directives);
  22654. ast.providers.forEach((providerAst, providerIndex) => {
  22655. let /** @type {?} */ dirAst = /** @type {?} */ ((undefined));
  22656. let /** @type {?} */ dirIndex = /** @type {?} */ ((undefined));
  22657. ast.directives.forEach((localDirAst, i) => {
  22658. if (localDirAst.directive.type.reference === tokenReference(providerAst.token)) {
  22659. dirAst = localDirAst;
  22660. dirIndex = i;
  22661. }
  22662. });
  22663. if (dirAst) {
  22664. const { hostBindings: dirHostBindings, hostEvents: dirHostEvents } = this._visitDirective(providerAst, dirAst, dirIndex, nodeIndex, ast.references, ast.queryMatches, usedEvents, /** @type {?} */ ((this.staticQueryIds.get(/** @type {?} */ (ast)))));
  22665. hostBindings.push(...dirHostBindings);
  22666. hostEvents.push(...dirHostEvents);
  22667. }
  22668. else {
  22669. this._visitProvider(providerAst, ast.queryMatches);
  22670. }
  22671. });
  22672. let /** @type {?} */ queryMatchExprs = [];
  22673. ast.queryMatches.forEach((match) => {
  22674. let /** @type {?} */ valueType = /** @type {?} */ ((undefined));
  22675. if (tokenReference(match.value) ===
  22676. this.reflector.resolveExternalReference(Identifiers.ElementRef)) {
  22677. valueType = 0 /* ElementRef */;
  22678. }
  22679. else if (tokenReference(match.value) ===
  22680. this.reflector.resolveExternalReference(Identifiers.ViewContainerRef)) {
  22681. valueType = 3 /* ViewContainerRef */;
  22682. }
  22683. else if (tokenReference(match.value) ===
  22684. this.reflector.resolveExternalReference(Identifiers.TemplateRef)) {
  22685. valueType = 2 /* TemplateRef */;
  22686. }
  22687. if (valueType != null) {
  22688. queryMatchExprs.push(literalArr([literal(match.queryId), literal(valueType)]));
  22689. }
  22690. });
  22691. ast.references.forEach((ref) => {
  22692. let /** @type {?} */ valueType = /** @type {?} */ ((undefined));
  22693. if (!ref.value) {
  22694. valueType = 1 /* RenderElement */;
  22695. }
  22696. else if (tokenReference(ref.value) ===
  22697. this.reflector.resolveExternalReference(Identifiers.TemplateRef)) {
  22698. valueType = 2 /* TemplateRef */;
  22699. }
  22700. if (valueType != null) {
  22701. this.refNodeIndices[ref.name] = nodeIndex;
  22702. queryMatchExprs.push(literalArr([literal(ref.name), literal(valueType)]));
  22703. }
  22704. });
  22705. ast.outputs.forEach((outputAst) => {
  22706. hostEvents.push({ context: COMP_VAR, eventAst: outputAst, dirAst: /** @type {?} */ ((null)) });
  22707. });
  22708. return {
  22709. flags,
  22710. usedEvents: Array.from(usedEvents.values()),
  22711. queryMatchesExpr: queryMatchExprs.length ? literalArr(queryMatchExprs) : NULL_EXPR,
  22712. hostBindings,
  22713. hostEvents: hostEvents
  22714. };
  22715. }
  22716. /**
  22717. * @param {?} providerAst
  22718. * @param {?} dirAst
  22719. * @param {?} directiveIndex
  22720. * @param {?} elementNodeIndex
  22721. * @param {?} refs
  22722. * @param {?} queryMatches
  22723. * @param {?} usedEvents
  22724. * @param {?} queryIds
  22725. * @return {?}
  22726. */
  22727. _visitDirective(providerAst, dirAst, directiveIndex, elementNodeIndex, refs, queryMatches, usedEvents, queryIds) {
  22728. const /** @type {?} */ nodeIndex = this.nodes.length;
  22729. // reserve the space in the nodeDefs array so we can add children
  22730. this.nodes.push(/** @type {?} */ ((null)));
  22731. dirAst.directive.queries.forEach((query, queryIndex) => {
  22732. const /** @type {?} */ queryId = dirAst.contentQueryStartId + queryIndex;
  22733. const /** @type {?} */ flags = 67108864 /* TypeContentQuery */ | calcStaticDynamicQueryFlags(queryIds, queryId, query.first);
  22734. const /** @type {?} */ bindingType = query.first ? 0 /* First */ : 1;
  22735. this.nodes.push(() => ({
  22736. sourceSpan: dirAst.sourceSpan,
  22737. nodeFlags: flags,
  22738. nodeDef: importExpr(Identifiers.queryDef).callFn([
  22739. literal(flags), literal(queryId),
  22740. new LiteralMapExpr([new LiteralMapEntry(query.propertyName, literal(bindingType), false)])
  22741. ]),
  22742. }));
  22743. });
  22744. // Note: the operation below might also create new nodeDefs,
  22745. // but we don't want them to be a child of a directive,
  22746. // as they might be a provider/pipe on their own.
  22747. // I.e. we only allow queries as children of directives nodes.
  22748. const /** @type {?} */ childCount = this.nodes.length - nodeIndex - 1;
  22749. let { flags, queryMatchExprs, providerExpr, depsExpr } = this._visitProviderOrDirective(providerAst, queryMatches);
  22750. refs.forEach((ref) => {
  22751. if (ref.value && tokenReference(ref.value) === tokenReference(providerAst.token)) {
  22752. this.refNodeIndices[ref.name] = nodeIndex;
  22753. queryMatchExprs.push(literalArr([literal(ref.name), literal(4 /* Provider */)]));
  22754. }
  22755. });
  22756. if (dirAst.directive.isComponent) {
  22757. flags |= 32768 /* Component */;
  22758. }
  22759. const /** @type {?} */ inputDefs = dirAst.inputs.map((inputAst, inputIndex) => {
  22760. const /** @type {?} */ mapValue = literalArr([literal(inputIndex), literal(inputAst.directiveName)]);
  22761. // Note: it's important to not quote the key so that we can capture renames by minifiers!
  22762. return new LiteralMapEntry(inputAst.directiveName, mapValue, false);
  22763. });
  22764. const /** @type {?} */ outputDefs = [];
  22765. const /** @type {?} */ dirMeta = dirAst.directive;
  22766. Object.keys(dirMeta.outputs).forEach((propName) => {
  22767. const /** @type {?} */ eventName = dirMeta.outputs[propName];
  22768. if (usedEvents.has(eventName)) {
  22769. // Note: it's important to not quote the key so that we can capture renames by minifiers!
  22770. outputDefs.push(new LiteralMapEntry(propName, literal(eventName), false));
  22771. }
  22772. });
  22773. let /** @type {?} */ updateDirectiveExpressions = [];
  22774. if (dirAst.inputs.length || (flags & (262144 /* DoCheck */ | 65536 /* OnInit */)) > 0) {
  22775. updateDirectiveExpressions =
  22776. dirAst.inputs.map((input, bindingIndex) => this._preprocessUpdateExpression({
  22777. nodeIndex,
  22778. bindingIndex,
  22779. sourceSpan: input.sourceSpan,
  22780. context: COMP_VAR,
  22781. value: input.value
  22782. }));
  22783. }
  22784. const /** @type {?} */ dirContextExpr = importExpr(Identifiers.nodeValue).callFn([VIEW_VAR, literal(nodeIndex)]);
  22785. const /** @type {?} */ hostBindings = dirAst.hostProperties.map((inputAst) => ({
  22786. context: dirContextExpr,
  22787. dirAst,
  22788. inputAst,
  22789. }));
  22790. const /** @type {?} */ hostEvents = dirAst.hostEvents.map((hostEventAst) => ({
  22791. context: dirContextExpr,
  22792. eventAst: hostEventAst, dirAst,
  22793. }));
  22794. // Check index is the same as the node index during compilation
  22795. // They might only differ at runtime
  22796. const /** @type {?} */ checkIndex = nodeIndex;
  22797. this.nodes[nodeIndex] = () => ({
  22798. sourceSpan: dirAst.sourceSpan,
  22799. nodeFlags: 16384 /* TypeDirective */ | flags,
  22800. nodeDef: importExpr(Identifiers.directiveDef).callFn([
  22801. literal(checkIndex),
  22802. literal(flags),
  22803. queryMatchExprs.length ? literalArr(queryMatchExprs) : NULL_EXPR,
  22804. literal(childCount),
  22805. providerExpr,
  22806. depsExpr,
  22807. inputDefs.length ? new LiteralMapExpr(inputDefs) : NULL_EXPR,
  22808. outputDefs.length ? new LiteralMapExpr(outputDefs) : NULL_EXPR,
  22809. ]),
  22810. updateDirectives: updateDirectiveExpressions,
  22811. directive: dirAst.directive.type,
  22812. });
  22813. return { hostBindings, hostEvents };
  22814. }
  22815. /**
  22816. * @param {?} providerAst
  22817. * @param {?} queryMatches
  22818. * @return {?}
  22819. */
  22820. _visitProvider(providerAst, queryMatches) {
  22821. this._addProviderNode(this._visitProviderOrDirective(providerAst, queryMatches));
  22822. }
  22823. /**
  22824. * @param {?} directives
  22825. * @return {?}
  22826. */
  22827. _visitComponentFactoryResolverProvider(directives) {
  22828. const /** @type {?} */ componentDirMeta = directives.find(dirAst => dirAst.directive.isComponent);
  22829. if (componentDirMeta && componentDirMeta.directive.entryComponents.length) {
  22830. const { providerExpr, depsExpr, flags, tokenExpr } = componentFactoryResolverProviderDef(this.reflector, this.outputCtx, 8192 /* PrivateProvider */, componentDirMeta.directive.entryComponents);
  22831. this._addProviderNode({
  22832. providerExpr,
  22833. depsExpr,
  22834. flags,
  22835. tokenExpr,
  22836. queryMatchExprs: [],
  22837. sourceSpan: componentDirMeta.sourceSpan
  22838. });
  22839. }
  22840. }
  22841. /**
  22842. * @param {?} data
  22843. * @return {?}
  22844. */
  22845. _addProviderNode(data) {
  22846. const /** @type {?} */ nodeIndex = this.nodes.length;
  22847. // providerDef(
  22848. // flags: NodeFlags, matchedQueries: [string, QueryValueType][], token:any,
  22849. // value: any, deps: ([DepFlags, any] | any)[]): NodeDef;
  22850. this.nodes.push(() => ({
  22851. sourceSpan: data.sourceSpan,
  22852. nodeFlags: data.flags,
  22853. nodeDef: importExpr(Identifiers.providerDef).callFn([
  22854. literal(data.flags),
  22855. data.queryMatchExprs.length ? literalArr(data.queryMatchExprs) : NULL_EXPR,
  22856. data.tokenExpr, data.providerExpr, data.depsExpr
  22857. ])
  22858. }));
  22859. }
  22860. /**
  22861. * @param {?} providerAst
  22862. * @param {?} queryMatches
  22863. * @return {?}
  22864. */
  22865. _visitProviderOrDirective(providerAst, queryMatches) {
  22866. let /** @type {?} */ flags = 0;
  22867. let /** @type {?} */ queryMatchExprs = [];
  22868. queryMatches.forEach((match) => {
  22869. if (tokenReference(match.value) === tokenReference(providerAst.token)) {
  22870. queryMatchExprs.push(literalArr([literal(match.queryId), literal(4 /* Provider */)]));
  22871. }
  22872. });
  22873. const { providerExpr, depsExpr, flags: providerFlags, tokenExpr } = providerDef(this.outputCtx, providerAst);
  22874. return {
  22875. flags: flags | providerFlags,
  22876. queryMatchExprs,
  22877. providerExpr,
  22878. depsExpr,
  22879. tokenExpr,
  22880. sourceSpan: providerAst.sourceSpan
  22881. };
  22882. }
  22883. /**
  22884. * @param {?} name
  22885. * @return {?}
  22886. */
  22887. getLocal(name) {
  22888. if (name == EventHandlerVars.event.name) {
  22889. return EventHandlerVars.event;
  22890. }
  22891. let /** @type {?} */ currViewExpr = VIEW_VAR;
  22892. for (let /** @type {?} */ currBuilder = this; currBuilder; currBuilder = currBuilder.parent,
  22893. currViewExpr = currViewExpr.prop('parent').cast(DYNAMIC_TYPE)) {
  22894. // check references
  22895. const /** @type {?} */ refNodeIndex = currBuilder.refNodeIndices[name];
  22896. if (refNodeIndex != null) {
  22897. return importExpr(Identifiers.nodeValue).callFn([currViewExpr, literal(refNodeIndex)]);
  22898. }
  22899. // check variables
  22900. const /** @type {?} */ varAst = currBuilder.variables.find((varAst) => varAst.name === name);
  22901. if (varAst) {
  22902. const /** @type {?} */ varValue = varAst.value || IMPLICIT_TEMPLATE_VAR;
  22903. return currViewExpr.prop('context').prop(varValue);
  22904. }
  22905. }
  22906. return null;
  22907. }
  22908. /**
  22909. * @param {?} sourceSpan
  22910. * @param {?} argCount
  22911. * @return {?}
  22912. */
  22913. _createLiteralArrayConverter(sourceSpan, argCount) {
  22914. if (argCount === 0) {
  22915. const /** @type {?} */ valueExpr = importExpr(Identifiers.EMPTY_ARRAY);
  22916. return () => valueExpr;
  22917. }
  22918. const /** @type {?} */ checkIndex = this.nodes.length;
  22919. this.nodes.push(() => ({
  22920. sourceSpan,
  22921. nodeFlags: 32 /* TypePureArray */,
  22922. nodeDef: importExpr(Identifiers.pureArrayDef).callFn([
  22923. literal(checkIndex),
  22924. literal(argCount),
  22925. ])
  22926. }));
  22927. return (args) => callCheckStmt(checkIndex, args);
  22928. }
  22929. /**
  22930. * @param {?} sourceSpan
  22931. * @param {?} keys
  22932. * @return {?}
  22933. */
  22934. _createLiteralMapConverter(sourceSpan, keys) {
  22935. if (keys.length === 0) {
  22936. const /** @type {?} */ valueExpr = importExpr(Identifiers.EMPTY_MAP);
  22937. return () => valueExpr;
  22938. }
  22939. const /** @type {?} */ map = literalMap(keys.map((e, i) => (Object.assign({}, e, { value: literal(i) }))));
  22940. const /** @type {?} */ checkIndex = this.nodes.length;
  22941. this.nodes.push(() => ({
  22942. sourceSpan,
  22943. nodeFlags: 64 /* TypePureObject */,
  22944. nodeDef: importExpr(Identifiers.pureObjectDef).callFn([
  22945. literal(checkIndex),
  22946. map,
  22947. ])
  22948. }));
  22949. return (args) => callCheckStmt(checkIndex, args);
  22950. }
  22951. /**
  22952. * @param {?} expression
  22953. * @param {?} name
  22954. * @param {?} argCount
  22955. * @return {?}
  22956. */
  22957. _createPipeConverter(expression, name, argCount) {
  22958. const /** @type {?} */ pipe = /** @type {?} */ ((this.usedPipes.find((pipeSummary) => pipeSummary.name === name)));
  22959. if (pipe.pure) {
  22960. const /** @type {?} */ checkIndex = this.nodes.length;
  22961. this.nodes.push(() => ({
  22962. sourceSpan: expression.sourceSpan,
  22963. nodeFlags: 128 /* TypePurePipe */,
  22964. nodeDef: importExpr(Identifiers.purePipeDef).callFn([
  22965. literal(checkIndex),
  22966. literal(argCount),
  22967. ])
  22968. }));
  22969. // find underlying pipe in the component view
  22970. let /** @type {?} */ compViewExpr = VIEW_VAR;
  22971. let /** @type {?} */ compBuilder = this;
  22972. while (compBuilder.parent) {
  22973. compBuilder = compBuilder.parent;
  22974. compViewExpr = compViewExpr.prop('parent').cast(DYNAMIC_TYPE);
  22975. }
  22976. const /** @type {?} */ pipeNodeIndex = compBuilder.purePipeNodeIndices[name];
  22977. const /** @type {?} */ pipeValueExpr = importExpr(Identifiers.nodeValue).callFn([compViewExpr, literal(pipeNodeIndex)]);
  22978. return (args) => callUnwrapValue(expression.nodeIndex, expression.bindingIndex, callCheckStmt(checkIndex, [pipeValueExpr].concat(args)));
  22979. }
  22980. else {
  22981. const /** @type {?} */ nodeIndex = this._createPipe(expression.sourceSpan, pipe);
  22982. const /** @type {?} */ nodeValueExpr = importExpr(Identifiers.nodeValue).callFn([VIEW_VAR, literal(nodeIndex)]);
  22983. return (args) => callUnwrapValue(expression.nodeIndex, expression.bindingIndex, nodeValueExpr.callMethod('transform', args));
  22984. }
  22985. }
  22986. /**
  22987. * @param {?} sourceSpan
  22988. * @param {?} pipe
  22989. * @return {?}
  22990. */
  22991. _createPipe(sourceSpan, pipe) {
  22992. const /** @type {?} */ nodeIndex = this.nodes.length;
  22993. let /** @type {?} */ flags = 0;
  22994. pipe.type.lifecycleHooks.forEach((lifecycleHook) => {
  22995. // for pipes, we only support ngOnDestroy
  22996. if (lifecycleHook === LifecycleHooks.OnDestroy) {
  22997. flags |= lifecycleHookToNodeFlag(lifecycleHook);
  22998. }
  22999. });
  23000. const /** @type {?} */ depExprs = pipe.type.diDeps.map((diDep) => depDef(this.outputCtx, diDep));
  23001. // function pipeDef(
  23002. // flags: NodeFlags, ctor: any, deps: ([DepFlags, any] | any)[]): NodeDef
  23003. this.nodes.push(() => ({
  23004. sourceSpan,
  23005. nodeFlags: 16 /* TypePipe */,
  23006. nodeDef: importExpr(Identifiers.pipeDef).callFn([
  23007. literal(flags), this.outputCtx.importExpr(pipe.type.reference), literalArr(depExprs)
  23008. ])
  23009. }));
  23010. return nodeIndex;
  23011. }
  23012. /**
  23013. * For the AST in `UpdateExpression.value`:
  23014. * - create nodes for pipes, literal arrays and, literal maps,
  23015. * - update the AST to replace pipes, literal arrays and, literal maps with calls to check fn.
  23016. *
  23017. * WARNING: This might create new nodeDefs (for pipes and literal arrays and literal maps)!
  23018. * @param {?} expression
  23019. * @return {?}
  23020. */
  23021. _preprocessUpdateExpression(expression) {
  23022. return {
  23023. nodeIndex: expression.nodeIndex,
  23024. bindingIndex: expression.bindingIndex,
  23025. sourceSpan: expression.sourceSpan,
  23026. context: expression.context,
  23027. value: convertPropertyBindingBuiltins({
  23028. createLiteralArrayConverter: (argCount) => this._createLiteralArrayConverter(expression.sourceSpan, argCount),
  23029. createLiteralMapConverter: (keys) => this._createLiteralMapConverter(expression.sourceSpan, keys),
  23030. createPipeConverter: (name, argCount) => this._createPipeConverter(expression, name, argCount)
  23031. }, expression.value)
  23032. };
  23033. }
  23034. /**
  23035. * @return {?}
  23036. */
  23037. _createNodeExpressions() {
  23038. const /** @type {?} */ self = this;
  23039. let /** @type {?} */ updateBindingCount = 0;
  23040. const /** @type {?} */ updateRendererStmts = [];
  23041. const /** @type {?} */ updateDirectivesStmts = [];
  23042. const /** @type {?} */ nodeDefExprs = this.nodes.map((factory, nodeIndex) => {
  23043. const { nodeDef, nodeFlags, updateDirectives, updateRenderer, sourceSpan } = factory();
  23044. if (updateRenderer) {
  23045. updateRendererStmts.push(...createUpdateStatements(nodeIndex, sourceSpan, updateRenderer, false));
  23046. }
  23047. if (updateDirectives) {
  23048. updateDirectivesStmts.push(...createUpdateStatements(nodeIndex, sourceSpan, updateDirectives, (nodeFlags & (262144 /* DoCheck */ | 65536 /* OnInit */)) > 0));
  23049. }
  23050. // We use a comma expression to call the log function before
  23051. // the nodeDef function, but still use the result of the nodeDef function
  23052. // as the value.
  23053. // Note: We only add the logger to elements / text nodes,
  23054. // so we don't generate too much code.
  23055. const /** @type {?} */ logWithNodeDef = nodeFlags & 3 /* CatRenderNode */ ?
  23056. new CommaExpr([LOG_VAR$1.callFn([]).callFn([]), nodeDef]) :
  23057. nodeDef;
  23058. return applySourceSpanToExpressionIfNeeded(logWithNodeDef, sourceSpan);
  23059. });
  23060. return { updateRendererStmts, updateDirectivesStmts, nodeDefExprs };
  23061. /**
  23062. * @param {?} nodeIndex
  23063. * @param {?} sourceSpan
  23064. * @param {?} expressions
  23065. * @param {?} allowEmptyExprs
  23066. * @return {?}
  23067. */
  23068. function createUpdateStatements(nodeIndex, sourceSpan, expressions, allowEmptyExprs) {
  23069. const /** @type {?} */ updateStmts = [];
  23070. const /** @type {?} */ exprs = expressions.map(({ sourceSpan, context, value }) => {
  23071. const /** @type {?} */ bindingId = `${updateBindingCount++}`;
  23072. const /** @type {?} */ nameResolver = context === COMP_VAR ? self : null;
  23073. const { stmts, currValExpr } = convertPropertyBinding(nameResolver, context, value, bindingId, BindingForm.General);
  23074. updateStmts.push(...stmts.map((stmt) => applySourceSpanToStatementIfNeeded(stmt, sourceSpan)));
  23075. return applySourceSpanToExpressionIfNeeded(currValExpr, sourceSpan);
  23076. });
  23077. if (expressions.length || allowEmptyExprs) {
  23078. updateStmts.push(applySourceSpanToStatementIfNeeded(callCheckStmt(nodeIndex, exprs).toStmt(), sourceSpan));
  23079. }
  23080. return updateStmts;
  23081. }
  23082. }
  23083. /**
  23084. * @param {?} nodeIndex
  23085. * @param {?} handlers
  23086. * @return {?}
  23087. */
  23088. _createElementHandleEventFn(nodeIndex, handlers) {
  23089. const /** @type {?} */ handleEventStmts = [];
  23090. let /** @type {?} */ handleEventBindingCount = 0;
  23091. handlers.forEach(({ context, eventAst, dirAst }) => {
  23092. const /** @type {?} */ bindingId = `${handleEventBindingCount++}`;
  23093. const /** @type {?} */ nameResolver = context === COMP_VAR ? this : null;
  23094. const { stmts, allowDefault } = convertActionBinding(nameResolver, context, eventAst.handler, bindingId);
  23095. const /** @type {?} */ trueStmts = stmts;
  23096. if (allowDefault) {
  23097. trueStmts.push(ALLOW_DEFAULT_VAR.set(allowDefault.and(ALLOW_DEFAULT_VAR)).toStmt());
  23098. }
  23099. const { target: eventTarget, name: eventName } = elementEventNameAndTarget(eventAst, dirAst);
  23100. const /** @type {?} */ fullEventName = elementEventFullName(eventTarget, eventName);
  23101. handleEventStmts.push(applySourceSpanToStatementIfNeeded(new IfStmt(literal(fullEventName).identical(EVENT_NAME_VAR), trueStmts), eventAst.sourceSpan));
  23102. });
  23103. let /** @type {?} */ handleEventFn;
  23104. if (handleEventStmts.length > 0) {
  23105. const /** @type {?} */ preStmts = [ALLOW_DEFAULT_VAR.set(literal(true)).toDeclStmt(BOOL_TYPE)];
  23106. if (!this.component.isHost && findReadVarNames(handleEventStmts).has(/** @type {?} */ ((COMP_VAR.name)))) {
  23107. preStmts.push(COMP_VAR.set(VIEW_VAR.prop('component')).toDeclStmt(this.compType));
  23108. }
  23109. handleEventFn = fn([
  23110. new FnParam(/** @type {?} */ ((VIEW_VAR.name)), INFERRED_TYPE),
  23111. new FnParam(/** @type {?} */ ((EVENT_NAME_VAR.name)), INFERRED_TYPE),
  23112. new FnParam(/** @type {?} */ ((EventHandlerVars.event.name)), INFERRED_TYPE)
  23113. ], [...preStmts, ...handleEventStmts, new ReturnStatement(ALLOW_DEFAULT_VAR)], INFERRED_TYPE);
  23114. }
  23115. else {
  23116. handleEventFn = NULL_EXPR;
  23117. }
  23118. return handleEventFn;
  23119. }
  23120. /**
  23121. * @param {?} ast
  23122. * @param {?} context
  23123. * @return {?}
  23124. */
  23125. visitDirective(ast, context) { }
  23126. /**
  23127. * @param {?} ast
  23128. * @param {?} context
  23129. * @return {?}
  23130. */
  23131. visitDirectiveProperty(ast, context) { }
  23132. /**
  23133. * @param {?} ast
  23134. * @param {?} context
  23135. * @return {?}
  23136. */
  23137. visitReference(ast, context) { }
  23138. /**
  23139. * @param {?} ast
  23140. * @param {?} context
  23141. * @return {?}
  23142. */
  23143. visitVariable(ast, context) { }
  23144. /**
  23145. * @param {?} ast
  23146. * @param {?} context
  23147. * @return {?}
  23148. */
  23149. visitEvent(ast, context) { }
  23150. /**
  23151. * @param {?} ast
  23152. * @param {?} context
  23153. * @return {?}
  23154. */
  23155. visitElementProperty(ast, context) { }
  23156. /**
  23157. * @param {?} ast
  23158. * @param {?} context
  23159. * @return {?}
  23160. */
  23161. visitAttr(ast, context) { }
  23162. }
  23163. /**
  23164. * @param {?} astNodes
  23165. * @return {?}
  23166. */
  23167. function needsAdditionalRootNode(astNodes) {
  23168. const /** @type {?} */ lastAstNode = astNodes[astNodes.length - 1];
  23169. if (lastAstNode instanceof EmbeddedTemplateAst) {
  23170. return lastAstNode.hasViewContainer;
  23171. }
  23172. if (lastAstNode instanceof ElementAst) {
  23173. if (isNgContainer(lastAstNode.name) && lastAstNode.children.length) {
  23174. return needsAdditionalRootNode(lastAstNode.children);
  23175. }
  23176. return lastAstNode.hasViewContainer;
  23177. }
  23178. return lastAstNode instanceof NgContentAst;
  23179. }
  23180. /**
  23181. * @param {?} inputAst
  23182. * @param {?} dirAst
  23183. * @return {?}
  23184. */
  23185. function elementBindingDef(inputAst, dirAst) {
  23186. switch (inputAst.type) {
  23187. case PropertyBindingType.Attribute:
  23188. return literalArr([
  23189. literal(1 /* TypeElementAttribute */), literal(inputAst.name),
  23190. literal(inputAst.securityContext)
  23191. ]);
  23192. case PropertyBindingType.Property:
  23193. return literalArr([
  23194. literal(8 /* TypeProperty */), literal(inputAst.name),
  23195. literal(inputAst.securityContext)
  23196. ]);
  23197. case PropertyBindingType.Animation:
  23198. const /** @type {?} */ bindingType = 8 /* TypeProperty */ |
  23199. (dirAst && dirAst.directive.isComponent ? 32 /* SyntheticHostProperty */ :
  23200. 16 /* SyntheticProperty */);
  23201. return literalArr([
  23202. literal(bindingType), literal('@' + inputAst.name), literal(inputAst.securityContext)
  23203. ]);
  23204. case PropertyBindingType.Class:
  23205. return literalArr([literal(2 /* TypeElementClass */), literal(inputAst.name), NULL_EXPR]);
  23206. case PropertyBindingType.Style:
  23207. return literalArr([
  23208. literal(4 /* TypeElementStyle */), literal(inputAst.name), literal(inputAst.unit)
  23209. ]);
  23210. }
  23211. }
  23212. /**
  23213. * @param {?} elementAst
  23214. * @return {?}
  23215. */
  23216. function fixedAttrsDef(elementAst) {
  23217. const /** @type {?} */ mapResult = Object.create(null);
  23218. elementAst.attrs.forEach(attrAst => { mapResult[attrAst.name] = attrAst.value; });
  23219. elementAst.directives.forEach(dirAst => {
  23220. Object.keys(dirAst.directive.hostAttributes).forEach(name => {
  23221. const /** @type {?} */ value = dirAst.directive.hostAttributes[name];
  23222. const /** @type {?} */ prevValue = mapResult[name];
  23223. mapResult[name] = prevValue != null ? mergeAttributeValue(name, prevValue, value) : value;
  23224. });
  23225. });
  23226. // Note: We need to sort to get a defined output order
  23227. // for tests and for caching generated artifacts...
  23228. return literalArr(Object.keys(mapResult).sort().map((attrName) => literalArr([literal(attrName), literal(mapResult[attrName])])));
  23229. }
  23230. /**
  23231. * @param {?} attrName
  23232. * @param {?} attrValue1
  23233. * @param {?} attrValue2
  23234. * @return {?}
  23235. */
  23236. function mergeAttributeValue(attrName, attrValue1, attrValue2) {
  23237. if (attrName == CLASS_ATTR$1 || attrName == STYLE_ATTR) {
  23238. return `${attrValue1} ${attrValue2}`;
  23239. }
  23240. else {
  23241. return attrValue2;
  23242. }
  23243. }
  23244. /**
  23245. * @param {?} nodeIndex
  23246. * @param {?} exprs
  23247. * @return {?}
  23248. */
  23249. function callCheckStmt(nodeIndex, exprs) {
  23250. if (exprs.length > 10) {
  23251. return CHECK_VAR.callFn([VIEW_VAR, literal(nodeIndex), literal(1 /* Dynamic */), literalArr(exprs)]);
  23252. }
  23253. else {
  23254. return CHECK_VAR.callFn([VIEW_VAR, literal(nodeIndex), literal(0 /* Inline */), ...exprs]);
  23255. }
  23256. }
  23257. /**
  23258. * @param {?} nodeIndex
  23259. * @param {?} bindingIdx
  23260. * @param {?} expr
  23261. * @return {?}
  23262. */
  23263. function callUnwrapValue(nodeIndex, bindingIdx, expr) {
  23264. return importExpr(Identifiers.unwrapValue).callFn([
  23265. VIEW_VAR, literal(nodeIndex), literal(bindingIdx), expr
  23266. ]);
  23267. }
  23268. /**
  23269. * @param {?} nodes
  23270. * @param {?=} result
  23271. * @return {?}
  23272. */
  23273. function findStaticQueryIds(nodes, result = new Map()) {
  23274. nodes.forEach((node) => {
  23275. const /** @type {?} */ staticQueryIds = new Set();
  23276. const /** @type {?} */ dynamicQueryIds = new Set();
  23277. let /** @type {?} */ queryMatches = /** @type {?} */ ((undefined));
  23278. if (node instanceof ElementAst) {
  23279. findStaticQueryIds(node.children, result);
  23280. node.children.forEach((child) => {
  23281. const /** @type {?} */ childData = /** @type {?} */ ((result.get(child)));
  23282. childData.staticQueryIds.forEach(queryId => staticQueryIds.add(queryId));
  23283. childData.dynamicQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
  23284. });
  23285. queryMatches = node.queryMatches;
  23286. }
  23287. else if (node instanceof EmbeddedTemplateAst) {
  23288. findStaticQueryIds(node.children, result);
  23289. node.children.forEach((child) => {
  23290. const /** @type {?} */ childData = /** @type {?} */ ((result.get(child)));
  23291. childData.staticQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
  23292. childData.dynamicQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
  23293. });
  23294. queryMatches = node.queryMatches;
  23295. }
  23296. if (queryMatches) {
  23297. queryMatches.forEach((match) => staticQueryIds.add(match.queryId));
  23298. }
  23299. dynamicQueryIds.forEach(queryId => staticQueryIds.delete(queryId));
  23300. result.set(node, { staticQueryIds, dynamicQueryIds });
  23301. });
  23302. return result;
  23303. }
  23304. /**
  23305. * @param {?} nodeStaticQueryIds
  23306. * @return {?}
  23307. */
  23308. function staticViewQueryIds(nodeStaticQueryIds) {
  23309. const /** @type {?} */ staticQueryIds = new Set();
  23310. const /** @type {?} */ dynamicQueryIds = new Set();
  23311. Array.from(nodeStaticQueryIds.values()).forEach((entry) => {
  23312. entry.staticQueryIds.forEach(queryId => staticQueryIds.add(queryId));
  23313. entry.dynamicQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
  23314. });
  23315. dynamicQueryIds.forEach(queryId => staticQueryIds.delete(queryId));
  23316. return { staticQueryIds, dynamicQueryIds };
  23317. }
  23318. /**
  23319. * @param {?} eventAst
  23320. * @param {?} dirAst
  23321. * @return {?}
  23322. */
  23323. function elementEventNameAndTarget(eventAst, dirAst) {
  23324. if (eventAst.isAnimation) {
  23325. return {
  23326. name: `@${eventAst.name}.${eventAst.phase}`,
  23327. target: dirAst && dirAst.directive.isComponent ? 'component' : null
  23328. };
  23329. }
  23330. else {
  23331. return eventAst;
  23332. }
  23333. }
  23334. /**
  23335. * @param {?} queryIds
  23336. * @param {?} queryId
  23337. * @param {?} isFirst
  23338. * @return {?}
  23339. */
  23340. function calcStaticDynamicQueryFlags(queryIds, queryId, isFirst) {
  23341. let /** @type {?} */ flags = 0;
  23342. // Note: We only make queries static that query for a single item.
  23343. // This is because of backwards compatibility with the old view compiler...
  23344. if (isFirst && (queryIds.staticQueryIds.has(queryId) || !queryIds.dynamicQueryIds.has(queryId))) {
  23345. flags |= 268435456 /* StaticQuery */;
  23346. }
  23347. else {
  23348. flags |= 536870912 /* DynamicQuery */;
  23349. }
  23350. return flags;
  23351. }
  23352. /**
  23353. * @param {?} target
  23354. * @param {?} name
  23355. * @return {?}
  23356. */
  23357. function elementEventFullName(target, name) {
  23358. return target ? `${target}:${name}` : name;
  23359. }
  23360. /**
  23361. * @fileoverview added by tsickle
  23362. * @suppress {checkTypes} checked by tsc
  23363. */
  23364. /**
  23365. * @license
  23366. * Copyright Google Inc. All Rights Reserved.
  23367. *
  23368. * Use of this source code is governed by an MIT-style license that can be
  23369. * found in the LICENSE file at https://angular.io/license
  23370. */
  23371. /**
  23372. * A container for message extracted from the templates.
  23373. */
  23374. class MessageBundle {
  23375. /**
  23376. * @param {?} _htmlParser
  23377. * @param {?} _implicitTags
  23378. * @param {?} _implicitAttrs
  23379. * @param {?=} _locale
  23380. */
  23381. constructor(_htmlParser, _implicitTags, _implicitAttrs, _locale = null) {
  23382. this._htmlParser = _htmlParser;
  23383. this._implicitTags = _implicitTags;
  23384. this._implicitAttrs = _implicitAttrs;
  23385. this._locale = _locale;
  23386. this._messages = [];
  23387. }
  23388. /**
  23389. * @param {?} html
  23390. * @param {?} url
  23391. * @param {?} interpolationConfig
  23392. * @return {?}
  23393. */
  23394. updateFromTemplate(html, url, interpolationConfig) {
  23395. const /** @type {?} */ htmlParserResult = this._htmlParser.parse(html, url, true, interpolationConfig);
  23396. if (htmlParserResult.errors.length) {
  23397. return htmlParserResult.errors;
  23398. }
  23399. const /** @type {?} */ i18nParserResult = extractMessages(htmlParserResult.rootNodes, interpolationConfig, this._implicitTags, this._implicitAttrs);
  23400. if (i18nParserResult.errors.length) {
  23401. return i18nParserResult.errors;
  23402. }
  23403. this._messages.push(...i18nParserResult.messages);
  23404. return [];
  23405. }
  23406. /**
  23407. * @return {?}
  23408. */
  23409. getMessages() { return this._messages; }
  23410. /**
  23411. * @param {?} serializer
  23412. * @param {?=} filterSources
  23413. * @return {?}
  23414. */
  23415. write(serializer, filterSources) {
  23416. const /** @type {?} */ messages = {};
  23417. const /** @type {?} */ mapperVisitor = new MapPlaceholderNames();
  23418. // Deduplicate messages based on their ID
  23419. this._messages.forEach(message => {
  23420. const /** @type {?} */ id = serializer.digest(message);
  23421. if (!messages.hasOwnProperty(id)) {
  23422. messages[id] = message;
  23423. }
  23424. else {
  23425. messages[id].sources.push(...message.sources);
  23426. }
  23427. });
  23428. // Transform placeholder names using the serializer mapping
  23429. const /** @type {?} */ msgList = Object.keys(messages).map(id => {
  23430. const /** @type {?} */ mapper = serializer.createNameMapper(messages[id]);
  23431. const /** @type {?} */ src = messages[id];
  23432. const /** @type {?} */ nodes = mapper ? mapperVisitor.convert(src.nodes, mapper) : src.nodes;
  23433. let /** @type {?} */ transformedMessage = new Message(nodes, {}, {}, src.meaning, src.description, id);
  23434. transformedMessage.sources = src.sources;
  23435. if (filterSources) {
  23436. transformedMessage.sources.forEach((source) => source.filePath = filterSources(source.filePath));
  23437. }
  23438. return transformedMessage;
  23439. });
  23440. return serializer.write(msgList, this._locale);
  23441. }
  23442. }
  23443. class MapPlaceholderNames extends CloneVisitor {
  23444. /**
  23445. * @param {?} nodes
  23446. * @param {?} mapper
  23447. * @return {?}
  23448. */
  23449. convert(nodes, mapper) {
  23450. return mapper ? nodes.map(n => n.visit(this, mapper)) : nodes;
  23451. }
  23452. /**
  23453. * @param {?} ph
  23454. * @param {?} mapper
  23455. * @return {?}
  23456. */
  23457. visitTagPlaceholder(ph, mapper) {
  23458. const /** @type {?} */ startName = /** @type {?} */ ((mapper.toPublicName(ph.startName)));
  23459. const /** @type {?} */ closeName = ph.closeName ? /** @type {?} */ ((mapper.toPublicName(ph.closeName))) : ph.closeName;
  23460. const /** @type {?} */ children = ph.children.map(n => n.visit(this, mapper));
  23461. return new TagPlaceholder(ph.tag, ph.attrs, startName, closeName, children, ph.isVoid, ph.sourceSpan);
  23462. }
  23463. /**
  23464. * @param {?} ph
  23465. * @param {?} mapper
  23466. * @return {?}
  23467. */
  23468. visitPlaceholder(ph, mapper) {
  23469. return new Placeholder(ph.value, /** @type {?} */ ((mapper.toPublicName(ph.name))), ph.sourceSpan);
  23470. }
  23471. /**
  23472. * @param {?} ph
  23473. * @param {?} mapper
  23474. * @return {?}
  23475. */
  23476. visitIcuPlaceholder(ph, mapper) {
  23477. return new IcuPlaceholder(ph.value, /** @type {?} */ ((mapper.toPublicName(ph.name))), ph.sourceSpan);
  23478. }
  23479. }
  23480. /**
  23481. * @fileoverview added by tsickle
  23482. * @suppress {checkTypes} checked by tsc
  23483. */
  23484. /**
  23485. * @license
  23486. * Copyright Google Inc. All Rights Reserved.
  23487. *
  23488. * Use of this source code is governed by an MIT-style license that can be
  23489. * found in the LICENSE file at https://angular.io/license
  23490. */
  23491. class GeneratedFile {
  23492. /**
  23493. * @param {?} srcFileUrl
  23494. * @param {?} genFileUrl
  23495. * @param {?} sourceOrStmts
  23496. */
  23497. constructor(srcFileUrl, genFileUrl, sourceOrStmts) {
  23498. this.srcFileUrl = srcFileUrl;
  23499. this.genFileUrl = genFileUrl;
  23500. if (typeof sourceOrStmts === 'string') {
  23501. this.source = sourceOrStmts;
  23502. this.stmts = null;
  23503. }
  23504. else {
  23505. this.source = null;
  23506. this.stmts = sourceOrStmts;
  23507. }
  23508. }
  23509. /**
  23510. * @param {?} other
  23511. * @return {?}
  23512. */
  23513. isEquivalent(other) {
  23514. if (this.genFileUrl !== other.genFileUrl) {
  23515. return false;
  23516. }
  23517. if (this.source) {
  23518. return this.source === other.source;
  23519. }
  23520. if (other.stmts == null) {
  23521. return false;
  23522. }
  23523. // Note: the constructor guarantees that if this.source is not filled,
  23524. // then this.stmts is.
  23525. return areAllEquivalent(/** @type {?} */ ((this.stmts)), /** @type {?} */ ((other.stmts)));
  23526. }
  23527. }
  23528. /**
  23529. * @param {?} file
  23530. * @param {?=} preamble
  23531. * @return {?}
  23532. */
  23533. function toTypeScript(file, preamble = '') {
  23534. if (!file.stmts) {
  23535. throw new Error(`Illegal state: No stmts present on GeneratedFile ${file.genFileUrl}`);
  23536. }
  23537. return new TypeScriptEmitter().emitStatements(file.genFileUrl, file.stmts, preamble);
  23538. }
  23539. /**
  23540. * @fileoverview added by tsickle
  23541. * @suppress {checkTypes} checked by tsc
  23542. */
  23543. /**
  23544. * @license
  23545. * Copyright Google Inc. All Rights Reserved.
  23546. *
  23547. * Use of this source code is governed by an MIT-style license that can be
  23548. * found in the LICENSE file at https://angular.io/license
  23549. */
  23550. /**
  23551. * @record
  23552. */
  23553. /**
  23554. * @param {?} moduleMeta
  23555. * @param {?} reflector
  23556. * @return {?}
  23557. */
  23558. function listLazyRoutes(moduleMeta, reflector) {
  23559. const /** @type {?} */ allLazyRoutes = [];
  23560. for (const { provider, module } of moduleMeta.transitiveModule.providers) {
  23561. if (tokenReference(provider.token) === reflector.ROUTES) {
  23562. const /** @type {?} */ loadChildren = _collectLoadChildren(provider.useValue);
  23563. for (const /** @type {?} */ route of loadChildren) {
  23564. allLazyRoutes.push(parseLazyRoute(route, reflector, module.reference));
  23565. }
  23566. }
  23567. }
  23568. return allLazyRoutes;
  23569. }
  23570. /**
  23571. * @param {?} routes
  23572. * @param {?=} target
  23573. * @return {?}
  23574. */
  23575. function _collectLoadChildren(routes, target = []) {
  23576. if (typeof routes === 'string') {
  23577. target.push(routes);
  23578. }
  23579. else if (Array.isArray(routes)) {
  23580. for (const /** @type {?} */ route of routes) {
  23581. _collectLoadChildren(route, target);
  23582. }
  23583. }
  23584. else if (routes.loadChildren) {
  23585. _collectLoadChildren(routes.loadChildren, target);
  23586. }
  23587. else if (routes.children) {
  23588. _collectLoadChildren(routes.children, target);
  23589. }
  23590. return target;
  23591. }
  23592. /**
  23593. * @param {?} route
  23594. * @param {?} reflector
  23595. * @param {?=} module
  23596. * @return {?}
  23597. */
  23598. function parseLazyRoute(route, reflector, module) {
  23599. const [routePath, routeName] = route.split('#');
  23600. const /** @type {?} */ referencedModule = reflector.resolveExternalReference({
  23601. moduleName: routePath,
  23602. name: routeName,
  23603. }, module ? module.filePath : undefined);
  23604. return { route: route, module: module || referencedModule, referencedModule };
  23605. }
  23606. /**
  23607. * @fileoverview added by tsickle
  23608. * @suppress {checkTypes} checked by tsc
  23609. */
  23610. /**
  23611. * @license
  23612. * Copyright Google Inc. All Rights Reserved.
  23613. *
  23614. * Use of this source code is governed by an MIT-style license that can be
  23615. * found in the LICENSE file at https://angular.io/license
  23616. */
  23617. class ResolvedStaticSymbol {
  23618. /**
  23619. * @param {?} symbol
  23620. * @param {?} metadata
  23621. */
  23622. constructor(symbol, metadata) {
  23623. this.symbol = symbol;
  23624. this.metadata = metadata;
  23625. }
  23626. }
  23627. /**
  23628. * The host of the SymbolResolverHost disconnects the implementation from TypeScript / other
  23629. * language
  23630. * services and from underlying file systems.
  23631. * @record
  23632. */
  23633. const SUPPORTED_SCHEMA_VERSION = 4;
  23634. /**
  23635. * This class is responsible for loading metadata per symbol,
  23636. * and normalizing references between symbols.
  23637. *
  23638. * Internally, it only uses symbols without members,
  23639. * and deduces the values for symbols with members based
  23640. * on these symbols.
  23641. */
  23642. class StaticSymbolResolver {
  23643. /**
  23644. * @param {?} host
  23645. * @param {?} staticSymbolCache
  23646. * @param {?} summaryResolver
  23647. * @param {?=} errorRecorder
  23648. */
  23649. constructor(host, staticSymbolCache, summaryResolver, errorRecorder) {
  23650. this.host = host;
  23651. this.staticSymbolCache = staticSymbolCache;
  23652. this.summaryResolver = summaryResolver;
  23653. this.errorRecorder = errorRecorder;
  23654. this.metadataCache = new Map();
  23655. this.resolvedSymbols = new Map();
  23656. this.resolvedFilePaths = new Set();
  23657. this.importAs = new Map();
  23658. this.symbolResourcePaths = new Map();
  23659. this.symbolFromFile = new Map();
  23660. this.knownFileNameToModuleNames = new Map();
  23661. }
  23662. /**
  23663. * @param {?} staticSymbol
  23664. * @return {?}
  23665. */
  23666. resolveSymbol(staticSymbol) {
  23667. if (staticSymbol.members.length > 0) {
  23668. return /** @type {?} */ ((this._resolveSymbolMembers(staticSymbol)));
  23669. }
  23670. // Note: always ask for a summary first,
  23671. // as we might have read shallow metadata via a .d.ts file
  23672. // for the symbol.
  23673. const /** @type {?} */ resultFromSummary = /** @type {?} */ ((this._resolveSymbolFromSummary(staticSymbol)));
  23674. if (resultFromSummary) {
  23675. return resultFromSummary;
  23676. }
  23677. const /** @type {?} */ resultFromCache = this.resolvedSymbols.get(staticSymbol);
  23678. if (resultFromCache) {
  23679. return resultFromCache;
  23680. }
  23681. // Note: Some users use libraries that were not compiled with ngc, i.e. they don't
  23682. // have summaries, only .d.ts files. So we always need to check both, the summary
  23683. // and metadata.
  23684. this._createSymbolsOf(staticSymbol.filePath);
  23685. return /** @type {?} */ ((this.resolvedSymbols.get(staticSymbol)));
  23686. }
  23687. /**
  23688. * getImportAs produces a symbol that can be used to import the given symbol.
  23689. * The import might be different than the symbol if the symbol is exported from
  23690. * a library with a summary; in which case we want to import the symbol from the
  23691. * ngfactory re-export instead of directly to avoid introducing a direct dependency
  23692. * on an otherwise indirect dependency.
  23693. *
  23694. * @param {?} staticSymbol the symbol for which to generate a import symbol
  23695. * @param {?=} useSummaries
  23696. * @return {?}
  23697. */
  23698. getImportAs(staticSymbol, useSummaries = true) {
  23699. if (staticSymbol.members.length) {
  23700. const /** @type {?} */ baseSymbol = this.getStaticSymbol(staticSymbol.filePath, staticSymbol.name);
  23701. const /** @type {?} */ baseImportAs = this.getImportAs(baseSymbol, useSummaries);
  23702. return baseImportAs ?
  23703. this.getStaticSymbol(baseImportAs.filePath, baseImportAs.name, staticSymbol.members) :
  23704. null;
  23705. }
  23706. const /** @type {?} */ summarizedFileName = stripSummaryForJitFileSuffix(staticSymbol.filePath);
  23707. if (summarizedFileName !== staticSymbol.filePath) {
  23708. const /** @type {?} */ summarizedName = stripSummaryForJitNameSuffix(staticSymbol.name);
  23709. const /** @type {?} */ baseSymbol = this.getStaticSymbol(summarizedFileName, summarizedName, staticSymbol.members);
  23710. const /** @type {?} */ baseImportAs = this.getImportAs(baseSymbol, useSummaries);
  23711. return baseImportAs ?
  23712. this.getStaticSymbol(summaryForJitFileName(baseImportAs.filePath), summaryForJitName(baseImportAs.name), baseSymbol.members) :
  23713. null;
  23714. }
  23715. let /** @type {?} */ result = (useSummaries && this.summaryResolver.getImportAs(staticSymbol)) || null;
  23716. if (!result) {
  23717. result = /** @type {?} */ ((this.importAs.get(staticSymbol)));
  23718. }
  23719. return result;
  23720. }
  23721. /**
  23722. * getResourcePath produces the path to the original location of the symbol and should
  23723. * be used to determine the relative location of resource references recorded in
  23724. * symbol metadata.
  23725. * @param {?} staticSymbol
  23726. * @return {?}
  23727. */
  23728. getResourcePath(staticSymbol) {
  23729. return this.symbolResourcePaths.get(staticSymbol) || staticSymbol.filePath;
  23730. }
  23731. /**
  23732. * getTypeArity returns the number of generic type parameters the given symbol
  23733. * has. If the symbol is not a type the result is null.
  23734. * @param {?} staticSymbol
  23735. * @return {?}
  23736. */
  23737. getTypeArity(staticSymbol) {
  23738. // If the file is a factory/ngsummary file, don't resolve the symbol as doing so would
  23739. // cause the metadata for an factory/ngsummary file to be loaded which doesn't exist.
  23740. // All references to generated classes must include the correct arity whenever
  23741. // generating code.
  23742. if (isGeneratedFile(staticSymbol.filePath)) {
  23743. return null;
  23744. }
  23745. let /** @type {?} */ resolvedSymbol = unwrapResolvedMetadata(this.resolveSymbol(staticSymbol));
  23746. while (resolvedSymbol && resolvedSymbol.metadata instanceof StaticSymbol) {
  23747. resolvedSymbol = unwrapResolvedMetadata(this.resolveSymbol(resolvedSymbol.metadata));
  23748. }
  23749. return (resolvedSymbol && resolvedSymbol.metadata && resolvedSymbol.metadata.arity) || null;
  23750. }
  23751. /**
  23752. * @param {?} filePath
  23753. * @return {?}
  23754. */
  23755. getKnownModuleName(filePath) {
  23756. return this.knownFileNameToModuleNames.get(filePath) || null;
  23757. }
  23758. /**
  23759. * @param {?} sourceSymbol
  23760. * @param {?} targetSymbol
  23761. * @return {?}
  23762. */
  23763. recordImportAs(sourceSymbol, targetSymbol) {
  23764. sourceSymbol.assertNoMembers();
  23765. targetSymbol.assertNoMembers();
  23766. this.importAs.set(sourceSymbol, targetSymbol);
  23767. }
  23768. /**
  23769. * @param {?} fileName
  23770. * @param {?} moduleName
  23771. * @return {?}
  23772. */
  23773. recordModuleNameForFileName(fileName, moduleName) {
  23774. this.knownFileNameToModuleNames.set(fileName, moduleName);
  23775. }
  23776. /**
  23777. * Invalidate all information derived from the given file.
  23778. *
  23779. * @param {?} fileName the file to invalidate
  23780. * @return {?}
  23781. */
  23782. invalidateFile(fileName) {
  23783. this.metadataCache.delete(fileName);
  23784. this.resolvedFilePaths.delete(fileName);
  23785. const /** @type {?} */ symbols = this.symbolFromFile.get(fileName);
  23786. if (symbols) {
  23787. this.symbolFromFile.delete(fileName);
  23788. for (const /** @type {?} */ symbol of symbols) {
  23789. this.resolvedSymbols.delete(symbol);
  23790. this.importAs.delete(symbol);
  23791. this.symbolResourcePaths.delete(symbol);
  23792. }
  23793. }
  23794. }
  23795. /**
  23796. * @template T
  23797. * @param {?} cb
  23798. * @return {?}
  23799. */
  23800. ignoreErrorsFor(cb) {
  23801. const /** @type {?} */ recorder = this.errorRecorder;
  23802. this.errorRecorder = () => { };
  23803. try {
  23804. return cb();
  23805. }
  23806. finally {
  23807. this.errorRecorder = recorder;
  23808. }
  23809. }
  23810. /**
  23811. * @param {?} staticSymbol
  23812. * @return {?}
  23813. */
  23814. _resolveSymbolMembers(staticSymbol) {
  23815. const /** @type {?} */ members = staticSymbol.members;
  23816. const /** @type {?} */ baseResolvedSymbol = this.resolveSymbol(this.getStaticSymbol(staticSymbol.filePath, staticSymbol.name));
  23817. if (!baseResolvedSymbol) {
  23818. return null;
  23819. }
  23820. let /** @type {?} */ baseMetadata = unwrapResolvedMetadata(baseResolvedSymbol.metadata);
  23821. if (baseMetadata instanceof StaticSymbol) {
  23822. return new ResolvedStaticSymbol(staticSymbol, this.getStaticSymbol(baseMetadata.filePath, baseMetadata.name, members));
  23823. }
  23824. else if (baseMetadata && baseMetadata.__symbolic === 'class') {
  23825. if (baseMetadata.statics && members.length === 1) {
  23826. return new ResolvedStaticSymbol(staticSymbol, baseMetadata.statics[members[0]]);
  23827. }
  23828. }
  23829. else {
  23830. let /** @type {?} */ value = baseMetadata;
  23831. for (let /** @type {?} */ i = 0; i < members.length && value; i++) {
  23832. value = value[members[i]];
  23833. }
  23834. return new ResolvedStaticSymbol(staticSymbol, value);
  23835. }
  23836. return null;
  23837. }
  23838. /**
  23839. * @param {?} staticSymbol
  23840. * @return {?}
  23841. */
  23842. _resolveSymbolFromSummary(staticSymbol) {
  23843. const /** @type {?} */ summary = this.summaryResolver.resolveSummary(staticSymbol);
  23844. return summary ? new ResolvedStaticSymbol(staticSymbol, summary.metadata) : null;
  23845. }
  23846. /**
  23847. * getStaticSymbol produces a Type whose metadata is known but whose implementation is not loaded.
  23848. * All types passed to the StaticResolver should be pseudo-types returned by this method.
  23849. *
  23850. * @param {?} declarationFile the absolute path of the file where the symbol is declared
  23851. * @param {?} name the name of the type.
  23852. * @param {?=} members a symbol for a static member of the named type
  23853. * @return {?}
  23854. */
  23855. getStaticSymbol(declarationFile, name, members) {
  23856. return this.staticSymbolCache.get(declarationFile, name, members);
  23857. }
  23858. /**
  23859. * hasDecorators checks a file's metadata for the presense of decorators without evalutating the
  23860. * metadata.
  23861. *
  23862. * @param {?} filePath the absolute path to examine for decorators.
  23863. * @return {?} true if any class in the file has a decorator.
  23864. */
  23865. hasDecorators(filePath) {
  23866. const /** @type {?} */ metadata = this.getModuleMetadata(filePath);
  23867. if (metadata['metadata']) {
  23868. return Object.keys(metadata['metadata']).some((metadataKey) => {
  23869. const /** @type {?} */ entry = metadata['metadata'][metadataKey];
  23870. return entry && entry.__symbolic === 'class' && entry.decorators;
  23871. });
  23872. }
  23873. return false;
  23874. }
  23875. /**
  23876. * @param {?} filePath
  23877. * @return {?}
  23878. */
  23879. getSymbolsOf(filePath) {
  23880. const /** @type {?} */ summarySymbols = this.summaryResolver.getSymbolsOf(filePath);
  23881. if (summarySymbols) {
  23882. return summarySymbols;
  23883. }
  23884. // Note: Some users use libraries that were not compiled with ngc, i.e. they don't
  23885. // have summaries, only .d.ts files, but `summaryResolver.isLibraryFile` returns true.
  23886. this._createSymbolsOf(filePath);
  23887. const /** @type {?} */ metadataSymbols = [];
  23888. this.resolvedSymbols.forEach((resolvedSymbol) => {
  23889. if (resolvedSymbol.symbol.filePath === filePath) {
  23890. metadataSymbols.push(resolvedSymbol.symbol);
  23891. }
  23892. });
  23893. return metadataSymbols;
  23894. }
  23895. /**
  23896. * @param {?} filePath
  23897. * @return {?}
  23898. */
  23899. _createSymbolsOf(filePath) {
  23900. if (this.resolvedFilePaths.has(filePath)) {
  23901. return;
  23902. }
  23903. this.resolvedFilePaths.add(filePath);
  23904. const /** @type {?} */ resolvedSymbols = [];
  23905. const /** @type {?} */ metadata = this.getModuleMetadata(filePath);
  23906. if (metadata['importAs']) {
  23907. // Index bundle indices should use the importAs module name defined
  23908. // in the bundle.
  23909. this.knownFileNameToModuleNames.set(filePath, metadata['importAs']);
  23910. }
  23911. // handle the symbols in one of the re-export location
  23912. if (metadata['exports']) {
  23913. for (const /** @type {?} */ moduleExport of metadata['exports']) {
  23914. // handle the symbols in the list of explicitly re-exported symbols.
  23915. if (moduleExport.export) {
  23916. moduleExport.export.forEach((exportSymbol) => {
  23917. let /** @type {?} */ symbolName;
  23918. if (typeof exportSymbol === 'string') {
  23919. symbolName = exportSymbol;
  23920. }
  23921. else {
  23922. symbolName = exportSymbol.as;
  23923. }
  23924. symbolName = unescapeIdentifier(symbolName);
  23925. let /** @type {?} */ symName = symbolName;
  23926. if (typeof exportSymbol !== 'string') {
  23927. symName = unescapeIdentifier(exportSymbol.name);
  23928. }
  23929. const /** @type {?} */ resolvedModule = this.resolveModule(moduleExport.from, filePath);
  23930. if (resolvedModule) {
  23931. const /** @type {?} */ targetSymbol = this.getStaticSymbol(resolvedModule, symName);
  23932. const /** @type {?} */ sourceSymbol = this.getStaticSymbol(filePath, symbolName);
  23933. resolvedSymbols.push(this.createExport(sourceSymbol, targetSymbol));
  23934. }
  23935. });
  23936. }
  23937. else {
  23938. // handle the symbols via export * directives.
  23939. const /** @type {?} */ resolvedModule = this.resolveModule(moduleExport.from, filePath);
  23940. if (resolvedModule) {
  23941. const /** @type {?} */ nestedExports = this.getSymbolsOf(resolvedModule);
  23942. nestedExports.forEach((targetSymbol) => {
  23943. const /** @type {?} */ sourceSymbol = this.getStaticSymbol(filePath, targetSymbol.name);
  23944. resolvedSymbols.push(this.createExport(sourceSymbol, targetSymbol));
  23945. });
  23946. }
  23947. }
  23948. }
  23949. }
  23950. // handle the actual metadata. Has to be after the exports
  23951. // as there migth be collisions in the names, and we want the symbols
  23952. // of the current module to win ofter reexports.
  23953. if (metadata['metadata']) {
  23954. // handle direct declarations of the symbol
  23955. const /** @type {?} */ topLevelSymbolNames = new Set(Object.keys(metadata['metadata']).map(unescapeIdentifier));
  23956. const /** @type {?} */ origins = metadata['origins'] || {};
  23957. Object.keys(metadata['metadata']).forEach((metadataKey) => {
  23958. const /** @type {?} */ symbolMeta = metadata['metadata'][metadataKey];
  23959. const /** @type {?} */ name = unescapeIdentifier(metadataKey);
  23960. const /** @type {?} */ symbol = this.getStaticSymbol(filePath, name);
  23961. const /** @type {?} */ origin = origins.hasOwnProperty(metadataKey) && origins[metadataKey];
  23962. if (origin) {
  23963. // If the symbol is from a bundled index, use the declaration location of the
  23964. // symbol so relative references (such as './my.html') will be calculated
  23965. // correctly.
  23966. const /** @type {?} */ originFilePath = this.resolveModule(origin, filePath);
  23967. if (!originFilePath) {
  23968. this.reportError(new Error(`Couldn't resolve original symbol for ${origin} from ${filePath}`));
  23969. }
  23970. else {
  23971. this.symbolResourcePaths.set(symbol, originFilePath);
  23972. }
  23973. }
  23974. resolvedSymbols.push(this.createResolvedSymbol(symbol, filePath, topLevelSymbolNames, symbolMeta));
  23975. });
  23976. }
  23977. resolvedSymbols.forEach((resolvedSymbol) => this.resolvedSymbols.set(resolvedSymbol.symbol, resolvedSymbol));
  23978. this.symbolFromFile.set(filePath, resolvedSymbols.map(resolvedSymbol => resolvedSymbol.symbol));
  23979. }
  23980. /**
  23981. * @param {?} sourceSymbol
  23982. * @param {?} topLevelPath
  23983. * @param {?} topLevelSymbolNames
  23984. * @param {?} metadata
  23985. * @return {?}
  23986. */
  23987. createResolvedSymbol(sourceSymbol, topLevelPath, topLevelSymbolNames, metadata) {
  23988. // For classes that don't have Angular summaries / metadata,
  23989. // we only keep their arity, but nothing else
  23990. // (e.g. their constructor parameters).
  23991. // We do this to prevent introducing deep imports
  23992. // as we didn't generate .ngfactory.ts files with proper reexports.
  23993. if (this.summaryResolver.isLibraryFile(sourceSymbol.filePath) && metadata &&
  23994. metadata['__symbolic'] === 'class') {
  23995. const /** @type {?} */ transformedMeta = { __symbolic: 'class', arity: metadata.arity };
  23996. return new ResolvedStaticSymbol(sourceSymbol, transformedMeta);
  23997. }
  23998. let /** @type {?} */ _originalFileMemo;
  23999. const /** @type {?} */ getOriginalName = () => {
  24000. if (!_originalFileMemo) {
  24001. // Guess what hte original file name is from the reference. If it has a `.d.ts` extension
  24002. // replace it with `.ts`. If it already has `.ts` just leave it in place. If it doesn't have
  24003. // .ts or .d.ts, append `.ts'. Also, if it is in `node_modules`, trim the `node_module`
  24004. // location as it is not important to finding the file.
  24005. _originalFileMemo =
  24006. this.host.getOutputName(topLevelPath.replace(/((\.ts)|(\.d\.ts)|)$/, '.ts')
  24007. .replace(/^.*node_modules[/\\]/, ''));
  24008. }
  24009. return _originalFileMemo;
  24010. };
  24011. const /** @type {?} */ self = this;
  24012. class ReferenceTransformer extends ValueTransformer {
  24013. /**
  24014. * @param {?} map
  24015. * @param {?} functionParams
  24016. * @return {?}
  24017. */
  24018. visitStringMap(map, functionParams) {
  24019. const /** @type {?} */ symbolic = map['__symbolic'];
  24020. if (symbolic === 'function') {
  24021. const /** @type {?} */ oldLen = functionParams.length;
  24022. functionParams.push(...(map['parameters'] || []));
  24023. const /** @type {?} */ result = super.visitStringMap(map, functionParams);
  24024. functionParams.length = oldLen;
  24025. return result;
  24026. }
  24027. else if (symbolic === 'reference') {
  24028. const /** @type {?} */ module = map['module'];
  24029. const /** @type {?} */ name = map['name'] ? unescapeIdentifier(map['name']) : map['name'];
  24030. if (!name) {
  24031. return null;
  24032. }
  24033. let /** @type {?} */ filePath;
  24034. if (module) {
  24035. filePath = /** @type {?} */ ((self.resolveModule(module, sourceSymbol.filePath)));
  24036. if (!filePath) {
  24037. return {
  24038. __symbolic: 'error',
  24039. message: `Could not resolve ${module} relative to ${sourceSymbol.filePath}.`,
  24040. line: map["line"],
  24041. character: map["character"],
  24042. fileName: getOriginalName()
  24043. };
  24044. }
  24045. return {
  24046. __symbolic: 'resolved',
  24047. symbol: self.getStaticSymbol(filePath, name),
  24048. line: map["line"],
  24049. character: map["character"],
  24050. fileName: getOriginalName()
  24051. };
  24052. }
  24053. else if (functionParams.indexOf(name) >= 0) {
  24054. // reference to a function parameter
  24055. return { __symbolic: 'reference', name: name };
  24056. }
  24057. else {
  24058. if (topLevelSymbolNames.has(name)) {
  24059. return self.getStaticSymbol(topLevelPath, name);
  24060. }
  24061. // ambient value
  24062. null;
  24063. }
  24064. }
  24065. else if (symbolic === 'error') {
  24066. return Object.assign({}, map, { fileName: getOriginalName() });
  24067. }
  24068. else {
  24069. return super.visitStringMap(map, functionParams);
  24070. }
  24071. }
  24072. }
  24073. const /** @type {?} */ transformedMeta = visitValue(metadata, new ReferenceTransformer(), []);
  24074. let /** @type {?} */ unwrappedTransformedMeta = unwrapResolvedMetadata(transformedMeta);
  24075. if (unwrappedTransformedMeta instanceof StaticSymbol) {
  24076. return this.createExport(sourceSymbol, unwrappedTransformedMeta);
  24077. }
  24078. return new ResolvedStaticSymbol(sourceSymbol, transformedMeta);
  24079. }
  24080. /**
  24081. * @param {?} sourceSymbol
  24082. * @param {?} targetSymbol
  24083. * @return {?}
  24084. */
  24085. createExport(sourceSymbol, targetSymbol) {
  24086. sourceSymbol.assertNoMembers();
  24087. targetSymbol.assertNoMembers();
  24088. if (this.summaryResolver.isLibraryFile(sourceSymbol.filePath) &&
  24089. this.summaryResolver.isLibraryFile(targetSymbol.filePath)) {
  24090. // This case is for an ng library importing symbols from a plain ts library
  24091. // transitively.
  24092. // Note: We rely on the fact that we discover symbols in the direction
  24093. // from source files to library files
  24094. this.importAs.set(targetSymbol, this.getImportAs(sourceSymbol) || sourceSymbol);
  24095. }
  24096. return new ResolvedStaticSymbol(sourceSymbol, targetSymbol);
  24097. }
  24098. /**
  24099. * @param {?} error
  24100. * @param {?=} context
  24101. * @param {?=} path
  24102. * @return {?}
  24103. */
  24104. reportError(error, context, path) {
  24105. if (this.errorRecorder) {
  24106. this.errorRecorder(error, (context && context.filePath) || path);
  24107. }
  24108. else {
  24109. throw error;
  24110. }
  24111. }
  24112. /**
  24113. * @param {?} module an absolute path to a module file.
  24114. * @return {?}
  24115. */
  24116. getModuleMetadata(module) {
  24117. let /** @type {?} */ moduleMetadata = this.metadataCache.get(module);
  24118. if (!moduleMetadata) {
  24119. const /** @type {?} */ moduleMetadatas = this.host.getMetadataFor(module);
  24120. if (moduleMetadatas) {
  24121. let /** @type {?} */ maxVersion = -1;
  24122. moduleMetadatas.forEach((md) => {
  24123. if (md && md['version'] > maxVersion) {
  24124. maxVersion = md['version'];
  24125. moduleMetadata = md;
  24126. }
  24127. });
  24128. }
  24129. if (!moduleMetadata) {
  24130. moduleMetadata =
  24131. { __symbolic: 'module', version: SUPPORTED_SCHEMA_VERSION, module: module, metadata: {} };
  24132. }
  24133. if (moduleMetadata['version'] != SUPPORTED_SCHEMA_VERSION) {
  24134. const /** @type {?} */ errorMessage = moduleMetadata['version'] == 2 ?
  24135. `Unsupported metadata version ${moduleMetadata['version']} for module ${module}. This module should be compiled with a newer version of ngc` :
  24136. `Metadata version mismatch for module ${module}, found version ${moduleMetadata['version']}, expected ${SUPPORTED_SCHEMA_VERSION}`;
  24137. this.reportError(new Error(errorMessage));
  24138. }
  24139. this.metadataCache.set(module, moduleMetadata);
  24140. }
  24141. return moduleMetadata;
  24142. }
  24143. /**
  24144. * @param {?} module
  24145. * @param {?} symbolName
  24146. * @param {?=} containingFile
  24147. * @return {?}
  24148. */
  24149. getSymbolByModule(module, symbolName, containingFile) {
  24150. const /** @type {?} */ filePath = this.resolveModule(module, containingFile);
  24151. if (!filePath) {
  24152. this.reportError(new Error(`Could not resolve module ${module}${containingFile ? ' relative to ' +
  24153. containingFile : ''}`));
  24154. return this.getStaticSymbol(`ERROR:${module}`, symbolName);
  24155. }
  24156. return this.getStaticSymbol(filePath, symbolName);
  24157. }
  24158. /**
  24159. * @param {?} module
  24160. * @param {?=} containingFile
  24161. * @return {?}
  24162. */
  24163. resolveModule(module, containingFile) {
  24164. try {
  24165. return this.host.moduleNameToFileName(module, containingFile);
  24166. }
  24167. catch (/** @type {?} */ e) {
  24168. console.error(`Could not resolve module '${module}' relative to file ${containingFile}`);
  24169. this.reportError(e, undefined, containingFile);
  24170. }
  24171. return null;
  24172. }
  24173. }
  24174. /**
  24175. * @param {?} identifier
  24176. * @return {?}
  24177. */
  24178. function unescapeIdentifier(identifier) {
  24179. return identifier.startsWith('___') ? identifier.substr(1) : identifier;
  24180. }
  24181. /**
  24182. * @param {?} metadata
  24183. * @return {?}
  24184. */
  24185. function unwrapResolvedMetadata(metadata) {
  24186. if (metadata && metadata.__symbolic === 'resolved') {
  24187. return metadata.symbol;
  24188. }
  24189. return metadata;
  24190. }
  24191. /**
  24192. * @fileoverview added by tsickle
  24193. * @suppress {checkTypes} checked by tsc
  24194. */
  24195. /**
  24196. * @param {?} srcFileName
  24197. * @param {?} forJitCtx
  24198. * @param {?} summaryResolver
  24199. * @param {?} symbolResolver
  24200. * @param {?} symbols
  24201. * @param {?} types
  24202. * @return {?}
  24203. */
  24204. function serializeSummaries(srcFileName, forJitCtx, summaryResolver, symbolResolver, symbols, types) {
  24205. const /** @type {?} */ toJsonSerializer = new ToJsonSerializer(symbolResolver, summaryResolver, srcFileName);
  24206. // for symbols, we use everything except for the class metadata itself
  24207. // (we keep the statics though), as the class metadata is contained in the
  24208. // CompileTypeSummary.
  24209. symbols.forEach((resolvedSymbol) => toJsonSerializer.addSummary({ symbol: resolvedSymbol.symbol, metadata: resolvedSymbol.metadata }));
  24210. // Add type summaries.
  24211. types.forEach(({ summary, metadata }) => {
  24212. toJsonSerializer.addSummary({ symbol: summary.type.reference, metadata: undefined, type: summary });
  24213. });
  24214. const { json, exportAs } = toJsonSerializer.serialize();
  24215. if (forJitCtx) {
  24216. const /** @type {?} */ forJitSerializer = new ForJitSerializer(forJitCtx, symbolResolver, summaryResolver);
  24217. types.forEach(({ summary, metadata }) => { forJitSerializer.addSourceType(summary, metadata); });
  24218. toJsonSerializer.unprocessedSymbolSummariesBySymbol.forEach((summary) => {
  24219. if (summaryResolver.isLibraryFile(summary.symbol.filePath) && summary.type) {
  24220. forJitSerializer.addLibType(summary.type);
  24221. }
  24222. });
  24223. forJitSerializer.serialize(exportAs);
  24224. }
  24225. return { json, exportAs };
  24226. }
  24227. /**
  24228. * @param {?} symbolCache
  24229. * @param {?} summaryResolver
  24230. * @param {?} libraryFileName
  24231. * @param {?} json
  24232. * @return {?}
  24233. */
  24234. function deserializeSummaries(symbolCache, summaryResolver, libraryFileName, json) {
  24235. const /** @type {?} */ deserializer = new FromJsonDeserializer(symbolCache, summaryResolver);
  24236. return deserializer.deserialize(libraryFileName, json);
  24237. }
  24238. /**
  24239. * @param {?} outputCtx
  24240. * @param {?} reference
  24241. * @return {?}
  24242. */
  24243. function createForJitStub(outputCtx, reference) {
  24244. return createSummaryForJitFunction(outputCtx, reference, NULL_EXPR);
  24245. }
  24246. /**
  24247. * @param {?} outputCtx
  24248. * @param {?} reference
  24249. * @param {?} value
  24250. * @return {?}
  24251. */
  24252. function createSummaryForJitFunction(outputCtx, reference, value) {
  24253. const /** @type {?} */ fnName = summaryForJitName(reference.name);
  24254. outputCtx.statements.push(fn([], [new ReturnStatement(value)], new ArrayType(DYNAMIC_TYPE)).toDeclStmt(fnName, [
  24255. StmtModifier.Final, StmtModifier.Exported
  24256. ]));
  24257. }
  24258. class ToJsonSerializer extends ValueTransformer {
  24259. /**
  24260. * @param {?} symbolResolver
  24261. * @param {?} summaryResolver
  24262. * @param {?} srcFileName
  24263. */
  24264. constructor(symbolResolver, summaryResolver, srcFileName) {
  24265. super();
  24266. this.symbolResolver = symbolResolver;
  24267. this.summaryResolver = summaryResolver;
  24268. this.srcFileName = srcFileName;
  24269. this.symbols = [];
  24270. this.indexBySymbol = new Map();
  24271. this.reexportedBy = new Map();
  24272. this.processedSummaryBySymbol = new Map();
  24273. this.processedSummaries = [];
  24274. this.unprocessedSymbolSummariesBySymbol = new Map();
  24275. this.moduleName = symbolResolver.getKnownModuleName(srcFileName);
  24276. }
  24277. /**
  24278. * @param {?} summary
  24279. * @return {?}
  24280. */
  24281. addSummary(summary) {
  24282. let /** @type {?} */ unprocessedSummary = this.unprocessedSymbolSummariesBySymbol.get(summary.symbol);
  24283. let /** @type {?} */ processedSummary = this.processedSummaryBySymbol.get(summary.symbol);
  24284. if (!unprocessedSummary) {
  24285. unprocessedSummary = { symbol: summary.symbol, metadata: undefined };
  24286. this.unprocessedSymbolSummariesBySymbol.set(summary.symbol, unprocessedSummary);
  24287. processedSummary = { symbol: this.processValue(summary.symbol, 0 /* None */) };
  24288. this.processedSummaries.push(processedSummary);
  24289. this.processedSummaryBySymbol.set(summary.symbol, processedSummary);
  24290. }
  24291. if (!unprocessedSummary.metadata && summary.metadata) {
  24292. let /** @type {?} */ metadata = summary.metadata || {};
  24293. if (metadata.__symbolic === 'class') {
  24294. // For classes, we keep everything except their class decorators.
  24295. // We need to keep e.g. the ctor args, method names, method decorators
  24296. // so that the class can be extended in another compilation unit.
  24297. // We don't keep the class decorators as
  24298. // 1) they refer to data
  24299. // that should not cause a rebuild of downstream compilation units
  24300. // (e.g. inline templates of @Component, or @NgModule.declarations)
  24301. // 2) their data is already captured in TypeSummaries, e.g. DirectiveSummary.
  24302. const /** @type {?} */ clone = {};
  24303. Object.keys(metadata).forEach((propName) => {
  24304. if (propName !== 'decorators') {
  24305. clone[propName] = metadata[propName];
  24306. }
  24307. });
  24308. metadata = clone;
  24309. }
  24310. else if (isCall(metadata)) {
  24311. if (!isFunctionCall(metadata) && !isMethodCallOnVariable(metadata)) {
  24312. // Don't store complex calls as we won't be able to simplify them anyways later on.
  24313. metadata = {
  24314. __symbolic: 'error',
  24315. message: 'Complex function calls are not supported.',
  24316. };
  24317. }
  24318. }
  24319. // Note: We need to keep storing ctor calls for e.g.
  24320. // `export const x = new InjectionToken(...)`
  24321. unprocessedSummary.metadata = metadata;
  24322. processedSummary.metadata = this.processValue(metadata, 1 /* ResolveValue */);
  24323. if (metadata instanceof StaticSymbol &&
  24324. this.summaryResolver.isLibraryFile(metadata.filePath)) {
  24325. const /** @type {?} */ declarationSymbol = this.symbols[/** @type {?} */ ((this.indexBySymbol.get(metadata)))];
  24326. if (!isLoweredSymbol(declarationSymbol.name)) {
  24327. // Note: symbols that were introduced during codegen in the user file can have a reexport
  24328. // if a user used `export *`. However, we can't rely on this as tsickle will change
  24329. // `export *` into named exports, using only the information from the typechecker.
  24330. // As we introduce the new symbols after typecheck, Tsickle does not know about them,
  24331. // and omits them when expanding `export *`.
  24332. // So we have to keep reexporting these symbols manually via .ngfactory files.
  24333. this.reexportedBy.set(declarationSymbol, summary.symbol);
  24334. }
  24335. }
  24336. }
  24337. if (!unprocessedSummary.type && summary.type) {
  24338. unprocessedSummary.type = summary.type;
  24339. // Note: We don't add the summaries of all referenced symbols as for the ResolvedSymbols,
  24340. // as the type summaries already contain the transitive data that they require
  24341. // (in a minimal way).
  24342. processedSummary.type = this.processValue(summary.type, 0 /* None */);
  24343. // except for reexported directives / pipes, so we need to store
  24344. // their summaries explicitly.
  24345. if (summary.type.summaryKind === CompileSummaryKind.NgModule) {
  24346. const /** @type {?} */ ngModuleSummary = /** @type {?} */ (summary.type);
  24347. ngModuleSummary.exportedDirectives.concat(ngModuleSummary.exportedPipes).forEach((id) => {
  24348. const /** @type {?} */ symbol = id.reference;
  24349. if (this.summaryResolver.isLibraryFile(symbol.filePath) &&
  24350. !this.unprocessedSymbolSummariesBySymbol.has(symbol)) {
  24351. const /** @type {?} */ summary = this.summaryResolver.resolveSummary(symbol);
  24352. if (summary) {
  24353. this.addSummary(summary);
  24354. }
  24355. }
  24356. });
  24357. }
  24358. }
  24359. }
  24360. /**
  24361. * @return {?}
  24362. */
  24363. serialize() {
  24364. const /** @type {?} */ exportAs = [];
  24365. const /** @type {?} */ json = JSON.stringify({
  24366. moduleName: this.moduleName,
  24367. summaries: this.processedSummaries,
  24368. symbols: this.symbols.map((symbol, index) => {
  24369. symbol.assertNoMembers();
  24370. let /** @type {?} */ importAs = /** @type {?} */ ((undefined));
  24371. if (this.summaryResolver.isLibraryFile(symbol.filePath)) {
  24372. const /** @type {?} */ reexportSymbol = this.reexportedBy.get(symbol);
  24373. if (reexportSymbol) {
  24374. importAs = /** @type {?} */ ((this.indexBySymbol.get(reexportSymbol)));
  24375. }
  24376. else {
  24377. const /** @type {?} */ summary = this.unprocessedSymbolSummariesBySymbol.get(symbol);
  24378. if (!summary || !summary.metadata || summary.metadata.__symbolic !== 'interface') {
  24379. importAs = `${symbol.name}_${index}`;
  24380. exportAs.push({ symbol, exportAs: importAs });
  24381. }
  24382. }
  24383. }
  24384. return {
  24385. __symbol: index,
  24386. name: symbol.name,
  24387. filePath: this.summaryResolver.toSummaryFileName(symbol.filePath, this.srcFileName),
  24388. importAs: importAs
  24389. };
  24390. })
  24391. });
  24392. return { json, exportAs };
  24393. }
  24394. /**
  24395. * @param {?} value
  24396. * @param {?} flags
  24397. * @return {?}
  24398. */
  24399. processValue(value, flags) {
  24400. return visitValue(value, this, flags);
  24401. }
  24402. /**
  24403. * @param {?} value
  24404. * @param {?} context
  24405. * @return {?}
  24406. */
  24407. visitOther(value, context) {
  24408. if (value instanceof StaticSymbol) {
  24409. let /** @type {?} */ baseSymbol = this.symbolResolver.getStaticSymbol(value.filePath, value.name);
  24410. const /** @type {?} */ index = this.visitStaticSymbol(baseSymbol, context);
  24411. return { __symbol: index, members: value.members };
  24412. }
  24413. }
  24414. /**
  24415. * Returns null if the options.resolveValue is true, and the summary for the symbol
  24416. * resolved to a type or could not be resolved.
  24417. * @param {?} baseSymbol
  24418. * @param {?} flags
  24419. * @return {?}
  24420. */
  24421. visitStaticSymbol(baseSymbol, flags) {
  24422. let /** @type {?} */ index = this.indexBySymbol.get(baseSymbol);
  24423. let /** @type {?} */ summary = null;
  24424. if (flags & 1 /* ResolveValue */ &&
  24425. this.summaryResolver.isLibraryFile(baseSymbol.filePath)) {
  24426. if (this.unprocessedSymbolSummariesBySymbol.has(baseSymbol)) {
  24427. // the summary for this symbol was already added
  24428. // -> nothing to do.
  24429. return /** @type {?} */ ((index));
  24430. }
  24431. summary = this.loadSummary(baseSymbol);
  24432. if (summary && summary.metadata instanceof StaticSymbol) {
  24433. // The summary is a reexport
  24434. index = this.visitStaticSymbol(summary.metadata, flags);
  24435. // reset the summary as it is just a reexport, so we don't want to store it.
  24436. summary = null;
  24437. }
  24438. }
  24439. else if (index != null) {
  24440. // Note: == on purpose to compare with undefined!
  24441. // No summary and the symbol is already added -> nothing to do.
  24442. return index;
  24443. }
  24444. // Note: == on purpose to compare with undefined!
  24445. if (index == null) {
  24446. index = this.symbols.length;
  24447. this.symbols.push(baseSymbol);
  24448. }
  24449. this.indexBySymbol.set(baseSymbol, index);
  24450. if (summary) {
  24451. this.addSummary(summary);
  24452. }
  24453. return index;
  24454. }
  24455. /**
  24456. * @param {?} symbol
  24457. * @return {?}
  24458. */
  24459. loadSummary(symbol) {
  24460. let /** @type {?} */ summary = this.summaryResolver.resolveSummary(symbol);
  24461. if (!summary) {
  24462. // some symbols might originate from a plain typescript library
  24463. // that just exported .d.ts and .metadata.json files, i.e. where no summary
  24464. // files were created.
  24465. const /** @type {?} */ resolvedSymbol = this.symbolResolver.resolveSymbol(symbol);
  24466. if (resolvedSymbol) {
  24467. summary = { symbol: resolvedSymbol.symbol, metadata: resolvedSymbol.metadata };
  24468. }
  24469. }
  24470. return summary;
  24471. }
  24472. }
  24473. class ForJitSerializer {
  24474. /**
  24475. * @param {?} outputCtx
  24476. * @param {?} symbolResolver
  24477. * @param {?} summaryResolver
  24478. */
  24479. constructor(outputCtx, symbolResolver, summaryResolver) {
  24480. this.outputCtx = outputCtx;
  24481. this.symbolResolver = symbolResolver;
  24482. this.summaryResolver = summaryResolver;
  24483. this.data = [];
  24484. }
  24485. /**
  24486. * @param {?} summary
  24487. * @param {?} metadata
  24488. * @return {?}
  24489. */
  24490. addSourceType(summary, metadata) {
  24491. this.data.push({ summary, metadata, isLibrary: false });
  24492. }
  24493. /**
  24494. * @param {?} summary
  24495. * @return {?}
  24496. */
  24497. addLibType(summary) {
  24498. this.data.push({ summary, metadata: null, isLibrary: true });
  24499. }
  24500. /**
  24501. * @param {?} exportAsArr
  24502. * @return {?}
  24503. */
  24504. serialize(exportAsArr) {
  24505. const /** @type {?} */ exportAsBySymbol = new Map();
  24506. for (const { symbol, exportAs } of exportAsArr) {
  24507. exportAsBySymbol.set(symbol, exportAs);
  24508. }
  24509. const /** @type {?} */ ngModuleSymbols = new Set();
  24510. for (const { summary, metadata, isLibrary } of this.data) {
  24511. if (summary.summaryKind === CompileSummaryKind.NgModule) {
  24512. // collect the symbols that refer to NgModule classes.
  24513. // Note: we can't just rely on `summary.type.summaryKind` to determine this as
  24514. // we don't add the summaries of all referenced symbols when we serialize type summaries.
  24515. // See serializeSummaries for details.
  24516. ngModuleSymbols.add(summary.type.reference);
  24517. const /** @type {?} */ modSummary = /** @type {?} */ (summary);
  24518. for (const /** @type {?} */ mod of modSummary.modules) {
  24519. ngModuleSymbols.add(mod.reference);
  24520. }
  24521. }
  24522. if (!isLibrary) {
  24523. const /** @type {?} */ fnName = summaryForJitName(summary.type.reference.name);
  24524. createSummaryForJitFunction(this.outputCtx, summary.type.reference, this.serializeSummaryWithDeps(summary, /** @type {?} */ ((metadata))));
  24525. }
  24526. }
  24527. ngModuleSymbols.forEach((ngModuleSymbol) => {
  24528. if (this.summaryResolver.isLibraryFile(ngModuleSymbol.filePath)) {
  24529. let /** @type {?} */ exportAs = exportAsBySymbol.get(ngModuleSymbol) || ngModuleSymbol.name;
  24530. const /** @type {?} */ jitExportAsName = summaryForJitName(exportAs);
  24531. this.outputCtx.statements.push(variable(jitExportAsName)
  24532. .set(this.serializeSummaryRef(ngModuleSymbol))
  24533. .toDeclStmt(null, [StmtModifier.Exported]));
  24534. }
  24535. });
  24536. }
  24537. /**
  24538. * @param {?} summary
  24539. * @param {?} metadata
  24540. * @return {?}
  24541. */
  24542. serializeSummaryWithDeps(summary, metadata) {
  24543. const /** @type {?} */ expressions = [this.serializeSummary(summary)];
  24544. let /** @type {?} */ providers = [];
  24545. if (metadata instanceof CompileNgModuleMetadata) {
  24546. expressions.push(...
  24547. // For directives / pipes, we only add the declared ones,
  24548. // and rely on transitively importing NgModules to get the transitive
  24549. // summaries.
  24550. metadata.declaredDirectives.concat(metadata.declaredPipes)
  24551. .map(type => type.reference)
  24552. .concat(metadata.transitiveModule.modules.map(type => type.reference)
  24553. .filter(ref => ref !== metadata.type.reference))
  24554. .map((ref) => this.serializeSummaryRef(ref)));
  24555. // Note: We don't use `NgModuleSummary.providers`, as that one is transitive,
  24556. // and we already have transitive modules.
  24557. providers = metadata.providers;
  24558. }
  24559. else if (summary.summaryKind === CompileSummaryKind.Directive) {
  24560. const /** @type {?} */ dirSummary = /** @type {?} */ (summary);
  24561. providers = dirSummary.providers.concat(dirSummary.viewProviders);
  24562. }
  24563. // Note: We can't just refer to the `ngsummary.ts` files for `useClass` providers (as we do for
  24564. // declaredDirectives / declaredPipes), as we allow
  24565. // providers without ctor arguments to skip the `@Injectable` decorator,
  24566. // i.e. we didn't generate .ngsummary.ts files for these.
  24567. expressions.push(...providers.filter(provider => !!provider.useClass).map(provider => this.serializeSummary(/** @type {?} */ ({
  24568. summaryKind: CompileSummaryKind.Injectable, type: provider.useClass
  24569. }))));
  24570. return literalArr(expressions);
  24571. }
  24572. /**
  24573. * @param {?} typeSymbol
  24574. * @return {?}
  24575. */
  24576. serializeSummaryRef(typeSymbol) {
  24577. const /** @type {?} */ jitImportedSymbol = this.symbolResolver.getStaticSymbol(summaryForJitFileName(typeSymbol.filePath), summaryForJitName(typeSymbol.name));
  24578. return this.outputCtx.importExpr(jitImportedSymbol);
  24579. }
  24580. /**
  24581. * @param {?} data
  24582. * @return {?}
  24583. */
  24584. serializeSummary(data) {
  24585. const /** @type {?} */ outputCtx = this.outputCtx;
  24586. class Transformer {
  24587. /**
  24588. * @param {?} arr
  24589. * @param {?} context
  24590. * @return {?}
  24591. */
  24592. visitArray(arr, context) {
  24593. return literalArr(arr.map(entry => visitValue(entry, this, context)));
  24594. }
  24595. /**
  24596. * @param {?} map
  24597. * @param {?} context
  24598. * @return {?}
  24599. */
  24600. visitStringMap(map, context) {
  24601. return new LiteralMapExpr(Object.keys(map).map((key) => new LiteralMapEntry(key, visitValue(map[key], this, context), false)));
  24602. }
  24603. /**
  24604. * @param {?} value
  24605. * @param {?} context
  24606. * @return {?}
  24607. */
  24608. visitPrimitive(value, context) { return literal(value); }
  24609. /**
  24610. * @param {?} value
  24611. * @param {?} context
  24612. * @return {?}
  24613. */
  24614. visitOther(value, context) {
  24615. if (value instanceof StaticSymbol) {
  24616. return outputCtx.importExpr(value);
  24617. }
  24618. else {
  24619. throw new Error(`Illegal State: Encountered value ${value}`);
  24620. }
  24621. }
  24622. }
  24623. return visitValue(data, new Transformer(), null);
  24624. }
  24625. }
  24626. class FromJsonDeserializer extends ValueTransformer {
  24627. /**
  24628. * @param {?} symbolCache
  24629. * @param {?} summaryResolver
  24630. */
  24631. constructor(symbolCache, summaryResolver) {
  24632. super();
  24633. this.symbolCache = symbolCache;
  24634. this.summaryResolver = summaryResolver;
  24635. }
  24636. /**
  24637. * @param {?} libraryFileName
  24638. * @param {?} json
  24639. * @return {?}
  24640. */
  24641. deserialize(libraryFileName, json) {
  24642. const /** @type {?} */ data = JSON.parse(json);
  24643. const /** @type {?} */ allImportAs = [];
  24644. this.symbols = data.symbols.map((serializedSymbol) => this.symbolCache.get(this.summaryResolver.fromSummaryFileName(serializedSymbol.filePath, libraryFileName), serializedSymbol.name));
  24645. data.symbols.forEach((serializedSymbol, index) => {
  24646. const /** @type {?} */ symbol = this.symbols[index];
  24647. const /** @type {?} */ importAs = serializedSymbol.importAs;
  24648. if (typeof importAs === 'number') {
  24649. allImportAs.push({ symbol, importAs: this.symbols[importAs] });
  24650. }
  24651. else if (typeof importAs === 'string') {
  24652. allImportAs.push({ symbol, importAs: this.symbolCache.get(ngfactoryFilePath(libraryFileName), importAs) });
  24653. }
  24654. });
  24655. const /** @type {?} */ summaries = /** @type {?} */ (visitValue(data.summaries, this, null));
  24656. return { moduleName: data.moduleName, summaries, importAs: allImportAs };
  24657. }
  24658. /**
  24659. * @param {?} map
  24660. * @param {?} context
  24661. * @return {?}
  24662. */
  24663. visitStringMap(map, context) {
  24664. if ('__symbol' in map) {
  24665. const /** @type {?} */ baseSymbol = this.symbols[map['__symbol']];
  24666. const /** @type {?} */ members = map['members'];
  24667. return members.length ? this.symbolCache.get(baseSymbol.filePath, baseSymbol.name, members) :
  24668. baseSymbol;
  24669. }
  24670. else {
  24671. return super.visitStringMap(map, context);
  24672. }
  24673. }
  24674. }
  24675. /**
  24676. * @param {?} metadata
  24677. * @return {?}
  24678. */
  24679. function isCall(metadata) {
  24680. return metadata && metadata.__symbolic === 'call';
  24681. }
  24682. /**
  24683. * @param {?} metadata
  24684. * @return {?}
  24685. */
  24686. function isFunctionCall(metadata) {
  24687. return isCall(metadata) && unwrapResolvedMetadata(metadata.expression) instanceof StaticSymbol;
  24688. }
  24689. /**
  24690. * @param {?} metadata
  24691. * @return {?}
  24692. */
  24693. function isMethodCallOnVariable(metadata) {
  24694. return isCall(metadata) && metadata.expression && metadata.expression.__symbolic === 'select' &&
  24695. unwrapResolvedMetadata(metadata.expression.expression) instanceof StaticSymbol;
  24696. }
  24697. /**
  24698. * @fileoverview added by tsickle
  24699. * @suppress {checkTypes} checked by tsc
  24700. */
  24701. /**
  24702. * @license
  24703. * Copyright Google Inc. All Rights Reserved.
  24704. *
  24705. * Use of this source code is governed by an MIT-style license that can be
  24706. * found in the LICENSE file at https://angular.io/license
  24707. */
  24708. /** @enum {number} */
  24709. const StubEmitFlags = {
  24710. Basic: 1,
  24711. TypeCheck: 2,
  24712. All: 3,
  24713. };
  24714. StubEmitFlags[StubEmitFlags.Basic] = "Basic";
  24715. StubEmitFlags[StubEmitFlags.TypeCheck] = "TypeCheck";
  24716. StubEmitFlags[StubEmitFlags.All] = "All";
  24717. class AotCompiler {
  24718. /**
  24719. * @param {?} _config
  24720. * @param {?} _options
  24721. * @param {?} _host
  24722. * @param {?} _reflector
  24723. * @param {?} _metadataResolver
  24724. * @param {?} _templateParser
  24725. * @param {?} _styleCompiler
  24726. * @param {?} _viewCompiler
  24727. * @param {?} _typeCheckCompiler
  24728. * @param {?} _ngModuleCompiler
  24729. * @param {?} _outputEmitter
  24730. * @param {?} _summaryResolver
  24731. * @param {?} _symbolResolver
  24732. */
  24733. constructor(_config, _options, _host, _reflector, _metadataResolver, _templateParser, _styleCompiler, _viewCompiler, _typeCheckCompiler, _ngModuleCompiler, _outputEmitter, _summaryResolver, _symbolResolver) {
  24734. this._config = _config;
  24735. this._options = _options;
  24736. this._host = _host;
  24737. this._reflector = _reflector;
  24738. this._metadataResolver = _metadataResolver;
  24739. this._templateParser = _templateParser;
  24740. this._styleCompiler = _styleCompiler;
  24741. this._viewCompiler = _viewCompiler;
  24742. this._typeCheckCompiler = _typeCheckCompiler;
  24743. this._ngModuleCompiler = _ngModuleCompiler;
  24744. this._outputEmitter = _outputEmitter;
  24745. this._summaryResolver = _summaryResolver;
  24746. this._symbolResolver = _symbolResolver;
  24747. this._templateAstCache = new Map();
  24748. this._analyzedFiles = new Map();
  24749. }
  24750. /**
  24751. * @return {?}
  24752. */
  24753. clearCache() { this._metadataResolver.clearCache(); }
  24754. /**
  24755. * @param {?} rootFiles
  24756. * @return {?}
  24757. */
  24758. analyzeModulesSync(rootFiles) {
  24759. const /** @type {?} */ analyzeResult = analyzeAndValidateNgModules(rootFiles, this._host, this._symbolResolver, this._metadataResolver);
  24760. analyzeResult.ngModules.forEach(ngModule => this._metadataResolver.loadNgModuleDirectiveAndPipeMetadata(ngModule.type.reference, true));
  24761. return analyzeResult;
  24762. }
  24763. /**
  24764. * @param {?} rootFiles
  24765. * @return {?}
  24766. */
  24767. analyzeModulesAsync(rootFiles) {
  24768. const /** @type {?} */ analyzeResult = analyzeAndValidateNgModules(rootFiles, this._host, this._symbolResolver, this._metadataResolver);
  24769. return Promise
  24770. .all(analyzeResult.ngModules.map(ngModule => this._metadataResolver.loadNgModuleDirectiveAndPipeMetadata(ngModule.type.reference, false)))
  24771. .then(() => analyzeResult);
  24772. }
  24773. /**
  24774. * @param {?} fileName
  24775. * @return {?}
  24776. */
  24777. _analyzeFile(fileName) {
  24778. let /** @type {?} */ analyzedFile = this._analyzedFiles.get(fileName);
  24779. if (!analyzedFile) {
  24780. analyzedFile =
  24781. analyzeFile(this._host, this._symbolResolver, this._metadataResolver, fileName);
  24782. this._analyzedFiles.set(fileName, analyzedFile);
  24783. }
  24784. return analyzedFile;
  24785. }
  24786. /**
  24787. * @param {?} fileName
  24788. * @return {?}
  24789. */
  24790. findGeneratedFileNames(fileName) {
  24791. const /** @type {?} */ genFileNames = [];
  24792. const /** @type {?} */ file = this._analyzeFile(fileName);
  24793. // Make sure we create a .ngfactory if we have a injectable/directive/pipe/NgModule
  24794. // or a reference to a non source file.
  24795. // Note: This is overestimating the required .ngfactory files as the real calculation is harder.
  24796. // Only do this for StubEmitFlags.Basic, as adding a type check block
  24797. // does not change this file (as we generate type check blocks based on NgModules).
  24798. if (this._options.allowEmptyCodegenFiles || file.directives.length || file.pipes.length ||
  24799. file.injectables.length || file.ngModules.length || file.exportsNonSourceFiles) {
  24800. genFileNames.push(ngfactoryFilePath(file.fileName, true));
  24801. if (this._options.enableSummariesForJit) {
  24802. genFileNames.push(summaryForJitFileName(file.fileName, true));
  24803. }
  24804. }
  24805. const /** @type {?} */ fileSuffix = normalizeGenFileSuffix(splitTypescriptSuffix(file.fileName, true)[1]);
  24806. file.directives.forEach((dirSymbol) => {
  24807. const /** @type {?} */ compMeta = /** @type {?} */ ((this._metadataResolver.getNonNormalizedDirectiveMetadata(dirSymbol))).metadata;
  24808. if (!compMeta.isComponent) {
  24809. return;
  24810. } /** @type {?} */
  24811. ((
  24812. // Note: compMeta is a component and therefore template is non null.
  24813. compMeta.template)).styleUrls.forEach((styleUrl) => {
  24814. const /** @type {?} */ normalizedUrl = this._host.resourceNameToFileName(styleUrl, file.fileName);
  24815. if (!normalizedUrl) {
  24816. throw syntaxError(`Couldn't resolve resource ${styleUrl} relative to ${file.fileName}`);
  24817. }
  24818. const /** @type {?} */ needsShim = (/** @type {?} */ ((compMeta.template)).encapsulation || this._config.defaultEncapsulation) === ViewEncapsulation.Emulated;
  24819. genFileNames.push(_stylesModuleUrl(normalizedUrl, needsShim, fileSuffix));
  24820. if (this._options.allowEmptyCodegenFiles) {
  24821. genFileNames.push(_stylesModuleUrl(normalizedUrl, !needsShim, fileSuffix));
  24822. }
  24823. });
  24824. });
  24825. return genFileNames;
  24826. }
  24827. /**
  24828. * @param {?} genFileName
  24829. * @param {?=} originalFileName
  24830. * @return {?}
  24831. */
  24832. emitBasicStub(genFileName, originalFileName) {
  24833. const /** @type {?} */ outputCtx = this._createOutputContext(genFileName);
  24834. if (genFileName.endsWith('.ngfactory.ts')) {
  24835. if (!originalFileName) {
  24836. throw new Error(`Assertion error: require the original file for .ngfactory.ts stubs. File: ${genFileName}`);
  24837. }
  24838. const /** @type {?} */ originalFile = this._analyzeFile(originalFileName);
  24839. this._createNgFactoryStub(outputCtx, originalFile, StubEmitFlags.Basic);
  24840. }
  24841. else if (genFileName.endsWith('.ngsummary.ts')) {
  24842. if (this._options.enableSummariesForJit) {
  24843. if (!originalFileName) {
  24844. throw new Error(`Assertion error: require the original file for .ngsummary.ts stubs. File: ${genFileName}`);
  24845. }
  24846. const /** @type {?} */ originalFile = this._analyzeFile(originalFileName);
  24847. _createEmptyStub(outputCtx);
  24848. originalFile.ngModules.forEach(ngModule => {
  24849. // create exports that user code can reference
  24850. createForJitStub(outputCtx, ngModule.type.reference);
  24851. });
  24852. }
  24853. }
  24854. else if (genFileName.endsWith('.ngstyle.ts')) {
  24855. _createEmptyStub(outputCtx);
  24856. }
  24857. // Note: for the stubs, we don't need a property srcFileUrl,
  24858. // as lateron in emitAllImpls we will create the proper GeneratedFiles with the
  24859. // correct srcFileUrl.
  24860. // This is good as e.g. for .ngstyle.ts files we can't derive
  24861. // the url of components based on the genFileUrl.
  24862. return this._codegenSourceModule('unknown', outputCtx);
  24863. }
  24864. /**
  24865. * @param {?} genFileName
  24866. * @param {?} originalFileName
  24867. * @return {?}
  24868. */
  24869. emitTypeCheckStub(genFileName, originalFileName) {
  24870. const /** @type {?} */ originalFile = this._analyzeFile(originalFileName);
  24871. const /** @type {?} */ outputCtx = this._createOutputContext(genFileName);
  24872. if (genFileName.endsWith('.ngfactory.ts')) {
  24873. this._createNgFactoryStub(outputCtx, originalFile, StubEmitFlags.TypeCheck);
  24874. }
  24875. return outputCtx.statements.length > 0 ?
  24876. this._codegenSourceModule(originalFile.fileName, outputCtx) :
  24877. null;
  24878. }
  24879. /**
  24880. * @param {?} fileNames
  24881. * @return {?}
  24882. */
  24883. loadFilesAsync(fileNames) {
  24884. const /** @type {?} */ files = fileNames.map(fileName => this._analyzeFile(fileName));
  24885. const /** @type {?} */ loadingPromises = [];
  24886. files.forEach(file => file.ngModules.forEach(ngModule => loadingPromises.push(this._metadataResolver.loadNgModuleDirectiveAndPipeMetadata(ngModule.type.reference, false))));
  24887. return Promise.all(loadingPromises).then(_ => mergeAndValidateNgFiles(files));
  24888. }
  24889. /**
  24890. * @param {?} fileNames
  24891. * @return {?}
  24892. */
  24893. loadFilesSync(fileNames) {
  24894. const /** @type {?} */ files = fileNames.map(fileName => this._analyzeFile(fileName));
  24895. files.forEach(file => file.ngModules.forEach(ngModule => this._metadataResolver.loadNgModuleDirectiveAndPipeMetadata(ngModule.type.reference, true)));
  24896. return mergeAndValidateNgFiles(files);
  24897. }
  24898. /**
  24899. * @param {?} outputCtx
  24900. * @param {?} file
  24901. * @param {?} emitFlags
  24902. * @return {?}
  24903. */
  24904. _createNgFactoryStub(outputCtx, file, emitFlags) {
  24905. let /** @type {?} */ componentId = 0;
  24906. file.ngModules.forEach((ngModuleMeta, ngModuleIndex) => {
  24907. // Note: the code below needs to executed for StubEmitFlags.Basic and StubEmitFlags.TypeCheck,
  24908. // so we don't change the .ngfactory file too much when adding the typecheck block.
  24909. // create exports that user code can reference
  24910. this._ngModuleCompiler.createStub(outputCtx, ngModuleMeta.type.reference);
  24911. // add references to the symbols from the metadata.
  24912. // These can be used by the type check block for components,
  24913. // and they also cause TypeScript to include these files into the program too,
  24914. // which will make them part of the analyzedFiles.
  24915. const /** @type {?} */ externalReferences = [
  24916. // Add references that are available from all the modules and imports.
  24917. ...ngModuleMeta.transitiveModule.directives.map(d => d.reference),
  24918. ...ngModuleMeta.transitiveModule.pipes.map(d => d.reference),
  24919. ...ngModuleMeta.importedModules.map(m => m.type.reference),
  24920. ...ngModuleMeta.exportedModules.map(m => m.type.reference),
  24921. // Add references that might be inserted by the template compiler.
  24922. ...this._externalIdentifierReferences([Identifiers.TemplateRef, Identifiers.ElementRef]),
  24923. ];
  24924. const /** @type {?} */ externalReferenceVars = new Map();
  24925. externalReferences.forEach((ref, typeIndex) => {
  24926. externalReferenceVars.set(ref, `_decl${ngModuleIndex}_${typeIndex}`);
  24927. });
  24928. externalReferenceVars.forEach((varName, reference) => {
  24929. outputCtx.statements.push(variable(varName)
  24930. .set(NULL_EXPR.cast(DYNAMIC_TYPE))
  24931. .toDeclStmt(expressionType(outputCtx.importExpr(reference, /* typeParams */ null, /* useSummaries */ /* useSummaries */ false))));
  24932. });
  24933. if (emitFlags & StubEmitFlags.TypeCheck) {
  24934. // add the typecheck block for all components of the NgModule
  24935. ngModuleMeta.declaredDirectives.forEach((dirId) => {
  24936. const /** @type {?} */ compMeta = this._metadataResolver.getDirectiveMetadata(dirId.reference);
  24937. if (!compMeta.isComponent) {
  24938. return;
  24939. }
  24940. componentId++;
  24941. this._createTypeCheckBlock(outputCtx, `${compMeta.type.reference.name}_Host_${componentId}`, ngModuleMeta, this._metadataResolver.getHostComponentMetadata(compMeta), [compMeta.type], externalReferenceVars);
  24942. this._createTypeCheckBlock(outputCtx, `${compMeta.type.reference.name}_${componentId}`, ngModuleMeta, compMeta, ngModuleMeta.transitiveModule.directives, externalReferenceVars);
  24943. });
  24944. }
  24945. });
  24946. if (outputCtx.statements.length === 0) {
  24947. _createEmptyStub(outputCtx);
  24948. }
  24949. }
  24950. /**
  24951. * @param {?} references
  24952. * @return {?}
  24953. */
  24954. _externalIdentifierReferences(references) {
  24955. const /** @type {?} */ result = [];
  24956. for (let /** @type {?} */ reference of references) {
  24957. const /** @type {?} */ token = createTokenForExternalReference(this._reflector, reference);
  24958. if (token.identifier) {
  24959. result.push(token.identifier.reference);
  24960. }
  24961. }
  24962. return result;
  24963. }
  24964. /**
  24965. * @param {?} ctx
  24966. * @param {?} componentId
  24967. * @param {?} moduleMeta
  24968. * @param {?} compMeta
  24969. * @param {?} directives
  24970. * @param {?} externalReferenceVars
  24971. * @return {?}
  24972. */
  24973. _createTypeCheckBlock(ctx, componentId, moduleMeta, compMeta, directives, externalReferenceVars) {
  24974. const { template: parsedTemplate, pipes: usedPipes } = this._parseTemplate(compMeta, moduleMeta, directives);
  24975. ctx.statements.push(...this._typeCheckCompiler.compileComponent(componentId, compMeta, parsedTemplate, usedPipes, externalReferenceVars, ctx));
  24976. }
  24977. /**
  24978. * @param {?} analyzeResult
  24979. * @param {?} locale
  24980. * @return {?}
  24981. */
  24982. emitMessageBundle(analyzeResult, locale) {
  24983. const /** @type {?} */ errors = [];
  24984. const /** @type {?} */ htmlParser = new HtmlParser();
  24985. // TODO(vicb): implicit tags & attributes
  24986. const /** @type {?} */ messageBundle = new MessageBundle(htmlParser, [], {}, locale);
  24987. analyzeResult.files.forEach(file => {
  24988. const /** @type {?} */ compMetas = [];
  24989. file.directives.forEach(directiveType => {
  24990. const /** @type {?} */ dirMeta = this._metadataResolver.getDirectiveMetadata(directiveType);
  24991. if (dirMeta && dirMeta.isComponent) {
  24992. compMetas.push(dirMeta);
  24993. }
  24994. });
  24995. compMetas.forEach(compMeta => {
  24996. const /** @type {?} */ html = /** @type {?} */ ((/** @type {?} */ ((compMeta.template)).template));
  24997. const /** @type {?} */ interpolationConfig = InterpolationConfig.fromArray(/** @type {?} */ ((compMeta.template)).interpolation);
  24998. errors.push(.../** @type {?} */ ((messageBundle.updateFromTemplate(html, file.fileName, interpolationConfig))));
  24999. });
  25000. });
  25001. if (errors.length) {
  25002. throw new Error(errors.map(e => e.toString()).join('\n'));
  25003. }
  25004. return messageBundle;
  25005. }
  25006. /**
  25007. * @param {?} analyzeResult
  25008. * @return {?}
  25009. */
  25010. emitAllImpls(analyzeResult) {
  25011. const { ngModuleByPipeOrDirective, files } = analyzeResult;
  25012. const /** @type {?} */ sourceModules = files.map(file => this._compileImplFile(file.fileName, ngModuleByPipeOrDirective, file.directives, file.pipes, file.ngModules, file.injectables));
  25013. return flatten(sourceModules);
  25014. }
  25015. /**
  25016. * @param {?} srcFileUrl
  25017. * @param {?} ngModuleByPipeOrDirective
  25018. * @param {?} directives
  25019. * @param {?} pipes
  25020. * @param {?} ngModules
  25021. * @param {?} injectables
  25022. * @return {?}
  25023. */
  25024. _compileImplFile(srcFileUrl, ngModuleByPipeOrDirective, directives, pipes, ngModules, injectables) {
  25025. const /** @type {?} */ fileSuffix = normalizeGenFileSuffix(splitTypescriptSuffix(srcFileUrl, true)[1]);
  25026. const /** @type {?} */ generatedFiles = [];
  25027. const /** @type {?} */ outputCtx = this._createOutputContext(ngfactoryFilePath(srcFileUrl, true));
  25028. generatedFiles.push(...this._createSummary(srcFileUrl, directives, pipes, ngModules, injectables, outputCtx));
  25029. // compile all ng modules
  25030. ngModules.forEach((ngModuleMeta) => this._compileModule(outputCtx, ngModuleMeta));
  25031. // compile components
  25032. directives.forEach((dirType) => {
  25033. const /** @type {?} */ compMeta = this._metadataResolver.getDirectiveMetadata(/** @type {?} */ (dirType));
  25034. if (!compMeta.isComponent) {
  25035. return;
  25036. }
  25037. const /** @type {?} */ ngModule = ngModuleByPipeOrDirective.get(dirType);
  25038. if (!ngModule) {
  25039. throw new Error(`Internal Error: cannot determine the module for component ${identifierName(compMeta.type)}!`);
  25040. }
  25041. // compile styles
  25042. const /** @type {?} */ componentStylesheet = this._styleCompiler.compileComponent(outputCtx, compMeta); /** @type {?} */
  25043. ((
  25044. // Note: compMeta is a component and therefore template is non null.
  25045. compMeta.template)).externalStylesheets.forEach((stylesheetMeta) => {
  25046. // Note: fill non shim and shim style files as they might
  25047. // be shared by component with and without ViewEncapsulation.
  25048. const /** @type {?} */ shim = this._styleCompiler.needsStyleShim(compMeta);
  25049. generatedFiles.push(this._codegenStyles(srcFileUrl, compMeta, stylesheetMeta, shim, fileSuffix));
  25050. if (this._options.allowEmptyCodegenFiles) {
  25051. generatedFiles.push(this._codegenStyles(srcFileUrl, compMeta, stylesheetMeta, !shim, fileSuffix));
  25052. }
  25053. });
  25054. // compile components
  25055. const /** @type {?} */ compViewVars = this._compileComponent(outputCtx, compMeta, ngModule, ngModule.transitiveModule.directives, componentStylesheet, fileSuffix);
  25056. this._compileComponentFactory(outputCtx, compMeta, ngModule, fileSuffix);
  25057. });
  25058. if (outputCtx.statements.length > 0 || this._options.allowEmptyCodegenFiles) {
  25059. const /** @type {?} */ srcModule = this._codegenSourceModule(srcFileUrl, outputCtx);
  25060. generatedFiles.unshift(srcModule);
  25061. }
  25062. return generatedFiles;
  25063. }
  25064. /**
  25065. * @param {?} srcFileName
  25066. * @param {?} directives
  25067. * @param {?} pipes
  25068. * @param {?} ngModules
  25069. * @param {?} injectables
  25070. * @param {?} ngFactoryCtx
  25071. * @return {?}
  25072. */
  25073. _createSummary(srcFileName, directives, pipes, ngModules, injectables, ngFactoryCtx) {
  25074. const /** @type {?} */ symbolSummaries = this._symbolResolver.getSymbolsOf(srcFileName)
  25075. .map(symbol => this._symbolResolver.resolveSymbol(symbol));
  25076. const /** @type {?} */ typeData = [
  25077. ...ngModules.map(meta => ({
  25078. summary: /** @type {?} */ ((this._metadataResolver.getNgModuleSummary(meta.type.reference))),
  25079. metadata: /** @type {?} */ ((this._metadataResolver.getNgModuleMetadata(meta.type.reference)))
  25080. })),
  25081. ...directives.map(ref => ({
  25082. summary: /** @type {?} */ ((this._metadataResolver.getDirectiveSummary(ref))),
  25083. metadata: /** @type {?} */ ((this._metadataResolver.getDirectiveMetadata(ref)))
  25084. })),
  25085. ...pipes.map(ref => ({
  25086. summary: /** @type {?} */ ((this._metadataResolver.getPipeSummary(ref))),
  25087. metadata: /** @type {?} */ ((this._metadataResolver.getPipeMetadata(ref)))
  25088. })),
  25089. ...injectables.map(ref => ({
  25090. summary: /** @type {?} */ ((this._metadataResolver.getInjectableSummary(ref))),
  25091. metadata: /** @type {?} */ ((this._metadataResolver.getInjectableSummary(ref))).type
  25092. }))
  25093. ];
  25094. const /** @type {?} */ forJitOutputCtx = this._options.enableSummariesForJit ?
  25095. this._createOutputContext(summaryForJitFileName(srcFileName, true)) :
  25096. null;
  25097. const { json, exportAs } = serializeSummaries(srcFileName, forJitOutputCtx, this._summaryResolver, this._symbolResolver, symbolSummaries, typeData);
  25098. exportAs.forEach((entry) => {
  25099. ngFactoryCtx.statements.push(variable(entry.exportAs).set(ngFactoryCtx.importExpr(entry.symbol)).toDeclStmt(null, [
  25100. StmtModifier.Exported
  25101. ]));
  25102. });
  25103. const /** @type {?} */ summaryJson = new GeneratedFile(srcFileName, summaryFileName(srcFileName), json);
  25104. const /** @type {?} */ result = [summaryJson];
  25105. if (forJitOutputCtx) {
  25106. result.push(this._codegenSourceModule(srcFileName, forJitOutputCtx));
  25107. }
  25108. return result;
  25109. }
  25110. /**
  25111. * @param {?} outputCtx
  25112. * @param {?} ngModule
  25113. * @return {?}
  25114. */
  25115. _compileModule(outputCtx, ngModule) {
  25116. const /** @type {?} */ providers = [];
  25117. if (this._options.locale) {
  25118. const /** @type {?} */ normalizedLocale = this._options.locale.replace(/_/g, '-');
  25119. providers.push({
  25120. token: createTokenForExternalReference(this._reflector, Identifiers.LOCALE_ID),
  25121. useValue: normalizedLocale,
  25122. });
  25123. }
  25124. if (this._options.i18nFormat) {
  25125. providers.push({
  25126. token: createTokenForExternalReference(this._reflector, Identifiers.TRANSLATIONS_FORMAT),
  25127. useValue: this._options.i18nFormat
  25128. });
  25129. }
  25130. this._ngModuleCompiler.compile(outputCtx, ngModule, providers);
  25131. }
  25132. /**
  25133. * @param {?} outputCtx
  25134. * @param {?} compMeta
  25135. * @param {?} ngModule
  25136. * @param {?} fileSuffix
  25137. * @return {?}
  25138. */
  25139. _compileComponentFactory(outputCtx, compMeta, ngModule, fileSuffix) {
  25140. const /** @type {?} */ hostMeta = this._metadataResolver.getHostComponentMetadata(compMeta);
  25141. const /** @type {?} */ hostViewFactoryVar = this._compileComponent(outputCtx, hostMeta, ngModule, [compMeta.type], null, fileSuffix)
  25142. .viewClassVar;
  25143. const /** @type {?} */ compFactoryVar = componentFactoryName(compMeta.type.reference);
  25144. const /** @type {?} */ inputsExprs = [];
  25145. for (let /** @type {?} */ propName in compMeta.inputs) {
  25146. const /** @type {?} */ templateName = compMeta.inputs[propName];
  25147. // Don't quote so that the key gets minified...
  25148. inputsExprs.push(new LiteralMapEntry(propName, literal(templateName), false));
  25149. }
  25150. const /** @type {?} */ outputsExprs = [];
  25151. for (let /** @type {?} */ propName in compMeta.outputs) {
  25152. const /** @type {?} */ templateName = compMeta.outputs[propName];
  25153. // Don't quote so that the key gets minified...
  25154. outputsExprs.push(new LiteralMapEntry(propName, literal(templateName), false));
  25155. }
  25156. outputCtx.statements.push(variable(compFactoryVar)
  25157. .set(importExpr(Identifiers.createComponentFactory).callFn([
  25158. literal(compMeta.selector), outputCtx.importExpr(compMeta.type.reference),
  25159. variable(hostViewFactoryVar), new LiteralMapExpr(inputsExprs),
  25160. new LiteralMapExpr(outputsExprs),
  25161. literalArr(/** @type {?} */ ((compMeta.template)).ngContentSelectors.map(selector => literal(selector)))
  25162. ]))
  25163. .toDeclStmt(importType(Identifiers.ComponentFactory, [/** @type {?} */ ((expressionType(outputCtx.importExpr(compMeta.type.reference))))], [TypeModifier.Const]), [StmtModifier.Final, StmtModifier.Exported]));
  25164. }
  25165. /**
  25166. * @param {?} outputCtx
  25167. * @param {?} compMeta
  25168. * @param {?} ngModule
  25169. * @param {?} directiveIdentifiers
  25170. * @param {?} componentStyles
  25171. * @param {?} fileSuffix
  25172. * @return {?}
  25173. */
  25174. _compileComponent(outputCtx, compMeta, ngModule, directiveIdentifiers, componentStyles, fileSuffix) {
  25175. const { template: parsedTemplate, pipes: usedPipes } = this._parseTemplate(compMeta, ngModule, directiveIdentifiers);
  25176. const /** @type {?} */ stylesExpr = componentStyles ? variable(componentStyles.stylesVar) : literalArr([]);
  25177. const /** @type {?} */ viewResult = this._viewCompiler.compileComponent(outputCtx, compMeta, parsedTemplate, stylesExpr, usedPipes);
  25178. if (componentStyles) {
  25179. _resolveStyleStatements(this._symbolResolver, componentStyles, this._styleCompiler.needsStyleShim(compMeta), fileSuffix);
  25180. }
  25181. return viewResult;
  25182. }
  25183. /**
  25184. * @param {?} compMeta
  25185. * @param {?} ngModule
  25186. * @param {?} directiveIdentifiers
  25187. * @return {?}
  25188. */
  25189. _parseTemplate(compMeta, ngModule, directiveIdentifiers) {
  25190. if (this._templateAstCache.has(compMeta.type.reference)) {
  25191. return /** @type {?} */ ((this._templateAstCache.get(compMeta.type.reference)));
  25192. }
  25193. const /** @type {?} */ preserveWhitespaces = /** @type {?} */ ((/** @type {?} */ ((compMeta)).template)).preserveWhitespaces;
  25194. const /** @type {?} */ directives = directiveIdentifiers.map(dir => this._metadataResolver.getDirectiveSummary(dir.reference));
  25195. const /** @type {?} */ pipes = ngModule.transitiveModule.pipes.map(pipe => this._metadataResolver.getPipeSummary(pipe.reference));
  25196. const /** @type {?} */ result = this._templateParser.parse(compMeta, /** @type {?} */ ((/** @type {?} */ ((compMeta.template)).htmlAst)), directives, pipes, ngModule.schemas, templateSourceUrl(ngModule.type, compMeta, /** @type {?} */ ((compMeta.template))), preserveWhitespaces);
  25197. this._templateAstCache.set(compMeta.type.reference, result);
  25198. return result;
  25199. }
  25200. /**
  25201. * @param {?} genFilePath
  25202. * @return {?}
  25203. */
  25204. _createOutputContext(genFilePath) {
  25205. const /** @type {?} */ importExpr$$1 = (symbol, typeParams = null, useSummaries = true) => {
  25206. if (!(symbol instanceof StaticSymbol)) {
  25207. throw new Error(`Internal error: unknown identifier ${JSON.stringify(symbol)}`);
  25208. }
  25209. const /** @type {?} */ arity = this._symbolResolver.getTypeArity(symbol) || 0;
  25210. const { filePath, name, members } = this._symbolResolver.getImportAs(symbol, useSummaries) || symbol;
  25211. const /** @type {?} */ importModule = this._fileNameToModuleName(filePath, genFilePath);
  25212. // It should be good enough to compare filePath to genFilePath and if they are equal
  25213. // there is a self reference. However, ngfactory files generate to .ts but their
  25214. // symbols have .d.ts so a simple compare is insufficient. They should be canonical
  25215. // and is tracked by #17705.
  25216. const /** @type {?} */ selfReference = this._fileNameToModuleName(genFilePath, genFilePath);
  25217. const /** @type {?} */ moduleName = importModule === selfReference ? null : importModule;
  25218. // If we are in a type expression that refers to a generic type then supply
  25219. // the required type parameters. If there were not enough type parameters
  25220. // supplied, supply any as the type. Outside a type expression the reference
  25221. // should not supply type parameters and be treated as a simple value reference
  25222. // to the constructor function itself.
  25223. const /** @type {?} */ suppliedTypeParams = typeParams || [];
  25224. const /** @type {?} */ missingTypeParamsCount = arity - suppliedTypeParams.length;
  25225. const /** @type {?} */ allTypeParams = suppliedTypeParams.concat(new Array(missingTypeParamsCount).fill(DYNAMIC_TYPE));
  25226. return members.reduce((expr, memberName) => expr.prop(memberName), /** @type {?} */ (importExpr(new ExternalReference(moduleName, name, null), allTypeParams)));
  25227. };
  25228. return { statements: [], genFilePath, importExpr: importExpr$$1 };
  25229. }
  25230. /**
  25231. * @param {?} importedFilePath
  25232. * @param {?} containingFilePath
  25233. * @return {?}
  25234. */
  25235. _fileNameToModuleName(importedFilePath, containingFilePath) {
  25236. return this._summaryResolver.getKnownModuleName(importedFilePath) ||
  25237. this._symbolResolver.getKnownModuleName(importedFilePath) ||
  25238. this._host.fileNameToModuleName(importedFilePath, containingFilePath);
  25239. }
  25240. /**
  25241. * @param {?} srcFileUrl
  25242. * @param {?} compMeta
  25243. * @param {?} stylesheetMetadata
  25244. * @param {?} isShimmed
  25245. * @param {?} fileSuffix
  25246. * @return {?}
  25247. */
  25248. _codegenStyles(srcFileUrl, compMeta, stylesheetMetadata, isShimmed, fileSuffix) {
  25249. const /** @type {?} */ outputCtx = this._createOutputContext(_stylesModuleUrl(/** @type {?} */ ((stylesheetMetadata.moduleUrl)), isShimmed, fileSuffix));
  25250. const /** @type {?} */ compiledStylesheet = this._styleCompiler.compileStyles(outputCtx, compMeta, stylesheetMetadata, isShimmed);
  25251. _resolveStyleStatements(this._symbolResolver, compiledStylesheet, isShimmed, fileSuffix);
  25252. return this._codegenSourceModule(srcFileUrl, outputCtx);
  25253. }
  25254. /**
  25255. * @param {?} srcFileUrl
  25256. * @param {?} ctx
  25257. * @return {?}
  25258. */
  25259. _codegenSourceModule(srcFileUrl, ctx) {
  25260. return new GeneratedFile(srcFileUrl, ctx.genFilePath, ctx.statements);
  25261. }
  25262. /**
  25263. * @param {?=} entryRoute
  25264. * @param {?=} analyzedModules
  25265. * @return {?}
  25266. */
  25267. listLazyRoutes(entryRoute, analyzedModules) {
  25268. const /** @type {?} */ self = this;
  25269. if (entryRoute) {
  25270. const /** @type {?} */ symbol = parseLazyRoute(entryRoute, this._reflector).referencedModule;
  25271. return visitLazyRoute(symbol);
  25272. }
  25273. else if (analyzedModules) {
  25274. const /** @type {?} */ allLazyRoutes = [];
  25275. for (const /** @type {?} */ ngModule of analyzedModules.ngModules) {
  25276. const /** @type {?} */ lazyRoutes = listLazyRoutes(ngModule, this._reflector);
  25277. for (const /** @type {?} */ lazyRoute of lazyRoutes) {
  25278. allLazyRoutes.push(lazyRoute);
  25279. }
  25280. }
  25281. return allLazyRoutes;
  25282. }
  25283. else {
  25284. throw new Error(`Either route or analyzedModules has to be specified!`);
  25285. }
  25286. /**
  25287. * @param {?} symbol
  25288. * @param {?=} seenRoutes
  25289. * @param {?=} allLazyRoutes
  25290. * @return {?}
  25291. */
  25292. function visitLazyRoute(symbol, seenRoutes = new Set(), allLazyRoutes = []) {
  25293. // Support pointing to default exports, but stop recursing there,
  25294. // as the StaticReflector does not yet support default exports.
  25295. if (seenRoutes.has(symbol) || !symbol.name) {
  25296. return allLazyRoutes;
  25297. }
  25298. seenRoutes.add(symbol);
  25299. const /** @type {?} */ lazyRoutes = listLazyRoutes(/** @type {?} */ ((self._metadataResolver.getNgModuleMetadata(symbol, true))), self._reflector);
  25300. for (const /** @type {?} */ lazyRoute of lazyRoutes) {
  25301. allLazyRoutes.push(lazyRoute);
  25302. visitLazyRoute(lazyRoute.referencedModule, seenRoutes, allLazyRoutes);
  25303. }
  25304. return allLazyRoutes;
  25305. }
  25306. }
  25307. }
  25308. /**
  25309. * @param {?} outputCtx
  25310. * @return {?}
  25311. */
  25312. function _createEmptyStub(outputCtx) {
  25313. // Note: We need to produce at least one import statement so that
  25314. // TypeScript knows that the file is an es6 module. Otherwise our generated
  25315. // exports / imports won't be emitted properly by TypeScript.
  25316. outputCtx.statements.push(importExpr(Identifiers.ComponentFactory).toStmt());
  25317. }
  25318. /**
  25319. * @param {?} symbolResolver
  25320. * @param {?} compileResult
  25321. * @param {?} needsShim
  25322. * @param {?} fileSuffix
  25323. * @return {?}
  25324. */
  25325. function _resolveStyleStatements(symbolResolver, compileResult, needsShim, fileSuffix) {
  25326. compileResult.dependencies.forEach((dep) => {
  25327. dep.setValue(symbolResolver.getStaticSymbol(_stylesModuleUrl(dep.moduleUrl, needsShim, fileSuffix), dep.name));
  25328. });
  25329. }
  25330. /**
  25331. * @param {?} stylesheetUrl
  25332. * @param {?} shim
  25333. * @param {?} suffix
  25334. * @return {?}
  25335. */
  25336. function _stylesModuleUrl(stylesheetUrl, shim, suffix) {
  25337. return `${stylesheetUrl}${shim ? '.shim' : ''}.ngstyle${suffix}`;
  25338. }
  25339. /**
  25340. * @record
  25341. */
  25342. /**
  25343. * @record
  25344. */
  25345. /**
  25346. * @record
  25347. */
  25348. /**
  25349. * @param {?} fileNames
  25350. * @param {?} host
  25351. * @param {?} staticSymbolResolver
  25352. * @param {?} metadataResolver
  25353. * @return {?}
  25354. */
  25355. function analyzeNgModules(fileNames, host, staticSymbolResolver, metadataResolver) {
  25356. const /** @type {?} */ files = _analyzeFilesIncludingNonProgramFiles(fileNames, host, staticSymbolResolver, metadataResolver);
  25357. return mergeAnalyzedFiles(files);
  25358. }
  25359. /**
  25360. * @param {?} fileNames
  25361. * @param {?} host
  25362. * @param {?} staticSymbolResolver
  25363. * @param {?} metadataResolver
  25364. * @return {?}
  25365. */
  25366. function analyzeAndValidateNgModules(fileNames, host, staticSymbolResolver, metadataResolver) {
  25367. return validateAnalyzedModules(analyzeNgModules(fileNames, host, staticSymbolResolver, metadataResolver));
  25368. }
  25369. /**
  25370. * @param {?} analyzedModules
  25371. * @return {?}
  25372. */
  25373. function validateAnalyzedModules(analyzedModules) {
  25374. if (analyzedModules.symbolsMissingModule && analyzedModules.symbolsMissingModule.length) {
  25375. const /** @type {?} */ messages = analyzedModules.symbolsMissingModule.map(s => `Cannot determine the module for class ${s.name} in ${s.filePath}! Add ${s.name} to the NgModule to fix it.`);
  25376. throw syntaxError(messages.join('\n'));
  25377. }
  25378. return analyzedModules;
  25379. }
  25380. /**
  25381. * @param {?} fileNames
  25382. * @param {?} host
  25383. * @param {?} staticSymbolResolver
  25384. * @param {?} metadataResolver
  25385. * @return {?}
  25386. */
  25387. function _analyzeFilesIncludingNonProgramFiles(fileNames, host, staticSymbolResolver, metadataResolver) {
  25388. const /** @type {?} */ seenFiles = new Set();
  25389. const /** @type {?} */ files = [];
  25390. const /** @type {?} */ visitFile = (fileName) => {
  25391. if (seenFiles.has(fileName) || !host.isSourceFile(fileName)) {
  25392. return false;
  25393. }
  25394. seenFiles.add(fileName);
  25395. const /** @type {?} */ analyzedFile = analyzeFile(host, staticSymbolResolver, metadataResolver, fileName);
  25396. files.push(analyzedFile);
  25397. analyzedFile.ngModules.forEach(ngModule => {
  25398. ngModule.transitiveModule.modules.forEach(modMeta => visitFile(modMeta.reference.filePath));
  25399. });
  25400. };
  25401. fileNames.forEach((fileName) => visitFile(fileName));
  25402. return files;
  25403. }
  25404. /**
  25405. * @param {?} host
  25406. * @param {?} staticSymbolResolver
  25407. * @param {?} metadataResolver
  25408. * @param {?} fileName
  25409. * @return {?}
  25410. */
  25411. function analyzeFile(host, staticSymbolResolver, metadataResolver, fileName) {
  25412. const /** @type {?} */ directives = [];
  25413. const /** @type {?} */ pipes = [];
  25414. const /** @type {?} */ injectables = [];
  25415. const /** @type {?} */ ngModules = [];
  25416. const /** @type {?} */ hasDecorators = staticSymbolResolver.hasDecorators(fileName);
  25417. let /** @type {?} */ exportsNonSourceFiles = false;
  25418. // Don't analyze .d.ts files that have no decorators as a shortcut
  25419. // to speed up the analysis. This prevents us from
  25420. // resolving the references in these files.
  25421. // Note: exportsNonSourceFiles is only needed when compiling with summaries,
  25422. // which is not the case when .d.ts files are treated as input files.
  25423. if (!fileName.endsWith('.d.ts') || hasDecorators) {
  25424. staticSymbolResolver.getSymbolsOf(fileName).forEach((symbol) => {
  25425. const /** @type {?} */ resolvedSymbol = staticSymbolResolver.resolveSymbol(symbol);
  25426. const /** @type {?} */ symbolMeta = resolvedSymbol.metadata;
  25427. if (!symbolMeta || symbolMeta.__symbolic === 'error') {
  25428. return;
  25429. }
  25430. let /** @type {?} */ isNgSymbol = false;
  25431. if (symbolMeta.__symbolic === 'class') {
  25432. if (metadataResolver.isDirective(symbol)) {
  25433. isNgSymbol = true;
  25434. directives.push(symbol);
  25435. }
  25436. else if (metadataResolver.isPipe(symbol)) {
  25437. isNgSymbol = true;
  25438. pipes.push(symbol);
  25439. }
  25440. else if (metadataResolver.isNgModule(symbol)) {
  25441. const /** @type {?} */ ngModule = metadataResolver.getNgModuleMetadata(symbol, false);
  25442. if (ngModule) {
  25443. isNgSymbol = true;
  25444. ngModules.push(ngModule);
  25445. }
  25446. }
  25447. else if (metadataResolver.isInjectable(symbol)) {
  25448. isNgSymbol = true;
  25449. injectables.push(symbol);
  25450. }
  25451. }
  25452. if (!isNgSymbol) {
  25453. exportsNonSourceFiles =
  25454. exportsNonSourceFiles || isValueExportingNonSourceFile(host, symbolMeta);
  25455. }
  25456. });
  25457. }
  25458. return {
  25459. fileName, directives, pipes, ngModules, injectables, exportsNonSourceFiles,
  25460. };
  25461. }
  25462. /**
  25463. * @param {?} host
  25464. * @param {?} metadata
  25465. * @return {?}
  25466. */
  25467. function isValueExportingNonSourceFile(host, metadata) {
  25468. let /** @type {?} */ exportsNonSourceFiles = false;
  25469. class Visitor {
  25470. /**
  25471. * @param {?} arr
  25472. * @param {?} context
  25473. * @return {?}
  25474. */
  25475. visitArray(arr, context) { arr.forEach(v => visitValue(v, this, context)); }
  25476. /**
  25477. * @param {?} map
  25478. * @param {?} context
  25479. * @return {?}
  25480. */
  25481. visitStringMap(map, context) {
  25482. Object.keys(map).forEach((key) => visitValue(map[key], this, context));
  25483. }
  25484. /**
  25485. * @param {?} value
  25486. * @param {?} context
  25487. * @return {?}
  25488. */
  25489. visitPrimitive(value, context) { }
  25490. /**
  25491. * @param {?} value
  25492. * @param {?} context
  25493. * @return {?}
  25494. */
  25495. visitOther(value, context) {
  25496. if (value instanceof StaticSymbol && !host.isSourceFile(value.filePath)) {
  25497. exportsNonSourceFiles = true;
  25498. }
  25499. }
  25500. }
  25501. visitValue(metadata, new Visitor(), null);
  25502. return exportsNonSourceFiles;
  25503. }
  25504. /**
  25505. * @param {?} analyzedFiles
  25506. * @return {?}
  25507. */
  25508. function mergeAnalyzedFiles(analyzedFiles) {
  25509. const /** @type {?} */ allNgModules = [];
  25510. const /** @type {?} */ ngModuleByPipeOrDirective = new Map();
  25511. const /** @type {?} */ allPipesAndDirectives = new Set();
  25512. analyzedFiles.forEach(af => {
  25513. af.ngModules.forEach(ngModule => {
  25514. allNgModules.push(ngModule);
  25515. ngModule.declaredDirectives.forEach(d => ngModuleByPipeOrDirective.set(d.reference, ngModule));
  25516. ngModule.declaredPipes.forEach(p => ngModuleByPipeOrDirective.set(p.reference, ngModule));
  25517. });
  25518. af.directives.forEach(d => allPipesAndDirectives.add(d));
  25519. af.pipes.forEach(p => allPipesAndDirectives.add(p));
  25520. });
  25521. const /** @type {?} */ symbolsMissingModule = [];
  25522. allPipesAndDirectives.forEach(ref => {
  25523. if (!ngModuleByPipeOrDirective.has(ref)) {
  25524. symbolsMissingModule.push(ref);
  25525. }
  25526. });
  25527. return {
  25528. ngModules: allNgModules,
  25529. ngModuleByPipeOrDirective,
  25530. symbolsMissingModule,
  25531. files: analyzedFiles
  25532. };
  25533. }
  25534. /**
  25535. * @param {?} files
  25536. * @return {?}
  25537. */
  25538. function mergeAndValidateNgFiles(files) {
  25539. return validateAnalyzedModules(mergeAnalyzedFiles(files));
  25540. }
  25541. /**
  25542. * @fileoverview added by tsickle
  25543. * @suppress {checkTypes} checked by tsc
  25544. */
  25545. /**
  25546. * @license
  25547. * Copyright Google Inc. All Rights Reserved.
  25548. *
  25549. * Use of this source code is governed by an MIT-style license that can be
  25550. * found in the LICENSE file at https://angular.io/license
  25551. */
  25552. /**
  25553. * @record
  25554. */
  25555. /**
  25556. * @record
  25557. */
  25558. const FORMATTED_MESSAGE = 'ngFormattedMessage';
  25559. /**
  25560. * @param {?} level
  25561. * @return {?}
  25562. */
  25563. function indentStr(level) {
  25564. if (level <= 0)
  25565. return '';
  25566. if (level < 6)
  25567. return ['', ' ', ' ', ' ', ' ', ' '][level];
  25568. const /** @type {?} */ half = indentStr(Math.floor(level / 2));
  25569. return half + half + (level % 2 === 1 ? ' ' : '');
  25570. }
  25571. /**
  25572. * @param {?} chain
  25573. * @param {?=} indent
  25574. * @return {?}
  25575. */
  25576. function formatChain(chain, indent = 0) {
  25577. if (!chain)
  25578. return '';
  25579. const /** @type {?} */ position = chain.position ?
  25580. `${chain.position.fileName}(${chain.position.line + 1},${chain.position.column + 1})` :
  25581. '';
  25582. const /** @type {?} */ prefix = position && indent === 0 ? `${position}: ` : '';
  25583. const /** @type {?} */ postfix = position && indent !== 0 ? ` at ${position}` : '';
  25584. const /** @type {?} */ message = `${prefix}${chain.message}${postfix}`;
  25585. return `${indentStr(indent)}${message}${(chain.next && ('\n' + formatChain(chain.next, indent + 2))) || ''}`;
  25586. }
  25587. /**
  25588. * @param {?} chain
  25589. * @return {?}
  25590. */
  25591. function formattedError(chain) {
  25592. const /** @type {?} */ message = formatChain(chain) + '.';
  25593. const /** @type {?} */ error = /** @type {?} */ (syntaxError(message));
  25594. (/** @type {?} */ (error))[FORMATTED_MESSAGE] = true;
  25595. error.chain = chain;
  25596. error.position = chain.position;
  25597. return error;
  25598. }
  25599. /**
  25600. * @param {?} error
  25601. * @return {?}
  25602. */
  25603. function isFormattedError(error) {
  25604. return !!(/** @type {?} */ (error))[FORMATTED_MESSAGE];
  25605. }
  25606. /**
  25607. * @fileoverview added by tsickle
  25608. * @suppress {checkTypes} checked by tsc
  25609. */
  25610. /**
  25611. * @license
  25612. * Copyright Google Inc. All Rights Reserved.
  25613. *
  25614. * Use of this source code is governed by an MIT-style license that can be
  25615. * found in the LICENSE file at https://angular.io/license
  25616. */
  25617. const ANGULAR_CORE = '@angular/core';
  25618. const ANGULAR_ROUTER = '@angular/router';
  25619. const HIDDEN_KEY = /^\$.*\$$/;
  25620. const IGNORE = {
  25621. __symbolic: 'ignore'
  25622. };
  25623. const USE_VALUE = 'useValue';
  25624. const PROVIDE = 'provide';
  25625. const REFERENCE_SET = new Set([USE_VALUE, 'useFactory', 'data']);
  25626. const TYPEGUARD_POSTFIX = 'TypeGuard';
  25627. const USE_IF = 'UseIf';
  25628. /**
  25629. * @param {?} value
  25630. * @return {?}
  25631. */
  25632. function shouldIgnore(value) {
  25633. return value && value.__symbolic == 'ignore';
  25634. }
  25635. /**
  25636. * A static reflector implements enough of the Reflector API that is necessary to compile
  25637. * templates statically.
  25638. */
  25639. class StaticReflector {
  25640. /**
  25641. * @param {?} summaryResolver
  25642. * @param {?} symbolResolver
  25643. * @param {?=} knownMetadataClasses
  25644. * @param {?=} knownMetadataFunctions
  25645. * @param {?=} errorRecorder
  25646. */
  25647. constructor(summaryResolver, symbolResolver, knownMetadataClasses = [], knownMetadataFunctions = [], errorRecorder) {
  25648. this.summaryResolver = summaryResolver;
  25649. this.symbolResolver = symbolResolver;
  25650. this.errorRecorder = errorRecorder;
  25651. this.annotationCache = new Map();
  25652. this.propertyCache = new Map();
  25653. this.parameterCache = new Map();
  25654. this.methodCache = new Map();
  25655. this.staticCache = new Map();
  25656. this.conversionMap = new Map();
  25657. this.resolvedExternalReferences = new Map();
  25658. this.annotationForParentClassWithSummaryKind = new Map();
  25659. this.initializeConversionMap();
  25660. knownMetadataClasses.forEach((kc) => this._registerDecoratorOrConstructor(this.getStaticSymbol(kc.filePath, kc.name), kc.ctor));
  25661. knownMetadataFunctions.forEach((kf) => this._registerFunction(this.getStaticSymbol(kf.filePath, kf.name), kf.fn));
  25662. this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.Directive, [createDirective, createComponent]);
  25663. this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.Pipe, [createPipe]);
  25664. this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.NgModule, [createNgModule]);
  25665. this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.Injectable, [createInjectable, createPipe, createDirective, createComponent, createNgModule]);
  25666. }
  25667. /**
  25668. * @param {?} typeOrFunc
  25669. * @return {?}
  25670. */
  25671. componentModuleUrl(typeOrFunc) {
  25672. const /** @type {?} */ staticSymbol = this.findSymbolDeclaration(typeOrFunc);
  25673. return this.symbolResolver.getResourcePath(staticSymbol);
  25674. }
  25675. /**
  25676. * @param {?} ref
  25677. * @param {?=} containingFile
  25678. * @return {?}
  25679. */
  25680. resolveExternalReference(ref, containingFile) {
  25681. let /** @type {?} */ key = undefined;
  25682. if (!containingFile) {
  25683. key = `${ref.moduleName}:${ref.name}`;
  25684. const /** @type {?} */ declarationSymbol = this.resolvedExternalReferences.get(key);
  25685. if (declarationSymbol)
  25686. return declarationSymbol;
  25687. }
  25688. const /** @type {?} */ refSymbol = this.symbolResolver.getSymbolByModule(/** @type {?} */ ((ref.moduleName)), /** @type {?} */ ((ref.name)), containingFile);
  25689. const /** @type {?} */ declarationSymbol = this.findSymbolDeclaration(refSymbol);
  25690. if (!containingFile) {
  25691. this.symbolResolver.recordModuleNameForFileName(refSymbol.filePath, /** @type {?} */ ((ref.moduleName)));
  25692. this.symbolResolver.recordImportAs(declarationSymbol, refSymbol);
  25693. }
  25694. if (key) {
  25695. this.resolvedExternalReferences.set(key, declarationSymbol);
  25696. }
  25697. return declarationSymbol;
  25698. }
  25699. /**
  25700. * @param {?} moduleUrl
  25701. * @param {?} name
  25702. * @param {?=} containingFile
  25703. * @return {?}
  25704. */
  25705. findDeclaration(moduleUrl, name, containingFile) {
  25706. return this.findSymbolDeclaration(this.symbolResolver.getSymbolByModule(moduleUrl, name, containingFile));
  25707. }
  25708. /**
  25709. * @param {?} moduleUrl
  25710. * @param {?} name
  25711. * @return {?}
  25712. */
  25713. tryFindDeclaration(moduleUrl, name) {
  25714. return this.symbolResolver.ignoreErrorsFor(() => this.findDeclaration(moduleUrl, name));
  25715. }
  25716. /**
  25717. * @param {?} symbol
  25718. * @return {?}
  25719. */
  25720. findSymbolDeclaration(symbol) {
  25721. const /** @type {?} */ resolvedSymbol = this.symbolResolver.resolveSymbol(symbol);
  25722. if (resolvedSymbol) {
  25723. let /** @type {?} */ resolvedMetadata = resolvedSymbol.metadata;
  25724. if (resolvedMetadata && resolvedMetadata.__symbolic === 'resolved') {
  25725. resolvedMetadata = resolvedMetadata.symbol;
  25726. }
  25727. if (resolvedMetadata instanceof StaticSymbol) {
  25728. return this.findSymbolDeclaration(resolvedSymbol.metadata);
  25729. }
  25730. }
  25731. return symbol;
  25732. }
  25733. /**
  25734. * @param {?} type
  25735. * @return {?}
  25736. */
  25737. annotations(type) {
  25738. let /** @type {?} */ annotations = this.annotationCache.get(type);
  25739. if (!annotations) {
  25740. annotations = [];
  25741. const /** @type {?} */ classMetadata = this.getTypeMetadata(type);
  25742. const /** @type {?} */ parentType = this.findParentType(type, classMetadata);
  25743. if (parentType) {
  25744. const /** @type {?} */ parentAnnotations = this.annotations(parentType);
  25745. annotations.push(...parentAnnotations);
  25746. }
  25747. let /** @type {?} */ ownAnnotations = [];
  25748. if (classMetadata['decorators']) {
  25749. ownAnnotations = this.simplify(type, classMetadata['decorators']);
  25750. annotations.push(...ownAnnotations);
  25751. }
  25752. if (parentType && !this.summaryResolver.isLibraryFile(type.filePath) &&
  25753. this.summaryResolver.isLibraryFile(parentType.filePath)) {
  25754. const /** @type {?} */ summary = this.summaryResolver.resolveSummary(parentType);
  25755. if (summary && summary.type) {
  25756. const /** @type {?} */ requiredAnnotationTypes = /** @type {?} */ ((this.annotationForParentClassWithSummaryKind.get(/** @type {?} */ ((summary.type.summaryKind)))));
  25757. const /** @type {?} */ typeHasRequiredAnnotation = requiredAnnotationTypes.some((requiredType) => ownAnnotations.some(ann => requiredType.isTypeOf(ann)));
  25758. if (!typeHasRequiredAnnotation) {
  25759. this.reportError(formatMetadataError(metadataError(`Class ${type.name} in ${type.filePath} extends from a ${CompileSummaryKind[(/** @type {?} */ ((summary.type.summaryKind)))]} in another compilation unit without duplicating the decorator`, undefined, `Please add a ${requiredAnnotationTypes.map((type) => type.ngMetadataName).join(' or ')} decorator to the class`), type), type);
  25760. }
  25761. }
  25762. }
  25763. this.annotationCache.set(type, annotations.filter(ann => !!ann));
  25764. }
  25765. return annotations;
  25766. }
  25767. /**
  25768. * @param {?} type
  25769. * @return {?}
  25770. */
  25771. propMetadata(type) {
  25772. let /** @type {?} */ propMetadata = this.propertyCache.get(type);
  25773. if (!propMetadata) {
  25774. const /** @type {?} */ classMetadata = this.getTypeMetadata(type);
  25775. propMetadata = {};
  25776. const /** @type {?} */ parentType = this.findParentType(type, classMetadata);
  25777. if (parentType) {
  25778. const /** @type {?} */ parentPropMetadata = this.propMetadata(parentType);
  25779. Object.keys(parentPropMetadata).forEach((parentProp) => {
  25780. /** @type {?} */ ((propMetadata))[parentProp] = parentPropMetadata[parentProp];
  25781. });
  25782. }
  25783. const /** @type {?} */ members = classMetadata['members'] || {};
  25784. Object.keys(members).forEach((propName) => {
  25785. const /** @type {?} */ propData = members[propName];
  25786. const /** @type {?} */ prop = (/** @type {?} */ (propData))
  25787. .find(a => a['__symbolic'] == 'property' || a['__symbolic'] == 'method');
  25788. const /** @type {?} */ decorators = [];
  25789. if (/** @type {?} */ ((propMetadata))[propName]) {
  25790. decorators.push(.../** @type {?} */ ((propMetadata))[propName]);
  25791. } /** @type {?} */
  25792. ((propMetadata))[propName] = decorators;
  25793. if (prop && prop['decorators']) {
  25794. decorators.push(...this.simplify(type, prop['decorators']));
  25795. }
  25796. });
  25797. this.propertyCache.set(type, propMetadata);
  25798. }
  25799. return propMetadata;
  25800. }
  25801. /**
  25802. * @param {?} type
  25803. * @return {?}
  25804. */
  25805. parameters(type) {
  25806. if (!(type instanceof StaticSymbol)) {
  25807. this.reportError(new Error(`parameters received ${JSON.stringify(type)} which is not a StaticSymbol`), type);
  25808. return [];
  25809. }
  25810. try {
  25811. let /** @type {?} */ parameters = this.parameterCache.get(type);
  25812. if (!parameters) {
  25813. const /** @type {?} */ classMetadata = this.getTypeMetadata(type);
  25814. const /** @type {?} */ parentType = this.findParentType(type, classMetadata);
  25815. const /** @type {?} */ members = classMetadata ? classMetadata['members'] : null;
  25816. const /** @type {?} */ ctorData = members ? members['__ctor__'] : null;
  25817. if (ctorData) {
  25818. const /** @type {?} */ ctor = (/** @type {?} */ (ctorData)).find(a => a['__symbolic'] == 'constructor');
  25819. const /** @type {?} */ rawParameterTypes = /** @type {?} */ (ctor['parameters']) || [];
  25820. const /** @type {?} */ parameterDecorators = /** @type {?} */ (this.simplify(type, ctor['parameterDecorators'] || []));
  25821. parameters = [];
  25822. rawParameterTypes.forEach((rawParamType, index) => {
  25823. const /** @type {?} */ nestedResult = [];
  25824. const /** @type {?} */ paramType = this.trySimplify(type, rawParamType);
  25825. if (paramType)
  25826. nestedResult.push(paramType);
  25827. const /** @type {?} */ decorators = parameterDecorators ? parameterDecorators[index] : null;
  25828. if (decorators) {
  25829. nestedResult.push(...decorators);
  25830. } /** @type {?} */
  25831. ((parameters)).push(nestedResult);
  25832. });
  25833. }
  25834. else if (parentType) {
  25835. parameters = this.parameters(parentType);
  25836. }
  25837. if (!parameters) {
  25838. parameters = [];
  25839. }
  25840. this.parameterCache.set(type, parameters);
  25841. }
  25842. return parameters;
  25843. }
  25844. catch (/** @type {?} */ e) {
  25845. console.error(`Failed on type ${JSON.stringify(type)} with error ${e}`);
  25846. throw e;
  25847. }
  25848. }
  25849. /**
  25850. * @param {?} type
  25851. * @return {?}
  25852. */
  25853. _methodNames(type) {
  25854. let /** @type {?} */ methodNames = this.methodCache.get(type);
  25855. if (!methodNames) {
  25856. const /** @type {?} */ classMetadata = this.getTypeMetadata(type);
  25857. methodNames = {};
  25858. const /** @type {?} */ parentType = this.findParentType(type, classMetadata);
  25859. if (parentType) {
  25860. const /** @type {?} */ parentMethodNames = this._methodNames(parentType);
  25861. Object.keys(parentMethodNames).forEach((parentProp) => {
  25862. /** @type {?} */ ((methodNames))[parentProp] = parentMethodNames[parentProp];
  25863. });
  25864. }
  25865. const /** @type {?} */ members = classMetadata['members'] || {};
  25866. Object.keys(members).forEach((propName) => {
  25867. const /** @type {?} */ propData = members[propName];
  25868. const /** @type {?} */ isMethod = (/** @type {?} */ (propData)).some(a => a['__symbolic'] == 'method'); /** @type {?} */
  25869. ((methodNames))[propName] = /** @type {?} */ ((methodNames))[propName] || isMethod;
  25870. });
  25871. this.methodCache.set(type, methodNames);
  25872. }
  25873. return methodNames;
  25874. }
  25875. /**
  25876. * @param {?} type
  25877. * @return {?}
  25878. */
  25879. _staticMembers(type) {
  25880. let /** @type {?} */ staticMembers = this.staticCache.get(type);
  25881. if (!staticMembers) {
  25882. const /** @type {?} */ classMetadata = this.getTypeMetadata(type);
  25883. const /** @type {?} */ staticMemberData = classMetadata['statics'] || {};
  25884. staticMembers = Object.keys(staticMemberData);
  25885. this.staticCache.set(type, staticMembers);
  25886. }
  25887. return staticMembers;
  25888. }
  25889. /**
  25890. * @param {?} type
  25891. * @param {?} classMetadata
  25892. * @return {?}
  25893. */
  25894. findParentType(type, classMetadata) {
  25895. const /** @type {?} */ parentType = this.trySimplify(type, classMetadata['extends']);
  25896. if (parentType instanceof StaticSymbol) {
  25897. return parentType;
  25898. }
  25899. }
  25900. /**
  25901. * @param {?} type
  25902. * @param {?} lcProperty
  25903. * @return {?}
  25904. */
  25905. hasLifecycleHook(type, lcProperty) {
  25906. if (!(type instanceof StaticSymbol)) {
  25907. this.reportError(new Error(`hasLifecycleHook received ${JSON.stringify(type)} which is not a StaticSymbol`), type);
  25908. }
  25909. try {
  25910. return !!this._methodNames(type)[lcProperty];
  25911. }
  25912. catch (/** @type {?} */ e) {
  25913. console.error(`Failed on type ${JSON.stringify(type)} with error ${e}`);
  25914. throw e;
  25915. }
  25916. }
  25917. /**
  25918. * @param {?} type
  25919. * @return {?}
  25920. */
  25921. guards(type) {
  25922. if (!(type instanceof StaticSymbol)) {
  25923. this.reportError(new Error(`guards received ${JSON.stringify(type)} which is not a StaticSymbol`), type);
  25924. return {};
  25925. }
  25926. const /** @type {?} */ staticMembers = this._staticMembers(type);
  25927. const /** @type {?} */ result = {};
  25928. for (let /** @type {?} */ name of staticMembers) {
  25929. if (name.endsWith(TYPEGUARD_POSTFIX)) {
  25930. let /** @type {?} */ property = name.substr(0, name.length - TYPEGUARD_POSTFIX.length);
  25931. let /** @type {?} */ value;
  25932. if (property.endsWith(USE_IF)) {
  25933. property = name.substr(0, property.length - USE_IF.length);
  25934. value = USE_IF;
  25935. }
  25936. else {
  25937. value = this.getStaticSymbol(type.filePath, type.name, [name]);
  25938. }
  25939. result[property] = value;
  25940. }
  25941. }
  25942. return result;
  25943. }
  25944. /**
  25945. * @param {?} type
  25946. * @param {?} ctor
  25947. * @return {?}
  25948. */
  25949. _registerDecoratorOrConstructor(type, ctor) {
  25950. this.conversionMap.set(type, (context, args) => new ctor(...args));
  25951. }
  25952. /**
  25953. * @param {?} type
  25954. * @param {?} fn
  25955. * @return {?}
  25956. */
  25957. _registerFunction(type, fn) {
  25958. this.conversionMap.set(type, (context, args) => fn.apply(undefined, args));
  25959. }
  25960. /**
  25961. * @return {?}
  25962. */
  25963. initializeConversionMap() {
  25964. this.injectionToken = this.findDeclaration(ANGULAR_CORE, 'InjectionToken');
  25965. this.opaqueToken = this.findDeclaration(ANGULAR_CORE, 'OpaqueToken');
  25966. this.ROUTES = this.tryFindDeclaration(ANGULAR_ROUTER, 'ROUTES');
  25967. this.ANALYZE_FOR_ENTRY_COMPONENTS =
  25968. this.findDeclaration(ANGULAR_CORE, 'ANALYZE_FOR_ENTRY_COMPONENTS');
  25969. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), createHost);
  25970. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Injectable'), createInjectable);
  25971. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), createSelf);
  25972. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), createSkipSelf);
  25973. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Inject'), createInject);
  25974. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Optional'), createOptional);
  25975. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Attribute'), createAttribute);
  25976. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'ContentChild'), createContentChild);
  25977. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'ContentChildren'), createContentChildren);
  25978. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'ViewChild'), createViewChild);
  25979. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'ViewChildren'), createViewChildren);
  25980. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Input'), createInput);
  25981. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Output'), createOutput);
  25982. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Pipe'), createPipe);
  25983. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'HostBinding'), createHostBinding);
  25984. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'HostListener'), createHostListener);
  25985. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Directive'), createDirective);
  25986. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Component'), createComponent);
  25987. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'NgModule'), createNgModule);
  25988. // Note: Some metadata classes can be used directly with Provider.deps.
  25989. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), createHost);
  25990. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), createSelf);
  25991. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), createSkipSelf);
  25992. this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Optional'), createOptional);
  25993. }
  25994. /**
  25995. * getStaticSymbol produces a Type whose metadata is known but whose implementation is not loaded.
  25996. * All types passed to the StaticResolver should be pseudo-types returned by this method.
  25997. *
  25998. * @param {?} declarationFile the absolute path of the file where the symbol is declared
  25999. * @param {?} name the name of the type.
  26000. * @param {?=} members
  26001. * @return {?}
  26002. */
  26003. getStaticSymbol(declarationFile, name, members) {
  26004. return this.symbolResolver.getStaticSymbol(declarationFile, name, members);
  26005. }
  26006. /**
  26007. * Simplify but discard any errors
  26008. * @param {?} context
  26009. * @param {?} value
  26010. * @return {?}
  26011. */
  26012. trySimplify(context, value) {
  26013. const /** @type {?} */ originalRecorder = this.errorRecorder;
  26014. this.errorRecorder = (error, fileName) => { };
  26015. const /** @type {?} */ result = this.simplify(context, value);
  26016. this.errorRecorder = originalRecorder;
  26017. return result;
  26018. }
  26019. /**
  26020. * \@internal
  26021. * @param {?} context
  26022. * @param {?} value
  26023. * @return {?}
  26024. */
  26025. simplify(context, value) {
  26026. const /** @type {?} */ self = this;
  26027. let /** @type {?} */ scope = BindingScope.empty;
  26028. const /** @type {?} */ calling = new Map();
  26029. const /** @type {?} */ rootContext = context;
  26030. /**
  26031. * @param {?} context
  26032. * @param {?} value
  26033. * @param {?} depth
  26034. * @param {?} references
  26035. * @return {?}
  26036. */
  26037. function simplifyInContext(context, value, depth, references) {
  26038. /**
  26039. * @param {?} staticSymbol
  26040. * @return {?}
  26041. */
  26042. function resolveReferenceValue(staticSymbol) {
  26043. const /** @type {?} */ resolvedSymbol = self.symbolResolver.resolveSymbol(staticSymbol);
  26044. return resolvedSymbol ? resolvedSymbol.metadata : null;
  26045. }
  26046. /**
  26047. * @param {?} value
  26048. * @return {?}
  26049. */
  26050. function simplifyEagerly(value) {
  26051. return simplifyInContext(context, value, depth, 0);
  26052. }
  26053. /**
  26054. * @param {?} value
  26055. * @return {?}
  26056. */
  26057. function simplifyLazily(value) {
  26058. return simplifyInContext(context, value, depth, references + 1);
  26059. }
  26060. /**
  26061. * @param {?} nestedContext
  26062. * @param {?} value
  26063. * @return {?}
  26064. */
  26065. function simplifyNested(nestedContext, value) {
  26066. if (nestedContext === context) {
  26067. // If the context hasn't changed let the exception propagate unmodified.
  26068. return simplifyInContext(nestedContext, value, depth + 1, references);
  26069. }
  26070. try {
  26071. return simplifyInContext(nestedContext, value, depth + 1, references);
  26072. }
  26073. catch (/** @type {?} */ e) {
  26074. if (isMetadataError(e)) {
  26075. // Propagate the message text up but add a message to the chain that explains how we got
  26076. // here.
  26077. // e.chain implies e.symbol
  26078. const /** @type {?} */ summaryMsg = e.chain ? 'references \'' + /** @type {?} */ ((e.symbol)).name + '\'' : errorSummary(e);
  26079. const /** @type {?} */ summary = `'${nestedContext.name}' ${summaryMsg}`;
  26080. const /** @type {?} */ chain = { message: summary, position: e.position, next: e.chain };
  26081. // TODO(chuckj): retrieve the position information indirectly from the collectors node
  26082. // map if the metadata is from a .ts file.
  26083. self.error({
  26084. message: e.message,
  26085. advise: e.advise,
  26086. context: e.context, chain,
  26087. symbol: nestedContext
  26088. }, context);
  26089. }
  26090. else {
  26091. // It is probably an internal error.
  26092. throw e;
  26093. }
  26094. }
  26095. }
  26096. /**
  26097. * @param {?} functionSymbol
  26098. * @param {?} targetFunction
  26099. * @param {?} args
  26100. * @param {?} targetExpression
  26101. * @return {?}
  26102. */
  26103. function simplifyCall(functionSymbol, targetFunction, args, targetExpression) {
  26104. if (targetFunction && targetFunction['__symbolic'] == 'function') {
  26105. if (calling.get(functionSymbol)) {
  26106. self.error({
  26107. message: 'Recursion is not supported',
  26108. summary: `called '${functionSymbol.name}' recursively`,
  26109. value: targetFunction
  26110. }, functionSymbol);
  26111. }
  26112. try {
  26113. const /** @type {?} */ value = targetFunction['value'];
  26114. if (value && (depth != 0 || value.__symbolic != 'error')) {
  26115. const /** @type {?} */ parameters = targetFunction['parameters'];
  26116. const /** @type {?} */ defaults = targetFunction.defaults;
  26117. args = args.map(arg => simplifyNested(context, arg))
  26118. .map(arg => shouldIgnore(arg) ? undefined : arg);
  26119. if (defaults && defaults.length > args.length) {
  26120. args.push(...defaults.slice(args.length).map((value) => simplify(value)));
  26121. }
  26122. calling.set(functionSymbol, true);
  26123. const /** @type {?} */ functionScope = BindingScope.build();
  26124. for (let /** @type {?} */ i = 0; i < parameters.length; i++) {
  26125. functionScope.define(parameters[i], args[i]);
  26126. }
  26127. const /** @type {?} */ oldScope = scope;
  26128. let /** @type {?} */ result;
  26129. try {
  26130. scope = functionScope.done();
  26131. result = simplifyNested(functionSymbol, value);
  26132. }
  26133. finally {
  26134. scope = oldScope;
  26135. }
  26136. return result;
  26137. }
  26138. }
  26139. finally {
  26140. calling.delete(functionSymbol);
  26141. }
  26142. }
  26143. if (depth === 0) {
  26144. // If depth is 0 we are evaluating the top level expression that is describing element
  26145. // decorator. In this case, it is a decorator we don't understand, such as a custom
  26146. // non-angular decorator, and we should just ignore it.
  26147. return IGNORE;
  26148. }
  26149. let /** @type {?} */ position = undefined;
  26150. if (targetExpression && targetExpression.__symbolic == 'resolved') {
  26151. const /** @type {?} */ line = targetExpression.line;
  26152. const /** @type {?} */ character = targetExpression.character;
  26153. const /** @type {?} */ fileName = targetExpression.fileName;
  26154. if (fileName != null && line != null && character != null) {
  26155. position = { fileName, line, column: character };
  26156. }
  26157. }
  26158. self.error({
  26159. message: FUNCTION_CALL_NOT_SUPPORTED,
  26160. context: functionSymbol,
  26161. value: targetFunction, position
  26162. }, context);
  26163. }
  26164. /**
  26165. * @param {?} expression
  26166. * @return {?}
  26167. */
  26168. function simplify(expression) {
  26169. if (isPrimitive(expression)) {
  26170. return expression;
  26171. }
  26172. if (expression instanceof Array) {
  26173. const /** @type {?} */ result = [];
  26174. for (const /** @type {?} */ item of (/** @type {?} */ (expression))) {
  26175. // Check for a spread expression
  26176. if (item && item.__symbolic === 'spread') {
  26177. // We call with references as 0 because we require the actual value and cannot
  26178. // tolerate a reference here.
  26179. const /** @type {?} */ spreadArray = simplifyEagerly(item.expression);
  26180. if (Array.isArray(spreadArray)) {
  26181. for (const /** @type {?} */ spreadItem of spreadArray) {
  26182. result.push(spreadItem);
  26183. }
  26184. continue;
  26185. }
  26186. }
  26187. const /** @type {?} */ value = simplify(item);
  26188. if (shouldIgnore(value)) {
  26189. continue;
  26190. }
  26191. result.push(value);
  26192. }
  26193. return result;
  26194. }
  26195. if (expression instanceof StaticSymbol) {
  26196. // Stop simplification at builtin symbols or if we are in a reference context and
  26197. // the symbol doesn't have members.
  26198. if (expression === self.injectionToken || self.conversionMap.has(expression) ||
  26199. (references > 0 && !expression.members.length)) {
  26200. return expression;
  26201. }
  26202. else {
  26203. const /** @type {?} */ staticSymbol = expression;
  26204. const /** @type {?} */ declarationValue = resolveReferenceValue(staticSymbol);
  26205. if (declarationValue != null) {
  26206. return simplifyNested(staticSymbol, declarationValue);
  26207. }
  26208. else {
  26209. return staticSymbol;
  26210. }
  26211. }
  26212. }
  26213. if (expression) {
  26214. if (expression['__symbolic']) {
  26215. let /** @type {?} */ staticSymbol;
  26216. switch (expression['__symbolic']) {
  26217. case 'binop':
  26218. let /** @type {?} */ left = simplify(expression['left']);
  26219. if (shouldIgnore(left))
  26220. return left;
  26221. let /** @type {?} */ right = simplify(expression['right']);
  26222. if (shouldIgnore(right))
  26223. return right;
  26224. switch (expression['operator']) {
  26225. case '&&':
  26226. return left && right;
  26227. case '||':
  26228. return left || right;
  26229. case '|':
  26230. return left | right;
  26231. case '^':
  26232. return left ^ right;
  26233. case '&':
  26234. return left & right;
  26235. case '==':
  26236. return left == right;
  26237. case '!=':
  26238. return left != right;
  26239. case '===':
  26240. return left === right;
  26241. case '!==':
  26242. return left !== right;
  26243. case '<':
  26244. return left < right;
  26245. case '>':
  26246. return left > right;
  26247. case '<=':
  26248. return left <= right;
  26249. case '>=':
  26250. return left >= right;
  26251. case '<<':
  26252. return left << right;
  26253. case '>>':
  26254. return left >> right;
  26255. case '+':
  26256. return left + right;
  26257. case '-':
  26258. return left - right;
  26259. case '*':
  26260. return left * right;
  26261. case '/':
  26262. return left / right;
  26263. case '%':
  26264. return left % right;
  26265. }
  26266. return null;
  26267. case 'if':
  26268. let /** @type {?} */ condition = simplify(expression['condition']);
  26269. return condition ? simplify(expression['thenExpression']) :
  26270. simplify(expression['elseExpression']);
  26271. case 'pre':
  26272. let /** @type {?} */ operand = simplify(expression['operand']);
  26273. if (shouldIgnore(operand))
  26274. return operand;
  26275. switch (expression['operator']) {
  26276. case '+':
  26277. return operand;
  26278. case '-':
  26279. return -operand;
  26280. case '!':
  26281. return !operand;
  26282. case '~':
  26283. return ~operand;
  26284. }
  26285. return null;
  26286. case 'index':
  26287. let /** @type {?} */ indexTarget = simplifyEagerly(expression['expression']);
  26288. let /** @type {?} */ index = simplifyEagerly(expression['index']);
  26289. if (indexTarget && isPrimitive(index))
  26290. return indexTarget[index];
  26291. return null;
  26292. case 'select':
  26293. const /** @type {?} */ member = expression['member'];
  26294. let /** @type {?} */ selectContext = context;
  26295. let /** @type {?} */ selectTarget = simplify(expression['expression']);
  26296. if (selectTarget instanceof StaticSymbol) {
  26297. const /** @type {?} */ members = selectTarget.members.concat(member);
  26298. selectContext =
  26299. self.getStaticSymbol(selectTarget.filePath, selectTarget.name, members);
  26300. const /** @type {?} */ declarationValue = resolveReferenceValue(selectContext);
  26301. if (declarationValue != null) {
  26302. return simplifyNested(selectContext, declarationValue);
  26303. }
  26304. else {
  26305. return selectContext;
  26306. }
  26307. }
  26308. if (selectTarget && isPrimitive(member))
  26309. return simplifyNested(selectContext, selectTarget[member]);
  26310. return null;
  26311. case 'reference':
  26312. // Note: This only has to deal with variable references, as symbol references have
  26313. // been converted into 'resolved'
  26314. // in the StaticSymbolResolver.
  26315. const /** @type {?} */ name = expression['name'];
  26316. const /** @type {?} */ localValue = scope.resolve(name);
  26317. if (localValue != BindingScope.missing) {
  26318. return localValue;
  26319. }
  26320. break;
  26321. case 'resolved':
  26322. try {
  26323. return simplify(expression.symbol);
  26324. }
  26325. catch (/** @type {?} */ e) {
  26326. // If an error is reported evaluating the symbol record the position of the
  26327. // reference in the error so it can
  26328. // be reported in the error message generated from the exception.
  26329. if (isMetadataError(e) && expression.fileName != null &&
  26330. expression.line != null && expression.character != null) {
  26331. e.position = {
  26332. fileName: expression.fileName,
  26333. line: expression.line,
  26334. column: expression.character
  26335. };
  26336. }
  26337. throw e;
  26338. }
  26339. case 'class':
  26340. return context;
  26341. case 'function':
  26342. return context;
  26343. case 'new':
  26344. case 'call':
  26345. // Determine if the function is a built-in conversion
  26346. staticSymbol = simplifyInContext(context, expression['expression'], depth + 1, /* references */ 0);
  26347. if (staticSymbol instanceof StaticSymbol) {
  26348. if (staticSymbol === self.injectionToken || staticSymbol === self.opaqueToken) {
  26349. // if somebody calls new InjectionToken, don't create an InjectionToken,
  26350. // but rather return the symbol to which the InjectionToken is assigned to.
  26351. // OpaqueToken is supported too as it is required by the language service to
  26352. // support v4 and prior versions of Angular.
  26353. return context;
  26354. }
  26355. const /** @type {?} */ argExpressions = expression['arguments'] || [];
  26356. let /** @type {?} */ converter = self.conversionMap.get(staticSymbol);
  26357. if (converter) {
  26358. const /** @type {?} */ args = argExpressions.map(arg => simplifyNested(context, arg))
  26359. .map(arg => shouldIgnore(arg) ? undefined : arg);
  26360. return converter(context, args);
  26361. }
  26362. else {
  26363. // Determine if the function is one we can simplify.
  26364. const /** @type {?} */ targetFunction = resolveReferenceValue(staticSymbol);
  26365. return simplifyCall(staticSymbol, targetFunction, argExpressions, expression['expression']);
  26366. }
  26367. }
  26368. return IGNORE;
  26369. case 'error':
  26370. let /** @type {?} */ message = expression.message;
  26371. if (expression['line'] != null) {
  26372. self.error({
  26373. message,
  26374. context: expression.context,
  26375. value: expression,
  26376. position: {
  26377. fileName: expression['fileName'],
  26378. line: expression['line'],
  26379. column: expression['character']
  26380. }
  26381. }, context);
  26382. }
  26383. else {
  26384. self.error({ message, context: expression.context }, context);
  26385. }
  26386. return IGNORE;
  26387. case 'ignore':
  26388. return expression;
  26389. }
  26390. return null;
  26391. }
  26392. return mapStringMap(expression, (value, name) => {
  26393. if (REFERENCE_SET.has(name)) {
  26394. if (name === USE_VALUE && PROVIDE in expression) {
  26395. // If this is a provider expression, check for special tokens that need the value
  26396. // during analysis.
  26397. const /** @type {?} */ provide = simplify(expression.provide);
  26398. if (provide === self.ROUTES || provide == self.ANALYZE_FOR_ENTRY_COMPONENTS) {
  26399. return simplify(value);
  26400. }
  26401. }
  26402. return simplifyLazily(value);
  26403. }
  26404. return simplify(value);
  26405. });
  26406. }
  26407. return IGNORE;
  26408. }
  26409. return simplify(value);
  26410. }
  26411. let /** @type {?} */ result;
  26412. try {
  26413. result = simplifyInContext(context, value, 0, 0);
  26414. }
  26415. catch (/** @type {?} */ e) {
  26416. if (this.errorRecorder) {
  26417. this.reportError(e, context);
  26418. }
  26419. else {
  26420. throw formatMetadataError(e, context);
  26421. }
  26422. }
  26423. if (shouldIgnore(result)) {
  26424. return undefined;
  26425. }
  26426. return result;
  26427. }
  26428. /**
  26429. * @param {?} type
  26430. * @return {?}
  26431. */
  26432. getTypeMetadata(type) {
  26433. const /** @type {?} */ resolvedSymbol = this.symbolResolver.resolveSymbol(type);
  26434. return resolvedSymbol && resolvedSymbol.metadata ? resolvedSymbol.metadata :
  26435. { __symbolic: 'class' };
  26436. }
  26437. /**
  26438. * @param {?} error
  26439. * @param {?} context
  26440. * @param {?=} path
  26441. * @return {?}
  26442. */
  26443. reportError(error, context, path) {
  26444. if (this.errorRecorder) {
  26445. this.errorRecorder(formatMetadataError(error, context), (context && context.filePath) || path);
  26446. }
  26447. else {
  26448. throw error;
  26449. }
  26450. }
  26451. /**
  26452. * @param {?} __0
  26453. * @param {?} reportingContext
  26454. * @return {?}
  26455. */
  26456. error({ message, summary, advise, position, context, value, symbol, chain }, reportingContext) {
  26457. this.reportError(metadataError(message, summary, advise, position, symbol, context, chain), reportingContext);
  26458. }
  26459. }
  26460. const METADATA_ERROR = 'ngMetadataError';
  26461. /**
  26462. * @param {?} message
  26463. * @param {?=} summary
  26464. * @param {?=} advise
  26465. * @param {?=} position
  26466. * @param {?=} symbol
  26467. * @param {?=} context
  26468. * @param {?=} chain
  26469. * @return {?}
  26470. */
  26471. function metadataError(message, summary, advise, position, symbol, context, chain) {
  26472. const /** @type {?} */ error = /** @type {?} */ (syntaxError(message));
  26473. (/** @type {?} */ (error))[METADATA_ERROR] = true;
  26474. if (advise)
  26475. error.advise = advise;
  26476. if (position)
  26477. error.position = position;
  26478. if (summary)
  26479. error.summary = summary;
  26480. if (context)
  26481. error.context = context;
  26482. if (chain)
  26483. error.chain = chain;
  26484. if (symbol)
  26485. error.symbol = symbol;
  26486. return error;
  26487. }
  26488. /**
  26489. * @param {?} error
  26490. * @return {?}
  26491. */
  26492. function isMetadataError(error) {
  26493. return !!(/** @type {?} */ (error))[METADATA_ERROR];
  26494. }
  26495. const REFERENCE_TO_NONEXPORTED_CLASS = 'Reference to non-exported class';
  26496. const VARIABLE_NOT_INITIALIZED = 'Variable not initialized';
  26497. const DESTRUCTURE_NOT_SUPPORTED = 'Destructuring not supported';
  26498. const COULD_NOT_RESOLVE_TYPE = 'Could not resolve type';
  26499. const FUNCTION_CALL_NOT_SUPPORTED = 'Function call not supported';
  26500. const REFERENCE_TO_LOCAL_SYMBOL = 'Reference to a local symbol';
  26501. const LAMBDA_NOT_SUPPORTED = 'Lambda not supported';
  26502. /**
  26503. * @param {?} message
  26504. * @param {?} context
  26505. * @return {?}
  26506. */
  26507. function expandedMessage(message, context) {
  26508. switch (message) {
  26509. case REFERENCE_TO_NONEXPORTED_CLASS:
  26510. if (context && context.className) {
  26511. return `References to a non-exported class are not supported in decorators but ${context.className} was referenced.`;
  26512. }
  26513. break;
  26514. case VARIABLE_NOT_INITIALIZED:
  26515. return 'Only initialized variables and constants can be referenced in decorators because the value of this variable is needed by the template compiler';
  26516. case DESTRUCTURE_NOT_SUPPORTED:
  26517. return 'Referencing an exported destructured variable or constant is not supported in decorators and this value is needed by the template compiler';
  26518. case COULD_NOT_RESOLVE_TYPE:
  26519. if (context && context.typeName) {
  26520. return `Could not resolve type ${context.typeName}`;
  26521. }
  26522. break;
  26523. case FUNCTION_CALL_NOT_SUPPORTED:
  26524. if (context && context.name) {
  26525. return `Function calls are not supported in decorators but '${context.name}' was called`;
  26526. }
  26527. return 'Function calls are not supported in decorators';
  26528. case REFERENCE_TO_LOCAL_SYMBOL:
  26529. if (context && context.name) {
  26530. return `Reference to a local (non-exported) symbols are not supported in decorators but '${context.name}' was referenced`;
  26531. }
  26532. break;
  26533. case LAMBDA_NOT_SUPPORTED:
  26534. return `Function expressions are not supported in decorators`;
  26535. }
  26536. return message;
  26537. }
  26538. /**
  26539. * @param {?} message
  26540. * @param {?} context
  26541. * @return {?}
  26542. */
  26543. function messageAdvise(message, context) {
  26544. switch (message) {
  26545. case REFERENCE_TO_NONEXPORTED_CLASS:
  26546. if (context && context.className) {
  26547. return `Consider exporting '${context.className}'`;
  26548. }
  26549. break;
  26550. case DESTRUCTURE_NOT_SUPPORTED:
  26551. return 'Consider simplifying to avoid destructuring';
  26552. case REFERENCE_TO_LOCAL_SYMBOL:
  26553. if (context && context.name) {
  26554. return `Consider exporting '${context.name}'`;
  26555. }
  26556. break;
  26557. case LAMBDA_NOT_SUPPORTED:
  26558. return `Consider changing the function expression into an exported function`;
  26559. }
  26560. return undefined;
  26561. }
  26562. /**
  26563. * @param {?} error
  26564. * @return {?}
  26565. */
  26566. function errorSummary(error) {
  26567. if (error.summary) {
  26568. return error.summary;
  26569. }
  26570. switch (error.message) {
  26571. case REFERENCE_TO_NONEXPORTED_CLASS:
  26572. if (error.context && error.context.className) {
  26573. return `references non-exported class ${error.context.className}`;
  26574. }
  26575. break;
  26576. case VARIABLE_NOT_INITIALIZED:
  26577. return 'is not initialized';
  26578. case DESTRUCTURE_NOT_SUPPORTED:
  26579. return 'is a destructured variable';
  26580. case COULD_NOT_RESOLVE_TYPE:
  26581. return 'could not be resolved';
  26582. case FUNCTION_CALL_NOT_SUPPORTED:
  26583. if (error.context && error.context.name) {
  26584. return `calls '${error.context.name}'`;
  26585. }
  26586. return `calls a function`;
  26587. case REFERENCE_TO_LOCAL_SYMBOL:
  26588. if (error.context && error.context.name) {
  26589. return `references local variable ${error.context.name}`;
  26590. }
  26591. return `references a local variable`;
  26592. }
  26593. return 'contains the error';
  26594. }
  26595. /**
  26596. * @param {?} input
  26597. * @param {?} transform
  26598. * @return {?}
  26599. */
  26600. function mapStringMap(input, transform) {
  26601. if (!input)
  26602. return {};
  26603. const /** @type {?} */ result = {};
  26604. Object.keys(input).forEach((key) => {
  26605. const /** @type {?} */ value = transform(input[key], key);
  26606. if (!shouldIgnore(value)) {
  26607. if (HIDDEN_KEY.test(key)) {
  26608. Object.defineProperty(result, key, { enumerable: false, configurable: true, value: value });
  26609. }
  26610. else {
  26611. result[key] = value;
  26612. }
  26613. }
  26614. });
  26615. return result;
  26616. }
  26617. /**
  26618. * @param {?} o
  26619. * @return {?}
  26620. */
  26621. function isPrimitive(o) {
  26622. return o === null || (typeof o !== 'function' && typeof o !== 'object');
  26623. }
  26624. /**
  26625. * @abstract
  26626. */
  26627. class BindingScope {
  26628. /**
  26629. * @return {?}
  26630. */
  26631. static build() {
  26632. const /** @type {?} */ current = new Map();
  26633. return {
  26634. define: function (name, value) {
  26635. current.set(name, value);
  26636. return this;
  26637. },
  26638. done: function () {
  26639. return current.size > 0 ? new PopulatedScope(current) : BindingScope.empty;
  26640. }
  26641. };
  26642. }
  26643. }
  26644. BindingScope.missing = {};
  26645. BindingScope.empty = { resolve: name => BindingScope.missing };
  26646. class PopulatedScope extends BindingScope {
  26647. /**
  26648. * @param {?} bindings
  26649. */
  26650. constructor(bindings) {
  26651. super();
  26652. this.bindings = bindings;
  26653. }
  26654. /**
  26655. * @param {?} name
  26656. * @return {?}
  26657. */
  26658. resolve(name) {
  26659. return this.bindings.has(name) ? this.bindings.get(name) : BindingScope.missing;
  26660. }
  26661. }
  26662. /**
  26663. * @param {?} chain
  26664. * @param {?} advise
  26665. * @return {?}
  26666. */
  26667. function formatMetadataMessageChain(chain, advise) {
  26668. const /** @type {?} */ expanded = expandedMessage(chain.message, chain.context);
  26669. const /** @type {?} */ nesting = chain.symbol ? ` in '${chain.symbol.name}'` : '';
  26670. const /** @type {?} */ message = `${expanded}${nesting}`;
  26671. const /** @type {?} */ position = chain.position;
  26672. const /** @type {?} */ next = chain.next ?
  26673. formatMetadataMessageChain(chain.next, advise) :
  26674. advise ? { message: advise } : undefined;
  26675. return { message, position, next };
  26676. }
  26677. /**
  26678. * @param {?} e
  26679. * @param {?} context
  26680. * @return {?}
  26681. */
  26682. function formatMetadataError(e, context) {
  26683. if (isMetadataError(e)) {
  26684. // Produce a formatted version of the and leaving enough information in the original error
  26685. // to recover the formatting information to eventually produce a diagnostic error message.
  26686. const /** @type {?} */ position = e.position;
  26687. const /** @type {?} */ chain = {
  26688. message: `Error during template compile of '${context.name}'`,
  26689. position: position,
  26690. next: { message: e.message, next: e.chain, context: e.context, symbol: e.symbol }
  26691. };
  26692. const /** @type {?} */ advise = e.advise || messageAdvise(e.message, e.context);
  26693. return formattedError(formatMetadataMessageChain(chain, advise));
  26694. }
  26695. return e;
  26696. }
  26697. /**
  26698. * @fileoverview added by tsickle
  26699. * @suppress {checkTypes} checked by tsc
  26700. */
  26701. /**
  26702. * @license
  26703. * Copyright Google Inc. All Rights Reserved.
  26704. *
  26705. * Use of this source code is governed by an MIT-style license that can be
  26706. * found in the LICENSE file at https://angular.io/license
  26707. */
  26708. /**
  26709. * @record
  26710. */
  26711. class AotSummaryResolver {
  26712. /**
  26713. * @param {?} host
  26714. * @param {?} staticSymbolCache
  26715. */
  26716. constructor(host, staticSymbolCache) {
  26717. this.host = host;
  26718. this.staticSymbolCache = staticSymbolCache;
  26719. this.summaryCache = new Map();
  26720. this.loadedFilePaths = new Map();
  26721. this.importAs = new Map();
  26722. this.knownFileNameToModuleNames = new Map();
  26723. }
  26724. /**
  26725. * @param {?} filePath
  26726. * @return {?}
  26727. */
  26728. isLibraryFile(filePath) {
  26729. // Note: We need to strip the .ngfactory. file path,
  26730. // so this method also works for generated files
  26731. // (for which host.isSourceFile will always return false).
  26732. return !this.host.isSourceFile(stripGeneratedFileSuffix(filePath));
  26733. }
  26734. /**
  26735. * @param {?} filePath
  26736. * @param {?} referringSrcFileName
  26737. * @return {?}
  26738. */
  26739. toSummaryFileName(filePath, referringSrcFileName) {
  26740. return this.host.toSummaryFileName(filePath, referringSrcFileName);
  26741. }
  26742. /**
  26743. * @param {?} fileName
  26744. * @param {?} referringLibFileName
  26745. * @return {?}
  26746. */
  26747. fromSummaryFileName(fileName, referringLibFileName) {
  26748. return this.host.fromSummaryFileName(fileName, referringLibFileName);
  26749. }
  26750. /**
  26751. * @param {?} staticSymbol
  26752. * @return {?}
  26753. */
  26754. resolveSummary(staticSymbol) {
  26755. const /** @type {?} */ rootSymbol = staticSymbol.members.length ?
  26756. this.staticSymbolCache.get(staticSymbol.filePath, staticSymbol.name) :
  26757. staticSymbol;
  26758. let /** @type {?} */ summary = this.summaryCache.get(rootSymbol);
  26759. if (!summary) {
  26760. this._loadSummaryFile(staticSymbol.filePath);
  26761. summary = /** @type {?} */ ((this.summaryCache.get(staticSymbol)));
  26762. }
  26763. return (rootSymbol === staticSymbol && summary) || null;
  26764. }
  26765. /**
  26766. * @param {?} filePath
  26767. * @return {?}
  26768. */
  26769. getSymbolsOf(filePath) {
  26770. if (this._loadSummaryFile(filePath)) {
  26771. return Array.from(this.summaryCache.keys()).filter((symbol) => symbol.filePath === filePath);
  26772. }
  26773. return null;
  26774. }
  26775. /**
  26776. * @param {?} staticSymbol
  26777. * @return {?}
  26778. */
  26779. getImportAs(staticSymbol) {
  26780. staticSymbol.assertNoMembers();
  26781. return /** @type {?} */ ((this.importAs.get(staticSymbol)));
  26782. }
  26783. /**
  26784. * Converts a file path to a module name that can be used as an `import`.
  26785. * @param {?} importedFilePath
  26786. * @return {?}
  26787. */
  26788. getKnownModuleName(importedFilePath) {
  26789. return this.knownFileNameToModuleNames.get(importedFilePath) || null;
  26790. }
  26791. /**
  26792. * @param {?} summary
  26793. * @return {?}
  26794. */
  26795. addSummary(summary) { this.summaryCache.set(summary.symbol, summary); }
  26796. /**
  26797. * @param {?} filePath
  26798. * @return {?}
  26799. */
  26800. _loadSummaryFile(filePath) {
  26801. let /** @type {?} */ hasSummary = this.loadedFilePaths.get(filePath);
  26802. if (hasSummary != null) {
  26803. return hasSummary;
  26804. }
  26805. let /** @type {?} */ json = null;
  26806. if (this.isLibraryFile(filePath)) {
  26807. const /** @type {?} */ summaryFilePath = summaryFileName(filePath);
  26808. try {
  26809. json = this.host.loadSummary(summaryFilePath);
  26810. }
  26811. catch (/** @type {?} */ e) {
  26812. console.error(`Error loading summary file ${summaryFilePath}`);
  26813. throw e;
  26814. }
  26815. }
  26816. hasSummary = json != null;
  26817. this.loadedFilePaths.set(filePath, hasSummary);
  26818. if (json) {
  26819. const { moduleName, summaries, importAs } = deserializeSummaries(this.staticSymbolCache, this, filePath, json);
  26820. summaries.forEach((summary) => this.summaryCache.set(summary.symbol, summary));
  26821. if (moduleName) {
  26822. this.knownFileNameToModuleNames.set(filePath, moduleName);
  26823. }
  26824. importAs.forEach((importAs) => { this.importAs.set(importAs.symbol, importAs.importAs); });
  26825. }
  26826. return hasSummary;
  26827. }
  26828. }
  26829. /**
  26830. * @fileoverview added by tsickle
  26831. * @suppress {checkTypes} checked by tsc
  26832. */
  26833. /**
  26834. * @license
  26835. * Copyright Google Inc. All Rights Reserved.
  26836. *
  26837. * Use of this source code is governed by an MIT-style license that can be
  26838. * found in the LICENSE file at https://angular.io/license
  26839. */
  26840. /**
  26841. * @param {?} host
  26842. * @return {?}
  26843. */
  26844. function createAotUrlResolver(host) {
  26845. return {
  26846. resolve: (basePath, url) => {
  26847. const /** @type {?} */ filePath = host.resourceNameToFileName(url, basePath);
  26848. if (!filePath) {
  26849. throw syntaxError(`Couldn't resolve resource ${url} from ${basePath}`);
  26850. }
  26851. return filePath;
  26852. }
  26853. };
  26854. }
  26855. /**
  26856. * Creates a new AotCompiler based on options and a host.
  26857. * @param {?} compilerHost
  26858. * @param {?} options
  26859. * @param {?=} errorCollector
  26860. * @return {?}
  26861. */
  26862. function createAotCompiler(compilerHost, options, errorCollector) {
  26863. let /** @type {?} */ translations = options.translations || '';
  26864. const /** @type {?} */ urlResolver = createAotUrlResolver(compilerHost);
  26865. const /** @type {?} */ symbolCache = new StaticSymbolCache();
  26866. const /** @type {?} */ summaryResolver = new AotSummaryResolver(compilerHost, symbolCache);
  26867. const /** @type {?} */ symbolResolver = new StaticSymbolResolver(compilerHost, symbolCache, summaryResolver);
  26868. const /** @type {?} */ staticReflector = new StaticReflector(summaryResolver, symbolResolver, [], [], errorCollector);
  26869. const /** @type {?} */ htmlParser = new I18NHtmlParser(new HtmlParser(), translations, options.i18nFormat, options.missingTranslation, console);
  26870. const /** @type {?} */ config = new CompilerConfig({
  26871. defaultEncapsulation: ViewEncapsulation.Emulated,
  26872. useJit: false,
  26873. enableLegacyTemplate: options.enableLegacyTemplate === true,
  26874. missingTranslation: options.missingTranslation,
  26875. preserveWhitespaces: options.preserveWhitespaces,
  26876. strictInjectionParameters: options.strictInjectionParameters,
  26877. });
  26878. const /** @type {?} */ normalizer = new DirectiveNormalizer({ get: (url) => compilerHost.loadResource(url) }, urlResolver, htmlParser, config);
  26879. const /** @type {?} */ expressionParser = new Parser(new Lexer());
  26880. const /** @type {?} */ elementSchemaRegistry = new DomElementSchemaRegistry();
  26881. const /** @type {?} */ tmplParser = new TemplateParser(config, staticReflector, expressionParser, elementSchemaRegistry, htmlParser, console, []);
  26882. const /** @type {?} */ resolver = new CompileMetadataResolver(config, htmlParser, new NgModuleResolver(staticReflector), new DirectiveResolver(staticReflector), new PipeResolver(staticReflector), summaryResolver, elementSchemaRegistry, normalizer, console, symbolCache, staticReflector, errorCollector);
  26883. // TODO(vicb): do not pass options.i18nFormat here
  26884. const /** @type {?} */ viewCompiler = new ViewCompiler(staticReflector);
  26885. const /** @type {?} */ typeCheckCompiler = new TypeCheckCompiler(options, staticReflector);
  26886. const /** @type {?} */ compiler = new AotCompiler(config, options, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver), viewCompiler, typeCheckCompiler, new NgModuleCompiler(staticReflector), new TypeScriptEmitter(), summaryResolver, symbolResolver);
  26887. return { compiler, reflector: staticReflector };
  26888. }
  26889. /**
  26890. * @fileoverview added by tsickle
  26891. * @suppress {checkTypes} checked by tsc
  26892. */
  26893. /**
  26894. * @record
  26895. * @template T
  26896. */
  26897. /**
  26898. * @abstract
  26899. * @template T
  26900. */
  26901. class SummaryResolver {
  26902. }
  26903. class JitSummaryResolver {
  26904. constructor() {
  26905. this._summaries = new Map();
  26906. }
  26907. /**
  26908. * @return {?}
  26909. */
  26910. isLibraryFile() { return false; }
  26911. /**
  26912. * @param {?} fileName
  26913. * @return {?}
  26914. */
  26915. toSummaryFileName(fileName) { return fileName; }
  26916. /**
  26917. * @param {?} fileName
  26918. * @return {?}
  26919. */
  26920. fromSummaryFileName(fileName) { return fileName; }
  26921. /**
  26922. * @param {?} reference
  26923. * @return {?}
  26924. */
  26925. resolveSummary(reference) {
  26926. return this._summaries.get(reference) || null;
  26927. }
  26928. /**
  26929. * @return {?}
  26930. */
  26931. getSymbolsOf() { return []; }
  26932. /**
  26933. * @param {?} reference
  26934. * @return {?}
  26935. */
  26936. getImportAs(reference) { return reference; }
  26937. /**
  26938. * @param {?} fileName
  26939. * @return {?}
  26940. */
  26941. getKnownModuleName(fileName) { return null; }
  26942. /**
  26943. * @param {?} summary
  26944. * @return {?}
  26945. */
  26946. addSummary(summary) { this._summaries.set(summary.symbol, summary); }
  26947. }
  26948. /**
  26949. * @fileoverview added by tsickle
  26950. * @suppress {checkTypes} checked by tsc
  26951. */
  26952. /**
  26953. * @license
  26954. * Copyright Google Inc. All Rights Reserved.
  26955. *
  26956. * Use of this source code is governed by an MIT-style license that can be
  26957. * found in the LICENSE file at https://angular.io/license
  26958. */
  26959. /**
  26960. * @param {?} statements
  26961. * @param {?} reflector
  26962. * @return {?}
  26963. */
  26964. function interpretStatements(statements, reflector) {
  26965. const /** @type {?} */ ctx = new _ExecutionContext(null, null, null, new Map());
  26966. const /** @type {?} */ visitor = new StatementInterpreter(reflector);
  26967. visitor.visitAllStatements(statements, ctx);
  26968. const /** @type {?} */ result = {};
  26969. ctx.exports.forEach((exportName) => { result[exportName] = ctx.vars.get(exportName); });
  26970. return result;
  26971. }
  26972. /**
  26973. * @param {?} varNames
  26974. * @param {?} varValues
  26975. * @param {?} statements
  26976. * @param {?} ctx
  26977. * @param {?} visitor
  26978. * @return {?}
  26979. */
  26980. function _executeFunctionStatements(varNames, varValues, statements, ctx, visitor) {
  26981. const /** @type {?} */ childCtx = ctx.createChildWihtLocalVars();
  26982. for (let /** @type {?} */ i = 0; i < varNames.length; i++) {
  26983. childCtx.vars.set(varNames[i], varValues[i]);
  26984. }
  26985. const /** @type {?} */ result = visitor.visitAllStatements(statements, childCtx);
  26986. return result ? result.value : null;
  26987. }
  26988. class _ExecutionContext {
  26989. /**
  26990. * @param {?} parent
  26991. * @param {?} instance
  26992. * @param {?} className
  26993. * @param {?} vars
  26994. */
  26995. constructor(parent, instance, className, vars) {
  26996. this.parent = parent;
  26997. this.instance = instance;
  26998. this.className = className;
  26999. this.vars = vars;
  27000. this.exports = [];
  27001. }
  27002. /**
  27003. * @return {?}
  27004. */
  27005. createChildWihtLocalVars() {
  27006. return new _ExecutionContext(this, this.instance, this.className, new Map());
  27007. }
  27008. }
  27009. class ReturnValue {
  27010. /**
  27011. * @param {?} value
  27012. */
  27013. constructor(value) {
  27014. this.value = value;
  27015. }
  27016. }
  27017. /**
  27018. * @param {?} _classStmt
  27019. * @param {?} _ctx
  27020. * @param {?} _visitor
  27021. * @return {?}
  27022. */
  27023. function createDynamicClass(_classStmt, _ctx, _visitor) {
  27024. const /** @type {?} */ propertyDescriptors = {};
  27025. _classStmt.getters.forEach((getter) => {
  27026. // Note: use `function` instead of arrow function to capture `this`
  27027. propertyDescriptors[getter.name] = {
  27028. configurable: false,
  27029. get: function () {
  27030. const /** @type {?} */ instanceCtx = new _ExecutionContext(_ctx, this, _classStmt.name, _ctx.vars);
  27031. return _executeFunctionStatements([], [], getter.body, instanceCtx, _visitor);
  27032. }
  27033. };
  27034. });
  27035. _classStmt.methods.forEach(function (method) {
  27036. const /** @type {?} */ paramNames = method.params.map(param => param.name);
  27037. // Note: use `function` instead of arrow function to capture `this`
  27038. propertyDescriptors[/** @type {?} */ ((method.name))] = {
  27039. writable: false,
  27040. configurable: false,
  27041. value: function (...args) {
  27042. const /** @type {?} */ instanceCtx = new _ExecutionContext(_ctx, this, _classStmt.name, _ctx.vars);
  27043. return _executeFunctionStatements(paramNames, args, method.body, instanceCtx, _visitor);
  27044. }
  27045. };
  27046. });
  27047. const /** @type {?} */ ctorParamNames = _classStmt.constructorMethod.params.map(param => param.name);
  27048. // Note: use `function` instead of arrow function to capture `this`
  27049. const /** @type {?} */ ctor = function (...args) {
  27050. const /** @type {?} */ instanceCtx = new _ExecutionContext(_ctx, this, _classStmt.name, _ctx.vars);
  27051. _classStmt.fields.forEach((field) => { this[field.name] = undefined; });
  27052. _executeFunctionStatements(ctorParamNames, args, _classStmt.constructorMethod.body, instanceCtx, _visitor);
  27053. };
  27054. const /** @type {?} */ superClass = _classStmt.parent ? _classStmt.parent.visitExpression(_visitor, _ctx) : Object;
  27055. ctor.prototype = Object.create(superClass.prototype, propertyDescriptors);
  27056. return ctor;
  27057. }
  27058. class StatementInterpreter {
  27059. /**
  27060. * @param {?} reflector
  27061. */
  27062. constructor(reflector) {
  27063. this.reflector = reflector;
  27064. }
  27065. /**
  27066. * @param {?} ast
  27067. * @return {?}
  27068. */
  27069. debugAst(ast) { return debugOutputAstAsTypeScript(ast); }
  27070. /**
  27071. * @param {?} stmt
  27072. * @param {?} ctx
  27073. * @return {?}
  27074. */
  27075. visitDeclareVarStmt(stmt, ctx) {
  27076. ctx.vars.set(stmt.name, stmt.value.visitExpression(this, ctx));
  27077. if (stmt.hasModifier(StmtModifier.Exported)) {
  27078. ctx.exports.push(stmt.name);
  27079. }
  27080. return null;
  27081. }
  27082. /**
  27083. * @param {?} expr
  27084. * @param {?} ctx
  27085. * @return {?}
  27086. */
  27087. visitWriteVarExpr(expr, ctx) {
  27088. const /** @type {?} */ value = expr.value.visitExpression(this, ctx);
  27089. let /** @type {?} */ currCtx = ctx;
  27090. while (currCtx != null) {
  27091. if (currCtx.vars.has(expr.name)) {
  27092. currCtx.vars.set(expr.name, value);
  27093. return value;
  27094. }
  27095. currCtx = /** @type {?} */ ((currCtx.parent));
  27096. }
  27097. throw new Error(`Not declared variable ${expr.name}`);
  27098. }
  27099. /**
  27100. * @param {?} ast
  27101. * @param {?} ctx
  27102. * @return {?}
  27103. */
  27104. visitReadVarExpr(ast, ctx) {
  27105. let /** @type {?} */ varName = /** @type {?} */ ((ast.name));
  27106. if (ast.builtin != null) {
  27107. switch (ast.builtin) {
  27108. case BuiltinVar.Super:
  27109. return ctx.instance.__proto__;
  27110. case BuiltinVar.This:
  27111. return ctx.instance;
  27112. case BuiltinVar.CatchError:
  27113. varName = CATCH_ERROR_VAR$2;
  27114. break;
  27115. case BuiltinVar.CatchStack:
  27116. varName = CATCH_STACK_VAR$2;
  27117. break;
  27118. default:
  27119. throw new Error(`Unknown builtin variable ${ast.builtin}`);
  27120. }
  27121. }
  27122. let /** @type {?} */ currCtx = ctx;
  27123. while (currCtx != null) {
  27124. if (currCtx.vars.has(varName)) {
  27125. return currCtx.vars.get(varName);
  27126. }
  27127. currCtx = /** @type {?} */ ((currCtx.parent));
  27128. }
  27129. throw new Error(`Not declared variable ${varName}`);
  27130. }
  27131. /**
  27132. * @param {?} expr
  27133. * @param {?} ctx
  27134. * @return {?}
  27135. */
  27136. visitWriteKeyExpr(expr, ctx) {
  27137. const /** @type {?} */ receiver = expr.receiver.visitExpression(this, ctx);
  27138. const /** @type {?} */ index = expr.index.visitExpression(this, ctx);
  27139. const /** @type {?} */ value = expr.value.visitExpression(this, ctx);
  27140. receiver[index] = value;
  27141. return value;
  27142. }
  27143. /**
  27144. * @param {?} expr
  27145. * @param {?} ctx
  27146. * @return {?}
  27147. */
  27148. visitWritePropExpr(expr, ctx) {
  27149. const /** @type {?} */ receiver = expr.receiver.visitExpression(this, ctx);
  27150. const /** @type {?} */ value = expr.value.visitExpression(this, ctx);
  27151. receiver[expr.name] = value;
  27152. return value;
  27153. }
  27154. /**
  27155. * @param {?} expr
  27156. * @param {?} ctx
  27157. * @return {?}
  27158. */
  27159. visitInvokeMethodExpr(expr, ctx) {
  27160. const /** @type {?} */ receiver = expr.receiver.visitExpression(this, ctx);
  27161. const /** @type {?} */ args = this.visitAllExpressions(expr.args, ctx);
  27162. let /** @type {?} */ result;
  27163. if (expr.builtin != null) {
  27164. switch (expr.builtin) {
  27165. case BuiltinMethod.ConcatArray:
  27166. result = receiver.concat(...args);
  27167. break;
  27168. case BuiltinMethod.SubscribeObservable:
  27169. result = receiver.subscribe({ next: args[0] });
  27170. break;
  27171. case BuiltinMethod.Bind:
  27172. result = receiver.bind(...args);
  27173. break;
  27174. default:
  27175. throw new Error(`Unknown builtin method ${expr.builtin}`);
  27176. }
  27177. }
  27178. else {
  27179. result = receiver[/** @type {?} */ ((expr.name))].apply(receiver, args);
  27180. }
  27181. return result;
  27182. }
  27183. /**
  27184. * @param {?} stmt
  27185. * @param {?} ctx
  27186. * @return {?}
  27187. */
  27188. visitInvokeFunctionExpr(stmt, ctx) {
  27189. const /** @type {?} */ args = this.visitAllExpressions(stmt.args, ctx);
  27190. const /** @type {?} */ fnExpr = stmt.fn;
  27191. if (fnExpr instanceof ReadVarExpr && fnExpr.builtin === BuiltinVar.Super) {
  27192. ctx.instance.constructor.prototype.constructor.apply(ctx.instance, args);
  27193. return null;
  27194. }
  27195. else {
  27196. const /** @type {?} */ fn$$1 = stmt.fn.visitExpression(this, ctx);
  27197. return fn$$1.apply(null, args);
  27198. }
  27199. }
  27200. /**
  27201. * @param {?} stmt
  27202. * @param {?} ctx
  27203. * @return {?}
  27204. */
  27205. visitReturnStmt(stmt, ctx) {
  27206. return new ReturnValue(stmt.value.visitExpression(this, ctx));
  27207. }
  27208. /**
  27209. * @param {?} stmt
  27210. * @param {?} ctx
  27211. * @return {?}
  27212. */
  27213. visitDeclareClassStmt(stmt, ctx) {
  27214. const /** @type {?} */ clazz = createDynamicClass(stmt, ctx, this);
  27215. ctx.vars.set(stmt.name, clazz);
  27216. if (stmt.hasModifier(StmtModifier.Exported)) {
  27217. ctx.exports.push(stmt.name);
  27218. }
  27219. return null;
  27220. }
  27221. /**
  27222. * @param {?} stmt
  27223. * @param {?} ctx
  27224. * @return {?}
  27225. */
  27226. visitExpressionStmt(stmt, ctx) {
  27227. return stmt.expr.visitExpression(this, ctx);
  27228. }
  27229. /**
  27230. * @param {?} stmt
  27231. * @param {?} ctx
  27232. * @return {?}
  27233. */
  27234. visitIfStmt(stmt, ctx) {
  27235. const /** @type {?} */ condition = stmt.condition.visitExpression(this, ctx);
  27236. if (condition) {
  27237. return this.visitAllStatements(stmt.trueCase, ctx);
  27238. }
  27239. else if (stmt.falseCase != null) {
  27240. return this.visitAllStatements(stmt.falseCase, ctx);
  27241. }
  27242. return null;
  27243. }
  27244. /**
  27245. * @param {?} stmt
  27246. * @param {?} ctx
  27247. * @return {?}
  27248. */
  27249. visitTryCatchStmt(stmt, ctx) {
  27250. try {
  27251. return this.visitAllStatements(stmt.bodyStmts, ctx);
  27252. }
  27253. catch (/** @type {?} */ e) {
  27254. const /** @type {?} */ childCtx = ctx.createChildWihtLocalVars();
  27255. childCtx.vars.set(CATCH_ERROR_VAR$2, e);
  27256. childCtx.vars.set(CATCH_STACK_VAR$2, e.stack);
  27257. return this.visitAllStatements(stmt.catchStmts, childCtx);
  27258. }
  27259. }
  27260. /**
  27261. * @param {?} stmt
  27262. * @param {?} ctx
  27263. * @return {?}
  27264. */
  27265. visitThrowStmt(stmt, ctx) {
  27266. throw stmt.error.visitExpression(this, ctx);
  27267. }
  27268. /**
  27269. * @param {?} stmt
  27270. * @param {?=} context
  27271. * @return {?}
  27272. */
  27273. visitCommentStmt(stmt, context) { return null; }
  27274. /**
  27275. * @param {?} ast
  27276. * @param {?} ctx
  27277. * @return {?}
  27278. */
  27279. visitInstantiateExpr(ast, ctx) {
  27280. const /** @type {?} */ args = this.visitAllExpressions(ast.args, ctx);
  27281. const /** @type {?} */ clazz = ast.classExpr.visitExpression(this, ctx);
  27282. return new clazz(...args);
  27283. }
  27284. /**
  27285. * @param {?} ast
  27286. * @param {?} ctx
  27287. * @return {?}
  27288. */
  27289. visitLiteralExpr(ast, ctx) { return ast.value; }
  27290. /**
  27291. * @param {?} ast
  27292. * @param {?} ctx
  27293. * @return {?}
  27294. */
  27295. visitExternalExpr(ast, ctx) {
  27296. return this.reflector.resolveExternalReference(ast.value);
  27297. }
  27298. /**
  27299. * @param {?} ast
  27300. * @param {?} ctx
  27301. * @return {?}
  27302. */
  27303. visitConditionalExpr(ast, ctx) {
  27304. if (ast.condition.visitExpression(this, ctx)) {
  27305. return ast.trueCase.visitExpression(this, ctx);
  27306. }
  27307. else if (ast.falseCase != null) {
  27308. return ast.falseCase.visitExpression(this, ctx);
  27309. }
  27310. return null;
  27311. }
  27312. /**
  27313. * @param {?} ast
  27314. * @param {?} ctx
  27315. * @return {?}
  27316. */
  27317. visitNotExpr(ast, ctx) {
  27318. return !ast.condition.visitExpression(this, ctx);
  27319. }
  27320. /**
  27321. * @param {?} ast
  27322. * @param {?} ctx
  27323. * @return {?}
  27324. */
  27325. visitAssertNotNullExpr(ast, ctx) {
  27326. return ast.condition.visitExpression(this, ctx);
  27327. }
  27328. /**
  27329. * @param {?} ast
  27330. * @param {?} ctx
  27331. * @return {?}
  27332. */
  27333. visitCastExpr(ast, ctx) {
  27334. return ast.value.visitExpression(this, ctx);
  27335. }
  27336. /**
  27337. * @param {?} ast
  27338. * @param {?} ctx
  27339. * @return {?}
  27340. */
  27341. visitFunctionExpr(ast, ctx) {
  27342. const /** @type {?} */ paramNames = ast.params.map((param) => param.name);
  27343. return _declareFn(paramNames, ast.statements, ctx, this);
  27344. }
  27345. /**
  27346. * @param {?} stmt
  27347. * @param {?} ctx
  27348. * @return {?}
  27349. */
  27350. visitDeclareFunctionStmt(stmt, ctx) {
  27351. const /** @type {?} */ paramNames = stmt.params.map((param) => param.name);
  27352. ctx.vars.set(stmt.name, _declareFn(paramNames, stmt.statements, ctx, this));
  27353. if (stmt.hasModifier(StmtModifier.Exported)) {
  27354. ctx.exports.push(stmt.name);
  27355. }
  27356. return null;
  27357. }
  27358. /**
  27359. * @param {?} ast
  27360. * @param {?} ctx
  27361. * @return {?}
  27362. */
  27363. visitBinaryOperatorExpr(ast, ctx) {
  27364. const /** @type {?} */ lhs = () => ast.lhs.visitExpression(this, ctx);
  27365. const /** @type {?} */ rhs = () => ast.rhs.visitExpression(this, ctx);
  27366. switch (ast.operator) {
  27367. case BinaryOperator.Equals:
  27368. return lhs() == rhs();
  27369. case BinaryOperator.Identical:
  27370. return lhs() === rhs();
  27371. case BinaryOperator.NotEquals:
  27372. return lhs() != rhs();
  27373. case BinaryOperator.NotIdentical:
  27374. return lhs() !== rhs();
  27375. case BinaryOperator.And:
  27376. return lhs() && rhs();
  27377. case BinaryOperator.Or:
  27378. return lhs() || rhs();
  27379. case BinaryOperator.Plus:
  27380. return lhs() + rhs();
  27381. case BinaryOperator.Minus:
  27382. return lhs() - rhs();
  27383. case BinaryOperator.Divide:
  27384. return lhs() / rhs();
  27385. case BinaryOperator.Multiply:
  27386. return lhs() * rhs();
  27387. case BinaryOperator.Modulo:
  27388. return lhs() % rhs();
  27389. case BinaryOperator.Lower:
  27390. return lhs() < rhs();
  27391. case BinaryOperator.LowerEquals:
  27392. return lhs() <= rhs();
  27393. case BinaryOperator.Bigger:
  27394. return lhs() > rhs();
  27395. case BinaryOperator.BiggerEquals:
  27396. return lhs() >= rhs();
  27397. default:
  27398. throw new Error(`Unknown operator ${ast.operator}`);
  27399. }
  27400. }
  27401. /**
  27402. * @param {?} ast
  27403. * @param {?} ctx
  27404. * @return {?}
  27405. */
  27406. visitReadPropExpr(ast, ctx) {
  27407. let /** @type {?} */ result;
  27408. const /** @type {?} */ receiver = ast.receiver.visitExpression(this, ctx);
  27409. result = receiver[ast.name];
  27410. return result;
  27411. }
  27412. /**
  27413. * @param {?} ast
  27414. * @param {?} ctx
  27415. * @return {?}
  27416. */
  27417. visitReadKeyExpr(ast, ctx) {
  27418. const /** @type {?} */ receiver = ast.receiver.visitExpression(this, ctx);
  27419. const /** @type {?} */ prop = ast.index.visitExpression(this, ctx);
  27420. return receiver[prop];
  27421. }
  27422. /**
  27423. * @param {?} ast
  27424. * @param {?} ctx
  27425. * @return {?}
  27426. */
  27427. visitLiteralArrayExpr(ast, ctx) {
  27428. return this.visitAllExpressions(ast.entries, ctx);
  27429. }
  27430. /**
  27431. * @param {?} ast
  27432. * @param {?} ctx
  27433. * @return {?}
  27434. */
  27435. visitLiteralMapExpr(ast, ctx) {
  27436. const /** @type {?} */ result = {};
  27437. ast.entries.forEach(entry => result[entry.key] = entry.value.visitExpression(this, ctx));
  27438. return result;
  27439. }
  27440. /**
  27441. * @param {?} ast
  27442. * @param {?} context
  27443. * @return {?}
  27444. */
  27445. visitCommaExpr(ast, context) {
  27446. const /** @type {?} */ values = this.visitAllExpressions(ast.parts, context);
  27447. return values[values.length - 1];
  27448. }
  27449. /**
  27450. * @param {?} expressions
  27451. * @param {?} ctx
  27452. * @return {?}
  27453. */
  27454. visitAllExpressions(expressions, ctx) {
  27455. return expressions.map((expr) => expr.visitExpression(this, ctx));
  27456. }
  27457. /**
  27458. * @param {?} statements
  27459. * @param {?} ctx
  27460. * @return {?}
  27461. */
  27462. visitAllStatements(statements, ctx) {
  27463. for (let /** @type {?} */ i = 0; i < statements.length; i++) {
  27464. const /** @type {?} */ stmt = statements[i];
  27465. const /** @type {?} */ val = stmt.visitStatement(this, ctx);
  27466. if (val instanceof ReturnValue) {
  27467. return val;
  27468. }
  27469. }
  27470. return null;
  27471. }
  27472. }
  27473. /**
  27474. * @param {?} varNames
  27475. * @param {?} statements
  27476. * @param {?} ctx
  27477. * @param {?} visitor
  27478. * @return {?}
  27479. */
  27480. function _declareFn(varNames, statements, ctx, visitor) {
  27481. return (...args) => _executeFunctionStatements(varNames, args, statements, ctx, visitor);
  27482. }
  27483. const CATCH_ERROR_VAR$2 = 'error';
  27484. const CATCH_STACK_VAR$2 = 'stack';
  27485. /**
  27486. * @fileoverview added by tsickle
  27487. * @suppress {checkTypes} checked by tsc
  27488. */
  27489. /**
  27490. * @license
  27491. * Copyright Google Inc. All Rights Reserved.
  27492. *
  27493. * Use of this source code is governed by an MIT-style license that can be
  27494. * found in the LICENSE file at https://angular.io/license
  27495. */
  27496. /**
  27497. * @abstract
  27498. */
  27499. class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
  27500. constructor() { super(false); }
  27501. /**
  27502. * @param {?} stmt
  27503. * @param {?} ctx
  27504. * @return {?}
  27505. */
  27506. visitDeclareClassStmt(stmt, ctx) {
  27507. ctx.pushClass(stmt);
  27508. this._visitClassConstructor(stmt, ctx);
  27509. if (stmt.parent != null) {
  27510. ctx.print(stmt, `${stmt.name}.prototype = Object.create(`);
  27511. stmt.parent.visitExpression(this, ctx);
  27512. ctx.println(stmt, `.prototype);`);
  27513. }
  27514. stmt.getters.forEach((getter) => this._visitClassGetter(stmt, getter, ctx));
  27515. stmt.methods.forEach((method) => this._visitClassMethod(stmt, method, ctx));
  27516. ctx.popClass();
  27517. return null;
  27518. }
  27519. /**
  27520. * @param {?} stmt
  27521. * @param {?} ctx
  27522. * @return {?}
  27523. */
  27524. _visitClassConstructor(stmt, ctx) {
  27525. ctx.print(stmt, `function ${stmt.name}(`);
  27526. if (stmt.constructorMethod != null) {
  27527. this._visitParams(stmt.constructorMethod.params, ctx);
  27528. }
  27529. ctx.println(stmt, `) {`);
  27530. ctx.incIndent();
  27531. if (stmt.constructorMethod != null) {
  27532. if (stmt.constructorMethod.body.length > 0) {
  27533. ctx.println(stmt, `var self = this;`);
  27534. this.visitAllStatements(stmt.constructorMethod.body, ctx);
  27535. }
  27536. }
  27537. ctx.decIndent();
  27538. ctx.println(stmt, `}`);
  27539. }
  27540. /**
  27541. * @param {?} stmt
  27542. * @param {?} getter
  27543. * @param {?} ctx
  27544. * @return {?}
  27545. */
  27546. _visitClassGetter(stmt, getter, ctx) {
  27547. ctx.println(stmt, `Object.defineProperty(${stmt.name}.prototype, '${getter.name}', { get: function() {`);
  27548. ctx.incIndent();
  27549. if (getter.body.length > 0) {
  27550. ctx.println(stmt, `var self = this;`);
  27551. this.visitAllStatements(getter.body, ctx);
  27552. }
  27553. ctx.decIndent();
  27554. ctx.println(stmt, `}});`);
  27555. }
  27556. /**
  27557. * @param {?} stmt
  27558. * @param {?} method
  27559. * @param {?} ctx
  27560. * @return {?}
  27561. */
  27562. _visitClassMethod(stmt, method, ctx) {
  27563. ctx.print(stmt, `${stmt.name}.prototype.${method.name} = function(`);
  27564. this._visitParams(method.params, ctx);
  27565. ctx.println(stmt, `) {`);
  27566. ctx.incIndent();
  27567. if (method.body.length > 0) {
  27568. ctx.println(stmt, `var self = this;`);
  27569. this.visitAllStatements(method.body, ctx);
  27570. }
  27571. ctx.decIndent();
  27572. ctx.println(stmt, `};`);
  27573. }
  27574. /**
  27575. * @param {?} ast
  27576. * @param {?} ctx
  27577. * @return {?}
  27578. */
  27579. visitReadVarExpr(ast, ctx) {
  27580. if (ast.builtin === BuiltinVar.This) {
  27581. ctx.print(ast, 'self');
  27582. }
  27583. else if (ast.builtin === BuiltinVar.Super) {
  27584. throw new Error(`'super' needs to be handled at a parent ast node, not at the variable level!`);
  27585. }
  27586. else {
  27587. super.visitReadVarExpr(ast, ctx);
  27588. }
  27589. return null;
  27590. }
  27591. /**
  27592. * @param {?} stmt
  27593. * @param {?} ctx
  27594. * @return {?}
  27595. */
  27596. visitDeclareVarStmt(stmt, ctx) {
  27597. ctx.print(stmt, `var ${stmt.name} = `);
  27598. stmt.value.visitExpression(this, ctx);
  27599. ctx.println(stmt, `;`);
  27600. return null;
  27601. }
  27602. /**
  27603. * @param {?} ast
  27604. * @param {?} ctx
  27605. * @return {?}
  27606. */
  27607. visitCastExpr(ast, ctx) {
  27608. ast.value.visitExpression(this, ctx);
  27609. return null;
  27610. }
  27611. /**
  27612. * @param {?} expr
  27613. * @param {?} ctx
  27614. * @return {?}
  27615. */
  27616. visitInvokeFunctionExpr(expr, ctx) {
  27617. const /** @type {?} */ fnExpr = expr.fn;
  27618. if (fnExpr instanceof ReadVarExpr && fnExpr.builtin === BuiltinVar.Super) {
  27619. /** @type {?} */ ((/** @type {?} */ ((ctx.currentClass)).parent)).visitExpression(this, ctx);
  27620. ctx.print(expr, `.call(this`);
  27621. if (expr.args.length > 0) {
  27622. ctx.print(expr, `, `);
  27623. this.visitAllExpressions(expr.args, ctx, ',');
  27624. }
  27625. ctx.print(expr, `)`);
  27626. }
  27627. else {
  27628. super.visitInvokeFunctionExpr(expr, ctx);
  27629. }
  27630. return null;
  27631. }
  27632. /**
  27633. * @param {?} ast
  27634. * @param {?} ctx
  27635. * @return {?}
  27636. */
  27637. visitFunctionExpr(ast, ctx) {
  27638. ctx.print(ast, `function(`);
  27639. this._visitParams(ast.params, ctx);
  27640. ctx.println(ast, `) {`);
  27641. ctx.incIndent();
  27642. this.visitAllStatements(ast.statements, ctx);
  27643. ctx.decIndent();
  27644. ctx.print(ast, `}`);
  27645. return null;
  27646. }
  27647. /**
  27648. * @param {?} stmt
  27649. * @param {?} ctx
  27650. * @return {?}
  27651. */
  27652. visitDeclareFunctionStmt(stmt, ctx) {
  27653. ctx.print(stmt, `function ${stmt.name}(`);
  27654. this._visitParams(stmt.params, ctx);
  27655. ctx.println(stmt, `) {`);
  27656. ctx.incIndent();
  27657. this.visitAllStatements(stmt.statements, ctx);
  27658. ctx.decIndent();
  27659. ctx.println(stmt, `}`);
  27660. return null;
  27661. }
  27662. /**
  27663. * @param {?} stmt
  27664. * @param {?} ctx
  27665. * @return {?}
  27666. */
  27667. visitTryCatchStmt(stmt, ctx) {
  27668. ctx.println(stmt, `try {`);
  27669. ctx.incIndent();
  27670. this.visitAllStatements(stmt.bodyStmts, ctx);
  27671. ctx.decIndent();
  27672. ctx.println(stmt, `} catch (${CATCH_ERROR_VAR$1.name}) {`);
  27673. ctx.incIndent();
  27674. const /** @type {?} */ catchStmts = [/** @type {?} */ (CATCH_STACK_VAR$1.set(CATCH_ERROR_VAR$1.prop('stack')).toDeclStmt(null, [
  27675. StmtModifier.Final
  27676. ]))].concat(stmt.catchStmts);
  27677. this.visitAllStatements(catchStmts, ctx);
  27678. ctx.decIndent();
  27679. ctx.println(stmt, `}`);
  27680. return null;
  27681. }
  27682. /**
  27683. * @param {?} params
  27684. * @param {?} ctx
  27685. * @return {?}
  27686. */
  27687. _visitParams(params, ctx) {
  27688. this.visitAllObjects(param => ctx.print(null, param.name), params, ctx, ',');
  27689. }
  27690. /**
  27691. * @param {?} method
  27692. * @return {?}
  27693. */
  27694. getBuiltinMethodName(method) {
  27695. let /** @type {?} */ name;
  27696. switch (method) {
  27697. case BuiltinMethod.ConcatArray:
  27698. name = 'concat';
  27699. break;
  27700. case BuiltinMethod.SubscribeObservable:
  27701. name = 'subscribe';
  27702. break;
  27703. case BuiltinMethod.Bind:
  27704. name = 'bind';
  27705. break;
  27706. default:
  27707. throw new Error(`Unknown builtin method: ${method}`);
  27708. }
  27709. return name;
  27710. }
  27711. }
  27712. /**
  27713. * @fileoverview added by tsickle
  27714. * @suppress {checkTypes} checked by tsc
  27715. */
  27716. /**
  27717. * @license
  27718. * Copyright Google Inc. All Rights Reserved.
  27719. *
  27720. * Use of this source code is governed by an MIT-style license that can be
  27721. * found in the LICENSE file at https://angular.io/license
  27722. */
  27723. /**
  27724. * @param {?} sourceUrl
  27725. * @param {?} ctx
  27726. * @param {?} vars
  27727. * @param {?} createSourceMap
  27728. * @return {?}
  27729. */
  27730. function evalExpression(sourceUrl, ctx, vars, createSourceMap) {
  27731. let /** @type {?} */ fnBody = `${ctx.toSource()}\n//# sourceURL=${sourceUrl}`;
  27732. const /** @type {?} */ fnArgNames = [];
  27733. const /** @type {?} */ fnArgValues = [];
  27734. for (const /** @type {?} */ argName in vars) {
  27735. fnArgNames.push(argName);
  27736. fnArgValues.push(vars[argName]);
  27737. }
  27738. if (createSourceMap) {
  27739. // using `new Function(...)` generates a header, 1 line of no arguments, 2 lines otherwise
  27740. // E.g. ```
  27741. // function anonymous(a,b,c
  27742. // /**/) { ... }```
  27743. // We don't want to hard code this fact, so we auto detect it via an empty function first.
  27744. const /** @type {?} */ emptyFn = new Function(...fnArgNames.concat('return null;')).toString();
  27745. const /** @type {?} */ headerLines = emptyFn.slice(0, emptyFn.indexOf('return null;')).split('\n').length - 1;
  27746. fnBody += `\n${ctx.toSourceMapGenerator(sourceUrl, headerLines).toJsComment()}`;
  27747. }
  27748. return new Function(...fnArgNames.concat(fnBody))(...fnArgValues);
  27749. }
  27750. /**
  27751. * @param {?} sourceUrl
  27752. * @param {?} statements
  27753. * @param {?} reflector
  27754. * @param {?} createSourceMaps
  27755. * @return {?}
  27756. */
  27757. function jitStatements(sourceUrl, statements, reflector, createSourceMaps) {
  27758. const /** @type {?} */ converter = new JitEmitterVisitor(reflector);
  27759. const /** @type {?} */ ctx = EmitterVisitorContext.createRoot();
  27760. converter.visitAllStatements(statements, ctx);
  27761. converter.createReturnStmt(ctx);
  27762. return evalExpression(sourceUrl, ctx, converter.getArgs(), createSourceMaps);
  27763. }
  27764. class JitEmitterVisitor extends AbstractJsEmitterVisitor {
  27765. /**
  27766. * @param {?} reflector
  27767. */
  27768. constructor(reflector) {
  27769. super();
  27770. this.reflector = reflector;
  27771. this._evalArgNames = [];
  27772. this._evalArgValues = [];
  27773. this._evalExportedVars = [];
  27774. }
  27775. /**
  27776. * @param {?} ctx
  27777. * @return {?}
  27778. */
  27779. createReturnStmt(ctx) {
  27780. const /** @type {?} */ stmt = new ReturnStatement(new LiteralMapExpr(this._evalExportedVars.map(resultVar => new LiteralMapEntry(resultVar, variable(resultVar), false))));
  27781. stmt.visitStatement(this, ctx);
  27782. }
  27783. /**
  27784. * @return {?}
  27785. */
  27786. getArgs() {
  27787. const /** @type {?} */ result = {};
  27788. for (let /** @type {?} */ i = 0; i < this._evalArgNames.length; i++) {
  27789. result[this._evalArgNames[i]] = this._evalArgValues[i];
  27790. }
  27791. return result;
  27792. }
  27793. /**
  27794. * @param {?} ast
  27795. * @param {?} ctx
  27796. * @return {?}
  27797. */
  27798. visitExternalExpr(ast, ctx) {
  27799. const /** @type {?} */ value = this.reflector.resolveExternalReference(ast.value);
  27800. let /** @type {?} */ id = this._evalArgValues.indexOf(value);
  27801. if (id === -1) {
  27802. id = this._evalArgValues.length;
  27803. this._evalArgValues.push(value);
  27804. const /** @type {?} */ name = identifierName({ reference: value }) || 'val';
  27805. this._evalArgNames.push(`jit_${name}_${id}`);
  27806. }
  27807. ctx.print(ast, this._evalArgNames[id]);
  27808. return null;
  27809. }
  27810. /**
  27811. * @param {?} stmt
  27812. * @param {?} ctx
  27813. * @return {?}
  27814. */
  27815. visitDeclareVarStmt(stmt, ctx) {
  27816. if (stmt.hasModifier(StmtModifier.Exported)) {
  27817. this._evalExportedVars.push(stmt.name);
  27818. }
  27819. return super.visitDeclareVarStmt(stmt, ctx);
  27820. }
  27821. /**
  27822. * @param {?} stmt
  27823. * @param {?} ctx
  27824. * @return {?}
  27825. */
  27826. visitDeclareFunctionStmt(stmt, ctx) {
  27827. if (stmt.hasModifier(StmtModifier.Exported)) {
  27828. this._evalExportedVars.push(stmt.name);
  27829. }
  27830. return super.visitDeclareFunctionStmt(stmt, ctx);
  27831. }
  27832. /**
  27833. * @param {?} stmt
  27834. * @param {?} ctx
  27835. * @return {?}
  27836. */
  27837. visitDeclareClassStmt(stmt, ctx) {
  27838. if (stmt.hasModifier(StmtModifier.Exported)) {
  27839. this._evalExportedVars.push(stmt.name);
  27840. }
  27841. return super.visitDeclareClassStmt(stmt, ctx);
  27842. }
  27843. }
  27844. /**
  27845. * @fileoverview added by tsickle
  27846. * @suppress {checkTypes} checked by tsc
  27847. */
  27848. /**
  27849. * @license
  27850. * Copyright Google Inc. All Rights Reserved.
  27851. *
  27852. * Use of this source code is governed by an MIT-style license that can be
  27853. * found in the LICENSE file at https://angular.io/license
  27854. */
  27855. /**
  27856. * @record
  27857. */
  27858. /**
  27859. * An internal module of the Angular compiler that begins with component types,
  27860. * extracts templates, and eventually produces a compiled version of the component
  27861. * ready for linking into an application.
  27862. *
  27863. * \@security When compiling templates at runtime, you must ensure that the entire template comes
  27864. * from a trusted source. Attacker-controlled data introduced by a template could expose your
  27865. * application to XSS risks. For more detail, see the [Security Guide](http://g.co/ng/security).
  27866. */
  27867. class JitCompiler {
  27868. /**
  27869. * @param {?} _metadataResolver
  27870. * @param {?} _templateParser
  27871. * @param {?} _styleCompiler
  27872. * @param {?} _viewCompiler
  27873. * @param {?} _ngModuleCompiler
  27874. * @param {?} _summaryResolver
  27875. * @param {?} _reflector
  27876. * @param {?} _compilerConfig
  27877. * @param {?} _console
  27878. * @param {?} getExtraNgModuleProviders
  27879. */
  27880. constructor(_metadataResolver, _templateParser, _styleCompiler, _viewCompiler, _ngModuleCompiler, _summaryResolver, _reflector, _compilerConfig, _console, getExtraNgModuleProviders) {
  27881. this._metadataResolver = _metadataResolver;
  27882. this._templateParser = _templateParser;
  27883. this._styleCompiler = _styleCompiler;
  27884. this._viewCompiler = _viewCompiler;
  27885. this._ngModuleCompiler = _ngModuleCompiler;
  27886. this._summaryResolver = _summaryResolver;
  27887. this._reflector = _reflector;
  27888. this._compilerConfig = _compilerConfig;
  27889. this._console = _console;
  27890. this.getExtraNgModuleProviders = getExtraNgModuleProviders;
  27891. this._compiledTemplateCache = new Map();
  27892. this._compiledHostTemplateCache = new Map();
  27893. this._compiledDirectiveWrapperCache = new Map();
  27894. this._compiledNgModuleCache = new Map();
  27895. this._sharedStylesheetCount = 0;
  27896. this._addedAotSummaries = new Set();
  27897. }
  27898. /**
  27899. * @param {?} moduleType
  27900. * @return {?}
  27901. */
  27902. compileModuleSync(moduleType) {
  27903. return SyncAsync.assertSync(this._compileModuleAndComponents(moduleType, true));
  27904. }
  27905. /**
  27906. * @param {?} moduleType
  27907. * @return {?}
  27908. */
  27909. compileModuleAsync(moduleType) {
  27910. return Promise.resolve(this._compileModuleAndComponents(moduleType, false));
  27911. }
  27912. /**
  27913. * @param {?} moduleType
  27914. * @return {?}
  27915. */
  27916. compileModuleAndAllComponentsSync(moduleType) {
  27917. return SyncAsync.assertSync(this._compileModuleAndAllComponents(moduleType, true));
  27918. }
  27919. /**
  27920. * @param {?} moduleType
  27921. * @return {?}
  27922. */
  27923. compileModuleAndAllComponentsAsync(moduleType) {
  27924. return Promise.resolve(this._compileModuleAndAllComponents(moduleType, false));
  27925. }
  27926. /**
  27927. * @param {?} component
  27928. * @return {?}
  27929. */
  27930. getComponentFactory(component) {
  27931. const /** @type {?} */ summary = this._metadataResolver.getDirectiveSummary(component);
  27932. return /** @type {?} */ (summary.componentFactory);
  27933. }
  27934. /**
  27935. * @param {?} summaries
  27936. * @return {?}
  27937. */
  27938. loadAotSummaries(summaries) {
  27939. this.clearCache();
  27940. this._addAotSummaries(summaries);
  27941. }
  27942. /**
  27943. * @param {?} fn
  27944. * @return {?}
  27945. */
  27946. _addAotSummaries(fn$$1) {
  27947. if (this._addedAotSummaries.has(fn$$1)) {
  27948. return;
  27949. }
  27950. this._addedAotSummaries.add(fn$$1);
  27951. const /** @type {?} */ summaries = fn$$1();
  27952. for (let /** @type {?} */ i = 0; i < summaries.length; i++) {
  27953. const /** @type {?} */ entry = summaries[i];
  27954. if (typeof entry === 'function') {
  27955. this._addAotSummaries(entry);
  27956. }
  27957. else {
  27958. const /** @type {?} */ summary = /** @type {?} */ (entry);
  27959. this._summaryResolver.addSummary({ symbol: summary.type.reference, metadata: null, type: summary });
  27960. }
  27961. }
  27962. }
  27963. /**
  27964. * @param {?} ref
  27965. * @return {?}
  27966. */
  27967. hasAotSummary(ref) { return !!this._summaryResolver.resolveSummary(ref); }
  27968. /**
  27969. * @param {?} ids
  27970. * @return {?}
  27971. */
  27972. _filterJitIdentifiers(ids) {
  27973. return ids.map(mod => mod.reference).filter((ref) => !this.hasAotSummary(ref));
  27974. }
  27975. /**
  27976. * @param {?} moduleType
  27977. * @param {?} isSync
  27978. * @return {?}
  27979. */
  27980. _compileModuleAndComponents(moduleType, isSync) {
  27981. return SyncAsync.then(this._loadModules(moduleType, isSync), () => {
  27982. this._compileComponents(moduleType, null);
  27983. return this._compileModule(moduleType);
  27984. });
  27985. }
  27986. /**
  27987. * @param {?} moduleType
  27988. * @param {?} isSync
  27989. * @return {?}
  27990. */
  27991. _compileModuleAndAllComponents(moduleType, isSync) {
  27992. return SyncAsync.then(this._loadModules(moduleType, isSync), () => {
  27993. const /** @type {?} */ componentFactories = [];
  27994. this._compileComponents(moduleType, componentFactories);
  27995. return {
  27996. ngModuleFactory: this._compileModule(moduleType),
  27997. componentFactories: componentFactories
  27998. };
  27999. });
  28000. }
  28001. /**
  28002. * @param {?} mainModule
  28003. * @param {?} isSync
  28004. * @return {?}
  28005. */
  28006. _loadModules(mainModule, isSync) {
  28007. const /** @type {?} */ loading = [];
  28008. const /** @type {?} */ mainNgModule = /** @type {?} */ ((this._metadataResolver.getNgModuleMetadata(mainModule)));
  28009. // Note: for runtime compilation, we want to transitively compile all modules,
  28010. // so we also need to load the declared directives / pipes for all nested modules.
  28011. this._filterJitIdentifiers(mainNgModule.transitiveModule.modules).forEach((nestedNgModule) => {
  28012. // getNgModuleMetadata only returns null if the value passed in is not an NgModule
  28013. const /** @type {?} */ moduleMeta = /** @type {?} */ ((this._metadataResolver.getNgModuleMetadata(nestedNgModule)));
  28014. this._filterJitIdentifiers(moduleMeta.declaredDirectives).forEach((ref) => {
  28015. const /** @type {?} */ promise = this._metadataResolver.loadDirectiveMetadata(moduleMeta.type.reference, ref, isSync);
  28016. if (promise) {
  28017. loading.push(promise);
  28018. }
  28019. });
  28020. this._filterJitIdentifiers(moduleMeta.declaredPipes)
  28021. .forEach((ref) => this._metadataResolver.getOrLoadPipeMetadata(ref));
  28022. });
  28023. return SyncAsync.all(loading);
  28024. }
  28025. /**
  28026. * @param {?} moduleType
  28027. * @return {?}
  28028. */
  28029. _compileModule(moduleType) {
  28030. let /** @type {?} */ ngModuleFactory = /** @type {?} */ ((this._compiledNgModuleCache.get(moduleType)));
  28031. if (!ngModuleFactory) {
  28032. const /** @type {?} */ moduleMeta = /** @type {?} */ ((this._metadataResolver.getNgModuleMetadata(moduleType)));
  28033. // Always provide a bound Compiler
  28034. const /** @type {?} */ extraProviders = this.getExtraNgModuleProviders(moduleMeta.type.reference);
  28035. const /** @type {?} */ outputCtx = createOutputContext();
  28036. const /** @type {?} */ compileResult = this._ngModuleCompiler.compile(outputCtx, moduleMeta, extraProviders);
  28037. ngModuleFactory = this._interpretOrJit(ngModuleJitUrl(moduleMeta), outputCtx.statements)[compileResult.ngModuleFactoryVar];
  28038. this._compiledNgModuleCache.set(moduleMeta.type.reference, ngModuleFactory);
  28039. }
  28040. return ngModuleFactory;
  28041. }
  28042. /**
  28043. * \@internal
  28044. * @param {?} mainModule
  28045. * @param {?} allComponentFactories
  28046. * @return {?}
  28047. */
  28048. _compileComponents(mainModule, allComponentFactories) {
  28049. const /** @type {?} */ ngModule = /** @type {?} */ ((this._metadataResolver.getNgModuleMetadata(mainModule)));
  28050. const /** @type {?} */ moduleByJitDirective = new Map();
  28051. const /** @type {?} */ templates = new Set();
  28052. const /** @type {?} */ transJitModules = this._filterJitIdentifiers(ngModule.transitiveModule.modules);
  28053. transJitModules.forEach((localMod) => {
  28054. const /** @type {?} */ localModuleMeta = /** @type {?} */ ((this._metadataResolver.getNgModuleMetadata(localMod)));
  28055. this._filterJitIdentifiers(localModuleMeta.declaredDirectives).forEach((dirRef) => {
  28056. moduleByJitDirective.set(dirRef, localModuleMeta);
  28057. const /** @type {?} */ dirMeta = this._metadataResolver.getDirectiveMetadata(dirRef);
  28058. if (dirMeta.isComponent) {
  28059. templates.add(this._createCompiledTemplate(dirMeta, localModuleMeta));
  28060. if (allComponentFactories) {
  28061. const /** @type {?} */ template = this._createCompiledHostTemplate(dirMeta.type.reference, localModuleMeta);
  28062. templates.add(template);
  28063. allComponentFactories.push(/** @type {?} */ (dirMeta.componentFactory));
  28064. }
  28065. }
  28066. });
  28067. });
  28068. transJitModules.forEach((localMod) => {
  28069. const /** @type {?} */ localModuleMeta = /** @type {?} */ ((this._metadataResolver.getNgModuleMetadata(localMod)));
  28070. this._filterJitIdentifiers(localModuleMeta.declaredDirectives).forEach((dirRef) => {
  28071. const /** @type {?} */ dirMeta = this._metadataResolver.getDirectiveMetadata(dirRef);
  28072. if (dirMeta.isComponent) {
  28073. dirMeta.entryComponents.forEach((entryComponentType) => {
  28074. const /** @type {?} */ moduleMeta = /** @type {?} */ ((moduleByJitDirective.get(entryComponentType.componentType)));
  28075. templates.add(this._createCompiledHostTemplate(entryComponentType.componentType, moduleMeta));
  28076. });
  28077. }
  28078. });
  28079. localModuleMeta.entryComponents.forEach((entryComponentType) => {
  28080. if (!this.hasAotSummary(entryComponentType.componentType.reference)) {
  28081. const /** @type {?} */ moduleMeta = /** @type {?} */ ((moduleByJitDirective.get(entryComponentType.componentType)));
  28082. templates.add(this._createCompiledHostTemplate(entryComponentType.componentType, moduleMeta));
  28083. }
  28084. });
  28085. });
  28086. templates.forEach((template) => this._compileTemplate(template));
  28087. }
  28088. /**
  28089. * @param {?} type
  28090. * @return {?}
  28091. */
  28092. clearCacheFor(type) {
  28093. this._compiledNgModuleCache.delete(type);
  28094. this._metadataResolver.clearCacheFor(type);
  28095. this._compiledHostTemplateCache.delete(type);
  28096. const /** @type {?} */ compiledTemplate = this._compiledTemplateCache.get(type);
  28097. if (compiledTemplate) {
  28098. this._compiledTemplateCache.delete(type);
  28099. }
  28100. }
  28101. /**
  28102. * @return {?}
  28103. */
  28104. clearCache() {
  28105. // Note: don't clear the _addedAotSummaries, as they don't change!
  28106. this._metadataResolver.clearCache();
  28107. this._compiledTemplateCache.clear();
  28108. this._compiledHostTemplateCache.clear();
  28109. this._compiledNgModuleCache.clear();
  28110. }
  28111. /**
  28112. * @param {?} compType
  28113. * @param {?} ngModule
  28114. * @return {?}
  28115. */
  28116. _createCompiledHostTemplate(compType, ngModule) {
  28117. if (!ngModule) {
  28118. throw new Error(`Component ${stringify(compType)} is not part of any NgModule or the module has not been imported into your module.`);
  28119. }
  28120. let /** @type {?} */ compiledTemplate = this._compiledHostTemplateCache.get(compType);
  28121. if (!compiledTemplate) {
  28122. const /** @type {?} */ compMeta = this._metadataResolver.getDirectiveMetadata(compType);
  28123. assertComponent(compMeta);
  28124. const /** @type {?} */ hostMeta = this._metadataResolver.getHostComponentMetadata(compMeta, (/** @type {?} */ (compMeta.componentFactory)).viewDefFactory);
  28125. compiledTemplate =
  28126. new CompiledTemplate(true, compMeta.type, hostMeta, ngModule, [compMeta.type]);
  28127. this._compiledHostTemplateCache.set(compType, compiledTemplate);
  28128. }
  28129. return compiledTemplate;
  28130. }
  28131. /**
  28132. * @param {?} compMeta
  28133. * @param {?} ngModule
  28134. * @return {?}
  28135. */
  28136. _createCompiledTemplate(compMeta, ngModule) {
  28137. let /** @type {?} */ compiledTemplate = this._compiledTemplateCache.get(compMeta.type.reference);
  28138. if (!compiledTemplate) {
  28139. assertComponent(compMeta);
  28140. compiledTemplate = new CompiledTemplate(false, compMeta.type, compMeta, ngModule, ngModule.transitiveModule.directives);
  28141. this._compiledTemplateCache.set(compMeta.type.reference, compiledTemplate);
  28142. }
  28143. return compiledTemplate;
  28144. }
  28145. /**
  28146. * @param {?} template
  28147. * @return {?}
  28148. */
  28149. _compileTemplate(template) {
  28150. if (template.isCompiled) {
  28151. return;
  28152. }
  28153. const /** @type {?} */ compMeta = template.compMeta;
  28154. const /** @type {?} */ externalStylesheetsByModuleUrl = new Map();
  28155. const /** @type {?} */ outputContext = createOutputContext();
  28156. const /** @type {?} */ componentStylesheet = this._styleCompiler.compileComponent(outputContext, compMeta); /** @type {?} */
  28157. ((compMeta.template)).externalStylesheets.forEach((stylesheetMeta) => {
  28158. const /** @type {?} */ compiledStylesheet = this._styleCompiler.compileStyles(createOutputContext(), compMeta, stylesheetMeta);
  28159. externalStylesheetsByModuleUrl.set(/** @type {?} */ ((stylesheetMeta.moduleUrl)), compiledStylesheet);
  28160. });
  28161. this._resolveStylesCompileResult(componentStylesheet, externalStylesheetsByModuleUrl);
  28162. const /** @type {?} */ pipes = template.ngModule.transitiveModule.pipes.map(pipe => this._metadataResolver.getPipeSummary(pipe.reference));
  28163. const { template: parsedTemplate, pipes: usedPipes } = this._parseTemplate(compMeta, template.ngModule, template.directives);
  28164. const /** @type {?} */ compileResult = this._viewCompiler.compileComponent(outputContext, compMeta, parsedTemplate, variable(componentStylesheet.stylesVar), usedPipes);
  28165. const /** @type {?} */ evalResult = this._interpretOrJit(templateJitUrl(template.ngModule.type, template.compMeta), outputContext.statements);
  28166. const /** @type {?} */ viewClass = evalResult[compileResult.viewClassVar];
  28167. const /** @type {?} */ rendererType = evalResult[compileResult.rendererTypeVar];
  28168. template.compiled(viewClass, rendererType);
  28169. }
  28170. /**
  28171. * @param {?} compMeta
  28172. * @param {?} ngModule
  28173. * @param {?} directiveIdentifiers
  28174. * @return {?}
  28175. */
  28176. _parseTemplate(compMeta, ngModule, directiveIdentifiers) {
  28177. // Note: ! is ok here as components always have a template.
  28178. const /** @type {?} */ preserveWhitespaces = /** @type {?} */ ((compMeta.template)).preserveWhitespaces;
  28179. const /** @type {?} */ directives = directiveIdentifiers.map(dir => this._metadataResolver.getDirectiveSummary(dir.reference));
  28180. const /** @type {?} */ pipes = ngModule.transitiveModule.pipes.map(pipe => this._metadataResolver.getPipeSummary(pipe.reference));
  28181. return this._templateParser.parse(compMeta, /** @type {?} */ ((/** @type {?} */ ((compMeta.template)).htmlAst)), directives, pipes, ngModule.schemas, templateSourceUrl(ngModule.type, compMeta, /** @type {?} */ ((compMeta.template))), preserveWhitespaces);
  28182. }
  28183. /**
  28184. * @param {?} result
  28185. * @param {?} externalStylesheetsByModuleUrl
  28186. * @return {?}
  28187. */
  28188. _resolveStylesCompileResult(result, externalStylesheetsByModuleUrl) {
  28189. result.dependencies.forEach((dep, i) => {
  28190. const /** @type {?} */ nestedCompileResult = /** @type {?} */ ((externalStylesheetsByModuleUrl.get(dep.moduleUrl)));
  28191. const /** @type {?} */ nestedStylesArr = this._resolveAndEvalStylesCompileResult(nestedCompileResult, externalStylesheetsByModuleUrl);
  28192. dep.setValue(nestedStylesArr);
  28193. });
  28194. }
  28195. /**
  28196. * @param {?} result
  28197. * @param {?} externalStylesheetsByModuleUrl
  28198. * @return {?}
  28199. */
  28200. _resolveAndEvalStylesCompileResult(result, externalStylesheetsByModuleUrl) {
  28201. this._resolveStylesCompileResult(result, externalStylesheetsByModuleUrl);
  28202. return this._interpretOrJit(sharedStylesheetJitUrl(result.meta, this._sharedStylesheetCount++), result.outputCtx.statements)[result.stylesVar];
  28203. }
  28204. /**
  28205. * @param {?} sourceUrl
  28206. * @param {?} statements
  28207. * @return {?}
  28208. */
  28209. _interpretOrJit(sourceUrl, statements) {
  28210. if (!this._compilerConfig.useJit) {
  28211. return interpretStatements(statements, this._reflector);
  28212. }
  28213. else {
  28214. return jitStatements(sourceUrl, statements, this._reflector, this._compilerConfig.jitDevMode);
  28215. }
  28216. }
  28217. }
  28218. class CompiledTemplate {
  28219. /**
  28220. * @param {?} isHost
  28221. * @param {?} compType
  28222. * @param {?} compMeta
  28223. * @param {?} ngModule
  28224. * @param {?} directives
  28225. */
  28226. constructor(isHost, compType, compMeta, ngModule, directives) {
  28227. this.isHost = isHost;
  28228. this.compType = compType;
  28229. this.compMeta = compMeta;
  28230. this.ngModule = ngModule;
  28231. this.directives = directives;
  28232. this._viewClass = /** @type {?} */ ((null));
  28233. this.isCompiled = false;
  28234. }
  28235. /**
  28236. * @param {?} viewClass
  28237. * @param {?} rendererType
  28238. * @return {?}
  28239. */
  28240. compiled(viewClass, rendererType) {
  28241. this._viewClass = viewClass;
  28242. (/** @type {?} */ (this.compMeta.componentViewType)).setDelegate(viewClass);
  28243. for (let /** @type {?} */ prop in rendererType) {
  28244. (/** @type {?} */ (this.compMeta.rendererType))[prop] = rendererType[prop];
  28245. }
  28246. this.isCompiled = true;
  28247. }
  28248. }
  28249. /**
  28250. * @param {?} meta
  28251. * @return {?}
  28252. */
  28253. function assertComponent(meta) {
  28254. if (!meta.isComponent) {
  28255. throw new Error(`Could not compile '${identifierName(meta.type)}' because it is not a component.`);
  28256. }
  28257. }
  28258. /**
  28259. * @return {?}
  28260. */
  28261. function createOutputContext() {
  28262. const /** @type {?} */ importExpr$$1 = (symbol) => importExpr({ name: identifierName(symbol), moduleName: null, runtime: symbol });
  28263. return { statements: [], genFilePath: '', importExpr: importExpr$$1 };
  28264. }
  28265. /**
  28266. * @fileoverview added by tsickle
  28267. * @suppress {checkTypes} checked by tsc
  28268. */
  28269. /**
  28270. * @license
  28271. * Copyright Google Inc. All Rights Reserved.
  28272. *
  28273. * Use of this source code is governed by an MIT-style license that can be
  28274. * found in the LICENSE file at https://angular.io/license
  28275. */
  28276. /**
  28277. * Provides access to reflection data about symbols that the compiler needs.
  28278. * @abstract
  28279. */
  28280. class CompileReflector {
  28281. }
  28282. /**
  28283. * @fileoverview added by tsickle
  28284. * @suppress {checkTypes} checked by tsc
  28285. */
  28286. /**
  28287. * @license
  28288. * Copyright Google Inc. All Rights Reserved.
  28289. *
  28290. * Use of this source code is governed by an MIT-style license that can be
  28291. * found in the LICENSE file at https://angular.io/license
  28292. */
  28293. /**
  28294. * Create a {\@link UrlResolver} with no package prefix.
  28295. * @return {?}
  28296. */
  28297. function createUrlResolverWithoutPackagePrefix() {
  28298. return new UrlResolver();
  28299. }
  28300. /**
  28301. * @return {?}
  28302. */
  28303. function createOfflineCompileUrlResolver() {
  28304. return new UrlResolver('.');
  28305. }
  28306. /**
  28307. * @record
  28308. */
  28309. const UrlResolver = class UrlResolverImpl {
  28310. /**
  28311. * @param {?=} _packagePrefix
  28312. */
  28313. constructor(_packagePrefix = null) {
  28314. this._packagePrefix = _packagePrefix;
  28315. }
  28316. /**
  28317. * Resolves the `url` given the `baseUrl`:
  28318. * - when the `url` is null, the `baseUrl` is returned,
  28319. * - if `url` is relative ('path/to/here', './path/to/here'), the resolved url is a combination of
  28320. * `baseUrl` and `url`,
  28321. * - if `url` is absolute (it has a scheme: 'http://', 'https://' or start with '/'), the `url` is
  28322. * returned as is (ignoring the `baseUrl`)
  28323. * @param {?} baseUrl
  28324. * @param {?} url
  28325. * @return {?}
  28326. */
  28327. resolve(baseUrl, url) {
  28328. let /** @type {?} */ resolvedUrl = url;
  28329. if (baseUrl != null && baseUrl.length > 0) {
  28330. resolvedUrl = _resolveUrl(baseUrl, resolvedUrl);
  28331. }
  28332. const /** @type {?} */ resolvedParts = _split(resolvedUrl);
  28333. let /** @type {?} */ prefix = this._packagePrefix;
  28334. if (prefix != null && resolvedParts != null &&
  28335. resolvedParts[_ComponentIndex.Scheme] == 'package') {
  28336. let /** @type {?} */ path = resolvedParts[_ComponentIndex.Path];
  28337. prefix = prefix.replace(/\/+$/, '');
  28338. path = path.replace(/^\/+/, '');
  28339. return `${prefix}/${path}`;
  28340. }
  28341. return resolvedUrl;
  28342. }
  28343. };
  28344. /**
  28345. * Extract the scheme of a URL.
  28346. * @param {?} url
  28347. * @return {?}
  28348. */
  28349. function getUrlScheme(url) {
  28350. const /** @type {?} */ match = _split(url);
  28351. return (match && match[_ComponentIndex.Scheme]) || '';
  28352. }
  28353. /**
  28354. * Builds a URI string from already-encoded parts.
  28355. *
  28356. * No encoding is performed. Any component may be omitted as either null or
  28357. * undefined.
  28358. *
  28359. * @param {?=} opt_scheme The scheme such as 'http'.
  28360. * @param {?=} opt_userInfo The user name before the '\@'.
  28361. * @param {?=} opt_domain The domain such as 'www.google.com', already
  28362. * URI-encoded.
  28363. * @param {?=} opt_port The port number.
  28364. * @param {?=} opt_path The path, already URI-encoded. If it is not
  28365. * empty, it must begin with a slash.
  28366. * @param {?=} opt_queryData The URI-encoded query data.
  28367. * @param {?=} opt_fragment The URI-encoded fragment identifier.
  28368. * @return {?} The fully combined URI.
  28369. */
  28370. function _buildFromEncodedParts(opt_scheme, opt_userInfo, opt_domain, opt_port, opt_path, opt_queryData, opt_fragment) {
  28371. const /** @type {?} */ out = [];
  28372. if (opt_scheme != null) {
  28373. out.push(opt_scheme + ':');
  28374. }
  28375. if (opt_domain != null) {
  28376. out.push('//');
  28377. if (opt_userInfo != null) {
  28378. out.push(opt_userInfo + '@');
  28379. }
  28380. out.push(opt_domain);
  28381. if (opt_port != null) {
  28382. out.push(':' + opt_port);
  28383. }
  28384. }
  28385. if (opt_path != null) {
  28386. out.push(opt_path);
  28387. }
  28388. if (opt_queryData != null) {
  28389. out.push('?' + opt_queryData);
  28390. }
  28391. if (opt_fragment != null) {
  28392. out.push('#' + opt_fragment);
  28393. }
  28394. return out.join('');
  28395. }
  28396. /**
  28397. * A regular expression for breaking a URI into its component parts.
  28398. *
  28399. * {\@link http://www.gbiv.com/protocols/uri/rfc/rfc3986.html#RFC2234} says
  28400. * As the "first-match-wins" algorithm is identical to the "greedy"
  28401. * disambiguation method used by POSIX regular expressions, it is natural and
  28402. * commonplace to use a regular expression for parsing the potential five
  28403. * components of a URI reference.
  28404. *
  28405. * The following line is the regular expression for breaking-down a
  28406. * well-formed URI reference into its components.
  28407. *
  28408. * <pre>
  28409. * ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
  28410. * 12 3 4 5 6 7 8 9
  28411. * </pre>
  28412. *
  28413. * The numbers in the second line above are only to assist readability; they
  28414. * indicate the reference points for each subexpression (i.e., each paired
  28415. * parenthesis). We refer to the value matched for subexpression <n> as $<n>.
  28416. * For example, matching the above expression to
  28417. * <pre>
  28418. * http://www.ics.uci.edu/pub/ietf/uri/#Related
  28419. * </pre>
  28420. * results in the following subexpression matches:
  28421. * <pre>
  28422. * $1 = http:
  28423. * $2 = http
  28424. * $3 = //www.ics.uci.edu
  28425. * $4 = www.ics.uci.edu
  28426. * $5 = /pub/ietf/uri/
  28427. * $6 = <undefined>
  28428. * $7 = <undefined>
  28429. * $8 = #Related
  28430. * $9 = Related
  28431. * </pre>
  28432. * where <undefined> indicates that the component is not present, as is the
  28433. * case for the query component in the above example. Therefore, we can
  28434. * determine the value of the five components as
  28435. * <pre>
  28436. * scheme = $2
  28437. * authority = $4
  28438. * path = $5
  28439. * query = $7
  28440. * fragment = $9
  28441. * </pre>
  28442. *
  28443. * The regular expression has been modified slightly to expose the
  28444. * userInfo, domain, and port separately from the authority.
  28445. * The modified version yields
  28446. * <pre>
  28447. * $1 = http scheme
  28448. * $2 = <undefined> userInfo -\
  28449. * $3 = www.ics.uci.edu domain | authority
  28450. * $4 = <undefined> port -/
  28451. * $5 = /pub/ietf/uri/ path
  28452. * $6 = <undefined> query without ?
  28453. * $7 = Related fragment without #
  28454. * </pre>
  28455. * \@internal
  28456. */
  28457. const _splitRe = new RegExp('^' +
  28458. '(?:' +
  28459. '([^:/?#.]+)' + // scheme - ignore special characters
  28460. ':)?' +
  28461. '(?://' +
  28462. '(?:([^/?#]*)@)?' + // userInfo
  28463. '([\\w\\d\\-\\u0100-\\uffff.%]*)' + // domain - restrict to letters,
  28464. '(?::([0-9]+))?' + // port
  28465. ')?' +
  28466. '([^?#]+)?' + // path
  28467. '(?:\\?([^#]*))?' + // query
  28468. '(?:#(.*))?' + // fragment
  28469. '$');
  28470. /** @enum {number} */
  28471. const _ComponentIndex = {
  28472. Scheme: 1,
  28473. UserInfo: 2,
  28474. Domain: 3,
  28475. Port: 4,
  28476. Path: 5,
  28477. QueryData: 6,
  28478. Fragment: 7,
  28479. };
  28480. _ComponentIndex[_ComponentIndex.Scheme] = "Scheme";
  28481. _ComponentIndex[_ComponentIndex.UserInfo] = "UserInfo";
  28482. _ComponentIndex[_ComponentIndex.Domain] = "Domain";
  28483. _ComponentIndex[_ComponentIndex.Port] = "Port";
  28484. _ComponentIndex[_ComponentIndex.Path] = "Path";
  28485. _ComponentIndex[_ComponentIndex.QueryData] = "QueryData";
  28486. _ComponentIndex[_ComponentIndex.Fragment] = "Fragment";
  28487. /**
  28488. * Splits a URI into its component parts.
  28489. *
  28490. * Each component can be accessed via the component indices; for example:
  28491. * <pre>
  28492. * goog.uri.utils.split(someStr)[goog.uri.utils.CompontentIndex.QUERY_DATA];
  28493. * </pre>
  28494. *
  28495. * @param {?} uri The URI string to examine.
  28496. * @return {?} Each component still URI-encoded.
  28497. * Each component that is present will contain the encoded value, whereas
  28498. * components that are not present will be undefined or empty, depending
  28499. * on the browser's regular expression implementation. Never null, since
  28500. * arbitrary strings may still look like path names.
  28501. */
  28502. function _split(uri) {
  28503. return /** @type {?} */ ((uri.match(_splitRe)));
  28504. }
  28505. /**
  28506. * Removes dot segments in given path component, as described in
  28507. * RFC 3986, section 5.2.4.
  28508. *
  28509. * @param {?} path A non-empty path component.
  28510. * @return {?} Path component with removed dot segments.
  28511. */
  28512. function _removeDotSegments(path) {
  28513. if (path == '/')
  28514. return '/';
  28515. const /** @type {?} */ leadingSlash = path[0] == '/' ? '/' : '';
  28516. const /** @type {?} */ trailingSlash = path[path.length - 1] === '/' ? '/' : '';
  28517. const /** @type {?} */ segments = path.split('/');
  28518. const /** @type {?} */ out = [];
  28519. let /** @type {?} */ up = 0;
  28520. for (let /** @type {?} */ pos = 0; pos < segments.length; pos++) {
  28521. const /** @type {?} */ segment = segments[pos];
  28522. switch (segment) {
  28523. case '':
  28524. case '.':
  28525. break;
  28526. case '..':
  28527. if (out.length > 0) {
  28528. out.pop();
  28529. }
  28530. else {
  28531. up++;
  28532. }
  28533. break;
  28534. default:
  28535. out.push(segment);
  28536. }
  28537. }
  28538. if (leadingSlash == '') {
  28539. while (up-- > 0) {
  28540. out.unshift('..');
  28541. }
  28542. if (out.length === 0)
  28543. out.push('.');
  28544. }
  28545. return leadingSlash + out.join('/') + trailingSlash;
  28546. }
  28547. /**
  28548. * Takes an array of the parts from split and canonicalizes the path part
  28549. * and then joins all the parts.
  28550. * @param {?} parts
  28551. * @return {?}
  28552. */
  28553. function _joinAndCanonicalizePath(parts) {
  28554. let /** @type {?} */ path = parts[_ComponentIndex.Path];
  28555. path = path == null ? '' : _removeDotSegments(path);
  28556. parts[_ComponentIndex.Path] = path;
  28557. return _buildFromEncodedParts(parts[_ComponentIndex.Scheme], parts[_ComponentIndex.UserInfo], parts[_ComponentIndex.Domain], parts[_ComponentIndex.Port], path, parts[_ComponentIndex.QueryData], parts[_ComponentIndex.Fragment]);
  28558. }
  28559. /**
  28560. * Resolves a URL.
  28561. * @param {?} base The URL acting as the base URL.
  28562. * @param {?} url
  28563. * @return {?}
  28564. */
  28565. function _resolveUrl(base, url) {
  28566. const /** @type {?} */ parts = _split(encodeURI(url));
  28567. const /** @type {?} */ baseParts = _split(base);
  28568. if (parts[_ComponentIndex.Scheme] != null) {
  28569. return _joinAndCanonicalizePath(parts);
  28570. }
  28571. else {
  28572. parts[_ComponentIndex.Scheme] = baseParts[_ComponentIndex.Scheme];
  28573. }
  28574. for (let /** @type {?} */ i = _ComponentIndex.Scheme; i <= _ComponentIndex.Port; i++) {
  28575. if (parts[i] == null) {
  28576. parts[i] = baseParts[i];
  28577. }
  28578. }
  28579. if (parts[_ComponentIndex.Path][0] == '/') {
  28580. return _joinAndCanonicalizePath(parts);
  28581. }
  28582. let /** @type {?} */ path = baseParts[_ComponentIndex.Path];
  28583. if (path == null)
  28584. path = '/';
  28585. const /** @type {?} */ index = path.lastIndexOf('/');
  28586. path = path.substring(0, index + 1) + parts[_ComponentIndex.Path];
  28587. parts[_ComponentIndex.Path] = path;
  28588. return _joinAndCanonicalizePath(parts);
  28589. }
  28590. /**
  28591. * @fileoverview added by tsickle
  28592. * @suppress {checkTypes} checked by tsc
  28593. */
  28594. /**
  28595. * @license
  28596. * Copyright Google Inc. All Rights Reserved.
  28597. *
  28598. * Use of this source code is governed by an MIT-style license that can be
  28599. * found in the LICENSE file at https://angular.io/license
  28600. */
  28601. /**
  28602. * An interface for retrieving documents by URL that the compiler uses
  28603. * to load templates.
  28604. */
  28605. class ResourceLoader {
  28606. /**
  28607. * @param {?} url
  28608. * @return {?}
  28609. */
  28610. get(url) { return ''; }
  28611. }
  28612. /**
  28613. * @fileoverview added by tsickle
  28614. * @suppress {checkTypes} checked by tsc
  28615. */
  28616. /**
  28617. * @license
  28618. * Copyright Google Inc. All Rights Reserved.
  28619. *
  28620. * Use of this source code is governed by an MIT-style license that can be
  28621. * found in the LICENSE file at https://angular.io/license
  28622. */
  28623. /**
  28624. * The host of the Extractor disconnects the implementation from TypeScript / other language
  28625. * services and from underlying file systems.
  28626. * @record
  28627. */
  28628. class Extractor {
  28629. /**
  28630. * @param {?} host
  28631. * @param {?} staticSymbolResolver
  28632. * @param {?} messageBundle
  28633. * @param {?} metadataResolver
  28634. */
  28635. constructor(host, staticSymbolResolver, messageBundle, metadataResolver) {
  28636. this.host = host;
  28637. this.staticSymbolResolver = staticSymbolResolver;
  28638. this.messageBundle = messageBundle;
  28639. this.metadataResolver = metadataResolver;
  28640. }
  28641. /**
  28642. * @param {?} rootFiles
  28643. * @return {?}
  28644. */
  28645. extract(rootFiles) {
  28646. const { files, ngModules } = analyzeAndValidateNgModules(rootFiles, this.host, this.staticSymbolResolver, this.metadataResolver);
  28647. return Promise
  28648. .all(ngModules.map(ngModule => this.metadataResolver.loadNgModuleDirectiveAndPipeMetadata(ngModule.type.reference, false)))
  28649. .then(() => {
  28650. const /** @type {?} */ errors = [];
  28651. files.forEach(file => {
  28652. const /** @type {?} */ compMetas = [];
  28653. file.directives.forEach(directiveType => {
  28654. const /** @type {?} */ dirMeta = this.metadataResolver.getDirectiveMetadata(directiveType);
  28655. if (dirMeta && dirMeta.isComponent) {
  28656. compMetas.push(dirMeta);
  28657. }
  28658. });
  28659. compMetas.forEach(compMeta => {
  28660. const /** @type {?} */ html = /** @type {?} */ ((/** @type {?} */ ((compMeta.template)).template));
  28661. const /** @type {?} */ interpolationConfig = InterpolationConfig.fromArray(/** @type {?} */ ((compMeta.template)).interpolation);
  28662. errors.push(.../** @type {?} */ ((this.messageBundle.updateFromTemplate(html, file.fileName, interpolationConfig))));
  28663. });
  28664. });
  28665. if (errors.length) {
  28666. throw new Error(errors.map(e => e.toString()).join('\n'));
  28667. }
  28668. return this.messageBundle;
  28669. });
  28670. }
  28671. /**
  28672. * @param {?} host
  28673. * @param {?} locale
  28674. * @return {?}
  28675. */
  28676. static create(host, locale) {
  28677. const /** @type {?} */ htmlParser = new HtmlParser();
  28678. const /** @type {?} */ urlResolver = createAotUrlResolver(host);
  28679. const /** @type {?} */ symbolCache = new StaticSymbolCache();
  28680. const /** @type {?} */ summaryResolver = new AotSummaryResolver(host, symbolCache);
  28681. const /** @type {?} */ staticSymbolResolver = new StaticSymbolResolver(host, symbolCache, summaryResolver);
  28682. const /** @type {?} */ staticReflector = new StaticReflector(summaryResolver, staticSymbolResolver);
  28683. const /** @type {?} */ config = new CompilerConfig({ defaultEncapsulation: ViewEncapsulation.Emulated, useJit: false });
  28684. const /** @type {?} */ normalizer = new DirectiveNormalizer({ get: (url) => host.loadResource(url) }, urlResolver, htmlParser, config);
  28685. const /** @type {?} */ elementSchemaRegistry = new DomElementSchemaRegistry();
  28686. const /** @type {?} */ resolver = new CompileMetadataResolver(config, htmlParser, new NgModuleResolver(staticReflector), new DirectiveResolver(staticReflector), new PipeResolver(staticReflector), summaryResolver, elementSchemaRegistry, normalizer, console, symbolCache, staticReflector);
  28687. // TODO(vicb): implicit tags & attributes
  28688. const /** @type {?} */ messageBundle = new MessageBundle(htmlParser, [], {}, locale);
  28689. const /** @type {?} */ extractor = new Extractor(host, staticSymbolResolver, messageBundle, resolver);
  28690. return { extractor, staticReflector };
  28691. }
  28692. }
  28693. /**
  28694. * @fileoverview added by tsickle
  28695. * @suppress {checkTypes} checked by tsc
  28696. */
  28697. /**
  28698. * @license
  28699. * Copyright Google Inc. All Rights Reserved.
  28700. *
  28701. * Use of this source code is governed by an MIT-style license that can be
  28702. * found in the LICENSE file at https://angular.io/license
  28703. */
  28704. /**
  28705. * @fileoverview added by tsickle
  28706. * @suppress {checkTypes} checked by tsc
  28707. */
  28708. /**
  28709. * @license
  28710. * Copyright Google Inc. All Rights Reserved.
  28711. *
  28712. * Use of this source code is governed by an MIT-style license that can be
  28713. * found in the LICENSE file at https://angular.io/license
  28714. */
  28715. // This file only reexports content of the `src` folder. Keep it that way.
  28716. /**
  28717. * @fileoverview added by tsickle
  28718. * @suppress {checkTypes} checked by tsc
  28719. */
  28720. /**
  28721. * @license
  28722. * Copyright Google Inc. All Rights Reserved.
  28723. *
  28724. * Use of this source code is governed by an MIT-style license that can be
  28725. * found in the LICENSE file at https://angular.io/license
  28726. */
  28727. /**
  28728. * @module
  28729. * @description
  28730. * Entry point for all public APIs of this package.
  28731. */
  28732. // This file only reexports content of the `src` folder. Keep it that way.
  28733. /**
  28734. * @fileoverview added by tsickle
  28735. * @suppress {checkTypes} checked by tsc
  28736. */
  28737. /**
  28738. * @license
  28739. * Copyright Google Inc. All Rights Reserved.
  28740. *
  28741. * Use of this source code is governed by an MIT-style license that can be
  28742. * found in the LICENSE file at https://angular.io/license
  28743. */
  28744. // This file is not used to build this module. It is only used during editing
  28745. // by the TypeScript language service and during build for verification. `ngc`
  28746. // replaces this file with production index.ts when it rewrites private symbol
  28747. // names.
  28748. export { core, CompilerConfig, preserveWhitespacesDefault, isLoweredSymbol, createLoweredSymbol, Identifiers, JitCompiler, DirectiveResolver, PipeResolver, NgModuleResolver, DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig, NgModuleCompiler, AssertNotNull, BinaryOperator, BinaryOperatorExpr, BuiltinMethod, BuiltinVar, CastExpr, ClassStmt, CommaExpr, CommentStmt, ConditionalExpr, DeclareFunctionStmt, DeclareVarStmt, ExpressionStatement, ExternalExpr, ExternalReference, FunctionExpr, IfStmt, InstantiateExpr, InvokeFunctionExpr, InvokeMethodExpr, LiteralArrayExpr, LiteralExpr, LiteralMapExpr, NotExpr, ReadKeyExpr, ReadPropExpr, ReadVarExpr, ReturnStatement, ThrowStmt, TryCatchStmt, WriteKeyExpr, WritePropExpr, WriteVarExpr, StmtModifier, Statement, collectExternalReferences, EmitterVisitorContext, ViewCompiler, getParseErrors, isSyntaxError, syntaxError, Version, VERSION, TextAst, BoundTextAst, AttrAst, BoundElementPropertyAst, BoundEventAst, ReferenceAst, VariableAst, ElementAst, EmbeddedTemplateAst, BoundDirectivePropertyAst, DirectiveAst, ProviderAst, ProviderAstType, NgContentAst, PropertyBindingType, NullTemplateVisitor, RecursiveTemplateAstVisitor, templateVisitAll, identifierName, identifierModuleUrl, viewClassName, rendererTypeName, hostViewClassName, componentFactoryName, CompileSummaryKind, tokenName, tokenReference, CompileStylesheetMetadata, CompileTemplateMetadata, CompileDirectiveMetadata, CompilePipeMetadata, CompileNgModuleMetadata, TransitiveCompileNgModuleMetadata, ProviderMeta, flatten, templateSourceUrl, sharedStylesheetJitUrl, ngModuleJitUrl, templateJitUrl, createAotUrlResolver, createAotCompiler, AotCompiler, analyzeNgModules, analyzeAndValidateNgModules, analyzeFile, mergeAnalyzedFiles, GeneratedFile, toTypeScript, formattedError, isFormattedError, StaticReflector, StaticSymbol, StaticSymbolCache, ResolvedStaticSymbol, StaticSymbolResolver, unescapeIdentifier, unwrapResolvedMetadata, AotSummaryResolver, AstPath, SummaryResolver, JitSummaryResolver, CompileReflector, createUrlResolverWithoutPackagePrefix, createOfflineCompileUrlResolver, UrlResolver, getUrlScheme, ResourceLoader, ElementSchemaRegistry, Extractor, I18NHtmlParser, MessageBundle, Serializer, Xliff, Xliff2, Xmb, Xtb, DirectiveNormalizer, ParserError, ParseSpan, AST, Quote, EmptyExpr, ImplicitReceiver, Chain, Conditional, PropertyRead, PropertyWrite, SafePropertyRead, KeyedRead, KeyedWrite, BindingPipe, LiteralPrimitive, LiteralArray, LiteralMap, Interpolation, Binary, PrefixNot, NonNullAssert, MethodCall, SafeMethodCall, FunctionCall, ASTWithSource, TemplateBinding, NullAstVisitor, RecursiveAstVisitor, AstTransformer, visitAstChildren, TokenType, Lexer, Token, EOF, isIdentifier, isQuote, SplitInterpolation, TemplateBindingParseResult, Parser, _ParseAST, ERROR_COMPONENT_TYPE, CompileMetadataResolver, Text, Expansion, ExpansionCase, Attribute$1 as Attribute, Element, Comment, visitAll, RecursiveVisitor, findNode, ParseTreeResult, TreeError, HtmlParser, HtmlTagDefinition, getHtmlTagDefinition, TagContentType, splitNsName, isNgContainer, isNgContent, isNgTemplate, getNsPrefix, mergeNsAndName, NAMED_ENTITIES, NGSP_UNICODE, debugOutputAstAsTypeScript, TypeScriptEmitter, ParseLocation, ParseSourceFile, ParseSourceSpan, ParseErrorLevel, ParseError, typeSourceSpan, DomElementSchemaRegistry, CssSelector, SelectorMatcher, SelectorListContext, SelectorContext, StylesCompileDependency, CompiledStylesheet, StyleCompiler, TemplateParseError, TemplateParseResult, TemplateParser, splitClasses, createElementCssSelector, removeSummaryDuplicates };
  28749. //# sourceMappingURL=compiler.js.map