Skip to content

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

Merged
6 commits merged into from
Sep 17, 2018

Conversation

ghost
Copy link

@ghost ghost commented Sep 12, 2018

(or similar bindDiagnostics-affecting options)

Fixes #24292

@ghost ghost requested a review from sheetalkamat September 12, 2018 23:02
export function getSourceFileAffectingCompilerOptions(compilerOptions: CompilerOptions): CompilerOptions {
const res: CompilerOptions = {};
for (const option of optionDeclarations) {
if (option.name in compilerOptions && isSourceFileAffectingCompilerOption(option)) {
Copy link
Member

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

Copy link
Member

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

Copy link
Author

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.

@ghost ghost force-pushed the unused_label_config branch from 6722236 to 6890ad2 Compare September 13, 2018 22:48
@@ -441,6 +449,7 @@ namespace ts {
type: "string",
isFilePath: true
},
affectsSourceFile: true,
Copy link
Member

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

Copy link
Author

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.

oldOptions.baseUrl !== newOptions.baseUrl ||
!equalOwnProperties(oldOptions.paths, newOptions.paths)
);
return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions));
Copy link
Member

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)

Copy link
Author

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".

Copy link
Member

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,
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

👍

oldOptions.baseUrl !== newOptions.baseUrl ||
!equalOwnProperties(oldOptions.paths, newOptions.paths)
);
return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions));
Copy link
Member

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.

Copy link
Author

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.

@ghost ghost force-pushed the unused_label_config branch from 09e065e to 433e9b4 Compare September 14, 2018 23:32
@@ -305,10 +305,10 @@ namespace ts {
assert.equal(program1.structureIsReused, StructureIsReused.Not);
});

it("fails if rootdir changes", () => {
it("succeeds if rootdir changes", () => {
Copy link
Author

@ghost ghost Sep 15, 2018

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.

@ghost
Copy link
Author

ghost commented Sep 15, 2018

Note: Filed issue #27108

@ghost ghost merged commit a57467a into master Sep 17, 2018
@ghost ghost deleted the unused_label_config branch September 17, 2018 17:53
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant