Skip to content

Commit

Permalink
fix(es): Fix bugs (#2469)
Browse files Browse the repository at this point in the history
swc:
 - Fix handling of `envs`.
 - Check for already fixed issues. (#2319)
  • Loading branch information
kdy1 authored Oct 19, 2021
1 parent 01e171a commit c9437d3
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.73.0"
version = "0.73.1"

[lib]
name = "swc"
Expand Down
18 changes: 18 additions & 0 deletions ecmascript/minifier/tests/compress/fixture/issues/2319/1/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function foo(l, r) {

var lightGreeting

if (l > 0) {
var greeting = "hello";
} else {
var greeting = "howdy";
}

if (r > 0) {
lightGreeting = greeting.substr(0, 2)
}

return lightGreeting
}

module.exports = foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function foo(l, r) {
var lightGreeting;
if (l > 0) var greeting = "hello";
else var greeting = "howdy";
return r > 0 && (lightGreeting = greeting.substr(0, 2)), lightGreeting;
}
module.exports = foo;
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ pub struct GlobalPassOption {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GlobalInliningPassEnvs {
List(AHashSet<String>),
Map(AHashMap<String, String>),
Expand Down
18 changes: 18 additions & 0 deletions tests/fixture/issue-2319/1/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function foo(l, r) {

var lightGreeting

if (l > 0) {
var greeting = "hello";
} else {
var greeting = "howdy";
}

if (r > 0) {
lightGreeting = greeting.substr(0, 2)
}

return lightGreeting
}

module.exports = foo;
13 changes: 13 additions & 0 deletions tests/fixture/issue-2319/1/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function foo(l, r) {
var lightGreeting;
if (l > 0) {
var greeting = "hello";
} else {
var greeting = "howdy";
}
if (r > 0) {
lightGreeting = greeting.substr(0, 2);
}
return lightGreeting;
}
module.exports = foo;
13 changes: 13 additions & 0 deletions tests/fixture/options/globals/1/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"jsc": {
"transform": {
"optimizer": {
"globals": {
"envs": {
"NODE_ENV_ALT": "true"
}
}
}
}
}
}
1 change: 1 addition & 0 deletions tests/fixture/options/globals/1/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(process.env.NODE_ENV_ALT)
1 change: 1 addition & 0 deletions tests/fixture/options/globals/1/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(true);

2 comments on commit c9437d3

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: c9437d3 Previous: 01e171a Ratio
base_tr_fixer 23274 ns/iter (± 265) 34628 ns/iter (± 2667) 0.67
base_tr_resolver_and_hygiene 88777 ns/iter (± 2812) 126071 ns/iter (± 11584) 0.70
codegen_es2015 52626 ns/iter (± 244) 67849 ns/iter (± 4121) 0.78
codegen_es2016 52571 ns/iter (± 272) 68127 ns/iter (± 8550) 0.77
codegen_es2017 52546 ns/iter (± 311) 67247 ns/iter (± 4409) 0.78
codegen_es2018 52637 ns/iter (± 325) 66127 ns/iter (± 4479) 0.80
codegen_es2019 52676 ns/iter (± 263) 68249 ns/iter (± 6398) 0.77
codegen_es2020 52716 ns/iter (± 327) 67494 ns/iter (± 3808) 0.78
codegen_es3 52457 ns/iter (± 279) 67166 ns/iter (± 8001) 0.78
codegen_es5 52867 ns/iter (± 313) 66665 ns/iter (± 4575) 0.79
config_for_file 13002 ns/iter (± 5042) 21089 ns/iter (± 4636) 0.62
full_es2015 170224386 ns/iter (± 3627702) 214164718 ns/iter (± 16409847) 0.79
full_es2016 132985240 ns/iter (± 3493196) 160043002 ns/iter (± 19958717) 0.83
full_es2017 137325861 ns/iter (± 5404282) 171111403 ns/iter (± 14111860) 0.80
full_es2018 137571659 ns/iter (± 8019225) 170101431 ns/iter (± 14496479) 0.81
full_es2019 134509814 ns/iter (± 5770543) 167114579 ns/iter (± 12755164) 0.80
full_es2020 136257227 ns/iter (± 4159508) 170368124 ns/iter (± 15210298) 0.80
full_es3 199995798 ns/iter (± 15813849) 270456708 ns/iter (± 47531837) 0.74
full_es5 190700604 ns/iter (± 9895633) 246122799 ns/iter (± 37065143) 0.77
parser 651395 ns/iter (± 15433) 851283 ns/iter (± 490108) 0.77
transforms_es2015 929001 ns/iter (± 121469) 1444880 ns/iter (± 338822) 0.64
transforms_es2016 499564 ns/iter (± 38355) 773673 ns/iter (± 112615) 0.65
transforms_es2017 481172 ns/iter (± 25965) 779027 ns/iter (± 115156) 0.62
transforms_es2018 480073 ns/iter (± 19990) 765048 ns/iter (± 145706) 0.63
transforms_es2019 492554 ns/iter (± 21805) 750598 ns/iter (± 130252) 0.66
transforms_es2020 468395 ns/iter (± 34250) 748735 ns/iter (± 91540) 0.63
transforms_es3 1109314 ns/iter (± 114393) 1759025 ns/iter (± 363940) 0.63
transforms_es5 960052 ns/iter (± 94341) 1412024 ns/iter (± 262887) 0.68
ser_ast_node 149 ns/iter (± 3) 192 ns/iter (± 13) 0.78
ser_serde 161 ns/iter (± 3) 214 ns/iter (± 15) 0.75
emit_colors 13963975 ns/iter (± 19212647) 16092103 ns/iter (± 22013615) 0.87
emit_large 102721592 ns/iter (± 159441804) 82340006 ns/iter (± 104839816) 1.25
base_clone 2454216 ns/iter (± 179174) 2900046 ns/iter (± 507623) 0.85
fold_span 4023292 ns/iter (± 348934) 4795207 ns/iter (± 905192) 0.84
fold_span_panic 4342496 ns/iter (± 417511) 5229199 ns/iter (± 731882) 0.83
visit_mut_span 2972585 ns/iter (± 200247) 3437775 ns/iter (± 530370) 0.86
visit_mut_span_panic 3103083 ns/iter (± 214471) 3532219 ns/iter (± 432354) 0.88
boxing_boxed 143 ns/iter (± 0) 185 ns/iter (± 39) 0.77
boxing_boxed_clone 68 ns/iter (± 0) 79 ns/iter (± 8) 0.86
boxing_unboxed 131 ns/iter (± 0) 186 ns/iter (± 24) 0.70
boxing_unboxed_clone 64 ns/iter (± 0) 77 ns/iter (± 6) 0.83

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: c9437d3 Previous: 01e171a Ratio
base_tr_fixer 34850 ns/iter (± 7369) 34628 ns/iter (± 2667) 1.01
base_tr_resolver_and_hygiene 125317 ns/iter (± 23688) 126071 ns/iter (± 11584) 0.99
codegen_es2015 66347 ns/iter (± 10024) 67849 ns/iter (± 4121) 0.98
codegen_es2016 67471 ns/iter (± 9866) 68127 ns/iter (± 8550) 0.99
codegen_es2017 68612 ns/iter (± 18122) 67247 ns/iter (± 4409) 1.02
codegen_es2018 69140 ns/iter (± 12564) 66127 ns/iter (± 4479) 1.05
codegen_es2019 66861 ns/iter (± 10044) 68249 ns/iter (± 6398) 0.98
codegen_es2020 68087 ns/iter (± 7071) 67494 ns/iter (± 3808) 1.01
codegen_es3 66318 ns/iter (± 8393) 67166 ns/iter (± 8001) 0.99
codegen_es5 67993 ns/iter (± 9437) 66665 ns/iter (± 4575) 1.02
config_for_file 21726 ns/iter (± 9302) 21089 ns/iter (± 4636) 1.03
full_es2015 219045992 ns/iter (± 14666370) 214164718 ns/iter (± 16409847) 1.02
full_es2016 165757333 ns/iter (± 16798483) 160043002 ns/iter (± 19958717) 1.04
full_es2017 177057496 ns/iter (± 13887823) 171111403 ns/iter (± 14111860) 1.03
full_es2018 173705701 ns/iter (± 12003457) 170101431 ns/iter (± 14496479) 1.02
full_es2019 173848671 ns/iter (± 14387523) 167114579 ns/iter (± 12755164) 1.04
full_es2020 169447861 ns/iter (± 14364205) 170368124 ns/iter (± 15210298) 0.99
full_es3 271566151 ns/iter (± 42368138) 270456708 ns/iter (± 47531837) 1.00
full_es5 251000106 ns/iter (± 26334645) 246122799 ns/iter (± 37065143) 1.02
parser 833160 ns/iter (± 137547) 851283 ns/iter (± 490108) 0.98
transforms_es2015 1389840 ns/iter (± 282031) 1444880 ns/iter (± 338822) 0.96
transforms_es2016 785029 ns/iter (± 158229) 773673 ns/iter (± 112615) 1.01
transforms_es2017 754132 ns/iter (± 201049) 779027 ns/iter (± 115156) 0.97
transforms_es2018 760032 ns/iter (± 149654) 765048 ns/iter (± 145706) 0.99
transforms_es2019 749107 ns/iter (± 225561) 750598 ns/iter (± 130252) 1.00
transforms_es2020 726843 ns/iter (± 233964) 748735 ns/iter (± 91540) 0.97
transforms_es3 1758571 ns/iter (± 391812) 1759025 ns/iter (± 363940) 1.00
transforms_es5 1462388 ns/iter (± 297938) 1412024 ns/iter (± 262887) 1.04
ser_ast_node 179 ns/iter (± 25) 192 ns/iter (± 13) 0.93
ser_serde 198 ns/iter (± 27) 214 ns/iter (± 15) 0.93
emit_colors 18293544 ns/iter (± 24269731) 16092103 ns/iter (± 22013615) 1.14
emit_large 82652908 ns/iter (± 109368481) 82340006 ns/iter (± 104839816) 1.00
base_clone 2928471 ns/iter (± 501991) 2900046 ns/iter (± 507623) 1.01
fold_span 5098709 ns/iter (± 877522) 4795207 ns/iter (± 905192) 1.06
fold_span_panic 5408968 ns/iter (± 1385686) 5229199 ns/iter (± 731882) 1.03
visit_mut_span 3633534 ns/iter (± 1000320) 3437775 ns/iter (± 530370) 1.06
visit_mut_span_panic 3695743 ns/iter (± 963955) 3532219 ns/iter (± 432354) 1.05
boxing_boxed 183 ns/iter (± 135) 185 ns/iter (± 39) 0.99
boxing_boxed_clone 80 ns/iter (± 6) 79 ns/iter (± 8) 1.01
boxing_unboxed 183 ns/iter (± 82) 186 ns/iter (± 24) 0.98
boxing_unboxed_clone 80 ns/iter (± 10) 77 ns/iter (± 6) 1.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.