js-code-detector 0.0.51 → 0.0.53

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 (79) hide show
  1. package/dist/cjs/services/DetectService.js +7 -1
  2. package/dist/cjs/services/projectServiceClass/UmiProjectService.js +5 -0
  3. package/dist/cjs/services/projectServiceClass/ViteProjectService.d.ts +23 -0
  4. package/dist/cjs/services/projectServiceClass/ViteProjectService.js +142 -0
  5. package/dist/cjs/services/projectServiceClass/VueProjectService.d.ts +3 -0
  6. package/dist/cjs/services/projectServiceClass/VueProjectService.js +32 -6
  7. package/dist/cjs/util/ast_util/AstKit.d.ts +5 -21
  8. package/dist/cjs/util/ast_util/AstKit.js +33 -524
  9. package/dist/cjs/util/ast_util/AstUtil.d.ts +2 -1
  10. package/dist/cjs/util/ast_util/AstUtil.js +14 -9
  11. package/dist/cjs/util/ast_util/getAstKitByFilePath.d.ts +1 -1
  12. package/dist/cjs/util/ast_util/getAstKitByFilePath.js +1 -1
  13. package/dist/cjs/util/ast_util/helper/collectDeclarationIdentifiers.d.ts +2 -0
  14. package/dist/cjs/util/ast_util/helper/collectDeclarationIdentifiers.js +31 -0
  15. package/dist/cjs/util/ast_util/helper/collectDependenceIds.d.ts +2 -0
  16. package/dist/cjs/util/ast_util/helper/collectDependenceIds.js +90 -0
  17. package/dist/cjs/util/ast_util/helper/collectDependenceIdsOfExportMembers.d.ts +2 -0
  18. package/dist/cjs/util/ast_util/helper/collectDependenceIdsOfExportMembers.js +44 -0
  19. package/dist/cjs/util/ast_util/helper/collectEffectId.d.ts +2 -0
  20. package/dist/cjs/util/ast_util/helper/collectEffectId.js +26 -0
  21. package/dist/cjs/util/ast_util/helper/collectExpressionIdentifiersShallow.d.ts +2 -0
  22. package/dist/cjs/util/ast_util/helper/collectExpressionIdentifiersShallow.js +39 -0
  23. package/dist/cjs/util/ast_util/helper/collectHoldingIds.d.ts +4 -0
  24. package/dist/cjs/util/ast_util/helper/collectHoldingIds.js +110 -0
  25. package/dist/cjs/util/ast_util/helper/collectImportDeclarationIdentifiers.d.ts +2 -0
  26. package/dist/cjs/util/ast_util/helper/collectImportDeclarationIdentifiers.js +38 -0
  27. package/dist/cjs/util/ast_util/helper/collectVariableDeclarationIdentifiers.d.ts +2 -0
  28. package/dist/cjs/util/ast_util/helper/collectVariableDeclarationIdentifiers.js +43 -0
  29. package/dist/cjs/util/ast_util/helper/createAstNodeExt.d.ts +40 -0
  30. package/dist/cjs/util/ast_util/helper/createAstNodeExt.js +54 -0
  31. package/dist/cjs/util/ast_util/helper/deepFirstTravel.d.ts +9 -0
  32. package/dist/cjs/util/ast_util/helper/deepFirstTravel.js +142 -0
  33. package/dist/cjs/util/ast_util/helper/deepSearchParamsIdentifier.d.ts +2 -0
  34. package/dist/cjs/util/ast_util/helper/deepSearchParamsIdentifier.js +55 -0
  35. package/dist/cjs/util/ast_util/helper/findOrCreateExportedMember.d.ts +9 -0
  36. package/dist/cjs/util/ast_util/helper/findOrCreateExportedMember.js +32 -0
  37. package/dist/cjs/util/ast_util/helper/findOrCreateImportedMember.d.ts +8 -0
  38. package/dist/cjs/util/ast_util/helper/findOrCreateImportedMember.js +32 -0
  39. package/dist/cjs/util/ast_util/helper/getExportedNameOfAncestor.d.ts +2 -0
  40. package/dist/cjs/util/ast_util/helper/getExportedNameOfAncestor.js +113 -0
  41. package/dist/cjs/util/ast_util/helper/getExportedNameOfDeclarationIdentifier.d.ts +2 -0
  42. package/dist/cjs/util/ast_util/helper/getExportedNameOfDeclarationIdentifier.js +40 -0
  43. package/dist/cjs/util/ast_util/helper/getImpactedNode.d.ts +2 -0
  44. package/dist/cjs/util/ast_util/helper/getImpactedNode.js +50 -0
  45. package/dist/cjs/util/ast_util/helper/getNearestImpactedNode.d.ts +2 -0
  46. package/dist/cjs/util/ast_util/helper/getNearestImpactedNode.js +43 -0
  47. package/dist/cjs/util/ast_util/helper/getNodePath.d.ts +2 -0
  48. package/dist/cjs/util/ast_util/helper/getNodePath.js +27 -0
  49. package/dist/cjs/util/ast_util/helper/getShortNodeMsg.d.ts +2 -0
  50. package/dist/cjs/util/ast_util/helper/getShortNodeMsg.js +38 -0
  51. package/dist/cjs/util/ast_util/helper/getTopScopeNodesByLineNumberRange.d.ts +2 -0
  52. package/dist/cjs/util/ast_util/helper/getTopScopeNodesByLineNumberRange.js +51 -0
  53. package/dist/cjs/util/ast_util/helper/isIdentifierUntracked.d.ts +2 -0
  54. package/dist/cjs/util/ast_util/helper/isIdentifierUntracked.js +39 -0
  55. package/dist/cjs/util/ast_util/helper/isValidArrayNodeCollect.d.ts +2 -0
  56. package/dist/cjs/util/ast_util/helper/isValidArrayNodeCollect.js +27 -0
  57. package/dist/cjs/util/ast_util/helper/isValidNodeCollect.d.ts +2 -0
  58. package/dist/cjs/util/ast_util/helper/isValidNodeCollect.js +27 -0
  59. package/dist/cjs/util/ast_util/helper/syncTravel.d.ts +11 -0
  60. package/dist/cjs/util/ast_util/helper/syncTravel.js +325 -0
  61. package/dist/cjs/util/ast_util/helper/updateImportedAndExportedMember.d.ts +2 -0
  62. package/dist/cjs/util/ast_util/helper/updateImportedAndExportedMember.js +135 -0
  63. package/dist/cjs/util/ast_util/helper/updateLoc.d.ts +6 -0
  64. package/dist/cjs/util/ast_util/helper/updateLoc.js +74 -0
  65. package/dist/cjs/util/project_umi_util/isVueEntryFile.d.ts +1 -0
  66. package/dist/cjs/util/project_umi_util/isVueEntryFile.js +57 -0
  67. package/dist/cjs/util/project_umi_util/tsConfigPathsToWebpackAlias.d.ts +10 -0
  68. package/dist/cjs/util/project_umi_util/tsConfigPathsToWebpackAlias.js +80 -0
  69. package/dist/cjs/util/report_util/filterEffectedCode.d.ts +1 -1
  70. package/dist/cjs/util/report_util/filterEffectedExportMember.d.ts +2 -0
  71. package/dist/cjs/util/report_util/filterEffectedExportMember.js +10 -2
  72. package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +1 -1
  73. package/dist/cjs/util/report_util/resolveImportPath.js +1 -1
  74. package/dist/cjs/util/report_util.d.ts +1 -1
  75. package/dist/cjs/util/shared/getMajorVersion.d.ts +1 -0
  76. package/dist/cjs/util/shared/getMajorVersion.js +37 -0
  77. package/dist/cjs/util/shared/getRepoSupportFlag.d.ts +1 -1
  78. package/dist/cjs/util/shared/getRepoSupportFlag.js +8 -3
  79. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/util/ast_util/AstKit.ts
@@ -25,549 +35,48 @@ module.exports = __toCommonJS(AstKit_exports);
25
35
  var import_intrinsicElements = require("./intrinsicElements");
26
36
  var import_SHARED_CONSTANTS = require("./SHARED_CONSTANTS");
27
37
  var import_windowProperties = require("./windowProperties");
28
- var _AstUtil = class {
38
+ var import_isIdentifierUntracked = __toESM(require("./helper/isIdentifierUntracked"));
39
+ var import_getExportedNameOfAncestor = __toESM(require("./helper/getExportedNameOfAncestor"));
40
+ var import_getTopScopeNodesByLineNumberRange = __toESM(require("./helper/getTopScopeNodesByLineNumberRange"));
41
+ var import_getShortNodeMsg = __toESM(require("./helper/getShortNodeMsg"));
42
+ var import_getNearestImpactedNode = __toESM(require("./helper/getNearestImpactedNode"));
43
+ var import_getNodePath = __toESM(require("./helper/getNodePath"));
44
+ var import_syncTravel = __toESM(require("./helper/syncTravel"));
45
+ var AstUtil = class {
46
+ static isUntrackedId(id) {
47
+ return (0, import_isIdentifierUntracked.default)(id);
48
+ }
29
49
  static getNodePath(node) {
30
- return [...node._util.ancestors, node].map((n) => n.type).join(":") + ":" + node.name;
50
+ return (0, import_getNodePath.default)(node);
31
51
  }
32
52
  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
- }
53
+ return (0, import_getShortNodeMsg.default)(node, hideParentProperty);
193
54
  }
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
- }
55
+ static findExportedMembersNameFromAncestors(node) {
56
+ return (0, import_getExportedNameOfAncestor.default)(node);
224
57
  }
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
- }
58
+ static getAncestorsFromBirth(occupationId, sourceId) {
59
+ const { _util: { ancestors } } = occupationId;
60
+ return ancestors.filter((ancestor) => !sourceId._util.ancestors.includes(ancestor));
244
61
  }
245
- static collectExpressionIdentifiersShallow(exp, callback) {
246
- if (!exp || exp.type === "ThisExpression") {
247
- return;
248
- }
249
- this._collectExpressionIdentifiersShallow(exp, callback);
62
+ static getNearestImpactedNode(ancestors) {
63
+ return (0, import_getNearestImpactedNode.default)(ancestors);
250
64
  }
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
- });
65
+ static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStart, lineNumberEnd, loose = false) {
66
+ return (0, import_getTopScopeNodesByLineNumberRange.default)(mapFileLineToNodeSet, lineNumberStart, lineNumberEnd, loose);
455
67
  }
456
68
  static deepFirstTravel(node, filePath, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback) {
457
69
  const visitedNodeSet = /* @__PURE__ */ new Set();
458
70
  if (!node) {
459
71
  return;
460
72
  }
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
- }
73
+ (0, import_syncTravel.default)(node, { filePath, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, visitedNodeSet, upstreamIdentifiers: [] }, () => {
522
74
  });
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
75
  }
563
76
  };
564
- var AstUtil = _AstUtil;
565
- AstUtil.invalidNodeKey = import_SHARED_CONSTANTS.INVALID_NODE_KEY;
566
77
  AstUtil.EXPORT_DECLARATION_TYPES = import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES;
567
78
  AstUtil.windowProperties = import_windowProperties.windowProperties;
568
79
  AstUtil.intrinsicElements = import_intrinsicElements.intrinsicElements;
569
- AstUtil.standardAttributes = import_intrinsicElements.standardAttributes;
570
- AstUtil.FUNCTION_TYPES = import_SHARED_CONSTANTS.FUNCTION_TYPES;
571
80
  // Annotate the CommonJS export names for ESM import in node:
572
81
  0 && (module.exports = {
573
82
  AstUtil
@@ -50,7 +50,8 @@ export interface AstNode {
50
50
  }[];
51
51
  };
52
52
  }
