@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
package/dist/index.js
CHANGED
|
@@ -670,6 +670,15 @@ function resolve(imp, fromPath, byKey) {
|
|
|
670
670
|
}
|
|
671
671
|
|
|
672
672
|
// src/client/lib/evaluate.ts
|
|
673
|
+
var stripNonCode = (src, level = "full") => {
|
|
674
|
+
const blank = (m) => m.replace(/[^\n]/g, " ");
|
|
675
|
+
let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`])*`/g, blank);
|
|
676
|
+
if (level === "full") {
|
|
677
|
+
result = result.replace(/"(?:\\[\s\S]|[^"])*"/g, blank).replace(/'(?:\\[\s\S]|[^'])*'/g, blank);
|
|
678
|
+
}
|
|
679
|
+
return result;
|
|
680
|
+
};
|
|
681
|
+
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/");
|
|
673
682
|
function transpile(code) {
|
|
674
683
|
try {
|
|
675
684
|
const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
|
|
@@ -691,7 +700,8 @@ function execute(files) {
|
|
|
691
700
|
projections: [],
|
|
692
701
|
acts: [],
|
|
693
702
|
error: void 0,
|
|
694
|
-
fileErrors: /* @__PURE__ */ new Map()
|
|
703
|
+
fileErrors: /* @__PURE__ */ new Map(),
|
|
704
|
+
expectedSlices: /* @__PURE__ */ new Map()
|
|
695
705
|
};
|
|
696
706
|
try {
|
|
697
707
|
const __built__ = {
|
|
@@ -743,11 +753,7 @@ function execute(files) {
|
|
|
743
753
|
}
|
|
744
754
|
return unknownModuleProxy();
|
|
745
755
|
};
|
|
746
|
-
const sorted = topoSort(
|
|
747
|
-
files.filter(
|
|
748
|
-
(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/")
|
|
749
|
-
)
|
|
750
|
-
);
|
|
756
|
+
const sorted = topoSort(files.filter(isSourceFile));
|
|
751
757
|
for (const file of sorted) {
|
|
752
758
|
_currentFile = file.path;
|
|
753
759
|
const js = transpile(file.content);
|
|
@@ -757,10 +763,19 @@ function execute(files) {
|
|
|
757
763
|
const sliceNamesInAct = [];
|
|
758
764
|
const wsRe = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
|
|
759
765
|
let wsm;
|
|
760
|
-
|
|
766
|
+
const codeOnly = stripNonCode(js);
|
|
767
|
+
while ((wsm = wsRe.exec(codeOnly)) !== null) {
|
|
761
768
|
if (!sliceNamesInAct.includes(wsm[1])) sliceNamesInAct.push(wsm[1]);
|
|
762
769
|
}
|
|
763
|
-
const
|
|
770
|
+
for (const m of codeOnly.matchAll(
|
|
771
|
+
/(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
|
|
772
|
+
)) {
|
|
773
|
+
result.expectedSlices.set(m[1], file.path);
|
|
774
|
+
}
|
|
775
|
+
const fileRequire = Object.assign(
|
|
776
|
+
(mod) => resolveModule(mod, key),
|
|
777
|
+
{ resolve: (mod) => mod, cache: {}, main: void 0 }
|
|
778
|
+
);
|
|
764
779
|
try {
|
|
765
780
|
const cleanJs = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
|
|
766
781
|
const fn = new Function(
|
|
@@ -806,48 +821,10 @@ function execute(files) {
|
|
|
806
821
|
}
|
|
807
822
|
function extractModel(files) {
|
|
808
823
|
const result = execute(files);
|
|
809
|
-
|
|
810
|
-
for (const file of files) {
|
|
811
|
-
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/"))
|
|
812
|
-
continue;
|
|
813
|
-
for (const m of file.content.matchAll(
|
|
814
|
-
/(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*slice\s*\(\s*\)/g
|
|
815
|
-
)) {
|
|
816
|
-
expectedSlices.set(m[1], file.path);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return buildModel(result, files, expectedSlices);
|
|
824
|
+
return buildModel(result, files, result.expectedSlices);
|
|
820
825
|
}
|
|
821
826
|
|
|
822
827
|
// src/client/lib/navigate.ts
|
|
823
|
-
function isInsideComment(content, matchIndex) {
|
|
824
|
-
const before = content.slice(0, matchIndex);
|
|
825
|
-
const lastNl = before.lastIndexOf("\n");
|
|
826
|
-
const lineStart = lastNl >= 0 ? lastNl + 1 : 0;
|
|
827
|
-
const lineEnd = content.indexOf("\n", matchIndex);
|
|
828
|
-
const lineText = content.slice(lineStart, lineEnd >= 0 ? lineEnd : content.length).trimStart();
|
|
829
|
-
if (lineText.startsWith("//") || lineText.startsWith("*") || lineText.startsWith("/*")) {
|
|
830
|
-
return true;
|
|
831
|
-
}
|
|
832
|
-
const lastBlockOpen = before.lastIndexOf("/*");
|
|
833
|
-
if (lastBlockOpen >= 0) {
|
|
834
|
-
const lastBlockClose = before.lastIndexOf("*/");
|
|
835
|
-
if (lastBlockClose < lastBlockOpen) return true;
|
|
836
|
-
}
|
|
837
|
-
return false;
|
|
838
|
-
}
|
|
839
|
-
function findNonCommentMatch(content, re, startFrom = 0) {
|
|
840
|
-
const globalRe = new RegExp(
|
|
841
|
-
re.source,
|
|
842
|
-
re.flags.includes("g") ? re.flags : re.flags + "g"
|
|
843
|
-
);
|
|
844
|
-
globalRe.lastIndex = startFrom;
|
|
845
|
-
let match;
|
|
846
|
-
while ((match = globalRe.exec(content)) !== null) {
|
|
847
|
-
if (!isInsideComment(content, match.index)) return match.index;
|
|
848
|
-
}
|
|
849
|
-
return -1;
|
|
850
|
-
}
|
|
851
828
|
function positionAt(content, index) {
|
|
852
829
|
const before = content.slice(0, index);
|
|
853
830
|
const line = before.split("\n").length;
|
|
@@ -923,10 +900,19 @@ function buildPatterns(esc, type) {
|
|
|
923
900
|
}
|
|
924
901
|
}
|
|
925
902
|
function navigateToCode(files, name, type, targetFile) {
|
|
903
|
+
const stripped = /* @__PURE__ */ new Map();
|
|
904
|
+
const code = (f) => {
|
|
905
|
+
let c = stripped.get(f.path);
|
|
906
|
+
if (c === void 0) {
|
|
907
|
+
c = stripNonCode(f.content, "nav");
|
|
908
|
+
stripped.set(f.path, c);
|
|
909
|
+
}
|
|
910
|
+
return c;
|
|
911
|
+
};
|
|
926
912
|
if (type === "file") {
|
|
927
913
|
const file = files.find((f) => f.path === name || f.path.endsWith(name));
|
|
928
914
|
if (file) {
|
|
929
|
-
const actMatch = /\bact\s*\(\s*\)/.exec(file
|
|
915
|
+
const actMatch = /\bact\s*\(\s*\)/.exec(code(file));
|
|
930
916
|
if (actMatch) {
|
|
931
917
|
const { line, col } = positionAt(file.content, actMatch.index);
|
|
932
918
|
return { file: file.path, line, col };
|
|
@@ -938,31 +924,35 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
938
924
|
if (targetFile) {
|
|
939
925
|
const file = files.find((f) => f.path === targetFile);
|
|
940
926
|
if (file) {
|
|
927
|
+
const c = code(file);
|
|
941
928
|
const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
942
929
|
if (type === "event") {
|
|
943
930
|
const emitsBlockRe = new RegExp(
|
|
944
931
|
`\\.emits\\([\\s\\S]*?(${esc2})\\s*[,:}]`
|
|
945
932
|
);
|
|
946
|
-
const blockMatch = emitsBlockRe.exec(
|
|
933
|
+
const blockMatch = emitsBlockRe.exec(c);
|
|
947
934
|
if (blockMatch) {
|
|
948
935
|
const nameIdx = blockMatch.index + blockMatch[0].lastIndexOf(name);
|
|
949
936
|
const { line, col } = positionAt(file.content, nameIdx);
|
|
950
937
|
return { file: file.path, line, col };
|
|
951
938
|
}
|
|
952
939
|
const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
953
|
-
if (
|
|
954
|
-
const
|
|
955
|
-
if (
|
|
956
|
-
const { line, col } = positionAt(
|
|
940
|
+
if (nameRe2.exec(c)) {
|
|
941
|
+
const emitsMatch = /\.emits\s*\(/.exec(c);
|
|
942
|
+
if (emitsMatch) {
|
|
943
|
+
const { line, col } = positionAt(
|
|
944
|
+
file.content,
|
|
945
|
+
emitsMatch.index + 1
|
|
946
|
+
);
|
|
957
947
|
return { file: file.path, line, col };
|
|
958
948
|
}
|
|
959
949
|
}
|
|
960
950
|
}
|
|
961
951
|
if (type === "guard") {
|
|
962
952
|
const descRe = new RegExp(`description:\\s*["'\`]${esc2}["'\`]`);
|
|
963
|
-
const descMatch = descRe.exec(
|
|
953
|
+
const descMatch = descRe.exec(c);
|
|
964
954
|
if (descMatch) {
|
|
965
|
-
const before =
|
|
955
|
+
const before = c.slice(0, descMatch.index);
|
|
966
956
|
const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
967
957
|
let lastDecl = null;
|
|
968
958
|
let m;
|
|
@@ -980,19 +970,20 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
980
970
|
}
|
|
981
971
|
if (type === "action") {
|
|
982
972
|
const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
|
|
983
|
-
const blockStart =
|
|
973
|
+
const blockStart = c.indexOf(".on(");
|
|
984
974
|
if (blockStart >= 0) {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
975
|
+
nameRe2.lastIndex = blockStart;
|
|
976
|
+
const match2 = nameRe2.exec(c);
|
|
977
|
+
if (match2) {
|
|
978
|
+
const { line, col } = positionAt(file.content, match2.index);
|
|
988
979
|
return { file: file.path, line, col };
|
|
989
980
|
}
|
|
990
981
|
}
|
|
991
982
|
}
|
|
992
|
-
const nameRe = new RegExp(`\\b${esc2}\\b
|
|
993
|
-
const
|
|
994
|
-
if (
|
|
995
|
-
const { line, col } = positionAt(file.content,
|
|
983
|
+
const nameRe = new RegExp(`\\b${esc2}\\b`);
|
|
984
|
+
const match = nameRe.exec(c);
|
|
985
|
+
if (match) {
|
|
986
|
+
const { line, col } = positionAt(file.content, match.index);
|
|
996
987
|
return { file: file.path, line, col };
|
|
997
988
|
}
|
|
998
989
|
}
|
|
@@ -1007,9 +998,10 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
1007
998
|
const descRe = new RegExp(`description:\\s*["'\`]${esc}["'\`]`);
|
|
1008
999
|
for (const f of sortedFiles) {
|
|
1009
1000
|
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
|
|
1001
|
+
const c = code(f);
|
|
1002
|
+
const descMatch = descRe.exec(c);
|
|
1003
|
+
if (descMatch) {
|
|
1004
|
+
const before = c.slice(0, descMatch.index);
|
|
1013
1005
|
const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
|
|
1014
1006
|
let lastDecl = null;
|
|
1015
1007
|
let m;
|
|
@@ -1026,18 +1018,17 @@ function navigateToCode(files, name, type, targetFile) {
|
|
|
1026
1018
|
}
|
|
1027
1019
|
const patterns = buildPatterns(esc, type);
|
|
1028
1020
|
for (const re of patterns) {
|
|
1029
|
-
for (
|
|
1030
|
-
if (!/\.tsx?$/.test(
|
|
1031
|
-
const
|
|
1021
|
+
for (const f of sortedFiles) {
|
|
1022
|
+
if (!/\.tsx?$/.test(f.path)) continue;
|
|
1023
|
+
const c = code(f);
|
|
1032
1024
|
const globalRe = new RegExp(re.source, re.flags + "g");
|
|
1033
1025
|
let match;
|
|
1034
|
-
while ((match = globalRe.exec(
|
|
1035
|
-
if (isInsideComment(content, match.index)) continue;
|
|
1026
|
+
while ((match = globalRe.exec(c)) !== null) {
|
|
1036
1027
|
const matchText = match[0];
|
|
1037
1028
|
const nameOffsetInMatch = matchText.lastIndexOf(name);
|
|
1038
1029
|
const nameStart = match.index + Math.max(0, nameOffsetInMatch);
|
|
1039
|
-
const { line, col } = positionAt(content, nameStart);
|
|
1040
|
-
return { file:
|
|
1030
|
+
const { line, col } = positionAt(f.content, nameStart);
|
|
1031
|
+
return { file: f.path, line, col };
|
|
1041
1032
|
}
|
|
1042
1033
|
}
|
|
1043
1034
|
}
|