Skip to content

Commit 81446ac

Browse files
committed
update class attribute lexers to fix matching of "computed" attributes
1 parent 825b067 commit 81446ac

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/lsp/util/lexers.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,51 @@ import { lazy } from './lazy'
33

44
const classAttributeStates: { [x: string]: moo.Rules } = {
55
doubleClassList: {
6-
lbrace: { match: /(?<!\\)\{/, push: 'interp' },
6+
lbrace: { match: /(?<!\\)\{/, push: 'interpBrace' },
77
rbrace: { match: /(?<!\\)\}/, pop: 1 },
88
end: { match: /(?<!\\)"/, pop: 1 },
99
classlist: { match: /[\s\S]/, lineBreaks: true },
1010
},
1111
singleClassList: {
12-
lbrace: { match: /(?<!\\)\{/, push: 'interp' },
12+
lbrace: { match: /(?<!\\)\{/, push: 'interpBrace' },
1313
rbrace: { match: /(?<!\\)\}/, pop: 1 },
1414
end: { match: /(?<!\\)'/, pop: 1 },
1515
classlist: { match: /[\s\S]/, lineBreaks: true },
1616
},
1717
tickClassList: {
18-
lbrace: { match: /(?<=(?<!\\)\$)\{/, push: 'interp' },
18+
lbrace: { match: /(?<=(?<!\\)\$)\{/, push: 'interpBrace' },
1919
rbrace: { match: /(?<!\\)\}/, pop: 1 },
2020
end: { match: /(?<!\\)`/, pop: 1 },
2121
classlist: { match: /[\s\S]/, lineBreaks: true },
2222
},
23-
interp: {
23+
interpBrace: {
2424
startSingle: { match: /(?<!\\)'/, push: 'singleClassList' },
2525
startDouble: { match: /(?<!\\)"/, push: 'doubleClassList' },
2626
startTick: { match: /(?<!\\)`/, push: 'tickClassList' },
27-
lbrace: { match: /(?<!\\)\{/, push: 'interp' },
27+
lbrace: { match: /(?<!\\)\{/, push: 'interpBrace' },
2828
rbrace: { match: /(?<!\\)\}/, pop: 1 },
2929
text: { match: /[\s\S]/, lineBreaks: true },
3030
},
31+
interpSingle: {
32+
startDouble: { match: /(?<!\\)"/, push: 'doubleClassList' },
33+
startTick: { match: /(?<!\\)`/, push: 'tickClassList' },
34+
single: { match: /(?<!\\)'/, pop: 1 },
35+
text: { match: /[\s\S]/, lineBreaks: true },
36+
},
37+
interpDouble: {
38+
startSingle: { match: /(?<!\\)'/, push: 'singleClassList' },
39+
startTick: { match: /(?<!\\)`/, push: 'tickClassList' },
40+
double: { match: /(?<!\\)"/, pop: 1 },
41+
text: { match: /[\s\S]/, lineBreaks: true },
42+
},
3143
}
3244

3345
export const getClassAttributeLexer = lazy(() =>
3446
moo.states({
3547
main: {
3648
start1: { match: '"', push: 'doubleClassList' },
3749
start2: { match: "'", push: 'singleClassList' },
38-
start3: { match: '{', push: 'interp' },
50+
start3: { match: '{', push: 'interpBrace' },
3951
},
4052
...classAttributeStates,
4153
})
@@ -44,10 +56,10 @@ export const getClassAttributeLexer = lazy(() =>
4456
export const getComputedClassAttributeLexer = lazy(() =>
4557
moo.states({
4658
main: {
47-
quote: { match: /['"{]/, push: 'interp' },
59+
lbrace: { match: '{', push: 'interpBrace' },
60+
single: { match: "'", push: 'interpSingle' },
61+
double: { match: '"', push: 'interpDouble' },
4862
},
49-
// TODO: really this should use a different interp definition that is
50-
// terminated correctly based on the initial quote type
5163
...classAttributeStates,
5264
})
5365
)

0 commit comments

Comments
 (0)