chore(compiler-core/codegen): avoid generate indent spaces of empty lines. (#701)
This commit is contained in:
parent
42db2fef9d
commit
782db6d7f5
@ -72,14 +72,16 @@ return function render() {
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`compiler: codegen assets 1`] = `
|
exports[`compiler: codegen assets + temps 1`] = `
|
||||||
"
|
"
|
||||||
return function render() {
|
return function render() {
|
||||||
with (this) {
|
with (this) {
|
||||||
const _component_Foo = _resolveComponent(\\"Foo\\")
|
const _component_Foo = _resolveComponent(\\"Foo\\")
|
||||||
const _component_bar_baz = _resolveComponent(\\"bar-baz\\")
|
const _component_bar_baz = _resolveComponent(\\"bar-baz\\")
|
||||||
const _component_barbaz = _resolveComponent(\\"barbaz\\")
|
const _component_barbaz = _resolveComponent(\\"barbaz\\")
|
||||||
const _directive_my_dir = _resolveDirective(\\"my_dir\\")
|
const _directive_my_dir_0 = _resolveDirective(\\"my_dir_0\\")
|
||||||
|
const _directive_my_dir_1 = _resolveDirective(\\"my_dir_1\\")
|
||||||
|
let _temp0, _temp1, _temp2
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -119,10 +119,11 @@ describe('compiler: codegen', () => {
|
|||||||
expect(code).toMatchSnapshot()
|
expect(code).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('assets', () => {
|
test('assets + temps', () => {
|
||||||
const root = createRoot({
|
const root = createRoot({
|
||||||
components: [`Foo`, `bar-baz`, `barbaz`],
|
components: [`Foo`, `bar-baz`, `barbaz`],
|
||||||
directives: [`my_dir`]
|
directives: [`my_dir_0`, `my_dir_1`],
|
||||||
|
temps: 3
|
||||||
})
|
})
|
||||||
const { code } = generate(root, { mode: 'function' })
|
const { code } = generate(root, { mode: 'function' })
|
||||||
expect(code).toMatch(
|
expect(code).toMatch(
|
||||||
@ -139,10 +140,16 @@ describe('compiler: codegen', () => {
|
|||||||
}("barbaz")\n`
|
}("barbaz")\n`
|
||||||
)
|
)
|
||||||
expect(code).toMatch(
|
expect(code).toMatch(
|
||||||
`const _directive_my_dir = _${
|
`const _directive_my_dir_0 = _${
|
||||||
helperNameMap[RESOLVE_DIRECTIVE]
|
helperNameMap[RESOLVE_DIRECTIVE]
|
||||||
}("my_dir")\n`
|
}("my_dir_0")\n`
|
||||||
)
|
)
|
||||||
|
expect(code).toMatch(
|
||||||
|
`const _directive_my_dir_1 = _${
|
||||||
|
helperNameMap[RESOLVE_DIRECTIVE]
|
||||||
|
}("my_dir_1")\n`
|
||||||
|
)
|
||||||
|
expect(code).toMatch(`let _temp0, _temp1, _temp2`)
|
||||||
expect(code).toMatchSnapshot()
|
expect(code).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -216,11 +216,11 @@ export function generate(
|
|||||||
.map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
|
.map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
|
||||||
.join(', ')} } = _Vue`
|
.join(', ')} } = _Vue`
|
||||||
)
|
)
|
||||||
newline()
|
|
||||||
if (ast.cached > 0) {
|
if (ast.cached > 0) {
|
||||||
push(`const _cache = $cache`)
|
|
||||||
newline()
|
newline()
|
||||||
|
push(`const _cache = $cache`)
|
||||||
}
|
}
|
||||||
|
push(`\n`)
|
||||||
newline()
|
newline()
|
||||||
}
|
}
|
||||||
} else if (!__BROWSER__ && !ssr) {
|
} else if (!__BROWSER__ && !ssr) {
|
||||||
@ -235,18 +235,24 @@ export function generate(
|
|||||||
// generate asset resolution statements
|
// generate asset resolution statements
|
||||||
if (ast.components.length) {
|
if (ast.components.length) {
|
||||||
genAssets(ast.components, 'component', context)
|
genAssets(ast.components, 'component', context)
|
||||||
|
if (ast.directives.length || ast.temps > 0) {
|
||||||
|
newline()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ast.directives.length) {
|
if (ast.directives.length) {
|
||||||
genAssets(ast.directives, 'directive', context)
|
genAssets(ast.directives, 'directive', context)
|
||||||
|
if (ast.temps > 0) {
|
||||||
|
newline()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ast.temps > 0) {
|
if (ast.temps > 0) {
|
||||||
push(`let `)
|
push(`let `)
|
||||||
for (let i = 0; i < ast.temps; i++) {
|
for (let i = 0; i < ast.temps; i++) {
|
||||||
push(`${i > 0 ? `, ` : ``}_temp${i}`)
|
push(`${i > 0 ? `, ` : ``}_temp${i}`)
|
||||||
}
|
}
|
||||||
push(`\n`)
|
|
||||||
}
|
}
|
||||||
if (ast.components.length || ast.directives.length || ast.temps) {
|
if (ast.components.length || ast.directives.length || ast.temps) {
|
||||||
|
push(`\n`)
|
||||||
newline()
|
newline()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,8 +425,6 @@ function genAssets(
|
|||||||
)
|
)
|
||||||
if (i < assets.length - 1) {
|
if (i < assets.length - 1) {
|
||||||
newline()
|
newline()
|
||||||
} else {
|
|
||||||
push(`\n`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user