From 5d721a42b140865e50a78445fe21c5f270bde703 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 9 Dec 2018 15:52:17 -0500 Subject: [PATCH] revert: fix(sfc): avoid deindent when pad option is specified (#7647) This reverts commit 9d2f9a034f9c40d5ba6d8b1e131b1bfb675dc1cf. --- src/sfc/parser.js | 8 ++---- test/unit/modules/sfc/sfc-parser.spec.js | 33 +++++------------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/sfc/parser.js b/src/sfc/parser.js index f6e83d362a3..d7868a40ab8 100644 --- a/src/sfc/parser.js +++ b/src/sfc/parser.js @@ -83,15 +83,11 @@ export function parseComponent ( function end (tag: string, start: number) { if (depth === 1 && currentBlock) { currentBlock.end = start - let text = content.slice(currentBlock.start, currentBlock.end) + let text = deindent(content.slice(currentBlock.start, currentBlock.end)) // pad content so that linters and pre-processors can output correct // line numbers in errors and warnings - if (options.pad) { + if (currentBlock.type !== 'template' && options.pad) { text = padContent(currentBlock, options.pad) + text - } else { - // avoid to deindent if pad option is specified - // to retain original source position. - text = deindent(text) } currentBlock.content = text currentBlock = null diff --git a/test/unit/modules/sfc/sfc-parser.spec.js b/test/unit/modules/sfc/sfc-parser.spec.js index 30a9f9e2c43..4cf6bad574a 100644 --- a/test/unit/modules/sfc/sfc-parser.spec.js +++ b/test/unit/modules/sfc/sfc-parser.spec.js @@ -71,42 +71,21 @@ describe('Single File Component parser', () => { const padLine = parseComponent(content.trim(), { pad: 'line' }) const padSpace = parseComponent(content.trim(), { pad: 'space' }) - expect(padDefault.template.content).toBe(Array(1).join('\n') + ` -
- `) - expect(padDefault.script.content).toBe(Array(3 + 1).join('//\n') + ` - export default {} - `) - expect(padDefault.styles[0].content).toBe(Array(6 + 1).join('\n') + ` - h1 { color: red } - `) - expect(padLine.template.content).toBe(Array(1).join('\n') + ` -
- `) - expect(padLine.script.content).toBe(Array(3 + 1).join('//\n') + ` - export default {} - `) - expect(padLine.styles[0].content).toBe(Array(6 + 1).join('\n') + ` - h1 { color: red } - `) - expect(padSpace.template.content).toBe(`