Skip to content

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

@marco-ippolito

Description

@marco-ippolito

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions