From: zhiyuanzmj <260480378@qq.com> Date: Fri, 17 Oct 2025 02:38:30 +0000 (+0800) Subject: refactor(compiler-vapor): remove redundant empty strings (#13993) X-Git-Tag: v3.6.0-alpha.3~39 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=27632bb439793638f1289a4222c63de8268aa08e;p=thirdparty%2Fvuejs%2Fcore.git refactor(compiler-vapor): remove redundant empty strings (#13993) --- diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap index 3188a86607..2b9ed3bdbb 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap @@ -125,7 +125,7 @@ exports[`compiler: element transform > component > static props 1`] = ` export function render(_ctx) { const _component_Foo = _resolveComponent("Foo") const n0 = _createComponentWithFallback(_component_Foo, { - id: () => ("foo"), + id: () => ("foo"), class: () => ("bar") }, null, true) return n0 @@ -150,7 +150,7 @@ exports[`compiler: element transform > component > v-bind="obj" after static pro export function render(_ctx) { const _component_Foo = _resolveComponent("Foo") const n0 = _createComponentWithFallback(_component_Foo, { - id: () => ("foo"), + id: () => ("foo"), $: [ () => (_ctx.obj) ] @@ -165,7 +165,7 @@ exports[`compiler: element transform > component > v-bind="obj" before static pr export function render(_ctx) { const _component_Foo = _resolveComponent("Foo") const n0 = _createComponentWithFallback(_component_Foo, { $: [ - () => (_ctx.obj), + () => (_ctx.obj), { id: () => ("foo") } ] }, null, true) return n0 @@ -178,9 +178,9 @@ exports[`compiler: element transform > component > v-bind="obj" between static p export function render(_ctx) { const _component_Foo = _resolveComponent("Foo") const n0 = _createComponentWithFallback(_component_Foo, { - id: () => ("foo"), + id: () => ("foo"), $: [ - () => (_ctx.obj), + () => (_ctx.obj), { class: () => ("bar") } ] }, null, true) @@ -262,7 +262,7 @@ exports[`compiler: element transform > component with dynamic event arguments 1` export function render(_ctx) { const _component_Foo = _resolveComponent("Foo") const n0 = _createComponentWithFallback(_component_Foo, { $: [ - () => ({ [_toHandlerKey(_ctx.foo-_ctx.bar)]: () => _ctx.bar }), + () => ({ [_toHandlerKey(_ctx.foo-_ctx.bar)]: () => _ctx.bar }), () => ({ [_toHandlerKey(_ctx.baz)]: () => _ctx.qux }) ] }, null, true) return n0 @@ -275,7 +275,7 @@ exports[`compiler: element transform > component with dynamic prop arguments 1`] export function render(_ctx) { const _component_Foo = _resolveComponent("Foo") const n0 = _createComponentWithFallback(_component_Foo, { $: [ - () => ({ [_ctx.foo-_ctx.bar]: _ctx.bar }), + () => ({ [_ctx.foo-_ctx.bar]: _ctx.bar }), () => ({ [_ctx.baz]: _ctx.qux }) ] }, null, true) return n0 diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snap index 6d62b9c4e3..caac138dce 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snap @@ -40,8 +40,8 @@ exports[`compiler: transform outlets > default slot outlet with props 1`] export function render(_ctx) { const n0 = _createSlot("default", { - foo: () => ("bar"), - baz: () => (_ctx.qux), + foo: () => ("bar"), + baz: () => (_ctx.qux), fooBar: () => (_ctx.foo-_ctx.bar) }) return n0 @@ -125,7 +125,7 @@ exports[`compiler: transform outlets > statically named slot outlet with export function render(_ctx) { const n0 = _createSlot("foo", { - foo: () => ("bar"), + foo: () => ("bar"), baz: () => (_ctx.qux) }) return n0 @@ -137,9 +137,9 @@ exports[`compiler: transform outlets > statically named slot outlet with export function render(_ctx) { const n0 = _createSlot("foo", { - foo: () => ("bar"), + foo: () => ("bar"), $: [ - () => (_ctx.obj), + () => (_ctx.obj), { baz: () => (_ctx.qux) } ] }) @@ -152,9 +152,9 @@ exports[`compiler: transform outlets > statically named slot outlet with export function render(_ctx) { const n0 = _createSlot("default", { - onClick: () => _ctx.foo, + onClick: () => _ctx.foo, $: [ - () => (_toHandlers(_ctx.bar)), + () => (_toHandlers(_ctx.bar)), { baz: () => (_ctx.qux) } ] }) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vModel.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vModel.spec.ts.snap index 5ef064974c..ae1def8300 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vModel.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vModel.spec.ts.snap @@ -31,7 +31,7 @@ export function render(_ctx) { const n0 = _createComponentWithFallback(_component_Comp, { foo: () => (_ctx.foo), "onUpdate:foo": () => _value => (_ctx.foo = _value), - fooModifiers: () => ({ trim: true }), + fooModifiers: () => ({ trim: true }), bar: () => (_ctx.bar), "onUpdate:bar": () => _value => (_ctx.bar = _value), barModifiers: () => ({ number: true }) @@ -59,7 +59,7 @@ export function render(_ctx) { const n0 = _createComponentWithFallback(_component_Comp, { $: [ () => ({ [_ctx.foo]: _ctx.foo, ["onUpdate:" + _ctx.foo]: () => _value => (_ctx.foo = _value), - [_ctx.foo + "Modifiers"]: () => ({ trim: true }) }), + [_ctx.foo + "Modifiers"]: () => ({ trim: true }) }), () => ({ [_ctx.bar]: _ctx.bar, ["onUpdate:" + _ctx.bar]: () => _value => (_ctx.bar = _value), [_ctx.bar + "Modifiers"]: () => ({ number: true }) }) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap index e7a2b30e69..8423cb2ed5 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap @@ -20,7 +20,7 @@ export function render(_ctx) { const _on_update_model = () => {} const _on_update_model1 = () => {} const n0 = _createComponentWithFallback(_component_Foo, { - "onUpdate:model": () => _on_update_model, + "onUpdate:model": () => _on_update_model, "onUpdate-model": () => _on_update_model1 }, null, true) return n0 @@ -333,7 +333,7 @@ const t0 = _template("
", true) export function render(_ctx) { const n0 = t0() _on(n0, "click", _withModifiers(e => _ctx.test(e), ["stop","prevent"]), { - capture: true, + capture: true, once: true }) return n0 diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap index f296d7257d..d77f05ab03 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap @@ -9,7 +9,7 @@ export function render(_ctx) { const n2 = _createComponentWithFallback(_component_Comp, null, { $: [ () => ({ - name: _ctx.name, + name: _ctx.name, fn: () => { const n0 = t0() return n0 @@ -30,7 +30,7 @@ export function render(_ctx) { const n2 = _createComponentWithFallback(_component_Comp, null, { $: [ () => (_createForSlots(_ctx.list, (item) => ({ - name: item, + name: item, fn: (_slotProps0) => { const n0 = t0() _renderEffect(() => _setText(n0, _toDisplayString(_slotProps0["bar"]))) @@ -52,7 +52,7 @@ export function render(_ctx) { const n2 = _createComponentWithFallback(_component_Comp, null, { $: [ () => (_createForSlots(_ctx.list, (_, __, index) => ({ - name: index, + name: index, fn: () => { const n0 = t0() return n0 @@ -76,7 +76,7 @@ export function render(_ctx) { $: [ () => (_ctx.condition ? { - name: "condition", + name: "condition", fn: () => { const n0 = t0() return n0 @@ -84,14 +84,14 @@ export function render(_ctx) { } : _ctx.anotherCondition ? { - name: "condition", + name: "condition", fn: (_slotProps0) => { const n2 = t1() return n2 } } : { - name: "condition", + name: "condition", fn: () => { const n4 = t2() return n4 @@ -131,7 +131,7 @@ export function render(_ctx) { "one": () => { const n0 = t0() return n0 - }, + }, "default": () => { const n2 = t1() const n3 = t2() @@ -192,7 +192,7 @@ export function render(_ctx) { const n1 = _createComponentWithFallback(_component_Comp, null, { $: [ () => ({ - name: _ctx.named, + name: _ctx.named, fn: (_slotProps0) => { const n0 = t0() _renderEffect(() => _setText(n0, _toDisplayString(_slotProps0["foo"] + _ctx.bar))) @@ -287,7 +287,7 @@ export function render(_ctx) { "header": () => { const n0 = t0() return n0 - }, + }, "default": () => { const n2 = t1() const n3 = t2() @@ -309,7 +309,7 @@ export function render(_ctx) { "header": () => { const n0 = t0() return n0 - }, + }, "default": () => { const n3 = t1() return n3 @@ -330,7 +330,7 @@ export function render(_ctx) { "header": () => { const n0 = t0() return n0 - }, + }, "footer": () => { const n3 = t1() return n3 diff --git a/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts b/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts index a693db4ad3..20f6005ffe 100644 --- a/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts @@ -194,7 +194,7 @@ describe('compiler: element transform', () => { expect(code).toMatchSnapshot() expect(code).contains(`{ - id: () => ("foo"), + id: () => ("foo"), class: () => ("bar") }`) @@ -262,7 +262,7 @@ describe('compiler: element transform', () => { ) expect(code).toMatchSnapshot() expect(code).contains(`{ - id: () => ("foo"), + id: () => ("foo"), $: [ () => (_ctx.obj) ] @@ -286,7 +286,7 @@ describe('compiler: element transform', () => { ) expect(code).toMatchSnapshot() expect(code).contains(`[ - () => (_ctx.obj), + () => (_ctx.obj), { id: () => ("foo") } ]`) expect(ir.block.dynamic.children[0].operation).toMatchObject({ @@ -308,9 +308,9 @@ describe('compiler: element transform', () => { ) expect(code).toMatchSnapshot() expect(code).contains(`{ - id: () => ("foo"), + id: () => ("foo"), $: [ - () => (_ctx.obj), + () => (_ctx.obj), { class: () => ("bar") } ] }`) diff --git a/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts b/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts index 963f46ad2a..414ea0e298 100644 --- a/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts @@ -415,7 +415,7 @@ describe('v-on', () => { ]) expect(code).contains( `_on(n0, "click", _withModifiers(e => _ctx.test(e), ["stop","prevent"]), { - capture: true, + capture: true, once: true })`, ) diff --git a/packages/compiler-vapor/src/generators/utils.ts b/packages/compiler-vapor/src/generators/utils.ts index 904b3dc87c..93e50a244c 100644 --- a/packages/compiler-vapor/src/generators/utils.ts +++ b/packages/compiler-vapor/src/generators/utils.ts @@ -79,13 +79,13 @@ export const DELIMITERS_ARRAY: CodeFragmentDelimiters = ['[', ']', ', '] export const DELIMITERS_ARRAY_NEWLINE: CodeFragmentDelimiters = [ ['[', INDENT_START, NEWLINE], [INDENT_END, NEWLINE, ']'], - [', ', NEWLINE], + [',', NEWLINE], ] export const DELIMITERS_OBJECT: CodeFragmentDelimiters = ['{ ', ' }', ', '] export const DELIMITERS_OBJECT_NEWLINE: CodeFragmentDelimiters = [ ['{', INDENT_START, NEWLINE], [INDENT_END, NEWLINE, '}'], - [', ', NEWLINE], + [',', NEWLINE], ] export function genCall(