From aaeb0ab3b325c4f9d789aec78a52eec0dfcfac83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sun, 29 Dec 2024 20:57:18 +0900 Subject: [PATCH] fix: Remove `Caused by: 'failed to parse'` from TS blank space (#9820) --- .../__tests__/__snapshots__/transform.js.snap | 9 +++++++++ bindings/binding_typescript_wasm/__tests__/transform.js | 8 ++++++++ bindings/binding_typescript_wasm/src/lib.rs | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap b/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap index 7b5b95a0cc17..23cb962051ca 100644 --- a/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap +++ b/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`transform in strip-only mode should not emit 'Caused by: failed to parse' 1`] = ` +" x await isn't allowed in non-async function + ,---- + 1 | function foo() { await Promise.resolve(1); } + : ^^^^^^^ + \`---- +" +`; + exports[`transform in strip-only mode should remove declare enum 1`] = ` { "code": " ", diff --git a/bindings/binding_typescript_wasm/__tests__/transform.js b/bindings/binding_typescript_wasm/__tests__/transform.js index b1bc08abedac..8a1e491db566 100644 --- a/bindings/binding_typescript_wasm/__tests__/transform.js +++ b/bindings/binding_typescript_wasm/__tests__/transform.js @@ -130,5 +130,13 @@ describe("transform", () => { }) ).rejects.toMatchSnapshot(); }); + + it("should not emit 'Caused by: failed to parse'", async () => { + await expect( + swc.transform("function foo() { await Promise.resolve(1); }", { + mode: "strip-only", + }) + ).rejects.toMatchSnapshot(); + }); }); }); diff --git a/bindings/binding_typescript_wasm/src/lib.rs b/bindings/binding_typescript_wasm/src/lib.rs index 0a9a3b35e525..13c751adc6e3 100644 --- a/bindings/binding_typescript_wasm/src/lib.rs +++ b/bindings/binding_typescript_wasm/src/lib.rs @@ -53,5 +53,5 @@ fn operate(input: String, options: Options) -> Result { } pub fn convert_err(err: Error) -> wasm_bindgen::prelude::JsValue { - format!("{:?}", err).into() + format!("{}", err).into() }