Skip to content

fix: report a missing class name as a syntax error - #54

Merged
marevol merged 1 commit into
es6/fix-template-reparsefrom
es6/fix-class-name-error
Aug 28, 2026
Merged

fix: report a missing class name as a syntax error#54
marevol merged 1 commit into
es6/fix-template-reparsefrom
es6/fix-class-name-error

Conversation

@marevol

@marevol marevol commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Stacked on #53.

A class declaration with no name did not produce a SyntaxError:

class {}      no message resource found for message id: parser.error.expected.ident
class 1 {}    same

className() asked for the message key parser.error.expected.ident, which does not exist. ECMAErrors.getMessage turns the MissingResourceException into a plain RuntimeException, so the error was neither a ParserException nor — under JSR-223 — a ScriptException.

Fix

There is no need for a new key: this is the same "Expected X but found Y" that expectDontAdvance reports everywhere else, so className() now builds it the same way, through the existing expected key. That also fixes the argument, which named the token being looked at rather than the one that was wrong — the message said class where the offending token was {.

class {}      Expected ident but found {
class 1 {}    Expected ident but found 1

Two error tests come with it. Neither a malformed class name nor a duplicated constructor had one, which is why a message key that never resolved could ship. The duplicate-constructor message was already correct and is now covered.

Verification

./gradlew build testOptimistic testPessimistic

suite before after
test 665, 0 fail 665, 0 fail
testOptimistic 1715, 0 fail 1717, 0 fail
testPessimistic 1715, 0 fail 1717, 0 fail

@marevol marevol added this to the 0.4.0 milestone Aug 28, 2026
A class declaration with no name did not produce a SyntaxError:

    class {}      no message resource found for message id: parser.error.expected.ident
    class 1 {}    same

className() asked for the message key parser.error.expected.ident, which does
not exist. ECMAErrors.getMessage turns the MissingResourceException into a plain
RuntimeException, so the error was neither a ParserException nor - under
JSR-223 - a ScriptException.

There is no need for a new key: this is the same "Expected X but found Y" that
expectDontAdvance reports everywhere else, so className() now builds it the same
way, through the existing "expected" key. That also fixes the argument, which
named the token being looked at rather than the one that was wrong: the message
said "class" where the offending token was "{".

    class {}      Expected ident but found {
    class 1 {}    Expected ident but found 1

Two error tests come with it. Neither a malformed class name nor a duplicated
constructor had one, which is why a message key that never resolved could ship.
The duplicate-constructor message was already correct and is now covered.

./gradlew build testOptimistic testPessimistic:

  suite            before         after
  test             665, 0 fail    665, 0 fail
  testOptimistic   1715, 0 fail   1717, 0 fail
  testPessimistic  1715, 0 fail   1717, 0 fail
@marevol
marevol force-pushed the es6/fix-class-name-error branch from 5959488 to f7cf55b Compare August 28, 2026 05:11
@marevol marevol self-assigned this Aug 28, 2026
@marevol
marevol merged commit 73a6182 into master Aug 28, 2026
1 check passed
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