-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
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 |
---|---|---|
|
@@ -1363,6 +1363,11 @@ namespace ts { | |
onUnRecoverableConfigFileDiagnostic: noop, | ||
}; | ||
|
||
// The call to isProgramUptoDate below may refer back to documentRegistryBucketKey; | ||
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. That's scary, but I don't see a better way around it. @sheetalkamat might. Either way, thanks for the comment! 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. Seems like its needed only for config file's json and we currently dont use that since we implement |
||
// calculate this early so it's not undefined if downleveled to a var (or, if emitted | ||
// as a const variable without downleveling, doesn't crash). | ||
const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings); | ||
|
||
// If the program is already up-to-date, we can reuse it | ||
if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), fileName => compilerHost!.fileExists(fileName), hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) { | ||
return; | ||
|
@@ -1374,7 +1379,6 @@ namespace ts { | |
// the program points to old source files that have been invalidated because of | ||
// incremental parsing. | ||
|
||
const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings); | ||
const options: CreateProgramOptions = { | ||
rootNames: rootFileNames, | ||
options: newSettings, | ||
|
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.
Was this intended to be equivalent? It doesn't look equivalent (and it isn't obviously related to
let
/const
).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.
+1 : This is not equivalent but clearly tests are not failing..
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.
It looks equivalent to me... Am I missing something?
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 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.
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.
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!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 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.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’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.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'm OOF but had some time in the airport, changed it so it's semantically equivalent to be safe.
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'm a little worried about someone adding a case and missing the exception, but I agree that it looks equivalent now.
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.
The alternative is to just use var, if you all find that preferable.