fix(compiler): avoid empty if() guard for .exact with all sys modifiers#13343
Draft
Bojun-Vvibe wants to merge 1 commit intovuejs:mainfrom
Draft
fix(compiler): avoid empty if() guard for .exact with all sys modifiers#13343Bojun-Vvibe wants to merge 1 commit intovuejs:mainfrom
Bojun-Vvibe wants to merge 1 commit intovuejs:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12319
Repo
vuejs/vue
Issue
#12319
Root cause
In
src/compiler/codegen/events.ts, the.exactmodifier 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 andjoin('||')returns'', which is then wrapped bygenGuardto produce the syntactically invalidif()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.exactguard becomes redundant and can be safely omitted.Regression test
test/unit/modules/compiler/codegen.spec.ts— added anassertCodegencase for<button @keydown.ctrl.shift.alt.meta.exact="onClick">asserting the generated render code contains the four individualif(!$event.XKey)return null;guards and no emptyif()clause.Risk
trivial
Verification
skipped: project devDependencies (
vitest) are not installed in this fresh clone, andnpx vitestcannot resolvevitest/config. Fix verified by inspection: the new branch only suppressesgenGuardwhen its condition string is empty, leaving all existing behavior untouched, and the new codegen assertion mirrors the deterministic output expected from the surrounding generator.