-
Notifications
You must be signed in to change notification settings - Fork 504
[explicit-resource-management] Add remaining tests specific to using statement syntax #4483
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
Open
rbuckton
wants to merge
5
commits into
tc39:main
Choose a base branch
from
rbuckton:explicit-resource-management-using-syntax
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
57bc079
Add remaining tests specific to using statement syntax
rbuckton 21b5577
Fix incorrect test, esid
rbuckton fc3079a
Add 'for(using of=' test
rbuckton f56e3f7
PR feedback and minor fixes due to banning 'using' in switch case/def…
rbuckton edc68c3
Fix spacing around esid
rbuckton 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
30 changes: 30 additions & 0 deletions
30
...ents/using/syntax/block-scope-syntax-using-declarations-mixed-with-without-initializer.js
This file contains hidden or 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,30 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-and-const-declarations-static-semantics-early-errors | ||
description: > | ||
using declarations mixed: with, without initializer | ||
info: | | ||
Static Semantics : Early Errors | ||
LexicalBinding : BindingIdentifier Initializer? | ||
|
||
- It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing | ||
this LexicalBinding is true. | ||
|
||
Static Semantics : IsConstantDeclaration | ||
UsingDeclaration : | ||
`using` BindingList ; | ||
|
||
1. Return true. | ||
|
||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
{ | ||
using x = null, y; | ||
} |
30 changes: 30 additions & 0 deletions
30
...ents/using/syntax/block-scope-syntax-using-declarations-mixed-without-with-initializer.js
This file contains hidden or 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,30 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-and-const-declarations-static-semantics-early-errors | ||
description: > | ||
using declarations mixed: without, with initializer | ||
info: | | ||
Static Semantics : Early Errors | ||
LexicalBinding : BindingIdentifier Initializer? | ||
|
||
- It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing | ||
this LexicalBinding is true. | ||
|
||
Static Semantics : IsConstantDeclaration | ||
UsingDeclaration : | ||
`using` BindingList ; | ||
|
||
1. Return true. | ||
|
||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
{ | ||
using x, y = null; | ||
} |
30 changes: 30 additions & 0 deletions
30
...uage/statements/using/syntax/block-scope-syntax-using-declarations-without-initializer.js
This file contains hidden or 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,30 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-and-const-declarations-static-semantics-early-errors | ||
description: > | ||
using declarations without initializer | ||
info: | | ||
Static Semantics : Early Errors | ||
LexicalBinding : BindingIdentifier Initializer? | ||
|
||
- It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing | ||
this LexicalBinding is true. | ||
|
||
Static Semantics : IsConstantDeclaration | ||
UsingDeclaration : | ||
`using` BindingList ; | ||
|
||
1. Return true. | ||
|
||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
{ | ||
using x; | ||
} |
19 changes: 19 additions & 0 deletions
19
test/language/statements/using/syntax/using-allowed-at-top-level-of-module.js
This file contains hidden or 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,19 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations-static-semantics-early-errors | ||
description: > | ||
using declarations allowed at the top level of a module | ||
info: | | ||
UsingDeclaration : using BindingList ; | ||
|
||
- It is a Syntax Error if the goal symbol is Script and UsingDeclaration is not contained, either directly or | ||
indirectly, within a Block, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody, | ||
AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or ClassBody. | ||
|
||
flags: [module] | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
using x = null; |
12 changes: 12 additions & 0 deletions
12
test/language/statements/using/syntax/using-allows-bindingidentifier.js
This file contains hidden or 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,12 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
'using' allows BindingIdentifier in lexical bindings | ||
features: [explicit-resource-management] | ||
---*/ | ||
{ | ||
using x = null; | ||
} |
13 changes: 13 additions & 0 deletions
13
test/language/statements/using/syntax/using-allows-multiple-bindings.js
This file contains hidden or 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,13 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
'using' allows multiple lexical bindings | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
{ | ||
using x = null, y = null; | ||
} |
20 changes: 20 additions & 0 deletions
20
test/language/statements/using/syntax/using-declaring-let-split-across-two-lines.js
This file contains hidden or 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,20 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
using: |using let| split across two lines is treated as two statements. | ||
info: | | ||
Lexical declarations may not declare a binding named "let". | ||
flags: [noStrict] | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
{ | ||
using | ||
let = "irrelevant initializer"; | ||
|
||
assert(typeof let === "string"); | ||
var using, let; | ||
} |
14 changes: 14 additions & 0 deletions
14
test/language/statements/using/syntax/using-for-statement.js
This file contains hidden or 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,14 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-for-statement | ||
description: > | ||
using: 'for (using x = ' and 'for (using of =' are interpreted as for loop | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
for (using x = null;;) break; | ||
|
||
// 'using of' lookahead restriction only applies to 'for-of'/'for-await-of'. In 'for' statement it is | ||
// handled similar to `for (let of = null;;)`: | ||
for (using of = null;;) break; |
22 changes: 22 additions & 0 deletions
22
test/language/statements/using/syntax/using-for-using-of-of.js
This file contains hidden or 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) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-for-in-and-for-of-statements | ||
description: > | ||
using: 'for (using of' is always interpreted as identifier | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
var using, of = [[9], [8], [7]], result = []; | ||
for (using of of [0, 1, 2]) { | ||
// ^^^^^ ^^^^^^^^^^^^ | ||
// | | | ||
// | interpreted as element access `of[2]` | ||
// | | ||
// interpreted as identifier named `using` | ||
|
||
result.push(using); | ||
} | ||
|
||
asserts.sameValue(result.length, 1); | ||
asserts.sameValue(result[0], 7); |
18 changes: 18 additions & 0 deletions
18
...uage/statements/using/syntax/using-invalid-arraybindingpattern-after-bindingidentifier.js
This file contains hidden or 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) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
'using' does not allow ArrayBindingPattern in lexical bindings, even after a valid lexical binding | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
{ | ||
using x = null, [] = null; | ||
} |
15 changes: 15 additions & 0 deletions
15
...tatements/using/syntax/using-invalid-arraybindingpattern-does-not-break-element-access.js
This file contains hidden or 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,15 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
'using' does not break existing element access | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
var using = [], x = 0; | ||
|
||
{ | ||
using[x] = null; | ||
} |
18 changes: 18 additions & 0 deletions
18
test/language/statements/using/syntax/using-invalid-arraybindingpattern.js
This file contains hidden or 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) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
'using' does not allow ArrayBindingPattern in lexical bindings | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
{ | ||
using [] = null; | ||
} |
14 changes: 14 additions & 0 deletions
14
test/language/statements/using/syntax/using-invalid-assignment-next-expression-for.js
This file contains hidden or 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,14 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-declarative-environment-records-setmutablebinding-n-v-s | ||
description: > | ||
using: invalid assignment in next expression. Since a `using` declaration introduces an immutable | ||
binding, any attempt to change it results in a ReferenceError. | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.throws(ReferenceError, function() { | ||
for (using i = 0; i < 1; i++) {} | ||
}); |
14 changes: 14 additions & 0 deletions
14
test/language/statements/using/syntax/using-invalid-assignment-statement-body-for-of.js
This file contains hidden or 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,14 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-declarative-environment-records-setmutablebinding-n-v-s | ||
description: > | ||
using: invalid assignment in Statement body. Since a `using` declaration introduces an immutable | ||
binding, any attempt to change it results in a ReferenceError. | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.throws(ReferenceError, function() { | ||
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. Ditto. |
||
for (using x of [1, 2, 3]) { x++ } | ||
}); |
14 changes: 14 additions & 0 deletions
14
test/language/statements/using/syntax/using-invalid-for-in.js
This file contains hidden or 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,14 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-for-in-and-for-of-statements | ||
description: > | ||
using: not allowed in for..in | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
for (using x in [1, 2, 3]) { } |
18 changes: 18 additions & 0 deletions
18
...age/statements/using/syntax/using-invalid-objectbindingpattern-after-bindingidentifier.js
This file contains hidden or 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) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
'using' does not allow ObjectBindingPattern in lexical bindings, even after a valid lexical binding | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
{ | ||
using x = null, {} = null; | ||
} |
18 changes: 18 additions & 0 deletions
18
test/language/statements/using/syntax/using-invalid-objectbindingpattern.js
This file contains hidden or 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) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations | ||
description: > | ||
'using' does not allow ObjectBindingPattern in lexical bindings | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
{ | ||
using {} = null; | ||
} |
20 changes: 20 additions & 0 deletions
20
test/language/statements/using/syntax/using-not-allowed-at-top-level-of-eval.js
This file contains hidden or 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,20 @@ | ||
// Copyright (C) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations-static-semantics-early-errors | ||
description: > | ||
using declarations not allowed at the top level of eval. Note that Eval parses text using the Script goal. | ||
info: | | ||
UsingDeclaration : using BindingList ; | ||
|
||
- It is a Syntax Error if the goal symbol is Script and UsingDeclaration is not contained, either directly or | ||
indirectly, within a Block, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody, | ||
AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or ClassBody. | ||
|
||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
assert.throws(SyntaxError, function() { | ||
eval('using x = null;') | ||
}); |
22 changes: 22 additions & 0 deletions
22
test/language/statements/using/syntax/using-not-allowed-at-top-level-of-script.js
This file contains hidden or 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) 2023 Ron Buckton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-let-const-using-and-await-using-declarations-static-semantics-early-errors | ||
description: > | ||
using declarations not allowed at the top level of a Script | ||
info: | | ||
UsingDeclaration : using BindingList ; | ||
|
||
- It is a Syntax Error if the goal symbol is Script and UsingDeclaration is not contained, either directly or | ||
indirectly, within a Block, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody, | ||
AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or ClassBody. | ||
|
||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
using x = null; |
Oops, something went wrong.
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.
Same question about ReferenceError vs TypeError as in the
await using
PR.