Skip to content

Commit cd1678b

Browse files
authored
Fix language features when using nested Vue <template> (#532)
1 parent ef111a9 commit cd1678b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

packages/tailwindcss-language-service/src/util/getLanguageBoundaries.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ let vueStates = {
8181
},
8282
html: {
8383
htmlBlockEnd: { match: '</template>', pop: 1 },
84+
nestedBlockStart: { match: '<template', push: 'nestedBlock' },
85+
...text,
86+
},
87+
nestedBlock: {
88+
nestedStart: { match: '>', next: 'nested' },
89+
nestedBlockEnd: { match: '/>', pop: 1 },
90+
...text,
91+
},
92+
nested: {
93+
nestedBlockEnd: { match: '</template>', pop: 1 },
94+
nestedBlockStart: { match: '<template', push: 'nestedBlock' },
8495
...text,
8596
},
8697
}
@@ -124,19 +135,21 @@ export function getLanguageBoundaries(
124135

125136
try {
126137
for (let token of lexer) {
127-
if (token.type.endsWith('BlockStart')) {
128-
let position = indexToPosition(text, offset)
129-
if (!boundaries[boundaries.length - 1].range.end) {
138+
if (!token.type.startsWith('nested')) {
139+
if (token.type.endsWith('BlockStart')) {
140+
let position = indexToPosition(text, offset)
141+
if (!boundaries[boundaries.length - 1].range.end) {
142+
boundaries[boundaries.length - 1].range.end = position
143+
}
144+
type = token.type.replace(/BlockStart$/, '')
145+
boundaries.push({ type, range: { start: position, end: undefined } })
146+
} else if (token.type.endsWith('BlockEnd')) {
147+
let position = indexToPosition(text, offset)
130148
boundaries[boundaries.length - 1].range.end = position
149+
boundaries.push({ type: defaultType, range: { start: position, end: undefined } })
150+
} else if (token.type === 'lang') {
151+
boundaries[boundaries.length - 1].type = token.text
131152
}
132-
type = token.type.replace(/BlockStart$/, '')
133-
boundaries.push({ type, range: { start: position, end: undefined } })
134-
} else if (token.type.endsWith('BlockEnd')) {
135-
let position = indexToPosition(text, offset)
136-
boundaries[boundaries.length - 1].range.end = position
137-
boundaries.push({ type: defaultType, range: { start: position, end: undefined } })
138-
} else if (token.type === 'lang') {
139-
boundaries[boundaries.length - 1].type = token.text
140153
}
141154
offset += token.text.length
142155
}

0 commit comments

Comments
 (0)