Skip to content

feat!: support jsx, ts and tsx via oxc transform by default - #1364

Merged
hyfdev merged 8 commits into
mainfrom
06-07-feat_support_jsx_ts_and_tsx_loader
Jun 16, 2024
Merged

hyfdev merged 8 commits into
mainfrom
06-07-feat_support_jsx_ts_and_tsx_loader

Conversation

@Dunqing

@Dunqing Dunqing commented Jun 7, 2024 •

Copy link
Copy Markdown
Contributor

Description

I'm not familiar with rolldown, where should I place the transform?

@Dunqing
Dunqing marked this pull request as draft June 7, 2024 05:24
@netlify

netlify Bot commented Jun 7, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 8be3fe9
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/666ebc6fb9aa9d0008cb0a44

@codecov

codecov Bot commented Jun 7, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 94.73684% with 4 lines in your changes missing coverage. Please review.

Project coverage is 85.74%. Comparing base (440e68e) to head (772ad55).
Report is 1 commits behind head on main.

❗ Current head 772ad55 differs from pull request most recent head 8be3fe9

Please upload reports for the commit 8be3fe9 to get more accurate results.

Files Patch % Lines
crates/rolldown_oxc_utils/src/oxc_ast/mod.rs 25.00% 3 Missing ⚠️
crates/rolldown/src/utils/pre_process_ast.rs 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1364      +/-   ##
==========================================
+ Coverage   85.64%   85.74%   +0.09%     
==========================================
  Files         144      145       +1     
  Lines        7239     7295      +56     
==========================================
+ Hits         6200     6255      +55     
- Misses       1039     1040       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Jun 7, 2024 •

Copy link
Copy Markdown
Contributor

Benchmarks Rust

  • target: main(b059278)
  • pr: 06-07-feat_support_jsx_ts_and_tsx_loader(8be3fe9)
group                                      pr                                     target
-----                                      --                                     ------
rolldown benchmark/threejs-bundle          1.00     29.8±0.50ms        ? ?/sec    1.00     29.8±0.46ms        ? ?/sec
rolldown benchmark/threejs-scan            1.00     21.5±0.51ms        ? ?/sec    1.01     21.7±0.57ms        ? ?/sec
rolldown benchmark/threejs-sourcemap       1.02     40.5±3.02ms        ? ?/sec    1.00     39.7±0.43ms        ? ?/sec
rolldown benchmark/threejs10x-bundle       1.00    320.9±5.91ms        ? ?/sec    1.01    323.9±3.81ms        ? ?/sec
rolldown benchmark/threejs10x-scan         1.01    211.2±6.56ms        ? ?/sec    1.00    208.5±1.91ms        ? ?/sec
rolldown benchmark/threejs10x-sourcemap    1.00   442.6±11.69ms        ? ?/sec    1.02   453.1±34.31ms        ? ?/sec

@codspeed

codspeed Bot commented Jun 7, 2024 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #1364 will not alter performance

Comparing 06-07-feat_support_jsx_ts_and_tsx_loader (8be3fe9) with main (440e68e)

Summary

✅ 6 untouched benchmarks

@Boshen

Boshen commented Jun 7, 2024

Copy link
Copy Markdown
Member

We need a feature toggle using an environment variable, turned off by default.

@Dunqing

Dunqing commented Jun 7, 2024

Copy link
Copy Markdown
Contributor Author

We need a feature toggle using an environment variable, turned off by default.

Let's discuss this topic next monday, and we also need to discuss how to configure TransformerOptions in Rolldown.

@Dunqing
Dunqing force-pushed the 06-07-feat_support_jsx_ts_and_tsx_loader branch from b90d148 to 277c317 Compare June 11, 2024 05:45
@Boshen Boshen changed the title feat: support jsx, ts and tsx loader feat: support jsx, ts and tsx via oxc transform Jun 11, 2024
@Dunqing

Dunqing commented Jun 11, 2024 •

Copy link
Copy Markdown
Contributor Author

Ready for review, But still wait oxc for release oxc-project/oxc#3580

@Dunqing
Dunqing marked this pull request as ready for review June 11, 2024 07:11
@hyfdev

hyfdev commented Jun 11, 2024

Copy link
Copy Markdown
Member

Ready for review, But still wait oxc for release oxc-project/oxc#3580

It's ok for OxcAst to change trivias: Trivias to trivias: Rc<Trivias>, but this would cause OxcAst not send and sync anymore.

Arc<Trivias> is suitable for rolldown but introduce extra overhead on cases don't require parallelism. Would it be better to introduce a feature gate parallel and use Lrc<T> around the oxc codebase? rustc use Lrc instead of using Arc and Rc directly. https://github.com/rust-lang/rust/blob/20ba13c38e5b8451b7b09e4009efc9010bfa3f2c/compiler/rustc_data_structures/src/sync.rs#L21 @Boshen cc

@Boshen
Boshen force-pushed the 06-07-feat_support_jsx_ts_and_tsx_loader branch from a2aeb63 to 27cb0cd Compare June 12, 2024 09:25
@Boshen
Boshen marked this pull request as draft June 12, 2024 09:31
@Boshen
Boshen force-pushed the 06-07-feat_support_jsx_ts_and_tsx_loader branch from 27cb0cd to 6e33184 Compare June 12, 2024 09:34
Comment thread Cargo.toml
rayon = "1.10.0"
regex = "1.10.5"
rustc-hash = "1.1.0"
rustc-hash = { git = "https://github.com/rust-lang/rustc-hash" } # v1.2.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1.2.0 was yanked.

@Boshen
Boshen force-pushed the 06-07-feat_support_jsx_ts_and_tsx_loader branch from 6e33184 to c3165ba Compare June 12, 2024 10:03
("jsx".to_string(), ModuleType::Jsx),
("ts".to_string(), ModuleType::Ts),
("tsx".to_string(), ModuleType::Tsx),
("txt".to_string(), ModuleType::Text),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"mts" and "cts" are missing 🤔

@Boshen
Boshen force-pushed the 06-07-feat_support_jsx_ts_and_tsx_loader branch from c3165ba to af19848 Compare June 12, 2024 10:07
@Boshen

Boshen commented Jun 12, 2024

Copy link
Copy Markdown
Member
error[E0308]: mismatched types
  --> crates/rolldown_plugin/src/transform_plugin_context.rs:39:5
   |
37 |     fn create_sourcemap(&self) -> SourceMap {
   |                                   --------- expected `SourceMap` because of return type
38 |       let magic_string = MagicString::new(self.original_code);
39 | /     magic_string.source_map(SourceMapOptions {
40 | |       hires: true,
41 | |       include_content: true,
42 | |       source: self.id.into(),
43 | |     })
   | |______^ expected `SourceMap`, found `oxc_sourcemap::sourcemap::SourceMap`
   |
   = note: `oxc_sourcemap::sourcemap::SourceMap` and `SourceMap` have similar names, but are actually distinct types
note: `oxc_sourcemap::sourcemap::SourceMap` is defined in crate `oxc_sourcemap`
  --> /Users/boshen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/oxc_sourcemap-0.13.5/src/sourcemap.rs:11:1

I think we should move that crate into rolldown ...

@hyfdev

hyfdev commented Jun 13, 2024

Copy link
Copy Markdown
Member
error[E0308]: mismatched types
  --> crates/rolldown_plugin/src/transform_plugin_context.rs:39:5
   |
37 |     fn create_sourcemap(&self) -> SourceMap {
   |                                   --------- expected `SourceMap` because of return type
38 |       let magic_string = MagicString::new(self.original_code);
39 | /     magic_string.source_map(SourceMapOptions {
40 | |       hires: true,
41 | |       include_content: true,
42 | |       source: self.id.into(),
43 | |     })
   | |______^ expected `SourceMap`, found `oxc_sourcemap::sourcemap::SourceMap`
   |
   = note: `oxc_sourcemap::sourcemap::SourceMap` and `SourceMap` have similar names, but are actually distinct types
note: `oxc_sourcemap::sourcemap::SourceMap` is defined in crate `oxc_sourcemap`
  --> /Users/boshen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/oxc_sourcemap-0.13.5/src/sourcemap.rs:11:1

I think we should move that crate into rolldown ...

I'm not sure the if best way to solve this is moving crate. We sooner or later will met the similar case with not having the auth to move crates around.

We need figure out how we met this gotcha and how to prevent it. What's the best practice to solve this kind of problem? I have seen putting efforts on wrong direction without reviewing just cause more problems in the future.

@underfin wants to avoid converting cost between rolldown_sourcemap and string_wizard, so these two crates both use oxcSourceMap directly.

The error is caused by treating oxc's SourceMap as the same struct between two different versions.

  • rolldown_sourcemap uses version A oxcSourceMap
  • string_wizard uses version B oxcSourceMap

The solution I propose:

If we consider string_wizard as a standalone crate

  • string_wizard should expose a own version of SourceMap. It should not expose any data structures related oxc.
  • string_wizard's SourceMap could expose it's fields with owned values. So we could use owned values to construct oxc's sourcemap without many overhead.
  • The logic that convert string_wizard's SourceMap to oxc's SourceMap should be place into rolldown's codebase.

string_wizard's features are very scoped and stable, moving it to rolldown's repo is not reasonable just because the above reason.

@Boshen

Boshen commented Jun 13, 2024

Copy link
Copy Markdown
Member

Yeah either decouple string_wizard, expose things via traits.

Or, relax the version constraint to 0.*.

@hyfdev
hyfdev marked this pull request as ready for review June 16, 2024 10:00

@hyfdev hyfdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it first. I think it's ok we don't have a feature gate for this. Let's start to accept feedback of bugs.

@hyfdev

hyfdev commented Jun 16, 2024

Copy link
Copy Markdown
Member

@IWANABETHATGUY you may start enable related ts tests of esbuild.

I will soon make the rolldown's self-compiling using oxc ts transfomer and drop the esbuild plugin.

@hyfdev
hyfdev enabled auto-merge June 16, 2024 10:25
@hyfdev
hyfdev disabled auto-merge June 16, 2024 10:25
@hyfdev hyfdev changed the title feat: support jsx, ts and tsx via oxc transform feat!: support jsx, ts and tsx via oxc transform by default Jun 16, 2024
@hyfdev
hyfdev enabled auto-merge June 16, 2024 10:27
@hyfdev
hyfdev added this pull request to the merge queue Jun 16, 2024
Merged via the queue into main with commit 26ca3da Jun 16, 2024
@hyfdev
hyfdev deleted the 06-07-feat_support_jsx_ts_and_tsx_loader branch June 16, 2024 10:52
kristofer-baxter added a commit to kristofer-baxter/rolldown that referenced this pull request Nov 13, 2026
Carry reshaped export HMR patches (`reshaped?.(all, unheld)`) with moved-binding, native-cell, TLA, and link-failure reload guards (rolldown#1352), and port production temporal read proofs, native unwrapped engine TDZ enforcement, and nameless minified `__checkTDZ` checks gated on compatibility temporal mode so upstream ordinary builds stay unchanged (rolldown#1364).

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants