swc icon indicating copy to clipboard operation
swc copied to clipboard

perf(es/parser): Rewrite parser

Open kdy1 opened this issue 1 year ago • 8 comments

Description:

I'm going to rewrite the ES parser of SWC because

  • I didn't know anything about compiler or parser theories at the time of writing the parser (#1).
  • @Boshen and oxc team investigated a lot and proved that the parser can be much faster than now. (Wonderful job, it's really nice)

Related issue (if exists):

kdy1 avatar Jul 22 '24 04:07 kdy1

⚠️ No Changeset found

Latest commit: 576d6cb51044fce1d06142fe9d4a67d565f4ad1a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jul 22 '24 04:07 changeset-bot[bot]

Please be aware in oxc, there is a second ast pass for ast path, symbols and scopes to complete all syntax errors.

We also use the latest conformance suite from https://github.com/tc39/test262, you may need to consider replacing the outdated one you are using.

Boshen avatar Jul 22 '24 05:07 Boshen

CodSpeed Performance Report

Merging #9313 will not alter performance

Comparing kdy1:new-parser (0fda55e) with main (a6d1db8)

Summary

✅ 178 untouched benchmarks

codspeed-hq[bot] avatar Jul 22 '24 06:07 codspeed-hq[bot]

Would be cool if there was a way for it to also produce a red green syntax tree to allow modifications to the code that preserves formatting.

@Boshen Any thoughts on this?

I personally have a lot of use cases where I need to parse some module and then transform the code. The problem is that with an AST, since it's lossy in terms of formatting, any transformations to the tree means that if you re-print it in the end you'd loose the formatting of the module.

It'd be cool if it used a lossless syntax tree instead of an AST.

d3lm avatar Jul 22 '24 09:07 d3lm

Would be cool if there was a way for it to also produce a red green syntax tree to allow modifications to the code that preserves formatting.

@Boshen Any thoughts on this?

I personally have a lot of use cases where I need to parse some module and then transform the code. The problem is that with an AST, since it's lossy in terms of formatting, any transformations to the tree means that if you re-print it in the end you'd loose the formatting of the module.

It'd be cool if it used a lossless syntax tree instead of an AST.

CST is out of scope for swc / oxc. Take a look at https://crates.io/crates/biome_parser for CST.

Boshen avatar Jul 22 '24 11:07 Boshen

Yea I was aware of Biome's parser that's inspired by the Rust Analyzer's parser I guess. Thanks!

d3lm avatar Jul 22 '24 13:07 d3lm

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

socket-security[bot] avatar Aug 16 '24 06:08 socket-security[bot]