Skip to content

Commit

Permalink
Decorators: add initial tests on class
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas authored and rwaldron committed May 18, 2022
1 parent 509363b commit 6f8e0f6
Show file tree
Hide file tree
Showing 27 changed files with 1,045 additions and 0 deletions.
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ Intl.DurationFormat
# https://github.com/tc39/proposal-regexp-set-notation
regexp-v-flag

# Decorators
# https://github.com/tc39/proposal-decorators
decorators

## 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,28 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: Valid accessor FieldDefinition, ClassElementName, PropertyName Syntax
info: |
FieldDefinition[Yield, Await] :
accessor [no LineTerminator here] ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt

template: default
features: [decorators]
---*/

//- elements
accessor
$;
static accessor
$;

//- assertions
let c = new C();

assert.sameValue(Object.hasOwnProperty.call(C.prototype, 'accessor'), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, '$'), false);
assert.sameValue(Object.hasOwnProperty.call(C, 'accessor'), true);
assert.sameValue(Object.hasOwnProperty.call(C, '$'), true);
assert.sameValue(Object.hasOwnProperty.call(c, 'accessor'), true);
assert.sameValue(Object.hasOwnProperty.call(c, '$'), true);
21 changes: 21 additions & 0 deletions src/class-elements/grammar-field-accessor.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: Valid accessor FieldDefinition, ClassElementName, PropertyName Syntax
info: |
FieldDefinition[Yield, Await] :
ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt
accessor [no LineTerminator here] ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt

template: syntax/valid
features: [decorators]
---*/

//- elements
accessor $;
accessor _;
accessor \u{6F};
accessor \u2118;
accessor ZW_\u200C_NJ;
accessor ZW_\u200D_J;
44 changes: 44 additions & 0 deletions src/decorator/decorator-call-expr-identifier-reference.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: >
Decorator @ DecoratorCallExpression
info: |
DecoratorCallExpression[Yield, Await] :
DecoratorMemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

DecoratorMemberExpression[Yield, Await] :
IdentifierReference[?Yield, ?Await]
PrivateIdentifier
DecoratorMemberExpression[?Yield, ?Await] . IdentifierName

IdentifierReference[Yield, Await] :
Identifier
[~Yield] yield
[~Await] await

template: syntax/valid
---*/

//- setup
function decorator() {
return () => {};
}
var _ = decorator;
var \u{6F} = decorator;
var \u2118 = decorator;
var ZW_\u200C_NJ = decorator;
var ZW_\u200D_J = decorator;
var yield = decorator;
var await = decorator;

//- decorators
@$()
@_()
@\u{6F}()
@\u2118()
@ZW_\u200C_NJ()
@ZW_\u200D_J()
@yield()
@await()
36 changes: 36 additions & 0 deletions src/decorator/decorator-member-expr-decorator-member-expr.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: >
Decorator @ DecoratorMemberExpression
info: |
DecoratorMemberExpression[Yield, Await] :
IdentifierReference[?Yield, ?Await]
PrivateIdentifier
DecoratorMemberExpression[?Yield, ?Await] . IdentifierName

template: syntax/valid
---*/

//- setup
let ns = {
$() {}
_() {}
\u{6F}() {}
\u2118() {}
ZW_\u200C_NJ() {}
ZW_\u200D_J() {}
yield() {}
await() {}
}

//- decorators
@ns.$
@ns._
@ns.\u{6F}
@ns.\u2118
@ns.ZW_\u200C_NJ
@ns.ZW_\u200D_J
@ns.yield
@ns.await
33 changes: 33 additions & 0 deletions src/decorator/decorator-member-expr-identifier-reference.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: >
Decorator @ DecoratorMemberExpression
info: |
IdentifierReference[Yield, Await] :
Identifier
[~Yield] yield
[~Await] await
template: syntax/valid
---*/

//- setup
function $() {}
function _() {}
function \u{6F}() {}
function \u2118() {}
function ZW_\u200C_NJ() {}
function ZW_\u200D_J() {}
function yield() {}
function await() {}

//- decorators
@$
@_
@\u{6F}
@\u2118
@ZW_\u200C_NJ
@ZW_\u200D_J
@yield
@await
35 changes: 35 additions & 0 deletions src/decorator/decorator-member-expr-private-identifier.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: >
Decorator @ DecoratorMemberExpression
info: |
DecoratorMemberExpression[Yield, Await] :
PrivateIdentifier

PrivateIdentifier ::
# IdentifierName

template: syntax/class-valid
---*/

