Skip to content

Commit

Permalink
test(ts/compat): Migrate inline tests to fixture testing (#6475)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 28, 2022
1 parent 3d58e37 commit cc4646a
Show file tree
Hide file tree
Showing 62 changed files with 389 additions and 618 deletions.
@@ -0,0 +1,5 @@
function test() {
return function () {
return arguments[0];
};
}
@@ -0,0 +1,5 @@
function test() {
return function() {
return arguments[0];
};
}
@@ -0,0 +1,5 @@
function test() {
return (foo) => {
return foo.arguments;
}
}
@@ -0,0 +1,5 @@
function test() {
return function(foo) {
return foo.arguments;
};
}
@@ -0,0 +1,3 @@
function test() {
return () => arguments[0];
}
@@ -0,0 +1,6 @@
function test() {
var _arguments = arguments;
return function() {
return _arguments[0];
};
}
@@ -0,0 +1 @@
let echo = (bar) => bar
3 changes: 3 additions & 0 deletions crates/swc_ecma_transforms_compat/tests/arrow/basic/output.js
@@ -0,0 +1,3 @@
let echo = function(bar) {
return bar;
};
@@ -0,0 +1,3 @@
function foo() {
const a = (a) => new.target
}
@@ -0,0 +1,6 @@
function foo() {
var _newtarget = new.target;
const a = function(a) {
return _newtarget;
};
}
@@ -0,0 +1,3 @@
var a = {
[(() => this)()]: 123
}
@@ -0,0 +1,6 @@
var _this = this;
var a = {
[function() {
return _this;
}()]: 123
};
@@ -0,0 +1 @@
let foo = ({ bar }) => undefined;
@@ -0,0 +1,3 @@
let foo = function({ bar }) {
return undefined;
};
@@ -0,0 +1 @@
var t = () => 5 + 5;
@@ -0,0 +1,3 @@
var t = function() {
return 5 + 5;
};
@@ -0,0 +1 @@
arr.map(x => x * x);
@@ -0,0 +1,3 @@
arr.map(function(x) {
return x * x;
});
@@ -0,0 +1,9 @@
function fn() {
var foo = () => {
return arguments;
};
}

var bar = () => arguments;

var baz = () => () => arguments;
@@ -0,0 +1,15 @@
var _arguments = arguments;
function fn() {
var _arguments = arguments;
var foo = function() {
return _arguments;
};
}
var bar = function() {
return _arguments;
};
var baz = function() {
return function() {
return _arguments;
};
};
@@ -0,0 +1,16 @@
function b() {
var t = x => this.x + x;
}

class Foo extends (function () { }) {
constructor() {
var foo = () => this;

if (true) {
console.log(super(), foo());
} else {
super();
console.log(foo());
}
}
}
@@ -0,0 +1,20 @@
function b() {
var _this = this;
var t = function(x) {
return _this.x + x;
};
}
class Foo extends function() {} {
constructor(){
var _this;
var foo = function() {
return _this;
};
if (true) {
console.log((super(), _this = this), foo());
} else {
super(), _this = this;
console.log(foo());
}
}
}
@@ -0,0 +1,5 @@
const a = () => ({
get this() { this; arguments },
set arguments(a = this) { this; arguments },
get [this]() { this; arguments },
})
@@ -0,0 +1,17 @@
var _this = this;
const a1 = function() {
return {
get this () {
this;
arguments;
},
set arguments (a = this){
this;
arguments;
},
get [_this] () {
this;
arguments;
}
};
};
@@ -0,0 +1 @@
arr.map(i => i + 1);
@@ -0,0 +1,3 @@
arr.map(function(i) {
return i + 1;
});
@@ -0,0 +1 @@
const foo = () => this
@@ -0,0 +1,4 @@
var _this = this;
const foo = function() {
return _this;
};
@@ -0,0 +1,3 @@
const foo = function () {
() => () => () => this
}
@@ -0,0 +1,10 @@
const foo = function() {
var _this = this;
(function() {
return function() {
return function() {
return _this;
};
};
});
};
@@ -0,0 +1 @@
const foo = () => ({ x, ...y }) => y
@@ -0,0 +1,5 @@
const foo = function() {
return function({ x , ...y }) {
return y;
};
};
@@ -0,0 +1,3 @@
export const getBadgeBorderRadius = (text, color) => {
return (text && style) || {}
}
@@ -0,0 +1,3 @@
export const getBadgeBorderRadius = function(text, color) {
return text && style || {};
};
@@ -0,0 +1,7 @@
const a = () => ({
[this](a = this) { this; arguments },
})
const b = () => class {
static [this]() { }
[arguments]() { }
}
@@ -0,0 +1,15 @@
var _this = this;
const a = function() {
return {
[_this] (a = this) {
this;
arguments;
}
};
};
const b = function() {
return class {
static [this]() {}
[arguments]() {}
};
};
@@ -0,0 +1 @@
var t = (i, x) => i * x;
@@ -0,0 +1,3 @@
var t = function(i, x) {
return i * x;
};
@@ -0,0 +1 @@
var t = i => i * 5;
@@ -0,0 +1,3 @@
var t = function(i) {
return i * 5;
};
@@ -0,0 +1 @@
var t = (i) => i * 5;
@@ -0,0 +1,3 @@
var t = function(i) {
return i * 5;
};
@@ -0,0 +1,5 @@
nums.forEach(v => {
if (v % 5 === 0) {
fives.push(v);
}
});
@@ -0,0 +1,5 @@
nums.forEach(function(v) {
if (v % 5 === 0) {
fives.push(v);
}
});
@@ -0,0 +1,3 @@
export const getBadgeBorderRadius = (text = this, color = arguments) => {
return (text && style) || {}
}
@@ -0,0 +1,4 @@
var _this = this, _arguments = arguments;
export const getBadgeBorderRadius = function(text = _this, color = _arguments) {
return text && style || {};
};
@@ -0,0 +1,4 @@
let foo = () => this;
let bar = () => this;
let foo1 = () => arguments;
let bar1 = () => arguments;
13 changes: 13 additions & 0 deletions crates/swc_ecma_transforms_compat/tests/arrow/two-arrow/output.js
@@ -0,0 +1,13 @@
var _this = this, _arguments = arguments;
let foo = function() {
return _this;
};
let bar = function() {
return _this;
};
let foo1 = function() {
return _arguments;
};
let bar1 = function() {
return _arguments;
};

1 comment on commit cc4646a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: cc4646a Previous: 5ff87af Ratio
es/full/bugs-1 427490 ns/iter (± 25483) 350392 ns/iter (± 19448) 1.22
es/full/minify/libraries/antd 2164778769 ns/iter (± 55831870) 1898511211 ns/iter (± 581464156) 1.14
es/full/minify/libraries/d3 455095668 ns/iter (± 37006585) 450979526 ns/iter (± 31006042) 1.01
es/full/minify/libraries/echarts 1834002752 ns/iter (± 56534552) 1601978219 ns/iter (± 28667172) 1.14
es/full/minify/libraries/jquery 120434670 ns/iter (± 3281561) 109828185 ns/iter (± 8901921) 1.10
es/full/minify/libraries/lodash 140268580 ns/iter (± 1341221) 132062228 ns/iter (± 11987289) 1.06
es/full/minify/libraries/moment 72196287 ns/iter (± 1747121) 63197456 ns/iter (± 2657598) 1.14
es/full/minify/libraries/react 24877755 ns/iter (± 672562) 21380738 ns/iter (± 527387) 1.16
es/full/minify/libraries/terser 324432633 ns/iter (± 22916747) 319114361 ns/iter (± 7801194) 1.02
es/full/minify/libraries/three 572280794 ns/iter (± 4147844) 572366211 ns/iter (± 12902778) 1.00
es/full/minify/libraries/typescript 3874189984 ns/iter (± 32924844) 3441050260 ns/iter (± 56977796) 1.13
es/full/minify/libraries/victory 878293545 ns/iter (± 45104561) 835860228 ns/iter (± 18617795) 1.05
es/full/minify/libraries/vue 179530844 ns/iter (± 7878381) 163406160 ns/iter (± 5170809) 1.10
es/full/codegen/es3 41604 ns/iter (± 2580) 33511 ns/iter (± 1034) 1.24
es/full/codegen/es5 39992 ns/iter (± 1763) 33534 ns/iter (± 1548) 1.19
es/full/codegen/es2015 39806 ns/iter (± 2689) 33559 ns/iter (± 472) 1.19
es/full/codegen/es2016 40047 ns/iter (± 1196) 33518 ns/iter (± 454) 1.19
es/full/codegen/es2017 40196 ns/iter (± 1112) 33557 ns/iter (± 1231) 1.20
es/full/codegen/es2018 40634 ns/iter (± 1292) 33591 ns/iter (± 1481) 1.21
es/full/codegen/es2019 40004 ns/iter (± 2293) 33485 ns/iter (± 1177) 1.19
es/full/codegen/es2020 40044 ns/iter (± 1370) 33625 ns/iter (± 1815) 1.19
es/full/all/es3 228574475 ns/iter (± 5720904) 206664286 ns/iter (± 12498926) 1.11
es/full/all/es5 219641587 ns/iter (± 9513814) 191500411 ns/iter (± 8490814) 1.15
es/full/all/es2015 175799988 ns/iter (± 8346251) 149312992 ns/iter (± 8069408) 1.18
es/full/all/es2016 176330961 ns/iter (± 7668247) 146712111 ns/iter (± 8617454) 1.20
es/full/all/es2017 172756372 ns/iter (± 4678786) 144623997 ns/iter (± 6551101) 1.19
es/full/all/es2018 171356401 ns/iter (± 4282540) 161296009 ns/iter (± 12676782) 1.06
es/full/all/es2019 170071991 ns/iter (± 5781264) 162354383 ns/iter (± 14501329) 1.05
es/full/all/es2020 163614586 ns/iter (± 10585798) 143815449 ns/iter (± 8530965) 1.14
es/full/parser 873173 ns/iter (± 28562) 710623 ns/iter (± 36070) 1.23
es/full/base/fixer 31921 ns/iter (± 498) 26710 ns/iter (± 690) 1.20
es/full/base/resolver_and_hygiene 113116 ns/iter (± 4782) 92088 ns/iter (± 3149) 1.23
serialization of ast node 247 ns/iter (± 7) 205 ns/iter (± 4) 1.20
serialization of serde 255 ns/iter (± 9) 213 ns/iter (± 5) 1.20

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.