Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
951b38d
preset-env
kdy1 Dec 23, 2019
8f8ab87
WIP: corejs3
kdy1 Dec 24, 2019
418e4de
WIP: Corejs 3
kdy1 Dec 24, 2019
65e69ac
Corejs 3 usage data
kdy1 Dec 24, 2019
e7cff33
WIP: corejs 3
kdy1 Dec 24, 2019
f1cfc20
Version now implements copy
kdy1 Dec 25, 2019
a352469
impl Deserialize for Version
kdy1 Dec 25, 2019
c01fd61
WIP: DataMapExt
kdy1 Dec 25, 2019
380adb5
corejs2: Migrate to datamap
kdy1 Dec 25, 2019
b473702
WIP: corejs-compat
kdy1 Dec 25, 2019
95be9d9
WIP: corejs-compat
kdy1 Dec 25, 2019
386fcd7
BrowserData.opera_mobile
kdy1 Dec 25, 2019
6eac1a6
lint
kdy1 Dec 25, 2019
2f44311
should_enable
kdy1 Dec 25, 2019
b3a8a8d
Fix should_enable
kdy1 Dec 25, 2019
2d9f012
Update a ref
kdy1 Dec 25, 2019
f820a37
corejs3::UsageVisitor is almost done
kdy1 Dec 25, 2019
06351d4
visit_object_pat_props
kdy1 Dec 25, 2019
4166796
MemberExpr
kdy1 Dec 25, 2019
5c255fb
Update a ref
kdy1 Dec 25, 2019
6dc3e46
Ignore tests starting with .
kdy1 Dec 25, 2019
512c0bf
Update a ref
kdy1 Dec 25, 2019
acce8d7
Ignore a test
kdy1 Dec 25, 2019
8235f7d
Ignore a test
kdy1 Dec 25, 2019
4cf9895
Ignore tests containing .
kdy1 Dec 25, 2019
9e53208
Ignore tests related to regenerator
kdy1 Dec 25, 2019
4efccd1
Ignore a test
kdy1 Dec 25, 2019
c25320c
Lit::Str
kdy1 Dec 25, 2019
f5322d6
Ignore a test
kdy1 Dec 25, 2019
52d91ba
@babel/polyfill -> @swc/polyfill
kdy1 Dec 25, 2019
f3cc28c
Ignore tests related to inlining
kdy1 Dec 25, 2019
5d78060
Ignore a test
kdy1 Dec 25, 2019
29966ee
Ignore a test
kdy1 Dec 25, 2019
8677d20
corejs3::UsageVisitor: use shipped_proposal
kdy1 Dec 25, 2019
228eec0
Ignore a test
kdy1 Dec 25, 2019
1e13787
Detect instance methods like padEnd / padStart
kdy1 Dec 25, 2019
d0d9ef4
Object is optional
kdy1 Dec 25, 2019
8ff07b0
dynamic import
kdy1 Dec 25, 2019
b3a3b4c
Mark as ignore instead of removing from list of tests
kdy1 Dec 25, 2019
26f2a48
core-js@3: entries.json
kdy1 Dec 25, 2019
3f5ab38
Use entry plugin
kdy1 Dec 25, 2019
4166bc5
Move CORE_JS_COMPAT_DATA
kdy1 Dec 25, 2019
7b047ab
add
kdy1 Dec 25, 2019
3f3df0c
WIP
kdy1 Dec 25, 2019
7b9ab56
Remove benchmark
kdy1 Dec 26, 2019
3ffa039
Use HashSet instead of vector
kdy1 Dec 26, 2019
007d3ee
Entry.target
kdy1 Dec 26, 2019
a019761
Use `Version` instead of usize for corejs
kdy1 Dec 26, 2019
6488c55
Fix
kdy1 Dec 26, 2019
c2795da
Fix core js parsing
kdy1 Dec 26, 2019
cdff8e4
Remove codes like `import 'corejs/stable'`
kdy1 Dec 26, 2019
c821079
core-js@3: usage: replace import only if specifiers is none
kdy1 Dec 26, 2019
4f286ca
regenerator
kdy1 Dec 26, 2019
a62e34d
Remove regenerator on entry
kdy1 Dec 26, 2019
95a935e
Rename
kdy1 Dec 26, 2019
a2e3bc3
Remove Config.regenerator
kdy1 Dec 26, 2019
70bf4a1
mobile to desktop
kdy1 Dec 26, 2019
653aea5
browserslist
kdy1 Dec 26, 2019
01f0e92
Verify that all browser data is parsed
kdy1 Dec 26, 2019
00c607e
Remap browserdata
kdy1 Dec 26, 2019
d6bcad1
Ignore a test
kdy1 Dec 26, 2019
deaff75
Ignore a test
kdy1 Dec 26, 2019
8e2d44f
Update a test reference
kdy1 Dec 26, 2019
7991a55
Regenerator
kdy1 Dec 26, 2019
ff9ffe8
Update tests
kdy1 Dec 26, 2019
8608bd1
core-js3: entry plugin is done
kdy1 Dec 26, 2019
d165739
WIP: core-js@2: entry
kdy1 Dec 26, 2019
9747b50
core-js@2: entry: default
kdy1 Dec 26, 2019
0f5e115
core-js@2: entry: regenerator
kdy1 Dec 26, 2019
61d5cc2
core-js@2
kdy1 Dec 26, 2019
3a2941c
Invoke browserslist
kdy1 Dec 26, 2019
96a5842
query
kdy1 Dec 26, 2019
3eb4c3e
Parse versions
kdy1 Dec 27, 2019
736fba7
Remove useless query.js
kdy1 Dec 27, 2019
7b904d4
Use is_any_target
kdy1 Dec 27, 2019
35285b4
query.js
kdy1 Dec 27, 2019
2cd74a5
impl traits for Query
kdy1 Dec 27, 2019
325bc56
require
kdy1 Dec 27, 2019
5e844c6
mobileToDesktop
kdy1 Dec 27, 2019
0dcbb50
Ignore some tests
kdy1 Dec 27, 2019
873f584
include / exclude: FeatureOrModule
kdy1 Dec 27, 2019
1f5c0ff
include / exclude
kdy1 Dec 27, 2019
b6b7f2f
Fix
kdy1 Dec 27, 2019
1aca0eb
Fix
kdy1 Dec 27, 2019
b7892ae
Ignore tests
kdy1 Dec 27, 2019
824158e
WIP
kdy1 Dec 27, 2019
fa0f0ae
Remove logging
kdy1 Dec 27, 2019
f34fd6e
Ignore a test
kdy1 Dec 27, 2019
8475ff4
Ignore a test
kdy1 Dec 27, 2019
f7be50a
Ignore a test
kdy1 Dec 27, 2019
6c14426
r# ident
kdy1 Dec 27, 2019
e1673dd
Detailed error message
kdy1 Dec 27, 2019
ad0f928
Update a test reference
kdy1 Dec 27, 2019
b21ec89
Ignore a test
kdy1 Dec 27, 2019
3008d95
Ignore a test
kdy1 Dec 27, 2019
cde7fb5
Ignore a module test
kdy1 Dec 27, 2019
f1adbcc
Ignore a test
kdy1 Dec 27, 2019
5f4e626
Ignore a module test
kdy1 Dec 27, 2019
017d7d6
ObjectPattern visitor for core-js@2
kdy1 Dec 27, 2019
b796501
Ignore a test
kdy1 Dec 27, 2019
d877df7
Fix CallExpr visitor
kdy1 Dec 27, 2019
5bd5fba
Ignore a test
kdy1 Dec 27, 2019
986d537
Ignore a module test
kdy1 Dec 27, 2019
35bc250
Ignore a test
kdy1 Dec 27, 2019
1106696
Update readme
kdy1 Dec 27, 2019
f99cc25
lint
kdy1 Dec 27, 2019
96988fa
chain!
kdy1 Dec 27, 2019
6ab14a1
Fix a test
kdy1 Dec 27, 2019
cc64e23
debug
kdy1 Dec 27, 2019
40ca49e
WIP: Adding tests for preset-env
kdy1 Dec 27, 2019
30ec2a9
rename
kdy1 Dec 27, 2019
5251ec1
Add query test
kdy1 Dec 27, 2019
97d197e
Emit helpful error message
kdy1 Dec 27, 2019
154019d
Reorder targets
kdy1 Dec 27, 2019
d7a4e78
Embed query.js
kdy1 Dec 27, 2019
fe6af26
lint
kdy1 Dec 27, 2019
25a3e29
Fix query.js
kdy1 Dec 27, 2019
3cdc919
Cache browserslist queries
kdy1 Dec 27, 2019
06e5316
Add env tests
kdy1 Dec 27, 2019
35a2502
Add a test
kdy1 Dec 28, 2019
6600f53
Fix parsing of browser versions
kdy1 Dec 28, 2019
49e52b4
Remove unused tests
kdy1 Dec 28, 2019
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
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ node_modules/

# Flamegraph
*.html
*.svg
*.svg
package-lock.json
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ before_install:
- git submodule update --init --recursive

install:
- npm install browserslist
- cargo test --no-run --color always --all --all-features

script:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ path-clean = "0.1"
lazy_static = "1"
hashbrown = "0.6"
regex = "1"
either = "1"
chashmap = "2.2.2"
sourcemap = "4.1.1 "

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ New generation javascript to old-days javascript.
- react
- [x] jsx

- preset-env
- [x] `entry` with core-js@2/3
- [ ] `usage` with core-js@2/3
It's implemented, but it's not perfect.

# Performance

The lower bound of the speedup compared to babel is **18**. The benchmarks were run on Macbook pro, dual core, 2.3GHz Intel Core i5, 16 GB ram
Expand Down
2 changes: 1 addition & 1 deletion atoms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "swc_atoms"
build = "build.rs"
version = "0.2.0"
version = "0.2.1"
authors = ["강동윤 <[email protected]>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"
Expand Down
2 changes: 1 addition & 1 deletion atoms/scripts/sort.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eu

cat words.txt | awk '{$1=$1};1' | uniq | sort > words_sorted.txt
Expand Down
2 changes: 1 addition & 1 deletion atoms/words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ abstract
any
apply
arguments
arguments
as
async
await
Expand Down Expand Up @@ -620,6 +619,7 @@ infer
instanceof
interface
is
iterator
key
keyof
length
Expand Down
1 change: 1 addition & 0 deletions ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ ast = { package = "swc_ecma_ast", path ="./ast" }
codegen = { package = "swc_ecma_codegen", path ="./codegen" }
parser = { package = "swc_ecma_parser", path ="./parser", features = ["verify"] }
transforms = { package = "swc_ecma_transforms", path ="./transforms" }
preset_env = { package = "swc_ecma_preset_env", path ="preset_env" }

[dev-dependencies]
15 changes: 13 additions & 2 deletions ecmascript/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,11 @@ impl<'a> Emitter<'a> {
}
self.wr.write_str_lit(num.span, "Infinity")?;
} else {
self.wr.write_str_lit(num.span, &format!("{}", num.value))?;
if num.value.is_sign_negative() && num.value == 0.0 {
self.wr.write_str_lit(num.span, "-0.0")?;
} else {
self.wr.write_str_lit(num.span, &format!("{}", num.value))?;
}
}
}

