js-code-detector 0.0.52 → 0.0.54

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 (78) hide show
  1. package/dist/cjs/index.d.ts +1 -1
  2. package/dist/cjs/services/DetectService.js +7 -1
  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.js +1 -1
  6. package/dist/cjs/util/ast_util/AstKit.d.ts +5 -21
  7. package/dist/cjs/util/ast_util/AstKit.js +33 -524
  8. package/dist/cjs/util/ast_util/AstUtil.d.ts +2 -1
  9. package/dist/cjs/util/ast_util/AstUtil.js +14 -9
  10. package/dist/cjs/util/ast_util/getAstKitByFilePath.d.ts +1 -1
  11. package/dist/cjs/util/ast_util/getAstKitByFilePath.js +1 -1
  12. package/dist/cjs/util/ast_util/helper/collectDeclarationIdentifiers.d.ts +2 -0
  13. package/dist/cjs/util/ast_util/helper/collectDeclarationIdentifiers.js +31 -0
  14. package/dist/cjs/util/ast_util/helper/collectDependenceIds.d.ts +2 -0
  15. package/dist/cjs/util/ast_util/helper/collectDependenceIds.js +90 -0
  16. package/dist/cjs/util/ast_util/helper/collectDependenceIdsOfExportMembers.d.ts +2 -0
  17. package/dist/cjs/util/ast_util/helper/collectDependenceIdsOfExportMembers.js +44 -0
  18. package/dist/cjs/util/ast_util/helper/collectEffectId.d.ts +2 -0
  19. package/dist/cjs/util/ast_util/helper/collectEffectId.js +26 -0
  20. package/dist/cjs/util/ast_util/helper/collectExpressionIdentifiersShallow.d.ts +2 -0
  21. package/dist/cjs/util/ast_util/helper/collectExpressionIdentifiersShallow.js +39 -0
  22. package/dist/cjs/util/ast_util/helper/collectHoldingIds.d.ts +4 -0
  23. package/dist/cjs/util/ast_util/helper/collectHoldingIds.js +110 -0
  24. package/dist/cjs/util/ast_util/helper/collectImportDeclarationIdentifiers.d.ts +2 -0
  25. package/dist/cjs/util/ast_util/helper/collectImportDeclarationIdentifiers.js +38 -0
  26. package/dist/cjs/util/ast_util/helper/collectVariableDeclarationIdentifiers.d.ts +2 -0
  27. package/dist/cjs/util/ast_util/helper/collectVariableDeclarationIdentifiers.js +43 -0
  28. package/dist/cjs/util/ast_util/helper/createAstNodeExt.d.ts +40 -0
  29. package/dist/cjs/util/ast_util/helper/createAstNodeExt.js +54 -0
  30. package/dist/cjs/util/ast_util/helper/deepFirstTravel.d.ts +9 -0
  31. package/dist/cjs/util/ast_util/helper/deepFirstTravel.js +142 -0
  32. package/dist/cjs/util/ast_util/helper/deepSearchParamsIdentifier.d.ts +2 -0
  33. package/dist/cjs/util/ast_util/helper/deepSearchParamsIdentifier.js +55 -0
  34. package/dist/cjs/util/ast_util/helper/findOrCreateExportedMember.d.ts +9 -0
  35. package/dist/cjs/util/ast_util/helper/findOrCreateExportedMember.js +32 -0
  36. package/dist/cjs/util/ast_util/helper/findOrCreateImportedMember.d.ts +8 -0
  37. package/dist/cjs/util/ast_util/helper/findOrCreateImportedMember.js +32 -0
  38. package/dist/cjs/util/ast_util/helper/getExportedNameOfAncestor.d.ts +2 -0
  39. package/dist/cjs/util/ast_util/helper/getExportedNameOfAncestor.js +113 -0
  40. package/dist/cjs/util/ast_util/helper/getExportedNameOfDeclarationIdentifier.d.ts +2 -0
  41. package/dist/cjs/util/ast_util/helper/getExportedNameOfDeclarationIdentifier.js +40 -0
  42. package/dist/cjs/util/ast_util/helper/getImpactedNode.d.ts +2 -0
  43. package/dist/cjs/util/ast_util/helper/getImpactedNode.js +50 -0
  44. package/dist/cjs/util/ast_util/helper/getNearestImpactedNode.d.ts +2 -0
  45. package/dist/cjs/util/ast_util/helper/getNearestImpactedNode.js +43 -0
  46. package/dist/cjs/util/ast_util/helper/getNodePath.d.ts +2 -0
  47. package/dist/cjs/util/ast_util/helper/getNodePath.js +27 -0
  48. package/dist/cjs/util/ast_util/helper/getShortNodeMsg.d.ts +2 -0
  49. package/dist/cjs/util/ast_util/helper/getShortNodeMsg.js +38 -0
  50. package/dist/cjs/util/ast_util/helper/getTopScopeNodesByLineNumberRange.d.ts +2 -0
  51. package/dist/cjs/util/ast_util/helper/getTopScopeNodesByLineNumberRange.js +51 -0
  52. package/dist/cjs/util/ast_util/helper/isIdentifierUntracked.d.ts +2 -0
  53. package/dist/cjs/util/ast_util/helper/isIdentifierUntracked.js +39 -0
  54. package/dist/cjs/util/ast_util/helper/isValidArrayNodeCollect.d.ts +2 -0
  55. package/dist/cjs/util/ast_util/helper/isValidArrayNodeCollect.js +27 -0
  56. package/dist/cjs/util/ast_util/helper/isValidNodeCollect.d.ts +2 -0
  57. package/dist/cjs/util/ast_util/helper/isValidNodeCollect.js +27 -0
  58. package/dist/cjs/util/ast_util/helper/syncTravel.d.ts +11 -0
  59. package/dist/cjs/util/ast_util/helper/syncTravel.js +325 -0
  60. package/dist/cjs/util/ast_util/helper/updateImportedAndExportedMember.d.ts +2 -0
  61. package/dist/cjs/util/ast_util/helper/updateImportedAndExportedMember.js +135 -0
  62. package/dist/cjs/util/ast_util/helper/updateLoc.d.ts +6 -0
  63. package/dist/cjs/util/ast_util/helper/updateLoc.js +74 -0
  64. package/dist/cjs/util/project_umi_util/isVueEntryFile.d.ts +1 -0
  65. package/dist/cjs/util/project_umi_util/isVueEntryFile.js +57 -0
  66. package/dist/cjs/util/project_umi_util/tsConfigPathsToWebpackAlias.d.ts +10 -0
  67. package/dist/cjs/util/project_umi_util/tsConfigPathsToWebpackAlias.js +80 -0
  68. package/dist/cjs/util/report_util/filterEffectedCode.d.ts +1 -1
  69. package/dist/cjs/util/report_util/filterEffectedExportMember.d.ts +2 -0
  70. package/dist/cjs/util/report_util/filterEffectedExportMember.js +9 -1
  71. package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +1 -1
  72. package/dist/cjs/util/report_util.d.ts +1 -1
  73. package/dist/cjs/util/shared/getMajorVersion.d.ts +1 -0
  74. package/dist/cjs/util/shared/getMajorVersion.js +37 -0
  75. package/dist/cjs/util/shared/getRepoSupportFlag.d.ts +1 -1
  76. package/dist/cjs/util/shared/getRepoSupportFlag.js +8 -3
  77. package/dist/cjs/util/shared/gitDiffTool.d.ts +1 -1
  78. package/package.json +1 -1
