@danielx/civet 0.7.4 → 0.7.5
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/astro.js +6 -6
- package/dist/babel-plugin.mjs +4 -2
- package/dist/browser.js +214 -132
- package/dist/bun-civet.mjs +4 -4
- package/dist/civet +4 -4
- package/dist/config.js +4 -1
- package/dist/esbuild-plugin.js +1 -1
- package/dist/esbuild.js +6 -6
- package/dist/esm.mjs +1 -1
- package/dist/main.js +215 -132
- package/dist/main.mjs +214 -132
- package/dist/rollup.js +6 -6
- package/dist/types.d.ts +15 -5
- package/dist/unplugin-shared.mjs +6 -6
- package/dist/unplugin.js +6 -6
- package/dist/vite.js +6 -6
- package/dist/webpack.js +6 -6
- package/package.json +2 -2
package/dist/browser.js
CHANGED
|
@@ -426,14 +426,14 @@ var Civet = (() => {
|
|
|
426
426
|
}, [1, 1]);
|
|
427
427
|
return [line, column];
|
|
428
428
|
}
|
|
429
|
-
function validate(input, result, { filename }) {
|
|
429
|
+
function validate(input, result, { filename: filename2 }) {
|
|
430
430
|
if (result && result.pos === input.length)
|
|
431
431
|
return result.value;
|
|
432
432
|
const expectations = Array.from(new Set(failExpected.slice(0, failIndex)));
|
|
433
433
|
let l = location(input, maxFailPos), [line, column] = l;
|
|
434
434
|
if (result && result.pos > maxFailPos) {
|
|
435
435
|
l = location(input, result.pos);
|
|
436
|
-
throw new Error(`${
|
|
436
|
+
throw new Error(`${filename2}:${line}:${column} Unconsumed input at #{l}
|
|
437
437
|
|
|
438
438
|
${input.slice(result.pos)}
|
|
439
439
|
`);
|
|
@@ -445,11 +445,11 @@ ${input.slice(result.pos)}
|
|
|
445
445
|
hint = JSON.stringify(hint);
|
|
446
446
|
else
|
|
447
447
|
hint = "EOF";
|
|
448
|
-
const error = new ParseError(`${
|
|
448
|
+
const error = new ParseError(`${filename2}:${line}:${column} Failed to parse
|
|
449
449
|
Expected:
|
|
450
450
|
${expectations.join("\n ")}
|
|
451
451
|
Found: ${hint}
|
|
452
|
-
`, "ParseError",
|
|
452
|
+
`, "ParseError", filename2, line, column, maxFailPos);
|
|
453
453
|
throw error;
|
|
454
454
|
}
|
|
455
455
|
if (result) {
|
|
@@ -473,11 +473,11 @@ ${input.slice(result.pos)}
|
|
|
473
473
|
};
|
|
474
474
|
}
|
|
475
475
|
var ParseError = class extends Error {
|
|
476
|
-
constructor(message, name,
|
|
476
|
+
constructor(message, name, filename2, line, column, offset) {
|
|
477
477
|
super(message);
|
|
478
478
|
this.message = message;
|
|
479
479
|
this.name = name;
|
|
480
|
-
this.filename =
|
|
480
|
+
this.filename = filename2;
|
|
481
481
|
this.line = line;
|
|
482
482
|
this.column = column;
|
|
483
483
|
this.offset = offset;
|
|
@@ -495,6 +495,7 @@ ${input.slice(result.pos)}
|
|
|
495
495
|
isCompileError: () => isCompileError,
|
|
496
496
|
lib: () => lib_exports,
|
|
497
497
|
parse: () => parse,
|
|
498
|
+
parseProgram: () => parseProgram,
|
|
498
499
|
prune: () => prune,
|
|
499
500
|
util: () => util_exports
|
|
500
501
|
});
|
|
@@ -554,6 +555,7 @@ ${input.slice(result.pos)}
|
|
|
554
555
|
processCoffeeInterpolation: () => processCoffeeInterpolation,
|
|
555
556
|
processForInOf: () => processForInOf,
|
|
556
557
|
processProgram: () => processProgram,
|
|
558
|
+
processProgramAsync: () => processProgramAsync,
|
|
557
559
|
processUnaryExpression: () => processUnaryExpression,
|
|
558
560
|
quoteString: () => quoteString,
|
|
559
561
|
reorderBindingRestProperty: () => reorderBindingRestProperty,
|
|
@@ -1176,14 +1178,12 @@ ${input.slice(result.pos)}
|
|
|
1176
1178
|
if (!prefix.length)
|
|
1177
1179
|
return;
|
|
1178
1180
|
if (isConstructor) {
|
|
1179
|
-
const superCalls = gatherNodes(
|
|
1180
|
-
|
|
1181
|
-
|
|
1181
|
+
const superCalls = gatherNodes(
|
|
1182
|
+
expressions,
|
|
1183
|
+
(a) => typeof a === "object" && a != null && "type" in a && a.type === "CallExpression" && "children" in a && Array.isArray(a.children) && a.children.length >= 1 && typeof a.children[0] === "object" && a.children[0] != null && "token" in a.children[0] && a.children[0].token === "super"
|
|
1184
|
+
);
|
|
1182
1185
|
if (superCalls.length) {
|
|
1183
|
-
const { child } = findAncestor(
|
|
1184
|
-
superCalls[0],
|
|
1185
|
-
(ancestor) => ancestor === block
|
|
1186
|
-
);
|
|
1186
|
+
const { child } = findAncestor(superCalls[0], (a1) => a1 === block);
|
|
1187
1187
|
const index = findChildIndex(expressions, child);
|
|
1188
1188
|
if (index < 0) {
|
|
1189
1189
|
throw new Error("Could not find super call within top-level expressions");
|
|
@@ -1268,7 +1268,7 @@ ${input.slice(result.pos)}
|
|
|
1268
1268
|
return block;
|
|
1269
1269
|
}
|
|
1270
1270
|
function braceBlock(block) {
|
|
1271
|
-
if (block.bare) {
|
|
1271
|
+
if (block.bare && !block.root) {
|
|
1272
1272
|
if (block.children === block.expressions) {
|
|
1273
1273
|
block.children = [block.expressions];
|
|
1274
1274
|
}
|
|
@@ -1320,7 +1320,7 @@ ${input.slice(result.pos)}
|
|
|
1320
1320
|
function replaceBlockExpression(node, child, replacement) {
|
|
1321
1321
|
let found = false;
|
|
1322
1322
|
const { expressions } = node;
|
|
1323
|
-
for (let i1 = 0,
|
|
1323
|
+
for (let i1 = 0, len3 = expressions.length; i1 < len3; i1++) {
|
|
1324
1324
|
const statement = expressions[i1];
|
|
1325
1325
|
const [, s] = statement;
|
|
1326
1326
|
if (s === child) {
|
|
@@ -1402,7 +1402,7 @@ ${input.slice(result.pos)}
|
|
|
1402
1402
|
return false;
|
|
1403
1403
|
}
|
|
1404
1404
|
if (Array.isArray(exp)) {
|
|
1405
|
-
for (let i3 = 0,
|
|
1405
|
+
for (let i3 = 0, len22 = exp.length; i3 < len22; i3++) {
|
|
1406
1406
|
const child = exp[i3];
|
|
1407
1407
|
if (!(child != null)) {
|
|
1408
1408
|
continue;
|
|
@@ -1445,6 +1445,9 @@ ${input.slice(result.pos)}
|
|
|
1445
1445
|
}
|
|
1446
1446
|
|
|
1447
1447
|
// source/parser/util.civet
|
|
1448
|
+
function len(arr, length) {
|
|
1449
|
+
return arr.length === length;
|
|
1450
|
+
}
|
|
1448
1451
|
var assert = {
|
|
1449
1452
|
equal(a, b, msg) {
|
|
1450
1453
|
if (a !== b) {
|
|
@@ -1468,7 +1471,7 @@ ${input.slice(result.pos)}
|
|
|
1468
1471
|
node.parent = parent;
|
|
1469
1472
|
}
|
|
1470
1473
|
if (node.children) {
|
|
1471
|
-
for (let ref1 = node.children, i1 = 0,
|
|
1474
|
+
for (let ref1 = node.children, i1 = 0, len1 = ref1.length; i1 < len1; i1++) {
|
|
1472
1475
|
const child = ref1[i1];
|
|
1473
1476
|
addParentPointers(child, node);
|
|
1474
1477
|
}
|
|
@@ -1525,8 +1528,7 @@ ${input.slice(result.pos)}
|
|
|
1525
1528
|
if (node?.type !== "BlockStatement")
|
|
1526
1529
|
return false;
|
|
1527
1530
|
const { bare, expressions } = node;
|
|
1528
|
-
return bare &&
|
|
1529
|
-
(expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
|
|
1531
|
+
return bare && (Array.isArray(expressions) && len(expressions, 0) || Array.isArray(expressions) && len(expressions, 1) && Array.isArray(expressions[0]) && expressions[0].length >= 2 && typeof expressions[0][1] === "object" && expressions[0][1] != null && "type" in expressions[0][1] && expressions[0][1].type === "EmptyStatement");
|
|
1530
1532
|
}
|
|
1531
1533
|
function isFunction(node) {
|
|
1532
1534
|
const { type } = node;
|
|
@@ -1883,7 +1885,7 @@ ${input.slice(result.pos)}
|
|
|
1883
1885
|
return;
|
|
1884
1886
|
}
|
|
1885
1887
|
if (Array.isArray(node)) {
|
|
1886
|
-
for (let i2 = 0,
|
|
1888
|
+
for (let i2 = 0, len22 = node.length; i2 < len22; i2++) {
|
|
1887
1889
|
const child = node[i2];
|
|
1888
1890
|
updateParentPointers(child, parent, depth);
|
|
1889
1891
|
}
|
|
@@ -1894,7 +1896,7 @@ ${input.slice(result.pos)}
|
|
|
1894
1896
|
node.parent = parent;
|
|
1895
1897
|
}
|
|
1896
1898
|
if (depth && isParent(node)) {
|
|
1897
|
-
for (let ref4 = node.children, i3 = 0,
|
|
1899
|
+
for (let ref4 = node.children, i3 = 0, len3 = ref4.length; i3 < len3; i3++) {
|
|
1898
1900
|
const child = ref4[i3];
|
|
1899
1901
|
updateParentPointers(child, node, depth - 1);
|
|
1900
1902
|
}
|
|
@@ -2025,7 +2027,7 @@ ${input.slice(result.pos)}
|
|
|
2025
2027
|
}
|
|
2026
2028
|
function flatJoin(array, separator) {
|
|
2027
2029
|
const result = [];
|
|
2028
|
-
for (let i4 = 0,
|
|
2030
|
+
for (let i4 = 0, len4 = array.length; i4 < len4; i4++) {
|
|
2029
2031
|
const i = i4;
|
|
2030
2032
|
const items = array[i4];
|
|
2031
2033
|
if (i) {
|
|
@@ -2048,7 +2050,7 @@ ${input.slice(result.pos)}
|
|
|
2048
2050
|
if (!(children != null)) {
|
|
2049
2051
|
return -1;
|
|
2050
2052
|
}
|
|
2051
|
-
for (let i1 = 0,
|
|
2053
|
+
for (let i1 = 0, len3 = children.length; i1 < len3; i1++) {
|
|
2052
2054
|
const i = i1;
|
|
2053
2055
|
const c = children[i1];
|
|
2054
2056
|
if (c === child || Array.isArray(c) && arrayRecurse(c)) {
|
|
@@ -2163,7 +2165,7 @@ ${input.slice(result.pos)}
|
|
|
2163
2165
|
["**"]
|
|
2164
2166
|
];
|
|
2165
2167
|
var precedenceMap = /* @__PURE__ */ new Map();
|
|
2166
|
-
for (let i1 = 0,
|
|
2168
|
+
for (let i1 = 0, len3 = precedenceOrder.length; i1 < len3; i1++) {
|
|
2167
2169
|
const prec = i1;
|
|
2168
2170
|
const ops = precedenceOrder[i1];
|
|
2169
2171
|
for (let i2 = 0, len1 = ops.length; i2 < len1; i2++) {
|
|
@@ -2274,7 +2276,7 @@ ${input.slice(result.pos)}
|
|
|
2274
2276
|
} else {
|
|
2275
2277
|
b = recurse(b);
|
|
2276
2278
|
}
|
|
2277
|
-
if (op.token === "instanceof" && b.type === "Literal" && b.children
|
|
2279
|
+
if (op.token === "instanceof" && (typeof b === "object" && b != null && "type" in b && b.type === "Literal" && "children" in b && Array.isArray(b.children) && b.children.length >= 1 && typeof b.children[0] === "object" && b.children[0] != null && "type" in b.children[0] && b.children[0].type === "StringLiteral")) {
|
|
2278
2280
|
a = ["typeof ", makeLeftHandSideExpression(a)];
|
|
2279
2281
|
if (op.negated) {
|
|
2280
2282
|
op = { ...op, token: "!==", negated: false };
|
|
@@ -2379,7 +2381,7 @@ ${input.slice(result.pos)}
|
|
|
2379
2381
|
let start = 0;
|
|
2380
2382
|
const chains = [];
|
|
2381
2383
|
var i = 0;
|
|
2382
|
-
for (let i3 = 0,
|
|
2384
|
+
for (let i3 = 0, len22 = binops.length; i3 < len22; i3++) {
|
|
2383
2385
|
var i = i3;
|
|
2384
2386
|
var [, op] = binops[i3];
|
|
2385
2387
|
if (isRelationalOp(op)) {
|
|
@@ -2989,7 +2991,7 @@ ${input.slice(result.pos)}
|
|
|
2989
2991
|
}
|
|
2990
2992
|
|
|
2991
2993
|
// source/parser/declaration.civet
|
|
2992
|
-
function
|
|
2994
|
+
function len2(arr, length) {
|
|
2993
2995
|
return arr.length === length;
|
|
2994
2996
|
}
|
|
2995
2997
|
function processAssignmentDeclaration(decl, pattern, suffix, ws, assign, e) {
|
|
@@ -3187,7 +3189,7 @@ ${input.slice(result.pos)}
|
|
|
3187
3189
|
return;
|
|
3188
3190
|
}
|
|
3189
3191
|
let { expression } = condition;
|
|
3190
|
-
if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "UnaryExpression" && "children" in expression && Array.isArray(expression.children) &&
|
|
3192
|
+
if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "UnaryExpression" && "children" in expression && Array.isArray(expression.children) && len2(expression.children, 2) && expression.children[0] === "!" && typeof expression.children[1] === "object" && expression.children[1] != null && "type" in expression.children[1] && expression.children[1].type === "ParenthesizedExpression" && "expression" in expression.children[1]) {
|
|
3191
3193
|
const { type: type1, children: [, { type: type2, expression: expression2 }] } = expression;
|
|
3192
3194
|
const type = [type1, type2];
|
|
3193
3195
|
expression = expression2;
|
|
@@ -3196,7 +3198,7 @@ ${input.slice(result.pos)}
|
|
|
3196
3198
|
const { ref, pattern } = expression;
|
|
3197
3199
|
if (pattern) {
|
|
3198
3200
|
const conditions = getPatternConditions(pattern, ref).filter((c) => {
|
|
3199
|
-
if (Array.isArray(c) &&
|
|
3201
|
+
if (Array.isArray(c) && len2(c, 2) && c[0] === ref && c[1] === " != null") {
|
|
3200
3202
|
const [,] = c;
|
|
3201
3203
|
return false;
|
|
3202
3204
|
} else {
|
|
@@ -4113,36 +4115,79 @@ ${input.slice(result.pos)}
|
|
|
4113
4115
|
if (!getInitialConfig()?.comptime) {
|
|
4114
4116
|
return;
|
|
4115
4117
|
}
|
|
4116
|
-
|
|
4118
|
+
let prepareEval = () => {
|
|
4119
|
+
};
|
|
4120
|
+
if (getSync()) {
|
|
4121
|
+
runComptime(statements, prepareEval);
|
|
4122
|
+
return;
|
|
4123
|
+
} else {
|
|
4124
|
+
return (async () => {
|
|
4125
|
+
{
|
|
4126
|
+
try {
|
|
4127
|
+
const path = (await import("node:path")).default;
|
|
4128
|
+
const { createRequire } = await import("node:module");
|
|
4129
|
+
return prepareEval = () => {
|
|
4130
|
+
global.__filename = path.resolve(getFilename() ?? "");
|
|
4131
|
+
global.__dirname = path.dirname(global.__filename);
|
|
4132
|
+
return global.require = createRequire(global.__filename);
|
|
4133
|
+
};
|
|
4134
|
+
} catch (e) {
|
|
4135
|
+
return;
|
|
4136
|
+
}
|
|
4137
|
+
}
|
|
4138
|
+
})().then(async () => {
|
|
4139
|
+
await Promise.all(runComptime(statements, prepareEval));
|
|
4140
|
+
});
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
function runComptime(statements, prepareEval) {
|
|
4144
|
+
const sync2 = getSync();
|
|
4145
|
+
return gatherRecursive(
|
|
4117
4146
|
statements,
|
|
4118
4147
|
(node) => {
|
|
4119
4148
|
return node.type === "ComptimeStatement" || node.type === "ComptimeExpression";
|
|
4120
4149
|
}
|
|
4121
|
-
).
|
|
4150
|
+
).map((exp) => {
|
|
4122
4151
|
const content = exp.type === "ComptimeStatement" ? exp.block : exp.expression;
|
|
4123
4152
|
const options = { js: true };
|
|
4124
4153
|
const js = generate_default(prune(content), options);
|
|
4125
4154
|
if (options.errors != null) {
|
|
4126
4155
|
return;
|
|
4127
4156
|
}
|
|
4128
|
-
|
|
4157
|
+
prepareEval();
|
|
4158
|
+
let output = eval?.(`"use strict";${js}`);
|
|
4159
|
+
let promise;
|
|
4129
4160
|
if (exp.type === "ComptimeExpression") {
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4161
|
+
const finish = () => {
|
|
4162
|
+
let string;
|
|
4163
|
+
try {
|
|
4164
|
+
string = serialize(output);
|
|
4165
|
+
} catch (e) {
|
|
4166
|
+
exp.children = [
|
|
4167
|
+
{
|
|
4168
|
+
type: "Error",
|
|
4169
|
+
message: `comptime result ${output} not serializable: ${e}`
|
|
4170
|
+
}
|
|
4171
|
+
];
|
|
4172
|
+
return;
|
|
4173
|
+
}
|
|
4174
|
+
return exp.children = [string];
|
|
4175
|
+
};
|
|
4176
|
+
if (sync2) {
|
|
4177
|
+
finish();
|
|
4178
|
+
} else {
|
|
4179
|
+
promise = (async () => {
|
|
4135
4180
|
{
|
|
4136
|
-
|
|
4137
|
-
|
|
4181
|
+
output = await output;
|
|
4182
|
+
return finish();
|
|
4138
4183
|
}
|
|
4139
|
-
|
|
4140
|
-
return;
|
|
4184
|
+
})();
|
|
4141
4185
|
}
|
|
4142
|
-
return exp.children = [string];
|
|
4143
4186
|
} else {
|
|
4144
|
-
|
|
4187
|
+
promise = output;
|
|
4188
|
+
exp.children = [];
|
|
4145
4189
|
}
|
|
4190
|
+
return promise;
|
|
4146
4191
|
});
|
|
4147
4192
|
}
|
|
4148
4193
|
function serialize(value) {
|
|
@@ -4250,7 +4295,7 @@ ${input.slice(result.pos)}
|
|
|
4250
4295
|
case Object.prototype: {
|
|
4251
4296
|
let objStr = "{";
|
|
4252
4297
|
let descStr = "";
|
|
4253
|
-
for (let ref2 = Object.getOwnPropertyNames(val).concat(Object.getOwnPropertySymbols(val)), i = 0,
|
|
4298
|
+
for (let ref2 = Object.getOwnPropertyNames(val).concat(Object.getOwnPropertySymbols(val)), i = 0, len3 = ref2.length; i < len3; i++) {
|
|
4254
4299
|
const prop = ref2[i];
|
|
4255
4300
|
const desc = Object.getOwnPropertyDescriptor(val, prop);
|
|
4256
4301
|
if (desc.enumerable && desc.configurable && desc.writable) {
|
|
@@ -4339,7 +4384,7 @@ ${input.slice(result.pos)}
|
|
|
4339
4384
|
}
|
|
4340
4385
|
function reduceIndentLevel(str, dedent, tab) {
|
|
4341
4386
|
if (tab != null && tab != 1) {
|
|
4342
|
-
for (let i1 = 0,
|
|
4387
|
+
for (let i1 = 0, len3 = str.length; i1 < len3; i1++) {
|
|
4343
4388
|
const i = i1;
|
|
4344
4389
|
const char = str[i1];
|
|
4345
4390
|
if (!dedent) {
|
|
@@ -4421,7 +4466,7 @@ ${input.slice(result.pos)}
|
|
|
4421
4466
|
;
|
|
4422
4467
|
const dedent = ref1;
|
|
4423
4468
|
let results = [s];
|
|
4424
|
-
for (let i3 = 0,
|
|
4469
|
+
for (let i3 = 0, len22 = strWithSubstitutions.length; i3 < len22; i3++) {
|
|
4425
4470
|
const i = i3;
|
|
4426
4471
|
let part = strWithSubstitutions[i3];
|
|
4427
4472
|
if (part.token != null) {
|
|
@@ -4551,9 +4596,8 @@ ${input.slice(result.pos)}
|
|
|
4551
4596
|
return true;
|
|
4552
4597
|
}
|
|
4553
4598
|
function expressionizeBlock(blockOrExpression) {
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
const { expressions } = ref1;
|
|
4599
|
+
if (blockOrExpression && typeof blockOrExpression === "object" && "expressions" in blockOrExpression) {
|
|
4600
|
+
const { expressions } = blockOrExpression;
|
|
4557
4601
|
const l = expressions.length;
|
|
4558
4602
|
const results = [];
|
|
4559
4603
|
let i1 = 0;
|
|
@@ -4652,7 +4696,7 @@ ${input.slice(result.pos)}
|
|
|
4652
4696
|
}
|
|
4653
4697
|
function processCallMemberExpression(node) {
|
|
4654
4698
|
const { children } = node;
|
|
4655
|
-
if (children[0]
|
|
4699
|
+
if (Array.isArray(children) && children.length >= 2 && typeof children[0] === "object" && children[0] != null && "parenthesizedOp" in children[0] && typeof children[0].parenthesizedOp === "object" && children[0].parenthesizedOp != null && "token" in children[0].parenthesizedOp && typeof children[1] === "object" && children[1] != null && "type" in children[1] && children[1].type === "Call") {
|
|
4656
4700
|
const op = children[0].parenthesizedOp;
|
|
4657
4701
|
let call = children[1];
|
|
4658
4702
|
const args = [...call.args];
|
|
@@ -4746,14 +4790,14 @@ ${input.slice(result.pos)}
|
|
|
4746
4790
|
});
|
|
4747
4791
|
}
|
|
4748
4792
|
}
|
|
4749
|
-
let
|
|
4793
|
+
let ref1;
|
|
4750
4794
|
let object = {
|
|
4751
4795
|
type: "ObjectExpression",
|
|
4752
4796
|
children: [
|
|
4753
4797
|
glob.object.children[0],
|
|
4754
4798
|
// {
|
|
4755
4799
|
...parts,
|
|
4756
|
-
(
|
|
4800
|
+
(ref1 = glob.object.children)[ref1.length - 1]
|
|
4757
4801
|
// whitespace and }
|
|
4758
4802
|
],
|
|
4759
4803
|
properties: parts,
|
|
@@ -4805,7 +4849,7 @@ ${input.slice(result.pos)}
|
|
|
4805
4849
|
throw new Error("replaceNode failed: node has no parent");
|
|
4806
4850
|
}
|
|
4807
4851
|
function recurse(children) {
|
|
4808
|
-
for (let i3 = 0,
|
|
4852
|
+
for (let i3 = 0, len22 = children.length; i3 < len22; i3++) {
|
|
4809
4853
|
const i = i3;
|
|
4810
4854
|
const child = children[i3];
|
|
4811
4855
|
if (child === node) {
|
|
@@ -4895,8 +4939,8 @@ ${input.slice(result.pos)}
|
|
|
4895
4939
|
return { type: "Error", message: "cannot use `type` in dynamic import" };
|
|
4896
4940
|
} else {
|
|
4897
4941
|
const { source, binding } = specifier;
|
|
4898
|
-
let
|
|
4899
|
-
const delim = (
|
|
4942
|
+
let ref2;
|
|
4943
|
+
const delim = (ref2 = specifier.children)[ref2.length - 1];
|
|
4900
4944
|
return {
|
|
4901
4945
|
type: pattern ? "BindingProperty" : "Property",
|
|
4902
4946
|
name: source,
|
|
@@ -4906,7 +4950,7 @@ ${input.slice(result.pos)}
|
|
|
4906
4950
|
};
|
|
4907
4951
|
}
|
|
4908
4952
|
});
|
|
4909
|
-
let
|
|
4953
|
+
let ref3;
|
|
4910
4954
|
return {
|
|
4911
4955
|
type: pattern ? "ObjectBindingPattern" : "ObjectExpression",
|
|
4912
4956
|
names: node.names,
|
|
@@ -4915,7 +4959,7 @@ ${input.slice(result.pos)}
|
|
|
4915
4959
|
node.children[0],
|
|
4916
4960
|
// {
|
|
4917
4961
|
properties,
|
|
4918
|
-
(
|
|
4962
|
+
(ref3 = node.children)[ref3.length - 1]
|
|
4919
4963
|
// }
|
|
4920
4964
|
]
|
|
4921
4965
|
};
|
|
@@ -5092,17 +5136,17 @@ ${input.slice(result.pos)}
|
|
|
5092
5136
|
statements,
|
|
5093
5137
|
(n) => n.type === "AssignmentExpression" && n.names === null,
|
|
5094
5138
|
(exp) => {
|
|
5095
|
-
let { lhs: $1, expression: $2 } = exp, tail = [], i = 0,
|
|
5139
|
+
let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len3 = $1.length;
|
|
5096
5140
|
let block;
|
|
5097
|
-
let
|
|
5098
|
-
if (exp.parent?.type === "BlockStatement" && !(
|
|
5141
|
+
let ref4;
|
|
5142
|
+
if (exp.parent?.type === "BlockStatement" && !(ref4 = $1[$1.length - 1])?.[ref4.length - 1]?.special) {
|
|
5099
5143
|
block = makeBlockFragment();
|
|
5100
|
-
let
|
|
5101
|
-
if (
|
|
5144
|
+
let ref5;
|
|
5145
|
+
if (ref5 = prependStatementExpressionBlock(
|
|
5102
5146
|
{ type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
|
|
5103
5147
|
block
|
|
5104
5148
|
)) {
|
|
5105
|
-
const ref =
|
|
5149
|
+
const ref = ref5;
|
|
5106
5150
|
exp.children = exp.children.map(function(c) {
|
|
5107
5151
|
if (c === $2)
|
|
5108
5152
|
return ref;
|
|
@@ -5132,7 +5176,7 @@ ${input.slice(result.pos)}
|
|
|
5132
5176
|
}
|
|
5133
5177
|
}
|
|
5134
5178
|
let wrapped = false;
|
|
5135
|
-
while (i <
|
|
5179
|
+
while (i < len3) {
|
|
5136
5180
|
const lastAssignment = $1[i++];
|
|
5137
5181
|
const [, lhs, , op] = lastAssignment;
|
|
5138
5182
|
if (op.token !== "=")
|
|
@@ -5145,7 +5189,7 @@ ${input.slice(result.pos)}
|
|
|
5145
5189
|
}
|
|
5146
5190
|
}
|
|
5147
5191
|
}
|
|
5148
|
-
i =
|
|
5192
|
+
i = len3 - 1;
|
|
5149
5193
|
while (i >= 0) {
|
|
5150
5194
|
const lastAssignment = $1[i];
|
|
5151
5195
|
if (lastAssignment[3].token === "=") {
|
|
@@ -5181,14 +5225,14 @@ ${input.slice(result.pos)}
|
|
|
5181
5225
|
}
|
|
5182
5226
|
i--;
|
|
5183
5227
|
}
|
|
5184
|
-
i =
|
|
5228
|
+
i = len3 - 1;
|
|
5185
5229
|
const optionalChainRef = makeRef();
|
|
5186
5230
|
while (i >= 0) {
|
|
5187
5231
|
const assignment = $1[i];
|
|
5188
5232
|
const [ws1, lhs, ws2, op] = assignment;
|
|
5189
5233
|
if (lhs.type === "MemberExpression" || lhs.type === "CallExpression") {
|
|
5190
5234
|
const newMemberExp = unchainOptionalMemberExpression(lhs, optionalChainRef, (children) => {
|
|
5191
|
-
const assigns = $1.splice(i + 1,
|
|
5235
|
+
const assigns = $1.splice(i + 1, len3 - 1 - i);
|
|
5192
5236
|
$1.pop();
|
|
5193
5237
|
return [ws1, ...children, ws2, op, ...assigns, $2];
|
|
5194
5238
|
});
|
|
@@ -5270,9 +5314,9 @@ ${input.slice(result.pos)}
|
|
|
5270
5314
|
}
|
|
5271
5315
|
j++;
|
|
5272
5316
|
}
|
|
5273
|
-
let
|
|
5274
|
-
if (
|
|
5275
|
-
const l =
|
|
5317
|
+
let ref6;
|
|
5318
|
+
if (ref6 = conditions.length) {
|
|
5319
|
+
const l = ref6;
|
|
5276
5320
|
const cs = flatJoin(conditions, " && ");
|
|
5277
5321
|
return {
|
|
5278
5322
|
...exp,
|
|
@@ -5309,8 +5353,8 @@ ${input.slice(result.pos)}
|
|
|
5309
5353
|
return gatherRecursiveAll(node, (n) => n.type === "UnaryType").forEach((unary) => {
|
|
5310
5354
|
let last;
|
|
5311
5355
|
let count = 0;
|
|
5312
|
-
let
|
|
5313
|
-
while (unary.suffix.length && (
|
|
5356
|
+
let ref7;
|
|
5357
|
+
while (unary.suffix.length && (ref7 = unary.suffix)[ref7.length - 1]?.token === "?") {
|
|
5314
5358
|
last = unary.suffix.pop();
|
|
5315
5359
|
count++;
|
|
5316
5360
|
}
|
|
@@ -5344,11 +5388,11 @@ ${input.slice(result.pos)}
|
|
|
5344
5388
|
gatherRecursiveAll(statements, ($) => $.type === "StatementExpression").forEach((_exp) => {
|
|
5345
5389
|
const exp = _exp;
|
|
5346
5390
|
const { statement } = exp;
|
|
5347
|
-
let
|
|
5391
|
+
let ref8;
|
|
5348
5392
|
switch (statement.type) {
|
|
5349
5393
|
case "IfStatement": {
|
|
5350
|
-
if (
|
|
5351
|
-
const expression =
|
|
5394
|
+
if (ref8 = expressionizeIfStatement(statement)) {
|
|
5395
|
+
const expression = ref8;
|
|
5352
5396
|
return replaceNode(statement, expression, exp);
|
|
5353
5397
|
} else {
|
|
5354
5398
|
return replaceNode(statement, wrapIIFE([["", statement]]), exp);
|
|
@@ -5356,7 +5400,8 @@ ${input.slice(result.pos)}
|
|
|
5356
5400
|
}
|
|
5357
5401
|
case "IterationExpression": {
|
|
5358
5402
|
if (statement.subtype === "ComptimeStatement") {
|
|
5359
|
-
const
|
|
5403
|
+
const { expressions } = statement.statement.block;
|
|
5404
|
+
const expression = wrapIIFE(expressions, hasAwait(expressions));
|
|
5360
5405
|
return replaceNode(statement, makeNode({
|
|
5361
5406
|
type: "ComptimeExpression",
|
|
5362
5407
|
expression,
|
|
@@ -5434,7 +5479,13 @@ ${input.slice(result.pos)}
|
|
|
5434
5479
|
processBlocks(statements);
|
|
5435
5480
|
populateRefs(statements);
|
|
5436
5481
|
adjustAtBindings(statements);
|
|
5437
|
-
|
|
5482
|
+
if (getSync()) {
|
|
5483
|
+
processComptime(statements);
|
|
5484
|
+
}
|
|
5485
|
+
}
|
|
5486
|
+
async function processProgramAsync(root) {
|
|
5487
|
+
const { expressions: statements } = root;
|
|
5488
|
+
await processComptime(statements);
|
|
5438
5489
|
}
|
|
5439
5490
|
function populateRefs(statements) {
|
|
5440
5491
|
const refNodes = gatherRecursive(statements, ({ type }) => type === "Ref");
|
|
@@ -5558,8 +5609,8 @@ ${input.slice(result.pos)}
|
|
|
5558
5609
|
for (let i4 = 0, len3 = placeholders.length; i4 < len3; i4++) {
|
|
5559
5610
|
const placeholder = placeholders[i4];
|
|
5560
5611
|
typeSuffix ??= placeholder.typeSuffix;
|
|
5561
|
-
let
|
|
5562
|
-
replaceNode((
|
|
5612
|
+
let ref9;
|
|
5613
|
+
replaceNode((ref9 = placeholder.children)[ref9.length - 1], ref);
|
|
5563
5614
|
}
|
|
5564
5615
|
const { parent } = ancestor;
|
|
5565
5616
|
const body = maybeUnwrap(ancestor);
|
|
@@ -5590,9 +5641,9 @@ ${input.slice(result.pos)}
|
|
|
5590
5641
|
fnExp = makeLeftHandSideExpression(fnExp);
|
|
5591
5642
|
}
|
|
5592
5643
|
replaceNode(ancestor, fnExp, parent);
|
|
5593
|
-
let
|
|
5594
|
-
if (
|
|
5595
|
-
const ws =
|
|
5644
|
+
let ref10;
|
|
5645
|
+
if (ref10 = getTrimmingSpace(body)) {
|
|
5646
|
+
const ws = ref10;
|
|
5596
5647
|
inplaceInsertTrimmingSpace(body, "");
|
|
5597
5648
|
inplacePrepend(ws, fnExp);
|
|
5598
5649
|
}
|
|
@@ -5637,8 +5688,8 @@ ${input.slice(result.pos)}
|
|
|
5637
5688
|
}
|
|
5638
5689
|
];
|
|
5639
5690
|
}
|
|
5640
|
-
let
|
|
5641
|
-
if (Array.isArray(rest.delim) && (
|
|
5691
|
+
let ref11;
|
|
5692
|
+
if (Array.isArray(rest.delim) && (ref11 = rest.delim)[ref11.length - 1]?.token === ",") {
|
|
5642
5693
|
rest.delim = rest.delim.slice(0, -1);
|
|
5643
5694
|
rest.children = [...rest.children.slice(0, -1), rest.delim];
|
|
5644
5695
|
}
|
|
@@ -6836,15 +6887,20 @@ ${input.slice(result.pos)}
|
|
|
6836
6887
|
var $R93 = (0, import_lib2.$R)(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
|
|
6837
6888
|
var $R94 = (0, import_lib2.$R)(new RegExp("[^]*", "suy"));
|
|
6838
6889
|
var Program$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Reset, Init, (0, import_lib2.$E)(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
6890
|
+
var reset = $1;
|
|
6891
|
+
var init = $2;
|
|
6892
|
+
var ws1 = $3;
|
|
6839
6893
|
var statements = $4;
|
|
6840
|
-
|
|
6894
|
+
var ws2 = $5;
|
|
6895
|
+
const program = {
|
|
6841
6896
|
type: "BlockStatement",
|
|
6842
6897
|
expressions: statements,
|
|
6843
|
-
children: [statements],
|
|
6898
|
+
children: [reset, init, ws1, statements, ws2],
|
|
6844
6899
|
bare: true,
|
|
6845
6900
|
root: true
|
|
6846
|
-
}
|
|
6847
|
-
|
|
6901
|
+
};
|
|
6902
|
+
processProgram(program);
|
|
6903
|
+
return program;
|
|
6848
6904
|
});
|
|
6849
6905
|
function Program(ctx, state2) {
|
|
6850
6906
|
return (0, import_lib2.$EVENT)(ctx, state2, "Program", Program$0);
|
|
@@ -8442,11 +8498,11 @@ ${input.slice(result.pos)}
|
|
|
8442
8498
|
var dot = $1;
|
|
8443
8499
|
var neg = $2;
|
|
8444
8500
|
var num = $3;
|
|
8445
|
-
const
|
|
8501
|
+
const len3 = {
|
|
8446
8502
|
children: []
|
|
8447
8503
|
}, children = [
|
|
8448
8504
|
adjustIndexAccess(dot),
|
|
8449
|
-
|
|
8505
|
+
len3,
|
|
8450
8506
|
neg,
|
|
8451
8507
|
num,
|
|
8452
8508
|
"]"
|
|
@@ -8454,7 +8510,7 @@ ${input.slice(result.pos)}
|
|
|
8454
8510
|
return {
|
|
8455
8511
|
type: "NegativeIndex",
|
|
8456
8512
|
children,
|
|
8457
|
-
len:
|
|
8513
|
+
len: len3
|
|
8458
8514
|
};
|
|
8459
8515
|
});
|
|
8460
8516
|
var PropertyAccess$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(AccessStart, (0, import_lib2.$Q)(InlineComment), (0, import_lib2.$C)(IdentifierName, PrivateIdentifier, LengthShorthand)), function($skip, $loc, $0, $1, $2, $3) {
|
|
@@ -16126,26 +16182,29 @@ ${input.slice(result.pos)}
|
|
|
16126
16182
|
const parser2 = options.startRule != null ? grammar[options.startRule] : Object.values(grammar)[0];
|
|
16127
16183
|
if (!parser2)
|
|
16128
16184
|
throw new Error(`Could not find rule with name '${options.startRule}'`);
|
|
16129
|
-
const
|
|
16185
|
+
const filename2 = options.filename || "<anonymous>";
|
|
16130
16186
|
reset();
|
|
16131
16187
|
Object.assign(ctx, { ...options.events, tokenize: options.tokenize });
|
|
16132
16188
|
return validate(input, parser2(ctx, {
|
|
16133
16189
|
input,
|
|
16134
16190
|
pos: 0
|
|
16135
16191
|
}), {
|
|
16136
|
-
filename
|
|
16192
|
+
filename: filename2
|
|
16137
16193
|
});
|
|
16138
16194
|
}
|
|
16139
16195
|
};
|
|
16140
16196
|
}();
|
|
16141
16197
|
var { parse } = parser;
|
|
16198
|
+
var filename;
|
|
16142
16199
|
var initialConfig;
|
|
16143
16200
|
var config;
|
|
16201
|
+
var sync;
|
|
16144
16202
|
var state = {};
|
|
16145
16203
|
var getState = () => state;
|
|
16146
16204
|
var getConfig = () => config;
|
|
16147
16205
|
var getInitialConfig = () => initialConfig;
|
|
16148
|
-
var
|
|
16206
|
+
var getFilename = () => filename;
|
|
16207
|
+
var getSync = () => sync;
|
|
16149
16208
|
Object.defineProperties(state, {
|
|
16150
16209
|
currentIndent: {
|
|
16151
16210
|
get() {
|
|
@@ -16190,6 +16249,21 @@ ${input.slice(result.pos)}
|
|
|
16190
16249
|
}
|
|
16191
16250
|
}
|
|
16192
16251
|
});
|
|
16252
|
+
function parseProgram(input, options) {
|
|
16253
|
+
filename = options?.filename;
|
|
16254
|
+
initialConfig = options?.parseOptions;
|
|
16255
|
+
sync = options?.sync;
|
|
16256
|
+
const root = parse(input, options);
|
|
16257
|
+
if (sync) {
|
|
16258
|
+
filename = initialConfig = sync = null;
|
|
16259
|
+
return root;
|
|
16260
|
+
} else {
|
|
16261
|
+
return processProgramAsync(root).then(() => {
|
|
16262
|
+
filename = initialConfig = sync = null;
|
|
16263
|
+
return root;
|
|
16264
|
+
});
|
|
16265
|
+
}
|
|
16266
|
+
}
|
|
16193
16267
|
|
|
16194
16268
|
// source/util.civet
|
|
16195
16269
|
var util_exports = {};
|
|
@@ -16616,15 +16690,15 @@ ${input.slice(result.pos)}
|
|
|
16616
16690
|
"RestoreTrailingMemberProperty",
|
|
16617
16691
|
"RestoreNewlineBinaryOp"
|
|
16618
16692
|
]);
|
|
16619
|
-
|
|
16693
|
+
function compile(src, options) {
|
|
16620
16694
|
if (!options) {
|
|
16621
16695
|
options = {};
|
|
16622
16696
|
} else {
|
|
16623
16697
|
options = { ...options };
|
|
16624
16698
|
}
|
|
16625
16699
|
options.parseOptions = { ...options.parseOptions };
|
|
16626
|
-
const
|
|
16627
|
-
if (
|
|
16700
|
+
const filename2 = options.filename || "unknown";
|
|
16701
|
+
if (filename2.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
16628
16702
|
options.parseOptions.coffeeCompat = true;
|
|
16629
16703
|
}
|
|
16630
16704
|
const { hits, trace, noCache } = options;
|
|
@@ -16636,21 +16710,18 @@ ${input.slice(result.pos)}
|
|
|
16636
16710
|
});
|
|
16637
16711
|
}
|
|
16638
16712
|
let ast;
|
|
16639
|
-
setInitialConfig(options.parseOptions);
|
|
16640
16713
|
try {
|
|
16641
|
-
ast =
|
|
16642
|
-
|
|
16714
|
+
ast = parseProgram(src, {
|
|
16715
|
+
parseOptions: options.parseOptions,
|
|
16716
|
+
sync: options.sync,
|
|
16717
|
+
filename: filename2,
|
|
16643
16718
|
events
|
|
16644
16719
|
});
|
|
16645
|
-
if (!(options.ast === "raw")) {
|
|
16646
|
-
ast = prune(ast);
|
|
16647
|
-
}
|
|
16648
16720
|
} finally {
|
|
16649
|
-
setInitialConfig(void 0);
|
|
16650
16721
|
if (hits || trace) {
|
|
16651
|
-
import("fs").then(function({ writeFileSync }) {
|
|
16722
|
+
import("node:fs").then(function({ writeFileSync }) {
|
|
16652
16723
|
let ref;
|
|
16653
|
-
if ((ref = events?.meta) && "logs" in ref) {
|
|
16724
|
+
if ((ref = events?.meta) && typeof ref === "object" && "logs" in ref) {
|
|
16654
16725
|
const { logs } = ref;
|
|
16655
16726
|
if (trace) {
|
|
16656
16727
|
writeFileSync(trace, logs.join("\n"));
|
|
@@ -16679,34 +16750,45 @@ ${counts}`;
|
|
|
16679
16750
|
});
|
|
16680
16751
|
}
|
|
16681
16752
|
}
|
|
16682
|
-
|
|
16683
|
-
|
|
16684
|
-
|
|
16685
|
-
|
|
16686
|
-
if (options.errors?.length) {
|
|
16687
|
-
throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
|
|
16753
|
+
function rest(ast2) {
|
|
16754
|
+
options = options;
|
|
16755
|
+
if (!(options.ast === "raw")) {
|
|
16756
|
+
ast2 = prune(ast2);
|
|
16688
16757
|
}
|
|
16689
|
-
|
|
16690
|
-
|
|
16691
|
-
|
|
16692
|
-
|
|
16693
|
-
|
|
16694
|
-
|
|
16695
|
-
|
|
16696
|
-
|
|
16697
|
-
|
|
16698
|
-
return SourceMap2.remap(code, sm, filename, filename + ".tsx");
|
|
16699
|
-
} else {
|
|
16700
|
-
return {
|
|
16701
|
-
code,
|
|
16702
|
-
sourceMap: sm
|
|
16703
|
-
};
|
|
16758
|
+
if (options.ast) {
|
|
16759
|
+
return ast2;
|
|
16760
|
+
}
|
|
16761
|
+
function checkErrors() {
|
|
16762
|
+
if (options.errors?.length) {
|
|
16763
|
+
throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
|
|
16764
|
+
}
|
|
16765
|
+
;
|
|
16766
|
+
return;
|
|
16704
16767
|
}
|
|
16768
|
+
if (options.sourceMap || options.inlineMap) {
|
|
16769
|
+
const sm = SourceMap2(src);
|
|
16770
|
+
options.updateSourceMap = sm.updateSourceMap;
|
|
16771
|
+
const code = generate_default(ast2, options);
|
|
16772
|
+
checkErrors();
|
|
16773
|
+
if (options.inlineMap) {
|
|
16774
|
+
return SourceMap2.remap(code, sm, filename2, filename2 + ".tsx");
|
|
16775
|
+
} else {
|
|
16776
|
+
return {
|
|
16777
|
+
code,
|
|
16778
|
+
sourceMap: sm
|
|
16779
|
+
};
|
|
16780
|
+
}
|
|
16781
|
+
}
|
|
16782
|
+
const result = generate_default(ast2, options);
|
|
16783
|
+
checkErrors();
|
|
16784
|
+
return result;
|
|
16705
16785
|
}
|
|
16706
|
-
|
|
16707
|
-
|
|
16708
|
-
|
|
16709
|
-
|
|
16786
|
+
if (ast.then != null) {
|
|
16787
|
+
return ast.then(rest);
|
|
16788
|
+
} else {
|
|
16789
|
+
return rest(ast);
|
|
16790
|
+
}
|
|
16791
|
+
}
|
|
16710
16792
|
var makeCache = function({ hits, trace } = {}) {
|
|
16711
16793
|
const meta = {};
|
|
16712
16794
|
let hitCount;
|
|
@@ -16773,6 +16855,6 @@ ${counts}`;
|
|
|
16773
16855
|
return err instanceof Error && //@ts-ignore
|
|
16774
16856
|
[err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
|
|
16775
16857
|
};
|
|
16776
|
-
var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
|
|
16858
|
+
var main_default = { parse, parseProgram, generate: generate_default, util: util_exports, compile, isCompileError };
|
|
16777
16859
|
return __toCommonJS(main_exports);
|
|
16778
16860
|
})();
|