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

TypeScript import pruning does not respect shadowed usages #298

Closed
alangpierce opened this issue Jul 7, 2018 · 0 comments
Closed

TypeScript import pruning does not respect shadowed usages #298

alangpierce opened this issue Jul 7, 2018 · 0 comments

Comments

@alangpierce
Copy link
Owner

This code in the TypeScript transform should NOT import the ./a module since it's not used (meaning "it's only used as a type" is vacuously true).

import a from './a';

function foo() {
  let a;
  a();
}

Instead, Sucrase gives this output:

"use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _a = require('./a'); var _a2 = _interopRequireDefault(_a);

function foo() {
  let a;
  a();
}

Playground link

Sucrase should notice that the a() usage refers to the shadowed a declaration and not to the import, and thus not count it as a runtime usage of a.

alangpierce added a commit that referenced this issue Nov 19, 2018
Fixes #298

TypeScript is required to remove imports where all bindings are never referenced
in a value position, but previously it could have false positives when there are
shadowed variables with the same name. Now, we do the intelligent scope-based
shadowed global detection like we do with import replacement and properly elide
when necessary.
alangpierce added a commit that referenced this issue Nov 19, 2018
…#342)

Fixes #298

TypeScript is required to remove imports where all bindings are never referenced
in a value position, but previously it could have false positives when there are
shadowed variables with the same name. Now, we do the intelligent scope-based
shadowed global detection like we do with import replacement and properly elide
when necessary.
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

No branches or pull requests

1 participant