mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-23 20:59:43 +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._output.set_indent(this._indentLevel);
|
||||
} else {
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -346,6 +351,12 @@ Beautifier.prototype.beautify = function() {
|
||||
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 === ":") {
|
||||
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
|
||||
// 'property: value' delimiter
|
||||
|
@ -343,6 +343,10 @@ class Beautifier:
|
||||
self.indent()
|
||||
self._output.set_indent(self._indentLevel)
|
||||
else:
|
||||
# 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)
|
||||
|
||||
@ -372,6 +376,10 @@ class Beautifier:
|
||||
):
|
||||
if self._input.peek() != "}":
|
||||
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 == ":":
|
||||
if (
|
||||
(insideRule or enteringConditionalGroup)
|
||||
|
@ -1361,8 +1361,7 @@ exports.test_data = {
|
||||
'.set {',
|
||||
' each(@set, {',
|
||||
' @{key}-@{index}: @value;',
|
||||
' }',
|
||||
' );',
|
||||
' });',
|
||||
'}'
|
||||
]
|
||||
},
|
||||
@ -1732,6 +1731,20 @@ exports.test_data = {
|
||||
'{{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"',
|
||||
input: '.a{} @import "custom.css";.rule{}',
|
||||
@ -1758,6 +1771,37 @@ exports.test_data = {
|
||||
' &: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',
|
||||
unchanged: [
|
||||
|
Loading…
Reference in New Issue
Block a user