refactor(compiler): better constant hoist/stringify checks
This commit is contained in:
@@ -189,11 +189,23 @@ export interface DirectiveNode extends Node {
|
||||
parseResult?: ForParseResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Static types have several levels.
|
||||
* Higher levels implies lower levels. e.g. a node that can be stringified
|
||||
* can always be hoisted and skipped for patch.
|
||||
*/
|
||||
export const enum ConstantTypes {
|
||||
NOT_CONSTANT = 0,
|
||||
CAN_SKIP_PATCH,
|
||||
CAN_HOIST,
|
||||
CAN_STRINGIFY
|
||||
}
|
||||
|
||||
export interface SimpleExpressionNode extends Node {
|
||||
type: NodeTypes.SIMPLE_EXPRESSION
|
||||
content: string
|
||||
isStatic: boolean
|
||||
isConstant: boolean
|
||||
constType: ConstantTypes
|
||||
/**
|
||||
* Indicates this is an identifier for a hoist vnode call and points to the
|
||||
* hoisted node.
|
||||
@@ -204,11 +216,6 @@ export interface SimpleExpressionNode extends Node {
|
||||
* the identifiers declared inside the function body.
|
||||
*/
|
||||
identifiers?: string[]
|
||||
/**
|
||||
* some expressions (e.g. transformAssetUrls import identifiers) are constant,
|
||||
* but cannot be stringified because they must be first evaluated at runtime.
|
||||
*/
|
||||
isRuntimeConstant?: boolean
|
||||
}
|
||||
|
||||
export interface InterpolationNode extends Node {
|
||||
@@ -611,14 +618,14 @@ export function createSimpleExpression(
|
||||
content: SimpleExpressionNode['content'],
|
||||
isStatic: SimpleExpressionNode['isStatic'],
|
||||
loc: SourceLocation = locStub,
|
||||
isConstant: boolean = false
|
||||
constType: ConstantTypes = ConstantTypes.NOT_CONSTANT
|
||||
): SimpleExpressionNode {
|
||||
return {
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
loc,
|
||||
isConstant,
|
||||
content,
|
||||
isStatic
|
||||
isStatic,
|
||||
constType: isStatic ? ConstantTypes.CAN_STRINGIFY : constType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user