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

feat: support text loader #1302

Merged
merged 4 commits into from
Jun 1, 2024
Merged

feat: support text loader #1302

merged 4 commits into from
Jun 1, 2024

Conversation

Cecil0o0
Copy link
Contributor

Copy link

netlify bot commented May 31, 2024

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit d866d2f
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/665ac1e0591a12000857fb04

crates/rolldown/src/utils/parse_to_ast.rs Outdated Show resolved Hide resolved
Copy link

codspeed-hq bot commented May 31, 2024

CodSpeed Performance Report

Merging #1302 will not alter performance

Comparing Cecil0o0:feat/text-loader (d866d2f) with main (5be6ffb)

Summary

✅ 6 untouched benchmarks

@Cecil0o0 Cecil0o0 force-pushed the feat/text-loader branch from dc355fc to fc1a202 Compare May 31, 2024 15:22
hyf0
hyf0 previously approved these changes May 31, 2024
Copy link
Member

@hyf0 hyf0 left a comment

Choose a reason for hiding this comment

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

Thanks

@hyf0
Copy link
Member

hyf0 commented May 31, 2024

CI failed.

@hyf0 hyf0 linked an issue May 31, 2024 that may be closed by this pull request
@Cecil0o0
Copy link
Contributor Author

already fixed

@@ -42,6 +42,7 @@ pub fn parse_to_ast(
let (source, parsed_type) = match loader {
Loader::Js => (source, ParseType::Js),
Loader::Json => (json_to_esm(&source)?.into(), ParseType::Js),
Loader::Text => (("export default \"".to_string() + &source + "\";").into(), ParseType::Js),
Copy link
Member

Choose a reason for hiding this comment

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

I believe this will met problems while the content contains ". Could you solve this one and add related tests in fixtures/loaders/txt/escape_quote.

Copy link
Member

@hyf0 hyf0 May 31, 2024

Choose a reason for hiding this comment

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

  1. add a function text_to_esm in rolldown/utils/text_to_esm.rs
  2. Convert the source to Value::String using serde_json
  3. serilized the value use serde_json and you should be able to escape the quote correctly.

Not sure if this is in best performant. @IWANABETHATGUY might have some thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have pushed a new commit for adding a fixture and declaring a text_to_esm function. I looked at esbuild's implementation, esbuild seems to use base64 encoding for text loader to realize escape_quote.

https://github.com/evanw/esbuild/blob/67cbf87a4909d87a902ca8c3b69ab5330defab0a/internal/bundler/bundler.go#L269-L280

Copy link
Member

Choose a reason for hiding this comment

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

It seems that esbuilds uses codegen of itself to escape the quote. Using oxc to do this is a little bit complex. I probably stay with serde_json.

Copy link
Contributor Author

@Cecil0o0 Cecil0o0 Jun 1, 2024

Choose a reason for hiding this comment

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

serde_json is quite useful~learned a new thing.

@hyf0 hyf0 self-assigned this May 31, 2024
@Cecil0o0 Cecil0o0 force-pushed the feat/text-loader branch from d317f01 to 1657407 Compare June 1, 2024 03:22
@Cecil0o0 Cecil0o0 force-pushed the feat/text-loader branch from 1657407 to 56d2060 Compare June 1, 2024 03:42
@Cecil0o0
Copy link
Contributor Author

Cecil0o0 commented Jun 1, 2024

test case passed but not correct, try to fix it.

@Cecil0o0 Cecil0o0 force-pushed the feat/text-loader branch from 56d2060 to 04e18a9 Compare June 1, 2024 04:45
@Cecil0o0 Cecil0o0 force-pushed the feat/text-loader branch from 04e18a9 to 16c0f08 Compare June 1, 2024 04:46
Copy link
Member

@hyf0 hyf0 left a comment

Choose a reason for hiding this comment

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

Thanks

@hyf0 hyf0 added this pull request to the merge queue Jun 1, 2024
Merged via the queue into rolldown:main with commit b0f19c1 Jun 1, 2024
22 checks passed
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.

Support text loader
3 participants