Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es/minifier): Implement minifier #1302

Merged
merged 1,235 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1235 commits
Select commit Hold shift + click to select a range
94b9ddd
More goldens
kdy1 Feb 3, 2021
8a0e8fb
Update test refs
kdy1 Feb 4, 2021
a39270a
analyzer: Mark do-while and while as loop.
kdy1 Feb 4, 2021
45e86dc
Sort methods
kdy1 Feb 4, 2021
90dabe6
More goldens
kdy1 Feb 4, 2021
4a2334d
WIP: drop_if_break
kdy1 Feb 4, 2021
b48d6e3
Update test refs
kdy1 Feb 4, 2021
dd207a4
Add `as_expr` to ExprOptExt
kdy1 Feb 4, 2021
8b317d9
Add ExprExt.cast_to_number
kdy1 Feb 4, 2021
19e64fa
as_bool: Support subtraction.
kdy1 Feb 4, 2021
3ace605
Add a ways to prepend / append statements.
kdy1 Feb 4, 2021
afc48a5
loops: Remove for statement completely
kdy1 Feb 4, 2021
4f0c180
Update test refs
kdy1 Feb 4, 2021
b36d498
More goldens
kdy1 Feb 4, 2021
d5e1173
Doc
kdy1 Feb 4, 2021
1551333
WIP: while_to_for
kdy1 Feb 4, 2021
2a58afd
Convert while loops to for loops
kdy1 Feb 4, 2021
489250a
More goldens
kdy1 Feb 4, 2021
ed25854
Rename
kdy1 Feb 4, 2021
6033b93
Convert do-while loops to for loops
kdy1 Feb 4, 2021
231720e
Logging
kdy1 Feb 4, 2021
4bb1058
analyzer: Mark for stmt as a loop.
kdy1 Feb 4, 2021
138e9fa
More goldens
kdy1 Feb 4, 2021
da4e748
inline: Handle very simple functions.
kdy1 Feb 4, 2021
e66129c
More goldens
kdy1 Feb 4, 2021
bbdfa09
inline: Revent simple-function inliner
kdy1 Feb 4, 2021
f3c5117
Update goldens
kdy1 Feb 4, 2021
7274dfc
loops: Remove test of a for stmt if possible.
kdy1 Feb 4, 2021
754849b
Update test refs
kdy1 Feb 4, 2021
273395f
More goldens
kdy1 Feb 4, 2021
4a10072
impl optimize_for_init
kdy1 Feb 4, 2021
f97a0ab
Fix optimize_for_init
kdy1 Feb 4, 2021
0933edd
ignore_return_value: Drop pure calls
kdy1 Feb 4, 2021
caa60da
Rename
kdy1 Feb 4, 2021
f4de10f
More goldens
kdy1 Feb 4, 2021
67f41ec
Update test refs
kdy1 Feb 4, 2021
8bbcf7b
Rename
kdy1 Feb 4, 2021
5ef9ad3
WIP: optimize_loops_with_break
kdy1 Feb 4, 2021
a371831
loops: Remove loops with instant break
kdy1 Feb 4, 2021
7c2de11
More goldens
kdy1 Feb 4, 2021
f3b8ee0
loops: Preserve cases if required
kdy1 Feb 4, 2021
f2ffc4f
More goldens
kdy1 Feb 4, 2021
ab9385e
Update test refs
kdy1 Feb 4, 2021
bbfece3
ignore_return_value: Support class expressions
kdy1 Feb 4, 2021
8e6c6ea
More goldens
kdy1 Feb 4, 2021
6d4859e
Don't invoke iife in obj of member expr
kdy1 Feb 4, 2021
c0eeac6
fixup
kdy1 Feb 4, 2021
b3250f3
Don't inline generators.
kdy1 Feb 4, 2021
653ce0d
More goldens
kdy1 Feb 4, 2021
d1ff056
WIP: optimize_arrow_method_prop
kdy1 Feb 4, 2021
f8a003c
impl MapWithMut
kdy1 Feb 4, 2021
224fa19
fixup
kdy1 Feb 4, 2021
9e4635f
impl optimize_arrow_method_prop
kdy1 Feb 4, 2021
7cb5835
More goldens
kdy1 Feb 4, 2021
b1a9408
Preserve directives
kdy1 Feb 4, 2021
5245a6c
More goldens
kdy1 Feb 4, 2021
275024a
Preserve use strict
kdy1 Feb 4, 2021
41df8ed
Preserve directives, really
kdy1 Feb 4, 2021
9fbd935
Remove use strict if it's an only item.
kdy1 Feb 4, 2021
bd9b583
Drop calls to empty arrow expressions.
kdy1 Feb 4, 2021
6c93162
Remove `void 0;`
kdy1 Feb 4, 2021
d3d9ced
More goldens
kdy1 Feb 4, 2021
bf58b32
Change pass ordering
kdy1 Feb 4, 2021
e1e06a6
Check for `this` before optimizing properties.
kdy1 Feb 4, 2021
bc5ec7e
fixup
kdy1 Feb 4, 2021
8f00aa9
Update test refs
kdy1 Feb 4, 2021
a718d78
analyzer: Handle setter
kdy1 Feb 4, 2021
29b82e8
More goldens
kdy1 Feb 4, 2021
e8eb3db
expr simplifier: Ignore lhs of assignments.
kdy1 Feb 4, 2021
5064572
Update test refs
kdy1 Feb 4, 2021
26a2c17
WIP
kdy1 Feb 5, 2021
0f300e3
More goldens
kdy1 Feb 5, 2021
edc5c85
Update test refs
kdy1 Feb 5, 2021
ef11f76
Small cleanup to add more codes.
kdy1 Feb 5, 2021
7886180
WIP: More rules for conditionals
kdy1 Feb 5, 2021
dba7543
Merge cons and alt if only one arg differs.
kdy1 Feb 5, 2021
df99744
More goldens
kdy1 Feb 5, 2021
4015fcb
WIP: move_vars_in_subscopes
kdy1 Feb 5, 2021
2162c9f
impl MapWithMut
kdy1 Feb 5, 2021
18e230d
WIP: extract_vars_in_subscopes
kdy1 Feb 5, 2021
819ae59
fixup
kdy1 Feb 5, 2021
4dfd0d4
Fix extract_vars
kdy1 Feb 5, 2021
11f472a
More goldens
kdy1 Feb 5, 2021
28191c6
Respect `hoist_vars`
kdy1 Feb 5, 2021
d5065b8
More goldens
kdy1 Feb 5, 2021
b6ef3b5
Optimize negate
kdy1 Feb 5, 2021
8467bb0
fixup
kdy1 Feb 5, 2021
dfc14b7
extract_vars: Preserve side effects
kdy1 Feb 5, 2021
b2f86e9
Update test refs
kdy1 Feb 5, 2021
cdbd98b
More goldens
kdy1 Feb 5, 2021
8de4f73
expr simplifier: Track modifications
kdy1 Feb 5, 2021
bbbd75e
Fix extract_vars
kdy1 Feb 5, 2021
1538260
Update test refs
kdy1 Feb 5, 2021
bec05ea
Update test refs
kdy1 Feb 5, 2021
433190c
WIP: optimize_arrow_body
kdy1 Feb 5, 2021
ba9f123
Optimize arrow bodies
kdy1 Feb 5, 2021
b835ba9
Update test refs
kdy1 Feb 5, 2021
049ea15
More goldens
kdy1 Feb 5, 2021
37659ef
Add TODOs
kdy1 Feb 5, 2021
411dea8
Fix a test
kdy1 Feb 5, 2021
89b6784
impl MapWithMut
kdy1 Feb 5, 2021
4335b51
Implement compress_tpl
kdy1 Feb 5, 2021
c0ecbfa
template literal => string literal
kdy1 Feb 5, 2021
f80eb56
More goldens
kdy1 Feb 5, 2021
84c158c
analyzer: Handle params of arrow expr correctly.
kdy1 Feb 6, 2021
d719173
More goldens
kdy1 Feb 6, 2021
40ff5b7
Print expected stdout
kdy1 Feb 6, 2021
cad9b60
tester: Support stdout tests
kdy1 Feb 6, 2021
63abbf0
More goldens
kdy1 Feb 6, 2021
fa16a1f
Move codes
kdy1 Feb 6, 2021
936668b
Convert tpl to str only if it's all printable.
kdy1 Feb 6, 2021
ffdf3b3
Inline very simple functions.
kdy1 Feb 6, 2021
6bb6fc1
Inline more simple functions.
kdy1 Feb 6, 2021
e9c767c
WIP: We need comments
kdy1 Feb 6, 2021
cc6bb25
Add comments to optimizer
kdy1 Feb 6, 2021
63ca53d
Support `/*#__NOINLINE__*/`.
kdy1 Feb 6, 2021
f62536f
Add annotation
kdy1 Feb 6, 2021
45e75ac
Respect noinline annotations.
kdy1 Feb 6, 2021
0d9515b
More goldens
kdy1 Feb 6, 2021
618995f
Add annotation
kdy1 Feb 6, 2021
75a5975
Don't print all comments
kdy1 Feb 6, 2021
8792f69
Add annotation
kdy1 Feb 6, 2021
13a10d9
Handle `/** @const */`
kdy1 Feb 6, 2021
112d735
Update test refs
kdy1 Feb 6, 2021
0f4cb5d
Drop unused vars more aggresively.
kdy1 Feb 6, 2021
07d3a79
ignore_return_value: Support object.
kdy1 Feb 6, 2021
989aa32
Update test refs.
kdy1 Feb 6, 2021
3e426b1
More goldens
kdy1 Feb 6, 2021
9c212c2
WIP: optimize_computed_prop_name_as_normal
kdy1 Feb 6, 2021
6b31565
Optimize some computed prop names.
kdy1 Feb 6, 2021
1ed12e2
More goldens
kdy1 Feb 6, 2021
b55362e
Optimize prop names more agressively.
kdy1 Feb 6, 2021
dcc0233
Remove more blocks.
kdy1 Feb 6, 2021
932c412
More goldens
kdy1 Feb 6, 2021
548144d
Respect `arrows`
kdy1 Feb 6, 2021
21d0f33
Don't inline async functions.
kdy1 Feb 6, 2021
b2ba68d
fixup
kdy1 Feb 6, 2021
755b210
fixup
kdy1 Feb 6, 2021
ea3e49e
ignore_return_value: Support arrays.
kdy1 Feb 6, 2021
a7cface
Log
kdy1 Feb 6, 2021
2e6ab86
Store more `typeof`s.
kdy1 Feb 7, 2021
4196684
Update test refs
kdy1 Feb 7, 2021
41f315e
Log
kdy1 Feb 7, 2021
d522e49
Don't panic on option `module: bool`.
kdy1 Feb 7, 2021
1a12186
lint
kdy1 Feb 7, 2021
2ecc2aa
Option: `global_defs`
kdy1 Feb 7, 2021
3fa8201
Move
kdy1 Feb 7, 2021
b88a4d4
Move terser option into crate
kdy1 Feb 7, 2021
b6569ac
More options
kdy1 Feb 8, 2021
110e0bb
More work for options
kdy1 Feb 8, 2021
4b149c2
More work for options.
kdy1 Feb 8, 2021
cf0c6c8
fixup
kdy1 Feb 8, 2021
632b172
More work for options
kdy1 Feb 8, 2021
82a425b
More works for option
kdy1 Feb 8, 2021
43270d6
Even more options.
kdy1 Feb 8, 2021
a9e58c1
Rename
kdy1 Feb 8, 2021
328b14d
More goldens
kdy1 Feb 8, 2021
5cc09db
Rebase
kdy1 Feb 23, 2021
3866004
fixup
kdy1 Feb 23, 2021
f3a8893
fixup
kdy1 Feb 23, 2021
2d67f32
fixup
kdy1 Feb 23, 2021
4174d77
Update test refs
kdy1 Feb 25, 2021
0be1e74
WIP: drop_unused_stmt_at_end_of_fn
kdy1 Feb 25, 2021
5f488c6
Remove useless `return void`s.
kdy1 Feb 25, 2021
95d9788
fixup
kdy1 Feb 25, 2021
5ad1f32
More golden
kdy1 Feb 25, 2021
1197c96
Track more modifications
kdy1 Feb 25, 2021
30ced34
ignored.txt
kdy1 Feb 25, 2021
e04671e
Add a script to ignore tests
kdy1 Feb 25, 2021
f4cc9d7
Ignore some
kdy1 Feb 25, 2021
6484162
Respect ignored.txt
kdy1 Feb 25, 2021
64a1186
Ignore more
kdy1 Feb 25, 2021
d2de015
Update test refs
kdy1 Feb 25, 2021
69f1371
Update test refs
kdy1 Feb 25, 2021
d6df890
Udpate test refs
kdy1 Feb 25, 2021
81d0ccb
More ignore
kdy1 Feb 25, 2021
c4910bf
Fix the test runner
kdy1 Feb 25, 2021
3413ec3
More ignore
kdy1 Feb 25, 2021
05dd014
Fix ignore_return_value for object literals.
kdy1 Feb 25, 2021
672dee7
More ignore
kdy1 Feb 25, 2021
181d327
Update test refs
kdy1 Feb 25, 2021
2c9080f
More ignore
kdy1 Feb 25, 2021
e86f8ad
unused: Preserve decls named `argument`.
kdy1 Feb 25, 2021
f23d28b
More ignore
kdy1 Feb 25, 2021
c0e2a0a
More ignore
kdy1 Feb 25, 2021
c979670
More ignore
kdy1 Feb 25, 2021
0b6314e
More ignore
kdy1 Feb 25, 2021
bdbf0a4
Update test refs
kdy1 Feb 25, 2021
fef704f
More ignore
kdy1 Feb 25, 2021
20d374b
More ignore
kdy1 Feb 25, 2021
cd5ed7e
Udpate test refs
kdy1 Feb 25, 2021
1d93992
More ignore
kdy1 Feb 25, 2021
c233515
More ignore
kdy1 Feb 25, 2021
cfd5073
More ignore
kdy1 Feb 25, 2021
9fd823d
More ignore
kdy1 Feb 25, 2021
7348270
Update test refs
kdy1 Feb 25, 2021
e25349b
Update test refs
kdy1 Feb 25, 2021
1d10616
More ignore
kdy1 Feb 25, 2021
85e3b3f
More ignore
kdy1 Feb 25, 2021
03827ad
More ignore
kdy1 Feb 25, 2021
d46d083
More ignore
kdy1 Feb 27, 2021
18a19f7
More ignore
kdy1 Feb 27, 2021
0355b15
Fix version issue
kdy1 Mar 5, 2021
773de2e
Rebase
kdy1 Mar 5, 2021
6d2fcce
Don't inline regex
kdy1 Mar 9, 2021
9dd9f58
fixup
kdy1 Mar 9, 2021
4c307a0
Update the list
kdy1 Mar 9, 2021
2433306
Ignore
kdy1 Mar 10, 2021
e5f97da
Don't inline `arguments`.
kdy1 Mar 10, 2021
f43f93b
Golden
kdy1 Mar 10, 2021
cb43593
fixup: Use typeof
kdy1 Mar 10, 2021
b4854fd
fix
kdy1 Mar 10, 2021
b883f0a
Revert "fix"
kdy1 Mar 10, 2021
24f98cd
Ignore
kdy1 Mar 10, 2021
b835c4f
More ignore
kdy1 Mar 10, 2021
e4ba6ac
More ignore
kdy1 Mar 10, 2021
13af369
More ignore
kdy1 Mar 10, 2021
e2e46f5
Add some comments
kdy1 Mar 24, 2021
a6ce251
WIP: property mangler
fabiosantoscode Mar 28, 2021
d9ebc28
use JsWord
fabiosantoscode Apr 11, 2021
c615beb
reorder structs to match operation order
fabiosantoscode Apr 11, 2021
ade6dcc
do not mangle undeclared
fabiosantoscode Apr 11, 2021
b14fd16
fix tests
fabiosantoscode Apr 11, 2021
0bf94b2
mangle shorthand object props
fabiosantoscode Apr 12, 2021
aabdbb0
create script to update JS properties; move domprops in
fabiosantoscode Apr 18, 2021
57ed8a4
use domprops and jsprops
fabiosantoscode Apr 18, 2021
dc41650
fix mangling defineProperty string args
fabiosantoscode Apr 18, 2021
058e18c
fix sorting differences between Linux and Mac
fabiosantoscode May 2, 2021
64c3e3e
mangle private properties, refactor
fabiosantoscode May 2, 2021
3915b2f
Add regex option to limit mangling to props that match the regex
fabiosantoscode May 2, 2021
5781084
add a golden test
fabiosantoscode May 5, 2021
19a85cd
fix fmt error
fabiosantoscode May 5, 2021
0c8acdd
fixup for the rebase
kdy1 May 6, 2021
cc10320
make test scripts faster when the runner wants to filter tests
fabiosantoscode May 8, 2021
1aa0e4e
fixup for rebase
kdy1 May 8, 2021
d3616d5
fixup
kdy1 May 8, 2021
dcc9a2e
implement timings struct
fabiosantoscode May 9, 2021
a0148eb
Make it beta
kdy1 May 19, 2021
fa315ed
Fix
kdy1 May 19, 2021
a81677a
Fix
kdy1 May 19, 2021
e0eeefb
More fix
kdy1 May 19, 2021
33f3848
Use master
kdy1 May 19, 2021
6207300
fixup
kdy1 May 19, 2021
5648c7e
fixup
kdy1 May 19, 2021
571360d
Use master
kdy1 May 19, 2021
97f6899
fixup
kdy1 May 20, 2021
d7e1aa1
Update tets refs
kdy1 May 20, 2021
1023b25
Use master
kdy1 May 20, 2021
14f2ce0
lint
kdy1 May 20, 2021
4d07751
Ignore
kdy1 May 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 4 additions & 0 deletions .github/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
1 change: 1 addition & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ jobs:
- swc_ecma_dep_graph
- swc_ecma_ext_transforms
- swc_ecma_loader
- swc_ecma_minifier
- swc_ecma_parser
- swc_ecma_preset_env
- swc_ecma_transforms
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "ecmascript/test262-parser-tests"]
path = ecmascript/parser/tests/test262-parser
url = https://github.com/tc39/test262-parser-tests.git
shallow = true
[submodule "vendor/terser"]
path = vendor/terser
url = https://github.com/terser/terser.git
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 4,
"useTabs": false
}
13 changes: 13 additions & 0 deletions common/src/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ impl EqIgnoreSpan for Span {
}
}

