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', () => {
// 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) {
}
}
+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--