Skip to content

Commit

Permalink
test(es/typescript): Migrate inline tests to fixture tests (#6546)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 30, 2022
1 parent 25fa080 commit cddbc41
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 164 deletions.
@@ -0,0 +1,3 @@
class Foo {
constructor(public readonly foo) { }
}
@@ -0,0 +1,5 @@
class Foo {
constructor(foo){
this.foo = foo;
}
}
@@ -0,0 +1,5 @@
class Foo {
constructor(readonly foo) {
this.bar = 1;
}
}
@@ -0,0 +1,6 @@
class Foo {
constructor(foo){
this.foo = foo;
this.bar = 1;
}
}
@@ -0,0 +1 @@
export = Foo
@@ -0,0 +1 @@
module.exports = Foo;
@@ -0,0 +1 @@
export import A = B
@@ -0,0 +1 @@
export var A = B;
@@ -0,0 +1,2 @@
import { Types } from 'other';
const a: Types.foo = {};
@@ -0,0 +1 @@
const a = {};
@@ -0,0 +1,2 @@
import { Types } from 'other';
const a: Types = Types.foo;
@@ -0,0 +1,2 @@
import { Types } from 'other';
const a = Types.foo;
@@ -0,0 +1 @@
export type Link = { key: string; text: string };
@@ -0,0 +1,2 @@
type Link = { key: string; text: string };
export { Link }
@@ -0,0 +1,3 @@
type Link = { key: string; text: string };
const Link = 'Boo';
export { Link }
@@ -0,0 +1,2 @@
const Link = 'Boo';
export { Link };
@@ -0,0 +1 @@
function foo(this: any, $scope: angular.IScope) { }
@@ -0,0 +1 @@
function foo($scope) {}
@@ -0,0 +1,23 @@
export function addProp<T, K extends string, V>(
obj: T,
prop: K,
value: V
): T & { [x in K]: V };
export function addProp<T, K extends string, V>(
prop: K,
value: V
): (obj: T) => T & { [x in K]: V };

export function addProp(arg1: any, arg2: any, arg3?: any): any {
if (arguments.length === 2) {
return (object: any) => _addProp(object, arg1, arg2);
}
return _addProp(arg1, arg2, arg3);
}

function _addProp(obj: any, prop: string, value: any) {
return {
...obj,
[prop]: value,
};
}
@@ -0,0 +1,12 @@
export function addProp(arg1, arg2, arg3) {
if (arguments.length === 2) {
return (object)=>_addProp(object, arg1, arg2);
}
return _addProp(arg1, arg2, arg3);
}
function _addProp(obj, prop, value) {
return {
...obj,
[prop]: value
};
}
@@ -0,0 +1,5 @@
class App {
public enter?(): void;
public leave?(): void;
public destroy?(): void;
}
@@ -0,0 +1,2 @@
class App {
}
@@ -0,0 +1,2 @@
function enter(): string;
function enter(foo: string): number;
@@ -0,0 +1,2 @@
import { PlainObject } from 'simplytyped';
const dict: PlainObject = {};
@@ -0,0 +1 @@
const dict = {};
@@ -0,0 +1,7 @@
class test {
#test();
#test() {
}

abstract #test();
}
@@ -0,0 +1,7 @@
var _test = /*#__PURE__*/ new WeakSet();
class test {
constructor(){
_classPrivateMethodInit(this, _test);
}
}
function test1() {}
164 changes: 0 additions & 164 deletions crates/swc_ecma_transforms_typescript/tests/strip.rs
Expand Up @@ -109,172 +109,8 @@ test!(
}"
);

to!(
constructor_01,
"class Foo {
constructor(public readonly foo) {}
}",
"class Foo {
constructor(foo) {
this.foo = foo;
}
}"
);

to!(
constructor_02,
"class Foo {
constructor(readonly foo) {
this.bar = 1;
}
}",
"class Foo {
constructor(foo) {
this.foo = foo;
this.bar = 1;
}
}"
);

to!(
private_method_overload_and_abstract,
"class test {
#test();
#test() {
}
abstract #test();
}",
"var _test = new WeakSet();
class test {
constructor(){
_classPrivateMethodInit(this, _test);
}
}
function test1() {}
"
);

to!(export_import, "export import A = B", "export var A = B;");

to!(export_equals, "export = Foo", "module.exports = Foo;");

to!(
issue_196_01,
"export type Link = { key: string; text: string };",
""
);

to!(
issue_196_02,
"type Link = { key: string; text: string };
export { Link };",
""
);

to!(
issue_196_03,
"type Link = { key: string; text: string };
const Link = 'Boo';
export { Link };",
"const Link = 'Boo';
export { Link };"
);

// TODO: Test function / variable hoisting

to!(
issue_179_01,
"import {Types} from 'other';
const a: Types.foo = {};",
"const a = {};"
);

to!(
issue_179_02,
"import {Types} from 'other';
const a: Types = Types.foo;",
"import {Types} from 'other';
const a = Types.foo;"
);

to!(
issue_236,
"function foo(this: any, $scope: angular.IScope){}",
"function foo($scope){}"
);

to!(
issue_357,
"export function addProp<T, K extends string, V>(
obj: T,
prop: K,
value: V
): T & { [x in K]: V };
export function addProp<T, K extends string, V>(
prop: K,
value: V
): (obj: T) => T & { [x in K]: V };
export function addProp(arg1: any, arg2: any, arg3?: any): any {
if (arguments.length === 2) {
return (object: any) => _addProp(object, arg1, arg2);
}
return _addProp(arg1, arg2, arg3);
}
function _addProp(obj: any, prop: string, value: any) {
return {
...obj,
[prop]: value,
};
}",
"export function addProp(arg1, arg2, arg3) {
if (arguments.length === 2) {
return (object) => _addProp(object, arg1, arg2);
}
return _addProp(arg1, arg2, arg3);
}
function _addProp(obj, prop, value) {
return {
...obj,
[prop]: value,
};
}
"
);

to!(
issue_366_01,
"
class App {
public enter?(): void;
public leave?(): void;
public destroy?(): void;
}",
"class App {}"
);

to!(
issue_366_02,
"
function enter(): string;
function enter(foo: string): number;
",
""
);

to!(
issue_392_1,
"
import { PlainObject } from 'simplytyped';
const dict: PlainObject = {};
",
"
const dict = {};"
);

test!(
::swc_ecma_parser::Syntax::Typescript(Default::default()),
|_| tr(),
Expand Down

1 comment on commit cddbc41

@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: cddbc41 Previous: d730186 Ratio
es/full/bugs-1 357309 ns/iter (± 42612) 345379 ns/iter (± 19869) 1.03
es/full/minify/libraries/antd 2077536687 ns/iter (± 67923863) 2067926065 ns/iter (± 69608197) 1.00
es/full/minify/libraries/d3 473800111 ns/iter (± 22983792) 515100103 ns/iter (± 159883441) 0.92
es/full/minify/libraries/echarts 1783899413 ns/iter (± 67617315) 1727549861 ns/iter (± 35722394) 1.03
es/full/minify/libraries/jquery 119025358 ns/iter (± 5082943) 118750879 ns/iter (± 5371722) 1.00
es/full/minify/libraries/lodash 137572892 ns/iter (± 4873905) 136956724 ns/iter (± 5420934) 1.00
es/full/minify/libraries/moment 65181397 ns/iter (± 2667553) 68490361 ns/iter (± 4232130) 0.95
es/full/minify/libraries/react 21820783 ns/iter (± 854899) 22436171 ns/iter (± 499643) 0.97
es/full/minify/libraries/terser 329186904 ns/iter (± 8615949) 365293069 ns/iter (± 14711338) 0.90
es/full/minify/libraries/three 624939548 ns/iter (± 12800053) 639076054 ns/iter (± 19203904) 0.98
es/full/minify/libraries/typescript 3750427652 ns/iter (± 73500617) 3847128151 ns/iter (± 42332388) 0.97
es/full/minify/libraries/victory 918989931 ns/iter (± 21850076) 925779231 ns/iter (± 22076710) 0.99
es/full/minify/libraries/vue 167528419 ns/iter (± 3932427) 178761656 ns/iter (± 6776693) 0.94
es/full/codegen/es3 34336 ns/iter (± 4164) 33356 ns/iter (± 1373) 1.03
es/full/codegen/es5 34840 ns/iter (± 3295) 33108 ns/iter (± 1359) 1.05
es/full/codegen/es2015 34185 ns/iter (± 2814) 33108 ns/iter (± 3263) 1.03
es/full/codegen/es2016 33920 ns/iter (± 3885) 33009 ns/iter (± 990) 1.03
es/full/codegen/es2017 34273 ns/iter (± 4906) 33031 ns/iter (± 1560) 1.04
es/full/codegen/es2018 34231 ns/iter (± 4051) 33031 ns/iter (± 1007) 1.04
es/full/codegen/es2019 33763 ns/iter (± 2550) 32954 ns/iter (± 830) 1.02
es/full/codegen/es2020 33737 ns/iter (± 1466) 33063 ns/iter (± 672) 1.02
es/full/all/es3 191663114 ns/iter (± 7710674) 195779380 ns/iter (± 10953299) 0.98
es/full/all/es5 187798717 ns/iter (± 11183553) 183610269 ns/iter (± 7889693) 1.02
es/full/all/es2015 151273374 ns/iter (± 12003133) 145884702 ns/iter (± 9063866) 1.04
es/full/all/es2016 146991801 ns/iter (± 6603391) 146264699 ns/iter (± 11150302) 1.00
es/full/all/es2017 144998175 ns/iter (± 6535093) 145117573 ns/iter (± 8081251) 1.00
es/full/all/es2018 138639213 ns/iter (± 4664425) 142505110 ns/iter (± 9325968) 0.97
es/full/all/es2019 138025344 ns/iter (± 4413714) 141478102 ns/iter (± 7693168) 0.98
es/full/all/es2020 139384393 ns/iter (± 6558169) 136921200 ns/iter (± 7734753) 1.02
es/full/parser 744675 ns/iter (± 80722) 718935 ns/iter (± 39841) 1.04
es/full/base/fixer 26915 ns/iter (± 1723) 26086 ns/iter (± 1585) 1.03
es/full/base/resolver_and_hygiene 92901 ns/iter (± 5656) 92031 ns/iter (± 5672) 1.01
serialization of ast node 213 ns/iter (± 17) 205 ns/iter (± 9) 1.04
serialization of serde 229 ns/iter (± 31) 221 ns/iter (± 9) 1.04

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

Please sign in to comment.