Skip to content

Commit

Permalink
refactor(migrations): update isReferenceToImport to not use `valueD…
Browse files Browse the repository at this point in the history
…eclaration` (#45292)

valueDeclaration is only set when the Symbol type is a `Value`:

* [setValueDeclaration](https://sourcegraph.com/github.com/microsoft/TypeScript@d8b21a8d6cef772fea5cf2a507b651c5d38194bd/-/blob/src/compiler/binder.ts?L321-322)
* [Value union](https://sourcegraph.com/github.com/microsoft/TypeScript@d8b21a8d6cef772fea5cf2a507b651c5d38194bd/-/blob/src/compiler/types.ts?L4849:9#tab=references)

This won't be the case if the symbol is an interface (notice that `Interface` is not in the union for `Value` above).

For this reason, we can't rely on the `valueDeclaration` property of the symbol.
Instead, it's more reliable to just compare the first items in the `declarations` list.

PR Close #45292
  • Loading branch information
atscott authored and AndrewKushnir committed Mar 8, 2022
1 parent 23003f8 commit 8227eb9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/schematics/utils/typescript/symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function isReferenceToImport(
typeChecker: ts.TypeChecker, node: ts.Node, importSpecifier: ts.ImportSpecifier): boolean {
const nodeSymbol = typeChecker.getTypeAtLocation(node).getSymbol();
const importSymbol = typeChecker.getTypeAtLocation(importSpecifier).getSymbol();
return !!(nodeSymbol && importSymbol) &&
nodeSymbol.valueDeclaration === importSymbol.valueDeclaration;
return !!(nodeSymbol?.declarations?.[0] && importSymbol?.declarations?.[0]) &&
nodeSymbol.declarations[0] === importSymbol.declarations[0];
}

/** Checks whether a node's type is nullable (`null`, `undefined` or `void`). */
Expand Down

0 comments on commit 8227eb9

Please sign in to comment.