mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-27 14:40:23 +00:00
Merge pull request #2017 from mhnaeem/bug/less-mixins-with-curly-braces
[LESS] Fixing issues with spacing when an object literal lives inside a mixin
This commit is contained in:
commit
51a283a476
@ -314,7 +314,12 @@ Beautifier.prototype.beautify = function() {
|
|||||||
this.indent();
|
this.indent();
|
||||||
this._output.set_indent(this._indentLevel);
|
this._output.set_indent(this._indentLevel);
|
||||||
} else {
|
} else {
|
||||||
this.indent();
|
// inside mixin and first param is object
|
||||||
|
if (previous_ch === '(') {
|
||||||
|
this._output.space_before_token = false;
|
||||||
|
} else if (previous_ch !== ',') {
|
||||||
|
this.indent();
|
||||||
|
}
|
||||||
this.print_string(this._ch);
|
this.print_string(this._ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,6 +351,12 @@ Beautifier.prototype.beautify = function() {
|
|||||||
this._output.add_new_line(true);
|
this._output.add_new_line(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this._input.peek() === ')') {
|
||||||
|
this._output.trim(true);
|
||||||
|
if (this._options.brace_style === "expand") {
|
||||||
|
this._output.add_new_line(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (this._ch === ":") {
|
} else if (this._ch === ":") {
|
||||||
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
|
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
|
||||||
// 'property: value' delimiter
|
// 'property: value' delimiter
|
||||||
|
@ -343,7 +343,11 @@ class Beautifier:
|
|||||||
self.indent()
|
self.indent()
|
||||||
self._output.set_indent(self._indentLevel)
|
self._output.set_indent(self._indentLevel)
|
||||||
else:
|
else:
|
||||||
self.indent()
|
# inside mixin and first param is object
|
||||||
|
if previous_ch == "(":
|
||||||
|
self._output.space_before_token = False
|
||||||
|
elif previous_ch != ",":
|
||||||
|
self.indent()
|
||||||
self.print_string(self._ch)
|
self.print_string(self._ch)
|
||||||
|
|
||||||
self.eatWhitespace(True)
|
self.eatWhitespace(True)
|
||||||
@ -372,6 +376,10 @@ class Beautifier:
|
|||||||
):
|
):
|
||||||
if self._input.peek() != "}":
|
if self._input.peek() != "}":
|
||||||
self._output.add_new_line(True)
|
self._output.add_new_line(True)
|
||||||
|
if self._input.peek() == ")":
|
||||||
|
self._output.trim(True)
|
||||||
|
if self._options.brace_style == "expand":
|
||||||
|
self._output.add_new_line(True)
|
||||||
elif self._ch == ":":
|
elif self._ch == ":":
|
||||||
if (
|
if (
|
||||||
(insideRule or enteringConditionalGroup)
|
(insideRule or enteringConditionalGroup)
|
||||||
|
@ -1360,9 +1360,8 @@ exports.test_data = {
|
|||||||
'}',
|
'}',
|
||||||
'.set {',
|
'.set {',
|
||||||
' each(@set, {',
|
' each(@set, {',
|
||||||
' @{key}-@{index}: @value;',
|
' @{key}-@{index}: @value;',
|
||||||
' }',
|
' });',
|
||||||
' );',
|
|
||||||
'}'
|
'}'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1732,6 +1731,20 @@ exports.test_data = {
|
|||||||
'{{empty_line_indent}} width: auto;',
|
'{{empty_line_indent}} width: auto;',
|
||||||
'}'
|
'}'
|
||||||
]
|
]
|
||||||
|
}, {
|
||||||
|
comment: 'mixins call with object notation, and brace_style="expand"',
|
||||||
|
input: [
|
||||||
|
'.example({',
|
||||||
|
' color:red;',
|
||||||
|
'});'
|
||||||
|
],
|
||||||
|
output: [
|
||||||
|
'.example(',
|
||||||
|
' {',
|
||||||
|
' color:red;',
|
||||||
|
' }',
|
||||||
|
');'
|
||||||
|
]
|
||||||
}, {
|
}, {
|
||||||
comment: 'integration test of newline_between_rules, imports, and brace_style="expand"',
|
comment: 'integration test of newline_between_rules, imports, and brace_style="expand"',
|
||||||
input: '.a{} @import "custom.css";.rule{}',
|
input: '.a{} @import "custom.css";.rule{}',
|
||||||
@ -1758,6 +1771,37 @@ exports.test_data = {
|
|||||||
' &:extend(a:hover);',
|
' &:extend(a:hover);',
|
||||||
'}'
|
'}'
|
||||||
]
|
]
|
||||||
|
}, {
|
||||||
|
unchanged: [
|
||||||
|
'.test {',
|
||||||
|
' .example({',
|
||||||
|
' color:red;',
|
||||||
|
' });',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
unchanged: [
|
||||||
|
'.example2({',
|
||||||
|
' display:none;',
|
||||||
|
'});'
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
unchanged: [
|
||||||
|
'.aa {',
|
||||||
|
' .mq-medium(a, {',
|
||||||
|
' background: red;',
|
||||||
|
' });',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
unchanged: [
|
||||||
|
'@selectors: blue, green, red;',
|
||||||
|
'each(@selectors, {',
|
||||||
|
' .sel-@{value} {',
|
||||||
|
' a: b;',
|
||||||
|
' }',
|
||||||
|
'});'
|
||||||
|
]
|
||||||
}, {
|
}, {
|
||||||
comment: 'Ensure simple closing parens do not break behavior',
|
comment: 'Ensure simple closing parens do not break behavior',
|
||||||
unchanged: [
|
unchanged: [
|
||||||
|
Loading…
Reference in New Issue
Block a user