perf(compiler-vapor): register as operations if no dynamic expressions

This commit is contained in:
三咲智子 Kevin Deng 2024-02-08 20:50:34 +08:00
parent 0cdc9f20c6
commit 6e80e34e6b
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
2 changed files with 15 additions and 5 deletions

View File

@ -159,11 +159,11 @@ export function render(_ctx) {
`; `;
exports[`compile > dynamic root 1`] = ` exports[`compile > dynamic root 1`] = `
"import { createTextNode as _createTextNode, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor'; "import { createTextNode as _createTextNode, setText as _setText } from 'vue/vapor';
export function render(_ctx) { export function render(_ctx) {
const n1 = _createTextNode() const n1 = _createTextNode()
_renderEffect(() => _setText(n1, 1, 2)) _setText(n1, 1, 2)
return [n1] return [n1]
}" }"
`; `;
@ -210,11 +210,11 @@ export function render(_ctx) {
`; `;
exports[`compile > static + dynamic root 1`] = ` exports[`compile > static + dynamic root 1`] = `
"import { createTextNode as _createTextNode, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor'; "import { createTextNode as _createTextNode, setText as _setText } from 'vue/vapor';
export function render(_ctx) { export function render(_ctx) {
const n1 = _createTextNode() const n1 = _createTextNode()
_renderEffect(() => _setText(n1, 1, 2, "3", 4, 5, "6", 7, 8, "9", 'A', 'B')) _setText(n1, 1, 2, "3", 4, 5, "6", 7, 8, "9", 'A', 'B')
return [n1] return [n1]
}" }"
`; `;

View File

@ -14,6 +14,7 @@ import {
createSimpleExpression, createSimpleExpression,
defaultOnError, defaultOnError,
defaultOnWarn, defaultOnWarn,
isLiteralWhitelisted,
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'
@ -153,7 +154,16 @@ function createRootContext(
return (this.dynamic.id = this.increaseId()) return (this.dynamic.id = this.increaseId())
}, },
registerEffect(expressions, operations) { registerEffect(expressions, operations) {
expressions = expressions.filter(exp => !exp.isStatic) expressions = expressions.filter(exp => {
// filter static expressions
if (!__BROWSER__) {
if (isLiteralWhitelisted(exp.content)) return false
if (exp.ast)
// also filter out string and number literals
return !['StringLiteral', 'NumericLiteral'].includes(exp.ast.type)
}
return !exp.isStatic
})
if (this.inVOnce || expressions.length === 0) { if (this.inVOnce || expressions.length === 0) {
return this.registerOperation(...operations) return this.registerOperation(...operations)
} }