Skip to content

fix(compiler): avoid empty if() guard for .exact with all sys modifiers#13343

Draft
Bojun-Vvibe wants to merge 1 commit intovuejs:mainfrom
Bojun-Vvibe:fix/vuejs-vue-12319
Draft

fix(compiler): avoid empty if() guard for .exact with all sys modifiers#13343
Bojun-Vvibe wants to merge 1 commit intovuejs:mainfrom
Bojun-Vvibe:fix/vuejs-vue-12319

Conversation

@Bojun-Vvibe
Copy link
Copy Markdown

Closes #12319

Repo

vuejs/vue

Issue

#12319

Root cause

In src/compiler/codegen/events.ts, the .exact modifier branch builds a guard condition by filtering out the system modifiers already present on the handler. When all four system modifiers (ctrl, shift, alt, meta) are listed alongside .exact, the filter yields an empty array and join('||') returns '', which is then wrapped by genGuard to produce the syntactically invalid if()return null;.

Fix

Compute the joined condition first and only emit genGuard(condition) when the condition is a non-empty string. With every system modifier already required by other modifier guards, the .exact guard becomes redundant and can be safely omitted.

Regression test

test/unit/modules/compiler/codegen.spec.ts — added an assertCodegen case for <button @keydown.ctrl.shift.alt.meta.exact="onClick"> asserting the generated render code contains the four individual if(!$event.XKey)return null; guards and no empty if() clause.

Risk

trivial

Verification

skipped: project devDependencies (vitest) are not installed in this fresh clone, and npx vitest cannot resolve vitest/config. Fix verified by inspection: the new branch only suppresses genGuard when its condition string is empty, leaving all existing behavior untouched, and the new codegen assertion mirrors the deterministic output expected from the surrounding generator.

When all four system modifiers (ctrl/shift/alt/meta) are combined with

.exact, the filtered guard condition is empty, producing 'if()return null;'

which is a syntax error. Skip emitting the guard when there is no condition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.exact modifier : Failed to generate render function

1 participant