From: Evan You Date: Mon, 27 Nov 2023 06:49:13 +0000 (+0800) Subject: fix(compiler-core): fix line/column tracking when fast forwarding X-Git-Tag: v3.4.0-alpha.2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e65ea481f74db8649df8110a031cbdc98f98c84;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-core): fix line/column tracking when fast forwarding --- diff --git a/packages/compiler-core/src/tokenizer.ts b/packages/compiler-core/src/tokenizer.ts index 39b64622dc..22ff504dbe 100644 --- a/packages/compiler-core/src/tokenizer.ts +++ b/packages/compiler-core/src/tokenizer.ts @@ -463,7 +463,11 @@ export default class Tokenizer { */ private fastForwardTo(c: number): boolean { while (++this.index < this.buffer.length) { - if (this.buffer.charCodeAt(this.index) === c) { + const cc = this.buffer.charCodeAt(this.index) + if (cc === CharCodes.NewLine) { + this.newlines.push(this.index) + } + if (cc === c) { return true } } diff --git a/packages/compiler-sfc/__tests__/parse.spec.ts b/packages/compiler-sfc/__tests__/parse.spec.ts index 7c8efdfc40..c19232a703 100644 --- a/packages/compiler-sfc/__tests__/parse.spec.ts +++ b/packages/compiler-sfc/__tests__/parse.spec.ts @@ -7,15 +7,61 @@ describe('compiler:sfc', () => { test('style block', () => { // Padding determines how many blank lines will there be before the style block const padding = Math.round(Math.random() * 10) - const style = parse( - `${'\n'.repeat(padding)}\n` - ).descriptor.styles[0] + const src = + `${'\n'.repeat(padding)}` + + ` - expect(style.map).not.toBeUndefined() + - const consumer = new SourceMapConsumer(style.map!) + + +` + const { + descriptor: { styles } + } = parse(src) + + expect(styles[0].map).not.toBeUndefined() + const consumer = new SourceMapConsumer(styles[0].map!) + const lineOffset = + src.slice(0, src.indexOf(`