fix: report a missing class name as a syntax error - #54
Merged
Conversation
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
force-pushed
the
es6/fix-class-name-error
branch
from
August 28, 2026 05:11
5959488 to
f7cf55b
Compare
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.
Stacked on #53.
A class declaration with no name did not produce a
SyntaxError:className()asked for the message keyparser.error.expected.ident, which does not exist.ECMAErrors.getMessageturns theMissingResourceExceptioninto a plainRuntimeException, so the error was neither aParserExceptionnor — under JSR-223 — aScriptException.Fix
There is no need for a new key: this is the same "Expected X but found Y" that
expectDontAdvancereports everywhere else, soclassName()now builds it the same way, through the existingexpectedkey. That also fixes the argument, which named the token being looked at rather than the one that was wrong — the message saidclasswhere the offending token was{.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