summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/global_state.rs27
-rw-r--r--cli/tests/integration_tests.rs5
-rw-r--r--cli/tests/ts_type_only_import.d.ts3
-rw-r--r--cli/tests/ts_type_only_import.ts1
-rw-r--r--cli/tests/ts_type_only_import.ts.out4
5 files changed, 29 insertions, 11 deletions
diff --git a/cli/global_state.rs b/cli/global_state.rs
index 3290be25f..8e5808c90 100644
--- a/cli/global_state.rs
+++ b/cli/global_state.rs
@@ -9,7 +9,6 @@ use crate::module_graph::ModuleGraphFile;
use crate::module_graph::ModuleGraphLoader;
use crate::msg;
use crate::msg::MediaType;
-use crate::op_error::OpError;
use crate::permissions::Permissions;
use crate::state::exit_unstable;
use crate::tsc::CompiledModule;
@@ -236,16 +235,22 @@ impl GlobalState {
};
let compiled_module = if was_compiled {
- state1
- .ts_compiler
- .get_compiled_module(&out.url)
- .map_err(|e| {
- let msg = e.to_string();
- OpError::other(format!(
- "Failed to get compiled source code of {}.\nReason: {}",
- out.url, msg
- ))
- })?
+ match state1.ts_compiler.get_compiled_module(&out.url) {
+ Ok(module) => module,
+ Err(e) => {
+ let msg = format!(
+ "Failed to get compiled source code of \"{}\".\nReason: {}\n\
+ If the source file provides only type exports, prefer to use \"import type\" or \"export type\" syntax instead.",
+ out.url, e.to_string()
+ );
+ info!("{} {}", crate::colors::yellow("Warning"), msg);
+
+ CompiledModule {
+ code: "".to_string(),
+ name: out.url.to_string(),
+ }
+ }
+ }
} else {
CompiledModule {
code: String::from_utf8(out.source_code.clone())?,
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index f832358ff..baed26523 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -1972,6 +1972,11 @@ itest!(ts_decorators {
output: "ts_decorators.ts.out",
});
+itest!(ts_type_only_import {
+ args: "run --reload ts_type_only_import.ts",
+ output: "ts_type_only_import.ts.out",
+});
+
itest!(swc_syntax_error {
args: "run --reload swc_syntax_error.ts",
output: "swc_syntax_error.ts.out",
diff --git a/cli/tests/ts_type_only_import.d.ts b/cli/tests/ts_type_only_import.d.ts
new file mode 100644
index 000000000..d48e4b48a
--- /dev/null
+++ b/cli/tests/ts_type_only_import.d.ts
@@ -0,0 +1,3 @@
+export interface HelloWorld {
+ a: string;
+}
diff --git a/cli/tests/ts_type_only_import.ts b/cli/tests/ts_type_only_import.ts
new file mode 100644
index 000000000..53e114373
--- /dev/null
+++ b/cli/tests/ts_type_only_import.ts
@@ -0,0 +1 @@
+export * from "./ts_type_only_import.d.ts";
diff --git a/cli/tests/ts_type_only_import.ts.out b/cli/tests/ts_type_only_import.ts.out
new file mode 100644
index 000000000..d7120966f
--- /dev/null
+++ b/cli/tests/ts_type_only_import.ts.out
@@ -0,0 +1,4 @@
+Check [WILDCARD]ts_type_only_import.ts
+Warning Failed to get compiled source code of "[WILDCARD]ts_type_only_import.d.ts".
+Reason: [WILDCARD] (os error 2)
+If the source file provides only type exports, prefer to use "import type" or "export type" syntax instead.