@danielx/civet 0.6.56 → 0.6.58
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/browser.js +54 -18
- package/dist/esbuild.js +39 -10
- package/dist/main.js +54 -18
- package/dist/main.mjs +54 -18
- package/dist/rollup.js +39 -10
- package/dist/unplugin-shared.mjs +39 -10
- package/dist/unplugin.d.mts +1 -0
- package/dist/unplugin.d.ts +1 -0
- package/dist/unplugin.js +39 -10
- package/dist/vite.js +39 -10
- package/dist/webpack.js +39 -10
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -1131,12 +1131,12 @@ ${input.slice(result.pos)}
|
|
|
1131
1131
|
}
|
|
1132
1132
|
return node;
|
|
1133
1133
|
}
|
|
1134
|
-
function wrapIterationReturningResults(statement, outerRef) {
|
|
1134
|
+
function wrapIterationReturningResults(statement, outer, outerRef) {
|
|
1135
1135
|
if (statement.type === "DoStatement") {
|
|
1136
1136
|
if (outerRef) {
|
|
1137
1137
|
insertPush(statement.block, outerRef);
|
|
1138
1138
|
} else {
|
|
1139
|
-
insertReturn(statement.block);
|
|
1139
|
+
insertReturn(statement.block, outer);
|
|
1140
1140
|
}
|
|
1141
1141
|
return;
|
|
1142
1142
|
}
|
|
@@ -1146,7 +1146,7 @@ ${input.slice(result.pos)}
|
|
|
1146
1146
|
children: ["const ", resultsRef, "=[];"]
|
|
1147
1147
|
};
|
|
1148
1148
|
insertPush(statement.block, resultsRef);
|
|
1149
|
-
|
|
1149
|
+
outer.children.unshift(declaration);
|
|
1150
1150
|
if (outerRef) {
|
|
1151
1151
|
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
1152
1152
|
} else {
|
|
@@ -1180,10 +1180,17 @@ ${input.slice(result.pos)}
|
|
|
1180
1180
|
}
|
|
1181
1181
|
if (!Array.isArray(node))
|
|
1182
1182
|
return;
|
|
1183
|
-
|
|
1184
|
-
if (!exp)
|
|
1183
|
+
let [, exp] = node;
|
|
1184
|
+
if (!exp) {
|
|
1185
1185
|
return;
|
|
1186
|
+
}
|
|
1186
1187
|
const indent = getIndent(node);
|
|
1188
|
+
const outer = exp;
|
|
1189
|
+
let { type } = exp;
|
|
1190
|
+
if (type === "LabelledStatement") {
|
|
1191
|
+
exp = exp.statement;
|
|
1192
|
+
({ type } = exp);
|
|
1193
|
+
}
|
|
1187
1194
|
switch (exp.type) {
|
|
1188
1195
|
case "BreakStatement":
|
|
1189
1196
|
case "ContinueStatement":
|
|
@@ -1204,7 +1211,7 @@ ${input.slice(result.pos)}
|
|
|
1204
1211
|
case "ForStatement":
|
|
1205
1212
|
case "IterationStatement":
|
|
1206
1213
|
case "DoStatement":
|
|
1207
|
-
wrapIterationReturningResults(exp, ref);
|
|
1214
|
+
wrapIterationReturningResults(exp, outer, ref);
|
|
1208
1215
|
return;
|
|
1209
1216
|
case "BlockStatement":
|
|
1210
1217
|
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
@@ -1573,7 +1580,7 @@ ${input.slice(result.pos)}
|
|
|
1573
1580
|
return pattern;
|
|
1574
1581
|
}
|
|
1575
1582
|
}
|
|
1576
|
-
function insertReturn(node) {
|
|
1583
|
+
function insertReturn(node, outerNode = node) {
|
|
1577
1584
|
if (!node)
|
|
1578
1585
|
return;
|
|
1579
1586
|
switch (node.type) {
|
|
@@ -1601,12 +1608,20 @@ ${input.slice(result.pos)}
|
|
|
1601
1608
|
}
|
|
1602
1609
|
if (!Array.isArray(node))
|
|
1603
1610
|
return;
|
|
1604
|
-
|
|
1605
|
-
if (semi?.type === "SemicolonDelimiter")
|
|
1611
|
+
let [, exp, semi] = node;
|
|
1612
|
+
if (semi?.type === "SemicolonDelimiter") {
|
|
1606
1613
|
return;
|
|
1607
|
-
|
|
1614
|
+
}
|
|
1615
|
+
if (!exp) {
|
|
1608
1616
|
return;
|
|
1609
|
-
|
|
1617
|
+
}
|
|
1618
|
+
const outer = exp;
|
|
1619
|
+
let { type } = exp;
|
|
1620
|
+
if (type === "LabelledStatement") {
|
|
1621
|
+
exp = exp.statement;
|
|
1622
|
+
({ type } = exp);
|
|
1623
|
+
}
|
|
1624
|
+
switch (type) {
|
|
1610
1625
|
case "BreakStatement":
|
|
1611
1626
|
case "ContinueStatement":
|
|
1612
1627
|
case "DebuggerStatement":
|
|
@@ -1637,7 +1652,7 @@ ${input.slice(result.pos)}
|
|
|
1637
1652
|
case "ForStatement":
|
|
1638
1653
|
case "IterationStatement":
|
|
1639
1654
|
case "DoStatement":
|
|
1640
|
-
wrapIterationReturningResults(exp);
|
|
1655
|
+
wrapIterationReturningResults(exp, outer);
|
|
1641
1656
|
return;
|
|
1642
1657
|
case "BlockStatement":
|
|
1643
1658
|
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
@@ -1690,6 +1705,9 @@ ${input.slice(result.pos)}
|
|
|
1690
1705
|
function isPromiseVoidType(t) {
|
|
1691
1706
|
return t?.type === "IdentifierType" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
|
|
1692
1707
|
}
|
|
1708
|
+
function isGeneratorVoidType(t) {
|
|
1709
|
+
return t?.type === "IdentifierType" && (t.raw === "Iterator" || t.raw === "Generator") && t.args?.types?.length >= 2 && isVoidType(t.args.types[1]);
|
|
1710
|
+
}
|
|
1693
1711
|
function isWhitespaceOrEmpty(node) {
|
|
1694
1712
|
if (!node)
|
|
1695
1713
|
return true;
|
|
@@ -2477,10 +2495,10 @@ ${input.slice(result.pos)}
|
|
|
2477
2495
|
if (!processReturnValue(f) && implicitReturns) {
|
|
2478
2496
|
const { signature, block } = f;
|
|
2479
2497
|
const { modifier, name, returnType } = signature;
|
|
2480
|
-
const { async, set } = modifier;
|
|
2498
|
+
const { async, generator, set } = modifier;
|
|
2481
2499
|
const isMethod = f.type === "MethodDefinition";
|
|
2482
2500
|
const isConstructor = isMethod && name === "constructor";
|
|
2483
|
-
const isVoid = isVoidType(returnType?.t) || async && isPromiseVoidType(returnType?.t);
|
|
2501
|
+
const isVoid = isVoidType(returnType?.t) || async && isPromiseVoidType(returnType?.t) || !async && generator && isGeneratorVoidType(returnType?.t);
|
|
2484
2502
|
const isBlock = block?.type === "BlockStatement";
|
|
2485
2503
|
if (!isVoid && !set && !isConstructor && isBlock) {
|
|
2486
2504
|
insertReturn(block);
|
|
@@ -6845,7 +6863,12 @@ ${input.slice(result.pos)}
|
|
|
6845
6863
|
return {
|
|
6846
6864
|
...fn,
|
|
6847
6865
|
id,
|
|
6848
|
-
children: [
|
|
6866
|
+
children: [
|
|
6867
|
+
...fn.children.slice(0, 3),
|
|
6868
|
+
insertTrimmingSpace(ws, " "),
|
|
6869
|
+
id,
|
|
6870
|
+
...fn.children.slice(3)
|
|
6871
|
+
]
|
|
6849
6872
|
};
|
|
6850
6873
|
});
|
|
6851
6874
|
var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3];
|
|
@@ -8100,7 +8123,7 @@ ${input.slice(result.pos)}
|
|
|
8100
8123
|
var block = $3;
|
|
8101
8124
|
let children = $0;
|
|
8102
8125
|
let generatorPos = 0;
|
|
8103
|
-
|
|
8126
|
+
let { modifier } = signature;
|
|
8104
8127
|
if (hasAwait(block)) {
|
|
8105
8128
|
generatorPos++;
|
|
8106
8129
|
children = children.slice();
|
|
@@ -8112,6 +8135,8 @@ ${input.slice(result.pos)}
|
|
|
8112
8135
|
} else if (modifier?.async) {
|
|
8113
8136
|
} else {
|
|
8114
8137
|
children.unshift("async ");
|
|
8138
|
+
modifier = { ...modifier, async: true };
|
|
8139
|
+
signature = { ...signature, modifier };
|
|
8115
8140
|
}
|
|
8116
8141
|
}
|
|
8117
8142
|
if (hasYield(block)) {
|
|
@@ -8125,6 +8150,8 @@ ${input.slice(result.pos)}
|
|
|
8125
8150
|
} else if (modifier?.generator) {
|
|
8126
8151
|
} else {
|
|
8127
8152
|
children.splice(generatorPos, 0, "*");
|
|
8153
|
+
modifier = { ...modifier, generator: true };
|
|
8154
|
+
signature = { ...signature, modifier };
|
|
8128
8155
|
}
|
|
8129
8156
|
}
|
|
8130
8157
|
return {
|
|
@@ -8226,7 +8253,7 @@ ${input.slice(result.pos)}
|
|
|
8226
8253
|
async: true,
|
|
8227
8254
|
get: false,
|
|
8228
8255
|
set: false,
|
|
8229
|
-
generator: !!$
|
|
8256
|
+
generator: !!$2,
|
|
8230
8257
|
children: $0
|
|
8231
8258
|
};
|
|
8232
8259
|
});
|
|
@@ -8853,7 +8880,16 @@ ${input.slice(result.pos)}
|
|
|
8853
8880
|
function BlockStatement(ctx, state) {
|
|
8854
8881
|
return $EVENT(ctx, state, "BlockStatement", BlockStatement$0);
|
|
8855
8882
|
}
|
|
8856
|
-
var LabelledStatement$0 = $S(Label, LabelledItem)
|
|
8883
|
+
var LabelledStatement$0 = $TS($S(Label, LabelledItem), function($skip, $loc, $0, $1, $2) {
|
|
8884
|
+
var label = $1;
|
|
8885
|
+
var statement = $2;
|
|
8886
|
+
return {
|
|
8887
|
+
type: "LabelledStatement",
|
|
8888
|
+
label,
|
|
8889
|
+
statement,
|
|
8890
|
+
children: $0
|
|
8891
|
+
};
|
|
8892
|
+
});
|
|
8857
8893
|
function LabelledStatement(ctx, state) {
|
|
8858
8894
|
return $EVENT(ctx, state, "LabelledStatement", LabelledStatement$0);
|
|
8859
8895
|
}
|
package/dist/esbuild.js
CHANGED
|
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
|
|
|
42
42
|
var import_path = __toESM(require("path"));
|
|
43
43
|
var tsvfs = __toESM(require("@typescript/vfs"));
|
|
44
44
|
var import_os = __toESM(require("os"));
|
|
45
|
-
var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
|
|
46
45
|
var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
|
|
47
46
|
var postfixRE = /[?#].*$/s;
|
|
48
47
|
var isWindows = import_os.default.platform() === "win32";
|
|
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
|
|
|
69
68
|
return normalizePath(file);
|
|
70
69
|
return void 0;
|
|
71
70
|
}
|
|
72
|
-
function resolveAbsolutePath(rootDir, id) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
function resolveAbsolutePath(rootDir, id, implicitExtension) {
|
|
72
|
+
const file = import_path.default.join(rootDir, id);
|
|
73
|
+
return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
|
|
74
|
+
}
|
|
75
|
+
function implicitCivet(file) {
|
|
76
|
+
if (tryFsResolve(file))
|
|
77
|
+
return;
|
|
78
|
+
const civet2 = file + ".civet";
|
|
79
|
+
if (tryFsResolve(civet2))
|
|
80
|
+
return civet2;
|
|
81
|
+
return;
|
|
77
82
|
}
|
|
78
83
|
var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
79
84
|
if (options.dts)
|
|
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
82
87
|
options.ts = "civet";
|
|
83
88
|
const transformTS = options.emitDeclaration || options.typecheck;
|
|
84
89
|
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
90
|
+
const implicitExtension = options.implicitExtension ?? true;
|
|
85
91
|
let fsMap = /* @__PURE__ */ new Map();
|
|
86
92
|
const sourceMaps = /* @__PURE__ */ new Map();
|
|
87
93
|
let compilerOptions;
|
|
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
196
202
|
resolveId(id, importer) {
|
|
197
203
|
if (/\0/.test(id))
|
|
198
204
|
return null;
|
|
199
|
-
if (!isCivet(id) && !isCivetTranspiled(id))
|
|
200
|
-
return null;
|
|
201
205
|
id = cleanCivetId(id);
|
|
202
|
-
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
206
|
+
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
203
207
|
if (!absolutePath)
|
|
204
208
|
return null;
|
|
205
|
-
|
|
209
|
+
let relativeId = import_path.default.relative(process.cwd(), absolutePath);
|
|
210
|
+
if (!relativeId.endsWith(".civet")) {
|
|
211
|
+
if (!implicitExtension)
|
|
212
|
+
return null;
|
|
213
|
+
const implicitId = implicitCivet(relativeId);
|
|
214
|
+
if (!implicitId)
|
|
215
|
+
return null;
|
|
216
|
+
relativeId = implicitId;
|
|
217
|
+
}
|
|
206
218
|
const relativePath = relativeId + outExt;
|
|
207
219
|
return relativePath;
|
|
208
220
|
},
|
|
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
294
306
|
},
|
|
295
307
|
vite: {
|
|
296
308
|
config(config) {
|
|
309
|
+
var _a;
|
|
297
310
|
rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
|
|
311
|
+
if (implicitExtension) {
|
|
312
|
+
config.resolve ?? (config.resolve = {});
|
|
313
|
+
(_a = config.resolve).extensions ?? (_a.extensions = []);
|
|
314
|
+
config.resolve.extensions.push(".civet");
|
|
315
|
+
}
|
|
298
316
|
},
|
|
299
317
|
async transformIndexHtml(html) {
|
|
300
318
|
return html.replace(
|
|
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
313
331
|
)
|
|
314
332
|
)
|
|
315
333
|
);
|
|
334
|
+
},
|
|
335
|
+
handleHotUpdate({ file, server, modules }) {
|
|
336
|
+
if (!file.endsWith(".civet"))
|
|
337
|
+
return;
|
|
338
|
+
const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
|
|
339
|
+
const module2 = server.moduleGraph.getModuleById(relativeId);
|
|
340
|
+
if (module2) {
|
|
341
|
+
server.moduleGraph.onFileChange(relativeId);
|
|
342
|
+
return [...modules, module2];
|
|
343
|
+
}
|
|
344
|
+
return modules;
|
|
316
345
|
}
|
|
317
346
|
}
|
|
318
347
|
};
|
package/dist/main.js
CHANGED
|
@@ -1123,12 +1123,12 @@ var require_lib = __commonJS({
|
|
|
1123
1123
|
}
|
|
1124
1124
|
return node;
|
|
1125
1125
|
}
|
|
1126
|
-
function wrapIterationReturningResults(statement, outerRef) {
|
|
1126
|
+
function wrapIterationReturningResults(statement, outer, outerRef) {
|
|
1127
1127
|
if (statement.type === "DoStatement") {
|
|
1128
1128
|
if (outerRef) {
|
|
1129
1129
|
insertPush(statement.block, outerRef);
|
|
1130
1130
|
} else {
|
|
1131
|
-
insertReturn(statement.block);
|
|
1131
|
+
insertReturn(statement.block, outer);
|
|
1132
1132
|
}
|
|
1133
1133
|
return;
|
|
1134
1134
|
}
|
|
@@ -1138,7 +1138,7 @@ var require_lib = __commonJS({
|
|
|
1138
1138
|
children: ["const ", resultsRef, "=[];"]
|
|
1139
1139
|
};
|
|
1140
1140
|
insertPush(statement.block, resultsRef);
|
|
1141
|
-
|
|
1141
|
+
outer.children.unshift(declaration);
|
|
1142
1142
|
if (outerRef) {
|
|
1143
1143
|
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
1144
1144
|
} else {
|
|
@@ -1172,10 +1172,17 @@ var require_lib = __commonJS({
|
|
|
1172
1172
|
}
|
|
1173
1173
|
if (!Array.isArray(node))
|
|
1174
1174
|
return;
|
|
1175
|
-
|
|
1176
|
-
if (!exp)
|
|
1175
|
+
let [, exp] = node;
|
|
1176
|
+
if (!exp) {
|
|
1177
1177
|
return;
|
|
1178
|
+
}
|
|
1178
1179
|
const indent = getIndent(node);
|
|
1180
|
+
const outer = exp;
|
|
1181
|
+
let { type } = exp;
|
|
1182
|
+
if (type === "LabelledStatement") {
|
|
1183
|
+
exp = exp.statement;
|
|
1184
|
+
({ type } = exp);
|
|
1185
|
+
}
|
|
1179
1186
|
switch (exp.type) {
|
|
1180
1187
|
case "BreakStatement":
|
|
1181
1188
|
case "ContinueStatement":
|
|
@@ -1196,7 +1203,7 @@ var require_lib = __commonJS({
|
|
|
1196
1203
|
case "ForStatement":
|
|
1197
1204
|
case "IterationStatement":
|
|
1198
1205
|
case "DoStatement":
|
|
1199
|
-
wrapIterationReturningResults(exp, ref);
|
|
1206
|
+
wrapIterationReturningResults(exp, outer, ref);
|
|
1200
1207
|
return;
|
|
1201
1208
|
case "BlockStatement":
|
|
1202
1209
|
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
@@ -1565,7 +1572,7 @@ var require_lib = __commonJS({
|
|
|
1565
1572
|
return pattern;
|
|
1566
1573
|
}
|
|
1567
1574
|
}
|
|
1568
|
-
function insertReturn(node) {
|
|
1575
|
+
function insertReturn(node, outerNode = node) {
|
|
1569
1576
|
if (!node)
|
|
1570
1577
|
return;
|
|
1571
1578
|
switch (node.type) {
|
|
@@ -1593,12 +1600,20 @@ var require_lib = __commonJS({
|
|
|
1593
1600
|
}
|
|
1594
1601
|
if (!Array.isArray(node))
|
|
1595
1602
|
return;
|
|
1596
|
-
|
|
1597
|
-
if (semi?.type === "SemicolonDelimiter")
|
|
1603
|
+
let [, exp, semi] = node;
|
|
1604
|
+
if (semi?.type === "SemicolonDelimiter") {
|
|
1598
1605
|
return;
|
|
1599
|
-
|
|
1606
|
+
}
|
|
1607
|
+
if (!exp) {
|
|
1600
1608
|
return;
|
|
1601
|
-
|
|
1609
|
+
}
|
|
1610
|
+
const outer = exp;
|
|
1611
|
+
let { type } = exp;
|
|
1612
|
+
if (type === "LabelledStatement") {
|
|
1613
|
+
exp = exp.statement;
|
|
1614
|
+
({ type } = exp);
|
|
1615
|
+
}
|
|
1616
|
+
switch (type) {
|
|
1602
1617
|
case "BreakStatement":
|
|
1603
1618
|
case "ContinueStatement":
|
|
1604
1619
|
case "DebuggerStatement":
|
|
@@ -1629,7 +1644,7 @@ var require_lib = __commonJS({
|
|
|
1629
1644
|
case "ForStatement":
|
|
1630
1645
|
case "IterationStatement":
|
|
1631
1646
|
case "DoStatement":
|
|
1632
|
-
wrapIterationReturningResults(exp);
|
|
1647
|
+
wrapIterationReturningResults(exp, outer);
|
|
1633
1648
|
return;
|
|
1634
1649
|
case "BlockStatement":
|
|
1635
1650
|
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
@@ -1682,6 +1697,9 @@ var require_lib = __commonJS({
|
|
|
1682
1697
|
function isPromiseVoidType(t) {
|
|
1683
1698
|
return t?.type === "IdentifierType" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
|
|
1684
1699
|
}
|
|
1700
|
+
function isGeneratorVoidType(t) {
|
|
1701
|
+
return t?.type === "IdentifierType" && (t.raw === "Iterator" || t.raw === "Generator") && t.args?.types?.length >= 2 && isVoidType(t.args.types[1]);
|
|
1702
|
+
}
|
|
1685
1703
|
function isWhitespaceOrEmpty(node) {
|
|
1686
1704
|
if (!node)
|
|
1687
1705
|
return true;
|
|
@@ -2469,10 +2487,10 @@ var require_lib = __commonJS({
|
|
|
2469
2487
|
if (!processReturnValue(f) && implicitReturns) {
|
|
2470
2488
|
const { signature, block } = f;
|
|
2471
2489
|
const { modifier, name, returnType } = signature;
|
|
2472
|
-
const { async, set } = modifier;
|
|
2490
|
+
const { async, generator, set } = modifier;
|
|
2473
2491
|
const isMethod = f.type === "MethodDefinition";
|
|
2474
2492
|
const isConstructor = isMethod && name === "constructor";
|
|
2475
|
-
const isVoid = isVoidType(returnType?.t) || async && isPromiseVoidType(returnType?.t);
|
|
2493
|
+
const isVoid = isVoidType(returnType?.t) || async && isPromiseVoidType(returnType?.t) || !async && generator && isGeneratorVoidType(returnType?.t);
|
|
2476
2494
|
const isBlock = block?.type === "BlockStatement";
|
|
2477
2495
|
if (!isVoid && !set && !isConstructor && isBlock) {
|
|
2478
2496
|
insertReturn(block);
|
|
@@ -6837,7 +6855,12 @@ var require_parser = __commonJS({
|
|
|
6837
6855
|
return {
|
|
6838
6856
|
...fn,
|
|
6839
6857
|
id,
|
|
6840
|
-
children: [
|
|
6858
|
+
children: [
|
|
6859
|
+
...fn.children.slice(0, 3),
|
|
6860
|
+
insertTrimmingSpace(ws, " "),
|
|
6861
|
+
id,
|
|
6862
|
+
...fn.children.slice(3)
|
|
6863
|
+
]
|
|
6841
6864
|
};
|
|
6842
6865
|
});
|
|
6843
6866
|
var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3];
|
|
@@ -8092,7 +8115,7 @@ var require_parser = __commonJS({
|
|
|
8092
8115
|
var block = $3;
|
|
8093
8116
|
let children = $0;
|
|
8094
8117
|
let generatorPos = 0;
|
|
8095
|
-
|
|
8118
|
+
let { modifier } = signature;
|
|
8096
8119
|
if (hasAwait(block)) {
|
|
8097
8120
|
generatorPos++;
|
|
8098
8121
|
children = children.slice();
|
|
@@ -8104,6 +8127,8 @@ var require_parser = __commonJS({
|
|
|
8104
8127
|
} else if (modifier?.async) {
|
|
8105
8128
|
} else {
|
|
8106
8129
|
children.unshift("async ");
|
|
8130
|
+
modifier = { ...modifier, async: true };
|
|
8131
|
+
signature = { ...signature, modifier };
|
|
8107
8132
|
}
|
|
8108
8133
|
}
|
|
8109
8134
|
if (hasYield(block)) {
|
|
@@ -8117,6 +8142,8 @@ var require_parser = __commonJS({
|
|
|
8117
8142
|
} else if (modifier?.generator) {
|
|
8118
8143
|
} else {
|
|
8119
8144
|
children.splice(generatorPos, 0, "*");
|
|
8145
|
+
modifier = { ...modifier, generator: true };
|
|
8146
|
+
signature = { ...signature, modifier };
|
|
8120
8147
|
}
|
|
8121
8148
|
}
|
|
8122
8149
|
return {
|
|
@@ -8218,7 +8245,7 @@ var require_parser = __commonJS({
|
|
|
8218
8245
|
async: true,
|
|
8219
8246
|
get: false,
|
|
8220
8247
|
set: false,
|
|
8221
|
-
generator: !!$
|
|
8248
|
+
generator: !!$2,
|
|
8222
8249
|
children: $0
|
|
8223
8250
|
};
|
|
8224
8251
|
});
|
|
@@ -8845,7 +8872,16 @@ var require_parser = __commonJS({
|
|
|
8845
8872
|
function BlockStatement(ctx, state) {
|
|
8846
8873
|
return $EVENT(ctx, state, "BlockStatement", BlockStatement$0);
|
|
8847
8874
|
}
|
|
8848
|
-
var LabelledStatement$0 = $S(Label, LabelledItem)
|
|
8875
|
+
var LabelledStatement$0 = $TS($S(Label, LabelledItem), function($skip, $loc, $0, $1, $2) {
|
|
8876
|
+
var label = $1;
|
|
8877
|
+
var statement = $2;
|
|
8878
|
+
return {
|
|
8879
|
+
type: "LabelledStatement",
|
|
8880
|
+
label,
|
|
8881
|
+
statement,
|
|
8882
|
+
children: $0
|
|
8883
|
+
};
|
|
8884
|
+
});
|
|
8849
8885
|
function LabelledStatement(ctx, state) {
|
|
8850
8886
|
return $EVENT(ctx, state, "LabelledStatement", LabelledStatement$0);
|
|
8851
8887
|
}
|
package/dist/main.mjs
CHANGED
|
@@ -1121,12 +1121,12 @@ var require_lib = __commonJS({
|
|
|
1121
1121
|
}
|
|
1122
1122
|
return node;
|
|
1123
1123
|
}
|
|
1124
|
-
function wrapIterationReturningResults(statement, outerRef) {
|
|
1124
|
+
function wrapIterationReturningResults(statement, outer, outerRef) {
|
|
1125
1125
|
if (statement.type === "DoStatement") {
|
|
1126
1126
|
if (outerRef) {
|
|
1127
1127
|
insertPush(statement.block, outerRef);
|
|
1128
1128
|
} else {
|
|
1129
|
-
insertReturn(statement.block);
|
|
1129
|
+
insertReturn(statement.block, outer);
|
|
1130
1130
|
}
|
|
1131
1131
|
return;
|
|
1132
1132
|
}
|
|
@@ -1136,7 +1136,7 @@ var require_lib = __commonJS({
|
|
|
1136
1136
|
children: ["const ", resultsRef, "=[];"]
|
|
1137
1137
|
};
|
|
1138
1138
|
insertPush(statement.block, resultsRef);
|
|
1139
|
-
|
|
1139
|
+
outer.children.unshift(declaration);
|
|
1140
1140
|
if (outerRef) {
|
|
1141
1141
|
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
1142
1142
|
} else {
|
|
@@ -1170,10 +1170,17 @@ var require_lib = __commonJS({
|
|
|
1170
1170
|
}
|
|
1171
1171
|
if (!Array.isArray(node))
|
|
1172
1172
|
return;
|
|
1173
|
-
|
|
1174
|
-
if (!exp)
|
|
1173
|
+
let [, exp] = node;
|
|
1174
|
+
if (!exp) {
|
|
1175
1175
|
return;
|
|
1176
|
+
}
|
|
1176
1177
|
const indent = getIndent(node);
|
|
1178
|
+
const outer = exp;
|
|
1179
|
+
let { type } = exp;
|
|
1180
|
+
if (type === "LabelledStatement") {
|
|
1181
|
+
exp = exp.statement;
|
|
1182
|
+
({ type } = exp);
|
|
1183
|
+
}
|
|
1177
1184
|
switch (exp.type) {
|
|
1178
1185
|
case "BreakStatement":
|
|
1179
1186
|
case "ContinueStatement":
|
|
@@ -1194,7 +1201,7 @@ var require_lib = __commonJS({
|
|
|
1194
1201
|
case "ForStatement":
|
|
1195
1202
|
case "IterationStatement":
|
|
1196
1203
|
case "DoStatement":
|
|
1197
|
-
wrapIterationReturningResults(exp, ref);
|
|
1204
|
+
wrapIterationReturningResults(exp, outer, ref);
|
|
1198
1205
|
return;
|
|
1199
1206
|
case "BlockStatement":
|
|
1200
1207
|
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
@@ -1563,7 +1570,7 @@ var require_lib = __commonJS({
|
|
|
1563
1570
|
return pattern;
|
|
1564
1571
|
}
|
|
1565
1572
|
}
|
|
1566
|
-
function insertReturn(node) {
|
|
1573
|
+
function insertReturn(node, outerNode = node) {
|
|
1567
1574
|
if (!node)
|
|
1568
1575
|
return;
|
|
1569
1576
|
switch (node.type) {
|
|
@@ -1591,12 +1598,20 @@ var require_lib = __commonJS({
|
|
|
1591
1598
|
}
|
|
1592
1599
|
if (!Array.isArray(node))
|
|
1593
1600
|
return;
|
|
1594
|
-
|
|
1595
|
-
if (semi?.type === "SemicolonDelimiter")
|
|
1601
|
+
let [, exp, semi] = node;
|
|
1602
|
+
if (semi?.type === "SemicolonDelimiter") {
|
|
1596
1603
|
return;
|
|
1597
|
-
|
|
1604
|
+
}
|
|
1605
|
+
if (!exp) {
|
|
1598
1606
|
return;
|
|
1599
|
-
|
|
1607
|
+
}
|
|
1608
|
+
const outer = exp;
|
|
1609
|
+
let { type } = exp;
|
|
1610
|
+
if (type === "LabelledStatement") {
|
|
1611
|
+
exp = exp.statement;
|
|
1612
|
+
({ type } = exp);
|
|
1613
|
+
}
|
|
1614
|
+
switch (type) {
|
|
1600
1615
|
case "BreakStatement":
|
|
1601
1616
|
case "ContinueStatement":
|
|
1602
1617
|
case "DebuggerStatement":
|
|
@@ -1627,7 +1642,7 @@ var require_lib = __commonJS({
|
|
|
1627
1642
|
case "ForStatement":
|
|
1628
1643
|
case "IterationStatement":
|
|
1629
1644
|
case "DoStatement":
|
|
1630
|
-
wrapIterationReturningResults(exp);
|
|
1645
|
+
wrapIterationReturningResults(exp, outer);
|
|
1631
1646
|
return;
|
|
1632
1647
|
case "BlockStatement":
|
|
1633
1648
|
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
@@ -1680,6 +1695,9 @@ var require_lib = __commonJS({
|
|
|
1680
1695
|
function isPromiseVoidType(t) {
|
|
1681
1696
|
return t?.type === "IdentifierType" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
|
|
1682
1697
|
}
|
|
1698
|
+
function isGeneratorVoidType(t) {
|
|
1699
|
+
return t?.type === "IdentifierType" && (t.raw === "Iterator" || t.raw === "Generator") && t.args?.types?.length >= 2 && isVoidType(t.args.types[1]);
|
|
1700
|
+
}
|
|
1683
1701
|
function isWhitespaceOrEmpty(node) {
|
|
1684
1702
|
if (!node)
|
|
1685
1703
|
return true;
|
|
@@ -2467,10 +2485,10 @@ var require_lib = __commonJS({
|
|
|
2467
2485
|
if (!processReturnValue(f) && implicitReturns) {
|
|
2468
2486
|
const { signature, block } = f;
|
|
2469
2487
|
const { modifier, name, returnType } = signature;
|
|
2470
|
-
const { async, set } = modifier;
|
|
2488
|
+
const { async, generator, set } = modifier;
|
|
2471
2489
|
const isMethod = f.type === "MethodDefinition";
|
|
2472
2490
|
const isConstructor = isMethod && name === "constructor";
|
|
2473
|
-
const isVoid = isVoidType(returnType?.t) || async && isPromiseVoidType(returnType?.t);
|
|
2491
|
+
const isVoid = isVoidType(returnType?.t) || async && isPromiseVoidType(returnType?.t) || !async && generator && isGeneratorVoidType(returnType?.t);
|
|
2474
2492
|
const isBlock = block?.type === "BlockStatement";
|
|
2475
2493
|
if (!isVoid && !set && !isConstructor && isBlock) {
|
|
2476
2494
|
insertReturn(block);
|
|
@@ -6835,7 +6853,12 @@ var require_parser = __commonJS({
|
|
|
6835
6853
|
return {
|
|
6836
6854
|
...fn,
|
|
6837
6855
|
id,
|
|
6838
|
-
children: [
|
|
6856
|
+
children: [
|
|
6857
|
+
...fn.children.slice(0, 3),
|
|
6858
|
+
insertTrimmingSpace(ws, " "),
|
|
6859
|
+
id,
|
|
6860
|
+
...fn.children.slice(3)
|
|
6861
|
+
]
|
|
6839
6862
|
};
|
|
6840
6863
|
});
|
|
6841
6864
|
var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3];
|
|
@@ -8090,7 +8113,7 @@ var require_parser = __commonJS({
|
|
|
8090
8113
|
var block = $3;
|
|
8091
8114
|
let children = $0;
|
|
8092
8115
|
let generatorPos = 0;
|
|
8093
|
-
|
|
8116
|
+
let { modifier } = signature;
|
|
8094
8117
|
if (hasAwait(block)) {
|
|
8095
8118
|
generatorPos++;
|
|
8096
8119
|
children = children.slice();
|
|
@@ -8102,6 +8125,8 @@ var require_parser = __commonJS({
|
|
|
8102
8125
|
} else if (modifier?.async) {
|
|
8103
8126
|
} else {
|
|
8104
8127
|
children.unshift("async ");
|
|
8128
|
+
modifier = { ...modifier, async: true };
|
|
8129
|
+
signature = { ...signature, modifier };
|
|
8105
8130
|
}
|
|
8106
8131
|
}
|
|
8107
8132
|
if (hasYield(block)) {
|
|
@@ -8115,6 +8140,8 @@ var require_parser = __commonJS({
|
|
|
8115
8140
|
} else if (modifier?.generator) {
|
|
8116
8141
|
} else {
|
|
8117
8142
|
children.splice(generatorPos, 0, "*");
|
|
8143
|
+
modifier = { ...modifier, generator: true };
|
|
8144
|
+
signature = { ...signature, modifier };
|
|
8118
8145
|
}
|
|
8119
8146
|
}
|
|
8120
8147
|
return {
|
|
@@ -8216,7 +8243,7 @@ var require_parser = __commonJS({
|
|
|
8216
8243
|
async: true,
|
|
8217
8244
|
get: false,
|
|
8218
8245
|
set: false,
|
|
8219
|
-
generator: !!$
|
|
8246
|
+
generator: !!$2,
|
|
8220
8247
|
children: $0
|
|
8221
8248
|
};
|
|
8222
8249
|
});
|
|
@@ -8843,7 +8870,16 @@ var require_parser = __commonJS({
|
|
|
8843
8870
|
function BlockStatement(ctx, state) {
|
|
8844
8871
|
return $EVENT(ctx, state, "BlockStatement", BlockStatement$0);
|
|
8845
8872
|
}
|
|
8846
|
-
var LabelledStatement$0 = $S(Label, LabelledItem)
|
|
8873
|
+
var LabelledStatement$0 = $TS($S(Label, LabelledItem), function($skip, $loc, $0, $1, $2) {
|
|
8874
|
+
var label = $1;
|
|
8875
|
+
var statement = $2;
|
|
8876
|
+
return {
|
|
8877
|
+
type: "LabelledStatement",
|
|
8878
|
+
label,
|
|
8879
|
+
statement,
|
|
8880
|
+
children: $0
|
|
8881
|
+
};
|
|
8882
|
+
});
|
|
8847
8883
|
function LabelledStatement(ctx, state) {
|
|
8848
8884
|
return $EVENT(ctx, state, "LabelledStatement", LabelledStatement$0);
|
|
8849
8885
|
}
|
package/dist/rollup.js
CHANGED
|
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
|
|
|
42
42
|
var import_path = __toESM(require("path"));
|
|
43
43
|
var tsvfs = __toESM(require("@typescript/vfs"));
|
|
44
44
|
var import_os = __toESM(require("os"));
|
|
45
|
-
var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
|
|
46
45
|
var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
|
|
47
46
|
var postfixRE = /[?#].*$/s;
|
|
48
47
|
var isWindows = import_os.default.platform() === "win32";
|
|
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
|
|
|
69
68
|
return normalizePath(file);
|
|
70
69
|
return void 0;
|
|
71
70
|
}
|
|
72
|
-
function resolveAbsolutePath(rootDir, id) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
function resolveAbsolutePath(rootDir, id, implicitExtension) {
|
|
72
|
+
const file = import_path.default.join(rootDir, id);
|
|
73
|
+
return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
|
|
74
|
+
}
|
|
75
|
+
function implicitCivet(file) {
|
|
76
|
+
if (tryFsResolve(file))
|
|
77
|
+
return;
|
|
78
|
+
const civet2 = file + ".civet";
|
|
79
|
+
if (tryFsResolve(civet2))
|
|
80
|
+
return civet2;
|
|
81
|
+
return;
|
|
77
82
|
}
|
|
78
83
|
var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
79
84
|
if (options.dts)
|
|
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
82
87
|
options.ts = "civet";
|
|
83
88
|
const transformTS = options.emitDeclaration || options.typecheck;
|
|
84
89
|
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
90
|
+
const implicitExtension = options.implicitExtension ?? true;
|
|
85
91
|
let fsMap = /* @__PURE__ */ new Map();
|
|
86
92
|
const sourceMaps = /* @__PURE__ */ new Map();
|
|
87
93
|
let compilerOptions;
|
|
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
196
202
|
resolveId(id, importer) {
|
|
197
203
|
if (/\0/.test(id))
|
|
198
204
|
return null;
|
|
199
|
-
if (!isCivet(id) && !isCivetTranspiled(id))
|
|
200
|
-
return null;
|
|
201
205
|
id = cleanCivetId(id);
|
|
202
|
-
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
206
|
+
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
203
207
|
if (!absolutePath)
|
|
204
208
|
return null;
|
|
205
|
-
|
|
209
|
+
let relativeId = import_path.default.relative(process.cwd(), absolutePath);
|
|
210
|
+
if (!relativeId.endsWith(".civet")) {
|
|
211
|
+
if (!implicitExtension)
|
|
212
|
+
return null;
|
|
213
|
+
const implicitId = implicitCivet(relativeId);
|
|
214
|
+
if (!implicitId)
|
|
215
|
+
return null;
|
|
216
|
+
relativeId = implicitId;
|
|
217
|
+
}
|
|
206
218
|
const relativePath = relativeId + outExt;
|
|
207
219
|
return relativePath;
|
|
208
220
|
},
|
|
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
294
306
|
},
|
|
295
307
|
vite: {
|
|
296
308
|
config(config) {
|
|
309
|
+
var _a;
|
|
297
310
|
rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
|
|
311
|
+
if (implicitExtension) {
|
|
312
|
+
config.resolve ?? (config.resolve = {});
|
|
313
|
+
(_a = config.resolve).extensions ?? (_a.extensions = []);
|
|
314
|
+
config.resolve.extensions.push(".civet");
|
|
315
|
+
}
|
|
298
316
|
},
|
|
299
317
|
async transformIndexHtml(html) {
|
|
300
318
|
return html.replace(
|
|
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
313
331
|
)
|
|
314
332
|
)
|
|
315
333
|
);
|
|
334
|
+
},
|
|
335
|
+
handleHotUpdate({ file, server, modules }) {
|
|
336
|
+
if (!file.endsWith(".civet"))
|
|
337
|
+
return;
|
|
338
|
+
const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
|
|
339
|
+
const module2 = server.moduleGraph.getModuleById(relativeId);
|
|
340
|
+
if (module2) {
|
|
341
|
+
server.moduleGraph.onFileChange(relativeId);
|
|
342
|
+
return [...modules, module2];
|
|
343
|
+
}
|
|
344
|
+
return modules;
|
|
316
345
|
}
|
|
317
346
|
}
|
|
318
347
|
};
|
package/dist/unplugin-shared.mjs
CHANGED
|
@@ -9,7 +9,6 @@ import * as fs from "fs";
|
|
|
9
9
|
import path from "path";
|
|
10
10
|
import * as tsvfs from "@typescript/vfs";
|
|
11
11
|
import os from "os";
|
|
12
|
-
var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
|
|
13
12
|
var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
|
|
14
13
|
var postfixRE = /[?#].*$/s;
|
|
15
14
|
var isWindows = os.platform() === "win32";
|
|
@@ -36,11 +35,17 @@ function tryFsResolve(file) {
|
|
|
36
35
|
return normalizePath(file);
|
|
37
36
|
return void 0;
|
|
38
37
|
}
|
|
39
|
-
function resolveAbsolutePath(rootDir, id) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
function resolveAbsolutePath(rootDir, id, implicitExtension) {
|
|
39
|
+
const file = path.join(rootDir, id);
|
|
40
|
+
return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
|
|
41
|
+
}
|
|
42
|
+
function implicitCivet(file) {
|
|
43
|
+
if (tryFsResolve(file))
|
|
44
|
+
return;
|
|
45
|
+
const civet2 = file + ".civet";
|
|
46
|
+
if (tryFsResolve(civet2))
|
|
47
|
+
return civet2;
|
|
48
|
+
return;
|
|
44
49
|
}
|
|
45
50
|
var civetUnplugin = createUnplugin((options = {}) => {
|
|
46
51
|
if (options.dts)
|
|
@@ -49,6 +54,7 @@ var civetUnplugin = createUnplugin((options = {}) => {
|
|
|
49
54
|
options.ts = "civet";
|
|
50
55
|
const transformTS = options.emitDeclaration || options.typecheck;
|
|
51
56
|
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
57
|
+
const implicitExtension = options.implicitExtension ?? true;
|
|
52
58
|
let fsMap = /* @__PURE__ */ new Map();
|
|
53
59
|
const sourceMaps = /* @__PURE__ */ new Map();
|
|
54
60
|
let compilerOptions;
|
|
@@ -163,13 +169,19 @@ var civetUnplugin = createUnplugin((options = {}) => {
|
|
|
163
169
|
resolveId(id, importer) {
|
|
164
170
|
if (/\0/.test(id))
|
|
165
171
|
return null;
|
|
166
|
-
if (!isCivet(id) && !isCivetTranspiled(id))
|
|
167
|
-
return null;
|
|
168
172
|
id = cleanCivetId(id);
|
|
169
|
-
const absolutePath = path.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : path.resolve(path.dirname(importer ?? ""), id);
|
|
173
|
+
const absolutePath = path.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : path.resolve(path.dirname(importer ?? ""), id);
|
|
170
174
|
if (!absolutePath)
|
|
171
175
|
return null;
|
|
172
|
-
|
|
176
|
+
let relativeId = path.relative(process.cwd(), absolutePath);
|
|
177
|
+
if (!relativeId.endsWith(".civet")) {
|
|
178
|
+
if (!implicitExtension)
|
|
179
|
+
return null;
|
|
180
|
+
const implicitId = implicitCivet(relativeId);
|
|
181
|
+
if (!implicitId)
|
|
182
|
+
return null;
|
|
183
|
+
relativeId = implicitId;
|
|
184
|
+
}
|
|
173
185
|
const relativePath = relativeId + outExt;
|
|
174
186
|
return relativePath;
|
|
175
187
|
},
|
|
@@ -261,7 +273,13 @@ var civetUnplugin = createUnplugin((options = {}) => {
|
|
|
261
273
|
},
|
|
262
274
|
vite: {
|
|
263
275
|
config(config) {
|
|
276
|
+
var _a;
|
|
264
277
|
rootDir = path.resolve(process.cwd(), config.root ?? "");
|
|
278
|
+
if (implicitExtension) {
|
|
279
|
+
config.resolve ?? (config.resolve = {});
|
|
280
|
+
(_a = config.resolve).extensions ?? (_a.extensions = []);
|
|
281
|
+
config.resolve.extensions.push(".civet");
|
|
282
|
+
}
|
|
265
283
|
},
|
|
266
284
|
async transformIndexHtml(html) {
|
|
267
285
|
return html.replace(
|
|
@@ -280,6 +298,17 @@ var civetUnplugin = createUnplugin((options = {}) => {
|
|
|
280
298
|
)
|
|
281
299
|
)
|
|
282
300
|
);
|
|
301
|
+
},
|
|
302
|
+
handleHotUpdate({ file, server, modules }) {
|
|
303
|
+
if (!file.endsWith(".civet"))
|
|
304
|
+
return;
|
|
305
|
+
const relativeId = slash(path.relative(process.cwd(), file) + outExt);
|
|
306
|
+
const module = server.moduleGraph.getModuleById(relativeId);
|
|
307
|
+
if (module) {
|
|
308
|
+
server.moduleGraph.onFileChange(relativeId);
|
|
309
|
+
return [...modules, module];
|
|
310
|
+
}
|
|
311
|
+
return modules;
|
|
283
312
|
}
|
|
284
313
|
}
|
|
285
314
|
};
|
package/dist/unplugin.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import * as unplugin from 'unplugin';
|
|
|
2
2
|
import { TransformResult } from 'unplugin';
|
|
3
3
|
|
|
4
4
|
type PluginOptions = {
|
|
5
|
+
implicitExtension?: boolean;
|
|
5
6
|
outputExtension?: string;
|
|
6
7
|
transformOutput?: (code: string, id: string) => TransformResult | Promise<TransformResult>;
|
|
7
8
|
emitDeclaration?: boolean;
|
package/dist/unplugin.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as unplugin from 'unplugin';
|
|
|
2
2
|
import { TransformResult } from 'unplugin';
|
|
3
3
|
|
|
4
4
|
type PluginOptions = {
|
|
5
|
+
implicitExtension?: boolean;
|
|
5
6
|
outputExtension?: string;
|
|
6
7
|
transformOutput?: (code: string, id: string) => TransformResult | Promise<TransformResult>;
|
|
7
8
|
emitDeclaration?: boolean;
|
package/dist/unplugin.js
CHANGED
|
@@ -41,7 +41,6 @@ var fs = __toESM(require("fs"));
|
|
|
41
41
|
var import_path = __toESM(require("path"));
|
|
42
42
|
var tsvfs = __toESM(require("@typescript/vfs"));
|
|
43
43
|
var import_os = __toESM(require("os"));
|
|
44
|
-
var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
|
|
45
44
|
var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
|
|
46
45
|
var postfixRE = /[?#].*$/s;
|
|
47
46
|
var isWindows = import_os.default.platform() === "win32";
|
|
@@ -68,11 +67,17 @@ function tryFsResolve(file) {
|
|
|
68
67
|
return normalizePath(file);
|
|
69
68
|
return void 0;
|
|
70
69
|
}
|
|
71
|
-
function resolveAbsolutePath(rootDir, id) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
function resolveAbsolutePath(rootDir, id, implicitExtension) {
|
|
71
|
+
const file = import_path.default.join(rootDir, id);
|
|
72
|
+
return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
|
|
73
|
+
}
|
|
74
|
+
function implicitCivet(file) {
|
|
75
|
+
if (tryFsResolve(file))
|
|
76
|
+
return;
|
|
77
|
+
const civet2 = file + ".civet";
|
|
78
|
+
if (tryFsResolve(civet2))
|
|
79
|
+
return civet2;
|
|
80
|
+
return;
|
|
76
81
|
}
|
|
77
82
|
var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
78
83
|
if (options.dts)
|
|
@@ -81,6 +86,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
81
86
|
options.ts = "civet";
|
|
82
87
|
const transformTS = options.emitDeclaration || options.typecheck;
|
|
83
88
|
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
89
|
+
const implicitExtension = options.implicitExtension ?? true;
|
|
84
90
|
let fsMap = /* @__PURE__ */ new Map();
|
|
85
91
|
const sourceMaps = /* @__PURE__ */ new Map();
|
|
86
92
|
let compilerOptions;
|
|
@@ -195,13 +201,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
195
201
|
resolveId(id, importer) {
|
|
196
202
|
if (/\0/.test(id))
|
|
197
203
|
return null;
|
|
198
|
-
if (!isCivet(id) && !isCivetTranspiled(id))
|
|
199
|
-
return null;
|
|
200
204
|
id = cleanCivetId(id);
|
|
201
|
-
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
205
|
+
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
202
206
|
if (!absolutePath)
|
|
203
207
|
return null;
|
|
204
|
-
|
|
208
|
+
let relativeId = import_path.default.relative(process.cwd(), absolutePath);
|
|
209
|
+
if (!relativeId.endsWith(".civet")) {
|
|
210
|
+
if (!implicitExtension)
|
|
211
|
+
return null;
|
|
212
|
+
const implicitId = implicitCivet(relativeId);
|
|
213
|
+
if (!implicitId)
|
|
214
|
+
return null;
|
|
215
|
+
relativeId = implicitId;
|
|
216
|
+
}
|
|
205
217
|
const relativePath = relativeId + outExt;
|
|
206
218
|
return relativePath;
|
|
207
219
|
},
|
|
@@ -293,7 +305,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
293
305
|
},
|
|
294
306
|
vite: {
|
|
295
307
|
config(config) {
|
|
308
|
+
var _a;
|
|
296
309
|
rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
|
|
310
|
+
if (implicitExtension) {
|
|
311
|
+
config.resolve ?? (config.resolve = {});
|
|
312
|
+
(_a = config.resolve).extensions ?? (_a.extensions = []);
|
|
313
|
+
config.resolve.extensions.push(".civet");
|
|
314
|
+
}
|
|
297
315
|
},
|
|
298
316
|
async transformIndexHtml(html) {
|
|
299
317
|
return html.replace(
|
|
@@ -312,6 +330,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
312
330
|
)
|
|
313
331
|
)
|
|
314
332
|
);
|
|
333
|
+
},
|
|
334
|
+
handleHotUpdate({ file, server, modules }) {
|
|
335
|
+
if (!file.endsWith(".civet"))
|
|
336
|
+
return;
|
|
337
|
+
const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
|
|
338
|
+
const module2 = server.moduleGraph.getModuleById(relativeId);
|
|
339
|
+
if (module2) {
|
|
340
|
+
server.moduleGraph.onFileChange(relativeId);
|
|
341
|
+
return [...modules, module2];
|
|
342
|
+
}
|
|
343
|
+
return modules;
|
|
315
344
|
}
|
|
316
345
|
}
|
|
317
346
|
};
|
package/dist/vite.js
CHANGED
|
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
|
|
|
42
42
|
var import_path = __toESM(require("path"));
|
|
43
43
|
var tsvfs = __toESM(require("@typescript/vfs"));
|
|
44
44
|
var import_os = __toESM(require("os"));
|
|
45
|
-
var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
|
|
46
45
|
var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
|
|
47
46
|
var postfixRE = /[?#].*$/s;
|
|
48
47
|
var isWindows = import_os.default.platform() === "win32";
|
|
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
|
|
|
69
68
|
return normalizePath(file);
|
|
70
69
|
return void 0;
|
|
71
70
|
}
|
|
72
|
-
function resolveAbsolutePath(rootDir, id) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
function resolveAbsolutePath(rootDir, id, implicitExtension) {
|
|
72
|
+
const file = import_path.default.join(rootDir, id);
|
|
73
|
+
return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
|
|
74
|
+
}
|
|
75
|
+
function implicitCivet(file) {
|
|
76
|
+
if (tryFsResolve(file))
|
|
77
|
+
return;
|
|
78
|
+
const civet2 = file + ".civet";
|
|
79
|
+
if (tryFsResolve(civet2))
|
|
80
|
+
return civet2;
|
|
81
|
+
return;
|
|
77
82
|
}
|
|
78
83
|
var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
79
84
|
if (options.dts)
|
|
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
82
87
|
options.ts = "civet";
|
|
83
88
|
const transformTS = options.emitDeclaration || options.typecheck;
|
|
84
89
|
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
90
|
+
const implicitExtension = options.implicitExtension ?? true;
|
|
85
91
|
let fsMap = /* @__PURE__ */ new Map();
|
|
86
92
|
const sourceMaps = /* @__PURE__ */ new Map();
|
|
87
93
|
let compilerOptions;
|
|
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
196
202
|
resolveId(id, importer) {
|
|
197
203
|
if (/\0/.test(id))
|
|
198
204
|
return null;
|
|
199
|
-
if (!isCivet(id) && !isCivetTranspiled(id))
|
|
200
|
-
return null;
|
|
201
205
|
id = cleanCivetId(id);
|
|
202
|
-
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
206
|
+
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
203
207
|
if (!absolutePath)
|
|
204
208
|
return null;
|
|
205
|
-
|
|
209
|
+
let relativeId = import_path.default.relative(process.cwd(), absolutePath);
|
|
210
|
+
if (!relativeId.endsWith(".civet")) {
|
|
211
|
+
if (!implicitExtension)
|
|
212
|
+
return null;
|
|
213
|
+
const implicitId = implicitCivet(relativeId);
|
|
214
|
+
if (!implicitId)
|
|
215
|
+
return null;
|
|
216
|
+
relativeId = implicitId;
|
|
217
|
+
}
|
|
206
218
|
const relativePath = relativeId + outExt;
|
|
207
219
|
return relativePath;
|
|
208
220
|
},
|
|
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
294
306
|
},
|
|
295
307
|
vite: {
|
|
296
308
|
config(config) {
|
|
309
|
+
var _a;
|
|
297
310
|
rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
|
|
311
|
+
if (implicitExtension) {
|
|
312
|
+
config.resolve ?? (config.resolve = {});
|
|
313
|
+
(_a = config.resolve).extensions ?? (_a.extensions = []);
|
|
314
|
+
config.resolve.extensions.push(".civet");
|
|
315
|
+
}
|
|
298
316
|
},
|
|
299
317
|
async transformIndexHtml(html) {
|
|
300
318
|
return html.replace(
|
|
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
313
331
|
)
|
|
314
332
|
)
|
|
315
333
|
);
|
|
334
|
+
},
|
|
335
|
+
handleHotUpdate({ file, server, modules }) {
|
|
336
|
+
if (!file.endsWith(".civet"))
|
|
337
|
+
return;
|
|
338
|
+
const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
|
|
339
|
+
const module2 = server.moduleGraph.getModuleById(relativeId);
|
|
340
|
+
if (module2) {
|
|
341
|
+
server.moduleGraph.onFileChange(relativeId);
|
|
342
|
+
return [...modules, module2];
|
|
343
|
+
}
|
|
344
|
+
return modules;
|
|
316
345
|
}
|
|
317
346
|
}
|
|
318
347
|
};
|
package/dist/webpack.js
CHANGED
|
@@ -42,7 +42,6 @@ var fs = __toESM(require("fs"));
|
|
|
42
42
|
var import_path = __toESM(require("path"));
|
|
43
43
|
var tsvfs = __toESM(require("@typescript/vfs"));
|
|
44
44
|
var import_os = __toESM(require("os"));
|
|
45
|
-
var isCivet = (id) => /\.civet([?#].*)?$/.test(id);
|
|
46
45
|
var isCivetTranspiled = (id) => /\.civet\.[jt]sx([?#].*)?$/.test(id);
|
|
47
46
|
var postfixRE = /[?#].*$/s;
|
|
48
47
|
var isWindows = import_os.default.platform() === "win32";
|
|
@@ -69,11 +68,17 @@ function tryFsResolve(file) {
|
|
|
69
68
|
return normalizePath(file);
|
|
70
69
|
return void 0;
|
|
71
70
|
}
|
|
72
|
-
function resolveAbsolutePath(rootDir, id) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
function resolveAbsolutePath(rootDir, id, implicitExtension) {
|
|
72
|
+
const file = import_path.default.join(rootDir, id);
|
|
73
|
+
return tryFsResolve(file) || implicitExtension && implicitCivet(file) || tryFsResolve(id) || implicitExtension && implicitCivet(id);
|
|
74
|
+
}
|
|
75
|
+
function implicitCivet(file) {
|
|
76
|
+
if (tryFsResolve(file))
|
|
77
|
+
return;
|
|
78
|
+
const civet2 = file + ".civet";
|
|
79
|
+
if (tryFsResolve(civet2))
|
|
80
|
+
return civet2;
|
|
81
|
+
return;
|
|
77
82
|
}
|
|
78
83
|
var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
79
84
|
if (options.dts)
|
|
@@ -82,6 +87,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
82
87
|
options.ts = "civet";
|
|
83
88
|
const transformTS = options.emitDeclaration || options.typecheck;
|
|
84
89
|
const outExt = options.outputExtension ?? (options.ts === "preserve" ? ".tsx" : ".jsx");
|
|
90
|
+
const implicitExtension = options.implicitExtension ?? true;
|
|
85
91
|
let fsMap = /* @__PURE__ */ new Map();
|
|
86
92
|
const sourceMaps = /* @__PURE__ */ new Map();
|
|
87
93
|
let compilerOptions;
|
|
@@ -196,13 +202,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
196
202
|
resolveId(id, importer) {
|
|
197
203
|
if (/\0/.test(id))
|
|
198
204
|
return null;
|
|
199
|
-
if (!isCivet(id) && !isCivetTranspiled(id))
|
|
200
|
-
return null;
|
|
201
205
|
id = cleanCivetId(id);
|
|
202
|
-
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
206
|
+
const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id, implicitExtension) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
|
|
203
207
|
if (!absolutePath)
|
|
204
208
|
return null;
|
|
205
|
-
|
|
209
|
+
let relativeId = import_path.default.relative(process.cwd(), absolutePath);
|
|
210
|
+
if (!relativeId.endsWith(".civet")) {
|
|
211
|
+
if (!implicitExtension)
|
|
212
|
+
return null;
|
|
213
|
+
const implicitId = implicitCivet(relativeId);
|
|
214
|
+
if (!implicitId)
|
|
215
|
+
return null;
|
|
216
|
+
relativeId = implicitId;
|
|
217
|
+
}
|
|
206
218
|
const relativePath = relativeId + outExt;
|
|
207
219
|
return relativePath;
|
|
208
220
|
},
|
|
@@ -294,7 +306,13 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
294
306
|
},
|
|
295
307
|
vite: {
|
|
296
308
|
config(config) {
|
|
309
|
+
var _a;
|
|
297
310
|
rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
|
|
311
|
+
if (implicitExtension) {
|
|
312
|
+
config.resolve ?? (config.resolve = {});
|
|
313
|
+
(_a = config.resolve).extensions ?? (_a.extensions = []);
|
|
314
|
+
config.resolve.extensions.push(".civet");
|
|
315
|
+
}
|
|
298
316
|
},
|
|
299
317
|
async transformIndexHtml(html) {
|
|
300
318
|
return html.replace(
|
|
@@ -313,6 +331,17 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
313
331
|
)
|
|
314
332
|
)
|
|
315
333
|
);
|
|
334
|
+
},
|
|
335
|
+
handleHotUpdate({ file, server, modules }) {
|
|
336
|
+
if (!file.endsWith(".civet"))
|
|
337
|
+
return;
|
|
338
|
+
const relativeId = slash(import_path.default.relative(process.cwd(), file) + outExt);
|
|
339
|
+
const module2 = server.moduleGraph.getModuleById(relativeId);
|
|
340
|
+
if (module2) {
|
|
341
|
+
server.moduleGraph.onFileChange(relativeId);
|
|
342
|
+
return [...modules, module2];
|
|
343
|
+
}
|
|
344
|
+
return modules;
|
|
316
345
|
}
|
|
317
346
|
}
|
|
318
347
|
};
|