Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,9 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
value = this.permissiveValue(/[;}]/);
}
}
else if (isVariable) {
value = this.variableValue();
}
// Try to store values as anonymous
// If we need the value later we'll re-parse it in ruleset.parseValue
else {
Expand Down Expand Up @@ -1638,6 +1641,18 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
parserInput.restore();
}
},
variableValue: function () {
let match = this.anonymousValue();
if (match) {
return match;
} else {
const index = parserInput.i;
match = parserInput.$re(/^([^#@$+/'"*`(;{}-]*);|(^[(?!.*\n)^.#@$+/'"*`(;{}-]*)(["'])((?!.*@.*)(?<!.*@.*).+?)\1;/);
if (match) {
return new(tree.Anonymous)(match[0].slice(0, -1), index + currentIndex);
}
}
},
anonymousValue: function () {
const index = parserInput.i;
const match = parserInput.$re(/^([^.#@$+/'"*`(;{}-]*);/);
Expand Down
11 changes: 11 additions & 0 deletions packages/test-data/css/_main/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@
.radio_checked {
border-color: #fff;
}
.mixed {
m-1: "a.hello";
m-2: 'a';
m-3: 'a' a a "a.";
m-4: a "a-" a "abc";
m-5: a "a.ab" c c 'a.bc' abc d;
m-6: a.hello;
m-7: 'a.b' "abc" abc a.b.c 'a.b.c';
m-8: hello;
m-9: 'a.hello';
}
div#apple {
color: blue;
}
Expand Down
22 changes: 22 additions & 0 deletions packages/test-data/less/_main/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@
border-color: #fff;
}

@doubleQuoted: "a.hello";
@quoted: 'a';
@mixedOne: 'a' a a "a.";
@mixedTwo: a "a-" a "abc";
@mixedThree: a "a.ab" c c 'a.bc' abc d;
@mixedFour: a.hello;
@mixedFive: 'a.b' "abc" abc a.b.c 'a.b.c';
@mixedSix: hello;
@mixedSeven: 'a.hello';

.mixed {
m-1: @doubleQuoted;
m-2: @quoted;
m-3: @mixedOne;
m-4: @mixedTwo;
m-5: @mixedThree;
m-6: @mixedFour;
m-7: @mixedFive;
m-8: @mixedSix;
m-9: @mixedSeven;
}

@items:
// Fruit
apple,
Expand Down
Loading