@@ -43,9 +43,7 @@ import {
|
||||
SET_BLOCK_TRACKING,
|
||||
CREATE_COMMENT,
|
||||
CREATE_TEXT,
|
||||
PUSH_SCOPE_ID,
|
||||
POP_SCOPE_ID,
|
||||
WITH_SCOPE_ID,
|
||||
SET_SCOPE_ID,
|
||||
WITH_DIRECTIVES,
|
||||
CREATE_BLOCK,
|
||||
OPEN_BLOCK,
|
||||
@@ -197,12 +195,11 @@ export function generate(
|
||||
indent,
|
||||
deindent,
|
||||
newline,
|
||||
scopeId,
|
||||
ssr
|
||||
} = context
|
||||
|
||||
const hasHelpers = ast.helpers.length > 0
|
||||
const useWithBlock = !prefixIdentifiers && mode !== 'module'
|
||||
const genScopeId = !__BROWSER__ && scopeId != null && mode === 'module'
|
||||
const isSetupInlined = !__BROWSER__ && !!options.inline
|
||||
|
||||
// preambles
|
||||
@@ -212,7 +209,7 @@ export function generate(
|
||||
? createCodegenContext(ast, options)
|
||||
: context
|
||||
if (!__BROWSER__ && mode === 'module') {
|
||||
genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined)
|
||||
genModulePreamble(ast, preambleContext, isSetupInlined)
|
||||
} else {
|
||||
genFunctionPreamble(ast, preambleContext)
|
||||
}
|
||||
@@ -229,14 +226,7 @@ export function generate(
|
||||
? args.map(arg => `${arg}: any`).join(',')
|
||||
: args.join(', ')
|
||||
|
||||
if (genScopeId) {
|
||||
if (isSetupInlined) {
|
||||
push(`${PURE_ANNOTATION}_withId(`)
|
||||
} else {
|
||||
push(`const ${functionName} = ${PURE_ANNOTATION}_withId(`)
|
||||
}
|
||||
}
|
||||
if (isSetupInlined || genScopeId) {
|
||||
if (isSetupInlined) {
|
||||
push(`(${signature}) => {`)
|
||||
} else {
|
||||
push(`function ${functionName}(${signature}) {`)
|
||||
@@ -301,10 +291,6 @@ export function generate(
|
||||
deindent()
|
||||
push(`}`)
|
||||
|
||||
if (genScopeId) {
|
||||
push(`)`)
|
||||
}
|
||||
|
||||
return {
|
||||
ast,
|
||||
code: context.code,
|
||||
@@ -375,23 +361,20 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
|
||||
function genModulePreamble(
|
||||
ast: RootNode,
|
||||
context: CodegenContext,
|
||||
genScopeId: boolean,
|
||||
inline?: boolean
|
||||
) {
|
||||
const {
|
||||
push,
|
||||
helper,
|
||||
newline,
|
||||
scopeId,
|
||||
optimizeImports,
|
||||
runtimeModuleName
|
||||
runtimeModuleName,
|
||||
scopeId,
|
||||
mode
|
||||
} = context
|
||||
|
||||
if (genScopeId) {
|
||||
ast.helpers.push(WITH_SCOPE_ID)
|
||||
if (ast.hoists.length) {
|
||||
ast.helpers.push(PUSH_SCOPE_ID, POP_SCOPE_ID)
|
||||
}
|
||||
const genScopeId = !__BROWSER__ && scopeId != null && mode === 'module'
|
||||
if (genScopeId && ast.hoists.length) {
|
||||
ast.helpers.push(SET_SCOPE_ID)
|
||||
}
|
||||
|
||||
// generate import statements for helpers
|
||||
@@ -434,13 +417,6 @@ function genModulePreamble(
|
||||
newline()
|
||||
}
|
||||
|
||||
if (genScopeId) {
|
||||
push(
|
||||
`const _withId = ${PURE_ANNOTATION}${helper(WITH_SCOPE_ID)}("${scopeId}")`
|
||||
)
|
||||
newline()
|
||||
}
|
||||
|
||||
genHoists(ast.hoists, context)
|
||||
newline()
|
||||
|
||||
@@ -480,7 +456,7 @@ function genHoists(hoists: (JSChildNode | null)[], context: CodegenContext) {
|
||||
// push scope Id before initializing hoisted vnodes so that these vnodes
|
||||
// get the proper scopeId as well.
|
||||
if (genScopeId) {
|
||||
push(`${helper(PUSH_SCOPE_ID)}("${scopeId}")`)
|
||||
push(`${helper(SET_SCOPE_ID)}("${scopeId}")`)
|
||||
newline()
|
||||
}
|
||||
|
||||
@@ -493,7 +469,7 @@ function genHoists(hoists: (JSChildNode | null)[], context: CodegenContext) {
|
||||
})
|
||||
|
||||
if (genScopeId) {
|
||||
push(`${helper(POP_SCOPE_ID)}()`)
|
||||
push(`${helper(SET_SCOPE_ID)}(null)`)
|
||||
newline()
|
||||
}
|
||||
context.pure = false
|
||||
@@ -817,15 +793,11 @@ function genFunctionExpression(
|
||||
node: FunctionExpression,
|
||||
context: CodegenContext
|
||||
) {
|
||||
const { push, indent, deindent, scopeId, mode } = context
|
||||
const { push, indent, deindent } = context
|
||||
const { params, returns, body, newline, isSlot } = node
|
||||
// slot functions also need to push scopeId before rendering its content
|
||||
const genScopeId =
|
||||
!__BROWSER__ && isSlot && scopeId != null && mode !== 'function'
|
||||
|
||||
if (genScopeId) {
|
||||
push(`_withId(`)
|
||||
} else if (isSlot) {
|
||||
if (isSlot) {
|
||||
// wrap slot functions with owner context
|
||||
push(`_${helperNameMap[WITH_CTX]}(`)
|
||||
}
|
||||
push(`(`, node)
|
||||
@@ -855,7 +827,7 @@ function genFunctionExpression(
|
||||
deindent()
|
||||
push(`}`)
|
||||
}
|
||||
if (genScopeId || isSlot) {
|
||||
if (isSlot) {
|
||||
push(`)`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ export const CAMELIZE = Symbol(__DEV__ ? `camelize` : ``)
|
||||
export const CAPITALIZE = Symbol(__DEV__ ? `capitalize` : ``)
|
||||
export const TO_HANDLER_KEY = Symbol(__DEV__ ? `toHandlerKey` : ``)
|
||||
export const SET_BLOCK_TRACKING = Symbol(__DEV__ ? `setBlockTracking` : ``)
|
||||
export const PUSH_SCOPE_ID = Symbol(__DEV__ ? `pushScopeId` : ``)
|
||||
export const POP_SCOPE_ID = Symbol(__DEV__ ? `popScopeId` : ``)
|
||||
export const WITH_SCOPE_ID = Symbol(__DEV__ ? `withScopeId` : ``)
|
||||
export const SET_SCOPE_ID = Symbol(__DEV__ ? `setScopeId` : ``)
|
||||
export const WITH_CTX = Symbol(__DEV__ ? `withCtx` : ``)
|
||||
export const UNREF = Symbol(__DEV__ ? `unref` : ``)
|
||||
export const IS_REF = Symbol(__DEV__ ? `isRef` : ``)
|
||||
@@ -61,9 +59,7 @@ export const helperNameMap: any = {
|
||||
[CAPITALIZE]: `capitalize`,
|
||||
[TO_HANDLER_KEY]: `toHandlerKey`,
|
||||
[SET_BLOCK_TRACKING]: `setBlockTracking`,
|
||||
[PUSH_SCOPE_ID]: `pushScopeId`,
|
||||
[POP_SCOPE_ID]: `popScopeId`,
|
||||
[WITH_SCOPE_ID]: `withScopeId`,
|
||||
[SET_SCOPE_ID]: `setScopeId`,
|
||||
[WITH_CTX]: `withCtx`,
|
||||
[UNREF]: `unref`,
|
||||
[IS_REF]: `isRef`
|
||||
|
||||
Reference in New Issue
Block a user