beautifier.js 223 KB

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