Skip to content

Commit 29c4afb

Browse files
authoredApr 1, 2025··
feat(ts/fast-strip): Improve error message format (#10298)
**Description:** I'll optimize the binary size in a follow-up PR. **Related issue:** - Closes #10275
1 parent 3ed8a7a commit 29c4afb

File tree

5 files changed

+914
-143
lines changed

5 files changed

+914
-143
lines changed
 

‎bindings/Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bindings/binding_typescript_wasm/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ swc_fast_ts_strip = { workspace = true, features = ["wasm-bindgen"] }
2828
tracing = { workspace = true, features = ["max_level_off"] }
2929
wasm-bindgen = { workspace = true, features = ["enable-interning"] }
3030
wasm-bindgen-futures = { workspace = true }
31+
owo-colors = { version = "4.0.0"}
32+
unicode-width = "0.1.11"

‎bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap

+21-51
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ exports[`transform in strip-only mode should not emit 'Caused by: failed to pars
77
"endLine": 1,
88
"filename": "test.ts",
99
"message": "await isn't allowed in non-async function",
10-
"snippet": "
11-
12-
function foo() { await Promise.resolve(1); }
13-
^^^^^
14-
10+
"snippet": "function foo() { await Promise.resolve(1); }
11+
^^^^^
1512
",
1613
"startColumn": 17,
1714
"startLine": 1,
@@ -51,11 +48,8 @@ exports[`transform in strip-only mode should report correct error for syntax err
5148
"endLine": 1,
5249
"filename": "test.ts",
5350
"message": "Expected ';', '}' or <eof>",
54-
"snippet": "
55-
56-
function foo() { invalid syntax }
57-
^^^^^^
58-
51+
"snippet": "function foo() { invalid syntax }
52+
^^^^^^
5953
",
6054
"startColumn": 25,
6155
"startLine": 1,
@@ -69,12 +63,9 @@ exports[`transform in strip-only mode should report correct error for unsupporte
6963
"endLine": 3,
7064
"filename": "test.ts",
7165
"message": "TypeScript enum is not supported in strip-only mode",
72-
"snippet": "
73-
74-
> enum Foo {
75-
a, b
76-
> }
77-
66+
"snippet": " > enum Foo {
67+
a, b
68+
> }
7869
",
7970
"startColumn": 0,
8071
"startLine": 1,
@@ -141,11 +132,8 @@ exports[`transform in strip-only mode should throw an error when it encounters a
141132
"endLine": 1,
142133
"filename": "test.ts",
143134
"message": "\`module\` keyword is not supported. Use \`namespace\` instead.",
144-
"snippet": "
145-
146-
module foo { }
147-
^^^^^^^^^^
148-
135+
"snippet": "module foo { }
136+
^^^^^^^^^^
149137
",
150138
"startColumn": 0,
151139
"startLine": 1,
@@ -159,11 +147,8 @@ exports[`transform in strip-only mode should throw an error when it encounters a
159147
"endLine": 1,
160148
"filename": "test.ts",
161149
"message": "\`module\` keyword is not supported. Use \`namespace\` instead.",
162-
"snippet": "
163-
164-
declare module foo { }
165-
^^^^^^^^^^
166-
150+
"snippet": "declare module foo { }
151+
^^^^^^^^^^
167152
",
168153
"startColumn": 8,
169154
"startLine": 1,
@@ -177,11 +162,8 @@ exports[`transform in strip-only mode should throw an error when it encounters a
177162
"endLine": 1,
178163
"filename": "test.ts",
179164
"message": "TypeScript namespace declaration is not supported in strip-only mode",
180-
"snippet": "
181-
182-
namespace Foo { export const m = 1; }
183-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
184-
165+
"snippet": "namespace Foo { export const m = 1; }
166+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185167
",
186168
"startColumn": 0,
187169
"startLine": 1,
@@ -195,11 +177,8 @@ exports[`transform in strip-only mode should throw an error when it encounters a
195177
"endLine": 1,
196178
"filename": "test.ts",
197179
"message": "TypeScript enum is not supported in strip-only mode",
198-
"snippet": "
199-
200-
enum Foo {}
201-
^^^^^^^^^^^
202-
180+
"snippet": "enum Foo {}
181+
^^^^^^^^^^^
203182
",
204183
"startColumn": 0,
205184
"startLine": 1,
@@ -213,11 +192,8 @@ exports[`transform in transform mode shoud throw an object even with deprecatedT
213192
"endLine": 1,
214193
"filename": "<anon>",
215194
"message": "\`module\` keyword is not supported. Use \`namespace\` instead.",
216-
"snippet": "
217-
218-
module F { export type x = number }
219-
^^^^^^^^
220-
195+
"snippet": "module F { export type x = number }
196+
^^^^^^^^
221197
",
222198
"startColumn": 0,
223199
"startLine": 1,
@@ -231,11 +207,8 @@ exports[`transform in transform mode should throw an error when it encounters a
231207
"endLine": 1,
232208
"filename": "test.ts",
233209
"message": "\`module\` keyword is not supported. Use \`namespace\` instead.",
234-
"snippet": "
235-
236-
declare module foo { }
237-
^^^^^^^^^^
238-
210+
"snippet": "declare module foo { }
211+
^^^^^^^^^^
239212
",
240213
"startColumn": 8,
241214
"startLine": 1,
@@ -249,11 +222,8 @@ exports[`transform in transform mode should throw an error when it encounters a
249222
"endLine": 1,
250223
"filename": "test.ts",
251224
"message": "\`module\` keyword is not supported. Use \`namespace\` instead.",
252-
"snippet": "
253-
254-
module foo { }
255-
^^^^^^^^^^
256-
225+
"snippet": "module foo { }
226+
^^^^^^^^^^
257227
",
258228
"startColumn": 0,
259229
"startLine": 1,

0 commit comments

Comments
 (0)
Please sign in to comment.