-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/minifier): Implement minifier partially (#1302)
Co-authored-by: Fábio Santos <[email protected]>
- Loading branch information
1 parent
b6589af
commit c6b22c5
Showing
6,904 changed files
with
65,882 additions
and
47 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"tabWidth": 4, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.