Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/org/codelibs/sai/internal/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,9 @@ private IdentNode className() {
final int nameIndex = k + 1;

if (T(nameIndex) != IDENT) {
throw error(AbstractParser.message("expected.ident", type.getNameOrType()), getToken(nameIndex));
final long nameToken = getToken(nameIndex);
throw error(AbstractParser.message("expected", IDENT.getNameOrType(), Token.toString(source, nameToken)),
nameToken);
}

return createIdentNode(getToken(nameIndex), finish, (String) getValue(getToken(nameIndex)));
Expand Down
32 changes: 32 additions & 0 deletions test/script/error/class_duplicate_constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026, CodeLibs Project and/or its affiliates. All rights reserved.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/**
* A class body may define at most one constructor.
*
* @test/compile-error
* @option --language=es6
*/

class Point {
constructor() {
}

constructor() {
}
}
6 changes: 6 additions & 0 deletions test/script/error/class_duplicate_constructor.js.EXPECTED
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test/script/error/class_duplicate_constructor.js:30:4 A class may only have one constructor
constructor() {
^
test/script/error/class_duplicate_constructor.js:31:4 Expected eof but found }
}
^
28 changes: 28 additions & 0 deletions test/script/error/class_name_missing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2026, CodeLibs Project and/or its affiliates. All rights reserved.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/**
* A class declaration needs a name. Saying so has to be an ordinary syntax error
* rather than a missing message resource.
*
* @test/compile-error
* @option --language=es6
*/

class {
}
6 changes: 6 additions & 0 deletions test/script/error/class_name_missing.js.EXPECTED
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test/script/error/class_name_missing.js:27:6 Expected ident but found {
class {
^
test/script/error/class_name_missing.js:28:0 Expected eof but found }
}
^