@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/README.md
CHANGED
|
@@ -26,7 +26,7 @@ The modern way to write TypeScript.
|
|
|
26
26
|
[Gulp](integration/gulp),
|
|
27
27
|
[ESM module resolution](source/esm.civet),
|
|
28
28
|
[CJS](register.js),
|
|
29
|
-
[Bun](source/bun-civet.
|
|
29
|
+
[Bun](source/bun-civet.civet)
|
|
30
30
|
- Starter templates for [Solid](https://github.com/orenelbaum/solid-civet-template) and [Solid Start](https://github.com/orenelbaum/solid-start-civet-template)
|
|
31
31
|
|
|
32
32
|
Quickstart Guide
|
package/dist/browser.js
CHANGED
|
@@ -7,7 +7,14 @@ var Civet = (() => {
|
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var
|
|
10
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
12
|
+
}) : x)(function(x) {
|
|
13
|
+
if (typeof require !== "undefined")
|
|
14
|
+
return require.apply(this, arguments);
|
|
15
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
16
|
+
});
|
|
17
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
11
18
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
19
|
};
|
|
13
20
|
var __export = (target, all) => {
|
|
@@ -893,6 +900,28 @@ ${input.slice(result.pos)}
|
|
|
893
900
|
}
|
|
894
901
|
return expandedOps;
|
|
895
902
|
}
|
|
903
|
+
function handleThisPrivateShorthands(value) {
|
|
904
|
+
if (value.privateShorthand) {
|
|
905
|
+
value = value.children[1].children[1];
|
|
906
|
+
return [value, false];
|
|
907
|
+
}
|
|
908
|
+
if (value.type === "MemberExpression" || value.type === "CallExpression") {
|
|
909
|
+
let suppressPrefix = value.thisShorthand;
|
|
910
|
+
value = {
|
|
911
|
+
...value,
|
|
912
|
+
children: value.children.map((c, i) => {
|
|
913
|
+
if (i === 0) {
|
|
914
|
+
let s;
|
|
915
|
+
[c, s] = handleThisPrivateShorthands(c);
|
|
916
|
+
suppressPrefix || (suppressPrefix = s);
|
|
917
|
+
}
|
|
918
|
+
return c;
|
|
919
|
+
})
|
|
920
|
+
};
|
|
921
|
+
return [value, suppressPrefix];
|
|
922
|
+
}
|
|
923
|
+
return [value, value.thisShorthand];
|
|
924
|
+
}
|
|
896
925
|
function processCallMemberExpression(node) {
|
|
897
926
|
const { children } = node;
|
|
898
927
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -920,11 +949,15 @@ ${input.slice(result.pos)}
|
|
|
920
949
|
throw new Error("Glob pattern cannot have method definition");
|
|
921
950
|
}
|
|
922
951
|
if (part.value && !["CallExpression", "MemberExpression", "Identifier"].includes(part.value.type)) {
|
|
923
|
-
throw new Error(
|
|
952
|
+
throw new Error(`Glob pattern must have call or member expression value, found ${JSON.stringify(part.value)}`);
|
|
924
953
|
}
|
|
954
|
+
let suppressPrefix = false;
|
|
925
955
|
let value = part.value ?? part.name;
|
|
926
956
|
const wValue = getTrimmingSpace(part.value);
|
|
927
|
-
value =
|
|
957
|
+
[value, suppressPrefix] = handleThisPrivateShorthands(value);
|
|
958
|
+
if (!suppressPrefix) {
|
|
959
|
+
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
960
|
+
}
|
|
928
961
|
if (wValue)
|
|
929
962
|
value.unshift(wValue);
|
|
930
963
|
if (part.type === "SpreadProperty") {
|
|
@@ -1138,14 +1171,14 @@ ${input.slice(result.pos)}
|
|
|
1138
1171
|
chains.push(i);
|
|
1139
1172
|
} else if (lowerPrecedenceOps.includes(op.token)) {
|
|
1140
1173
|
processChains(op);
|
|
1141
|
-
first =
|
|
1174
|
+
first = void 0;
|
|
1142
1175
|
}
|
|
1143
1176
|
i++;
|
|
1144
1177
|
}
|
|
1145
1178
|
processChains(op);
|
|
1146
1179
|
return results;
|
|
1147
1180
|
function processChains(op2) {
|
|
1148
|
-
if (isRelationalOp(op2)) {
|
|
1181
|
+
if (first && isRelationalOp(op2)) {
|
|
1149
1182
|
first = expandExistence(first);
|
|
1150
1183
|
}
|
|
1151
1184
|
if (chains.length > 1) {
|
|
@@ -1154,7 +1187,7 @@ ${input.slice(result.pos)}
|
|
|
1154
1187
|
results.push(" ", "&&", " ");
|
|
1155
1188
|
}
|
|
1156
1189
|
const binop = binops[index];
|
|
1157
|
-
let [
|
|
1190
|
+
let [, , , exp] = binop;
|
|
1158
1191
|
exp = binop[3] = expandExistence(exp);
|
|
1159
1192
|
let endIndex;
|
|
1160
1193
|
if (k < chains.length - 1) {
|
|
@@ -1167,10 +1200,13 @@ ${input.slice(result.pos)}
|
|
|
1167
1200
|
return start = endIndex;
|
|
1168
1201
|
});
|
|
1169
1202
|
} else {
|
|
1170
|
-
|
|
1203
|
+
if (first) {
|
|
1204
|
+
results.push(first);
|
|
1205
|
+
}
|
|
1206
|
+
results.push(...binops.slice(start, i + 1).flat());
|
|
1171
1207
|
start = i + 1;
|
|
1172
1208
|
}
|
|
1173
|
-
|
|
1209
|
+
chains.length = 0;
|
|
1174
1210
|
}
|
|
1175
1211
|
function expandExistence(exp) {
|
|
1176
1212
|
const existence = isExistence(exp);
|
|
@@ -1252,6 +1288,23 @@ ${input.slice(result.pos)}
|
|
|
1252
1288
|
}
|
|
1253
1289
|
}
|
|
1254
1290
|
}
|
|
1291
|
+
function replaceBlockExpression(node, child, replacement) {
|
|
1292
|
+
let found = false;
|
|
1293
|
+
const { expressions } = node;
|
|
1294
|
+
for (let i = 0, l = expressions.length; i < l; i++) {
|
|
1295
|
+
const statement = expressions[i];
|
|
1296
|
+
const [, s] = statement;
|
|
1297
|
+
if (s === child) {
|
|
1298
|
+
statement[1] = replacement;
|
|
1299
|
+
replacement.parent = node;
|
|
1300
|
+
found = true;
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
if (!found) {
|
|
1305
|
+
throw new Error("Could not find child to replace");
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1255
1308
|
function findChildIndex(parent, child) {
|
|
1256
1309
|
const children = Array.isArray(parent) ? parent : parent.children;
|
|
1257
1310
|
const len = children.length;
|
|
@@ -2138,12 +2191,12 @@ ${input.slice(result.pos)}
|
|
|
2138
2191
|
}
|
|
2139
2192
|
function processDeclarationConditions(node) {
|
|
2140
2193
|
gatherRecursiveAll(node, (n) => {
|
|
2141
|
-
return n.type === "IfStatement" || n.type === "IterationStatement";
|
|
2194
|
+
return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
|
|
2142
2195
|
}).forEach(processDeclarationConditionStatement);
|
|
2143
2196
|
}
|
|
2144
2197
|
function processDeclarationConditionStatement(s) {
|
|
2145
2198
|
const { condition } = s;
|
|
2146
|
-
if (!condition) {
|
|
2199
|
+
if (!condition?.expression) {
|
|
2147
2200
|
return;
|
|
2148
2201
|
}
|
|
2149
2202
|
processDeclarationCondition(condition.expression);
|
|
@@ -2184,6 +2237,27 @@ ${input.slice(result.pos)}
|
|
|
2184
2237
|
updateParentPointers(newBlock, s);
|
|
2185
2238
|
break;
|
|
2186
2239
|
}
|
|
2240
|
+
case "SwitchStatement": {
|
|
2241
|
+
const { blockPrefix, ref: ref2 } = condition.expression;
|
|
2242
|
+
if (!blockPrefix) {
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2245
|
+
s.condition = {
|
|
2246
|
+
type: "ParenthesizedExpression",
|
|
2247
|
+
children: ["(", ref2, ")"],
|
|
2248
|
+
expression: ref2,
|
|
2249
|
+
parent: s
|
|
2250
|
+
};
|
|
2251
|
+
s.children[1] = s.condition;
|
|
2252
|
+
const block = blockWithPrefix([["", [{
|
|
2253
|
+
type: "Declaration",
|
|
2254
|
+
children: ["let ", ...condition.expression.children]
|
|
2255
|
+
}], ";"], ...blockPrefix], makeEmptyBlock());
|
|
2256
|
+
replaceBlockExpression(s.parent, s, block);
|
|
2257
|
+
block.expressions.push(["", s]);
|
|
2258
|
+
s.parent = block;
|
|
2259
|
+
break;
|
|
2260
|
+
}
|
|
2187
2261
|
}
|
|
2188
2262
|
}
|
|
2189
2263
|
function implicitFunctionBlock(f) {
|
|
@@ -2632,12 +2706,12 @@ ${input.slice(result.pos)}
|
|
|
2632
2706
|
}
|
|
2633
2707
|
if (errors || !isPattern)
|
|
2634
2708
|
return;
|
|
2635
|
-
let {
|
|
2636
|
-
if (
|
|
2637
|
-
|
|
2709
|
+
let { condition } = s;
|
|
2710
|
+
if (condition.type === "ParenthesizedExpression") {
|
|
2711
|
+
condition = condition.expression;
|
|
2638
2712
|
}
|
|
2639
|
-
let hoistDec, refAssignment = [], ref = maybeRef(
|
|
2640
|
-
if (ref !==
|
|
2713
|
+
let hoistDec, refAssignment = [], ref = maybeRef(condition, "m");
|
|
2714
|
+
if (ref !== condition) {
|
|
2641
2715
|
hoistDec = {
|
|
2642
2716
|
type: "Declaration",
|
|
2643
2717
|
children: ["let ", ref],
|
|
@@ -2645,7 +2719,7 @@ ${input.slice(result.pos)}
|
|
|
2645
2719
|
};
|
|
2646
2720
|
refAssignment = [{
|
|
2647
2721
|
type: "AssignmentExpression",
|
|
2648
|
-
children: [ref, " = ",
|
|
2722
|
+
children: [ref, " = ", condition]
|
|
2649
2723
|
}, ","];
|
|
2650
2724
|
}
|
|
2651
2725
|
let prev = [], root = prev;
|
|
@@ -2673,7 +2747,7 @@ ${input.slice(result.pos)}
|
|
|
2673
2747
|
return conditionArray;
|
|
2674
2748
|
return [" || ", ...conditionArray];
|
|
2675
2749
|
});
|
|
2676
|
-
const
|
|
2750
|
+
const condition2 = {
|
|
2677
2751
|
type: "ParenthesizedExpression",
|
|
2678
2752
|
children: ["(", ...refAssignment, conditionExpression, ")"],
|
|
2679
2753
|
expression: conditionExpression
|
|
@@ -2708,7 +2782,7 @@ ${input.slice(result.pos)}
|
|
|
2708
2782
|
next.push("\n", "else ");
|
|
2709
2783
|
prev.push(["", {
|
|
2710
2784
|
type: "IfStatement",
|
|
2711
|
-
children: ["if",
|
|
2785
|
+
children: ["if", condition2, block, next],
|
|
2712
2786
|
then: block,
|
|
2713
2787
|
else: next,
|
|
2714
2788
|
hoistDec
|
|
@@ -5361,7 +5435,8 @@ ${input.slice(result.pos)}
|
|
|
5361
5435
|
type: "PropertyAccess",
|
|
5362
5436
|
name: id,
|
|
5363
5437
|
children: [".", id]
|
|
5364
|
-
}]
|
|
5438
|
+
}],
|
|
5439
|
+
thisShorthand: true
|
|
5365
5440
|
};
|
|
5366
5441
|
});
|
|
5367
5442
|
var ThisLiteral$2 = AtThis;
|
|
@@ -5382,7 +5457,8 @@ ${input.slice(result.pos)}
|
|
|
5382
5457
|
type: "PropertyAccess",
|
|
5383
5458
|
name: id.name,
|
|
5384
5459
|
children: [".", id]
|
|
5385
|
-
}]
|
|
5460
|
+
}],
|
|
5461
|
+
privateShorthand: true
|
|
5386
5462
|
};
|
|
5387
5463
|
});
|
|
5388
5464
|
var PrivateThis$$ = [PrivateThis$0, PrivateThis$1];
|
|
@@ -7050,7 +7126,7 @@ ${input.slice(result.pos)}
|
|
|
7050
7126
|
names: exp.names
|
|
7051
7127
|
};
|
|
7052
7128
|
});
|
|
7053
|
-
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)),
|
|
7129
|
+
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
|
|
7054
7130
|
var expMaybeSpread = $1;
|
|
7055
7131
|
if (expMaybeSpread) {
|
|
7056
7132
|
const [spread, exp] = expMaybeSpread;
|
|
@@ -7234,20 +7310,7 @@ ${input.slice(result.pos)}
|
|
|
7234
7310
|
function ObjectPropertyDelimiter(ctx, state) {
|
|
7235
7311
|
return $EVENT_C(ctx, state, "ObjectPropertyDelimiter", ObjectPropertyDelimiter$$);
|
|
7236
7312
|
}
|
|
7237
|
-
var PropertyDefinition$0 = $TS($S($E(_),
|
|
7238
|
-
var ws = $1;
|
|
7239
|
-
var at = $2;
|
|
7240
|
-
var id = $3;
|
|
7241
|
-
const value = [at, ".", id];
|
|
7242
|
-
return {
|
|
7243
|
-
type: "Property",
|
|
7244
|
-
children: [ws, id, ": ", ...value],
|
|
7245
|
-
name: id,
|
|
7246
|
-
names: id.names,
|
|
7247
|
-
value
|
|
7248
|
-
};
|
|
7249
|
-
});
|
|
7250
|
-
var PropertyDefinition$1 = $TS($S($E(_), NamedProperty), function($skip, $loc, $0, $1, $2) {
|
|
7313
|
+
var PropertyDefinition$0 = $TS($S($E(_), NamedProperty), function($skip, $loc, $0, $1, $2) {
|
|
7251
7314
|
var ws = $1;
|
|
7252
7315
|
var prop = $2;
|
|
7253
7316
|
return {
|
|
@@ -7255,7 +7318,7 @@ ${input.slice(result.pos)}
|
|
|
7255
7318
|
children: [ws, ...prop.children]
|
|
7256
7319
|
};
|
|
7257
7320
|
});
|
|
7258
|
-
var PropertyDefinition$
|
|
7321
|
+
var PropertyDefinition$1 = $TS($S($E(_), $TEXT($EXPECT($R6, "PropertyDefinition /[!+-]/")), PropertyName), function($skip, $loc, $0, $1, $2, $3) {
|
|
7259
7322
|
var ws = $1;
|
|
7260
7323
|
var toggle = $2;
|
|
7261
7324
|
var id = $3;
|
|
@@ -7268,7 +7331,7 @@ ${input.slice(result.pos)}
|
|
|
7268
7331
|
value
|
|
7269
7332
|
};
|
|
7270
7333
|
});
|
|
7271
|
-
var PropertyDefinition$
|
|
7334
|
+
var PropertyDefinition$2 = $TS($S($E(_), MethodDefinition), function($skip, $loc, $0, $1, $2) {
|
|
7272
7335
|
var ws = $1;
|
|
7273
7336
|
var def = $2;
|
|
7274
7337
|
if (!def.block || def.block.empty)
|
|
@@ -7278,7 +7341,7 @@ ${input.slice(result.pos)}
|
|
|
7278
7341
|
children: [ws, ...def.children]
|
|
7279
7342
|
};
|
|
7280
7343
|
});
|
|
7281
|
-
var PropertyDefinition$
|
|
7344
|
+
var PropertyDefinition$3 = $TS($S($E(_), DotDotDot, ExtendedExpression), function($skip, $loc, $0, $1, $2, $3) {
|
|
7282
7345
|
var ws = $1;
|
|
7283
7346
|
var dots = $2;
|
|
7284
7347
|
var exp = $3;
|
|
@@ -7290,7 +7353,7 @@ ${input.slice(result.pos)}
|
|
|
7290
7353
|
value: exp
|
|
7291
7354
|
};
|
|
7292
7355
|
});
|
|
7293
|
-
var PropertyDefinition$
|
|
7356
|
+
var PropertyDefinition$4 = $TS($S($E(_), $N(EOS), CallExpression), function($skip, $loc, $0, $1, $2, $3) {
|
|
7294
7357
|
var ws = $1;
|
|
7295
7358
|
var value = $3;
|
|
7296
7359
|
switch (value.type) {
|
|
@@ -7349,16 +7412,18 @@ ${input.slice(result.pos)}
|
|
|
7349
7412
|
if (!name)
|
|
7350
7413
|
return $skip;
|
|
7351
7414
|
}
|
|
7415
|
+
if (name[0] === "#")
|
|
7416
|
+
name = name.slice(1);
|
|
7352
7417
|
return {
|
|
7353
7418
|
type: "Property",
|
|
7354
7419
|
children: [ws, name, ": ", value],
|
|
7355
7420
|
name,
|
|
7356
|
-
value,
|
|
7357
7421
|
names: [],
|
|
7422
|
+
value,
|
|
7358
7423
|
hoistDec
|
|
7359
7424
|
};
|
|
7360
7425
|
});
|
|
7361
|
-
var PropertyDefinition$$ = [PropertyDefinition$0, PropertyDefinition$1, PropertyDefinition$2, PropertyDefinition$3, PropertyDefinition$4
|
|
7426
|
+
var PropertyDefinition$$ = [PropertyDefinition$0, PropertyDefinition$1, PropertyDefinition$2, PropertyDefinition$3, PropertyDefinition$4];
|
|
7362
7427
|
function PropertyDefinition(ctx, state) {
|
|
7363
7428
|
return $EVENT_C(ctx, state, "PropertyDefinition", PropertyDefinition$$);
|
|
7364
7429
|
}
|
|
@@ -8615,7 +8680,7 @@ ${input.slice(result.pos)}
|
|
|
8615
8680
|
children: $0
|
|
8616
8681
|
};
|
|
8617
8682
|
});
|
|
8618
|
-
var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS),
|
|
8683
|
+
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) {
|
|
8619
8684
|
var declaration = $3;
|
|
8620
8685
|
return {
|
|
8621
8686
|
declaration,
|
|
@@ -8722,7 +8787,7 @@ ${input.slice(result.pos)}
|
|
|
8722
8787
|
return {
|
|
8723
8788
|
type: "SwitchStatement",
|
|
8724
8789
|
children: $0,
|
|
8725
|
-
|
|
8790
|
+
condition,
|
|
8726
8791
|
caseBlock
|
|
8727
8792
|
};
|
|
8728
8793
|
});
|
|
@@ -13418,6 +13483,7 @@ ${input.slice(result.pos)}
|
|
|
13418
13483
|
generate: () => generate_default,
|
|
13419
13484
|
isCompileError: () => isCompileError,
|
|
13420
13485
|
parse: () => parse,
|
|
13486
|
+
prune: () => prune,
|
|
13421
13487
|
util: () => util_exports
|
|
13422
13488
|
});
|
|
13423
13489
|
var import_parser = __toESM(require_parser());
|
|
@@ -13585,7 +13651,10 @@ ${input.slice(result.pos)}
|
|
|
13585
13651
|
sources: [srcFileName],
|
|
13586
13652
|
mappings: this.renderMappings(),
|
|
13587
13653
|
names: [],
|
|
13588
|
-
sourcesContent: [sourceString]
|
|
13654
|
+
sourcesContent: [sourceString],
|
|
13655
|
+
toString: function() {
|
|
13656
|
+
return JSON.stringify(this);
|
|
13657
|
+
}
|
|
13589
13658
|
};
|
|
13590
13659
|
},
|
|
13591
13660
|
updateSourceMap: function(outputStr, inputPos) {
|
|
@@ -13929,15 +13998,55 @@ ${input.slice(result.pos)}
|
|
|
13929
13998
|
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
13930
13999
|
options.parseOptions.coffeeCompat = true;
|
|
13931
14000
|
}
|
|
14001
|
+
;
|
|
14002
|
+
const { hits, trace, noCache } = options;
|
|
13932
14003
|
let events;
|
|
13933
|
-
if (!
|
|
13934
|
-
events = makeCache(
|
|
14004
|
+
if (!noCache) {
|
|
14005
|
+
events = makeCache({
|
|
14006
|
+
hits: !!hits,
|
|
14007
|
+
trace: !!trace
|
|
14008
|
+
});
|
|
14009
|
+
}
|
|
14010
|
+
let ast;
|
|
14011
|
+
try {
|
|
14012
|
+
parse.config = options.parseOptions || {};
|
|
14013
|
+
ast = prune(parse(src, {
|
|
14014
|
+
filename,
|
|
14015
|
+
events
|
|
14016
|
+
}));
|
|
14017
|
+
} finally {
|
|
14018
|
+
if (hits || trace) {
|
|
14019
|
+
import("fs").then(function({ writeFileSync }) {
|
|
14020
|
+
let ref;
|
|
14021
|
+
if ((ref = events?.meta) && "logs" in ref) {
|
|
14022
|
+
const { logs } = ref;
|
|
14023
|
+
if (trace) {
|
|
14024
|
+
writeFileSync(trace, logs.join("\n"));
|
|
14025
|
+
}
|
|
14026
|
+
}
|
|
14027
|
+
if (hits) {
|
|
14028
|
+
let ref1;
|
|
14029
|
+
if (ref1 = events?.meta.hits) {
|
|
14030
|
+
const hitData = ref1;
|
|
14031
|
+
let total = 0;
|
|
14032
|
+
const data = [...hitData.entries()];
|
|
14033
|
+
const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
|
|
14034
|
+
total += v;
|
|
14035
|
+
return `${k}: ${v}`;
|
|
14036
|
+
}).join("\n");
|
|
14037
|
+
const hitSummary = `Total: ${total}
|
|
14038
|
+
|
|
14039
|
+
${counts}`;
|
|
14040
|
+
return writeFileSync(hits, hitSummary);
|
|
14041
|
+
}
|
|
14042
|
+
;
|
|
14043
|
+
return;
|
|
14044
|
+
}
|
|
14045
|
+
;
|
|
14046
|
+
return;
|
|
14047
|
+
});
|
|
14048
|
+
}
|
|
13935
14049
|
}
|
|
13936
|
-
parse.config = options.parseOptions || {};
|
|
13937
|
-
const ast = prune(parse(src, {
|
|
13938
|
-
filename,
|
|
13939
|
-
events
|
|
13940
|
-
}));
|
|
13941
14050
|
if (options.ast) {
|
|
13942
14051
|
return ast;
|
|
13943
14052
|
}
|
|
@@ -13960,22 +14069,45 @@ ${input.slice(result.pos)}
|
|
|
13960
14069
|
}
|
|
13961
14070
|
return result;
|
|
13962
14071
|
}
|
|
13963
|
-
function makeCache() {
|
|
14072
|
+
function makeCache({ hits, trace } = {}) {
|
|
14073
|
+
const meta = {};
|
|
14074
|
+
let hitCount;
|
|
14075
|
+
if (hits) {
|
|
14076
|
+
hitCount = /* @__PURE__ */ new Map();
|
|
14077
|
+
meta.hits = hitCount;
|
|
14078
|
+
}
|
|
14079
|
+
let logs;
|
|
14080
|
+
if (trace) {
|
|
14081
|
+
logs = [];
|
|
14082
|
+
meta.logs = logs;
|
|
14083
|
+
}
|
|
13964
14084
|
const stateCache = new StateCache();
|
|
13965
14085
|
let getStateKey = null;
|
|
14086
|
+
const stack = [];
|
|
13966
14087
|
const events = {
|
|
14088
|
+
meta,
|
|
13967
14089
|
enter: function(ruleName, state) {
|
|
14090
|
+
if (hits) {
|
|
14091
|
+
hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
|
|
14092
|
+
}
|
|
13968
14093
|
if (uncacheable.has(ruleName)) {
|
|
13969
14094
|
return;
|
|
13970
14095
|
}
|
|
13971
14096
|
;
|
|
13972
14097
|
const key = [ruleName, state.pos, ...getStateKey()];
|
|
13973
14098
|
if (stateCache.has(key)) {
|
|
14099
|
+
if (trace) {
|
|
14100
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
|
|
14101
|
+
}
|
|
13974
14102
|
const result = stateCache.get(key);
|
|
13975
14103
|
return {
|
|
13976
14104
|
cache: result ? { ...result } : void 0
|
|
13977
14105
|
};
|
|
13978
14106
|
}
|
|
14107
|
+
if (trace) {
|
|
14108
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
|
|
14109
|
+
stack.push(ruleName);
|
|
14110
|
+
}
|
|
13979
14111
|
return;
|
|
13980
14112
|
},
|
|
13981
14113
|
exit: function(ruleName, state, result) {
|
|
@@ -13993,6 +14125,10 @@ ${input.slice(result.pos)}
|
|
|
13993
14125
|
if (parse.config.verbose && result) {
|
|
13994
14126
|
console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
|
|
13995
14127
|
}
|
|
14128
|
+
if (trace) {
|
|
14129
|
+
stack.pop();
|
|
14130
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
|
|
14131
|
+
}
|
|
13996
14132
|
return;
|
|
13997
14133
|
}
|
|
13998
14134
|
};
|
package/dist/civet
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
3
25
|
|
|
4
26
|
// source/cli.civet
|
|
5
27
|
var import_main = require("./main.js");
|
|
6
28
|
var import_config = require("./config.js");
|
|
7
|
-
var
|
|
29
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
30
|
+
var import_path = __toESM(require("path"));
|
|
8
31
|
var version;
|
|
9
|
-
var encoding;
|
|
10
|
-
var fs;
|
|
11
|
-
var path;
|
|
12
32
|
var parseArgs;
|
|
13
33
|
var readFiles;
|
|
14
34
|
var repl;
|
|
15
35
|
var cli;
|
|
16
36
|
var indexOf = [].indexOf;
|
|
17
|
-
({ prune } = import_main.generate);
|
|
18
37
|
version = function() {
|
|
19
38
|
return require("../package.json").version;
|
|
20
39
|
};
|
|
@@ -60,9 +79,7 @@ if (process.argv.includes("--help")) {
|
|
|
60
79
|
`);
|
|
61
80
|
process.exit(0);
|
|
62
81
|
}
|
|
63
|
-
encoding = "utf8";
|
|
64
|
-
fs = require("fs/promises");
|
|
65
|
-
path = require("path");
|
|
82
|
+
var encoding = "utf8";
|
|
66
83
|
parseArgs = function(args) {
|
|
67
84
|
var options, filenames, scriptArgs, i, endOfArgs, arg;
|
|
68
85
|
options = {};
|
|
@@ -136,6 +153,14 @@ parseArgs = function(args) {
|
|
|
136
153
|
options.js = true;
|
|
137
154
|
break;
|
|
138
155
|
}
|
|
156
|
+
case "--hits": {
|
|
157
|
+
options.hits = args[++i];
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "--trace": {
|
|
161
|
+
options.trace = args[++i];
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
139
164
|
case "--": {
|
|
140
165
|
endOfArgs(++i);
|
|
141
166
|
break;
|
|
@@ -167,7 +192,7 @@ readFiles = async function* (filenames, options) {
|
|
|
167
192
|
process.stdin.setEncoding(encoding);
|
|
168
193
|
filename = "<stdin>";
|
|
169
194
|
try {
|
|
170
|
-
filename = await
|
|
195
|
+
filename = await import_promises.default.realpath("/dev/stdin");
|
|
171
196
|
} catch (e) {
|
|
172
197
|
}
|
|
173
198
|
if (process.stdin.isTTY) {
|
|
@@ -196,7 +221,7 @@ readFiles = async function* (filenames, options) {
|
|
|
196
221
|
})()).join("");
|
|
197
222
|
}
|
|
198
223
|
} else {
|
|
199
|
-
content = await
|
|
224
|
+
content = await import_promises.default.readFile(filename, { encoding });
|
|
200
225
|
}
|
|
201
226
|
results1.push(yield { filename, content, stdin });
|
|
202
227
|
} catch (error) {
|
|
@@ -284,7 +309,7 @@ repl = function(options) {
|
|
|
284
309
|
});
|
|
285
310
|
};
|
|
286
311
|
cli = async function() {
|
|
287
|
-
var argv, filenames, scriptArgs, options, filename, error, content, stdin, output, outputPath, outputFilename, optionsPath, stat, esm, child;
|
|
312
|
+
var argv, filenames, scriptArgs, options, filename, error, content, stdin, output, outputPath, outputFilename, optionsPath, stat, esm, execArgv, debugRe, isDebug, child;
|
|
288
313
|
argv = process.argv;
|
|
289
314
|
({ filenames, scriptArgs, options } = parseArgs(argv.slice(2)));
|
|
290
315
|
if (options.config !== false) {
|
|
@@ -330,7 +355,7 @@ cli = async function() {
|
|
|
330
355
|
if (stdin && !options.output || options.output === "-") {
|
|
331
356
|
results3.push(process.stdout.write(output));
|
|
332
357
|
} else {
|
|
333
|
-
outputPath =
|
|
358
|
+
outputPath = import_path.default.parse(filename);
|
|
334
359
|
delete outputPath.base;
|
|
335
360
|
if (options.js) {
|
|
336
361
|
outputPath.ext += ".jsx";
|
|
@@ -338,13 +363,13 @@ cli = async function() {
|
|
|
338
363
|
outputPath.ext += ".tsx";
|
|
339
364
|
}
|
|
340
365
|
if (options.output) {
|
|
341
|
-
optionsPath =
|
|
366
|
+
optionsPath = import_path.default.parse(options.output);
|
|
342
367
|
try {
|
|
343
|
-
stat = await
|
|
368
|
+
stat = await import_promises.default.stat(options.output);
|
|
344
369
|
} catch {
|
|
345
370
|
stat = null;
|
|
346
371
|
}
|
|
347
|
-
if (stat?.isDirectory() || options.output.endsWith(
|
|
372
|
+
if (stat?.isDirectory() || options.output.endsWith(import_path.default.sep) || options.output.endsWith("/")) {
|
|
348
373
|
outputPath.dir = options.output;
|
|
349
374
|
} else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
|
|
350
375
|
outputPath.ext = optionsPath.base;
|
|
@@ -356,11 +381,11 @@ cli = async function() {
|
|
|
356
381
|
}
|
|
357
382
|
}
|
|
358
383
|
if (outputPath.dir) {
|
|
359
|
-
|
|
384
|
+
import_promises.default.mkdir(outputPath.dir, { recursive: true });
|
|
360
385
|
}
|
|
361
|
-
outputFilename =
|
|
386
|
+
outputFilename = import_path.default.format(outputPath);
|
|
362
387
|
try {
|
|
363
|
-
results3.push(await
|
|
388
|
+
results3.push(await import_promises.default.writeFile(outputFilename, output));
|
|
364
389
|
} catch (error2) {
|
|
365
390
|
console.error(`${outputFilename} failed to write:`);
|
|
366
391
|
results3.push(console.error(error2));
|
|
@@ -372,32 +397,45 @@ cli = async function() {
|
|
|
372
397
|
if (stdin) {
|
|
373
398
|
filename = `.stdin-${process.pid}.civet`;
|
|
374
399
|
try {
|
|
375
|
-
await
|
|
400
|
+
await import_promises.default.writeFile(filename, content, { encoding });
|
|
376
401
|
} catch (e) {
|
|
377
402
|
console.error(`Could not write ${filename} for Civet ESM mode:`);
|
|
378
403
|
console.error(e);
|
|
379
404
|
process.exit(1);
|
|
380
405
|
}
|
|
381
406
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
await fs.unlink(filename);
|
|
407
|
+
;
|
|
408
|
+
const { fork } = await import("child_process");
|
|
409
|
+
execArgv = ["--loader", "@danielx/civet/esm"];
|
|
410
|
+
debugRe = /--debug|--inspect/;
|
|
411
|
+
isDebug = typeof v8debug === "object" || debugRe.test(process.execArgv.join(" ")) || debugRe.test(process.env.NODE_OPTIONS);
|
|
412
|
+
if (process.env.NODE_OPTIONS) {
|
|
413
|
+
execArgv.push(process.env.NODE_OPTIONS);
|
|
390
414
|
}
|
|
391
|
-
|
|
415
|
+
if (isDebug) {
|
|
416
|
+
execArgv.push("--inspect=" + (process.debugPort + 1));
|
|
417
|
+
}
|
|
418
|
+
child = fork(filename, [
|
|
419
|
+
...scriptArgs
|
|
420
|
+
], {
|
|
421
|
+
execArgv,
|
|
422
|
+
stdio: "inherit"
|
|
423
|
+
});
|
|
424
|
+
results3.push(child.on("exit", async function(code) {
|
|
425
|
+
if (stdin) {
|
|
426
|
+
await import_promises.default.unlink(filename);
|
|
427
|
+
}
|
|
428
|
+
return process.exit(code ?? 1);
|
|
429
|
+
}));
|
|
392
430
|
} else {
|
|
393
431
|
require("../register.js");
|
|
394
432
|
try {
|
|
395
|
-
module.filename = await
|
|
433
|
+
module.filename = await import_promises.default.realpath(filename);
|
|
396
434
|
} catch {
|
|
397
435
|
module.filename = filename;
|
|
398
436
|
}
|
|
399
437
|
process.argv = ["civet", module.filename, ...scriptArgs];
|
|
400
|
-
module.paths = require("module")._nodeModulePaths(
|
|
438
|
+
module.paths = require("module")._nodeModulePaths(import_path.default.dirname(module.filename));
|
|
401
439
|
try {
|
|
402
440
|
results3.push(module._compile(output, module.filename));
|
|
403
441
|
} catch (error2) {
|
package/dist/config.js
CHANGED
|
@@ -84,7 +84,7 @@ async function loadConfig(path2) {
|
|
|
84
84
|
const js = (0, import_main.compile)(config, { js: true });
|
|
85
85
|
let exports;
|
|
86
86
|
try {
|
|
87
|
-
exports = await import(`data:text/javascript,${js}`);
|
|
87
|
+
exports = await import(`data:text/javascript,${encodeURIComponent(js)}`);
|
|
88
88
|
} catch (e) {
|
|
89
89
|
console.error("Error loading config file", path2, e);
|
|
90
90
|
}
|