@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/main.mjs
CHANGED
|
@@ -890,6 +890,28 @@ var require_lib = __commonJS({
|
|
|
890
890
|
}
|
|
891
891
|
return expandedOps;
|
|
892
892
|
}
|
|
893
|
+
function handleThisPrivateShorthands(value) {
|
|
894
|
+
if (value.privateShorthand) {
|
|
895
|
+
value = value.children[1].children[1];
|
|
896
|
+
return [value, false];
|
|
897
|
+
}
|
|
898
|
+
if (value.type === "MemberExpression" || value.type === "CallExpression") {
|
|
899
|
+
let suppressPrefix = value.thisShorthand;
|
|
900
|
+
value = {
|
|
901
|
+
...value,
|
|
902
|
+
children: value.children.map((c, i) => {
|
|
903
|
+
if (i === 0) {
|
|
904
|
+
let s;
|
|
905
|
+
[c, s] = handleThisPrivateShorthands(c);
|
|
906
|
+
suppressPrefix || (suppressPrefix = s);
|
|
907
|
+
}
|
|
908
|
+
return c;
|
|
909
|
+
})
|
|
910
|
+
};
|
|
911
|
+
return [value, suppressPrefix];
|
|
912
|
+
}
|
|
913
|
+
return [value, value.thisShorthand];
|
|
914
|
+
}
|
|
893
915
|
function processCallMemberExpression(node) {
|
|
894
916
|
const { children } = node;
|
|
895
917
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -917,11 +939,15 @@ var require_lib = __commonJS({
|
|
|
917
939
|
throw new Error("Glob pattern cannot have method definition");
|
|
918
940
|
}
|
|
919
941
|
if (part.value && !["CallExpression", "MemberExpression", "Identifier"].includes(part.value.type)) {
|
|
920
|
-
throw new Error(
|
|
942
|
+
throw new Error(`Glob pattern must have call or member expression value, found ${JSON.stringify(part.value)}`);
|
|
921
943
|
}
|
|
944
|
+
let suppressPrefix = false;
|
|
922
945
|
let value = part.value ?? part.name;
|
|
923
946
|
const wValue = getTrimmingSpace(part.value);
|
|
924
|
-
value =
|
|
947
|
+
[value, suppressPrefix] = handleThisPrivateShorthands(value);
|
|
948
|
+
if (!suppressPrefix) {
|
|
949
|
+
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
950
|
+
}
|
|
925
951
|
if (wValue)
|
|
926
952
|
value.unshift(wValue);
|
|
927
953
|
if (part.type === "SpreadProperty") {
|
|
@@ -1135,14 +1161,14 @@ var require_lib = __commonJS({
|
|
|
1135
1161
|
chains.push(i);
|
|
1136
1162
|
} else if (lowerPrecedenceOps.includes(op.token)) {
|
|
1137
1163
|
processChains(op);
|
|
1138
|
-
first =
|
|
1164
|
+
first = void 0;
|
|
1139
1165
|
}
|
|
1140
1166
|
i++;
|
|
1141
1167
|
}
|
|
1142
1168
|
processChains(op);
|
|
1143
1169
|
return results;
|
|
1144
1170
|
function processChains(op2) {
|
|
1145
|
-
if (isRelationalOp(op2)) {
|
|
1171
|
+
if (first && isRelationalOp(op2)) {
|
|
1146
1172
|
first = expandExistence(first);
|
|
1147
1173
|
}
|
|
1148
1174
|
if (chains.length > 1) {
|
|
@@ -1151,7 +1177,7 @@ var require_lib = __commonJS({
|
|
|
1151
1177
|
results.push(" ", "&&", " ");
|
|
1152
1178
|
}
|
|
1153
1179
|
const binop = binops[index];
|
|
1154
|
-
let [
|
|
1180
|
+
let [, , , exp] = binop;
|
|
1155
1181
|
exp = binop[3] = expandExistence(exp);
|
|
1156
1182
|
let endIndex;
|
|
1157
1183
|
if (k < chains.length - 1) {
|
|
@@ -1164,10 +1190,13 @@ var require_lib = __commonJS({
|
|
|
1164
1190
|
return start = endIndex;
|
|
1165
1191
|
});
|
|
1166
1192
|
} else {
|
|
1167
|
-
|
|
1193
|
+
if (first) {
|
|
1194
|
+
results.push(first);
|
|
1195
|
+
}
|
|
1196
|
+
results.push(...binops.slice(start, i + 1).flat());
|
|
1168
1197
|
start = i + 1;
|
|
1169
1198
|
}
|
|
1170
|
-
|
|
1199
|
+
chains.length = 0;
|
|
1171
1200
|
}
|
|
1172
1201
|
function expandExistence(exp) {
|
|
1173
1202
|
const existence = isExistence(exp);
|
|
@@ -1249,6 +1278,23 @@ var require_lib = __commonJS({
|
|
|
1249
1278
|
}
|
|
1250
1279
|
}
|
|
1251
1280
|
}
|
|
1281
|
+
function replaceBlockExpression(node, child, replacement) {
|
|
1282
|
+
let found = false;
|
|
1283
|
+
const { expressions } = node;
|
|
1284
|
+
for (let i = 0, l = expressions.length; i < l; i++) {
|
|
1285
|
+
const statement = expressions[i];
|
|
1286
|
+
const [, s] = statement;
|
|
1287
|
+
if (s === child) {
|
|
1288
|
+
statement[1] = replacement;
|
|
1289
|
+
replacement.parent = node;
|
|
1290
|
+
found = true;
|
|
1291
|
+
break;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
if (!found) {
|
|
1295
|
+
throw new Error("Could not find child to replace");
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1252
1298
|
function findChildIndex(parent, child) {
|
|
1253
1299
|
const children = Array.isArray(parent) ? parent : parent.children;
|
|
1254
1300
|
const len = children.length;
|
|
@@ -2135,12 +2181,12 @@ var require_lib = __commonJS({
|
|
|
2135
2181
|
}
|
|
2136
2182
|
function processDeclarationConditions(node) {
|
|
2137
2183
|
gatherRecursiveAll(node, (n) => {
|
|
2138
|
-
return n.type === "IfStatement" || n.type === "IterationStatement";
|
|
2184
|
+
return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
|
|
2139
2185
|
}).forEach(processDeclarationConditionStatement);
|
|
2140
2186
|
}
|
|
2141
2187
|
function processDeclarationConditionStatement(s) {
|
|
2142
2188
|
const { condition } = s;
|
|
2143
|
-
if (!condition) {
|
|
2189
|
+
if (!condition?.expression) {
|
|
2144
2190
|
return;
|
|
2145
2191
|
}
|
|
2146
2192
|
processDeclarationCondition(condition.expression);
|
|
@@ -2181,6 +2227,27 @@ var require_lib = __commonJS({
|
|
|
2181
2227
|
updateParentPointers(newBlock, s);
|
|
2182
2228
|
break;
|
|
2183
2229
|
}
|
|
2230
|
+
case "SwitchStatement": {
|
|
2231
|
+
const { blockPrefix, ref: ref2 } = condition.expression;
|
|
2232
|
+
if (!blockPrefix) {
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2235
|
+
s.condition = {
|
|
2236
|
+
type: "ParenthesizedExpression",
|
|
2237
|
+
children: ["(", ref2, ")"],
|
|
2238
|
+
expression: ref2,
|
|
2239
|
+
parent: s
|
|
2240
|
+
};
|
|
2241
|
+
s.children[1] = s.condition;
|
|
2242
|
+
const block = blockWithPrefix([["", [{
|
|
2243
|
+
type: "Declaration",
|
|
2244
|
+
children: ["let ", ...condition.expression.children]
|
|
2245
|
+
}], ";"], ...blockPrefix], makeEmptyBlock());
|
|
2246
|
+
replaceBlockExpression(s.parent, s, block);
|
|
2247
|
+
block.expressions.push(["", s]);
|
|
2248
|
+
s.parent = block;
|
|
2249
|
+
break;
|
|
2250
|
+
}
|
|
2184
2251
|
}
|
|
2185
2252
|
}
|
|
2186
2253
|
function implicitFunctionBlock(f) {
|
|
@@ -2629,12 +2696,12 @@ var require_lib = __commonJS({
|
|
|
2629
2696
|
}
|
|
2630
2697
|
if (errors || !isPattern)
|
|
2631
2698
|
return;
|
|
2632
|
-
let {
|
|
2633
|
-
if (
|
|
2634
|
-
|
|
2699
|
+
let { condition } = s;
|
|
2700
|
+
if (condition.type === "ParenthesizedExpression") {
|
|
2701
|
+
condition = condition.expression;
|
|
2635
2702
|
}
|
|
2636
|
-
let hoistDec, refAssignment = [], ref = maybeRef(
|
|
2637
|
-
if (ref !==
|
|
2703
|
+
let hoistDec, refAssignment = [], ref = maybeRef(condition, "m");
|
|
2704
|
+
if (ref !== condition) {
|
|
2638
2705
|
hoistDec = {
|
|
2639
2706
|
type: "Declaration",
|
|
2640
2707
|
children: ["let ", ref],
|
|
@@ -2642,7 +2709,7 @@ var require_lib = __commonJS({
|
|
|
2642
2709
|
};
|
|
2643
2710
|
refAssignment = [{
|
|
2644
2711
|
type: "AssignmentExpression",
|
|
2645
|
-
children: [ref, " = ",
|
|
2712
|
+
children: [ref, " = ", condition]
|
|
2646
2713
|
}, ","];
|
|
2647
2714
|
}
|
|
2648
2715
|
let prev = [], root = prev;
|
|
@@ -2670,7 +2737,7 @@ var require_lib = __commonJS({
|
|
|
2670
2737
|
return conditionArray;
|
|
2671
2738
|
return [" || ", ...conditionArray];
|
|
2672
2739
|
});
|
|
2673
|
-
const
|
|
2740
|
+
const condition2 = {
|
|
2674
2741
|
type: "ParenthesizedExpression",
|
|
2675
2742
|
children: ["(", ...refAssignment, conditionExpression, ")"],
|
|
2676
2743
|
expression: conditionExpression
|
|
@@ -2705,7 +2772,7 @@ var require_lib = __commonJS({
|
|
|
2705
2772
|
next.push("\n", "else ");
|
|
2706
2773
|
prev.push(["", {
|
|
2707
2774
|
type: "IfStatement",
|
|
2708
|
-
children: ["if",
|
|
2775
|
+
children: ["if", condition2, block, next],
|
|
2709
2776
|
then: block,
|
|
2710
2777
|
else: next,
|
|
2711
2778
|
hoistDec
|
|
@@ -5358,7 +5425,8 @@ var require_parser = __commonJS({
|
|
|
5358
5425
|
type: "PropertyAccess",
|
|
5359
5426
|
name: id,
|
|
5360
5427
|
children: [".", id]
|
|
5361
|
-
}]
|
|
5428
|
+
}],
|
|
5429
|
+
thisShorthand: true
|
|
5362
5430
|
};
|
|
5363
5431
|
});
|
|
5364
5432
|
var ThisLiteral$2 = AtThis;
|
|
@@ -5379,7 +5447,8 @@ var require_parser = __commonJS({
|
|
|
5379
5447
|
type: "PropertyAccess",
|
|
5380
5448
|
name: id.name,
|
|
5381
5449
|
children: [".", id]
|
|
5382
|
-
}]
|
|
5450
|
+
}],
|
|
5451
|
+
privateShorthand: true
|
|
5383
5452
|
};
|
|
5384
5453
|
});
|
|
5385
5454
|
var PrivateThis$$ = [PrivateThis$0, PrivateThis$1];
|
|
@@ -7047,7 +7116,7 @@ var require_parser = __commonJS({
|
|
|
7047
7116
|
names: exp.names
|
|
7048
7117
|
};
|
|
7049
7118
|
});
|
|
7050
|
-
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)),
|
|
7119
|
+
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
|
|
7051
7120
|
var expMaybeSpread = $1;
|
|
7052
7121
|
if (expMaybeSpread) {
|
|
7053
7122
|
const [spread, exp] = expMaybeSpread;
|
|
@@ -7231,20 +7300,7 @@ var require_parser = __commonJS({
|
|
|
7231
7300
|
function ObjectPropertyDelimiter(ctx, state) {
|
|
7232
7301
|
return $EVENT_C(ctx, state, "ObjectPropertyDelimiter", ObjectPropertyDelimiter$$);
|
|
7233
7302
|
}
|
|
7234
|
-
var PropertyDefinition$0 = $TS($S($E(_),
|
|
7235
|
-
var ws = $1;
|
|
7236
|
-
var at = $2;
|
|
7237
|
-
var id = $3;
|
|
7238
|
-
const value = [at, ".", id];
|
|
7239
|
-
return {
|
|
7240
|
-
type: "Property",
|
|
7241
|
-
children: [ws, id, ": ", ...value],
|
|
7242
|
-
name: id,
|
|
7243
|
-
names: id.names,
|
|
7244
|
-
value
|
|
7245
|
-
};
|
|
7246
|
-
});
|
|
7247
|
-
var PropertyDefinition$1 = $TS($S($E(_), NamedProperty), function($skip, $loc, $0, $1, $2) {
|
|
7303
|
+
var PropertyDefinition$0 = $TS($S($E(_), NamedProperty), function($skip, $loc, $0, $1, $2) {
|
|
7248
7304
|
var ws = $1;
|
|
7249
7305
|
var prop = $2;
|
|
7250
7306
|
return {
|
|
@@ -7252,7 +7308,7 @@ var require_parser = __commonJS({
|
|
|
7252
7308
|
children: [ws, ...prop.children]
|
|
7253
7309
|
};
|
|
7254
7310
|
});
|
|
7255
|
-
var PropertyDefinition$
|
|
7311
|
+
var PropertyDefinition$1 = $TS($S($E(_), $TEXT($EXPECT($R6, "PropertyDefinition /[!+-]/")), PropertyName), function($skip, $loc, $0, $1, $2, $3) {
|
|
7256
7312
|
var ws = $1;
|
|
7257
7313
|
var toggle = $2;
|
|
7258
7314
|
var id = $3;
|
|
@@ -7265,7 +7321,7 @@ var require_parser = __commonJS({
|
|
|
7265
7321
|
value
|
|
7266
7322
|
};
|
|
7267
7323
|
});
|
|
7268
|
-
var PropertyDefinition$
|
|
7324
|
+
var PropertyDefinition$2 = $TS($S($E(_), MethodDefinition), function($skip, $loc, $0, $1, $2) {
|
|
7269
7325
|
var ws = $1;
|
|
7270
7326
|
var def = $2;
|
|
7271
7327
|
if (!def.block || def.block.empty)
|
|
@@ -7275,7 +7331,7 @@ var require_parser = __commonJS({
|
|
|
7275
7331
|
children: [ws, ...def.children]
|
|
7276
7332
|
};
|
|
7277
7333
|
});
|
|
7278
|
-
var PropertyDefinition$
|
|
7334
|
+
var PropertyDefinition$3 = $TS($S($E(_), DotDotDot, ExtendedExpression), function($skip, $loc, $0, $1, $2, $3) {
|
|
7279
7335
|
var ws = $1;
|
|
7280
7336
|
var dots = $2;
|
|
7281
7337
|
var exp = $3;
|
|
@@ -7287,7 +7343,7 @@ var require_parser = __commonJS({
|
|
|
7287
7343
|
value: exp
|
|
7288
7344
|
};
|
|
7289
7345
|
});
|
|
7290
|
-
var PropertyDefinition$
|
|
7346
|
+
var PropertyDefinition$4 = $TS($S($E(_), $N(EOS), CallExpression), function($skip, $loc, $0, $1, $2, $3) {
|
|
7291
7347
|
var ws = $1;
|
|
7292
7348
|
var value = $3;
|
|
7293
7349
|
switch (value.type) {
|
|
@@ -7346,16 +7402,18 @@ var require_parser = __commonJS({
|
|
|
7346
7402
|
if (!name)
|
|
7347
7403
|
return $skip;
|
|
7348
7404
|
}
|
|
7405
|
+
if (name[0] === "#")
|
|
7406
|
+
name = name.slice(1);
|
|
7349
7407
|
return {
|
|
7350
7408
|
type: "Property",
|
|
7351
7409
|
children: [ws, name, ": ", value],
|
|
7352
7410
|
name,
|
|
7353
|
-
value,
|
|
7354
7411
|
names: [],
|
|
7412
|
+
value,
|
|
7355
7413
|
hoistDec
|
|
7356
7414
|
};
|
|
7357
7415
|
});
|
|
7358
|
-
var PropertyDefinition$$ = [PropertyDefinition$0, PropertyDefinition$1, PropertyDefinition$2, PropertyDefinition$3, PropertyDefinition$4
|
|
7416
|
+
var PropertyDefinition$$ = [PropertyDefinition$0, PropertyDefinition$1, PropertyDefinition$2, PropertyDefinition$3, PropertyDefinition$4];
|
|
7359
7417
|
function PropertyDefinition(ctx, state) {
|
|
7360
7418
|
return $EVENT_C(ctx, state, "PropertyDefinition", PropertyDefinition$$);
|
|
7361
7419
|
}
|
|
@@ -8612,7 +8670,7 @@ var require_parser = __commonJS({
|
|
|
8612
8670
|
children: $0
|
|
8613
8671
|
};
|
|
8614
8672
|
});
|
|
8615
|
-
var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS),
|
|
8673
|
+
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) {
|
|
8616
8674
|
var declaration = $3;
|
|
8617
8675
|
return {
|
|
8618
8676
|
declaration,
|
|
@@ -8719,7 +8777,7 @@ var require_parser = __commonJS({
|
|
|
8719
8777
|
return {
|
|
8720
8778
|
type: "SwitchStatement",
|
|
8721
8779
|
children: $0,
|
|
8722
|
-
|
|
8780
|
+
condition,
|
|
8723
8781
|
caseBlock
|
|
8724
8782
|
};
|
|
8725
8783
|
});
|
|
@@ -13573,7 +13631,10 @@ var SourceMap = function(sourceString) {
|
|
|
13573
13631
|
sources: [srcFileName],
|
|
13574
13632
|
mappings: this.renderMappings(),
|
|
13575
13633
|
names: [],
|
|
13576
|
-
sourcesContent: [sourceString]
|
|
13634
|
+
sourcesContent: [sourceString],
|
|
13635
|
+
toString: function() {
|
|
13636
|
+
return JSON.stringify(this);
|
|
13637
|
+
}
|
|
13577
13638
|
};
|
|
13578
13639
|
},
|
|
13579
13640
|
updateSourceMap: function(outputStr, inputPos) {
|
|
@@ -13917,15 +13978,55 @@ function compile(src, options) {
|
|
|
13917
13978
|
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
13918
13979
|
options.parseOptions.coffeeCompat = true;
|
|
13919
13980
|
}
|
|
13981
|
+
;
|
|
13982
|
+
const { hits, trace, noCache } = options;
|
|
13920
13983
|
let events;
|
|
13921
|
-
if (!
|
|
13922
|
-
events = makeCache(
|
|
13984
|
+
if (!noCache) {
|
|
13985
|
+
events = makeCache({
|
|
13986
|
+
hits: !!hits,
|
|
13987
|
+
trace: !!trace
|
|
13988
|
+
});
|
|
13989
|
+
}
|
|
13990
|
+
let ast;
|
|
13991
|
+
try {
|
|
13992
|
+
parse.config = options.parseOptions || {};
|
|
13993
|
+
ast = prune(parse(src, {
|
|
13994
|
+
filename,
|
|
13995
|
+
events
|
|
13996
|
+
}));
|
|
13997
|
+
} finally {
|
|
13998
|
+
if (hits || trace) {
|
|
13999
|
+
import("fs").then(function({ writeFileSync }) {
|
|
14000
|
+
let ref;
|
|
14001
|
+
if ((ref = events?.meta) && "logs" in ref) {
|
|
14002
|
+
const { logs } = ref;
|
|
14003
|
+
if (trace) {
|
|
14004
|
+
writeFileSync(trace, logs.join("\n"));
|
|
14005
|
+
}
|
|
14006
|
+
}
|
|
14007
|
+
if (hits) {
|
|
14008
|
+
let ref1;
|
|
14009
|
+
if (ref1 = events?.meta.hits) {
|
|
14010
|
+
const hitData = ref1;
|
|
14011
|
+
let total = 0;
|
|
14012
|
+
const data = [...hitData.entries()];
|
|
14013
|
+
const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
|
|
14014
|
+
total += v;
|
|
14015
|
+
return `${k}: ${v}`;
|
|
14016
|
+
}).join("\n");
|
|
14017
|
+
const hitSummary = `Total: ${total}
|
|
14018
|
+
|
|
14019
|
+
${counts}`;
|
|
14020
|
+
return writeFileSync(hits, hitSummary);
|
|
14021
|
+
}
|
|
14022
|
+
;
|
|
14023
|
+
return;
|
|
14024
|
+
}
|
|
14025
|
+
;
|
|
14026
|
+
return;
|
|
14027
|
+
});
|
|
14028
|
+
}
|
|
13923
14029
|
}
|
|
13924
|
-
parse.config = options.parseOptions || {};
|
|
13925
|
-
const ast = prune(parse(src, {
|
|
13926
|
-
filename,
|
|
13927
|
-
events
|
|
13928
|
-
}));
|
|
13929
14030
|
if (options.ast) {
|
|
13930
14031
|
return ast;
|
|
13931
14032
|
}
|
|
@@ -13948,22 +14049,45 @@ function compile(src, options) {
|
|
|
13948
14049
|
}
|
|
13949
14050
|
return result;
|
|
13950
14051
|
}
|
|
13951
|
-
function makeCache() {
|
|
14052
|
+
function makeCache({ hits, trace } = {}) {
|
|
14053
|
+
const meta = {};
|
|
14054
|
+
let hitCount;
|
|
14055
|
+
if (hits) {
|
|
14056
|
+
hitCount = /* @__PURE__ */ new Map();
|
|
14057
|
+
meta.hits = hitCount;
|
|
14058
|
+
}
|
|
14059
|
+
let logs;
|
|
14060
|
+
if (trace) {
|
|
14061
|
+
logs = [];
|
|
14062
|
+
meta.logs = logs;
|
|
14063
|
+
}
|
|
13952
14064
|
const stateCache = new StateCache();
|
|
13953
14065
|
let getStateKey = null;
|
|
14066
|
+
const stack = [];
|
|
13954
14067
|
const events = {
|
|
14068
|
+
meta,
|
|
13955
14069
|
enter: function(ruleName, state) {
|
|
14070
|
+
if (hits) {
|
|
14071
|
+
hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
|
|
14072
|
+
}
|
|
13956
14073
|
if (uncacheable.has(ruleName)) {
|
|
13957
14074
|
return;
|
|
13958
14075
|
}
|
|
13959
14076
|
;
|
|
13960
14077
|
const key = [ruleName, state.pos, ...getStateKey()];
|
|
13961
14078
|
if (stateCache.has(key)) {
|
|
14079
|
+
if (trace) {
|
|
14080
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
|
|
14081
|
+
}
|
|
13962
14082
|
const result = stateCache.get(key);
|
|
13963
14083
|
return {
|
|
13964
14084
|
cache: result ? { ...result } : void 0
|
|
13965
14085
|
};
|
|
13966
14086
|
}
|
|
14087
|
+
if (trace) {
|
|
14088
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
|
|
14089
|
+
stack.push(ruleName);
|
|
14090
|
+
}
|
|
13967
14091
|
return;
|
|
13968
14092
|
},
|
|
13969
14093
|
exit: function(ruleName, state, result) {
|
|
@@ -13981,6 +14105,10 @@ function makeCache() {
|
|
|
13981
14105
|
if (parse.config.verbose && result) {
|
|
13982
14106
|
console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
|
|
13983
14107
|
}
|
|
14108
|
+
if (trace) {
|
|
14109
|
+
stack.pop();
|
|
14110
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
|
|
14111
|
+
}
|
|
13984
14112
|
return;
|
|
13985
14113
|
}
|
|
13986
14114
|
};
|
|
@@ -13997,5 +14125,6 @@ export {
|
|
|
13997
14125
|
generate_default as generate,
|
|
13998
14126
|
isCompileError,
|
|
13999
14127
|
parse,
|
|
14128
|
+
prune,
|
|
14000
14129
|
util_exports as util
|
|
14001
14130
|
};
|
package/dist/rollup.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(rollup_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
|
},
|