From bf0ab3872cf8969c3fbffa65ee6d3c8e3558ed34 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sun, 17 Nov 2024 21:55:34 +0800 Subject: [PATCH 1/5] perf(runtime-vapor): use setAttr for attributes that must be set as attirbute --- .../__snapshots__/vBind.spec.ts.snap | 40 ++++++++++++++++ .../__tests__/transforms/vBind.spec.ts | 28 +++++++++++ .../compiler-vapor/src/generators/prop.ts | 5 +- packages/compiler-vapor/src/ir/index.ts | 1 + .../src/transforms/transformElement.ts | 1 + packages/runtime-vapor/src/dom/prop.ts | 38 +-------------- packages/shared/src/domAttrConfig.ts | 46 +++++++++++++++++++ 7 files changed, 122 insertions(+), 37 deletions(-) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap index 5e1e43c88..09e944f84 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap @@ -121,6 +121,46 @@ export function render(_ctx) { }" `; +exports[`compiler v-bind > attributes must be set as attribute 1`] = ` +"import { renderEffect as _renderEffect, setAttr as _setAttr, template as _template } from 'vue/vapor'; +const t0 = _template("
") +const t1 = _template("") +const t2 = _template("") +const t3 = _template("") +const t4 = _template("") +const t5 = _template("") +const t6 = _template("") + +export function render(_ctx) { + const n0 = t0() + const n1 = t1() + const n2 = t2() + const n3 = t3() + const n4 = t4() + const n5 = t5() + const n6 = t6() + _renderEffect(() => _setAttr(n0, "spellcheck", _ctx.spellcheck)) + _renderEffect(() => _setAttr(n0, "draggable", _ctx.draggable)) + _renderEffect(() => _setAttr(n0, "translate", _ctx.translate)) + _renderEffect(() => _setAttr(n0, "form", _ctx.form)) + _renderEffect(() => _setAttr(n1, "list", _ctx.list)) + _renderEffect(() => _setAttr(n2, "type", _ctx.type)) + _renderEffect(() => { + _setAttr(n3, "width", _ctx.width) + _setAttr(n4, "width", _ctx.width) + _setAttr(n5, "width", _ctx.width) + _setAttr(n6, "width", _ctx.width) + }) + _renderEffect(() => { + _setAttr(n3, "height", _ctx.height) + _setAttr(n4, "height", _ctx.height) + _setAttr(n5, "height", _ctx.height) + _setAttr(n6, "height", _ctx.height) + }) + return [n0, n1, n2, n3, n4, n5, n6] +}" +`; + exports[`compiler v-bind > basic 1`] = ` "import { setInheritAttrs as _setInheritAttrs, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor'; const t0 = _template("
") diff --git a/packages/compiler-vapor/__tests__/transforms/vBind.spec.ts b/packages/compiler-vapor/__tests__/transforms/vBind.spec.ts index 0097d0b7c..fd9d81e21 100644 --- a/packages/compiler-vapor/__tests__/transforms/vBind.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/vBind.spec.ts @@ -526,4 +526,32 @@ describe('compiler v-bind', () => { expect(code).contains('renderEffect') expect(code).contains('_setAttr(n0, "foo-bar", _ctx.fooBar, true)') }) + + test('attributes must be set as attribute', () => { + const { code } = compileWithVBind(` +
+ +