fix(compiler-core): do not increase newlines in `InEntity` state (#13362)

This commit is contained in:
山吹色御守 2025-06-04 18:39:05 -07:00 committed by GitHub
parent 762fae4b57
commit f05a8d613b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -2271,6 +2271,11 @@ describe('compiler: parse', () => {
expect(span.loc.start.offset).toBe(0) expect(span.loc.start.offset).toBe(0)
expect(span.loc.end.offset).toBe(27) expect(span.loc.end.offset).toBe(27)
}) })
test('correct loc when a line in attribute value ends with &', () => {
const [span] = baseParse(`<span v-if="foo &&\nbar"></span>`).children
expect(span.loc.end.line).toBe(2)
})
}) })
describe('decodeEntities option', () => { describe('decodeEntities option', () => {

View File

@ -929,7 +929,7 @@ export default class Tokenizer {
this.buffer = input this.buffer = input
while (this.index < this.buffer.length) { while (this.index < this.buffer.length) {
const c = this.buffer.charCodeAt(this.index) const c = this.buffer.charCodeAt(this.index)
if (c === CharCodes.NewLine) { if (c === CharCodes.NewLine && this.state !== State.InEntity) {
this.newlines.push(this.index) this.newlines.push(this.index)
} }
switch (this.state) { switch (this.state) {