Skip to content

Commit 5d721a4

Browse files
committed
revert: fix(sfc): avoid deindent when pad option is specified (#7647)
This reverts commit 9d2f9a0.
1 parent 780dac5 commit 5d721a4

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

src/sfc/parser.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,11 @@ export function parseComponent (
8383
function end (tag: string, start: number) {
8484
if (depth === 1 && currentBlock) {
8585
currentBlock.end = start
86-
let text = content.slice(currentBlock.start, currentBlock.end)
86+
let text = deindent(content.slice(currentBlock.start, currentBlock.end))
8787
// pad content so that linters and pre-processors can output correct
8888
// line numbers in errors and warnings
89-
if (options.pad) {
89+
if (currentBlock.type !== 'template' && options.pad) {
9090
text = padContent(currentBlock, options.pad) + text
91-
} else {
92-
// avoid to deindent if pad option is specified
93-
// to retain original source position.
94-
text = deindent(text)
9591
}
9692
currentBlock.content = text
9793
currentBlock = null

test/unit/modules/sfc/sfc-parser.spec.js

+6-27
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,21 @@ describe('Single File Component parser', () => {
7171
const padLine = parseComponent(content.trim(), { pad: 'line' })
7272
const padSpace = parseComponent(content.trim(), { pad: 'space' })
7373

74-
expect(padDefault.template.content).toBe(Array(1).join('\n') + `
75-
<div></div>
76-
`)
77-
expect(padDefault.script.content).toBe(Array(3 + 1).join('//\n') + `
78-
export default {}
79-
`)
80-
expect(padDefault.styles[0].content).toBe(Array(6 + 1).join('\n') + `
81-
h1 { color: red }
82-
`)
83-
expect(padLine.template.content).toBe(Array(1).join('\n') + `
84-
<div></div>
85-
`)
86-
expect(padLine.script.content).toBe(Array(3 + 1).join('//\n') + `
87-
export default {}
88-
`)
89-
expect(padLine.styles[0].content).toBe(Array(6 + 1).join('\n') + `
90-
h1 { color: red }
91-
`)
92-
expect(padSpace.template.content).toBe(`<template>`.replace(/./g, ' ') + `
93-
<div></div>
94-
`)
74+
expect(padDefault.script.content).toBe(Array(3 + 1).join('//\n') + '\nexport default {}\n')
75+
expect(padDefault.styles[0].content).toBe(Array(6 + 1).join('\n') + '\nh1 { color: red }\n')
76+
expect(padLine.script.content).toBe(Array(3 + 1).join('//\n') + '\nexport default {}\n')
77+
expect(padLine.styles[0].content).toBe(Array(6 + 1).join('\n') + '\nh1 { color: red }\n')
9578
expect(padSpace.script.content).toBe(`<template>
9679
<div></div>
9780
</template>
98-
<script>`.replace(/./g, ' ') + `
99-
export default {}
100-
`)
81+
<script>`.replace(/./g, ' ') + '\nexport default {}\n')
10182
expect(padSpace.styles[0].content).toBe(`<template>
10283
<div></div>
10384
</template>
10485
<script>
10586
export default {}
10687
</script>
107-
<style>`.replace(/./g, ' ') + `
108-
h1 { color: red }
109-
`)
88+
<style>`.replace(/./g, ' ') + '\nh1 { color: red }\n')
11089
})
11190

11291
it('should handle template blocks with lang as special text', () => {

0 commit comments

Comments
 (0)