js-beautify 1.14.0 → 1.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1003,8 +1003,8 @@ module.exports.Directives = Directives;
1003
1003
 
1004
1004
 
1005
1005
 
1006
- var Beautifier = __webpack_require__(16).Beautifier,
1007
- Options = __webpack_require__(17).Options;
1006
+ var Beautifier = (__webpack_require__(16).Beautifier),
1007
+ Options = (__webpack_require__(17).Options);
1008
1008
 
1009
1009
  function css_beautify(source_text, options) {
1010
1010
  var beautifier = new Beautifier(source_text, options);
@@ -1051,10 +1051,10 @@ module.exports.defaultOptions = function() {
1051
1051
 
1052
1052
 
1053
1053
 
1054
- var Options = __webpack_require__(17).Options;
1055
- var Output = __webpack_require__(2).Output;
1056
- var InputScanner = __webpack_require__(8).InputScanner;
1057
- var Directives = __webpack_require__(13).Directives;
1054
+ var Options = (__webpack_require__(17).Options);
1055
+ var Output = (__webpack_require__(2).Output);
1056
+ var InputScanner = (__webpack_require__(8).InputScanner);
1057
+ var Directives = (__webpack_require__(13).Directives);
1058
1058
 
1059
1059
  var directives_core = new Directives(/\/\*/, /\*\//);
1060
1060
 
@@ -1090,6 +1090,9 @@ function Beautifier(source_text, options) {
1090
1090
  "@supports": true,
1091
1091
  "@document": true
1092
1092
  };
1093
+ this.NON_SEMICOLON_NEWLINE_PROPERTY = [
1094
+ "grid-template"
1095
+ ];
1093
1096
 
1094
1097
  }
1095
1098
 
@@ -1214,7 +1217,9 @@ Beautifier.prototype.beautify = function() {
1214
1217
  var enteringConditionalGroup = false;
1215
1218
  var insideAtExtend = false;
1216
1219
  var insideAtImport = false;
1220
+ var insideScssMap = false;
1217
1221
  var topCharacter = this._ch;
1222
+ var insideNonSemiColonValues = false;
1218
1223
  var whitespace;
1219
1224
  var isAfterSpace;
1220
1225
  var previous_ch;
@@ -1266,7 +1271,7 @@ Beautifier.prototype.beautify = function() {
1266
1271
 
1267
1272
  // Ensures any new lines following the comment are preserved
1268
1273
  this.eatWhitespace(true);
1269
- } else if (this._ch === '@') {
1274
+ } else if (this._ch === '@' || this._ch === '$') {
1270
1275
  this.preserveSingleSpace(isAfterSpace);
1271
1276
 
1272
1277
  // deal with less propery mixins @{...}
@@ -1337,7 +1342,12 @@ Beautifier.prototype.beautify = function() {
1337
1342
  this.indent();
1338
1343
  this._output.set_indent(this._indentLevel);
1339
1344
  } else {
1340
- this.indent();
1345
+ // inside mixin and first param is object
1346
+ if (previous_ch === '(') {
1347
+ this._output.space_before_token = false;
1348
+ } else if (previous_ch !== ',') {
1349
+ this.indent();
1350
+ }
1341
1351
  this.print_string(this._ch);
1342
1352
  }
1343
1353
 
@@ -1369,7 +1379,21 @@ Beautifier.prototype.beautify = function() {
1369
1379
  this._output.add_new_line(true);
1370
1380
  }
1371
1381
  }
1382
+ if (this._input.peek() === ')') {
1383
+ this._output.trim(true);
1384
+ if (this._options.brace_style === "expand") {
1385
+ this._output.add_new_line(true);
1386
+ }
1387
+ }
1372
1388
  } else if (this._ch === ":") {
1389
+
1390
+ for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
1391
+ if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
1392
+ insideNonSemiColonValues = true;
1393
+ break;
1394
+ }
1395
+ }
1396
+
1373
1397
  if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
1374
1398
  // 'property: value' delimiter
1375
1399
  // which could be in a conditional group query
@@ -1402,6 +1426,7 @@ Beautifier.prototype.beautify = function() {
1402
1426
  this.print_string(this._ch + this.eatString(this._ch));
1403
1427
  this.eatWhitespace(true);
1404
1428
  } else if (this._ch === ';') {
1429
+ insideNonSemiColonValues = false;
1405
1430
  if (parenLevel === 0) {
1406
1431
  if (insidePropertyValue) {
1407
1432
  this.outdent();
@@ -1443,20 +1468,32 @@ Beautifier.prototype.beautify = function() {
1443
1468
  } else {
1444
1469
  this.preserveSingleSpace(isAfterSpace);
1445
1470
  this.print_string(this._ch);
1446
- this.eatWhitespace();
1447
- parenLevel++;
1448
- this.indent();
1471
+
1472
+ // handle scss/sass map
1473
+ if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
1474
+ this._output.add_new_line();
1475
+ insideScssMap = true;
1476
+ } else {
1477
+ this.eatWhitespace();
1478
+ parenLevel++;
1479
+ this.indent();
1480
+ }
1449
1481
  }
1450
1482
  } else if (this._ch === ')') {
1451
1483
  if (parenLevel) {
1452
1484
  parenLevel--;
1453
1485
  this.outdent();
1454
1486
  }
1487
+ if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
1488
+ insideScssMap = false;
1489
+ this.outdent();
1490
+ this._output.add_new_line();
1491
+ }
1455
1492
  this.print_string(this._ch);
1456
1493
  } else if (this._ch === ',') {
1457
1494
  this.print_string(this._ch);
1458
1495
  this.eatWhitespace(true);
1459
- if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
1496
+ if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
1460
1497
  this._output.add_new_line();
1461
1498
  } else {
1462
1499
  this._output.space_before_token = true;
@@ -1490,8 +1527,13 @@ Beautifier.prototype.beautify = function() {
1490
1527
  this.print_string(' ');
1491
1528
  this.print_string(this._ch);
1492
1529
  } else {
1493
- this.preserveSingleSpace(isAfterSpace);
1530
+ var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
1531
+ this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
1494
1532
  this.print_string(this._ch);
1533
+
1534
+ if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
1535
+ this._output.add_new_line();
1536
+ }
1495
1537
  }
1496
1538
  }
1497
1539
 
@@ -1537,7 +1579,7 @@ module.exports.Beautifier = Beautifier;
1537
1579
 
1538
1580
 
1539
1581
 
1540
- var BaseOptions = __webpack_require__(6).Options;
1582
+ var BaseOptions = (__webpack_require__(6).Options);
1541
1583
 
1542
1584
  function Options(options) {
1543
1585
  BaseOptions.call(this, options, 'css');
@@ -999,10 +999,10 @@ module.exports.InputScanner = InputScanner;
999
999
 
1000
1000
 
1001
1001
 
1002
- var InputScanner = __webpack_require__(8).InputScanner;
1003
- var Token = __webpack_require__(3).Token;
1004
- var TokenStream = __webpack_require__(10).TokenStream;
1005
- var WhitespacePattern = __webpack_require__(11).WhitespacePattern;
1002
+ var InputScanner = (__webpack_require__(8).InputScanner);
1003
+ var Token = (__webpack_require__(3).Token);
1004
+ var TokenStream = (__webpack_require__(10).TokenStream);
1005
+ var WhitespacePattern = (__webpack_require__(11).WhitespacePattern);
1006
1006
 
1007
1007
  var TOKEN = {
1008
1008
  START: 'TK_START',
@@ -1229,7 +1229,7 @@ module.exports.TokenStream = TokenStream;
1229
1229
 
1230
1230
 
1231
1231
 
1232
- var Pattern = __webpack_require__(12).Pattern;
1232
+ var Pattern = (__webpack_require__(12).Pattern);
1233
1233
 
1234
1234
  function WhitespacePattern(input_scanner, parent) {
1235
1235
  Pattern.call(this, input_scanner, parent);
@@ -1508,7 +1508,7 @@ module.exports.Directives = Directives;
1508
1508
 
1509
1509
 
1510
1510
 
1511
- var Pattern = __webpack_require__(12).Pattern;
1511
+ var Pattern = (__webpack_require__(12).Pattern);
1512
1512
 
1513
1513
 
1514
1514
  var template_names = {
@@ -1728,8 +1728,8 @@ module.exports.TemplatablePattern = TemplatablePattern;
1728
1728
 
1729
1729
 
1730
1730
 
1731
- var Beautifier = __webpack_require__(19).Beautifier,
1732
- Options = __webpack_require__(20).Options;
1731
+ var Beautifier = (__webpack_require__(19).Beautifier),
1732
+ Options = (__webpack_require__(20).Options);
1733
1733
 
1734
1734
  function style_html(html_source, options, js_beautify, css_beautify) {
1735
1735
  var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
@@ -1776,10 +1776,10 @@ module.exports.defaultOptions = function() {
1776
1776
 
1777
1777
 
1778
1778
 
1779
- var Options = __webpack_require__(20).Options;
1780
- var Output = __webpack_require__(2).Output;
1781
- var Tokenizer = __webpack_require__(21).Tokenizer;
1782
- var TOKEN = __webpack_require__(21).TOKEN;
1779
+ var Options = (__webpack_require__(20).Options);
1780
+ var Output = (__webpack_require__(2).Output);
1781
+ var Tokenizer = (__webpack_require__(21).Tokenizer);
1782
+ var TOKEN = (__webpack_require__(21).TOKEN);
1783
1783
 
1784
1784
  var lineBreak = /\r\n|[\r\n]/;
1785
1785
  var allLineBreaks = /\r\n|[\r\n]/g;
@@ -2360,7 +2360,7 @@ var TagOpenParserToken = function(parent, raw_token) {
2360
2360
 
2361
2361
  // handle "{{#> myPartial}}
2362
2362
  if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
2363
- this.tag_check = raw_token.next.text;
2363
+ this.tag_check = raw_token.next.text.split(' ')[0];
2364
2364
  }
2365
2365
  }
2366
2366
  this.tag_check = this.tag_check.toLowerCase();
@@ -2647,7 +2647,7 @@ module.exports.Beautifier = Beautifier;
2647
2647
 
2648
2648
 
2649
2649
 
2650
- var BaseOptions = __webpack_require__(6).Options;
2650
+ var BaseOptions = (__webpack_require__(6).Options);
2651
2651
 
2652
2652
  function Options(options) {
2653
2653
  BaseOptions.call(this, options, 'html');
@@ -2744,11 +2744,11 @@ module.exports.Options = Options;
2744
2744
 
2745
2745
 
2746
2746
 
2747
- var BaseTokenizer = __webpack_require__(9).Tokenizer;
2748
- var BASETOKEN = __webpack_require__(9).TOKEN;
2749
- var Directives = __webpack_require__(13).Directives;
2750
- var TemplatablePattern = __webpack_require__(14).TemplatablePattern;
2751
- var Pattern = __webpack_require__(12).Pattern;
2747
+ var BaseTokenizer = (__webpack_require__(9).Tokenizer);
2748
+ var BASETOKEN = (__webpack_require__(9).TOKEN);
2749
+ var Directives = (__webpack_require__(13).Directives);
2750
+ var TemplatablePattern = (__webpack_require__(14).TemplatablePattern);
2751
+ var Pattern = (__webpack_require__(12).Pattern);
2752
2752
 
2753
2753
  var TOKEN = {
2754
2754
  TAG_OPEN: 'TK_TAG_OPEN',
@@ -125,8 +125,8 @@ var legacy_beautify_js;
125
125
 
126
126
 
127
127
 
128
- var Beautifier = __webpack_require__(1).Beautifier,
129
- Options = __webpack_require__(5).Options;
128
+ var Beautifier = (__webpack_require__(1).Beautifier),
129
+ Options = (__webpack_require__(5).Options);
130
130
 
131
131
  function js_beautify(js_source_text, options) {
132
132
  var beautifier = new Beautifier(js_source_text, options);
@@ -173,14 +173,14 @@ module.exports.defaultOptions = function() {
173
173
 
174
174
 
175
175
 
176
- var Output = __webpack_require__(2).Output;
177
- var Token = __webpack_require__(3).Token;
176
+ var Output = (__webpack_require__(2).Output);
177
+ var Token = (__webpack_require__(3).Token);
178
178
  var acorn = __webpack_require__(4);
179
- var Options = __webpack_require__(5).Options;
180
- var Tokenizer = __webpack_require__(7).Tokenizer;
181
- var line_starters = __webpack_require__(7).line_starters;
182
- var positionable_operators = __webpack_require__(7).positionable_operators;
183
- var TOKEN = __webpack_require__(7).TOKEN;
179
+ var Options = (__webpack_require__(5).Options);
180
+ var Tokenizer = (__webpack_require__(7).Tokenizer);
181
+ var line_starters = (__webpack_require__(7).line_starters);
182
+ var positionable_operators = (__webpack_require__(7).positionable_operators);
183
+ var TOKEN = (__webpack_require__(7).TOKEN);
184
184
 
185
185
 
186
186
  function in_array(what, arr) {
@@ -336,6 +336,7 @@ Beautifier.prototype.create_flags = function(flags_base, mode) {
336
336
  in_case_statement: false, // switch(..){ INSIDE HERE }
337
337
  in_case: false, // we're on the exact line with "case 0:"
338
338
  case_body: false, // the indented case-action block
339
+ case_block: false, // the indented case-action block is wrapped with {}
339
340
  indentation_level: next_indent_level,
340
341
  alignment: 0,
341
342
  line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
@@ -835,10 +836,10 @@ Beautifier.prototype.handle_start_block = function(current_token) {
835
836
  )) {
836
837
  // We don't support TypeScript,but we didn't break it for a very long time.
837
838
  // We'll try to keep not breaking it.
838
- if (!in_array(this._last_last_text, ['class', 'interface'])) {
839
- this.set_mode(MODE.ObjectLiteral);
840
- } else {
839
+ if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
841
840
  this.set_mode(MODE.BlockStatement);
841
+ } else {
842
+ this.set_mode(MODE.ObjectLiteral);
842
843
  }
843
844
  } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
844
845
  // arrow function: (param1, paramN) => { statements }
@@ -954,7 +955,7 @@ Beautifier.prototype.handle_word = function(current_token) {
954
955
  if (current_token.type === TOKEN.RESERVED) {
955
956
  if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
956
957
  current_token.type = TOKEN.WORD;
957
- } else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
958
+ } else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
958
959
  current_token.type = TOKEN.WORD;
959
960
  } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
960
961
  current_token.type = TOKEN.WORD;
@@ -1014,7 +1015,7 @@ Beautifier.prototype.handle_word = function(current_token) {
1014
1015
 
1015
1016
  if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
1016
1017
  this.print_newline();
1017
- if (this._flags.last_token.type !== TOKEN.END_BLOCK && (this._flags.case_body || this._options.jslint_happy)) {
1018
+ if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
1018
1019
  // switch cases following one another
1019
1020
  this.deindent();
1020
1021
  }
@@ -1328,7 +1329,9 @@ Beautifier.prototype.handle_operator = function(current_token) {
1328
1329
  if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
1329
1330
  this.indent();
1330
1331
  this.print_newline();
1332
+ this._flags.case_block = false;
1331
1333
  } else {
1334
+ this._flags.case_block = true;
1332
1335
  this._output.space_before_token = true;
1333
1336
  }
1334
1337
  return;
@@ -1426,7 +1429,7 @@ Beautifier.prototype.handle_operator = function(current_token) {
1426
1429
 
1427
1430
  // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
1428
1431
  // if there is a newline between -- or ++ and anything else we should preserve it.
1429
- if (current_token.newlines && (current_token.text === '--' || current_token.text === '++')) {
1432
+ if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
1430
1433
  this.print_newline(false, true);
1431
1434
  }
1432
1435
 
@@ -2186,7 +2189,7 @@ exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
2186
2189
 
2187
2190
 
2188
2191
 
2189
- var BaseOptions = __webpack_require__(6).Options;
2192
+ var BaseOptions = (__webpack_require__(6).Options);
2190
2193
 
2191
2194
  var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
2192
2195
 
@@ -2484,13 +2487,13 @@ module.exports.mergeOpts = _mergeOpts;
2484
2487
 
2485
2488
 
2486
2489
 
2487
- var InputScanner = __webpack_require__(8).InputScanner;
2488
- var BaseTokenizer = __webpack_require__(9).Tokenizer;
2489
- var BASETOKEN = __webpack_require__(9).TOKEN;
2490
- var Directives = __webpack_require__(13).Directives;
2490
+ var InputScanner = (__webpack_require__(8).InputScanner);
2491
+ var BaseTokenizer = (__webpack_require__(9).Tokenizer);
2492
+ var BASETOKEN = (__webpack_require__(9).TOKEN);
2493
+ var Directives = (__webpack_require__(13).Directives);
2491
2494
  var acorn = __webpack_require__(4);
2492
- var Pattern = __webpack_require__(12).Pattern;
2493
- var TemplatablePattern = __webpack_require__(14).TemplatablePattern;
2495
+ var Pattern = (__webpack_require__(12).Pattern);
2496
+ var TemplatablePattern = (__webpack_require__(14).TemplatablePattern);
2494
2497
 
2495
2498
 
2496
2499
  function in_array(what, arr) {
@@ -2530,7 +2533,7 @@ var digit = /[0-9]/;
2530
2533
  var dot_pattern = /[^\d\.]/;
2531
2534
 
2532
2535
  var positionable_operators = (
2533
- ">>> === !== " +
2536
+ ">>> === !== &&= ??= ||= " +
2534
2537
  "<< && >= ** != == <= >> || ?? |> " +
2535
2538
  "< / - + > : & % ? ^ | *").split(' ');
2536
2539
 
@@ -2538,7 +2541,7 @@ var positionable_operators = (
2538
2541
  // Also, you must update possitionable operators separately from punct
2539
2542
  var punct =
2540
2543
  ">>>= " +
2541
- "... >>= <<= === >>> !== **= " +
2544
+ "... >>= <<= === >>> !== **= &&= ??= ||= " +
2542
2545
  "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
2543
2546
  "= ! ? > < : / ^ - + * & % ~ |";
2544
2547
 
@@ -2582,7 +2585,7 @@ var Tokenizer = function(input_string, options) {
2582
2585
  html_comment_end: pattern_reader.matching(/-->/),
2583
2586
  include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
2584
2587
  shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
2585
- 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*>/),
2588
+ xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[^}]+?}|!\[CDATA\[[^\]]*?\]\]|)(\s*{[^}]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{([^{}]|{[^}]+?})+?}))*\s*(\/?)\s*>/),
2586
2589
  single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
2587
2590
  double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
2588
2591
  template_text: templatable.until(/[`\\$]/),
@@ -3254,10 +3257,10 @@ module.exports.InputScanner = InputScanner;
3254
3257
 
3255
3258
 
3256
3259
 
3257
- var InputScanner = __webpack_require__(8).InputScanner;
3258
- var Token = __webpack_require__(3).Token;
3259
- var TokenStream = __webpack_require__(10).TokenStream;
3260
- var WhitespacePattern = __webpack_require__(11).WhitespacePattern;
3260
+ var InputScanner = (__webpack_require__(8).InputScanner);
3261
+ var Token = (__webpack_require__(3).Token);
3262
+ var TokenStream = (__webpack_require__(10).TokenStream);
3263
+ var WhitespacePattern = (__webpack_require__(11).WhitespacePattern);
3261
3264
 
3262
3265
  var TOKEN = {
3263
3266
  START: 'TK_START',
@@ -3484,7 +3487,7 @@ module.exports.TokenStream = TokenStream;
3484
3487
 
3485
3488
 
3486
3489
 
3487
- var Pattern = __webpack_require__(12).Pattern;
3490
+ var Pattern = (__webpack_require__(12).Pattern);
3488
3491
 
3489
3492
  function WhitespacePattern(input_scanner, parent) {
3490
3493
  Pattern.call(this, input_scanner, parent);
@@ -3763,7 +3766,7 @@ module.exports.Directives = Directives;
3763
3766
 
3764
3767
 
3765
3768
 
3766
- var Pattern = __webpack_require__(12).Pattern;
3769
+ var Pattern = (__webpack_require__(12).Pattern);
3767
3770
 
3768
3771
 
3769
3772
  var template_names = {
@@ -67,6 +67,9 @@ function Beautifier(source_text, options) {
67
67
  "@supports": true,
68
68
  "@document": true
69
69
  };
70
+ this.NON_SEMICOLON_NEWLINE_PROPERTY = [
71
+ "grid-template"
72
+ ];
70
73
 
71
74
  }
72
75
 
@@ -191,7 +194,9 @@ Beautifier.prototype.beautify = function() {
191
194
  var enteringConditionalGroup = false;
192
195
  var insideAtExtend = false;
193
196
  var insideAtImport = false;
197
+ var insideScssMap = false;
194
198
  var topCharacter = this._ch;
199
+ var insideNonSemiColonValues = false;
195
200
  var whitespace;
196
201
  var isAfterSpace;
197
202
  var previous_ch;
@@ -243,7 +248,7 @@ Beautifier.prototype.beautify = function() {
243
248
 
244
249
  // Ensures any new lines following the comment are preserved
245
250
  this.eatWhitespace(true);
246
- } else if (this._ch === '@') {
251
+ } else if (this._ch === '@' || this._ch === '$') {
247
252
  this.preserveSingleSpace(isAfterSpace);
248
253
 
249
254
  // deal with less propery mixins @{...}
@@ -314,7 +319,12 @@ Beautifier.prototype.beautify = function() {
314
319
  this.indent();
315
320
  this._output.set_indent(this._indentLevel);
316
321
  } else {
317
- this.indent();
322
+ // inside mixin and first param is object
323
+ if (previous_ch === '(') {
324
+ this._output.space_before_token = false;
325
+ } else if (previous_ch !== ',') {
326
+ this.indent();
327
+ }
318
328
  this.print_string(this._ch);
319
329
  }
320
330
 
@@ -346,7 +356,21 @@ Beautifier.prototype.beautify = function() {
346
356
  this._output.add_new_line(true);
347
357
  }
348
358
  }
359
+ if (this._input.peek() === ')') {
360
+ this._output.trim(true);
361
+ if (this._options.brace_style === "expand") {
362
+ this._output.add_new_line(true);
363
+ }
364
+ }
349
365
  } else if (this._ch === ":") {
366
+
367
+ for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
368
+ if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
369
+ insideNonSemiColonValues = true;
370
+ break;
371
+ }
372
+ }
373
+
350
374
  if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
351
375
  // 'property: value' delimiter
352
376
  // which could be in a conditional group query
@@ -379,6 +403,7 @@ Beautifier.prototype.beautify = function() {
379
403
  this.print_string(this._ch + this.eatString(this._ch));
380
404
  this.eatWhitespace(true);
381
405
  } else if (this._ch === ';') {
406
+ insideNonSemiColonValues = false;
382
407
  if (parenLevel === 0) {
383
408
  if (insidePropertyValue) {
384
409
  this.outdent();
@@ -420,20 +445,32 @@ Beautifier.prototype.beautify = function() {
420
445
  } else {
421
446
  this.preserveSingleSpace(isAfterSpace);
422
447
  this.print_string(this._ch);
423
- this.eatWhitespace();
424
- parenLevel++;
425
- this.indent();
448
+
449
+ // handle scss/sass map
450
+ if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
451
+ this._output.add_new_line();
452
+ insideScssMap = true;
453
+ } else {
454
+ this.eatWhitespace();
455
+ parenLevel++;
456
+ this.indent();
457
+ }
426
458
  }
427
459
  } else if (this._ch === ')') {
428
460
  if (parenLevel) {
429
461
  parenLevel--;
430
462
  this.outdent();
431
463
  }
464
+ if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
465
+ insideScssMap = false;
466
+ this.outdent();
467
+ this._output.add_new_line();
468
+ }
432
469
  this.print_string(this._ch);
433
470
  } else if (this._ch === ',') {
434
471
  this.print_string(this._ch);
435
472
  this.eatWhitespace(true);
436
- if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
473
+ if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
437
474
  this._output.add_new_line();
438
475
  } else {
439
476
  this._output.space_before_token = true;
@@ -467,8 +504,13 @@ Beautifier.prototype.beautify = function() {
467
504
  this.print_string(' ');
468
505
  this.print_string(this._ch);
469
506
  } else {
470
- this.preserveSingleSpace(isAfterSpace);
507
+ var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
508
+ this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
471
509
  this.print_string(this._ch);
510
+
511
+ if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
512
+ this._output.add_new_line();
513
+ }
472
514
  }
473
515
  }
474
516
 
@@ -612,7 +612,7 @@ var TagOpenParserToken = function(parent, raw_token) {
612
612
 
613
613
  // handle "{{#> myPartial}}
614
614
  if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
615
- this.tag_check = raw_token.next.text;
615
+ this.tag_check = raw_token.next.text.split(' ')[0];
616
616
  }
617
617
  }
618
618
  this.tag_check = this.tag_check.toLowerCase();
@@ -191,6 +191,7 @@ Beautifier.prototype.create_flags = function(flags_base, mode) {
191
191
  in_case_statement: false, // switch(..){ INSIDE HERE }
192
192
  in_case: false, // we're on the exact line with "case 0:"
193
193
  case_body: false, // the indented case-action block
194
+ case_block: false, // the indented case-action block is wrapped with {}
194
195
  indentation_level: next_indent_level,
195
196
  alignment: 0,
196
197
  line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
@@ -690,10 +691,10 @@ Beautifier.prototype.handle_start_block = function(current_token) {
690
691
  )) {
691
692
  // We don't support TypeScript,but we didn't break it for a very long time.
692
693
  // We'll try to keep not breaking it.
693
- if (!in_array(this._last_last_text, ['class', 'interface'])) {
694
- this.set_mode(MODE.ObjectLiteral);
695
- } else {
694
+ if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
696
695
  this.set_mode(MODE.BlockStatement);
696
+ } else {
697
+ this.set_mode(MODE.ObjectLiteral);
697
698
  }
698
699
  } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
699
700
  // arrow function: (param1, paramN) => { statements }
@@ -809,7 +810,7 @@ Beautifier.prototype.handle_word = function(current_token) {
809
810
  if (current_token.type === TOKEN.RESERVED) {
810
811
  if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
811
812
  current_token.type = TOKEN.WORD;
812
- } else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
813
+ } else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
813
814
  current_token.type = TOKEN.WORD;
814
815
  } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
815
816
  current_token.type = TOKEN.WORD;
@@ -869,7 +870,7 @@ Beautifier.prototype.handle_word = function(current_token) {
869
870
 
870
871
  if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
871
872
  this.print_newline();
872
- if (this._flags.last_token.type !== TOKEN.END_BLOCK && (this._flags.case_body || this._options.jslint_happy)) {
873
+ if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
873
874
  // switch cases following one another
874
875
  this.deindent();
875
876
  }
@@ -1183,7 +1184,9 @@ Beautifier.prototype.handle_operator = function(current_token) {
1183
1184
  if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
1184
1185
  this.indent();
1185
1186
  this.print_newline();
1187
+ this._flags.case_block = false;
1186
1188
  } else {
1189
+ this._flags.case_block = true;
1187
1190
  this._output.space_before_token = true;
1188
1191
  }
1189
1192
  return;
@@ -1281,7 +1284,7 @@ Beautifier.prototype.handle_operator = function(current_token) {
1281
1284
 
1282
1285
  // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
1283
1286
  // if there is a newline between -- or ++ and anything else we should preserve it.
1284
- if (current_token.newlines && (current_token.text === '--' || current_token.text === '++')) {
1287
+ if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
1285
1288
  this.print_newline(false, true);
1286
1289
  }
1287
1290
 
@@ -74,7 +74,7 @@ var digit = /[0-9]/;
74
74
  var dot_pattern = /[^\d\.]/;
75
75
 
76
76
  var positionable_operators = (
77
- ">>> === !== " +
77
+ ">>> === !== &&= ??= ||= " +
78
78
  "<< && >= ** != == <= >> || ?? |> " +
79
79
  "< / - + > : & % ? ^ | *").split(' ');
80
80
 
@@ -82,7 +82,7 @@ var positionable_operators = (
82
82
  // Also, you must update possitionable operators separately from punct
83
83
  var punct =
84
84
  ">>>= " +
85
- "... >>= <<= === >>> !== **= " +
85
+ "... >>= <<= === >>> !== **= &&= ??= ||= " +
86
86
  "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
87
87
  "= ! ? > < : / ^ - + * & % ~ |";
88
88
 
@@ -126,7 +126,7 @@ var Tokenizer = function(input_string, options) {
126
126
  html_comment_end: pattern_reader.matching(/-->/),
127
127
  include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
128
128
  shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
129
- 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*>/),
129
+ xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[^}]+?}|!\[CDATA\[[^\]]*?\]\]|)(\s*{[^}]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{([^{}]|{[^}]+?})+?}))*\s*(\/?)\s*>/),
130
130
  single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
131
131
  double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
132
132
  template_text: templatable.until(/[`\\$]/),