@rotorsoft/act-diagram 0.1.2 → 0.1.3
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/.tsbuildinfo +1 -1
- package/dist/@types/client/lib/evaluate.d.ts +4 -0
- package/dist/@types/client/lib/evaluate.d.ts.map +1 -1
- package/dist/@types/client/lib/navigate.d.ts.map +1 -1
- package/dist/index.cjs +64 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -73
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { DomainModel, FileTab } from "../types/index.js";
|
|
2
|
+
/** Replace non-executable content with same-length whitespace (preserving offsets).
|
|
3
|
+
* `level: "full"` strips comments + strings + template literals (for scanning).
|
|
4
|
+
* `level: "nav"` strips comments + template literals only (for navigation). */
|
|
5
|
+
export declare const stripNonCode: (src: string, level?: "full" | "nav") => string;
|
|
2
6
|
export declare function extractModel(files: FileTab[]): {
|
|
3
7
|
model: DomainModel;
|
|
4
8
|
error?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/evaluate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/evaluate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAK9D;;gFAEgF;AAChF,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,QAAO,MAAM,GAAG,KAAc,WAYvE,CAAC;AA8NF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG;IAC9C,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAGA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/navigate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/navigate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAoFjD,KAAK,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EAAE,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,GAAG,SAAS,CA8J5B"}
|
package/dist/index.cjs
CHANGED
|
@@ -710,6 +710,15 @@ function resolve(imp, fromPath, byKey) {
|
|
|
710
710
|
}
|
|
711
711
|
|
|
712
712
|
// src/client/lib/evaluate.ts
|
|
713
|
+
var stripNonCode = (src, level = "full") => {
|
|
714
|
+
const blank = (m) => m.replace(/[^\n]/g, " ");
|
|
715
|
+
let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`])*`/g, blank);
|
|
716
|
+
if (level === "full") {
|
|
717
|
+
result = result.replace(/"(?:\\[\s\S]|[^"])*"/g, blank).replace(/'(?:\\[\s\S]|[^'])*'/g, blank);
|
|
718
|
+
}
|
|
719
|
+
return result;
|
|
720
|
+
};
|
|
721
|
+
var isSourceFile = (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/");
|
|
713
722
|
function transpile(code) {
|
|
714
723
|
try {
|
|
715
724
|
const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
|
|
@@ -731,7 +740,8 @@ function execute(files) {
|
|
|
731
740
|
projections: [],
|
|
732
741
|
acts: [],
|
|
733
742
|
error: void 0,
|
|
734
|
-
fileErrors: /* @__PURE__ */ new Map()
|
|
743
|
+
fileErrors: /* @__PURE__ */ new Map(),
|
|
744
|
+
expectedSlices: /* @__PURE__ */ new Map()
|
|
735
745
|
};
|
|
736
746
|
try {
|
|
737
747
|
const __built__ = {
|
|
@@ -783,11 +793,7 @@ function execute(files) {
|
|
|
783
793
|
}
|
|
784
794
|
return unknownModuleProxy();
|
|
785
795
|
};
|
|
786
|
-
const sorted = topoSort(
|
|
787
|
-
files.filter(
|
|
788
|
-
(f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/")
|
|
789
|
-
)
|
|
790
|
-
);
|
|
796
|
+
const sorted = topoSort(files.filter(isSourceFile));
|
|
791
797
|
for (const file of sorted) {
|
|
792
798
|
_currentFile = file.path;
|
|
793
799
|
const js = transpile(file.content);
|
|
@@ -797,10 +803,19 @@ function execute(files) {
|
|
|
797
803
|
const sliceNamesInAct = [];
|
|
798
804
|
const wsRe = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
|
|
799
805
|
let wsm;
|
|
800
|
-
|
|
806
|
+
const codeOnly = stripNonCode(js);
|
|
807
|
+
while ((wsm = wsRe.exec(codeOnly)) !== null) {
|
|
801
808
|
if (!sliceNamesInAct.includes(wsm[1])) sliceNamesInAct.push(wsm[1]);
|
|
802
809
|
}
|
|
803
|
-
const
|
|
810
|
+
for (const m of codeOnly.matchAll(
|
|
811
|
+
/(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
|
|
812
|
+
)) {
|
|
813
|
+
result.expectedSlices.set(m[1], file.path);
|
|
814
|
+
}
|
|
815
|
+
const fileRequire = Object.assign(
|
|
816
|
+
(mod) => resolveModule(mod, key),
|
|
817
|
+
{ resolve: (mod) => mod, cache: {}, main: void 0 }
|
|
818
|
+
);
|
|
804
819
|
try {
|
|
805
820
|
const cleanJs = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
|
|
806
821
|
const fn = new Function(
|
|
@@ -846,48 +861,10 @@ function execute(files) {
|
|
|
846
861
|
}
|
|
847
862
|
function extractModel(files) {
|
|
848
863
|
const result = execute(files);
|
|
849
|
-
|
|
850
|
-
for (const file of files) {
|
|
851
|
-
if (!file.path.endsWith(".ts") || file.path.endsWith(".d.ts") || file.path.endsWith(".spec.ts") || file.path.endsWith(".test.ts") || file.path.includes("node_modules/"))
|
|
852
|
-
continue;
|
|
853
|
-
for (const m of file.content.matchAll(
|
|
854
|
-
/(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*slice\s*\(\s*\)/g
|
|
855
|
-
)) {
|
|
856
|
-
expectedSlices.set(m[1], file.path);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
return buildModel(result, files, expectedSlices);
|
|
864
|
+
return buildModel(result, files, result.expectedSlices);
|
|
860
865
|
}
|
|
861
866
|
|
|
862
867
|
// src/client/lib/navigate.ts
|
|
863
|
-
function isInsideComment(content, matchIndex) {
|
|
864
|
-
const before = content.slice(0, matchIndex);
|
|
865
|
-
const lastNl = before.lastIndexOf("\n");
|
|
866
|
-
const lineStart = lastNl >= 0 ? lastNl + 1 : 0;
|
|
867
|
-
const lineEnd = content.indexOf("\n", matchIndex);
|
|
868
|
-
const lineText = content.slice(lineStart, lineEnd >= 0 ? lineEnd : content.length).trimStart();
|
|
869
|
-
if (lineText.startsWith("//") || lineText.startsWith("*") || lineText.startsWith("/*")) {
|
|
870
|
-
return true;
|
|
871
|
-
}
|
|
872
|
-
const lastBlockOpen = before.lastIndexOf("/*");
|
|
873
|
-
if (lastBlockOpen >= 0) {
|
|
874
|
-
const lastBlockClose = before.lastIndexOf("*/");
|
|
875
|
-
if (lastBlockClose < lastBlockOpen) return true;
|
|
876
|
-
}
|
|
877
|
-
return false;
|
|
878
|
-
}
|
|
879
|
-
function findNonCommentMatch(content, re, startFrom = 0) {
|
|
880
|
-
const globalRe = new RegExp(
|
|
881
|
-
re.source,
|
|
882
|
-
re.flags.includes("g") ? re.flags : re.flags + "g"
|
|
883
|
-
);
|
|
884
|
-
globalRe.lastIndex = startFrom;
|
|
885
|
-
let match;
|
|
886
|
-
while ((match = globalRe.exec(content)) !== null) {
|
|
887
|
-
if (!isInsideComment(content, match.index)) return match.index;
|
|
888
|
-
}
|
|
889
|
-
return -1;
|
|
890
|
-
}
|
|
891
868
|
function positionAt(content, index) {
|
|
892
869
|
const before = content.slice(0, index);
|
|
893
870
|
const line = before.split("\n").length;
|
|
@@ -963,10 +940,19 @@ function buildPatterns(esc, type) {
|
|
|
963
940
|
}
|
|
964
941
|
}
|
|
965
942
|
function navigateToCode(files, name, type, targetFile) {
|
|
943
|
+
const stripped = /* @__PURE__ */ new Map();
|
|
944
|
+
const code = (f) => {
|
|
945
|
+
let c = stripped.get(f.path);
|
|
946
|
+
if (c === void 0) {
|
|
947
|
+
c = stripNonCode(f.content, "nav");
|
|
948
|
+
stripped.set(f.path, c);
|
|
949
|
+
}
|
|
950
|
+
return c;
|
|
951
|
+
};
|
|
966
952
|
if (type === "file") {
|
|
967
953
|
const file = files.find((f) => f.path === name || f.path.endsWith(name));
|
|
968
954
|
if (file) {
|
|
969
|
-
const actMatch = /\bact\s*\(\s*\)/.exec(file
|
|
955
|
+
const actMatch = /\bact\s*\(\s*\)/.exec(code(file));
|
|
970
956
|
if (actMatch) {
|
|
971
957
|
const { line, col } = positionAt(file.content, actMatch.index);
|
|
972
958
|
return { file: file.path, line, col };
|
|
@@ -978,31 +964,35 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
978
964
|
if (targetFile) {
|
|
979
965
|
const file = files.find((f) => f.path === targetFile);
|
|
980
966
|
if (file) {
|
|
967
|
+
const c = code(file);
|
|
981
968
|
const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
982
969
|
if (type === "event") {
|
|
983
970
|
const emitsBlockRe = new RegExp(
|
|
984
971
|
`\\.emits\\([\\s\\S]*?(${esc2})\\s*[,:}]`
|
|
985
972
|
);
|
|
986
|
-
const blockMatch = emitsBlockRe.exec(
|
|
973
|
+
const blockMatch = emitsBlockRe.exec(c);
|
|
987
974
|
if (blockMatch) {
|
|
988
975
|
const nameIdx = blockMatch.index + blockMatch[0].lastIndexOf(name);
|
|
989
976
|
const { line, col } = positionAt(file.content, nameIdx);
|
|
990
977
|
return { file: file.path, line, col };
|
|
991
978
|
}
|
|
992
979
|
const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
993
|
-
if (
|
|
994
|
-
const
|
|
995
|
-
if (
|
|
996
|
-
const { line, col } = positionAt(
|
|
980
|
+
if (nameRe2.exec(c)) {
|
|
981
|
+
const emitsMatch = /\.emits\s*\(/.exec(c);
|
|
982
|
+
if (emitsMatch) {
|
|
983
|
+
const { line, col } = positionAt(
|
|
984
|
+
file.content,
|
|
985
|
+
emitsMatch.index + 1
|
|
986
|
+
);
|
|
997
987
|
return { file: file.path, line, col };
|
|
998
988
|
}
|
|
999
989
|
}
|
|
1000
990
|
}
|
|
1001
991
|
if (type === "guard") {
|
|
1002
992
|
const descRe = new RegExp(`description:\\s*["'\`]${esc2}["'\`]`);
|
|
1003
|
-
const descMatch = descRe.exec(
|
|
993
|
+
const descMatch = descRe.exec(c);
|
|
1004
994
|
if (descMatch) {
|
|
1005
|
-
const before =
|
|
995
|
+
const before = c.slice(0, descMatch.index);
|
|
1006
996
|
const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
1007
997
|
let lastDecl = null;
|
|
1008
998
|
let m;
|
|
@@ -1020,19 +1010,20 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
1020
1010
|
}
|
|
1021
1011
|
if (type === "action") {
|
|
1022
1012
|
const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
1023
|
-
const blockStart =
|
|
1013
|
+
const blockStart = c.indexOf(".on(");
|
|
1024
1014
|
if (blockStart >= 0) {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1015
|
+
nameRe2.lastIndex = blockStart;
|
|
1016
|
+
const match2 = nameRe2.exec(c);
|
|
1017
|
+
if (match2) {
|
|
1018
|
+
const { line, col } = positionAt(file.content, match2.index);
|
|
1028
1019
|
return { file: file.path, line, col };
|
|
1029
1020
|
}
|
|
1030
1021
|
}
|
|
1031
1022
|
}
|
|
1032
|
-
const nameRe = new RegExp(`\\b${esc2}\\b
|
|
1033
|
-
const
|
|
1034
|
-
if (
|
|
1035
|
-
const { line, col } = positionAt(file.content,
|
|
1023
|
+
const nameRe = new RegExp(`\\b${esc2}\\b`);
|
|
1024
|
+
const match = nameRe.exec(c);
|
|
1025
|
+
if (match) {
|
|
1026
|
+
const { line, col } = positionAt(file.content, match.index);
|
|
1036
1027
|
return { file: file.path, line, col };
|
|
1037
1028
|
}
|
|
1038
1029
|
}
|
|
@@ -1047,9 +1038,10 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
1047
1038
|
const descRe = new RegExp(`description:\\s*["'\`]${esc}["'\`]`);
|
|
1048
1039
|
for (const f of sortedFiles) {
|
|
1049
1040
|
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1052
|
-
|
|
1041
|
+
const c = code(f);
|
|
1042
|
+
const descMatch = descRe.exec(c);
|
|
1043
|
+
if (descMatch) {
|
|
1044
|
+
const before = c.slice(0, descMatch.index);
|
|
1053
1045
|
const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
1054
1046
|
let lastDecl = null;
|
|
1055
1047
|
let m;
|
|
@@ -1066,18 +1058,17 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
1066
1058
|
}
|
|
1067
1059
|
const patterns = buildPatterns(esc, type);
|
|
1068
1060
|
for (const re of patterns) {
|
|
1069
|
-
for (
|
|
1070
|
-
if (!/\.tsx?$/.test(
|
|
1071
|
-
const
|
|
1061
|
+
for (const f of sortedFiles) {
|
|
1062
|
+
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1063
|
+
const c = code(f);
|
|
1072
1064
|
const globalRe = new RegExp(re.source, re.flags + "g");
|
|
1073
1065
|
let match;
|
|
1074
|
-
while ((match = globalRe.exec(
|
|
1075
|
-
if (isInsideComment(content, match.index)) continue;
|
|
1066
|
+
while ((match = globalRe.exec(c)) !== null) {
|
|
1076
1067
|
const matchText = match[0];
|
|
1077
1068
|
const nameOffsetInMatch = matchText.lastIndexOf(name);
|
|
1078
1069
|
const nameStart = match.index + Math.max(0, nameOffsetInMatch);
|
|
1079
|
-
const { line, col } = positionAt(content, nameStart);
|
|
1080
|
-
return { file:
|
|
1070
|
+
const { line, col } = positionAt(f.content, nameStart);
|
|
1071
|
+
return { file: f.path, line, col };
|
|
1081
1072
|
}
|
|
1082
1073
|
}
|
|
1083
1074
|
}
|