feat(compiler): transformStyle + context.hoist

This commit is contained in:
Evan You
2019-09-25 14:13:33 -04:00
parent 3e8cd3f25f
commit b43f3b61b7
13 changed files with 290 additions and 59 deletions

View File

@@ -148,14 +148,16 @@ export function generate(
if (mode === 'function') {
// generate const declarations for helpers
if (imports) {
push(`const { ${imports} } = Vue\n\n`)
push(`const { ${imports} } = Vue\n`)
}
genHoists(ast.hoists, context)
push(`return `)
} else {
// generate import statements for helpers
if (imports) {
push(`import { ${imports} } from 'vue'\n\n`)
push(`import { ${imports} } from 'vue'\n`)
}
genHoists(ast.hoists, context)
push(`export default `)
}
push(`function render() {`)
@@ -190,6 +192,15 @@ export function generate(
}
}
function genHoists(hoists: JSChildNode[], context: CodegenContext) {
hoists.forEach((exp, i) => {
context.push(`const _hoisted_${i + 1} = `)
genNode(exp, context)
context.newline()
})
context.newline()
}
// This will generate a single vnode call if:
// - The list has length === 1, AND:
// - This is a root node, OR: