diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-05-22 19:05:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 19:05:18 +0200 |
commit | e191c70989a1dbf29b095bf6c2f7b62b90de012a (patch) | |
tree | 1cece207e007ce9655a90606289a9984932098ab | |
parent | 4b06e357655e5e4e1aba6d9591eeb7ca269850ed (diff) |
fix: ts type imports (#5733)
-rw-r--r-- | cli/swc_util.rs | 14 | ||||
-rw-r--r-- | cli/tests/error_005_missing_dynamic_import.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/error_012_bad_dynamic_import_specifier.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 7 | ||||
-rw-r--r-- | cli/tests/ts_type_imports.ts | 5 | ||||
-rw-r--r-- | cli/tests/ts_type_imports.ts.out | 6 | ||||
-rw-r--r-- | cli/tests/ts_type_imports_foo.ts | 1 | ||||
-rw-r--r-- | cli/tsc.rs | 2 |
8 files changed, 36 insertions, 3 deletions
diff --git a/cli/swc_util.rs b/cli/swc_util.rs index e07486cd7..5d900a708 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -307,6 +307,20 @@ impl Visit for NewDependencyVisitor { }); } + fn visit_ts_import_type( + &mut self, + ts_import_type: &swc_ecma_ast::TsImportType, + _parent: &dyn Node, + ) { + // TODO(bartlomieju): possibly add separate DependencyKind + let src_str = ts_import_type.arg.value.to_string(); + self.dependencies.push(DependencyDescriptor { + specifier: src_str, + kind: DependencyKind::Import, + span: ts_import_type.arg.span, + }); + } + fn visit_call_expr( &mut self, call_expr: &swc_ecma_ast::CallExpr, diff --git a/cli/tests/error_005_missing_dynamic_import.ts.out b/cli/tests/error_005_missing_dynamic_import.ts.out index 0f0e449c4..346e8cd6f 100644 --- a/cli/tests/error_005_missing_dynamic_import.ts.out +++ b/cli/tests/error_005_missing_dynamic_import.ts.out @@ -1 +1 @@ -[WILDCARD]error: Uncaught TypeError: Cannot resolve module "[WILDCARD]/bad-module.ts" +error: Cannot resolve module "[WILDCARD]/bad-module.ts" from "[WILDCARD]/error_005_missing_dynamic_import.ts" diff --git a/cli/tests/error_012_bad_dynamic_import_specifier.ts.out b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out index 57e4003ce..7bebeda12 100644 --- a/cli/tests/error_012_bad_dynamic_import_specifier.ts.out +++ b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out @@ -1 +1 @@ -[WILDCARD]error: Uncaught TypeError: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts" +error: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts" diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 59e5f554d..9f73c91b3 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1571,6 +1571,13 @@ itest!(type_directives_redirect { http_server: true, }); +itest!(ts_type_imports { + args: "run --reload ts_type_imports.ts", + output: "ts_type_imports.ts.out", + exit_code: 1, + http_server: true, +}); + itest!(types { args: "types", output: "types.out", diff --git a/cli/tests/ts_type_imports.ts b/cli/tests/ts_type_imports.ts new file mode 100644 index 000000000..f39dc7500 --- /dev/null +++ b/cli/tests/ts_type_imports.ts @@ -0,0 +1,5 @@ +/* eslint-disable */ + +type Foo = import("./ts_type_imports_foo.ts").Foo; + +const foo: Foo = new Map<string, string>(); diff --git a/cli/tests/ts_type_imports.ts.out b/cli/tests/ts_type_imports.ts.out new file mode 100644 index 000000000..2763fbce1 --- /dev/null +++ b/cli/tests/ts_type_imports.ts.out @@ -0,0 +1,6 @@ +Compile [WILDCARD]ts_type_imports.ts +error: TS2322 [ERROR]: Type 'Map<string, string>' is not assignable to type 'Foo'. + Type 'string' is not assignable to type 'number'. +const foo: Foo = new Map<string, string>(); + ~~~ + at [WILDCARD]ts_type_imports.ts:5:7 diff --git a/cli/tests/ts_type_imports_foo.ts b/cli/tests/ts_type_imports_foo.ts new file mode 100644 index 000000000..db20773f6 --- /dev/null +++ b/cli/tests/ts_type_imports_foo.ts @@ -0,0 +1 @@ +export type Foo = Map<string, number>; diff --git a/cli/tsc.rs b/cli/tsc.rs index 0bfcf6266..34f3b6de4 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -459,7 +459,7 @@ impl TsCompiler { import_map, permissions.clone(), is_dyn_import, - false, + true, ); module_graph_loader.add_to_graph(&module_specifier).await?; |