js-code-detector 0.0.48 → 0.0.51

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 (47) hide show
  1. package/dist/cjs/index.d.ts +1 -43
  2. package/dist/cjs/index.js +3 -25
  3. package/dist/cjs/services/DetectService.d.ts +3 -1
  4. package/dist/cjs/services/DetectService.js +30 -7
  5. package/dist/cjs/services/ProjectService.d.ts +1 -2
  6. package/dist/cjs/services/projectServiceClass/UmiProjectService.d.ts +4 -0
  7. package/dist/cjs/services/projectServiceClass/UmiProjectService.js +11 -7
  8. package/dist/cjs/services/projectServiceClass/VueProjectService.d.ts +31 -0
  9. package/dist/cjs/services/projectServiceClass/VueProjectService.js +191 -0
  10. package/dist/cjs/util/ast_util/AstFeatUtil.js +2 -4
  11. package/dist/cjs/util/ast_util/AstKit.d.ts +30 -0
  12. package/dist/cjs/util/ast_util/AstKit.js +574 -0
  13. package/dist/cjs/util/ast_util/AstUtil.d.ts +7 -7
  14. package/dist/cjs/util/ast_util/AstUtil.js +18 -14
  15. package/dist/cjs/util/ast_util/SHARED_CONSTANTS.d.ts +3 -0
  16. package/dist/cjs/util/ast_util/SHARED_CONSTANTS.js +35 -0
  17. package/dist/cjs/util/constants.d.ts +1 -0
  18. package/dist/cjs/util/constants.js +5 -2
  19. package/dist/cjs/util/{shared/gitUtil.d.ts → git_util/cloneRepoWithBranchAndDefault.d.ts} +1 -5
  20. package/dist/cjs/util/{shared/gitUtil.js → git_util/cloneRepoWithBranchAndDefault.js} +5 -25
  21. package/dist/cjs/util/git_util/execGitDiff.d.ts +4 -0
  22. package/dist/cjs/util/git_util/execGitDiff.js +39 -0
  23. package/dist/cjs/util/git_util/getGitRepositoryAndBranch.d.ts +4 -0
  24. package/dist/cjs/util/{report_util/getFileDepends.js → git_util/getGitRepositoryAndBranch.js} +15 -18
  25. package/dist/cjs/util/{parseGitLabDiffUril.js → git_util/parseGitLabDiffUril.js} +2 -2
  26. package/dist/cjs/util/{shared → project_umi_util}/umi4ProjectUtil.js +1 -1
  27. package/dist/cjs/util/{shared → project_umi_util}/vueProjectUtil.js +1 -1
  28. package/dist/cjs/util/report_util/createDependenceMap.js +3 -3
  29. package/dist/cjs/util/report_util/filterEffectedCode.d.ts +1 -1
  30. package/dist/cjs/util/report_util/filterEffectedExportMember.js +5 -1
  31. package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +1 -1
  32. package/dist/cjs/util/report_util/generateGitDiffReport.js +2 -2
  33. package/dist/cjs/util/{ast_util/filePathResolver.d.ts → report_util/resolveImportPath.d.ts} +1 -1
  34. package/dist/cjs/util/{ast_util/filePathResolver.js → report_util/resolveImportPath.js} +5 -9
  35. package/dist/cjs/util/{createRandomStr.js → shared/createRandomStr.js} +1 -1
  36. package/dist/cjs/util/shared/getRepoSupportFlag.d.ts +1 -3
  37. package/dist/cjs/util/shared/getRepoSupportFlag.js +1 -18
  38. package/dist/cjs/util/shared/gitDiffTool.d.ts +0 -40
  39. package/dist/cjs/util/shared/gitDiffTool.js +7 -116
  40. package/package.json +5 -1
  41. package/dist/cjs/util/madge_util.d.ts +0 -12
  42. package/dist/cjs/util/madge_util.js +0 -120
  43. package/dist/cjs/util/report_util/getFileDepends.d.ts +0 -1
  44. /package/dist/cjs/util/{parseGitLabDiffUril.d.ts → git_util/parseGitLabDiffUril.d.ts} +0 -0
  45. /package/dist/cjs/util/{shared → project_umi_util}/umi4ProjectUtil.d.ts +0 -0
  46. /package/dist/cjs/util/{shared → project_umi_util}/vueProjectUtil.d.ts +0 -0
  47. /package/dist/cjs/util/{createRandomStr.d.ts → shared/createRandomStr.d.ts} +0 -0
@@ -0,0 +1,574 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/util/ast_util/AstKit.ts
20
+ var AstKit_exports = {};
21
+ __export(AstKit_exports, {
22
+ AstUtil: () => AstUtil
23
+ });
24
+ module.exports = __toCommonJS(AstKit_exports);
25
+ var import_intrinsicElements = require("./intrinsicElements");
26
+ var import_SHARED_CONSTANTS = require("./SHARED_CONSTANTS");
27
+ var import_windowProperties = require("./windowProperties");
28
+ var _AstUtil = class {
29
+ static getNodePath(node) {
30
+ return [...node._util.ancestors, node].map((n) => n.type).join(":") + ":" + node.name;
31
+ }
32
+ static getShortNodeMsg(node, hideParentProperty = false) {
33
+ const { _util: { startLine, startColumn, endLine, endColumn, parentProperty, indexOfProperty } } = node;
34
+ let type = node.type;
35
+ let name = node.name;
36
+ if (name && typeof name === "object") {
37
+ type = name.type;
38
+ name = name.name;
39
+ }
40
+ const msg = [
41
+ hideParentProperty ? [] : [parentProperty, indexOfProperty !== null ? String(indexOfProperty) : null],
42
+ [type, name]
43
+ ].map((e) => e.filter(Boolean).join(":")).filter(Boolean).join(" ");
44
+ return `${msg}「${startLine}:${startColumn}, ${endLine}:${endColumn}」`;
45
+ }
46
+ static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStart, lineNumberEnd, loose = false) {
47
+ const nodeSet = /* @__PURE__ */ new Set();
48
+ for (let i = lineNumberStart; i <= lineNumberEnd; i++) {
49
+ const astNode = mapFileLineToNodeSet.get(i);
50
+ if (!astNode) {
51
+ continue;
52
+ }
53
+ let added = false;
54
+ for (const nodeItem of astNode) {
55
+ const { startLine, endLine } = nodeItem._util;
56
+ if (startLine >= lineNumberStart && endLine <= lineNumberEnd) {
57
+ if (!["File", "Program"].includes(nodeItem.type)) {
58
+ nodeSet.add(nodeItem);
59
+ }
60
+ added = true;
61
+ }
62
+ }
63
+ if (!added && loose) {
64
+ const firstNode = [...astNode][0];
65
+ if (!["File", "Program"].includes(firstNode.type)) {
66
+ nodeSet.add(firstNode);
67
+ }
68
+ }
69
+ }
70
+ const collections = [...nodeSet].map((e) => e._util.nodeCollection).flat();
71
+ return [...nodeSet].filter((e) => !collections.includes(e));
72
+ }
73
+ static isValidNodeCollect(astNode) {
74
+ return typeof (astNode == null ? void 0 : astNode.type) === "string";
75
+ }
76
+ static isValidArrayNodeCollect(astNode) {
77
+ return Array.isArray(astNode) && astNode.some((v) => typeof (v == null ? void 0 : v.type) === "string");
78
+ }
79
+ static collectEffectId(id) {
80
+ }
81
+ static findOrCreateImportedMember(importedMember, sourceValue) {
82
+ let target = importedMember.find((v) => v.sourcePath === sourceValue);
83
+ if (!target) {
84
+ target = { sourcePath: sourceValue, members: [] };
85
+ importedMember.push(target);
86
+ }
87
+ return target;
88
+ }
89
+ static findOrCreateExportedMember(exportedMember, sourceValue) {
90
+ let target = exportedMember.find((v) => v.sourcePath === sourceValue);
91
+ if (!target) {
92
+ target = { sourcePath: sourceValue, members: [], ExportAllDeclaration: false };
93
+ exportedMember.push(target);
94
+ }
95
+ return target;
96
+ }
97
+ static updateImportedAndExportedMember(node, programNode) {
98
+ var _a;
99
+ const { type, source, declaration, specifiers, _util } = node;
100
+ const { filePath } = _util;
101
+ const sourceValue = (source == null ? void 0 : source.value) || filePath;
102
+ const { importedMember, exportedMember } = programNode._util;
103
+ if (type === "ImportDeclaration") {
104
+ specifiers.forEach((specifier) => {
105
+ const { local, imported } = specifier;
106
+ const target = this.findOrCreateImportedMember(importedMember, sourceValue);
107
+ if (specifier.type === "ImportNamespaceSpecifier") {
108
+ target.members.push({
109
+ localName: local.name,
110
+ importedName: "*"
111
+ });
112
+ return;
113
+ }
114
+ if (specifier.type === "ImportDefaultSpecifier") {
115
+ target.members.push({
116
+ localName: local.name,
117
+ importedName: "default"
118
+ });
119
+ return;
120
+ }
121
+ if (specifier.type === "ImportSpecifier") {
122
+ target.members.push({
123
+ localName: local.name,
124
+ importedName: imported.name
125
+ });
126
+ }
127
+ });
128
+ }
129
+ if (type === "ExportAllDeclaration") {
130
+ const target = exportedMember.find((v) => v.sourcePath === sourceValue);
131
+ if (!target) {
132
+ exportedMember.push({ sourcePath: sourceValue, members: [], ExportAllDeclaration: true });
133
+ }
134
+ }
135
+ if (type === "ExportNamedDeclaration") {
136
+ Array.isArray(specifiers) && specifiers.forEach((specifier) => {
137
+ const { local, exported } = specifier;
138
+ const target = this.findOrCreateExportedMember(exportedMember, sourceValue);
139
+ if (specifier.type === "ExportNamespaceSpecifier") {
140
+ target.members.push({
141
+ localName: "*",
142
+ exportedName: exported.name
143
+ });
144
+ return;
145
+ }
146
+ if (specifier.type === "ExportSpecifier") {
147
+ target.members.push({
148
+ localName: local.name,
149
+ exportedName: exported.name
150
+ });
151
+ return;
152
+ }
153
+ });
154
+ if (Array.isArray(declaration == null ? void 0 : declaration.declarations)) {
155
+ declaration == null ? void 0 : declaration.declarations.forEach((dec) => {
156
+ const target = this.findOrCreateExportedMember(exportedMember, sourceValue);
157
+ this.collectVariableDeclarationIdentifiers(dec, (identifier) => {
158
+ try {
159
+ const idName = identifier.name;
160
+ target.members.push({
161
+ localName: idName,
162
+ exportedName: idName
163
+ });
164
+ } catch (e) {
165
+ console.log("declaration?.declarations.forEach", e.message);
166
+ }
167
+ });
168
+ });
169
+ } else if (this.EXPORT_DECLARATION_TYPES.includes(declaration == null ? void 0 : declaration.type)) {
170
+ const target = this.findOrCreateExportedMember(exportedMember, sourceValue);
171
+ try {
172
+ const idName = (_a = declaration.id) == null ? void 0 : _a.name;
173
+ target.members.push({
174
+ localName: idName,
175
+ exportedName: idName
176
+ });
177
+ } catch (e) {
178
+ console.log("declaration " + e.message);
179
+ }
180
+ }
181
+ }
182
+ if (type === "ExportDefaultDeclaration") {
183
+ let target = exportedMember.find((v) => v.sourcePath === filePath);
184
+ if (!target) {
185
+ target = { sourcePath: filePath, members: [], ExportAllDeclaration: false };
186
+ exportedMember.push(target);
187
+ }
188
+ target.members.push({
189
+ localName: "default",
190
+ exportedName: "default"
191
+ });
192
+ }
193
+ }
194
+ static deepSearchParamsIdentifier(id, callback) {
195
+ if (!id) {
196
+ return;
197
+ }
198
+ if (id.type === "Identifier") {
199
+ callback(id);
200
+ }
201
+ if (id.type === "AssignmentPattern") {
202
+ const left = id.left;
203
+ this.deepSearchParamsIdentifier(left, callback);
204
+ }
205
+ if (id.type === "RestElement") {
206
+ this.deepSearchParamsIdentifier(id.argument, callback);
207
+ }
208
+ if (id.type === "ObjectProperty") {
209
+ const value = id.value;
210
+ this.deepSearchParamsIdentifier(value, callback);
211
+ }
212
+ if (id.type === "ObjectPattern") {
213
+ const properties = id.properties;
214
+ for (const property of properties) {
215
+ this.deepSearchParamsIdentifier(property, callback);
216
+ }
217
+ }
218
+ if (id.type === "ArrayPattern") {
219
+ const elements = id.elements;
220
+ for (const element of elements) {
221
+ this.deepSearchParamsIdentifier(element, callback);
222
+ }
223
+ }
224
+ }
225
+ static collectDependenceIdsOfExportMembers(node, callback) {
226
+ if (node.type === "ExportNamedDeclaration") {
227
+ const { declaration, specifiers } = node;
228
+ if ((declaration == null ? void 0 : declaration.type) === "Identifier") {
229
+ callback(declaration);
230
+ }
231
+ for (const specifier of specifiers) {
232
+ const { local } = specifier;
233
+ if ((local == null ? void 0 : local.type) === "Identifier") {
234
+ callback(local);
235
+ }
236
+ }
237
+ }
238
+ if (node.type === "ExportDefaultDeclaration") {
239
+ const declaration = node.declaration;
240
+ if ((declaration == null ? void 0 : declaration.type) === "Identifier") {
241
+ callback(declaration);
242
+ }
243
+ }
244
+ }
245
+ static collectExpressionIdentifiersShallow(exp, callback) {
246
+ if (!exp || exp.type === "ThisExpression") {
247
+ return;
248
+ }
249
+ this._collectExpressionIdentifiersShallow(exp, callback);
250
+ }
251
+ static _collectExpressionIdentifiersShallow(exp, callback) {
252
+ var _a, _b;
253
+ if (!exp || exp.type === "ThisExpression" || exp._util.holdingIdType)
254
+ return;
255
+ if (exp.type === "Identifier") {
256
+ if ((exp._util.parentProperty === "property" || exp._util.parentProperty === "key") && !((_a = exp._util.parent) == null ? void 0 : _a.computed))
257
+ return;
258
+ callback(exp);
259
+ return;
260
+ }
261
+ if (exp.type === "JSXIdentifier" && ((_b = exp._util.parent) == null ? void 0 : _b.type) !== "JSXAttribute") {
262
+ callback(exp);
263
+ return;
264
+ }
265
+ }
266
+ static collectDependenceIds(node) {
267
+ const { _util } = node;
268
+ const { dependenceIds, holdingIdNameMap, children, dependenceIdsNoScope, holdingIds } = _util;
269
+ children.forEach((child) => {
270
+ if (child._util.dependenceIdsNoScope.size > 0) {
271
+ child._util.dependenceIdsNoScope.forEach((id) => dependenceIds.add(id));
272
+ }
273
+ this.collectDependenceIdsOfExportMembers(child, (id) => dependenceIds.add(id));
274
+ this.collectExpressionIdentifiersShallow(child, (exp) => {
275
+ var _a, _b;
276
+ if (exp.type === "ThisExpression" || exp._util.holdingIdType || ["imported", "exported"].includes(exp._util.parentProperty))
277
+ return;
278
+ if (exp.type === "Identifier") {
279
+ if ((exp._util.parentProperty === "property" || exp._util.parentProperty === "key") && !((_a = exp._util.parent) == null ? void 0 : _a.computed))
280
+ return;
281
+ }
282
+ if (exp.type === "JSXIdentifier" && ((_b = exp._util.parent) == null ? void 0 : _b.type) === "JSXAttribute")
283
+ return;
284
+ dependenceIds.add(exp);
285
+ });
286
+ });
287
+ for (const dependenceId of [...dependenceIds]) {
288
+ if (!dependenceId._util) {
289
+ continue;
290
+ }
291
+ if (holdingIds.has(dependenceId)) {
292
+ dependenceIds.delete(dependenceId);
293
+ continue;
294
+ }
295
+ if (dependenceId._util.variableScope.length === 0 && typeof dependenceId.name === "string" && holdingIdNameMap.has(dependenceId.name)) {
296
+ dependenceId._util.variableScope.push(...holdingIdNameMap.get(dependenceId.name));
297
+ const firstPick = dependenceId._util.variableScope[0];
298
+ if (firstPick && firstPick._util.uuid !== dependenceId._util.uuid) {
299
+ firstPick._util.occupation.add(dependenceId);
300
+ }
301
+ }
302
+ if (dependenceId._util.variableScope.length === 0) {
303
+ dependenceIdsNoScope.add(dependenceId);
304
+ }
305
+ }
306
+ if (node.type === "Program") {
307
+ for (const dependenceId of [...dependenceIdsNoScope]) {
308
+ if (dependenceId.type === "JSXIdentifier" && this.intrinsicElements.includes(dependenceId.name)) {
309
+ dependenceIdsNoScope.delete(dependenceId);
310
+ dependenceIds.delete(dependenceId);
311
+ } else if (dependenceId.type === "Identifier" && this.windowProperties.includes(dependenceId.name)) {
312
+ dependenceIdsNoScope.delete(dependenceId);
313
+ dependenceIds.delete(dependenceId);
314
+ }
315
+ }
316
+ }
317
+ }
318
+ static updateLoc(astNode, extra) {
319
+ var _a, _b, _c, _d, _e, _f, _g;
320
+ const { _util, type, name } = astNode;
321
+ const { mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet } = extra;
322
+ const { nodeCollection, filePath, parent } = _util;
323
+ _util.startLine = Math.min(...nodeCollection.map((n) => {
324
+ var _a2, _b2;
325
+ return (_b2 = (_a2 = n.loc) == null ? void 0 : _a2.start) == null ? void 0 : _b2.line;
326
+ }), (_a = astNode.loc) == null ? void 0 : _a.start.line);
327
+ _util.endLine = Math.max(...nodeCollection.map((n) => {
328
+ var _a2, _b2;
329
+ return (_b2 = (_a2 = n.loc) == null ? void 0 : _a2.end) == null ? void 0 : _b2.line;
330
+ }), (_b = astNode.loc) == null ? void 0 : _b.end.line);
331
+ _util.startColumn = ((_c = astNode.loc) == null ? void 0 : _c.start.column) ?? Math.min(...nodeCollection.map((n) => {
332
+ var _a2, _b2;
333
+ return (_b2 = (_a2 = n.loc) == null ? void 0 : _a2.start) == null ? void 0 : _b2.column;
334
+ }), (_d = astNode.loc) == null ? void 0 : _d.start.column);
335
+ _util.endColumn = ((_e = astNode.loc) == null ? void 0 : _e.end.column) ?? Math.max(...nodeCollection.map((n) => {
336
+ var _a2, _b2;
337
+ return (_b2 = (_a2 = n.loc) == null ? void 0 : _a2.end) == null ? void 0 : _b2.column;
338
+ }), (_f = astNode.loc) == null ? void 0 : _f.end.column);
339
+ _util.uuid = `${filePath}@${type}:${name}「${_util.startLine}:${_util.startColumn},${_util.endLine}:${_util.endColumn}」`;
340
+ mapUuidToNode.set(_util.uuid, astNode);
341
+ for (let i = _util.startLine; i <= _util.endLine; i++) {
342
+ mapFileLineToNodeSet.set(i, mapFileLineToNodeSet.get(i) || /* @__PURE__ */ new Set());
343
+ (_g = mapFileLineToNodeSet.get(i)) == null ? void 0 : _g.add(astNode);
344
+ }
345
+ if (astNode.type === "Program") {
346
+ mapUuidToNode.set(astNode.type, astNode);
347
+ }
348
+ if (parent === null) {
349
+ nodeCollection.forEach((n) => {
350
+ var _a2;
351
+ const path = _AstUtil.getNodePath(n);
352
+ mapPathToNodeSet.set(path, mapPathToNodeSet.get(path) || /* @__PURE__ */ new Set());
353
+ (_a2 = mapPathToNodeSet.get(path)) == null ? void 0 : _a2.add(n);
354
+ });
355
+ }
356
+ }
357
+ static collectVariableDeclarationIdentifiers(node, callback) {
358
+ if (node.type !== "VariableDeclaration")
359
+ return;
360
+ const declarations = node.declarations;
361
+ for (const declaration of declarations) {
362
+ this.deepSearchParamsIdentifier(declaration.id, callback);
363
+ }
364
+ }
365
+ static collectDeclarationIdentifiers(node, callback) {
366
+ if (!this.EXPORT_DECLARATION_TYPES.includes(node.type))
367
+ return;
368
+ const id = node.id;
369
+ id && callback(id);
370
+ }
371
+ static collectImportDeclarationIdentifiers(node, callback) {
372
+ if (node.type !== "Program")
373
+ return;
374
+ const { body } = node;
375
+ Array.isArray(body) && body.forEach((node2) => {
376
+ if (node2.type === "ImportDeclaration") {
377
+ const specifiers = node2.specifiers;
378
+ for (const specifier of specifiers) {
379
+ const local = specifier.local;
380
+ callback(local);
381
+ }
382
+ }
383
+ });
384
+ }
385
+ static collectHoldingIds(node) {
386
+ const { holdingIds, holdingIdNameMap } = node._util;
387
+ if (this.FUNCTION_TYPES.includes(node.type)) {
388
+ const { params, id } = node;
389
+ if (Array.isArray(params) && params.length > 0) {
390
+ params.forEach((param) => this.deepSearchParamsIdentifier(param, (id2) => {
391
+ holdingIds.add(id2 || node);
392
+ id2._util.variableScope = [id2];
393
+ id2._util.holdingIdType = "Param";
394
+ }));
395
+ }
396
+ if (node.body && node.body.type === "BlockStatement") {
397
+ node.body._util.holdingIds.forEach((id2) => {
398
+ holdingIds.add(id2);
399
+ });
400
+ }
401
+ }
402
+ this.collectImportDeclarationIdentifiers(node, (id) => {
403
+ holdingIds.add(id);
404
+ id._util.variableScope = [id];
405
+ id._util.holdingIdType = "Import";
406
+ });
407
+ if (["BlockStatement", "Program"].includes(node.type)) {
408
+ const body = node.body;
409
+ Array.isArray(body) && body.forEach((bodyChild) => {
410
+ this.collectVariableDeclarationIdentifiers(bodyChild, (id) => {
411
+ holdingIds.add(id);
412
+ id._util.variableScope = [id];
413
+ id._util.holdingIdType = "Variable";
414
+ });
415
+ if (this.EXPORT_DECLARATION_TYPES.includes(bodyChild.type)) {
416
+ this.collectDeclarationIdentifiers(bodyChild, (id) => {
417
+ var _a, _b;
418
+ holdingIds.add(id);
419
+ (_b = (_a = id._util.parent) == null ? void 0 : _a._util.holdingIds) == null ? void 0 : _b.add(id);
420
+ id._util.variableScope = [id];
421
+ id._util.holdingIdType = node.type.replace("Declaration", "");
422
+ });
423
+ }
424
+ if (["ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(bodyChild.type)) {
425
+ const declaration = bodyChild.declaration;
426
+ if (declaration) {
427
+ if (declaration.type === "VariableDeclaration") {
428
+ this.collectVariableDeclarationIdentifiers(declaration, (id) => {
429
+ holdingIds.add(id);
430
+ id._util.variableScope = [id];
431
+ id._util.holdingIdType = "Variable";
432
+ });
433
+ } else {
434
+ this.collectDeclarationIdentifiers(declaration, (id) => {
435
+ var _a, _b;
436
+ holdingIds.add(id);
437
+ (_b = (_a = id._util.parent) == null ? void 0 : _a._util.holdingIds) == null ? void 0 : _b.add(id);
438
+ id._util.variableScope = [id];
439
+ id._util.holdingIdType = declaration.type.replace("Declaration", "");
440
+ });
441
+ }
442
+ }
443
+ }
444
+ });
445
+ }
446
+ ;
447
+ holdingIds.forEach((holdingId) => {
448
+ const holdingIdName = holdingId.name;
449
+ if (typeof holdingIdName !== "string")
450
+ return;
451
+ const nodeSetOfIdName = holdingIdNameMap.get(holdingIdName) || /* @__PURE__ */ new Set();
452
+ nodeSetOfIdName.add(holdingId);
453
+ holdingIdNameMap.set(holdingIdName, nodeSetOfIdName);
454
+ });
455
+ }
456
+ static deepFirstTravel(node, filePath, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback) {
457
+ const visitedNodeSet = /* @__PURE__ */ new Set();
458
+ if (!node) {
459
+ return;
460
+ }
461
+ return this._deepFirstTravel(node, visitedNodeSet, { filePath, depth: 0, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback });
462
+ }
463
+ static _deepFirstTravel(node, visitedNodeSet, extra) {
464
+ visitedNodeSet.add(node);
465
+ const { filePath, depth, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback } = extra;
466
+ const _util = {
467
+ startLine: NaN,
468
+ endLine: NaN,
469
+ startColumn: NaN,
470
+ endColumn: NaN,
471
+ filePath,
472
+ parent: null,
473
+ parentProperty: "",
474
+ indexOfProperty: null,
475
+ ancestors: [],
476
+ nodeCollection: [],
477
+ children: [],
478
+ uuid: "",
479
+ variableScope: [],
480
+ dependenceIds: /* @__PURE__ */ new Set(),
481
+ dependenceIdsNoScope: /* @__PURE__ */ new Set(),
482
+ holdingIdType: null,
483
+ holdingIds: /* @__PURE__ */ new Set(),
484
+ holdingIdNameMap: /* @__PURE__ */ new Map(),
485
+ inject: /* @__PURE__ */ new Set(),
486
+ provide: /* @__PURE__ */ new Set(),
487
+ effectIds: /* @__PURE__ */ new Set(),
488
+ occupation: /* @__PURE__ */ new Set(),
489
+ importedMember: [],
490
+ exportedMember: []
491
+ };
492
+ node._util = _util;
493
+ const { nodeCollection, children } = _util;
494
+ const stopTravel = stopTravelCallback == null ? void 0 : stopTravelCallback(node);
495
+ if (stopTravel) {
496
+ return node;
497
+ }
498
+ Object.keys(node).forEach((nodeKey) => {
499
+ if (this.invalidNodeKey.includes(nodeKey)) {
500
+ return;
501
+ }
502
+ const nodeValue = node[nodeKey];
503
+ if (visitedNodeSet.has(nodeValue) || !nodeValue) {
504
+ return;
505
+ }
506
+ if (this.isValidNodeCollect(nodeValue)) {
507
+ const childNode = this._deepFirstTravel(nodeValue, visitedNodeSet, { filePath, depth: depth + 1, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback });
508
+ nodeCollection.push(childNode, ...childNode._util.nodeCollection);
509
+ children.push(childNode);
510
+ childNode._util.parentProperty = nodeKey;
511
+ } else if (this.isValidArrayNodeCollect(nodeValue)) {
512
+ const validNodeArray = nodeValue.filter((nodeItem) => this.isValidNodeCollect(nodeItem)).map((v) => {
513
+ return this._deepFirstTravel(v, visitedNodeSet, { filePath, depth: depth + 1, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback });
514
+ });
515
+ nodeCollection.push(...validNodeArray.map((n) => [n, ...n._util.nodeCollection]).flat());
516
+ children.push(...validNodeArray);
517
+ validNodeArray.forEach((v, index) => {
518
+ v._util.parentProperty = nodeKey;
519
+ v._util.indexOfProperty = index;
520
+ });
521
+ }
522
+ });
523
+ try {
524
+ children.forEach((child) => child._util.parent = node);
525
+ nodeCollection.forEach((nodeItem) => {
526
+ !nodeItem._util.ancestors.includes(node) && nodeItem._util.ancestors.unshift(node);
527
+ });
528
+ } catch (e) {
529
+ console.error("parent ancestors update", e.message);
530
+ }
531
+ try {
532
+ const skip = nodeCollection.some((nodeItem) => stopTravelCallback == null ? void 0 : stopTravelCallback(nodeItem));
533
+ if (!skip) {
534
+ this.collectHoldingIds(node);
535
+ }
536
+ } catch (e) {
537
+ console.error("收集持有的 identifier 出错", e.message);
538
+ }
539
+ try {
540
+ this.collectDependenceIds(node);
541
+ } catch (e) {
542
+ console.error("收集使用的标识符号", e.message);
543
+ }
544
+ if (node.type === "Program") {
545
+ try {
546
+ nodeCollection.forEach((child) => this.collectEffectId(child));
547
+ } catch (e) {
548
+ console.error("collectEffectId", e.message);
549
+ }
550
+ try {
551
+ node.body.forEach((child) => this.updateImportedAndExportedMember(child, node));
552
+ } catch (e) {
553
+ console.error("收集导入、导出成员信息报错", e.message);
554
+ }
555
+ }
556
+ try {
557
+ this.updateLoc(node, { mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet });
558
+ } catch (e) {
559
+ console.error("updateLoc", e.message);
560
+ }
561
+ return node;
562
+ }
563
+ };
564
+ var AstUtil = _AstUtil;
565
+ AstUtil.invalidNodeKey = import_SHARED_CONSTANTS.INVALID_NODE_KEY;
566
+ AstUtil.EXPORT_DECLARATION_TYPES = import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES;
567
+ AstUtil.windowProperties = import_windowProperties.windowProperties;
568
+ AstUtil.intrinsicElements = import_intrinsicElements.intrinsicElements;
569
+ AstUtil.standardAttributes = import_intrinsicElements.standardAttributes;
570
+ AstUtil.FUNCTION_TYPES = import_SHARED_CONSTANTS.FUNCTION_TYPES;
571
+ // Annotate the CommonJS export names for ESM import in node:
572
+ 0 && (module.exports = {
573
+ AstUtil
574
+ });
@@ -28,7 +28,7 @@ export interface AstNode {
28
28
  dependenceIdsNoScope: Set<AstNode>;
29
29
  holdingIds: Set<AstNode>;
30
30
  holdingIdNameMap: Map<string, Set<AstNode>>;
31
- holdingIdType: 'Import' | 'Variable' | 'Function' | 'Class' | 'Param' | null;
31
+ holdingIdType: 'Import' | 'Variable' | 'Function' | 'Class' | 'Param' | 'Enum' | 'Interface' | 'TypeAlias' | null;
32
32
  inject: Set<AstNode>;
33
33
  provide: Set<AstNode>;
34
34
  effectIds: Set<AstNode>;
@@ -52,7 +52,12 @@ export interface AstNode {
52
52
  }
53
53
  export default class AstUtil {
54
54
  static invalidNodeKey: string[];
55
- static EXPORT_DECLARATION_TYPES: string[];
55
+ static EXPORT_DECLARATION_TYPES: readonly ["FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration", "ClassDeclaration"];
56
+ static windowProperties: string[];
57
+ static intrinsicElements: string[];
58
+ static standardAttributes: string[];
59
+ private static isValidNodeCollect;
60
+ private static isValidArrayNodeCollect;
56
61
  static getNodePath(node: AstNode): string;
57
62
  static getShortNodeMsg(node: AstNode, hideParentProperty?: boolean): string;
58
63
  static getAncestorsFromBirth(occupationId: AstNode, sourceId: AstNode): AstNode[];
@@ -88,11 +93,6 @@ export default class AstUtil {
88
93
  private static findIdOfVariable;
89
94
  private static _deepFindIdentifier;
90
95
  private static updateLoc;
91
- private static isValidArrayNodeCollect;
92
- private static isValidNodeCollect;
93
- static windowProperties: string[];
94
- static intrinsicElements: string[];
95
- static standardAttributes: string[];
96
96
  static isUntrackedId(id: AstNode): boolean;
97
97
  static isPropertyOfGlobal(node: AstNode): boolean;
98
98
  static isIntrinsicElement(node: AstNode): boolean | "" | undefined;
@@ -24,7 +24,14 @@ __export(AstUtil_exports, {
24
24
  module.exports = __toCommonJS(AstUtil_exports);
25
25
  var import_windowProperties = require("./windowProperties");
26
26
  var import_intrinsicElements = require("./intrinsicElements");
27
+ var import_SHARED_CONSTANTS = require("./SHARED_CONSTANTS");
27
28
  var _AstUtil = class {
29
+ static isValidNodeCollect(astNode) {
30
+ return typeof (astNode == null ? void 0 : astNode.type) === "string";
31
+ }
32
+ static isValidArrayNodeCollect(astNode) {
33
+ return Array.isArray(astNode) && astNode.some((v) => typeof (v == null ? void 0 : v.type) === "string");
34
+ }
28
35
  static getNodePath(node) {
29
36
  return [...node._util.ancestors, node].map((n) => n.type).join(":") + ":" + node.name;
30
37
  }
@@ -149,7 +156,9 @@ var _AstUtil = class {
149
156
  });
150
157
  try {
151
158
  children.forEach((child) => child._util.parent = node);
152
- nodeCollection.forEach((nodeItem) => nodeItem._util.ancestors.unshift(node));
159
+ nodeCollection.forEach((nodeItem) => {
160
+ !nodeItem._util.ancestors.includes(node) && nodeItem._util.ancestors.unshift(node);
161
+ });
153
162
  } catch (e) {
154
163
  console.error("parent ancestors update", e.message);
155
164
  }
@@ -180,7 +189,7 @@ var _AstUtil = class {
180
189
  try {
181
190
  node.body.forEach((child) => this.updateImportedAndExportedMember(child, node));
182
191
  } catch (e) {
183
- console.error("updateImportedAndExportedMember", e.message);
192
+ console.error("收集导入、导出成员 报错", e.message);
184
193
  }
185
194
  }
186
195
  try {
@@ -217,6 +226,10 @@ var _AstUtil = class {
217
226
  const nameList = /* @__PURE__ */ new Set();
218
227
  outer:
219
228
  for (const ancestor of nodeArray) {
229
+ if (ancestor.type === "VElement") {
230
+ nameList.add("default");
231
+ break outer;
232
+ }
220
233
  if (ancestor.type === "ExportDefaultDeclaration") {
221
234
  const { declaration } = ancestor;
222
235
  if (declaration) {
@@ -877,7 +890,7 @@ var _AstUtil = class {
877
890
  var _a2, _b2;
878
891
  return (_b2 = (_a2 = n.loc) == null ? void 0 : _a2.end) == null ? void 0 : _b2.column;
879
892
  }), (_f = astNode.loc) == null ? void 0 : _f.end.column);
880
- _util.uuid = `${filePath}:${type}:${name}「${_util.startLine}:${_util.startColumn},${_util.endLine}:${_util.endColumn}」`;
893
+ _util.uuid = `${filePath}@${type}:${name}「${_util.startLine}:${_util.startColumn},${_util.endLine}:${_util.endColumn}」`;
881
894
  mapUuidToNode.set(_util.uuid, astNode);
882
895
  for (let i = _util.startLine; i <= _util.endLine; i++) {
883
896
  mapFileLineToNodeSet.set(i, mapFileLineToNodeSet.get(i) || /* @__PURE__ */ new Set());
@@ -895,12 +908,6 @@ var _AstUtil = class {
895
908
  });
896
909
  }
897
910
  }
898
- static isValidArrayNodeCollect(astNode) {
899
- return Array.isArray(astNode) && astNode.some((v) => typeof (v == null ? void 0 : v.type) === "string");
900
- }
901
- static isValidNodeCollect(astNode) {
902
- return typeof (astNode == null ? void 0 : astNode.type) === "string";
903
- }
904
911
  static isUntrackedId(id) {
905
912
  return id._util.variableScope.length === 0 && !this.isPropertyOfGlobal(id) && !this.isIntrinsicElement(id) && !this.isStandardAttribute(id);
906
913
  }
@@ -943,11 +950,8 @@ var _AstUtil = class {
943
950
  }
944
951
  };
945
952
  var AstUtil = _AstUtil;
946
- AstUtil.invalidNodeKey = [
947
- "comments",
948
- "tokens"
949
- ];
950
- AstUtil.EXPORT_DECLARATION_TYPES = ["FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration", "ClassDeclaration"];
953
+ AstUtil.invalidNodeKey = import_SHARED_CONSTANTS.INVALID_NODE_KEY;
954
+ AstUtil.EXPORT_DECLARATION_TYPES = import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES;
951
955
  AstUtil.windowProperties = import_windowProperties.windowProperties;
952
956
  AstUtil.intrinsicElements = import_intrinsicElements.intrinsicElements;
953
957
  AstUtil.standardAttributes = import_intrinsicElements.standardAttributes;
@@ -0,0 +1,3 @@
1
+ export declare const INVALID_NODE_KEY: string[];
2
+ export declare const EXPORT_DECLARATION_TYPES: readonly ["FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration", "ClassDeclaration"];
3
+ export declare const FUNCTION_TYPES: string[];