mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-24 07:11:17 +00:00
Merge pull request #1459 from MacKLess/less
Fix LESS variable formatting
This commit is contained in:
commit
6e95ef83af
@ -195,6 +195,8 @@ function Beautifier(source_text, options) {
|
||||
parenLevel = 0;
|
||||
|
||||
var insideRule = false;
|
||||
// This is the value side of a property value pair (blue in the following ex)
|
||||
// label { content: blue }
|
||||
var insidePropertyValue = false;
|
||||
var enteringConditionalGroup = false;
|
||||
var insideAtExtend = false;
|
||||
@ -263,6 +265,9 @@ function Beautifier(source_text, options) {
|
||||
if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
|
||||
enteringConditionalGroup = true;
|
||||
}
|
||||
// might be less variable
|
||||
} else if (!insideRule && parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
|
||||
insidePropertyValue = true;
|
||||
}
|
||||
}
|
||||
} else if (ch === '#' && input.peek() === '{') {
|
||||
|
@ -466,11 +466,7 @@ function Tokenizer(input_string, opts) {
|
||||
return [trim(resulting_string) + '\n', 'TK_UNKNOWN'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Spidermonkey-specific sharp variables for circular references
|
||||
// https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
|
||||
// http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
|
||||
// Spidermonkey-specific sharp variables for circular references. Considered obsolete.
|
||||
var sharp = '#';
|
||||
if (input.hasNext() && input.testChar(digit)) {
|
||||
do {
|
||||
|
@ -9318,6 +9318,24 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
|
||||
t('@page: first {}');
|
||||
|
||||
|
||||
//============================================================
|
||||
// Issue 1411 -- LESS Variable Assignment Spacing
|
||||
reset_options();
|
||||
t(
|
||||
'@set: {\n' +
|
||||
'\tone: blue;\n' +
|
||||
'\ttwo: green;\n' +
|
||||
'\tthree: red;\n' +
|
||||
'}\n' +
|
||||
'.set {\n' +
|
||||
'\teach(@set, {\n' +
|
||||
'\t\t@{key}-@{index}: @value;\n' +
|
||||
'\t}\n' +
|
||||
'\t);\n' +
|
||||
'}');
|
||||
t('@light-blue: @nice-blue + #111;');
|
||||
|
||||
|
||||
//============================================================
|
||||
// SASS/SCSS
|
||||
reset_options();
|
||||
|
@ -284,6 +284,8 @@ class Beautifier:
|
||||
printer.nestedLevel += 1
|
||||
if variableOrRule in self.CONDITIONAL_GROUP_RULE:
|
||||
enteringConditionalGroup = True
|
||||
elif not insideRule and parenLevel == 0 and variableOrRule[-1] == ":":
|
||||
insidePropertyValue = True
|
||||
elif self.ch == '#' and input.peek() == '{':
|
||||
printer.preserveSingleSpace(isAfterSpace)
|
||||
printer.print_string(self.ch + self.eatString('}'))
|
||||
|
@ -9276,6 +9276,24 @@ class CSSBeautifierTest(unittest.TestCase):
|
||||
t('@page: first {}')
|
||||
|
||||
|
||||
#============================================================
|
||||
# Issue 1411 -- LESS Variable Assignment Spacing
|
||||
self.reset_options()
|
||||
t(
|
||||
'@set: {\n' +
|
||||
'\tone: blue;\n' +
|
||||
'\ttwo: green;\n' +
|
||||
'\tthree: red;\n' +
|
||||
'}\n' +
|
||||
'.set {\n' +
|
||||
'\teach(@set, {\n' +
|
||||
'\t\t@{key}-@{index}: @value;\n' +
|
||||
'\t}\n' +
|
||||
'\t);\n' +
|
||||
'}')
|
||||
t('@light-blue: @nice-blue + #111;')
|
||||
|
||||
|
||||
#============================================================
|
||||
# SASS/SCSS
|
||||
self.reset_options()
|
||||
|
@ -588,6 +588,27 @@ exports.test_data = {
|
||||
},
|
||||
{ unchanged: '@page: first {}' }
|
||||
]
|
||||
}, {
|
||||
name: "Issue 1411 -- LESS Variable Assignment Spacing",
|
||||
description: "",
|
||||
tests: [{
|
||||
unchanged: [
|
||||
'@set: {',
|
||||
'\tone: blue;',
|
||||
'\ttwo: green;',
|
||||
'\tthree: red;',
|
||||
'}',
|
||||
'.set {',
|
||||
'\teach(@set, {',
|
||||
'\t\t@{key}-@{index}: @value;',
|
||||
'\t}',
|
||||
// This is not optimal formatting, included to document current behavior.
|
||||
'\t);',
|
||||
'}'
|
||||
]
|
||||
},
|
||||
{ unchanged: '@light-blue: @nice-blue + #111;' }
|
||||
]
|
||||
}, {
|
||||
name: "SASS/SCSS",
|
||||
description: "",
|
||||
|
Loading…
x
Reference in New Issue
Block a user