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

test(es/typescript): Migrate inline tests to fixture tests #6546

Merged
merged 20 commits into from Nov 30, 2022
8 changes: 4 additions & 4 deletions .github/workflows/CI.yml
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
pull_request:
types: ['opened', 'reopened', 'synchronize']
types: ["opened", "reopened", "synchronize"]
push:
branches:
- main
Expand Down Expand Up @@ -170,7 +170,7 @@ jobs:
run: |
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update
cd bindings && cargo upgrade --workspace swc_core && cargo update

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
Expand Down Expand Up @@ -733,7 +733,7 @@ jobs:
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update
cd bindings && cargo upgrade --workspace swc_core && cargo update

- name: Cache
uses: actions/cache@v3
Expand Down Expand Up @@ -795,7 +795,7 @@ jobs:
run: |
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
cd bindings && cargo update
cd bindings && cargo upgrade --workspace swc_core && cargo update

- name: Prepare
run: |
Expand Down
@@ -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