From 915a8e54d1c73ef22886004858f5c9d0f0af35e0 Mon Sep 17 00:00:00 2001 From: zengzengran Date: Fri, 6 Jun 2025 23:51:36 +0800 Subject: [PATCH] Allow "use static" on files first line Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICACF5 Description: Allow use "use static" on the first line of source files and declaration files 1. In parser phase, first step is to attempt to load "use static" -> StringLiteral and add it to topstatements. 2. In TopLevelStatements phase, check topstatements. If the first statement is "use static", remove it. Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran # --- .../ets/topLevelStmts/topLevelStmts.cpp | 21 ++++++++++++++++ ets2panda/compiler/scripts/signatures.yaml | 2 ++ ets2panda/parser/ETSparser.cpp | 19 ++++++++++++++ ets2panda/parser/ETSparser.h | 1 + .../compiler/ets/use_static_flag/export1.ets | 17 +++++++++++++ .../compiler/ets/use_static_flag/export2.ets | 17 +++++++++++++ .../use_static_flag/flag_after_copyright.ets | 18 +++++++++++++ .../use_static_flag/flag_after_importdecl.ets | 20 +++++++++++++++ .../flag_before_importdecl.ets | 18 +++++++++++++ .../use_static_flag/flag_in_first_line.ets | 17 +++++++++++++ .../use_static_flag/flag_in_first_line_2.ets | 17 +++++++++++++ .../flag_in_first_line_2_neg.ets | 19 ++++++++++++++ .../flag_in_first_line_3_neg.ets | 19 ++++++++++++++ .../flag_in_first_line_neg.ets | 19 ++++++++++++++ .../flag_middle_importdecl_neg.ets | 20 +++++++++++++++ .../package/flag_before_package.ets | 17 +++++++++++++ .../package/flag_before_package2.ets | 17 +++++++++++++ .../package_2_neg/flag_before_package.ets | 24 ++++++++++++++++++ .../package_3_neg/flag_before_package.ets | 25 +++++++++++++++++++ .../package_neg/flag_package.ets | 20 +++++++++++++++ .../package_neg/flag_package2.ets | 19 ++++++++++++++ .../srcdumper/srcdumper-ets-ignored.txt | 2 ++ 22 files changed, 368 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/export1.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/export2.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_copyright.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_importdecl.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_before_importdecl.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2_neg.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_3_neg.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_neg.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/flag_middle_importdecl_neg.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package2.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/package_2_neg/flag_before_package.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/package_3_neg/flag_before_package.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package.ets create mode 100644 ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package2.ets diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp index 28c205ee50..bd503f088e 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/topLevelStmts.cpp @@ -48,8 +48,29 @@ static bool CheckProgramSourcesConsistency(parser::Program *program) return success; } +static void CheckFileHeaderFlag(parser::Program *program) +{ + auto &statements = program->Ast()->Statements(); + if (statements.empty()) { + return; + } + + if (!statements.front()->IsExpressionStatement()) { + return; + } + + // If further processing based on "use static" is required later, such as throwing a warning or modifying the node, + // perform the operation here. + auto *expansion = statements.front()->AsExpressionStatement()->GetExpression(); + if (expansion->IsStringLiteral() && expansion->AsStringLiteral()->Str() == Signatures::STATIC_PROGRAM_FLAG) { + statements.erase(statements.begin()); + return; + } +} + bool TopLevelStatements::Perform(public_lib::Context *ctx, parser::Program *program) { + CheckFileHeaderFlag(program); auto imports = ImportExportDecls(program->VarBinder()->AsETSBinder(), ctx->parser->AsETSParser()); imports.ParseDefaultSources(); if (!CheckProgramSourcesConsistency(program)) { diff --git a/ets2panda/compiler/scripts/signatures.yaml b/ets2panda/compiler/scripts/signatures.yaml index 930c5a0408..3a4186c8b7 100644 --- a/ets2panda/compiler/scripts/signatures.yaml +++ b/ets2panda/compiler/scripts/signatures.yaml @@ -226,6 +226,8 @@ defines: ref: UNUSED_ETSGLOBAL_INIT - name: 'ETSGLOBAL.main:void;' ref: UNUSED_ETSGLOBAL_MAIN + - name: 'use static' + ref: STATIC_PROGRAM_FLAG packages: - name: 'std.core' diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 6f423f8142..f42151a120 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -121,6 +121,7 @@ void ETSParser::ParseProgram(ScriptKind kind) } ArenaVector statements(Allocator()->Adapter()); + ParseFileHeaderFlag(startLoc, &statements); auto decl = ParsePackageDeclaration(); if (decl != nullptr) { statements.emplace_back(decl); @@ -147,6 +148,23 @@ void ETSParser::ParseProgram(ScriptKind kind) GetProgram()->SetAst(script); } +void ETSParser::ParseFileHeaderFlag(lexer::SourcePosition startLoc, ArenaVector *statements) +{ + if (Lexer()->GetToken().KeywordType() != lexer::TokenType::LITERAL_STRING || + Lexer()->GetToken().String() != compiler::Signatures::STATIC_PROGRAM_FLAG) { + return; + } + + ir::Expression *fileHeaderFlag = ParseStringLiteral(); + auto *exprStatementNode = AllocNode(fileHeaderFlag); + + exprStatementNode->SetRange({startLoc, fileHeaderFlag->End()}); + ConsumeSemicolon(exprStatementNode); + if (statements != nullptr) { + statements->push_back(exprStatementNode); + } +} + ir::ETSModule *ETSParser::ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements) { ETSNolintParser etsnolintParser(this); @@ -408,6 +426,7 @@ parser::Program *ETSParser::ParseSource(const SourceFile &sourceFile) Lexer()->NextToken(); ArenaVector statements(Allocator()->Adapter()); + ParseFileHeaderFlag(startLoc, nullptr); auto decl = ParsePackageDeclaration(); ir::ETSModule *script = nullptr; if (decl != nullptr) { diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 6a2e718765..37b3d195b3 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -210,6 +210,7 @@ private: ArenaVector &directImportsFromMainSource); parser::Program *ParseSource(const SourceFile &sourceFile); ir::ETSModule *ParseETSGlobalScript(lexer::SourcePosition startLoc, ArenaVector &statements); + void ParseFileHeaderFlag(lexer::SourcePosition startLoc, ArenaVector *statements); ir::ETSModule *ParseImportsOnly(lexer::SourcePosition startLoc, ArenaVector &statements); ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers) override; void *ApplyAnnotationsToClassElement(ir::AstNode *property, ArenaVector &&annotations, diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/export1.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/export1.ets new file mode 100644 index 0000000000..3b6361ce1a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/export1.ets @@ -0,0 +1,17 @@ +"use static" +/* + * 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. + */ + +export class A{} diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/export2.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/export2.ets new file mode 100644 index 0000000000..dd2d2b0a2b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/export2.ets @@ -0,0 +1,17 @@ +"use static" +/* + * 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. + */ + +export class B{} diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_copyright.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_copyright.ets new file mode 100644 index 0000000000..f5862745c1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_copyright.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +"use static" + +class A{} diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_importdecl.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_importdecl.ets new file mode 100644 index 0000000000..7245e8367d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_after_importdecl.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. + */ + +import { A as A } from "./export1.ets" +import { B as B } from "./export2.ets" + +"use static" +let str:String = "use static" diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_before_importdecl.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_before_importdecl.ets new file mode 100644 index 0000000000..730bab7c5d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_before_importdecl.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +"use static" +import {A as A} from "./export1.ets" +import {B as B} from "./export2.ets" diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line.ets new file mode 100644 index 0000000000..34045c2ff1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line.ets @@ -0,0 +1,17 @@ +"use static" +/* + * 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. + */ + +class A{} diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2.ets new file mode 100644 index 0000000000..c14b258b49 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2.ets @@ -0,0 +1,17 @@ +'use static' +/* + * 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. + */ + +class A{} diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2_neg.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2_neg.ets new file mode 100644 index 0000000000..df09abb5e1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_2_neg.ets @@ -0,0 +1,19 @@ +'use statics' +/* + * 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. + */ + +import { A as A } from "./export1.ets" + +/* @@? 17:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_3_neg.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_3_neg.ets new file mode 100644 index 0000000000..1b1cd257ac --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_3_neg.ets @@ -0,0 +1,19 @@ +"uses static" +/* + * 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. + */ + +import { A as A } from "./export1.ets" + +/* @@? 17:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_neg.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_neg.ets new file mode 100644 index 0000000000..e0a410adc7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_in_first_line_neg.ets @@ -0,0 +1,19 @@ +'uses static' +/* + * 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. + */ + +import { A as A } from "./export1.ets" + +/* @@? 17:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/flag_middle_importdecl_neg.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_middle_importdecl_neg.ets new file mode 100644 index 0000000000..b048662c57 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/flag_middle_importdecl_neg.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. + */ + +import {A as A} from "./export1.ets" +"use static" +import {B as B} from "./export2.ets" + +/* @@? 18:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package.ets new file mode 100644 index 0000000000..07508594ee --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package.ets @@ -0,0 +1,17 @@ +"use static" +/* + * 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. + */ + +package usestaticpackage; diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package2.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package2.ets new file mode 100644 index 0000000000..07508594ee --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/package/flag_before_package2.ets @@ -0,0 +1,17 @@ +"use static" +/* + * 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. + */ + +package usestaticpackage; diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/package_2_neg/flag_before_package.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/package_2_neg/flag_before_package.ets new file mode 100644 index 0000000000..ee44269d82 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/package_2_neg/flag_before_package.ets @@ -0,0 +1,24 @@ +"use static" +/* + * 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. + */ + +package usestaticpackage3; + +let str2:String = "use static" +import {A as A} from "../export1.ets" +import {B as B} from "../export2.ets" + +/* @@? 20:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ +/* @@? 21:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/package_3_neg/flag_before_package.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/package_3_neg/flag_before_package.ets new file mode 100644 index 0000000000..55490f06d0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/package_3_neg/flag_before_package.ets @@ -0,0 +1,25 @@ +"use static" +/* + * 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. + */ + +package usestaticpackage3; + +"use static" +import {A as A} from "../export1.ets" +import {B as B} from "../export2.ets" + +/* @@? 19:1 Error SyntaxError: Invalid package toplevel statement */ +/* @@? 20:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ +/* @@? 21:1 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package.ets new file mode 100644 index 0000000000..ae374bb21f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package.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. + */ + +package usestaticpackage2; + +"use static" + +/* @@? 18:1 Error SyntaxError: Invalid package toplevel statement */ diff --git a/ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package2.ets b/ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package2.ets new file mode 100644 index 0000000000..551145bbe7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/use_static_flag/package_neg/flag_package2.ets @@ -0,0 +1,19 @@ +"use static" +/* + * 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. + */ + +package usestaticpackage2; + +/* @@? flag_package.ets:18:1 Error SyntaxError: Invalid package toplevel statement */ diff --git a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt index 93f5508e79..0f60c8fe11 100644 --- a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt +++ b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt @@ -178,6 +178,8 @@ ast/compiler/ets/namespace_tests/namespace.ets ast/compiler/ets/namespace_tests/namespace_ambient_export01.ets ast/compiler/ets/namespace_tests/namespace_ambient_export02.ets ast/compiler/ets/namespace_tests/namespace_ambient_export03.ets +ast/compiler/ets/use_static_flag/flag_after_importdecl.ets +ast/compiler/ets/use_static_flag/flag_before_importdecl.ets runtime/ets/namespace_tests/namespace_import_type_test/namespace_import.ets runtime/ets/namespace_tests/namespace_initializer.ets runtime/ets/interface_with_optional_property_cycle_import/class_file.ets -- Gitee