arkanalyzer 1.0.94 → 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.
Files changed (291) hide show
  1. package/lib/Config.d.ts +7 -0
  2. package/lib/Config.d.ts.map +1 -1
  3. package/lib/Scene.d.ts +134 -170
  4. package/lib/Scene.d.ts.map +1 -1
  5. package/lib/Scene.js +412 -976
  6. package/lib/callgraph/algorithm/AbstractAnalysis.js +3 -2
  7. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +1 -1
  8. package/lib/callgraph/model/CallGraph.js +1 -1
  9. package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +1 -3
  10. package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts.map +1 -1
  11. package/lib/callgraph/pointerAnalysis/PTAUtils.js +17 -7
  12. package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
  13. package/lib/callgraph/pointerAnalysis/Pag.js +4 -14
  14. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
  15. package/lib/callgraph/pointerAnalysis/PagBuilder.js +2 -1
  16. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
  17. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +1 -2
  18. package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.d.ts.map +1 -1
  19. package/lib/callgraph/pointerAnalysis/plugins/WorkerPlugin.js +0 -1
  20. package/lib/cli/commands/cg.d.ts +1 -0
  21. package/lib/cli/commands/cg.d.ts.map +1 -1
  22. package/lib/cli/commands/cg.js +22 -18
  23. package/lib/cli/commands/ir.d.ts +1 -0
  24. package/lib/cli/commands/ir.d.ts.map +1 -1
  25. package/lib/cli/commands/ir.js +5 -2
  26. package/lib/core/base/Constant.d.ts +5 -5
  27. package/lib/core/base/Constant.d.ts.map +1 -1
  28. package/lib/core/base/Constant.js +12 -9
  29. package/lib/core/base/Expr.d.ts +36 -20
  30. package/lib/core/base/Expr.d.ts.map +1 -1
  31. package/lib/core/base/Expr.js +206 -94
  32. package/lib/core/base/Local.d.ts +10 -20
  33. package/lib/core/base/Local.d.ts.map +1 -1
  34. package/lib/core/base/Local.js +25 -28
  35. package/lib/core/base/Position.d.ts +6 -0
  36. package/lib/core/base/Position.d.ts.map +1 -1
  37. package/lib/core/base/Position.js +37 -11
  38. package/lib/core/base/Ref.d.ts +45 -33
  39. package/lib/core/base/Ref.d.ts.map +1 -1
  40. package/lib/core/base/Ref.js +225 -51
  41. package/lib/core/base/Stmt.d.ts +19 -9
  42. package/lib/core/base/Stmt.d.ts.map +1 -1
  43. package/lib/core/base/Stmt.js +135 -52
  44. package/lib/core/base/Type.d.ts +67 -4
  45. package/lib/core/base/Type.d.ts.map +1 -1
  46. package/lib/core/base/Type.js +391 -20
  47. package/lib/core/base/TypeExpr.d.ts +6 -4
  48. package/lib/core/base/TypeExpr.d.ts.map +1 -1
  49. package/lib/core/base/TypeExpr.js +34 -10
  50. package/lib/core/base/Value.d.ts +20 -2
  51. package/lib/core/base/Value.d.ts.map +1 -1
  52. package/lib/core/base/Value.js +12 -0
  53. package/lib/core/common/ArkIRTransformer.d.ts +18 -0
  54. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
  55. package/lib/core/common/ArkIRTransformer.js +94 -75
  56. package/lib/core/common/ArkValueTransformer.d.ts +21 -3
  57. package/lib/core/common/ArkValueTransformer.d.ts.map +1 -1
  58. package/lib/core/common/ArkValueTransformer.js +455 -265
  59. package/lib/core/common/Builtin.d.ts +48 -24
  60. package/lib/core/common/Builtin.d.ts.map +1 -1
  61. package/lib/core/common/Builtin.js +90 -52
  62. package/lib/core/common/CanonicalizerValidator.d.ts +308 -0
  63. package/lib/core/common/CanonicalizerValidator.d.ts.map +1 -0
  64. package/lib/core/common/CanonicalizerValidator.js +888 -0
  65. package/lib/core/common/Const.d.ts +3 -3
  66. package/lib/core/common/Const.d.ts.map +1 -1
  67. package/lib/core/common/Const.js +3 -3
  68. package/lib/core/common/DummyMainCreater.d.ts +2 -21
  69. package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
  70. package/lib/core/common/DummyMainCreater.js +8 -105
  71. package/lib/core/common/IRInference.d.ts +55 -3
  72. package/lib/core/common/IRInference.d.ts.map +1 -1
  73. package/lib/core/common/IRInference.js +407 -126
  74. package/lib/core/common/IRUtils.d.ts +1 -0
  75. package/lib/core/common/IRUtils.d.ts.map +1 -1
  76. package/lib/core/common/IRUtils.js +44 -13
  77. package/lib/core/common/ModelUtils.d.ts +44 -20
  78. package/lib/core/common/ModelUtils.d.ts.map +1 -1
  79. package/lib/core/common/ModelUtils.js +378 -208
  80. package/lib/core/common/SdkUtils.d.ts +35 -5
  81. package/lib/core/common/SdkUtils.d.ts.map +1 -1
  82. package/lib/core/common/SdkUtils.js +181 -53
  83. package/lib/core/common/SignatureCanonicalizer.d.ts +95 -0
  84. package/lib/core/common/SignatureCanonicalizer.d.ts.map +1 -0
  85. package/lib/core/common/SignatureCanonicalizer.js +116 -0
  86. package/lib/core/common/SignatureCanonicalizerRegistry.d.ts +176 -0
  87. package/lib/core/common/SignatureCanonicalizerRegistry.d.ts.map +1 -0
  88. package/lib/core/common/SignatureCanonicalizerRegistry.js +343 -0
  89. package/lib/core/common/SignatureModelCanonicalizer.d.ts +69 -0
  90. package/lib/core/common/SignatureModelCanonicalizer.d.ts.map +1 -0
  91. package/lib/core/common/SignatureModelCanonicalizer.js +109 -0
  92. package/lib/core/common/StmtUseReplacer.d.ts +1 -0
  93. package/lib/core/common/StmtUseReplacer.d.ts.map +1 -1
  94. package/lib/core/common/StmtUseReplacer.js +9 -0
  95. package/lib/core/common/StringUtils.d.ts +12 -1
  96. package/lib/core/common/StringUtils.d.ts.map +1 -1
  97. package/lib/core/common/StringUtils.js +36 -17
  98. package/lib/core/common/TempSignatureCanonicalizer.d.ts +82 -0
  99. package/lib/core/common/TempSignatureCanonicalizer.d.ts.map +1 -0
  100. package/lib/core/common/TempSignatureCanonicalizer.js +177 -0
  101. package/lib/core/common/TypeInference.d.ts +24 -6
  102. package/lib/core/common/TypeInference.d.ts.map +1 -1
  103. package/lib/core/common/TypeInference.js +243 -117
  104. package/lib/core/common/ValueUtil.d.ts +2 -1
  105. package/lib/core/common/ValueUtil.d.ts.map +1 -1
  106. package/lib/core/common/ValueUtil.js +4 -1
  107. package/lib/core/graph/Cfg.d.ts.map +1 -1
  108. package/lib/core/graph/Cfg.js +21 -6
  109. package/lib/core/graph/builder/CfgBuilder.d.ts.map +1 -1
  110. package/lib/core/graph/builder/CfgBuilder.js +46 -33
  111. package/lib/core/graph/builder/IfBuilder.d.ts.map +1 -1
  112. package/lib/core/graph/builder/IfBuilder.js +6 -2
  113. package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
  114. package/lib/core/graph/builder/ViewTreeBuilder.js +6 -2
  115. package/lib/core/inference/ModelInference.d.ts +24 -4
  116. package/lib/core/inference/ModelInference.d.ts.map +1 -1
  117. package/lib/core/inference/ModelInference.js +273 -79
  118. package/lib/core/inference/ValueInference.d.ts +3 -2
  119. package/lib/core/inference/ValueInference.d.ts.map +1 -1
  120. package/lib/core/inference/ValueInference.js +90 -40
  121. package/lib/core/inference/abc/AbcInference.d.ts.map +1 -1
  122. package/lib/core/inference/abc/AbcInference.js +28 -15
  123. package/lib/core/inference/arkts/ArkTsInference.d.ts +9 -3
  124. package/lib/core/inference/arkts/ArkTsInference.d.ts.map +1 -1
  125. package/lib/core/inference/arkts/ArkTsInference.js +54 -16
  126. package/lib/core/model/ArkClass.d.ts +192 -18
  127. package/lib/core/model/ArkClass.d.ts.map +1 -1
  128. package/lib/core/model/ArkClass.js +852 -122
  129. package/lib/core/model/ArkExport.d.ts.map +1 -1
  130. package/lib/core/model/ArkExport.js +1 -2
  131. package/lib/core/model/ArkField.d.ts +34 -2
  132. package/lib/core/model/ArkField.d.ts.map +1 -1
  133. package/lib/core/model/ArkField.js +89 -14
  134. package/lib/core/model/ArkFile.d.ts +72 -12
  135. package/lib/core/model/ArkFile.d.ts.map +1 -1
  136. package/lib/core/model/ArkFile.js +275 -65
  137. package/lib/core/model/ArkImport.d.ts.map +1 -1
  138. package/lib/core/model/ArkImport.js +1 -2
  139. package/lib/core/model/ArkMethod.d.ts +101 -15
  140. package/lib/core/model/ArkMethod.d.ts.map +1 -1
  141. package/lib/core/model/ArkMethod.js +252 -39
  142. package/lib/core/model/ArkModule.d.ts +1 -1
  143. package/lib/core/model/ArkModule.js +1 -1
  144. package/lib/core/model/ArkNamespace.d.ts +80 -10
  145. package/lib/core/model/ArkNamespace.d.ts.map +1 -1
  146. package/lib/core/model/ArkNamespace.js +309 -76
  147. package/lib/core/model/ArkSignature.d.ts +242 -18
  148. package/lib/core/model/ArkSignature.d.ts.map +1 -1
  149. package/lib/core/model/ArkSignature.js +725 -95
  150. package/lib/core/model/builder/ArkClassBuilder.d.ts +6 -3
  151. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
  152. package/lib/core/model/builder/ArkClassBuilder.js +116 -71
  153. package/lib/core/model/builder/ArkExportBuilder.d.ts +1 -1
  154. package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
  155. package/lib/core/model/builder/ArkExportBuilder.js +1 -1
  156. package/lib/core/model/builder/ArkFieldBuilder.d.ts +0 -2
  157. package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
  158. package/lib/core/model/builder/ArkFieldBuilder.js +9 -43
  159. package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -1
  160. package/lib/core/model/builder/ArkFileBuilder.js +32 -33
  161. package/lib/core/model/builder/ArkMethodBuilder.d.ts +10 -3
  162. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  163. package/lib/core/model/builder/ArkMethodBuilder.js +40 -26
  164. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +3 -2
  165. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
  166. package/lib/core/model/builder/ArkNamespaceBuilder.js +45 -77
  167. package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
  168. package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -1
  169. package/lib/core/model/builder/ArkSignatureBuilder.js +26 -3
  170. package/lib/core/model/builder/BodyBuilder.d.ts +1 -0
  171. package/lib/core/model/builder/BodyBuilder.d.ts.map +1 -1
  172. package/lib/core/model/builder/BodyBuilder.js +37 -11
  173. package/lib/core/model/builder/builderUtils.d.ts +11 -1
  174. package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
  175. package/lib/core/model/builder/builderUtils.js +124 -90
  176. package/lib/frontend/FrontendBuilder.d.ts +10 -6
  177. package/lib/frontend/FrontendBuilder.d.ts.map +1 -1
  178. package/lib/frontend/FrontendBuilder.js +19 -45
  179. package/lib/frontend/ModuleScene.d.ts +43 -0
  180. package/lib/frontend/ModuleScene.d.ts.map +1 -0
  181. package/lib/frontend/ModuleScene.js +143 -0
  182. package/lib/frontend/SceneBuildStage.d.ts +15 -0
  183. package/lib/frontend/SceneBuildStage.d.ts.map +1 -0
  184. package/lib/frontend/SceneBuildStage.js +32 -0
  185. package/lib/frontend/SceneBuilder.d.ts +153 -0
  186. package/lib/frontend/SceneBuilder.d.ts.map +1 -0
  187. package/lib/frontend/SceneBuilder.js +859 -0
  188. package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts +0 -2
  189. package/lib/frontend/arktsFrontend/ArktsFrontend.d.ts.map +1 -1
  190. package/lib/frontend/arktsFrontend/ArktsFrontend.js +0 -18
  191. package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts +17 -0
  192. package/lib/frontend/arktsFrontend/FileBodyRemount.d.ts.map +1 -0
  193. package/lib/frontend/arktsFrontend/FileBodyRemount.js +187 -0
  194. package/lib/frontend/common/ModuleBuilder.d.ts +4 -2
  195. package/lib/frontend/common/ModuleBuilder.d.ts.map +1 -1
  196. package/lib/frontend/common/ModuleBuilder.js +19 -9
  197. package/lib/frontend/cppFrontend/CppFrontend.d.ts +0 -6
  198. package/lib/frontend/cppFrontend/CppFrontend.d.ts.map +1 -1
  199. package/lib/frontend/cppFrontend/CppFrontend.js +0 -56
  200. package/lib/frontend/cppFrontend/base/Type.d.ts +7 -0
  201. package/lib/frontend/cppFrontend/base/Type.d.ts.map +1 -1
  202. package/lib/frontend/cppFrontend/base/Type.js +29 -0
  203. package/lib/frontend/cppFrontend/common/ArkIRTransformer.d.ts.map +1 -1
  204. package/lib/frontend/cppFrontend/common/ArkIRTransformer.js +56 -56
  205. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts +1 -1
  206. package/lib/frontend/cppFrontend/common/ArkValueTransformer.d.ts.map +1 -1
  207. package/lib/frontend/cppFrontend/common/ArkValueTransformer.js +124 -113
  208. package/lib/frontend/cppFrontend/common/Builtin.d.ts +29 -19
  209. package/lib/frontend/cppFrontend/common/Builtin.d.ts.map +1 -1
  210. package/lib/frontend/cppFrontend/common/Builtin.js +56 -35
  211. package/lib/frontend/cppFrontend/common/IRInference.d.ts +7 -2
  212. package/lib/frontend/cppFrontend/common/IRInference.d.ts.map +1 -1
  213. package/lib/frontend/cppFrontend/common/IRInference.js +61 -28
  214. package/lib/frontend/cppFrontend/common/IRUtils.d.ts +1 -0
  215. package/lib/frontend/cppFrontend/common/IRUtils.d.ts.map +1 -1
  216. package/lib/frontend/cppFrontend/common/IRUtils.js +22 -10
  217. package/lib/frontend/cppFrontend/common/ModelUtils.d.ts +19 -0
  218. package/lib/frontend/cppFrontend/common/ModelUtils.d.ts.map +1 -1
  219. package/lib/frontend/cppFrontend/common/ModelUtils.js +84 -3
  220. package/lib/frontend/cppFrontend/common/TypeInference.d.ts.map +1 -1
  221. package/lib/frontend/cppFrontend/common/TypeInference.js +44 -54
  222. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.d.ts.map +1 -1
  223. package/lib/frontend/cppFrontend/graph/builder/CfgBuilder.js +2 -1
  224. package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts +1 -1
  225. package/lib/frontend/cppFrontend/inference/CxxModelInference.d.ts.map +1 -1
  226. package/lib/frontend/cppFrontend/inference/CxxValueInference.d.ts.map +1 -1
  227. package/lib/frontend/cppFrontend/inference/CxxValueInference.js +41 -5
  228. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.d.ts.map +1 -1
  229. package/lib/frontend/cppFrontend/model/builder/ArkClassBuilder.js +18 -28
  230. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.d.ts.map +1 -1
  231. package/lib/frontend/cppFrontend/model/builder/ArkFieldBuilder.js +2 -3
  232. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts +2 -2
  233. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.d.ts.map +1 -1
  234. package/lib/frontend/cppFrontend/model/builder/ArkFileBuilder.js +31 -24
  235. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.d.ts.map +1 -1
  236. package/lib/frontend/cppFrontend/model/builder/ArkMethodBuilder.js +10 -16
  237. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts +0 -2
  238. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
  239. package/lib/frontend/cppFrontend/model/builder/ArkNamespaceBuilder.js +19 -37
  240. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts +1 -0
  241. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.d.ts.map +1 -1
  242. package/lib/frontend/cppFrontend/model/builder/BodyBuilder.js +30 -3
  243. package/lib/frontend/cppFrontend/model/builder/builderUtils.d.ts.map +1 -1
  244. package/lib/frontend/cppFrontend/model/builder/builderUtils.js +8 -4
  245. package/lib/index.d.ts +3 -0
  246. package/lib/index.d.ts.map +1 -1
  247. package/lib/index.js +10 -2
  248. package/lib/save/json/JsonSerialization.js +2 -2
  249. package/lib/save/source/SourceStmt.js +1 -1
  250. package/lib/save/source/SourceTransformer.d.ts.map +1 -1
  251. package/lib/save/source/SourceTransformer.js +0 -9
  252. package/lib/statistics/StageStatistics.d.ts +195 -0
  253. package/lib/statistics/StageStatistics.d.ts.map +1 -0
  254. package/lib/statistics/StageStatistics.js +346 -0
  255. package/lib/statistics/StageStatisticsReporter.d.ts +58 -0
  256. package/lib/statistics/StageStatisticsReporter.d.ts.map +1 -0
  257. package/lib/statistics/StageStatisticsReporter.js +255 -0
  258. package/lib/utils/Canonicalizer.d.ts +9 -2
  259. package/lib/utils/Canonicalizer.d.ts.map +1 -1
  260. package/lib/utils/Canonicalizer.js +19 -2
  261. package/lib/utils/CxxSceneUtils.d.ts +7 -0
  262. package/lib/utils/CxxSceneUtils.d.ts.map +1 -1
  263. package/lib/utils/CxxSceneUtils.js +10 -1
  264. package/lib/utils/FileUtils.d.ts +0 -1
  265. package/lib/utils/FileUtils.d.ts.map +1 -1
  266. package/lib/utils/FileUtils.js +1 -9
  267. package/lib/utils/HashUtils.d.ts +9 -0
  268. package/lib/utils/HashUtils.d.ts.map +1 -0
  269. package/lib/utils/HashUtils.js +65 -0
  270. package/lib/utils/ModuleUtils.d.ts.map +1 -1
  271. package/lib/utils/ModuleUtils.js +24 -5
  272. package/lib/utils/VisitedSegment.d.ts +23 -0
  273. package/lib/utils/VisitedSegment.d.ts.map +1 -0
  274. package/lib/utils/VisitedSegment.js +64 -0
  275. package/lib/utils/callGraphUtils.d.ts.map +1 -1
  276. package/lib/utils/callGraphUtils.js +7 -7
  277. package/lib/utils/getAllFiles.d.ts.map +1 -1
  278. package/lib/utils/getAllFiles.js +11 -8
  279. package/lib/utils/logger.d.ts +4 -0
  280. package/lib/utils/logger.d.ts.map +1 -1
  281. package/lib/utils/logger.js +16 -0
  282. package/lib/utils/parseArkSourceFile.d.ts +33 -0
  283. package/lib/utils/parseArkSourceFile.d.ts.map +1 -0
  284. package/lib/utils/parseArkSourceFile.js +131 -0
  285. package/package.json +1 -1
  286. package/lib/utils/DependenciesSort.d.ts +0 -3
  287. package/lib/utils/DependenciesSort.d.ts.map +0 -1
  288. package/lib/utils/DependenciesSort.js +0 -72
  289. package/lib/utils/crypto_utils.d.ts +0 -6
  290. package/lib/utils/crypto_utils.d.ts.map +0 -1
  291. package/lib/utils/crypto_utils.js +0 -57
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024-2026 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.fixupParentReferences = exports.parseArkSourceFile = void 0;
21
+ const ohos_typescript_1 = __importDefault(require("ohos-typescript"));
22
+ const DECLARATION_FILE_NAME = /\.d\.(ts|ets)$/;
23
+ /**
24
+ * Parse a source file, keeping the parser from building JSDoc nodes for declaration files.
25
+ *
26
+ * Documentation is read out of the raw text - `getLeadingCommentRanges` plus `substring` in
27
+ * ArkMetadataBuilder, and the scanner in every comment query - never out of `node.jsDoc`, so the JSDoc
28
+ * nodes the parser materialises are pure cost. They are 88% of the parse time of an SDK `.d.ts` file,
29
+ * which is where most of the build's declaration volume sits; project sources carry almost no JSDoc,
30
+ * so they are parsed unchanged.
31
+ *
32
+ * The parser decides from the comment opener alone, so the opener is blanked for the parse
33
+ * (`/**` becomes `/* `). That is one character per comment and it leaves the comment's extent and every
34
+ * offset in the file exactly where they were, so the only difference in the tree is the absent `jsDoc`
35
+ * array. The original text is put back on the SourceFile before anything reads it, which keeps
36
+ * text-derived comments, JSDoc metadata and line maps identical.
37
+ */
38
+ function parseArkSourceFile(fileName, sourceText, setParentNodes, options) {
39
+ const parseText = DECLARATION_FILE_NAME.test(fileName) ? blankJsDocOpeners(sourceText) : sourceText;
40
+ const sourceFile = ohos_typescript_1.default.createSourceFile(fileName, parseText, ohos_typescript_1.default.ScriptTarget.Latest, false, undefined, options);
41
+ if (parseText !== sourceText) {
42
+ sourceFile.text = sourceText;
43
+ sourceFile.lineMap = undefined;
44
+ }
45
+ if (setParentNodes) {
46
+ fixupParentReferences(sourceFile);
47
+ }
48
+ return sourceFile;
49
+ }
50
+ exports.parseArkSourceFile = parseArkSourceFile;
51
+ const fixupStack = [];
52
+ const fixupChildren = [];
53
+ let fixupStackTop = 0;
54
+ let fixupChildCount = 0;
55
+ const collectFixupChild = (child) => {
56
+ fixupChildren[fixupChildCount++] = child;
57
+ };
58
+ /**
59
+ * Zero-allocation replacement for the parser's built-in parent fixup. The bundled walk
60
+ * (`setParentRecursive` -> `forEachChildRecursively` -> `gatherPossibleChildren`) allocates a
61
+ * children array plus a collector closure per node and grows two parallel work stacks with
62
+ * `unshift`/`push` - gigabytes of churn on a full build where every project file is parsed
63
+ * twice (signature round plus body remount). This explicit-stack walk reuses two module-level
64
+ * scratch arrays and one shared collector closure, and reproduces the same parent links,
65
+ * including the JSDoc nodes the bundled walk binds via `bindJSDoc`.
66
+ *
67
+ * The scratches are reset by cursor, never by `length = 0`: truncating a V8 array to zero
68
+ * drops its backing store, so every refill would reallocate from scratch (measured 12x the
69
+ * scavenge count of the cursor pattern). Spent slots are nulled to the high-water mark so
70
+ * the parsed tree stays collectable; null keeps the arrays in PACKED_ELEMENTS.
71
+ */
72
+ function fixupParentReferences(rootNode) {
73
+ fixupStack[fixupStackTop++] = rootNode;
74
+ let stackHighWater = fixupStackTop;
75
+ let childHighWater = 0;
76
+ while (fixupStackTop > 0) {
77
+ const node = fixupStack[--fixupStackTop];
78
+ fixupChildCount = 0;
79
+ ohos_typescript_1.default.forEachChild(node, collectFixupChild);
80
+ const jsDoc = node.jsDoc;
81
+ if (jsDoc !== undefined) {
82
+ for (const doc of jsDoc) {
83
+ fixupChildren[fixupChildCount++] = doc;
84
+ }
85
+ }
86
+ if (fixupChildCount > childHighWater) {
87
+ childHighWater = fixupChildCount;
88
+ }
89
+ for (let i = 0; i < fixupChildCount; i++) {
90
+ const child = fixupChildren[i];
91
+ child.parent = node;
92
+ fixupStack[fixupStackTop++] = child;
93
+ }
94
+ if (fixupStackTop > stackHighWater) {
95
+ stackHighWater = fixupStackTop;
96
+ }
97
+ }
98
+ const nullNode = null;
99
+ for (let i = 0; i < stackHighWater; i++) {
100
+ fixupStack[i] = nullNode;
101
+ }
102
+ for (let i = 0; i < childHighWater; i++) {
103
+ fixupChildren[i] = nullNode;
104
+ }
105
+ fixupStackTop = 0;
106
+ fixupChildCount = 0;
107
+ }
108
+ exports.fixupParentReferences = fixupParentReferences;
109
+ function blankJsDocOpeners(sourceText) {
110
+ const scanner = ohos_typescript_1.default.createScanner(ohos_typescript_1.default.ScriptTarget.Latest, false, ohos_typescript_1.default.LanguageVariant.Standard, sourceText);
111
+ const openers = [];
112
+ for (let token = scanner.scan(); token !== ohos_typescript_1.default.SyntaxKind.EndOfFileToken; token = scanner.scan()) {
113
+ if (token === ohos_typescript_1.default.SyntaxKind.MultiLineCommentTrivia) {
114
+ const pos = scanner.getTokenPos();
115
+ if (sourceText.startsWith('/**', pos) && sourceText[pos + 3] !== '/') {
116
+ openers.push(pos);
117
+ }
118
+ }
119
+ }
120
+ if (openers.length === 0) {
121
+ return sourceText;
122
+ }
123
+ const parts = [];
124
+ let last = 0;
125
+ for (const pos of openers) {
126
+ parts.push(sourceText.slice(last, pos + 2), ' ');
127
+ last = pos + 3;
128
+ }
129
+ parts.push(sourceText.slice(last));
130
+ return parts.join('');
131
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkanalyzer",
3
- "version": "1.0.94",
3
+ "version": "2.0.0-beta1",
4
4
  "files": [
5
5
  "lib",
6
6
  "config"
@@ -1,3 +0,0 @@
1
- import { ArkFile } from '../core/model/ArkFile';
2
- export declare function sortByDependency(filesMap: Map<string, ArkFile>, projectName: string): ArkFile[];
3
- //# sourceMappingURL=DependenciesSort.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DependenciesSort.d.ts","sourceRoot":"","sources":["../../src/utils/DependenciesSort.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIhD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,EAAE,CAoD/F"}
@@ -1,72 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024-2026 Huawei Device Co., Ltd.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.sortByDependency = void 0;
18
- const ModelUtils_1 = require("../core/common/ModelUtils");
19
- function sortByDependency(filesMap, projectName) {
20
- const inDegree = new Map();
21
- const adjacency = new Map();
22
- filesMap.forEach((file, key) => {
23
- inDegree.set(key, 0);
24
- adjacency.set(key, new Set());
25
- });
26
- // Build dependency graph: if file A imports file B, add edge B -> A (B should be processed before A)
27
- filesMap.forEach((file, fileKey) => {
28
- let fromInfos = file.getImportInfos();
29
- fromInfos = fromInfos.concat(file.getExportInfos());
30
- for (const importInfo of fromInfos) {
31
- const depFile = (0, ModelUtils_1.getArkFile)(importInfo);
32
- if (!depFile || depFile.getProjectName() !== projectName) {
33
- continue;
34
- }
35
- const depKey = depFile.getFileSignature().toMapKey();
36
- let importedFilesSet = adjacency.get(depKey);
37
- if (depKey !== fileKey && importedFilesSet && !importedFilesSet.has(fileKey)) {
38
- importedFilesSet.add(fileKey);
39
- inDegree.set(fileKey, (inDegree.get(fileKey) || 0) + 1);
40
- }
41
- }
42
- });
43
- // Topological sort (Kahn's algorithm)
44
- const queue = [];
45
- for (const [key, degree] of inDegree) {
46
- if (degree === 0) {
47
- queue.push(key);
48
- }
49
- }
50
- const result = [];
51
- const visited = new Set();
52
- while (queue.length > 0) {
53
- const current = queue.shift();
54
- visited.add(current);
55
- result.push(filesMap.get(current));
56
- for (const neighbor of adjacency.get(current)) {
57
- const newDegree = (inDegree.get(neighbor) || 0) - 1;
58
- inDegree.set(neighbor, newDegree);
59
- if (newDegree === 0) {
60
- queue.push(neighbor);
61
- }
62
- }
63
- }
64
- // Add remaining files that are part of cycles
65
- filesMap.forEach((file, key) => {
66
- if (!visited.has(key)) {
67
- result.push(file);
68
- }
69
- });
70
- return result;
71
- }
72
- exports.sortByDependency = sortByDependency;
@@ -1,6 +0,0 @@
1
- export declare class CryptoUtils {
2
- static sha256(content: string): string;
3
- static hash(content: string, algorithm: string): string;
4
- static hashcode(content: string): number;
5
- }
6
- //# sourceMappingURL=crypto_utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto_utils.d.ts","sourceRoot":"","sources":["../../src/utils/crypto_utils.ts"],"names":[],"mappings":"AAiBA,qBAAa,WAAW;WACN,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;WAI/B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;WAIhD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAOlD"}
@@ -1,57 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- var desc = Object.getOwnPropertyDescriptor(m, k);
19
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
- desc = { enumerable: true, get: function() { return m[k]; } };
21
- }
22
- Object.defineProperty(o, k2, desc);
23
- }) : (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- o[k2] = m[k];
26
- }));
27
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
- Object.defineProperty(o, "default", { enumerable: true, value: v });
29
- }) : function(o, v) {
30
- o["default"] = v;
31
- });
32
- var __importStar = (this && this.__importStar) || function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.CryptoUtils = void 0;
41
- const crypto = __importStar(require("crypto"));
42
- class CryptoUtils {
43
- static sha256(content) {
44
- return this.hash(content, 'sha256');
45
- }
46
- static hash(content, algorithm) {
47
- return crypto.createHash(algorithm).update(content).digest('base64url');
48
- }
49
- static hashcode(content) {
50
- let h = 0;
51
- for (let i = 0; i < content.length; i++) {
52
- h = (Math.imul(31, h) + content.charCodeAt(i)) | 0;
53
- }
54
- return h;
55
- }
56
- }
57
- exports.CryptoUtils = CryptoUtils;