Skip to content

Apply ASI to a class field named get/set before a generator method - #1650

Open
andreasrosdal wants to merge 3 commits into
quickjs-ng:masterfrom
nordstjernen-web:fix-asi-class-field-get-set
Open

Apply ASI to a class field named get/set before a generator method#1650
andreasrosdal wants to merge 3 commits into
quickjs-ng:masterfrom
nordstjernen-web:fix-asi-class-field-get-set

Conversation

@andreasrosdal

Copy link
Copy Markdown
Contributor

get or set alone on a line, followed by a generator method, is a class field named get/set: an accessor cannot be a generator, so the * cannot continue the ClassElement and automatic semicolon insertion ends the field declaration there.

js_parse_property_name() only ends the pseudo-keyword at :, ,, }, (, = or ;, so it reads the * as part of a getter and rejects the class:

class C {
  get
  *m() { yield 1; }
}
// SyntaxError: invalid property name

Treat a * that follows a line terminator the same way. The check is limited to class bodies (allow_private), since an object literal has no field declaration for ASI to end. A generator method on the same line, class C { get *m() {} }, is still a SyntaxError, and a getter split across a newline (class D { get\n m() {} }) still parses as a getter.

Testing

Fixes the two grammar-field-named-{get,set}-followed-by-generator-asi tests listed in test262_errors.txt; the entries are dropped.

suite before after
language/statements/class 2/4353 0/4353
language/expressions/object 1/1170 1/1170

🤖 Generated with Claude Code

https://claude.ai/code/session_014mv33YvfHz7t9mmkituBnn


Generated by Claude Code

claude and others added 3 commits August 6, 2026 17:45
`get` or `set` alone on a line, followed by a generator method, is a class
field named get/set: an accessor cannot be a generator, so the `*` cannot
continue the ClassElement and automatic semicolon insertion ends the field
declaration there.

js_parse_property_name() only ends the pseudo-keyword at ':', ',', '}',
'(', '=' or ';', so it reads the `*` as part of a getter and rejects the
class:

    class C {
      get
      *m() { yield 1; }
    }
    // SyntaxError: invalid property name

Treat a '*' that follows a line terminator the same way. The check is
limited to class bodies (allow_private), since an object literal has no
field declaration for ASI to end. A generator method on the same line,
`class C { get *m() {} }`, is still a SyntaxError.

Fixes the two test262 grammar-field-named-{get,set}-followed-by-generator-asi
tests listed in test262_errors.txt; the entries are dropped.
language/statements/class goes from 2/4353 to 0/4353;
language/expressions/object is unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014mv33YvfHz7t9mmkituBnn
Pins the shape the inserted semicolon produces -- an own data field and a
separate generator element -- across the static, computed, private and
multi-line-comment spellings, and keeps the cases that must stay a
SyntaxError: the same construct without a line terminator, and the same
construct in an object literal, which has no field definitions to end.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K6eRbuuuCujKgQkrHgvMrc
The semicolon goes in front of the offending token, so it is only the '*'
that is itself preceded by the line terminator that ends the field. Added
the neighbours where it is not: 'get' followed by async, static or a second
get, all of which are getter names that carry the parse across the newline
and leave the '*' an error, plus a '*' with no method after it.

Also the generator the field is followed by being named async, get or set,
and the two element prefixes that reach the same place through their own
paths: 'async', which cannot start an async generator across a line
terminator and so becomes a field, and 'static', which is a modifier rather
than a name and keeps applying to the generator that follows it.
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.

2 participants