Skip to content

Fix bugs: Replace SourceFile if '--noUnusedLabels' changed#27060

Merged
6 commits merged into
masterfrom
unused_label_config
Sep 17, 2018
Merged

Fix bugs: Replace SourceFile if '--noUnusedLabels' changed#27060
6 commits merged into
masterfrom
unused_label_config

Conversation

@ghost
Copy link
Copy Markdown

@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
Comment thread 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)) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread src/compiler/commandLineParser.ts Outdated
type: "string",
isFilePath: true
},
affectsSourceFile: true,
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/compiler/program.ts Outdated
oldOptions.baseUrl !== newOptions.baseUrl ||
!equalOwnProperties(oldOptions.paths, newOptions.paths)
);
return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions));
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

// use type = object to copy the value as-is
name: "paths",
type: "object",
affectsModuleResolution: true,
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍

Comment thread src/compiler/program.ts Outdated
oldOptions.baseUrl !== newOptions.baseUrl ||
!equalOwnProperties(oldOptions.paths, newOptions.paths)
);
return !!oldOptions && !isJsonEqual(getSourceFileAffectingCompilerOptions(oldOptions), getSourceFileAffectingCompilerOptions(newOptions));
Copy link
Copy Markdown
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
Copy Markdown
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
});

it("fails if rootdir changes", () => {
it("succeeds if rootdir changes", () => {
Copy link
Copy Markdown
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
Copy Markdown
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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant