@hadss/hmrouter-plugin 1.2.3-rc.0 → 1.2.3-rc.1
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/README.md +5 -1
- package/dist/HMRouterPluginManager.d.ts +1 -0
- package/dist/HMRouterPluginManager.js +15 -0
- package/dist/framework/utils/ArkAnalyzerUtil.d.ts +24 -0
- package/dist/framework/utils/ArkAnalyzerUtil.js +208 -0
- package/dist/framework/utils/index.d.ts +1 -0
- package/dist/framework/utils/index.js +1 -0
- package/dist/hmrouter_extension/HMRouterExtension.js +1 -1
- package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.d.ts +1 -1
- package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.js +2 -2
- package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +1 -5
- package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +7 -59
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ HMRouter编译插件是一个基于hvigor的编译插件,用于:
|
|
|
23
23
|
```json5
|
|
24
24
|
{
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@hadss/hmrouter-plugin": "^1.2.3-rc.
|
|
26
|
+
"@hadss/hmrouter-plugin": "^1.2.3-rc.1" // 使用最新版本
|
|
27
27
|
},
|
|
28
28
|
// ...其余配置
|
|
29
29
|
}
|
|
@@ -440,6 +440,10 @@ hvigor 5.7.3及以上
|
|
|
440
440
|
|
|
441
441
|
## 更新日志
|
|
442
442
|
|
|
443
|
+
### 1.2.3-rc.1 (2026.01.15)
|
|
444
|
+
|
|
445
|
+
- [修复插件编译报错路由常量找不到问题](https://gitcode.com/openharmony-sig/ohrouter/issues/207)
|
|
446
|
+
|
|
443
447
|
### 1.2.3-rc.0 (2025.12.11)
|
|
444
448
|
|
|
445
449
|
- [修复库版本与插件版本不匹配时编译报错的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/250)
|
|
@@ -9,4 +9,5 @@ export declare class HMRouterPluginManager {
|
|
|
9
9
|
static getInstance(): HMRouterPluginManager;
|
|
10
10
|
registerPlugin(node: HvigorNode, pluginId: string, options: PluginParam): void;
|
|
11
11
|
addModuleNode(node: HvigorNode, isIgnored: boolean): void;
|
|
12
|
+
private initializeArkAnalyzer;
|
|
12
13
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HMRouterPluginManager = void 0;
|
|
4
4
|
const hvigor_1 = require("@ohos/hvigor");
|
|
5
|
+
const hvigor_ohos_plugin_1 = require("@ohos/hvigor-ohos-plugin");
|
|
5
6
|
const PluginError_1 = require("./hmrouter_extension/error/PluginError");
|
|
6
7
|
const HMRouterExtension_1 = require("./hmrouter_extension/HMRouterExtension");
|
|
7
8
|
const framework_1 = require("./framework");
|
|
@@ -13,6 +14,7 @@ class HMRouterPluginManager {
|
|
|
13
14
|
framework_1.Logger.info('', 'HMRouterPlugin starting...');
|
|
14
15
|
(0, framework_1.registerPluginExtension)(new HMRouterExtension_1.HMRouterDefaultExtension());
|
|
15
16
|
hvigor_1.hvigor.nodesEvaluated(() => {
|
|
17
|
+
this.initializeArkAnalyzer();
|
|
16
18
|
this.moduleNodes.forEach((node) => {
|
|
17
19
|
if (this.controllerMap.has(node.getNodeName())) {
|
|
18
20
|
return;
|
|
@@ -29,6 +31,7 @@ class HMRouterPluginManager {
|
|
|
29
31
|
this.controllerMap.forEach((controller) => {
|
|
30
32
|
controller.complete();
|
|
31
33
|
});
|
|
34
|
+
framework_1.ArkAnalyzerUtil.clear();
|
|
32
35
|
HMRouterPluginManager.instance = null;
|
|
33
36
|
framework_1.PluginStore.destroy();
|
|
34
37
|
framework_1.ExtensionManager.destroy();
|
|
@@ -73,6 +76,18 @@ class HMRouterPluginManager {
|
|
|
73
76
|
this.nodeIgnored.add(node.getNodeName());
|
|
74
77
|
}
|
|
75
78
|
}
|
|
79
|
+
initializeArkAnalyzer() {
|
|
80
|
+
if (this.moduleNodes.length === 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const firstNode = this.moduleNodes[0];
|
|
84
|
+
const appContext = firstNode.getParentNode()?.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN);
|
|
85
|
+
if (appContext) {
|
|
86
|
+
const projectPath = appContext.getProjectPath();
|
|
87
|
+
framework_1.Logger.info('', `Initializing ArkAnalyzer for project: ${projectPath}`);
|
|
88
|
+
framework_1.ArkAnalyzerUtil.initialize(projectPath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
76
91
|
}
|
|
77
92
|
exports.HMRouterPluginManager = HMRouterPluginManager;
|
|
78
93
|
HMRouterPluginManager.instance = null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class ArkAnalyzerUtil {
|
|
2
|
+
private static instance;
|
|
3
|
+
private scene;
|
|
4
|
+
private isInitialized;
|
|
5
|
+
private constructor();
|
|
6
|
+
static getInstance(): ArkAnalyzerUtil;
|
|
7
|
+
init(projectRoot: string): boolean;
|
|
8
|
+
isReady(): boolean;
|
|
9
|
+
findVariableFilePath(moduleName: string, variableName: string): string | undefined;
|
|
10
|
+
private findModuleSceneByName;
|
|
11
|
+
private getAllModuleScenes;
|
|
12
|
+
private findInModuleScene;
|
|
13
|
+
private findInAllFiles;
|
|
14
|
+
private isModuleMatch;
|
|
15
|
+
private findExportInFile;
|
|
16
|
+
private traceToDefinition;
|
|
17
|
+
private findFileByPath;
|
|
18
|
+
private normalizeModuleName;
|
|
19
|
+
clear(): void;
|
|
20
|
+
static isReady(): boolean;
|
|
21
|
+
static findVariableFilePath(moduleName: string, variableName: string): string | undefined;
|
|
22
|
+
static initialize(projectRoot: string): void;
|
|
23
|
+
static clear(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ArkAnalyzerUtil = void 0;
|
|
7
|
+
const arkanalyzer_1 = require("arkanalyzer");
|
|
8
|
+
const Logger_1 = require("./Logger");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
class ArkAnalyzerUtil {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.scene = null;
|
|
13
|
+
this.isInitialized = false;
|
|
14
|
+
}
|
|
15
|
+
static getInstance() {
|
|
16
|
+
if (!ArkAnalyzerUtil.instance) {
|
|
17
|
+
ArkAnalyzerUtil.instance = new ArkAnalyzerUtil();
|
|
18
|
+
}
|
|
19
|
+
return ArkAnalyzerUtil.instance;
|
|
20
|
+
}
|
|
21
|
+
init(projectRoot) {
|
|
22
|
+
if (this.isInitialized) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
this.scene = new arkanalyzer_1.Scene();
|
|
27
|
+
const options = {
|
|
28
|
+
supportFileExts: ['.ets', '.d.ets'],
|
|
29
|
+
projectName: 'HMRouterProject'
|
|
30
|
+
};
|
|
31
|
+
const config = new arkanalyzer_1.SceneConfig(options);
|
|
32
|
+
config.buildFromProjectDir(projectRoot);
|
|
33
|
+
this.scene.buildSceneFromProjectDir(config);
|
|
34
|
+
this.scene.buildScene4HarmonyProject();
|
|
35
|
+
this.scene.inferTypes();
|
|
36
|
+
this.isInitialized = true;
|
|
37
|
+
Logger_1.Logger.info('ArkAnalyzerUtil', 'Initialized successfully');
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
Logger_1.Logger.error('ArkAnalyzerUtil', `Failed to initialize: ${e}`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
isReady() {
|
|
46
|
+
return this.isInitialized && this.scene !== null;
|
|
47
|
+
}
|
|
48
|
+
findVariableFilePath(moduleName, variableName) {
|
|
49
|
+
if (!this.scene) {
|
|
50
|
+
throw new Error('ArkAnalyzer scene not initialized');
|
|
51
|
+
}
|
|
52
|
+
const moduleScene = this.findModuleSceneByName(moduleName);
|
|
53
|
+
if (moduleScene) {
|
|
54
|
+
const result = this.findInModuleScene(moduleScene, variableName);
|
|
55
|
+
if (result) {
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return this.findInAllFiles(moduleName, variableName);
|
|
60
|
+
}
|
|
61
|
+
findModuleSceneByName(moduleName) {
|
|
62
|
+
if (!this.scene) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
let moduleScene = this.scene.getModuleScene(moduleName);
|
|
66
|
+
if (moduleScene) {
|
|
67
|
+
return moduleScene;
|
|
68
|
+
}
|
|
69
|
+
const allScenes = this.getAllModuleScenes();
|
|
70
|
+
moduleScene = allScenes.find(scene => scene.getModuleName().toLowerCase() === moduleName.toLowerCase());
|
|
71
|
+
if (moduleScene) {
|
|
72
|
+
return moduleScene;
|
|
73
|
+
}
|
|
74
|
+
const normalizedModuleName = this.normalizeModuleName(moduleName);
|
|
75
|
+
if (normalizedModuleName !== moduleName) {
|
|
76
|
+
moduleScene = allScenes.find(scene => {
|
|
77
|
+
const sceneName = scene.getModuleName();
|
|
78
|
+
const normalizedSceneName = this.normalizeModuleName(sceneName);
|
|
79
|
+
return normalizedSceneName.toLowerCase() === normalizedModuleName.toLowerCase();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return moduleScene;
|
|
83
|
+
}
|
|
84
|
+
getAllModuleScenes() {
|
|
85
|
+
if (!this.scene) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
const scenes = [];
|
|
89
|
+
const files = this.scene.getFiles();
|
|
90
|
+
const seenScenes = new Set();
|
|
91
|
+
for (const file of files) {
|
|
92
|
+
const moduleScene = file.getModuleScene();
|
|
93
|
+
if (moduleScene && !seenScenes.has(moduleScene)) {
|
|
94
|
+
seenScenes.add(moduleScene);
|
|
95
|
+
scenes.push(moduleScene);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return scenes;
|
|
99
|
+
}
|
|
100
|
+
findInModuleScene(moduleScene, variableName) {
|
|
101
|
+
const filesMap = moduleScene.getModuleFilesMap();
|
|
102
|
+
for (const [, arkFile] of filesMap) {
|
|
103
|
+
const exportInfos = arkFile.getExportInfos();
|
|
104
|
+
for (const exportInfo of exportInfos) {
|
|
105
|
+
if (exportInfo.getExportClauseName() === variableName) {
|
|
106
|
+
return this.traceToDefinition(exportInfo, arkFile);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
findInAllFiles(moduleName, variableName) {
|
|
113
|
+
const normalizedModuleName = this.normalizeModuleName(moduleName);
|
|
114
|
+
const files = this.scene.getFiles();
|
|
115
|
+
for (const arkFile of files) {
|
|
116
|
+
if (!this.isModuleMatch(arkFile, moduleName, normalizedModuleName)) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const result = this.findExportInFile(arkFile, variableName);
|
|
120
|
+
if (result) {
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
isModuleMatch(arkFile, moduleName, normalizedModuleName) {
|
|
127
|
+
const fileModuleName = arkFile.getModuleName() || arkFile.getModuleScene()?.getModuleName() || '';
|
|
128
|
+
const normalizedFileModule = this.normalizeModuleName(fileModuleName);
|
|
129
|
+
if (fileModuleName === moduleName) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
if (fileModuleName.toLowerCase() === moduleName.toLowerCase()) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
if (normalizedFileModule.toLowerCase() === normalizedModuleName.toLowerCase()) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
findExportInFile(arkFile, variableName) {
|
|
141
|
+
const exportInfos = arkFile.getExportInfos();
|
|
142
|
+
for (const exportInfo of exportInfos) {
|
|
143
|
+
if (exportInfo.getExportClauseName() === variableName) {
|
|
144
|
+
return this.traceToDefinition(exportInfo, arkFile);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
traceToDefinition(exportInfo, currentFile) {
|
|
150
|
+
const fromPath = exportInfo.getFrom();
|
|
151
|
+
if (!fromPath) {
|
|
152
|
+
return currentFile.getFilePath();
|
|
153
|
+
}
|
|
154
|
+
const currentDir = path_1.default.dirname(currentFile.getFilePath());
|
|
155
|
+
let targetPath = path_1.default.resolve(currentDir, fromPath);
|
|
156
|
+
if (!targetPath.endsWith('.ets') && !targetPath.endsWith('.d.ets')) {
|
|
157
|
+
targetPath += '.ets';
|
|
158
|
+
}
|
|
159
|
+
const targetFile = this.findFileByPath(targetPath);
|
|
160
|
+
if (!targetFile) {
|
|
161
|
+
return currentFile.getFilePath();
|
|
162
|
+
}
|
|
163
|
+
const variableName = exportInfo.getNameBeforeAs() || exportInfo.getExportClauseName();
|
|
164
|
+
const targetExports = targetFile.getExportInfos();
|
|
165
|
+
for (const targetExport of targetExports) {
|
|
166
|
+
if (targetExport.getExportClauseName() === variableName) {
|
|
167
|
+
return this.traceToDefinition(targetExport, targetFile);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return targetFile.getFilePath();
|
|
171
|
+
}
|
|
172
|
+
findFileByPath(filePath) {
|
|
173
|
+
const files = this.scene.getFiles();
|
|
174
|
+
for (const arkFile of files) {
|
|
175
|
+
if (arkFile.getFilePath() === filePath) {
|
|
176
|
+
return arkFile;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
normalizeModuleName(moduleName) {
|
|
182
|
+
if (moduleName.startsWith('@')) {
|
|
183
|
+
const parts = moduleName.split('/');
|
|
184
|
+
return parts.length >= 2 ? parts[1] : moduleName;
|
|
185
|
+
}
|
|
186
|
+
return moduleName;
|
|
187
|
+
}
|
|
188
|
+
clear() {
|
|
189
|
+
if (this.scene) {
|
|
190
|
+
this.scene.dispose();
|
|
191
|
+
this.scene = null;
|
|
192
|
+
}
|
|
193
|
+
this.isInitialized = false;
|
|
194
|
+
}
|
|
195
|
+
static isReady() {
|
|
196
|
+
return ArkAnalyzerUtil.getInstance().isReady();
|
|
197
|
+
}
|
|
198
|
+
static findVariableFilePath(moduleName, variableName) {
|
|
199
|
+
return ArkAnalyzerUtil.getInstance().findVariableFilePath(moduleName, variableName);
|
|
200
|
+
}
|
|
201
|
+
static initialize(projectRoot) {
|
|
202
|
+
ArkAnalyzerUtil.getInstance().init(projectRoot);
|
|
203
|
+
}
|
|
204
|
+
static clear() {
|
|
205
|
+
ArkAnalyzerUtil.getInstance().clear();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.ArkAnalyzerUtil = ArkAnalyzerUtil;
|
|
@@ -19,7 +19,7 @@ class HMRouterDefaultExtension extends framework_1.PluginExtension {
|
|
|
19
19
|
framework_2.Logger.debug(this.name, 'module ignored: annotationAnalysis');
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().initialize(
|
|
22
|
+
AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().initialize();
|
|
23
23
|
const analyzers = AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().getAnalyzers();
|
|
24
24
|
for (const analyzer of analyzers) {
|
|
25
25
|
analyzer.analyze(sourceFile, filePath, context);
|
|
@@ -6,7 +6,7 @@ export declare class AnnotationAnalyzerRegistry {
|
|
|
6
6
|
private constantResolver;
|
|
7
7
|
private constructor();
|
|
8
8
|
static getInstance(): AnnotationAnalyzerRegistry;
|
|
9
|
-
initialize(
|
|
9
|
+
initialize(): void;
|
|
10
10
|
registerAnalyzer(analyzer: AbstractAnnotationAnalyzer): void;
|
|
11
11
|
getAnalyzers(): AbstractAnnotationAnalyzer[];
|
|
12
12
|
getConstantResolver(): IConstantResolver;
|
|
@@ -15,11 +15,11 @@ class AnnotationAnalyzerRegistry {
|
|
|
15
15
|
}
|
|
16
16
|
return this.instance;
|
|
17
17
|
}
|
|
18
|
-
initialize(
|
|
18
|
+
initialize() {
|
|
19
19
|
if (this.constantResolver) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
this.constantResolver = new ConstantResolver_1.ConstantResolver(
|
|
22
|
+
this.constantResolver = new ConstantResolver_1.ConstantResolver();
|
|
23
23
|
this.registerDefaultAnalyzers();
|
|
24
24
|
}
|
|
25
25
|
registerAnalyzer(analyzer) {
|
|
@@ -2,14 +2,10 @@ import { Expression, SourceFile } from 'ts-morph';
|
|
|
2
2
|
import { IConstantResolver } from '../interface/IConstantResolver';
|
|
3
3
|
export declare class ConstantResolver implements IConstantResolver {
|
|
4
4
|
private importMapCache;
|
|
5
|
-
private readonly modulePath;
|
|
6
|
-
constructor(modulePath: string);
|
|
7
5
|
resolveConstant(value: any, sourceFile: SourceFile, filePath: string): any;
|
|
8
6
|
resolvePropertyValue(value: Expression, sourceFile: SourceFile, filePath: string): any;
|
|
9
7
|
getVariableFilePath(variableName: string, sourceFile: SourceFile, filePath: string): string;
|
|
10
|
-
getOtherModuleVariableFilePath(moduleName: string, variableName: string
|
|
8
|
+
getOtherModuleVariableFilePath(moduleName: string, variableName: string): string;
|
|
11
9
|
private parsePrimitiveValue;
|
|
12
10
|
private parseConstantValue;
|
|
13
|
-
private parseCrossModuleVariable;
|
|
14
|
-
getExportedVariables(sourceFile: SourceFile): string[];
|
|
15
11
|
}
|
|
@@ -7,9 +7,8 @@ const constants_1 = require("../../constants");
|
|
|
7
7
|
const ImportAnalyzer_1 = require("./ImportAnalyzer");
|
|
8
8
|
const PluginError_1 = require("../../error/PluginError");
|
|
9
9
|
class ConstantResolver {
|
|
10
|
-
constructor(
|
|
10
|
+
constructor() {
|
|
11
11
|
this.importMapCache = new Map();
|
|
12
|
-
this.modulePath = modulePath;
|
|
13
12
|
}
|
|
14
13
|
resolveConstant(value, sourceFile, filePath) {
|
|
15
14
|
if (value.type === 'constant') {
|
|
@@ -87,33 +86,18 @@ class ConstantResolver {
|
|
|
87
86
|
if (!resultPath) {
|
|
88
87
|
for (const [importPath, importNames] of importMap.entries()) {
|
|
89
88
|
if (importNames.includes(variableName)) {
|
|
90
|
-
resultPath = this.getOtherModuleVariableFilePath(importPath, variableName
|
|
89
|
+
resultPath = this.getOtherModuleVariableFilePath(importPath, variableName);
|
|
91
90
|
break;
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
return resultPath;
|
|
96
95
|
}
|
|
97
|
-
getOtherModuleVariableFilePath(moduleName, variableName
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const variableCache = framework_1.PluginStore.getInstance().get('variableCache');
|
|
103
|
-
if (!variableCache) {
|
|
104
|
-
framework_1.PluginStore.getInstance().set('variableCache', new Map());
|
|
105
|
-
}
|
|
106
|
-
let variableMap;
|
|
107
|
-
if (variableCache?.has(moduleName)) {
|
|
108
|
-
variableMap = variableCache.get(moduleName);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
variableMap = this.parseCrossModuleVariable(moduleFilePath);
|
|
112
|
-
variableCache?.set(moduleName, variableMap);
|
|
113
|
-
}
|
|
114
|
-
for (let [key, value] of variableMap) {
|
|
115
|
-
if (value.includes(variableName)) {
|
|
116
|
-
return key;
|
|
96
|
+
getOtherModuleVariableFilePath(moduleName, variableName) {
|
|
97
|
+
if (framework_1.ArkAnalyzerUtil.isReady()) {
|
|
98
|
+
const filePath = framework_1.ArkAnalyzerUtil.findVariableFilePath(moduleName, variableName);
|
|
99
|
+
if (filePath) {
|
|
100
|
+
return filePath;
|
|
117
101
|
}
|
|
118
102
|
}
|
|
119
103
|
throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.UNKNOWN_VARIABLE, '', variableName);
|
|
@@ -177,41 +161,5 @@ class ConstantResolver {
|
|
|
177
161
|
}
|
|
178
162
|
return resultValue;
|
|
179
163
|
}
|
|
180
|
-
parseCrossModuleVariable(scanDir) {
|
|
181
|
-
let sourceFiles = framework_1.TsAstUtil.project.addSourceFilesAtPaths(`${scanDir}/**/*.ets`);
|
|
182
|
-
const exportMap = new Map();
|
|
183
|
-
for (let sourceFile of sourceFiles) {
|
|
184
|
-
const exportedNames = this.getExportedVariables(sourceFile);
|
|
185
|
-
if (exportedNames.length > 0) {
|
|
186
|
-
exportMap.set(sourceFile.getFilePath(), exportedNames);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return exportMap;
|
|
190
|
-
}
|
|
191
|
-
getExportedVariables(sourceFile) {
|
|
192
|
-
const exportSymbols = [];
|
|
193
|
-
let exportKeywordNodes = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ExportKeyword);
|
|
194
|
-
exportKeywordNodes.forEach((node) => {
|
|
195
|
-
let parentNodeKind = node.getParent()?.getKind();
|
|
196
|
-
switch (parentNodeKind) {
|
|
197
|
-
case ts_morph_1.SyntaxKind.VariableStatement:
|
|
198
|
-
let variableStatement = node.getParent()?.asKind(ts_morph_1.SyntaxKind.VariableStatement);
|
|
199
|
-
let variableNames = variableStatement
|
|
200
|
-
.getDeclarationList()
|
|
201
|
-
.getDeclarations()
|
|
202
|
-
.map((declaration) => {
|
|
203
|
-
return declaration.getName();
|
|
204
|
-
});
|
|
205
|
-
exportSymbols.push(...variableNames);
|
|
206
|
-
break;
|
|
207
|
-
case ts_morph_1.SyntaxKind.ClassDeclaration:
|
|
208
|
-
let classDeclaration = node.getParent();
|
|
209
|
-
let className = classDeclaration?.asKind(ts_morph_1.SyntaxKind.ClassDeclaration)?.getName();
|
|
210
|
-
exportSymbols.push(className);
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
return exportSymbols;
|
|
215
|
-
}
|
|
216
164
|
}
|
|
217
165
|
exports.ConstantResolver = ConstantResolver;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadss/hmrouter-plugin",
|
|
3
|
-
"version": "1.2.3-rc.
|
|
3
|
+
"version": "1.2.3-rc.1",
|
|
4
4
|
"description": "HMRouter Compiler Plugin",
|
|
5
5
|
"main": "dist/Index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"ejs": "^3.1.10",
|
|
23
23
|
"micromatch": "^4.0.8",
|
|
24
|
-
"ts-morph": "^23.0.0"
|
|
24
|
+
"ts-morph": "^23.0.0",
|
|
25
|
+
"arkanalyzer": "^1.0.79"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@ohos/hvigor": "^5.8.9",
|