Fix bugs: Replace SourceFile if '--noUnusedLabels' changed#27060
Conversation
| 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.
Like this! Can we instead put property on option declaration instead. Eg look at affectsSemanticDiagnostics in CommandLineOptionBase
There was a problem hiding this comment.
Also noUnusedLabels shouldnt need the new sourceFile. Instead it needs to set affectsSemanticDiagnostics
There was a problem hiding this comment.
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
| type: "string", | ||
| isFilePath: true | ||
| }, | ||
| affectsSourceFile: true, |
There was a problem hiding this comment.
Why ? RootDir and paths shouldn't affect syntaxTree or bindDiagnostics?
Same goes for lib, baseUrl, typeRoots, paths
There was a problem hiding this comment.
Those all effect module resolution, and SourceFile stores resolvedModules.
| oldOptions.baseUrl !== newOptions.baseUrl || | ||
| !equalOwnProperties(oldOptions.paths, newOptions.paths) | ||
| ); | ||
| return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions)); |
There was a problem hiding this comment.
Also want to check if: getStrictOptionValue(opts, "alwaysStrict") (which depends on value of strict and alwaysStrict flag)
There was a problem hiding this comment.
Handled this by adding affectsSourceFile to both "alwaysStrict" and "strict".
There was a problem hiding this comment.
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
| // use type = object to copy the value as-is | ||
| name: "paths", | ||
| type: "object", | ||
| affectsModuleResolution: true, |
There was a problem hiding this comment.
While you have added this, could you please change changesAffectModuleResolution as well to use this instead of manual checks.
| oldOptions.baseUrl !== newOptions.baseUrl || | ||
| !equalOwnProperties(oldOptions.paths, newOptions.paths) | ||
| ); | ||
| return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions)); |
There was a problem hiding this comment.
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.
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
| }); | ||
|
|
||
| it("fails if rootdir changes", () => { | ||
| it("succeeds if rootdir changes", () => { |
There was a problem hiding this comment.
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