impl<T> EqIgnoreSpan for [T]
where
T: EqIgnoreSpan,
{
fn eq_ignore_span(&self, other: &Self) -> bool {
self.len() == other.len()
&& self
.iter()
.zip(other.iter())
.all(|(a, b)| a.eq_ignore_span(b))
}
}

impl<T> EqIgnoreSpan for Option<T>
where
T: EqIgnoreSpan,
Expand Down
2 changes: 2 additions & 0 deletions ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ all-features = true
[features]
codegen = ["swc_ecma_codegen"]
dep_graph = ["swc_ecma_dep_graph"]
minifier = ["swc_ecma_minifier"]
parser = ["swc_ecma_parser"]
transforms = ["swc_ecma_transforms"]
utils = ["swc_ecma_utils"]
Expand All @@ -30,6 +31,7 @@ typescript = ["swc_ecma_transforms/typescript"]
swc_ecma_ast = {version = "0.45.0", path = "./ast"}
swc_ecma_codegen = {version = "0.55.0", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.25.0", path = "./dep-graph", optional = true}
swc_ecma_minifier = {version = "0.1.0-beta.0", path = "./minifier", optional = true}
swc_ecma_parser = {version = "0.57.0", path = "./parser", optional = true}
swc_ecma_transforms = {version = "0.50.0", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.36.0", path = "./utils", optional = true}
Expand Down
35 changes: 35 additions & 0 deletions ecmascript/minifier/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
authors = ["강동윤 <[email protected]>"]
description = "Ecmascript code minifier."
documentation = "https://swc.rs/rustdoc/swc_ecma_minifier/"
edition = "2018"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_minifier"
repository = "https://github.com/swc-project/swc.git"
version = "0.1.0-beta.0"

[dependencies]
fxhash = "0.2.1"
log = "0.4"
once_cell = "1.5.2"
pretty_assertions = "0.6.1"
regex = "1.5.3"
retain_mut = "0.1.2"
serde = {version = "1.0.118", features = ["derive"]}
serde_json = "1.0.61"
serde_regex = "1.1.0"
swc_atoms = {version = "0.2", path = "../../atoms"}
swc_common = {version = "0.10.8", path = "../../common"}
swc_ecma_ast = {version = "0.45.0", path = "../ast"}
swc_ecma_codegen = {version = "0.55.0", path = "../codegen"}
swc_ecma_transforms = {version = "0.50.0", path = "../transforms/", features = ["optimization"]}
swc_ecma_transforms_base = {version = "0.15.0", path = "../transforms/base"}
swc_ecma_utils = {version = "0.36.0", path = "../utils"}
swc_ecma_visit = {version = "0.31.0", path = "../visit"}

[dev-dependencies]
ansi_term = "0.12.1"
swc_ecma_parser = {version = "0.57.0", path = "../parser"}
testing = {version = "0.10.2", path = "../../testing"}
walkdir = "2.3.1"
7 changes: 7 additions & 0 deletions ecmascript/minifier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Minifier

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

## Copying tests

Replace the content of `terser/test/compress.js` with it of `scripts/compress.js` and run `npm run test:compress`
15 changes: 15 additions & 0 deletions ecmascript/minifier/scripts/add-golden.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
#
# This script automatically add tests to golden.
# Note that this is append-only.
set -eu

cargo test --test compress \
| grep 'js .\.\. ok$' \
| sed -e 's!test fixture_terser__compress__!!' \
| sed -e 's! ... ok!!' \
| sed -e 's!__!/!g' \
| sed -e 's!_js!.js!' \
>> tests/golden.txt

./scripts/sort.sh
12 changes: 12 additions & 0 deletions ecmascript/minifier/scripts/ignore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -eu

cargo test --test compress $1 \
| grep 'js .\.\. FAILED$' \
| sed -e 's!test fixture_terser__compress__!!' \
| sed -e 's! ... FAILED!!' \
| sed -e 's!__!/!g' \
| sed -e 's!_js!.js!' \
>> tests/ignored.txt

./scripts/sort.sh
47 changes: 47 additions & 0 deletions ecmascript/minifier/scripts/jsprops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Run this script to build jsprops.json

const fs = require('fs')

// Compatibility fix for some standard defined globals not defined on every js environment
var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
var objects = {};
var global_ref = typeof global === "object" ? global : self;

new_globals.forEach(function (new_global) {
objects[new_global] = global_ref[new_global] || new Function();
});

const addedProps = new Set();

const add = propName => addedProps.add(propName);

[
"null",
"true",
"false",
"NaN",
"Infinity",
"-Infinity",
"undefined",
].forEach(add);
[ Object, Array, Function, Number,
String, Boolean, Error, Math,
Date, RegExp, objects.Symbol, ArrayBuffer,
DataView, decodeURI, decodeURIComponent,
encodeURI, encodeURIComponent, eval, EvalError,
Float32Array, Float64Array, Int8Array, Int16Array,
Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat,
parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError,
objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array,
Uint8ClampedArray, Uint16Array, Uint32Array, URIError,
objects.WeakMap, objects.WeakSet
].forEach((ctor) => {
Object.getOwnPropertyNames(ctor).map(add);
if (ctor.prototype) {
Object.getOwnPropertyNames(ctor.prototype).map(add);
}
});

const propsJSON = JSON.stringify([...addedProps].sort(), null, 4)

fs.writeFileSync(__dirname + '/../src/lists/jsprops.json', propsJSON)
22 changes: 22 additions & 0 deletions ecmascript/minifier/scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# This script exists to prevent regression.
#
# This script invoked tests two time.
# For first, it runs tests in no-regression mode.
# In the mode, only tests listed in tests/golden.txt will be tested.
#
# For second invokation, arguments are passed to cargo test so the user can
# filter tests.
#
set -eu

if [ -z "$@" ]; then
./scripts/sort.sh

export RUST_LOG=swc_ecma_minifier=trace

GOLDEN_ONLY=1 cargo test --test compress
fi

cargo test --test compress $@
11 changes: 11 additions & 0 deletions ecmascript/minifier/scripts/sort.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -eu

# Fix sorting differences between Linux and Mac
export LC_ALL=C

cat tests/golden.txt | awk NF | sort | uniq | awk '{$1=$1};1' | uniq | sort > tests/golden_sorted.txt
mv tests/golden_sorted.txt tests/golden.txt

cat tests/ignored.txt | awk NF | sort | uniq | awk '{$1=$1};1' | uniq | sort > tests/ignored_sorted.txt
mv tests/ignored_sorted.txt tests/ignored.txt
Loading