@@ -0,0 +1,51 @@
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/helper/getTopScopeNodesByLineNumberRange.ts
20
+ var getTopScopeNodesByLineNumberRange_exports = {};
21
+ __export(getTopScopeNodesByLineNumberRange_exports, {
22
+ default: () => getTopScopeNodesByLineNumberRange
23
+ });
24
+ module.exports = __toCommonJS(getTopScopeNodesByLineNumberRange_exports);
25
+ function getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStart, lineNumberEnd, loose = false) {
26
+ const nodeSet = /* @__PURE__ */ new Set();
27
+ for (let i = lineNumberStart; i <= lineNumberEnd; i++) {
28
+ const astNode = mapFileLineToNodeSet.get(i);
29
+ if (!astNode) {
30
+ continue;
31
+ }
32
+ let added = false;
33
+ for (const nodeItem of astNode) {
34
+ const { startLine, endLine } = nodeItem._util;
35
+ if (startLine >= lineNumberStart && endLine <= lineNumberEnd) {
36
+ if (!["File", "Program"].includes(nodeItem.type)) {
37
+ nodeSet.add(nodeItem);
38
+ }
39
+ added = true;
40
+ }
41
+ }
42
+ if (!added && loose) {
43
+ const firstNode = [...astNode][0];
44
+ if (!["File", "Program"].includes(firstNode.type)) {
45
+ nodeSet.add(firstNode);
46
+ }
47
+ }
48
+ }
49
+ const collections = [...nodeSet].map((e) => e._util.nodeCollection).flat();
50
+ return [...nodeSet].filter((e) => !collections.includes(e));
51
+ }
@@ -0,0 +1,2 @@
1
+ import { AstNode } from "../AstUtil";
2
+ export default function isIdentifierUntracked(id: AstNode): boolean;
@@ -0,0 +1,39 @@
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/helper/isIdentifierUntracked.ts
20
+ var isIdentifierUntracked_exports = {};
21
+ __export(isIdentifierUntracked_exports, {
22
+ default: () => isIdentifierUntracked
23
+ });
24
+ module.exports = __toCommonJS(isIdentifierUntracked_exports);
25
+ var import_windowProperties = require("../windowProperties");
26
+ var import_intrinsicElements = require("../intrinsicElements");
27
+ function isIdentifierUntracked(id) {
28
+ return id._util.variableScope.length === 0 && !isPropertyOfGlobal(id) && !isIntrinsicElement(id) && !isStandardAttribute(id);
29
+ }
30
+ function isPropertyOfGlobal(node) {
31
+ return node.type === "Identifier" && !node._util.variableScope.length && typeof node.name === "string" && import_windowProperties.windowProperties.includes(node.name);
32
+ }
33
+ function isIntrinsicElement(node) {
34
+ var _a;
35
+ return node.type === "JSXIdentifier" && ((_a = node._util.parent) == null ? void 0 : _a.type) && ["JSXOpeningElement", "JSXClosingElement"].includes(node._util.parent.type) && typeof node.name === "string" && import_intrinsicElements.intrinsicElements.includes(node.name);
36
+ }
37
+ function isStandardAttribute(node) {
38
+ return node._util.parent.type === "JSXAttribute" && typeof node.name === "string" && import_intrinsicElements.standardAttributes.includes(node.name);
39
+ }
@@ -0,0 +1,2 @@
1
+ import { AstNode } from "../AstUtil";
2
+ export default function isValidArrayNodeCollect(astNode: any): astNode is AstNode[];
@@ -0,0 +1,27 @@
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/helper/isValidArrayNodeCollect.ts
20
+ var isValidArrayNodeCollect_exports = {};
21
+ __export(isValidArrayNodeCollect_exports, {
22
+ default: () => isValidArrayNodeCollect
23
+ });
24
+ module.exports = __toCommonJS(isValidArrayNodeCollect_exports);
25
+ function isValidArrayNodeCollect(astNode) {
26
+ return Array.isArray(astNode) && astNode.some((v) => typeof (v == null ? void 0 : v.type) === "string");
27
+ }
@@ -0,0 +1,2 @@
1
+ import { AstNode } from "../AstUtil";
2
+ export default function isValidNodeCollect(astNode: AstNode): astNode is AstNode;
@@ -0,0 +1,27 @@
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/helper/isValidNodeCollect.ts
20
+ var isValidNodeCollect_exports = {};
21
+ __export(isValidNodeCollect_exports, {
22
+ default: () => isValidNodeCollect
23
+ });
24
+ module.exports = __toCommonJS(isValidNodeCollect_exports);
25
+ function isValidNodeCollect(astNode) {
26
+ return typeof (astNode == null ? void 0 : astNode.type) === "string";
27
+ }
@@ -0,0 +1,11 @@
1
+ import { AstNode } from "../AstUtil";
2
+ type Extra = {
3
+ visitedNodeSet: Set<AstNode>;
4
+ filePath: string;
5
+ mapUuidToNode: Map<string, AstNode>;
6
+ mapFileLineToNodeSet: Map<number, Set<AstNode>>;
7
+ mapPathToNodeSet: Map<string, Set<AstNode>>;
8
+ upstreamIdentifiers: AstNode[];
9
+ };
10
+ export default function syncTravel(astNode: AstNode, extra: Extra, travelFn: (astNode: AstNode) => void): void;
11
+ export {};
@@ -0,0 +1,325 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
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
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/util/ast_util/helper/syncTravel.ts
30
+ var syncTravel_exports = {};
31
+ __export(syncTravel_exports, {
32
+ default: () => syncTravel
33
+ });
34
+ module.exports = __toCommonJS(syncTravel_exports);
35
+ var import_SHARED_CONSTANTS = require("../SHARED_CONSTANTS");
36
+ var import_isValidNodeCollect = __toESM(require("./isValidNodeCollect"));
37
+ var import_isValidArrayNodeCollect = __toESM(require("./isValidArrayNodeCollect"));
38
+ var import_createAstNodeExt = __toESM(require("./createAstNodeExt"));
39
+ var import_deepSearchParamsIdentifier = __toESM(require("./deepSearchParamsIdentifier"));
40
+ var import_updateImportedAndExportedMember = __toESM(require("./updateImportedAndExportedMember"));
41
+ var import_updateLoc = __toESM(require("./updateLoc"));
42
+ var import_intrinsicElements = require("../intrinsicElements");
43
+ function syncTravel(astNode, extra, travelFn) {
44
+ if (!astNode)
45
+ return;
46
+ extra.upstreamIdentifiers = extra.upstreamIdentifiers || [];
47
+ const { visitedNodeSet, filePath } = extra;
48
+ astNode._util = (0, import_createAstNodeExt.default)({ filePath });
49
+ visitedNodeSet.add(astNode);
50
+ if (shouldWideTravel(astNode)) {
51
+ wideTravel([astNode], extra, travelFn);
52
+ } else {
53
+ deepTravel(astNode, extra, travelFn);
54
+ }
55
+ }
56
+ function wideTravel(wideTravelNodeList, extra, travelFn) {
57
+ const { visitedNodeSet, filePath } = extra;
58
+ const wideTravelNodes = [];
59
+ for (const wideTravelNode of wideTravelNodeList) {
60
+ if (!shouldWideTravel(wideTravelNode)) {
61
+ deepTravel(wideTravelNode, extra, travelFn);
62
+ continue;
63
+ }
64
+ const { children: childrenOfChild } = wideTravelNode._util;
65
+ Object.keys(wideTravelNode).forEach((childKey) => {
66
+ if (import_SHARED_CONSTANTS.INVALID_NODE_KEY.includes(childKey))
67
+ return;
68
+ const childValue = wideTravelNode[childKey];
69
+ if ((0, import_isValidNodeCollect.default)(childValue) && !visitedNodeSet.has(childValue)) {
70
+ visitedNodeSet.add(childValue);
71
+ childValue._util = (0, import_createAstNodeExt.default)({
72
+ filePath,
73
+ parent: wideTravelNode,
74
+ parentProperty: childKey,
75
+ indexOfProperty: null,
76
+ ancestors: [...wideTravelNode._util.ancestors, wideTravelNode]
77
+ });
78
+ childrenOfChild.push(childValue);
79
+ wideTravelNodes.push(childValue);
80
+ } else if ((0, import_isValidArrayNodeCollect.default)(childValue)) {
81
+ childValue.forEach((childInArray, index) => {
82
+ if (visitedNodeSet.has(childInArray) || !(0, import_isValidNodeCollect.default)(childInArray))
83
+ return;
84
+ visitedNodeSet.add(childInArray);
85
+ childInArray._util = (0, import_createAstNodeExt.default)({
86
+ filePath,
87
+ parent: wideTravelNode,
88
+ parentProperty: childKey,
89
+ indexOfProperty: index,
90
+ ancestors: [...wideTravelNode._util.ancestors, wideTravelNode]
91
+ });
92
+ childrenOfChild.push(childInArray);
93
+ wideTravelNodes.push(childInArray);
94
+ });
95
+ }
96
+ });
97
+ }
98
+ const { hoistedNodeList, exportDeclarations, notHoistedNodes } = resortNodes(wideTravelNodes);
99
+ const holdingIdentifiers = [...extra.upstreamIdentifiers];
100
+ for (const ele of [...hoistedNodeList, ...exportDeclarations]) {
101
+ collectHoldingIdentifiers(ele, holdingIdentifiers, exportDeclarations);
102
+ }
103
+ for (const ele of wideTravelNodes) {
104
+ if (notHoistedNodes.includes(ele)) {
105
+ collectHoldingIdentifiers(ele, holdingIdentifiers, exportDeclarations);
106
+ }
107
+ const mergedExtra = { ...extra, upstreamIdentifiers: [...holdingIdentifiers] };
108
+ const holdingIdentifierSet = new Set(holdingIdentifiers);
109
+ ele._util.holdingIds = holdingIdentifierSet;
110
+ if (shouldWideTravel(ele)) {
111
+ wideTravel([ele], mergedExtra, travelFn);
112
+ } else {
113
+ deepTravel(ele, mergedExtra, travelFn);
114
+ }
115
+ if (!ele._util.uuid) {
116
+ (0, import_updateLoc.default)(ele, extra);
117
+ }
118
+ if (ele.type === "Program") {
119
+ console.log("需要处理兜底 Programs");
120
+ }
121
+ addIdentifiersToAncestors([ele], ele._util.ancestors);
122
+ }
123
+ }
124
+ function deepTravel(deepTravelNode, extra, travelFn) {
125
+ const { upstreamIdentifiers } = extra;
126
+ const holdingIdentifiers = [...upstreamIdentifiers];
127
+ collectParamsIdentifier(deepTravelNode, holdingIdentifiers);
128
+ updateVariableScopeAndOccupation(deepTravelNode, holdingIdentifiers);
129
+ const { visitedNodeSet, filePath } = extra;
130
+ const { children } = deepTravelNode._util;
131
+ const ancestors = [...deepTravelNode._util.ancestors, deepTravelNode];
132
+ Object.keys(deepTravelNode).forEach((childKey) => {
133
+ if (import_SHARED_CONSTANTS.INVALID_NODE_KEY.includes(childKey))
134
+ return;
135
+ const commonNodeExt = {
136
+ parentProperty: childKey,
137
+ filePath,
138
+ parent: deepTravelNode,
139
+ ancestors
140
+ };
141
+ const childValue = deepTravelNode[childKey];
142
+ if ((0, import_isValidNodeCollect.default)(childValue) && !visitedNodeSet.has(childValue)) {
143
+ visitedNodeSet.add(childValue);
144
+ childValue._util = (0, import_createAstNodeExt.default)({
145
+ indexOfProperty: null,
146
+ ...commonNodeExt
147
+ });
148
+ children.push(childValue);
149
+ } else if ((0, import_isValidArrayNodeCollect.default)(childValue)) {
150
+ childValue.forEach((childInArray, index) => {
151
+ if (visitedNodeSet.has(childInArray) || !(0, import_isValidNodeCollect.default)(childInArray))
152
+ return;
153
+ visitedNodeSet.add(childInArray);
154
+ childInArray._util = (0, import_createAstNodeExt.default)({
155
+ indexOfProperty: index,
156
+ ...commonNodeExt
157
+ });
158
+ children.push(childInArray);
159
+ });
160
+ }
161
+ });
162
+ const mergedExtra = { ...extra, upstreamIdentifiers: holdingIdentifiers };
163
+ travelFn(deepTravelNode);
164
+ for (const child of children) {
165
+ if (shouldWideTravel(child)) {
166
+ wideTravel([child], mergedExtra, travelFn);
167
+ } else {
168
+ deepTravel(child, mergedExtra, travelFn);
169
+ }
170
+ if (child.type === "Program") {
171
+ child.body.forEach((bodyElement) => (0, import_updateImportedAndExportedMember.default)(bodyElement, child));
172
+ }
173
+ if (!child._util.uuid) {
174
+ (0, import_updateLoc.default)(child, extra);
175
+ }
176
+ addIdentifiersToAncestors([child], ancestors);
177
+ }
178
+ }
179
+ function resortNodes(nodes) {
180
+ var _a, _b;
181
+ const hoistedNodeList = [];
182
+ const exportDeclarations = [];
183
+ for (const astNode of nodes) {
184
+ if (["ImportDeclaration", "FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration"].includes(astNode.type)) {
185
+ hoistedNodeList.push(astNode);
186
+ }
187
+ if (["ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(astNode.type)) {
188
+ const decType = (_a = astNode.declaration) == null ? void 0 : _a.type;
189
+ const decId = (_b = astNode.declaration) == null ? void 0 : _b.id;
190
+ if (["FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration"].includes(decType) && decId) {
191
+ exportDeclarations.push(astNode);
192
+ }
193
+ }
194
+ }
195
+ const notHoistedNodes = nodes.filter((node) => ![...hoistedNodeList, ...exportDeclarations].includes(node));
196
+ return {
197
+ hoistedNodeList,
198
+ exportDeclarations,
199
+ notHoistedNodes
200
+ };
201
+ }
202
+ function shouldWideTravel(astNode) {
203
+ return ["BlockStatement", "Program"].includes(astNode.type);
204
+ }
205
+ function updateHoldingIdMap(holdingIdentifiers, holdingIdNameMap) {
206
+ [...holdingIdentifiers].reverse().forEach((holdingId) => {
207
+ const holdingIdName = holdingId.name;
208
+ if (typeof holdingIdName !== "string")
209
+ return;
210
+ const nodeSetOfIdName = holdingIdNameMap.get(holdingIdName) || /* @__PURE__ */ new Set();
211
+ nodeSetOfIdName.add(holdingId);
212
+ holdingIdNameMap.set(holdingIdName, nodeSetOfIdName);
213
+ });
214
+ }
215
+ function collectParamsIdentifier(deepTravelNode, holdingIdentifiers) {
216
+ if (import_SHARED_CONSTANTS.FUNCTION_TYPES.includes(deepTravelNode.type)) {
217
+ const params = deepTravelNode.params;
218
+ Array.isArray(params) && params.forEach((param) => {
219
+ (0, import_deepSearchParamsIdentifier.default)(param, (identifier) => {
220
+ holdingIdentifiers.push(identifier);
221
+ });
222
+ });
223
+ }
224
+ }
225
+ function collectHoldingIdentifiers(ele, holdingIdentifiers, exportDeclarations) {
226
+ var _a, _b, _c;
227
+ if (ele.type === "ImportDeclaration") {
228
+ const specifiers = ele.specifiers;
229
+ for (const specifier of specifiers) {
230
+ holdingIdentifiers.push(specifier.local);
231
+ }
232
+ }
233
+ if (import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES.includes(ele.type)) {
234
+ const id = ele.id;
235
+ if (id) {
236
+ holdingIdentifiers.push(id);
237
+ }
238
+ }
239
+ if (import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES.includes((_a = ele.declaration) == null ? void 0 : _a.type)) {
240
+ const id = (_b = ele.declaration) == null ? void 0 : _b.id;
241
+ if (id) {
242
+ holdingIdentifiers.push(id);
243
+ }
244
+ }
245
+ if (exportDeclarations.includes(ele)) {
246
+ const id = (_c = ele == null ? void 0 : ele.declaration) == null ? void 0 : _c.id;
247
+ if (id) {
248
+ holdingIdentifiers.push(id);
249
+ }
250
+ }
251
+ if (ele.type === "VariableDeclaration") {
252
+ Array.from(new Set(ele.declarations)).forEach((declaration) => {
253
+ const id = declaration.id;
254
+ if (id) {
255
+ (0, import_deepSearchParamsIdentifier.default)(id, (identifier) => holdingIdentifiers.push(identifier));
256
+ }
257
+ });
258
+ }
259
+ if (ele.declaration && ele.declaration.type === "VariableDeclaration") {
260
+ Array.from(new Set(ele.declaration.declarations)).forEach((declaration) => {
261
+ const id = declaration.id;
262
+ if (id) {
263
+ (0, import_deepSearchParamsIdentifier.default)(id, (identifier) => holdingIdentifiers.push(identifier));
264
+ }
265
+ });
266
+ }
267
+ }
268
+ function isValidIdentifierOrJSXIdentifier(node) {
269
+ if (node.type === "Identifier" && !isImportedOrExported(node) && !isLiteralPropertyNode(node)) {
270
+ return true;
271
+ } else if (node.type === "JSXIdentifier" && isJsxElementIdentifier(node)) {
272
+ if (isJsxElementNameIdentifier(node)) {
273
+ return !import_intrinsicElements.intrinsicElements.includes(node.name);
274
+ }
275
+ return true;
276
+ }
277
+ return false;
278
+ }
279
+ function updateVariableScopeAndOccupation(deepTravelNode, holdingIdentifiers) {
280
+ var _a;
281
+ const holdingIdentifierSet = new Set(holdingIdentifiers);
282
+ deepTravelNode._util.holdingIds = holdingIdentifierSet;
283
+ updateHoldingIdMap(holdingIdentifiers, deepTravelNode._util.holdingIdNameMap);
284
+ const nodeName = deepTravelNode.name;
285
+ if (typeof nodeName !== "string") {
286
+ return;
287
+ }
288
+ const valid = isValidIdentifierOrJSXIdentifier(deepTravelNode);
289
+ if (!valid) {
290
+ return;
291
+ }
292
+ !holdingIdentifierSet.has(deepTravelNode) && deepTravelNode._util.ancestors.forEach((ancestor) => {
293
+ ancestor._util.dependenceIds.add(deepTravelNode);
294
+ });
295
+ deepTravelNode._util.variableScope = [...deepTravelNode._util.holdingIdNameMap.get(nodeName) || []];
296
+ const firstPick = deepTravelNode._util.variableScope[0];
297
+ if (firstPick && firstPick !== deepTravelNode) {
298
+ if (firstPick._util) {
299
+ firstPick._util.occupation.add(deepTravelNode);
300
+ } else {
301
+ console.log(deepTravelNode._util.filePath, (_a = deepTravelNode.loc) == null ? void 0 : _a.start.line, deepTravelNode.type, deepTravelNode.name);
302
+ }
303
+ }
304
+ }
305
+ function isLiteralPropertyNode(exp) {
306
+ var _a;
307
+ return (exp._util.parentProperty === "property" || exp._util.parentProperty === "key") && !((_a = exp._util.parent) == null ? void 0 : _a.computed);
308
+ }
309
+ function isJsxElementNameIdentifier(deepTravelNode) {
310
+ return deepTravelNode._util.parentProperty === "name" && typeof deepTravelNode.name === "string";
311
+ }
312
+ function isJsxElementIdentifier(deepTravelNode) {
313
+ var _a;
314
+ return ((_a = deepTravelNode._util.parent) == null ? void 0 : _a.type) !== "JSXAttribute" || isJsxElementNameIdentifier(deepTravelNode);
315
+ }
316
+ function isImportedOrExported(deepTravelNode) {
317
+ return deepTravelNode._util.parentProperty === "imported" || deepTravelNode._util.parentProperty === "exported";
318
+ }
319
+ function addIdentifiersToAncestors(children, ancestors) {
320
+ for (const child of children) {
321
+ ancestors.forEach((ancestor) => {
322
+ !ancestor._util.nodeCollection.includes(child) && ancestor._util.nodeCollection.push(child);
323
+ });
324
+ }
325
+ }
@@ -0,0 +1,2 @@
1
+ import { AstNode } from "../AstUtil";
2
+ export default function updateImportedAndExportedMember(node: AstNode, programNode: AstNode): void;
@@ -0,0 +1,135 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
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
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/util/ast_util/helper/updateImportedAndExportedMember.ts
30
+ var updateImportedAndExportedMember_exports = {};
31
+ __export(updateImportedAndExportedMember_exports, {
32
+ default: () => updateImportedAndExportedMember
33
+ });
34
+ module.exports = __toCommonJS(updateImportedAndExportedMember_exports);
35
+ var import_SHARED_CONSTANTS = require("../SHARED_CONSTANTS");
36
+ var import_findOrCreateExportedMember = __toESM(require("./findOrCreateExportedMember"));
37
+ var import_findOrCreateImportedMember = __toESM(require("./findOrCreateImportedMember"));
38
+ var import_collectVariableDeclarationIdentifiers = __toESM(require("./collectVariableDeclarationIdentifiers"));
39
+ function updateImportedAndExportedMember(node, programNode) {
40
+ var _a;
41
+ const { type, source, declaration, specifiers, _util } = node;
42
+ const { filePath } = _util;
43
+ const sourceValue = (source == null ? void 0 : source.value) || filePath;
44
+ const { importedMember, exportedMember } = programNode._util;
45
+ if (type === "ImportDeclaration") {
46
+ specifiers.forEach((specifier) => {
47
+ const { local, imported } = specifier;
48
+ const target = (0, import_findOrCreateImportedMember.default)(importedMember, sourceValue);
49
+ if (specifier.type === "ImportNamespaceSpecifier") {
50
+ target.members.push({
51
+ localName: local.name,
52
+ importedName: "*"
53
+ });
54
+ return;
55
+ }
56
+ if (specifier.type === "ImportDefaultSpecifier") {
57
+ target.members.push({
58
+ localName: local.name,
59
+ importedName: "default"
60
+ });
61
+ return;
62
+ }
63
+ if (specifier.type === "ImportSpecifier") {
64
+ target.members.push({
65
+ localName: local.name,
66
+ importedName: imported.name
67
+ });
68
+ }
69
+ });
70
+ }
71
+ if (type === "ExportAllDeclaration") {
72
+ const target = exportedMember.find((v) => v.sourcePath === sourceValue);
73
+ if (!target) {
74
+ exportedMember.push({ sourcePath: sourceValue, members: [], ExportAllDeclaration: true });
75
+ }
76
+ }
77
+ if (type === "ExportNamedDeclaration") {
78
+ Array.isArray(specifiers) && specifiers.forEach((specifier) => {
79
+ const { local, exported } = specifier;
80
+ const target = (0, import_findOrCreateExportedMember.default)(exportedMember, sourceValue);
81
+ if (specifier.type === "ExportNamespaceSpecifier") {
82
+ target.members.push({
83
+ localName: "*",
84
+ exportedName: exported.name
85
+ });
86
+ return;
87
+ }
88
+ if (specifier.type === "ExportSpecifier") {
89
+ target.members.push({
90
+ localName: local.name,
91
+ exportedName: exported.name
92
+ });
93
+ return;
94
+ }
95
+ });
96
+ if (Array.isArray(declaration == null ? void 0 : declaration.declarations)) {
97
+ declaration == null ? void 0 : declaration.declarations.forEach((dec) => {
98
+ const target = (0, import_findOrCreateExportedMember.default)(exportedMember, sourceValue);
99
+ (0, import_collectVariableDeclarationIdentifiers.default)(dec, (identifier) => {
100
+ try {
101
+ const idName = identifier.name;
102
+ target.members.push({
103
+ localName: idName,
104
+ exportedName: idName
105
+ });
106
+ } catch (e) {
107
+ console.log("declaration?.declarations.forEach", e.message);
108
+ }
109
+ });
110
+ });
111
+ } else if (import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES.includes(declaration == null ? void 0 : declaration.type)) {
112
+ const target = (0, import_findOrCreateExportedMember.default)(exportedMember, sourceValue);
113
+ try {
114
+ const idName = (_a = declaration.id) == null ? void 0 : _a.name;
115
+ target.members.push({
116
+ localName: idName,
117
+ exportedName: idName
118
+ });
119
+ } catch (e) {
120
+ console.log("declaration " + e.message);
121
+ }
122
+ }
123
+ }
124
+ if (type === "ExportDefaultDeclaration") {
125
+ let target = exportedMember.find((v) => v.sourcePath === filePath);
126
+ if (!target) {
127
+ target = { sourcePath: filePath, members: [], ExportAllDeclaration: false };
128
+ exportedMember.push(target);
129
+ }
130
+ target.members.push({
131
+ localName: "default",
132
+ exportedName: "default"
133
+ });
134
+ }
135
+ }
@@ -0,0 +1,6 @@
1
+ import { AstNode } from "../AstUtil";
2
+ export default function updateLoc(astNode: AstNode, extra: {
3
+ mapUuidToNode: Map<string, AstNode>;
4
+ mapFileLineToNodeSet: Map<number, Set<AstNode>>;
5
+ mapPathToNodeSet: Map<string, Set<AstNode>>;
6
+ }): void;