refactor(compiler): better constant hoist/stringify checks

This commit is contained in:
Evan You
2020-11-20 19:26:07 -05:00
parent acba86ef45
commit 90bdf59f4c
22 changed files with 291 additions and 204 deletions

View File

@@ -22,7 +22,8 @@ import {
TextNode,
TemplateChildNode,
InterpolationNode,
createRoot
createRoot,
ConstantTypes
} from './ast'
type OptionalOptions = 'isNativeTag' | 'isBuiltInComponent'
@@ -656,7 +657,9 @@ function parseAttribute(
type: NodeTypes.SIMPLE_EXPRESSION,
content,
isStatic,
isConstant: isStatic,
constType: isStatic
? ConstantTypes.CAN_STRINGIFY
: ConstantTypes.NOT_CONSTANT,
loc
}
}
@@ -677,8 +680,8 @@ function parseAttribute(
content: value.content,
isStatic: false,
// Treat as non-constant by default. This can be potentially set to
// true by `transformExpression` to make it eligible for hoisting.
isConstant: false,
// other values by `transformExpression` to make it eligible for hoisting.
constType: ConstantTypes.NOT_CONSTANT,
loc: value.loc
},
arg,
@@ -785,7 +788,7 @@ function parseInterpolation(
type: NodeTypes.SIMPLE_EXPRESSION,
isStatic: false,
// Set `isConstant` to false by default and will decide in transformExpression
isConstant: false,
constType: ConstantTypes.NOT_CONSTANT,
content,
loc: getSelection(context, innerStart, innerEnd)
},