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: add comments in module code generation #2893

Merged

Conversation

faga295
Copy link
Contributor

@faga295 faga295 commented Apr 24, 2023

Related issue (if exists)

#2868

Summary

🤖 Generated by Copilot at 15c7690

Add support for comments in the JavaScript plugin. Modify the stringify function in stringify.rs to pass the comments from the AST to the print function.

Walkthrough

🤖 Generated by Copilot at 15c7690

  • Preserve comments in AST when stringifying JavaScript code (link)

@changeset-bot
Copy link

changeset-bot bot commented Apr 24, 2023

🦋 Changeset detected

Latest commit: 0587b99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@rspack/binding Patch
@rspack/postcss-loader Patch
@rspack/core Patch
webpack-test Patch
@rspack/cli Patch
@rspack/dev-middleware Patch
@rspack/dev-server Patch
@rspack/plugin-html Patch
benchmarkcase-rspack-react-refresh Patch
@rspack/dev-client Patch
@rspack/plugin-minify Patch
@rspack/plugin-node-polyfill Patch
@rspack/binding-darwin-arm64 Patch
@rspack/binding-darwin-x64 Patch
@rspack/binding-linux-x64-gnu Patch
@rspack/binding-win32-x64-msvc Patch
@rspack/fs Patch

Not sure what this means? Click here to learn what changesets are.

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

@faga295 faga295 marked this pull request as ready for review April 24, 2023 06:26
@faga295
Copy link
Contributor Author

faga295 commented Apr 24, 2023

this pr also includes some expected file change, and the tree-shaking/ts-target-es5's test seems has some diff problem, it's failed even though the expected file is same as actual file, and I'm very confused about this.

@IWANABETHATGUY
Copy link
Contributor

IWANABETHATGUY commented Apr 24, 2023

Would you mind adding an option to control this behavior? Not everyone wants comments in their outputs, also this would slow the codegen phase. You could add some tests in another dir, comments are kinds of noise in tree shaking test.

@faga295
Copy link
Contributor Author

faga295 commented Apr 24, 2023

Ok, I will add comments option in minifyOption, and the default value is false.

@IWANABETHATGUY
Copy link
Contributor

I don't think it is a good option to mix this behavior with minifyOption, because according to your implementation, this option should control development mode code generation behavior as well. Would you mind waiting about one day or so? Maybe we could discuss where should we put the option, or we don't need a option just codegenerate the comments anyway.

@IWANABETHATGUY IWANABETHATGUY added the to be discussed Rspack team would discuss these issues per week label Apr 24, 2023
@underfin underfin removed the to be discussed Rspack team would discuss these issues per week label Apr 25, 2023
@faga295
Copy link
Contributor Author

faga295 commented Apr 25, 2023

Hey @IWANABETHATGUY , after discussing how this option should be designed🤔️

@IWANABETHATGUY
Copy link
Contributor

We don't want this feature to introduce too much overhead, so let's bench it first.
!bench

@github-actions
Copy link
Contributor

Benchmark Results

group                                                 baseline                                 pr
-----                                                 --------                                 --
criterion_benchmark/ten_copy_of_threejs               444.86      2.5±0.08s        ? ?/sec     1.00      5.5±0.97ms        ? ?/sec
high_cost_benchmark/ten_copy_of_threejs_production    1178.94      8.8±0.13s        ? ?/sec    1.00      7.4±0.66ms        ? ?/sec

@IWANABETHATGUY
Copy link
Contributor

!bench

@IWANABETHATGUY
Copy link
Contributor

please make sure to pass the CI, you could run UPDATE=1 cargo test -p rspack

@github-actions
Copy link
Contributor

Benchmark Results

group                                                 baseline                               pr
-----                                                 --------                               --
criterion_benchmark/ten_copy_of_threejs               1.00       3.1±0.14s        ? ?/sec    1.07       3.3±0.30s        ? ?/sec
high_cost_benchmark/ten_copy_of_threejs_production    1.00      11.0±0.23s        ? ?/sec    1.01      11.1±0.38s        ? ?/sec

@IWANABETHATGUY
Copy link
Contributor

!bench

@github-actions
Copy link
Contributor

Benchmark Results

group                                                 baseline                               pr
-----                                                 --------                               --
criterion_benchmark/ten_copy_of_threejs               1.00       2.3±0.08s        ? ?/sec    1.03       2.4±0.10s        ? ?/sec
high_cost_benchmark/ten_copy_of_threejs_production    1.00       8.1±0.10s        ? ?/sec    1.01       8.2±0.25s        ? ?/sec

@faga295 faga295 force-pushed the feat/add_comments_when_no_minimize branch from 32b144c to 2e73575 Compare April 26, 2023 04:44
@faga295
Copy link
Contributor Author

faga295 commented Apr 26, 2023

this pr also includes some expected file change, and the tree-shaking/ts-target-es5's test seems has some diff problem, it's failed even though the expected file is same as actual file, and I'm very confused about this.

the tree-shaking/ts-target-es5 is strange, after run UPDATE=1 cargo test -p rspack, test can pass locally, but no files changed

@IWANABETHATGUY
Copy link
Contributor

Do you use Windows?

@faga295
Copy link
Contributor Author

faga295 commented Apr 26, 2023

Do you use Windows

OS: macOS 13.0
CPU: (8) arm64 Apple M1 Pro

image
There is really no difference between the expected file and the actual file

if is_expect_file && is_actual_file {
let expected_buf = fs::read(expected_dir.as_path()).expect("TODO:");
let expected_str = String::from_utf8_lossy(&expected_buf);
let actual_buf = fs::read(actual_dir.as_path()).expect("TODO:");
let actual_str = String::from_utf8_lossy(&actual_buf);
if expected_str != actual_str {
let diff = FileDiff {
expected_path: expected_dir.clone(),
actual_path: actual_dir.clone(),
expected_content: expected_str.to_string(),
actual_content: actual_str.to_string(),
};
err.push(TestErrorKind::Difference(diff))
}

Is this problem due to diff?

@IWANABETHATGUY
Copy link
Contributor

I don't think so,
image
image
It has some diff but will be replaced by git when you commit to GitHub.

@IWANABETHATGUY
Copy link
Contributor

I think you could add an option to control this behavior, like builtins.codeGeneration.keepComments

@IWANABETHATGUY
Copy link
Contributor

By default this option should be disabled, you could add extra test case to test this behavior, this will not conflict with current test case.

Copy link
Contributor

@IWANABETHATGUY IWANABETHATGUY left a comment

Choose a reason for hiding this comment

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

Thanks!

@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Apr 26, 2023
Merged via the queue into web-infra-dev:main with commit e764de6 Apr 26, 2023
10 checks passed
@github-actions github-actions bot mentioned this pull request May 9, 2023
siyou pushed a commit to siyou/rspack that referenced this pull request May 14, 2023
* feat: add comments in module code generation

* feat: add builtins.codeGeneration.keepComments

* chore: update
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.

None yet

4 participants