beautifier.js 217 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define("beautifier", [], factory);
  6. else if(typeof exports === 'object')
  7. exports["beautifier"] = factory();
  8. else
  9. root["beautifier"] = factory();
  10. })(typeof self !== 'undefined' ? self : typeof windows !== 'undefined' ? window : typeof global !== 'undefined' ? global : this, function() {
  11. return /******/ (function() { // webpackBootstrap
  12. /******/ "use strict";
  13. /******/ var __webpack_modules__ = ([
  14. /* 0 */
  15. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  16. /*jshint node:true */
  17. /*
  18. The MIT License (MIT)
  19. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  20. Permission is hereby granted, free of charge, to any person
  21. obtaining a copy of this software and associated documentation files
  22. (the "Software"), to deal in the Software without restriction,
  23. including without limitation the rights to use, copy, modify, merge,
  24. publish, distribute, sublicense, and/or sell copies of the Software,
  25. and to permit persons to whom the Software is furnished to do so,
  26. subject to the following conditions:
  27. The above copyright notice and this permission notice shall be
  28. included in all copies or substantial portions of the Software.
  29. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  33. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  34. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  36. SOFTWARE.
  37. */
  38. var js_beautify = __webpack_require__(1);
  39. var css_beautify = __webpack_require__(16);
  40. var html_beautify = __webpack_require__(19);
  41. function style_html(html_source, options, js, css) {
  42. js = js || js_beautify;
  43. css = css || css_beautify;
  44. return html_beautify(html_source, options, js, css);
  45. }
  46. style_html.defaultOptions = html_beautify.defaultOptions;
  47. module.exports.js = js_beautify;
  48. module.exports.css = css_beautify;
  49. module.exports.html = style_html;
  50. /***/ }),
  51. /* 1 */
  52. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  53. /*jshint node:true */
  54. /*
  55. The MIT License (MIT)
  56. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  57. Permission is hereby granted, free of charge, to any person
  58. obtaining a copy of this software and associated documentation files
  59. (the "Software"), to deal in the Software without restriction,
  60. including without limitation the rights to use, copy, modify, merge,
  61. publish, distribute, sublicense, and/or sell copies of the Software,
  62. and to permit persons to whom the Software is furnished to do so,
  63. subject to the following conditions:
  64. The above copyright notice and this permission notice shall be
  65. included in all copies or substantial portions of the Software.
  66. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  67. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  68. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  69. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  70. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  71. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  72. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  73. SOFTWARE.
  74. */
  75. var Beautifier = (__webpack_require__(2).Beautifier),
  76. Options = (__webpack_require__(6).Options);
  77. function js_beautify(js_source_text, options) {
  78. var beautifier = new Beautifier(js_source_text, options);
  79. return beautifier.beautify();
  80. }
  81. module.exports = js_beautify;
  82. module.exports.defaultOptions = function() {
  83. return new Options();
  84. };
  85. /***/ }),
  86. /* 2 */
  87. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  88. /*jshint node:true */
  89. /*
  90. The MIT License (MIT)
  91. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  92. Permission is hereby granted, free of charge, to any person
  93. obtaining a copy of this software and associated documentation files
  94. (the "Software"), to deal in the Software without restriction,
  95. including without limitation the rights to use, copy, modify, merge,
  96. publish, distribute, sublicense, and/or sell copies of the Software,
  97. and to permit persons to whom the Software is furnished to do so,
  98. subject to the following conditions:
  99. The above copyright notice and this permission notice shall be
  100. included in all copies or substantial portions of the Software.
  101. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  102. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  103. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  104. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  105. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  106. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  107. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  108. SOFTWARE.
  109. */
  110. var Output = (__webpack_require__(3).Output);
  111. var Token = (__webpack_require__(4).Token);
  112. var acorn = __webpack_require__(5);
  113. var Options = (__webpack_require__(6).Options);
  114. var Tokenizer = (__webpack_require__(8).Tokenizer);
  115. var line_starters = (__webpack_require__(8).line_starters);
  116. var positionable_operators = (__webpack_require__(8).positionable_operators);
  117. var TOKEN = (__webpack_require__(8).TOKEN);
  118. function in_array(what, arr) {
  119. return arr.indexOf(what) !== -1;
  120. }
  121. function ltrim(s) {
  122. return s.replace(/^\s+/g, '');
  123. }
  124. function generateMapFromStrings(list) {
  125. var result = {};
  126. for (var x = 0; x < list.length; x++) {
  127. // make the mapped names underscored instead of dash
  128. result[list[x].replace(/-/g, '_')] = list[x];
  129. }
  130. return result;
  131. }
  132. function reserved_word(token, word) {
  133. return token && token.type === TOKEN.RESERVED && token.text === word;
  134. }
  135. function reserved_array(token, words) {
  136. return token && token.type === TOKEN.RESERVED && in_array(token.text, words);
  137. }
  138. // Unsure of what they mean, but they work. Worth cleaning up in future.
  139. var special_words = ['case', 'return', 'do', 'if', 'throw', 'else', 'await', 'break', 'continue', 'async'];
  140. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  141. // Generate map from array
  142. var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
  143. var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
  144. var MODE = {
  145. BlockStatement: 'BlockStatement', // 'BLOCK'
  146. Statement: 'Statement', // 'STATEMENT'
  147. ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
  148. ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
  149. ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
  150. Conditional: 'Conditional', //'(COND-EXPRESSION)',
  151. Expression: 'Expression' //'(EXPRESSION)'
  152. };
  153. function remove_redundant_indentation(output, frame) {
  154. // This implementation is effective but has some issues:
  155. // - can cause line wrap to happen too soon due to indent removal
  156. // after wrap points are calculated
  157. // These issues are minor compared to ugly indentation.
  158. if (frame.multiline_frame ||
  159. frame.mode === MODE.ForInitializer ||
  160. frame.mode === MODE.Conditional) {
  161. return;
  162. }
  163. // remove one indent from each line inside this section
  164. output.remove_indent(frame.start_line_index);
  165. }
  166. // we could use just string.split, but
  167. // IE doesn't like returning empty strings
  168. function split_linebreaks(s) {
  169. //return s.split(/\x0d\x0a|\x0a/);
  170. s = s.replace(acorn.allLineBreaks, '\n');
  171. var out = [],
  172. idx = s.indexOf("\n");
  173. while (idx !== -1) {
  174. out.push(s.substring(0, idx));
  175. s = s.substring(idx + 1);
  176. idx = s.indexOf("\n");
  177. }
  178. if (s.length) {
  179. out.push(s);
  180. }
  181. return out;
  182. }
  183. function is_array(mode) {
  184. return mode === MODE.ArrayLiteral;
  185. }
  186. function is_expression(mode) {
  187. return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
  188. }
  189. function all_lines_start_with(lines, c) {
  190. for (var i = 0; i < lines.length; i++) {
  191. var line = lines[i].trim();
  192. if (line.charAt(0) !== c) {
  193. return false;
  194. }
  195. }
  196. return true;
  197. }
  198. function each_line_matches_indent(lines, indent) {
  199. var i = 0,
  200. len = lines.length,
  201. line;
  202. for (; i < len; i++) {
  203. line = lines[i];
  204. // allow empty lines to pass through
  205. if (line && line.indexOf(indent) !== 0) {
  206. return false;
  207. }
  208. }
  209. return true;
  210. }
  211. function Beautifier(source_text, options) {
  212. options = options || {};
  213. this._source_text = source_text || '';
  214. this._output = null;
  215. this._tokens = null;
  216. this._last_last_text = null;
  217. this._flags = null;
  218. this._previous_flags = null;
  219. this._flag_store = null;
  220. this._options = new Options(options);
  221. }
  222. Beautifier.prototype.create_flags = function(flags_base, mode) {
  223. var next_indent_level = 0;
  224. if (flags_base) {
  225. next_indent_level = flags_base.indentation_level;
  226. if (!this._output.just_added_newline() &&
  227. flags_base.line_indent_level > next_indent_level) {
  228. next_indent_level = flags_base.line_indent_level;
  229. }
  230. }
  231. var next_flags = {
  232. mode: mode,
  233. parent: flags_base,
  234. last_token: flags_base ? flags_base.last_token : new Token(TOKEN.START_BLOCK, ''), // last token text
  235. last_word: flags_base ? flags_base.last_word : '', // last TOKEN.WORD passed
  236. declaration_statement: false,
  237. declaration_assignment: false,
  238. multiline_frame: false,
  239. inline_frame: false,
  240. if_block: false,
  241. else_block: false,
  242. class_start_block: false, // class A { INSIDE HERE } or class B extends C { INSIDE HERE }
  243. do_block: false,
  244. do_while: false,
  245. import_block: false,
  246. in_case_statement: false, // switch(..){ INSIDE HERE }
  247. in_case: false, // we're on the exact line with "case 0:"
  248. case_body: false, // the indented case-action block
  249. case_block: false, // the indented case-action block is wrapped with {}
  250. indentation_level: next_indent_level,
  251. alignment: 0,
  252. line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
  253. start_line_index: this._output.get_line_number(),
  254. ternary_depth: 0
  255. };
  256. return next_flags;
  257. };
  258. Beautifier.prototype._reset = function(source_text) {
  259. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  260. this._last_last_text = ''; // pre-last token text
  261. this._output = new Output(this._options, baseIndentString);
  262. // If testing the ignore directive, start with output disable set to true
  263. this._output.raw = this._options.test_output_raw;
  264. // Stack of parsing/formatting states, including MODE.
  265. // We tokenize, parse, and output in an almost purely a forward-only stream of token input
  266. // and formatted output. This makes the beautifier less accurate than full parsers
  267. // but also far more tolerant of syntax errors.
  268. //
  269. // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
  270. // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
  271. // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
  272. // most full parsers would die, but the beautifier gracefully falls back to
  273. // MODE.BlockStatement and continues on.
  274. this._flag_store = [];
  275. this.set_mode(MODE.BlockStatement);
  276. var tokenizer = new Tokenizer(source_text, this._options);
  277. this._tokens = tokenizer.tokenize();
  278. return source_text;
  279. };
  280. Beautifier.prototype.beautify = function() {
  281. // if disabled, return the input unchanged.
  282. if (this._options.disabled) {
  283. return this._source_text;
  284. }
  285. var sweet_code;
  286. var source_text = this._reset(this._source_text);
  287. var eol = this._options.eol;
  288. if (this._options.eol === 'auto') {
  289. eol = '\n';
  290. if (source_text && acorn.lineBreak.test(source_text || '')) {
  291. eol = source_text.match(acorn.lineBreak)[0];
  292. }
  293. }
  294. var current_token = this._tokens.next();
  295. while (current_token) {
  296. this.handle_token(current_token);
  297. this._last_last_text = this._flags.last_token.text;
  298. this._flags.last_token = current_token;
  299. current_token = this._tokens.next();
  300. }
  301. sweet_code = this._output.get_code(eol);
  302. return sweet_code;
  303. };
  304. Beautifier.prototype.handle_token = function(current_token, preserve_statement_flags) {
  305. if (current_token.type === TOKEN.START_EXPR) {
  306. this.handle_start_expr(current_token);
  307. } else if (current_token.type === TOKEN.END_EXPR) {
  308. this.handle_end_expr(current_token);
  309. } else if (current_token.type === TOKEN.START_BLOCK) {
  310. this.handle_start_block(current_token);
  311. } else if (current_token.type === TOKEN.END_BLOCK) {
  312. this.handle_end_block(current_token);
  313. } else if (current_token.type === TOKEN.WORD) {
  314. this.handle_word(current_token);
  315. } else if (current_token.type === TOKEN.RESERVED) {
  316. this.handle_word(current_token);
  317. } else if (current_token.type === TOKEN.SEMICOLON) {
  318. this.handle_semicolon(current_token);
  319. } else if (current_token.type === TOKEN.STRING) {
  320. this.handle_string(current_token);
  321. } else if (current_token.type === TOKEN.EQUALS) {
  322. this.handle_equals(current_token);
  323. } else if (current_token.type === TOKEN.OPERATOR) {
  324. this.handle_operator(current_token);
  325. } else if (current_token.type === TOKEN.COMMA) {
  326. this.handle_comma(current_token);
  327. } else if (current_token.type === TOKEN.BLOCK_COMMENT) {
  328. this.handle_block_comment(current_token, preserve_statement_flags);
  329. } else if (current_token.type === TOKEN.COMMENT) {
  330. this.handle_comment(current_token, preserve_statement_flags);
  331. } else if (current_token.type === TOKEN.DOT) {
  332. this.handle_dot(current_token);
  333. } else if (current_token.type === TOKEN.EOF) {
  334. this.handle_eof(current_token);
  335. } else if (current_token.type === TOKEN.UNKNOWN) {
  336. this.handle_unknown(current_token, preserve_statement_flags);
  337. } else {
  338. this.handle_unknown(current_token, preserve_statement_flags);
  339. }
  340. };
  341. Beautifier.prototype.handle_whitespace_and_comments = function(current_token, preserve_statement_flags) {
  342. var newlines = current_token.newlines;
  343. var keep_whitespace = this._options.keep_array_indentation && is_array(this._flags.mode);
  344. if (current_token.comments_before) {
  345. var comment_token = current_token.comments_before.next();
  346. while (comment_token) {
  347. // The cleanest handling of inline comments is to treat them as though they aren't there.
  348. // Just continue formatting and the behavior should be logical.
  349. // Also ignore unknown tokens. Again, this should result in better behavior.
  350. this.handle_whitespace_and_comments(comment_token, preserve_statement_flags);
  351. this.handle_token(comment_token, preserve_statement_flags);
  352. comment_token = current_token.comments_before.next();
  353. }
  354. }
  355. if (keep_whitespace) {
  356. for (var i = 0; i < newlines; i += 1) {
  357. this.print_newline(i > 0, preserve_statement_flags);
  358. }
  359. } else {
  360. if (this._options.max_preserve_newlines && newlines > this._options.max_preserve_newlines) {
  361. newlines = this._options.max_preserve_newlines;
  362. }
  363. if (this._options.preserve_newlines) {
  364. if (newlines > 1) {
  365. this.print_newline(false, preserve_statement_flags);
  366. for (var j = 1; j < newlines; j += 1) {
  367. this.print_newline(true, preserve_statement_flags);
  368. }
  369. }
  370. }
  371. }
  372. };
  373. var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];
  374. Beautifier.prototype.allow_wrap_or_preserved_newline = function(current_token, force_linewrap) {
  375. force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
  376. // Never wrap the first token on a line
  377. if (this._output.just_added_newline()) {
  378. return;
  379. }
  380. var shouldPreserveOrForce = (this._options.preserve_newlines && current_token.newlines) || force_linewrap;
  381. var operatorLogicApplies = in_array(this._flags.last_token.text, positionable_operators) ||
  382. in_array(current_token.text, positionable_operators);
  383. if (operatorLogicApplies) {
  384. var shouldPrintOperatorNewline = (
  385. in_array(this._flags.last_token.text, positionable_operators) &&
  386. in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
  387. ) ||
  388. in_array(current_token.text, positionable_operators);
  389. shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
  390. }
  391. if (shouldPreserveOrForce) {
  392. this.print_newline(false, true);
  393. } else if (this._options.wrap_line_length) {
  394. if (reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  395. // These tokens should never have a newline inserted
  396. // between them and the following expression.
  397. return;
  398. }
  399. this._output.set_wrap_point();
  400. }
  401. };
  402. Beautifier.prototype.print_newline = function(force_newline, preserve_statement_flags) {
  403. if (!preserve_statement_flags) {
  404. if (this._flags.last_token.text !== ';' && this._flags.last_token.text !== ',' && this._flags.last_token.text !== '=' && (this._flags.last_token.type !== TOKEN.OPERATOR || this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) {
  405. var next_token = this._tokens.peek();
  406. while (this._flags.mode === MODE.Statement &&
  407. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  408. !this._flags.do_block) {
  409. this.restore_mode();
  410. }
  411. }
  412. }
  413. if (this._output.add_new_line(force_newline)) {
  414. this._flags.multiline_frame = true;
  415. }
  416. };
  417. Beautifier.prototype.print_token_line_indentation = function(current_token) {
  418. if (this._output.just_added_newline()) {
  419. if (this._options.keep_array_indentation &&
  420. current_token.newlines &&
  421. (current_token.text === '[' || is_array(this._flags.mode))) {
  422. this._output.current_line.set_indent(-1);
  423. this._output.current_line.push(current_token.whitespace_before);
  424. this._output.space_before_token = false;
  425. } else if (this._output.set_indent(this._flags.indentation_level, this._flags.alignment)) {
  426. this._flags.line_indent_level = this._flags.indentation_level;
  427. }
  428. }
  429. };
  430. Beautifier.prototype.print_token = function(current_token) {
  431. if (this._output.raw) {
  432. this._output.add_raw_token(current_token);
  433. return;
  434. }
  435. if (this._options.comma_first && current_token.previous && current_token.previous.type === TOKEN.COMMA &&
  436. this._output.just_added_newline()) {
  437. if (this._output.previous_line.last() === ',') {
  438. var popped = this._output.previous_line.pop();
  439. // if the comma was already at the start of the line,
  440. // pull back onto that line and reprint the indentation
  441. if (this._output.previous_line.is_empty()) {
  442. this._output.previous_line.push(popped);
  443. this._output.trim(true);
  444. this._output.current_line.pop();
  445. this._output.trim();
  446. }
  447. // add the comma in front of the next token
  448. this.print_token_line_indentation(current_token);
  449. this._output.add_token(',');
  450. this._output.space_before_token = true;
  451. }
  452. }
  453. this.print_token_line_indentation(current_token);
  454. this._output.non_breaking_space = true;
  455. this._output.add_token(current_token.text);
  456. if (this._output.previous_token_wrapped) {
  457. this._flags.multiline_frame = true;
  458. }
  459. };
  460. Beautifier.prototype.indent = function() {
  461. this._flags.indentation_level += 1;
  462. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  463. };
  464. Beautifier.prototype.deindent = function() {
  465. if (this._flags.indentation_level > 0 &&
  466. ((!this._flags.parent) || this._flags.indentation_level > this._flags.parent.indentation_level)) {
  467. this._flags.indentation_level -= 1;
  468. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  469. }
  470. };
  471. Beautifier.prototype.set_mode = function(mode) {
  472. if (this._flags) {
  473. this._flag_store.push(this._flags);
  474. this._previous_flags = this._flags;
  475. } else {
  476. this._previous_flags = this.create_flags(null, mode);
  477. }
  478. this._flags = this.create_flags(this._previous_flags, mode);
  479. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  480. };
  481. Beautifier.prototype.restore_mode = function() {
  482. if (this._flag_store.length > 0) {
  483. this._previous_flags = this._flags;
  484. this._flags = this._flag_store.pop();
  485. if (this._previous_flags.mode === MODE.Statement) {
  486. remove_redundant_indentation(this._output, this._previous_flags);
  487. }
  488. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  489. }
  490. };
  491. Beautifier.prototype.start_of_object_property = function() {
  492. return this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement && (
  493. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || (reserved_array(this._flags.last_token, ['get', 'set'])));
  494. };
  495. Beautifier.prototype.start_of_statement = function(current_token) {
  496. var start = false;
  497. start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
  498. start = start || reserved_word(this._flags.last_token, 'do');
  499. start = start || (!(this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement)) && reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines;
  500. start = start || reserved_word(this._flags.last_token, 'else') &&
  501. !(reserved_word(current_token, 'if') && !current_token.comments_before);
  502. start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
  503. start = start || (this._flags.last_token.type === TOKEN.WORD && this._flags.mode === MODE.BlockStatement &&
  504. !this._flags.in_case &&
  505. !(current_token.text === '--' || current_token.text === '++') &&
  506. this._last_last_text !== 'function' &&
  507. current_token.type !== TOKEN.WORD && current_token.type !== TOKEN.RESERVED);
  508. start = start || (this._flags.mode === MODE.ObjectLiteral && (
  509. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || reserved_array(this._flags.last_token, ['get', 'set'])));
  510. if (start) {
  511. this.set_mode(MODE.Statement);
  512. this.indent();
  513. this.handle_whitespace_and_comments(current_token, true);
  514. // Issue #276:
  515. // If starting a new statement with [if, for, while, do], push to a new line.
  516. // if (a) if (b) if(c) d(); else e(); else f();
  517. if (!this.start_of_object_property()) {
  518. this.allow_wrap_or_preserved_newline(current_token,
  519. reserved_array(current_token, ['do', 'for', 'if', 'while']));
  520. }
  521. return true;
  522. }
  523. return false;
  524. };
  525. Beautifier.prototype.handle_start_expr = function(current_token) {
  526. // The conditional starts the statement if appropriate.
  527. if (!this.start_of_statement(current_token)) {
  528. this.handle_whitespace_and_comments(current_token);
  529. }
  530. var next_mode = MODE.Expression;
  531. if (current_token.text === '[') {
  532. if (this._flags.last_token.type === TOKEN.WORD || this._flags.last_token.text === ')') {
  533. // this is array index specifier, break immediately
  534. // a[x], fn()[x]
  535. if (reserved_array(this._flags.last_token, line_starters)) {
  536. this._output.space_before_token = true;
  537. }
  538. this.print_token(current_token);
  539. this.set_mode(next_mode);
  540. this.indent();
  541. if (this._options.space_in_paren) {
  542. this._output.space_before_token = true;
  543. }
  544. return;
  545. }
  546. next_mode = MODE.ArrayLiteral;
  547. if (is_array(this._flags.mode)) {
  548. if (this._flags.last_token.text === '[' ||
  549. (this._flags.last_token.text === ',' && (this._last_last_text === ']' || this._last_last_text === '}'))) {
  550. // ], [ goes to new line
  551. // }, [ goes to new line
  552. if (!this._options.keep_array_indentation) {
  553. this.print_newline();
  554. }
  555. }
  556. }
  557. if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR, TOKEN.DOT])) {
  558. this._output.space_before_token = true;
  559. }
  560. } else {
  561. if (this._flags.last_token.type === TOKEN.RESERVED) {
  562. if (this._flags.last_token.text === 'for') {
  563. this._output.space_before_token = this._options.space_before_conditional;
  564. next_mode = MODE.ForInitializer;
  565. } else if (in_array(this._flags.last_token.text, ['if', 'while', 'switch'])) {
  566. this._output.space_before_token = this._options.space_before_conditional;
  567. next_mode = MODE.Conditional;
  568. } else if (in_array(this._flags.last_word, ['await', 'async'])) {
  569. // Should be a space between await and an IIFE, or async and an arrow function
  570. this._output.space_before_token = true;
  571. } else if (this._flags.last_token.text === 'import' && current_token.whitespace_before === '') {
  572. this._output.space_before_token = false;
  573. } else if (in_array(this._flags.last_token.text, line_starters) || this._flags.last_token.text === 'catch') {
  574. this._output.space_before_token = true;
  575. }
  576. } else if (this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  577. // Support of this kind of newline preservation.
  578. // a = (b &&
  579. // (c || d));
  580. if (!this.start_of_object_property()) {
  581. this.allow_wrap_or_preserved_newline(current_token);
  582. }
  583. } else if (this._flags.last_token.type === TOKEN.WORD) {
  584. this._output.space_before_token = false;
  585. // function name() vs function name ()
  586. // function* name() vs function* name ()
  587. // async name() vs async name ()
  588. // In ES6, you can also define the method properties of an object
  589. // var obj = {a: function() {}}
  590. // It can be abbreviated
  591. // var obj = {a() {}}
  592. // var obj = { a() {}} vs var obj = { a () {}}
  593. // var obj = { * a() {}} vs var obj = { * a () {}}
  594. var peek_back_two = this._tokens.peek(-3);
  595. if (this._options.space_after_named_function && peek_back_two) {
  596. // peek starts at next character so -1 is current token
  597. var peek_back_three = this._tokens.peek(-4);
  598. if (reserved_array(peek_back_two, ['async', 'function']) ||
  599. (peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
  600. this._output.space_before_token = true;
  601. } else if (this._flags.mode === MODE.ObjectLiteral) {
  602. if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
  603. (peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
  604. this._output.space_before_token = true;
  605. }
  606. } else if (this._flags.parent && this._flags.parent.class_start_block) {
  607. this._output.space_before_token = true;
  608. }
  609. }
  610. } else {
  611. // Support preserving wrapped arrow function expressions
  612. // a.b('c',
  613. // () => d.e
  614. // )
  615. this.allow_wrap_or_preserved_newline(current_token);
  616. }
  617. // function() vs function ()
  618. // yield*() vs yield* ()
  619. // function*() vs function* ()
  620. if ((this._flags.last_token.type === TOKEN.RESERVED && (this._flags.last_word === 'function' || this._flags.last_word === 'typeof')) ||
  621. (this._flags.last_token.text === '*' &&
  622. (in_array(this._last_last_text, ['function', 'yield']) ||
  623. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  624. this._output.space_before_token = this._options.space_after_anon_function;
  625. }
  626. }
  627. if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
  628. this.print_newline();
  629. } else if (this._flags.last_token.type === TOKEN.END_EXPR || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.END_BLOCK || this._flags.last_token.text === '.' || this._flags.last_token.type === TOKEN.COMMA) {
  630. // do nothing on (( and )( and ][ and ]( and .(
  631. // TODO: Consider whether forcing this is required. Review failing tests when removed.
  632. this.allow_wrap_or_preserved_newline(current_token, current_token.newlines);
  633. }
  634. this.print_token(current_token);
  635. this.set_mode(next_mode);
  636. if (this._options.space_in_paren) {
  637. this._output.space_before_token = true;
  638. }
  639. // In all cases, if we newline while inside an expression it should be indented.
  640. this.indent();
  641. };
  642. Beautifier.prototype.handle_end_expr = function(current_token) {
  643. // statements inside expressions are not valid syntax, but...
  644. // statements must all be closed when their container closes
  645. while (this._flags.mode === MODE.Statement) {
  646. this.restore_mode();
  647. }
  648. this.handle_whitespace_and_comments(current_token);
  649. if (this._flags.multiline_frame) {
  650. this.allow_wrap_or_preserved_newline(current_token,
  651. current_token.text === ']' && is_array(this._flags.mode) && !this._options.keep_array_indentation);
  652. }
  653. if (this._options.space_in_paren) {
  654. if (this._flags.last_token.type === TOKEN.START_EXPR && !this._options.space_in_empty_paren) {
  655. // () [] no inner space in empty parens like these, ever, ref #320
  656. this._output.trim();
  657. this._output.space_before_token = false;
  658. } else {
  659. this._output.space_before_token = true;
  660. }
  661. }
  662. this.deindent();
  663. this.print_token(current_token);
  664. this.restore_mode();
  665. remove_redundant_indentation(this._output, this._previous_flags);
  666. // do {} while () // no statement required after
  667. if (this._flags.do_while && this._previous_flags.mode === MODE.Conditional) {
  668. this._previous_flags.mode = MODE.Expression;
  669. this._flags.do_block = false;
  670. this._flags.do_while = false;
  671. }
  672. };
  673. Beautifier.prototype.handle_start_block = function(current_token) {
  674. this.handle_whitespace_and_comments(current_token);
  675. // Check if this is should be treated as a ObjectLiteral
  676. var next_token = this._tokens.peek();
  677. var second_token = this._tokens.peek(1);
  678. if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) {
  679. this.set_mode(MODE.BlockStatement);
  680. this._flags.in_case_statement = true;
  681. } else if (this._flags.case_body) {
  682. this.set_mode(MODE.BlockStatement);
  683. } else if (second_token && (
  684. (in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
  685. (in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
  686. )) {
  687. // We don't support TypeScript,but we didn't break it for a very long time.
  688. // We'll try to keep not breaking it.
  689. if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
  690. this.set_mode(MODE.BlockStatement);
  691. } else {
  692. this.set_mode(MODE.ObjectLiteral);
  693. }
  694. } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
  695. // arrow function: (param1, paramN) => { statements }
  696. this.set_mode(MODE.BlockStatement);
  697. } else if (in_array(this._flags.last_token.type, [TOKEN.EQUALS, TOKEN.START_EXPR, TOKEN.COMMA, TOKEN.OPERATOR]) ||
  698. reserved_array(this._flags.last_token, ['return', 'throw', 'import', 'default'])
  699. ) {
  700. // Detecting shorthand function syntax is difficult by scanning forward,
  701. // so check the surrounding context.
  702. // If the block is being returned, imported, export default, passed as arg,
  703. // assigned with = or assigned in a nested object, treat as an ObjectLiteral.
  704. this.set_mode(MODE.ObjectLiteral);
  705. } else {
  706. this.set_mode(MODE.BlockStatement);
  707. }
  708. if (this._flags.last_token) {
  709. if (reserved_array(this._flags.last_token.previous, ['class', 'extends'])) {
  710. this._flags.class_start_block = true;
  711. }
  712. }
  713. var empty_braces = !next_token.comments_before && next_token.text === '}';
  714. var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
  715. this._flags.last_token.type === TOKEN.END_EXPR;
  716. if (this._options.brace_preserve_inline) // check for inline, set inline_frame if so
  717. {
  718. // search forward for a newline wanted inside this block
  719. var index = 0;
  720. var check_token = null;
  721. this._flags.inline_frame = true;
  722. do {
  723. index += 1;
  724. check_token = this._tokens.peek(index - 1);
  725. if (check_token.newlines) {
  726. this._flags.inline_frame = false;
  727. break;
  728. }
  729. } while (check_token.type !== TOKEN.EOF &&
  730. !(check_token.type === TOKEN.END_BLOCK && check_token.opened === current_token));
  731. }
  732. if ((this._options.brace_style === "expand" ||
  733. (this._options.brace_style === "none" && current_token.newlines)) &&
  734. !this._flags.inline_frame) {
  735. if (this._flags.last_token.type !== TOKEN.OPERATOR &&
  736. (empty_anonymous_function ||
  737. this._flags.last_token.type === TOKEN.EQUALS ||
  738. (reserved_array(this._flags.last_token, special_words) && this._flags.last_token.text !== 'else'))) {
  739. this._output.space_before_token = true;
  740. } else {
  741. this.print_newline(false, true);
  742. }
  743. } else { // collapse || inline_frame
  744. if (is_array(this._previous_flags.mode) && (this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.COMMA)) {
  745. if (this._flags.last_token.type === TOKEN.COMMA || this._options.space_in_paren) {
  746. this._output.space_before_token = true;
  747. }
  748. if (this._flags.last_token.type === TOKEN.COMMA || (this._flags.last_token.type === TOKEN.START_EXPR && this._flags.inline_frame)) {
  749. this.allow_wrap_or_preserved_newline(current_token);
  750. this._previous_flags.multiline_frame = this._previous_flags.multiline_frame || this._flags.multiline_frame;
  751. this._flags.multiline_frame = false;
  752. }
  753. }
  754. if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
  755. if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
  756. this.print_newline();
  757. } else {
  758. this._output.space_before_token = true;
  759. }
  760. }
  761. }
  762. this.print_token(current_token);
  763. this.indent();
  764. // Except for specific cases, open braces are followed by a new line.
  765. if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
  766. this.print_newline();
  767. }
  768. };
  769. Beautifier.prototype.handle_end_block = function(current_token) {
  770. // statements must all be closed when their container closes
  771. this.handle_whitespace_and_comments(current_token);
  772. while (this._flags.mode === MODE.Statement) {
  773. this.restore_mode();
  774. }
  775. var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
  776. if (this._flags.inline_frame && !empty_braces) { // try inline_frame (only set if this._options.braces-preserve-inline) first
  777. this._output.space_before_token = true;
  778. } else if (this._options.brace_style === "expand") {
  779. if (!empty_braces) {
  780. this.print_newline();
  781. }
  782. } else {
  783. // skip {}
  784. if (!empty_braces) {
  785. if (is_array(this._flags.mode) && this._options.keep_array_indentation) {
  786. // we REALLY need a newline here, but newliner would skip that
  787. this._options.keep_array_indentation = false;
  788. this.print_newline();
  789. this._options.keep_array_indentation = true;
  790. } else {
  791. this.print_newline();
  792. }
  793. }
  794. }
  795. this.restore_mode();
  796. this.print_token(current_token);
  797. };
  798. Beautifier.prototype.handle_word = function(current_token) {
  799. if (current_token.type === TOKEN.RESERVED) {
  800. if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
  801. current_token.type = TOKEN.WORD;
  802. } else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
  803. current_token.type = TOKEN.WORD;
  804. } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
  805. current_token.type = TOKEN.WORD;
  806. } else if (this._flags.mode === MODE.ObjectLiteral) {
  807. var next_token = this._tokens.peek();
  808. if (next_token.text === ':') {
  809. current_token.type = TOKEN.WORD;
  810. }
  811. }
  812. }
  813. if (this.start_of_statement(current_token)) {
  814. // The conditional starts the statement if appropriate.
  815. if (reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD) {
  816. this._flags.declaration_statement = true;
  817. }
  818. } else if (current_token.newlines && !is_expression(this._flags.mode) &&
  819. (this._flags.last_token.type !== TOKEN.OPERATOR || (this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) &&
  820. this._flags.last_token.type !== TOKEN.EQUALS &&
  821. (this._options.preserve_newlines || !reserved_array(this._flags.last_token, ['var', 'let', 'const', 'set', 'get']))) {
  822. this.handle_whitespace_and_comments(current_token);
  823. this.print_newline();
  824. } else {
  825. this.handle_whitespace_and_comments(current_token);
  826. }
  827. if (this._flags.do_block && !this._flags.do_while) {
  828. if (reserved_word(current_token, 'while')) {
  829. // do {} ## while ()
  830. this._output.space_before_token = true;
  831. this.print_token(current_token);
  832. this._output.space_before_token = true;
  833. this._flags.do_while = true;
  834. return;
  835. } else {
  836. // do {} should always have while as the next word.
  837. // if we don't see the expected while, recover
  838. this.print_newline();
  839. this._flags.do_block = false;
  840. }
  841. }
  842. // if may be followed by else, or not
  843. // Bare/inline ifs are tricky
  844. // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
  845. if (this._flags.if_block) {
  846. if (!this._flags.else_block && reserved_word(current_token, 'else')) {
  847. this._flags.else_block = true;
  848. } else {
  849. while (this._flags.mode === MODE.Statement) {
  850. this.restore_mode();
  851. }
  852. this._flags.if_block = false;
  853. this._flags.else_block = false;
  854. }
  855. }
  856. if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
  857. this.print_newline();
  858. if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
  859. // switch cases following one another
  860. this.deindent();
  861. }
  862. this._flags.case_body = false;
  863. this.print_token(current_token);
  864. this._flags.in_case = true;
  865. return;
  866. }
  867. if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  868. if (!this.start_of_object_property()) {
  869. this.allow_wrap_or_preserved_newline(current_token);
  870. }
  871. }
  872. if (reserved_word(current_token, 'function')) {
  873. if (in_array(this._flags.last_token.text, ['}', ';']) ||
  874. (this._output.just_added_newline() && !(in_array(this._flags.last_token.text, ['(', '[', '{', ':', '=', ',']) || this._flags.last_token.type === TOKEN.OPERATOR))) {
  875. // make sure there is a nice clean space of at least one blank line
  876. // before a new function definition
  877. if (!this._output.just_added_blankline() && !current_token.comments_before) {
  878. this.print_newline();
  879. this.print_newline(true);
  880. }
  881. }
  882. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD) {
  883. if (reserved_array(this._flags.last_token, ['get', 'set', 'new', 'export']) ||
  884. reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  885. this._output.space_before_token = true;
  886. } else if (reserved_word(this._flags.last_token, 'default') && this._last_last_text === 'export') {
  887. this._output.space_before_token = true;
  888. } else if (this._flags.last_token.text === 'declare') {
  889. // accomodates Typescript declare function formatting
  890. this._output.space_before_token = true;
  891. } else {
  892. this.print_newline();
  893. }
  894. } else if (this._flags.last_token.type === TOKEN.OPERATOR || this._flags.last_token.text === '=') {
  895. // foo = function
  896. this._output.space_before_token = true;
  897. } else if (!this._flags.multiline_frame && (is_expression(this._flags.mode) || is_array(this._flags.mode))) {
  898. // (function
  899. } else {
  900. this.print_newline();
  901. }
  902. this.print_token(current_token);
  903. this._flags.last_word = current_token.text;
  904. return;
  905. }
  906. var prefix = 'NONE';
  907. if (this._flags.last_token.type === TOKEN.END_BLOCK) {
  908. if (this._previous_flags.inline_frame) {
  909. prefix = 'SPACE';
  910. } else if (!reserved_array(current_token, ['else', 'catch', 'finally', 'from'])) {
  911. prefix = 'NEWLINE';
  912. } else {
  913. if (this._options.brace_style === "expand" ||
  914. this._options.brace_style === "end-expand" ||
  915. (this._options.brace_style === "none" && current_token.newlines)) {
  916. prefix = 'NEWLINE';
  917. } else {
  918. prefix = 'SPACE';
  919. this._output.space_before_token = true;
  920. }
  921. }
  922. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && this._flags.mode === MODE.BlockStatement) {
  923. // TODO: Should this be for STATEMENT as well?
  924. prefix = 'NEWLINE';
  925. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && is_expression(this._flags.mode)) {
  926. prefix = 'SPACE';
  927. } else if (this._flags.last_token.type === TOKEN.STRING) {
  928. prefix = 'NEWLINE';
  929. } else if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD ||
  930. (this._flags.last_token.text === '*' &&
  931. (in_array(this._last_last_text, ['function', 'yield']) ||
  932. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  933. prefix = 'SPACE';
  934. } else if (this._flags.last_token.type === TOKEN.START_BLOCK) {
  935. if (this._flags.inline_frame) {
  936. prefix = 'SPACE';
  937. } else {
  938. prefix = 'NEWLINE';
  939. }
  940. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  941. this._output.space_before_token = true;
  942. prefix = 'NEWLINE';
  943. }
  944. if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  945. if (this._flags.inline_frame || this._flags.last_token.text === 'else' || this._flags.last_token.text === 'export') {
  946. prefix = 'SPACE';
  947. } else {
  948. prefix = 'NEWLINE';
  949. }
  950. }
  951. if (reserved_array(current_token, ['else', 'catch', 'finally'])) {
  952. if ((!(this._flags.last_token.type === TOKEN.END_BLOCK && this._previous_flags.mode === MODE.BlockStatement) ||
  953. this._options.brace_style === "expand" ||
  954. this._options.brace_style === "end-expand" ||
  955. (this._options.brace_style === "none" && current_token.newlines)) &&
  956. !this._flags.inline_frame) {
  957. this.print_newline();
  958. } else {
  959. this._output.trim(true);
  960. var line = this._output.current_line;
  961. // If we trimmed and there's something other than a close block before us
  962. // put a newline back in. Handles '} // comment' scenario.
  963. if (line.last() !== '}') {
  964. this.print_newline();
  965. }
  966. this._output.space_before_token = true;
  967. }
  968. } else if (prefix === 'NEWLINE') {
  969. if (reserved_array(this._flags.last_token, special_words)) {
  970. // no newline between 'return nnn'
  971. this._output.space_before_token = true;
  972. } else if (this._flags.last_token.text === 'declare' && reserved_array(current_token, ['var', 'let', 'const'])) {
  973. // accomodates Typescript declare formatting
  974. this._output.space_before_token = true;
  975. } else if (this._flags.last_token.type !== TOKEN.END_EXPR) {
  976. if ((this._flags.last_token.type !== TOKEN.START_EXPR || !reserved_array(current_token, ['var', 'let', 'const'])) && this._flags.last_token.text !== ':') {
  977. // no need to force newline on 'var': for (var x = 0...)
  978. if (reserved_word(current_token, 'if') && reserved_word(current_token.previous, 'else')) {
  979. // no newline for } else if {
  980. this._output.space_before_token = true;
  981. } else {
  982. this.print_newline();
  983. }
  984. }
  985. } else if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  986. this.print_newline();
  987. }
  988. } else if (this._flags.multiline_frame && is_array(this._flags.mode) && this._flags.last_token.text === ',' && this._last_last_text === '}') {
  989. this.print_newline(); // }, in lists get a newline treatment
  990. } else if (prefix === 'SPACE') {
  991. this._output.space_before_token = true;
  992. }
  993. if (current_token.previous && (current_token.previous.type === TOKEN.WORD || current_token.previous.type === TOKEN.RESERVED)) {
  994. this._output.space_before_token = true;
  995. }
  996. this.print_token(current_token);
  997. this._flags.last_word = current_token.text;
  998. if (current_token.type === TOKEN.RESERVED) {
  999. if (current_token.text === 'do') {
  1000. this._flags.do_block = true;
  1001. } else if (current_token.text === 'if') {
  1002. this._flags.if_block = true;
  1003. } else if (current_token.text === 'import') {
  1004. this._flags.import_block = true;
  1005. } else if (this._flags.import_block && reserved_word(current_token, 'from')) {
  1006. this._flags.import_block = false;
  1007. }
  1008. }
  1009. };
  1010. Beautifier.prototype.handle_semicolon = function(current_token) {
  1011. if (this.start_of_statement(current_token)) {
  1012. // The conditional starts the statement if appropriate.
  1013. // Semicolon can be the start (and end) of a statement
  1014. this._output.space_before_token = false;
  1015. } else {
  1016. this.handle_whitespace_and_comments(current_token);
  1017. }
  1018. var next_token = this._tokens.peek();
  1019. while (this._flags.mode === MODE.Statement &&
  1020. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  1021. !this._flags.do_block) {
  1022. this.restore_mode();
  1023. }
  1024. // hacky but effective for the moment
  1025. if (this._flags.import_block) {
  1026. this._flags.import_block = false;
  1027. }
  1028. this.print_token(current_token);
  1029. };
  1030. Beautifier.prototype.handle_string = function(current_token) {
  1031. if (current_token.text.startsWith("`") && current_token.newlines === 0 && current_token.whitespace_before === '' && (current_token.previous.text === ')' || this._flags.last_token.type === TOKEN.WORD)) {
  1032. //Conditional for detectign backtick strings
  1033. } else if (this.start_of_statement(current_token)) {
  1034. // The conditional starts the statement if appropriate.
  1035. // One difference - strings want at least a space before
  1036. this._output.space_before_token = true;
  1037. } else {
  1038. this.handle_whitespace_and_comments(current_token);
  1039. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD || this._flags.inline_frame) {
  1040. this._output.space_before_token = true;
  1041. } else if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  1042. if (!this.start_of_object_property()) {
  1043. this.allow_wrap_or_preserved_newline(current_token);
  1044. }
  1045. } else if ((current_token.text.startsWith("`") && this._flags.last_token.type === TOKEN.END_EXPR && (current_token.previous.text === ']' || current_token.previous.text === ')') && current_token.newlines === 0)) {
  1046. this._output.space_before_token = true;
  1047. } else {
  1048. this.print_newline();
  1049. }
  1050. }
  1051. this.print_token(current_token);
  1052. };
  1053. Beautifier.prototype.handle_equals = function(current_token) {
  1054. if (this.start_of_statement(current_token)) {
  1055. // The conditional starts the statement if appropriate.
  1056. } else {
  1057. this.handle_whitespace_and_comments(current_token);
  1058. }
  1059. if (this._flags.declaration_statement) {
  1060. // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
  1061. this._flags.declaration_assignment = true;
  1062. }
  1063. this._output.space_before_token = true;
  1064. this.print_token(current_token);
  1065. this._output.space_before_token = true;
  1066. };
  1067. Beautifier.prototype.handle_comma = function(current_token) {
  1068. this.handle_whitespace_and_comments(current_token, true);
  1069. this.print_token(current_token);
  1070. this._output.space_before_token = true;
  1071. if (this._flags.declaration_statement) {
  1072. if (is_expression(this._flags.parent.mode)) {
  1073. // do not break on comma, for(var a = 1, b = 2)
  1074. this._flags.declaration_assignment = false;
  1075. }
  1076. if (this._flags.declaration_assignment) {
  1077. this._flags.declaration_assignment = false;
  1078. this.print_newline(false, true);
  1079. } else if (this._options.comma_first) {
  1080. // for comma-first, we want to allow a newline before the comma
  1081. // to turn into a newline after the comma, which we will fixup later
  1082. this.allow_wrap_or_preserved_newline(current_token);
  1083. }
  1084. } else if (this._flags.mode === MODE.ObjectLiteral ||
  1085. (this._flags.mode === MODE.Statement && this._flags.parent.mode === MODE.ObjectLiteral)) {
  1086. if (this._flags.mode === MODE.Statement) {
  1087. this.restore_mode();
  1088. }
  1089. if (!this._flags.inline_frame) {
  1090. this.print_newline();
  1091. }
  1092. } else if (this._options.comma_first) {
  1093. // EXPR or DO_BLOCK
  1094. // for comma-first, we want to allow a newline before the comma
  1095. // to turn into a newline after the comma, which we will fixup later
  1096. this.allow_wrap_or_preserved_newline(current_token);
  1097. }
  1098. };
  1099. Beautifier.prototype.handle_operator = function(current_token) {
  1100. var isGeneratorAsterisk = current_token.text === '*' &&
  1101. (reserved_array(this._flags.last_token, ['function', 'yield']) ||
  1102. (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.COMMA, TOKEN.END_BLOCK, TOKEN.SEMICOLON]))
  1103. );
  1104. var isUnary = in_array(current_token.text, ['-', '+']) && (
  1105. in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.START_EXPR, TOKEN.EQUALS, TOKEN.OPERATOR]) ||
  1106. in_array(this._flags.last_token.text, line_starters) ||
  1107. this._flags.last_token.text === ','
  1108. );
  1109. if (this.start_of_statement(current_token)) {
  1110. // The conditional starts the statement if appropriate.
  1111. } else {
  1112. var preserve_statement_flags = !isGeneratorAsterisk;
  1113. this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
  1114. }
  1115. // hack for actionscript's import .*;
  1116. if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
  1117. this.print_token(current_token);
  1118. return;
  1119. }
  1120. if (current_token.text === '::') {
  1121. // no spaces around exotic namespacing syntax operator
  1122. this.print_token(current_token);
  1123. return;
  1124. }
  1125. // Allow line wrapping between operators when operator_position is
  1126. // set to before or preserve
  1127. if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
  1128. this.allow_wrap_or_preserved_newline(current_token);
  1129. }
  1130. if (current_token.text === ':' && this._flags.in_case) {
  1131. this.print_token(current_token);
  1132. this._flags.in_case = false;
  1133. this._flags.case_body = true;
  1134. if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
  1135. this.indent();
  1136. this.print_newline();
  1137. this._flags.case_block = false;
  1138. } else {
  1139. this._flags.case_block = true;
  1140. this._output.space_before_token = true;
  1141. }
  1142. return;
  1143. }
  1144. var space_before = true;
  1145. var space_after = true;
  1146. var in_ternary = false;
  1147. if (current_token.text === ':') {
  1148. if (this._flags.ternary_depth === 0) {
  1149. // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
  1150. space_before = false;
  1151. } else {
  1152. this._flags.ternary_depth -= 1;
  1153. in_ternary = true;
  1154. }
  1155. } else if (current_token.text === '?') {
  1156. this._flags.ternary_depth += 1;
  1157. }
  1158. // let's handle the operator_position option prior to any conflicting logic
  1159. if (!isUnary && !isGeneratorAsterisk && this._options.preserve_newlines && in_array(current_token.text, positionable_operators)) {
  1160. var isColon = current_token.text === ':';
  1161. var isTernaryColon = (isColon && in_ternary);
  1162. var isOtherColon = (isColon && !in_ternary);
  1163. switch (this._options.operator_position) {
  1164. case OPERATOR_POSITION.before_newline:
  1165. // if the current token is : and it's not a ternary statement then we set space_before to false
  1166. this._output.space_before_token = !isOtherColon;
  1167. this.print_token(current_token);
  1168. if (!isColon || isTernaryColon) {
  1169. this.allow_wrap_or_preserved_newline(current_token);
  1170. }
  1171. this._output.space_before_token = true;
  1172. return;
  1173. case OPERATOR_POSITION.after_newline:
  1174. // if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement,
  1175. // then print a newline.
  1176. this._output.space_before_token = true;
  1177. if (!isColon || isTernaryColon) {
  1178. if (this._tokens.peek().newlines) {
  1179. this.print_newline(false, true);
  1180. } else {
  1181. this.allow_wrap_or_preserved_newline(current_token);
  1182. }
  1183. } else {
  1184. this._output.space_before_token = false;
  1185. }
  1186. this.print_token(current_token);
  1187. this._output.space_before_token = true;
  1188. return;
  1189. case OPERATOR_POSITION.preserve_newline:
  1190. if (!isOtherColon) {
  1191. this.allow_wrap_or_preserved_newline(current_token);
  1192. }
  1193. // if we just added a newline, or the current token is : and it's not a ternary statement,
  1194. // then we set space_before to false
  1195. space_before = !(this._output.just_added_newline() || isOtherColon);
  1196. this._output.space_before_token = space_before;
  1197. this.print_token(current_token);
  1198. this._output.space_before_token = true;
  1199. return;
  1200. }
  1201. }
  1202. if (isGeneratorAsterisk) {
  1203. this.allow_wrap_or_preserved_newline(current_token);
  1204. space_before = false;
  1205. var next_token = this._tokens.peek();
  1206. space_after = next_token && in_array(next_token.type, [TOKEN.WORD, TOKEN.RESERVED]);
  1207. } else if (current_token.text === '...') {
  1208. this.allow_wrap_or_preserved_newline(current_token);
  1209. space_before = this._flags.last_token.type === TOKEN.START_BLOCK;
  1210. space_after = false;
  1211. } else if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
  1212. // unary operators (and binary +/- pretending to be unary) special cases
  1213. if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR) {
  1214. this.allow_wrap_or_preserved_newline(current_token);
  1215. }
  1216. space_before = false;
  1217. space_after = false;
  1218. // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
  1219. // if there is a newline between -- or ++ and anything else we should preserve it.
  1220. if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
  1221. var new_line_needed = reserved_array(this._flags.last_token, special_words) && current_token.newlines;
  1222. if (new_line_needed && (this._previous_flags.if_block || this._previous_flags.else_block)) {
  1223. this.restore_mode();
  1224. }
  1225. this.print_newline(new_line_needed, true);
  1226. }
  1227. if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
  1228. // for (;; ++i)
  1229. // ^^^
  1230. space_before = true;
  1231. }
  1232. if (this._flags.last_token.type === TOKEN.RESERVED) {
  1233. space_before = true;
  1234. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  1235. space_before = !(this._flags.last_token.text === ']' && (current_token.text === '--' || current_token.text === '++'));
  1236. } else if (this._flags.last_token.type === TOKEN.OPERATOR) {
  1237. // a++ + ++b;
  1238. // a - -b
  1239. space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(this._flags.last_token.text, ['--', '-', '++', '+']);
  1240. // + and - are not unary when preceeded by -- or ++ operator
  1241. // a-- + b
  1242. // a * +b
  1243. // a - -b
  1244. if (in_array(current_token.text, ['+', '-']) && in_array(this._flags.last_token.text, ['--', '++'])) {
  1245. space_after = true;
  1246. }
  1247. }
  1248. if (((this._flags.mode === MODE.BlockStatement && !this._flags.inline_frame) || this._flags.mode === MODE.Statement) &&
  1249. (this._flags.last_token.text === '{' || this._flags.last_token.text === ';')) {
  1250. // { foo; --i }
  1251. // foo(); --bar;
  1252. this.print_newline();
  1253. }
  1254. }
  1255. this._output.space_before_token = this._output.space_before_token || space_before;
  1256. this.print_token(current_token);
  1257. this._output.space_before_token = space_after;
  1258. };
  1259. Beautifier.prototype.handle_block_comment = function(current_token, preserve_statement_flags) {
  1260. if (this._output.raw) {
  1261. this._output.add_raw_token(current_token);
  1262. if (current_token.directives && current_token.directives.preserve === 'end') {
  1263. // If we're testing the raw output behavior, do not allow a directive to turn it off.
  1264. this._output.raw = this._options.test_output_raw;
  1265. }
  1266. return;
  1267. }
  1268. if (current_token.directives) {
  1269. this.print_newline(false, preserve_statement_flags);
  1270. this.print_token(current_token);
  1271. if (current_token.directives.preserve === 'start') {
  1272. this._output.raw = true;
  1273. }
  1274. this.print_newline(false, true);
  1275. return;
  1276. }
  1277. // inline block
  1278. if (!acorn.newline.test(current_token.text) && !current_token.newlines) {
  1279. this._output.space_before_token = true;
  1280. this.print_token(current_token);
  1281. this._output.space_before_token = true;
  1282. return;
  1283. } else {
  1284. this.print_block_commment(current_token, preserve_statement_flags);
  1285. }
  1286. };
  1287. Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) {
  1288. var lines = split_linebreaks(current_token.text);
  1289. var j; // iterator for this case
  1290. var javadoc = false;
  1291. var starless = false;
  1292. var lastIndent = current_token.whitespace_before;
  1293. var lastIndentLength = lastIndent.length;
  1294. // block comment starts with a new line
  1295. this.print_newline(false, preserve_statement_flags);
  1296. // first line always indented
  1297. this.print_token_line_indentation(current_token);
  1298. this._output.add_token(lines[0]);
  1299. this.print_newline(false, preserve_statement_flags);
  1300. if (lines.length > 1) {
  1301. lines = lines.slice(1);
  1302. javadoc = all_lines_start_with(lines, '*');
  1303. starless = each_line_matches_indent(lines, lastIndent);
  1304. if (javadoc) {
  1305. this._flags.alignment = 1;
  1306. }
  1307. for (j = 0; j < lines.length; j++) {
  1308. if (javadoc) {
  1309. // javadoc: reformat and re-indent
  1310. this.print_token_line_indentation(current_token);
  1311. this._output.add_token(ltrim(lines[j]));
  1312. } else if (starless && lines[j]) {
  1313. // starless: re-indent non-empty content, avoiding trim
  1314. this.print_token_line_indentation(current_token);
  1315. this._output.add_token(lines[j].substring(lastIndentLength));
  1316. } else {
  1317. // normal comments output raw
  1318. this._output.current_line.set_indent(-1);
  1319. this._output.add_token(lines[j]);
  1320. }
  1321. // for comments on their own line or more than one line, make sure there's a new line after
  1322. this.print_newline(false, preserve_statement_flags);
  1323. }
  1324. this._flags.alignment = 0;
  1325. }
  1326. };
  1327. Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
  1328. if (current_token.newlines) {
  1329. this.print_newline(false, preserve_statement_flags);
  1330. } else {
  1331. this._output.trim(true);
  1332. }
  1333. this._output.space_before_token = true;
  1334. this.print_token(current_token);
  1335. this.print_newline(false, preserve_statement_flags);
  1336. };
  1337. Beautifier.prototype.handle_dot = function(current_token) {
  1338. if (this.start_of_statement(current_token)) {
  1339. // The conditional starts the statement if appropriate.
  1340. } else {
  1341. this.handle_whitespace_and_comments(current_token, true);
  1342. }
  1343. if (this._flags.last_token.text.match('^[0-9]+$')) {
  1344. this._output.space_before_token = true;
  1345. }
  1346. if (reserved_array(this._flags.last_token, special_words)) {
  1347. this._output.space_before_token = false;
  1348. } else {
  1349. // allow preserved newlines before dots in general
  1350. // force newlines on dots after close paren when break_chained - for bar().baz()
  1351. this.allow_wrap_or_preserved_newline(current_token,
  1352. this._flags.last_token.text === ')' && this._options.break_chained_methods);
  1353. }
  1354. // Only unindent chained method dot if this dot starts a new line.
  1355. // Otherwise the automatic extra indentation removal will handle the over indent
  1356. if (this._options.unindent_chained_methods && this._output.just_added_newline()) {
  1357. this.deindent();
  1358. }
  1359. this.print_token(current_token);
  1360. };
  1361. Beautifier.prototype.handle_unknown = function(current_token, preserve_statement_flags) {
  1362. this.print_token(current_token);
  1363. if (current_token.text[current_token.text.length - 1] === '\n') {
  1364. this.print_newline(false, preserve_statement_flags);
  1365. }
  1366. };
  1367. Beautifier.prototype.handle_eof = function(current_token) {
  1368. // Unwind any open statements
  1369. while (this._flags.mode === MODE.Statement) {
  1370. this.restore_mode();
  1371. }
  1372. this.handle_whitespace_and_comments(current_token);
  1373. };
  1374. module.exports.Beautifier = Beautifier;
  1375. /***/ }),
  1376. /* 3 */
  1377. /***/ (function(module) {
  1378. /*jshint node:true */
  1379. /*
  1380. The MIT License (MIT)
  1381. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1382. Permission is hereby granted, free of charge, to any person
  1383. obtaining a copy of this software and associated documentation files
  1384. (the "Software"), to deal in the Software without restriction,
  1385. including without limitation the rights to use, copy, modify, merge,
  1386. publish, distribute, sublicense, and/or sell copies of the Software,
  1387. and to permit persons to whom the Software is furnished to do so,
  1388. subject to the following conditions:
  1389. The above copyright notice and this permission notice shall be
  1390. included in all copies or substantial portions of the Software.
  1391. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1392. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1393. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1394. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1395. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1396. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1397. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1398. SOFTWARE.
  1399. */
  1400. function OutputLine(parent) {
  1401. this.__parent = parent;
  1402. this.__character_count = 0;
  1403. // use indent_count as a marker for this.__lines that have preserved indentation
  1404. this.__indent_count = -1;
  1405. this.__alignment_count = 0;
  1406. this.__wrap_point_index = 0;
  1407. this.__wrap_point_character_count = 0;
  1408. this.__wrap_point_indent_count = -1;
  1409. this.__wrap_point_alignment_count = 0;
  1410. this.__items = [];
  1411. }
  1412. OutputLine.prototype.clone_empty = function() {
  1413. var line = new OutputLine(this.__parent);
  1414. line.set_indent(this.__indent_count, this.__alignment_count);
  1415. return line;
  1416. };
  1417. OutputLine.prototype.item = function(index) {
  1418. if (index < 0) {
  1419. return this.__items[this.__items.length + index];
  1420. } else {
  1421. return this.__items[index];
  1422. }
  1423. };
  1424. OutputLine.prototype.has_match = function(pattern) {
  1425. for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
  1426. if (this.__items[lastCheckedOutput].match(pattern)) {
  1427. return true;
  1428. }
  1429. }
  1430. return false;
  1431. };
  1432. OutputLine.prototype.set_indent = function(indent, alignment) {
  1433. if (this.is_empty()) {
  1434. this.__indent_count = indent || 0;
  1435. this.__alignment_count = alignment || 0;
  1436. this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
  1437. }
  1438. };
  1439. OutputLine.prototype._set_wrap_point = function() {
  1440. if (this.__parent.wrap_line_length) {
  1441. this.__wrap_point_index = this.__items.length;
  1442. this.__wrap_point_character_count = this.__character_count;
  1443. this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
  1444. this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
  1445. }
  1446. };
  1447. OutputLine.prototype._should_wrap = function() {
  1448. return this.__wrap_point_index &&
  1449. this.__character_count > this.__parent.wrap_line_length &&
  1450. this.__wrap_point_character_count > this.__parent.next_line.__character_count;
  1451. };
  1452. OutputLine.prototype._allow_wrap = function() {
  1453. if (this._should_wrap()) {
  1454. this.__parent.add_new_line();
  1455. var next = this.__parent.current_line;
  1456. next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
  1457. next.__items = this.__items.slice(this.__wrap_point_index);
  1458. this.__items = this.__items.slice(0, this.__wrap_point_index);
  1459. next.__character_count += this.__character_count - this.__wrap_point_character_count;
  1460. this.__character_count = this.__wrap_point_character_count;
  1461. if (next.__items[0] === " ") {
  1462. next.__items.splice(0, 1);
  1463. next.__character_count -= 1;
  1464. }
  1465. return true;
  1466. }
  1467. return false;
  1468. };
  1469. OutputLine.prototype.is_empty = function() {
  1470. return this.__items.length === 0;
  1471. };
  1472. OutputLine.prototype.last = function() {
  1473. if (!this.is_empty()) {
  1474. return this.__items[this.__items.length - 1];
  1475. } else {
  1476. return null;
  1477. }
  1478. };
  1479. OutputLine.prototype.push = function(item) {
  1480. this.__items.push(item);
  1481. var last_newline_index = item.lastIndexOf('\n');
  1482. if (last_newline_index !== -1) {
  1483. this.__character_count = item.length - last_newline_index;
  1484. } else {
  1485. this.__character_count += item.length;
  1486. }
  1487. };
  1488. OutputLine.prototype.pop = function() {
  1489. var item = null;
  1490. if (!this.is_empty()) {
  1491. item = this.__items.pop();
  1492. this.__character_count -= item.length;
  1493. }
  1494. return item;
  1495. };
  1496. OutputLine.prototype._remove_indent = function() {
  1497. if (this.__indent_count > 0) {
  1498. this.__indent_count -= 1;
  1499. this.__character_count -= this.__parent.indent_size;
  1500. }
  1501. };
  1502. OutputLine.prototype._remove_wrap_indent = function() {
  1503. if (this.__wrap_point_indent_count > 0) {
  1504. this.__wrap_point_indent_count -= 1;
  1505. }
  1506. };
  1507. OutputLine.prototype.trim = function() {
  1508. while (this.last() === ' ') {
  1509. this.__items.pop();
  1510. this.__character_count -= 1;
  1511. }
  1512. };
  1513. OutputLine.prototype.toString = function() {
  1514. var result = '';
  1515. if (this.is_empty()) {
  1516. if (this.__parent.indent_empty_lines) {
  1517. result = this.__parent.get_indent_string(this.__indent_count);
  1518. }
  1519. } else {
  1520. result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
  1521. result += this.__items.join('');
  1522. }
  1523. return result;
  1524. };
  1525. function IndentStringCache(options, baseIndentString) {
  1526. this.__cache = [''];
  1527. this.__indent_size = options.indent_size;
  1528. this.__indent_string = options.indent_char;
  1529. if (!options.indent_with_tabs) {
  1530. this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
  1531. }
  1532. // Set to null to continue support for auto detection of base indent
  1533. baseIndentString = baseIndentString || '';
  1534. if (options.indent_level > 0) {
  1535. baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
  1536. }
  1537. this.__base_string = baseIndentString;
  1538. this.__base_string_length = baseIndentString.length;
  1539. }
  1540. IndentStringCache.prototype.get_indent_size = function(indent, column) {
  1541. var result = this.__base_string_length;
  1542. column = column || 0;
  1543. if (indent < 0) {
  1544. result = 0;
  1545. }
  1546. result += indent * this.__indent_size;
  1547. result += column;
  1548. return result;
  1549. };
  1550. IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
  1551. var result = this.__base_string;
  1552. column = column || 0;
  1553. if (indent_level < 0) {
  1554. indent_level = 0;
  1555. result = '';
  1556. }
  1557. column += indent_level * this.__indent_size;
  1558. this.__ensure_cache(column);
  1559. result += this.__cache[column];
  1560. return result;
  1561. };
  1562. IndentStringCache.prototype.__ensure_cache = function(column) {
  1563. while (column >= this.__cache.length) {
  1564. this.__add_column();
  1565. }
  1566. };
  1567. IndentStringCache.prototype.__add_column = function() {
  1568. var column = this.__cache.length;
  1569. var indent = 0;
  1570. var result = '';
  1571. if (this.__indent_size && column >= this.__indent_size) {
  1572. indent = Math.floor(column / this.__indent_size);
  1573. column -= indent * this.__indent_size;
  1574. result = new Array(indent + 1).join(this.__indent_string);
  1575. }
  1576. if (column) {
  1577. result += new Array(column + 1).join(' ');
  1578. }
  1579. this.__cache.push(result);
  1580. };
  1581. function Output(options, baseIndentString) {
  1582. this.__indent_cache = new IndentStringCache(options, baseIndentString);
  1583. this.raw = false;
  1584. this._end_with_newline = options.end_with_newline;
  1585. this.indent_size = options.indent_size;
  1586. this.wrap_line_length = options.wrap_line_length;
  1587. this.indent_empty_lines = options.indent_empty_lines;
  1588. this.__lines = [];
  1589. this.previous_line = null;
  1590. this.current_line = null;
  1591. this.next_line = new OutputLine(this);
  1592. this.space_before_token = false;
  1593. this.non_breaking_space = false;
  1594. this.previous_token_wrapped = false;
  1595. // initialize
  1596. this.__add_outputline();
  1597. }
  1598. Output.prototype.__add_outputline = function() {
  1599. this.previous_line = this.current_line;
  1600. this.current_line = this.next_line.clone_empty();
  1601. this.__lines.push(this.current_line);
  1602. };
  1603. Output.prototype.get_line_number = function() {
  1604. return this.__lines.length;
  1605. };
  1606. Output.prototype.get_indent_string = function(indent, column) {
  1607. return this.__indent_cache.get_indent_string(indent, column);
  1608. };
  1609. Output.prototype.get_indent_size = function(indent, column) {
  1610. return this.__indent_cache.get_indent_size(indent, column);
  1611. };
  1612. Output.prototype.is_empty = function() {
  1613. return !this.previous_line && this.current_line.is_empty();
  1614. };
  1615. Output.prototype.add_new_line = function(force_newline) {
  1616. // never newline at the start of file
  1617. // otherwise, newline only if we didn't just add one or we're forced
  1618. if (this.is_empty() ||
  1619. (!force_newline && this.just_added_newline())) {
  1620. return false;
  1621. }
  1622. // if raw output is enabled, don't print additional newlines,
  1623. // but still return True as though you had
  1624. if (!this.raw) {
  1625. this.__add_outputline();
  1626. }
  1627. return true;
  1628. };
  1629. Output.prototype.get_code = function(eol) {
  1630. this.trim(true);
  1631. // handle some edge cases where the last tokens
  1632. // has text that ends with newline(s)
  1633. var last_item = this.current_line.pop();
  1634. if (last_item) {
  1635. if (last_item[last_item.length - 1] === '\n') {
  1636. last_item = last_item.replace(/\n+$/g, '');
  1637. }
  1638. this.current_line.push(last_item);
  1639. }
  1640. if (this._end_with_newline) {
  1641. this.__add_outputline();
  1642. }
  1643. var sweet_code = this.__lines.join('\n');
  1644. if (eol !== '\n') {
  1645. sweet_code = sweet_code.replace(/[\n]/g, eol);
  1646. }
  1647. return sweet_code;
  1648. };
  1649. Output.prototype.set_wrap_point = function() {
  1650. this.current_line._set_wrap_point();
  1651. };
  1652. Output.prototype.set_indent = function(indent, alignment) {
  1653. indent = indent || 0;
  1654. alignment = alignment || 0;
  1655. // Next line stores alignment values
  1656. this.next_line.set_indent(indent, alignment);
  1657. // Never indent your first output indent at the start of the file
  1658. if (this.__lines.length > 1) {
  1659. this.current_line.set_indent(indent, alignment);
  1660. return true;
  1661. }
  1662. this.current_line.set_indent();
  1663. return false;
  1664. };
  1665. Output.prototype.add_raw_token = function(token) {
  1666. for (var x = 0; x < token.newlines; x++) {
  1667. this.__add_outputline();
  1668. }
  1669. this.current_line.set_indent(-1);
  1670. this.current_line.push(token.whitespace_before);
  1671. this.current_line.push(token.text);
  1672. this.space_before_token = false;
  1673. this.non_breaking_space = false;
  1674. this.previous_token_wrapped = false;
  1675. };
  1676. Output.prototype.add_token = function(printable_token) {
  1677. this.__add_space_before_token();
  1678. this.current_line.push(printable_token);
  1679. this.space_before_token = false;
  1680. this.non_breaking_space = false;
  1681. this.previous_token_wrapped = this.current_line._allow_wrap();
  1682. };
  1683. Output.prototype.__add_space_before_token = function() {
  1684. if (this.space_before_token && !this.just_added_newline()) {
  1685. if (!this.non_breaking_space) {
  1686. this.set_wrap_point();
  1687. }
  1688. this.current_line.push(' ');
  1689. }
  1690. };
  1691. Output.prototype.remove_indent = function(index) {
  1692. var output_length = this.__lines.length;
  1693. while (index < output_length) {
  1694. this.__lines[index]._remove_indent();
  1695. index++;
  1696. }
  1697. this.current_line._remove_wrap_indent();
  1698. };
  1699. Output.prototype.trim = function(eat_newlines) {
  1700. eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
  1701. this.current_line.trim();
  1702. while (eat_newlines && this.__lines.length > 1 &&
  1703. this.current_line.is_empty()) {
  1704. this.__lines.pop();
  1705. this.current_line = this.__lines[this.__lines.length - 1];
  1706. this.current_line.trim();
  1707. }
  1708. this.previous_line = this.__lines.length > 1 ?
  1709. this.__lines[this.__lines.length - 2] : null;
  1710. };
  1711. Output.prototype.just_added_newline = function() {
  1712. return this.current_line.is_empty();
  1713. };
  1714. Output.prototype.just_added_blankline = function() {
  1715. return this.is_empty() ||
  1716. (this.current_line.is_empty() && this.previous_line.is_empty());
  1717. };
  1718. Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
  1719. var index = this.__lines.length - 2;
  1720. while (index >= 0) {
  1721. var potentialEmptyLine = this.__lines[index];
  1722. if (potentialEmptyLine.is_empty()) {
  1723. break;
  1724. } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
  1725. potentialEmptyLine.item(-1) !== ends_with) {
  1726. this.__lines.splice(index + 1, 0, new OutputLine(this));
  1727. this.previous_line = this.__lines[this.__lines.length - 2];
  1728. break;
  1729. }
  1730. index--;
  1731. }
  1732. };
  1733. module.exports.Output = Output;
  1734. /***/ }),
  1735. /* 4 */
  1736. /***/ (function(module) {
  1737. /*jshint node:true */
  1738. /*
  1739. The MIT License (MIT)
  1740. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1741. Permission is hereby granted, free of charge, to any person
  1742. obtaining a copy of this software and associated documentation files
  1743. (the "Software"), to deal in the Software without restriction,
  1744. including without limitation the rights to use, copy, modify, merge,
  1745. publish, distribute, sublicense, and/or sell copies of the Software,
  1746. and to permit persons to whom the Software is furnished to do so,
  1747. subject to the following conditions:
  1748. The above copyright notice and this permission notice shall be
  1749. included in all copies or substantial portions of the Software.
  1750. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1751. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1752. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1753. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1754. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1755. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1756. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1757. SOFTWARE.
  1758. */
  1759. function Token(type, text, newlines, whitespace_before) {
  1760. this.type = type;
  1761. this.text = text;
  1762. // comments_before are
  1763. // comments that have a new line before them
  1764. // and may or may not have a newline after
  1765. // this is a set of comments before
  1766. this.comments_before = null; /* inline comment*/
  1767. // this.comments_after = new TokenStream(); // no new line before and newline after
  1768. this.newlines = newlines || 0;
  1769. this.whitespace_before = whitespace_before || '';
  1770. this.parent = null;
  1771. this.next = null;
  1772. this.previous = null;
  1773. this.opened = null;
  1774. this.closed = null;
  1775. this.directives = null;
  1776. }
  1777. module.exports.Token = Token;
  1778. /***/ }),
  1779. /* 5 */
  1780. /***/ (function(__unused_webpack_module, exports) {
  1781. /* jshint node: true, curly: false */
  1782. // Parts of this section of code is taken from acorn.
  1783. //
  1784. // Acorn was written by Marijn Haverbeke and released under an MIT
  1785. // license. The Unicode regexps (for identifiers and whitespace) were
  1786. // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
  1787. //
  1788. // Git repositories for Acorn are available at
  1789. //
  1790. // http://marijnhaverbeke.nl/git/acorn
  1791. // https://github.com/marijnh/acorn.git
  1792. // ## Character categories
  1793. // acorn used char codes to squeeze the last bit of performance out
  1794. // Beautifier is okay without that, so we're using regex
  1795. // permit # (23), $ (36), and @ (64). @ is used in ES7 decorators.
  1796. // 65 through 91 are uppercase letters.
  1797. // permit _ (95).
  1798. // 97 through 123 are lowercase letters.
  1799. var baseASCIIidentifierStartChars = "\\x23\\x24\\x40\\x41-\\x5a\\x5f\\x61-\\x7a";
  1800. // inside an identifier @ is not allowed but 0-9 are.
  1801. var baseASCIIidentifierChars = "\\x24\\x30-\\x39\\x41-\\x5a\\x5f\\x61-\\x7a";
  1802. // Big ugly regular expressions that match characters in the
  1803. // whitespace, identifier, and identifier-start categories. These
  1804. // are only applied when a character is found to actually have a
  1805. // code point above 128.
  1806. var nonASCIIidentifierStartChars = "\\xaa\\xb5\\xba\\xc0-\\xd6\\xd8-\\xf6\\xf8-\\u02c1\\u02c6-\\u02d1\\u02e0-\\u02e4\\u02ec\\u02ee\\u0370-\\u0374\\u0376\\u0377\\u037a-\\u037d\\u0386\\u0388-\\u038a\\u038c\\u038e-\\u03a1\\u03a3-\\u03f5\\u03f7-\\u0481\\u048a-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05d0-\\u05ea\\u05f0-\\u05f2\\u0620-\\u064a\\u066e\\u066f\\u0671-\\u06d3\\u06d5\\u06e5\\u06e6\\u06ee\\u06ef\\u06fa-\\u06fc\\u06ff\\u0710\\u0712-\\u072f\\u074d-\\u07a5\\u07b1\\u07ca-\\u07ea\\u07f4\\u07f5\\u07fa\\u0800-\\u0815\\u081a\\u0824\\u0828\\u0840-\\u0858\\u08a0\\u08a2-\\u08ac\\u0904-\\u0939\\u093d\\u0950\\u0958-\\u0961\\u0971-\\u0977\\u0979-\\u097f\\u0985-\\u098c\\u098f\\u0990\\u0993-\\u09a8\\u09aa-\\u09b0\\u09b2\\u09b6-\\u09b9\\u09bd\\u09ce\\u09dc\\u09dd\\u09df-\\u09e1\\u09f0\\u09f1\\u0a05-\\u0a0a\\u0a0f\\u0a10\\u0a13-\\u0a28\\u0a2a-\\u0a30\\u0a32\\u0a33\\u0a35\\u0a36\\u0a38\\u0a39\\u0a59-\\u0a5c\\u0a5e\\u0a72-\\u0a74\\u0a85-\\u0a8d\\u0a8f-\\u0a91\\u0a93-\\u0aa8\\u0aaa-\\u0ab0\\u0ab2\\u0ab3\\u0ab5-\\u0ab9\\u0abd\\u0ad0\\u0ae0\\u0ae1\\u0b05-\\u0b0c\\u0b0f\\u0b10\\u0b13-\\u0b28\\u0b2a-\\u0b30\\u0b32\\u0b33\\u0b35-\\u0b39\\u0b3d\\u0b5c\\u0b5d\\u0b5f-\\u0b61\\u0b71\\u0b83\\u0b85-\\u0b8a\\u0b8e-\\u0b90\\u0b92-\\u0b95\\u0b99\\u0b9a\\u0b9c\\u0b9e\\u0b9f\\u0ba3\\u0ba4\\u0ba8-\\u0baa\\u0bae-\\u0bb9\\u0bd0\\u0c05-\\u0c0c\\u0c0e-\\u0c10\\u0c12-\\u0c28\\u0c2a-\\u0c33\\u0c35-\\u0c39\\u0c3d\\u0c58\\u0c59\\u0c60\\u0c61\\u0c85-\\u0c8c\\u0c8e-\\u0c90\\u0c92-\\u0ca8\\u0caa-\\u0cb3\\u0cb5-\\u0cb9\\u0cbd\\u0cde\\u0ce0\\u0ce1\\u0cf1\\u0cf2\\u0d05-\\u0d0c\\u0d0e-\\u0d10\\u0d12-\\u0d3a\\u0d3d\\u0d4e\\u0d60\\u0d61\\u0d7a-\\u0d7f\\u0d85-\\u0d96\\u0d9a-\\u0db1\\u0db3-\\u0dbb\\u0dbd\\u0dc0-\\u0dc6\\u0e01-\\u0e30\\u0e32\\u0e33\\u0e40-\\u0e46\\u0e81\\u0e82\\u0e84\\u0e87\\u0e88\\u0e8a\\u0e8d\\u0e94-\\u0e97\\u0e99-\\u0e9f\\u0ea1-\\u0ea3\\u0ea5\\u0ea7\\u0eaa\\u0eab\\u0ead-\\u0eb0\\u0eb2\\u0eb3\\u0ebd\\u0ec0-\\u0ec4\\u0ec6\\u0edc-\\u0edf\\u0f00\\u0f40-\\u0f47\\u0f49-\\u0f6c\\u0f88-\\u0f8c\\u1000-\\u102a\\u103f\\u1050-\\u1055\\u105a-\\u105d\\u1061\\u1065\\u1066\\u106e-\\u1070\\u1075-\\u1081\\u108e\\u10a0-\\u10c5\\u10c7\\u10cd\\u10d0-\\u10fa\\u10fc-\\u1248\\u124a-\\u124d\\u1250-\\u1256\\u1258\\u125a-\\u125d\\u1260-\\u1288\\u128a-\\u128d\\u1290-\\u12b0\\u12b2-\\u12b5\\u12b8-\\u12be\\u12c0\\u12c2-\\u12c5\\u12c8-\\u12d6\\u12d8-\\u1310\\u1312-\\u1315\\u1318-\\u135a\\u1380-\\u138f\\u13a0-\\u13f4\\u1401-\\u166c\\u166f-\\u167f\\u1681-\\u169a\\u16a0-\\u16ea\\u16ee-\\u16f0\\u1700-\\u170c\\u170e-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176c\\u176e-\\u1770\\u1780-\\u17b3\\u17d7\\u17dc\\u1820-\\u1877\\u1880-\\u18a8\\u18aa\\u18b0-\\u18f5\\u1900-\\u191c\\u1950-\\u196d\\u1970-\\u1974\\u1980-\\u19ab\\u19c1-\\u19c7\\u1a00-\\u1a16\\u1a20-\\u1a54\\u1aa7\\u1b05-\\u1b33\\u1b45-\\u1b4b\\u1b83-\\u1ba0\\u1bae\\u1baf\\u1bba-\\u1be5\\u1c00-\\u1c23\\u1c4d-\\u1c4f\\u1c5a-\\u1c7d\\u1ce9-\\u1cec\\u1cee-\\u1cf1\\u1cf5\\u1cf6\\u1d00-\\u1dbf\\u1e00-\\u1f15\\u1f18-\\u1f1d\\u1f20-\\u1f45\\u1f48-\\u1f4d\\u1f50-\\u1f57\\u1f59\\u1f5b\\u1f5d\\u1f5f-\\u1f7d\\u1f80-\\u1fb4\\u1fb6-\\u1fbc\\u1fbe\\u1fc2-\\u1fc4\\u1fc6-\\u1fcc\\u1fd0-\\u1fd3\\u1fd6-\\u1fdb\\u1fe0-\\u1fec\\u1ff2-\\u1ff4\\u1ff6-\\u1ffc\\u2071\\u207f\\u2090-\\u209c\\u2102\\u2107\\u210a-\\u2113\\u2115\\u2119-\\u211d\\u2124\\u2126\\u2128\\u212a-\\u212d\\u212f-\\u2139\\u213c-\\u213f\\u2145-\\u2149\\u214e\\u2160-\\u2188\\u2c00-\\u2c2e\\u2c30-\\u2c5e\\u2c60-\\u2ce4\\u2ceb-\\u2cee\\u2cf2\\u2cf3\\u2d00-\\u2d25\\u2d27\\u2d2d\\u2d30-\\u2d67\\u2d6f\\u2d80-\\u2d96\\u2da0-\\u2da6\\u2da8-\\u2dae\\u2db0-\\u2db6\\u2db8-\\u2dbe\\u2dc0-\\u2dc6\\u2dc8-\\u2dce\\u2dd0-\\u2dd6\\u2dd8-\\u2dde\\u2e2f\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303c\\u3041-\\u3096\\u309d-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312d\\u3131-\\u318e\\u31a0-\\u31ba\\u31f0-\\u31ff\\u3400-\\u4db5\\u4e00-\\u9fcc\\ua000-\\ua48c\\ua4d0-\\ua4fd\\ua500-\\ua60c\\ua610-\\ua61f\\ua62a\\ua62b\\ua640-\\ua66e\\ua67f-\\ua697\\ua6a0-\\ua6ef\\ua717-\\ua71f\\ua722-\\ua788\\ua78b-\\ua78e\\ua790-\\ua793\\ua7a0-\\ua7aa\\ua7f8-\\ua801\\ua803-\\ua805\\ua807-\\ua80a\\ua80c-\\ua822\\ua840-\\ua873\\ua882-\\ua8b3\\ua8f2-\\ua8f7\\ua8fb\\ua90a-\\ua925\\ua930-\\ua946\\ua960-\\ua97c\\ua984-\\ua9b2\\ua9cf\\uaa00-\\uaa28\\uaa40-\\uaa42\\uaa44-\\uaa4b\\uaa60-\\uaa76\\uaa7a\\uaa80-\\uaaaf\\uaab1\\uaab5\\uaab6\\uaab9-\\uaabd\\uaac0\\uaac2\\uaadb-\\uaadd\\uaae0-\\uaaea\\uaaf2-\\uaaf4\\uab01-\\uab06\\uab09-\\uab0e\\uab11-\\uab16\\uab20-\\uab26\\uab28-\\uab2e\\uabc0-\\uabe2\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufb00-\\ufb06\\ufb13-\\ufb17\\ufb1d\\ufb1f-\\ufb28\\ufb2a-\\ufb36\\ufb38-\\ufb3c\\ufb3e\\ufb40\\ufb41\\ufb43\\ufb44\\ufb46-\\ufbb1\\ufbd3-\\ufd3d\\ufd50-\\ufd8f\\ufd92-\\ufdc7\\ufdf0-\\ufdfb\\ufe70-\\ufe74\\ufe76-\\ufefc\\uff21-\\uff3a\\uff41-\\uff5a\\uff66-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc";
  1807. var nonASCIIidentifierChars = "\\u0300-\\u036f\\u0483-\\u0487\\u0591-\\u05bd\\u05bf\\u05c1\\u05c2\\u05c4\\u05c5\\u05c7\\u0610-\\u061a\\u0620-\\u0649\\u0672-\\u06d3\\u06e7-\\u06e8\\u06fb-\\u06fc\\u0730-\\u074a\\u0800-\\u0814\\u081b-\\u0823\\u0825-\\u0827\\u0829-\\u082d\\u0840-\\u0857\\u08e4-\\u08fe\\u0900-\\u0903\\u093a-\\u093c\\u093e-\\u094f\\u0951-\\u0957\\u0962-\\u0963\\u0966-\\u096f\\u0981-\\u0983\\u09bc\\u09be-\\u09c4\\u09c7\\u09c8\\u09d7\\u09df-\\u09e0\\u0a01-\\u0a03\\u0a3c\\u0a3e-\\u0a42\\u0a47\\u0a48\\u0a4b-\\u0a4d\\u0a51\\u0a66-\\u0a71\\u0a75\\u0a81-\\u0a83\\u0abc\\u0abe-\\u0ac5\\u0ac7-\\u0ac9\\u0acb-\\u0acd\\u0ae2-\\u0ae3\\u0ae6-\\u0aef\\u0b01-\\u0b03\\u0b3c\\u0b3e-\\u0b44\\u0b47\\u0b48\\u0b4b-\\u0b4d\\u0b56\\u0b57\\u0b5f-\\u0b60\\u0b66-\\u0b6f\\u0b82\\u0bbe-\\u0bc2\\u0bc6-\\u0bc8\\u0bca-\\u0bcd\\u0bd7\\u0be6-\\u0bef\\u0c01-\\u0c03\\u0c46-\\u0c48\\u0c4a-\\u0c4d\\u0c55\\u0c56\\u0c62-\\u0c63\\u0c66-\\u0c6f\\u0c82\\u0c83\\u0cbc\\u0cbe-\\u0cc4\\u0cc6-\\u0cc8\\u0cca-\\u0ccd\\u0cd5\\u0cd6\\u0ce2-\\u0ce3\\u0ce6-\\u0cef\\u0d02\\u0d03\\u0d46-\\u0d48\\u0d57\\u0d62-\\u0d63\\u0d66-\\u0d6f\\u0d82\\u0d83\\u0dca\\u0dcf-\\u0dd4\\u0dd6\\u0dd8-\\u0ddf\\u0df2\\u0df3\\u0e34-\\u0e3a\\u0e40-\\u0e45\\u0e50-\\u0e59\\u0eb4-\\u0eb9\\u0ec8-\\u0ecd\\u0ed0-\\u0ed9\\u0f18\\u0f19\\u0f20-\\u0f29\\u0f35\\u0f37\\u0f39\\u0f41-\\u0f47\\u0f71-\\u0f84\\u0f86-\\u0f87\\u0f8d-\\u0f97\\u0f99-\\u0fbc\\u0fc6\\u1000-\\u1029\\u1040-\\u1049\\u1067-\\u106d\\u1071-\\u1074\\u1082-\\u108d\\u108f-\\u109d\\u135d-\\u135f\\u170e-\\u1710\\u1720-\\u1730\\u1740-\\u1750\\u1772\\u1773\\u1780-\\u17b2\\u17dd\\u17e0-\\u17e9\\u180b-\\u180d\\u1810-\\u1819\\u1920-\\u192b\\u1930-\\u193b\\u1951-\\u196d\\u19b0-\\u19c0\\u19c8-\\u19c9\\u19d0-\\u19d9\\u1a00-\\u1a15\\u1a20-\\u1a53\\u1a60-\\u1a7c\\u1a7f-\\u1a89\\u1a90-\\u1a99\\u1b46-\\u1b4b\\u1b50-\\u1b59\\u1b6b-\\u1b73\\u1bb0-\\u1bb9\\u1be6-\\u1bf3\\u1c00-\\u1c22\\u1c40-\\u1c49\\u1c5b-\\u1c7d\\u1cd0-\\u1cd2\\u1d00-\\u1dbe\\u1e01-\\u1f15\\u200c\\u200d\\u203f\\u2040\\u2054\\u20d0-\\u20dc\\u20e1\\u20e5-\\u20f0\\u2d81-\\u2d96\\u2de0-\\u2dff\\u3021-\\u3028\\u3099\\u309a\\ua640-\\ua66d\\ua674-\\ua67d\\ua69f\\ua6f0-\\ua6f1\\ua7f8-\\ua800\\ua806\\ua80b\\ua823-\\ua827\\ua880-\\ua881\\ua8b4-\\ua8c4\\ua8d0-\\ua8d9\\ua8f3-\\ua8f7\\ua900-\\ua909\\ua926-\\ua92d\\ua930-\\ua945\\ua980-\\ua983\\ua9b3-\\ua9c0\\uaa00-\\uaa27\\uaa40-\\uaa41\\uaa4c-\\uaa4d\\uaa50-\\uaa59\\uaa7b\\uaae0-\\uaae9\\uaaf2-\\uaaf3\\uabc0-\\uabe1\\uabec\\uabed\\uabf0-\\uabf9\\ufb20-\\ufb28\\ufe00-\\ufe0f\\ufe20-\\ufe26\\ufe33\\ufe34\\ufe4d-\\ufe4f\\uff10-\\uff19\\uff3f";
  1808. //var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1809. //var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1810. var identifierStart = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
  1811. var identifierChars = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
  1812. exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
  1813. exports.identifierStart = new RegExp(identifierStart);
  1814. exports.identifierMatch = new RegExp("(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
  1815. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line
  1816. // Whether a single character denotes a newline.
  1817. exports.newline = /[\n\r\u2028\u2029]/;
  1818. // Matches a whole line break (where CRLF is considered a single
  1819. // line break). Used to count lines.
  1820. // in javascript, these two differ
  1821. // in python they are the same, different methods are called on them
  1822. exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
  1823. exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
  1824. /***/ }),
  1825. /* 6 */
  1826. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1827. /*jshint node:true */
  1828. /*
  1829. The MIT License (MIT)
  1830. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1831. Permission is hereby granted, free of charge, to any person
  1832. obtaining a copy of this software and associated documentation files
  1833. (the "Software"), to deal in the Software without restriction,
  1834. including without limitation the rights to use, copy, modify, merge,
  1835. publish, distribute, sublicense, and/or sell copies of the Software,
  1836. and to permit persons to whom the Software is furnished to do so,
  1837. subject to the following conditions:
  1838. The above copyright notice and this permission notice shall be
  1839. included in all copies or substantial portions of the Software.
  1840. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1841. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1842. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1843. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1844. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1845. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1846. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1847. SOFTWARE.
  1848. */
  1849. var BaseOptions = (__webpack_require__(7).Options);
  1850. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  1851. function Options(options) {
  1852. BaseOptions.call(this, options, 'js');
  1853. // compatibility, re
  1854. var raw_brace_style = this.raw_options.brace_style || null;
  1855. if (raw_brace_style === "expand-strict") { //graceful handling of deprecated option
  1856. this.raw_options.brace_style = "expand";
  1857. } else if (raw_brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
  1858. this.raw_options.brace_style = "collapse,preserve-inline";
  1859. } else if (this.raw_options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
  1860. this.raw_options.brace_style = this.raw_options.braces_on_own_line ? "expand" : "collapse";
  1861. // } else if (!raw_brace_style) { //Nothing exists to set it
  1862. // raw_brace_style = "collapse";
  1863. }
  1864. //preserve-inline in delimited string will trigger brace_preserve_inline, everything
  1865. //else is considered a brace_style and the last one only will have an effect
  1866. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  1867. this.brace_preserve_inline = false; //Defaults in case one or other was not specified in meta-option
  1868. this.brace_style = "collapse";
  1869. for (var bs = 0; bs < brace_style_split.length; bs++) {
  1870. if (brace_style_split[bs] === "preserve-inline") {
  1871. this.brace_preserve_inline = true;
  1872. } else {
  1873. this.brace_style = brace_style_split[bs];
  1874. }
  1875. }
  1876. this.unindent_chained_methods = this._get_boolean('unindent_chained_methods');
  1877. this.break_chained_methods = this._get_boolean('break_chained_methods');
  1878. this.space_in_paren = this._get_boolean('space_in_paren');
  1879. this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
  1880. this.jslint_happy = this._get_boolean('jslint_happy');
  1881. this.space_after_anon_function = this._get_boolean('space_after_anon_function');
  1882. this.space_after_named_function = this._get_boolean('space_after_named_function');
  1883. this.keep_array_indentation = this._get_boolean('keep_array_indentation');
  1884. this.space_before_conditional = this._get_boolean('space_before_conditional', true);
  1885. this.unescape_strings = this._get_boolean('unescape_strings');
  1886. this.e4x = this._get_boolean('e4x');
  1887. this.comma_first = this._get_boolean('comma_first');
  1888. this.operator_position = this._get_selection('operator_position', validPositionValues);
  1889. // For testing of beautify preserve:start directive
  1890. this.test_output_raw = this._get_boolean('test_output_raw');
  1891. // force this._options.space_after_anon_function to true if this._options.jslint_happy
  1892. if (this.jslint_happy) {
  1893. this.space_after_anon_function = true;
  1894. }
  1895. }
  1896. Options.prototype = new BaseOptions();
  1897. module.exports.Options = Options;
  1898. /***/ }),
  1899. /* 7 */
  1900. /***/ (function(module) {
  1901. /*jshint node:true */
  1902. /*
  1903. The MIT License (MIT)
  1904. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1905. Permission is hereby granted, free of charge, to any person
  1906. obtaining a copy of this software and associated documentation files
  1907. (the "Software"), to deal in the Software without restriction,
  1908. including without limitation the rights to use, copy, modify, merge,
  1909. publish, distribute, sublicense, and/or sell copies of the Software,
  1910. and to permit persons to whom the Software is furnished to do so,
  1911. subject to the following conditions:
  1912. The above copyright notice and this permission notice shall be
  1913. included in all copies or substantial portions of the Software.
  1914. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1915. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1916. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1917. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1918. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1919. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1920. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1921. SOFTWARE.
  1922. */
  1923. function Options(options, merge_child_field) {
  1924. this.raw_options = _mergeOpts(options, merge_child_field);
  1925. // Support passing the source text back with no change
  1926. this.disabled = this._get_boolean('disabled');
  1927. this.eol = this._get_characters('eol', 'auto');
  1928. this.end_with_newline = this._get_boolean('end_with_newline');
  1929. this.indent_size = this._get_number('indent_size', 4);
  1930. this.indent_char = this._get_characters('indent_char', ' ');
  1931. this.indent_level = this._get_number('indent_level');
  1932. this.preserve_newlines = this._get_boolean('preserve_newlines', true);
  1933. this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
  1934. if (!this.preserve_newlines) {
  1935. this.max_preserve_newlines = 0;
  1936. }
  1937. this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
  1938. if (this.indent_with_tabs) {
  1939. this.indent_char = '\t';
  1940. // indent_size behavior changed after 1.8.6
  1941. // It used to be that indent_size would be
  1942. // set to 1 for indent_with_tabs. That is no longer needed and
  1943. // actually doesn't make sense - why not use spaces? Further,
  1944. // that might produce unexpected behavior - tabs being used
  1945. // for single-column alignment. So, when indent_with_tabs is true
  1946. // and indent_size is 1, reset indent_size to 4.
  1947. if (this.indent_size === 1) {
  1948. this.indent_size = 4;
  1949. }
  1950. }
  1951. // Backwards compat with 1.3.x
  1952. this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
  1953. this.indent_empty_lines = this._get_boolean('indent_empty_lines');
  1954. // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty']
  1955. // For now, 'auto' = all off for javascript, all on for html (and inline javascript).
  1956. // other values ignored
  1957. this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
  1958. }
  1959. Options.prototype._get_array = function(name, default_value) {
  1960. var option_value = this.raw_options[name];
  1961. var result = default_value || [];
  1962. if (typeof option_value === 'object') {
  1963. if (option_value !== null && typeof option_value.concat === 'function') {
  1964. result = option_value.concat();
  1965. }
  1966. } else if (typeof option_value === 'string') {
  1967. result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
  1968. }
  1969. return result;
  1970. };
  1971. Options.prototype._get_boolean = function(name, default_value) {
  1972. var option_value = this.raw_options[name];
  1973. var result = option_value === undefined ? !!default_value : !!option_value;
  1974. return result;
  1975. };
  1976. Options.prototype._get_characters = function(name, default_value) {
  1977. var option_value = this.raw_options[name];
  1978. var result = default_value || '';
  1979. if (typeof option_value === 'string') {
  1980. result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
  1981. }
  1982. return result;
  1983. };
  1984. Options.prototype._get_number = function(name, default_value) {
  1985. var option_value = this.raw_options[name];
  1986. default_value = parseInt(default_value, 10);
  1987. if (isNaN(default_value)) {
  1988. default_value = 0;
  1989. }
  1990. var result = parseInt(option_value, 10);
  1991. if (isNaN(result)) {
  1992. result = default_value;
  1993. }
  1994. return result;
  1995. };
  1996. Options.prototype._get_selection = function(name, selection_list, default_value) {
  1997. var result = this._get_selection_list(name, selection_list, default_value);
  1998. if (result.length !== 1) {
  1999. throw new Error(
  2000. "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
  2001. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2002. }
  2003. return result[0];
  2004. };
  2005. Options.prototype._get_selection_list = function(name, selection_list, default_value) {
  2006. if (!selection_list || selection_list.length === 0) {
  2007. throw new Error("Selection list cannot be empty.");
  2008. }
  2009. default_value = default_value || [selection_list[0]];
  2010. if (!this._is_valid_selection(default_value, selection_list)) {
  2011. throw new Error("Invalid Default Value!");
  2012. }
  2013. var result = this._get_array(name, default_value);
  2014. if (!this._is_valid_selection(result, selection_list)) {
  2015. throw new Error(
  2016. "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
  2017. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2018. }
  2019. return result;
  2020. };
  2021. Options.prototype._is_valid_selection = function(result, selection_list) {
  2022. return result.length && selection_list.length &&
  2023. !result.some(function(item) { return selection_list.indexOf(item) === -1; });
  2024. };
  2025. // merges child options up with the parent options object
  2026. // Example: obj = {a: 1, b: {a: 2}}
  2027. // mergeOpts(obj, 'b')
  2028. //
  2029. // Returns: {a: 2}
  2030. function _mergeOpts(allOptions, childFieldName) {
  2031. var finalOpts = {};
  2032. allOptions = _normalizeOpts(allOptions);
  2033. var name;
  2034. for (name in allOptions) {
  2035. if (name !== childFieldName) {
  2036. finalOpts[name] = allOptions[name];
  2037. }
  2038. }
  2039. //merge in the per type settings for the childFieldName
  2040. if (childFieldName && allOptions[childFieldName]) {
  2041. for (name in allOptions[childFieldName]) {
  2042. finalOpts[name] = allOptions[childFieldName][name];
  2043. }
  2044. }
  2045. return finalOpts;
  2046. }
  2047. function _normalizeOpts(options) {
  2048. var convertedOpts = {};
  2049. var key;
  2050. for (key in options) {
  2051. var newKey = key.replace(/-/g, "_");
  2052. convertedOpts[newKey] = options[key];
  2053. }
  2054. return convertedOpts;
  2055. }
  2056. module.exports.Options = Options;
  2057. module.exports.normalizeOpts = _normalizeOpts;
  2058. module.exports.mergeOpts = _mergeOpts;
  2059. /***/ }),
  2060. /* 8 */
  2061. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2062. /*jshint node:true */
  2063. /*
  2064. The MIT License (MIT)
  2065. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2066. Permission is hereby granted, free of charge, to any person
  2067. obtaining a copy of this software and associated documentation files
  2068. (the "Software"), to deal in the Software without restriction,
  2069. including without limitation the rights to use, copy, modify, merge,
  2070. publish, distribute, sublicense, and/or sell copies of the Software,
  2071. and to permit persons to whom the Software is furnished to do so,
  2072. subject to the following conditions:
  2073. The above copyright notice and this permission notice shall be
  2074. included in all copies or substantial portions of the Software.
  2075. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2076. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2077. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2078. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2079. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2080. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2081. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2082. SOFTWARE.
  2083. */
  2084. var InputScanner = (__webpack_require__(9).InputScanner);
  2085. var BaseTokenizer = (__webpack_require__(10).Tokenizer);
  2086. var BASETOKEN = (__webpack_require__(10).TOKEN);
  2087. var Directives = (__webpack_require__(14).Directives);
  2088. var acorn = __webpack_require__(5);
  2089. var Pattern = (__webpack_require__(13).Pattern);
  2090. var TemplatablePattern = (__webpack_require__(15).TemplatablePattern);
  2091. function in_array(what, arr) {
  2092. return arr.indexOf(what) !== -1;
  2093. }
  2094. var TOKEN = {
  2095. START_EXPR: 'TK_START_EXPR',
  2096. END_EXPR: 'TK_END_EXPR',
  2097. START_BLOCK: 'TK_START_BLOCK',
  2098. END_BLOCK: 'TK_END_BLOCK',
  2099. WORD: 'TK_WORD',
  2100. RESERVED: 'TK_RESERVED',
  2101. SEMICOLON: 'TK_SEMICOLON',
  2102. STRING: 'TK_STRING',
  2103. EQUALS: 'TK_EQUALS',
  2104. OPERATOR: 'TK_OPERATOR',
  2105. COMMA: 'TK_COMMA',
  2106. BLOCK_COMMENT: 'TK_BLOCK_COMMENT',
  2107. COMMENT: 'TK_COMMENT',
  2108. DOT: 'TK_DOT',
  2109. UNKNOWN: 'TK_UNKNOWN',
  2110. START: BASETOKEN.START,
  2111. RAW: BASETOKEN.RAW,
  2112. EOF: BASETOKEN.EOF
  2113. };
  2114. var directives_core = new Directives(/\/\*/, /\*\//);
  2115. var number_pattern = /0[xX][0123456789abcdefABCDEF_]*n?|0[oO][01234567_]*n?|0[bB][01_]*n?|\d[\d_]*n|(?:\.\d[\d_]*|\d[\d_]*\.?[\d_]*)(?:[eE][+-]?[\d_]+)?/;
  2116. var digit = /[0-9]/;
  2117. // Dot "." must be distinguished from "..." and decimal
  2118. var dot_pattern = /[^\d\.]/;
  2119. var positionable_operators = (
  2120. ">>> === !== &&= ??= ||= " +
  2121. "<< && >= ** != == <= >> || ?? |> " +
  2122. "< / - + > : & % ? ^ | *").split(' ');
  2123. // IMPORTANT: this must be sorted longest to shortest or tokenizing many not work.
  2124. // Also, you must update possitionable operators separately from punct
  2125. var punct =
  2126. ">>>= " +
  2127. "... >>= <<= === >>> !== **= &&= ??= ||= " +
  2128. "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
  2129. "= ! ? > < : / ^ - + * & % ~ |";
  2130. punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
  2131. // ?. but not if followed by a number
  2132. punct = '\\?\\.(?!\\d) ' + punct;
  2133. punct = punct.replace(/ /g, '|');
  2134. var punct_pattern = new RegExp(punct);
  2135. // words which should always start on new line.
  2136. var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
  2137. var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as', 'class', 'extends']);
  2138. var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');
  2139. // var template_pattern = /(?:(?:<\?php|<\?=)[\s\S]*?\?>)|(?:<%[\s\S]*?%>)/g;
  2140. var in_html_comment;
  2141. var Tokenizer = function(input_string, options) {
  2142. BaseTokenizer.call(this, input_string, options);
  2143. this._patterns.whitespace = this._patterns.whitespace.matching(
  2144. /\u00A0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff/.source,
  2145. /\u2028\u2029/.source);
  2146. var pattern_reader = new Pattern(this._input);
  2147. var templatable = new TemplatablePattern(this._input)
  2148. .read_options(this._options);
  2149. this.__patterns = {
  2150. template: templatable,
  2151. identifier: templatable.starting_with(acorn.identifier).matching(acorn.identifierMatch),
  2152. number: pattern_reader.matching(number_pattern),
  2153. punct: pattern_reader.matching(punct_pattern),
  2154. // comment ends just before nearest linefeed or end of file
  2155. comment: pattern_reader.starting_with(/\/\//).until(/[\n\r\u2028\u2029]/),
  2156. // /* ... */ comment ends with nearest */ or end of file
  2157. block_comment: pattern_reader.starting_with(/\/\*/).until_after(/\*\//),
  2158. html_comment_start: pattern_reader.matching(/<!--/),
  2159. html_comment_end: pattern_reader.matching(/-->/),
  2160. include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
  2161. shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
  2162. xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[^}]+?}|!\[CDATA\[[^\]]*?\]\]|)(\s*{[^}]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{([^{}]|{[^}]+?})+?}))*\s*(\/?)\s*>/),
  2163. single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
  2164. double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
  2165. template_text: templatable.until(/[`\\$]/),
  2166. template_expression: templatable.until(/[`}\\]/)
  2167. };
  2168. };
  2169. Tokenizer.prototype = new BaseTokenizer();
  2170. Tokenizer.prototype._is_comment = function(current_token) {
  2171. return current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.BLOCK_COMMENT || current_token.type === TOKEN.UNKNOWN;
  2172. };
  2173. Tokenizer.prototype._is_opening = function(current_token) {
  2174. return current_token.type === TOKEN.START_BLOCK || current_token.type === TOKEN.START_EXPR;
  2175. };
  2176. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  2177. return (current_token.type === TOKEN.END_BLOCK || current_token.type === TOKEN.END_EXPR) &&
  2178. (open_token && (
  2179. (current_token.text === ']' && open_token.text === '[') ||
  2180. (current_token.text === ')' && open_token.text === '(') ||
  2181. (current_token.text === '}' && open_token.text === '{')));
  2182. };
  2183. Tokenizer.prototype._reset = function() {
  2184. in_html_comment = false;
  2185. };
  2186. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2187. var token = null;
  2188. this._readWhitespace();
  2189. var c = this._input.peek();
  2190. if (c === null) {
  2191. return this._create_token(TOKEN.EOF, '');
  2192. }
  2193. token = token || this._read_non_javascript(c);
  2194. token = token || this._read_string(c);
  2195. token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
  2196. token = token || this._read_word(previous_token);
  2197. token = token || this._read_singles(c);
  2198. token = token || this._read_comment(c);
  2199. token = token || this._read_regexp(c, previous_token);
  2200. token = token || this._read_xml(c, previous_token);
  2201. token = token || this._read_punctuation();
  2202. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  2203. return token;
  2204. };
  2205. Tokenizer.prototype._read_word = function(previous_token) {
  2206. var resulting_string;
  2207. resulting_string = this.__patterns.identifier.read();
  2208. if (resulting_string !== '') {
  2209. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  2210. if (!(previous_token.type === TOKEN.DOT ||
  2211. (previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
  2212. reserved_word_pattern.test(resulting_string)) {
  2213. if ((resulting_string === 'in' || resulting_string === 'of') &&
  2214. (previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) { // hack for 'in' and 'of' operators
  2215. return this._create_token(TOKEN.OPERATOR, resulting_string);
  2216. }
  2217. return this._create_token(TOKEN.RESERVED, resulting_string);
  2218. }
  2219. return this._create_token(TOKEN.WORD, resulting_string);
  2220. }
  2221. resulting_string = this.__patterns.number.read();
  2222. if (resulting_string !== '') {
  2223. return this._create_token(TOKEN.WORD, resulting_string);
  2224. }
  2225. };
  2226. Tokenizer.prototype._read_singles = function(c) {
  2227. var token = null;
  2228. if (c === '(' || c === '[') {
  2229. token = this._create_token(TOKEN.START_EXPR, c);
  2230. } else if (c === ')' || c === ']') {
  2231. token = this._create_token(TOKEN.END_EXPR, c);
  2232. } else if (c === '{') {
  2233. token = this._create_token(TOKEN.START_BLOCK, c);
  2234. } else if (c === '}') {
  2235. token = this._create_token(TOKEN.END_BLOCK, c);
  2236. } else if (c === ';') {
  2237. token = this._create_token(TOKEN.SEMICOLON, c);
  2238. } else if (c === '.' && dot_pattern.test(this._input.peek(1))) {
  2239. token = this._create_token(TOKEN.DOT, c);
  2240. } else if (c === ',') {
  2241. token = this._create_token(TOKEN.COMMA, c);
  2242. }
  2243. if (token) {
  2244. this._input.next();
  2245. }
  2246. return token;
  2247. };
  2248. Tokenizer.prototype._read_pair = function(c, d) {
  2249. var token = null;
  2250. if (c === '#' && d === '{') {
  2251. token = this._create_token(TOKEN.START_BLOCK, c + d);
  2252. }
  2253. if (token) {
  2254. this._input.next();
  2255. this._input.next();
  2256. }
  2257. return token;
  2258. };
  2259. Tokenizer.prototype._read_punctuation = function() {
  2260. var resulting_string = this.__patterns.punct.read();
  2261. if (resulting_string !== '') {
  2262. if (resulting_string === '=') {
  2263. return this._create_token(TOKEN.EQUALS, resulting_string);
  2264. } else if (resulting_string === '?.') {
  2265. return this._create_token(TOKEN.DOT, resulting_string);
  2266. } else {
  2267. return this._create_token(TOKEN.OPERATOR, resulting_string);
  2268. }
  2269. }
  2270. };
  2271. Tokenizer.prototype._read_non_javascript = function(c) {
  2272. var resulting_string = '';
  2273. if (c === '#') {
  2274. if (this._is_first_token()) {
  2275. resulting_string = this.__patterns.shebang.read();
  2276. if (resulting_string) {
  2277. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  2278. }
  2279. }
  2280. // handles extendscript #includes
  2281. resulting_string = this.__patterns.include.read();
  2282. if (resulting_string) {
  2283. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  2284. }
  2285. c = this._input.next();
  2286. // Spidermonkey-specific sharp variables for circular references. Considered obsolete.
  2287. var sharp = '#';
  2288. if (this._input.hasNext() && this._input.testChar(digit)) {
  2289. do {
  2290. c = this._input.next();
  2291. sharp += c;
  2292. } while (this._input.hasNext() && c !== '#' && c !== '=');
  2293. if (c === '#') {
  2294. //
  2295. } else if (this._input.peek() === '[' && this._input.peek(1) === ']') {
  2296. sharp += '[]';
  2297. this._input.next();
  2298. this._input.next();
  2299. } else if (this._input.peek() === '{' && this._input.peek(1) === '}') {
  2300. sharp += '{}';
  2301. this._input.next();
  2302. this._input.next();
  2303. }
  2304. return this._create_token(TOKEN.WORD, sharp);
  2305. }
  2306. this._input.back();
  2307. } else if (c === '<' && this._is_first_token()) {
  2308. resulting_string = this.__patterns.html_comment_start.read();
  2309. if (resulting_string) {
  2310. while (this._input.hasNext() && !this._input.testChar(acorn.newline)) {
  2311. resulting_string += this._input.next();
  2312. }
  2313. in_html_comment = true;
  2314. return this._create_token(TOKEN.COMMENT, resulting_string);
  2315. }
  2316. } else if (in_html_comment && c === '-') {
  2317. resulting_string = this.__patterns.html_comment_end.read();
  2318. if (resulting_string) {
  2319. in_html_comment = false;
  2320. return this._create_token(TOKEN.COMMENT, resulting_string);
  2321. }
  2322. }
  2323. return null;
  2324. };
  2325. Tokenizer.prototype._read_comment = function(c) {
  2326. var token = null;
  2327. if (c === '/') {
  2328. var comment = '';
  2329. if (this._input.peek(1) === '*') {
  2330. // peek for comment /* ... */
  2331. comment = this.__patterns.block_comment.read();
  2332. var directives = directives_core.get_directives(comment);
  2333. if (directives && directives.ignore === 'start') {
  2334. comment += directives_core.readIgnored(this._input);
  2335. }
  2336. comment = comment.replace(acorn.allLineBreaks, '\n');
  2337. token = this._create_token(TOKEN.BLOCK_COMMENT, comment);
  2338. token.directives = directives;
  2339. } else if (this._input.peek(1) === '/') {
  2340. // peek for comment // ...
  2341. comment = this.__patterns.comment.read();
  2342. token = this._create_token(TOKEN.COMMENT, comment);
  2343. }
  2344. }
  2345. return token;
  2346. };
  2347. Tokenizer.prototype._read_string = function(c) {
  2348. if (c === '`' || c === "'" || c === '"') {
  2349. var resulting_string = this._input.next();
  2350. this.has_char_escapes = false;
  2351. if (c === '`') {
  2352. resulting_string += this._read_string_recursive('`', true, '${');
  2353. } else {
  2354. resulting_string += this._read_string_recursive(c);
  2355. }
  2356. if (this.has_char_escapes && this._options.unescape_strings) {
  2357. resulting_string = unescape_string(resulting_string);
  2358. }
  2359. if (this._input.peek() === c) {
  2360. resulting_string += this._input.next();
  2361. }
  2362. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  2363. return this._create_token(TOKEN.STRING, resulting_string);
  2364. }
  2365. return null;
  2366. };
  2367. Tokenizer.prototype._allow_regexp_or_xml = function(previous_token) {
  2368. // regex and xml can only appear in specific locations during parsing
  2369. return (previous_token.type === TOKEN.RESERVED && in_array(previous_token.text, ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
  2370. (previous_token.type === TOKEN.END_EXPR && previous_token.text === ')' &&
  2371. previous_token.opened.previous.type === TOKEN.RESERVED && in_array(previous_token.opened.previous.text, ['if', 'while', 'for'])) ||
  2372. (in_array(previous_token.type, [TOKEN.COMMENT, TOKEN.START_EXPR, TOKEN.START_BLOCK, TOKEN.START,
  2373. TOKEN.END_BLOCK, TOKEN.OPERATOR, TOKEN.EQUALS, TOKEN.EOF, TOKEN.SEMICOLON, TOKEN.COMMA
  2374. ]));
  2375. };
  2376. Tokenizer.prototype._read_regexp = function(c, previous_token) {
  2377. if (c === '/' && this._allow_regexp_or_xml(previous_token)) {
  2378. // handle regexp
  2379. //
  2380. var resulting_string = this._input.next();
  2381. var esc = false;
  2382. var in_char_class = false;
  2383. while (this._input.hasNext() &&
  2384. ((esc || in_char_class || this._input.peek() !== c) &&
  2385. !this._input.testChar(acorn.newline))) {
  2386. resulting_string += this._input.peek();
  2387. if (!esc) {
  2388. esc = this._input.peek() === '\\';
  2389. if (this._input.peek() === '[') {
  2390. in_char_class = true;
  2391. } else if (this._input.peek() === ']') {
  2392. in_char_class = false;
  2393. }
  2394. } else {
  2395. esc = false;
  2396. }
  2397. this._input.next();
  2398. }
  2399. if (this._input.peek() === c) {
  2400. resulting_string += this._input.next();
  2401. // regexps may have modifiers /regexp/MOD , so fetch those, too
  2402. // Only [gim] are valid, but if the user puts in garbage, do what we can to take it.
  2403. resulting_string += this._input.read(acorn.identifier);
  2404. }
  2405. return this._create_token(TOKEN.STRING, resulting_string);
  2406. }
  2407. return null;
  2408. };
  2409. Tokenizer.prototype._read_xml = function(c, previous_token) {
  2410. if (this._options.e4x && c === "<" && this._allow_regexp_or_xml(previous_token)) {
  2411. var xmlStr = '';
  2412. var match = this.__patterns.xml.read_match();
  2413. // handle e4x xml literals
  2414. //
  2415. if (match) {
  2416. // Trim root tag to attempt to
  2417. var rootTag = match[2].replace(/^{\s+/, '{').replace(/\s+}$/, '}');
  2418. var isCurlyRoot = rootTag.indexOf('{') === 0;
  2419. var depth = 0;
  2420. while (match) {
  2421. var isEndTag = !!match[1];
  2422. var tagName = match[2];
  2423. var isSingletonTag = (!!match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
  2424. if (!isSingletonTag &&
  2425. (tagName === rootTag || (isCurlyRoot && tagName.replace(/^{\s+/, '{').replace(/\s+}$/, '}')))) {
  2426. if (isEndTag) {
  2427. --depth;
  2428. } else {
  2429. ++depth;
  2430. }
  2431. }
  2432. xmlStr += match[0];
  2433. if (depth <= 0) {
  2434. break;
  2435. }
  2436. match = this.__patterns.xml.read_match();
  2437. }
  2438. // if we didn't close correctly, keep unformatted.
  2439. if (!match) {
  2440. xmlStr += this._input.match(/[\s\S]*/g)[0];
  2441. }
  2442. xmlStr = xmlStr.replace(acorn.allLineBreaks, '\n');
  2443. return this._create_token(TOKEN.STRING, xmlStr);
  2444. }
  2445. }
  2446. return null;
  2447. };
  2448. function unescape_string(s) {
  2449. // You think that a regex would work for this
  2450. // return s.replace(/\\x([0-9a-f]{2})/gi, function(match, val) {
  2451. // return String.fromCharCode(parseInt(val, 16));
  2452. // })
  2453. // However, dealing with '\xff', '\\xff', '\\\xff' makes this more fun.
  2454. var out = '',
  2455. escaped = 0;
  2456. var input_scan = new InputScanner(s);
  2457. var matched = null;
  2458. while (input_scan.hasNext()) {
  2459. // Keep any whitespace, non-slash characters
  2460. // also keep slash pairs.
  2461. matched = input_scan.match(/([\s]|[^\\]|\\\\)+/g);
  2462. if (matched) {
  2463. out += matched[0];
  2464. }
  2465. if (input_scan.peek() === '\\') {
  2466. input_scan.next();
  2467. if (input_scan.peek() === 'x') {
  2468. matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
  2469. } else if (input_scan.peek() === 'u') {
  2470. matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
  2471. } else {
  2472. out += '\\';
  2473. if (input_scan.hasNext()) {
  2474. out += input_scan.next();
  2475. }
  2476. continue;
  2477. }
  2478. // If there's some error decoding, return the original string
  2479. if (!matched) {
  2480. return s;
  2481. }
  2482. escaped = parseInt(matched[1], 16);
  2483. if (escaped > 0x7e && escaped <= 0xff && matched[0].indexOf('x') === 0) {
  2484. // we bail out on \x7f..\xff,
  2485. // leaving whole string escaped,
  2486. // as it's probably completely binary
  2487. return s;
  2488. } else if (escaped >= 0x00 && escaped < 0x20) {
  2489. // leave 0x00...0x1f escaped
  2490. out += '\\' + matched[0];
  2491. continue;
  2492. } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
  2493. // single-quote, apostrophe, backslash - escape these
  2494. out += '\\' + String.fromCharCode(escaped);
  2495. } else {
  2496. out += String.fromCharCode(escaped);
  2497. }
  2498. }
  2499. }
  2500. return out;
  2501. }
  2502. // handle string
  2503. //
  2504. Tokenizer.prototype._read_string_recursive = function(delimiter, allow_unescaped_newlines, start_sub) {
  2505. var current_char;
  2506. var pattern;
  2507. if (delimiter === '\'') {
  2508. pattern = this.__patterns.single_quote;
  2509. } else if (delimiter === '"') {
  2510. pattern = this.__patterns.double_quote;
  2511. } else if (delimiter === '`') {
  2512. pattern = this.__patterns.template_text;
  2513. } else if (delimiter === '}') {
  2514. pattern = this.__patterns.template_expression;
  2515. }
  2516. var resulting_string = pattern.read();
  2517. var next = '';
  2518. while (this._input.hasNext()) {
  2519. next = this._input.next();
  2520. if (next === delimiter ||
  2521. (!allow_unescaped_newlines && acorn.newline.test(next))) {
  2522. this._input.back();
  2523. break;
  2524. } else if (next === '\\' && this._input.hasNext()) {
  2525. current_char = this._input.peek();
  2526. if (current_char === 'x' || current_char === 'u') {
  2527. this.has_char_escapes = true;
  2528. } else if (current_char === '\r' && this._input.peek(1) === '\n') {
  2529. this._input.next();
  2530. }
  2531. next += this._input.next();
  2532. } else if (start_sub) {
  2533. if (start_sub === '${' && next === '$' && this._input.peek() === '{') {
  2534. next += this._input.next();
  2535. }
  2536. if (start_sub === next) {
  2537. if (delimiter === '`') {
  2538. next += this._read_string_recursive('}', allow_unescaped_newlines, '`');
  2539. } else {
  2540. next += this._read_string_recursive('`', allow_unescaped_newlines, '${');
  2541. }
  2542. if (this._input.hasNext()) {
  2543. next += this._input.next();
  2544. }
  2545. }
  2546. }
  2547. next += pattern.read();
  2548. resulting_string += next;
  2549. }
  2550. return resulting_string;
  2551. };
  2552. module.exports.Tokenizer = Tokenizer;
  2553. module.exports.TOKEN = TOKEN;
  2554. module.exports.positionable_operators = positionable_operators.slice();
  2555. module.exports.line_starters = line_starters.slice();
  2556. /***/ }),
  2557. /* 9 */
  2558. /***/ (function(module) {
  2559. /*jshint node:true */
  2560. /*
  2561. The MIT License (MIT)
  2562. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2563. Permission is hereby granted, free of charge, to any person
  2564. obtaining a copy of this software and associated documentation files
  2565. (the "Software"), to deal in the Software without restriction,
  2566. including without limitation the rights to use, copy, modify, merge,
  2567. publish, distribute, sublicense, and/or sell copies of the Software,
  2568. and to permit persons to whom the Software is furnished to do so,
  2569. subject to the following conditions:
  2570. The above copyright notice and this permission notice shall be
  2571. included in all copies or substantial portions of the Software.
  2572. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2573. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2574. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2575. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2576. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2577. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2578. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2579. SOFTWARE.
  2580. */
  2581. var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
  2582. function InputScanner(input_string) {
  2583. this.__input = input_string || '';
  2584. this.__input_length = this.__input.length;
  2585. this.__position = 0;
  2586. }
  2587. InputScanner.prototype.restart = function() {
  2588. this.__position = 0;
  2589. };
  2590. InputScanner.prototype.back = function() {
  2591. if (this.__position > 0) {
  2592. this.__position -= 1;
  2593. }
  2594. };
  2595. InputScanner.prototype.hasNext = function() {
  2596. return this.__position < this.__input_length;
  2597. };
  2598. InputScanner.prototype.next = function() {
  2599. var val = null;
  2600. if (this.hasNext()) {
  2601. val = this.__input.charAt(this.__position);
  2602. this.__position += 1;
  2603. }
  2604. return val;
  2605. };
  2606. InputScanner.prototype.peek = function(index) {
  2607. var val = null;
  2608. index = index || 0;
  2609. index += this.__position;
  2610. if (index >= 0 && index < this.__input_length) {
  2611. val = this.__input.charAt(index);
  2612. }
  2613. return val;
  2614. };
  2615. // This is a JavaScript only helper function (not in python)
  2616. // Javascript doesn't have a match method
  2617. // and not all implementation support "sticky" flag.
  2618. // If they do not support sticky then both this.match() and this.test() method
  2619. // must get the match and check the index of the match.
  2620. // If sticky is supported and set, this method will use it.
  2621. // Otherwise it will check that global is set, and fall back to the slower method.
  2622. InputScanner.prototype.__match = function(pattern, index) {
  2623. pattern.lastIndex = index;
  2624. var pattern_match = pattern.exec(this.__input);
  2625. if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
  2626. if (pattern_match.index !== index) {
  2627. pattern_match = null;
  2628. }
  2629. }
  2630. return pattern_match;
  2631. };
  2632. InputScanner.prototype.test = function(pattern, index) {
  2633. index = index || 0;
  2634. index += this.__position;
  2635. if (index >= 0 && index < this.__input_length) {
  2636. return !!this.__match(pattern, index);
  2637. } else {
  2638. return false;
  2639. }
  2640. };
  2641. InputScanner.prototype.testChar = function(pattern, index) {
  2642. // test one character regex match
  2643. var val = this.peek(index);
  2644. pattern.lastIndex = 0;
  2645. return val !== null && pattern.test(val);
  2646. };
  2647. InputScanner.prototype.match = function(pattern) {
  2648. var pattern_match = this.__match(pattern, this.__position);
  2649. if (pattern_match) {
  2650. this.__position += pattern_match[0].length;
  2651. } else {
  2652. pattern_match = null;
  2653. }
  2654. return pattern_match;
  2655. };
  2656. InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
  2657. var val = '';
  2658. var match;
  2659. if (starting_pattern) {
  2660. match = this.match(starting_pattern);
  2661. if (match) {
  2662. val += match[0];
  2663. }
  2664. }
  2665. if (until_pattern && (match || !starting_pattern)) {
  2666. val += this.readUntil(until_pattern, until_after);
  2667. }
  2668. return val;
  2669. };
  2670. InputScanner.prototype.readUntil = function(pattern, until_after) {
  2671. var val = '';
  2672. var match_index = this.__position;
  2673. pattern.lastIndex = this.__position;
  2674. var pattern_match = pattern.exec(this.__input);
  2675. if (pattern_match) {
  2676. match_index = pattern_match.index;
  2677. if (until_after) {
  2678. match_index += pattern_match[0].length;
  2679. }
  2680. } else {
  2681. match_index = this.__input_length;
  2682. }
  2683. val = this.__input.substring(this.__position, match_index);
  2684. this.__position = match_index;
  2685. return val;
  2686. };
  2687. InputScanner.prototype.readUntilAfter = function(pattern) {
  2688. return this.readUntil(pattern, true);
  2689. };
  2690. InputScanner.prototype.get_regexp = function(pattern, match_from) {
  2691. var result = null;
  2692. var flags = 'g';
  2693. if (match_from && regexp_has_sticky) {
  2694. flags = 'y';
  2695. }
  2696. // strings are converted to regexp
  2697. if (typeof pattern === "string" && pattern !== '') {
  2698. // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
  2699. result = new RegExp(pattern, flags);
  2700. } else if (pattern) {
  2701. result = new RegExp(pattern.source, flags);
  2702. }
  2703. return result;
  2704. };
  2705. InputScanner.prototype.get_literal_regexp = function(literal_string) {
  2706. return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  2707. };
  2708. /* css beautifier legacy helpers */
  2709. InputScanner.prototype.peekUntilAfter = function(pattern) {
  2710. var start = this.__position;
  2711. var val = this.readUntilAfter(pattern);
  2712. this.__position = start;
  2713. return val;
  2714. };
  2715. InputScanner.prototype.lookBack = function(testVal) {
  2716. var start = this.__position - 1;
  2717. return start >= testVal.length && this.__input.substring(start - testVal.length, start)
  2718. .toLowerCase() === testVal;
  2719. };
  2720. module.exports.InputScanner = InputScanner;
  2721. /***/ }),
  2722. /* 10 */
  2723. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2724. /*jshint node:true */
  2725. /*
  2726. The MIT License (MIT)
  2727. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2728. Permission is hereby granted, free of charge, to any person
  2729. obtaining a copy of this software and associated documentation files
  2730. (the "Software"), to deal in the Software without restriction,
  2731. including without limitation the rights to use, copy, modify, merge,
  2732. publish, distribute, sublicense, and/or sell copies of the Software,
  2733. and to permit persons to whom the Software is furnished to do so,
  2734. subject to the following conditions:
  2735. The above copyright notice and this permission notice shall be
  2736. included in all copies or substantial portions of the Software.
  2737. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2738. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2739. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2740. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2741. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2742. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2743. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2744. SOFTWARE.
  2745. */
  2746. var InputScanner = (__webpack_require__(9).InputScanner);
  2747. var Token = (__webpack_require__(4).Token);
  2748. var TokenStream = (__webpack_require__(11).TokenStream);
  2749. var WhitespacePattern = (__webpack_require__(12).WhitespacePattern);
  2750. var TOKEN = {
  2751. START: 'TK_START',
  2752. RAW: 'TK_RAW',
  2753. EOF: 'TK_EOF'
  2754. };
  2755. var Tokenizer = function(input_string, options) {
  2756. this._input = new InputScanner(input_string);
  2757. this._options = options || {};
  2758. this.__tokens = null;
  2759. this._patterns = {};
  2760. this._patterns.whitespace = new WhitespacePattern(this._input);
  2761. };
  2762. Tokenizer.prototype.tokenize = function() {
  2763. this._input.restart();
  2764. this.__tokens = new TokenStream();
  2765. this._reset();
  2766. var current;
  2767. var previous = new Token(TOKEN.START, '');
  2768. var open_token = null;
  2769. var open_stack = [];
  2770. var comments = new TokenStream();
  2771. while (previous.type !== TOKEN.EOF) {
  2772. current = this._get_next_token(previous, open_token);
  2773. while (this._is_comment(current)) {
  2774. comments.add(current);
  2775. current = this._get_next_token(previous, open_token);
  2776. }
  2777. if (!comments.isEmpty()) {
  2778. current.comments_before = comments;
  2779. comments = new TokenStream();
  2780. }
  2781. current.parent = open_token;
  2782. if (this._is_opening(current)) {
  2783. open_stack.push(open_token);
  2784. open_token = current;
  2785. } else if (open_token && this._is_closing(current, open_token)) {
  2786. current.opened = open_token;
  2787. open_token.closed = current;
  2788. open_token = open_stack.pop();
  2789. current.parent = open_token;
  2790. }
  2791. current.previous = previous;
  2792. previous.next = current;
  2793. this.__tokens.add(current);
  2794. previous = current;
  2795. }
  2796. return this.__tokens;
  2797. };
  2798. Tokenizer.prototype._is_first_token = function() {
  2799. return this.__tokens.isEmpty();
  2800. };
  2801. Tokenizer.prototype._reset = function() {};
  2802. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2803. this._readWhitespace();
  2804. var resulting_string = this._input.read(/.+/g);
  2805. if (resulting_string) {
  2806. return this._create_token(TOKEN.RAW, resulting_string);
  2807. } else {
  2808. return this._create_token(TOKEN.EOF, '');
  2809. }
  2810. };
  2811. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  2812. return false;
  2813. };
  2814. Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
  2815. return false;
  2816. };
  2817. Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
  2818. return false;
  2819. };
  2820. Tokenizer.prototype._create_token = function(type, text) {
  2821. var token = new Token(type, text,
  2822. this._patterns.whitespace.newline_count,
  2823. this._patterns.whitespace.whitespace_before_token);
  2824. return token;
  2825. };
  2826. Tokenizer.prototype._readWhitespace = function() {
  2827. return this._patterns.whitespace.read();
  2828. };
  2829. module.exports.Tokenizer = Tokenizer;
  2830. module.exports.TOKEN = TOKEN;
  2831. /***/ }),
  2832. /* 11 */
  2833. /***/ (function(module) {
  2834. /*jshint node:true */
  2835. /*
  2836. The MIT License (MIT)
  2837. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2838. Permission is hereby granted, free of charge, to any person
  2839. obtaining a copy of this software and associated documentation files
  2840. (the "Software"), to deal in the Software without restriction,
  2841. including without limitation the rights to use, copy, modify, merge,
  2842. publish, distribute, sublicense, and/or sell copies of the Software,
  2843. and to permit persons to whom the Software is furnished to do so,
  2844. subject to the following conditions:
  2845. The above copyright notice and this permission notice shall be
  2846. included in all copies or substantial portions of the Software.
  2847. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2848. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2849. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2850. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2851. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2852. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2853. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2854. SOFTWARE.
  2855. */
  2856. function TokenStream(parent_token) {
  2857. // private
  2858. this.__tokens = [];
  2859. this.__tokens_length = this.__tokens.length;
  2860. this.__position = 0;
  2861. this.__parent_token = parent_token;
  2862. }
  2863. TokenStream.prototype.restart = function() {
  2864. this.__position = 0;
  2865. };
  2866. TokenStream.prototype.isEmpty = function() {
  2867. return this.__tokens_length === 0;
  2868. };
  2869. TokenStream.prototype.hasNext = function() {
  2870. return this.__position < this.__tokens_length;
  2871. };
  2872. TokenStream.prototype.next = function() {
  2873. var val = null;
  2874. if (this.hasNext()) {
  2875. val = this.__tokens[this.__position];
  2876. this.__position += 1;
  2877. }
  2878. return val;
  2879. };
  2880. TokenStream.prototype.peek = function(index) {
  2881. var val = null;
  2882. index = index || 0;
  2883. index += this.__position;
  2884. if (index >= 0 && index < this.__tokens_length) {
  2885. val = this.__tokens[index];
  2886. }
  2887. return val;
  2888. };
  2889. TokenStream.prototype.add = function(token) {
  2890. if (this.__parent_token) {
  2891. token.parent = this.__parent_token;
  2892. }
  2893. this.__tokens.push(token);
  2894. this.__tokens_length += 1;
  2895. };
  2896. module.exports.TokenStream = TokenStream;
  2897. /***/ }),
  2898. /* 12 */
  2899. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2900. /*jshint node:true */
  2901. /*
  2902. The MIT License (MIT)
  2903. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2904. Permission is hereby granted, free of charge, to any person
  2905. obtaining a copy of this software and associated documentation files
  2906. (the "Software"), to deal in the Software without restriction,
  2907. including without limitation the rights to use, copy, modify, merge,
  2908. publish, distribute, sublicense, and/or sell copies of the Software,
  2909. and to permit persons to whom the Software is furnished to do so,
  2910. subject to the following conditions:
  2911. The above copyright notice and this permission notice shall be
  2912. included in all copies or substantial portions of the Software.
  2913. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2914. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2915. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2916. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2917. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2918. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2919. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2920. SOFTWARE.
  2921. */
  2922. var Pattern = (__webpack_require__(13).Pattern);
  2923. function WhitespacePattern(input_scanner, parent) {
  2924. Pattern.call(this, input_scanner, parent);
  2925. if (parent) {
  2926. this._line_regexp = this._input.get_regexp(parent._line_regexp);
  2927. } else {
  2928. this.__set_whitespace_patterns('', '');
  2929. }
  2930. this.newline_count = 0;
  2931. this.whitespace_before_token = '';
  2932. }
  2933. WhitespacePattern.prototype = new Pattern();
  2934. WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
  2935. whitespace_chars += '\\t ';
  2936. newline_chars += '\\n\\r';
  2937. this._match_pattern = this._input.get_regexp(
  2938. '[' + whitespace_chars + newline_chars + ']+', true);
  2939. this._newline_regexp = this._input.get_regexp(
  2940. '\\r\\n|[' + newline_chars + ']');
  2941. };
  2942. WhitespacePattern.prototype.read = function() {
  2943. this.newline_count = 0;
  2944. this.whitespace_before_token = '';
  2945. var resulting_string = this._input.read(this._match_pattern);
  2946. if (resulting_string === ' ') {
  2947. this.whitespace_before_token = ' ';
  2948. } else if (resulting_string) {
  2949. var matches = this.__split(this._newline_regexp, resulting_string);
  2950. this.newline_count = matches.length - 1;
  2951. this.whitespace_before_token = matches[this.newline_count];
  2952. }
  2953. return resulting_string;
  2954. };
  2955. WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
  2956. var result = this._create();
  2957. result.__set_whitespace_patterns(whitespace_chars, newline_chars);
  2958. result._update();
  2959. return result;
  2960. };
  2961. WhitespacePattern.prototype._create = function() {
  2962. return new WhitespacePattern(this._input, this);
  2963. };
  2964. WhitespacePattern.prototype.__split = function(regexp, input_string) {
  2965. regexp.lastIndex = 0;
  2966. var start_index = 0;
  2967. var result = [];
  2968. var next_match = regexp.exec(input_string);
  2969. while (next_match) {
  2970. result.push(input_string.substring(start_index, next_match.index));
  2971. start_index = next_match.index + next_match[0].length;
  2972. next_match = regexp.exec(input_string);
  2973. }
  2974. if (start_index < input_string.length) {
  2975. result.push(input_string.substring(start_index, input_string.length));
  2976. } else {
  2977. result.push('');
  2978. }
  2979. return result;
  2980. };
  2981. module.exports.WhitespacePattern = WhitespacePattern;
  2982. /***/ }),
  2983. /* 13 */
  2984. /***/ (function(module) {
  2985. /*jshint node:true */
  2986. /*
  2987. The MIT License (MIT)
  2988. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2989. Permission is hereby granted, free of charge, to any person
  2990. obtaining a copy of this software and associated documentation files
  2991. (the "Software"), to deal in the Software without restriction,
  2992. including without limitation the rights to use, copy, modify, merge,
  2993. publish, distribute, sublicense, and/or sell copies of the Software,
  2994. and to permit persons to whom the Software is furnished to do so,
  2995. subject to the following conditions:
  2996. The above copyright notice and this permission notice shall be
  2997. included in all copies or substantial portions of the Software.
  2998. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2999. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3000. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3001. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3002. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3003. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3004. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3005. SOFTWARE.
  3006. */
  3007. function Pattern(input_scanner, parent) {
  3008. this._input = input_scanner;
  3009. this._starting_pattern = null;
  3010. this._match_pattern = null;
  3011. this._until_pattern = null;
  3012. this._until_after = false;
  3013. if (parent) {
  3014. this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
  3015. this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
  3016. this._until_pattern = this._input.get_regexp(parent._until_pattern);
  3017. this._until_after = parent._until_after;
  3018. }
  3019. }
  3020. Pattern.prototype.read = function() {
  3021. var result = this._input.read(this._starting_pattern);
  3022. if (!this._starting_pattern || result) {
  3023. result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
  3024. }
  3025. return result;
  3026. };
  3027. Pattern.prototype.read_match = function() {
  3028. return this._input.match(this._match_pattern);
  3029. };
  3030. Pattern.prototype.until_after = function(pattern) {
  3031. var result = this._create();
  3032. result._until_after = true;
  3033. result._until_pattern = this._input.get_regexp(pattern);
  3034. result._update();
  3035. return result;
  3036. };
  3037. Pattern.prototype.until = function(pattern) {
  3038. var result = this._create();
  3039. result._until_after = false;
  3040. result._until_pattern = this._input.get_regexp(pattern);
  3041. result._update();
  3042. return result;
  3043. };
  3044. Pattern.prototype.starting_with = function(pattern) {
  3045. var result = this._create();
  3046. result._starting_pattern = this._input.get_regexp(pattern, true);
  3047. result._update();
  3048. return result;
  3049. };
  3050. Pattern.prototype.matching = function(pattern) {
  3051. var result = this._create();
  3052. result._match_pattern = this._input.get_regexp(pattern, true);
  3053. result._update();
  3054. return result;
  3055. };
  3056. Pattern.prototype._create = function() {
  3057. return new Pattern(this._input, this);
  3058. };
  3059. Pattern.prototype._update = function() {};
  3060. module.exports.Pattern = Pattern;
  3061. /***/ }),
  3062. /* 14 */
  3063. /***/ (function(module) {
  3064. /*jshint node:true */
  3065. /*
  3066. The MIT License (MIT)
  3067. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3068. Permission is hereby granted, free of charge, to any person
  3069. obtaining a copy of this software and associated documentation files
  3070. (the "Software"), to deal in the Software without restriction,
  3071. including without limitation the rights to use, copy, modify, merge,
  3072. publish, distribute, sublicense, and/or sell copies of the Software,
  3073. and to permit persons to whom the Software is furnished to do so,
  3074. subject to the following conditions:
  3075. The above copyright notice and this permission notice shall be
  3076. included in all copies or substantial portions of the Software.
  3077. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3078. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3079. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3080. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3081. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3082. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3083. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3084. SOFTWARE.
  3085. */
  3086. function Directives(start_block_pattern, end_block_pattern) {
  3087. start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
  3088. end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
  3089. this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
  3090. this.__directive_pattern = / (\w+)[:](\w+)/g;
  3091. this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
  3092. }
  3093. Directives.prototype.get_directives = function(text) {
  3094. if (!text.match(this.__directives_block_pattern)) {
  3095. return null;
  3096. }
  3097. var directives = {};
  3098. this.__directive_pattern.lastIndex = 0;
  3099. var directive_match = this.__directive_pattern.exec(text);
  3100. while (directive_match) {
  3101. directives[directive_match[1]] = directive_match[2];
  3102. directive_match = this.__directive_pattern.exec(text);
  3103. }
  3104. return directives;
  3105. };
  3106. Directives.prototype.readIgnored = function(input) {
  3107. return input.readUntilAfter(this.__directives_end_ignore_pattern);
  3108. };
  3109. module.exports.Directives = Directives;
  3110. /***/ }),
  3111. /* 15 */
  3112. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  3113. /*jshint node:true */
  3114. /*
  3115. The MIT License (MIT)
  3116. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3117. Permission is hereby granted, free of charge, to any person
  3118. obtaining a copy of this software and associated documentation files
  3119. (the "Software"), to deal in the Software without restriction,
  3120. including without limitation the rights to use, copy, modify, merge,
  3121. publish, distribute, sublicense, and/or sell copies of the Software,
  3122. and to permit persons to whom the Software is furnished to do so,
  3123. subject to the following conditions:
  3124. The above copyright notice and this permission notice shall be
  3125. included in all copies or substantial portions of the Software.
  3126. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3127. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3128. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3129. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3130. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3131. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3132. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3133. SOFTWARE.
  3134. */
  3135. var Pattern = (__webpack_require__(13).Pattern);
  3136. var template_names = {
  3137. django: false,
  3138. erb: false,
  3139. handlebars: false,
  3140. php: false,
  3141. smarty: false
  3142. };
  3143. // This lets templates appear anywhere we would do a readUntil
  3144. // The cost is higher but it is pay to play.
  3145. function TemplatablePattern(input_scanner, parent) {
  3146. Pattern.call(this, input_scanner, parent);
  3147. this.__template_pattern = null;
  3148. this._disabled = Object.assign({}, template_names);
  3149. this._excluded = Object.assign({}, template_names);
  3150. if (parent) {
  3151. this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
  3152. this._excluded = Object.assign(this._excluded, parent._excluded);
  3153. this._disabled = Object.assign(this._disabled, parent._disabled);
  3154. }
  3155. var pattern = new Pattern(input_scanner);
  3156. this.__patterns = {
  3157. handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
  3158. handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
  3159. handlebars: pattern.starting_with(/{{/).until_after(/}}/),
  3160. php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
  3161. erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
  3162. // django coflicts with handlebars a bit.
  3163. django: pattern.starting_with(/{%/).until_after(/%}/),
  3164. django_value: pattern.starting_with(/{{/).until_after(/}}/),
  3165. django_comment: pattern.starting_with(/{#/).until_after(/#}/),
  3166. smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
  3167. smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
  3168. smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
  3169. };
  3170. }
  3171. TemplatablePattern.prototype = new Pattern();
  3172. TemplatablePattern.prototype._create = function() {
  3173. return new TemplatablePattern(this._input, this);
  3174. };
  3175. TemplatablePattern.prototype._update = function() {
  3176. this.__set_templated_pattern();
  3177. };
  3178. TemplatablePattern.prototype.disable = function(language) {
  3179. var result = this._create();
  3180. result._disabled[language] = true;
  3181. result._update();
  3182. return result;
  3183. };
  3184. TemplatablePattern.prototype.read_options = function(options) {
  3185. var result = this._create();
  3186. for (var language in template_names) {
  3187. result._disabled[language] = options.templating.indexOf(language) === -1;
  3188. }
  3189. result._update();
  3190. return result;
  3191. };
  3192. TemplatablePattern.prototype.exclude = function(language) {
  3193. var result = this._create();
  3194. result._excluded[language] = true;
  3195. result._update();
  3196. return result;
  3197. };
  3198. TemplatablePattern.prototype.read = function() {
  3199. var result = '';
  3200. if (this._match_pattern) {
  3201. result = this._input.read(this._starting_pattern);
  3202. } else {
  3203. result = this._input.read(this._starting_pattern, this.__template_pattern);
  3204. }
  3205. var next = this._read_template();
  3206. while (next) {
  3207. if (this._match_pattern) {
  3208. next += this._input.read(this._match_pattern);
  3209. } else {
  3210. next += this._input.readUntil(this.__template_pattern);
  3211. }
  3212. result += next;
  3213. next = this._read_template();
  3214. }
  3215. if (this._until_after) {
  3216. result += this._input.readUntilAfter(this._until_pattern);
  3217. }
  3218. return result;
  3219. };
  3220. TemplatablePattern.prototype.__set_templated_pattern = function() {
  3221. var items = [];
  3222. if (!this._disabled.php) {
  3223. items.push(this.__patterns.php._starting_pattern.source);
  3224. }
  3225. if (!this._disabled.handlebars) {
  3226. items.push(this.__patterns.handlebars._starting_pattern.source);
  3227. }
  3228. if (!this._disabled.erb) {
  3229. items.push(this.__patterns.erb._starting_pattern.source);
  3230. }
  3231. if (!this._disabled.django) {
  3232. items.push(this.__patterns.django._starting_pattern.source);
  3233. // The starting pattern for django is more complex because it has different
  3234. // patterns for value, comment, and other sections
  3235. items.push(this.__patterns.django_value._starting_pattern.source);
  3236. items.push(this.__patterns.django_comment._starting_pattern.source);
  3237. }
  3238. if (!this._disabled.smarty) {
  3239. items.push(this.__patterns.smarty._starting_pattern.source);
  3240. }
  3241. if (this._until_pattern) {
  3242. items.push(this._until_pattern.source);
  3243. }
  3244. this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
  3245. };
  3246. TemplatablePattern.prototype._read_template = function() {
  3247. var resulting_string = '';
  3248. var c = this._input.peek();
  3249. if (c === '<') {
  3250. var peek1 = this._input.peek(1);
  3251. //if we're in a comment, do something special
  3252. // We treat all comments as literals, even more than preformatted tags
  3253. // we just look for the appropriate close tag
  3254. if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
  3255. resulting_string = resulting_string ||
  3256. this.__patterns.php.read();
  3257. }
  3258. if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
  3259. resulting_string = resulting_string ||
  3260. this.__patterns.erb.read();
  3261. }
  3262. } else if (c === '{') {
  3263. if (!this._disabled.handlebars && !this._excluded.handlebars) {
  3264. resulting_string = resulting_string ||
  3265. this.__patterns.handlebars_comment.read();
  3266. resulting_string = resulting_string ||
  3267. this.__patterns.handlebars_unescaped.read();
  3268. resulting_string = resulting_string ||
  3269. this.__patterns.handlebars.read();
  3270. }
  3271. if (!this._disabled.django) {
  3272. // django coflicts with handlebars a bit.
  3273. if (!this._excluded.django && !this._excluded.handlebars) {
  3274. resulting_string = resulting_string ||
  3275. this.__patterns.django_value.read();
  3276. }
  3277. if (!this._excluded.django) {
  3278. resulting_string = resulting_string ||
  3279. this.__patterns.django_comment.read();
  3280. resulting_string = resulting_string ||
  3281. this.__patterns.django.read();
  3282. }
  3283. }
  3284. if (!this._disabled.smarty) {
  3285. // smarty cannot be enabled with django or handlebars enabled
  3286. if (this._disabled.django && this._disabled.handlebars) {
  3287. resulting_string = resulting_string ||
  3288. this.__patterns.smarty_comment.read();
  3289. resulting_string = resulting_string ||
  3290. this.__patterns.smarty_literal.read();
  3291. resulting_string = resulting_string ||
  3292. this.__patterns.smarty.read();
  3293. }
  3294. }
  3295. }
  3296. return resulting_string;
  3297. };
  3298. module.exports.TemplatablePattern = TemplatablePattern;
  3299. /***/ }),
  3300. /* 16 */
  3301. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  3302. /*jshint node:true */
  3303. /*
  3304. The MIT License (MIT)
  3305. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3306. Permission is hereby granted, free of charge, to any person
  3307. obtaining a copy of this software and associated documentation files
  3308. (the "Software"), to deal in the Software without restriction,
  3309. including without limitation the rights to use, copy, modify, merge,
  3310. publish, distribute, sublicense, and/or sell copies of the Software,
  3311. and to permit persons to whom the Software is furnished to do so,
  3312. subject to the following conditions:
  3313. The above copyright notice and this permission notice shall be
  3314. included in all copies or substantial portions of the Software.
  3315. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3316. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3317. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3318. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3319. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3320. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3321. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3322. SOFTWARE.
  3323. */
  3324. var Beautifier = (__webpack_require__(17).Beautifier),
  3325. Options = (__webpack_require__(18).Options);
  3326. function css_beautify(source_text, options) {
  3327. var beautifier = new Beautifier(source_text, options);
  3328. return beautifier.beautify();
  3329. }
  3330. module.exports = css_beautify;
  3331. module.exports.defaultOptions = function() {
  3332. return new Options();
  3333. };
  3334. /***/ }),
  3335. /* 17 */
  3336. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  3337. /*jshint node:true */
  3338. /*
  3339. The MIT License (MIT)
  3340. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3341. Permission is hereby granted, free of charge, to any person
  3342. obtaining a copy of this software and associated documentation files
  3343. (the "Software"), to deal in the Software without restriction,
  3344. including without limitation the rights to use, copy, modify, merge,
  3345. publish, distribute, sublicense, and/or sell copies of the Software,
  3346. and to permit persons to whom the Software is furnished to do so,
  3347. subject to the following conditions:
  3348. The above copyright notice and this permission notice shall be
  3349. included in all copies or substantial portions of the Software.
  3350. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3351. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3352. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3353. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3354. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3355. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3356. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3357. SOFTWARE.
  3358. */
  3359. var Options = (__webpack_require__(18).Options);
  3360. var Output = (__webpack_require__(3).Output);
  3361. var InputScanner = (__webpack_require__(9).InputScanner);
  3362. var Directives = (__webpack_require__(14).Directives);
  3363. var directives_core = new Directives(/\/\*/, /\*\//);
  3364. var lineBreak = /\r\n|[\r\n]/;
  3365. var allLineBreaks = /\r\n|[\r\n]/g;
  3366. // tokenizer
  3367. var whitespaceChar = /\s/;
  3368. var whitespacePattern = /(?:\s|\n)+/g;
  3369. var block_comment_pattern = /\/\*(?:[\s\S]*?)((?:\*\/)|$)/g;
  3370. var comment_pattern = /\/\/(?:[^\n\r\u2028\u2029]*)/g;
  3371. function Beautifier(source_text, options) {
  3372. this._source_text = source_text || '';
  3373. // Allow the setting of language/file-type specific options
  3374. // with inheritance of overall settings
  3375. this._options = new Options(options);
  3376. this._ch = null;
  3377. this._input = null;
  3378. // https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
  3379. this.NESTED_AT_RULE = {
  3380. "page": true,
  3381. "font-face": true,
  3382. "keyframes": true,
  3383. // also in CONDITIONAL_GROUP_RULE below
  3384. "media": true,
  3385. "supports": true,
  3386. "document": true
  3387. };
  3388. this.CONDITIONAL_GROUP_RULE = {
  3389. "media": true,
  3390. "supports": true,
  3391. "document": true
  3392. };
  3393. this.NON_SEMICOLON_NEWLINE_PROPERTY = [
  3394. "grid-template-areas",
  3395. "grid-template"
  3396. ];
  3397. }
  3398. Beautifier.prototype.eatString = function(endChars) {
  3399. var result = '';
  3400. this._ch = this._input.next();
  3401. while (this._ch) {
  3402. result += this._ch;
  3403. if (this._ch === "\\") {
  3404. result += this._input.next();
  3405. } else if (endChars.indexOf(this._ch) !== -1 || this._ch === "\n") {
  3406. break;
  3407. }
  3408. this._ch = this._input.next();
  3409. }
  3410. return result;
  3411. };
  3412. // Skips any white space in the source text from the current position.
  3413. // When allowAtLeastOneNewLine is true, will output new lines for each
  3414. // newline character found; if the user has preserve_newlines off, only
  3415. // the first newline will be output
  3416. Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) {
  3417. var result = whitespaceChar.test(this._input.peek());
  3418. var newline_count = 0;
  3419. while (whitespaceChar.test(this._input.peek())) {
  3420. this._ch = this._input.next();
  3421. if (allowAtLeastOneNewLine && this._ch === '\n') {
  3422. if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) {
  3423. newline_count++;
  3424. this._output.add_new_line(true);
  3425. }
  3426. }
  3427. }
  3428. return result;
  3429. };
  3430. // Nested pseudo-class if we are insideRule
  3431. // and the next special character found opens
  3432. // a new block
  3433. Beautifier.prototype.foundNestedPseudoClass = function() {
  3434. var openParen = 0;
  3435. var i = 1;
  3436. var ch = this._input.peek(i);
  3437. while (ch) {
  3438. if (ch === "{") {
  3439. return true;
  3440. } else if (ch === '(') {
  3441. // pseudoclasses can contain ()
  3442. openParen += 1;
  3443. } else if (ch === ')') {
  3444. if (openParen === 0) {
  3445. return false;
  3446. }
  3447. openParen -= 1;
  3448. } else if (ch === ";" || ch === "}") {
  3449. return false;
  3450. }
  3451. i++;
  3452. ch = this._input.peek(i);
  3453. }
  3454. return false;
  3455. };
  3456. Beautifier.prototype.print_string = function(output_string) {
  3457. this._output.set_indent(this._indentLevel);
  3458. this._output.non_breaking_space = true;
  3459. this._output.add_token(output_string);
  3460. };
  3461. Beautifier.prototype.preserveSingleSpace = function(isAfterSpace) {
  3462. if (isAfterSpace) {
  3463. this._output.space_before_token = true;
  3464. }
  3465. };
  3466. Beautifier.prototype.indent = function() {
  3467. this._indentLevel++;
  3468. };
  3469. Beautifier.prototype.outdent = function() {
  3470. if (this._indentLevel > 0) {
  3471. this._indentLevel--;
  3472. }
  3473. };
  3474. /*_____________________--------------------_____________________*/
  3475. Beautifier.prototype.beautify = function() {
  3476. if (this._options.disabled) {
  3477. return this._source_text;
  3478. }
  3479. var source_text = this._source_text;
  3480. var eol = this._options.eol;
  3481. if (eol === 'auto') {
  3482. eol = '\n';
  3483. if (source_text && lineBreak.test(source_text || '')) {
  3484. eol = source_text.match(lineBreak)[0];
  3485. }
  3486. }
  3487. // HACK: newline parsing inconsistent. This brute force normalizes the this._input.
  3488. source_text = source_text.replace(allLineBreaks, '\n');
  3489. // reset
  3490. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  3491. this._output = new Output(this._options, baseIndentString);
  3492. this._input = new InputScanner(source_text);
  3493. this._indentLevel = 0;
  3494. this._nestedLevel = 0;
  3495. this._ch = null;
  3496. var parenLevel = 0;
  3497. var insideRule = false;
  3498. // This is the value side of a property value pair (blue in the following ex)
  3499. // label { content: blue }
  3500. var insidePropertyValue = false;
  3501. var enteringConditionalGroup = false;
  3502. var insideNonNestedAtRule = false;
  3503. var insideScssMap = false;
  3504. var topCharacter = this._ch;
  3505. var insideNonSemiColonValues = false;
  3506. var whitespace;
  3507. var isAfterSpace;
  3508. var previous_ch;
  3509. while (true) {
  3510. whitespace = this._input.read(whitespacePattern);
  3511. isAfterSpace = whitespace !== '';
  3512. previous_ch = topCharacter;
  3513. this._ch = this._input.next();
  3514. if (this._ch === '\\' && this._input.hasNext()) {
  3515. this._ch += this._input.next();
  3516. }
  3517. topCharacter = this._ch;
  3518. if (!this._ch) {
  3519. break;
  3520. } else if (this._ch === '/' && this._input.peek() === '*') {
  3521. // /* css comment */
  3522. // Always start block comments on a new line.
  3523. // This handles scenarios where a block comment immediately
  3524. // follows a property definition on the same line or where
  3525. // minified code is being beautified.
  3526. this._output.add_new_line();
  3527. this._input.back();
  3528. var comment = this._input.read(block_comment_pattern);
  3529. // Handle ignore directive
  3530. var directives = directives_core.get_directives(comment);
  3531. if (directives && directives.ignore === 'start') {
  3532. comment += directives_core.readIgnored(this._input);
  3533. }
  3534. this.print_string(comment);
  3535. // Ensures any new lines following the comment are preserved
  3536. this.eatWhitespace(true);
  3537. // Block comments are followed by a new line so they don't
  3538. // share a line with other properties
  3539. this._output.add_new_line();
  3540. } else if (this._ch === '/' && this._input.peek() === '/') {
  3541. // // single line comment
  3542. // Preserves the space before a comment
  3543. // on the same line as a rule
  3544. this._output.space_before_token = true;
  3545. this._input.back();
  3546. this.print_string(this._input.read(comment_pattern));
  3547. // Ensures any new lines following the comment are preserved
  3548. this.eatWhitespace(true);
  3549. } else if (this._ch === '$') {
  3550. this.preserveSingleSpace(isAfterSpace);
  3551. this.print_string(this._ch);
  3552. // strip trailing space, if present, for hash property checks
  3553. var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
  3554. if (variable.match(/[ :]$/)) {
  3555. // we have a variable or pseudo-class, add it and insert one space before continuing
  3556. variable = this.eatString(": ").replace(/\s$/, '');
  3557. this.print_string(variable);
  3558. this._output.space_before_token = true;
  3559. }
  3560. variable = variable.replace(/\s$/, '');
  3561. // might be sass variable
  3562. if (parenLevel === 0 && variable.indexOf(':') !== -1) {
  3563. insidePropertyValue = true;
  3564. this.indent();
  3565. }
  3566. } else if (this._ch === '@') {
  3567. this.preserveSingleSpace(isAfterSpace);
  3568. // deal with less property mixins @{...}
  3569. if (this._input.peek() === '{') {
  3570. this.print_string(this._ch + this.eatString('}'));
  3571. } else {
  3572. this.print_string(this._ch);
  3573. // strip trailing space, if present, for hash property checks
  3574. var variableOrRule = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
  3575. if (variableOrRule.match(/[ :]$/)) {
  3576. // we have a variable or pseudo-class, add it and insert one space before continuing
  3577. variableOrRule = this.eatString(": ").replace(/\s$/, '');
  3578. this.print_string(variableOrRule);
  3579. this._output.space_before_token = true;
  3580. }
  3581. variableOrRule = variableOrRule.replace(/\s$/, '');
  3582. // might be less variable
  3583. if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
  3584. insidePropertyValue = true;
  3585. this.indent();
  3586. // might be a nesting at-rule
  3587. } else if (variableOrRule in this.NESTED_AT_RULE) {
  3588. this._nestedLevel += 1;
  3589. if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
  3590. enteringConditionalGroup = true;
  3591. }
  3592. // might be a non-nested at-rule
  3593. } else if (parenLevel === 0 && !insidePropertyValue) {
  3594. insideNonNestedAtRule = true;
  3595. }
  3596. }
  3597. } else if (this._ch === '#' && this._input.peek() === '{') {
  3598. this.preserveSingleSpace(isAfterSpace);
  3599. this.print_string(this._ch + this.eatString('}'));
  3600. } else if (this._ch === '{') {
  3601. if (insidePropertyValue) {
  3602. insidePropertyValue = false;
  3603. this.outdent();
  3604. }
  3605. // non nested at rule becomes nested
  3606. insideNonNestedAtRule = false;
  3607. // when entering conditional groups, only rulesets are allowed
  3608. if (enteringConditionalGroup) {
  3609. enteringConditionalGroup = false;
  3610. insideRule = (this._indentLevel >= this._nestedLevel);
  3611. } else {
  3612. // otherwise, declarations are also allowed
  3613. insideRule = (this._indentLevel >= this._nestedLevel - 1);
  3614. }
  3615. if (this._options.newline_between_rules && insideRule) {
  3616. if (this._output.previous_line && this._output.previous_line.item(-1) !== '{') {
  3617. this._output.ensure_empty_line_above('/', ',');
  3618. }
  3619. }
  3620. this._output.space_before_token = true;
  3621. // The difference in print_string and indent order is necessary to indent the '{' correctly
  3622. if (this._options.brace_style === 'expand') {
  3623. this._output.add_new_line();
  3624. this.print_string(this._ch);
  3625. this.indent();
  3626. this._output.set_indent(this._indentLevel);
  3627. } else {
  3628. // inside mixin and first param is object
  3629. if (previous_ch === '(') {
  3630. this._output.space_before_token = false;
  3631. } else if (previous_ch !== ',') {
  3632. this.indent();
  3633. }
  3634. this.print_string(this._ch);
  3635. }
  3636. this.eatWhitespace(true);
  3637. this._output.add_new_line();
  3638. } else if (this._ch === '}') {
  3639. this.outdent();
  3640. this._output.add_new_line();
  3641. if (previous_ch === '{') {
  3642. this._output.trim(true);
  3643. }
  3644. if (insidePropertyValue) {
  3645. this.outdent();
  3646. insidePropertyValue = false;
  3647. }
  3648. this.print_string(this._ch);
  3649. insideRule = false;
  3650. if (this._nestedLevel) {
  3651. this._nestedLevel--;
  3652. }
  3653. this.eatWhitespace(true);
  3654. this._output.add_new_line();
  3655. if (this._options.newline_between_rules && !this._output.just_added_blankline()) {
  3656. if (this._input.peek() !== '}') {
  3657. this._output.add_new_line(true);
  3658. }
  3659. }
  3660. if (this._input.peek() === ')') {
  3661. this._output.trim(true);
  3662. if (this._options.brace_style === "expand") {
  3663. this._output.add_new_line(true);
  3664. }
  3665. }
  3666. } else if (this._ch === ":") {
  3667. for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
  3668. if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
  3669. insideNonSemiColonValues = true;
  3670. break;
  3671. }
  3672. }
  3673. if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
  3674. // 'property: value' delimiter
  3675. // which could be in a conditional group query
  3676. this.print_string(':');
  3677. if (!insidePropertyValue) {
  3678. insidePropertyValue = true;
  3679. this._output.space_before_token = true;
  3680. this.eatWhitespace(true);
  3681. this.indent();
  3682. }
  3683. } else {
  3684. // sass/less parent reference don't use a space
  3685. // sass nested pseudo-class don't use a space
  3686. // preserve space before pseudoclasses/pseudoelements, as it means "in any child"
  3687. if (this._input.lookBack(" ")) {
  3688. this._output.space_before_token = true;
  3689. }
  3690. if (this._input.peek() === ":") {
  3691. // pseudo-element
  3692. this._ch = this._input.next();
  3693. this.print_string("::");
  3694. } else {
  3695. // pseudo-class
  3696. this.print_string(':');
  3697. }
  3698. }
  3699. } else if (this._ch === '"' || this._ch === '\'') {
  3700. var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
  3701. this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
  3702. this.print_string(this._ch + this.eatString(this._ch));
  3703. this.eatWhitespace(true);
  3704. } else if (this._ch === ';') {
  3705. insideNonSemiColonValues = false;
  3706. if (parenLevel === 0) {
  3707. if (insidePropertyValue) {
  3708. this.outdent();
  3709. insidePropertyValue = false;
  3710. }
  3711. insideNonNestedAtRule = false;
  3712. this.print_string(this._ch);
  3713. this.eatWhitespace(true);
  3714. // This maintains single line comments on the same
  3715. // line. Block comments are also affected, but
  3716. // a new line is always output before one inside
  3717. // that section
  3718. if (this._input.peek() !== '/') {
  3719. this._output.add_new_line();
  3720. }
  3721. } else {
  3722. this.print_string(this._ch);
  3723. this.eatWhitespace(true);
  3724. this._output.space_before_token = true;
  3725. }
  3726. } else if (this._ch === '(') { // may be a url
  3727. if (this._input.lookBack("url")) {
  3728. this.print_string(this._ch);
  3729. this.eatWhitespace();
  3730. parenLevel++;
  3731. this.indent();
  3732. this._ch = this._input.next();
  3733. if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
  3734. this._input.back();
  3735. } else if (this._ch) {
  3736. this.print_string(this._ch + this.eatString(')'));
  3737. if (parenLevel) {
  3738. parenLevel--;
  3739. this.outdent();
  3740. }
  3741. }
  3742. } else {
  3743. var space_needed = false;
  3744. if (this._input.lookBack("with")) {
  3745. // look back is not an accurate solution, we need tokens to confirm without whitespaces
  3746. space_needed = true;
  3747. }
  3748. this.preserveSingleSpace(isAfterSpace || space_needed);
  3749. this.print_string(this._ch);
  3750. // handle scss/sass map
  3751. if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
  3752. this._output.add_new_line();
  3753. insideScssMap = true;
  3754. } else {
  3755. this.eatWhitespace();
  3756. parenLevel++;
  3757. this.indent();
  3758. }
  3759. }
  3760. } else if (this._ch === ')') {
  3761. if (parenLevel) {
  3762. parenLevel--;
  3763. this.outdent();
  3764. }
  3765. if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
  3766. insideScssMap = false;
  3767. this.outdent();
  3768. this._output.add_new_line();
  3769. }
  3770. this.print_string(this._ch);
  3771. } else if (this._ch === ',') {
  3772. this.print_string(this._ch);
  3773. this.eatWhitespace(true);
  3774. if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
  3775. this._output.add_new_line();
  3776. } else {
  3777. this._output.space_before_token = true;
  3778. }
  3779. } else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) {
  3780. //handle combinator spacing
  3781. if (this._options.space_around_combinator) {
  3782. this._output.space_before_token = true;
  3783. this.print_string(this._ch);
  3784. this._output.space_before_token = true;
  3785. } else {
  3786. this.print_string(this._ch);
  3787. this.eatWhitespace();
  3788. // squash extra whitespace
  3789. if (this._ch && whitespaceChar.test(this._ch)) {
  3790. this._ch = '';
  3791. }
  3792. }
  3793. } else if (this._ch === ']') {
  3794. this.print_string(this._ch);
  3795. } else if (this._ch === '[') {
  3796. this.preserveSingleSpace(isAfterSpace);
  3797. this.print_string(this._ch);
  3798. } else if (this._ch === '=') { // no whitespace before or after
  3799. this.eatWhitespace();
  3800. this.print_string('=');
  3801. if (whitespaceChar.test(this._ch)) {
  3802. this._ch = '';
  3803. }
  3804. } else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
  3805. this._output.space_before_token = true;
  3806. this.print_string(this._ch);
  3807. } else {
  3808. var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
  3809. this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
  3810. this.print_string(this._ch);
  3811. if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
  3812. this._output.add_new_line();
  3813. }
  3814. }
  3815. }
  3816. var sweetCode = this._output.get_code(eol);
  3817. return sweetCode;
  3818. };
  3819. module.exports.Beautifier = Beautifier;
  3820. /***/ }),
  3821. /* 18 */
  3822. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  3823. /*jshint node:true */
  3824. /*
  3825. The MIT License (MIT)
  3826. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3827. Permission is hereby granted, free of charge, to any person
  3828. obtaining a copy of this software and associated documentation files
  3829. (the "Software"), to deal in the Software without restriction,
  3830. including without limitation the rights to use, copy, modify, merge,
  3831. publish, distribute, sublicense, and/or sell copies of the Software,
  3832. and to permit persons to whom the Software is furnished to do so,
  3833. subject to the following conditions:
  3834. The above copyright notice and this permission notice shall be
  3835. included in all copies or substantial portions of the Software.
  3836. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3837. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3838. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3839. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3840. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3841. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3842. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3843. SOFTWARE.
  3844. */
  3845. var BaseOptions = (__webpack_require__(7).Options);
  3846. function Options(options) {
  3847. BaseOptions.call(this, options, 'css');
  3848. this.selector_separator_newline = this._get_boolean('selector_separator_newline', true);
  3849. this.newline_between_rules = this._get_boolean('newline_between_rules', true);
  3850. var space_around_selector_separator = this._get_boolean('space_around_selector_separator');
  3851. this.space_around_combinator = this._get_boolean('space_around_combinator') || space_around_selector_separator;
  3852. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  3853. this.brace_style = 'collapse';
  3854. for (var bs = 0; bs < brace_style_split.length; bs++) {
  3855. if (brace_style_split[bs] !== 'expand') {
  3856. // default to collapse, as only collapse|expand is implemented for now
  3857. this.brace_style = 'collapse';
  3858. } else {
  3859. this.brace_style = brace_style_split[bs];
  3860. }
  3861. }
  3862. }
  3863. Options.prototype = new BaseOptions();
  3864. module.exports.Options = Options;
  3865. /***/ }),
  3866. /* 19 */
  3867. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  3868. /*jshint node:true */
  3869. /*
  3870. The MIT License (MIT)
  3871. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3872. Permission is hereby granted, free of charge, to any person
  3873. obtaining a copy of this software and associated documentation files
  3874. (the "Software"), to deal in the Software without restriction,
  3875. including without limitation the rights to use, copy, modify, merge,
  3876. publish, distribute, sublicense, and/or sell copies of the Software,
  3877. and to permit persons to whom the Software is furnished to do so,
  3878. subject to the following conditions:
  3879. The above copyright notice and this permission notice shall be
  3880. included in all copies or substantial portions of the Software.
  3881. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3882. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3883. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3884. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3885. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3886. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3887. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3888. SOFTWARE.
  3889. */
  3890. var Beautifier = (__webpack_require__(20).Beautifier),
  3891. Options = (__webpack_require__(21).Options);
  3892. function style_html(html_source, options, js_beautify, css_beautify) {
  3893. var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
  3894. return beautifier.beautify();
  3895. }
  3896. module.exports = style_html;
  3897. module.exports.defaultOptions = function() {
  3898. return new Options();
  3899. };
  3900. /***/ }),
  3901. /* 20 */
  3902. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  3903. /*jshint node:true */
  3904. /*
  3905. The MIT License (MIT)
  3906. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3907. Permission is hereby granted, free of charge, to any person
  3908. obtaining a copy of this software and associated documentation files
  3909. (the "Software"), to deal in the Software without restriction,
  3910. including without limitation the rights to use, copy, modify, merge,
  3911. publish, distribute, sublicense, and/or sell copies of the Software,
  3912. and to permit persons to whom the Software is furnished to do so,
  3913. subject to the following conditions:
  3914. The above copyright notice and this permission notice shall be
  3915. included in all copies or substantial portions of the Software.
  3916. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3917. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3918. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3919. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3920. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3921. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3922. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3923. SOFTWARE.
  3924. */
  3925. var Options = (__webpack_require__(21).Options);
  3926. var Output = (__webpack_require__(3).Output);
  3927. var Tokenizer = (__webpack_require__(22).Tokenizer);
  3928. var TOKEN = (__webpack_require__(22).TOKEN);
  3929. var lineBreak = /\r\n|[\r\n]/;
  3930. var allLineBreaks = /\r\n|[\r\n]/g;
  3931. var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions
  3932. this.indent_level = 0;
  3933. this.alignment_size = 0;
  3934. this.max_preserve_newlines = options.max_preserve_newlines;
  3935. this.preserve_newlines = options.preserve_newlines;
  3936. this._output = new Output(options, base_indent_string);
  3937. };
  3938. Printer.prototype.current_line_has_match = function(pattern) {
  3939. return this._output.current_line.has_match(pattern);
  3940. };
  3941. Printer.prototype.set_space_before_token = function(value, non_breaking) {
  3942. this._output.space_before_token = value;
  3943. this._output.non_breaking_space = non_breaking;
  3944. };
  3945. Printer.prototype.set_wrap_point = function() {
  3946. this._output.set_indent(this.indent_level, this.alignment_size);
  3947. this._output.set_wrap_point();
  3948. };
  3949. Printer.prototype.add_raw_token = function(token) {
  3950. this._output.add_raw_token(token);
  3951. };
  3952. Printer.prototype.print_preserved_newlines = function(raw_token) {
  3953. var newlines = 0;
  3954. if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
  3955. newlines = raw_token.newlines ? 1 : 0;
  3956. }
  3957. if (this.preserve_newlines) {
  3958. newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
  3959. }
  3960. for (var n = 0; n < newlines; n++) {
  3961. this.print_newline(n > 0);
  3962. }
  3963. return newlines !== 0;
  3964. };
  3965. Printer.prototype.traverse_whitespace = function(raw_token) {
  3966. if (raw_token.whitespace_before || raw_token.newlines) {
  3967. if (!this.print_preserved_newlines(raw_token)) {
  3968. this._output.space_before_token = true;
  3969. }
  3970. return true;
  3971. }
  3972. return false;
  3973. };
  3974. Printer.prototype.previous_token_wrapped = function() {
  3975. return this._output.previous_token_wrapped;
  3976. };
  3977. Printer.prototype.print_newline = function(force) {
  3978. this._output.add_new_line(force);
  3979. };
  3980. Printer.prototype.print_token = function(token) {
  3981. if (token.text) {
  3982. this._output.set_indent(this.indent_level, this.alignment_size);
  3983. this._output.add_token(token.text);
  3984. }
  3985. };
  3986. Printer.prototype.indent = function() {
  3987. this.indent_level++;
  3988. };
  3989. Printer.prototype.get_full_indent = function(level) {
  3990. level = this.indent_level + (level || 0);
  3991. if (level < 1) {
  3992. return '';
  3993. }
  3994. return this._output.get_indent_string(level);
  3995. };
  3996. var get_type_attribute = function(start_token) {
  3997. var result = null;
  3998. var raw_token = start_token.next;
  3999. // Search attributes for a type attribute
  4000. while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
  4001. if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
  4002. if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
  4003. raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
  4004. result = raw_token.next.next.text;
  4005. }
  4006. break;
  4007. }
  4008. raw_token = raw_token.next;
  4009. }
  4010. return result;
  4011. };
  4012. var get_custom_beautifier_name = function(tag_check, raw_token) {
  4013. var typeAttribute = null;
  4014. var result = null;
  4015. if (!raw_token.closed) {
  4016. return null;
  4017. }
  4018. if (tag_check === 'script') {
  4019. typeAttribute = 'text/javascript';
  4020. } else if (tag_check === 'style') {
  4021. typeAttribute = 'text/css';
  4022. }
  4023. typeAttribute = get_type_attribute(raw_token) || typeAttribute;
  4024. // For script and style tags that have a type attribute, only enable custom beautifiers for matching values
  4025. // For those without a type attribute use default;
  4026. if (typeAttribute.search('text/css') > -1) {
  4027. result = 'css';
  4028. } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
  4029. result = 'javascript';
  4030. } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
  4031. result = 'html';
  4032. } else if (typeAttribute.search(/test\/null/) > -1) {
  4033. // Test only mime-type for testing the beautifier when null is passed as beautifing function
  4034. result = 'null';
  4035. }
  4036. return result;
  4037. };
  4038. function in_array(what, arr) {
  4039. return arr.indexOf(what) !== -1;
  4040. }
  4041. function TagFrame(parent, parser_token, indent_level) {
  4042. this.parent = parent || null;
  4043. this.tag = parser_token ? parser_token.tag_name : '';
  4044. this.indent_level = indent_level || 0;
  4045. this.parser_token = parser_token || null;
  4046. }
  4047. function TagStack(printer) {
  4048. this._printer = printer;
  4049. this._current_frame = null;
  4050. }
  4051. TagStack.prototype.get_parser_token = function() {
  4052. return this._current_frame ? this._current_frame.parser_token : null;
  4053. };
  4054. TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object
  4055. var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
  4056. this._current_frame = new_frame;
  4057. };
  4058. TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer
  4059. var parser_token = null;
  4060. if (frame) {
  4061. parser_token = frame.parser_token;
  4062. this._printer.indent_level = frame.indent_level;
  4063. this._current_frame = frame.parent;
  4064. }
  4065. return parser_token;
  4066. };
  4067. TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer
  4068. var frame = this._current_frame;
  4069. while (frame) { //till we reach '' (the initial value);
  4070. if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it
  4071. break;
  4072. } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
  4073. frame = null;
  4074. break;
  4075. }
  4076. frame = frame.parent;
  4077. }
  4078. return frame;
  4079. };
  4080. TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer
  4081. var frame = this._get_frame([tag], stop_list);
  4082. return this._try_pop_frame(frame);
  4083. };
  4084. TagStack.prototype.indent_to_tag = function(tag_list) {
  4085. var frame = this._get_frame(tag_list);
  4086. if (frame) {
  4087. this._printer.indent_level = frame.indent_level;
  4088. }
  4089. };
  4090. function Beautifier(source_text, options, js_beautify, css_beautify) {
  4091. //Wrapper function to invoke all the necessary constructors and deal with the output.
  4092. this._source_text = source_text || '';
  4093. options = options || {};
  4094. this._js_beautify = js_beautify;
  4095. this._css_beautify = css_beautify;
  4096. this._tag_stack = null;
  4097. // Allow the setting of language/file-type specific options
  4098. // with inheritance of overall settings
  4099. var optionHtml = new Options(options, 'html');
  4100. this._options = optionHtml;
  4101. this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
  4102. this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
  4103. this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
  4104. this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
  4105. this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
  4106. this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
  4107. }
  4108. Beautifier.prototype.beautify = function() {
  4109. // if disabled, return the input unchanged.
  4110. if (this._options.disabled) {
  4111. return this._source_text;
  4112. }
  4113. var source_text = this._source_text;
  4114. var eol = this._options.eol;
  4115. if (this._options.eol === 'auto') {
  4116. eol = '\n';
  4117. if (source_text && lineBreak.test(source_text)) {
  4118. eol = source_text.match(lineBreak)[0];
  4119. }
  4120. }
  4121. // HACK: newline parsing inconsistent. This brute force normalizes the input.
  4122. source_text = source_text.replace(allLineBreaks, '\n');
  4123. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  4124. var last_token = {
  4125. text: '',
  4126. type: ''
  4127. };
  4128. var last_tag_token = new TagOpenParserToken();
  4129. var printer = new Printer(this._options, baseIndentString);
  4130. var tokens = new Tokenizer(source_text, this._options).tokenize();
  4131. this._tag_stack = new TagStack(printer);
  4132. var parser_token = null;
  4133. var raw_token = tokens.next();
  4134. while (raw_token.type !== TOKEN.EOF) {
  4135. if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
  4136. parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
  4137. last_tag_token = parser_token;
  4138. } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
  4139. (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
  4140. parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
  4141. } else if (raw_token.type === TOKEN.TAG_CLOSE) {
  4142. parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
  4143. } else if (raw_token.type === TOKEN.TEXT) {
  4144. parser_token = this._handle_text(printer, raw_token, last_tag_token);
  4145. } else {
  4146. // This should never happen, but if it does. Print the raw token
  4147. printer.add_raw_token(raw_token);
  4148. }
  4149. last_token = parser_token;
  4150. raw_token = tokens.next();
  4151. }
  4152. var sweet_code = printer._output.get_code(eol);
  4153. return sweet_code;
  4154. };
  4155. Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
  4156. var parser_token = {
  4157. text: raw_token.text,
  4158. type: raw_token.type
  4159. };
  4160. printer.alignment_size = 0;
  4161. last_tag_token.tag_complete = true;
  4162. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  4163. if (last_tag_token.is_unformatted) {
  4164. printer.add_raw_token(raw_token);
  4165. } else {
  4166. if (last_tag_token.tag_start_char === '<') {
  4167. printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
  4168. if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
  4169. printer.print_newline(false);
  4170. }
  4171. }
  4172. printer.print_token(raw_token);
  4173. }
  4174. if (last_tag_token.indent_content &&
  4175. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  4176. printer.indent();
  4177. // only indent once per opened tag
  4178. last_tag_token.indent_content = false;
  4179. }
  4180. if (!last_tag_token.is_inline_element &&
  4181. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  4182. printer.set_wrap_point();
  4183. }
  4184. return parser_token;
  4185. };
  4186. Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
  4187. var wrapped = last_tag_token.has_wrapped_attrs;
  4188. var parser_token = {
  4189. text: raw_token.text,
  4190. type: raw_token.type
  4191. };
  4192. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  4193. if (last_tag_token.is_unformatted) {
  4194. printer.add_raw_token(raw_token);
  4195. } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
  4196. // For the insides of handlebars allow newlines or a single space between open and contents
  4197. if (printer.print_preserved_newlines(raw_token)) {
  4198. raw_token.newlines = 0;
  4199. printer.add_raw_token(raw_token);
  4200. } else {
  4201. printer.print_token(raw_token);
  4202. }
  4203. } else {
  4204. if (raw_token.type === TOKEN.ATTRIBUTE) {
  4205. printer.set_space_before_token(true);
  4206. } else if (raw_token.type === TOKEN.EQUALS) { //no space before =
  4207. printer.set_space_before_token(false);
  4208. } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
  4209. printer.set_space_before_token(false);
  4210. }
  4211. if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
  4212. if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
  4213. printer.traverse_whitespace(raw_token);
  4214. wrapped = wrapped || raw_token.newlines !== 0;
  4215. }
  4216. // Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
  4217. // 1. always wrap the second and beyond attributes
  4218. // 2. wrap the first attribute only if 'force-expand-multiline' is specified
  4219. if (this._is_wrap_attributes_force &&
  4220. last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
  4221. (last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
  4222. this._is_wrap_attributes_force_expand_multiline)) {
  4223. printer.print_newline(false);
  4224. wrapped = true;
  4225. }
  4226. }
  4227. printer.print_token(raw_token);
  4228. wrapped = wrapped || printer.previous_token_wrapped();
  4229. last_tag_token.has_wrapped_attrs = wrapped;
  4230. }
  4231. return parser_token;
  4232. };
  4233. Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
  4234. var parser_token = {
  4235. text: raw_token.text,
  4236. type: 'TK_CONTENT'
  4237. };
  4238. if (last_tag_token.custom_beautifier_name) { //check if we need to format javascript
  4239. this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
  4240. } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
  4241. printer.add_raw_token(raw_token);
  4242. } else {
  4243. printer.traverse_whitespace(raw_token);
  4244. printer.print_token(raw_token);
  4245. }
  4246. return parser_token;
  4247. };
  4248. Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
  4249. var local = this;
  4250. if (raw_token.text !== '') {
  4251. var text = raw_token.text,
  4252. _beautifier,
  4253. script_indent_level = 1,
  4254. pre = '',
  4255. post = '';
  4256. if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
  4257. _beautifier = this._js_beautify;
  4258. } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
  4259. _beautifier = this._css_beautify;
  4260. } else if (last_tag_token.custom_beautifier_name === 'html') {
  4261. _beautifier = function(html_source, options) {
  4262. var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
  4263. return beautifier.beautify();
  4264. };
  4265. }
  4266. if (this._options.indent_scripts === "keep") {
  4267. script_indent_level = 0;
  4268. } else if (this._options.indent_scripts === "separate") {
  4269. script_indent_level = -printer.indent_level;
  4270. }
  4271. var indentation = printer.get_full_indent(script_indent_level);
  4272. // if there is at least one empty line at the end of this text, strip it
  4273. // we'll be adding one back after the text but before the containing tag.
  4274. text = text.replace(/\n[ \t]*$/, '');
  4275. // Handle the case where content is wrapped in a comment or cdata.
  4276. if (last_tag_token.custom_beautifier_name !== 'html' &&
  4277. text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
  4278. var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
  4279. // if we start to wrap but don't finish, print raw
  4280. if (!matched) {
  4281. printer.add_raw_token(raw_token);
  4282. return;
  4283. }
  4284. pre = indentation + matched[1] + '\n';
  4285. text = matched[4];
  4286. if (matched[5]) {
  4287. post = indentation + matched[5];
  4288. }
  4289. // if there is at least one empty line at the end of this text, strip it
  4290. // we'll be adding one back after the text but before the containing tag.
  4291. text = text.replace(/\n[ \t]*$/, '');
  4292. if (matched[2] || matched[3].indexOf('\n') !== -1) {
  4293. // if the first line of the non-comment text has spaces
  4294. // use that as the basis for indenting in null case.
  4295. matched = matched[3].match(/[ \t]+$/);
  4296. if (matched) {
  4297. raw_token.whitespace_before = matched[0];
  4298. }
  4299. }
  4300. }
  4301. if (text) {
  4302. if (_beautifier) {
  4303. // call the Beautifier if avaliable
  4304. var Child_options = function() {
  4305. this.eol = '\n';
  4306. };
  4307. Child_options.prototype = this._options.raw_options;
  4308. var child_options = new Child_options();
  4309. text = _beautifier(indentation + text, child_options);
  4310. } else {
  4311. // simply indent the string otherwise
  4312. var white = raw_token.whitespace_before;
  4313. if (white) {
  4314. text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
  4315. }
  4316. text = indentation + text.replace(/\n/g, '\n' + indentation);
  4317. }
  4318. }
  4319. if (pre) {
  4320. if (!text) {
  4321. text = pre + post;
  4322. } else {
  4323. text = pre + text + '\n' + post;
  4324. }
  4325. }
  4326. printer.print_newline(false);
  4327. if (text) {
  4328. raw_token.text = text;
  4329. raw_token.whitespace_before = '';
  4330. raw_token.newlines = 0;
  4331. printer.add_raw_token(raw_token);
  4332. printer.print_newline(true);
  4333. }
  4334. }
  4335. };
  4336. Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
  4337. var parser_token = this._get_tag_open_token(raw_token);
  4338. if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
  4339. !last_tag_token.is_empty_element &&
  4340. raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
  4341. // End element tags for unformatted or content_unformatted elements
  4342. // are printed raw to keep any newlines inside them exactly the same.
  4343. printer.add_raw_token(raw_token);
  4344. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
  4345. } else {
  4346. printer.traverse_whitespace(raw_token);
  4347. this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
  4348. if (!parser_token.is_inline_element) {
  4349. printer.set_wrap_point();
  4350. }
  4351. printer.print_token(raw_token);
  4352. }
  4353. // count the number of attributes
  4354. if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
  4355. var peek_index = 0;
  4356. var peek_token;
  4357. do {
  4358. peek_token = tokens.peek(peek_index);
  4359. if (peek_token.type === TOKEN.ATTRIBUTE) {
  4360. parser_token.attr_count += 1;
  4361. }
  4362. peek_index += 1;
  4363. } while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
  4364. }
  4365. //indent attributes an auto, forced, aligned or forced-align line-wrap
  4366. if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
  4367. parser_token.alignment_size = raw_token.text.length + 1;
  4368. }
  4369. if (!parser_token.tag_complete && !parser_token.is_unformatted) {
  4370. printer.alignment_size = parser_token.alignment_size;
  4371. }
  4372. return parser_token;
  4373. };
  4374. var TagOpenParserToken = function(parent, raw_token) {
  4375. this.parent = parent || null;
  4376. this.text = '';
  4377. this.type = 'TK_TAG_OPEN';
  4378. this.tag_name = '';
  4379. this.is_inline_element = false;
  4380. this.is_unformatted = false;
  4381. this.is_content_unformatted = false;
  4382. this.is_empty_element = false;
  4383. this.is_start_tag = false;
  4384. this.is_end_tag = false;
  4385. this.indent_content = false;
  4386. this.multiline_content = false;
  4387. this.custom_beautifier_name = null;
  4388. this.start_tag_token = null;
  4389. this.attr_count = 0;
  4390. this.has_wrapped_attrs = false;
  4391. this.alignment_size = 0;
  4392. this.tag_complete = false;
  4393. this.tag_start_char = '';
  4394. this.tag_check = '';
  4395. if (!raw_token) {
  4396. this.tag_complete = true;
  4397. } else {
  4398. var tag_check_match;
  4399. this.tag_start_char = raw_token.text[0];
  4400. this.text = raw_token.text;
  4401. if (this.tag_start_char === '<') {
  4402. tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
  4403. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  4404. } else {
  4405. tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/);
  4406. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  4407. // handle "{{#> myPartial}}" or "{{~#> myPartial}}"
  4408. if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
  4409. if (this.tag_check === '>' && raw_token.next !== null) {
  4410. this.tag_check = raw_token.next.text.split(' ')[0];
  4411. } else {
  4412. this.tag_check = raw_token.text.split('>')[1];
  4413. }
  4414. }
  4415. }
  4416. this.tag_check = this.tag_check.toLowerCase();
  4417. if (raw_token.type === TOKEN.COMMENT) {
  4418. this.tag_complete = true;
  4419. }
  4420. this.is_start_tag = this.tag_check.charAt(0) !== '/';
  4421. this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
  4422. this.is_end_tag = !this.is_start_tag ||
  4423. (raw_token.closed && raw_token.closed.text === '/>');
  4424. // if whitespace handler ~ included (i.e. {{~#if true}}), handlebars tags start at pos 3 not pos 2
  4425. var handlebar_starts = 2;
  4426. if (this.tag_start_char === '{' && this.text.length >= 3) {
  4427. if (this.text.charAt(2) === '~') {
  4428. handlebar_starts = 3;
  4429. }
  4430. }
  4431. // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
  4432. this.is_end_tag = this.is_end_tag ||
  4433. (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
  4434. }
  4435. };
  4436. Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
  4437. var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
  4438. parser_token.alignment_size = this._options.wrap_attributes_indent_size;
  4439. parser_token.is_end_tag = parser_token.is_end_tag ||
  4440. in_array(parser_token.tag_check, this._options.void_elements);
  4441. parser_token.is_empty_element = parser_token.tag_complete ||
  4442. (parser_token.is_start_tag && parser_token.is_end_tag);
  4443. parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
  4444. parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
  4445. parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
  4446. return parser_token;
  4447. };
  4448. Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
  4449. if (!parser_token.is_empty_element) {
  4450. if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  4451. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors
  4452. } else { // it's a start-tag
  4453. // check if this tag is starting an element that has optional end element
  4454. // and do an ending needed
  4455. if (this._do_optional_end_element(parser_token)) {
  4456. if (!parser_token.is_inline_element) {
  4457. printer.print_newline(false);
  4458. }
  4459. }
  4460. this._tag_stack.record_tag(parser_token); //push it on the tag stack
  4461. if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
  4462. !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
  4463. parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
  4464. }
  4465. }
  4466. }
  4467. if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line
  4468. printer.print_newline(false);
  4469. if (!printer._output.just_added_blankline()) {
  4470. printer.print_newline(true);
  4471. }
  4472. }
  4473. if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /)
  4474. // if you hit an else case, reset the indent level if you are inside an:
  4475. // 'if', 'unless', or 'each' block.
  4476. if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
  4477. this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
  4478. parser_token.indent_content = true;
  4479. // Don't add a newline if opening {{#if}} tag is on the current line
  4480. var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
  4481. if (!foundIfOnCurrentLine) {
  4482. printer.print_newline(false);
  4483. }
  4484. }
  4485. // Don't add a newline before elements that should remain where they are.
  4486. if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
  4487. last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) {
  4488. //Do nothing. Leave comments on same line.
  4489. } else {
  4490. if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
  4491. printer.print_newline(false);
  4492. }
  4493. this._calcluate_parent_multiline(printer, parser_token);
  4494. }
  4495. } else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  4496. var do_end_expand = false;
  4497. // deciding whether a block is multiline should not be this hard
  4498. do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
  4499. do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
  4500. !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
  4501. !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
  4502. last_token.type !== 'TK_CONTENT'
  4503. );
  4504. if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
  4505. do_end_expand = false;
  4506. }
  4507. if (do_end_expand) {
  4508. printer.print_newline(false);
  4509. }
  4510. } else { // it's a start-tag
  4511. parser_token.indent_content = !parser_token.custom_beautifier_name;
  4512. if (parser_token.tag_start_char === '<') {
  4513. if (parser_token.tag_name === 'html') {
  4514. parser_token.indent_content = this._options.indent_inner_html;
  4515. } else if (parser_token.tag_name === 'head') {
  4516. parser_token.indent_content = this._options.indent_head_inner_html;
  4517. } else if (parser_token.tag_name === 'body') {
  4518. parser_token.indent_content = this._options.indent_body_inner_html;
  4519. }
  4520. }
  4521. if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
  4522. (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
  4523. printer.print_newline(false);
  4524. }
  4525. this._calcluate_parent_multiline(printer, parser_token);
  4526. }
  4527. };
  4528. Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
  4529. if (parser_token.parent && printer._output.just_added_newline() &&
  4530. !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
  4531. parser_token.parent.multiline_content = true;
  4532. }
  4533. };
  4534. //To be used for <p> tag special case:
  4535. var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
  4536. var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
  4537. Beautifier.prototype._do_optional_end_element = function(parser_token) {
  4538. var result = null;
  4539. // NOTE: cases of "if there is no more content in the parent element"
  4540. // are handled automatically by the beautifier.
  4541. // It assumes parent or ancestor close tag closes all children.
  4542. // https://www.w3.org/TR/html5/syntax.html#optional-tags
  4543. if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
  4544. return;
  4545. }
  4546. if (parser_token.tag_name === 'body') {
  4547. // A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
  4548. result = result || this._tag_stack.try_pop('head');
  4549. //} else if (parser_token.tag_name === 'body') {
  4550. // DONE: A body element’s end tag may be omitted if the body element is not immediately followed by a comment.
  4551. } else if (parser_token.tag_name === 'li') {
  4552. // An li element’s end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.
  4553. result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
  4554. } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
  4555. // A dd element’s end tag may be omitted if the dd element is immediately followed by another dd element or a dt element, or if there is no more content in the parent element.
  4556. // A dt element’s end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.
  4557. result = result || this._tag_stack.try_pop('dt', ['dl']);
  4558. result = result || this._tag_stack.try_pop('dd', ['dl']);
  4559. } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
  4560. // IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
  4561. // check for the parent element is an HTML element that is not an <a>, <audio>, <del>, <ins>, <map>, <noscript>, or <video> element, or an autonomous custom element.
  4562. // To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
  4563. // But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
  4564. var p_parent = parser_token.parent.parent;
  4565. if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
  4566. result = result || this._tag_stack.try_pop('p');
  4567. }
  4568. } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
  4569. // An rt element’s end tag may be omitted if the rt element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
  4570. // An rp element’s end tag may be omitted if the rp element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
  4571. result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
  4572. result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
  4573. } else if (parser_token.tag_name === 'optgroup') {
  4574. // An optgroup element’s end tag may be omitted if the optgroup element is immediately followed by another optgroup element, or if there is no more content in the parent element.
  4575. // An option element’s end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
  4576. result = result || this._tag_stack.try_pop('optgroup', ['select']);
  4577. //result = result || this._tag_stack.try_pop('option', ['select']);
  4578. } else if (parser_token.tag_name === 'option') {
  4579. // An option element’s end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
  4580. result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
  4581. } else if (parser_token.tag_name === 'colgroup') {
  4582. // DONE: A colgroup element’s end tag may be omitted if the colgroup element is not immediately followed by a space character or a comment.
  4583. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  4584. result = result || this._tag_stack.try_pop('caption', ['table']);
  4585. } else if (parser_token.tag_name === 'thead') {
  4586. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  4587. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  4588. result = result || this._tag_stack.try_pop('caption', ['table']);
  4589. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  4590. //} else if (parser_token.tag_name === 'caption') {
  4591. // DONE: A caption element’s end tag may be omitted if the caption element is not immediately followed by a space character or a comment.
  4592. } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
  4593. // A thead element’s end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.
  4594. // A tbody element’s end tag may be omitted if the tbody element is immediately followed by a tbody or tfoot element, or if there is no more content in the parent element.
  4595. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  4596. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  4597. result = result || this._tag_stack.try_pop('caption', ['table']);
  4598. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  4599. result = result || this._tag_stack.try_pop('thead', ['table']);
  4600. result = result || this._tag_stack.try_pop('tbody', ['table']);
  4601. //} else if (parser_token.tag_name === 'tfoot') {
  4602. // DONE: A tfoot element’s end tag may be omitted if there is no more content in the parent element.
  4603. } else if (parser_token.tag_name === 'tr') {
  4604. // A tr element’s end tag may be omitted if the tr element is immediately followed by another tr element, or if there is no more content in the parent element.
  4605. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  4606. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  4607. result = result || this._tag_stack.try_pop('caption', ['table']);
  4608. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  4609. result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
  4610. } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
  4611. // A td element’s end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
  4612. // A th element’s end tag may be omitted if the th element is immediately followed by a td or th element, or if there is no more content in the parent element.
  4613. result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  4614. result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  4615. }
  4616. // Start element omission not handled currently
  4617. // A head element’s start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.
  4618. // A tbody element’s start tag may be omitted if the first thing inside the tbody element is a tr element, and if the element is not immediately preceded by a tbody, thead, or tfoot element whose end tag has been omitted. (It can’t be omitted if the element is empty.)
  4619. // A colgroup element’s start tag may be omitted if the first thing inside the colgroup element is a col element, and if the element is not immediately preceded by another colgroup element whose end tag has been omitted. (It can’t be omitted if the element is empty.)
  4620. // Fix up the parent of the parser token
  4621. parser_token.parent = this._tag_stack.get_parser_token();
  4622. return result;
  4623. };
  4624. module.exports.Beautifier = Beautifier;
  4625. /***/ }),
  4626. /* 21 */
  4627. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  4628. /*jshint node:true */
  4629. /*
  4630. The MIT License (MIT)
  4631. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  4632. Permission is hereby granted, free of charge, to any person
  4633. obtaining a copy of this software and associated documentation files
  4634. (the "Software"), to deal in the Software without restriction,
  4635. including without limitation the rights to use, copy, modify, merge,
  4636. publish, distribute, sublicense, and/or sell copies of the Software,
  4637. and to permit persons to whom the Software is furnished to do so,
  4638. subject to the following conditions:
  4639. The above copyright notice and this permission notice shall be
  4640. included in all copies or substantial portions of the Software.
  4641. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  4642. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4643. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  4644. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  4645. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  4646. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  4647. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  4648. SOFTWARE.
  4649. */
  4650. var BaseOptions = (__webpack_require__(7).Options);
  4651. function Options(options) {
  4652. BaseOptions.call(this, options, 'html');
  4653. if (this.templating.length === 1 && this.templating[0] === 'auto') {
  4654. this.templating = ['django', 'erb', 'handlebars', 'php'];
  4655. }
  4656. this.indent_inner_html = this._get_boolean('indent_inner_html');
  4657. this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
  4658. this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
  4659. this.indent_handlebars = this._get_boolean('indent_handlebars', true);
  4660. this.wrap_attributes = this._get_selection('wrap_attributes',
  4661. ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
  4662. this.wrap_attributes_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
  4663. this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
  4664. this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
  4665. // Block vs inline elements
  4666. // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
  4667. // https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
  4668. // https://www.w3.org/TR/html5/dom.html#phrasing-content
  4669. this.inline = this._get_array('inline', [
  4670. 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
  4671. 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
  4672. 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
  4673. 'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
  4674. 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
  4675. 'video', 'wbr', 'text',
  4676. // obsolete inline tags
  4677. 'acronym', 'big', 'strike', 'tt'
  4678. ]);
  4679. this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
  4680. this.void_elements = this._get_array('void_elements', [
  4681. // HTLM void elements - aka self-closing tags - aka singletons
  4682. // https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
  4683. 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
  4684. 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
  4685. // NOTE: Optional tags are too complex for a simple list
  4686. // they are hard coded in _do_optional_end_element
  4687. // Doctype and xml elements
  4688. '!doctype', '?xml',
  4689. // obsolete tags
  4690. // basefont: https://www.computerhope.com/jargon/h/html-basefont-tag.htm
  4691. // isndex: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex
  4692. 'basefont', 'isindex'
  4693. ]);
  4694. this.unformatted = this._get_array('unformatted', []);
  4695. this.content_unformatted = this._get_array('content_unformatted', [
  4696. 'pre', 'textarea'
  4697. ]);
  4698. this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
  4699. this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
  4700. }
  4701. Options.prototype = new BaseOptions();
  4702. module.exports.Options = Options;
  4703. /***/ }),
  4704. /* 22 */
  4705. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  4706. /*jshint node:true */
  4707. /*
  4708. The MIT License (MIT)
  4709. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  4710. Permission is hereby granted, free of charge, to any person
  4711. obtaining a copy of this software and associated documentation files
  4712. (the "Software"), to deal in the Software without restriction,
  4713. including without limitation the rights to use, copy, modify, merge,
  4714. publish, distribute, sublicense, and/or sell copies of the Software,
  4715. and to permit persons to whom the Software is furnished to do so,
  4716. subject to the following conditions:
  4717. The above copyright notice and this permission notice shall be
  4718. included in all copies or substantial portions of the Software.
  4719. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  4720. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  4721. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  4722. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  4723. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  4724. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  4725. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  4726. SOFTWARE.
  4727. */
  4728. var BaseTokenizer = (__webpack_require__(10).Tokenizer);
  4729. var BASETOKEN = (__webpack_require__(10).TOKEN);
  4730. var Directives = (__webpack_require__(14).Directives);
  4731. var TemplatablePattern = (__webpack_require__(15).TemplatablePattern);
  4732. var Pattern = (__webpack_require__(13).Pattern);
  4733. var TOKEN = {
  4734. TAG_OPEN: 'TK_TAG_OPEN',
  4735. TAG_CLOSE: 'TK_TAG_CLOSE',
  4736. ATTRIBUTE: 'TK_ATTRIBUTE',
  4737. EQUALS: 'TK_EQUALS',
  4738. VALUE: 'TK_VALUE',
  4739. COMMENT: 'TK_COMMENT',
  4740. TEXT: 'TK_TEXT',
  4741. UNKNOWN: 'TK_UNKNOWN',
  4742. START: BASETOKEN.START,
  4743. RAW: BASETOKEN.RAW,
  4744. EOF: BASETOKEN.EOF
  4745. };
  4746. var directives_core = new Directives(/<\!--/, /-->/);
  4747. var Tokenizer = function(input_string, options) {
  4748. BaseTokenizer.call(this, input_string, options);
  4749. this._current_tag_name = '';
  4750. // Words end at whitespace or when a tag starts
  4751. // if we are indenting handlebars, they are considered tags
  4752. var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
  4753. var pattern_reader = new Pattern(this._input);
  4754. this.__patterns = {
  4755. word: templatable_reader.until(/[\n\r\t <]/),
  4756. single_quote: templatable_reader.until_after(/'/),
  4757. double_quote: templatable_reader.until_after(/"/),
  4758. attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
  4759. element_name: templatable_reader.until(/[\n\r\t >\/]/),
  4760. handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
  4761. handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
  4762. handlebars_open: pattern_reader.until(/[\n\r\t }]/),
  4763. handlebars_raw_close: pattern_reader.until(/}}/),
  4764. comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
  4765. cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
  4766. // https://en.wikipedia.org/wiki/Conditional_comment
  4767. conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
  4768. processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
  4769. };
  4770. if (this._options.indent_handlebars) {
  4771. this.__patterns.word = this.__patterns.word.exclude('handlebars');
  4772. }
  4773. this._unformatted_content_delimiter = null;
  4774. if (this._options.unformatted_content_delimiter) {
  4775. var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
  4776. this.__patterns.unformatted_content_delimiter =
  4777. pattern_reader.matching(literal_regexp)
  4778. .until_after(literal_regexp);
  4779. }
  4780. };
  4781. Tokenizer.prototype = new BaseTokenizer();
  4782. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  4783. return false; //current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.UNKNOWN;
  4784. };
  4785. Tokenizer.prototype._is_opening = function(current_token) {
  4786. return current_token.type === TOKEN.TAG_OPEN;
  4787. };
  4788. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  4789. return current_token.type === TOKEN.TAG_CLOSE &&
  4790. (open_token && (
  4791. ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
  4792. (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
  4793. };
  4794. Tokenizer.prototype._reset = function() {
  4795. this._current_tag_name = '';
  4796. };
  4797. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  4798. var token = null;
  4799. this._readWhitespace();
  4800. var c = this._input.peek();
  4801. if (c === null) {
  4802. return this._create_token(TOKEN.EOF, '');
  4803. }
  4804. token = token || this._read_open_handlebars(c, open_token);
  4805. token = token || this._read_attribute(c, previous_token, open_token);
  4806. token = token || this._read_close(c, open_token);
  4807. token = token || this._read_raw_content(c, previous_token, open_token);
  4808. token = token || this._read_content_word(c);
  4809. token = token || this._read_comment_or_cdata(c);
  4810. token = token || this._read_processing(c);
  4811. token = token || this._read_open(c, open_token);
  4812. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  4813. return token;
  4814. };
  4815. Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
  4816. var token = null;
  4817. var resulting_string = null;
  4818. var directives = null;
  4819. if (c === '<') {
  4820. var peek1 = this._input.peek(1);
  4821. // We treat all comments as literals, even more than preformatted tags
  4822. // we only look for the appropriate closing marker
  4823. if (peek1 === '!') {
  4824. resulting_string = this.__patterns.comment.read();
  4825. // only process directive on html comments
  4826. if (resulting_string) {
  4827. directives = directives_core.get_directives(resulting_string);
  4828. if (directives && directives.ignore === 'start') {
  4829. resulting_string += directives_core.readIgnored(this._input);
  4830. }
  4831. } else {
  4832. resulting_string = this.__patterns.cdata.read();
  4833. }
  4834. }
  4835. if (resulting_string) {
  4836. token = this._create_token(TOKEN.COMMENT, resulting_string);
  4837. token.directives = directives;
  4838. }
  4839. }
  4840. return token;
  4841. };
  4842. Tokenizer.prototype._read_processing = function(c) { // jshint unused:false
  4843. var token = null;
  4844. var resulting_string = null;
  4845. var directives = null;
  4846. if (c === '<') {
  4847. var peek1 = this._input.peek(1);
  4848. if (peek1 === '!' || peek1 === '?') {
  4849. resulting_string = this.__patterns.conditional_comment.read();
  4850. resulting_string = resulting_string || this.__patterns.processing.read();
  4851. }
  4852. if (resulting_string) {
  4853. token = this._create_token(TOKEN.COMMENT, resulting_string);
  4854. token.directives = directives;
  4855. }
  4856. }
  4857. return token;
  4858. };
  4859. Tokenizer.prototype._read_open = function(c, open_token) {
  4860. var resulting_string = null;
  4861. var token = null;
  4862. if (!open_token) {
  4863. if (c === '<') {
  4864. resulting_string = this._input.next();
  4865. if (this._input.peek() === '/') {
  4866. resulting_string += this._input.next();
  4867. }
  4868. resulting_string += this.__patterns.element_name.read();
  4869. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  4870. }
  4871. }
  4872. return token;
  4873. };
  4874. Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
  4875. var resulting_string = null;
  4876. var token = null;
  4877. if (!open_token) {
  4878. if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
  4879. if (this._input.peek(2) === '!') {
  4880. resulting_string = this.__patterns.handlebars_comment.read();
  4881. resulting_string = resulting_string || this.__patterns.handlebars.read();
  4882. token = this._create_token(TOKEN.COMMENT, resulting_string);
  4883. } else {
  4884. resulting_string = this.__patterns.handlebars_open.read();
  4885. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  4886. }
  4887. }
  4888. }
  4889. return token;
  4890. };
  4891. Tokenizer.prototype._read_close = function(c, open_token) {
  4892. var resulting_string = null;
  4893. var token = null;
  4894. if (open_token) {
  4895. if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
  4896. resulting_string = this._input.next();
  4897. if (c === '/') { // for close tag "/>"
  4898. resulting_string += this._input.next();
  4899. }
  4900. token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
  4901. } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
  4902. this._input.next();
  4903. this._input.next();
  4904. token = this._create_token(TOKEN.TAG_CLOSE, '}}');
  4905. }
  4906. }
  4907. return token;
  4908. };
  4909. Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
  4910. var token = null;
  4911. var resulting_string = '';
  4912. if (open_token && open_token.text[0] === '<') {
  4913. if (c === '=') {
  4914. token = this._create_token(TOKEN.EQUALS, this._input.next());
  4915. } else if (c === '"' || c === "'") {
  4916. var content = this._input.next();
  4917. if (c === '"') {
  4918. content += this.__patterns.double_quote.read();
  4919. } else {
  4920. content += this.__patterns.single_quote.read();
  4921. }
  4922. token = this._create_token(TOKEN.VALUE, content);
  4923. } else {
  4924. resulting_string = this.__patterns.attribute.read();
  4925. if (resulting_string) {
  4926. if (previous_token.type === TOKEN.EQUALS) {
  4927. token = this._create_token(TOKEN.VALUE, resulting_string);
  4928. } else {
  4929. token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
  4930. }
  4931. }
  4932. }
  4933. }
  4934. return token;
  4935. };
  4936. Tokenizer.prototype._is_content_unformatted = function(tag_name) {
  4937. // void_elements have no content and so cannot have unformatted content
  4938. // script and style tags should always be read as unformatted content
  4939. // finally content_unformatted and unformatted element contents are unformatted
  4940. return this._options.void_elements.indexOf(tag_name) === -1 &&
  4941. (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
  4942. this._options.unformatted.indexOf(tag_name) !== -1);
  4943. };
  4944. Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
  4945. var resulting_string = '';
  4946. if (open_token && open_token.text[0] === '{') {
  4947. resulting_string = this.__patterns.handlebars_raw_close.read();
  4948. } else if (previous_token.type === TOKEN.TAG_CLOSE &&
  4949. previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
  4950. // ^^ empty tag has no content
  4951. var tag_name = previous_token.opened.text.substr(1).toLowerCase();
  4952. if (tag_name === 'script' || tag_name === 'style') {
  4953. // Script and style tags are allowed to have comments wrapping their content
  4954. // or just have regular content.
  4955. var token = this._read_comment_or_cdata(c);
  4956. if (token) {
  4957. token.type = TOKEN.TEXT;
  4958. return token;
  4959. }
  4960. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  4961. } else if (this._is_content_unformatted(tag_name)) {
  4962. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  4963. }
  4964. }
  4965. if (resulting_string) {
  4966. return this._create_token(TOKEN.TEXT, resulting_string);
  4967. }
  4968. return null;
  4969. };
  4970. Tokenizer.prototype._read_content_word = function(c) {
  4971. var resulting_string = '';
  4972. if (this._options.unformatted_content_delimiter) {
  4973. if (c === this._options.unformatted_content_delimiter[0]) {
  4974. resulting_string = this.__patterns.unformatted_content_delimiter.read();
  4975. }
  4976. }
  4977. if (!resulting_string) {
  4978. resulting_string = this.__patterns.word.read();
  4979. }
  4980. if (resulting_string) {
  4981. return this._create_token(TOKEN.TEXT, resulting_string);
  4982. }
  4983. };
  4984. module.exports.Tokenizer = Tokenizer;
  4985. module.exports.TOKEN = TOKEN;
  4986. /***/ })
  4987. /******/ ]);
  4988. /************************************************************************/
  4989. /******/ // The module cache
  4990. /******/ var __webpack_module_cache__ = {};
  4991. /******/
  4992. /******/ // The require function
  4993. /******/ function __webpack_require__(moduleId) {
  4994. /******/ // Check if module is in cache
  4995. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  4996. /******/ if (cachedModule !== undefined) {
  4997. /******/ return cachedModule.exports;
  4998. /******/ }
  4999. /******/ // Create a new module (and put it into the cache)
  5000. /******/ var module = __webpack_module_cache__[moduleId] = {
  5001. /******/ // no module.id needed
  5002. /******/ // no module.loaded needed
  5003. /******/ exports: {}
  5004. /******/ };
  5005. /******/
  5006. /******/ // Execute the module function
  5007. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  5008. /******/
  5009. /******/ // Return the exports of the module
  5010. /******/ return module.exports;
  5011. /******/ }
  5012. /******/
  5013. /************************************************************************/
  5014. /******/
  5015. /******/ // startup
  5016. /******/ // Load entry module and return exports
  5017. /******/ // This entry module used 'module' so it can't be inlined
  5018. /******/ var __webpack_exports__ = __webpack_require__(0);
  5019. /******/
  5020. /******/ return __webpack_exports__;
  5021. /******/ })()
  5022. ;
  5023. });
  5024. //# sourceMappingURL=beautifier.js.map