From 56a2dba9756626455656a7990e66e392a941674d Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Fri, 2 Aug 2019 17:14:24 -0400 Subject: [PATCH] First set of tests for Top Level Await --- features.txt | 4 + .../await-expr-func-expression.js | 50 +++++++++++++ .../top-level-await/await-expr-regexp.js | 56 ++++++++++++++ .../syntax/await-expr-array-literal.js | 41 ++++++++++ .../syntax/await-expr-dyn-import.js | 41 ++++++++++ .../syntax/await-expr-func-expression.js | 45 +++++++++++ .../syntax/await-expr-identifier.js | 43 +++++++++++ .../syntax/await-expr-literal-number.js | 41 ++++++++++ .../syntax/await-expr-literal-string.js | 41 ++++++++++ .../syntax/await-expr-nested.js | 35 +++++++++ .../top-level-await/syntax/await-expr-null.js | 41 ++++++++++ .../syntax/await-expr-obj-literal.js | 44 +++++++++++ .../syntax/await-expr-regexp.js | 41 ++++++++++ .../syntax/await-expr-template-literal.js | 42 +++++++++++ .../top-level-await/syntax/await-expr-this.js | 41 ++++++++++ .../syntax/block-await-expr.js | 74 +++++++++++++++++++ ...es-not-propagate-to-fn-declaration-body.js | 38 ++++++++++ ...-not-propagate-to-fn-declaration-params.js | 40 ++++++++++ ...arly-does-not-propagate-to-fn-expr-body.js | 30 ++++++++ ...ly-does-not-propagate-to-fn-expr-params.js | 30 ++++++++ .../syntax/early-no-escaped-await.js | 25 +++++++ .../syntax/if-await-expr-boolean.js | 34 +++++++++ .../top-level-await/syntax/try-await-expr.js | 53 +++++++++++++ 23 files changed, 930 insertions(+) create mode 100644 test/language/module-code/top-level-await/await-expr-func-expression.js create mode 100644 test/language/module-code/top-level-await/await-expr-regexp.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-array-literal.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-dyn-import.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-func-expression.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-identifier.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-literal-number.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-literal-string.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-nested.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-null.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-obj-literal.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-regexp.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-template-literal.js create mode 100644 test/language/module-code/top-level-await/syntax/await-expr-this.js create mode 100644 test/language/module-code/top-level-await/syntax/block-await-expr.js create mode 100644 test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-body.js create mode 100644 test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-params.js create mode 100644 test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-body.js create mode 100644 test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-params.js create mode 100644 test/language/module-code/top-level-await/syntax/early-no-escaped-await.js create mode 100644 test/language/module-code/top-level-await/syntax/if-await-expr-boolean.js create mode 100644 test/language/module-code/top-level-await/syntax/try-await-expr.js diff --git a/features.txt b/features.txt index 40ee8f33be..e3e348ad19 100644 --- a/features.txt +++ b/features.txt @@ -137,6 +137,10 @@ FinalizationGroup # https://github.com/tc39/proposal-optional-chaining optional-chaining +# Top Level Await +# https://github.com/tc39/proposal-top-level-await +top-level-await + ## Standard language features # # Language features that have been included in a published version of the diff --git a/test/language/module-code/top-level-await/await-expr-func-expression.js b/test/language/module-code/top-level-await/await-expr-func-expression.js new file mode 100644 index 0000000000..3c2daefeaa --- /dev/null +++ b/test/language/module-code/top-level-await/await-expr-func-expression.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + A function after top level await is an expression and not a hoistable declaration +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + ExpressionStatement[Yield, Await]: + [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] + Expression[+In, ?Yield, ?Await]; + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module, async] +features: [top-level-await] +---*/ + +function fn() { return 1; } +function fn() { return 2; } +await function fn() { return 3; }; + +assert.sameValue(fn(), 2); + +$DONE(); diff --git a/test/language/module-code/top-level-await/await-expr-regexp.js b/test/language/module-code/top-level-await/await-expr-regexp.js new file mode 100644 index 0000000000..34f7debecd --- /dev/null +++ b/test/language/module-code/top-level-await/await-expr-regexp.js @@ -0,0 +1,56 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Verify a RegularExpressionLiteral following an AwaitExpression is + not ambiguous to an Division +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module, async] +features: [top-level-await] +---*/ + +var lol = false; +var x = { + get y() { + lol = true; + } +}; + +var g = 42; + +await /x.y/g; + +if (lol) { + $DONE('It should be a RegExp'); +} else { + $DONE(); +} diff --git a/test/language/module-code/top-level-await/syntax/await-expr-array-literal.js b/test/language/module-code/top-level-await/syntax/await-expr-array-literal.js new file mode 100644 index 0000000000..843413383a --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-array-literal.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression ArrayLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await []; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-dyn-import.js b/test/language/module-code/top-level-await/syntax/await-expr-dyn-import.js new file mode 100644 index 0000000000..8f87b75c17 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-dyn-import.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression ImportCall +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + LeftHandSideExpression[Yield, Await]: + NewExpression[?Yield, ?Await] + CallExpression[?Yield, ?Await] + + CallExpression[Yield, Await]: + ImportCall[?Yield, ?Await] + + ImportCall[Yield, Await]: + import ( AssignmentExpression[+In, ?Yield, ?Await] ) +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await, dynamic-import] +---*/ + +try { + await import('foo'); +} catch (e) { + // Ignore errors, we are just checking if the syntax is valid and + // we should not worry if a module was loaded. +} diff --git a/test/language/module-code/top-level-await/syntax/await-expr-func-expression.js b/test/language/module-code/top-level-await/syntax/await-expr-func-expression.js new file mode 100644 index 0000000000..bdcb8671d3 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-func-expression.js @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression StringLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + ExpressionStatement[Yield, Await]: + [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] + Expression[+In, ?Yield, ?Await]; + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await function() {}; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-identifier.js b/test/language/module-code/top-level-await/syntax/await-expr-identifier.js new file mode 100644 index 0000000000..2b539276c7 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-identifier.js @@ -0,0 +1,43 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression IdentifierReference +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +var foo = 1; + +await foo; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-literal-number.js b/test/language/module-code/top-level-await/syntax/await-expr-literal-number.js new file mode 100644 index 0000000000..ae071aa20f --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-literal-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression NumberLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await 1; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-literal-string.js b/test/language/module-code/top-level-await/syntax/await-expr-literal-string.js new file mode 100644 index 0000000000..5236c681df --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-literal-string.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression StringLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await ''; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-nested.js b/test/language/module-code/top-level-await/syntax/await-expr-nested.js new file mode 100644 index 0000000000..fe2a915750 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-nested.js @@ -0,0 +1,35 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + Nested AwaitExpressions +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + TryStatement[Yield, Await, Return]: + try Block[?Yield, ?Await, ?Return] Catch[?Yield, ?Await, ?Return] + try Block[?Yield, ?Await, ?Return] Finally[?Yield, ?Await, ?Return] + try Block[?Yield, ?Await, ?Return] Catch[?Yield, ?Await, ?Return] Finally[?Yield, ?Await, ?Return] + + ... + + ExpressionStatement[Yield, Await]: + [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] + Expression[+In, ?Yield, ?Await]; + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await await await await await await await await await await await await await await await 'await'; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-null.js b/test/language/module-code/top-level-await/syntax/await-expr-null.js new file mode 100644 index 0000000000..da8f88683c --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-null.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression NullLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await null; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-obj-literal.js b/test/language/module-code/top-level-await/syntax/await-expr-obj-literal.js new file mode 100644 index 0000000000..7b833e6579 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-obj-literal.js @@ -0,0 +1,44 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression ObjectLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +// This syntax helps avoiding the code being parsed as a Block +await { function() {} }; + +// Yes, it's a MethodDefinition... diff --git a/test/language/module-code/top-level-await/syntax/await-expr-regexp.js b/test/language/module-code/top-level-await/syntax/await-expr-regexp.js new file mode 100644 index 0000000000..fc5c3a1e4d --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-regexp.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression RegularExpressionLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await /1/; diff --git a/test/language/module-code/top-level-await/syntax/await-expr-template-literal.js b/test/language/module-code/top-level-await/syntax/await-expr-template-literal.js new file mode 100644 index 0000000000..16abaefa70 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-template-literal.js @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression TemplateLiteral +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await ``; + diff --git a/test/language/module-code/top-level-await/syntax/await-expr-this.js b/test/language/module-code/top-level-await/syntax/await-expr-this.js new file mode 100644 index 0000000000..7766dafaee --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/await-expr-this.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + AwaitExpression this +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] + + ... + + PrimaryExpression[Yield, Await]: + this + IdentifierReference[?Yield, ?Await] + Literal + ArrayLiteral[?Yield, ?Await] + ObjectLiteral[?Yield, ?Await] + FunctionExpression + ClassExpression[?Yield, ?Await] + GeneratorExpression + AsyncFunctionExpression + AsyncGeneratorExpression + RegularExpressionLiteral + TemplateLiteral[?Yield, ?Await, ~Tagged] + CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +await this; diff --git a/test/language/module-code/top-level-await/syntax/block-await-expr.js b/test/language/module-code/top-level-await/syntax/block-await-expr.js new file mode 100644 index 0000000000..8c7b5d5193 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/block-await-expr.js @@ -0,0 +1,74 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. It propagates to the StatementList of a Block +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + StatementListItem[Yield, Await, Return]: + Statement[?Yield, ?Await, ?Return] + Declaration[?Yield, ?Await] + + Statement[Yield, Await, Return]: + BlockStatement[?Yield, ?Await, ?Return] + + BlockStatement[Yield, Await, Return]: + Block[?Yield, ?Await, ?Return] + + Block[Yield, Await, Return]: + { StatementList[?Yield, ?Await, ?Return]_opt } + + ... + + ExpressionStatement[Yield, Await]: + [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] + Expression[+In, ?Yield, ?Await]; + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +{ + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + { + await {}; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} diff --git a/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-body.js b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-body.js new file mode 100644 index 0000000000..e1a0a0cfeb --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-body.js @@ -0,0 +1,38 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + The Await capability does not propagate to the body of a function declaration +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + StatementListItem[Yield, Await, Return]: + Statement[?Yield, ?Await, ?Return] + Declaration[?Yield, ?Await] + + Declaration[Yield, Await]: + HoistableDeclaration[?Yield, ?Await, ~Default] + ClassDeclaration[?Yield, ?Await, ~Default] + LexicalDeclaration[+In, ?Yield, ?Await] + + HoistableDeclaration[Yield, Await, Default]: + FunctionDeclaration[?Yield, ?Await, ?Default] + GeneratorDeclaration[?Yield, ?Await, ?Default] + AsyncFunctionDeclaration[?Yield, ?Await, ?Default] + AsyncGeneratorDeclaration[?Yield, ?Await, ?Default] + + FunctionDeclaration[Yield, Await, Default]: + function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } +negative: + phase: parse + type: SyntaxError +esid: prod-ModuleItem +flags: [module] +features: [top-level-await] +---*/ + +$DONOTEVALUATE(); + +function fn() { await 0; } diff --git a/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-params.js b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-params.js new file mode 100644 index 0000000000..28b6e0ef5d --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-declaration-params.js @@ -0,0 +1,40 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + The Await capability does not propagate to the parameters of a function declaration +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + StatementListItem[Yield, Await, Return]: + Statement[?Yield, ?Await, ?Return] + Declaration[?Yield, ?Await] + + Declaration[Yield, Await]: + HoistableDeclaration[?Yield, ?Await, ~Default] + ClassDeclaration[?Yield, ?Await, ~Default] + LexicalDeclaration[+In, ?Yield, ?Await] + + HoistableDeclaration[Yield, Await, Default]: + FunctionDeclaration[?Yield, ?Await, ?Default] + GeneratorDeclaration[?Yield, ?Await, ?Default] + AsyncFunctionDeclaration[?Yield, ?Await, ?Default] + AsyncGeneratorDeclaration[?Yield, ?Await, ?Default] + + FunctionDeclaration[Yield, Await, Default]: + function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } +negative: + phase: parse + type: SyntaxError +esid: prod-ModuleItem +flags: [module] +features: [top-level-await] +---*/ + +$DONOTEVALUATE(); + +function fn(x = await 1) { + return x; +} diff --git a/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-body.js b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-body.js new file mode 100644 index 0000000000..63aba43da5 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-body.js @@ -0,0 +1,30 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + The Await capability does not propagate to the body of a function expression +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + StatementListItem[Yield, Await, Return]: + Statement[?Yield, ?Await, ?Return] + Declaration[?Yield, ?Await] + + FunctionExpression: + function BindingIdentifier[~Yield, ~Await]_opt ( FormalParameters[~Yield, ~Await] ) + { FunctionBody[~Yield, ~Await] } +negative: + phase: parse + type: SyntaxError +esid: prod-ModuleItem +flags: [module] +features: [top-level-await] +---*/ + +$DONOTEVALUATE(); + +0, function () { + await 1; +}; diff --git a/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-params.js b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-params.js new file mode 100644 index 0000000000..f8690b9fd6 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/early-does-not-propagate-to-fn-expr-params.js @@ -0,0 +1,30 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + The Await capability does not propagate to the parameters of a function expression +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + StatementListItem[Yield, Await, Return]: + Statement[?Yield, ?Await, ?Return] + Declaration[?Yield, ?Await] + + FunctionExpression: + function BindingIdentifier[~Yield, ~Await]_opt ( FormalParameters[~Yield, ~Await] ) + { FunctionBody[~Yield, ~Await] } +negative: + phase: parse + type: SyntaxError +esid: prod-ModuleItem +flags: [module] +features: [top-level-await] +---*/ + +$DONOTEVALUATE(); + +0, function (x = await 1) { + return x; +}; diff --git a/test/language/module-code/top-level-await/syntax/early-no-escaped-await.js b/test/language/module-code/top-level-await/syntax/early-no-escaped-await.js new file mode 100644 index 0000000000..ea9da4432f --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/early-no-escaped-await.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + The await keyword can't be escaped +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] +negative: + phase: parse + type: SyntaxError +esid: prod-ModuleItem +flags: [module] +features: [top-level-await] +---*/ + +$DONOTEVALUATE(); + +\u0061wait 0; diff --git a/test/language/module-code/top-level-await/syntax/if-await-expr-boolean.js b/test/language/module-code/top-level-await/syntax/if-await-expr-boolean.js new file mode 100644 index 0000000000..894c6eafa7 --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/if-await-expr-boolean.js @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. + IfStatement ( AwaitExpression BooleanLiteral ) +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + IfStatement[Yield, Await, Return]: + if(Expression[+In, ?Yield, ?Await])Statement[?Yield, ?Await, ?Return]elseStatement[?Yield, ?Await, ?Return] + if(Expression[+In, ?Yield, ?Await])Statement[?Yield, ?Await, ?Return] + + ... + + ExpressionStatement[Yield, Await]: + [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] + Expression[+In, ?Yield, ?Await]; + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +if (await false) {}; diff --git a/test/language/module-code/top-level-await/syntax/try-await-expr.js b/test/language/module-code/top-level-await/syntax/try-await-expr.js new file mode 100644 index 0000000000..8435bcd91a --- /dev/null +++ b/test/language/module-code/top-level-await/syntax/try-await-expr.js @@ -0,0 +1,53 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Valid syntax for top level await. It propagates to nested blocks + TryStatement with AwaitExpression +info: | + ModuleItem: + StatementListItem[~Yield, +Await, ~Return] + + ... + + TryStatement[Yield, Await, Return]: + try Block[?Yield, ?Await, ?Return] Catch[?Yield, ?Await, ?Return] + try Block[?Yield, ?Await, ?Return] Finally[?Yield, ?Await, ?Return] + try Block[?Yield, ?Await, ?Return] Catch[?Yield, ?Await, ?Return] Finally[?Yield, ?Await, ?Return] + + ... + + ExpressionStatement[Yield, Await]: + [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] + Expression[+In, ?Yield, ?Await]; + + UnaryExpression[Yield, Await] + [+Await]AwaitExpression[?Yield] + + AwaitExpression[Yield]: + await UnaryExpression[?Yield, +Await] +esid: prod-AwaitExpression +flags: [module] +features: [top-level-await] +---*/ + +try { + await 0; +} catch(e) { + await 1; +} + +try { + await 0; +} finally { + await 1; +} + +try { + await 0; +} catch(e) { + await 1; +} finally { + await 2; +}