Fix paren indenting

This commit is contained in:
Liam Newman 2019-04-27 19:14:13 -07:00
parent 737b425ad2
commit 12c476d997
5 changed files with 28 additions and 13 deletions

View File

@ -392,22 +392,31 @@ Beautifier.prototype.beautify = function() {
if (this._input.lookBack("url")) {
this.print_string(this._ch);
this.eatWhitespace();
parenLevel++;
this.indent();
this._ch = this._input.next();
if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
this._input.back();
parenLevel++;
} else if (this._ch) {
this.print_string(this._ch + this.eatString(')'));
if (parenLevel) {
parenLevel--;
this.outdent();
}
}
} else {
parenLevel++;
this.preserveSingleSpace(isAfterSpace);
this.print_string(this._ch);
this.eatWhitespace();
parenLevel++;
this.indent();
}
} else if (this._ch === ')') {
if (parenLevel) {
parenLevel--;
this.outdent();
}
this.print_string(this._ch);
parenLevel = Math.max(parenLevel - 1, 0);
} else if (this._ch === ',') {
this.print_string(this._ch);
this.eatWhitespace(true);

View File

@ -10494,8 +10494,8 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
'}\n' +
'.set {\n' +
' each(@set, {\n' +
' @{key}-@{index}: @value;\n' +
' }\n' +
' @{key}-@{index}: @value;\n' +
' }\n' +
' );\n' +
'}');
t('@light-blue: @nice-blue + #111;');

View File

@ -413,20 +413,27 @@ class Beautifier:
if self._input.lookBack("url"):
self.print_string(self._ch)
self.eatWhitespace()
parenLevel += 1
self.indent()
self._ch = self._input.next()
if self._ch in {')', '"', '\''}:
self._input.back()
parenLevel += 1
elif self._ch is not None:
self.print_string(self._ch + self.eatString(')'))
if parenLevel:
parenLevel -= 1
self.outdent()
else:
parenLevel += 1
self.preserveSingleSpace(isAfterSpace)
self.print_string(self._ch)
self.eatWhitespace()
parenLevel += 1
self.indent()
elif self._ch == ')':
if parenLevel:
parenLevel -= 1
self.outdent()
self.print_string(self._ch)
parenLevel = max(parenLevel - 1, 0)
elif self._ch == ',':
self.print_string(self._ch)
self.eatWhitespace(True)

View File

@ -10379,8 +10379,8 @@ class CSSBeautifierTest(unittest.TestCase):
'}\n' +
'.set {\n' +
' each(@set, {\n' +
' @{key}-@{index}: @value;\n' +
' }\n' +
' @{key}-@{index}: @value;\n' +
' }\n' +
' );\n' +
'}')
t('@light-blue: @nice-blue + #111;')

View File

@ -1297,9 +1297,8 @@ exports.test_data = {
'}',
'.set {',
' each(@set, {',
' @{key}-@{index}: @value;',
' }',
// This is not optimal formatting, included to document current behavior.
' @{key}-@{index}: @value;',
' }',
' );',
'}'
]