js-code-detector 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/util/report_util/createMdByJson.js +11 -6
- package/dist/cjs/util/report_util/file_identifier_detect.d.ts +0 -1
- package/dist/cjs/util/report_util/file_identifier_detect.js +2 -13
- package/dist/cjs/util/report_util.d.ts +4 -3
- package/dist/cjs/util/report_util.js +7 -6
- package/package.json +1 -1
|
@@ -43,7 +43,8 @@ function reportItemToMd(report) {
|
|
|
43
43
|
${filesDependsOnMe.slice(0, 1).map((files) => files.map((file) => `- ${file}`)).flat().join("\n")}` : "",
|
|
44
44
|
undefinedIdentifiers.length > 0 ? `### 未定义的变量
|
|
45
45
|
> ${undefinedIdentifiers.map((e) => `**${e}**`).join(", ")}` : "",
|
|
46
|
-
//
|
|
46
|
+
// todo 拿到具体的节点 对应的 文本
|
|
47
|
+
// dangerIdentifiers.length > 0 ? `### 请确认以下删除是安全的\n${dangerIdentifiers.map(e => `> ${e}`).join('\n')}` : '',
|
|
47
48
|
blockReports.length > 0 ? `### 对比分析 共${blockReports.length}处` : "",
|
|
48
49
|
...blockReports.map(blockReportToMd)
|
|
49
50
|
].filter(Boolean).join("\n\n");
|
|
@@ -65,16 +66,20 @@ ${diff_txt.join("\n")}
|
|
|
65
66
|
function blockReportInfoItemToMd(info) {
|
|
66
67
|
const {
|
|
67
68
|
causeBy,
|
|
68
|
-
|
|
69
|
+
effectsUpstream,
|
|
70
|
+
effectsDownstream,
|
|
69
71
|
occupations
|
|
70
72
|
} = info;
|
|
71
73
|
return [
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
${
|
|
74
|
+
effectsUpstream.length > 0 ? `#### ${causeBy}
|
|
75
|
+
- 上游影响:
|
|
76
|
+
${effectsUpstream.map((e) => `> ${e}`).join("\n")}` : "",
|
|
75
77
|
occupations.length > 0 ? `#### ${causeBy}
|
|
76
78
|
- 使用:
|
|
77
|
-
${occupations.map((e) => `> ${e}`).join("\n")}` : "
|
|
79
|
+
${occupations.map((e) => `> ${e}`).join("\n")}` : "",
|
|
80
|
+
effectsDownstream.length > 0 ? `#### ${causeBy}
|
|
81
|
+
- 下游影响:
|
|
82
|
+
${effectsDownstream.map((e) => `> ${e}`).join("\n")}` : ""
|
|
78
83
|
].filter(Boolean).join("\n\n");
|
|
79
84
|
}
|
|
80
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -29,8 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/util/report_util/file_identifier_detect.ts
|
|
30
30
|
var file_identifier_detect_exports = {};
|
|
31
31
|
__export(file_identifier_detect_exports, {
|
|
32
|
-
extractUndefinedIdentifiers: () => extractUndefinedIdentifiers
|
|
33
|
-
fileIdentifierDetect: () => fileIdentifierDetect
|
|
32
|
+
extractUndefinedIdentifiers: () => extractUndefinedIdentifiers
|
|
34
33
|
});
|
|
35
34
|
module.exports = __toCommonJS(file_identifier_detect_exports);
|
|
36
35
|
var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
|
|
@@ -45,17 +44,7 @@ function extractUndefinedIdentifiers(filePath, absPathPrefix) {
|
|
|
45
44
|
const ids = [...dependenceIds].filter((id) => import_AstUtil.default.isUntrackedId(id));
|
|
46
45
|
return ids.map((id) => import_AstUtil.default.getShortNodeMsg(id));
|
|
47
46
|
}
|
|
48
|
-
function fileIdentifierDetect(filePath, absPathPrefix) {
|
|
49
|
-
const { mapUuidToNode } = (0, import_getAstKitByFilePath.default)(filePath, absPathPrefix);
|
|
50
|
-
const programNode = mapUuidToNode.get("Program");
|
|
51
|
-
if (!programNode) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
const { effectIds } = programNode._util;
|
|
55
|
-
return [...effectIds].map((id) => import_AstUtil.default.getShortNodeMsg(id));
|
|
56
|
-
}
|
|
57
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
48
|
0 && (module.exports = {
|
|
59
|
-
extractUndefinedIdentifiers
|
|
60
|
-
fileIdentifierDetect
|
|
49
|
+
extractUndefinedIdentifiers
|
|
61
50
|
});
|
|
@@ -25,18 +25,19 @@ type Arg = {
|
|
|
25
25
|
absPathPrefix: string;
|
|
26
26
|
};
|
|
27
27
|
export declare function createDetectReport(arg: Arg): {
|
|
28
|
+
dangerIdentifiers: string[];
|
|
28
29
|
blockReports: {
|
|
29
30
|
diff_txt: string[];
|
|
30
31
|
infos: {
|
|
31
32
|
causeBy: string;
|
|
32
|
-
|
|
33
|
+
effectsUpstream: string[];
|
|
33
34
|
occupations: string[];
|
|
35
|
+
effectsDownstream: string[];
|
|
34
36
|
}[];
|
|
35
37
|
}[];
|
|
36
|
-
type: "
|
|
38
|
+
type: "modify" | "add" | "delete";
|
|
37
39
|
filesDependsOnMe: string[][];
|
|
38
40
|
undefinedIdentifiers: string[];
|
|
39
|
-
dangerIdentifiers: string[];
|
|
40
41
|
filePath: string;
|
|
41
42
|
}[];
|
|
42
43
|
export {};
|
|
@@ -58,7 +58,6 @@ function createDetectReport(arg) {
|
|
|
58
58
|
reports.push(reportItem);
|
|
59
59
|
}
|
|
60
60
|
reportItem.undefinedIdentifiers = (0, import_file_identifier_detect.extractUndefinedIdentifiers)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix);
|
|
61
|
-
reportItem.dangerIdentifiers = (0, import_file_identifier_detect.fileIdentifierDetect)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix);
|
|
62
61
|
if (type === "modify") {
|
|
63
62
|
(0, import_diffBlockDetect.diffBlockDetect)(item, index, { reportItem, absPathPrefix });
|
|
64
63
|
}
|
|
@@ -67,10 +66,11 @@ function createDetectReport(arg) {
|
|
|
67
66
|
const { _fileAddedNodesPaths, _fileRemovedNodesPaths, filePath, blockReports, ...reportProperties } = reportItem;
|
|
68
67
|
(0, import_diffBlockDetect.reportItemDetect)(reportItem, absPathPrefix);
|
|
69
68
|
const fileAddedNodesPaths = reportItem._fileAddedNodesPaths.map((item) => item.nodePath);
|
|
70
|
-
const fileRemovedNodesPaths = reportItem._fileRemovedNodesPaths.map((item) => item.
|
|
69
|
+
const fileRemovedNodesPaths = reportItem._fileRemovedNodesPaths.map((item) => import_AstUtil.default.getShortNodeMsg(item.node, true));
|
|
71
70
|
return {
|
|
72
71
|
filePath,
|
|
73
72
|
...reportProperties,
|
|
73
|
+
dangerIdentifiers: fileRemovedNodesPaths,
|
|
74
74
|
blockReports: blockReports.map((blockReport) => {
|
|
75
75
|
const { diff_txt } = blockReport;
|
|
76
76
|
const addNodeAndPaths = blockReport.addNodeAndPaths.filter((e) => fileAddedNodesPaths.includes(e.nodePath));
|
|
@@ -79,16 +79,17 @@ function createDetectReport(arg) {
|
|
|
79
79
|
const { effectIds, occupation, holdingIdType } = node._util;
|
|
80
80
|
return {
|
|
81
81
|
causeBy: import_AstUtil.default.getShortNodeMsg(node, true),
|
|
82
|
-
|
|
82
|
+
effectsUpstream: [...effectIds].map((e) => import_AstUtil.default.getShortNodeMsg(e, true)),
|
|
83
|
+
occupations: [...occupation].map((e) => import_AstUtil.default.getShortNodeMsg(e, true)),
|
|
84
|
+
effectsDownstream: holdingIdType ? [...occupation].map((occupationId) => {
|
|
83
85
|
const ans = import_AstUtil.default.getAncestorsFromBirth(occupationId, node);
|
|
84
86
|
return import_AstUtil.default.getNearestImpactedNode(ans.reverse());
|
|
85
|
-
}).filter(Boolean).map((e) => import_AstUtil.default.getShortNodeMsg(e, true)) : [
|
|
86
|
-
occupations: [...occupation].map((e) => import_AstUtil.default.getShortNodeMsg(e, true))
|
|
87
|
+
}).filter(Boolean).map((e) => import_AstUtil.default.getShortNodeMsg(e, true)) : []
|
|
87
88
|
};
|
|
88
89
|
});
|
|
89
90
|
return {
|
|
90
91
|
diff_txt,
|
|
91
|
-
infos: infosList.filter((e) => e.
|
|
92
|
+
infos: infosList.filter((e) => e.effectsUpstream.length > 0 || e.occupations.length > 0 || e.effectsDownstream.length > 0)
|
|
92
93
|
};
|
|
93
94
|
}).filter((e) => e.infos.length > 0)
|
|
94
95
|
};
|