mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(minifier): do not minify Object.defineProperty in sequence expressions (#8416)
This commit is contained in:
parent
5b5b8443f4
commit
357b61d179
4 changed files with 42 additions and 10 deletions
|
|
@ -108,15 +108,20 @@ impl<'a> Traverse<'a> for PeepholeSubstituteAlternateSyntax {
|
||||||
call_expr: &mut CallExpression<'a>,
|
call_expr: &mut CallExpression<'a>,
|
||||||
ctx: &mut TraverseCtx<'a>,
|
ctx: &mut TraverseCtx<'a>,
|
||||||
) {
|
) {
|
||||||
if ctx.parent().is_expression_statement()
|
if !self.in_fixed_loop {
|
||||||
&& Self::is_object_define_property_exports(call_expr)
|
let parent = ctx.parent();
|
||||||
{
|
if (parent.is_expression_statement() || parent.is_sequence_expression())
|
||||||
self.in_define_export = true;
|
&& Self::is_object_define_property_exports(call_expr)
|
||||||
|
{
|
||||||
|
self.in_define_export = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_call_expression(&mut self, expr: &mut CallExpression<'a>, ctx: &mut TraverseCtx<'a>) {
|
fn exit_call_expression(&mut self, expr: &mut CallExpression<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||||
self.in_define_export = false;
|
if !self.in_fixed_loop {
|
||||||
|
self.in_define_export = false;
|
||||||
|
}
|
||||||
self.try_compress_call_expression_arguments(expr, ctx);
|
self.try_compress_call_expression_arguments(expr, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,35 @@ fn cjs() {
|
||||||
}
|
}
|
||||||
});",
|
});",
|
||||||
);
|
);
|
||||||
|
test_same(
|
||||||
|
"Object.defineProperty(exports, 'ConnectableObservable', {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return ConnectableObservable_1.ConnectableObservable;
|
||||||
|
}
|
||||||
|
});",
|
||||||
|
);
|
||||||
// @babel/types/lib/index.js
|
// @babel/types/lib/index.js
|
||||||
|
test(
|
||||||
|
r#"
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(exports, "TargetNames", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () {
|
||||||
|
return _options.TargetNames;
|
||||||
|
}
|
||||||
|
});"#,
|
||||||
|
r#"
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true }), Object.defineProperty(exports, "TargetNames", {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return _options.TargetNames;
|
||||||
|
}
|
||||||
|
});"#,
|
||||||
|
);
|
||||||
|
|
||||||
test(
|
test(
|
||||||
r#"Object.keys(_index6).forEach(function(key) {
|
r#"Object.keys(_index6).forEach(function(key) {
|
||||||
if (key === "default" || key === "__esModule") return;
|
if (key === "default" || key === "__esModule") return;
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,15 @@ Original | minified | minified | gzip | gzip | Fixture
|
||||||
|
|
||||||
544.10 kB | 71.76 kB | 72.48 kB | 26.15 kB | 26.20 kB | lodash.js
|
544.10 kB | 71.76 kB | 72.48 kB | 26.15 kB | 26.20 kB | lodash.js
|
||||||
|
|
||||||
555.77 kB | 273.21 kB | 270.13 kB | 90.92 kB | 90.80 kB | d3.js
|
555.77 kB | 273.21 kB | 270.13 kB | 90.93 kB | 90.80 kB | d3.js
|
||||||
|
|
||||||
1.01 MB | 460.18 kB | 458.89 kB | 126.77 kB | 126.71 kB | bundle.min.js
|
1.01 MB | 460.18 kB | 458.89 kB | 126.77 kB | 126.71 kB | bundle.min.js
|
||||||
|
|
||||||
1.25 MB | 652.85 kB | 646.76 kB | 163.54 kB | 163.73 kB | three.js
|
1.25 MB | 652.86 kB | 646.76 kB | 163.54 kB | 163.73 kB | three.js
|
||||||
|
|
||||||
2.14 MB | 726.27 kB | 724.14 kB | 180.09 kB | 181.07 kB | victory.js
|
2.14 MB | 726.27 kB | 724.14 kB | 180.08 kB | 181.07 kB | victory.js
|
||||||
|
|
||||||
3.20 MB | 1.01 MB | 1.01 MB | 331.78 kB | 331.56 kB | echarts.js
|
3.20 MB | 1.01 MB | 1.01 MB | 331.79 kB | 331.56 kB | echarts.js
|
||||||
|
|
||||||
6.69 MB | 2.32 MB | 2.31 MB | 492.64 kB | 488.28 kB | antd.js
|
6.69 MB | 2.32 MB | 2.31 MB | 492.64 kB | 488.28 kB | antd.js
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,6 @@ pub fn run() -> Result<(), io::Error> {
|
||||||
let save_path = Path::new("./target/minifier").join(marker);
|
let save_path = Path::new("./target/minifier").join(marker);
|
||||||
|
|
||||||
for file in files.files() {
|
for file in files.files() {
|
||||||
println!("{}", &file.file_name);
|
|
||||||
let minified = minify_twice(file);
|
let minified = minify_twice(file);
|
||||||
|
|
||||||
fs::create_dir_all(&save_path).unwrap();
|
fs::create_dir_all(&save_path).unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue