diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 268455be78070ccbc237e3940dc9c15e6b2cbaec..02dd76cabd71dcb5ba8e2fb610a58f19923b1729 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -130,7 +130,11 @@ bool TypedParser::IsNamespaceDecl() } auto savedPos = Lexer()->Save(); Lexer()->NextToken(); - bool isNamespaceDecl = Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT; + // namespace is a soft keyword, so it can be used as an identifier outside declarations + // If followed by an identifier (literal or keyword), it's treated as a declaration + // Using keywords as identifiers is invalid, but that error is handled later during parsing + bool isNamespaceDecl = + Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT || Lexer()->GetToken().IsKeyword(); Lexer()->Rewind(savedPos); return isNamespaceDecl; } diff --git a/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_super.ets b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_super.ets new file mode 100644 index 0000000000000000000000000000000000000000..fb422ff9ccc56d5101b2a29dec30962ce8c2bde5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_super.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare namespace super { + +} + +/* @@? 16:19 Error SyntaxError: Identifier expected, got 'super'. */ diff --git a/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_this.ets b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_this.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd9e3c4376721c2f0f3521ae6c98140cdea999b8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_this.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare namespace this { + +} + +/* @@? 16:19 Error SyntaxError: Identifier expected, got 'this'. */