Apply ASI to a class field named get/set before a generator method - #1650
Open
andreasrosdal wants to merge 3 commits into
Open
Apply ASI to a class field named get/set before a generator method#1650andreasrosdal wants to merge 3 commits into
andreasrosdal wants to merge 3 commits into
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getorsetalone on a line, followed by a generator method, is a class field namedget/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: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-asitests listed intest262_errors.txt; the entries are dropped.language/statements/classlanguage/expressions/object🤖 Generated with Claude Code
https://claude.ai/code/session_014mv33YvfHz7t9mmkituBnn
Generated by Claude Code