Fix language features when using nested Vue `<template>` (#532)
parent
ef111a9bc7
commit
cd1678bd8d
|
@ -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,19 +135,21 @@ export function getLanguageBoundaries(
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (let token of lexer) {
|
for (let token of lexer) {
|
||||||
if (token.type.endsWith('BlockStart')) {
|
if (!token.type.startsWith('nested')) {
|
||||||
let position = indexToPosition(text, offset)
|
if (token.type.endsWith('BlockStart')) {
|
||||||
if (!boundaries[boundaries.length - 1].range.end) {
|
let position = indexToPosition(text, offset)
|
||||||
|
if (!boundaries[boundaries.length - 1].range.end) {
|
||||||
|
boundaries[boundaries.length - 1].range.end = position
|
||||||
|
}
|
||||||
|
type = token.type.replace(/BlockStart$/, '')
|
||||||
|
boundaries.push({ type, range: { start: position, end: undefined } })
|
||||||
|
} else if (token.type.endsWith('BlockEnd')) {
|
||||||
|
let position = indexToPosition(text, offset)
|
||||||
boundaries[boundaries.length - 1].range.end = position
|
boundaries[boundaries.length - 1].range.end = position
|
||||||
|
boundaries.push({ type: defaultType, range: { start: position, end: undefined } })
|
||||||
|
} else if (token.type === 'lang') {
|
||||||
|
boundaries[boundaries.length - 1].type = token.text
|
||||||
}
|
}
|
||||||
type = token.type.replace(/BlockStart$/, '')
|
|
||||||
boundaries.push({ type, range: { start: position, end: undefined } })
|
|
||||||
} else if (token.type.endsWith('BlockEnd')) {
|
|
||||||
let position = indexToPosition(text, offset)
|
|
||||||
boundaries[boundaries.length - 1].range.end = position
|
|
||||||
boundaries.push({ type: defaultType, range: { start: position, end: undefined } })
|
|
||||||
} else if (token.type === 'lang') {
|
|
||||||
boundaries[boundaries.length - 1].type = token.text
|
|
||||||
}
|
}
|
||||||
offset += token.text.length
|
offset += token.text.length
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue