Skip to content

fix(wasm): transfer AST to JS as JSON string#9259

Merged
graphite-app[bot] merged 1 commit intomainfrom
02-20-fix_wasm_transfer_ast_to_js_as_json_string
Feb 20, 2025
Merged

fix(wasm): transfer AST to JS as JSON string#9259
graphite-app[bot] merged 1 commit intomainfrom
02-20-fix_wasm_transfer_ast_to_js_as_json_string

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Feb 20, 2025

In @oxc-parser/wasm NPM package, transfer the AST to JS as a JSON string, and parse it to a Program object on JS side.

This fixes a couple of bugs - previously RegExps and BigInts were deserialized as null.

The mechanism for doing this is pretty hacky. After wasm-pack generates the JS binding files, a script modifies these files to add a getter for program property on ParseResult. That getter deserializes the JSON to a Program.

The hackyness is not ideal, but I'm not familiar enough with WASM build systems to see if there's a better way. This does at least seem to work!

Copy link
Member Author

overlookmotel commented Feb 20, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the C-bug Category - Bug label Feb 20, 2025
@overlookmotel overlookmotel marked this pull request as ready for review February 20, 2025 14:12
@overlookmotel overlookmotel force-pushed the 02-20-fix_wasm_transfer_ast_to_js_as_json_string branch from 047383b to f41affb Compare February 20, 2025 14:26
@overlookmotel overlookmotel requested a review from Boshen February 20, 2025 14:33
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Feb 20, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 20, 2025

Merge activity

@overlookmotel overlookmotel force-pushed the 02-20-fix_wasm_transfer_ast_to_js_as_json_string branch from f41affb to a670475 Compare February 20, 2025 14:37
In [@oxc-parser/wasm](https://www.npmjs.com/package/@oxc-parser/wasm) NPM package, transfer the AST to JS as a JSON string, and parse it to a `Program` object on JS side.

This fixes a couple of bugs - previously `RegExp`s and `BigInt`s were deserialized as `null`.

The mechanism for doing this is pretty hacky. After `wasm-pack` generates the JS binding files, a script modifies these files to add a getter for `program` property on `ParseResult`. That getter deserializes the JSON to a `Program`.

The hackyness is not ideal, but I'm not familiar enough with WASM build systems to see if there's a better way. This does at least seem to work!
@graphite-app graphite-app bot force-pushed the 02-20-fix_wasm_transfer_ast_to_js_as_json_string branch from a670475 to 5acc6ec Compare February 20, 2025 14:37
@graphite-app graphite-app bot merged commit 5acc6ec into main Feb 20, 2025
15 checks passed
@graphite-app graphite-app bot deleted the 02-20-fix_wasm_transfer_ast_to_js_as_json_string branch February 20, 2025 14:42
Boshen pushed a commit that referenced this pull request Feb 21, 2025
Same as #9259, but for `oxc-wasm` package.

This fixes a couple of bugs - previously `RegExp`s and `BigInt`s were
deserialized as `null`.

Only differences from the implementation in
[@oxc-parser/wasm](https://www.npmjs.com/package/@oxc-parser/wasm) are:

1. Getter for `ast` does not cache the result of `JSON.parse`. I
couldn't quite get my head around Playground code, but I *think* the
`Oxc` class instance is being used as a singleton, and therefore the
value may change as the user updates the source code.

2. JSON is pretty-printed. This is so that when "Raw" is ticked, the
JSON can be displayed exactly as it came out of the parser (rather than
stringifying the AST object again).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant