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

refactor(ast)!: change 'raw' from &str to Option<Atom> #7547

Merged

Conversation

ShuiRuTian
Copy link
Contributor

Fix #7254

Changed all "raw" propperty of literal types(if it has this property) to Option

Copy link

graphite-app bot commented Nov 29, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

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

@github-actions github-actions bot added A-linter Area - Linter A-parser Area - Parser A-semantic Area - Semantic A-minifier Area - Minifier A-ast Area - AST A-transformer Area - Transformer / Transpiler A-codegen Area - Code Generation A-prettier Area - Prettier A-isolated-declarations Isolated Declarations labels Nov 29, 2024
@overlookmotel overlookmotel changed the title refactor: change 'raw' from &str to Option<Atom> refactor(ast)!: change 'raw' from &str to Option<Atom> Nov 30, 2024
@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Nov 30, 2024
@overlookmotel overlookmotel removed the request for review from leaysgur November 30, 2024 12:04
Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Thanks loads for tackling this.

Turns out this is more complicated than I thought! Sorry for the litany of comments below.

First off, could you please rebase on main and fix the merge conflicts so CI can run?

Most of my comments are the same - they relate to not unwrapping when can't be sure that raw is Some.

In lots of places we need a fallback for converting NumericLiteral's value to a string if raw is None. Probably it'd be good to add a method NumericLiteral::raw_str which can be used in all those places (which I guess will need to return a Cow<str>).

crates/oxc_ast/src/ast_builder_impl.rs Outdated Show resolved Hide resolved
crates/oxc_ast/src/ast_impl/js.rs Outdated Show resolved Hide resolved
crates/oxc_ast/src/ast_impl/literal.rs Outdated Show resolved Hide resolved
crates/oxc_ast/src/ast/literal.rs Outdated Show resolved Hide resolved
crates/oxc_codegen/src/gen.rs Outdated Show resolved Hide resolved
crates/oxc_minifier/src/node_util/mod.rs Outdated Show resolved Hide resolved
crates/oxc_prettier/src/format/mod.rs Outdated Show resolved Hide resolved
crates/oxc_semantic/src/checker/javascript.rs Outdated Show resolved Hide resolved
@ShuiRuTian ShuiRuTian force-pushed the update-raw-for-literal-types branch 2 times, most recently from cc5c3a2 to 6604759 Compare November 30, 2024 17:45
@ShuiRuTian
Copy link
Contributor Author

Thanks a lot for the detailed comments!

Sorry, I was indeed abusing unwrap...

Add a new method called raw_str as suggested.

Most problems should already be fixed.

Copy link

codspeed-hq bot commented Nov 30, 2024

CodSpeed Performance Report

Merging #7547 will improve performances by 4.67%

Comparing ShuiRuTian:update-raw-for-literal-types (7eb3802) with main (e5145b0)

Summary

⚡ 2 improvements
✅ 27 untouched benchmarks

Benchmarks breakdown

Benchmark main ShuiRuTian:update-raw-for-literal-types Change
semantic[cal.com.tsx] 29 ms 28.1 ms +3.1%
transformer[RadixUIAdoptionSection.jsx] 154.6 µs 147.7 µs +4.67%

@overlookmotel
Copy link
Contributor

overlookmotel commented Dec 2, 2024

Thanks a lot for the detailed comments!

Glad you found them useful and not annoying!

Nice speed bump on transformer benchmarks.

Could you please try and fix the failing test, and fix clippy, and then I'll review again?

A couple of quick things in meantime:

  1. When formatting NumericLiteral's value, I don't think there's any need to look at what base is. Just Cow::Owned(self.value.to_string()) should do it.
  2. Please make sure all changes related to BigIntLiteral are removed. I can see a few remaining in the diff.

Side note: I think we can also remove NumericLiteral::base field later on, or make it an Option. Like raw, it only has meaning where the NumericLiteral came from source code. A NumericLiteral which is generated is just a value. It has no "base". But please don't do that now! We should look at doing that in a separate PR, if we want to do it at all.

@ShuiRuTian ShuiRuTian force-pushed the update-raw-for-literal-types branch 2 times, most recently from 8c93101 to 9b6952f Compare December 3, 2024 17:17
@overlookmotel
Copy link
Contributor

overlookmotel commented Dec 4, 2024

I believe the CI failure on "Test NAPI" CI job is unrelated to content of this PR. I've also seen it on one of my recent PRs #7618.

Please let me know when ready for me to review again.

@ShuiRuTian
Copy link
Contributor Author

I believe the CI failure on "Test NAPI" CI job is unrelated to content of this PR. I've also seen it on one of my recent PRs #7618.

Cool, if so, the PR should be ready to be reviewed now.

There might also be some comment issues, like whether I should add "Safety: xxx" above unwrap or some comments is not clearly enough. but the logic part should be done.

@overlookmotel overlookmotel force-pushed the update-raw-for-literal-types branch from 9b6952f to 7eb3802 Compare December 5, 2024 00:26
Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

Branch got out of date with main. I've rebased on main and fixed conflicts. I've also taken the liberty of pushing a few small commits to fix a few things, rather than going through another round of review - I hope you don't mind.

Am going to merge now. @ShuiRuTian please take a look at the extra commits I pushed if you're interested.

Thanks loads for your work on this!

@overlookmotel overlookmotel merged commit ebc80f6 into oxc-project:main Dec 5, 2024
26 checks passed
@ShuiRuTian
Copy link
Contributor Author

Thanks much for the detailed guide! It really helps a lot

@overlookmotel
Copy link
Contributor

To be honest, I don't think this one is correct: 4874660

If raw is None then it returns None, which it shouldn't. But how RegExpLiteral stores raw needs changes anyway. At present it stores it in 2 places.

This was referenced Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area - AST A-codegen Area - Code Generation A-isolated-declarations Isolated Declarations A-linter Area - Linter A-minifier Area - Minifier A-parser Area - Parser A-prettier Area - Prettier A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make raw field on literal AST types optional, or remove them
2 participants