Coverage: Computed Property Names. Fixes gh-1741

This commit is contained in:
Rick Waldron 2020-09-17 14:13:34 -04:00
parent be7e9ff98b
commit 4ca3c51afd
39 changed files with 926 additions and 0 deletions

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from additive expression "add"
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1 + 1
//- value
2

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from additive expression "subtract"
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1 - 1
//- value
0

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from arrow function
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
() => { }
//- value
1

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from assignment expression
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = 0;
//- ComputedPropertyName
x = 1
//- value
2
//- teardown
assert.sameValue(x, 1);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from assignment expression bitwise or
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = 0;
//- ComputedPropertyName
x |= 1
//- value
2
//- teardown
assert.sameValue(x, 1);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from assignment expression coalesce
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = null;
//- ComputedPropertyName
x ??= 1
//- value
2
//- teardown
assert.sameValue(x, 1);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from assignment expression logical and
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = 0;
//- ComputedPropertyName
x &&= 1
//- value
2
//- teardown
assert.sameValue(x, 0);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from assignment expression logical or
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = 0;
//- ComputedPropertyName
x ||= 1
//- value
2
//- teardown
assert.sameValue(x, 1);

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from function expression
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
async () => {}
//- value
1

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from condition expression
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
false ? 1 : 2
//- value
1

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from condition expression
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
true ? 1 : 2
//- value
2

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from decimal e notational literal
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1.e1
//- value
2

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from decimal literal
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1.1
//- value
2

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from exponentiation expression
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
2 ** 2
//- value
4

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from coalesce
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x;
//- ComputedPropertyName
x ?? 1
//- value
2
//- teardown
assert.sameValue(x, undefined);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from logical and
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = 0;
//- ComputedPropertyName
x && 1
//- value
2
//- teardown
assert.sameValue(x, 0);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from logical or
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = 0;
//- ComputedPropertyName
x || 1
//- value
2
//- teardown
assert.sameValue(x, 0);

View File

@ -0,0 +1,14 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from function
template: evaluation
features: [computed-property-names]
---*/
//- setup
function f() {}
//- ComputedPropertyName
f()
//- value
1

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from function expression
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
function () {}
//- value
1

View File

@ -0,0 +1,14 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from generator function
template: evaluation
features: [computed-property-names]
---*/
//- setup
function * g() { return 1; }
//- ComputedPropertyName
g()
//- value
1

View File

@ -0,0 +1,16 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from string literal
template: evaluation
features: [computed-property-names]
---*/
//- setup
let x = 1;
//- ComputedPropertyName
x
//- value
'2'

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from numeric literal
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1
//- value
2

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from integer with separators
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1_2_3_4_5_6_7_8
//- value
1_2_3_4_5_6_7_8

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from math
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1 + 2 - 3 * 4 / 5 ** 6
//- value
2.999232

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from multiplicative expression "divide"
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1 / 1
//- value
1

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from multiplicative expression "multiply"
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1 * 1
//- value
1

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from numeric literal
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
1
//- value
2

View File

@ -0,0 +1,13 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from string literal
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
'1'
//- value
'2'

View File

@ -0,0 +1,12 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed property name from condition expression
template: evaluation
features: [computed-property-names]
---*/
//- ComputedPropertyName
true ? 1 : 2
//- value
2

View File

@ -0,0 +1,72 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/cpn-accessors-
name: ComputedPropertyName in ClassDeclaration
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
class C {
get [/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
set [/*{ComputedPropertyName}*/](v) {
return /*{value}*/;
}
static get [/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
static set [/*{ComputedPropertyName}*/](v) {
return /*{value}*/;
}
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/],
/*{value}*/
);
assert.sameValue(
c[/*{ComputedPropertyName}*/] = /*{value}*/,
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/],
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/] = /*{value}*/,
/*{value}*/
);

View File

@ -0,0 +1,55 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/cpn-fields-methods-
name: ComputedPropertyName in ClassExpression
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let C = class {
[/*{ComputedPropertyName}*/] = () => {
return /*{value}*/;
};
static [/*{ComputedPropertyName}*/] = () => {
return /*{value}*/;
};
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/](),
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/](),
/*{value}*/
);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/cpn-fields-
name: ComputedPropertyName in ClassExpression
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let C = class {
[/*{ComputedPropertyName}*/] = /*{value}*/;
static [/*{ComputedPropertyName}*/] = /*{value}*/;
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/],
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/],
/*{value}*/
);

View File

@ -0,0 +1,54 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/cpn-
name: ComputedPropertyName in ClassDeclaration
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
class C {
[/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
static [/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/](),
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/](),
/*{value}*/
);

View File

@ -0,0 +1,72 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/cpn-accessors-
name: ComputedPropertyName in ClassExpression
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let C = class {
get [/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
set [/*{ComputedPropertyName}*/](v) {
return /*{value}*/;
}
static get [/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
static set [/*{ComputedPropertyName}*/](v) {
return /*{value}*/;
}
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/],
/*{value}*/
);
assert.sameValue(
c[/*{ComputedPropertyName}*/] = /*{value}*/,
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/],
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/] = /*{value}*/,
/*{value}*/
);

View File

@ -0,0 +1,55 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/cpn-fields-methods-
name: ComputedPropertyName in ClassExpression
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let C = class {
[/*{ComputedPropertyName}*/] = () => {
return /*{value}*/;
};
static [/*{ComputedPropertyName}*/] = () => {
return /*{value}*/;
};
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/](),
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/](),
/*{value}*/
);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/cpn-fields-
name: ComputedPropertyName in ClassExpression
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let C = class {
[/*{ComputedPropertyName}*/] = /*{value}*/;
static [/*{ComputedPropertyName}*/] = /*{value}*/;
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/],
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/],
/*{value}*/
);

View File

@ -0,0 +1,54 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/cpn-
name: ComputedPropertyName in ClassExpression
esid: prod-ComputedPropertyName
info: |
ClassExpression:
classBindingIdentifier opt ClassTail
ClassTail:
ClassHeritage opt { ClassBody opt }
ClassBody:
ClassElementList
ClassElementList:
ClassElement
ClassElement:
MethodDefinition
MethodDefinition:
PropertyName ...
get PropertyName ...
set PropertyName ...
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let C = class {
[/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
static [/*{ComputedPropertyName}*/]() {
return /*{value}*/;
}
};
let c = new C();
assert.sameValue(
c[/*{ComputedPropertyName}*/](),
/*{value}*/
);
assert.sameValue(
C[/*{ComputedPropertyName}*/](),
/*{value}*/
);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/object/cpn-
name: ComputedPropertyName in ObjectLiteral
esid: prod-ComputedPropertyName
info: |
ObjectLiteral:
{ PropertyDefinitionList }
PropertyDefinitionList:
PropertyDefinition
PropertyDefinition:
PropertyName: AssignmentExpression
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let o = {
[/*{ComputedPropertyName}*/]: /*{value}*/
};
assert.sameValue(
o[/*{ComputedPropertyName}*/],
/*{value}*/
);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/object/cpn-
name: ComputedPropertyName in ObjectLiteral
esid: prod-ComputedPropertyName
info: |
ObjectLiteral:
{ PropertyDefinitionList }
PropertyDefinitionList:
PropertyDefinition
PropertyDefinition:
PropertyName: AssignmentExpression
PropertyName:
ComputedPropertyName
ComputedPropertyName:
[ AssignmentExpression ]
---*/
let o = {
[/*{ComputedPropertyName}*/]: /*{value}*/
};
assert.sameValue(
o[/*{ComputedPropertyName}*/],
/*{value}*/
);