fastscript 3.0.0 → 3.0.1
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/CHANGELOG.md +6 -0
- package/README.md +667 -636
- package/node_modules/@fastscript/core-private/src/fs-normalize.mjs +125 -121
- package/node_modules/@fastscript/core-private/src/typecheck.mjs +1466 -1464
- package/package.json +18 -3
- package/src/compatibility-governance.mjs +257 -0
- package/src/fs-normalize.mjs +6 -4
- package/src/generated/compatibility-registry-report.mjs +815 -0
- package/src/generated/docs-search-index.mjs +710 -219
- package/src/validate.mjs +2 -0
|
@@ -1,121 +1,125 @@
|
|
|
1
|
-
import { compileFastScript } from "./fs-parser.mjs";
|
|
2
|
-
|
|
3
|
-
export function normalizeFastScript(source, options = {}) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
next = next.replace(/\
|
|
82
|
-
next = next.replace(/\
|
|
83
|
-
next = next.replace(/\
|
|
84
|
-
next = next.replace(
|
|
85
|
-
|
|
86
|
-
next = next.replace(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
next = next.replace(/\
|
|
106
|
-
next = next.replace(/\
|
|
107
|
-
next = next.replace(
|
|
108
|
-
next = next.replace(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
next = next.replace(
|
|
114
|
-
next = next.replace(/\
|
|
115
|
-
next = next.replace(/\
|
|
116
|
-
next = next.replace(/\s+
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
import { compileFastScript } from "./fs-parser.mjs";
|
|
2
|
+
|
|
3
|
+
export function normalizeFastScript(source, options = {}) {
|
|
4
|
+
const prepared = stripTypeScriptHints(String(source ?? ""));
|
|
5
|
+
const { code } = compileFastScript(prepared, {
|
|
6
|
+
file: options.file || "",
|
|
7
|
+
mode: options.mode || "lenient",
|
|
8
|
+
recover: options.recover !== false,
|
|
9
|
+
inlineSourceMap: options.sourceMap === "inline",
|
|
10
|
+
});
|
|
11
|
+
return code;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function normalizeFastScriptWithMetadata(source, options = {}) {
|
|
15
|
+
const prepared = stripTypeScriptHints(String(source ?? ""));
|
|
16
|
+
return compileFastScript(prepared, {
|
|
17
|
+
file: options.file || "",
|
|
18
|
+
mode: options.mode || "lenient",
|
|
19
|
+
recover: options.recover !== false,
|
|
20
|
+
inlineSourceMap: options.sourceMap === "inline",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function stripTypeScriptHints(source) {
|
|
25
|
+
const lines = source.split(/\r?\n/);
|
|
26
|
+
const out = [];
|
|
27
|
+
let skippingBlock = false;
|
|
28
|
+
let blockDepth = 0;
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
31
|
+
const line = lines[i];
|
|
32
|
+
let next = line;
|
|
33
|
+
|
|
34
|
+
if (skippingBlock) {
|
|
35
|
+
const opens = (next.match(/{/g) || []).length;
|
|
36
|
+
const closes = (next.match(/}/g) || []).length;
|
|
37
|
+
blockDepth += opens - closes;
|
|
38
|
+
if (blockDepth <= 0) {
|
|
39
|
+
skippingBlock = false;
|
|
40
|
+
blockDepth = 0;
|
|
41
|
+
}
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (/^\\s*interface\\s+[A-Za-z_$][\\w$]*(?:\\s*<[^>]+>)?\\s*[{]/.test(next) || /^\s*enum\s+[A-Za-z_$][\w$]*\s*[{]/.test(next)) {
|
|
46
|
+
out.push(`// ${next.trim()} (removed by fastscript migrate)`);
|
|
47
|
+
skippingBlock = true;
|
|
48
|
+
const opens = (next.match(/{/g) || []).length;
|
|
49
|
+
const closes = (next.match(/}/g) || []).length;
|
|
50
|
+
blockDepth = Math.max(1, opens - closes);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (/^\\s*type\\s+[A-Za-z_$][\\w$]*(?:\\s*<[^>]+>)?\\s*=/.test(next)) {
|
|
55
|
+
out.push(`// ${next.trim()} (removed by fastscript migrate)`);
|
|
56
|
+
if (!next.includes(";") && next.includes("{")) {
|
|
57
|
+
skippingBlock = true;
|
|
58
|
+
const opens = (next.match(/{/g) || []).length;
|
|
59
|
+
const closes = (next.match(/}/g) || []).length;
|
|
60
|
+
blockDepth = Math.max(1, opens - closes);
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (/^\s*declare\s+(global|module|namespace)\b/.test(next)) {
|
|
66
|
+
out.push(`// ${next.trim()} (removed by fastscript migrate)`);
|
|
67
|
+
if (next.includes("{")) {
|
|
68
|
+
skippingBlock = true;
|
|
69
|
+
const opens = (next.match(/{/g) || []).length;
|
|
70
|
+
const closes = (next.match(/}/g) || []).length;
|
|
71
|
+
blockDepth = Math.max(1, opens - closes);
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (/^\s*declare\s+/.test(next)) {
|
|
77
|
+
out.push(`// ${next.trim()} (removed by fastscript migrate)`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
next = next.replace(/\bimport\s+type\b/g, "import");
|
|
82
|
+
next = next.replace(/\bexport\s+type\b/g, "export");
|
|
83
|
+
next = next.replace(/\btype\s+([A-Za-z_$][\w$]*)\s+as\s+/g, "$1 as ");
|
|
84
|
+
next = next.replace(/\b(?:public|private|protected|readonly|declare|override|abstract)\s+/g, "");
|
|
85
|
+
next = next.replace(/\s+implements\s+[A-Za-z_$][\w$<>\[\]\|&, ?.]+/g, "");
|
|
86
|
+
next = next.replace(/([A-Za-z_$][\w$]*)!([?:;=,\)])/g, "$1$2");
|
|
87
|
+
|
|
88
|
+
next = next.replace(
|
|
89
|
+
/^(\s*)(const|let|var)\s+([A-Za-z_$][\w$]*)\s*:\s*([^=;]+)([=;].*)$/,
|
|
90
|
+
"$1$2 $3 $5",
|
|
91
|
+
);
|
|
92
|
+
next = next.replace(
|
|
93
|
+
/^(\s*)(const|let|var)\s+([A-Za-z_$][\w$]*)\s*<[^>]+>\s*=\s*/,
|
|
94
|
+
"$1$2 $3 = ",
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
if (/\bfunction\b/.test(next) || /\bfn\b/.test(next) || /\)\s*=>/.test(next)) {
|
|
98
|
+
next = next.replace(/\(([^)]*)\)/, (_, params) => {
|
|
99
|
+
const cleaned = params.replace(
|
|
100
|
+
/([A-Za-z_$][\w$]*)(\?)?\s*:\s*([A-Za-z_$][\w$<>\[\]\|&, ?.:{}=]*)/g,
|
|
101
|
+
"$1",
|
|
102
|
+
);
|
|
103
|
+
return `(${cleaned})`;
|
|
104
|
+
});
|
|
105
|
+
next = next.replace(/\)\s*:\s*([A-Za-z_$][\w$<>\[\]\|&, ?.:{}=]*)\s*\{/g, ") {");
|
|
106
|
+
next = next.replace(/\)\s*:\s*([A-Za-z_$][\w$<>\[\]\|&, ?.:{}=]*)\s*=>/g, ") =>");
|
|
107
|
+
next = next.replace(/\bfunction\s+([A-Za-z_$][\w$]*)\s*<[^>]+>\s*\(/g, "function $1(");
|
|
108
|
+
next = next.replace(/\bfn\s+([A-Za-z_$][\w$]*)\s*<[^>]+>\s*\(/g, "fn $1(");
|
|
109
|
+
next = next.replace(/=\s*async\s*<[^>]+>\s*\(/g, "= async (");
|
|
110
|
+
next = next.replace(/=\s*<[^>]+>\s*\(/g, "= (");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
next = next.replace(/^\s*<([A-Za-z_$][\w$,\s]*)>\s*\(/, "(");
|
|
114
|
+
next = next.replace(/\)\s*=>\s*<[A-Za-z_$][\w$<>\[\]\|&, ?.]*>/g, ") =>");
|
|
115
|
+
next = next.replace(/\s+as\s+const\b/g, "");
|
|
116
|
+
next = next.replace(/\s+as\s+[A-Za-z_$][\w$<>\[\]\|&, ?.:{}=]*/g, "");
|
|
117
|
+
next = next.replace(/\sas\s+const\b/g, "");
|
|
118
|
+
next = next.replace(/\s+satisfies\s+[A-Za-z_$][\w$<>\[\]\|&, ?.]*/g, "");
|
|
119
|
+
out.push(next);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return out.join("\n");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|