@danielx/civet 0.6.87 → 0.6.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/browser.js +219 -34
- package/dist/civet +106 -10
- package/dist/esm.mjs +0 -11
- package/dist/main.js +219 -34
- package/dist/main.mjs +219 -34
- package/package.json +2 -2
- package/register.js +20 -4
package/README.md
CHANGED
|
@@ -22,10 +22,9 @@ The modern way to write TypeScript.
|
|
|
22
22
|
[esbuild](source/esbuild-plugin.civet),
|
|
23
23
|
[Vite](https://github.com/edemaine/vite-plugin-civet),
|
|
24
24
|
-->
|
|
25
|
+
[ESM/CJS loader](source/esm.civet),
|
|
25
26
|
[Babel](source/babel-plugin.mjs),
|
|
26
27
|
[Gulp](integration/gulp),
|
|
27
|
-
[ESM module resolution](source/esm.civet),
|
|
28
|
-
[CJS](register.js),
|
|
29
28
|
[Bun](source/bun-civet.civet)
|
|
30
29
|
- Starter templates for [Solid](https://github.com/orenelbaum/solid-civet-template) and [Solid Start](https://github.com/orenelbaum/solid-start-civet-template)
|
|
31
30
|
|
|
@@ -43,8 +42,8 @@ civet -c
|
|
|
43
42
|
civet < source.civet > output.ts
|
|
44
43
|
# Execute a .civet script
|
|
45
44
|
civet source.civet ...args...
|
|
46
|
-
# Execute a .civet source file in node
|
|
47
|
-
node --
|
|
45
|
+
# Execute a .civet source file in node
|
|
46
|
+
node --import @danielx/civet/register source.civet
|
|
48
47
|
```
|
|
49
48
|
|
|
50
49
|

|
package/dist/browser.js
CHANGED
|
@@ -1712,7 +1712,11 @@ var Civet = (() => {
|
|
|
1712
1712
|
}
|
|
1713
1713
|
case "Identifier":
|
|
1714
1714
|
case "BindingProperty": {
|
|
1715
|
-
const children = [
|
|
1715
|
+
const children = [
|
|
1716
|
+
// { name: value } = ... declares value, not name
|
|
1717
|
+
pattern.value ?? pattern.name,
|
|
1718
|
+
pattern.delim
|
|
1719
|
+
];
|
|
1716
1720
|
if (isWhitespaceOrEmpty(pattern.children[0])) {
|
|
1717
1721
|
children.unshift(pattern.children[0]);
|
|
1718
1722
|
}
|
|
@@ -2320,6 +2324,111 @@ var Civet = (() => {
|
|
|
2320
2324
|
}
|
|
2321
2325
|
}
|
|
2322
2326
|
}
|
|
2327
|
+
function dynamizeFromClause(from) {
|
|
2328
|
+
from = from.slice(1);
|
|
2329
|
+
from = insertTrimmingSpace(from, "");
|
|
2330
|
+
if (from.at(-1)?.type === "ImportAssertion") {
|
|
2331
|
+
const assert2 = from.pop();
|
|
2332
|
+
from.push(", {", assert2.keyword, ":", assert2.object, "}");
|
|
2333
|
+
}
|
|
2334
|
+
return ["(", ...from, ")"];
|
|
2335
|
+
}
|
|
2336
|
+
function dynamizeImportDeclaration(decl) {
|
|
2337
|
+
const { imports } = decl;
|
|
2338
|
+
let { star, binding, specifiers } = imports;
|
|
2339
|
+
const justDefault = binding && !specifiers && !star;
|
|
2340
|
+
const pattern = (() => {
|
|
2341
|
+
{
|
|
2342
|
+
if (binding) {
|
|
2343
|
+
if (specifiers) {
|
|
2344
|
+
return makeRef();
|
|
2345
|
+
} else {
|
|
2346
|
+
return binding;
|
|
2347
|
+
}
|
|
2348
|
+
} else {
|
|
2349
|
+
return convertNamedImportsToObject(imports, true);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
})();
|
|
2353
|
+
const c = "const";
|
|
2354
|
+
const initializer = [
|
|
2355
|
+
" = ",
|
|
2356
|
+
justDefault ? "(" : void 0,
|
|
2357
|
+
{ type: "Await", children: ["await"] },
|
|
2358
|
+
" ",
|
|
2359
|
+
decl.children[0],
|
|
2360
|
+
// import
|
|
2361
|
+
dynamizeFromClause(decl.from),
|
|
2362
|
+
justDefault ? ").default" : void 0
|
|
2363
|
+
];
|
|
2364
|
+
const bindings = [{
|
|
2365
|
+
type: "Binding",
|
|
2366
|
+
names: pattern.names,
|
|
2367
|
+
pattern,
|
|
2368
|
+
initializer,
|
|
2369
|
+
children: [pattern, initializer]
|
|
2370
|
+
}];
|
|
2371
|
+
if (binding && specifiers) {
|
|
2372
|
+
const pattern2 = binding;
|
|
2373
|
+
const initializer2 = [
|
|
2374
|
+
" = ",
|
|
2375
|
+
pattern,
|
|
2376
|
+
".default"
|
|
2377
|
+
];
|
|
2378
|
+
bindings.push({
|
|
2379
|
+
type: "Binding",
|
|
2380
|
+
names: binding.names,
|
|
2381
|
+
pattern: pattern2,
|
|
2382
|
+
initializer: initializer2,
|
|
2383
|
+
children: [pattern2, initializer2]
|
|
2384
|
+
});
|
|
2385
|
+
const pattern3 = convertNamedImportsToObject(imports.children.at(-1), true);
|
|
2386
|
+
const initializer3 = [
|
|
2387
|
+
" = ",
|
|
2388
|
+
pattern
|
|
2389
|
+
];
|
|
2390
|
+
bindings.push({
|
|
2391
|
+
type: "Binding",
|
|
2392
|
+
names: specifiers.names,
|
|
2393
|
+
pattern: pattern3,
|
|
2394
|
+
initializer: initializer3,
|
|
2395
|
+
children: [pattern3, initializer3]
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
return {
|
|
2399
|
+
type: "Declaration",
|
|
2400
|
+
names: imports.names,
|
|
2401
|
+
bindings,
|
|
2402
|
+
decl: c,
|
|
2403
|
+
children: [
|
|
2404
|
+
c,
|
|
2405
|
+
" ",
|
|
2406
|
+
bindings.flatMap((binding2, i) => i > 0 ? [", ", binding2] : [binding2])
|
|
2407
|
+
]
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
function dynamizeImportDeclarationExpression($0) {
|
|
2411
|
+
const [imp, ws1, named, ws2, from] = $0;
|
|
2412
|
+
const object = convertNamedImportsToObject(named);
|
|
2413
|
+
const dot = ".";
|
|
2414
|
+
return processCallMemberExpression({
|
|
2415
|
+
type: "CallExpression",
|
|
2416
|
+
children: [
|
|
2417
|
+
{ type: "Await", children: "await" },
|
|
2418
|
+
" ",
|
|
2419
|
+
imp,
|
|
2420
|
+
insertTrimmingSpace(ws2, ""),
|
|
2421
|
+
dynamizeFromClause(from),
|
|
2422
|
+
{
|
|
2423
|
+
type: "PropertyGlob",
|
|
2424
|
+
dot,
|
|
2425
|
+
object,
|
|
2426
|
+
children: [ws1, dot, object],
|
|
2427
|
+
reversed: true
|
|
2428
|
+
}
|
|
2429
|
+
]
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2323
2432
|
var init_declaration = __esm({
|
|
2324
2433
|
"source/parser/declaration.civet"() {
|
|
2325
2434
|
"use strict";
|
|
@@ -2329,6 +2438,7 @@ var Civet = (() => {
|
|
|
2329
2438
|
init_util();
|
|
2330
2439
|
init_function();
|
|
2331
2440
|
init_binding();
|
|
2441
|
+
init_lib();
|
|
2332
2442
|
}
|
|
2333
2443
|
});
|
|
2334
2444
|
|
|
@@ -3145,10 +3255,13 @@ var Civet = (() => {
|
|
|
3145
3255
|
adjustIndexAccess: () => adjustIndexAccess,
|
|
3146
3256
|
attachPostfixStatementAsExpression: () => attachPostfixStatementAsExpression,
|
|
3147
3257
|
blockWithPrefix: () => blockWithPrefix,
|
|
3258
|
+
convertNamedImportsToObject: () => convertNamedImportsToObject,
|
|
3148
3259
|
convertObjectToJSXAttributes: () => convertObjectToJSXAttributes,
|
|
3149
3260
|
dedentBlockString: () => dedentBlockString,
|
|
3150
3261
|
dedentBlockSubstitutions: () => dedentBlockSubstitutions,
|
|
3151
3262
|
deepCopy: () => deepCopy,
|
|
3263
|
+
dynamizeImportDeclaration: () => dynamizeImportDeclaration,
|
|
3264
|
+
dynamizeImportDeclarationExpression: () => dynamizeImportDeclarationExpression,
|
|
3152
3265
|
expressionizeTypeIf: () => expressionizeTypeIf,
|
|
3153
3266
|
forRange: () => forRange,
|
|
3154
3267
|
gatherBindingCode: () => gatherBindingCode,
|
|
@@ -3420,9 +3533,13 @@ var Civet = (() => {
|
|
|
3420
3533
|
throw new Error(`Glob pattern must have call or member expression value, found ${JSON.stringify(part.value)}`);
|
|
3421
3534
|
}
|
|
3422
3535
|
let suppressPrefix = false;
|
|
3423
|
-
let
|
|
3536
|
+
let name = part.name;
|
|
3537
|
+
let value = part.value ?? name;
|
|
3424
3538
|
const wValue = getTrimmingSpace(part.value);
|
|
3425
3539
|
[value, suppressPrefix] = handleThisPrivateShorthands(value);
|
|
3540
|
+
if (glob.reversed) {
|
|
3541
|
+
[name, value] = [value, name];
|
|
3542
|
+
}
|
|
3426
3543
|
if (!suppressPrefix) {
|
|
3427
3544
|
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
3428
3545
|
}
|
|
@@ -3440,13 +3557,13 @@ var Civet = (() => {
|
|
|
3440
3557
|
} else {
|
|
3441
3558
|
parts.push({
|
|
3442
3559
|
type: part.type === "Identifier" ? "Property" : part.type,
|
|
3443
|
-
name
|
|
3560
|
+
name,
|
|
3444
3561
|
value,
|
|
3445
3562
|
delim: part.delim,
|
|
3446
3563
|
names: part.names,
|
|
3447
3564
|
children: [
|
|
3448
3565
|
isWhitespaceOrEmpty(part.children[0]) && part.children[0],
|
|
3449
|
-
|
|
3566
|
+
name,
|
|
3450
3567
|
isWhitespaceOrEmpty(part.children[2]) && part.children[2],
|
|
3451
3568
|
part.children[3]?.token === ":" ? part.children[3] : ":",
|
|
3452
3569
|
value,
|
|
@@ -3591,6 +3708,35 @@ var Civet = (() => {
|
|
|
3591
3708
|
block
|
|
3592
3709
|
};
|
|
3593
3710
|
}
|
|
3711
|
+
function convertNamedImportsToObject(node, pattern) {
|
|
3712
|
+
const properties = node.specifiers.map((specifier) => {
|
|
3713
|
+
if (specifier.ts) {
|
|
3714
|
+
return { type: "Error", message: "cannot use `type` in dynamic import" };
|
|
3715
|
+
} else {
|
|
3716
|
+
const { source, binding } = specifier;
|
|
3717
|
+
const delim = specifier.children.at(-1);
|
|
3718
|
+
return {
|
|
3719
|
+
type: pattern ? "BindingProperty" : "Property",
|
|
3720
|
+
name: source,
|
|
3721
|
+
value: !(source === binding) ? binding : void 0,
|
|
3722
|
+
delim,
|
|
3723
|
+
children: source === binding ? [source, delim] : [source, ":", binding, delim]
|
|
3724
|
+
};
|
|
3725
|
+
}
|
|
3726
|
+
});
|
|
3727
|
+
return {
|
|
3728
|
+
type: pattern ? "ObjectBindingPattern" : "ObjectExpression",
|
|
3729
|
+
names: node.names,
|
|
3730
|
+
properties,
|
|
3731
|
+
children: [
|
|
3732
|
+
node.children[0],
|
|
3733
|
+
// {
|
|
3734
|
+
properties,
|
|
3735
|
+
node.children.at(-1)
|
|
3736
|
+
// }
|
|
3737
|
+
]
|
|
3738
|
+
};
|
|
3739
|
+
}
|
|
3594
3740
|
function convertObjectToJSXAttributes(obj) {
|
|
3595
3741
|
const { properties } = obj;
|
|
3596
3742
|
const parts = [];
|
|
@@ -7066,14 +7212,17 @@ ${input.slice(result.pos)}
|
|
|
7066
7212
|
children: [$1, ...$2, ...rest.flat()]
|
|
7067
7213
|
});
|
|
7068
7214
|
});
|
|
7069
|
-
var CallExpression$1 = $TS($S(
|
|
7215
|
+
var CallExpression$1 = $TS($S(Import, _, NamedImports, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
7216
|
+
return dynamizeImportDeclarationExpression($0);
|
|
7217
|
+
});
|
|
7218
|
+
var CallExpression$2 = $TS($S($EXPECT($L20, 'CallExpression "import"'), ArgumentsWithTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
7070
7219
|
var rest = $3;
|
|
7071
7220
|
return processCallMemberExpression({
|
|
7072
7221
|
type: "CallExpression",
|
|
7073
7222
|
children: [$1, ...$2, ...rest.flat()]
|
|
7074
7223
|
});
|
|
7075
7224
|
});
|
|
7076
|
-
var CallExpression$
|
|
7225
|
+
var CallExpression$3 = $TS($S(MemberExpression, AllowedTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
7077
7226
|
var member = $1;
|
|
7078
7227
|
var trailing = $2;
|
|
7079
7228
|
var rest = $3;
|
|
@@ -7086,7 +7235,7 @@ ${input.slice(result.pos)}
|
|
|
7086
7235
|
}
|
|
7087
7236
|
return member;
|
|
7088
7237
|
});
|
|
7089
|
-
var CallExpression$$ = [CallExpression$0, CallExpression$1, CallExpression$2];
|
|
7238
|
+
var CallExpression$$ = [CallExpression$0, CallExpression$1, CallExpression$2, CallExpression$3];
|
|
7090
7239
|
function CallExpression(ctx, state) {
|
|
7091
7240
|
return $EVENT_C(ctx, state, "CallExpression", CallExpression$$);
|
|
7092
7241
|
}
|
|
@@ -11350,28 +11499,31 @@ ${input.slice(result.pos)}
|
|
|
11350
11499
|
};
|
|
11351
11500
|
});
|
|
11352
11501
|
var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause), function(value) {
|
|
11353
|
-
|
|
11502
|
+
var imports = value[4];
|
|
11503
|
+
var from = value[6];
|
|
11504
|
+
return { "type": "ImportDeclaration", "ts": true, "children": value, "imports": imports, "from": from };
|
|
11354
11505
|
});
|
|
11355
11506
|
var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause), function(value) {
|
|
11356
|
-
|
|
11507
|
+
var imports = value[2];
|
|
11508
|
+
var from = value[4];
|
|
11509
|
+
return { "type": "ImportDeclaration", "children": value, "imports": imports, "from": from };
|
|
11357
11510
|
});
|
|
11358
11511
|
var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier), function(value) {
|
|
11359
|
-
|
|
11512
|
+
var module3 = value[2];
|
|
11513
|
+
return { "type": "ImportDeclaration", "children": value, "module": module3 };
|
|
11360
11514
|
});
|
|
11361
11515
|
var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
11362
11516
|
var i = $1;
|
|
11363
11517
|
var t = $2;
|
|
11364
|
-
var
|
|
11518
|
+
var imports = $3;
|
|
11365
11519
|
var w = $4;
|
|
11366
|
-
var
|
|
11520
|
+
var from = $5;
|
|
11367
11521
|
i.$loc = {
|
|
11368
|
-
pos:
|
|
11369
|
-
length:
|
|
11522
|
+
pos: from[0].$loc.pos - 1,
|
|
11523
|
+
length: from[0].$loc.length + 1
|
|
11370
11524
|
};
|
|
11371
|
-
const children = [i, t,
|
|
11372
|
-
|
|
11373
|
-
return children;
|
|
11374
|
-
return { type: "ImportDeclaration", ts: true, children };
|
|
11525
|
+
const children = [i, t, imports, w, from];
|
|
11526
|
+
return { type: "ImportDeclaration", ts: !!t, children, imports, from };
|
|
11375
11527
|
});
|
|
11376
11528
|
var ImportDeclaration$$ = [ImportDeclaration$0, ImportDeclaration$1, ImportDeclaration$2, ImportDeclaration$3, ImportDeclaration$4];
|
|
11377
11529
|
function ImportDeclaration(ctx, state) {
|
|
@@ -11389,14 +11541,17 @@ ${input.slice(result.pos)}
|
|
|
11389
11541
|
if (rest) {
|
|
11390
11542
|
return {
|
|
11391
11543
|
type: "Declaration",
|
|
11392
|
-
children:
|
|
11393
|
-
names: [...binding.names, ...rest[3].names]
|
|
11544
|
+
children: [binding, ...rest],
|
|
11545
|
+
names: [...binding.names, ...rest[3].names],
|
|
11546
|
+
binding,
|
|
11547
|
+
specifiers: rest[3].specifiers
|
|
11394
11548
|
};
|
|
11395
11549
|
}
|
|
11396
11550
|
return {
|
|
11397
11551
|
type: "Declaration",
|
|
11398
|
-
children:
|
|
11399
|
-
names: binding.names
|
|
11552
|
+
children: [binding],
|
|
11553
|
+
names: binding.names,
|
|
11554
|
+
binding
|
|
11400
11555
|
};
|
|
11401
11556
|
});
|
|
11402
11557
|
var ImportClause$1 = NameSpaceImport;
|
|
@@ -11406,11 +11561,14 @@ ${input.slice(result.pos)}
|
|
|
11406
11561
|
return $EVENT_C(ctx, state, "ImportClause", ImportClause$$);
|
|
11407
11562
|
}
|
|
11408
11563
|
var NameSpaceImport$0 = $TS($S(Star, ImportAsToken, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
11564
|
+
var star = $1;
|
|
11409
11565
|
var binding = $4;
|
|
11410
11566
|
return {
|
|
11411
11567
|
type: "Declaration",
|
|
11412
11568
|
children: $0,
|
|
11413
|
-
names: binding.names
|
|
11569
|
+
names: binding.names,
|
|
11570
|
+
binding,
|
|
11571
|
+
star
|
|
11414
11572
|
};
|
|
11415
11573
|
});
|
|
11416
11574
|
function NameSpaceImport(ctx, state) {
|
|
@@ -11422,17 +11580,32 @@ ${input.slice(result.pos)}
|
|
|
11422
11580
|
return {
|
|
11423
11581
|
type: "Declaration",
|
|
11424
11582
|
children: $0,
|
|
11425
|
-
names
|
|
11583
|
+
names,
|
|
11584
|
+
specifiers
|
|
11426
11585
|
};
|
|
11427
11586
|
});
|
|
11428
11587
|
function NamedImports(ctx, state) {
|
|
11429
11588
|
return $EVENT(ctx, state, "NamedImports", NamedImports$0);
|
|
11430
11589
|
}
|
|
11431
|
-
var FromClause$0 = $S(From, __, ModuleSpecifier)
|
|
11590
|
+
var FromClause$0 = $TS($S(From, __, ModuleSpecifier), function($skip, $loc, $0, $1, $2, $3) {
|
|
11591
|
+
var module3 = $3;
|
|
11592
|
+
if (!Array.isArray(module3))
|
|
11593
|
+
return $0;
|
|
11594
|
+
return [$1, $2, ...module3];
|
|
11595
|
+
});
|
|
11432
11596
|
function FromClause(ctx, state) {
|
|
11433
11597
|
return $EVENT(ctx, state, "FromClause", FromClause$0);
|
|
11434
11598
|
}
|
|
11435
|
-
var ImportAssertion$0 = $S($E(_), $C($EXPECT($L117, 'ImportAssertion "with"'), $EXPECT($L118, 'ImportAssertion "assert"')), NonIdContinue, $E(_), ObjectLiteral)
|
|
11599
|
+
var ImportAssertion$0 = $TS($S($E(_), $C($EXPECT($L117, 'ImportAssertion "with"'), $EXPECT($L118, 'ImportAssertion "assert"')), NonIdContinue, $E(_), ObjectLiteral), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
11600
|
+
var keyword = $2;
|
|
11601
|
+
var object = $5;
|
|
11602
|
+
return {
|
|
11603
|
+
type: "ImportAssertion",
|
|
11604
|
+
keyword,
|
|
11605
|
+
object,
|
|
11606
|
+
children: $0
|
|
11607
|
+
};
|
|
11608
|
+
});
|
|
11436
11609
|
function ImportAssertion(ctx, state) {
|
|
11437
11610
|
return $EVENT(ctx, state, "ImportAssertion", ImportAssertion$0);
|
|
11438
11611
|
}
|
|
@@ -11462,8 +11635,10 @@ ${input.slice(result.pos)}
|
|
|
11462
11635
|
return $EVENT_C(ctx, state, "TypeAndImportSpecifier", TypeAndImportSpecifier$$);
|
|
11463
11636
|
}
|
|
11464
11637
|
var ImportSpecifier$0 = $TS($S(__, ModuleExportName, ImportAsToken, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
|
|
11638
|
+
var source = $2;
|
|
11465
11639
|
var binding = $5;
|
|
11466
11640
|
return {
|
|
11641
|
+
source,
|
|
11467
11642
|
binding,
|
|
11468
11643
|
children: $0
|
|
11469
11644
|
};
|
|
@@ -11471,6 +11646,7 @@ ${input.slice(result.pos)}
|
|
|
11471
11646
|
var ImportSpecifier$1 = $TS($S(__, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3) {
|
|
11472
11647
|
var binding = $2;
|
|
11473
11648
|
return {
|
|
11649
|
+
source: binding,
|
|
11474
11650
|
binding,
|
|
11475
11651
|
children: $0
|
|
11476
11652
|
};
|
|
@@ -11662,9 +11838,18 @@ ${input.slice(result.pos)}
|
|
|
11662
11838
|
function ImplicitExportSpecifier(ctx, state) {
|
|
11663
11839
|
return $EVENT(ctx, state, "ImplicitExportSpecifier", ImplicitExportSpecifier$0);
|
|
11664
11840
|
}
|
|
11665
|
-
var Declaration$0 =
|
|
11666
|
-
|
|
11667
|
-
|
|
11841
|
+
var Declaration$0 = $TV(ImportDeclaration, function($skip, $loc, $0, $1) {
|
|
11842
|
+
var decl = $0;
|
|
11843
|
+
if (decl.ts || decl.module || !decl.imports || !decl.from)
|
|
11844
|
+
return $skip;
|
|
11845
|
+
const { imports } = decl;
|
|
11846
|
+
if (!imports.binding && !imports.specifiers)
|
|
11847
|
+
return $skip;
|
|
11848
|
+
return dynamizeImportDeclaration(decl);
|
|
11849
|
+
});
|
|
11850
|
+
var Declaration$1 = HoistableDeclaration;
|
|
11851
|
+
var Declaration$2 = ClassDeclaration;
|
|
11852
|
+
var Declaration$3 = $TV(LexicalDeclaration, function($skip, $loc, $0, $1) {
|
|
11668
11853
|
var d = $0;
|
|
11669
11854
|
if (d.thisAssignments?.length)
|
|
11670
11855
|
return {
|
|
@@ -11678,11 +11863,11 @@ ${input.slice(result.pos)}
|
|
|
11678
11863
|
};
|
|
11679
11864
|
return d;
|
|
11680
11865
|
});
|
|
11681
|
-
var Declaration$
|
|
11682
|
-
var Declaration$
|
|
11683
|
-
var Declaration$
|
|
11684
|
-
var Declaration$
|
|
11685
|
-
var Declaration$$ = [Declaration$0, Declaration$1, Declaration$2, Declaration$3, Declaration$4, Declaration$5, Declaration$6];
|
|
11866
|
+
var Declaration$4 = TypeDeclaration;
|
|
11867
|
+
var Declaration$5 = EnumDeclaration;
|
|
11868
|
+
var Declaration$6 = OperatorDeclaration;
|
|
11869
|
+
var Declaration$7 = UsingDeclaration;
|
|
11870
|
+
var Declaration$$ = [Declaration$0, Declaration$1, Declaration$2, Declaration$3, Declaration$4, Declaration$5, Declaration$6, Declaration$7];
|
|
11686
11871
|
function Declaration(ctx, state) {
|
|
11687
11872
|
return $EVENT_C(ctx, state, "Declaration", Declaration$$);
|
|
11688
11873
|
}
|
package/dist/civet
CHANGED
|
@@ -6,6 +6,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
9
13
|
var __copyProps = (to, from, except, desc) => {
|
|
10
14
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
15
|
for (let key of __getOwnPropNames(from))
|
|
@@ -22,8 +26,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
26
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
27
|
mod
|
|
24
28
|
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
30
|
|
|
26
31
|
// source/cli.civet
|
|
32
|
+
var cli_exports = {};
|
|
33
|
+
__export(cli_exports, {
|
|
34
|
+
cli: () => cli,
|
|
35
|
+
parseArgs: () => parseArgs,
|
|
36
|
+
repl: () => repl,
|
|
37
|
+
version: () => version
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(cli_exports);
|
|
27
40
|
var import_main = require("./main.js");
|
|
28
41
|
var import_config = require("./config.js");
|
|
29
42
|
var import_unplugin = require("./unplugin");
|
|
@@ -244,6 +257,33 @@ async function* readFiles(filenames) {
|
|
|
244
257
|
return results1;
|
|
245
258
|
}
|
|
246
259
|
async function repl(options) {
|
|
260
|
+
const vm = await import("vm");
|
|
261
|
+
let importModuleDynamically = vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
262
|
+
if (!importModuleDynamically) {
|
|
263
|
+
if (vm.SourceTextModule != null) {
|
|
264
|
+
const { pathToFileURL } = await import("url");
|
|
265
|
+
importModuleDynamically = (specifier) => {
|
|
266
|
+
if (/^\.\.?[/\\]/.test(specifier)) {
|
|
267
|
+
return import(pathToFileURL(import_path.default.join(process.cwd(), specifier)));
|
|
268
|
+
} else {
|
|
269
|
+
return import(specifier);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
} else {
|
|
273
|
+
const execArgv = ["--experimental-vm-modules"];
|
|
274
|
+
const { register } = await import("module");
|
|
275
|
+
if (process.env.NODE_OPTIONS) {
|
|
276
|
+
execArgv.push(process.env.NODE_OPTIONS);
|
|
277
|
+
}
|
|
278
|
+
const { fork } = await import("child_process");
|
|
279
|
+
fork(__filename, process.argv.slice(2), {
|
|
280
|
+
execArgv,
|
|
281
|
+
stdio: "inherit"
|
|
282
|
+
});
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
require("../register.js");
|
|
247
287
|
console.log(`Civet ${version()} REPL. Enter a blank line to ${(() => {
|
|
248
288
|
switch (false) {
|
|
249
289
|
case !options.ast: {
|
|
@@ -259,7 +299,6 @@ async function repl(options) {
|
|
|
259
299
|
})()} code.`);
|
|
260
300
|
global.quit = global.exit = () => process.exit(0);
|
|
261
301
|
const nodeRepl = await import("repl");
|
|
262
|
-
const vm = await import("vm");
|
|
263
302
|
const r = nodeRepl.start({
|
|
264
303
|
prompt: (() => {
|
|
265
304
|
switch (false) {
|
|
@@ -288,29 +327,66 @@ async function repl(options) {
|
|
|
288
327
|
return "";
|
|
289
328
|
}
|
|
290
329
|
} : void 0,
|
|
291
|
-
eval: function(input, context, filename, callback) {
|
|
330
|
+
eval: async function(input, context, filename, callback) {
|
|
292
331
|
if (input === "\n") {
|
|
293
332
|
return callback(null, void 0);
|
|
294
333
|
} else if (input in ["quit\n", "exit\n", "quit()\n", "exit()\n"]) {
|
|
295
334
|
return process.exit(0);
|
|
296
335
|
} else if (input.endsWith("\n\n")) {
|
|
297
336
|
let output;
|
|
337
|
+
if (options.compile || options.ast) {
|
|
338
|
+
try {
|
|
339
|
+
output = (0, import_main.compile)(input, { ...options, filename });
|
|
340
|
+
} catch (error) {
|
|
341
|
+
console.error(error);
|
|
342
|
+
return callback(null, void 0);
|
|
343
|
+
}
|
|
344
|
+
return callback(null, output);
|
|
345
|
+
}
|
|
346
|
+
let ast = (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
347
|
+
const topLevelAwait = import_main.lib.gatherRecursive(
|
|
348
|
+
ast,
|
|
349
|
+
($) => $.type === "Await",
|
|
350
|
+
import_main.lib.isFunction
|
|
351
|
+
).length > 0;
|
|
352
|
+
if (topLevelAwait) {
|
|
353
|
+
const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
|
|
354
|
+
const prefix = input.slice(0, -rest.length);
|
|
355
|
+
const coffee = prologue.some((p) => p.type === "CivetPrologue" && (p.config.coffeeCompat || p.config.coffeeDo));
|
|
356
|
+
ast = (0, import_main.compile)(
|
|
357
|
+
prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
|
|
358
|
+
{ ...options, filename, ast: true }
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
const errors = [];
|
|
298
362
|
try {
|
|
299
|
-
output = (0, import_main.
|
|
363
|
+
output = (0, import_main.generate)(ast, { errors });
|
|
300
364
|
} catch (error) {
|
|
301
365
|
console.error(error);
|
|
302
366
|
return callback(null, void 0);
|
|
303
367
|
}
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
368
|
+
if (errors.length) {
|
|
369
|
+
console.error(`Parse errors: ${errors.map(($1) => $1.message).join("\n")}`);
|
|
370
|
+
return callback(null, void 0);
|
|
371
|
+
}
|
|
372
|
+
let result;
|
|
373
|
+
try {
|
|
374
|
+
result = vm.runInContext(output, context, {
|
|
375
|
+
filename,
|
|
376
|
+
importModuleDynamically
|
|
377
|
+
});
|
|
378
|
+
} catch (error) {
|
|
379
|
+
return callback(error, void 0);
|
|
380
|
+
}
|
|
381
|
+
if (topLevelAwait) {
|
|
308
382
|
try {
|
|
309
|
-
result =
|
|
383
|
+
result = await result;
|
|
310
384
|
} catch (error) {
|
|
311
|
-
|
|
385
|
+
callback(error, void 0);
|
|
312
386
|
}
|
|
313
387
|
return callback(null, result);
|
|
388
|
+
} else {
|
|
389
|
+
return callback(null, result);
|
|
314
390
|
}
|
|
315
391
|
} else {
|
|
316
392
|
return callback(new nodeRepl.Recoverable(new Error("Enter a blank line to execute code.")), null);
|
|
@@ -451,7 +527,20 @@ async function cli() {
|
|
|
451
527
|
}
|
|
452
528
|
}
|
|
453
529
|
const { fork } = await import("child_process");
|
|
454
|
-
const
|
|
530
|
+
const { register } = await import("module");
|
|
531
|
+
let execArgv;
|
|
532
|
+
if (register) {
|
|
533
|
+
execArgv = ["--import", "@danielx/civet/register"];
|
|
534
|
+
} else {
|
|
535
|
+
execArgv = [
|
|
536
|
+
"--loader",
|
|
537
|
+
"@danielx/civet/esm",
|
|
538
|
+
// ESM
|
|
539
|
+
"--require",
|
|
540
|
+
"@danielx/civet/register"
|
|
541
|
+
// CJS
|
|
542
|
+
];
|
|
543
|
+
}
|
|
455
544
|
const debugRe = /--debug|--inspect/;
|
|
456
545
|
const isDebug = typeof v8debug === "object" || debugRe.test(process.execArgv.join(" ")) || debugRe.test(process.env.NODE_OPTIONS ?? "");
|
|
457
546
|
if (process.env.NODE_OPTIONS) {
|
|
@@ -516,3 +605,10 @@ async function cli() {
|
|
|
516
605
|
if (require.main === module) {
|
|
517
606
|
cli();
|
|
518
607
|
}
|
|
608
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
609
|
+
0 && (module.exports = {
|
|
610
|
+
cli,
|
|
611
|
+
parseArgs,
|
|
612
|
+
repl,
|
|
613
|
+
version
|
|
614
|
+
});
|
package/dist/esm.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// source/esm.civet
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
|
-
import { createRequire } from "module";
|
|
4
3
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
5
4
|
import sourceMapSupport from "@cspotcode/source-map-support";
|
|
6
5
|
import Civet from "./main.js";
|
|
@@ -72,16 +71,6 @@ async function load(url, context, next) {
|
|
|
72
71
|
}
|
|
73
72
|
return next(url, context);
|
|
74
73
|
}
|
|
75
|
-
var require2 = createRequire(import.meta.url);
|
|
76
|
-
require2.extensions[".civet"] = function(m, filename) {
|
|
77
|
-
const source = readFileSync(filename, "utf8");
|
|
78
|
-
const code = compile(source, {
|
|
79
|
-
filename,
|
|
80
|
-
inlineMap: true,
|
|
81
|
-
js: true
|
|
82
|
-
});
|
|
83
|
-
return m._compile(code, filename);
|
|
84
|
-
};
|
|
85
74
|
export {
|
|
86
75
|
load,
|
|
87
76
|
resolve
|