test(es/transforms): Add tests for fixed issues (#5655)

This commit is contained in:
Donny/강동윤 2022-08-29 15:17:16 +09:00 committed by GitHub
parent 51335ebc35
commit 2cddb240c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 196 additions and 0 deletions

View File

@ -0,0 +1,16 @@
function cache(target, key, value) {
return {
get() {
return value;
}
}
}
class Life {
#friends = true;
@cache // remove this and see private class field transpile without errors
get happy() {
return this.#friends;
}
}

View File

@ -0,0 +1,25 @@
{
"test": ".*.ts$",
"sourceMaps": true,
"jsc": {
"loose": true,
"target": "es2020",
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
}
},
"module": {
"type": "commonjs",
"strict": true,
"strictMode": false,
"lazy": false,
"noInterop": false
}
}

View File

@ -0,0 +1,43 @@
class LoggerService {
debug(message: string): void {
console.log({ message });
}
}
export function Logger(): any {
return (target: Record<string, any>, key: string | symbol): void => {
const loggerService: LoggerService = new LoggerService();
const updated: boolean = Reflect.defineProperty(target, key, {
configurable: false,
enumerable: true,
value: loggerService,
writable: false,
});
if (!updated) {
throw new Error(`Unable to define ${String(key)} property for ${JSON.stringify(target)}`);
}
};
}
class TestClass1 {
@Logger() private readonly logger: LoggerService;
test(): void {
this.logger.debug('test1');
}
}
class TestClass2 {
@Logger() private readonly logger: LoggerService;
test(): void {
this.logger.debug('test2');
}
}
(async (): Promise<void> => {
new TestClass1().test();
new TestClass2().test();
console.log('OK');
})();

View File

@ -0,0 +1,7 @@
//a.ts
import { Foo } from "./b";
// import type { Foo } from "./b"; has the same behavior
const Foo = "hey";
// b.ts
export type Foo = string;

View File

@ -0,0 +1,2 @@
const module = 'left-pad'
module

View File

@ -0,0 +1,10 @@
console.log([
...(function* () {
for (const i of [1, 2, 3]) {
Promise.resolve().then(() => {
console.log(`async: ${i}`);
});
yield i;
}
})(),
]);

View File

@ -0,0 +1,26 @@
const obj = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
}
const wait = n => new Promise(r => setTimeout(r, n))
const action = async () => {
for (let i in obj) {
// halt for a second
await wait(1000)
// this one is trouble
wait(1000).then(() => console.log(i))
}
console.log('done')
}
await action()

View File

@ -0,0 +1 @@
const r = n => { return true ? (true) : t => { } }

View File

@ -0,0 +1,12 @@
export enum THEME_SETTINGS_MODE {
default = "default",
dark = "dark"
}
export enum THEME_SETTINGS_MAP {
normal = THEME_SETTINGS_MODE.default,
fancy = THEME_SETTINGS_MODE.dark
}
console.log(THEME_SETTINGS_MAP.normal)
expect(THEME_SETTINGS_MAP.normal).toEqual('default')

View File

@ -0,0 +1 @@
Promise.all<<T>() => void>([]);

View File

@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "ecmascript",
"decorators": true
}
}
}

View File

@ -0,0 +1,4 @@
export class MyClass {
@MyDecorator()
export = true;
}

View File

@ -0,0 +1,18 @@
{
"jsc": {
"target": "es5",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": false,
"decoratorMetadata": true
}
},
"sourceMaps": true,
"module": {
"type": "commonjs"
}
}

View File

@ -0,0 +1,12 @@
const t = {
1: 'a',
2: 'b'
}
function g(arg) {
if (t[arg] === undefined) {
var arg = 2
}
return t[arg]
}
console.log(g(1))

View File

@ -0,0 +1,10 @@
function Decorator() { }
class User {
@Decorator()
property: import("./Test").Test
}
// Test.ts
export class Test { }