Skip to content

Imported variables that used in string switch are not imported correctly in output #5645

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

Closed
seanchas116 opened this issue Nov 13, 2015 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@seanchas116
Copy link
Contributor

I experienced the following problem:

Problem

Variables that are imported with import statement and used in switch statement with string parameter
are not imported correctly in emitted JavaScript (no import statement emitted for those variables).

Using other types than string in switch does not cause the problem oddly.

Version

Version 1.8.0-dev.20151112

Code

mod.ts

export const foo = 1;
export const bar = "2";

test.ts

import {foo, bar} from "./mod";

switch ("foo") {
  case "foo": {
    foo;
  }
  case "bar": {
    bar;
  }
}

Command

tsc test.ts --target es6

Output

tsc does not generate import statement for foo and bar.

test.js

switch ("foo") {
    case "foo":
        foo;
    case "bar":
        bar;
}
@seanchas116
Copy link
Contributor Author

This problem seems to be introduced since 1.8.0-dev.20151110.

@seanchas116
Copy link
Contributor Author

I noticed whole type checking doesn't work inside switch (any wrong code inside switch compiles without errors)...

@seanchas116
Copy link
Contributor Author

Oh this is fixed in #5639

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 13, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants