Skip to content
Permalink
Browse files
revert: fix(sfc): avoid deindent when pad option is specified (#7647)
This reverts commit 9d2f9a0.
  • Loading branch information
yyx990803 committed Dec 9, 2018
1 parent 780dac5 commit 5d721a42b140865e50a78445fe21c5f270bde703
Showing with 8 additions and 33 deletions.
  1. +2 鈭6 src/sfc/parser.js
  2. +6 鈭27 test/unit/modules/sfc/sfc-parser.spec.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
@@ -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') + `
<div></div>
`)
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') + `
<div></div>
`)
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(`<template>`.replace(/./g, ' ') + `
<div></div>
`)
expect(padDefault.script.content).toBe(Array(3 + 1).join('//\n') + '\nexport default {}\n')
expect(padDefault.styles[0].content).toBe(Array(6 + 1).join('\n') + '\nh1 { color: red }\n')
expect(padLine.script.content).toBe(Array(3 + 1).join('//\n') + '\nexport default {}\n')
expect(padLine.styles[0].content).toBe(Array(6 + 1).join('\n') + '\nh1 { color: red }\n')
expect(padSpace.script.content).toBe(`<template>
<div></div>
</template>
<script>`.replace(/./g, ' ') + `
export default {}
`)
<script>`.replace(/./g, ' ') + '\nexport default {}\n')
expect(padSpace.styles[0].content).toBe(`<template>
<div></div>
</template>
<script>
export default {}
</script>
<style>`.replace(/./g, ' ') + `
h1 { color: red }
`)
<style>`.replace(/./g, ' ') + '\nh1 { color: red }\n')
})

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

0 comments on commit 5d721a4

Please sign in to comment.