//- elements
static #$() {}
static #_() {}
static #\u{6F}() {}
static #\u2118() {}
static #ZW_\u200C_NJ() {}
static #ZW_\u200D_J() {}
static #yield() {}
static #await() {}

//- decorators
@#$
@#_
@#\u{6F}
@#\u2118
@#ZW_\u200C_NJ
@#ZW_\u200D_J
@#yield
@#await
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: >
Decorator @ DecoratorParenthesizedExpression
info: |
DecoratorParenthesizedExpression[Yield, Await] :
( Expression[+In, ?Yield, ?Await] )

PrimaryExpression[Yield, Await] :
this
IdentifierReference[?Yield, ?Await]
Literal
ArrayLiteral[?Yield, ?Await]
ObjectLiteral[?Yield, ?Await]
FunctionExpression
ClassExpression[?Yield, ?Await]
GeneratorExpression
AsyncFunctionExpression
AsyncGeneratorExpression
RegularExpressionLiteral
TemplateLiteral[?Yield, ?Await, ~Tagged]
CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]

template: syntax/valid
---*/

//- setup
function $() {}
function _() {}
function \u{6F}() {}
function \u2118() {}
function ZW_\u200C_NJ() {}
function ZW_\u200D_J() {}
function yield() {}
function await() {}

//- decorators
@($)
@(_)
@(\u{6F})
@(\u2118)
@(ZW_\u200C_NJ)
@(ZW_\u200D_J)
@(yield)
@(await)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-ClassDeclaration
name: Valid syntax for decorator on class declaration in class body.
path: language/statements/class/decorator/syntax/class-valid/
info: |
ClassDeclaration[Yield, Await, Default] :
DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await]
[+Default] DecoratorList[?Yield, ?Await]opt class ClassTail[?Yield, ?Await]

DecoratorList[Yield, Await] :
DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await]

Decorator[Yield, Await] :
@ DecoratorMemberExpression[?Yield, ?Await]
@ DecoratorParenthesizedExpression[?Yield, ?Await]
@ DecoratorCallExpression[?Yield, ?Await]

...
features: [class, decorators]
---*/

class C {
/*{ elements }*/
static {
/*{ decorators }*/ class C {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-ClassExpression
name: Valid syntax for decorator on class expression in class body.
path: language/expressions/class/decorator/syntax/class-valid/
info: |
ClassExpression[Yield, Await] :
DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await]

DecoratorList[Yield, Await] :
DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await]

Decorator[Yield, Await] :
@ DecoratorMemberExpression[?Yield, ?Await]
@ DecoratorParenthesizedExpression[?Yield, ?Await]
@ DecoratorCallExpression[?Yield, ?Await]

...
features: [class, decorators]
---*/

var C = class {
/*{ elements }*/
static {
var C = /*{ decorators }*/ class {}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-ClassDeclaration
name: Valid syntax for decorator on class.
path: language/statements/class/decorator/syntax/valid/
info: |
ClassDeclaration[Yield, Await, Default] :
DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await]
[+Default] DecoratorList[?Yield, ?Await]opt class ClassTail[?Yield, ?Await]

DecoratorList[Yield, Await] :
DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await]

Decorator[Yield, Await] :
@ DecoratorMemberExpression[?Yield, ?Await]
@ DecoratorParenthesizedExpression[?Yield, ?Await]
@ DecoratorCallExpression[?Yield, ?Await]

...
features: [class, decorators]
---*/

/*{ decorators }*/ class C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2022 Chengzhong Wu. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: prod-ClassDeclaration
name: Valid syntax for decorator on class.
path: language/statements/class/decorator/syntax/valid/
info: |
ClassElement[Yield, Await] :
DecoratorList[?Yield, ?Await]opt MethodDefinition[?Yield, ?Await]
DecoratorList[?Yield, ?Await]opt static MethodDefinition[?Yield, ?Await]
DecoratorList[?Yield, ?Await]opt FieldDefinition[?Yield, ?Await] ;
DecoratorList[?Yield, ?Await]opt static FieldDefinition[?Yield, ?Await] ;
ClassStaticBlock
;

DecoratorList[Yield, Await] :
DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await]

Decorator[Yield, Await] :
@ DecoratorMemberExpression[?Yield, ?Await]
@ DecoratorParenthesizedExpression[?Yield, ?Await]
@ DecoratorCallExpression[?Yield, ?Await]

...
features: [class, decorators]
---*/

class C {
/*{ decorators }*/ method() {}
/*{ decorators }*/ static method() {}
/*{ decorators }*/ field;
/*{ decorators }*/ static field;
}

0 comments on commit 6f8e0f6

Please sign in to comment.