Skip to content

Commit

Permalink
feat(es/typescript): Add swc_fast_ts_strip (#9143)
Browse files Browse the repository at this point in the history
**Description:**

This PR also adds a CI process for each Wasm binding.

---------

Co-authored-by: magic-akari <akari.ccino@gmail.com>
  • Loading branch information
kdy1 and magic-akari authored Jul 5, 2024
1 parent ce78baa commit b129343
Show file tree
Hide file tree
Showing 51 changed files with 689 additions and 364 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ jobs:
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pkg:
- binding_core_wasm
- binding_minifier_wasm
- binding_typescript_wasm

steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -200,7 +208,7 @@ jobs:
- name: Test
run: |
(cd bindings/binding_core_wasm && ./scripts/test.sh)
(cd bindings/${{ matrix.pkg }} && ./scripts/test.sh)
cargo-test:
name: Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }}
Expand Down Expand Up @@ -460,6 +468,8 @@ jobs:
runner: ubuntu-latest
- crate: swc_fast_graph
os: ubuntu-latest
- crate: swc_fast_ts_strip
os: ubuntu-latest
runner: ubuntu-latest
- crate: swc_graph_analyzer
os: ubuntu-latest
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [
"crates/swc_x_optimizer",
"crates/swc_transform_common",
"crates/swc_typescript",
"crates/swc_fast_ts_strip",
]
resolver = "2"

Expand Down
118 changes: 35 additions & 83 deletions bindings/Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`minify should work 1`] = `
Object {
"code": "console.log(1);",
}
`;
15 changes: 15 additions & 0 deletions bindings/binding_minifier_wasm/__tests__/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const swc = require("../pkg");

describe("minify", () => {
it("should work", async () => {
const output = await swc.minify(
`{
const a = 1;
console.log(a);
}`,
{}
);

expect(output).toMatchSnapshot();
});
});
6 changes: 6 additions & 0 deletions bindings/binding_minifier_wasm/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eu

wasm-pack build --out-name wasm --release --scope=swc --target nodejs
npx jest $@
13 changes: 2 additions & 11 deletions bindings/binding_typescript_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,9 @@ getrandom = { version = "0.2.10", features = ["js"] }
serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.4.5"
serde_json = "1.0.120"
swc_core = { version = "0.96.3", features = [
"common",
"common_sourcemap",
"ecma_ast",
"ecma_codegen",
"ecma_parser",
"ecma_transforms",
"ecma_transforms_typescript",
"ecma_visit",
] }
swc_ecma_codegen = { version = "0.151.1", features = ["serde-impl"] }
swc_common = "0.34.3"
swc_error_reporters = "0.18.0"
swc_fast_ts_strip = "0.1.1"
tracing = { version = "0.1.37", features = ["max_level_off"] }
wasm-bindgen = { version = "0.2.82", features = ["enable-interning"] }
wasm-bindgen-futures = { version = "0.4.41" }
Loading

1 comment on commit b129343

@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: b129343 Previous: 648830a Ratio
es/full/bugs-1 288325 ns/iter (± 8717) 273458 ns/iter (± 2515) 1.05
es/full/minify/libraries/antd 1879280621 ns/iter (± 38123998) 1770859708 ns/iter (± 77956683) 1.06
es/full/minify/libraries/d3 351501508 ns/iter (± 20228169) 346352491 ns/iter (± 5946405) 1.01
es/full/minify/libraries/echarts 1586310245 ns/iter (± 46242281) 1470229933 ns/iter (± 41431908) 1.08
es/full/minify/libraries/jquery 103020423 ns/iter (± 460519) 101841081 ns/iter (± 140626) 1.01
es/full/minify/libraries/lodash 114489897 ns/iter (± 854426) 112930325 ns/iter (± 141754) 1.01
es/full/minify/libraries/moment 59852238 ns/iter (± 742596) 59058699 ns/iter (± 66670) 1.01
es/full/minify/libraries/react 18379265 ns/iter (± 35385) 18262325 ns/iter (± 44354) 1.01
es/full/minify/libraries/terser 277587688 ns/iter (± 1995837) 270216193 ns/iter (± 1309033) 1.03
es/full/minify/libraries/three 481968952 ns/iter (± 4616216) 457866709 ns/iter (± 12016419) 1.05
es/full/minify/libraries/typescript 3307022111 ns/iter (± 16255943) 3247242918 ns/iter (± 53803273) 1.02
es/full/minify/libraries/victory 870839048 ns/iter (± 18414802) 729492702 ns/iter (± 27224813) 1.19
es/full/minify/libraries/vue 151321344 ns/iter (± 1505695) 143797838 ns/iter (± 157638) 1.05
es/full/codegen/es3 58862 ns/iter (± 388) 58538 ns/iter (± 292) 1.01
es/full/codegen/es5 58902 ns/iter (± 361) 58416 ns/iter (± 318) 1.01
es/full/codegen/es2015 59170 ns/iter (± 211) 58247 ns/iter (± 381) 1.02
es/full/codegen/es2016 59147 ns/iter (± 204) 58363 ns/iter (± 256) 1.01
es/full/codegen/es2017 58903 ns/iter (± 125) 58445 ns/iter (± 288) 1.01
es/full/codegen/es2018 58822 ns/iter (± 160) 58336 ns/iter (± 611) 1.01
es/full/codegen/es2019 59174 ns/iter (± 1683) 58226 ns/iter (± 316) 1.02
es/full/codegen/es2020 59032 ns/iter (± 790) 58249 ns/iter (± 136) 1.01
es/full/all/es3 162576133 ns/iter (± 1712726) 163525596 ns/iter (± 818499) 0.99
es/full/all/es5 157447049 ns/iter (± 781906) 156307600 ns/iter (± 583753) 1.01
es/full/all/es2015 115645694 ns/iter (± 743644) 115618105 ns/iter (± 1226515) 1.00
es/full/all/es2016 114266537 ns/iter (± 1056874) 114498114 ns/iter (± 530003) 1.00
es/full/all/es2017 114182949 ns/iter (± 1403863) 113641086 ns/iter (± 743295) 1.00
es/full/all/es2018 112348635 ns/iter (± 838662) 111617061 ns/iter (± 597848) 1.01
es/full/all/es2019 111421246 ns/iter (± 683835) 110685694 ns/iter (± 412248) 1.01
es/full/all/es2020 107538250 ns/iter (± 1350301) 106991238 ns/iter (± 1038597) 1.01
es/full/parser 449999 ns/iter (± 2592) 450234 ns/iter (± 2967) 1.00
es/full/base/fixer 15243 ns/iter (± 67) 14972 ns/iter (± 48) 1.02
es/full/base/resolver_and_hygiene 79599 ns/iter (± 296) 79622 ns/iter (± 406) 1.00
serialization of serde 252 ns/iter (± 11) 278 ns/iter (± 9) 0.91
css/minify/libraries/bootstrap 22047020 ns/iter (± 296785) 22163497 ns/iter (± 95103) 0.99
css/visitor/compare/clone 1367831 ns/iter (± 7178) 1363146 ns/iter (± 18606) 1.00
css/visitor/compare/visit_mut_span 1484018 ns/iter (± 15691) 1484304 ns/iter (± 5371) 1.00
css/visitor/compare/visit_mut_span_panic 1503105 ns/iter (± 34041) 1501762 ns/iter (± 33465) 1.00
css/visitor/compare/fold_span 2005873 ns/iter (± 20311) 1994548 ns/iter (± 6796) 1.01
css/visitor/compare/fold_span_panic 2127809 ns/iter (± 6065) 2124181 ns/iter (± 3522) 1.00
css/lexer/bootstrap_5_1_3 3489458 ns/iter (± 858) 3455936 ns/iter (± 42346) 1.01
css/lexer/foundation_6_7_4 2816489 ns/iter (± 1830) 2807454 ns/iter (± 4172) 1.00
css/lexer/tailwind_3_1_1 540062 ns/iter (± 7442) 539519 ns/iter (± 399) 1.00
css/parser/bootstrap_5_1_3 16428835 ns/iter (± 102463) 16512698 ns/iter (± 162154) 0.99
css/parser/foundation_6_7_4 13232056 ns/iter (± 21907) 13185028 ns/iter (± 19281) 1.00
css/parser/tailwind_3_1_1 2612318 ns/iter (± 5335) 2589731 ns/iter (± 4003) 1.01
es/codegen/colors 726083 ns/iter (± 396739) 713407 ns/iter (± 388773) 1.02
es/codegen/large 2985817 ns/iter (± 1604136) 3071203 ns/iter (± 1595862) 0.97
es/codegen/with-parser/colors 40196 ns/iter (± 406) 40561 ns/iter (± 318) 0.99
es/codegen/with-parser/large 447338 ns/iter (± 3328) 449886 ns/iter (± 1661) 0.99
es/minify/libraries/antd 1340890230 ns/iter (± 13121536) 1434271070 ns/iter (± 83861289) 0.93
es/minify/libraries/d3 277047461 ns/iter (± 1355343) 281041364 ns/iter (± 9256937) 0.99
es/minify/libraries/echarts 1096213161 ns/iter (± 6320199) 1170520197 ns/iter (± 6345398) 0.94
es/minify/libraries/jquery 82102572 ns/iter (± 690376) 82085767 ns/iter (± 520186) 1.00
es/minify/libraries/lodash 103744601 ns/iter (± 543007) 103780810 ns/iter (± 434544) 1.00
es/minify/libraries/moment 48123474 ns/iter (± 111447) 47878339 ns/iter (± 202603) 1.01
es/minify/libraries/react 16281279 ns/iter (± 17789) 16125402 ns/iter (± 19475) 1.01
es/minify/libraries/terser 215793450 ns/iter (± 300636) 217321034 ns/iter (± 1632066) 0.99
es/minify/libraries/three 355989390 ns/iter (± 1196511) 367226995 ns/iter (± 982198) 0.97
es/minify/libraries/typescript 2647872511 ns/iter (± 6124707) 2727367081 ns/iter (± 11999405) 0.97
es/minify/libraries/victory 541346207 ns/iter (± 7685908) 580700254 ns/iter (± 2479238) 0.93
es/minify/libraries/vue 120543947 ns/iter (± 227250) 120341606 ns/iter (± 245584) 1.00
es/visitor/compare/clone 1729529 ns/iter (± 6874) 1700813 ns/iter (± 7138) 1.02
es/visitor/compare/visit_mut_span 2060368 ns/iter (± 6527) 2047491 ns/iter (± 4991) 1.01
es/visitor/compare/visit_mut_span_panic 2070067 ns/iter (± 38494) 2050167 ns/iter (± 5524) 1.01
es/visitor/compare/fold_span 2784874 ns/iter (± 7379) 2743846 ns/iter (± 21522) 1.01
es/visitor/compare/fold_span_panic 2812851 ns/iter (± 3784) 2801700 ns/iter (± 9501) 1.00
es/lexer/colors 9896 ns/iter (± 76) 9874 ns/iter (± 59) 1.00
es/lexer/angular 5163115 ns/iter (± 11704) 5141017 ns/iter (± 25059) 1.00
es/lexer/backbone 635467 ns/iter (± 3688) 650723 ns/iter (± 5545) 0.98
es/lexer/jquery 3632349 ns/iter (± 24780) 3656106 ns/iter (± 42593) 0.99
es/lexer/jquery mobile 5289392 ns/iter (± 30932) 5513101 ns/iter (± 15240) 0.96
es/lexer/mootools 2784144 ns/iter (± 3357) 2920670 ns/iter (± 21412) 0.95
es/lexer/underscore 542842 ns/iter (± 2339) 530220 ns/iter (± 1126) 1.02
es/lexer/three 15934603 ns/iter (± 42526) 15995785 ns/iter (± 23201) 1.00
es/lexer/yui 2891342 ns/iter (± 9896) 2954828 ns/iter (± 11721) 0.98
es/lexer/cal-com 13097583 ns/iter (± 56974) 13442651 ns/iter (± 96296) 0.97
es/lexer/typescript 90625123 ns/iter (± 209307) 91792534 ns/iter (± 357915) 0.99
es/parser/colors 23863 ns/iter (± 91) 24019 ns/iter (± 94) 0.99
es/parser/angular 12401752 ns/iter (± 168200) 12816522 ns/iter (± 64147) 0.97
es/parser/backbone 1808963 ns/iter (± 10086) 1828680 ns/iter (± 6877) 0.99
es/parser/jquery 10035652 ns/iter (± 92904) 10093974 ns/iter (± 56358) 0.99
es/parser/jquery mobile 15154419 ns/iter (± 130013) 15283760 ns/iter (± 89692) 0.99
es/parser/mootools 7791668 ns/iter (± 35263) 7886228 ns/iter (± 18426) 0.99
es/parser/underscore 1579661 ns/iter (± 4779) 1595070 ns/iter (± 5893) 0.99
es/parser/three 44480113 ns/iter (± 471773) 44907312 ns/iter (± 363261) 0.99
es/parser/yui 7395269 ns/iter (± 31796) 7541745 ns/iter (± 38663) 0.98
es/parser/cal-com 39989983 ns/iter (± 1386786) 40590071 ns/iter (± 293202) 0.99
es/parser/typescript 266724473 ns/iter (± 1871621) 269537275 ns/iter (± 516075) 0.99
es/preset-env/usage/builtin_type 135868 ns/iter (± 33783) 135657 ns/iter (± 33889) 1.00
es/preset-env/usage/property 16629 ns/iter (± 151) 16420 ns/iter (± 148) 1.01
es/resolver/typescript 100298299 ns/iter (± 1871134) 103485237 ns/iter (± 2498633) 0.97
es/fixer/typescript 77968991 ns/iter (± 3145804) 82595442 ns/iter (± 2584173) 0.94
es/hygiene/typescript 183153003 ns/iter (± 4139211) 191377278 ns/iter (± 4792431) 0.96
es/resolver_with_hygiene/typescript 308348235 ns/iter (± 2645639) 316694111 ns/iter (± 4410263) 0.97
es/visitor/base-perf/module_clone 57101 ns/iter (± 506) 56511 ns/iter (± 2151) 1.01
es/visitor/base-perf/fold_empty 60342 ns/iter (± 954) 59598 ns/iter (± 949) 1.01
es/visitor/base-perf/fold_noop_impl_all 60410 ns/iter (± 815) 59965 ns/iter (± 1545) 1.01
es/visitor/base-perf/fold_noop_impl_vec 59936 ns/iter (± 344) 59626 ns/iter (± 918) 1.01
es/visitor/base-perf/boxing_boxed_clone 59 ns/iter (± 0) 60 ns/iter (± 0) 0.98
es/visitor/base-perf/boxing_unboxed_clone 47 ns/iter (± 0) 47 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 106 ns/iter (± 0) 106 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed 81 ns/iter (± 0) 81 ns/iter (± 0) 1
es/visitor/base-perf/visit_contains_this 2626 ns/iter (± 7) 2670 ns/iter (± 34) 0.98
es/base/parallel/resolver/typescript 2378749507 ns/iter (± 107216295) 2530510942 ns/iter (± 105358930) 0.94
es/base/parallel/hygiene/typescript 3273332113 ns/iter (± 50920779) 3340294291 ns/iter (± 39637267) 0.98
babelify-only 493226 ns/iter (± 5739) 495439 ns/iter (± 2797) 1.00
parse_and_babelify_angular 42607577 ns/iter (± 698781) 42252347 ns/iter (± 793116) 1.01
parse_and_babelify_backbone 4377726 ns/iter (± 162018) 4422637 ns/iter (± 164383) 0.99
parse_and_babelify_jquery 28814833 ns/iter (± 654763) 28142288 ns/iter (± 220807) 1.02
parse_and_babelify_jquery_mobile 50586011 ns/iter (± 943485) 48018438 ns/iter (± 865593) 1.05
parse_and_babelify_mootools 26208475 ns/iter (± 235037) 25219988 ns/iter (± 134165) 1.04
parse_and_babelify_underscore 3665153 ns/iter (± 10551) 3680344 ns/iter (± 29133) 1.00
parse_and_babelify_yui 24458997 ns/iter (± 207327) 23501594 ns/iter (± 590277) 1.04
html/minify/document/css_spec 45137595 ns/iter (± 975708) 45105331 ns/iter (± 136782) 1.00
html/minify/document/github 17935112 ns/iter (± 36260) 18019303 ns/iter (± 46760) 1.00
html/minify/document/stackoverflow 16341912 ns/iter (± 239458) 16497988 ns/iter (± 755320) 0.99
html/minify/document_fragment/css_spec 44630536 ns/iter (± 772967) 44352982 ns/iter (± 239301) 1.01
html/minify/document_fragment/github 17714318 ns/iter (± 72156) 17710953 ns/iter (± 56113) 1.00
html/minify/document_fragment/stackoverflow 16282774 ns/iter (± 53392) 16154035 ns/iter (± 30184) 1.01
html/document/visitor/compare/clone 165159 ns/iter (± 2724) 166566 ns/iter (± 2426) 0.99
html/document/visitor/compare/visit_mut_span 181278 ns/iter (± 3688) 180689 ns/iter (± 1500) 1.00
html/document/visitor/compare/visit_mut_span_panic 187151 ns/iter (± 6271) 184940 ns/iter (± 4728) 1.01
html/document/visitor/compare/fold_span 231813 ns/iter (± 774) 229346 ns/iter (± 1390) 1.01
html/document/visitor/compare/fold_span_panic 282806 ns/iter (± 1664) 281340 ns/iter (± 1562) 1.01
html/document_fragment/visitor/compare/clone 164274 ns/iter (± 1854) 166450 ns/iter (± 1582) 0.99
html/document_fragment/visitor/compare/visit_mut_span 181872 ns/iter (± 668) 182955 ns/iter (± 4262) 0.99
html/document_fragment/visitor/compare/visit_mut_span_panic 187048 ns/iter (± 2019) 188707 ns/iter (± 806) 0.99
html/document_fragment/visitor/compare/fold_span 232741 ns/iter (± 1340) 229735 ns/iter (± 1339) 1.01
html/document_fragment/visitor/compare/fold_span_panic 280846 ns/iter (± 693) 280458 ns/iter (± 1687) 1.00
html/lexer/css_2021_spec 12957349 ns/iter (± 28923) 12901617 ns/iter (± 24218) 1.00
html/lexer/github_com_17_05_2022 4983304 ns/iter (± 40119) 4978719 ns/iter (± 11414) 1.00
html/lexer/stackoverflow_com_17_05_2022 4718789 ns/iter (± 105072) 4745049 ns/iter (± 14318) 0.99
html/parser/parser_document/css_2021_spec 26025369 ns/iter (± 330734) 26031057 ns/iter (± 152767) 1.00
html/parser/parser_document/github_com_17_05_2022 8615559 ns/iter (± 19904) 8628515 ns/iter (± 32437) 1.00
html/parser/parser_document/stackoverflow_com_17_05_2022 7563696 ns/iter (± 25997) 7626536 ns/iter (± 24859) 0.99
html/parser/parser_document_fragment/css_2021_spec 26063164 ns/iter (± 264580) 25501225 ns/iter (± 226725) 1.02
html/parser/parser_document_fragment/github_com_17_05_2022 8598135 ns/iter (± 28469) 8467896 ns/iter (± 40022) 1.02
html/parser/parser_document_fragment/stackoverflow_com_17_05_2022 7503358 ns/iter (± 13927) 7406890 ns/iter (± 14359) 1.01

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

Please sign in to comment.