53
- export default class AstUtil {
53
+ export { AstUtil as default } from "./AstKit";
54
+ export declare class AstUtil {
54
55
  static invalidNodeKey: string[];
55
56
  static EXPORT_DECLARATION_TYPES: readonly ["FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration", "ClassDeclaration"];
56
57
  static windowProperties: string[];
@@ -19,13 +19,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/util/ast_util/AstUtil.ts
20
20
  var AstUtil_exports = {};
21
21
  __export(AstUtil_exports, {
22
- default: () => AstUtil
22
+ AstUtil: () => AstUtil2,
23
+ default: () => import_AstKit.AstUtil
23
24
  });
24
25
  module.exports = __toCommonJS(AstUtil_exports);
25
26
  var import_windowProperties = require("./windowProperties");
26
27
  var import_intrinsicElements = require("./intrinsicElements");
27
28
  var import_SHARED_CONSTANTS = require("./SHARED_CONSTANTS");
28
- var _AstUtil = class {
29
+ var import_AstKit = require("./AstKit");
30
+ var AstUtil2 = class {
29
31
  static isValidNodeCollect(astNode) {
30
32
  return typeof (astNode == null ? void 0 : astNode.type) === "string";
31
33
  }
@@ -902,7 +904,7 @@ var _AstUtil = class {
902
904
  if (parent === null) {
903
905
  nodeCollection.forEach((n) => {
904
906
  var _a2;
905
- const path = _AstUtil.getNodePath(n);
907
+ const path = this.getNodePath(n);
906
908
  mapPathToNodeSet.set(path, mapPathToNodeSet.get(path) || /* @__PURE__ */ new Set());
907
909
  (_a2 = mapPathToNodeSet.get(path)) == null ? void 0 : _a2.add(n);
908
910
  });
@@ -949,9 +951,12 @@ var _AstUtil = class {
949
951
  return [...nodeSet].filter((e) => !collections.includes(e));
950
952
  }
951
953
  };
952
- var AstUtil = _AstUtil;
953
- AstUtil.invalidNodeKey = import_SHARED_CONSTANTS.INVALID_NODE_KEY;
954
- AstUtil.EXPORT_DECLARATION_TYPES = import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES;
955
- AstUtil.windowProperties = import_windowProperties.windowProperties;
956
- AstUtil.intrinsicElements = import_intrinsicElements.intrinsicElements;
957
- AstUtil.standardAttributes = import_intrinsicElements.standardAttributes;
954
+ AstUtil2.invalidNodeKey = import_SHARED_CONSTANTS.INVALID_NODE_KEY;
955
+ AstUtil2.EXPORT_DECLARATION_TYPES = import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES;
956
+ AstUtil2.windowProperties = import_windowProperties.windowProperties;
957
+ AstUtil2.intrinsicElements = import_intrinsicElements.intrinsicElements;
958
+ AstUtil2.standardAttributes = import_intrinsicElements.standardAttributes;
959
+ // Annotate the CommonJS export names for ESM import in node:
960
+ 0 && (module.exports = {
961
+ AstUtil
962
+ });
@@ -1,5 +1,5 @@
1
1
  import AstUtil, { AstNode } from "./AstUtil";
2
- export default function getAstKitByFilePath(filePath: string, absPathPrefix: string, stopTravelCallback?: Parameters<typeof AstUtil.deepFirstTravel>[5]): {
2
+ export default function getAstKitByFilePath(filePath: string, absPathPrefix?: string, stopTravelCallback?: Parameters<typeof AstUtil.deepFirstTravel>[5]): {
3
3
  mapFileLineToNodeSet: Map<number, Set<AstNode>>;
4
4
  mapUuidToNode: Map<string, AstNode>;
5
5
  mapPathToNodeSet: Map<string, Set<AstNode>>;
@@ -44,7 +44,7 @@ var createMapFileLineToNodeSet = (file, absPathPrefix, stopTravelCallback) => {
44
44
  import_AstUtil.default.deepFirstTravel(ast, filePathRelative, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback);
45
45
  return { mapFileLineToNodeSet, mapUuidToNode, mapPathToNodeSet };
46
46
  };
47
- function getAstKitByFilePath(filePath, absPathPrefix, stopTravelCallback) {
47
+ function getAstKitByFilePath(filePath, absPathPrefix = "", stopTravelCallback) {
48
48
  if (stopTravelCallback) {
49
49
  return createMapFileLineToNodeSet(filePath, absPathPrefix, stopTravelCallback);
50
50
  }
@@ -0,0 +1,2 @@
1
+ import { AstNode } from "../AstUtil";
2
+ export default function collectDeclarationIdentifiers(node: AstNode, callback: (identifier: AstNode) => void): void;