-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix bugs: Replace SourceFile if '--noUnusedLabels' changed #27060
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
Conversation
src/compiler/utilities.ts
Outdated
export function getSourceFileAffectingCompilerOptions(compilerOptions: CompilerOptions): CompilerOptions { | ||
const res: CompilerOptions = {}; | ||
for (const option of optionDeclarations) { | ||
if (option.name in compilerOptions && isSourceFileAffectingCompilerOption(option)) { |
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.
Like this! Can we instead put property on option declaration instead. Eg look at affectsSemanticDiagnostics
in CommandLineOptionBase
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.
Also noUnusedLabels
shouldnt need the new sourceFile. Instead it needs to set affectsSemanticDiagnostics
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 already had affectsSemanticDiagnostics
, the problem is that the --noUnusedLabels
error is attached to the SourceFile#bindDiagnostics
directly during binding. While affectsSemanticDiagnostics
seems to only affect semanticDiagnosticsPerFile
.
6722236
to
6890ad2
Compare
src/compiler/commandLineParser.ts
Outdated
@@ -441,6 +449,7 @@ namespace ts { | |||
type: "string", | |||
isFilePath: true | |||
}, | |||
affectsSourceFile: true, |
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.
Why ? RootDir and paths shouldn't affect syntaxTree or bindDiagnostics?
Same goes for lib, baseUrl, typeRoots, paths
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.
Those all effect module resolution, and SourceFile
stores resolvedModules
.
src/compiler/program.ts
Outdated
oldOptions.baseUrl !== newOptions.baseUrl || | ||
!equalOwnProperties(oldOptions.paths, newOptions.paths) | ||
); | ||
return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions)); |
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.
Also want to check if: getStrictOptionValue(opts, "alwaysStrict")
(which depends on value of strict
and alwaysStrict
flag)
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.
Handled this by adding affectsSourceFile
to both "alwaysStrict" and "strict".
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 don't think you need to create separate objects just for comparison, You should just iterate through options and achieve same thing.. Eg. compilerOptionsAffectSemanticDiagnostics
@@ -426,6 +434,7 @@ namespace ts { | |||
// use type = object to copy the value as-is | |||
name: "paths", | |||
type: "object", | |||
affectsModuleResolution: true, |
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.
While you have added this, could you please change changesAffectModuleResolution
as well to use this instead of manual checks.
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.
👍
src/compiler/program.ts
Outdated
oldOptions.baseUrl !== newOptions.baseUrl || | ||
!equalOwnProperties(oldOptions.paths, newOptions.paths) | ||
); | ||
return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions)); |
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.
Btw you have option.type to determine if you want to do arrayIsEqualTo or equalOwnProperties or just direct equals check.
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.
Here's how far I got:
export function areCompilerOptionsEqual(option: CommandLineOption, a: unknown, b: unknown) {
switch (option.type) {
case "boolean":
case "number":
case "string":
return a === b;
case "list":
return arraysEqual(a as unknown[], b as unknown[], (aa, bb) => areCompilerOptionsEqual((option as CommandLineOptionOfListType).element, aa, bb));
case "object":
return equalOwnProperties(a as MapLike<unknown>, b as MapLike<unknown>, isJsonEqual);
default:
something with maps;
}
}
Doesn't seem worth it since I need to call isJsonEqual
in the nested case anyway, and I need some casts which might not be valid if someone put a wrong value in their tsconfig.
1a3f969
to
09e065e
Compare
09e065e
to
433e9b4
Compare
@@ -305,10 +305,10 @@ namespace ts { | |||
assert.equal(program1.structureIsReused, StructureIsReused.Not); | |||
}); | |||
|
|||
it("fails if rootdir changes", () => { | |||
it("succeeds if rootdir changes", () => { |
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 think this change is correct? rootDir
doesn't affect module resolution, it affects emit.
Note: Filed issue #27108 |
(or similar bindDiagnostics-affecting options)
Fixes #24292