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

fix: accept both keep_fnames and keep_classnames in jsc minify options #7090

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/swc/src/config/issue-6996.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"test": ".jsx?$",
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"react": {
"refresh": true
}
},
"minify": {
"keep_fnames": true
}
}
}
4 changes: 2 additions & 2 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,10 +920,10 @@ pub struct JsMinifyOptions {
#[serde(default)]
pub ecma: TerserEcmaVersion,

#[serde(default)]
#[serde(default, alias = "keep_classnames")]
pub keep_classnames: bool,

#[serde(default)]
#[serde(default, alias = "keep_fnames")]
pub keep_fnames: bool,

#[serde(default)]
Expand Down
6 changes: 6 additions & 0 deletions crates/swc/src/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ fn jsonc() {
let rc = parse_swcrc(include_str!("jsonc.json")).expect("failed to parse");
dbg!(&rc);
}

#[test]
fn issue_6996() {
let rc = parse_swcrc(include_str!("issue-6996.json")).expect("failed to parse");
dbg!(&rc);
}
15 changes: 15 additions & 0 deletions node-swc/__tests__/minify/issue_6996_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import swc from "../../..";

it("should not throw when keep_fnames is on", async () => {
async function minify() {
const { code } = await swc.transform('function Foo() {}', {
jsc: {
minify: {
keep_fnames: true,
},
},
});
return code;
}
await expect(minify()).resolves.toEqual('function Foo() {}\n');
});
Copy link
Contributor Author

@cyjake cyjake Mar 16, 2023

Choose a reason for hiding this comment

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

it seems binding tests is done with published swc_core. I've changed local bindings/binding_core_node/Cargo.toml to point to crates/swc_core to have this test case covered, but the CI might fail because of said reason. Should the Cargo.toml be updated as well?

Copy link
Member

Choose a reason for hiding this comment

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

No, it's patched from CI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great, guess this pr is ready for review now