beautifier.js 208 KB

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