beautifier.js 213 KB

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