- Notifications
You must be signed in to change notification settings - Fork12.9k
Add logical assignment operator#37727
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
DanielRosenwasser commentedApr 1, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Resolved |
} | ||
function foo2 (f?: (a: number) => void) { | ||
f ||= (a => a) |
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.
Great test!
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.
😉
if (thing &&= thing.original) { | ||
console.log(thing.name); | ||
~~~~~ | ||
!!! error TS2532: Object is possibly 'undefined'. |
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.
Glad the test caught this - that was part of my intent when I wrote it. As you probably know, this needs to be fixed becausething.original
should be defined. Let@ahejlsberg or@rbuckton know if you need help with that.
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.
I spent all afternoon And evening in this one😂
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.
Yeah, the code can be hard to get through, and I've honestly never wired up the CFG. Also, binary expressions recently changed to use a "trampolining" approach to avoid stack overflows on deep traversals. You can ask@weswigham about that.
If you want to play around to see if you can get it working, I'll provide a few tips and@weswigham and@ahejlsberg can weigh in case I'm totally off.
First take a look at some of the logic at
TypeScript/src/compiler/binder.ts
Line 1418 inb58a29b
constpreRightLabel=createBranchLabel(); |
and
TypeScript/src/compiler/binder.ts
Line 1513 inb58a29b
if(operator===SyntaxKind.AmpersandAmpersandToken||operator===SyntaxKind.BarBarToken||operator===SyntaxKind.QuestionQuestionToken){ |
The binder needs to create branch labels for these new compound assignment operators (similar to inbindLogicalExpression
) while creating at least one flow node that's considered an assignment after the expression (as inbindAssignmentTargetFlow
). At a glance, Ithink that a lot of the logic can be reused and the changes can be added aroundhere
Eventually ingetTypeAtFlowNode
in the type-checker, you need to try to find a way to combine the logic whenflags & FlowFlags.Assignment
andflags & FlowFlags.Label
both apply. To start, I'd just get something working, then worry about how to share the code.
Feel free to ask some questions if you need help. If you'd prefer, I'm also sure we could send a PR if you'd like, but it's up to you.
src/compiler/utilities.ts Outdated
@@ -4355,6 +4365,12 @@ namespace ts { | |||
|| token === SyntaxKind.ExclamationToken; | |||
} | |||
export function isLogicalAssignmentOperator(token: SyntaxKind): boolean { |
DanielRosenwasserApr 1, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
ConsiderisShortCircuitingAssignmentOperator
orisLogicalOrCoalescingAssignmentOperator
src/compiler/utilities.ts Outdated
@@ -3334,6 +3340,10 @@ namespace ts { | |||
return 14; | |||
case SyntaxKind.AsteriskAsteriskToken: | |||
return 15; | |||
case SyntaxKind.BarBarEqualsToken: |
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.
This section doesn't seem to cover any of the assignment or compound assignment operators. I'd get clarity from whoever originally wrote this function whether this should be here, because I think these 3 cases don't belong here.
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.
Yeah, it seems to be caught bygetOperatorPrecedence
above.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
It seems works, but i don't know why.🤷🏻♂️ |
@typescript-bot pack this |
typescript-bot commentedApr 2, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Heya@DanielRosenwasser, I've started to run the tarball bundle task on this PR at1c92781. You can monitor the buildhere. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Current CFG is
the same as downlevel result
|
@typescript-bot pack this. |
typescript-bot commentedApr 2, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hey@Kingwl, I've packed this intoan installable tgz. You can install it for testing by referencing it in your
and then running |
@typescript-bot pack this. |
typescript-bot commentedApr 4, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hey@Kingwl, I've packed this intoan installable tgz. You can install it for testing by referencing it in your
and then running |
Does the playground not supported pull request build now?🤷🏻♂️ |
@weswigham or@orta might know |
orta commentedApr 7, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the ping, looks like I need to dig into the playground builder - been red for a week |
Made a PR:microsoft/monaco-typescript#59 |
and withorta/make-monaco-builds@f17ca4a in I can request a playground again -@typescript-bot pack this. |
typescript-bot commentedApr 7, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
typescript-bot commentedApr 7, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hey@orta, I've packed this intoan installable tgz. You can install it for testing by referencing it in your
and then running There is also a playgroundfor this build. |
Only one pipeline failed with ECONNRESET. |
Looks like this needs to be rebased onto the latest |
Uh oh!
There was an error while loading.Please reload this page.
DanielRosenwasser commentedMay 20, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
One more review? |
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment2.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
tests/baselines/reference/logicalAssignment5(target=es2015).errors.txt OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
DanielRosenwasser commentedMay 27, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
One more peek@rbuckton? |
up👆 |
Xample commentedJul 24, 2020
Glad to see things moved since#20378 😀 |
g-patel commentedSep 3, 2020
What version of typescript will this be available in? |
ExE-Boss commentedSep 3, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@g-patel This shippedin TypeScript 4.0. |
Uh oh!
There was an error while loading.Please reload this page.
Fixes#37255