@danielx/civet 0.7.3 → 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 +260 -158
- 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 +261 -158
- package/dist/main.mjs +260 -158
- 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/main.js
CHANGED
|
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// node_modules/@danielx/hera/dist/machine.js
|
|
34
34
|
var require_machine = __commonJS({
|
|
35
|
-
"
|
|
35
|
+
"node_modules/@danielx/hera/dist/machine.js"(exports2, module2) {
|
|
36
36
|
"use strict";
|
|
37
37
|
var __defProp2 = Object.defineProperty;
|
|
38
38
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -418,14 +418,14 @@ var require_machine = __commonJS({
|
|
|
418
418
|
}, [1, 1]);
|
|
419
419
|
return [line, column];
|
|
420
420
|
}
|
|
421
|
-
function validate(input, result, { filename }) {
|
|
421
|
+
function validate(input, result, { filename: filename2 }) {
|
|
422
422
|
if (result && result.pos === input.length)
|
|
423
423
|
return result.value;
|
|
424
424
|
const expectations = Array.from(new Set(failExpected.slice(0, failIndex)));
|
|
425
425
|
let l = location(input, maxFailPos), [line, column] = l;
|
|
426
426
|
if (result && result.pos > maxFailPos) {
|
|
427
427
|
l = location(input, result.pos);
|
|
428
|
-
throw new Error(`${
|
|
428
|
+
throw new Error(`${filename2}:${line}:${column} Unconsumed input at #{l}
|
|
429
429
|
|
|
430
430
|
${input.slice(result.pos)}
|
|
431
431
|
`);
|
|
@@ -437,11 +437,11 @@ ${input.slice(result.pos)}
|
|
|
437
437
|
hint = JSON.stringify(hint);
|
|
438
438
|
else
|
|
439
439
|
hint = "EOF";
|
|
440
|
-
const error = new ParseError(`${
|
|
440
|
+
const error = new ParseError(`${filename2}:${line}:${column} Failed to parse
|
|
441
441
|
Expected:
|
|
442
442
|
${expectations.join("\n ")}
|
|
443
443
|
Found: ${hint}
|
|
444
|
-
`, "ParseError",
|
|
444
|
+
`, "ParseError", filename2, line, column, maxFailPos);
|
|
445
445
|
throw error;
|
|
446
446
|
}
|
|
447
447
|
if (result) {
|
|
@@ -465,11 +465,11 @@ ${input.slice(result.pos)}
|
|
|
465
465
|
};
|
|
466
466
|
}
|
|
467
467
|
var ParseError = class extends Error {
|
|
468
|
-
constructor(message, name,
|
|
468
|
+
constructor(message, name, filename2, line, column, offset) {
|
|
469
469
|
super(message);
|
|
470
470
|
this.message = message;
|
|
471
471
|
this.name = name;
|
|
472
|
-
this.filename =
|
|
472
|
+
this.filename = filename2;
|
|
473
473
|
this.line = line;
|
|
474
474
|
this.column = column;
|
|
475
475
|
this.offset = offset;
|
|
@@ -487,6 +487,7 @@ __export(main_exports, {
|
|
|
487
487
|
isCompileError: () => isCompileError,
|
|
488
488
|
lib: () => lib_exports,
|
|
489
489
|
parse: () => parse,
|
|
490
|
+
parseProgram: () => parseProgram,
|
|
490
491
|
prune: () => prune,
|
|
491
492
|
util: () => util_exports
|
|
492
493
|
});
|
|
@@ -547,6 +548,7 @@ __export(lib_exports, {
|
|
|
547
548
|
processCoffeeInterpolation: () => processCoffeeInterpolation,
|
|
548
549
|
processForInOf: () => processForInOf,
|
|
549
550
|
processProgram: () => processProgram,
|
|
551
|
+
processProgramAsync: () => processProgramAsync,
|
|
550
552
|
processUnaryExpression: () => processUnaryExpression,
|
|
551
553
|
quoteString: () => quoteString,
|
|
552
554
|
reorderBindingRestProperty: () => reorderBindingRestProperty,
|
|
@@ -1169,14 +1171,12 @@ function processParams(f) {
|
|
|
1169
1171
|
if (!prefix.length)
|
|
1170
1172
|
return;
|
|
1171
1173
|
if (isConstructor) {
|
|
1172
|
-
const superCalls = gatherNodes(
|
|
1173
|
-
|
|
1174
|
-
|
|
1174
|
+
const superCalls = gatherNodes(
|
|
1175
|
+
expressions,
|
|
1176
|
+
(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"
|
|
1177
|
+
);
|
|
1175
1178
|
if (superCalls.length) {
|
|
1176
|
-
const { child } = findAncestor(
|
|
1177
|
-
superCalls[0],
|
|
1178
|
-
(ancestor) => ancestor === block
|
|
1179
|
-
);
|
|
1179
|
+
const { child } = findAncestor(superCalls[0], (a1) => a1 === block);
|
|
1180
1180
|
const index = findChildIndex(expressions, child);
|
|
1181
1181
|
if (index < 0) {
|
|
1182
1182
|
throw new Error("Could not find super call within top-level expressions");
|
|
@@ -1261,7 +1261,7 @@ function blockWithPrefix(prefixStatements, block) {
|
|
|
1261
1261
|
return block;
|
|
1262
1262
|
}
|
|
1263
1263
|
function braceBlock(block) {
|
|
1264
|
-
if (block.bare) {
|
|
1264
|
+
if (block.bare && !block.root) {
|
|
1265
1265
|
if (block.children === block.expressions) {
|
|
1266
1266
|
block.children = [block.expressions];
|
|
1267
1267
|
}
|
|
@@ -1313,8 +1313,8 @@ function makeBlockFragment() {
|
|
|
1313
1313
|
function replaceBlockExpression(node, child, replacement) {
|
|
1314
1314
|
let found = false;
|
|
1315
1315
|
const { expressions } = node;
|
|
1316
|
-
for (let
|
|
1317
|
-
const statement = expressions[
|
|
1316
|
+
for (let i1 = 0, len3 = expressions.length; i1 < len3; i1++) {
|
|
1317
|
+
const statement = expressions[i1];
|
|
1318
1318
|
const [, s] = statement;
|
|
1319
1319
|
if (s === child) {
|
|
1320
1320
|
statement[1] = replacement;
|
|
@@ -1375,9 +1375,9 @@ function processBlocks(statements) {
|
|
|
1375
1375
|
}
|
|
1376
1376
|
function insertSemicolon(statements) {
|
|
1377
1377
|
const l = statements.length;
|
|
1378
|
-
for (let
|
|
1379
|
-
const i =
|
|
1380
|
-
const s = statements[
|
|
1378
|
+
for (let i2 = 0, len1 = statements.length; i2 < len1; i2++) {
|
|
1379
|
+
const i = i2;
|
|
1380
|
+
const s = statements[i2];
|
|
1381
1381
|
if (i < l - 1) {
|
|
1382
1382
|
if (needsPrecedingSemicolon(statements[i + 1][1])) {
|
|
1383
1383
|
const delim = s[2];
|
|
@@ -1395,8 +1395,8 @@ function needsPrecedingSemicolon(exp) {
|
|
|
1395
1395
|
return false;
|
|
1396
1396
|
}
|
|
1397
1397
|
if (Array.isArray(exp)) {
|
|
1398
|
-
for (let
|
|
1399
|
-
const child = exp[
|
|
1398
|
+
for (let i3 = 0, len22 = exp.length; i3 < len22; i3++) {
|
|
1399
|
+
const child = exp[i3];
|
|
1400
1400
|
if (!(child != null)) {
|
|
1401
1401
|
continue;
|
|
1402
1402
|
}
|
|
@@ -1438,6 +1438,9 @@ function needsPrecedingSemicolon(exp) {
|
|
|
1438
1438
|
}
|
|
1439
1439
|
|
|
1440
1440
|
// source/parser/util.civet
|
|
1441
|
+
function len(arr, length) {
|
|
1442
|
+
return arr.length === length;
|
|
1443
|
+
}
|
|
1441
1444
|
var assert = {
|
|
1442
1445
|
equal(a, b, msg) {
|
|
1443
1446
|
if (a !== b) {
|
|
@@ -1457,9 +1460,12 @@ function addParentPointers(node, parent) {
|
|
|
1457
1460
|
return;
|
|
1458
1461
|
}
|
|
1459
1462
|
node = node;
|
|
1460
|
-
|
|
1463
|
+
if (parent != null) {
|
|
1464
|
+
node.parent = parent;
|
|
1465
|
+
}
|
|
1461
1466
|
if (node.children) {
|
|
1462
|
-
for (
|
|
1467
|
+
for (let ref1 = node.children, i1 = 0, len1 = ref1.length; i1 < len1; i1++) {
|
|
1468
|
+
const child = ref1[i1];
|
|
1463
1469
|
addParentPointers(child, node);
|
|
1464
1470
|
}
|
|
1465
1471
|
}
|
|
@@ -1469,10 +1475,9 @@ function clone(node) {
|
|
|
1469
1475
|
return deepCopy(node);
|
|
1470
1476
|
}
|
|
1471
1477
|
function removeParentPointers(node) {
|
|
1472
|
-
if (node
|
|
1473
|
-
return;
|
|
1474
|
-
if (typeof node !== "object")
|
|
1478
|
+
if (!(node != null && typeof node === "object")) {
|
|
1475
1479
|
return;
|
|
1480
|
+
}
|
|
1476
1481
|
if (Array.isArray(node)) {
|
|
1477
1482
|
for (const child of node) {
|
|
1478
1483
|
removeParentPointers(child);
|
|
@@ -1516,7 +1521,7 @@ function isEmptyBareBlock(node) {
|
|
|
1516
1521
|
if (node?.type !== "BlockStatement")
|
|
1517
1522
|
return false;
|
|
1518
1523
|
const { bare, expressions } = node;
|
|
1519
|
-
return bare && (expressions
|
|
1524
|
+
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");
|
|
1520
1525
|
}
|
|
1521
1526
|
function isFunction(node) {
|
|
1522
1527
|
const { type } = node;
|
|
@@ -1564,8 +1569,8 @@ function isExit(node) {
|
|
|
1564
1569
|
if (!(node != null)) {
|
|
1565
1570
|
return false;
|
|
1566
1571
|
}
|
|
1567
|
-
let ref1;
|
|
1568
1572
|
let ref2;
|
|
1573
|
+
let ref3;
|
|
1569
1574
|
switch (node.type) {
|
|
1570
1575
|
case "ReturnStatement":
|
|
1571
1576
|
case "ThrowStatement":
|
|
@@ -1574,10 +1579,10 @@ function isExit(node) {
|
|
|
1574
1579
|
return true;
|
|
1575
1580
|
}
|
|
1576
1581
|
case "IfStatement": {
|
|
1577
|
-
return isExit(node.then) && isExit((
|
|
1582
|
+
return isExit(node.then) && isExit((ref2 = node.else)?.[ref2.length - 1]);
|
|
1578
1583
|
}
|
|
1579
1584
|
case "BlockStatement": {
|
|
1580
|
-
return isExit((
|
|
1585
|
+
return isExit((ref3 = node.expressions)[ref3.length - 1]?.[1]);
|
|
1581
1586
|
}
|
|
1582
1587
|
case "IterationStatement": {
|
|
1583
1588
|
return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
|
|
@@ -1873,8 +1878,8 @@ function updateParentPointers(node, parent, depth = 1) {
|
|
|
1873
1878
|
return;
|
|
1874
1879
|
}
|
|
1875
1880
|
if (Array.isArray(node)) {
|
|
1876
|
-
for (let
|
|
1877
|
-
const child = node[
|
|
1881
|
+
for (let i2 = 0, len22 = node.length; i2 < len22; i2++) {
|
|
1882
|
+
const child = node[i2];
|
|
1878
1883
|
updateParentPointers(child, parent, depth);
|
|
1879
1884
|
}
|
|
1880
1885
|
return;
|
|
@@ -1884,8 +1889,8 @@ function updateParentPointers(node, parent, depth = 1) {
|
|
|
1884
1889
|
node.parent = parent;
|
|
1885
1890
|
}
|
|
1886
1891
|
if (depth && isParent(node)) {
|
|
1887
|
-
for (let
|
|
1888
|
-
const child =
|
|
1892
|
+
for (let ref4 = node.children, i3 = 0, len3 = ref4.length; i3 < len3; i3++) {
|
|
1893
|
+
const child = ref4[i3];
|
|
1889
1894
|
updateParentPointers(child, node, depth - 1);
|
|
1890
1895
|
}
|
|
1891
1896
|
}
|
|
@@ -2015,9 +2020,9 @@ function wrapWithReturn(expression) {
|
|
|
2015
2020
|
}
|
|
2016
2021
|
function flatJoin(array, separator) {
|
|
2017
2022
|
const result = [];
|
|
2018
|
-
for (let
|
|
2019
|
-
const i =
|
|
2020
|
-
const items = array[
|
|
2023
|
+
for (let i4 = 0, len4 = array.length; i4 < len4; i4++) {
|
|
2024
|
+
const i = i4;
|
|
2025
|
+
const items = array[i4];
|
|
2021
2026
|
if (i) {
|
|
2022
2027
|
result.push(separator);
|
|
2023
2028
|
}
|
|
@@ -2038,7 +2043,7 @@ function findChildIndex(parent, child) {
|
|
|
2038
2043
|
if (!(children != null)) {
|
|
2039
2044
|
return -1;
|
|
2040
2045
|
}
|
|
2041
|
-
for (let i1 = 0,
|
|
2046
|
+
for (let i1 = 0, len3 = children.length; i1 < len3; i1++) {
|
|
2042
2047
|
const i = i1;
|
|
2043
2048
|
const c = children[i1];
|
|
2044
2049
|
if (c === child || Array.isArray(c) && arrayRecurse(c)) {
|
|
@@ -2068,8 +2073,9 @@ function findAncestor(node, predicate, stopPredicate) {
|
|
|
2068
2073
|
return { ancestor: void 0, child: node };
|
|
2069
2074
|
}
|
|
2070
2075
|
function gatherNodes(node, predicate) {
|
|
2071
|
-
if (node == null)
|
|
2076
|
+
if (node == null || typeof node === "string") {
|
|
2072
2077
|
return [];
|
|
2078
|
+
}
|
|
2073
2079
|
if (Array.isArray(node)) {
|
|
2074
2080
|
return node.flatMap((n) => gatherNodes(n, predicate));
|
|
2075
2081
|
}
|
|
@@ -2077,24 +2083,30 @@ function gatherNodes(node, predicate) {
|
|
|
2077
2083
|
return [node];
|
|
2078
2084
|
}
|
|
2079
2085
|
switch (node.type) {
|
|
2080
|
-
case "BlockStatement":
|
|
2086
|
+
case "BlockStatement": {
|
|
2081
2087
|
return [];
|
|
2082
|
-
|
|
2088
|
+
}
|
|
2089
|
+
case "ForStatement": {
|
|
2083
2090
|
const isDec = node.declaration?.type === "Declaration";
|
|
2084
2091
|
return node.children.flatMap((n) => {
|
|
2085
|
-
if (isDec && n === node.declaration)
|
|
2092
|
+
if (isDec && n === node.declaration) {
|
|
2086
2093
|
return [];
|
|
2087
|
-
|
|
2094
|
+
} else {
|
|
2095
|
+
return gatherNodes(n, predicate);
|
|
2096
|
+
}
|
|
2088
2097
|
});
|
|
2089
|
-
|
|
2098
|
+
}
|
|
2099
|
+
default: {
|
|
2090
2100
|
return gatherNodes(node.children, predicate);
|
|
2101
|
+
}
|
|
2091
2102
|
}
|
|
2092
2103
|
}
|
|
2093
2104
|
function gatherRecursive(node, predicate, skipPredicate) {
|
|
2094
|
-
if (node == null)
|
|
2105
|
+
if (node == null || typeof node === "string") {
|
|
2095
2106
|
return [];
|
|
2107
|
+
}
|
|
2096
2108
|
if (Array.isArray(node)) {
|
|
2097
|
-
return node.flatMap((
|
|
2109
|
+
return node.flatMap(($) => gatherRecursive($, predicate, skipPredicate));
|
|
2098
2110
|
}
|
|
2099
2111
|
if (skipPredicate?.(node))
|
|
2100
2112
|
return [];
|
|
@@ -2104,8 +2116,9 @@ function gatherRecursive(node, predicate, skipPredicate) {
|
|
|
2104
2116
|
return gatherRecursive(node.children, predicate, skipPredicate);
|
|
2105
2117
|
}
|
|
2106
2118
|
function gatherRecursiveAll(node, predicate) {
|
|
2107
|
-
if (node == null)
|
|
2119
|
+
if (node == null || typeof node === "string") {
|
|
2108
2120
|
return [];
|
|
2121
|
+
}
|
|
2109
2122
|
if (Array.isArray(node)) {
|
|
2110
2123
|
return node.flatMap((n) => gatherRecursiveAll(n, predicate));
|
|
2111
2124
|
}
|
|
@@ -2145,7 +2158,7 @@ var precedenceOrder = [
|
|
|
2145
2158
|
["**"]
|
|
2146
2159
|
];
|
|
2147
2160
|
var precedenceMap = /* @__PURE__ */ new Map();
|
|
2148
|
-
for (let i1 = 0,
|
|
2161
|
+
for (let i1 = 0, len3 = precedenceOrder.length; i1 < len3; i1++) {
|
|
2149
2162
|
const prec = i1;
|
|
2150
2163
|
const ops = precedenceOrder[i1];
|
|
2151
2164
|
for (let i2 = 0, len1 = ops.length; i2 < len1; i2++) {
|
|
@@ -2256,7 +2269,7 @@ function processBinaryOpExpression($0) {
|
|
|
2256
2269
|
} else {
|
|
2257
2270
|
b = recurse(b);
|
|
2258
2271
|
}
|
|
2259
|
-
if (op.token === "instanceof" && b.type === "Literal" && b.children
|
|
2272
|
+
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")) {
|
|
2260
2273
|
a = ["typeof ", makeLeftHandSideExpression(a)];
|
|
2261
2274
|
if (op.negated) {
|
|
2262
2275
|
op = { ...op, token: "!==", negated: false };
|
|
@@ -2361,7 +2374,7 @@ function expandChainedComparisons([first, binops]) {
|
|
|
2361
2374
|
let start = 0;
|
|
2362
2375
|
const chains = [];
|
|
2363
2376
|
var i = 0;
|
|
2364
|
-
for (let i3 = 0,
|
|
2377
|
+
for (let i3 = 0, len22 = binops.length; i3 < len22; i3++) {
|
|
2365
2378
|
var i = i3;
|
|
2366
2379
|
var [, op] = binops[i3];
|
|
2367
2380
|
if (isRelationalOp(op)) {
|
|
@@ -2971,7 +2984,7 @@ function aliasBinding(p, ref) {
|
|
|
2971
2984
|
}
|
|
2972
2985
|
|
|
2973
2986
|
// source/parser/declaration.civet
|
|
2974
|
-
function
|
|
2987
|
+
function len2(arr, length) {
|
|
2975
2988
|
return arr.length === length;
|
|
2976
2989
|
}
|
|
2977
2990
|
function processAssignmentDeclaration(decl, pattern, suffix, ws, assign, e) {
|
|
@@ -3154,9 +3167,12 @@ function processDeclarationCondition(condition, rootCondition, parent) {
|
|
|
3154
3167
|
rootCondition.blockPrefix = getPatternBlockPrefix(pattern, ref, decl, suffix);
|
|
3155
3168
|
}
|
|
3156
3169
|
function processDeclarationConditions(node) {
|
|
3157
|
-
gatherRecursiveAll(
|
|
3158
|
-
|
|
3159
|
-
|
|
3170
|
+
gatherRecursiveAll(
|
|
3171
|
+
node,
|
|
3172
|
+
(n) => {
|
|
3173
|
+
return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
|
|
3174
|
+
}
|
|
3175
|
+
).forEach((s) => {
|
|
3160
3176
|
return processDeclarationConditionStatement(s);
|
|
3161
3177
|
});
|
|
3162
3178
|
}
|
|
@@ -3166,7 +3182,7 @@ function processDeclarationConditionStatement(s) {
|
|
|
3166
3182
|
return;
|
|
3167
3183
|
}
|
|
3168
3184
|
let { expression } = condition;
|
|
3169
|
-
if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "UnaryExpression" && "children" in expression && Array.isArray(expression.children) &&
|
|
3185
|
+
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]) {
|
|
3170
3186
|
const { type: type1, children: [, { type: type2, expression: expression2 }] } = expression;
|
|
3171
3187
|
const type = [type1, type2];
|
|
3172
3188
|
expression = expression2;
|
|
@@ -3175,7 +3191,7 @@ function processDeclarationConditionStatement(s) {
|
|
|
3175
3191
|
const { ref, pattern } = expression;
|
|
3176
3192
|
if (pattern) {
|
|
3177
3193
|
const conditions = getPatternConditions(pattern, ref).filter((c) => {
|
|
3178
|
-
if (Array.isArray(c) &&
|
|
3194
|
+
if (Array.isArray(c) && len2(c, 2) && c[0] === ref && c[1] === " != null") {
|
|
3179
3195
|
const [,] = c;
|
|
3180
3196
|
return false;
|
|
3181
3197
|
} else {
|
|
@@ -4092,36 +4108,79 @@ function processComptime(statements) {
|
|
|
4092
4108
|
if (!getInitialConfig()?.comptime) {
|
|
4093
4109
|
return;
|
|
4094
4110
|
}
|
|
4095
|
-
|
|
4111
|
+
let prepareEval = () => {
|
|
4112
|
+
};
|
|
4113
|
+
if (getSync()) {
|
|
4114
|
+
runComptime(statements, prepareEval);
|
|
4115
|
+
return;
|
|
4116
|
+
} else {
|
|
4117
|
+
return (async () => {
|
|
4118
|
+
{
|
|
4119
|
+
try {
|
|
4120
|
+
const path = (await import("node:path")).default;
|
|
4121
|
+
const { createRequire } = await import("node:module");
|
|
4122
|
+
return prepareEval = () => {
|
|
4123
|
+
global.__filename = path.resolve(getFilename() ?? "");
|
|
4124
|
+
global.__dirname = path.dirname(global.__filename);
|
|
4125
|
+
return global.require = createRequire(global.__filename);
|
|
4126
|
+
};
|
|
4127
|
+
} catch (e) {
|
|
4128
|
+
return;
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4131
|
+
})().then(async () => {
|
|
4132
|
+
await Promise.all(runComptime(statements, prepareEval));
|
|
4133
|
+
});
|
|
4134
|
+
}
|
|
4135
|
+
}
|
|
4136
|
+
function runComptime(statements, prepareEval) {
|
|
4137
|
+
const sync2 = getSync();
|
|
4138
|
+
return gatherRecursive(
|
|
4096
4139
|
statements,
|
|
4097
4140
|
(node) => {
|
|
4098
4141
|
return node.type === "ComptimeStatement" || node.type === "ComptimeExpression";
|
|
4099
4142
|
}
|
|
4100
|
-
).
|
|
4143
|
+
).map((exp) => {
|
|
4101
4144
|
const content = exp.type === "ComptimeStatement" ? exp.block : exp.expression;
|
|
4102
4145
|
const options = { js: true };
|
|
4103
4146
|
const js = generate_default(prune(content), options);
|
|
4104
4147
|
if (options.errors != null) {
|
|
4105
4148
|
return;
|
|
4106
4149
|
}
|
|
4107
|
-
|
|
4150
|
+
prepareEval();
|
|
4151
|
+
let output = eval?.(`"use strict";${js}`);
|
|
4152
|
+
let promise;
|
|
4108
4153
|
if (exp.type === "ComptimeExpression") {
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4154
|
+
const finish = () => {
|
|
4155
|
+
let string;
|
|
4156
|
+
try {
|
|
4157
|
+
string = serialize(output);
|
|
4158
|
+
} catch (e) {
|
|
4159
|
+
exp.children = [
|
|
4160
|
+
{
|
|
4161
|
+
type: "Error",
|
|
4162
|
+
message: `comptime result ${output} not serializable: ${e}`
|
|
4163
|
+
}
|
|
4164
|
+
];
|
|
4165
|
+
return;
|
|
4166
|
+
}
|
|
4167
|
+
return exp.children = [string];
|
|
4168
|
+
};
|
|
4169
|
+
if (sync2) {
|
|
4170
|
+
finish();
|
|
4171
|
+
} else {
|
|
4172
|
+
promise = (async () => {
|
|
4114
4173
|
{
|
|
4115
|
-
|
|
4116
|
-
|
|
4174
|
+
output = await output;
|
|
4175
|
+
return finish();
|
|
4117
4176
|
}
|
|
4118
|
-
|
|
4119
|
-
return;
|
|
4177
|
+
})();
|
|
4120
4178
|
}
|
|
4121
|
-
return exp.children = [string];
|
|
4122
4179
|
} else {
|
|
4123
|
-
|
|
4180
|
+
promise = output;
|
|
4181
|
+
exp.children = [];
|
|
4124
4182
|
}
|
|
4183
|
+
return promise;
|
|
4125
4184
|
});
|
|
4126
4185
|
}
|
|
4127
4186
|
function serialize(value) {
|
|
@@ -4229,7 +4288,7 @@ function serialize(value) {
|
|
|
4229
4288
|
case Object.prototype: {
|
|
4230
4289
|
let objStr = "{";
|
|
4231
4290
|
let descStr = "";
|
|
4232
|
-
for (let ref2 = Object.getOwnPropertyNames(val).concat(Object.getOwnPropertySymbols(val)), i = 0,
|
|
4291
|
+
for (let ref2 = Object.getOwnPropertyNames(val).concat(Object.getOwnPropertySymbols(val)), i = 0, len3 = ref2.length; i < len3; i++) {
|
|
4233
4292
|
const prop = ref2[i];
|
|
4234
4293
|
const desc = Object.getOwnPropertyDescriptor(val, prop);
|
|
4235
4294
|
if (desc.enumerable && desc.configurable && desc.writable) {
|
|
@@ -4318,7 +4377,7 @@ function getIndentLevel(str, tab) {
|
|
|
4318
4377
|
}
|
|
4319
4378
|
function reduceIndentLevel(str, dedent, tab) {
|
|
4320
4379
|
if (tab != null && tab != 1) {
|
|
4321
|
-
for (let i1 = 0,
|
|
4380
|
+
for (let i1 = 0, len3 = str.length; i1 < len3; i1++) {
|
|
4322
4381
|
const i = i1;
|
|
4323
4382
|
const char = str[i1];
|
|
4324
4383
|
if (!dedent) {
|
|
@@ -4400,7 +4459,7 @@ function dedentBlockSubstitutions($0, tab) {
|
|
|
4400
4459
|
;
|
|
4401
4460
|
const dedent = ref1;
|
|
4402
4461
|
let results = [s];
|
|
4403
|
-
for (let i3 = 0,
|
|
4462
|
+
for (let i3 = 0, len22 = strWithSubstitutions.length; i3 < len22; i3++) {
|
|
4404
4463
|
const i = i3;
|
|
4405
4464
|
let part = strWithSubstitutions[i3];
|
|
4406
4465
|
if (part.token != null) {
|
|
@@ -4530,9 +4589,8 @@ function isExpression(node) {
|
|
|
4530
4589
|
return true;
|
|
4531
4590
|
}
|
|
4532
4591
|
function expressionizeBlock(blockOrExpression) {
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
const { expressions } = ref1;
|
|
4592
|
+
if (blockOrExpression && typeof blockOrExpression === "object" && "expressions" in blockOrExpression) {
|
|
4593
|
+
const { expressions } = blockOrExpression;
|
|
4536
4594
|
const l = expressions.length;
|
|
4537
4595
|
const results = [];
|
|
4538
4596
|
let i1 = 0;
|
|
@@ -4631,7 +4689,7 @@ function handleThisPrivateShorthands(value) {
|
|
|
4631
4689
|
}
|
|
4632
4690
|
function processCallMemberExpression(node) {
|
|
4633
4691
|
const { children } = node;
|
|
4634
|
-
if (children[0]
|
|
4692
|
+
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") {
|
|
4635
4693
|
const op = children[0].parenthesizedOp;
|
|
4636
4694
|
let call = children[1];
|
|
4637
4695
|
const args = [...call.args];
|
|
@@ -4725,14 +4783,14 @@ function processCallMemberExpression(node) {
|
|
|
4725
4783
|
});
|
|
4726
4784
|
}
|
|
4727
4785
|
}
|
|
4728
|
-
let
|
|
4786
|
+
let ref1;
|
|
4729
4787
|
let object = {
|
|
4730
4788
|
type: "ObjectExpression",
|
|
4731
4789
|
children: [
|
|
4732
4790
|
glob.object.children[0],
|
|
4733
4791
|
// {
|
|
4734
4792
|
...parts,
|
|
4735
|
-
(
|
|
4793
|
+
(ref1 = glob.object.children)[ref1.length - 1]
|
|
4736
4794
|
// whitespace and }
|
|
4737
4795
|
],
|
|
4738
4796
|
properties: parts,
|
|
@@ -4784,7 +4842,7 @@ function replaceNode(node, newNode, parent) {
|
|
|
4784
4842
|
throw new Error("replaceNode failed: node has no parent");
|
|
4785
4843
|
}
|
|
4786
4844
|
function recurse(children) {
|
|
4787
|
-
for (let i3 = 0,
|
|
4845
|
+
for (let i3 = 0, len22 = children.length; i3 < len22; i3++) {
|
|
4788
4846
|
const i = i3;
|
|
4789
4847
|
const child = children[i3];
|
|
4790
4848
|
if (child === node) {
|
|
@@ -4874,8 +4932,8 @@ function convertNamedImportsToObject(node, pattern) {
|
|
|
4874
4932
|
return { type: "Error", message: "cannot use `type` in dynamic import" };
|
|
4875
4933
|
} else {
|
|
4876
4934
|
const { source, binding } = specifier;
|
|
4877
|
-
let
|
|
4878
|
-
const delim = (
|
|
4935
|
+
let ref2;
|
|
4936
|
+
const delim = (ref2 = specifier.children)[ref2.length - 1];
|
|
4879
4937
|
return {
|
|
4880
4938
|
type: pattern ? "BindingProperty" : "Property",
|
|
4881
4939
|
name: source,
|
|
@@ -4885,7 +4943,7 @@ function convertNamedImportsToObject(node, pattern) {
|
|
|
4885
4943
|
};
|
|
4886
4944
|
}
|
|
4887
4945
|
});
|
|
4888
|
-
let
|
|
4946
|
+
let ref3;
|
|
4889
4947
|
return {
|
|
4890
4948
|
type: pattern ? "ObjectBindingPattern" : "ObjectExpression",
|
|
4891
4949
|
names: node.names,
|
|
@@ -4894,7 +4952,7 @@ function convertNamedImportsToObject(node, pattern) {
|
|
|
4894
4952
|
node.children[0],
|
|
4895
4953
|
// {
|
|
4896
4954
|
properties,
|
|
4897
|
-
(
|
|
4955
|
+
(ref3 = node.children)[ref3.length - 1]
|
|
4898
4956
|
// }
|
|
4899
4957
|
]
|
|
4900
4958
|
};
|
|
@@ -5071,17 +5129,17 @@ function processAssignments(statements) {
|
|
|
5071
5129
|
statements,
|
|
5072
5130
|
(n) => n.type === "AssignmentExpression" && n.names === null,
|
|
5073
5131
|
(exp) => {
|
|
5074
|
-
let { lhs: $1, expression: $2 } = exp, tail = [], i = 0,
|
|
5132
|
+
let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len3 = $1.length;
|
|
5075
5133
|
let block;
|
|
5076
|
-
let
|
|
5077
|
-
if (exp.parent?.type === "BlockStatement" && !(
|
|
5134
|
+
let ref4;
|
|
5135
|
+
if (exp.parent?.type === "BlockStatement" && !(ref4 = $1[$1.length - 1])?.[ref4.length - 1]?.special) {
|
|
5078
5136
|
block = makeBlockFragment();
|
|
5079
|
-
let
|
|
5080
|
-
if (
|
|
5137
|
+
let ref5;
|
|
5138
|
+
if (ref5 = prependStatementExpressionBlock(
|
|
5081
5139
|
{ type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
|
|
5082
5140
|
block
|
|
5083
5141
|
)) {
|
|
5084
|
-
const ref =
|
|
5142
|
+
const ref = ref5;
|
|
5085
5143
|
exp.children = exp.children.map(function(c) {
|
|
5086
5144
|
if (c === $2)
|
|
5087
5145
|
return ref;
|
|
@@ -5111,7 +5169,7 @@ function processAssignments(statements) {
|
|
|
5111
5169
|
}
|
|
5112
5170
|
}
|
|
5113
5171
|
let wrapped = false;
|
|
5114
|
-
while (i <
|
|
5172
|
+
while (i < len3) {
|
|
5115
5173
|
const lastAssignment = $1[i++];
|
|
5116
5174
|
const [, lhs, , op] = lastAssignment;
|
|
5117
5175
|
if (op.token !== "=")
|
|
@@ -5124,7 +5182,7 @@ function processAssignments(statements) {
|
|
|
5124
5182
|
}
|
|
5125
5183
|
}
|
|
5126
5184
|
}
|
|
5127
|
-
i =
|
|
5185
|
+
i = len3 - 1;
|
|
5128
5186
|
while (i >= 0) {
|
|
5129
5187
|
const lastAssignment = $1[i];
|
|
5130
5188
|
if (lastAssignment[3].token === "=") {
|
|
@@ -5160,14 +5218,14 @@ function processAssignments(statements) {
|
|
|
5160
5218
|
}
|
|
5161
5219
|
i--;
|
|
5162
5220
|
}
|
|
5163
|
-
i =
|
|
5221
|
+
i = len3 - 1;
|
|
5164
5222
|
const optionalChainRef = makeRef();
|
|
5165
5223
|
while (i >= 0) {
|
|
5166
5224
|
const assignment = $1[i];
|
|
5167
5225
|
const [ws1, lhs, ws2, op] = assignment;
|
|
5168
5226
|
if (lhs.type === "MemberExpression" || lhs.type === "CallExpression") {
|
|
5169
5227
|
const newMemberExp = unchainOptionalMemberExpression(lhs, optionalChainRef, (children) => {
|
|
5170
|
-
const assigns = $1.splice(i + 1,
|
|
5228
|
+
const assigns = $1.splice(i + 1, len3 - 1 - i);
|
|
5171
5229
|
$1.pop();
|
|
5172
5230
|
return [ws1, ...children, ws2, op, ...assigns, $2];
|
|
5173
5231
|
});
|
|
@@ -5249,9 +5307,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
|
|
|
5249
5307
|
}
|
|
5250
5308
|
j++;
|
|
5251
5309
|
}
|
|
5252
|
-
let
|
|
5253
|
-
if (
|
|
5254
|
-
const l =
|
|
5310
|
+
let ref6;
|
|
5311
|
+
if (ref6 = conditions.length) {
|
|
5312
|
+
const l = ref6;
|
|
5255
5313
|
const cs = flatJoin(conditions, " && ");
|
|
5256
5314
|
return {
|
|
5257
5315
|
...exp,
|
|
@@ -5288,8 +5346,8 @@ function processTypes(node) {
|
|
|
5288
5346
|
return gatherRecursiveAll(node, (n) => n.type === "UnaryType").forEach((unary) => {
|
|
5289
5347
|
let last;
|
|
5290
5348
|
let count = 0;
|
|
5291
|
-
let
|
|
5292
|
-
while (unary.suffix.length && (
|
|
5349
|
+
let ref7;
|
|
5350
|
+
while (unary.suffix.length && (ref7 = unary.suffix)[ref7.length - 1]?.token === "?") {
|
|
5293
5351
|
last = unary.suffix.pop();
|
|
5294
5352
|
count++;
|
|
5295
5353
|
}
|
|
@@ -5323,11 +5381,11 @@ function processStatementExpressions(statements) {
|
|
|
5323
5381
|
gatherRecursiveAll(statements, ($) => $.type === "StatementExpression").forEach((_exp) => {
|
|
5324
5382
|
const exp = _exp;
|
|
5325
5383
|
const { statement } = exp;
|
|
5326
|
-
let
|
|
5384
|
+
let ref8;
|
|
5327
5385
|
switch (statement.type) {
|
|
5328
5386
|
case "IfStatement": {
|
|
5329
|
-
if (
|
|
5330
|
-
const expression =
|
|
5387
|
+
if (ref8 = expressionizeIfStatement(statement)) {
|
|
5388
|
+
const expression = ref8;
|
|
5331
5389
|
return replaceNode(statement, expression, exp);
|
|
5332
5390
|
} else {
|
|
5333
5391
|
return replaceNode(statement, wrapIIFE([["", statement]]), exp);
|
|
@@ -5335,7 +5393,8 @@ function processStatementExpressions(statements) {
|
|
|
5335
5393
|
}
|
|
5336
5394
|
case "IterationExpression": {
|
|
5337
5395
|
if (statement.subtype === "ComptimeStatement") {
|
|
5338
|
-
const
|
|
5396
|
+
const { expressions } = statement.statement.block;
|
|
5397
|
+
const expression = wrapIIFE(expressions, hasAwait(expressions));
|
|
5339
5398
|
return replaceNode(statement, makeNode({
|
|
5340
5399
|
type: "ComptimeExpression",
|
|
5341
5400
|
expression,
|
|
@@ -5413,7 +5472,13 @@ function processProgram(root) {
|
|
|
5413
5472
|
processBlocks(statements);
|
|
5414
5473
|
populateRefs(statements);
|
|
5415
5474
|
adjustAtBindings(statements);
|
|
5416
|
-
|
|
5475
|
+
if (getSync()) {
|
|
5476
|
+
processComptime(statements);
|
|
5477
|
+
}
|
|
5478
|
+
}
|
|
5479
|
+
async function processProgramAsync(root) {
|
|
5480
|
+
const { expressions: statements } = root;
|
|
5481
|
+
await processComptime(statements);
|
|
5417
5482
|
}
|
|
5418
5483
|
function populateRefs(statements) {
|
|
5419
5484
|
const refNodes = gatherRecursive(statements, ({ type }) => type === "Ref");
|
|
@@ -5537,8 +5602,8 @@ function processPlaceholders(statements) {
|
|
|
5537
5602
|
for (let i4 = 0, len3 = placeholders.length; i4 < len3; i4++) {
|
|
5538
5603
|
const placeholder = placeholders[i4];
|
|
5539
5604
|
typeSuffix ??= placeholder.typeSuffix;
|
|
5540
|
-
let
|
|
5541
|
-
replaceNode((
|
|
5605
|
+
let ref9;
|
|
5606
|
+
replaceNode((ref9 = placeholder.children)[ref9.length - 1], ref);
|
|
5542
5607
|
}
|
|
5543
5608
|
const { parent } = ancestor;
|
|
5544
5609
|
const body = maybeUnwrap(ancestor);
|
|
@@ -5569,9 +5634,9 @@ function processPlaceholders(statements) {
|
|
|
5569
5634
|
fnExp = makeLeftHandSideExpression(fnExp);
|
|
5570
5635
|
}
|
|
5571
5636
|
replaceNode(ancestor, fnExp, parent);
|
|
5572
|
-
let
|
|
5573
|
-
if (
|
|
5574
|
-
const ws =
|
|
5637
|
+
let ref10;
|
|
5638
|
+
if (ref10 = getTrimmingSpace(body)) {
|
|
5639
|
+
const ws = ref10;
|
|
5575
5640
|
inplaceInsertTrimmingSpace(body, "");
|
|
5576
5641
|
inplacePrepend(ws, fnExp);
|
|
5577
5642
|
}
|
|
@@ -5616,8 +5681,8 @@ function reorderBindingRestProperty(props) {
|
|
|
5616
5681
|
}
|
|
5617
5682
|
];
|
|
5618
5683
|
}
|
|
5619
|
-
let
|
|
5620
|
-
if (Array.isArray(rest.delim) && (
|
|
5684
|
+
let ref11;
|
|
5685
|
+
if (Array.isArray(rest.delim) && (ref11 = rest.delim)[ref11.length - 1]?.token === ",") {
|
|
5621
5686
|
rest.delim = rest.delim.slice(0, -1);
|
|
5622
5687
|
rest.children = [...rest.children.slice(0, -1), rest.delim];
|
|
5623
5688
|
}
|
|
@@ -6815,15 +6880,20 @@ var $R92 = (0, import_lib2.$R)(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
|
|
|
6815
6880
|
var $R93 = (0, import_lib2.$R)(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
|
|
6816
6881
|
var $R94 = (0, import_lib2.$R)(new RegExp("[^]*", "suy"));
|
|
6817
6882
|
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) {
|
|
6883
|
+
var reset = $1;
|
|
6884
|
+
var init = $2;
|
|
6885
|
+
var ws1 = $3;
|
|
6818
6886
|
var statements = $4;
|
|
6819
|
-
|
|
6887
|
+
var ws2 = $5;
|
|
6888
|
+
const program = {
|
|
6820
6889
|
type: "BlockStatement",
|
|
6821
6890
|
expressions: statements,
|
|
6822
|
-
children: [statements],
|
|
6891
|
+
children: [reset, init, ws1, statements, ws2],
|
|
6823
6892
|
bare: true,
|
|
6824
6893
|
root: true
|
|
6825
|
-
}
|
|
6826
|
-
|
|
6894
|
+
};
|
|
6895
|
+
processProgram(program);
|
|
6896
|
+
return program;
|
|
6827
6897
|
});
|
|
6828
6898
|
function Program(ctx, state2) {
|
|
6829
6899
|
return (0, import_lib2.$EVENT)(ctx, state2, "Program", Program$0);
|
|
@@ -7262,8 +7332,8 @@ var SingleLineBinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impor
|
|
|
7262
7332
|
function SingleLineBinaryOpRHS(ctx, state2) {
|
|
7263
7333
|
return (0, import_lib2.$EVENT)(ctx, state2, "SingleLineBinaryOpRHS", SingleLineBinaryOpRHS$0);
|
|
7264
7334
|
}
|
|
7265
|
-
var RHS$0 =
|
|
7266
|
-
var RHS$1 =
|
|
7335
|
+
var RHS$0 = ExpressionizedStatementWithTrailingCallExpressions;
|
|
7336
|
+
var RHS$1 = UnaryExpression;
|
|
7267
7337
|
var RHS$$ = [RHS$0, RHS$1];
|
|
7268
7338
|
function RHS(ctx, state2) {
|
|
7269
7339
|
return (0, import_lib2.$EVENT_C)(ctx, state2, "RHS", RHS$$);
|
|
@@ -8421,11 +8491,11 @@ var PropertyAccess$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(AccessStart, (0,
|
|
|
8421
8491
|
var dot = $1;
|
|
8422
8492
|
var neg = $2;
|
|
8423
8493
|
var num = $3;
|
|
8424
|
-
const
|
|
8494
|
+
const len3 = {
|
|
8425
8495
|
children: []
|
|
8426
8496
|
}, children = [
|
|
8427
8497
|
adjustIndexAccess(dot),
|
|
8428
|
-
|
|
8498
|
+
len3,
|
|
8429
8499
|
neg,
|
|
8430
8500
|
num,
|
|
8431
8501
|
"]"
|
|
@@ -8433,7 +8503,7 @@ var PropertyAccess$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(AccessStart, (0,
|
|
|
8433
8503
|
return {
|
|
8434
8504
|
type: "NegativeIndex",
|
|
8435
8505
|
children,
|
|
8436
|
-
len:
|
|
8506
|
+
len: len3
|
|
8437
8507
|
};
|
|
8438
8508
|
});
|
|
8439
8509
|
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) {
|
|
@@ -13519,7 +13589,7 @@ var Comma$0 = (0, import_lib2.$TV)((0, import_lib2.$EXPECT)($L25, 'Comma ","'),
|
|
|
13519
13589
|
function Comma(ctx, state2) {
|
|
13520
13590
|
return (0, import_lib2.$EVENT)(ctx, state2, "Comma", Comma$0);
|
|
13521
13591
|
}
|
|
13522
|
-
var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
13592
|
+
var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($L15, 'Comptime ":"'))), function($skip, $loc, $0, $1, $2, $3) {
|
|
13523
13593
|
return { $loc, token: $1 };
|
|
13524
13594
|
});
|
|
13525
13595
|
function Comptime(ctx, state2) {
|
|
@@ -16105,26 +16175,29 @@ var parser = function() {
|
|
|
16105
16175
|
const parser2 = options.startRule != null ? grammar[options.startRule] : Object.values(grammar)[0];
|
|
16106
16176
|
if (!parser2)
|
|
16107
16177
|
throw new Error(`Could not find rule with name '${options.startRule}'`);
|
|
16108
|
-
const
|
|
16178
|
+
const filename2 = options.filename || "<anonymous>";
|
|
16109
16179
|
reset();
|
|
16110
16180
|
Object.assign(ctx, { ...options.events, tokenize: options.tokenize });
|
|
16111
16181
|
return validate(input, parser2(ctx, {
|
|
16112
16182
|
input,
|
|
16113
16183
|
pos: 0
|
|
16114
16184
|
}), {
|
|
16115
|
-
filename
|
|
16185
|
+
filename: filename2
|
|
16116
16186
|
});
|
|
16117
16187
|
}
|
|
16118
16188
|
};
|
|
16119
16189
|
}();
|
|
16120
16190
|
var { parse } = parser;
|
|
16191
|
+
var filename;
|
|
16121
16192
|
var initialConfig;
|
|
16122
16193
|
var config;
|
|
16194
|
+
var sync;
|
|
16123
16195
|
var state = {};
|
|
16124
16196
|
var getState = () => state;
|
|
16125
16197
|
var getConfig = () => config;
|
|
16126
16198
|
var getInitialConfig = () => initialConfig;
|
|
16127
|
-
var
|
|
16199
|
+
var getFilename = () => filename;
|
|
16200
|
+
var getSync = () => sync;
|
|
16128
16201
|
Object.defineProperties(state, {
|
|
16129
16202
|
currentIndent: {
|
|
16130
16203
|
get() {
|
|
@@ -16169,6 +16242,21 @@ Object.defineProperties(state, {
|
|
|
16169
16242
|
}
|
|
16170
16243
|
}
|
|
16171
16244
|
});
|
|
16245
|
+
function parseProgram(input, options) {
|
|
16246
|
+
filename = options?.filename;
|
|
16247
|
+
initialConfig = options?.parseOptions;
|
|
16248
|
+
sync = options?.sync;
|
|
16249
|
+
const root = parse(input, options);
|
|
16250
|
+
if (sync) {
|
|
16251
|
+
filename = initialConfig = sync = null;
|
|
16252
|
+
return root;
|
|
16253
|
+
} else {
|
|
16254
|
+
return processProgramAsync(root).then(() => {
|
|
16255
|
+
filename = initialConfig = sync = null;
|
|
16256
|
+
return root;
|
|
16257
|
+
});
|
|
16258
|
+
}
|
|
16259
|
+
}
|
|
16172
16260
|
|
|
16173
16261
|
// source/util.civet
|
|
16174
16262
|
var util_exports = {};
|
|
@@ -16595,15 +16683,15 @@ var uncacheable = /* @__PURE__ */ new Set([
|
|
|
16595
16683
|
"RestoreTrailingMemberProperty",
|
|
16596
16684
|
"RestoreNewlineBinaryOp"
|
|
16597
16685
|
]);
|
|
16598
|
-
|
|
16686
|
+
function compile(src, options) {
|
|
16599
16687
|
if (!options) {
|
|
16600
16688
|
options = {};
|
|
16601
16689
|
} else {
|
|
16602
16690
|
options = { ...options };
|
|
16603
16691
|
}
|
|
16604
16692
|
options.parseOptions = { ...options.parseOptions };
|
|
16605
|
-
const
|
|
16606
|
-
if (
|
|
16693
|
+
const filename2 = options.filename || "unknown";
|
|
16694
|
+
if (filename2.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
16607
16695
|
options.parseOptions.coffeeCompat = true;
|
|
16608
16696
|
}
|
|
16609
16697
|
const { hits, trace, noCache } = options;
|
|
@@ -16615,21 +16703,18 @@ var compile = function(src, options) {
|
|
|
16615
16703
|
});
|
|
16616
16704
|
}
|
|
16617
16705
|
let ast;
|
|
16618
|
-
setInitialConfig(options.parseOptions);
|
|
16619
16706
|
try {
|
|
16620
|
-
ast =
|
|
16621
|
-
|
|
16707
|
+
ast = parseProgram(src, {
|
|
16708
|
+
parseOptions: options.parseOptions,
|
|
16709
|
+
sync: options.sync,
|
|
16710
|
+
filename: filename2,
|
|
16622
16711
|
events
|
|
16623
16712
|
});
|
|
16624
|
-
if (!(options.ast === "raw")) {
|
|
16625
|
-
ast = prune(ast);
|
|
16626
|
-
}
|
|
16627
16713
|
} finally {
|
|
16628
|
-
setInitialConfig(void 0);
|
|
16629
16714
|
if (hits || trace) {
|
|
16630
|
-
import("fs").then(function({ writeFileSync }) {
|
|
16715
|
+
import("node:fs").then(function({ writeFileSync }) {
|
|
16631
16716
|
let ref;
|
|
16632
|
-
if ((ref = events?.meta) && "logs" in ref) {
|
|
16717
|
+
if ((ref = events?.meta) && typeof ref === "object" && "logs" in ref) {
|
|
16633
16718
|
const { logs } = ref;
|
|
16634
16719
|
if (trace) {
|
|
16635
16720
|
writeFileSync(trace, logs.join("\n"));
|
|
@@ -16658,28 +16743,45 @@ ${counts}`;
|
|
|
16658
16743
|
});
|
|
16659
16744
|
}
|
|
16660
16745
|
}
|
|
16661
|
-
|
|
16662
|
-
|
|
16663
|
-
|
|
16664
|
-
|
|
16665
|
-
|
|
16666
|
-
options.
|
|
16667
|
-
|
|
16668
|
-
|
|
16669
|
-
|
|
16670
|
-
|
|
16671
|
-
|
|
16672
|
-
|
|
16673
|
-
|
|
16674
|
-
|
|
16746
|
+
function rest(ast2) {
|
|
16747
|
+
options = options;
|
|
16748
|
+
if (!(options.ast === "raw")) {
|
|
16749
|
+
ast2 = prune(ast2);
|
|
16750
|
+
}
|
|
16751
|
+
if (options.ast) {
|
|
16752
|
+
return ast2;
|
|
16753
|
+
}
|
|
16754
|
+
function checkErrors() {
|
|
16755
|
+
if (options.errors?.length) {
|
|
16756
|
+
throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
|
|
16757
|
+
}
|
|
16758
|
+
;
|
|
16759
|
+
return;
|
|
16760
|
+
}
|
|
16761
|
+
if (options.sourceMap || options.inlineMap) {
|
|
16762
|
+
const sm = SourceMap2(src);
|
|
16763
|
+
options.updateSourceMap = sm.updateSourceMap;
|
|
16764
|
+
const code = generate_default(ast2, options);
|
|
16765
|
+
checkErrors();
|
|
16766
|
+
if (options.inlineMap) {
|
|
16767
|
+
return SourceMap2.remap(code, sm, filename2, filename2 + ".tsx");
|
|
16768
|
+
} else {
|
|
16769
|
+
return {
|
|
16770
|
+
code,
|
|
16771
|
+
sourceMap: sm
|
|
16772
|
+
};
|
|
16773
|
+
}
|
|
16675
16774
|
}
|
|
16775
|
+
const result = generate_default(ast2, options);
|
|
16776
|
+
checkErrors();
|
|
16777
|
+
return result;
|
|
16676
16778
|
}
|
|
16677
|
-
|
|
16678
|
-
|
|
16679
|
-
|
|
16779
|
+
if (ast.then != null) {
|
|
16780
|
+
return ast.then(rest);
|
|
16781
|
+
} else {
|
|
16782
|
+
return rest(ast);
|
|
16680
16783
|
}
|
|
16681
|
-
|
|
16682
|
-
};
|
|
16784
|
+
}
|
|
16683
16785
|
var makeCache = function({ hits, trace } = {}) {
|
|
16684
16786
|
const meta = {};
|
|
16685
16787
|
let hitCount;
|
|
@@ -16746,7 +16848,7 @@ var isCompileError = function(err) {
|
|
|
16746
16848
|
return err instanceof Error && //@ts-ignore
|
|
16747
16849
|
[err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
|
|
16748
16850
|
};
|
|
16749
|
-
var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
|
|
16851
|
+
var main_default = { parse, parseProgram, generate: generate_default, util: util_exports, compile, isCompileError };
|
|
16750
16852
|
// Annotate the CommonJS export names for ESM import in node:
|
|
16751
16853
|
0 && (module.exports = {
|
|
16752
16854
|
compile,
|
|
@@ -16754,6 +16856,7 @@ var main_default = { parse, generate: generate_default, util: util_exports, comp
|
|
|
16754
16856
|
isCompileError,
|
|
16755
16857
|
lib,
|
|
16756
16858
|
parse,
|
|
16859
|
+
parseProgram,
|
|
16757
16860
|
prune,
|
|
16758
16861
|
util
|
|
16759
16862
|
});
|