Skip to content

Add tests for class elements continued after a line terminator - #5142

Open
hexbinoct wants to merge 1 commit into
tc39:mainfrom
hexbinoct:class-element-name-after-line-terminator
Open

hexbinoct wants to merge 1 commit into
tc39:mainfrom
hexbinoct:class-element-name-after-line-terminator

Conversation

@hexbinoct

@hexbinoct hexbinoct commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

test262 checks that a semicolon is inserted between a field named get or set and a generator method on the next line (grammar-field-named-get-followed-by-generator-asi.js and its set sibling). It does not check the other side: when the token on the next line can continue the element, no semicolon is inserted, because only async and accessor are followed by [no LineTerminator here].

class C {
  get
  a() {}   // a getter named a, not a field named get and a method
}

engine262 gets these wrong, and nothing in the suite catches it. This adds, next to the two existing ASI tests in class/elements/syntax/valid:

  • get or set, a line break, then a name: a getter or setter (prototype, static, computed and private)
  • static, a line break, then a method, generator, async method or getter: a static method
  • static, a line break, then a field name: a static field
  • a method named static, as static(), static static() and static with ( on the next line
  • a method name, a line break, then (: a method, for m, get and set
  • a SyntaxError for get, a line break, then a name with no parameter list (generated, class declaration and expression)

I could not find an existing test for a class method named static. The only static() methods in the suite are object literal methods in staging/sm/class/methDefn.js.

I found this while reviewing #5134: with the escapes removed from its cases, engine262 read get, a line break and a() {} as a field and a method.

Results, default and strict mode:

node v24.14.0, v26.5.1 (V8)              8/8 pass
bun 1.3.14 (JavaScriptCore)              8/8 pass
engine262 main (a600354c)                0/8, e.g. "(A) a is a getter on the prototype Expected SameValue(«"undefined"», «"function"») to be true"
engine262 with the fix                   8/8 pass

The engine262 fix is engine262/engine262#368.

Lint is clean. To check that each test can fail, I ran mutated copies: flipping the key expectation in each positive test, and giving the getter in the negative test its parameter list. All of them fail on all four engines.

LLM disclosure: Claude Opus 5.5 helped me find the gap, write the tests and check them; I reviewed the result.

A line terminator after get, set or static, or between a method name and
its parameter list, does not end the element as a field, since only async
and accessor have a [no LineTerminator here] restriction. Also covers a
method named static, and a getter whose name is on the next line but that
has no parameter list.
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

8 new or modified tests were run on 7 engines.

View workflow run

Test Engine262 GraalJS JavaScriptCore QuickJS SpiderMonkey V8 XS
language/expressions/class/elements/syntax/early-errors/grammar-get-followed-by-name-on-next-line-without-parameters-error.js ❌ ✅ ✅ ❌ ✅ ✅ ❌
language/statements/class/elements/syntax/early-errors/grammar-get-followed-by-name-on-next-line-without-parameters-error.js ❌ ✅ ✅ ❌ ✅ ✅ ❌
language/statements/class/elements/syntax/valid/grammar-get-followed-by-name-on-next-line.js ❌ ✅ ✅ ❌ ✅ ✅ ✅
language/statements/class/elements/syntax/valid/grammar-method-name-followed-by-parameters-on-next-line.js ❌ ✅ ✅ ✅ ✅ ✅ ✅
language/statements/class/elements/syntax/valid/grammar-method-named-static.js ❌ ✅ ✅ ❌ ✅ ✅ ❌
language/statements/class/elements/syntax/valid/grammar-set-followed-by-name-on-next-line.js ❌ ✅ ✅ ❌ ✅ ✅ ✅
language/statements/class/elements/syntax/valid/grammar-static-followed-by-field-on-next-line.js ❌ ✅ ✅ ✅ ✅ ✅ ✅
language/statements/class/elements/syntax/valid/grammar-static-followed-by-method-on-next-line.js ❌ ✅ ✅ ❌ ✅ ✅ ✅

@hexbinoct

Copy link
Copy Markdown
Contributor Author

The failures in the engine table are engine bugs, reproduced outside the harness with small snippets:

V8, SpiderMonkey, JavaScriptCore and GraalJS pass all 8.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant