Skip to content
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 up code so we don't crash when TS itself is emitted with let/const #50151

Merged
merged 2 commits into from
Aug 10, 2022

Conversation

jakebailey
Copy link
Member

Alternative to #50141 split out from #50022 where I was performance testing the cost of let/const.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 2, 2022
case AssignmentDeclarationKind.ModuleExports:
valueDeclaration ||= binaryExpression.symbol?.valueDeclaration;
const valueDeclaration = kind !== AssignmentDeclarationKind.ModuleExports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intended to be equivalent? It doesn't look equivalent (and it isn't obviously related to let/const).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 : This is not equivalent but clearly tests are not failing..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks equivalent to me... Am I missing something?

Copy link
Member Author

@jakebailey jakebailey Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's any of the original three, it'll not be equal to the 4th one, so it picks the first branch, otherwise it's ModuleExports, so it picks the second branch. I tried to keep them in order, but maybe it'd be clearer to just not use an if, and copy the two lines to both blocks.

Copy link
Member Author

@jakebailey jakebailey Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. If it was one of the first few cases but the expression turned out to be undefined, it'll pick the second expression even if it's not ModuleExports. That is different!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, and in all of our test cases, if binaryExpression.left.symbol?.valueDeclaration is undefined, binaryExpression.symbol?.valueDeclaration is also undefined, hence why my PR doesn't fail even though the logic is different.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m sure I wouldn’t have written this as a falls-through and ||= if I could have combined the cases like you have here, but it’s disappointing the tests don’t capture that. It’s possible I was being overly defensive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OOF but had some time in the airport, changed it so it's semantically equivalent to be safe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about someone adding a case and missing the exception, but I agree that it looks equivalent now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is to just use var, if you all find that preferable.

@@ -1363,6 +1363,11 @@ namespace ts {
onUnRecoverableConfigFileDiagnostic: noop,
};

// The call to isProgramUptoDate below may refer back to documentRegistryBucketKey;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's scary, but I don't see a better way around it. @sheetalkamat might.

Either way, thanks for the comment!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like its needed only for config file's json and we currently dont use that since we implement getParsedCommandLine on project.. But yeah this change looks good

@jakebailey
Copy link
Member Author

I know this is approved (so people must be happy enough with it), but would it be preferred for this to be var instead just so that it's less likely someone adds an extra case not realizing they want one behavior over another?

Happy to do it either way.

@amcasey
Copy link
Member

amcasey commented Aug 10, 2022

I know this is approved (so people must be happy enough with it), but would it be preferred for this to be var instead just so that it's less likely someone adds an extra case not realizing they want one behavior over another?

Happy to do it either way.

Please don't use var.

@jakebailey jakebailey merged commit 8a24fe7 into microsoft:main Aug 10, 2022
@jakebailey jakebailey deleted the fix-tdz branch August 10, 2022 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants