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

fix: ts type imports #5733

Merged
merged 9 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cli/swc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/error_005_missing_dynamic_import.ts.out
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion cli/tests/error_012_bad_dynamic_import_specifier.ts.out
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/ts_type_imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable */

type Foo = import("./ts_type_imports_foo.ts").Foo;

const foo: Foo = new Map<string, string>();
6 changes: 6 additions & 0 deletions cli/tests/ts_type_imports.ts.out
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions cli/tests/ts_type_imports_foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Foo = Map<string, number>;
2 changes: 1 addition & 1 deletion cli/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl TsCompiler {
import_map,
permissions.clone(),
is_dyn_import,
false,
true,
);

module_graph_loader.add_to_graph(&module_specifier).await?;
Expand Down