From 8db48138a8ea64b434ea56b6b14593c48c0fd1b0 Mon Sep 17 00:00:00 2001 From: huyunhui1 Date: Wed, 4 Dec 2024 18:23:06 +0800 Subject: [PATCH 1/3] Fix bug of sendable class Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IBALL7 Signed-off-by: huyunhui1 Change-Id: Iaba94d62c058382d5f296d0ad8c565f9fac44d2f --- es2panda/ir/base/classDefinition.cpp | 25 +++-- .../sendable-field-type-5-expected.txt | 8 ++ .../sendable/sendable-field-type-5.ts | 93 +++++++++++++++++++ 3 files changed, 112 insertions(+), 14 deletions(-) create mode 100644 es2panda/test/compiler/sendable/sendable-field-type-5-expected.txt create mode 100644 es2panda/test/compiler/sendable/sendable-field-type-5.ts diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index 299b1dd5c..560c377b1 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -585,13 +585,9 @@ void ClassDefinition::AddFieldTypeForTypeReference(const TSTypeReference *typeRe // ts enum type const ir::AstNode *declNode = GetDeclNodeFromIdentifier(typeName->AsIdentifier()); - if (declNode != nullptr) { - // If the result of "declNode->Original()" is nullptr, it means the declNode is original and not transformed. - auto originalNode = (declNode->Original() != nullptr) ? declNode->Original() : declNode; - if (originalNode->Type() == ir::AstNodeType::TS_ENUM_DECLARATION) { - fieldType |= FieldType::STRING | FieldType::NUMBER; - return; - } + if (declNode != nullptr && declNode->IsTSEnumDeclaration()) { + fieldType |= FieldType::STRING | FieldType::NUMBER; + return; } // sendable class and sendable fuction @@ -604,14 +600,7 @@ const ir::AstNode *ClassDefinition::GetDeclNodeFromIdentifier(const ir::Identifi return nullptr; } - std::vector variables; - variables.reserve(identifier->TSVariables().size() + 1U); - variables.emplace_back(identifier->Variable()); for (const auto &v : identifier->TSVariables()) { - variables.emplace_back(v); - } - - for (const auto &v : variables) { if (v == nullptr || v->Declaration() == nullptr || v->Declaration()->Node() == nullptr) { continue; } @@ -619,6 +608,14 @@ const ir::AstNode *ClassDefinition::GetDeclNodeFromIdentifier(const ir::Identifi auto res = v->Declaration()->Node(); return res; } + + // In general, the declaration node of a type node could alaways be found in ts ast. + // The following branch, finding declaration node in js ast, is added for some unexpected corner cases. + if (identifier->Variable() && identifier->Variable()->Declaration() && + identifier->Variable()->Declaration()->Node()) { + return identifier->Variable()->Declaration()->Node()->Original(); + } + return nullptr; } diff --git a/es2panda/test/compiler/sendable/sendable-field-type-5-expected.txt b/es2panda/test/compiler/sendable/sendable-field-type-5-expected.txt new file mode 100644 index 000000000..1173f1db5 --- /dev/null +++ b/es2panda/test/compiler/sendable/sendable-field-type-5-expected.txt @@ -0,0 +1,8 @@ +1 +0 +1 +0 +0 +1 +0 +1 diff --git a/es2panda/test/compiler/sendable/sendable-field-type-5.ts b/es2panda/test/compiler/sendable/sendable-field-type-5.ts new file mode 100644 index 000000000..56c9aa576 --- /dev/null +++ b/es2panda/test/compiler/sendable/sendable-field-type-5.ts @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 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. + */ + +// test const enum inside namespace +namespace ns { + export const enum Enum { + ONE, + TWO + } + + export class A { + constructor() { + "use sendable"; + } + prop1: Enum = 0; + static prop2: Enum1 = 1; + } + + const enum Enum1 { + ONE, + TWO + } + + + namespace ns1 { + export class A { + constructor() { + "use sendable"; + } + prop1: Enum = 0; + static prop2: Enum1 = 1; + } + } + + print(ns1.A.prop2); + print(new ns1.A().prop1); +} + +print(ns.A.prop2) +print(new ns.A().prop1) + +// test merged namespaces +namespace ns_1 { + export class A{ + constructor() { + "use sendable"; + } + static prop1: Enum = 0 + prop2: Enum = 1 + } +} + +namespace ns_1 { + export const enum Enum { + ONE, + TWO + } +} + +print(ns_1.A.prop1) +print(new ns_1.A().prop2) + +// test merged enum and namespace +namespace ns_2 { + namespace Enum {} + export const enum Enum { + ONE, + TWO + } + + export class A{ + constructor() { + "use sendable"; + } + static prop1: Enum = 0 + prop2: Enum = 1 + } +} + +print(ns_2.A.prop1) +print(new ns_2.A().prop2) \ No newline at end of file -- Gitee From d2e7e22d1d0f402feb1988b4f984dd562ef8361e Mon Sep 17 00:00:00 2001 From: ElevenDuan Date: Fri, 25 Oct 2024 16:24:24 +0800 Subject: [PATCH 2/3] Support inter-app hsp deps bytecode har to 5.0.2 Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IBJ6EU Signed-off-by: ElevenDuan Change-Id: Idb018278ae9282534f35a093f4c1d7493dd20734 --- es2panda/aot/options.cpp | 8 + es2panda/compiler/core/compileQueue.cpp | 43 +- es2panda/compiler/core/compileQueue.h | 13 +- es2panda/es2panda.cpp | 3 + .../abcinputs/bytecodehar.txt | 2 + .../bytecodehar-dynamic-import.ts | 54 + .../bytecodehar-static-import.ts | 36 + .../compileContextInfo.json | 17 + .../bytecodehar-inter-app-hsp/importfile1.ts | 16 + .../bytecodehar-inter-app-hsp/importfile2.ts | 16 + .../bytecodehar-inter-app-hsp/importfile3.ts | 16 + .../bytecodehar-inter-app-hsp/importfile4.ts | 16 + .../inter-app-hsp-file-exec-expected.pa.txt | 1372 +++++++++++++++++ .../inter-app-hsp-file-exec.ts | 20 + .../bytecodehar-inter-app-hsp/recordnames.txt | 7 + es2panda/util/commonUtil.cpp | 53 + es2panda/util/commonUtil.h | 5 + es2panda/util/helpers.h | 6 + 18 files changed, 1685 insertions(+), 18 deletions(-) create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/abcinputs/bytecodehar.txt create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-dynamic-import.ts create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-static-import.ts create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/compileContextInfo.json create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile1.ts create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile2.ts create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile3.ts create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile4.ts create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec-expected.pa.txt create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec.ts create mode 100644 es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/recordnames.txt diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 066a81030..062b1303b 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -305,6 +305,14 @@ void Options::ParseCompileContextInfo(const std::string compileContextInfoPath) std::cerr << "The input json file '" << compileContextInfoPath << "' content type is incorrect" << std::endl; return; } + if (compileContextInfoJson.contains("needModifyRecord") && + compileContextInfoJson["needModifyRecord"].is_boolean()) { + compilerOptions_.compileContextInfo.needModifyRecord = compileContextInfoJson["needModifyRecord"]; + } + if (compileContextInfoJson.contains("bundleName") && + compileContextInfoJson["bundleName"].is_string()) { + compilerOptions_.compileContextInfo.bundleName = compileContextInfoJson["bundleName"]; + } std::set externalPkgNames; for (const auto& elem : compileContextInfoJson["hspPkgNames"]) { if (elem.is_string()) { diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index 6122498d3..2369cb560 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -185,14 +185,15 @@ void CompileAbcClassJob::Run() std::string record_name = ""; compiler_.CompileAbcClass(recordId, *program, record_name); - // Update version for abc input when needed - if (options_.updatePkgVersionForAbcInput && pkgVersionUpdateRequiredInAbc_) { + // Update ohmurl for abc input when needed + if (options_.compileContextInfo.needModifyRecord || + (options_.updatePkgVersionForAbcInput && pkgVersionUpdateRequiredInAbc_)) { panda::Timer::timerStart(panda::EVENT_UPDATE_ABC_PKG_VERSION, record_name); - UpdatePackageVersion(program, options_); + UpdateImportOhmurl(program, options_); panda::Timer::timerEnd(panda::EVENT_UPDATE_ABC_PKG_VERSION, record_name); // Remove redundant strings created due to version replacement panda::Timer::timerStart(panda::EVENT_UPDATE_ABC_PROGRAM_STRING, record_name); - if (options_.removeRedundantFile && hasUpdatedVersion_) { + if (options_.removeRedundantFile && hasOhmurlBeenChanged_) { program->strings.clear(); for (const auto &[_, function] : program->function_table) { const auto &funcStringSet = function.CollectStringsFromFunctionInsns(); @@ -219,47 +220,65 @@ void CompileAbcClassJob::Run() program = nullptr; } -void CompileAbcClassJob::UpdateDynamicImportPackageVersion(panda::pandasm::Program *prog, +void CompileAbcClassJob::UpdateBundleNameOfOhmurl(std::string &ohmurl) +{ + const auto &newOhmurl = util::UpdateBundleNameIfNeeded(ohmurl, options_.compileContextInfo.bundleName, + options_.compileContextInfo.externalPkgNames); + if (newOhmurl == ohmurl) { + return; + } + SetOhmurlBeenChanged(true); + ohmurl = newOhmurl; +} + +void CompileAbcClassJob::UpdateDynamicImport(panda::pandasm::Program *prog, const std::unordered_map &pkgContextInfo) { for (auto &[name, function] : prog->function_table) { util::VisitDyanmicImports(function, [this, &prog, pkgContextInfo](std::string &ohmurl) { + if (this->options_.compileContextInfo.needModifyRecord) { + this->UpdateBundleNameOfOhmurl(ohmurl); + } const auto &newOhmurl = util::UpdatePackageVersionIfNeeded(ohmurl, pkgContextInfo); if (newOhmurl == ohmurl) { return; } - this->SetHasUpdatedVersion(true); + this->SetOhmurlBeenChanged(true); prog->strings.insert(newOhmurl); ohmurl = newOhmurl; }); } } -void CompileAbcClassJob::UpdateStaticImportPackageVersion(panda::pandasm::Program *prog, +void CompileAbcClassJob::UpdateStaticImport(panda::pandasm::Program *prog, const std::unordered_map &pkgContextInfo) { for (auto &[recordName, record] : prog->record_table) { util::VisitStaticImports(*prog, record, [this, pkgContextInfo](std::string &ohmurl) { + if (this->options_.compileContextInfo.needModifyRecord) { + this->UpdateBundleNameOfOhmurl(ohmurl); + } + const auto &newOhmurl = util::UpdatePackageVersionIfNeeded(ohmurl, pkgContextInfo); if (newOhmurl == ohmurl) { return; } - this->SetHasUpdatedVersion(true); + this->SetOhmurlBeenChanged(true); ohmurl = newOhmurl; }); } } -void CompileAbcClassJob::UpdatePackageVersion(panda::pandasm::Program *prog, - const panda::es2panda::CompilerOptions &options) +void CompileAbcClassJob::UpdateImportOhmurl(panda::pandasm::Program *prog, + const panda::es2panda::CompilerOptions &options) { bool isAccurateUpdateVersion = !options.compileContextInfo.updateVersionInfo.empty(); const std::unordered_map &pkgContextInfo = isAccurateUpdateVersion ? options.compileContextInfo.updateVersionInfo.at(abcPkgName_) : options.compileContextInfo.pkgContextInfo; // Replace for esm module static import - UpdateStaticImportPackageVersion(prog, pkgContextInfo); + UpdateStaticImport(prog, pkgContextInfo); // Replace for dynamic import - UpdateDynamicImportPackageVersion(prog, pkgContextInfo); + UpdateDynamicImport(prog, pkgContextInfo); } void PostAnalysisOptimizeFileJob::Run() diff --git a/es2panda/compiler/core/compileQueue.h b/es2panda/compiler/core/compileQueue.h index f12a49d7b..6e9b4e1c1 100644 --- a/es2panda/compiler/core/compileQueue.h +++ b/es2panda/compiler/core/compileQueue.h @@ -114,9 +114,9 @@ public: allocator_(allocator), abcPkgName_(abcPkgName), pkgVersionUpdateRequiredInAbc_(pkgVersionUpdateRequiredInAbc) {}; - void SetHasUpdatedVersion(bool hasUpdatedVersion) + void SetOhmurlBeenChanged(bool hasOhmurlBeenChanged) { - hasUpdatedVersion_ = hasUpdatedVersion; + hasOhmurlBeenChanged_ = hasOhmurlBeenChanged; } NO_COPY_SEMANTIC(CompileAbcClassJob); @@ -126,11 +126,12 @@ public: void Run() override; private: - void UpdatePackageVersion(panda::pandasm::Program *prog, const CompilerOptions &options); - void UpdateDynamicImportPackageVersion(panda::pandasm::Program *prog, + void UpdateImportOhmurl(panda::pandasm::Program *prog, const CompilerOptions &options); + void UpdateDynamicImport(panda::pandasm::Program *prog, const std::unordered_map &pkgContextInfo); - void UpdateStaticImportPackageVersion(panda::pandasm::Program *prog, + void UpdateStaticImport(panda::pandasm::Program *prog, const std::unordered_map &pkgContextInfo); + void UpdateBundleNameOfOhmurl(std::string &ohmurl); const uint32_t classId_; const es2panda::CompilerOptions &options_; @@ -139,7 +140,7 @@ private: panda::ArenaAllocator *allocator_; std::string abcPkgName_; bool pkgVersionUpdateRequiredInAbc_; - bool hasUpdatedVersion_ {false}; + bool hasOhmurlBeenChanged_ {false}; }; class PostAnalysisOptimizeFileJob : public util::WorkerJob { diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index f6383620f..9d1c69f0a 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -110,6 +110,9 @@ void Compiler::CompileAbcFileInParallel(SourceFile *src, const CompilerOptions & std::cerr << " [" << src->fileName << "]" << std::endl; throw; } + if (options.compileContextInfo.needModifyRecord) { + abcToAsmCompiler_->SetBundleName(options.compileContextInfo.bundleName); + } auto *compileAbcClassQueue = new compiler::CompileAbcClassQueue(options.abcClassThreadCount, options, diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/abcinputs/bytecodehar.txt b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/abcinputs/bytecodehar.txt new file mode 100644 index 000000000..2bed2a047 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/abcinputs/bytecodehar.txt @@ -0,0 +1,2 @@ +bytecodehar-dynamic-import.ts +bytecodehar-static-import.ts diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-dynamic-import.ts b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-dynamic-import.ts new file mode 100644 index 000000000..8be6bf83a --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-dynamic-import.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 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 let test: string = "test"; + +function testReplacementWoAt() { + import("@normalized:N&module&bundle&lib/importfile1&1.0.0"); + import("@normalized:N&module&bundle&lib/importfile1&"); + import("@normalized:N&&bundle&lib/importfile1&1.0.0"); + import("@normalized:N&&bundle&lib/importfile1&"); + + // No-effect since no version info in compileContextInfo.json + import("@normalized:N&&&lib2/importfile3&"); +} + +function testReplacementWithAt() { + import("@normalized:N&module&&@ohos/lib/importfile2&1.0.0"); + import("@normalized:N&module&&@ohos/lib/importfile2&"); + import("@normalized:N&&&@ohos/lib/importfile2&1.0.0"); + import("@normalized:N&&&@ohos/lib/importfile2&"); + + // No-effect since no version info in compileContextInfo.json + import("@normalized:N&&&@ohos/lib2/importfile4&"); +} + +function testNonOhmurl() { + import("aaa"); +} + +function testNonConst() { + // Take effect only under release due to bcopt + let a = "@normalized:N&&bundle&lib/importfile1&" + import(a); + + a = "@normalized:N&&bundle&lib/importfile1&"; + let b = "@normalized:N&&bundle&lib/importfile1&"; + import(a); + + a = "@normalized:N&&bundle&lib/importfile1&"; + "@normalized:N&&bundle&lib/importfile1&"; + import(a); +} diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-static-import.ts b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-static-import.ts new file mode 100644 index 000000000..a475a9636 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/bytecodehar-static-import.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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. + */ + +// testReplacementWoAt +import * as a from "@normalized:N&module&bundle&lib/importfile1&1.0.0"; +import * as b from "@normalized:N&module&bundle&lib/importfile1&"; +import * as c from "@normalized:N&&bundle&lib/importfile1&1.0.0"; +import * as d from "@normalized:N&&bundle&lib/importfile1&"; + +// No-effect since no version info in compileContextInfo.json +import * as e from "@normalized:N&&&lib2/importfile3&"; + +//testReplacementWithAt +import * as f from "@normalized:N&module&&@ohos/lib/importfile2&1.0.0"; +import * as g from "@normalized:N&module&&@ohos/lib/importfile2&"; +import * as h from "@normalized:N&&&@ohos/lib/importfile2&1.0.0"; +import * as i from "@normalized:N&&&@ohos/lib/importfile2&"; + +// No-effect since no version info in compileContextInfo.json +import * as j from "@normalized:N&&&@ohos/lib2/importfile4&"; + +function foo() { + print([a, b, c, d, e, f, g, h, i, j]); +} diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/compileContextInfo.json b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/compileContextInfo.json new file mode 100644 index 000000000..f7127bcf7 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/compileContextInfo.json @@ -0,0 +1,17 @@ +{ + "compileEntries": [ + "com.inter_app.hsp&myapp/inter-app-hsp-file-exec&" + ], + "hspPkgNames": [ + "lib", + "@ohos/lib" + ], + "updateVersionInfo": { + "bytecodehar": { + "lib": "2.0.0", + "@ohos/lib": "2.0.0" + } + }, + "needModifyRecord": true, + "bundleName": "com.inter_app.hsp" +} diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile1.ts b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile1.ts new file mode 100644 index 000000000..90b72d939 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile1.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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 const test1: boolean = true; \ No newline at end of file diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile2.ts b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile2.ts new file mode 100644 index 000000000..f53bd6ea8 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile2.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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 const test2: boolean = true; \ No newline at end of file diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile3.ts b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile3.ts new file mode 100644 index 000000000..331af037e --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile3.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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 const test3: boolean = true; \ No newline at end of file diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile4.ts b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile4.ts new file mode 100644 index 000000000..048946bd9 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/importfile4.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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 const test4: boolean = true; \ No newline at end of file diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec-expected.pa.txt b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec-expected.pa.txt new file mode 100644 index 000000000..72401a9d1 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec-expected.pa.txt @@ -0,0 +1,1372 @@ +All Dependency Files: +program_file: bytecodehar-abcinput.abc +record_name: com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import& +program_file: bytecodehar-abcinput.abc +record_name: com.inter_app.hsp&bytecodehar/bytecodehar-static-import& +program_file: importfile3.ts +record_name: com.inter_app.hsp&lib2/importfile3& +program_file: importfile4.ts +record_name: com.inter_app.hsp&@ohos/lib2/importfile4& +program_file: inter-app-hsp-file-exec.ts +record_name: com.inter_app.hsp&myapp/inter-app-hsp-file-exec& + +.language ECMAScript + + +======> literal array buffer <====== +======> strings <====== + +.language ECMAScript + + +======> literal array buffer <====== +======> strings <====== + +.language ECMAScript + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst(any a0, any a1, any a2) { + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl(any a0, any a1, any a2) { + lda.str aaa + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt(any a0, any a1, any a2) { + lda.str @normalized:N&module&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&module&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&com.inter_app.hsp&@ohos/lib2/importfile4& + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt(any a0, any a1, any a2) { + lda.str @normalized:N&module&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&module&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&com.inter_app.hsp&lib2/importfile3& + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x4 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst, 0x0 + definefunc 0x1, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl, 0x0 + definefunc 0x2, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt, 0x0 + definefunc 0x3, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt, 0x0 + lda.str test + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&_2004 +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&_2008 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"@normalized:N&&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&&bundle&lib/importfile1&2.0.0"; "@normalized:N&&com.inter_app.hsp&@ohos/lib2/importfile4&"; "@normalized:N&&com.inter_app.hsp&lib2/importfile3&"; "@normalized:N&module&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&module&bundle&lib/importfile1&2.0.0"; "aaa"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt"; "test"; +.language ECMAScript + +slotNum = 0x18 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.#*#foo(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + createemptyarray 0x1 + sta v1 + ldlexvar 0x0, 0x0 + sta v2 + throw.undefinedifholewithname a + lda v2 + stownbyindex 0x2, v1, 0x0 + ldlexvar 0x0, 0x1 + sta v2 + throw.undefinedifholewithname b + lda v2 + stownbyindex 0x4, v1, 0x1 + ldlexvar 0x0, 0x2 + sta v2 + throw.undefinedifholewithname c + lda v2 + stownbyindex 0x6, v1, 0x2 + ldlexvar 0x0, 0x3 + sta v2 + throw.undefinedifholewithname d + lda v2 + stownbyindex 0x8, v1, 0x3 + ldlexvar 0x0, 0x4 + sta v2 + throw.undefinedifholewithname e + lda v2 + stownbyindex 0xa, v1, 0x4 + ldlexvar 0x0, 0x5 + sta v2 + throw.undefinedifholewithname f + lda v2 + stownbyindex 0xc, v1, 0x5 + ldlexvar 0x0, 0x6 + sta v2 + throw.undefinedifholewithname g + lda v2 + stownbyindex 0xe, v1, 0x6 + ldlexvar 0x0, 0x7 + sta v2 + throw.undefinedifholewithname h + lda v2 + stownbyindex 0x10, v1, 0x7 + ldlexvar 0x0, 0x8 + sta v2 + throw.undefinedifholewithname i + lda v2 + stownbyindex 0x12, v1, 0x8 + ldlexvar 0x0, 0x9 + sta v2 + throw.undefinedifholewithname j + lda v2 + stownbyindex 0x14, v1, 0x9 + lda v0 + callarg1 0x16, v1 + ldundefined + returnundefined +} + +slotNum = 0x1 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.func_main_0(any a0, any a1, any a2) { + newlexenv 0xa + definefunc 0x0, com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.#*#foo, 0x0 + getmodulenamespace 0x0 + stlexvar 0x0, 0x0 + getmodulenamespace 0x1 + stlexvar 0x0, 0x1 + getmodulenamespace 0x2 + stlexvar 0x0, 0x2 + getmodulenamespace 0x3 + stlexvar 0x0, 0x3 + getmodulenamespace 0x4 + stlexvar 0x0, 0x4 + getmodulenamespace 0x5 + stlexvar 0x0, 0x5 + getmodulenamespace 0x6 + stlexvar 0x0, 0x6 + getmodulenamespace 0x7 + stlexvar 0x0, 0x7 + getmodulenamespace 0x8 + stlexvar 0x0, 0x8 + getmodulenamespace 0x9 + stlexvar 0x0, 0x9 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-static-import&_2044 +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-static-import&_2048 +{ + index: 0 + tag: 2 + val: 10 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&module&bundle&lib/importfile1&2.0.0 +}, +{ + index: 2 + tag: 5 + val: @normalized:N&module&bundle&lib/importfile1&2.0.0 +}, +{ + index: 3 + tag: 5 + val: @normalized:N&&bundle&lib/importfile1&2.0.0 +}, +{ + index: 4 + tag: 5 + val: @normalized:N&&bundle&lib/importfile1&2.0.0 +}, +{ + index: 5 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&lib2/importfile3& +}, +{ + index: 6 + tag: 5 + val: @normalized:N&module&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 7 + tag: 5 + val: @normalized:N&module&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 8 + tag: 5 + val: @normalized:N&&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 9 + tag: 5 + val: @normalized:N&&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 10 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&@ohos/lib2/importfile4& +}, +{ + index: 11 + tag: 2 + val: 0 +}, +{ + index: 12 + tag: 2 + val: 10 +}, +{ + index: 13 + tag: 5 + val: a +}, +{ + index: 14 + tag: 9 + val: 0 +}, +{ + index: 15 + tag: 5 + val: b +}, +{ + index: 16 + tag: 9 + val: 1 +}, +{ + index: 17 + tag: 5 + val: c +}, +{ + index: 18 + tag: 9 + val: 2 +}, +{ + index: 19 + tag: 5 + val: d +}, +{ + index: 20 + tag: 9 + val: 3 +}, +{ + index: 21 + tag: 5 + val: e +}, +{ + index: 22 + tag: 9 + val: 4 +}, +{ + index: 23 + tag: 5 + val: f +}, +{ + index: 24 + tag: 9 + val: 5 +}, +{ + index: 25 + tag: 5 + val: g +}, +{ + index: 26 + tag: 9 + val: 6 +}, +{ + index: 27 + tag: 5 + val: h +}, +{ + index: 28 + tag: 9 + val: 7 +}, +{ + index: 29 + tag: 5 + val: i +}, +{ + index: 30 + tag: 9 + val: 8 +}, +{ + index: 31 + tag: 5 + val: j +}, +{ + index: 32 + tag: 9 + val: 9 +}, +{ + index: 33 + tag: 2 + val: 0 +}, +{ + index: 34 + tag: 2 + val: 0 +}, +{ + index: 35 + tag: 2 + val: 0 +}, +======> strings <====== +"a"; "b"; "c"; "com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.#*#foo"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "print"; +.language ECMAScript + +slotNum = 0x0 +.function any bundle&lib/importfile1&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot bundle&lib/importfile1&2.0.0_0 +------------------------------------ +slot bundle&lib/importfile1&2.0.0_1 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test1 +}, +{ + index: 5 + tag: 5 + val: test1 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +slotNum = 0x0 +.function any com.inter_app.hsp&@ohos/lib/importfile2&2.0.0.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&@ohos/lib/importfile2&2.0.0_0 +------------------------------------ +slot com.inter_app.hsp&@ohos/lib/importfile2&2.0.0_1 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test2 +}, +{ + index: 5 + tag: 5 + val: test2 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +slotNum = 0x0 +.function any com.inter_app.hsp&lib2/importfile3&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&lib2/importfile3&_0 +------------------------------------ +slot com.inter_app.hsp&lib2/importfile3&_1 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test3 +}, +{ + index: 5 + tag: 5 + val: test3 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +slotNum = 0x0 +.function any com.inter_app.hsp&@ohos/lib2/importfile4&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&@ohos/lib2/importfile4&_0 +------------------------------------ +slot com.inter_app.hsp&@ohos/lib2/importfile4&_1 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test4 +}, +{ + index: 5 + tag: 5 + val: test4 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +slotNum = 0xa +.function any com.inter_app.hsp&myapp/inter-app-hsp-file-exec&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + getmodulenamespace 0x0 + sta v0 + getmodulenamespace 0x1 + sta v1 + tryldglobalbyname 0x0, print + sta v2 + lda v0 + ldobjbyname 0x1, test + sta v0 + lda v2 + callarg1 0x3, v0 + tryldglobalbyname 0x5, print + sta v0 + lda v1 + ldobjbyname 0x6, test + sta v1 + lda v0 + callarg1 0x8, v1 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&myapp/inter-app-hsp-file-exec&_0 +------------------------------------ +slot com.inter_app.hsp&myapp/inter-app-hsp-file-exec&_1 +{ + index: 0 + tag: 2 + val: 2 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import& +}, +{ + index: 2 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&bytecodehar/bytecodehar-static-import& +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 2 + val: 2 +}, +{ + index: 5 + tag: 5 + val: bytecodeharDynamicImport +}, +{ + index: 6 + tag: 9 + val: 0 +}, +{ + index: 7 + tag: 5 + val: bytecodeharStaticImport +}, +{ + index: 8 + tag: 9 + val: 1 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"print"; "test"; +.language ECMAScript + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst(any a0, any a1, any a2) { + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl(any a0, any a1, any a2) { + lda.str aaa + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt(any a0, any a1, any a2) { + lda.str @normalized:N&module&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&module&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&&@ohos/lib/importfile2&2.0.0 + dynamicimport + lda.str @normalized:N&&com.inter_app.hsp&@ohos/lib2/importfile4& + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x0 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt(any a0, any a1, any a2) { + lda.str @normalized:N&module&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&module&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&bundle&lib/importfile1&2.0.0 + dynamicimport + lda.str @normalized:N&&com.inter_app.hsp&lib2/importfile3& + dynamicimport + ldundefined + returnundefined +} + +slotNum = 0x4 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.func_main_0(any a0, any a1, any a2) { + definefunc 0x0, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst, 0x0 + definefunc 0x1, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl, 0x0 + definefunc 0x2, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt, 0x0 + definefunc 0x3, com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt, 0x0 + lda.str test + stmodulevar 0x0 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&_2004 +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&_2008 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test +}, +{ + index: 5 + tag: 5 + val: test +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== +"@normalized:N&&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&&bundle&lib/importfile1&2.0.0"; "@normalized:N&&com.inter_app.hsp&@ohos/lib2/importfile4&"; "@normalized:N&&com.inter_app.hsp&lib2/importfile3&"; "@normalized:N&module&&@ohos/lib/importfile2&2.0.0"; "@normalized:N&module&bundle&lib/importfile1&2.0.0"; "aaa"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonConst"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testNonOhmurl"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWithAt"; "com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&.#*#testReplacementWoAt"; "test"; +.language ECMAScript + +slotNum = 0x18 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.#*#foo(any a0, any a1, any a2) { + tryldglobalbyname 0x0, print + sta v0 + createemptyarray 0x1 + sta v1 + ldlexvar 0x0, 0x0 + sta v2 + throw.undefinedifholewithname a + lda v2 + stownbyindex 0x2, v1, 0x0 + ldlexvar 0x0, 0x1 + sta v2 + throw.undefinedifholewithname b + lda v2 + stownbyindex 0x4, v1, 0x1 + ldlexvar 0x0, 0x2 + sta v2 + throw.undefinedifholewithname c + lda v2 + stownbyindex 0x6, v1, 0x2 + ldlexvar 0x0, 0x3 + sta v2 + throw.undefinedifholewithname d + lda v2 + stownbyindex 0x8, v1, 0x3 + ldlexvar 0x0, 0x4 + sta v2 + throw.undefinedifholewithname e + lda v2 + stownbyindex 0xa, v1, 0x4 + ldlexvar 0x0, 0x5 + sta v2 + throw.undefinedifholewithname f + lda v2 + stownbyindex 0xc, v1, 0x5 + ldlexvar 0x0, 0x6 + sta v2 + throw.undefinedifholewithname g + lda v2 + stownbyindex 0xe, v1, 0x6 + ldlexvar 0x0, 0x7 + sta v2 + throw.undefinedifholewithname h + lda v2 + stownbyindex 0x10, v1, 0x7 + ldlexvar 0x0, 0x8 + sta v2 + throw.undefinedifholewithname i + lda v2 + stownbyindex 0x12, v1, 0x8 + ldlexvar 0x0, 0x9 + sta v2 + throw.undefinedifholewithname j + lda v2 + stownbyindex 0x14, v1, 0x9 + lda v0 + callarg1 0x16, v1 + ldundefined + returnundefined +} + +slotNum = 0x1 +.function any com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.func_main_0(any a0, any a1, any a2) { + newlexenv 0xa + definefunc 0x0, com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.#*#foo, 0x0 + getmodulenamespace 0x0 + stlexvar 0x0, 0x0 + getmodulenamespace 0x1 + stlexvar 0x0, 0x1 + getmodulenamespace 0x2 + stlexvar 0x0, 0x2 + getmodulenamespace 0x3 + stlexvar 0x0, 0x3 + getmodulenamespace 0x4 + stlexvar 0x0, 0x4 + getmodulenamespace 0x5 + stlexvar 0x0, 0x5 + getmodulenamespace 0x6 + stlexvar 0x0, 0x6 + getmodulenamespace 0x7 + stlexvar 0x0, 0x7 + getmodulenamespace 0x8 + stlexvar 0x0, 0x8 + getmodulenamespace 0x9 + stlexvar 0x0, 0x9 + ldundefined + returnundefined +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-static-import&_2044 +------------------------------------ +slot com.inter_app.hsp&bytecodehar/bytecodehar-static-import&_2048 +{ + index: 0 + tag: 2 + val: 10 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&module&bundle&lib/importfile1&2.0.0 +}, +{ + index: 2 + tag: 5 + val: @normalized:N&module&bundle&lib/importfile1&2.0.0 +}, +{ + index: 3 + tag: 5 + val: @normalized:N&&bundle&lib/importfile1&2.0.0 +}, +{ + index: 4 + tag: 5 + val: @normalized:N&&bundle&lib/importfile1&2.0.0 +}, +{ + index: 5 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&lib2/importfile3& +}, +{ + index: 6 + tag: 5 + val: @normalized:N&module&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 7 + tag: 5 + val: @normalized:N&module&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 8 + tag: 5 + val: @normalized:N&&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 9 + tag: 5 + val: @normalized:N&&&@ohos/lib/importfile2&2.0.0 +}, +{ + index: 10 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&@ohos/lib2/importfile4& +}, +{ + index: 11 + tag: 2 + val: 0 +}, +{ + index: 12 + tag: 2 + val: 10 +}, +{ + index: 13 + tag: 5 + val: a +}, +{ + index: 14 + tag: 9 + val: 0 +}, +{ + index: 15 + tag: 5 + val: b +}, +{ + index: 16 + tag: 9 + val: 1 +}, +{ + index: 17 + tag: 5 + val: c +}, +{ + index: 18 + tag: 9 + val: 2 +}, +{ + index: 19 + tag: 5 + val: d +}, +{ + index: 20 + tag: 9 + val: 3 +}, +{ + index: 21 + tag: 5 + val: e +}, +{ + index: 22 + tag: 9 + val: 4 +}, +{ + index: 23 + tag: 5 + val: f +}, +{ + index: 24 + tag: 9 + val: 5 +}, +{ + index: 25 + tag: 5 + val: g +}, +{ + index: 26 + tag: 9 + val: 6 +}, +{ + index: 27 + tag: 5 + val: h +}, +{ + index: 28 + tag: 9 + val: 7 +}, +{ + index: 29 + tag: 5 + val: i +}, +{ + index: 30 + tag: 9 + val: 8 +}, +{ + index: 31 + tag: 5 + val: j +}, +{ + index: 32 + tag: 9 + val: 9 +}, +{ + index: 33 + tag: 2 + val: 0 +}, +{ + index: 34 + tag: 2 + val: 0 +}, +{ + index: 35 + tag: 2 + val: 0 +}, +======> strings <====== +"a"; "b"; "c"; "com.inter_app.hsp&bytecodehar/bytecodehar-static-import&.#*#foo"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "print"; +.language ECMAScript + +slotNum = 0x0 +.function any com.inter_app.hsp&lib2/importfile3&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&lib2/importfile3&_0 +------------------------------------ +slot com.inter_app.hsp&lib2/importfile3&_1 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test3 +}, +{ + index: 5 + tag: 5 + val: test3 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +slotNum = 0x0 +.function any com.inter_app.hsp&@ohos/lib2/importfile4&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + ldtrue + stmodulevar 0x0 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&@ohos/lib2/importfile4&_0 +------------------------------------ +slot com.inter_app.hsp&@ohos/lib2/importfile4&_1 +{ + index: 0 + tag: 2 + val: 0 +}, +{ + index: 1 + tag: 2 + val: 0 +}, +{ + index: 2 + tag: 2 + val: 0 +}, +{ + index: 3 + tag: 2 + val: 1 +}, +{ + index: 4 + tag: 5 + val: test4 +}, +{ + index: 5 + tag: 5 + val: test4 +}, +{ + index: 6 + tag: 2 + val: 0 +}, +{ + index: 7 + tag: 2 + val: 0 +}, +======> strings <====== + +.language ECMAScript + +slotNum = 0xa +.function any com.inter_app.hsp&myapp/inter-app-hsp-file-exec&.func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + getmodulenamespace 0x0 + sta v0 + getmodulenamespace 0x1 + sta v1 + tryldglobalbyname 0x0, print + sta v2 + lda v0 + ldobjbyname 0x1, test + sta v0 + lda v2 + callarg1 0x3, v0 + tryldglobalbyname 0x5, print + sta v0 + lda v1 + ldobjbyname 0x6, test + sta v1 + lda v0 + callarg1 0x8, v1 + ldundefined + returnundefined +label_2: +} + + +======> literal array buffer <====== +------------------------------------ +slot com.inter_app.hsp&myapp/inter-app-hsp-file-exec&_0 +------------------------------------ +slot com.inter_app.hsp&myapp/inter-app-hsp-file-exec&_1 +{ + index: 0 + tag: 2 + val: 2 +}, +{ + index: 1 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import& +}, +{ + index: 2 + tag: 5 + val: @normalized:N&&com.inter_app.hsp&bytecodehar/bytecodehar-static-import& +}, +{ + index: 3 + tag: 2 + val: 0 +}, +{ + index: 4 + tag: 2 + val: 2 +}, +{ + index: 5 + tag: 5 + val: bytecodeharDynamicImport +}, +{ + index: 6 + tag: 9 + val: 0 +}, +{ + index: 7 + tag: 5 + val: bytecodeharStaticImport +}, +{ + index: 8 + tag: 9 + val: 1 +}, +{ + index: 9 + tag: 2 + val: 0 +}, +{ + index: 10 + tag: 2 + val: 0 +}, +{ + index: 11 + tag: 2 + val: 0 +}, +======> strings <====== +"print"; "test"; diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec.ts b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec.ts new file mode 100644 index 000000000..a3aced5a8 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/inter-app-hsp-file-exec.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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 * as bytecodeharDynamicImport from "@normalized:N&&com.inter_app.hsp&bytecodehar/bytecodehar-dynamic-import&"; +import * as bytecodeharStaticImport from "@normalized:N&&com.inter_app.hsp&bytecodehar/bytecodehar-static-import&"; + +print(bytecodeharDynamicImport.test) +print(bytecodeharStaticImport.test) \ No newline at end of file diff --git a/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/recordnames.txt b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/recordnames.txt new file mode 100644 index 000000000..7fff897e3 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/projects/bytecodehar-inter-app-hsp/recordnames.txt @@ -0,0 +1,7 @@ +bytecodehar-dynamic-import:&bytecodehar/bytecodehar-dynamic-import& +bytecodehar-static-import:&bytecodehar/bytecodehar-static-import& +importfile1:bundle&lib/importfile1&2.0.0 +importfile2:com.inter_app.hsp&@ohos/lib/importfile2&2.0.0 +importfile3:com.inter_app.hsp&lib2/importfile3& +importfile4:com.inter_app.hsp&@ohos/lib2/importfile4& +inter-app-hsp-file-exec:com.inter_app.hsp&myapp/inter-app-hsp-file-exec& diff --git a/es2panda/util/commonUtil.cpp b/es2panda/util/commonUtil.cpp index 95eb70578..d3c98515c 100644 --- a/es2panda/util/commonUtil.cpp +++ b/es2panda/util/commonUtil.cpp @@ -16,6 +16,7 @@ #include "commonUtil.h" #include +#include #include "util/helpers.h" @@ -41,6 +42,20 @@ std::vector Split(const std::string &str, const char delimiter) return items; } +std::string GetStringByVectorElementsWithDelimiter(const std::vector &vec, const char delimiter) +{ + std::ostringstream oss; + auto it = vec.begin(); + if (it != vec.end()) { + oss << *it; + ++it; + } + for (; it != vec.end(); ++it) { + oss << delimiter << *it; + } + return oss.str(); +} + std::string GetPkgNameFromNormalizedImport(const std::string &normalizedImport) { std::string pkgName {}; @@ -119,6 +134,44 @@ std::string UpdatePackageVersionIfNeeded(const std::string &ohmurl, return ohmurl.substr(0, versionStart + 1) + iter->second.version; } +/** + * If a Har package is dependent of a cross-app Hsp, its ohmurl need to contain the bundleName of this cross-app Hsp. + * Since Har's ohmurl doesn't contain bundleName during its own compilation, the bundleName need to be added during + * the compilation of cross-app Hsp. + */ +std::string UpdateBundleNameIfNeeded(std::string &ohmurl, const std::string &bundleName, + const std::set &externalPkgNames) +{ + // Input ohmurl format: + // @normalized:{N|Y}&[module name]&[bundle name]&{|<@package/name>}/{import_path}&[version] + if (ohmurl.find(util::NORMALIZED) != 0) { + return ohmurl; + } + + std::vector items = Split(ohmurl, NORMALIZED_OHMURL_SEPARATOR); + // Incorrect ohmurl format: The quantity of '&' is incorrect + if (items.size() <= VERSION_POS) { + return ohmurl; + } + /** + * If an ohmurl already contains [bundle name], it means its not from a Har, so there's no need to updated its + * [bundle name]. + */ + if (!items[BUNDLE_NAME_POS].empty()) { + return ohmurl; + } + /** + * The hsp package don't compile into the current abc file. + * Ohmurl of both Har and in-app Hsp don't contain [bundle name], need to further screen out Hsp. + */ + if (IsExternalPkgNames(ohmurl, externalPkgNames)) { + return ohmurl; + } + + items[BUNDLE_NAME_POS] = bundleName; + return GetStringByVectorElementsWithDelimiter(items, NORMALIZED_OHMURL_SEPARATOR); +} + bool RecordNotGeneratedFromBytecode(std::string recordName) { return recordName.find(util::CHAR_VERTICAL_LINE) == std::string::npos; diff --git a/es2panda/util/commonUtil.h b/es2panda/util/commonUtil.h index 6875f9618..0883d189e 100644 --- a/es2panda/util/commonUtil.h +++ b/es2panda/util/commonUtil.h @@ -38,6 +38,7 @@ const std::string NPM_ENTRIES = "npmEntries.txt"; const std::string IS_COMMONJS = "isCommonjs"; // The format of ohmurl for non-SO files are start with '@normalized:N'. const std::string NORMALIZED_OHMURL_NOT_SO = "@normalized:N"; +const std::string NORMALIZED = "@normalized:"; const std::string MODULE_RECORD_IDX = "moduleRecordIdx"; const std::string GLOBAL_TYPE_NAME = "_GLOBAL"; @@ -46,17 +47,21 @@ constexpr char NORMALIZED_OHMURL_PREFIX = '@'; constexpr char SLASH_TAG = '/'; constexpr char CHAR_VERTICAL_LINE = '|'; +constexpr size_t MODULE_NAME_POS = 1U; constexpr size_t BUNDLE_NAME_POS = 2U; constexpr size_t NORMALIZED_IMPORT_POS = 3U; constexpr size_t VERSION_POS = 4U; std::vector Split(const std::string &str, const char delimiter); +std::string GetStringByVectorElementsWithDelimiter(const std::vector &vec, const char delimiter); bool IsExternalPkgNames(const std::string &ohmurl, const std::set &externalPkgNames); std::string GetRecordNameFromNormalizedOhmurl(const std::string &ohmurl); std::string GetPkgNameFromNormalizedOhmurl(const std::string &ohmurl); std::string GetPkgNameFromNormalizedImport(const std::string &normalizedImport); std::string UpdatePackageVersionIfNeeded(const std::string &ohmurl, const std::unordered_map &pkgContextInfo); +std::string UpdateBundleNameIfNeeded(std::string &ohmurl, const std::string &bundleName, + const std::set &externalPkgNames); bool RecordNotGeneratedFromBytecode(std::string recordName); template diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index 9b9818b1a..6d81654de 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -54,6 +54,12 @@ struct CompileContextInfo { // The key of updateVersionInfo is the package name for an abc file, and the value contains the name of its // dependent pacakge and corresponding package version which need to update version. std::unordered_map> updateVersionInfo; + /** + * When there is an abc file as input and needModifyRecord is true, it is necessary to modify the recordName + * in abc2program and modify the ohmurl for dynamic and static imports. + **/ + bool needModifyRecord {false}; + std::string bundleName {}; }; } // namespace panda::es2panda -- Gitee From b3885fa1beb67a03041db339f64acb8ff32eee72 Mon Sep 17 00:00:00 2001 From: ElevenDuan Date: Fri, 17 Jan 2025 17:24:52 +0800 Subject: [PATCH 3/3] Fix commonjs require json file failed in runtime Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IBJDU7 Signed-off-by: ElevenDuan Change-Id: I4eabf3b4ec188ca24d87e7dc2d32ba79762c1538 --- es2panda/aot/resolveDepsRelation.cpp | 10 +++-- es2panda/aot/resolveDepsRelation.h | 4 +- .../commonjs-say.js | 3 +- .../deps-json.json | 3 ++ .../hap-file-exec-expected.pa.txt | 44 ++++++++++++++----- .../recordnames.txt | 1 + es2panda/test/runner.py | 6 +++ es2panda/util/commonUtil.h | 1 + 8 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/deps-json.json diff --git a/es2panda/aot/resolveDepsRelation.cpp b/es2panda/aot/resolveDepsRelation.cpp index c52a5db3e..eefd92464 100644 --- a/es2panda/aot/resolveDepsRelation.cpp +++ b/es2panda/aot/resolveDepsRelation.cpp @@ -19,10 +19,14 @@ namespace panda::es2panda::aot { -bool DepsRelationResolver::CollectCommonjsRecords(const std::vector &fieldList, - const std::string &progKey, const std::string &recordName) +bool DepsRelationResolver::CollectCommonjsAndJsonRecords(const std::vector &fieldList, + const std::string &progKey, const std::string &recordName) { for (const auto &field: fieldList) { + if (field.name == util::JSON_FilE_CONTENT) { + resolvedDepsRelation_[progKey].insert(recordName); + return true; + } if (field.name.find(util::IS_COMMONJS) == std::string::npos) { continue; } @@ -50,7 +54,7 @@ void DepsRelationResolver::FillRecord2ProgramMap(std::unordered_map &record2ProgramMap); - bool CollectCommonjsRecords(const std::vector &fieldList, - const std::string &progKey, const std::string &recordName); + bool CollectCommonjsAndJsonRecords(const std::vector &fieldList, + const std::string &progKey, const std::string &recordName); void CollectDepsIfNeeded(const std::string &ohmurl); void DumpDepsRelations(); diff --git a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/commonjs-say.js b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/commonjs-say.js index 8b3edc137..d3233fb4e 100644 --- a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/commonjs-say.js +++ b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/commonjs-say.js @@ -13,8 +13,9 @@ * limitations under the License. */ +var json = require('./deps-json.json') function hi() { - return "hello require"; + return "hello require" + json.test; } module.exports.hi = hi diff --git a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/deps-json.json b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/deps-json.json new file mode 100644 index 000000000..238f6a270 --- /dev/null +++ b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/deps-json.json @@ -0,0 +1,3 @@ +{ + "test": "123" +} diff --git a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt index f9c9241a4..6bd5bdca4 100644 --- a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt +++ b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/hap-file-exec-expected.pa.txt @@ -364,27 +364,39 @@ slot &@ohos/bytecodehar2/bytecodehar2-file2&2.0.0_1186 .language ECMAScript -slotNum = 0x5 +slotNum = 0x7 .function any commonjs-say.#*#(any a0, any a1, any a2, any a3, any a4, any a5, any a6, any a7) { label_1: label_0: + newlexenv 0x1 definefunc 0x0, commonjs-say.#**#hi, 0x0 sta v0 + ldundefined + stlexvar 0x0, 0x0 + lda.str ./deps-json.json + sta v1 + lda a4 + callarg1 0x1, v1 + stlexvar 0x0, 0x0 lda a5 - ldobjbyname 0x1, exports + ldobjbyname 0x3, exports sta v1 lda v0 - stobjbyname 0x3, hi, v1 + stobjbyname 0x5, hi, v1 ldundefined returnundefined label_2: } -slotNum = 0x0 +slotNum = 0x3 .function any commonjs-say.#**#hi(any a0, any a1, any a2) { label_1: label_0: lda.str hello require + sta v0 + ldlexvar 0x0, 0x0 + ldobjbyname 0x0, test + add2 0x2, v0 return label_2: } @@ -423,7 +435,7 @@ label_2: ------------------------------------ slot commonjs-say_0 ======> strings <====== -"Reflect"; "apply"; "commonjs-say.#*#"; "commonjs-say.#**#hi"; "exports"; "hello require"; "hi"; +"./deps-json.json"; "Reflect"; "apply"; "commonjs-say.#*#"; "commonjs-say.#**#hi"; "exports"; "hello require"; "hi"; "test"; .language ECMAScript slotNum = 0x4 @@ -955,27 +967,39 @@ slot &@ohos/bytecodehar2/bytecodehar2-file1&2.0.0_1146 "&@ohos/bytecodehar2/bytecodehar2-file1&2.0.0.#*#test"; "bytecodehar2.file1.test"; "print"; .language ECMAScript -slotNum = 0x5 +slotNum = 0x7 .function any commonjs-say.#*#(any a0, any a1, any a2, any a3, any a4, any a5, any a6, any a7) { label_1: label_0: + newlexenv 0x1 definefunc 0x0, commonjs-say.#**#hi, 0x0 sta v0 + ldundefined + stlexvar 0x0, 0x0 + lda.str ./deps-json.json + sta v1 + lda a4 + callarg1 0x1, v1 + stlexvar 0x0, 0x0 lda a5 - ldobjbyname 0x1, exports + ldobjbyname 0x3, exports sta v1 lda v0 - stobjbyname 0x3, hi, v1 + stobjbyname 0x5, hi, v1 ldundefined returnundefined label_2: } -slotNum = 0x0 +slotNum = 0x3 .function any commonjs-say.#**#hi(any a0, any a1, any a2) { label_1: label_0: lda.str hello require + sta v0 + ldlexvar 0x0, 0x0 + ldobjbyname 0x0, test + add2 0x2, v0 return label_2: } @@ -1014,7 +1038,7 @@ label_2: ------------------------------------ slot commonjs-say_0 ======> strings <====== -"Reflect"; "apply"; "commonjs-say.#*#"; "commonjs-say.#**#hi"; "exports"; "hello require"; "hi"; +"./deps-json.json"; "Reflect"; "apply"; "commonjs-say.#*#"; "commonjs-say.#**#hi"; "exports"; "hello require"; "hi"; "test"; .language ECMAScript slotNum = 0x4 diff --git a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/recordnames.txt b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/recordnames.txt index 7f1a91dfa..1ec3d9ee2 100644 --- a/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/recordnames.txt +++ b/es2panda/test/compiler/bytecodehar/js/projects/bytecodehar-dependency-resolve/recordnames.txt @@ -7,3 +7,4 @@ sourcehar-file2:&sourcehar/sourcehar-file2&2.0.0 hap-file-exec:&myapp/hap-file-exec& test-require:&myapp/test-require& say:&myapp/say& +deps-json:&myapp/deps-json& diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 9a580de96..1274479f5 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -723,6 +723,7 @@ class CompilerProjectTest(Test): self.abc_input_filenames = None self.record_names_path = os.path.join(os.path.join(self.projects_path, self.project), 'recordnames.txt') self.abc_inputs_path = os.path.join(os.path.join(self.projects_path, self.project), 'abcinputs') + self.deps_json_path = os.path.join(os.path.join(self.projects_path, self.project), 'deps-json.json') def remove_project(self, runner): project_path = runner.build_dir + "/" + self.project @@ -843,6 +844,11 @@ class CompilerProjectTest(Test): abc_files_infos[belonging_abc_input].append(file_info) else: f.writelines(file_info) + if (os.path.exists(self.deps_json_path)): + record_name = self.get_record_name(self.deps_json_path) + file_info = ('%s;%s;%s;%s;%s;%s\n' % (self.deps_json_path, record_name, 'esm', + os.path.relpath(self.deps_json_path, self.projects_path), record_name, + 'false')) self.gen_abc_input_files_infos(runner, abc_files_infos, f) f.close() diff --git a/es2panda/util/commonUtil.h b/es2panda/util/commonUtil.h index 0883d189e..8bcef4ec8 100644 --- a/es2panda/util/commonUtil.h +++ b/es2panda/util/commonUtil.h @@ -36,6 +36,7 @@ struct PkgInfo; namespace panda::es2panda::util { const std::string NPM_ENTRIES = "npmEntries.txt"; const std::string IS_COMMONJS = "isCommonjs"; +const std::string JSON_FilE_CONTENT = "jsonFileContent"; // The format of ohmurl for non-SO files are start with '@normalized:N'. const std::string NORMALIZED_OHMURL_NOT_SO = "@normalized:N"; const std::string NORMALIZED = "@normalized:"; -- Gitee