Support destructuring into member expression targets#413
Conversation
- Allow destructuring assignments into member expressions - Handle object, computed, and default-value targets
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds support for using member expressions as destructuring assignment targets (e.g., Changes
Sequence DiagramsequenceDiagram
participant Parser
participant AST as "AST Pattern"
participant Compiler
participant Evaluator
participant Runtime
Parser->>Parser: Parse destructuring statement
Parser->>AST: ConvertToPattern(memberExpression) -> TGocciaMemberExpressionDestructuringPattern
Parser->>Compiler: Emit bytecode for assignment (pattern)
Compiler->>Runtime: Evaluate RHS -> produce sourceValue
Compiler->>Runtime: Prepare temporaries/registers for member targets
Compiler->>Runtime: Evaluate target receiver (object) and key (if computed)
Compiler->>Runtime: Emit op to write sourceValue to target (OP_ARRAY_SET / OP_SET_PROP_CONST)
Runtime-->>Evaluator: Execute assignment opcode(s)
Evaluator->>Runtime: For runtime path, evaluate receiver/key and call AssignProperty or symbol fast-path
Runtime-->>Evaluator: Return assigned value
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/language/expressions/destructuring/member-expression-targets.js (1)
131-136: Add object-pattern coverage for the new default-member branches.The default-value check here only covers the array case. The parser change added separate
obj.prop = defaultandobj[key] = defaultconversion paths for object destructuring, but this file never exercises them, so that part of the feature can regress silently.Based on learnings: JavaScript tests should cover happy paths, edge cases, and error cases. Keep tests isolated and grouped by feature/filename.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/language/expressions/destructuring/member-expression-targets.js` around lines 131 - 136, Add two tests to the same file alongside "member expression targets with default values" covering the object-pattern branches: one named like "object member expression target with default values (static key)" that destructures an object into properties using obj.prop = default and asserts obj.prop receives the source value when present and the default when undefined (e.g., expect(obj.a).toBe(1); expect(obj.b).toBe(20)); and another named like "object member expression target with default values (computed key)" that does the same but uses a computed key path (obj[key] = default) and asserts the same outcomes; place them grouped near the existing array-case test so object default-member conversion paths are exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/language/expressions/destructuring/member-expression-targets.js`:
- Around line 131-136: Add two tests to the same file alongside "member
expression targets with default values" covering the object-pattern branches:
one named like "object member expression target with default values (static
key)" that destructures an object into properties using obj.prop = default and
asserts obj.prop receives the source value when present and the default when
undefined (e.g., expect(obj.a).toBe(1); expect(obj.b).toBe(20)); and another
named like "object member expression target with default values (computed key)"
that does the same but uses a computed key path (obj[key] = default) and asserts
the same outcomes; place them grouped near the existing array-case test so
object default-member conversion paths are exercised.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a27c839f-7335-420a-a04b-7464e0036a73
📒 Files selected for processing (5)
source/units/Goccia.AST.Expressions.passource/units/Goccia.Compiler.Expressions.passource/units/Goccia.Evaluator.passource/units/Goccia.Parser.pastests/language/expressions/destructuring/member-expression-targets.js
Benchmark Results386 benchmarks Interpreted: 🟢 120 improved · 🔴 21 regressed · 245 unchanged · avg +2.0% arraybuffer.js — Interp: 🟢 3, 11 unch. · avg +1.6% · Bytecode: 🟢 1, 🔴 6, 7 unch. · avg -2.5%
arrays.js — Interp: 🟢 6, 13 unch. · avg +1.7% · Bytecode: 🟢 2, 🔴 4, 13 unch. · avg +0.8%
async-await.js — Interp: 🟢 1, 5 unch. · avg +1.9% · Bytecode: 🟢 1, 5 unch. · avg +2.9%
base64.js — Interp: 🟢 1, 9 unch. · avg +1.7% · Bytecode: 🔴 1, 9 unch. · avg -1.6%
classes.js — Interp: 🟢 15, 16 unch. · avg +3.1% · Bytecode: 🟢 4, 🔴 2, 25 unch. · avg -0.2%
closures.js — Interp: 🟢 4, 7 unch. · avg +2.2% · Bytecode: 🟢 1, 🔴 3, 7 unch. · avg -0.5%
collections.js — Interp: 🟢 2, 10 unch. · avg +1.1% · Bytecode: 🟢 2, 10 unch. · avg +1.5%
csv.js — Interp: 🟢 2, 🔴 1, 10 unch. · avg +1.4% · Bytecode: 13 unch. · avg -0.2%
destructuring.js — Interp: 🟢 5, 🔴 1, 16 unch. · avg +1.5% · Bytecode: 🟢 6, 🔴 6, 10 unch. · avg -0.0%
fibonacci.js — Interp: 🟢 1, 7 unch. · avg +1.5% · Bytecode: 🔴 3, 5 unch. · avg -0.6%
float16array.js — Interp: 🟢 13, 🔴 3, 16 unch. · avg +2.3% · Bytecode: 🟢 12, 🔴 7, 13 unch. · avg +10.8%
for-of.js — Interp: 🟢 4, 3 unch. · avg +4.8% · Bytecode: 🔴 1, 6 unch. · avg -1.7%
helpers/bench-module.js — Interp: 0 · Bytecode: 0
iterators.js — Interp: 🟢 4, 🔴 2, 36 unch. · avg +1.4% · Bytecode: 🟢 1, 🔴 21, 20 unch. · avg -2.4%
json.js — Interp: 🟢 10, 10 unch. · avg +4.7% · Bytecode: 🟢 3, 🔴 1, 16 unch. · avg +0.4%
jsx.jsx — Interp: 🟢 7, 🔴 1, 13 unch. · avg +3.2% · Bytecode: 🔴 7, 14 unch. · avg -2.2%
modules.js — Interp: 9 unch. · avg +1.5% · Bytecode: 🔴 2, 7 unch. · avg -1.6%
numbers.js — Interp: 🟢 1, 10 unch. · avg +2.3% · Bytecode: 🔴 5, 6 unch. · avg -2.4%
objects.js — Interp: 🟢 4, 3 unch. · avg +2.8% · Bytecode: 🔴 1, 6 unch. · avg -1.0%
promises.js — Interp: 🟢 4, 8 unch. · avg +2.7% · Bytecode: 🔴 2, 10 unch. · avg -1.2%
regexp.js — Interp: 🟢 3, 8 unch. · avg +2.0% · Bytecode: 🟢 6, 5 unch. · avg +2.3%
strings.js — Interp: 🟢 5, 14 unch. · avg +10.3% · Bytecode: 🟢 2, 🔴 4, 13 unch. · avg -1.0%
tsv.js — Interp: 🔴 6, 3 unch. · avg -5.5% · Bytecode: 🔴 4, 5 unch. · avg -1.7%
typed-arrays.js — Interp: 🟢 20, 2 unch. · avg +5.8% · Bytecode: 🟢 2, 🔴 9, 11 unch. · avg -1.8%
uint8array-encoding.js — Interp: 🟢 5, 🔴 7, 6 unch. · avg -11.9% · Bytecode: 🟢 5, 🔴 7, 6 unch. · avg -17.6%
Measured on ubuntu-latest x64. Benchmark ranges compare cached main-branch min/max ops/sec with the PR run; overlapping ranges are treated as unchanged noise. Percentage deltas are secondary context. |
Suite Timing
Measured on ubuntu-latest x64. |
- Cover static and computed member targets - Verify default values apply when source values are undefined
Summary
obj.prop,this.x, andobj[key].Fixes #399