Skip to content

Commit b02e189

Browse files
authored
feat(es/minifier): Implement more rules (#1871)
swc_ecma_codegen: - Fix codegen of `U+0028` and `U+0029`. swc_ecma_minifier: - Implement MVP. swc_ecma_transforms_base: - `fixer`: Handle seq/await in rhs of for-of.
1 parent d64aa6f commit b02e189

File tree

366 files changed

+238128
-1304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

366 files changed

+238128
-1304
lines changed

.github/workflows/cargo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
# Source map format
161161
- uses: actions/setup-node@v2
162162
with:
163-
node-version: "14"
163+
node-version: "16"
164164

165165
# We explicitly do this to cache properly.
166166
- name: Install Rust
@@ -170,7 +170,7 @@ jobs:
170170

171171
- uses: actions/setup-node@v2
172172
with:
173-
node-version: 14
173+
node-version: 16
174174

175175
- uses: denoland/setup-deno@v1
176176
with:

Cargo.lock

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecmascript/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66
license = "Apache-2.0/MIT"
77
name = "swc_ecmascript"
88
repository = "https://github.com/swc-project/swc.git"
9-
version = "0.48.0"
9+
version = "0.49.0"
1010

1111
[package.metadata.docs.rs]
1212
all-features = true
@@ -34,7 +34,7 @@ typescript = ["typescript-parser", "swc_ecma_transforms/typescript"]
3434
swc_ecma_ast = {version = "0.49.0", path = "./ast"}
3535
swc_ecma_codegen = {version = "0.64.0", path = "./codegen", optional = true}
3636
swc_ecma_dep_graph = {version = "0.33.0", path = "./dep-graph", optional = true}
37-
swc_ecma_minifier = {version = "0.14.0", path = "./minifier", optional = true}
37+
swc_ecma_minifier = {version = "0.15.0", path = "./minifier", optional = true}
3838
swc_ecma_parser = {version = "0.65.0", path = "./parser", optional = true, default-features = false}
3939
swc_ecma_transforms = {version = "0.61.0", path = "./transforms", optional = true}
4040
swc_ecma_utils = {version = "0.41.0", path = "./utils", optional = true}

ecmascript/codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
77
license = "Apache-2.0/MIT"
88
name = "swc_ecma_codegen"
99
repository = "https://github.com/swc-project/swc.git"
10-
version = "0.64.1"
10+
version = "0.64.2"
1111

1212
[dependencies]
1313
bitflags = "1"

ecmascript/codegen/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,13 @@ fn escape_without_source(v: &str, target: JscTarget, single_quote: bool) -> Stri
25432543
let _ = write!(buf, "\\x{:x}", c as u8);
25442544
}
25452545

2546+
'\u{2028}' => {
2547+
buf.push_str("\\u2028");
2548+
}
2549+
'\u{2029}' => {
2550+
buf.push_str("\\u2029");
2551+
}
2552+
25462553
_ => {
25472554
buf.push(c);
25482555
}

ecmascript/codegen/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ fn test_escape_without_source() {
560560
es2020("abcde", "abcde");
561561
es2020(
562562
"\x00\r\n\u{85}\u{2028}\u{2029};",
563-
"\\x00\\r\\n\\x85\u{2028}\u{2029};",
563+
"\\x00\\r\\n\\x85\\u2028\\u2029;",
564564
);
565565

566566
es2020("\n", "\\n");

ecmascript/minifier/.eslintrc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"parser": "babel-eslint",
3+
"rules": {
4+
"indent": [
5+
"error",
6+
4
7+
],
8+
"semi": [
9+
"error",
10+
"always"
11+
],
12+
"space-unary-ops": 2,
13+
"no-undef": "off",
14+
"consistent-return": "off",
15+
"no-prototype-builtins": "off",
16+
"no-cond-assign": "off",
17+
"multiline-ternary": [
18+
"error",
19+
"always-multiline"
20+
],
21+
"object-property-newline": [
22+
"error",
23+
{
24+
"allowAllPropertiesOnSameLine": false
25+
}
26+
],
27+
"function-call-argument-newline": [
28+
"error",
29+
"always"
30+
],
31+
"object-curly-newline": [
32+
"error",
33+
"always"
34+
],
35+
"comma-dangle": [
36+
"error",
37+
"always"
38+
],
39+
"function-paren-newline": [
40+
"error",
41+
"always"
42+
],
43+
"no-trailing-spaces": [
44+
"error"
45+
]
46+
}
47+
}

ecmascript/minifier/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Used to see ideal output using terser
2+
lab.js

ecmascript/minifier/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ include = ["Cargo.toml", "src/**/*.rs", "src/lists/*.json"]
77
license = "Apache-2.0/MIT"
88
name = "swc_ecma_minifier"
99
repository = "https://github.com/swc-project/swc.git"
10-
version = "0.14.0"
10+
version = "0.15.0"
1111

1212
[features]
1313
debug = []
1414

1515
[dependencies]
1616
fxhash = "0.2.1"
17+
indexmap = "1.7.0"
1718
log = "0.4"
1819
once_cell = "1.5.2"
1920
pretty_assertions = {version = "0.6.1", optional = true}
@@ -31,10 +32,12 @@ swc_ecma_transforms = {version = "0.61.0", path = "../transforms/", features = [
3132
swc_ecma_transforms_base = {version = "0.24.0", path = "../transforms/base"}
3233
swc_ecma_utils = {version = "0.41.0", path = "../utils"}
3334
swc_ecma_visit = {version = "0.35.0", path = "../visit"}
35+
unicode-xid = "0.2.2"
3436

3537
[dev-dependencies]
3638
ansi_term = "0.12.1"
3739
anyhow = "1"
3840
pretty_assertions = "0.6.1"
41+
swc_node_base = {version = "0.2.0", path = "../../node/base"}
3942
testing = {version = "0.12.0", path = "../../testing"}
4043
walkdir = "2.3.1"

ecmascript/minifier/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ Currently name mangler is very simple. To focus on creating a MVP, I (kdy1) will
88

99
## Testing
1010

11+
### Real-library tests
12+
13+
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.
14+
15+
#### Splitting a library test
16+
17+
Extracting only subset from a library test makes development much easier.
18+
19+
Split status:
20+
21+
- [ ] angular-1.2.5
22+
- [x] backbone-1.1.0
23+
- [ ] jquery-1.9.1
24+
- [ ] jquery.mobile-1.4.2
25+
- [ ] mootools-1.4.5
26+
- [x] underscore-1.5.2
27+
- [ ] yui-3.12.0
28+
29+
### Tests from terser
30+
1131
Tests ported from terser has
1232

1333
- input.js
@@ -16,6 +36,6 @@ Tests ported from terser has
1636
- output.js (if exists and can be modified if our one is better or due to lack of frequency-aware base54)
1737
- output.terser.js (if exists)
1838

19-
## Copying tests
39+
#### Copying tests
2040

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

0 commit comments

Comments
 (0)