@danielx/civet 0.6.37 → 0.6.39
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/README.md +1 -1
- package/dist/browser.js +188 -52
- package/dist/civet +68 -30
- package/dist/config.js +1 -1
- package/dist/esbuild.js +74 -23
- package/dist/main.js +181 -51
- package/dist/main.mjs +180 -51
- package/dist/rollup.js +74 -23
- package/dist/ts-diagnostic.js +152 -0
- package/dist/ts-diagnostic.mjs +114 -0
- package/dist/unplugin-shared.mjs +80 -24
- package/dist/unplugin.d.mts +2 -0
- package/dist/unplugin.d.ts +2 -0
- package/dist/unplugin.js +74 -23
- package/dist/vite.js +74 -23
- package/dist/webpack.js +74 -23
- package/package.json +8 -2
package/dist/esbuild.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(esbuild_exports);
|
|
|
37
37
|
// src/index.ts
|
|
38
38
|
var import_unplugin = require("unplugin");
|
|
39
39
|
var import_civet = __toESM(require("@danielx/civet"));
|
|
40
|
+
var import_ts_diagnostic = require("@danielx/civet/ts-diagnostic");
|
|
40
41
|
var fs = __toESM(require("fs"));
|
|
41
42
|
var import_path = __toESM(require("path"));
|
|
42
43
|
var import_typescript = __toESM(require("typescript"));
|
|
@@ -52,15 +53,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
52
53
|
if (options.dts && options.js) {
|
|
53
54
|
throw new Error("Can't have both `dts` and `js` be set to `true`.");
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
if (options.typecheck && options.js) {
|
|
57
|
+
throw new Error("Can't have both `typecheck` and `js` be set to `true`.");
|
|
58
|
+
}
|
|
59
|
+
const transpileToJS = options.js ?? !(options.dts || options.typecheck);
|
|
56
60
|
const outExt = options.outputExtension ?? (transpileToJS ? ".jsx" : ".tsx");
|
|
57
61
|
let fsMap = /* @__PURE__ */ new Map();
|
|
62
|
+
const sourceMaps = /* @__PURE__ */ new Map();
|
|
58
63
|
let compilerOptions;
|
|
59
64
|
return {
|
|
60
65
|
name: "unplugin-civet",
|
|
61
66
|
enforce: "pre",
|
|
62
67
|
async buildStart() {
|
|
63
|
-
if (options.dts) {
|
|
68
|
+
if (options.dts || options.typecheck) {
|
|
64
69
|
const configPath = import_typescript.default.findConfigFile(process.cwd(), import_typescript.default.sys.fileExists);
|
|
65
70
|
if (!configPath) {
|
|
66
71
|
throw new Error("Could not find 'tsconfig.json'");
|
|
@@ -86,7 +91,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
86
91
|
}
|
|
87
92
|
},
|
|
88
93
|
buildEnd() {
|
|
89
|
-
if (options.dts) {
|
|
94
|
+
if (options.dts || options.typecheck) {
|
|
90
95
|
const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), import_typescript.default);
|
|
91
96
|
const host = tsvfs.createVirtualCompilerHost(
|
|
92
97
|
system,
|
|
@@ -98,20 +103,55 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
98
103
|
options: compilerOptions,
|
|
99
104
|
host: host.compilerHost
|
|
100
105
|
});
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
const diagnostics = import_typescript.default.getPreEmitDiagnostics(program).map((diagnostic) => {
|
|
107
|
+
const file = diagnostic.file;
|
|
108
|
+
if (!file)
|
|
109
|
+
return diagnostic;
|
|
110
|
+
const sourceMap = sourceMaps.get(file.fileName);
|
|
111
|
+
if (!sourceMap)
|
|
112
|
+
return diagnostic;
|
|
113
|
+
const sourcemapLines = sourceMap.data.lines;
|
|
114
|
+
const range = (0, import_ts_diagnostic.remapRange)(
|
|
115
|
+
{
|
|
116
|
+
start: diagnostic.start || 0,
|
|
117
|
+
end: (diagnostic.start || 0) + (diagnostic.length || 1)
|
|
111
118
|
},
|
|
112
|
-
|
|
113
|
-
true
|
|
119
|
+
sourcemapLines
|
|
114
120
|
);
|
|
121
|
+
return {
|
|
122
|
+
...diagnostic,
|
|
123
|
+
messageText: (0, import_ts_diagnostic.flattenDiagnosticMessageText)(diagnostic.messageText),
|
|
124
|
+
length: diagnostic.length,
|
|
125
|
+
start: range.start
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
if (diagnostics.length > 0) {
|
|
129
|
+
console.error(
|
|
130
|
+
import_typescript.default.formatDiagnosticsWithColorAndContext(diagnostics, formatHost)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (options.dts) {
|
|
134
|
+
for (const file of fsMap.keys()) {
|
|
135
|
+
const sourceFile = program.getSourceFile(file);
|
|
136
|
+
program.emit(
|
|
137
|
+
sourceFile,
|
|
138
|
+
async (filePath, content) => {
|
|
139
|
+
const dir = import_path.default.dirname(filePath);
|
|
140
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
141
|
+
const pathFromDistDir = import_path.default.relative(
|
|
142
|
+
compilerOptions.outDir ?? process.cwd(),
|
|
143
|
+
filePath
|
|
144
|
+
);
|
|
145
|
+
this.emitFile({
|
|
146
|
+
source: content,
|
|
147
|
+
fileName: pathFromDistDir,
|
|
148
|
+
type: "asset"
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
void 0,
|
|
152
|
+
true
|
|
153
|
+
);
|
|
154
|
+
}
|
|
115
155
|
}
|
|
116
156
|
}
|
|
117
157
|
},
|
|
@@ -135,13 +175,20 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
135
175
|
return null;
|
|
136
176
|
const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
|
|
137
177
|
const code = await fs.promises.readFile(filename, "utf-8");
|
|
178
|
+
const compiled = import_civet.default.compile(code, {
|
|
179
|
+
// inlineMap: true,
|
|
180
|
+
filename: id,
|
|
181
|
+
js: transpileToJS,
|
|
182
|
+
sourceMap: true
|
|
183
|
+
});
|
|
184
|
+
sourceMaps.set(import_path.default.resolve(process.cwd(), id), compiled.sourceMap);
|
|
185
|
+
const jsonSourceMap = compiled.sourceMap.json(
|
|
186
|
+
import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
|
|
187
|
+
import_path.default.basename(id)
|
|
188
|
+
);
|
|
138
189
|
let transformed = {
|
|
139
|
-
code:
|
|
140
|
-
|
|
141
|
-
filename: id,
|
|
142
|
-
js: transpileToJS
|
|
143
|
-
}),
|
|
144
|
-
map: null
|
|
190
|
+
code: compiled.code,
|
|
191
|
+
map: jsonSourceMap
|
|
145
192
|
};
|
|
146
193
|
if (options.transformOutput)
|
|
147
194
|
transformed = await options.transformOutput(transformed.code, id);
|
|
@@ -150,8 +197,12 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
150
197
|
transform(code, id) {
|
|
151
198
|
if (!/\.civet\.tsx?$/.test(id))
|
|
152
199
|
return null;
|
|
153
|
-
if (options.dts) {
|
|
154
|
-
|
|
200
|
+
if (options.dts || options.typecheck) {
|
|
201
|
+
const resolved = import_path.default.resolve(process.cwd(), id);
|
|
202
|
+
fsMap.set(resolved, code);
|
|
203
|
+
const slash = resolved.replace(/\\/g, "/");
|
|
204
|
+
if (resolved !== slash)
|
|
205
|
+
fsMap.set(slash, code);
|
|
155
206
|
}
|
|
156
207
|
return null;
|
|
157
208
|
},
|
package/dist/main.js
CHANGED
|
@@ -892,6 +892,28 @@ var require_lib = __commonJS({
|
|
|
892
892
|
}
|
|
893
893
|
return expandedOps;
|
|
894
894
|
}
|
|
895
|
+
function handleThisPrivateShorthands(value) {
|
|
896
|
+
if (value.privateShorthand) {
|
|
897
|
+
value = value.children[1].children[1];
|
|
898
|
+
return [value, false];
|
|
899
|
+
}
|
|
900
|
+
if (value.type === "MemberExpression" || value.type === "CallExpression") {
|
|
901
|
+
let suppressPrefix = value.thisShorthand;
|
|
902
|
+
value = {
|
|
903
|
+
...value,
|
|
904
|
+
children: value.children.map((c, i) => {
|
|
905
|
+
if (i === 0) {
|
|
906
|
+
let s;
|
|
907
|
+
[c, s] = handleThisPrivateShorthands(c);
|
|
908
|
+
suppressPrefix || (suppressPrefix = s);
|
|
909
|
+
}
|
|
910
|
+
return c;
|
|
911
|
+
})
|
|
912
|
+
};
|
|
913
|
+
return [value, suppressPrefix];
|
|
914
|
+
}
|
|
915
|
+
return [value, value.thisShorthand];
|
|
916
|
+
}
|
|
895
917
|
function processCallMemberExpression(node) {
|
|
896
918
|
const { children } = node;
|
|
897
919
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -919,11 +941,15 @@ var require_lib = __commonJS({
|
|
|
919
941
|
throw new Error("Glob pattern cannot have method definition");
|
|
920
942
|
}
|
|
921
943
|
if (part.value && !["CallExpression", "MemberExpression", "Identifier"].includes(part.value.type)) {
|
|
922
|
-
throw new Error(
|
|
944
|
+
throw new Error(`Glob pattern must have call or member expression value, found ${JSON.stringify(part.value)}`);
|
|
923
945
|
}
|
|
946
|
+
let suppressPrefix = false;
|
|
924
947
|
let value = part.value ?? part.name;
|
|
925
948
|
const wValue = getTrimmingSpace(part.value);
|
|
926
|
-
value =
|
|
949
|
+
[value, suppressPrefix] = handleThisPrivateShorthands(value);
|
|
950
|
+
if (!suppressPrefix) {
|
|
951
|
+
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
952
|
+
}
|
|
927
953
|
if (wValue)
|
|
928
954
|
value.unshift(wValue);
|
|
929
955
|
if (part.type === "SpreadProperty") {
|
|
@@ -1137,14 +1163,14 @@ var require_lib = __commonJS({
|
|
|
1137
1163
|
chains.push(i);
|
|
1138
1164
|
} else if (lowerPrecedenceOps.includes(op.token)) {
|
|
1139
1165
|
processChains(op);
|
|
1140
|
-
first =
|
|
1166
|
+
first = void 0;
|
|
1141
1167
|
}
|
|
1142
1168
|
i++;
|
|
1143
1169
|
}
|
|
1144
1170
|
processChains(op);
|
|
1145
1171
|
return results;
|
|
1146
1172
|
function processChains(op2) {
|
|
1147
|
-
if (isRelationalOp(op2)) {
|
|
1173
|
+
if (first && isRelationalOp(op2)) {
|
|
1148
1174
|
first = expandExistence(first);
|
|
1149
1175
|
}
|
|
1150
1176
|
if (chains.length > 1) {
|
|
@@ -1153,7 +1179,7 @@ var require_lib = __commonJS({
|
|
|
1153
1179
|
results.push(" ", "&&", " ");
|
|
1154
1180
|
}
|
|
1155
1181
|
const binop = binops[index];
|
|
1156
|
-
let [
|
|
1182
|
+
let [, , , exp] = binop;
|
|
1157
1183
|
exp = binop[3] = expandExistence(exp);
|
|
1158
1184
|
let endIndex;
|
|
1159
1185
|
if (k < chains.length - 1) {
|
|
@@ -1166,10 +1192,13 @@ var require_lib = __commonJS({
|
|
|
1166
1192
|
return start = endIndex;
|
|
1167
1193
|
});
|
|
1168
1194
|
} else {
|
|
1169
|
-
|
|
1195
|
+
if (first) {
|
|
1196
|
+
results.push(first);
|
|
1197
|
+
}
|
|
1198
|
+
results.push(...binops.slice(start, i + 1).flat());
|
|
1170
1199
|
start = i + 1;
|
|
1171
1200
|
}
|
|
1172
|
-
|
|
1201
|
+
chains.length = 0;
|
|
1173
1202
|
}
|
|
1174
1203
|
function expandExistence(exp) {
|
|
1175
1204
|
const existence = isExistence(exp);
|
|
@@ -1251,6 +1280,23 @@ var require_lib = __commonJS({
|
|
|
1251
1280
|
}
|
|
1252
1281
|
}
|
|
1253
1282
|
}
|
|
1283
|
+
function replaceBlockExpression(node, child, replacement) {
|
|
1284
|
+
let found = false;
|
|
1285
|
+
const { expressions } = node;
|
|
1286
|
+
for (let i = 0, l = expressions.length; i < l; i++) {
|
|
1287
|
+
const statement = expressions[i];
|
|
1288
|
+
const [, s] = statement;
|
|
1289
|
+
if (s === child) {
|
|
1290
|
+
statement[1] = replacement;
|
|
1291
|
+
replacement.parent = node;
|
|
1292
|
+
found = true;
|
|
1293
|
+
break;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
if (!found) {
|
|
1297
|
+
throw new Error("Could not find child to replace");
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1254
1300
|
function findChildIndex(parent, child) {
|
|
1255
1301
|
const children = Array.isArray(parent) ? parent : parent.children;
|
|
1256
1302
|
const len = children.length;
|
|
@@ -2137,12 +2183,12 @@ var require_lib = __commonJS({
|
|
|
2137
2183
|
}
|
|
2138
2184
|
function processDeclarationConditions(node) {
|
|
2139
2185
|
gatherRecursiveAll(node, (n) => {
|
|
2140
|
-
return n.type === "IfStatement" || n.type === "IterationStatement";
|
|
2186
|
+
return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
|
|
2141
2187
|
}).forEach(processDeclarationConditionStatement);
|
|
2142
2188
|
}
|
|
2143
2189
|
function processDeclarationConditionStatement(s) {
|
|
2144
2190
|
const { condition } = s;
|
|
2145
|
-
if (!condition) {
|
|
2191
|
+
if (!condition?.expression) {
|
|
2146
2192
|
return;
|
|
2147
2193
|
}
|
|
2148
2194
|
processDeclarationCondition(condition.expression);
|
|
@@ -2183,6 +2229,27 @@ var require_lib = __commonJS({
|
|
|
2183
2229
|
updateParentPointers(newBlock, s);
|
|
2184
2230
|
break;
|
|
2185
2231
|
}
|
|
2232
|
+
case "SwitchStatement": {
|
|
2233
|
+
const { blockPrefix, ref: ref2 } = condition.expression;
|
|
2234
|
+
if (!blockPrefix) {
|
|
2235
|
+
return;
|
|
2236
|
+
}
|
|
2237
|
+
s.condition = {
|
|
2238
|
+
type: "ParenthesizedExpression",
|
|
2239
|
+
children: ["(", ref2, ")"],
|
|
2240
|
+
expression: ref2,
|
|
2241
|
+
parent: s
|
|
2242
|
+
};
|
|
2243
|
+
s.children[1] = s.condition;
|
|
2244
|
+
const block = blockWithPrefix([["", [{
|
|
2245
|
+
type: "Declaration",
|
|
2246
|
+
children: ["let ", ...condition.expression.children]
|
|
2247
|
+
}], ";"], ...blockPrefix], makeEmptyBlock());
|
|
2248
|
+
replaceBlockExpression(s.parent, s, block);
|
|
2249
|
+
block.expressions.push(["", s]);
|
|
2250
|
+
s.parent = block;
|
|
2251
|
+
break;
|
|
2252
|
+
}
|
|
2186
2253
|
}
|
|
2187
2254
|
}
|
|
2188
2255
|
function implicitFunctionBlock(f) {
|
|
@@ -2631,12 +2698,12 @@ var require_lib = __commonJS({
|
|
|
2631
2698
|
}
|
|
2632
2699
|
if (errors || !isPattern)
|
|
2633
2700
|
return;
|
|
2634
|
-
let {
|
|
2635
|
-
if (
|
|
2636
|
-
|
|
2701
|
+
let { condition } = s;
|
|
2702
|
+
if (condition.type === "ParenthesizedExpression") {
|
|
2703
|
+
condition = condition.expression;
|
|
2637
2704
|
}
|
|
2638
|
-
let hoistDec, refAssignment = [], ref = maybeRef(
|
|
2639
|
-
if (ref !==
|
|
2705
|
+
let hoistDec, refAssignment = [], ref = maybeRef(condition, "m");
|
|
2706
|
+
if (ref !== condition) {
|
|
2640
2707
|
hoistDec = {
|
|
2641
2708
|
type: "Declaration",
|
|
2642
2709
|
children: ["let ", ref],
|
|
@@ -2644,7 +2711,7 @@ var require_lib = __commonJS({
|
|
|
2644
2711
|
};
|
|
2645
2712
|
refAssignment = [{
|
|
2646
2713
|
type: "AssignmentExpression",
|
|
2647
|
-
children: [ref, " = ",
|
|
2714
|
+
children: [ref, " = ", condition]
|
|
2648
2715
|
}, ","];
|
|
2649
2716
|
}
|
|
2650
2717
|
let prev = [], root = prev;
|
|
@@ -2672,7 +2739,7 @@ var require_lib = __commonJS({
|
|
|
2672
2739
|
return conditionArray;
|
|
2673
2740
|
return [" || ", ...conditionArray];
|
|
2674
2741
|
});
|
|
2675
|
-
const
|
|
2742
|
+
const condition2 = {
|
|
2676
2743
|
type: "ParenthesizedExpression",
|
|
2677
2744
|
children: ["(", ...refAssignment, conditionExpression, ")"],
|
|
2678
2745
|
expression: conditionExpression
|
|
@@ -2707,7 +2774,7 @@ var require_lib = __commonJS({
|
|
|
2707
2774
|
next.push("\n", "else ");
|
|
2708
2775
|
prev.push(["", {
|
|
2709
2776
|
type: "IfStatement",
|
|
2710
|
-
children: ["if",
|
|
2777
|
+
children: ["if", condition2, block, next],
|
|
2711
2778
|
then: block,
|
|
2712
2779
|
else: next,
|
|
2713
2780
|
hoistDec
|
|
@@ -5360,7 +5427,8 @@ var require_parser = __commonJS({
|
|
|
5360
5427
|
type: "PropertyAccess",
|
|
5361
5428
|
name: id,
|
|
5362
5429
|
children: [".", id]
|
|
5363
|
-
}]
|
|
5430
|
+
}],
|
|
5431
|
+
thisShorthand: true
|
|
5364
5432
|
};
|
|
5365
5433
|
});
|
|
5366
5434
|
var ThisLiteral$2 = AtThis;
|
|
@@ -5381,7 +5449,8 @@ var require_parser = __commonJS({
|
|
|
5381
5449
|
type: "PropertyAccess",
|
|
5382
5450
|
name: id.name,
|
|
5383
5451
|
children: [".", id]
|
|
5384
|
-
}]
|
|
5452
|
+
}],
|
|
5453
|
+
privateShorthand: true
|
|
5385
5454
|
};
|
|
5386
5455
|
});
|
|
5387
5456
|
var PrivateThis$$ = [PrivateThis$0, PrivateThis$1];
|
|
@@ -7049,7 +7118,7 @@ var require_parser = __commonJS({
|
|
|
7049
7118
|
names: exp.names
|
|
7050
7119
|
};
|
|
7051
7120
|
});
|
|
7052
|
-
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)),
|
|
7121
|
+
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
|
|
7053
7122
|
var expMaybeSpread = $1;
|
|
7054
7123
|
if (expMaybeSpread) {
|
|
7055
7124
|
const [spread, exp] = expMaybeSpread;
|
|
@@ -7233,20 +7302,7 @@ var require_parser = __commonJS({
|
|
|
7233
7302
|
function ObjectPropertyDelimiter(ctx, state) {
|
|
7234
7303
|
return $EVENT_C(ctx, state, "ObjectPropertyDelimiter", ObjectPropertyDelimiter$$);
|
|
7235
7304
|
}
|
|
7236
|
-
var PropertyDefinition$0 = $TS($S($E(_),
|
|
7237
|
-
var ws = $1;
|
|
7238
|
-
var at = $2;
|
|
7239
|
-
var id = $3;
|
|
7240
|
-
const value = [at, ".", id];
|
|
7241
|
-
return {
|
|
7242
|
-
type: "Property",
|
|
7243
|
-
children: [ws, id, ": ", ...value],
|
|
7244
|
-
name: id,
|
|
7245
|
-
names: id.names,
|
|
7246
|
-
value
|
|
7247
|
-
};
|
|
7248
|
-
});
|
|
7249
|
-
var PropertyDefinition$1 = $TS($S($E(_), NamedProperty), function($skip, $loc, $0, $1, $2) {
|
|
7305
|
+
var PropertyDefinition$0 = $TS($S($E(_), NamedProperty), function($skip, $loc, $0, $1, $2) {
|
|
7250
7306
|
var ws = $1;
|
|
7251
7307
|
var prop = $2;
|
|
7252
7308
|
return {
|
|
@@ -7254,7 +7310,7 @@ var require_parser = __commonJS({
|
|
|
7254
7310
|
children: [ws, ...prop.children]
|
|
7255
7311
|
};
|
|
7256
7312
|
});
|
|
7257
|
-
var PropertyDefinition$
|
|
7313
|
+
var PropertyDefinition$1 = $TS($S($E(_), $TEXT($EXPECT($R6, "PropertyDefinition /[!+-]/")), PropertyName), function($skip, $loc, $0, $1, $2, $3) {
|
|
7258
7314
|
var ws = $1;
|
|
7259
7315
|
var toggle = $2;
|
|
7260
7316
|
var id = $3;
|
|
@@ -7267,7 +7323,7 @@ var require_parser = __commonJS({
|
|
|
7267
7323
|
value
|
|
7268
7324
|
};
|
|
7269
7325
|
});
|
|
7270
|
-
var PropertyDefinition$
|
|
7326
|
+
var PropertyDefinition$2 = $TS($S($E(_), MethodDefinition), function($skip, $loc, $0, $1, $2) {
|
|
7271
7327
|
var ws = $1;
|
|
7272
7328
|
var def = $2;
|
|
7273
7329
|
if (!def.block || def.block.empty)
|
|
@@ -7277,7 +7333,7 @@ var require_parser = __commonJS({
|
|
|
7277
7333
|
children: [ws, ...def.children]
|
|
7278
7334
|
};
|
|
7279
7335
|
});
|
|
7280
|
-
var PropertyDefinition$
|
|
7336
|
+
var PropertyDefinition$3 = $TS($S($E(_), DotDotDot, ExtendedExpression), function($skip, $loc, $0, $1, $2, $3) {
|
|
7281
7337
|
var ws = $1;
|
|
7282
7338
|
var dots = $2;
|
|
7283
7339
|
var exp = $3;
|
|
@@ -7289,7 +7345,7 @@ var require_parser = __commonJS({
|
|
|
7289
7345
|
value: exp
|
|
7290
7346
|
};
|
|
7291
7347
|
});
|
|
7292
|
-
var PropertyDefinition$
|
|
7348
|
+
var PropertyDefinition$4 = $TS($S($E(_), $N(EOS), CallExpression), function($skip, $loc, $0, $1, $2, $3) {
|
|
7293
7349
|
var ws = $1;
|
|
7294
7350
|
var value = $3;
|
|
7295
7351
|
switch (value.type) {
|
|
@@ -7348,16 +7404,18 @@ var require_parser = __commonJS({
|
|
|
7348
7404
|
if (!name)
|
|
7349
7405
|
return $skip;
|
|
7350
7406
|
}
|
|
7407
|
+
if (name[0] === "#")
|
|
7408
|
+
name = name.slice(1);
|
|
7351
7409
|
return {
|
|
7352
7410
|
type: "Property",
|
|
7353
7411
|
children: [ws, name, ": ", value],
|
|
7354
7412
|
name,
|
|
7355
|
-
value,
|
|
7356
7413
|
names: [],
|
|
7414
|
+
value,
|
|
7357
7415
|
hoistDec
|
|
7358
7416
|
};
|
|
7359
7417
|
});
|
|
7360
|
-
var PropertyDefinition$$ = [PropertyDefinition$0, PropertyDefinition$1, PropertyDefinition$2, PropertyDefinition$3, PropertyDefinition$4
|
|
7418
|
+
var PropertyDefinition$$ = [PropertyDefinition$0, PropertyDefinition$1, PropertyDefinition$2, PropertyDefinition$3, PropertyDefinition$4];
|
|
7361
7419
|
function PropertyDefinition(ctx, state) {
|
|
7362
7420
|
return $EVENT_C(ctx, state, "PropertyDefinition", PropertyDefinition$$);
|
|
7363
7421
|
}
|
|
@@ -8614,7 +8672,7 @@ var require_parser = __commonJS({
|
|
|
8614
8672
|
children: $0
|
|
8615
8673
|
};
|
|
8616
8674
|
});
|
|
8617
|
-
var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS),
|
|
8675
|
+
var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), ExpressionWithIndentedApplicationForbidden)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
8618
8676
|
var declaration = $3;
|
|
8619
8677
|
return {
|
|
8620
8678
|
declaration,
|
|
@@ -8721,7 +8779,7 @@ var require_parser = __commonJS({
|
|
|
8721
8779
|
return {
|
|
8722
8780
|
type: "SwitchStatement",
|
|
8723
8781
|
children: $0,
|
|
8724
|
-
|
|
8782
|
+
condition,
|
|
8725
8783
|
caseBlock
|
|
8726
8784
|
};
|
|
8727
8785
|
});
|
|
@@ -13417,6 +13475,7 @@ __export(main_exports, {
|
|
|
13417
13475
|
generate: () => generate_default,
|
|
13418
13476
|
isCompileError: () => isCompileError,
|
|
13419
13477
|
parse: () => parse,
|
|
13478
|
+
prune: () => prune,
|
|
13420
13479
|
util: () => util_exports
|
|
13421
13480
|
});
|
|
13422
13481
|
module.exports = __toCommonJS(main_exports);
|
|
@@ -13585,7 +13644,10 @@ var SourceMap = function(sourceString) {
|
|
|
13585
13644
|
sources: [srcFileName],
|
|
13586
13645
|
mappings: this.renderMappings(),
|
|
13587
13646
|
names: [],
|
|
13588
|
-
sourcesContent: [sourceString]
|
|
13647
|
+
sourcesContent: [sourceString],
|
|
13648
|
+
toString: function() {
|
|
13649
|
+
return JSON.stringify(this);
|
|
13650
|
+
}
|
|
13589
13651
|
};
|
|
13590
13652
|
},
|
|
13591
13653
|
updateSourceMap: function(outputStr, inputPos) {
|
|
@@ -13929,15 +13991,55 @@ function compile(src, options) {
|
|
|
13929
13991
|
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
13930
13992
|
options.parseOptions.coffeeCompat = true;
|
|
13931
13993
|
}
|
|
13994
|
+
;
|
|
13995
|
+
const { hits, trace, noCache } = options;
|
|
13932
13996
|
let events;
|
|
13933
|
-
if (!
|
|
13934
|
-
events = makeCache(
|
|
13997
|
+
if (!noCache) {
|
|
13998
|
+
events = makeCache({
|
|
13999
|
+
hits: !!hits,
|
|
14000
|
+
trace: !!trace
|
|
14001
|
+
});
|
|
14002
|
+
}
|
|
14003
|
+
let ast;
|
|
14004
|
+
try {
|
|
14005
|
+
parse.config = options.parseOptions || {};
|
|
14006
|
+
ast = prune(parse(src, {
|
|
14007
|
+
filename,
|
|
14008
|
+
events
|
|
14009
|
+
}));
|
|
14010
|
+
} finally {
|
|
14011
|
+
if (hits || trace) {
|
|
14012
|
+
import("fs").then(function({ writeFileSync }) {
|
|
14013
|
+
let ref;
|
|
14014
|
+
if ((ref = events?.meta) && "logs" in ref) {
|
|
14015
|
+
const { logs } = ref;
|
|
14016
|
+
if (trace) {
|
|
14017
|
+
writeFileSync(trace, logs.join("\n"));
|
|
14018
|
+
}
|
|
14019
|
+
}
|
|
14020
|
+
if (hits) {
|
|
14021
|
+
let ref1;
|
|
14022
|
+
if (ref1 = events?.meta.hits) {
|
|
14023
|
+
const hitData = ref1;
|
|
14024
|
+
let total = 0;
|
|
14025
|
+
const data = [...hitData.entries()];
|
|
14026
|
+
const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
|
|
14027
|
+
total += v;
|
|
14028
|
+
return `${k}: ${v}`;
|
|
14029
|
+
}).join("\n");
|
|
14030
|
+
const hitSummary = `Total: ${total}
|
|
14031
|
+
|
|
14032
|
+
${counts}`;
|
|
14033
|
+
return writeFileSync(hits, hitSummary);
|
|
14034
|
+
}
|
|
14035
|
+
;
|
|
14036
|
+
return;
|
|
14037
|
+
}
|
|
14038
|
+
;
|
|
14039
|
+
return;
|
|
14040
|
+
});
|
|
14041
|
+
}
|
|
13935
14042
|
}
|
|
13936
|
-
parse.config = options.parseOptions || {};
|
|
13937
|
-
const ast = prune(parse(src, {
|
|
13938
|
-
filename,
|
|
13939
|
-
events
|
|
13940
|
-
}));
|
|
13941
14043
|
if (options.ast) {
|
|
13942
14044
|
return ast;
|
|
13943
14045
|
}
|
|
@@ -13960,22 +14062,45 @@ function compile(src, options) {
|
|
|
13960
14062
|
}
|
|
13961
14063
|
return result;
|
|
13962
14064
|
}
|
|
13963
|
-
function makeCache() {
|
|
14065
|
+
function makeCache({ hits, trace } = {}) {
|
|
14066
|
+
const meta = {};
|
|
14067
|
+
let hitCount;
|
|
14068
|
+
if (hits) {
|
|
14069
|
+
hitCount = /* @__PURE__ */ new Map();
|
|
14070
|
+
meta.hits = hitCount;
|
|
14071
|
+
}
|
|
14072
|
+
let logs;
|
|
14073
|
+
if (trace) {
|
|
14074
|
+
logs = [];
|
|
14075
|
+
meta.logs = logs;
|
|
14076
|
+
}
|
|
13964
14077
|
const stateCache = new StateCache();
|
|
13965
14078
|
let getStateKey = null;
|
|
14079
|
+
const stack = [];
|
|
13966
14080
|
const events = {
|
|
14081
|
+
meta,
|
|
13967
14082
|
enter: function(ruleName, state) {
|
|
14083
|
+
if (hits) {
|
|
14084
|
+
hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
|
|
14085
|
+
}
|
|
13968
14086
|
if (uncacheable.has(ruleName)) {
|
|
13969
14087
|
return;
|
|
13970
14088
|
}
|
|
13971
14089
|
;
|
|
13972
14090
|
const key = [ruleName, state.pos, ...getStateKey()];
|
|
13973
14091
|
if (stateCache.has(key)) {
|
|
14092
|
+
if (trace) {
|
|
14093
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
|
|
14094
|
+
}
|
|
13974
14095
|
const result = stateCache.get(key);
|
|
13975
14096
|
return {
|
|
13976
14097
|
cache: result ? { ...result } : void 0
|
|
13977
14098
|
};
|
|
13978
14099
|
}
|
|
14100
|
+
if (trace) {
|
|
14101
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
|
|
14102
|
+
stack.push(ruleName);
|
|
14103
|
+
}
|
|
13979
14104
|
return;
|
|
13980
14105
|
},
|
|
13981
14106
|
exit: function(ruleName, state, result) {
|
|
@@ -13993,6 +14118,10 @@ function makeCache() {
|
|
|
13993
14118
|
if (parse.config.verbose && result) {
|
|
13994
14119
|
console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
|
|
13995
14120
|
}
|
|
14121
|
+
if (trace) {
|
|
14122
|
+
stack.pop();
|
|
14123
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
|
|
14124
|
+
}
|
|
13996
14125
|
return;
|
|
13997
14126
|
}
|
|
13998
14127
|
};
|
|
@@ -14009,5 +14138,6 @@ var main_default = { parse, generate: generate_default, util: util_exports, comp
|
|
|
14009
14138
|
generate,
|
|
14010
14139
|
isCompileError,
|
|
14011
14140
|
parse,
|
|
14141
|
+
prune,
|
|
14012
14142
|
util
|
|
14013
14143
|
});
|