}
function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
- const { mode, helper, prefixIdentifiers, push, newline } = context
- const VueBinding = mode === 'function' ? `Vue` : `require("vue")`
+ const { ssr, helper, prefixIdentifiers, push, newline } = context
+ const VueBinding = ssr ? `require("vue")` : `Vue`
// Generate const declaration for helpers
// In prefix mode, we place the const declaration at top so it's done
// only once; But if we not prefixing, we place the declaration inside the
}
function genTemplateLiteral(node: TemplateLiteral, context: CodegenContext) {
- const { push } = context
+ const { push, indent, deindent } = context
push('`')
for (let i = 0; i < node.elements.length; i++) {
const e = node.elements[i]
push(e.replace(/`/g, '\\`'))
} else {
push('${')
+ indent()
genNode(e, context)
+ deindent()
push('}')
}
}
// - Function mode will generate a single `const { helpers... } = Vue`
// statement and return the render function. It is meant to be used with
// `new Function(code)()` to generate a render function at runtime.
- // - CommonJS mode is like function mode except it retrives helpers from
- // `require('vue')`.
// - Default: 'function'
- mode?: 'module' | 'function' | 'cjs'
+ mode?: 'module' | 'function'
// Generate source map?
// - Default: false
sourceMap?: boolean