fix(lower): #6143 — unresolvable object shorthand throws ReferenceError (was silently dropped)#6144
Merged
Merged
Conversation
…renceError (was silently dropped)
`const o = { undeclaredName }` must throw `ReferenceError: undeclaredName is not
defined` — the shorthand reads the binding. Perry's object-literal lowering
instead did `continue`, silently dropping the property, in both legacy handlers
(non-spread and spread). The closed-shape fast path already bails to these on an
unresolvable shorthand, so `{ undeclaredName }` produced an empty object.
Fix: lower the unresolvable shorthand as a normal identifier read
(`lower_expr(Ident)`), which throws for a truly-undeclared name and reads a
sloppy implicit global when one was assigned.
Validated vs Node: `{ undeclaredZZZ }` and `{ ...{x:1}, undeclaredYYY }` now throw
ReferenceError; resolvable shorthands (`{a,b}`, `{a, fn: fn()}`), spreads
(`{...{a}, b}`), and sloppy implicit globals (`g=5; {g}`) are unchanged.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn object literal lowering, unresolvable shorthand properties in both the spread/IIFE path and the computed-key post-init path now lower to an identifier read via ChangesObject literal shorthand lowering fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Fixes #6143.
const o = { undeclaredName }must throwReferenceError: undeclaredName is not defined(a shorthand reads its binding). Perry's object-literal lowering instead didcontinue, silently dropping the property, in both legacy handlers (non-spread + spread). The closed-shape fast path bails to those on an unresolvable shorthand, so{ undeclaredName }produced an empty object.Fix
Lower the unresolvable shorthand as a normal identifier read (
lower_expr(Ident)) — which throws for a truly-undeclared name and reads a sloppy implicit global if one exists.Validation (vs Node)
Now throw ReferenceError:
{ a, undeclaredZZZ, b },{ ...{x:1}, undeclaredYYY },{ undeclaredXYZ }.Unchanged:
{a,b}→{"a":1,"b":2},{a, fn: fn()}, spread{...{a}, b}, sloppy implicit globalg=5; {g}→{"g":5}.Summary by CodeRabbit
ReferenceErrorrather than disappearing.