Skip to content
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 cases for Optional Expressions as DestructuringAssignmentTarget #2270

Merged
merged 2 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ import.meta
WeakRef
FinalizationGroup

# Optional Chaining
# https://github.com/tc39/proposal-optional-chaining
optional-chaining

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-DestructuringAssignmentTarget
desc: >
It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an
ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple
Using Object
(MemberExpression OptionalChain .IdentifierName Initializer)
info: |
Syntax

AssignmentElement : DestructuringAssignmentTarget Initializer_opt
DestructuringAssignmentTarget : LeftHandSideExpression

Static Semantics: Early Errors

OptionalExpression:
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain

OptionalChain:
?. [ Expression ]
?. IdentifierName
?. Arguments
?. TemplateLiteral
OptionalChain [ Expression ]
OptionalChain .IdentifierName
OptionalChain Arguments
OptionalChain TemplateLiteral

DestructuringAssignmentTarget : LeftHandSideExpression

- It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true.

Static Semantics: IsValidSimpleAssignmentTarget

LeftHandSideExpression : OptionalExpression
1. Return false.
features: [optional-chaining]
template: syntax
negative:
phase: parse
type: SyntaxError
---*/

//- setup
$DONOTEVALUATE();
var x = {};
//- elems
[x?.y = 42]
//- vals
[23]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what purpose does [23] serve here?

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-DestructuringAssignmentTarget
desc: >
It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an
ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple
Using Object
(MemberExpression OptionalChain .IdentifierName)
info: |
Syntax

AssignmentElement : DestructuringAssignmentTarget Initializer_opt
DestructuringAssignmentTarget : LeftHandSideExpression

Static Semantics: Early Errors

OptionalExpression:
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain

OptionalChain:
?. [ Expression ]
?. IdentifierName
?. Arguments
?. TemplateLiteral
OptionalChain [ Expression ]
OptionalChain .IdentifierName
OptionalChain Arguments
OptionalChain TemplateLiteral

DestructuringAssignmentTarget : LeftHandSideExpression

- It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true.

Static Semantics: IsValidSimpleAssignmentTarget

LeftHandSideExpression : OptionalExpression
1. Return false.
features: [optional-chaining]
template: syntax
negative:
phase: parse
type: SyntaxError
---*/

//- setup
$DONOTEVALUATE();
var x = {};
//- elems
[x?.y]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ does [x.y] without a RHS evaluate as a destructuring assignment?

I think I would have assumed that this was an [ Expression ]. Would this production work:

const arr = [x?.y, x?.z];

//- vals
[23]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-DestructuringAssignmentTarget
desc: >
It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an
ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple
Using Object
info: |
Syntax

AssignmentElement : DestructuringAssignmentTarget Initializer_opt
DestructuringAssignmentTarget : LeftHandSideExpression

Static Semantics: Early Errors

OptionalExpression:
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain

OptionalChain:
?. [ Expression ]
?. IdentifierName
?. Arguments
?. TemplateLiteral
OptionalChain [ Expression ]
OptionalChain .IdentifierName
OptionalChain Arguments
OptionalChain TemplateLiteral

DestructuringAssignmentTarget : LeftHandSideExpression

- It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true.

Static Semantics: IsValidSimpleAssignmentTarget

LeftHandSideExpression : OptionalExpression
1. Return false.
features: [optional-chaining]
template: syntax
negative:
phase: parse
type: SyntaxError
---*/

//- setup
$DONOTEVALUATE();
//- elems
[{
set y(val) {
throw new Test262Error('The property should not be accessed.');
}
}?.y = 42]
//- vals
[23]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-DestructuringAssignmentTarget
desc: >
It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an
ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple
Using Object
info: |
Syntax

AssignmentElement : DestructuringAssignmentTarget Initializer_opt
DestructuringAssignmentTarget : LeftHandSideExpression

Static Semantics: Early Errors

OptionalExpression:
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain

OptionalChain:
?. [ Expression ]
?. IdentifierName
?. Arguments
?. TemplateLiteral
OptionalChain [ Expression ]
OptionalChain .IdentifierName
OptionalChain Arguments
OptionalChain TemplateLiteral

DestructuringAssignmentTarget : LeftHandSideExpression

- It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true.

Static Semantics: IsValidSimpleAssignmentTarget

LeftHandSideExpression : OptionalExpression
1. Return false.
features: [optional-chaining]
template: syntax
negative:
phase: parse
type: SyntaxError
---*/

//- setup
$DONOTEVALUATE();
//- elems
[{
set y(val) {
throw new Test262Error('The property should not be accessed.');
}
}?.y]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above, probably me failing to read this production properly.

//- vals
[23]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-DestructuringAssignmentTarget
desc: >
It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an
ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple
Using Object
(MemberExpression OptionalChain .IdentifierName Initializer)
info: |
Syntax

AssignmentElement : DestructuringAssignmentTarget Initializer_opt
DestructuringAssignmentTarget : LeftHandSideExpression

Static Semantics: Early Errors

OptionalExpression:
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain

OptionalChain:
?. [ Expression ]
?. IdentifierName
?. Arguments
?. TemplateLiteral
OptionalChain [ Expression ]
OptionalChain .IdentifierName
OptionalChain Arguments
OptionalChain TemplateLiteral

DestructuringAssignmentTarget : LeftHandSideExpression

- It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true.

Static Semantics: IsValidSimpleAssignmentTarget

LeftHandSideExpression : OptionalExpression
1. Return false.
features: [optional-chaining]
template: syntax
negative:
phase: parse
type: SyntaxError
---*/

//- setup
$DONOTEVALUATE();
var y = {};
//- elems
{ x: y?.z = 42 }
//- vals
{ x: 23 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-DestructuringAssignmentTarget
desc: >
It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an
ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple
Using Object
(MemberExpression OptionalChain .IdentifierName)
info: |
Syntax

AssignmentElement : DestructuringAssignmentTarget Initializer_opt
DestructuringAssignmentTarget : LeftHandSideExpression

Static Semantics: Early Errors

OptionalExpression:
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain

OptionalChain:
?. [ Expression ]
?. IdentifierName
?. Arguments
?. TemplateLiteral
OptionalChain [ Expression ]
OptionalChain .IdentifierName
OptionalChain Arguments
OptionalChain TemplateLiteral

DestructuringAssignmentTarget : LeftHandSideExpression

- It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true.

Static Semantics: IsValidSimpleAssignmentTarget

LeftHandSideExpression : OptionalExpression
1. Return false.
features: [optional-chaining]
template: syntax
negative:
phase: parse
type: SyntaxError
---*/

//- setup
$DONOTEVALUATE();
var y = {};
//- elems
{ x: y?.z }
//- vals
{ x: 23 }
Loading