test262 icon indicating copy to clipboard operation
test262 copied to clipboard

Decorators: Class decorators are part of the class and their local names must be valid in strict mode.

Open lpardosixtosMs opened this issue 1 year ago • 0 comments

The decorators spec PR has the following note at the bottom of the Class Definition secition (15.8):

A class definition is always strict mode code.

The existing spec also specifies that "All parts of a ClassDeclaration or a ClassExpression are strict mode code." Given that DecoratorList is part of ClassDeclaration and ClassExpression, I understand that decorators are in strict mode too.

ClassDeclaration[Yield, Await, Default] :
  DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await]

ClassExpression[Yield, Await] :
  DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await]

As a consequence expressions like @yield class C{} or @yield() class C{} are not allowed because "yield" as an IdentifierReference is not allowed in strict mode, contradicting these tests:

  • https://github.com/tc39/test262/blob/main/src/decorator/decorator-member-expr-identifier-reference-yield.case
  • https://github.com/tc39/test262/blob/main/src/decorator/decorator-parenthesized-expr-identifier-reference-yield.case
  • https://github.com/tc39/test262/blob/main/src/decorator/decorator-call-expr-identifier-reference-yield.case

Related issue in the decorators proposal: https://github.com/tc39/proposal-decorators/issues/545

lpardosixtosMs avatar Sep 25 '24 16:09 lpardosixtosMs