-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for "Class Static Init. Blocks" proposal #2968
Merged
rwaldron
merged 7 commits into
tc39:main
from
bocoup:class-static-initialization-blocks
Jul 15, 2021
+1,582
−0
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff9be07
Add tests for "Class Static Init. Blocks" proposal
jugglinmike 6d97fc4
fixup! Add tests for "Class Static Init. Blocks" proposal
jugglinmike 3495b43
Merge branch 'main' into class-static-initialization-blocks
jugglinmike c2559d9
Correct identifier reference
jugglinmike fd6af5c
Update tests for grammar
jugglinmike c015c57
Update tests for identifiers
jugglinmike a502d69
Add tests for scope derivation
jugglinmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/language/expressions/arrow-function/static-init-await-binding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is disallowed in the BindingIdentifier position | ||
features: [class-static-block] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
class C { | ||
static { | ||
(await => 0); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/language/expressions/arrow-function/static-init-await-reference.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is disallowed in the IdentifierReference position | ||
features: [class-static-block] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
class C { | ||
static { | ||
((x = await) => 0); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
test/language/expressions/class/static-init-await-binding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is disallowed as a BindingIdentifier | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
class C { | ||
static { | ||
(class await {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be allowed if the intention is that class static blocks are like async function bodies for the purposes of [Await].
|
||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/language/expressions/class/static-init-await-reference.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as a IdentifierReference in method parameter lists | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
var await = 0; | ||
var fromParam, fromBody; | ||
|
||
class C { | ||
static { | ||
new (class { | ||
constructor(x = fromParam = await) { | ||
fromBody = await; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
assert.sameValue(fromParam, 0, 'from parameter'); | ||
assert.sameValue(fromBody, 0, 'from body'); |
18 changes: 18 additions & 0 deletions
18
test/language/expressions/function/static-init-await-binding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an IdentifierReference within function expressions | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
class C { | ||
static { | ||
(function await(await) {}); | ||
rwaldron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
test/language/expressions/function/static-init-await-reference.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an IdentifierReference within function expressions | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
var await = 0; | ||
var fromParam, fromBody; | ||
|
||
class C { | ||
static { | ||
(function (x = fromParam = await) { | ||
fromBody = await; | ||
})(); | ||
} | ||
} | ||
|
||
assert.sameValue(fromParam, 0, 'from parameter'); | ||
assert.sameValue(fromBody, 0, 'from body'); |
18 changes: 18 additions & 0 deletions
18
test/language/expressions/generators/static-init-await-binding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an Identifier within generator function expressions | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
class C { | ||
static { | ||
(function * await (await) {}); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
test/language/expressions/generators/static-init-await-reference.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an Identifier within generator function expressions | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
var await = 0; | ||
var fromParam, fromBody; | ||
|
||
class C { | ||
static { | ||
(function * (x = fromParam = await) { | ||
fromBody = await; | ||
})().next(); | ||
} | ||
} | ||
|
||
assert.sameValue(fromParam, 0, 'from parameter'); | ||
assert.sameValue(fromBody, 0, 'from body'); |
22 changes: 22 additions & 0 deletions
22
test/language/expressions/object/ident-name-prop-name-literal-await-static-init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The restriction on `await` does not apply to IdentifierName | ||
info: | | ||
BindingIdentifier : Identifier | ||
|
||
[...] | ||
- It is a Syntax Error if the code matched by this production is nested, | ||
directly or indirectly (but not crossing function or static initialization | ||
block boundaries), within a ClassStaticBlock and the StringValue of | ||
Identifier is "await". | ||
features: [class-static-block] | ||
---*/ | ||
|
||
class C { | ||
static { | ||
({ await: 0 }); | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
test/language/expressions/object/identifier-shorthand-static-init-await-invalid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: IdentifierReference may not be `await` within class static blocks | ||
info: | | ||
IdentifierReference : Identifier | ||
|
||
- It is a Syntax Error if the code matched by this production is nested, | ||
directly or indirectly (but not crossing function or static initialization | ||
block boundaries), within a ClassStaticBlock and the StringValue of | ||
Identifier is "arguments" or "await". | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [class-static-block] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
class C { | ||
static { | ||
({ await }); | ||
} | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
test/language/expressions/object/identifier-shorthand-static-init-await-valid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an identifier within the body of arrow functions | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
class C { | ||
static { | ||
(() => ({ await })); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/language/expressions/object/method-definition/static-init-await-binding-accessor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an identifier within the body of accessor methods | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
class C { | ||
static { | ||
({set accessor(await) {}}); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/language/expressions/object/method-definition/static-init-await-binding-generator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an identifier within the parameter list of generator methods | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
class C { | ||
static { | ||
({*method(await) {}}); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/language/expressions/object/method-definition/static-init-await-binding-normal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an identifier within the parameter list of methods | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
class C { | ||
static { | ||
({method(await) {}}); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/language/expressions/object/method-definition/static-init-await-reference-accessor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an identifier within accessor methods | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
var await = 0; | ||
var fromParam, fromBody; | ||
|
||
class C { | ||
static { | ||
({ | ||
set accessor(x = fromParam = await) { | ||
fromBody = await; | ||
} | ||
}).accessor = undefined; | ||
} | ||
} | ||
|
||
assert.sameValue(fromParam, 0, 'from parameter'); | ||
assert.sameValue(fromBody, 0, 'from body'); |
28 changes: 28 additions & 0 deletions
28
test/language/expressions/object/method-definition/static-init-await-reference-generator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-class-definitions-static-semantics-early-errors | ||
description: The `await` keyword is interpreted as an identifier within generator methods | ||
info: | | ||
ClassStaticBlockBody : ClassStaticBlockStatementList | ||
|
||
[...] | ||
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. | ||
features: [class-static-block] | ||
---*/ | ||
|
||
var await = 0; | ||
var fromParam, fromBody; | ||
|
||
class C { | ||
static { | ||
({ | ||
*method(x = fromParam = await) { | ||
fromBody = await; | ||
} | ||
}).method().next(); | ||
} | ||
} | ||
|
||
assert.sameValue(fromParam, 0, 'from parameter'); | ||
assert.sameValue(fromBody, 0, 'from body'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here and in other arrow function tests,
await
is never allowed as an arrow parameter in async function bodies, so shouldn't here either.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned by @syg,
await
should be disallowed here, per tc39/proposal-class-static-block#46