From d16e846ab42e1da1558b8bbc6a28bb76ddae207f Mon Sep 17 00:00:00 2001 From: Andrej Baran Date: Thu, 6 Oct 2016 00:41:22 +0200 Subject: [PATCH] ES8/ES2017 target tests --- src/harness/unittests/commandLineParsing.ts | 2 +- .../convertCompilerOptionsFromJson.ts | 2 +- tests/baselines/reference/es8-async.js | 87 +++++++++++++ tests/baselines/reference/es8-async.symbols | 79 ++++++++++++ tests/baselines/reference/es8-async.types | 121 ++++++++++++++++++ tests/cases/compiler/es8-async.ts | 49 +++++++ 6 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/es8-async.js create mode 100644 tests/baselines/reference/es8-async.symbols create mode 100644 tests/baselines/reference/es8-async.types create mode 100644 tests/cases/compiler/es8-async.ts diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index 028786eef24..42fc242f08e 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -165,7 +165,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es8', 'es2015', 'es2017'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index ba25409a9b4..db3d6cfc102 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -176,7 +176,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es8', 'es2015', 'es2017'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/tests/baselines/reference/es8-async.js b/tests/baselines/reference/es8-async.js new file mode 100644 index 00000000000..3338b1f88a6 --- /dev/null +++ b/tests/baselines/reference/es8-async.js @@ -0,0 +1,87 @@ +//// [es8-async.ts] + +async (): Promise => { + await 0; +} + +async function asyncFunc() { + await 0; +} + +const asycnArrowFunc = async (): Promise => { + await 0; +} + +async function asyncIIFE() { + await 0; + + await (async function(): Promise { + await 1; + })(); + + await (async function asyncNamedFunc(): Promise { + await 1; + })(); + + await (async (): Promise => { + await 1; + })(); +} + +class AsyncClass { + asyncPropFunc = async function(): Promise { + await 2; + } + + asyncPropNamedFunc = async function namedFunc(): Promise { + await 2; + } + + asyncPropArrowFunc = async (): Promise => { + await 2; + } + + async asyncMethod(): Promise { + await 2; + } +} + + +//// [es8-async.js] +async () => { + await 0; +}; +async function asyncFunc() { + await 0; +} +const asycnArrowFunc = async () => { + await 0; +}; +async function asyncIIFE() { + await 0; + await (async function () { + await 1; + })(); + await (async function asyncNamedFunc() { + await 1; + })(); + await (async () => { + await 1; + })(); +} +class AsyncClass { + constructor() { + this.asyncPropFunc = async function () { + await 2; + }; + this.asyncPropNamedFunc = async function namedFunc() { + await 2; + }; + this.asyncPropArrowFunc = async () => { + await 2; + }; + } + async asyncMethod() { + await 2; + } +} diff --git a/tests/baselines/reference/es8-async.symbols b/tests/baselines/reference/es8-async.symbols new file mode 100644 index 00000000000..25a77351aef --- /dev/null +++ b/tests/baselines/reference/es8-async.symbols @@ -0,0 +1,79 @@ +=== tests/cases/compiler/es8-async.ts === + +async (): Promise => { +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 0; +} + +async function asyncFunc() { +>asyncFunc : Symbol(asyncFunc, Decl(es8-async.ts, 3, 1)) + + await 0; +} + +const asycnArrowFunc = async (): Promise => { +>asycnArrowFunc : Symbol(asycnArrowFunc, Decl(es8-async.ts, 9, 5)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 0; +} + +async function asyncIIFE() { +>asyncIIFE : Symbol(asyncIIFE, Decl(es8-async.ts, 11, 1)) + + await 0; + + await (async function(): Promise { +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 1; + })(); + + await (async function asyncNamedFunc(): Promise { +>asyncNamedFunc : Symbol(asyncNamedFunc, Decl(es8-async.ts, 20, 11)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 1; + })(); + + await (async (): Promise => { +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 1; + })(); +} + +class AsyncClass { +>AsyncClass : Symbol(AsyncClass, Decl(es8-async.ts, 27, 1)) + + asyncPropFunc = async function(): Promise { +>asyncPropFunc : Symbol(AsyncClass.asyncPropFunc, Decl(es8-async.ts, 29, 18)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 2; + } + + asyncPropNamedFunc = async function namedFunc(): Promise { +>asyncPropNamedFunc : Symbol(AsyncClass.asyncPropNamedFunc, Decl(es8-async.ts, 32, 5)) +>namedFunc : Symbol(namedFunc, Decl(es8-async.ts, 34, 24)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 2; + } + + asyncPropArrowFunc = async (): Promise => { +>asyncPropArrowFunc : Symbol(AsyncClass.asyncPropArrowFunc, Decl(es8-async.ts, 36, 5)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 2; + } + + async asyncMethod(): Promise { +>asyncMethod : Symbol(AsyncClass.asyncMethod, Decl(es8-async.ts, 40, 5)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + await 2; + } +} + diff --git a/tests/baselines/reference/es8-async.types b/tests/baselines/reference/es8-async.types new file mode 100644 index 00000000000..da0ca063777 --- /dev/null +++ b/tests/baselines/reference/es8-async.types @@ -0,0 +1,121 @@ +=== tests/cases/compiler/es8-async.ts === + +async (): Promise => { +>async (): Promise => { await 0;} : () => Promise +>Promise : Promise + + await 0; +>await 0 : 0 +>0 : 0 +} + +async function asyncFunc() { +>asyncFunc : () => Promise + + await 0; +>await 0 : 0 +>0 : 0 +} + +const asycnArrowFunc = async (): Promise => { +>asycnArrowFunc : () => Promise +>async (): Promise => { await 0;} : () => Promise +>Promise : Promise + + await 0; +>await 0 : 0 +>0 : 0 +} + +async function asyncIIFE() { +>asyncIIFE : () => Promise + + await 0; +>await 0 : 0 +>0 : 0 + + await (async function(): Promise { +>await (async function(): Promise { await 1; })() : void +>(async function(): Promise { await 1; })() : Promise +>(async function(): Promise { await 1; }) : () => Promise +>async function(): Promise { await 1; } : () => Promise +>Promise : Promise + + await 1; +>await 1 : 1 +>1 : 1 + + })(); + + await (async function asyncNamedFunc(): Promise { +>await (async function asyncNamedFunc(): Promise { await 1; })() : void +>(async function asyncNamedFunc(): Promise { await 1; })() : Promise +>(async function asyncNamedFunc(): Promise { await 1; }) : () => Promise +>async function asyncNamedFunc(): Promise { await 1; } : () => Promise +>asyncNamedFunc : () => Promise +>Promise : Promise + + await 1; +>await 1 : 1 +>1 : 1 + + })(); + + await (async (): Promise => { +>await (async (): Promise => { await 1; })() : void +>(async (): Promise => { await 1; })() : Promise +>(async (): Promise => { await 1; }) : () => Promise +>async (): Promise => { await 1; } : () => Promise +>Promise : Promise + + await 1; +>await 1 : 1 +>1 : 1 + + })(); +} + +class AsyncClass { +>AsyncClass : AsyncClass + + asyncPropFunc = async function(): Promise { +>asyncPropFunc : () => Promise +>async function(): Promise { await 2; } : () => Promise +>Promise : Promise + + await 2; +>await 2 : 2 +>2 : 2 + } + + asyncPropNamedFunc = async function namedFunc(): Promise { +>asyncPropNamedFunc : () => Promise +>async function namedFunc(): Promise { await 2; } : () => Promise +>namedFunc : () => Promise +>Promise : Promise + + await 2; +>await 2 : 2 +>2 : 2 + } + + asyncPropArrowFunc = async (): Promise => { +>asyncPropArrowFunc : () => Promise +>async (): Promise => { await 2; } : () => Promise +>Promise : Promise + + await 2; +>await 2 : 2 +>2 : 2 + } + + async asyncMethod(): Promise { +>asyncMethod : () => Promise +>Promise : Promise + + await 2; +>await 2 : 2 +>2 : 2 + } +} + diff --git a/tests/cases/compiler/es8-async.ts b/tests/cases/compiler/es8-async.ts new file mode 100644 index 00000000000..0ceb6e397e5 --- /dev/null +++ b/tests/cases/compiler/es8-async.ts @@ -0,0 +1,49 @@ +// @target: es8 +// @lib: es2017 +// @noEmitHelpers: true + +async (): Promise => { + await 0; +} + +async function asyncFunc() { + await 0; +} + +const asycnArrowFunc = async (): Promise => { + await 0; +} + +async function asyncIIFE() { + await 0; + + await (async function(): Promise { + await 1; + })(); + + await (async function asyncNamedFunc(): Promise { + await 1; + })(); + + await (async (): Promise => { + await 1; + })(); +} + +class AsyncClass { + asyncPropFunc = async function(): Promise { + await 2; + } + + asyncPropNamedFunc = async function namedFunc(): Promise { + await 2; + } + + asyncPropArrowFunc = async (): Promise => { + await 2; + } + + async asyncMethod(): Promise { + await 2; + } +}