Add tests and update baselines
This commit is contained in:
parent
feefd520b6
commit
77d69c8c1d
4 changed files with 273 additions and 0 deletions
92
tests/baselines/reference/correctOrderOfPromiseMethod.js
Normal file
92
tests/baselines/reference/correctOrderOfPromiseMethod.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
//// [correctOrderOfPromiseMethod.ts]
|
||||
interface A {
|
||||
id: string
|
||||
}
|
||||
|
||||
interface B {
|
||||
id: string
|
||||
fieldB: string
|
||||
}
|
||||
|
||||
async function countEverything(): Promise<number> {
|
||||
const providerA = async (): Promise<A[]> => { return [] }
|
||||
const providerB = async (): Promise<B[]> => { return [] }
|
||||
|
||||
const [resultA, resultB] = await Promise.all([
|
||||
providerA(),
|
||||
providerB(),
|
||||
]);
|
||||
|
||||
const dataA: A[] = resultA;
|
||||
const dataB: B[] = resultB;
|
||||
if (dataA && dataB) {
|
||||
return dataA.length + dataB.length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//// [correctOrderOfPromiseMethod.js]
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
function countEverything() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
var providerA, providerB, _a, resultA, resultB, dataA, dataB;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
providerA = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
return [2 /*return*/, []];
|
||||
}); }); };
|
||||
providerB = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
return [2 /*return*/, []];
|
||||
}); }); };
|
||||
return [4 /*yield*/, Promise.all([
|
||||
providerA(),
|
||||
providerB(),
|
||||
])];
|
||||
case 1:
|
||||
_a = _b.sent(), resultA = _a[0], resultB = _a[1];
|
||||
dataA = resultA;
|
||||
dataB = resultB;
|
||||
if (dataA && dataB) {
|
||||
return [2 /*return*/, dataA.length + dataB.length];
|
||||
}
|
||||
return [2 /*return*/, 0];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
=== tests/cases/compiler/correctOrderOfPromiseMethod.ts ===
|
||||
interface A {
|
||||
>A : Symbol(A, Decl(correctOrderOfPromiseMethod.ts, 0, 0))
|
||||
|
||||
id: string
|
||||
>id : Symbol(A.id, Decl(correctOrderOfPromiseMethod.ts, 0, 13))
|
||||
}
|
||||
|
||||
interface B {
|
||||
>B : Symbol(B, Decl(correctOrderOfPromiseMethod.ts, 2, 1))
|
||||
|
||||
id: string
|
||||
>id : Symbol(B.id, Decl(correctOrderOfPromiseMethod.ts, 4, 13))
|
||||
|
||||
fieldB: string
|
||||
>fieldB : Symbol(B.fieldB, Decl(correctOrderOfPromiseMethod.ts, 5, 14))
|
||||
}
|
||||
|
||||
async function countEverything(): Promise<number> {
|
||||
>countEverything : Symbol(countEverything, Decl(correctOrderOfPromiseMethod.ts, 7, 1))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
|
||||
const providerA = async (): Promise<A[]> => { return [] }
|
||||
>providerA : Symbol(providerA, Decl(correctOrderOfPromiseMethod.ts, 10, 9))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>A : Symbol(A, Decl(correctOrderOfPromiseMethod.ts, 0, 0))
|
||||
|
||||
const providerB = async (): Promise<B[]> => { return [] }
|
||||
>providerB : Symbol(providerB, Decl(correctOrderOfPromiseMethod.ts, 11, 9))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>B : Symbol(B, Decl(correctOrderOfPromiseMethod.ts, 2, 1))
|
||||
|
||||
const [resultA, resultB] = await Promise.all([
|
||||
>resultA : Symbol(resultA, Decl(correctOrderOfPromiseMethod.ts, 13, 11))
|
||||
>resultB : Symbol(resultB, Decl(correctOrderOfPromiseMethod.ts, 13, 19))
|
||||
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
|
||||
providerA(),
|
||||
>providerA : Symbol(providerA, Decl(correctOrderOfPromiseMethod.ts, 10, 9))
|
||||
|
||||
providerB(),
|
||||
>providerB : Symbol(providerB, Decl(correctOrderOfPromiseMethod.ts, 11, 9))
|
||||
|
||||
]);
|
||||
|
||||
const dataA: A[] = resultA;
|
||||
>dataA : Symbol(dataA, Decl(correctOrderOfPromiseMethod.ts, 18, 9))
|
||||
>A : Symbol(A, Decl(correctOrderOfPromiseMethod.ts, 0, 0))
|
||||
>resultA : Symbol(resultA, Decl(correctOrderOfPromiseMethod.ts, 13, 11))
|
||||
|
||||
const dataB: B[] = resultB;
|
||||
>dataB : Symbol(dataB, Decl(correctOrderOfPromiseMethod.ts, 19, 9))
|
||||
>B : Symbol(B, Decl(correctOrderOfPromiseMethod.ts, 2, 1))
|
||||
>resultB : Symbol(resultB, Decl(correctOrderOfPromiseMethod.ts, 13, 19))
|
||||
|
||||
if (dataA && dataB) {
|
||||
>dataA : Symbol(dataA, Decl(correctOrderOfPromiseMethod.ts, 18, 9))
|
||||
>dataB : Symbol(dataB, Decl(correctOrderOfPromiseMethod.ts, 19, 9))
|
||||
|
||||
return dataA.length + dataB.length;
|
||||
>dataA.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
|
||||
>dataA : Symbol(dataA, Decl(correctOrderOfPromiseMethod.ts, 18, 9))
|
||||
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
|
||||
>dataB.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
|
||||
>dataB : Symbol(dataB, Decl(correctOrderOfPromiseMethod.ts, 19, 9))
|
||||
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
|
||||
}
|
||||
return 0;
|
||||
}
|
83
tests/baselines/reference/correctOrderOfPromiseMethod.types
Normal file
83
tests/baselines/reference/correctOrderOfPromiseMethod.types
Normal file
|
@ -0,0 +1,83 @@
|
|||
=== tests/cases/compiler/correctOrderOfPromiseMethod.ts ===
|
||||
interface A {
|
||||
>A : A
|
||||
|
||||
id: string
|
||||
>id : string
|
||||
}
|
||||
|
||||
interface B {
|
||||
>B : B
|
||||
|
||||
id: string
|
||||
>id : string
|
||||
|
||||
fieldB: string
|
||||
>fieldB : string
|
||||
}
|
||||
|
||||
async function countEverything(): Promise<number> {
|
||||
>countEverything : () => Promise<number>
|
||||
>Promise : Promise<T>
|
||||
|
||||
const providerA = async (): Promise<A[]> => { return [] }
|
||||
>providerA : () => Promise<A[]>
|
||||
>async (): Promise<A[]> => { return [] } : () => Promise<A[]>
|
||||
>Promise : Promise<T>
|
||||
>A : A
|
||||
>[] : undefined[]
|
||||
|
||||
const providerB = async (): Promise<B[]> => { return [] }
|
||||
>providerB : () => Promise<B[]>
|
||||
>async (): Promise<B[]> => { return [] } : () => Promise<B[]>
|
||||
>Promise : Promise<T>
|
||||
>B : B
|
||||
>[] : undefined[]
|
||||
|
||||
const [resultA, resultB] = await Promise.all([
|
||||
>resultA : A[]
|
||||
>resultB : B[]
|
||||
>await Promise.all([ providerA(), providerB(), ]) : [A[], B[]]
|
||||
>Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]>
|
||||
>Promise.all : { <TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: (T | PromiseLike<T>)[]): Promise<T[]>; }
|
||||
>Promise : PromiseConstructor
|
||||
>all : { <TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: (T | PromiseLike<T>)[]): Promise<T[]>; }
|
||||
>[ providerA(), providerB(), ] : [Promise<A[]>, Promise<B[]>]
|
||||
|
||||
providerA(),
|
||||
>providerA() : Promise<A[]>
|
||||
>providerA : () => Promise<A[]>
|
||||
|
||||
providerB(),
|
||||
>providerB() : Promise<B[]>
|
||||
>providerB : () => Promise<B[]>
|
||||
|
||||
]);
|
||||
|
||||
const dataA: A[] = resultA;
|
||||
>dataA : A[]
|
||||
>A : A
|
||||
>resultA : A[]
|
||||
|
||||
const dataB: B[] = resultB;
|
||||
>dataB : B[]
|
||||
>B : B
|
||||
>resultB : B[]
|
||||
|
||||
if (dataA && dataB) {
|
||||
>dataA && dataB : B[]
|
||||
>dataA : A[]
|
||||
>dataB : B[]
|
||||
|
||||
return dataA.length + dataB.length;
|
||||
>dataA.length + dataB.length : number
|
||||
>dataA.length : number
|
||||
>dataA : A[]
|
||||
>length : number
|
||||
>dataB.length : number
|
||||
>dataB : B[]
|
||||
>length : number
|
||||
}
|
||||
return 0;
|
||||
>0 : 0
|
||||
}
|
27
tests/cases/compiler/correctOrderOfPromiseMethod.ts
Normal file
27
tests/cases/compiler/correctOrderOfPromiseMethod.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
// @lib: dom, es7
|
||||
|
||||
interface A {
|
||||
id: string
|
||||
}
|
||||
|
||||
interface B {
|
||||
id: string
|
||||
fieldB: string
|
||||
}
|
||||
|
||||
async function countEverything(): Promise<number> {
|
||||
const providerA = async (): Promise<A[]> => { return [] }
|
||||
const providerB = async (): Promise<B[]> => { return [] }
|
||||
|
||||
const [resultA, resultB] = await Promise.all([
|
||||
providerA(),
|
||||
providerB(),
|
||||
]);
|
||||
|
||||
const dataA: A[] = resultA;
|
||||
const dataB: B[] = resultB;
|
||||
if (dataA && dataB) {
|
||||
return dataA.length + dataB.length;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue