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

@swc/wasm-typescript improve error message output #9884

Closed
marco-ippolito opened this issue Jan 15, 2025 · 1 comment · Fixed by #10144
Closed

@swc/wasm-typescript improve error message output #9884

marco-ippolito opened this issue Jan 15, 2025 · 1 comment · Fixed by #10144
Assignees
Milestone

Comments

@marco-ippolito
Copy link
Contributor

marco-ippolito commented Jan 15, 2025

Describe the feature

This is the swc error:

   x await isn't allowed in non-async function
   ,----
 1 | function foo(){ await Promise.resolve(1) }
   :                       ^^^^^^^
   `----

This is the Node.js error

function foo(){ await Promise.resolve(1) }
                ^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules

Since we are rewrapping these error messages I'd like them to be consistent.
I'd remove the x and the blank space at its left and the dashes around the function.
Maybe splitting the message and the body as object properties would be useful

Babel plugin or link to the feature description

No response

Additional context

No response

@marco-ippolito
Copy link
Contributor Author

marco-ippolito commented Feb 13, 2025

@kdy1
this would be the most complete error object

type SwcError = {
       code: "UnsupportedSyntax" | "InvalidSyntax";
       message: string; // await isn't allowed in non-async function
       snippet:  string, // (snippet is a bad name but you get the idea) function foo(){ await Promise.resolve(1) }
       //                                                                                 ^^^^^
       filename: string,
       line: number,
       column: number
}

kdy1 added a commit that referenced this issue Mar 4, 2025
**Description:**

 - Improves span for `swc_fast_ts_strip`.
 - Add `try_with_json_handler` to `swc_error_reporters`.
 - `@swc/wasm-typescript` now throws a string separated by `\n`.

**Related issue:**

 - Closes #9884
@kdy1 kdy1 modified the milestones: Planned, v1.11.7 Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants