beautifier.js 213 KB

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