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 errors are now strings #10150

Open
marco-ippolito opened this issue Mar 5, 2025 · 0 comments
Open

@swc/wasm-typescript errors are now strings #10150

marco-ippolito opened this issue Mar 5, 2025 · 0 comments
Labels

Comments

@marco-ippolito
Copy link
Contributor

marco-ippolito commented Mar 5, 2025

Describe the bug

I think this was a breaking change since the error is emitted as a string, which is unexpected and slightly unconvinient. The expectation was to keep emitting an js object error.
The main issue is that:

  • json parsing adds some overhead and it has to be done ALWAYS since string is not useful
  • makes error handling weird/inconsistent since swc wasm crashes are also strings so we try to json.parse and it fails while right now if its a string we know its a wasm crash

Input code

const inputCode = "module F { export type x = number }";
try {
	transformSync(inputCode, {
		mode: "transform",
	});
} catch (error) {
	console.log("TYPEOF OF ERROR", typeof error);
	assert.strictEqual(error.code, "UnsupportedSyntax");
}



TYPEOF OF ERROR string

Config

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.11.7&code=H4sIAAAAAAAAA8vNTynNSVVwU6hWSK0oyC8qUSipLEhVqFCwVcgrzU1KLVKoBQBGDE3yIwAAAA%3D%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D&strip-types=

SWC Info output

No response

Expected behavior

Emit an object

Actual behavior

Emits a string

Version

1.11.7

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant