swc/crates/swc_ecma_minifier
2022-04-17 14:27:11 +00:00
..
benches perf(es/minifier): Make name mangler faster (#4342) 2022-04-17 15:35:36 +09:00
examples chore(es/minifier): Improve scripts (#4339) 2022-04-17 19:53:47 +09:00
inputs fix(es/minifier): Fix bugs (#2955) 2022-01-05 05:12:52 +09:00
scripts chore(es/minifier): Improve scripts (#4339) 2022-04-17 19:53:47 +09:00
src perf(es/minifier): Split frequently used functions (#4352) 2022-04-17 14:22:38 +00:00
tests fix(es/minifier): Preserve vars in dead branches (#4345) 2022-04-17 08:15:14 +00:00
.eslintrc refactor: Flatten ecmascript (#2708) 2021-11-10 19:00:54 +09:00
.gitignore perf(es/minifier): Add a fast-path to export merger (#3891) 2022-03-07 14:21:57 +09:00
Cargo.toml chore: Publish crates 2022-04-17 14:27:11 +00:00
one.sh feat(es/minifier): Implement more rules for hoist_props (#4262) 2022-04-06 11:01:45 +00:00
package.json fix(es/minifier): Fix optimization of assignment expressions (#3231) 2022-01-12 08:26:56 +09:00
README.md fix(es/minifier): Fix handling of eval (#4273) 2022-04-08 08:56:28 +00:00
yarn.lock fix(es/minifier): Fix optimization of assignment expressions (#3231) 2022-01-12 08:26:56 +09:00

Minifier

EcmaScript minifier for the SWC project. This is basically a port of terser.

Note

Currently name mangler is very simple. To focus on creating a MVP, I (kdy1) will use simple logic for name mangler and implement the content-aware name mangler after publishing first non-beta version.

Debugging tips

If the output contains variables named e, t, n it typically means the original library is published in a minified form and the input contains eval. The current swc name mangler does not do anything if eval is used.

Testing

Real-library tests

You can use vscode to see diffs. Select a file from tests/projects/output and select the corresponding file from tests/projects/refs. Then you can right click to see an option to open diff.

Splitting a library test

Extracting only subset from a library test makes development much easier.

Split status:

  • angular-1.2.5
  • backbone-1.1.0
  • jquery-1.9.1
  • jquery.mobile-1.4.2
  • mootools-1.4.5
  • underscore-1.5.2
  • yui-3.12.0

Tests from terser

Tests ported from terser has

  • input.js
  • config.json
  • mangle.json (if name mangling is enabled)
  • output.js (if exists and can be modified if our one is better or due to lack of frequency-aware base54)
  • output.terser.js (if exists)

Copying tests

Replace the content of terser/test/compress.js with it of scripts/compress.js and run npm run test:compress