-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix complex property globs #1610
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1285,7 +1285,15 @@ describe "object", -> | |
--- | ||
x.y()?.z.{a,b} | ||
--- | ||
let ref;(ref = x.y()?.z,{a:ref.a,b:ref.b}) | ||
let ref;({a:(ref = x.y()?.z).a,b:ref.b}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be out of scope for this particular fix but if Also related to that we should decide what to return in the case of the ref not resolving. I think I think the check will end up being something like Sorry it's dense but note the use of the comma operator inside the first ternary branch to manually update the ref. We may need to do it for each time Essentially manually short circuiting every There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, good point: this is probably unexpected behavior that One challenge with your compilation is that globs can appear inside object expressions, e.g. A simpler workaround, but with different behavior, would be to compile {a, b} := object.{a,b} Although, in that case, we could just write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ultimately we'll need to short circuit at exactly each Checking later in aggregate wouldn't quite be semantically correct. In this case Spacing for clarity:
For the case of projecting I think we'd want to explicitly show that we'd prefer to ignore the missing object rather than to absorb the error. TS will also warn us if the value may potentially be undefined.
Though a case could be made that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. The I'm still not totally sure which interpretation is correct, but I'm coming around to and you're probably right that Note that if we want the latter, we could avoid {c, x()?.y.{a,b}}
---
let xref, yref;
({
c,
a: (xref = x()) == null ? undefined :
(yref = xref.y).a,
b: xref == null ? undefined : yref.b
}) |
||
""" | ||
|
||
testCase """ | ||
no ref if single right-hand side | ||
--- | ||
a.b.{x} | ||
--- | ||
({x:a.b.x}) | ||
""" | ||
|
||
testCase """ | ||
|
@@ -1356,15 +1364,15 @@ describe "object", -> | |
--- | ||
f a.b.{x,y} | ||
--- | ||
let ref;f((ref = a.b,{x:ref.x,y:ref.y})) | ||
let ref;f({x:(ref = a.b).x,y:ref.y}) | ||
""" | ||
|
||
testCase """ | ||
ref in multi-argument function call | ||
--- | ||
f first, a.b.{x,y}, last | ||
--- | ||
let ref;f(first, (ref = a.b,{x:ref.x,y:ref.y}), last) | ||
let ref;f(first, {x:(ref = a.b).x,y:ref.y}, last) | ||
""" | ||
|
||
throws """ | ||
|
@@ -1421,6 +1429,14 @@ describe "object", -> | |
({a:x.a,b:x.b, c:y.c,d:y.d}) | ||
""" | ||
|
||
testCase """ | ||
two inside braced object literals with complex base | ||
--- | ||
{x().{a,b}, y()?.{c,d}} | ||
--- | ||
let ref;let ref1;({a:(ref = x()).a,b:ref.b, c:(ref1 = y())?.c,d:ref1?.d}) | ||
""" | ||
|
||
testCase """ | ||
with reserved word keys | ||
--- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to preserve the order here if possible. I believe it can have an impact if the same key also appears in the spread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This is an issue "inherited" from my old JSX attribute code, which e.g. compiles
<Foo {a, [b]: x, c}>
to<Foo a={a} c={c} {...{ [b]: x }} />
. But it shouldn't be too hard to fix, by accumulating maximal chunks that need{...{
treatment. I'll leave it for a future PR for easier review.