Expand Down Expand Up @@ -481,7 +485,7 @@ impl<'a> Emitter<'a> {
Expr::TsConstAssertion(ref n) => emit!(n),
Expr::TsTypeCast(ref n) => emit!(n),
Expr::OptChain(ref n) => emit!(n),
Expr::Invalid(..) => unimplemented!("emit Expr::Invalid"),
Expr::Invalid(ref n) => emit!(n),
}
}

Expand Down Expand Up @@ -514,6 +518,13 @@ impl<'a> Emitter<'a> {
}
}

#[emitter]
pub fn emit_invalid(&mut self, n: &Invalid) -> Result {
self.emit_leading_comments_of_pos(n.span.lo())?;

self.wr.write_str_lit(n.span, "<invalid>")?;
}

#[emitter]
pub fn emit_call_expr(&mut self, node: &CallExpr) -> Result {
self.emit_leading_comments_of_pos(node.span().lo())?;
Expand Down
30 changes: 30 additions & 0 deletions ecmascript/preset_env/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "swc_ecma_preset_env"
version = "0.1.0"
authors = ["강동윤 <[email protected]>"]
edition = "2018"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
swc_atoms = { path = "../../atoms" }
swc_common = { path = "../../common" }
swc_ecma_ast = { path = "../ast" }
swc_ecma_transforms = { path = "../transforms" }
string_enum = { path = "../../macros/string_enum" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
walkdir = "2"
semver = { version = "0.9.0", features = ["serde"] }
once_cell = "1.2.0"
hashbrown = "0.6"
st-map = "0.1.2"
fxhash = "0.2.1"
chashmap = "2.2"

[dev-dependencies]
swc_ecma_codegen = { path = "../codegen" }
swc_ecma_parser = { path = "../parser", features = ["verify"] }
testing = { path = "../../testing" }
pretty_assertions = "0.6"
85 changes: 85 additions & 0 deletions ecmascript/preset_env/benches/polyfills.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#![feature(test)]
#![feature(specialization)]
#![feature(box_syntax)]

extern crate test;

use swc_common::{FileName, FoldWith};
use swc_ecma_parser::{Parser, Session, SourceFileInput, Syntax};
use swc_ecma_preset_env::{preset_env, Config};
use test::Bencher;

fn run(b: &mut Bencher, src: &str, config: Config) {
b.bytes = src.len() as _;

let _ = ::testing::run_test(false, |cm, handler| {
let fm = cm.new_source_file(FileName::Anon, src.into());

let mut parser = Parser::new(
Session { handler: &handler },
Syntax::default(),
SourceFileInput::from(&*fm),
None,
);
let module = parser
.parse_module()
.map_err(|mut e| {
e.emit();
})
.unwrap();
let mut folder = preset_env(config);

b.iter(|| test::black_box(module.clone().fold_with(&mut folder)));
Ok(())
});
}

#[bench]
fn usage_builtin_type(b: &mut Bencher) {
const SOURCE: &str = r#"
// From a length
var float32 = new Float32Array(2);
float32[0] = 42;
console.log(float32[0]); // 42
console.log(float32.length); // 2
console.log(float32.BYTES_PER_ELEMENT); // 4

// From an array
var arr = new Float32Array([21,31]);
console.log(arr[1]); // 31

// From another TypedArray
var x = new Float32Array([21, 31]);
var y = new Float32Array(x);
console.log(y[0]); // 21

// From an ArrayBuffer
var buffer = new ArrayBuffer(16);
var z = new Float32Array(buffer, 0, 4);

// From an iterable
var iterable = function*(){ yield* [1,2,3]; }();
var float32 = new Float32Array(iterable);
// Float32Array[1, 2, 3]
"#;

run(b, SOURCE, Default::default())
}

#[bench]
fn usage_property(b: &mut Bencher) {
const SOURCE: &str = r#"
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };

const returnedTarget = Object.assign(target, source);

console.log(target);
// expected output: Object { a: 1, b: 4, c: 5 }

console.log(returnedTarget);
// expected output: Object { a: 1, b: 4, c: 5 }
"#;

run(b, SOURCE, Default::default())
}
5 changes: 5 additions & 0 deletions ecmascript/preset_env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"browserslist": "=4.7.3"
}
}
8 changes: 8 additions & 0 deletions ecmascript/preset_env/scripts/corejs-compat-gen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const data = require('core-js-compat/data');

// for (const feature in data) {
// const browserData = data[feature];
//
// }

console.log(JSON.stringify(data))
Loading