Skip to content
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

Fixes making changes on JS imports #32626

Merged
merged 3 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29973,8 +29973,10 @@ namespace ts {
function checkAliasSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier) {
const symbol = getSymbolOfNode(node);
const target = resolveAlias(symbol);
if (target !== unknownSymbol) {
// For external modules symbol represent local symbol for an alias.

const shouldSkipWithJSExpandoTargets = symbol.flags & SymbolFlags.Assignment;
Copy link
Member

Choose a reason for hiding this comment

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

I find an ad-hoc change like this suspect (despite our JS support being littered with them). You said the differences were caused by the symbol being bound with different flags in JS vs in TS - would that not imply that the appropriate fix lies in adjusting what flags the symbol is bound with, or using the symbol flags that are already different to change the behavior (and not walking up the node tree to find the context file)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK makes sense, I've changed it - I'm a little worried now that before I felt like I definitely got what was going on previously, and now I partially get the change.

Copy link
Member

Choose a reason for hiding this comment

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

The only flag you should need to check here is Assignment - Module comes from the thing being a module, and Alias (AliasExcludes === Alias, so, y'know, if you see AliasExcludes in the debug otuput it means Alias) from the thing being an import. Also, you should be able to check for that instead of isInJSFile(node) && moduleKind !== ModuleKind.ES2015, not in addition to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ergh, I'm so sure I tried that earlier and got a tonne of fails. Thanks yeah, that's exactly what it needed.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the Assignment symbol flag is used to mean "allow unusual symbol merges, don't issue an error, deal with the result", since what you wanna suppress here is an error, checking just for that flag means sense.

if (!shouldSkipWithJSExpandoTargets && target !== unknownSymbol) {
// For external modules symbol represents local symbol for an alias.
// This local symbol will merge any other local declarations (excluding other aliases)
// and symbol.flags will contains combined representation for all merged declaration.
// Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ namespace ts {
isDebugInfoEnabled = true;
}
}
}
}

This file was deleted.