2016-12-23 22:31:38 +03:00
|
|
|
exports[`test delegate_yield.js 1`] = `
|
|
|
|
"async function *delegate_next() {
|
|
|
|
async function *inner() {
|
|
|
|
var x: void = yield; // error: number ~> void
|
|
|
|
}
|
|
|
|
yield *inner();
|
|
|
|
}
|
|
|
|
delegate_next().next(0);
|
|
|
|
|
|
|
|
async function *delegate_yield() {
|
|
|
|
async function *inner() {
|
|
|
|
yield 0;
|
|
|
|
}
|
|
|
|
yield *inner();
|
|
|
|
}
|
|
|
|
(async () => {
|
|
|
|
for await (const x of delegate_yield()) {
|
|
|
|
(x: void); // error: number ~> void
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
async function *delegate_return() {
|
|
|
|
async function *inner() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
var x: void = yield *inner(); // error: number ~> void
|
|
|
|
}
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
async function* delegate_next() {
|
|
|
|
async function* inner() {
|
2017-01-10 05:49:06 +03:00
|
|
|
var x: void = yield; // error: number ~> void
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
yield* inner();
|
|
|
|
}
|
2016-12-28 05:40:04 +03:00
|
|
|
delegate_next().next(0);
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
async function* delegate_yield() {
|
|
|
|
async function* inner() {
|
2016-12-28 05:40:04 +03:00
|
|
|
yield 0;
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
yield* inner();
|
|
|
|
}
|
|
|
|
async () => {
|
|
|
|
for await (const x of delegate_yield()) {
|
2017-01-10 05:49:06 +03:00
|
|
|
(x: void); // error: number ~> void
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
};
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
async function* delegate_return() {
|
|
|
|
async function* inner() {
|
2016-12-28 05:40:04 +03:00
|
|
|
return 0;
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
var x: void = yield* inner(); // error: number ~> void
|
2017-01-11 18:16:38 +03:00
|
|
|
}
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test generator.js 1`] = `
|
|
|
|
"declare interface File {
|
|
|
|
readLine(): Promise<string>;
|
|
|
|
close(): void;
|
|
|
|
EOF: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
declare function fileOpen(path: string): Promise<File>;
|
|
|
|
|
|
|
|
async function* readLines(path) {
|
|
|
|
let file: File = await fileOpen(path);
|
|
|
|
|
|
|
|
try {
|
|
|
|
while (!file.EOF) {
|
|
|
|
yield await file.readLine();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function f() {
|
2016-12-30 22:10:52 +03:00
|
|
|
for await (const line of readLines(\"/path/to/file\")) {
|
2016-12-23 22:31:38 +03:00
|
|
|
(line: void); // error: string ~> void
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2017-01-14 07:15:30 +03:00
|
|
|
interface File { readLine(): Promise<string>, close(): void, EOF: boolean }
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
declare function fileOpen(path: string): Promise<File>;
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
async function* readLines(path) {
|
|
|
|
let file: File = await fileOpen(path);
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
try {
|
|
|
|
while (!file.EOF) {
|
|
|
|
yield await file.readLine();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
async function f() {
|
2016-12-30 22:10:52 +03:00
|
|
|
for await (const line of readLines(\"/path/to/file\")) {
|
2017-01-10 05:49:06 +03:00
|
|
|
(line: void); // error: string ~> void
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-11 18:16:38 +03:00
|
|
|
}
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test return.js 1`] = `
|
|
|
|
"declare var gen: AsyncGenerator<void,string,void>;
|
|
|
|
|
2016-12-30 22:10:52 +03:00
|
|
|
// You can pass whatever you like to return, it doesn\'t need to be related to
|
|
|
|
// the AsyncGenerator\'s return type
|
2016-12-23 22:31:38 +03:00
|
|
|
gen.return(0).then(result => {
|
|
|
|
(result.value: void); // error: string | number ~> void
|
|
|
|
});
|
|
|
|
|
2016-12-30 22:10:52 +03:00
|
|
|
// However, a generator can \"refuse\" the return by catching an exception and
|
2016-12-23 22:31:38 +03:00
|
|
|
// yielding or returning internally.
|
|
|
|
async function *refuse_return() {
|
|
|
|
try {
|
|
|
|
yield 1;
|
|
|
|
} finally {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-12-30 22:10:52 +03:00
|
|
|
refuse_return().return(\"string\").then(result => {
|
2016-12-23 22:31:38 +03:00
|
|
|
if (result.done) {
|
|
|
|
(result.value: string); // error: number | void ~> string
|
|
|
|
}
|
|
|
|
});
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2017-01-10 05:49:06 +03:00
|
|
|
declare var gen: AsyncGenerator<void, string, void>;
|
|
|
|
|
2016-12-30 22:10:52 +03:00
|
|
|
// You can pass whatever you like to return, it doesn\'t need to be related to
|
|
|
|
// the AsyncGenerator\'s return type
|
2017-01-04 23:24:10 +03:00
|
|
|
gen.return(0).then(result => {
|
2017-01-10 05:49:06 +03:00
|
|
|
(result.value: void); // error: string | number ~> void
|
2017-01-04 23:24:10 +03:00
|
|
|
});
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// However, a generator can \"refuse\" the return by catching an exception and
|
|
|
|
// yielding or returning internally.
|
2016-12-27 21:29:31 +03:00
|
|
|
async function* refuse_return() {
|
|
|
|
try {
|
2016-12-28 05:40:04 +03:00
|
|
|
yield 1;
|
2016-12-27 21:29:31 +03:00
|
|
|
} finally {
|
2016-12-28 05:40:04 +03:00
|
|
|
return 0;
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-04 23:24:10 +03:00
|
|
|
refuse_return().return(\"string\").then(result => {
|
|
|
|
if (result.done) {
|
2017-01-10 05:49:06 +03:00
|
|
|
(result.value: string); // error: number | void ~> string
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-11 18:16:38 +03:00
|
|
|
});
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test throw.js 1`] = `
|
|
|
|
"async function *catch_return() {
|
|
|
|
try {
|
|
|
|
yield 0;
|
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
2016-12-30 22:10:52 +03:00
|
|
|
catch_return().throw(\"\").then(({value}) => {
|
2016-12-23 22:31:38 +03:00
|
|
|
if (value !== undefined) {
|
|
|
|
(value: void); // error: number ~> void
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
async function *yield_return() {
|
|
|
|
try {
|
|
|
|
yield 0;
|
|
|
|
return;
|
|
|
|
} catch (e) {
|
|
|
|
yield e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
2016-12-30 22:10:52 +03:00
|
|
|
yield_return().throw(\"\").then(({value}) => {
|
2016-12-23 22:31:38 +03:00
|
|
|
if (value !== undefined) {
|
|
|
|
(value: void); // error: number ~> void
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
async function* catch_return() {
|
|
|
|
try {
|
2016-12-28 05:40:04 +03:00
|
|
|
yield 0;
|
2016-12-23 22:31:38 +03:00
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
async () => {
|
2017-01-04 23:24:10 +03:00
|
|
|
catch_return().throw(\"\").then(({ value }) => {
|
|
|
|
if (value !== undefined) {
|
2017-01-10 05:49:06 +03:00
|
|
|
(value: void); // error: number ~> void
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-04 23:24:10 +03:00
|
|
|
});
|
2016-12-23 22:31:38 +03:00
|
|
|
};
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
async function* yield_return() {
|
|
|
|
try {
|
2016-12-28 05:40:04 +03:00
|
|
|
yield 0;
|
2016-12-23 22:31:38 +03:00
|
|
|
return;
|
|
|
|
} catch (e) {
|
|
|
|
yield e;
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
async () => {
|
2017-01-04 23:24:10 +03:00
|
|
|
yield_return().throw(\"\").then(({ value }) => {
|
|
|
|
if (value !== undefined) {
|
2017-01-10 05:49:06 +03:00
|
|
|
(value: void); // error: number ~> void
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-04 23:24:10 +03:00
|
|
|
});
|
2017-01-11 18:16:38 +03:00
|
|
|
};
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|