From fff28cb9ebcc669b7f66c2c2ed8dae97e23d2ebf Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 1 Mar 2019 22:56:13 +0800 Subject: [PATCH] fix(compiler): set end location for incomplete elements (#9598) --- src/compiler/parser/html-parser.js | 2 +- src/compiler/parser/index.js | 3 ++- test/unit/modules/compiler/compiler-options.spec.js | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler/parser/html-parser.js b/src/compiler/parser/html-parser.js index b574e9c40ed..f93c098fa5a 100644 --- a/src/compiler/parser/html-parser.js +++ b/src/compiler/parser/html-parser.js @@ -279,7 +279,7 @@ export function parseHTML (html, options) { ) { options.warn( `tag <${stack[i].tag}> has no matching end tag.`, - { start: stack[i].start } + { start: stack[i].start, end: stack[i].end } ) } if (options.end) { diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 01cbadd1ded..0689eb873dd 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -210,7 +210,7 @@ export function parse ( shouldDecodeNewlinesForHref: options.shouldDecodeNewlinesForHref, shouldKeepComment: options.comments, outputSourceRange: options.outputSourceRange, - start (tag, attrs, unary, start) { + start (tag, attrs, unary, start, end) { // check namespace. // inherit parent ns if there is one const ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag) @@ -229,6 +229,7 @@ export function parse ( if (process.env.NODE_ENV !== 'production') { if (options.outputSourceRange) { element.start = start + element.end = end element.rawAttrsMap = element.attrsList.reduce((cumulated, attr) => { cumulated[attr.name] = attr return cumulated diff --git a/test/unit/modules/compiler/compiler-options.spec.js b/test/unit/modules/compiler/compiler-options.spec.js index 4b17545bd5b..a0cfcdde5ca 100644 --- a/test/unit/modules/compiler/compiler-options.spec.js +++ b/test/unit/modules/compiler/compiler-options.spec.js @@ -140,6 +140,11 @@ describe('compile options', () => { expect(compiled.errors[0].end).toBe(17) expect(compiled.errors[1].start).toBe(18) expect(compiled.errors[1].end).toBe(29) + + compiled = compile('
', { outputSourceRange: true }) + expect(compiled.errors.length).toBe(1) + expect(compiled.errors[0].start).toBe(5) + expect(compiled.errors[0].end).toBe(11) }) it('should collect source range for binding keys', () => {