Fix language features when using nested Vue `<template>` (#532)

master
Brad Cornes 2022-04-19 15:02:27 +01:00 committed by GitHub
parent ef111a9bc7
commit cd1678bd8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 11 deletions

View File

@ -81,6 +81,17 @@ let vueStates = {
}, },
html: { html: {
htmlBlockEnd: { match: '</template>', pop: 1 }, htmlBlockEnd: { match: '</template>', pop: 1 },
nestedBlockStart: { match: '<template', push: 'nestedBlock' },
...text,
},
nestedBlock: {
nestedStart: { match: '>', next: 'nested' },
nestedBlockEnd: { match: '/>', pop: 1 },
...text,
},
nested: {
nestedBlockEnd: { match: '</template>', pop: 1 },
nestedBlockStart: { match: '<template', push: 'nestedBlock' },
...text, ...text,
}, },
} }
@ -124,6 +135,7 @@ export function getLanguageBoundaries(
try { try {
for (let token of lexer) { for (let token of lexer) {
if (!token.type.startsWith('nested')) {
if (token.type.endsWith('BlockStart')) { if (token.type.endsWith('BlockStart')) {
let position = indexToPosition(text, offset) let position = indexToPosition(text, offset)
if (!boundaries[boundaries.length - 1].range.end) { if (!boundaries[boundaries.length - 1].range.end) {
@ -138,6 +150,7 @@ export function getLanguageBoundaries(
} else if (token.type === 'lang') { } else if (token.type === 'lang') {
boundaries[boundaries.length - 1].type = token.text boundaries[boundaries.length - 1].type = token.text
} }
}
offset += token.text.length offset += token.text.length
} }
} catch { } catch {