Skip to content

A class method named static is a SyntaxError, and get followed by a line break and a name without parameters is accepted #1729

Open

Description

@hexbinoct

Environment: XS 17.9.3, slot 32 bytes, ID 4 bytes (xst from Moddable SDK 9.5.0, the build the test262 CI installs; same commit as public b6e06ba), Linux x86_64

Description
Two class element parsing problems, found with the new tests in tc39/test262#5142, which V8, SpiderMonkey, JavaScriptCore and GraalJS pass.

  1. A method named static is rejected:
class C {
  static() { return 1; }
}
// SyntaxError: missing identifier

The same with the parameter list on the next line (static / () {}). static static() {} works.

  1. get, a line break, then a name with no parameter list is accepted:
class C {
  get
  a
}
Object.getOwnPropertyNames(new C());
// => ["a"]

Steps to Reproduce
Run the snippets above with xst.

Expected behavior

  1. static is a valid ClassElementName (ClassElementName : PropertyName, with static as an IdentifierName), so static() {} is a MethodDefinition named static. ( cannot start a ClassElementName, so it is not the static modifier, whether or not a line break comes first.
  2. A SyntaxError. MethodDefinition : get ClassElementName ( ) { FunctionBody } has no [no LineTerminator here] after get, so a name on the next line is allowed and automatic semicolon insertion does not end the element after get. get a then needs a parameter list, and neither } nor a semicolon inserted before it completes the getter. V8, SpiderMonkey and JavaScriptCore throw a SyntaxError.

Actual behavior

  1. SyntaxError: missing identifier.
  2. The class parses with a single field a; the get is dropped. In test262 this shows as This statement should not be evaluated. for language/{statements,expressions}/class/elements/syntax/early-errors/grammar-get-followed-by-name-on-next-line-without-parameters-error.js; the other failing file is language/statements/class/elements/syntax/valid/grammar-method-named-static.js.

Other information
Getters and setters with a line break after get or set, and static followed by a line break and a method or field, already work in XS.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    conformancebehavior does not match standard

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions