Fix Parser.name() to treat '}' as a terminator for shorthand properties - #422
Fix Parser.name() to treat '}' as a terminator for shorthand properties#422jasonmobley wants to merge 2 commits into
Conversation
An ES6 shorthand object property immediately followed by '}' (e.g. `{a}`)
failed to parse because the terminator set in name() didn't include '}',
causing the scanner to consume it and run past the end of the object
literal. Add regression tests covering the bare-brace case plus its
variants in function-call args and array elements.
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe parser now treats ChangesES6 shorthand object property parsing
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
|
Caution CodeRabbit couldn't update its existing comment. The review summary may be out of date. Error details |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/utils.parser/spec/parserBehaviors.ts (1)
137-171: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a whitespace regression case.
The objective requires shorthand properties with whitespace before
}to remain supported. The added cases do not exercise input such asx: { a }.Proposed test
+ it('parses a shorthand property with whitespace before }', function () { + const bindings = new Parser().parse('x: { a }', ctxStub({ a: 1 })) + assert.equal(bindings.x().a, 1) + })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/utils.parser/spec/parserBehaviors.ts` around lines 137 - 171, Add a regression test in the shorthand ES6 object properties suite covering whitespace around the shorthand property, such as parsing `x: { a }` with `ctxStub({ a: 1 })`; assert that the resulting object contains key `a` with value `1`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/utils.parser/src/Parser.ts`:
- Line 136: Update the name-termination condition in Parser’s name parsing logic
so the `}` delimiter applies only when `enclosedBy` is unset, preserving `}`
inside quoted names. Add a regression test covering parsing a binding such as
`"a}b": 1` and verify the complete quoted name is returned successfully.
---
Nitpick comments:
In `@packages/utils.parser/spec/parserBehaviors.ts`:
- Around line 137-171: Add a regression test in the shorthand ES6 object
properties suite covering whitespace around the shorthand property, such as
parsing `x: { a }` with `ctxStub({ a: 1 })`; assert that the resulting object
contains key `a` with value `1`.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 906a6700-ab26-4824-9056-e3dbc6ef613e
📒 Files selected for processing (2)
packages/utils.parser/spec/parserBehaviors.tspackages/utils.parser/src/Parser.ts
The terminator characters (':', whitespace, ',', '|', '}') only mark the
end of an unquoted name. Without the !enclosedBy guard, any of these
characters occurring inside a quoted name (e.g. "a}b", "a b", "a,b")
would end the name early, since the check ran unconditionally instead of
only when not inside a quoted string. This predates the prior '}'
addition -- space/comma/pipe already had the same defect.
An ES6 shorthand object property immediately followed by '}' (e.g.
{a}) failed to parse because the terminator set in name() didn't include '}', causing the scanner to consume it and run past the end of the object literal. Add regression tests covering the bare-brace case plus its variants in function-call args and array elements.Fixes #421
Summary by CodeRabbit
Bug Fixes
Tests