beautifier.js 186 KB

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