fix(compiler-core): fix loc.source for end tags with whitespace before >
close #10694 close #10695
This commit is contained in:
parent
f709238c30
commit
16174da21d
|
@ -2070,6 +2070,16 @@ describe('compiler: parse', () => {
|
|||
baseParse(`<Foo>`, { parseMode: 'sfc', onError() {} })
|
||||
expect(() => baseParse(`{ foo }`)).not.toThrow()
|
||||
})
|
||||
|
||||
test('correct loc when the closing > is foarmatted', () => {
|
||||
const [span] = baseParse(`<span></span
|
||||
|
||||
>`).children
|
||||
|
||||
expect(span.loc.source).toBe('<span></span\n \n >')
|
||||
expect(span.loc.start.offset).toBe(0)
|
||||
expect(span.loc.end.offset).toBe(27)
|
||||
})
|
||||
})
|
||||
|
||||
describe('decodeEntities option', () => {
|
||||
|
|
|
@ -613,7 +613,7 @@ function onCloseTag(el: ElementNode, end: number, isImplied = false) {
|
|||
// implied close, end should be backtracked to close
|
||||
setLocEnd(el.loc, backTrack(end, CharCodes.Lt))
|
||||
} else {
|
||||
setLocEnd(el.loc, end + 1)
|
||||
setLocEnd(el.loc, lookAhead(end, CharCodes.Gt) + 1)
|
||||
}
|
||||
|
||||
if (tokenizer.inSFCRoot) {
|
||||
|
@ -736,6 +736,12 @@ function onCloseTag(el: ElementNode, end: number, isImplied = false) {
|
|||
}
|
||||
}
|
||||
|
||||
function lookAhead(index: number, c: number) {
|
||||
let i = index
|
||||
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++
|
||||
return i
|
||||
}
|
||||
|
||||
function backTrack(index: number, c: number) {
|
||||
let i = index
|
||||
while (currentInput.charCodeAt(i) !== c && i >= 0) i--
|
||||
|
|
Loading…
Reference in New Issue