diff --git a/src/compiler/parser/html-parser.js b/src/compiler/parser/html-parser.js index dbc59146331..6bcc3a04dbf 100644 --- a/src/compiler/parser/html-parser.js +++ b/src/compiler/parser/html-parser.js @@ -44,7 +44,7 @@ const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g // #5992 const isIgnoreNewlineTag = makeMap('pre,textarea', true) -const shouldIgnoreFirstNewline = (tag, html) => tag && isIgnoreNewlineTag(tag) && html[0] === '\n' +const shouldIgnoreFirstNewline = (tag, html) => tag && isIgnoreNewlineTag(tag) && html[0] === '\n' && html[1] && html[1] !== '\n' function decodeAttr (value, shouldDecodeNewlines) { const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr diff --git a/test/unit/modules/compiler/parser.spec.js b/test/unit/modules/compiler/parser.spec.js index d6521bbf625..e9999cbd7b5 100644 --- a/test/unit/modules/compiler/parser.spec.js +++ b/test/unit/modules/compiler/parser.spec.js @@ -698,7 +698,7 @@ describe('parser', () => { expect(text.text).toBe('\ndef') const pre2 = ast.children[2] expect(pre2.children[0].type).toBe(3) - expect(pre2.children[0].text).toBe('\nabc') + expect(pre2.children[0].text).toBe('\n\nabc') }) it('keep first newline after unary tag in
', () => { @@ -870,7 +870,7 @@ describe('parser', () => { expect(text.text).toBe(' def') const pre2 = ast.children[2] expect(pre2.children[0].type).toBe(3) - expect(pre2.children[0].text).toBe('\nabc') + expect(pre2.children[0].text).toBe('\n\nabc') }) it(`keep first newline after unary tag inwith whitespace: 'condense'`, () => {