LESS mixin fix

This commit is contained in:
Hanabishi 2019-04-21 02:07:29 +05:00
parent d88c6a6462
commit c374263b5a
5 changed files with 77 additions and 27 deletions

View File

@ -366,21 +366,27 @@ Beautifier.prototype.beautify = function() {
this.print_string(this._ch + this.eatString(this._ch));
this.eatWhitespace(true);
} else if (this._ch === ';') {
if (insidePropertyValue) {
this.outdent();
insidePropertyValue = false;
}
insideAtExtend = false;
insideAtImport = false;
this.print_string(this._ch);
this.eatWhitespace(true);
if (parenLevel < 1) {
if (insidePropertyValue) {
this.outdent();
insidePropertyValue = false;
}
insideAtExtend = false;
insideAtImport = false;
this.print_string(this._ch);
this.eatWhitespace(true);
// This maintains single line comments on the same
// line. Block comments are also affected, but
// a new line is always output before one inside
// that section
if (this._input.peek() !== '/') {
this._output.add_new_line();
// This maintains single line comments on the same
// line. Block comments are also affected, but
// a new line is always output before one inside
// that section
if (this._input.peek() !== '/') {
this._output.add_new_line();
}
} else {
this.print_string(this._ch);
this.eatWhitespace(true);
this._output.space_before_token = true;
}
} else if (this._ch === '(') { // may be a url
if (this._input.lookBack("url")) {

View File

@ -10718,6 +10718,19 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
'}');
//============================================================
// LESS mixins
reset_options();
set_name('LESS mixins');
test_fragment(
'.btn {\n' +
' .generate-animation(@mykeyframes, 1.4s, .5s, 1, ease-out);\n' +
'}\n' +
'.mymixin(@color: #ccc; @border-width: 1px) {\n' +
' border: @border-width solid @color;\n' +
'}');
//============================================================
//
reset_options();

View File

@ -388,20 +388,25 @@ class Beautifier:
self.print_string(self._ch + self.eatString(self._ch))
self.eatWhitespace(True)
elif self._ch == ';':
if insidePropertyValue:
self.outdent()
insidePropertyValue = False
insideAtExtend = False
insideAtImport = False
self.print_string(self._ch)
self.eatWhitespace(True)
if parenLevel < 1:
if insidePropertyValue:
self.outdent()
insidePropertyValue = False
insideAtExtend = False
insideAtImport = False
self.print_string(self._ch)
self.eatWhitespace(True)
# This maintains single line comments on the same
# line. Block comments are also affected, but
# a new line is always output before one inside
# that section
if self._input.peek() is not '/':
self._output.add_new_line()
# This maintains single line comments on the same
# line. Block comments are also affected, but
# a new line is always output before one inside
# that section
if self._input.peek() is not '/':
self._output.add_new_line()
else:
self.print_string(self._ch)
self.eatWhitespace(True)
self._output.space_before_token = True
elif self._ch == '(':
# may be a url
if self._input.lookBack("url"):

View File

@ -10594,6 +10594,18 @@ class CSSBeautifierTest(unittest.TestCase):
'}')
#============================================================
# LESS mixins
self.reset_options()
test_fragment(
'.btn {\n' +
' .generate-animation(@mykeyframes, 1.4s, .5s, 1, ease-out);\n' +
'}\n' +
'.mymixin(@color: #ccc; @border-width: 1px) {\n' +
' border: @border-width solid @color;\n' +
'}')
#============================================================
#
self.reset_options()

View File

@ -1533,6 +1533,20 @@ exports.test_data = {
]
}]
}, {
name: "LESS mixins",
description: "",
tests: [{
fragment: true,
unchanged: [
'.btn {',
' .generate-animation(@mykeyframes, 1.4s, .5s, 1, ease-out);',
'}',
'.mymixin(@color: #ccc; @border-width: 1px) {',
' border: @border-width solid @color;',
'}'
]
}]
}, {
}
]