Skip to content

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

Closed
@seanchas116

Description

@seanchas116

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions