wip(compiler): improve node stringification to support adjacent nodes
This commit is contained in:
@@ -194,6 +194,11 @@ export interface SimpleExpressionNode extends Node {
|
||||
content: string
|
||||
isStatic: boolean
|
||||
isConstant: boolean
|
||||
/**
|
||||
* Indicates this is an identifier for a hoist vnode call and points to the
|
||||
* hoisted node.
|
||||
*/
|
||||
hoisted?: JSChildNode
|
||||
/**
|
||||
* an expression parsed as the params of a function will track
|
||||
* the identifiers declared inside the function body.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ElementNode, Namespace, JSChildNode, PlainElementNode } from './ast'
|
||||
import { ElementNode, Namespace, TemplateChildNode } from './ast'
|
||||
import { TextModes } from './parse'
|
||||
import { CompilerError } from './errors'
|
||||
import {
|
||||
@@ -52,9 +52,9 @@ export interface ParserOptions {
|
||||
}
|
||||
|
||||
export type HoistTransform = (
|
||||
node: PlainElementNode,
|
||||
children: TemplateChildNode[],
|
||||
context: TransformContext
|
||||
) => JSChildNode
|
||||
) => void
|
||||
|
||||
export interface TransformOptions {
|
||||
/**
|
||||
|
||||
@@ -230,12 +230,14 @@ export function createTransformContext(
|
||||
},
|
||||
hoist(exp) {
|
||||
context.hoists.push(exp)
|
||||
return createSimpleExpression(
|
||||
const identifier = createSimpleExpression(
|
||||
`_hoisted_${context.hoists.length}`,
|
||||
false,
|
||||
exp.loc,
|
||||
true
|
||||
)
|
||||
identifier.hoisted = exp
|
||||
return identifier
|
||||
},
|
||||
cache(exp, isVNode = false) {
|
||||
return createCacheExpression(++context.cached, exp, isVNode)
|
||||
|
||||
@@ -54,10 +54,7 @@ function walk(
|
||||
// whole tree is static
|
||||
;(child.codegenNode as VNodeCall).patchFlag =
|
||||
PatchFlags.HOISTED + (__DEV__ ? ` /* HOISTED */` : ``)
|
||||
const hoisted = context.transformHoist
|
||||
? context.transformHoist(child, context)
|
||||
: child.codegenNode!
|
||||
child.codegenNode = context.hoist(hoisted)
|
||||
child.codegenNode = context.hoist(child.codegenNode!)
|
||||
continue
|
||||
} else {
|
||||
// node may contain dynamic children, but its props may be eligible for
|
||||
@@ -100,6 +97,10 @@ function walk(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (context.transformHoist) {
|
||||
context.transformHoist(children, context)
|
||||
}
|
||||
}
|
||||
|
||||
export function isStaticNode(
|
||||
|
||||
Reference in New Issue
Block a user