Skip to content

Commit 3fba092

Browse files
chenfuqiangchenfuqiang
chenfuqiang
and
chenfuqiang
authored
fix: parse interpolation error (#159)
Co-authored-by: chenfuqiang <chenfuqiang.xiaogui@bytedance.com>
1 parent b5b9cc9 commit 3fba092

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/nodes/interpolation.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
module.exports = {
44
interpolation(token) {
5-
let first = token;
6-
const tokens = [token];
7-
const validTypes = ['word', '{', '}'];
8-
9-
token = this.tokenizer.nextToken();
5+
const tokens = [token, this.tokenizer.nextToken()];
6+
const validTypes = ['word', '}'];
107

118
// look for @{ but not @[word]{
12-
if (first[1].length > 1 || token[0] !== '{') {
13-
this.tokenizer.back(token);
9+
if (tokens[0][1].length > 1 || tokens[1][0] !== '{') {
10+
this.tokenizer.back(tokens[1]);
1411
return false;
1512
}
1613

14+
token = this.tokenizer.nextToken();
1715
while (token && validTypes.includes(token[0])) {
1816
tokens.push(token);
1917
token = this.tokenizer.nextToken();
2018
}
2119

2220
const words = tokens.map((tokn) => tokn[1]);
23-
[first] = tokens;
21+
const [first] = tokens;
2422
const last = tokens.pop();
2523
const newToken = ['word', words.join(''), first[2], last[2]];
2624

test/parser/interpolation.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ test('parses interpolation', (t) => {
1212
t.is(root.first.first.value, '@{color}');
1313
});
1414

15+
test('parses interpolation when there is not space between selector with open bracket', (t) => {
16+
const root = parse('@{selector}-title{ @{prop}-size: @{color} }');
17+
18+
t.is(root.first.selector, '@{selector}-title');
19+
t.is(root.first.first.prop, '@{prop}-size');
20+
t.is(root.first.first.value, '@{color}');
21+
});
22+
1523
test('parses mixin interpolation', (t) => {
1624
const less = '.browser-prefix(@prop, @args) {\n @{prop}: @args;\n}';
1725
const root = parse(less);

0 commit comments

Comments
 (0)