|
@@ -1,6 +1,7 @@
|
|
|
import {
|
|
import {
|
|
|
type AllNode,
|
|
type AllNode,
|
|
|
type TransformOptions as BaseTransformOptions,
|
|
type TransformOptions as BaseTransformOptions,
|
|
|
|
|
+ BindingTypes,
|
|
|
type CommentNode,
|
|
type CommentNode,
|
|
|
type CompilerCompatOptions,
|
|
type CompilerCompatOptions,
|
|
|
type ElementNode,
|
|
type ElementNode,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
type TemplateChildNode,
|
|
type TemplateChildNode,
|
|
|
defaultOnError,
|
|
defaultOnError,
|
|
|
defaultOnWarn,
|
|
defaultOnWarn,
|
|
|
|
|
+ isConstantNode,
|
|
|
isVSlot,
|
|
isVSlot,
|
|
|
} from '@vue/compiler-dom'
|
|
} from '@vue/compiler-dom'
|
|
|
import { EMPTY_OBJ, NOOP, extend, isArray, isString } from '@vue/shared'
|
|
import { EMPTY_OBJ, NOOP, extend, isArray, isString } from '@vue/shared'
|
|
@@ -139,7 +141,11 @@ export class TransformContext<T extends AllNode = AllNode> {
|
|
|
...operations: OperationNode[]
|
|
...operations: OperationNode[]
|
|
|
): void {
|
|
): void {
|
|
|
expressions = expressions.filter(exp => !isConstantExpression(exp))
|
|
expressions = expressions.filter(exp => !isConstantExpression(exp))
|
|
|
- if (this.inVOnce || expressions.length === 0) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ this.inVOnce ||
|
|
|
|
|
+ expressions.length === 0 ||
|
|
|
|
|
+ isStaticExpression(this.root, expressions)
|
|
|
|
|
+ ) {
|
|
|
return this.registerOperation(...operations)
|
|
return this.registerOperation(...operations)
|
|
|
}
|
|
}
|
|
|
const existing = this.block.effect.find(e =>
|
|
const existing = this.block.effect.find(e =>
|
|
@@ -298,3 +304,21 @@ export function createStructuralDirectiveTransform(
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+function isStaticExpression(
|
|
|
|
|
+ context: TransformContext,
|
|
|
|
|
+ expressions: SimpleExpressionNode[],
|
|
|
|
|
+) {
|
|
|
|
|
+ const {
|
|
|
|
|
+ options: { bindingMetadata },
|
|
|
|
|
+ } = context
|
|
|
|
|
+ const isLiteralConst = (name: string) =>
|
|
|
|
|
+ bindingMetadata[name] === BindingTypes.LITERAL_CONST
|
|
|
|
|
+ return expressions.every(node => {
|
|
|
|
|
+ if (node.ast) {
|
|
|
|
|
+ return isConstantNode(node.ast, isLiteralConst)
|
|
|
|
|
+ } else if (node.ast === null) {
|
|
|
|
|
+ return isLiteralConst(node.content)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|