beautify.js 144 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006
  1. /* AUTO-GENERATED. DO NOT MODIFY. */
  2. /*
  3. The MIT License (MIT)
  4. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  5. Permission is hereby granted, free of charge, to any person
  6. obtaining a copy of this software and associated documentation files
  7. (the "Software"), to deal in the Software without restriction,
  8. including without limitation the rights to use, copy, modify, merge,
  9. publish, distribute, sublicense, and/or sell copies of the Software,
  10. and to permit persons to whom the Software is furnished to do so,
  11. subject to the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. JS Beautifier
  23. ---------------
  24. Written by Einar Lielmanis, <einar@beautifier.io>
  25. https://beautifier.io/
  26. Originally converted to javascript by Vital, <vital76@gmail.com>
  27. "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
  28. Parsing improvements for brace-less statements by Liam Newman <bitwiseman@beautifier.io>
  29. Usage:
  30. js_beautify(js_source_text);
  31. js_beautify(js_source_text, options);
  32. The options are:
  33. indent_size (default 4) - indentation size,
  34. indent_char (default space) - character to indent with,
  35. preserve_newlines (default true) - whether existing line breaks should be preserved,
  36. max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
  37. jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
  38. jslint_happy !jslint_happy
  39. ---------------------------------
  40. function () function()
  41. switch () { switch() {
  42. case 1: case 1:
  43. break; break;
  44. } }
  45. space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()",
  46. NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
  47. brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none" | any of the former + ",preserve-inline"
  48. put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are.
  49. preserve-inline will try to preserve inline blocks of curly braces
  50. space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
  51. unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
  52. wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.
  53. NOTE: This is not a hard limit. Lines will continue until a point where a newline would
  54. be preserved if it were present.
  55. end_with_newline (default false) - end output with a newline
  56. e.g
  57. js_beautify(js_source_text, {
  58. 'indent_size': 1,
  59. 'indent_char': '\t'
  60. });
  61. */
  62. (function() {
  63. /* GENERATED_BUILD_OUTPUT */
  64. var legacy_beautify_js;
  65. /******/ (function() { // webpackBootstrap
  66. /******/ "use strict";
  67. /******/ var __webpack_modules__ = ([
  68. /* 0 */
  69. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  70. /*jshint node:true */
  71. /*
  72. The MIT License (MIT)
  73. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  74. Permission is hereby granted, free of charge, to any person
  75. obtaining a copy of this software and associated documentation files
  76. (the "Software"), to deal in the Software without restriction,
  77. including without limitation the rights to use, copy, modify, merge,
  78. publish, distribute, sublicense, and/or sell copies of the Software,
  79. and to permit persons to whom the Software is furnished to do so,
  80. subject to the following conditions:
  81. The above copyright notice and this permission notice shall be
  82. included in all copies or substantial portions of the Software.
  83. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  84. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  85. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  86. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  87. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  88. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  89. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  90. SOFTWARE.
  91. */
  92. var Beautifier = __webpack_require__(1).Beautifier,
  93. Options = __webpack_require__(5).Options;
  94. function js_beautify(js_source_text, options) {
  95. var beautifier = new Beautifier(js_source_text, options);
  96. return beautifier.beautify();
  97. }
  98. module.exports = js_beautify;
  99. module.exports.defaultOptions = function() {
  100. return new Options();
  101. };
  102. /***/ }),
  103. /* 1 */
  104. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  105. /*jshint node:true */
  106. /*
  107. The MIT License (MIT)
  108. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  109. Permission is hereby granted, free of charge, to any person
  110. obtaining a copy of this software and associated documentation files
  111. (the "Software"), to deal in the Software without restriction,
  112. including without limitation the rights to use, copy, modify, merge,
  113. publish, distribute, sublicense, and/or sell copies of the Software,
  114. and to permit persons to whom the Software is furnished to do so,
  115. subject to the following conditions:
  116. The above copyright notice and this permission notice shall be
  117. included in all copies or substantial portions of the Software.
  118. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  119. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  120. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  121. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  122. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  123. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  124. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  125. SOFTWARE.
  126. */
  127. var Output = __webpack_require__(2).Output;
  128. var Token = __webpack_require__(3).Token;
  129. var acorn = __webpack_require__(4);
  130. var Options = __webpack_require__(5).Options;
  131. var Tokenizer = __webpack_require__(7).Tokenizer;
  132. var line_starters = __webpack_require__(7).line_starters;
  133. var positionable_operators = __webpack_require__(7).positionable_operators;
  134. var TOKEN = __webpack_require__(7).TOKEN;
  135. function in_array(what, arr) {
  136. return arr.indexOf(what) !== -1;
  137. }
  138. function ltrim(s) {
  139. return s.replace(/^\s+/g, '');
  140. }
  141. function generateMapFromStrings(list) {
  142. var result = {};
  143. for (var x = 0; x < list.length; x++) {
  144. // make the mapped names underscored instead of dash
  145. result[list[x].replace(/-/g, '_')] = list[x];
  146. }
  147. return result;
  148. }
  149. function reserved_word(token, word) {
  150. return token && token.type === TOKEN.RESERVED && token.text === word;
  151. }
  152. function reserved_array(token, words) {
  153. return token && token.type === TOKEN.RESERVED && in_array(token.text, words);
  154. }
  155. // Unsure of what they mean, but they work. Worth cleaning up in future.
  156. var special_words = ['case', 'return', 'do', 'if', 'throw', 'else', 'await', 'break', 'continue', 'async'];
  157. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  158. // Generate map from array
  159. var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
  160. var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
  161. var MODE = {
  162. BlockStatement: 'BlockStatement', // 'BLOCK'
  163. Statement: 'Statement', // 'STATEMENT'
  164. ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
  165. ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
  166. ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
  167. Conditional: 'Conditional', //'(COND-EXPRESSION)',
  168. Expression: 'Expression' //'(EXPRESSION)'
  169. };
  170. function remove_redundant_indentation(output, frame) {
  171. // This implementation is effective but has some issues:
  172. // - can cause line wrap to happen too soon due to indent removal
  173. // after wrap points are calculated
  174. // These issues are minor compared to ugly indentation.
  175. if (frame.multiline_frame ||
  176. frame.mode === MODE.ForInitializer ||
  177. frame.mode === MODE.Conditional) {
  178. return;
  179. }
  180. // remove one indent from each line inside this section
  181. output.remove_indent(frame.start_line_index);
  182. }
  183. // we could use just string.split, but
  184. // IE doesn't like returning empty strings
  185. function split_linebreaks(s) {
  186. //return s.split(/\x0d\x0a|\x0a/);
  187. s = s.replace(acorn.allLineBreaks, '\n');
  188. var out = [],
  189. idx = s.indexOf("\n");
  190. while (idx !== -1) {
  191. out.push(s.substring(0, idx));
  192. s = s.substring(idx + 1);
  193. idx = s.indexOf("\n");
  194. }
  195. if (s.length) {
  196. out.push(s);
  197. }
  198. return out;
  199. }
  200. function is_array(mode) {
  201. return mode === MODE.ArrayLiteral;
  202. }
  203. function is_expression(mode) {
  204. return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
  205. }
  206. function all_lines_start_with(lines, c) {
  207. for (var i = 0; i < lines.length; i++) {
  208. var line = lines[i].trim();
  209. if (line.charAt(0) !== c) {
  210. return false;
  211. }
  212. }
  213. return true;
  214. }
  215. function each_line_matches_indent(lines, indent) {
  216. var i = 0,
  217. len = lines.length,
  218. line;
  219. for (; i < len; i++) {
  220. line = lines[i];
  221. // allow empty lines to pass through
  222. if (line && line.indexOf(indent) !== 0) {
  223. return false;
  224. }
  225. }
  226. return true;
  227. }
  228. function Beautifier(source_text, options) {
  229. options = options || {};
  230. this._source_text = source_text || '';
  231. this._output = null;
  232. this._tokens = null;
  233. this._last_last_text = null;
  234. this._flags = null;
  235. this._previous_flags = null;
  236. this._flag_store = null;
  237. this._options = new Options(options);
  238. }
  239. Beautifier.prototype.create_flags = function(flags_base, mode) {
  240. var next_indent_level = 0;
  241. if (flags_base) {
  242. next_indent_level = flags_base.indentation_level;
  243. if (!this._output.just_added_newline() &&
  244. flags_base.line_indent_level > next_indent_level) {
  245. next_indent_level = flags_base.line_indent_level;
  246. }
  247. }
  248. var next_flags = {
  249. mode: mode,
  250. parent: flags_base,
  251. last_token: flags_base ? flags_base.last_token : new Token(TOKEN.START_BLOCK, ''), // last token text
  252. last_word: flags_base ? flags_base.last_word : '', // last TOKEN.WORD passed
  253. declaration_statement: false,
  254. declaration_assignment: false,
  255. multiline_frame: false,
  256. inline_frame: false,
  257. if_block: false,
  258. else_block: false,
  259. do_block: false,
  260. do_while: false,
  261. import_block: false,
  262. in_case_statement: false, // switch(..){ INSIDE HERE }
  263. in_case: false, // we're on the exact line with "case 0:"
  264. case_body: false, // the indented case-action block
  265. indentation_level: next_indent_level,
  266. alignment: 0,
  267. line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
  268. start_line_index: this._output.get_line_number(),
  269. ternary_depth: 0
  270. };
  271. return next_flags;
  272. };
  273. Beautifier.prototype._reset = function(source_text) {
  274. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  275. this._last_last_text = ''; // pre-last token text
  276. this._output = new Output(this._options, baseIndentString);
  277. // If testing the ignore directive, start with output disable set to true
  278. this._output.raw = this._options.test_output_raw;
  279. // Stack of parsing/formatting states, including MODE.
  280. // We tokenize, parse, and output in an almost purely a forward-only stream of token input
  281. // and formatted output. This makes the beautifier less accurate than full parsers
  282. // but also far more tolerant of syntax errors.
  283. //
  284. // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
  285. // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
  286. // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
  287. // most full parsers would die, but the beautifier gracefully falls back to
  288. // MODE.BlockStatement and continues on.
  289. this._flag_store = [];
  290. this.set_mode(MODE.BlockStatement);
  291. var tokenizer = new Tokenizer(source_text, this._options);
  292. this._tokens = tokenizer.tokenize();
  293. return source_text;
  294. };
  295. Beautifier.prototype.beautify = function() {
  296. // if disabled, return the input unchanged.
  297. if (this._options.disabled) {
  298. return this._source_text;
  299. }
  300. var sweet_code;
  301. var source_text = this._reset(this._source_text);
  302. var eol = this._options.eol;
  303. if (this._options.eol === 'auto') {
  304. eol = '\n';
  305. if (source_text && acorn.lineBreak.test(source_text || '')) {
  306. eol = source_text.match(acorn.lineBreak)[0];
  307. }
  308. }
  309. var current_token = this._tokens.next();
  310. while (current_token) {
  311. this.handle_token(current_token);
  312. this._last_last_text = this._flags.last_token.text;
  313. this._flags.last_token = current_token;
  314. current_token = this._tokens.next();
  315. }
  316. sweet_code = this._output.get_code(eol);
  317. return sweet_code;
  318. };
  319. Beautifier.prototype.handle_token = function(current_token, preserve_statement_flags) {
  320. if (current_token.type === TOKEN.START_EXPR) {
  321. this.handle_start_expr(current_token);
  322. } else if (current_token.type === TOKEN.END_EXPR) {
  323. this.handle_end_expr(current_token);
  324. } else if (current_token.type === TOKEN.START_BLOCK) {
  325. this.handle_start_block(current_token);
  326. } else if (current_token.type === TOKEN.END_BLOCK) {
  327. this.handle_end_block(current_token);
  328. } else if (current_token.type === TOKEN.WORD) {
  329. this.handle_word(current_token);
  330. } else if (current_token.type === TOKEN.RESERVED) {
  331. this.handle_word(current_token);
  332. } else if (current_token.type === TOKEN.SEMICOLON) {
  333. this.handle_semicolon(current_token);
  334. } else if (current_token.type === TOKEN.STRING) {
  335. this.handle_string(current_token);
  336. } else if (current_token.type === TOKEN.EQUALS) {
  337. this.handle_equals(current_token);
  338. } else if (current_token.type === TOKEN.OPERATOR) {
  339. this.handle_operator(current_token);
  340. } else if (current_token.type === TOKEN.COMMA) {
  341. this.handle_comma(current_token);
  342. } else if (current_token.type === TOKEN.BLOCK_COMMENT) {
  343. this.handle_block_comment(current_token, preserve_statement_flags);
  344. } else if (current_token.type === TOKEN.COMMENT) {
  345. this.handle_comment(current_token, preserve_statement_flags);
  346. } else if (current_token.type === TOKEN.DOT) {
  347. this.handle_dot(current_token);
  348. } else if (current_token.type === TOKEN.EOF) {
  349. this.handle_eof(current_token);
  350. } else if (current_token.type === TOKEN.UNKNOWN) {
  351. this.handle_unknown(current_token, preserve_statement_flags);
  352. } else {
  353. this.handle_unknown(current_token, preserve_statement_flags);
  354. }
  355. };
  356. Beautifier.prototype.handle_whitespace_and_comments = function(current_token, preserve_statement_flags) {
  357. var newlines = current_token.newlines;
  358. var keep_whitespace = this._options.keep_array_indentation && is_array(this._flags.mode);
  359. if (current_token.comments_before) {
  360. var comment_token = current_token.comments_before.next();
  361. while (comment_token) {
  362. // The cleanest handling of inline comments is to treat them as though they aren't there.
  363. // Just continue formatting and the behavior should be logical.
  364. // Also ignore unknown tokens. Again, this should result in better behavior.
  365. this.handle_whitespace_and_comments(comment_token, preserve_statement_flags);
  366. this.handle_token(comment_token, preserve_statement_flags);
  367. comment_token = current_token.comments_before.next();
  368. }
  369. }
  370. if (keep_whitespace) {
  371. for (var i = 0; i < newlines; i += 1) {
  372. this.print_newline(i > 0, preserve_statement_flags);
  373. }
  374. } else {
  375. if (this._options.max_preserve_newlines && newlines > this._options.max_preserve_newlines) {
  376. newlines = this._options.max_preserve_newlines;
  377. }
  378. if (this._options.preserve_newlines) {
  379. if (newlines > 1) {
  380. this.print_newline(false, preserve_statement_flags);
  381. for (var j = 1; j < newlines; j += 1) {
  382. this.print_newline(true, preserve_statement_flags);
  383. }
  384. }
  385. }
  386. }
  387. };
  388. var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];
  389. Beautifier.prototype.allow_wrap_or_preserved_newline = function(current_token, force_linewrap) {
  390. force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
  391. // Never wrap the first token on a line
  392. if (this._output.just_added_newline()) {
  393. return;
  394. }
  395. var shouldPreserveOrForce = (this._options.preserve_newlines && current_token.newlines) || force_linewrap;
  396. var operatorLogicApplies = in_array(this._flags.last_token.text, positionable_operators) ||
  397. in_array(current_token.text, positionable_operators);
  398. if (operatorLogicApplies) {
  399. var shouldPrintOperatorNewline = (
  400. in_array(this._flags.last_token.text, positionable_operators) &&
  401. in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
  402. ) ||
  403. in_array(current_token.text, positionable_operators);
  404. shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
  405. }
  406. if (shouldPreserveOrForce) {
  407. this.print_newline(false, true);
  408. } else if (this._options.wrap_line_length) {
  409. if (reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  410. // These tokens should never have a newline inserted
  411. // between them and the following expression.
  412. return;
  413. }
  414. this._output.set_wrap_point();
  415. }
  416. };
  417. Beautifier.prototype.print_newline = function(force_newline, preserve_statement_flags) {
  418. if (!preserve_statement_flags) {
  419. 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 === '++')) {
  420. var next_token = this._tokens.peek();
  421. while (this._flags.mode === MODE.Statement &&
  422. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  423. !this._flags.do_block) {
  424. this.restore_mode();
  425. }
  426. }
  427. }
  428. if (this._output.add_new_line(force_newline)) {
  429. this._flags.multiline_frame = true;
  430. }
  431. };
  432. Beautifier.prototype.print_token_line_indentation = function(current_token) {
  433. if (this._output.just_added_newline()) {
  434. if (this._options.keep_array_indentation &&
  435. current_token.newlines &&
  436. (current_token.text === '[' || is_array(this._flags.mode))) {
  437. this._output.current_line.set_indent(-1);
  438. this._output.current_line.push(current_token.whitespace_before);
  439. this._output.space_before_token = false;
  440. } else if (this._output.set_indent(this._flags.indentation_level, this._flags.alignment)) {
  441. this._flags.line_indent_level = this._flags.indentation_level;
  442. }
  443. }
  444. };
  445. Beautifier.prototype.print_token = function(current_token) {
  446. if (this._output.raw) {
  447. this._output.add_raw_token(current_token);
  448. return;
  449. }
  450. if (this._options.comma_first && current_token.previous && current_token.previous.type === TOKEN.COMMA &&
  451. this._output.just_added_newline()) {
  452. if (this._output.previous_line.last() === ',') {
  453. var popped = this._output.previous_line.pop();
  454. // if the comma was already at the start of the line,
  455. // pull back onto that line and reprint the indentation
  456. if (this._output.previous_line.is_empty()) {
  457. this._output.previous_line.push(popped);
  458. this._output.trim(true);
  459. this._output.current_line.pop();
  460. this._output.trim();
  461. }
  462. // add the comma in front of the next token
  463. this.print_token_line_indentation(current_token);
  464. this._output.add_token(',');
  465. this._output.space_before_token = true;
  466. }
  467. }
  468. this.print_token_line_indentation(current_token);
  469. this._output.non_breaking_space = true;
  470. this._output.add_token(current_token.text);
  471. if (this._output.previous_token_wrapped) {
  472. this._flags.multiline_frame = true;
  473. }
  474. };
  475. Beautifier.prototype.indent = function() {
  476. this._flags.indentation_level += 1;
  477. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  478. };
  479. Beautifier.prototype.deindent = function() {
  480. if (this._flags.indentation_level > 0 &&
  481. ((!this._flags.parent) || this._flags.indentation_level > this._flags.parent.indentation_level)) {
  482. this._flags.indentation_level -= 1;
  483. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  484. }
  485. };
  486. Beautifier.prototype.set_mode = function(mode) {
  487. if (this._flags) {
  488. this._flag_store.push(this._flags);
  489. this._previous_flags = this._flags;
  490. } else {
  491. this._previous_flags = this.create_flags(null, mode);
  492. }
  493. this._flags = this.create_flags(this._previous_flags, mode);
  494. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  495. };
  496. Beautifier.prototype.restore_mode = function() {
  497. if (this._flag_store.length > 0) {
  498. this._previous_flags = this._flags;
  499. this._flags = this._flag_store.pop();
  500. if (this._previous_flags.mode === MODE.Statement) {
  501. remove_redundant_indentation(this._output, this._previous_flags);
  502. }
  503. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  504. }
  505. };
  506. Beautifier.prototype.start_of_object_property = function() {
  507. return this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement && (
  508. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || (reserved_array(this._flags.last_token, ['get', 'set'])));
  509. };
  510. Beautifier.prototype.start_of_statement = function(current_token) {
  511. var start = false;
  512. start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
  513. start = start || reserved_word(this._flags.last_token, 'do');
  514. 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;
  515. start = start || reserved_word(this._flags.last_token, 'else') &&
  516. !(reserved_word(current_token, 'if') && !current_token.comments_before);
  517. start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
  518. start = start || (this._flags.last_token.type === TOKEN.WORD && this._flags.mode === MODE.BlockStatement &&
  519. !this._flags.in_case &&
  520. !(current_token.text === '--' || current_token.text === '++') &&
  521. this._last_last_text !== 'function' &&
  522. current_token.type !== TOKEN.WORD && current_token.type !== TOKEN.RESERVED);
  523. start = start || (this._flags.mode === MODE.ObjectLiteral && (
  524. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || reserved_array(this._flags.last_token, ['get', 'set'])));
  525. if (start) {
  526. this.set_mode(MODE.Statement);
  527. this.indent();
  528. this.handle_whitespace_and_comments(current_token, true);
  529. // Issue #276:
  530. // If starting a new statement with [if, for, while, do], push to a new line.
  531. // if (a) if (b) if(c) d(); else e(); else f();
  532. if (!this.start_of_object_property()) {
  533. this.allow_wrap_or_preserved_newline(current_token,
  534. reserved_array(current_token, ['do', 'for', 'if', 'while']));
  535. }
  536. return true;
  537. }
  538. return false;
  539. };
  540. Beautifier.prototype.handle_start_expr = function(current_token) {
  541. // The conditional starts the statement if appropriate.
  542. if (!this.start_of_statement(current_token)) {
  543. this.handle_whitespace_and_comments(current_token);
  544. }
  545. var next_mode = MODE.Expression;
  546. if (current_token.text === '[') {
  547. if (this._flags.last_token.type === TOKEN.WORD || this._flags.last_token.text === ')') {
  548. // this is array index specifier, break immediately
  549. // a[x], fn()[x]
  550. if (reserved_array(this._flags.last_token, line_starters)) {
  551. this._output.space_before_token = true;
  552. }
  553. this.print_token(current_token);
  554. this.set_mode(next_mode);
  555. this.indent();
  556. if (this._options.space_in_paren) {
  557. this._output.space_before_token = true;
  558. }
  559. return;
  560. }
  561. next_mode = MODE.ArrayLiteral;
  562. if (is_array(this._flags.mode)) {
  563. if (this._flags.last_token.text === '[' ||
  564. (this._flags.last_token.text === ',' && (this._last_last_text === ']' || this._last_last_text === '}'))) {
  565. // ], [ goes to new line
  566. // }, [ goes to new line
  567. if (!this._options.keep_array_indentation) {
  568. this.print_newline();
  569. }
  570. }
  571. }
  572. if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR, TOKEN.DOT])) {
  573. this._output.space_before_token = true;
  574. }
  575. } else {
  576. if (this._flags.last_token.type === TOKEN.RESERVED) {
  577. if (this._flags.last_token.text === 'for') {
  578. this._output.space_before_token = this._options.space_before_conditional;
  579. next_mode = MODE.ForInitializer;
  580. } else if (in_array(this._flags.last_token.text, ['if', 'while', 'switch'])) {
  581. this._output.space_before_token = this._options.space_before_conditional;
  582. next_mode = MODE.Conditional;
  583. } else if (in_array(this._flags.last_word, ['await', 'async'])) {
  584. // Should be a space between await and an IIFE, or async and an arrow function
  585. this._output.space_before_token = true;
  586. } else if (this._flags.last_token.text === 'import' && current_token.whitespace_before === '') {
  587. this._output.space_before_token = false;
  588. } else if (in_array(this._flags.last_token.text, line_starters) || this._flags.last_token.text === 'catch') {
  589. this._output.space_before_token = true;
  590. }
  591. } else if (this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  592. // Support of this kind of newline preservation.
  593. // a = (b &&
  594. // (c || d));
  595. if (!this.start_of_object_property()) {
  596. this.allow_wrap_or_preserved_newline(current_token);
  597. }
  598. } else if (this._flags.last_token.type === TOKEN.WORD) {
  599. this._output.space_before_token = false;
  600. // function name() vs function name ()
  601. // function* name() vs function* name ()
  602. // async name() vs async name ()
  603. // In ES6, you can also define the method properties of an object
  604. // var obj = {a: function() {}}
  605. // It can be abbreviated
  606. // var obj = {a() {}}
  607. // var obj = { a() {}} vs var obj = { a () {}}
  608. // var obj = { * a() {}} vs var obj = { * a () {}}
  609. var peek_back_two = this._tokens.peek(-3);
  610. if (this._options.space_after_named_function && peek_back_two) {
  611. // peek starts at next character so -1 is current token
  612. var peek_back_three = this._tokens.peek(-4);
  613. if (reserved_array(peek_back_two, ['async', 'function']) ||
  614. (peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
  615. this._output.space_before_token = true;
  616. } else if (this._flags.mode === MODE.ObjectLiteral) {
  617. if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
  618. (peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
  619. this._output.space_before_token = true;
  620. }
  621. }
  622. }
  623. } else {
  624. // Support preserving wrapped arrow function expressions
  625. // a.b('c',
  626. // () => d.e
  627. // )
  628. this.allow_wrap_or_preserved_newline(current_token);
  629. }
  630. // function() vs function ()
  631. // yield*() vs yield* ()
  632. // function*() vs function* ()
  633. if ((this._flags.last_token.type === TOKEN.RESERVED && (this._flags.last_word === 'function' || this._flags.last_word === 'typeof')) ||
  634. (this._flags.last_token.text === '*' &&
  635. (in_array(this._last_last_text, ['function', 'yield']) ||
  636. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  637. this._output.space_before_token = this._options.space_after_anon_function;
  638. }
  639. }
  640. if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
  641. this.print_newline();
  642. } 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) {
  643. // do nothing on (( and )( and ][ and ]( and .(
  644. // TODO: Consider whether forcing this is required. Review failing tests when removed.
  645. this.allow_wrap_or_preserved_newline(current_token, current_token.newlines);
  646. }
  647. this.print_token(current_token);
  648. this.set_mode(next_mode);
  649. if (this._options.space_in_paren) {
  650. this._output.space_before_token = true;
  651. }
  652. // In all cases, if we newline while inside an expression it should be indented.
  653. this.indent();
  654. };
  655. Beautifier.prototype.handle_end_expr = function(current_token) {
  656. // statements inside expressions are not valid syntax, but...
  657. // statements must all be closed when their container closes
  658. while (this._flags.mode === MODE.Statement) {
  659. this.restore_mode();
  660. }
  661. this.handle_whitespace_and_comments(current_token);
  662. if (this._flags.multiline_frame) {
  663. this.allow_wrap_or_preserved_newline(current_token,
  664. current_token.text === ']' && is_array(this._flags.mode) && !this._options.keep_array_indentation);
  665. }
  666. if (this._options.space_in_paren) {
  667. if (this._flags.last_token.type === TOKEN.START_EXPR && !this._options.space_in_empty_paren) {
  668. // () [] no inner space in empty parens like these, ever, ref #320
  669. this._output.trim();
  670. this._output.space_before_token = false;
  671. } else {
  672. this._output.space_before_token = true;
  673. }
  674. }
  675. this.deindent();
  676. this.print_token(current_token);
  677. this.restore_mode();
  678. remove_redundant_indentation(this._output, this._previous_flags);
  679. // do {} while () // no statement required after
  680. if (this._flags.do_while && this._previous_flags.mode === MODE.Conditional) {
  681. this._previous_flags.mode = MODE.Expression;
  682. this._flags.do_block = false;
  683. this._flags.do_while = false;
  684. }
  685. };
  686. Beautifier.prototype.handle_start_block = function(current_token) {
  687. this.handle_whitespace_and_comments(current_token);
  688. // Check if this is should be treated as a ObjectLiteral
  689. var next_token = this._tokens.peek();
  690. var second_token = this._tokens.peek(1);
  691. if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) {
  692. this.set_mode(MODE.BlockStatement);
  693. this._flags.in_case_statement = true;
  694. } else if (this._flags.case_body) {
  695. this.set_mode(MODE.BlockStatement);
  696. } else if (second_token && (
  697. (in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
  698. (in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
  699. )) {
  700. // We don't support TypeScript,but we didn't break it for a very long time.
  701. // We'll try to keep not breaking it.
  702. if (!in_array(this._last_last_text, ['class', 'interface'])) {
  703. this.set_mode(MODE.ObjectLiteral);
  704. } else {
  705. this.set_mode(MODE.BlockStatement);
  706. }
  707. } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
  708. // arrow function: (param1, paramN) => { statements }
  709. this.set_mode(MODE.BlockStatement);
  710. } else if (in_array(this._flags.last_token.type, [TOKEN.EQUALS, TOKEN.START_EXPR, TOKEN.COMMA, TOKEN.OPERATOR]) ||
  711. reserved_array(this._flags.last_token, ['return', 'throw', 'import', 'default'])
  712. ) {
  713. // Detecting shorthand function syntax is difficult by scanning forward,
  714. // so check the surrounding context.
  715. // If the block is being returned, imported, export default, passed as arg,
  716. // assigned with = or assigned in a nested object, treat as an ObjectLiteral.
  717. this.set_mode(MODE.ObjectLiteral);
  718. } else {
  719. this.set_mode(MODE.BlockStatement);
  720. }
  721. var empty_braces = !next_token.comments_before && next_token.text === '}';
  722. var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
  723. this._flags.last_token.type === TOKEN.END_EXPR;
  724. if (this._options.brace_preserve_inline) // check for inline, set inline_frame if so
  725. {
  726. // search forward for a newline wanted inside this block
  727. var index = 0;
  728. var check_token = null;
  729. this._flags.inline_frame = true;
  730. do {
  731. index += 1;
  732. check_token = this._tokens.peek(index - 1);
  733. if (check_token.newlines) {
  734. this._flags.inline_frame = false;
  735. break;
  736. }
  737. } while (check_token.type !== TOKEN.EOF &&
  738. !(check_token.type === TOKEN.END_BLOCK && check_token.opened === current_token));
  739. }
  740. if ((this._options.brace_style === "expand" ||
  741. (this._options.brace_style === "none" && current_token.newlines)) &&
  742. !this._flags.inline_frame) {
  743. if (this._flags.last_token.type !== TOKEN.OPERATOR &&
  744. (empty_anonymous_function ||
  745. this._flags.last_token.type === TOKEN.EQUALS ||
  746. (reserved_array(this._flags.last_token, special_words) && this._flags.last_token.text !== 'else'))) {
  747. this._output.space_before_token = true;
  748. } else {
  749. this.print_newline(false, true);
  750. }
  751. } else { // collapse || inline_frame
  752. if (is_array(this._previous_flags.mode) && (this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.COMMA)) {
  753. if (this._flags.last_token.type === TOKEN.COMMA || this._options.space_in_paren) {
  754. this._output.space_before_token = true;
  755. }
  756. if (this._flags.last_token.type === TOKEN.COMMA || (this._flags.last_token.type === TOKEN.START_EXPR && this._flags.inline_frame)) {
  757. this.allow_wrap_or_preserved_newline(current_token);
  758. this._previous_flags.multiline_frame = this._previous_flags.multiline_frame || this._flags.multiline_frame;
  759. this._flags.multiline_frame = false;
  760. }
  761. }
  762. if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
  763. if (this._flags.last_token.type === TOKEN.START_BLOCK && !this._flags.inline_frame) {
  764. this.print_newline();
  765. } else {
  766. this._output.space_before_token = true;
  767. }
  768. }
  769. }
  770. this.print_token(current_token);
  771. this.indent();
  772. // Except for specific cases, open braces are followed by a new line.
  773. if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
  774. this.print_newline();
  775. }
  776. };
  777. Beautifier.prototype.handle_end_block = function(current_token) {
  778. // statements must all be closed when their container closes
  779. this.handle_whitespace_and_comments(current_token);
  780. while (this._flags.mode === MODE.Statement) {
  781. this.restore_mode();
  782. }
  783. var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
  784. if (this._flags.inline_frame && !empty_braces) { // try inline_frame (only set if this._options.braces-preserve-inline) first
  785. this._output.space_before_token = true;
  786. } else if (this._options.brace_style === "expand") {
  787. if (!empty_braces) {
  788. this.print_newline();
  789. }
  790. } else {
  791. // skip {}
  792. if (!empty_braces) {
  793. if (is_array(this._flags.mode) && this._options.keep_array_indentation) {
  794. // we REALLY need a newline here, but newliner would skip that
  795. this._options.keep_array_indentation = false;
  796. this.print_newline();
  797. this._options.keep_array_indentation = true;
  798. } else {
  799. this.print_newline();
  800. }
  801. }
  802. }
  803. this.restore_mode();
  804. this.print_token(current_token);
  805. };
  806. Beautifier.prototype.handle_word = function(current_token) {
  807. if (current_token.type === TOKEN.RESERVED) {
  808. if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
  809. current_token.type = TOKEN.WORD;
  810. } else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
  811. current_token.type = TOKEN.WORD;
  812. } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
  813. current_token.type = TOKEN.WORD;
  814. } else if (this._flags.mode === MODE.ObjectLiteral) {
  815. var next_token = this._tokens.peek();
  816. if (next_token.text === ':') {
  817. current_token.type = TOKEN.WORD;
  818. }
  819. }
  820. }
  821. if (this.start_of_statement(current_token)) {
  822. // The conditional starts the statement if appropriate.
  823. if (reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD) {
  824. this._flags.declaration_statement = true;
  825. }
  826. } else if (current_token.newlines && !is_expression(this._flags.mode) &&
  827. (this._flags.last_token.type !== TOKEN.OPERATOR || (this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) &&
  828. this._flags.last_token.type !== TOKEN.EQUALS &&
  829. (this._options.preserve_newlines || !reserved_array(this._flags.last_token, ['var', 'let', 'const', 'set', 'get']))) {
  830. this.handle_whitespace_and_comments(current_token);
  831. this.print_newline();
  832. } else {
  833. this.handle_whitespace_and_comments(current_token);
  834. }
  835. if (this._flags.do_block && !this._flags.do_while) {
  836. if (reserved_word(current_token, 'while')) {
  837. // do {} ## while ()
  838. this._output.space_before_token = true;
  839. this.print_token(current_token);
  840. this._output.space_before_token = true;
  841. this._flags.do_while = true;
  842. return;
  843. } else {
  844. // do {} should always have while as the next word.
  845. // if we don't see the expected while, recover
  846. this.print_newline();
  847. this._flags.do_block = false;
  848. }
  849. }
  850. // if may be followed by else, or not
  851. // Bare/inline ifs are tricky
  852. // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
  853. if (this._flags.if_block) {
  854. if (!this._flags.else_block && reserved_word(current_token, 'else')) {
  855. this._flags.else_block = true;
  856. } else {
  857. while (this._flags.mode === MODE.Statement) {
  858. this.restore_mode();
  859. }
  860. this._flags.if_block = false;
  861. this._flags.else_block = false;
  862. }
  863. }
  864. if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
  865. this.print_newline();
  866. if (this._flags.last_token.type !== TOKEN.END_BLOCK && (this._flags.case_body || this._options.jslint_happy)) {
  867. // switch cases following one another
  868. this.deindent();
  869. }
  870. this._flags.case_body = false;
  871. this.print_token(current_token);
  872. this._flags.in_case = true;
  873. return;
  874. }
  875. 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) {
  876. if (!this.start_of_object_property()) {
  877. this.allow_wrap_or_preserved_newline(current_token);
  878. }
  879. }
  880. if (reserved_word(current_token, 'function')) {
  881. if (in_array(this._flags.last_token.text, ['}', ';']) ||
  882. (this._output.just_added_newline() && !(in_array(this._flags.last_token.text, ['(', '[', '{', ':', '=', ',']) || this._flags.last_token.type === TOKEN.OPERATOR))) {
  883. // make sure there is a nice clean space of at least one blank line
  884. // before a new function definition
  885. if (!this._output.just_added_blankline() && !current_token.comments_before) {
  886. this.print_newline();
  887. this.print_newline(true);
  888. }
  889. }
  890. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD) {
  891. if (reserved_array(this._flags.last_token, ['get', 'set', 'new', 'export']) ||
  892. reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  893. this._output.space_before_token = true;
  894. } else if (reserved_word(this._flags.last_token, 'default') && this._last_last_text === 'export') {
  895. this._output.space_before_token = true;
  896. } else if (this._flags.last_token.text === 'declare') {
  897. // accomodates Typescript declare function formatting
  898. this._output.space_before_token = true;
  899. } else {
  900. this.print_newline();
  901. }
  902. } else if (this._flags.last_token.type === TOKEN.OPERATOR || this._flags.last_token.text === '=') {
  903. // foo = function
  904. this._output.space_before_token = true;
  905. } else if (!this._flags.multiline_frame && (is_expression(this._flags.mode) || is_array(this._flags.mode))) {
  906. // (function
  907. } else {
  908. this.print_newline();
  909. }
  910. this.print_token(current_token);
  911. this._flags.last_word = current_token.text;
  912. return;
  913. }
  914. var prefix = 'NONE';
  915. if (this._flags.last_token.type === TOKEN.END_BLOCK) {
  916. if (this._previous_flags.inline_frame) {
  917. prefix = 'SPACE';
  918. } else if (!reserved_array(current_token, ['else', 'catch', 'finally', 'from'])) {
  919. prefix = 'NEWLINE';
  920. } else {
  921. if (this._options.brace_style === "expand" ||
  922. this._options.brace_style === "end-expand" ||
  923. (this._options.brace_style === "none" && current_token.newlines)) {
  924. prefix = 'NEWLINE';
  925. } else {
  926. prefix = 'SPACE';
  927. this._output.space_before_token = true;
  928. }
  929. }
  930. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && this._flags.mode === MODE.BlockStatement) {
  931. // TODO: Should this be for STATEMENT as well?
  932. prefix = 'NEWLINE';
  933. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && is_expression(this._flags.mode)) {
  934. prefix = 'SPACE';
  935. } else if (this._flags.last_token.type === TOKEN.STRING) {
  936. prefix = 'NEWLINE';
  937. } else if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD ||
  938. (this._flags.last_token.text === '*' &&
  939. (in_array(this._last_last_text, ['function', 'yield']) ||
  940. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  941. prefix = 'SPACE';
  942. } else if (this._flags.last_token.type === TOKEN.START_BLOCK) {
  943. if (this._flags.inline_frame) {
  944. prefix = 'SPACE';
  945. } else {
  946. prefix = 'NEWLINE';
  947. }
  948. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  949. this._output.space_before_token = true;
  950. prefix = 'NEWLINE';
  951. }
  952. if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  953. if (this._flags.inline_frame || this._flags.last_token.text === 'else' || this._flags.last_token.text === 'export') {
  954. prefix = 'SPACE';
  955. } else {
  956. prefix = 'NEWLINE';
  957. }
  958. }
  959. if (reserved_array(current_token, ['else', 'catch', 'finally'])) {
  960. if ((!(this._flags.last_token.type === TOKEN.END_BLOCK && this._previous_flags.mode === MODE.BlockStatement) ||
  961. this._options.brace_style === "expand" ||
  962. this._options.brace_style === "end-expand" ||
  963. (this._options.brace_style === "none" && current_token.newlines)) &&
  964. !this._flags.inline_frame) {
  965. this.print_newline();
  966. } else {
  967. this._output.trim(true);
  968. var line = this._output.current_line;
  969. // If we trimmed and there's something other than a close block before us
  970. // put a newline back in. Handles '} // comment' scenario.
  971. if (line.last() !== '}') {
  972. this.print_newline();
  973. }
  974. this._output.space_before_token = true;
  975. }
  976. } else if (prefix === 'NEWLINE') {
  977. if (reserved_array(this._flags.last_token, special_words)) {
  978. // no newline between 'return nnn'
  979. this._output.space_before_token = true;
  980. } else if (this._flags.last_token.text === 'declare' && reserved_array(current_token, ['var', 'let', 'const'])) {
  981. // accomodates Typescript declare formatting
  982. this._output.space_before_token = true;
  983. } else if (this._flags.last_token.type !== TOKEN.END_EXPR) {
  984. if ((this._flags.last_token.type !== TOKEN.START_EXPR || !reserved_array(current_token, ['var', 'let', 'const'])) && this._flags.last_token.text !== ':') {
  985. // no need to force newline on 'var': for (var x = 0...)
  986. if (reserved_word(current_token, 'if') && reserved_word(current_token.previous, 'else')) {
  987. // no newline for } else if {
  988. this._output.space_before_token = true;
  989. } else {
  990. this.print_newline();
  991. }
  992. }
  993. } else if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  994. this.print_newline();
  995. }
  996. } else if (this._flags.multiline_frame && is_array(this._flags.mode) && this._flags.last_token.text === ',' && this._last_last_text === '}') {
  997. this.print_newline(); // }, in lists get a newline treatment
  998. } else if (prefix === 'SPACE') {
  999. this._output.space_before_token = true;
  1000. }
  1001. if (current_token.previous && (current_token.previous.type === TOKEN.WORD || current_token.previous.type === TOKEN.RESERVED)) {
  1002. this._output.space_before_token = true;
  1003. }
  1004. this.print_token(current_token);
  1005. this._flags.last_word = current_token.text;
  1006. if (current_token.type === TOKEN.RESERVED) {
  1007. if (current_token.text === 'do') {
  1008. this._flags.do_block = true;
  1009. } else if (current_token.text === 'if') {
  1010. this._flags.if_block = true;
  1011. } else if (current_token.text === 'import') {
  1012. this._flags.import_block = true;
  1013. } else if (this._flags.import_block && reserved_word(current_token, 'from')) {
  1014. this._flags.import_block = false;
  1015. }
  1016. }
  1017. };
  1018. Beautifier.prototype.handle_semicolon = function(current_token) {
  1019. if (this.start_of_statement(current_token)) {
  1020. // The conditional starts the statement if appropriate.
  1021. // Semicolon can be the start (and end) of a statement
  1022. this._output.space_before_token = false;
  1023. } else {
  1024. this.handle_whitespace_and_comments(current_token);
  1025. }
  1026. var next_token = this._tokens.peek();
  1027. while (this._flags.mode === MODE.Statement &&
  1028. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  1029. !this._flags.do_block) {
  1030. this.restore_mode();
  1031. }
  1032. // hacky but effective for the moment
  1033. if (this._flags.import_block) {
  1034. this._flags.import_block = false;
  1035. }
  1036. this.print_token(current_token);
  1037. };
  1038. Beautifier.prototype.handle_string = function(current_token) {
  1039. if (current_token.text.startsWith("`") && current_token.newlines === 0 && current_token.whitespace_before === '' && (current_token.previous.text === ')' || this._flags.last_token.type === TOKEN.WORD)) {
  1040. //Conditional for detectign backtick strings
  1041. } else if (this.start_of_statement(current_token)) {
  1042. // The conditional starts the statement if appropriate.
  1043. // One difference - strings want at least a space before
  1044. this._output.space_before_token = true;
  1045. } else {
  1046. this.handle_whitespace_and_comments(current_token);
  1047. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD || this._flags.inline_frame) {
  1048. this._output.space_before_token = true;
  1049. } 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) {
  1050. if (!this.start_of_object_property()) {
  1051. this.allow_wrap_or_preserved_newline(current_token);
  1052. }
  1053. } else if ((current_token.text.startsWith("`") && this._flags.last_token.type === TOKEN.END_EXPR && (current_token.previous.text === ']' || current_token.previous.text === ')') && current_token.newlines === 0)) {
  1054. this._output.space_before_token = true;
  1055. } else {
  1056. this.print_newline();
  1057. }
  1058. }
  1059. this.print_token(current_token);
  1060. };
  1061. Beautifier.prototype.handle_equals = function(current_token) {
  1062. if (this.start_of_statement(current_token)) {
  1063. // The conditional starts the statement if appropriate.
  1064. } else {
  1065. this.handle_whitespace_and_comments(current_token);
  1066. }
  1067. if (this._flags.declaration_statement) {
  1068. // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
  1069. this._flags.declaration_assignment = true;
  1070. }
  1071. this._output.space_before_token = true;
  1072. this.print_token(current_token);
  1073. this._output.space_before_token = true;
  1074. };
  1075. Beautifier.prototype.handle_comma = function(current_token) {
  1076. this.handle_whitespace_and_comments(current_token, true);
  1077. this.print_token(current_token);
  1078. this._output.space_before_token = true;
  1079. if (this._flags.declaration_statement) {
  1080. if (is_expression(this._flags.parent.mode)) {
  1081. // do not break on comma, for(var a = 1, b = 2)
  1082. this._flags.declaration_assignment = false;
  1083. }
  1084. if (this._flags.declaration_assignment) {
  1085. this._flags.declaration_assignment = false;
  1086. this.print_newline(false, true);
  1087. } else if (this._options.comma_first) {
  1088. // for comma-first, we want to allow a newline before the comma
  1089. // to turn into a newline after the comma, which we will fixup later
  1090. this.allow_wrap_or_preserved_newline(current_token);
  1091. }
  1092. } else if (this._flags.mode === MODE.ObjectLiteral ||
  1093. (this._flags.mode === MODE.Statement && this._flags.parent.mode === MODE.ObjectLiteral)) {
  1094. if (this._flags.mode === MODE.Statement) {
  1095. this.restore_mode();
  1096. }
  1097. if (!this._flags.inline_frame) {
  1098. this.print_newline();
  1099. }
  1100. } else if (this._options.comma_first) {
  1101. // EXPR or DO_BLOCK
  1102. // for comma-first, we want to allow a newline before the comma
  1103. // to turn into a newline after the comma, which we will fixup later
  1104. this.allow_wrap_or_preserved_newline(current_token);
  1105. }
  1106. };
  1107. Beautifier.prototype.handle_operator = function(current_token) {
  1108. var isGeneratorAsterisk = current_token.text === '*' &&
  1109. (reserved_array(this._flags.last_token, ['function', 'yield']) ||
  1110. (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.COMMA, TOKEN.END_BLOCK, TOKEN.SEMICOLON]))
  1111. );
  1112. var isUnary = in_array(current_token.text, ['-', '+']) && (
  1113. in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.START_EXPR, TOKEN.EQUALS, TOKEN.OPERATOR]) ||
  1114. in_array(this._flags.last_token.text, line_starters) ||
  1115. this._flags.last_token.text === ','
  1116. );
  1117. if (this.start_of_statement(current_token)) {
  1118. // The conditional starts the statement if appropriate.
  1119. } else {
  1120. var preserve_statement_flags = !isGeneratorAsterisk;
  1121. this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
  1122. }
  1123. if (reserved_array(this._flags.last_token, special_words)) {
  1124. // "return" had a special handling in TK_WORD. Now we need to return the favor
  1125. this._output.space_before_token = true;
  1126. this.print_token(current_token);
  1127. return;
  1128. }
  1129. // hack for actionscript's import .*;
  1130. if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
  1131. this.print_token(current_token);
  1132. return;
  1133. }
  1134. if (current_token.text === '::') {
  1135. // no spaces around exotic namespacing syntax operator
  1136. this.print_token(current_token);
  1137. return;
  1138. }
  1139. // Allow line wrapping between operators when operator_position is
  1140. // set to before or preserve
  1141. if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
  1142. this.allow_wrap_or_preserved_newline(current_token);
  1143. }
  1144. if (current_token.text === ':' && this._flags.in_case) {
  1145. this.print_token(current_token);
  1146. this._flags.in_case = false;
  1147. this._flags.case_body = true;
  1148. if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
  1149. this.indent();
  1150. this.print_newline();
  1151. } else {
  1152. this._output.space_before_token = true;
  1153. }
  1154. return;
  1155. }
  1156. var space_before = true;
  1157. var space_after = true;
  1158. var in_ternary = false;
  1159. if (current_token.text === ':') {
  1160. if (this._flags.ternary_depth === 0) {
  1161. // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
  1162. space_before = false;
  1163. } else {
  1164. this._flags.ternary_depth -= 1;
  1165. in_ternary = true;
  1166. }
  1167. } else if (current_token.text === '?') {
  1168. this._flags.ternary_depth += 1;
  1169. }
  1170. // let's handle the operator_position option prior to any conflicting logic
  1171. if (!isUnary && !isGeneratorAsterisk && this._options.preserve_newlines && in_array(current_token.text, positionable_operators)) {
  1172. var isColon = current_token.text === ':';
  1173. var isTernaryColon = (isColon && in_ternary);
  1174. var isOtherColon = (isColon && !in_ternary);
  1175. switch (this._options.operator_position) {
  1176. case OPERATOR_POSITION.before_newline:
  1177. // if the current token is : and it's not a ternary statement then we set space_before to false
  1178. this._output.space_before_token = !isOtherColon;
  1179. this.print_token(current_token);
  1180. if (!isColon || isTernaryColon) {
  1181. this.allow_wrap_or_preserved_newline(current_token);
  1182. }
  1183. this._output.space_before_token = true;
  1184. return;
  1185. case OPERATOR_POSITION.after_newline:
  1186. // if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement,
  1187. // then print a newline.
  1188. this._output.space_before_token = true;
  1189. if (!isColon || isTernaryColon) {
  1190. if (this._tokens.peek().newlines) {
  1191. this.print_newline(false, true);
  1192. } else {
  1193. this.allow_wrap_or_preserved_newline(current_token);
  1194. }
  1195. } else {
  1196. this._output.space_before_token = false;
  1197. }
  1198. this.print_token(current_token);
  1199. this._output.space_before_token = true;
  1200. return;
  1201. case OPERATOR_POSITION.preserve_newline:
  1202. if (!isOtherColon) {
  1203. this.allow_wrap_or_preserved_newline(current_token);
  1204. }
  1205. // if we just added a newline, or the current token is : and it's not a ternary statement,
  1206. // then we set space_before to false
  1207. space_before = !(this._output.just_added_newline() || isOtherColon);
  1208. this._output.space_before_token = space_before;
  1209. this.print_token(current_token);
  1210. this._output.space_before_token = true;
  1211. return;
  1212. }
  1213. }
  1214. if (isGeneratorAsterisk) {
  1215. this.allow_wrap_or_preserved_newline(current_token);
  1216. space_before = false;
  1217. var next_token = this._tokens.peek();
  1218. space_after = next_token && in_array(next_token.type, [TOKEN.WORD, TOKEN.RESERVED]);
  1219. } else if (current_token.text === '...') {
  1220. this.allow_wrap_or_preserved_newline(current_token);
  1221. space_before = this._flags.last_token.type === TOKEN.START_BLOCK;
  1222. space_after = false;
  1223. } else if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
  1224. // unary operators (and binary +/- pretending to be unary) special cases
  1225. if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR) {
  1226. this.allow_wrap_or_preserved_newline(current_token);
  1227. }
  1228. space_before = false;
  1229. space_after = false;
  1230. // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
  1231. // if there is a newline between -- or ++ and anything else we should preserve it.
  1232. if (current_token.newlines && (current_token.text === '--' || current_token.text === '++')) {
  1233. this.print_newline(false, true);
  1234. }
  1235. if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
  1236. // for (;; ++i)
  1237. // ^^^
  1238. space_before = true;
  1239. }
  1240. if (this._flags.last_token.type === TOKEN.RESERVED) {
  1241. space_before = true;
  1242. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  1243. space_before = !(this._flags.last_token.text === ']' && (current_token.text === '--' || current_token.text === '++'));
  1244. } else if (this._flags.last_token.type === TOKEN.OPERATOR) {
  1245. // a++ + ++b;
  1246. // a - -b
  1247. space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(this._flags.last_token.text, ['--', '-', '++', '+']);
  1248. // + and - are not unary when preceeded by -- or ++ operator
  1249. // a-- + b
  1250. // a * +b
  1251. // a - -b
  1252. if (in_array(current_token.text, ['+', '-']) && in_array(this._flags.last_token.text, ['--', '++'])) {
  1253. space_after = true;
  1254. }
  1255. }
  1256. if (((this._flags.mode === MODE.BlockStatement && !this._flags.inline_frame) || this._flags.mode === MODE.Statement) &&
  1257. (this._flags.last_token.text === '{' || this._flags.last_token.text === ';')) {
  1258. // { foo; --i }
  1259. // foo(); --bar;
  1260. this.print_newline();
  1261. }
  1262. }
  1263. this._output.space_before_token = this._output.space_before_token || space_before;
  1264. this.print_token(current_token);
  1265. this._output.space_before_token = space_after;
  1266. };
  1267. Beautifier.prototype.handle_block_comment = function(current_token, preserve_statement_flags) {
  1268. if (this._output.raw) {
  1269. this._output.add_raw_token(current_token);
  1270. if (current_token.directives && current_token.directives.preserve === 'end') {
  1271. // If we're testing the raw output behavior, do not allow a directive to turn it off.
  1272. this._output.raw = this._options.test_output_raw;
  1273. }
  1274. return;
  1275. }
  1276. if (current_token.directives) {
  1277. this.print_newline(false, preserve_statement_flags);
  1278. this.print_token(current_token);
  1279. if (current_token.directives.preserve === 'start') {
  1280. this._output.raw = true;
  1281. }
  1282. this.print_newline(false, true);
  1283. return;
  1284. }
  1285. // inline block
  1286. if (!acorn.newline.test(current_token.text) && !current_token.newlines) {
  1287. this._output.space_before_token = true;
  1288. this.print_token(current_token);
  1289. this._output.space_before_token = true;
  1290. return;
  1291. } else {
  1292. this.print_block_commment(current_token, preserve_statement_flags);
  1293. }
  1294. };
  1295. Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) {
  1296. var lines = split_linebreaks(current_token.text);
  1297. var j; // iterator for this case
  1298. var javadoc = false;
  1299. var starless = false;
  1300. var lastIndent = current_token.whitespace_before;
  1301. var lastIndentLength = lastIndent.length;
  1302. // block comment starts with a new line
  1303. this.print_newline(false, preserve_statement_flags);
  1304. // first line always indented
  1305. this.print_token_line_indentation(current_token);
  1306. this._output.add_token(lines[0]);
  1307. this.print_newline(false, preserve_statement_flags);
  1308. if (lines.length > 1) {
  1309. lines = lines.slice(1);
  1310. javadoc = all_lines_start_with(lines, '*');
  1311. starless = each_line_matches_indent(lines, lastIndent);
  1312. if (javadoc) {
  1313. this._flags.alignment = 1;
  1314. }
  1315. for (j = 0; j < lines.length; j++) {
  1316. if (javadoc) {
  1317. // javadoc: reformat and re-indent
  1318. this.print_token_line_indentation(current_token);
  1319. this._output.add_token(ltrim(lines[j]));
  1320. } else if (starless && lines[j]) {
  1321. // starless: re-indent non-empty content, avoiding trim
  1322. this.print_token_line_indentation(current_token);
  1323. this._output.add_token(lines[j].substring(lastIndentLength));
  1324. } else {
  1325. // normal comments output raw
  1326. this._output.current_line.set_indent(-1);
  1327. this._output.add_token(lines[j]);
  1328. }
  1329. // for comments on their own line or more than one line, make sure there's a new line after
  1330. this.print_newline(false, preserve_statement_flags);
  1331. }
  1332. this._flags.alignment = 0;
  1333. }
  1334. };
  1335. Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
  1336. if (current_token.newlines) {
  1337. this.print_newline(false, preserve_statement_flags);
  1338. } else {
  1339. this._output.trim(true);
  1340. }
  1341. this._output.space_before_token = true;
  1342. this.print_token(current_token);
  1343. this.print_newline(false, preserve_statement_flags);
  1344. };
  1345. Beautifier.prototype.handle_dot = function(current_token) {
  1346. if (this.start_of_statement(current_token)) {
  1347. // The conditional starts the statement if appropriate.
  1348. } else {
  1349. this.handle_whitespace_and_comments(current_token, true);
  1350. }
  1351. if (reserved_array(this._flags.last_token, special_words)) {
  1352. this._output.space_before_token = false;
  1353. } else {
  1354. // allow preserved newlines before dots in general
  1355. // force newlines on dots after close paren when break_chained - for bar().baz()
  1356. this.allow_wrap_or_preserved_newline(current_token,
  1357. this._flags.last_token.text === ')' && this._options.break_chained_methods);
  1358. }
  1359. // Only unindent chained method dot if this dot starts a new line.
  1360. // Otherwise the automatic extra indentation removal will handle the over indent
  1361. if (this._options.unindent_chained_methods && this._output.just_added_newline()) {
  1362. this.deindent();
  1363. }
  1364. this.print_token(current_token);
  1365. };
  1366. Beautifier.prototype.handle_unknown = function(current_token, preserve_statement_flags) {
  1367. this.print_token(current_token);
  1368. if (current_token.text[current_token.text.length - 1] === '\n') {
  1369. this.print_newline(false, preserve_statement_flags);
  1370. }
  1371. };
  1372. Beautifier.prototype.handle_eof = function(current_token) {
  1373. // Unwind any open statements
  1374. while (this._flags.mode === MODE.Statement) {
  1375. this.restore_mode();
  1376. }
  1377. this.handle_whitespace_and_comments(current_token);
  1378. };
  1379. module.exports.Beautifier = Beautifier;
  1380. /***/ }),
  1381. /* 2 */
  1382. /***/ (function(module) {
  1383. /*jshint node:true */
  1384. /*
  1385. The MIT License (MIT)
  1386. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1387. Permission is hereby granted, free of charge, to any person
  1388. obtaining a copy of this software and associated documentation files
  1389. (the "Software"), to deal in the Software without restriction,
  1390. including without limitation the rights to use, copy, modify, merge,
  1391. publish, distribute, sublicense, and/or sell copies of the Software,
  1392. and to permit persons to whom the Software is furnished to do so,
  1393. subject to the following conditions:
  1394. The above copyright notice and this permission notice shall be
  1395. included in all copies or substantial portions of the Software.
  1396. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1397. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1398. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1399. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1400. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1401. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1402. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1403. SOFTWARE.
  1404. */
  1405. function OutputLine(parent) {
  1406. this.__parent = parent;
  1407. this.__character_count = 0;
  1408. // use indent_count as a marker for this.__lines that have preserved indentation
  1409. this.__indent_count = -1;
  1410. this.__alignment_count = 0;
  1411. this.__wrap_point_index = 0;
  1412. this.__wrap_point_character_count = 0;
  1413. this.__wrap_point_indent_count = -1;
  1414. this.__wrap_point_alignment_count = 0;
  1415. this.__items = [];
  1416. }
  1417. OutputLine.prototype.clone_empty = function() {
  1418. var line = new OutputLine(this.__parent);
  1419. line.set_indent(this.__indent_count, this.__alignment_count);
  1420. return line;
  1421. };
  1422. OutputLine.prototype.item = function(index) {
  1423. if (index < 0) {
  1424. return this.__items[this.__items.length + index];
  1425. } else {
  1426. return this.__items[index];
  1427. }
  1428. };
  1429. OutputLine.prototype.has_match = function(pattern) {
  1430. for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
  1431. if (this.__items[lastCheckedOutput].match(pattern)) {
  1432. return true;
  1433. }
  1434. }
  1435. return false;
  1436. };
  1437. OutputLine.prototype.set_indent = function(indent, alignment) {
  1438. if (this.is_empty()) {
  1439. this.__indent_count = indent || 0;
  1440. this.__alignment_count = alignment || 0;
  1441. this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
  1442. }
  1443. };
  1444. OutputLine.prototype._set_wrap_point = function() {
  1445. if (this.__parent.wrap_line_length) {
  1446. this.__wrap_point_index = this.__items.length;
  1447. this.__wrap_point_character_count = this.__character_count;
  1448. this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
  1449. this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
  1450. }
  1451. };
  1452. OutputLine.prototype._should_wrap = function() {
  1453. return this.__wrap_point_index &&
  1454. this.__character_count > this.__parent.wrap_line_length &&
  1455. this.__wrap_point_character_count > this.__parent.next_line.__character_count;
  1456. };
  1457. OutputLine.prototype._allow_wrap = function() {
  1458. if (this._should_wrap()) {
  1459. this.__parent.add_new_line();
  1460. var next = this.__parent.current_line;
  1461. next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
  1462. next.__items = this.__items.slice(this.__wrap_point_index);
  1463. this.__items = this.__items.slice(0, this.__wrap_point_index);
  1464. next.__character_count += this.__character_count - this.__wrap_point_character_count;
  1465. this.__character_count = this.__wrap_point_character_count;
  1466. if (next.__items[0] === " ") {
  1467. next.__items.splice(0, 1);
  1468. next.__character_count -= 1;
  1469. }
  1470. return true;
  1471. }
  1472. return false;
  1473. };
  1474. OutputLine.prototype.is_empty = function() {
  1475. return this.__items.length === 0;
  1476. };
  1477. OutputLine.prototype.last = function() {
  1478. if (!this.is_empty()) {
  1479. return this.__items[this.__items.length - 1];
  1480. } else {
  1481. return null;
  1482. }
  1483. };
  1484. OutputLine.prototype.push = function(item) {
  1485. this.__items.push(item);
  1486. var last_newline_index = item.lastIndexOf('\n');
  1487. if (last_newline_index !== -1) {
  1488. this.__character_count = item.length - last_newline_index;
  1489. } else {
  1490. this.__character_count += item.length;
  1491. }
  1492. };
  1493. OutputLine.prototype.pop = function() {
  1494. var item = null;
  1495. if (!this.is_empty()) {
  1496. item = this.__items.pop();
  1497. this.__character_count -= item.length;
  1498. }
  1499. return item;
  1500. };
  1501. OutputLine.prototype._remove_indent = function() {
  1502. if (this.__indent_count > 0) {
  1503. this.__indent_count -= 1;
  1504. this.__character_count -= this.__parent.indent_size;
  1505. }
  1506. };
  1507. OutputLine.prototype._remove_wrap_indent = function() {
  1508. if (this.__wrap_point_indent_count > 0) {
  1509. this.__wrap_point_indent_count -= 1;
  1510. }
  1511. };
  1512. OutputLine.prototype.trim = function() {
  1513. while (this.last() === ' ') {
  1514. this.__items.pop();
  1515. this.__character_count -= 1;
  1516. }
  1517. };
  1518. OutputLine.prototype.toString = function() {
  1519. var result = '';
  1520. if (this.is_empty()) {
  1521. if (this.__parent.indent_empty_lines) {
  1522. result = this.__parent.get_indent_string(this.__indent_count);
  1523. }
  1524. } else {
  1525. result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
  1526. result += this.__items.join('');
  1527. }
  1528. return result;
  1529. };
  1530. function IndentStringCache(options, baseIndentString) {
  1531. this.__cache = [''];
  1532. this.__indent_size = options.indent_size;
  1533. this.__indent_string = options.indent_char;
  1534. if (!options.indent_with_tabs) {
  1535. this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
  1536. }
  1537. // Set to null to continue support for auto detection of base indent
  1538. baseIndentString = baseIndentString || '';
  1539. if (options.indent_level > 0) {
  1540. baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
  1541. }
  1542. this.__base_string = baseIndentString;
  1543. this.__base_string_length = baseIndentString.length;
  1544. }
  1545. IndentStringCache.prototype.get_indent_size = function(indent, column) {
  1546. var result = this.__base_string_length;
  1547. column = column || 0;
  1548. if (indent < 0) {
  1549. result = 0;
  1550. }
  1551. result += indent * this.__indent_size;
  1552. result += column;
  1553. return result;
  1554. };
  1555. IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
  1556. var result = this.__base_string;
  1557. column = column || 0;
  1558. if (indent_level < 0) {
  1559. indent_level = 0;
  1560. result = '';
  1561. }
  1562. column += indent_level * this.__indent_size;
  1563. this.__ensure_cache(column);
  1564. result += this.__cache[column];
  1565. return result;
  1566. };
  1567. IndentStringCache.prototype.__ensure_cache = function(column) {
  1568. while (column >= this.__cache.length) {
  1569. this.__add_column();
  1570. }
  1571. };
  1572. IndentStringCache.prototype.__add_column = function() {
  1573. var column = this.__cache.length;
  1574. var indent = 0;
  1575. var result = '';
  1576. if (this.__indent_size && column >= this.__indent_size) {
  1577. indent = Math.floor(column / this.__indent_size);
  1578. column -= indent * this.__indent_size;
  1579. result = new Array(indent + 1).join(this.__indent_string);
  1580. }
  1581. if (column) {
  1582. result += new Array(column + 1).join(' ');
  1583. }
  1584. this.__cache.push(result);
  1585. };
  1586. function Output(options, baseIndentString) {
  1587. this.__indent_cache = new IndentStringCache(options, baseIndentString);
  1588. this.raw = false;
  1589. this._end_with_newline = options.end_with_newline;
  1590. this.indent_size = options.indent_size;
  1591. this.wrap_line_length = options.wrap_line_length;
  1592. this.indent_empty_lines = options.indent_empty_lines;
  1593. this.__lines = [];
  1594. this.previous_line = null;
  1595. this.current_line = null;
  1596. this.next_line = new OutputLine(this);
  1597. this.space_before_token = false;
  1598. this.non_breaking_space = false;
  1599. this.previous_token_wrapped = false;
  1600. // initialize
  1601. this.__add_outputline();
  1602. }
  1603. Output.prototype.__add_outputline = function() {
  1604. this.previous_line = this.current_line;
  1605. this.current_line = this.next_line.clone_empty();
  1606. this.__lines.push(this.current_line);
  1607. };
  1608. Output.prototype.get_line_number = function() {
  1609. return this.__lines.length;
  1610. };
  1611. Output.prototype.get_indent_string = function(indent, column) {
  1612. return this.__indent_cache.get_indent_string(indent, column);
  1613. };
  1614. Output.prototype.get_indent_size = function(indent, column) {
  1615. return this.__indent_cache.get_indent_size(indent, column);
  1616. };
  1617. Output.prototype.is_empty = function() {
  1618. return !this.previous_line && this.current_line.is_empty();
  1619. };
  1620. Output.prototype.add_new_line = function(force_newline) {
  1621. // never newline at the start of file
  1622. // otherwise, newline only if we didn't just add one or we're forced
  1623. if (this.is_empty() ||
  1624. (!force_newline && this.just_added_newline())) {
  1625. return false;
  1626. }
  1627. // if raw output is enabled, don't print additional newlines,
  1628. // but still return True as though you had
  1629. if (!this.raw) {
  1630. this.__add_outputline();
  1631. }
  1632. return true;
  1633. };
  1634. Output.prototype.get_code = function(eol) {
  1635. this.trim(true);
  1636. // handle some edge cases where the last tokens
  1637. // has text that ends with newline(s)
  1638. var last_item = this.current_line.pop();
  1639. if (last_item) {
  1640. if (last_item[last_item.length - 1] === '\n') {
  1641. last_item = last_item.replace(/\n+$/g, '');
  1642. }
  1643. this.current_line.push(last_item);
  1644. }
  1645. if (this._end_with_newline) {
  1646. this.__add_outputline();
  1647. }
  1648. var sweet_code = this.__lines.join('\n');
  1649. if (eol !== '\n') {
  1650. sweet_code = sweet_code.replace(/[\n]/g, eol);
  1651. }
  1652. return sweet_code;
  1653. };
  1654. Output.prototype.set_wrap_point = function() {
  1655. this.current_line._set_wrap_point();
  1656. };
  1657. Output.prototype.set_indent = function(indent, alignment) {
  1658. indent = indent || 0;
  1659. alignment = alignment || 0;
  1660. // Next line stores alignment values
  1661. this.next_line.set_indent(indent, alignment);
  1662. // Never indent your first output indent at the start of the file
  1663. if (this.__lines.length > 1) {
  1664. this.current_line.set_indent(indent, alignment);
  1665. return true;
  1666. }
  1667. this.current_line.set_indent();
  1668. return false;
  1669. };
  1670. Output.prototype.add_raw_token = function(token) {
  1671. for (var x = 0; x < token.newlines; x++) {
  1672. this.__add_outputline();
  1673. }
  1674. this.current_line.set_indent(-1);
  1675. this.current_line.push(token.whitespace_before);
  1676. this.current_line.push(token.text);
  1677. this.space_before_token = false;
  1678. this.non_breaking_space = false;
  1679. this.previous_token_wrapped = false;
  1680. };
  1681. Output.prototype.add_token = function(printable_token) {
  1682. this.__add_space_before_token();
  1683. this.current_line.push(printable_token);
  1684. this.space_before_token = false;
  1685. this.non_breaking_space = false;
  1686. this.previous_token_wrapped = this.current_line._allow_wrap();
  1687. };
  1688. Output.prototype.__add_space_before_token = function() {
  1689. if (this.space_before_token && !this.just_added_newline()) {
  1690. if (!this.non_breaking_space) {
  1691. this.set_wrap_point();
  1692. }
  1693. this.current_line.push(' ');
  1694. }
  1695. };
  1696. Output.prototype.remove_indent = function(index) {
  1697. var output_length = this.__lines.length;
  1698. while (index < output_length) {
  1699. this.__lines[index]._remove_indent();
  1700. index++;
  1701. }
  1702. this.current_line._remove_wrap_indent();
  1703. };
  1704. Output.prototype.trim = function(eat_newlines) {
  1705. eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
  1706. this.current_line.trim();
  1707. while (eat_newlines && this.__lines.length > 1 &&
  1708. this.current_line.is_empty()) {
  1709. this.__lines.pop();
  1710. this.current_line = this.__lines[this.__lines.length - 1];
  1711. this.current_line.trim();
  1712. }
  1713. this.previous_line = this.__lines.length > 1 ?
  1714. this.__lines[this.__lines.length - 2] : null;
  1715. };
  1716. Output.prototype.just_added_newline = function() {
  1717. return this.current_line.is_empty();
  1718. };
  1719. Output.prototype.just_added_blankline = function() {
  1720. return this.is_empty() ||
  1721. (this.current_line.is_empty() && this.previous_line.is_empty());
  1722. };
  1723. Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
  1724. var index = this.__lines.length - 2;
  1725. while (index >= 0) {
  1726. var potentialEmptyLine = this.__lines[index];
  1727. if (potentialEmptyLine.is_empty()) {
  1728. break;
  1729. } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
  1730. potentialEmptyLine.item(-1) !== ends_with) {
  1731. this.__lines.splice(index + 1, 0, new OutputLine(this));
  1732. this.previous_line = this.__lines[this.__lines.length - 2];
  1733. break;
  1734. }
  1735. index--;
  1736. }
  1737. };
  1738. module.exports.Output = Output;
  1739. /***/ }),
  1740. /* 3 */
  1741. /***/ (function(module) {
  1742. /*jshint node:true */
  1743. /*
  1744. The MIT License (MIT)
  1745. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1746. Permission is hereby granted, free of charge, to any person
  1747. obtaining a copy of this software and associated documentation files
  1748. (the "Software"), to deal in the Software without restriction,
  1749. including without limitation the rights to use, copy, modify, merge,
  1750. publish, distribute, sublicense, and/or sell copies of the Software,
  1751. and to permit persons to whom the Software is furnished to do so,
  1752. subject to the following conditions:
  1753. The above copyright notice and this permission notice shall be
  1754. included in all copies or substantial portions of the Software.
  1755. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1756. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1757. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1758. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1759. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1760. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1761. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1762. SOFTWARE.
  1763. */
  1764. function Token(type, text, newlines, whitespace_before) {
  1765. this.type = type;
  1766. this.text = text;
  1767. // comments_before are
  1768. // comments that have a new line before them
  1769. // and may or may not have a newline after
  1770. // this is a set of comments before
  1771. this.comments_before = null; /* inline comment*/
  1772. // this.comments_after = new TokenStream(); // no new line before and newline after
  1773. this.newlines = newlines || 0;
  1774. this.whitespace_before = whitespace_before || '';
  1775. this.parent = null;
  1776. this.next = null;
  1777. this.previous = null;
  1778. this.opened = null;
  1779. this.closed = null;
  1780. this.directives = null;
  1781. }
  1782. module.exports.Token = Token;
  1783. /***/ }),
  1784. /* 4 */
  1785. /***/ (function(__unused_webpack_module, exports) {
  1786. /* jshint node: true, curly: false */
  1787. // Parts of this section of code is taken from acorn.
  1788. //
  1789. // Acorn was written by Marijn Haverbeke and released under an MIT
  1790. // license. The Unicode regexps (for identifiers and whitespace) were
  1791. // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
  1792. //
  1793. // Git repositories for Acorn are available at
  1794. //
  1795. // http://marijnhaverbeke.nl/git/acorn
  1796. // https://github.com/marijnh/acorn.git
  1797. // ## Character categories
  1798. // acorn used char codes to squeeze the last bit of performance out
  1799. // Beautifier is okay without that, so we're using regex
  1800. // permit # (23), $ (36), and @ (64). @ is used in ES7 decorators.
  1801. // 65 through 91 are uppercase letters.
  1802. // permit _ (95).
  1803. // 97 through 123 are lowercase letters.
  1804. var baseASCIIidentifierStartChars = "\\x23\\x24\\x40\\x41-\\x5a\\x5f\\x61-\\x7a";
  1805. // inside an identifier @ is not allowed but 0-9 are.
  1806. var baseASCIIidentifierChars = "\\x24\\x30-\\x39\\x41-\\x5a\\x5f\\x61-\\x7a";
  1807. // Big ugly regular expressions that match characters in the
  1808. // whitespace, identifier, and identifier-start categories. These
  1809. // are only applied when a character is found to actually have a
  1810. // code point above 128.
  1811. 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";
  1812. 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";
  1813. //var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1814. //var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1815. var identifierStart = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
  1816. var identifierChars = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
  1817. exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
  1818. exports.identifierStart = new RegExp(identifierStart);
  1819. exports.identifierMatch = new RegExp("(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
  1820. var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line
  1821. // Whether a single character denotes a newline.
  1822. exports.newline = /[\n\r\u2028\u2029]/;
  1823. // Matches a whole line break (where CRLF is considered a single
  1824. // line break). Used to count lines.
  1825. // in javascript, these two differ
  1826. // in python they are the same, different methods are called on them
  1827. exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
  1828. exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
  1829. /***/ }),
  1830. /* 5 */
  1831. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1832. /*jshint node:true */
  1833. /*
  1834. The MIT License (MIT)
  1835. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1836. Permission is hereby granted, free of charge, to any person
  1837. obtaining a copy of this software and associated documentation files
  1838. (the "Software"), to deal in the Software without restriction,
  1839. including without limitation the rights to use, copy, modify, merge,
  1840. publish, distribute, sublicense, and/or sell copies of the Software,
  1841. and to permit persons to whom the Software is furnished to do so,
  1842. subject to the following conditions:
  1843. The above copyright notice and this permission notice shall be
  1844. included in all copies or substantial portions of the Software.
  1845. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1846. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1847. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1848. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1849. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1850. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1851. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1852. SOFTWARE.
  1853. */
  1854. var BaseOptions = __webpack_require__(6).Options;
  1855. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  1856. function Options(options) {
  1857. BaseOptions.call(this, options, 'js');
  1858. // compatibility, re
  1859. var raw_brace_style = this.raw_options.brace_style || null;
  1860. if (raw_brace_style === "expand-strict") { //graceful handling of deprecated option
  1861. this.raw_options.brace_style = "expand";
  1862. } else if (raw_brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
  1863. this.raw_options.brace_style = "collapse,preserve-inline";
  1864. } else if (this.raw_options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
  1865. this.raw_options.brace_style = this.raw_options.braces_on_own_line ? "expand" : "collapse";
  1866. // } else if (!raw_brace_style) { //Nothing exists to set it
  1867. // raw_brace_style = "collapse";
  1868. }
  1869. //preserve-inline in delimited string will trigger brace_preserve_inline, everything
  1870. //else is considered a brace_style and the last one only will have an effect
  1871. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  1872. this.brace_preserve_inline = false; //Defaults in case one or other was not specified in meta-option
  1873. this.brace_style = "collapse";
  1874. for (var bs = 0; bs < brace_style_split.length; bs++) {
  1875. if (brace_style_split[bs] === "preserve-inline") {
  1876. this.brace_preserve_inline = true;
  1877. } else {
  1878. this.brace_style = brace_style_split[bs];
  1879. }
  1880. }
  1881. this.unindent_chained_methods = this._get_boolean('unindent_chained_methods');
  1882. this.break_chained_methods = this._get_boolean('break_chained_methods');
  1883. this.space_in_paren = this._get_boolean('space_in_paren');
  1884. this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
  1885. this.jslint_happy = this._get_boolean('jslint_happy');
  1886. this.space_after_anon_function = this._get_boolean('space_after_anon_function');
  1887. this.space_after_named_function = this._get_boolean('space_after_named_function');
  1888. this.keep_array_indentation = this._get_boolean('keep_array_indentation');
  1889. this.space_before_conditional = this._get_boolean('space_before_conditional', true);
  1890. this.unescape_strings = this._get_boolean('unescape_strings');
  1891. this.e4x = this._get_boolean('e4x');
  1892. this.comma_first = this._get_boolean('comma_first');
  1893. this.operator_position = this._get_selection('operator_position', validPositionValues);
  1894. // For testing of beautify preserve:start directive
  1895. this.test_output_raw = this._get_boolean('test_output_raw');
  1896. // force this._options.space_after_anon_function to true if this._options.jslint_happy
  1897. if (this.jslint_happy) {
  1898. this.space_after_anon_function = true;
  1899. }
  1900. }
  1901. Options.prototype = new BaseOptions();
  1902. module.exports.Options = Options;
  1903. /***/ }),
  1904. /* 6 */
  1905. /***/ (function(module) {
  1906. /*jshint node:true */
  1907. /*
  1908. The MIT License (MIT)
  1909. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  1910. Permission is hereby granted, free of charge, to any person
  1911. obtaining a copy of this software and associated documentation files
  1912. (the "Software"), to deal in the Software without restriction,
  1913. including without limitation the rights to use, copy, modify, merge,
  1914. publish, distribute, sublicense, and/or sell copies of the Software,
  1915. and to permit persons to whom the Software is furnished to do so,
  1916. subject to the following conditions:
  1917. The above copyright notice and this permission notice shall be
  1918. included in all copies or substantial portions of the Software.
  1919. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  1920. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1921. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  1922. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  1923. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  1924. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1925. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1926. SOFTWARE.
  1927. */
  1928. function Options(options, merge_child_field) {
  1929. this.raw_options = _mergeOpts(options, merge_child_field);
  1930. // Support passing the source text back with no change
  1931. this.disabled = this._get_boolean('disabled');
  1932. this.eol = this._get_characters('eol', 'auto');
  1933. this.end_with_newline = this._get_boolean('end_with_newline');
  1934. this.indent_size = this._get_number('indent_size', 4);
  1935. this.indent_char = this._get_characters('indent_char', ' ');
  1936. this.indent_level = this._get_number('indent_level');
  1937. this.preserve_newlines = this._get_boolean('preserve_newlines', true);
  1938. this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
  1939. if (!this.preserve_newlines) {
  1940. this.max_preserve_newlines = 0;
  1941. }
  1942. this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
  1943. if (this.indent_with_tabs) {
  1944. this.indent_char = '\t';
  1945. // indent_size behavior changed after 1.8.6
  1946. // It used to be that indent_size would be
  1947. // set to 1 for indent_with_tabs. That is no longer needed and
  1948. // actually doesn't make sense - why not use spaces? Further,
  1949. // that might produce unexpected behavior - tabs being used
  1950. // for single-column alignment. So, when indent_with_tabs is true
  1951. // and indent_size is 1, reset indent_size to 4.
  1952. if (this.indent_size === 1) {
  1953. this.indent_size = 4;
  1954. }
  1955. }
  1956. // Backwards compat with 1.3.x
  1957. this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
  1958. this.indent_empty_lines = this._get_boolean('indent_empty_lines');
  1959. // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty']
  1960. // For now, 'auto' = all off for javascript, all on for html (and inline javascript).
  1961. // other values ignored
  1962. this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
  1963. }
  1964. Options.prototype._get_array = function(name, default_value) {
  1965. var option_value = this.raw_options[name];
  1966. var result = default_value || [];
  1967. if (typeof option_value === 'object') {
  1968. if (option_value !== null && typeof option_value.concat === 'function') {
  1969. result = option_value.concat();
  1970. }
  1971. } else if (typeof option_value === 'string') {
  1972. result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
  1973. }
  1974. return result;
  1975. };
  1976. Options.prototype._get_boolean = function(name, default_value) {
  1977. var option_value = this.raw_options[name];
  1978. var result = option_value === undefined ? !!default_value : !!option_value;
  1979. return result;
  1980. };
  1981. Options.prototype._get_characters = function(name, default_value) {
  1982. var option_value = this.raw_options[name];
  1983. var result = default_value || '';
  1984. if (typeof option_value === 'string') {
  1985. result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
  1986. }
  1987. return result;
  1988. };
  1989. Options.prototype._get_number = function(name, default_value) {
  1990. var option_value = this.raw_options[name];
  1991. default_value = parseInt(default_value, 10);
  1992. if (isNaN(default_value)) {
  1993. default_value = 0;
  1994. }
  1995. var result = parseInt(option_value, 10);
  1996. if (isNaN(result)) {
  1997. result = default_value;
  1998. }
  1999. return result;
  2000. };
  2001. Options.prototype._get_selection = function(name, selection_list, default_value) {
  2002. var result = this._get_selection_list(name, selection_list, default_value);
  2003. if (result.length !== 1) {
  2004. throw new Error(
  2005. "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
  2006. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2007. }
  2008. return result[0];
  2009. };
  2010. Options.prototype._get_selection_list = function(name, selection_list, default_value) {
  2011. if (!selection_list || selection_list.length === 0) {
  2012. throw new Error("Selection list cannot be empty.");
  2013. }
  2014. default_value = default_value || [selection_list[0]];
  2015. if (!this._is_valid_selection(default_value, selection_list)) {
  2016. throw new Error("Invalid Default Value!");
  2017. }
  2018. var result = this._get_array(name, default_value);
  2019. if (!this._is_valid_selection(result, selection_list)) {
  2020. throw new Error(
  2021. "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
  2022. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2023. }
  2024. return result;
  2025. };
  2026. Options.prototype._is_valid_selection = function(result, selection_list) {
  2027. return result.length && selection_list.length &&
  2028. !result.some(function(item) { return selection_list.indexOf(item) === -1; });
  2029. };
  2030. // merges child options up with the parent options object
  2031. // Example: obj = {a: 1, b: {a: 2}}
  2032. // mergeOpts(obj, 'b')
  2033. //
  2034. // Returns: {a: 2}
  2035. function _mergeOpts(allOptions, childFieldName) {
  2036. var finalOpts = {};
  2037. allOptions = _normalizeOpts(allOptions);
  2038. var name;
  2039. for (name in allOptions) {
  2040. if (name !== childFieldName) {
  2041. finalOpts[name] = allOptions[name];
  2042. }
  2043. }
  2044. //merge in the per type settings for the childFieldName
  2045. if (childFieldName && allOptions[childFieldName]) {
  2046. for (name in allOptions[childFieldName]) {
  2047. finalOpts[name] = allOptions[childFieldName][name];
  2048. }
  2049. }
  2050. return finalOpts;
  2051. }
  2052. function _normalizeOpts(options) {
  2053. var convertedOpts = {};
  2054. var key;
  2055. for (key in options) {
  2056. var newKey = key.replace(/-/g, "_");
  2057. convertedOpts[newKey] = options[key];
  2058. }
  2059. return convertedOpts;
  2060. }
  2061. module.exports.Options = Options;
  2062. module.exports.normalizeOpts = _normalizeOpts;
  2063. module.exports.mergeOpts = _mergeOpts;
  2064. /***/ }),
  2065. /* 7 */
  2066. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2067. /*jshint node:true */
  2068. /*
  2069. The MIT License (MIT)
  2070. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2071. Permission is hereby granted, free of charge, to any person
  2072. obtaining a copy of this software and associated documentation files
  2073. (the "Software"), to deal in the Software without restriction,
  2074. including without limitation the rights to use, copy, modify, merge,
  2075. publish, distribute, sublicense, and/or sell copies of the Software,
  2076. and to permit persons to whom the Software is furnished to do so,
  2077. subject to the following conditions:
  2078. The above copyright notice and this permission notice shall be
  2079. included in all copies or substantial portions of the Software.
  2080. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2081. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2082. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2083. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2084. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2085. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2086. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2087. SOFTWARE.
  2088. */
  2089. var InputScanner = __webpack_require__(8).InputScanner;
  2090. var BaseTokenizer = __webpack_require__(9).Tokenizer;
  2091. var BASETOKEN = __webpack_require__(9).TOKEN;
  2092. var Directives = __webpack_require__(13).Directives;
  2093. var acorn = __webpack_require__(4);
  2094. var Pattern = __webpack_require__(12).Pattern;
  2095. var TemplatablePattern = __webpack_require__(14).TemplatablePattern;
  2096. function in_array(what, arr) {
  2097. return arr.indexOf(what) !== -1;
  2098. }
  2099. var TOKEN = {
  2100. START_EXPR: 'TK_START_EXPR',
  2101. END_EXPR: 'TK_END_EXPR',
  2102. START_BLOCK: 'TK_START_BLOCK',
  2103. END_BLOCK: 'TK_END_BLOCK',
  2104. WORD: 'TK_WORD',
  2105. RESERVED: 'TK_RESERVED',
  2106. SEMICOLON: 'TK_SEMICOLON',
  2107. STRING: 'TK_STRING',
  2108. EQUALS: 'TK_EQUALS',
  2109. OPERATOR: 'TK_OPERATOR',
  2110. COMMA: 'TK_COMMA',
  2111. BLOCK_COMMENT: 'TK_BLOCK_COMMENT',
  2112. COMMENT: 'TK_COMMENT',
  2113. DOT: 'TK_DOT',
  2114. UNKNOWN: 'TK_UNKNOWN',
  2115. START: BASETOKEN.START,
  2116. RAW: BASETOKEN.RAW,
  2117. EOF: BASETOKEN.EOF
  2118. };
  2119. var directives_core = new Directives(/\/\*/, /\*\//);
  2120. var number_pattern = /0[xX][0123456789abcdefABCDEF_]*n?|0[oO][01234567_]*n?|0[bB][01_]*n?|\d[\d_]*n|(?:\.\d[\d_]*|\d[\d_]*\.?[\d_]*)(?:[eE][+-]?[\d_]+)?/;
  2121. var digit = /[0-9]/;
  2122. // Dot "." must be distinguished from "..." and decimal
  2123. var dot_pattern = /[^\d\.]/;
  2124. var positionable_operators = (
  2125. ">>> === !== " +
  2126. "<< && >= ** != == <= >> || ?? |> " +
  2127. "< / - + > : & % ? ^ | *").split(' ');
  2128. // IMPORTANT: this must be sorted longest to shortest or tokenizing many not work.
  2129. // Also, you must update possitionable operators separately from punct
  2130. var punct =
  2131. ">>>= " +
  2132. "... >>= <<= === >>> !== **= " +
  2133. "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
  2134. "= ! ? > < : / ^ - + * & % ~ |";
  2135. punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
  2136. // ?. but not if followed by a number
  2137. punct = '\\?\\.(?!\\d) ' + punct;
  2138. punct = punct.replace(/ /g, '|');
  2139. var punct_pattern = new RegExp(punct);
  2140. // words which should always start on new line.
  2141. var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
  2142. var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as']);
  2143. var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');
  2144. // var template_pattern = /(?:(?:<\?php|<\?=)[\s\S]*?\?>)|(?:<%[\s\S]*?%>)/g;
  2145. var in_html_comment;
  2146. var Tokenizer = function(input_string, options) {
  2147. BaseTokenizer.call(this, input_string, options);
  2148. this._patterns.whitespace = this._patterns.whitespace.matching(
  2149. /\u00A0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff/.source,
  2150. /\u2028\u2029/.source);
  2151. var pattern_reader = new Pattern(this._input);
  2152. var templatable = new TemplatablePattern(this._input)
  2153. .read_options(this._options);
  2154. this.__patterns = {
  2155. template: templatable,
  2156. identifier: templatable.starting_with(acorn.identifier).matching(acorn.identifierMatch),
  2157. number: pattern_reader.matching(number_pattern),
  2158. punct: pattern_reader.matching(punct_pattern),
  2159. // comment ends just before nearest linefeed or end of file
  2160. comment: pattern_reader.starting_with(/\/\//).until(/[\n\r\u2028\u2029]/),
  2161. // /* ... */ comment ends with nearest */ or end of file
  2162. block_comment: pattern_reader.starting_with(/\/\*/).until_after(/\*\//),
  2163. html_comment_start: pattern_reader.matching(/<!--/),
  2164. html_comment_end: pattern_reader.matching(/-->/),
  2165. include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
  2166. shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
  2167. xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[\s\S]+?}|!\[CDATA\[[\s\S]*?\]\]|)(\s+{[\s\S]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{[\s\S]+?}))*\s*(\/?)\s*>/),
  2168. single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
  2169. double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
  2170. template_text: templatable.until(/[`\\$]/),
  2171. template_expression: templatable.until(/[`}\\]/)
  2172. };
  2173. };
  2174. Tokenizer.prototype = new BaseTokenizer();
  2175. Tokenizer.prototype._is_comment = function(current_token) {
  2176. return current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.BLOCK_COMMENT || current_token.type === TOKEN.UNKNOWN;
  2177. };
  2178. Tokenizer.prototype._is_opening = function(current_token) {
  2179. return current_token.type === TOKEN.START_BLOCK || current_token.type === TOKEN.START_EXPR;
  2180. };
  2181. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  2182. return (current_token.type === TOKEN.END_BLOCK || current_token.type === TOKEN.END_EXPR) &&
  2183. (open_token && (
  2184. (current_token.text === ']' && open_token.text === '[') ||
  2185. (current_token.text === ')' && open_token.text === '(') ||
  2186. (current_token.text === '}' && open_token.text === '{')));
  2187. };
  2188. Tokenizer.prototype._reset = function() {
  2189. in_html_comment = false;
  2190. };
  2191. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2192. var token = null;
  2193. this._readWhitespace();
  2194. var c = this._input.peek();
  2195. if (c === null) {
  2196. return this._create_token(TOKEN.EOF, '');
  2197. }
  2198. token = token || this._read_non_javascript(c);
  2199. token = token || this._read_string(c);
  2200. token = token || this._read_word(previous_token);
  2201. token = token || this._read_singles(c);
  2202. token = token || this._read_comment(c);
  2203. token = token || this._read_regexp(c, previous_token);
  2204. token = token || this._read_xml(c, previous_token);
  2205. token = token || this._read_punctuation();
  2206. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  2207. return token;
  2208. };
  2209. Tokenizer.prototype._read_word = function(previous_token) {
  2210. var resulting_string;
  2211. resulting_string = this.__patterns.identifier.read();
  2212. if (resulting_string !== '') {
  2213. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  2214. if (!(previous_token.type === TOKEN.DOT ||
  2215. (previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
  2216. reserved_word_pattern.test(resulting_string)) {
  2217. if (resulting_string === 'in' || resulting_string === 'of') { // hack for 'in' and 'of' operators
  2218. return this._create_token(TOKEN.OPERATOR, resulting_string);
  2219. }
  2220. return this._create_token(TOKEN.RESERVED, resulting_string);
  2221. }
  2222. return this._create_token(TOKEN.WORD, resulting_string);
  2223. }
  2224. resulting_string = this.__patterns.number.read();
  2225. if (resulting_string !== '') {
  2226. return this._create_token(TOKEN.WORD, resulting_string);
  2227. }
  2228. };
  2229. Tokenizer.prototype._read_singles = function(c) {
  2230. var token = null;
  2231. if (c === '(' || c === '[') {
  2232. token = this._create_token(TOKEN.START_EXPR, c);
  2233. } else if (c === ')' || c === ']') {
  2234. token = this._create_token(TOKEN.END_EXPR, c);
  2235. } else if (c === '{') {
  2236. token = this._create_token(TOKEN.START_BLOCK, c);
  2237. } else if (c === '}') {
  2238. token = this._create_token(TOKEN.END_BLOCK, c);
  2239. } else if (c === ';') {
  2240. token = this._create_token(TOKEN.SEMICOLON, c);
  2241. } else if (c === '.' && dot_pattern.test(this._input.peek(1))) {
  2242. token = this._create_token(TOKEN.DOT, c);
  2243. } else if (c === ',') {
  2244. token = this._create_token(TOKEN.COMMA, c);
  2245. }
  2246. if (token) {
  2247. this._input.next();
  2248. }
  2249. return token;
  2250. };
  2251. Tokenizer.prototype._read_punctuation = function() {
  2252. var resulting_string = this.__patterns.punct.read();
  2253. if (resulting_string !== '') {
  2254. if (resulting_string === '=') {
  2255. return this._create_token(TOKEN.EQUALS, resulting_string);
  2256. } else if (resulting_string === '?.') {
  2257. return this._create_token(TOKEN.DOT, resulting_string);
  2258. } else {
  2259. return this._create_token(TOKEN.OPERATOR, resulting_string);
  2260. }
  2261. }
  2262. };
  2263. Tokenizer.prototype._read_non_javascript = function(c) {
  2264. var resulting_string = '';
  2265. if (c === '#') {
  2266. if (this._is_first_token()) {
  2267. resulting_string = this.__patterns.shebang.read();
  2268. if (resulting_string) {
  2269. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  2270. }
  2271. }
  2272. // handles extendscript #includes
  2273. resulting_string = this.__patterns.include.read();
  2274. if (resulting_string) {
  2275. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  2276. }
  2277. c = this._input.next();
  2278. // Spidermonkey-specific sharp variables for circular references. Considered obsolete.
  2279. var sharp = '#';
  2280. if (this._input.hasNext() && this._input.testChar(digit)) {
  2281. do {
  2282. c = this._input.next();
  2283. sharp += c;
  2284. } while (this._input.hasNext() && c !== '#' && c !== '=');
  2285. if (c === '#') {
  2286. //
  2287. } else if (this._input.peek() === '[' && this._input.peek(1) === ']') {
  2288. sharp += '[]';
  2289. this._input.next();
  2290. this._input.next();
  2291. } else if (this._input.peek() === '{' && this._input.peek(1) === '}') {
  2292. sharp += '{}';
  2293. this._input.next();
  2294. this._input.next();
  2295. }
  2296. return this._create_token(TOKEN.WORD, sharp);
  2297. }
  2298. this._input.back();
  2299. } else if (c === '<' && this._is_first_token()) {
  2300. resulting_string = this.__patterns.html_comment_start.read();
  2301. if (resulting_string) {
  2302. while (this._input.hasNext() && !this._input.testChar(acorn.newline)) {
  2303. resulting_string += this._input.next();
  2304. }
  2305. in_html_comment = true;
  2306. return this._create_token(TOKEN.COMMENT, resulting_string);
  2307. }
  2308. } else if (in_html_comment && c === '-') {
  2309. resulting_string = this.__patterns.html_comment_end.read();
  2310. if (resulting_string) {
  2311. in_html_comment = false;
  2312. return this._create_token(TOKEN.COMMENT, resulting_string);
  2313. }
  2314. }
  2315. return null;
  2316. };
  2317. Tokenizer.prototype._read_comment = function(c) {
  2318. var token = null;
  2319. if (c === '/') {
  2320. var comment = '';
  2321. if (this._input.peek(1) === '*') {
  2322. // peek for comment /* ... */
  2323. comment = this.__patterns.block_comment.read();
  2324. var directives = directives_core.get_directives(comment);
  2325. if (directives && directives.ignore === 'start') {
  2326. comment += directives_core.readIgnored(this._input);
  2327. }
  2328. comment = comment.replace(acorn.allLineBreaks, '\n');
  2329. token = this._create_token(TOKEN.BLOCK_COMMENT, comment);
  2330. token.directives = directives;
  2331. } else if (this._input.peek(1) === '/') {
  2332. // peek for comment // ...
  2333. comment = this.__patterns.comment.read();
  2334. token = this._create_token(TOKEN.COMMENT, comment);
  2335. }
  2336. }
  2337. return token;
  2338. };
  2339. Tokenizer.prototype._read_string = function(c) {
  2340. if (c === '`' || c === "'" || c === '"') {
  2341. var resulting_string = this._input.next();
  2342. this.has_char_escapes = false;
  2343. if (c === '`') {
  2344. resulting_string += this._read_string_recursive('`', true, '${');
  2345. } else {
  2346. resulting_string += this._read_string_recursive(c);
  2347. }
  2348. if (this.has_char_escapes && this._options.unescape_strings) {
  2349. resulting_string = unescape_string(resulting_string);
  2350. }
  2351. if (this._input.peek() === c) {
  2352. resulting_string += this._input.next();
  2353. }
  2354. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  2355. return this._create_token(TOKEN.STRING, resulting_string);
  2356. }
  2357. return null;
  2358. };
  2359. Tokenizer.prototype._allow_regexp_or_xml = function(previous_token) {
  2360. // regex and xml can only appear in specific locations during parsing
  2361. return (previous_token.type === TOKEN.RESERVED && in_array(previous_token.text, ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
  2362. (previous_token.type === TOKEN.END_EXPR && previous_token.text === ')' &&
  2363. previous_token.opened.previous.type === TOKEN.RESERVED && in_array(previous_token.opened.previous.text, ['if', 'while', 'for'])) ||
  2364. (in_array(previous_token.type, [TOKEN.COMMENT, TOKEN.START_EXPR, TOKEN.START_BLOCK, TOKEN.START,
  2365. TOKEN.END_BLOCK, TOKEN.OPERATOR, TOKEN.EQUALS, TOKEN.EOF, TOKEN.SEMICOLON, TOKEN.COMMA
  2366. ]));
  2367. };
  2368. Tokenizer.prototype._read_regexp = function(c, previous_token) {
  2369. if (c === '/' && this._allow_regexp_or_xml(previous_token)) {
  2370. // handle regexp
  2371. //
  2372. var resulting_string = this._input.next();
  2373. var esc = false;
  2374. var in_char_class = false;
  2375. while (this._input.hasNext() &&
  2376. ((esc || in_char_class || this._input.peek() !== c) &&
  2377. !this._input.testChar(acorn.newline))) {
  2378. resulting_string += this._input.peek();
  2379. if (!esc) {
  2380. esc = this._input.peek() === '\\';
  2381. if (this._input.peek() === '[') {
  2382. in_char_class = true;
  2383. } else if (this._input.peek() === ']') {
  2384. in_char_class = false;
  2385. }
  2386. } else {
  2387. esc = false;
  2388. }
  2389. this._input.next();
  2390. }
  2391. if (this._input.peek() === c) {
  2392. resulting_string += this._input.next();
  2393. // regexps may have modifiers /regexp/MOD , so fetch those, too
  2394. // Only [gim] are valid, but if the user puts in garbage, do what we can to take it.
  2395. resulting_string += this._input.read(acorn.identifier);
  2396. }
  2397. return this._create_token(TOKEN.STRING, resulting_string);
  2398. }
  2399. return null;
  2400. };
  2401. Tokenizer.prototype._read_xml = function(c, previous_token) {
  2402. if (this._options.e4x && c === "<" && this._allow_regexp_or_xml(previous_token)) {
  2403. var xmlStr = '';
  2404. var match = this.__patterns.xml.read_match();
  2405. // handle e4x xml literals
  2406. //
  2407. if (match) {
  2408. // Trim root tag to attempt to
  2409. var rootTag = match[2].replace(/^{\s+/, '{').replace(/\s+}$/, '}');
  2410. var isCurlyRoot = rootTag.indexOf('{') === 0;
  2411. var depth = 0;
  2412. while (match) {
  2413. var isEndTag = !!match[1];
  2414. var tagName = match[2];
  2415. var isSingletonTag = (!!match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
  2416. if (!isSingletonTag &&
  2417. (tagName === rootTag || (isCurlyRoot && tagName.replace(/^{\s+/, '{').replace(/\s+}$/, '}')))) {
  2418. if (isEndTag) {
  2419. --depth;
  2420. } else {
  2421. ++depth;
  2422. }
  2423. }
  2424. xmlStr += match[0];
  2425. if (depth <= 0) {
  2426. break;
  2427. }
  2428. match = this.__patterns.xml.read_match();
  2429. }
  2430. // if we didn't close correctly, keep unformatted.
  2431. if (!match) {
  2432. xmlStr += this._input.match(/[\s\S]*/g)[0];
  2433. }
  2434. xmlStr = xmlStr.replace(acorn.allLineBreaks, '\n');
  2435. return this._create_token(TOKEN.STRING, xmlStr);
  2436. }
  2437. }
  2438. return null;
  2439. };
  2440. function unescape_string(s) {
  2441. // You think that a regex would work for this
  2442. // return s.replace(/\\x([0-9a-f]{2})/gi, function(match, val) {
  2443. // return String.fromCharCode(parseInt(val, 16));
  2444. // })
  2445. // However, dealing with '\xff', '\\xff', '\\\xff' makes this more fun.
  2446. var out = '',
  2447. escaped = 0;
  2448. var input_scan = new InputScanner(s);
  2449. var matched = null;
  2450. while (input_scan.hasNext()) {
  2451. // Keep any whitespace, non-slash characters
  2452. // also keep slash pairs.
  2453. matched = input_scan.match(/([\s]|[^\\]|\\\\)+/g);
  2454. if (matched) {
  2455. out += matched[0];
  2456. }
  2457. if (input_scan.peek() === '\\') {
  2458. input_scan.next();
  2459. if (input_scan.peek() === 'x') {
  2460. matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
  2461. } else if (input_scan.peek() === 'u') {
  2462. matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
  2463. } else {
  2464. out += '\\';
  2465. if (input_scan.hasNext()) {
  2466. out += input_scan.next();
  2467. }
  2468. continue;
  2469. }
  2470. // If there's some error decoding, return the original string
  2471. if (!matched) {
  2472. return s;
  2473. }
  2474. escaped = parseInt(matched[1], 16);
  2475. if (escaped > 0x7e && escaped <= 0xff && matched[0].indexOf('x') === 0) {
  2476. // we bail out on \x7f..\xff,
  2477. // leaving whole string escaped,
  2478. // as it's probably completely binary
  2479. return s;
  2480. } else if (escaped >= 0x00 && escaped < 0x20) {
  2481. // leave 0x00...0x1f escaped
  2482. out += '\\' + matched[0];
  2483. continue;
  2484. } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
  2485. // single-quote, apostrophe, backslash - escape these
  2486. out += '\\' + String.fromCharCode(escaped);
  2487. } else {
  2488. out += String.fromCharCode(escaped);
  2489. }
  2490. }
  2491. }
  2492. return out;
  2493. }
  2494. // handle string
  2495. //
  2496. Tokenizer.prototype._read_string_recursive = function(delimiter, allow_unescaped_newlines, start_sub) {
  2497. var current_char;
  2498. var pattern;
  2499. if (delimiter === '\'') {
  2500. pattern = this.__patterns.single_quote;
  2501. } else if (delimiter === '"') {
  2502. pattern = this.__patterns.double_quote;
  2503. } else if (delimiter === '`') {
  2504. pattern = this.__patterns.template_text;
  2505. } else if (delimiter === '}') {
  2506. pattern = this.__patterns.template_expression;
  2507. }
  2508. var resulting_string = pattern.read();
  2509. var next = '';
  2510. while (this._input.hasNext()) {
  2511. next = this._input.next();
  2512. if (next === delimiter ||
  2513. (!allow_unescaped_newlines && acorn.newline.test(next))) {
  2514. this._input.back();
  2515. break;
  2516. } else if (next === '\\' && this._input.hasNext()) {
  2517. current_char = this._input.peek();
  2518. if (current_char === 'x' || current_char === 'u') {
  2519. this.has_char_escapes = true;
  2520. } else if (current_char === '\r' && this._input.peek(1) === '\n') {
  2521. this._input.next();
  2522. }
  2523. next += this._input.next();
  2524. } else if (start_sub) {
  2525. if (start_sub === '${' && next === '$' && this._input.peek() === '{') {
  2526. next += this._input.next();
  2527. }
  2528. if (start_sub === next) {
  2529. if (delimiter === '`') {
  2530. next += this._read_string_recursive('}', allow_unescaped_newlines, '`');
  2531. } else {
  2532. next += this._read_string_recursive('`', allow_unescaped_newlines, '${');
  2533. }
  2534. if (this._input.hasNext()) {
  2535. next += this._input.next();
  2536. }
  2537. }
  2538. }
  2539. next += pattern.read();
  2540. resulting_string += next;
  2541. }
  2542. return resulting_string;
  2543. };
  2544. module.exports.Tokenizer = Tokenizer;
  2545. module.exports.TOKEN = TOKEN;
  2546. module.exports.positionable_operators = positionable_operators.slice();
  2547. module.exports.line_starters = line_starters.slice();
  2548. /***/ }),
  2549. /* 8 */
  2550. /***/ (function(module) {
  2551. /*jshint node:true */
  2552. /*
  2553. The MIT License (MIT)
  2554. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2555. Permission is hereby granted, free of charge, to any person
  2556. obtaining a copy of this software and associated documentation files
  2557. (the "Software"), to deal in the Software without restriction,
  2558. including without limitation the rights to use, copy, modify, merge,
  2559. publish, distribute, sublicense, and/or sell copies of the Software,
  2560. and to permit persons to whom the Software is furnished to do so,
  2561. subject to the following conditions:
  2562. The above copyright notice and this permission notice shall be
  2563. included in all copies or substantial portions of the Software.
  2564. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2565. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2566. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2567. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2568. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2569. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2570. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2571. SOFTWARE.
  2572. */
  2573. var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
  2574. function InputScanner(input_string) {
  2575. this.__input = input_string || '';
  2576. this.__input_length = this.__input.length;
  2577. this.__position = 0;
  2578. }
  2579. InputScanner.prototype.restart = function() {
  2580. this.__position = 0;
  2581. };
  2582. InputScanner.prototype.back = function() {
  2583. if (this.__position > 0) {
  2584. this.__position -= 1;
  2585. }
  2586. };
  2587. InputScanner.prototype.hasNext = function() {
  2588. return this.__position < this.__input_length;
  2589. };
  2590. InputScanner.prototype.next = function() {
  2591. var val = null;
  2592. if (this.hasNext()) {
  2593. val = this.__input.charAt(this.__position);
  2594. this.__position += 1;
  2595. }
  2596. return val;
  2597. };
  2598. InputScanner.prototype.peek = function(index) {
  2599. var val = null;
  2600. index = index || 0;
  2601. index += this.__position;
  2602. if (index >= 0 && index < this.__input_length) {
  2603. val = this.__input.charAt(index);
  2604. }
  2605. return val;
  2606. };
  2607. // This is a JavaScript only helper function (not in python)
  2608. // Javascript doesn't have a match method
  2609. // and not all implementation support "sticky" flag.
  2610. // If they do not support sticky then both this.match() and this.test() method
  2611. // must get the match and check the index of the match.
  2612. // If sticky is supported and set, this method will use it.
  2613. // Otherwise it will check that global is set, and fall back to the slower method.
  2614. InputScanner.prototype.__match = function(pattern, index) {
  2615. pattern.lastIndex = index;
  2616. var pattern_match = pattern.exec(this.__input);
  2617. if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
  2618. if (pattern_match.index !== index) {
  2619. pattern_match = null;
  2620. }
  2621. }
  2622. return pattern_match;
  2623. };
  2624. InputScanner.prototype.test = function(pattern, index) {
  2625. index = index || 0;
  2626. index += this.__position;
  2627. if (index >= 0 && index < this.__input_length) {
  2628. return !!this.__match(pattern, index);
  2629. } else {
  2630. return false;
  2631. }
  2632. };
  2633. InputScanner.prototype.testChar = function(pattern, index) {
  2634. // test one character regex match
  2635. var val = this.peek(index);
  2636. pattern.lastIndex = 0;
  2637. return val !== null && pattern.test(val);
  2638. };
  2639. InputScanner.prototype.match = function(pattern) {
  2640. var pattern_match = this.__match(pattern, this.__position);
  2641. if (pattern_match) {
  2642. this.__position += pattern_match[0].length;
  2643. } else {
  2644. pattern_match = null;
  2645. }
  2646. return pattern_match;
  2647. };
  2648. InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
  2649. var val = '';
  2650. var match;
  2651. if (starting_pattern) {
  2652. match = this.match(starting_pattern);
  2653. if (match) {
  2654. val += match[0];
  2655. }
  2656. }
  2657. if (until_pattern && (match || !starting_pattern)) {
  2658. val += this.readUntil(until_pattern, until_after);
  2659. }
  2660. return val;
  2661. };
  2662. InputScanner.prototype.readUntil = function(pattern, until_after) {
  2663. var val = '';
  2664. var match_index = this.__position;
  2665. pattern.lastIndex = this.__position;
  2666. var pattern_match = pattern.exec(this.__input);
  2667. if (pattern_match) {
  2668. match_index = pattern_match.index;
  2669. if (until_after) {
  2670. match_index += pattern_match[0].length;
  2671. }
  2672. } else {
  2673. match_index = this.__input_length;
  2674. }
  2675. val = this.__input.substring(this.__position, match_index);
  2676. this.__position = match_index;
  2677. return val;
  2678. };
  2679. InputScanner.prototype.readUntilAfter = function(pattern) {
  2680. return this.readUntil(pattern, true);
  2681. };
  2682. InputScanner.prototype.get_regexp = function(pattern, match_from) {
  2683. var result = null;
  2684. var flags = 'g';
  2685. if (match_from && regexp_has_sticky) {
  2686. flags = 'y';
  2687. }
  2688. // strings are converted to regexp
  2689. if (typeof pattern === "string" && pattern !== '') {
  2690. // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
  2691. result = new RegExp(pattern, flags);
  2692. } else if (pattern) {
  2693. result = new RegExp(pattern.source, flags);
  2694. }
  2695. return result;
  2696. };
  2697. InputScanner.prototype.get_literal_regexp = function(literal_string) {
  2698. return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  2699. };
  2700. /* css beautifier legacy helpers */
  2701. InputScanner.prototype.peekUntilAfter = function(pattern) {
  2702. var start = this.__position;
  2703. var val = this.readUntilAfter(pattern);
  2704. this.__position = start;
  2705. return val;
  2706. };
  2707. InputScanner.prototype.lookBack = function(testVal) {
  2708. var start = this.__position - 1;
  2709. return start >= testVal.length && this.__input.substring(start - testVal.length, start)
  2710. .toLowerCase() === testVal;
  2711. };
  2712. module.exports.InputScanner = InputScanner;
  2713. /***/ }),
  2714. /* 9 */
  2715. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2716. /*jshint node:true */
  2717. /*
  2718. The MIT License (MIT)
  2719. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2720. Permission is hereby granted, free of charge, to any person
  2721. obtaining a copy of this software and associated documentation files
  2722. (the "Software"), to deal in the Software without restriction,
  2723. including without limitation the rights to use, copy, modify, merge,
  2724. publish, distribute, sublicense, and/or sell copies of the Software,
  2725. and to permit persons to whom the Software is furnished to do so,
  2726. subject to the following conditions:
  2727. The above copyright notice and this permission notice shall be
  2728. included in all copies or substantial portions of the Software.
  2729. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2730. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2731. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2732. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2733. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2734. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2735. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2736. SOFTWARE.
  2737. */
  2738. var InputScanner = __webpack_require__(8).InputScanner;
  2739. var Token = __webpack_require__(3).Token;
  2740. var TokenStream = __webpack_require__(10).TokenStream;
  2741. var WhitespacePattern = __webpack_require__(11).WhitespacePattern;
  2742. var TOKEN = {
  2743. START: 'TK_START',
  2744. RAW: 'TK_RAW',
  2745. EOF: 'TK_EOF'
  2746. };
  2747. var Tokenizer = function(input_string, options) {
  2748. this._input = new InputScanner(input_string);
  2749. this._options = options || {};
  2750. this.__tokens = null;
  2751. this._patterns = {};
  2752. this._patterns.whitespace = new WhitespacePattern(this._input);
  2753. };
  2754. Tokenizer.prototype.tokenize = function() {
  2755. this._input.restart();
  2756. this.__tokens = new TokenStream();
  2757. this._reset();
  2758. var current;
  2759. var previous = new Token(TOKEN.START, '');
  2760. var open_token = null;
  2761. var open_stack = [];
  2762. var comments = new TokenStream();
  2763. while (previous.type !== TOKEN.EOF) {
  2764. current = this._get_next_token(previous, open_token);
  2765. while (this._is_comment(current)) {
  2766. comments.add(current);
  2767. current = this._get_next_token(previous, open_token);
  2768. }
  2769. if (!comments.isEmpty()) {
  2770. current.comments_before = comments;
  2771. comments = new TokenStream();
  2772. }
  2773. current.parent = open_token;
  2774. if (this._is_opening(current)) {
  2775. open_stack.push(open_token);
  2776. open_token = current;
  2777. } else if (open_token && this._is_closing(current, open_token)) {
  2778. current.opened = open_token;
  2779. open_token.closed = current;
  2780. open_token = open_stack.pop();
  2781. current.parent = open_token;
  2782. }
  2783. current.previous = previous;
  2784. previous.next = current;
  2785. this.__tokens.add(current);
  2786. previous = current;
  2787. }
  2788. return this.__tokens;
  2789. };
  2790. Tokenizer.prototype._is_first_token = function() {
  2791. return this.__tokens.isEmpty();
  2792. };
  2793. Tokenizer.prototype._reset = function() {};
  2794. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2795. this._readWhitespace();
  2796. var resulting_string = this._input.read(/.+/g);
  2797. if (resulting_string) {
  2798. return this._create_token(TOKEN.RAW, resulting_string);
  2799. } else {
  2800. return this._create_token(TOKEN.EOF, '');
  2801. }
  2802. };
  2803. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  2804. return false;
  2805. };
  2806. Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
  2807. return false;
  2808. };
  2809. Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
  2810. return false;
  2811. };
  2812. Tokenizer.prototype._create_token = function(type, text) {
  2813. var token = new Token(type, text,
  2814. this._patterns.whitespace.newline_count,
  2815. this._patterns.whitespace.whitespace_before_token);
  2816. return token;
  2817. };
  2818. Tokenizer.prototype._readWhitespace = function() {
  2819. return this._patterns.whitespace.read();
  2820. };
  2821. module.exports.Tokenizer = Tokenizer;
  2822. module.exports.TOKEN = TOKEN;
  2823. /***/ }),
  2824. /* 10 */
  2825. /***/ (function(module) {
  2826. /*jshint node:true */
  2827. /*
  2828. The MIT License (MIT)
  2829. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2830. Permission is hereby granted, free of charge, to any person
  2831. obtaining a copy of this software and associated documentation files
  2832. (the "Software"), to deal in the Software without restriction,
  2833. including without limitation the rights to use, copy, modify, merge,
  2834. publish, distribute, sublicense, and/or sell copies of the Software,
  2835. and to permit persons to whom the Software is furnished to do so,
  2836. subject to the following conditions:
  2837. The above copyright notice and this permission notice shall be
  2838. included in all copies or substantial portions of the Software.
  2839. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2840. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2841. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2842. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2843. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2844. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2845. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2846. SOFTWARE.
  2847. */
  2848. function TokenStream(parent_token) {
  2849. // private
  2850. this.__tokens = [];
  2851. this.__tokens_length = this.__tokens.length;
  2852. this.__position = 0;
  2853. this.__parent_token = parent_token;
  2854. }
  2855. TokenStream.prototype.restart = function() {
  2856. this.__position = 0;
  2857. };
  2858. TokenStream.prototype.isEmpty = function() {
  2859. return this.__tokens_length === 0;
  2860. };
  2861. TokenStream.prototype.hasNext = function() {
  2862. return this.__position < this.__tokens_length;
  2863. };
  2864. TokenStream.prototype.next = function() {
  2865. var val = null;
  2866. if (this.hasNext()) {
  2867. val = this.__tokens[this.__position];
  2868. this.__position += 1;
  2869. }
  2870. return val;
  2871. };
  2872. TokenStream.prototype.peek = function(index) {
  2873. var val = null;
  2874. index = index || 0;
  2875. index += this.__position;
  2876. if (index >= 0 && index < this.__tokens_length) {
  2877. val = this.__tokens[index];
  2878. }
  2879. return val;
  2880. };
  2881. TokenStream.prototype.add = function(token) {
  2882. if (this.__parent_token) {
  2883. token.parent = this.__parent_token;
  2884. }
  2885. this.__tokens.push(token);
  2886. this.__tokens_length += 1;
  2887. };
  2888. module.exports.TokenStream = TokenStream;
  2889. /***/ }),
  2890. /* 11 */
  2891. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  2892. /*jshint node:true */
  2893. /*
  2894. The MIT License (MIT)
  2895. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2896. Permission is hereby granted, free of charge, to any person
  2897. obtaining a copy of this software and associated documentation files
  2898. (the "Software"), to deal in the Software without restriction,
  2899. including without limitation the rights to use, copy, modify, merge,
  2900. publish, distribute, sublicense, and/or sell copies of the Software,
  2901. and to permit persons to whom the Software is furnished to do so,
  2902. subject to the following conditions:
  2903. The above copyright notice and this permission notice shall be
  2904. included in all copies or substantial portions of the Software.
  2905. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2906. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2907. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2908. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2909. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2910. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2911. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2912. SOFTWARE.
  2913. */
  2914. var Pattern = __webpack_require__(12).Pattern;
  2915. function WhitespacePattern(input_scanner, parent) {
  2916. Pattern.call(this, input_scanner, parent);
  2917. if (parent) {
  2918. this._line_regexp = this._input.get_regexp(parent._line_regexp);
  2919. } else {
  2920. this.__set_whitespace_patterns('', '');
  2921. }
  2922. this.newline_count = 0;
  2923. this.whitespace_before_token = '';
  2924. }
  2925. WhitespacePattern.prototype = new Pattern();
  2926. WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
  2927. whitespace_chars += '\\t ';
  2928. newline_chars += '\\n\\r';
  2929. this._match_pattern = this._input.get_regexp(
  2930. '[' + whitespace_chars + newline_chars + ']+', true);
  2931. this._newline_regexp = this._input.get_regexp(
  2932. '\\r\\n|[' + newline_chars + ']');
  2933. };
  2934. WhitespacePattern.prototype.read = function() {
  2935. this.newline_count = 0;
  2936. this.whitespace_before_token = '';
  2937. var resulting_string = this._input.read(this._match_pattern);
  2938. if (resulting_string === ' ') {
  2939. this.whitespace_before_token = ' ';
  2940. } else if (resulting_string) {
  2941. var matches = this.__split(this._newline_regexp, resulting_string);
  2942. this.newline_count = matches.length - 1;
  2943. this.whitespace_before_token = matches[this.newline_count];
  2944. }
  2945. return resulting_string;
  2946. };
  2947. WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
  2948. var result = this._create();
  2949. result.__set_whitespace_patterns(whitespace_chars, newline_chars);
  2950. result._update();
  2951. return result;
  2952. };
  2953. WhitespacePattern.prototype._create = function() {
  2954. return new WhitespacePattern(this._input, this);
  2955. };
  2956. WhitespacePattern.prototype.__split = function(regexp, input_string) {
  2957. regexp.lastIndex = 0;
  2958. var start_index = 0;
  2959. var result = [];
  2960. var next_match = regexp.exec(input_string);
  2961. while (next_match) {
  2962. result.push(input_string.substring(start_index, next_match.index));
  2963. start_index = next_match.index + next_match[0].length;
  2964. next_match = regexp.exec(input_string);
  2965. }
  2966. if (start_index < input_string.length) {
  2967. result.push(input_string.substring(start_index, input_string.length));
  2968. } else {
  2969. result.push('');
  2970. }
  2971. return result;
  2972. };
  2973. module.exports.WhitespacePattern = WhitespacePattern;
  2974. /***/ }),
  2975. /* 12 */
  2976. /***/ (function(module) {
  2977. /*jshint node:true */
  2978. /*
  2979. The MIT License (MIT)
  2980. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  2981. Permission is hereby granted, free of charge, to any person
  2982. obtaining a copy of this software and associated documentation files
  2983. (the "Software"), to deal in the Software without restriction,
  2984. including without limitation the rights to use, copy, modify, merge,
  2985. publish, distribute, sublicense, and/or sell copies of the Software,
  2986. and to permit persons to whom the Software is furnished to do so,
  2987. subject to the following conditions:
  2988. The above copyright notice and this permission notice shall be
  2989. included in all copies or substantial portions of the Software.
  2990. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2991. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2992. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2993. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  2994. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2995. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2996. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2997. SOFTWARE.
  2998. */
  2999. function Pattern(input_scanner, parent) {
  3000. this._input = input_scanner;
  3001. this._starting_pattern = null;
  3002. this._match_pattern = null;
  3003. this._until_pattern = null;
  3004. this._until_after = false;
  3005. if (parent) {
  3006. this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
  3007. this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
  3008. this._until_pattern = this._input.get_regexp(parent._until_pattern);
  3009. this._until_after = parent._until_after;
  3010. }
  3011. }
  3012. Pattern.prototype.read = function() {
  3013. var result = this._input.read(this._starting_pattern);
  3014. if (!this._starting_pattern || result) {
  3015. result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
  3016. }
  3017. return result;
  3018. };
  3019. Pattern.prototype.read_match = function() {
  3020. return this._input.match(this._match_pattern);
  3021. };
  3022. Pattern.prototype.until_after = function(pattern) {
  3023. var result = this._create();
  3024. result._until_after = true;
  3025. result._until_pattern = this._input.get_regexp(pattern);
  3026. result._update();
  3027. return result;
  3028. };
  3029. Pattern.prototype.until = function(pattern) {
  3030. var result = this._create();
  3031. result._until_after = false;
  3032. result._until_pattern = this._input.get_regexp(pattern);
  3033. result._update();
  3034. return result;
  3035. };
  3036. Pattern.prototype.starting_with = function(pattern) {
  3037. var result = this._create();
  3038. result._starting_pattern = this._input.get_regexp(pattern, true);
  3039. result._update();
  3040. return result;
  3041. };
  3042. Pattern.prototype.matching = function(pattern) {
  3043. var result = this._create();
  3044. result._match_pattern = this._input.get_regexp(pattern, true);
  3045. result._update();
  3046. return result;
  3047. };
  3048. Pattern.prototype._create = function() {
  3049. return new Pattern(this._input, this);
  3050. };
  3051. Pattern.prototype._update = function() {};
  3052. module.exports.Pattern = Pattern;
  3053. /***/ }),
  3054. /* 13 */
  3055. /***/ (function(module) {
  3056. /*jshint node:true */
  3057. /*
  3058. The MIT License (MIT)
  3059. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3060. Permission is hereby granted, free of charge, to any person
  3061. obtaining a copy of this software and associated documentation files
  3062. (the "Software"), to deal in the Software without restriction,
  3063. including without limitation the rights to use, copy, modify, merge,
  3064. publish, distribute, sublicense, and/or sell copies of the Software,
  3065. and to permit persons to whom the Software is furnished to do so,
  3066. subject to the following conditions:
  3067. The above copyright notice and this permission notice shall be
  3068. included in all copies or substantial portions of the Software.
  3069. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3070. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3071. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3072. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3073. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3074. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3075. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3076. SOFTWARE.
  3077. */
  3078. function Directives(start_block_pattern, end_block_pattern) {
  3079. start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
  3080. end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
  3081. this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
  3082. this.__directive_pattern = / (\w+)[:](\w+)/g;
  3083. this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
  3084. }
  3085. Directives.prototype.get_directives = function(text) {
  3086. if (!text.match(this.__directives_block_pattern)) {
  3087. return null;
  3088. }
  3089. var directives = {};
  3090. this.__directive_pattern.lastIndex = 0;
  3091. var directive_match = this.__directive_pattern.exec(text);
  3092. while (directive_match) {
  3093. directives[directive_match[1]] = directive_match[2];
  3094. directive_match = this.__directive_pattern.exec(text);
  3095. }
  3096. return directives;
  3097. };
  3098. Directives.prototype.readIgnored = function(input) {
  3099. return input.readUntilAfter(this.__directives_end_ignore_pattern);
  3100. };
  3101. module.exports.Directives = Directives;
  3102. /***/ }),
  3103. /* 14 */
  3104. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  3105. /*jshint node:true */
  3106. /*
  3107. The MIT License (MIT)
  3108. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  3109. Permission is hereby granted, free of charge, to any person
  3110. obtaining a copy of this software and associated documentation files
  3111. (the "Software"), to deal in the Software without restriction,
  3112. including without limitation the rights to use, copy, modify, merge,
  3113. publish, distribute, sublicense, and/or sell copies of the Software,
  3114. and to permit persons to whom the Software is furnished to do so,
  3115. subject to the following conditions:
  3116. The above copyright notice and this permission notice shall be
  3117. included in all copies or substantial portions of the Software.
  3118. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  3119. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3120. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  3121. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  3122. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  3123. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3124. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  3125. SOFTWARE.
  3126. */
  3127. var Pattern = __webpack_require__(12).Pattern;
  3128. var template_names = {
  3129. django: false,
  3130. erb: false,
  3131. handlebars: false,
  3132. php: false,
  3133. smarty: false
  3134. };
  3135. // This lets templates appear anywhere we would do a readUntil
  3136. // The cost is higher but it is pay to play.
  3137. function TemplatablePattern(input_scanner, parent) {
  3138. Pattern.call(this, input_scanner, parent);
  3139. this.__template_pattern = null;
  3140. this._disabled = Object.assign({}, template_names);
  3141. this._excluded = Object.assign({}, template_names);
  3142. if (parent) {
  3143. this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
  3144. this._excluded = Object.assign(this._excluded, parent._excluded);
  3145. this._disabled = Object.assign(this._disabled, parent._disabled);
  3146. }
  3147. var pattern = new Pattern(input_scanner);
  3148. this.__patterns = {
  3149. handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
  3150. handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
  3151. handlebars: pattern.starting_with(/{{/).until_after(/}}/),
  3152. php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
  3153. erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
  3154. // django coflicts with handlebars a bit.
  3155. django: pattern.starting_with(/{%/).until_after(/%}/),
  3156. django_value: pattern.starting_with(/{{/).until_after(/}}/),
  3157. django_comment: pattern.starting_with(/{#/).until_after(/#}/),
  3158. smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
  3159. smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
  3160. smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
  3161. };
  3162. }
  3163. TemplatablePattern.prototype = new Pattern();
  3164. TemplatablePattern.prototype._create = function() {
  3165. return new TemplatablePattern(this._input, this);
  3166. };
  3167. TemplatablePattern.prototype._update = function() {
  3168. this.__set_templated_pattern();
  3169. };
  3170. TemplatablePattern.prototype.disable = function(language) {
  3171. var result = this._create();
  3172. result._disabled[language] = true;
  3173. result._update();
  3174. return result;
  3175. };
  3176. TemplatablePattern.prototype.read_options = function(options) {
  3177. var result = this._create();
  3178. for (var language in template_names) {
  3179. result._disabled[language] = options.templating.indexOf(language) === -1;
  3180. }
  3181. result._update();
  3182. return result;
  3183. };
  3184. TemplatablePattern.prototype.exclude = function(language) {
  3185. var result = this._create();
  3186. result._excluded[language] = true;
  3187. result._update();
  3188. return result;
  3189. };
  3190. TemplatablePattern.prototype.read = function() {
  3191. var result = '';
  3192. if (this._match_pattern) {
  3193. result = this._input.read(this._starting_pattern);
  3194. } else {
  3195. result = this._input.read(this._starting_pattern, this.__template_pattern);
  3196. }
  3197. var next = this._read_template();
  3198. while (next) {
  3199. if (this._match_pattern) {
  3200. next += this._input.read(this._match_pattern);
  3201. } else {
  3202. next += this._input.readUntil(this.__template_pattern);
  3203. }
  3204. result += next;
  3205. next = this._read_template();
  3206. }
  3207. if (this._until_after) {
  3208. result += this._input.readUntilAfter(this._until_pattern);
  3209. }
  3210. return result;
  3211. };
  3212. TemplatablePattern.prototype.__set_templated_pattern = function() {
  3213. var items = [];
  3214. if (!this._disabled.php) {
  3215. items.push(this.__patterns.php._starting_pattern.source);
  3216. }
  3217. if (!this._disabled.handlebars) {
  3218. items.push(this.__patterns.handlebars._starting_pattern.source);
  3219. }
  3220. if (!this._disabled.erb) {
  3221. items.push(this.__patterns.erb._starting_pattern.source);
  3222. }
  3223. if (!this._disabled.django) {
  3224. items.push(this.__patterns.django._starting_pattern.source);
  3225. // The starting pattern for django is more complex because it has different
  3226. // patterns for value, comment, and other sections
  3227. items.push(this.__patterns.django_value._starting_pattern.source);
  3228. items.push(this.__patterns.django_comment._starting_pattern.source);
  3229. }
  3230. if (!this._disabled.smarty) {
  3231. items.push(this.__patterns.smarty._starting_pattern.source);
  3232. }
  3233. if (this._until_pattern) {
  3234. items.push(this._until_pattern.source);
  3235. }
  3236. this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
  3237. };
  3238. TemplatablePattern.prototype._read_template = function() {
  3239. var resulting_string = '';
  3240. var c = this._input.peek();
  3241. if (c === '<') {
  3242. var peek1 = this._input.peek(1);
  3243. //if we're in a comment, do something special
  3244. // We treat all comments as literals, even more than preformatted tags
  3245. // we just look for the appropriate close tag
  3246. if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
  3247. resulting_string = resulting_string ||
  3248. this.__patterns.php.read();
  3249. }
  3250. if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
  3251. resulting_string = resulting_string ||
  3252. this.__patterns.erb.read();
  3253. }
  3254. } else if (c === '{') {
  3255. if (!this._disabled.handlebars && !this._excluded.handlebars) {
  3256. resulting_string = resulting_string ||
  3257. this.__patterns.handlebars_comment.read();
  3258. resulting_string = resulting_string ||
  3259. this.__patterns.handlebars_unescaped.read();
  3260. resulting_string = resulting_string ||
  3261. this.__patterns.handlebars.read();
  3262. }
  3263. if (!this._disabled.django) {
  3264. // django coflicts with handlebars a bit.
  3265. if (!this._excluded.django && !this._excluded.handlebars) {
  3266. resulting_string = resulting_string ||
  3267. this.__patterns.django_value.read();
  3268. }
  3269. if (!this._excluded.django) {
  3270. resulting_string = resulting_string ||
  3271. this.__patterns.django_comment.read();
  3272. resulting_string = resulting_string ||
  3273. this.__patterns.django.read();
  3274. }
  3275. }
  3276. if (!this._disabled.smarty) {
  3277. // smarty cannot be enabled with django or handlebars enabled
  3278. if (this._disabled.django && this._disabled.handlebars) {
  3279. resulting_string = resulting_string ||
  3280. this.__patterns.smarty_comment.read();
  3281. resulting_string = resulting_string ||
  3282. this.__patterns.smarty_literal.read();
  3283. resulting_string = resulting_string ||
  3284. this.__patterns.smarty.read();
  3285. }
  3286. }
  3287. }
  3288. return resulting_string;
  3289. };
  3290. module.exports.TemplatablePattern = TemplatablePattern;
  3291. /***/ })
  3292. /******/ ]);
  3293. /************************************************************************/
  3294. /******/ // The module cache
  3295. /******/ var __webpack_module_cache__ = {};
  3296. /******/
  3297. /******/ // The require function
  3298. /******/ function __webpack_require__(moduleId) {
  3299. /******/ // Check if module is in cache
  3300. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  3301. /******/ if (cachedModule !== undefined) {
  3302. /******/ return cachedModule.exports;
  3303. /******/ }
  3304. /******/ // Create a new module (and put it into the cache)
  3305. /******/ var module = __webpack_module_cache__[moduleId] = {
  3306. /******/ // no module.id needed
  3307. /******/ // no module.loaded needed
  3308. /******/ exports: {}
  3309. /******/ };
  3310. /******/
  3311. /******/ // Execute the module function
  3312. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  3313. /******/
  3314. /******/ // Return the exports of the module
  3315. /******/ return module.exports;
  3316. /******/ }
  3317. /******/
  3318. /************************************************************************/
  3319. /******/
  3320. /******/ // startup
  3321. /******/ // Load entry module and return exports
  3322. /******/ // This entry module is referenced by other modules so it can't be inlined
  3323. /******/ var __webpack_exports__ = __webpack_require__(0);
  3324. /******/ legacy_beautify_js = __webpack_exports__;
  3325. /******/
  3326. /******/ })()
  3327. ;
  3328. var js_beautify = legacy_beautify_js;
  3329. /* Footer */
  3330. if (typeof define === "function" && define.amd) {
  3331. // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
  3332. define([], function() {
  3333. return { js_beautify: js_beautify };
  3334. });
  3335. } else if (typeof exports !== "undefined") {
  3336. // Add support for CommonJS. Just put this file somewhere on your require.paths
  3337. // and you will be able to `var js_beautify = require("beautify").js_beautify`.
  3338. exports.js_beautify = js_beautify;
  3339. } else if (typeof window !== "undefined") {
  3340. // If we're running a web page and don't have either of the above, add our one global
  3341. window.js_beautify = js_beautify;
  3342. } else if (typeof global !== "undefined") {
  3343. // If we don't even have window, try global.
  3344. global.js_beautify = js_beautify;
  3345. }
  3346. }());