beautifier.js 214 KB

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