Skip to content

Commit

Permalink
chore: address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Aug 2, 2019
1 parent 3b89774 commit 7081b52
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 60 deletions.

This file was deleted.

20 changes: 20 additions & 0 deletions test/language/expressions/optional-chaining/call-expression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-OptionalExpression
desc: >
optional chain on call expression
info: |
Left-Hand-Side Expressions
OptionalExpression:
CallExpression OptionalChain
features: [optional-chaining]
---*/

function fn () {
return {a: 33};
};

// CallExpression Arguments
assert.sameValue(33, fn()?.a);
assert.sameValue(undefined, fn()?.b);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-OptionalExpression
desc: >
template string passed to tail position of optional chain
info: |
Static Semantics: Early Errors
OptionalChain:
?.TemplateLiteral
OptionalChain TemplateLiteral
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
---*/

$DONOTEVALUATE();

const a = {fn() {}};

// This production exists in order to prevent automatic semicolon
// insertion rules.
a?.fn
`hello`
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
info: |
esid: prod-OptionalExpression
desc: >
template string passed to tail position of optional chain
description: >
info: |
Static Semantics: Early Errors
OptionalChain:
?.TemplateLiteral
Expand All @@ -17,5 +19,6 @@ $DONOTEVALUATE();

const a = {fn() {}};

a?.fn
`hello`;
// This production exists in order to prevent automatic semicolon
// insertion rules.
a?.fn`hello`;
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
info: |
esid: prod-OptionalExpression
desc: >
optional chain on member expression
description: >
info: |
Left-Hand-Side Expressions
OptionalExpression:
MemberExpression OptionalChain
features: [optional-chaining]
---*/

// PrimaryExpression
// IdentifierReference

const arr = [10, 11];
const fn = (arg1, arg2) => {
return arg1 + arg2;
Expand Down

This file was deleted.

27 changes: 27 additions & 0 deletions test/language/expressions/optional-chaining/optional-expression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-OptionalExpression
desc: >
optional chain on recursive optional expression
info: |
Left-Hand-Side Expressions
OptionalExpression:
OptionalExpression OptionalChain
features: [optional-chaining]
---*/

const obj = {
a: {
b: 22
}
};

function fn () {
return {};
}

// MemberExpression
assert.sameValue(22, (obj?.a)?.b);
// CallExpression
assert.sameValue(undefined, (fn()?.a)?.b);
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
info: |
esid: prod-OptionalExpression
desc: >
ternary operation with decimal does not evaluate as optional chain
description: >
info: |
Punctuators
OptionalChainingPunctuator::
?.[lookahead ∉ DecimalDigit]
features: [optional-chaining]
---*/

const value = true ?.30 : false
assert.sameValue(.30, value)
const value = true ?.30 : false;
assert.sameValue(.30, value);
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
info: |
esid: prod-OptionalExpression
desc: >
accessing optional value on undefined or null returns undefined.
description: >
info: |
If baseValue is undefined or null, then
Return undefined.
features: [optional-chaining]
Expand All @@ -12,3 +14,5 @@ const nul = null;
const undf = undefined;
assert.sameValue(undefined, nul?.a);
assert.sameValue(undefined, undf?.b);
assert.sameValue(undefined, null?.a);
assert.sameValue(undefined, undefined?.b);
12 changes: 9 additions & 3 deletions test/language/expressions/optional-chaining/short-circuiting.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
esid: prod-OptionalExpression
desc: >
demonstrate syntax-based short-circuiting.
info: |
If the expression on the LHS of ?. evaluates to null/undefined, the RHS is
not evaluated
description: >
demonstrate syntax-based short-circuiting.
features: [optional-chaining]
---*/

const a = undefined;
let x = 1;

a?.[++x] // short-circuiting.
a?.b.c(++x).d; // long short-circuiting.

undefined?.[++x] // short-circuiting.
undefined?.b.c(++x).d; // long short-circuiting.

assert.sameValue(1, x);
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

// Copyright 2019 Google, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
info: |
esid: prod-OptionalExpression
desc: >
an optional expression cannot be target of assignment
description: >
info: |
Static Semantics: IsValidSimpleAssignmentTarget
LeftHandSideExpression:
OptionalExpression
Expand Down

0 comments on commit 7081b52

Please sign in to comment.