Skip to content

Commit

Permalink
fix(es/codegen): Use emitAssertForImportAttributes (#7936)
Browse files Browse the repository at this point in the history
**Description:**

 - Add `format.emitAssertForImportAttributes` to `minify()`
 - Use `jsc.experimental. emitAssertForImportAttributes`.

**Related issue (if exists):**

 - Closes #7926
 - Closes #7928
  • Loading branch information
kdy1 authored Sep 11, 2023
1 parent 5431010 commit dac8888
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,9 @@ pub struct JsMinifyFormatOptions {
/// Not implemented yet.
#[serde(default, alias = "wrap_func_args")]
pub wrap_func_args: bool,

#[serde(default)]
pub emit_assert_for_import_attributes: bool,
}

fn default_comments() -> BoolOrDataConfig<JsMinifyCommentOption> {
Expand Down
8 changes: 7 additions & 1 deletion crates/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,10 @@ impl Compiler {
swc_ecma_codegen::Config::default()
.with_target(target)
.with_minify(true)
.with_ascii_only(opts.format.ascii_only),
.with_ascii_only(opts.format.ascii_only)
.with_emit_assert_for_import_attributes(
opts.format.emit_assert_for_import_attributes,
),
)
})
}
Expand Down Expand Up @@ -1237,6 +1240,9 @@ impl Compiler {
.charset
.map(|v| matches!(v, OutputCharset::Ascii))
.unwrap_or(false),
)
.with_emit_assert_for_import_attributes(
config.emit_assert_for_import_attributes,
),
)
})
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7908/output/1/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import packageJSON from "./package.json" with {
import packageJSON from "./package.json" assert {
type: "json"
};
console.log(packageJSON);
6 changes: 3 additions & 3 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ where
if let Some(with) = &n.with {
formatting_space!();
if self.cfg.emit_assert_for_import_attributes {
keyword!("asserts");
keyword!("assert");
} else {
keyword!("with")
};
Expand Down Expand Up @@ -458,7 +458,7 @@ where
if let Some(with) = &node.with {
formatting_space!();
if self.cfg.emit_assert_for_import_attributes {
keyword!("asserts");
keyword!("assert");
} else {
keyword!("with")
};
Expand Down Expand Up @@ -488,7 +488,7 @@ where
if let Some(with) = &node.with {
formatting_space!();
if self.cfg.emit_assert_for_import_attributes {
keyword!("asserts");
keyword!("assert");
} else {
keyword!("with")
};
Expand Down

1 comment on commit dac8888

@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: dac8888 Previous: 2da5895 Ratio
es/full/bugs-1 284563 ns/iter (± 6196) 289779 ns/iter (± 11558) 0.98
es/full/minify/libraries/antd 1321433453 ns/iter (± 16038374) 1313107827 ns/iter (± 9704007) 1.01
es/full/minify/libraries/d3 275433814 ns/iter (± 1571355) 274542639 ns/iter (± 3603876) 1.00
es/full/minify/libraries/echarts 1090302749 ns/iter (± 28888648) 1074444775 ns/iter (± 10541381) 1.01
es/full/minify/libraries/jquery 83971135 ns/iter (± 355752) 83565230 ns/iter (± 356159) 1.00
es/full/minify/libraries/lodash 97073701 ns/iter (± 365208) 96443383 ns/iter (± 307018) 1.01
es/full/minify/libraries/moment 49675669 ns/iter (± 108243) 49585171 ns/iter (± 352579) 1.00
es/full/minify/libraries/react 17949922 ns/iter (± 48406) 17836455 ns/iter (± 141309) 1.01
es/full/minify/libraries/terser 216833107 ns/iter (± 628205) 221489095 ns/iter (± 1878049) 0.98
es/full/minify/libraries/three 391691049 ns/iter (± 4649111) 405249100 ns/iter (± 4843695) 0.97
es/full/minify/libraries/typescript 2619933916 ns/iter (± 13596617) 2656317362 ns/iter (± 19187954) 0.99
es/full/minify/libraries/victory 568641217 ns/iter (± 6600986) 614757312 ns/iter (± 13202103) 0.92
es/full/minify/libraries/vue 119762119 ns/iter (± 238145) 119395257 ns/iter (± 555424) 1.00
es/full/codegen/es3 34926 ns/iter (± 63) 34178 ns/iter (± 207) 1.02
es/full/codegen/es5 34951 ns/iter (± 75) 34099 ns/iter (± 148) 1.02
es/full/codegen/es2015 34920 ns/iter (± 70) 34075 ns/iter (± 127) 1.02
es/full/codegen/es2016 35027 ns/iter (± 54) 34031 ns/iter (± 187) 1.03
es/full/codegen/es2017 35092 ns/iter (± 86) 34037 ns/iter (± 215) 1.03
es/full/codegen/es2018 34896 ns/iter (± 54) 34107 ns/iter (± 177) 1.02
es/full/codegen/es2019 34871 ns/iter (± 48) 34042 ns/iter (± 121) 1.02
es/full/codegen/es2020 34952 ns/iter (± 100) 33963 ns/iter (± 201) 1.03
es/full/all/es3 168832910 ns/iter (± 1028229) 169793034 ns/iter (± 1237967) 0.99
es/full/all/es5 160473267 ns/iter (± 960197) 162327010 ns/iter (± 1024317) 0.99
es/full/all/es2015 119338123 ns/iter (± 691420) 121460025 ns/iter (± 702792) 0.98
es/full/all/es2016 118504908 ns/iter (± 621556) 120568911 ns/iter (± 645716) 0.98
es/full/all/es2017 118704960 ns/iter (± 571699) 119968145 ns/iter (± 536006) 0.99
es/full/all/es2018 115616968 ns/iter (± 476944) 117981353 ns/iter (± 715177) 0.98
es/full/all/es2019 115433152 ns/iter (± 564978) 117903291 ns/iter (± 824520) 0.98
es/full/all/es2020 110262119 ns/iter (± 819539) 112645356 ns/iter (± 492260) 0.98
es/full/parser 487067 ns/iter (± 4907) 489277 ns/iter (± 5963) 1.00
es/full/base/fixer 18496 ns/iter (± 306) 18366 ns/iter (± 524) 1.01
es/full/base/resolver_and_hygiene 79844 ns/iter (± 131) 81057 ns/iter (± 170) 0.99
serialization of serde 309 ns/iter (± 2) 304 ns/iter (± 0) 1.02
css/minify/libraries/bootstrap 29422831 ns/iter (± 205774) 28796306 ns/iter (± 66100) 1.02
css/visitor/compare/clone 1677547 ns/iter (± 5073) 1688595 ns/iter (± 9332) 0.99
css/visitor/compare/visit_mut_span 1794128 ns/iter (± 4906) 1797549 ns/iter (± 7049) 1.00
css/visitor/compare/visit_mut_span_panic 1872905 ns/iter (± 5279) 1866046 ns/iter (± 4885) 1.00
css/visitor/compare/fold_span 2582273 ns/iter (± 10678) 2607260 ns/iter (± 29289) 0.99
css/visitor/compare/fold_span_panic 2785806 ns/iter (± 6114) 2795141 ns/iter (± 9230) 1.00
css/lexer/bootstrap_5_1_3 4574244 ns/iter (± 2509) 4490938 ns/iter (± 11096) 1.02
css/lexer/foundation_6_7_4 3819100 ns/iter (± 1883) 3756837 ns/iter (± 3635) 1.02
css/lexer/tailwind_3_1_1 733384 ns/iter (± 393) 716059 ns/iter (± 1371) 1.02
css/parser/bootstrap_5_1_3 19546368 ns/iter (± 23278) 19214648 ns/iter (± 32212) 1.02
css/parser/foundation_6_7_4 15687091 ns/iter (± 33623) 15240702 ns/iter (± 96167) 1.03
css/parser/tailwind_3_1_1 3037635 ns/iter (± 3280) 2927927 ns/iter (± 5766) 1.04
es/codegen/colors 727734 ns/iter (± 396495) 736629 ns/iter (± 406004) 0.99
es/codegen/large 3148661 ns/iter (± 1666137) 2884724 ns/iter (± 1535627) 1.09
es/codegen/with-parser/colors 45153 ns/iter (± 562) 45487 ns/iter (± 471) 0.99
es/codegen/with-parser/large 490346 ns/iter (± 1055) 491120 ns/iter (± 966) 1.00
es/minify/libraries/antd 1146212548 ns/iter (± 21637876) 1172543111 ns/iter (± 13796156) 0.98
es/minify/libraries/d3 240130106 ns/iter (± 2758734) 240416537 ns/iter (± 3640884) 1.00
es/minify/libraries/echarts 904201103 ns/iter (± 5995332) 901530260 ns/iter (± 6919292) 1.00
es/minify/libraries/jquery 72839403 ns/iter (± 165564) 72782849 ns/iter (± 107685) 1.00
es/minify/libraries/lodash 86889616 ns/iter (± 235742) 86810795 ns/iter (± 396319) 1.00
es/minify/libraries/moment 43256812 ns/iter (± 89475) 43287421 ns/iter (± 63546) 1.00
es/minify/libraries/react 15960334 ns/iter (± 63919) 15979196 ns/iter (± 48259) 1.00
es/minify/libraries/terser 185595395 ns/iter (± 726083) 185448834 ns/iter (± 1210790) 1.00
es/minify/libraries/three 319244024 ns/iter (± 1050891) 321798988 ns/iter (± 1287810) 0.99
es/minify/libraries/typescript 2230664453 ns/iter (± 18244392) 2242056923 ns/iter (± 17543023) 0.99
es/minify/libraries/victory 477659514 ns/iter (± 5979536) 475511419 ns/iter (± 4618065) 1.00
es/minify/libraries/vue 105530233 ns/iter (± 301429) 105833893 ns/iter (± 415943) 1.00
es/visitor/compare/clone 1950934 ns/iter (± 6253) 1933229 ns/iter (± 4896) 1.01
es/visitor/compare/visit_mut_span 2282054 ns/iter (± 3671) 2277994 ns/iter (± 13410) 1.00
es/visitor/compare/visit_mut_span_panic 2313877 ns/iter (± 987) 2310515 ns/iter (± 3702) 1.00
es/visitor/compare/fold_span 3385236 ns/iter (± 7058) 3352194 ns/iter (± 3983) 1.01
es/visitor/compare/fold_span_panic 3498076 ns/iter (± 7137) 3507230 ns/iter (± 8037) 1.00
es/lexer/colors 13117 ns/iter (± 38) 12988 ns/iter (± 73) 1.01
es/lexer/angular 6097119 ns/iter (± 12078) 6138999 ns/iter (± 5784) 0.99
es/lexer/backbone 777599 ns/iter (± 971) 778424 ns/iter (± 907) 1.00
es/lexer/jquery 4471044 ns/iter (± 18043) 4480417 ns/iter (± 10549) 1.00
es/lexer/jquery mobile 6846033 ns/iter (± 17274) 6831364 ns/iter (± 8381) 1.00
es/lexer/mootools 3507615 ns/iter (± 4433) 3536421 ns/iter (± 4407) 0.99
es/lexer/underscore 653085 ns/iter (± 870) 658029 ns/iter (± 424) 0.99
es/lexer/three 21223351 ns/iter (± 50330) 21447347 ns/iter (± 21301) 0.99
es/lexer/yui 3781741 ns/iter (± 4903) 3816745 ns/iter (± 5264) 0.99
es/parser/colors 27085 ns/iter (± 46) 27291 ns/iter (± 82) 0.99
es/parser/angular 13520460 ns/iter (± 56389) 13548271 ns/iter (± 54625) 1.00
es/parser/backbone 1976574 ns/iter (± 6846) 1984874 ns/iter (± 8195) 1.00
es/parser/jquery 10805757 ns/iter (± 34777) 10815709 ns/iter (± 40011) 1.00
es/parser/jquery mobile 16523597 ns/iter (± 35587) 16612289 ns/iter (± 56654) 0.99
es/parser/mootools 8305104 ns/iter (± 17917) 8319129 ns/iter (± 20438) 1.00
es/parser/underscore 1706100 ns/iter (± 9137) 1707813 ns/iter (± 10212) 1.00
es/parser/three 46851132 ns/iter (± 234358) 46764022 ns/iter (± 552162) 1.00
es/parser/yui 8212478 ns/iter (± 33845) 8220966 ns/iter (± 41438) 1.00
es/preset-env/usage/builtin_type 137918 ns/iter (± 32149) 135688 ns/iter (± 32636) 1.02
es/preset-env/usage/property 17111 ns/iter (± 62) 16391 ns/iter (± 77) 1.04
es/resolver/typescript 90341622 ns/iter (± 1329631) 90118602 ns/iter (± 625688) 1.00
es/fixer/typescript 62618990 ns/iter (± 560104) 63422190 ns/iter (± 340730) 0.99
es/hygiene/typescript 128768249 ns/iter (± 947869) 130994580 ns/iter (± 2545233) 0.98
es/resolver_with_hygiene/typescript 244817326 ns/iter (± 1842010) 255011950 ns/iter (± 2853776) 0.96
es/visitor/base-perf/module_clone 59436 ns/iter (± 379) 58887 ns/iter (± 321) 1.01
es/visitor/base-perf/fold_empty 63398 ns/iter (± 373) 63035 ns/iter (± 633) 1.01
es/visitor/base-perf/fold_noop_impl_all 63921 ns/iter (± 534) 63356 ns/iter (± 492) 1.01
es/visitor/base-perf/fold_noop_impl_vec 64257 ns/iter (± 358) 63198 ns/iter (± 221) 1.02
es/visitor/base-perf/boxing_boxed_clone 57 ns/iter (± 0) 56 ns/iter (± 0) 1.02
es/visitor/base-perf/boxing_unboxed_clone 39 ns/iter (± 0) 40 ns/iter (± 0) 0.97
es/visitor/base-perf/boxing_boxed 111 ns/iter (± 0) 109 ns/iter (± 0) 1.02
es/visitor/base-perf/boxing_unboxed 92 ns/iter (± 0) 78 ns/iter (± 0) 1.18
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 3200 ns/iter (± 36) 2517 ns/iter (± 8) 1.27
es/base/parallel/resolver/typescript 4483788948 ns/iter (± 276518977) 4159058026 ns/iter (± 168275065) 1.08
es/base/parallel/hygiene/typescript 1400518561 ns/iter (± 13361695) 1408137381 ns/iter (± 18216952) 0.99
misc/visitors/time-complexity/time 5 134 ns/iter (± 2) 120 ns/iter (± 3) 1.12
misc/visitors/time-complexity/time 10 368 ns/iter (± 4) 388 ns/iter (± 7) 0.95
misc/visitors/time-complexity/time 15 672 ns/iter (± 3) 508 ns/iter (± 0) 1.32
misc/visitors/time-complexity/time 20 1109 ns/iter (± 3) 1066 ns/iter (± 39) 1.04
misc/visitors/time-complexity/time 40 3579 ns/iter (± 9) 4134 ns/iter (± 296) 0.87
misc/visitors/time-complexity/time 60 7371 ns/iter (± 45) 7421 ns/iter (± 47) 0.99
es/full-target/es2016 233245 ns/iter (± 748) 229148 ns/iter (± 358) 1.02
es/full-target/es2017 221635 ns/iter (± 606) 218530 ns/iter (± 893) 1.01
es/full-target/es2018 209917 ns/iter (± 929) 206553 ns/iter (± 620) 1.02
es2020_nullish_coalescing 70959 ns/iter (± 589) 69760 ns/iter (± 455) 1.02
es2020_optional_chaining 80395 ns/iter (± 378) 81210 ns/iter (± 289) 0.99
es2022_class_properties 117391 ns/iter (± 377) 113942 ns/iter (± 493) 1.03
es2018_object_rest_spread 76615 ns/iter (± 232) 74333 ns/iter (± 195) 1.03
es2019_optional_catch_binding 65951 ns/iter (± 354) 63937 ns/iter (± 322) 1.03
es2017_async_to_generator 64871 ns/iter (± 228) 64268 ns/iter (± 236) 1.01
es2016_exponentiation 69871 ns/iter (± 199) 68151 ns/iter (± 222) 1.03
es2015_arrow 73254 ns/iter (± 126) 71796 ns/iter (± 327) 1.02
es2015_block_scoped_fn 69440 ns/iter (± 234) 68239 ns/iter (± 211) 1.02
es2015_block_scoping 125628 ns/iter (± 259) 120438 ns/iter (± 379) 1.04

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

Please sign in to comment.