-
Notifications
You must be signed in to change notification settings - Fork 531
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
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
CodSpeed Performance ReportMerging #1302 will not alter performanceComparing Summary
|
dc355fc
to
fc1a202
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
CI failed. |
fc1a202
to
d62c7e1
Compare
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), |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- add a function
text_to_esm
inrolldown/utils/text_to_esm.rs
- Convert the source to Value::String using
serde_json
- 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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d317f01
to
1657407
Compare
1657407
to
56d2060
Compare
test case passed but not correct, try to fix it. |
56d2060
to
04e18a9
Compare
04e18a9
to
16c0f08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Description
relative issue #1300
esbuild's snapshot:
https://github.com/evanw/esbuild/blob/67cbf87a4909d87a902ca8c3b69ab5330defab0a/internal/bundler_tests/snapshots/snapshots_loader.txt#L942-L957