js-code-detector 0.0.9 → 0.0.10

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.
@@ -1,5 +1,5 @@
1
- import { FileSegment, MapFilePathToDetail } from "./FileUtil";
2
- import AstFeatUtil, { AstFeatNode, MapHashKeyToAstNodeSet } from "./AstFeatUtil";
1
+ import { FileSegment } from "./FileUtil";
2
+ import { AstFeatNode } from "./AstFeatUtil";
3
3
  export default class Core {
4
4
  static createMarkdownFile(result: {
5
5
  list: {
@@ -40,31 +40,8 @@ export default class Core {
40
40
  countList: number[];
41
41
  depthList: number[];
42
42
  };
43
- static getFileContentByLine(map: MapFilePathToDetail, filePath: string, start: number, end: number): {
44
- location: string;
45
- content: string;
46
- };
47
- static getListOfGroup(mapFilePathToDetail: MapFilePathToDetail, validFullNodeList: ReturnType<typeof Core.getListOfNodeGroup>['nodeGroupList']): {
48
- list: {
49
- astNode: AstFeatNode;
50
- location: string;
51
- content: string;
52
- }[];
53
- listOfNodeInfo: (typeof validFullNodeList)[number]["listOfNodeInfo"];
54
- nodeCount: number;
55
- depth: number;
56
- hashKey: string;
57
- }[];
58
- static createMapHashKeyToAstNodeSet(fileList: FileSegment[]): readonly [MapHashKeyToAstNodeSet, Set<string>, string[]];
59
- static getListOfNodeGroup(mapHashKeyToNodeSet: MapHashKeyToAstNodeSet): {
60
- nodeGroupList: {
61
- list: AstFeatNode[];
62
- listOfNodeInfo: ReturnType<typeof AstFeatUtil.spreadSubNode>;
63
- nodeCount: number;
64
- depth: number;
65
- hashKey: string;
66
- }[];
67
- countList: number[];
68
- depthList: number[];
69
- };
43
+ private static getFileContentByLine;
44
+ private static getListOfGroup;
45
+ private static createMapHashKeyToAstNodeSet;
46
+ private static getListOfNodeGroup;
70
47
  }
@@ -69,19 +69,21 @@ function codeBlockDetect(arg) {
69
69
  const filePathOfOld = (0, import_path.join)(process.cwd(), "..", "source", filePath);
70
70
  const { mapFileLineToNodeSet: mapFileLineToNodeSetOld } = (0, import_getAstKitByFilePath.default)(filePathOfOld, absPathPrefix);
71
71
  const programNode = mapUuidToNode.get("Program");
72
- const lineNumberStartNew = Number(startLineOfNew);
73
- const lineNumberEndNew = lineNumberStartNew + items.filter((item) => item.startsWith("+")).length - 1;
74
- const lineNumberStartOld = Number(startLineOfOld);
75
- const lineNumberEndOld = lineNumberStartOld + items.filter((item) => item.startsWith("-")).length - 1;
76
- const addNodes = import_AstUtil.default.getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStartNew, lineNumberEndNew);
77
- const removeNodes = import_AstUtil.default.getTopScopeNodesByLineNumberRange(mapFileLineToNodeSetOld, lineNumberStartOld, lineNumberEndOld);
78
- iterateNodes(addNodes, "add", { blockReports, programNode });
79
- iterateNodes(removeNodes, "remove", { blockReports, programNode });
80
- const lastReport = blockReports.at(-1);
81
- if (lastReport) {
82
- lastReport.diff_txt = items;
83
- lastReport.topAdded = addNodes;
84
- lastReport.topRemoved = removeNodes;
72
+ if (programNode) {
73
+ const lineNumberStartNew = Number(startLineOfNew);
74
+ const lineNumberEndNew = lineNumberStartNew + items.filter((item) => item.startsWith("+")).length - 1;
75
+ const lineNumberStartOld = Number(startLineOfOld);
76
+ const lineNumberEndOld = lineNumberStartOld + items.filter((item) => item.startsWith("-")).length - 1;
77
+ const addNodes = import_AstUtil.default.getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStartNew, lineNumberEndNew);
78
+ const removeNodes = import_AstUtil.default.getTopScopeNodesByLineNumberRange(mapFileLineToNodeSetOld, lineNumberStartOld, lineNumberEndOld);
79
+ iterateNodes(addNodes, "add", { blockReports, programNode });
80
+ iterateNodes(removeNodes, "remove", { blockReports, programNode });
81
+ const lastReport = blockReports.at(-1);
82
+ if (lastReport) {
83
+ lastReport.diff_txt = items;
84
+ lastReport.topAdded = addNodes;
85
+ lastReport.topRemoved = removeNodes;
86
+ }
85
87
  }
86
88
  blockReports.push(createBlockReport("Never"));
87
89
  }
@@ -34,10 +34,10 @@ function reportItemToMd(report) {
34
34
  const { filePath, filesDependsOnMe, type, dangerIdentifiers, blockReports } = report;
35
35
  return [
36
36
  `## ${filePath}`,
37
- `- 类型: ${mapReportType[type]}`,
38
- filesDependsOnMe.length > 0 ? `- 依赖${filePath}的文件` : "",
39
- ...filesDependsOnMe.map((file, i) => `${i + 1}. ${file}`),
40
- dangerIdentifiers.length > 0 ? `- 重点检查使用的变量` : "",
37
+ `### 类型: ${mapReportType[type]}`,
38
+ filesDependsOnMe.length > 0 ? `### 依赖${filePath}的文件` : "",
39
+ ...filesDependsOnMe.map((file) => `- ${file}`),
40
+ dangerIdentifiers.length > 0 ? `### 重点检查使用的变量` : "",
41
41
  dangerIdentifiers.length > 0 ? `> ${dangerIdentifiers.join(", ")}` : "",
42
42
  blockReports.length > 0 ? `### 代码块分析` : "",
43
43
  ...blockReports.map(blockReportToMd)
@@ -37,6 +37,9 @@ var import_AstUtil = __toESM(require("../ast_util/AstUtil"));
37
37
  function fileIdentifierDetect(filePath, absPathPrefix) {
38
38
  const { mapUuidToNode } = (0, import_getAstKitByFilePath.default)(filePath, absPathPrefix);
39
39
  const programNode = mapUuidToNode.get("Program");
40
+ if (!programNode) {
41
+ return [];
42
+ }
40
43
  const { dependenceIds } = programNode._util;
41
44
  const ids = [...dependenceIds].filter((id) => {
42
45
  return import_AstUtil.default.isUntrackedId(id) || id._util.crossScope.size > 0;
@@ -31,7 +31,7 @@ export declare function createDetectReport(arg: Arg): {
31
31
  kind: "Import" | "Declaration" | "Assignment" | "SelfUpdate" | "Invoke" | "Other" | "Never";
32
32
  }[];
33
33
  filePath: string;
34
- type: "add" | "delete" | "modify";
34
+ type: "add" | "modify" | "delete";
35
35
  filesDependsOnMe: string[];
36
36
  dangerIdentifiers: string[];
37
37
  }[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",