arkanalyzer 1.0.93 → 2.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Config.d.ts +7 -0
- package/lib/Config.d.ts.map +1 -1
- package/lib/Scene.d.ts +134 -170
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +412 -976
- package/lib/callgraph/algorithm/AbstractAnalysis.js +3 -2
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +2 -3
- package/lib/callgraph/model/CallGraph.js +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +1 -3
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +17 -7
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +4 -14
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +2 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +1 -2
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.js +0 -1
- package/lib/cli/commands/cg.d.ts +1 -0
- package/lib/cli/commands/cg.d.ts.map +1 -1
- package/lib/cli/commands/cg.js +22 -18
- package/lib/cli/commands/ir.d.ts +1 -0
- package/lib/cli/commands/ir.d.ts.map +1 -1
- package/lib/cli/commands/ir.js +5 -2
- package/lib/core/base/Constant.d.ts +5 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +12 -9
- package/lib/core/base/Expr.d.ts +36 -20
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +206 -94
- package/lib/core/base/Local.d.ts +10 -20
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +25 -28
- package/lib/core/base/Position.d.ts +6 -0
- package/lib/core/base/Position.d.ts.map +1 -1
- package/lib/core/base/Position.js +37 -11
- package/lib/core/base/Ref.d.ts +45 -33
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +225 -51
- package/lib/core/base/Stmt.d.ts +19 -9
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +135 -52
- package/lib/core/base/Type.d.ts +67 -4
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +391 -20
- package/lib/core/base/TypeExpr.d.ts +6 -4
- package/lib/core/base/TypeExpr.d.ts.map +1 -1
- package/lib/core/base/TypeExpr.js +34 -10
- package/lib/core/base/Value.d.ts +20 -2
- package/lib/core/base/Value.d.ts.map +1 -1
- package/lib/core/base/Value.js +12 -0
- package/lib/core/common/ArkIRTransformer.d.ts +18 -0
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +94 -75
- package/lib/core/common/ArkValueTransformer.d.ts +21 -3
- package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkValueTransformer.js +458 -266
- package/lib/core/common/Builtin.d.ts +48 -24
- package/lib/core/common/Builtin.d.ts.map +1 -1
- package/lib/core/common/Builtin.js +90 -52
- package/lib/core/common/CanonicalizerValidator.d.ts +308 -0
- package/lib/core/common/CanonicalizerValidator.d.ts.map +1 -0
- package/lib/core/common/CanonicalizerValidator.js +888 -0
- package/lib/core/common/Const.d.ts +3 -3
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +3 -3
- package/lib/core/common/DummyMainCreater.d.ts +2 -21
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +8 -105
- package/lib/core/common/IRInference.d.ts +55 -3
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +407 -126
- package/lib/core/common/IRUtils.d.ts +1 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +44 -13
- package/lib/core/common/ModelUtils.d.ts +44 -20
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +378 -208
- package/lib/core/common/SdkUtils.d.ts +35 -5
- package/lib/core/common/SdkUtils.d.ts.map +1 -1
- package/lib/core/common/SdkUtils.js +203 -59
- package/lib/core/common/SignatureCanonicalizer.d.ts +95 -0
- package/lib/core/common/SignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizer.js +116 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts +176 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.d.ts.map +1 -0
- package/lib/core/common/SignatureCanonicalizerRegistry.js +343 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts +69 -0
- package/lib/core/common/SignatureModelCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/SignatureModelCanonicalizer.js +109 -0
- package/lib/core/common/StmtUseReplacer.d.ts +1 -0
- package/lib/core/common/StmtUseReplacer.d.ts.map +1 -1
- package/lib/core/common/StmtUseReplacer.js +9 -0
- package/lib/core/common/StringUtils.d.ts +12 -1
- package/lib/core/common/StringUtils.d.ts.map +1 -1
- package/lib/core/common/StringUtils.js +36 -17
- package/lib/core/common/TempSignatureCanonicalizer.d.ts +82 -0
- package/lib/core/common/TempSignatureCanonicalizer.d.ts.map +1 -0
- package/lib/core/common/TempSignatureCanonicalizer.js +177 -0
- package/lib/core/common/TypeInference.d.ts +24 -6
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +243 -117
- package/lib/core/common/ValueUtil.d.ts +2 -1
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/common/ValueUtil.js +4 -1
- package/lib/core/graph/Cfg.d.ts.map +1 -1
- package/lib/core/graph/Cfg.js +21 -6
- package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/CfgBuilder.js +46 -33
- package/lib/core/graph/builder/IfBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/IfBuilder.js +6 -2
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +6 -2
- package/lib/core/inference/ModelInference.d.ts +24 -4
- package/lib/core/inference/ModelInference.d.ts.map +1 -1
- package/lib/core/inference/ModelInference.js +273 -79
- package/lib/core/inference/ValueInference.d.ts +3 -2
- package/lib/core/inference/ValueInference.d.ts.map +1 -1
- package/lib/core/inference/ValueInference.js +90 -40
- package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
- package/lib/core/inference/abc/AbcInference.js +28 -15
- package/lib/core/inference/arkts/ArkTsInference.d.ts +9 -3
- package/lib/core/inference/arkts/ArkTsInference.d.ts.map +1 -1
- package/lib/core/inference/arkts/ArkTsInference.js +54 -16
- package/lib/core/model/ArkClass.d.ts +192 -18
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +852 -122
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +1 -2
- package/lib/core/model/ArkField.d.ts +34 -2
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +89 -14
- package/lib/core/model/ArkFile.d.ts +72 -12
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +275 -65
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +1 -2
- package/lib/core/model/ArkMethod.d.ts +101 -15
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +252 -39
- package/lib/core/model/ArkModule.d.ts +1 -1
- package/lib/core/model/ArkModule.js +1 -1
- package/lib/core/model/ArkNamespace.d.ts +80 -10
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +309 -76
- package/lib/core/model/ArkSignature.d.ts +242 -18
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +725 -95
- package/lib/core/model/builder/ArkClassBuilder.d.ts +6 -3
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +119 -73
- package/lib/core/model/builder/ArkExportBuilder.d.ts +1 -1
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.d.ts +0 -2
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +9 -43
- package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFileBuilder.js +32 -33
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +10 -3
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +40 -26
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +3 -2
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +45 -77
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
- package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkSignatureBuilder.js +26 -3
- package/lib/core/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/BodyBuilder.js +37 -11
- package/lib/core/model/builder/builderUtils.d.ts +11 -1
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +124 -90
- package/lib/frontend/FrontendBuilder.d.ts +10 -6
- package/lib/frontend/FrontendBuilder.d.ts.map +1 -1
- package/lib/frontend/FrontendBuilder.js +19 -45
- package/lib/frontend/ModuleScene.d.ts +43 -0
- package/lib/frontend/ModuleScene.d.ts.map +1 -0
- package/lib/frontend/ModuleScene.js +143 -0
- package/lib/frontend/SceneBuildStage.d.ts +15 -0
- package/lib/frontend/SceneBuildStage.d.ts.map +1 -0
- package/lib/frontend/SceneBuildStage.js +32 -0
- package/lib/frontend/SceneBuilder.d.ts +153 -0
- package/lib/frontend/SceneBuilder.d.ts.map +1 -0
- package/lib/frontend/SceneBuilder.js +859 -0
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +0 -2
- package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -1
- package/lib/frontend/arktsFrontend/ArktsFrontend.js +0 -18
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts +17 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts.map +1 -0
- package/lib/frontend/arktsFrontend/FileBodyRemount.js +187 -0
- package/lib/frontend/common/ModuleBuilder.d.ts +4 -2
- package/lib/frontend/common/ModuleBuilder.d.ts.map +1 -1
- package/lib/frontend/common/ModuleBuilder.js +19 -9
- package/lib/frontend/cppFrontend/CppFrontend.d.ts +0 -6
- package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/CppFrontend.js +0 -56
- package/lib/frontend/cppFrontend/base/Type.d.ts +7 -0
- package/lib/frontend/cppFrontend/base/Type.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/base/Type.js +29 -0
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +56 -56
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +124 -113
- package/lib/frontend/cppFrontend/common/Builtin.d.ts +29 -19
- package/lib/frontend/cppFrontend/common/Builtin.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/Builtin.js +56 -35
- package/lib/frontend/cppFrontend/common/IRInference.d.ts +7 -2
- package/lib/frontend/cppFrontend/common/IRInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRInference.js +61 -28
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -0
- package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/IRUtils.js +22 -10
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts +19 -0
- package/lib/frontend/cppFrontend/common/ModelUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/ModelUtils.js +84 -3
- package/lib/frontend/cppFrontend/common/TypeInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/common/TypeInference.js +44 -54
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +2 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts +1 -1
- package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/inference/CxxValueInference.js +41 -5
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +18 -28
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.js +2 -3
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +2 -2
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +31 -24
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +10 -16
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +0 -2
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +19 -37
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -0
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/BodyBuilder.js +30 -3
- package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/frontend/cppFrontend/model/builder/builderUtils.js +8 -4
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -2
- package/lib/save/json/JsonSerialization.js +2 -2
- package/lib/save/source/SourceStmt.js +1 -1
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +0 -9
- package/lib/statistics/StageStatistics.d.ts +195 -0
- package/lib/statistics/StageStatistics.d.ts.map +1 -0
- package/lib/statistics/StageStatistics.js +346 -0
- package/lib/statistics/StageStatisticsReporter.d.ts +58 -0
- package/lib/statistics/StageStatisticsReporter.d.ts.map +1 -0
- package/lib/statistics/StageStatisticsReporter.js +255 -0
- package/lib/utils/Canonicalizer.d.ts +9 -2
- package/lib/utils/Canonicalizer.d.ts.map +1 -1
- package/lib/utils/Canonicalizer.js +19 -2
- package/lib/utils/CxxSceneUtils.d.ts +7 -0
- package/lib/utils/CxxSceneUtils.d.ts.map +1 -1
- package/lib/utils/CxxSceneUtils.js +10 -1
- package/lib/utils/FileUtils.d.ts +0 -1
- package/lib/utils/FileUtils.d.ts.map +1 -1
- package/lib/utils/FileUtils.js +1 -9
- package/lib/utils/HashUtils.d.ts +9 -0
- package/lib/utils/HashUtils.d.ts.map +1 -0
- package/lib/utils/HashUtils.js +65 -0
- package/lib/utils/ModuleUtils.d.ts.map +1 -1
- package/lib/utils/ModuleUtils.js +24 -5
- package/lib/utils/VisitedSegment.d.ts +23 -0
- package/lib/utils/VisitedSegment.d.ts.map +1 -0
- package/lib/utils/VisitedSegment.js +64 -0
- package/lib/utils/callGraphUtils.d.ts.map +1 -1
- package/lib/utils/callGraphUtils.js +7 -7
- package/lib/utils/getAllFiles.d.ts.map +1 -1
- package/lib/utils/getAllFiles.js +11 -8
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +16 -0
- package/lib/utils/parseArkSourceFile.d.ts +33 -0
- package/lib/utils/parseArkSourceFile.d.ts.map +1 -0
- package/lib/utils/parseArkSourceFile.js +131 -0
- package/package.json +1 -1
- package/lib/node_modules/ohos-typescript/README.OpenSource +0 -11
- package/lib/node_modules/ohos-typescript/README.md +0 -81
- package/lib/node_modules/ohos-typescript/SECURITY.md +0 -41
- package/lib/node_modules/ohos-typescript/ThirdPartyNoticeText.txt +0 -193
- package/lib/node_modules/ohos-typescript/bin/tsc +0 -2
- package/lib/node_modules/ohos-typescript/bin/tsserver +0 -2
- package/lib/node_modules/ohos-typescript/lib/README.md +0 -5
- package/lib/node_modules/ohos-typescript/lib/cancellationToken.js +0 -86
- package/lib/node_modules/ohos-typescript/lib/cs/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/de/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/es/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/fr/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/it/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/ja/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/ko/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/lib.dom.d.ts +0 -18505
- package/lib/node_modules/ohos-typescript/lib/lib.dom.iterable.d.ts +0 -341
- package/lib/node_modules/ohos-typescript/lib/lib.scripthost.d.ts +0 -327
- package/lib/node_modules/ohos-typescript/lib/lib.webworker.d.ts +0 -6192
- package/lib/node_modules/ohos-typescript/lib/lib.webworker.importscripts.d.ts +0 -26
- package/lib/node_modules/ohos-typescript/lib/lib.webworker.iterable.d.ts +0 -175
- package/lib/node_modules/ohos-typescript/lib/pl/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/pt-br/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/ru/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/tr/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/tsc.js +0 -114551
- package/lib/node_modules/ohos-typescript/lib/tsserver.js +0 -179691
- package/lib/node_modules/ohos-typescript/lib/tsserverlibrary.d.ts +0 -13648
- package/lib/node_modules/ohos-typescript/lib/tsserverlibrary.js +0 -178688
- package/lib/node_modules/ohos-typescript/lib/typesMap.json +0 -497
- package/lib/node_modules/ohos-typescript/lib/typingsInstaller.js +0 -39871
- package/lib/node_modules/ohos-typescript/lib/watchGuard.js +0 -49
- package/lib/node_modules/ohos-typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -1880
- package/lib/node_modules/ohos-typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -1880
- package/lib/utils/DependenciesSort.d.ts +0 -3
- package/lib/utils/DependenciesSort.d.ts.map +0 -1
- package/lib/utils/DependenciesSort.js +0 -72
- package/lib/utils/crypto_utils.d.ts +0 -6
- package/lib/utils/crypto_utils.d.ts.map +0 -1
- package/lib/utils/crypto_utils.js +0 -57
|
@@ -41,6 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
};
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
43
|
exports.findExportInfoInfile = exports.findArkExportInFile = exports.findArkExport = exports.findExportInfo = exports.getArkFile = exports.ModelUtils = void 0;
|
|
44
|
+
const VisitedSegment_1 = require("../../utils/VisitedSegment");
|
|
44
45
|
const Local_1 = require("../base/Local");
|
|
45
46
|
const ArkClass_1 = require("../model/ArkClass");
|
|
46
47
|
const ArkFile_1 = require("../model/ArkFile");
|
|
@@ -53,6 +54,7 @@ const logger_1 = __importStar(require("../../utils/logger"));
|
|
|
53
54
|
const path_1 = __importDefault(require("path"));
|
|
54
55
|
const TSConst_1 = require("./TSConst");
|
|
55
56
|
const ArkExportBuilder_1 = require("../model/builder/ArkExportBuilder");
|
|
57
|
+
const ArkSignatureBuilder_1 = require("../model/builder/ArkSignatureBuilder");
|
|
56
58
|
const Type_1 = require("../base/Type");
|
|
57
59
|
const Const_1 = require("./Const");
|
|
58
60
|
const ValueUtil_1 = require("./ValueUtil");
|
|
@@ -64,7 +66,26 @@ const Constant_1 = require("../base/Constant");
|
|
|
64
66
|
const Builtin_1 = require("./Builtin");
|
|
65
67
|
const EtsConst_1 = require("./EtsConst");
|
|
66
68
|
const ModuleUtils_1 = require("../../utils/ModuleUtils");
|
|
69
|
+
const SignatureCanonicalizerRegistry_1 = require("./SignatureCanonicalizerRegistry");
|
|
70
|
+
const SignatureCanonicalizer_1 = require("./SignatureCanonicalizer");
|
|
67
71
|
class ModelUtils {
|
|
72
|
+
/** @internal Get the Registry singleton (dynamic: dispose 后重建的实例不可被静态字段缓存,否则推断期查空 registry)。 */
|
|
73
|
+
static get registry() {
|
|
74
|
+
return SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @internal 取或建组件方法 stub 签名(缓存入口;className 必须在组件白名单内——调用面 generateComponentCreationStmts / ArkIRTransformer 的
|
|
78
|
+
* If/Repeat 分支,均为白名单组件名/常量)。
|
|
79
|
+
*/
|
|
80
|
+
static getOrCreateComponentMethodSig(className, methodName) {
|
|
81
|
+
const key = `${className}.${methodName}`;
|
|
82
|
+
let sig = this.componentMethodSigCache.get(key);
|
|
83
|
+
if (sig === undefined) {
|
|
84
|
+
sig = ArkSignatureBuilder_1.ArkSignatureBuilder.buildMethodSignatureFromClassNameAndMethodName(className, methodName);
|
|
85
|
+
this.componentMethodSigCache.set(key, sig);
|
|
86
|
+
}
|
|
87
|
+
return sig;
|
|
88
|
+
}
|
|
68
89
|
/*
|
|
69
90
|
* Set static field to be null, then all related objects could be freed by GC.
|
|
70
91
|
* Static field implicitArkUIBuilderMethods is only used during method body building, the dispose method should be called after build all body.
|
|
@@ -72,6 +93,8 @@ class ModelUtils {
|
|
|
72
93
|
static dispose() {
|
|
73
94
|
this.implicitArkUIBuilderMethods.clear();
|
|
74
95
|
this.popMethodSignatureCache.clear();
|
|
96
|
+
this.componentMethodSigCache.clear();
|
|
97
|
+
Builtin_1.Builtin.clearStubMethodSigCaches();
|
|
75
98
|
}
|
|
76
99
|
static getMethodSignatureFromArkClass(arkClass, methodName) {
|
|
77
100
|
for (const arkMethod of arkClass.getMethods()) {
|
|
@@ -81,49 +104,6 @@ class ModelUtils {
|
|
|
81
104
|
}
|
|
82
105
|
return null;
|
|
83
106
|
}
|
|
84
|
-
static getClassWithNameInNamespaceRecursively(className, ns) {
|
|
85
|
-
if (className === '') {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
let res = null;
|
|
89
|
-
res = ns.getClassWithName(className);
|
|
90
|
-
if (res == null) {
|
|
91
|
-
let declaringNs = ns.getDeclaringArkNamespace();
|
|
92
|
-
if (declaringNs != null) {
|
|
93
|
-
res = this.getClassWithNameInNamespaceRecursively(className, declaringNs);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
res = this.getClassInFileWithName(className, ns.getDeclaringArkFile());
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return res;
|
|
100
|
-
}
|
|
101
|
-
static getClassWithNameFromClass(className, startFrom) {
|
|
102
|
-
if (!className.includes('.')) {
|
|
103
|
-
let res = null;
|
|
104
|
-
const arkNamespace = startFrom.getDeclaringArkNamespace();
|
|
105
|
-
if (arkNamespace) {
|
|
106
|
-
res = this.getClassWithNameInNamespaceRecursively(className, arkNamespace);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
res = this.getClassInFileWithName(className, startFrom.getDeclaringArkFile());
|
|
110
|
-
}
|
|
111
|
-
return res;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
const names = className.split('.');
|
|
115
|
-
let nameSpace = this.getNamespaceWithNameFromClass(names[0], startFrom);
|
|
116
|
-
for (let i = 1; i < names.length - 1; i++) {
|
|
117
|
-
if (nameSpace) {
|
|
118
|
-
nameSpace = nameSpace.getNamespaceWithName(names[i]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (nameSpace) {
|
|
122
|
-
return nameSpace.getClassWithName(names[names.length - 1]);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
107
|
/**
|
|
128
108
|
* search class within the file that contain the given method
|
|
129
109
|
*/
|
|
@@ -138,14 +118,6 @@ class ModelUtils {
|
|
|
138
118
|
}
|
|
139
119
|
return classSearched;
|
|
140
120
|
}
|
|
141
|
-
/** search class within the given file */
|
|
142
|
-
static getClassInFileWithName(className, arkFile) {
|
|
143
|
-
let classSearched = arkFile.getClassWithName(className);
|
|
144
|
-
if (classSearched != null) {
|
|
145
|
-
return classSearched;
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
121
|
static getClassInImportInfoWithName(className, arkFile) {
|
|
150
122
|
let arkExport = this.getArkExportInImportInfoWithName(className, arkFile);
|
|
151
123
|
if (arkExport instanceof ArkClass_1.ArkClass) {
|
|
@@ -158,46 +130,6 @@ class ModelUtils {
|
|
|
158
130
|
var _a, _b, _c;
|
|
159
131
|
return (_c = (_b = (_a = arkFile.getImportInfoBy(name)) === null || _a === void 0 ? void 0 : _a.getLazyExportInfo()) === null || _b === void 0 ? void 0 : _b.getArkExport()) !== null && _c !== void 0 ? _c : null;
|
|
160
132
|
}
|
|
161
|
-
/** search method within the file that contain the given method */
|
|
162
|
-
static getMethodWithName(methodName, startFrom) {
|
|
163
|
-
if (!methodName.includes('.')) {
|
|
164
|
-
if (startFrom.getName() === methodName) {
|
|
165
|
-
return startFrom;
|
|
166
|
-
}
|
|
167
|
-
const thisClass = startFrom.getDeclaringArkClass();
|
|
168
|
-
let methodSearched = thisClass.getMethodWithName(methodName);
|
|
169
|
-
if (!methodSearched) {
|
|
170
|
-
methodSearched = thisClass.getStaticMethodWithName(methodName);
|
|
171
|
-
}
|
|
172
|
-
return methodSearched;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
const names = methodName.split('.');
|
|
176
|
-
let nameSpace = this.getNamespaceWithName(names[0], startFrom.getDeclaringArkClass());
|
|
177
|
-
for (let i = 1; i < names.length - 1; i++) {
|
|
178
|
-
if (nameSpace) {
|
|
179
|
-
nameSpace = nameSpace.getNamespaceWithName(names[i]);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (nameSpace) {
|
|
183
|
-
return nameSpace.getDefaultClass().getMethodWithName(names[names.length - 1]);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
static getNamespaceWithNameFromClass(namespaceName, startFrom) {
|
|
189
|
-
const thisNamespace = startFrom.getDeclaringArkNamespace();
|
|
190
|
-
let namespaceSearched = null;
|
|
191
|
-
if (thisNamespace) {
|
|
192
|
-
namespaceSearched = thisNamespace.getNamespaceWithName(namespaceName);
|
|
193
|
-
if (namespaceSearched) {
|
|
194
|
-
return namespaceSearched;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const thisFile = startFrom.getDeclaringArkFile();
|
|
198
|
-
namespaceSearched = this.getNamespaceInFileWithName(namespaceName, thisFile);
|
|
199
|
-
return namespaceSearched;
|
|
200
|
-
}
|
|
201
133
|
static getNamespaceWithName(namespaceName, thisClass) {
|
|
202
134
|
let thisNamespace = thisClass.getDeclaringArkNamespace();
|
|
203
135
|
let namespaceSearched = null;
|
|
@@ -210,22 +142,17 @@ class ModelUtils {
|
|
|
210
142
|
}
|
|
211
143
|
return namespaceSearched;
|
|
212
144
|
}
|
|
213
|
-
static getNamespaceInFileWithName(namespaceName, arkFile) {
|
|
214
|
-
let namespaceSearched = arkFile.getNamespaceWithName(namespaceName);
|
|
215
|
-
if (namespaceSearched) {
|
|
216
|
-
return namespaceSearched;
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
145
|
static findSymbolInFileWithName(symbolName, arkClass, onlyType = false) {
|
|
221
146
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
222
147
|
// look up symbol from inner to outer
|
|
223
148
|
let currNamespace = arkClass.getDeclaringArkNamespace();
|
|
224
149
|
let result;
|
|
225
150
|
while (currNamespace) {
|
|
226
|
-
result =
|
|
151
|
+
result =
|
|
152
|
+
(_e = (_a = currNamespace.getClassWithName(symbolName)) !== null && _a !== void 0 ? _a : (_d = (_c = (_b = currNamespace.getDefaultClass()) === null || _b === void 0 ? void 0 : _b.getDefaultArkMethod()) === null || _c === void 0 ? void 0 : _c.getBody()) === null || _d === void 0 ? void 0 : _d.getAliasTypeByName(symbolName)) !== null && _e !== void 0 ? _e : (_j = (_h = (_g = (_f = currNamespace.getDefaultClass()) === null || _f === void 0 ? void 0 : _f.getDefaultArkMethod()) === null || _g === void 0 ? void 0 : _g.getBody()) === null || _h === void 0 ? void 0 : _h.getLocals()) === null || _j === void 0 ? void 0 : _j.get(symbolName);
|
|
227
153
|
if (!result && !onlyType) {
|
|
228
|
-
result =
|
|
154
|
+
result =
|
|
155
|
+
(_l = (_k = (currNamespace.getName() === symbolName ? currNamespace : null)) !== null && _k !== void 0 ? _k : currNamespace.getNamespaceWithName(symbolName)) !== null && _l !== void 0 ? _l : currNamespace.getDefaultClass().getMethodWithName(symbolName);
|
|
229
156
|
}
|
|
230
157
|
if (result) {
|
|
231
158
|
return result;
|
|
@@ -250,7 +177,7 @@ class ModelUtils {
|
|
|
250
177
|
static getStaticMethodWithName(methodName, thisClass) {
|
|
251
178
|
const thisNamespace = thisClass.getDeclaringArkNamespace();
|
|
252
179
|
if (thisNamespace) {
|
|
253
|
-
const defaultClass = thisNamespace.
|
|
180
|
+
const defaultClass = thisNamespace.getDefaultClass();
|
|
254
181
|
if (defaultClass) {
|
|
255
182
|
const method = defaultClass.getMethodWithName(methodName);
|
|
256
183
|
if (method) {
|
|
@@ -269,19 +196,9 @@ class ModelUtils {
|
|
|
269
196
|
}
|
|
270
197
|
}
|
|
271
198
|
static getStaticMethodInFileWithName(methodName, arkFile) {
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
if (method) {
|
|
276
|
-
return method;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
281
|
-
static getStaticMethodInImportInfoWithName(methodName, arkFile) {
|
|
282
|
-
let arkExport = this.getArkExportInImportInfoWithName(methodName, arkFile);
|
|
283
|
-
if (arkExport instanceof ArkMethod_1.ArkMethod) {
|
|
284
|
-
return arkExport;
|
|
199
|
+
const method = arkFile.getDefaultClass().getMethodWithName(methodName);
|
|
200
|
+
if (method) {
|
|
201
|
+
return method;
|
|
285
202
|
}
|
|
286
203
|
return null;
|
|
287
204
|
}
|
|
@@ -292,13 +209,11 @@ class ModelUtils {
|
|
|
292
209
|
}
|
|
293
210
|
return null;
|
|
294
211
|
}
|
|
295
|
-
|
|
212
|
+
/**
|
|
213
|
+
* @deprecated Use {@link ArkFile.getAllNamespacesUnderThisFile} instead.
|
|
214
|
+
*/
|
|
296
215
|
static getAllNamespacesInFile(arkFile) {
|
|
297
|
-
|
|
298
|
-
for (const arkNamespace of arkFile.getNamespaces()) {
|
|
299
|
-
this.getAllNamespacesInNamespace(arkNamespace, arkNamespaces);
|
|
300
|
-
}
|
|
301
|
-
return arkNamespaces;
|
|
216
|
+
return arkFile.getAllNamespacesUnderThisFile();
|
|
302
217
|
}
|
|
303
218
|
/* get nested namespaces in a namespace */
|
|
304
219
|
static getAllNamespacesInNamespace(arkNamespace, allNamespaces) {
|
|
@@ -309,7 +224,7 @@ class ModelUtils {
|
|
|
309
224
|
}
|
|
310
225
|
static getAllClassesInFile(arkFile) {
|
|
311
226
|
const allClasses = arkFile.getClasses();
|
|
312
|
-
|
|
227
|
+
arkFile.getAllNamespacesUnderThisFile().forEach(namespace => {
|
|
313
228
|
allClasses.push(...namespace.getClasses());
|
|
314
229
|
});
|
|
315
230
|
return allClasses;
|
|
@@ -317,7 +232,10 @@ class ModelUtils {
|
|
|
317
232
|
static getAllMethodsInFile(arkFile) {
|
|
318
233
|
const allMethods = [];
|
|
319
234
|
this.getAllClassesInFile(arkFile).forEach(cls => {
|
|
320
|
-
|
|
235
|
+
cls.forEachMethod(method => {
|
|
236
|
+
allMethods.push(method);
|
|
237
|
+
return true;
|
|
238
|
+
});
|
|
321
239
|
});
|
|
322
240
|
return allMethods;
|
|
323
241
|
}
|
|
@@ -332,14 +250,17 @@ class ModelUtils {
|
|
|
332
250
|
return isArkUIBuilderMethod;
|
|
333
251
|
}
|
|
334
252
|
static getArkClassInBuild(scene, classType) {
|
|
335
|
-
var _a;
|
|
253
|
+
var _a, _b;
|
|
336
254
|
const classSignature = classType.getClassSignature();
|
|
337
|
-
const file = scene.getFile(classSignature.
|
|
255
|
+
const file = scene.getFile(classSignature.getDeclaringFileSigID());
|
|
256
|
+
if (!file) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
338
259
|
const namespaceSignature = classSignature.getDeclaringNamespaceSignature();
|
|
339
260
|
if (namespaceSignature) {
|
|
340
|
-
return ((_a = file === null ||
|
|
261
|
+
return (_b = (_a = file.getNamespace(namespaceSignature)) === null || _a === void 0 ? void 0 : _a.getClass(classSignature)) !== null && _b !== void 0 ? _b : null;
|
|
341
262
|
}
|
|
342
|
-
return
|
|
263
|
+
return file.getClass(classSignature);
|
|
343
264
|
}
|
|
344
265
|
static getDefaultClass(arkClass) {
|
|
345
266
|
var _a, _b;
|
|
@@ -373,6 +294,30 @@ class ModelUtils {
|
|
|
373
294
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
374
295
|
return ((_k = (_j = (_h = (_g = (_e = (_d = (_c = (_b = (_a = namespace.getDefaultClass()) === null || _a === void 0 ? void 0 : _a.getDefaultArkMethod()) === null || _b === void 0 ? void 0 : _b.getBody()) === null || _c === void 0 ? void 0 : _c.getLocals()) === null || _d === void 0 ? void 0 : _d.get(name)) !== null && _e !== void 0 ? _e : (_f = namespace.getDefaultClass()) === null || _f === void 0 ? void 0 : _f.getMethodWithName(name)) !== null && _g !== void 0 ? _g : findArkExport(namespace.getExportInfoBy(name))) !== null && _h !== void 0 ? _h : namespace.getClassWithName(name)) !== null && _j !== void 0 ? _j : namespace.getNamespaceWithName(name)) !== null && _k !== void 0 ? _k : (_o = (_m = (_l = namespace.getDefaultClass()) === null || _l === void 0 ? void 0 : _l.getDefaultArkMethod()) === null || _m === void 0 ? void 0 : _m.getBody()) === null || _o === void 0 ? void 0 : _o.getAliasTypeByName(name));
|
|
375
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Multi-entity variant of {@link findPropertyInNamespace}: after the primary
|
|
299
|
+
* namespace misses, probe sibling entities of the same-name global symbol
|
|
300
|
+
* (cross-file same-name namespaces, e.g. `Intl` declared across lib.es5 +
|
|
301
|
+
* lib.es20XX.intl — later files' entities carry members declared there).
|
|
302
|
+
* Covers each sibling's %dflt locals (declare const vars), inner classes, nested namespaces
|
|
303
|
+
* and exports — members physically stay in their declaring entities. Order follows
|
|
304
|
+
* registration order (= DFS file order).
|
|
305
|
+
*/
|
|
306
|
+
static findPropertyInNamespaces(name, namespace) {
|
|
307
|
+
const primary = this.findPropertyInNamespace(name, namespace);
|
|
308
|
+
if (primary) {
|
|
309
|
+
return primary;
|
|
310
|
+
}
|
|
311
|
+
for (const e of SdkUtils_1.SdkUtils.getSdkGlobals(namespace.getName())) {
|
|
312
|
+
if (e instanceof ArkNamespace_1.ArkNamespace && e !== namespace) {
|
|
313
|
+
const property = this.findPropertyInNamespace(name, e);
|
|
314
|
+
if (property) {
|
|
315
|
+
return property;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
376
321
|
static findPropertyInClass(name, arkClass) {
|
|
377
322
|
var _a, _b, _c, _d, _e;
|
|
378
323
|
let property = (_e = (_d = (_c = (_b = (_a = arkClass.getMethodWithName(name)) !== null && _a !== void 0 ? _a : arkClass.getFieldWithName(name)) !== null && _b !== void 0 ? _b : arkClass.getStaticMethodWithName(name)) !== null && _c !== void 0 ? _c : arkClass.getStaticFieldWithName(name)) !== null && _d !== void 0 ? _d : arkClass.getMethodWithName(Const_1.GETTER_PREFIX + name)) !== null && _e !== void 0 ? _e : arkClass.getStaticMethodWithName(Const_1.GETTER_PREFIX + name);
|
|
@@ -388,21 +333,23 @@ class ModelUtils {
|
|
|
388
333
|
return property;
|
|
389
334
|
}
|
|
390
335
|
}
|
|
391
|
-
const objectClass =
|
|
336
|
+
const objectClass = SdkUtils_1.SdkUtils.getSdkGlobal(Builtin_1.Builtin.OBJECT);
|
|
392
337
|
if (objectClass instanceof ArkClass_1.ArkClass && arkClass !== objectClass) {
|
|
393
338
|
return this.findPropertyInClass(name, objectClass);
|
|
394
339
|
}
|
|
395
340
|
return null;
|
|
396
341
|
}
|
|
397
342
|
static findDeclaredLocal(local, arkMethod, times = 0) {
|
|
398
|
-
var _a
|
|
343
|
+
var _a;
|
|
399
344
|
const name = local.getName();
|
|
400
345
|
if (name === TSConst_1.THIS_NAME || name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
401
346
|
return null;
|
|
402
347
|
}
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
348
|
+
const parameters = arkMethod.getParameters();
|
|
349
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
350
|
+
if (parameters[i].getName() === name) {
|
|
351
|
+
return new Local_1.Local(parameters[i].getName(), parameters[i].getType());
|
|
352
|
+
}
|
|
406
353
|
}
|
|
407
354
|
if (times > 0) {
|
|
408
355
|
const declaredLocal = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
|
|
@@ -418,24 +365,73 @@ class ModelUtils {
|
|
|
418
365
|
}
|
|
419
366
|
let invokeMethod = arkMethod.getOuterMethod();
|
|
420
367
|
if (!invokeMethod) {
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
const outerEnd = className.lastIndexOf(Const_1.NESTED_CLASS_METHOD_DELIMITER);
|
|
424
|
-
if (outerStart > -1 && outerEnd > -1) {
|
|
425
|
-
invokeMethod = (_b = arkMethod
|
|
426
|
-
.getDeclaringArkFile()
|
|
427
|
-
.getClassWithName(className.substring(outerStart + 1, outerEnd))) === null || _b === void 0 ? void 0 : _b.getMethodWithName(className.substring(outerEnd + 1));
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
const symbol = this.findSymbolInFileWithName(name, arkMethod.getDeclaringArkClass(), true);
|
|
431
|
-
return symbol instanceof Local_1.Local ? symbol : null;
|
|
432
|
-
}
|
|
368
|
+
const symbol = this.findSymbolInFileWithName(name, arkMethod.getDeclaringArkClass(), true);
|
|
369
|
+
return symbol instanceof Local_1.Local ? symbol : null;
|
|
433
370
|
}
|
|
434
371
|
if (invokeMethod) {
|
|
435
372
|
return this.findDeclaredLocal(local, invokeMethod, ++times);
|
|
436
373
|
}
|
|
437
374
|
return null;
|
|
438
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* @internal Same walk as {@link findDeclaredLocal} for callers that only read the resolved
|
|
378
|
+
* type: matches `findDeclaredLocal(...)?.getType()` exactly (undefined when not found) but
|
|
379
|
+
* neither wraps the name into a throwaway Local nor allocates a parameter Local on hits.
|
|
380
|
+
*/
|
|
381
|
+
static findDeclaredLocalType(name, arkMethod, times = 0) {
|
|
382
|
+
var _a;
|
|
383
|
+
if (name === TSConst_1.THIS_NAME || name.startsWith(Const_1.TEMP_LOCAL_PREFIX)) {
|
|
384
|
+
return undefined;
|
|
385
|
+
}
|
|
386
|
+
const parameters = arkMethod.getParameters();
|
|
387
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
388
|
+
if (parameters[i].getName() === name) {
|
|
389
|
+
return parameters[i].getType();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (times > 0) {
|
|
393
|
+
const declaredLocal = (_a = arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(name);
|
|
394
|
+
if (declaredLocal &&
|
|
395
|
+
declaredLocal.getDeclaringStmt() instanceof Stmt_1.ArkAssignStmt &&
|
|
396
|
+
!(declaredLocal.getDeclaringStmt().getRightOp() instanceof Ref_1.ClosureFieldRef)) {
|
|
397
|
+
return declaredLocal.getType();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
let parentName = arkMethod.getName();
|
|
401
|
+
if (parentName === Const_1.DEFAULT_ARK_METHOD_NAME) {
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
let invokeMethod = arkMethod.getOuterMethod();
|
|
405
|
+
if (!invokeMethod) {
|
|
406
|
+
const symbol = this.findSymbolInFileWithName(name, arkMethod.getDeclaringArkClass(), true);
|
|
407
|
+
return symbol instanceof Local_1.Local ? symbol.getType() : undefined;
|
|
408
|
+
}
|
|
409
|
+
return this.findDeclaredLocalType(name, invokeMethod, times + 1);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Find a class declared inside a method body by its bare source name, walking the
|
|
413
|
+
* outer-method chain (so classes captured from enclosing functions resolve too).
|
|
414
|
+
* The class model lives at file/namespace top level under the composed name
|
|
415
|
+
* (`Local$Outer-m`); this lookup goes through the bare-name → ClassSigID bindings
|
|
416
|
+
* registered at build time, giving deterministic scope-chain resolution.
|
|
417
|
+
* @param className - the bare source name of the local class
|
|
418
|
+
* @param arkMethod - the method where the reference occurs
|
|
419
|
+
* @returns The local ArkClass, or null if not declared in any enclosing method.
|
|
420
|
+
*/
|
|
421
|
+
static findLocalClassInMethodChain(className, arkMethod) {
|
|
422
|
+
let method = arkMethod;
|
|
423
|
+
while (method) {
|
|
424
|
+
const sigID = method.getLocalClassSigID(className);
|
|
425
|
+
if (sigID !== undefined) {
|
|
426
|
+
const cls = SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance().getClassById(sigID);
|
|
427
|
+
if (cls) {
|
|
428
|
+
return cls;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
method = method.getOuterMethod();
|
|
432
|
+
}
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
439
435
|
static findArkModel(baseName, arkClass) {
|
|
440
436
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
441
437
|
let arkModel = (_c = (_b = (_a = arkClass.getMethodWithName(baseName)) !== null && _a !== void 0 ? _a : arkClass.getStaticMethodWithName(baseName)) !== null && _b !== void 0 ? _b : arkClass.getFieldWithName(baseName)) !== null && _c !== void 0 ? _c : arkClass.getStaticFieldWithName(baseName);
|
|
@@ -445,13 +441,13 @@ class ModelUtils {
|
|
|
445
441
|
arkModel =
|
|
446
442
|
(_r = (_m = (_k = (_j = (_h = (_g = (_f = (_e = (_d = ModelUtils.getDefaultClass(arkClass)) === null || _d === void 0 ? void 0 : _d.getDefaultArkMethod()) === null || _e === void 0 ? void 0 : _e.getBody()) === null || _f === void 0 ? void 0 : _f.getLocals()) === null || _g === void 0 ? void 0 : _g.get(baseName)) !== null && _h !== void 0 ? _h : ModelUtils.getClassWithName(baseName, arkClass)) !== null && _j !== void 0 ? _j : ModelUtils.getNamespaceWithName(baseName, arkClass)) !== null && _k !== void 0 ? _k : (_l = ModelUtils.getDefaultClass(arkClass)) === null || _l === void 0 ? void 0 : _l.getMethodWithName(baseName)) !== null && _m !== void 0 ? _m : (_q = (_p = (_o = ModelUtils.getDefaultClass(arkClass)) === null || _o === void 0 ? void 0 : _o.getDefaultArkMethod()) === null || _p === void 0 ? void 0 : _p.getBody()) === null || _q === void 0 ? void 0 : _q.getAliasTypeByName(baseName)) !== null && _r !== void 0 ? _r : ModelUtils.getArkExportInImportInfoWithName(baseName, arkClass.getDeclaringArkFile());
|
|
447
443
|
if (!arkModel && !arkClass.getDeclaringArkFile().getImportInfoBy(baseName)) {
|
|
448
|
-
arkModel =
|
|
444
|
+
arkModel = SdkUtils_1.SdkUtils.getSdkGlobal(baseName);
|
|
449
445
|
}
|
|
450
446
|
return arkModel;
|
|
451
447
|
}
|
|
452
448
|
static findGlobalRef(refName, method) {
|
|
453
449
|
var _a, _b;
|
|
454
|
-
return ((_b = (_a = this.findDeclaredLocal(new Local_1.Local(refName), method, 1)) !== null && _a !== void 0 ? _a : this.getArkExportInImportInfoWithName(refName, method.getDeclaringArkFile())) !== null && _b !== void 0 ? _b :
|
|
450
|
+
return ((_b = (_a = this.findDeclaredLocal(new Local_1.Local(refName), method, 1)) !== null && _a !== void 0 ? _a : this.getArkExportInImportInfoWithName(refName, method.getDeclaringArkFile())) !== null && _b !== void 0 ? _b : SdkUtils_1.SdkUtils.getSdkGlobal(refName));
|
|
455
451
|
}
|
|
456
452
|
static findArkModelByRefName(refName, arkClass) {
|
|
457
453
|
const singleNames = refName.split('.');
|
|
@@ -460,10 +456,10 @@ class ModelUtils {
|
|
|
460
456
|
if (model instanceof Local_1.Local || model instanceof ArkField_1.ArkField) {
|
|
461
457
|
const type = model.getType();
|
|
462
458
|
if (type instanceof Type_1.ClassType) {
|
|
463
|
-
model =
|
|
459
|
+
model = this.registry.getClassBySig(type.getClassSignature());
|
|
464
460
|
}
|
|
465
461
|
else if (type instanceof Type_1.AnnotationNamespaceType) {
|
|
466
|
-
model =
|
|
462
|
+
model = this.registry.getNamespaceBySig(type.getNamespaceSignature());
|
|
467
463
|
}
|
|
468
464
|
}
|
|
469
465
|
const name = singleNames[i].replace(/<(\w+)>/, ValueUtil_1.EMPTY_STRING);
|
|
@@ -474,7 +470,8 @@ class ModelUtils {
|
|
|
474
470
|
model = this.findPropertyInClass(name, model);
|
|
475
471
|
}
|
|
476
472
|
else if (model instanceof ArkNamespace_1.ArkNamespace) {
|
|
477
|
-
|
|
473
|
+
// 多实体探测:跨文件同名 ns(Intl 系)成员可见性
|
|
474
|
+
model = this.findPropertyInNamespaces(name, model);
|
|
478
475
|
}
|
|
479
476
|
if (!model) {
|
|
480
477
|
return null;
|
|
@@ -499,7 +496,7 @@ class ModelUtils {
|
|
|
499
496
|
return this.findPropertyInClass(signature.getFieldName(), declare);
|
|
500
497
|
}
|
|
501
498
|
else if (declare instanceof ArkNamespace_1.ArkNamespace) {
|
|
502
|
-
return this.
|
|
499
|
+
return this.findPropertyInNamespaces(signature.getFieldName(), declare) || null;
|
|
503
500
|
}
|
|
504
501
|
return null;
|
|
505
502
|
}
|
|
@@ -594,7 +591,11 @@ class ModelUtils {
|
|
|
594
591
|
return false;
|
|
595
592
|
}
|
|
596
593
|
const parameters = paramType.getMethodSignature().getMethodSubSignature().getParameters();
|
|
597
|
-
const args = argType
|
|
594
|
+
const args = argType
|
|
595
|
+
.getMethodSignature()
|
|
596
|
+
.getMethodSubSignature()
|
|
597
|
+
.getParameters()
|
|
598
|
+
.filter(p => !p.getName().startsWith(Const_1.LEXICAL_ENV_NAME_PREFIX));
|
|
598
599
|
return ModelUtils.isMatched(parameters, args, scene, true);
|
|
599
600
|
}
|
|
600
601
|
return ModelUtils.matchType(paramType, argType, arg, scene);
|
|
@@ -603,15 +604,15 @@ class ModelUtils {
|
|
|
603
604
|
var _a, _b;
|
|
604
605
|
if (paramType instanceof Type_1.LiteralType) {
|
|
605
606
|
const argStr = arg instanceof Constant_1.Constant ? arg.getValue() : argType.toString();
|
|
606
|
-
return argStr.replace(/[\"|\']/g, '') ===
|
|
607
|
-
paramType.toString().replace(/[\"|\']/g, '');
|
|
607
|
+
return argStr.replace(/[\"|\']/g, '') === paramType.toString().replace(/[\"|\']/g, '');
|
|
608
608
|
}
|
|
609
609
|
else if (paramType instanceof Type_1.ClassType && argType instanceof Type_1.EnumValueType) {
|
|
610
|
-
|
|
610
|
+
// Value-semantic identity comparison (hash fast reject + equals verdict).
|
|
611
|
+
return (0, SignatureCanonicalizer_1.signatureEquals)(paramType.getClassSignature(), argType.getFieldSignature().getDeclaringSignature());
|
|
611
612
|
}
|
|
612
613
|
else if (paramType instanceof Type_1.EnumValueType) {
|
|
613
614
|
if (argType instanceof Type_1.EnumValueType) {
|
|
614
|
-
return paramType.getFieldSignature()
|
|
615
|
+
return (0, SignatureCanonicalizer_1.signatureEquals)(paramType.getFieldSignature(), argType.getFieldSignature());
|
|
615
616
|
}
|
|
616
617
|
else if (argType.constructor === ((_a = paramType.getConstant()) === null || _a === void 0 ? void 0 : _a.getType().constructor) && arg instanceof Constant_1.Constant) {
|
|
617
618
|
return ((_b = paramType.getConstant()) === null || _b === void 0 ? void 0 : _b.getValue()) === arg.getValue();
|
|
@@ -646,7 +647,13 @@ class ModelUtils {
|
|
|
646
647
|
if (noMatchedField) {
|
|
647
648
|
return false;
|
|
648
649
|
}
|
|
649
|
-
const mustMethods =
|
|
650
|
+
const mustMethods = [];
|
|
651
|
+
paramClass.forEachMethod(f => {
|
|
652
|
+
if (!f.isStatic() && !f.getQuestionToken()) {
|
|
653
|
+
mustMethods.push(f);
|
|
654
|
+
}
|
|
655
|
+
return true;
|
|
656
|
+
});
|
|
650
657
|
const noMatchedMethod = mustMethods.find(f => !argClass.getMethodWithName(f.getName()));
|
|
651
658
|
if (noMatchedMethod) {
|
|
652
659
|
return false;
|
|
@@ -656,7 +663,14 @@ class ModelUtils {
|
|
|
656
663
|
if (excessField) {
|
|
657
664
|
return false;
|
|
658
665
|
}
|
|
659
|
-
|
|
666
|
+
let excessMethod;
|
|
667
|
+
argClass.forEachMethod(f => {
|
|
668
|
+
if (!paramClass.getMethodWithName(f.getName())) {
|
|
669
|
+
excessMethod = f;
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
return true;
|
|
673
|
+
});
|
|
660
674
|
if (excessMethod) {
|
|
661
675
|
return false;
|
|
662
676
|
}
|
|
@@ -680,6 +694,8 @@ class ModelUtils {
|
|
|
680
694
|
exports.ModelUtils = ModelUtils;
|
|
681
695
|
ModelUtils.implicitArkUIBuilderMethods = new Set();
|
|
682
696
|
ModelUtils.popMethodSignatureCache = new Map();
|
|
697
|
+
/** @internal */
|
|
698
|
+
ModelUtils.componentMethodSigCache = new Map();
|
|
683
699
|
const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'ModelUtils');
|
|
684
700
|
/**
|
|
685
701
|
* find arkFile by from info
|
|
@@ -688,13 +704,53 @@ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER,
|
|
|
688
704
|
* import xx from '@ohos.xx'
|
|
689
705
|
* @param im importInfo or exportInfo
|
|
690
706
|
*/
|
|
707
|
+
/**
|
|
708
|
+
* Resolutions of a from-info's target file, memoized by the from-info object. Hits live here, misses
|
|
709
|
+
* in {@link unresolvedArkFile} - each miss carrying the table state it was decided under.
|
|
710
|
+
*/
|
|
711
|
+
const resolvedArkFile = new WeakMap();
|
|
712
|
+
/**
|
|
713
|
+
* Monotonic sum of the registration tables this resolution reads: registered file signatures, the SDK
|
|
714
|
+
* global map, the module map and the SDK import map. A miss is stored with the sum it saw and
|
|
715
|
+
* re-resolved once the sum changes, so a "no file" answer given before a later registration - the
|
|
716
|
+
* window the resolution contract cares about - answers again afterwards. Every part only grows, so
|
|
717
|
+
* equal sums mean equal parts and a change in one of them cannot hide behind another.
|
|
718
|
+
*/
|
|
719
|
+
function resolutionTableState() {
|
|
720
|
+
const registry = SignatureCanonicalizerRegistry_1.SignatureCanonicalizerRegistry.getInstance();
|
|
721
|
+
return registry.fileSigCanonicalizer.size() + registry.sdkGlobalMap.size + ModuleUtils_1.ModuleUtils.MODULES.size + SdkUtils_1.SdkUtils.getSdkImportMapSize();
|
|
722
|
+
}
|
|
723
|
+
/** From-infos whose resolution found no file, with the {@link resolutionTableState} they saw. */
|
|
724
|
+
const unresolvedArkFile = new WeakMap();
|
|
691
725
|
function getArkFile(im) {
|
|
726
|
+
const memoized = resolvedArkFile.get(im);
|
|
727
|
+
if (memoized !== undefined) {
|
|
728
|
+
return memoized;
|
|
729
|
+
}
|
|
730
|
+
const missedAt = unresolvedArkFile.get(im);
|
|
731
|
+
if (missedAt !== undefined && missedAt === resolutionTableState()) {
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
const tableState = resolutionTableState();
|
|
735
|
+
const resolved = resolveArkFile(im);
|
|
736
|
+
if (resolved !== null) {
|
|
737
|
+
resolvedArkFile.set(im, resolved);
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
unresolvedArkFile.set(im, tableState);
|
|
741
|
+
}
|
|
742
|
+
return resolved;
|
|
743
|
+
}
|
|
744
|
+
exports.getArkFile = getArkFile;
|
|
745
|
+
const RELATIVE_PATH_PATTERN = /^\.\.?\/|^\.$/;
|
|
746
|
+
function resolveArkFile(im) {
|
|
692
747
|
var _a;
|
|
748
|
+
// TODO: 这个方法的性能很差,需要结合id化后的架构进行重构。
|
|
693
749
|
const from = im.getFrom();
|
|
694
750
|
if (!from) {
|
|
695
751
|
return null;
|
|
696
752
|
}
|
|
697
|
-
if (
|
|
753
|
+
if (RELATIVE_PATH_PATTERN.test(from)) {
|
|
698
754
|
//relative path
|
|
699
755
|
return getArkFileFromScene(im, path_1.default.resolve(path_1.default.dirname(im.getDeclaringArkFile().getFilePath()), from));
|
|
700
756
|
}
|
|
@@ -712,15 +768,18 @@ function getArkFile(im) {
|
|
|
712
768
|
}
|
|
713
769
|
// ohos common module
|
|
714
770
|
const scene = im.getDeclaringArkFile().getScene();
|
|
715
|
-
const module =
|
|
771
|
+
const module = SdkUtils_1.SdkUtils.getSdkGlobal(from);
|
|
716
772
|
if (module instanceof ArkNamespace_1.ArkNamespace) {
|
|
717
773
|
return module.getDeclaringArkFile();
|
|
718
774
|
}
|
|
719
775
|
// custom sdk
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
for (const sdk of
|
|
776
|
+
const sdkMap = scene.getProjectSdkMap();
|
|
777
|
+
const skip = sdkMap.size > EtsConst_1.DEFAULT_SDK_NUMS ? EtsConst_1.DEFAULT_SDK_NUMS : sdkMap.size - 1;
|
|
778
|
+
let seen = 0;
|
|
779
|
+
for (const sdk of sdkMap.values()) {
|
|
780
|
+
if (seen++ < skip) {
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
724
783
|
const arkFile = getArkFileFormSDK(sdk, from, scene);
|
|
725
784
|
if (arkFile) {
|
|
726
785
|
return arkFile;
|
|
@@ -728,17 +787,32 @@ function getArkFile(im) {
|
|
|
728
787
|
}
|
|
729
788
|
return null;
|
|
730
789
|
}
|
|
731
|
-
exports.getArkFile = getArkFile;
|
|
732
790
|
/**
|
|
733
791
|
* find from info's export
|
|
734
792
|
* @param fromInfo importInfo or exportInfo
|
|
735
793
|
* @param visited
|
|
736
794
|
*/
|
|
737
|
-
function findExportInfo(fromInfo, visited
|
|
795
|
+
function findExportInfo(fromInfo, visited) {
|
|
796
|
+
if (visited !== undefined) {
|
|
797
|
+
return findExportInfoVisited(fromInfo, visited);
|
|
798
|
+
}
|
|
799
|
+
const prevBase = fileVisitedSeg.enter();
|
|
800
|
+
fileVisitedSeg.add(fromInfo.getDeclaringArkFile());
|
|
801
|
+
try {
|
|
802
|
+
return findExportInfoVisited(fromInfo, fileVisitedSeg);
|
|
803
|
+
}
|
|
804
|
+
finally {
|
|
805
|
+
fileVisitedSeg.leave(prevBase);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
exports.findExportInfo = findExportInfo;
|
|
809
|
+
function findExportInfoVisited(fromInfo, visited) {
|
|
738
810
|
var _a, _b;
|
|
739
811
|
let file = getArkFile(fromInfo);
|
|
740
812
|
if (!file) {
|
|
741
|
-
|
|
813
|
+
if (logger_1.default.isWarnEnabled(logger)) {
|
|
814
|
+
logger.warn(`${fromInfo.getOriginName()} ${fromInfo.getFrom()} file not found: ${(_b = (_a = fromInfo.getDeclaringArkFile()) === null || _a === void 0 ? void 0 : _a.getFileSignature()) === null || _b === void 0 ? void 0 : _b.toString()}`);
|
|
815
|
+
}
|
|
742
816
|
return null;
|
|
743
817
|
}
|
|
744
818
|
if (fromInfo.getOriginName() === TSConst_1.ALL) {
|
|
@@ -762,8 +836,24 @@ function findExportInfo(fromInfo, visited = new Set([fromInfo.getDeclaringArkFil
|
|
|
762
836
|
}
|
|
763
837
|
return exportInfo;
|
|
764
838
|
}
|
|
765
|
-
|
|
766
|
-
|
|
839
|
+
function findArkExport(exportInfo, visited) {
|
|
840
|
+
if (visited !== undefined && !visited.isEmpty()) {
|
|
841
|
+
return findArkExportVisited(exportInfo, visited);
|
|
842
|
+
}
|
|
843
|
+
if (!exportInfo) {
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
const prevBase = fileVisitedSeg.enter();
|
|
847
|
+
fileVisitedSeg.add(exportInfo.getDeclaringArkFile());
|
|
848
|
+
try {
|
|
849
|
+
return findArkExportVisited(exportInfo, fileVisitedSeg);
|
|
850
|
+
}
|
|
851
|
+
finally {
|
|
852
|
+
fileVisitedSeg.leave(prevBase);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
exports.findArkExport = findArkExport;
|
|
856
|
+
function findArkExportVisited(exportInfo, visited) {
|
|
767
857
|
var _a, _b, _c, _d, _e, _f;
|
|
768
858
|
if (!exportInfo) {
|
|
769
859
|
return null;
|
|
@@ -773,7 +863,6 @@ function findArkExport(exportInfo, visited = new Set()) {
|
|
|
773
863
|
return arkExport;
|
|
774
864
|
}
|
|
775
865
|
const declaringFile = exportInfo.getDeclaringArkFile();
|
|
776
|
-
const effectiveVisited = visited.size > 0 ? visited : new Set([declaringFile]);
|
|
777
866
|
if (!exportInfo.getFrom()) {
|
|
778
867
|
const name = exportInfo.getOriginName();
|
|
779
868
|
const defaultClass = (_b = (_a = exportInfo.getDeclaringArkNamespace()) === null || _a === void 0 ? void 0 : _a.getDefaultClass()) !== null && _b !== void 0 ? _b : declaringFile.getDefaultClass();
|
|
@@ -784,11 +873,11 @@ function findArkExport(exportInfo, visited = new Set()) {
|
|
|
784
873
|
arkExport = (_f = (_e = defaultClass.getDefaultArkMethod()) === null || _e === void 0 ? void 0 : _e.getBody()) === null || _f === void 0 ? void 0 : _f.getAliasTypeByName(name);
|
|
785
874
|
}
|
|
786
875
|
else {
|
|
787
|
-
arkExport = findArkExportInFile(name, declaringFile,
|
|
876
|
+
arkExport = findArkExportInFile(name, declaringFile, visited);
|
|
788
877
|
}
|
|
789
878
|
}
|
|
790
879
|
else if (exportInfo.getExportClauseType() === ArkExport_1.ExportType.UNKNOWN) {
|
|
791
|
-
const result = findExportInfo(exportInfo,
|
|
880
|
+
const result = findExportInfo(exportInfo, visited);
|
|
792
881
|
if (result) {
|
|
793
882
|
arkExport = result.getArkExport() || null;
|
|
794
883
|
}
|
|
@@ -797,13 +886,28 @@ function findArkExport(exportInfo, visited = new Set()) {
|
|
|
797
886
|
exportInfo.setArkExport(arkExport);
|
|
798
887
|
}
|
|
799
888
|
else {
|
|
800
|
-
|
|
801
|
-
|
|
889
|
+
if (logger_1.default.isWarnEnabled(logger)) {
|
|
890
|
+
const file = exportInfo.getDeclaringArkFile().getFileSignature().toString();
|
|
891
|
+
logger.warn(`${exportInfo.getExportClauseName()} get arkExport fail from ${exportInfo.getFrom()} at ${file}`);
|
|
892
|
+
}
|
|
802
893
|
}
|
|
803
894
|
return arkExport || null;
|
|
804
895
|
}
|
|
805
|
-
|
|
806
|
-
|
|
896
|
+
function findArkExportInFile(name, declaringArkFile, visited) {
|
|
897
|
+
if (visited !== undefined) {
|
|
898
|
+
return findArkExportInFileVisited(name, declaringArkFile, visited);
|
|
899
|
+
}
|
|
900
|
+
const prevBase = fileVisitedSeg.enter();
|
|
901
|
+
fileVisitedSeg.add(declaringArkFile);
|
|
902
|
+
try {
|
|
903
|
+
return findArkExportInFileVisited(name, declaringArkFile, fileVisitedSeg);
|
|
904
|
+
}
|
|
905
|
+
finally {
|
|
906
|
+
fileVisitedSeg.leave(prevBase);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
exports.findArkExportInFile = findArkExportInFile;
|
|
910
|
+
function findArkExportInFileVisited(name, declaringArkFile, visited) {
|
|
807
911
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
808
912
|
let arkExport = (_f = (_e = (_d = (_a = declaringArkFile.getNamespaceWithName(name)) !== null && _a !== void 0 ? _a : (_c = (_b = declaringArkFile.getDefaultClass().getDefaultArkMethod()) === null || _b === void 0 ? void 0 : _b.getBody()) === null || _c === void 0 ? void 0 : _c.getAliasTypeByName(name)) !== null && _d !== void 0 ? _d : declaringArkFile.getClassWithName(name)) !== null && _e !== void 0 ? _e : declaringArkFile.getDefaultClass().getMethodWithName(name)) !== null && _f !== void 0 ? _f : (_h = (_g = declaringArkFile.getDefaultClass().getDefaultArkMethod()) === null || _g === void 0 ? void 0 : _g.getBody()) === null || _h === void 0 ? void 0 : _h.getExportLocalByName(name);
|
|
809
913
|
if (!arkExport) {
|
|
@@ -817,42 +921,98 @@ function findArkExportInFile(name, declaringArkFile, visited = new Set([declarin
|
|
|
817
921
|
}
|
|
818
922
|
return arkExport || null;
|
|
819
923
|
}
|
|
820
|
-
|
|
924
|
+
/**
|
|
925
|
+
* Scene-lifetime memo of resolved target files, keyed by declaring project dir + origin path.
|
|
926
|
+
*
|
|
927
|
+
* The resolution is a pure function of those two inputs within a scene: the file table is fixed
|
|
928
|
+
* once the shells exist (project files and SDK files are registered before signature loading), so
|
|
929
|
+
* the memo caches misses as well as hits - a specifier that names no file names none for the rest
|
|
930
|
+
* of the build. Keyed by scene so a disposed scene's entries die with it.
|
|
931
|
+
*/
|
|
932
|
+
const resolvedSceneFiles = new WeakMap();
|
|
933
|
+
const fileVisitedSeg = new VisitedSegment_1.VisitedSegment();
|
|
934
|
+
function sceneFileMemo(scene, store = resolvedSceneFiles) {
|
|
935
|
+
let memo = store.get(scene);
|
|
936
|
+
if (memo === undefined) {
|
|
937
|
+
memo = new Map();
|
|
938
|
+
store.set(scene, memo);
|
|
939
|
+
}
|
|
940
|
+
return memo;
|
|
941
|
+
}
|
|
821
942
|
function getArkFileFromScene(im, originPath) {
|
|
943
|
+
var _a, _b;
|
|
944
|
+
const declaringFile = im.getDeclaringArkFile();
|
|
945
|
+
const scene = declaringFile.getScene();
|
|
946
|
+
const memo = sceneFileMemo(scene);
|
|
947
|
+
const key = declaringFile.getProjectDir() + '\u0000' + originPath;
|
|
948
|
+
if (memo.has(key)) {
|
|
949
|
+
return (_a = memo.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
950
|
+
}
|
|
822
951
|
const realPath = ModuleUtils_1.ModuleUtils.getFileRealPath(originPath);
|
|
823
|
-
const fileName = path_1.default.relative(
|
|
824
|
-
const fromSignature = new ArkSignature_1.FileSignature(
|
|
825
|
-
const
|
|
826
|
-
|
|
952
|
+
const fileName = path_1.default.relative(declaringFile.getProjectDir(), realPath);
|
|
953
|
+
const fromSignature = new ArkSignature_1.FileSignature(declaringFile.getProjectName(), fileName);
|
|
954
|
+
const file = (_b = scene.getFile(fromSignature)) !== null && _b !== void 0 ? _b : null;
|
|
955
|
+
memo.set(key, file);
|
|
956
|
+
return file;
|
|
827
957
|
}
|
|
958
|
+
/** Same scene-lifetime memo, for the custom-SDK lookup: its inputs are (sdk, from) and nothing else. */
|
|
959
|
+
const resolvedSdkFiles = new WeakMap();
|
|
828
960
|
function getArkFileFormSDK(sdk, from, scene) {
|
|
961
|
+
var _a, _b;
|
|
962
|
+
const memo = sceneFileMemo(scene, resolvedSdkFiles);
|
|
963
|
+
const key = sdk.name + '\u0000' + sdk.path + '\u0000' + from;
|
|
964
|
+
if (memo.has(key)) {
|
|
965
|
+
return (_a = memo.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
966
|
+
}
|
|
829
967
|
const realPath = ModuleUtils_1.ModuleUtils.getFileRealPath(path_1.default.resolve(sdk.path, from));
|
|
830
|
-
|
|
831
|
-
|
|
968
|
+
let file = null;
|
|
969
|
+
if (realPath) {
|
|
970
|
+
const fromSignature = new ArkSignature_1.FileSignature(sdk.name, path_1.default.relative(sdk.path, realPath));
|
|
971
|
+
file = (_b = scene.getFile(fromSignature)) !== null && _b !== void 0 ? _b : null;
|
|
832
972
|
}
|
|
833
|
-
|
|
834
|
-
return
|
|
973
|
+
memo.set(key, file);
|
|
974
|
+
return file;
|
|
835
975
|
}
|
|
836
|
-
function findExportInfoInfile(fromInfo, file, visited
|
|
976
|
+
function findExportInfoInfile(fromInfo, file, visited) {
|
|
977
|
+
if (visited !== undefined) {
|
|
978
|
+
return findExportInfoInfileVisited(fromInfo, file, visited);
|
|
979
|
+
}
|
|
980
|
+
const prevBase = fileVisitedSeg.enter();
|
|
981
|
+
fileVisitedSeg.add(fromInfo.getDeclaringArkFile());
|
|
982
|
+
try {
|
|
983
|
+
return findExportInfoInfileVisited(fromInfo, file, fileVisitedSeg);
|
|
984
|
+
}
|
|
985
|
+
finally {
|
|
986
|
+
fileVisitedSeg.leave(prevBase);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
exports.findExportInfoInfile = findExportInfoInfile;
|
|
990
|
+
function findExportInfoInfileVisited(fromInfo, file, visited) {
|
|
837
991
|
//check cycle
|
|
838
992
|
if (!visited.has(file)) {
|
|
839
993
|
visited.add(file);
|
|
840
994
|
// expand export *
|
|
841
|
-
file.getExportInfos()
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
995
|
+
const allExports = file.getExportInfos();
|
|
996
|
+
for (let i = 0; i < allExports.length; i++) {
|
|
997
|
+
if (allExports[i].getExportClauseName().startsWith(TSConst_1.TEMP_EXPORT_ALL_PREFIX)) {
|
|
998
|
+
findExportInfo(allExports[i], visited);
|
|
999
|
+
file.removeExportInfo(allExports[i]);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
846
1002
|
}
|
|
847
1003
|
if (fromInfo.getOriginName().startsWith(TSConst_1.TEMP_EXPORT_ALL_PREFIX) && fromInfo instanceof ArkExport_1.ExportInfo) {
|
|
848
1004
|
const declaringArkFile = fromInfo.getDeclaringArkFile();
|
|
849
|
-
|
|
850
|
-
|
|
1005
|
+
const expandableExports = file.getExportInfos();
|
|
1006
|
+
for (let i = 0; i < expandableExports.length; i++) {
|
|
1007
|
+
const exportInfo = expandableExports[i];
|
|
1008
|
+
if (exportInfo.isDefault() || exportInfo.getExportClauseName().startsWith(TSConst_1.TEMP_EXPORT_ALL_PREFIX)) {
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
851
1011
|
const existing = declaringArkFile.getExportInfoBy(exportInfo.getExportClauseName());
|
|
852
1012
|
if (!existing || existing.getFrom()) {
|
|
853
1013
|
declaringArkFile.addExportInfo(exportInfo);
|
|
854
1014
|
}
|
|
855
|
-
}
|
|
1015
|
+
}
|
|
856
1016
|
declaringArkFile.removeExportInfo(fromInfo);
|
|
857
1017
|
return undefined;
|
|
858
1018
|
}
|
|
@@ -860,17 +1020,12 @@ function findExportInfoInfile(fromInfo, file, visited = new Set([fromInfo.getDec
|
|
|
860
1020
|
let exportInfo = file.getExportInfoBy(exportName);
|
|
861
1021
|
if (exportInfo) {
|
|
862
1022
|
// Re-export with target already in visited indicates a cycle; return undefined to avoid stack overflow
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
if (targetFile && visited.has(targetFile)) {
|
|
866
|
-
return undefined;
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
return exportInfo;
|
|
1023
|
+
const targetFile = exportInfo.getFrom() ? getArkFile(exportInfo) : null;
|
|
1024
|
+
return visited.has(targetFile) ? undefined : exportInfo;
|
|
870
1025
|
}
|
|
871
1026
|
if (exportName === TSConst_1.DEFAULT) {
|
|
872
|
-
exportInfo = file.getExportInfos().find(
|
|
873
|
-
if (exportInfo) {
|
|
1027
|
+
exportInfo = file.getExportInfos().find(candidate => candidate.isDefault());
|
|
1028
|
+
if (exportInfo !== undefined) {
|
|
874
1029
|
file.addExportInfo(exportInfo, TSConst_1.DEFAULT);
|
|
875
1030
|
return exportInfo;
|
|
876
1031
|
}
|
|
@@ -878,22 +1033,35 @@ function findExportInfoInfile(fromInfo, file, visited = new Set([fromInfo.getDec
|
|
|
878
1033
|
if (fromInfo.getOriginName() === TSConst_1.ALL) {
|
|
879
1034
|
exportInfo = (0, ArkExportBuilder_1.buildDefaultExportInfo)(fromInfo, file);
|
|
880
1035
|
file.addExportInfo(exportInfo, TSConst_1.ALL);
|
|
1036
|
+
return exportInfo;
|
|
881
1037
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
exportInfo = (0, ArkExportBuilder_1.buildDefaultExportInfo)(fromInfo, file, declare);
|
|
1038
|
+
if (/\.d\.e?ts$/.test(file.getName())) {
|
|
1039
|
+
return (0, ArkExportBuilder_1.buildDefaultExportInfo)(fromInfo, file, exportName === TSConst_1.DEFAULT ? undefined : findArkExportInFile(fromInfo.getOriginName(), file, visited));
|
|
885
1040
|
}
|
|
886
1041
|
return exportInfo;
|
|
887
1042
|
}
|
|
888
|
-
exports.findExportInfoInfile = findExportInfoInfile;
|
|
889
1043
|
function getArkFileFromOtherModule(fromInfo) {
|
|
1044
|
+
var _a;
|
|
890
1045
|
const from = fromInfo.getFrom();
|
|
891
1046
|
if (!from || ModuleUtils_1.ModuleUtils.MODULES.size === 0) {
|
|
892
1047
|
return null;
|
|
893
1048
|
}
|
|
1049
|
+
const declaringFile = fromInfo.getDeclaringArkFile();
|
|
1050
|
+
const memo = sceneFileMemo(declaringFile.getScene());
|
|
1051
|
+
const key = declaringFile.getProjectDir() + '\u0000' + from;
|
|
1052
|
+
if (memo.has(key)) {
|
|
1053
|
+
return (_a = memo.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
1054
|
+
}
|
|
894
1055
|
//find file by given from like '@ohos/module/src/xxx' 'module/src/xxx'
|
|
895
|
-
const
|
|
896
|
-
|
|
1056
|
+
const firstDelimiter = from.indexOf(EtsConst_1.PATH_DELIMITER);
|
|
1057
|
+
let candidate;
|
|
1058
|
+
if (from.startsWith(EtsConst_1.SCOPE_PREFIX) && firstDelimiter >= 0) {
|
|
1059
|
+
const secondDelimiter = from.indexOf(EtsConst_1.PATH_DELIMITER, firstDelimiter + 1);
|
|
1060
|
+
candidate = secondDelimiter < 0 ? from : from.substring(0, secondDelimiter);
|
|
1061
|
+
}
|
|
1062
|
+
else {
|
|
1063
|
+
candidate = firstDelimiter < 0 ? from : from.substring(0, firstDelimiter);
|
|
1064
|
+
}
|
|
897
1065
|
const modulePath = ModuleUtils_1.ModuleUtils.MODULES.get(candidate);
|
|
898
1066
|
if (!modulePath) {
|
|
899
1067
|
return null;
|
|
@@ -901,5 +1069,7 @@ function getArkFileFromOtherModule(fromInfo) {
|
|
|
901
1069
|
const suffix = from.substring(candidate.length + 1).trim();
|
|
902
1070
|
const middle = suffix.startsWith(EtsConst_1.ETS_CODE_PATH) ? EtsConst_1.PATH_BE_OMITTED : '';
|
|
903
1071
|
const filePath = suffix.length > 1 ? path_1.default.join(modulePath.path, middle, suffix) : modulePath.main;
|
|
904
|
-
|
|
1072
|
+
const file = getArkFileFromScene(fromInfo, filePath);
|
|
1073
|
+
memo.set(key, file);
|
|
1074
|
+
return file;
|
|
905
1075
|
}
|